@@ -551,48 +551,15 @@ export abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
551551 // streaming is set on first write (before it should be "submitted")
552552 this . setStatus ( { status : 'streaming' } ) ;
553553
554- // Handle multiple messages in the queue
555- if ( activeResponse . state . messageQueue && activeResponse . state . messageQueue . length > 0 ) {
556- // Add all queued messages to the chat
557- for ( const queuedMessage of activeResponse . state . messageQueue ) {
558- const existingMessageIndex = this . state . messages . findIndex (
559- msg => msg . id === queuedMessage . id
560- ) ;
561-
562- if ( existingMessageIndex >= 0 ) {
563- // Update existing message
564- this . state . replaceMessage ( existingMessageIndex , queuedMessage ) ;
565- } else {
566- // Add new message
567- this . state . pushMessage ( queuedMessage ) ;
568- }
569- }
570- // Clear the queue after processing
571- activeResponse . state . messageQueue = [ ] ;
572- }
573-
574- // Handle the current message
575554 const replaceLastMessage =
576555 activeResponse . state . message . id === this . lastMessage ?. id ;
577556
578- const existingMessageIndex = this . state . messages . findIndex (
579- msg => msg . id === activeResponse . state . message . id
580- ) ;
581-
582- if ( existingMessageIndex >= 0 ) {
583- // Update existing message
584- this . state . replaceMessage (
585- existingMessageIndex ,
586- activeResponse . state . message ,
587- ) ;
588- } else if ( replaceLastMessage ) {
589- // Replace last message for backward compatibility
557+ if ( replaceLastMessage ) {
590558 this . state . replaceMessage (
591559 this . state . messages . length - 1 ,
592560 activeResponse . state . message ,
593561 ) ;
594562 } else {
595- // Add new message
596563 this . state . pushMessage ( activeResponse . state . message ) ;
597564 }
598565 } ,
@@ -616,22 +583,6 @@ export abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
616583 } ,
617584 } ) ;
618585
619- // Process any remaining messages in the queue after stream consumption
620- if ( activeResponse . state . messageQueue && activeResponse . state . messageQueue . length > 0 ) {
621- for ( const queuedMessage of activeResponse . state . messageQueue ) {
622- const existingMessageIndex = this . state . messages . findIndex (
623- msg => msg . id === queuedMessage . id
624- ) ;
625-
626- if ( existingMessageIndex >= 0 ) {
627- this . state . replaceMessage ( existingMessageIndex , queuedMessage ) ;
628- } else {
629- this . state . pushMessage ( queuedMessage ) ;
630- }
631- }
632- activeResponse . state . messageQueue = [ ] ;
633- }
634-
635586 this . setStatus ( { status : 'ready' } ) ;
636587 } catch ( err ) {
637588 // Ignore abort errors as they are expected.
0 commit comments