@@ -550,7 +550,6 @@ class ChatStore {
550
550
await this . updateConversationName ( this . activeConversation . id , title ) ;
551
551
}
552
552
553
- const allMessages = await DatabaseStore . getConversationMessages ( this . activeConversation . id ) ;
554
553
const assistantMessage = await this . createAssistantMessage ( userMessage . id ) ;
555
554
556
555
if ( ! assistantMessage ) {
@@ -560,15 +559,23 @@ class ChatStore {
560
559
this . activeMessages . push ( assistantMessage ) ;
561
560
// Don't update currNode until after streaming completes to maintain proper conversation path
562
561
563
- await this . streamChatCompletion ( allMessages , assistantMessage , undefined , ( error : Error ) => {
564
- if ( error . name === 'ContextError' && userMessage ) {
565
- const userMessageIndex = this . findMessageIndex ( userMessage . id ) ;
566
- if ( userMessageIndex !== - 1 ) {
567
- this . activeMessages . splice ( userMessageIndex , 1 ) ;
568
- DatabaseStore . deleteMessage ( userMessage . id ) . catch ( console . error ) ;
562
+ const conversationContext = this . activeMessages . slice ( 0 , - 1 ) ;
563
+
564
+ await this . streamChatCompletion (
565
+ conversationContext ,
566
+ assistantMessage ,
567
+ undefined ,
568
+ ( error : Error ) => {
569
+ if ( error . name === 'ContextError' && userMessage ) {
570
+ const userMessageIndex = this . findMessageIndex ( userMessage . id ) ;
571
+
572
+ if ( userMessageIndex !== - 1 ) {
573
+ this . activeMessages . splice ( userMessageIndex , 1 ) ;
574
+ DatabaseStore . deleteMessage ( userMessage . id ) . catch ( console . error ) ;
575
+ }
569
576
}
570
577
}
571
- } ) ;
578
+ ) ;
572
579
} catch ( error ) {
573
580
if ( this . isAbortError ( error ) ) {
574
581
this . isLoading = false ;
@@ -810,7 +817,6 @@ class ChatStore {
810
817
this . currentResponse = '' ;
811
818
812
819
try {
813
- const allMessages = await DatabaseStore . getConversationMessages ( this . activeConversation . id ) ;
814
820
const assistantMessage = await this . createAssistantMessage ( ) ;
815
821
816
822
if ( ! assistantMessage ) {
@@ -821,7 +827,9 @@ class ChatStore {
821
827
await DatabaseStore . updateCurrentNode ( this . activeConversation . id , assistantMessage . id ) ;
822
828
this . activeConversation . currNode = assistantMessage . id ;
823
829
824
- await this . streamChatCompletion ( allMessages , assistantMessage ) ;
830
+ const conversationContext = this . activeMessages . slice ( 0 , - 1 ) ;
831
+
832
+ await this . streamChatCompletion ( conversationContext , assistantMessage ) ;
825
833
} catch ( regenerateError ) {
826
834
console . error ( 'Failed to regenerate response:' , regenerateError ) ;
827
835
this . isLoading = false ;
0 commit comments