@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.109
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7716e18: Support promises and synchronous or asynchronous callbacks in provider API key and token settings. Resolve credentials per authenticated request while preserving existing authentication behavior and synchronous credential serialization.
|
|
8
|
+
|
|
9
|
+
The experimental OpenAI Live `getServerWebSocketConfig()` method can now resolve asynchronously. Await its result before using the connection settings.
|
|
10
|
+
|
|
11
|
+
- dfed8e8: Consolidate Google language model capabilities and request policies into a model catalog shared by runtime resolution and generated documentation, preserving existing Google and Vertex request behavior.
|
|
12
|
+
- Updated dependencies [7716e18]
|
|
13
|
+
- Updated dependencies [5c247e9]
|
|
14
|
+
- Updated dependencies [dcd2f8d]
|
|
15
|
+
- @ai-sdk/provider-utils@5.0.72
|
|
16
|
+
- @ai-sdk/provider@4.0.35
|
|
17
|
+
|
|
3
18
|
## 4.0.108
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -754,7 +754,7 @@ interface GoogleProviderSettings {
|
|
|
754
754
|
* API key that is being send using the `x-goog-api-key` header.
|
|
755
755
|
* It defaults to the `GOOGLE_GENERATIVE_AI_API_KEY` environment variable.
|
|
756
756
|
*/
|
|
757
|
-
apiKey?: string
|
|
757
|
+
apiKey?: Resolvable<string>;
|
|
758
758
|
/**
|
|
759
759
|
* Custom headers to include in the requests.
|
|
760
760
|
*/
|
|
@@ -792,7 +792,7 @@ export declare const google: GoogleProvider;
|
|
|
792
792
|
type GoogleRealtimeModelConfig = {
|
|
793
793
|
provider: string;
|
|
794
794
|
baseURL: string;
|
|
795
|
-
headers:
|
|
795
|
+
headers: Resolvable<Record<string, string | undefined>>;
|
|
796
796
|
fetch?: FetchFunction;
|
|
797
797
|
};
|
|
798
798
|
declare class GoogleRealtimeModel implements Experimental_RealtimeModelV4 {
|
|
@@ -908,7 +908,7 @@ export declare class GoogleTranscriptionModel implements TranscriptionModelV4 {
|
|
|
908
908
|
type GoogleSpeechTranslationModelConfig = {
|
|
909
909
|
provider: string;
|
|
910
910
|
baseURL: string;
|
|
911
|
-
headers:
|
|
911
|
+
headers: Resolvable<Record<string, string | undefined>>;
|
|
912
912
|
webSocket?: WebSocketConstructor;
|
|
913
913
|
_internal?: {
|
|
914
914
|
currentDate?: () => Date;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["DecisionModelV4","BatchV4","SpeechTranslationModelV4","RealtimeFactoryV4","RealtimeModelV4ClientSecretOptions","RealtimeModelV4ClientSecretResult","RealtimeModelV4ServerEvent","RealtimeModelV4ClientEvent","RealtimeModelV4","RealtimeModelV4SessionConfig","TranscriptionModelV4StreamOptions","SpeechTranslationModelV4StreamOptions","SpeechTranslationModelV4"],"sources":["../src/google-error.ts","../src/google-language-model-options.ts","../src/google-language-model.ts","../src/google-prompt.ts","../src/tool/google-search.ts","../src/google-image-model-options.ts","../src/google-embedding-model-options.ts","../src/google-video-model-options.ts","../src/google-video-settings.ts","../src/google-speech-model-options.ts","../src/google-files.ts","../src/interactions/google-interactions-language-model-options.ts","../src/interactions/google-interactions-provider-metadata.ts","../src/interactions/google-interactions-agent.ts","../src/google-tools.ts","../src/google-image-settings.ts","../src/transcription/google-transcription-model-options.ts","../src/speech-translation/google-speech-translation-model-options.ts","../src/google-provider.ts","../src/realtime/google-realtime-model.ts","../src/realtime/google-realtime-model-options.ts","../src/transcription/google-transcription-model.ts","../src/speech-translation/google-speech-translation-model.ts","../src/version.ts"],"mappings":";;;;cAgBM,wDAAqB;;;;;;;;KAQf,kBAAkB,mBAAmB;;;KCjBrC;cAqDC,6DAA0B;;;;;;;;;;;;;;;WAA1B;;;;;;;;;;;;;;;;;;;;;;;;KA+OD,6BAA6B,mBAChC;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["DecisionModelV4","BatchV4","SpeechTranslationModelV4","RealtimeFactoryV4","RealtimeModelV4ClientSecretOptions","RealtimeModelV4ClientSecretResult","RealtimeModelV4ServerEvent","RealtimeModelV4ClientEvent","RealtimeModelV4","RealtimeModelV4SessionConfig","TranscriptionModelV4StreamOptions","SpeechTranslationModelV4StreamOptions","SpeechTranslationModelV4"],"sources":["../src/google-error.ts","../src/google-language-model-options.ts","../src/google-language-model.ts","../src/google-prompt.ts","../src/tool/google-search.ts","../src/google-image-model-options.ts","../src/google-embedding-model-options.ts","../src/google-video-model-options.ts","../src/google-video-settings.ts","../src/google-speech-model-options.ts","../src/google-files.ts","../src/interactions/google-interactions-language-model-options.ts","../src/interactions/google-interactions-provider-metadata.ts","../src/interactions/google-interactions-agent.ts","../src/google-tools.ts","../src/google-image-settings.ts","../src/transcription/google-transcription-model-options.ts","../src/speech-translation/google-speech-translation-model-options.ts","../src/google-provider.ts","../src/realtime/google-realtime-model.ts","../src/realtime/google-realtime-model-options.ts","../src/transcription/google-transcription-model.ts","../src/speech-translation/google-speech-translation-model.ts","../src/version.ts"],"mappings":"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"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, connectToWebSocket, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertInlineFileDataToUint8Array, convertJsonResponseToolStream, convertToBase64, convertUint8ArrayToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonLinesResponseHandler, createJsonResponseHandler, createNullLanguageModelUsage, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, delay, detectMediaType, downloadBlob, encodePathSegment, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, isAbortError, isCustomReasoning, isFullMediaType, isRecord, isSameOrigin, isUrlSupported, lazySchema, loadApiKey, mapReasoningToProviderBudget, mapReasoningToProviderEffort, normalizeBatchRequestCounts, parseProviderOptions, postJsonToApi, postToApi, resolve, resolveFullMediaType, resolveProviderReference, safeParseJSON, safeValidateTypes, secureJsonParse, serializeModelOptions, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
1
|
+
import { EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, connectToWebSocket, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertInlineFileDataToUint8Array, convertJsonResponseToolStream, convertToBase64, convertUint8ArrayToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonLinesResponseHandler, createJsonResponseHandler, createNullLanguageModelUsage, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, delay, detectMediaType, downloadBlob, encodePathSegment, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, isAbortError, isCustomReasoning, isFullMediaType, isRecord, isSameOrigin, isUrlSupported, lazySchema, loadApiKey, mapReasoningToProviderBudget, mapReasoningToProviderEffort, normalizeBatchRequestCounts, parseProviderOptions, postJsonToApi, postToApi, resolve, resolveFullMediaType, resolveProviderReference, resolveWith, safeParseJSON, safeValidateTypes, secureJsonParse, serializeModelOptions, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
2
2
|
import { Experimental_DecisionLanguageModel } from "@ai-sdk/provider-utils/experimental-decision";
|
|
3
3
|
import { AISDKError, InvalidArgumentError, InvalidResponseDataError, TooManyEmbeddingValuesForCallError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
|
|
4
4
|
import { z } from "zod/v4";
|
|
5
5
|
//#region src/version.ts
|
|
6
|
-
const VERSION = "4.0.
|
|
6
|
+
const VERSION = "4.0.109";
|
|
7
7
|
//#endregion
|
|
8
8
|
//#region src/google-error.ts
|
|
9
9
|
const getGoogleErrorSchema = () => z.object({
|
|
@@ -1030,11 +1030,129 @@ const googleLanguageModelOptions = lazySchema(() => zodSchema(z.object({
|
|
|
1030
1030
|
requestType: z.enum(["shared"]).optional()
|
|
1031
1031
|
})));
|
|
1032
1032
|
//#endregion
|
|
1033
|
-
//#region src/google-model-
|
|
1033
|
+
//#region src/google-model-catalog.ts
|
|
1034
1034
|
const gemini1ModelPattern = /(^|[/.])gemini-1(?:[.-]|$)/i;
|
|
1035
1035
|
const gemini2ModelPattern = /(^|[/.])gemini-2(?:[.-]|$)/i;
|
|
1036
|
-
const gemini25ModelPattern
|
|
1036
|
+
const gemini25ModelPattern = /(^|[/.])gemini-2\.5(?:[.-]|$)/i;
|
|
1037
1037
|
const geminiModelPattern = /(^|[/.])gemini-/i;
|
|
1038
|
+
/** Options accepted under providerOptions.google (or googleVertex on Vertex). */
|
|
1039
|
+
const googleProviderOptions = { language: {
|
|
1040
|
+
responseModalities: { description: "Response modalities to generate." },
|
|
1041
|
+
thinkingConfig: { description: "Thinking budget, level, and thought output." },
|
|
1042
|
+
cachedContent: { description: "Cached content to use as request context." },
|
|
1043
|
+
structuredOutputs: { description: "Whether to send the JSON response schema." },
|
|
1044
|
+
safetySettings: { description: "Safety settings for the request." },
|
|
1045
|
+
threshold: { description: "Default threshold for configurable safety categories." },
|
|
1046
|
+
audioTimestamp: { description: "Enable timestamp understanding for audio." },
|
|
1047
|
+
labels: { description: "Billing labels. Vertex AI only." },
|
|
1048
|
+
mediaResolution: { description: "Resolution used to process media inputs." },
|
|
1049
|
+
imageConfig: { description: "Image generation configuration." },
|
|
1050
|
+
retrievalConfig: { description: "Retrieval configuration for tools." },
|
|
1051
|
+
streamFunctionCallArguments: { description: "Stream function arguments. Vertex AI only." },
|
|
1052
|
+
serviceTier: { description: "Service tier. Gemini API only." },
|
|
1053
|
+
continuationToken: { description: "Resume a response using its continuation token." },
|
|
1054
|
+
sharedRequestType: { description: "Shared PayGo tier. Vertex AI only." },
|
|
1055
|
+
requestType: { description: "Request routing type. Vertex AI only." }
|
|
1056
|
+
} };
|
|
1057
|
+
const standard = {
|
|
1058
|
+
image: true,
|
|
1059
|
+
objectGeneration: true,
|
|
1060
|
+
tools: true,
|
|
1061
|
+
streaming: true,
|
|
1062
|
+
googleSearch: true,
|
|
1063
|
+
urlContext: true
|
|
1064
|
+
};
|
|
1065
|
+
const googleModelCatalog = Object.fromEntries(Object.entries({
|
|
1066
|
+
"gemini-nano-banana-2.1": {
|
|
1067
|
+
image: true,
|
|
1068
|
+
objectGeneration: false,
|
|
1069
|
+
tools: false,
|
|
1070
|
+
streaming: false,
|
|
1071
|
+
googleSearch: true,
|
|
1072
|
+
urlContext: false
|
|
1073
|
+
},
|
|
1074
|
+
"gemini-4-argon": standard,
|
|
1075
|
+
"gemini-3.8-flash": standard,
|
|
1076
|
+
"gemini-3.7-flash": standard,
|
|
1077
|
+
"gemini-3.6-flash": standard,
|
|
1078
|
+
"gemini-3.5-flash": standard,
|
|
1079
|
+
"gemini-3.5-flash-lite": standard,
|
|
1080
|
+
"gemini-3.1-pro-preview": standard,
|
|
1081
|
+
"gemini-3.1-flash-image-preview": standard,
|
|
1082
|
+
"gemini-3.1-flash-lite-preview": standard,
|
|
1083
|
+
"gemini-3-pro-preview": standard,
|
|
1084
|
+
"gemini-3-pro-image-preview": standard,
|
|
1085
|
+
"gemini-3-flash-preview": standard,
|
|
1086
|
+
"gemini-2.5-pro": standard,
|
|
1087
|
+
"gemini-2.5-flash": standard,
|
|
1088
|
+
"gemini-2.5-flash-lite": standard,
|
|
1089
|
+
"gemini-2.5-flash-lite-preview-06-17": standard,
|
|
1090
|
+
"gemini-2.0-flash": standard
|
|
1091
|
+
}).map(([modelId, documented]) => [modelId, createGoogleLanguageModelEntry(modelId, documented)]));
|
|
1092
|
+
function getGoogleLanguageModelEntry(modelId) {
|
|
1093
|
+
return Object.prototype.hasOwnProperty.call(googleModelCatalog, modelId) ? googleModelCatalog[modelId] : createGoogleLanguageModelEntry(modelId);
|
|
1094
|
+
}
|
|
1095
|
+
function createGoogleLanguageModelEntry(modelId, documented) {
|
|
1096
|
+
const runtime = resolveRuntimeDefinition(modelId);
|
|
1097
|
+
const declared = documented != null;
|
|
1098
|
+
const id = modelId.toLowerCase();
|
|
1099
|
+
const thinkingFormat = runtime.usesGemini3Features && !modelId.includes("gemini-3-pro-image") ? "level" : "budget";
|
|
1100
|
+
const minLevel = getMinimumThinkingLevelForGemini3Model(modelId);
|
|
1101
|
+
return {
|
|
1102
|
+
capabilities: { language: {
|
|
1103
|
+
inputs: {
|
|
1104
|
+
image: documented?.image ?? "unknown",
|
|
1105
|
+
audio: "unknown"
|
|
1106
|
+
},
|
|
1107
|
+
objectGeneration: documented?.objectGeneration ?? "unknown",
|
|
1108
|
+
tools: {
|
|
1109
|
+
usage: documented?.tools ?? "unknown",
|
|
1110
|
+
streaming: documented?.streaming ?? "unknown",
|
|
1111
|
+
gemini2: runtime.supportsGemini2Tools,
|
|
1112
|
+
googleSearch: documented?.googleSearch ?? "unknown",
|
|
1113
|
+
urlContext: documented?.urlContext ?? "unknown",
|
|
1114
|
+
fileSearch: runtime.supportsFileSearch,
|
|
1115
|
+
mixed: runtime.usesGemini3Features,
|
|
1116
|
+
functionResponseParts: runtime.usesGemini3Features
|
|
1117
|
+
},
|
|
1118
|
+
reasoning: {
|
|
1119
|
+
support: "unknown",
|
|
1120
|
+
efforts: thinkingFormat === "level" ? [
|
|
1121
|
+
...minLevel === "minimal" ? ["minimal"] : [],
|
|
1122
|
+
"low",
|
|
1123
|
+
"medium",
|
|
1124
|
+
"high"
|
|
1125
|
+
] : void 0,
|
|
1126
|
+
minBudget: id.includes("2.5-pro") ? 128 : 0,
|
|
1127
|
+
maxBudget: id.includes("2.5-pro") || id.includes("gemini-3-pro-image") ? 32768 : 24576
|
|
1128
|
+
},
|
|
1129
|
+
sampling: {
|
|
1130
|
+
temperature: "unknown",
|
|
1131
|
+
topP: "unknown",
|
|
1132
|
+
topK: "unknown",
|
|
1133
|
+
logprobs: false,
|
|
1134
|
+
penalties: gemini25ModelPattern.test(modelId) ? { condition: "Only supported on the Vertex AI API." } : true
|
|
1135
|
+
},
|
|
1136
|
+
structuredOutput: { withFunctionTools: runtime.usesGemini3Features }
|
|
1137
|
+
} },
|
|
1138
|
+
providerOptions: { language: declareProviderOptions(declared ? true : "unknown", {
|
|
1139
|
+
labels: { condition: "Only supported on the Vertex AI API." },
|
|
1140
|
+
sharedRequestType: { condition: "Only supported on the Vertex AI API." },
|
|
1141
|
+
requestType: { condition: "Only supported on the Vertex AI API." },
|
|
1142
|
+
serviceTier: { condition: "Only supported on the Gemini API." },
|
|
1143
|
+
streamFunctionCallArguments: { condition: "Only supported for streaming requests on the Vertex AI API with Gemini 3 or newer." }
|
|
1144
|
+
}) },
|
|
1145
|
+
requestConfig: { language: {
|
|
1146
|
+
systemInstruction: id.startsWith("gemma-") ? "user" : "system",
|
|
1147
|
+
thinkingFormat,
|
|
1148
|
+
reasoningMaxOutputTokens: 65536,
|
|
1149
|
+
jsonResponseTool: /(^|\/)gemini-/i.test(modelId)
|
|
1150
|
+
} }
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
function declareProviderOptions(support, exceptions) {
|
|
1154
|
+
return Object.fromEntries(Object.keys(googleProviderOptions.language).map((option) => [option, exceptions[option] ?? support]));
|
|
1155
|
+
}
|
|
1038
1156
|
function isKnownPreGemini2Model(modelId) {
|
|
1039
1157
|
return gemini1ModelPattern.test(modelId) || /(^|[/.])gemini-pro(?:-vision)?$/i.test(modelId) || /(^|[/.])gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId);
|
|
1040
1158
|
}
|
|
@@ -1045,17 +1163,39 @@ function isKnownPreGemini2Model(modelId) {
|
|
|
1045
1163
|
* intentionally inherit the newest supported behavior. Add exceptions here
|
|
1046
1164
|
* only when a model is known to require a legacy request shape.
|
|
1047
1165
|
*/
|
|
1048
|
-
function
|
|
1166
|
+
function resolveRuntimeDefinition(modelId) {
|
|
1049
1167
|
const isGeminiModel = geminiModelPattern.test(modelId);
|
|
1050
1168
|
const isGemini2Model = gemini2ModelPattern.test(modelId);
|
|
1051
1169
|
const isKnownPreGemini2 = isKnownPreGemini2Model(modelId);
|
|
1052
1170
|
const usesGemini3Features = isGeminiModel && !(isKnownPreGemini2 || isGemini2Model);
|
|
1053
1171
|
return {
|
|
1054
1172
|
supportsGemini2Tools: isGeminiModel && !isKnownPreGemini2 || modelId.toLowerCase().includes("nano-banana"),
|
|
1055
|
-
supportsFileSearch: gemini25ModelPattern
|
|
1173
|
+
supportsFileSearch: gemini25ModelPattern.test(modelId) || usesGemini3Features,
|
|
1056
1174
|
usesGemini3Features
|
|
1057
1175
|
};
|
|
1058
1176
|
}
|
|
1177
|
+
function getMinimumThinkingLevelForGemini3Model(modelId) {
|
|
1178
|
+
const modelName = /(?:^|[/.])(gemini-[^/]*)$/i.exec(modelId)?.[1].toLowerCase();
|
|
1179
|
+
if (modelName === "gemini-flash-latest") return "low";
|
|
1180
|
+
const proVersionMatch = /^gemini-(\d+)(?:\.\d+)?-pro(?:$|-)/.exec(modelName ?? "");
|
|
1181
|
+
if (Number(proVersionMatch?.[1]) >= 3) return "low";
|
|
1182
|
+
const versionMatch = /^gemini-(\d+)\.(\d+)-flash(?:$|-(?!lite(?:-|$)))/.exec(modelName ?? "");
|
|
1183
|
+
if (versionMatch == null) return "minimal";
|
|
1184
|
+
const majorVersion = Number(versionMatch[1]);
|
|
1185
|
+
const minorVersion = Number(versionMatch[2]);
|
|
1186
|
+
return majorVersion > 3 || majorVersion === 3 && minorVersion >= 7 ? "low" : "minimal";
|
|
1187
|
+
}
|
|
1188
|
+
//#endregion
|
|
1189
|
+
//#region src/google-model-capabilities.ts
|
|
1190
|
+
/** Compatibility projection of the resolved catalog for existing request code. */
|
|
1191
|
+
function getGoogleModelCapabilities(modelId) {
|
|
1192
|
+
const { tools } = getGoogleLanguageModelEntry(modelId).capabilities.language;
|
|
1193
|
+
return {
|
|
1194
|
+
supportsGemini2Tools: tools.gemini2,
|
|
1195
|
+
supportsFileSearch: tools.fileSearch,
|
|
1196
|
+
usesGemini3Features: tools.mixed
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1059
1199
|
//#endregion
|
|
1060
1200
|
//#region src/google-prepare-tools.ts
|
|
1061
1201
|
function prepareTools({ tools, toolChoice, modelId, isVertexProvider = false }) {
|
|
@@ -1537,7 +1677,6 @@ const configurableSafetySettingCategories = [
|
|
|
1537
1677
|
"HARM_CATEGORY_HARASSMENT",
|
|
1538
1678
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
|
1539
1679
|
];
|
|
1540
|
-
const gemini25ModelPattern = /(^|[/.])gemini-2\.5(?:[.-]|$)/i;
|
|
1541
1680
|
const googleCloudStorageFunctionResponseUrls = {
|
|
1542
1681
|
"image/png": [/^gs:\/\/.*$/],
|
|
1543
1682
|
"image/jpeg": [/^gs:\/\/.*$/],
|
|
@@ -1622,8 +1761,9 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1622
1761
|
imageConfig = geminiApiImageConfig;
|
|
1623
1762
|
}
|
|
1624
1763
|
}
|
|
1625
|
-
const
|
|
1626
|
-
const
|
|
1764
|
+
const entry = getGoogleLanguageModelEntry(modelId);
|
|
1765
|
+
const isGemmaModel = entry.requestConfig.language.systemInstruction === "user";
|
|
1766
|
+
const isGemini25DeveloperApiModel = !isVertexProvider && entry.capabilities.language.sampling.penalties !== true;
|
|
1627
1767
|
if (isGemini25DeveloperApiModel && frequencyPenalty != null) warnings.push({
|
|
1628
1768
|
type: "unsupported",
|
|
1629
1769
|
feature: "frequencyPenalty"
|
|
@@ -1632,7 +1772,7 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1632
1772
|
type: "unsupported",
|
|
1633
1773
|
feature: "presencePenalty"
|
|
1634
1774
|
});
|
|
1635
|
-
const
|
|
1775
|
+
const usesGemini3Features = entry.capabilities.language.tools.functionResponseParts;
|
|
1636
1776
|
const supportedFunctionResponseUrls = usesGemini3Features && config.downloadToolResultFiles?.supportsGoogleCloudStorageUrls ? googleCloudStorageFunctionResponseUrls : void 0;
|
|
1637
1777
|
const { contents, systemInstruction } = convertToGoogleMessages(config.downloadToolResultFiles ? await downloadToolResultFiles(prompt, {
|
|
1638
1778
|
abortSignal,
|
|
@@ -1717,8 +1857,10 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1717
1857
|
}
|
|
1718
1858
|
async getArgs(options, { isStreaming = false } = {}) {
|
|
1719
1859
|
const { responseFormat, tools, toolChoice } = options;
|
|
1860
|
+
const entry = getGoogleLanguageModelEntry(this.modelId);
|
|
1861
|
+
const { structuredOutput } = entry.capabilities.language;
|
|
1720
1862
|
let jsonResponseTool;
|
|
1721
|
-
if (responseFormat?.type === "json" && responseFormat.schema != null && tools?.some((tool) => tool.type === "function") &&
|
|
1863
|
+
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")) {
|
|
1722
1864
|
let name = "json";
|
|
1723
1865
|
for (let suffix = 1; tools.some((tool) => tool.name === name); suffix++) name = `json_${suffix}`;
|
|
1724
1866
|
jsonResponseTool = {
|
|
@@ -1888,10 +2030,9 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1888
2030
|
}
|
|
1889
2031
|
async doGenerate(options) {
|
|
1890
2032
|
const { args, warnings, providerOptionsNames, extraHeaders, toolNameMapping, jsonResponseToolName } = await this.getArgs(options);
|
|
1891
|
-
const
|
|
1892
|
-
const generateContent = (body) => postJsonToApi({
|
|
2033
|
+
const generateContent = async (body) => postJsonToApi({
|
|
1893
2034
|
url: `${this.config.baseURL}/${getModelPath(this.modelId)}:generateContent`,
|
|
1894
|
-
headers:
|
|
2035
|
+
headers: combineHeaders(await resolve(this.config.headers), options.headers, extraHeaders),
|
|
1895
2036
|
body,
|
|
1896
2037
|
failedResponseHandler: googleFailedResponseHandler,
|
|
1897
2038
|
successfulResponseHandler: createJsonResponseHandler(responseSchema),
|
|
@@ -1954,10 +2095,9 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
1954
2095
|
async doStream(options) {
|
|
1955
2096
|
const { args, warnings, providerOptionsNames, extraHeaders, toolNameMapping, jsonResponseToolName } = await this.getArgs(options, { isStreaming: true });
|
|
1956
2097
|
const wrapProviderMetadata = (payload) => Object.fromEntries(providerOptionsNames.map((name) => [name, payload]));
|
|
1957
|
-
const
|
|
1958
|
-
const streamGenerateContent = (body) => postJsonToApi({
|
|
2098
|
+
const streamGenerateContent = async (body) => postJsonToApi({
|
|
1959
2099
|
url: `${this.config.baseURL}/${getModelPath(this.modelId)}:streamGenerateContent?alt=sse`,
|
|
1960
|
-
headers,
|
|
2100
|
+
headers: combineHeaders(await resolve(this.config.headers), options.headers, extraHeaders),
|
|
1961
2101
|
body,
|
|
1962
2102
|
failedResponseHandler: googleFailedResponseHandler,
|
|
1963
2103
|
successfulResponseHandler: createEventSourceResponseHandler(chunkSchema),
|
|
@@ -2410,25 +2550,9 @@ var GoogleLanguageModel = class GoogleLanguageModel {
|
|
|
2410
2550
|
};
|
|
2411
2551
|
}
|
|
2412
2552
|
};
|
|
2413
|
-
function getMaxOutputTokensForGemini25Model() {
|
|
2414
|
-
return 65536;
|
|
2415
|
-
}
|
|
2416
|
-
function getMaxThinkingTokensForGemini25Model(modelId) {
|
|
2417
|
-
const id = modelId.toLowerCase();
|
|
2418
|
-
if (id.includes("2.5-pro") || id.includes("gemini-3-pro-image")) return 32768;
|
|
2419
|
-
return 24576;
|
|
2420
|
-
}
|
|
2421
|
-
/**
|
|
2422
|
-
* Gemini 2.5 Pro cannot disable thinking and requires a thinking budget of at
|
|
2423
|
-
* least 128 tokens. Other Gemini 2.5 models can disable thinking with a budget
|
|
2424
|
-
* of 0.
|
|
2425
|
-
*/
|
|
2426
|
-
function getMinThinkingTokensForGemini25Model(modelId) {
|
|
2427
|
-
return modelId.toLowerCase().includes("2.5-pro") ? 128 : 0;
|
|
2428
|
-
}
|
|
2429
2553
|
function resolveThinkingConfig({ reasoning, modelId, warnings }) {
|
|
2430
2554
|
if (!isCustomReasoning(reasoning)) return;
|
|
2431
|
-
if (
|
|
2555
|
+
if (getGoogleLanguageModelEntry(modelId).requestConfig.language.thinkingFormat === "level") return resolveGemini3ThinkingConfig({
|
|
2432
2556
|
reasoning,
|
|
2433
2557
|
modelId,
|
|
2434
2558
|
warnings
|
|
@@ -2440,7 +2564,7 @@ function resolveThinkingConfig({ reasoning, modelId, warnings }) {
|
|
|
2440
2564
|
});
|
|
2441
2565
|
}
|
|
2442
2566
|
function resolveGemini3ThinkingConfig({ reasoning, modelId, warnings }) {
|
|
2443
|
-
const minimumThinkingLevel =
|
|
2567
|
+
const minimumThinkingLevel = getGoogleLanguageModelEntry(modelId).capabilities.language.reasoning.efforts?.[0];
|
|
2444
2568
|
const thinkingLevel = mapReasoningToProviderEffort({
|
|
2445
2569
|
reasoning,
|
|
2446
2570
|
effortMap: {
|
|
@@ -2454,24 +2578,14 @@ function resolveGemini3ThinkingConfig({ reasoning, modelId, warnings }) {
|
|
|
2454
2578
|
if (thinkingLevel == null) return;
|
|
2455
2579
|
return { thinkingLevel };
|
|
2456
2580
|
}
|
|
2457
|
-
function getMinimumThinkingLevelForGemini3Model(modelId) {
|
|
2458
|
-
const modelName = /(?:^|[/.])(gemini-[^/]*)$/i.exec(modelId)?.[1].toLowerCase();
|
|
2459
|
-
if (modelName === "gemini-flash-latest") return "low";
|
|
2460
|
-
const proVersionMatch = /^gemini-(\d+)(?:\.\d+)?-pro(?:$|-)/.exec(modelName ?? "");
|
|
2461
|
-
if (Number(proVersionMatch?.[1]) >= 3) return "low";
|
|
2462
|
-
const versionMatch = /^gemini-(\d+)\.(\d+)-flash(?:$|-(?!lite(?:-|$)))/.exec(modelName ?? "");
|
|
2463
|
-
if (versionMatch == null) return "minimal";
|
|
2464
|
-
const majorVersion = Number(versionMatch[1]);
|
|
2465
|
-
const minorVersion = Number(versionMatch[2]);
|
|
2466
|
-
return majorVersion > 3 || majorVersion === 3 && minorVersion >= 7 ? "low" : "minimal";
|
|
2467
|
-
}
|
|
2468
2581
|
function resolveGemini25ThinkingConfig({ reasoning, modelId, warnings }) {
|
|
2469
|
-
const
|
|
2582
|
+
const entry = getGoogleLanguageModelEntry(modelId);
|
|
2583
|
+
const minThinkingBudget = entry.capabilities.language.reasoning.minBudget;
|
|
2470
2584
|
if (reasoning === "none" && minThinkingBudget === 0) return { thinkingBudget: 0 };
|
|
2471
2585
|
return { thinkingBudget: mapReasoningToProviderBudget({
|
|
2472
2586
|
reasoning,
|
|
2473
|
-
maxOutputTokens:
|
|
2474
|
-
maxReasoningBudget:
|
|
2587
|
+
maxOutputTokens: entry.requestConfig.language.reasoningMaxOutputTokens,
|
|
2588
|
+
maxReasoningBudget: entry.capabilities.language.reasoning.maxBudget,
|
|
2475
2589
|
minReasoningBudget: minThinkingBudget,
|
|
2476
2590
|
warnings
|
|
2477
2591
|
}) };
|
|
@@ -2887,12 +3001,11 @@ var GoogleBatch = class {
|
|
|
2887
3001
|
warning
|
|
2888
3002
|
});
|
|
2889
3003
|
}
|
|
2890
|
-
const headers = await this.getHeaders(options.headers);
|
|
2891
3004
|
const createUrl = `${this.batchConfig.baseURL}/${getModelPath(modelId)}:batchGenerateContent`;
|
|
2892
3005
|
if (fileParts == null) {
|
|
2893
3006
|
const { value: operation } = await postJsonToApi({
|
|
2894
3007
|
url: createUrl,
|
|
2895
|
-
headers,
|
|
3008
|
+
headers: await this.getHeaders(options.headers),
|
|
2896
3009
|
body: inlineBatchBody,
|
|
2897
3010
|
failedResponseHandler: googleFailedResponseHandler,
|
|
2898
3011
|
successfulResponseHandler: createJsonResponseHandler(googleBatchOperationSchema),
|
|
@@ -2913,7 +3026,7 @@ var GoogleBatch = class {
|
|
|
2913
3026
|
});
|
|
2914
3027
|
const { value: uploadUrl } = await postJsonToApi({
|
|
2915
3028
|
url: `${this.getBaseOrigin()}/upload/v1beta/files`,
|
|
2916
|
-
headers: combineHeaders(headers, {
|
|
3029
|
+
headers: combineHeaders(await this.getHeaders(options.headers), {
|
|
2917
3030
|
"X-Goog-Upload-Protocol": "resumable",
|
|
2918
3031
|
"X-Goog-Upload-Command": "start",
|
|
2919
3032
|
"X-Goog-Upload-Header-Content-Length": String(inputFile.size),
|
|
@@ -2946,7 +3059,7 @@ var GoogleBatch = class {
|
|
|
2946
3059
|
});
|
|
2947
3060
|
const { value: operation } = await postJsonToApi({
|
|
2948
3061
|
url: createUrl,
|
|
2949
|
-
headers,
|
|
3062
|
+
headers: await this.getHeaders(options.headers),
|
|
2950
3063
|
body: { batch: {
|
|
2951
3064
|
displayName,
|
|
2952
3065
|
...options.webhookUrl != null && { webhookConfig: { uris: [options.webhookUrl] } },
|
|
@@ -3568,7 +3681,7 @@ var GoogleFiles = class {
|
|
|
3568
3681
|
providerOptions: options.providerOptions,
|
|
3569
3682
|
schema: googleFilesUploadOptionsSchema
|
|
3570
3683
|
});
|
|
3571
|
-
const
|
|
3684
|
+
const getHeaders = async () => combineHeaders(await resolve(this.config.headers), options.headers);
|
|
3572
3685
|
const fetchFn = this.config.fetch ?? globalThis.fetch;
|
|
3573
3686
|
const warnings = [];
|
|
3574
3687
|
if (options.filename != null) warnings.push({
|
|
@@ -3581,7 +3694,7 @@ var GoogleFiles = class {
|
|
|
3581
3694
|
const initResponse = await fetchFn(`${this.config.baseURL.replace(/\/v1beta$/, "")}/upload/v1beta/files`, {
|
|
3582
3695
|
method: "POST",
|
|
3583
3696
|
headers: {
|
|
3584
|
-
...
|
|
3697
|
+
...await getHeaders(),
|
|
3585
3698
|
"X-Goog-Upload-Protocol": "resumable",
|
|
3586
3699
|
"X-Goog-Upload-Command": "start",
|
|
3587
3700
|
"X-Goog-Upload-Header-Content-Length": String(fileBytes.length),
|
|
@@ -3634,7 +3747,7 @@ var GoogleFiles = class {
|
|
|
3634
3747
|
const { value: fileStatus } = await getFromApi({
|
|
3635
3748
|
url: `${this.config.baseURL}/${filePath}`,
|
|
3636
3749
|
validateUrl: false,
|
|
3637
|
-
headers:
|
|
3750
|
+
headers: await getHeaders(),
|
|
3638
3751
|
successfulResponseHandler: createJsonResponseHandler(googleFileResponseSchema),
|
|
3639
3752
|
failedResponseHandler: googleFailedResponseHandler,
|
|
3640
3753
|
abortSignal: options.abortSignal,
|
|
@@ -6148,7 +6261,7 @@ async function cancelGoogleInteraction({ baseURL, interactionId, headers, fetch
|
|
|
6148
6261
|
try {
|
|
6149
6262
|
const response = await fetch(url, {
|
|
6150
6263
|
method: "POST",
|
|
6151
|
-
headers: withUserAgentSuffix(combineHeaders({ "Content-Type": "application/json" }, headers), getRuntimeEnvironmentUserAgent()),
|
|
6264
|
+
headers: withUserAgentSuffix(combineHeaders({ "Content-Type": "application/json" }, await resolve(headers)), getRuntimeEnvironmentUserAgent()),
|
|
6152
6265
|
body: "{}"
|
|
6153
6266
|
});
|
|
6154
6267
|
try {
|
|
@@ -6198,7 +6311,7 @@ async function pollGoogleInteractionUntilTerminal({ baseURL, interactionId, head
|
|
|
6198
6311
|
const { value: response, rawValue: rawResponse, responseHeaders } = await getFromApi({
|
|
6199
6312
|
url,
|
|
6200
6313
|
validateUrl: false,
|
|
6201
|
-
headers,
|
|
6314
|
+
headers: await resolve(headers),
|
|
6202
6315
|
failedResponseHandler: googleFailedResponseHandler,
|
|
6203
6316
|
successfulResponseHandler: createJsonResponseHandler(googleInteractionsResponseSchema),
|
|
6204
6317
|
abortSignal,
|
|
@@ -6393,10 +6506,6 @@ const DEFAULT_RETRY_DELAY_MS = 500;
|
|
|
6393
6506
|
*/
|
|
6394
6507
|
function streamGoogleInteractionEvents({ baseURL, interactionId, headers, fetch, abortSignal, maxRetries = DEFAULT_MAX_RETRIES, retryDelayMs = DEFAULT_RETRY_DELAY_MS }) {
|
|
6395
6508
|
if (interactionId.length === 0) throw new Error("google.interactions: cannot stream a background interaction without an id.");
|
|
6396
|
-
const eventSourceHeaders = {
|
|
6397
|
-
...headers,
|
|
6398
|
-
accept: "text/event-stream"
|
|
6399
|
-
};
|
|
6400
6509
|
let lastEventId;
|
|
6401
6510
|
let complete = false;
|
|
6402
6511
|
let attempt = 0;
|
|
@@ -6419,7 +6528,10 @@ function streamGoogleInteractionEvents({ baseURL, interactionId, headers, fetch,
|
|
|
6419
6528
|
const { value: stream } = await getFromApi({
|
|
6420
6529
|
url: buildUrl(),
|
|
6421
6530
|
validateUrl: false,
|
|
6422
|
-
headers:
|
|
6531
|
+
headers: {
|
|
6532
|
+
...await resolve(headers),
|
|
6533
|
+
accept: "text/event-stream"
|
|
6534
|
+
},
|
|
6423
6535
|
failedResponseHandler: googleFailedResponseHandler,
|
|
6424
6536
|
successfulResponseHandler: createEventSourceResponseHandler(googleInteractionsEventSchema),
|
|
6425
6537
|
abortSignal: effectiveSignal,
|
|
@@ -6890,10 +7002,10 @@ var GoogleInteractionsLanguageModel = class GoogleInteractionsLanguageModel {
|
|
|
6890
7002
|
async doGenerate(options) {
|
|
6891
7003
|
const { args, warnings, isAgent, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
6892
7004
|
const url = `${this.config.baseURL}/interactions`;
|
|
6893
|
-
const mergedHeaders =
|
|
7005
|
+
const mergedHeaders = async () => combineHeaders(await resolve(this.config.headers), options.headers);
|
|
6894
7006
|
let { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
|
|
6895
7007
|
url,
|
|
6896
|
-
headers: mergedHeaders,
|
|
7008
|
+
headers: await resolve(mergedHeaders),
|
|
6897
7009
|
body: args,
|
|
6898
7010
|
failedResponseHandler: googleFailedResponseHandler,
|
|
6899
7011
|
successfulResponseHandler: createJsonResponseHandler(googleInteractionsResponseSchema),
|
|
@@ -6957,7 +7069,7 @@ var GoogleInteractionsLanguageModel = class GoogleInteractionsLanguageModel {
|
|
|
6957
7069
|
async doStream(options) {
|
|
6958
7070
|
const { args, warnings, isBackground, pollingTimeoutMs } = await this.getArgs(options);
|
|
6959
7071
|
const url = `${this.config.baseURL}/interactions`;
|
|
6960
|
-
const mergedHeaders =
|
|
7072
|
+
const mergedHeaders = async () => combineHeaders(await resolve(this.config.headers), options.headers);
|
|
6961
7073
|
if (isBackground) return this.doStreamBackground({
|
|
6962
7074
|
args,
|
|
6963
7075
|
warnings,
|
|
@@ -6972,7 +7084,7 @@ var GoogleInteractionsLanguageModel = class GoogleInteractionsLanguageModel {
|
|
|
6972
7084
|
};
|
|
6973
7085
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
6974
7086
|
url,
|
|
6975
|
-
headers: mergedHeaders,
|
|
7087
|
+
headers: await resolve(mergedHeaders),
|
|
6976
7088
|
body,
|
|
6977
7089
|
failedResponseHandler: googleFailedResponseHandler,
|
|
6978
7090
|
successfulResponseHandler: createEventSourceResponseHandler(googleInteractionsEventSchema),
|
|
@@ -6995,7 +7107,7 @@ var GoogleInteractionsLanguageModel = class GoogleInteractionsLanguageModel {
|
|
|
6995
7107
|
async doStreamBackground({ args, warnings, url, mergedHeaders, options, pollingTimeoutMs }) {
|
|
6996
7108
|
const { responseHeaders: postHeaders, value: postResponse } = await postJsonToApi({
|
|
6997
7109
|
url,
|
|
6998
|
-
headers: mergedHeaders,
|
|
7110
|
+
headers: await resolve(mergedHeaders),
|
|
6999
7111
|
body: args,
|
|
7000
7112
|
failedResponseHandler: googleFailedResponseHandler,
|
|
7001
7113
|
successfulResponseHandler: createJsonResponseHandler(googleInteractionsResponseSchema),
|
|
@@ -7429,7 +7541,7 @@ var GoogleRealtimeModel = class {
|
|
|
7429
7541
|
}
|
|
7430
7542
|
async doCreateClientSecret(options) {
|
|
7431
7543
|
const fetchFn = this.config.fetch ?? fetch;
|
|
7432
|
-
const apiKey = this.config.headers
|
|
7544
|
+
const apiKey = (await resolve(this.config.headers))["x-goog-api-key"];
|
|
7433
7545
|
if (!apiKey) throw new Error("Google Generative AI API key is required for realtime token creation.");
|
|
7434
7546
|
const now = Date.now();
|
|
7435
7547
|
const openWindowMs = (options.expiresAfterSeconds ?? 60) * 1e3;
|
|
@@ -7954,7 +8066,7 @@ var GoogleSpeechTranslationModel = class GoogleSpeechTranslationModel {
|
|
|
7954
8066
|
feature: "outputAudioFormat",
|
|
7955
8067
|
details: "The Gemini Live API always outputs 24kHz 16-bit PCM audio and does not accept an output audio format."
|
|
7956
8068
|
});
|
|
7957
|
-
const headers = combineHeaders(this.config.headers
|
|
8069
|
+
const headers = combineHeaders(await resolve(this.config.headers), options.headers);
|
|
7958
8070
|
let apiKey;
|
|
7959
8071
|
for (const [key, value] of Object.entries(headers)) if (key.toLowerCase() === "x-goog-api-key" && value != null) apiKey = value;
|
|
7960
8072
|
if (apiKey == null) throw new Error("Google Generative AI API key is required for streaming translation.");
|
|
@@ -8270,14 +8382,14 @@ function supportsExternalFileUrls(modelId) {
|
|
|
8270
8382
|
function createGoogle(options = {}) {
|
|
8271
8383
|
const baseURL = withoutTrailingSlash(options.baseURL) ?? DEFAULT_BASE_URL;
|
|
8272
8384
|
const providerName = options.name ?? "google.generative-ai";
|
|
8273
|
-
const getHeaders = () => withUserAgentSuffix({
|
|
8385
|
+
const getHeaders = () => resolveWith(options.apiKey, (apiKey) => withUserAgentSuffix({
|
|
8274
8386
|
"x-goog-api-key": loadApiKey({
|
|
8275
|
-
apiKey
|
|
8387
|
+
apiKey,
|
|
8276
8388
|
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
8277
8389
|
description: "Google Generative AI"
|
|
8278
8390
|
}),
|
|
8279
8391
|
...options.headers
|
|
8280
|
-
}, `ai-sdk-google/${VERSION}`);
|
|
8392
|
+
}, `ai-sdk-google/${VERSION}`));
|
|
8281
8393
|
const getSupportedUrls = (modelId, includeExternalUrls = modelId == null || supportsExternalFileUrls(modelId)) => ({
|
|
8282
8394
|
"*": [
|
|
8283
8395
|
googleFilesUrlPattern,
|