@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.
@@ -638,6 +638,7 @@ function prepareTools({
638
638
  };
639
639
  }
640
640
  const functionDeclarations = [];
641
+ let hasStrictTools = false;
641
642
  for (const tool of tools) {
642
643
  switch (tool.type) {
643
644
  case "function":
@@ -646,6 +647,9 @@ function prepareTools({
646
647
  description: (_a = tool.description) != null ? _a : "",
647
648
  parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
648
649
  });
650
+ if (tool.strict === true) {
651
+ hasStrictTools = true;
652
+ }
649
653
  break;
650
654
  default:
651
655
  toolWarnings.push({
@@ -658,7 +662,7 @@ function prepareTools({
658
662
  if (toolChoice == null) {
659
663
  return {
660
664
  tools: [{ functionDeclarations }],
661
- toolConfig: void 0,
665
+ toolConfig: hasStrictTools ? { functionCallingConfig: { mode: "VALIDATED" } } : void 0,
662
666
  toolWarnings
663
667
  };
664
668
  }
@@ -667,7 +671,11 @@ function prepareTools({
667
671
  case "auto":
668
672
  return {
669
673
  tools: [{ functionDeclarations }],
670
- toolConfig: { functionCallingConfig: { mode: "AUTO" } },
674
+ toolConfig: {
675
+ functionCallingConfig: {
676
+ mode: hasStrictTools ? "VALIDATED" : "AUTO"
677
+ }
678
+ },
671
679
  toolWarnings
672
680
  };
673
681
  case "none":
@@ -679,7 +687,11 @@ function prepareTools({
679
687
  case "required":
680
688
  return {
681
689
  tools: [{ functionDeclarations }],
682
- toolConfig: { functionCallingConfig: { mode: "ANY" } },
690
+ toolConfig: {
691
+ functionCallingConfig: {
692
+ mode: hasStrictTools ? "VALIDATED" : "ANY"
693
+ }
694
+ },
683
695
  toolWarnings
684
696
  };
685
697
  case "tool":
@@ -687,7 +699,7 @@ function prepareTools({
687
699
  tools: [{ functionDeclarations }],
688
700
  toolConfig: {
689
701
  functionCallingConfig: {
690
- mode: "ANY",
702
+ mode: hasStrictTools ? "VALIDATED" : "ANY",
691
703
  allowedFunctionNames: [toolChoice.toolName]
692
704
  }
693
705
  },
@@ -996,6 +1008,8 @@ var GoogleGenerativeAILanguageModel = class {
996
1008
  };
997
1009
  let usage = void 0;
998
1010
  let providerMetadata = void 0;
1011
+ let lastGroundingMetadata = null;
1012
+ let lastUrlContextMetadata = null;
999
1013
  const generateId2 = this.config.generateId;
1000
1014
  let hasToolCalls = false;
1001
1015
  let currentTextBlockId = null;
@@ -1010,7 +1024,7 @@ var GoogleGenerativeAILanguageModel = class {
1010
1024
  controller.enqueue({ type: "stream-start", warnings });
1011
1025
  },
1012
1026
  transform(chunk, controller) {
1013
- var _a, _b, _c, _d, _e, _f, _g, _h;
1027
+ var _a, _b, _c, _d, _e, _f;
1014
1028
  if (options.includeRawChunks) {
1015
1029
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1016
1030
  }
@@ -1028,6 +1042,12 @@ var GoogleGenerativeAILanguageModel = class {
1028
1042
  return;
1029
1043
  }
1030
1044
  const content = candidate.content;
1045
+ if (candidate.groundingMetadata != null) {
1046
+ lastGroundingMetadata = candidate.groundingMetadata;
1047
+ }
1048
+ if (candidate.urlContextMetadata != null) {
1049
+ lastUrlContextMetadata = candidate.urlContextMetadata;
1050
+ }
1031
1051
  const sources = extractSources({
1032
1052
  groundingMetadata: candidate.groundingMetadata,
1033
1053
  generateId: generateId2
@@ -1201,9 +1221,9 @@ var GoogleGenerativeAILanguageModel = class {
1201
1221
  providerMetadata = {
1202
1222
  [providerOptionsName]: {
1203
1223
  promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
1204
- groundingMetadata: (_f = candidate.groundingMetadata) != null ? _f : null,
1205
- urlContextMetadata: (_g = candidate.urlContextMetadata) != null ? _g : null,
1206
- safetyRatings: (_h = candidate.safetyRatings) != null ? _h : null
1224
+ groundingMetadata: lastGroundingMetadata,
1225
+ urlContextMetadata: lastUrlContextMetadata,
1226
+ safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null
1207
1227
  }
1208
1228
  };
1209
1229
  if (usageMetadata != null) {