From 10ee46c373875c6e559cf9c2126939bfa88cb81f Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 12 Apr 2026 03:43:24 +0100 Subject: [PATCH] fix(plugins): extract provider config policy contexts --- src/plugins/provider-config-context.types.ts | 36 ++++++++++++++++ src/plugins/provider-public-artifacts.ts | 4 +- src/plugins/types.ts | 43 +++++--------------- 3 files changed, 48 insertions(+), 35 deletions(-) create mode 100644 src/plugins/provider-config-context.types.ts diff --git a/src/plugins/provider-config-context.types.ts b/src/plugins/provider-config-context.types.ts new file mode 100644 index 00000000000..650ddf25850 --- /dev/null +++ b/src/plugins/provider-config-context.types.ts @@ -0,0 +1,36 @@ +import type { ModelProviderConfig } from "../config/types.js"; +import type { OpenClawConfig } from "../config/types.openclaw.js"; + +/** + * Provider-owned config normalization for `models.providers.` entries. + * + * Use this for provider-specific config cleanup that should stay with the + * plugin rather than in core config-policy tables. + */ +export type ProviderNormalizeConfigContext = { + provider: string; + providerConfig: ModelProviderConfig; +}; + +/** + * Provider-owned env/config auth marker resolution for `models.providers`. + * + * Use this when a provider resolves auth from env vars that do not follow the + * generic API-key conventions. + */ +export type ProviderResolveConfigApiKeyContext = { + provider: string; + env: NodeJS.ProcessEnv; +}; + +/** + * Provider-owned config-default application input. + * + * Use this when a provider needs to add global config defaults that depend on + * provider auth mode or provider-specific model families. + */ +export type ProviderApplyConfigDefaultsContext = { + provider: string; + config: OpenClawConfig; + env: NodeJS.ProcessEnv; +}; diff --git a/src/plugins/provider-public-artifacts.ts b/src/plugins/provider-public-artifacts.ts index d5e8fa07328..60b555c396f 100644 --- a/src/plugins/provider-public-artifacts.ts +++ b/src/plugins/provider-public-artifacts.ts @@ -1,12 +1,12 @@ import { normalizeProviderId } from "../agents/provider-id.js"; import type { ModelProviderConfig } from "../config/types.js"; import type { OpenClawConfig } from "../config/types.openclaw.js"; -import { loadBundledPluginPublicArtifactModuleSync } from "./public-surface-loader.js"; import type { ProviderApplyConfigDefaultsContext, ProviderNormalizeConfigContext, ProviderResolveConfigApiKeyContext, -} from "./types.js"; +} from "./provider-config-context.types.js"; +import { loadBundledPluginPublicArtifactModuleSync } from "./public-surface-loader.js"; const PROVIDER_POLICY_ARTIFACT_CANDIDATES = ["provider-policy-api.js"] as const; diff --git a/src/plugins/types.ts b/src/plugins/types.ts index 77fd715a9b1..e812334e016 100644 --- a/src/plugins/types.ts +++ b/src/plugins/types.ts @@ -89,6 +89,11 @@ import type { import type { PluginKind } from "./plugin-kind.types.js"; import type { PluginOrigin } from "./plugin-origin.types.js"; import type { SecretInputMode } from "./provider-auth-types.js"; +import type { + ProviderApplyConfigDefaultsContext, + ProviderNormalizeConfigContext, + ProviderResolveConfigApiKeyContext, +} from "./provider-config-context.types.js"; import type { ProviderExternalAuthProfile, ProviderExternalOAuthProfile, @@ -432,16 +437,11 @@ export type ProviderNormalizeModelIdContext = { modelId: string; }; -/** - * Provider-owned config normalization for `models.providers.` entries. - * - * Use this for provider-specific config cleanup that should stay with the - * plugin rather than in core config-policy tables. - */ -export type ProviderNormalizeConfigContext = { - provider: string; - providerConfig: ModelProviderConfig; -}; +export type { + ProviderApplyConfigDefaultsContext, + ProviderNormalizeConfigContext, + ProviderResolveConfigApiKeyContext, +} from "./provider-config-context.types.js"; /** * Provider-owned transport normalization for arbitrary provider/model config. @@ -456,17 +456,6 @@ export type ProviderNormalizeTransportContext = { baseUrl?: string; }; -/** - * Provider-owned env/config auth marker resolution for `models.providers`. - * - * Use this when a provider resolves auth from env vars that do not follow the - * generic API-key conventions. - */ -export type ProviderResolveConfigApiKeyContext = { - provider: string; - env: NodeJS.ProcessEnv; -}; - /** * Runtime auth input for providers that need an extra exchange step before * inference. The incoming `apiKey` is the raw credential resolved from auth @@ -800,18 +789,6 @@ export type ProviderFailoverErrorContext = { errorMessage: string; }; -/** - * Provider-owned config-default application input. - * - * Use this when a provider needs to add global config defaults that depend on - * provider auth mode or provider-specific model families. - */ -export type ProviderApplyConfigDefaultsContext = { - provider: string; - config: OpenClawConfig; - env: NodeJS.ProcessEnv; -}; - /** * Generic embedding provider shape returned by provider plugins. *