agenticmail 0.3.13 → 0.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +37 -64
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4370,55 +4370,17 @@ function printSummary(result, exitAfter) {
|
|
|
4370
4370
|
}
|
|
4371
4371
|
}
|
|
4372
4372
|
async function registerWithOpenClaw(config) {
|
|
4373
|
-
const
|
|
4374
|
-
if (!
|
|
4373
|
+
const openclawConfigPath = findOpenClawConfig();
|
|
4374
|
+
if (!openclawConfigPath) return;
|
|
4375
4375
|
try {
|
|
4376
|
-
const raw = readFileSync2(
|
|
4377
|
-
const
|
|
4378
|
-
if (
|
|
4376
|
+
const raw = readFileSync2(openclawConfigPath, "utf-8");
|
|
4377
|
+
const existing = JSON5.parse(raw);
|
|
4378
|
+
if (existing.plugins?.entries?.agenticmail?.config?.apiKey) {
|
|
4379
4379
|
ok2(`OpenClaw integration already configured`);
|
|
4380
4380
|
return;
|
|
4381
4381
|
}
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
const resolved = import.meta.resolve("@agenticmail/openclaw");
|
|
4385
|
-
const resolvedPath = fileURLToPath(resolved);
|
|
4386
|
-
pluginPath = dirname(dirname(resolvedPath));
|
|
4387
|
-
} catch {
|
|
4388
|
-
}
|
|
4389
|
-
if (!pluginPath) {
|
|
4390
|
-
const thisDir = dirname(fileURLToPath(import.meta.url));
|
|
4391
|
-
let dir = thisDir;
|
|
4392
|
-
for (let i = 0; i < 10; i++) {
|
|
4393
|
-
const candidate = join(dir, "node_modules", "@agenticmail", "openclaw");
|
|
4394
|
-
if (existsSync2(join(candidate, "package.json"))) {
|
|
4395
|
-
pluginPath = candidate;
|
|
4396
|
-
break;
|
|
4397
|
-
}
|
|
4398
|
-
const parent = dirname(dir);
|
|
4399
|
-
if (parent === dir) break;
|
|
4400
|
-
dir = parent;
|
|
4401
|
-
}
|
|
4402
|
-
}
|
|
4403
|
-
if (!pluginPath) {
|
|
4404
|
-
try {
|
|
4405
|
-
const { execSync } = await import("child_process");
|
|
4406
|
-
const prefix = execSync("npm prefix -g", { timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] }).toString().trim();
|
|
4407
|
-
const globalCandidate = join(prefix, "lib", "node_modules", "@agenticmail", "openclaw");
|
|
4408
|
-
if (existsSync2(join(globalCandidate, "package.json"))) pluginPath = globalCandidate;
|
|
4409
|
-
if (!pluginPath) {
|
|
4410
|
-
const globalCandidate2 = join(prefix, "node_modules", "@agenticmail", "openclaw");
|
|
4411
|
-
if (existsSync2(join(globalCandidate2, "package.json"))) pluginPath = globalCandidate2;
|
|
4412
|
-
}
|
|
4413
|
-
} catch {
|
|
4414
|
-
}
|
|
4415
|
-
}
|
|
4416
|
-
if (!pluginPath) return;
|
|
4417
|
-
try {
|
|
4418
|
-
pluginPath = realpathSync(pluginPath);
|
|
4419
|
-
} catch {
|
|
4420
|
-
}
|
|
4421
|
-
let apiKey = "";
|
|
4382
|
+
const pluginDir = resolveOpenClawPluginDir();
|
|
4383
|
+
let agentApiKey;
|
|
4422
4384
|
try {
|
|
4423
4385
|
const base = `http://${config.api.host}:${config.api.port}`;
|
|
4424
4386
|
const resp = await fetch(`${base}/api/agenticmail/accounts`, {
|
|
@@ -4428,30 +4390,41 @@ async function registerWithOpenClaw(config) {
|
|
|
4428
4390
|
if (resp.ok) {
|
|
4429
4391
|
const data = await resp.json();
|
|
4430
4392
|
const agents = data.agents || data || [];
|
|
4431
|
-
if (agents.length > 0)
|
|
4432
|
-
apiKey = agents[0].apiKey;
|
|
4433
|
-
}
|
|
4393
|
+
if (agents.length > 0) agentApiKey = agents[0].apiKey;
|
|
4434
4394
|
}
|
|
4435
4395
|
} catch {
|
|
4436
4396
|
}
|
|
4437
|
-
if (!
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
if (
|
|
4442
|
-
|
|
4443
|
-
|
|
4397
|
+
if (!agentApiKey) return;
|
|
4398
|
+
const apiUrl = `http://${config.api.host}:${config.api.port}`;
|
|
4399
|
+
const updated = mergePluginConfig(existing, apiUrl, config.masterKey, agentApiKey, pluginDir);
|
|
4400
|
+
writeFileSync2(openclawConfigPath, JSON.stringify(updated, null, 2) + "\n");
|
|
4401
|
+
if (pluginDir) ok2(`Plugin found: ${c2.cyan(pluginDir)}`);
|
|
4402
|
+
ok2(`OpenClaw config updated: ${c2.cyan(openclawConfigPath)}`);
|
|
4403
|
+
if (!existing?.hooks?.enabled && updated?.hooks?.enabled) {
|
|
4404
|
+
ok2(`${c2.bold("Agent auto-spawn")} enabled \u2014 call_agent will auto-create sessions`);
|
|
4444
4405
|
}
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4406
|
+
let hasOpenClawCli = false;
|
|
4407
|
+
try {
|
|
4408
|
+
const { execSync } = await import("child_process");
|
|
4409
|
+
execSync("which openclaw", { stdio: "ignore" });
|
|
4410
|
+
hasOpenClawCli = true;
|
|
4411
|
+
} catch {
|
|
4412
|
+
}
|
|
4413
|
+
if (hasOpenClawCli) {
|
|
4414
|
+
log2("");
|
|
4415
|
+
const restartSpinner = new Spinner("gateway", "Restarting OpenClaw gateway...");
|
|
4416
|
+
restartSpinner.start();
|
|
4417
|
+
try {
|
|
4418
|
+
const { execSync } = await import("child_process");
|
|
4419
|
+
execSync("openclaw gateway restart", { stdio: "pipe", timeout: 3e4 });
|
|
4420
|
+
restartSpinner.succeed("OpenClaw gateway restarted");
|
|
4421
|
+
} catch {
|
|
4422
|
+
restartSpinner.fail("Gateway restart failed");
|
|
4423
|
+
log2(` Run manually: ${c2.green("openclaw gateway restart")}`);
|
|
4451
4424
|
}
|
|
4452
|
-
}
|
|
4453
|
-
|
|
4454
|
-
|
|
4425
|
+
} else {
|
|
4426
|
+
info2(`Restart OpenClaw to pick up the changes: ${c2.green("openclaw gateway restart")}`);
|
|
4427
|
+
}
|
|
4455
4428
|
} catch {
|
|
4456
4429
|
}
|
|
4457
4430
|
}
|