@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.
@@ -627,6 +627,7 @@ function prepareTools({
627
627
  };
628
628
  }
629
629
  const functionDeclarations = [];
630
+ let hasStrictTools = false;
630
631
  for (const tool of tools) {
631
632
  switch (tool.type) {
632
633
  case "function":
@@ -635,6 +636,9 @@ function prepareTools({
635
636
  description: (_a = tool.description) != null ? _a : "",
636
637
  parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
637
638
  });
639
+ if (tool.strict === true) {
640
+ hasStrictTools = true;
641
+ }
638
642
  break;
639
643
  default:
640
644
  toolWarnings.push({
@@ -647,7 +651,7 @@ function prepareTools({
647
651
  if (toolChoice == null) {
648
652
  return {
649
653
  tools: [{ functionDeclarations }],
650
- toolConfig: void 0,
654
+ toolConfig: hasStrictTools ? { functionCallingConfig: { mode: "VALIDATED" } } : void 0,
651
655
  toolWarnings
652
656
  };
653
657
  }
@@ -656,7 +660,11 @@ function prepareTools({
656
660
  case "auto":
657
661
  return {
658
662
  tools: [{ functionDeclarations }],
659
- toolConfig: { functionCallingConfig: { mode: "AUTO" } },
663
+ toolConfig: {
664
+ functionCallingConfig: {
665
+ mode: hasStrictTools ? "VALIDATED" : "AUTO"
666
+ }
667
+ },
660
668
  toolWarnings
661
669
  };
662
670
  case "none":
@@ -668,7 +676,11 @@ function prepareTools({
668
676
  case "required":
669
677
  return {
670
678
  tools: [{ functionDeclarations }],
671
- toolConfig: { functionCallingConfig: { mode: "ANY" } },
679
+ toolConfig: {
680
+ functionCallingConfig: {
681
+ mode: hasStrictTools ? "VALIDATED" : "ANY"
682
+ }
683
+ },
672
684
  toolWarnings
673
685
  };
674
686
  case "tool":
@@ -676,7 +688,7 @@ function prepareTools({
676
688
  tools: [{ functionDeclarations }],
677
689
  toolConfig: {
678
690
  functionCallingConfig: {
679
- mode: "ANY",
691
+ mode: hasStrictTools ? "VALIDATED" : "ANY",
680
692
  allowedFunctionNames: [toolChoice.toolName]
681
693
  }
682
694
  },
@@ -985,6 +997,8 @@ var GoogleGenerativeAILanguageModel = class {
985
997
  };
986
998
  let usage = void 0;
987
999
  let providerMetadata = void 0;
1000
+ let lastGroundingMetadata = null;
1001
+ let lastUrlContextMetadata = null;
988
1002
  const generateId2 = this.config.generateId;
989
1003
  let hasToolCalls = false;
990
1004
  let currentTextBlockId = null;
@@ -999,7 +1013,7 @@ var GoogleGenerativeAILanguageModel = class {
999
1013
  controller.enqueue({ type: "stream-start", warnings });
1000
1014
  },
1001
1015
  transform(chunk, controller) {
1002
- var _a, _b, _c, _d, _e, _f, _g, _h;
1016
+ var _a, _b, _c, _d, _e, _f;
1003
1017
  if (options.includeRawChunks) {
1004
1018
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1005
1019
  }
@@ -1017,6 +1031,12 @@ var GoogleGenerativeAILanguageModel = class {
1017
1031
  return;
1018
1032
  }
1019
1033
  const content = candidate.content;
1034
+ if (candidate.groundingMetadata != null) {
1035
+ lastGroundingMetadata = candidate.groundingMetadata;
1036
+ }
1037
+ if (candidate.urlContextMetadata != null) {
1038
+ lastUrlContextMetadata = candidate.urlContextMetadata;
1039
+ }
1020
1040
  const sources = extractSources({
1021
1041
  groundingMetadata: candidate.groundingMetadata,
1022
1042
  generateId: generateId2
@@ -1190,9 +1210,9 @@ var GoogleGenerativeAILanguageModel = class {
1190
1210
  providerMetadata = {
1191
1211
  [providerOptionsName]: {
1192
1212
  promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
1193
- groundingMetadata: (_f = candidate.groundingMetadata) != null ? _f : null,
1194
- urlContextMetadata: (_g = candidate.urlContextMetadata) != null ? _g : null,
1195
- safetyRatings: (_h = candidate.safetyRatings) != null ? _h : null
1213
+ groundingMetadata: lastGroundingMetadata,
1214
+ urlContextMetadata: lastUrlContextMetadata,
1215
+ safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null
1196
1216
  }
1197
1217
  };
1198
1218
  if (usageMetadata != null) {