mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 08:51:23 +00:00
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:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user