@@ -352,13 +352,13 @@ export const useChatStore = createPersistStore(
352352 return session ;
353353 } ,
354354
355- onNewMessage ( message : ChatMessage ) {
356- get ( ) . updateCurrentSession ( ( session ) => {
355+ onNewMessage ( message : ChatMessage , targetSession : ChatSession ) {
356+ get ( ) . updateTargetSession ( targetSession , ( session ) => {
357357 session . messages = session . messages . concat ( ) ;
358358 session . lastUpdate = Date . now ( ) ;
359359 } ) ;
360360 get ( ) . updateStat ( message ) ;
361- get ( ) . summarizeSession ( ) ;
361+ get ( ) . summarizeSession ( false , targetSession ) ;
362362 } ,
363363
364364 async onUserInput ( content : string , attachImages ?: string [ ] ) {
@@ -428,7 +428,7 @@ export const useChatStore = createPersistStore(
428428 botMessage . streaming = false ;
429429 if ( message ) {
430430 botMessage . content = message ;
431- get ( ) . onNewMessage ( botMessage ) ;
431+ get ( ) . onNewMessage ( botMessage , session ) ;
432432 }
433433 ChatControllerPool . remove ( session . id , botMessage . id ) ;
434434 } ,
@@ -598,9 +598,12 @@ export const useChatStore = createPersistStore(
598598 } ) ;
599599 } ,
600600
601- summarizeSession ( refreshTitle : boolean = false ) {
601+ summarizeSession (
602+ refreshTitle : boolean = false ,
603+ targetSession : ChatSession ,
604+ ) {
602605 const config = useAppConfig . getState ( ) ;
603- const session = get ( ) . currentSession ( ) ;
606+ const session = targetSession ;
604607 const modelConfig = session . mask . modelConfig ;
605608 // skip summarize when using dalle3?
606609 if ( isDalle3 ( modelConfig . model ) ) {
@@ -651,7 +654,8 @@ export const useChatStore = createPersistStore(
651654 } ,
652655 onFinish ( message , responseRes ) {
653656 if ( responseRes ?. status === 200 ) {
654- get ( ) . updateCurrentSession (
657+ get ( ) . updateTargetSession (
658+ session ,
655659 ( session ) =>
656660 ( session . topic =
657661 message . length > 0 ? trimTopic ( message ) : DEFAULT_TOPIC ) ,
@@ -719,7 +723,7 @@ export const useChatStore = createPersistStore(
719723 onFinish ( message , responseRes ) {
720724 if ( responseRes ?. status === 200 ) {
721725 console . log ( "[Memory] " , message ) ;
722- get ( ) . updateCurrentSession ( ( session ) => {
726+ get ( ) . updateTargetSession ( session , ( session ) => {
723727 session . lastSummarizeIndex = lastSummarizeIndex ;
724728 session . memoryPrompt = message ; // Update the memory prompt for stored it in local storage
725729 } ) ;
@@ -745,6 +749,16 @@ export const useChatStore = createPersistStore(
745749 updater ( sessions [ index ] ) ;
746750 set ( ( ) => ( { sessions } ) ) ;
747751 } ,
752+ updateTargetSession (
753+ targetSession : ChatSession ,
754+ updater : ( session : ChatSession ) => void ,
755+ ) {
756+ const sessions = get ( ) . sessions ;
757+ const index = sessions . findIndex ( ( s ) => s . id === targetSession . id ) ;
758+ if ( index < 0 ) return ;
759+ updater ( sessions [ index ] ) ;
760+ set ( ( ) => ( { sessions } ) ) ;
761+ } ,
748762
749763 clearChatData ( ) {
750764 set ( ( ) => ( {
0 commit comments