@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/dist/internal/index.js
CHANGED
|
@@ -209,7 +209,7 @@ function convertUrlToolResultPart(url) {
|
|
|
209
209
|
}
|
|
210
210
|
};
|
|
211
211
|
}
|
|
212
|
-
function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
212
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
|
|
213
213
|
const functionResponseParts = [];
|
|
214
214
|
const responseTextParts = [];
|
|
215
215
|
for (const contentPart of outputValue) {
|
|
@@ -248,7 +248,7 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
|
248
248
|
}
|
|
249
249
|
parts.push({
|
|
250
250
|
functionResponse: {
|
|
251
|
-
...toolCallId != null ? { id: toolCallId } : {},
|
|
251
|
+
...includeFunctionCallIds && toolCallId != null ? { id: toolCallId } : {},
|
|
252
252
|
name: toolName,
|
|
253
253
|
response: {
|
|
254
254
|
name: toolName,
|
|
@@ -258,13 +258,13 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
|
258
258
|
}
|
|
259
259
|
});
|
|
260
260
|
}
|
|
261
|
-
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
261
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
|
|
262
262
|
for (const contentPart of outputValue) {
|
|
263
263
|
switch (contentPart.type) {
|
|
264
264
|
case "text":
|
|
265
265
|
parts.push({
|
|
266
266
|
functionResponse: {
|
|
267
|
-
...toolCallId != null ? { id: toolCallId } : {},
|
|
267
|
+
...includeFunctionCallIds && toolCallId != null ? { id: toolCallId } : {},
|
|
268
268
|
name: toolName,
|
|
269
269
|
response: {
|
|
270
270
|
name: toolName,
|
|
@@ -299,16 +299,17 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
function convertToGoogleMessages(prompt, options) {
|
|
302
|
-
var _a, _b, _c, _d, _e;
|
|
302
|
+
var _a, _b, _c, _d, _e, _f;
|
|
303
303
|
const systemInstructionParts = [];
|
|
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");
|
|
311
311
|
const supportsFunctionResponseParts = (_d = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _d : true;
|
|
312
|
+
const includeFunctionCallIds = (_e = options == null ? void 0 : options.includeFunctionCallIds) != null ? _e : true;
|
|
312
313
|
let sentinelInjected = false;
|
|
313
314
|
const missingSignatureToolNames = [];
|
|
314
315
|
const injectSkipSignature = (toolName) => {
|
|
@@ -506,7 +507,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
506
507
|
// model response legitimately have no signature.
|
|
507
508
|
!isServerToolCall && thoughtSignature == null && modelResponseHasSignedFunctionCall
|
|
508
509
|
);
|
|
509
|
-
const effectiveThoughtSignature = thoughtSignature != null ? thoughtSignature :
|
|
510
|
+
const effectiveThoughtSignature = thoughtSignature != null ? thoughtSignature : isGemini3Model && !shouldSkipMissingSignatureMitigation ? injectSkipSignature(part.toolName) : void 0;
|
|
510
511
|
if (!isServerToolCall && thoughtSignature != null) {
|
|
511
512
|
modelResponseHasSignedFunctionCall = true;
|
|
512
513
|
}
|
|
@@ -522,7 +523,7 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
522
523
|
}
|
|
523
524
|
return {
|
|
524
525
|
functionCall: {
|
|
525
|
-
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
526
|
+
...includeFunctionCallIds && part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
526
527
|
name: part.toolName,
|
|
527
528
|
args: part.input
|
|
528
529
|
},
|
|
@@ -583,24 +584,26 @@ function convertToGoogleMessages(prompt, options) {
|
|
|
583
584
|
parts,
|
|
584
585
|
part.toolName,
|
|
585
586
|
output.value,
|
|
586
|
-
part.toolCallId
|
|
587
|
+
part.toolCallId,
|
|
588
|
+
includeFunctionCallIds
|
|
587
589
|
);
|
|
588
590
|
} else {
|
|
589
591
|
appendLegacyToolResultParts(
|
|
590
592
|
parts,
|
|
591
593
|
part.toolName,
|
|
592
594
|
output.value,
|
|
593
|
-
part.toolCallId
|
|
595
|
+
part.toolCallId,
|
|
596
|
+
includeFunctionCallIds
|
|
594
597
|
);
|
|
595
598
|
}
|
|
596
599
|
} else {
|
|
597
600
|
parts.push({
|
|
598
601
|
functionResponse: {
|
|
599
|
-
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
602
|
+
...includeFunctionCallIds && part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
600
603
|
name: part.toolName,
|
|
601
604
|
response: {
|
|
602
605
|
name: part.toolName,
|
|
603
|
-
content: output.type === "execution-denied" ? (
|
|
606
|
+
content: output.type === "execution-denied" ? (_f = output.reason) != null ? _f : "Tool call execution denied." : output.value
|
|
604
607
|
}
|
|
605
608
|
}
|
|
606
609
|
});
|
|
@@ -850,6 +853,27 @@ var googleLanguageModelOptions = lazySchema2(
|
|
|
850
853
|
)
|
|
851
854
|
);
|
|
852
855
|
|
|
856
|
+
// src/google-model-capabilities.ts
|
|
857
|
+
var gemini1ModelPattern = /(^|\/)gemini-1(?:[.-]|$)/i;
|
|
858
|
+
var gemini2ModelPattern = /(^|\/)gemini-2(?:[.-]|$)/i;
|
|
859
|
+
var gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
860
|
+
var geminiModelPattern = /(^|\/)gemini-/i;
|
|
861
|
+
function isKnownPreGemini2Model(modelId) {
|
|
862
|
+
return gemini1ModelPattern.test(modelId) || /(^|\/)gemini-pro(?:-vision)?$/i.test(modelId) || /(^|\/)gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId);
|
|
863
|
+
}
|
|
864
|
+
function getGoogleModelCapabilities(modelId) {
|
|
865
|
+
const isGeminiModel = geminiModelPattern.test(modelId);
|
|
866
|
+
const isGemini2Model = gemini2ModelPattern.test(modelId);
|
|
867
|
+
const isKnownPreGemini2 = isKnownPreGemini2Model(modelId);
|
|
868
|
+
const isKnownOlderModel = isKnownPreGemini2 || isGemini2Model;
|
|
869
|
+
const usesGemini3Features = isGeminiModel && !isKnownOlderModel;
|
|
870
|
+
return {
|
|
871
|
+
supportsGemini2Tools: isGeminiModel && !isKnownPreGemini2 || modelId.toLowerCase().includes("nano-banana"),
|
|
872
|
+
supportsFileSearch: gemini25ModelPattern.test(modelId) || usesGemini3Features,
|
|
873
|
+
usesGemini3Features
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
|
|
853
877
|
// src/google-prepare-tools.ts
|
|
854
878
|
import {
|
|
855
879
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
@@ -863,20 +887,13 @@ function prepareTools({
|
|
|
863
887
|
var _a, _b;
|
|
864
888
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
865
889
|
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");
|
|
890
|
+
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
874
891
|
if (tools == null) {
|
|
875
892
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
876
893
|
}
|
|
877
894
|
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
|
878
895
|
const hasProviderTools = tools.some((tool) => tool.type === "provider");
|
|
879
|
-
if (hasFunctionTools && hasProviderTools && !
|
|
896
|
+
if (hasFunctionTools && hasProviderTools && !usesGemini3Features) {
|
|
880
897
|
toolWarnings.push({
|
|
881
898
|
type: "unsupported",
|
|
882
899
|
feature: `combination of function and provider-defined tools`
|
|
@@ -888,7 +905,7 @@ function prepareTools({
|
|
|
888
905
|
ProviderTools.forEach((tool) => {
|
|
889
906
|
switch (tool.id) {
|
|
890
907
|
case "google.google_search":
|
|
891
|
-
if (
|
|
908
|
+
if (supportsGemini2Tools) {
|
|
892
909
|
googleTools2.push({ googleSearch: { ...tool.args } });
|
|
893
910
|
} else {
|
|
894
911
|
toolWarnings.push({
|
|
@@ -899,7 +916,7 @@ function prepareTools({
|
|
|
899
916
|
}
|
|
900
917
|
break;
|
|
901
918
|
case "google.enterprise_web_search":
|
|
902
|
-
if (
|
|
919
|
+
if (supportsGemini2Tools) {
|
|
903
920
|
googleTools2.push({ enterpriseWebSearch: {} });
|
|
904
921
|
} else {
|
|
905
922
|
toolWarnings.push({
|
|
@@ -910,7 +927,7 @@ function prepareTools({
|
|
|
910
927
|
}
|
|
911
928
|
break;
|
|
912
929
|
case "google.url_context":
|
|
913
|
-
if (
|
|
930
|
+
if (supportsGemini2Tools) {
|
|
914
931
|
googleTools2.push({ urlContext: {} });
|
|
915
932
|
} else {
|
|
916
933
|
toolWarnings.push({
|
|
@@ -921,7 +938,7 @@ function prepareTools({
|
|
|
921
938
|
}
|
|
922
939
|
break;
|
|
923
940
|
case "google.code_execution":
|
|
924
|
-
if (
|
|
941
|
+
if (supportsGemini2Tools) {
|
|
925
942
|
googleTools2.push({ codeExecution: {} });
|
|
926
943
|
} else {
|
|
927
944
|
toolWarnings.push({
|
|
@@ -943,7 +960,7 @@ function prepareTools({
|
|
|
943
960
|
}
|
|
944
961
|
break;
|
|
945
962
|
case "google.vertex_rag_store":
|
|
946
|
-
if (
|
|
963
|
+
if (supportsGemini2Tools) {
|
|
947
964
|
googleTools2.push({
|
|
948
965
|
retrieval: {
|
|
949
966
|
vertex_rag_store: {
|
|
@@ -963,7 +980,7 @@ function prepareTools({
|
|
|
963
980
|
}
|
|
964
981
|
break;
|
|
965
982
|
case "google.google_maps":
|
|
966
|
-
if (
|
|
983
|
+
if (supportsGemini2Tools) {
|
|
967
984
|
googleTools2.push({ googleMaps: {} });
|
|
968
985
|
} else {
|
|
969
986
|
toolWarnings.push({
|
|
@@ -981,7 +998,7 @@ function prepareTools({
|
|
|
981
998
|
break;
|
|
982
999
|
}
|
|
983
1000
|
});
|
|
984
|
-
if (hasFunctionTools &&
|
|
1001
|
+
if (hasFunctionTools && usesGemini3Features && googleTools2.length > 0) {
|
|
985
1002
|
const functionDeclarations2 = [];
|
|
986
1003
|
for (const tool of tools) {
|
|
987
1004
|
if (tool.type === "function") {
|
|
@@ -1496,14 +1513,14 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1496
1513
|
}
|
|
1497
1514
|
}
|
|
1498
1515
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1499
|
-
const
|
|
1500
|
-
const supportsFunctionResponseParts = isGemini3Model2;
|
|
1516
|
+
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1501
1517
|
const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
|
|
1502
1518
|
isGemmaModel,
|
|
1503
|
-
isGemini3Model:
|
|
1519
|
+
isGemini3Model: usesGemini3Features,
|
|
1504
1520
|
onWarning: (warning) => warnings.push(warning),
|
|
1505
1521
|
providerOptionsNames,
|
|
1506
|
-
supportsFunctionResponseParts
|
|
1522
|
+
supportsFunctionResponseParts: usesGemini3Features,
|
|
1523
|
+
includeFunctionCallIds: !isVertexProvider
|
|
1507
1524
|
});
|
|
1508
1525
|
const {
|
|
1509
1526
|
tools: googleTools2,
|
|
@@ -2169,9 +2186,6 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
2169
2186
|
};
|
|
2170
2187
|
}
|
|
2171
2188
|
};
|
|
2172
|
-
function isGemini3Model(modelId) {
|
|
2173
|
-
return /gemini-3[\.\-]/i.test(modelId) || /gemini-3$/i.test(modelId);
|
|
2174
|
-
}
|
|
2175
2189
|
function getMaxOutputTokensForGemini25Model() {
|
|
2176
2190
|
return 65536;
|
|
2177
2191
|
}
|
|
@@ -2190,7 +2204,7 @@ function resolveThinkingConfig({
|
|
|
2190
2204
|
if (!isCustomReasoning(reasoning)) {
|
|
2191
2205
|
return void 0;
|
|
2192
2206
|
}
|
|
2193
|
-
if (
|
|
2207
|
+
if (getGoogleModelCapabilities(modelId).usesGemini3Features && !modelId.includes("gemini-3-pro-image")) {
|
|
2194
2208
|
return resolveGemini3ThinkingConfig({ reasoning, warnings });
|
|
2195
2209
|
}
|
|
2196
2210
|
return resolveGemini25ThinkingConfig({ reasoning, modelId, warnings });
|