@@ -352,13 +352,13 @@ export const useChatStore = createPersistStore(
352
352
return session ;
353
353
} ,
354
354
355
- onNewMessage ( message : ChatMessage ) {
356
- get ( ) . updateCurrentSession ( ( session ) => {
355
+ onNewMessage ( message : ChatMessage , targetSession : ChatSession ) {
356
+ get ( ) . updateTargetSession ( targetSession , ( session ) => {
357
357
session . messages = session . messages . concat ( ) ;
358
358
session . lastUpdate = Date . now ( ) ;
359
359
} ) ;
360
360
get ( ) . updateStat ( message ) ;
361
- get ( ) . summarizeSession ( ) ;
361
+ get ( ) . summarizeSession ( false , targetSession ) ;
362
362
} ,
363
363
364
364
async onUserInput ( content : string , attachImages ?: string [ ] ) {
@@ -428,7 +428,7 @@ export const useChatStore = createPersistStore(
428
428
botMessage . streaming = false ;
429
429
if ( message ) {
430
430
botMessage . content = message ;
431
- get ( ) . onNewMessage ( botMessage ) ;
431
+ get ( ) . onNewMessage ( botMessage , session ) ;
432
432
}
433
433
ChatControllerPool . remove ( session . id , botMessage . id ) ;
434
434
} ,
@@ -598,9 +598,12 @@ export const useChatStore = createPersistStore(
598
598
} ) ;
599
599
} ,
600
600
601
- summarizeSession ( refreshTitle : boolean = false ) {
601
+ summarizeSession (
602
+ refreshTitle : boolean = false ,
603
+ targetSession : ChatSession ,
604
+ ) {
602
605
const config = useAppConfig . getState ( ) ;
603
- const session = get ( ) . currentSession ( ) ;
606
+ const session = targetSession ;
604
607
const modelConfig = session . mask . modelConfig ;
605
608
// skip summarize when using dalle3?
606
609
if ( isDalle3 ( modelConfig . model ) ) {
@@ -651,7 +654,8 @@ export const useChatStore = createPersistStore(
651
654
} ,
652
655
onFinish ( message , responseRes ) {
653
656
if ( responseRes ?. status === 200 ) {
654
- get ( ) . updateCurrentSession (
657
+ get ( ) . updateTargetSession (
658
+ session ,
655
659
( session ) =>
656
660
( session . topic =
657
661
message . length > 0 ? trimTopic ( message ) : DEFAULT_TOPIC ) ,
@@ -719,7 +723,7 @@ export const useChatStore = createPersistStore(
719
723
onFinish ( message , responseRes ) {
720
724
if ( responseRes ?. status === 200 ) {
721
725
console . log ( "[Memory] " , message ) ;
722
- get ( ) . updateCurrentSession ( ( session ) => {
726
+ get ( ) . updateTargetSession ( session , ( session ) => {
723
727
session . lastSummarizeIndex = lastSummarizeIndex ;
724
728
session . memoryPrompt = message ; // Update the memory prompt for stored it in local storage
725
729
} ) ;
@@ -745,7 +749,16 @@ export const useChatStore = createPersistStore(
745
749
updater ( sessions [ index ] ) ;
746
750
set ( ( ) => ( { sessions } ) ) ;
747
751
} ,
748
-
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
+ } ,
749
762
async clearAllData ( ) {
750
763
await indexedDBStorage . clear ( ) ;
751
764
localStorage . clear ( ) ;
0 commit comments