@ai-sdk/google 4.0.22 → 4.0.24
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 +12 -0
- package/dist/index.js +51 -37
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +50 -36
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +16 -6
- package/package.json +1 -1
- package/src/convert-to-google-messages.ts +16 -4
- package/src/google-language-model.ts +9 -9
- package/src/google-model-capabilities.ts +44 -0
- package/src/google-prepare-tools.ts +11 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.24
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c57a353: fix(google): omit unsupported function call IDs
|
|
8
|
+
|
|
9
|
+
## 4.0.23
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- f126649: feat(provider/google): default unknown Gemini model IDs to the newest supported capabilities
|
|
14
|
+
|
|
3
15
|
## 4.0.22
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "4.0.
|
|
10
|
+
var VERSION = true ? "4.0.24" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -461,7 +461,7 @@ function convertUrlToolResultPart(url) {
|
|
|
461
461
|
}
|
|
462
462
|
};
|
|
463
463
|
}
|
|
464
|
-
function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
464
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
|
|
465
465
|
const functionResponseParts = [];
|
|
466
466
|
const responseTextParts = [];
|
|
467
467
|
for (const contentPart of outputValue) {
|
|
@@ -500,7 +500,7 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
|
500
500
|
}
|
|
501
501
|
parts.push({
|
|
502
502
|
functionResponse: {
|
|
503
|
-
...toolCallId != null ? { id: toolCallId } : {},
|
|
503
|
+
...includeFunctionCallIds && toolCallId != null ? { id: toolCallId } : {},
|
|
504
504
|
name: toolName,
|
|
505
505
|
response: {
|
|
506
506
|
name: toolName,
|
|
@@ -510,13 +510,13 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
|
510
510
|
}
|
|
511
511
|
});
|
|
512
512
|
}
|
|
513
|
-
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
513
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
|
|
514
514
|
for (const contentPart of outputValue) {
|
|
515
515
|
switch (contentPart.type) {
|
|
516
516
|
case "text":
|
|
517
517
|
parts.push({
|
|
518
518
|
functionResponse: {
|
|
519
|
-
...toolCallId != null ? { id: toolCallId } : {},
|
|
519
|
+
...includeFunctionCallIds && toolCallId != null ? { id: toolCallId } : {},
|
|
520
520
|
name: toolName,
|
|
521
521
|
response: {
|
|
522
522
|
name: toolName,
|
|
@@ -551,16 +551,17 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
|
551
551
|
}
|
|
552
552
|
}
|
|
553
553
|
function convertToGoogleMessages(prompt, options) {
|
|
554
|
-
var _a, _b, _c, _d, _e;
|
|
554
|
+
var _a, _b, _c, _d, _e, _f;
|
|
555
555
|
const systemInstructionParts = [];
|
|
556
556
|
const contents = [];
|
|
557
557
|
let systemMessagesAllowed = true;
|
|
558
558
|
const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
|
|
559
|
-
const
|
|
559
|
+
const isGemini3Model = (_b = options == null ? void 0 : options.isGemini3Model) != null ? _b : false;
|
|
560
560
|
const onWarning = options == null ? void 0 : options.onWarning;
|
|
561
561
|
const providerOptionsNames = (_c = options == null ? void 0 : options.providerOptionsNames) != null ? _c : ["google"];
|
|
562
562
|
const isVertexLike = !providerOptionsNames.includes("google");
|
|
563
563
|
const supportsFunctionResponseParts = (_d = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _d : true;
|
|
564
|
+
const includeFunctionCallIds = (_e = options == null ? void 0 : options.includeFunctionCallIds) != null ? _e : true;
|
|
564
565
|
let sentinelInjected = false;
|
|
565
566
|
const missingSignatureToolNames = [];
|
|
566
567
|
const injectSkipSignature = (toolName) => {
|
|
@@ -758,7 +759,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
758
759
|
// model response legitimately have no signature.
|
|
759
760
|
!isServerToolCall && thoughtSignature == null && modelResponseHasSignedFunctionCall
|
|
760
761
|
);
|
|
761
|
-
const effectiveThoughtSignature = thoughtSignature != null ? thoughtSignature :
|
|
762
|
+
const effectiveThoughtSignature = thoughtSignature != null ? thoughtSignature : isGemini3Model && !shouldSkipMissingSignatureMitigation ? injectSkipSignature(part.toolName) : void 0;
|
|
762
763
|
if (!isServerToolCall && thoughtSignature != null) {
|
|
763
764
|
modelResponseHasSignedFunctionCall = true;
|
|
764
765
|
}
|
|
@@ -774,7 +775,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
774
775
|
}
|
|
775
776
|
return {
|
|
776
777
|
functionCall: {
|
|
777
|
-
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
778
|
+
...includeFunctionCallIds && part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
778
779
|
name: part.toolName,
|
|
779
780
|
args: part.input
|
|
780
781
|
},
|
|
@@ -835,24 +836,26 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
835
836
|
parts,
|
|
836
837
|
part.toolName,
|
|
837
838
|
output.value,
|
|
838
|
-
part.toolCallId
|
|
839
|
+
part.toolCallId,
|
|
840
|
+
includeFunctionCallIds
|
|
839
841
|
);
|
|
840
842
|
} else {
|
|
841
843
|
appendLegacyToolResultParts(
|
|
842
844
|
parts,
|
|
843
845
|
part.toolName,
|
|
844
846
|
output.value,
|
|
845
|
-
part.toolCallId
|
|
847
|
+
part.toolCallId,
|
|
848
|
+
includeFunctionCallIds
|
|
846
849
|
);
|
|
847
850
|
}
|
|
848
851
|
} else {
|
|
849
852
|
parts.push({
|
|
850
853
|
functionResponse: {
|
|
851
|
-
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
854
|
+
...includeFunctionCallIds && part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
852
855
|
name: part.toolName,
|
|
853
856
|
response: {
|
|
854
857
|
name: part.toolName,
|
|
855
|
-
content: output.type === "execution-denied" ? (
|
|
858
|
+
content: output.type === "execution-denied" ? (_f = output.reason) != null ? _f : "Tool call execution denied." : output.value
|
|
856
859
|
}
|
|
857
860
|
}
|
|
858
861
|
});
|
|
@@ -1079,6 +1082,27 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1079
1082
|
)
|
|
1080
1083
|
);
|
|
1081
1084
|
|
|
1085
|
+
// src/google-model-capabilities.ts
|
|
1086
|
+
var gemini1ModelPattern = /(^|\/)gemini-1(?:[.-]|$)/i;
|
|
1087
|
+
var gemini2ModelPattern = /(^|\/)gemini-2(?:[.-]|$)/i;
|
|
1088
|
+
var gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
1089
|
+
var geminiModelPattern = /(^|\/)gemini-/i;
|
|
1090
|
+
function isKnownPreGemini2Model(modelId) {
|
|
1091
|
+
return gemini1ModelPattern.test(modelId) || /(^|\/)gemini-pro(?:-vision)?$/i.test(modelId) || /(^|\/)gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId);
|
|
1092
|
+
}
|
|
1093
|
+
function getGoogleModelCapabilities(modelId) {
|
|
1094
|
+
const isGeminiModel2 = geminiModelPattern.test(modelId);
|
|
1095
|
+
const isGemini2Model = gemini2ModelPattern.test(modelId);
|
|
1096
|
+
const isKnownPreGemini2 = isKnownPreGemini2Model(modelId);
|
|
1097
|
+
const isKnownOlderModel = isKnownPreGemini2 || isGemini2Model;
|
|
1098
|
+
const usesGemini3Features = isGeminiModel2 && !isKnownOlderModel;
|
|
1099
|
+
return {
|
|
1100
|
+
supportsGemini2Tools: isGeminiModel2 && !isKnownPreGemini2 || modelId.toLowerCase().includes("nano-banana"),
|
|
1101
|
+
supportsFileSearch: gemini25ModelPattern.test(modelId) || usesGemini3Features,
|
|
1102
|
+
usesGemini3Features
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1082
1106
|
// src/google-prepare-tools.ts
|
|
1083
1107
|
import {
|
|
1084
1108
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
@@ -1092,20 +1116,13 @@ function prepareTools({
|
|
|
1092
1116
|
var _a, _b;
|
|
1093
1117
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
1094
1118
|
const toolWarnings = [];
|
|
1095
|
-
const
|
|
1096
|
-
"gemini-flash-latest",
|
|
1097
|
-
"gemini-flash-lite-latest",
|
|
1098
|
-
"gemini-pro-latest"
|
|
1099
|
-
].some((id) => id === modelId);
|
|
1100
|
-
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
1101
|
-
const isGemini3orNewer = modelId.includes("gemini-3");
|
|
1102
|
-
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
1119
|
+
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
1103
1120
|
if (tools == null) {
|
|
1104
1121
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
1105
1122
|
}
|
|
1106
1123
|
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
|
1107
1124
|
const hasProviderTools = tools.some((tool) => tool.type === "provider");
|
|
1108
|
-
if (hasFunctionTools && hasProviderTools && !
|
|
1125
|
+
if (hasFunctionTools && hasProviderTools && !usesGemini3Features) {
|
|
1109
1126
|
toolWarnings.push({
|
|
1110
1127
|
type: "unsupported",
|
|
1111
1128
|
feature: `combination of function and provider-defined tools`
|
|
@@ -1117,7 +1134,7 @@ function prepareTools({
|
|
|
1117
1134
|
ProviderTools.forEach((tool) => {
|
|
1118
1135
|
switch (tool.id) {
|
|
1119
1136
|
case "google.google_search":
|
|
1120
|
-
if (
|
|
1137
|
+
if (supportsGemini2Tools) {
|
|
1121
1138
|
googleTools2.push({ googleSearch: { ...tool.args } });
|
|
1122
1139
|
} else {
|
|
1123
1140
|
toolWarnings.push({
|
|
@@ -1128,7 +1145,7 @@ function prepareTools({
|
|
|
1128
1145
|
}
|
|
1129
1146
|
break;
|
|
1130
1147
|
case "google.enterprise_web_search":
|
|
1131
|
-
if (
|
|
1148
|
+
if (supportsGemini2Tools) {
|
|
1132
1149
|
googleTools2.push({ enterpriseWebSearch: {} });
|
|
1133
1150
|
} else {
|
|
1134
1151
|
toolWarnings.push({
|
|
@@ -1139,7 +1156,7 @@ function prepareTools({
|
|
|
1139
1156
|
}
|
|
1140
1157
|
break;
|
|
1141
1158
|
case "google.url_context":
|
|
1142
|
-
if (
|
|
1159
|
+
if (supportsGemini2Tools) {
|
|
1143
1160
|
googleTools2.push({ urlContext: {} });
|
|
1144
1161
|
} else {
|
|
1145
1162
|
toolWarnings.push({
|
|
@@ -1150,7 +1167,7 @@ function prepareTools({
|
|
|
1150
1167
|
}
|
|
1151
1168
|
break;
|
|
1152
1169
|
case "google.code_execution":
|
|
1153
|
-
if (
|
|
1170
|
+
if (supportsGemini2Tools) {
|
|
1154
1171
|
googleTools2.push({ codeExecution: {} });
|
|
1155
1172
|
} else {
|
|
1156
1173
|
toolWarnings.push({
|
|
@@ -1172,7 +1189,7 @@ function prepareTools({
|
|
|
1172
1189
|
}
|
|
1173
1190
|
break;
|
|
1174
1191
|
case "google.vertex_rag_store":
|
|
1175
|
-
if (
|
|
1192
|
+
if (supportsGemini2Tools) {
|
|
1176
1193
|
googleTools2.push({
|
|
1177
1194
|
retrieval: {
|
|
1178
1195
|
vertex_rag_store: {
|
|
@@ -1192,7 +1209,7 @@ function prepareTools({
|
|
|
1192
1209
|
}
|
|
1193
1210
|
break;
|
|
1194
1211
|
case "google.google_maps":
|
|
1195
|
-
if (
|
|
1212
|
+
if (supportsGemini2Tools) {
|
|
1196
1213
|
googleTools2.push({ googleMaps: {} });
|
|
1197
1214
|
} else {
|
|
1198
1215
|
toolWarnings.push({
|
|
@@ -1210,7 +1227,7 @@ function prepareTools({
|
|
|
1210
1227
|
break;
|
|
1211
1228
|
}
|
|
1212
1229
|
});
|
|
1213
|
-
if (hasFunctionTools &&
|
|
1230
|
+
if (hasFunctionTools && usesGemini3Features && googleTools2.length > 0) {
|
|
1214
1231
|
const functionDeclarations2 = [];
|
|
1215
1232
|
for (const tool of tools) {
|
|
1216
1233
|
if (tool.type === "function") {
|
|
@@ -1725,14 +1742,14 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1725
1742
|
}
|
|
1726
1743
|
}
|
|
1727
1744
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1728
|
-
const
|
|
1729
|
-
const supportsFunctionResponseParts = isGemini3Model2;
|
|
1745
|
+
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1730
1746
|
const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
|
|
1731
1747
|
isGemmaModel,
|
|
1732
|
-
isGemini3Model:
|
|
1748
|
+
isGemini3Model: usesGemini3Features,
|
|
1733
1749
|
onWarning: (warning) => warnings.push(warning),
|
|
1734
1750
|
providerOptionsNames,
|
|
1735
|
-
supportsFunctionResponseParts
|
|
1751
|
+
supportsFunctionResponseParts: usesGemini3Features,
|
|
1752
|
+
includeFunctionCallIds: !isVertexProvider
|
|
1736
1753
|
});
|
|
1737
1754
|
const {
|
|
1738
1755
|
tools: googleTools2,
|
|
@@ -2398,9 +2415,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2398
2415
|
};
|
|
2399
2416
|
}
|
|
2400
2417
|
};
|
|
2401
|
-
function isGemini3Model(modelId) {
|
|
2402
|
-
return /gemini-3[\.\-]/i.test(modelId) || /gemini-3$/i.test(modelId);
|
|
2403
|
-
}
|
|
2404
2418
|
function getMaxOutputTokensForGemini25Model() {
|
|
2405
2419
|
return 65536;
|
|
2406
2420
|
}
|
|
@@ -2419,7 +2433,7 @@ function resolveThinkingConfig({
|
|
|
2419
2433
|
if (!isCustomReasoning(reasoning)) {
|
|
2420
2434
|
return void 0;
|
|
2421
2435
|
}
|
|
2422
|
-
if (
|
|
2436
|
+
if (getGoogleModelCapabilities(modelId).usesGemini3Features && !modelId.includes("gemini-3-pro-image")) {
|
|
2423
2437
|
return resolveGemini3ThinkingConfig({ reasoning, warnings });
|
|
2424
2438
|
}
|
|
2425
2439
|
return resolveGemini25ThinkingConfig({ reasoning, modelId, warnings });
|