@ai-sdk/google 4.0.39 → 4.0.41
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 +14 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +79 -15
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +78 -14
- package/dist/internal/index.js.map +1 -1
- package/package.json +2 -2
- package/src/convert-json-schema-to-openapi-schema.ts +127 -8
- package/src/google-error.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.41
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- da78d58: fix(google): convert enum values to the Gemini schema format
|
|
8
|
+
- 8a2482d: Preserve Google API error details in `APICallError.data`.
|
|
9
|
+
|
|
10
|
+
## 4.0.40
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [401a4ba]
|
|
15
|
+
- @ai-sdk/provider-utils@5.0.26
|
|
16
|
+
|
|
3
17
|
## 4.0.39
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "4.0.
|
|
10
|
+
var VERSION = true ? "4.0.41" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -40,7 +40,8 @@ var googleErrorDataSchema = lazySchema(
|
|
|
40
40
|
error: z.object({
|
|
41
41
|
code: z.number().nullable(),
|
|
42
42
|
message: z.string(),
|
|
43
|
-
status: z.string()
|
|
43
|
+
status: z.string(),
|
|
44
|
+
details: z.array(z.unknown()).nullish()
|
|
44
45
|
})
|
|
45
46
|
})
|
|
46
47
|
)
|
|
@@ -298,6 +299,9 @@ function convertGoogleUsage(usage) {
|
|
|
298
299
|
}
|
|
299
300
|
|
|
300
301
|
// src/convert-json-schema-to-openapi-schema.ts
|
|
302
|
+
import {
|
|
303
|
+
UnsupportedFunctionalityError
|
|
304
|
+
} from "@ai-sdk/provider";
|
|
301
305
|
function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
302
306
|
if (jsonSchema == null) {
|
|
303
307
|
return void 0;
|
|
@@ -332,9 +336,6 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
332
336
|
if (description) result.description = description;
|
|
333
337
|
if (required) result.required = required;
|
|
334
338
|
if (format) result.format = format;
|
|
335
|
-
if (constValue !== void 0) {
|
|
336
|
-
result.enum = [constValue];
|
|
337
|
-
}
|
|
338
339
|
if (type) {
|
|
339
340
|
if (Array.isArray(type)) {
|
|
340
341
|
const hasNull = type.includes("null");
|
|
@@ -351,8 +352,9 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
351
352
|
result.type = type;
|
|
352
353
|
}
|
|
353
354
|
}
|
|
354
|
-
|
|
355
|
-
|
|
355
|
+
const values = enumValues != null ? enumValues : constValue !== void 0 ? [constValue] : void 0;
|
|
356
|
+
if (values !== void 0) {
|
|
357
|
+
addEnumToSchema({ values, type, result });
|
|
356
358
|
}
|
|
357
359
|
if (properties != null) {
|
|
358
360
|
result.properties = Object.entries(properties).reduce(
|
|
@@ -409,13 +411,75 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
|
|
|
409
411
|
}
|
|
410
412
|
return result;
|
|
411
413
|
}
|
|
414
|
+
function addEnumToSchema({
|
|
415
|
+
values,
|
|
416
|
+
type,
|
|
417
|
+
result
|
|
418
|
+
}) {
|
|
419
|
+
const nullable = Array.isArray(type) && type.includes("null") || type === void 0 && values.includes(null);
|
|
420
|
+
const enumValues = nullable ? values.filter((value) => value !== null) : values;
|
|
421
|
+
if (values.length > 0 && values.every((value) => value === null)) {
|
|
422
|
+
const typeAllowsNull = type === void 0 || type === "null" || Array.isArray(type) && type.includes("null");
|
|
423
|
+
if (typeAllowsNull) {
|
|
424
|
+
result.type = "null";
|
|
425
|
+
if (Array.isArray(type)) {
|
|
426
|
+
delete result.anyOf;
|
|
427
|
+
}
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
const enumType = getEnumType({ values: enumValues, type });
|
|
432
|
+
if (enumType === void 0) {
|
|
433
|
+
throw new UnsupportedFunctionalityError({
|
|
434
|
+
functionality: "JSON Schema enum with mixed or unsupported values",
|
|
435
|
+
message: "Google does not support this JSON Schema enum. Enum values must share one supported primitive type and match the schema type."
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
result.type = enumType;
|
|
439
|
+
if (Array.isArray(type)) {
|
|
440
|
+
delete result.anyOf;
|
|
441
|
+
}
|
|
442
|
+
if (nullable) {
|
|
443
|
+
result.nullable = true;
|
|
444
|
+
}
|
|
445
|
+
if (enumType === "string") {
|
|
446
|
+
result.enum = enumValues;
|
|
447
|
+
} else {
|
|
448
|
+
result.format = "enum";
|
|
449
|
+
result.enum = enumValues.map(String);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
function getEnumType({
|
|
453
|
+
values,
|
|
454
|
+
type
|
|
455
|
+
}) {
|
|
456
|
+
if (values.length === 0) {
|
|
457
|
+
return void 0;
|
|
458
|
+
}
|
|
459
|
+
const typeAllows = (enumType) => type === void 0 || type === enumType || Array.isArray(type) && type.includes(enumType);
|
|
460
|
+
if (typeAllows("string") && values.every((value) => typeof value === "string")) {
|
|
461
|
+
return "string";
|
|
462
|
+
}
|
|
463
|
+
if ((typeAllows("number") || typeAllows("integer")) && values.every((value) => typeof value === "number" && Number.isFinite(value))) {
|
|
464
|
+
if (typeAllows("number")) {
|
|
465
|
+
return "number";
|
|
466
|
+
}
|
|
467
|
+
if (values.every((value) => Number.isInteger(value))) {
|
|
468
|
+
return "integer";
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
if (typeAllows("boolean") && values.every((value) => typeof value === "boolean")) {
|
|
472
|
+
return "boolean";
|
|
473
|
+
}
|
|
474
|
+
return void 0;
|
|
475
|
+
}
|
|
412
476
|
function isEmptyObjectSchema(jsonSchema) {
|
|
413
477
|
return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
|
|
414
478
|
}
|
|
415
479
|
|
|
416
480
|
// src/convert-to-google-messages.ts
|
|
417
481
|
import {
|
|
418
|
-
UnsupportedFunctionalityError
|
|
482
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
419
483
|
} from "@ai-sdk/provider";
|
|
420
484
|
import {
|
|
421
485
|
convertToBase64,
|
|
@@ -572,7 +636,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
572
636
|
switch (role) {
|
|
573
637
|
case "system": {
|
|
574
638
|
if (!systemMessagesAllowed) {
|
|
575
|
-
throw new
|
|
639
|
+
throw new UnsupportedFunctionalityError2({
|
|
576
640
|
functionality: "system messages are only supported at the beginning of the conversation"
|
|
577
641
|
});
|
|
578
642
|
}
|
|
@@ -601,7 +665,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
601
665
|
}
|
|
602
666
|
case "reference": {
|
|
603
667
|
if (isVertexLike) {
|
|
604
|
-
throw new
|
|
668
|
+
throw new UnsupportedFunctionalityError2({
|
|
605
669
|
functionality: "file parts with provider references"
|
|
606
670
|
});
|
|
607
671
|
}
|
|
@@ -669,7 +733,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
669
733
|
case "reasoning-file": {
|
|
670
734
|
switch (part.data.type) {
|
|
671
735
|
case "url": {
|
|
672
|
-
throw new
|
|
736
|
+
throw new UnsupportedFunctionalityError2({
|
|
673
737
|
functionality: "File data URLs in assistant messages are not supported"
|
|
674
738
|
});
|
|
675
739
|
}
|
|
@@ -689,13 +753,13 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
689
753
|
case "file": {
|
|
690
754
|
switch (part.data.type) {
|
|
691
755
|
case "url": {
|
|
692
|
-
throw new
|
|
756
|
+
throw new UnsupportedFunctionalityError2({
|
|
693
757
|
functionality: "File data URLs in assistant messages are not supported"
|
|
694
758
|
});
|
|
695
759
|
}
|
|
696
760
|
case "reference": {
|
|
697
761
|
if (isVertexLike) {
|
|
698
|
-
throw new
|
|
762
|
+
throw new UnsupportedFunctionalityError2({
|
|
699
763
|
functionality: "file parts with provider references"
|
|
700
764
|
});
|
|
701
765
|
}
|
|
@@ -1093,7 +1157,7 @@ function getGoogleModelCapabilities(modelId) {
|
|
|
1093
1157
|
|
|
1094
1158
|
// src/google-prepare-tools.ts
|
|
1095
1159
|
import {
|
|
1096
|
-
UnsupportedFunctionalityError as
|
|
1160
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
1097
1161
|
} from "@ai-sdk/provider";
|
|
1098
1162
|
function prepareTools({
|
|
1099
1163
|
tools,
|
|
@@ -1332,7 +1396,7 @@ function prepareTools({
|
|
|
1332
1396
|
};
|
|
1333
1397
|
default: {
|
|
1334
1398
|
const _exhaustiveCheck = type;
|
|
1335
|
-
throw new
|
|
1399
|
+
throw new UnsupportedFunctionalityError3({
|
|
1336
1400
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
1337
1401
|
});
|
|
1338
1402
|
}
|