@ai-sdk/google 3.0.98 → 3.0.100
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 +48 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -23
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +47 -22
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +47 -22
- 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 +18 -7
- package/src/google-generative-ai-language-model.ts +4 -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.100
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- dae771a: feat(provider/google): default unknown Gemini model IDs to the newest supported capabilities
|
|
8
|
+
|
|
9
|
+
## 3.0.99
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 2886d22: Avoid missing thought-signature warnings and skip-validator injection for valid unsigned Gemini 3 parallel function calls in the same model response.
|
|
14
|
+
|
|
3
15
|
## 3.0.98
|
|
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.100" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -593,6 +593,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
593
593
|
}
|
|
594
594
|
case "assistant": {
|
|
595
595
|
systemMessagesAllowed = false;
|
|
596
|
+
let modelResponseHasSignedFunctionCall = false;
|
|
596
597
|
contents.push({
|
|
597
598
|
role: "model",
|
|
598
599
|
parts: content.map((part) => {
|
|
@@ -633,8 +634,19 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
633
634
|
case "tool-call": {
|
|
634
635
|
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
635
636
|
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
636
|
-
const
|
|
637
|
-
|
|
637
|
+
const isServerToolCall = serverToolCallId != null && serverToolType != null;
|
|
638
|
+
const shouldSkipMissingSignatureMitigation = (
|
|
639
|
+
// Gemini 3 returns a single signature for a parallel
|
|
640
|
+
// function-call response on the first standard function
|
|
641
|
+
// call. Subsequent standard function calls in the same
|
|
642
|
+
// model response legitimately have no signature.
|
|
643
|
+
!isServerToolCall && thoughtSignature == null && modelResponseHasSignedFunctionCall
|
|
644
|
+
);
|
|
645
|
+
const effectiveThoughtSignature = thoughtSignature != null ? thoughtSignature : isGemini3Model && !shouldSkipMissingSignatureMitigation ? injectSkipSignature(part.toolName) : void 0;
|
|
646
|
+
if (!isServerToolCall && thoughtSignature != null) {
|
|
647
|
+
modelResponseHasSignedFunctionCall = true;
|
|
648
|
+
}
|
|
649
|
+
if (isServerToolCall) {
|
|
638
650
|
return {
|
|
639
651
|
toolCall: {
|
|
640
652
|
toolType: serverToolType,
|
|
@@ -951,6 +963,27 @@ var googleLanguageModelOptions = (0, import_provider_utils5.lazySchema)(
|
|
|
951
963
|
)
|
|
952
964
|
);
|
|
953
965
|
|
|
966
|
+
// src/google-model-capabilities.ts
|
|
967
|
+
var gemini1ModelPattern = /(^|\/)gemini-1(?:[.-]|$)/i;
|
|
968
|
+
var gemini2ModelPattern = /(^|\/)gemini-2(?:[.-]|$)/i;
|
|
969
|
+
var gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
970
|
+
var geminiModelPattern = /(^|\/)gemini-/i;
|
|
971
|
+
function isKnownPreGemini2Model(modelId) {
|
|
972
|
+
return gemini1ModelPattern.test(modelId) || /(^|\/)gemini-pro(?:-vision)?$/i.test(modelId) || /(^|\/)gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId);
|
|
973
|
+
}
|
|
974
|
+
function getGoogleModelCapabilities(modelId) {
|
|
975
|
+
const isGeminiModel2 = geminiModelPattern.test(modelId);
|
|
976
|
+
const isGemini2Model = gemini2ModelPattern.test(modelId);
|
|
977
|
+
const isKnownPreGemini2 = isKnownPreGemini2Model(modelId);
|
|
978
|
+
const isKnownOlderModel = isKnownPreGemini2 || isGemini2Model;
|
|
979
|
+
const usesGemini3Features = isGeminiModel2 && !isKnownOlderModel;
|
|
980
|
+
return {
|
|
981
|
+
supportsGemini2Tools: isGeminiModel2 && !isKnownPreGemini2 || modelId.toLowerCase().includes("nano-banana"),
|
|
982
|
+
supportsFileSearch: gemini25ModelPattern.test(modelId) || usesGemini3Features,
|
|
983
|
+
usesGemini3Features
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
|
|
954
987
|
// src/google-prepare-tools.ts
|
|
955
988
|
var import_provider3 = require("@ai-sdk/provider");
|
|
956
989
|
function prepareTools({
|
|
@@ -962,20 +995,13 @@ function prepareTools({
|
|
|
962
995
|
var _a, _b;
|
|
963
996
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
964
997
|
const toolWarnings = [];
|
|
965
|
-
const
|
|
966
|
-
"gemini-flash-latest",
|
|
967
|
-
"gemini-flash-lite-latest",
|
|
968
|
-
"gemini-pro-latest"
|
|
969
|
-
].some((id) => id === modelId);
|
|
970
|
-
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
971
|
-
const isGemini3orNewer = modelId.includes("gemini-3");
|
|
972
|
-
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
998
|
+
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
973
999
|
if (tools == null) {
|
|
974
1000
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
975
1001
|
}
|
|
976
1002
|
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
|
977
1003
|
const hasProviderTools = tools.some((tool) => tool.type === "provider");
|
|
978
|
-
if (hasFunctionTools && hasProviderTools && !
|
|
1004
|
+
if (hasFunctionTools && hasProviderTools && !usesGemini3Features) {
|
|
979
1005
|
toolWarnings.push({
|
|
980
1006
|
type: "unsupported",
|
|
981
1007
|
feature: `combination of function and provider-defined tools`
|
|
@@ -987,7 +1013,7 @@ function prepareTools({
|
|
|
987
1013
|
ProviderTools.forEach((tool) => {
|
|
988
1014
|
switch (tool.id) {
|
|
989
1015
|
case "google.google_search":
|
|
990
|
-
if (
|
|
1016
|
+
if (supportsGemini2Tools) {
|
|
991
1017
|
googleTools2.push({ googleSearch: { ...tool.args } });
|
|
992
1018
|
} else {
|
|
993
1019
|
toolWarnings.push({
|
|
@@ -998,7 +1024,7 @@ function prepareTools({
|
|
|
998
1024
|
}
|
|
999
1025
|
break;
|
|
1000
1026
|
case "google.enterprise_web_search":
|
|
1001
|
-
if (
|
|
1027
|
+
if (supportsGemini2Tools) {
|
|
1002
1028
|
googleTools2.push({ enterpriseWebSearch: {} });
|
|
1003
1029
|
} else {
|
|
1004
1030
|
toolWarnings.push({
|
|
@@ -1009,7 +1035,7 @@ function prepareTools({
|
|
|
1009
1035
|
}
|
|
1010
1036
|
break;
|
|
1011
1037
|
case "google.url_context":
|
|
1012
|
-
if (
|
|
1038
|
+
if (supportsGemini2Tools) {
|
|
1013
1039
|
googleTools2.push({ urlContext: {} });
|
|
1014
1040
|
} else {
|
|
1015
1041
|
toolWarnings.push({
|
|
@@ -1020,7 +1046,7 @@ function prepareTools({
|
|
|
1020
1046
|
}
|
|
1021
1047
|
break;
|
|
1022
1048
|
case "google.code_execution":
|
|
1023
|
-
if (
|
|
1049
|
+
if (supportsGemini2Tools) {
|
|
1024
1050
|
googleTools2.push({ codeExecution: {} });
|
|
1025
1051
|
} else {
|
|
1026
1052
|
toolWarnings.push({
|
|
@@ -1042,7 +1068,7 @@ function prepareTools({
|
|
|
1042
1068
|
}
|
|
1043
1069
|
break;
|
|
1044
1070
|
case "google.vertex_rag_store":
|
|
1045
|
-
if (
|
|
1071
|
+
if (supportsGemini2Tools) {
|
|
1046
1072
|
googleTools2.push({
|
|
1047
1073
|
retrieval: {
|
|
1048
1074
|
vertex_rag_store: {
|
|
@@ -1062,7 +1088,7 @@ function prepareTools({
|
|
|
1062
1088
|
}
|
|
1063
1089
|
break;
|
|
1064
1090
|
case "google.google_maps":
|
|
1065
|
-
if (
|
|
1091
|
+
if (supportsGemini2Tools) {
|
|
1066
1092
|
googleTools2.push({ googleMaps: {} });
|
|
1067
1093
|
} else {
|
|
1068
1094
|
toolWarnings.push({
|
|
@@ -1080,7 +1106,7 @@ function prepareTools({
|
|
|
1080
1106
|
break;
|
|
1081
1107
|
}
|
|
1082
1108
|
});
|
|
1083
|
-
if (hasFunctionTools &&
|
|
1109
|
+
if (hasFunctionTools && usesGemini3Features && googleTools2.length > 0) {
|
|
1084
1110
|
const functionDeclarations2 = [];
|
|
1085
1111
|
for (const tool of tools) {
|
|
1086
1112
|
if (tool.type === "function") {
|
|
@@ -1577,15 +1603,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1577
1603
|
}
|
|
1578
1604
|
}
|
|
1579
1605
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1580
|
-
const
|
|
1581
|
-
const supportsFunctionResponseParts = isGemini3Model;
|
|
1606
|
+
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1582
1607
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1583
1608
|
prompt,
|
|
1584
1609
|
{
|
|
1585
1610
|
isGemmaModel,
|
|
1586
|
-
isGemini3Model,
|
|
1611
|
+
isGemini3Model: usesGemini3Features,
|
|
1587
1612
|
providerOptionsName,
|
|
1588
|
-
supportsFunctionResponseParts,
|
|
1613
|
+
supportsFunctionResponseParts: usesGemini3Features,
|
|
1589
1614
|
onWarning: (warning) => warnings.push(warning)
|
|
1590
1615
|
}
|
|
1591
1616
|
);
|