@assistant-ui/ai-sdk 0.0.7 → 0.0.9
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/LICENSE +1 -1
- 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 +34 -24
- package/dist/converters/convertMessage.d.ts.map +1 -1
- package/dist/converters/convertMessage.js +56 -12
- 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/AISDKChat.js.map +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 +76 -70
- package/dist/runtime/useAISDKRuntime.d.ts.map +1 -1
- package/dist/runtime/useAISDKRuntime.js +311 -77
- 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 +44 -15
- 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 +231 -60
- 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/AssistantChatTransport.js +9 -2
- package/dist/transport/AssistantChatTransport.js.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 +13 -9
- package/src/adapters/vercelAttachmentAdapter.test.ts +23 -0
- package/src/adapters/vercelAttachmentAdapter.ts +2 -2
- package/src/converters/convertMessage.test.ts +541 -3
- package/src/converters/convertMessage.ts +123 -15
- package/src/index.native.ts +1 -1
- package/src/index.ts +1 -1
- package/src/runtime/AISDKChat.ts +0 -4
- package/src/runtime/AISDKThreads.cloud.test.ts +60 -2
- package/src/runtime/AISDKThreads.test.ts +105 -46
- package/src/runtime/AISDKThreads.ts +1 -1
- package/src/runtime/useAISDKRuntime.approval.integration.test.tsx +1639 -19
- package/src/runtime/useAISDKRuntime.approval.test.tsx +252 -9
- package/src/runtime/useAISDKRuntime.fast-refresh.test.tsx +182 -0
- package/src/runtime/useAISDKRuntime.test.ts +275 -5
- package/src/runtime/useAISDKRuntime.ts +533 -60
- package/src/runtime/useAISDKRuntime.voice.test.tsx +50 -1
- package/src/runtime/useChatRuntime.fast-refresh.test.tsx +94 -0
- package/src/runtime/useChatRuntime.integration.test.tsx +143 -65
- package/src/runtime/useChatRuntime.test.ts +11 -7
- package/src/runtime/useChatRuntime.ts +6 -2
- package/src/runtime/useChatThread.test.ts +166 -2
- package/src/runtime/useChatThread.transport.test.tsx +152 -0
- package/src/runtime/useChatThread.ts +89 -22
- package/src/runtime/useExternalHistory.test.ts +943 -3
- package/src/runtime/useExternalHistory.ts +378 -15
- package/src/runtime/useResourceCleanup.ts +41 -15
- package/src/transport/AssistantChatTransport.test.ts +164 -0
- package/src/transport/AssistantChatTransport.ts +22 -2
- package/src/usage.ts +1 -1
package/LICENSE
CHANGED
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,39 @@
|
|
|
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
|
+
cancelledToolApprovalIds?: ReadonlySet<string>;
|
|
22
|
+
cancelledStatusMessageIds?: ReadonlySet<string>;
|
|
23
|
+
/** Id of the currently-streaming message, flagged optimistic (#4037). */
|
|
24
|
+
optimisticMessageId?: string | undefined;
|
|
14
25
|
};
|
|
15
26
|
export declare const AISDKMessageConverter: {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
useThreadMessages: ({ messages, isRunning, joinStrategy, metadata, }: {
|
|
28
|
+
messages: UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>[];
|
|
29
|
+
isRunning: boolean;
|
|
30
|
+
joinStrategy?: import("@assistant-ui/core/store").JoinStrategy | undefined;
|
|
31
|
+
metadata?: useExternalMessageConverter.Metadata;
|
|
32
|
+
}) => import("@assistant-ui/core").ThreadMessage[];
|
|
33
|
+
toThreadMessages: (messages: UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>[], isRunning?: boolean, metadata?: useExternalMessageConverter.Metadata) => import("@assistant-ui/core").ThreadMessage[];
|
|
34
|
+
toOriginalMessages: (input: import("@assistant-ui/core").ThreadRuntimeState | import("@assistant-ui/core").ThreadMessage | import("@assistant-ui/core").ThreadMessage["content"][number]) => unknown[];
|
|
35
|
+
toOriginalMessage: (input: import("@assistant-ui/core").ThreadRuntimeState | import("@assistant-ui/core").ThreadMessage | import("@assistant-ui/core").ThreadMessage["content"][number]) => {};
|
|
36
|
+
useOriginalMessage: () => {};
|
|
37
|
+
useOriginalMessages: () => unknown[];
|
|
27
38
|
};
|
|
28
|
-
//#endregion
|
|
29
39
|
//# 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,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ant-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,
|
|
@@ -28,7 +28,9 @@ const toThreadMetadata = (metadata) => {
|
|
|
28
28
|
return result;
|
|
29
29
|
};
|
|
30
30
|
function stripClosingDelimiters(json) {
|
|
31
|
-
|
|
31
|
+
let end = json.length;
|
|
32
|
+
while (end > 0 && "}]\"".includes(json[end - 1])) end--;
|
|
33
|
+
return json.slice(0, end);
|
|
32
34
|
}
|
|
33
35
|
const MCP_APP_METADATA_CACHE_MAX = 100;
|
|
34
36
|
function extractMcpAppMetadata(part, cache) {
|
|
@@ -97,16 +99,40 @@ const normalizeToolApprovalOptions = (options) => {
|
|
|
97
99
|
}];
|
|
98
100
|
});
|
|
99
101
|
};
|
|
100
|
-
|
|
102
|
+
const APPROVAL_DESCRIPTOR_FIELDS = [
|
|
103
|
+
"prompt",
|
|
104
|
+
"display",
|
|
105
|
+
"allowFreeform",
|
|
106
|
+
"dismissible",
|
|
107
|
+
"options",
|
|
108
|
+
"optionId",
|
|
109
|
+
"text",
|
|
110
|
+
"resolution"
|
|
111
|
+
];
|
|
112
|
+
const readApprovalDescriptor = (descriptor) => {
|
|
113
|
+
if (!descriptor || typeof descriptor !== "object" || Array.isArray(descriptor)) return {};
|
|
114
|
+
const fields = {};
|
|
115
|
+
for (const key of APPROVAL_DESCRIPTOR_FIELDS) if (Object.hasOwn(descriptor, key)) fields[key] = descriptor[key];
|
|
116
|
+
return fields;
|
|
117
|
+
};
|
|
118
|
+
function getToolApprovalAndInterrupt(part, toolStatus, supportsRichToolApprovalResponses, toolApprovalResponses, cancelledToolApprovalIds) {
|
|
101
119
|
if (part.approval) {
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
...part.approval
|
|
120
|
+
const rawApproval = {
|
|
121
|
+
...readApprovalDescriptor(part.approval.descriptor),
|
|
122
|
+
...part.approval
|
|
123
|
+
};
|
|
124
|
+
const approval = typeof rawApproval.id === "string" && rawApproval.approved === void 0 && rawApproval.resolution === void 0 && cancelledToolApprovalIds?.has(rawApproval.id) ? {
|
|
125
|
+
...rawApproval,
|
|
126
|
+
resolution: "cancelled"
|
|
127
|
+
} : rawApproval;
|
|
128
|
+
const response = typeof approval.id === "string" && approval.approved === void 0 && approval.resolution !== "cancelled" && approval.resolution !== "expired" ? toolApprovalResponses?.get(approval.id) : void 0;
|
|
129
|
+
const { id, prompt, approved, reason, isAutomatic, resolution, display, allowFreeform, dismissible, options, optionId, text, ...additionalApprovalFields } = response ? {
|
|
130
|
+
...approval,
|
|
105
131
|
approved: response.approved,
|
|
106
132
|
...response.reason != null && { reason: response.reason },
|
|
107
133
|
...response.optionId != null && { optionId: response.optionId },
|
|
108
134
|
...response.text != null && { text: response.text }
|
|
109
|
-
} :
|
|
135
|
+
} : approval;
|
|
110
136
|
const normalizedOptions = supportsRichToolApprovalResponses ? normalizeToolApprovalOptions(options) : void 0;
|
|
111
137
|
const requestReason = additionalApprovalFields.requestReason;
|
|
112
138
|
if (typeof id === "string") return { approval: {
|
|
@@ -119,6 +145,7 @@ function getToolApprovalAndInterrupt(part, toolStatus, supportsRichToolApprovalR
|
|
|
119
145
|
...supportsRichToolApprovalResponses && {
|
|
120
146
|
...(display === "decision" || display === "select" || display === "text") && { display },
|
|
121
147
|
...typeof allowFreeform === "boolean" && { allowFreeform },
|
|
148
|
+
...typeof dismissible === "boolean" && { dismissible },
|
|
122
149
|
...normalizedOptions && { options: normalizedOptions },
|
|
123
150
|
...typeof optionId === "string" && { optionId },
|
|
124
151
|
...typeof text === "string" && { text }
|
|
@@ -158,7 +185,7 @@ function convertParts(message, metadata) {
|
|
|
158
185
|
const toolName = getToolName(part);
|
|
159
186
|
const toolCallId = part.toolCallId;
|
|
160
187
|
const argsKeyOrderCacheKey = `${message.id}:${toolCallId}`;
|
|
161
|
-
const rawInput = part.input;
|
|
188
|
+
const rawInput = part.input ?? ("rawInput" in part ? part.rawInput : void 0);
|
|
162
189
|
let args;
|
|
163
190
|
if (rawInput != null && typeof rawInput === "object" && !Array.isArray(rawInput)) {
|
|
164
191
|
args = rawInput;
|
|
@@ -178,16 +205,26 @@ function convertParts(message, metadata) {
|
|
|
178
205
|
isError = true;
|
|
179
206
|
result = { error: part.approval?.reason || "Tool approval denied" };
|
|
180
207
|
}
|
|
181
|
-
let argsText
|
|
208
|
+
let argsText;
|
|
182
209
|
if (part.state === "input-streaming") {
|
|
210
|
+
argsText = stableStringifyToolArgs(metadata.toolArgsKeyOrderCache, argsKeyOrderCacheKey, args);
|
|
183
211
|
argsText = stripClosingDelimiters(argsText);
|
|
184
212
|
args = parsePartialJsonObject(argsText) ?? args;
|
|
185
213
|
} else {
|
|
214
|
+
const frozen = metadata.toolArgsTextCache?.get(args) ?? /* @__PURE__ */ new Map();
|
|
215
|
+
const frozenText = frozen.get(argsKeyOrderCacheKey);
|
|
216
|
+
if (frozenText !== void 0) argsText = frozenText;
|
|
217
|
+
else {
|
|
218
|
+
argsText = stableStringifyToolArgs(metadata.toolArgsKeyOrderCache, argsKeyOrderCacheKey, args);
|
|
219
|
+
metadata.toolArgsTextCache?.set(args, frozen.set(argsKeyOrderCacheKey, argsText));
|
|
220
|
+
}
|
|
186
221
|
metadata.toolArgsKeyOrderCache?.delete(argsKeyOrderCacheKey);
|
|
187
222
|
if (part.state === "output-available" || part.state === "output-error" || part.state === "output-denied") metadata.toolLastInputCache?.delete(argsKeyOrderCacheKey);
|
|
188
223
|
}
|
|
189
224
|
const toolStatus = metadata.toolStatuses?.[toolCallId];
|
|
190
225
|
const mcpApp = extractMcpAppMetadata(part, metadata.mcpAppMetadataCache);
|
|
226
|
+
const artifact = metadata.toolArtifacts?.get(toolCallId);
|
|
227
|
+
const interactions = metadata.toolInteractions?.get(toolCallId);
|
|
191
228
|
return {
|
|
192
229
|
type: "tool-call",
|
|
193
230
|
toolName,
|
|
@@ -196,10 +233,13 @@ function convertParts(message, metadata) {
|
|
|
196
233
|
args,
|
|
197
234
|
result,
|
|
198
235
|
isError,
|
|
236
|
+
...artifact !== void 0 && { artifact },
|
|
237
|
+
...interactions !== void 0 && { unstable_interactions: interactions },
|
|
238
|
+
...part.state === "output-available" && part.preliminary === true && { isPreliminary: true },
|
|
199
239
|
...modelContent !== void 0 && { modelContent },
|
|
200
240
|
...mcpApp && { mcp: { app: mcpApp } },
|
|
201
241
|
...part.callProviderMetadata != null ? { providerMetadata: part.callProviderMetadata } : void 0,
|
|
202
|
-
...getToolApprovalAndInterrupt(part, toolStatus, metadata.supportsRichToolApprovalResponses === true, metadata.toolApprovalResponses)
|
|
242
|
+
...getToolApprovalAndInterrupt(part, toolStatus, metadata.supportsRichToolApprovalResponses === true, metadata.toolApprovalResponses, metadata.cancelledToolApprovalIds)
|
|
203
243
|
};
|
|
204
244
|
}
|
|
205
245
|
if (part.type === "source-url") return {
|
|
@@ -293,6 +333,10 @@ const AISDKMessageConverter = createMessageConverter((message, metadata) => {
|
|
|
293
333
|
id: message.id,
|
|
294
334
|
createdAt,
|
|
295
335
|
content,
|
|
336
|
+
...message.role === "assistant" && metadata.cancelledStatusMessageIds?.has(message.id) ? { status: {
|
|
337
|
+
type: "incomplete",
|
|
338
|
+
reason: "cancelled"
|
|
339
|
+
} } : void 0,
|
|
296
340
|
metadata: {
|
|
297
341
|
...toThreadMetadata(message.metadata),
|
|
298
342
|
...timing && { timing },
|
|
@@ -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,O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ACxD,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","cancelledToolApprovalIds","ReadonlySet","cancelledStatusMessageIds","optimisticMessageId","stripClosingDelimiters","json","end","includes","slice","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","rawApproval","approved","resolution","response","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 cancelledToolApprovalIds?: ReadonlySet<string>;\n cancelledStatusMessageIds?: ReadonlySet<string>;\n /** Id of the currently-streaming message, flagged optimistic (#4037). */\n optimisticMessageId?: string | undefined;\n };\n\nfunction stripClosingDelimiters(json: string): string {\n let end = json.length;\n while (end > 0 && '}]\"'.includes(json[end - 1]!)) end--;\n return json.slice(0, end);\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 cancelledToolApprovalIds: ReadonlySet<string> | undefined,\n): {\n approval?: NonNullable<ToolCallMessagePart[\"approval\"]>;\n interrupt?: NonNullable<ToolCallMessagePart[\"interrupt\"]>;\n} {\n if (part.approval) {\n const rawApproval = {\n ...readApprovalDescriptor(part.approval.descriptor),\n ...part.approval,\n };\n const approval =\n typeof rawApproval.id === \"string\" &&\n rawApproval.approved === undefined &&\n rawApproval.resolution === undefined &&\n cancelledToolApprovalIds?.has(rawApproval.id)\n ? { ...rawApproval, resolution: \"cancelled\" as const }\n : rawApproval;\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 metadata.cancelledToolApprovalIds,\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 ...(message.role === \"assistant\" &&\n metadata.cancelledStatusMessageIds?.has(message.id)\n ? {\n status: {\n type: \"incomplete\" as const,\n reason: \"cancelled\" as const,\n },\n }\n : undefined),\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,GAAIF,OAAOW;CAA8B;CAEvE,OAAOX;AACT;AAwBA,SAAS6B,uBAAuBC,MAAsB;CACpD,IAAIC,MAAMD,KAAKpB;CACf,OAAOqB,MAAM,KAAK,OAAMC,SAASF,KAAKC,MAAM,EAAG,GAAGA;CAClD,OAAOD,KAAKG,MAAM,GAAGF,GAAG;AAC1B;AAEA,MAAMG,6BAA6B;AAEnC,SAASC,sBACPC,MACAC,OAC4B;CAC5B,IAAI,CAACD,QAAQ,OAAOA,SAAS,UAAU,OAAOrC,KAAAA;CAC9C,MAAMuC,OAAQF,KACX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/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"}
|