@assistant-ui/ai-sdk 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/adapters/aiSDKFormatAdapter.d.ts +2 -2
- package/dist/adapters/aiSDKFormatAdapter.d.ts.map +1 -0
- package/dist/adapters/vercelAttachmentAdapter.d.ts +1 -3
- package/dist/adapters/vercelAttachmentAdapter.d.ts.map +1 -1
- package/dist/adapters/vercelAttachmentAdapter.js +3 -3
- package/dist/adapters/vercelAttachmentAdapter.js.map +1 -1
- package/dist/aiSDKExtras.d.ts +4 -6
- package/dist/aiSDKExtras.d.ts.map +1 -1
- package/dist/converters/convertMessage.d.ts +32 -24
- package/dist/converters/convertMessage.d.ts.map +1 -1
- package/dist/converters/convertMessage.js +43 -9
- package/dist/converters/convertMessage.js.map +1 -1
- package/dist/converters/modelContentEnvelope.d.ts +6 -7
- package/dist/converters/modelContentEnvelope.d.ts.map +1 -1
- package/dist/converters/toCreateMessage.d.ts +2 -4
- package/dist/converters/toCreateMessage.d.ts.map +1 -1
- package/dist/converters/toolOutputConversion.d.ts +20 -22
- package/dist/converters/toolOutputConversion.d.ts.map +1 -1
- package/dist/hooks.d.ts +2 -4
- package/dist/hooks.d.ts.map +1 -1
- package/dist/index.d.ts +17 -14
- package/dist/index.d.ts.map +1 -0
- package/dist/index.native.d.ts +15 -12
- package/dist/index.native.d.ts.map +1 -0
- package/dist/model-context/injectInteractableContext.d.ts +2 -4
- package/dist/model-context/injectInteractableContext.d.ts.map +1 -1
- package/dist/model-context/injectQuoteContext.d.ts +1 -3
- package/dist/model-context/injectQuoteContext.d.ts.map +1 -1
- package/dist/runtime/AISDKChat.d.ts +2 -4
- package/dist/runtime/AISDKChat.d.ts.map +1 -1
- package/dist/runtime/AISDKChat.js +1 -1
- package/dist/runtime/AISDKThreads.d.ts +29 -31
- package/dist/runtime/AISDKThreads.d.ts.map +1 -1
- package/dist/runtime/AISDKThreads.js +22 -23
- package/dist/runtime/AISDKThreads.js.map +1 -1
- package/dist/runtime/sdkIdentity.d.ts +1 -3
- package/dist/runtime/sdkIdentity.d.ts.map +1 -1
- package/dist/runtime/sdkIdentity.js +1 -1
- package/dist/runtime/useAISDKRuntime.d.ts +69 -70
- package/dist/runtime/useAISDKRuntime.d.ts.map +1 -1
- package/dist/runtime/useAISDKRuntime.js +112 -56
- package/dist/runtime/useAISDKRuntime.js.map +1 -1
- package/dist/runtime/useChatRuntime.d.ts +6 -8
- package/dist/runtime/useChatRuntime.d.ts.map +1 -1
- package/dist/runtime/useChatRuntime.js +14 -10
- package/dist/runtime/useChatRuntime.js.map +1 -1
- package/dist/runtime/useChatThread.d.ts +94 -89
- package/dist/runtime/useChatThread.d.ts.map +1 -1
- package/dist/runtime/useChatThread.js +4 -5
- package/dist/runtime/useChatThread.js.map +1 -1
- package/dist/runtime/useExternalHistory.d.ts +7 -7
- package/dist/runtime/useExternalHistory.d.ts.map +1 -1
- package/dist/runtime/useExternalHistory.js +229 -59
- package/dist/runtime/useExternalHistory.js.map +1 -1
- package/dist/runtime/useResourceCleanup.d.ts +1 -3
- package/dist/runtime/useResourceCleanup.d.ts.map +1 -1
- package/dist/runtime/useResourceCleanup.js +38 -14
- package/dist/runtime/useResourceCleanup.js.map +1 -1
- package/dist/runtime/useStreamingTiming.d.ts +3 -5
- package/dist/runtime/useStreamingTiming.d.ts.map +1 -1
- package/dist/runtime/useStreamingTiming.js +1 -1
- package/dist/tools/frontendTools.d.ts +21 -23
- package/dist/tools/frontendTools.d.ts.map +1 -1
- package/dist/tools/generativeTools.d.ts +24 -26
- package/dist/tools/generativeTools.d.ts.map +1 -1
- package/dist/tools/mcp-stdio.node.d.ts +2 -2
- package/dist/tools/mcp-stdio.node.d.ts.map +1 -0
- package/dist/tools/mcp-stdio.unsupported.d.ts +2 -4
- package/dist/tools/mcp-stdio.unsupported.d.ts.map +1 -1
- package/dist/transport/AssistantChatTransport.d.ts +14 -16
- package/dist/transport/AssistantChatTransport.d.ts.map +1 -1
- package/dist/transport/resumable.d.ts +25 -27
- package/dist/transport/resumable.d.ts.map +1 -1
- package/dist/usage.d.ts +8 -10
- package/dist/usage.d.ts.map +1 -1
- package/dist/usage.js.map +1 -1
- package/dist/utils/getVercelAIMessages.d.ts +2 -4
- package/dist/utils/getVercelAIMessages.d.ts.map +1 -1
- package/dist/utils/sliceMessagesUntil.d.ts +1 -3
- package/dist/utils/sliceMessagesUntil.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/adapters/vercelAttachmentAdapter.test.ts +23 -0
- package/src/adapters/vercelAttachmentAdapter.ts +2 -2
- package/src/converters/convertMessage.test.ts +478 -3
- package/src/converters/convertMessage.ts +100 -14
- package/src/index.native.ts +1 -1
- package/src/index.ts +1 -1
- package/src/runtime/AISDKThreads.cloud.test.ts +60 -2
- package/src/runtime/AISDKThreads.test.ts +79 -46
- package/src/runtime/AISDKThreads.ts +1 -1
- package/src/runtime/useAISDKRuntime.approval.integration.test.tsx +51 -0
- package/src/runtime/useAISDKRuntime.approval.test.tsx +225 -9
- package/src/runtime/useAISDKRuntime.test.ts +275 -5
- package/src/runtime/useAISDKRuntime.ts +141 -37
- package/src/runtime/useAISDKRuntime.voice.test.tsx +50 -1
- package/src/runtime/useChatRuntime.integration.test.tsx +56 -0
- package/src/runtime/useChatRuntime.test.ts +5 -1
- package/src/runtime/useChatRuntime.ts +6 -2
- package/src/runtime/useChatThread.transport.test.tsx +149 -0
- package/src/runtime/useChatThread.ts +33 -5
- package/src/runtime/useExternalHistory.test.ts +943 -3
- package/src/runtime/useExternalHistory.ts +366 -14
- package/src/runtime/useResourceCleanup.ts +41 -15
- package/src/usage.ts +1 -1
package/README.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { aiSDKV6FormatAdapter, type AISDKStorageFormat, } from "assistant-cloud/ai-sdk";
|
|
2
|
+
//# sourceMappingURL=aiSDKFormatAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aiSDKFormatAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/aiSDKFormatAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,KAAK,kBAAkB,GACxB,MAAM,wBAAwB,CAAC"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { AttachmentAdapter } from "@assistant-ui/core";
|
|
2
|
-
//#region src/adapters/vercelAttachmentAdapter.d.ts
|
|
1
|
+
import type { AttachmentAdapter } from "@assistant-ui/core";
|
|
3
2
|
export declare const vercelAttachmentAdapter: AttachmentAdapter;
|
|
4
|
-
//#endregion
|
|
5
3
|
//# sourceMappingURL=vercelAttachmentAdapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vercelAttachmentAdapter.d.ts","
|
|
1
|
+
{"version":3,"file":"vercelAttachmentAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/vercelAttachmentAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAI5D,eAAO,MAAM,uBAAuB,EAAE,iBA+BrC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { generateId } from "ai";
|
|
2
1
|
import { getFileDataURL } from "@assistant-ui/core/internal";
|
|
2
|
+
import { generateId } from "ai";
|
|
3
3
|
//#region src/adapters/vercelAttachmentAdapter.ts
|
|
4
4
|
const vercelAttachmentAdapter = {
|
|
5
5
|
accept: "*",
|
|
@@ -17,7 +17,7 @@ const vercelAttachmentAdapter = {
|
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
},
|
|
20
|
-
async send(attachment) {
|
|
20
|
+
async send(attachment, options) {
|
|
21
21
|
return {
|
|
22
22
|
...attachment,
|
|
23
23
|
status: { type: "complete" },
|
|
@@ -25,7 +25,7 @@ const vercelAttachmentAdapter = {
|
|
|
25
25
|
type: "file",
|
|
26
26
|
mimeType: attachment.contentType ?? "",
|
|
27
27
|
filename: attachment.name,
|
|
28
|
-
data: await getFileDataURL(attachment.file)
|
|
28
|
+
data: await getFileDataURL(attachment.file, options)
|
|
29
29
|
}]
|
|
30
30
|
};
|
|
31
31
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vercelAttachmentAdapter.js","names":["AttachmentAdapter","getFileDataURL","generateId","vercelAttachmentAdapter","accept","add","file","id","type","startsWith","name","contentType","content","status","reason","send","attachment","mimeType","filename","data","remove"],"sources":["../../src/adapters/vercelAttachmentAdapter.ts"],"sourcesContent":["import type { AttachmentAdapter } from \"@assistant-ui/core\";\nimport { getFileDataURL } from \"@assistant-ui/core/internal\";\nimport { generateId } from \"ai\";\n\nexport const vercelAttachmentAdapter: AttachmentAdapter = {\n accept: \"*\",\n async add({ file }) {\n return {\n id: generateId(),\n type: file.type.startsWith(\"image/\") ? \"image\" : \"file\",\n name: file.name,\n file,\n contentType: file.type,\n content: [],\n status: { type: \"requires-action\", reason: \"composer-send\" },\n };\n },\n async send(attachment) {\n // noop\n return {\n ...attachment,\n status: { type: \"complete\" },\n content: [\n {\n type: \"file\",\n mimeType: attachment.contentType ?? \"\",\n filename: attachment.name,\n data: await getFileDataURL(attachment.file),\n },\n ],\n };\n },\n async remove() {\n // noop\n },\n};\n"],"mappings":";;;AAIA,MAAaG,0BAA6C;CACxDC,QAAQ;CACR,MAAMC,IAAI,EAAEC,QAAQ;EAClB,OAAO;GACLC,IAAIL,WAAW;GACfM,MAAMF,KAAKE,KAAKC,WAAW,QAAQ,IAAI,UAAU;GACjDC,MAAMJ,KAAKI;GACXJ;GACAK,aAAaL,KAAKE;GAClBI,SAAS,CAAA;GACTC,QAAQ;IAAEL,MAAM;IAAmBM,QAAQ;GAAgB;EAC7D;CACF;CACA,MAAMC,KAAKC,
|
|
1
|
+
{"version":3,"file":"vercelAttachmentAdapter.js","names":["AttachmentAdapter","getFileDataURL","generateId","vercelAttachmentAdapter","accept","add","file","id","type","startsWith","name","contentType","content","status","reason","send","attachment","options","mimeType","filename","data","remove"],"sources":["../../src/adapters/vercelAttachmentAdapter.ts"],"sourcesContent":["import type { AttachmentAdapter } from \"@assistant-ui/core\";\nimport { getFileDataURL } from \"@assistant-ui/core/internal\";\nimport { generateId } from \"ai\";\n\nexport const vercelAttachmentAdapter: AttachmentAdapter = {\n accept: \"*\",\n async add({ file }) {\n return {\n id: generateId(),\n type: file.type.startsWith(\"image/\") ? \"image\" : \"file\",\n name: file.name,\n file,\n contentType: file.type,\n content: [],\n status: { type: \"requires-action\", reason: \"composer-send\" },\n };\n },\n async send(attachment, options) {\n // noop\n return {\n ...attachment,\n status: { type: \"complete\" },\n content: [\n {\n type: \"file\",\n mimeType: attachment.contentType ?? \"\",\n filename: attachment.name,\n data: await getFileDataURL(attachment.file, options),\n },\n ],\n };\n },\n async remove() {\n // noop\n },\n};\n"],"mappings":";;;AAIA,MAAaG,0BAA6C;CACxDC,QAAQ;CACR,MAAMC,IAAI,EAAEC,QAAQ;EAClB,OAAO;GACLC,IAAIL,WAAW;GACfM,MAAMF,KAAKE,KAAKC,WAAW,QAAQ,IAAI,UAAU;GACjDC,MAAMJ,KAAKI;GACXJ;GACAK,aAAaL,KAAKE;GAClBI,SAAS,CAAA;GACTC,QAAQ;IAAEL,MAAM;IAAmBM,QAAQ;GAAgB;EAC7D;CACF;CACA,MAAMC,KAAKC,YAAYC,SAAS;EAE9B,OAAO;GACL,GAAGD;GACHH,QAAQ,EAAEL,MAAM,WAAW;GAC3BI,SAAS,CACP;IACEJ,MAAM;IACNU,UAAUF,WAAWL,eAAe;IACpCQ,UAAUH,WAAWN;IACrBU,MAAM,MAAMnB,eAAee,WAAWV,MAAMW,OAAO;GACrD,CAAC;EAEL;CACF;CACA,MAAMI,SAAS,CACb;AAEJ"}
|
package/dist/aiSDKExtras.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
//#region src/aiSDKExtras.d.ts
|
|
1
|
+
import type { UseChatHelpers } from "@ai-sdk/react";
|
|
2
|
+
import type { UIMessage } from "ai";
|
|
4
3
|
export type AISDKRuntimeExtras = {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
chat: UseChatHelpers<UIMessage>;
|
|
5
|
+
error: Error | undefined;
|
|
7
6
|
};
|
|
8
7
|
export declare const aiSDKExtras: import("@assistant-ui/core/react").RuntimeExtras<AISDKRuntimeExtras>;
|
|
9
|
-
//#endregion
|
|
10
8
|
//# sourceMappingURL=aiSDKExtras.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiSDKExtras.d.ts","
|
|
1
|
+
{"version":3,"file":"aiSDKExtras.d.ts","sourceRoot":"","sources":["../src/aiSDKExtras.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;IAChC,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,WAAW,sEACoC,CAAC"}
|
|
@@ -1,29 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { McpAppMetadata, RespondToToolApprovalOptions } from "@assistant-ui/core";
|
|
4
|
-
import { ReadonlyJSONObject } from "assistant-stream/utils";
|
|
5
|
-
//#region src/converters/convertMessage.d.ts
|
|
1
|
+
import { type UIMessage } from "ai";
|
|
2
|
+
import { type useExternalMessageConverter } from "@assistant-ui/core/react";
|
|
3
|
+
import { type McpAppMetadata, type RespondToToolApprovalOptions, type Unstable_ToolInteractionLog } from "@assistant-ui/core";
|
|
4
|
+
import { type ReadonlyJSONObject } from "assistant-stream/utils";
|
|
6
5
|
export type AISDKMessageConverterMetadata = useExternalMessageConverter.Metadata & {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
toolArgsKeyOrderCache?: Map<string, Map<string, string[]>>;
|
|
7
|
+
/**
|
|
8
|
+
* Frozen `argsText` keyed weakly by a settled tool call's input object, then
|
|
9
|
+
* by call, since the text carries the call's streamed key order. A known
|
|
10
|
+
* call/input pair skips serialization; the entries become collectible once
|
|
11
|
+
* the input is unreachable. A fresh input object re-serializes in its own
|
|
12
|
+
* deterministic key order.
|
|
13
|
+
*/
|
|
14
|
+
toolArgsTextCache?: WeakMap<ReadonlyJSONObject, Map<string, string>>;
|
|
15
|
+
toolLastInputCache?: Map<string, ReadonlyJSONObject>;
|
|
16
|
+
mcpAppMetadataCache?: Map<string, McpAppMetadata>;
|
|
17
|
+
toolArtifacts?: ReadonlyMap<string, unknown>;
|
|
18
|
+
toolInteractions?: ReadonlyMap<string, Unstable_ToolInteractionLog>;
|
|
19
|
+
supportsRichToolApprovalResponses?: boolean;
|
|
20
|
+
toolApprovalResponses?: ReadonlyMap<string, RespondToToolApprovalOptions>;
|
|
21
|
+
/** Id of the currently-streaming message, flagged optimistic (#4037). */
|
|
22
|
+
optimisticMessageId?: string | undefined;
|
|
14
23
|
};
|
|
15
24
|
export declare const AISDKMessageConverter: {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
useThreadMessages: ({ messages, isRunning, joinStrategy, metadata, }: {
|
|
26
|
+
messages: UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>[];
|
|
27
|
+
isRunning: boolean;
|
|
28
|
+
joinStrategy?: import("@assistant-ui/core/store").JoinStrategy | undefined;
|
|
29
|
+
metadata?: useExternalMessageConverter.Metadata;
|
|
30
|
+
}) => import("@assistant-ui/core").ThreadMessage[];
|
|
31
|
+
toThreadMessages: (messages: UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>[], isRunning?: boolean, metadata?: useExternalMessageConverter.Metadata) => import("@assistant-ui/core").ThreadMessage[];
|
|
32
|
+
toOriginalMessages: (input: import("@assistant-ui/core").ThreadRuntimeState | import("@assistant-ui/core").ThreadMessage | import("@assistant-ui/core").ThreadMessage["content"][number]) => unknown[];
|
|
33
|
+
toOriginalMessage: (input: import("@assistant-ui/core").ThreadRuntimeState | import("@assistant-ui/core").ThreadMessage | import("@assistant-ui/core").ThreadMessage["content"][number]) => {};
|
|
34
|
+
useOriginalMessage: () => {};
|
|
35
|
+
useOriginalMessages: () => unknown[];
|
|
27
36
|
};
|
|
28
|
-
//#endregion
|
|
29
37
|
//# sourceMappingURL=convertMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertMessage.d.ts","
|
|
1
|
+
{"version":3,"file":"convertMessage.d.ts","sourceRoot":"","sources":["../../src/converters/convertMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,IAAI,CAAC;AACZ,OAAO,EAEL,KAAK,2BAA2B,EACjC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAYL,KAAK,cAAc,EAEnB,KAAK,4BAA4B,EACjC,KAAK,2BAA2B,EACjC,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,wBAAwB,CAAC;AA6BhC,MAAM,MAAM,6BAA6B,GACvC,2BAA2B,CAAC,QAAQ,GAAG;IACrC,qBAAqB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAC3D;;;;;;OAMG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACrE,kBAAkB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IACrD,mBAAmB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAClD,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,gBAAgB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;IACpE,iCAAiC,CAAC,EAAE,OAAO,CAAC;IAC5C,qBAAqB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,4BAA4B,CAAC,CAAC;IAC1E,yEAAyE;IACzE,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1C,CAAC;AAkhBJ,eAAO,MAAM,qBAAqB;;;;;;;;+HApkBX,qDACD;8HAE+B,qDAE7C;;;CAioBP,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { unwrapModelContentEnvelope } from "./modelContentEnvelope.js";
|
|
2
|
-
import {
|
|
2
|
+
import { stableStringifyToolArgs } from "@assistant-ui/core/internal";
|
|
3
3
|
import { getToolName, isCustomContentUIPart, isReasoningFileUIPart, isToolUIPart } from "ai";
|
|
4
|
+
import { createMessageConverter } from "@assistant-ui/core/react";
|
|
4
5
|
import { isMcpAppUri } from "@assistant-ui/core";
|
|
5
|
-
import { stableStringifyToolArgs } from "@assistant-ui/core/internal";
|
|
6
6
|
import { parsePartialJsonObject } from "assistant-stream/utils";
|
|
7
7
|
//#region src/converters/convertMessage.ts
|
|
8
8
|
const THREAD_METADATA_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -19,7 +19,7 @@ const THREAD_METADATA_KEYS = /* @__PURE__ */ new Set([
|
|
|
19
19
|
const toThreadMetadata = (metadata) => {
|
|
20
20
|
if (!metadata || typeof metadata !== "object") return void 0;
|
|
21
21
|
const result = {};
|
|
22
|
-
const extra =
|
|
22
|
+
const extra = Object.create(null);
|
|
23
23
|
for (const [key, value] of Object.entries(metadata)) (THREAD_METADATA_KEYS.has(key) ? result : extra)[key] = value;
|
|
24
24
|
if (Object.keys(extra).length > 0) result.custom = {
|
|
25
25
|
...extra,
|
|
@@ -97,16 +97,36 @@ const normalizeToolApprovalOptions = (options) => {
|
|
|
97
97
|
}];
|
|
98
98
|
});
|
|
99
99
|
};
|
|
100
|
+
const APPROVAL_DESCRIPTOR_FIELDS = [
|
|
101
|
+
"prompt",
|
|
102
|
+
"display",
|
|
103
|
+
"allowFreeform",
|
|
104
|
+
"dismissible",
|
|
105
|
+
"options",
|
|
106
|
+
"optionId",
|
|
107
|
+
"text",
|
|
108
|
+
"resolution"
|
|
109
|
+
];
|
|
110
|
+
const readApprovalDescriptor = (descriptor) => {
|
|
111
|
+
if (!descriptor || typeof descriptor !== "object" || Array.isArray(descriptor)) return {};
|
|
112
|
+
const fields = {};
|
|
113
|
+
for (const key of APPROVAL_DESCRIPTOR_FIELDS) if (Object.hasOwn(descriptor, key)) fields[key] = descriptor[key];
|
|
114
|
+
return fields;
|
|
115
|
+
};
|
|
100
116
|
function getToolApprovalAndInterrupt(part, toolStatus, supportsRichToolApprovalResponses, toolApprovalResponses) {
|
|
101
117
|
if (part.approval) {
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
...part.approval
|
|
118
|
+
const approval = {
|
|
119
|
+
...readApprovalDescriptor(part.approval.descriptor),
|
|
120
|
+
...part.approval
|
|
121
|
+
};
|
|
122
|
+
const response = typeof approval.id === "string" && approval.approved === void 0 && approval.resolution !== "cancelled" && approval.resolution !== "expired" ? toolApprovalResponses?.get(approval.id) : void 0;
|
|
123
|
+
const { id, prompt, approved, reason, isAutomatic, resolution, display, allowFreeform, dismissible, options, optionId, text, ...additionalApprovalFields } = response ? {
|
|
124
|
+
...approval,
|
|
105
125
|
approved: response.approved,
|
|
106
126
|
...response.reason != null && { reason: response.reason },
|
|
107
127
|
...response.optionId != null && { optionId: response.optionId },
|
|
108
128
|
...response.text != null && { text: response.text }
|
|
109
|
-
} :
|
|
129
|
+
} : approval;
|
|
110
130
|
const normalizedOptions = supportsRichToolApprovalResponses ? normalizeToolApprovalOptions(options) : void 0;
|
|
111
131
|
const requestReason = additionalApprovalFields.requestReason;
|
|
112
132
|
if (typeof id === "string") return { approval: {
|
|
@@ -119,6 +139,7 @@ function getToolApprovalAndInterrupt(part, toolStatus, supportsRichToolApprovalR
|
|
|
119
139
|
...supportsRichToolApprovalResponses && {
|
|
120
140
|
...(display === "decision" || display === "select" || display === "text") && { display },
|
|
121
141
|
...typeof allowFreeform === "boolean" && { allowFreeform },
|
|
142
|
+
...typeof dismissible === "boolean" && { dismissible },
|
|
122
143
|
...normalizedOptions && { options: normalizedOptions },
|
|
123
144
|
...typeof optionId === "string" && { optionId },
|
|
124
145
|
...typeof text === "string" && { text }
|
|
@@ -158,7 +179,7 @@ function convertParts(message, metadata) {
|
|
|
158
179
|
const toolName = getToolName(part);
|
|
159
180
|
const toolCallId = part.toolCallId;
|
|
160
181
|
const argsKeyOrderCacheKey = `${message.id}:${toolCallId}`;
|
|
161
|
-
const rawInput = part.input;
|
|
182
|
+
const rawInput = part.input ?? ("rawInput" in part ? part.rawInput : void 0);
|
|
162
183
|
let args;
|
|
163
184
|
if (rawInput != null && typeof rawInput === "object" && !Array.isArray(rawInput)) {
|
|
164
185
|
args = rawInput;
|
|
@@ -178,16 +199,26 @@ function convertParts(message, metadata) {
|
|
|
178
199
|
isError = true;
|
|
179
200
|
result = { error: part.approval?.reason || "Tool approval denied" };
|
|
180
201
|
}
|
|
181
|
-
let argsText
|
|
202
|
+
let argsText;
|
|
182
203
|
if (part.state === "input-streaming") {
|
|
204
|
+
argsText = stableStringifyToolArgs(metadata.toolArgsKeyOrderCache, argsKeyOrderCacheKey, args);
|
|
183
205
|
argsText = stripClosingDelimiters(argsText);
|
|
184
206
|
args = parsePartialJsonObject(argsText) ?? args;
|
|
185
207
|
} else {
|
|
208
|
+
const frozen = metadata.toolArgsTextCache?.get(args) ?? /* @__PURE__ */ new Map();
|
|
209
|
+
const frozenText = frozen.get(argsKeyOrderCacheKey);
|
|
210
|
+
if (frozenText !== void 0) argsText = frozenText;
|
|
211
|
+
else {
|
|
212
|
+
argsText = stableStringifyToolArgs(metadata.toolArgsKeyOrderCache, argsKeyOrderCacheKey, args);
|
|
213
|
+
metadata.toolArgsTextCache?.set(args, frozen.set(argsKeyOrderCacheKey, argsText));
|
|
214
|
+
}
|
|
186
215
|
metadata.toolArgsKeyOrderCache?.delete(argsKeyOrderCacheKey);
|
|
187
216
|
if (part.state === "output-available" || part.state === "output-error" || part.state === "output-denied") metadata.toolLastInputCache?.delete(argsKeyOrderCacheKey);
|
|
188
217
|
}
|
|
189
218
|
const toolStatus = metadata.toolStatuses?.[toolCallId];
|
|
190
219
|
const mcpApp = extractMcpAppMetadata(part, metadata.mcpAppMetadataCache);
|
|
220
|
+
const artifact = metadata.toolArtifacts?.get(toolCallId);
|
|
221
|
+
const interactions = metadata.toolInteractions?.get(toolCallId);
|
|
191
222
|
return {
|
|
192
223
|
type: "tool-call",
|
|
193
224
|
toolName,
|
|
@@ -196,6 +227,9 @@ function convertParts(message, metadata) {
|
|
|
196
227
|
args,
|
|
197
228
|
result,
|
|
198
229
|
isError,
|
|
230
|
+
...artifact !== void 0 && { artifact },
|
|
231
|
+
...interactions !== void 0 && { unstable_interactions: interactions },
|
|
232
|
+
...part.state === "output-available" && part.preliminary === true && { isPreliminary: true },
|
|
199
233
|
...modelContent !== void 0 && { modelContent },
|
|
200
234
|
...mcpApp && { mcp: { app: mcpApp } },
|
|
201
235
|
...part.callProviderMetadata != null ? { providerMetadata: part.callProviderMetadata } : void 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertMessage.js","names":["isToolUIPart","isReasoningFileUIPart","isCustomContentUIPart","getToolName","UIMessage","createMessageConverter","unstable_createMessageConverter","useExternalMessageConverter","isMcpAppUri","ReasoningMessagePart","ToolApprovalOption","ToolCallMessagePart","TextMessagePart","DataMessagePart","PartProviderMetadata","SourceMessagePart","SourceProviderMetadata","FileMessagePart","ThreadMessageLike","McpAppMetadata","MessagePartStreamStatus","RespondToToolApprovalOptions","stableStringifyToolArgs","parsePartialJsonObject","ReadonlyJSONObject","unwrapModelContentEnvelope","MessageMetadata","THREAD_METADATA_KEYS","Set","toThreadMetadata","metadata","undefined","result","Record","extra","key","value","Object","entries","has","keys","length","custom","AISDKMessageConverterMetadata","Metadata","toolArgsKeyOrderCache","Map","toolLastInputCache","mcpAppMetadataCache","supportsRichToolApprovalResponses","toolApprovalResponses","ReadonlyMap","optimisticMessageId","stripClosingDelimiters","json","replace","MCP_APP_METADATA_CACHE_MAX","extractMcpAppMetadata","part","cache","meta","callProviderMetadata","mcp","app","a","output","outMeta","_meta","ui","uiMeta","resourceUri","Array","isArray","visibility","flat","cacheKey","cached","get","delete","set","out","K","mimeType","filter","v","serverId","size","oldest","next","normalizeToolApprovalOptions","options","flatMap","option","id","kind","confirm","confirmDetails","label","description","grants","grant","title","getToolApprovalAndInterrupt","approval","toolStatus","type","payload","NonNullable","interrupt","response","approved","resolution","prompt","reason","isAutomatic","display","allowFreeform","optionId","text","additionalApprovalFields","normalizedOptions","requestReason","MessageContent","Exclude","uiPartStateToStatus","state","convertParts","message","parts","converted","p","role","map","status","providerMetadata","toolName","toolCallId","argsKeyOrderCacheKey","rawInput","input","args","modelContent","isError","unwrapped","error","errorText","argsText","toolStatuses","mcpApp","sourceType","sourceId","url","data","mediaType","filename","startsWith","name","substring","console","warn","Boolean","seenToolCallIds","add","AISDKMessageConverter","createdAt","Date","content","attachments","idx","isImage","toString","image","contentType","const","timing","messageTiming","isOptimistic"],"sources":["../../src/converters/convertMessage.ts"],"sourcesContent":["import {\n isToolUIPart,\n isReasoningFileUIPart,\n isCustomContentUIPart,\n getToolName,\n type UIMessage,\n} from \"ai\";\nimport {\n createMessageConverter as unstable_createMessageConverter,\n type useExternalMessageConverter,\n} from \"@assistant-ui/core/react\";\nimport {\n isMcpAppUri,\n type ReasoningMessagePart,\n type ToolApprovalOption,\n type ToolCallMessagePart,\n type TextMessagePart,\n type DataMessagePart,\n type PartProviderMetadata,\n type SourceMessagePart,\n type SourceProviderMetadata,\n type FileMessagePart,\n type ThreadMessageLike,\n type McpAppMetadata,\n type MessagePartStreamStatus,\n type RespondToToolApprovalOptions,\n} from \"@assistant-ui/core\";\nimport { stableStringifyToolArgs } from \"@assistant-ui/core/internal\";\nimport {\n parsePartialJsonObject,\n type ReadonlyJSONObject,\n} from \"assistant-stream/utils\";\nimport { unwrapModelContentEnvelope } from \"./modelContentEnvelope\";\n\ntype MessageMetadata = ThreadMessageLike[\"metadata\"];\n\nconst THREAD_METADATA_KEYS = new Set([\n \"unstable_state\",\n \"unstable_annotations\",\n \"unstable_data\",\n \"steps\",\n \"timing\",\n \"submittedFeedback\",\n \"isOptimistic\",\n \"modality\",\n \"custom\",\n]);\n\nconst toThreadMetadata = (metadata: unknown): MessageMetadata => {\n if (!metadata || typeof metadata !== \"object\") return undefined;\n const result: Record<string, unknown> = {};\n const extra: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(metadata)) {\n (THREAD_METADATA_KEYS.has(key) ? result : extra)[key] = value;\n }\n if (Object.keys(extra).length > 0) {\n result.custom = { ...extra, ...(result.custom as object | undefined) };\n }\n return result as MessageMetadata;\n};\nexport type AISDKMessageConverterMetadata =\n useExternalMessageConverter.Metadata & {\n toolArgsKeyOrderCache?: Map<string, Map<string, string[]>>;\n toolLastInputCache?: Map<string, ReadonlyJSONObject>;\n mcpAppMetadataCache?: Map<string, McpAppMetadata>;\n supportsRichToolApprovalResponses?: boolean;\n toolApprovalResponses?: ReadonlyMap<string, RespondToToolApprovalOptions>;\n /** Id of the currently-streaming message, flagged optimistic (#4037). */\n optimisticMessageId?: string | undefined;\n };\n\nfunction stripClosingDelimiters(json: string): string {\n return json.replace(/[}\\]\"]+$/, \"\");\n}\n\nconst MCP_APP_METADATA_CACHE_MAX = 100;\n\nfunction extractMcpAppMetadata(\n part: unknown,\n cache: Map<string, McpAppMetadata> | undefined,\n): McpAppMetadata | undefined {\n if (!part || typeof part !== \"object\") return undefined;\n const meta = (part as { callProviderMetadata?: unknown })\n .callProviderMetadata;\n const mcp =\n meta && typeof meta === \"object\"\n ? (meta as { mcp?: unknown }).mcp\n : undefined;\n const app =\n mcp && typeof mcp === \"object\" ? (mcp as { app?: unknown }).app : undefined;\n let a: Record<string, unknown>;\n if (app && typeof app === \"object\") {\n a = app as Record<string, unknown>;\n } else {\n // MCP-UI tools surface the pointer on result._meta: canonical nested\n // `ui.resourceUri`, or the deprecated flat `\"ui/resourceUri\"` key.\n const output = (part as { output?: unknown }).output;\n const outMeta =\n output && typeof output === \"object\"\n ? (output as { _meta?: unknown })._meta\n : undefined;\n const ui =\n outMeta && typeof outMeta === \"object\"\n ? (outMeta as Record<string, unknown>)[\"ui\"]\n : undefined;\n if (\n ui &&\n typeof ui === \"object\" &&\n typeof (ui as Record<string, unknown>)[\"resourceUri\"] === \"string\" &&\n isMcpAppUri((ui as Record<string, unknown>)[\"resourceUri\"] as string)\n ) {\n // Only the spec'd ui fields cross from the result body; serverId is a\n // routing key and stays transport-derived via callProviderMetadata.\n const uiMeta = ui as Record<string, unknown>;\n a = {\n resourceUri: uiMeta[\"resourceUri\"],\n ...(Array.isArray(uiMeta[\"visibility\"])\n ? { visibility: uiMeta[\"visibility\"] }\n : {}),\n };\n } else {\n const flat =\n outMeta && typeof outMeta === \"object\"\n ? (outMeta as Record<string, unknown>)[\"ui/resourceUri\"]\n : undefined;\n if (typeof flat !== \"string\" || !isMcpAppUri(flat)) return undefined;\n a = { resourceUri: flat };\n }\n }\n if (typeof a[\"resourceUri\"] !== \"string\") return undefined;\n if (!isMcpAppUri(a[\"resourceUri\"])) return undefined;\n const cacheKey = `${typeof a[\"serverId\"] === \"string\" ? a[\"serverId\"] : \"\"} ${a[\"resourceUri\"]}`;\n const cached = cache?.get(cacheKey);\n if (cached) {\n cache!.delete(cacheKey);\n cache!.set(cacheKey, cached);\n return cached;\n }\n const out: { -readonly [K in keyof McpAppMetadata]: McpAppMetadata[K] } = {\n resourceUri: a[\"resourceUri\"],\n };\n if (typeof a[\"mimeType\"] === \"string\") out.mimeType = a[\"mimeType\"];\n if (Array.isArray(a[\"visibility\"])) {\n out.visibility = a[\"visibility\"].filter(\n (v): v is \"model\" | \"app\" => v === \"model\" || v === \"app\",\n );\n }\n if (typeof a[\"serverId\"] === \"string\" && a[\"serverId\"].length > 0)\n out.serverId = a[\"serverId\"];\n if (cache) {\n if (cache.size >= MCP_APP_METADATA_CACHE_MAX) {\n const oldest = cache.keys().next().value;\n if (oldest !== undefined) cache.delete(oldest);\n }\n cache.set(cacheKey, out);\n }\n return out;\n}\n\nconst normalizeToolApprovalOptions = (\n options: unknown,\n): readonly ToolApprovalOption[] | undefined => {\n if (!Array.isArray(options)) return undefined;\n\n return options.flatMap<ToolApprovalOption>((value) => {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return [];\n const option = value as Record<string, unknown>;\n if (typeof option.id !== \"string\" || typeof option.kind !== \"string\")\n return [];\n\n const confirm = option.confirm;\n const confirmDetails =\n confirm && typeof confirm === \"object\" && !Array.isArray(confirm)\n ? (confirm as Record<string, unknown>)\n : undefined;\n\n return [\n {\n id: option.id,\n kind: option.kind,\n ...(typeof option.label === \"string\" && { label: option.label }),\n ...(typeof option.description === \"string\" && {\n description: option.description,\n }),\n ...(Array.isArray(option.grants) && {\n grants: option.grants.filter(\n (grant): grant is string => typeof grant === \"string\",\n ),\n }),\n ...(typeof confirm === \"boolean\"\n ? { confirm }\n : confirmDetails\n ? {\n confirm: {\n ...(typeof confirmDetails.title === \"string\" && {\n title: confirmDetails.title,\n }),\n ...(typeof confirmDetails.description === \"string\" && {\n description: confirmDetails.description,\n }),\n },\n }\n : {}),\n },\n ];\n });\n};\n\nfunction getToolApprovalAndInterrupt(\n part: {\n approval?: Record<string, unknown> | undefined;\n },\n toolStatus: { type: string; payload?: unknown } | undefined,\n supportsRichToolApprovalResponses: boolean,\n toolApprovalResponses:\n | ReadonlyMap<string, RespondToToolApprovalOptions>\n | undefined,\n): {\n approval?: NonNullable<ToolCallMessagePart[\"approval\"]>;\n interrupt?: NonNullable<ToolCallMessagePart[\"interrupt\"]>;\n} {\n if (part.approval) {\n const response =\n typeof part.approval.id === \"string\" &&\n part.approval.approved === undefined &&\n part.approval.resolution !== \"cancelled\" &&\n part.approval.resolution !== \"expired\"\n ? toolApprovalResponses?.get(part.approval.id)\n : undefined;\n // The built-in AI SDK channel sends only id, approved and reason back to\n // the server, so a request shape promising any other answer would render\n // controls whose response cannot travel.\n const {\n id,\n prompt,\n approved,\n reason,\n isAutomatic,\n resolution,\n display,\n allowFreeform,\n options,\n optionId,\n text,\n ...additionalApprovalFields\n } = response\n ? {\n ...part.approval,\n approved: response.approved,\n ...(response.reason != null && { reason: response.reason }),\n ...(response.optionId != null && { optionId: response.optionId }),\n ...(response.text != null && { text: response.text }),\n }\n : part.approval;\n const normalizedOptions = supportsRichToolApprovalResponses\n ? normalizeToolApprovalOptions(options)\n : undefined;\n const requestReason = additionalApprovalFields.requestReason;\n if (typeof id === \"string\")\n return {\n approval: {\n ...additionalApprovalFields,\n id,\n ...(typeof prompt === \"string\"\n ? { prompt }\n : typeof requestReason === \"string\"\n ? { prompt: requestReason }\n : {}),\n ...(typeof approved === \"boolean\" && { approved }),\n ...(typeof reason === \"string\" && { reason }),\n ...(isAutomatic === true && { isAutomatic: true }),\n ...(supportsRichToolApprovalResponses && {\n ...((display === \"decision\" ||\n display === \"select\" ||\n display === \"text\") && { display }),\n ...(typeof allowFreeform === \"boolean\" && { allowFreeform }),\n ...(normalizedOptions && { options: normalizedOptions }),\n ...(typeof optionId === \"string\" && { optionId }),\n ...(typeof text === \"string\" && { text }),\n }),\n ...((resolution === \"cancelled\" || resolution === \"expired\") && {\n resolution,\n }),\n } as NonNullable<ToolCallMessagePart[\"approval\"]>,\n };\n }\n\n if (toolStatus?.type === \"interrupt\") {\n return {\n interrupt: toolStatus.payload as NonNullable<\n ToolCallMessagePart[\"interrupt\"]\n >,\n };\n }\n\n return {};\n}\n\ntype MessageContent = Exclude<ThreadMessageLike[\"content\"], string>;\n\nconst uiPartStateToStatus = (\n state: \"streaming\" | \"done\" | undefined,\n): MessagePartStreamStatus | undefined => {\n if (state === \"streaming\") return { type: \"running\" };\n if (state === \"done\") return { type: \"complete\" };\n return undefined;\n};\n\nfunction convertParts(\n message: UIMessage,\n metadata: AISDKMessageConverterMetadata,\n): MessageContent {\n if (!message.parts || message.parts.length === 0) {\n return [];\n }\n\n const converted = message.parts\n .filter(\n (p) =>\n p.type !== \"step-start\" &&\n (message.role !== \"user\" || p.type !== \"file\"),\n )\n .map((part) => {\n if (part.type === \"text\") {\n const status = uiPartStateToStatus(part.state);\n return {\n type: \"text\",\n text: part.text,\n ...(status != null ? { status } : undefined),\n ...(part.providerMetadata != null\n ? {\n providerMetadata: part.providerMetadata as PartProviderMetadata,\n }\n : undefined),\n } satisfies TextMessagePart;\n }\n\n if (part.type === \"reasoning\") {\n const status = uiPartStateToStatus(part.state);\n return {\n type: \"reasoning\",\n text: part.text,\n ...(status != null ? { status } : undefined),\n ...(part.providerMetadata != null\n ? {\n providerMetadata: part.providerMetadata as PartProviderMetadata,\n }\n : undefined),\n } satisfies ReasoningMessagePart;\n }\n\n if (isToolUIPart(part)) {\n const toolName = getToolName(part);\n const toolCallId = part.toolCallId;\n const argsKeyOrderCacheKey = `${message.id}:${toolCallId}`;\n\n const rawInput = part.input as ReadonlyJSONObject | null | undefined;\n let args: ReadonlyJSONObject;\n if (\n rawInput != null &&\n typeof rawInput === \"object\" &&\n !Array.isArray(rawInput)\n ) {\n args = rawInput;\n metadata.toolLastInputCache?.set(argsKeyOrderCacheKey, args);\n } else {\n args = metadata.toolLastInputCache?.get(argsKeyOrderCacheKey) ?? {};\n }\n\n let result: unknown;\n let modelContent: ToolCallMessagePart[\"modelContent\"];\n let isError = false;\n\n if (part.state === \"output-available\") {\n const unwrapped = unwrapModelContentEnvelope(part.output);\n result = unwrapped.result;\n modelContent = unwrapped.modelContent;\n } else if (part.state === \"output-error\") {\n isError = true;\n result = { error: part.errorText };\n } else if (part.state === \"output-denied\") {\n isError = true;\n result = {\n error:\n (part as { approval?: { reason?: string } }).approval?.reason ||\n \"Tool approval denied\",\n };\n }\n\n let argsText = stableStringifyToolArgs(\n metadata.toolArgsKeyOrderCache,\n argsKeyOrderCacheKey,\n args,\n );\n if (part.state === \"input-streaming\") {\n // strip closing delimiters added by the AI SDK's fix-json\n argsText = stripClosingDelimiters(argsText);\n // Re-parse so args carries the partial-JSON meta that marks which\n // field is still mid-arrival, like every argsText-based runtime.\n // The key-order cache appends new keys last, so the trailing field\n // of the stripped text is the streaming frontier.\n args = parsePartialJsonObject(argsText) ?? args;\n } else {\n metadata.toolArgsKeyOrderCache?.delete(argsKeyOrderCacheKey);\n if (\n part.state === \"output-available\" ||\n part.state === \"output-error\" ||\n part.state === \"output-denied\"\n ) {\n metadata.toolLastInputCache?.delete(argsKeyOrderCacheKey);\n }\n }\n\n const toolStatus = metadata.toolStatuses?.[toolCallId];\n const mcpApp = extractMcpAppMetadata(\n part,\n metadata.mcpAppMetadataCache,\n );\n return {\n type: \"tool-call\",\n toolName,\n toolCallId,\n argsText,\n args,\n result,\n isError,\n ...(modelContent !== undefined && { modelContent }),\n ...(mcpApp && { mcp: { app: mcpApp } }),\n ...(part.callProviderMetadata != null\n ? {\n providerMetadata:\n part.callProviderMetadata as PartProviderMetadata,\n }\n : undefined),\n ...getToolApprovalAndInterrupt(\n part,\n toolStatus,\n metadata.supportsRichToolApprovalResponses === true,\n metadata.toolApprovalResponses,\n ),\n } satisfies ToolCallMessagePart;\n }\n\n if (part.type === \"source-url\") {\n return {\n type: \"source\",\n sourceType: \"url\",\n id: part.sourceId,\n url: part.url,\n ...(part.title != null ? { title: part.title } : undefined),\n ...(part.providerMetadata != null\n ? {\n providerMetadata:\n part.providerMetadata as SourceProviderMetadata,\n }\n : undefined),\n } satisfies SourceMessagePart;\n }\n\n if (part.type === \"file\") {\n return {\n type: \"file\",\n data: part.url,\n mimeType: part.mediaType,\n ...(part.filename != null && { filename: part.filename }),\n } satisfies FileMessagePart;\n }\n\n if (part.type === \"source-document\") {\n return {\n type: \"source\",\n sourceType: \"document\",\n id: part.sourceId,\n title: part.title,\n mediaType: part.mediaType,\n ...(part.filename != null ? { filename: part.filename } : undefined),\n ...(part.providerMetadata != null\n ? {\n providerMetadata:\n part.providerMetadata as SourceProviderMetadata,\n }\n : undefined),\n } satisfies SourceMessagePart;\n }\n\n if (part.type.startsWith(\"data-\")) {\n return {\n type: \"data\",\n name: part.type.substring(5),\n data: (part as any).data,\n } satisfies DataMessagePart;\n }\n\n if (isReasoningFileUIPart(part)) {\n return {\n type: \"file\",\n data: part.url,\n mimeType: part.mediaType,\n } satisfies FileMessagePart;\n }\n\n if (isCustomContentUIPart(part)) {\n return {\n type: \"data\",\n name: part.kind,\n data: part.providerMetadata ?? null,\n } satisfies DataMessagePart;\n }\n\n console.warn(`Unsupported message part type: ${part.type}`);\n return null;\n })\n .filter(Boolean) as MessageContent[number][];\n\n const seenToolCallIds = new Set<string>();\n return converted.filter((part) => {\n if (part.type === \"tool-call\" && part.toolCallId != null) {\n if (seenToolCallIds.has(part.toolCallId)) return false;\n seenToolCallIds.add(part.toolCallId);\n }\n return true;\n });\n}\n\nexport const AISDKMessageConverter = unstable_createMessageConverter(\n (message: UIMessage, metadata: AISDKMessageConverterMetadata) => {\n const createdAt = new Date();\n const content = convertParts(message, metadata);\n\n switch (message.role) {\n case \"user\":\n return {\n role: \"user\",\n id: message.id,\n createdAt,\n content,\n attachments: message.parts\n ?.filter((p) => p.type === \"file\")\n .map((part, idx) => {\n const mediaType = part.mediaType ?? \"unknown/unknown\";\n const isImage = mediaType.startsWith(\"image/\");\n return {\n id: idx.toString(),\n type: isImage ? \"image\" : \"file\",\n name: part.filename ?? \"file\",\n content: [\n isImage\n ? {\n type: \"image\",\n image: part.url,\n filename: part.filename!,\n }\n : {\n type: \"file\",\n filename: part.filename!,\n data: part.url,\n mimeType: mediaType,\n },\n ],\n contentType: mediaType,\n status: { type: \"complete\" as const },\n };\n }),\n metadata: toThreadMetadata(message.metadata),\n };\n\n case \"system\":\n case \"assistant\": {\n const timing = metadata.messageTiming?.[message.id];\n const isOptimistic =\n message.role === \"assistant\" &&\n message.id === metadata.optimisticMessageId;\n return {\n role: message.role,\n id: message.id,\n createdAt,\n content,\n metadata: {\n ...toThreadMetadata(message.metadata),\n ...(timing && { timing }),\n ...(isOptimistic && { isOptimistic: true }),\n },\n };\n }\n\n default:\n console.warn(`Unsupported message role: ${message.role}`);\n return [];\n }\n },\n);\n"],"mappings":";;;;;;;AAoCA,MAAM2B,uCAAuB,IAAIC,IAAI;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAAQ,CACT;AAED,MAAMC,oBAAoBC,aAAuC;CAC/D,IAAI,CAACA,YAAY,OAAOA,aAAa,UAAU,OAAOC,KAAAA;CACtD,MAAMC,SAAkC,CAAC;CACzC,MAAME,QAAiC,CAAC;CACxC,KAAK,MAAM,CAACC,KAAKC,UAAUC,OAAOC,QAAQR,QAAQ,GAChD,CAACH,qBAAqBY,IAAIJ,GAAG,IAAIH,SAASE,MAAAA,CAAOC,OAAOC;CAE1D,IAAIC,OAAOG,KAAKN,KAAK,CAAC,CAACO,SAAS,GAC9BT,OAAOU,SAAS;EAAE,GAAGR;EAAO,GAAIF,OAAOU;CAA8B;CAEvE,OAAOV;AACT;AAYA,SAASqB,uBAAuBC,MAAsB;CACpD,OAAOA,KAAKC,QAAQ,YAAY,EAAE;AACpC;AAEA,MAAMC,6BAA6B;AAEnC,SAASC,sBACPC,MACAC,OAC4B;CAC5B,IAAI,CAACD,QAAQ,OAAOA,SAAS,UAAU,OAAO3B,KAAAA;CAC9C,MAAM6B,OAAQF,KACXG;CACH,MAAMC,MACJF,QAAQ,OAAOA,SAAS,WACnBA,KAA2BE,M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UE,WAAW,QAAQ;IAC7C,OAAO;KACL9D,IAAI2E,IAAIE,SAAS;KACjBjE,MAAMgE,UAAU,UAAU;KAC1Bb,MAAMlG,KAAKgG,YAAY;KACvBY,SAAS,CACPG,UACI;MACEhE,MAAM;MACNkE,OAAOjH,KAAK6F;MACZG,UAAUhG,KAAKgG;KACjB,IACA;MACEjD,MAAM;MACNiD,UAAUhG,KAAKgG;MACfF,MAAM9F,KAAK6F;MACXrE,UAAUuE;KACZ,CAAC;KAEPmB,aAAanB;KACbpB,QAAQ,EAAE5B,MAAM,WAAoB;IACtC;GACF,CAAC;GACH3E,UAAUD,iBAAiBkG,QAAQjG,QAAQ;EAC7C;EAEF,KAAK;EACL,KAAK,aAAa;GAChB,MAAMgJ,SAAShJ,SAASiJ,gBAAgBhD,QAAQlC;GAChD,MAAMmF,eACJjD,QAAQI,SAAS,eACjBJ,QAAQlC,OAAO/D,SAASsB;GAC1B,OAAO;IACL+E,MAAMJ,QAAQI;IACdtC,IAAIkC,QAAQlC;IACZuE;IACAE;IACAxI,UAAU;KACR,GAAGD,iBAAiBkG,QAAQjG,QAAQ;KACpC,GAAIgJ,UAAU,EAAEA,OAAO;KACvB,GAAIE,gBAAgB,EAAEA,cAAc,KAAK;IAC3C;GACF;EACF;EAEA;GACElB,QAAQC,KAAK,6BAA6BhC,QAAQI,MAAM;GACxD,OAAO,CAAA;CACX;AACF,CACF"}
|
|
1
|
+
{"version":3,"file":"convertMessage.js","names":["isToolUIPart","isReasoningFileUIPart","isCustomContentUIPart","getToolName","UIMessage","createMessageConverter","unstable_createMessageConverter","useExternalMessageConverter","isMcpAppUri","ReasoningMessagePart","ToolApprovalOption","ToolCallMessagePart","TextMessagePart","DataMessagePart","PartProviderMetadata","SourceMessagePart","SourceProviderMetadata","FileMessagePart","ThreadMessageLike","McpAppMetadata","MessagePartStreamStatus","RespondToToolApprovalOptions","Unstable_ToolInteractionLog","stableStringifyToolArgs","parsePartialJsonObject","ReadonlyJSONObject","unwrapModelContentEnvelope","MessageMetadata","THREAD_METADATA_KEYS","Set","toThreadMetadata","metadata","undefined","result","Record","extra","Object","create","key","value","entries","has","keys","length","custom","AISDKMessageConverterMetadata","Metadata","toolArgsKeyOrderCache","Map","toolArgsTextCache","WeakMap","toolLastInputCache","mcpAppMetadataCache","toolArtifacts","ReadonlyMap","toolInteractions","supportsRichToolApprovalResponses","toolApprovalResponses","optimisticMessageId","stripClosingDelimiters","json","replace","MCP_APP_METADATA_CACHE_MAX","extractMcpAppMetadata","part","cache","meta","callProviderMetadata","mcp","app","a","output","outMeta","_meta","ui","uiMeta","resourceUri","Array","isArray","visibility","flat","cacheKey","cached","get","delete","set","out","K","mimeType","filter","v","serverId","size","oldest","next","normalizeToolApprovalOptions","options","flatMap","option","id","kind","confirm","confirmDetails","label","description","grants","grant","title","APPROVAL_DESCRIPTOR_FIELDS","const","readApprovalDescriptor","descriptor","fields","hasOwn","getToolApprovalAndInterrupt","approval","toolStatus","type","payload","NonNullable","interrupt","response","approved","resolution","prompt","reason","isAutomatic","display","allowFreeform","dismissible","optionId","text","additionalApprovalFields","normalizedOptions","requestReason","MessageContent","Exclude","uiPartStateToStatus","state","convertParts","message","parts","converted","p","role","map","status","providerMetadata","toolName","toolCallId","argsKeyOrderCacheKey","rawInput","input","args","modelContent","isError","unwrapped","error","errorText","argsText","frozen","frozenText","toolStatuses","mcpApp","artifact","interactions","unstable_interactions","preliminary","isPreliminary","sourceType","sourceId","url","data","mediaType","filename","startsWith","name","substring","console","warn","Boolean","seenToolCallIds","add","AISDKMessageConverter","createdAt","Date","content","attachments","idx","isImage","toString","image","contentType","timing","messageTiming","isOptimistic"],"sources":["../../src/converters/convertMessage.ts"],"sourcesContent":["import {\n isToolUIPart,\n isReasoningFileUIPart,\n isCustomContentUIPart,\n getToolName,\n type UIMessage,\n} from \"ai\";\nimport {\n createMessageConverter as unstable_createMessageConverter,\n type useExternalMessageConverter,\n} from \"@assistant-ui/core/react\";\nimport {\n isMcpAppUri,\n type ReasoningMessagePart,\n type ToolApprovalOption,\n type ToolCallMessagePart,\n type TextMessagePart,\n type DataMessagePart,\n type PartProviderMetadata,\n type SourceMessagePart,\n type SourceProviderMetadata,\n type FileMessagePart,\n type ThreadMessageLike,\n type McpAppMetadata,\n type MessagePartStreamStatus,\n type RespondToToolApprovalOptions,\n type Unstable_ToolInteractionLog,\n} from \"@assistant-ui/core\";\nimport { stableStringifyToolArgs } from \"@assistant-ui/core/internal\";\nimport {\n parsePartialJsonObject,\n type ReadonlyJSONObject,\n} from \"assistant-stream/utils\";\nimport { unwrapModelContentEnvelope } from \"./modelContentEnvelope\";\n\ntype MessageMetadata = ThreadMessageLike[\"metadata\"];\n\nconst THREAD_METADATA_KEYS = new Set([\n \"unstable_state\",\n \"unstable_annotations\",\n \"unstable_data\",\n \"steps\",\n \"timing\",\n \"submittedFeedback\",\n \"isOptimistic\",\n \"modality\",\n \"custom\",\n]);\n\nconst toThreadMetadata = (metadata: unknown): MessageMetadata => {\n if (!metadata || typeof metadata !== \"object\") return undefined;\n const result: Record<string, unknown> = {};\n const extra = Object.create(null) as Record<string, unknown>;\n for (const [key, value] of Object.entries(metadata)) {\n (THREAD_METADATA_KEYS.has(key) ? result : extra)[key] = value;\n }\n if (Object.keys(extra).length > 0) {\n result.custom = { ...extra, ...(result.custom as object | undefined) };\n }\n return result as MessageMetadata;\n};\nexport type AISDKMessageConverterMetadata =\n useExternalMessageConverter.Metadata & {\n toolArgsKeyOrderCache?: Map<string, Map<string, string[]>>;\n /**\n * Frozen `argsText` keyed weakly by a settled tool call's input object, then\n * by call, since the text carries the call's streamed key order. A known\n * call/input pair skips serialization; the entries become collectible once\n * the input is unreachable. A fresh input object re-serializes in its own\n * deterministic key order.\n */\n toolArgsTextCache?: WeakMap<ReadonlyJSONObject, Map<string, string>>;\n toolLastInputCache?: Map<string, ReadonlyJSONObject>;\n mcpAppMetadataCache?: Map<string, McpAppMetadata>;\n toolArtifacts?: ReadonlyMap<string, unknown>;\n toolInteractions?: ReadonlyMap<string, Unstable_ToolInteractionLog>;\n supportsRichToolApprovalResponses?: boolean;\n toolApprovalResponses?: ReadonlyMap<string, RespondToToolApprovalOptions>;\n /** Id of the currently-streaming message, flagged optimistic (#4037). */\n optimisticMessageId?: string | undefined;\n };\n\nfunction stripClosingDelimiters(json: string): string {\n return json.replace(/[}\\]\"]+$/, \"\");\n}\n\nconst MCP_APP_METADATA_CACHE_MAX = 100;\n\nfunction extractMcpAppMetadata(\n part: unknown,\n cache: Map<string, McpAppMetadata> | undefined,\n): McpAppMetadata | undefined {\n if (!part || typeof part !== \"object\") return undefined;\n const meta = (part as { callProviderMetadata?: unknown })\n .callProviderMetadata;\n const mcp =\n meta && typeof meta === \"object\"\n ? (meta as { mcp?: unknown }).mcp\n : undefined;\n const app =\n mcp && typeof mcp === \"object\" ? (mcp as { app?: unknown }).app : undefined;\n let a: Record<string, unknown>;\n if (app && typeof app === \"object\") {\n a = app as Record<string, unknown>;\n } else {\n // MCP-UI tools surface the pointer on result._meta: canonical nested\n // `ui.resourceUri`, or the deprecated flat `\"ui/resourceUri\"` key.\n const output = (part as { output?: unknown }).output;\n const outMeta =\n output && typeof output === \"object\"\n ? (output as { _meta?: unknown })._meta\n : undefined;\n const ui =\n outMeta && typeof outMeta === \"object\"\n ? (outMeta as Record<string, unknown>)[\"ui\"]\n : undefined;\n if (\n ui &&\n typeof ui === \"object\" &&\n typeof (ui as Record<string, unknown>)[\"resourceUri\"] === \"string\" &&\n isMcpAppUri((ui as Record<string, unknown>)[\"resourceUri\"] as string)\n ) {\n // Only the spec'd ui fields cross from the result body; serverId is a\n // routing key and stays transport-derived via callProviderMetadata.\n const uiMeta = ui as Record<string, unknown>;\n a = {\n resourceUri: uiMeta[\"resourceUri\"],\n ...(Array.isArray(uiMeta[\"visibility\"])\n ? { visibility: uiMeta[\"visibility\"] }\n : {}),\n };\n } else {\n const flat =\n outMeta && typeof outMeta === \"object\"\n ? (outMeta as Record<string, unknown>)[\"ui/resourceUri\"]\n : undefined;\n if (typeof flat !== \"string\" || !isMcpAppUri(flat)) return undefined;\n a = { resourceUri: flat };\n }\n }\n if (typeof a[\"resourceUri\"] !== \"string\") return undefined;\n if (!isMcpAppUri(a[\"resourceUri\"])) return undefined;\n const cacheKey = `${typeof a[\"serverId\"] === \"string\" ? a[\"serverId\"] : \"\"} ${a[\"resourceUri\"]}`;\n const cached = cache?.get(cacheKey);\n if (cached) {\n cache!.delete(cacheKey);\n cache!.set(cacheKey, cached);\n return cached;\n }\n const out: { -readonly [K in keyof McpAppMetadata]: McpAppMetadata[K] } = {\n resourceUri: a[\"resourceUri\"],\n };\n if (typeof a[\"mimeType\"] === \"string\") out.mimeType = a[\"mimeType\"];\n if (Array.isArray(a[\"visibility\"])) {\n out.visibility = a[\"visibility\"].filter(\n (v): v is \"model\" | \"app\" => v === \"model\" || v === \"app\",\n );\n }\n if (typeof a[\"serverId\"] === \"string\" && a[\"serverId\"].length > 0)\n out.serverId = a[\"serverId\"];\n if (cache) {\n if (cache.size >= MCP_APP_METADATA_CACHE_MAX) {\n const oldest = cache.keys().next().value;\n if (oldest !== undefined) cache.delete(oldest);\n }\n cache.set(cacheKey, out);\n }\n return out;\n}\n\nconst normalizeToolApprovalOptions = (\n options: unknown,\n): readonly ToolApprovalOption[] | undefined => {\n if (!Array.isArray(options)) return undefined;\n\n return options.flatMap<ToolApprovalOption>((value) => {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return [];\n const option = value as Record<string, unknown>;\n if (typeof option.id !== \"string\" || typeof option.kind !== \"string\")\n return [];\n\n const confirm = option.confirm;\n const confirmDetails =\n confirm && typeof confirm === \"object\" && !Array.isArray(confirm)\n ? (confirm as Record<string, unknown>)\n : undefined;\n\n return [\n {\n id: option.id,\n kind: option.kind,\n ...(typeof option.label === \"string\" && { label: option.label }),\n ...(typeof option.description === \"string\" && {\n description: option.description,\n }),\n ...(Array.isArray(option.grants) && {\n grants: option.grants.filter(\n (grant): grant is string => typeof grant === \"string\",\n ),\n }),\n ...(typeof confirm === \"boolean\"\n ? { confirm }\n : confirmDetails\n ? {\n confirm: {\n ...(typeof confirmDetails.title === \"string\" && {\n title: confirmDetails.title,\n }),\n ...(typeof confirmDetails.description === \"string\" && {\n description: confirmDetails.description,\n }),\n },\n }\n : {}),\n },\n ];\n });\n};\n\nconst APPROVAL_DESCRIPTOR_FIELDS = [\n \"prompt\",\n \"display\",\n \"allowFreeform\",\n \"dismissible\",\n \"options\",\n \"optionId\",\n \"text\",\n \"resolution\",\n] as const;\n\n// The AI SDK's approval object declares none of the core request and answer\n// fields and `validateUIMessages` strips unknown ones, so a host streams or\n// persists them inside the opaque `approvalDescriptor`. Only those fields are\n// read from it: a descriptor cannot approve its own request.\nconst readApprovalDescriptor = (\n descriptor: unknown,\n): Record<string, unknown> => {\n if (\n !descriptor ||\n typeof descriptor !== \"object\" ||\n Array.isArray(descriptor)\n )\n return {};\n const fields: Record<string, unknown> = {};\n for (const key of APPROVAL_DESCRIPTOR_FIELDS) {\n if (Object.hasOwn(descriptor, key))\n fields[key] = (descriptor as Record<string, unknown>)[key];\n }\n return fields;\n};\n\nfunction getToolApprovalAndInterrupt(\n part: {\n approval?: Record<string, unknown> | undefined;\n },\n toolStatus: { type: string; payload?: unknown } | undefined,\n supportsRichToolApprovalResponses: boolean,\n toolApprovalResponses:\n | ReadonlyMap<string, RespondToToolApprovalOptions>\n | undefined,\n): {\n approval?: NonNullable<ToolCallMessagePart[\"approval\"]>;\n interrupt?: NonNullable<ToolCallMessagePart[\"interrupt\"]>;\n} {\n if (part.approval) {\n const approval = {\n ...readApprovalDescriptor(part.approval.descriptor),\n ...part.approval,\n };\n const response =\n typeof approval.id === \"string\" &&\n approval.approved === undefined &&\n approval.resolution !== \"cancelled\" &&\n approval.resolution !== \"expired\"\n ? toolApprovalResponses?.get(approval.id)\n : undefined;\n // The built-in AI SDK channel sends only id, approved and reason back to\n // the server, so a request shape promising any other answer would render\n // controls whose response cannot travel.\n const {\n id,\n prompt,\n approved,\n reason,\n isAutomatic,\n resolution,\n display,\n allowFreeform,\n dismissible,\n options,\n optionId,\n text,\n ...additionalApprovalFields\n } = response\n ? {\n ...approval,\n approved: response.approved,\n ...(response.reason != null && { reason: response.reason }),\n ...(response.optionId != null && { optionId: response.optionId }),\n ...(response.text != null && { text: response.text }),\n }\n : approval;\n const normalizedOptions = supportsRichToolApprovalResponses\n ? normalizeToolApprovalOptions(options)\n : undefined;\n const requestReason = additionalApprovalFields.requestReason;\n if (typeof id === \"string\")\n return {\n approval: {\n ...additionalApprovalFields,\n id,\n ...(typeof prompt === \"string\"\n ? { prompt }\n : typeof requestReason === \"string\"\n ? { prompt: requestReason }\n : {}),\n ...(typeof approved === \"boolean\" && { approved }),\n ...(typeof reason === \"string\" && { reason }),\n ...(isAutomatic === true && { isAutomatic: true }),\n ...(supportsRichToolApprovalResponses && {\n ...((display === \"decision\" ||\n display === \"select\" ||\n display === \"text\") && { display }),\n ...(typeof allowFreeform === \"boolean\" && { allowFreeform }),\n ...(typeof dismissible === \"boolean\" && { dismissible }),\n ...(normalizedOptions && { options: normalizedOptions }),\n ...(typeof optionId === \"string\" && { optionId }),\n ...(typeof text === \"string\" && { text }),\n }),\n ...((resolution === \"cancelled\" || resolution === \"expired\") && {\n resolution,\n }),\n } as NonNullable<ToolCallMessagePart[\"approval\"]>,\n };\n }\n\n if (toolStatus?.type === \"interrupt\") {\n return {\n interrupt: toolStatus.payload as NonNullable<\n ToolCallMessagePart[\"interrupt\"]\n >,\n };\n }\n\n return {};\n}\n\ntype MessageContent = Exclude<ThreadMessageLike[\"content\"], string>;\n\nconst uiPartStateToStatus = (\n state: \"streaming\" | \"done\" | undefined,\n): MessagePartStreamStatus | undefined => {\n if (state === \"streaming\") return { type: \"running\" };\n if (state === \"done\") return { type: \"complete\" };\n return undefined;\n};\n\nfunction convertParts(\n message: UIMessage,\n metadata: AISDKMessageConverterMetadata,\n): MessageContent {\n if (!message.parts || message.parts.length === 0) {\n return [];\n }\n\n const converted = message.parts\n .filter(\n (p) =>\n p.type !== \"step-start\" &&\n (message.role !== \"user\" || p.type !== \"file\"),\n )\n .map((part) => {\n if (part.type === \"text\") {\n const status = uiPartStateToStatus(part.state);\n return {\n type: \"text\",\n text: part.text,\n ...(status != null ? { status } : undefined),\n ...(part.providerMetadata != null\n ? {\n providerMetadata: part.providerMetadata as PartProviderMetadata,\n }\n : undefined),\n } satisfies TextMessagePart;\n }\n\n if (part.type === \"reasoning\") {\n const status = uiPartStateToStatus(part.state);\n return {\n type: \"reasoning\",\n text: part.text,\n ...(status != null ? { status } : undefined),\n ...(part.providerMetadata != null\n ? {\n providerMetadata: part.providerMetadata as PartProviderMetadata,\n }\n : undefined),\n } satisfies ReasoningMessagePart;\n }\n\n if (isToolUIPart(part)) {\n const toolName = getToolName(part);\n const toolCallId = part.toolCallId;\n const argsKeyOrderCacheKey = `${message.id}:${toolCallId}`;\n\n // A tool call that streamed complete arguments then failed schema\n // validation keeps them in `rawInput`, not `input`; reading `input`\n // alone would convert the error snapshot to `{}` and hide the input.\n const rawInput = (part.input ??\n (\"rawInput\" in part ? part.rawInput : undefined)) as\n | ReadonlyJSONObject\n | null\n | undefined;\n let args: ReadonlyJSONObject;\n if (\n rawInput != null &&\n typeof rawInput === \"object\" &&\n !Array.isArray(rawInput)\n ) {\n args = rawInput;\n metadata.toolLastInputCache?.set(argsKeyOrderCacheKey, args);\n } else {\n args = metadata.toolLastInputCache?.get(argsKeyOrderCacheKey) ?? {};\n }\n\n let result: unknown;\n let modelContent: ToolCallMessagePart[\"modelContent\"];\n let isError = false;\n\n if (part.state === \"output-available\") {\n const unwrapped = unwrapModelContentEnvelope(part.output);\n result = unwrapped.result;\n modelContent = unwrapped.modelContent;\n } else if (part.state === \"output-error\") {\n isError = true;\n result = { error: part.errorText };\n } else if (part.state === \"output-denied\") {\n isError = true;\n result = {\n error:\n (part as { approval?: { reason?: string } }).approval?.reason ||\n \"Tool approval denied\",\n };\n }\n\n let argsText: string;\n if (part.state === \"input-streaming\") {\n argsText = stableStringifyToolArgs(\n metadata.toolArgsKeyOrderCache,\n argsKeyOrderCacheKey,\n args,\n );\n // strip closing delimiters added by the AI SDK's fix-json\n argsText = stripClosingDelimiters(argsText);\n // Re-parse so args carries the partial-JSON meta that marks which\n // field is still mid-arrival, like every argsText-based runtime.\n // The key-order cache appends new keys last, so the trailing field\n // of the stripped text is the streaming frontier.\n args = parsePartialJsonObject(argsText) ?? args;\n } else {\n // A settled part is re-converted whenever its message or the converter\n // metadata changes; the text frozen on its input object skips\n // re-serializing large args while the call keeps that input. Arrival\n // order only matters while args stream, so the key-order entry is\n // released.\n const frozen =\n metadata.toolArgsTextCache?.get(args) ?? new Map<string, string>();\n const frozenText = frozen.get(argsKeyOrderCacheKey);\n if (frozenText !== undefined) {\n argsText = frozenText;\n } else {\n argsText = stableStringifyToolArgs(\n metadata.toolArgsKeyOrderCache,\n argsKeyOrderCacheKey,\n args,\n );\n metadata.toolArgsTextCache?.set(\n args,\n frozen.set(argsKeyOrderCacheKey, argsText),\n );\n }\n metadata.toolArgsKeyOrderCache?.delete(argsKeyOrderCacheKey);\n if (\n part.state === \"output-available\" ||\n part.state === \"output-error\" ||\n part.state === \"output-denied\"\n ) {\n metadata.toolLastInputCache?.delete(argsKeyOrderCacheKey);\n }\n }\n\n const toolStatus = metadata.toolStatuses?.[toolCallId];\n const mcpApp = extractMcpAppMetadata(\n part,\n metadata.mcpAppMetadataCache,\n );\n const artifact = metadata.toolArtifacts?.get(toolCallId);\n const interactions = metadata.toolInteractions?.get(toolCallId);\n return {\n type: \"tool-call\",\n toolName,\n toolCallId,\n argsText,\n args,\n result,\n isError,\n ...(artifact !== undefined && { artifact }),\n ...(interactions !== undefined && {\n unstable_interactions: interactions,\n }),\n ...(part.state === \"output-available\" &&\n part.preliminary === true && { isPreliminary: true }),\n ...(modelContent !== undefined && { modelContent }),\n ...(mcpApp && { mcp: { app: mcpApp } }),\n ...(part.callProviderMetadata != null\n ? {\n providerMetadata:\n part.callProviderMetadata as PartProviderMetadata,\n }\n : undefined),\n ...getToolApprovalAndInterrupt(\n part,\n toolStatus,\n metadata.supportsRichToolApprovalResponses === true,\n metadata.toolApprovalResponses,\n ),\n } satisfies ToolCallMessagePart;\n }\n\n if (part.type === \"source-url\") {\n return {\n type: \"source\",\n sourceType: \"url\",\n id: part.sourceId,\n url: part.url,\n ...(part.title != null ? { title: part.title } : undefined),\n ...(part.providerMetadata != null\n ? {\n providerMetadata:\n part.providerMetadata as SourceProviderMetadata,\n }\n : undefined),\n } satisfies SourceMessagePart;\n }\n\n if (part.type === \"file\") {\n return {\n type: \"file\",\n data: part.url,\n mimeType: part.mediaType,\n ...(part.filename != null && { filename: part.filename }),\n } satisfies FileMessagePart;\n }\n\n if (part.type === \"source-document\") {\n return {\n type: \"source\",\n sourceType: \"document\",\n id: part.sourceId,\n title: part.title,\n mediaType: part.mediaType,\n ...(part.filename != null ? { filename: part.filename } : undefined),\n ...(part.providerMetadata != null\n ? {\n providerMetadata:\n part.providerMetadata as SourceProviderMetadata,\n }\n : undefined),\n } satisfies SourceMessagePart;\n }\n\n if (part.type.startsWith(\"data-\")) {\n return {\n type: \"data\",\n name: part.type.substring(5),\n data: (part as any).data,\n } satisfies DataMessagePart;\n }\n\n if (isReasoningFileUIPart(part)) {\n return {\n type: \"file\",\n data: part.url,\n mimeType: part.mediaType,\n } satisfies FileMessagePart;\n }\n\n if (isCustomContentUIPart(part)) {\n return {\n type: \"data\",\n name: part.kind,\n data: part.providerMetadata ?? null,\n } satisfies DataMessagePart;\n }\n\n console.warn(`Unsupported message part type: ${part.type}`);\n return null;\n })\n .filter(Boolean) as MessageContent[number][];\n\n const seenToolCallIds = new Set<string>();\n return converted.filter((part) => {\n if (part.type === \"tool-call\" && part.toolCallId != null) {\n if (seenToolCallIds.has(part.toolCallId)) return false;\n seenToolCallIds.add(part.toolCallId);\n }\n return true;\n });\n}\n\nexport const AISDKMessageConverter = unstable_createMessageConverter(\n (message: UIMessage, metadata: AISDKMessageConverterMetadata) => {\n const createdAt = new Date();\n const content = convertParts(message, metadata);\n\n switch (message.role) {\n case \"user\":\n return {\n role: \"user\",\n id: message.id,\n createdAt,\n content,\n attachments: message.parts\n ?.filter((p) => p.type === \"file\")\n .map((part, idx) => {\n const mediaType = part.mediaType ?? \"unknown/unknown\";\n const isImage = mediaType.startsWith(\"image/\");\n return {\n id: idx.toString(),\n type: isImage ? \"image\" : \"file\",\n name: part.filename ?? \"file\",\n content: [\n isImage\n ? {\n type: \"image\",\n image: part.url,\n filename: part.filename!,\n }\n : {\n type: \"file\",\n filename: part.filename!,\n data: part.url,\n mimeType: mediaType,\n },\n ],\n contentType: mediaType,\n status: { type: \"complete\" as const },\n };\n }),\n metadata: toThreadMetadata(message.metadata),\n };\n\n case \"system\":\n case \"assistant\": {\n const timing = metadata.messageTiming?.[message.id];\n const isOptimistic =\n message.role === \"assistant\" &&\n message.id === metadata.optimisticMessageId;\n return {\n role: message.role,\n id: message.id,\n createdAt,\n content,\n metadata: {\n ...toThreadMetadata(message.metadata),\n ...(timing && { timing }),\n ...(isOptimistic && { isOptimistic: true }),\n },\n };\n }\n\n default:\n console.warn(`Unsupported message role: ${message.role}`);\n return [];\n }\n },\n);\n"],"mappings":";;;;;;;AAqCA,MAAM4B,uCAAuB,IAAIC,IAAI;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAAQ,CACT;AAED,MAAMC,oBAAoBC,aAAuC;CAC/D,IAAI,CAACA,YAAY,OAAOA,aAAa,UAAU,OAAOC,KAAAA;CACtD,MAAMC,SAAkC,CAAC;CACzC,MAAME,QAAQC,OAAOC,OAAO,IAAI;CAChC,KAAK,MAAM,CAACC,KAAKC,UAAUH,OAAOI,QAAQT,QAAQ,GAChD,CAACH,qBAAqBa,IAAIH,GAAG,IAAIL,SAASE,MAAAA,CAAOG,OAAOC;CAE1D,IAAIH,OAAOM,KAAKP,KAAK,CAAC,CAACQ,SAAS,GAC9BV,OAAOW,SAAS;EAAE,GAAGT;EAAO,GA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,QAAQC,OACjBpD,QAAQsD,MAAMA,EAAE1B,SAAS,MAAM,CAAC,CACjC4B,KAAKjF,MAAM4H,QAAQ;IAClB,MAAMf,YAAY7G,KAAK6G,aAAa;IACpC,MAAMgB,UAAUhB,UAAUE,WAAW,QAAQ;IAC7C,OAAO;KACL5E,IAAIyF,IAAIE,SAAS;KACjBzE,MAAMwE,UAAU,UAAU;KAC1Bb,MAAMhH,KAAK8G,YAAY;KACvBY,SAAS,CACPG,UACI;MACExE,MAAM;MACN0E,OAAO/H,KAAK2G;MACZG,UAAU9G,KAAK8G;KACjB,IACA;MACEzD,MAAM;MACNyD,UAAU9G,KAAK8G;MACfF,MAAM5G,KAAK2G;MACXnF,UAAUqF;KACZ,CAAC;KAEPmB,aAAanB;KACb3B,QAAQ,EAAE7B,MAAM,WAAoB;IACtC;GACF,CAAC;GACHtF,UAAUD,iBAAiB8G,QAAQ7G,QAAQ;EAC7C;EAEF,KAAK;EACL,KAAK,aAAa;GAChB,MAAMkK,SAASlK,SAASmK,gBAAgBtD,QAAQzC;GAChD,MAAMgG,eACJvD,QAAQI,SAAS,eACjBJ,QAAQzC,OAAOpE,SAAS2B;GAC1B,OAAO;IACLsF,MAAMJ,QAAQI;IACd7C,IAAIyC,QAAQzC;IACZqF;IACAE;IACA3J,UAAU;KACR,GAAGD,iBAAiB8G,QAAQ7G,QAAQ;KACpC,GAAIkK,UAAU,EAAEA,OAAO;KACvB,GAAIE,gBAAgB,EAAEA,cAAc,KAAK;IAC3C;GACF;EACF;EAEA;GACEjB,QAAQC,KAAK,6BAA6BvC,QAAQI,MAAM;GACxD,OAAO,CAAA;CACX;AACF,CACF"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { ToolModelContentPart } from "assistant-stream";
|
|
2
|
-
//#region src/converters/modelContentEnvelope.d.ts
|
|
1
|
+
import type { ToolModelContentPart } from "assistant-stream";
|
|
3
2
|
declare const ENVELOPE_KEY = "__aui_modelContent";
|
|
4
3
|
export type ModelContentEnvelope<TResult = unknown> = {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
readonly [ENVELOPE_KEY]: readonly ToolModelContentPart[];
|
|
5
|
+
readonly value: TResult;
|
|
7
6
|
};
|
|
8
7
|
export declare function isModelContentEnvelope<TResult = unknown>(value: TResult | ModelContentEnvelope<TResult>): value is ModelContentEnvelope<TResult>;
|
|
9
8
|
export declare function wrapModelContentEnvelope<TResult>(result: TResult, modelContent: readonly ToolModelContentPart[]): ModelContentEnvelope<TResult>;
|
|
10
9
|
export declare function unwrapModelContentEnvelope<TResult>(output: TResult | ModelContentEnvelope<TResult>): {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
result: TResult;
|
|
11
|
+
modelContent?: readonly ToolModelContentPart[];
|
|
13
12
|
};
|
|
14
|
-
|
|
13
|
+
export {};
|
|
15
14
|
//# sourceMappingURL=modelContentEnvelope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modelContentEnvelope.d.ts","
|
|
1
|
+
{"version":3,"file":"modelContentEnvelope.d.ts","sourceRoot":"","sources":["../../src/converters/modelContentEnvelope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,QAAA,MAAM,YAAY,uBAAuB,CAAC;AAE1C,MAAM,MAAM,oBAAoB,CAAC,OAAO,GAAG,OAAO,IAAI;IACpD,QAAQ,CAAC,CAAC,YAAY,CAAC,EAAE,SAAS,oBAAoB,EAAE,CAAC;IACzD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,OAAO,GAAG,OAAO,EACtD,KAAK,EAAE,OAAO,GAAG,oBAAoB,CAAC,OAAO,CAAC,GAC7C,KAAK,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAOxC;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAC9C,MAAM,EAAE,OAAO,EACf,YAAY,EAAE,SAAS,oBAAoB,EAAE,GAC5C,oBAAoB,CAAC,OAAO,CAAC,CAE/B;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAChD,MAAM,EAAE,OAAO,GAAG,oBAAoB,CAAC,OAAO,CAAC,GAC9C;IACD,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,SAAS,oBAAoB,EAAE,CAAC;CAChD,CAQA"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
//#region src/converters/toCreateMessage.d.ts
|
|
1
|
+
import type { AppendMessage } from "@assistant-ui/core";
|
|
2
|
+
import type { CreateUIMessage, UIMessage } from "ai";
|
|
4
3
|
export declare const toCreateMessage: <UI_MESSAGE extends UIMessage = UIMessage>(message: AppendMessage) => CreateUIMessage<UI_MESSAGE>;
|
|
5
|
-
//#endregion
|
|
6
4
|
//# sourceMappingURL=toCreateMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toCreateMessage.d.ts","
|
|
1
|
+
{"version":3,"file":"toCreateMessage.d.ts","sourceRoot":"","sources":["../../src/converters/toCreateMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAOxD,OAAO,KAAK,EACV,eAAe,EAEf,SAAS,EAGV,MAAM,IAAI,CAAC;AAOZ,eAAO,MAAM,eAAe,GAAI,UAAU,SAAS,SAAS,GAAG,SAAS,EACtE,SAAS,aAAa,KACrB,eAAe,CAAC,UAAU,CA6E5B,CAAC"}
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
import { JSONValue } from "ai";
|
|
2
|
-
import { ToolModelContentPart } from "assistant-stream";
|
|
3
|
-
//#region src/converters/toolOutputConversion.d.ts
|
|
1
|
+
import type { JSONValue } from "ai";
|
|
2
|
+
import type { ToolModelContentPart } from "assistant-stream";
|
|
4
3
|
export declare const toAISDKContent: (parts: readonly ToolModelContentPart[]) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
type: "content";
|
|
5
|
+
value: ({
|
|
6
|
+
type: "text";
|
|
7
|
+
text: string;
|
|
8
|
+
} | {
|
|
9
|
+
filename?: string;
|
|
10
|
+
type: "file";
|
|
11
|
+
data: {
|
|
12
|
+
type: "data";
|
|
13
|
+
data: string;
|
|
14
|
+
};
|
|
15
|
+
mediaType: string;
|
|
16
|
+
text?: never;
|
|
17
|
+
})[];
|
|
19
18
|
};
|
|
20
19
|
export declare const toAISDKDefaultOutput: (output: unknown) => {
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
type: "text";
|
|
21
|
+
value: string;
|
|
23
22
|
} | {
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
type: "json";
|
|
24
|
+
value: JSONValue;
|
|
26
25
|
};
|
|
27
|
-
//#endregion
|
|
28
26
|
//# sourceMappingURL=toolOutputConversion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolOutputConversion.d.ts","
|
|
1
|
+
{"version":3,"file":"toolOutputConversion.d.ts","sourceRoot":"","sources":["../../src/converters/toolOutputConversion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,eAAO,MAAM,cAAc,GAAI,OAAO,SAAS,oBAAoB,EAAE;;;;;;;;;;;;;;;CAiBnE,CAAC;AAEH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,OAAO;;;;;WAGM,SAAS;CAAE,CAAC"}
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
//#region src/hooks.d.ts
|
|
1
|
+
import type { UseChatHelpers } from "@ai-sdk/react";
|
|
2
|
+
import type { UIMessage } from "ai";
|
|
4
3
|
/**
|
|
5
4
|
* Read the last AI SDK chat error object from the runtime extras.
|
|
6
5
|
* `undefined` when there is no error or the current thread is not backed by
|
|
@@ -14,5 +13,4 @@ export declare const useAISDKError: () => Error | undefined;
|
|
|
14
13
|
* SDK runtime.
|
|
15
14
|
*/
|
|
16
15
|
export declare const useAISDKChat: <UI_MESSAGE extends UIMessage = UIMessage>() => UseChatHelpers<UI_MESSAGE> | undefined;
|
|
17
|
-
//#endregion
|
|
18
16
|
//# sourceMappingURL=hooks.d.ts.map
|
package/dist/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAGpC;;;;GAIG;AACH,eAAO,MAAM,aAAa,yBAAmD,CAAC;AAE9E;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,UAAU,SAAS,SAAS,GAAG,SAAS,OAE/D,cAAc,CAAC,UAAU,CAAC,GAC1B,SAAS,CAAC"}
|