fix: sync built-in channel enablement across config paths

This commit is contained in:
Peter Steinberger
2026-02-23 19:40:32 +00:00
parent 69b17a37e8
commit 87603b5c45
10 changed files with 213 additions and 86 deletions

View File

@@ -1,6 +1,7 @@
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;
@@ -17,41 +18,7 @@ export function enablePluginInConfig(cfg: OpenClawConfig, pluginId: string): Plu
if (cfg.plugins?.deny?.includes(pluginId) || cfg.plugins?.deny?.includes(resolvedId)) {
return { config: cfg, enabled: false, reason: "blocked by denylist" };
}
if (builtInChannelId) {
const channels = cfg.channels as Record<string, unknown> | undefined;
const existing = channels?.[builtInChannelId];
const existingRecord =
existing && typeof existing === "object" && !Array.isArray(existing)
? (existing as Record<string, unknown>)
: {};
let next: OpenClawConfig = {
...cfg,
channels: {
...cfg.channels,
[builtInChannelId]: {
...existingRecord,
enabled: true,
},
},
};
next = ensurePluginAllowlisted(next, resolvedId);
return { config: next, enabled: true };
}
const entries = {
...cfg.plugins?.entries,
[resolvedId]: {
...(cfg.plugins?.entries?.[resolvedId] as Record<string, unknown> | undefined),
enabled: true,
},
};
let next: OpenClawConfig = {
...cfg,
plugins: {
...cfg.plugins,
entries,
},
};
let next = setPluginEnabledInConfig(cfg, resolvedId, true);
next = ensurePluginAllowlisted(next, resolvedId);
return { config: next, enabled: true };
}