@anvia/core 0.26.0 → 1.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +303 -94
- package/dist/agent/index.d.ts +36 -70
- package/dist/agent/index.js +25 -18
- package/dist/agent-yBG8e9Jj.d.ts +153 -0
- package/dist/chunk-4WI3VGZK.js +127 -0
- package/dist/chunk-4WI3VGZK.js.map +1 -0
- package/dist/chunk-77AIYARB.js +654 -0
- package/dist/chunk-77AIYARB.js.map +1 -0
- package/dist/chunk-AI5JMUW7.js +45 -0
- package/dist/chunk-AI5JMUW7.js.map +1 -0
- package/dist/chunk-BEYBU7VJ.js +53 -0
- package/dist/chunk-BEYBU7VJ.js.map +1 -0
- package/dist/chunk-CWM7B2OO.js +315 -0
- package/dist/chunk-CWM7B2OO.js.map +1 -0
- package/dist/chunk-D37WMSP6.js +131 -0
- package/dist/chunk-D37WMSP6.js.map +1 -0
- package/dist/chunk-DBSCKTUL.js +3793 -0
- package/dist/chunk-DBSCKTUL.js.map +1 -0
- package/dist/chunk-EINTGEGY.js +629 -0
- package/dist/chunk-EINTGEGY.js.map +1 -0
- package/dist/chunk-FMHLROPQ.js +351 -0
- package/dist/chunk-FMHLROPQ.js.map +1 -0
- package/dist/chunk-FN7HLLAZ.js +211 -0
- package/dist/chunk-FN7HLLAZ.js.map +1 -0
- package/dist/chunk-GKDERULJ.js +50 -0
- package/dist/chunk-GKDERULJ.js.map +1 -0
- package/dist/{chunk-CWUJUSOS.js → chunk-KIDGIJM7.js} +26 -5
- package/dist/chunk-KIDGIJM7.js.map +1 -0
- package/dist/chunk-KR3RCCHJ.js +500 -0
- package/dist/chunk-KR3RCCHJ.js.map +1 -0
- package/dist/chunk-MGNTXGTX.js +37 -0
- package/dist/chunk-MGNTXGTX.js.map +1 -0
- package/dist/{chunk-MRQLEK2B.js → chunk-OJH6HWHX.js} +63 -51
- package/dist/chunk-OJH6HWHX.js.map +1 -0
- package/dist/chunk-QOUPWOGW.js +29 -0
- package/dist/chunk-QOUPWOGW.js.map +1 -0
- package/dist/chunk-TIZYTPJO.js +208 -0
- package/dist/chunk-TIZYTPJO.js.map +1 -0
- package/dist/{chunk-NCPN4SJR.js → chunk-XKYYBABH.js} +13 -13
- package/dist/chunk-XKYYBABH.js.map +1 -0
- package/dist/client-B8DT1vUG.d.ts +83 -0
- package/dist/completion/index.d.ts +6 -36
- package/dist/completion/index.js +25 -29
- package/dist/dynamic-tools-KwEGRbHp.d.ts +45 -0
- package/dist/embeddings/index.d.ts +11 -9
- package/dist/embeddings/index.js +2 -4
- package/dist/evals/index.d.ts +47 -20
- package/dist/evals/index.js +104 -65
- package/dist/evals/index.js.map +1 -1
- package/dist/extractor/index.d.ts +27 -42
- package/dist/extractor/index.js +7 -22
- package/dist/guardrails/index.d.ts +3 -2
- package/dist/guardrails/index.js +1 -1
- package/dist/image-generation/index.d.ts +23 -23
- package/dist/image-generation/index.js +5 -39
- package/dist/image-generation/index.js.map +1 -1
- package/dist/index.d.ts +25 -20
- package/dist/index.js +60 -63
- package/dist/internal/agent.d.ts +163 -9
- package/dist/internal/agent.js +25 -18
- package/dist/loaders/index.d.ts +6 -10
- package/dist/loaders/index.js.map +1 -1
- package/dist/mcp/index.d.ts +19 -13
- package/dist/mcp/index.js +13 -348
- package/dist/mcp/index.js.map +1 -1
- package/dist/memory/index.d.ts +20 -6
- package/dist/memory/index.js +9 -10
- package/dist/message-schema-Cn7ezRfJ.d.ts +52 -0
- package/dist/middleware-C7PdmKF7.d.ts +56 -0
- package/dist/model-call-options-CZkSw_xN.d.ts +6 -0
- package/dist/model-listing/index.d.ts +3 -1
- package/dist/observability/index.d.ts +20 -3
- package/dist/observability/index.js +8 -5
- package/dist/observability/index.js.map +1 -1
- package/dist/pipeline/index.d.ts +114 -72
- package/dist/pipeline/index.js +478 -286
- package/dist/pipeline/index.js.map +1 -1
- package/dist/retry-CjvSlKGW.d.ts +16 -0
- package/dist/skills/index.d.ts +5 -4
- package/dist/skills/index.js +7 -8
- package/dist/speech-generation/index.d.ts +37 -0
- package/dist/speech-generation/index.js +8 -0
- package/dist/streaming/index.js +37 -3
- package/dist/streaming/index.js.map +1 -1
- package/dist/{think-tool-DfCMuO8e.d.ts → think-tool-6H2QNQzQ.d.ts} +5 -5
- package/dist/tool/index.d.ts +10 -6
- package/dist/tool/index.js +15 -21
- package/dist/tool--Mz4v1eL.d.ts +57 -0
- package/dist/transcription/index.d.ts +29 -22
- package/dist/transcription/index.js +5 -57
- package/dist/transcription/index.js.map +1 -1
- package/dist/type-utils-CtHVDRn_.d.ts +6 -0
- package/dist/types-3x3mOLHU.d.ts +379 -0
- package/dist/types-BVzM4RsC.d.ts +155 -0
- package/dist/types-CQ_ioXWK.d.ts +319 -0
- package/dist/types-Cr4uiYo5.d.ts +99 -0
- package/dist/{types-04LqWrmy.d.ts → types-DiJqJejp.d.ts} +1 -1
- package/dist/types-Dld1TpWj.d.ts +130 -0
- package/dist/vector-store/index.d.ts +33 -34
- package/dist/vector-store/index.js +6 -6
- package/package.json +6 -18
- package/dist/agent-x3YTyv5i.d.ts +0 -222
- package/dist/audio-generation/index.d.ts +0 -33
- package/dist/audio-generation/index.js +0 -42
- package/dist/audio-generation/index.js.map +0 -1
- package/dist/chunk-2ODTMRHP.js +0 -54
- package/dist/chunk-2ODTMRHP.js.map +0 -1
- package/dist/chunk-ADH7NNCS.js +0 -512
- package/dist/chunk-ADH7NNCS.js.map +0 -1
- package/dist/chunk-BALBBVI3.js +0 -2732
- package/dist/chunk-BALBBVI3.js.map +0 -1
- package/dist/chunk-CWUJUSOS.js.map +0 -1
- package/dist/chunk-DALYP4PX.js +0 -225
- package/dist/chunk-DALYP4PX.js.map +0 -1
- package/dist/chunk-HYUYZEAJ.js +0 -223
- package/dist/chunk-HYUYZEAJ.js.map +0 -1
- package/dist/chunk-I6XOQ4LK.js +0 -466
- package/dist/chunk-I6XOQ4LK.js.map +0 -1
- package/dist/chunk-JI5YZWNT.js +0 -220
- package/dist/chunk-JI5YZWNT.js.map +0 -1
- package/dist/chunk-MC3CCKEB.js +0 -221
- package/dist/chunk-MC3CCKEB.js.map +0 -1
- package/dist/chunk-MELYDKWQ.js +0 -337
- package/dist/chunk-MELYDKWQ.js.map +0 -1
- package/dist/chunk-MNWK2USR.js +0 -243
- package/dist/chunk-MNWK2USR.js.map +0 -1
- package/dist/chunk-MRQLEK2B.js.map +0 -1
- package/dist/chunk-NCPN4SJR.js.map +0 -1
- package/dist/chunk-OIMLU4SF.js +0 -20
- package/dist/chunk-OIMLU4SF.js.map +0 -1
- package/dist/chunk-Q25IWLBT.js +0 -138
- package/dist/chunk-Q25IWLBT.js.map +0 -1
- package/dist/chunk-UQX6EXWG.js +0 -33
- package/dist/chunk-UQX6EXWG.js.map +0 -1
- package/dist/chunk-WQKHFADH.js +0 -12
- package/dist/chunk-WQKHFADH.js.map +0 -1
- package/dist/chunk-XUUY2L2D.js +0 -42
- package/dist/chunk-XUUY2L2D.js.map +0 -1
- package/dist/chunk-XWUC7CIT.js +0 -1
- package/dist/chunk-XWUC7CIT.js.map +0 -1
- package/dist/chunk-YLMDBQO4.js +0 -141
- package/dist/chunk-YLMDBQO4.js.map +0 -1
- package/dist/errors-2moLDuuN.d.ts +0 -17
- package/dist/hooks/index.d.ts +0 -12
- package/dist/hooks/index.js +0 -17
- package/dist/index-BxSbmOMr.d.ts +0 -257
- package/dist/json-BVPssigK.d.ts +0 -39
- package/dist/middleware-Dp3d_pxi.d.ts +0 -90
- package/dist/request/index.d.ts +0 -28
- package/dist/request/index.js +0 -25
- package/dist/request/index.js.map +0 -1
- package/dist/tool-Cohdv5GC.d.ts +0 -65
- package/dist/types-BCTRUGex.d.ts +0 -47
- package/dist/types-BrLbKnEz.d.ts +0 -119
- package/dist/types-D9JpeAPF.d.ts +0 -114
- package/dist/types-G12i56s2.d.ts +0 -354
- package/dist/types-JJCxRnaZ.d.ts +0 -70
- package/dist/types-O-abTIin.d.ts +0 -79
- package/dist/ui/index.d.ts +0 -107
- package/dist/ui/index.js +0 -10
- package/dist/ui/index.js.map +0 -1
- /package/dist/{hooks → speech-generation}/index.js.map +0 -0
package/dist/chunk-I6XOQ4LK.js
DELETED
|
@@ -1,466 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AssistantContent,
|
|
3
|
-
Message,
|
|
4
|
-
ToolContent,
|
|
5
|
-
UserContent,
|
|
6
|
-
isJsonValue,
|
|
7
|
-
reasoningDisplayText,
|
|
8
|
-
serializeToolResultOutput
|
|
9
|
-
} from "./chunk-ADH7NNCS.js";
|
|
10
|
-
|
|
11
|
-
// src/ui/messages.ts
|
|
12
|
-
function uiMessagesToCoreMessages(messages) {
|
|
13
|
-
const coreMessages = [];
|
|
14
|
-
for (const message of messages) {
|
|
15
|
-
const text = textFromUIParts(message.parts);
|
|
16
|
-
if (message.role === "system") {
|
|
17
|
-
if (text.length > 0) {
|
|
18
|
-
coreMessages.push(Message.system(text, metadataOptions(message.metadata)));
|
|
19
|
-
}
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
if (message.role === "user") {
|
|
23
|
-
const content = [];
|
|
24
|
-
for (const part of message.parts) {
|
|
25
|
-
if (part.type === "text") {
|
|
26
|
-
content.push(UserContent.text(part.text));
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
if (part.type === "attachment") {
|
|
30
|
-
content.push(attachmentToUserContent(part.attachment));
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (part.type === "data" && isUserContent(part.data)) {
|
|
34
|
-
content.push(part.data);
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
throw new TypeError(
|
|
38
|
-
"User UI messages can only be converted from text, attachment, or image/document data parts."
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
if (content.length > 0) {
|
|
42
|
-
coreMessages.push(Message.user(content, metadataOptions(message.metadata)));
|
|
43
|
-
}
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
if (message.role === "assistant") {
|
|
47
|
-
const content = [];
|
|
48
|
-
const toolResults2 = [];
|
|
49
|
-
for (const part of message.parts) {
|
|
50
|
-
if (part.type === "text" && part.text.length > 0) {
|
|
51
|
-
content.push(AssistantContent.text(part.text));
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
if (part.type === "reasoning" && part.text.length > 0) {
|
|
55
|
-
content.push(AssistantContent.reasoning(part.text, part.reasoningId));
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
if (part.type === "tool" && (part.state === "input-streaming" || part.state === "input-available" || part.state === "output-available")) {
|
|
59
|
-
content.push(
|
|
60
|
-
AssistantContent.toolCall(
|
|
61
|
-
part.toolCallId,
|
|
62
|
-
part.toolName,
|
|
63
|
-
part.input ?? {},
|
|
64
|
-
part.callId
|
|
65
|
-
)
|
|
66
|
-
);
|
|
67
|
-
if (part.state === "output-available") {
|
|
68
|
-
toolResults2.push(
|
|
69
|
-
ToolContent.toolResult(part.toolCallId, outputToToolResultContent(part.output), {
|
|
70
|
-
callId: part.callId,
|
|
71
|
-
toolName: part.toolName
|
|
72
|
-
})
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (content.length > 0) {
|
|
78
|
-
coreMessages.push(
|
|
79
|
-
Message.assistant(content, {
|
|
80
|
-
id: message.id,
|
|
81
|
-
...metadataOptions(message.metadata)
|
|
82
|
-
})
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
if (toolResults2.length > 0) {
|
|
86
|
-
coreMessages.push(Message.tool(toolResults2));
|
|
87
|
-
}
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
const toolResults = [];
|
|
91
|
-
for (const part of message.parts) {
|
|
92
|
-
if (part.type !== "tool" || part.state !== "output-available") {
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
toolResults.push(
|
|
96
|
-
ToolContent.toolResult(part.toolCallId, outputToToolResultContent(part.output), {
|
|
97
|
-
callId: part.callId,
|
|
98
|
-
toolName: part.toolName
|
|
99
|
-
})
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
if (toolResults.length > 0) {
|
|
103
|
-
coreMessages.push(Message.tool(toolResults, metadataOptions(message.metadata)));
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return coreMessages;
|
|
107
|
-
}
|
|
108
|
-
function coreMessagesToUIMessages(messages) {
|
|
109
|
-
const uiMessages = [];
|
|
110
|
-
const toolPartLocations = {
|
|
111
|
-
byToolCallId: /* @__PURE__ */ new Map(),
|
|
112
|
-
byCallId: /* @__PURE__ */ new Map()
|
|
113
|
-
};
|
|
114
|
-
for (const message of messages) {
|
|
115
|
-
if (message.role === "system") {
|
|
116
|
-
uiMessages.push({
|
|
117
|
-
id: createId("msg"),
|
|
118
|
-
role: "system",
|
|
119
|
-
parts: [{ id: createId("part"), type: "text", text: message.content }],
|
|
120
|
-
...uiMetadata(message.metadata)
|
|
121
|
-
});
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
if (message.role === "user") {
|
|
125
|
-
const parts2 = [];
|
|
126
|
-
for (const content of message.content) {
|
|
127
|
-
if (content.type === "text") {
|
|
128
|
-
parts2.push({ id: createId("part"), type: "text", text: content.text });
|
|
129
|
-
} else {
|
|
130
|
-
parts2.push({
|
|
131
|
-
id: createId("part"),
|
|
132
|
-
type: "attachment",
|
|
133
|
-
attachment: userContentToAttachment(content)
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
uiMessages.push({
|
|
138
|
-
id: createId("msg"),
|
|
139
|
-
role: "user",
|
|
140
|
-
parts: parts2,
|
|
141
|
-
...uiMetadata(message.metadata)
|
|
142
|
-
});
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
if (message.role === "assistant") {
|
|
146
|
-
const parts2 = [];
|
|
147
|
-
for (const content of message.content) {
|
|
148
|
-
if (content.type === "text") {
|
|
149
|
-
parts2.push({ id: createId("part"), type: "text", text: content.text });
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
if (content.type === "reasoning") {
|
|
153
|
-
const part = {
|
|
154
|
-
id: createId("part"),
|
|
155
|
-
type: "reasoning",
|
|
156
|
-
text: reasoningDisplayText(content)
|
|
157
|
-
};
|
|
158
|
-
if (content.id !== void 0) {
|
|
159
|
-
part.reasoningId = content.id;
|
|
160
|
-
}
|
|
161
|
-
parts2.push(part);
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
if (content.type === "tool_call") {
|
|
165
|
-
const part = {
|
|
166
|
-
id: toolPartId(content.id),
|
|
167
|
-
type: "tool",
|
|
168
|
-
toolName: content.function.name,
|
|
169
|
-
toolCallId: content.id,
|
|
170
|
-
state: "input-available",
|
|
171
|
-
input: content.function.arguments
|
|
172
|
-
};
|
|
173
|
-
if (content.callId !== void 0) {
|
|
174
|
-
part.callId = content.callId;
|
|
175
|
-
}
|
|
176
|
-
parts2.push(part);
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
parts2.push({
|
|
180
|
-
id: createId("part"),
|
|
181
|
-
type: "data",
|
|
182
|
-
name: content.type,
|
|
183
|
-
data: content
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
const messageIndex = uiMessages.length;
|
|
187
|
-
uiMessages.push({
|
|
188
|
-
id: message.id ?? createId("msg"),
|
|
189
|
-
role: "assistant",
|
|
190
|
-
parts: parts2,
|
|
191
|
-
...uiMetadata(message.metadata)
|
|
192
|
-
});
|
|
193
|
-
registerToolPartLocations(parts2, messageIndex, toolPartLocations);
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
|
-
const parts = [];
|
|
197
|
-
for (const content of message.content) {
|
|
198
|
-
const part = {
|
|
199
|
-
id: toolPartId(content.id),
|
|
200
|
-
type: "tool",
|
|
201
|
-
toolName: toolNameForResult(content, uiMessages, toolPartLocations),
|
|
202
|
-
toolCallId: content.id,
|
|
203
|
-
state: "output-available",
|
|
204
|
-
output: toolResultContentToJson(content.content)
|
|
205
|
-
};
|
|
206
|
-
if (content.callId !== void 0) {
|
|
207
|
-
part.callId = content.callId;
|
|
208
|
-
}
|
|
209
|
-
if (message.metadata === void 0 && mergeToolResultPart(uiMessages, toolPartLocations, part)) {
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
parts.push(part);
|
|
213
|
-
}
|
|
214
|
-
if (parts.length > 0) {
|
|
215
|
-
uiMessages.push({
|
|
216
|
-
id: createId("msg"),
|
|
217
|
-
role: "tool",
|
|
218
|
-
parts,
|
|
219
|
-
...uiMetadata(message.metadata)
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return uiMessages;
|
|
224
|
-
}
|
|
225
|
-
function metadataOptions(metadata) {
|
|
226
|
-
if (metadata === void 0) {
|
|
227
|
-
return {};
|
|
228
|
-
}
|
|
229
|
-
if (!isJsonValue(metadata)) {
|
|
230
|
-
throw new TypeError("UI message metadata must be a strict JSON value.");
|
|
231
|
-
}
|
|
232
|
-
return { metadata };
|
|
233
|
-
}
|
|
234
|
-
function uiMetadata(metadata) {
|
|
235
|
-
if (metadata === void 0) {
|
|
236
|
-
return {};
|
|
237
|
-
}
|
|
238
|
-
if (!isJsonValue(metadata)) {
|
|
239
|
-
throw new TypeError("Core message metadata must be a strict JSON value.");
|
|
240
|
-
}
|
|
241
|
-
return { metadata };
|
|
242
|
-
}
|
|
243
|
-
function registerToolPartLocations(parts, messageIndex, toolPartLocations) {
|
|
244
|
-
for (const [partIndex, part] of parts.entries()) {
|
|
245
|
-
if (part.type !== "tool") {
|
|
246
|
-
continue;
|
|
247
|
-
}
|
|
248
|
-
const location = { messageIndex, partIndex };
|
|
249
|
-
toolPartLocations.byToolCallId.set(part.toolCallId, location);
|
|
250
|
-
if (part.callId !== void 0) {
|
|
251
|
-
toolPartLocations.byCallId.set(part.callId, location);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
function mergeToolResultPart(uiMessages, toolPartLocations, resultPart) {
|
|
256
|
-
if (resultPart.type !== "tool") {
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
const location = findToolPartLocation(
|
|
260
|
-
resultPart.toolCallId,
|
|
261
|
-
resultPart.callId,
|
|
262
|
-
toolPartLocations
|
|
263
|
-
);
|
|
264
|
-
if (location === void 0) {
|
|
265
|
-
return false;
|
|
266
|
-
}
|
|
267
|
-
const message = uiMessages[location.messageIndex];
|
|
268
|
-
const currentPart = message?.parts[location.partIndex];
|
|
269
|
-
if (message === void 0 || currentPart?.type !== "tool") {
|
|
270
|
-
return false;
|
|
271
|
-
}
|
|
272
|
-
const mergedPart = {
|
|
273
|
-
...currentPart,
|
|
274
|
-
toolName: resultPart.toolName === "tool" ? currentPart.toolName : resultPart.toolName,
|
|
275
|
-
state: "output-available"
|
|
276
|
-
};
|
|
277
|
-
if (resultPart.output !== void 0) {
|
|
278
|
-
mergedPart.output = resultPart.output;
|
|
279
|
-
}
|
|
280
|
-
if (currentPart.callId === void 0 && resultPart.callId !== void 0) {
|
|
281
|
-
mergedPart.callId = resultPart.callId;
|
|
282
|
-
toolPartLocations.byCallId.set(resultPart.callId, location);
|
|
283
|
-
}
|
|
284
|
-
const nextParts = [...message.parts];
|
|
285
|
-
nextParts[location.partIndex] = mergedPart;
|
|
286
|
-
uiMessages[location.messageIndex] = { ...message, parts: nextParts };
|
|
287
|
-
return true;
|
|
288
|
-
}
|
|
289
|
-
function findToolPartLocation(toolCallId, callId, toolPartLocations) {
|
|
290
|
-
return (callId === void 0 ? void 0 : toolPartLocations.byCallId.get(callId)) ?? toolPartLocations.byToolCallId.get(toolCallId);
|
|
291
|
-
}
|
|
292
|
-
function toolNameForResult(content, uiMessages, toolPartLocations) {
|
|
293
|
-
if (content.toolName !== void 0) {
|
|
294
|
-
return content.toolName;
|
|
295
|
-
}
|
|
296
|
-
const location = findToolPartLocation(content.id, content.callId, toolPartLocations);
|
|
297
|
-
const part = location === void 0 ? void 0 : uiMessages[location.messageIndex]?.parts[location.partIndex];
|
|
298
|
-
return part?.type === "tool" ? part.toolName : "tool";
|
|
299
|
-
}
|
|
300
|
-
function textFromUIParts(parts) {
|
|
301
|
-
return parts.flatMap((part) => part.type === "text" ? [part.text] : []).join("");
|
|
302
|
-
}
|
|
303
|
-
function outputToToolResultContent(output) {
|
|
304
|
-
return [{ type: "text", text: serializeToolResultOutput(output ?? null) }];
|
|
305
|
-
}
|
|
306
|
-
function attachmentToUserContent(attachment) {
|
|
307
|
-
if (attachment.type === "image" || isImageFileAttachment(attachment)) {
|
|
308
|
-
if (attachment.url !== void 0) {
|
|
309
|
-
return UserContent.imageUrl(attachment.url, imageOptions(attachment));
|
|
310
|
-
}
|
|
311
|
-
if (attachment.data !== void 0 && attachment.mediaType !== void 0) {
|
|
312
|
-
return UserContent.imageBase64(
|
|
313
|
-
attachment.data,
|
|
314
|
-
attachment.mediaType,
|
|
315
|
-
imageOptions(attachment)
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
throw new TypeError("Image attachments require a url or base64 data with mediaType.");
|
|
319
|
-
}
|
|
320
|
-
if (attachment.text !== void 0) {
|
|
321
|
-
const source = {
|
|
322
|
-
type: "text",
|
|
323
|
-
text: attachment.text
|
|
324
|
-
};
|
|
325
|
-
if (attachment.mediaType !== void 0) {
|
|
326
|
-
source.mediaType = attachment.mediaType;
|
|
327
|
-
}
|
|
328
|
-
if (attachment.name !== void 0) {
|
|
329
|
-
source.filename = attachment.name;
|
|
330
|
-
}
|
|
331
|
-
return {
|
|
332
|
-
type: "document",
|
|
333
|
-
source
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
const mediaType = attachment.mediaType ?? "application/octet-stream";
|
|
337
|
-
if (attachment.url !== void 0) {
|
|
338
|
-
return UserContent.documentUrl(attachment.url, mediaType, documentOptions(attachment));
|
|
339
|
-
}
|
|
340
|
-
if (attachment.data !== void 0) {
|
|
341
|
-
return UserContent.documentBase64(attachment.data, mediaType, documentOptions(attachment));
|
|
342
|
-
}
|
|
343
|
-
throw new TypeError("Document attachments require a url, base64 data, or text.");
|
|
344
|
-
}
|
|
345
|
-
function userContentToAttachment(content) {
|
|
346
|
-
if (content.type === "image") {
|
|
347
|
-
const attachment2 = {
|
|
348
|
-
id: createId("attachment"),
|
|
349
|
-
type: "image"
|
|
350
|
-
};
|
|
351
|
-
if (content.detail !== void 0) {
|
|
352
|
-
attachment2.detail = content.detail;
|
|
353
|
-
}
|
|
354
|
-
if (content.source.type === "url") {
|
|
355
|
-
attachment2.url = content.source.url;
|
|
356
|
-
} else {
|
|
357
|
-
attachment2.data = content.source.data;
|
|
358
|
-
attachment2.mediaType = content.source.mediaType;
|
|
359
|
-
}
|
|
360
|
-
return attachment2;
|
|
361
|
-
}
|
|
362
|
-
const attachment = {
|
|
363
|
-
id: createId("attachment"),
|
|
364
|
-
type: "document"
|
|
365
|
-
};
|
|
366
|
-
if (content.source.type === "url") {
|
|
367
|
-
attachment.url = content.source.url;
|
|
368
|
-
attachment.mediaType = content.source.mediaType;
|
|
369
|
-
if (content.source.filename !== void 0) {
|
|
370
|
-
attachment.name = content.source.filename;
|
|
371
|
-
}
|
|
372
|
-
} else if (content.source.type === "base64") {
|
|
373
|
-
attachment.data = content.source.data;
|
|
374
|
-
attachment.mediaType = content.source.mediaType;
|
|
375
|
-
if (content.source.filename !== void 0) {
|
|
376
|
-
attachment.name = content.source.filename;
|
|
377
|
-
}
|
|
378
|
-
} else {
|
|
379
|
-
attachment.text = content.source.text;
|
|
380
|
-
if (content.source.mediaType !== void 0) {
|
|
381
|
-
attachment.mediaType = content.source.mediaType;
|
|
382
|
-
}
|
|
383
|
-
if (content.source.filename !== void 0) {
|
|
384
|
-
attachment.name = content.source.filename;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
return attachment;
|
|
388
|
-
}
|
|
389
|
-
function isImageFileAttachment(attachment) {
|
|
390
|
-
return attachment.type === "file" && attachment.mediaType?.startsWith("image/") === true;
|
|
391
|
-
}
|
|
392
|
-
function imageOptions(attachment) {
|
|
393
|
-
return attachment.detail === void 0 ? {} : { detail: attachment.detail };
|
|
394
|
-
}
|
|
395
|
-
function documentOptions(attachment) {
|
|
396
|
-
return attachment.name === void 0 ? {} : { filename: attachment.name };
|
|
397
|
-
}
|
|
398
|
-
function toolResultContentToJson(content) {
|
|
399
|
-
if (content.length === 1 && content[0]?.type === "text") {
|
|
400
|
-
return content[0].text;
|
|
401
|
-
}
|
|
402
|
-
return content;
|
|
403
|
-
}
|
|
404
|
-
function isUserContent(value) {
|
|
405
|
-
if (!isRecord(value)) {
|
|
406
|
-
return false;
|
|
407
|
-
}
|
|
408
|
-
if (value.type === "text") {
|
|
409
|
-
return typeof value.text === "string";
|
|
410
|
-
}
|
|
411
|
-
if (value.type === "image") {
|
|
412
|
-
return isImageContent(value);
|
|
413
|
-
}
|
|
414
|
-
if (value.type === "document") {
|
|
415
|
-
return isDocumentContent(value);
|
|
416
|
-
}
|
|
417
|
-
return false;
|
|
418
|
-
}
|
|
419
|
-
function isImageContent(value) {
|
|
420
|
-
if (!isRecord(value.source)) {
|
|
421
|
-
return false;
|
|
422
|
-
}
|
|
423
|
-
if (value.source.type === "url") {
|
|
424
|
-
return typeof value.source.url === "string";
|
|
425
|
-
}
|
|
426
|
-
if (value.source.type === "base64") {
|
|
427
|
-
return typeof value.source.data === "string" && typeof value.source.mediaType === "string";
|
|
428
|
-
}
|
|
429
|
-
return false;
|
|
430
|
-
}
|
|
431
|
-
function isDocumentContent(value) {
|
|
432
|
-
if (!isRecord(value.source)) {
|
|
433
|
-
return false;
|
|
434
|
-
}
|
|
435
|
-
if (value.source.type === "url") {
|
|
436
|
-
return typeof value.source.url === "string" && typeof value.source.mediaType === "string";
|
|
437
|
-
}
|
|
438
|
-
if (value.source.type === "base64") {
|
|
439
|
-
return typeof value.source.data === "string" && typeof value.source.mediaType === "string";
|
|
440
|
-
}
|
|
441
|
-
if (value.source.type === "text") {
|
|
442
|
-
return typeof value.source.text === "string" && (value.source.mediaType === void 0 || typeof value.source.mediaType === "string");
|
|
443
|
-
}
|
|
444
|
-
return false;
|
|
445
|
-
}
|
|
446
|
-
function toolPartId(toolCallId) {
|
|
447
|
-
return `tool_${toolCallId}`;
|
|
448
|
-
}
|
|
449
|
-
var nextId = 0;
|
|
450
|
-
function createId(prefix) {
|
|
451
|
-
const random = globalThis.crypto?.randomUUID?.();
|
|
452
|
-
if (random !== void 0) {
|
|
453
|
-
return `${prefix}_${random}`;
|
|
454
|
-
}
|
|
455
|
-
nextId += 1;
|
|
456
|
-
return `${prefix}_${nextId.toString(36)}`;
|
|
457
|
-
}
|
|
458
|
-
function isRecord(value) {
|
|
459
|
-
return typeof value === "object" && value !== null;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
export {
|
|
463
|
-
uiMessagesToCoreMessages,
|
|
464
|
-
coreMessagesToUIMessages
|
|
465
|
-
};
|
|
466
|
-
//# sourceMappingURL=chunk-I6XOQ4LK.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ui/messages.ts"],"sourcesContent":["import { isJsonValue } from \"../completion/json\";\nimport {\n AssistantContent,\n type AssistantContent as AssistantContentType,\n type Message as CoreMessage,\n type DocumentContent,\n type ImageContent,\n type ImageDetail,\n type JsonValue,\n Message,\n reasoningDisplayText,\n serializeToolResultOutput,\n ToolContent,\n type ToolContent as ToolContentType,\n type ToolResultContent,\n UserContent,\n type UserContent as UserContentType,\n} from \"../completion/types\";\nimport type { UIAttachment, UIMessage, UIMessagePart } from \"./types\";\n\ntype UIToolPartLocation = {\n messageIndex: number;\n partIndex: number;\n};\n\ntype UIToolPartLocations = {\n byToolCallId: Map<string, UIToolPartLocation>;\n byCallId: Map<string, UIToolPartLocation>;\n};\n\ntype UIToolMessagePart = Extract<UIMessagePart, { type: \"tool\" }>;\n\nexport function uiMessagesToCoreMessages(messages: UIMessage[]): CoreMessage[] {\n const coreMessages: CoreMessage[] = [];\n\n for (const message of messages) {\n const text = textFromUIParts(message.parts);\n\n if (message.role === \"system\") {\n if (text.length > 0) {\n coreMessages.push(Message.system(text, metadataOptions(message.metadata)));\n }\n continue;\n }\n\n if (message.role === \"user\") {\n const content: UserContentType[] = [];\n for (const part of message.parts) {\n if (part.type === \"text\") {\n content.push(UserContent.text(part.text));\n continue;\n }\n if (part.type === \"attachment\") {\n content.push(attachmentToUserContent(part.attachment));\n continue;\n }\n if (part.type === \"data\" && isUserContent(part.data)) {\n content.push(part.data);\n continue;\n }\n throw new TypeError(\n \"User UI messages can only be converted from text, attachment, or image/document data parts.\",\n );\n }\n if (content.length > 0) {\n coreMessages.push(Message.user(content, metadataOptions(message.metadata)));\n }\n continue;\n }\n\n if (message.role === \"assistant\") {\n const content: AssistantContentType[] = [];\n const toolResults: ToolContentType[] = [];\n for (const part of message.parts) {\n if (part.type === \"text\" && part.text.length > 0) {\n content.push(AssistantContent.text(part.text));\n continue;\n }\n if (part.type === \"reasoning\" && part.text.length > 0) {\n content.push(AssistantContent.reasoning(part.text, part.reasoningId));\n continue;\n }\n if (\n part.type === \"tool\" &&\n (part.state === \"input-streaming\" ||\n part.state === \"input-available\" ||\n part.state === \"output-available\")\n ) {\n content.push(\n AssistantContent.toolCall(\n part.toolCallId,\n part.toolName,\n part.input ?? {},\n part.callId,\n ),\n );\n if (part.state === \"output-available\") {\n toolResults.push(\n ToolContent.toolResult(part.toolCallId, outputToToolResultContent(part.output), {\n callId: part.callId,\n toolName: part.toolName,\n }),\n );\n }\n }\n }\n if (content.length > 0) {\n coreMessages.push(\n Message.assistant(content, {\n id: message.id,\n ...metadataOptions(message.metadata),\n }),\n );\n }\n if (toolResults.length > 0) {\n coreMessages.push(Message.tool(toolResults));\n }\n continue;\n }\n\n const toolResults: ToolContentType[] = [];\n for (const part of message.parts) {\n if (part.type !== \"tool\" || part.state !== \"output-available\") {\n continue;\n }\n toolResults.push(\n ToolContent.toolResult(part.toolCallId, outputToToolResultContent(part.output), {\n callId: part.callId,\n toolName: part.toolName,\n }),\n );\n }\n if (toolResults.length > 0) {\n coreMessages.push(Message.tool(toolResults, metadataOptions(message.metadata)));\n }\n }\n\n return coreMessages;\n}\n\nexport function coreMessagesToUIMessages(messages: CoreMessage[]): UIMessage[] {\n const uiMessages: UIMessage[] = [];\n const toolPartLocations: UIToolPartLocations = {\n byToolCallId: new Map(),\n byCallId: new Map(),\n };\n\n for (const message of messages) {\n if (message.role === \"system\") {\n uiMessages.push({\n id: createId(\"msg\"),\n role: \"system\",\n parts: [{ id: createId(\"part\"), type: \"text\", text: message.content }],\n ...uiMetadata(message.metadata),\n });\n continue;\n }\n\n if (message.role === \"user\") {\n const parts: UIMessagePart[] = [];\n for (const content of message.content) {\n if (content.type === \"text\") {\n parts.push({ id: createId(\"part\"), type: \"text\", text: content.text });\n } else {\n parts.push({\n id: createId(\"part\"),\n type: \"attachment\",\n attachment: userContentToAttachment(content),\n });\n }\n }\n uiMessages.push({\n id: createId(\"msg\"),\n role: \"user\",\n parts,\n ...uiMetadata(message.metadata),\n });\n continue;\n }\n\n if (message.role === \"assistant\") {\n const parts: UIMessagePart[] = [];\n for (const content of message.content) {\n if (content.type === \"text\") {\n parts.push({ id: createId(\"part\"), type: \"text\", text: content.text });\n continue;\n }\n if (content.type === \"reasoning\") {\n const part: UIMessagePart = {\n id: createId(\"part\"),\n type: \"reasoning\",\n text: reasoningDisplayText(content),\n };\n if (content.id !== undefined) {\n part.reasoningId = content.id;\n }\n parts.push(part);\n continue;\n }\n if (content.type === \"tool_call\") {\n const part: UIMessagePart = {\n id: toolPartId(content.id),\n type: \"tool\",\n toolName: content.function.name,\n toolCallId: content.id,\n state: \"input-available\",\n input: content.function.arguments,\n };\n if (content.callId !== undefined) {\n part.callId = content.callId;\n }\n parts.push(part);\n continue;\n }\n parts.push({\n id: createId(\"part\"),\n type: \"data\",\n name: content.type,\n data: content as JsonValue,\n });\n }\n const messageIndex = uiMessages.length;\n uiMessages.push({\n id: message.id ?? createId(\"msg\"),\n role: \"assistant\",\n parts,\n ...uiMetadata(message.metadata),\n });\n registerToolPartLocations(parts, messageIndex, toolPartLocations);\n continue;\n }\n\n const parts: UIMessagePart[] = [];\n for (const content of message.content) {\n const part: UIToolMessagePart = {\n id: toolPartId(content.id),\n type: \"tool\",\n toolName: toolNameForResult(content, uiMessages, toolPartLocations),\n toolCallId: content.id,\n state: \"output-available\",\n output: toolResultContentToJson(content.content),\n };\n if (content.callId !== undefined) {\n part.callId = content.callId;\n }\n if (\n message.metadata === undefined &&\n mergeToolResultPart(uiMessages, toolPartLocations, part)\n ) {\n continue;\n }\n parts.push(part);\n }\n if (parts.length > 0) {\n uiMessages.push({\n id: createId(\"msg\"),\n role: \"tool\",\n parts,\n ...uiMetadata(message.metadata),\n });\n }\n }\n\n return uiMessages;\n}\n\nfunction metadataOptions(metadata: UIMessage[\"metadata\"]): { metadata?: JsonValue } {\n if (metadata === undefined) {\n return {};\n }\n if (!isJsonValue(metadata)) {\n throw new TypeError(\"UI message metadata must be a strict JSON value.\");\n }\n return { metadata };\n}\n\nfunction uiMetadata(metadata: JsonValue | undefined): { metadata?: JsonValue } {\n if (metadata === undefined) {\n return {};\n }\n if (!isJsonValue(metadata)) {\n throw new TypeError(\"Core message metadata must be a strict JSON value.\");\n }\n return { metadata };\n}\n\nfunction registerToolPartLocations(\n parts: UIMessagePart[],\n messageIndex: number,\n toolPartLocations: UIToolPartLocations,\n): void {\n for (const [partIndex, part] of parts.entries()) {\n if (part.type !== \"tool\") {\n continue;\n }\n const location = { messageIndex, partIndex };\n toolPartLocations.byToolCallId.set(part.toolCallId, location);\n if (part.callId !== undefined) {\n toolPartLocations.byCallId.set(part.callId, location);\n }\n }\n}\n\nfunction mergeToolResultPart(\n uiMessages: UIMessage[],\n toolPartLocations: UIToolPartLocations,\n resultPart: UIMessagePart,\n): boolean {\n if (resultPart.type !== \"tool\") {\n return false;\n }\n\n const location = findToolPartLocation(\n resultPart.toolCallId,\n resultPart.callId,\n toolPartLocations,\n );\n if (location === undefined) {\n return false;\n }\n\n const message = uiMessages[location.messageIndex];\n const currentPart = message?.parts[location.partIndex];\n if (message === undefined || currentPart?.type !== \"tool\") {\n return false;\n }\n\n const mergedPart: UIToolMessagePart = {\n ...currentPart,\n toolName: resultPart.toolName === \"tool\" ? currentPart.toolName : resultPart.toolName,\n state: \"output-available\",\n };\n if (resultPart.output !== undefined) {\n mergedPart.output = resultPart.output;\n }\n if (currentPart.callId === undefined && resultPart.callId !== undefined) {\n mergedPart.callId = resultPart.callId;\n toolPartLocations.byCallId.set(resultPart.callId, location);\n }\n\n const nextParts = [...message.parts];\n nextParts[location.partIndex] = mergedPart;\n uiMessages[location.messageIndex] = { ...message, parts: nextParts };\n return true;\n}\n\nfunction findToolPartLocation(\n toolCallId: string,\n callId: string | undefined,\n toolPartLocations: UIToolPartLocations,\n): UIToolPartLocation | undefined {\n return (\n (callId === undefined ? undefined : toolPartLocations.byCallId.get(callId)) ??\n toolPartLocations.byToolCallId.get(toolCallId)\n );\n}\n\nfunction toolNameForResult(\n content: ToolContentType,\n uiMessages: UIMessage[],\n toolPartLocations: UIToolPartLocations,\n): string {\n if (content.toolName !== undefined) {\n return content.toolName;\n }\n\n const location = findToolPartLocation(content.id, content.callId, toolPartLocations);\n const part =\n location === undefined\n ? undefined\n : uiMessages[location.messageIndex]?.parts[location.partIndex];\n return part?.type === \"tool\" ? part.toolName : \"tool\";\n}\n\nexport function isUIMessage(value: unknown): value is UIMessage {\n return (\n isRecord(value) &&\n typeof value.id === \"string\" &&\n isUIMessageRole(value.role) &&\n Array.isArray(value.parts)\n );\n}\n\nexport function isUIMessageArray(value: unknown): value is UIMessage[] {\n return Array.isArray(value) && value.every(isUIMessage);\n}\n\nfunction textFromUIParts(parts: UIMessagePart[]): string {\n return parts.flatMap((part) => (part.type === \"text\" ? [part.text] : [])).join(\"\");\n}\n\nfunction outputToToolResultContent(output: JsonValue | undefined): ToolResultContent[] {\n return [{ type: \"text\", text: serializeToolResultOutput(output ?? null) }];\n}\n\nfunction attachmentToUserContent(attachment: UIAttachment): UserContentType {\n if (attachment.type === \"image\" || isImageFileAttachment(attachment)) {\n if (attachment.url !== undefined) {\n return UserContent.imageUrl(attachment.url, imageOptions(attachment));\n }\n if (attachment.data !== undefined && attachment.mediaType !== undefined) {\n return UserContent.imageBase64(\n attachment.data,\n attachment.mediaType,\n imageOptions(attachment),\n );\n }\n throw new TypeError(\"Image attachments require a url or base64 data with mediaType.\");\n }\n\n if (attachment.text !== undefined) {\n const source: Extract<DocumentContent[\"source\"], { type: \"text\" }> = {\n type: \"text\",\n text: attachment.text,\n };\n if (attachment.mediaType !== undefined) {\n source.mediaType = attachment.mediaType;\n }\n if (attachment.name !== undefined) {\n source.filename = attachment.name;\n }\n return {\n type: \"document\",\n source,\n };\n }\n\n const mediaType = attachment.mediaType ?? \"application/octet-stream\";\n if (attachment.url !== undefined) {\n return UserContent.documentUrl(attachment.url, mediaType, documentOptions(attachment));\n }\n if (attachment.data !== undefined) {\n return UserContent.documentBase64(attachment.data, mediaType, documentOptions(attachment));\n }\n\n throw new TypeError(\"Document attachments require a url, base64 data, or text.\");\n}\n\nfunction userContentToAttachment(content: ImageContent | DocumentContent): UIAttachment {\n if (content.type === \"image\") {\n const attachment: UIAttachment = {\n id: createId(\"attachment\"),\n type: \"image\",\n };\n if (content.detail !== undefined) {\n attachment.detail = content.detail;\n }\n if (content.source.type === \"url\") {\n attachment.url = content.source.url;\n } else {\n attachment.data = content.source.data;\n attachment.mediaType = content.source.mediaType;\n }\n return attachment;\n }\n\n const attachment: UIAttachment = {\n id: createId(\"attachment\"),\n type: \"document\",\n };\n if (content.source.type === \"url\") {\n attachment.url = content.source.url;\n attachment.mediaType = content.source.mediaType;\n if (content.source.filename !== undefined) {\n attachment.name = content.source.filename;\n }\n } else if (content.source.type === \"base64\") {\n attachment.data = content.source.data;\n attachment.mediaType = content.source.mediaType;\n if (content.source.filename !== undefined) {\n attachment.name = content.source.filename;\n }\n } else {\n attachment.text = content.source.text;\n if (content.source.mediaType !== undefined) {\n attachment.mediaType = content.source.mediaType;\n }\n if (content.source.filename !== undefined) {\n attachment.name = content.source.filename;\n }\n }\n return attachment;\n}\n\nfunction isImageFileAttachment(attachment: UIAttachment): boolean {\n return attachment.type === \"file\" && attachment.mediaType?.startsWith(\"image/\") === true;\n}\n\nfunction imageOptions(attachment: UIAttachment): { detail?: ImageDetail } {\n return attachment.detail === undefined ? {} : { detail: attachment.detail };\n}\n\nfunction documentOptions(attachment: UIAttachment): { filename?: string } {\n return attachment.name === undefined ? {} : { filename: attachment.name };\n}\n\nfunction toolResultContentToJson(content: ToolResultContent[]): JsonValue {\n if (content.length === 1 && content[0]?.type === \"text\") {\n return content[0].text;\n }\n return content as JsonValue;\n}\n\nfunction isUserContent(value: unknown): value is UserContentType {\n if (!isRecord(value)) {\n return false;\n }\n\n if (value.type === \"text\") {\n return typeof value.text === \"string\";\n }\n\n if (value.type === \"image\") {\n return isImageContent(value);\n }\n\n if (value.type === \"document\") {\n return isDocumentContent(value);\n }\n\n return false;\n}\n\nfunction isImageContent(value: Record<string, unknown>): boolean {\n if (!isRecord(value.source)) {\n return false;\n }\n\n if (value.source.type === \"url\") {\n return typeof value.source.url === \"string\";\n }\n\n if (value.source.type === \"base64\") {\n return typeof value.source.data === \"string\" && typeof value.source.mediaType === \"string\";\n }\n\n return false;\n}\n\nfunction isDocumentContent(value: Record<string, unknown>): boolean {\n if (!isRecord(value.source)) {\n return false;\n }\n\n if (value.source.type === \"url\") {\n return typeof value.source.url === \"string\" && typeof value.source.mediaType === \"string\";\n }\n\n if (value.source.type === \"base64\") {\n return typeof value.source.data === \"string\" && typeof value.source.mediaType === \"string\";\n }\n\n if (value.source.type === \"text\") {\n return (\n typeof value.source.text === \"string\" &&\n (value.source.mediaType === undefined || typeof value.source.mediaType === \"string\")\n );\n }\n\n return false;\n}\n\nfunction toolPartId(toolCallId: string): string {\n return `tool_${toolCallId}`;\n}\n\nlet nextId = 0;\n\nfunction createId(prefix: string): string {\n const random = globalThis.crypto?.randomUUID?.();\n if (random !== undefined) {\n return `${prefix}_${random}`;\n }\n nextId += 1;\n return `${prefix}_${nextId.toString(36)}`;\n}\n\nfunction isUIMessageRole(value: unknown): value is UIMessage[\"role\"] {\n return value === \"system\" || value === \"user\" || value === \"assistant\" || value === \"tool\";\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n"],"mappings":";;;;;;;;;;;AAgCO,SAAS,yBAAyB,UAAsC;AAC7E,QAAM,eAA8B,CAAC;AAErC,aAAW,WAAW,UAAU;AAC9B,UAAM,OAAO,gBAAgB,QAAQ,KAAK;AAE1C,QAAI,QAAQ,SAAS,UAAU;AAC7B,UAAI,KAAK,SAAS,GAAG;AACnB,qBAAa,KAAK,QAAQ,OAAO,MAAM,gBAAgB,QAAQ,QAAQ,CAAC,CAAC;AAAA,MAC3E;AACA;AAAA,IACF;AAEA,QAAI,QAAQ,SAAS,QAAQ;AAC3B,YAAM,UAA6B,CAAC;AACpC,iBAAW,QAAQ,QAAQ,OAAO;AAChC,YAAI,KAAK,SAAS,QAAQ;AACxB,kBAAQ,KAAK,YAAY,KAAK,KAAK,IAAI,CAAC;AACxC;AAAA,QACF;AACA,YAAI,KAAK,SAAS,cAAc;AAC9B,kBAAQ,KAAK,wBAAwB,KAAK,UAAU,CAAC;AACrD;AAAA,QACF;AACA,YAAI,KAAK,SAAS,UAAU,cAAc,KAAK,IAAI,GAAG;AACpD,kBAAQ,KAAK,KAAK,IAAI;AACtB;AAAA,QACF;AACA,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AACA,UAAI,QAAQ,SAAS,GAAG;AACtB,qBAAa,KAAK,QAAQ,KAAK,SAAS,gBAAgB,QAAQ,QAAQ,CAAC,CAAC;AAAA,MAC5E;AACA;AAAA,IACF;AAEA,QAAI,QAAQ,SAAS,aAAa;AAChC,YAAM,UAAkC,CAAC;AACzC,YAAMA,eAAiC,CAA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