@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.
package/dist/index.mjs CHANGED
@@ -272,7 +272,7 @@ import {
272
272
  } from "@ai-sdk/provider-utils";
273
273
 
274
274
  // src/version.ts
275
- var VERSION = true ? "3.0.141" : "0.0.0-test";
275
+ var VERSION = true ? "3.0.143" : "0.0.0-test";
276
276
 
277
277
  // src/google-generative-ai-embedding-model.ts
278
278
  import {
@@ -671,25 +671,54 @@ function addTokenDetails(a, b) {
671
671
  import {
672
672
  UnsupportedFunctionalityError
673
673
  } from "@ai-sdk/provider";
674
+ var maxSchemaDepth = 100;
675
+ var maxSchemaNodes = 1e4;
676
+ var maxSchemaSize = 1e6;
674
677
  var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
675
678
  function isRecursiveJSONSchemaReferenceError(error) {
676
679
  return UnsupportedFunctionalityError.isInstance(error) && error.functionality.startsWith(recursiveReferenceFunctionalityPrefix);
677
680
  }
678
681
  function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
682
+ consumeSchemaBudget(jsonSchema, {
683
+ nodes: maxSchemaNodes,
684
+ size: maxSchemaSize
685
+ });
679
686
  const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
680
687
  return convertJSONSchemaDefinition(jsonSchema, isRoot, {
681
688
  definitions: rootSchema == null ? void 0 : rootSchema.definitions,
682
689
  dollarDefinitions: rootSchema == null ? void 0 : rootSchema.$defs,
683
- resolvingReferences: /* @__PURE__ */ new Set()
690
+ resolvingReferences: /* @__PURE__ */ new Set(),
691
+ budget: { nodes: maxSchemaNodes, size: maxSchemaSize },
692
+ depth: 0
684
693
  });
685
694
  }
686
695
  function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
687
696
  if (jsonSchema == null) {
688
697
  return void 0;
689
698
  }
699
+ referenceContext.budget.nodes--;
700
+ referenceContext.budget.size -= 128;
701
+ checkSchemaBudget(referenceContext.budget, referenceContext.depth);
702
+ referenceContext = {
703
+ ...referenceContext,
704
+ depth: referenceContext.depth + 1
705
+ };
690
706
  if (typeof jsonSchema === "boolean") {
691
707
  return { type: "boolean", properties: {} };
692
708
  }
709
+ consumeSchemaBudget(
710
+ [
711
+ jsonSchema.$ref,
712
+ jsonSchema.type,
713
+ jsonSchema.description,
714
+ jsonSchema.required,
715
+ jsonSchema.format,
716
+ jsonSchema.const,
717
+ jsonSchema.enum,
718
+ jsonSchema.minLength
719
+ ],
720
+ referenceContext.budget
721
+ );
693
722
  if (jsonSchema.$ref != null) {
694
723
  return convertJSONSchemaReference({
695
724
  jsonSchema,
@@ -753,6 +782,7 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
753
782
  if (properties != null) {
754
783
  result.properties = Object.entries(properties).reduce(
755
784
  (acc, [key, value]) => {
785
+ consumeSchemaBudget(key, referenceContext.budget);
756
786
  acc[key] = convertJSONSchemaDefinition(value, false, referenceContext);
757
787
  return acc;
758
788
  },
@@ -808,6 +838,38 @@ function convertJSONSchemaDefinition(jsonSchema, isRoot, referenceContext) {
808
838
  }
809
839
  return result;
810
840
  }
841
+ function checkSchemaBudget(budget, depth) {
842
+ if (budget.nodes < 0 || budget.size < 0 || depth > maxSchemaDepth) {
843
+ throw new UnsupportedFunctionalityError({
844
+ functionality: "JSON Schema conversion exceeding resource limits",
845
+ message: "Google schema conversion exceeded its node, size, or depth limit."
846
+ });
847
+ }
848
+ }
849
+ function consumeSchemaBudget(value, budget, depth = 0) {
850
+ if (value === void 0) {
851
+ return;
852
+ }
853
+ budget.nodes--;
854
+ budget.size -= typeof value === "string" ? value.length * 6 + 2 : 32;
855
+ checkSchemaBudget(budget, depth);
856
+ if (Array.isArray(value)) {
857
+ for (const item of value) {
858
+ consumeSchemaBudget(item, budget, depth + 1);
859
+ }
860
+ } else if (value !== null && typeof value === "object") {
861
+ for (const key in value) {
862
+ if (Object.prototype.hasOwnProperty.call(value, key)) {
863
+ consumeSchemaBudget(key, budget, depth + 1);
864
+ consumeSchemaBudget(
865
+ value[key],
866
+ budget,
867
+ depth + 1
868
+ );
869
+ }
870
+ }
871
+ }
872
+ }
811
873
  function addEnumToSchema({
812
874
  values,
813
875
  type,
@@ -1696,6 +1758,9 @@ function prepareTools({
1696
1758
  modelId,
1697
1759
  isVertexProvider = false
1698
1760
  }) {
1761
+ if ((toolChoice == null ? void 0 : toolChoice.type) === "none") {
1762
+ tools = tools == null ? void 0 : tools.filter((tool) => tool.type === "function");
1763
+ }
1699
1764
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
1700
1765
  const toolWarnings = [];
1701
1766
  const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
@@ -1974,6 +2039,7 @@ var GoogleJSONAccumulator = class {
1974
2039
  const rawPath = jsonPath.replace(/^\$\./, "");
1975
2040
  if (!rawPath || rawPath === "$") continue;
1976
2041
  const segments = parsePath(rawPath);
2042
+ if (!hasContiguousIndexes(this.accumulatedArgs, segments)) continue;
1977
2043
  const existingValue = getNestedValue(this.accumulatedArgs, segments);
1978
2044
  const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
1979
2045
  if (isStringContinuation) {
@@ -2194,6 +2260,17 @@ function getNestedValue(obj, segments) {
2194
2260
  }
2195
2261
  return current;
2196
2262
  }
2263
+ function hasContiguousIndexes(obj, segments) {
2264
+ let current = obj;
2265
+ for (const pathSegment of segments) {
2266
+ if (typeof pathSegment === "number") {
2267
+ const length = Array.isArray(current) ? current.length : current == null ? 0 : void 0;
2268
+ if (length !== void 0 && pathSegment > length) return false;
2269
+ }
2270
+ current = current != null && typeof current === "object" && hasOwnProperty(current, pathSegment) ? current[pathSegment] : void 0;
2271
+ }
2272
+ return true;
2273
+ }
2197
2274
  function setNestedValue(obj, segments, value) {
2198
2275
  let current = obj;
2199
2276
  for (let i = 0; i < segments.length - 1; i++) {
@@ -5824,6 +5901,8 @@ import { z as z19 } from "zod/v4";
5824
5901
  var googleInteractionsLanguageModelOptions = lazySchema16(
5825
5902
  () => zodSchema16(
5826
5903
  z19.object({
5904
+ /** User-defined request metadata, including `safety_identifier`. */
5905
+ labels: z19.record(z19.string(), z19.string()).nullish(),
5827
5906
  previousInteractionId: z19.string().nullish(),
5828
5907
  store: z19.boolean().nullish(),
5829
5908
  agent: z19.string().nullish(),
@@ -6788,7 +6867,7 @@ var GoogleInteractionsLanguageModel = class {
6788
6867
  };
6789
6868
  }
6790
6869
  async getArgs(options) {
6791
- 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;
6870
+ 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;
6792
6871
  const warnings = [];
6793
6872
  const opts = await parseProviderOptions6({
6794
6873
  provider: "google",
@@ -7023,24 +7102,25 @@ var GoogleInteractionsLanguageModel = class {
7023
7102
  const args = pruneUndefined({
7024
7103
  ...isAgent ? { agent: this.agent } : { model: this.modelId },
7025
7104
  input,
7105
+ labels: (_B = opts == null ? void 0 : opts.labels) != null ? _B : void 0,
7026
7106
  system_instruction: systemInstruction,
7027
7107
  tools: toolsForBody,
7028
7108
  response_format: responseFormatEntries.length > 0 ? responseFormatEntries : void 0,
7029
7109
  response_modalities: (opts == null ? void 0 : opts.responseModalities) != null ? opts.responseModalities : void 0,
7030
- previous_interaction_id: (_B = opts == null ? void 0 : opts.previousInteractionId) != null ? _B : void 0,
7031
- service_tier: (_C = opts == null ? void 0 : opts.serviceTier) != null ? _C : void 0,
7032
- store: (_D = opts == null ? void 0 : opts.store) != null ? _D : void 0,
7110
+ previous_interaction_id: (_C = opts == null ? void 0 : opts.previousInteractionId) != null ? _C : void 0,
7111
+ service_tier: (_D = opts == null ? void 0 : opts.serviceTier) != null ? _D : void 0,
7112
+ store: (_E = opts == null ? void 0 : opts.store) != null ? _E : void 0,
7033
7113
  generation_config: generationConfig != null && Object.keys(generationConfig).length > 0 ? generationConfig : void 0,
7034
7114
  agent_config: agentConfig,
7035
7115
  environment,
7036
- background: (_E = opts == null ? void 0 : opts.background) != null ? _E : void 0
7116
+ background: (_F = opts == null ? void 0 : opts.background) != null ? _F : void 0
7037
7117
  });
7038
7118
  return {
7039
7119
  args,
7040
7120
  warnings,
7041
7121
  isAgent,
7042
7122
  isBackground: (opts == null ? void 0 : opts.background) === true,
7043
- pollingTimeoutMs: (_F = opts == null ? void 0 : opts.pollingTimeoutMs) != null ? _F : void 0
7123
+ pollingTimeoutMs: (_G = opts == null ? void 0 : opts.pollingTimeoutMs) != null ? _G : void 0
7044
7124
  };
7045
7125
  }
7046
7126
  async doGenerate(options) {