1- import { resolveProviderEndpoint } from "openclaw/plugin-sdk/provider-http" ;
1+ import {
2+ resolveProviderEndpoint ,
3+ resolveProviderHttpRequestConfig ,
4+ type ProviderRequestTransportOverrides ,
5+ } from "openclaw/plugin-sdk/provider-http" ;
26import type { ModelProviderConfig } from "openclaw/plugin-sdk/provider-model-shared" ;
37import {
48 applyAgentDefaultModelPrimary ,
59 type OpenClawConfig ,
610} from "openclaw/plugin-sdk/provider-onboard" ;
711import { normalizeAntigravityModelId , normalizeGoogleModelId } from "./model-id.js" ;
12+ import { parseGoogleOauthApiKey } from "./oauth-token-shared.js" ;
813export { normalizeAntigravityModelId , normalizeGoogleModelId } ;
914
1015type GoogleApiCarrier = {
@@ -138,20 +143,14 @@ export function normalizeGoogleProviderConfig(
138143}
139144
140145export function parseGeminiAuth ( apiKey : string ) : { headers : Record < string , string > } {
141- if ( apiKey . startsWith ( "{" ) ) {
142- try {
143- const parsed = JSON . parse ( apiKey ) as { token ?: string ; projectId ?: string } ;
144- if ( typeof parsed . token === "string" && parsed . token ) {
145- return {
146- headers : {
147- Authorization : `Bearer ${ parsed . token } ` ,
148- "Content-Type" : "application/json" ,
149- } ,
150- } ;
151- }
152- } catch {
153- // Fall back to API key mode.
154- }
146+ const parsed = apiKey . startsWith ( "{" ) ? parseGoogleOauthApiKey ( apiKey ) : null ;
147+ if ( parsed ?. token ) {
148+ return {
149+ headers : {
150+ Authorization : `Bearer ${ parsed . token } ` ,
151+ "Content-Type" : "application/json" ,
152+ } ,
153+ } ;
155154 }
156155
157156 return {
@@ -162,6 +161,28 @@ export function parseGeminiAuth(apiKey: string): { headers: Record<string, strin
162161 } ;
163162}
164163
164+ export function resolveGoogleGenerativeAiHttpRequestConfig ( params : {
165+ apiKey : string ;
166+ baseUrl ?: string ;
167+ headers ?: Record < string , string > ;
168+ request ?: ProviderRequestTransportOverrides ;
169+ capability : "image" | "audio" | "video" ;
170+ transport : "http" | "media-understanding" ;
171+ } ) {
172+ return resolveProviderHttpRequestConfig ( {
173+ baseUrl : normalizeGoogleApiBaseUrl ( params . baseUrl ?? DEFAULT_GOOGLE_API_BASE_URL ) ,
174+ defaultBaseUrl : DEFAULT_GOOGLE_API_BASE_URL ,
175+ allowPrivateNetwork : Boolean ( params . baseUrl ?. trim ( ) ) ,
176+ headers : params . headers ,
177+ request : params . request ,
178+ defaultHeaders : parseGeminiAuth ( params . apiKey ) . headers ,
179+ provider : "google" ,
180+ api : "google-generative-ai" ,
181+ capability : params . capability ,
182+ transport : params . transport ,
183+ } ) ;
184+ }
185+
165186export const GOOGLE_GEMINI_DEFAULT_MODEL = "google/gemini-3.1-pro-preview" ;
166187
167188export function applyGoogleGeminiModelDefault ( cfg : OpenClawConfig ) : {
0 commit comments