Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/browser/utils/messages/StreamingMessageAggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1269,15 +1269,23 @@ export class StreamingMessageAggregator {
if (message) {
// If nested, update in parent's nestedCalls array
if (data.parentToolCallId) {
const parentPart = message.parts.find(
const parentIndex = message.parts.findIndex(
(part): part is DynamicToolPart =>
part.type === "dynamic-tool" && part.toolCallId === data.parentToolCallId
);
const parentPart = message.parts[parentIndex] as DynamicToolPart | undefined;
if (parentPart?.nestedCalls) {
const nestedCall = parentPart.nestedCalls.find((nc) => nc.toolCallId === data.toolCallId);
if (nestedCall) {
nestedCall.state = "output-available";
nestedCall.output = data.result;
const nestedIndex = parentPart.nestedCalls.findIndex(
(nc) => nc.toolCallId === data.toolCallId
);
if (nestedIndex !== -1) {
// Create new objects to trigger React re-render (immutable update pattern)
const updatedNestedCalls = parentPart.nestedCalls.map((nc, i) =>
i === nestedIndex
? { ...nc, state: "output-available" as const, output: data.result }
: nc
);
message.parts[parentIndex] = { ...parentPart, nestedCalls: updatedNestedCalls };
this.invalidateCache();
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/node/services/aiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,7 @@ export class AIService extends EventEmitter {
historySequence,
systemMessage,
runtime,
assistantMessageId, // Shared messageId ensures nested tool events match stream events
abortSignal,
tools,
{
Expand Down
5 changes: 5 additions & 0 deletions src/node/services/streamManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe("StreamManager - Concurrent Stream Prevention", () => {
1,
"You are a helpful assistant",
runtime,
"test-msg-1",
undefined,
{}
);
Expand All @@ -108,6 +109,7 @@ describe("StreamManager - Concurrent Stream Prevention", () => {
2,
"You are a helpful assistant",
runtime,
"test-msg-2",
undefined,
{}
);
Expand Down Expand Up @@ -280,6 +282,7 @@ describe("StreamManager - Concurrent Stream Prevention", () => {
1,
"system",
runtime,
"test-msg-1",
undefined,
{}
),
Expand All @@ -291,6 +294,7 @@ describe("StreamManager - Concurrent Stream Prevention", () => {
2,
"system",
runtime,
"test-msg-2",
undefined,
{}
),
Expand All @@ -302,6 +306,7 @@ describe("StreamManager - Concurrent Stream Prevention", () => {
3,
"system",
runtime,
"test-msg-3",
undefined,
{}
),
Expand Down
5 changes: 3 additions & 2 deletions src/node/services/streamManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ export class StreamManager extends EventEmitter {
abortSignal: AbortSignal | undefined,
system: string,
historySequence: number,
messageId: string,
tools?: Record<string, Tool>,
initialMetadata?: Partial<MuxMetadata>,
providerOptions?: Record<string, unknown>,
Expand Down Expand Up @@ -720,8 +721,6 @@ export class StreamManager extends EventEmitter {
throw error;
}

const messageId = `assistant-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;

const streamInfo: WorkspaceStreamInfo = {
state: StreamState.STARTING,
streamResult,
Expand Down Expand Up @@ -1512,6 +1511,7 @@ export class StreamManager extends EventEmitter {
historySequence: number,
system: string,
runtime: Runtime,
messageId: string,
abortSignal?: AbortSignal,
tools?: Record<string, Tool>,
initialMetadata?: Partial<MuxMetadata>,
Expand Down Expand Up @@ -1568,6 +1568,7 @@ export class StreamManager extends EventEmitter {
abortSignal,
system,
historySequence,
messageId,
tools,
initialMetadata,
providerOptions,
Expand Down
Loading