@ai-sdk/google 3.0.142 → 3.0.144

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,24 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 3.0.144
4
+
5
+ ### Patch Changes
6
+
7
+ - d55ff04: Preserve the served service tier from the `x-gemini-service-tier` response header when usage metadata omits it, for generated and streamed responses.
8
+ - 733b167: Apply contiguous array-index validation to dotted numeric paths in streamed tool arguments, while preserving numeric object keys and valid contiguous array updates.
9
+ - Updated dependencies [88bb257]
10
+ - @ai-sdk/provider-utils@4.0.66
11
+
12
+ ## 3.0.143
13
+
14
+ ### Patch Changes
15
+
16
+ - 93f4a18: Bound Google JSON Schema conversion work, output size, and depth to prevent excessive resource use when inlining repeated local references. Input inspection and conversion each have a separate budget of 10,000 visited JSON values and a conservative 1,000,000-character serialized-size allowance, with a depth limit of 100. Schemas exceeding these limits now fail with a controlled error, including large schemas that were previously accepted. String-size accounting reserves six characters per UTF-16 code unit for JSON escaping.
17
+ - 2a57dab: Pass `providerOptions.google.labels` through to Google and Vertex AI Interactions requests, including streaming, so callers can attach request metadata such as `safety_identifier`.
18
+ - f3c2cb3: skip streamed tool-call array indexes that leave a gap so a small response can't build a huge sparse array
19
+ - Updated dependencies [f0dee4b]
20
+ - @ai-sdk/provider-utils@4.0.65
21
+
3
22
  ## 3.0.142
4
23
 
5
24
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -350,6 +350,7 @@ type GoogleInteractionsModelId = 'gemini-2.5-computer-use-preview-10-2025' | 'ge
350
350
  * All fields are `.nullish()` per the existing google provider convention.
351
351
  */
352
352
  declare const googleInteractionsLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
353
+ labels?: Record<string, string> | null | undefined;
353
354
  previousInteractionId?: string | null | undefined;
354
355
  store?: boolean | null | undefined;
355
356
  agent?: string | null | undefined;
package/dist/index.d.ts CHANGED
@@ -350,6 +350,7 @@ type GoogleInteractionsModelId = 'gemini-2.5-computer-use-preview-10-2025' | 'ge
350
350
  * All fields are `.nullish()` per the existing google provider convention.
351
351
  */
