ai 3.4.18 → 3.4.20
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 +37 -0
- package/dist/index.d.mts +107 -76
- package/dist/index.d.ts +107 -76
- package/dist/index.js +378 -397
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +364 -386
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -12
- package/rsc/dist/index.d.ts +13 -0
- package/rsc/dist/rsc-server.d.mts +13 -0
- package/rsc/dist/rsc-server.mjs +178 -241
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/test/dist/index.d.mts +3 -1
- package/test/dist/index.d.ts +3 -1
- package/test/dist/index.js +2 -0
- package/test/dist/index.js.map +1 -1
- package/test/dist/index.mjs +2 -0
- package/test/dist/index.mjs.map +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ai",
|
3
|
-
"version": "3.4.
|
3
|
+
"version": "3.4.20",
|
4
4
|
"description": "AI SDK by Vercel - The AI Toolkit for TypeScript and JavaScript",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"sideEffects": false,
|
@@ -64,20 +64,19 @@
|
|
64
64
|
}
|
65
65
|
},
|
66
66
|
"dependencies": {
|
67
|
-
"@ai-sdk/provider": "0.0.
|
68
|
-
"@ai-sdk/provider-utils": "1.0.
|
69
|
-
"@ai-sdk/react": "0.0.
|
70
|
-
"@ai-sdk/solid": "0.0.
|
71
|
-
"@ai-sdk/svelte": "0.0.
|
72
|
-
"@ai-sdk/ui-utils": "0.0.
|
73
|
-
"@ai-sdk/vue": "0.0.
|
67
|
+
"@ai-sdk/provider": "0.0.26",
|
68
|
+
"@ai-sdk/provider-utils": "1.0.22",
|
69
|
+
"@ai-sdk/react": "0.0.66",
|
70
|
+
"@ai-sdk/solid": "0.0.52",
|
71
|
+
"@ai-sdk/svelte": "0.0.54",
|
72
|
+
"@ai-sdk/ui-utils": "0.0.48",
|
73
|
+
"@ai-sdk/vue": "0.0.57",
|
74
74
|
"@opentelemetry/api": "1.9.0",
|
75
75
|
"eventsource-parser": "1.1.2",
|
76
76
|
"jsondiffpatch": "0.6.0",
|
77
|
-
"json-schema": "0.4.0",
|
78
|
-
"
|
79
|
-
"
|
80
|
-
"zod-to-json-schema": "3.23.2"
|
77
|
+
"json-schema": "^0.4.0",
|
78
|
+
"secure-json-parse": "^2.7.0",
|
79
|
+
"zod-to-json-schema": "^3.23.3"
|
81
80
|
},
|
82
81
|
"devDependencies": {
|
83
82
|
"@anthropic-ai/sdk": "0.18.0",
|
package/rsc/dist/index.d.ts
CHANGED
@@ -234,6 +234,15 @@ Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffe
|
|
234
234
|
*/
|
235
235
|
type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
236
236
|
|
237
|
+
type ToolResultContent = Array<{
|
238
|
+
type: 'text';
|
239
|
+
text: string;
|
240
|
+
} | {
|
241
|
+
type: 'image';
|
242
|
+
data: string;
|
243
|
+
mimeType?: string;
|
244
|
+
}>;
|
245
|
+
|
237
246
|
/**
|
238
247
|
Text content part of a prompt. It contains a string of text.
|
239
248
|
*/
|
@@ -338,6 +347,10 @@ interface ToolResultPart {
|
|
338
347
|
*/
|
339
348
|
result: unknown;
|
340
349
|
/**
|
350
|
+
Multi-part content of the tool result. Only for tools that support multipart results.
|
351
|
+
*/
|
352
|
+
experimental_content?: ToolResultContent;
|
353
|
+
/**
|
341
354
|
Optional flag if the result is an error or an error message.
|
342
355
|
*/
|
343
356
|
isError?: boolean;
|
@@ -232,6 +232,15 @@ Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffe
|
|
232
232
|
*/
|
233
233
|
type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
234
234
|
|
235
|
+
type ToolResultContent = Array<{
|
236
|
+
type: 'text';
|
237
|
+
text: string;
|
238
|
+
} | {
|
239
|
+
type: 'image';
|
240
|
+
data: string;
|
241
|
+
mimeType?: string;
|
242
|
+
}>;
|
243
|
+
|
235
244
|
/**
|
236
245
|
Text content part of a prompt. It contains a string of text.
|
237
246
|
*/
|
@@ -336,6 +345,10 @@ interface ToolResultPart {
|
|
336
345
|
*/
|
337
346
|
result: unknown;
|
338
347
|
/**
|
348
|
+
Multi-part content of the tool result. Only for tools that support multipart results.
|
349
|
+
*/
|
350
|
+
experimental_content?: ToolResultContent;
|
351
|
+
/**
|
339
352
|
Optional flag if the result is an error or an error message.
|
340
353
|
*/
|
341
354
|
isError?: boolean;
|
package/rsc/dist/rsc-server.mjs
CHANGED
@@ -213,12 +213,6 @@ function createAI({
|
|
213
213
|
// rsc/stream-ui/stream-ui.tsx
|
214
214
|
import { safeParseJSON } from "@ai-sdk/provider-utils";
|
215
215
|
|
216
|
-
// core/prompt/convert-to-language-model-prompt.ts
|
217
|
-
import {
|
218
|
-
convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
|
219
|
-
getErrorMessage
|
220
|
-
} from "@ai-sdk/provider-utils";
|
221
|
-
|
222
216
|
// util/download-error.ts
|
223
217
|
import { AISDKError } from "@ai-sdk/provider";
|
224
218
|
var name = "AI_DownloadError";
|
@@ -457,19 +451,21 @@ function splitDataUrl(dataUrl) {
|
|
457
451
|
async function convertToLanguageModelPrompt({
|
458
452
|
prompt,
|
459
453
|
modelSupportsImageUrls = true,
|
454
|
+
modelSupportsUrl = () => false,
|
460
455
|
downloadImplementation = download
|
461
456
|
}) {
|
462
|
-
const downloadedAssets =
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
457
|
+
const downloadedAssets = await downloadAssets(
|
458
|
+
prompt.messages,
|
459
|
+
downloadImplementation,
|
460
|
+
modelSupportsImageUrls,
|
461
|
+
modelSupportsUrl
|
462
|
+
);
|
463
|
+
return [
|
464
|
+
...prompt.system != null ? [{ role: "system", content: prompt.system }] : [],
|
468
465
|
...prompt.messages.map(
|
469
466
|
(message) => convertToLanguageModelMessage(message, downloadedAssets)
|
470
467
|
)
|
471
|
-
|
472
|
-
return languageModelMessages;
|
468
|
+
];
|
473
469
|
}
|
474
470
|
function convertToLanguageModelMessage(message, downloadedAssets) {
|
475
471
|
const role = message.role;
|
@@ -491,178 +487,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
491
487
|
}
|
492
488
|
return {
|
493
489
|
role: "user",
|
494
|
-
content: message.content.map(
|
495
|
-
(part) => {
|
496
|
-
var _a8, _b, _c, _d, _e;
|
497
|
-
switch (part.type) {
|
498
|
-
case "text": {
|
499
|
-
return {
|
500
|
-
type: "text",
|
501
|
-
text: part.text,
|
502
|
-
providerMetadata: part.experimental_providerMetadata
|
503
|
-
};
|
504
|
-
}
|
505
|
-
case "image": {
|
506
|
-
if (part.image instanceof URL) {
|
507
|
-
if (downloadedAssets == null) {
|
508
|
-
return {
|
509
|
-
type: "image",
|
510
|
-
image: part.image,
|
511
|
-
mimeType: part.mimeType,
|
512
|
-
providerMetadata: part.experimental_providerMetadata
|
513
|
-
};
|
514
|
-
} else {
|
515
|
-
const downloadedImage = downloadedAssets[part.image.toString()];
|
516
|
-
return {
|
517
|
-
type: "image",
|
518
|
-
image: downloadedImage.data,
|
519
|
-
mimeType: (_a8 = part.mimeType) != null ? _a8 : downloadedImage.mimeType,
|
520
|
-
providerMetadata: part.experimental_providerMetadata
|
521
|
-
};
|
522
|
-
}
|
523
|
-
}
|
524
|
-
if (typeof part.image === "string") {
|
525
|
-
try {
|
526
|
-
const url = new URL(part.image);
|
527
|
-
switch (url.protocol) {
|
528
|
-
case "http:":
|
529
|
-
case "https:": {
|
530
|
-
if (downloadedAssets == null) {
|
531
|
-
return {
|
532
|
-
type: "image",
|
533
|
-
image: url,
|
534
|
-
mimeType: part.mimeType,
|
535
|
-
providerMetadata: part.experimental_providerMetadata
|
536
|
-
};
|
537
|
-
} else {
|
538
|
-
const downloadedImage = downloadedAssets[url.toString()];
|
539
|
-
return {
|
540
|
-
type: "image",
|
541
|
-
image: downloadedImage.data,
|
542
|
-
mimeType: (_b = part.mimeType) != null ? _b : downloadedImage.mimeType,
|
543
|
-
providerMetadata: part.experimental_providerMetadata
|
544
|
-
};
|
545
|
-
}
|
546
|
-
}
|
547
|
-
case "data:": {
|
548
|
-
try {
|
549
|
-
const { mimeType, base64Content } = splitDataUrl(
|
550
|
-
part.image
|
551
|
-
);
|
552
|
-
if (mimeType == null || base64Content == null) {
|
553
|
-
throw new Error("Invalid data URL format");
|
554
|
-
}
|
555
|
-
return {
|
556
|
-
type: "image",
|
557
|
-
image: convertDataContentToUint8Array(base64Content),
|
558
|
-
mimeType,
|
559
|
-
providerMetadata: part.experimental_providerMetadata
|
560
|
-
};
|
561
|
-
} catch (error) {
|
562
|
-
throw new Error(
|
563
|
-
`Error processing data URL: ${getErrorMessage(
|
564
|
-
message
|
565
|
-
)}`
|
566
|
-
);
|
567
|
-
}
|
568
|
-
}
|
569
|
-
}
|
570
|
-
} catch (_ignored) {
|
571
|
-
}
|
572
|
-
}
|
573
|
-
const imageUint8 = convertDataContentToUint8Array(part.image);
|
574
|
-
return {
|
575
|
-
type: "image",
|
576
|
-
image: imageUint8,
|
577
|
-
mimeType: (_c = part.mimeType) != null ? _c : detectImageMimeType(imageUint8),
|
578
|
-
providerMetadata: part.experimental_providerMetadata
|
579
|
-
};
|
580
|
-
}
|
581
|
-
case "file": {
|
582
|
-
if (part.data instanceof URL) {
|
583
|
-
if (downloadedAssets == null) {
|
584
|
-
return {
|
585
|
-
type: "file",
|
586
|
-
data: part.data,
|
587
|
-
mimeType: part.mimeType,
|
588
|
-
providerMetadata: part.experimental_providerMetadata
|
589
|
-
};
|
590
|
-
} else {
|
591
|
-
const downloadedImage = downloadedAssets[part.data.toString()];
|
592
|
-
return {
|
593
|
-
type: "file",
|
594
|
-
data: convertUint8ArrayToBase642(downloadedImage.data),
|
595
|
-
mimeType: (_d = part.mimeType) != null ? _d : downloadedImage.mimeType,
|
596
|
-
providerMetadata: part.experimental_providerMetadata
|
597
|
-
};
|
598
|
-
}
|
599
|
-
}
|
600
|
-
if (typeof part.data === "string") {
|
601
|
-
try {
|
602
|
-
const url = new URL(part.data);
|
603
|
-
switch (url.protocol) {
|
604
|
-
case "http:":
|
605
|
-
case "https:": {
|
606
|
-
if (downloadedAssets == null) {
|
607
|
-
return {
|
608
|
-
type: "file",
|
609
|
-
data: url,
|
610
|
-
mimeType: part.mimeType,
|
611
|
-
providerMetadata: part.experimental_providerMetadata
|
612
|
-
};
|
613
|
-
} else {
|
614
|
-
const downloadedImage = downloadedAssets[url.toString()];
|
615
|
-
return {
|
616
|
-
type: "file",
|
617
|
-
data: convertUint8ArrayToBase642(
|
618
|
-
downloadedImage.data
|
619
|
-
),
|
620
|
-
mimeType: (_e = part.mimeType) != null ? _e : downloadedImage.mimeType,
|
621
|
-
providerMetadata: part.experimental_providerMetadata
|
622
|
-
};
|
623
|
-
}
|
624
|
-
}
|
625
|
-
case "data:": {
|
626
|
-
try {
|
627
|
-
const { mimeType, base64Content } = splitDataUrl(
|
628
|
-
part.data
|
629
|
-
);
|
630
|
-
if (mimeType == null || base64Content == null) {
|
631
|
-
throw new Error("Invalid data URL format");
|
632
|
-
}
|
633
|
-
return {
|
634
|
-
type: "file",
|
635
|
-
data: convertDataContentToBase64String(
|
636
|
-
base64Content
|
637
|
-
),
|
638
|
-
mimeType,
|
639
|
-
providerMetadata: part.experimental_providerMetadata
|
640
|
-
};
|
641
|
-
} catch (error) {
|
642
|
-
throw new Error(
|
643
|
-
`Error processing data URL: ${getErrorMessage(
|
644
|
-
message
|
645
|
-
)}`
|
646
|
-
);
|
647
|
-
}
|
648
|
-
}
|
649
|
-
}
|
650
|
-
} catch (_ignored) {
|
651
|
-
}
|
652
|
-
}
|
653
|
-
const imageBase64 = convertDataContentToBase64String(
|
654
|
-
part.data
|
655
|
-
);
|
656
|
-
return {
|
657
|
-
type: "file",
|
658
|
-
data: imageBase64,
|
659
|
-
mimeType: part.mimeType,
|
660
|
-
providerMetadata: part.experimental_providerMetadata
|
661
|
-
};
|
662
|
-
}
|
663
|
-
}
|
664
|
-
}
|
665
|
-
).filter((part) => part.type !== "text" || part.text !== ""),
|
490
|
+
content: message.content.map((part) => convertPartToLanguageModelPart(part, downloadedAssets)).filter((part) => part.type !== "text" || part.text !== ""),
|
666
491
|
providerMetadata: message.experimental_providerMetadata
|
667
492
|
};
|
668
493
|
}
|
@@ -697,6 +522,8 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
697
522
|
toolCallId: part.toolCallId,
|
698
523
|
toolName: part.toolName,
|
699
524
|
result: part.result,
|
525
|
+
content: part.experimental_content,
|
526
|
+
isError: part.isError,
|
700
527
|
providerMetadata: part.experimental_providerMetadata
|
701
528
|
})),
|
702
529
|
providerMetadata: message.experimental_providerMetadata
|
@@ -708,17 +535,19 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
708
535
|
}
|
709
536
|
}
|
710
537
|
}
|
711
|
-
async function downloadAssets(messages, downloadImplementation) {
|
538
|
+
async function downloadAssets(messages, downloadImplementation, modelSupportsImageUrls, modelSupportsUrl) {
|
712
539
|
const urls = messages.filter((message) => message.role === "user").map((message) => message.content).filter(
|
713
540
|
(content) => Array.isArray(content)
|
714
541
|
).flat().filter(
|
715
542
|
(part) => part.type === "image" || part.type === "file"
|
543
|
+
).filter(
|
544
|
+
(part) => !(part.type === "image" && modelSupportsImageUrls === true)
|
716
545
|
).map((part) => part.type === "image" ? part.image : part.data).map(
|
717
546
|
(part) => (
|
718
547
|
// support string urls:
|
719
548
|
typeof part === "string" && (part.startsWith("http:") || part.startsWith("https:")) ? new URL(part) : part
|
720
549
|
)
|
721
|
-
).filter((image) => image instanceof URL);
|
550
|
+
).filter((image) => image instanceof URL).filter((url) => !modelSupportsUrl(url));
|
722
551
|
const downloadedImages = await Promise.all(
|
723
552
|
urls.map(async (url) => ({
|
724
553
|
url,
|
@@ -729,6 +558,79 @@ async function downloadAssets(messages, downloadImplementation) {
|
|
729
558
|
downloadedImages.map(({ url, data }) => [url.toString(), data])
|
730
559
|
);
|
731
560
|
}
|
561
|
+
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
562
|
+
if (part.type === "text") {
|
563
|
+
return {
|
564
|
+
type: "text",
|
565
|
+
text: part.text,
|
566
|
+
providerMetadata: part.experimental_providerMetadata
|
567
|
+
};
|
568
|
+
}
|
569
|
+
let mimeType = part.mimeType;
|
570
|
+
let data;
|
571
|
+
let content;
|
572
|
+
let normalizedData;
|
573
|
+
const type = part.type;
|
574
|
+
switch (type) {
|
575
|
+
case "image":
|
576
|
+
data = part.image;
|
577
|
+
break;
|
578
|
+
case "file":
|
579
|
+
data = part.data;
|
580
|
+
break;
|
581
|
+
default:
|
582
|
+
throw new Error(`Unsupported part type: ${type}`);
|
583
|
+
}
|
584
|
+
try {
|
585
|
+
content = typeof data === "string" ? new URL(data) : data;
|
586
|
+
} catch (error) {
|
587
|
+
content = data;
|
588
|
+
}
|
589
|
+
if (content instanceof URL) {
|
590
|
+
if (content.protocol === "data:") {
|
591
|
+
const { mimeType: dataUrlMimeType, base64Content } = splitDataUrl(
|
592
|
+
content.toString()
|
593
|
+
);
|
594
|
+
if (dataUrlMimeType == null || base64Content == null) {
|
595
|
+
throw new Error(`Invalid data URL format in part ${type}`);
|
596
|
+
}
|
597
|
+
mimeType = dataUrlMimeType;
|
598
|
+
normalizedData = convertDataContentToUint8Array(base64Content);
|
599
|
+
} else {
|
600
|
+
const downloadedFile = downloadedAssets[content.toString()];
|
601
|
+
if (downloadedFile) {
|
602
|
+
normalizedData = downloadedFile.data;
|
603
|
+
mimeType != null ? mimeType : mimeType = downloadedFile.mimeType;
|
604
|
+
} else {
|
605
|
+
normalizedData = content;
|
606
|
+
}
|
607
|
+
}
|
608
|
+
} else {
|
609
|
+
normalizedData = convertDataContentToUint8Array(content);
|
610
|
+
}
|
611
|
+
switch (type) {
|
612
|
+
case "image":
|
613
|
+
if (mimeType == null && normalizedData instanceof Uint8Array) {
|
614
|
+
mimeType = detectImageMimeType(normalizedData);
|
615
|
+
}
|
616
|
+
return {
|
617
|
+
type: "image",
|
618
|
+
image: normalizedData,
|
619
|
+
mimeType,
|
620
|
+
providerMetadata: part.experimental_providerMetadata
|
621
|
+
};
|
622
|
+
case "file":
|
623
|
+
if (mimeType == null) {
|
624
|
+
throw new Error(`Mime type is missing for file part`);
|
625
|
+
}
|
626
|
+
return {
|
627
|
+
type: "file",
|
628
|
+
data: normalizedData instanceof Uint8Array ? convertDataContentToBase64String(normalizedData) : normalizedData,
|
629
|
+
mimeType,
|
630
|
+
providerMetadata: part.experimental_providerMetadata
|
631
|
+
};
|
632
|
+
}
|
633
|
+
}
|
732
634
|
|
733
635
|
// errors/invalid-argument-error.ts
|
734
636
|
import { AISDKError as AISDKError4 } from "@ai-sdk/provider";
|
@@ -906,12 +808,30 @@ function prepareToolsAndToolChoice({
|
|
906
808
|
([name8]) => activeTools.includes(name8)
|
907
809
|
) : Object.entries(tools);
|
908
810
|
return {
|
909
|
-
tools: filteredTools.map(([name8, tool]) =>
|
910
|
-
type
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
811
|
+
tools: filteredTools.map(([name8, tool]) => {
|
812
|
+
const toolType = tool.type;
|
813
|
+
switch (toolType) {
|
814
|
+
case void 0:
|
815
|
+
case "function":
|
816
|
+
return {
|
817
|
+
type: "function",
|
818
|
+
name: name8,
|
819
|
+
description: tool.description,
|
820
|
+
parameters: asSchema(tool.parameters).jsonSchema
|
821
|
+
};
|
822
|
+
case "provider-defined":
|
823
|
+
return {
|
824
|
+
type: "provider-defined",
|
825
|
+
name: name8,
|
826
|
+
id: tool.id,
|
827
|
+
args: tool.args
|
828
|
+
};
|
829
|
+
default: {
|
830
|
+
const exhaustiveCheck = toolType;
|
831
|
+
throw new Error(`Unsupported tool type: ${exhaustiveCheck}`);
|
832
|
+
}
|
833
|
+
}
|
834
|
+
}),
|
915
835
|
toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
|
916
836
|
};
|
917
837
|
}
|
@@ -919,10 +839,10 @@ function prepareToolsAndToolChoice({
|
|
919
839
|
// core/prompt/standardize-prompt.ts
|
920
840
|
import { InvalidPromptError } from "@ai-sdk/provider";
|
921
841
|
import { safeValidateTypes } from "@ai-sdk/provider-utils";
|
922
|
-
import { z as
|
842
|
+
import { z as z7 } from "zod";
|
923
843
|
|
924
844
|
// core/prompt/message.ts
|
925
|
-
import { z as
|
845
|
+
import { z as z6 } from "zod";
|
926
846
|
|
927
847
|
// core/types/provider-metadata.ts
|
928
848
|
import { z as z3 } from "zod";
|
@@ -947,67 +867,83 @@ var providerMetadataSchema = z3.record(
|
|
947
867
|
);
|
948
868
|
|
949
869
|
// core/prompt/content-part.ts
|
870
|
+
import { z as z5 } from "zod";
|
871
|
+
|
872
|
+
// core/prompt/tool-result-content.ts
|
950
873
|
import { z as z4 } from "zod";
|
951
|
-
var
|
952
|
-
|
953
|
-
|
874
|
+
var toolResultContentSchema = z4.array(
|
875
|
+
z4.union([
|
876
|
+
z4.object({ type: z4.literal("text"), text: z4.string() }),
|
877
|
+
z4.object({
|
878
|
+
type: z4.literal("image"),
|
879
|
+
data: z4.string(),
|
880
|
+
mimeType: z4.string().optional()
|
881
|
+
})
|
882
|
+
])
|
883
|
+
);
|
884
|
+
|
885
|
+
// core/prompt/content-part.ts
|
886
|
+
var textPartSchema = z5.object({
|
887
|
+
type: z5.literal("text"),
|
888
|
+
text: z5.string(),
|
954
889
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
955
890
|
});
|
956
|
-
var imagePartSchema =
|
957
|
-
type:
|
958
|
-
image:
|
959
|
-
mimeType:
|
891
|
+
var imagePartSchema = z5.object({
|
892
|
+
type: z5.literal("image"),
|
893
|
+
image: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
894
|
+
mimeType: z5.string().optional(),
|
960
895
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
961
896
|
});
|
962
|
-
var filePartSchema =
|
963
|
-
type:
|
964
|
-
data:
|
965
|
-
mimeType:
|
897
|
+
var filePartSchema = z5.object({
|
898
|
+
type: z5.literal("file"),
|
899
|
+
data: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
900
|
+
mimeType: z5.string(),
|
966
901
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
967
902
|
});
|
968
|
-
var toolCallPartSchema =
|
969
|
-
type:
|
970
|
-
toolCallId:
|
971
|
-
toolName:
|
972
|
-
args:
|
903
|
+
var toolCallPartSchema = z5.object({
|
904
|
+
type: z5.literal("tool-call"),
|
905
|
+
toolCallId: z5.string(),
|
906
|
+
toolName: z5.string(),
|
907
|
+
args: z5.unknown()
|
973
908
|
});
|
974
|
-
var toolResultPartSchema =
|
975
|
-
type:
|
976
|
-
toolCallId:
|
977
|
-
toolName:
|
978
|
-
result:
|
979
|
-
|
909
|
+
var toolResultPartSchema = z5.object({
|
910
|
+
type: z5.literal("tool-result"),
|
911
|
+
toolCallId: z5.string(),
|
912
|
+
toolName: z5.string(),
|
913
|
+
result: z5.unknown(),
|
914
|
+
content: toolResultContentSchema.optional(),
|
915
|
+
isError: z5.boolean().optional(),
|
980
916
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
981
917
|
});
|
982
918
|
|
983
919
|
// core/prompt/message.ts
|
984
|
-
var coreSystemMessageSchema =
|
985
|
-
role:
|
986
|
-
content:
|
920
|
+
var coreSystemMessageSchema = z6.object({
|
921
|
+
role: z6.literal("system"),
|
922
|
+
content: z6.string(),
|
987
923
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
988
924
|
});
|
989
|
-
var coreUserMessageSchema =
|
990
|
-
role:
|
991
|
-
content:
|
992
|
-
|
993
|
-
|
925
|
+
var coreUserMessageSchema = z6.object({
|
926
|
+
role: z6.literal("user"),
|
927
|
+
content: z6.union([
|
928
|
+
z6.string(),
|
929
|
+
z6.array(z6.union([textPartSchema, imagePartSchema, filePartSchema]))
|
994
930
|
]),
|
995
931
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
996
932
|
});
|
997
|
-
var coreAssistantMessageSchema =
|
998
|
-
role:
|
999
|
-
content:
|
1000
|
-
|
1001
|
-
|
933
|
+
var coreAssistantMessageSchema = z6.object({
|
934
|
+
role: z6.literal("assistant"),
|
935
|
+
content: z6.union([
|
936
|
+
z6.string(),
|
937
|
+
z6.array(z6.union([textPartSchema, toolCallPartSchema]))
|
1002
938
|
]),
|
1003
939
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1004
940
|
});
|
1005
|
-
var coreToolMessageSchema =
|
1006
|
-
role:
|
1007
|
-
content:
|
941
|
+
var coreToolMessageSchema = z6.object({
|
942
|
+
role: z6.literal("tool"),
|
943
|
+
content: z6.array(toolResultPartSchema),
|
1008
944
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1009
945
|
});
|
1010
|
-
var coreMessageSchema =
|
946
|
+
var coreMessageSchema = z6.union([
|
1011
947
|
coreSystemMessageSchema,
|
1012
948
|
coreUserMessageSchema,
|
1013
949
|
coreAssistantMessageSchema,
|
@@ -1055,7 +991,7 @@ function standardizePrompt(prompt) {
|
|
1055
991
|
if (prompt.messages != null) {
|
1056
992
|
const validationResult = safeValidateTypes({
|
1057
993
|
value: prompt.messages,
|
1058
|
-
schema:
|
994
|
+
schema: z7.array(coreMessageSchema)
|
1059
995
|
});
|
1060
996
|
if (!validationResult.success) {
|
1061
997
|
throw new InvalidPromptError({
|
@@ -1084,7 +1020,7 @@ function calculateLanguageModelUsage(usage) {
|
|
1084
1020
|
}
|
1085
1021
|
|
1086
1022
|
// errors/invalid-tool-arguments-error.ts
|
1087
|
-
import { AISDKError as AISDKError5, getErrorMessage
|
1023
|
+
import { AISDKError as AISDKError5, getErrorMessage } from "@ai-sdk/provider";
|
1088
1024
|
var name5 = "AI_InvalidToolArgumentsError";
|
1089
1025
|
var marker5 = `vercel.ai.error.${name5}`;
|
1090
1026
|
var symbol5 = Symbol.for(marker5);
|
@@ -1094,7 +1030,7 @@ var InvalidToolArgumentsError = class extends AISDKError5 {
|
|
1094
1030
|
toolArgs,
|
1095
1031
|
toolName,
|
1096
1032
|
cause,
|
1097
|
-
message = `Invalid arguments for tool ${toolName}: ${
|
1033
|
+
message = `Invalid arguments for tool ${toolName}: ${getErrorMessage(
|
1098
1034
|
cause
|
1099
1035
|
)}`
|
1100
1036
|
}) {
|
@@ -1181,7 +1117,7 @@ function isGenerator(value) {
|
|
1181
1117
|
|
1182
1118
|
// util/retry-with-exponential-backoff.ts
|
1183
1119
|
import { APICallError } from "@ai-sdk/provider";
|
1184
|
-
import { getErrorMessage as
|
1120
|
+
import { getErrorMessage as getErrorMessage2, isAbortError } from "@ai-sdk/provider-utils";
|
1185
1121
|
|
1186
1122
|
// util/delay.ts
|
1187
1123
|
async function delay(delayInMs) {
|
@@ -1254,7 +1190,7 @@ async function _retryWithExponentialBackoff(f, {
|
|
1254
1190
|
if (maxRetries === 0) {
|
1255
1191
|
throw error;
|
1256
1192
|
}
|
1257
|
-
const errorMessage =
|
1193
|
+
const errorMessage = getErrorMessage2(error);
|
1258
1194
|
const newErrors = [...errors, error];
|
1259
1195
|
const tryNumber = newErrors.length;
|
1260
1196
|
if (tryNumber > maxRetries) {
|
@@ -1487,7 +1423,8 @@ async function streamUI({
|
|
1487
1423
|
inputFormat: validatedPrompt.type,
|
1488
1424
|
prompt: await convertToLanguageModelPrompt({
|
1489
1425
|
prompt: validatedPrompt,
|
1490
|
-
modelSupportsImageUrls: model.supportsImageUrls
|
1426
|
+
modelSupportsImageUrls: model.supportsImageUrls,
|
1427
|
+
modelSupportsUrl: model.supportsUrl
|
1491
1428
|
}),
|
1492
1429
|
providerMetadata,
|
1493
1430
|
abortSignal,
|