@ai-sdk/google 3.0.113 → 3.0.114

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.
@@ -55,6 +55,10 @@ function convertGoogleGenerativeAIUsage(usage) {
55
55
  import {
56
56
  UnsupportedFunctionalityError
57
57
  } from "@ai-sdk/provider";
58
+ var recursiveReferenceFunctionalityPrefix = "recursive JSON Schema reference:";
59
+ function isRecursiveJSONSchemaReferenceError(error) {
60
+ return UnsupportedFunctionalityError.isInstance(error) && error.functionality.startsWith(recursiveReferenceFunctionalityPrefix);
61
+ }
58
62
  function convertJSONSchemaToOpenAPISchema(jsonSchema, isRoot = true) {
59
63
  const rootSchema = typeof jsonSchema === "object" ? jsonSchema : void 0;
60
64
  return convertJSONSchemaDefinition(jsonSchema, isRoot, {
@@ -197,7 +201,7 @@ function convertJSONSchemaReference({
197
201
  );
198
202
  if (referenceContext.resolvingReferences.has(referenceKey)) {
199
203
  throw new UnsupportedFunctionalityError({
200
- functionality: `recursive JSON Schema reference: ${reference}`,
204
+ functionality: `${recursiveReferenceFunctionalityPrefix} ${reference}`,
201
205
  message: "Google schema conversion does not support recursive JSON Schema references."
202
206
  });
203
207
  }
@@ -882,7 +886,6 @@ function prepareTools({
882
886
  modelId,
883
887
  isVertexProvider = false
884
888
  }) {
885
- var _a, _b;
886
889
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
887
890
  const toolWarnings = [];
888
891
  const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
@@ -1000,11 +1003,7 @@ function prepareTools({
1000
1003
  const functionDeclarations2 = [];
1001
1004
  for (const tool of tools) {
1002
1005
  if (tool.type === "function") {
1003
- functionDeclarations2.push({
1004
- name: tool.name,
1005
- description: (_a = tool.description) != null ? _a : "",
1006
- parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
1007
- });
1006
+ functionDeclarations2.push(prepareFunctionDeclaration(tool));
1008
1007
  }
1009
1008
  }
1010
1009
  const combinedToolConfig = {
@@ -1048,11 +1047,7 @@ function prepareTools({
1048
1047
  for (const tool of tools) {
1049
1048
  switch (tool.type) {
1050
1049
  case "function":
1051
- functionDeclarations.push({
1052
- name: tool.name,
1053
- description: (_b = tool.description) != null ? _b : "",
1054
- parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
1055
- });
1050
+ functionDeclarations.push(prepareFunctionDeclaration(tool));
1056
1051
  if (tool.strict === true) {
1057
1052
  hasStrictTools = true;
1058
1053
  }
@@ -1119,6 +1114,27 @@ function prepareTools({
1119
1114
  }
1120
1115
  }
1121
1116
  }
1117
+ function prepareFunctionDeclaration(tool) {
1118
+ var _a;
1119
+ const declaration = {
1120
+ name: tool.name,
1121
+ description: (_a = tool.description) != null ? _a : ""
1122
+ };
1123
+ try {
1124
+ return {
1125
+ ...declaration,
1126
+ parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
1127
+ };
1128
+ } catch (error) {
1129
+ if (!isRecursiveJSONSchemaReferenceError(error)) {
1130
+ throw error;
1131
+ }
1132
+ return {
1133
+ ...declaration,
1134
+ parametersJsonSchema: tool.inputSchema
1135
+ };
1136
+ }
1137
+ }
1122
1138
 
1123
1139
  // src/google-json-accumulator.ts
1124
1140
  var GoogleJSONAccumulator = class {