@ai-sdk/google 4.0.21 → 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 +13 -0
- package/dist/index.js +71 -28
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +49 -27
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +21 -6
- package/package.json +1 -1
- package/src/convert-to-google-messages.ts +18 -2
- 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/src/realtime/google-realtime-event-mapper.ts +34 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.23
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f126649: feat(provider/google): default unknown Gemini model IDs to the newest supported capabilities
|
|
8
|
+
|
|
9
|
+
## 4.0.22
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 66b7151: fix(provider/google): preserve Gemini Live lifecycle events
|
|
14
|
+
- 5e5453c: Avoid missing thought-signature warnings and skip-validator injection for valid unsigned Gemini 3 parallel function calls in the same model response.
|
|
15
|
+
|
|
3
16
|
## 4.0.21
|
|
4
17
|
|
|
5
18
|
### 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.23" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -556,7 +556,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
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");
|
|
@@ -657,6 +657,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
657
657
|
}
|
|
658
658
|
case "assistant": {
|
|
659
659
|
systemMessagesAllowed = false;
|
|
660
|
+
let modelResponseHasSignedFunctionCall = false;
|
|
660
661
|
contents.push({
|
|
661
662
|
role: "model",
|
|
662
663
|
parts: content.map((part) => {
|
|
@@ -749,8 +750,19 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
749
750
|
case "tool-call": {
|
|
750
751
|
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
751
752
|
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
752
|
-
const
|
|
753
|
-
|
|
753
|
+
const isServerToolCall = serverToolCallId != null && serverToolType != null;
|
|
754
|
+
const shouldSkipMissingSignatureMitigation = (
|
|
755
|
+
// Gemini 3 returns a single signature for a parallel
|
|
756
|
+
// function-call response on the first standard function
|
|
757
|
+
// call. Subsequent standard function calls in the same
|
|
758
|
+
// model response legitimately have no signature.
|
|
759
|
+
!isServerToolCall && thoughtSignature == null && modelResponseHasSignedFunctionCall
|
|
760
|
+
);
|
|
761
|
+
const effectiveThoughtSignature = thoughtSignature != null ? thoughtSignature : isGemini3Model && !shouldSkipMissingSignatureMitigation ? injectSkipSignature(part.toolName) : void 0;
|
|
762
|
+
if (!isServerToolCall && thoughtSignature != null) {
|
|
763
|
+
modelResponseHasSignedFunctionCall = true;
|
|
764
|
+
}
|
|
765
|
+
if (isServerToolCall) {
|
|
754
766
|
return {
|
|
755
767
|
toolCall: {
|
|
756
768
|
toolType: serverToolType,
|
|
@@ -1067,6 +1079,27 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
1067
1079
|
)
|
|
1068
1080
|
);
|
|
1069
1081
|
|
|
1082
|
+
// src/google-model-capabilities.ts
|
|
1083
|
+
var gemini1ModelPattern = /(^|\/)gemini-1(?:[.-]|$)/i;
|
|
1084
|
+
var gemini2ModelPattern = /(^|\/)gemini-2(?:[.-]|$)/i;
|
|
1085
|
+
var gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
1086
|
+
var geminiModelPattern = /(^|\/)gemini-/i;
|
|
1087
|
+
function isKnownPreGemini2Model(modelId) {
|
|
1088
|
+
return gemini1ModelPattern.test(modelId) || /(^|\/)gemini-pro(?:-vision)?$/i.test(modelId) || /(^|\/)gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId);
|
|
1089
|
+
}
|
|
1090
|
+
function getGoogleModelCapabilities(modelId) {
|
|
1091
|
+
const isGeminiModel2 = geminiModelPattern.test(modelId);
|
|
1092
|
+
const isGemini2Model = gemini2ModelPattern.test(modelId);
|
|
1093
|
+
const isKnownPreGemini2 = isKnownPreGemini2Model(modelId);
|
|
1094
|
+
const isKnownOlderModel = isKnownPreGemini2 || isGemini2Model;
|
|
1095
|
+
const usesGemini3Features = isGeminiModel2 && !isKnownOlderModel;
|
|
1096
|
+
return {
|
|
1097
|
+
supportsGemini2Tools: isGeminiModel2 && !isKnownPreGemini2 || modelId.toLowerCase().includes("nano-banana"),
|
|
1098
|
+
supportsFileSearch: gemini25ModelPattern.test(modelId) || usesGemini3Features,
|
|
1099
|
+
usesGemini3Features
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1070
1103
|
// src/google-prepare-tools.ts
|
|
1071
1104
|
import {
|
|
1072
1105
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
@@ -1080,20 +1113,13 @@ function prepareTools({
|
|
|
1080
1113
|
var _a, _b;
|
|
1081
1114
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
1082
1115
|
const toolWarnings = [];
|
|
1083
|
-
const
|
|
1084
|
-
"gemini-flash-latest",
|
|
1085
|
-
"gemini-flash-lite-latest",
|
|
1086
|
-
"gemini-pro-latest"
|
|
1087
|
-
].some((id) => id === modelId);
|
|
1088
|
-
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
1089
|
-
const isGemini3orNewer = modelId.includes("gemini-3");
|
|
1090
|
-
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
1116
|
+
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
1091
1117
|
if (tools == null) {
|
|
1092
1118
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
1093
1119
|
}
|
|
1094
1120
|
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
|
1095
1121
|
const hasProviderTools = tools.some((tool) => tool.type === "provider");
|
|
1096
|
-
if (hasFunctionTools && hasProviderTools && !
|
|
1122
|
+
if (hasFunctionTools && hasProviderTools && !usesGemini3Features) {
|
|
1097
1123
|
toolWarnings.push({
|
|
1098
1124
|
type: "unsupported",
|
|
1099
1125
|
feature: `combination of function and provider-defined tools`
|
|
@@ -1105,7 +1131,7 @@ function prepareTools({
|
|
|
1105
1131
|
ProviderTools.forEach((tool) => {
|
|
1106
1132
|
switch (tool.id) {
|
|
1107
1133
|
case "google.google_search":
|
|
1108
|
-
if (
|
|
1134
|
+
if (supportsGemini2Tools) {
|
|
1109
1135
|
googleTools2.push({ googleSearch: { ...tool.args } });
|
|
1110
1136
|
} else {
|
|
1111
1137
|
toolWarnings.push({
|
|
@@ -1116,7 +1142,7 @@ function prepareTools({
|
|
|
1116
1142
|
}
|
|
1117
1143
|
break;
|
|
1118
1144
|
case "google.enterprise_web_search":
|
|
1119
|
-
if (
|
|
1145
|
+
if (supportsGemini2Tools) {
|
|
1120
1146
|
googleTools2.push({ enterpriseWebSearch: {} });
|
|
1121
1147
|
} else {
|
|
1122
1148
|
toolWarnings.push({
|
|
@@ -1127,7 +1153,7 @@ function prepareTools({
|
|
|
1127
1153
|
}
|
|
1128
1154
|
break;
|
|
1129
1155
|
case "google.url_context":
|
|
1130
|
-
if (
|
|
1156
|
+
if (supportsGemini2Tools) {
|
|
1131
1157
|
googleTools2.push({ urlContext: {} });
|
|
1132
1158
|
} else {
|
|
1133
1159
|
toolWarnings.push({
|
|
@@ -1138,7 +1164,7 @@ function prepareTools({
|
|
|
1138
1164
|
}
|
|
1139
1165
|
break;
|
|
1140
1166
|
case "google.code_execution":
|
|
1141
|
-
if (
|
|
1167
|
+
if (supportsGemini2Tools) {
|
|
1142
1168
|
googleTools2.push({ codeExecution: {} });
|
|
1143
1169
|
} else {
|
|
1144
1170
|
toolWarnings.push({
|
|
@@ -1160,7 +1186,7 @@ function prepareTools({
|
|
|
1160
1186
|
}
|
|
1161
1187
|
break;
|
|
1162
1188
|
case "google.vertex_rag_store":
|
|
1163
|
-
if (
|
|
1189
|
+
if (supportsGemini2Tools) {
|
|
1164
1190
|
googleTools2.push({
|
|
1165
1191
|
retrieval: {
|
|
1166
1192
|
vertex_rag_store: {
|
|
@@ -1180,7 +1206,7 @@ function prepareTools({
|
|
|
1180
1206
|
}
|
|
1181
1207
|
break;
|
|
1182
1208
|
case "google.google_maps":
|
|
1183
|
-
if (
|
|
1209
|
+
if (supportsGemini2Tools) {
|
|
1184
1210
|
googleTools2.push({ googleMaps: {} });
|
|
1185
1211
|
} else {
|
|
1186
1212
|
toolWarnings.push({
|
|
@@ -1198,7 +1224,7 @@ function prepareTools({
|
|
|
1198
1224
|
break;
|
|
1199
1225
|
}
|
|
1200
1226
|
});
|
|
1201
|
-
if (hasFunctionTools &&
|
|
1227
|
+
if (hasFunctionTools && usesGemini3Features && googleTools2.length > 0) {
|
|
1202
1228
|
const functionDeclarations2 = [];
|
|
1203
1229
|
for (const tool of tools) {
|
|
1204
1230
|
if (tool.type === "function") {
|
|
@@ -1713,14 +1739,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1713
1739
|
}
|
|
1714
1740
|
}
|
|
1715
1741
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1716
|
-
const
|
|
1717
|
-
const supportsFunctionResponseParts = isGemini3Model2;
|
|
1742
|
+
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1718
1743
|
const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
|
|
1719
1744
|
isGemmaModel,
|
|
1720
|
-
isGemini3Model:
|
|
1745
|
+
isGemini3Model: usesGemini3Features,
|
|
1721
1746
|
onWarning: (warning) => warnings.push(warning),
|
|
1722
1747
|
providerOptionsNames,
|
|
1723
|
-
supportsFunctionResponseParts
|
|
1748
|
+
supportsFunctionResponseParts: usesGemini3Features
|
|
1724
1749
|
});
|
|
1725
1750
|
const {
|
|
1726
1751
|
tools: googleTools2,
|
|
@@ -2386,9 +2411,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2386
2411
|
};
|
|
2387
2412
|
}
|
|
2388
2413
|
};
|
|
2389
|
-
function isGemini3Model(modelId) {
|
|
2390
|
-
return /gemini-3[\.\-]/i.test(modelId) || /gemini-3$/i.test(modelId);
|
|
2391
|
-
}
|
|
2392
2414
|
function getMaxOutputTokensForGemini25Model() {
|
|
2393
2415
|
return 65536;
|
|
2394
2416
|
}
|
|
@@ -2407,7 +2429,7 @@ function resolveThinkingConfig({
|
|
|
2407
2429
|
if (!isCustomReasoning(reasoning)) {
|
|
2408
2430
|
return void 0;
|
|
2409
2431
|
}
|
|
2410
|
-
if (
|
|
2432
|
+
if (getGoogleModelCapabilities(modelId).usesGemini3Features && !modelId.includes("gemini-3-pro-image")) {
|
|
2411
2433
|
return resolveGemini3ThinkingConfig({ reasoning, warnings });
|
|
2412
2434
|
}
|
|
2413
2435
|
return resolveGemini25ThinkingConfig({ reasoning, modelId, warnings });
|
|
@@ -6980,6 +7002,20 @@ var GoogleRealtimeEventMapper = class {
|
|
|
6980
7002
|
raw
|
|
6981
7003
|
};
|
|
6982
7004
|
}
|
|
7005
|
+
if (data.goAway != null) {
|
|
7006
|
+
return {
|
|
7007
|
+
type: "custom",
|
|
7008
|
+
rawType: "goAway",
|
|
7009
|
+
raw
|
|
7010
|
+
};
|
|
7011
|
+
}
|
|
7012
|
+
if (data.sessionResumptionUpdate != null) {
|
|
7013
|
+
return {
|
|
7014
|
+
type: "custom",
|
|
7015
|
+
rawType: "sessionResumptionUpdate",
|
|
7016
|
+
raw
|
|
7017
|
+
};
|
|
7018
|
+
}
|
|
6983
7019
|
if (data.serverContent != null) {
|
|
6984
7020
|
return this.parseServerContent(data.serverContent, raw);
|
|
6985
7021
|
}
|
|
@@ -7045,6 +7081,13 @@ var GoogleRealtimeEventMapper = class {
|
|
|
7045
7081
|
raw
|
|
7046
7082
|
});
|
|
7047
7083
|
}
|
|
7084
|
+
if (serverContent.generationComplete) {
|
|
7085
|
+
events.push({
|
|
7086
|
+
type: "custom",
|
|
7087
|
+
rawType: "generationComplete",
|
|
7088
|
+
raw
|
|
7089
|
+
});
|
|
7090
|
+
}
|
|
7048
7091
|
if (serverContent.turnComplete) {
|
|
7049
7092
|
if (this.hasAudio) {
|
|
7050
7093
|
events.push({
|