@assistant-ui/react-ag-ui 0.0.56 → 0.0.57
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/dist/runtime/AgUiThreadRuntimeCore.d.ts +2 -13
- package/dist/runtime/AgUiThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtime/AgUiThreadRuntimeCore.js +106 -193
- package/dist/runtime/AgUiThreadRuntimeCore.js.map +1 -1
- package/dist/runtime/adapter/conversions.d.ts.map +1 -1
- package/dist/runtime/adapter/conversions.js +20 -14
- package/dist/runtime/adapter/conversions.js.map +1 -1
- package/dist/runtime/adapter/run-aggregator.d.ts +18 -1
- package/dist/runtime/adapter/run-aggregator.d.ts.map +1 -1
- package/dist/runtime/adapter/run-aggregator.js +130 -41
- package/dist/runtime/adapter/run-aggregator.js.map +1 -1
- package/dist/useAgUiRuntime.js +11 -9
- package/dist/useAgUiRuntime.js.map +1 -1
- package/package.json +8 -8
- package/src/runtime/AgUiThreadRuntimeCore.test.ts +105 -0
- package/src/runtime/AgUiThreadRuntimeCore.ts +152 -261
- package/src/runtime/adapter/conversions.ts +41 -19
- package/src/runtime/adapter/run-aggregator.ts +198 -47
- package/src/useAgUiRuntime.history.test.tsx +76 -0
- package/src/useAgUiRuntime.ts +11 -9
|
@@ -23,12 +23,22 @@ var RunAggregator = class {
|
|
|
23
23
|
showThinking;
|
|
24
24
|
logger;
|
|
25
25
|
onServerMessageId;
|
|
26
|
+
onTextMessageStart;
|
|
26
27
|
status;
|
|
27
28
|
interrupts;
|
|
28
29
|
textParts = /* @__PURE__ */ new Map();
|
|
29
30
|
activeTextMessageId;
|
|
30
31
|
reasoningParts = /* @__PURE__ */ new Map();
|
|
31
32
|
reasoningSignatures = /* @__PURE__ */ new Map();
|
|
33
|
+
reasoningSignatureIds = /* @__PURE__ */ new Map();
|
|
34
|
+
hiddenSignatures = /* @__PURE__ */ new Map();
|
|
35
|
+
hiddenSignatureAnchors = /* @__PURE__ */ new Map();
|
|
36
|
+
hiddenBlockAnchors = /* @__PURE__ */ new Map();
|
|
37
|
+
hiddenAnonymousAnchor;
|
|
38
|
+
hiddenReasoningIds = /* @__PURE__ */ new Set();
|
|
39
|
+
hiddenActiveReasoning = "none";
|
|
40
|
+
hasEmittedOpaqueReasoning = false;
|
|
41
|
+
loggedDroppedOpaqueIds = /* @__PURE__ */ new Set();
|
|
32
42
|
reasoningMessageIds = /* @__PURE__ */ new Map();
|
|
33
43
|
anonymousReasoningKeys = /* @__PURE__ */ new Set();
|
|
34
44
|
activeReasoningKey;
|
|
@@ -40,6 +50,8 @@ var RunAggregator = class {
|
|
|
40
50
|
partOrder = [];
|
|
41
51
|
textPartCounter = 0;
|
|
42
52
|
serverMessageIdReported = false;
|
|
53
|
+
reportedServerMessageId;
|
|
54
|
+
lastTextMessageId;
|
|
43
55
|
streamStartTime;
|
|
44
56
|
firstTokenTime;
|
|
45
57
|
totalChunks = 0;
|
|
@@ -48,6 +60,7 @@ var RunAggregator = class {
|
|
|
48
60
|
this.showThinking = options.showThinking;
|
|
49
61
|
this.logger = options.logger;
|
|
50
62
|
this.onServerMessageId = options.onServerMessageId;
|
|
63
|
+
this.onTextMessageStart = options.onTextMessageStart;
|
|
51
64
|
}
|
|
52
65
|
hasToolCall(toolCallId) {
|
|
53
66
|
return this.toolCalls.has(toolCallId);
|
|
@@ -55,22 +68,11 @@ var RunAggregator = class {
|
|
|
55
68
|
handle(event) {
|
|
56
69
|
switch (event.type) {
|
|
57
70
|
case "RUN_STARTED":
|
|
58
|
-
this.
|
|
59
|
-
this.reasoningParts.clear();
|
|
60
|
-
this.reasoningSignatures.clear();
|
|
61
|
-
this.reasoningMessageIds.clear();
|
|
62
|
-
this.anonymousReasoningKeys.clear();
|
|
63
|
-
this.activeReasoningKey = void 0;
|
|
64
|
-
this.reasoningPartCounter = 0;
|
|
65
|
-
this.toolCalls.clear();
|
|
66
|
-
this.a2uiBuckets.clear();
|
|
67
|
-
this.a2uiToolCallIds.clear();
|
|
68
|
-
this.lastResolvedToolCallId = void 0;
|
|
69
|
-
this.partOrder.length = 0;
|
|
70
|
-
this.textPartCounter = 0;
|
|
71
|
-
this.activeTextMessageId = void 0;
|
|
71
|
+
this.resetMessageParts();
|
|
72
72
|
this.interrupts = void 0;
|
|
73
73
|
this.serverMessageIdReported = false;
|
|
74
|
+
this.lastTextMessageId = void 0;
|
|
75
|
+
this.reportedServerMessageId = void 0;
|
|
74
76
|
this.streamStartTime = Date.now();
|
|
75
77
|
this.firstTokenTime = void 0;
|
|
76
78
|
this.totalChunks = 0;
|
|
@@ -114,17 +116,19 @@ var RunAggregator = class {
|
|
|
114
116
|
};
|
|
115
117
|
this.emit();
|
|
116
118
|
break;
|
|
117
|
-
case "TEXT_MESSAGE_START":
|
|
119
|
+
case "TEXT_MESSAGE_START":
|
|
120
|
+
this.beginDistinctTextMessage(event.messageId);
|
|
118
121
|
this.reportServerMessageId(event.messageId);
|
|
119
|
-
|
|
120
|
-
if (
|
|
122
|
+
this.startTextMessage(event.messageId);
|
|
123
|
+
if (event.messageId) this.lastTextMessageId = event.messageId;
|
|
121
124
|
this.emit();
|
|
122
125
|
break;
|
|
123
|
-
}
|
|
124
126
|
case "TEXT_MESSAGE_CONTENT":
|
|
125
127
|
case "TEXT_MESSAGE_CHUNK": {
|
|
126
128
|
const incomingId = "messageId" in event ? event.messageId : void 0;
|
|
129
|
+
this.beginDistinctTextMessage(incomingId);
|
|
127
130
|
this.reportServerMessageId(incomingId);
|
|
131
|
+
if (incomingId) this.lastTextMessageId = incomingId;
|
|
128
132
|
if (!event.delta) break;
|
|
129
133
|
this.recordFirstToken();
|
|
130
134
|
const id = this.resolveTextMessageId(incomingId);
|
|
@@ -156,9 +160,14 @@ var RunAggregator = class {
|
|
|
156
160
|
case "REASONING_ENCRYPTED_VALUE":
|
|
157
161
|
if (event.subtype === "message") {
|
|
158
162
|
const active = this.activeReasoningKey;
|
|
159
|
-
const key = this.reasoningParts.has(event.entityId) ? event.entityId : active !== void 0 && this.anonymousReasoningKeys.has(active) ? active : void 0;
|
|
163
|
+
const key = this.showThinking ? this.reasoningParts.has(event.entityId) ? event.entityId : active !== void 0 && this.anonymousReasoningKeys.has(active) ? active : void 0 : void 0;
|
|
160
164
|
if (key !== void 0) {
|
|
161
165
|
this.reasoningSignatures.set(key, event.encryptedValue);
|
|
166
|
+
this.reasoningSignatureIds.set(key, event.entityId);
|
|
167
|
+
this.emit();
|
|
168
|
+
} else if (!this.showThinking && event.entityId.trim().length > 0 && event.encryptedValue.trim().length > 0 && (this.hiddenReasoningIds.has(event.entityId) || this.hiddenActiveReasoning === "anonymous")) {
|
|
169
|
+
this.hiddenSignatures.set(event.entityId, event.encryptedValue);
|
|
170
|
+
this.hiddenSignatureAnchors.set(event.entityId, this.hiddenBlockAnchors.get(event.entityId) ?? this.hiddenAnonymousAnchor ?? this.partOrder.length);
|
|
162
171
|
this.emit();
|
|
163
172
|
}
|
|
164
173
|
}
|
|
@@ -277,13 +286,46 @@ var RunAggregator = class {
|
|
|
277
286
|
}
|
|
278
287
|
}
|
|
279
288
|
reportServerMessageId(messageId) {
|
|
280
|
-
if (
|
|
289
|
+
if (!messageId) return;
|
|
290
|
+
if (this.lastTextMessageId === void 0) this.lastTextMessageId = messageId;
|
|
291
|
+
if (this.serverMessageIdReported) return;
|
|
281
292
|
this.serverMessageIdReported = true;
|
|
293
|
+
this.reportedServerMessageId = messageId;
|
|
282
294
|
this.onServerMessageId?.(messageId);
|
|
283
295
|
}
|
|
284
296
|
clearTextParts() {
|
|
285
297
|
this.textParts.clear();
|
|
286
298
|
}
|
|
299
|
+
resetMessageParts() {
|
|
300
|
+
this.clearTextParts();
|
|
301
|
+
this.reasoningParts.clear();
|
|
302
|
+
this.reasoningSignatures.clear();
|
|
303
|
+
this.reasoningSignatureIds.clear();
|
|
304
|
+
this.reasoningMessageIds.clear();
|
|
305
|
+
this.hiddenSignatures.clear();
|
|
306
|
+
this.hiddenSignatureAnchors.clear();
|
|
307
|
+
this.hiddenBlockAnchors.clear();
|
|
308
|
+
this.hiddenAnonymousAnchor = void 0;
|
|
309
|
+
this.hiddenReasoningIds.clear();
|
|
310
|
+
this.hiddenActiveReasoning = "none";
|
|
311
|
+
this.loggedDroppedOpaqueIds.clear();
|
|
312
|
+
this.anonymousReasoningKeys.clear();
|
|
313
|
+
this.activeReasoningKey = void 0;
|
|
314
|
+
this.reasoningPartCounter = 0;
|
|
315
|
+
this.toolCalls.clear();
|
|
316
|
+
this.a2uiBuckets.clear();
|
|
317
|
+
this.a2uiToolCallIds.clear();
|
|
318
|
+
this.lastResolvedToolCallId = void 0;
|
|
319
|
+
this.partOrder.length = 0;
|
|
320
|
+
this.textPartCounter = 0;
|
|
321
|
+
this.activeTextMessageId = void 0;
|
|
322
|
+
this.reportedServerMessageId = void 0;
|
|
323
|
+
}
|
|
324
|
+
beginDistinctTextMessage(messageId) {
|
|
325
|
+
if (!messageId || this.lastTextMessageId === void 0 || this.lastTextMessageId === messageId || !this.onTextMessageStart) return;
|
|
326
|
+
this.resetMessageParts();
|
|
327
|
+
this.onTextMessageStart(messageId);
|
|
328
|
+
}
|
|
287
329
|
generateTextKey() {
|
|
288
330
|
this.textPartCounter += 1;
|
|
289
331
|
return `text-${this.textPartCounter}`;
|
|
@@ -308,27 +350,18 @@ var RunAggregator = class {
|
|
|
308
350
|
}
|
|
309
351
|
ensureTextPart(id) {
|
|
310
352
|
if (!this.textParts.has(id)) {
|
|
311
|
-
this.textParts.set(id, {
|
|
312
|
-
buffer: "",
|
|
313
|
-
touched: false
|
|
314
|
-
});
|
|
353
|
+
this.textParts.set(id, { buffer: "" });
|
|
315
354
|
if (!this.partOrder.some((part) => part.kind === "text" && part.key === id)) this.partOrder.push({
|
|
316
355
|
kind: "text",
|
|
317
356
|
key: id
|
|
318
357
|
});
|
|
319
358
|
}
|
|
320
359
|
}
|
|
321
|
-
markTextPartTouched(id) {
|
|
322
|
-
const entry = this.textParts.get(id);
|
|
323
|
-
if (!entry) return;
|
|
324
|
-
entry.touched = true;
|
|
325
|
-
}
|
|
326
360
|
appendText(id, delta) {
|
|
327
361
|
this.ensureTextPart(id);
|
|
328
362
|
const entry = this.textParts.get(id);
|
|
329
363
|
if (!entry) return;
|
|
330
364
|
entry.buffer += delta;
|
|
331
|
-
entry.touched = true;
|
|
332
365
|
}
|
|
333
366
|
startToolCall(id, name, parentMessageId) {
|
|
334
367
|
if (!id) return;
|
|
@@ -428,7 +461,19 @@ var RunAggregator = class {
|
|
|
428
461
|
emit() {
|
|
429
462
|
const snapshot = [];
|
|
430
463
|
const approvals = projectAgUiToolApprovals(this.status?.type === "requires-action" ? this.interrupts : void 0, new Set(this.toolCalls.keys()));
|
|
431
|
-
|
|
464
|
+
const opaqueCandidates = Array.from(this.hiddenSignatures, ([id, encryptedValue]) => ({
|
|
465
|
+
id,
|
|
466
|
+
encryptedValue,
|
|
467
|
+
anchor: this.hiddenSignatureAnchors.get(id)
|
|
468
|
+
}));
|
|
469
|
+
let currentIndex = -1;
|
|
470
|
+
let lastMaterializedIndex = -1;
|
|
471
|
+
const pushSnapshotPart = (part) => {
|
|
472
|
+
snapshot.push(part);
|
|
473
|
+
lastMaterializedIndex = currentIndex;
|
|
474
|
+
};
|
|
475
|
+
for (const [index, part] of this.partOrder.entries()) {
|
|
476
|
+
currentIndex = index;
|
|
432
477
|
if (part.kind === "reasoning") {
|
|
433
478
|
if (this.showThinking) {
|
|
434
479
|
const buffer = this.reasoningParts.get(part.key) ?? "";
|
|
@@ -439,25 +484,33 @@ var RunAggregator = class {
|
|
|
439
484
|
...reasoningId !== void 0 ? { reasoningId } : {},
|
|
440
485
|
...encryptedValue !== void 0 ? { encryptedValue } : {}
|
|
441
486
|
};
|
|
442
|
-
|
|
487
|
+
pushSnapshotPart({
|
|
443
488
|
type: "reasoning",
|
|
444
489
|
text: buffer,
|
|
445
490
|
...Object.keys(meta).length > 0 ? { providerMetadata: { [AG_UI_METADATA_NAMESPACE]: meta } } : {}
|
|
446
491
|
});
|
|
492
|
+
} else {
|
|
493
|
+
const encryptedValue = this.reasoningSignatures.get(part.key);
|
|
494
|
+
const id = this.reasoningSignatureIds.get(part.key);
|
|
495
|
+
if (id?.trim() && encryptedValue?.trim()) opaqueCandidates.push({
|
|
496
|
+
id,
|
|
497
|
+
encryptedValue,
|
|
498
|
+
anchor: index + 1
|
|
499
|
+
});
|
|
447
500
|
}
|
|
448
501
|
}
|
|
449
502
|
continue;
|
|
450
503
|
}
|
|
451
504
|
if (part.kind === "text") {
|
|
452
505
|
const entry = this.textParts.get(part.key);
|
|
453
|
-
if (entry
|
|
506
|
+
if (entry && entry.buffer.trim().length > 0) pushSnapshotPart({
|
|
454
507
|
type: "text",
|
|
455
508
|
text: entry.buffer
|
|
456
509
|
});
|
|
457
510
|
continue;
|
|
458
511
|
}
|
|
459
512
|
if (part.kind === "data") {
|
|
460
|
-
|
|
513
|
+
pushSnapshotPart({
|
|
461
514
|
type: "data",
|
|
462
515
|
name: part.name,
|
|
463
516
|
data: part.value
|
|
@@ -467,7 +520,7 @@ var RunAggregator = class {
|
|
|
467
520
|
const entry = this.toolCalls.get(part.toolCallId);
|
|
468
521
|
if (!entry) continue;
|
|
469
522
|
const approval = approvals.get(entry.toolCallId);
|
|
470
|
-
|
|
523
|
+
pushSnapshotPart({
|
|
471
524
|
type: "tool-call",
|
|
472
525
|
toolCallId: entry.toolCallId,
|
|
473
526
|
toolName: entry.toolCallName,
|
|
@@ -483,13 +536,31 @@ var RunAggregator = class {
|
|
|
483
536
|
} } } : {},
|
|
484
537
|
...entry.parentMessageId ? { parentId: entry.parentMessageId } : {},
|
|
485
538
|
...entry.toolMessageId ? { unstable_toolMessageId: entry.toolMessageId } : {}
|
|
486
|
-
};
|
|
487
|
-
snapshot.push(toolPart);
|
|
539
|
+
});
|
|
488
540
|
}
|
|
541
|
+
const toolMessageIds = /* @__PURE__ */ new Set();
|
|
542
|
+
for (const call of this.toolCalls.values()) if (call.toolMessageId) toolMessageIds.add(call.toolMessageId);
|
|
543
|
+
opaqueCandidates.sort((a, b) => a.anchor - b.anchor);
|
|
544
|
+
const publishableOpaqueReasoning = opaqueCandidates.filter((entry) => {
|
|
545
|
+
const collides = this.textParts.has(entry.id) || entry.id === this.reportedServerMessageId || toolMessageIds.has(entry.id);
|
|
546
|
+
if (collides && !this.loggedDroppedOpaqueIds.has(entry.id)) {
|
|
547
|
+
this.loggedDroppedOpaqueIds.add(entry.id);
|
|
548
|
+
this.logger.debug?.("[agui] aggregator dropped opaque reasoning signature: id collides with a message id", entry.id);
|
|
549
|
+
}
|
|
550
|
+
return !collides;
|
|
551
|
+
}).map(({ anchor, ...entry }) => lastMaterializedIndex < anchor ? {
|
|
552
|
+
...entry,
|
|
553
|
+
after: true
|
|
554
|
+
} : entry);
|
|
555
|
+
if (publishableOpaqueReasoning.length > 0) this.hasEmittedOpaqueReasoning = true;
|
|
556
|
+
const includeOpaque = this.hasEmittedOpaqueReasoning;
|
|
489
557
|
const timing = this.getTiming();
|
|
490
558
|
const metadata = {
|
|
491
559
|
...timing ? { timing } : {},
|
|
492
|
-
...this.interrupts ? { custom: { [AG_UI_METADATA_NAMESPACE]: {
|
|
560
|
+
...this.interrupts || includeOpaque ? { custom: { [AG_UI_METADATA_NAMESPACE]: {
|
|
561
|
+
...this.interrupts ? { interrupts: this.interrupts } : {},
|
|
562
|
+
...includeOpaque ? { opaqueReasoning: publishableOpaqueReasoning } : {}
|
|
563
|
+
} } } : {}
|
|
493
564
|
};
|
|
494
565
|
const result = {
|
|
495
566
|
content: snapshot,
|
|
@@ -517,7 +588,18 @@ var RunAggregator = class {
|
|
|
517
588
|
};
|
|
518
589
|
}
|
|
519
590
|
handleReasoningStart(messageId, isMessageId = false) {
|
|
520
|
-
if (!this.showThinking)
|
|
591
|
+
if (!this.showThinking) {
|
|
592
|
+
const anchor = this.partOrder.length;
|
|
593
|
+
if (messageId === void 0) {
|
|
594
|
+
this.hiddenActiveReasoning = "anonymous";
|
|
595
|
+
this.hiddenAnonymousAnchor = anchor;
|
|
596
|
+
} else {
|
|
597
|
+
this.hiddenReasoningIds.add(messageId);
|
|
598
|
+
this.hiddenBlockAnchors.set(messageId, anchor);
|
|
599
|
+
this.hiddenActiveReasoning = "identified";
|
|
600
|
+
}
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
521
603
|
this.activeTextMessageId = void 0;
|
|
522
604
|
const key = messageId ?? `__auto-reasoning-${++this.reasoningPartCounter}`;
|
|
523
605
|
if (messageId === void 0) this.anonymousReasoningKeys.add(key);
|
|
@@ -533,7 +615,11 @@ var RunAggregator = class {
|
|
|
533
615
|
this.emit();
|
|
534
616
|
}
|
|
535
617
|
handleReasoningContent(delta, messageId, isMessageId = false) {
|
|
536
|
-
if (!
|
|
618
|
+
if (!delta) return;
|
|
619
|
+
if (!this.showThinking) {
|
|
620
|
+
if (this.hiddenActiveReasoning === "none") this.handleReasoningStart(messageId, isMessageId);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
537
623
|
if (!this.activeReasoningKey) this.handleReasoningStart(messageId, isMessageId);
|
|
538
624
|
const key = this.activeReasoningKey;
|
|
539
625
|
if (!key) return;
|
|
@@ -541,7 +627,10 @@ var RunAggregator = class {
|
|
|
541
627
|
this.emit();
|
|
542
628
|
}
|
|
543
629
|
handleReasoningEnd() {
|
|
544
|
-
if (!this.showThinking)
|
|
630
|
+
if (!this.showThinking) {
|
|
631
|
+
this.hiddenActiveReasoning = "none";
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
545
634
|
this.activeReasoningKey = void 0;
|
|
546
635
|
this.emit();
|
|
547
636
|
}
|
|
@@ -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 MessageTiming,\n type ThreadAssistantMessagePart,\n type ToolCallMessagePart,\n type ToolModelContentPart,\n} from \"@assistant-ui/core\";\nimport {\n applyA2uiOperations,\n convertSurfaceToUISpec,\n type A2uiState,\n type A2uiSurfaceState,\n} from \"@assistant-ui/react-generative-ui/a2ui\";\nimport { readMcpAppResourceUri } from \"../mcp-tool-result\";\nimport { projectAgUiToolApprovals } from \"./tool-approval\";\nimport type { AgUiEvent, AgUiInterrupt } from \"../types\";\nimport type { Logger } from \"../logger\";\n\nexport const AG_UI_METADATA_NAMESPACE = \"agui\";\n\nexport type AgUiOpaqueReasoning = {\n id: string;\n encryptedValue: string;\n after?: boolean;\n};\n\nexport type AgUiCustomMetadata = {\n interrupts?: AgUiInterrupt[];\n opaqueReasoning?: AgUiOpaqueReasoning[];\n};\n\ntype Emit = (update: ChatModelRunResult) => void;\n\ntype ToolCallState = {\n toolCallId: string;\n toolCallName: string;\n argsText: string;\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 modelContent?: ToolModelContentPart[];\n snapshotResultApplied: boolean;\n};\n\nexport const MCP_APPS_ACTIVITY_TYPE = \"mcp-apps\";\n\nexport const A2UI_SURFACE_ACTIVITY_TYPE = \"a2ui-surface\";\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 logger: Logger;\n emit: Emit;\n onServerMessageId?: (messageId: 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 logger: Logger;\n private readonly onServerMessageId: ((messageId: string) => void) | undefined;\n\n private status: ChatModelRunResult[\"status\"] | undefined;\n private interrupts: AgUiInterrupt[] | undefined;\n private readonly textParts = new Map<\n string,\n { buffer: string; touched: boolean }\n >();\n private activeTextMessageId: string | undefined;\n private readonly reasoningParts = new Map<string, string>(); // key → buffer\n private readonly reasoningSignatures = new Map<string, string>();\n private readonly reasoningMessageIds = new Map<string, string>();\n private readonly anonymousReasoningKeys = new Set<string>();\n private activeReasoningKey: string | undefined;\n private reasoningPartCounter = 0;\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 lastResolvedToolCallId: string | undefined;\n private readonly partOrder: (\n | { kind: \"text\"; key: string }\n | { kind: \"reasoning\"; key: string }\n | { kind: \"tool-call\"; toolCallId: string }\n | { kind: \"data\"; name: string; value: unknown }\n )[] = [];\n private textPartCounter = 0;\n private serverMessageIdReported = false;\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.logger = options.logger;\n this.onServerMessageId = options.onServerMessageId;\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.clearTextParts();\n this.reasoningParts.clear();\n this.reasoningSignatures.clear();\n this.reasoningMessageIds.clear();\n this.anonymousReasoningKeys.clear();\n this.activeReasoningKey = undefined;\n this.reasoningPartCounter = 0;\n this.toolCalls.clear();\n this.a2uiBuckets.clear();\n this.a2uiToolCallIds.clear();\n this.lastResolvedToolCallId = undefined;\n this.partOrder.length = 0;\n this.textPartCounter = 0;\n this.activeTextMessageId = undefined;\n this.interrupts = undefined;\n this.serverMessageIdReported = false;\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 === \"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 const hasUnresolvedToolCalls = Array.from(this.toolCalls.values()).some(\n (tc) => tc.result === undefined,\n );\n\n this.status =\n event.outcome?.type === \"success\" || !hasUnresolvedToolCalls\n ? { type: \"complete\", reason: \"unknown\" }\n : { type: \"requires-action\", reason: \"tool-calls\" };\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.emit();\n break;\n }\n case \"RUN_CANCELLED\": {\n this.status = { type: \"incomplete\", reason: \"cancelled\" };\n this.emit();\n break;\n }\n\n case \"TEXT_MESSAGE_START\": {\n this.reportServerMessageId(event.messageId);\n const id = this.startTextMessage(event.messageId);\n if (id) {\n this.markTextPartTouched(id);\n }\n this.emit();\n break;\n }\n case \"TEXT_MESSAGE_CONTENT\":\n case \"TEXT_MESSAGE_CHUNK\": {\n const incomingId = \"messageId\" in event ? event.messageId : undefined;\n this.reportServerMessageId(incomingId);\n if (!event.delta) break;\n this.recordFirstToken();\n const id = this.resolveTextMessageId(incomingId);\n this.appendText(id, event.delta);\n this.totalChunks++;\n this.emit();\n break;\n }\n case \"TEXT_MESSAGE_END\": {\n this.reportServerMessageId(event.messageId);\n if (event.messageId && this.activeTextMessageId === event.messageId) {\n this.activeTextMessageId = undefined;\n }\n this.emit();\n break;\n }\n\n case \"CUSTOM\": {\n this.activeTextMessageId = undefined;\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 \"THINKING_START\":\n case \"THINKING_TEXT_MESSAGE_START\":\n case \"REASONING_START\":\n case \"REASONING_MESSAGE_START\":\n this.handleReasoningStart(\n \"messageId\" in event ? event.messageId : undefined,\n event.type === \"REASONING_MESSAGE_START\",\n );\n break;\n case \"REASONING_ENCRYPTED_VALUE\":\n if (event.subtype === \"message\") {\n // entityId names any message, not necessarily a reasoning one, so an\n // unmatched id may only claim a block that has no id to contradict it.\n const active = this.activeReasoningKey;\n const key = this.reasoningParts.has(event.entityId)\n ? event.entityId\n : active !== undefined && this.anonymousReasoningKeys.has(active)\n ? active\n : undefined;\n if (key !== undefined) {\n this.reasoningSignatures.set(key, event.encryptedValue);\n this.emit();\n }\n }\n break;\n case \"THINKING_TEXT_MESSAGE_CONTENT\":\n this.handleReasoningContent(event.delta);\n this.totalChunks++;\n this.recordFirstToken();\n break;\n case \"REASONING_MESSAGE_CONTENT\":\n this.handleReasoningContent(\n event.delta,\n \"messageId\" in event ? event.messageId : undefined,\n true,\n );\n this.totalChunks++;\n this.recordFirstToken();\n break;\n case \"THINKING_TEXT_MESSAGE_END\":\n case \"THINKING_END\":\n case \"REASONING_MESSAGE_END\":\n case \"REASONING_END\":\n this.handleReasoningEnd();\n break;\n\n case \"TOOL_CALL_START\": {\n this.reportServerMessageId(event.parentMessageId);\n this.startToolCall(\n event.toolCallId,\n event.toolCallName,\n event.parentMessageId,\n );\n this.emit();\n break;\n }\n case \"TOOL_CALL_ARGS\":\n case \"TOOL_CALL_CHUNK\": {\n if (event.type === \"TOOL_CALL_CHUNK\") {\n this.reportServerMessageId(event.parentMessageId);\n }\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 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) break;\n const toolCallId = event.content.toolCallId;\n const entry =\n typeof toolCallId === \"string\"\n ? this.toolCalls.get(toolCallId)\n : this.lastResolvedToolCallId\n ? this.toolCalls.get(this.lastResolvedToolCallId)\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 default: {\n this.logger.debug?.(\"[agui] aggregator ignored event\", event);\n }\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 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 toolCallId = `a2ui:${surfaceId}`;\n const { spec, warnings } = convertSurfaceToUISpec(surface);\n for (const warning of warnings) {\n this.logger.debug(\"[agui] a2ui surface conversion warning\", warning);\n }\n if (!spec) continue;\n\n activeToolCallIds.add(toolCallId);\n\n const entry: ToolCallState = {\n toolCallId,\n toolCallName: \"present\",\n argsText: JSON.stringify(spec),\n parsedArgs: spec,\n result: {},\n isError: undefined,\n snapshotResultApplied: false,\n };\n if (!this.toolCalls.has(toolCallId)) {\n this.partOrder.push({ kind: \"tool-call\", toolCallId });\n }\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.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 (this.serverMessageIdReported || !messageId) return;\n this.serverMessageIdReported = true;\n this.onServerMessageId?.(messageId);\n }\n\n private clearTextParts(): void {\n this.textParts.clear();\n }\n\n private generateTextKey(): string {\n this.textPartCounter += 1;\n return `text-${this.textPartCounter}`;\n }\n\n private startTextMessage(messageId?: string): string {\n const id = messageId ?? this.generateTextKey();\n this.ensureTextPart(id);\n this.activeTextMessageId = id;\n return id;\n }\n\n private resolveTextMessageId(messageId?: string): string {\n if (messageId) {\n this.ensureTextPart(messageId);\n this.activeTextMessageId = messageId;\n return messageId;\n }\n\n if (this.activeTextMessageId) {\n return this.activeTextMessageId;\n }\n\n const generated = this.generateTextKey();\n this.ensureTextPart(generated);\n this.activeTextMessageId = generated;\n return generated;\n }\n\n private ensureTextPart(id: string): void {\n if (!this.textParts.has(id)) {\n this.textParts.set(id, { buffer: \"\", touched: false });\n if (\n !this.partOrder.some((part) => part.kind === \"text\" && part.key === id)\n ) {\n this.partOrder.push({ kind: \"text\", key: id });\n }\n }\n }\n\n private markTextPartTouched(id: string): void {\n const entry = this.textParts.get(id);\n if (!entry) return;\n entry.touched = true;\n }\n\n private appendText(id: string, delta: string): void {\n this.ensureTextPart(id);\n const entry = this.textParts.get(id);\n if (!entry) return;\n entry.buffer += delta;\n entry.touched = true;\n }\n\n private startToolCall(\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 this.activeTextMessageId = undefined;\n if (\n !this.partOrder.some(\n (part) => part.kind === \"tool-call\" && part.toolCallId === id,\n )\n ) {\n this.insertToolPart(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 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(id: string, parentMessageId?: string) {\n const entry = { kind: \"tool-call\", toolCallId: id } as const;\n if (parentMessageId) {\n const parentIndex = this.partOrder.findIndex(\n (part) => part.kind === \"text\" && part.key === parentMessageId,\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 entry.argsText += delta;\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 id: string,\n content: string,\n isError?: boolean,\n toolMessageId?: string,\n mcpResult?: Record<string, unknown>,\n ) {\n if (!id) return;\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 };\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: content }];\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: content }];\n }\n if (entry.isError === undefined) {\n entry.isError = isError;\n }\n } else {\n entry.result = tryParseJSON(content);\n entry.isError = isError;\n }\n if (toolMessageId) {\n entry.toolMessageId = toolMessageId;\n }\n this.lastResolvedToolCallId = id;\n }\n\n private emit(): void {\n const snapshot: ThreadAssistantMessagePart[] = [];\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.\n const approvals = projectAgUiToolApprovals(\n this.status?.type === \"requires-action\" ? this.interrupts : undefined,\n new Set(this.toolCalls.keys()),\n );\n\n for (const part of this.partOrder) {\n if (part.kind === \"reasoning\") {\n if (this.showThinking) {\n const buffer = this.reasoningParts.get(part.key) ?? \"\";\n if (buffer.length > 0 || this.activeReasoningKey === part.key) {\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 ...(Object.keys(meta).length > 0\n ? { providerMetadata: { [AG_UI_METADATA_NAMESPACE]: meta } }\n : {}),\n } as const);\n }\n }\n continue;\n }\n\n if (part.kind === \"text\") {\n const entry = this.textParts.get(part.key);\n if (entry?.touched) {\n snapshot.push({ type: \"text\", text: entry.buffer } as const);\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 continue;\n }\n\n const entry = this.toolCalls.get(part.toolCallId);\n if (!entry) continue;\n const approval = approvals.get(entry.toolCallId);\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.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 } as ToolCallMessagePart & { unstable_toolMessageId?: string };\n snapshot.push(toolPart);\n }\n\n const timing = this.getTiming();\n const metadata = {\n ...(timing ? { timing } : {}),\n ...(this.interrupts\n ? {\n custom: {\n [AG_UI_METADATA_NAMESPACE]: {\n interrupts: this.interrupts,\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(messageId?: string, isMessageId = false): void {\n if (!this.showThinking) return;\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.\n this.activeTextMessageId = undefined;\n const key = messageId ?? `__auto-reasoning-${++this.reasoningPartCounter}`;\n // Two different questions: which id may be replayed as a ReasoningMessage.id\n // (only the message-scoped aliases carry one), and which block an unmatched\n // signature may claim (any block opened without an id at all).\n if (messageId === undefined) {\n this.anonymousReasoningKeys.add(key);\n } else if (isMessageId) {\n this.reasoningMessageIds.set(key, messageId);\n }\n if (!this.reasoningParts.has(key)) {\n this.reasoningParts.set(key, \"\");\n this.partOrder.push({ kind: \"reasoning\", key });\n }\n this.activeReasoningKey = key;\n this.emit();\n }\n\n private handleReasoningContent(\n delta: string,\n messageId?: string,\n isMessageId = false,\n ): void {\n if (!this.showThinking || !delta) return;\n if (!this.activeReasoningKey) {\n // Content arrived without a preceding START — create the slot lazily.\n this.handleReasoningStart(messageId, isMessageId);\n }\n const key = this.activeReasoningKey;\n if (!key) return;\n this.reasoningParts.set(key, (this.reasoningParts.get(key) ?? \"\") + delta);\n this.emit();\n }\n\n private handleReasoningEnd(): void {\n if (!this.showThinking) return;\n this.activeReasoningKey = undefined;\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":";;;;;;AAqBA,MAAa,2BAA2B;AA8BxC,MAAa,yBAAyB;AAEtC,MAAa,6BAA6B;AAE1C,MAAa,iBACX,UAEA,CAAC,CAAC,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;;;;;;;;;;;AAmB9D,IAAa,gBAAb,MAA2B;CACzB;CACA;CACA;CACA;CAEA;CACA;CACA,4BAA6B,IAAI,IAG/B;CACF;CACA,iCAAkC,IAAI,IAAoB;CAC1D,sCAAuC,IAAI,IAAoB;CAC/D,sCAAuC,IAAI,IAAoB;CAC/D,yCAA0C,IAAI,IAAY;CAC1D;CACA,uBAA+B;CAC/B,4BAA6B,IAAI,IAA2B;CAC5D,8BAA+B,IAAI,IAAuB;CAC1D,kCAAmC,IAAI,IAAY;CACnD;CACA,YAKM,CAAC;CACP,kBAA0B;CAC1B,0BAAkC;CAElC;CACA;CACA,cAAsB;CAEtB,YAAY,SAA+B;EACzC,KAAK,aAAa,QAAQ;EAC1B,KAAK,eAAe,QAAQ;EAC5B,KAAK,SAAS,QAAQ;EACtB,KAAK,o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I,KAAK,SAAS;EAE7C,IAAI,CAAC,KAAK,eAAe,IAAI,GAAG,GAAG;GACjC,KAAK,eAAe,IAAI,KAAK,EAAE;GAC/B,KAAK,UAAU,KAAK;IAAE,MAAM;IAAa;GAAI,CAAC;EAChD;EACA,KAAK,qBAAqB;EAC1B,KAAK,KAAK;CACZ;CAEA,uBACE,OACA,WACA,cAAc,OACR;EACN,IAAI,CAAC,KAAK,gBAAgB,CAAC,OAAO;EAClC,IAAI,CAAC,KAAK,oBAER,KAAK,qBAAqB,WAAW,WAAW;EAElD,MAAM,MAAM,KAAK;EACjB,IAAI,CAAC,KAAK;EACV,KAAK,eAAe,IAAI,MAAM,KAAK,eAAe,IAAI,GAAG,KAAK,MAAM,KAAK;EACzE,KAAK,KAAK;CACZ;CAEA,qBAAmC;EACjC,IAAI,CAAC,KAAK,cAAc;EACxB,KAAK,qBAAqB,KAAA;EAC1B,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 MessageTiming,\n type ThreadAssistantMessagePart,\n type ToolCallMessagePart,\n type ToolModelContentPart,\n} from \"@assistant-ui/core\";\nimport {\n applyA2uiOperations,\n convertSurfaceToUISpec,\n type A2uiState,\n type A2uiSurfaceState,\n} from \"@assistant-ui/react-generative-ui/a2ui\";\nimport { readMcpAppResourceUri } from \"../mcp-tool-result\";\nimport { projectAgUiToolApprovals } from \"./tool-approval\";\nimport type { AgUiEvent, AgUiInterrupt } from \"../types\";\nimport type { Logger } from \"../logger\";\n\nexport const AG_UI_METADATA_NAMESPACE = \"agui\";\n\nexport type AgUiOpaqueReasoning = {\n id: string;\n encryptedValue: string;\n after?: boolean;\n};\n\nexport type AgUiCustomMetadata = {\n /** Wire role restored on export for messages the internal model cannot\n * represent (a developer record rides as a system message). */\n role?: \"developer\";\n interrupts?: AgUiInterrupt[];\n opaqueReasoning?: AgUiOpaqueReasoning[];\n};\n\ntype Emit = (update: ChatModelRunResult) => void;\n\ntype ToolCallState = {\n toolCallId: string;\n toolCallName: string;\n argsText: string;\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 modelContent?: ToolModelContentPart[];\n snapshotResultApplied: boolean;\n};\n\nexport const MCP_APPS_ACTIVITY_TYPE = \"mcp-apps\";\n\nexport const A2UI_SURFACE_ACTIVITY_TYPE = \"a2ui-surface\";\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 logger: Logger;\n emit: Emit;\n onServerMessageId?: (messageId: string) => void;\n onTextMessageStart?: (messageId: 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 logger: Logger;\n private readonly onServerMessageId: ((messageId: string) => void) | undefined;\n private readonly onTextMessageStart:\n | ((messageId: string) => void)\n | undefined;\n\n private status: ChatModelRunResult[\"status\"] | undefined;\n private interrupts: AgUiInterrupt[] | undefined;\n private readonly textParts = new Map<string, { buffer: string }>();\n private activeTextMessageId: string | undefined;\n private readonly reasoningParts = new Map<string, string>(); // key → buffer\n private readonly reasoningSignatures = new Map<string, string>();\n private readonly reasoningSignatureIds = new Map<string, string>();\n // Signatures captured while thinking is hidden have no block to live on;\n // they are transport state that must survive to the next run input. The\n // claim rules mirror the visible path: an id-carrying block, or an open\n // anonymous one.\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 hiddenAnonymousAnchor: number | undefined;\n private readonly hiddenReasoningIds = new Set<string>();\n private hiddenActiveReasoning: \"none\" | \"anonymous\" | \"identified\" = \"none\";\n private hasEmittedOpaqueReasoning = false;\n private readonly loggedDroppedOpaqueIds = new Set<string>();\n private readonly reasoningMessageIds = new Map<string, string>();\n private readonly anonymousReasoningKeys = new Set<string>();\n private activeReasoningKey: string | undefined;\n private reasoningPartCounter = 0;\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 lastResolvedToolCallId: string | undefined;\n private readonly partOrder: (\n | { kind: \"text\"; key: string }\n | { kind: \"reasoning\"; key: string }\n | { kind: \"tool-call\"; toolCallId: string }\n | { kind: \"data\"; name: string; value: unknown }\n )[] = [];\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.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 === \"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 const hasUnresolvedToolCalls = Array.from(this.toolCalls.values()).some(\n (tc) => tc.result === undefined,\n );\n\n this.status =\n event.outcome?.type === \"success\" || !hasUnresolvedToolCalls\n ? { type: \"complete\", reason: \"unknown\" }\n : { type: \"requires-action\", reason: \"tool-calls\" };\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.emit();\n break;\n }\n case \"RUN_CANCELLED\": {\n this.status = { type: \"incomplete\", reason: \"cancelled\" };\n this.emit();\n break;\n }\n\n case \"TEXT_MESSAGE_START\": {\n this.beginDistinctTextMessage(event.messageId);\n this.reportServerMessageId(event.messageId);\n this.startTextMessage(event.messageId);\n if (event.messageId) this.lastTextMessageId = event.messageId;\n this.emit();\n break;\n }\n case \"TEXT_MESSAGE_CONTENT\":\n case \"TEXT_MESSAGE_CHUNK\": {\n const incomingId = \"messageId\" in event ? event.messageId : undefined;\n this.beginDistinctTextMessage(incomingId);\n this.reportServerMessageId(incomingId);\n if (incomingId) this.lastTextMessageId = incomingId;\n if (!event.delta) break;\n this.recordFirstToken();\n const id = this.resolveTextMessageId(incomingId);\n this.appendText(id, event.delta);\n this.totalChunks++;\n this.emit();\n break;\n }\n case \"TEXT_MESSAGE_END\": {\n this.reportServerMessageId(event.messageId);\n if (event.messageId && this.activeTextMessageId === event.messageId) {\n this.activeTextMessageId = undefined;\n }\n this.emit();\n break;\n }\n\n case \"CUSTOM\": {\n this.activeTextMessageId = undefined;\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 \"THINKING_START\":\n case \"THINKING_TEXT_MESSAGE_START\":\n case \"REASONING_START\":\n case \"REASONING_MESSAGE_START\":\n this.handleReasoningStart(\n \"messageId\" in event ? event.messageId : undefined,\n event.type === \"REASONING_MESSAGE_START\",\n );\n break;\n case \"REASONING_ENCRYPTED_VALUE\":\n if (event.subtype === \"message\") {\n // entityId names any message, not necessarily a reasoning one, so an\n // unmatched id may only claim a block that has no id to contradict it.\n const active = this.activeReasoningKey;\n const key = this.showThinking\n ? this.reasoningParts.has(event.entityId)\n ? event.entityId\n : active !== undefined && this.anonymousReasoningKeys.has(active)\n ? active\n : undefined\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 event.entityId.trim().length > 0 &&\n event.encryptedValue.trim().length > 0 &&\n (this.hiddenReasoningIds.has(event.entityId) ||\n this.hiddenActiveReasoning === \"anonymous\")\n ) {\n this.hiddenSignatures.set(event.entityId, event.encryptedValue);\n this.hiddenSignatureAnchors.set(\n event.entityId,\n this.hiddenBlockAnchors.get(event.entityId) ??\n this.hiddenAnonymousAnchor ??\n this.partOrder.length,\n );\n this.emit();\n }\n }\n break;\n case \"THINKING_TEXT_MESSAGE_CONTENT\":\n this.handleReasoningContent(event.delta);\n this.totalChunks++;\n this.recordFirstToken();\n break;\n case \"REASONING_MESSAGE_CONTENT\":\n this.handleReasoningContent(\n event.delta,\n \"messageId\" in event ? event.messageId : undefined,\n true,\n );\n this.totalChunks++;\n this.recordFirstToken();\n break;\n case \"THINKING_TEXT_MESSAGE_END\":\n case \"THINKING_END\":\n case \"REASONING_MESSAGE_END\":\n case \"REASONING_END\":\n this.handleReasoningEnd();\n break;\n\n case \"TOOL_CALL_START\": {\n this.reportServerMessageId(event.parentMessageId);\n this.startToolCall(\n event.toolCallId,\n event.toolCallName,\n event.parentMessageId,\n );\n this.emit();\n break;\n }\n case \"TOOL_CALL_ARGS\":\n case \"TOOL_CALL_CHUNK\": {\n if (event.type === \"TOOL_CALL_CHUNK\") {\n this.reportServerMessageId(event.parentMessageId);\n }\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 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) break;\n const toolCallId = event.content.toolCallId;\n const entry =\n typeof toolCallId === \"string\"\n ? this.toolCalls.get(toolCallId)\n : this.lastResolvedToolCallId\n ? this.toolCalls.get(this.lastResolvedToolCallId)\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 default: {\n this.logger.debug?.(\"[agui] aggregator ignored event\", event);\n }\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 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 toolCallId = `a2ui:${surfaceId}`;\n const { spec, warnings } = convertSurfaceToUISpec(surface);\n for (const warning of warnings) {\n this.logger.debug(\"[agui] a2ui surface conversion warning\", warning);\n }\n if (!spec) continue;\n\n activeToolCallIds.add(toolCallId);\n\n const entry: ToolCallState = {\n toolCallId,\n toolCallName: \"present\",\n argsText: JSON.stringify(spec),\n parsedArgs: spec,\n result: {},\n isError: undefined,\n snapshotResultApplied: false,\n };\n if (!this.toolCalls.has(toolCallId)) {\n this.partOrder.push({ kind: \"tool-call\", toolCallId });\n }\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.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.hiddenAnonymousAnchor = undefined;\n this.hiddenReasoningIds.clear();\n this.hiddenActiveReasoning = \"none\";\n this.loggedDroppedOpaqueIds.clear();\n this.anonymousReasoningKeys.clear();\n this.activeReasoningKey = undefined;\n this.reasoningPartCounter = 0;\n this.toolCalls.clear();\n this.a2uiBuckets.clear();\n this.a2uiToolCallIds.clear();\n this.lastResolvedToolCallId = undefined;\n this.partOrder.length = 0;\n this.textPartCounter = 0;\n this.activeTextMessageId = undefined;\n this.reportedServerMessageId = undefined;\n }\n\n private beginDistinctTextMessage(messageId: string | undefined): void {\n if (\n !messageId ||\n this.lastTextMessageId === undefined ||\n this.lastTextMessageId === messageId ||\n !this.onTextMessageStart\n ) {\n return;\n }\n this.resetMessageParts();\n this.onTextMessageStart(messageId);\n }\n\n private generateTextKey(): string {\n this.textPartCounter += 1;\n return `text-${this.textPartCounter}`;\n }\n\n private startTextMessage(messageId?: string): string {\n const id = messageId ?? this.generateTextKey();\n this.ensureTextPart(id);\n this.activeTextMessageId = id;\n return id;\n }\n\n private resolveTextMessageId(messageId?: string): string {\n if (messageId) {\n this.ensureTextPart(messageId);\n this.activeTextMessageId = messageId;\n return messageId;\n }\n\n if (this.activeTextMessageId) {\n return this.activeTextMessageId;\n }\n\n const generated = this.generateTextKey();\n this.ensureTextPart(generated);\n this.activeTextMessageId = generated;\n return generated;\n }\n\n private ensureTextPart(id: string): void {\n if (!this.textParts.has(id)) {\n this.textParts.set(id, { buffer: \"\" });\n if (\n !this.partOrder.some((part) => part.kind === \"text\" && part.key === id)\n ) {\n this.partOrder.push({ kind: \"text\", key: id });\n }\n }\n }\n\n private appendText(id: string, delta: string): void {\n this.ensureTextPart(id);\n const entry = this.textParts.get(id);\n if (!entry) return;\n entry.buffer += delta;\n }\n\n private startToolCall(\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 this.activeTextMessageId = undefined;\n if (\n !this.partOrder.some(\n (part) => part.kind === \"tool-call\" && part.toolCallId === id,\n )\n ) {\n this.insertToolPart(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 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(id: string, parentMessageId?: string) {\n const entry = { kind: \"tool-call\", toolCallId: id } as const;\n if (parentMessageId) {\n const parentIndex = this.partOrder.findIndex(\n (part) => part.kind === \"text\" && part.key === parentMessageId,\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 entry.argsText += delta;\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 id: string,\n content: string,\n isError?: boolean,\n toolMessageId?: string,\n mcpResult?: Record<string, unknown>,\n ) {\n if (!id) return;\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 };\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: content }];\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: content }];\n }\n if (entry.isError === undefined) {\n entry.isError = isError;\n }\n } else {\n entry.result = tryParseJSON(content);\n entry.isError = isError;\n }\n if (toolMessageId) {\n entry.toolMessageId = toolMessageId;\n }\n this.lastResolvedToolCallId = id;\n }\n\n private emit(): void {\n const snapshot: ThreadAssistantMessagePart[] = [];\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.\n const approvals = projectAgUiToolApprovals(\n this.status?.type === \"requires-action\" ? this.interrupts : undefined,\n new Set(this.toolCalls.keys()),\n );\n\n const opaqueCandidates: (AgUiOpaqueReasoning & { anchor: number })[] =\n Array.from(this.hiddenSignatures, ([id, encryptedValue]) => ({\n id,\n encryptedValue,\n anchor: this.hiddenSignatureAnchors.get(id)!,\n }));\n\n let currentIndex = -1;\n let lastMaterializedIndex = -1;\n const pushSnapshotPart = (part: (typeof snapshot)[number]) => {\n snapshot.push(part);\n lastMaterializedIndex = currentIndex;\n };\n\n for (const [index, part] of this.partOrder.entries()) {\n currentIndex = index;\n if (part.kind === \"reasoning\") {\n if (this.showThinking) {\n const buffer = this.reasoningParts.get(part.key) ?? \"\";\n if (buffer.length > 0 || this.activeReasoningKey === part.key) {\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 pushSnapshotPart({\n type: \"reasoning\",\n text: buffer,\n ...(Object.keys(meta).length > 0\n ? { providerMetadata: { [AG_UI_METADATA_NAMESPACE]: meta } }\n : {}),\n } as const);\n } else {\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 opaqueCandidates.push({ id, encryptedValue, anchor: index + 1 });\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 pushSnapshotPart({ type: \"text\", text: entry.buffer } as const);\n }\n continue;\n }\n\n if (part.kind === \"data\") {\n pushSnapshotPart({\n type: \"data\",\n name: part.name,\n data: part.value,\n });\n continue;\n }\n\n const entry = this.toolCalls.get(part.toolCallId);\n if (!entry) continue;\n const approval = approvals.get(entry.toolCallId);\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.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 } as ToolCallMessagePart & { unstable_toolMessageId?: string };\n pushSnapshotPart(toolPart);\n }\n\n // An anonymous claim promotes the signature's entityId to a wire message\n // id; when that id actually names a text message or the adopted assistant\n // message id (which can also arrive via TOOL_CALL_START.parentMessageId),\n // replaying it as its own record would put two wire records under one id,\n // so such entries are dropped instead — the same outcome the visible\n // path's claim guard produces for a signature that is \"not for this\n // block\". Entries with no materialized part after their anchor trail the\n // assistant record, matching the snapshot path's anchor/after\n // bookkeeping.\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 || includeOpaque\n ? {\n custom: {\n [AG_UI_METADATA_NAMESPACE]: {\n ...(this.interrupts ? { interrupts: this.interrupts } : {}),\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(messageId?: string, isMessageId = false): void {\n if (!this.showThinking) {\n const anchor = this.partOrder.length;\n if (messageId === undefined) {\n this.hiddenActiveReasoning = \"anonymous\";\n this.hiddenAnonymousAnchor = anchor;\n } else {\n this.hiddenReasoningIds.add(messageId);\n this.hiddenBlockAnchors.set(messageId, anchor);\n this.hiddenActiveReasoning = \"identified\";\n }\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.\n this.activeTextMessageId = undefined;\n const key = messageId ?? `__auto-reasoning-${++this.reasoningPartCounter}`;\n // Two different questions: which id may be replayed as a ReasoningMessage.id\n // (only the message-scoped aliases carry one), and which block an unmatched\n // signature may claim (any block opened without an id at all).\n if (messageId === undefined) {\n this.anonymousReasoningKeys.add(key);\n } else if (isMessageId) {\n this.reasoningMessageIds.set(key, messageId);\n }\n if (!this.reasoningParts.has(key)) {\n this.reasoningParts.set(key, \"\");\n this.partOrder.push({ kind: \"reasoning\", key });\n }\n this.activeReasoningKey = key;\n this.emit();\n }\n\n private handleReasoningContent(\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 (this.hiddenActiveReasoning === \"none\") {\n this.handleReasoningStart(messageId, isMessageId);\n }\n return;\n }\n if (!this.activeReasoningKey) {\n // Content arrived without a preceding START — create the slot lazily.\n this.handleReasoningStart(messageId, isMessageId);\n }\n const key = this.activeReasoningKey;\n if (!key) return;\n this.reasoningParts.set(key, (this.reasoningParts.get(key) ?? \"\") + delta);\n this.emit();\n }\n\n private handleReasoningEnd(): void {\n if (!this.showThinking) {\n this.hiddenActiveReasoning = \"none\";\n return;\n }\n this.activeReasoningKey = undefined;\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":";;;;;;AAqBA,MAAa,2BAA2B;AAiCxC,MAAa,yBAAyB;AAEtC,MAAa,6BAA6B;AAE1C,MAAa,iBACX,UAEA,CAAC,CAAC,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;;;;;;;;;;;AAoB9D,IAAa,gBAAb,MAA2B;CACzB;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MAAM,KAAK;EACzE,KAAK,KAAK;CACZ;CAEA,qBAAmC;EACjC,IAAI,CAAC,KAAK,cAAc;GACtB,KAAK,wBAAwB;GAC7B;EACF;EACA,KAAK,qBAAqB,KAAA;EAC1B,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"}
|
package/dist/useAgUiRuntime.js
CHANGED
|
@@ -28,14 +28,16 @@ function useAgUiRuntime(options) {
|
|
|
28
28
|
notifyUpdate
|
|
29
29
|
});
|
|
30
30
|
const core = coreRef.current;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
core.updateOptions({
|
|
33
|
+
agent: options.agent,
|
|
34
|
+
logger,
|
|
35
|
+
showThinking: options.showThinking ?? true,
|
|
36
|
+
autoCancelPendingToolCalls: options.autoCancelPendingToolCalls,
|
|
37
|
+
...options.onError && { onError: options.onError },
|
|
38
|
+
...options.onCancel && { onCancel: options.onCancel },
|
|
39
|
+
...historyAdapter && { history: historyAdapter }
|
|
40
|
+
});
|
|
39
41
|
});
|
|
40
42
|
const [toolStatuses, setToolStatuses] = useState({});
|
|
41
43
|
const hasExecutingTools = Object.values(toolStatuses).some((s) => s?.type === "executing");
|
|
@@ -108,7 +110,7 @@ function useAgUiRuntime(options) {
|
|
|
108
110
|
isLoading: core.isLoading,
|
|
109
111
|
messageRepository: core.getMessageRepository(),
|
|
110
112
|
state: core.getState(),
|
|
111
|
-
isRunning,
|
|
113
|
+
isRunning: core.isRunning(),
|
|
112
114
|
extras: agUiExtras.provide({
|
|
113
115
|
interrupts: core.getPendingInterrupts()?.interrupts ?? EMPTY_INTERRUPTS,
|
|
114
116
|
sendA2uiAction: (action) => core.sendA2uiAction(action),
|