@ai-sdk/google 3.0.141 → 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,
@@ -1245,6 +1307,9 @@ function prepareTools({
1245
1307
  modelId,
1246
1308
  isVertexProvider = false
1247
1309
  }) {
1310
+ if ((toolChoice == null ? void 0 : toolChoice.type) === "none") {
1311
+ tools = tools == null ? void 0 : tools.filter((tool) => tool.type === "function");
1312
+ }
1248
1313
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
1249
1314
  const toolWarnings = [];
1250
1315
  const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
@@ -1523,6 +1588,7 @@ var GoogleJSONAccumulator = class {
1523
1588
  const rawPath = jsonPath.replace(/^\$\./, "");
1524
1589
  if (!rawPath || rawPath === "$") continue;
1525
1590
  const segments = parsePath(rawPath);
1591
+ if (!hasContiguousIndexes(this.accumulatedArgs, segments)) continue;
1526
1592
  const existingValue = getNestedValue(this.accumulatedArgs, segments);
1527
1593
  const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
1528
1594
  if (isStringContinuation) {
@@ -1743,6 +1809,17 @@ function getNestedValue(obj, segments) {
1743
1809
  }
1744
1810
  return current;
1745
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
+ }
1746
1823
  function setNestedValue(obj, segments, value) {
1747
1824
  let current = obj;
1748
1825
  for (let i = 0; i < segments.length - 1; i++) {
@@ -4753,6 +4830,8 @@ import { z as z13 } from "zod/v4";
4753
4830
  var googleInteractionsLanguageModelOptions = lazySchema10(
4754
4831
  () => zodSchema10(
4755
4832
  z13.object({
4833
+ /** User-defined request metadata, including `safety_identifier`. */
4834
+ labels: z13.record(z13.string(), z13.string()).nullish(),
4756
4835
  previousInteractionId: z13.string().nullish(),
4757
4836
  store: z13.boolean().nullish(),
4758
4837
  agent: z13.string().nullish(),
@@ -5717,7 +5796,7 @@ var GoogleInteractionsLanguageModel = class {
5717
5796
  };
5718
5797
  }
5719
5798
  async getArgs(options) {
5720
- 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;
5721
5800
  const warnings = [];
5722
5801
  const opts = await parseProviderOptions2({
5723
5802
  provider: "google",
@@ -5952,24 +6031,25 @@ var GoogleInteractionsLanguageModel = class {
5952
6031
  const args = pruneUndefined({
5953
6032
  ...isAgent ? { agent: this.agent } : { model: this.modelId },
5954
6033
  input,
6034
+ labels: (_B = opts == null ? void 0 : opts.labels) != null ? _B : void 0,
5955
6035
  system_instruction: systemInstruction,
5956
6036
  tools: toolsForBody,
5957
6037
  response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
5958
6038
  response_modalities: (opts == null ? void 0 : opts.responseModalities) != null ? opts.responseModalities : void 0,
5959
- previous_interaction_id: (_B = opts == null ? void 0 : opts.previousInteractionId) != null ? _B : void 0,
5960
- service_tier: (_C = opts == null ? void 0 : opts.serviceTier) != null ? _C : void 0,
5961
- 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,
5962
6042
  generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
5963
6043
  agent_config: agentConfig,
5964
6044
  environment,
5965
- 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
5966
6046
  });
5967
6047
  return {
5968
6048
  args,
5969
6049
  warnings,
5970
6050
  isAgent,
5971
6051
  isBackground: (opts == null ? void 0 : opts.background) === true,
5972
- 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
5973
6053
  };
5974
6054
  }
5975
6055
  async doGenerate(options) {