@ai-sdk/google 3.0.99 → 3.0.101
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 +49 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -32
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +48 -31
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +48 -31
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +16 -6
- package/package.json +1 -1
- package/src/convert-to-google-generative-ai-messages.ts +16 -4
- package/src/google-generative-ai-language-model.ts +5 -4
- 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
|
+
## 3.0.101
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 326887b: fix(google): omit unsupported function call IDs
|
|
8
|
+
|
|
9
|
+
## 3.0.100
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- dae771a: feat(provider/google): default unknown Gemini model IDs to the newest supported capabilities
|
|
14
|
+
|
|
3
15
|
## 3.0.99
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
30
30
|
var import_provider_utils23 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "3.0.
|
|
33
|
+
var VERSION = true ? "3.0.101" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -446,7 +446,7 @@ function convertUrlToolResultPart(url) {
|
|
|
446
446
|
}
|
|
447
447
|
};
|
|
448
448
|
}
|
|
449
|
-
function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
449
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
|
|
450
450
|
const functionResponseParts = [];
|
|
451
451
|
const responseTextParts = [];
|
|
452
452
|
for (const contentPart of outputValue) {
|
|
@@ -485,7 +485,7 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
|
485
485
|
}
|
|
486
486
|
parts.push({
|
|
487
487
|
functionResponse: {
|
|
488
|
-
...toolCallId != null ? { id: toolCallId } : {},
|
|
488
|
+
...includeFunctionCallIds && toolCallId != null ? { id: toolCallId } : {},
|
|
489
489
|
name: toolName,
|
|
490
490
|
response: {
|
|
491
491
|
name: toolName,
|
|
@@ -495,13 +495,13 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
|
495
495
|
}
|
|
496
496
|
});
|
|
497
497
|
}
|
|
498
|
-
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
498
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
|
|
499
499
|
for (const contentPart of outputValue) {
|
|
500
500
|
switch (contentPart.type) {
|
|
501
501
|
case "text":
|
|
502
502
|
parts.push({
|
|
503
503
|
functionResponse: {
|
|
504
|
-
...toolCallId != null ? { id: toolCallId } : {},
|
|
504
|
+
...includeFunctionCallIds && toolCallId != null ? { id: toolCallId } : {},
|
|
505
505
|
name: toolName,
|
|
506
506
|
response: {
|
|
507
507
|
name: toolName,
|
|
@@ -533,7 +533,7 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
|
533
533
|
}
|
|
534
534
|
}
|
|
535
535
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
536
|
-
var _a, _b, _c, _d, _e;
|
|
536
|
+
var _a, _b, _c, _d, _e, _f;
|
|
537
537
|
const systemInstructionParts = [];
|
|
538
538
|
const contents = [];
|
|
539
539
|
let systemMessagesAllowed = true;
|
|
@@ -542,6 +542,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
542
542
|
const providerOptionsName = (_c = options == null ? void 0 : options.providerOptionsName) != null ? _c : "google";
|
|
543
543
|
const supportsFunctionResponseParts = (_d = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _d : true;
|
|
544
544
|
const onWarning = options == null ? void 0 : options.onWarning;
|
|
545
|
+
const includeFunctionCallIds = (_e = options == null ? void 0 : options.includeFunctionCallIds) != null ? _e : true;
|
|
545
546
|
let sentinelInjected = false;
|
|
546
547
|
const missingSignatureToolNames = [];
|
|
547
548
|
const injectSkipSignature = (toolName) => {
|
|
@@ -658,7 +659,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
658
659
|
}
|
|
659
660
|
return {
|
|
660
661
|
functionCall: {
|
|
661
|
-
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
662
|
+
...includeFunctionCallIds && part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
662
663
|
name: part.toolName,
|
|
663
664
|
args: part.input
|
|
664
665
|
},
|
|
@@ -722,24 +723,26 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
722
723
|
parts,
|
|
723
724
|
part.toolName,
|
|
724
725
|
output.value,
|
|
725
|
-
part.toolCallId
|
|
726
|
+
part.toolCallId,
|
|
727
|
+
includeFunctionCallIds
|
|
726
728
|
);
|
|
727
729
|
} else {
|
|
728
730
|
appendLegacyToolResultParts(
|
|
729
731
|
parts,
|
|
730
732
|
part.toolName,
|
|
731
733
|
output.value,
|
|
732
|
-
part.toolCallId
|
|
734
|
+
part.toolCallId,
|
|
735
|
+
includeFunctionCallIds
|
|
733
736
|
);
|
|
734
737
|
}
|
|
735
738
|
} else {
|
|
736
739
|
parts.push({
|
|
737
740
|
functionResponse: {
|
|
738
|
-
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
741
|
+
...includeFunctionCallIds && part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
739
742
|
name: part.toolName,
|
|
740
743
|
response: {
|
|
741
744
|
name: part.toolName,
|
|
742
|
-
content: output.type === "execution-denied" ? (
|
|
745
|
+
content: output.type === "execution-denied" ? (_f = output.reason) != null ? _f : "Tool call execution denied." : output.value
|
|
743
746
|
}
|
|
744
747
|
}
|
|
745
748
|
});
|
|
@@ -963,6 +966,27 @@ var googleLanguageModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
963
966
|
)
|
|
964
967
|
);
|
|
965
968
|
|
|
969
|
+
// src/google-model-capabilities.ts
|
|
970
|
+
var gemini1ModelPattern = /(^|\/)gemini-1(?:[.-]|$)/i;
|
|
971
|
+
var gemini2ModelPattern = /(^|\/)gemini-2(?:[.-]|$)/i;
|
|
972
|
+
var gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
973
|
+
var geminiModelPattern = /(^|\/)gemini-/i;
|
|
974
|
+
function isKnownPreGemini2Model(modelId) {
|
|
975
|
+
return gemini1ModelPattern.test(modelId) || /(^|\/)gemini-pro(?:-vision)?$/i.test(modelId) || /(^|\/)gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId);
|
|
976
|
+
}
|
|
977
|
+
function getGoogleModelCapabilities(modelId) {
|
|
978
|
+
const isGeminiModel2 = geminiModelPattern.test(modelId);
|
|
979
|
+
const isGemini2Model = gemini2ModelPattern.test(modelId);
|
|
980
|
+
const isKnownPreGemini2 = isKnownPreGemini2Model(modelId);
|
|
981
|
+
const isKnownOlderModel = isKnownPreGemini2 || isGemini2Model;
|
|
982
|
+
const usesGemini3Features = isGeminiModel2 && !isKnownOlderModel;
|
|
983
|
+
return {
|
|
984
|
+
supportsGemini2Tools: isGeminiModel2 && !isKnownPreGemini2 || modelId.toLowerCase().includes("nano-banana"),
|
|
985
|
+
supportsFileSearch: gemini25ModelPattern.test(modelId) || usesGemini3Features,
|
|
986
|
+
usesGemini3Features
|
|
987
|
+
};
|
|
988
|
+
}
|
|
989
|
+
|
|
966
990
|
// src/google-prepare-tools.ts
|
|
967
991
|
var import_provider3 = require("@ai-sdk/provider");
|
|
968
992
|
function prepareTools({
|
|
@@ -974,20 +998,13 @@ function prepareTools({
|
|
|
974
998
|
var _a, _b;
|
|
975
999
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
976
1000
|
const toolWarnings = [];
|
|
977
|
-
const
|
|
978
|
-
"gemini-flash-latest",
|
|
979
|
-
"gemini-flash-lite-latest",
|
|
980
|
-
"gemini-pro-latest"
|
|
981
|
-
].some((id) => id === modelId);
|
|
982
|
-
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
983
|
-
const isGemini3orNewer = modelId.includes("gemini-3");
|
|
984
|
-
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
1001
|
+
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
985
1002
|
if (tools == null) {
|
|
986
1003
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
987
1004
|
}
|
|
988
1005
|
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
|
989
1006
|
const hasProviderTools = tools.some((tool) => tool.type === "provider");
|
|
990
|
-
if (hasFunctionTools && hasProviderTools && !
|
|
1007
|
+
if (hasFunctionTools && hasProviderTools && !usesGemini3Features) {
|
|
991
1008
|
toolWarnings.push({
|
|
992
1009
|
type: "unsupported",
|
|
993
1010
|
feature: `combination of function and provider-defined tools`
|
|
@@ -999,7 +1016,7 @@ function prepareTools({
|
|
|
999
1016
|
ProviderTools.forEach((tool) => {
|
|
1000
1017
|
switch (tool.id) {
|
|
1001
1018
|
case "google.google_search":
|
|
1002
|
-
if (
|
|
1019
|
+
if (supportsGemini2Tools) {
|
|
1003
1020
|
googleTools2.push({ googleSearch: { ...tool.args } });
|
|
1004
1021
|
} else {
|
|
1005
1022
|
toolWarnings.push({
|
|
@@ -1010,7 +1027,7 @@ function prepareTools({
|
|
|
1010
1027
|
}
|
|
1011
1028
|
break;
|
|
1012
1029
|
case "google.enterprise_web_search":
|
|
1013
|
-
if (
|
|
1030
|
+
if (supportsGemini2Tools) {
|
|
1014
1031
|
googleTools2.push({ enterpriseWebSearch: {} });
|
|
1015
1032
|
} else {
|
|
1016
1033
|
toolWarnings.push({
|
|
@@ -1021,7 +1038,7 @@ function prepareTools({
|
|
|
1021
1038
|
}
|
|
1022
1039
|
break;
|
|
1023
1040
|
case "google.url_context":
|
|
1024
|
-
if (
|
|
1041
|
+
if (supportsGemini2Tools) {
|
|
1025
1042
|
googleTools2.push({ urlContext: {} });
|
|
1026
1043
|
} else {
|
|
1027
1044
|
toolWarnings.push({
|
|
@@ -1032,7 +1049,7 @@ function prepareTools({
|
|
|
1032
1049
|
}
|
|
1033
1050
|
break;
|
|
1034
1051
|
case "google.code_execution":
|
|
1035
|
-
if (
|
|
1052
|
+
if (supportsGemini2Tools) {
|
|
1036
1053
|
googleTools2.push({ codeExecution: {} });
|
|
1037
1054
|
} else {
|
|
1038
1055
|
toolWarnings.push({
|
|
@@ -1054,7 +1071,7 @@ function prepareTools({
|
|
|
1054
1071
|
}
|
|
1055
1072
|
break;
|
|
1056
1073
|
case "google.vertex_rag_store":
|
|
1057
|
-
if (
|
|
1074
|
+
if (supportsGemini2Tools) {
|
|
1058
1075
|
googleTools2.push({
|
|
1059
1076
|
retrieval: {
|
|
1060
1077
|
vertex_rag_store: {
|
|
@@ -1074,7 +1091,7 @@ function prepareTools({
|
|
|
1074
1091
|
}
|
|
1075
1092
|
break;
|
|
1076
1093
|
case "google.google_maps":
|
|
1077
|
-
if (
|
|
1094
|
+
if (supportsGemini2Tools) {
|
|
1078
1095
|
googleTools2.push({ googleMaps: {} });
|
|
1079
1096
|
} else {
|
|
1080
1097
|
toolWarnings.push({
|
|
@@ -1092,7 +1109,7 @@ function prepareTools({
|
|
|
1092
1109
|
break;
|
|
1093
1110
|
}
|
|
1094
1111
|
});
|
|
1095
|
-
if (hasFunctionTools &&
|
|
1112
|
+
if (hasFunctionTools && usesGemini3Features && googleTools2.length > 0) {
|
|
1096
1113
|
const functionDeclarations2 = [];
|
|
1097
1114
|
for (const tool of tools) {
|
|
1098
1115
|
if (tool.type === "function") {
|
|
@@ -1589,16 +1606,16 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1589
1606
|
}
|
|
1590
1607
|
}
|
|
1591
1608
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1592
|
-
const
|
|
1593
|
-
const supportsFunctionResponseParts = isGemini3Model;
|
|
1609
|
+
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1594
1610
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1595
1611
|
prompt,
|
|
1596
1612
|
{
|
|
1597
1613
|
isGemmaModel,
|
|
1598
|
-
isGemini3Model,
|
|
1614
|
+
isGemini3Model: usesGemini3Features,
|
|
1599
1615
|
providerOptionsName,
|
|
1600
|
-
supportsFunctionResponseParts,
|
|
1601
|
-
onWarning: (warning) => warnings.push(warning)
|
|
1616
|
+
supportsFunctionResponseParts: usesGemini3Features,
|
|
1617
|
+
onWarning: (warning) => warnings.push(warning),
|
|
1618
|
+
includeFunctionCallIds: !isVertexProvider
|
|
1602
1619
|
}
|
|
1603
1620
|
);
|
|
1604
1621
|
const {
|