Skip to content

Commit 2396b4e

Browse files
committed
[NEB-87] Dashboard, Docs - Use updated Nebula API (#6157)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on updating the API's context handling by replacing the `context_filter` with a simplified `context` structure, changing types, and cleaning up related components to improve clarity and functionality in the codebase. ### Detailed summary - Changed `description` type from `string` to `React.ReactNode` in `APIParameter`. - Replaced `nebulaContextFilterPathParameter` and `nebulaExecuteConfigPathParameter` with `nebulaContextParameter`. - Updated JSON structures to use `context` instead of `context_filter`. - Modified related API response types and request parameters to align with the new context structure. - Refactored components to use `NebulaContext` instead of `ContextFilters`. - Adjusted context handling in various components and functions for consistency. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent ca6c913 commit 2396b4e

File tree

13 files changed

+131
-329
lines changed

13 files changed

+131
-329
lines changed

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,33 @@ import { NEXT_PUBLIC_NEBULA_URL } from "@/constants/env";
22
// TODO - copy the source of this library to dashboard
33
import { stream } from "fetch-event-stream";
44
import type { NebulaTxData } from "../components/Chats";
5-
import type { ExecuteConfig } from "./types";
65

7-
export type ContextFilters = {
8-
chainIds?: string[];
9-
contractAddresses?: string[];
10-
walletAddresses?: string[];
6+
export type NebulaContext = {
7+
chainIds: string[] | null;
8+
walletAddress: string | null;
119
};
1210

1311
export async function promptNebula(params: {
1412
message: string;
1513
sessionId: string;
16-
config: ExecuteConfig | null;
1714
authToken: string;
1815
handleStream: (res: ChatStreamedResponse) => void;
1916
abortController: AbortController;
20-
contextFilters: undefined | ContextFilters;
17+
context: undefined | NebulaContext;
2118
}) {
2219
const body: Record<string, string | boolean | object> = {
2320
message: params.message,
24-
user_id: "default-user",
25-
session_id: params.sessionId,
2621
stream: true,
22+
session_id: params.sessionId,
2723
};
2824

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 || [],
25+
if (params.context) {
26+
body.context = {
27+
chain_ids: params.context.chainIds || [],
28+
wallet_address: params.context.walletAddress,
3429
};
3530
}
3631

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

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

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
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,
6-
ExecuteConfig,
76
SessionInfo,
87
TruncatedSessionInfo,
98
UpdatedSessionInfo,
109
} from "./types";
1110

12-
// TODO - get the spec for return types on /session POST and PUT
13-
1411
export async function createSession(params: {
1512
authToken: string;
16-
config: ExecuteConfig | null;
17-
contextFilters: ContextFilters | undefined;
13+
context: NebulaContext | undefined;
1814
}) {
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-
}
15+
const body: Record<string, string | boolean | object> = {};
2516

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 || [],
17+
if (params.context) {
18+
body.context = {
19+
chain_ids: params.context.chainIds || [],
20+
wallet_address: params.context.walletAddress,
3121
};
3222
}
3323

@@ -48,22 +38,15 @@ export async function createSession(params: {
4838

4939
export async function updateSession(params: {
5040
authToken: string;
51-
config: ExecuteConfig | null;
5241
sessionId: string;
53-
contextFilters: ContextFilters | undefined;
42+
contextFilters: NebulaContext | undefined;
5443
}) {
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-
}
44+
const body: Record<string, string | boolean | object> = {};
6145

6246
if (params.contextFilters) {
63-
body.context_filter = {
47+
body.context = {
6448
chain_ids: params.contextFilters.chainIds || [],
65-
contract_addresses: params.contextFilters.contractAddresses || [],
66-
wallet_addresses: params.contextFilters.walletAddresses || [],
49+
wallet_address: params.contextFilters.walletAddress,
6750
};
6851
}
6952

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

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
1-
type EngineConfig = {
2-
mode: "engine";
3-
engine_url: string;
4-
engine_authorization_token: string;
5-
engine_backend_wallet_address: string;
6-
};
7-
8-
type SessionKeyConfig = {
9-
mode: "session_key";
10-
smart_account_address: string;
11-
smart_account_factory_address: string;
12-
smart_account_session_key: string;
13-
};
14-
15-
type ClientConfig = {
16-
mode: "client";
17-
signer_wallet_address: string;
18-
};
19-
20-
export type ExecuteConfig = EngineConfig | SessionKeyConfig | ClientConfig;
21-
221
type SessionContextFilter = {
232
chain_ids: string[] | null;
24-
contract_addresses: string[] | null;
25-
wallet_addresses: string[] | null;
3+
wallet_address: string | null;
264
};
275

286
export type SessionInfo = {
@@ -31,7 +9,6 @@ export type SessionInfo = {
319
modal_name: string;
3210
archive_at: string | null;
3311
can_execute: boolean;
34-
execute_config: ExecuteConfig | null;
3512
created_at: string;
3613
deleted_at: string | null;
3714
history: Array<{
@@ -43,7 +20,7 @@ export type SessionInfo = {
4320
archived_at: string | null;
4421
title: string | null;
4522
is_public: boolean | null;
46-
context_filter: SessionContextFilter | null;
23+
context: SessionContextFilter | null;
4724
// memory
4825
// 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
4926
};
@@ -52,8 +29,7 @@ export type UpdatedSessionInfo = {
5229
title: string;
5330
modal_name: string;
5431
account_id: string;
55-
execute_config: ExecuteConfig | null;
56-
context_filter: SessionContextFilter | null;
32+
context: SessionContextFilter | null;
5733
};
5834

5935
export type DeletedSessionInfo = {

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

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import { useThirdwebClient } from "@/constants/thirdweb.client";
1212
import type { Account } from "@3rdweb-sdk/react/hooks/useApi";
1313
import { ArrowRightIcon } from "lucide-react";
1414
import Link from "next/link";
15-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
15+
import { useCallback, useEffect, 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";
19-
import type { ExecuteConfig, SessionInfo } from "../api/types";
19+
import type { SessionInfo } from "../api/types";
2020
import { newChatPageUrlStore, newSessionsStore } from "../stores";
2121
import { ChatBar } from "./ChatBar";
2222
import { type ChatMessage, Chats } from "./Chats";
@@ -81,39 +81,43 @@ 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 || null,
89+
walletAddress: contextRes?.wallet_address || null,
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
113-
? { ..._contextFilters }
114-
: {};
111+
const updatedContextFilters: NebulaContext = _contextFilters
112+
? {
113+
..._contextFilters,
114+
}
115+
: {
116+
chainIds: [],
117+
walletAddress: null,
118+
};
115119

116-
updatedContextFilters.walletAddresses = address ? [address] : [];
120+
updatedContextFilters.walletAddress = address || null;
117121
updatedContextFilters.chainIds = activeChain
118122
? [activeChain.id.toString()]
119123
: [];
@@ -122,15 +126,6 @@ export function ChatPageContent(props: {
122126
});
123127
}, [address, isNewSession, hasUserUpdatedContextFilters, activeChain]);
124128

125-
const config: ExecuteConfig | null = useMemo(() => {
126-
return address
127-
? {
128-
mode: "client",
129-
signer_wallet_address: address,
130-
}
131-
: null;
132-
}, [address]);
133-
134129
const [sessionId, _setSessionId] = useState<string | undefined>(
135130
props.session?.id,
136131
);
@@ -163,12 +158,11 @@ export function ChatPageContent(props: {
163158
const initSession = useCallback(async () => {
164159
const session = await createSession({
165160
authToken: props.authToken,
166-
config,
167-
contextFilters,
161+
context: contextFilters,
168162
});
169163
setSessionId(session.id);
170164
return session;
171-
}, [config, contextFilters, props.authToken, setSessionId]);
165+
}, [contextFilters, props.authToken, setSessionId]);
172166

173167
const handleSendMessage = useCallback(
174168
async (message: string) => {
@@ -221,7 +215,6 @@ export function ChatPageContent(props: {
221215
abortController,
222216
message: message,
223217
sessionId: currentSessionId,
224-
config: config,
225218
authToken: props.authToken,
226219
handleStream(res) {
227220
if (abortController.signal.aborted) {
@@ -308,7 +301,7 @@ export function ChatPageContent(props: {
308301
}
309302
}
310303
},
311-
contextFilters: contextFilters,
304+
context: contextFilters,
312305
});
313306
} catch (error) {
314307
if (abortController.signal.aborted) {
@@ -338,7 +331,6 @@ export function ChatPageContent(props: {
338331
[
339332
sessionId,
340333
contextFilters,
341-
config,
342334
props.authToken,
343335
messages.length,
344336
initSession,
@@ -363,13 +355,12 @@ export function ChatPageContent(props: {
363355
const showEmptyState = !userHasSubmittedMessage && messages.length === 0;
364356

365357
const handleUpdateContextFilters = async (
366-
values: ContextFilters | undefined,
358+
values: NebulaContext | undefined,
367359
) => {
368-
// if session is not yet created, don't need to update sessions - starting a chat will create a session with the context filters
360+
// if session is not yet created, don't need to update sessions - starting a chat will create a session with the context
369361
if (sessionId) {
370362
await updateSession({
371363
authToken: props.authToken,
372-
config,
373364
sessionId,
374365
contextFilters: values,
375366
});

0 commit comments

Comments
 (0)