From 9ea3da08dff2b2dad20de75109a43a1e4bc052a3 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Tue, 7 Apr 2026 11:55:02 +0100 Subject: [PATCH] perf(plugin-sdk): narrow provider contract config types --- src/config/plugin-web-search-config.ts | 14 ++++++++++-- src/config/plugins-allowlist.ts | 13 +++++++++--- src/plugin-sdk/provider-enable-config.ts | 27 ++++++++++++++++++------ 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/config/plugin-web-search-config.ts b/src/config/plugin-web-search-config.ts index 342081e0345..089d59a1320 100644 --- a/src/config/plugin-web-search-config.ts +++ b/src/config/plugin-web-search-config.ts @@ -1,8 +1,18 @@ import { isRecord } from "../utils.js"; -import type { OpenClawConfig } from "./config.js"; + +type PluginWebSearchConfigCarrier = { + plugins?: { + entries?: Record< + string, + { + config?: unknown; + } + >; + }; +}; export function resolvePluginWebSearchConfig( - config: OpenClawConfig | undefined, + config: PluginWebSearchConfigCarrier | undefined, pluginId: string, ): Record | undefined { const pluginConfig = config?.plugins?.entries?.[pluginId]?.config; diff --git a/src/config/plugins-allowlist.ts b/src/config/plugins-allowlist.ts index a0893f131da..ff8b08aa077 100644 --- a/src/config/plugins-allowlist.ts +++ b/src/config/plugins-allowlist.ts @@ -1,6 +1,13 @@ -import type { OpenClawConfig } from "./config.js"; +type PluginAllowlistConfigCarrier = { + plugins?: { + allow?: string[]; + }; +}; -export function ensurePluginAllowlisted(cfg: OpenClawConfig, pluginId: string): OpenClawConfig { +export function ensurePluginAllowlisted( + cfg: T, + pluginId: string, +): T { const allow = cfg.plugins?.allow; if (!Array.isArray(allow) || allow.includes(pluginId)) { return cfg; @@ -11,5 +18,5 @@ export function ensurePluginAllowlisted(cfg: OpenClawConfig, pluginId: string): ...cfg.plugins, allow: [...allow, pluginId], }, - }; + } as T; } diff --git a/src/plugin-sdk/provider-enable-config.ts b/src/plugin-sdk/provider-enable-config.ts index 5d830ecacca..b657754eec5 100644 --- a/src/plugin-sdk/provider-enable-config.ts +++ b/src/plugin-sdk/provider-enable-config.ts @@ -1,8 +1,20 @@ -import type { OpenClawConfig } from "../config/config.js"; import { ensurePluginAllowlisted } from "../config/plugins-allowlist.js"; -export type PluginEnableResult = { - config: OpenClawConfig; +type ProviderPluginConfig = { + enabled?: boolean; +}; + +type ProviderEnableConfigCarrier = { + plugins?: { + enabled?: boolean; + deny?: string[]; + allow?: string[]; + entries?: Record; + }; +}; + +export type PluginEnableResult = { + config: TConfig; enabled: boolean; reason?: string; }; @@ -11,7 +23,10 @@ export type PluginEnableResult = { * Provider contract surfaces only ever enable provider plugins, so they do not * need the built-in channel normalization path from plugins/enable.ts. */ -export function enablePluginInConfig(cfg: OpenClawConfig, pluginId: string): PluginEnableResult { +export function enablePluginInConfig( + cfg: TConfig, + pluginId: string, +): PluginEnableResult { if (cfg.plugins?.enabled === false) { return { config: cfg, enabled: false, reason: "plugins disabled" }; } @@ -19,7 +34,7 @@ export function enablePluginInConfig(cfg: OpenClawConfig, pluginId: string): Plu return { config: cfg, enabled: false, reason: "blocked by denylist" }; } - let next: OpenClawConfig = { + let next = { ...cfg, plugins: { ...cfg.plugins, @@ -31,7 +46,7 @@ export function enablePluginInConfig(cfg: OpenClawConfig, pluginId: string): Plu }, }, }, - }; + } as TConfig; next = ensurePluginAllowlisted(next, pluginId); return { config: next, enabled: true }; }