@assistant-ui/react-ai-sdk 0.10.14 → 0.10.15
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ui/utils/convertMessage.ts"],"sourcesContent":["import { Message } from \"@ai-sdk/ui-utils\";\nimport {\n unstable_createMessageConverter,\n type
|
|
1
|
+
{"version":3,"sources":["../../../src/ui/utils/convertMessage.ts"],"sourcesContent":["import { Message } from \"@ai-sdk/ui-utils\";\nimport {\n unstable_createMessageConverter,\n type ReasoningMessagePart,\n type ToolCallMessagePart,\n type TextMessagePart,\n type CompleteAttachment,\n type SourceMessagePart,\n type FileMessagePart,\n} from \"@assistant-ui/react\";\n\nconst convertParts = (message: Message) => {\n if (message.parts && message.parts.length > 0) {\n return message.parts\n .filter((p) => p.type !== \"step-start\")\n .map((part) => {\n const type = part.type;\n switch (type) {\n case \"text\":\n return {\n type: \"text\",\n text: part.text,\n } satisfies TextMessagePart;\n case \"tool-invocation\":\n return {\n type: \"tool-call\",\n toolName: part.toolInvocation.toolName,\n toolCallId: part.toolInvocation.toolCallId,\n argsText: JSON.stringify(part.toolInvocation.args),\n args: part.toolInvocation.args,\n result:\n part.toolInvocation.state === \"result\" &&\n part.toolInvocation.result,\n } satisfies ToolCallMessagePart;\n case \"reasoning\":\n return {\n type: \"reasoning\",\n text: part.reasoning,\n } satisfies ReasoningMessagePart;\n case \"source\":\n return {\n type: \"source\",\n ...part.source,\n } satisfies SourceMessagePart;\n case \"file\":\n return {\n type: \"file\",\n data: part.data,\n mimeType: part.mimeType,\n } satisfies FileMessagePart;\n default: {\n const _unsupported: never = type;\n throw new Error(\n `You have a message with an unsupported part type. The type ${_unsupported} is not supported.`,\n );\n }\n }\n });\n }\n\n return message.content\n ? [\n {\n type: \"text\",\n text: message.content,\n } satisfies TextMessagePart,\n ]\n : [];\n};\n\nexport const AISDKMessageConverter = unstable_createMessageConverter(\n (message: Message) => {\n switch (message.role) {\n case \"user\":\n return {\n role: \"user\",\n id: message.id,\n createdAt: message.createdAt,\n content: convertParts(message),\n attachments: message.experimental_attachments?.map(\n (attachment, idx) =>\n ({\n id: idx.toString(),\n type: \"file\",\n name: attachment.name ?? attachment.url,\n content: [],\n contentType: attachment.contentType ?? \"unknown/unknown\",\n status: { type: \"complete\" },\n }) satisfies CompleteAttachment,\n ),\n };\n\n case \"system\":\n return {\n role: \"system\",\n id: message.id,\n createdAt: message.createdAt,\n content: convertParts(message),\n };\n\n case \"assistant\":\n return {\n role: \"assistant\",\n id: message.id,\n createdAt: message.createdAt,\n content: convertParts(message),\n metadata: {\n unstable_annotations: message.annotations,\n unstable_data: Array.isArray(message.data)\n ? message.data\n : message.data\n ? [message.data]\n : undefined,\n },\n };\n\n case \"data\": {\n type MaybeSupportedDataMessage =\n | { type?: \"unsafe_other\" }\n | ToolCallMessagePart\n | {\n type: \"tool-result\";\n toolCallId: string;\n result: any;\n };\n\n if (\n !message.data ||\n !(typeof message.data === \"object\") ||\n Array.isArray(message.data)\n )\n return [];\n\n const data = message.data as MaybeSupportedDataMessage;\n\n if (data.type === \"tool-call\") {\n return {\n role: \"assistant\",\n id: message.id,\n createdAt: message.createdAt,\n content: [data],\n };\n } else if (data.type === \"tool-result\") {\n return {\n role: \"tool\",\n id: message.id,\n toolCallId: data.toolCallId,\n result: data.result,\n };\n }\n return [];\n }\n\n default:\n const _unsupported: \"function\" | \"tool\" = message.role;\n throw new Error(\n `You have a message with an unsupported role. The role ${_unsupported} is not supported.`,\n );\n }\n },\n);\n"],"mappings":";AACA;AAAA,EACE;AAAA,OAOK;AAEP,IAAM,eAAe,CAAC,YAAqB;AACzC,MAAI,QAAQ,SAAS,QAAQ,MAAM,SAAS,GAAG;AAC7C,WAAO,QAAQ,MACZ,OAAO,CAAC,MAAM,EAAE,SAAS,YAAY,EACrC,IAAI,CAAC,SAAS;AACb,YAAM,OAAO,KAAK;AAClB,cAAQ,MAAM;AA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((m) => m.id === messageId);
|
|
5
5
|
if (messageIdx === -1)
|
|
6
6
|
throw new Error(
|
|
7
|
-
"useVercelAIThreadState: Message not found. This is
|
|
7
|
+
"useVercelAIThreadState: Message not found. This is likely an internal bug in assistant-ui."
|
|
8
8
|
);
|
|
9
9
|
while (messages[messageIdx + 1]?.role === "assistant") {
|
|
10
10
|
messageIdx++;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ui/utils/sliceMessagesUntil.tsx"],"sourcesContent":["import type { Message } from \"@ai-sdk/ui-utils\";\n\nexport const sliceMessagesUntil = (\n messages: Message[],\n messageId: string | null,\n) => {\n if (messageId == null) return [];\n\n let messageIdx = messages.findIndex((m) => m.id === messageId);\n if (messageIdx === -1)\n throw new Error(\n \"useVercelAIThreadState: Message not found. This is
|
|
1
|
+
{"version":3,"sources":["../../../src/ui/utils/sliceMessagesUntil.tsx"],"sourcesContent":["import type { Message } from \"@ai-sdk/ui-utils\";\n\nexport const sliceMessagesUntil = (\n messages: Message[],\n messageId: string | null,\n) => {\n if (messageId == null) return [];\n\n let messageIdx = messages.findIndex((m) => m.id === messageId);\n if (messageIdx === -1)\n throw new Error(\n \"useVercelAIThreadState: Message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n while (messages[messageIdx + 1]?.role === \"assistant\") {\n messageIdx++;\n }\n\n return messages.slice(0, messageIdx + 1);\n};\n"],"mappings":";AAEO,IAAM,qBAAqB,CAChC,UACA,cACG;AACH,MAAI,aAAa,KAAM,QAAO,CAAC;AAE/B,MAAI,aAAa,SAAS,UAAU,CAAC,MAAM,EAAE,OAAO,SAAS;AAC7D,MAAI,eAAe;AACjB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEF,SAAO,SAAS,aAAa,CAAC,GAAG,SAAS,aAAa;AACrD;AAAA,EACF;AAEA,SAAO,SAAS,MAAM,GAAG,aAAa,CAAC;AACzC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/react-ai-sdk",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.15",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"@ai-sdk/ui-utils": "*",
|
|
23
23
|
"@radix-ui/react-use-callback-ref": "^1.1.1",
|
|
24
24
|
"@types/json-schema": "^7.0.15",
|
|
25
|
-
"zod": "^3.25.
|
|
26
|
-
"zustand": "^5.0.
|
|
27
|
-
"@assistant-ui/react-edge": "0.2.
|
|
25
|
+
"zod": "^3.25.67",
|
|
26
|
+
"zustand": "^5.0.6",
|
|
27
|
+
"@assistant-ui/react-edge": "0.2.13"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@assistant-ui/react": "^0.10.
|
|
30
|
+
"@assistant-ui/react": "^0.10.25",
|
|
31
31
|
"@types/react": "*",
|
|
32
32
|
"react": "^18 || ^19 || ^19.0.0-rc"
|
|
33
33
|
},
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/node": "^24.0.
|
|
40
|
+
"@types/node": "^24.0.4",
|
|
41
41
|
"@types/react": "^19.1.8",
|
|
42
42
|
"eslint": "^9",
|
|
43
|
-
"eslint-config-next": "15.3.
|
|
43
|
+
"eslint-config-next": "15.3.4",
|
|
44
44
|
"react": "^19.1.0",
|
|
45
45
|
"tsx": "^4.20.3",
|
|
46
46
|
"@assistant-ui/x-buildutils": "0.0.1"
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Message } from "@ai-sdk/ui-utils";
|
|
2
2
|
import {
|
|
3
3
|
unstable_createMessageConverter,
|
|
4
|
-
type
|
|
5
|
-
type
|
|
6
|
-
type
|
|
4
|
+
type ReasoningMessagePart,
|
|
5
|
+
type ToolCallMessagePart,
|
|
6
|
+
type TextMessagePart,
|
|
7
7
|
type CompleteAttachment,
|
|
8
|
-
type
|
|
9
|
-
type
|
|
8
|
+
type SourceMessagePart,
|
|
9
|
+
type FileMessagePart,
|
|
10
10
|
} from "@assistant-ui/react";
|
|
11
11
|
|
|
12
12
|
const convertParts = (message: Message) => {
|
|
@@ -20,7 +20,7 @@ const convertParts = (message: Message) => {
|
|
|
20
20
|
return {
|
|
21
21
|
type: "text",
|
|
22
22
|
text: part.text,
|
|
23
|
-
} satisfies
|
|
23
|
+
} satisfies TextMessagePart;
|
|
24
24
|
case "tool-invocation":
|
|
25
25
|
return {
|
|
26
26
|
type: "tool-call",
|
|
@@ -31,23 +31,23 @@ const convertParts = (message: Message) => {
|
|
|
31
31
|
result:
|
|
32
32
|
part.toolInvocation.state === "result" &&
|
|
33
33
|
part.toolInvocation.result,
|
|
34
|
-
} satisfies
|
|
34
|
+
} satisfies ToolCallMessagePart;
|
|
35
35
|
case "reasoning":
|
|
36
36
|
return {
|
|
37
37
|
type: "reasoning",
|
|
38
38
|
text: part.reasoning,
|
|
39
|
-
} satisfies
|
|
39
|
+
} satisfies ReasoningMessagePart;
|
|
40
40
|
case "source":
|
|
41
41
|
return {
|
|
42
42
|
type: "source",
|
|
43
43
|
...part.source,
|
|
44
|
-
} satisfies
|
|
44
|
+
} satisfies SourceMessagePart;
|
|
45
45
|
case "file":
|
|
46
46
|
return {
|
|
47
47
|
type: "file",
|
|
48
48
|
data: part.data,
|
|
49
49
|
mimeType: part.mimeType,
|
|
50
|
-
} satisfies
|
|
50
|
+
} satisfies FileMessagePart;
|
|
51
51
|
default: {
|
|
52
52
|
const _unsupported: never = type;
|
|
53
53
|
throw new Error(
|
|
@@ -63,7 +63,7 @@ const convertParts = (message: Message) => {
|
|
|
63
63
|
{
|
|
64
64
|
type: "text",
|
|
65
65
|
text: message.content,
|
|
66
|
-
} satisfies
|
|
66
|
+
} satisfies TextMessagePart,
|
|
67
67
|
]
|
|
68
68
|
: [];
|
|
69
69
|
};
|
|
@@ -117,7 +117,7 @@ export const AISDKMessageConverter = unstable_createMessageConverter(
|
|
|
117
117
|
case "data": {
|
|
118
118
|
type MaybeSupportedDataMessage =
|
|
119
119
|
| { type?: "unsafe_other" }
|
|
120
|
-
|
|
|
120
|
+
| ToolCallMessagePart
|
|
121
121
|
| {
|
|
122
122
|
type: "tool-result";
|
|
123
123
|
toolCallId: string;
|
|
@@ -9,7 +9,7 @@ export const sliceMessagesUntil = (
|
|
|
9
9
|
let messageIdx = messages.findIndex((m) => m.id === messageId);
|
|
10
10
|
if (messageIdx === -1)
|
|
11
11
|
throw new Error(
|
|
12
|
-
"useVercelAIThreadState: Message not found. This is
|
|
12
|
+
"useVercelAIThreadState: Message not found. This is likely an internal bug in assistant-ui.",
|
|
13
13
|
);
|
|
14
14
|
|
|
15
15
|
while (messages[messageIdx + 1]?.role === "assistant") {
|