Files
openclaw/src/plugins/enable.ts
Vincent Koc caba05b94a fix(plugins): harden bundled install/uninstall sweep
Fix bundled plugin install/uninstall sweep coverage and avoid persisting invalid placeholder config for config-gated bundled plugins.
2026-04-27 01:57:40 -07:00

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,
};
}