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.js
CHANGED
@@ -4,8 +4,8 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
6
|
var __export = (target, all) => {
|
7
|
-
for (var
|
8
|
-
__defProp(target,
|
7
|
+
for (var name6 in all)
|
8
|
+
__defProp(target, name6, { get: all[name6], enumerable: true });
|
9
9
|
};
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
11
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
@@ -36,229 +36,40 @@ __export(internal_exports, {
|
|
36
36
|
module.exports = __toCommonJS(internal_exports);
|
37
37
|
|
38
38
|
// core/prompt/standardize-prompt.ts
|
39
|
-
var
|
39
|
+
var import_provider3 = require("@ai-sdk/provider");
|
40
40
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
41
41
|
var import_zod7 = require("zod");
|
42
42
|
|
43
|
-
// core/prompt/
|
44
|
-
var import_provider2 = require("@ai-sdk/provider");
|
45
|
-
var import_provider_utils = require("@ai-sdk/provider-utils");
|
46
|
-
var import_zod = require("zod");
|
47
|
-
|
48
|
-
// core/prompt/invalid-data-content-error.ts
|
43
|
+
// core/prompt/message-conversion-error.ts
|
49
44
|
var import_provider = require("@ai-sdk/provider");
|
50
|
-
var name = "
|
45
|
+
var name = "AI_MessageConversionError";
|
51
46
|
var marker = `vercel.ai.error.${name}`;
|
52
47
|
var symbol = Symbol.for(marker);
|
53
48
|
var _a;
|
54
|
-
var
|
55
|
-
constructor({
|
56
|
-
content,
|
57
|
-
cause,
|
58
|
-
message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
|
59
|
-
}) {
|
60
|
-
super({ name, message, cause });
|
61
|
-
this[_a] = true;
|
62
|
-
this.content = content;
|
63
|
-
}
|
64
|
-
static isInstance(error) {
|
65
|
-
return import_provider.AISDKError.hasMarker(error, marker);
|
66
|
-
}
|
67
|
-
};
|
68
|
-
_a = symbol;
|
69
|
-
|
70
|
-
// core/prompt/split-data-url.ts
|
71
|
-
function splitDataUrl(dataUrl) {
|
72
|
-
try {
|
73
|
-
const [header, base64Content] = dataUrl.split(",");
|
74
|
-
return {
|
75
|
-
mediaType: header.split(";")[0].split(":")[1],
|
76
|
-
base64Content
|
77
|
-
};
|
78
|
-
} catch (error) {
|
79
|
-
return {
|
80
|
-
mediaType: void 0,
|
81
|
-
base64Content: void 0
|
82
|
-
};
|
83
|
-
}
|
84
|
-
}
|
85
|
-
|
86
|
-
// core/prompt/data-content.ts
|
87
|
-
var dataContentSchema = import_zod.z.union([
|
88
|
-
import_zod.z.string(),
|
89
|
-
import_zod.z.instanceof(Uint8Array),
|
90
|
-
import_zod.z.instanceof(ArrayBuffer),
|
91
|
-
import_zod.z.custom(
|
92
|
-
// Buffer might not be available in some environments such as CloudFlare:
|
93
|
-
(value) => {
|
94
|
-
var _a7, _b;
|
95
|
-
return (_b = (_a7 = globalThis.Buffer) == null ? void 0 : _a7.isBuffer(value)) != null ? _b : false;
|
96
|
-
},
|
97
|
-
{ message: "Must be a Buffer" }
|
98
|
-
)
|
99
|
-
]);
|
100
|
-
function convertToLanguageModelV2DataContent(content) {
|
101
|
-
if (content instanceof Uint8Array) {
|
102
|
-
return { data: content, mediaType: void 0 };
|
103
|
-
}
|
104
|
-
if (content instanceof ArrayBuffer) {
|
105
|
-
return { data: new Uint8Array(content), mediaType: void 0 };
|
106
|
-
}
|
107
|
-
if (typeof content === "string") {
|
108
|
-
try {
|
109
|
-
content = new URL(content);
|
110
|
-
} catch (error) {
|
111
|
-
}
|
112
|
-
}
|
113
|
-
if (content instanceof URL && content.protocol === "data:") {
|
114
|
-
const { mediaType: dataUrlMediaType, base64Content } = splitDataUrl(
|
115
|
-
content.toString()
|
116
|
-
);
|
117
|
-
if (dataUrlMediaType == null || base64Content == null) {
|
118
|
-
throw new import_provider2.AISDKError({
|
119
|
-
name: "InvalidDataContentError",
|
120
|
-
message: `Invalid data URL format in content ${content.toString()}`
|
121
|
-
});
|
122
|
-
}
|
123
|
-
return { data: base64Content, mediaType: dataUrlMediaType };
|
124
|
-
}
|
125
|
-
return { data: content, mediaType: void 0 };
|
126
|
-
}
|
127
|
-
function convertDataContentToUint8Array(content) {
|
128
|
-
if (content instanceof Uint8Array) {
|
129
|
-
return content;
|
130
|
-
}
|
131
|
-
if (typeof content === "string") {
|
132
|
-
try {
|
133
|
-
return (0, import_provider_utils.convertBase64ToUint8Array)(content);
|
134
|
-
} catch (error) {
|
135
|
-
throw new InvalidDataContentError({
|
136
|
-
message: "Invalid data content. Content string is not a base64-encoded media.",
|
137
|
-
content,
|
138
|
-
cause: error
|
139
|
-
});
|
140
|
-
}
|
141
|
-
}
|
142
|
-
if (content instanceof ArrayBuffer) {
|
143
|
-
return new Uint8Array(content);
|
144
|
-
}
|
145
|
-
throw new InvalidDataContentError({ content });
|
146
|
-
}
|
147
|
-
function convertUint8ArrayToText(uint8Array) {
|
148
|
-
try {
|
149
|
-
return new TextDecoder().decode(uint8Array);
|
150
|
-
} catch (error) {
|
151
|
-
throw new Error("Error decoding Uint8Array to text");
|
152
|
-
}
|
153
|
-
}
|
154
|
-
|
155
|
-
// core/prompt/attachments-to-parts.ts
|
156
|
-
function attachmentsToParts(attachments) {
|
157
|
-
var _a7, _b, _c;
|
158
|
-
const parts = [];
|
159
|
-
for (const attachment of attachments) {
|
160
|
-
let url;
|
161
|
-
try {
|
162
|
-
url = new URL(attachment.url);
|
163
|
-
} catch (error) {
|
164
|
-
throw new Error(`Invalid URL: ${attachment.url}`);
|
165
|
-
}
|
166
|
-
switch (url.protocol) {
|
167
|
-
case "http:":
|
168
|
-
case "https:": {
|
169
|
-
if ((_a7 = attachment.contentType) == null ? void 0 : _a7.startsWith("image/")) {
|
170
|
-
parts.push({ type: "image", image: url });
|
171
|
-
} else {
|
172
|
-
if (!attachment.contentType) {
|
173
|
-
throw new Error(
|
174
|
-
"If the attachment is not an image, it must specify a content type"
|
175
|
-
);
|
176
|
-
}
|
177
|
-
parts.push({
|
178
|
-
type: "file",
|
179
|
-
data: url,
|
180
|
-
mediaType: attachment.contentType
|
181
|
-
});
|
182
|
-
}
|
183
|
-
break;
|
184
|
-
}
|
185
|
-
case "data:": {
|
186
|
-
let header;
|
187
|
-
let base64Content;
|
188
|
-
let mediaType;
|
189
|
-
try {
|
190
|
-
[header, base64Content] = attachment.url.split(",");
|
191
|
-
mediaType = header.split(";")[0].split(":")[1];
|
192
|
-
} catch (error) {
|
193
|
-
throw new Error(`Error processing data URL: ${attachment.url}`);
|
194
|
-
}
|
195
|
-
if (mediaType == null || base64Content == null) {
|
196
|
-
throw new Error(`Invalid data URL format: ${attachment.url}`);
|
197
|
-
}
|
198
|
-
if ((_b = attachment.contentType) == null ? void 0 : _b.startsWith("image/")) {
|
199
|
-
parts.push({
|
200
|
-
type: "image",
|
201
|
-
image: convertDataContentToUint8Array(base64Content)
|
202
|
-
});
|
203
|
-
} else if ((_c = attachment.contentType) == null ? void 0 : _c.startsWith("text/")) {
|
204
|
-
parts.push({
|
205
|
-
type: "text",
|
206
|
-
text: convertUint8ArrayToText(
|
207
|
-
convertDataContentToUint8Array(base64Content)
|
208
|
-
)
|
209
|
-
});
|
210
|
-
} else {
|
211
|
-
if (!attachment.contentType) {
|
212
|
-
throw new Error(
|
213
|
-
"If the attachment is not an image or text, it must specify a content type"
|
214
|
-
);
|
215
|
-
}
|
216
|
-
parts.push({
|
217
|
-
type: "file",
|
218
|
-
data: base64Content,
|
219
|
-
mediaType: attachment.contentType
|
220
|
-
});
|
221
|
-
}
|
222
|
-
break;
|
223
|
-
}
|
224
|
-
default: {
|
225
|
-
throw new Error(`Unsupported URL protocol: ${url.protocol}`);
|
226
|
-
}
|
227
|
-
}
|
228
|
-
}
|
229
|
-
return parts;
|
230
|
-
}
|
231
|
-
|
232
|
-
// core/prompt/message-conversion-error.ts
|
233
|
-
var import_provider3 = require("@ai-sdk/provider");
|
234
|
-
var name2 = "AI_MessageConversionError";
|
235
|
-
var marker2 = `vercel.ai.error.${name2}`;
|
236
|
-
var symbol2 = Symbol.for(marker2);
|
237
|
-
var _a2;
|
238
|
-
var MessageConversionError = class extends import_provider3.AISDKError {
|
49
|
+
var MessageConversionError = class extends import_provider.AISDKError {
|
239
50
|
constructor({
|
240
51
|
originalMessage,
|
241
52
|
message
|
242
53
|
}) {
|
243
|
-
super({ name
|
244
|
-
this[
|
54
|
+
super({ name, message });
|
55
|
+
this[_a] = true;
|
245
56
|
this.originalMessage = originalMessage;
|
246
57
|
}
|
247
58
|
static isInstance(error) {
|
248
|
-
return
|
59
|
+
return import_provider.AISDKError.hasMarker(error, marker);
|
249
60
|
}
|
250
61
|
};
|
251
|
-
|
62
|
+
_a = symbol;
|
252
63
|
|
253
|
-
// core/prompt/convert-to-
|
254
|
-
function
|
255
|
-
var
|
256
|
-
const tools = (
|
64
|
+
// core/prompt/convert-to-model-messages.ts
|
65
|
+
function convertToModelMessages(messages, options) {
|
66
|
+
var _a6, _b;
|
67
|
+
const tools = (_a6 = options == null ? void 0 : options.tools) != null ? _a6 : {};
|
257
68
|
const coreMessages = [];
|
258
69
|
for (let i = 0; i < messages.length; i++) {
|
259
70
|
const message = messages[i];
|
260
71
|
const isLastMessage = i === messages.length - 1;
|
261
|
-
const { role, content
|
72
|
+
const { role, content } = message;
|
262
73
|
switch (role) {
|
263
74
|
case "system": {
|
264
75
|
coreMessages.push({
|
@@ -268,30 +79,24 @@ function convertToCoreMessages(messages, options) {
|
|
268
79
|
break;
|
269
80
|
}
|
270
81
|
case "user": {
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
coreMessages.push({
|
285
|
-
role: "user",
|
286
|
-
content: experimental_attachments ? [...textParts, ...attachmentsToParts(experimental_attachments)] : textParts
|
287
|
-
});
|
288
|
-
}
|
82
|
+
coreMessages.push({
|
83
|
+
role: "user",
|
84
|
+
content: message.parts.filter(
|
85
|
+
(part) => part.type === "text" || part.type === "file"
|
86
|
+
).map(
|
87
|
+
(part) => part.type === "file" ? {
|
88
|
+
type: "file",
|
89
|
+
mediaType: part.mediaType,
|
90
|
+
filename: part.filename,
|
91
|
+
data: part.url
|
92
|
+
} : part
|
93
|
+
)
|
94
|
+
});
|
289
95
|
break;
|
290
96
|
}
|
291
97
|
case "assistant": {
|
292
98
|
if (message.parts != null) {
|
293
99
|
let processBlock2 = function() {
|
294
|
-
var _a8;
|
295
100
|
const content2 = [];
|
296
101
|
for (const part of block) {
|
297
102
|
switch (part.type) {
|
@@ -302,16 +107,15 @@ function convertToCoreMessages(messages, options) {
|
|
302
107
|
case "file": {
|
303
108
|
content2.push({
|
304
109
|
type: "file",
|
305
|
-
|
306
|
-
|
307
|
-
// TODO migration, remove
|
110
|
+
mediaType: part.mediaType,
|
111
|
+
data: part.url
|
308
112
|
});
|
309
113
|
break;
|
310
114
|
}
|
311
115
|
case "reasoning": {
|
312
116
|
content2.push({
|
313
117
|
type: "reasoning",
|
314
|
-
text: part.
|
118
|
+
text: part.text,
|
315
119
|
providerOptions: part.providerMetadata
|
316
120
|
});
|
317
121
|
break;
|
@@ -401,73 +205,11 @@ function convertToCoreMessages(messages, options) {
|
|
401
205
|
processBlock2();
|
402
206
|
break;
|
403
207
|
}
|
404
|
-
const toolInvocations = message.toolInvocations;
|
405
|
-
if (toolInvocations == null || toolInvocations.length === 0) {
|
406
|
-
coreMessages.push({ role: "assistant", content });
|
407
|
-
break;
|
408
|
-
}
|
409
|
-
const maxStep = toolInvocations.reduce((max, toolInvocation) => {
|
410
|
-
var _a8;
|
411
|
-
return Math.max(max, (_a8 = toolInvocation.step) != null ? _a8 : 0);
|
412
|
-
}, 0);
|
413
|
-
for (let i2 = 0; i2 <= maxStep; i2++) {
|
414
|
-
const stepInvocations = toolInvocations.filter(
|
415
|
-
(toolInvocation) => {
|
416
|
-
var _a8;
|
417
|
-
return ((_a8 = toolInvocation.step) != null ? _a8 : 0) === i2;
|
418
|
-
}
|
419
|
-
);
|
420
|
-
if (stepInvocations.length === 0) {
|
421
|
-
continue;
|
422
|
-
}
|
423
|
-
coreMessages.push({
|
424
|
-
role: "assistant",
|
425
|
-
content: [
|
426
|
-
...isLastMessage && content && i2 === 0 ? [{ type: "text", text: content }] : [],
|
427
|
-
...stepInvocations.map(
|
428
|
-
({ toolCallId, toolName, args }) => ({
|
429
|
-
type: "tool-call",
|
430
|
-
toolCallId,
|
431
|
-
toolName,
|
432
|
-
args
|
433
|
-
})
|
434
|
-
)
|
435
|
-
]
|
436
|
-
});
|
437
|
-
coreMessages.push({
|
438
|
-
role: "tool",
|
439
|
-
content: stepInvocations.map((toolInvocation) => {
|
440
|
-
if (!("result" in toolInvocation)) {
|
441
|
-
throw new MessageConversionError({
|
442
|
-
originalMessage: message,
|
443
|
-
message: "ToolInvocation must have a result: " + JSON.stringify(toolInvocation)
|
444
|
-
});
|
445
|
-
}
|
446
|
-
const { toolCallId, toolName, result } = toolInvocation;
|
447
|
-
const tool = tools[toolName];
|
448
|
-
return (tool == null ? void 0 : tool.experimental_toToolResultContent) != null ? {
|
449
|
-
type: "tool-result",
|
450
|
-
toolCallId,
|
451
|
-
toolName,
|
452
|
-
result: tool.experimental_toToolResultContent(result),
|
453
|
-
experimental_content: tool.experimental_toToolResultContent(result)
|
454
|
-
} : {
|
455
|
-
type: "tool-result",
|
456
|
-
toolCallId,
|
457
|
-
toolName,
|
458
|
-
result
|
459
|
-
};
|
460
|
-
})
|
461
|
-
});
|
462
|
-
}
|
463
208
|
if (content && !isLastMessage) {
|
464
209
|
coreMessages.push({ role: "assistant", content });
|
465
210
|
}
|
466
211
|
break;
|
467
212
|
}
|
468
|
-
case "data": {
|
469
|
-
break;
|
470
|
-
}
|
471
213
|
default: {
|
472
214
|
const _exhaustiveCheck = role;
|
473
215
|
throw new MessageConversionError({
|
@@ -520,30 +262,93 @@ function detectSingleMessageCharacteristics(message) {
|
|
520
262
|
var import_zod6 = require("zod");
|
521
263
|
|
522
264
|
// core/types/provider-metadata.ts
|
523
|
-
var
|
265
|
+
var import_zod2 = require("zod");
|
524
266
|
|
525
267
|
// core/types/json-value.ts
|
526
|
-
var
|
527
|
-
var jsonValueSchema =
|
528
|
-
() =>
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
268
|
+
var import_zod = require("zod");
|
269
|
+
var jsonValueSchema = import_zod.z.lazy(
|
270
|
+
() => import_zod.z.union([
|
271
|
+
import_zod.z.null(),
|
272
|
+
import_zod.z.string(),
|
273
|
+
import_zod.z.number(),
|
274
|
+
import_zod.z.boolean(),
|
275
|
+
import_zod.z.record(import_zod.z.string(), jsonValueSchema),
|
276
|
+
import_zod.z.array(jsonValueSchema)
|
535
277
|
])
|
536
278
|
);
|
537
279
|
|
538
280
|
// core/types/provider-metadata.ts
|
539
|
-
var providerMetadataSchema =
|
540
|
-
|
541
|
-
|
281
|
+
var providerMetadataSchema = import_zod2.z.record(
|
282
|
+
import_zod2.z.string(),
|
283
|
+
import_zod2.z.record(import_zod2.z.string(), jsonValueSchema)
|
542
284
|
);
|
543
285
|
|
544
286
|
// core/prompt/content-part.ts
|
545
287
|
var import_zod5 = require("zod");
|
546
288
|
|
289
|
+
// core/prompt/data-content.ts
|
290
|
+
var import_provider2 = require("@ai-sdk/provider");
|
291
|
+
var import_provider_utils = require("@ai-sdk/provider-utils");
|
292
|
+
var import_zod3 = require("zod");
|
293
|
+
|
294
|
+
// core/prompt/split-data-url.ts
|
295
|
+
function splitDataUrl(dataUrl) {
|
296
|
+
try {
|
297
|
+
const [header, base64Content] = dataUrl.split(",");
|
298
|
+
return {
|
299
|
+
mediaType: header.split(";")[0].split(":")[1],
|
300
|
+
base64Content
|
301
|
+
};
|
302
|
+
} catch (error) {
|
303
|
+
return {
|
304
|
+
mediaType: void 0,
|
305
|
+
base64Content: void 0
|
306
|
+
};
|
307
|
+
}
|
308
|
+
}
|
309
|
+
|
310
|
+
// core/prompt/data-content.ts
|
311
|
+
var dataContentSchema = import_zod3.z.union([
|
312
|
+
import_zod3.z.string(),
|
313
|
+
import_zod3.z.instanceof(Uint8Array),
|
314
|
+
import_zod3.z.instanceof(ArrayBuffer),
|
315
|
+
import_zod3.z.custom(
|
316
|
+
// Buffer might not be available in some environments such as CloudFlare:
|
317
|
+
(value) => {
|
318
|
+
var _a6, _b;
|
319
|
+
return (_b = (_a6 = globalThis.Buffer) == null ? void 0 : _a6.isBuffer(value)) != null ? _b : false;
|
320
|
+
},
|
321
|
+
{ message: "Must be a Buffer" }
|
322
|
+
)
|
323
|
+
]);
|
324
|
+
function convertToLanguageModelV2DataContent(content) {
|
325
|
+
if (content instanceof Uint8Array) {
|
326
|
+
return { data: content, mediaType: void 0 };
|
327
|
+
}
|
328
|
+
if (content instanceof ArrayBuffer) {
|
329
|
+
return { data: new Uint8Array(content), mediaType: void 0 };
|
330
|
+
}
|
331
|
+
if (typeof content === "string") {
|
332
|
+
try {
|
333
|
+
content = new URL(content);
|
334
|
+
} catch (error) {
|
335
|
+
}
|
336
|
+
}
|
337
|
+
if (content instanceof URL && content.protocol === "data:") {
|
338
|
+
const { mediaType: dataUrlMediaType, base64Content } = splitDataUrl(
|
339
|
+
content.toString()
|
340
|
+
);
|
341
|
+
if (dataUrlMediaType == null || base64Content == null) {
|
342
|
+
throw new import_provider2.AISDKError({
|
343
|
+
name: "InvalidDataContentError",
|
344
|
+
message: `Invalid data URL format in content ${content.toString()}`
|
345
|
+
});
|
346
|
+
}
|
347
|
+
return { data: base64Content, mediaType: dataUrlMediaType };
|
348
|
+
}
|
349
|
+
return { data: content, mediaType: void 0 };
|
350
|
+
}
|
351
|
+
|
547
352
|
// core/prompt/tool-result-content.ts
|
548
353
|
var import_zod4 = require("zod");
|
549
354
|
var toolResultContentSchema = import_zod4.z.array(
|
@@ -567,7 +372,6 @@ var imagePartSchema = import_zod5.z.object({
|
|
567
372
|
type: import_zod5.z.literal("image"),
|
568
373
|
image: import_zod5.z.union([dataContentSchema, import_zod5.z.instanceof(URL)]),
|
569
374
|
mediaType: import_zod5.z.string().optional(),
|
570
|
-
mimeType: import_zod5.z.string().optional(),
|
571
375
|
providerOptions: providerMetadataSchema.optional()
|
572
376
|
});
|
573
377
|
var filePartSchema = import_zod5.z.object({
|
@@ -575,7 +379,6 @@ var filePartSchema = import_zod5.z.object({
|
|
575
379
|
data: import_zod5.z.union([dataContentSchema, import_zod5.z.instanceof(URL)]),
|
576
380
|
filename: import_zod5.z.string().optional(),
|
577
381
|
mediaType: import_zod5.z.string(),
|
578
|
-
mimeType: import_zod5.z.string().optional(),
|
579
382
|
providerOptions: providerMetadataSchema.optional()
|
580
383
|
});
|
581
384
|
var reasoningPartSchema = import_zod5.z.object({
|
@@ -601,12 +404,14 @@ var toolResultPartSchema = import_zod5.z.object({
|
|
601
404
|
});
|
602
405
|
|
603
406
|
// core/prompt/message.ts
|
604
|
-
var
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
407
|
+
var systemModelMessageSchema = import_zod6.z.object(
|
408
|
+
{
|
409
|
+
role: import_zod6.z.literal("system"),
|
410
|
+
content: import_zod6.z.string(),
|
411
|
+
providerOptions: providerMetadataSchema.optional()
|
412
|
+
}
|
413
|
+
);
|
414
|
+
var userModelMessageSchema = import_zod6.z.object({
|
610
415
|
role: import_zod6.z.literal("user"),
|
611
416
|
content: import_zod6.z.union([
|
612
417
|
import_zod6.z.string(),
|
@@ -614,7 +419,7 @@ var coreUserMessageSchema = import_zod6.z.object({
|
|
614
419
|
]),
|
615
420
|
providerOptions: providerMetadataSchema.optional()
|
616
421
|
});
|
617
|
-
var
|
422
|
+
var assistantModelMessageSchema = import_zod6.z.object({
|
618
423
|
role: import_zod6.z.literal("assistant"),
|
619
424
|
content: import_zod6.z.union([
|
620
425
|
import_zod6.z.string(),
|
@@ -629,16 +434,16 @@ var coreAssistantMessageSchema = import_zod6.z.object({
|
|
629
434
|
]),
|
630
435
|
providerOptions: providerMetadataSchema.optional()
|
631
436
|
});
|
632
|
-
var
|
437
|
+
var toolModelMessageSchema = import_zod6.z.object({
|
633
438
|
role: import_zod6.z.literal("tool"),
|
634
439
|
content: import_zod6.z.array(toolResultPartSchema),
|
635
440
|
providerOptions: providerMetadataSchema.optional()
|
636
441
|
});
|
637
|
-
var
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
442
|
+
var modelMessageSchema = import_zod6.z.union([
|
443
|
+
systemModelMessageSchema,
|
444
|
+
userModelMessageSchema,
|
445
|
+
assistantModelMessageSchema,
|
446
|
+
toolModelMessageSchema
|
642
447
|
]);
|
643
448
|
|
644
449
|
// core/prompt/standardize-prompt.ts
|
@@ -647,26 +452,26 @@ async function standardizePrompt({
|
|
647
452
|
tools
|
648
453
|
}) {
|
649
454
|
if (prompt.prompt == null && prompt.messages == null) {
|
650
|
-
throw new
|
455
|
+
throw new import_provider3.InvalidPromptError({
|
651
456
|
prompt,
|
652
457
|
message: "prompt or messages must be defined"
|
653
458
|
});
|
654
459
|
}
|
655
460
|
if (prompt.prompt != null && prompt.messages != null) {
|
656
|
-
throw new
|
461
|
+
throw new import_provider3.InvalidPromptError({
|
657
462
|
prompt,
|
658
463
|
message: "prompt and messages cannot be defined at the same time"
|
659
464
|
});
|
660
465
|
}
|
661
466
|
if (prompt.system != null && typeof prompt.system !== "string") {
|
662
|
-
throw new
|
467
|
+
throw new import_provider3.InvalidPromptError({
|
663
468
|
prompt,
|
664
469
|
message: "system must be a string"
|
665
470
|
});
|
666
471
|
}
|
667
472
|
if (prompt.prompt != null) {
|
668
473
|
if (typeof prompt.prompt !== "string") {
|
669
|
-
throw new
|
474
|
+
throw new import_provider3.InvalidPromptError({
|
670
475
|
prompt,
|
671
476
|
message: "prompt must be a string"
|
672
477
|
});
|
@@ -684,28 +489,28 @@ async function standardizePrompt({
|
|
684
489
|
if (prompt.messages != null) {
|
685
490
|
const promptType = detectPromptType(prompt.messages);
|
686
491
|
if (promptType === "other") {
|
687
|
-
throw new
|
492
|
+
throw new import_provider3.InvalidPromptError({
|
688
493
|
prompt,
|
689
|
-
message: "messages must be an array of
|
494
|
+
message: "messages must be an array of ModelMessage or UIMessage"
|
690
495
|
});
|
691
496
|
}
|
692
|
-
const messages = promptType === "ui-messages" ?
|
497
|
+
const messages = promptType === "ui-messages" ? convertToModelMessages(prompt.messages, {
|
693
498
|
tools
|
694
499
|
}) : prompt.messages;
|
695
500
|
if (messages.length === 0) {
|
696
|
-
throw new
|
501
|
+
throw new import_provider3.InvalidPromptError({
|
697
502
|
prompt,
|
698
503
|
message: "messages must not be empty"
|
699
504
|
});
|
700
505
|
}
|
701
506
|
const validationResult = await (0, import_provider_utils2.safeValidateTypes)({
|
702
507
|
value: messages,
|
703
|
-
schema: import_zod7.z.array(
|
508
|
+
schema: import_zod7.z.array(modelMessageSchema)
|
704
509
|
});
|
705
510
|
if (!validationResult.success) {
|
706
|
-
throw new
|
511
|
+
throw new import_provider3.InvalidPromptError({
|
707
512
|
prompt,
|
708
|
-
message: "messages must be an array of
|
513
|
+
message: "messages must be an array of ModelMessage or UIMessage",
|
709
514
|
cause: validationResult.error
|
710
515
|
});
|
711
516
|
}
|
@@ -925,9 +730,9 @@ var fileStreamPart = {
|
|
925
730
|
code: "k",
|
926
731
|
name: "file",
|
927
732
|
parse: (value) => {
|
928
|
-
if (value == null || typeof value !== "object" || !("
|
733
|
+
if (value == null || typeof value !== "object" || !("url" in value) || typeof value.url !== "string" || !("mediaType" in value) || typeof value.mediaType !== "string") {
|
929
734
|
throw new Error(
|
930
|
-
'"file" parts expect an object with a "
|
735
|
+
'"file" parts expect an object with a "url" and "mediaType" property.'
|
931
736
|
);
|
932
737
|
}
|
933
738
|
return { type: "file", value };
|
@@ -994,24 +799,24 @@ function prepareToolsAndToolChoice({
|
|
994
799
|
};
|
995
800
|
}
|
996
801
|
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
997
|
-
([
|
802
|
+
([name6]) => activeTools.includes(name6)
|
998
803
|
) : Object.entries(tools);
|
999
804
|
return {
|
1000
|
-
tools: filteredTools.map(([
|
805
|
+
tools: filteredTools.map(([name6, tool]) => {
|
1001
806
|
const toolType = tool.type;
|
1002
807
|
switch (toolType) {
|
1003
808
|
case void 0:
|
1004
809
|
case "function":
|
1005
810
|
return {
|
1006
811
|
type: "function",
|
1007
|
-
name:
|
812
|
+
name: name6,
|
1008
813
|
description: tool.description,
|
1009
814
|
parameters: (0, import_provider_utils3.asSchema)(tool.parameters).jsonSchema
|
1010
815
|
};
|
1011
816
|
case "provider-defined":
|
1012
817
|
return {
|
1013
818
|
type: "provider-defined",
|
1014
|
-
name:
|
819
|
+
name: name6,
|
1015
820
|
id: tool.id,
|
1016
821
|
args: tool.args
|
1017
822
|
};
|
@@ -1026,58 +831,58 @@ function prepareToolsAndToolChoice({
|
|
1026
831
|
}
|
1027
832
|
|
1028
833
|
// errors/invalid-argument-error.ts
|
1029
|
-
var
|
1030
|
-
var
|
1031
|
-
var
|
1032
|
-
var
|
1033
|
-
var
|
1034
|
-
var InvalidArgumentError = class extends
|
834
|
+
var import_provider4 = require("@ai-sdk/provider");
|
835
|
+
var name2 = "AI_InvalidArgumentError";
|
836
|
+
var marker2 = `vercel.ai.error.${name2}`;
|
837
|
+
var symbol2 = Symbol.for(marker2);
|
838
|
+
var _a2;
|
839
|
+
var InvalidArgumentError = class extends import_provider4.AISDKError {
|
1035
840
|
constructor({
|
1036
841
|
parameter,
|
1037
842
|
value,
|
1038
843
|
message
|
1039
844
|
}) {
|
1040
845
|
super({
|
1041
|
-
name:
|
846
|
+
name: name2,
|
1042
847
|
message: `Invalid argument for parameter ${parameter}: ${message}`
|
1043
848
|
});
|
1044
|
-
this[
|
849
|
+
this[_a2] = true;
|
1045
850
|
this.parameter = parameter;
|
1046
851
|
this.value = value;
|
1047
852
|
}
|
1048
853
|
static isInstance(error) {
|
1049
|
-
return
|
854
|
+
return import_provider4.AISDKError.hasMarker(error, marker2);
|
1050
855
|
}
|
1051
856
|
};
|
1052
|
-
|
857
|
+
_a2 = symbol2;
|
1053
858
|
|
1054
859
|
// util/retry-with-exponential-backoff.ts
|
1055
|
-
var
|
860
|
+
var import_provider6 = require("@ai-sdk/provider");
|
1056
861
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
1057
862
|
|
1058
863
|
// util/retry-error.ts
|
1059
|
-
var
|
1060
|
-
var
|
1061
|
-
var
|
1062
|
-
var
|
1063
|
-
var
|
1064
|
-
var RetryError = class extends
|
864
|
+
var import_provider5 = require("@ai-sdk/provider");
|
865
|
+
var name3 = "AI_RetryError";
|
866
|
+
var marker3 = `vercel.ai.error.${name3}`;
|
867
|
+
var symbol3 = Symbol.for(marker3);
|
868
|
+
var _a3;
|
869
|
+
var RetryError = class extends import_provider5.AISDKError {
|
1065
870
|
constructor({
|
1066
871
|
message,
|
1067
872
|
reason,
|
1068
873
|
errors
|
1069
874
|
}) {
|
1070
|
-
super({ name:
|
1071
|
-
this[
|
875
|
+
super({ name: name3, message });
|
876
|
+
this[_a3] = true;
|
1072
877
|
this.reason = reason;
|
1073
878
|
this.errors = errors;
|
1074
879
|
this.lastError = errors[errors.length - 1];
|
1075
880
|
}
|
1076
881
|
static isInstance(error) {
|
1077
|
-
return
|
882
|
+
return import_provider5.AISDKError.hasMarker(error, marker3);
|
1078
883
|
}
|
1079
884
|
};
|
1080
|
-
|
885
|
+
_a3 = symbol3;
|
1081
886
|
|
1082
887
|
// util/retry-with-exponential-backoff.ts
|
1083
888
|
var retryWithExponentialBackoff = ({
|
@@ -1113,7 +918,7 @@ async function _retryWithExponentialBackoff(f, {
|
|
1113
918
|
errors: newErrors
|
1114
919
|
});
|
1115
920
|
}
|
1116
|
-
if (error instanceof Error &&
|
921
|
+
if (error instanceof Error && import_provider6.APICallError.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
1117
922
|
await (0, import_provider_utils4.delay)(delayInMs);
|
1118
923
|
return _retryWithExponentialBackoff(
|
1119
924
|
f,
|
@@ -1252,13 +1057,16 @@ function prepareCallSettings({
|
|
1252
1057
|
};
|
1253
1058
|
}
|
1254
1059
|
|
1060
|
+
// core/prompt/convert-to-language-model-prompt.ts
|
1061
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
1062
|
+
|
1255
1063
|
// util/download-error.ts
|
1256
|
-
var
|
1257
|
-
var
|
1258
|
-
var
|
1259
|
-
var
|
1260
|
-
var
|
1261
|
-
var DownloadError = class extends
|
1064
|
+
var import_provider7 = require("@ai-sdk/provider");
|
1065
|
+
var name4 = "AI_DownloadError";
|
1066
|
+
var marker4 = `vercel.ai.error.${name4}`;
|
1067
|
+
var symbol4 = Symbol.for(marker4);
|
1068
|
+
var _a4;
|
1069
|
+
var DownloadError = class extends import_provider7.AISDKError {
|
1262
1070
|
constructor({
|
1263
1071
|
url,
|
1264
1072
|
statusCode,
|
@@ -1266,21 +1074,21 @@ var DownloadError = class extends import_provider8.AISDKError {
|
|
1266
1074
|
cause,
|
1267
1075
|
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
1268
1076
|
}) {
|
1269
|
-
super({ name:
|
1270
|
-
this[
|
1077
|
+
super({ name: name4, message, cause });
|
1078
|
+
this[_a4] = true;
|
1271
1079
|
this.url = url;
|
1272
1080
|
this.statusCode = statusCode;
|
1273
1081
|
this.statusText = statusText;
|
1274
1082
|
}
|
1275
1083
|
static isInstance(error) {
|
1276
|
-
return
|
1084
|
+
return import_provider7.AISDKError.hasMarker(error, marker4);
|
1277
1085
|
}
|
1278
1086
|
};
|
1279
|
-
|
1087
|
+
_a4 = symbol4;
|
1280
1088
|
|
1281
1089
|
// util/download.ts
|
1282
1090
|
async function download({ url }) {
|
1283
|
-
var
|
1091
|
+
var _a6;
|
1284
1092
|
const urlText = url.toString();
|
1285
1093
|
try {
|
1286
1094
|
const response = await fetch(urlText);
|
@@ -1293,7 +1101,7 @@ async function download({ url }) {
|
|
1293
1101
|
}
|
1294
1102
|
return {
|
1295
1103
|
data: new Uint8Array(await response.arrayBuffer()),
|
1296
|
-
mediaType: (
|
1104
|
+
mediaType: (_a6 = response.headers.get("content-type")) != null ? _a6 : void 0
|
1297
1105
|
};
|
1298
1106
|
} catch (error) {
|
1299
1107
|
if (DownloadError.isInstance(error)) {
|
@@ -1405,28 +1213,27 @@ function detectMediaType({
|
|
1405
1213
|
}
|
1406
1214
|
|
1407
1215
|
// core/prompt/invalid-message-role-error.ts
|
1408
|
-
var
|
1409
|
-
var
|
1410
|
-
var
|
1411
|
-
var
|
1412
|
-
var
|
1413
|
-
var InvalidMessageRoleError = class extends
|
1216
|
+
var import_provider8 = require("@ai-sdk/provider");
|
1217
|
+
var name5 = "AI_InvalidMessageRoleError";
|
1218
|
+
var marker5 = `vercel.ai.error.${name5}`;
|
1219
|
+
var symbol5 = Symbol.for(marker5);
|
1220
|
+
var _a5;
|
1221
|
+
var InvalidMessageRoleError = class extends import_provider8.AISDKError {
|
1414
1222
|
constructor({
|
1415
1223
|
role,
|
1416
1224
|
message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
|
1417
1225
|
}) {
|
1418
|
-
super({ name:
|
1419
|
-
this[
|
1226
|
+
super({ name: name5, message });
|
1227
|
+
this[_a5] = true;
|
1420
1228
|
this.role = role;
|
1421
1229
|
}
|
1422
1230
|
static isInstance(error) {
|
1423
|
-
return
|
1231
|
+
return import_provider8.AISDKError.hasMarker(error, marker5);
|
1424
1232
|
}
|
1425
1233
|
};
|
1426
|
-
|
1234
|
+
_a5 = symbol5;
|
1427
1235
|
|
1428
1236
|
// core/prompt/convert-to-language-model-prompt.ts
|
1429
|
-
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
1430
1237
|
async function convertToLanguageModelPrompt({
|
1431
1238
|
prompt,
|
1432
1239
|
supportedUrls,
|
@@ -1482,7 +1289,6 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1482
1289
|
// remove empty text parts:
|
1483
1290
|
(part) => part.type !== "text" || part.text !== ""
|
1484
1291
|
).map((part) => {
|
1485
|
-
var _a7;
|
1486
1292
|
const providerOptions = part.providerOptions;
|
1487
1293
|
switch (part.type) {
|
1488
1294
|
case "file": {
|
@@ -1493,7 +1299,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1493
1299
|
type: "file",
|
1494
1300
|
data,
|
1495
1301
|
filename: part.filename,
|
1496
|
-
mediaType:
|
1302
|
+
mediaType: mediaType != null ? mediaType : part.mediaType,
|
1497
1303
|
providerOptions
|
1498
1304
|
};
|
1499
1305
|
}
|
@@ -1552,8 +1358,8 @@ async function downloadAssets(messages, downloadImplementation, supportedUrls) {
|
|
1552
1358
|
).flat().filter(
|
1553
1359
|
(part) => part.type === "image" || part.type === "file"
|
1554
1360
|
).map((part) => {
|
1555
|
-
var
|
1556
|
-
const mediaType = (
|
1361
|
+
var _a6;
|
1362
|
+
const mediaType = (_a6 = part.mediaType) != null ? _a6 : part.type === "image" ? "image/*" : void 0;
|
1557
1363
|
let data = part.type === "image" ? part.image : part.data;
|
1558
1364
|
if (typeof data === "string") {
|
1559
1365
|
try {
|
@@ -1580,7 +1386,7 @@ async function downloadAssets(messages, downloadImplementation, supportedUrls) {
|
|
1580
1386
|
);
|
1581
1387
|
}
|
1582
1388
|
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
1583
|
-
var
|
1389
|
+
var _a6, _b;
|
1584
1390
|
if (part.type === "text") {
|
1585
1391
|
return {
|
1586
1392
|
type: "text",
|
@@ -1601,19 +1407,19 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
1601
1407
|
throw new Error(`Unsupported part type: ${type}`);
|
1602
1408
|
}
|
1603
1409
|
const { data: convertedData, mediaType: convertedMediaType } = convertToLanguageModelV2DataContent(originalData);
|
1604
|
-
let mediaType =
|
1410
|
+
let mediaType = convertedMediaType != null ? convertedMediaType : part.mediaType;
|
1605
1411
|
let data = convertedData;
|
1606
1412
|
if (data instanceof URL) {
|
1607
1413
|
const downloadedFile = downloadedAssets[data.toString()];
|
1608
1414
|
if (downloadedFile) {
|
1609
1415
|
data = downloadedFile.data;
|
1610
|
-
mediaType = (
|
1416
|
+
mediaType = (_a6 = downloadedFile.mediaType) != null ? _a6 : mediaType;
|
1611
1417
|
}
|
1612
1418
|
}
|
1613
1419
|
switch (type) {
|
1614
1420
|
case "image": {
|
1615
1421
|
if (data instanceof Uint8Array || typeof data === "string") {
|
1616
|
-
mediaType = (
|
1422
|
+
mediaType = (_b = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _b : mediaType;
|
1617
1423
|
}
|
1618
1424
|
return {
|
1619
1425
|
type: "file",
|