





















@@ -0,0 +1,105 @@
1+import type { OpenClawConfig } from "../config/types.openclaw.js";
2+import { isRecord } from "../utils.js";
3+4+function hasOwnValue(record: Record<string, unknown>, key: string): boolean {
5+return Object.prototype.hasOwnProperty.call(record, key);
6+}
7+8+function mergeChannelActivationSections(params: {
9+runtimeConfig: OpenClawConfig;
10+activationConfig: OpenClawConfig;
11+}): OpenClawConfig {
12+const activationChannels = params.activationConfig.channels;
13+if (!isRecord(activationChannels)) {
14+return params.runtimeConfig;
15+}
16+17+const runtimeChannels = isRecord(params.runtimeConfig.channels)
18+ ? params.runtimeConfig.channels
19+ : {};
20+let nextChannels: Record<string, unknown> | undefined;
21+22+for (const [channelId, activationChannel] of Object.entries(activationChannels)) {
23+if (!isRecord(activationChannel) || !hasOwnValue(activationChannel, "enabled")) {
24+continue;
25+}
26+const runtimeChannel = runtimeChannels[channelId];
27+const runtimeChannelRecord = isRecord(runtimeChannel) ? runtimeChannel : {};
28+nextChannels ??= { ...runtimeChannels };
29+nextChannels[channelId] = {
30+ ...runtimeChannelRecord,
31+enabled: activationChannel.enabled,
32+};
33+}
34+35+if (nextChannels === undefined) {
36+return params.runtimeConfig;
37+}
38+return {
39+ ...params.runtimeConfig,
40+channels: nextChannels as OpenClawConfig["channels"],
41+};
42+}
43+44+function mergePluginActivationSections(params: {
45+runtimeConfig: OpenClawConfig;
46+activationConfig: OpenClawConfig;
47+}): OpenClawConfig {
48+const activationPlugins = params.activationConfig.plugins;
49+if (!isRecord(activationPlugins)) {
50+return params.runtimeConfig;
51+}
52+53+const runtimePlugins = isRecord(params.runtimeConfig.plugins) ? params.runtimeConfig.plugins : {};
54+let nextPlugins: Record<string, unknown> | undefined;
55+56+if (Array.isArray(activationPlugins.allow)) {
57+nextPlugins = {
58+ ...runtimePlugins,
59+allow: [...activationPlugins.allow],
60+};
61+}
62+63+const activationEntries = activationPlugins.entries;
64+if (isRecord(activationEntries)) {
65+const runtimeEntries = isRecord(runtimePlugins.entries) ? runtimePlugins.entries : {};
66+let nextEntries: Record<string, unknown> | undefined;
67+for (const [pluginId, activationEntry] of Object.entries(activationEntries)) {
68+if (!isRecord(activationEntry) || !hasOwnValue(activationEntry, "enabled")) {
69+continue;
70+}
71+const runtimeEntry = runtimeEntries[pluginId];
72+const runtimeEntryRecord = isRecord(runtimeEntry) ? runtimeEntry : {};
73+nextEntries ??= { ...runtimeEntries };
74+nextEntries[pluginId] = {
75+ ...runtimeEntryRecord,
76+enabled: activationEntry.enabled,
77+};
78+}
79+if (nextEntries !== undefined) {
80+nextPlugins = {
81+ ...runtimePlugins,
82+ ...nextPlugins,
83+entries: nextEntries,
84+};
85+}
86+}
87+88+if (nextPlugins === undefined) {
89+return params.runtimeConfig;
90+}
91+return {
92+ ...params.runtimeConfig,
93+plugins: nextPlugins as OpenClawConfig["plugins"],
94+};
95+}
96+97+export function mergeActivationSectionsIntoRuntimeConfig(params: {
98+runtimeConfig: OpenClawConfig;
99+activationConfig: OpenClawConfig;
100+}): OpenClawConfig {
101+return mergePluginActivationSections({
102+ ...params,
103+runtimeConfig: mergeChannelActivationSections(params),
104+});
105+}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。