mirror of https://github.com/openclaw/openclaw.git
refactor: centralize plugin allowlist mutation
This commit is contained in:
parent
7147cd9cc0
commit
5195179150
|
|
@ -1,3 +1,4 @@
|
|||
import type { OpenClawConfig } from "./config.js";
|
||||
import { normalizeProviderId } from "../agents/model-selection.js";
|
||||
import {
|
||||
getChannelPluginCatalogEntry,
|
||||
|
|
@ -10,7 +11,7 @@ import {
|
|||
} from "../channels/registry.js";
|
||||
import { isRecord } from "../utils.js";
|
||||
import { hasAnyWhatsAppAuth } from "../web/accounts.js";
|
||||
import type { OpenClawConfig } from "./config.js";
|
||||
import { ensurePluginAllowlisted } from "./plugins-allowlist.js";
|
||||
|
||||
type PluginEnableChange = {
|
||||
pluginId: string;
|
||||
|
|
@ -388,20 +389,6 @@ function shouldSkipPreferredPluginAutoEnable(
|
|||
return false;
|
||||
}
|
||||
|
||||
function ensureAllowlisted(cfg: OpenClawConfig, pluginId: string): OpenClawConfig {
|
||||
const allow = cfg.plugins?.allow;
|
||||
if (!Array.isArray(allow) || allow.includes(pluginId)) {
|
||||
return cfg;
|
||||
}
|
||||
return {
|
||||
...cfg,
|
||||
plugins: {
|
||||
...cfg.plugins,
|
||||
allow: [...allow, pluginId],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function registerPluginEntry(cfg: OpenClawConfig, pluginId: string): OpenClawConfig {
|
||||
const entries = {
|
||||
...cfg.plugins?.entries,
|
||||
|
|
@ -463,7 +450,7 @@ export function applyPluginAutoEnable(params: {
|
|||
continue;
|
||||
}
|
||||
next = registerPluginEntry(next, entry.pluginId);
|
||||
next = ensureAllowlisted(next, entry.pluginId);
|
||||
next = ensurePluginAllowlisted(next, entry.pluginId);
|
||||
changes.push(formatAutoEnableChange(entry));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
import type { OpenClawConfig } from "./config.js";
|
||||
|
||||
export function ensurePluginAllowlisted(cfg: OpenClawConfig, pluginId: string): OpenClawConfig {
|
||||
const allow = cfg.plugins?.allow;
|
||||
if (!Array.isArray(allow) || allow.includes(pluginId)) {
|
||||
return cfg;
|
||||
}
|
||||
return {
|
||||
...cfg,
|
||||
plugins: {
|
||||
...cfg.plugins,
|
||||
allow: [...allow, pluginId],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { ensurePluginAllowlisted } from "../config/plugins-allowlist.js";
|
||||
|
||||
export type PluginEnableResult = {
|
||||
config: OpenClawConfig;
|
||||
|
|
@ -6,20 +7,6 @@ export type PluginEnableResult = {
|
|||
reason?: string;
|
||||
};
|
||||
|
||||
function ensureAllowlisted(cfg: OpenClawConfig, pluginId: string): OpenClawConfig {
|
||||
const allow = cfg.plugins?.allow;
|
||||
if (!Array.isArray(allow) || allow.includes(pluginId)) {
|
||||
return cfg;
|
||||
}
|
||||
return {
|
||||
...cfg,
|
||||
plugins: {
|
||||
...cfg.plugins,
|
||||
allow: [...allow, pluginId],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function enablePluginInConfig(cfg: OpenClawConfig, pluginId: string): PluginEnableResult {
|
||||
if (cfg.plugins?.enabled === false) {
|
||||
return { config: cfg, enabled: false, reason: "plugins disabled" };
|
||||
|
|
@ -42,6 +29,6 @@ export function enablePluginInConfig(cfg: OpenClawConfig, pluginId: string): Plu
|
|||
entries,
|
||||
},
|
||||
};
|
||||
next = ensureAllowlisted(next, pluginId);
|
||||
next = ensurePluginAllowlisted(next, pluginId);
|
||||
return { config: next, enabled: true };
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue