@ai-sdk/google 2.0.89 → 2.0.93
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 +29 -0
- package/dist/index.js +94 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -18
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +93 -17
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +93 -17
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "2.0.
|
|
10
|
+
var VERSION = true ? "2.0.93" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-generative-ai-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -249,6 +249,10 @@ import { z as z5 } from "zod/v4";
|
|
|
249
249
|
import {
|
|
250
250
|
UnsupportedFunctionalityError
|
|
251
251
|
} from "@ai-sdk/provider";
|
|
252
|
+
var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
|
|
253
|
+
function isRecursiveJSONSchemaReferenceError(error) {
|
|
254
|
+
return UnsupportedFunctionalityError.isInstance(error) && error.functionality.startsWith(recursiveReferenceFunctionalityPrefix);
|
|
255
|
+
}
|
|
252
256
|
function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
253
257
|
const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
|
|
254
258
|
return convertJSONSchemaDefinition(jsonSchema, isRoot, {
|
|
@@ -299,9 +303,6 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
299
303
|
if (description) result.description = description;
|
|
300
304
|
if (required) result.required = required;
|
|
301
305
|
if (format) result.format = format;
|
|
302
|
-
if (constValue !== void 0) {
|
|
303
|
-
result.enum = [constValue];
|
|
304
|
-
}
|
|
305
306
|
if (type) {
|
|
306
307
|
if (Array.isArray(type)) {
|
|
307
308
|
const hasNull = type.includes("null");
|
|
@@ -318,8 +319,9 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
318
319
|
result.type = type;
|
|
319
320
|
}
|
|
320
321
|
}
|
|
321
|
-
|
|
322
|
-
|
|
322
|
+
const values = enumValues != null ? enumValues : constValue !== void 0 ? [constValue] : void 0;
|
|
323
|
+
if (values !== void 0) {
|
|
324
|
+
addEnumToSchema({ values, type, result });
|
|
323
325
|
}
|
|
324
326
|
if (properties != null) {
|
|
325
327
|
result.properties = Object.entries(properties).reduce(
|
|
@@ -379,6 +381,68 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
379
381
|
}
|
|
380
382
|
return result;
|
|
381
383
|
}
|
|
384
|
+
function addEnumToSchema({
|
|
385
|
+
values,
|
|
386
|
+
type,
|
|
387
|
+
result
|
|
388
|
+
}) {
|
|
389
|
+
const nullable = Array.isArray(type) && type.includes("null") || type === void 0 && values.includes(null);
|
|
390
|
+
const enumValues = nullable ? values.filter((value) => value !== null) : values;
|
|
391
|
+
if (values.length > 0 && values.every((value) => value === null)) {
|
|
392
|
+
const typeAllowsNull = type === void 0 || type === "null" || Array.isArray(type) && type.includes("null");
|
|
393
|
+
if (typeAllowsNull) {
|
|
394
|
+
result.type = "null";
|
|
395
|
+
if (Array.isArray(type)) {
|
|
396
|
+
delete result.anyOf;
|
|
397
|
+
}
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
const enumType = getEnumType({ values: enumValues, type });
|
|
402
|
+
if (enumType === void 0) {
|
|
403
|
+
throw new UnsupportedFunctionalityError({
|
|
404
|
+
functionality: "JSON Schema enum with mixed or unsupported values",
|
|
405
|
+
message: "Google does not support this JSON Schema enum. Enum values must share one supported primitive type and match the schema type."
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
result.type = enumType;
|
|
409
|
+
if (Array.isArray(type)) {
|
|
410
|
+
delete result.anyOf;
|
|
411
|
+
}
|
|
412
|
+
if (nullable) {
|
|
413
|
+
result.nullable = true;
|
|
414
|
+
}
|
|
415
|
+
if (enumType === "string") {
|
|
416
|
+
result.enum = enumValues;
|
|
417
|
+
} else {
|
|
418
|
+
result.format = "enum";
|
|
419
|
+
result.enum = enumValues.map(String);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
function getEnumType({
|
|
423
|
+
values,
|
|
424
|
+
type
|
|
425
|
+
}) {
|
|
426
|
+
if (values.length === 0) {
|
|
427
|
+
return void 0;
|
|
428
|
+
}
|
|
429
|
+
const typeAllows = (enumType) => type === void 0 || type === enumType || Array.isArray(type) && type.includes(enumType);
|
|
430
|
+
if (typeAllows("string") && values.every((value) => typeof value === "string")) {
|
|
431
|
+
return "string";
|
|
432
|
+
}
|
|
433
|
+
if ((typeAllows("number") || typeAllows("integer")) && values.every((value) => typeof value === "number" && Number.isFinite(value))) {
|
|
434
|
+
if (typeAllows("number")) {
|
|
435
|
+
return "number";
|
|
436
|
+
}
|
|
437
|
+
if (values.every((value) => Number.isInteger(value))) {
|
|
438
|
+
return "integer";
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (typeAllows("boolean") && values.every((value) => typeof value === "boolean")) {
|
|
442
|
+
return "boolean";
|
|
443
|
+
}
|
|
444
|
+
return void 0;
|
|
445
|
+
}
|
|
382
446
|
function convertJSONSchemaReference({
|
|
383
447
|
jsonSchema,
|
|
384
448
|
reference,
|
|
@@ -391,7 +455,7 @@ function convertJSONSchemaReference({
|
|
|
391
455
|
);
|
|
392
456
|
if (referenceContext.resolvingReferences.has(referenceKey)) {
|
|
393
457
|
throw new UnsupportedFunctionalityError({
|
|
394
|
-
functionality:
|
|
458
|
+
functionality: `${recursiveReferenceFunctionalityPrefix} ${reference}`,
|
|
395
459
|
message: "Google schema conversion does not support recursive JSON Schema references."
|
|
396
460
|
});
|
|
397
461
|
}
|
|
@@ -884,7 +948,6 @@ function prepareTools({
|
|
|
884
948
|
modelId,
|
|
885
949
|
isVertexProvider = false
|
|
886
950
|
}) {
|
|
887
|
-
var _a, _b;
|
|
888
951
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
889
952
|
const toolWarnings = [];
|
|
890
953
|
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
@@ -1005,11 +1068,7 @@ function prepareTools({
|
|
|
1005
1068
|
const functionDeclarations2 = [];
|
|
1006
1069
|
for (const tool of tools) {
|
|
1007
1070
|
if (tool.type === "function") {
|
|
1008
|
-
functionDeclarations2.push(
|
|
1009
|
-
name: tool.name,
|
|
1010
|
-
description: (_a = tool.description) != null ? _a : "",
|
|
1011
|
-
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
1012
|
-
});
|
|
1071
|
+
functionDeclarations2.push(prepareFunctionDeclaration(tool));
|
|
1013
1072
|
}
|
|
1014
1073
|
}
|
|
1015
1074
|
const combinedToolConfig = {
|
|
@@ -1053,11 +1112,7 @@ function prepareTools({
|
|
|
1053
1112
|
for (const tool of tools) {
|
|
1054
1113
|
switch (tool.type) {
|
|
1055
1114
|
case "function":
|
|
1056
|
-
functionDeclarations.push(
|
|
1057
|
-
name: tool.name,
|
|
1058
|
-
description: (_b = tool.description) != null ? _b : "",
|
|
1059
|
-
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
1060
|
-
});
|
|
1115
|
+
functionDeclarations.push(prepareFunctionDeclaration(tool));
|
|
1061
1116
|
if (tool.strict === true) {
|
|
1062
1117
|
hasStrictTools = true;
|
|
1063
1118
|
}
|
|
@@ -1121,6 +1176,27 @@ function prepareTools({
|
|
|
1121
1176
|
}
|
|
1122
1177
|
}
|
|
1123
1178
|
}
|
|
1179
|
+
function prepareFunctionDeclaration(tool) {
|
|
1180
|
+
var _a;
|
|
1181
|
+
const declaration = {
|
|
1182
|
+
name: tool.name,
|
|
1183
|
+
description: (_a = tool.description) != null ? _a : ""
|
|
1184
|
+
};
|
|
1185
|
+
try {
|
|
1186
|
+
return {
|
|
1187
|
+
...declaration,
|
|
1188
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
1189
|
+
};
|
|
1190
|
+
} catch (error) {
|
|
1191
|
+
if (!isRecursiveJSONSchemaReferenceError(error)) {
|
|
1192
|
+
throw error;
|
|
1193
|
+
}
|
|
1194
|
+
return {
|
|
1195
|
+
...declaration,
|
|
1196
|
+
parametersJsonSchema: tool.inputSchema
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1124
1200
|
|
|
1125
1201
|
// src/map-google-generative-ai-finish-reason.ts
|
|
1126
1202
|
function mapGoogleGenerativeAIFinishReason({
|