fix(config): persist built-in channel enable state in channels

Co-authored-by: HirokiKobayashi-R <HirokiKobayashi-R@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-02-22 19:18:08 +01:00
parent 1bd79add8f
commit 8839162b97
5 changed files with 112 additions and 15 deletions

View File

@@ -31,4 +31,12 @@ describe("enablePluginInConfig", () => {
expect(result.enabled).toBe(false);
expect(result.reason).toBe("blocked by denylist");
});
it("writes built-in channels to channels.<id>.enabled instead of plugins.entries", () => {
const cfg: OpenClawConfig = {};
const result = enablePluginInConfig(cfg, "telegram");
expect(result.enabled).toBe(true);
expect(result.config.channels?.telegram?.enabled).toBe(true);
expect(result.config.plugins?.entries?.telegram).toBeUndefined();
});
});

View File

@@ -1,3 +1,4 @@
import { normalizeChatChannelId } from "../channels/registry.js";
import type { OpenClawConfig } from "../config/config.js";
import { ensurePluginAllowlisted } from "../config/plugins-allowlist.js";
@@ -8,17 +9,40 @@ export type PluginEnableResult = {
};
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)) {
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>)
: {};
return {
config: {
...cfg,
channels: {
...cfg.channels,
[builtInChannelId]: {
...existingRecord,
enabled: true,
},
},
},
enabled: true,
};
}
const entries = {
...cfg.plugins?.entries,
[pluginId]: {
...(cfg.plugins?.entries?.[pluginId] as Record<string, unknown> | undefined),
[resolvedId]: {
...(cfg.plugins?.entries?.[resolvedId] as Record<string, unknown> | undefined),
enabled: true,
},
};
@@ -29,6 +53,6 @@ export function enablePluginInConfig(cfg: OpenClawConfig, pluginId: string): Plu
entries,
},
};
next = ensurePluginAllowlisted(next, pluginId);
next = ensurePluginAllowlisted(next, resolvedId);
return { config: next, enabled: true };
}