Compare commits

..

2 Commits

2 changed files with 32 additions and 25 deletions

View File

@@ -514,8 +514,7 @@ export default {
ensurePolicyStateLoaded(api, liveAtRegister); ensurePolicyStateLoaded(api, liveAtRegister);
// Resolve plugin directory for locating sibling modules (no-reply-api/) // Resolve plugin directory for locating sibling modules (no-reply-api/)
// Use api.resolvePath to get the actual plugin directory in OpenClaw environment const pluginDir = path.dirname(new URL(import.meta.url).pathname);
const pluginDir = api.resolvePath(".");
// Gateway lifecycle: start/stop no-reply API and moderator bot with the gateway // Gateway lifecycle: start/stop no-reply API and moderator bot with the gateway
api.on("gateway_start", () => { api.on("gateway_start", () => {

View File

@@ -294,25 +294,22 @@ else {
const delta = rec.delta || { added: {}, replaced: {}, removed: {} }; const delta = rec.delta || { added: {}, replaced: {}, removed: {} };
try { try {
// ── IMPORTANT: Order matters for OpenClaw config validation ──────────── // ── Handle ADDED entries: remove them ─────────────────────────────────
// 1. First remove from allow (before deleting entry, otherwise validation fails) if (delta.added[PATH_PLUGIN_ENTRY] !== undefined) {
if (delta.added[PATH_PLUGINS_ALLOW] !== undefined) { const plugins = getJson("plugins") || {};
const allowList = getJson(PATH_PLUGINS_ALLOW) || []; plugins.entries = plugins.entries || {};
const idx = allowList.indexOf("dirigent"); delete plugins.entries.dirigent;
if (idx !== -1) { setJson("plugins", plugins);
allowList.splice(idx, 1);
setJson(PATH_PLUGINS_ALLOW, allowList);
console.log("[dirigent] removed 'dirigent' from plugins.allow");
}
}
// 2. Then remove entry
if (delta.added[PATH_PLUGIN_ENTRY] !== undefined || delta.replaced[PATH_PLUGIN_ENTRY] !== undefined) {
unsetPath(PATH_PLUGIN_ENTRY);
console.log("[dirigent] removed plugins.entries.dirigent"); console.log("[dirigent] removed plugins.entries.dirigent");
} }
// 3. Then remove plugin path (after entry is gone) if (delta.added[PATH_PROVIDER_ENTRY] !== undefined) {
const providers = getJson(PATH_PROVIDERS) || {};
delete providers[NO_REPLY_PROVIDER_ID];
setJson(PATH_PROVIDERS, providers);
console.log(`[dirigent] removed models.providers.${NO_REPLY_PROVIDER_ID}`);
}
if (delta.added[PATH_PLUGINS_LOAD] !== undefined) { if (delta.added[PATH_PLUGINS_LOAD] !== undefined) {
const plugins = getJson("plugins") || {}; const plugins = getJson("plugins") || {};
const paths = plugins.load?.paths || []; const paths = plugins.load?.paths || [];
@@ -325,15 +322,26 @@ else {
} }
} }
// 4. Finally remove provider // ── Handle plugins.allow ──────────────────────────────────────────────
if (delta.added[PATH_PROVIDER_ENTRY] !== undefined) { if (delta.added[PATH_PLUGINS_ALLOW] !== undefined) {
const providers = getJson(PATH_PROVIDERS) || {}; const allowList = getJson(PATH_PLUGINS_ALLOW) || [];
delete providers[NO_REPLY_PROVIDER_ID]; const idx = allowList.indexOf("dirigent");
setJson(PATH_PROVIDERS, providers); if (idx !== -1) {
console.log(`[dirigent] removed models.providers.${NO_REPLY_PROVIDER_ID}`); allowList.splice(idx, 1);
setJson(PATH_PLUGINS_ALLOW, allowList);
console.log("[dirigent] removed 'dirigent' from plugins.allow");
}
}
// ── Handle REPLACED entries: restore old value ────────────────────────
if (delta.replaced[PATH_PLUGIN_ENTRY] !== undefined) {
const plugins = getJson("plugins") || {};
plugins.entries = plugins.entries || {};
plugins.entries.dirigent = delta.replaced[PATH_PLUGIN_ENTRY];
setJson("plugins", plugins);
console.log("[dirigent] restored previous plugins.entries.dirigent");
} }
// ── Handle REPLACED provider: restore old value ───────────────────────
if (delta.replaced[PATH_PROVIDER_ENTRY] !== undefined) { if (delta.replaced[PATH_PROVIDER_ENTRY] !== undefined) {
const providers = getJson(PATH_PROVIDERS) || {}; const providers = getJson(PATH_PROVIDERS) || {};
providers[NO_REPLY_PROVIDER_ID] = delta.replaced[PATH_PROVIDER_ENTRY]; providers[NO_REPLY_PROVIDER_ID] = delta.replaced[PATH_PROVIDER_ENTRY];