Skip to content

Commit cc95b9e

Browse files
committed
Revert "fix: multi message in single stream support"
This reverts commit 49a53f2.
1 parent 3cbeb7e commit cc95b9e

File tree

3 files changed

+4
-87
lines changed

3 files changed

+4
-87
lines changed

packages/ai/src/ui/chat.ts

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

packages/ai/src/ui/process-ui-message-stream-multi.test.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/ai/src/ui/process-ui-message-stream.ts

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ export type StreamingUIMessageState<UI_MESSAGE extends UIMessage> = {
3838
string,
3939
{ text: string; index: number; toolName: string; dynamic?: boolean }
4040
>;
41-
// Support for multiple messages in a single stream
42-
isFinalized?: boolean;
43-
messageQueue?: UI_MESSAGE[];
4441
};
4542

4643
export function createStreamingUIMessageState<UI_MESSAGE extends UIMessage>({
@@ -66,8 +63,6 @@ export function createStreamingUIMessageState<UI_MESSAGE extends UIMessage>({
6663
activeTextParts: {},
6764
activeReasoningParts: {},
6865
partialToolCalls: {},
69-
isFinalized: false,
70-
messageQueue: [],
7166
};
7267
}
7368

@@ -605,38 +600,12 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
605600
}
606601

607602
case 'start': {
608-
// Handle multiple messages in a single stream
609603
if (chunk.messageId != null) {
610-
// If current message is finalized, save it and create a new one
611-
if (state.isFinalized && state.message.parts.length > 0) {
612-
// Save the current message to the queue
613-
state.messageQueue!.push(state.message);
614-
615-
// Create a new message for the new messageId
616-
state.message = {
617-
id: chunk.messageId,
618-
metadata: chunk.messageMetadata as InferUIMessageMetadata<UI_MESSAGE>,
619-
role: 'assistant',
620-
parts: [] as UIMessagePart<
621-
InferUIMessageData<UI_MESSAGE>,
622-
InferUIMessageTools<UI_MESSAGE>
623-
>[],
624-
} as UI_MESSAGE;
625-
626-
// Reset state for the new message
627-
state.activeTextParts = {};
628-
state.activeReasoningParts = {};
629-
state.partialToolCalls = {};
630-
state.isFinalized = false;
631-
} else {
632-
// First message or updating existing message
633-
state.message.id = chunk.messageId;
634-
await updateMessageMetadata(chunk.messageMetadata);
635-
}
636-
} else {
637-
await updateMessageMetadata(chunk.messageMetadata);
604+
state.message.id = chunk.messageId;
638605
}
639606

607+
await updateMessageMetadata(chunk.messageMetadata);
608+
640609
if (chunk.messageId != null || chunk.messageMetadata != null) {
641610
write();
642611
}
@@ -648,8 +617,6 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
648617
if (chunk.messageMetadata != null) {
649618
write();
650619
}
651-
// Mark the current message as finalized for multi-message support
652-
state.isFinalized = true;
653620
break;
654621
}
655622

0 commit comments

Comments
 (0)