@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/internal/index.mjs
CHANGED
|
@@ -212,7 +212,7 @@ function convertUrlToolResultPart(url) {
|
|
|
212
212
|
}
|
|
213
213
|
};
|
|
214
214
|
}
|
|
215
|
-
function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
215
|
+
function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
|
|
216
216
|
const functionResponseParts = [];
|
|
217
217
|
const responseTextParts = [];
|
|
218
218
|
for (const contentPart of outputValue) {
|
|
@@ -251,7 +251,7 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
|
251
251
|
}
|
|
252
252
|
parts.push({
|
|
253
253
|
functionResponse: {
|
|
254
|
-
...toolCallId != null ? { id: toolCallId } : {},
|
|
254
|
+
...includeFunctionCallIds && toolCallId != null ? { id: toolCallId } : {},
|
|
255
255
|
name: toolName,
|
|
256
256
|
response: {
|
|
257
257
|
name: toolName,
|
|
@@ -261,13 +261,13 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
|
261
261
|
}
|
|
262
262
|
});
|
|
263
263
|
}
|
|
264
|
-
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
264
|
+
function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
|
|
265
265
|
for (const contentPart of outputValue) {
|
|
266
266
|
switch (contentPart.type) {
|
|
267
267
|
case "text":
|
|
268
268
|
parts.push({
|
|
269
269
|
functionResponse: {
|
|
270
|
-
...toolCallId != null ? { id: toolCallId } : {},
|
|
270
|
+
...includeFunctionCallIds && toolCallId != null ? { id: toolCallId } : {},
|
|
271
271
|
name: toolName,
|
|
272
272
|
response: {
|
|
273
273
|
name: toolName,
|
|
@@ -299,7 +299,7 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId) {
|
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
function convertToGoogleGenerativeAIMessages(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;
|
|
@@ -308,6 +308,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
308
308
|
const providerOptionsName = (_c = options == null ? void 0 : options.providerOptionsName) != null ? _c : "google";
|
|
309
309
|
const supportsFunctionResponseParts = (_d = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _d : true;
|
|
310
310
|
const onWarning = options == null ? void 0 : options.onWarning;
|
|
311
|
+
const includeFunctionCallIds = (_e = options == null ? void 0 : options.includeFunctionCallIds) != null ? _e : true;
|
|
311
312
|
let sentinelInjected = false;
|
|
312
313
|
const missingSignatureToolNames = [];
|
|
313
314
|
const injectSkipSignature = (toolName) => {
|
|
@@ -424,7 +425,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
424
425
|
}
|
|
425
426
|
return {
|
|
426
427
|
functionCall: {
|
|
427
|
-
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
428
|
+
...includeFunctionCallIds && part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
428
429
|
name: part.toolName,
|
|
429
430
|
args: part.input
|
|
430
431
|
},
|
|
@@ -488,24 +489,26 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
488
489
|
parts,
|
|
489
490
|
part.toolName,
|
|
490
491
|
output.value,
|
|
491
|
-
part.toolCallId
|
|
492
|
+
part.toolCallId,
|
|
493
|
+
includeFunctionCallIds
|
|
492
494
|
);
|
|
493
495
|
} else {
|
|
494
496
|
appendLegacyToolResultParts(
|
|
495
497
|
parts,
|
|
496
498
|
part.toolName,
|
|
497
499
|
output.value,
|
|
498
|
-
part.toolCallId
|
|
500
|
+
part.toolCallId,
|
|
501
|
+
includeFunctionCallIds
|
|
499
502
|
);
|
|
500
503
|
}
|
|
501
504
|
} else {
|
|
502
505
|
parts.push({
|
|
503
506
|
functionResponse: {
|
|
504
|
-
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
507
|
+
...includeFunctionCallIds && part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
505
508
|
name: part.toolName,
|
|
506
509
|
response: {
|
|
507
510
|
name: part.toolName,
|
|
508
|
-
content: output.type === "execution-denied" ? (
|
|
511
|
+
content: output.type === "execution-denied" ? (_f = output.reason) != null ? _f : "Tool call execution denied." : output.value
|
|
509
512
|
}
|
|
510
513
|
}
|
|
511
514
|
});
|
|
@@ -755,6 +758,27 @@ var googleLanguageModelOptions = lazySchema2(
|
|
|
755
758
|
)
|
|
756
759
|
);
|
|
757
760
|
|
|
761
|
+
// src/google-model-capabilities.ts
|
|
762
|
+
var gemini1ModelPattern = /(^|\/)gemini-1(?:[.-]|$)/i;
|
|
763
|
+
var gemini2ModelPattern = /(^|\/)gemini-2(?:[.-]|$)/i;
|
|
764
|
+
var gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
765
|
+
var geminiModelPattern = /(^|\/)gemini-/i;
|
|
766
|
+
function isKnownPreGemini2Model(modelId) {
|
|
767
|
+
return gemini1ModelPattern.test(modelId) || /(^|\/)gemini-pro(?:-vision)?$/i.test(modelId) || /(^|\/)gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId);
|
|
768
|
+
}
|
|
769
|
+
function getGoogleModelCapabilities(modelId) {
|
|
770
|
+
const isGeminiModel = geminiModelPattern.test(modelId);
|
|
771
|
+
const isGemini2Model = gemini2ModelPattern.test(modelId);
|
|
772
|
+
const isKnownPreGemini2 = isKnownPreGemini2Model(modelId);
|
|
773
|
+
const isKnownOlderModel = isKnownPreGemini2 || isGemini2Model;
|
|
774
|
+
const usesGemini3Features = isGeminiModel && !isKnownOlderModel;
|
|
775
|
+
return {
|
|
776
|
+
supportsGemini2Tools: isGeminiModel && !isKnownPreGemini2 || modelId.toLowerCase().includes("nano-banana"),
|
|
777
|
+
supportsFileSearch: gemini25ModelPattern.test(modelId) || usesGemini3Features,
|
|
778
|
+
usesGemini3Features
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
|
|
758
782
|
// src/google-prepare-tools.ts
|
|
759
783
|
import {
|
|
760
784
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
@@ -768,20 +792,13 @@ function prepareTools({
|
|
|
768
792
|
var _a, _b;
|
|
769
793
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
770
794
|
const toolWarnings = [];
|
|
771
|
-
const
|
|
772
|
-
"gemini-flash-latest",
|
|
773
|
-
"gemini-flash-lite-latest",
|
|
774
|
-
"gemini-pro-latest"
|
|
775
|
-
].some((id) => id === modelId);
|
|
776
|
-
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
777
|
-
const isGemini3orNewer = modelId.includes("gemini-3");
|
|
778
|
-
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
795
|
+
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
779
796
|
if (tools == null) {
|
|
780
797
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
781
798
|
}
|
|
782
799
|
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
|
783
800
|
const hasProviderTools = tools.some((tool) => tool.type === "provider");
|
|
784
|
-
if (hasFunctionTools && hasProviderTools && !
|
|
801
|
+
if (hasFunctionTools && hasProviderTools && !usesGemini3Features) {
|
|
785
802
|
toolWarnings.push({
|
|
786
803
|
type: "unsupported",
|
|
787
804
|
feature: `combination of function and provider-defined tools`
|
|
@@ -793,7 +810,7 @@ function prepareTools({
|
|
|
793
810
|
ProviderTools.forEach((tool) => {
|
|
794
811
|
switch (tool.id) {
|
|
795
812
|
case "google.google_search":
|
|
796
|
-
if (
|
|
813
|
+
if (supportsGemini2Tools) {
|
|
797
814
|
googleTools2.push({ googleSearch: { ...tool.args } });
|
|
798
815
|
} else {
|
|
799
816
|
toolWarnings.push({
|
|
@@ -804,7 +821,7 @@ function prepareTools({
|
|
|
804
821
|
}
|
|
805
822
|
break;
|
|
806
823
|
case "google.enterprise_web_search":
|
|
807
|
-
if (
|
|
824
|
+
if (supportsGemini2Tools) {
|
|
808
825
|
googleTools2.push({ enterpriseWebSearch: {} });
|
|
809
826
|
} else {
|
|
810
827
|
toolWarnings.push({
|
|
@@ -815,7 +832,7 @@ function prepareTools({
|
|
|
815
832
|
}
|
|
816
833
|
break;
|
|
817
834
|
case "google.url_context":
|
|
818
|
-
if (
|
|
835
|
+
if (supportsGemini2Tools) {
|
|
819
836
|
googleTools2.push({ urlContext: {} });
|
|
820
837
|
} else {
|
|
821
838
|
toolWarnings.push({
|
|
@@ -826,7 +843,7 @@ function prepareTools({
|
|
|
826
843
|
}
|
|
827
844
|
break;
|
|
828
845
|
case "google.code_execution":
|
|
829
|
-
if (
|
|
846
|
+
if (supportsGemini2Tools) {
|
|
830
847
|
googleTools2.push({ codeExecution: {} });
|
|
831
848
|
} else {
|
|
832
849
|
toolWarnings.push({
|
|
@@ -848,7 +865,7 @@ function prepareTools({
|
|
|
848
865
|
}
|
|
849
866
|
break;
|
|
850
867
|
case "google.vertex_rag_store":
|
|
851
|
-
if (
|
|
868
|
+
if (supportsGemini2Tools) {
|
|
852
869
|
googleTools2.push({
|
|
853
870
|
retrieval: {
|
|
854
871
|
vertex_rag_store: {
|
|
@@ -868,7 +885,7 @@ function prepareTools({
|
|
|
868
885
|
}
|
|
869
886
|
break;
|
|
870
887
|
case "google.google_maps":
|
|
871
|
-
if (
|
|
888
|
+
if (supportsGemini2Tools) {
|
|
872
889
|
googleTools2.push({ googleMaps: {} });
|
|
873
890
|
} else {
|
|
874
891
|
toolWarnings.push({
|
|
@@ -886,7 +903,7 @@ function prepareTools({
|
|
|
886
903
|
break;
|
|
887
904
|
}
|
|
888
905
|
});
|
|
889
|
-
if (hasFunctionTools &&
|
|
906
|
+
if (hasFunctionTools && usesGemini3Features && googleTools2.length > 0) {
|
|
890
907
|
const functionDeclarations2 = [];
|
|
891
908
|
for (const tool of tools) {
|
|
892
909
|
if (tool.type === "function") {
|
|
@@ -1383,16 +1400,16 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1383
1400
|
}
|
|
1384
1401
|
}
|
|
1385
1402
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1386
|
-
const
|
|
1387
|
-
const supportsFunctionResponseParts = isGemini3Model;
|
|
1403
|
+
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1388
1404
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1389
1405
|
prompt,
|
|
1390
1406
|
{
|
|
1391
1407
|
isGemmaModel,
|
|
1392
|
-
isGemini3Model,
|
|
1408
|
+
isGemini3Model: usesGemini3Features,
|
|
1393
1409
|
providerOptionsName,
|
|
1394
|
-
supportsFunctionResponseParts,
|
|
1395
|
-
onWarning: (warning) => warnings.push(warning)
|
|
1410
|
+
supportsFunctionResponseParts: usesGemini3Features,
|
|
1411
|
+
onWarning: (warning) => warnings.push(warning),
|
|
1412
|
+
includeFunctionCallIds: !isVertexProvider
|
|
1396
1413
|
}
|
|
1397
1414
|
);
|
|
1398
1415
|
const {
|