@ai-sdk/google 3.0.110 → 3.0.111

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,11 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 3.0.111
4
+
5
+ ### Patch Changes
6
+
7
+ - c715588: Inline local JSON Schema references in Google tool and structured-output schemas.
8
+
3
9
  ## 3.0.110
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(index_exports);
30
30
  var import_provider_utils23 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/version.ts
33
- var VERSION = true ? "3.0.110" : "0.0.0-test";
33
+ var VERSION = true ? "3.0.111" : "0.0.0-test";
34
34
 
35
35
  // src/google-generative-ai-embedding-model.ts
36
36
  var import_provider = require("@ai-sdk/provider");
@@ -289,22 +289,39 @@ function convertGoogleGenerativeAIUsage(usage) {
289
289
  }
290
290
 
291
291
  // src/convert-json-schema-to-openapi-schema.ts
292
+ var import_provider2 = require("@ai-sdk/provider");
292
293
  function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
294
+ const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
295
+ return convertJSONSchemaDefinition(jsonSchema, isRoot, {
296
+ definitions: rootSchema == null ? void 0 : rootSchema.definitions,
297
+ dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
298
+ resolvingReferences: /* @__PURE__ */ new Set()
299
+ });
300
+ }
301
+ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
293
302
  if (jsonSchema == null) {
294
303
  return void 0;
295
304
  }
