@ai-sdk/google 3.0.99 → 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 +6 -0
- package/dist/index.js +34 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -21
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +33 -20
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +33 -20
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +16 -6
- package/package.json +1 -1
- 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/internal/index.js
CHANGED
|
@@ -766,6 +766,27 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
|
|
|
766
766
|
)
|
|
767
767
|
);
|
|
768
768
|
|
|
769
|
+
// src/google-model-capabilities.ts
|
|
770
|
+
var gemini1ModelPattern = /(^|\/)gemini-1(?:[.-]|$)/i;
|
|
771
|
+
var gemini2ModelPattern = /(^|\/)gemini-2(?:[.-]|$)/i;
|
|
772
|
+
var gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
773
|
+
var geminiModelPattern = /(^|\/)gemini-/i;
|
|
774
|
+
function isKnownPreGemini2Model(modelId) {
|
|
775
|
+
return gemini1ModelPattern.test(modelId) || /(^|\/)gemini-pro(?:-vision)?$/i.test(modelId) || /(^|\/)gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId);
|
|
776
|
+
}
|
|
777
|
+
function getGoogleModelCapabilities(modelId) {
|
|
778
|
+
const isGeminiModel = geminiModelPattern.test(modelId);
|
|
779
|
+
const isGemini2Model = gemini2ModelPattern.test(modelId);
|
|
780
|
+
const isKnownPreGemini2 = isKnownPreGemini2Model(modelId);
|
|
781
|
+
const isKnownOlderModel = isKnownPreGemini2 || isGemini2Model;
|
|
782
|
+
const usesGemini3Features = isGeminiModel && !isKnownOlderModel;
|
|
783
|
+
return {
|
|
784
|
+
supportsGemini2Tools: isGeminiModel && !isKnownPreGemini2 || modelId.toLowerCase().includes("nano-banana"),
|
|
785
|
+
supportsFileSearch: gemini25ModelPattern.test(modelId) || usesGemini3Features,
|
|
786
|
+
usesGemini3Features
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
|
|
769
790
|
// src/google-prepare-tools.ts
|
|
770
791
|
var import_provider2 = require("@ai-sdk/provider");
|
|
771
792
|
function prepareTools({
|
|
@@ -777,20 +798,13 @@ function prepareTools({
|
|
|
777
798
|
var _a, _b;
|
|
778
799
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
779
800
|
const toolWarnings = [];
|
|
780
|
-
const
|
|
781
|
-
"gemini-flash-latest",
|
|
782
|
-
"gemini-flash-lite-latest",
|
|
783
|
-
"gemini-pro-latest"
|
|
784
|
-
].some((id) => id === modelId);
|
|
785
|
-
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
786
|
-
const isGemini3orNewer = modelId.includes("gemini-3");
|
|
787
|
-
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
801
|
+
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
788
802
|
if (tools == null) {
|
|
789
803
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
790
804
|
}
|
|
791
805
|
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
|
792
806
|
const hasProviderTools = tools.some((tool) => tool.type === "provider");
|
|
793
|
-
if (hasFunctionTools && hasProviderTools && !
|
|
807
|
+
if (hasFunctionTools && hasProviderTools && !usesGemini3Features) {
|
|
794
808
|
toolWarnings.push({
|
|
795
809
|
type: "unsupported",
|
|
796
810
|
feature: `combination of function and provider-defined tools`
|
|
@@ -802,7 +816,7 @@ function prepareTools({
|
|
|
802
816
|
ProviderTools.forEach((tool) => {
|
|
803
817
|
switch (tool.id) {
|
|
804
818
|
case "google.google_search":
|
|
805
|
-
if (
|
|
819
|
+
if (supportsGemini2Tools) {
|
|
806
820
|
googleTools2.push({ googleSearch: { ...tool.args } });
|
|
807
821
|
} else {
|
|
808
822
|
toolWarnings.push({
|
|
@@ -813,7 +827,7 @@ function prepareTools({
|
|
|
813
827
|
}
|
|
814
828
|
break;
|
|
815
829
|
case "google.enterprise_web_search":
|
|
816
|
-
if (
|
|
830
|
+
if (supportsGemini2Tools) {
|
|
817
831
|
googleTools2.push({ enterpriseWebSearch: {} });
|
|
818
832
|
} else {
|
|
819
833
|
toolWarnings.push({
|
|
@@ -824,7 +838,7 @@ function prepareTools({
|
|
|
824
838
|
}
|
|
825
839
|
break;
|
|
826
840
|
case "google.url_context":
|
|
827
|
-
if (
|
|
841
|
+
if (supportsGemini2Tools) {
|
|
828
842
|
googleTools2.push({ urlContext: {} });
|
|
829
843
|
} else {
|
|
830
844
|
toolWarnings.push({
|
|
@@ -835,7 +849,7 @@ function prepareTools({
|
|
|
835
849
|
}
|
|
836
850
|
break;
|
|
837
851
|
case "google.code_execution":
|
|
838
|
-
if (
|
|
852
|
+
if (supportsGemini2Tools) {
|
|
839
853
|
googleTools2.push({ codeExecution: {} });
|
|
840
854
|
} else {
|
|
841
855
|
toolWarnings.push({
|
|
@@ -857,7 +871,7 @@ function prepareTools({
|
|
|
857
871
|
}
|
|
858
872
|
break;
|
|
859
873
|
case "google.vertex_rag_store":
|
|
860
|
-
if (
|
|
874
|
+
if (supportsGemini2Tools) {
|
|
861
875
|
googleTools2.push({
|
|
862
876
|
retrieval: {
|
|
863
877
|
vertex_rag_store: {
|
|
@@ -877,7 +891,7 @@ function prepareTools({
|
|
|
877
891
|
}
|
|
878
892
|
break;
|
|
879
893
|
case "google.google_maps":
|
|
880
|
-
if (
|
|
894
|
+
if (supportsGemini2Tools) {
|
|
881
895
|
googleTools2.push({ googleMaps: {} });
|
|
882
896
|
} else {
|
|
883
897
|
toolWarnings.push({
|
|
@@ -895,7 +909,7 @@ function prepareTools({
|
|
|
895
909
|
break;
|
|
896
910
|
}
|
|
897
911
|
});
|
|
898
|
-
if (hasFunctionTools &&
|
|
912
|
+
if (hasFunctionTools && usesGemini3Features && googleTools2.length > 0) {
|
|
899
913
|
const functionDeclarations2 = [];
|
|
900
914
|
for (const tool of tools) {
|
|
901
915
|
if (tool.type === "function") {
|
|
@@ -1392,15 +1406,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1392
1406
|
}
|
|
1393
1407
|
}
|
|
1394
1408
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1395
|
-
const
|
|
1396
|
-
const supportsFunctionResponseParts = isGemini3Model;
|
|
1409
|
+
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1397
1410
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1398
1411
|
prompt,
|
|
1399
1412
|
{
|
|
1400
1413
|
isGemmaModel,
|
|
1401
|
-
isGemini3Model,
|
|
1414
|
+
isGemini3Model: usesGemini3Features,
|
|
1402
1415
|
providerOptionsName,
|
|
1403
|
-
supportsFunctionResponseParts,
|
|
1416
|
+
supportsFunctionResponseParts: usesGemini3Features,
|
|
1404
1417
|
onWarning: (warning) => warnings.push(warning)
|
|
1405
1418
|
}
|
|
1406
1419
|
);
|