@ai-sdk/google 2.0.90 → 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 +22 -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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 2.0.93
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a3fe2a8: fix(google): convert enum values to the Gemini schema format
|
|
8
|
+
|
|
9
|
+
## 2.0.92
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [77d33c0]
|
|
14
|
+
- @ai-sdk/provider-utils@3.0.35
|
|
15
|
+
|
|
16
|
+
## 2.0.91
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- b616db6: Preserve recursive tool input schemas without aborting Google model calls.
|
|
21
|
+
- Updated dependencies [2fff9f1]
|
|
22
|
+
- Updated dependencies [f364ea0]
|
|
23
|
+
- @ai-sdk/provider-utils@3.0.34
|
|
24
|
+
|
|
3
25
|
## 2.0.90
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
30
30
|
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "2.0.
|
|
33
|
+
var VERSION = true ? "2.0.93" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -243,6 +243,10 @@ var import_v45 = require("zod/v4");
|
|
|
243
243
|
|
|
244
244
|
// src/convert-json-schema-to-openapi-schema.ts
|
|
245
245
|
var import_provider2 = require("@ai-sdk/provider");
|
|
246
|
+
var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
|
|
247
|
+
function isRecursiveJSONSchemaReferenceError(error) {
|
|
248
|
+
return import_provider2.UnsupportedFunctionalityError.isInstance(error) && error.functionality.startsWith(recursiveReferenceFunctionalityPrefix);
|
|
249
|
+
}
|
|
246
250
|
function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
247
251
|
const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
|
|
248
252
|
return convertJSONSchemaDefinition(jsonSchema, isRoot, {
|
|
@@ -293,9 +297,6 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
293
297
|
if (description) result.description = description;
|
|
294
298
|
if (required) result.required = required;
|
|
295
299
|
if (format) result.format = format;
|
|
296
|
-
if (constValue !== void 0) {
|
|
297
|
-
result.enum = [constValue];
|
|
298
|
-
}
|
|
299
300
|
if (type) {
|
|
300
301
|
if (Array.isArray(type)) {
|
|
301
302
|
const hasNull = type.includes("null");
|
|
@@ -312,8 +313,9 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
312
313
|
result.type = type;
|
|
313
314
|
}
|
|
314
315
|
}
|
|
315
|
-
|
|
316
|
-
|
|
316
|
+
const values = enumValues != null ? enumValues : constValue !== void 0 ? [constValue] : void 0;
|
|
317
|
+
if (values !== void 0) {
|
|
318
|
+
addEnumToSchema({ values, type, result });
|
|
317
319
|
}
|
|
318
320
|
if (properties != null) {
|
|
319
321
|
result.properties = Object.entries(properties).reduce(
|
|
@@ -373,6 +375,68 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
|
|
|
373
375
|
}
|
|
374
376
|
return result;
|
|
375
377
|
}
|
|
378
|
+
function addEnumToSchema({
|
|
379
|
+
values,
|
|
380
|
+
type,
|
|
381
|
+
result
|
|
382
|
+
}) {
|
|
383
|
+
const nullable = Array.isArray(type) && type.includes("null") || type === void 0 && values.includes(null);
|
|
384
|
+
const enumValues = nullable ? values.filter((value) => value !== null) : values;
|
|
385
|
+
if (values.length > 0 && values.every((value) => value === null)) {
|
|
386
|
+
const typeAllowsNull = type === void 0 || type === "null" || Array.isArray(type) && type.includes("null");
|
|
387
|
+
if (typeAllowsNull) {
|
|
388
|
+
result.type = "null";
|
|
389
|
+
if (Array.isArray(type)) {
|
|
390
|
+
delete result.anyOf;
|
|
391
|
+
}
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
const enumType = getEnumType({ values: enumValues, type });
|
|
396
|
+
if (enumType === void 0) {
|
|
397
|
+
throw new import_provider2.UnsupportedFunctionalityError({
|
|
398
|
+
functionality: "JSON Schema enum with mixed or unsupported values",
|
|
399
|
+
message: "Google does not support this JSON Schema enum. Enum values must share one supported primitive type and match the schema type."
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
result.type = enumType;
|
|
403
|
+
if (Array.isArray(type)) {
|
|
404
|
+
delete result.anyOf;
|
|
405
|
+
}
|
|
406
|
+
if (nullable) {
|
|
407
|
+
result.nullable = true;
|
|
408
|
+
}
|
|
409
|
+
if (enumType === "string") {
|
|
410
|
+
result.enum = enumValues;
|
|
411
|
+
} else {
|
|
412
|
+
result.format = "enum";
|
|
413
|
+
result.enum = enumValues.map(String);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
function getEnumType({
|
|
417
|
+
values,
|
|
418
|
+
type
|
|
419
|
+
}) {
|
|
420
|
+
if (values.length === 0) {
|
|
421
|
+
return void 0;
|
|
422
|
+
}
|
|
423
|
+
const typeAllows = (enumType) => type === void 0 || type === enumType || Array.isArray(type) && type.includes(enumType);
|
|
424
|
+
if (typeAllows("string") && values.every((value) => typeof value === "string")) {
|
|
425
|
+
return "string";
|
|
426
|
+
}
|
|
427
|
+
if ((typeAllows("number") || typeAllows("integer")) && values.every((value) => typeof value === "number" && Number.isFinite(value))) {
|
|
428
|
+
if (typeAllows("number")) {
|
|
429
|
+
return "number";
|
|
430
|
+
}
|
|
431
|
+
if (values.every((value) => Number.isInteger(value))) {
|
|
432
|
+
return "integer";
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
if (typeAllows("boolean") && values.every((value) => typeof value === "boolean")) {
|
|
436
|
+
return "boolean";
|
|
437
|
+
}
|
|
438
|
+
return void 0;
|
|
439
|
+
}
|
|
376
440
|
function convertJSONSchemaReference({
|
|
377
441
|
jsonSchema,
|
|
378
442
|
reference,
|
|
@@ -385,7 +449,7 @@ function convertJSONSchemaReference({
|
|
|
385
449
|
);
|
|
386
450
|
if (referenceContext.resolvingReferences.has(referenceKey)) {
|
|
387
451
|
throw new import_provider2.UnsupportedFunctionalityError({
|
|
388
|
-
functionality:
|
|
452
|
+
functionality: `${recursiveReferenceFunctionalityPrefix} ${reference}`,
|
|
389
453
|
message: "Google schema conversion does not support recursive JSON Schema references."
|
|
390
454
|
});
|
|
391
455
|
}
|
|
@@ -871,7 +935,6 @@ function prepareTools({
|
|
|
871
935
|
modelId,
|
|
872
936
|
isVertexProvider = false
|
|
873
937
|
}) {
|
|
874
|
-
var _a, _b;
|
|
875
938
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
876
939
|
const toolWarnings = [];
|
|
877
940
|
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
@@ -992,11 +1055,7 @@ function prepareTools({
|
|
|
992
1055
|
const functionDeclarations2 = [];
|
|
993
1056
|
for (const tool of tools) {
|
|
994
1057
|
if (tool.type === "function") {
|
|
995
|
-
functionDeclarations2.push(
|
|
996
|
-
name: tool.name,
|
|
997
|
-
description: (_a = tool.description) != null ? _a : "",
|
|
998
|
-
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
999
|
-
});
|
|
1058
|
+
functionDeclarations2.push(prepareFunctionDeclaration(tool));
|
|
1000
1059
|
}
|
|
1001
1060
|
}
|
|
1002
1061
|
const combinedToolConfig = {
|
|
@@ -1040,11 +1099,7 @@ function prepareTools({
|
|
|
1040
1099
|
for (const tool of tools) {
|
|
1041
1100
|
switch (tool.type) {
|
|
1042
1101
|
case "function":
|
|
1043
|
-
functionDeclarations.push(
|
|
1044
|
-
name: tool.name,
|
|
1045
|
-
description: (_b = tool.description) != null ? _b : "",
|
|
1046
|
-
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
1047
|
-
});
|
|
1102
|
+
functionDeclarations.push(prepareFunctionDeclaration(tool));
|
|
1048
1103
|
if (tool.strict === true) {
|
|
1049
1104
|
hasStrictTools = true;
|
|
1050
1105
|
}
|
|
@@ -1108,6 +1163,27 @@ function prepareTools({
|
|
|
1108
1163
|
}
|
|
1109
1164
|
}
|
|
1110
1165
|
}
|
|
1166
|
+
function prepareFunctionDeclaration(tool) {
|
|
1167
|
+
var _a;
|
|
1168
|
+
const declaration = {
|
|
1169
|
+
name: tool.name,
|
|
1170
|
+
description: (_a = tool.description) != null ? _a : ""
|
|
1171
|
+
};
|
|
1172
|
+
try {
|
|
1173
|
+
return {
|
|
1174
|
+
...declaration,
|
|
1175
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
1176
|
+
};
|
|
1177
|
+
} catch (error) {
|
|
1178
|
+
if (!isRecursiveJSONSchemaReferenceError(error)) {
|
|
1179
|
+
throw error;
|
|
1180
|
+
}
|
|
1181
|
+
return {
|
|
1182
|
+
...declaration,
|
|
1183
|
+
parametersJsonSchema: tool.inputSchema
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1111
1187
|
|
|
1112
1188
|
// src/map-google-generative-ai-finish-reason.ts
|
|
1113
1189
|
function mapGoogleGenerativeAIFinishReason({
|