agenticmail 0.3.14 → 0.3.16

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 +60 -72
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -4370,55 +4370,22 @@ 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 {
4382
+ const pluginDir = resolveOpenClawPluginDir();
4383
+ if (!pluginDir) {
4384
+ info2(`Install the OpenClaw plugin first: ${c2.green("npm i @agenticmail/openclaw")}`);
4385
+ info2(`Then run: ${c2.green("agenticmail openclaw")}`);
4386
+ return;
4420
4387
  }
4421
- let apiKey = "";
4388
+ let agentApiKey;
4422
4389
  try {
4423
4390
  const base = `http://${config.api.host}:${config.api.port}`;
4424
4391
  const resp = await fetch(`${base}/api/agenticmail/accounts`, {
@@ -4428,31 +4395,19 @@ async function registerWithOpenClaw(config) {
4428
4395
  if (resp.ok) {
4429
4396
  const data = await resp.json();
4430
4397
  const agents = data.agents || data || [];
4431
- if (agents.length > 0) {
4432
- apiKey = agents[0].apiKey;
4433
- }
4398
+ if (agents.length > 0) agentApiKey = agents[0].apiKey;
4434
4399
  }
4435
4400
  } catch {
4436
4401
  }
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);
4402
+ if (!agentApiKey) return;
4403
+ const apiUrl = `http://${config.api.host}:${config.api.port}`;
4404
+ const updated = mergePluginConfig(existing, apiUrl, config.masterKey, agentApiKey, pluginDir);
4405
+ writeFileSync2(openclawConfigPath, JSON.stringify(updated, null, 2) + "\n");
4406
+ if (pluginDir) ok2(`Plugin found: ${c2.cyan(pluginDir)}`);
4407
+ ok2(`OpenClaw config updated: ${c2.cyan(openclawConfigPath)}`);
4408
+ if (!existing?.hooks?.enabled && updated?.hooks?.enabled) {
4409
+ ok2(`${c2.bold("Agent auto-spawn")} enabled \u2014 call_agent will auto-create sessions`);
4444
4410
  }
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
4451
- }
4452
- };
4453
- writeFileSync2(openclawConfig, JSON.stringify(ocConfig, null, 2) + "\n", "utf8");
4454
- ok2(`OpenClaw config updated: ${c2.cyan(openclawConfig)}`);
4455
- if (pluginPath) ok2(`Plugin found: ${c2.cyan(pluginPath)}`);
4456
4411
  let hasOpenClawCli = false;
4457
4412
  try {
4458
4413
  const { execSync } = await import("child_process");
@@ -4795,25 +4750,58 @@ async function setupDomain(config) {
4795
4750
  }
4796
4751
  }
4797
4752
  function resolveOpenClawPluginDir() {
4753
+ const pluginMarker = "openclaw.plugin.json";
4754
+ const pkgPath = join("node_modules", "@agenticmail", "openclaw");
4798
4755
  const thisDir = dirname(fileURLToPath(import.meta.url));
4799
4756
  let dir = thisDir;
4800
4757
  for (let i = 0; i < 10; i++) {
4801
- const candidate = join(dir, "node_modules", "@agenticmail", "openclaw");
4802
- if (existsSync2(join(candidate, "openclaw.plugin.json"))) return realpathSync(candidate);
4758
+ const candidate = join(dir, pkgPath);
4759
+ if (existsSync2(join(candidate, pluginMarker))) return realpathSync(candidate);
4803
4760
  const parent = dirname(dir);
4804
4761
  if (parent === dir) break;
4805
4762
  dir = parent;
4806
4763
  }
4807
- const candidates = [
4764
+ const monorepo = [
4808
4765
  join(thisDir, "..", "..", "packages", "openclaw"),
4809
4766
  join(thisDir, "..", "packages", "openclaw")
4810
4767
  ];
4811
- for (const p of candidates) {
4812
- if (existsSync2(join(p, "openclaw.plugin.json"))) return p;
4768
+ for (const p of monorepo) {
4769
+ if (existsSync2(join(p, pluginMarker))) return p;
4770
+ }
4771
+ const userDirs = [
4772
+ join(process.cwd(), pkgPath),
4773
+ join(homedir(), pkgPath)
4774
+ ];
4775
+ for (const p of userDirs) {
4776
+ if (existsSync2(join(p, pluginMarker))) {
4777
+ try {
4778
+ return realpathSync(p);
4779
+ } catch {
4780
+ return p;
4781
+ }
4782
+ }
4783
+ }
4784
+ try {
4785
+ const cp = createRequire(import.meta.url)("node:child_process");
4786
+ const prefix = cp.execSync("npm prefix -g", { timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] }).toString().trim();
4787
+ const globalCandidates = [
4788
+ join(prefix, "lib", pkgPath),
4789
+ join(prefix, pkgPath)
4790
+ ];
4791
+ for (const p of globalCandidates) {
4792
+ if (existsSync2(join(p, pluginMarker))) {
4793
+ try {
4794
+ return realpathSync(p);
4795
+ } catch {
4796
+ return p;
4797
+ }
4798
+ }
4799
+ }
4800
+ } catch {
4813
4801
  }
4814
4802
  try {
4815
- const require2 = createRequire(import.meta.url);
4816
- const resolved = require2.resolve("@agenticmail/openclaw/openclaw.plugin.json");
4803
+ const req = createRequire(import.meta.url);
4804
+ const resolved = req.resolve("@agenticmail/openclaw/openclaw.plugin.json");
4817
4805
  return dirname(resolved);
4818
4806
  } catch {
4819
4807
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agenticmail",
3
- "version": "0.3.14",
3
+ "version": "0.3.16",
4
4
  "description": "Email infrastructure for AI agents — send and receive real email programmatically",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",