ai 3.3.11 → 3.3.12
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 +174 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +164 -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 +157 -40
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/dist/index.mjs
CHANGED
@@ -730,15 +730,13 @@ var InvalidDataContentError = class extends AISDKError3 {
|
|
730
730
|
_a3 = symbol3;
|
731
731
|
|
732
732
|
// core/prompt/data-content.ts
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
return convertUint8ArrayToBase64(content);
|
741
|
-
}
|
733
|
+
import { z } from "zod";
|
734
|
+
var dataContentSchema = z.union([
|
735
|
+
z.string(),
|
736
|
+
z.instanceof(Uint8Array),
|
737
|
+
z.instanceof(ArrayBuffer),
|
738
|
+
z.instanceof(Buffer)
|
739
|
+
]);
|
742
740
|
function convertDataContentToUint8Array(content) {
|
743
741
|
if (content instanceof Uint8Array) {
|
744
742
|
return content;
|
@@ -1013,45 +1011,6 @@ async function downloadImages(messages, downloadImplementation) {
|
|
1013
1011
|
);
|
1014
1012
|
}
|
1015
1013
|
|
1016
|
-
// core/prompt/get-validated-prompt.ts
|
1017
|
-
import { InvalidPromptError } from "@ai-sdk/provider";
|
1018
|
-
function getValidatedPrompt(prompt) {
|
1019
|
-
if (prompt.prompt == null && prompt.messages == null) {
|
1020
|
-
throw new InvalidPromptError({
|
1021
|
-
prompt,
|
1022
|
-
message: "prompt or messages must be defined"
|
1023
|
-
});
|
1024
|
-
}
|
1025
|
-
if (prompt.prompt != null && prompt.messages != null) {
|
1026
|
-
throw new InvalidPromptError({
|
1027
|
-
prompt,
|
1028
|
-
message: "prompt and messages cannot be defined at the same time"
|
1029
|
-
});
|
1030
|
-
}
|
1031
|
-
if (prompt.messages != null) {
|
1032
|
-
for (const message of prompt.messages) {
|
1033
|
-
if (message.role === "system" && typeof message.content !== "string") {
|
1034
|
-
throw new InvalidPromptError({
|
1035
|
-
prompt,
|
1036
|
-
message: "system message content must be a string"
|
1037
|
-
});
|
1038
|
-
}
|
1039
|
-
}
|
1040
|
-
}
|
1041
|
-
return prompt.prompt != null ? {
|
1042
|
-
type: "prompt",
|
1043
|
-
prompt: prompt.prompt,
|
1044
|
-
messages: void 0,
|
1045
|
-
system: prompt.system
|
1046
|
-
} : {
|
1047
|
-
type: "messages",
|
1048
|
-
prompt: void 0,
|
1049
|
-
messages: prompt.messages,
|
1050
|
-
// only possible case bc of checks above
|
1051
|
-
system: prompt.system
|
1052
|
-
};
|
1053
|
-
}
|
1054
|
-
|
1055
1014
|
// errors/invalid-argument-error.ts
|
1056
1015
|
import { AISDKError as AISDKError5 } from "@ai-sdk/provider";
|
1057
1016
|
var name5 = "AI_InvalidArgumentError";
|
@@ -1193,6 +1152,155 @@ function prepareCallSettings({
|
|
1193
1152
|
};
|
1194
1153
|
}
|
1195
1154
|
|
1155
|
+
// core/prompt/validate-prompt.ts
|
1156
|
+
import { InvalidPromptError } from "@ai-sdk/provider";
|
1157
|
+
import { safeValidateTypes } from "@ai-sdk/provider-utils";
|
1158
|
+
import { z as z6 } from "zod";
|
1159
|
+
|
1160
|
+
// core/prompt/message.ts
|
1161
|
+
import { z as z5 } from "zod";
|
1162
|
+
|
1163
|
+
// core/types/provider-metadata.ts
|
1164
|
+
import { z as z3 } from "zod";
|
1165
|
+
|
1166
|
+
// core/types/json-value.ts
|
1167
|
+
import { z as z2 } from "zod";
|
1168
|
+
var jsonValueSchema = z2.lazy(
|
1169
|
+
() => z2.union([
|
1170
|
+
z2.null(),
|
1171
|
+
z2.string(),
|
1172
|
+
z2.number(),
|
1173
|
+
z2.boolean(),
|
1174
|
+
z2.record(z2.string(), jsonValueSchema),
|
1175
|
+
z2.array(jsonValueSchema)
|
1176
|
+
])
|
1177
|
+
);
|
1178
|
+
|
1179
|
+
// core/types/provider-metadata.ts
|
1180
|
+
var providerMetadataSchema = z3.record(
|
1181
|
+
z3.string(),
|
1182
|
+
z3.record(z3.string(), jsonValueSchema)
|
1183
|
+
);
|
1184
|
+
|
1185
|
+
// core/prompt/content-part.ts
|
1186
|
+
import { z as z4 } from "zod";
|
1187
|
+
var textPartSchema = z4.object({
|
1188
|
+
type: z4.literal("text"),
|
1189
|
+
text: z4.string(),
|
1190
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1191
|
+
});
|
1192
|
+
var imagePartSchema = z4.object({
|
1193
|
+
type: z4.literal("image"),
|
1194
|
+
image: z4.union([dataContentSchema, z4.instanceof(URL)]),
|
1195
|
+
mimeType: z4.string().optional(),
|
1196
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1197
|
+
});
|
1198
|
+
var toolCallPartSchema = z4.object({
|
1199
|
+
type: z4.literal("tool-call"),
|
1200
|
+
toolCallId: z4.string(),
|
1201
|
+
toolName: z4.string(),
|
1202
|
+
args: z4.unknown()
|
1203
|
+
});
|
1204
|
+
var toolResultPartSchema = z4.object({
|
1205
|
+
type: z4.literal("tool-result"),
|
1206
|
+
toolCallId: z4.string(),
|
1207
|
+
toolName: z4.string(),
|
1208
|
+
result: z4.unknown(),
|
1209
|
+
isError: z4.boolean().optional(),
|
1210
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1211
|
+
});
|
1212
|
+
|
1213
|
+
// core/prompt/message.ts
|
1214
|
+
var coreSystemMessageSchema = z5.object({
|
1215
|
+
role: z5.literal("system"),
|
1216
|
+
content: z5.string(),
|
1217
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1218
|
+
});
|
1219
|
+
var coreUserMessageSchema = z5.object({
|
1220
|
+
role: z5.literal("user"),
|
1221
|
+
content: z5.union([
|
1222
|
+
z5.string(),
|
1223
|
+
z5.array(z5.union([textPartSchema, imagePartSchema]))
|
1224
|
+
]),
|
1225
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1226
|
+
});
|
1227
|
+
var coreAssistantMessageSchema = z5.object({
|
1228
|
+
role: z5.literal("assistant"),
|
1229
|
+
content: z5.union([
|
1230
|
+
z5.string(),
|
1231
|
+
z5.array(z5.union([textPartSchema, toolCallPartSchema]))
|
1232
|
+
]),
|
1233
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1234
|
+
});
|
1235
|
+
var coreToolMessageSchema = z5.object({
|
1236
|
+
role: z5.literal("tool"),
|
1237
|
+
content: z5.array(toolResultPartSchema),
|
1238
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1239
|
+
});
|
1240
|
+
var coreMessageSchema = z5.union([
|
1241
|
+
coreSystemMessageSchema,
|
1242
|
+
coreUserMessageSchema,
|
1243
|
+
coreAssistantMessageSchema,
|
1244
|
+
coreToolMessageSchema
|
1245
|
+
]);
|
1246
|
+
|
1247
|
+
// core/prompt/validate-prompt.ts
|
1248
|
+
function validatePrompt(prompt) {
|
1249
|
+
if (prompt.prompt == null && prompt.messages == null) {
|
1250
|
+
throw new InvalidPromptError({
|
1251
|
+
prompt,
|
1252
|
+
message: "prompt or messages must be defined"
|
1253
|
+
});
|
1254
|
+
}
|
1255
|
+
if (prompt.prompt != null && prompt.messages != null) {
|
1256
|
+
throw new InvalidPromptError({
|
1257
|
+
prompt,
|
1258
|
+
message: "prompt and messages cannot be defined at the same time"
|
1259
|
+
});
|
1260
|
+
}
|
1261
|
+
if (prompt.system != null && typeof prompt.system !== "string") {
|
1262
|
+
throw new InvalidPromptError({
|
1263
|
+
prompt,
|
1264
|
+
message: "system must be a string"
|
1265
|
+
});
|
1266
|
+
}
|
1267
|
+
if (prompt.prompt != null) {
|
1268
|
+
if (typeof prompt.prompt !== "string") {
|
1269
|
+
throw new InvalidPromptError({
|
1270
|
+
prompt,
|
1271
|
+
message: "prompt must be a string"
|
1272
|
+
});
|
1273
|
+
}
|
1274
|
+
return {
|
1275
|
+
type: "prompt",
|
1276
|
+
prompt: prompt.prompt,
|
1277
|
+
messages: void 0,
|
1278
|
+
system: prompt.system
|
1279
|
+
};
|
1280
|
+
}
|
1281
|
+
if (prompt.messages != null) {
|
1282
|
+
const validationResult = safeValidateTypes({
|
1283
|
+
value: prompt.messages,
|
1284
|
+
schema: z6.array(coreMessageSchema)
|
1285
|
+
});
|
1286
|
+
if (!validationResult.success) {
|
1287
|
+
throw new InvalidPromptError({
|
1288
|
+
prompt,
|
1289
|
+
message: "messages must be an array of CoreMessage",
|
1290
|
+
cause: validationResult.error
|
1291
|
+
});
|
1292
|
+
}
|
1293
|
+
return {
|
1294
|
+
type: "messages",
|
1295
|
+
prompt: void 0,
|
1296
|
+
messages: prompt.messages,
|
1297
|
+
// only possible case bc of checks above
|
1298
|
+
system: prompt.system
|
1299
|
+
};
|
1300
|
+
}
|
1301
|
+
throw new Error("unreachable");
|
1302
|
+
}
|
1303
|
+
|
1196
1304
|
// core/types/token-usage.ts
|
1197
1305
|
function calculateCompletionTokenUsage(usage) {
|
1198
1306
|
return {
|
@@ -1334,7 +1442,7 @@ async function generateObject({
|
|
1334
1442
|
let providerMetadata;
|
1335
1443
|
switch (mode) {
|
1336
1444
|
case "json": {
|
1337
|
-
const validatedPrompt =
|
1445
|
+
const validatedPrompt = validatePrompt({
|
1338
1446
|
system: model.supportsStructuredOutputs ? system : injectJsonSchemaIntoSystem({
|
1339
1447
|
system,
|
1340
1448
|
schema: schema.jsonSchema
|
@@ -1420,7 +1528,7 @@ async function generateObject({
|
|
1420
1528
|
break;
|
1421
1529
|
}
|
1422
1530
|
case "tool": {
|
1423
|
-
const validatedPrompt =
|
1531
|
+
const validatedPrompt = validatePrompt({
|
1424
1532
|
system,
|
1425
1533
|
prompt,
|
1426
1534
|
messages
|
@@ -1569,7 +1677,7 @@ var DefaultGenerateObjectResult = class {
|
|
1569
1677
|
var experimental_generateObject = generateObject;
|
1570
1678
|
|
1571
1679
|
// core/generate-object/stream-object.ts
|
1572
|
-
import { safeValidateTypes } from "@ai-sdk/provider-utils";
|
1680
|
+
import { safeValidateTypes as safeValidateTypes2 } from "@ai-sdk/provider-utils";
|
1573
1681
|
import {
|
1574
1682
|
asSchema as asSchema2,
|
1575
1683
|
isDeepEqualData,
|
@@ -1703,7 +1811,7 @@ async function streamObject({
|
|
1703
1811
|
let transformer;
|
1704
1812
|
switch (mode) {
|
1705
1813
|
case "json": {
|
1706
|
-
const validatedPrompt =
|
1814
|
+
const validatedPrompt = validatePrompt({
|
1707
1815
|
system: model.supportsStructuredOutputs ? system : injectJsonSchemaIntoSystem({
|
1708
1816
|
system,
|
1709
1817
|
schema: schema.jsonSchema
|
@@ -1743,7 +1851,7 @@ async function streamObject({
|
|
1743
1851
|
break;
|
1744
1852
|
}
|
1745
1853
|
case "tool": {
|
1746
|
-
const validatedPrompt =
|
1854
|
+
const validatedPrompt = validatePrompt({
|
1747
1855
|
system,
|
1748
1856
|
prompt,
|
1749
1857
|
messages
|
@@ -1925,7 +2033,7 @@ var DefaultStreamObjectResult = class {
|
|
1925
2033
|
controller.enqueue({ ...chunk, usage });
|
1926
2034
|
resolveUsage(usage);
|
1927
2035
|
resolveProviderMetadata(providerMetadata);
|
1928
|
-
const validationResult =
|
2036
|
+
const validationResult = safeValidateTypes2({
|
1929
2037
|
value: latestObject,
|
1930
2038
|
schema
|
1931
2039
|
});
|
@@ -2286,7 +2394,7 @@ async function generateText({
|
|
2286
2394
|
fn: async (span) => {
|
2287
2395
|
var _a13, _b, _c, _d;
|
2288
2396
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
2289
|
-
const validatedPrompt =
|
2397
|
+
const validatedPrompt = validatePrompt({
|
2290
2398
|
system,
|
2291
2399
|
prompt,
|
2292
2400
|
messages
|
@@ -2863,7 +2971,7 @@ async function streamText({
|
|
2863
2971
|
endWhenDone: false,
|
2864
2972
|
fn: async (rootSpan) => {
|
2865
2973
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
2866
|
-
const validatedPrompt =
|
2974
|
+
const validatedPrompt = validatePrompt({ system, prompt, messages });
|
2867
2975
|
const promptMessages = await convertToLanguageModelPrompt({
|
2868
2976
|
prompt: validatedPrompt,
|
2869
2977
|
modelSupportsImageUrls: model.supportsImageUrls
|
@@ -4738,10 +4846,7 @@ export {
|
|
4738
4846
|
StreamingTextResponse,
|
4739
4847
|
TypeValidationError,
|
4740
4848
|
UnsupportedFunctionalityError,
|
4741
|
-
convertDataContentToBase64String,
|
4742
|
-
convertDataContentToUint8Array,
|
4743
4849
|
convertToCoreMessages,
|
4744
|
-
convertUint8ArrayToText,
|
4745
4850
|
cosineSimilarity,
|
4746
4851
|
createCallbacksTransformer,
|
4747
4852
|
createEventStreamTransformer,
|