352
352
  declare const googleInteractionsLanguageModelOptions: _ai_sdk_provider_utils.LazySchema<{
353
+ labels?: Record<string, string> | null | undefined;
353
354
  previousInteractionId?: string | null | undefined;
354
355
  store?: boolean | null | undefined;
355
356
  agent?: string | null | undefined;
package/dist/index.js CHANGED
@@ -278,7 +278,7 @@ var googleInteractionsTranscriptionResponseSchema = (0, import_provider_utils3.l
278
278
  var import_provider_utils26 = require("@ai-sdk/provider-utils");
279
279
 
280
280
  // src/version.ts
281
- var VERSION = true ? "3.0.142" : "0.0.0-test";
281
+ var VERSION = true ? "3.0.144" : "0.0.0-test";
282
282
 
283
283
  // src/google-generative-ai-embedding-model.ts
284
284
  var import_provider2 = require("@ai-sdk/provider");
@@ -649,25 +649,54 @@ function addTokenDetails(a, b) {
649
649
 
650
650
  // src/convert-json-schema-to-openapi-schema.ts
651
651
  var import_provider3 = require("@ai-sdk/provider");
652
+ var maxSchemaDepth = 100;
653
+ var maxSchemaNodes = 1e4;
654
+ var maxSchemaSize = 1e6;
652
655
  var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
653
656
  function isRecursiveJSONSchemaReferenceError(error) {
654
657
  return import_provider3.UnsupportedFunctionalityError.isInstance(error) && error.functionality.startsWith(recursiveReferenceFunctionalityPrefix);
655
658
  }
656
659
  function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
660
+ consumeSchemaBudget(jsonSchema, {
661
+ nodes: maxSchemaNodes,
662
+ size: maxSchemaSize
663
+ });
657
664
  const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
658
665
  return convertJSONSchemaDefinition(jsonSchema, isRoot, {
659
666
  definitions: rootSchema == null ? void 0 : rootSchema.definitions,
660
667
  dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
661
- resolvingReferences: /* @__PURE__ */ new Set()
668
+ resolvingReferences: /* @__PURE__ */ new Set(),
669
+ budget: { nodes: maxSchemaNodes, size: maxSchemaSize },
670
+ depth: 0
662
671
  });
663
672
  }
664
673
  function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
665
674
  if (jsonSchema == null) {
666
675
  return void 0;
667
676
  }
677
+ referenceContext.budget.nodes--;
678
+ referenceContext.budget.size -= 128;
679
+ checkSchemaBudget(referenceContext.budget, referenceContext.depth);
680
+ referenceContext = {
681
+ ...referenceContext,
682
+ depth: referenceContext.depth + 1
683
+ };
668
684
  if (typeof jsonSchema === "boolean") {
669
685
  return { type: "boolean", properties: {} };
670
686
  }
687
+ consumeSchemaBudget(
688
+ [
689
+ jsonSchema.$ref,
690
+ jsonSchema.type,
691
+ jsonSchema.description,
692
+ jsonSchema.required,
693
+ jsonSchema.format,
694
+ jsonSchema.const,
695
+ jsonSchema.enum,
696
+ jsonSchema.minLength
697
+ ],
698
+ referenceContext.budget
699
+ );
671
700
  if (jsonSchema.$ref != null) {
672
701
  return convertJSONSchemaReference({
673
702
  jsonSchema,
@@ -731,6 +760,7 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
731
760
  if (properties != null) {
732
761
  result.properties = Object.entries(properties).reduce(
733
762
  (acc, [key, value]) => {
763
+ consumeSchemaBudget(key, referenceContext.budget);
734
764
  acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
735
765
  return acc;
736
766
  },
@@ -786,6 +816,38 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
786
816
  }
787
817
  return result;
788
818
  }
819
+ function checkSchemaBudget(budget, depth) {
820
+ if (budget.nodes < 0 || budget.size < 0 || depth > maxSchemaDepth) {
821
+ throw new import_provider3.UnsupportedFunctionalityError({
822
+ functionality: "JSON Schema conversion exceeding resource limits",
823
+ message: "Google schema conversion exceeded its node, size, or depth limit."
824
+ });
825
+ }
826
+ }
827
+ function consumeSchemaBudget(value, budget, depth = 0) {
828
+ if (value === void 0) {
829
+ return;
830
+ }
831
+ budget.nodes--;
832
+ budget.size -= typeof value === "string" ? value.length * 6 + 2 : 32;
833
+ checkSchemaBudget(budget, depth);
834
+ if (Array.isArray(value)) {
835
+ for (const item of value) {
836
+ consumeSchemaBudget(item, budget, depth + 1);
837
+ }
838
+ } else if (value !== null && typeof value === "object") {
839
+ for (const key in value) {
840
+ if (Object.prototype.hasOwnProperty.call(value, key)) {
841
+ consumeSchemaBudget(key, budget, depth + 1);
842
+ consumeSchemaBudget(
843
+ value[key],
844
+ budget,
845
+ depth + 1
846
+ );
847
+ }
848
+ }
849
+ }
850
+ }
789
851
  function addEnumToSchema({
790
852
  values,
791
853
  type,
@@ -1939,6 +2001,7 @@ var GoogleJSONAccumulator = class {
1939
2001
  const rawPath = jsonPath.replace(/^\$\./, "");
1940
2002
  if (!rawPath || rawPath === "$") continue;
1941
2003
  const segments = parsePath(rawPath);
2004
+ if (!normalizeAndCheckIndexes(this.accumulatedArgs, segments)) continue;
1942
2005
  const existingValue = getNestedValue(this.accumulatedArgs, segments);
1943
2006
  const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
1944
2007
  if (isStringContinuation) {
@@ -2159,6 +2222,25 @@ function getNestedValue(obj, segments) {
2159
2222
  }
2160
2223
  return current;
2161
2224
  }
2225
+ function normalizeAndCheckIndexes(obj, segments) {
2226
+ let current = obj;
2227
+ for (let i = 0; i < segments.length; i++) {
2228
+ let pathSegment = segments[i];
2229
+ if (Array.isArray(current) && typeof pathSegment === "string") {
2230
+ const index = Number(pathSegment);
2231
+ if (Number.isInteger(index) && index >= 0 && index < 2 ** 32 - 1 && String(index) === pathSegment) {
2232
+ pathSegment = index;
2233
+ segments[i] = index;
2234
+ }
2235
+ }
2236
+ if (typeof pathSegment === "number") {
2237
+ const length = Array.isArray(current) ? current.length : current == null ? 0 : void 0;
2238
+ if (length !== void 0 && pathSegment > length) return false;
2239
+ }
2240
+ current = current != null && typeof current === "object" && hasOwnProperty(current, pathSegment) ? current[pathSegment] : void 0;
2241
+ }
2242
+ return true;
2243
+ }
2162
2244
  function setNestedValue(obj, segments, value) {
2163
2245
  let current = obj;
2164
2246
  for (let i = 0; i < segments.length - 1; i++) {
@@ -2433,7 +2515,7 @@ var GoogleGenerativeAILanguageModel = class {
2433
2515
  };
2434
2516
  }
2435
2517
  async doGenerate(options) {
2436
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
2518
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C;
2437
2519
  const { args, warnings, providerOptionsName, extraHeaders } = await this.getArgs(options);
2438
2520
  const mergedHeaders = (0, import_provider_utils9.combineHeaders)(
2439
2521
  await (0, import_provider_utils9.resolve)(this.config.headers),
@@ -2635,7 +2717,7 @@ var GoogleGenerativeAILanguageModel = class {
2635
2717
  safetyRatings: (_y = candidate == null ? void 0 : candidate.safetyRatings) != null ? _y : null,
2636
2718
  usageMetadata: usageMetadata != null ? usageMetadata : null,
2637
2719
  finishMessage: (_z = candidate == null ? void 0 : candidate.finishMessage) != null ? _z : null,
2638
- serviceTier: (_A = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _A : null,
2720
+ serviceTier: (_B = (_A = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _A : responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _B : null,
2639
2721
  ...(candidate == null ? void 0 : candidate.continuationToken) != null && rawFinishReason === "MAX_TOKENS" ? { continuationToken: candidate.continuationToken } : {},
2640
2722
  ...continuedUsageMetadata != null && firstPromptTokenCount != null ? { initialPromptTokenCount: firstPromptTokenCount } : {}
2641
2723
  }
@@ -2643,7 +2725,7 @@ var GoogleGenerativeAILanguageModel = class {
2643
2725
  request: { body: args },
2644
2726
  response: {
2645
2727
  // TODO timestamp, model id
2646
- id: (_B = response.responseId) != null ? _B : void 0,
2728
+ id: (_C = response.responseId) != null ? _C : void 0,
2647
2729
  headers: responseHeaders,
2648
2730
  body: rawResponse
2649
2731
  }
@@ -3119,7 +3201,7 @@ var GoogleGenerativeAILanguageModel = class {
3119
3201
  }
3120
3202
  },
3121
3203
  flush(controller) {
3122
- var _a2;
3204
+ var _a2, _b;
3123
3205
  usage = addGoogleGenerativeAIUsageMetadata(continuedUsage, usage);
3124
3206
  if (currentTextBlockId !== null) {
3125
3207
  controller.enqueue({
@@ -3151,7 +3233,7 @@ var GoogleGenerativeAILanguageModel = class {
3151
3233
  safetyRatings: lastSafetyRatings,
3152
3234
  usageMetadata: usage != null ? usage : null,
3153
3235
  finishMessage: lastFinishMessage,
3154
- serviceTier: (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : null,
3236
+ serviceTier: (_b = (_a2 = usage == null ? void 0 : usage.serviceTier) != null ? _a2 : responseHeaders == null ? void 0 : responseHeaders["x-gemini-service-tier"]) != null ? _b : null,
3155
3237
  // Only surface the token when the response stopped early
3156
3238
  // (budget used up, or continuing failed), not for the
3157
3239
  // checkpoint tokens of a stream that finished normally.
@@ -5731,6 +5813,8 @@ var import_v419 = require("zod/v4");
5731
5813
  var googleInteractionsLanguageModelOptions = (0, import_provider_utils21.lazySchema)(
5732
5814
  () => (0, import_provider_utils21.zodSchema)(
5733
5815
  import_v419.z.object({
5816
+ /** User-defined request metadata, including `safety_identifier`. */
5817
+ labels: import_v419.z.record(import_v419.z.string(), import_v419.z.string()).nullish(),
5734
5818
  previousInteractionId: import_v419.z.string().nullish(),
5735
5819
  store: import_v419.z.boolean().nullish(),
5736
5820
  agent: import_v419.z.string().nullish(),
@@ -6681,7 +6765,7 @@ var GoogleInteractionsLanguageModel = class {
6681
6765
  };
6682
6766
  }
6683
6767
  async getArgs(options) {
6684
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
6768
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G;
6685
6769
  const warnings = [];
6686
6770
  const opts = await (0, import_provider_utils25.parseProviderOptions)({
6687
6771
  provider: "google",
@@ -6916,24 +7000,25 @@ var GoogleInteractionsLanguageModel = class {
6916
7000
  const args = pruneUndefined({
6917
7001
  ...isAgent ? { agent: this.agent } : { model: this.modelId },
6918
7002
  input,
7003
+ labels: (_B = opts == null ? void 0 : opts.labels) != null ? _B : void 0,
6919
7004
  system_instruction: systemInstruction,
6920
7005
  tools: toolsForBody,
6921
7006
  response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
6922
7007
  response_modalities: (opts == null ? void 0 : opts.responseModalities) != null ? opts.responseModalities : void 0,
6923
- previous_interaction_id: (_B = opts == null ? void 0 : opts.previousInteractionId) != null ? _B : void 0,
6924
- service_tier: (_C = opts == null ? void 0 : opts.serviceTier) != null ? _C : void 0,
6925
- store: (_D = opts == null ? void 0 : opts.store) != null ? _D : void 0,
7008
+ previous_interaction_id: (_C = opts == null ? void 0 : opts.previousInteractionId) != null ? _C : void 0,
7009
+ service_tier: (_D = opts == null ? void 0 : opts.serviceTier) != null ? _D : void 0,
7010
+ store: (_E = opts == null ? void 0 : opts.store) != null ? _E : void 0,
6926
7011
  generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
6927
7012
  agent_config: agentConfig,
6928
7013
  environment,
6929
- background: (_E = opts == null ? void 0 : opts.background) != null ? _E : void 0
7014
+ background: (_F = opts == null ? void 0 : opts.background) != null ? _F : void 0
6930
7015
  });
6931
7016
  return {
6932
7017
  args,
6933
7018
  warnings,
6934
7019
  isAgent,
6935
7020
  isBackground: (opts == null ? void 0 : opts.background) === true,
6936
- pollingTimeoutMs: (_F = opts == null ? void 0 : opts.pollingTimeoutMs) != null ? _F : void 0
7021
+ pollingTimeoutMs: (_G = opts == null ? void 0 : opts.pollingTimeoutMs) != null ? _G : void 0
6937
7022
  };
6938
7023
  }
6939
7024
  async doGenerate(options) {