@ai-sdk/google 3.0.43 → 3.0.45

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
@@ -7,7 +7,7 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "3.0.43" : "0.0.0-test";
10
+ var VERSION = true ? "3.0.45" : "0.0.0-test";
11
11
 
12
12
  // src/google-generative-ai-embedding-model.ts
13
13
  import {
@@ -803,6 +803,7 @@ function prepareTools({
803
803
  };
804
804
  }
805
805
  const functionDeclarations = [];
806
+ let hasStrictTools = false;
806
807
  for (const tool of tools) {
807
808
  switch (tool.type) {
808
809
  case "function":
@@ -811,6 +812,9 @@ function prepareTools({
811
812
  description: (_a = tool.description) != null ? _a : "",
812
813
  parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
813
814
  });
815
+ if (tool.strict === true) {
816
+ hasStrictTools = true;
817
+ }
814
818
  break;
815
819
  default:
816
820
  toolWarnings.push({
@@ -823,7 +827,7 @@ function prepareTools({
823
827
  if (toolChoice == null) {
824
828
  return {
825
829
  tools: [{ functionDeclarations }],
826
- toolConfig: void 0,
830
+ toolConfig: hasStrictTools ? { functionCallingConfig: { mode: "VALIDATED" } } : void 0,
827
831
  toolWarnings
828
832
  };
829
833
  }
@@ -832,7 +836,11 @@ function prepareTools({
832
836
  case "auto":
833
837
  return {
834
838
  tools: [{ functionDeclarations }],
835
- toolConfig: { functionCallingConfig: { mode: "AUTO" } },
839
+ toolConfig: {
840
+ functionCallingConfig: {
841
+ mode: hasStrictTools ? "VALIDATED" : "AUTO"
842
+ }
843
+ },
836
844
  toolWarnings
837
845
  };
838
846
  case "none":
@@ -844,7 +852,11 @@ function prepareTools({
844
852
  case "required":
845
853
  return {
846
854
  tools: [{ functionDeclarations }],
847
- toolConfig: { functionCallingConfig: { mode: "ANY" } },
855
+ toolConfig: {
856
+ functionCallingConfig: {
857
+ mode: hasStrictTools ? "VALIDATED" : "ANY"
858
+ }
859
+ },
848
860
  toolWarnings
849
861
  };
850
862
  case "tool":
@@ -852,7 +864,7 @@ function prepareTools({
852
864
  tools: [{ functionDeclarations }],
853
865
  toolConfig: {
854
866
  functionCallingConfig: {
855
- mode: "ANY",
867
+ mode: hasStrictTools ? "VALIDATED" : "ANY",
856
868
  allowedFunctionNames: [toolChoice.toolName]
857
869
  }
858
870
  },
@@ -1161,6 +1173,8 @@ var GoogleGenerativeAILanguageModel = class {
1161
1173
  };
1162
1174
  let usage = void 0;
1163
1175
  let providerMetadata = void 0;
1176
+ let lastGroundingMetadata = null;
1177
+ let lastUrlContextMetadata = null;
1164
1178
  const generateId3 = this.config.generateId;
1165
1179
  let hasToolCalls = false;
1166
1180
  let currentTextBlockId = null;
@@ -1175,7 +1189,7 @@ var GoogleGenerativeAILanguageModel = class {
1175
1189
  controller.enqueue({ type: "stream-start", warnings });
1176
1190
  },
1177
1191
  transform(chunk, controller) {
1178
- var _a, _b, _c, _d, _e, _f, _g, _h;
1192
+ var _a, _b, _c, _d, _e, _f;
1179
1193
  if (options.includeRawChunks) {
1180
1194
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1181
1195
  }
@@ -1193,6 +1207,12 @@ var GoogleGenerativeAILanguageModel = class {
1193
1207
  return;
1194
1208
  }
1195
1209
  const content = candidate.content;
1210
+ if (candidate.groundingMetadata != null) {
1211
+ lastGroundingMetadata = candidate.groundingMetadata;
1212
+ }
1213
+ if (candidate.urlContextMetadata != null) {
1214
+ lastUrlContextMetadata = candidate.urlContextMetadata;
1215
+ }
1196
1216
  const sources = extractSources({
1197
1217
  groundingMetadata: candidate.groundingMetadata,
1198
1218
  generateId: generateId3
@@ -1366,9 +1386,9 @@ var GoogleGenerativeAILanguageModel = class {
1366
1386
  providerMetadata = {
1367
1387
  [providerOptionsName]: {
1368
1388
  promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
1369
- groundingMetadata: (_f = candidate.groundingMetadata) != null ? _f : null,
1370
- urlContextMetadata: (_g = candidate.urlContextMetadata) != null ? _g : null,
1371
- safetyRatings: (_h = candidate.safetyRatings) != null ? _h : null
1389
+ groundingMetadata: lastGroundingMetadata,
1390
+ urlContextMetadata: lastUrlContextMetadata,
1391
+ safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null
1372
1392
  }
1373
1393
  };
1374
1394
  if (usageMetadata != null) {