@ai-sdk/google 2.0.84 → 2.0.85
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 +95 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -26
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +94 -25
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +94 -25
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
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 ? "2.0.
|
|
10
|
+
var VERSION = true ? "2.0.85" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-generative-ai-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -365,13 +365,15 @@ import {
|
|
|
365
365
|
UnsupportedFunctionalityError
|
|
366
366
|
} from "@ai-sdk/provider";
|
|
367
367
|
import { convertToBase64 } from "@ai-sdk/provider-utils";
|
|
368
|
+
var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
|
|
368
369
|
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
369
|
-
var _a, _b;
|
|
370
|
+
var _a, _b, _c;
|
|
370
371
|
const systemInstructionParts = [];
|
|
371
372
|
const contents = [];
|
|
372
373
|
let systemMessagesAllowed = true;
|
|
373
374
|
const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
|
|
374
|
-
const
|
|
375
|
+
const isGemini3Model = (_b = options == null ? void 0 : options.isGemini3Model) != null ? _b : false;
|
|
376
|
+
const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
|
|
375
377
|
for (const { role, content } of prompt) {
|
|
376
378
|
switch (role) {
|
|
377
379
|
case "system": {
|
|
@@ -416,11 +418,12 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
416
418
|
}
|
|
417
419
|
case "assistant": {
|
|
418
420
|
systemMessagesAllowed = false;
|
|
421
|
+
let modelResponseHasSignedFunctionCall = false;
|
|
419
422
|
contents.push({
|
|
420
423
|
role: "model",
|
|
421
424
|
parts: content.map((part) => {
|
|
422
|
-
var _a2, _b2,
|
|
423
|
-
const thoughtSignature = ((_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b2.thoughtSignature) != null ? String((
|
|
425
|
+
var _a2, _b2, _c2;
|
|
426
|
+
const thoughtSignature = ((_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b2.thoughtSignature) != null ? String((_c2 = part.providerOptions.google) == null ? void 0 : _c2.thoughtSignature) : void 0;
|
|
424
427
|
switch (part.type) {
|
|
425
428
|
case "text": {
|
|
426
429
|
return part.text.length === 0 ? void 0 : {
|
|
@@ -454,13 +457,17 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
454
457
|
};
|
|
455
458
|
}
|
|
456
459
|
case "tool-call": {
|
|
460
|
+
const effectiveThoughtSignature = thoughtSignature != null ? thoughtSignature : isGemini3Model && !modelResponseHasSignedFunctionCall ? SKIP_THOUGHT_SIGNATURE_VALIDATOR : void 0;
|
|
461
|
+
if (thoughtSignature != null) {
|
|
462
|
+
modelResponseHasSignedFunctionCall = true;
|
|
463
|
+
}
|
|
457
464
|
return {
|
|
458
465
|
functionCall: {
|
|
459
466
|
...part.toolCallId != null ? { id: part.toolCallId } : {},
|
|
460
467
|
name: part.toolName,
|
|
461
468
|
args: part.input
|
|
462
469
|
},
|
|
463
|
-
thoughtSignature
|
|
470
|
+
thoughtSignature: effectiveThoughtSignature
|
|
464
471
|
};
|
|
465
472
|
}
|
|
466
473
|
}
|
|
@@ -753,6 +760,27 @@ var VertexServiceTierMap = {
|
|
|
753
760
|
priority: "SERVICE_TIER_PRIORITY"
|
|
754
761
|
};
|
|
755
762
|
|
|
763
|
+
// src/google-model-capabilities.ts
|
|
764
|
+
var gemini1ModelPattern = /(^|\/)gemini-1(?:[.-]|$)/i;
|
|
765
|
+
var gemini2ModelPattern = /(^|\/)gemini-2(?:[.-]|$)/i;
|
|
766
|
+
var gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
767
|
+
var geminiModelPattern = /(^|\/)gemini-/i;
|
|
768
|
+
function isKnownPreGemini2Model(modelId) {
|
|
769
|
+
return gemini1ModelPattern.test(modelId) || /(^|\/)gemini-pro(?:-vision)?$/i.test(modelId) || /(^|\/)gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId);
|
|
770
|
+
}
|
|
771
|
+
function getGoogleModelCapabilities(modelId) {
|
|
772
|
+
const isGeminiModel = geminiModelPattern.test(modelId);
|
|
773
|
+
const isGemini2Model = gemini2ModelPattern.test(modelId);
|
|
774
|
+
const isKnownPreGemini2 = isKnownPreGemini2Model(modelId);
|
|
775
|
+
const isKnownOlderModel = isKnownPreGemini2 || isGemini2Model;
|
|
776
|
+
const usesGemini3Features = isGeminiModel && !isKnownOlderModel;
|
|
777
|
+
return {
|
|
778
|
+
supportsGemini2Tools: isGeminiModel && !isKnownPreGemini2 || modelId.toLowerCase().includes("nano-banana"),
|
|
779
|
+
supportsFileSearch: gemini25ModelPattern.test(modelId) || usesGemini3Features,
|
|
780
|
+
usesGemini3Features
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
|
|
756
784
|
// src/google-prepare-tools.ts
|
|
757
785
|
import {
|
|
758
786
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
@@ -760,18 +788,13 @@ import {
|
|
|
760
788
|
function prepareTools({
|
|
761
789
|
tools,
|
|
762
790
|
toolChoice,
|
|
763
|
-
modelId
|
|
791
|
+
modelId,
|
|
792
|
+
isVertexProvider = false
|
|
764
793
|
}) {
|
|
765
|
-
var _a;
|
|
794
|
+
var _a, _b;
|
|
766
795
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
767
796
|
const toolWarnings = [];
|
|
768
|
-
const
|
|
769
|
-
"gemini-flash-latest",
|
|
770
|
-
"gemini-flash-lite-latest",
|
|
771
|
-
"gemini-pro-latest"
|
|
772
|
-
].some((id) => id === modelId);
|
|
773
|
-
const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
|
|
774
|
-
const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
|
|
797
|
+
const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = getGoogleModelCapabilities(modelId);
|
|
775
798
|
if (tools == null) {
|
|
776
799
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
777
800
|
}
|
|
@@ -779,7 +802,7 @@ function prepareTools({
|
|
|
779
802
|
const hasProviderDefinedTools = tools.some(
|
|
780
803
|
(tool) => tool.type === "provider-defined"
|
|
781
804
|
);
|
|
782
|
-
if (hasFunctionTools && hasProviderDefinedTools) {
|
|
805
|
+
if (hasFunctionTools && hasProviderDefinedTools && !usesGemini3Features) {
|
|
783
806
|
const functionTools = tools.filter((tool) => tool.type === "function");
|
|
784
807
|
toolWarnings.push({
|
|
785
808
|
type: "unsupported-tool",
|
|
@@ -795,7 +818,7 @@ function prepareTools({
|
|
|
795
818
|
providerDefinedTools.forEach((tool) => {
|
|
796
819
|
switch (tool.id) {
|
|
797
820
|
case "google.google_search":
|
|
798
|
-
if (
|
|
821
|
+
if (supportsGemini2Tools) {
|
|
799
822
|
googleTools2.push({ googleSearch: { ...tool.args } });
|
|
800
823
|
} else {
|
|
801
824
|
toolWarnings.push({
|
|
@@ -806,7 +829,7 @@ function prepareTools({
|
|
|
806
829
|
}
|
|
807
830
|
break;
|
|
808
831
|
case "google.enterprise_web_search":
|
|
809
|
-
if (
|
|
832
|
+
if (supportsGemini2Tools) {
|
|
810
833
|
googleTools2.push({ enterpriseWebSearch: {} });
|
|
811
834
|
} else {
|
|
812
835
|
toolWarnings.push({
|
|
@@ -817,7 +840,7 @@ function prepareTools({
|
|
|
817
840
|
}
|
|
818
841
|
break;
|
|
819
842
|
case "google.url_context":
|
|
820
|
-
if (
|
|
843
|
+
if (supportsGemini2Tools) {
|
|
821
844
|
googleTools2.push({ urlContext: {} });
|
|
822
845
|
} else {
|
|
823
846
|
toolWarnings.push({
|
|
@@ -828,7 +851,7 @@ function prepareTools({
|
|
|
828
851
|
}
|
|
829
852
|
break;
|
|
830
853
|
case "google.code_execution":
|
|
831
|
-
if (
|
|
854
|
+
if (supportsGemini2Tools) {
|
|
832
855
|
googleTools2.push({ codeExecution: {} });
|
|
833
856
|
} else {
|
|
834
857
|
toolWarnings.push({
|
|
@@ -850,7 +873,7 @@ function prepareTools({
|
|
|
850
873
|
}
|
|
851
874
|
break;
|
|
852
875
|
case "google.vertex_rag_store":
|
|
853
|
-
if (
|
|
876
|
+
if (supportsGemini2Tools) {
|
|
854
877
|
googleTools2.push({
|
|
855
878
|
retrieval: {
|
|
856
879
|
vertex_rag_store: {
|
|
@@ -870,7 +893,7 @@ function prepareTools({
|
|
|
870
893
|
}
|
|
871
894
|
break;
|
|
872
895
|
case "google.google_maps":
|
|
873
|
-
if (
|
|
896
|
+
if (supportsGemini2Tools) {
|
|
874
897
|
googleTools2.push({ googleMaps: {} });
|
|
875
898
|
} else {
|
|
876
899
|
toolWarnings.push({
|
|
@@ -885,6 +908,47 @@ function prepareTools({
|
|
|
885
908
|
break;
|
|
886
909
|
}
|
|
887
910
|
});
|
|
911
|
+
if (hasFunctionTools && usesGemini3Features && googleTools2.length > 0) {
|
|
912
|
+
const functionDeclarations2 = [];
|
|
913
|
+
for (const tool of tools) {
|
|
914
|
+
if (tool.type === "function") {
|
|
915
|
+
functionDeclarations2.push({
|
|
916
|
+
name: tool.name,
|
|
917
|
+
description: (_a = tool.description) != null ? _a : "",
|
|
918
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
const combinedToolConfig = {
|
|
923
|
+
functionCallingConfig: { mode: "VALIDATED" },
|
|
924
|
+
...!isVertexProvider && {
|
|
925
|
+
includeServerSideToolInvocations: true
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
if (toolChoice != null) {
|
|
929
|
+
switch (toolChoice.type) {
|
|
930
|
+
case "auto":
|
|
931
|
+
break;
|
|
932
|
+
case "none":
|
|
933
|
+
combinedToolConfig.functionCallingConfig = { mode: "NONE" };
|
|
934
|
+
break;
|
|
935
|
+
case "required":
|
|
936
|
+
combinedToolConfig.functionCallingConfig = { mode: "ANY" };
|
|
937
|
+
break;
|
|
938
|
+
case "tool":
|
|
939
|
+
combinedToolConfig.functionCallingConfig = {
|
|
940
|
+
mode: "ANY",
|
|
941
|
+
allowedFunctionNames: [toolChoice.toolName]
|
|
942
|
+
};
|
|
943
|
+
break;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
return {
|
|
947
|
+
tools: [...googleTools2, { functionDeclarations: functionDeclarations2 }],
|
|
948
|
+
toolConfig: combinedToolConfig,
|
|
949
|
+
toolWarnings
|
|
950
|
+
};
|
|
951
|
+
}
|
|
888
952
|
return {
|
|
889
953
|
tools: googleTools2.length > 0 ? googleTools2 : void 0,
|
|
890
954
|
toolConfig: void 0,
|
|
@@ -898,7 +962,7 @@ function prepareTools({
|
|
|
898
962
|
case "function":
|
|
899
963
|
functionDeclarations.push({
|
|
900
964
|
name: tool.name,
|
|
901
|
-
description: (
|
|
965
|
+
description: (_b = tool.description) != null ? _b : "",
|
|
902
966
|
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
|
903
967
|
});
|
|
904
968
|
if (tool.strict === true) {
|
|
@@ -1076,10 +1140,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1076
1140
|
threshold: safetyThreshold
|
|
1077
1141
|
})) : void 0;
|
|
1078
1142
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1079
|
-
const
|
|
1143
|
+
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1080
1144
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
1081
1145
|
prompt,
|
|
1082
|
-
{
|
|
1146
|
+
{
|
|
1147
|
+
isGemmaModel,
|
|
1148
|
+
isGemini3Model: usesGemini3Features,
|
|
1149
|
+
supportsFunctionResponseParts: usesGemini3Features
|
|
1150
|
+
}
|
|
1083
1151
|
);
|
|
1084
1152
|
const {
|
|
1085
1153
|
tools: googleTools2,
|
|
@@ -1088,7 +1156,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
1088
1156
|
} = prepareTools({
|
|
1089
1157
|
tools,
|
|
1090
1158
|
toolChoice,
|
|
1091
|
-
modelId: this.modelId
|
|
1159
|
+
modelId: this.modelId,
|
|
1160
|
+
isVertexProvider
|
|
1092
1161
|
});
|
|
1093
1162
|
return {
|
|
1094
1163
|
args: {
|