@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/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "3.0.
|
|
10
|
+
var VERSION = true ? "3.0.100" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-generative-ai-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -599,6 +599,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
599
599
|
}
|
|
600
600
|
case "assistant": {
|
|
601
601
|
systemMessagesAllowed = false;
|
|
602
|
+
let modelResponseHasSignedFunctionCall = false;
|
|
602
603
|
contents.push({
|
|
603
604
|
role: "model",
|
|
604
605
|
parts: content.map((part) => {
|
|
@@ -639,8 +640,19 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
639
640
|
case "tool-call": {
|
|
640
641
|
const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
|
|
641
642
|
const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
|
|
642
|
-
const
|
|
643
|
-
|
|
643
|
+
const isServerToolCall = serverToolCallId != null && serverToolType != null;
|
|
644
|
+
const shouldSkipMissingSignatureMitigation = (
|
|
645
|
+
// Gemini 3 returns a single signature for a parallel
|
|
646
|
+
// function-call response on the first standard function
|
|
647
|
+
// call. Subsequent standard function calls in the same
|
|
648
|
+
// model response legitimately have no signature.
|
|
649
|
+
!isServerToolCall && thoughtSignature == null && modelResponseHasSignedFunctionCall
|
|
650
|
+
);
|
|
651
|
+
const effectiveThoughtSignature = thoughtSignature != null ? thoughtSignature : isGemini3Model && !shouldSkipMissingSignatureMitigation ? injectSkipSignature(part.toolName) : void 0;
|
|
652
|
+
if (!isServerToolCall && thoughtSignature != null) {
|
|
653
|
+
modelResponseHasSignedFunctionCall = true;
|
|
654
|
+
}
|
|
655
|
+
if (isServerToolCall) {
|
|
644
656
|
return {
|
|
645
657
|
toolCall: {
|
|
646
658
|
toolType: serverToolType,
|
|
@@ -960,6 +972,27 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
960
972
|
)
|
|
961
973
|
);
|
|
962
974
|
|
|
975
|
+
// src/google-model-capabilities.ts
|
|
976
|
+
var gemini1ModelPattern = /(^|\/)gemini-1(?:[.-]|$)/i;
|
|
977
|
+
var gemini2ModelPattern = /(^|\/)gemini-2(?:[.-]|$)/i;
|
|
978
|
+
var gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
979
|
+
var geminiModelPattern = /(^|\/)gemini-/i;
|
|
980
|
+
function isKnownPreGemini2Model(modelId) {
|
|
981
|
+
return gemini1ModelPattern.test(modelId) || /(^|\/)gemini-pro(?:-vision)?$/i.test(modelId) || /(^|\/)gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId);
|
|
982
|
+
}
|
|
983
|
+
function getGoogleModelCapabilities(modelId) {
|
|
984
|
+
const isGeminiModel2 = geminiModelPattern.test(modelId);
|
|
985
|
+
const isGemini2Model = gemini2ModelPattern.test(modelId);
|
|
986
|
+
const isKnownPreGemini2 = isKnownPreGemini2Model(modelId);
|
|
987
|
+
const isKnownOlderModel = isKnownPreGemini2 || isGemini2Model;
|
|
988
|
+
const usesGemini3Features = isGeminiModel2 && !isKnownOlderModel;
|
|
989
|
+
return {
|
|
990
|
+
supportsGemini2Tools: isGeminiModel2 && !isKnownPreGemini2 || modelId.toLowerCase().includes("nano-banana"),
|
|
991
|
+
supportsFileSearch: gemini25ModelPattern.test(modelId) || usesGemini3Features,
|
|
992
|
+
usesGemini3Features
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
|
|
963
996
|
// src/google-prepare-tools.ts
|
|
964
997
|
import {
|
|
965
998
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
@@ -973,20 +1006,13 @@ function prepareTools({
|
|
|
973
1006
|
var _a, _b;
|
|
974
1007
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
975
1008
|
const toolWarnings = [];
|
|
976
|
-
const
|
|
977
|
-
"gemini-flash-latest",
|
|
978
|
-
"gemini-flash-lite-latest",
|
|
979
|
-
"gemini-pro-latest"
|
|
980
|
-
].some((id) => id === modelId);
|
|
981
|
-
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
982
|
-
const isGemini3orNewer = modelId.includes("gemini-3");
|
|
983
|
-
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
1009
|
+
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
984
1010
|
if (tools == null) {
|
|
985
1011
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
986
1012
|
}
|
|
987
1013
|
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
|
988
1014
|
const hasProviderTools = tools.some((tool) => tool.type === "provider");
|
|
989
|
-
if (hasFunctionTools && hasProviderTools && !
|
|
1015
|
+
if (hasFunctionTools && hasProviderTools && !usesGemini3Features) {
|
|
990
1016
|
toolWarnings.push({
|
|
991
1017
|
type: "unsupported",
|
|
992
1018
|
feature: `combination of function and provider-defined tools`
|
|
@@ -998,7 +1024,7 @@ function prepareTools({
|
|
|
998
1024
|
ProviderTools.forEach((tool) => {
|
|
999
1025
|
switch (tool.id) {
|
|
1000
1026
|
case "google.google_search":
|
|
1001
|
-
if (
|
|
1027
|
+
if (supportsGemini2Tools) {
|
|
1002
1028
|
googleTools2.push({ googleSearch: { ...tool.args } });
|
|
1003
1029
|
} else {
|
|
1004
1030
|
toolWarnings.push({
|
|
@@ -1009,7 +1035,7 @@ function prepareTools({
|
|
|
1009
1035
|
}
|
|
1010
1036
|
break;
|
|
1011
1037
|
case "google.enterprise_web_search":
|
|
1012
|
-
if (
|
|
1038
|
+
if (supportsGemini2Tools) {
|
|
1013
1039
|
googleTools2.push({ enterpriseWebSearch: {} });
|
|
1014
1040
|
} else {
|
|
1015
1041
|
toolWarnings.push({
|
|
@@ -1020,7 +1046,7 @@ function prepareTools({
|
|
|
1020
1046
|
}
|
|
1021
1047
|
break;
|
|
1022
1048
|
case "google.url_context":
|
|
1023
|
-
if (
|
|
1049
|
+
if (supportsGemini2Tools) {
|
|
1024
1050
|
googleTools2.push({ urlContext: {} });
|
|
1025
1051
|
} else {
|
|
1026
1052
|
toolWarnings.push({
|
|
@@ -1031,7 +1057,7 @@ function prepareTools({
|
|
|
1031
1057
|
}
|
|
1032
1058
|
break;
|
|
1033
1059
|
case "google.code_execution":
|
|
1034
|
-
if (
|
|
1060
|
+
if (supportsGemini2Tools) {
|
|
1035
1061
|
googleTools2.push({ codeExecution: {} });
|
|
1036
1062
|
} else {
|
|
1037
1063
|
toolWarnings.push({
|
|
@@ -1053,7 +1079,7 @@ function prepareTools({
|
|
|
1053
1079
|
}
|
|
1054
1080
|
break;
|
|
1055
1081
|
case "google.vertex_rag_store":
|
|
1056
|
-
if (
|
|
1082
|
+
if (supportsGemini2Tools) {
|
|
1057
1083
|
googleTools2.push({
|
|
1058
1084
|
retrieval: {
|
|
1059
1085
|
vertex_rag_store: {
|
|
@@ -1073,7 +1099,7 @@ function prepareTools({
|
|
|
1073
1099
|
}
|
|
1074
1100
|
break;
|
|
1075
1101
|
case "google.google_maps":
|
|
1076
|
-
if (
|
|
1102
|
+
if (supportsGemini2Tools) {
|
|
1077
1103
|
googleTools2.push({ googleMaps: {} });
|
|
1078
1104
|
} else {
|
|
1079
1105
|
toolWarnings.push({
|
|
@@ -1091,7 +1117,7 @@ function prepareTools({
|
|
|
1091
1117
|
break;
|
|
1092
1118
|
}
|
|
1093
1119
|
});
|
|
1094
|
-
if (hasFunctionTools &&
|
|
1120
|
+
if (hasFunctionTools && usesGemini3Features && googleTools2.length > 0) {
|
|
1095
1121
|
const functionDeclarations2 = [];
|
|
1096
1122
|
for (const tool of tools) {
|
|
1097
1123
|
if (tool.type === "function") {
|
|
@@ -1588,15 +1614,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1588
1614
|
}
|
|
1589
1615
|
}
|
|
1590
1616
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1591
|
-
const
|
|
1592
|
-
const supportsFunctionResponseParts = isGemini3Model;
|
|
1617
|
+
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1593
1618
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1594
1619
|
prompt,
|
|
1595
1620
|
{
|
|
1596
1621
|
isGemmaModel,
|
|
1597
|
-
isGemini3Model,
|
|
1622
|
+
isGemini3Model: usesGemini3Features,
|
|
1598
1623
|
providerOptionsName,
|
|
1599
|
-
supportsFunctionResponseParts,
|
|
1624
|
+
supportsFunctionResponseParts: usesGemini3Features,
|
|
1600
1625
|
onWarning: (warning) => warnings.push(warning)
|
|
1601
1626
|
}
|
|
1602
1627
|
);
|