@@ -29,7 +29,8 @@ export function useChatActions(
2929 isDeepThinkActive ?: boolean ,
3030 isMCPActive ?: boolean ,
3131 changeInput ?: ( val : string ) => void ,
32- showChatHistory ?: boolean
32+ showChatHistory ?: boolean ,
33+ getChatHistoryChatPage ?: ( ) => void ,
3334) {
3435 const isCurrentLogin = useAuthStore ( ( state ) => state . isCurrentLogin ) ;
3536
@@ -197,34 +198,34 @@ export function useChatActions(
197198 ) {
198199 try {
199200 const response = JSON . parse ( msg ) ;
200- console . log ( "first" , response ) ;
201+ // console.log("first", response);
201202
202203 let updatedChat : Chat ;
203204 if ( Array . isArray ( response ) ) {
204205 curIdRef . current = response [ 0 ] ?. _id ;
205206 curSessionIdRef . current = response [ 0 ] ?. _source ?. session_id ;
206- console . log (
207- "curIdRef-curSessionIdRef-Array" ,
208- curIdRef . current ,
209- curSessionIdRef . current
210- ) ;
207+ // console.log(
208+ // "curIdRef-curSessionIdRef-Array",
209+ // curIdRef.current,
210+ // curSessionIdRef.current
211+ // );
211212 updatedChat = {
212213 ...updatedChatRef . current ,
213214 messages : [
214215 ...( updatedChatRef . current ?. messages || [ ] ) ,
215216 ...( response || [ ] ) ,
216217 ] ,
217218 } ;
218- console . log ( "array" , updatedChat , updatedChatRef . current ?. messages ) ;
219+ // console.log("array", updatedChat, updatedChatRef.current?.messages);
219220 } else {
220221 const newChat : Chat = response ;
221222 curIdRef . current = response ?. payload ?. id ;
222223 curSessionIdRef . current = response ?. payload ?. session_id ;
223- console . log (
224- "curIdRef-curSessionIdRef" ,
225- curIdRef . current ,
226- curSessionIdRef . current
227- ) ;
224+ // console.log(
225+ // "curIdRef-curSessionIdRef",
226+ // curIdRef.current,
227+ // curSessionIdRef.current
228+ // );
228229
229230 newChat . _source = {
230231 ...response ?. payload ,
@@ -252,7 +253,7 @@ export function useChatActions(
252253 async ( timestamp : number ) => {
253254 cleanupListeners ( ) ;
254255
255- console . log ( "setupListeners" , clientId , timestamp ) ;
256+ // console.log("setupListeners", clientId, timestamp);
256257 const unlisten_chat_message = await platformAdapter . listenEvent (
257258 `chat-stream-${ clientId } -${ timestamp } ` ,
258259 ( event ) => {
@@ -300,12 +301,45 @@ export function useChatActions(
300301 [ setupListeners ]
301302 ) ;
302303
304+ const getChatHistory = useCallback ( async ( ) => {
305+ let response : any ;
306+ if ( isTauri ) {
307+ if ( await unrequitable ( ) ) {
308+ return setChats ( [ ] ) ;
309+ }
310+
311+ response = await platformAdapter . commands ( "chat_history" , {
312+ serverId : currentService ?. id ,
313+ from : 0 ,
314+ size : 100 ,
315+ query : keyword ,
316+ } ) ;
317+
318+ response = response ? JSON . parse ( response ) : null ;
319+ } else {
320+ const [ _error , res ] = await Get ( `/chat/_history` , {
321+ from : 0 ,
322+ size : 100 ,
323+ } ) ;
324+ response = res ;
325+ }
326+
327+ const hits = response ?. hits ?. hits || [ ] ;
328+ setChats ( hits ) ;
329+ } , [
330+ currentService ?. id ,
331+ keyword ,
332+ isTauri ,
333+ currentService ?. enabled ,
334+ isCurrentLogin ,
335+ ] ) ;
336+
303337 const createNewChat = useCallback (
304338 async ( params ?: SendMessageParams ) => {
305339 const { message, attachments } = params || { } ;
306340
307- console . log ( "message" , message ) ;
308- console . log ( "attachments" , attachments ) ;
341+ // console.log("message", message);
342+ // console.log("attachments", attachments);
309343
310344 if ( ! message && isEmpty ( attachments ) ) return ;
311345
@@ -325,7 +359,7 @@ export function useChatActions(
325359 if ( isTauri ) {
326360 if ( ! currentService ?. id ) return ;
327361
328- console . log ( "chat_create" , clientId , timestamp ) ;
362+ // console.log("chat_create", clientId, timestamp);
329363
330364 await platformAdapter . commands ( "chat_create" , {
331365 serverId : currentService ?. id ,
@@ -334,20 +368,25 @@ export function useChatActions(
334368 queryParams,
335369 clientId : `chat-stream-${ clientId } -${ timestamp } ` ,
336370 } ) ;
337- console . log ( "_create end" , message ) ;
371+ // console.log("_create end", message);
338372 resetChatState ( ) ;
339373 } else {
340374 await streamPost ( {
341375 url : "/chat/_create" ,
342376 body : { message } ,
343377 queryParams,
344378 onMessage : ( line ) => {
345- console . log ( "⏳" , line ) ;
379+ // console.log("⏳", line);
346380 handleChatCreateStreamMessage ( line ) ;
347381 // append to chat box
348382 } ,
349383 } ) ;
350384 }
385+ // console.log("showChatHistory", showChatHistory);
386+
387+ if ( showChatHistory ) {
388+ getChatHistoryChatPage ? getChatHistoryChatPage ( ) : getChatHistory ( ) ;
389+ }
351390 } ,
352391 [
353392 isTauri ,
@@ -360,6 +399,8 @@ export function useChatActions(
360399 currentAssistant ,
361400 chatClose ,
362401 clientId ,
402+ showChatHistory ,
403+ getChatHistory ,
363404 ]
364405 ) ;
365406
@@ -386,7 +427,7 @@ export function useChatActions(
386427
387428 if ( isTauri ) {
388429 if ( ! currentService ?. id ) return ;
389- console . log ( "chat_chat" , clientId , timestamp ) ;
430+ // console.log("chat_chat", clientId, timestamp);
390431 await platformAdapter . commands ( "chat_chat" , {
391432 serverId : currentService ?. id ,
392433 sessionId : newChat ?. _id ,
@@ -395,15 +436,15 @@ export function useChatActions(
395436 attachments,
396437 clientId : `chat-stream-${ clientId } -${ timestamp } ` ,
397438 } ) ;
398- console . log ( "chat_chat end" , message , clientId ) ;
439+ // console.log("chat_chat end", message, clientId);
399440 resetChatState ( ) ;
400441 } else {
401442 await streamPost ( {
402443 url : `/chat/${ newChat ?. _id } /_chat` ,
403444 body : { message } ,
404445 queryParams,
405446 onMessage : ( line ) => {
406- console . log ( "line" , line ) ;
447+ // console.log("line", line);
407448 handleChatCreateStreamMessage ( line ) ;
408449 // append to chat box
409450 } ,
@@ -468,39 +509,6 @@ export function useChatActions(
468509 [ currentService ?. id , isTauri ]
469510 ) ;
470511
471- const getChatHistory = useCallback ( async ( ) => {
472- let response : any ;
473- if ( isTauri ) {
474- if ( await unrequitable ( ) ) {
475- return setChats ( [ ] ) ;
476- }
477-
478- response = await platformAdapter . commands ( "chat_history" , {
479- serverId : currentService ?. id ,
480- from : 0 ,
481- size : 100 ,
482- query : keyword ,
483- } ) ;
484-
485- response = response ? JSON . parse ( response ) : null ;
486- } else {
487- const [ _error , res ] = await Get ( `/chat/_history` , {
488- from : 0 ,
489- size : 100 ,
490- } ) ;
491- response = res ;
492- }
493-
494- const hits = response ?. hits ?. hits || [ ] ;
495- setChats ( hits ) ;
496- } , [
497- currentService ?. id ,
498- keyword ,
499- isTauri ,
500- currentService ?. enabled ,
501- isCurrentLogin ,
502- ] ) ;
503-
504512 useEffect ( ( ) => {
505513 if ( showChatHistory ) {
506514 getChatHistory ( ) ;
0 commit comments