ai 5.0.0-canary.16 → 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 +40 -0
- package/dist/index.d.mts +105 -75
- package/dist/index.d.ts +105 -75
- package/dist/index.js +168 -215
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +163 -216
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +24 -45
- package/dist/internal/index.d.ts +24 -45
- package/dist/internal/index.js +192 -324
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +185 -317
- package/dist/internal/index.mjs.map +1 -1
- 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,9 +70,8 @@ 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
|
}
|
@@ -424,30 +225,96 @@ function detectSingleMessageCharacteristics(message) {
|
|
424
225
|
import { z as z6 } from "zod";
|
425
226
|
|
426
227
|
// core/types/provider-metadata.ts
|
427
|
-
import { z as
|
228
|
+
import { z as z2 } from "zod";
|
428
229
|
|
429
230
|
// core/types/json-value.ts
|
430
|
-
import { z
|
431
|
-
var jsonValueSchema =
|
432
|
-
() =>
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
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)
|
439
240
|
])
|
440
241
|
);
|
441
242
|
|
442
243
|
// core/types/provider-metadata.ts
|
443
|
-
var providerMetadataSchema =
|
444
|
-
|
445
|
-
|
244
|
+
var providerMetadataSchema = z2.record(
|
245
|
+
z2.string(),
|
246
|
+
z2.record(z2.string(), jsonValueSchema)
|
446
247
|
);
|
447
248
|
|
448
249
|
// core/prompt/content-part.ts
|
449
250
|
import { z as z5 } from "zod";
|
450
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
|
+
|
451
318
|
// core/prompt/tool-result-content.ts
|
452
319
|
import { z as z4 } from "zod";
|
453
320
|
var toolResultContentSchema = z4.array(
|
@@ -471,7 +338,6 @@ var imagePartSchema = z5.object({
|
|
471
338
|
type: z5.literal("image"),
|
472
339
|
image: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
473
340
|
mediaType: z5.string().optional(),
|
474
|
-
mimeType: z5.string().optional(),
|
475
341
|
providerOptions: providerMetadataSchema.optional()
|
476
342
|
});
|
477
343
|
var filePartSchema = z5.object({
|
@@ -479,7 +345,6 @@ var filePartSchema = z5.object({
|
|
479
345
|
data: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
480
346
|
filename: z5.string().optional(),
|
481
347
|
mediaType: z5.string(),
|
482
|
-
mimeType: z5.string().optional(),
|
483
348
|
providerOptions: providerMetadataSchema.optional()
|
484
349
|
});
|
485
350
|
var reasoningPartSchema = z5.object({
|
@@ -505,12 +370,14 @@ var toolResultPartSchema = z5.object({
|
|
505
370
|
});
|
506
371
|
|
507
372
|
// core/prompt/message.ts
|
508
|
-
var
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
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({
|
514
381
|
role: z6.literal("user"),
|
515
382
|
content: z6.union([
|
516
383
|
z6.string(),
|
@@ -518,7 +385,7 @@ var coreUserMessageSchema = z6.object({
|
|
518
385
|
]),
|
519
386
|
providerOptions: providerMetadataSchema.optional()
|
520
387
|
});
|
521
|
-
var
|
388
|
+
var assistantModelMessageSchema = z6.object({
|
522
389
|
role: z6.literal("assistant"),
|
523
390
|
content: z6.union([
|
524
391
|
z6.string(),
|
@@ -533,16 +400,16 @@ var coreAssistantMessageSchema = z6.object({
|
|
533
400
|
]),
|
534
401
|
providerOptions: providerMetadataSchema.optional()
|
535
402
|
});
|
536
|
-
var
|
403
|
+
var toolModelMessageSchema = z6.object({
|
537
404
|
role: z6.literal("tool"),
|
538
405
|
content: z6.array(toolResultPartSchema),
|
539
406
|
providerOptions: providerMetadataSchema.optional()
|
540
407
|
});
|
541
|
-
var
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
408
|
+
var modelMessageSchema = z6.union([
|
409
|
+
systemModelMessageSchema,
|
410
|
+
userModelMessageSchema,
|
411
|
+
assistantModelMessageSchema,
|
412
|
+
toolModelMessageSchema
|
546
413
|
]);
|
547
414
|
|
548
415
|
// core/prompt/standardize-prompt.ts
|
@@ -590,10 +457,10 @@ async function standardizePrompt({
|
|
590
457
|
if (promptType === "other") {
|
591
458
|
throw new InvalidPromptError({
|
592
459
|
prompt,
|
593
|
-
message: "messages must be an array of
|
460
|
+
message: "messages must be an array of ModelMessage or UIMessage"
|
594
461
|
});
|
595
462
|
}
|
596
|
-
const messages = promptType === "ui-messages" ?
|
463
|
+
const messages = promptType === "ui-messages" ? convertToModelMessages(prompt.messages, {
|
597
464
|
tools
|
598
465
|
}) : prompt.messages;
|
599
466
|
if (messages.length === 0) {
|
@@ -604,12 +471,12 @@ async function standardizePrompt({
|
|
604
471
|
}
|
605
472
|
const validationResult = await safeValidateTypes({
|
606
473
|
value: messages,
|
607
|
-
schema: z7.array(
|
474
|
+
schema: z7.array(modelMessageSchema)
|
608
475
|
});
|
609
476
|
if (!validationResult.success) {
|
610
477
|
throw new InvalidPromptError({
|
611
478
|
prompt,
|
612
|
-
message: "messages must be an array of
|
479
|
+
message: "messages must be an array of ModelMessage or UIMessage",
|
613
480
|
cause: validationResult.error
|
614
481
|
});
|
615
482
|
}
|
@@ -623,9 +490,9 @@ async function standardizePrompt({
|
|
623
490
|
|
624
491
|
// core/util/index.ts
|
625
492
|
import {
|
493
|
+
asSchema,
|
626
494
|
generateId,
|
627
|
-
jsonSchema
|
628
|
-
asSchema
|
495
|
+
jsonSchema
|
629
496
|
} from "@ai-sdk/provider-utils";
|
630
497
|
|
631
498
|
// core/util/data-stream-parts.ts
|
@@ -833,9 +700,9 @@ var fileStreamPart = {
|
|
833
700
|
code: "k",
|
834
701
|
name: "file",
|
835
702
|
parse: (value) => {
|
836
|
-
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") {
|
837
704
|
throw new Error(
|
838
|
-
'"file" parts expect an object with a "
|
705
|
+
'"file" parts expect an object with a "url" and "mediaType" property.'
|
839
706
|
);
|
840
707
|
}
|
841
708
|
return { type: "file", value };
|
@@ -902,24 +769,24 @@ function prepareToolsAndToolChoice({
|
|
902
769
|
};
|
903
770
|
}
|
904
771
|
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
905
|
-
([
|
772
|
+
([name6]) => activeTools.includes(name6)
|
906
773
|
) : Object.entries(tools);
|
907
774
|
return {
|
908
|
-
tools: filteredTools.map(([
|
775
|
+
tools: filteredTools.map(([name6, tool]) => {
|
909
776
|
const toolType = tool.type;
|
910
777
|
switch (toolType) {
|
911
778
|
case void 0:
|
912
779
|
case "function":
|
913
780
|
return {
|
914
781
|
type: "function",
|
915
|
-
name:
|
782
|
+
name: name6,
|
916
783
|
description: tool.description,
|
917
784
|
parameters: asSchema(tool.parameters).jsonSchema
|
918
785
|
};
|
919
786
|
case "provider-defined":
|
920
787
|
return {
|
921
788
|
type: "provider-defined",
|
922
|
-
name:
|
789
|
+
name: name6,
|
923
790
|
id: tool.id,
|
924
791
|
args: tool.args
|
925
792
|
};
|
@@ -934,58 +801,58 @@ function prepareToolsAndToolChoice({
|
|
934
801
|
}
|
935
802
|
|
936
803
|
// errors/invalid-argument-error.ts
|
937
|
-
import { AISDKError as
|
938
|
-
var
|
939
|
-
var
|
940
|
-
var
|
941
|
-
var
|
942
|
-
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 {
|
943
810
|
constructor({
|
944
811
|
parameter,
|
945
812
|
value,
|
946
813
|
message
|
947
814
|
}) {
|
948
815
|
super({
|
949
|
-
name:
|
816
|
+
name: name2,
|
950
817
|
message: `Invalid argument for parameter ${parameter}: ${message}`
|
951
818
|
});
|
952
|
-
this[
|
819
|
+
this[_a2] = true;
|
953
820
|
this.parameter = parameter;
|
954
821
|
this.value = value;
|
955
822
|
}
|
956
823
|
static isInstance(error) {
|
957
|
-
return
|
824
|
+
return AISDKError3.hasMarker(error, marker2);
|
958
825
|
}
|
959
826
|
};
|
960
|
-
|
827
|
+
_a2 = symbol2;
|
961
828
|
|
962
829
|
// util/retry-with-exponential-backoff.ts
|
963
830
|
import { APICallError } from "@ai-sdk/provider";
|
964
831
|
import { delay, getErrorMessage, isAbortError } from "@ai-sdk/provider-utils";
|
965
832
|
|
966
833
|
// util/retry-error.ts
|
967
|
-
import { AISDKError as
|
968
|
-
var
|
969
|
-
var
|
970
|
-
var
|
971
|
-
var
|
972
|
-
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 {
|
973
840
|
constructor({
|
974
841
|
message,
|
975
842
|
reason,
|
976
843
|
errors
|
977
844
|
}) {
|
978
|
-
super({ name:
|
979
|
-
this[
|
845
|
+
super({ name: name3, message });
|
846
|
+
this[_a3] = true;
|
980
847
|
this.reason = reason;
|
981
848
|
this.errors = errors;
|
982
849
|
this.lastError = errors[errors.length - 1];
|
983
850
|
}
|
984
851
|
static isInstance(error) {
|
985
|
-
return
|
852
|
+
return AISDKError4.hasMarker(error, marker3);
|
986
853
|
}
|
987
854
|
};
|
988
|
-
|
855
|
+
_a3 = symbol3;
|
989
856
|
|
990
857
|
// util/retry-with-exponential-backoff.ts
|
991
858
|
var retryWithExponentialBackoff = ({
|
@@ -1160,13 +1027,16 @@ function prepareCallSettings({
|
|
1160
1027
|
};
|
1161
1028
|
}
|
1162
1029
|
|
1030
|
+
// core/prompt/convert-to-language-model-prompt.ts
|
1031
|
+
import { isUrlSupported } from "@ai-sdk/provider-utils";
|
1032
|
+
|
1163
1033
|
// util/download-error.ts
|
1164
|
-
import { AISDKError as
|
1165
|
-
var
|
1166
|
-
var
|
1167
|
-
var
|
1168
|
-
var
|
1169
|
-
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 {
|
1170
1040
|
constructor({
|
1171
1041
|
url,
|
1172
1042
|
statusCode,
|
@@ -1174,21 +1044,21 @@ var DownloadError = class extends AISDKError6 {
|
|
1174
1044
|
cause,
|
1175
1045
|
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
1176
1046
|
}) {
|
1177
|
-
super({ name:
|
1178
|
-
this[
|
1047
|
+
super({ name: name4, message, cause });
|
1048
|
+
this[_a4] = true;
|
1179
1049
|
this.url = url;
|
1180
1050
|
this.statusCode = statusCode;
|
1181
1051
|
this.statusText = statusText;
|
1182
1052
|
}
|
1183
1053
|
static isInstance(error) {
|
1184
|
-
return
|
1054
|
+
return AISDKError5.hasMarker(error, marker4);
|
1185
1055
|
}
|
1186
1056
|
};
|
1187
|
-
|
1057
|
+
_a4 = symbol4;
|
1188
1058
|
|
1189
1059
|
// util/download.ts
|
1190
1060
|
async function download({ url }) {
|
1191
|
-
var
|
1061
|
+
var _a6;
|
1192
1062
|
const urlText = url.toString();
|
1193
1063
|
try {
|
1194
1064
|
const response = await fetch(urlText);
|
@@ -1201,7 +1071,7 @@ async function download({ url }) {
|
|
1201
1071
|
}
|
1202
1072
|
return {
|
1203
1073
|
data: new Uint8Array(await response.arrayBuffer()),
|
1204
|
-
mediaType: (
|
1074
|
+
mediaType: (_a6 = response.headers.get("content-type")) != null ? _a6 : void 0
|
1205
1075
|
};
|
1206
1076
|
} catch (error) {
|
1207
1077
|
if (DownloadError.isInstance(error)) {
|
@@ -1313,28 +1183,27 @@ function detectMediaType({
|
|
1313
1183
|
}
|
1314
1184
|
|
1315
1185
|
// core/prompt/invalid-message-role-error.ts
|
1316
|
-
import { AISDKError as
|
1317
|
-
var
|
1318
|
-
var
|
1319
|
-
var
|
1320
|
-
var
|
1321
|
-
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 {
|
1322
1192
|
constructor({
|
1323
1193
|
role,
|
1324
1194
|
message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
|
1325
1195
|
}) {
|
1326
|
-
super({ name:
|
1327
|
-
this[
|
1196
|
+
super({ name: name5, message });
|
1197
|
+
this[_a5] = true;
|
1328
1198
|
this.role = role;
|
1329
1199
|
}
|
1330
1200
|
static isInstance(error) {
|
1331
|
-
return
|
1201
|
+
return AISDKError6.hasMarker(error, marker5);
|
1332
1202
|
}
|
1333
1203
|
};
|
1334
|
-
|
1204
|
+
_a5 = symbol5;
|
1335
1205
|
|
1336
1206
|
// core/prompt/convert-to-language-model-prompt.ts
|
1337
|
-
import { isUrlSupported } from "@ai-sdk/provider-utils";
|
1338
1207
|
async function convertToLanguageModelPrompt({
|
1339
1208
|
prompt,
|
1340
1209
|
supportedUrls,
|
@@ -1390,7 +1259,6 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1390
1259
|
// remove empty text parts:
|
1391
1260
|
(part) => part.type !== "text" || part.text !== ""
|
1392
1261
|
).map((part) => {
|
1393
|
-
var _a7;
|
1394
1262
|
const providerOptions = part.providerOptions;
|
1395
1263
|
switch (part.type) {
|
1396
1264
|
case "file": {
|
@@ -1401,7 +1269,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1401
1269
|
type: "file",
|
1402
1270
|
data,
|
1403
1271
|
filename: part.filename,
|
1404
|
-
mediaType:
|
1272
|
+
mediaType: mediaType != null ? mediaType : part.mediaType,
|
1405
1273
|
providerOptions
|
1406
1274
|
};
|
1407
1275
|
}
|
@@ -1460,8 +1328,8 @@ async function downloadAssets(messages, downloadImplementation, supportedUrls) {
|
|
1460
1328
|
).flat().filter(
|
1461
1329
|
(part) => part.type === "image" || part.type === "file"
|
1462
1330
|
).map((part) => {
|
1463
|
-
var
|
1464
|
-
const mediaType = (
|
1331
|
+
var _a6;
|
1332
|
+
const mediaType = (_a6 = part.mediaType) != null ? _a6 : part.type === "image" ? "image/*" : void 0;
|
1465
1333
|
let data = part.type === "image" ? part.image : part.data;
|
1466
1334
|
if (typeof data === "string") {
|
1467
1335
|
try {
|
@@ -1488,7 +1356,7 @@ async function downloadAssets(messages, downloadImplementation, supportedUrls) {
|
|
1488
1356
|
);
|
1489
1357
|
}
|
1490
1358
|
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
1491
|
-
var
|
1359
|
+
var _a6, _b;
|
1492
1360
|
if (part.type === "text") {
|
1493
1361
|
return {
|
1494
1362
|
type: "text",
|
@@ -1509,19 +1377,19 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
1509
1377
|
throw new Error(`Unsupported part type: ${type}`);
|
1510
1378
|
}
|
1511
1379
|
const { data: convertedData, mediaType: convertedMediaType } = convertToLanguageModelV2DataContent(originalData);
|
1512
|
-
let mediaType =
|
1380
|
+
let mediaType = convertedMediaType != null ? convertedMediaType : part.mediaType;
|
1513
1381
|
let data = convertedData;
|
1514
1382
|
if (data instanceof URL) {
|
1515
1383
|
const downloadedFile = downloadedAssets[data.toString()];
|
1516
1384
|
if (downloadedFile) {
|
1517
1385
|
data = downloadedFile.data;
|
1518
|
-
mediaType = (
|
1386
|
+
mediaType = (_a6 = downloadedFile.mediaType) != null ? _a6 : mediaType;
|
1519
1387
|
}
|
1520
1388
|
}
|
1521
1389
|
switch (type) {
|
1522
1390
|
case "image": {
|
1523
1391
|
if (data instanceof Uint8Array || typeof data === "string") {
|
1524
|
-
mediaType = (
|
1392
|
+
mediaType = (_b = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _b : mediaType;
|
1525
1393
|
}
|
1526
1394
|
return {
|
1527
1395
|
type: "file",
|