@agenticmail/cli 0.9.35 → 0.9.37

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 CHANGED
@@ -4927,6 +4927,75 @@ var NON_INTERACTIVE = false;
4927
4927
  function nonInteractiveDefault(value) {
4928
4928
  return NON_INTERACTIVE ? value : null;
4929
4929
  }
4930
+ async function cmdSetupRelay() {
4931
+ const args = process.argv.slice(3);
4932
+ if (args.some((a) => a === "--help" || a === "-h" || a === "help")) {
4933
+ log2("");
4934
+ log2(` ${c2.pinkBg(" \u{1F380} agenticmail setup-relay ")}`);
4935
+ log2("");
4936
+ log2(` ${c2.bold("Usage:")} agenticmail setup-relay`);
4937
+ log2("");
4938
+ log2(` Adds (or updates) the Gmail / Outlook / custom relay AgenticMail uses`);
4939
+ log2(` to send mail to the public internet. Run this YOURSELF \u2014 never paste`);
4940
+ log2(` the Gmail app password into an agent's chat (it would end up in the`);
4941
+ log2(` LLM's context / logs / conversation history).`);
4942
+ log2("");
4943
+ log2(` Password input is hidden (raw-mode stdin). The agent never sees it.`);
4944
+ log2("");
4945
+ log2(` Prereq: AgenticMail already bootstrapped (run \`agenticmail setup\` first).`);
4946
+ log2("");
4947
+ return;
4948
+ }
4949
+ const configPath = join(homedir(), ".agenticmail", "config.json");
4950
+ if (!existsSync2(configPath)) {
4951
+ log2("");
4952
+ fail2(`AgenticMail isn't set up yet \u2014 no config at ${c2.dim(configPath)}`);
4953
+ log2(` Run ${c2.cyan("agenticmail setup")} first, then come back to add the relay.`);
4954
+ log2("");
4955
+ process.exit(1);
4956
+ }
4957
+ let config;
4958
+ try {
4959
+ config = JSON.parse(readFileSync2(configPath, "utf-8"));
4960
+ } catch (err) {
4961
+ log2("");
4962
+ fail2(`Could not read ${configPath}: ${err.message}`);
4963
+ log2("");
4964
+ process.exit(1);
4965
+ }
4966
+ log2("");
4967
+ log2(` ${c2.bold("\u{1F380} AgenticMail \u2014 set up Gmail relay")} `);
4968
+ log2("");
4969
+ log2(` ${c2.dim("This command runs entirely in your terminal. The password")}`);
4970
+ log2(` ${c2.dim("input is hidden and never leaves this process \u2014 your agent")}`);
4971
+ log2(` ${c2.dim("doesn't see it.")}`);
4972
+ log2("");
4973
+ try {
4974
+ const result = await setupRelay(config);
4975
+ if (!result.success) {
4976
+ log2("");
4977
+ fail2("Relay setup did not complete \u2014 see messages above.");
4978
+ process.exit(1);
4979
+ }
4980
+ log2("");
4981
+ ok2("Gmail relay configured.");
4982
+ log2("");
4983
+ log2(` ${c2.bold("Next:")} point bridge-escalation alerts at your personal email:`);
4984
+ log2("");
4985
+ log2(` ${c2.cyan("Option A")} \u2014 tell your host agent: "set my operator notification email to <you@gmail.com>"`);
4986
+ log2(` ${c2.cyan("Option B")} \u2014 open the web UI \u2192 click your avatar \u2192 ${c2.bold("Alert email")} \u2192 type, Save`);
4987
+ log2("");
4988
+ log2(` ${c2.dim("Either path writes ~/.agenticmail/operator-prefs.json \u2014 the dispatcher")}`);
4989
+ log2(` ${c2.dim("forwards a digest there when sub-agents mail your bridge and the")}`);
4990
+ log2(` ${c2.dim("dispatcher can't resume your host session.")}`);
4991
+ log2("");
4992
+ } catch (err) {
4993
+ log2("");
4994
+ fail2(`Setup-relay failed: ${err.message}`);
4995
+ log2("");
4996
+ process.exit(1);
4997
+ }
4998
+ }
4930
4999
  async function cmdSetup() {
4931
5000
  const setupArgs = process.argv.slice(3);
4932
5001
  if (setupArgs.some((a) => a === "--help" || a === "-h" || a === "help")) {
@@ -7392,6 +7461,13 @@ switch (command) {
7392
7461
  process.exit(1);
7393
7462
  });
7394
7463
  break;
7464
+ case "setup-relay":
7465
+ case "relay":
7466
+ cmdSetupRelay().catch((err) => {
7467
+ console.error(err);
7468
+ process.exit(1);
7469
+ });
7470
+ break;
7395
7471
  case "start":
7396
7472
  cmdStart().catch((err) => {
7397
7473
  console.error(err);
@@ -63,6 +63,8 @@
63
63
  <div class="profile-menu-section">Inboxes</div>
64
64
  <div id="profile-menu-list"></div>
65
65
  <div class="profile-menu-divider"></div>
66
+ <div id="profile-menu-operator-email"></div>
67
+ <div class="profile-menu-divider"></div>
66
68
  <div class="profile-menu-footer">
67
69
  <a id="signout-link">Sign out</a>
68
70
  </div>
@@ -37,6 +37,25 @@ export async function apiPut(path, body, opts = {}) {
37
37
  return await r.json();
38
38
  }
39
39
 
40
+ export async function apiPatch(path, body, opts = {}) {
41
+ const r = await fetch(`${API_URL}/api/agenticmail${path}`, {
42
+ method: 'PATCH',
43
+ headers: {
44
+ 'Content-Type': 'application/json',
45
+ Authorization: `Bearer ${opts.agentKey ?? state.masterKey}`,
46
+ },
47
+ body: JSON.stringify(body),
48
+ });
49
+ if (!r.ok) {
50
+ // Try to surface the server's error body so the UI can show
51
+ // "operator email must contain an @" instead of a bare 400.
52
+ let detail = '';
53
+ try { const j = await r.json(); detail = j?.error ? `: ${j.error}` : ''; } catch { /* ignore */ }
54
+ throw new Error(`${r.status} ${path}${detail}`);
55
+ }
56
+ return await r.json();
57
+ }
58
+
40
59
  /**
41
60
  * Fetch an attachment with auth and trigger a browser download.
42
61
  *
@@ -16,9 +16,10 @@
16
16
  // The selected host persists in localStorage so the operator's view
17
17
  // preference survives reloads and across browser tabs.
18
18
  import { state } from './state.js';
19
- import { escapeHtml } from './utils.js';
19
+ import { escapeHtml, toast } from './utils.js';
20
20
  import { avatarHtml, isBridgeAgent } from './avatar.js';
21
21
  import { icon } from './icons.js';
22
+ import { apiGet, apiPatch } from './api.js';
22
23
 
23
24
  /**
24
25
  * Host registry mirrors the one in avatar.js. Kept duplicated rather
@@ -339,8 +340,131 @@ export function bindHostSwitcher() {
339
340
  });
340
341
  }
341
342
 
343
+ /**
344
+ * Operator notification email — show + edit in the profile menu.
345
+ *
346
+ * The dispatcher emails this address when a sub-agent mails a host
347
+ * bridge AND no fresh host session is available for a headless
348
+ * resume. Wired to `GET / PATCH /system/operator-email` (the same
349
+ * endpoints the `setup_operator_email` MCP tool uses, so changes
350
+ * from the UI and changes from a host agent stay in sync).
351
+ *
352
+ * Two states:
353
+ * 1. Display: shows the current email or "Not set", with a small
354
+ * "Edit" pencil. Clicking the pencil swaps to state 2.
355
+ * 2. Edit: <input> + Save / Cancel buttons. Save fires PATCH,
356
+ * shows a toast, and re-renders state 1.
357
+ *
358
+ * Cached value: `operatorEmail` lives on `state.operatorEmail` so a
359
+ * re-render of the profile menu doesn't refetch every time.
360
+ */
361
+
362
+ async function loadOperatorEmail() {
363
+ try {
364
+ const r = await apiGet('/system/operator-email');
365
+ state.operatorEmail = (typeof r?.email === 'string' && r.email) ? r.email : null;
366
+ } catch (err) {
367
+ // 404 / 500 on older servers — degrade silently to "not set".
368
+ state.operatorEmail = null;
369
+ }
370
+ renderOperatorEmail();
371
+ }
372
+
373
+ function renderOperatorEmail() {
374
+ const slot = document.getElementById('profile-menu-operator-email');
375
+ if (!slot) return;
376
+ const value = state.operatorEmail;
377
+ const editing = slot.dataset.mode === 'edit';
378
+
379
+ if (editing) {
380
+ slot.innerHTML = `
381
+ <div class="profile-menu-section">Alert email</div>
382
+ <div class="operator-email-edit">
383
+ <input
384
+ type="email"
385
+ id="operator-email-input"
386
+ class="operator-email-input"
387
+ placeholder="you@example.com"
388
+ value="${escapeHtml(value ?? '')}" />
389
+ <div class="operator-email-actions">
390
+ <button class="operator-email-btn operator-email-btn-primary" id="operator-email-save">Save</button>
391
+ <button class="operator-email-btn" id="operator-email-cancel">Cancel</button>
392
+ ${value ? `<button class="operator-email-btn operator-email-btn-danger" id="operator-email-clear" title="Clear — no email forward">Clear</button>` : ''}
393
+ </div>
394
+ <div class="operator-email-hint">
395
+ Dispatcher emails this address when sub-agents mail your host bridge and the resume can't run (no fresh session, expired token). Phone push via your normal mail app.
396
+ </div>
397
+ </div>
398
+ `;
399
+ const input = document.getElementById('operator-email-input');
400
+ input?.focus();
401
+ input?.select();
402
+ document.getElementById('operator-email-save')?.addEventListener('click', () => saveOperatorEmail(input?.value ?? ''));
403
+ document.getElementById('operator-email-cancel')?.addEventListener('click', () => {
404
+ slot.dataset.mode = '';
405
+ renderOperatorEmail();
406
+ });
407
+ document.getElementById('operator-email-clear')?.addEventListener('click', () => saveOperatorEmail(''));
408
+ input?.addEventListener('keydown', (e) => {
409
+ if (e.key === 'Enter') saveOperatorEmail(input.value);
410
+ if (e.key === 'Escape') { slot.dataset.mode = ''; renderOperatorEmail(); }
411
+ });
412
+ return;
413
+ }
414
+
415
+ slot.innerHTML = `
416
+ <div class="profile-menu-section">Alert email</div>
417
+ <div class="operator-email-display" id="operator-email-display">
418
+ <div class="operator-email-value ${value ? '' : 'is-empty'}">
419
+ ${value ? escapeHtml(value) : 'Not set — sub-agent escalations stay in the web UI only'}
420
+ </div>
421
+ <button class="operator-email-edit-btn" id="operator-email-edit" title="${value ? 'Change' : 'Set up'}">
422
+ ${icon('compose', { size: 14 })}
423
+ </button>
424
+ </div>
425
+ `;
426
+ document.getElementById('operator-email-edit')?.addEventListener('click', () => {
427
+ slot.dataset.mode = 'edit';
428
+ renderOperatorEmail();
429
+ });
430
+ }
431
+
432
+ async function saveOperatorEmail(raw) {
433
+ const trimmed = String(raw ?? '').trim();
434
+ try {
435
+ // Server canonicalises (trims) and validates (must contain @ when
436
+ // non-empty). Empty string = clear, server stores null. We mirror
437
+ // the server's canonical value back into state so a refresh
438
+ // shows exactly what was persisted.
439
+ const r = await apiPatch('/system/operator-email', { email: trimmed || null });
440
+ state.operatorEmail = (typeof r?.email === 'string' && r.email) ? r.email : null;
441
+ toast(state.operatorEmail ? `Alerts now route to ${state.operatorEmail}` : 'Alert email cleared.');
442
+ const slot = document.getElementById('profile-menu-operator-email');
443
+ if (slot) slot.dataset.mode = '';
444
+ renderOperatorEmail();
445
+ } catch (err) {
446
+ toast(`Could not save: ${err.message.replace(/^\d+\s+\S+:\s*/, '')}`, true);
447
+ }
448
+ }
449
+
450
+ /** Lazy-load on first profile-menu open — keeps the initial page
451
+ * load free of an extra round-trip. Subsequent opens use the
452
+ * cached value in state.operatorEmail. */
453
+ let operatorEmailHydrated = false;
454
+ export function hydrateOperatorEmail() {
455
+ if (operatorEmailHydrated) {
456
+ renderOperatorEmail();
457
+ return;
458
+ }
459
+ operatorEmailHydrated = true;
460
+ void loadOperatorEmail();
461
+ }
462
+
342
463
  export function toggleProfileMenu(e) {
343
464
  if (e) e.stopPropagation();
465
+ // Lazy-hydrate the operator email block the first time the menu
466
+ // opens (idempotent for subsequent opens — re-renders from cache).
467
+ hydrateOperatorEmail();
344
468
  document.getElementById('profile-menu').classList.toggle('open');
345
469
  }
346
470
  export function closeProfileMenu() {
@@ -48,6 +48,16 @@ export const state = {
48
48
  * `state.agents` so no UI work is needed when a new bridge appears.
49
49
  */
50
50
  activeHost: localStorage.getItem('agenticmail.activeHost') || 'all',
51
+ /**
52
+ * Operator's notification email address (or null when not set).
53
+ * Hydrated lazily on first profile-menu open via
54
+ * `GET /system/operator-email`. Used by the dispatcher's
55
+ * bridge-escalation path to forward digests when a sub-agent
56
+ * mails a bridge and no host session is resumable. See
57
+ * packages/core/src/operator-prefs.ts for the storage and
58
+ * profile.js for the in-menu edit affordance.
59
+ */
60
+ operatorEmail: null,
51
61
  };
52
62
 
53
63
  export const API_URL = window.location.origin;
@@ -446,6 +446,109 @@ a { color: var(--accent-strong); }
446
446
  }
447
447
  .profile-menu-footer a:hover { text-decoration: underline; }
448
448
 
449
+ /* ─── Operator notification email — display + inline edit ──────────
450
+ *
451
+ * Lives between the inbox list and the Sign out footer. Two states:
452
+ * - Display: current address (or "Not set" placeholder) + pencil
453
+ * - Edit: <input> + Save / Cancel / Clear buttons + hint copy
454
+ *
455
+ * Visual weight is deliberately understated — this is a "set once,
456
+ * forget" knob, not a primary action. */
457
+ .operator-email-display {
458
+ padding: 6px 20px 10px;
459
+ display: flex; align-items: center; gap: 8px;
460
+ font-size: 13px;
461
+ }
462
+ .operator-email-value {
463
+ flex: 1;
464
+ color: var(--ink);
465
+ overflow: hidden;
466
+ text-overflow: ellipsis;
467
+ white-space: nowrap;
468
+ }
469
+ .operator-email-value.is-empty {
470
+ color: var(--muted);
471
+ font-style: italic;
472
+ font-size: 12px;
473
+ }
474
+ .operator-email-edit-btn {
475
+ background: transparent;
476
+ border: none;
477
+ cursor: pointer;
478
+ color: var(--muted);
479
+ padding: 4px;
480
+ border-radius: 4px;
481
+ display: flex;
482
+ align-items: center;
483
+ justify-content: center;
484
+ }
485
+ .operator-email-edit-btn:hover {
486
+ background: var(--bg-hover);
487
+ color: var(--ink);
488
+ }
489
+ .operator-email-edit {
490
+ padding: 4px 20px 12px;
491
+ }
492
+ .operator-email-input {
493
+ width: 100%;
494
+ padding: 8px 10px;
495
+ border: 1px solid var(--line);
496
+ border-radius: 6px;
497
+ background: var(--bg);
498
+ color: var(--ink);
499
+ font-size: 13px;
500
+ font-family: inherit;
501
+ box-sizing: border-box;
502
+ }
503
+ .operator-email-input:focus {
504
+ outline: none;
505
+ border-color: var(--accent-strong);
506
+ }
507
+ .operator-email-actions {
508
+ display: flex;
509
+ gap: 6px;
510
+ margin-top: 8px;
511
+ }
512
+ .operator-email-btn {
513
+ padding: 6px 12px;
514
+ border: 1px solid var(--line);
515
+ border-radius: 6px;
516
+ background: var(--bg);
517
+ color: var(--ink);
518
+ font-size: 12px;
519
+ font-weight: 500;
520
+ cursor: pointer;
521
+ transition: background 120ms, border-color 120ms;
522
+ }
523
+ .operator-email-btn:hover { background: var(--bg-hover); }
524
+ .operator-email-btn-primary {
525
+ background: var(--accent-strong);
526
+ color: white;
527
+ border-color: var(--accent-strong);
528
+ }
529
+ .operator-email-btn-primary:hover {
530
+ background: var(--accent-strong);
531
+ opacity: 0.9;
532
+ }
533
+ .operator-email-btn-danger {
534
+ margin-left: auto;
535
+ color: #b91c1c;
536
+ border-color: transparent;
537
+ }
538
+ .operator-email-btn-danger:hover {
539
+ background: #fee2e2;
540
+ }
541
+ .operator-email-hint {
542
+ margin-top: 8px;
543
+ font-size: 11px;
544
+ color: var(--muted);
545
+ line-height: 1.45;
546
+ }
547
+ @media (prefers-color-scheme: dark) {
548
+ .operator-email-btn-danger { color: #fca5a5; }
549
+ .operator-email-btn-danger:hover { background: #2a1717; }
550
+ }
551
+
449
552
  /* ─── Avatars ──────────────────────────────────────────────────────── */
450
553
  .avatar {
451
554
  width: 32px; height: 32px; border-radius: 50%;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenticmail/cli",
3
- "version": "0.9.35",
3
+ "version": "0.9.37",
4
4
  "description": "Email and SMS infrastructure for AI agents — the first platform to give agents real email addresses and phone numbers",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -31,7 +31,7 @@
31
31
  "prepublishOnly": "npm run build"
32
32
  },
33
33
  "dependencies": {
34
- "@agenticmail/api": "^0.9.26",
34
+ "@agenticmail/api": "^0.9.27",
35
35
  "@agenticmail/core": "^0.9.7",
36
36
  "json5": "^2.2.3"
37
37
  },