2026-02-22 19:18:08 +01:00
|
|
|
import { normalizeChatChannelId } from "../channels/registry.js";
|
2026-01-30 03:15:10 +01:00
|
|
|
import type { OpenClawConfig } from "../config/config.js";
|
2026-02-17 00:44:43 +00:00
|
|
|
import { ensurePluginAllowlisted } from "../config/plugins-allowlist.js";
|
2026-02-23 19:40:32 +00:00
|
|
|
import { setPluginEnabledInConfig } from "./toggle-config.js";
|
2026-01-18 16:22:50 +00:00
|
|
|
|
|
|
|
|
export type PluginEnableResult = {
|
2026-01-30 03:15:10 +01:00
|
|
|
config: OpenClawConfig;
|
2026-01-18 16:22:50 +00:00
|
|
|
enabled: boolean;
|
|
|
|
|
reason?: string;
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-30 03:15:10 +01:00
|
|
|
export function enablePluginInConfig(cfg: OpenClawConfig, pluginId: string): PluginEnableResult {
|
2026-02-22 19:18:08 +01:00
|
|
|
const builtInChannelId = normalizeChatChannelId(pluginId);
|
|
|
|
|
const resolvedId = builtInChannelId ?? pluginId;
|
2026-01-18 16:22:50 +00:00
|
|
|
if (cfg.plugins?.enabled === false) {
|
|
|
|
|
return { config: cfg, enabled: false, reason: "plugins disabled" };
|
|
|
|
|
}
|
2026-02-22 19:18:08 +01:00
|
|
|
if (cfg.plugins?.deny?.includes(pluginId) || cfg.plugins?.deny?.includes(resolvedId)) {
|
2026-01-18 16:22:50 +00:00
|
|
|
return { config: cfg, enabled: false, reason: "blocked by denylist" };
|
|
|
|
|
}
|
2026-02-23 19:40:32 +00:00
|
|
|
let next = setPluginEnabledInConfig(cfg, resolvedId, true);
|
2026-02-22 19:18:08 +01:00
|
|
|
next = ensurePluginAllowlisted(next, resolvedId);
|
2026-01-18 16:22:50 +00:00
|
|
|
return { config: next, enabled: true };
|
|
|
|
|
}
|