Skip to content

Commit d8ae044

Browse files
committed
[Nebula] Fix context filters not prepopulated when viewing chat from history
1 parent ce0da51 commit d8ae044

File tree

4 files changed

+123
-100
lines changed

4 files changed

+123
-100
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { NEXT_PUBLIC_NEBULA_URL } from "@/constants/env";
22
import { fetchWithAuthToken } from "../../../../utils/fetchWithAuthToken";
33
import type { ContextFilters } from "./chat";
4-
import type { ExecuteConfig, SessionInfo, TruncatedSessionInfo } from "./types";
4+
import type {
5+
DeletedSessionInfo,
6+
ExecuteConfig,
7+
SessionInfo,
8+
TruncatedSessionInfo,
9+
UpdatedSessionInfo,
10+
} from "./types";
511

612
// TODO - get the spec for return types on /session POST and PUT
713

@@ -71,7 +77,7 @@ export async function updateSession(params: {
7177
}
7278
const data = await res.json();
7379

74-
return data.result as SessionInfo;
80+
return data.result as UpdatedSessionInfo;
7581
}
7682

7783
export async function deleteSession(params: {
@@ -89,10 +95,7 @@ export async function deleteSession(params: {
8995
}
9096
const data = await res.json();
9197

92-
return data.result as {
93-
id: string;
94-
deleted_at: string;
95-
};
98+
return data.result as DeletedSessionInfo;
9699
}
97100

98101
export async function getSessions(params: {

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,30 @@ export type SessionInfo = {
3737
archived_at: string | null;
3838
title: string | null;
3939
is_public: boolean | null;
40+
context_filter: {
41+
chain_ids: string[];
42+
contract_addresses: string[];
43+
} | null;
4044
// memory
4145
// 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
4246
};
4347

48+
export type UpdatedSessionInfo = {
49+
title: string;
50+
modal_name: string;
51+
account_id: string;
52+
execute_config: ExecuteConfig | null;
53+
context_filter: {
54+
chain_ids: string[];
55+
contract_addresses: string[];
56+
} | null;
57+
};
58+
59+
export type DeletedSessionInfo = {
60+
id: string;
61+
deleted_at: string;
62+
};
63+
4464
export type TruncatedSessionInfo = {
4565
created_at: string;
4666
id: string;

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ export function ChatPageContent(props: {
3838
const [_config, setConfig] = useState<ExecuteConfig | null>();
3939
const [contextFilters, setContextFilters] = useState<
4040
ContextFilters | undefined
41-
>(undefined);
41+
>(() => {
42+
const contextFilterRes = props.session?.context_filter;
43+
if (contextFilterRes) {
44+
return {
45+
chainIds: contextFilterRes.chain_ids,
46+
contractAddresses: contextFilterRes.contract_addresses,
47+
};
48+
}
49+
});
4250

4351
const config = _config || {
4452
mode: "client",
@@ -254,16 +262,12 @@ export function ChatPageContent(props: {
254262
// If no session exists, create a new one
255263
await initSession();
256264
} else {
257-
const newSession = await updateSession({
265+
await updateSession({
258266
authToken: props.authToken,
259267
config: newConfig,
260268
sessionId,
261269
contextFilters,
262270
});
263-
264-
if (newSession) {
265-
setSessionId(newSession.id);
266-
}
267271
}
268272
} catch (error) {
269273
console.error("Failed to update session", error);
@@ -292,16 +296,12 @@ export function ChatPageContent(props: {
292296
updateContextFilters={async (values) => {
293297
// if session is not yet created, don't need to update sessions - starting a chat will create a session with the context filters
294298
if (sessionId) {
295-
const newSession = await updateSession({
299+
await updateSession({
296300
authToken: props.authToken,
297301
config,
298302
sessionId,
299303
contextFilters: values,
300304
});
301-
// setting new id - but it doesn't actually change if the session was already created ( which is the case here )
302-
if (newSession) {
303-
setSessionId(newSession.id);
304-
}
305305
}
306306
}}
307307
/>

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

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,24 @@ export default function ContextFiltersButton(props: {
5252
: "Set context filters"}
5353
</Button>
5454
</DialogTrigger>
55-
<ContextFilterDialogContent
56-
contextFilters={props.contextFilters}
57-
isPending={updateMutation.isPending}
58-
updateFilters={async (data) => {
59-
const promise = updateMutation.mutateAsync(data);
60-
toast.promise(promise, {
61-
success: "Context filters updated",
62-
error: "Failed to update context filters",
63-
});
55+
<DialogContent className="p-0">
56+
<ContextFilterDialogContent
57+
contextFilters={props.contextFilters}
58+
isPending={updateMutation.isPending}
59+
updateFilters={async (data) => {
60+
const promise = updateMutation.mutateAsync(data);
61+
toast.promise(promise, {
62+
success: "Context filters updated",
63+
error: "Failed to update context filters",
64+
});
6465

65-
promise.then(() => {
66-
props.setContextFilters(data);
67-
setIsOpen(false);
68-
});
69-
}}
70-
/>
66+
promise.then(() => {
67+
props.setContextFilters(data);
68+
setIsOpen(false);
69+
});
70+
}}
71+
/>
72+
</DialogContent>
7173
</Dialog>
7274
);
7375
}
@@ -137,76 +139,74 @@ function ContextFilterDialogContent(props: {
137139
}
138140

139141
return (
140-
<DialogContent className="p-0">
141-
<Form {...form}>
142-
<DialogHeader className="px-6 pt-6 pb-1">
143-
<DialogTitle className="font-semibold text-xl">
144-
Context Filters
145-
</DialogTitle>
146-
<DialogDescription className="text-muted-foreground">
147-
Provide context information to Nebula for your prompts
148-
</DialogDescription>
149-
</DialogHeader>
142+
<Form {...form}>
143+
<DialogHeader className="px-6 pt-6 pb-1">
144+
<DialogTitle className="font-semibold text-xl">
145+
Context Filters
146+
</DialogTitle>
147+
<DialogDescription className="text-muted-foreground">
148+
Provide context information to Nebula for your prompts
149+
</DialogDescription>
150+
</DialogHeader>
150151

151-
<form onSubmit={form.handleSubmit(onSubmit)}>
152-
<div className="flex flex-col gap-5 px-6">
153-
<FormField
154-
control={form.control}
155-
name="chainIds"
156-
render={() => (
157-
<FormItem>
158-
<FormLabel>Chain IDs</FormLabel>
159-
<FormControl>
160-
<MultiNetworkSelector
161-
selectedChainIds={form
162-
.watch()
163-
.chainIds.split(",")
164-
.filter(Boolean)
165-
.map(Number)}
166-
onChange={(values) => {
167-
console.log("values", values);
168-
form.setValue("chainIds", values.join(","));
169-
}}
170-
/>
171-
</FormControl>
172-
<FormMessage />
173-
</FormItem>
174-
)}
175-
/>
152+
<form onSubmit={form.handleSubmit(onSubmit)}>
153+
<div className="flex flex-col gap-5 px-6">
154+
<FormField
155+
control={form.control}
156+
name="chainIds"
157+
render={() => (
158+
<FormItem>
159+
<FormLabel>Chain IDs</FormLabel>
160+
<FormControl>
161+
<MultiNetworkSelector
162+
selectedChainIds={form
163+
.watch()
164+
.chainIds.split(",")
165+
.filter(Boolean)
166+
.map(Number)}
167+
onChange={(values) => {
168+
console.log("values", values);
169+
form.setValue("chainIds", values.join(","));
170+
}}
171+
/>
172+
</FormControl>
173+
<FormMessage />
174+
</FormItem>
175+
)}
176+
/>
176177

177-
<FormField
178-
control={form.control}
179-
name="contractAddresses"
180-
render={({ field }) => (
181-
<FormItem>
182-
<FormLabel>Contract Addresses</FormLabel>
183-
<FormControl>
184-
<AutoResizeTextarea
185-
{...field}
186-
placeholder="0x123..., 0x456..."
187-
className="min-h-[32px] resize-none"
188-
/>
189-
</FormControl>
190-
<FormDescription>
191-
Comma separated list of contract addresses
192-
</FormDescription>
193-
<FormMessage />
194-
</FormItem>
195-
)}
196-
/>
197-
</div>
178+
<FormField
179+
control={form.control}
180+
name="contractAddresses"
181+
render={({ field }) => (
182+
<FormItem>
183+
<FormLabel>Contract Addresses</FormLabel>
184+
<FormControl>
185+
<AutoResizeTextarea
186+
{...field}
187+
placeholder="0x123..., 0x456..."
188+
className="min-h-[32px] resize-none"
189+
/>
190+
</FormControl>
191+
<FormDescription>
192+
Comma separated list of contract addresses
193+
</FormDescription>
194+
<FormMessage />
195+
</FormItem>
196+
)}
197+
/>
198+
</div>
198199

199-
<div className="mt-10 flex justify-end gap-3 border-t bg-muted/50 p-6">
200-
<DialogClose asChild>
201-
<Button variant="outline">Cancel</Button>
202-
</DialogClose>
203-
<Button className="min-w-28 gap-2" type="submit">
204-
{props.isPending && <Spinner className="size-4" />}
205-
Update
206-
</Button>
207-
</div>
208-
</form>
209-
</Form>
210-
</DialogContent>
200+
<div className="mt-10 flex justify-end gap-3 border-t bg-muted/50 p-6">
201+
<DialogClose asChild>
202+
<Button variant="outline">Cancel</Button>
203+
</DialogClose>
204+
<Button className="min-w-28 gap-2" type="submit">
205+
{props.isPending && <Spinner className="size-4" />}
206+
Update
207+
</Button>
208+
</div>
209+
</form>
210+
</Form>
211211
);
212212
}

0 commit comments

Comments
 (0)