305
+ if (typeof jsonSchema === "boolean") {
306
+ return { type: "boolean", properties: {} };
307
+ }
308
+ if (jsonSchema.$ref != null) {
309
+ return convertJSONSchemaReference({
310
+ jsonSchema,
311
+ reference: jsonSchema.$ref,
312
+ isRoot,
313
+ referenceContext
314
+ });
315
+ }
296
316
  if (isEmptyObjectSchema(jsonSchema)) {
297
317
  if (isRoot) {
298
318
  return void 0;
299
319
  }
300
- if (typeof jsonSchema === "object" && jsonSchema.description) {
320
+ if (jsonSchema.description) {
301
321
  return { type: "object", description: jsonSchema.description };
302
322
  }
303
323
  return { type: "object" };
304
324
  }
305
- if (typeof jsonSchema === "boolean") {
306
- return { type: "boolean", properties: {} };
307
- }
308
325
  const {
309
326
  type,
310
327
  description,
@@ -348,18 +365,20 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
348
365
  if (properties != null) {
349
366
  result.properties = Object.entries(properties).reduce(
350
367
  (acc, [key, value]) => {
351
- acc[key] = convertJSONSchemaToOpenAPISchema(value, false);
368
+ acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
352
369
  return acc;
353
370
  },
354
371
  {}
355
372
  );
356
373
  }
357
374
  if (items) {
358
- result.items = Array.isArray(items) ? items.map((item) => convertJSONSchemaToOpenAPISchema(item, false)) : convertJSONSchemaToOpenAPISchema(items, false);
375
+ result.items = Array.isArray(items) ? items.map(
376
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
377
+ ) : convertJSONSchemaDefinition(items, false, referenceContext);
359
378
  }
360
379
  if (allOf) {
361
380
  result.allOf = allOf.map(
362
- (item) => convertJSONSchemaToOpenAPISchema(item, false)
381
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
363
382
  );
364
383
  }
365
384
  if (anyOf) {
@@ -370,9 +389,10 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
370
389
  (schema) => !(typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null")
371
390
  );
372
391
  if (nonNullSchemas.length === 1) {
373
- const converted = convertJSONSchemaToOpenAPISchema(
392
+ const converted = convertJSONSchemaDefinition(
374
393
  nonNullSchemas[0],
375
- false
394
+ false,
395
+ referenceContext
376
396
  );
377
397
  if (typeof converted === "object") {
378
398
  result.nullable = true;
@@ -380,19 +400,19 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
380
400
  }
381
401
  } else {
382
402
  result.anyOf = nonNullSchemas.map(
383
- (item) => convertJSONSchemaToOpenAPISchema(item, false)
403
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
384
404
  );
385
405
  result.nullable = true;
386
406
  }
387
407
  } else {
388
408
  result.anyOf = anyOf.map(
389
- (item) => convertJSONSchemaToOpenAPISchema(item, false)
409
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
390
410
  );
391
411
  }
392
412
  }
393
413
  if (oneOf) {
394
414
  result.oneOf = oneOf.map(
395
- (item) => convertJSONSchemaToOpenAPISchema(item, false)
415
+ (item) => convertJSONSchemaDefinition(item, false, referenceContext)
396
416
  );
397
417
  }
398
418
  if (minLength !== void 0) {
@@ -400,12 +420,82 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
400
420
  }
401
421
  return result;
402
422
  }
423
+ function convertJSONSchemaReference({
424
+ jsonSchema,
425
+ reference,
426
+ isRoot,
427
+ referenceContext
428
+ }) {
429
+ const { definition, referenceKey } = getReferencedDefinition(
430
+ reference,
431
+ referenceContext
432
+ );
433
+ if (referenceContext.resolvingReferences.has(referenceKey)) {
434
+ throw new import_provider2.UnsupportedFunctionalityError({
435
+ functionality: `recursive JSON Schema reference: ${reference}`,
436
+ message: "Google schema conversion does not support recursive JSON Schema references."
437
+ });
438
+ }
439
+ const resolvingReferences = new Set(referenceContext.resolvingReferences);
440
+ resolvingReferences.add(referenceKey);
441
+ const { $ref: _reference, ...siblingSchema } = jsonSchema;
442
+ const resolvedSchema = typeof definition === "boolean" ? definition ? siblingSchema : false : { ...definition, ...siblingSchema };
443
+ return convertJSONSchemaDefinition(resolvedSchema, isRoot, {
444
+ ...referenceContext,
445
+ resolvingReferences
446
+ });
447
+ }
448
+ function getReferencedDefinition(reference, referenceContext) {
449
+ const definitionSources = [
450
+ {
451
+ prefix: "#/$defs/",
452
+ definitions: referenceContext.dollarDefinitions
453
+ },
454
+ {
455
+ prefix: "#/definitions/",
456
+ definitions: referenceContext.definitions
457
+ }
458
+ ];
459
+ const source = definitionSources.find(
460
+ ({ prefix }) => reference.startsWith(prefix)
461
+ );
462
+ const encodedDefinitionName = source ? reference.slice(source.prefix.length) : void 0;
463
+ if (source == null || encodedDefinitionName == null || encodedDefinitionName.length === 0 || encodedDefinitionName.includes("/")) {
464
+ throwUnsupportedReference(reference);
465
+ }
466
+ let decodedDefinitionName;
467
+ try {
468
+ decodedDefinitionName = decodeURIComponent(encodedDefinitionName);
469
+ } catch (e) {
470
+ throwUnsupportedReference(reference);
471
+ }
472
+ if (decodedDefinitionName.includes("/") || /~(?![01])/u.test(decodedDefinitionName) || source.definitions == null) {
473
+ throwUnsupportedReference(reference);
474
+ }
475
+ const definitionName = decodedDefinitionName.replace(
476
+ /~[01]/g,
477
+ (match) => match === "~1" ? "/" : "~"
478
+ );
479
+ if (!Object.prototype.hasOwnProperty.call(source.definitions, definitionName)) {
480
+ throwUnsupportedReference(reference);
481
+ }
482
+ return {
483
+ definition: source.definitions[definitionName],
484
+ referenceKey: `${source.prefix}${definitionName}`
485
+ };
486
+ }
487
+ function throwUnsupportedReference(reference) {
488
+ throw new import_provider2.UnsupportedFunctionalityError({
489
+ functionality: `JSON Schema reference: ${reference}`,
490
+ message: "Google schema conversion only supports references to direct children of root-level $defs or definitions."
491
+ });
492
+ }
403
493
  function isEmptyObjectSchema(jsonSchema) {
404
494
  return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
405
495
  }
406
496
 
407
497
  // src/convert-to-google-generative-ai-messages.ts
408
- var import_provider2 = require("@ai-sdk/provider");
498
+ var import_provider3 = require("@ai-sdk/provider");
409
499
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
410
500
  var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
411
501
  function getGoogleProviderOptions(providerOptions, providerOptionsName) {
@@ -555,7 +645,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
555
645
  switch (role) {
556
646
  case "system": {
557
647
  if (!systemMessagesAllowed) {
558
- throw new import_provider2.UnsupportedFunctionalityError({
648
+ throw new import_provider3.UnsupportedFunctionalityError({
559
649
  functionality: "system messages are only supported at the beginning of the conversation"
560
650
  });
561
651
  }
@@ -620,7 +710,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
620
710
  }
621
711
  case "file": {
622
712
  if (part.data instanceof URL) {
623
- throw new import_provider2.UnsupportedFunctionalityError({
713
+ throw new import_provider3.UnsupportedFunctionalityError({
624
714
  functionality: "File data URLs in assistant messages are not supported"
625
715
  });
626
716
  }
@@ -989,7 +1079,7 @@ function getGoogleModelCapabilities(modelId) {
989
1079
  }
990
1080
 
991
1081
  // src/google-prepare-tools.ts
992
- var import_provider3 = require("@ai-sdk/provider");
1082
+ var import_provider4 = require("@ai-sdk/provider");
993
1083
  function prepareTools({
994
1084
  tools,
995
1085
  toolChoice,
@@ -1227,7 +1317,7 @@ function prepareTools({
1227
1317
  };
1228
1318
  default: {
1229
1319
  const _exhaustiveCheck = type;
1230
- throw new import_provider3.UnsupportedFunctionalityError({
1320
+ throw new import_provider4.UnsupportedFunctionalityError({
1231
1321
  functionality: `tool choice type: ${_exhaustiveCheck}`
1232
1322
  });
1233
1323
  }
@@ -3022,7 +3112,7 @@ var googleImageModelOptionsSchema = (0, import_provider_utils14.lazySchema)(
3022
3112
  );
3023
3113
 
3024
3114
  // src/google-generative-ai-video-model.ts
3025
- var import_provider4 = require("@ai-sdk/provider");
3115
+ var import_provider5 = require("@ai-sdk/provider");
3026
3116
  var import_provider_utils15 = require("@ai-sdk/provider-utils");
3027
3117
  var import_v414 = require("zod/v4");
3028
3118
  function getFirstFrameImage(options) {
@@ -3197,7 +3287,7 @@ var GoogleGenerativeAIVideoModel = class {
3197
3287
  });
3198
3288
  const operationName = operation.name;
3199
3289
  if (!operationName) {
3200
- throw new import_provider4.AISDKError({
3290
+ throw new import_provider5.AISDKError({
3201
3291
  name: "GOOGLE_VIDEO_GENERATION_ERROR",
3202
3292
  message: "No operation name returned from API"
3203
3293
  });
@@ -3209,14 +3299,14 @@ var GoogleGenerativeAIVideoModel = class {
3209
3299
  let responseHeaders;
3210
3300
  while (!finalOperation.done) {
3211
3301
  if (Date.now() - startTime > pollTimeoutMs) {
3212
- throw new import_provider4.AISDKError({
3302
+ throw new import_provider5.AISDKError({
3213
3303
  name: "GOOGLE_VIDEO_GENERATION_TIMEOUT",
3214
3304
  message: `Video generation timed out after ${pollTimeoutMs}ms`
3215
3305
  });
3216
3306
  }
3217
3307
  await (0, import_provider_utils15.delay)(pollIntervalMs);
3218
3308
  if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
3219
- throw new import_provider4.AISDKError({
3309
+ throw new import_provider5.AISDKError({
3220
3310
  name: "GOOGLE_VIDEO_GENERATION_ABORTED",
3221
3311
  message: "Video generation request was aborted"
3222
3312
  });
@@ -3238,14 +3328,14 @@ var GoogleGenerativeAIVideoModel = class {
3238
3328
  responseHeaders = pollHeaders;
3239
3329
  }
3240
3330
  if (finalOperation.error) {
3241
- throw new import_provider4.AISDKError({
3331
+ throw new import_provider5.AISDKError({
3242
3332
  name: "GOOGLE_VIDEO_GENERATION_FAILED",
3243
3333
  message: `Video generation failed: ${finalOperation.error.message}`
3244
3334
  });
3245
3335
  }
3246
3336
  const response = finalOperation.response;
3247
3337
  if (!((_g = response == null ? void 0 : response.generateVideoResponse) == null ? void 0 : _g.generatedSamples) || response.generateVideoResponse.generatedSamples.length === 0) {
3248
- throw new import_provider4.AISDKError({
3338
+ throw new import_provider5.AISDKError({
3249
3339
  name: "GOOGLE_VIDEO_GENERATION_ERROR",
3250
3340
  message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
3251
3341
  });
@@ -3268,7 +3358,7 @@ var GoogleGenerativeAIVideoModel = class {
3268
3358
  }
3269
3359
  }
3270
3360
  if (videos.length === 0) {
3271
- throw new import_provider4.AISDKError({
3361
+ throw new import_provider5.AISDKError({
3272
3362
  name: "GOOGLE_VIDEO_GENERATION_ERROR",
3273
3363
  message: "No valid videos in response"
3274
3364
  });