@assistant-ui/react-ag-ui 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/runtime/AgUiThreadController.d.ts +11 -0
- package/dist/runtime/AgUiThreadController.d.ts.map +1 -1
- package/dist/runtime/AgUiThreadController.js +212 -22
- package/dist/runtime/AgUiThreadController.js.map +1 -1
- package/dist/runtime/adapter/conversions.d.ts +9 -1
- package/dist/runtime/adapter/conversions.d.ts.map +1 -1
- package/dist/runtime/adapter/conversions.js +184 -9
- package/dist/runtime/adapter/conversions.js.map +1 -1
- package/dist/runtime/adapter/run-aggregator.d.ts +1 -0
- package/dist/runtime/adapter/run-aggregator.d.ts.map +1 -1
- package/dist/runtime/adapter/run-aggregator.js +34 -12
- package/dist/runtime/adapter/run-aggregator.js.map +1 -1
- package/dist/runtime/adapter/subscriber.d.ts +0 -1
- package/dist/runtime/adapter/subscriber.d.ts.map +1 -1
- package/dist/runtime/adapter/subscriber.js +1 -8
- package/dist/runtime/adapter/subscriber.js.map +1 -1
- package/dist/runtime/event-parser.d.ts.map +1 -1
- package/dist/runtime/event-parser.js +1 -0
- package/dist/runtime/event-parser.js.map +1 -1
- package/dist/runtime/types.d.ts +2 -0
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/types.js +2 -1
- package/dist/runtime/types.js.map +1 -1
- package/package.json +5 -5
- package/src/runtime/AgUiThreadController.disconnect.test.ts +914 -0
- package/src/runtime/AgUiThreadController.interrupt-history.test.ts +392 -0
- package/src/runtime/AgUiThreadController.replay.test.ts +8 -1
- package/src/runtime/AgUiThreadController.snapshot-head-move.test.ts +167 -0
- package/src/runtime/AgUiThreadController.subagent-snapshot.test.ts +854 -0
- package/src/runtime/AgUiThreadController.test.ts +40 -0
- package/src/runtime/AgUiThreadController.ts +459 -27
- package/src/runtime/adapter/conversions.content.test.ts +129 -0
- package/src/runtime/adapter/conversions.subagent-messages.test.ts +550 -0
- package/src/runtime/adapter/conversions.ts +331 -20
- package/src/runtime/adapter/run-aggregator.metadata.test.ts +151 -0
- package/src/runtime/adapter/run-aggregator.ts +52 -9
- package/src/runtime/adapter/subscriber.test.ts +1 -1
- package/src/runtime/adapter/subscriber.ts +1 -6
- package/src/runtime/event-parser.ts +3 -0
- package/src/runtime/types.ts +5 -0
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import { readMcpAppResourceUri, toolContentText } from "../mcp-tool-result.js";
|
|
3
3
|
import { AG_UI_METADATA_NAMESPACE } from "../types.js";
|
|
4
4
|
import { projectAgUiToolApprovals } from "./tool-approval.js";
|
|
5
|
+
import { withAgUiPartMessageMetadata } from "./conversions.js";
|
|
5
6
|
import { isMcpAppUri } from "@assistant-ui/core";
|
|
6
7
|
import jsonpatch from "fast-json-patch";
|
|
7
8
|
import { applyA2uiOperations, surfaceToPresentToolCall } from "@assistant-ui/generative-ui/a2ui";
|
|
8
9
|
// src/runtime/adapter/run-aggregator.ts
|
|
9
10
|
const ROOT_SCOPE = "";
|
|
10
|
-
const MAX_SUBAGENT_DEPTH = 16;
|
|
11
11
|
const createJSONContainerScanner = () => ({
|
|
12
12
|
state: "pending",
|
|
13
13
|
stack: [],
|
|
@@ -84,6 +84,7 @@ var RunAggregator = class {
|
|
|
84
84
|
interrupts;
|
|
85
85
|
pendingToolCallIds;
|
|
86
86
|
textParts = /* @__PURE__ */ new Map();
|
|
87
|
+
pendingSnapshotText = /* @__PURE__ */ new Map();
|
|
87
88
|
activeTextMessageIdByScope = /* @__PURE__ */ new Map();
|
|
88
89
|
reasoningParts = /* @__PURE__ */ new Map();
|
|
89
90
|
reasoningSignatures = /* @__PURE__ */ new Map();
|
|
@@ -138,6 +139,15 @@ var RunAggregator = class {
|
|
|
138
139
|
this.status = { type: "running" };
|
|
139
140
|
this.emit();
|
|
140
141
|
break;
|
|
142
|
+
case "MESSAGES_SNAPSHOT":
|
|
143
|
+
this.pendingSnapshotText.clear();
|
|
144
|
+
for (const message of event.messages) {
|
|
145
|
+
if (message.role !== "assistant" || typeof message.content !== "string") continue;
|
|
146
|
+
const part = this.textParts.get(message.id);
|
|
147
|
+
if (part) part.buffer = message.content;
|
|
148
|
+
else this.pendingSnapshotText.set(message.id, message.content);
|
|
149
|
+
}
|
|
150
|
+
break;
|
|
141
151
|
case "RUN_FINISHED": {
|
|
142
152
|
if (event.outcome?.type === "cancelled") {
|
|
143
153
|
this.interrupts = void 0;
|
|
@@ -209,7 +219,7 @@ var RunAggregator = class {
|
|
|
209
219
|
const incomingId = event.messageId;
|
|
210
220
|
const scope = this.scopeOf(event);
|
|
211
221
|
if (scope === ROOT_SCOPE) {
|
|
212
|
-
this.beginDistinctTextMessage(incomingId);
|
|
222
|
+
this.beginDistinctTextMessage(incomingId, true);
|
|
213
223
|
this.reportServerMessageId(incomingId);
|
|
214
224
|
if (incomingId) this.lastTextMessageId = incomingId;
|
|
215
225
|
}
|
|
@@ -282,7 +292,7 @@ var RunAggregator = class {
|
|
|
282
292
|
this.emit();
|
|
283
293
|
break;
|
|
284
294
|
case "TOOL_CALL_RESULT":
|
|
285
|
-
this.finishToolCall(this.scopeOf(event), event.toolCallId, event.content ?? "", typeof event.mcpResult?.isError === "boolean" ? event.mcpResult.isError : event.role === "tool" ? false : void 0, event.messageId, event.mcpResult);
|
|
295
|
+
this.finishToolCall(this.scopeOf(event), event.toolCallId, event.content ?? "", typeof event.mcpResult?.isError === "boolean" ? event.mcpResult.isError : event.role === "tool" ? false : void 0, event.messageId, event.mcpResult, event.metadata);
|
|
286
296
|
this.emit();
|
|
287
297
|
break;
|
|
288
298
|
case "ACTIVITY_SNAPSHOT": {
|
|
@@ -485,6 +495,7 @@ var RunAggregator = class {
|
|
|
485
495
|
}
|
|
486
496
|
resetMessageParts() {
|
|
487
497
|
this.clearTextParts();
|
|
498
|
+
this.pendingSnapshotText.clear();
|
|
488
499
|
this.reasoningParts.clear();
|
|
489
500
|
this.reasoningSignatures.clear();
|
|
490
501
|
this.reasoningSignatureIds.clear();
|
|
@@ -518,12 +529,14 @@ var RunAggregator = class {
|
|
|
518
529
|
partKey(scope, id) {
|
|
519
530
|
return scope === ROOT_SCOPE ? id : `${scope}\u0000${id}`;
|
|
520
531
|
}
|
|
521
|
-
beginDistinctTextMessage(messageId) {
|
|
532
|
+
beginDistinctTextMessage(messageId, preserveSnapshotText = false) {
|
|
522
533
|
if (this.joinStrategy === "concat-content" || !messageId || this.lastTextMessageId === void 0 || this.lastTextMessageId === messageId || !this.onTextMessageStart) return;
|
|
523
534
|
const carried = this.takeTrailingReasoning();
|
|
524
535
|
if (carried.parts.length > 0 || carried.hiddenSignatures.length > 0) this.emit();
|
|
525
536
|
const openToolCallIds = Array.from(this.toolCalls.values()).filter((call) => call.result === void 0).map((call) => call.toolCallId);
|
|
537
|
+
const snapshotText = preserveSnapshotText ? this.pendingSnapshotText.get(messageId) : void 0;
|
|
526
538
|
this.resetMessageParts();
|
|
539
|
+
if (snapshotText !== void 0) this.pendingSnapshotText.set(messageId, snapshotText);
|
|
527
540
|
this.onTextMessageStart(messageId, openToolCallIds);
|
|
528
541
|
this.restoreReasoning(carried);
|
|
529
542
|
}
|
|
@@ -586,15 +599,19 @@ var RunAggregator = class {
|
|
|
586
599
|
startTextMessage(scope, messageId) {
|
|
587
600
|
const id = messageId ?? this.generateTextKey();
|
|
588
601
|
const key = this.ensureTextPart(scope, id);
|
|
602
|
+
if (scope === ROOT_SCOPE && messageId) {
|
|
603
|
+
const snapshotText = this.pendingSnapshotText.get(messageId);
|
|
604
|
+
const part = this.textParts.get(key);
|
|
605
|
+
if (snapshotText !== void 0 && part) {
|
|
606
|
+
part.buffer = snapshotText;
|
|
607
|
+
this.pendingSnapshotText.delete(messageId);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
589
610
|
this.activeTextMessageIdByScope.set(scope, key);
|
|
590
611
|
return key;
|
|
591
612
|
}
|
|
592
613
|
resolveTextMessageId(scope, messageId) {
|
|
593
|
-
if (messageId)
|
|
594
|
-
const key = this.ensureTextPart(scope, messageId);
|
|
595
|
-
this.activeTextMessageIdByScope.set(scope, key);
|
|
596
|
-
return key;
|
|
597
|
-
}
|
|
614
|
+
if (messageId) return this.startTextMessage(scope, messageId);
|
|
598
615
|
const active = this.activeTextMessageIdByScope.get(scope);
|
|
599
616
|
if (active) return active;
|
|
600
617
|
const key = this.ensureTextPart(scope, this.generateTextKey());
|
|
@@ -683,7 +700,7 @@ var RunAggregator = class {
|
|
|
683
700
|
entry.parsedArgs = void 0;
|
|
684
701
|
}
|
|
685
702
|
}
|
|
686
|
-
finishToolCall(scope, id, content, isError, toolMessageId, mcpResult) {
|
|
703
|
+
finishToolCall(scope, id, content, isError, toolMessageId, mcpResult, metadata) {
|
|
687
704
|
if (!id) return;
|
|
688
705
|
const modelText = toolContentText(content);
|
|
689
706
|
let entry = this.toolCalls.get(id);
|
|
@@ -729,6 +746,10 @@ var RunAggregator = class {
|
|
|
729
746
|
entry.isError = isError;
|
|
730
747
|
}
|
|
731
748
|
if (toolMessageId) entry.toolMessageId = toolMessageId;
|
|
749
|
+
if (metadata !== void 0) entry.resultMetadata = {
|
|
750
|
+
...entry.resultMetadata,
|
|
751
|
+
...metadata
|
|
752
|
+
};
|
|
732
753
|
this.lastResolvedToolCallIdByScope.set(scope, id);
|
|
733
754
|
}
|
|
734
755
|
nesting() {
|
|
@@ -754,7 +775,7 @@ var RunAggregator = class {
|
|
|
754
775
|
reachableSubagentRunIds(subagentsByParentToolCallId) {
|
|
755
776
|
const reachable = /* @__PURE__ */ new Set();
|
|
756
777
|
const walk = (scope, depth) => {
|
|
757
|
-
if (depth >
|
|
778
|
+
if (depth > 16) return;
|
|
758
779
|
for (const entry of this.toolCalls.values()) {
|
|
759
780
|
if ((entry.subagentRunId ?? ROOT_SCOPE) !== scope) continue;
|
|
760
781
|
for (const id of subagentsByParentToolCallId.get(entry.toolCallId) ?? []) {
|
|
@@ -769,7 +790,7 @@ var RunAggregator = class {
|
|
|
769
790
|
}
|
|
770
791
|
materializeSubagentMessage(subagentRunId, depth, ctx) {
|
|
771
792
|
const run = this.subagentRuns.get(subagentRunId);
|
|
772
|
-
if (!run || depth >
|
|
793
|
+
if (!run || depth > 16) return void 0;
|
|
773
794
|
const content = this.buildParts(subagentRunId, depth + 1, ctx);
|
|
774
795
|
return {
|
|
775
796
|
id: run.subagentRunId,
|
|
@@ -822,6 +843,7 @@ var RunAggregator = class {
|
|
|
822
843
|
} } } : {},
|
|
823
844
|
...entry.parentMessageId ? { parentId: entry.parentMessageId } : {},
|
|
824
845
|
...entry.toolMessageId ? { unstable_toolMessageId: entry.toolMessageId } : {},
|
|
846
|
+
...entry.resultMetadata !== void 0 ? { providerMetadata: withAgUiPartMessageMetadata(void 0, entry.resultMetadata) } : {},
|
|
825
847
|
...nestedMessages.length > 0 ? { messages: nestedMessages } : {}
|
|
826
848
|
};
|
|
827
849
|
snapshot.push(toolPart);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-aggregator.js","names":[],"sources":["../../../src/runtime/adapter/run-aggregator.ts"],"sourcesContent":["\"use client\";\n\nimport {\n isMcpAppUri,\n type ChatModelRunResult,\n type MessagePartTiming,\n type MessageStatus,\n type MessageTiming,\n type ThreadAssistantMessagePart,\n type ThreadMessage,\n type ToolCallMessagePart,\n type ToolModelContentPart,\n} from \"@assistant-ui/core\";\nimport type { JoinStrategy } from \"@assistant-ui/core/react\";\nimport type { ContentPart } from \"@ag-ui/client\";\nimport {\n applyA2uiOperations,\n surfaceToPresentToolCall,\n type A2uiState,\n type A2uiSurfaceState,\n} from \"@assistant-ui/generative-ui/a2ui\";\nimport jsonpatch, { type Operation } from \"fast-json-patch\";\nimport { readMcpAppResourceUri, toolContentText } from \"../mcp-tool-result\";\nimport { projectAgUiToolApprovals } from \"./tool-approval\";\nimport {\n AG_UI_METADATA_NAMESPACE,\n A2UI_SURFACE_ACTIVITY_TYPE,\n MCP_APPS_ACTIVITY_TYPE,\n type AgUiCustomMetadata,\n type AgUiEvent,\n type AgUiInterrupt,\n type AgUiOpaqueReasoning,\n} from \"../types\";\nimport type { Logger } from \"../logger\";\n\nconst ROOT_SCOPE = \"\";\n\n// Defensive guard against a malformed or cyclic parentToolCallId /\n// parentSubagentRunId chain, not a realistic nesting depth.\nconst MAX_SUBAGENT_DEPTH = 16;\n\ntype SubagentRunState = {\n subagentRunId: string;\n name: string;\n description?: string;\n parentSubagentRunId?: string;\n parentToolCallId?: string;\n parentMessageId?: string;\n createdAt: Date;\n status: MessageStatus;\n result?: unknown;\n interruptIds?: string[];\n errorCode?: string;\n};\n\ntype ToolApproval = NonNullable<ToolCallMessagePart[\"approval\"]>;\n\ntype PartOrderEntry =\n | { kind: \"text\"; key: string; subagentRunId?: string }\n | { kind: \"reasoning\"; key: string; subagentRunId?: string }\n | { kind: \"tool-call\"; toolCallId: string }\n | { kind: \"data\"; name: string; value: unknown; subagentRunId?: string };\n\ntype BuildContext = {\n subagentsByParentToolCallId: Map<string, string[]>;\n reachable: Set<string>;\n approvals: ReadonlyMap<string, ToolApproval>;\n // partOrder bucketed by the scope each part renders in, so one emit walks\n // every part once however many subagents the run spawned.\n partsByScope: Map<string, { index: number; part: PartOrderEntry }[]>;\n // Present only for the root walk: the pass that builds the snapshot is also\n // the one that decides where a retracted reasoning signature anchors, so the\n // two can never disagree about what materialized.\n root?: {\n opaqueCandidates: (AgUiOpaqueReasoning & { anchor: number })[];\n lastMaterializedIndex: number;\n };\n};\n\ntype Emit = (update: ChatModelRunResult) => void;\n\ntype ToolCallState = {\n toolCallId: string;\n toolCallName: string;\n argsText: string;\n argsTextScanner?: JSONContainerScanner | undefined;\n parsedArgs: Record<string, unknown> | undefined;\n result: unknown;\n isError: boolean | undefined;\n parentMessageId?: string;\n toolMessageId?: string;\n mcpAppResourceUri?: string;\n mcpAppServerId?: string;\n artifact?: unknown;\n modelContent?: ToolModelContentPart[];\n snapshotResultApplied: boolean;\n subagentRunId?: string;\n};\n\ntype JSONContainerScanner = {\n state: \"pending\" | \"open\" | \"complete\" | \"invalid\";\n stack: (\"{\" | \"[\")[];\n inString: boolean;\n escaped: boolean;\n};\n\nconst createJSONContainerScanner = (): JSONContainerScanner => ({\n state: \"pending\",\n stack: [],\n inString: false,\n escaped: false,\n});\n\nconst isJSONWhitespace = (char: string): boolean =>\n char === \" \" || char === \"\\t\" || char === \"\\n\" || char === \"\\r\";\n\nconst scanJSONContainerDelta = (\n scanner: JSONContainerScanner,\n delta: string,\n): boolean => {\n let completed = false;\n\n for (const char of delta) {\n if (scanner.state === \"invalid\") continue;\n if (scanner.state === \"complete\") {\n if (isJSONWhitespace(char)) continue;\n scanner.state = \"invalid\";\n continue;\n }\n if (scanner.state === \"pending\") {\n if (isJSONWhitespace(char)) continue;\n if (char !== \"{\" && char !== \"[\") {\n scanner.state = \"invalid\";\n continue;\n }\n scanner.state = \"open\";\n scanner.stack.push(char);\n continue;\n }\n if (scanner.inString) {\n if (scanner.escaped) {\n scanner.escaped = false;\n } else if (char === \"\\\\\") {\n scanner.escaped = true;\n } else if (char === '\"') {\n scanner.inString = false;\n }\n continue;\n }\n if (char === '\"') {\n scanner.inString = true;\n continue;\n }\n if (char === \"{\" || char === \"[\") {\n scanner.stack.push(char);\n continue;\n }\n if (char === \"}\" || char === \"]\") {\n const expected = char === \"}\" ? \"{\" : \"[\";\n if (scanner.stack.pop() !== expected) {\n scanner.state = \"invalid\";\n continue;\n }\n if (scanner.stack.length === 0) {\n scanner.state = \"complete\";\n completed = true;\n }\n }\n }\n\n return completed && scanner.state === \"complete\";\n};\n\nexport const isPlainObject = (\n value: unknown,\n): value is Record<string, unknown> =>\n !!value && typeof value === \"object\" && !Array.isArray(value);\n\nexport type RunAggregatorOptions = {\n showThinking: boolean;\n joinStrategy?: JoinStrategy | undefined;\n logger: Logger;\n emit: Emit;\n onServerMessageId?: (messageId: string) => void;\n onTextMessageStart?: (messageId: string, openToolCallIds: string[]) => void;\n};\n\n/**\n * Collects AG-UI events into assistant-ui run snapshots that can be yielded from a ChatModelAdapter.\n *\n * The aggregator keeps a single assistant message worth of parts. Each incoming event updates the parts and\n * emits a fresh snapshot through the provided `emit` callback. `CUSTOM` events\n * become canonical data parts; integration plumbing names such as\n * `on_interrupt`, `PredictState`, `Exit`, `hook_error`, `state_update_error`,\n * `system:*`, and `MultiAgentHandoff` are forwarded the same way, so apps only\n * need data renderers for names they own.\n */\nexport class RunAggregator {\n private readonly emitUpdate: Emit;\n private readonly showThinking: boolean;\n private readonly joinStrategy: JoinStrategy | undefined;\n private readonly logger: Logger;\n private readonly onServerMessageId: ((messageId: string) => void) | undefined;\n private readonly onTextMessageStart:\n | ((messageId: string, openToolCallIds: string[]) => void)\n | undefined;\n\n private status: ChatModelRunResult[\"status\"] | undefined;\n private interrupts: AgUiInterrupt[] | undefined;\n private pendingToolCallIds: string[] | undefined;\n private readonly textParts = new Map<string, { buffer: string }>();\n private readonly activeTextMessageIdByScope = new Map<string, string>();\n private readonly reasoningParts = new Map<\n string,\n { buffer: string; timing?: MessagePartTiming }\n >();\n private readonly reasoningSignatures = new Map<string, string>();\n private readonly reasoningSignatureIds = new Map<string, string>();\n private readonly hiddenSignatures = new Map<string, string>();\n private readonly hiddenSignatureAnchors = new Map<string, number>();\n private readonly hiddenBlockAnchors = new Map<string, number>();\n private readonly hiddenReasoningIds = new Set<string>();\n private hiddenActiveReasoningId: string | undefined;\n private hasEmittedOpaqueReasoning = false;\n private readonly loggedDroppedOpaqueIds = new Set<string>();\n private readonly reasoningMessageIds = new Map<string, string>();\n private readonly activeReasoningKeyByScope = new Map<string, string>();\n private readonly subagentRuns = new Map<string, SubagentRunState>();\n // The nesting graph only moves when a run is announced or a tool call is\n // created, which is rare next to emit(), so it is derived once per change\n // rather than per streamed delta.\n private nestingMemo:\n | {\n subagentsByParentToolCallId: Map<string, string[]>;\n reachable: Set<string>;\n }\n | undefined;\n private readonly toolCalls = new Map<string, ToolCallState>();\n private readonly a2uiBuckets = new Map<string, A2uiState>();\n private readonly a2uiToolCallIds = new Set<string>();\n private readonly activityParts = new Map<\n string,\n { kind: \"data\"; name: string; value: unknown; subagentRunId?: string }\n >();\n private readonly lastResolvedToolCallIdByScope = new Map<string, string>();\n private readonly partOrder: PartOrderEntry[] = [];\n private lastReasoningBeforeToolCall: PartOrderEntry | undefined;\n private textPartCounter = 0;\n private serverMessageIdReported = false;\n private reportedServerMessageId: string | undefined;\n private lastTextMessageId: string | undefined;\n\n private streamStartTime: number | undefined;\n private firstTokenTime: number | undefined;\n private totalChunks = 0;\n\n constructor(options: RunAggregatorOptions) {\n this.emitUpdate = options.emit;\n this.showThinking = options.showThinking;\n this.joinStrategy = options.joinStrategy;\n this.logger = options.logger;\n this.onServerMessageId = options.onServerMessageId;\n this.onTextMessageStart = options.onTextMessageStart;\n }\n\n hasToolCall(toolCallId: string): boolean {\n return this.toolCalls.has(toolCallId);\n }\n\n handle(event: AgUiEvent): void {\n switch (event.type) {\n case \"RUN_STARTED\": {\n this.resetMessageParts();\n this.interrupts = undefined;\n this.serverMessageIdReported = false;\n this.lastTextMessageId = undefined;\n this.reportedServerMessageId = undefined;\n this.streamStartTime = Date.now();\n this.firstTokenTime = undefined;\n this.totalChunks = 0;\n this.status = { type: \"running\" };\n this.emit();\n break;\n }\n case \"RUN_FINISHED\": {\n if (event.outcome?.type === \"cancelled\") {\n this.interrupts = undefined;\n this.status = { type: \"incomplete\", reason: \"cancelled\" };\n this.closeOpenSubagentRuns(this.status);\n this.emit();\n break;\n }\n if (event.outcome?.type === \"interrupt\") {\n this.interrupts = event.outcome.interrupts;\n this.status = { type: \"requires-action\", reason: \"interrupt\" };\n this.emit();\n break;\n }\n\n this.interrupts = undefined;\n // A call nested inside a subagent message is answerable the same way\n // a root call is: getPendingToolCalls and addToolResult walk\n // ToolCallMessagePart.messages, so any unresolved call keeps the run\n // resumable.\n const pendingToolCallIds =\n event.outcome?.type === \"success\"\n ? event.outcome.pendingToolCallIds\n : undefined;\n const hasUnresolvedToolCalls =\n pendingToolCallIds && pendingToolCallIds.length > 0\n ? pendingToolCallIds.some((id) => {\n const call = this.toolCalls.get(id);\n return call !== undefined && call.result === undefined;\n })\n : Array.from(this.toolCalls.values()).some(\n (tc) => tc.result === undefined,\n );\n\n this.status = hasUnresolvedToolCalls\n ? { type: \"requires-action\", reason: \"tool-calls\" }\n : { type: \"complete\", reason: \"unknown\" };\n this.pendingToolCallIds =\n hasUnresolvedToolCalls && pendingToolCallIds?.length\n ? pendingToolCallIds\n : undefined;\n this.closeOpenSubagentRuns(this.status);\n this.emit();\n break;\n }\n case \"RUN_ERROR\": {\n this.status = {\n type: \"incomplete\",\n reason: \"error\",\n ...(event.message !== undefined ? { error: event.message } : {}),\n };\n this.closeOpenSubagentRuns(this.status);\n this.emit();\n break;\n }\n case \"RUN_CANCELLED\": {\n // A cancel can land after RUN_FINISHED while the response is still\n // closing: the finished answer stays complete, and an interrupt the run\n // already delivered stays answerable.\n if (\n this.status?.type === \"complete\" ||\n (this.status?.type === \"requires-action\" &&\n this.status.reason === \"interrupt\")\n )\n break;\n this.status = { type: \"incomplete\", reason: \"cancelled\" };\n this.closeOpenSubagentRuns(this.status);\n this.emit();\n break;\n }\n\n case \"TEXT_MESSAGE_START\": {\n const scope = this.scopeOf(event);\n if (scope === ROOT_SCOPE) {\n this.beginDistinctTextMessage(event.messageId);\n this.reportServerMessageId(event.messageId);\n if (event.messageId) this.lastTextMessageId = event.messageId;\n }\n this.startTextMessage(scope, event.messageId);\n this.emit();\n break;\n }\n case \"TEXT_MESSAGE_CONTENT\": {\n const incomingId = event.messageId;\n const scope = this.scopeOf(event);\n if (scope === ROOT_SCOPE) {\n this.beginDistinctTextMessage(incomingId);\n this.reportServerMessageId(incomingId);\n if (incomingId) this.lastTextMessageId = incomingId;\n }\n if (!event.delta) break;\n this.recordFirstToken();\n const id = this.resolveTextMessageId(scope, incomingId);\n this.appendText(id, event.delta);\n this.totalChunks++;\n this.emit();\n break;\n }\n case \"TEXT_MESSAGE_END\": {\n const scope = this.scopeOf(event);\n if (scope === ROOT_SCOPE) this.reportServerMessageId(event.messageId);\n if (\n event.messageId &&\n this.activeTextMessageIdByScope.get(scope) ===\n this.partKey(scope, event.messageId)\n ) {\n this.activeTextMessageIdByScope.delete(scope);\n }\n this.emit();\n break;\n }\n\n case \"CUSTOM\": {\n this.activeTextMessageIdByScope.delete(ROOT_SCOPE);\n this.partOrder.push({\n kind: \"data\",\n name: event.name,\n value: event.value,\n });\n this.emit();\n break;\n }\n\n case \"REASONING_START\":\n case \"REASONING_MESSAGE_START\":\n this.handleReasoningStart(\n this.scopeOf(event),\n event.messageId,\n event.type === \"REASONING_MESSAGE_START\",\n event.timestamp,\n );\n break;\n case \"REASONING_ENCRYPTED_VALUE\":\n if (event.subtype === \"message\") {\n const scope = this.scopeOf(event);\n const entityKey = this.partKey(scope, event.entityId);\n const key =\n this.showThinking && this.reasoningParts.has(entityKey)\n ? entityKey\n : undefined;\n if (key !== undefined) {\n this.reasoningSignatures.set(key, event.encryptedValue);\n this.reasoningSignatureIds.set(key, event.entityId);\n this.emit();\n } else if (\n !this.showThinking &&\n scope === ROOT_SCOPE &&\n event.entityId.trim().length > 0 &&\n event.encryptedValue.trim().length > 0 &&\n this.hiddenReasoningIds.has(event.entityId)\n ) {\n this.hiddenSignatures.set(event.entityId, event.encryptedValue);\n this.hiddenSignatureAnchors.set(\n event.entityId,\n this.hiddenBlockAnchors.get(event.entityId) ??\n this.partOrder.length,\n );\n this.emit();\n }\n }\n break;\n case \"REASONING_MESSAGE_CONTENT\":\n this.handleReasoningContent(\n this.scopeOf(event),\n event.delta,\n event.messageId,\n true,\n );\n this.totalChunks++;\n this.recordFirstToken();\n break;\n case \"REASONING_MESSAGE_END\":\n case \"REASONING_END\":\n this.handleReasoningEnd(this.scopeOf(event), event.timestamp);\n break;\n\n case \"TOOL_CALL_START\": {\n const scope = this.scopeOf(event);\n if (scope === ROOT_SCOPE) {\n this.reportServerMessageId(event.parentMessageId);\n }\n this.startToolCall(\n scope,\n event.toolCallId,\n event.toolCallName,\n event.parentMessageId,\n );\n this.emit();\n break;\n }\n case \"TOOL_CALL_ARGS\": {\n if (!event.delta) break;\n this.appendToolArgs(event.toolCallId, event.delta);\n this.emit();\n break;\n }\n case \"TOOL_CALL_END\": {\n this.emit();\n break;\n }\n case \"TOOL_CALL_RESULT\": {\n this.finishToolCall(\n this.scopeOf(event),\n event.toolCallId,\n event.content ?? \"\",\n typeof event.mcpResult?.isError === \"boolean\"\n ? event.mcpResult.isError\n : event.role === \"tool\"\n ? false\n : undefined,\n event.messageId,\n event.mcpResult,\n );\n this.emit();\n break;\n }\n case \"ACTIVITY_SNAPSHOT\": {\n if (event.activityType === A2UI_SURFACE_ACTIVITY_TYPE) {\n this.handleA2uiActivitySnapshot(event);\n break;\n }\n if (event.activityType !== MCP_APPS_ACTIVITY_TYPE) {\n this.handleActivitySnapshot(event);\n break;\n }\n const activityScope = this.scopeOf(event);\n const toolCallId = event.content.toolCallId;\n const fallbackId =\n this.lastResolvedToolCallIdByScope.get(activityScope);\n const entry =\n typeof toolCallId === \"string\"\n ? this.toolCalls.get(toolCallId)\n : fallbackId\n ? this.toolCalls.get(fallbackId)\n : undefined;\n const resourceUri = event.content.resourceUri;\n if (\n entry &&\n typeof resourceUri === \"string\" &&\n isMcpAppUri(resourceUri)\n ) {\n entry.mcpAppResourceUri = resourceUri;\n const id = event.content.serverId;\n const hash = event.content.serverHash;\n if (typeof id === \"string\" && id.length > 0) {\n entry.mcpAppServerId = id;\n } else if (typeof hash === \"string\" && hash.length > 0) {\n entry.mcpAppServerId = hash;\n }\n const result = event.content.result;\n if (isPlainObject(result)) {\n if (\n entry.result !== undefined &&\n entry.modelContent === undefined\n ) {\n entry.modelContent = [\n {\n type: \"text\",\n text:\n typeof entry.result === \"string\"\n ? entry.result\n : JSON.stringify(entry.result),\n },\n ];\n }\n entry.result = result;\n entry.snapshotResultApplied = true;\n if (typeof result.isError === \"boolean\") {\n entry.isError = result.isError;\n }\n }\n this.emit();\n }\n break;\n }\n\n case \"SUBAGENT_STARTED\": {\n // A suspended subagent is re-announced with the same id on resume, so\n // a repeat is a continuation: it may refresh the descriptive fields\n // and reopen the status, but re-parenting an established run would\n // move its already-rendered output to a different tool call.\n const existing = this.subagentRuns.get(event.subagentRunId);\n if (existing) {\n existing.name = event.name;\n if (event.description !== undefined)\n existing.description = event.description;\n existing.status = { type: \"running\" };\n this.emit();\n break;\n }\n this.nestingMemo = undefined;\n this.subagentRuns.set(event.subagentRunId, {\n subagentRunId: event.subagentRunId,\n name: event.name,\n ...(event.description !== undefined\n ? { description: event.description }\n : {}),\n ...(event.parentSubagentRunId !== undefined\n ? { parentSubagentRunId: event.parentSubagentRunId }\n : {}),\n ...(event.parentToolCallId !== undefined\n ? { parentToolCallId: event.parentToolCallId }\n : {}),\n ...(event.parentMessageId !== undefined\n ? { parentMessageId: event.parentMessageId }\n : {}),\n createdAt: new Date(),\n status: { type: \"running\" },\n });\n this.emit();\n break;\n }\n case \"SUBAGENT_FINISHED\": {\n const run = this.subagentRuns.get(event.subagentRunId);\n if (run) {\n run.status =\n event.outcome?.type === \"suspended\"\n ? { type: \"requires-action\", reason: \"interrupt\" }\n : { type: \"complete\", reason: \"unknown\" };\n if (event.result !== undefined) run.result = event.result;\n if (event.outcome?.type === \"suspended\" && event.outcome.interruptIds)\n run.interruptIds = event.outcome.interruptIds;\n }\n this.emit();\n break;\n }\n case \"SUBAGENT_ERROR\": {\n const run = this.subagentRuns.get(event.subagentRunId);\n if (run) {\n run.status = {\n type: \"incomplete\",\n reason: \"error\",\n ...(event.message !== undefined ? { error: event.message } : {}),\n };\n if (event.code !== undefined) run.errorCode = event.code;\n }\n this.emit();\n break;\n }\n\n case \"ACTIVITY_DELTA\": {\n this.handleActivityDelta(event);\n break;\n }\n\n default: {\n this.logger.debug?.(\"[agui] aggregator ignored event\", event);\n }\n }\n }\n\n private handleActivityDelta(\n event: Extract<AgUiEvent, { type: \"ACTIVITY_DELTA\" }>,\n ): void {\n const scope = this.scopeOf(event);\n const existing = this.activityParts.get(\n this.partKey(scope, `message:${event.messageId}`),\n );\n if (!existing) {\n this.logger.debug?.(\"[agui] activity delta has no snapshot\", event);\n return;\n }\n if (event.patch.length === 0) return;\n try {\n const result = jsonpatch.applyPatch(\n existing.value,\n event.patch as Operation[],\n /* validateOperation */ true,\n /* mutateDocument */ false,\n );\n if (!isPlainObject(result.newDocument)) {\n this.logger.debug?.(\n \"[agui] activity delta produced non-object content\",\n event,\n );\n return;\n }\n existing.name = `agui-activity/${event.activityType}`;\n existing.value = result.newDocument;\n this.emit();\n } catch (error) {\n this.logger.error?.(\"[agui] failed to apply activity delta\", error);\n }\n }\n\n private handleA2uiActivitySnapshot(\n event: Extract<AgUiEvent, { type: \"ACTIVITY_SNAPSHOT\" }>,\n ): void {\n const operations = event.content[\"a2ui_operations\"];\n if (!Array.isArray(operations)) return;\n\n const messageId = event.messageId ?? \"a2ui:anonymous\";\n if (event.replace === false && this.a2uiBuckets.has(messageId)) return;\n\n const { state, warnings } = applyA2uiOperations(new Map(), operations);\n for (const warning of warnings) {\n this.logger.debug(\"[agui] a2ui operation warning\", warning);\n }\n this.a2uiBuckets.delete(messageId);\n this.a2uiBuckets.set(messageId, state);\n this.synthesizeA2uiToolCalls();\n this.emit();\n }\n\n private handleActivitySnapshot(\n event: Extract<AgUiEvent, { type: \"ACTIVITY_SNAPSHOT\" }>,\n ): void {\n const scope = this.scopeOf(event);\n const key = this.partKey(\n scope,\n event.messageId !== undefined\n ? `message:${event.messageId}`\n : `type:${event.activityType}`,\n );\n const existing = this.activityParts.get(key);\n if (existing) {\n if (event.replace === false) return;\n existing.name = `agui-activity/${event.activityType}`;\n existing.value = event.content;\n } else {\n const part =\n scope === ROOT_SCOPE\n ? {\n kind: \"data\" as const,\n name: `agui-activity/${event.activityType}`,\n value: event.content,\n }\n : {\n kind: \"data\" as const,\n name: `agui-activity/${event.activityType}`,\n value: event.content,\n subagentRunId: scope,\n };\n this.activityParts.set(key, part);\n this.partOrder.push(part);\n this.activeTextMessageIdByScope.delete(scope);\n }\n this.emit();\n }\n\n private synthesizeA2uiToolCalls(): void {\n const surfaces = new Map<string, A2uiSurfaceState>();\n\n for (const bucket of this.a2uiBuckets.values()) {\n for (const [surfaceId, surface] of bucket) {\n surfaces.set(surfaceId, surface);\n }\n }\n\n const activeToolCallIds = new Set<string>();\n for (const [surfaceId, surface] of surfaces) {\n const { toolCall, warnings } = surfaceToPresentToolCall(\n surfaceId,\n surface,\n );\n for (const warning of warnings) {\n this.logger.debug(\"[agui] a2ui surface conversion warning\", warning);\n }\n if (!toolCall) continue;\n\n const { toolCallId } = toolCall;\n\n activeToolCallIds.add(toolCallId);\n\n const entry: ToolCallState = {\n toolCallId: toolCall.toolCallId,\n toolCallName: toolCall.toolName,\n argsText: toolCall.argsText,\n parsedArgs: toolCall.args,\n result: toolCall.result,\n isError: undefined,\n artifact: toolCall.artifact,\n snapshotResultApplied: false,\n };\n if (!this.toolCalls.has(toolCallId)) {\n this.partOrder.push({ kind: \"tool-call\", toolCallId });\n }\n this.nestingMemo = undefined;\n this.toolCalls.set(toolCallId, entry);\n this.a2uiToolCallIds.add(toolCallId);\n }\n\n for (const toolCallId of this.a2uiToolCallIds) {\n if (activeToolCallIds.has(toolCallId)) continue;\n this.nestingMemo = undefined;\n this.toolCalls.delete(toolCallId);\n const partIndex = this.partOrder.findIndex(\n (part) => part.kind === \"tool-call\" && part.toolCallId === toolCallId,\n );\n if (partIndex !== -1) this.partOrder.splice(partIndex, 1);\n this.a2uiToolCallIds.delete(toolCallId);\n }\n }\n\n private reportServerMessageId(messageId: string | undefined): void {\n if (!messageId) return;\n if (this.lastTextMessageId === undefined) {\n this.lastTextMessageId = messageId;\n }\n if (this.serverMessageIdReported) return;\n this.serverMessageIdReported = true;\n this.reportedServerMessageId = messageId;\n this.onServerMessageId?.(messageId);\n }\n\n private clearTextParts(): void {\n this.textParts.clear();\n }\n\n private resetMessageParts(): void {\n this.clearTextParts();\n this.reasoningParts.clear();\n this.reasoningSignatures.clear();\n this.reasoningSignatureIds.clear();\n this.reasoningMessageIds.clear();\n this.hiddenSignatures.clear();\n this.hiddenSignatureAnchors.clear();\n this.hiddenBlockAnchors.clear();\n this.hiddenReasoningIds.clear();\n this.hiddenActiveReasoningId = undefined;\n this.loggedDroppedOpaqueIds.clear();\n this.activeReasoningKeyByScope.clear();\n this.nestingMemo = undefined;\n this.subagentRuns.clear();\n this.toolCalls.clear();\n this.a2uiBuckets.clear();\n this.a2uiToolCallIds.clear();\n this.activityParts.clear();\n this.lastResolvedToolCallIdByScope.clear();\n this.partOrder.length = 0;\n this.lastReasoningBeforeToolCall = undefined;\n this.textPartCounter = 0;\n this.activeTextMessageIdByScope.clear();\n this.reportedServerMessageId = undefined;\n }\n\n // A subagent only ever reports its own terminal, so a run that ends while\n // one is still streaming would leave that nested message spinning forever.\n private closeOpenSubagentRuns(status: MessageStatus): void {\n for (const run of this.subagentRuns.values()) {\n if (run.status.type === \"running\") run.status = status;\n }\n }\n\n private scopeOf(event: { subagentRunId?: string }): string {\n return event.subagentRunId ?? ROOT_SCOPE;\n }\n\n // Nothing in the AG-UI schema makes a messageId unique across subagent runs,\n // so the accumulators key on the scope too. Root keys stay bare, which is\n // what the wire-id collision checks against reported message ids compare on.\n private partKey(scope: string, id: string): string {\n return scope === ROOT_SCOPE ? id : `${scope}\\u0000${id}`;\n }\n\n private beginDistinctTextMessage(messageId: string | undefined): void {\n if (\n this.joinStrategy === \"concat-content\" ||\n !messageId ||\n this.lastTextMessageId === undefined ||\n this.lastTextMessageId === messageId ||\n !this.onTextMessageStart\n ) {\n return;\n }\n const carried = this.takeTrailingReasoning();\n if (carried.parts.length > 0 || carried.hiddenSignatures.length > 0) {\n this.emit();\n }\n const openToolCallIds = Array.from(this.toolCalls.values())\n .filter((call) => call.result === undefined)\n .map((call) => call.toolCallId);\n this.resetMessageParts();\n this.onTextMessageStart(messageId, openToolCallIds);\n this.restoreReasoning(carried);\n }\n\n private takeTrailingReasoning() {\n const parts: {\n key: string;\n entry: { buffer: string; timing?: MessagePartTiming };\n signature: string | undefined;\n signatureId: string | undefined;\n reasoningId: string | undefined;\n }[] = [];\n let last = this.partOrder.at(-1);\n while (\n last?.kind === \"reasoning\" &&\n last.subagentRunId === undefined &&\n last !== this.lastReasoningBeforeToolCall\n ) {\n this.partOrder.pop();\n parts.unshift({\n key: last.key,\n entry: this.reasoningParts.get(last.key) ?? { buffer: \"\" },\n signature: this.reasoningSignatures.get(last.key),\n signatureId: this.reasoningSignatureIds.get(last.key),\n reasoningId: this.reasoningMessageIds.get(last.key),\n });\n last = this.partOrder.at(-1);\n }\n const cut = this.partOrder.length;\n const hiddenSignatures = Array.from(this.hiddenSignatures).filter(\n ([id]) => this.hiddenSignatureAnchors.get(id)! >= cut,\n );\n for (const [id] of hiddenSignatures) {\n this.hiddenSignatures.delete(id);\n this.hiddenSignatureAnchors.delete(id);\n }\n const hiddenBlockIds = Array.from(this.hiddenBlockAnchors)\n .filter(([, anchor]) => anchor >= cut)\n .map(([id]) => id);\n const hiddenActiveReasoningId = this.hiddenActiveReasoningId;\n return {\n parts,\n activeKey: this.activeReasoningKeyByScope.get(ROOT_SCOPE),\n hiddenSignatures,\n hiddenBlockIds,\n hiddenActiveReasoningId:\n hiddenActiveReasoningId !== undefined &&\n hiddenBlockIds.includes(hiddenActiveReasoningId)\n ? hiddenActiveReasoningId\n : undefined,\n };\n }\n\n private restoreReasoning(\n carried: ReturnType<RunAggregator[\"takeTrailingReasoning\"]>,\n ): void {\n for (const part of carried.parts) {\n this.partOrder.push({ kind: \"reasoning\", key: part.key });\n this.reasoningParts.set(part.key, part.entry);\n if (part.signature !== undefined)\n this.reasoningSignatures.set(part.key, part.signature);\n if (part.signatureId !== undefined)\n this.reasoningSignatureIds.set(part.key, part.signatureId);\n if (part.reasoningId !== undefined)\n this.reasoningMessageIds.set(part.key, part.reasoningId);\n }\n if (\n carried.activeKey !== undefined &&\n this.reasoningParts.has(carried.activeKey)\n ) {\n this.activeReasoningKeyByScope.set(ROOT_SCOPE, carried.activeKey);\n }\n for (const [id, encryptedValue] of carried.hiddenSignatures) {\n this.hiddenSignatures.set(id, encryptedValue);\n this.hiddenSignatureAnchors.set(id, 0);\n }\n for (const id of carried.hiddenBlockIds) {\n this.hiddenReasoningIds.add(id);\n this.hiddenBlockAnchors.set(id, 0);\n }\n this.hiddenActiveReasoningId = carried.hiddenActiveReasoningId;\n }\n\n private generateTextKey(): string {\n this.textPartCounter += 1;\n return `text-${this.textPartCounter}`;\n }\n\n private startTextMessage(scope: string, messageId?: string): string {\n const id = messageId ?? this.generateTextKey();\n const key = this.ensureTextPart(scope, id);\n this.activeTextMessageIdByScope.set(scope, key);\n return key;\n }\n\n private resolveTextMessageId(scope: string, messageId?: string): string {\n if (messageId) {\n const key = this.ensureTextPart(scope, messageId);\n this.activeTextMessageIdByScope.set(scope, key);\n return key;\n }\n\n const active = this.activeTextMessageIdByScope.get(scope);\n if (active) {\n return active;\n }\n\n const key = this.ensureTextPart(scope, this.generateTextKey());\n this.activeTextMessageIdByScope.set(scope, key);\n return key;\n }\n\n private ensureTextPart(scope: string, id: string): string {\n const key = this.partKey(scope, id);\n if (!this.textParts.has(key)) {\n this.textParts.set(key, { buffer: \"\" });\n if (\n !this.partOrder.some((part) => part.kind === \"text\" && part.key === key)\n ) {\n this.partOrder.push(\n scope === ROOT_SCOPE\n ? { kind: \"text\", key }\n : { kind: \"text\", key, subagentRunId: scope },\n );\n }\n }\n return key;\n }\n\n private appendText(id: string, delta: string): void {\n const entry = this.textParts.get(id);\n if (!entry) return;\n entry.buffer += delta;\n }\n\n private startToolCall(\n scope: string,\n id: string | undefined,\n name?: string,\n parentMessageId?: string,\n ) {\n if (!id) return;\n // A new tool call acts as a boundary: any anonymous text that arrives\n // after it should be a new part, not appended to the pre-tool text —\n // scoped, so a subagent's tool call doesn't break the root run's text\n // and vice versa.\n this.activeTextMessageIdByScope.delete(scope);\n if (\n !this.partOrder.some(\n (part) => part.kind === \"tool-call\" && part.toolCallId === id,\n )\n ) {\n // Tool insertion can precede existing reasoning in display order.\n if (scope === ROOT_SCOPE) {\n this.lastReasoningBeforeToolCall = this.partOrder.findLast(\n (part) =>\n part.kind === \"reasoning\" && part.subagentRunId === undefined,\n );\n }\n this.insertToolPart(scope, id, parentMessageId);\n }\n const state: ToolCallState = {\n toolCallId: id,\n toolCallName: name ?? \"tool\",\n argsText: \"\",\n parsedArgs: undefined,\n result: undefined,\n isError: undefined,\n snapshotResultApplied: false,\n };\n if (parentMessageId) {\n state.parentMessageId = parentMessageId;\n }\n if (scope !== ROOT_SCOPE) {\n state.subagentRunId = scope;\n }\n this.nestingMemo = undefined;\n this.toolCalls.set(id, state);\n }\n\n // The message and tool-call channels are unordered on the wire, so anchor a\n // tool call under its parentMessageId text part instead of appending it.\n private insertToolPart(scope: string, id: string, parentMessageId?: string) {\n const entry = { kind: \"tool-call\", toolCallId: id } as const;\n if (parentMessageId) {\n const parentKey = this.partKey(scope, parentMessageId);\n const parentIndex = this.partOrder.findIndex(\n (part) => part.kind === \"text\" && part.key === parentKey,\n );\n if (parentIndex !== -1) {\n let insertAt = parentIndex + 1;\n while (insertAt < this.partOrder.length) {\n const part = this.partOrder[insertAt];\n if (\n part?.kind === \"tool-call\" &&\n this.toolCalls.get(part.toolCallId)?.parentMessageId ===\n parentMessageId\n ) {\n insertAt += 1;\n continue;\n }\n break;\n }\n this.partOrder.splice(insertAt, 0, entry);\n return;\n }\n }\n this.partOrder.push(entry);\n }\n\n private appendToolArgs(id: string | undefined, delta: string) {\n const entry = id ? this.toolCalls.get(id) : undefined;\n if (!entry) return;\n if (!entry.argsTextScanner) {\n entry.argsTextScanner = createJSONContainerScanner();\n }\n entry.argsText += delta;\n const shouldParse = scanJSONContainerDelta(entry.argsTextScanner, delta);\n if (!shouldParse) {\n if (entry.argsTextScanner.state === \"invalid\") {\n entry.parsedArgs = undefined;\n }\n return;\n }\n try {\n const parsed = JSON.parse(entry.argsText);\n if (parsed && typeof parsed === \"object\") {\n entry.parsedArgs = parsed as Record<string, unknown>;\n } else {\n entry.parsedArgs = undefined;\n }\n } catch {\n entry.parsedArgs = undefined;\n }\n }\n\n private finishToolCall(\n scope: string,\n id: string,\n content: string | ContentPart[],\n isError?: boolean,\n toolMessageId?: string,\n mcpResult?: Record<string, unknown>,\n ) {\n if (!id) return;\n const modelText = toolContentText(content);\n let entry = this.toolCalls.get(id);\n if (!entry) {\n entry = {\n toolCallId: id,\n toolCallName: \"tool\",\n argsText: \"\",\n parsedArgs: undefined,\n result: undefined,\n isError: undefined,\n snapshotResultApplied: false,\n ...(scope !== ROOT_SCOPE ? { subagentRunId: scope } : {}),\n };\n this.nestingMemo = undefined;\n this.toolCalls.set(id, entry);\n }\n if (\n !this.partOrder.some(\n (part) => part.kind === \"tool-call\" && part.toolCallId === id,\n )\n ) {\n this.partOrder.push({ kind: \"tool-call\", toolCallId: id });\n }\n if (mcpResult !== undefined && !entry.snapshotResultApplied) {\n entry.result = mcpResult;\n entry.modelContent = [{ type: \"text\", text: modelText }];\n entry.snapshotResultApplied = true;\n entry.isError = isError;\n if (entry.mcpAppResourceUri === undefined) {\n const uri = readMcpAppResourceUri(mcpResult._meta);\n if (uri !== undefined) entry.mcpAppResourceUri = uri;\n }\n } else if (entry.snapshotResultApplied) {\n if (entry.modelContent === undefined) {\n entry.modelContent = [{ type: \"text\", text: modelText }];\n }\n if (entry.isError === undefined) {\n entry.isError = isError;\n }\n } else {\n entry.result = Array.isArray(content) ? content : tryParseJSON(content);\n if (Array.isArray(content)) {\n delete entry.modelContent;\n }\n entry.isError = isError;\n }\n if (toolMessageId) {\n entry.toolMessageId = toolMessageId;\n }\n this.lastResolvedToolCallIdByScope.set(scope, id);\n }\n\n private nesting(): {\n subagentsByParentToolCallId: Map<string, string[]>;\n reachable: Set<string>;\n } {\n if (!this.nestingMemo) {\n const subagentsByParentToolCallId = this.subagentsByParentToolCallId();\n this.nestingMemo = {\n subagentsByParentToolCallId,\n reachable: this.reachableSubagentRunIds(subagentsByParentToolCallId),\n };\n }\n return this.nestingMemo;\n }\n\n private subagentsByParentToolCallId(): Map<string, string[]> {\n const map = new Map<string, string[]>();\n for (const run of this.subagentRuns.values()) {\n if (!run.parentToolCallId) continue;\n const list = map.get(run.parentToolCallId) ?? [];\n list.push(run.subagentRunId);\n map.set(run.parentToolCallId, list);\n }\n return map;\n }\n\n // A subagent nests under its spawning tool call only when that call is itself\n // reachable from the root scope. A run with no parentToolCallId, one naming a\n // call this run never saw, or one in a cycle has nowhere to hang; the visited\n // set also keeps a malformed chain to one visit per run instead of branching\n // at every level.\n private reachableSubagentRunIds(\n subagentsByParentToolCallId: Map<string, string[]>,\n ): Set<string> {\n const reachable = new Set<string>();\n const walk = (scope: string, depth: number): void => {\n if (depth > MAX_SUBAGENT_DEPTH) return;\n for (const entry of this.toolCalls.values()) {\n if ((entry.subagentRunId ?? ROOT_SCOPE) !== scope) continue;\n for (const id of subagentsByParentToolCallId.get(entry.toolCallId) ??\n []) {\n if (reachable.has(id)) continue;\n reachable.add(id);\n walk(id, depth + 1);\n }\n }\n };\n walk(ROOT_SCOPE, 0);\n return reachable;\n }\n\n // Nested messages rather than a discovery hook (the shape react-langchain\n // uses): ToolCallMessagePart.messages is the contract core consumers already\n // walk, and SUBAGENT_STARTED.parentToolCallId names the spawning call\n // outright, so the join needs no namespace scheme of its own.\n private materializeSubagentMessage(\n subagentRunId: string,\n depth: number,\n ctx: BuildContext,\n ): ThreadMessage | undefined {\n const run = this.subagentRuns.get(subagentRunId);\n if (!run || depth > MAX_SUBAGENT_DEPTH) return undefined;\n const content = this.buildParts(subagentRunId, depth + 1, ctx);\n return {\n id: run.subagentRunId,\n role: \"assistant\",\n createdAt: run.createdAt,\n status: run.status,\n content,\n metadata: {\n unstable_state: null,\n unstable_annotations: [],\n unstable_data: [],\n steps: [],\n custom: {\n [AG_UI_METADATA_NAMESPACE]: {\n name: run.name,\n ...(run.description !== undefined\n ? { description: run.description }\n : {}),\n ...(run.parentSubagentRunId !== undefined\n ? { parentSubagentRunId: run.parentSubagentRunId }\n : {}),\n ...(run.result !== undefined ? { result: run.result } : {}),\n ...(run.interruptIds !== undefined\n ? { interruptIds: run.interruptIds }\n : {}),\n ...(run.errorCode !== undefined\n ? { errorCode: run.errorCode }\n : {}),\n },\n },\n },\n } as ThreadMessage;\n }\n\n private buildParts(\n scope: string,\n depth: number,\n ctx: BuildContext,\n ): ThreadAssistantMessagePart[] {\n const snapshot: ThreadAssistantMessagePart[] = [];\n const isRoot = scope === ROOT_SCOPE;\n\n for (const { index, part } of ctx.partsByScope.get(scope) ?? []) {\n const materialized = () => {\n if (isRoot && ctx.root) ctx.root.lastMaterializedIndex = index;\n };\n\n if (part.kind === \"tool-call\") {\n const entry = this.toolCalls.get(part.toolCallId);\n if (!entry) continue;\n const approval = ctx.approvals.get(entry.toolCallId);\n const nestedMessages = (\n ctx.subagentsByParentToolCallId.get(entry.toolCallId) ?? []\n )\n .filter((id) => ctx.reachable.has(id))\n .map((id) => this.materializeSubagentMessage(id, depth, ctx))\n .filter((m): m is ThreadMessage => m !== undefined);\n const toolPart: ToolCallMessagePart = {\n type: \"tool-call\",\n toolCallId: entry.toolCallId,\n toolName: entry.toolCallName,\n args: (entry.parsedArgs ?? {}) as any,\n argsText: entry.argsText,\n ...(approval ? { approval } : {}),\n ...(entry.result !== undefined ? { result: entry.result } : {}),\n ...(entry.artifact !== undefined ? { artifact: entry.artifact } : {}),\n ...(entry.modelContent !== undefined\n ? { modelContent: entry.modelContent }\n : {}),\n ...(entry.isError !== undefined ? { isError: entry.isError } : {}),\n ...(entry.mcpAppResourceUri\n ? {\n mcp: {\n app: {\n resourceUri: entry.mcpAppResourceUri,\n ...(entry.mcpAppServerId\n ? { serverId: entry.mcpAppServerId }\n : {}),\n },\n },\n }\n : {}),\n ...(entry.parentMessageId ? { parentId: entry.parentMessageId } : {}),\n ...(entry.toolMessageId\n ? { unstable_toolMessageId: entry.toolMessageId }\n : {}),\n ...(nestedMessages.length > 0 ? { messages: nestedMessages } : {}),\n } as ToolCallMessagePart & { unstable_toolMessageId?: string };\n snapshot.push(toolPart);\n materialized();\n continue;\n }\n\n const rawScope =\n \"subagentRunId\" in part\n ? (part.subagentRunId ?? ROOT_SCOPE)\n : ROOT_SCOPE;\n\n if (part.kind === \"reasoning\") {\n if (this.showThinking) {\n const entry = this.reasoningParts.get(part.key);\n const buffer = entry?.buffer ?? \"\";\n const isActive =\n this.activeReasoningKeyByScope.get(rawScope) === part.key;\n if (buffer.length > 0 || isActive) {\n const encryptedValue = this.reasoningSignatures.get(part.key);\n const reasoningId = this.reasoningMessageIds.get(part.key);\n const meta = {\n ...(reasoningId !== undefined ? { reasoningId } : {}),\n ...(encryptedValue !== undefined ? { encryptedValue } : {}),\n };\n snapshot.push({\n type: \"reasoning\",\n text: buffer,\n ...(entry?.timing ? { timing: entry.timing } : {}),\n ...(Object.keys(meta).length > 0\n ? { providerMetadata: { [AG_UI_METADATA_NAMESPACE]: meta } }\n : {}),\n } as const);\n materialized();\n } else if (isRoot && ctx.root) {\n // A retracted empty block still carries transport state: without\n // a part to live on, its signature rides the message metadata,\n // matching the shape a snapshot reload produces.\n const encryptedValue = this.reasoningSignatures.get(part.key);\n const id = this.reasoningSignatureIds.get(part.key);\n if (id?.trim() && encryptedValue?.trim()) {\n ctx.root.opaqueCandidates.push({\n id,\n encryptedValue,\n anchor: index + 1,\n });\n }\n }\n }\n continue;\n }\n\n if (part.kind === \"text\") {\n const entry = this.textParts.get(part.key);\n if (entry && entry.buffer.trim().length > 0) {\n snapshot.push({ type: \"text\", text: entry.buffer } as const);\n materialized();\n }\n continue;\n }\n\n if (part.kind === \"data\") {\n snapshot.push({\n type: \"data\",\n name: part.name,\n data: part.value,\n });\n materialized();\n continue;\n }\n }\n\n return snapshot;\n }\n\n private emit(): void {\n const { subagentsByParentToolCallId, reachable } = this.nesting();\n const root = {\n opaqueCandidates: Array.from(\n this.hiddenSignatures,\n ([id, encryptedValue]) => ({\n id,\n encryptedValue,\n anchor: this.hiddenSignatureAnchors.get(id)!,\n }),\n ) as (AgUiOpaqueReasoning & { anchor: number })[],\n lastMaterializedIndex: -1,\n };\n // A run that ended incomplete can no longer be resumed, so a gate left over\n // from an earlier interrupt outcome is unanswerable and must not stay\n // projected. The interrupts themselves are kept on the message, since the\n // bespoke hooks read that payload. Bound ids cover every call the run\n // produced, root or nested: the approval seams walk\n // ToolCallMessagePart.messages, so a gate naming a subagent-scoped call is\n // answerable and projects onto the nested part.\n const partsByScope = new Map<\n string,\n { index: number; part: PartOrderEntry }[]\n >();\n for (const [index, part] of this.partOrder.entries()) {\n const rawScope =\n part.kind === \"tool-call\"\n ? (this.toolCalls.get(part.toolCallId)?.subagentRunId ?? ROOT_SCOPE)\n : \"subagentRunId\" in part\n ? (part.subagentRunId ?? ROOT_SCOPE)\n : ROOT_SCOPE;\n const bucketScope =\n rawScope === ROOT_SCOPE || reachable.has(rawScope)\n ? rawScope\n : ROOT_SCOPE;\n const bucket = partsByScope.get(bucketScope);\n if (bucket) bucket.push({ index, part });\n else partsByScope.set(bucketScope, [{ index, part }]);\n }\n const ctx: BuildContext = {\n subagentsByParentToolCallId,\n reachable,\n partsByScope,\n approvals: projectAgUiToolApprovals(\n this.status?.type === \"requires-action\" ? this.interrupts : undefined,\n new Set(\n Array.from(this.toolCalls.values()).map((entry) => entry.toolCallId),\n ),\n ),\n root,\n };\n const snapshot = this.buildParts(ROOT_SCOPE, 0, ctx);\n const { opaqueCandidates, lastMaterializedIndex } = root;\n\n const toolMessageIds = new Set<string>();\n for (const call of this.toolCalls.values()) {\n if (call.toolMessageId) toolMessageIds.add(call.toolMessageId);\n }\n opaqueCandidates.sort((a, b) => a.anchor - b.anchor);\n const publishableOpaqueReasoning = opaqueCandidates\n .filter((entry) => {\n const collides =\n this.textParts.has(entry.id) ||\n entry.id === this.reportedServerMessageId ||\n toolMessageIds.has(entry.id);\n if (collides && !this.loggedDroppedOpaqueIds.has(entry.id)) {\n this.loggedDroppedOpaqueIds.add(entry.id);\n this.logger.debug?.(\n \"[agui] aggregator dropped opaque reasoning signature: id collides with a message id\",\n entry.id,\n );\n }\n return !collides;\n })\n .map(({ anchor, ...entry }) =>\n lastMaterializedIndex < anchor ? { ...entry, after: true } : entry,\n );\n if (publishableOpaqueReasoning.length > 0)\n this.hasEmittedOpaqueReasoning = true;\n // Once an opaque entry has been published this run, the key keeps being\n // emitted (empty when withdrawn) so the namespace merge can retract it.\n const includeOpaque = this.hasEmittedOpaqueReasoning;\n const timing = this.getTiming();\n const metadata = {\n ...(timing ? { timing } : {}),\n ...(this.interrupts ||\n (this.status?.type === \"requires-action\" &&\n this.status.reason === \"tool-calls\" &&\n this.pendingToolCallIds) ||\n includeOpaque\n ? {\n custom: {\n [AG_UI_METADATA_NAMESPACE]: {\n ...(this.interrupts ? { interrupts: this.interrupts } : {}),\n ...(this.status?.type === \"requires-action\" &&\n this.status.reason === \"tool-calls\" &&\n this.pendingToolCallIds\n ? { pendingToolCallIds: this.pendingToolCallIds }\n : {}),\n ...(includeOpaque\n ? { opaqueReasoning: publishableOpaqueReasoning }\n : {}),\n } satisfies AgUiCustomMetadata,\n },\n }\n : {}),\n };\n const result: ChatModelRunResult = {\n content: snapshot,\n ...(this.status ? { status: this.status } : undefined),\n ...(Object.keys(metadata).length > 0 ? { metadata } : undefined),\n };\n this.emitUpdate(result);\n }\n\n private recordFirstToken(): void {\n if (\n this.firstTokenTime === undefined &&\n this.streamStartTime !== undefined\n ) {\n this.firstTokenTime = Date.now() - this.streamStartTime;\n }\n }\n\n private getTiming(): MessageTiming | undefined {\n if (this.streamStartTime === undefined) return undefined;\n\n const now = Date.now();\n const totalStreamTime = now - this.streamStartTime;\n const tokenCount =\n this.totalChunks > 0\n ? Math.ceil(\n Array.from(this.textParts.values()).reduce(\n (sum, p) => sum + p.buffer.length,\n 0,\n ) / 4,\n )\n : undefined;\n const tokensPerSecond =\n tokenCount && totalStreamTime > 0\n ? (tokenCount / totalStreamTime) * 1000\n : undefined;\n\n return {\n streamStartTime: this.streamStartTime,\n ...(this.firstTokenTime !== undefined\n ? { firstTokenTime: this.firstTokenTime }\n : {}),\n totalStreamTime,\n ...(tokenCount !== undefined ? { tokenCount } : {}),\n ...(tokensPerSecond !== undefined ? { tokensPerSecond } : {}),\n totalChunks: this.totalChunks,\n toolCallCount: this.toolCalls.size,\n };\n }\n\n private handleReasoningStart(\n scope: string,\n messageId: string,\n isMessageId = false,\n timestamp?: number,\n ): void {\n if (!this.showThinking) {\n if (scope !== ROOT_SCOPE) return;\n const anchor = this.partOrder.length;\n this.hiddenReasoningIds.add(messageId);\n this.hiddenBlockAnchors.set(messageId, anchor);\n this.hiddenActiveReasoningId = messageId;\n return;\n }\n // A reasoning block acts as a boundary: anonymous text arriving after it\n // should be a new part, not appended to any pre-reasoning text — scoped.\n this.activeTextMessageIdByScope.delete(scope);\n const key = this.partKey(scope, messageId);\n if (isMessageId) {\n this.reasoningMessageIds.set(key, messageId);\n }\n if (!this.reasoningParts.has(key)) {\n this.reasoningParts.set(key, { buffer: \"\" });\n this.partOrder.push(\n scope === ROOT_SCOPE\n ? { kind: \"reasoning\", key }\n : { kind: \"reasoning\", key, subagentRunId: scope },\n );\n }\n const entry = this.reasoningParts.get(key);\n if (entry?.timing) {\n entry.timing = { startedAt: entry.timing.startedAt };\n } else if (\n entry &&\n typeof timestamp === \"number\" &&\n Number.isFinite(timestamp)\n ) {\n entry.timing = { startedAt: timestamp };\n }\n this.activeReasoningKeyByScope.set(scope, key);\n this.emit();\n }\n\n private handleReasoningContent(\n scope: string,\n delta: string,\n messageId: string,\n isMessageId = false,\n ): void {\n if (!delta) return;\n if (!this.showThinking) {\n // Content without a preceding START still names the block (the visible\n // path opens it lazily); register it so a signature can claim it.\n if (scope !== ROOT_SCOPE) return;\n if (this.hiddenActiveReasoningId === undefined) {\n this.handleReasoningStart(scope, messageId, isMessageId);\n }\n return;\n }\n if (!this.activeReasoningKeyByScope.has(scope)) {\n // Content arrived without a preceding START — create the slot lazily.\n this.handleReasoningStart(scope, messageId, isMessageId);\n }\n const key = this.activeReasoningKeyByScope.get(scope);\n if (!key) return;\n const entry = this.reasoningParts.get(key);\n if (entry) entry.buffer += delta;\n this.emit();\n }\n\n private handleReasoningEnd(scope: string, timestamp?: number): void {\n if (!this.showThinking) {\n if (scope === ROOT_SCOPE) this.hiddenActiveReasoningId = undefined;\n return;\n }\n const key = this.activeReasoningKeyByScope.get(scope);\n const entry = key ? this.reasoningParts.get(key) : undefined;\n if (\n entry?.timing &&\n typeof timestamp === \"number\" &&\n Number.isFinite(timestamp)\n ) {\n entry.timing = { ...entry.timing, completedAt: timestamp };\n }\n this.activeReasoningKeyByScope.delete(scope);\n this.emit();\n }\n}\n\nexport function tryParseJSON(value: string): unknown {\n if (!value) return value;\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n}\n"],"mappings":";;;;;;;;AAmCA,MAAM,aAAa;AAInB,MAAM,qBAAqB;AAmE3B,MAAM,oCAA0D;CAC9D,OAAO;CACP,OAAO,CAAC;CACR,UAAU;CACV,SAAS;AACX;AAEA,MAAM,oBAAoB,SACxB,SAAS,OAAO,SAAS,OAAQ,SAAS,QAAQ,SAAS;AAE7D,MAAM,0BACJ,SACA,UACY;CACZ,IAAI,YAAY;CAEhB,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,QAAQ,UAAU,WAAW;EACjC,IAAI,QAAQ,UAAU,YAAY;GAChC,IAAI,iBAAiB,IAAI,GAAG;GAC5B,QAAQ,QAAQ;GAChB;EACF;EACA,IAAI,QAAQ,UAAU,WAAW;GAC/B,IAAI,iBAAiB,IAAI,GAAG;GAC5B,IAAI,SAAS,OAAO,SAAS,KAAK;IAChC,QAAQ,QAAQ;IAChB;GACF;GACA,QAAQ,QAAQ;GAChB,QAAQ,MAAM,KAAK,IAAI;GACvB;EACF;EACA,IAAI,QAAQ,UAAU;GACpB,IAAI,QAAQ,SACV,QAAQ,UAAU;QACb,IAAI,SAAS,MAClB,QAAQ,UAAU;QACb,IAAI,SAA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AAK,cAAc;GACtB,IAAI,UAAU,YAAY,KAAK,0BAA0B,KAAA;GACzD;EACF;EACA,MAAM,MAAM,KAAK,0BAA0B,IAAI,KAAK;EACpD,MAAM,QAAQ,MAAM,KAAK,eAAe,IAAI,GAAG,IAAI,KAAA;EACnD,IACE,OAAO,UACP,OAAO,cAAc,YACrB,OAAO,SAAS,SAAS,GAEzB,MAAM,SAAS;GAAE,GAAG,MAAM;GAAQ,aAAa;EAAU;EAE3D,KAAK,0BAA0B,OAAO,KAAK;EAC3C,KAAK,KAAK;CACZ;AACF;AAEA,SAAgB,aAAa,OAAwB;CACnD,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI;EACF,OAAO,KAAK,MAAM,KAAK;CACzB,QAAQ;EACN,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"run-aggregator.js","names":[],"sources":["../../../src/runtime/adapter/run-aggregator.ts"],"sourcesContent":["\"use client\";\n\nimport {\n isMcpAppUri,\n type ChatModelRunResult,\n type MessagePartTiming,\n type MessageStatus,\n type MessageTiming,\n type ThreadAssistantMessagePart,\n type ThreadMessage,\n type ToolCallMessagePart,\n type ToolModelContentPart,\n} from \"@assistant-ui/core\";\nimport type { JoinStrategy } from \"@assistant-ui/core/react\";\nimport type { ContentPart } from \"@ag-ui/client\";\nimport {\n applyA2uiOperations,\n surfaceToPresentToolCall,\n type A2uiState,\n type A2uiSurfaceState,\n} from \"@assistant-ui/generative-ui/a2ui\";\nimport jsonpatch, { type Operation } from \"fast-json-patch\";\nimport { readMcpAppResourceUri, toolContentText } from \"../mcp-tool-result\";\nimport { projectAgUiToolApprovals } from \"./tool-approval\";\nimport { withAgUiPartMessageMetadata } from \"./conversions\";\nimport {\n AG_UI_METADATA_NAMESPACE,\n A2UI_SURFACE_ACTIVITY_TYPE,\n MCP_APPS_ACTIVITY_TYPE,\n type AgUiCustomMetadata,\n type AgUiEvent,\n type AgUiInterrupt,\n type AgUiOpaqueReasoning,\n MAX_SUBAGENT_DEPTH,\n} from \"../types\";\nimport type { Logger } from \"../logger\";\n\nconst ROOT_SCOPE = \"\";\n\ntype SubagentRunState = {\n subagentRunId: string;\n name: string;\n description?: string;\n parentSubagentRunId?: string;\n parentToolCallId?: string;\n parentMessageId?: string;\n createdAt: Date;\n status: MessageStatus;\n result?: unknown;\n interruptIds?: string[];\n errorCode?: string;\n};\n\ntype ToolApproval = NonNullable<ToolCallMessagePart[\"approval\"]>;\n\ntype PartOrderEntry =\n | { kind: \"text\"; key: string; subagentRunId?: string }\n | { kind: \"reasoning\"; key: string; subagentRunId?: string }\n | { kind: \"tool-call\"; toolCallId: string }\n | { kind: \"data\"; name: string; value: unknown; subagentRunId?: string };\n\ntype BuildContext = {\n subagentsByParentToolCallId: Map<string, string[]>;\n reachable: Set<string>;\n approvals: ReadonlyMap<string, ToolApproval>;\n // partOrder bucketed by the scope each part renders in, so one emit walks\n // every part once however many subagents the run spawned.\n partsByScope: Map<string, { index: number; part: PartOrderEntry }[]>;\n // Present only for the root walk: the pass that builds the snapshot is also\n // the one that decides where a retracted reasoning signature anchors, so the\n // two can never disagree about what materialized.\n root?: {\n opaqueCandidates: (AgUiOpaqueReasoning & { anchor: number })[];\n lastMaterializedIndex: number;\n };\n};\n\ntype Emit = (update: ChatModelRunResult) => void;\n\ntype ToolCallState = {\n toolCallId: string;\n toolCallName: string;\n argsText: string;\n argsTextScanner?: JSONContainerScanner | undefined;\n parsedArgs: Record<string, unknown> | undefined;\n result: unknown;\n isError: boolean | undefined;\n parentMessageId?: string;\n toolMessageId?: string;\n mcpAppResourceUri?: string;\n mcpAppServerId?: string;\n artifact?: unknown;\n modelContent?: ToolModelContentPart[];\n resultMetadata?: Record<string, unknown>;\n snapshotResultApplied: boolean;\n subagentRunId?: string;\n};\n\ntype JSONContainerScanner = {\n state: \"pending\" | \"open\" | \"complete\" | \"invalid\";\n stack: (\"{\" | \"[\")[];\n inString: boolean;\n escaped: boolean;\n};\n\nconst createJSONContainerScanner = (): JSONContainerScanner => ({\n state: \"pending\",\n stack: [],\n inString: false,\n escaped: false,\n});\n\nconst isJSONWhitespace = (char: string): boolean =>\n char === \" \" || char === \"\\t\" || char === \"\\n\" || char === \"\\r\";\n\nconst scanJSONContainerDelta = (\n scanner: JSONContainerScanner,\n delta: string,\n): boolean => {\n let completed = false;\n\n for (const char of delta) {\n if (scanner.state === \"invalid\") continue;\n if (scanner.state === \"complete\") {\n if (isJSONWhitespace(char)) continue;\n scanner.state = \"invalid\";\n continue;\n }\n if (scanner.state === \"pending\") {\n if (isJSONWhitespace(char)) continue;\n if (char !== \"{\" && char !== \"[\") {\n scanner.state = \"invalid\";\n continue;\n }\n scanner.state = \"open\";\n scanner.stack.push(char);\n continue;\n }\n if (scanner.inString) {\n if (scanner.escaped) {\n scanner.escaped = false;\n } else if (char === \"\\\\\") {\n scanner.escaped = true;\n } else if (char === '\"') {\n scanner.inString = false;\n }\n continue;\n }\n if (char === '\"') {\n scanner.inString = true;\n continue;\n }\n if (char === \"{\" || char === \"[\") {\n scanner.stack.push(char);\n continue;\n }\n if (char === \"}\" || char === \"]\") {\n const expected = char === \"}\" ? \"{\" : \"[\";\n if (scanner.stack.pop() !== expected) {\n scanner.state = \"invalid\";\n continue;\n }\n if (scanner.stack.length === 0) {\n scanner.state = \"complete\";\n completed = true;\n }\n }\n }\n\n return completed && scanner.state === \"complete\";\n};\n\nexport const isPlainObject = (\n value: unknown,\n): value is Record<string, unknown> =>\n !!value && typeof value === \"object\" && !Array.isArray(value);\n\nexport type RunAggregatorOptions = {\n showThinking: boolean;\n joinStrategy?: JoinStrategy | undefined;\n logger: Logger;\n emit: Emit;\n onServerMessageId?: (messageId: string) => void;\n onTextMessageStart?: (messageId: string, openToolCallIds: string[]) => void;\n};\n\n/**\n * Collects AG-UI events into assistant-ui run snapshots that can be yielded from a ChatModelAdapter.\n *\n * The aggregator keeps a single assistant message worth of parts. Each incoming event updates the parts and\n * emits a fresh snapshot through the provided `emit` callback. `CUSTOM` events\n * become canonical data parts; integration plumbing names such as\n * `on_interrupt`, `PredictState`, `Exit`, `hook_error`, `state_update_error`,\n * `system:*`, and `MultiAgentHandoff` are forwarded the same way, so apps only\n * need data renderers for names they own.\n */\nexport class RunAggregator {\n private readonly emitUpdate: Emit;\n private readonly showThinking: boolean;\n private readonly joinStrategy: JoinStrategy | undefined;\n private readonly logger: Logger;\n private readonly onServerMessageId: ((messageId: string) => void) | undefined;\n private readonly onTextMessageStart:\n | ((messageId: string, openToolCallIds: string[]) => void)\n | undefined;\n\n private status: ChatModelRunResult[\"status\"] | undefined;\n private interrupts: AgUiInterrupt[] | undefined;\n private pendingToolCallIds: string[] | undefined;\n private readonly textParts = new Map<string, { buffer: string }>();\n private readonly pendingSnapshotText = new Map<string, string>();\n private readonly activeTextMessageIdByScope = new Map<string, string>();\n private readonly reasoningParts = new Map<\n string,\n { buffer: string; timing?: MessagePartTiming }\n >();\n private readonly reasoningSignatures = new Map<string, string>();\n private readonly reasoningSignatureIds = new Map<string, string>();\n private readonly hiddenSignatures = new Map<string, string>();\n private readonly hiddenSignatureAnchors = new Map<string, number>();\n private readonly hiddenBlockAnchors = new Map<string, number>();\n private readonly hiddenReasoningIds = new Set<string>();\n private hiddenActiveReasoningId: string | undefined;\n private hasEmittedOpaqueReasoning = false;\n private readonly loggedDroppedOpaqueIds = new Set<string>();\n private readonly reasoningMessageIds = new Map<string, string>();\n private readonly activeReasoningKeyByScope = new Map<string, string>();\n private readonly subagentRuns = new Map<string, SubagentRunState>();\n // The nesting graph only moves when a run is announced or a tool call is\n // created, which is rare next to emit(), so it is derived once per change\n // rather than per streamed delta.\n private nestingMemo:\n | {\n subagentsByParentToolCallId: Map<string, string[]>;\n reachable: Set<string>;\n }\n | undefined;\n private readonly toolCalls = new Map<string, ToolCallState>();\n private readonly a2uiBuckets = new Map<string, A2uiState>();\n private readonly a2uiToolCallIds = new Set<string>();\n private readonly activityParts = new Map<\n string,\n { kind: \"data\"; name: string; value: unknown; subagentRunId?: string }\n >();\n private readonly lastResolvedToolCallIdByScope = new Map<string, string>();\n private readonly partOrder: PartOrderEntry[] = [];\n private lastReasoningBeforeToolCall: PartOrderEntry | undefined;\n private textPartCounter = 0;\n private serverMessageIdReported = false;\n private reportedServerMessageId: string | undefined;\n private lastTextMessageId: string | undefined;\n\n private streamStartTime: number | undefined;\n private firstTokenTime: number | undefined;\n private totalChunks = 0;\n\n constructor(options: RunAggregatorOptions) {\n this.emitUpdate = options.emit;\n this.showThinking = options.showThinking;\n this.joinStrategy = options.joinStrategy;\n this.logger = options.logger;\n this.onServerMessageId = options.onServerMessageId;\n this.onTextMessageStart = options.onTextMessageStart;\n }\n\n hasToolCall(toolCallId: string): boolean {\n return this.toolCalls.has(toolCallId);\n }\n\n handle(event: AgUiEvent): void {\n switch (event.type) {\n case \"RUN_STARTED\": {\n this.resetMessageParts();\n this.interrupts = undefined;\n this.serverMessageIdReported = false;\n this.lastTextMessageId = undefined;\n this.reportedServerMessageId = undefined;\n this.streamStartTime = Date.now();\n this.firstTokenTime = undefined;\n this.totalChunks = 0;\n this.status = { type: \"running\" };\n this.emit();\n break;\n }\n case \"MESSAGES_SNAPSHOT\": {\n this.pendingSnapshotText.clear();\n for (const message of event.messages) {\n if (\n message.role !== \"assistant\" ||\n typeof message.content !== \"string\"\n )\n continue;\n const part = this.textParts.get(message.id);\n if (part) part.buffer = message.content;\n else this.pendingSnapshotText.set(message.id, message.content);\n }\n break;\n }\n case \"RUN_FINISHED\": {\n if (event.outcome?.type === \"cancelled\") {\n this.interrupts = undefined;\n this.status = { type: \"incomplete\", reason: \"cancelled\" };\n this.closeOpenSubagentRuns(this.status);\n this.emit();\n break;\n }\n if (event.outcome?.type === \"interrupt\") {\n this.interrupts = event.outcome.interrupts;\n this.status = { type: \"requires-action\", reason: \"interrupt\" };\n this.emit();\n break;\n }\n\n this.interrupts = undefined;\n // A call nested inside a subagent message is answerable the same way\n // a root call is: getPendingToolCalls and addToolResult walk\n // ToolCallMessagePart.messages, so any unresolved call keeps the run\n // resumable.\n const pendingToolCallIds =\n event.outcome?.type === \"success\"\n ? event.outcome.pendingToolCallIds\n : undefined;\n const hasUnresolvedToolCalls =\n pendingToolCallIds && pendingToolCallIds.length > 0\n ? pendingToolCallIds.some((id) => {\n const call = this.toolCalls.get(id);\n return call !== undefined && call.result === undefined;\n })\n : Array.from(this.toolCalls.values()).some(\n (tc) => tc.result === undefined,\n );\n\n this.status = hasUnresolvedToolCalls\n ? { type: \"requires-action\", reason: \"tool-calls\" }\n : { type: \"complete\", reason: \"unknown\" };\n this.pendingToolCallIds =\n hasUnresolvedToolCalls && pendingToolCallIds?.length\n ? pendingToolCallIds\n : undefined;\n this.closeOpenSubagentRuns(this.status);\n this.emit();\n break;\n }\n case \"RUN_ERROR\": {\n this.status = {\n type: \"incomplete\",\n reason: \"error\",\n ...(event.message !== undefined ? { error: event.message } : {}),\n };\n this.closeOpenSubagentRuns(this.status);\n this.emit();\n break;\n }\n case \"RUN_CANCELLED\": {\n // A cancel can land after RUN_FINISHED while the response is still\n // closing: the finished answer stays complete, and an interrupt the run\n // already delivered stays answerable.\n if (\n this.status?.type === \"complete\" ||\n (this.status?.type === \"requires-action\" &&\n this.status.reason === \"interrupt\")\n )\n break;\n this.status = { type: \"incomplete\", reason: \"cancelled\" };\n this.closeOpenSubagentRuns(this.status);\n this.emit();\n break;\n }\n\n case \"TEXT_MESSAGE_START\": {\n const scope = this.scopeOf(event);\n if (scope === ROOT_SCOPE) {\n this.beginDistinctTextMessage(event.messageId);\n this.reportServerMessageId(event.messageId);\n if (event.messageId) this.lastTextMessageId = event.messageId;\n }\n this.startTextMessage(scope, event.messageId);\n this.emit();\n break;\n }\n case \"TEXT_MESSAGE_CONTENT\": {\n const incomingId = event.messageId;\n const scope = this.scopeOf(event);\n if (scope === ROOT_SCOPE) {\n this.beginDistinctTextMessage(incomingId, true);\n this.reportServerMessageId(incomingId);\n if (incomingId) this.lastTextMessageId = incomingId;\n }\n if (!event.delta) break;\n this.recordFirstToken();\n const id = this.resolveTextMessageId(scope, incomingId);\n this.appendText(id, event.delta);\n this.totalChunks++;\n this.emit();\n break;\n }\n case \"TEXT_MESSAGE_END\": {\n const scope = this.scopeOf(event);\n if (scope === ROOT_SCOPE) this.reportServerMessageId(event.messageId);\n if (\n event.messageId &&\n this.activeTextMessageIdByScope.get(scope) ===\n this.partKey(scope, event.messageId)\n ) {\n this.activeTextMessageIdByScope.delete(scope);\n }\n this.emit();\n break;\n }\n\n case \"CUSTOM\": {\n this.activeTextMessageIdByScope.delete(ROOT_SCOPE);\n this.partOrder.push({\n kind: \"data\",\n name: event.name,\n value: event.value,\n });\n this.emit();\n break;\n }\n\n case \"REASONING_START\":\n case \"REASONING_MESSAGE_START\":\n this.handleReasoningStart(\n this.scopeOf(event),\n event.messageId,\n event.type === \"REASONING_MESSAGE_START\",\n event.timestamp,\n );\n break;\n case \"REASONING_ENCRYPTED_VALUE\":\n if (event.subtype === \"message\") {\n const scope = this.scopeOf(event);\n const entityKey = this.partKey(scope, event.entityId);\n const key =\n this.showThinking && this.reasoningParts.has(entityKey)\n ? entityKey\n : undefined;\n if (key !== undefined) {\n this.reasoningSignatures.set(key, event.encryptedValue);\n this.reasoningSignatureIds.set(key, event.entityId);\n this.emit();\n } else if (\n !this.showThinking &&\n scope === ROOT_SCOPE &&\n event.entityId.trim().length > 0 &&\n event.encryptedValue.trim().length > 0 &&\n this.hiddenReasoningIds.has(event.entityId)\n ) {\n this.hiddenSignatures.set(event.entityId, event.encryptedValue);\n this.hiddenSignatureAnchors.set(\n event.entityId,\n this.hiddenBlockAnchors.get(event.entityId) ??\n this.partOrder.length,\n );\n this.emit();\n }\n }\n break;\n case \"REASONING_MESSAGE_CONTENT\":\n this.handleReasoningContent(\n this.scopeOf(event),\n event.delta,\n event.messageId,\n true,\n );\n this.totalChunks++;\n this.recordFirstToken();\n break;\n case \"REASONING_MESSAGE_END\":\n case \"REASONING_END\":\n this.handleReasoningEnd(this.scopeOf(event), event.timestamp);\n break;\n\n case \"TOOL_CALL_START\": {\n const scope = this.scopeOf(event);\n if (scope === ROOT_SCOPE) {\n this.reportServerMessageId(event.parentMessageId);\n }\n this.startToolCall(\n scope,\n event.toolCallId,\n event.toolCallName,\n event.parentMessageId,\n );\n this.emit();\n break;\n }\n case \"TOOL_CALL_ARGS\": {\n if (!event.delta) break;\n this.appendToolArgs(event.toolCallId, event.delta);\n this.emit();\n break;\n }\n case \"TOOL_CALL_END\": {\n this.emit();\n break;\n }\n case \"TOOL_CALL_RESULT\": {\n this.finishToolCall(\n this.scopeOf(event),\n event.toolCallId,\n event.content ?? \"\",\n typeof event.mcpResult?.isError === \"boolean\"\n ? event.mcpResult.isError\n : event.role === \"tool\"\n ? false\n : undefined,\n event.messageId,\n event.mcpResult,\n event.metadata,\n );\n this.emit();\n break;\n }\n case \"ACTIVITY_SNAPSHOT\": {\n if (event.activityType === A2UI_SURFACE_ACTIVITY_TYPE) {\n this.handleA2uiActivitySnapshot(event);\n break;\n }\n if (event.activityType !== MCP_APPS_ACTIVITY_TYPE) {\n this.handleActivitySnapshot(event);\n break;\n }\n const activityScope = this.scopeOf(event);\n const toolCallId = event.content.toolCallId;\n const fallbackId =\n this.lastResolvedToolCallIdByScope.get(activityScope);\n const entry =\n typeof toolCallId === \"string\"\n ? this.toolCalls.get(toolCallId)\n : fallbackId\n ? this.toolCalls.get(fallbackId)\n : undefined;\n const resourceUri = event.content.resourceUri;\n if (\n entry &&\n typeof resourceUri === \"string\" &&\n isMcpAppUri(resourceUri)\n ) {\n entry.mcpAppResourceUri = resourceUri;\n const id = event.content.serverId;\n const hash = event.content.serverHash;\n if (typeof id === \"string\" && id.length > 0) {\n entry.mcpAppServerId = id;\n } else if (typeof hash === \"string\" && hash.length > 0) {\n entry.mcpAppServerId = hash;\n }\n const result = event.content.result;\n if (isPlainObject(result)) {\n if (\n entry.result !== undefined &&\n entry.modelContent === undefined\n ) {\n entry.modelContent = [\n {\n type: \"text\",\n text:\n typeof entry.result === \"string\"\n ? entry.result\n : JSON.stringify(entry.result),\n },\n ];\n }\n entry.result = result;\n entry.snapshotResultApplied = true;\n if (typeof result.isError === \"boolean\") {\n entry.isError = result.isError;\n }\n }\n this.emit();\n }\n break;\n }\n\n case \"SUBAGENT_STARTED\": {\n // A suspended subagent is re-announced with the same id on resume, so\n // a repeat is a continuation: it may refresh the descriptive fields\n // and reopen the status, but re-parenting an established run would\n // move its already-rendered output to a different tool call.\n const existing = this.subagentRuns.get(event.subagentRunId);\n if (existing) {\n existing.name = event.name;\n if (event.description !== undefined)\n existing.description = event.description;\n existing.status = { type: \"running\" };\n this.emit();\n break;\n }\n this.nestingMemo = undefined;\n this.subagentRuns.set(event.subagentRunId, {\n subagentRunId: event.subagentRunId,\n name: event.name,\n ...(event.description !== undefined\n ? { description: event.description }\n : {}),\n ...(event.parentSubagentRunId !== undefined\n ? { parentSubagentRunId: event.parentSubagentRunId }\n : {}),\n ...(event.parentToolCallId !== undefined\n ? { parentToolCallId: event.parentToolCallId }\n : {}),\n ...(event.parentMessageId !== undefined\n ? { parentMessageId: event.parentMessageId }\n : {}),\n createdAt: new Date(),\n status: { type: \"running\" },\n });\n this.emit();\n break;\n }\n case \"SUBAGENT_FINISHED\": {\n const run = this.subagentRuns.get(event.subagentRunId);\n if (run) {\n run.status =\n event.outcome?.type === \"suspended\"\n ? { type: \"requires-action\", reason: \"interrupt\" }\n : { type: \"complete\", reason: \"unknown\" };\n if (event.result !== undefined) run.result = event.result;\n if (event.outcome?.type === \"suspended\" && event.outcome.interruptIds)\n run.interruptIds = event.outcome.interruptIds;\n }\n this.emit();\n break;\n }\n case \"SUBAGENT_ERROR\": {\n const run = this.subagentRuns.get(event.subagentRunId);\n if (run) {\n run.status = {\n type: \"incomplete\",\n reason: \"error\",\n ...(event.message !== undefined ? { error: event.message } : {}),\n };\n if (event.code !== undefined) run.errorCode = event.code;\n }\n this.emit();\n break;\n }\n\n case \"ACTIVITY_DELTA\": {\n this.handleActivityDelta(event);\n break;\n }\n\n default: {\n this.logger.debug?.(\"[agui] aggregator ignored event\", event);\n }\n }\n }\n\n private handleActivityDelta(\n event: Extract<AgUiEvent, { type: \"ACTIVITY_DELTA\" }>,\n ): void {\n const scope = this.scopeOf(event);\n const existing = this.activityParts.get(\n this.partKey(scope, `message:${event.messageId}`),\n );\n if (!existing) {\n this.logger.debug?.(\"[agui] activity delta has no snapshot\", event);\n return;\n }\n if (event.patch.length === 0) return;\n try {\n const result = jsonpatch.applyPatch(\n existing.value,\n event.patch as Operation[],\n /* validateOperation */ true,\n /* mutateDocument */ false,\n );\n if (!isPlainObject(result.newDocument)) {\n this.logger.debug?.(\n \"[agui] activity delta produced non-object content\",\n event,\n );\n return;\n }\n existing.name = `agui-activity/${event.activityType}`;\n existing.value = result.newDocument;\n this.emit();\n } catch (error) {\n this.logger.error?.(\"[agui] failed to apply activity delta\", error);\n }\n }\n\n private handleA2uiActivitySnapshot(\n event: Extract<AgUiEvent, { type: \"ACTIVITY_SNAPSHOT\" }>,\n ): void {\n const operations = event.content[\"a2ui_operations\"];\n if (!Array.isArray(operations)) return;\n\n const messageId = event.messageId ?? \"a2ui:anonymous\";\n if (event.replace === false && this.a2uiBuckets.has(messageId)) return;\n\n const { state, warnings } = applyA2uiOperations(new Map(), operations);\n for (const warning of warnings) {\n this.logger.debug(\"[agui] a2ui operation warning\", warning);\n }\n this.a2uiBuckets.delete(messageId);\n this.a2uiBuckets.set(messageId, state);\n this.synthesizeA2uiToolCalls();\n this.emit();\n }\n\n private handleActivitySnapshot(\n event: Extract<AgUiEvent, { type: \"ACTIVITY_SNAPSHOT\" }>,\n ): void {\n const scope = this.scopeOf(event);\n const key = this.partKey(\n scope,\n event.messageId !== undefined\n ? `message:${event.messageId}`\n : `type:${event.activityType}`,\n );\n const existing = this.activityParts.get(key);\n if (existing) {\n if (event.replace === false) return;\n existing.name = `agui-activity/${event.activityType}`;\n existing.value = event.content;\n } else {\n const part =\n scope === ROOT_SCOPE\n ? {\n kind: \"data\" as const,\n name: `agui-activity/${event.activityType}`,\n value: event.content,\n }\n : {\n kind: \"data\" as const,\n name: `agui-activity/${event.activityType}`,\n value: event.content,\n subagentRunId: scope,\n };\n this.activityParts.set(key, part);\n this.partOrder.push(part);\n this.activeTextMessageIdByScope.delete(scope);\n }\n this.emit();\n }\n\n private synthesizeA2uiToolCalls(): void {\n const surfaces = new Map<string, A2uiSurfaceState>();\n\n for (const bucket of this.a2uiBuckets.values()) {\n for (const [surfaceId, surface] of bucket) {\n surfaces.set(surfaceId, surface);\n }\n }\n\n const activeToolCallIds = new Set<string>();\n for (const [surfaceId, surface] of surfaces) {\n const { toolCall, warnings } = surfaceToPresentToolCall(\n surfaceId,\n surface,\n );\n for (const warning of warnings) {\n this.logger.debug(\"[agui] a2ui surface conversion warning\", warning);\n }\n if (!toolCall) continue;\n\n const { toolCallId } = toolCall;\n\n activeToolCallIds.add(toolCallId);\n\n const entry: ToolCallState = {\n toolCallId: toolCall.toolCallId,\n toolCallName: toolCall.toolName,\n argsText: toolCall.argsText,\n parsedArgs: toolCall.args,\n result: toolCall.result,\n isError: undefined,\n artifact: toolCall.artifact,\n snapshotResultApplied: false,\n };\n if (!this.toolCalls.has(toolCallId)) {\n this.partOrder.push({ kind: \"tool-call\", toolCallId });\n }\n this.nestingMemo = undefined;\n this.toolCalls.set(toolCallId, entry);\n this.a2uiToolCallIds.add(toolCallId);\n }\n\n for (const toolCallId of this.a2uiToolCallIds) {\n if (activeToolCallIds.has(toolCallId)) continue;\n this.nestingMemo = undefined;\n this.toolCalls.delete(toolCallId);\n const partIndex = this.partOrder.findIndex(\n (part) => part.kind === \"tool-call\" && part.toolCallId === toolCallId,\n );\n if (partIndex !== -1) this.partOrder.splice(partIndex, 1);\n this.a2uiToolCallIds.delete(toolCallId);\n }\n }\n\n private reportServerMessageId(messageId: string | undefined): void {\n if (!messageId) return;\n if (this.lastTextMessageId === undefined) {\n this.lastTextMessageId = messageId;\n }\n if (this.serverMessageIdReported) return;\n this.serverMessageIdReported = true;\n this.reportedServerMessageId = messageId;\n this.onServerMessageId?.(messageId);\n }\n\n private clearTextParts(): void {\n this.textParts.clear();\n }\n\n private resetMessageParts(): void {\n this.clearTextParts();\n this.pendingSnapshotText.clear();\n this.reasoningParts.clear();\n this.reasoningSignatures.clear();\n this.reasoningSignatureIds.clear();\n this.reasoningMessageIds.clear();\n this.hiddenSignatures.clear();\n this.hiddenSignatureAnchors.clear();\n this.hiddenBlockAnchors.clear();\n this.hiddenReasoningIds.clear();\n this.hiddenActiveReasoningId = undefined;\n this.loggedDroppedOpaqueIds.clear();\n this.activeReasoningKeyByScope.clear();\n this.nestingMemo = undefined;\n this.subagentRuns.clear();\n this.toolCalls.clear();\n this.a2uiBuckets.clear();\n this.a2uiToolCallIds.clear();\n this.activityParts.clear();\n this.lastResolvedToolCallIdByScope.clear();\n this.partOrder.length = 0;\n this.lastReasoningBeforeToolCall = undefined;\n this.textPartCounter = 0;\n this.activeTextMessageIdByScope.clear();\n this.reportedServerMessageId = undefined;\n }\n\n // A subagent only ever reports its own terminal, so a run that ends while\n // one is still streaming would leave that nested message spinning forever.\n private closeOpenSubagentRuns(status: MessageStatus): void {\n for (const run of this.subagentRuns.values()) {\n if (run.status.type === \"running\") run.status = status;\n }\n }\n\n private scopeOf(event: { subagentRunId?: string }): string {\n return event.subagentRunId ?? ROOT_SCOPE;\n }\n\n // Nothing in the AG-UI schema makes a messageId unique across subagent runs,\n // so the accumulators key on the scope too. Root keys stay bare, which is\n // what the wire-id collision checks against reported message ids compare on.\n private partKey(scope: string, id: string): string {\n return scope === ROOT_SCOPE ? id : `${scope}\\u0000${id}`;\n }\n\n private beginDistinctTextMessage(\n messageId: string | undefined,\n preserveSnapshotText = false,\n ): void {\n if (\n this.joinStrategy === \"concat-content\" ||\n !messageId ||\n this.lastTextMessageId === undefined ||\n this.lastTextMessageId === messageId ||\n !this.onTextMessageStart\n ) {\n return;\n }\n const carried = this.takeTrailingReasoning();\n if (carried.parts.length > 0 || carried.hiddenSignatures.length > 0) {\n this.emit();\n }\n const openToolCallIds = Array.from(this.toolCalls.values())\n .filter((call) => call.result === undefined)\n .map((call) => call.toolCallId);\n const snapshotText = preserveSnapshotText\n ? this.pendingSnapshotText.get(messageId)\n : undefined;\n this.resetMessageParts();\n if (snapshotText !== undefined) {\n this.pendingSnapshotText.set(messageId, snapshotText);\n }\n this.onTextMessageStart(messageId, openToolCallIds);\n this.restoreReasoning(carried);\n }\n\n private takeTrailingReasoning() {\n const parts: {\n key: string;\n entry: { buffer: string; timing?: MessagePartTiming };\n signature: string | undefined;\n signatureId: string | undefined;\n reasoningId: string | undefined;\n }[] = [];\n let last = this.partOrder.at(-1);\n while (\n last?.kind === \"reasoning\" &&\n last.subagentRunId === undefined &&\n last !== this.lastReasoningBeforeToolCall\n ) {\n this.partOrder.pop();\n parts.unshift({\n key: last.key,\n entry: this.reasoningParts.get(last.key) ?? { buffer: \"\" },\n signature: this.reasoningSignatures.get(last.key),\n signatureId: this.reasoningSignatureIds.get(last.key),\n reasoningId: this.reasoningMessageIds.get(last.key),\n });\n last = this.partOrder.at(-1);\n }\n const cut = this.partOrder.length;\n const hiddenSignatures = Array.from(this.hiddenSignatures).filter(\n ([id]) => this.hiddenSignatureAnchors.get(id)! >= cut,\n );\n for (const [id] of hiddenSignatures) {\n this.hiddenSignatures.delete(id);\n this.hiddenSignatureAnchors.delete(id);\n }\n const hiddenBlockIds = Array.from(this.hiddenBlockAnchors)\n .filter(([, anchor]) => anchor >= cut)\n .map(([id]) => id);\n const hiddenActiveReasoningId = this.hiddenActiveReasoningId;\n return {\n parts,\n activeKey: this.activeReasoningKeyByScope.get(ROOT_SCOPE),\n hiddenSignatures,\n hiddenBlockIds,\n hiddenActiveReasoningId:\n hiddenActiveReasoningId !== undefined &&\n hiddenBlockIds.includes(hiddenActiveReasoningId)\n ? hiddenActiveReasoningId\n : undefined,\n };\n }\n\n private restoreReasoning(\n carried: ReturnType<RunAggregator[\"takeTrailingReasoning\"]>,\n ): void {\n for (const part of carried.parts) {\n this.partOrder.push({ kind: \"reasoning\", key: part.key });\n this.reasoningParts.set(part.key, part.entry);\n if (part.signature !== undefined)\n this.reasoningSignatures.set(part.key, part.signature);\n if (part.signatureId !== undefined)\n this.reasoningSignatureIds.set(part.key, part.signatureId);\n if (part.reasoningId !== undefined)\n this.reasoningMessageIds.set(part.key, part.reasoningId);\n }\n if (\n carried.activeKey !== undefined &&\n this.reasoningParts.has(carried.activeKey)\n ) {\n this.activeReasoningKeyByScope.set(ROOT_SCOPE, carried.activeKey);\n }\n for (const [id, encryptedValue] of carried.hiddenSignatures) {\n this.hiddenSignatures.set(id, encryptedValue);\n this.hiddenSignatureAnchors.set(id, 0);\n }\n for (const id of carried.hiddenBlockIds) {\n this.hiddenReasoningIds.add(id);\n this.hiddenBlockAnchors.set(id, 0);\n }\n this.hiddenActiveReasoningId = carried.hiddenActiveReasoningId;\n }\n\n private generateTextKey(): string {\n this.textPartCounter += 1;\n return `text-${this.textPartCounter}`;\n }\n\n private startTextMessage(scope: string, messageId?: string): string {\n const id = messageId ?? this.generateTextKey();\n const key = this.ensureTextPart(scope, id);\n if (scope === ROOT_SCOPE && messageId) {\n const snapshotText = this.pendingSnapshotText.get(messageId);\n const part = this.textParts.get(key);\n if (snapshotText !== undefined && part) {\n part.buffer = snapshotText;\n this.pendingSnapshotText.delete(messageId);\n }\n }\n this.activeTextMessageIdByScope.set(scope, key);\n return key;\n }\n\n private resolveTextMessageId(scope: string, messageId?: string): string {\n if (messageId) {\n return this.startTextMessage(scope, messageId);\n }\n\n const active = this.activeTextMessageIdByScope.get(scope);\n if (active) {\n return active;\n }\n\n const key = this.ensureTextPart(scope, this.generateTextKey());\n this.activeTextMessageIdByScope.set(scope, key);\n return key;\n }\n\n private ensureTextPart(scope: string, id: string): string {\n const key = this.partKey(scope, id);\n if (!this.textParts.has(key)) {\n this.textParts.set(key, { buffer: \"\" });\n if (\n !this.partOrder.some((part) => part.kind === \"text\" && part.key === key)\n ) {\n this.partOrder.push(\n scope === ROOT_SCOPE\n ? { kind: \"text\", key }\n : { kind: \"text\", key, subagentRunId: scope },\n );\n }\n }\n return key;\n }\n\n private appendText(id: string, delta: string): void {\n const entry = this.textParts.get(id);\n if (!entry) return;\n entry.buffer += delta;\n }\n\n private startToolCall(\n scope: string,\n id: string | undefined,\n name?: string,\n parentMessageId?: string,\n ) {\n if (!id) return;\n // A new tool call acts as a boundary: any anonymous text that arrives\n // after it should be a new part, not appended to the pre-tool text —\n // scoped, so a subagent's tool call doesn't break the root run's text\n // and vice versa.\n this.activeTextMessageIdByScope.delete(scope);\n if (\n !this.partOrder.some(\n (part) => part.kind === \"tool-call\" && part.toolCallId === id,\n )\n ) {\n // Tool insertion can precede existing reasoning in display order.\n if (scope === ROOT_SCOPE) {\n this.lastReasoningBeforeToolCall = this.partOrder.findLast(\n (part) =>\n part.kind === \"reasoning\" && part.subagentRunId === undefined,\n );\n }\n this.insertToolPart(scope, id, parentMessageId);\n }\n const state: ToolCallState = {\n toolCallId: id,\n toolCallName: name ?? \"tool\",\n argsText: \"\",\n parsedArgs: undefined,\n result: undefined,\n isError: undefined,\n snapshotResultApplied: false,\n };\n if (parentMessageId) {\n state.parentMessageId = parentMessageId;\n }\n if (scope !== ROOT_SCOPE) {\n state.subagentRunId = scope;\n }\n this.nestingMemo = undefined;\n this.toolCalls.set(id, state);\n }\n\n // The message and tool-call channels are unordered on the wire, so anchor a\n // tool call under its parentMessageId text part instead of appending it.\n private insertToolPart(scope: string, id: string, parentMessageId?: string) {\n const entry = { kind: \"tool-call\", toolCallId: id } as const;\n if (parentMessageId) {\n const parentKey = this.partKey(scope, parentMessageId);\n const parentIndex = this.partOrder.findIndex(\n (part) => part.kind === \"text\" && part.key === parentKey,\n );\n if (parentIndex !== -1) {\n let insertAt = parentIndex + 1;\n while (insertAt < this.partOrder.length) {\n const part = this.partOrder[insertAt];\n if (\n part?.kind === \"tool-call\" &&\n this.toolCalls.get(part.toolCallId)?.parentMessageId ===\n parentMessageId\n ) {\n insertAt += 1;\n continue;\n }\n break;\n }\n this.partOrder.splice(insertAt, 0, entry);\n return;\n }\n }\n this.partOrder.push(entry);\n }\n\n private appendToolArgs(id: string | undefined, delta: string) {\n const entry = id ? this.toolCalls.get(id) : undefined;\n if (!entry) return;\n if (!entry.argsTextScanner) {\n entry.argsTextScanner = createJSONContainerScanner();\n }\n entry.argsText += delta;\n const shouldParse = scanJSONContainerDelta(entry.argsTextScanner, delta);\n if (!shouldParse) {\n if (entry.argsTextScanner.state === \"invalid\") {\n entry.parsedArgs = undefined;\n }\n return;\n }\n try {\n const parsed = JSON.parse(entry.argsText);\n if (parsed && typeof parsed === \"object\") {\n entry.parsedArgs = parsed as Record<string, unknown>;\n } else {\n entry.parsedArgs = undefined;\n }\n } catch {\n entry.parsedArgs = undefined;\n }\n }\n\n private finishToolCall(\n scope: string,\n id: string,\n content: string | ContentPart[],\n isError?: boolean,\n toolMessageId?: string,\n mcpResult?: Record<string, unknown>,\n metadata?: Record<string, unknown>,\n ) {\n if (!id) return;\n const modelText = toolContentText(content);\n let entry = this.toolCalls.get(id);\n if (!entry) {\n entry = {\n toolCallId: id,\n toolCallName: \"tool\",\n argsText: \"\",\n parsedArgs: undefined,\n result: undefined,\n isError: undefined,\n snapshotResultApplied: false,\n ...(scope !== ROOT_SCOPE ? { subagentRunId: scope } : {}),\n };\n this.nestingMemo = undefined;\n this.toolCalls.set(id, entry);\n }\n if (\n !this.partOrder.some(\n (part) => part.kind === \"tool-call\" && part.toolCallId === id,\n )\n ) {\n this.partOrder.push({ kind: \"tool-call\", toolCallId: id });\n }\n if (mcpResult !== undefined && !entry.snapshotResultApplied) {\n entry.result = mcpResult;\n entry.modelContent = [{ type: \"text\", text: modelText }];\n entry.snapshotResultApplied = true;\n entry.isError = isError;\n if (entry.mcpAppResourceUri === undefined) {\n const uri = readMcpAppResourceUri(mcpResult._meta);\n if (uri !== undefined) entry.mcpAppResourceUri = uri;\n }\n } else if (entry.snapshotResultApplied) {\n if (entry.modelContent === undefined) {\n entry.modelContent = [{ type: \"text\", text: modelText }];\n }\n if (entry.isError === undefined) {\n entry.isError = isError;\n }\n } else {\n entry.result = Array.isArray(content) ? content : tryParseJSON(content);\n if (Array.isArray(content)) {\n delete entry.modelContent;\n }\n entry.isError = isError;\n }\n if (toolMessageId) {\n entry.toolMessageId = toolMessageId;\n }\n if (metadata !== undefined) {\n entry.resultMetadata = { ...entry.resultMetadata, ...metadata };\n }\n this.lastResolvedToolCallIdByScope.set(scope, id);\n }\n\n private nesting(): {\n subagentsByParentToolCallId: Map<string, string[]>;\n reachable: Set<string>;\n } {\n if (!this.nestingMemo) {\n const subagentsByParentToolCallId = this.subagentsByParentToolCallId();\n this.nestingMemo = {\n subagentsByParentToolCallId,\n reachable: this.reachableSubagentRunIds(subagentsByParentToolCallId),\n };\n }\n return this.nestingMemo;\n }\n\n private subagentsByParentToolCallId(): Map<string, string[]> {\n const map = new Map<string, string[]>();\n for (const run of this.subagentRuns.values()) {\n if (!run.parentToolCallId) continue;\n const list = map.get(run.parentToolCallId) ?? [];\n list.push(run.subagentRunId);\n map.set(run.parentToolCallId, list);\n }\n return map;\n }\n\n // A subagent nests under its spawning tool call only when that call is itself\n // reachable from the root scope. A run with no parentToolCallId, one naming a\n // call this run never saw, or one in a cycle has nowhere to hang; the visited\n // set also keeps a malformed chain to one visit per run instead of branching\n // at every level.\n private reachableSubagentRunIds(\n subagentsByParentToolCallId: Map<string, string[]>,\n ): Set<string> {\n const reachable = new Set<string>();\n const walk = (scope: string, depth: number): void => {\n if (depth > MAX_SUBAGENT_DEPTH) return;\n for (const entry of this.toolCalls.values()) {\n if ((entry.subagentRunId ?? ROOT_SCOPE) !== scope) continue;\n for (const id of subagentsByParentToolCallId.get(entry.toolCallId) ??\n []) {\n if (reachable.has(id)) continue;\n reachable.add(id);\n walk(id, depth + 1);\n }\n }\n };\n walk(ROOT_SCOPE, 0);\n return reachable;\n }\n\n // Nested messages rather than a discovery hook (the shape react-langchain\n // uses): ToolCallMessagePart.messages is the contract core consumers already\n // walk, and SUBAGENT_STARTED.parentToolCallId names the spawning call\n // outright, so the join needs no namespace scheme of its own.\n private materializeSubagentMessage(\n subagentRunId: string,\n depth: number,\n ctx: BuildContext,\n ): ThreadMessage | undefined {\n const run = this.subagentRuns.get(subagentRunId);\n if (!run || depth > MAX_SUBAGENT_DEPTH) return undefined;\n const content = this.buildParts(subagentRunId, depth + 1, ctx);\n return {\n id: run.subagentRunId,\n role: \"assistant\",\n createdAt: run.createdAt,\n status: run.status,\n content,\n metadata: {\n unstable_state: null,\n unstable_annotations: [],\n unstable_data: [],\n steps: [],\n custom: {\n [AG_UI_METADATA_NAMESPACE]: {\n name: run.name,\n ...(run.description !== undefined\n ? { description: run.description }\n : {}),\n ...(run.parentSubagentRunId !== undefined\n ? { parentSubagentRunId: run.parentSubagentRunId }\n : {}),\n ...(run.result !== undefined ? { result: run.result } : {}),\n ...(run.interruptIds !== undefined\n ? { interruptIds: run.interruptIds }\n : {}),\n ...(run.errorCode !== undefined\n ? { errorCode: run.errorCode }\n : {}),\n },\n },\n },\n } as ThreadMessage;\n }\n\n private buildParts(\n scope: string,\n depth: number,\n ctx: BuildContext,\n ): ThreadAssistantMessagePart[] {\n const snapshot: ThreadAssistantMessagePart[] = [];\n const isRoot = scope === ROOT_SCOPE;\n\n for (const { index, part } of ctx.partsByScope.get(scope) ?? []) {\n const materialized = () => {\n if (isRoot && ctx.root) ctx.root.lastMaterializedIndex = index;\n };\n\n if (part.kind === \"tool-call\") {\n const entry = this.toolCalls.get(part.toolCallId);\n if (!entry) continue;\n const approval = ctx.approvals.get(entry.toolCallId);\n const nestedMessages = (\n ctx.subagentsByParentToolCallId.get(entry.toolCallId) ?? []\n )\n .filter((id) => ctx.reachable.has(id))\n .map((id) => this.materializeSubagentMessage(id, depth, ctx))\n .filter((m): m is ThreadMessage => m !== undefined);\n const toolPart: ToolCallMessagePart = {\n type: \"tool-call\",\n toolCallId: entry.toolCallId,\n toolName: entry.toolCallName,\n args: (entry.parsedArgs ?? {}) as any,\n argsText: entry.argsText,\n ...(approval ? { approval } : {}),\n ...(entry.result !== undefined ? { result: entry.result } : {}),\n ...(entry.artifact !== undefined ? { artifact: entry.artifact } : {}),\n ...(entry.modelContent !== undefined\n ? { modelContent: entry.modelContent }\n : {}),\n ...(entry.isError !== undefined ? { isError: entry.isError } : {}),\n ...(entry.mcpAppResourceUri\n ? {\n mcp: {\n app: {\n resourceUri: entry.mcpAppResourceUri,\n ...(entry.mcpAppServerId\n ? { serverId: entry.mcpAppServerId }\n : {}),\n },\n },\n }\n : {}),\n ...(entry.parentMessageId ? { parentId: entry.parentMessageId } : {}),\n ...(entry.toolMessageId\n ? { unstable_toolMessageId: entry.toolMessageId }\n : {}),\n ...(entry.resultMetadata !== undefined\n ? {\n providerMetadata: withAgUiPartMessageMetadata(\n undefined,\n entry.resultMetadata,\n ),\n }\n : {}),\n ...(nestedMessages.length > 0 ? { messages: nestedMessages } : {}),\n } as ToolCallMessagePart & { unstable_toolMessageId?: string };\n snapshot.push(toolPart);\n materialized();\n continue;\n }\n\n const rawScope =\n \"subagentRunId\" in part\n ? (part.subagentRunId ?? ROOT_SCOPE)\n : ROOT_SCOPE;\n\n if (part.kind === \"reasoning\") {\n if (this.showThinking) {\n const entry = this.reasoningParts.get(part.key);\n const buffer = entry?.buffer ?? \"\";\n const isActive =\n this.activeReasoningKeyByScope.get(rawScope) === part.key;\n if (buffer.length > 0 || isActive) {\n const encryptedValue = this.reasoningSignatures.get(part.key);\n const reasoningId = this.reasoningMessageIds.get(part.key);\n const meta = {\n ...(reasoningId !== undefined ? { reasoningId } : {}),\n ...(encryptedValue !== undefined ? { encryptedValue } : {}),\n };\n snapshot.push({\n type: \"reasoning\",\n text: buffer,\n ...(entry?.timing ? { timing: entry.timing } : {}),\n ...(Object.keys(meta).length > 0\n ? { providerMetadata: { [AG_UI_METADATA_NAMESPACE]: meta } }\n : {}),\n } as const);\n materialized();\n } else if (isRoot && ctx.root) {\n // A retracted empty block still carries transport state: without\n // a part to live on, its signature rides the message metadata,\n // matching the shape a snapshot reload produces.\n const encryptedValue = this.reasoningSignatures.get(part.key);\n const id = this.reasoningSignatureIds.get(part.key);\n if (id?.trim() && encryptedValue?.trim()) {\n ctx.root.opaqueCandidates.push({\n id,\n encryptedValue,\n anchor: index + 1,\n });\n }\n }\n }\n continue;\n }\n\n if (part.kind === \"text\") {\n const entry = this.textParts.get(part.key);\n if (entry && entry.buffer.trim().length > 0) {\n snapshot.push({ type: \"text\", text: entry.buffer } as const);\n materialized();\n }\n continue;\n }\n\n if (part.kind === \"data\") {\n snapshot.push({\n type: \"data\",\n name: part.name,\n data: part.value,\n });\n materialized();\n continue;\n }\n }\n\n return snapshot;\n }\n\n private emit(): void {\n const { subagentsByParentToolCallId, reachable } = this.nesting();\n const root = {\n opaqueCandidates: Array.from(\n this.hiddenSignatures,\n ([id, encryptedValue]) => ({\n id,\n encryptedValue,\n anchor: this.hiddenSignatureAnchors.get(id)!,\n }),\n ) as (AgUiOpaqueReasoning & { anchor: number })[],\n lastMaterializedIndex: -1,\n };\n // A run that ended incomplete can no longer be resumed, so a gate left over\n // from an earlier interrupt outcome is unanswerable and must not stay\n // projected. The interrupts themselves are kept on the message, since the\n // bespoke hooks read that payload. Bound ids cover every call the run\n // produced, root or nested: the approval seams walk\n // ToolCallMessagePart.messages, so a gate naming a subagent-scoped call is\n // answerable and projects onto the nested part.\n const partsByScope = new Map<\n string,\n { index: number; part: PartOrderEntry }[]\n >();\n for (const [index, part] of this.partOrder.entries()) {\n const rawScope =\n part.kind === \"tool-call\"\n ? (this.toolCalls.get(part.toolCallId)?.subagentRunId ?? ROOT_SCOPE)\n : \"subagentRunId\" in part\n ? (part.subagentRunId ?? ROOT_SCOPE)\n : ROOT_SCOPE;\n const bucketScope =\n rawScope === ROOT_SCOPE || reachable.has(rawScope)\n ? rawScope\n : ROOT_SCOPE;\n const bucket = partsByScope.get(bucketScope);\n if (bucket) bucket.push({ index, part });\n else partsByScope.set(bucketScope, [{ index, part }]);\n }\n const ctx: BuildContext = {\n subagentsByParentToolCallId,\n reachable,\n partsByScope,\n approvals: projectAgUiToolApprovals(\n this.status?.type === \"requires-action\" ? this.interrupts : undefined,\n new Set(\n Array.from(this.toolCalls.values()).map((entry) => entry.toolCallId),\n ),\n ),\n root,\n };\n const snapshot = this.buildParts(ROOT_SCOPE, 0, ctx);\n const { opaqueCandidates, lastMaterializedIndex } = root;\n\n const toolMessageIds = new Set<string>();\n for (const call of this.toolCalls.values()) {\n if (call.toolMessageId) toolMessageIds.add(call.toolMessageId);\n }\n opaqueCandidates.sort((a, b) => a.anchor - b.anchor);\n const publishableOpaqueReasoning = opaqueCandidates\n .filter((entry) => {\n const collides =\n this.textParts.has(entry.id) ||\n entry.id === this.reportedServerMessageId ||\n toolMessageIds.has(entry.id);\n if (collides && !this.loggedDroppedOpaqueIds.has(entry.id)) {\n this.loggedDroppedOpaqueIds.add(entry.id);\n this.logger.debug?.(\n \"[agui] aggregator dropped opaque reasoning signature: id collides with a message id\",\n entry.id,\n );\n }\n return !collides;\n })\n .map(({ anchor, ...entry }) =>\n lastMaterializedIndex < anchor ? { ...entry, after: true } : entry,\n );\n if (publishableOpaqueReasoning.length > 0)\n this.hasEmittedOpaqueReasoning = true;\n // Once an opaque entry has been published this run, the key keeps being\n // emitted (empty when withdrawn) so the namespace merge can retract it.\n const includeOpaque = this.hasEmittedOpaqueReasoning;\n const timing = this.getTiming();\n const metadata = {\n ...(timing ? { timing } : {}),\n ...(this.interrupts ||\n (this.status?.type === \"requires-action\" &&\n this.status.reason === \"tool-calls\" &&\n this.pendingToolCallIds) ||\n includeOpaque\n ? {\n custom: {\n [AG_UI_METADATA_NAMESPACE]: {\n ...(this.interrupts ? { interrupts: this.interrupts } : {}),\n ...(this.status?.type === \"requires-action\" &&\n this.status.reason === \"tool-calls\" &&\n this.pendingToolCallIds\n ? { pendingToolCallIds: this.pendingToolCallIds }\n : {}),\n ...(includeOpaque\n ? { opaqueReasoning: publishableOpaqueReasoning }\n : {}),\n } satisfies AgUiCustomMetadata,\n },\n }\n : {}),\n };\n const result: ChatModelRunResult = {\n content: snapshot,\n ...(this.status ? { status: this.status } : undefined),\n ...(Object.keys(metadata).length > 0 ? { metadata } : undefined),\n };\n this.emitUpdate(result);\n }\n\n private recordFirstToken(): void {\n if (\n this.firstTokenTime === undefined &&\n this.streamStartTime !== undefined\n ) {\n this.firstTokenTime = Date.now() - this.streamStartTime;\n }\n }\n\n private getTiming(): MessageTiming | undefined {\n if (this.streamStartTime === undefined) return undefined;\n\n const now = Date.now();\n const totalStreamTime = now - this.streamStartTime;\n const tokenCount =\n this.totalChunks > 0\n ? Math.ceil(\n Array.from(this.textParts.values()).reduce(\n (sum, p) => sum + p.buffer.length,\n 0,\n ) / 4,\n )\n : undefined;\n const tokensPerSecond =\n tokenCount && totalStreamTime > 0\n ? (tokenCount / totalStreamTime) * 1000\n : undefined;\n\n return {\n streamStartTime: this.streamStartTime,\n ...(this.firstTokenTime !== undefined\n ? { firstTokenTime: this.firstTokenTime }\n : {}),\n totalStreamTime,\n ...(tokenCount !== undefined ? { tokenCount } : {}),\n ...(tokensPerSecond !== undefined ? { tokensPerSecond } : {}),\n totalChunks: this.totalChunks,\n toolCallCount: this.toolCalls.size,\n };\n }\n\n private handleReasoningStart(\n scope: string,\n messageId: string,\n isMessageId = false,\n timestamp?: number,\n ): void {\n if (!this.showThinking) {\n if (scope !== ROOT_SCOPE) return;\n const anchor = this.partOrder.length;\n this.hiddenReasoningIds.add(messageId);\n this.hiddenBlockAnchors.set(messageId, anchor);\n this.hiddenActiveReasoningId = messageId;\n return;\n }\n // A reasoning block acts as a boundary: anonymous text arriving after it\n // should be a new part, not appended to any pre-reasoning text — scoped.\n this.activeTextMessageIdByScope.delete(scope);\n const key = this.partKey(scope, messageId);\n if (isMessageId) {\n this.reasoningMessageIds.set(key, messageId);\n }\n if (!this.reasoningParts.has(key)) {\n this.reasoningParts.set(key, { buffer: \"\" });\n this.partOrder.push(\n scope === ROOT_SCOPE\n ? { kind: \"reasoning\", key }\n : { kind: \"reasoning\", key, subagentRunId: scope },\n );\n }\n const entry = this.reasoningParts.get(key);\n if (entry?.timing) {\n entry.timing = { startedAt: entry.timing.startedAt };\n } else if (\n entry &&\n typeof timestamp === \"number\" &&\n Number.isFinite(timestamp)\n ) {\n entry.timing = { startedAt: timestamp };\n }\n this.activeReasoningKeyByScope.set(scope, key);\n this.emit();\n }\n\n private handleReasoningContent(\n scope: string,\n delta: string,\n messageId: string,\n isMessageId = false,\n ): void {\n if (!delta) return;\n if (!this.showThinking) {\n // Content without a preceding START still names the block (the visible\n // path opens it lazily); register it so a signature can claim it.\n if (scope !== ROOT_SCOPE) return;\n if (this.hiddenActiveReasoningId === undefined) {\n this.handleReasoningStart(scope, messageId, isMessageId);\n }\n return;\n }\n if (!this.activeReasoningKeyByScope.has(scope)) {\n // Content arrived without a preceding START — create the slot lazily.\n this.handleReasoningStart(scope, messageId, isMessageId);\n }\n const key = this.activeReasoningKeyByScope.get(scope);\n if (!key) return;\n const entry = this.reasoningParts.get(key);\n if (entry) entry.buffer += delta;\n this.emit();\n }\n\n private handleReasoningEnd(scope: string, timestamp?: number): void {\n if (!this.showThinking) {\n if (scope === ROOT_SCOPE) this.hiddenActiveReasoningId = undefined;\n return;\n }\n const key = this.activeReasoningKeyByScope.get(scope);\n const entry = key ? this.reasoningParts.get(key) : undefined;\n if (\n entry?.timing &&\n typeof timestamp === \"number\" &&\n Number.isFinite(timestamp)\n ) {\n entry.timing = { ...entry.timing, completedAt: timestamp };\n }\n this.activeReasoningKeyByScope.delete(scope);\n this.emit();\n }\n}\n\nexport function tryParseJSON(value: string): unknown {\n if (!value) return value;\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n}\n"],"mappings":";;;;;;;;;AAqCA,MAAM,aAAa;AAoEnB,MAAM,oCAA0D;CAC9D,OAAO;CACP,OAAO,CAAC;CACR,UAAU;CACV,SAAS;AACX;AAEA,MAAM,oBAAoB,SACxB,SAAS,OAAO,SAAS,O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C/D,uBAAuB,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IAChE,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IAC7D,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IAC3D,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IACxD,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IAC3D,mBAAmB,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IAC5D,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,KAAK,IAAI,CAAC;CACnD,CAAC;AAsBF,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACtC,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,SAAS,iBAAiB,KACzB,UA8FF,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
|
@@ -11,7 +11,7 @@ const ensureEvent = (raw, type, logger) => {
|
|
|
11
11
|
return parsed && parsed.type === type ? parsed : null;
|
|
12
12
|
};
|
|
13
13
|
const createAgUiSubscriber = (options) => {
|
|
14
|
-
const { dispatch,
|
|
14
|
+
const { dispatch, logger, onRunFailed } = options;
|
|
15
15
|
let runFinishedDispatched = false;
|
|
16
16
|
const dispatchIfValid = (raw, type) => {
|
|
17
17
|
const event = ensureEvent(raw, type, logger);
|
|
@@ -59,13 +59,6 @@ const createAgUiSubscriber = (options) => {
|
|
|
59
59
|
},
|
|
60
60
|
onStepStartedEvent: ({ event }) => logger?.debug?.("[agui] step boundary ignored", event),
|
|
61
61
|
onStepFinishedEvent: ({ event }) => logger?.debug?.("[agui] step boundary ignored", event),
|
|
62
|
-
onRunFinalized: () => {
|
|
63
|
-
if (runFinishedDispatched) return;
|
|
64
|
-
dispatch({
|
|
65
|
-
type: "RUN_FINISHED",
|
|
66
|
-
runId
|
|
67
|
-
});
|
|
68
|
-
},
|
|
69
62
|
onRunFailed: ({ error }) => {
|
|
70
63
|
if (runFinishedDispatched) return;
|
|
71
64
|
runFinishedDispatched = true;
|