@assistant-ui/react-ai-sdk 1.3.25 → 1.3.27
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/frontendTools.d.ts +9 -5
- package/dist/frontendTools.d.ts.map +1 -1
- package/dist/frontendTools.js +36 -35
- package/dist/frontendTools.js.map +1 -1
- package/dist/index.d.ts +9 -11
- package/dist/index.js +9 -10
- package/dist/injectQuoteContext.d.ts +6 -2
- package/dist/injectQuoteContext.d.ts.map +1 -1
- package/dist/injectQuoteContext.js +46 -53
- package/dist/injectQuoteContext.js.map +1 -1
- package/dist/modelContentEnvelope.d.ts +12 -10
- package/dist/modelContentEnvelope.d.ts.map +1 -1
- package/dist/modelContentEnvelope.js +17 -15
- package/dist/modelContentEnvelope.js.map +1 -1
- package/dist/node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts +141 -0
- package/dist/node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts.map +1 -0
- package/dist/packages/assistant-stream/dist/core/AssistantStream.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/core/AssistantStreamChunk.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/core/accumulators/AssistantMessageStream.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/core/accumulators/assistant-message-accumulator.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/core/modules/assistant-stream.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/core/modules/text.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/core/modules/tool-call.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/core/serialization/PlainText.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/core/serialization/assistant-transport/AssistantTransport.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/core/serialization/data-stream/DataStream.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/core/serialization/ui-message-stream/UIMessageStream.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/core/tool/ToolExecutionStream.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/core/tool/schema-utils.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/core/tool/schema-utils.js +50 -0
- package/dist/packages/assistant-stream/dist/core/tool/schema-utils.js.map +1 -0
- package/dist/packages/assistant-stream/dist/core/tool/tool-types.d.ts +43 -0
- package/dist/packages/assistant-stream/dist/core/tool/tool-types.d.ts.map +1 -0
- package/dist/packages/assistant-stream/dist/core/tool/toolResultStream.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/core/utils/stream/AssistantMetaTransformStream.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/core/utils/stream/AssistantTransformStream.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/core/utils/types.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/index.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/resumable/createResumableAssistantStreamResponse.d.ts +6 -0
- package/dist/packages/assistant-stream/dist/resumable/createResumableAssistantStreamResponse.d.ts.map +1 -0
- package/dist/packages/assistant-stream/dist/resumable/createResumableAssistantStreamResponse.js +6 -0
- package/dist/packages/assistant-stream/dist/resumable/createResumableAssistantStreamResponse.js.map +1 -0
- package/dist/packages/assistant-stream/dist/resumable/index.d.ts +1 -0
- package/dist/packages/assistant-stream/dist/utils/json/json-value.d.ts +10 -0
- package/dist/packages/assistant-stream/dist/utils/json/json-value.d.ts.map +1 -0
- package/dist/packages/assistant-stream/dist/utils.d.ts +1 -0
- package/dist/ui/adapters/aiSDKFormatAdapter.d.ts +8 -4
- package/dist/ui/adapters/aiSDKFormatAdapter.d.ts.map +1 -1
- package/dist/ui/adapters/aiSDKFormatAdapter.js +24 -20
- package/dist/ui/adapters/aiSDKFormatAdapter.js.map +1 -1
- package/dist/ui/getVercelAIMessages.d.ts +7 -3
- package/dist/ui/getVercelAIMessages.d.ts.map +1 -1
- package/dist/ui/getVercelAIMessages.js +7 -3
- package/dist/ui/getVercelAIMessages.js.map +1 -1
- package/dist/ui/resumable.d.ts +18 -15
- package/dist/ui/resumable.d.ts.map +1 -1
- package/dist/ui/resumable.js +21 -20
- package/dist/ui/resumable.js.map +1 -1
- package/dist/ui/use-chat/AssistantChatTransport.d.ts +17 -14
- package/dist/ui/use-chat/AssistantChatTransport.d.ts.map +1 -1
- package/dist/ui/use-chat/AssistantChatTransport.js +98 -108
- package/dist/ui/use-chat/AssistantChatTransport.js.map +1 -1
- package/dist/ui/use-chat/useAISDKRuntime.d.ts +43 -33
- package/dist/ui/use-chat/useAISDKRuntime.d.ts.map +1 -1
- package/dist/ui/use-chat/useAISDKRuntime.js +176 -204
- package/dist/ui/use-chat/useAISDKRuntime.js.map +1 -1
- package/dist/ui/use-chat/useChatRuntime.d.ts +19 -12
- package/dist/ui/use-chat/useChatRuntime.d.ts.map +1 -1
- package/dist/ui/use-chat/useChatRuntime.js +60 -81
- package/dist/ui/use-chat/useChatRuntime.js.map +1 -1
- package/dist/ui/use-chat/useExternalHistory.d.ts +8 -4
- package/dist/ui/use-chat/useExternalHistory.d.ts.map +1 -1
- package/dist/ui/use-chat/useExternalHistory.js +178 -200
- package/dist/ui/use-chat/useExternalHistory.js.map +1 -1
- package/dist/ui/use-chat/useStreamingTiming.d.ts +7 -3
- package/dist/ui/use-chat/useStreamingTiming.d.ts.map +1 -1
- package/dist/ui/use-chat/useStreamingTiming.js +60 -75
- package/dist/ui/use-chat/useStreamingTiming.js.map +1 -1
- package/dist/ui/utils/convertMessage.d.ts +29 -20
- package/dist/ui/utils/convertMessage.d.ts.map +1 -1
- package/dist/ui/utils/convertMessage.js +219 -286
- package/dist/ui/utils/convertMessage.js.map +1 -1
- package/dist/ui/utils/sliceMessagesUntil.d.ts +6 -2
- package/dist/ui/utils/sliceMessagesUntil.d.ts.map +1 -1
- package/dist/ui/utils/sliceMessagesUntil.js +10 -10
- package/dist/ui/utils/sliceMessagesUntil.js.map +1 -1
- package/dist/ui/utils/toCreateMessage.d.ts +7 -3
- package/dist/ui/utils/toCreateMessage.d.ts.map +1 -1
- package/dist/ui/utils/toCreateMessage.js +34 -38
- package/dist/ui/utils/toCreateMessage.js.map +1 -1
- package/dist/ui/utils/vercelAttachmentAdapter.d.ts +6 -2
- package/dist/ui/utils/vercelAttachmentAdapter.d.ts.map +1 -1
- package/dist/ui/utils/vercelAttachmentAdapter.js +37 -35
- package/dist/ui/utils/vercelAttachmentAdapter.js.map +1 -1
- package/dist/usage.d.ts +15 -12
- package/dist/usage.d.ts.map +1 -1
- package/dist/usage.js +80 -99
- package/dist/usage.js.map +1 -1
- package/package.json +12 -11
- package/src/ui/use-chat/useAISDKRuntime.test.ts +2 -2
- package/src/ui/utils/convertMessage.test.ts +28 -0
- package/src/ui/utils/convertMessage.ts +24 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useExternalHistory.js","sourceRoot":"","sources":["../../../src/ui/use-chat/useExternalHistory.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAUb,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EACL,MAAM,EACN,SAAS,EACT,QAAQ,EAER,WAAW,EACX,OAAO,GACR,MAAM,OAAO,CAAC;AAEf,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,gBAA2D,EAC3D,QAA2C,EAChB,EAAE;IAC7B,OAAO;QACL,MAAM,EAAE,QAAQ,CAAC,MAAO;QACxB,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACpC,MAAM,OAAO,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC;YAClD,OAAO;gBACL,GAAG,CAAC;gBACJ,OAA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AC;YACH,CAAC,EAAE,CAAC,CAAC,CAAC;QACR,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,WAAW,EAAE,CAAC;YACd,IAAI,eAAe,CAAC,OAAO,EAAE,CAAC;gBAC5B,YAAY,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;gBACtC,eAAe,CAAC,OAAO,GAAG,IAAI,CAAC;YACjC,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,aAAa,EAAE,oBAAoB,EAAE,UAAU,CAAC,CAAC,CAAC;IAEtD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"useExternalHistory.js","names":[],"sources":["../../../src/ui/use-chat/useExternalHistory.ts"],"sourcesContent":["\"use client\";\n\nimport type {\n AssistantRuntime,\n ThreadHistoryAdapter,\n ThreadMessage,\n MessageFormatAdapter,\n MessageFormatRepository,\n ExportedMessageRepository,\n} from \"@assistant-ui/core\";\nimport { getExternalStoreMessages } from \"@assistant-ui/core\";\nimport { MessageRepository } from \"@assistant-ui/core/internal\";\nimport { useAui } from \"@assistant-ui/store\";\nimport {\n useRef,\n useEffect,\n useState,\n type RefObject,\n useCallback,\n useMemo,\n} from \"react\";\n\nexport const toExportedMessageRepository = <TMessage>(\n toThreadMessages: (messages: TMessage[]) => ThreadMessage[],\n messages: MessageFormatRepository<TMessage>,\n): ExportedMessageRepository => {\n return {\n headId: messages.headId!,\n messages: messages.messages.map((m) => {\n const message = toThreadMessages([m.message])[0]!;\n return {\n ...m,\n message,\n };\n }),\n };\n};\n\nexport const useExternalHistory = <TMessage>(\n runtimeRef: RefObject<AssistantRuntime>,\n historyAdapter: ThreadHistoryAdapter | undefined,\n toThreadMessages: (messages: TMessage[]) => ThreadMessage[],\n storageFormatAdapter: MessageFormatAdapter<TMessage, any>,\n onSetMessages: (messages: TMessage[]) => void,\n) => {\n const loadedRef = useRef(false);\n\n const aui = useAui();\n const optionalThreadListItem = useCallback(\n () => (aui.threadListItem.source ? aui.threadListItem() : null),\n [aui],\n );\n\n const [isLoading, setIsLoading] = useState(false);\n\n const historyIds = useRef(new Set<string>());\n\n const onSetMessagesRef = useRef(onSetMessages);\n useEffect(() => {\n onSetMessagesRef.current = onSetMessages;\n });\n\n const formatAdapter = useMemo(() => {\n if (!historyAdapter) return undefined;\n if (!historyAdapter.withFormat) {\n throw new Error(\n \"useAISDKRuntime: ThreadHistoryAdapter is missing the required `withFormat` method.\",\n );\n }\n return historyAdapter.withFormat<TMessage, any>(storageFormatAdapter);\n }, [historyAdapter, storageFormatAdapter]);\n\n useEffect(() => {\n if (!formatAdapter || loadedRef.current) return;\n\n const loadHistory = async () => {\n setIsLoading(true);\n try {\n const repo = await formatAdapter.load();\n if (repo && repo.messages.length > 0) {\n const converted = toExportedMessageRepository(toThreadMessages, repo);\n runtimeRef.current.thread.import(converted);\n\n const tempRepo = new MessageRepository();\n tempRepo.import(converted);\n const messages = tempRepo.getMessages();\n\n onSetMessagesRef.current(\n messages.flatMap(getExternalStoreMessages<TMessage>),\n );\n\n historyIds.current = new Set(\n converted.messages.map((m) => m.message.id),\n );\n }\n } catch (error) {\n console.error(\"Failed to load message history:\", error);\n } finally {\n setIsLoading(false);\n }\n };\n\n loadedRef.current = true;\n\n if (!optionalThreadListItem()?.getState().remoteId) {\n setIsLoading(false);\n return;\n }\n\n loadHistory();\n }, [formatAdapter, toThreadMessages, runtimeRef, optionalThreadListItem]);\n\n const runStartRef = useRef<number | null>(null);\n const persistTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const stepBoundariesRef = useRef<number[]>([]);\n const wasRunningRef = useRef(false);\n const toolCallCountRef = useRef(0);\n\n useEffect(() => {\n if (!formatAdapter) return;\n\n const unsubscribe = runtimeRef.current.thread.subscribe(() => {\n const { isRunning } = runtimeRef.current.thread.getState();\n const wasRunning = wasRunningRef.current;\n wasRunningRef.current = isRunning;\n\n // Track step boundaries by content changes (more reliable than isRunning)\n if (runStartRef.current != null) {\n const lastMsg = runtimeRef.current.thread.getState().messages.at(-1);\n if (lastMsg?.role === \"assistant\") {\n const currentToolCallCount = lastMsg.content.filter(\n (p) => p.type === \"tool-call\",\n ).length;\n while (toolCallCountRef.current < currentToolCallCount) {\n stepBoundariesRef.current.push(Date.now() - runStartRef.current);\n toolCallCountRef.current++;\n }\n }\n }\n\n if (isRunning) {\n if (runStartRef.current == null) {\n runStartRef.current = Date.now();\n stepBoundariesRef.current = [];\n toolCallCountRef.current = 0;\n }\n // Cancel any pending persist — isRunning went back to true\n if (persistTimerRef.current) {\n clearTimeout(persistTimerRef.current);\n persistTimerRef.current = null;\n }\n return;\n }\n\n // Only act on the true→false transition\n if (!wasRunning) return;\n\n // Record step boundary offset (synchronous for accuracy)\n if (runStartRef.current != null) {\n stepBoundariesRef.current.push(Date.now() - runStartRef.current);\n }\n\n // Debounce: wait one macrotask so agentic step flickers are absorbed\n if (persistTimerRef.current) clearTimeout(persistTimerRef.current);\n persistTimerRef.current = setTimeout(async () => {\n persistTimerRef.current = null;\n\n // Re-read latest state — may have changed since the timeout was scheduled\n const latest = runtimeRef.current.thread.getState();\n if (latest.isRunning) return; // was just a flicker\n\n // Derive durationMs from the last boundary (covers all steps)\n const boundaries = stepBoundariesRef.current;\n const durationMs =\n boundaries.length > 0 ? boundaries.at(-1) : undefined;\n\n // Fallback: if only 1 boundary but message has multiple steps, distribute evenly\n if (boundaries.length === 1 && durationMs != null) {\n const lastAssistant = latest.messages.findLast(\n (m) => m.role === \"assistant\",\n );\n if (lastAssistant) {\n const tcCount = lastAssistant.content.filter(\n (p) => p.type === \"tool-call\",\n ).length;\n if (tcCount > 0) {\n const totalSteps = tcCount + 1;\n const stepDur = durationMs / totalSteps;\n boundaries.length = 0;\n for (let i = 0; i < totalSteps; i++) {\n boundaries.push(Math.round((i + 1) * stepDur));\n }\n }\n }\n }\n\n // Build per-step timestamps when there are multiple steps\n const stepTimestamps =\n boundaries.length > 1\n ? boundaries.map((endMs, i) => ({\n start_ms: i === 0 ? 0 : boundaries[i - 1]!,\n end_ms: endMs,\n }))\n : undefined;\n\n runStartRef.current = null;\n stepBoundariesRef.current = [];\n\n const telemetryOptions = {\n ...(durationMs != null ? { durationMs } : undefined),\n ...(stepTimestamps != null ? { stepTimestamps } : undefined),\n };\n\n const { messages } = latest;\n let lastInnerMessageId: string | null = null;\n\n const getLastInnerId = (msgs: TMessage[]): string | null =>\n msgs.length > 0 ? storageFormatAdapter.getId(msgs.at(-1)!) : null;\n\n const toBatchItems = (msgs: TMessage[]) =>\n msgs.map((msg, idx) => ({\n parentId:\n idx === 0\n ? lastInnerMessageId\n : storageFormatAdapter.getId(msgs[idx - 1]!),\n message: msg,\n }));\n\n for (const message of messages) {\n const innerMessages = getExternalStoreMessages<TMessage>(message);\n\n const isReady =\n message.status === undefined ||\n message.status.type === \"complete\" ||\n message.status.type === \"incomplete\";\n\n if (!isReady) {\n lastInnerMessageId =\n getLastInnerId(innerMessages) ?? lastInnerMessageId;\n continue;\n }\n\n if (historyIds.current.has(message.id)) {\n if (durationMs !== undefined) {\n let parentId = lastInnerMessageId;\n for (const innerMessage of innerMessages) {\n try {\n await formatAdapter.update?.(\n { parentId, message: innerMessage },\n storageFormatAdapter.getId(innerMessage),\n );\n } catch {\n // ignore update failures to avoid breaking the message processing loop\n }\n parentId = storageFormatAdapter.getId(innerMessage);\n }\n }\n lastInnerMessageId =\n getLastInnerId(innerMessages) ?? lastInnerMessageId;\n continue;\n }\n historyIds.current.add(message.id);\n\n const batchItems = toBatchItems(innerMessages);\n for (const item of batchItems) {\n await formatAdapter.append(item);\n }\n\n lastInnerMessageId =\n getLastInnerId(innerMessages) ?? lastInnerMessageId;\n\n formatAdapter.reportTelemetry?.(batchItems, telemetryOptions);\n }\n }, 0);\n });\n\n return () => {\n unsubscribe();\n if (persistTimerRef.current) {\n clearTimeout(persistTimerRef.current);\n persistTimerRef.current = null;\n }\n };\n }, [formatAdapter, storageFormatAdapter, runtimeRef]);\n\n return isLoading;\n};\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,IACJ,qBACA,qBAAqB,MAAM,KAAK,MAAM,EAAG;KAC/C,SAAS;IACX,EAAE;IAEJ,KAAK,MAAM,WAAW,UAAU;KAC9B,MAAM,gBAAgB,yBAAmC,OAAO;KAOhE,IAAI,EAJF,QAAQ,WAAW,KAAA,KACnB,QAAQ,OAAO,SAAS,cACxB,QAAQ,OAAO,SAAS,eAEZ;MACZ,qBACE,eAAe,aAAa,KAAK;MACnC;KACF;KAEA,IAAI,WAAW,QAAQ,IAAI,QAAQ,EAAE,GAAG;MACtC,IAAI,eAAe,KAAA,GAAW;OAC5B,IAAI,WAAW;OACf,KAAK,MAAM,gBAAgB,eAAe;QACxC,IAAI;SACF,MAAM,cAAc,SAClB;UAAE;UAAU,SAAS;SAAa,GAClC,qBAAqB,MAAM,YAAY,CACzC;QACF,QAAQ,CAER;QACA,WAAW,qBAAqB,MAAM,YAAY;OACpD;MACF;MACA,qBACE,eAAe,aAAa,KAAK;MACnC;KACF;KACA,WAAW,QAAQ,IAAI,QAAQ,EAAE;KAEjC,MAAM,aAAa,aAAa,aAAa;KAC7C,KAAK,MAAM,QAAQ,YACjB,MAAM,cAAc,OAAO,IAAI;KAGjC,qBACE,eAAe,aAAa,KAAK;KAEnC,cAAc,kBAAkB,YAAY,gBAAgB;IAC9D;GACF,GAAG,CAAC;EACN,CAAC;EAED,aAAa;GACX,YAAY;GACZ,IAAI,gBAAgB,SAAS;IAC3B,aAAa,gBAAgB,OAAO;IACpC,gBAAgB,UAAU;GAC5B;EACF;CACF,GAAG;EAAC;EAAe;EAAsB;CAAU,CAAC;CAEpD,OAAO;AACT"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { MessageTiming } from "@assistant-ui/core";
|
|
2
|
+
import { UIMessage } from "@ai-sdk/react";
|
|
3
|
+
|
|
4
|
+
//#region src/ui/use-chat/useStreamingTiming.d.ts
|
|
3
5
|
/**
|
|
4
6
|
* Tracks streaming timing for AI SDK messages client-side.
|
|
5
7
|
*
|
|
@@ -7,5 +9,7 @@ import type { MessageTiming } from "@assistant-ui/core";
|
|
|
7
9
|
* timing metrics (TTFT, duration, tok/s). Timing is finalized when
|
|
8
10
|
* streaming ends and stored per message ID.
|
|
9
11
|
*/
|
|
10
|
-
|
|
12
|
+
declare const useStreamingTiming: (messages: UIMessage[], isRunning: boolean) => Record<string, MessageTiming>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { useStreamingTiming };
|
|
11
15
|
//# sourceMappingURL=useStreamingTiming.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStreamingTiming.d.ts","
|
|
1
|
+
{"version":3,"file":"useStreamingTiming.d.ts","names":[],"sources":["../../../src/ui/use-chat/useStreamingTiming.ts"],"mappings":";;;;;;AAwCA;;;;;cAAa,kBAAA,GACX,QAAA,EAAU,SAAA,IACV,SAAA,cACC,MAAA,SAAe,aAAA"}
|
|
@@ -1,84 +1,69 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useEffect, useRef, useState } from "react";
|
|
3
2
|
import { isToolUIPart } from "ai";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
//#region src/ui/use-chat/useStreamingTiming.ts
|
|
4
5
|
function getTextLength(message) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (part.type === "text")
|
|
10
|
-
len += part.text.length;
|
|
11
|
-
}
|
|
12
|
-
return len;
|
|
6
|
+
if (!message?.parts) return 0;
|
|
7
|
+
let len = 0;
|
|
8
|
+
for (const part of message.parts) if (part.type === "text") len += part.text.length;
|
|
9
|
+
return len;
|
|
13
10
|
}
|
|
14
11
|
function getToolCallCount(message) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (isToolUIPart(part))
|
|
20
|
-
count++;
|
|
21
|
-
}
|
|
22
|
-
return count;
|
|
12
|
+
if (!message?.parts) return 0;
|
|
13
|
+
let count = 0;
|
|
14
|
+
for (const part of message.parts) if (isToolUIPart(part)) count++;
|
|
15
|
+
return count;
|
|
23
16
|
}
|
|
24
17
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
...(tokenCount > 0 && { tokenCount }),
|
|
73
|
-
...(totalStreamTime > 0 &&
|
|
74
|
-
tokenCount > 0 && {
|
|
75
|
-
tokensPerSecond: tokenCount / (totalStreamTime / 1000),
|
|
76
|
-
}),
|
|
77
|
-
};
|
|
78
|
-
setTimings((prev) => ({ ...prev, [t.messageId]: timing }));
|
|
79
|
-
trackRef.current = null;
|
|
80
|
-
}
|
|
81
|
-
}, [messages, isRunning]);
|
|
82
|
-
return timings;
|
|
18
|
+
* Tracks streaming timing for AI SDK messages client-side.
|
|
19
|
+
*
|
|
20
|
+
* Observes `isRunning` transitions and content changes to estimate
|
|
21
|
+
* timing metrics (TTFT, duration, tok/s). Timing is finalized when
|
|
22
|
+
* streaming ends and stored per message ID.
|
|
23
|
+
*/
|
|
24
|
+
const useStreamingTiming = (messages, isRunning) => {
|
|
25
|
+
const [timings, setTimings] = useState({});
|
|
26
|
+
const trackRef = useRef(null);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const lastAssistant = messages.findLast((m) => m.role === "assistant");
|
|
29
|
+
if (isRunning && lastAssistant) {
|
|
30
|
+
if (!trackRef.current || trackRef.current.messageId !== lastAssistant.id) trackRef.current = {
|
|
31
|
+
messageId: lastAssistant.id,
|
|
32
|
+
startTime: Date.now(),
|
|
33
|
+
lastContentLength: 0,
|
|
34
|
+
totalChunks: 0
|
|
35
|
+
};
|
|
36
|
+
const t = trackRef.current;
|
|
37
|
+
const len = getTextLength(lastAssistant);
|
|
38
|
+
if (len > t.lastContentLength) {
|
|
39
|
+
if (t.firstTokenTime === void 0) t.firstTokenTime = Date.now() - t.startTime;
|
|
40
|
+
t.totalChunks++;
|
|
41
|
+
t.lastContentLength = len;
|
|
42
|
+
}
|
|
43
|
+
} else if (!isRunning && trackRef.current) {
|
|
44
|
+
const t = trackRef.current;
|
|
45
|
+
const totalStreamTime = Date.now() - t.startTime;
|
|
46
|
+
const tokenCount = Math.ceil(t.lastContentLength / 4);
|
|
47
|
+
const toolCallCount = getToolCallCount(lastAssistant);
|
|
48
|
+
const timing = {
|
|
49
|
+
streamStartTime: t.startTime,
|
|
50
|
+
totalStreamTime,
|
|
51
|
+
totalChunks: t.totalChunks,
|
|
52
|
+
toolCallCount,
|
|
53
|
+
...t.firstTokenTime !== void 0 && { firstTokenTime: t.firstTokenTime },
|
|
54
|
+
...tokenCount > 0 && { tokenCount },
|
|
55
|
+
...totalStreamTime > 0 && tokenCount > 0 && { tokensPerSecond: tokenCount / (totalStreamTime / 1e3) }
|
|
56
|
+
};
|
|
57
|
+
setTimings((prev) => ({
|
|
58
|
+
...prev,
|
|
59
|
+
[t.messageId]: timing
|
|
60
|
+
}));
|
|
61
|
+
trackRef.current = null;
|
|
62
|
+
}
|
|
63
|
+
}, [messages, isRunning]);
|
|
64
|
+
return timings;
|
|
83
65
|
};
|
|
66
|
+
//#endregion
|
|
67
|
+
export { useStreamingTiming };
|
|
68
|
+
|
|
84
69
|
//# sourceMappingURL=useStreamingTiming.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStreamingTiming.js","
|
|
1
|
+
{"version":3,"file":"useStreamingTiming.js","names":[],"sources":["../../../src/ui/use-chat/useStreamingTiming.ts"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport type { UIMessage } from \"@ai-sdk/react\";\nimport { isToolUIPart } from \"ai\";\nimport type { MessageTiming } from \"@assistant-ui/core\";\n\ntype TrackingState = {\n messageId: string;\n startTime: number;\n firstTokenTime?: number;\n lastContentLength: number;\n totalChunks: number;\n};\n\nfunction getTextLength(message: UIMessage | undefined): number {\n if (!message?.parts) return 0;\n let len = 0;\n for (const part of message.parts) {\n if (part.type === \"text\") len += part.text.length;\n }\n return len;\n}\n\nfunction getToolCallCount(message: UIMessage | undefined): number {\n if (!message?.parts) return 0;\n let count = 0;\n for (const part of message.parts) {\n if (isToolUIPart(part)) count++;\n }\n return count;\n}\n\n/**\n * Tracks streaming timing for AI SDK messages client-side.\n *\n * Observes `isRunning` transitions and content changes to estimate\n * timing metrics (TTFT, duration, tok/s). Timing is finalized when\n * streaming ends and stored per message ID.\n */\nexport const useStreamingTiming = (\n messages: UIMessage[],\n isRunning: boolean,\n): Record<string, MessageTiming> => {\n const [timings, setTimings] = useState<Record<string, MessageTiming>>({});\n const trackRef = useRef<TrackingState | null>(null);\n\n useEffect(() => {\n const lastAssistant = messages.findLast((m) => m.role === \"assistant\");\n\n if (isRunning && lastAssistant) {\n // Start tracking if not already or if message changed\n if (\n !trackRef.current ||\n trackRef.current.messageId !== lastAssistant.id\n ) {\n trackRef.current = {\n messageId: lastAssistant.id,\n startTime: Date.now(),\n lastContentLength: 0,\n totalChunks: 0,\n };\n }\n\n // Track content changes\n const t = trackRef.current;\n const len = getTextLength(lastAssistant);\n if (len > t.lastContentLength) {\n if (t.firstTokenTime === undefined) {\n t.firstTokenTime = Date.now() - t.startTime;\n }\n t.totalChunks++;\n t.lastContentLength = len;\n }\n } else if (!isRunning && trackRef.current) {\n // Streaming ended — finalize timing\n const t = trackRef.current;\n const totalStreamTime = Date.now() - t.startTime;\n const tokenCount = Math.ceil(t.lastContentLength / 4);\n const toolCallCount = getToolCallCount(lastAssistant);\n\n const timing: MessageTiming = {\n streamStartTime: t.startTime,\n totalStreamTime,\n totalChunks: t.totalChunks,\n toolCallCount,\n ...(t.firstTokenTime !== undefined && {\n firstTokenTime: t.firstTokenTime,\n }),\n ...(tokenCount > 0 && { tokenCount }),\n ...(totalStreamTime > 0 &&\n tokenCount > 0 && {\n tokensPerSecond: tokenCount / (totalStreamTime / 1000),\n }),\n };\n setTimings((prev) => ({ ...prev, [t.messageId]: timing }));\n trackRef.current = null;\n }\n }, [messages, isRunning]);\n\n return timings;\n};\n"],"mappings":";;;;AAeA,SAAS,cAAc,SAAwC;CAC7D,IAAI,CAAC,SAAS,OAAO,OAAO;CAC5B,IAAI,MAAM;CACV,KAAK,MAAM,QAAQ,QAAQ,OACzB,IAAI,KAAK,SAAS,QAAQ,OAAO,KAAK,KAAK;CAE7C,OAAO;AACT;AAEA,SAAS,iBAAiB,SAAwC;CAChE,IAAI,CAAC,SAAS,OAAO,OAAO;CAC5B,IAAI,QAAQ;CACZ,KAAK,MAAM,QAAQ,QAAQ,OACzB,IAAI,aAAa,IAAI,GAAG;CAE1B,OAAO;AACT;;;;;;;;AASA,MAAa,sBACX,UACA,cACkC;CAClC,MAAM,CAAC,SAAS,cAAc,SAAwC,CAAC,CAAC;CACxE,MAAM,WAAW,OAA6B,IAAI;CAElD,gBAAgB;EACd,MAAM,gBAAgB,SAAS,UAAU,MAAM,EAAE,SAAS,WAAW;EAErE,IAAI,aAAa,eAAe;GAE9B,IACE,CAAC,SAAS,WACV,SAAS,QAAQ,cAAc,cAAc,IAE7C,SAAS,UAAU;IACjB,WAAW,cAAc;IACzB,WAAW,KAAK,IAAI;IACpB,mBAAmB;IACnB,aAAa;GACf;GAIF,MAAM,IAAI,SAAS;GACnB,MAAM,MAAM,cAAc,aAAa;GACvC,IAAI,MAAM,EAAE,mBAAmB;IAC7B,IAAI,EAAE,mBAAmB,KAAA,GACvB,EAAE,iBAAiB,KAAK,IAAI,IAAI,EAAE;IAEpC,EAAE;IACF,EAAE,oBAAoB;GACxB;EACF,OAAO,IAAI,CAAC,aAAa,SAAS,SAAS;GAEzC,MAAM,IAAI,SAAS;GACnB,MAAM,kBAAkB,KAAK,IAAI,IAAI,EAAE;GACvC,MAAM,aAAa,KAAK,KAAK,EAAE,oBAAoB,CAAC;GACpD,MAAM,gBAAgB,iBAAiB,aAAa;GAEpD,MAAM,SAAwB;IAC5B,iBAAiB,EAAE;IACnB;IACA,aAAa,EAAE;IACf;IACA,GAAI,EAAE,mBAAmB,KAAA,KAAa,EACpC,gBAAgB,EAAE,eACpB;IACA,GAAI,aAAa,KAAK,EAAE,WAAW;IACnC,GAAI,kBAAkB,KACpB,aAAa,KAAK,EAChB,iBAAiB,cAAc,kBAAkB,KACnD;GACJ;GACA,YAAY,UAAU;IAAE,GAAG;KAAO,EAAE,YAAY;GAAO,EAAE;GACzD,SAAS,UAAU;EACrB;CACF,GAAG,CAAC,UAAU,SAAS,CAAC;CAExB,OAAO;AACT"}
|
|
@@ -1,23 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { ReadonlyJSONObject } from "../../packages/assistant-stream/dist/utils/json/json-value.js";
|
|
2
|
+
import { UIMessage } from "ai";
|
|
3
|
+
import { useExternalMessageConverter } from "@assistant-ui/core/react";
|
|
4
|
+
import { McpAppMetadata } from "@assistant-ui/core";
|
|
5
|
+
|
|
6
|
+
//#region src/ui/utils/convertMessage.d.ts
|
|
7
|
+
type AISDKMessageConverterMetadata = useExternalMessageConverter.Metadata & {
|
|
8
|
+
toolArgsKeyOrderCache?: Map<string, Map<string, string[]>>;
|
|
9
|
+
toolLastInputCache?: Map<string, ReadonlyJSONObject>;
|
|
10
|
+
mcpAppMetadataCache?: Map<string, McpAppMetadata>;
|
|
9
11
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
declare const AISDKMessageConverter: {
|
|
13
|
+
useThreadMessages: ({
|
|
14
|
+
messages,
|
|
15
|
+
isRunning,
|
|
16
|
+
joinStrategy,
|
|
17
|
+
metadata
|
|
18
|
+
}: {
|
|
19
|
+
messages: UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>[];
|
|
20
|
+
isRunning: boolean;
|
|
21
|
+
joinStrategy?: "concat-content" | "none" | undefined;
|
|
22
|
+
metadata?: useExternalMessageConverter.Metadata;
|
|
23
|
+
}) => import("@assistant-ui/core").ThreadMessage[];
|
|
24
|
+
toThreadMessages: (messages: UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>[], isRunning?: boolean, metadata?: useExternalMessageConverter.Metadata) => import("@assistant-ui/core").ThreadMessage[];
|
|
25
|
+
toOriginalMessages: (input: import("@assistant-ui/core").ThreadState | import("@assistant-ui/core").ThreadMessage | import("@assistant-ui/core").ThreadMessage["content"][number]) => unknown[];
|
|
26
|
+
toOriginalMessage: (input: import("@assistant-ui/core").ThreadState | import("@assistant-ui/core").ThreadMessage | import("@assistant-ui/core").ThreadMessage["content"][number]) => {};
|
|
27
|
+
useOriginalMessage: () => {};
|
|
28
|
+
useOriginalMessages: () => unknown[];
|
|
22
29
|
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { AISDKMessageConverter, AISDKMessageConverterMetadata };
|
|
23
32
|
//# sourceMappingURL=convertMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertMessage.d.ts","
|
|
1
|
+
{"version":3,"file":"convertMessage.d.ts","names":[],"sources":["../../../src/ui/utils/convertMessage.ts"],"mappings":";;;;;;KAqBY,6BAAA,GACV,2BAAA,CAA4B,QAAA;EAC1B,qBAAA,GAAwB,GAAA,SAAY,GAAA;EACpC,kBAAA,GAAqB,GAAA,SAAY,kBAAA;EACjC,mBAAA,GAAsB,GAAA,SAAY,cAAA;AAAA;AAAA,cAuUzB,qBAAA;;;;;;;;;;;;;mJAzUyC,aAAA;kJAEf,aAAA"}
|