mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-07 07:58:36 +00:00
Reuse current installed-plugin registry records for policy-only enable and disable refreshes.\n\nThanks @vincentkoc
40 lines
1.3 KiB
TypeScript
40 lines
1.3 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;
|
|
pluginId: string;
|
|
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, pluginId: resolvedId, reason: "plugins disabled" };
|
|
}
|
|
if (cfg.plugins?.deny?.includes(pluginId) || cfg.plugins?.deny?.includes(resolvedId)) {
|
|
return { config: cfg, enabled: false, pluginId: resolvedId, 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, pluginId: resolvedId, reason: "blocked by allowlist" };
|
|
}
|
|
return {
|
|
config: setPluginEnabledInConfig(cfg, resolvedId, true, options),
|
|
enabled: true,
|
|
pluginId: resolvedId,
|
|
};
|
|
}
|