@@ -50,30 +50,37 @@ type UseAiBotReturnType = {
50
50
changeChatVisibility : ( threadId : string , isPublic : boolean ) => void ;
51
51
isChangeVisibilityLoading : boolean ;
52
52
unsubscribe : ( threadId : string ) => void ;
53
+ chatsList : UseBotChatsListHook [ 'chatsList' ] ;
54
+ chatsListLoading : UseBotChatsListHook [ 'loading' ] ;
55
+ getChatsList : UseBotChatsListHook [ 'getChatsList' ]
53
56
model : UseLLMModelsList [ 'model' ] ,
54
57
setModel : UseLLMModelsList [ 'setModel' ]
55
58
llmModels : UseLLMModelsList [ 'llmModels' ]
56
59
}
57
60
58
61
type UseAiBotArgs = {
59
62
threadId ?: string ;
60
- prevThreadId ?: string ;
61
- onChatLoadingError ?: ( ) => void ;
63
+ orgId ?: number
62
64
}
63
65
64
66
export const useAiBot = ( args : UseAiBotArgs ) : UseAiBotReturnType => {
65
- const { threadId, onChatLoadingError } = args ;
67
+ const { threadId, orgId } = args ;
66
68
const { showMessage, closeSnackbar } = useAlertSnackbar ( ) ;
67
69
const { llmModels, model, setModel } = useLLMModelsList ( ) ;
68
70
let location = useLocation < { skipReloading ?: boolean } > ( ) ;
69
71
72
+ const {
73
+ chatsList,
74
+ loading : chatsListLoading ,
75
+ getChatsList,
76
+ } = useBotChatsList ( orgId ) ;
77
+
70
78
const [ messages , setMessages ] = useState < BotMessage [ ] | null > ( null ) ;
71
79
const [ isLoading , setLoading ] = useState < boolean > ( false ) ;
72
80
const [ error , setError ] = useState < ErrorType | null > ( null ) ;
73
81
const [ wsLoading , setWsLoading ] = useState < boolean > ( false ) ;
74
- const [ isChangeVisibilityLoading , setIsChangeVisibilityLoading ] = useState < boolean > ( false ) ;
82
+ const [ isChangeVisibilityLoading , setIsChangeVisibilityLoading ] = useState < boolean > ( false )
75
83
76
-
77
84
const token = localStorage . getAuthToken ( )
78
85
79
86
const onWebSocketError = ( error : WebSocketEventMap [ 'error' ] ) => {
@@ -105,6 +112,9 @@ export const useAiBot = (args: UseAiBotArgs): UseAiBotReturnType => {
105
112
} ) ;
106
113
}
107
114
}
115
+ } else if ( threadId !== messageData . thread_id ) {
116
+ const threadInList = chatsList ?. find ( ( item ) => item . thread_id === messageData . thread_id )
117
+ if ( ! threadInList ) getChatsList ( )
108
118
}
109
119
} else {
110
120
showMessage ( 'An error occurred. Please try again' )
@@ -150,7 +160,6 @@ export const useAiBot = (args: UseAiBotArgs): UseAiBotReturnType => {
150
160
if ( response && response . length > 0 ) {
151
161
setMessages ( response ) ;
152
162
} else {
153
- if ( onChatLoadingError ) onChatLoadingError ( ) ;
154
163
setError ( {
155
164
code : 404 ,
156
165
message : 'Specified chat not found or you have no access.' ,
@@ -181,7 +190,6 @@ export const useAiBot = (args: UseAiBotArgs): UseAiBotReturnType => {
181
190
} else if ( threadId ) {
182
191
subscribe ( threadId )
183
192
}
184
-
185
193
return ( ) => {
186
194
isCancelled = true ;
187
195
} ;
@@ -309,6 +317,9 @@ export const useAiBot = (args: UseAiBotArgs): UseAiBotReturnType => {
309
317
clearChat,
310
318
messages,
311
319
unsubscribe,
320
+ chatsList,
321
+ chatsListLoading,
322
+ getChatsList,
312
323
model,
313
324
setModel,
314
325
llmModels
@@ -319,7 +330,7 @@ type UseBotChatsListHook = {
319
330
chatsList : BotMessage [ ] | null ;
320
331
error : Response | null ;
321
332
loading : boolean ;
322
- getChatsList : ( ) => void
333
+ getChatsList : ( ) => void ;
323
334
} ;
324
335
325
336
export const useBotChatsList = ( orgId ?: number ) : UseBotChatsListHook => {
0 commit comments