@ai-sdk/google 3.0.99 → 3.0.101

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.
@@ -230,7 +230,7 @@ function convertUrlToolResultPart(url) {
230
230
  }
231
231
  };
232
232
  }
233
- function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
233
+ function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
234
234
  const functionResponseParts = [];
235
235
  const responseTextParts = [];
236
236
  for (const contentPart of outputValue) {
@@ -269,7 +269,7 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
269
269
  }
270
270
  parts.push({
271
271
  functionResponse: {
272
- ...toolCallId != null ? { id: toolCallId } : {},
272
+ ...includeFunctionCallIds && toolCallId != null ? { id: toolCallId } : {},
273
273
  name: toolName,
274
274
  response: {
275
275
  name: toolName,
@@ -279,13 +279,13 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
279
279
  }
280
280
  });
281
281
  }
282
- function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
282
+ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
283
283
  for (const contentPart of outputValue) {
284
284
  switch (contentPart.type) {
285
285
  case "text":
286
286
  parts.push({
287
287
  functionResponse: {
288
- ...toolCallId != null ? { id: toolCallId } : {},
288
+ ...includeFunctionCallIds && toolCallId != null ? { id: toolCallId } : {},
289
289
  name: toolName,
290
290
  response: {
291
291
  name: toolName,
@@ -317,7 +317,7 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
317
317
  }
318
318
  }
319
319
  function convertToGoogleGenerativeAIMessages(prompt, options) {
320
- var _a, _b, _c, _d, _e;
320
+ var _a, _b, _c, _d, _e, _f;
321
321
  const systemInstructionParts = [];
322
322
  const contents = [];
323
323
  let systemMessagesAllowed = true;
@@ -326,6 +326,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
326
326
  const providerOptionsName = (_c = options == null ? void 0 : options.providerOptionsName) != null ? _c : "google";
327
327
  const supportsFunctionResponseParts = (_d = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _d : true;
328
328
  const onWarning = options == null ? void 0 : options.onWarning;
329
+ const includeFunctionCallIds = (_e = options == null ? void 0 : options.includeFunctionCallIds) != null ? _e : true;
329
330
  let sentinelInjected = false;
330
331
  const missingSignatureToolNames = [];
331
332
  const injectSkipSignature = (toolName) => {
@@ -442,7 +443,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
442
443
  }
443
444
  return {
444
445
  functionCall: {
445
- ...part.toolCallId != null ? { id: part.toolCallId } : {},
446
+ ...includeFunctionCallIds && part.toolCallId != null ? { id: part.toolCallId } : {},
446
447
  name: part.toolName,
447
448
  args: part.input
448
449
  },
@@ -506,24 +507,26 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
506
507
  parts,
507
508
  part.toolName,
508
509
  output.value,
509
- part.toolCallId
510
+ part.toolCallId,
511
+ includeFunctionCallIds
510
512
  );
511
513
  } else {
512
514
  appendLegacyToolResultParts(
513
515
  parts,
514
516
  part.toolName,
515
517
  output.value,
516
- part.toolCallId
518
+ part.toolCallId,
519
+ includeFunctionCallIds
517
520
  );
518
521
  }
519
522
  } else {
520
523
  parts.push({
521
524
  functionResponse: {
522
- ...part.toolCallId != null ? { id: part.toolCallId } : {},
525
+ ...includeFunctionCallIds && part.toolCallId != null ? { id: part.toolCallId } : {},
523
526
  name: part.toolName,
524
527
  response: {
525
528
  name: part.toolName,
526
- content: output.type === "execution-denied" ? (_e = output.reason) != null ? _e : "Tool call execution denied." : output.value
529
+ content: output.type === "execution-denied" ? (_f = output.reason) != null ? _f : "Tool call execution denied." : output.value
527
530
  }
528
531
  }
529
532
  });
@@ -766,6 +769,27 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
766
769
  )
767
770
  );
768
771
 
772
+ // src/google-model-capabilities.ts
773
+ var gemini1ModelPattern = /(^|\/)gemini-1(?:[.-]|$)/i;
774
+ var gemini2ModelPattern = /(^|\/)gemini-2(?:[.-]|$)/i;
775
+ var gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
776
+ var geminiModelPattern = /(^|\/)gemini-/i;
777
+ function isKnownPreGemini2Model(modelId) {
778
+ return gemini1ModelPattern.test(modelId) || /(^|\/)gemini-pro(?:-vision)?$/i.test(modelId) || /(^|\/)gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId);
779
+ }
780
+ function getGoogleModelCapabilities(modelId) {
781
+ const isGeminiModel = geminiModelPattern.test(modelId);
782
+ const isGemini2Model = gemini2ModelPattern.test(modelId);
783
+ const isKnownPreGemini2 = isKnownPreGemini2Model(modelId);
784
+ const isKnownOlderModel = isKnownPreGemini2 || isGemini2Model;
785
+ const usesGemini3Features = isGeminiModel && !isKnownOlderModel;
786
+ return {
787
+ supportsGemini2Tools: isGeminiModel && !isKnownPreGemini2 || modelId.toLowerCase().includes("nano-banana"),
788
+ supportsFileSearch: gemini25ModelPattern.test(modelId) || usesGemini3Features,
789
+ usesGemini3Features
790
+ };
791
+ }
792
+
769
793
  // src/google-prepare-tools.ts
770
794
  var import_provider2 = require("@ai-sdk/provider");
771
795
  function prepareTools({
@@ -777,20 +801,13 @@ function prepareTools({
777
801
  var _a, _b;
778
802
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
779
803
  const toolWarnings = [];
780
- const isLatest = [
781
- "gemini-flash-latest",
782
- "gemini-flash-lite-latest",
783
- "gemini-pro-latest"
784
- ].some((id) => id === modelId);
785
- const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
786
- const isGemini3orNewer = modelId.includes("gemini-3");
787
- const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
804
+ const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
788
805
  if (tools == null) {
789
806
  return { tools: void 0, toolConfig: void 0, toolWarnings };
790
807
  }
791
808
  const hasFunctionTools = tools.some((tool) => tool.type === "function");
792
809
  const hasProviderTools = tools.some((tool) => tool.type === "provider");
793
- if (hasFunctionTools && hasProviderTools && !isGemini3orNewer) {
810
+ if (hasFunctionTools && hasProviderTools && !usesGemini3Features) {
794
811
  toolWarnings.push({
795
812
  type: "unsupported",
796
813
  feature: `combination of function and provider-defined tools`
@@ -802,7 +819,7 @@ function prepareTools({
802
819
  ProviderTools.forEach((tool) => {
803
820
  switch (tool.id) {
804
821
  case "google.google_search":
805
- if (isGemini2orNewer) {
822
+ if (supportsGemini2Tools) {
806
823
  googleTools2.push({ googleSearch: { ...tool.args } });
807
824
  } else {
808
825
  toolWarnings.push({
@@ -813,7 +830,7 @@ function prepareTools({
813
830
  }
814
831
  break;
815
832
  case "google.enterprise_web_search":
816
- if (isGemini2orNewer) {
833
+ if (supportsGemini2Tools) {
817
834
  googleTools2.push({ enterpriseWebSearch: {} });
818
835
  } else {
819
836
  toolWarnings.push({
@@ -824,7 +841,7 @@ function prepareTools({
824
841
  }
825
842
  break;
826
843
  case "google.url_context":
827
- if (isGemini2orNewer) {
844
+ if (supportsGemini2Tools) {
828
845
  googleTools2.push({ urlContext: {} });
829
846
  } else {
830
847
  toolWarnings.push({
@@ -835,7 +852,7 @@ function prepareTools({
835
852
  }
836
853
  break;
837
854
  case "google.code_execution":
838
- if (isGemini2orNewer) {
855
+ if (supportsGemini2Tools) {
839
856
  googleTools2.push({ codeExecution: {} });
840
857
  } else {
841
858
  toolWarnings.push({
@@ -857,7 +874,7 @@ function prepareTools({
857
874
  }
858
875
  break;
859
876
  case "google.vertex_rag_store":
860
- if (isGemini2orNewer) {
877
+ if (supportsGemini2Tools) {
861
878
  googleTools2.push({
862
879
  retrieval: {
863
880
  vertex_rag_store: {
@@ -877,7 +894,7 @@ function prepareTools({
877
894
  }
878
895
  break;
879
896
  case "google.google_maps":
880
- if (isGemini2orNewer) {
897
+ if (supportsGemini2Tools) {
881
898
  googleTools2.push({ googleMaps: {} });
882
899
  } else {
883
900
  toolWarnings.push({
@@ -895,7 +912,7 @@ function prepareTools({
895
912
  break;
896
913
  }
897
914
  });
898
- if (hasFunctionTools && isGemini3orNewer && googleTools2.length > 0) {
915
+ if (hasFunctionTools && usesGemini3Features && googleTools2.length > 0) {
899
916
  const functionDeclarations2 = [];
900
917
  for (const tool of tools) {
901
918
  if (tool.type === "function") {
@@ -1392,16 +1409,16 @@ var GoogleGenerativeAILanguageModel = class {
1392
1409
  }
1393
1410
  }
1394
1411
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
1395
- const isGemini3Model = /^gemini-3[.-]/.test(this.modelId);
1396
- const supportsFunctionResponseParts = isGemini3Model;
1412
+ const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
1397
1413
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
1398
1414
  prompt,
1399
1415
  {
1400
1416
  isGemmaModel,
1401
- isGemini3Model,
1417
+ isGemini3Model: usesGemini3Features,
1402
1418
  providerOptionsName,
1403
- supportsFunctionResponseParts,
1404
- onWarning: (warning) => warnings.push(warning)
1419
+ supportsFunctionResponseParts: usesGemini3Features,
1420
+ onWarning: (warning) => warnings.push(warning),
1421
+ includeFunctionCallIds: !isVertexProvider
1405
1422
  }
1406
1423
  );
1407
1424
  const {