agenticmail 0.3.11 → 0.3.12
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 +89 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4338,6 +4338,9 @@ async function cmdSetup() {
|
|
|
4338
4338
|
} else if (!existingEmail) {
|
|
4339
4339
|
info2("No problem! You can set up email anytime by running this again.");
|
|
4340
4340
|
}
|
|
4341
|
+
if (serverReady) {
|
|
4342
|
+
await registerWithOpenClaw(result.config);
|
|
4343
|
+
}
|
|
4341
4344
|
printSummary(result, false);
|
|
4342
4345
|
if (serverReady) {
|
|
4343
4346
|
await interactiveShell({ config: result.config, onExit: cleanupChild });
|
|
@@ -4360,6 +4363,92 @@ function printSummary(result, exitAfter) {
|
|
|
4360
4363
|
process.exit(0);
|
|
4361
4364
|
}
|
|
4362
4365
|
}
|
|
4366
|
+
async function registerWithOpenClaw(config) {
|
|
4367
|
+
const openclawConfig = join(homedir(), ".openclaw", "openclaw.json");
|
|
4368
|
+
if (!existsSync2(openclawConfig)) return;
|
|
4369
|
+
try {
|
|
4370
|
+
const raw = readFileSync2(openclawConfig, "utf8");
|
|
4371
|
+
const ocConfig = JSON.parse(raw);
|
|
4372
|
+
if (ocConfig.plugins?.entries?.agenticmail?.config?.apiKey) {
|
|
4373
|
+
ok2(`OpenClaw integration already configured`);
|
|
4374
|
+
return;
|
|
4375
|
+
}
|
|
4376
|
+
let pluginPath = null;
|
|
4377
|
+
try {
|
|
4378
|
+
const resolved = import.meta.resolve("@agenticmail/openclaw");
|
|
4379
|
+
const resolvedPath = fileURLToPath(resolved);
|
|
4380
|
+
pluginPath = dirname(dirname(resolvedPath));
|
|
4381
|
+
} catch {
|
|
4382
|
+
}
|
|
4383
|
+
if (!pluginPath) {
|
|
4384
|
+
const thisDir = dirname(fileURLToPath(import.meta.url));
|
|
4385
|
+
let dir = thisDir;
|
|
4386
|
+
for (let i = 0; i < 10; i++) {
|
|
4387
|
+
const candidate = join(dir, "node_modules", "@agenticmail", "openclaw");
|
|
4388
|
+
if (existsSync2(join(candidate, "package.json"))) {
|
|
4389
|
+
pluginPath = candidate;
|
|
4390
|
+
break;
|
|
4391
|
+
}
|
|
4392
|
+
const parent = dirname(dir);
|
|
4393
|
+
if (parent === dir) break;
|
|
4394
|
+
dir = parent;
|
|
4395
|
+
}
|
|
4396
|
+
}
|
|
4397
|
+
if (!pluginPath) {
|
|
4398
|
+
try {
|
|
4399
|
+
const { execSync } = await import("child_process");
|
|
4400
|
+
const prefix = execSync("npm prefix -g", { timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] }).toString().trim();
|
|
4401
|
+
const globalCandidate = join(prefix, "lib", "node_modules", "@agenticmail", "openclaw");
|
|
4402
|
+
if (existsSync2(join(globalCandidate, "package.json"))) pluginPath = globalCandidate;
|
|
4403
|
+
if (!pluginPath) {
|
|
4404
|
+
const globalCandidate2 = join(prefix, "node_modules", "@agenticmail", "openclaw");
|
|
4405
|
+
if (existsSync2(join(globalCandidate2, "package.json"))) pluginPath = globalCandidate2;
|
|
4406
|
+
}
|
|
4407
|
+
} catch {
|
|
4408
|
+
}
|
|
4409
|
+
}
|
|
4410
|
+
if (!pluginPath) return;
|
|
4411
|
+
try {
|
|
4412
|
+
pluginPath = realpathSync(pluginPath);
|
|
4413
|
+
} catch {
|
|
4414
|
+
}
|
|
4415
|
+
let apiKey = "";
|
|
4416
|
+
try {
|
|
4417
|
+
const base = `http://${config.api.host}:${config.api.port}`;
|
|
4418
|
+
const resp = await fetch(`${base}/api/agenticmail/accounts`, {
|
|
4419
|
+
headers: { "Authorization": `Bearer ${config.masterKey}` },
|
|
4420
|
+
signal: AbortSignal.timeout(5e3)
|
|
4421
|
+
});
|
|
4422
|
+
if (resp.ok) {
|
|
4423
|
+
const data = await resp.json();
|
|
4424
|
+
const agents = data.agents || data || [];
|
|
4425
|
+
if (agents.length > 0) {
|
|
4426
|
+
apiKey = agents[0].apiKey;
|
|
4427
|
+
}
|
|
4428
|
+
}
|
|
4429
|
+
} catch {
|
|
4430
|
+
}
|
|
4431
|
+
if (!apiKey) return;
|
|
4432
|
+
if (!ocConfig.plugins) ocConfig.plugins = {};
|
|
4433
|
+
if (!ocConfig.plugins.load) ocConfig.plugins.load = {};
|
|
4434
|
+
if (!ocConfig.plugins.load.paths) ocConfig.plugins.load.paths = [];
|
|
4435
|
+
if (!ocConfig.plugins.entries) ocConfig.plugins.entries = {};
|
|
4436
|
+
if (!ocConfig.plugins.load.paths.includes(pluginPath)) {
|
|
4437
|
+
ocConfig.plugins.load.paths.push(pluginPath);
|
|
4438
|
+
}
|
|
4439
|
+
ocConfig.plugins.entries.agenticmail = {
|
|
4440
|
+
enabled: true,
|
|
4441
|
+
config: {
|
|
4442
|
+
apiUrl: `http://${config.api.host}:${config.api.port}`,
|
|
4443
|
+
apiKey,
|
|
4444
|
+
masterKey: config.masterKey
|
|
4445
|
+
}
|
|
4446
|
+
};
|
|
4447
|
+
writeFileSync2(openclawConfig, JSON.stringify(ocConfig, null, 2) + "\n", "utf8");
|
|
4448
|
+
ok2(`OpenClaw integration configured \u2014 your agents can now use email!`);
|
|
4449
|
+
} catch {
|
|
4450
|
+
}
|
|
4451
|
+
}
|
|
4363
4452
|
async function setupRelay(config) {
|
|
4364
4453
|
log2(" Which email service do you use?");
|
|
4365
4454
|
log2(` ${c2.cyan("1.")} Gmail`);
|