ai 3.4.17 → 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 +43 -0
- package/dist/index.d.mts +110 -76
- package/dist/index.d.ts +110 -76
- package/dist/index.js +388 -447
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +374 -436
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -12
- package/rsc/dist/index.d.ts +16 -2
- package/rsc/dist/rsc-server.d.mts +16 -2
- package/rsc/dist/rsc-server.mjs +192 -269
- 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/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,36 +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
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
break;
|
475
|
-
}
|
476
|
-
case "messages": {
|
477
|
-
languageModelMessages.push(
|
478
|
-
...prompt.messages.map(
|
479
|
-
(message) => convertToLanguageModelMessage(message, downloadedAssets)
|
480
|
-
)
|
481
|
-
);
|
482
|
-
break;
|
483
|
-
}
|
484
|
-
default: {
|
485
|
-
const _exhaustiveCheck = promptType;
|
486
|
-
throw new Error(`Unsupported prompt type: ${_exhaustiveCheck}`);
|
487
|
-
}
|
488
|
-
}
|
489
|
-
return languageModelMessages;
|
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 }] : [],
|
465
|
+
...prompt.messages.map(
|
466
|
+
(message) => convertToLanguageModelMessage(message, downloadedAssets)
|
467
|
+
)
|
468
|
+
];
|
490
469
|
}
|
491
470
|
function convertToLanguageModelMessage(message, downloadedAssets) {
|
492
471
|
const role = message.role;
|
@@ -508,178 +487,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
508
487
|
}
|
509
488
|
return {
|
510
489
|
role: "user",
|
511
|
-
content: message.content.map(
|
512
|
-
(part) => {
|
513
|
-
var _a8, _b, _c, _d, _e;
|
514
|
-
switch (part.type) {
|
515
|
-
case "text": {
|
516
|
-
return {
|
517
|
-
type: "text",
|
518
|
-
text: part.text,
|
519
|
-
providerMetadata: part.experimental_providerMetadata
|
520
|
-
};
|
521
|
-
}
|
522
|
-
case "image": {
|
523
|
-
if (part.image instanceof URL) {
|
524
|
-
if (downloadedAssets == null) {
|
525
|
-
return {
|
526
|
-
type: "image",
|
527
|
-
image: part.image,
|
528
|
-
mimeType: part.mimeType,
|
529
|
-
providerMetadata: part.experimental_providerMetadata
|
530
|
-
};
|
531
|
-
} else {
|
532
|
-
const downloadedImage = downloadedAssets[part.image.toString()];
|
533
|
-
return {
|
534
|
-
type: "image",
|
535
|
-
image: downloadedImage.data,
|
536
|
-
mimeType: (_a8 = part.mimeType) != null ? _a8 : downloadedImage.mimeType,
|
537
|
-
providerMetadata: part.experimental_providerMetadata
|
538
|
-
};
|
539
|
-
}
|
540
|
-
}
|
541
|
-
if (typeof part.image === "string") {
|
542
|
-
try {
|
543
|
-
const url = new URL(part.image);
|
544
|
-
switch (url.protocol) {
|
545
|
-
case "http:":
|
546
|
-
case "https:": {
|
547
|
-
if (downloadedAssets == null) {
|
548
|
-
return {
|
549
|
-
type: "image",
|
550
|
-
image: url,
|
551
|
-
mimeType: part.mimeType,
|
552
|
-
providerMetadata: part.experimental_providerMetadata
|
553
|
-
};
|
554
|
-
} else {
|
555
|
-
const downloadedImage = downloadedAssets[url.toString()];
|
556
|
-
return {
|
557
|
-
type: "image",
|
558
|
-
image: downloadedImage.data,
|
559
|
-
mimeType: (_b = part.mimeType) != null ? _b : downloadedImage.mimeType,
|
560
|
-
providerMetadata: part.experimental_providerMetadata
|
561
|
-
};
|
562
|
-
}
|
563
|
-
}
|
564
|
-
case "data:": {
|
565
|
-
try {
|
566
|
-
const { mimeType, base64Content } = splitDataUrl(
|
567
|
-
part.image
|
568
|
-
);
|
569
|
-
if (mimeType == null || base64Content == null) {
|
570
|
-
throw new Error("Invalid data URL format");
|
571
|
-
}
|
572
|
-
return {
|
573
|
-
type: "image",
|
574
|
-
image: convertDataContentToUint8Array(base64Content),
|
575
|
-
mimeType,
|
576
|
-
providerMetadata: part.experimental_providerMetadata
|
577
|
-
};
|
578
|
-
} catch (error) {
|
579
|
-
throw new Error(
|
580
|
-
`Error processing data URL: ${getErrorMessage(
|
581
|
-
message
|
582
|
-
)}`
|
583
|
-
);
|
584
|
-
}
|
585
|
-
}
|
586
|
-
}
|
587
|
-
} catch (_ignored) {
|
588
|
-
}
|
589
|
-
}
|
590
|
-
const imageUint8 = convertDataContentToUint8Array(part.image);
|
591
|
-
return {
|
592
|
-
type: "image",
|
593
|
-
image: imageUint8,
|
594
|
-
mimeType: (_c = part.mimeType) != null ? _c : detectImageMimeType(imageUint8),
|
595
|
-
providerMetadata: part.experimental_providerMetadata
|
596
|
-
};
|
597
|
-
}
|
598
|
-
case "file": {
|
599
|
-
if (part.data instanceof URL) {
|
600
|
-
if (downloadedAssets == null) {
|
601
|
-
return {
|
602
|
-
type: "file",
|
603
|
-
data: part.data,
|
604
|
-
mimeType: part.mimeType,
|
605
|
-
providerMetadata: part.experimental_providerMetadata
|
606
|
-
};
|
607
|
-
} else {
|
608
|
-
const downloadedImage = downloadedAssets[part.data.toString()];
|
609
|
-
return {
|
610
|
-
type: "file",
|
611
|
-
data: convertUint8ArrayToBase642(downloadedImage.data),
|
612
|
-
mimeType: (_d = part.mimeType) != null ? _d : downloadedImage.mimeType,
|
613
|
-
providerMetadata: part.experimental_providerMetadata
|
614
|
-
};
|
615
|
-
}
|
616
|
-
}
|
617
|
-
if (typeof part.data === "string") {
|
618
|
-
try {
|
619
|
-
const url = new URL(part.data);
|
620
|
-
switch (url.protocol) {
|
621
|
-
case "http:":
|
622
|
-
case "https:": {
|
623
|
-
if (downloadedAssets == null) {
|
624
|
-
return {
|
625
|
-
type: "file",
|
626
|
-
data: url,
|
627
|
-
mimeType: part.mimeType,
|
628
|
-
providerMetadata: part.experimental_providerMetadata
|
629
|
-
};
|
630
|
-
} else {
|
631
|
-
const downloadedImage = downloadedAssets[url.toString()];
|
632
|
-
return {
|
633
|
-
type: "file",
|
634
|
-
data: convertUint8ArrayToBase642(
|
635
|
-
downloadedImage.data
|
636
|
-
),
|
637
|
-
mimeType: (_e = part.mimeType) != null ? _e : downloadedImage.mimeType,
|
638
|
-
providerMetadata: part.experimental_providerMetadata
|
639
|
-
};
|
640
|
-
}
|
641
|
-
}
|
642
|
-
case "data:": {
|
643
|
-
try {
|
644
|
-
const { mimeType, base64Content } = splitDataUrl(
|
645
|
-
part.data
|
646
|
-
);
|
647
|
-
if (mimeType == null || base64Content == null) {
|
648
|
-
throw new Error("Invalid data URL format");
|
649
|
-
}
|
650
|
-
return {
|
651
|
-
type: "file",
|
652
|
-
data: convertDataContentToBase64String(
|
653
|
-
base64Content
|
654
|
-
),
|
655
|
-
mimeType,
|
656
|
-
providerMetadata: part.experimental_providerMetadata
|
657
|
-
};
|
658
|
-
} catch (error) {
|
659
|
-
throw new Error(
|
660
|
-
`Error processing data URL: ${getErrorMessage(
|
661
|
-
message
|
662
|
-
)}`
|
663
|
-
);
|
664
|
-
}
|
665
|
-
}
|
666
|
-
}
|
667
|
-
} catch (_ignored) {
|
668
|
-
}
|
669
|
-
}
|
670
|
-
const imageBase64 = convertDataContentToBase64String(
|
671
|
-
part.data
|
672
|
-
);
|
673
|
-
return {
|
674
|
-
type: "file",
|
675
|
-
data: imageBase64,
|
676
|
-
mimeType: part.mimeType,
|
677
|
-
providerMetadata: part.experimental_providerMetadata
|
678
|
-
};
|
679
|
-
}
|
680
|
-
}
|
681
|
-
}
|
682
|
-
).filter((part) => part.type !== "text" || part.text !== ""),
|
490
|
+
content: message.content.map((part) => convertPartToLanguageModelPart(part, downloadedAssets)).filter((part) => part.type !== "text" || part.text !== ""),
|
683
491
|
providerMetadata: message.experimental_providerMetadata
|
684
492
|
};
|
685
493
|
}
|
@@ -714,6 +522,8 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
714
522
|
toolCallId: part.toolCallId,
|
715
523
|
toolName: part.toolName,
|
716
524
|
result: part.result,
|
525
|
+
content: part.experimental_content,
|
526
|
+
isError: part.isError,
|
717
527
|
providerMetadata: part.experimental_providerMetadata
|
718
528
|
})),
|
719
529
|
providerMetadata: message.experimental_providerMetadata
|
@@ -725,17 +535,19 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
725
535
|
}
|
726
536
|
}
|
727
537
|
}
|
728
|
-
async function downloadAssets(messages, downloadImplementation) {
|
538
|
+
async function downloadAssets(messages, downloadImplementation, modelSupportsImageUrls, modelSupportsUrl) {
|
729
539
|
const urls = messages.filter((message) => message.role === "user").map((message) => message.content).filter(
|
730
540
|
(content) => Array.isArray(content)
|
731
541
|
).flat().filter(
|
732
542
|
(part) => part.type === "image" || part.type === "file"
|
543
|
+
).filter(
|
544
|
+
(part) => !(part.type === "image" && modelSupportsImageUrls === true)
|
733
545
|
).map((part) => part.type === "image" ? part.image : part.data).map(
|
734
546
|
(part) => (
|
735
547
|
// support string urls:
|
736
548
|
typeof part === "string" && (part.startsWith("http:") || part.startsWith("https:")) ? new URL(part) : part
|
737
549
|
)
|
738
|
-
).filter((image) => image instanceof URL);
|
550
|
+
).filter((image) => image instanceof URL).filter((url) => !modelSupportsUrl(url));
|
739
551
|
const downloadedImages = await Promise.all(
|
740
552
|
urls.map(async (url) => ({
|
741
553
|
url,
|
@@ -746,6 +558,79 @@ async function downloadAssets(messages, downloadImplementation) {
|
|
746
558
|
downloadedImages.map(({ url, data }) => [url.toString(), data])
|
747
559
|
);
|
748
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
|
+
}
|
749
634
|
|
750
635
|
// errors/invalid-argument-error.ts
|
751
636
|
import { AISDKError as AISDKError4 } from "@ai-sdk/provider";
|
@@ -923,23 +808,41 @@ function prepareToolsAndToolChoice({
|
|
923
808
|
([name8]) => activeTools.includes(name8)
|
924
809
|
) : Object.entries(tools);
|
925
810
|
return {
|
926
|
-
tools: filteredTools.map(([name8, tool]) =>
|
927
|
-
type
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
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
|
+
}),
|
932
835
|
toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
|
933
836
|
};
|
934
837
|
}
|
935
838
|
|
936
|
-
// core/prompt/
|
839
|
+
// core/prompt/standardize-prompt.ts
|
937
840
|
import { InvalidPromptError } from "@ai-sdk/provider";
|
938
841
|
import { safeValidateTypes } from "@ai-sdk/provider-utils";
|
939
|
-
import { z as
|
842
|
+
import { z as z7 } from "zod";
|
940
843
|
|
941
844
|
// core/prompt/message.ts
|
942
|
-
import { z as
|
845
|
+
import { z as z6 } from "zod";
|
943
846
|
|
944
847
|
// core/types/provider-metadata.ts
|
945
848
|
import { z as z3 } from "zod";
|
@@ -964,75 +867,91 @@ var providerMetadataSchema = z3.record(
|
|
964
867
|
);
|
965
868
|
|
966
869
|
// core/prompt/content-part.ts
|
870
|
+
import { z as z5 } from "zod";
|
871
|
+
|
872
|
+
// core/prompt/tool-result-content.ts
|
967
873
|
import { z as z4 } from "zod";
|
968
|
-
var
|
969
|
-
|
970
|
-
|
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(),
|
971
889
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
972
890
|
});
|
973
|
-
var imagePartSchema =
|
974
|
-
type:
|
975
|
-
image:
|
976
|
-
mimeType:
|
891
|
+
var imagePartSchema = z5.object({
|
892
|
+
type: z5.literal("image"),
|
893
|
+
image: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
894
|
+
mimeType: z5.string().optional(),
|
977
895
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
978
896
|
});
|
979
|
-
var filePartSchema =
|
980
|
-
type:
|
981
|
-
data:
|
982
|
-
mimeType:
|
897
|
+
var filePartSchema = z5.object({
|
898
|
+
type: z5.literal("file"),
|
899
|
+
data: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
900
|
+
mimeType: z5.string(),
|
983
901
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
984
902
|
});
|
985
|
-
var toolCallPartSchema =
|
986
|
-
type:
|
987
|
-
toolCallId:
|
988
|
-
toolName:
|
989
|
-
args:
|
903
|
+
var toolCallPartSchema = z5.object({
|
904
|
+
type: z5.literal("tool-call"),
|
905
|
+
toolCallId: z5.string(),
|
906
|
+
toolName: z5.string(),
|
907
|
+
args: z5.unknown()
|
990
908
|
});
|
991
|
-
var toolResultPartSchema =
|
992
|
-
type:
|
993
|
-
toolCallId:
|
994
|
-
toolName:
|
995
|
-
result:
|
996
|
-
|
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(),
|
997
916
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
998
917
|
});
|
999
918
|
|
1000
919
|
// core/prompt/message.ts
|
1001
|
-
var coreSystemMessageSchema =
|
1002
|
-
role:
|
1003
|
-
content:
|
920
|
+
var coreSystemMessageSchema = z6.object({
|
921
|
+
role: z6.literal("system"),
|
922
|
+
content: z6.string(),
|
1004
923
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1005
924
|
});
|
1006
|
-
var coreUserMessageSchema =
|
1007
|
-
role:
|
1008
|
-
content:
|
1009
|
-
|
1010
|
-
|
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]))
|
1011
930
|
]),
|
1012
931
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1013
932
|
});
|
1014
|
-
var coreAssistantMessageSchema =
|
1015
|
-
role:
|
1016
|
-
content:
|
1017
|
-
|
1018
|
-
|
933
|
+
var coreAssistantMessageSchema = z6.object({
|
934
|
+
role: z6.literal("assistant"),
|
935
|
+
content: z6.union([
|
936
|
+
z6.string(),
|
937
|
+
z6.array(z6.union([textPartSchema, toolCallPartSchema]))
|
1019
938
|
]),
|
1020
939
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1021
940
|
});
|
1022
|
-
var coreToolMessageSchema =
|
1023
|
-
role:
|
1024
|
-
content:
|
941
|
+
var coreToolMessageSchema = z6.object({
|
942
|
+
role: z6.literal("tool"),
|
943
|
+
content: z6.array(toolResultPartSchema),
|
1025
944
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1026
945
|
});
|
1027
|
-
var coreMessageSchema =
|
946
|
+
var coreMessageSchema = z6.union([
|
1028
947
|
coreSystemMessageSchema,
|
1029
948
|
coreUserMessageSchema,
|
1030
949
|
coreAssistantMessageSchema,
|
1031
950
|
coreToolMessageSchema
|
1032
951
|
]);
|
1033
952
|
|
1034
|
-
// core/prompt/
|
1035
|
-
function
|
953
|
+
// core/prompt/standardize-prompt.ts
|
954
|
+
function standardizePrompt(prompt) {
|
1036
955
|
if (prompt.prompt == null && prompt.messages == null) {
|
1037
956
|
throw new InvalidPromptError({
|
1038
957
|
prompt,
|
@@ -1060,15 +979,19 @@ function validatePrompt(prompt) {
|
|
1060
979
|
}
|
1061
980
|
return {
|
1062
981
|
type: "prompt",
|
1063
|
-
|
1064
|
-
messages:
|
1065
|
-
|
982
|
+
system: prompt.system,
|
983
|
+
messages: [
|
984
|
+
{
|
985
|
+
role: "user",
|
986
|
+
content: prompt.prompt
|
987
|
+
}
|
988
|
+
]
|
1066
989
|
};
|
1067
990
|
}
|
1068
991
|
if (prompt.messages != null) {
|
1069
992
|
const validationResult = safeValidateTypes({
|
1070
993
|
value: prompt.messages,
|
1071
|
-
schema:
|
994
|
+
schema: z7.array(coreMessageSchema)
|
1072
995
|
});
|
1073
996
|
if (!validationResult.success) {
|
1074
997
|
throw new InvalidPromptError({
|
@@ -1079,7 +1002,6 @@ function validatePrompt(prompt) {
|
|
1079
1002
|
}
|
1080
1003
|
return {
|
1081
1004
|
type: "messages",
|
1082
|
-
prompt: void 0,
|
1083
1005
|
messages: prompt.messages,
|
1084
1006
|
// only possible case bc of checks above
|
1085
1007
|
system: prompt.system
|
@@ -1098,7 +1020,7 @@ function calculateLanguageModelUsage(usage) {
|
|
1098
1020
|
}
|
1099
1021
|
|
1100
1022
|
// errors/invalid-tool-arguments-error.ts
|
1101
|
-
import { AISDKError as AISDKError5, getErrorMessage
|
1023
|
+
import { AISDKError as AISDKError5, getErrorMessage } from "@ai-sdk/provider";
|
1102
1024
|
var name5 = "AI_InvalidToolArgumentsError";
|
1103
1025
|
var marker5 = `vercel.ai.error.${name5}`;
|
1104
1026
|
var symbol5 = Symbol.for(marker5);
|
@@ -1108,7 +1030,7 @@ var InvalidToolArgumentsError = class extends AISDKError5 {
|
|
1108
1030
|
toolArgs,
|
1109
1031
|
toolName,
|
1110
1032
|
cause,
|
1111
|
-
message = `Invalid arguments for tool ${toolName}: ${
|
1033
|
+
message = `Invalid arguments for tool ${toolName}: ${getErrorMessage(
|
1112
1034
|
cause
|
1113
1035
|
)}`
|
1114
1036
|
}) {
|
@@ -1195,7 +1117,7 @@ function isGenerator(value) {
|
|
1195
1117
|
|
1196
1118
|
// util/retry-with-exponential-backoff.ts
|
1197
1119
|
import { APICallError } from "@ai-sdk/provider";
|
1198
|
-
import { getErrorMessage as
|
1120
|
+
import { getErrorMessage as getErrorMessage2, isAbortError } from "@ai-sdk/provider-utils";
|
1199
1121
|
|
1200
1122
|
// util/delay.ts
|
1201
1123
|
async function delay(delayInMs) {
|
@@ -1268,7 +1190,7 @@ async function _retryWithExponentialBackoff(f, {
|
|
1268
1190
|
if (maxRetries === 0) {
|
1269
1191
|
throw error;
|
1270
1192
|
}
|
1271
|
-
const errorMessage =
|
1193
|
+
const errorMessage = getErrorMessage2(error);
|
1272
1194
|
const newErrors = [...errors, error];
|
1273
1195
|
const tryNumber = newErrors.length;
|
1274
1196
|
if (tryNumber > maxRetries) {
|
@@ -1486,7 +1408,7 @@ async function streamUI({
|
|
1486
1408
|
renderFinished.resolve(void 0);
|
1487
1409
|
}
|
1488
1410
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
1489
|
-
const validatedPrompt =
|
1411
|
+
const validatedPrompt = standardizePrompt({ system, prompt, messages });
|
1490
1412
|
const result = await retry(
|
1491
1413
|
async () => model.doStream({
|
1492
1414
|
mode: {
|
@@ -1501,7 +1423,8 @@ async function streamUI({
|
|
1501
1423
|
inputFormat: validatedPrompt.type,
|
1502
1424
|
prompt: await convertToLanguageModelPrompt({
|
1503
1425
|
prompt: validatedPrompt,
|
1504
|
-
modelSupportsImageUrls: model.supportsImageUrls
|
1426
|
+
modelSupportsImageUrls: model.supportsImageUrls,
|
1427
|
+
modelSupportsUrl: model.supportsUrl
|
1505
1428
|
}),
|
1506
1429
|
providerMetadata,
|
1507
1430
|
abortSignal,
|