ai 5.0.0-canary.15 → 5.0.0-canary.17
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/CHANGELOG.md +55 -0
- package/dist/index.d.mts +145 -120
- package/dist/index.d.ts +145 -120
- package/dist/index.js +276 -391
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +270 -390
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +32 -59
- package/dist/internal/index.d.ts +32 -59
- package/dist/internal/index.js +193 -387
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +186 -380
- package/dist/internal/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.d.mts +2 -2
- package/dist/mcp-stdio/index.d.ts +2 -2
- package/package.json +3 -3
package/dist/internal/index.mjs
CHANGED
@@ -3,228 +3,36 @@ import { InvalidPromptError } from "@ai-sdk/provider";
|
|
3
3
|
import { safeValidateTypes } from "@ai-sdk/provider-utils";
|
4
4
|
import { z as z7 } from "zod";
|
5
5
|
|
6
|
-
// core/prompt/
|
7
|
-
import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
|
8
|
-
import {
|
9
|
-
convertBase64ToUint8Array,
|
10
|
-
convertUint8ArrayToBase64
|
11
|
-
} from "@ai-sdk/provider-utils";
|
12
|
-
import { z } from "zod";
|
13
|
-
|
14
|
-
// core/prompt/invalid-data-content-error.ts
|
6
|
+
// core/prompt/message-conversion-error.ts
|
15
7
|
import { AISDKError } from "@ai-sdk/provider";
|
16
|
-
var name = "
|
8
|
+
var name = "AI_MessageConversionError";
|
17
9
|
var marker = `vercel.ai.error.${name}`;
|
18
10
|
var symbol = Symbol.for(marker);
|
19
11
|
var _a;
|
20
|
-
var
|
21
|
-
constructor({
|
22
|
-
content,
|
23
|
-
cause,
|
24
|
-
message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
|
25
|
-
}) {
|
26
|
-
super({ name, message, cause });
|
27
|
-
this[_a] = true;
|
28
|
-
this.content = content;
|
29
|
-
}
|
30
|
-
static isInstance(error) {
|
31
|
-
return AISDKError.hasMarker(error, marker);
|
32
|
-
}
|
33
|
-
};
|
34
|
-
_a = symbol;
|
35
|
-
|
36
|
-
// core/prompt/split-data-url.ts
|
37
|
-
function splitDataUrl(dataUrl) {
|
38
|
-
try {
|
39
|
-
const [header, base64Content] = dataUrl.split(",");
|
40
|
-
return {
|
41
|
-
mediaType: header.split(";")[0].split(":")[1],
|
42
|
-
base64Content
|
43
|
-
};
|
44
|
-
} catch (error) {
|
45
|
-
return {
|
46
|
-
mediaType: void 0,
|
47
|
-
base64Content: void 0
|
48
|
-
};
|
49
|
-
}
|
50
|
-
}
|
51
|
-
|
52
|
-
// core/prompt/data-content.ts
|
53
|
-
var dataContentSchema = z.union([
|
54
|
-
z.string(),
|
55
|
-
z.instanceof(Uint8Array),
|
56
|
-
z.instanceof(ArrayBuffer),
|
57
|
-
z.custom(
|
58
|
-
// Buffer might not be available in some environments such as CloudFlare:
|
59
|
-
(value) => {
|
60
|
-
var _a7, _b;
|
61
|
-
return (_b = (_a7 = globalThis.Buffer) == null ? void 0 : _a7.isBuffer(value)) != null ? _b : false;
|
62
|
-
},
|
63
|
-
{ message: "Must be a Buffer" }
|
64
|
-
)
|
65
|
-
]);
|
66
|
-
function convertToLanguageModelV2DataContent(content) {
|
67
|
-
if (content instanceof Uint8Array) {
|
68
|
-
return { data: content, mediaType: void 0 };
|
69
|
-
}
|
70
|
-
if (content instanceof ArrayBuffer) {
|
71
|
-
return { data: new Uint8Array(content), mediaType: void 0 };
|
72
|
-
}
|
73
|
-
if (typeof content === "string") {
|
74
|
-
try {
|
75
|
-
content = new URL(content);
|
76
|
-
} catch (error) {
|
77
|
-
}
|
78
|
-
}
|
79
|
-
if (content instanceof URL && content.protocol === "data:") {
|
80
|
-
const { mediaType: dataUrlMediaType, base64Content } = splitDataUrl(
|
81
|
-
content.toString()
|
82
|
-
);
|
83
|
-
if (dataUrlMediaType == null || base64Content == null) {
|
84
|
-
throw new AISDKError2({
|
85
|
-
name: "InvalidDataContentError",
|
86
|
-
message: `Invalid data URL format in content ${content.toString()}`
|
87
|
-
});
|
88
|
-
}
|
89
|
-
return { data: base64Content, mediaType: dataUrlMediaType };
|
90
|
-
}
|
91
|
-
return { data: content, mediaType: void 0 };
|
92
|
-
}
|
93
|
-
function convertDataContentToUint8Array(content) {
|
94
|
-
if (content instanceof Uint8Array) {
|
95
|
-
return content;
|
96
|
-
}
|
97
|
-
if (typeof content === "string") {
|
98
|
-
try {
|
99
|
-
return convertBase64ToUint8Array(content);
|
100
|
-
} catch (error) {
|
101
|
-
throw new InvalidDataContentError({
|
102
|
-
message: "Invalid data content. Content string is not a base64-encoded media.",
|
103
|
-
content,
|
104
|
-
cause: error
|
105
|
-
});
|
106
|
-
}
|
107
|
-
}
|
108
|
-
if (content instanceof ArrayBuffer) {
|
109
|
-
return new Uint8Array(content);
|
110
|
-
}
|
111
|
-
throw new InvalidDataContentError({ content });
|
112
|
-
}
|
113
|
-
function convertUint8ArrayToText(uint8Array) {
|
114
|
-
try {
|
115
|
-
return new TextDecoder().decode(uint8Array);
|
116
|
-
} catch (error) {
|
117
|
-
throw new Error("Error decoding Uint8Array to text");
|
118
|
-
}
|
119
|
-
}
|
120
|
-
|
121
|
-
// core/prompt/attachments-to-parts.ts
|
122
|
-
function attachmentsToParts(attachments) {
|
123
|
-
var _a7, _b, _c;
|
124
|
-
const parts = [];
|
125
|
-
for (const attachment of attachments) {
|
126
|
-
let url;
|
127
|
-
try {
|
128
|
-
url = new URL(attachment.url);
|
129
|
-
} catch (error) {
|
130
|
-
throw new Error(`Invalid URL: ${attachment.url}`);
|
131
|
-
}
|
132
|
-
switch (url.protocol) {
|
133
|
-
case "http:":
|
134
|
-
case "https:": {
|
135
|
-
if ((_a7 = attachment.contentType) == null ? void 0 : _a7.startsWith("image/")) {
|
136
|
-
parts.push({ type: "image", image: url });
|
137
|
-
} else {
|
138
|
-
if (!attachment.contentType) {
|
139
|
-
throw new Error(
|
140
|
-
"If the attachment is not an image, it must specify a content type"
|
141
|
-
);
|
142
|
-
}
|
143
|
-
parts.push({
|
144
|
-
type: "file",
|
145
|
-
data: url,
|
146
|
-
mediaType: attachment.contentType
|
147
|
-
});
|
148
|
-
}
|
149
|
-
break;
|
150
|
-
}
|
151
|
-
case "data:": {
|
152
|
-
let header;
|
153
|
-
let base64Content;
|
154
|
-
let mediaType;
|
155
|
-
try {
|
156
|
-
[header, base64Content] = attachment.url.split(",");
|
157
|
-
mediaType = header.split(";")[0].split(":")[1];
|
158
|
-
} catch (error) {
|
159
|
-
throw new Error(`Error processing data URL: ${attachment.url}`);
|
160
|
-
}
|
161
|
-
if (mediaType == null || base64Content == null) {
|
162
|
-
throw new Error(`Invalid data URL format: ${attachment.url}`);
|
163
|
-
}
|
164
|
-
if ((_b = attachment.contentType) == null ? void 0 : _b.startsWith("image/")) {
|
165
|
-
parts.push({
|
166
|
-
type: "image",
|
167
|
-
image: convertDataContentToUint8Array(base64Content)
|
168
|
-
});
|
169
|
-
} else if ((_c = attachment.contentType) == null ? void 0 : _c.startsWith("text/")) {
|
170
|
-
parts.push({
|
171
|
-
type: "text",
|
172
|
-
text: convertUint8ArrayToText(
|
173
|
-
convertDataContentToUint8Array(base64Content)
|
174
|
-
)
|
175
|
-
});
|
176
|
-
} else {
|
177
|
-
if (!attachment.contentType) {
|
178
|
-
throw new Error(
|
179
|
-
"If the attachment is not an image or text, it must specify a content type"
|
180
|
-
);
|
181
|
-
}
|
182
|
-
parts.push({
|
183
|
-
type: "file",
|
184
|
-
data: base64Content,
|
185
|
-
mediaType: attachment.contentType
|
186
|
-
});
|
187
|
-
}
|
188
|
-
break;
|
189
|
-
}
|
190
|
-
default: {
|
191
|
-
throw new Error(`Unsupported URL protocol: ${url.protocol}`);
|
192
|
-
}
|
193
|
-
}
|
194
|
-
}
|
195
|
-
return parts;
|
196
|
-
}
|
197
|
-
|
198
|
-
// core/prompt/message-conversion-error.ts
|
199
|
-
import { AISDKError as AISDKError3 } from "@ai-sdk/provider";
|
200
|
-
var name2 = "AI_MessageConversionError";
|
201
|
-
var marker2 = `vercel.ai.error.${name2}`;
|
202
|
-
var symbol2 = Symbol.for(marker2);
|
203
|
-
var _a2;
|
204
|
-
var MessageConversionError = class extends AISDKError3 {
|
12
|
+
var MessageConversionError = class extends AISDKError {
|
205
13
|
constructor({
|
206
14
|
originalMessage,
|
207
15
|
message
|
208
16
|
}) {
|
209
|
-
super({ name
|
210
|
-
this[
|
17
|
+
super({ name, message });
|
18
|
+
this[_a] = true;
|
211
19
|
this.originalMessage = originalMessage;
|
212
20
|
}
|
213
21
|
static isInstance(error) {
|
214
|
-
return
|
22
|
+
return AISDKError.hasMarker(error, marker);
|
215
23
|
}
|
216
24
|
};
|
217
|
-
|
25
|
+
_a = symbol;
|
218
26
|
|
219
|
-
// core/prompt/convert-to-
|
220
|
-
function
|
221
|
-
var
|
222
|
-
const tools = (
|
27
|
+
// core/prompt/convert-to-model-messages.ts
|
28
|
+
function convertToModelMessages(messages, options) {
|
29
|
+
var _a6, _b;
|
30
|
+
const tools = (_a6 = options == null ? void 0 : options.tools) != null ? _a6 : {};
|
223
31
|
const coreMessages = [];
|
224
32
|
for (let i = 0; i < messages.length; i++) {
|
225
33
|
const message = messages[i];
|
226
34
|
const isLastMessage = i === messages.length - 1;
|
227
|
-
const { role, content
|
35
|
+
const { role, content } = message;
|
228
36
|
switch (role) {
|
229
37
|
case "system": {
|
230
38
|
coreMessages.push({
|
@@ -234,30 +42,24 @@ function convertToCoreMessages(messages, options) {
|
|
234
42
|
break;
|
235
43
|
}
|
236
44
|
case "user": {
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
coreMessages.push({
|
251
|
-
role: "user",
|
252
|
-
content: experimental_attachments ? [...textParts, ...attachmentsToParts(experimental_attachments)] : textParts
|
253
|
-
});
|
254
|
-
}
|
45
|
+
coreMessages.push({
|
46
|
+
role: "user",
|
47
|
+
content: message.parts.filter(
|
48
|
+
(part) => part.type === "text" || part.type === "file"
|
49
|
+
).map(
|
50
|
+
(part) => part.type === "file" ? {
|
51
|
+
type: "file",
|
52
|
+
mediaType: part.mediaType,
|
53
|
+
filename: part.filename,
|
54
|
+
data: part.url
|
55
|
+
} : part
|
56
|
+
)
|
57
|
+
});
|
255
58
|
break;
|
256
59
|
}
|
257
60
|
case "assistant": {
|
258
61
|
if (message.parts != null) {
|
259
62
|
let processBlock2 = function() {
|
260
|
-
var _a8;
|
261
63
|
const content2 = [];
|
262
64
|
for (const part of block) {
|
263
65
|
switch (part.type) {
|
@@ -268,16 +70,15 @@ function convertToCoreMessages(messages, options) {
|
|
268
70
|
case "file": {
|
269
71
|
content2.push({
|
270
72
|
type: "file",
|
271
|
-
|
272
|
-
|
273
|
-
// TODO migration, remove
|
73
|
+
mediaType: part.mediaType,
|
74
|
+
data: part.url
|
274
75
|
});
|
275
76
|
break;
|
276
77
|
}
|
277
78
|
case "reasoning": {
|
278
79
|
content2.push({
|
279
80
|
type: "reasoning",
|
280
|
-
text: part.
|
81
|
+
text: part.text,
|
281
82
|
providerOptions: part.providerMetadata
|
282
83
|
});
|
283
84
|
break;
|
@@ -367,73 +168,11 @@ function convertToCoreMessages(messages, options) {
|
|
367
168
|
processBlock2();
|
368
169
|
break;
|
369
170
|
}
|
370
|
-
const toolInvocations = message.toolInvocations;
|
371
|
-
if (toolInvocations == null || toolInvocations.length === 0) {
|
372
|
-
coreMessages.push({ role: "assistant", content });
|
373
|
-
break;
|
374
|
-
}
|
375
|
-
const maxStep = toolInvocations.reduce((max, toolInvocation) => {
|
376
|
-
var _a8;
|
377
|
-
return Math.max(max, (_a8 = toolInvocation.step) != null ? _a8 : 0);
|
378
|
-
}, 0);
|
379
|
-
for (let i2 = 0; i2 <= maxStep; i2++) {
|
380
|
-
const stepInvocations = toolInvocations.filter(
|
381
|
-
(toolInvocation) => {
|
382
|
-
var _a8;
|
383
|
-
return ((_a8 = toolInvocation.step) != null ? _a8 : 0) === i2;
|
384
|
-
}
|
385
|
-
);
|
386
|
-
if (stepInvocations.length === 0) {
|
387
|
-
continue;
|
388
|
-
}
|
389
|
-
coreMessages.push({
|
390
|
-
role: "assistant",
|
391
|
-
content: [
|
392
|
-
...isLastMessage && content && i2 === 0 ? [{ type: "text", text: content }] : [],
|
393
|
-
...stepInvocations.map(
|
394
|
-
({ toolCallId, toolName, args }) => ({
|
395
|
-
type: "tool-call",
|
396
|
-
toolCallId,
|
397
|
-
toolName,
|
398
|
-
args
|
399
|
-
})
|
400
|
-
)
|
401
|
-
]
|
402
|
-
});
|
403
|
-
coreMessages.push({
|
404
|
-
role: "tool",
|
405
|
-
content: stepInvocations.map((toolInvocation) => {
|
406
|
-
if (!("result" in toolInvocation)) {
|
407
|
-
throw new MessageConversionError({
|
408
|
-
originalMessage: message,
|
409
|
-
message: "ToolInvocation must have a result: " + JSON.stringify(toolInvocation)
|
410
|
-
});
|
411
|
-
}
|
412
|
-
const { toolCallId, toolName, result } = toolInvocation;
|
413
|
-
const tool = tools[toolName];
|
414
|
-
return (tool == null ? void 0 : tool.experimental_toToolResultContent) != null ? {
|
415
|
-
type: "tool-result",
|
416
|
-
toolCallId,
|
417
|
-
toolName,
|
418
|
-
result: tool.experimental_toToolResultContent(result),
|
419
|
-
experimental_content: tool.experimental_toToolResultContent(result)
|
420
|
-
} : {
|
421
|
-
type: "tool-result",
|
422
|
-
toolCallId,
|
423
|
-
toolName,
|
424
|
-
result
|
425
|
-
};
|
426
|
-
})
|
427
|
-
});
|
428
|
-
}
|
429
171
|
if (content && !isLastMessage) {
|
430
172
|
coreMessages.push({ role: "assistant", content });
|
431
173
|
}
|
432
174
|
break;
|
433
175
|
}
|
434
|
-
case "data": {
|
435
|
-
break;
|
436
|
-
}
|
437
176
|
default: {
|
438
177
|
const _exhaustiveCheck = role;
|
439
178
|
throw new MessageConversionError({
|
@@ -486,30 +225,96 @@ function detectSingleMessageCharacteristics(message) {
|
|
486
225
|
import { z as z6 } from "zod";
|
487
226
|
|
488
227
|
// core/types/provider-metadata.ts
|
489
|
-
import { z as
|
228
|
+
import { z as z2 } from "zod";
|
490
229
|
|
491
230
|
// core/types/json-value.ts
|
492
|
-
import { z
|
493
|
-
var jsonValueSchema =
|
494
|
-
() =>
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
231
|
+
import { z } from "zod";
|
232
|
+
var jsonValueSchema = z.lazy(
|
233
|
+
() => z.union([
|
234
|
+
z.null(),
|
235
|
+
z.string(),
|
236
|
+
z.number(),
|
237
|
+
z.boolean(),
|
238
|
+
z.record(z.string(), jsonValueSchema),
|
239
|
+
z.array(jsonValueSchema)
|
501
240
|
])
|
502
241
|
);
|
503
242
|
|
504
243
|
// core/types/provider-metadata.ts
|
505
|
-
var providerMetadataSchema =
|
506
|
-
|
507
|
-
|
244
|
+
var providerMetadataSchema = z2.record(
|
245
|
+
z2.string(),
|
246
|
+
z2.record(z2.string(), jsonValueSchema)
|
508
247
|
);
|
509
248
|
|
510
249
|
// core/prompt/content-part.ts
|
511
250
|
import { z as z5 } from "zod";
|
512
251
|
|
252
|
+
// core/prompt/data-content.ts
|
253
|
+
import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
|
254
|
+
import {
|
255
|
+
convertBase64ToUint8Array,
|
256
|
+
convertUint8ArrayToBase64
|
257
|
+
} from "@ai-sdk/provider-utils";
|
258
|
+
import { z as z3 } from "zod";
|
259
|
+
|
260
|
+
// core/prompt/split-data-url.ts
|
261
|
+
function splitDataUrl(dataUrl) {
|
262
|
+
try {
|
263
|
+
const [header, base64Content] = dataUrl.split(",");
|
264
|
+
return {
|
265
|
+
mediaType: header.split(";")[0].split(":")[1],
|
266
|
+
base64Content
|
267
|
+
};
|
268
|
+
} catch (error) {
|
269
|
+
return {
|
270
|
+
mediaType: void 0,
|
271
|
+
base64Content: void 0
|
272
|
+
};
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
// core/prompt/data-content.ts
|
277
|
+
var dataContentSchema = z3.union([
|
278
|
+
z3.string(),
|
279
|
+
z3.instanceof(Uint8Array),
|
280
|
+
z3.instanceof(ArrayBuffer),
|
281
|
+
z3.custom(
|
282
|
+
// Buffer might not be available in some environments such as CloudFlare:
|
283
|
+
(value) => {
|
284
|
+
var _a6, _b;
|
285
|
+
return (_b = (_a6 = globalThis.Buffer) == null ? void 0 : _a6.isBuffer(value)) != null ? _b : false;
|
286
|
+
},
|
287
|
+
{ message: "Must be a Buffer" }
|
288
|
+
)
|
289
|
+
]);
|
290
|
+
function convertToLanguageModelV2DataContent(content) {
|
291
|
+
if (content instanceof Uint8Array) {
|
292
|
+
return { data: content, mediaType: void 0 };
|
293
|
+
}
|
294
|
+
if (content instanceof ArrayBuffer) {
|
295
|
+
return { data: new Uint8Array(content), mediaType: void 0 };
|
296
|
+
}
|
297
|
+
if (typeof content === "string") {
|
298
|
+
try {
|
299
|
+
content = new URL(content);
|
300
|
+
} catch (error) {
|
301
|
+
}
|
302
|
+
}
|
303
|
+
if (content instanceof URL && content.protocol === "data:") {
|
304
|
+
const { mediaType: dataUrlMediaType, base64Content } = splitDataUrl(
|
305
|
+
content.toString()
|
306
|
+
);
|
307
|
+
if (dataUrlMediaType == null || base64Content == null) {
|
308
|
+
throw new AISDKError2({
|
309
|
+
name: "InvalidDataContentError",
|
310
|
+
message: `Invalid data URL format in content ${content.toString()}`
|
311
|
+
});
|
312
|
+
}
|
313
|
+
return { data: base64Content, mediaType: dataUrlMediaType };
|
314
|
+
}
|
315
|
+
return { data: content, mediaType: void 0 };
|
316
|
+
}
|
317
|
+
|
513
318
|
// core/prompt/tool-result-content.ts
|
514
319
|
import { z as z4 } from "zod";
|
515
320
|
var toolResultContentSchema = z4.array(
|
@@ -533,7 +338,6 @@ var imagePartSchema = z5.object({
|
|
533
338
|
type: z5.literal("image"),
|
534
339
|
image: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
535
340
|
mediaType: z5.string().optional(),
|
536
|
-
mimeType: z5.string().optional(),
|
537
341
|
providerOptions: providerMetadataSchema.optional()
|
538
342
|
});
|
539
343
|
var filePartSchema = z5.object({
|
@@ -541,7 +345,6 @@ var filePartSchema = z5.object({
|
|
541
345
|
data: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
542
346
|
filename: z5.string().optional(),
|
543
347
|
mediaType: z5.string(),
|
544
|
-
mimeType: z5.string().optional(),
|
545
348
|
providerOptions: providerMetadataSchema.optional()
|
546
349
|
});
|
547
350
|
var reasoningPartSchema = z5.object({
|
@@ -567,12 +370,14 @@ var toolResultPartSchema = z5.object({
|
|
567
370
|
});
|
568
371
|
|
569
372
|
// core/prompt/message.ts
|
570
|
-
var
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
373
|
+
var systemModelMessageSchema = z6.object(
|
374
|
+
{
|
375
|
+
role: z6.literal("system"),
|
376
|
+
content: z6.string(),
|
377
|
+
providerOptions: providerMetadataSchema.optional()
|
378
|
+
}
|
379
|
+
);
|
380
|
+
var userModelMessageSchema = z6.object({
|
576
381
|
role: z6.literal("user"),
|
577
382
|
content: z6.union([
|
578
383
|
z6.string(),
|
@@ -580,7 +385,7 @@ var coreUserMessageSchema = z6.object({
|
|
580
385
|
]),
|
581
386
|
providerOptions: providerMetadataSchema.optional()
|
582
387
|
});
|
583
|
-
var
|
388
|
+
var assistantModelMessageSchema = z6.object({
|
584
389
|
role: z6.literal("assistant"),
|
585
390
|
content: z6.union([
|
586
391
|
z6.string(),
|
@@ -595,16 +400,16 @@ var coreAssistantMessageSchema = z6.object({
|
|
595
400
|
]),
|
596
401
|
providerOptions: providerMetadataSchema.optional()
|
597
402
|
});
|
598
|
-
var
|
403
|
+
var toolModelMessageSchema = z6.object({
|
599
404
|
role: z6.literal("tool"),
|
600
405
|
content: z6.array(toolResultPartSchema),
|
601
406
|
providerOptions: providerMetadataSchema.optional()
|
602
407
|
});
|
603
|
-
var
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
408
|
+
var modelMessageSchema = z6.union([
|
409
|
+
systemModelMessageSchema,
|
410
|
+
userModelMessageSchema,
|
411
|
+
assistantModelMessageSchema,
|
412
|
+
toolModelMessageSchema
|
608
413
|
]);
|
609
414
|
|
610
415
|
// core/prompt/standardize-prompt.ts
|
@@ -652,10 +457,10 @@ async function standardizePrompt({
|
|
652
457
|
if (promptType === "other") {
|
653
458
|
throw new InvalidPromptError({
|
654
459
|
prompt,
|
655
|
-
message: "messages must be an array of
|
460
|
+
message: "messages must be an array of ModelMessage or UIMessage"
|
656
461
|
});
|
657
462
|
}
|
658
|
-
const messages = promptType === "ui-messages" ?
|
463
|
+
const messages = promptType === "ui-messages" ? convertToModelMessages(prompt.messages, {
|
659
464
|
tools
|
660
465
|
}) : prompt.messages;
|
661
466
|
if (messages.length === 0) {
|
@@ -666,12 +471,12 @@ async function standardizePrompt({
|
|
666
471
|
}
|
667
472
|
const validationResult = await safeValidateTypes({
|
668
473
|
value: messages,
|
669
|
-
schema: z7.array(
|
474
|
+
schema: z7.array(modelMessageSchema)
|
670
475
|
});
|
671
476
|
if (!validationResult.success) {
|
672
477
|
throw new InvalidPromptError({
|
673
478
|
prompt,
|
674
|
-
message: "messages must be an array of
|
479
|
+
message: "messages must be an array of ModelMessage or UIMessage",
|
675
480
|
cause: validationResult.error
|
676
481
|
});
|
677
482
|
}
|
@@ -685,9 +490,9 @@ async function standardizePrompt({
|
|
685
490
|
|
686
491
|
// core/util/index.ts
|
687
492
|
import {
|
493
|
+
asSchema,
|
688
494
|
generateId,
|
689
|
-
jsonSchema
|
690
|
-
asSchema
|
495
|
+
jsonSchema
|
691
496
|
} from "@ai-sdk/provider-utils";
|
692
497
|
|
693
498
|
// core/util/data-stream-parts.ts
|
@@ -895,9 +700,9 @@ var fileStreamPart = {
|
|
895
700
|
code: "k",
|
896
701
|
name: "file",
|
897
702
|
parse: (value) => {
|
898
|
-
if (value == null || typeof value !== "object" || !("
|
703
|
+
if (value == null || typeof value !== "object" || !("url" in value) || typeof value.url !== "string" || !("mediaType" in value) || typeof value.mediaType !== "string") {
|
899
704
|
throw new Error(
|
900
|
-
'"file" parts expect an object with a "
|
705
|
+
'"file" parts expect an object with a "url" and "mediaType" property.'
|
901
706
|
);
|
902
707
|
}
|
903
708
|
return { type: "file", value };
|
@@ -964,24 +769,24 @@ function prepareToolsAndToolChoice({
|
|
964
769
|
};
|
965
770
|
}
|
966
771
|
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
967
|
-
([
|
772
|
+
([name6]) => activeTools.includes(name6)
|
968
773
|
) : Object.entries(tools);
|
969
774
|
return {
|
970
|
-
tools: filteredTools.map(([
|
775
|
+
tools: filteredTools.map(([name6, tool]) => {
|
971
776
|
const toolType = tool.type;
|
972
777
|
switch (toolType) {
|
973
778
|
case void 0:
|
974
779
|
case "function":
|
975
780
|
return {
|
976
781
|
type: "function",
|
977
|
-
name:
|
782
|
+
name: name6,
|
978
783
|
description: tool.description,
|
979
784
|
parameters: asSchema(tool.parameters).jsonSchema
|
980
785
|
};
|
981
786
|
case "provider-defined":
|
982
787
|
return {
|
983
788
|
type: "provider-defined",
|
984
|
-
name:
|
789
|
+
name: name6,
|
985
790
|
id: tool.id,
|
986
791
|
args: tool.args
|
987
792
|
};
|
@@ -996,58 +801,58 @@ function prepareToolsAndToolChoice({
|
|
996
801
|
}
|
997
802
|
|
998
803
|
// errors/invalid-argument-error.ts
|
999
|
-
import { AISDKError as
|
1000
|
-
var
|
1001
|
-
var
|
1002
|
-
var
|
1003
|
-
var
|
1004
|
-
var InvalidArgumentError = class extends
|
804
|
+
import { AISDKError as AISDKError3 } from "@ai-sdk/provider";
|
805
|
+
var name2 = "AI_InvalidArgumentError";
|
806
|
+
var marker2 = `vercel.ai.error.${name2}`;
|
807
|
+
var symbol2 = Symbol.for(marker2);
|
808
|
+
var _a2;
|
809
|
+
var InvalidArgumentError = class extends AISDKError3 {
|
1005
810
|
constructor({
|
1006
811
|
parameter,
|
1007
812
|
value,
|
1008
813
|
message
|
1009
814
|
}) {
|
1010
815
|
super({
|
1011
|
-
name:
|
816
|
+
name: name2,
|
1012
817
|
message: `Invalid argument for parameter ${parameter}: ${message}`
|
1013
818
|
});
|
1014
|
-
this[
|
819
|
+
this[_a2] = true;
|
1015
820
|
this.parameter = parameter;
|
1016
821
|
this.value = value;
|
1017
822
|
}
|
1018
823
|
static isInstance(error) {
|
1019
|
-
return
|
824
|
+
return AISDKError3.hasMarker(error, marker2);
|
1020
825
|
}
|
1021
826
|
};
|
1022
|
-
|
827
|
+
_a2 = symbol2;
|
1023
828
|
|
1024
829
|
// util/retry-with-exponential-backoff.ts
|
1025
830
|
import { APICallError } from "@ai-sdk/provider";
|
1026
831
|
import { delay, getErrorMessage, isAbortError } from "@ai-sdk/provider-utils";
|
1027
832
|
|
1028
833
|
// util/retry-error.ts
|
1029
|
-
import { AISDKError as
|
1030
|
-
var
|
1031
|
-
var
|
1032
|
-
var
|
1033
|
-
var
|
1034
|
-
var RetryError = class extends
|
834
|
+
import { AISDKError as AISDKError4 } from "@ai-sdk/provider";
|
835
|
+
var name3 = "AI_RetryError";
|
836
|
+
var marker3 = `vercel.ai.error.${name3}`;
|
837
|
+
var symbol3 = Symbol.for(marker3);
|
838
|
+
var _a3;
|
839
|
+
var RetryError = class extends AISDKError4 {
|
1035
840
|
constructor({
|
1036
841
|
message,
|
1037
842
|
reason,
|
1038
843
|
errors
|
1039
844
|
}) {
|
1040
|
-
super({ name:
|
1041
|
-
this[
|
845
|
+
super({ name: name3, message });
|
846
|
+
this[_a3] = true;
|
1042
847
|
this.reason = reason;
|
1043
848
|
this.errors = errors;
|
1044
849
|
this.lastError = errors[errors.length - 1];
|
1045
850
|
}
|
1046
851
|
static isInstance(error) {
|
1047
|
-
return
|
852
|
+
return AISDKError4.hasMarker(error, marker3);
|
1048
853
|
}
|
1049
854
|
};
|
1050
|
-
|
855
|
+
_a3 = symbol3;
|
1051
856
|
|
1052
857
|
// util/retry-with-exponential-backoff.ts
|
1053
858
|
var retryWithExponentialBackoff = ({
|
@@ -1222,13 +1027,16 @@ function prepareCallSettings({
|
|
1222
1027
|
};
|
1223
1028
|
}
|
1224
1029
|
|
1030
|
+
// core/prompt/convert-to-language-model-prompt.ts
|
1031
|
+
import { isUrlSupported } from "@ai-sdk/provider-utils";
|
1032
|
+
|
1225
1033
|
// util/download-error.ts
|
1226
|
-
import { AISDKError as
|
1227
|
-
var
|
1228
|
-
var
|
1229
|
-
var
|
1230
|
-
var
|
1231
|
-
var DownloadError = class extends
|
1034
|
+
import { AISDKError as AISDKError5 } from "@ai-sdk/provider";
|
1035
|
+
var name4 = "AI_DownloadError";
|
1036
|
+
var marker4 = `vercel.ai.error.${name4}`;
|
1037
|
+
var symbol4 = Symbol.for(marker4);
|
1038
|
+
var _a4;
|
1039
|
+
var DownloadError = class extends AISDKError5 {
|
1232
1040
|
constructor({
|
1233
1041
|
url,
|
1234
1042
|
statusCode,
|
@@ -1236,21 +1044,21 @@ var DownloadError = class extends AISDKError6 {
|
|
1236
1044
|
cause,
|
1237
1045
|
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
1238
1046
|
}) {
|
1239
|
-
super({ name:
|
1240
|
-
this[
|
1047
|
+
super({ name: name4, message, cause });
|
1048
|
+
this[_a4] = true;
|
1241
1049
|
this.url = url;
|
1242
1050
|
this.statusCode = statusCode;
|
1243
1051
|
this.statusText = statusText;
|
1244
1052
|
}
|
1245
1053
|
static isInstance(error) {
|
1246
|
-
return
|
1054
|
+
return AISDKError5.hasMarker(error, marker4);
|
1247
1055
|
}
|
1248
1056
|
};
|
1249
|
-
|
1057
|
+
_a4 = symbol4;
|
1250
1058
|
|
1251
1059
|
// util/download.ts
|
1252
1060
|
async function download({ url }) {
|
1253
|
-
var
|
1061
|
+
var _a6;
|
1254
1062
|
const urlText = url.toString();
|
1255
1063
|
try {
|
1256
1064
|
const response = await fetch(urlText);
|
@@ -1263,7 +1071,7 @@ async function download({ url }) {
|
|
1263
1071
|
}
|
1264
1072
|
return {
|
1265
1073
|
data: new Uint8Array(await response.arrayBuffer()),
|
1266
|
-
mediaType: (
|
1074
|
+
mediaType: (_a6 = response.headers.get("content-type")) != null ? _a6 : void 0
|
1267
1075
|
};
|
1268
1076
|
} catch (error) {
|
1269
1077
|
if (DownloadError.isInstance(error)) {
|
@@ -1375,28 +1183,27 @@ function detectMediaType({
|
|
1375
1183
|
}
|
1376
1184
|
|
1377
1185
|
// core/prompt/invalid-message-role-error.ts
|
1378
|
-
import { AISDKError as
|
1379
|
-
var
|
1380
|
-
var
|
1381
|
-
var
|
1382
|
-
var
|
1383
|
-
var InvalidMessageRoleError = class extends
|
1186
|
+
import { AISDKError as AISDKError6 } from "@ai-sdk/provider";
|
1187
|
+
var name5 = "AI_InvalidMessageRoleError";
|
1188
|
+
var marker5 = `vercel.ai.error.${name5}`;
|
1189
|
+
var symbol5 = Symbol.for(marker5);
|
1190
|
+
var _a5;
|
1191
|
+
var InvalidMessageRoleError = class extends AISDKError6 {
|
1384
1192
|
constructor({
|
1385
1193
|
role,
|
1386
1194
|
message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
|
1387
1195
|
}) {
|
1388
|
-
super({ name:
|
1389
|
-
this[
|
1196
|
+
super({ name: name5, message });
|
1197
|
+
this[_a5] = true;
|
1390
1198
|
this.role = role;
|
1391
1199
|
}
|
1392
1200
|
static isInstance(error) {
|
1393
|
-
return
|
1201
|
+
return AISDKError6.hasMarker(error, marker5);
|
1394
1202
|
}
|
1395
1203
|
};
|
1396
|
-
|
1204
|
+
_a5 = symbol5;
|
1397
1205
|
|
1398
1206
|
// core/prompt/convert-to-language-model-prompt.ts
|
1399
|
-
import { isUrlSupported } from "@ai-sdk/provider-utils";
|
1400
1207
|
async function convertToLanguageModelPrompt({
|
1401
1208
|
prompt,
|
1402
1209
|
supportedUrls,
|
@@ -1452,7 +1259,6 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1452
1259
|
// remove empty text parts:
|
1453
1260
|
(part) => part.type !== "text" || part.text !== ""
|
1454
1261
|
).map((part) => {
|
1455
|
-
var _a7;
|
1456
1262
|
const providerOptions = part.providerOptions;
|
1457
1263
|
switch (part.type) {
|
1458
1264
|
case "file": {
|
@@ -1463,7 +1269,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1463
1269
|
type: "file",
|
1464
1270
|
data,
|
1465
1271
|
filename: part.filename,
|
1466
|
-
mediaType:
|
1272
|
+
mediaType: mediaType != null ? mediaType : part.mediaType,
|
1467
1273
|
providerOptions
|
1468
1274
|
};
|
1469
1275
|
}
|
@@ -1522,8 +1328,8 @@ async function downloadAssets(messages, downloadImplementation, supportedUrls) {
|
|
1522
1328
|
).flat().filter(
|
1523
1329
|
(part) => part.type === "image" || part.type === "file"
|
1524
1330
|
).map((part) => {
|
1525
|
-
var
|
1526
|
-
const mediaType = (
|
1331
|
+
var _a6;
|
1332
|
+
const mediaType = (_a6 = part.mediaType) != null ? _a6 : part.type === "image" ? "image/*" : void 0;
|
1527
1333
|
let data = part.type === "image" ? part.image : part.data;
|
1528
1334
|
if (typeof data === "string") {
|
1529
1335
|
try {
|
@@ -1550,7 +1356,7 @@ async function downloadAssets(messages, downloadImplementation, supportedUrls) {
|
|
1550
1356
|
);
|
1551
1357
|
}
|
1552
1358
|
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
1553
|
-
var
|
1359
|
+
var _a6, _b;
|
1554
1360
|
if (part.type === "text") {
|
1555
1361
|
return {
|
1556
1362
|
type: "text",
|
@@ -1571,19 +1377,19 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
1571
1377
|
throw new Error(`Unsupported part type: ${type}`);
|
1572
1378
|
}
|
1573
1379
|
const { data: convertedData, mediaType: convertedMediaType } = convertToLanguageModelV2DataContent(originalData);
|
1574
|
-
let mediaType =
|
1380
|
+
let mediaType = convertedMediaType != null ? convertedMediaType : part.mediaType;
|
1575
1381
|
let data = convertedData;
|
1576
1382
|
if (data instanceof URL) {
|
1577
1383
|
const downloadedFile = downloadedAssets[data.toString()];
|
1578
1384
|
if (downloadedFile) {
|
1579
1385
|
data = downloadedFile.data;
|
1580
|
-
mediaType = (
|
1386
|
+
mediaType = (_a6 = downloadedFile.mediaType) != null ? _a6 : mediaType;
|
1581
1387
|
}
|
1582
1388
|
}
|
1583
1389
|
switch (type) {
|
1584
1390
|
case "image": {
|
1585
1391
|
if (data instanceof Uint8Array || typeof data === "string") {
|
1586
|
-
mediaType = (
|
1392
|
+
mediaType = (_b = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _b : mediaType;
|
1587
1393
|
}
|
1588
1394
|
return {
|
1589
1395
|
type: "file",
|