@ai-sdk/google 3.0.142 → 3.0.143

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.
@@ -162,25 +162,54 @@ function addTokenDetails(a, b) {
162
162
  import {
163
163
  UnsupportedFunctionalityError
164
164
  } from "@ai-sdk/provider";
165
+ var maxSchemaDepth = 100;
166
+ var maxSchemaNodes = 1e4;
167
+ var maxSchemaSize = 1e6;
165
168
  var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
166
169
  function isRecursiveJSONSchemaReferenceError(error) {
167
170
  return UnsupportedFunctionalityError.isInstance(error) && error.functionality.startsWith(recursiveReferenceFunctionalityPrefix);
168
171
  }
169
172
  function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
173
+ consumeSchemaBudget(jsonSchema, {
174
+ nodes: maxSchemaNodes,
175
+ size: maxSchemaSize
176
+ });
170
177
  const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
171
178
  return convertJSONSchemaDefinition(jsonSchema, isRoot, {
172
179
  definitions: rootSchema == null ? void 0 : rootSchema.definitions,
173
180
  dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
174
- resolvingReferences: /* @__PURE__ */ new Set()
181
+ resolvingReferences: /* @__PURE__ */ new Set(),
182
+ budget: { nodes: maxSchemaNodes, size: maxSchemaSize },
183
+ depth: 0
175
184
  });
176
185
  }
177
186
  function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
178
187
  if (jsonSchema == null) {
179
188
  return void 0;
180
189
  }
190
+ referenceContext.budget.nodes--;
191
+ referenceContext.budget.size -= 128;
192
+ checkSchemaBudget(referenceContext.budget, referenceContext.depth);
193
+ referenceContext = {
194
+ ...referenceContext,
195
+ depth: referenceContext.depth + 1
196
+ };
181
197
  if (typeof jsonSchema === "boolean") {
182
198
  return { type: "boolean", properties: {} };
183
199
  }
