@ai-sdk/google 2.0.87 → 2.0.89

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 2.0.89
4
+
5
+ ### Patch Changes
6
+
7
+ - 1284605: Inline local JSON Schema references in Google tool and structured-output schemas.
8
+
9
+ ## 2.0.88
10
+
11
+ ### Patch Changes
12
+
13
+ - df0cbe9: feat(google): add `gemini-3.7-flash` model
14
+
3
15
  ## 2.0.87
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -12,7 +12,7 @@ declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
12
12
  }>;
13
13
  type GoogleErrorData = InferValidator<typeof googleErrorDataSchema>;
14
14
 
15
- type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-3.5-flash' | 'gemini-3.5-flash-lite' | 'gemini-3.6-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
15
+ type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-3.5-flash' | 'gemini-3.5-flash-lite' | 'gemini-3.6-flash' | 'gemini-3.7-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
16
16
  declare const googleGenerativeAIProviderOptions: _ai_sdk_provider_utils.LazySchema<{
17
17
  responseModalities?: ("TEXT" | "IMAGE")[] | undefined;
18
18
  thinkingConfig?: {
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
12
12
  }>;
13
13
  type GoogleErrorData = InferValidator<typeof googleErrorDataSchema>;
14
14
 
15
- type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-3.5-flash' | 'gemini-3.5-flash-lite' | 'gemini-3.6-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
15
+ type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-3.5-flash' | 'gemini-3.5-flash-lite' | 'gemini-3.6-flash' | 'gemini-3.7-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
16
16
  declare const googleGenerativeAIProviderOptions: _ai_sdk_provider_utils.LazySchema<{
17
17
  responseModalities?: ("TEXT" | "IMAGE")[] | undefined;
18
18
  thinkingConfig?: {
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.87" : "0.0.0-test";
33
+ var VERSION = true ? "2.0.89" : "0.0.0-test";
34
34
 
35
35
  // src/google-generative-ai-embedding-model.ts
36
36
  var import_provider = require("@ai-sdk/provider");
@@ -242,22 +242,39 @@ var import_provider_utils6 = require("@ai-sdk/provider-utils");
242
242
  var import_v45 = require("zod/v4");
243
243
 
244
244
  // src/convert-json-schema-to-openapi-schema.ts
245
+ var import_provider2 = require("@ai-sdk/provider");
245
246
  function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
247
+ const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
248
+ return convertJSONSchemaDefinition(jsonSchema, isRoot, {
249
+ definitions: rootSchema == null ? void 0 : rootSchema.definitions,
250
+ dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
251
+ resolvingReferences: /* @__PURE__ */ new Set()
252
+ });
253
+ }
254
+ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
246
255
  if (jsonSchema == null) {
247
256
  return void 0;
248
257
  }
258
+ if (typeof jsonSchema === "boolean") {
259
+ return { type: "boolean", properties: {} };
260
+ }
261
+ if (jsonSchema.$ref != null) {
262
+ return convertJSONSchemaReference({
263
+ jsonSchema,
264
+ reference: jsonSchema.$ref,
265
+ isRoot,
266
+ referenceContext
267
+ });
268
+ }
249
269
  if (isEmptyObjectSchema(jsonSchema)) {
250
270
  if (isRoot) {
251
271
  return void 0;
252
272
  }
253
- if (typeof jsonSchema === "object" && jsonSchema.description) {
273
+ if (jsonSchema.description) {
254
274
  return { type: "object", description: jsonSchema.description };
255
275
  }
256
276
  return { type: "object" };
257
277
  }
258
- if (typeof jsonSchema === "boolean") {
259
- return { type: "boolean", properties: {} };
260
- }
261
278
  const {
262
279
  type,
263
280
  description,
@@ -301,18 +318,20 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
301
318
  if (properties != null) {
302
319
  result.properties = Object.entries(properties).reduce(
303
320
  (acc, [key, value]) => {
304
- acc[key] = convertJSONSchemaToOpenAPISchema(value, false);
321
+ acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
305
322
  return acc;
306
323
  },
307
324
  {}
308
325
  );
309
326
  }
310
327
  if (items) {
311
- result.items = Array.isArray(items) ? items.map((item) => convertJSONSchemaToOpenAPISchema(item, false)) : convertJSONSchemaToOpenAPISchema(items, false);
328
+ result.items = Array.isArray(items) ? items.map(
329
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
330
+ ) : convertJSONSchemaDefinition(items, false, referenceContext);
312
331
  }
313
332
  if (allOf) {
314
333
  result.allOf = allOf.map(
315
- (item) => convertJSONSchemaToOpenAPISchema(item, false)
334
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
316
335
  );
317
336
  }
318
337
  if (anyOf) {
@@ -323,9 +342,10 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
323
342
  (schema) => !(typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null")
324
343
  );
325
344
  if (nonNullSchemas.length === 1) {
326
- const converted = convertJSONSchemaToOpenAPISchema(
345
+ const converted = convertJSONSchemaDefinition(
327
346
  nonNullSchemas[0],
328
- false
347
+ false,
348
+ referenceContext
329
349
  );
330
350
  if (typeof converted === "object") {
331
351
  result.nullable = true;
@@ -333,19 +353,19 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
333
353
  }
334
354
  } else {
335
355
  result.anyOf = nonNullSchemas.map(
336
- (item) => convertJSONSchemaToOpenAPISchema(item, false)
356
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
337
357
  );
338
358
  result.nullable = true;
339
359
  }
340
360
  } else {
341
361
  result.anyOf = anyOf.map(
342
- (item) => convertJSONSchemaToOpenAPISchema(item, false)
362
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
343
363
  );
344
364
  }
345
365
  }
346
366
  if (oneOf) {
347
367
  result.oneOf = oneOf.map(
348
- (item) => convertJSONSchemaToOpenAPISchema(item, false)
368
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
349
369
  );
350
370
  }
351
371
  if (minLength !== void 0) {
@@ -353,12 +373,82 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
353
373
  }
354
374
  return result;
355
375
  }
376
+ function convertJSONSchemaReference({
377
+ jsonSchema,
378
+ reference,
379
+ isRoot,
380
+ referenceContext
381
+ }) {
382
+ const { definition, referenceKey } = getReferencedDefinition(
383
+ reference,
384
+ referenceContext
385
+ );
386
+ if (referenceContext.resolvingReferences.has(referenceKey)) {
387
+ throw new import_provider2.UnsupportedFunctionalityError({
388
+ functionality: `recursive JSON Schema reference: ${reference}`,
389
+ message: "Google schema conversion does not support recursive JSON Schema references."
390
+ });
391
+ }
392
+ const resolvingReferences = new Set(referenceContext.resolvingReferences);
393
+ resolvingReferences.add(referenceKey);
394
+ const { $ref: _reference, ...siblingSchema } = jsonSchema;
395
+ const resolvedSchema = typeof definition === "boolean" ? definition ? siblingSchema : false : { ...definition, ...siblingSchema };
396
+ return convertJSONSchemaDefinition(resolvedSchema, isRoot, {
397
+ ...referenceContext,
398
+ resolvingReferences
399
+ });
400
+ }
401
+ function getReferencedDefinition(reference, referenceContext) {
402
+ const definitionSources = [
403
+ {
404
+ prefix: "#/$defs/",
405
+ definitions: referenceContext.dollarDefinitions
406
+ },
407
+ {
408
+ prefix: "#/definitions/",
409
+ definitions: referenceContext.definitions
410
+ }
411
+ ];
412
+ const source = definitionSources.find(
413
+ ({ prefix }) => reference.startsWith(prefix)
414
+ );
415
+ const encodedDefinitionName = source ? reference.slice(source.prefix.length) : void 0;
416
+ if (source == null || encodedDefinitionName == null || encodedDefinitionName.length === 0 || encodedDefinitionName.includes("/")) {
417
+ throwUnsupportedReference(reference);
418
+ }
419
+ let decodedDefinitionName;
420
+ try {
421
+ decodedDefinitionName = decodeURIComponent(encodedDefinitionName);
422
+ } catch (e) {
423
+ throwUnsupportedReference(reference);
424
+ }
425
+ if (decodedDefinitionName.includes("/") || /~(?![01])/u.test(decodedDefinitionName) || source.definitions == null) {
426
+ throwUnsupportedReference(reference);
427
+ }
428
+ const definitionName = decodedDefinitionName.replace(
429
+ /~[01]/g,
430
+ (match) => match === "~1" ? "/" : "~"
431
+ );
432
+ if (!Object.prototype.hasOwnProperty.call(source.definitions, definitionName)) {
433
+ throwUnsupportedReference(reference);
434
+ }
435
+ return {
436
+ definition: source.definitions[definitionName],
437
+ referenceKey: `${source.prefix}${definitionName}`
438
+ };
439
+ }
440
+ function throwUnsupportedReference(reference) {
441
+ throw new import_provider2.UnsupportedFunctionalityError({
442
+ functionality: `JSON Schema reference: ${reference}`,
443
+ message: "Google schema conversion only supports references to direct children of root-level $defs or definitions."
444
+ });
445
+ }
356
446
  function isEmptyObjectSchema(jsonSchema) {
357
447
  return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
358
448
  }
359
449
 
360
450
  // src/convert-to-google-generative-ai-messages.ts
361
- var import_provider2 = require("@ai-sdk/provider");
451
+ var import_provider3 = require("@ai-sdk/provider");
362
452
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
363
453
  var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
364
454
  function convertToGoogleGenerativeAIMessages(prompt, options) {
@@ -373,7 +463,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
373
463
  switch (role) {
374
464
  case "system": {
375
465
  if (!systemMessagesAllowed) {
376
- throw new import_provider2.UnsupportedFunctionalityError({
466
+ throw new import_provider3.UnsupportedFunctionalityError({
377
467
  functionality: "system messages are only supported at the beginning of the conversation"
378
468
  });
379
469
  }
@@ -435,12 +525,12 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
435
525
  }
436
526
  case "file": {
437
527
  if (part.mediaType !== "image/png") {
438
- throw new import_provider2.UnsupportedFunctionalityError({
528
+ throw new import_provider3.UnsupportedFunctionalityError({
439
529
  functionality: "Only PNG images are supported in assistant messages"
440
530
  });
441
531
  }
442
532
  if (part.data instanceof URL) {
443
- throw new import_provider2.UnsupportedFunctionalityError({
533
+ throw new import_provider3.UnsupportedFunctionalityError({
444
534
  functionality: "File data URLs in assistant messages are not supported"
445
535
  });
446
536
  }
@@ -774,7 +864,7 @@ function getGoogleModelCapabilities(modelId) {
774
864
  }
775
865
 
776
866
  // src/google-prepare-tools.ts
777
- var import_provider3 = require("@ai-sdk/provider");
867
+ var import_provider4 = require("@ai-sdk/provider");
778
868
  function prepareTools({
779
869
  tools,
780
870
  toolChoice,
@@ -1012,7 +1102,7 @@ function prepareTools({
1012
1102
  };
1013
1103
  default: {
1014
1104
  const _exhaustiveCheck = type;
1015
- throw new import_provider3.UnsupportedFunctionalityError({
1105
+ throw new import_provider4.UnsupportedFunctionalityError({
1016
1106
  functionality: `tool choice type: ${_exhaustiveCheck}`
1017
1107
  });
1018
1108
  }