@assistant-ui/ai-sdk 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/aiSDKFormatAdapter.d.ts +2 -8
- package/dist/adapters/aiSDKFormatAdapter.js +1 -25
- package/dist/adapters/vercelAttachmentAdapter.d.ts +1 -2
- package/dist/adapters/vercelAttachmentAdapter.d.ts.map +1 -1
- package/dist/aiSDKExtras.d.ts +2 -3
- package/dist/aiSDKExtras.d.ts.map +1 -1
- package/dist/converters/convertMessage.d.ts +5 -4
- package/dist/converters/convertMessage.d.ts.map +1 -1
- package/dist/converters/convertMessage.js +40 -3
- package/dist/converters/convertMessage.js.map +1 -1
- package/dist/converters/modelContentEnvelope.d.ts +4 -5
- package/dist/converters/modelContentEnvelope.d.ts.map +1 -1
- package/dist/converters/toCreateMessage.d.ts +1 -2
- package/dist/converters/toCreateMessage.d.ts.map +1 -1
- package/dist/converters/toolOutputConversion.d.ts +2 -3
- package/dist/converters/toolOutputConversion.d.ts.map +1 -1
- package/dist/hooks.d.ts +2 -3
- package/dist/hooks.d.ts.map +1 -1
- package/dist/model-context/injectInteractableContext.d.ts +1 -2
- package/dist/model-context/injectInteractableContext.d.ts.map +1 -1
- package/dist/model-context/injectQuoteContext.d.ts +1 -2
- package/dist/model-context/injectQuoteContext.d.ts.map +1 -1
- package/dist/runtime/AISDKChat.d.ts +2 -3
- package/dist/runtime/AISDKChat.d.ts.map +1 -1
- package/dist/runtime/AISDKThreads.d.ts +2 -3
- package/dist/runtime/AISDKThreads.d.ts.map +1 -1
- package/dist/runtime/AISDKThreads.js +87 -68
- package/dist/runtime/AISDKThreads.js.map +1 -1
- package/dist/runtime/sdkIdentity.d.ts +5 -0
- package/dist/runtime/sdkIdentity.d.ts.map +1 -0
- package/dist/runtime/sdkIdentity.js +9 -0
- package/dist/runtime/sdkIdentity.js.map +1 -0
- package/dist/runtime/useAISDKRuntime.d.ts +17 -5
- package/dist/runtime/useAISDKRuntime.d.ts.map +1 -1
- package/dist/runtime/useAISDKRuntime.js +103 -38
- package/dist/runtime/useAISDKRuntime.js.map +1 -1
- package/dist/runtime/useChatRuntime.d.ts +2 -3
- package/dist/runtime/useChatRuntime.d.ts.map +1 -1
- package/dist/runtime/useChatRuntime.js +5 -1
- package/dist/runtime/useChatRuntime.js.map +1 -1
- package/dist/runtime/useChatThread.d.ts +19 -5
- package/dist/runtime/useChatThread.d.ts.map +1 -1
- package/dist/runtime/useChatThread.js +31 -10
- package/dist/runtime/useChatThread.js.map +1 -1
- package/dist/runtime/useExternalHistory.d.ts +2 -3
- package/dist/runtime/useExternalHistory.d.ts.map +1 -1
- package/dist/runtime/useExternalHistory.js +31 -20
- package/dist/runtime/useExternalHistory.js.map +1 -1
- package/dist/runtime/useResourceCleanup.d.ts +1 -2
- package/dist/runtime/useResourceCleanup.d.ts.map +1 -1
- package/dist/runtime/useStreamingTiming.d.ts +2 -3
- package/dist/runtime/useStreamingTiming.d.ts.map +1 -1
- package/dist/tools/frontendTools.d.ts +3 -4
- package/dist/tools/frontendTools.d.ts.map +1 -1
- package/dist/tools/generativeTools.d.ts +5 -6
- package/dist/tools/generativeTools.d.ts.map +1 -1
- package/dist/tools/mcp-stdio.unsupported.d.ts +1 -2
- package/dist/tools/mcp-stdio.unsupported.d.ts.map +1 -1
- package/dist/transport/AssistantChatTransport.d.ts +3 -4
- package/dist/transport/AssistantChatTransport.d.ts.map +1 -1
- package/dist/transport/resumable.d.ts +4 -5
- package/dist/transport/resumable.d.ts.map +1 -1
- package/dist/usage.d.ts +4 -5
- package/dist/usage.d.ts.map +1 -1
- package/dist/utils/getVercelAIMessages.d.ts +1 -2
- package/dist/utils/getVercelAIMessages.d.ts.map +1 -1
- package/dist/utils/sliceMessagesUntil.d.ts +1 -2
- package/dist/utils/sliceMessagesUntil.d.ts.map +1 -1
- package/package.json +15 -14
- package/src/adapters/aiSDKFormatAdapter.ts +4 -41
- package/src/converters/convertMessage.test.ts +152 -0
- package/src/converters/convertMessage.ts +95 -5
- package/src/runtime/AISDKChat.test.ts +4 -5
- package/src/runtime/AISDKThreads.cloud.test.ts +12 -3
- package/src/runtime/AISDKThreads.test.ts +140 -13
- package/src/runtime/AISDKThreads.ts +23 -4
- package/src/runtime/sdkIdentity.ts +9 -0
- package/src/runtime/useAISDKRuntime.approval.integration.test.tsx +287 -0
- package/src/runtime/useAISDKRuntime.approval.test.tsx +257 -1
- package/src/runtime/useAISDKRuntime.test.ts +46 -4
- package/src/runtime/useAISDKRuntime.ts +164 -24
- package/src/runtime/useAISDKRuntime.voice.test.tsx +270 -0
- package/src/runtime/useChatRuntime.test.ts +72 -5
- package/src/runtime/useChatRuntime.ts +2 -1
- package/src/runtime/useChatThread.test.ts +74 -0
- package/src/runtime/useChatThread.ts +45 -6
- package/src/runtime/useExternalHistory.test.ts +75 -0
- package/src/runtime/useExternalHistory.ts +28 -11
- package/src/tools/generativeTools.test.ts +7 -1
- package/src/transport/AssistantChatTransport.test.ts +1 -9
- package/dist/adapters/aiSDKFormatAdapter.d.ts.map +0 -1
- package/dist/adapters/aiSDKFormatAdapter.js.map +0 -1
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/adapters/aiSDKFormatAdapter.d.ts
|
|
4
|
-
type AISDKStorageFormat = Omit<UIMessage, "id">;
|
|
5
|
-
declare const aiSDKV6FormatAdapter: MessageFormatAdapter<UIMessage, AISDKStorageFormat>;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { AISDKStorageFormat, aiSDKV6FormatAdapter };
|
|
8
|
-
//# sourceMappingURL=aiSDKFormatAdapter.d.ts.map
|
|
1
|
+
import { AISDKStorageFormat, aiSDKV6FormatAdapter } from "assistant-cloud/ai-sdk";
|
|
2
|
+
export { type AISDKStorageFormat, aiSDKV6FormatAdapter };
|
|
@@ -1,26 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
const aiSDKV6FormatAdapter = {
|
|
3
|
-
format: "ai-sdk/v6",
|
|
4
|
-
encode({ message: { id, parts, ...message } }) {
|
|
5
|
-
return {
|
|
6
|
-
...message,
|
|
7
|
-
parts
|
|
8
|
-
};
|
|
9
|
-
},
|
|
10
|
-
decode(stored) {
|
|
11
|
-
return {
|
|
12
|
-
parentId: stored.parent_id,
|
|
13
|
-
message: {
|
|
14
|
-
id: stored.id,
|
|
15
|
-
...stored.content
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
},
|
|
19
|
-
getId(message) {
|
|
20
|
-
return message.id;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
//#endregion
|
|
1
|
+
import { aiSDKV6FormatAdapter } from "assistant-cloud/ai-sdk";
|
|
24
2
|
export { aiSDKV6FormatAdapter };
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=aiSDKFormatAdapter.js.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AttachmentAdapter } from "@assistant-ui/core";
|
|
2
2
|
//#region src/adapters/vercelAttachmentAdapter.d.ts
|
|
3
|
-
declare const vercelAttachmentAdapter: AttachmentAdapter;
|
|
3
|
+
export declare const vercelAttachmentAdapter: AttachmentAdapter;
|
|
4
4
|
//#endregion
|
|
5
|
-
export { vercelAttachmentAdapter };
|
|
6
5
|
//# sourceMappingURL=vercelAttachmentAdapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vercelAttachmentAdapter.d.ts","names":[],"sources":["../../src/adapters/vercelAttachmentAdapter.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"vercelAttachmentAdapter.d.ts","names":[],"sources":["../../src/adapters/vercelAttachmentAdapter.ts"],"mappings":";;qBAIa,yBAAyB"}
|
package/dist/aiSDKExtras.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { UIMessage } from "ai";
|
|
2
2
|
import { UseChatHelpers } from "@ai-sdk/react";
|
|
3
3
|
//#region src/aiSDKExtras.d.ts
|
|
4
|
-
type AISDKRuntimeExtras = {
|
|
4
|
+
export type AISDKRuntimeExtras = {
|
|
5
5
|
chat: UseChatHelpers<UIMessage>;
|
|
6
6
|
error: Error | undefined;
|
|
7
7
|
};
|
|
8
|
-
declare const aiSDKExtras: import("@assistant-ui/core/react").RuntimeExtras<AISDKRuntimeExtras>;
|
|
8
|
+
export declare const aiSDKExtras: import("@assistant-ui/core/react").RuntimeExtras<AISDKRuntimeExtras>;
|
|
9
9
|
//#endregion
|
|
10
|
-
export { AISDKRuntimeExtras, aiSDKExtras };
|
|
11
10
|
//# sourceMappingURL=aiSDKExtras.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiSDKExtras.d.ts","names":[],"sources":["../src/aiSDKExtras.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"aiSDKExtras.d.ts","names":[],"sources":["../src/aiSDKExtras.ts"],"mappings":";;;YAIY;EACV,MAAM,eAAe;EACrB,OAAO;;qBAGI,gDAAW,cAAA"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { useExternalMessageConverter } from "@assistant-ui/core/react";
|
|
2
2
|
import { UIMessage } from "ai";
|
|
3
|
-
import { McpAppMetadata } from "@assistant-ui/core";
|
|
3
|
+
import { McpAppMetadata, RespondToToolApprovalOptions } from "@assistant-ui/core";
|
|
4
4
|
import { ReadonlyJSONObject } from "assistant-stream/utils";
|
|
5
5
|
//#region src/converters/convertMessage.d.ts
|
|
6
|
-
type AISDKMessageConverterMetadata = useExternalMessageConverter.Metadata & {
|
|
6
|
+
export type AISDKMessageConverterMetadata = useExternalMessageConverter.Metadata & {
|
|
7
7
|
toolArgsKeyOrderCache?: Map<string, Map<string, string[]>>;
|
|
8
8
|
toolLastInputCache?: Map<string, ReadonlyJSONObject>;
|
|
9
9
|
mcpAppMetadataCache?: Map<string, McpAppMetadata>;
|
|
10
|
+
supportsRichToolApprovalResponses?: boolean;
|
|
11
|
+
toolApprovalResponses?: ReadonlyMap<string, RespondToToolApprovalOptions>;
|
|
10
12
|
/** Id of the currently-streaming message, flagged optimistic (#4037). */
|
|
11
13
|
optimisticMessageId?: string | undefined;
|
|
12
14
|
};
|
|
13
|
-
declare const AISDKMessageConverter: {
|
|
15
|
+
export declare const AISDKMessageConverter: {
|
|
14
16
|
useThreadMessages: ({ messages, isRunning, joinStrategy, metadata }: {
|
|
15
17
|
messages: UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>[];
|
|
16
18
|
isRunning: boolean;
|
|
@@ -24,5 +26,4 @@ declare const AISDKMessageConverter: {
|
|
|
24
26
|
useOriginalMessages: () => unknown[];
|
|
25
27
|
};
|
|
26
28
|
//#endregion
|
|
27
|
-
export { AISDKMessageConverter, AISDKMessageConverterMetadata };
|
|
28
29
|
//# sourceMappingURL=convertMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertMessage.d.ts","names":[],"sources":["../../src/converters/convertMessage.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"convertMessage.d.ts","names":[],"sources":["../../src/converters/convertMessage.ts"],"mappings":";;;;;YA4DY,gCACV,4BAA4B;EAC1B,wBAAwB,YAAY;EACpC,qBAAqB,YAAY;EACjC,sBAAsB,YAAY;EAClC;EACA,wBAAwB,oBAAoB;;EAE5C;;qBAwcS;;;;;;;;EA5egC,qBAAA,oCAAA,2CAAA,6CAAA;EAIlB,oBAAA,oCAAA,2CAAA,6CAAA"}
|
|
@@ -13,6 +13,7 @@ const THREAD_METADATA_KEYS = /* @__PURE__ */ new Set([
|
|
|
13
13
|
"timing",
|
|
14
14
|
"submittedFeedback",
|
|
15
15
|
"isOptimistic",
|
|
16
|
+
"modality",
|
|
16
17
|
"custom"
|
|
17
18
|
]);
|
|
18
19
|
const toThreadMetadata = (metadata) => {
|
|
@@ -75,9 +76,38 @@ function extractMcpAppMetadata(part, cache) {
|
|
|
75
76
|
}
|
|
76
77
|
return out;
|
|
77
78
|
}
|
|
78
|
-
|
|
79
|
+
const normalizeToolApprovalOptions = (options) => {
|
|
80
|
+
if (!Array.isArray(options)) return void 0;
|
|
81
|
+
return options.flatMap((value) => {
|
|
82
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return [];
|
|
83
|
+
const option = value;
|
|
84
|
+
if (typeof option.id !== "string" || typeof option.kind !== "string") return [];
|
|
85
|
+
const confirm = option.confirm;
|
|
86
|
+
const confirmDetails = confirm && typeof confirm === "object" && !Array.isArray(confirm) ? confirm : void 0;
|
|
87
|
+
return [{
|
|
88
|
+
id: option.id,
|
|
89
|
+
kind: option.kind,
|
|
90
|
+
...typeof option.label === "string" && { label: option.label },
|
|
91
|
+
...typeof option.description === "string" && { description: option.description },
|
|
92
|
+
...Array.isArray(option.grants) && { grants: option.grants.filter((grant) => typeof grant === "string") },
|
|
93
|
+
...typeof confirm === "boolean" ? { confirm } : confirmDetails ? { confirm: {
|
|
94
|
+
...typeof confirmDetails.title === "string" && { title: confirmDetails.title },
|
|
95
|
+
...typeof confirmDetails.description === "string" && { description: confirmDetails.description }
|
|
96
|
+
} } : {}
|
|
97
|
+
}];
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
function getToolApprovalAndInterrupt(part, toolStatus, supportsRichToolApprovalResponses, toolApprovalResponses) {
|
|
79
101
|
if (part.approval) {
|
|
80
|
-
const
|
|
102
|
+
const response = typeof part.approval.id === "string" && part.approval.approved === void 0 && part.approval.resolution !== "cancelled" && part.approval.resolution !== "expired" ? toolApprovalResponses?.get(part.approval.id) : void 0;
|
|
103
|
+
const { id, prompt, approved, reason, isAutomatic, resolution, display, allowFreeform, options, optionId, text, ...additionalApprovalFields } = response ? {
|
|
104
|
+
...part.approval,
|
|
105
|
+
approved: response.approved,
|
|
106
|
+
...response.reason != null && { reason: response.reason },
|
|
107
|
+
...response.optionId != null && { optionId: response.optionId },
|
|
108
|
+
...response.text != null && { text: response.text }
|
|
109
|
+
} : part.approval;
|
|
110
|
+
const normalizedOptions = supportsRichToolApprovalResponses ? normalizeToolApprovalOptions(options) : void 0;
|
|
81
111
|
const requestReason = additionalApprovalFields.requestReason;
|
|
82
112
|
if (typeof id === "string") return { approval: {
|
|
83
113
|
...additionalApprovalFields,
|
|
@@ -86,6 +116,13 @@ function getToolApprovalAndInterrupt(part, toolStatus) {
|
|
|
86
116
|
...typeof approved === "boolean" && { approved },
|
|
87
117
|
...typeof reason === "string" && { reason },
|
|
88
118
|
...isAutomatic === true && { isAutomatic: true },
|
|
119
|
+
...supportsRichToolApprovalResponses && {
|
|
120
|
+
...(display === "decision" || display === "select" || display === "text") && { display },
|
|
121
|
+
...typeof allowFreeform === "boolean" && { allowFreeform },
|
|
122
|
+
...normalizedOptions && { options: normalizedOptions },
|
|
123
|
+
...typeof optionId === "string" && { optionId },
|
|
124
|
+
...typeof text === "string" && { text }
|
|
125
|
+
},
|
|
89
126
|
...(resolution === "cancelled" || resolution === "expired") && { resolution }
|
|
90
127
|
} };
|
|
91
128
|
}
|
|
@@ -162,7 +199,7 @@ function convertParts(message, metadata) {
|
|
|
162
199
|
...modelContent !== void 0 && { modelContent },
|
|
163
200
|
...mcpApp && { mcp: { app: mcpApp } },
|
|
164
201
|
...part.callProviderMetadata != null ? { providerMetadata: part.callProviderMetadata } : void 0,
|
|
165
|
-
...getToolApprovalAndInterrupt(part, toolStatus)
|
|
202
|
+
...getToolApprovalAndInterrupt(part, toolStatus, metadata.supportsRichToolApprovalResponses === true, metadata.toolApprovalResponses)
|
|
166
203
|
};
|
|
167
204
|
}
|
|
168
205
|
if (part.type === "source-url") return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertMessage.js","names":["isToolUIPart","isReasoningFileUIPart","isCustomContentUIPart","getToolName","UIMessage","createMessageConverter","unstable_createMessageConverter","useExternalMessageConverter","isMcpAppUri","ReasoningMessagePart","ToolCallMessagePart","TextMessagePart","DataMessagePart","PartProviderMetadata","SourceMessagePart","SourceProviderMetadata","FileMessagePart","ThreadMessageLike","McpAppMetadata","MessagePartStreamStatus","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","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","getToolApprovalAndInterrupt","approval","toolStatus","type","payload","NonNullable","interrupt","id","prompt","approved","reason","isAutomatic","resolution","display","allowFreeform","options","optionId","text","additionalApprovalFields","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","title","data","mediaType","filename","startsWith","name","substring","kind","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 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} 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 \"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 /** 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\nfunction getToolApprovalAndInterrupt(\n part: {\n approval?: Record<string, unknown> | undefined;\n },\n toolStatus: { type: string; payload?: unknown } | undefined,\n): {\n approval?: NonNullable<ToolCallMessagePart[\"approval\"]>;\n interrupt?: NonNullable<ToolCallMessagePart[\"interrupt\"]>;\n} {\n if (part.approval) {\n // The AI SDK sends only id, approved and reason back to the server, so a\n // request shape promising any other answer would render controls whose\n // 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 } = part.approval;\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 ...((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(part, toolStatus),\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 [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aAAa1C,QAAQC,OACjBhC,QAAQkC,MAAMA,EAAEzB,SAAS,MAAM,CAAC,CACjC2B,KAAK7D,MAAMmG,QAAQ;IAClB,MAAMhB,YAAYnF,KAAKmF,aAAa;IACpC,MAAMiB,UAAUjB,UAAUE,WAAW,QAAQ;IAC7C,OAAO;KACL/C,IAAI6D,IAAIE,SAAS;KACjBnE,MAAMkE,UAAU,UAAU;KAC1Bd,MAAMtF,KAAKoF,YAAY;KACvBa,SAAS,CACPG,UACI;MACElE,MAAM;MACNoE,OAAOtG,KAAKgF;MACZI,UAAUpF,KAAKoF;KACjB,IACA;MACElD,MAAM;MACNkD,UAAUpF,KAAKoF;MACfF,MAAMlF,KAAKgF;MACXxD,UAAU2D;KACZ,CAAC;KAEPoB,aAAapB;KACbrB,QAAQ,EAAE5B,MAAM,WAAoB;IACtC;GACF,CAAC;GACH3D,UAAUD,iBAAiBkF,QAAQjF,QAAQ;EAC7C;EAEF,KAAK;EACL,KAAK,aAAa;GAChB,MAAMkI,SAASlI,SAASmI,gBAAgBlD,QAAQlB;GAChD,MAAMqE,eACJnD,QAAQI,SAAS,eACjBJ,QAAQlB,OAAO/D,SAASmB;GAC1B,OAAO;IACLkE,MAAMJ,QAAQI;IACdtB,IAAIkB,QAAQlB;IACZyD;IACAE;IACA1H,UAAU;KACR,GAAGD,iBAAiBkF,QAAQjF,QAAQ;KACpC,GAAIkI,UAAU,EAAEA,OAAO;KACvB,GAAIE,gBAAgB,EAAEA,cAAc,KAAK;IAC3C;GACF;EACF;EAEA;GACElB,QAAQC,KAAK,6BAA6BlC,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","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,MAC5B/B,KAAAA;CACN,MAAMgC,M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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,16 +1,15 @@
|
|
|
1
1
|
import { ToolModelContentPart } from "assistant-stream";
|
|
2
2
|
//#region src/converters/modelContentEnvelope.d.ts
|
|
3
3
|
declare const ENVELOPE_KEY = "__aui_modelContent";
|
|
4
|
-
type ModelContentEnvelope<TResult = unknown> = {
|
|
4
|
+
export type ModelContentEnvelope<TResult = unknown> = {
|
|
5
5
|
readonly [ENVELOPE_KEY]: readonly ToolModelContentPart[];
|
|
6
6
|
readonly value: TResult;
|
|
7
7
|
};
|
|
8
|
-
declare function isModelContentEnvelope<TResult = unknown>(value: TResult | ModelContentEnvelope<TResult>): value is ModelContentEnvelope<TResult>;
|
|
9
|
-
declare function wrapModelContentEnvelope<TResult>(result: TResult, modelContent: readonly ToolModelContentPart[]): ModelContentEnvelope<TResult>;
|
|
10
|
-
declare function unwrapModelContentEnvelope<TResult>(output: TResult | ModelContentEnvelope<TResult>): {
|
|
8
|
+
export declare function isModelContentEnvelope<TResult = unknown>(value: TResult | ModelContentEnvelope<TResult>): value is ModelContentEnvelope<TResult>;
|
|
9
|
+
export declare function wrapModelContentEnvelope<TResult>(result: TResult, modelContent: readonly ToolModelContentPart[]): ModelContentEnvelope<TResult>;
|
|
10
|
+
export declare function unwrapModelContentEnvelope<TResult>(output: TResult | ModelContentEnvelope<TResult>): {
|
|
11
11
|
result: TResult;
|
|
12
12
|
modelContent?: readonly ToolModelContentPart[];
|
|
13
13
|
};
|
|
14
14
|
//#endregion
|
|
15
|
-
export { ModelContentEnvelope, isModelContentEnvelope, unwrapModelContentEnvelope, wrapModelContentEnvelope };
|
|
16
15
|
//# sourceMappingURL=modelContentEnvelope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modelContentEnvelope.d.ts","names":[],"sources":["../../src/converters/modelContentEnvelope.ts"],"mappings":";;cAEM;
|
|
1
|
+
{"version":3,"file":"modelContentEnvelope.d.ts","names":[],"sources":["../../src/converters/modelContentEnvelope.ts"],"mappings":";;cAEM;YAEM,qBAAqB;YACrB,wBAAwB;WACzB,OAAO;;wBAGF,uBAAuB,mBACrC,OAAO,UAAU,qBAAqB,WACrC,SAAS,qBAAqB;wBASjB,yBAAyB,SACvC,QAAQ,SACR,uBAAuB,yBACtB,qBAAqB;wBAIR,2BAA2B,SACzC,QAAQ,UAAU,qBAAqB;EAEvC,QAAQ;EACR,wBAAwB"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { CreateUIMessage, UIMessage } from "ai";
|
|
2
2
|
import { AppendMessage } from "@assistant-ui/core";
|
|
3
3
|
//#region src/converters/toCreateMessage.d.ts
|
|
4
|
-
declare const toCreateMessage: <UI_MESSAGE extends UIMessage = UIMessage>(message: AppendMessage) => CreateUIMessage<UI_MESSAGE>;
|
|
4
|
+
export declare const toCreateMessage: <UI_MESSAGE extends UIMessage = UIMessage>(message: AppendMessage) => CreateUIMessage<UI_MESSAGE>;
|
|
5
5
|
//#endregion
|
|
6
|
-
export { toCreateMessage };
|
|
7
6
|
//# sourceMappingURL=toCreateMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toCreateMessage.d.ts","names":[],"sources":["../../src/converters/toCreateMessage.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"toCreateMessage.d.ts","names":[],"sources":["../../src/converters/toCreateMessage.ts"],"mappings":";;;qBAoBa,kBAAmB,mBAAmB,YAAY,WAC7D,SAAS,kBACR,gBAAgB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JSONValue } from "ai";
|
|
2
2
|
import { ToolModelContentPart } from "assistant-stream";
|
|
3
3
|
//#region src/converters/toolOutputConversion.d.ts
|
|
4
|
-
declare const toAISDKContent: (parts: readonly ToolModelContentPart[]) => {
|
|
4
|
+
export declare const toAISDKContent: (parts: readonly ToolModelContentPart[]) => {
|
|
5
5
|
type: "content";
|
|
6
6
|
value: ({
|
|
7
7
|
type: "text";
|
|
@@ -17,7 +17,7 @@ declare const toAISDKContent: (parts: readonly ToolModelContentPart[]) => {
|
|
|
17
17
|
text?: never;
|
|
18
18
|
})[];
|
|
19
19
|
};
|
|
20
|
-
declare const toAISDKDefaultOutput: (output: unknown) => {
|
|
20
|
+
export declare const toAISDKDefaultOutput: (output: unknown) => {
|
|
21
21
|
type: "text";
|
|
22
22
|
value: string;
|
|
23
23
|
} | {
|
|
@@ -25,5 +25,4 @@ declare const toAISDKDefaultOutput: (output: unknown) => {
|
|
|
25
25
|
value: JSONValue;
|
|
26
26
|
};
|
|
27
27
|
//#endregion
|
|
28
|
-
export { toAISDKContent, toAISDKDefaultOutput };
|
|
29
28
|
//# sourceMappingURL=toolOutputConversion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolOutputConversion.d.ts","names":[],"sources":["../../src/converters/toolOutputConversion.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"toolOutputConversion.d.ts","names":[],"sources":["../../src/converters/toolOutputConversion.ts"],"mappings":";;;qBAGa,iBAAkB,gBAAgB;;;;;;;;;;;;;;;;qBAmBlC,uBAAwB;;;;;EAGqB,OAAA"}
|
package/dist/hooks.d.ts
CHANGED
|
@@ -6,14 +6,13 @@ import { UseChatHelpers } from "@ai-sdk/react";
|
|
|
6
6
|
* `undefined` when there is no error or the current thread is not backed by
|
|
7
7
|
* the AI SDK runtime.
|
|
8
8
|
*/
|
|
9
|
-
declare const useAISDKError: () => Error | undefined;
|
|
9
|
+
export declare const useAISDKError: () => Error | undefined;
|
|
10
10
|
/**
|
|
11
11
|
* The underlying `useChat` helpers object, for advanced views — reach
|
|
12
12
|
* `resumeStream`, `clearError`, or the raw `sendMessage` without forking the
|
|
13
13
|
* runtime hook. `undefined` when the current thread is not backed by the AI
|
|
14
14
|
* SDK runtime.
|
|
15
15
|
*/
|
|
16
|
-
declare const useAISDKChat: <UI_MESSAGE extends UIMessage = UIMessage>() => UseChatHelpers<UI_MESSAGE> | undefined;
|
|
16
|
+
export declare const useAISDKChat: <UI_MESSAGE extends UIMessage = UIMessage>() => UseChatHelpers<UI_MESSAGE> | undefined;
|
|
17
17
|
//#endregion
|
|
18
|
-
export { useAISDKChat, useAISDKError };
|
|
19
18
|
//# sourceMappingURL=hooks.d.ts.map
|
package/dist/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","names":[],"sources":["../src/hooks.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","names":[],"sources":["../src/hooks.ts"],"mappings":";;;;;;;;qBAWa,qBAAa;;;;;;;qBAQb,eAAgB,mBAAmB,YAAY,gBAEtD,eAAe"}
|
|
@@ -31,7 +31,6 @@ import { Unstable_InteractableSnapshotEntry } from "@assistant-ui/core";
|
|
|
31
31
|
* }
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
|
-
declare function unstable_injectInteractableContext(messages: UIMessage[], format?: (item: Unstable_InteractableSnapshotEntry) => string): UIMessage[];
|
|
34
|
+
export declare function unstable_injectInteractableContext(messages: UIMessage[], format?: (item: Unstable_InteractableSnapshotEntry) => string): UIMessage[];
|
|
35
35
|
//#endregion
|
|
36
|
-
export { unstable_injectInteractableContext };
|
|
37
36
|
//# sourceMappingURL=injectInteractableContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectInteractableContext.d.ts","names":[],"sources":["../../src/model-context/injectInteractableContext.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"injectInteractableContext.d.ts","names":[],"sources":["../../src/model-context/injectInteractableContext.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqCgB,mCACd,UAAU,aACV,UACE,MAAM,gDAEP"}
|
|
@@ -21,7 +21,6 @@ import { UIMessage } from "ai";
|
|
|
21
21
|
* }
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
declare function injectQuoteContext(messages: UIMessage[]): UIMessage[];
|
|
24
|
+
export declare function injectQuoteContext(messages: UIMessage[]): UIMessage[];
|
|
25
25
|
//#endregion
|
|
26
|
-
export { injectQuoteContext };
|
|
27
26
|
//# sourceMappingURL=injectQuoteContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectQuoteContext.d.ts","names":[],"sources":["../../src/model-context/injectQuoteContext.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"injectQuoteContext.d.ts","names":[],"sources":["../../src/model-context/injectQuoteContext.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;wBAoCgB,mBAAmB,UAAU,cAAc"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ChatThreadOptions } from "./useChatThread.js";
|
|
2
2
|
import { UIMessage } from "@ai-sdk/react";
|
|
3
3
|
//#region src/runtime/AISDKChat.d.ts
|
|
4
|
-
type AISDKChatOptions<UI_MESSAGE extends UIMessage = UIMessage> = ChatThreadOptions<UI_MESSAGE>;
|
|
4
|
+
export type AISDKChatOptions<UI_MESSAGE extends UIMessage = UIMessage> = ChatThreadOptions<UI_MESSAGE>;
|
|
5
5
|
/**
|
|
6
6
|
* `AuiConfig` entry that runs the AI SDK chat as the `threads` scope. Hosts the
|
|
7
7
|
* same orchestration as `useChatRuntime` inside the client's own resource tree,
|
|
@@ -10,7 +10,6 @@ type AISDKChatOptions<UI_MESSAGE extends UIMessage = UIMessage> = ChatThreadOpti
|
|
|
10
10
|
* id is captured when the entry mounts, so a later `id` change in the options
|
|
11
11
|
* has no effect.
|
|
12
12
|
*/
|
|
13
|
-
declare const AISDKChat: <UI_MESSAGE extends UIMessage = UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>>(options?: AISDKChatOptions<UI_MESSAGE> | undefined) => import("@assistant-ui/tap").ResourceElement<import("@assistant-ui/store").ClientOutput<"threads">>;
|
|
13
|
+
export declare const AISDKChat: <UI_MESSAGE extends UIMessage = UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>>(options?: AISDKChatOptions<UI_MESSAGE> | undefined) => import("@assistant-ui/tap").ResourceElement<import("@assistant-ui/store").ClientOutput<"threads">>;
|
|
14
14
|
//#endregion
|
|
15
|
-
export { AISDKChat, AISDKChatOptions };
|
|
16
15
|
//# sourceMappingURL=AISDKChat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AISDKChat.d.ts","names":[],"sources":["../../src/runtime/AISDKChat.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"AISDKChat.d.ts","names":[],"sources":["../../src/runtime/AISDKChat.ts"],"mappings":";;;YAaY,iBAAiB,mBAAmB,YAAY,aAC1D,kBAAkB;;;;;;;;;qBA8BP,YA5BS,mBAAmB,YAAS,gCAAA,0BAAA,UAAA,UAAA,iBAAA,wDAAA,8CAAA"}
|
|
@@ -3,7 +3,7 @@ import { ChatTransport } from "ai";
|
|
|
3
3
|
import { UIMessage as UIMessage$1 } from "@ai-sdk/react";
|
|
4
4
|
import { AssistantCloud } from "assistant-cloud";
|
|
5
5
|
//#region src/runtime/AISDKThreads.d.ts
|
|
6
|
-
type AISDKThreadsOptions<UI_MESSAGE extends UIMessage$1 = UIMessage$1> = Omit<ChatThreadOptions<UI_MESSAGE>, "id" | "transport" | "messages"> & {
|
|
6
|
+
export type AISDKThreadsOptions<UI_MESSAGE extends UIMessage$1 = UIMessage$1> = Omit<ChatThreadOptions<UI_MESSAGE>, "id" | "transport" | "messages"> & {
|
|
7
7
|
/**
|
|
8
8
|
* The transport threads send through. A factory is invoked once per
|
|
9
9
|
* thread so each thread owns its instance. A plain
|
|
@@ -41,7 +41,6 @@ type AISDKThreadsOptions<UI_MESSAGE extends UIMessage$1 = UIMessage$1> = Omit<Ch
|
|
|
41
41
|
* delete, and a freshly created thread titles itself. Model context is
|
|
42
42
|
* registered on every mounted thread.
|
|
43
43
|
*/
|
|
44
|
-
declare const AISDKThreads: <UI_MESSAGE extends UIMessage$1 = UIMessage$1<unknown, import("ai").UIDataTypes, import("ai").UITools>>(options?: AISDKThreadsOptions<UI_MESSAGE> | undefined) => import("@assistant-ui/tap").ResourceElement<import("@assistant-ui/store").ClientOutput<"threads">>;
|
|
44
|
+
export declare const AISDKThreads: <UI_MESSAGE extends UIMessage$1 = UIMessage$1<unknown, import("ai").UIDataTypes, import("ai").UITools>>(options?: AISDKThreadsOptions<UI_MESSAGE> | undefined) => import("@assistant-ui/tap").ResourceElement<import("@assistant-ui/store").ClientOutput<"threads">>;
|
|
45
45
|
//#endregion
|
|
46
|
-
export { AISDKThreads, AISDKThreadsOptions };
|
|
47
46
|
//# sourceMappingURL=AISDKThreads.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AISDKThreads.d.ts","names":[],"sources":["../../src/runtime/AISDKThreads.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"AISDKThreads.d.ts","names":[],"sources":["../../src/runtime/AISDKThreads.ts"],"mappings":";;;;;YA+BY,oBAAoB,mBAAmB,cAAY,eAC7D,KAAK,kBAAkB;;;;;;;;EAQrB,YACI,cAAc,qBACP,cAAc;;;;;;;EAQzB,QAAQ;;;;EAIR;;;;EAIA,qBAAqB;;;;;;;;;;;;;;;qBA4LZ,eAjEY,mBAAmB,cAAS,kCAAA,0BAAA,UAAA,UAAA,oBAAA,wDAAA,8CAAA"}
|