fix(plugin): start moderator reliably and colocate no-reply-api under plugin dir

This commit is contained in:
2026-03-08 06:57:22 +00:00
parent a2781139b0
commit bb10d6913e
3 changed files with 19 additions and 11 deletions

View File

@@ -16,7 +16,7 @@ export function startNoReplyApi(
return;
}
const serverPath = path.resolve(pluginDir, "..", "no-reply-api", "server.mjs");
const serverPath = path.resolve(pluginDir, "no-reply-api", "server.mjs");
logger.info(`dirigent: resolved serverPath=${serverPath}`);
if (!fs.existsSync(serverPath)) {

View File

@@ -77,22 +77,21 @@ export default {
api.on("gateway_start", () => {
api.logger.info(`dirigent: gateway_start event received`);
const live = getLivePluginConfig(api, baseConfig as DirigentConfig);
// Check no-reply-api server file exists
const serverPath = path.resolve(pluginDir, "..", "no-reply-api", "server.mjs");
const serverPath = path.resolve(pluginDir, "no-reply-api", "server.mjs");
api.logger.info(`dirigent: checking no-reply-api server at ${serverPath}, exists=${fs.existsSync(serverPath)}`);
// Additional debug: list what's in the parent directory
const parentDir = path.resolve(pluginDir, "..");
// Additional debug: list what's in the plugin directory
try {
const entries = fs.readdirSync(parentDir);
api.logger.info(`dirigent: parent dir (${parentDir}) entries: ${JSON.stringify(entries)}`);
const entries = fs.readdirSync(pluginDir);
api.logger.info(`dirigent: plugin dir (${pluginDir}) entries: ${JSON.stringify(entries)}`);
} catch (e) {
api.logger.warn(`dirigent: cannot read parent dir: ${String(e)}`);
api.logger.warn(`dirigent: cannot read plugin dir: ${String(e)}`);
}
startNoReplyApi(api.logger, pluginDir, Number(live.noReplyPort || 8787));
const live = getLivePluginConfig(api, baseConfig as DirigentConfig);
api.logger.info(`dirigent: config loaded, moderatorBotToken=${live.moderatorBotToken ? "[set]" : "[not set]"}`);
if (live.moderatorBotToken) {

View File

@@ -79,7 +79,7 @@ const __dirname = path.dirname(new URL(import.meta.url).pathname);
const REPO_ROOT = path.resolve(__dirname, "..");
const PLUGINS_DIR = path.join(OPENCLAW_DIR, "plugins");
const PLUGIN_INSTALL_DIR = path.join(PLUGINS_DIR, "dirigent");
const NO_REPLY_INSTALL_DIR = path.join(PLUGINS_DIR, "no-reply-api");
const NO_REPLY_INSTALL_DIR = path.join(PLUGIN_INSTALL_DIR, "no-reply-api");
const NO_REPLY_PROVIDER_ID = process.env.NO_REPLY_PROVIDER_ID || "dirigentway";
const NO_REPLY_MODEL_ID = process.env.NO_REPLY_MODEL_ID || "no-reply";
@@ -155,7 +155,7 @@ if (mode === "install") {
const pluginSrc = path.resolve(REPO_ROOT, "plugin");
const noReplySrc = path.resolve(REPO_ROOT, "no-reply-api");
const distPlugin = path.resolve(REPO_ROOT, "dist", "dirigent");
const distNoReply = path.resolve(REPO_ROOT, "dist", "no-reply-api");
const distNoReply = path.resolve(REPO_ROOT, "dist", "dirigent", "no-reply-api");
syncDirRecursive(pluginSrc, distPlugin);
syncDirRecursive(noReplySrc, distNoReply);
@@ -164,6 +164,13 @@ if (mode === "install") {
syncDirRecursive(distPlugin, PLUGIN_INSTALL_DIR);
syncDirRecursive(distNoReply, NO_REPLY_INSTALL_DIR);
// cleanup old layout from previous versions
const oldTopLevelNoReply = path.join(PLUGINS_DIR, "no-reply-api");
if (fs.existsSync(oldTopLevelNoReply)) {
fs.rmSync(oldTopLevelNoReply, { recursive: true, force: true });
ok(`removed legacy path: ${oldTopLevelNoReply}`);
}
if (!fs.existsSync(CHANNEL_POLICIES_FILE)) {
fs.mkdirSync(path.dirname(CHANNEL_POLICIES_FILE), { recursive: true });
fs.writeFileSync(CHANNEL_POLICIES_FILE, `${CHANNEL_POLICIES_JSON}\n`);
@@ -263,6 +270,8 @@ if (mode === "uninstall") {
if (fs.existsSync(NO_REPLY_INSTALL_DIR)) fs.rmSync(NO_REPLY_INSTALL_DIR, { recursive: true, force: true });
const legacyNoReply = path.join(PLUGINS_DIR, "dirigent-no-reply-api");
if (fs.existsSync(legacyNoReply)) fs.rmSync(legacyNoReply, { recursive: true, force: true });
const oldTopLevelNoReply = path.join(PLUGINS_DIR, "no-reply-api");
if (fs.existsSync(oldTopLevelNoReply)) fs.rmSync(oldTopLevelNoReply, { recursive: true, force: true });
ok("removed installed files");
console.log("↻ restart gateway: openclaw gateway restart");