@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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 3.0.45
4
+
5
+ ### Patch Changes
6
+
7
+ - e2a59ef: fix(provider/google): preserve groundingMetadata and urlContextMetadata when they arrive in a stream chunk before the finishReason chunk
8
+
9
+ ## 3.0.44
10
+
11
+ ### Patch Changes
12
+
13
+ - 45d71c3: fix(google): use VALIDATED function calling mode when any tool has strict:true
14
+
3
15
  ## 3.0.43
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(src_exports);
30
30
  var import_provider_utils16 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/version.ts
33
- var VERSION = true ? "3.0.43" : "0.0.0-test";
33
+ var VERSION = true ? "3.0.45" : "0.0.0-test";
34
34
 
35
35
  // src/google-generative-ai-embedding-model.ts
36
36
  var import_provider = require("@ai-sdk/provider");
@@ -795,6 +795,7 @@ function prepareTools({
795
795
  };
796
796
  }
797
797
  const functionDeclarations = [];
798
+ let hasStrictTools = false;
798
799
  for (const tool of tools) {
799
800
  switch (tool.type) {
800
801
  case "function":
@@ -803,6 +804,9 @@ function prepareTools({
803
804
  description: (_a = tool.description) != null ? _a : "",
804
805
  parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
805
806
  });
807
+ if (tool.strict === true) {
808
+ hasStrictTools = true;
809
+ }
806
810
  break;
807
811
  default:
808
812
  toolWarnings.push({
@@ -815,7 +819,7 @@ function prepareTools({
815
819
  if (toolChoice == null) {
816
820
  return {
817
821
  tools: [{ functionDeclarations }],
818
- toolConfig: void 0,
822
+ toolConfig: hasStrictTools ? { functionCallingConfig: { mode: "VALIDATED" } } : void 0,
819
823
  toolWarnings
820
824
  };
821
825
  }
@@ -824,7 +828,11 @@ function prepareTools({
824
828
  case "auto":
825
829
  return {
826
830
  tools: [{ functionDeclarations }],
827
- toolConfig: { functionCallingConfig: { mode: "AUTO" } },
831
+ toolConfig: {
832
+ functionCallingConfig: {
833
+ mode: hasStrictTools ? "VALIDATED" : "AUTO"
834
+ }
835
+ },
828
836
  toolWarnings
829
837
  };
830
838
  case "none":
@@ -836,7 +844,11 @@ function prepareTools({
836
844
  case "required":
837
845
  return {
838
846
  tools: [{ functionDeclarations }],
839
- toolConfig: { functionCallingConfig: { mode: "ANY" } },
847
+ toolConfig: {
848
+ functionCallingConfig: {
849
+ mode: hasStrictTools ? "VALIDATED" : "ANY"
850
+ }
851
+ },
840
852
  toolWarnings
841
853
  };
842
854
  case "tool":
@@ -844,7 +856,7 @@ function prepareTools({
844
856
  tools: [{ functionDeclarations }],
845
857
  toolConfig: {
846
858
  functionCallingConfig: {
847
- mode: "ANY",
859
+ mode: hasStrictTools ? "VALIDATED" : "ANY",
848
860
  allowedFunctionNames: [toolChoice.toolName]
849
861
  }
850
862
  },
@@ -1153,6 +1165,8 @@ var GoogleGenerativeAILanguageModel = class {
1153
1165
  };
1154
1166
  let usage = void 0;
1155
1167
  let providerMetadata = void 0;
1168
+ let lastGroundingMetadata = null;
1169
+ let lastUrlContextMetadata = null;
1156
1170
  const generateId3 = this.config.generateId;
1157
1171
  let hasToolCalls = false;
1158
1172
  let currentTextBlockId = null;
@@ -1167,7 +1181,7 @@ var GoogleGenerativeAILanguageModel = class {
1167
1181
  controller.enqueue({ type: "stream-start", warnings });
1168
1182
  },
1169
1183
  transform(chunk, controller) {
1170
- var _a, _b, _c, _d, _e, _f, _g, _h;
1184
+ var _a, _b, _c, _d, _e, _f;
1171
1185
  if (options.includeRawChunks) {
1172
1186
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1173
1187
  }
@@ -1185,6 +1199,12 @@ var GoogleGenerativeAILanguageModel = class {
1185
1199
  return;
1186
1200
  }
1187
1201
  const content = candidate.content;
1202
+ if (candidate.groundingMetadata != null) {
1203
+ lastGroundingMetadata = candidate.groundingMetadata;
1204
+ }
1205
+ if (candidate.urlContextMetadata != null) {
1206
+ lastUrlContextMetadata = candidate.urlContextMetadata;
1207
+ }
1188
1208
  const sources = extractSources({
1189
1209
  groundingMetadata: candidate.groundingMetadata,
1190
1210
  generateId: generateId3
@@ -1358,9 +1378,9 @@ var GoogleGenerativeAILanguageModel = class {
1358
1378
  providerMetadata = {
1359
1379
  [providerOptionsName]: {
1360
1380
  promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
1361
- groundingMetadata: (_f = candidate.groundingMetadata) != null ? _f : null,
1362
- urlContextMetadata: (_g = candidate.urlContextMetadata) != null ? _g : null,
1363
- safetyRatings: (_h = candidate.safetyRatings) != null ? _h : null
1381
+ groundingMetadata: lastGroundingMetadata,
1382
+ urlContextMetadata: lastUrlContextMetadata,
1383
+ safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null
1364
1384
  }
1365
1385
  };
1366
1386
  if (usageMetadata != null) {