ai 3.3.11 → 3.3.13
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/dist/index.d.mts +13 -33
- package/dist/index.d.ts +13 -33
- package/dist/index.js +181 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +171 -59
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/rsc/dist/index.d.ts +12 -11
- package/rsc/dist/rsc-server.d.mts +12 -11
- package/rsc/dist/rsc-server.mjs +164 -40
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ai",
|
3
|
-
"version": "3.3.
|
3
|
+
"version": "3.3.13",
|
4
4
|
"description": "Vercel AI SDK - The AI Toolkit for TypeScript and JavaScript",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"sideEffects": false,
|
@@ -58,13 +58,13 @@
|
|
58
58
|
}
|
59
59
|
},
|
60
60
|
"dependencies": {
|
61
|
-
"@ai-sdk/provider": "0.0.
|
62
|
-
"@ai-sdk/provider-utils": "1.0.
|
63
|
-
"@ai-sdk/react": "0.0.
|
64
|
-
"@ai-sdk/solid": "0.0.
|
65
|
-
"@ai-sdk/svelte": "0.0.
|
66
|
-
"@ai-sdk/ui-utils": "0.0.
|
67
|
-
"@ai-sdk/vue": "0.0.
|
61
|
+
"@ai-sdk/provider": "0.0.21",
|
62
|
+
"@ai-sdk/provider-utils": "1.0.14",
|
63
|
+
"@ai-sdk/react": "0.0.47",
|
64
|
+
"@ai-sdk/solid": "0.0.37",
|
65
|
+
"@ai-sdk/svelte": "0.0.39",
|
66
|
+
"@ai-sdk/ui-utils": "0.0.34",
|
67
|
+
"@ai-sdk/vue": "0.0.39",
|
68
68
|
"@opentelemetry/api": "1.9.0",
|
69
69
|
"eventsource-parser": "1.1.2",
|
70
70
|
"jsondiffpatch": "0.6.0",
|
package/rsc/dist/index.d.ts
CHANGED
@@ -214,12 +214,6 @@ some settings might not be supported, which can lead to suboptimal results.
|
|
214
214
|
*/
|
215
215
|
type CallWarning = LanguageModelV1CallWarning;
|
216
216
|
/**
|
217
|
-
Additional provider-specific metadata. They are passed through
|
218
|
-
to the provider from the AI SDK and enable provider-specific
|
219
|
-
functionality that can be fully encapsulated in the provider.
|
220
|
-
*/
|
221
|
-
type ProviderMetadata = LanguageModelV1ProviderMetadata;
|
222
|
-
/**
|
223
217
|
Tool choice for the generation. It supports the following settings:
|
224
218
|
|
225
219
|
- `auto` (default): the model can choose whether and which tools to call.
|
@@ -232,6 +226,13 @@ type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | '
|
|
232
226
|
toolName: keyof TOOLS;
|
233
227
|
};
|
234
228
|
|
229
|
+
/**
|
230
|
+
Additional provider-specific metadata. They are passed through
|
231
|
+
to the provider from the AI SDK and enable provider-specific
|
232
|
+
functionality that can be fully encapsulated in the provider.
|
233
|
+
*/
|
234
|
+
type ProviderMetadata = LanguageModelV1ProviderMetadata;
|
235
|
+
|
235
236
|
/**
|
236
237
|
Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
237
238
|
*/
|
@@ -323,11 +324,6 @@ interface ToolResultPart {
|
|
323
324
|
experimental_providerMetadata?: ProviderMetadata;
|
324
325
|
}
|
325
326
|
|
326
|
-
/**
|
327
|
-
A message that can be used in the `messages` field of a prompt.
|
328
|
-
It can be a user message, an assistant message, or a tool message.
|
329
|
-
*/
|
330
|
-
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
331
327
|
/**
|
332
328
|
A system message. It can contain system information.
|
333
329
|
|
@@ -396,6 +392,11 @@ type CoreToolMessage = {
|
|
396
392
|
Content of a tool message. It is an array of tool result parts.
|
397
393
|
*/
|
398
394
|
type ToolContent = Array<ToolResultPart>;
|
395
|
+
/**
|
396
|
+
A message that can be used in the `messages` field of a prompt.
|
397
|
+
It can be a user message, an assistant message, or a tool message.
|
398
|
+
*/
|
399
|
+
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
399
400
|
|
400
401
|
/**
|
401
402
|
Prompt part of the AI function options. It contains a system message, a simple text prompt, or a list of messages.
|
@@ -212,12 +212,6 @@ some settings might not be supported, which can lead to suboptimal results.
|
|
212
212
|
*/
|
213
213
|
type CallWarning = LanguageModelV1CallWarning;
|
214
214
|
/**
|
215
|
-
Additional provider-specific metadata. They are passed through
|
216
|
-
to the provider from the AI SDK and enable provider-specific
|
217
|
-
functionality that can be fully encapsulated in the provider.
|
218
|
-
*/
|
219
|
-
type ProviderMetadata = LanguageModelV1ProviderMetadata;
|
220
|
-
/**
|
221
215
|
Tool choice for the generation. It supports the following settings:
|
222
216
|
|
223
217
|
- `auto` (default): the model can choose whether and which tools to call.
|
@@ -230,6 +224,13 @@ type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | '
|
|
230
224
|
toolName: keyof TOOLS;
|
231
225
|
};
|
232
226
|
|
227
|
+
/**
|
228
|
+
Additional provider-specific metadata. They are passed through
|
229
|
+
to the provider from the AI SDK and enable provider-specific
|
230
|
+
functionality that can be fully encapsulated in the provider.
|
231
|
+
*/
|
232
|
+
type ProviderMetadata = LanguageModelV1ProviderMetadata;
|
233
|
+
|
233
234
|
/**
|
234
235
|
Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
235
236
|
*/
|
@@ -321,11 +322,6 @@ interface ToolResultPart {
|
|
321
322
|
experimental_providerMetadata?: ProviderMetadata;
|
322
323
|
}
|
323
324
|
|
324
|
-
/**
|
325
|
-
A message that can be used in the `messages` field of a prompt.
|
326
|
-
It can be a user message, an assistant message, or a tool message.
|
327
|
-
*/
|
328
|
-
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
329
325
|
/**
|
330
326
|
A system message. It can contain system information.
|
331
327
|
|
@@ -394,6 +390,11 @@ type CoreToolMessage = {
|
|
394
390
|
Content of a tool message. It is an array of tool result parts.
|
395
391
|
*/
|
396
392
|
type ToolContent = Array<ToolResultPart>;
|
393
|
+
/**
|
394
|
+
A message that can be used in the `messages` field of a prompt.
|
395
|
+
It can be a user message, an assistant message, or a tool message.
|
396
|
+
*/
|
397
|
+
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
397
398
|
|
398
399
|
/**
|
399
400
|
Prompt part of the AI function options. It contains a system message, a simple text prompt, or a list of messages.
|
package/rsc/dist/rsc-server.mjs
CHANGED
@@ -351,6 +351,20 @@ var InvalidDataContentError = class extends AISDKError2 {
|
|
351
351
|
_a2 = symbol2;
|
352
352
|
|
353
353
|
// core/prompt/data-content.ts
|
354
|
+
import { z } from "zod";
|
355
|
+
var dataContentSchema = z.union([
|
356
|
+
z.string(),
|
357
|
+
z.instanceof(Uint8Array),
|
358
|
+
z.instanceof(ArrayBuffer),
|
359
|
+
z.custom(
|
360
|
+
// Buffer might not be available in some environments such as CloudFlare:
|
361
|
+
(value) => {
|
362
|
+
var _a8, _b;
|
363
|
+
return (_b = (_a8 = globalThis.Buffer) == null ? void 0 : _a8.isBuffer(value)) != null ? _b : false;
|
364
|
+
},
|
365
|
+
{ message: "Must be a Buffer" }
|
366
|
+
)
|
367
|
+
]);
|
354
368
|
function convertDataContentToUint8Array(content) {
|
355
369
|
if (content instanceof Uint8Array) {
|
356
370
|
return content;
|
@@ -618,45 +632,6 @@ async function downloadImages(messages, downloadImplementation) {
|
|
618
632
|
);
|
619
633
|
}
|
620
634
|
|
621
|
-
// core/prompt/get-validated-prompt.ts
|
622
|
-
import { InvalidPromptError } from "@ai-sdk/provider";
|
623
|
-
function getValidatedPrompt(prompt) {
|
624
|
-
if (prompt.prompt == null && prompt.messages == null) {
|
625
|
-
throw new InvalidPromptError({
|
626
|
-
prompt,
|
627
|
-
message: "prompt or messages must be defined"
|
628
|
-
});
|
629
|
-
}
|
630
|
-
if (prompt.prompt != null && prompt.messages != null) {
|
631
|
-
throw new InvalidPromptError({
|
632
|
-
prompt,
|
633
|
-
message: "prompt and messages cannot be defined at the same time"
|
634
|
-
});
|
635
|
-
}
|
636
|
-
if (prompt.messages != null) {
|
637
|
-
for (const message of prompt.messages) {
|
638
|
-
if (message.role === "system" && typeof message.content !== "string") {
|
639
|
-
throw new InvalidPromptError({
|
640
|
-
prompt,
|
641
|
-
message: "system message content must be a string"
|
642
|
-
});
|
643
|
-
}
|
644
|
-
}
|
645
|
-
}
|
646
|
-
return prompt.prompt != null ? {
|
647
|
-
type: "prompt",
|
648
|
-
prompt: prompt.prompt,
|
649
|
-
messages: void 0,
|
650
|
-
system: prompt.system
|
651
|
-
} : {
|
652
|
-
type: "messages",
|
653
|
-
prompt: void 0,
|
654
|
-
messages: prompt.messages,
|
655
|
-
// only possible case bc of checks above
|
656
|
-
system: prompt.system
|
657
|
-
};
|
658
|
-
}
|
659
|
-
|
660
635
|
// errors/invalid-argument-error.ts
|
661
636
|
import { AISDKError as AISDKError4 } from "@ai-sdk/provider";
|
662
637
|
var name4 = "AI_InvalidArgumentError";
|
@@ -828,6 +803,155 @@ function prepareToolsAndToolChoice({
|
|
828
803
|
};
|
829
804
|
}
|
830
805
|
|
806
|
+
// core/prompt/validate-prompt.ts
|
807
|
+
import { InvalidPromptError } from "@ai-sdk/provider";
|
808
|
+
import { safeValidateTypes } from "@ai-sdk/provider-utils";
|
809
|
+
import { z as z6 } from "zod";
|
810
|
+
|
811
|
+
// core/prompt/message.ts
|
812
|
+
import { z as z5 } from "zod";
|
813
|
+
|
814
|
+
// core/types/provider-metadata.ts
|
815
|
+
import { z as z3 } from "zod";
|
816
|
+
|
817
|
+
// core/types/json-value.ts
|
818
|
+
import { z as z2 } from "zod";
|
819
|
+
var jsonValueSchema = z2.lazy(
|
820
|
+
() => z2.union([
|
821
|
+
z2.null(),
|
822
|
+
z2.string(),
|
823
|
+
z2.number(),
|
824
|
+
z2.boolean(),
|
825
|
+
z2.record(z2.string(), jsonValueSchema),
|
826
|
+
z2.array(jsonValueSchema)
|
827
|
+
])
|
828
|
+
);
|
829
|
+
|
830
|
+
// core/types/provider-metadata.ts
|
831
|
+
var providerMetadataSchema = z3.record(
|
832
|
+
z3.string(),
|
833
|
+
z3.record(z3.string(), jsonValueSchema)
|
834
|
+
);
|
835
|
+
|
836
|
+
// core/prompt/content-part.ts
|
837
|
+
import { z as z4 } from "zod";
|
838
|
+
var textPartSchema = z4.object({
|
839
|
+
type: z4.literal("text"),
|
840
|
+
text: z4.string(),
|
841
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
842
|
+
});
|
843
|
+
var imagePartSchema = z4.object({
|
844
|
+
type: z4.literal("image"),
|
845
|
+
image: z4.union([dataContentSchema, z4.instanceof(URL)]),
|
846
|
+
mimeType: z4.string().optional(),
|
847
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
848
|
+
});
|
849
|
+
var toolCallPartSchema = z4.object({
|
850
|
+
type: z4.literal("tool-call"),
|
851
|
+
toolCallId: z4.string(),
|
852
|
+
toolName: z4.string(),
|
853
|
+
args: z4.unknown()
|
854
|
+
});
|
855
|
+
var toolResultPartSchema = z4.object({
|
856
|
+
type: z4.literal("tool-result"),
|
857
|
+
toolCallId: z4.string(),
|
858
|
+
toolName: z4.string(),
|
859
|
+
result: z4.unknown(),
|
860
|
+
isError: z4.boolean().optional(),
|
861
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
862
|
+
});
|
863
|
+
|
864
|
+
// core/prompt/message.ts
|
865
|
+
var coreSystemMessageSchema = z5.object({
|
866
|
+
role: z5.literal("system"),
|
867
|
+
content: z5.string(),
|
868
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
869
|
+
});
|
870
|
+
var coreUserMessageSchema = z5.object({
|
871
|
+
role: z5.literal("user"),
|
872
|
+
content: z5.union([
|
873
|
+
z5.string(),
|
874
|
+
z5.array(z5.union([textPartSchema, imagePartSchema]))
|
875
|
+
]),
|
876
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
877
|
+
});
|
878
|
+
var coreAssistantMessageSchema = z5.object({
|
879
|
+
role: z5.literal("assistant"),
|
880
|
+
content: z5.union([
|
881
|
+
z5.string(),
|
882
|
+
z5.array(z5.union([textPartSchema, toolCallPartSchema]))
|
883
|
+
]),
|
884
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
885
|
+
});
|
886
|
+
var coreToolMessageSchema = z5.object({
|
887
|
+
role: z5.literal("tool"),
|
888
|
+
content: z5.array(toolResultPartSchema),
|
889
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
890
|
+
});
|
891
|
+
var coreMessageSchema = z5.union([
|
892
|
+
coreSystemMessageSchema,
|
893
|
+
coreUserMessageSchema,
|
894
|
+
coreAssistantMessageSchema,
|
895
|
+
coreToolMessageSchema
|
896
|
+
]);
|
897
|
+
|
898
|
+
// core/prompt/validate-prompt.ts
|
899
|
+
function validatePrompt(prompt) {
|
900
|
+
if (prompt.prompt == null && prompt.messages == null) {
|
901
|
+
throw new InvalidPromptError({
|
902
|
+
prompt,
|
903
|
+
message: "prompt or messages must be defined"
|
904
|
+
});
|
905
|
+
}
|
906
|
+
if (prompt.prompt != null && prompt.messages != null) {
|
907
|
+
throw new InvalidPromptError({
|
908
|
+
prompt,
|
909
|
+
message: "prompt and messages cannot be defined at the same time"
|
910
|
+
});
|
911
|
+
}
|
912
|
+
if (prompt.system != null && typeof prompt.system !== "string") {
|
913
|
+
throw new InvalidPromptError({
|
914
|
+
prompt,
|
915
|
+
message: "system must be a string"
|
916
|
+
});
|
917
|
+
}
|
918
|
+
if (prompt.prompt != null) {
|
919
|
+
if (typeof prompt.prompt !== "string") {
|
920
|
+
throw new InvalidPromptError({
|
921
|
+
prompt,
|
922
|
+
message: "prompt must be a string"
|
923
|
+
});
|
924
|
+
}
|
925
|
+
return {
|
926
|
+
type: "prompt",
|
927
|
+
prompt: prompt.prompt,
|
928
|
+
messages: void 0,
|
929
|
+
system: prompt.system
|
930
|
+
};
|
931
|
+
}
|
932
|
+
if (prompt.messages != null) {
|
933
|
+
const validationResult = safeValidateTypes({
|
934
|
+
value: prompt.messages,
|
935
|
+
schema: z6.array(coreMessageSchema)
|
936
|
+
});
|
937
|
+
if (!validationResult.success) {
|
938
|
+
throw new InvalidPromptError({
|
939
|
+
prompt,
|
940
|
+
message: "messages must be an array of CoreMessage",
|
941
|
+
cause: validationResult.error
|
942
|
+
});
|
943
|
+
}
|
944
|
+
return {
|
945
|
+
type: "messages",
|
946
|
+
prompt: void 0,
|
947
|
+
messages: prompt.messages,
|
948
|
+
// only possible case bc of checks above
|
949
|
+
system: prompt.system
|
950
|
+
};
|
951
|
+
}
|
952
|
+
throw new Error("unreachable");
|
953
|
+
}
|
954
|
+
|
831
955
|
// core/types/token-usage.ts
|
832
956
|
function calculateCompletionTokenUsage(usage) {
|
833
957
|
return {
|
@@ -1224,7 +1348,7 @@ async function streamUI({
|
|
1224
1348
|
renderFinished.resolve(void 0);
|
1225
1349
|
}
|
1226
1350
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
1227
|
-
const validatedPrompt =
|
1351
|
+
const validatedPrompt = validatePrompt({ system, prompt, messages });
|
1228
1352
|
const result = await retry(
|
1229
1353
|
async () => model.doStream({
|
1230
1354
|
mode: {
|