@ai-sdk/google 4.0.22 → 4.0.23
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 +6 -0
- package/dist/index.js +37 -27
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +36 -26
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +16 -6
- package/package.json +1 -1
- package/src/google-language-model.ts +8 -9
- package/src/google-model-capabilities.ts +44 -0
- package/src/google-prepare-tools.ts +11 -23
package/dist/internal/index.js
CHANGED
|
@@ -304,7 +304,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
304
304
|
const contents = [];
|
|
305
305
|
let systemMessagesAllowed = true;
|
|
306
306
|
const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
|
|
307
|
-
const
|
|
307
|
+
const isGemini3Model = (_b = options == null ? void 0 : options.isGemini3Model) != null ? _b : false;
|
|
308
308
|
const onWarning = options == null ? void 0 : options.onWarning;
|
|
309
309
|
const providerOptionsNames = (_c = options == null ? void 0 : options.providerOptionsNames) != null ? _c : ["google"];
|
|
310
310
|
const isVertexLike = !providerOptionsNames.includes("google");
|
|
@@ -506,7 +506,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
506
506
|
// model response legitimately have no signature.
|
|
507
507
|
!isServerToolCall && thoughtSignature == null && modelResponseHasSignedFunctionCall
|
|
508
508
|
);
|
|
509
|
-
const effectiveThoughtSignature = thoughtSignature != null ? thoughtSignature :
|
|
509
|
+
const effectiveThoughtSignature = thoughtSignature != null ? thoughtSignature : isGemini3Model && !shouldSkipMissingSignatureMitigation ? injectSkipSignature(part.toolName) : void 0;
|
|
510
510
|
if (!isServerToolCall && thoughtSignature != null) {
|
|
511
511
|
modelResponseHasSignedFunctionCall = true;
|
|
512
512
|
}
|
|
@@ -850,6 +850,27 @@ var googleLanguageModelOptions = lazySchema2(
|
|
|
850
850
|
)
|
|
851
851
|
);
|
|
852
852
|
|
|
853
|
+
// src/google-model-capabilities.ts
|
|
854
|
+
var gemini1ModelPattern = /(^|\/)gemini-1(?:[.-]|$)/i;
|
|
855
|
+
var gemini2ModelPattern = /(^|\/)gemini-2(?:[.-]|$)/i;
|
|
856
|
+
var gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
857
|
+
var geminiModelPattern = /(^|\/)gemini-/i;
|
|
858
|
+
function isKnownPreGemini2Model(modelId) {
|
|
859
|
+
return gemini1ModelPattern.test(modelId) || /(^|\/)gemini-pro(?:-vision)?$/i.test(modelId) || /(^|\/)gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId);
|
|
860
|
+
}
|
|
861
|
+
function getGoogleModelCapabilities(modelId) {
|
|
862
|
+
const isGeminiModel = geminiModelPattern.test(modelId);
|
|
863
|
+
const isGemini2Model = gemini2ModelPattern.test(modelId);
|
|
864
|
+
const isKnownPreGemini2 = isKnownPreGemini2Model(modelId);
|
|
865
|
+
const isKnownOlderModel = isKnownPreGemini2 || isGemini2Model;
|
|
866
|
+
const usesGemini3Features = isGeminiModel && !isKnownOlderModel;
|
|
867
|
+
return {
|
|
868
|
+
supportsGemini2Tools: isGeminiModel && !isKnownPreGemini2 || modelId.toLowerCase().includes("nano-banana"),
|
|
869
|
+
supportsFileSearch: gemini25ModelPattern.test(modelId) || usesGemini3Features,
|
|
870
|
+
usesGemini3Features
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
|
|
853
874
|
// src/google-prepare-tools.ts
|
|
854
875
|
import {
|
|
855
876
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
@@ -863,20 +884,13 @@ function prepareTools({
|
|
|
863
884
|
var _a, _b;
|
|
864
885
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
865
886
|
const toolWarnings = [];
|
|
866
|
-
const
|
|
867
|
-
"gemini-flash-latest",
|
|
868
|
-
"gemini-flash-lite-latest",
|
|
869
|
-
"gemini-pro-latest"
|
|
870
|
-
].some((id) => id === modelId);
|
|
871
|
-
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
872
|
-
const isGemini3orNewer = modelId.includes("gemini-3");
|
|
873
|
-
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
887
|
+
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
874
888
|
if (tools == null) {
|
|
875
889
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
876
890
|
}
|
|
877
891
|
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
|
878
892
|
const hasProviderTools = tools.some((tool) => tool.type === "provider");
|
|
879
|
-
if (hasFunctionTools && hasProviderTools && !
|
|
893
|
+
if (hasFunctionTools && hasProviderTools && !usesGemini3Features) {
|
|
880
894
|
toolWarnings.push({
|
|
881
895
|
type: "unsupported",
|
|
882
896
|
feature: `combination of function and provider-defined tools`
|
|
@@ -888,7 +902,7 @@ function prepareTools({
|
|
|
888
902
|
ProviderTools.forEach((tool) => {
|
|
889
903
|
switch (tool.id) {
|
|
890
904
|
case "google.google_search":
|
|
891
|
-
if (
|
|
905
|
+
if (supportsGemini2Tools) {
|
|
892
906
|
googleTools2.push({ googleSearch: { ...tool.args } });
|
|
893
907
|
} else {
|
|
894
908
|
toolWarnings.push({
|
|
@@ -899,7 +913,7 @@ function prepareTools({
|
|
|
899
913
|
}
|
|
900
914
|
break;
|
|
901
915
|
case "google.enterprise_web_search":
|
|
902
|
-
if (
|
|
916
|
+
if (supportsGemini2Tools) {
|
|
903
917
|
googleTools2.push({ enterpriseWebSearch: {} });
|
|
904
918
|
} else {
|
|
905
919
|
toolWarnings.push({
|
|
@@ -910,7 +924,7 @@ function prepareTools({
|
|
|
910
924
|
}
|
|
911
925
|
break;
|
|
912
926
|
case "google.url_context":
|
|
913
|
-
if (
|
|
927
|
+
if (supportsGemini2Tools) {
|
|
914
928
|
googleTools2.push({ urlContext: {} });
|
|
915
929
|
} else {
|
|
916
930
|
toolWarnings.push({
|
|
@@ -921,7 +935,7 @@ function prepareTools({
|
|
|
921
935
|
}
|
|
922
936
|
break;
|
|
923
937
|
case "google.code_execution":
|
|
924
|
-
if (
|
|
938
|
+
if (supportsGemini2Tools) {
|
|
925
939
|
googleTools2.push({ codeExecution: {} });
|
|
926
940
|
} else {
|
|
927
941
|
toolWarnings.push({
|
|
@@ -943,7 +957,7 @@ function prepareTools({
|
|
|
943
957
|
}
|
|
944
958
|
break;
|
|
945
959
|
case "google.vertex_rag_store":
|
|
946
|
-
if (
|
|
960
|
+
if (supportsGemini2Tools) {
|
|
947
961
|
googleTools2.push({
|
|
948
962
|
retrieval: {
|
|
949
963
|
vertex_rag_store: {
|
|
@@ -963,7 +977,7 @@ function prepareTools({
|
|
|
963
977
|
}
|
|
964
978
|
break;
|
|
965
979
|
case "google.google_maps":
|
|
966
|
-
if (
|
|
980
|
+
if (supportsGemini2Tools) {
|
|
967
981
|
googleTools2.push({ googleMaps: {} });
|
|
968
982
|
} else {
|
|
969
983
|
toolWarnings.push({
|
|
@@ -981,7 +995,7 @@ function prepareTools({
|
|
|
981
995
|
break;
|
|
982
996
|
}
|
|
983
997
|
});
|
|
984
|
-
if (hasFunctionTools &&
|
|
998
|
+
if (hasFunctionTools && usesGemini3Features && googleTools2.length > 0) {
|
|
985
999
|
const functionDeclarations2 = [];
|
|
986
1000
|
for (const tool of tools) {
|
|
987
1001
|
if (tool.type === "function") {
|
|
@@ -1496,14 +1510,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1496
1510
|
}
|
|
1497
1511
|
}
|
|
1498
1512
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1499
|
-
const
|
|
1500
|
-
const supportsFunctionResponseParts = isGemini3Model2;
|
|
1513
|
+
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1501
1514
|
const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
|
|
1502
1515
|
isGemmaModel,
|
|
1503
|
-
isGemini3Model:
|
|
1516
|
+
isGemini3Model: usesGemini3Features,
|
|
1504
1517
|
onWarning: (warning) => warnings.push(warning),
|
|
1505
1518
|
providerOptionsNames,
|
|
1506
|
-
supportsFunctionResponseParts
|
|
1519
|
+
supportsFunctionResponseParts: usesGemini3Features
|
|
1507
1520
|
});
|
|
1508
1521
|
const {
|
|
1509
1522
|
tools: googleTools2,
|
|
@@ -2169,9 +2182,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2169
2182
|
};
|
|
2170
2183
|
}
|
|
2171
2184
|
};
|
|
2172
|
-
function isGemini3Model(modelId) {
|
|
2173
|
-
return /gemini-3[\.\-]/i.test(modelId) || /gemini-3$/i.test(modelId);
|
|
2174
|
-
}
|
|
2175
2185
|
function getMaxOutputTokensForGemini25Model() {
|
|
2176
2186
|
return 65536;
|
|
2177
2187
|
}
|
|
@@ -2190,7 +2200,7 @@ function resolveThinkingConfig({
|
|
|
2190
2200
|
if (!isCustomReasoning(reasoning)) {
|
|
2191
2201
|
return void 0;
|
|
2192
2202
|
}
|
|
2193
|
-
if (
|
|
2203
|
+
if (getGoogleModelCapabilities(modelId).usesGemini3Features && !modelId.includes("gemini-3-pro-image")) {
|
|
2194
2204
|
return resolveGemini3ThinkingConfig({ reasoning, warnings });
|
|
2195
2205
|
}
|
|
2196
2206
|
return resolveGemini25ThinkingConfig({ reasoning, modelId, warnings });
|