@@ -2,6 +2,7 @@ import type { OpenClawConfig } from "../config/config.js";
22import { coerceSecretRef , resolveSecretInputRef } from "../config/types.secrets.js" ;
33import { createSubsystemLogger } from "../logging/subsystem.js" ;
44import { formatApiKeyPreview } from "../plugins/provider-auth-input.js" ;
5+ import { resolveProviderSyntheticAuthWithPlugin } from "../plugins/provider-runtime.js" ;
56import { normalizeOptionalSecretInput } from "../utils/normalize-secret-input.js" ;
67import { listProfilesForProvider } from "./auth-profiles/profiles.js" ;
78import { ensureAuthProfileStore } from "./auth-profiles/store.js" ;
@@ -13,7 +14,6 @@ import {
1314 resolveNonEnvSecretRefHeaderValueMarker ,
1415} from "./model-auth-markers.js" ;
1516import { resolveAwsSdkEnvVarName } from "./model-auth-runtime-shared.js" ;
16- import { normalizeProviderId } from "./provider-id.js" ;
1717
1818type ModelsConfig = NonNullable < OpenClawConfig [ "models" ] > ;
1919export type ProviderConfig = NonNullable < ModelsConfig [ "providers" ] > [ string ] ;
@@ -438,34 +438,16 @@ function resolveConfigBackedProviderAuth(params: { provider: string; config?: Op
438438 source : "config" ;
439439 }
440440 | undefined {
441- let apiKey : string | undefined ;
442- if ( normalizeProviderId ( params . provider ) === "xai" ) {
443- const pluginApiKey = normalizeOptionalSecretInput (
444- params . config ?. plugins ?. entries ?. xai ?. config &&
445- typeof params . config . plugins . entries . xai . config === "object" &&
446- ! Array . isArray ( params . config . plugins . entries . xai . config )
447- ? ( ( params . config . plugins . entries . xai . config as { webSearch ?: { apiKey ?: unknown } } )
448- . webSearch ?. apiKey ?? undefined )
449- : undefined ,
450- ) ;
451- const pluginApiKeyRef = coerceSecretRef (
452- params . config ?. plugins ?. entries ?. xai ?. config &&
453- typeof params . config . plugins . entries . xai . config === "object" &&
454- ! Array . isArray ( params . config . plugins . entries . xai . config )
455- ? ( ( params . config . plugins . entries . xai . config as { webSearch ?: { apiKey ?: unknown } } )
456- . webSearch ?. apiKey ?? undefined )
457- : undefined ,
458- ) ;
459- const legacyApiKey = normalizeOptionalSecretInput (
460- params . config ?. tools ?. web ?. search ?. grok ?. apiKey ,
461- ) ;
462- const legacyApiKeyRef = coerceSecretRef ( params . config ?. tools ?. web ?. search ?. grok ?. apiKey ) ;
463- apiKey =
464- pluginApiKey ??
465- ( pluginApiKeyRef ? resolveNonEnvSecretRefApiKeyMarker ( pluginApiKeyRef . source ) : undefined ) ??
466- legacyApiKey ??
467- ( legacyApiKeyRef ? resolveNonEnvSecretRefApiKeyMarker ( legacyApiKeyRef . source ) : undefined ) ;
468- }
441+ const synthetic = resolveProviderSyntheticAuthWithPlugin ( {
442+ provider : params . provider ,
443+ config : params . config ,
444+ context : {
445+ config : params . config ,
446+ provider : params . provider ,
447+ providerConfig : params . config ?. models ?. providers ?. [ params . provider ] ,
448+ } ,
449+ } ) ;
450+ const apiKey = synthetic ?. apiKey ?. trim ( ) ;
469451 if ( ! apiKey ) {
470452 if ( shouldTraceProviderAuth ( params . provider ) ) {
471453 log . info ( "[xai-auth] bootstrap config fallback: no config-backed key found" ) ;
0 commit comments