@@ -12,11 +12,11 @@ import { useThirdwebClient } from "@/constants/thirdweb.client";
1212import type { Account } from "@3rdweb-sdk/react/hooks/useApi" ;
1313import { ArrowRightIcon } from "lucide-react" ;
1414import Link from "next/link" ;
15- import { useCallback , useEffect , useMemo , useRef , useState } from "react" ;
15+ import { useCallback , useEffect , useRef , useState } from "react" ;
1616import { useActiveAccount , useActiveWalletChain } from "thirdweb/react" ;
17- import { type ContextFilters , promptNebula } from "../api/chat" ;
17+ import { type NebulaContext , promptNebula } from "../api/chat" ;
1818import { createSession , updateSession } from "../api/session" ;
19- import type { ExecuteConfig , SessionInfo } from "../api/types" ;
19+ import type { SessionInfo } from "../api/types" ;
2020import { newChatPageUrlStore , newSessionsStore } from "../stores" ;
2121import { ChatBar } from "./ChatBar" ;
2222import { 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