Skip to content

Commit 0ebc455

Browse files
committed
Dashboard, Docs - Use updated Nebula API
1 parent f03ded3 commit 0ebc455

File tree

13 files changed

+118
-283
lines changed

13 files changed

+118
-283
lines changed

apps/dashboard/src/app/nebula-app/(app)/api/chat.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import { stream } from "fetch-event-stream";
44
import type { NebulaTxData } from "../components/Chats";
55
import type { ExecuteConfig } from "./types";
66

7-
export type ContextFilters = {
7+
export type NebulaContext = {
88
chainIds?: string[];
9-
contractAddresses?: string[];
10-
walletAddresses?: string[];
9+
walletAddress?: string;
1110
};
1211

1312
export async function promptNebula(params: {
@@ -17,27 +16,23 @@ export async function promptNebula(params: {
1716
authToken: string;
1817
handleStream: (res: ChatStreamedResponse) => void;
1918
abortController: AbortController;
20-
contextFilters: undefined | ContextFilters;
19+
context: undefined | NebulaContext;
2120
}) {
2221
const body: Record<string, string | boolean | object> = {
2322
message: params.message,
2423
user_id: "default-user",
25-
session_id: params.sessionId,
2624
stream: true,
25+
// TODO: move the session_id back here once the bug is fixed
2726
};
2827

29-
if (params.contextFilters) {
30-
body.context_filter = {
31-
chain_ids: params.contextFilters.chainIds || [],
32-
contract_addresses: params.contextFilters.contractAddresses || [],
33-
wallet_addresses: params.contextFilters.walletAddresses || [],
28+
if (params.context) {
29+
body.context = {
30+
session_id: params.sessionId, // TODO - this can be moved back to top level once this is fixed in nebula-server
31+
chain_ids: params.context.chainIds || [],
32+
wallet_address: params.context.walletAddress,
3433
};
3534
}
3635

37-
if (params.config) {
38-
body.execute_config = params.config;
39-
}
40-
4136
const events = await stream(`${NEXT_PUBLIC_NEBULA_URL}/chat`, {
4237
method: "POST",
4338
headers: {

apps/dashboard/src/app/nebula-app/(app)/api/session.ts

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NEXT_PUBLIC_NEBULA_URL } from "@/constants/env";
22
import { fetchWithAuthToken } from "../../../../utils/fetchWithAuthToken";
3-
import type { ContextFilters } from "./chat";
3+
import type { NebulaContext } from "./chat";
44
import type {
55
DeletedSessionInfo,
66
ExecuteConfig,
@@ -9,25 +9,17 @@ import type {
99
UpdatedSessionInfo,
1010
} from "./types";
1111

12-
// TODO - get the spec for return types on /session POST and PUT
13-
1412
export async function createSession(params: {
1513
authToken: string;
1614
config: ExecuteConfig | null;
17-
contextFilters: ContextFilters | undefined;
15+
context: NebulaContext | undefined;
1816
}) {
19-
const body: Record<string, string | boolean | object> = {
20-
can_execute: !!params.config,
21-
};
22-
if (params.config) {
23-
body.execute_config = params.config;
24-
}
17+
const body: Record<string, string | boolean | object> = {};
2518

26-
if (params.contextFilters) {
27-
body.context_filter = {
28-
chain_ids: params.contextFilters.chainIds || [],
29-
contract_addresses: params.contextFilters.contractAddresses || [],
30-
wallet_addresses: params.contextFilters.walletAddresses || [],
19+
if (params.context) {
20+
body.context = {
21+
chain_ids: params.context.chainIds || [],
22+
wallet_address: params.context.walletAddress,
3123
};
3224
}
3325

@@ -50,20 +42,14 @@ export async function updateSession(params: {
5042
authToken: string;
5143
config: ExecuteConfig | null;
5244
sessionId: string;
53-
contextFilters: ContextFilters | undefined;
45+
contextFilters: NebulaContext | undefined;
5446
}) {
55-
const body: Record<string, string | boolean | object> = {
56-
can_execute: !!params.config,
57-
};
58-
if (params.config) {
59-
body.execute_config = params.config;
60-
}
47+
const body: Record<string, string | boolean | object> = {};
6148

6249
if (params.contextFilters) {
63-
body.context_filter = {
50+
body.context = {
6451
chain_ids: params.contextFilters.chainIds || [],
65-
contract_addresses: params.contextFilters.contractAddresses || [],
66-
wallet_addresses: params.contextFilters.walletAddresses || [],
52+
wallet_address: params.contextFilters.walletAddress,
6753
};
6854
}
6955

apps/dashboard/src/app/nebula-app/(app)/api/types.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ export type ExecuteConfig = EngineConfig | SessionKeyConfig | ClientConfig;
2121

2222
type SessionContextFilter = {
2323
chain_ids: string[] | null;
24-
contract_addresses: string[] | null;
25-
wallet_addresses: string[] | null;
24+
wallet_address: string | null;
2625
};
2726

2827
export type SessionInfo = {
@@ -31,7 +30,6 @@ export type SessionInfo = {
3130
modal_name: string;
3231
archive_at: string | null;
3332
can_execute: boolean;
34-
execute_config: ExecuteConfig | null;
3533
created_at: string;
3634
deleted_at: string | null;
3735
history: Array<{
@@ -43,7 +41,7 @@ export type SessionInfo = {
4341
archived_at: string | null;
4442
title: string | null;
4543
is_public: boolean | null;
46-
context_filter: SessionContextFilter | null;
44+
context: SessionContextFilter | null;
4745
// memory
4846
// action: array<object> | null; <-- type of this is not available on https://nebula-api.thirdweb-dev.com/docs#/default/get_session_session__session_id__get
4947
};
@@ -52,8 +50,7 @@ export type UpdatedSessionInfo = {
5250
title: string;
5351
modal_name: string;
5452
account_id: string;
55-
execute_config: ExecuteConfig | null;
56-
context_filter: SessionContextFilter | null;
53+
context: SessionContextFilter | null;
5754
};
5855

5956
export type DeletedSessionInfo = {

apps/dashboard/src/app/nebula-app/(app)/components/ChatPageContent.tsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { ArrowRightIcon } from "lucide-react";
1414
import Link from "next/link";
1515
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
1616
import { useActiveAccount, useActiveWalletChain } from "thirdweb/react";
17-
import { type ContextFilters, promptNebula } from "../api/chat";
17+
import { type NebulaContext, promptNebula } from "../api/chat";
1818
import { createSession, updateSession } from "../api/session";
1919
import type { ExecuteConfig, SessionInfo } from "../api/types";
2020
import { newChatPageUrlStore, newSessionsStore } from "../stores";
@@ -81,39 +81,38 @@ export function ChatPageContent(props: {
8181
useState(false);
8282

8383
const [contextFilters, _setContextFilters] = useState<
84-
ContextFilters | undefined
84+
NebulaContext | undefined
8585
>(() => {
86-
const contextFilterRes = props.session?.context_filter;
87-
const value: ContextFilters = {
88-
chainIds: contextFilterRes?.chain_ids || undefined,
89-
contractAddresses: contextFilterRes?.contract_addresses || undefined,
90-
walletAddresses: contextFilterRes?.wallet_addresses || undefined,
86+
const contextRes = props.session?.context;
87+
const value: NebulaContext = {
88+
chainIds: contextRes?.chain_ids || undefined,
89+
walletAddress: contextRes?.wallet_address || undefined,
9190
};
9291

9392
return value;
9493
});
9594

96-
const setContextFilters = useCallback((v: ContextFilters | undefined) => {
95+
const setContextFilters = useCallback((v: NebulaContext | undefined) => {
9796
_setContextFilters(v);
9897
setHasUserUpdatedContextFilters(true);
9998
}, []);
10099

101100
const isNewSession = !props.session;
102101

103-
// if this is a new session, user has not manually updated context filters
104-
// update the context filters to the current user's wallet address and chain id
102+
// if this is a new session, user has not manually updated context
103+
// update the context to the current user's wallet address and chain id
105104
// eslint-disable-next-line no-restricted-syntax
106105
useEffect(() => {
107106
if (!isNewSession || hasUserUpdatedContextFilters) {
108107
return;
109108
}
110109

111110
_setContextFilters((_contextFilters) => {
112-
const updatedContextFilters: ContextFilters = _contextFilters
111+
const updatedContextFilters: NebulaContext = _contextFilters
113112
? { ..._contextFilters }
114113
: {};
115114

116-
updatedContextFilters.walletAddresses = address ? [address] : [];
115+
updatedContextFilters.walletAddress = address;
117116
updatedContextFilters.chainIds = activeChain
118117
? [activeChain.id.toString()]
119118
: [];
@@ -164,7 +163,7 @@ export function ChatPageContent(props: {
164163
const session = await createSession({
165164
authToken: props.authToken,
166165
config,
167-
contextFilters,
166+
context: contextFilters,
168167
});
169168
setSessionId(session.id);
170169
return session;
@@ -308,7 +307,7 @@ export function ChatPageContent(props: {
308307
}
309308
}
310309
},
311-
contextFilters: contextFilters,
310+
context: contextFilters,
312311
});
313312
} catch (error) {
314313
if (abortController.signal.aborted) {
@@ -363,9 +362,9 @@ export function ChatPageContent(props: {
363362
const showEmptyState = !userHasSubmittedMessage && messages.length === 0;
364363

365364
const handleUpdateContextFilters = async (
366-
values: ContextFilters | undefined,
365+
values: NebulaContext | undefined,
367366
) => {
368-
// if session is not yet created, don't need to update sessions - starting a chat will create a session with the context filters
367+
// if session is not yet created, don't need to update sessions - starting a chat will create a session with the context
369368
if (sessionId) {
370369
await updateSession({
371370
authToken: props.authToken,

apps/dashboard/src/app/nebula-app/(app)/components/ContextFilters.stories.tsx

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Meta, StoryObj } from "@storybook/react";
22
import { useState } from "react";
33
import { Toaster } from "sonner";
44
import { BadgeContainer, mobileViewport } from "../../../../stories/utils";
5-
import type { ContextFilters } from "../api/chat";
5+
import type { NebulaContext } from "../api/chat";
66
import ContextFiltersButton from "./ContextFilters";
77

88
const meta = {
@@ -50,51 +50,17 @@ function Story() {
5050

5151
<Variant
5252
contextFilters={{
53-
contractAddresses: ["0x1E51e33F9838A5a043E099C60409f62aA564272f"],
54-
}}
55-
label="1 contract"
56-
/>
57-
58-
<Variant
59-
contextFilters={{
60-
contractAddresses: [
61-
"0x1E51e33F9838A5a043E099C60409f62aA564272f",
62-
"0xF61c8d5492139b40af09bDB353733d5F0a348aCf",
63-
],
64-
}}
65-
label="Few contracts"
66-
/>
67-
68-
<Variant
69-
contextFilters={{
70-
walletAddresses: ["0x1F846F6DAE38E1C88D71EAA191760B15f38B7A37"],
53+
walletAddress: "0x1F846F6DAE38E1C88D71EAA191760B15f38B7A37",
7154
}}
7255
label="1 wallet"
7356
/>
7457

75-
<Variant
76-
contextFilters={{
77-
walletAddresses: [
78-
"0x1F846F6DAE38E1C88D71EAA191760B15f38B7A37",
79-
"0x83Dd93fA5D8343094f850f90B3fb90088C1bB425",
80-
],
81-
}}
82-
label="Few wallets"
83-
/>
84-
8558
<Variant
8659
contextFilters={{
8760
chainIds: ["137", "10", "421614"],
88-
contractAddresses: [
89-
"0x1E51e33F9838A5a043E099C60409f62aA564272f",
90-
"0xF61c8d5492139b40af09bDB353733d5F0a348aCf",
91-
],
92-
walletAddresses: [
93-
"0x1F846F6DAE38E1C88D71EAA191760B15f38B7A37",
94-
"0x83Dd93fA5D8343094f850f90B3fb90088C1bB425",
95-
],
61+
walletAddress: "0x1F846F6DAE38E1C88D71EAA191760B15f38B7A37",
9662
}}
97-
label="chains + wallets + contracts"
63+
label="chains + wallet"
9864
/>
9965
<Toaster richColors />
10066
</div>
@@ -103,18 +69,18 @@ function Story() {
10369

10470
function Variant(props: {
10571
label: string;
106-
contextFilters: ContextFilters | undefined;
72+
contextFilters: NebulaContext | undefined;
10773
}) {
10874
const [contextFilters, setContextFilters] = useState<
109-
ContextFilters | undefined
75+
NebulaContext | undefined
11076
>(props.contextFilters);
11177
return (
11278
<BadgeContainer label={props.label}>
11379
<ContextFiltersButton
11480
contextFilters={contextFilters}
11581
setContextFilters={setContextFilters}
11682
updateContextFilters={async (values) => {
117-
console.log("Updating context filters", values);
83+
console.log("Updating context", values);
11884
await new Promise((resolve) => setTimeout(resolve, 1000));
11985
}}
12086
/>

0 commit comments

Comments
 (0)