@ai-sdk/google 4.0.108 → 4.0.109
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 +15 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +185 -73
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +172 -59
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +9 -1
- package/package.json +3 -3
- package/src/google-batch.ts +3 -4
- package/src/google-embedding-model.ts +2 -1
- package/src/google-files.ts +7 -7
- package/src/google-language-model.ts +33 -86
- package/src/google-model-capabilities.ts +7 -40
- package/src/google-model-catalog.ts +319 -0
- package/src/google-provider.ts +15 -11
- package/src/interactions/cancel-google-interaction.ts +7 -2
- package/src/interactions/google-interactions-language-model.ts +8 -12
- package/src/interactions/poll-google-interactions.ts +4 -2
- package/src/interactions/stream-google-interactions.ts +4 -7
- package/src/realtime/google-realtime-model.ts +7 -3
- package/src/speech-translation/google-speech-translation-model.ts +7 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["_$__google_prompt0.GoogleContent","_$__google_prompt0.GoogleSystemInstruction"],"sources":["../../src/google-prompt.ts","../../src/google-language-model-options.ts","../../src/google-language-model.ts","../../src/google-speech-model-options.ts","../../src/google-speech-model.ts","../../src/google-speech-input.ts","../../src/google-tools.ts","../../src/interactions/google-interactions-language-model-options.ts","../../src/interactions/google-interactions-language-model.ts","../../src/interactions/google-interactions-agent.ts"],"mappings":";;;;KAcY;EACV,OAAO;IAAQ;;;KAGL;EACV;EACA,OAAO,MAAM;;cAGF,2BAAyB,EAAA;;;;GAOpC,EAAA,KAAA;;KAGU,sBAAsB,EAAE,aAAa;KAErC;EACN;EAAc;EAAmB;;EAEjC;IAAc;IAAkB;;EAChC,gBAAgB;EAChB;EACA;;EAGA;IAAgB;IAAa;IAAc;;EAC3C;;EAGA;IACE;IACA;IACA;IACA,QAAQ,MAAM;;;EAIhB;IAAY;IAAkB;;EAC9B,gBAAgB;EAChB;EACA;;EAGA;IACE;IACA;IACA;;EAEF;;EAGA;IACE;IACA;IACA;;EAEF;;EAGA;IACE;IACA;;;EAIF;IACE;IACA;;;KAII;EAEN;IAAc;IAAkB;;;EAGhC;IAAY;IAAkB;;;;;KCxFxB;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["_$__google_prompt0.GoogleContent","_$__google_prompt0.GoogleSystemInstruction"],"sources":["../../src/google-prompt.ts","../../src/google-language-model-options.ts","../../src/google-language-model.ts","../../src/google-speech-model-options.ts","../../src/google-speech-model.ts","../../src/google-speech-input.ts","../../src/google-tools.ts","../../src/interactions/google-interactions-language-model-options.ts","../../src/interactions/google-interactions-language-model.ts","../../src/interactions/google-interactions-agent.ts"],"mappings":"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"}
|
package/dist/internal/index.js
CHANGED
|
@@ -854,11 +854,129 @@ const googleLanguageModelOptions = lazySchema(() => zodSchema(z.object({
|
|
|
854
854
|
requestType: z.enum(["shared"]).optional()
|
|
855
855
|
})));
|
|
856
856
|
//#endregion
|
|
857
|
-
//#region src/google-model-
|
|
857
|
+
//#region src/google-model-catalog.ts
|
|
858
858
|
const gemini1ModelPattern = /(^|[/.])gemini-1(?:[.-]|$)/i;
|
|
859
859
|
const gemini2ModelPattern = /(^|[/.])gemini-2(?:[.-]|$)/i;
|
|
860
|
-
const gemini25ModelPattern
|
|
860
|
+
const gemini25ModelPattern = /(^|[/.])gemini-2\.5(?:[.-]|$)/i;
|
|
861
861
|
const geminiModelPattern = /(^|[/.])gemini-/i;
|
|
862
|
+
/** Options accepted under providerOptions.google (or googleVertex on Vertex). */
|
|
863
|
+
const googleProviderOptions = { language: {
|
|
864
|
+
responseModalities: { description: "Response modalities to generate." },
|
|
865
|
+
thinkingConfig: { description: "Thinking budget, level, and thought output." },
|
|
866
|
+
cachedContent: { description: "Cached content to use as request context." },
|
|
867
|
+
structuredOutputs: { description: "Whether to send the JSON response schema." },
|
|
868
|
+
safetySettings: { description: "Safety settings for the request." },
|
|
869
|
+
threshold: { description: "Default threshold for configurable safety categories." },
|
|
870
|
+
audioTimestamp: { description: "Enable timestamp understanding for audio." },
|
|
871
|
+
labels: { description: "Billing labels. Vertex AI only." },
|
|
872
|
+
mediaResolution: { description: "Resolution used to process media inputs." },
|
|
873
|
+
imageConfig: { description: "Image generation configuration." },
|
|
874
|
+
retrievalConfig: { description: "Retrieval configuration for tools." },
|
|
875
|
+
streamFunctionCallArguments: { description: "Stream function arguments. Vertex AI only." },
|
|
876
|
+
serviceTier: { description: "Service tier. Gemini API only." },
|
|
877
|
+
continuationToken: { description: "Resume a response using its continuation token." },
|
|
878
|
+
sharedRequestType: { description: "Shared PayGo tier. Vertex AI only." },
|
|
879
|
+
requestType: { description: "Request routing type. Vertex AI only." }
|
|
880
|
+
} };
|
|
881
|
+
const standard = {
|
|
882
|
+
image: true,
|
|
883
|
+
objectGeneration: true,
|
|
884
|
+
tools: true,
|
|
885
|
+
streaming: true,
|
|
886
|
+
googleSearch: true,
|
|
887
|
+
urlContext: true
|
|
888
|
+
};
|
|
889
|
+
const googleModelCatalog = Object.fromEntries(Object.entries({
|
|
890
|
+
"gemini-nano-banana-2.1": {
|
|
891
|
+
image: true,
|
|
892
|
+
objectGeneration: false,
|
|
893
|
+
tools: false,
|
|
894
|
+
streaming: false,
|
|
895
|
+
googleSearch: true,
|
|
896
|
+
urlContext: false
|
|
897
|
+
},
|
|
898
|
+
"gemini-4-argon": standard,
|
|
899
|
+
"gemini-3.8-flash": standard,
|
|
900
|
+
"gemini-3.7-flash": standard,
|
|
901
|
+
"gemini-3.6-flash": standard,
|
|
902
|
+
"gemini-3.5-flash": standard,
|
|
903
|
+
"gemini-3.5-flash-lite": standard,
|
|
904
|
+
"gemini-3.1-pro-preview": standard,
|
|
905
|
+
"gemini-3.1-flash-image-preview": standard,
|
|
906
|
+
"gemini-3.1-flash-lite-preview": standard,
|
|
907
|
+
"gemini-3-pro-preview": standard,
|
|
908
|
+
"gemini-3-pro-image-preview": standard,
|
|
909
|
+
"gemini-3-flash-preview": standard,
|
|
910
|
+
"gemini-2.5-pro": standard,
|
|
911
|
+
"gemini-2.5-flash": standard,
|
|
912
|
+
"gemini-2.5-flash-lite": standard,
|
|
913
|
+
"gemini-2.5-flash-lite-preview-06-17": standard,
|
|
914
|
+
"gemini-2.0-flash": standard
|
|
915
|
+
}).map(([modelId, documented]) => [modelId, createGoogleLanguageModelEntry(modelId, documented)]));
|
|
916
|
+
function getGoogleLanguageModelEntry(modelId) {
|
|
917
|
+
return Object.prototype.hasOwnProperty.call(googleModelCatalog, modelId) ? googleModelCatalog[modelId] : createGoogleLanguageModelEntry(modelId);
|
|
918
|
+
}
|
|
919
|
+
function createGoogleLanguageModelEntry(modelId, documented) {
|
|
920
|
+
const runtime = resolveRuntimeDefinition(modelId);
|
|
921
|
+
const declared = documented != null;
|
|
922
|
+
const id = modelId.toLowerCase();
|
|
923
|
+
const thinkingFormat = runtime.usesGemini3Features && !modelId.includes("gemini-3-pro-image") ? "level" : "budget";
|
|
924
|
+
const minLevel = getMinimumThinkingLevelForGemini3Model(modelId);
|
|
925
|
+
return {
|
|
926
|
+
capabilities: { language: {
|
|
927
|
+
inputs: {
|
|
928
|
+
image: documented?.image ?? "unknown",
|
|
929
|
+
audio: "unknown"
|
|
930
|
+
},
|
|
931
|
+
objectGeneration: documented?.objectGeneration ?? "unknown",
|
|
932
|
+
tools: {
|
|
933
|
+
usage: documented?.tools ?? "unknown",
|
|
934
|
+
streaming: documented?.streaming ?? "unknown",
|
|
935
|
+
gemini2: runtime.supportsGemini2Tools,
|
|
936
|
+
googleSearch: documented?.googleSearch ?? "unknown",
|
|
937
|
+
urlContext: documented?.urlContext ?? "unknown",
|
|
938
|
+
fileSearch: runtime.supportsFileSearch,
|
|
939
|
+
mixed: runtime.usesGemini3Features,
|
|
940
|
+
functionResponseParts: runtime.usesGemini3Features
|
|
941
|
+
},
|
|
942
|
+
reasoning: {
|
|
943
|
+
support: "unknown",
|
|
944
|
+
efforts: thinkingFormat === "level" ? [
|
|
945
|
+
...minLevel === "minimal" ? ["minimal"] : [],
|
|
946
|
+
"low",
|
|
947
|
+
"medium",
|
|
948
|
+
"high"
|
|
949
|
+
] : void 0,
|
|
950
|
+
minBudget: id.includes("2.5-pro") ? 128 : 0,
|
|
951
|
+
maxBudget: id.includes("2.5-pro") || id.includes("gemini-3-pro-image") ? 32768 : 24576
|
|
952
|
+
},
|
|
953
|
+
sampling: {
|
|
954
|
+
temperature: "unknown",
|
|
955
|
+
topP: "unknown",
|
|
956
|
+
topK: "unknown",
|
|
957
|
+
logprobs: false,
|
|
958
|
+
penalties: gemini25ModelPattern.test(modelId) ? { condition: "Only supported on the Vertex AI API." } : true
|
|
959
|
+
},
|
|
960
|
+
structuredOutput: { withFunctionTools: runtime.usesGemini3Features }
|
|
961
|
+
} },
|
|
962
|
+
providerOptions: { language: declareProviderOptions(declared ? true : "unknown", {
|
|
963
|
+
labels: { condition: "Only supported on the Vertex AI API." },
|
|
964
|
+
sharedRequestType: { condition: "Only supported on the Vertex AI API." },
|
|
965
|
+
requestType: { condition: "Only supported on the Vertex AI API." },
|
|
966
|
+
serviceTier: { condition: "Only supported on the Gemini API." },
|
|
967
|
+
streamFunctionCallArguments: { condition: "Only supported for streaming requests on the Vertex AI API with Gemini 3 or newer." }
|
|
968
|
+
}) },
|
|
969
|
+
requestConfig: { language: {
|
|
970
|
+
systemInstruction: id.startsWith("gemma-") ? "user" : "system",
|
|
971
|
+
thinkingFormat,
|
|
972
|
+
reasoningMaxOutputTokens: 65536,
|
|
973
|
+
jsonResponseTool: /(^|\/)gemini-/i.test(modelId)
|
|
974
|
+
} }
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
function declareProviderOptions(support, exceptions) {
|
|
978
|
+
return Object.fromEntries(Object.keys(googleProviderOptions.language).map((option) => [option, exceptions[option] ?? support]));
|
|
979
|
+
}
|
|
862
980
|
function isKnownPreGemini2Model(modelId) {
|
|
863
981
|
return gemini1ModelPattern.test(modelId) || /(^|[/.])gemini-pro(?:-vision)?$/i.test(modelId) || /(^|[/.])gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId);
|
|
864
982
|
}
|
|
@@ -869,17 +987,39 @@ function isKnownPreGemini2Model(modelId) {
|
|
|
869
987
|
* intentionally inherit the newest supported behavior. Add exceptions here
|
|
870
988
|
* only when a model is known to require a legacy request shape.
|
|
871
989
|
*/
|
|
872
|
-
function
|
|
990
|
+
function resolveRuntimeDefinition(modelId) {
|
|
873
991
|
const isGeminiModel = geminiModelPattern.test(modelId);
|
|
874
992
|
const isGemini2Model = gemini2ModelPattern.test(modelId);
|
|
875
993
|
const isKnownPreGemini2 = isKnownPreGemini2Model(modelId);
|
|
876
994
|
const usesGemini3Features = isGeminiModel && !(isKnownPreGemini2 || isGemini2Model);
|
|
877
995
|
return {
|
|
878
996
|
supportsGemini2Tools: isGeminiModel && !isKnownPreGemini2 || modelId.toLowerCase().includes("nano-banana"),
|
|
879
|
-
supportsFileSearch: gemini25ModelPattern
|
|
997
|
+
supportsFileSearch: gemini25ModelPattern.test(modelId) || usesGemini3Features,
|
|
880
998
|
usesGemini3Features
|
|
881
999
|
};
|
|
882
1000
|
}
|
|
1001
|
+
function getMinimumThinkingLevelForGemini3Model(modelId) {
|
|
1002
|
+
const modelName = /(?:^|[/.])(gemini-[^/]*)$/i.exec(modelId)?.[1].toLowerCase();
|
|
1003
|
+
if (modelName === "gemini-flash-latest") return "low";
|
|
1004
|
+
const proVersionMatch = /^gemini-(\d+)(?:\.\d+)?-pro(?:$|-)/.exec(modelName ?? "");
|
|
1005
|
+
if (Number(proVersionMatch?.[1]) >= 3) return "low";
|
|
1006
|
+
const versionMatch = /^gemini-(\d+)\.(\d+)-flash(?:$|-(?!lite(?:-|$)))/.exec(modelName ?? "");
|
|
1007
|
+
if (versionMatch == null) return "minimal";
|
|
1008
|
+
const majorVersion = Number(versionMatch[1]);
|
|
1009
|
+
const minorVersion = Number(versionMatch[2]);
|
|
1010
|
+
return majorVersion > 3 || majorVersion === 3 && minorVersion >= 7 ? "low" : "minimal";
|
|
1011
|
+
}
|
|
1012
|
+
//#endregion
|
|
1013
|
+
//#region src/google-model-capabilities.ts
|
|
1014
|
+
/** Compatibility projection of the resolved catalog for existing request code. */
|
|
1015
|
+
function getGoogleModelCapabilities(modelId) {
|
|
1016
|
+
const { tools } = getGoogleLanguageModelEntry(modelId).capabilities.language;
|
|
1017
|
+
return {
|
|
1018
|
+
supportsGemini2Tools: tools.gemini2,
|
|
1019
|
+
supportsFileSearch: tools.fileSearch,
|
|
1020
|
+
usesGemini3Features: tools.mixed
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
883
1023
|
//#endregion
|
|
884
1024
|
//#region src/google-prepare-tools.ts
|
|
885
1025
|
function prepareTools({ tools, toolChoice, modelId, isVertexProvider = false }) {
|
|
@@ -1361,7 +1501,6 @@ const configurableSafetySettingCategories = [
|
|
|
1361
1501
|
"HARM_CATEGORY_HARASSMENT",
|
|
1362
1502
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
|
1363
1503
|
];
|
|
1364
|
-
const gemini25ModelPattern = /(^|[/.])gemini-2\.5(?:[.-]|$)/i;
|
|
1365
1504
|
const googleCloudStorageFunctionResponseUrls = {
|
|
1366
1505
|
"image/png": [/^gs:\/\/.*$/],
|
|
1367
1506
|
"image/jpeg": [/^gs:\/\/.*$/],
|
|
@@ -1446,8 +1585,9 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1446
1585
|
imageConfig = geminiApiImageConfig;
|
|
1447
1586
|
}
|
|
1448
1587
|
}
|
|
1449
|
-
const
|
|
1450
|
-
const
|
|
1588
|
+
const entry = getGoogleLanguageModelEntry(modelId);
|
|
1589
|
+
const isGemmaModel = entry.requestConfig.language.systemInstruction === "user";
|
|
1590
|
+
const isGemini25DeveloperApiModel = !isVertexProvider && entry.capabilities.language.sampling.penalties !== true;
|
|
1451
1591
|
if (isGemini25DeveloperApiModel && frequencyPenalty != null) warnings.push({
|
|
1452
1592
|
type: "unsupported",
|
|
1453
1593
|
feature: "frequencyPenalty"
|
|
@@ -1456,7 +1596,7 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1456
1596
|
type: "unsupported",
|
|
1457
1597
|
feature: "presencePenalty"
|
|
1458
1598
|
});
|
|
1459
|
-
const
|
|
1599
|
+
const usesGemini3Features = entry.capabilities.language.tools.functionResponseParts;
|
|
1460
1600
|
const supportedFunctionResponseUrls = usesGemini3Features && config.downloadToolResultFiles?.supportsGoogleCloudStorageUrls ? googleCloudStorageFunctionResponseUrls : void 0;
|
|
1461
1601
|
const { contents, systemInstruction } = convertToGoogleMessages(config.downloadToolResultFiles ? await downloadToolResultFiles(prompt, {
|
|
1462
1602
|
abortSignal,
|
|
@@ -1541,8 +1681,10 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1541
1681
|
}
|
|
1542
1682
|
async getArgs(options, { isStreaming = false } = {}) {
|
|
1543
1683
|
const { responseFormat, tools, toolChoice } = options;
|
|
1684
|
+
const entry = getGoogleLanguageModelEntry(this.modelId);
|
|
1685
|
+
const { structuredOutput } = entry.capabilities.language;
|
|
1544
1686
|
let jsonResponseTool;
|
|
1545
|
-
if (responseFormat?.type === "json" && responseFormat.schema != null && tools?.some((tool) => tool.type === "function") &&
|
|
1687
|
+
if (responseFormat?.type === "json" && responseFormat.schema != null && tools?.some((tool) => tool.type === "function") && entry.requestConfig.language.jsonResponseTool && (!structuredOutput.withFunctionTools || toolChoice?.type === "required" || toolChoice?.type === "tool")) {
|
|
1546
1688
|
let name = "json";
|
|
1547
1689
|
for (let suffix = 1; tools.some((tool) => tool.name === name); suffix++) name = `json_${suffix}`;
|
|
1548
1690
|
jsonResponseTool = {
|
|
@@ -1712,10 +1854,9 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1712
1854
|
}
|
|
1713
1855
|
async doGenerate(options) {
|
|
1714
1856
|
const { args, warnings, providerOptionsNames, extraHeaders, toolNameMapping, jsonResponseToolName } = await this.getArgs(options);
|
|
1715
|
-
const
|
|
1716
|
-
const generateContent = (body) => postJsonToApi({
|
|
1857
|
+
const generateContent = async (body) => postJsonToApi({
|
|
1717
1858
|
url: `${this.config.baseURL}/${getModelPath(this.modelId)}:generateContent`,
|
|
1718
|
-
headers:
|
|
1859
|
+
headers: combineHeaders(await resolve(this.config.headers), options.headers, extraHeaders),
|
|
1719
1860
|
body,
|
|
1720
1861
|
failedResponseHandler: googleFailedResponseHandler,
|
|
1721
1862
|
successfulResponseHandler: createJsonResponseHandler(responseSchema),
|
|
@@ -1778,10 +1919,9 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1778
1919
|
async doStream(options) {
|
|
1779
1920
|
const { args, warnings, providerOptionsNames, extraHeaders, toolNameMapping, jsonResponseToolName } = await this.getArgs(options, { isStreaming: true });
|
|
1780
1921
|
const wrapProviderMetadata = (payload) => Object.fromEntries(providerOptionsNames.map((name) => [name, payload]));
|
|
1781
|
-
const
|
|
1782
|
-
const streamGenerateContent = (body) => postJsonToApi({
|
|
1922
|
+
const streamGenerateContent = async (body) => postJsonToApi({
|
|
1783
1923
|
url: `${this.config.baseURL}/${getModelPath(this.modelId)}:streamGenerateContent?alt=sse`,
|
|
1784
|
-
headers,
|
|
1924
|
+
headers: combineHeaders(await resolve(this.config.headers), options.headers, extraHeaders),
|
|
1785
1925
|
body,
|
|
1786
1926
|
failedResponseHandler: googleFailedResponseHandler,
|
|
1787
1927
|
successfulResponseHandler: createEventSourceResponseHandler(chunkSchema),
|
|
@@ -2234,25 +2374,9 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
2234
2374
|
};
|
|
2235
2375
|
}
|
|
2236
2376
|
};
|
|
2237
|
-
function getMaxOutputTokensForGemini25Model() {
|
|
2238
|
-
return 65536;
|
|
2239
|
-
}
|
|
2240
|
-
function getMaxThinkingTokensForGemini25Model(modelId) {
|
|
2241
|
-
const id = modelId.toLowerCase();
|
|
2242
|
-
if (id.includes("2.5-pro") || id.includes("gemini-3-pro-image")) return 32768;
|
|
2243
|
-
return 24576;
|
|
2244
|
-
}
|
|
2245
|
-
/**
|
|
2246
|
-
* Gemini 2.5 Pro cannot disable thinking and requires a thinking budget of at
|
|
2247
|
-
* least 128 tokens. Other Gemini 2.5 models can disable thinking with a budget
|
|
2248
|
-
* of 0.
|
|
2249
|
-
*/
|
|
2250
|
-
function getMinThinkingTokensForGemini25Model(modelId) {
|
|
2251
|
-
return modelId.toLowerCase().includes("2.5-pro") ? 128 : 0;
|
|
2252
|
-
}
|
|
2253
2377
|
function resolveThinkingConfig({ reasoning, modelId, warnings }) {
|
|
2254
2378
|
if (!isCustomReasoning(reasoning)) return;
|
|
2255
|
-
if (
|
|
2379
|
+
if (getGoogleLanguageModelEntry(modelId).requestConfig.language.thinkingFormat === "level") return resolveGemini3ThinkingConfig({
|
|
2256
2380
|
reasoning,
|
|
2257
2381
|
modelId,
|
|
2258
2382
|
warnings
|
|
@@ -2264,7 +2388,7 @@ function resolveThinkingConfig({ reasoning, modelId, warnings }) {
|
|
|
2264
2388
|
});
|
|
2265
2389
|
}
|
|
2266
2390
|
function resolveGemini3ThinkingConfig({ reasoning, modelId, warnings }) {
|
|
2267
|
-
const minimumThinkingLevel =
|
|
2391
|
+
const minimumThinkingLevel = getGoogleLanguageModelEntry(modelId).capabilities.language.reasoning.efforts?.[0];
|
|
2268
2392
|
const thinkingLevel = mapReasoningToProviderEffort({
|
|
2269
2393
|
reasoning,
|
|
2270
2394
|
effortMap: {
|
|
@@ -2278,24 +2402,14 @@ function resolveGemini3ThinkingConfig({ reasoning, modelId, warnings }) {
|
|
|
2278
2402
|
if (thinkingLevel == null) return;
|
|
2279
2403
|
return { thinkingLevel };
|
|
2280
2404
|
}
|
|
2281
|
-
function getMinimumThinkingLevelForGemini3Model(modelId) {
|
|
2282
|
-
const modelName = /(?:^|[/.])(gemini-[^/]*)$/i.exec(modelId)?.[1].toLowerCase();
|
|
2283
|
-
if (modelName === "gemini-flash-latest") return "low";
|
|
2284
|
-
const proVersionMatch = /^gemini-(\d+)(?:\.\d+)?-pro(?:$|-)/.exec(modelName ?? "");
|
|
2285
|
-
if (Number(proVersionMatch?.[1]) >= 3) return "low";
|
|
2286
|
-
const versionMatch = /^gemini-(\d+)\.(\d+)-flash(?:$|-(?!lite(?:-|$)))/.exec(modelName ?? "");
|
|
2287
|
-
if (versionMatch == null) return "minimal";
|
|
2288
|
-
const majorVersion = Number(versionMatch[1]);
|
|
2289
|
-
const minorVersion = Number(versionMatch[2]);
|
|
2290
|
-
return majorVersion > 3 || majorVersion === 3 && minorVersion >= 7 ? "low" : "minimal";
|
|
2291
|
-
}
|
|
2292
2405
|
function resolveGemini25ThinkingConfig({ reasoning, modelId, warnings }) {
|
|
2293
|
-
const
|
|
2406
|
+
const entry = getGoogleLanguageModelEntry(modelId);
|
|
2407
|
+
const minThinkingBudget = entry.capabilities.language.reasoning.minBudget;
|
|
2294
2408
|
if (reasoning === "none" && minThinkingBudget === 0) return { thinkingBudget: 0 };
|
|
2295
2409
|
return { thinkingBudget: mapReasoningToProviderBudget({
|
|
2296
2410
|
reasoning,
|
|
2297
|
-
maxOutputTokens:
|
|
2298
|
-
maxReasoningBudget:
|
|
2411
|
+
maxOutputTokens: entry.requestConfig.language.reasoningMaxOutputTokens,
|
|
2412
|
+
maxReasoningBudget: entry.capabilities.language.reasoning.maxBudget,
|
|
2299
2413
|
minReasoningBudget: minThinkingBudget,
|
|
2300
2414
|
warnings
|
|
2301
2415
|
}) };
|
|
@@ -4873,7 +4987,7 @@ async function cancelGoogleInteraction({ baseURL, interactionId, headers, fetch
|
|
|
4873
4987
|
try {
|
|
4874
4988
|
const response = await fetch(url, {
|
|
4875
4989
|
method: "POST",
|
|
4876
|
-
headers: withUserAgentSuffix(combineHeaders({ "Content-Type": "application/json" }, headers), getRuntimeEnvironmentUserAgent()),
|
|
4990
|
+
headers: withUserAgentSuffix(combineHeaders({ "Content-Type": "application/json" }, await resolve(headers)), getRuntimeEnvironmentUserAgent()),
|
|
4877
4991
|
body: "{}"
|
|
4878
4992
|
});
|
|
4879
4993
|
try {
|
|
@@ -4923,7 +5037,7 @@ async function pollGoogleInteractionUntilTerminal({ baseURL, interactionId, head
|
|
|
4923
5037
|
const { value: response, rawValue: rawResponse, responseHeaders } = await getFromApi({
|
|
4924
5038
|
url,
|
|
4925
5039
|
validateUrl: false,
|
|
4926
|
-
headers,
|
|
5040
|
+
headers: await resolve(headers),
|
|
4927
5041
|
failedResponseHandler: googleFailedResponseHandler,
|
|
4928
5042
|
successfulResponseHandler: createJsonResponseHandler(googleInteractionsResponseSchema),
|
|
4929
5043
|
abortSignal,
|
|
@@ -5118,10 +5232,6 @@ const DEFAULT_RETRY_DELAY_MS = 500;
|
|
|
5118
5232
|
*/
|
|
5119
5233
|
function streamGoogleInteractionEvents({ baseURL, interactionId, headers, fetch, abortSignal, maxRetries = DEFAULT_MAX_RETRIES, retryDelayMs = DEFAULT_RETRY_DELAY_MS }) {
|
|
5120
5234
|
if (interactionId.length === 0) throw new Error("google.interactions: cannot stream a background interaction without an id.");
|
|
5121
|
-
const eventSourceHeaders = {
|
|
5122
|
-
...headers,
|
|
5123
|
-
accept: "text/event-stream"
|
|
5124
|
-
};
|
|
5125
5235
|
let lastEventId;
|
|
5126
5236
|
let complete = false;
|
|
5127
5237
|
let attempt = 0;
|
|
@@ -5144,7 +5254,10 @@ function streamGoogleInteractionEvents({ baseURL, interactionId, headers, fetch,
|
|
|
5144
5254
|
const { value: stream } = await getFromApi({
|
|
5145
5255
|
url: buildUrl(),
|
|
5146
5256
|
validateUrl: false,
|
|
5147
|
-
headers:
|
|
5257
|
+
headers: {
|
|
5258
|
+
...await resolve(headers),
|
|
5259
|
+
accept: "text/event-stream"
|
|
5260
|
+
},
|
|
5148
5261
|
failedResponseHandler: googleFailedResponseHandler,
|
|
5149
5262
|
successfulResponseHandler: createEventSourceResponseHandler(googleInteractionsEventSchema),
|
|
5150
5263
|
abortSignal: effectiveSignal,
|
|
@@ -5615,10 +5728,10 @@ var GoogleInteractionsLanguageModel = class GoogleInteractionsLanguageModel {
|
|
|
5615
5728
|
async doGenerate(options) {
|
|
5616
5729
|
const { args, warnings, isAgent, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
5617
5730
|
const url = `${this.config.baseURL}/interactions`;
|
|
5618
|
-
const mergedHeaders =
|
|
5731
|
+
const mergedHeaders = async () => combineHeaders(await resolve(this.config.headers), options.headers);
|
|
5619
5732
|
let { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
|
|
5620
5733
|
url,
|
|
5621
|
-
headers: mergedHeaders,
|
|
5734
|
+
headers: await resolve(mergedHeaders),
|
|
5622
5735
|
body: args,
|
|
5623
5736
|
failedResponseHandler: googleFailedResponseHandler,
|
|
5624
5737
|
successfulResponseHandler: createJsonResponseHandler(googleInteractionsResponseSchema),
|
|
@@ -5682,7 +5795,7 @@ var GoogleInteractionsLanguageModel = class GoogleInteractionsLanguageModel {
|
|
|
5682
5795
|
async doStream(options) {
|
|
5683
5796
|
const { args, warnings, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
5684
5797
|
const url = `${this.config.baseURL}/interactions`;
|
|
5685
|
-
const mergedHeaders =
|
|
5798
|
+
const mergedHeaders = async () => combineHeaders(await resolve(this.config.headers), options.headers);
|
|
5686
5799
|
if (isBackground) return this.doStreamBackground({
|
|
5687
5800
|
args,
|
|
5688
5801
|
warnings,
|
|
@@ -5697,7 +5810,7 @@ var GoogleInteractionsLanguageModel = class GoogleInteractionsLanguageModel {
|
|
|
5697
5810
|
};
|
|
5698
5811
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
5699
5812
|
url,
|
|
5700
|
-
headers: mergedHeaders,
|
|
5813
|
+
headers: await resolve(mergedHeaders),
|
|
5701
5814
|
body,
|
|
5702
5815
|
failedResponseHandler: googleFailedResponseHandler,
|
|
5703
5816
|
successfulResponseHandler: createEventSourceResponseHandler(googleInteractionsEventSchema),
|
|
@@ -5720,7 +5833,7 @@ var GoogleInteractionsLanguageModel = class GoogleInteractionsLanguageModel {
|
|
|
5720
5833
|
async doStreamBackground({ args, warnings, url, mergedHeaders, options, pollingTimeoutMs }) {
|
|
5721
5834
|
const { responseHeaders: postHeaders, value: postResponse } = await postJsonToApi({
|
|
5722
5835
|
url,
|
|
5723
|
-
headers: mergedHeaders,
|
|
5836
|
+
headers: await resolve(mergedHeaders),
|
|
5724
5837
|
body: args,
|
|
5725
5838
|
failedResponseHandler: googleFailedResponseHandler,
|
|
5726
5839
|
successfulResponseHandler: createJsonResponseHandler(googleInteractionsResponseSchema),
|