@ai-sdk/google
Advanced tools
+1
-0
@@ -11,2 +11,3 @@ import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils'; | ||
| status: string; | ||
| details?: unknown[] | null | undefined; | ||
| }; | ||
@@ -13,0 +14,0 @@ }>; |
+3
-3
| { | ||
| "name": "@ai-sdk/google", | ||
| "version": "4.0.40", | ||
| "version": "4.0.41", | ||
| "type": "module", | ||
@@ -46,4 +46,4 @@ "license": "Apache-2.0", | ||
| "zod": "3.25.76", | ||
| "@vercel/ai-tsconfig": "0.0.0", | ||
| "@ai-sdk/test-server": "2.0.1" | ||
| "@ai-sdk/test-server": "2.0.1", | ||
| "@vercel/ai-tsconfig": "0.0.0" | ||
| }, | ||
@@ -50,0 +50,0 @@ "peerDependencies": { |
@@ -1,2 +0,6 @@ | ||
| import type { JSONSchema7Definition } from '@ai-sdk/provider'; | ||
| import { | ||
| UnsupportedFunctionalityError, | ||
| type JSONSchema7, | ||
| type JSONSchema7Definition, | ||
| } from '@ai-sdk/provider'; | ||
@@ -51,6 +55,2 @@ /** | ||
| if (constValue !== undefined) { | ||
| result.enum = [constValue]; | ||
| } | ||
| // Handle type | ||
@@ -77,5 +77,7 @@ if (type) { | ||
| // Handle enum | ||
| if (enumValues !== undefined) { | ||
| result.enum = enumValues; | ||
| const values = | ||
| enumValues ?? (constValue !== undefined ? [constValue] : undefined); | ||
| if (values !== undefined) { | ||
| addEnumToSchema({ values, type, result }); | ||
| } | ||
@@ -151,2 +153,119 @@ | ||
| type EnumValues = NonNullable<JSONSchema7['enum']>; | ||
| type EnumType = 'string' | 'number' | 'integer' | 'boolean'; | ||
| type GoogleEnumSchema = { | ||
| type?: JSONSchema7['type']; | ||
| enum?: JSONSchema7['enum']; | ||
| format?: JSONSchema7['format']; | ||
| anyOf?: JSONSchema7['anyOf']; | ||
| nullable?: boolean; | ||
| }; | ||
| function addEnumToSchema({ | ||
| values, | ||
| type, | ||
| result, | ||
| }: { | ||
| values: EnumValues; | ||
| type: JSONSchema7['type']; | ||
| result: GoogleEnumSchema; | ||
| }) { | ||
| const nullable = | ||
| (Array.isArray(type) && type.includes('null')) || | ||
| (type === undefined && values.includes(null)); | ||
| // Gemini uses nullable instead of a null enum member. | ||
| const enumValues = nullable ? values.filter(value => value !== null) : values; | ||
| if (values.length > 0 && values.every(value => value === null)) { | ||
| const typeAllowsNull = | ||
| type === undefined || | ||
| type === 'null' || | ||
| (Array.isArray(type) && type.includes('null')); | ||
| if (typeAllowsNull) { | ||
| result.type = 'null'; | ||
| if (Array.isArray(type)) { | ||
| delete result.anyOf; | ||
| } | ||
| return; | ||
| } | ||
| } | ||
| const enumType = getEnumType({ values: enumValues, type }); | ||
| if (enumType === undefined) { | ||
| throw new UnsupportedFunctionalityError({ | ||
| functionality: 'JSON Schema enum with mixed or unsupported values', | ||
| message: | ||
| 'Google does not support this JSON Schema enum. Enum values must share one supported primitive type and match the schema type.', | ||
| }); | ||
| } | ||
| result.type = enumType; | ||
| // The earlier type-array conversion created anyOf. The enum gives us one | ||
| // concrete value type, so store that type directly. | ||
| if (Array.isArray(type)) { | ||
| delete result.anyOf; | ||
| } | ||
| if (nullable) { | ||
| result.nullable = true; | ||
| } | ||
| if (enumType === 'string') { | ||
| result.enum = enumValues; | ||
| } else { | ||
| result.format = 'enum'; | ||
| result.enum = enumValues.map(String); | ||
| } | ||
| } | ||
| function getEnumType({ | ||
| values, | ||
| type, | ||
| }: { | ||
| values: EnumValues; | ||
| type: JSONSchema7['type']; | ||
| }): EnumType | undefined { | ||
| if (values.length === 0) { | ||
| return undefined; | ||
| } | ||
| const typeAllows = (enumType: EnumType) => | ||
| type === undefined || | ||
| type === enumType || | ||
| (Array.isArray(type) && type.includes(enumType)); | ||
| if ( | ||
| typeAllows('string') && | ||
| values.every(value => typeof value === 'string') | ||
| ) { | ||
| return 'string'; | ||
| } | ||
| if ( | ||
| (typeAllows('number') || typeAllows('integer')) && | ||
| values.every(value => typeof value === 'number' && Number.isFinite(value)) | ||
| ) { | ||
| if (typeAllows('number')) { | ||
| return 'number'; | ||
| } | ||
| if (values.every(value => Number.isInteger(value))) { | ||
| return 'integer'; | ||
| } | ||
| } | ||
| if ( | ||
| typeAllows('boolean') && | ||
| values.every(value => typeof value === 'boolean') | ||
| ) { | ||
| return 'boolean'; | ||
| } | ||
| return undefined; | ||
| } | ||
| function isEmptyObjectSchema(jsonSchema: JSONSchema7Definition): boolean { | ||
@@ -153,0 +272,0 @@ return ( |
@@ -16,2 +16,3 @@ import { | ||
| status: z.string(), | ||
| details: z.array(z.unknown()).nullish(), | ||
| }), | ||
@@ -18,0 +19,0 @@ }), |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
2119027
0.78%26896
0.87%