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.
Files changed (2) hide show
  1. package/dist/cli.js +37 -64
  2. 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 openclawConfig = join(homedir(), ".openclaw", "openclaw.json");
4374
- if (!existsSync2(openclawConfig)) return;
4373
+ const openclawConfigPath = findOpenClawConfig();
4374
+ if (!openclawConfigPath) return;
4375
4375
  try {
4376
- const raw = readFileSync2(openclawConfig, "utf8");
4377
- const ocConfig = JSON.parse(raw);
4378
- if (ocConfig.plugins?.entries?.agenticmail?.config?.apiKey) {
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
- let pluginPath = null;
4383
- try {
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 (!apiKey) return;
4438
- if (!ocConfig.plugins) ocConfig.plugins = {};
4439
- if (!ocConfig.plugins.load) ocConfig.plugins.load = {};
4440
- if (!ocConfig.plugins.load.paths) ocConfig.plugins.load.paths = [];
4441
- if (!ocConfig.plugins.entries) ocConfig.plugins.entries = {};
4442
- if (!ocConfig.plugins.load.paths.includes(pluginPath)) {
4443
- ocConfig.plugins.load.paths.push(pluginPath);
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
- ocConfig.plugins.entries.agenticmail = {
4446
- enabled: true,
4447
- config: {
4448
- apiUrl: `http://${config.api.host}:${config.api.port}`,
4449
- apiKey,
4450
- masterKey: config.masterKey
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
- writeFileSync2(openclawConfig, JSON.stringify(ocConfig, null, 2) + "\n", "utf8");
4454
- ok2(`OpenClaw integration configured \u2014 your agents can now use email!`);
4425
+ } else {
4426
+ info2(`Restart OpenClaw to pick up the changes: ${c2.green("openclaw gateway restart")}`);
4427
+ }
4455
4428
  } catch {
4456
4429
  }
4457
4430
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agenticmail",
3
- "version": "0.3.13",
3
+ "version": "0.3.15",
4
4
  "description": "Email infrastructure for AI agents — send and receive real email programmatically",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",