@assistant-ui/react-ag-ui 0.0.64 → 0.0.65

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.
@@ -155,23 +155,29 @@ export type AgUiEvent = {
155
155
  } | {
156
156
  type: "THINKING_START";
157
157
  title?: string;
158
+ timestamp?: number;
158
159
  } | {
159
160
  type: "THINKING_TEXT_MESSAGE_START";
161
+ timestamp?: number;
160
162
  } | {
161
163
  type: "THINKING_TEXT_MESSAGE_CONTENT";
162
164
  delta: string;
163
165
  } | {
164
166
  type: "THINKING_TEXT_MESSAGE_END";
167
+ timestamp?: number;
165
168
  } | {
166
169
  type: "THINKING_END";
170
+ timestamp?: number;
167
171
  } | {
168
172
  type: "REASONING_START";
169
173
  messageId?: string;
170
174
  subagentRunId?: string;
175
+ timestamp?: number;
171
176
  } | {
172
177
  type: "REASONING_MESSAGE_START";
173
178
  messageId?: string;
174
179
  subagentRunId?: string;
180
+ timestamp?: number;
175
181
  } | {
176
182
  type: "REASONING_MESSAGE_CONTENT";
177
183
  messageId?: string;
@@ -181,6 +187,7 @@ export type AgUiEvent = {
181
187
  type: "REASONING_MESSAGE_END";
182
188
  messageId?: string;
183
189
  subagentRunId?: string;
190
+ timestamp?: number;
184
191
  } | {
185
192
  type: "REASONING_ENCRYPTED_VALUE";
186
193
  subtype: "message" | "tool-call";
@@ -191,6 +198,7 @@ export type AgUiEvent = {
191
198
  type: "REASONING_END";
192
199
  messageId?: string;
193
200
  subagentRunId?: string;
201
+ timestamp?: number;
194
202
  } | {
195
203
  type: "TOOL_CALL_START";
196
204
  toolCallId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/runtime/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,0BAA0B,EAC1B,8BAA8B,EAC9B,eAAe,EACf,oBAAoB,EACpB,sBAAsB,EACtB,oBAAo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Aa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,GACD;IACE,IAAI,EAAE,mBAAmB,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,2BAA2B,CAAC;CACvC,GACD;IACE,IAAI,EAAE,gBAAgB,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useAgUiRuntime.d.ts","sourceRoot":"","sources":["../src/useAgUiRuntime.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EACV,gBAAgB,EAIjB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,qBAAqB,EACtB,2BAAwB;AASzB,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,GAAG;IACpD;;;OAGG;IACH,6BAA6B,EAAE,MAAM,SAAS,aAAa,EAAE,CAAC;IAC9D;;;;OAIG;IACH,iCAAiC,EAAE,CACjC,SAAS,EAAE,SAAS,eAAe,EAAE,KAClC,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AAEF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,qBAAqB,GAC7B,oBAAoB,CAqStB"}
1
+ {"version":3,"file":"useAgUiRuntime.d.ts","sourceRoot":"","sources":["../src/useAgUiRuntime.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EACV,gBAAgB,EAIjB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,qBAAqB,EACtB,2BAAwB;AASzB,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,GAAG;IACpD;;;OAGG;IACH,6BAA6B,EAAE,MAAM,SAAS,aAAa,EAAE,CAAC;IAC9D;;;;OAIG;IACH,iCAAiC,EAAE,CACjC,SAAS,EAAE,SAAS,eAAe,EAAE,KAClC,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AAEF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,qBAAqB,GAC7B,oBAAoB,CA6StB"}
@@ -71,6 +71,10 @@ function useAgUiRuntime(options) {
71
71
  const queueItems = useSyncExternalStore(queueController?.subscribe ?? subscribeNoop, () => queueController?.adapter.items ?? EMPTY_QUEUE_ITEMS, () => EMPTY_QUEUE_ITEMS);
72
72
  const steerQueueItems = useSyncExternalStore(queueController?.subscribe ?? subscribeNoop, () => queueController?.adapter.steerItems ?? EMPTY_QUEUE_ITEMS, () => EMPTY_QUEUE_ITEMS);
73
73
  const queueBusy = isRunning || core.getPendingInterrupts() !== null;
74
+ useEffect(() => {
75
+ if (options.isSendDisabled === true) queueController?.hold();
76
+ else queueController?.release();
77
+ }, [options.isSendDisabled, queueController]);
74
78
  useEffect(() => {
75
79
  if (!queueController) return;
76
80
  if (lastQueueEdgeRef.current?.controller === queueController && lastQueueEdgeRef.current.busy === queueBusy) return;
@@ -1 +1 @@
1
- {"version":3,"file":"useAgUiRuntime.js","names":[],"sources":["../src/useAgUiRuntime.ts"],"sourcesContent":["\"use client\";\n\nimport {\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\nimport {\n useExternalStoreRuntime,\n useExternalStoreSharedOptions,\n useRuntimeAdapters,\n} from \"@assistant-ui/core/react\";\nimport { useReplaySafeEffect } from \"@assistant-ui/store/internal\";\nimport { createMessageQueue } from \"@assistant-ui/core\";\nimport type {\n MessageQueueController,\n ToolExecutionStatus,\n} from \"@assistant-ui/core\";\nimport type {\n AssistantRuntime,\n AppendMessage,\n ExternalStoreAdapter,\n ThreadMessage,\n} from \"@assistant-ui/core\";\nimport type { ReadonlyJSONValue } from \"assistant-stream/utils\";\nimport { makeLogger } from \"./runtime/logger\";\nimport type {\n AgUiInterrupt,\n AgUiResumeEntry,\n UseAgUiRuntimeOptions,\n} from \"./runtime/types\";\nimport { AgUiThreadRuntimeCore } from \"./runtime/AgUiThreadRuntimeCore\";\nimport { agUiExtras } from \"./agUiExtras\";\nimport type { QueueItemState } from \"@assistant-ui/core/store\";\n\nconst EMPTY_INTERRUPTS: readonly AgUiInterrupt[] = [];\nconst EMPTY_QUEUE_ITEMS: readonly QueueItemState[] = Object.freeze([]);\nconst subscribeNoop = () => () => {};\n\nexport type AgUiAssistantRuntime = AssistantRuntime & {\n /**\n * @deprecated Use the `useAgUiInterrupts()` hook instead. This method is kept\n * for backward compatibility and will be removed in a future major release.\n */\n unstable_getPendingInterrupts: () => readonly AgUiInterrupt[];\n /**\n * @deprecated Use the `useAgUiSubmitInterruptResponses()` hook instead. This\n * method is kept for backward compatibility and will be removed in a future\n * major release.\n */\n unstable_submitInterruptResponses: (\n responses: readonly AgUiResumeEntry[],\n ) => Promise<void>;\n};\n\nexport function useAgUiRuntime(\n options: UseAgUiRuntimeOptions,\n): AgUiAssistantRuntime {\n const logger = useMemo(() => makeLogger(options.logger), [options.logger]);\n const [_version, setVersion] = useState(0);\n const notifyUpdate = useCallback(() => setVersion((v) => v + 1), []);\n const coreRef = useRef<AgUiThreadRuntimeCore | null>(null);\n const threadSwitchGenerationRef = useRef(0);\n const runtimeAdapters = useRuntimeAdapters();\n\n const historyAdapter = options.adapters?.history ?? runtimeAdapters?.history;\n const threadListAdapter = options.adapters?.threadList;\n\n if (!coreRef.current) {\n coreRef.current = new AgUiThreadRuntimeCore({\n agent: options.agent,\n logger,\n showThinking: options.showThinking ?? true,\n resumeTranscript: options.resumeTranscript,\n autoCancelPendingToolCalls: options.autoCancelPendingToolCalls,\n ...(options.onError && { onError: options.onError }),\n ...(options.onCancel && { onCancel: options.onCancel }),\n ...(historyAdapter && { history: historyAdapter }),\n notifyUpdate,\n });\n }\n\n const core = coreRef.current;\n useEffect(() => {\n core.updateOptions({\n agent: options.agent,\n logger,\n showThinking: options.showThinking ?? true,\n resumeTranscript: options.resumeTranscript,\n autoCancelPendingToolCalls: options.autoCancelPendingToolCalls,\n ...(options.onError && { onError: options.onError }),\n ...(options.onCancel && { onCancel: options.onCancel }),\n ...(historyAdapter && { history: historyAdapter }),\n });\n });\n\n const [toolStatuses, setToolStatuses] = useState<\n Record<string, ToolExecutionStatus>\n >({});\n\n const hasExecutingTools = Object.values(toolStatuses).some(\n (s) => s?.type === \"executing\",\n );\n const isRunning = core.isRunning() || hasExecutingTools;\n\n // The driver sends through the agent core rather than the runtime, because\n // the runtime's append routes every tail append back into this queue.\n const queueRef = useRef<MessageQueueController | null>(null);\n // Counts rendered busy edges, whether a run start or an interrupt arriving.\n // A dispatch whose count never moves was never observed as busy, so no\n // falling edge is coming to release the queue.\n const busyEdgesRef = useRef(0);\n const lastQueueEdgeRef = useRef<{\n controller: MessageQueueController;\n busy: boolean;\n } | null>(null);\n if (options.unstable_enableMessageQueue && !queueRef.current) {\n queueRef.current = createMessageQueue({\n run: (message) => {\n const controller = queueRef.current;\n const edgesAtDispatch = busyEdgesRef.current;\n // The queue drops the item before dispatching and stays busy until an\n // idle edge. An append observed as busy is released by that falling\n // edge, and releasing again here would advance the queue twice; one\n // that never runs (a pre-run rejection, or startRun false) has to be\n // released here or every later send buffers forever. An interrupt is\n // rechecked because a run that resolves without yielding to React\n // reaches here before the effect below has seen either edge.\n const releaseIfNoRun = () => {\n if (\n queueRef.current !== controller ||\n busyEdgesRef.current !== edgesAtDispatch ||\n core.getPendingInterrupts() !== null\n )\n return;\n controller?.notifyIdle();\n };\n void core.append(message).then(releaseIfNoRun, (e: unknown) => {\n releaseIfNoRun();\n logger.error?.(\"[agui] queued message failed to send\", e);\n });\n },\n });\n }\n const queueController = options.unstable_enableMessageQueue\n ? queueRef.current\n : null;\n useLayoutEffect(() => {\n if (options.unstable_enableMessageQueue || !queueRef.current) return;\n const controller = queueRef.current;\n queueRef.current = null;\n controller.clear();\n }, [options.unstable_enableMessageQueue]);\n\n // Feeds the store memo below: the runtime core skips an adapter whose\n // identity is unchanged, so queue items have to move the store reference or\n // subscribers never see composer.queue change.\n const queueItems = useSyncExternalStore(\n queueController?.subscribe ?? subscribeNoop,\n () => queueController?.adapter.items ?? EMPTY_QUEUE_ITEMS,\n () => EMPTY_QUEUE_ITEMS,\n );\n const steerQueueItems = useSyncExternalStore(\n queueController?.subscribe ?? subscribeNoop,\n () => queueController?.adapter.steerItems ?? EMPTY_QUEUE_ITEMS,\n () => EMPTY_QUEUE_ITEMS,\n );\n\n // Holds the queue while client-side tools are still executing, and while an\n // interrupt is unanswered: `append` refuses a new run until it is resolved,\n // and the queue drops an item before dispatching it, so draining into that\n // refusal would lose the message instead of keeping it visible.\n const queueBusy = isRunning || core.getPendingInterrupts() !== null;\n useEffect(() => {\n if (!queueController) return;\n if (\n lastQueueEdgeRef.current?.controller === queueController &&\n lastQueueEdgeRef.current.busy === queueBusy\n )\n return;\n lastQueueEdgeRef.current = { controller: queueController, busy: queueBusy };\n if (queueBusy) {\n busyEdgesRef.current++;\n queueController.notifyBusy();\n } else {\n queueController.notifyIdle();\n }\n }, [queueBusy, queueController]);\n\n const threadList = useMemo(() => {\n if (!threadListAdapter) return undefined;\n\n const { onSwitchToNewThread, onSwitchToThread, ...rest } =\n threadListAdapter;\n\n return {\n ...rest,\n onSwitchToNewThread: onSwitchToNewThread\n ? async () => {\n const generation = ++threadSwitchGenerationRef.current;\n // Clear before the thread id flips, or the old messages leak\n // into the new thread as a sibling branch.\n core.applyExternalMessages([]);\n core.resetThreadState();\n await onSwitchToNewThread();\n if (generation !== threadSwitchGenerationRef.current) return;\n core.applyExternalMessages([]);\n core.resetThreadState();\n }\n : undefined,\n onSwitchToThread: onSwitchToThread\n ? async (threadId: string) => {\n const generation = ++threadSwitchGenerationRef.current;\n // Clear before the thread id flips, or the old messages leak\n // into the new thread as a sibling branch.\n core.applyExternalMessages([]);\n core.resetThreadState();\n const result = await onSwitchToThread(threadId);\n if (generation !== threadSwitchGenerationRef.current) return;\n core.applyExternalMessages([]);\n core.resetThreadState();\n core.applyExternalMessages(result.messages);\n if (result.state !== undefined) {\n core.loadExternalState(result.state);\n }\n if (result.unstable_resume) {\n void core.resumeInFlightRun(result.messages);\n }\n }\n : undefined,\n };\n }, [threadListAdapter, core]);\n\n const adapters = options.adapters;\n const adapterAdapters = useMemo(\n () => ({\n attachments: adapters?.attachments ?? runtimeAdapters?.attachments,\n speech: adapters?.speech,\n dictation: adapters?.dictation,\n voice: adapters?.voice,\n feedback: adapters?.feedback,\n threadList,\n }),\n [adapters, runtimeAdapters, threadList],\n );\n\n const shared = useExternalStoreSharedOptions(options);\n const store = useMemo(\n () => {\n void _version; // rerender on version change\n\n return {\n ...shared,\n isLoading: core.isLoading,\n messageRepository: core.getMessageRepository(),\n state: core.getState(),\n isRunning: core.isRunning(),\n extras: agUiExtras.provide({\n interrupts:\n core.getPendingInterrupts()?.interrupts ?? EMPTY_INTERRUPTS,\n sendA2uiAction: (action) => core.sendA2uiAction(action),\n submitInterruptResponses: (responses) =>\n core.submitInterruptResponses(responses),\n steerAway: (message, responses) => core.steerAway(message, responses),\n state: core.getState(),\n setState: (next) => core.setState(next),\n }),\n unstable_enableToolInvocations: true,\n unstable_persistsHistory: true,\n setToolStatuses,\n onNew: (message: AppendMessage) => core.append(message),\n onVoiceTranscript: (message) => core.appendVoiceTranscript(message),\n onEdit: (message: AppendMessage) => {\n queueController?.clear();\n return core.edit(message);\n },\n onReload: (parentId: string | null, config: { runConfig?: any }) => {\n queueController?.clear();\n return core.reload(parentId, config);\n },\n onCancel: async () => {\n queueController?.notifyCancelled();\n core.cancel();\n },\n onAddToolResult: (options) => core.addToolResult(options),\n unstable_onRecordToolInteraction: (options) =>\n core.recordToolInteraction(options),\n onRespondToToolApproval: (options) =>\n core.respondToToolApproval(options).catch((error: unknown) => {\n core.reportError(error);\n throw error;\n }),\n onResume: (config) => core.resume(config),\n setMessages: (messages: readonly ThreadMessage[]) =>\n core.applyExternalMessages(messages),\n onImport: (messages: readonly ThreadMessage[]) =>\n core.applyExternalMessages(messages),\n onLoadExternalState: (state: ReadonlyJSONValue) =>\n core.loadExternalState(state),\n adapters: adapterAdapters,\n ...(queueController && { queue: queueController.adapter }),\n } satisfies ExternalStoreAdapter<ThreadMessage>;\n },\n // _version is intentionally included to trigger re-computation when core state changes via notifyUpdate\n // toolInvocations intentionally excluded: abort/resume use refs internally and work with stale captures\n [\n adapterAdapters,\n core,\n _version,\n isRunning,\n queueController,\n queueItems,\n steerQueueItems,\n shared,\n ],\n );\n\n const baseRuntime = useExternalStoreRuntime(store);\n\n const createRuntime = (): AgUiAssistantRuntime => {\n const wrapper = Object.create(baseRuntime) as AgUiAssistantRuntime;\n wrapper.unstable_getPendingInterrupts = () =>\n core.getPendingInterrupts()?.interrupts ?? [];\n wrapper.unstable_submitInterruptResponses = (responses) =>\n core.submitInterruptResponses(responses);\n return wrapper;\n };\n const [pinnedRuntime, setPinnedRuntime] = useState(() => ({\n baseRuntime,\n runtime: createRuntime(),\n }));\n let currentRuntime = pinnedRuntime;\n if (pinnedRuntime.baseRuntime !== baseRuntime) {\n currentRuntime = { baseRuntime, runtime: createRuntime() };\n setPinnedRuntime(currentRuntime);\n }\n const runtime = currentRuntime.runtime;\n\n useReplaySafeEffect(() => {\n core.attachRuntime(runtime);\n return () => {\n core.detachRuntime();\n };\n }, [core, runtime]);\n\n useEffect(() => {\n core.__internal_load();\n }, [core]);\n\n return runtime;\n}\n"],"mappings":";;;;;;;;;AAuCA,MAAM,mBAA6C,CAAC;AACpD,MAAM,oBAA+C,OAAO,OAAO,CAAC,CAAC;AACrE,MAAM,4BAA4B,CAAC;AAkBnC,SAAgB,eACd,SACsB;CACtB,MAAM,SAAS,cAAc,WAAW,QAAQ,M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Aa;EAC7C,iBAAiB;GAAE;GAAa,SAAS,cAAc;EAAE;EACzD,iBAAiB,cAAc;CACjC;CACA,MAAM,UAAU,eAAe;CAE/B,0BAA0B;EACxB,KAAK,cAAc,OAAO;EAC1B,aAAa;GACX,KAAK,cAAc;EACrB;CACF,GAAG,CAAC,MAAM,OAAO,CAAC;CAElB,gBAAgB;EACd,KAAK,gBAAgB;CACvB,GAAG,CAAC,IAAI,CAAC;CAET,OAAO;AACT"}
1
+ {"version":3,"file":"useAgUiRuntime.js","names":[],"sources":["../src/useAgUiRuntime.ts"],"sourcesContent":["\"use client\";\n\nimport {\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\";\nimport {\n useExternalStoreRuntime,\n useExternalStoreSharedOptions,\n useRuntimeAdapters,\n} from \"@assistant-ui/core/react\";\nimport { useReplaySafeEffect } from \"@assistant-ui/store/internal\";\nimport { createMessageQueue } from \"@assistant-ui/core\";\nimport type {\n MessageQueueController,\n ToolExecutionStatus,\n} from \"@assistant-ui/core\";\nimport type {\n AssistantRuntime,\n AppendMessage,\n ExternalStoreAdapter,\n ThreadMessage,\n} from \"@assistant-ui/core\";\nimport type { ReadonlyJSONValue } from \"assistant-stream/utils\";\nimport { makeLogger } from \"./runtime/logger\";\nimport type {\n AgUiInterrupt,\n AgUiResumeEntry,\n UseAgUiRuntimeOptions,\n} from \"./runtime/types\";\nimport { AgUiThreadRuntimeCore } from \"./runtime/AgUiThreadRuntimeCore\";\nimport { agUiExtras } from \"./agUiExtras\";\nimport type { QueueItemState } from \"@assistant-ui/core/store\";\n\nconst EMPTY_INTERRUPTS: readonly AgUiInterrupt[] = [];\nconst EMPTY_QUEUE_ITEMS: readonly QueueItemState[] = Object.freeze([]);\nconst subscribeNoop = () => () => {};\n\nexport type AgUiAssistantRuntime = AssistantRuntime & {\n /**\n * @deprecated Use the `useAgUiInterrupts()` hook instead. This method is kept\n * for backward compatibility and will be removed in a future major release.\n */\n unstable_getPendingInterrupts: () => readonly AgUiInterrupt[];\n /**\n * @deprecated Use the `useAgUiSubmitInterruptResponses()` hook instead. This\n * method is kept for backward compatibility and will be removed in a future\n * major release.\n */\n unstable_submitInterruptResponses: (\n responses: readonly AgUiResumeEntry[],\n ) => Promise<void>;\n};\n\nexport function useAgUiRuntime(\n options: UseAgUiRuntimeOptions,\n): AgUiAssistantRuntime {\n const logger = useMemo(() => makeLogger(options.logger), [options.logger]);\n const [_version, setVersion] = useState(0);\n const notifyUpdate = useCallback(() => setVersion((v) => v + 1), []);\n const coreRef = useRef<AgUiThreadRuntimeCore | null>(null);\n const threadSwitchGenerationRef = useRef(0);\n const runtimeAdapters = useRuntimeAdapters();\n\n const historyAdapter = options.adapters?.history ?? runtimeAdapters?.history;\n const threadListAdapter = options.adapters?.threadList;\n\n if (!coreRef.current) {\n coreRef.current = new AgUiThreadRuntimeCore({\n agent: options.agent,\n logger,\n showThinking: options.showThinking ?? true,\n resumeTranscript: options.resumeTranscript,\n autoCancelPendingToolCalls: options.autoCancelPendingToolCalls,\n ...(options.onError && { onError: options.onError }),\n ...(options.onCancel && { onCancel: options.onCancel }),\n ...(historyAdapter && { history: historyAdapter }),\n notifyUpdate,\n });\n }\n\n const core = coreRef.current;\n useEffect(() => {\n core.updateOptions({\n agent: options.agent,\n logger,\n showThinking: options.showThinking ?? true,\n resumeTranscript: options.resumeTranscript,\n autoCancelPendingToolCalls: options.autoCancelPendingToolCalls,\n ...(options.onError && { onError: options.onError }),\n ...(options.onCancel && { onCancel: options.onCancel }),\n ...(historyAdapter && { history: historyAdapter }),\n });\n });\n\n const [toolStatuses, setToolStatuses] = useState<\n Record<string, ToolExecutionStatus>\n >({});\n\n const hasExecutingTools = Object.values(toolStatuses).some(\n (s) => s?.type === \"executing\",\n );\n const isRunning = core.isRunning() || hasExecutingTools;\n\n // The driver sends through the agent core rather than the runtime, because\n // the runtime's append routes every tail append back into this queue.\n const queueRef = useRef<MessageQueueController | null>(null);\n // Counts rendered busy edges, whether a run start or an interrupt arriving.\n // A dispatch whose count never moves was never observed as busy, so no\n // falling edge is coming to release the queue.\n const busyEdgesRef = useRef(0);\n const lastQueueEdgeRef = useRef<{\n controller: MessageQueueController;\n busy: boolean;\n } | null>(null);\n if (options.unstable_enableMessageQueue && !queueRef.current) {\n queueRef.current = createMessageQueue({\n run: (message) => {\n const controller = queueRef.current;\n const edgesAtDispatch = busyEdgesRef.current;\n // The queue drops the item before dispatching and stays busy until an\n // idle edge. An append observed as busy is released by that falling\n // edge, and releasing again here would advance the queue twice; one\n // that never runs (a pre-run rejection, or startRun false) has to be\n // released here or every later send buffers forever. An interrupt is\n // rechecked because a run that resolves without yielding to React\n // reaches here before the effect below has seen either edge.\n const releaseIfNoRun = () => {\n if (\n queueRef.current !== controller ||\n busyEdgesRef.current !== edgesAtDispatch ||\n core.getPendingInterrupts() !== null\n )\n return;\n controller?.notifyIdle();\n };\n void core.append(message).then(releaseIfNoRun, (e: unknown) => {\n releaseIfNoRun();\n logger.error?.(\"[agui] queued message failed to send\", e);\n });\n },\n });\n }\n const queueController = options.unstable_enableMessageQueue\n ? queueRef.current\n : null;\n useLayoutEffect(() => {\n if (options.unstable_enableMessageQueue || !queueRef.current) return;\n const controller = queueRef.current;\n queueRef.current = null;\n controller.clear();\n }, [options.unstable_enableMessageQueue]);\n\n // Feeds the store memo below: the runtime core skips an adapter whose\n // identity is unchanged, so queue items have to move the store reference or\n // subscribers never see composer.queue change.\n const queueItems = useSyncExternalStore(\n queueController?.subscribe ?? subscribeNoop,\n () => queueController?.adapter.items ?? EMPTY_QUEUE_ITEMS,\n () => EMPTY_QUEUE_ITEMS,\n );\n const steerQueueItems = useSyncExternalStore(\n queueController?.subscribe ?? subscribeNoop,\n () => queueController?.adapter.steerItems ?? EMPTY_QUEUE_ITEMS,\n () => EMPTY_QUEUE_ITEMS,\n );\n\n // Holds the queue while client-side tools are still executing, and while an\n // interrupt is unanswered: `append` refuses a new run until it is resolved,\n // and the queue drops an item before dispatching it, so draining into that\n // refusal would lose the message instead of keeping it visible.\n const queueBusy = isRunning || core.getPendingInterrupts() !== null;\n useEffect(() => {\n if (options.isSendDisabled === true) {\n queueController?.hold();\n } else {\n queueController?.release();\n }\n }, [options.isSendDisabled, queueController]);\n\n useEffect(() => {\n if (!queueController) return;\n if (\n lastQueueEdgeRef.current?.controller === queueController &&\n lastQueueEdgeRef.current.busy === queueBusy\n )\n return;\n lastQueueEdgeRef.current = { controller: queueController, busy: queueBusy };\n if (queueBusy) {\n busyEdgesRef.current++;\n queueController.notifyBusy();\n } else {\n queueController.notifyIdle();\n }\n }, [queueBusy, queueController]);\n\n const threadList = useMemo(() => {\n if (!threadListAdapter) return undefined;\n\n const { onSwitchToNewThread, onSwitchToThread, ...rest } =\n threadListAdapter;\n\n return {\n ...rest,\n onSwitchToNewThread: onSwitchToNewThread\n ? async () => {\n const generation = ++threadSwitchGenerationRef.current;\n // Clear before the thread id flips, or the old messages leak\n // into the new thread as a sibling branch.\n core.applyExternalMessages([]);\n core.resetThreadState();\n await onSwitchToNewThread();\n if (generation !== threadSwitchGenerationRef.current) return;\n core.applyExternalMessages([]);\n core.resetThreadState();\n }\n : undefined,\n onSwitchToThread: onSwitchToThread\n ? async (threadId: string) => {\n const generation = ++threadSwitchGenerationRef.current;\n // Clear before the thread id flips, or the old messages leak\n // into the new thread as a sibling branch.\n core.applyExternalMessages([]);\n core.resetThreadState();\n const result = await onSwitchToThread(threadId);\n if (generation !== threadSwitchGenerationRef.current) return;\n core.applyExternalMessages([]);\n core.resetThreadState();\n core.applyExternalMessages(result.messages);\n if (result.state !== undefined) {\n core.loadExternalState(result.state);\n }\n if (result.unstable_resume) {\n void core.resumeInFlightRun(result.messages);\n }\n }\n : undefined,\n };\n }, [threadListAdapter, core]);\n\n const adapters = options.adapters;\n const adapterAdapters = useMemo(\n () => ({\n attachments: adapters?.attachments ?? runtimeAdapters?.attachments,\n speech: adapters?.speech,\n dictation: adapters?.dictation,\n voice: adapters?.voice,\n feedback: adapters?.feedback,\n threadList,\n }),\n [adapters, runtimeAdapters, threadList],\n );\n\n const shared = useExternalStoreSharedOptions(options);\n const store = useMemo(\n () => {\n void _version; // rerender on version change\n\n return {\n ...shared,\n isLoading: core.isLoading,\n messageRepository: core.getMessageRepository(),\n state: core.getState(),\n isRunning: core.isRunning(),\n extras: agUiExtras.provide({\n interrupts:\n core.getPendingInterrupts()?.interrupts ?? EMPTY_INTERRUPTS,\n sendA2uiAction: (action) => core.sendA2uiAction(action),\n submitInterruptResponses: (responses) =>\n core.submitInterruptResponses(responses),\n steerAway: (message, responses) => core.steerAway(message, responses),\n state: core.getState(),\n setState: (next) => core.setState(next),\n }),\n unstable_enableToolInvocations: true,\n unstable_persistsHistory: true,\n setToolStatuses,\n onNew: (message: AppendMessage) => core.append(message),\n onVoiceTranscript: (message) => core.appendVoiceTranscript(message),\n onEdit: (message: AppendMessage) => {\n queueController?.clear();\n return core.edit(message);\n },\n onReload: (parentId: string | null, config: { runConfig?: any }) => {\n queueController?.clear();\n return core.reload(parentId, config);\n },\n onCancel: async () => {\n queueController?.notifyCancelled();\n core.cancel();\n },\n onAddToolResult: (options) => core.addToolResult(options),\n unstable_onRecordToolInteraction: (options) =>\n core.recordToolInteraction(options),\n onRespondToToolApproval: (options) =>\n core.respondToToolApproval(options).catch((error: unknown) => {\n core.reportError(error);\n throw error;\n }),\n onResume: (config) => core.resume(config),\n setMessages: (messages: readonly ThreadMessage[]) =>\n core.applyExternalMessages(messages),\n onImport: (messages: readonly ThreadMessage[]) =>\n core.applyExternalMessages(messages),\n onLoadExternalState: (state: ReadonlyJSONValue) =>\n core.loadExternalState(state),\n adapters: adapterAdapters,\n ...(queueController && { queue: queueController.adapter }),\n } satisfies ExternalStoreAdapter<ThreadMessage>;\n },\n // _version is intentionally included to trigger re-computation when core state changes via notifyUpdate\n // toolInvocations intentionally excluded: abort/resume use refs internally and work with stale captures\n [\n adapterAdapters,\n core,\n _version,\n isRunning,\n queueController,\n queueItems,\n steerQueueItems,\n shared,\n ],\n );\n\n const baseRuntime = useExternalStoreRuntime(store);\n\n const createRuntime = (): AgUiAssistantRuntime => {\n const wrapper = Object.create(baseRuntime) as AgUiAssistantRuntime;\n wrapper.unstable_getPendingInterrupts = () =>\n core.getPendingInterrupts()?.interrupts ?? [];\n wrapper.unstable_submitInterruptResponses = (responses) =>\n core.submitInterruptResponses(responses);\n return wrapper;\n };\n const [pinnedRuntime, setPinnedRuntime] = useState(() => ({\n baseRuntime,\n runtime: createRuntime(),\n }));\n let currentRuntime = pinnedRuntime;\n if (pinnedRuntime.baseRuntime !== baseRuntime) {\n currentRuntime = { baseRuntime, runtime: createRuntime() };\n setPinnedRuntime(currentRuntime);\n }\n const runtime = currentRuntime.runtime;\n\n useReplaySafeEffect(() => {\n core.attachRuntime(runtime);\n return () => {\n core.detachRuntime();\n };\n }, [core, runtime]);\n\n useEffect(() => {\n core.__internal_load();\n }, [core]);\n\n return runtime;\n}\n"],"mappings":";;;;;;;;;AAuCA,MAAM,mBAA6C,CAAC;AACpD,MAAM,oBAA+C,OAAO,OAAO,CAAC,CAAC;AACrE,MAAM,4BAA4B,CAAC;AAkBnC,SAAgB,eACd,SACsB;CACtB,MAAM,SAAS,cAAc,WAAW,QAAQ,MAAM,GAAG,CAAC,QAAQ,MAAM,CAAC;CACzE,MAAM,CAAC,UAAU,cAAc,SAAS,CAAC;CACzC,MAAM,eAAe,kBAAkB,YAAY,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC;CACnE,MAAM,UAAU,OAAqC,IAAI;CACzD,MAAM,4BAA4B,OAAO,CAAC;CAC1C,MAAM,kBAAkB,mBAAmB;CAE3C,MAAM,iBAAiB,QAAQ,UAAU,WAAW,iBAAiB;CACrE,MAAM,oBAAoB,QAAQ,UAAU;CAE5C,IAAI,CAAC,QAAQ,SACX,QAAQ,UAAU,IAAI,sBAAsB;EAC1C,OAAO,QAAQ;EACf;EACA,cAAc,QAAQ,gBAAgB;EACtC,kBAAkB,QAAQ;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
1
1
  {
2
2
  "name": "@assistant-ui/react-ag-ui",
3
- "version": "0.0.64",
3
+ "version": "0.0.65",
4
4
  "description": "AG-UI protocol adapter for assistant-ui",
5
5
  "keywords": [
6
6
  "ag-ui",
@@ -30,10 +30,10 @@
30
30
  "sideEffects": false,
31
31
  "dependencies": {
32
32
  "@ag-ui/client": "^0.0.59",
33
- "@assistant-ui/core": "^0.3.23",
34
- "@assistant-ui/react-generative-ui": "^0.0.23",
33
+ "@assistant-ui/core": "^0.3.24",
34
+ "@assistant-ui/react-generative-ui": "^0.0.24",
35
35
  "@assistant-ui/store": "^0.3.17",
36
- "assistant-stream": "^0.3.47",
36
+ "assistant-stream": "^0.3.48",
37
37
  "fast-json-patch": "^3.1.1"
38
38
  },
39
39
  "peerDependencies": {
@@ -72,6 +72,7 @@
72
72
  "scripts": {
73
73
  "build": "aui-build",
74
74
  "test": "vitest run",
75
+ "test:coverage": "vitest run --coverage --coverage.reporter=text --coverage.reporter=html --coverage.reporter=json-summary",
75
76
  "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
76
77
  "test:peer-react18": "vitest run --config vitest.peer-react18.config.ts",
77
78
  "test:types:peer-react18": "aui-react18-types",
@@ -0,0 +1,107 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import type { ThreadMessageLike } from "@assistant-ui/core";
3
+ import { toAgUiMessages } from "./conversions";
4
+
5
+ type Message = ThreadMessageLike;
6
+ type ToolCall = Extract<
7
+ Exclude<Message["content"], string>[number],
8
+ { type: "tool-call" }
9
+ >;
10
+
11
+ const toolCall = (
12
+ toolCallId: string,
13
+ messages?: readonly Message[],
14
+ ): ToolCall =>
15
+ ({
16
+ type: "tool-call",
17
+ toolCallId,
18
+ toolName: "test",
19
+ args: {},
20
+ ...(messages ? { messages } : {}),
21
+ }) as ToolCall;
22
+
23
+ const assistant = (id: string, content: readonly ToolCall[]): Message =>
24
+ ({ id, role: "assistant", content }) as Message;
25
+
26
+ const deepToolCall = (depth: number) => {
27
+ let part = toolCall(String(depth - 1));
28
+ for (let index = depth - 2; index >= 0; index--) {
29
+ part = toolCall(String(index), [assistant(`nested-${index}`, [part])]);
30
+ }
31
+ return part;
32
+ };
33
+
34
+ describe("toAgUiMessages nested tool calls", () => {
35
+ it("preserves document order", () => {
36
+ const [converted] = toAgUiMessages([
37
+ assistant("root", [
38
+ toolCall("root-call", [
39
+ assistant("nested", [
40
+ toolCall("first", [assistant("deep", [toolCall("first-child")])]),
41
+ toolCall("second"),
42
+ ]),
43
+ ]),
44
+ ]),
45
+ ]);
46
+
47
+ expect(converted).toMatchObject({ role: "assistant" });
48
+ if (converted?.role !== "assistant") throw new Error("expected assistant");
49
+ expect(converted.toolCalls?.map(({ id }) => id)).toEqual([
50
+ "root-call",
51
+ "first",
52
+ "first-child",
53
+ "second",
54
+ ]);
55
+ });
56
+
57
+ it("prunes nested tool calls below filtered a2ui parts", () => {
58
+ const [converted] = toAgUiMessages([
59
+ assistant("root", [
60
+ toolCall("root-call", [
61
+ assistant("nested", [
62
+ toolCall("a2ui:surface", [
63
+ assistant("hidden", [toolCall("hidden")]),
64
+ ]),
65
+ toolCall("visible"),
66
+ ]),
67
+ ]),
68
+ ]),
69
+ ]);
70
+
71
+ expect(converted).toMatchObject({ role: "assistant" });
72
+ if (converted?.role !== "assistant") throw new Error("expected assistant");
73
+ expect(converted.toolCalls?.map(({ id }) => id)).toEqual([
74
+ "root-call",
75
+ "visible",
76
+ ]);
77
+ });
78
+
79
+ it("converts deeply nested tool calls without overflowing the stack", () => {
80
+ const depth = 10_000;
81
+
82
+ const [converted] = toAgUiMessages([
83
+ assistant("root", [deepToolCall(depth)]),
84
+ ]);
85
+
86
+ expect(converted).toMatchObject({ role: "assistant" });
87
+ if (converted?.role !== "assistant") throw new Error("expected assistant");
88
+ expect(converted.toolCalls).toHaveLength(depth);
89
+ expect(converted.toolCalls?.at(-1)?.id).toBe(String(depth - 1));
90
+ });
91
+
92
+ it("terminates cyclic nested tool-call messages without throwing", () => {
93
+ const messages: Message[] = [];
94
+ messages.push(assistant("nested", [toolCall("nested-call", messages)]));
95
+
96
+ const [converted] = toAgUiMessages([
97
+ assistant("root", [toolCall("root-call", messages)]),
98
+ ]);
99
+
100
+ expect(converted).toMatchObject({ role: "assistant" });
101
+ if (converted?.role !== "assistant") throw new Error("expected assistant");
102
+ expect(converted.toolCalls?.map(({ id }) => id)).toEqual([
103
+ "root-call",
104
+ "nested-call",
105
+ ]);
106
+ });
107
+ });
@@ -6,14 +6,12 @@ import type {
6
6
  ThreadMessageLike as CoreThreadMessageLike,
7
7
  PartProviderMetadata,
8
8
  ReasoningMessagePart,
9
- ThreadMessage,
10
- ToolCallMessagePartMcpMetadata,
11
- ToolModelContentPart,
12
9
  } from "@assistant-ui/core";
13
10
  import {
14
11
  getAutoStatus,
15
12
  parseDataUrl,
16
13
  resolveFilePartSource,
14
+ walkToolCallTree,
17
15
  } from "@assistant-ui/core/internal";
18
16
  import { type Tool, toToolsJSONSchema } from "assistant-stream";
19
17
  import type { ReadonlyJSONObject } from "assistant-stream/utils";
@@ -99,29 +97,17 @@ export type AgUiMessage =
99
97
  error?: string;
100
98
  };
101
99
 
102
- type ToolCallPart = {
103
- type: "tool-call";
104
- toolCallId?: string;
105
- toolName: string;
106
- argsText?: string;
107
- args?: ReadonlyJSONObject;
100
+ type CoreToolCallPart = Extract<
101
+ Exclude<CoreThreadMessageLike["content"], string>[number],
102
+ { type: "tool-call" }
103
+ >;
104
+
105
+ type ToolCallPart = Omit<CoreToolCallPart, "result" | "isError"> & {
108
106
  result?: unknown;
109
- artifact?: unknown;
110
- isError?: boolean;
111
- modelContent?: readonly ToolModelContentPart[];
107
+ isError?: boolean | undefined;
112
108
  unstable_toolMessageId?: string;
113
- mcp?: ToolCallMessagePartMcpMetadata;
114
- messages?: readonly ThreadMessage[];
115
- approval?: CoreToolCallPartApproval;
116
109
  };
117
110
 
118
- type CoreToolCallPartApproval = NonNullable<
119
- Extract<
120
- Exclude<CoreThreadMessageLike["content"], string>[number],
121
- { type: "tool-call" }
122
- >["approval"]
123
- >;
124
-
125
111
  const isObject = (value: unknown): value is Record<string, unknown> =>
126
112
  typeof value === "object" && value !== null;
127
113
 
@@ -215,6 +201,9 @@ function normalizeToolCall(part: ToolCallPart): {
215
201
  };
216
202
  }
217
203
 
204
+ const isExportableNestedToolCall = (part: { readonly toolCallId?: unknown }) =>
205
+ typeof part.toolCallId === "string" && !part.toolCallId.startsWith("a2ui:");
206
+
218
207
  function extractText(content: unknown): string {
219
208
  if (typeof content === "string") return content;
220
209
  if (!Array.isArray(content)) return "";
@@ -1316,7 +1305,16 @@ function convertAssistantMessage(
1316
1305
  part: ToolCallPart;
1317
1306
  }[] = [];
1318
1307
  for (const { part } of toolCalls) {
1319
- collectNestedToolCalls(part, nestedToolCalls);
1308
+ for (const { part: nestedToolCall } of walkToolCallTree(
1309
+ part.messages ?? [],
1310
+ { shouldDescend: isExportableNestedToolCall },
1311
+ )) {
1312
+ if (!isExportableNestedToolCall(nestedToolCall)) continue;
1313
+ nestedToolCalls.push({
1314
+ ...normalizeToolCall(nestedToolCall),
1315
+ part: nestedToolCall,
1316
+ });
1317
+ }
1320
1318
  }
1321
1319
 
1322
1320
  converted.push({
@@ -1348,28 +1346,6 @@ function convertAssistantMessage(
1348
1346
  }
1349
1347
  }
1350
1348
 
1351
- function collectNestedToolCalls(
1352
- part: ToolCallPart,
1353
- out: { id: string; call: AgUiToolCall; part: ToolCallPart }[],
1354
- ): void {
1355
- for (const nested of part.messages ?? []) {
1356
- if (!isObject(nested) || nested.role !== "assistant") continue;
1357
- const nestedContent = Array.isArray(nested.content) ? nested.content : [];
1358
- for (const nestedPart of nestedContent) {
1359
- if (!isObject(nestedPart) || nestedPart.type !== "tool-call") continue;
1360
- const nestedToolCall = nestedPart as ToolCallPart;
1361
- if (
1362
- typeof nestedToolCall.toolCallId !== "string" ||
1363
- nestedToolCall.toolCallId.startsWith("a2ui:")
1364
- ) {
1365
- continue;
1366
- }
1367
- out.push({ ...normalizeToolCall(nestedToolCall), part: nestedToolCall });
1368
- collectNestedToolCalls(nestedToolCall, out);
1369
- }
1370
- }
1371
- }
1372
-
1373
1349
  function emitToolResult(
1374
1350
  toolCallId: string,
1375
1351
  part: ToolCallPart,
@@ -3,6 +3,7 @@
3
3
  import {
4
4
  isMcpAppUri,
5
5
  type ChatModelRunResult,
6
+ type MessagePartTiming,
6
7
  type MessageStatus,
7
8
  type MessageTiming,
8
9
  type ThreadAssistantMessagePart,
@@ -217,7 +218,10 @@ export class RunAggregator {
217
218
  private interrupts: AgUiInterrupt[] | undefined;
218
219
  private readonly textParts = new Map<string, { buffer: string }>();
219
220
  private readonly activeTextMessageIdByScope = new Map<string, string>();
220
- private readonly reasoningParts = new Map<string, string>(); // key → buffer
221
+ private readonly reasoningParts = new Map<
222
+ string,
223
+ { buffer: string; timing?: MessagePartTiming }
224
+ >();
221
225
  private readonly reasoningSignatures = new Map<string, string>();
222
226
  private readonly reasoningSignatureIds = new Map<string, string>();
223
227
  // Signatures captured while thinking is hidden have no block to live on;
@@ -396,6 +400,7 @@ export class RunAggregator {
396
400
  this.scopeOf("subagentRunId" in event ? event : {}),
397
401
  "messageId" in event ? event.messageId : undefined,
398
402
  event.type === "REASONING_MESSAGE_START",
403
+ event.timestamp,
399
404
  );
400
405
  break;
401
406
  case "REASONING_ENCRYPTED_VALUE":
@@ -454,11 +459,11 @@ export class RunAggregator {
454
459
  break;
455
460
  case "THINKING_TEXT_MESSAGE_END":
456
461
  case "THINKING_END":
457
- this.handleReasoningEnd(ROOT_SCOPE);
462
+ this.handleReasoningEnd(ROOT_SCOPE, event.timestamp);
458
463
  break;
459
464
  case "REASONING_MESSAGE_END":
460
465
  case "REASONING_END":
461
- this.handleReasoningEnd(this.scopeOf(event));
466
+ this.handleReasoningEnd(this.scopeOf(event), event.timestamp);
462
467
  break;
463
468
 
464
469
  case "TOOL_CALL_START": {
@@ -1222,7 +1227,8 @@ export class RunAggregator {
1222
1227
 
1223
1228
  if (part.kind === "reasoning") {
1224
1229
  if (this.showThinking) {
1225
- const buffer = this.reasoningParts.get(part.key) ?? "";
1230
+ const entry = this.reasoningParts.get(part.key);
1231
+ const buffer = entry?.buffer ?? "";
1226
1232
  const isActive =
1227
1233
  this.activeReasoningKeyByScope.get(rawScope) === part.key;
1228
1234
  if (buffer.length > 0 || isActive) {
@@ -1235,6 +1241,7 @@ export class RunAggregator {
1235
1241
  snapshot.push({
1236
1242
  type: "reasoning",
1237
1243
  text: buffer,
1244
+ ...(entry?.timing ? { timing: entry.timing } : {}),
1238
1245
  ...(Object.keys(meta).length > 0
1239
1246
  ? { providerMetadata: { [AG_UI_METADATA_NAMESPACE]: meta } }
1240
1247
  : {}),
@@ -1441,6 +1448,7 @@ export class RunAggregator {
1441
1448
  scope: string,
1442
1449
  messageId?: string,
1443
1450
  isMessageId = false,
1451
+ timestamp?: number,
1444
1452
  ): void {
1445
1453
  if (!this.showThinking) {
1446
1454
  // Hidden-reasoning bookkeeping stays root-only for this task — a
@@ -1473,13 +1481,23 @@ export class RunAggregator {
1473
1481
  this.reasoningMessageIds.set(key, messageId);
1474
1482
  }
1475
1483
  if (!this.reasoningParts.has(key)) {
1476
- this.reasoningParts.set(key, "");
1484
+ this.reasoningParts.set(key, { buffer: "" });
1477
1485
  this.partOrder.push(
1478
1486
  scope === ROOT_SCOPE
1479
1487
  ? { kind: "reasoning", key }
1480
1488
  : { kind: "reasoning", key, subagentRunId: scope },
1481
1489
  );
1482
1490
  }
1491
+ const entry = this.reasoningParts.get(key);
1492
+ if (entry?.timing) {
1493
+ entry.timing = { startedAt: entry.timing.startedAt };
1494
+ } else if (
1495
+ entry &&
1496
+ typeof timestamp === "number" &&
1497
+ Number.isFinite(timestamp)
1498
+ ) {
1499
+ entry.timing = { startedAt: timestamp };
1500
+ }
1483
1501
  this.activeReasoningKeyByScope.set(scope, key);
1484
1502
  this.emit();
1485
1503
  }
@@ -1506,15 +1524,25 @@ export class RunAggregator {
1506
1524
  }
1507
1525
  const key = this.activeReasoningKeyByScope.get(scope);
1508
1526
  if (!key) return;
1509
- this.reasoningParts.set(key, (this.reasoningParts.get(key) ?? "") + delta);
1527
+ const entry = this.reasoningParts.get(key);
1528
+ if (entry) entry.buffer += delta;
1510
1529
  this.emit();
1511
1530
  }
1512
1531
 
1513
- private handleReasoningEnd(scope: string): void {
1532
+ private handleReasoningEnd(scope: string, timestamp?: number): void {
1514
1533
  if (!this.showThinking) {
1515
1534
  if (scope === ROOT_SCOPE) this.hiddenActiveReasoning = "none";
1516
1535
  return;
1517
1536
  }
1537
+ const key = this.activeReasoningKeyByScope.get(scope);
1538
+ const entry = key ? this.reasoningParts.get(key) : undefined;
1539
+ if (
1540
+ entry?.timing &&
1541
+ typeof timestamp === "number" &&
1542
+ Number.isFinite(timestamp)
1543
+ ) {
1544
+ entry.timing = { ...entry.timing, completedAt: timestamp };
1545
+ }
1518
1546
  this.activeReasoningKeyByScope.delete(scope);
1519
1547
  this.emit();
1520
1548
  }
@@ -146,6 +146,10 @@ export const parseAgUiEvent = (
146
146
 
147
147
  const getString = (key: string) =>
148
148
  isString(payload[key]) ? (payload[key] as string) : undefined;
149
+ const timestamp =
150
+ typeof payload.timestamp === "number" && Number.isFinite(payload.timestamp)
151
+ ? payload.timestamp
152
+ : undefined;
149
153
 
150
154
  switch (typeValue) {
151
155
  case "RUN_STARTED": {
@@ -219,24 +223,31 @@ export const parseAgUiEvent = (
219
223
  case "THINKING_START":
220
224
  return withOptional(
221
225
  { type: "THINKING_START" as const },
222
- { title: getString("title") },
226
+ { title: getString("title"), timestamp },
223
227
  );
224
228
  case "THINKING_TEXT_MESSAGE_START":
225
- return { type: "THINKING_TEXT_MESSAGE_START" };
229
+ return withOptional(
230
+ { type: "THINKING_TEXT_MESSAGE_START" as const },
231
+ { timestamp },
232
+ );
226
233
  case "THINKING_TEXT_MESSAGE_CONTENT": {
227
234
  const delta = getString("delta") ?? "";
228
235
  return { type: "THINKING_TEXT_MESSAGE_CONTENT", delta };
229
236
  }
230
237
  case "THINKING_TEXT_MESSAGE_END":
231
- return { type: "THINKING_TEXT_MESSAGE_END" };
238
+ return withOptional(
239
+ { type: "THINKING_TEXT_MESSAGE_END" as const },
240
+ { timestamp },
241
+ );
232
242
  case "THINKING_END":
233
- return { type: "THINKING_END" };
243
+ return withOptional({ type: "THINKING_END" as const }, { timestamp });
234
244
  case "REASONING_START":
235
245
  return withOptional(
236
246
  { type: "REASONING_START" as const },
237
247
  {
238
248
  messageId: getString("messageId"),
239
249
  subagentRunId: getString("subagentRunId"),
250
+ timestamp,
240
251
  },
241
252
  );
242
253
  case "REASONING_MESSAGE_START":
@@ -245,6 +256,7 @@ export const parseAgUiEvent = (
245
256
  {
246
257
  messageId: getString("messageId"),
247
258
  subagentRunId: getString("subagentRunId"),
259
+ timestamp,
248
260
  },
249
261
  );
250
262
  case "REASONING_MESSAGE_CONTENT": {
@@ -263,6 +275,7 @@ export const parseAgUiEvent = (
263
275
  {
264
276
  messageId: getString("messageId"),
265
277
  subagentRunId: getString("subagentRunId"),
278
+ timestamp,
266
279
  },
267
280
  );
268
281
  case "REASONING_ENCRYPTED_VALUE": {
@@ -292,6 +305,7 @@ export const parseAgUiEvent = (
292
305
  {
293
306
  messageId: getString("messageId"),
294
307
  subagentRunId: getString("subagentRunId"),
308
+ timestamp,
295
309
  },
296
310
  );
297
311
  case "TOOL_CALL_START": {