mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 02:10:43 +00:00
Fix bundled plugin install/uninstall sweep coverage and avoid persisting invalid placeholder config for config-gated bundled plugins.
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { normalizeChatChannelId } from "../channels/ids.js";
|
|
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
|
import { setPluginEnabledInConfig } from "./toggle-config.js";
|
|
|
|
export type PluginEnableResult = {
|
|
config: OpenClawConfig;
|
|
enabled: boolean;
|
|
reason?: string;
|
|
};
|
|
|
|
export function enablePluginInConfig(
|
|
cfg: OpenClawConfig,
|
|
pluginId: string,
|
|
options: { updateChannelConfig?: boolean } = {},
|
|
): PluginEnableResult {
|
|
const builtInChannelId = normalizeChatChannelId(pluginId);
|
|
const resolvedId = builtInChannelId ?? pluginId;
|
|
if (cfg.plugins?.enabled === false) {
|
|
return { config: cfg, enabled: false, reason: "plugins disabled" };
|
|
}
|
|
if (cfg.plugins?.deny?.includes(pluginId) || cfg.plugins?.deny?.includes(resolvedId)) {
|
|
return { config: cfg, enabled: false, reason: "blocked by denylist" };
|
|
}
|
|
const allow = cfg.plugins?.allow;
|
|
if (
|
|
Array.isArray(allow) &&
|
|
allow.length > 0 &&
|
|
!allow.includes(pluginId) &&
|
|
!allow.includes(resolvedId)
|
|
) {
|
|
return { config: cfg, enabled: false, reason: "blocked by allowlist" };
|
|
}
|
|
return {
|
|
config: setPluginEnabledInConfig(cfg, resolvedId, true, options),
|
|
enabled: true,
|
|
};
|
|
}
|