@ai-sdk/google 2.0.83 → 2.0.85

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
+ ## 2.0.85
4
+
5
+ ### Patch Changes
6
+
7
+ - 5e9957e: feat(provider/google): default unknown Gemini model IDs to the newest supported capabilities
8
+
9
+ ## 2.0.84
10
+
11
+ ### Patch Changes
12
+
13
+ - b05bffb: feat(google): add `gemini-3.6-flash` and `gemini-3.5-flash-lite` models
14
+
3
15
  ## 2.0.83
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -11,7 +11,7 @@ declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
11
11
  }>;
12
12
  type GoogleErrorData = InferValidator<typeof googleErrorDataSchema>;
13
13
 
14
- type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-3.5-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
14
+ type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-3.5-flash' | 'gemini-3.5-flash-lite' | 'gemini-3.6-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
15
15
  declare const googleGenerativeAIProviderOptions: _ai_sdk_provider_utils.LazySchema<{
16
16
  responseModalities?: ("TEXT" | "IMAGE")[] | undefined;
17
17
  thinkingConfig?: {
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
11
11
  }>;
12
12
  type GoogleErrorData = InferValidator<typeof googleErrorDataSchema>;
13
13
 
14
- type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-3.5-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
14
+ type GoogleGenerativeAIModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-latest' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-flash-8b' | 'gemini-1.5-flash-8b-latest' | 'gemini-1.5-flash-8b-001' | 'gemini-1.5-pro' | 'gemini-1.5-pro-latest' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-2.0-flash' | 'gemini-2.0-flash-001' | 'gemini-2.0-flash-live-001' | 'gemini-2.0-flash-lite' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-thinking-exp-01-21' | 'gemini-2.0-flash-exp' | 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-image-preview' | 'gemini-2.5-flash-lite' | 'gemini-2.5-flash-preview-tts' | 'gemini-2.5-pro-preview-tts' | 'gemini-2.5-flash-native-audio-latest' | 'gemini-2.5-flash-native-audio-preview-09-2025' | 'gemini-2.5-flash-native-audio-preview-12-2025' | 'gemini-2.5-computer-use-preview-10-2025' | 'gemini-3-pro-preview' | 'gemini-3-pro-image-preview' | 'gemini-3-flash-preview' | 'gemini-3.1-pro-preview' | 'gemini-3.1-pro-preview-customtools' | 'gemini-3.1-flash-image-preview' | 'gemini-3.1-flash-lite-preview' | 'gemini-3.1-flash-tts-preview' | 'gemini-3.5-flash' | 'gemini-3.5-flash-lite' | 'gemini-3.6-flash' | 'gemini-pro-latest' | 'gemini-flash-latest' | 'gemini-flash-lite-latest' | 'gemini-2.5-pro-exp-03-25' | 'gemini-exp-1206' | 'gemma-3-12b-it' | 'gemma-3-27b-it' | (string & {});
15
15
  declare const googleGenerativeAIProviderOptions: _ai_sdk_provider_utils.LazySchema<{
16
16
  responseModalities?: ("TEXT" | "IMAGE")[] | undefined;
17
17
  thinkingConfig?: {
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(index_exports);
30
30
  var import_provider_utils15 = require("@ai-sdk/provider-utils");
31
31
 
32
32
  // src/version.ts
33
- var VERSION = true ? "2.0.83" : "0.0.0-test";
33
+ var VERSION = true ? "2.0.85" : "0.0.0-test";
34
34
 
35
35
  // src/google-generative-ai-embedding-model.ts
36
36
  var import_provider = require("@ai-sdk/provider");
@@ -359,13 +359,15 @@ function isEmptyObjectSchema(jsonSchema) {
359
359
  // src/convert-to-google-generative-ai-messages.ts
360
360
  var import_provider2 = require("@ai-sdk/provider");
361
361
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
362
+ var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
362
363
  function convertToGoogleGenerativeAIMessages(prompt, options) {
363
- var _a, _b;
364
+ var _a, _b, _c;
364
365
  const systemInstructionParts = [];
365
366
  const contents = [];
366
367
  let systemMessagesAllowed = true;
367
368
  const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
368
- const supportsFunctionResponseParts = (_b = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _b : true;
369
+ const isGemini3Model = (_b = options == null ? void 0 : options.isGemini3Model) != null ? _b : false;
370
+ const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
369
371
  for (const { role, content } of prompt) {
370
372
  switch (role) {
371
373
  case "system": {
@@ -410,11 +412,12 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
410
412
  }
411
413
  case "assistant": {
412
414
  systemMessagesAllowed = false;
415
+ let modelResponseHasSignedFunctionCall = false;
413
416
  contents.push({
414
417
  role: "model",
415
418
  parts: content.map((part) => {
416
- var _a2, _b2, _c;
417
- const thoughtSignature = ((_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b2.thoughtSignature) != null ? String((_c = part.providerOptions.google) == null ? void 0 : _c.thoughtSignature) : void 0;
419
+ var _a2, _b2, _c2;
420
+ const thoughtSignature = ((_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b2.thoughtSignature) != null ? String((_c2 = part.providerOptions.google) == null ? void 0 : _c2.thoughtSignature) : void 0;
418
421
  switch (part.type) {
419
422
  case "text": {
420
423
  return part.text.length === 0 ? void 0 : {
@@ -448,13 +451,17 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
448
451
  };
449
452
  }
450
453
  case "tool-call": {
454
+ const effectiveThoughtSignature = thoughtSignature != null ? thoughtSignature : isGemini3Model && !modelResponseHasSignedFunctionCall ? SKIP_THOUGHT_SIGNATURE_VALIDATOR : void 0;
455
+ if (thoughtSignature != null) {
456
+ modelResponseHasSignedFunctionCall = true;
457
+ }
451
458
  return {
452
459
  functionCall: {
453
460
  ...part.toolCallId != null ? { id: part.toolCallId } : {},
454
461
  name: part.toolName,
455
462
  args: part.input
456
463
  },
457
- thoughtSignature
464
+ thoughtSignature: effectiveThoughtSignature
458
465
  };
459
466
  }
460
467
  }
@@ -744,23 +751,39 @@ var VertexServiceTierMap = {
744
751
  priority: "SERVICE_TIER_PRIORITY"
745
752
  };
746
753
 
754
+ // src/google-model-capabilities.ts
755
+ var gemini1ModelPattern = /(^|\/)gemini-1(?:[.-]|$)/i;
756
+ var gemini2ModelPattern = /(^|\/)gemini-2(?:[.-]|$)/i;
757
+ var gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
758
+ var geminiModelPattern = /(^|\/)gemini-/i;
759
+ function isKnownPreGemini2Model(modelId) {
760
+ return gemini1ModelPattern.test(modelId) || /(^|\/)gemini-pro(?:-vision)?$/i.test(modelId) || /(^|\/)gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId);
761
+ }
762
+ function getGoogleModelCapabilities(modelId) {
763
+ const isGeminiModel = geminiModelPattern.test(modelId);
764
+ const isGemini2Model = gemini2ModelPattern.test(modelId);
765
+ const isKnownPreGemini2 = isKnownPreGemini2Model(modelId);
766
+ const isKnownOlderModel = isKnownPreGemini2 || isGemini2Model;
767
+ const usesGemini3Features = isGeminiModel && !isKnownOlderModel;
768
+ return {
769
+ supportsGemini2Tools: isGeminiModel && !isKnownPreGemini2 || modelId.toLowerCase().includes("nano-banana"),
770
+ supportsFileSearch: gemini25ModelPattern.test(modelId) || usesGemini3Features,
771
+ usesGemini3Features
772
+ };
773
+ }
774
+
747
775
  // src/google-prepare-tools.ts
748
776
  var import_provider3 = require("@ai-sdk/provider");
749
777
  function prepareTools({
750
778
  tools,
751
779
  toolChoice,
752
- modelId
780
+ modelId,
781
+ isVertexProvider = false
753
782
  }) {
754
- var _a;
783
+ var _a, _b;
755
784
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
756
785
  const toolWarnings = [];
757
- const isLatest = [
758
- "gemini-flash-latest",
759
- "gemini-flash-lite-latest",
760
- "gemini-pro-latest"
761
- ].some((id) => id === modelId);
762
- const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
763
- const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
786
+ const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
764
787
  if (tools == null) {
765
788
  return { tools: void 0, toolConfig: void 0, toolWarnings };
766
789
  }
@@ -768,7 +791,7 @@ function prepareTools({
768
791
  const hasProviderDefinedTools = tools.some(
769
792
  (tool) => tool.type === "provider-defined"
770
793
  );
771
- if (hasFunctionTools && hasProviderDefinedTools) {
794
+ if (hasFunctionTools && hasProviderDefinedTools && !usesGemini3Features) {
772
795
  const functionTools = tools.filter((tool) => tool.type === "function");
773
796
  toolWarnings.push({
774
797
  type: "unsupported-tool",
@@ -784,7 +807,7 @@ function prepareTools({
784
807
  providerDefinedTools.forEach((tool) => {
785
808
  switch (tool.id) {
786
809
  case "google.google_search":
787
- if (isGemini2orNewer) {
810
+ if (supportsGemini2Tools) {
788
811
  googleTools2.push({ googleSearch: { ...tool.args } });
789
812
  } else {
790
813
  toolWarnings.push({
@@ -795,7 +818,7 @@ function prepareTools({
795
818
  }
796
819
  break;
797
820
  case "google.enterprise_web_search":
798
- if (isGemini2orNewer) {
821
+ if (supportsGemini2Tools) {
799
822
  googleTools2.push({ enterpriseWebSearch: {} });
800
823
  } else {
801
824
  toolWarnings.push({
@@ -806,7 +829,7 @@ function prepareTools({
806
829
  }
807
830
  break;
808
831
  case "google.url_context":
809
- if (isGemini2orNewer) {
832
+ if (supportsGemini2Tools) {
810
833
  googleTools2.push({ urlContext: {} });
811
834
  } else {
812
835
  toolWarnings.push({
@@ -817,7 +840,7 @@ function prepareTools({
817
840
  }
818
841
  break;
819
842
  case "google.code_execution":
820
- if (isGemini2orNewer) {
843
+ if (supportsGemini2Tools) {
821
844
  googleTools2.push({ codeExecution: {} });
822
845
  } else {
823
846
  toolWarnings.push({
@@ -839,7 +862,7 @@ function prepareTools({
839
862
  }
840
863
  break;
841
864
  case "google.vertex_rag_store":
842
- if (isGemini2orNewer) {
865
+ if (supportsGemini2Tools) {
843
866
  googleTools2.push({
844
867
  retrieval: {
845
868
  vertex_rag_store: {
@@ -859,7 +882,7 @@ function prepareTools({
859
882
  }
860
883
  break;
861
884
  case "google.google_maps":
862
- if (isGemini2orNewer) {
885
+ if (supportsGemini2Tools) {
863
886
  googleTools2.push({ googleMaps: {} });
864
887
  } else {
865
888
  toolWarnings.push({
@@ -874,6 +897,47 @@ function prepareTools({
874
897
  break;
875
898
  }
876
899
  });
900
+ if (hasFunctionTools && usesGemini3Features && googleTools2.length > 0) {
901
+ const functionDeclarations2 = [];
902
+ for (const tool of tools) {
903
+ if (tool.type === "function") {
904
+ functionDeclarations2.push({
905
+ name: tool.name,
906
+ description: (_a = tool.description) != null ? _a : "",
907
+ parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
908
+ });
909
+ }
910
+ }
911
+ const combinedToolConfig = {
912
+ functionCallingConfig: { mode: "VALIDATED" },
913
+ ...!isVertexProvider && {
914
+ includeServerSideToolInvocations: true
915
+ }
916
+ };
917
+ if (toolChoice != null) {
918
+ switch (toolChoice.type) {
919
+ case "auto":
920
+ break;
921
+ case "none":
922
+ combinedToolConfig.functionCallingConfig = { mode: "NONE" };
923
+ break;
924
+ case "required":
925
+ combinedToolConfig.functionCallingConfig = { mode: "ANY" };
926
+ break;
927
+ case "tool":
928
+ combinedToolConfig.functionCallingConfig = {
929
+ mode: "ANY",
930
+ allowedFunctionNames: [toolChoice.toolName]
931
+ };
932
+ break;
933
+ }
934
+ }
935
+ return {
936
+ tools: [...googleTools2, { functionDeclarations: functionDeclarations2 }],
937
+ toolConfig: combinedToolConfig,
938
+ toolWarnings
939
+ };
940
+ }
877
941
  return {
878
942
  tools: googleTools2.length > 0 ? googleTools2 : void 0,
879
943
  toolConfig: void 0,
@@ -887,7 +951,7 @@ function prepareTools({
887
951
  case "function":
888
952
  functionDeclarations.push({
889
953
  name: tool.name,
890
- description: (_a = tool.description) != null ? _a : "",
954
+ description: (_b = tool.description) != null ? _b : "",
891
955
  parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
892
956
  });
893
957
  if (tool.strict === true) {
@@ -1065,10 +1129,14 @@ var GoogleGenerativeAILanguageModel = class {
1065
1129
  threshold: safetyThreshold
1066
1130
  })) : void 0;
1067
1131
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
1068
- const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
1132
+ const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
1069
1133
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
1070
1134
  prompt,
1071
- { isGemmaModel, supportsFunctionResponseParts }
1135
+ {
1136
+ isGemmaModel,
1137
+ isGemini3Model: usesGemini3Features,
1138
+ supportsFunctionResponseParts: usesGemini3Features
1139
+ }
1072
1140
  );
1073
1141
  const {
1074
1142
  tools: googleTools2,
@@ -1077,7 +1145,8 @@ var GoogleGenerativeAILanguageModel = class {
1077
1145
  } = prepareTools({
1078
1146
  tools,
1079
1147
  toolChoice,
1080
- modelId: this.modelId
1148
+ modelId: this.modelId,
1149
+ isVertexProvider
1081
1150
  });
1082
1151
  return {
1083
1152
  args: {