refactor(google): move Gemini transport into plugin

This commit is contained in:
Peter Steinberger
2026-04-18 21:28:19 +01:00
parent 3a20606c04
commit 85826c83e4
15 changed files with 227 additions and 60 deletions

View File

@@ -2,7 +2,8 @@ import {
resolveProviderHttpRequestConfig,
type ProviderRequestTransportOverrides,
} from "openclaw/plugin-sdk/provider-http";
import { parseGoogleOauthApiKey } from "./oauth-token-shared.js";
import { parseGeminiAuth } from "./gemini-auth.js";
export { parseGeminiAuth };
export { applyGoogleGeminiModelDefault, GOOGLE_GEMINI_DEFAULT_MODEL } from "./onboard.js";
import {
DEFAULT_GOOGLE_API_BASE_URL,
@@ -23,6 +24,10 @@ export {
type GoogleThinkingInputLevel,
type GoogleThinkingLevel,
} from "./thinking-api.js";
export {
buildGoogleGenerativeAiParams,
createGoogleGenerativeAiTransportStreamFn,
} from "./transport-stream.js";
export {
DEFAULT_GOOGLE_API_BASE_URL,
isGoogleGenerativeAiApi,
@@ -37,25 +42,6 @@ export {
export { buildGoogleGeminiCliProvider } from "./gemini-cli-provider.js";
export { buildGoogleProvider } from "./provider-registration.js";
export function parseGeminiAuth(apiKey: string): { headers: Record<string, string> } {
const parsed = apiKey.startsWith("{") ? parseGoogleOauthApiKey(apiKey) : null;
if (parsed?.token) {
return {
headers: {
Authorization: `Bearer ${parsed.token}`,
"Content-Type": "application/json",
},
};
}
return {
headers: {
"x-goog-api-key": apiKey,
"Content-Type": "application/json",
},
};
}
function resolveTrustedGoogleGenerativeAiBaseUrl(baseUrl?: string): string {
const normalized =
normalizeGoogleGenerativeAiBaseUrl(baseUrl ?? DEFAULT_GOOGLE_API_BASE_URL) ??