mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 23:40:45 +00:00
25 lines
1020 B
TypeScript
25 lines
1020 B
TypeScript
import { normalizeChatChannelId } from "../channels/registry.js";
|
|
import type { OpenClawConfig } from "../config/config.js";
|
|
import { ensurePluginAllowlisted } from "../config/plugins-allowlist.js";
|
|
import { setPluginEnabledInConfig } from "./toggle-config.js";
|
|
|
|
export type PluginEnableResult = {
|
|
config: OpenClawConfig;
|
|
enabled: boolean;
|
|
reason?: string;
|
|
};
|
|
|
|
export function enablePluginInConfig(cfg: OpenClawConfig, pluginId: string): 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" };
|
|
}
|
|
let next = setPluginEnabledInConfig(cfg, resolvedId, true);
|
|
next = ensurePluginAllowlisted(next, resolvedId);
|
|
return { config: next, enabled: true };
|
|
}
|