@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/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.101" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-generative-ai-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -452,7 +452,7 @@ function convertUrlToolResultPart(url) {
|
|
|
452
452
|
}
|
|
453
453
|
};
|
|
454
454
|
}
|
|
455
|
-
function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
455
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
|
|
456
456
|
const functionResponseParts = [];
|
|
457
457
|
const responseTextParts = [];
|
|
458
458
|
for (const contentPart of outputValue) {
|
|
@@ -491,7 +491,7 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
|
491
491
|
}
|
|
492
492
|
parts.push({
|
|
493
493
|
functionResponse: {
|
|
494
|
-
...toolCallId != null ? { id: toolCallId } : {},
|
|
494
|
+
...includeFunctionCallIds && toolCallId != null ? { id: toolCallId } : {},
|
|
495
495
|
name: toolName,
|
|
496
496
|
response: {
|
|
497
497
|
name: toolName,
|
|
@@ -501,13 +501,13 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
|
501
501
|
}
|
|
502
502
|
});
|
|
503
503
|
}
|
|
504
|
-
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
504
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
|
|
505
505
|
for (const contentPart of outputValue) {
|
|
506
506
|
switch (contentPart.type) {
|
|
507
507
|
case "text":
|
|
508
508
|
parts.push({
|
|
509
509
|
functionResponse: {
|
|
510
|
-
...toolCallId != null ? { id: toolCallId } : {},
|
|
510
|
+
...includeFunctionCallIds && toolCallId != null ? { id: toolCallId } : {},
|
|
511
511
|
name: toolName,
|
|
512
512
|
response: {
|
|
513
513
|
name: toolName,
|
|
@@ -539,7 +539,7 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
541
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
542
|
-
var _a, _b, _c, _d, _e;
|
|
542
|
+
var _a, _b, _c, _d, _e, _f;
|
|
543
543
|
const systemInstructionParts = [];
|
|
544
544
|
const contents = [];
|
|
545
545
|
let systemMessagesAllowed = true;
|
|
@@ -548,6 +548,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
548
548
|
const providerOptionsName = (_c = options == null ? void 0 : options.providerOptionsName) != null ? _c : "google";
|
|
549
549
|
const supportsFunctionResponseParts = (_d = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _d : true;
|
|
550
550
|
const onWarning = options == null ? void 0 : options.onWarning;
|
|
551
|
+
const includeFunctionCallIds = (_e = options == null ? void 0 : options.includeFunctionCallIds) != null ? _e : true;
|
|
551
552
|
let sentinelInjected = false;
|
|
552
553
|
const missingSignatureToolNames = [];
|
|
553
554
|
const injectSkipSignature = (toolName) => {
|
|
@@ -664,7 +665,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
664
665
|
}
|
|
665
666
|
return {
|
|
666
667
|
functionCall: {
|
|
667
|
-
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
668
|
+
...includeFunctionCallIds && part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
668
669
|
name: part.toolName,
|
|
669
670
|
args: part.input
|
|
670
671
|
},
|
|
@@ -728,24 +729,26 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
728
729
|
parts,
|
|
729
730
|
part.toolName,
|
|
730
731
|
output.value,
|
|
731
|
-
part.toolCallId
|
|
732
|
+
part.toolCallId,
|
|
733
|
+
includeFunctionCallIds
|
|
732
734
|
);
|
|
733
735
|
} else {
|
|
734
736
|
appendLegacyToolResultParts(
|
|
735
737
|
parts,
|
|
736
738
|
part.toolName,
|
|
737
739
|
output.value,
|
|
738
|
-
part.toolCallId
|
|
740
|
+
part.toolCallId,
|
|
741
|
+
includeFunctionCallIds
|
|
739
742
|
);
|
|
740
743
|
}
|
|
741
744
|
} else {
|
|
742
745
|
parts.push({
|
|
743
746
|
functionResponse: {
|
|
744
|
-
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
747
|
+
...includeFunctionCallIds && part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
745
748
|
name: part.toolName,
|
|
746
749
|
response: {
|
|
747
750
|
name: part.toolName,
|
|
748
|
-
content: output.type === "execution-denied" ? (
|
|
751
|
+
content: output.type === "execution-denied" ? (_f = output.reason) != null ? _f : "Tool call execution denied." : output.value
|
|
749
752
|
}
|
|
750
753
|
}
|
|
751
754
|
});
|
|
@@ -972,6 +975,27 @@ var googleLanguageModelOptions = lazySchema4(
|
|
|
972
975
|
)
|
|
973
976
|
);
|
|
974
977
|
|
|
978
|
+
// src/google-model-capabilities.ts
|
|
979
|
+
var gemini1ModelPattern = /(^|\/)gemini-1(?:[.-]|$)/i;
|
|
980
|
+
var gemini2ModelPattern = /(^|\/)gemini-2(?:[.-]|$)/i;
|
|
981
|
+
var gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
982
|
+
var geminiModelPattern = /(^|\/)gemini-/i;
|
|
983
|
+
function isKnownPreGemini2Model(modelId) {
|
|
984
|
+
return gemini1ModelPattern.test(modelId) || /(^|\/)gemini-pro(?:-vision)?$/i.test(modelId) || /(^|\/)gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId);
|
|
985
|
+
}
|
|
986
|
+
function getGoogleModelCapabilities(modelId) {
|
|
987
|
+
const isGeminiModel2 = geminiModelPattern.test(modelId);
|
|
988
|
+
const isGemini2Model = gemini2ModelPattern.test(modelId);
|
|
989
|
+
const isKnownPreGemini2 = isKnownPreGemini2Model(modelId);
|
|
990
|
+
const isKnownOlderModel = isKnownPreGemini2 || isGemini2Model;
|
|
991
|
+
const usesGemini3Features = isGeminiModel2 && !isKnownOlderModel;
|
|
992
|
+
return {
|
|
993
|
+
supportsGemini2Tools: isGeminiModel2 && !isKnownPreGemini2 || modelId.toLowerCase().includes("nano-banana"),
|
|
994
|
+
supportsFileSearch: gemini25ModelPattern.test(modelId) || usesGemini3Features,
|
|
995
|
+
usesGemini3Features
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
|
|
975
999
|
// src/google-prepare-tools.ts
|
|
976
1000
|
import {
|
|
977
1001
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
@@ -985,20 +1009,13 @@ function prepareTools({
|
|
|
985
1009
|
var _a, _b;
|
|
986
1010
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
987
1011
|
const toolWarnings = [];
|
|
988
|
-
const
|
|
989
|
-
"gemini-flash-latest",
|
|
990
|
-
"gemini-flash-lite-latest",
|
|
991
|
-
"gemini-pro-latest"
|
|
992
|
-
].some((id) => id === modelId);
|
|
993
|
-
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
994
|
-
const isGemini3orNewer = modelId.includes("gemini-3");
|
|
995
|
-
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
1012
|
+
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
996
1013
|
if (tools == null) {
|
|
997
1014
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
998
1015
|
}
|
|
999
1016
|
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
|
1000
1017
|
const hasProviderTools = tools.some((tool) => tool.type === "provider");
|
|
1001
|
-
if (hasFunctionTools && hasProviderTools && !
|
|
1018
|
+
if (hasFunctionTools && hasProviderTools && !usesGemini3Features) {
|
|
1002
1019
|
toolWarnings.push({
|
|
1003
1020
|
type: "unsupported",
|
|
1004
1021
|
feature: `combination of function and provider-defined tools`
|
|
@@ -1010,7 +1027,7 @@ function prepareTools({
|
|
|
1010
1027
|
ProviderTools.forEach((tool) => {
|
|
1011
1028
|
switch (tool.id) {
|
|
1012
1029
|
case "google.google_search":
|
|
1013
|
-
if (
|
|
1030
|
+
if (supportsGemini2Tools) {
|
|
1014
1031
|
googleTools2.push({ googleSearch: { ...tool.args } });
|
|
1015
1032
|
} else {
|
|
1016
1033
|
toolWarnings.push({
|
|
@@ -1021,7 +1038,7 @@ function prepareTools({
|
|
|
1021
1038
|
}
|
|
1022
1039
|
break;
|
|
1023
1040
|
case "google.enterprise_web_search":
|
|
1024
|
-
if (
|
|
1041
|
+
if (supportsGemini2Tools) {
|
|
1025
1042
|
googleTools2.push({ enterpriseWebSearch: {} });
|
|
1026
1043
|
} else {
|
|
1027
1044
|
toolWarnings.push({
|
|
@@ -1032,7 +1049,7 @@ function prepareTools({
|
|
|
1032
1049
|
}
|
|
1033
1050
|
break;
|
|
1034
1051
|
case "google.url_context":
|
|
1035
|
-
if (
|
|
1052
|
+
if (supportsGemini2Tools) {
|
|
1036
1053
|
googleTools2.push({ urlContext: {} });
|
|
1037
1054
|
} else {
|
|
1038
1055
|
toolWarnings.push({
|
|
@@ -1043,7 +1060,7 @@ function prepareTools({
|
|
|
1043
1060
|
}
|
|
1044
1061
|
break;
|
|
1045
1062
|
case "google.code_execution":
|
|
1046
|
-
if (
|
|
1063
|
+
if (supportsGemini2Tools) {
|
|
1047
1064
|
googleTools2.push({ codeExecution: {} });
|
|
1048
1065
|
} else {
|
|
1049
1066
|
toolWarnings.push({
|
|
@@ -1065,7 +1082,7 @@ function prepareTools({
|
|
|
1065
1082
|
}
|
|
1066
1083
|
break;
|
|
1067
1084
|
case "google.vertex_rag_store":
|
|
1068
|
-
if (
|
|
1085
|
+
if (supportsGemini2Tools) {
|
|
1069
1086
|
googleTools2.push({
|
|
1070
1087
|
retrieval: {
|
|
1071
1088
|
vertex_rag_store: {
|
|
@@ -1085,7 +1102,7 @@ function prepareTools({
|
|
|
1085
1102
|
}
|
|
1086
1103
|
break;
|
|
1087
1104
|
case "google.google_maps":
|
|
1088
|
-
if (
|
|
1105
|
+
if (supportsGemini2Tools) {
|
|
1089
1106
|
googleTools2.push({ googleMaps: {} });
|
|
1090
1107
|
} else {
|
|
1091
1108
|
toolWarnings.push({
|
|
@@ -1103,7 +1120,7 @@ function prepareTools({
|
|
|
1103
1120
|
break;
|
|
1104
1121
|
}
|
|
1105
1122
|
});
|
|
1106
|
-
if (hasFunctionTools &&
|
|
1123
|
+
if (hasFunctionTools && usesGemini3Features && googleTools2.length > 0) {
|
|
1107
1124
|
const functionDeclarations2 = [];
|
|
1108
1125
|
for (const tool of tools) {
|
|
1109
1126
|
if (tool.type === "function") {
|
|
@@ -1600,16 +1617,16 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1600
1617
|
}
|
|
1601
1618
|
}
|
|
1602
1619
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1603
|
-
const
|
|
1604
|
-
const supportsFunctionResponseParts = isGemini3Model;
|
|
1620
|
+
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1605
1621
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1606
1622
|
prompt,
|
|
1607
1623
|
{
|
|
1608
1624
|
isGemmaModel,
|
|
1609
|
-
isGemini3Model,
|
|
1625
|
+
isGemini3Model: usesGemini3Features,
|
|
1610
1626
|
providerOptionsName,
|
|
1611
|
-
supportsFunctionResponseParts,
|
|
1612
|
-
onWarning: (warning) => warnings.push(warning)
|
|
1627
|
+
supportsFunctionResponseParts: usesGemini3Features,
|
|
1628
|
+
onWarning: (warning) => warnings.push(warning),
|
|
1629
|
+
includeFunctionCallIds: !isVertexProvider
|
|
1613
1630
|
}
|
|
1614
1631
|
);
|
|
1615
1632
|
const {
|