200
+ consumeSchemaBudget(
201
+ [
202
+ jsonSchema.$ref,
203
+ jsonSchema.type,
204
+ jsonSchema.description,
205
+ jsonSchema.required,
206
+ jsonSchema.format,
207
+ jsonSchema.const,
208
+ jsonSchema.enum,
209
+ jsonSchema.minLength
210
+ ],
211
+ referenceContext.budget
212
+ );
184
213
  if (jsonSchema.$ref != null) {
185
214
  return convertJSONSchemaReference({
186
215
  jsonSchema,
@@ -244,6 +273,7 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
244
273
  if (properties != null) {
245
274
  result.properties = Object.entries(properties).reduce(
246
275
  (acc, [key, value]) => {
276
+ consumeSchemaBudget(key, referenceContext.budget);
247
277
  acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
248
278
  return acc;
249
279
  },
@@ -299,6 +329,38 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
299
329
  }
300
330
  return result;
301
331
  }
332
+ function checkSchemaBudget(budget, depth) {
333
+ if (budget.nodes < 0 || budget.size < 0 || depth > maxSchemaDepth) {
334
+ throw new UnsupportedFunctionalityError({
335
+ functionality: "JSON Schema conversion exceeding resource limits",
336
+ message: "Google schema conversion exceeded its node, size, or depth limit."
337
+ });
338
+ }
339
+ }
340
+ function consumeSchemaBudget(value, budget, depth = 0) {
341
+ if (value === void 0) {
342
+ return;
343
+ }
344
+ budget.nodes--;
345
+ budget.size -= typeof value === "string" ? value.length * 6 + 2 : 32;
346
+ checkSchemaBudget(budget, depth);
347
+ if (Array.isArray(value)) {
348
+ for (const item of value) {
349
+ consumeSchemaBudget(item, budget, depth + 1);
350
+ }
351
+ } else if (value !== null && typeof value === "object") {
352
+ for (const key in value) {
353
+ if (Object.prototype.hasOwnProperty.call(value, key)) {
354
+ consumeSchemaBudget(key, budget, depth + 1);
355
+ consumeSchemaBudget(
356
+ value[key],
357
+ budget,
358
+ depth + 1
359
+ );
360
+ }
361
+ }
362
+ }
363
+ }
302
364
  function addEnumToSchema({
303
365
  values,
304
366
  type,
@@ -1526,6 +1588,7 @@ var GoogleJSONAccumulator = class {
1526
1588
  const rawPath = jsonPath.replace(/^\$\./, "");
1527
1589
  if (!rawPath || rawPath === "$") continue;
1528
1590
  const segments = parsePath(rawPath);
1591
+ if (!hasContiguousIndexes(this.accumulatedArgs, segments)) continue;
1529
1592
  const existingValue = getNestedValue(this.accumulatedArgs, segments);
1530
1593
  const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
1531
1594
  if (isStringContinuation) {
@@ -1746,6 +1809,17 @@ function getNestedValue(obj, segments) {
1746
1809
  }
1747
1810
  return current;
1748
1811
  }
1812
+ function hasContiguousIndexes(obj, segments) {
1813
+ let current = obj;
1814
+ for (const pathSegment of segments) {
1815
+ if (typeof pathSegment === "number") {
1816
+ const length = Array.isArray(current) ? current.length : current == null ? 0 : void 0;
1817
+ if (length !== void 0 && pathSegment > length) return false;
1818
+ }
1819
+ current = current != null && typeof current === "object" && hasOwnProperty(current, pathSegment) ? current[pathSegment] : void 0;
1820
+ }
1821
+ return true;
1822
+ }
1749
1823
  function setNestedValue(obj, segments, value) {
1750
1824
  let current = obj;
1751
1825
  for (let i = 0; i < segments.length - 1; i++) {
@@ -4756,6 +4830,8 @@ import { z as z13 } from "zod/v4";
4756
4830
  var googleInteractionsLanguageModelOptions = lazySchema10(
4757
4831
  () => zodSchema10(
4758
4832
  z13.object({
4833
+ /** User-defined request metadata, including `safety_identifier`. */
4834
+ labels: z13.record(z13.string(), z13.string()).nullish(),
4759
4835
  previousInteractionId: z13.string().nullish(),
4760
4836
  store: z13.boolean().nullish(),
4761
4837
  agent: z13.string().nullish(),
@@ -5720,7 +5796,7 @@ var GoogleInteractionsLanguageModel = class {
5720
5796
  };
5721
5797
  }
5722
5798
  async getArgs(options) {
5723
- var _a, _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;
5799
+ var _a, _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;
5724
5800
  const warnings = [];
5725
5801
  const opts = await parseProviderOptions2({
5726
5802
  provider: "google",
@@ -5955,24 +6031,25 @@ var GoogleInteractionsLanguageModel = class {
5955
6031
  const args = pruneUndefined({
5956
6032
  ...isAgent ? { agent: this.agent } : { model: this.modelId },
5957
6033
  input,
6034
+ labels: (_B = opts == null ? void 0 : opts.labels) != null ? _B : void 0,
5958
6035
  system_instruction: systemInstruction,
5959
6036
  tools: toolsForBody,
5960
6037
  response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
5961
6038
  response_modalities: (opts == null ? void 0 : opts.responseModalities) != null ? opts.responseModalities : void 0,
5962
- previous_interaction_id: (_B = opts == null ? void 0 : opts.previousInteractionId) != null ? _B : void 0,
5963
- service_tier: (_C = opts == null ? void 0 : opts.serviceTier) != null ? _C : void 0,
5964
- store: (_D = opts == null ? void 0 : opts.store) != null ? _D : void 0,
6039
+ previous_interaction_id: (_C = opts == null ? void 0 : opts.previousInteractionId) != null ? _C : void 0,
6040
+ service_tier: (_D = opts == null ? void 0 : opts.serviceTier) != null ? _D : void 0,
6041
+ store: (_E = opts == null ? void 0 : opts.store) != null ? _E : void 0,
5965
6042
  generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
5966
6043
  agent_config: agentConfig,
5967
6044
  environment,
5968
- background: (_E = opts == null ? void 0 : opts.background) != null ? _E : void 0
6045
+ background: (_F = opts == null ? void 0 : opts.background) != null ? _F : void 0
5969
6046
  });
5970
6047
  return {
5971
6048
  args,
5972
6049
  warnings,
5973
6050
  isAgent,
5974
6051
  isBackground: (opts == null ? void 0 : opts.background) === true,
5975
- pollingTimeoutMs: (_F = opts == null ? void 0 : opts.pollingTimeoutMs) != null ? _F : void 0
6052
+ pollingTimeoutMs: (_G = opts == null ? void 0 : opts.pollingTimeoutMs) != null ? _G : void 0
5976
6053
  };
5977
6054
  }
5978
6055
  async doGenerate(options) {