@agenticmail/enterprise 0.5.322 → 0.5.324

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.
@@ -0,0 +1,260 @@
1
+ import "./chunk-KFQGP6VL.js";
2
+
3
+ // src/cli-serve.ts
4
+ import { existsSync, readFileSync } from "fs";
5
+ import { join } from "path";
6
+ import { homedir } from "os";
7
+ function loadEnvFile() {
8
+ const candidates = [
9
+ join(process.cwd(), ".env"),
10
+ join(homedir(), ".agenticmail", ".env")
11
+ ];
12
+ for (const envPath of candidates) {
13
+ if (!existsSync(envPath)) continue;
14
+ try {
15
+ const content = readFileSync(envPath, "utf8");
16
+ for (const line of content.split("\n")) {
17
+ const trimmed = line.trim();
18
+ if (!trimmed || trimmed.startsWith("#")) continue;
19
+ const eq = trimmed.indexOf("=");
20
+ if (eq < 0) continue;
21
+ const key = trimmed.slice(0, eq).trim();
22
+ let val = trimmed.slice(eq + 1).trim();
23
+ if (val.startsWith('"') && val.endsWith('"') || val.startsWith("'") && val.endsWith("'")) {
24
+ val = val.slice(1, -1);
25
+ }
26
+ if (!process.env[key]) process.env[key] = val;
27
+ }
28
+ console.log(`Loaded config from ${envPath}`);
29
+ return;
30
+ } catch {
31
+ }
32
+ }
33
+ }
34
+ async function ensureSecrets() {
35
+ const { randomUUID } = await import("crypto");
36
+ const envDir = join(homedir(), ".agenticmail");
37
+ const envPath = join(envDir, ".env");
38
+ let dirty = false;
39
+ if (!process.env.JWT_SECRET) {
40
+ process.env.JWT_SECRET = randomUUID() + randomUUID();
41
+ dirty = true;
42
+ console.log("[startup] Generated new JWT_SECRET (existing sessions will need to re-login)");
43
+ }
44
+ if (!process.env.AGENTICMAIL_VAULT_KEY) {
45
+ process.env.AGENTICMAIL_VAULT_KEY = randomUUID() + randomUUID();
46
+ dirty = true;
47
+ console.log("[startup] Generated new AGENTICMAIL_VAULT_KEY");
48
+ console.log("[startup] \u26A0\uFE0F Previously encrypted credentials will need to be re-entered in the dashboard");
49
+ }
50
+ if (dirty) {
51
+ try {
52
+ if (!existsSync(envDir)) {
53
+ const { mkdirSync } = await import("fs");
54
+ mkdirSync(envDir, { recursive: true });
55
+ }
56
+ const { appendFileSync } = await import("fs");
57
+ const lines = [];
58
+ let existing = "";
59
+ if (existsSync(envPath)) {
60
+ existing = readFileSync(envPath, "utf8");
61
+ }
62
+ if (!existing.includes("JWT_SECRET=")) {
63
+ lines.push(`JWT_SECRET=${process.env.JWT_SECRET}`);
64
+ }
65
+ if (!existing.includes("AGENTICMAIL_VAULT_KEY=")) {
66
+ lines.push(`AGENTICMAIL_VAULT_KEY=${process.env.AGENTICMAIL_VAULT_KEY}`);
67
+ }
68
+ if (lines.length) {
69
+ appendFileSync(envPath, "\n" + lines.join("\n") + "\n", { mode: 384 });
70
+ console.log(`[startup] Saved secrets to ${envPath}`);
71
+ }
72
+ } catch (e) {
73
+ console.warn(`[startup] Could not save secrets to ${envPath}: ${e.message}`);
74
+ }
75
+ }
76
+ }
77
+ async function runServe(_args) {
78
+ loadEnvFile();
79
+ const DATABASE_URL = process.env.DATABASE_URL;
80
+ const PORT = parseInt(process.env.PORT || "8080", 10);
81
+ await ensureSecrets();
82
+ const JWT_SECRET = process.env.JWT_SECRET;
83
+ const VAULT_KEY = process.env.AGENTICMAIL_VAULT_KEY;
84
+ if (!DATABASE_URL) {
85
+ console.error("ERROR: DATABASE_URL is required.");
86
+ console.error("");
87
+ console.error("Set it via environment variable or .env file:");
88
+ console.error(" DATABASE_URL=postgresql://user:pass@host:5432/db npx @agenticmail/enterprise start");
89
+ console.error("");
90
+ console.error("Or create a .env file (in cwd or ~/.agenticmail/.env):");
91
+ console.error(" DATABASE_URL=postgresql://user:pass@host:5432/db");
92
+ console.error(" JWT_SECRET=your-secret-here");
93
+ console.error(" PORT=3200");
94
+ process.exit(1);
95
+ }
96
+ const { createAdapter, smartDbConfig } = await import("./factory-MQASIPEB.js");
97
+ const { createServer } = await import("./server-7NT4LMSQ.js");
98
+ const db = await createAdapter(smartDbConfig(DATABASE_URL));
99
+ await db.migrate();
100
+ const server = createServer({
101
+ port: PORT,
102
+ db,
103
+ jwtSecret: JWT_SECRET,
104
+ corsOrigins: ["*"]
105
+ });
106
+ await server.start();
107
+ console.log(`AgenticMail Enterprise server running on :${PORT}`);
108
+ try {
109
+ const { startPreventSleep } = await import("./screen-unlock-4RPZBHOI.js");
110
+ const adminDb = server.getAdminDb?.() || server.adminDb;
111
+ if (adminDb) {
112
+ const settings = await adminDb.getSettings?.().catch(() => null);
113
+ const screenAccess = settings?.securityConfig?.screenAccess;
114
+ if (screenAccess?.enabled && screenAccess?.preventSleep) {
115
+ startPreventSleep();
116
+ console.log("[startup] Prevent-sleep enabled \u2014 system will stay awake while agents are active");
117
+ }
118
+ }
119
+ } catch {
120
+ }
121
+ try {
122
+ await setupSystemPersistence();
123
+ } catch (e) {
124
+ console.warn("[startup] System persistence setup skipped: " + e.message);
125
+ }
126
+ const tunnelToken = process.env.CLOUDFLARED_TOKEN;
127
+ if (tunnelToken) {
128
+ try {
129
+ const { execSync, spawn } = await import("child_process");
130
+ try {
131
+ execSync("which cloudflared", { timeout: 3e3 });
132
+ } catch {
133
+ console.log("[startup] cloudflared not found \u2014 skipping tunnel auto-start");
134
+ console.log("[startup] Install cloudflared to enable tunnel: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/");
135
+ return;
136
+ }
137
+ try {
138
+ execSync('pgrep -f "cloudflared.*tunnel.*run"', { timeout: 3e3 });
139
+ console.log("[startup] cloudflared tunnel already running");
140
+ return;
141
+ } catch {
142
+ }
143
+ const subdomain = process.env.AGENTICMAIL_SUBDOMAIN || process.env.AGENTICMAIL_DOMAIN || "";
144
+ console.log(`[startup] Starting cloudflared tunnel${subdomain ? ` for ${subdomain}.agenticmail.io` : ""}...`);
145
+ const child = spawn("cloudflared", ["tunnel", "--no-autoupdate", "run", "--token", tunnelToken], {
146
+ detached: true,
147
+ stdio: "ignore"
148
+ });
149
+ child.unref();
150
+ console.log("[startup] cloudflared tunnel started (pid " + child.pid + ")");
151
+ } catch (e) {
152
+ console.warn("[startup] Could not auto-start cloudflared: " + e.message);
153
+ }
154
+ }
155
+ }
156
+ async function setupSystemPersistence() {
157
+ const { execSync, spawnSync } = await import("child_process");
158
+ const { existsSync: exists, writeFileSync, mkdirSync } = await import("fs");
159
+ const { join: pathJoin } = await import("path");
160
+ const platform = process.platform;
161
+ if (!process.env.PM2_HOME && !process.env.pm_id) {
162
+ return;
163
+ }
164
+ const markerDir = pathJoin(homedir(), ".agenticmail");
165
+ const markerFile = pathJoin(markerDir, ".persistence-configured");
166
+ if (exists(markerFile)) {
167
+ try {
168
+ execSync("pm2 save --silent", { timeout: 1e4, stdio: "ignore" });
169
+ } catch {
170
+ }
171
+ return;
172
+ }
173
+ console.log("[startup] Configuring system persistence (one-time setup)...");
174
+ try {
175
+ if (platform === "darwin") {
176
+ const result = spawnSync("pm2", ["startup", "launchd", "--silent"], {
177
+ timeout: 15e3,
178
+ stdio: "pipe",
179
+ encoding: "utf-8"
180
+ });
181
+ const output = (result.stdout || "") + (result.stderr || "");
182
+ const sudoMatch = output.match(/sudo\s+env\s+.*pm2\s+startup.*/);
183
+ if (sudoMatch) {
184
+ console.log("[startup] PM2 startup requires sudo. Run this once:");
185
+ console.log(" " + sudoMatch[0]);
186
+ } else {
187
+ console.log("[startup] PM2 startup configured (launchd)");
188
+ }
189
+ const plistPath = pathJoin(homedir(), "Library", "LaunchAgents", `pm2.${process.env.USER || "user"}.plist`);
190
+ if (exists(plistPath)) {
191
+ try {
192
+ execSync(`launchctl load -w "${plistPath}"`, { timeout: 5e3, stdio: "ignore" });
193
+ } catch {
194
+ }
195
+ }
196
+ } else if (platform === "linux") {
197
+ const result = spawnSync("pm2", ["startup", "systemd", "--silent"], {
198
+ timeout: 15e3,
199
+ stdio: "pipe",
200
+ encoding: "utf-8"
201
+ });
202
+ const output = (result.stdout || "") + (result.stderr || "");
203
+ const sudoMatch = output.match(/sudo\s+env\s+.*pm2\s+startup.*/);
204
+ if (sudoMatch) {
205
+ try {
206
+ execSync(sudoMatch[0], { timeout: 15e3, stdio: "ignore" });
207
+ console.log("[startup] PM2 startup configured (systemd)");
208
+ } catch {
209
+ console.log("[startup] PM2 startup requires root. Run this once:");
210
+ console.log(" " + sudoMatch[0]);
211
+ }
212
+ } else {
213
+ console.log("[startup] PM2 startup configured (systemd)");
214
+ }
215
+ } else if (platform === "win32") {
216
+ try {
217
+ execSync("npm list -g pm2-windows-startup", { timeout: 1e4, stdio: "ignore" });
218
+ } catch {
219
+ console.log("[startup] Installing pm2-windows-startup...");
220
+ try {
221
+ execSync("npm install -g pm2-windows-startup", { timeout: 6e4, stdio: "ignore" });
222
+ execSync("pm2-startup install", { timeout: 15e3, stdio: "ignore" });
223
+ console.log("[startup] PM2 startup configured (Windows Service)");
224
+ } catch (e) {
225
+ console.warn("[startup] Could not install pm2-windows-startup: " + e.message);
226
+ }
227
+ }
228
+ }
229
+ } catch (e) {
230
+ console.warn("[startup] PM2 startup setup: " + e.message);
231
+ }
232
+ try {
233
+ const moduleList = execSync("pm2 ls --silent 2>/dev/null || true", { timeout: 1e4, encoding: "utf-8" });
234
+ if (!moduleList.includes("pm2-logrotate")) {
235
+ console.log("[startup] Installing pm2-logrotate...");
236
+ execSync("pm2 install pm2-logrotate --silent", { timeout: 6e4, stdio: "ignore" });
237
+ execSync("pm2 set pm2-logrotate:max_size 10M --silent", { timeout: 5e3, stdio: "ignore" });
238
+ execSync("pm2 set pm2-logrotate:retain 5 --silent", { timeout: 5e3, stdio: "ignore" });
239
+ execSync("pm2 set pm2-logrotate:compress true --silent", { timeout: 5e3, stdio: "ignore" });
240
+ console.log("[startup] Log rotation configured (10MB, 5 files)");
241
+ }
242
+ } catch {
243
+ }
244
+ try {
245
+ execSync("pm2 save --silent", { timeout: 1e4, stdio: "ignore" });
246
+ console.log("[startup] Process list saved");
247
+ } catch {
248
+ }
249
+ try {
250
+ if (!exists(markerDir)) mkdirSync(markerDir, { recursive: true });
251
+ writeFileSync(markerFile, (/* @__PURE__ */ new Date()).toISOString() + `
252
+ platform=${platform}
253
+ `, { mode: 384 });
254
+ console.log("[startup] System persistence configured successfully");
255
+ } catch {
256
+ }
257
+ }
258
+ export {
259
+ runServe
260
+ };
package/dist/cli.js CHANGED
@@ -57,14 +57,14 @@ Skill Development:
57
57
  break;
58
58
  case "serve":
59
59
  case "start":
60
- import("./cli-serve-53FVANQK.js").then((m) => m.runServe(args.slice(1))).catch(fatal);
60
+ import("./cli-serve-7JQ4FVUQ.js").then((m) => m.runServe(args.slice(1))).catch(fatal);
61
61
  break;
62
62
  case "agent":
63
- import("./cli-agent-ION2W5JF.js").then((m) => m.runAgent(args.slice(1))).catch(fatal);
63
+ import("./cli-agent-USMKX7WN.js").then((m) => m.runAgent(args.slice(1))).catch(fatal);
64
64
  break;
65
65
  case "setup":
66
66
  default:
67
- import("./setup-T6KYFR7O.js").then((m) => m.runSetupWizard()).catch(fatal);
67
+ import("./setup-6NUSB4XO.js").then((m) => m.runSetupWizard()).catch(fatal);
68
68
  break;
69
69
  }
70
70
  function fatal(err) {
@@ -31,6 +31,7 @@ import { DatabaseAccessPage } from './pages/database-access.js';
31
31
  import { OrganizationsPage } from './pages/organizations.js';
32
32
  import { RolesPage } from './pages/roles.js';
33
33
  import { MemoryTransferPage } from './pages/memory-transfer.js';
34
+ import { ClusterPage } from './pages/cluster.js';
34
35
 
35
36
  // ─── Toast System ────────────────────────────────────────
36
37
  let toastId = 0;
@@ -252,7 +253,7 @@ function App() {
252
253
  setUser(d.user);
253
254
  // Immediately restrict permissions for client org users (before async fetch)
254
255
  if (d.user.clientOrgId) {
255
- setPermissions({ dashboard: true, agents: true, roles: true, skills: true, 'community-skills': true, 'skill-connections': true, 'database-access': true, knowledge: true, 'knowledge-contributions': true, 'memory-transfer': true, approvals: true, 'org-chart': true, 'task-pipeline': true, workforce: true, messages: true, guardrails: true, journal: true, activity: true, dlp: true, compliance: true, vault: true, audit: true, settings: true });
256
+ setPermissions({ dashboard: true, agents: true, roles: true, skills: true, 'community-skills': true, 'skill-connections': true, 'database-access': true, knowledge: true, 'knowledge-contributions': true, 'memory-transfer': true, approvals: true, 'org-chart': true, 'task-pipeline': true, cluster: true, workforce: true, messages: true, guardrails: true, journal: true, activity: true, dlp: true, compliance: true, vault: true, audit: true, settings: true });
256
257
  }
257
258
  // Then fetch computed permissions for the definitive set
258
259
  apiCall('/me/permissions').then(function(p) { if (p && p.permissions) setPermissions(p.permissions); }).catch(function() {});
@@ -404,6 +405,7 @@ function App() {
404
405
  { section: 'Operations', items: [
405
406
  { id: 'org-chart', icon: I.orgChart, label: 'Org Chart' },
406
407
  { id: 'task-pipeline', icon: I.workflow, label: 'Task Pipeline' },
408
+ { id: 'cluster', icon: I.server, label: 'Cluster' },
407
409
  { id: 'workforce', icon: I.clock, label: 'Workforce' },
408
410
  { id: 'messages', icon: I.messages, label: 'Messages' },
409
411
  { id: 'guardrails', icon: I.guardrails, label: 'Guardrails' },
@@ -447,6 +449,7 @@ function App() {
447
449
  organizations: OrganizationsPage,
448
450
  roles: RolesPage,
449
451
  'memory-transfer': MemoryTransferPage,
452
+ cluster: ClusterPage,
450
453
  };
451
454
 
452
455
  const navigateToAgent = (agentId) => { _setSelectedAgentId(agentId); history.pushState(null, '', '/dashboard/agents/' + agentId); };
@@ -58,6 +58,7 @@ chevronRight: () => h('svg', S, h('polyline', { points: '9 18 15 12 9 6' })),
58
58
  chevronDown: () => h('svg', S, h('polyline', { points: '6 9 12 15 18 9' })),
59
59
  mail: () => h('svg', S, h('path', { d: 'M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z' }), h('polyline', { points: '22,6 12,13 2,6' })),
60
60
  building: () => h('svg', S, h('path', { d: 'M3 21h18M3 10h18M3 7l9-4 9 4M4 10v11M20 10v11M8 14v.01M12 14v.01M16 14v.01M8 18v.01M12 18v.01M16 18v.01' })),
61
+ server: () => h('svg', S, h('rect', { x: 2, y: 2, width: 20, height: 8, rx: 2, ry: 2 }), h('rect', { x: 2, y: 14, width: 20, height: 8, rx: 2, ry: 2 }), h('line', { x1: 6, y1: 6, x2: 6.01, y2: 6 }), h('line', { x1: 6, y1: 18, x2: 6.01, y2: 18 })),
61
62
  brain: () => h('svg', S, h('path', { d: 'M9.5 2a3.5 3.5 0 00-3.21 4.87A3.5 3.5 0 004 10.5a3.5 3.5 0 002.81 3.43A3.5 3.5 0 009.5 18h1V2z' }), h('path', { d: 'M14.5 2a3.5 3.5 0 013.21 4.87A3.5 3.5 0 0120 10.5a3.5 3.5 0 01-2.81 3.43A3.5 3.5 0 0114.5 18h-1V2z' }), h('path', { d: 'M12 2v16' }), h('path', { d: 'M4.93 7.5h2.57M16.5 7.5h2.57M7 13h3M14 13h3' })),
62
63
  edit: () => h('svg', S, h('path', { d: 'M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7' }), h('path', { d: 'M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z' })),
63
64
  };
@@ -103,14 +103,35 @@ export function AgentDetailPage(props) {
103
103
 
104
104
  useEffect(function() { load(); }, [agentId]);
105
105
 
106
+ // ─── Real-Time Status from Agent Process ────────────────
107
+ var [liveStatus, setLiveStatus] = useState(null);
108
+ useEffect(function() {
109
+ var es = new EventSource('/api/engine/agent-status-stream?agentId=' + encodeURIComponent(agentId));
110
+ es.onmessage = function(ev) {
111
+ try {
112
+ var d = JSON.parse(ev.data);
113
+ if (d.type === 'status' && d.agentId === agentId) { setLiveStatus(d); }
114
+ } catch(e) {}
115
+ };
116
+ es.onerror = function() { /* reconnects automatically */ };
117
+ return function() { es.close(); };
118
+ }, [agentId]);
119
+
106
120
  // ─── Derived Values ─────────────────────────────────────
107
121
 
108
122
  var ea = engineAgent || {};
109
123
  var a = agent || {};
110
124
  var config = ea.config || {};
111
125
  var identity = config.identity || {};
112
- var state = ea.state || ea.status || a.status || 'unknown';
113
- var stateColor = { running: 'success', active: 'success', deploying: 'info', starting: 'info', provisioning: 'info', degraded: 'warning', error: 'danger', stopped: 'neutral', draft: 'neutral', ready: 'primary' }[state] || 'neutral';
126
+ // Prefer live process status over DB state
127
+ var liveState = liveStatus ? liveStatus.status : null;
128
+ var dbState = ea.state || ea.status || a.status || 'unknown';
129
+ var state = liveState || dbState;
130
+ // Map live statuses: online→running, idle→idle, offline→stopped, error→error
131
+ if (state === 'online') state = 'running';
132
+ if (state === 'idle') state = 'idle';
133
+ if (state === 'offline') state = 'stopped';
134
+ var stateColor = { running: 'success', active: 'success', idle: 'info', deploying: 'info', starting: 'info', provisioning: 'info', degraded: 'warning', error: 'danger', stopped: 'neutral', draft: 'neutral', ready: 'primary' }[state] || 'neutral';
114
135
  var displayName = identity.name || config.name || config.displayName || a.name || 'Unnamed Agent';
115
136
  var displayEmail = identity.email || config.email || a.email || '';
116
137
  var avatarUrl = identity.avatar && identity.avatar.length > 2 ? identity.avatar : null;
@@ -175,7 +196,8 @@ export function AgentDetailPage(props) {
175
196
  h('div', { style: { flex: 1, minWidth: 0 } },
176
197
  h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } },
177
198
  h('h1', { style: { fontSize: 20, fontWeight: 700, margin: 0 } }, displayName),
178
- h('span', { className: 'badge badge-' + stateColor, style: { textTransform: 'capitalize' } }, state)
199
+ h('span', { className: 'badge badge-' + stateColor, style: { textTransform: 'capitalize' } }, state),
200
+ liveStatus && liveStatus.currentActivity && h('span', { style: { fontSize: 11, color: 'var(--text-muted)', fontStyle: 'italic' } }, liveStatus.currentActivity.detail || liveStatus.currentActivity.type)
179
201
  ),
180
202
  h('div', { style: { display: 'flex', alignItems: 'center', gap: 12, marginTop: 4 } },
181
203
  displayEmail && h('span', { style: { fontFamily: 'var(--font-mono, monospace)', fontSize: 12, color: 'var(--text-muted)' } }, displayEmail),
@@ -1132,6 +1132,25 @@ export function AgentsPage({ onSelectAgent }) {
1132
1132
  var orgCtx = useOrgContext();
1133
1133
  const [agents, setAgents] = useState([]);
1134
1134
  const [creating, setCreating] = useState(false);
1135
+ const [liveStatuses, setLiveStatuses] = useState({});
1136
+
1137
+ // Subscribe to real-time agent status
1138
+ useEffect(function() {
1139
+ var es = new EventSource('/api/engine/agent-status-stream');
1140
+ es.onmessage = function(ev) {
1141
+ try {
1142
+ var d = JSON.parse(ev.data);
1143
+ if (d.type === 'status' && d.agentId) {
1144
+ setLiveStatuses(function(prev) {
1145
+ var next = Object.assign({}, prev);
1146
+ next[d.agentId] = d;
1147
+ return next;
1148
+ });
1149
+ }
1150
+ } catch(e) {}
1151
+ };
1152
+ return function() { es.close(); };
1153
+ }, []);
1135
1154
 
1136
1155
  const perms = app.permissions || '*';
1137
1156
  const allowedAgents = perms === '*' ? '*' : (perms._allowedAgents || '*');
@@ -1190,7 +1209,17 @@ export function AgentsPage({ onSelectAgent }) {
1190
1209
  h('td', null, h('strong', { style: { cursor: 'pointer', color: 'var(--accent-text)' }, onClick: () => onSelectAgent && onSelectAgent(a.id) }, a.name)),
1191
1210
  h('td', null, h('span', { style: { fontFamily: 'var(--font-mono)', fontSize: 12 } }, a.email || '-')),
1192
1211
  h('td', null, h('span', { className: 'badge badge-neutral' }, a.role || 'agent')),
1193
- h('td', null, h('span', { className: 'badge badge-' + (a.status === 'active' ? 'success' : a.status === 'archived' ? 'neutral' : 'warning') }, a.status || 'active')),
1212
+ h('td', null, (function() {
1213
+ var live = liveStatuses[a.id];
1214
+ var st = live ? live.status : null;
1215
+ var label = st === 'online' ? 'running' : st === 'idle' ? 'idle' : st === 'offline' ? 'stopped' : st === 'error' ? 'error' : (a.status || 'active');
1216
+ var color = { running: 'success', idle: 'info', stopped: 'neutral', error: 'danger', active: 'success', archived: 'neutral' }[label] || 'warning';
1217
+ var activity = live && live.currentActivity ? live.currentActivity.detail || live.currentActivity.type : null;
1218
+ return h(Fragment, null,
1219
+ h('span', { className: 'badge badge-' + color, style: { textTransform: 'capitalize' } }, label),
1220
+ activity && h('span', { style: { fontSize: 10, color: 'var(--text-muted)', marginLeft: 6, fontStyle: 'italic' } }, activity)
1221
+ );
1222
+ })()),
1194
1223
  h('td', { style: { fontSize: 12, color: 'var(--text-muted)' } }, a.createdAt ? new Date(a.createdAt).toLocaleDateString() : '-'),
1195
1224
  h('td', null,
1196
1225
  h('div', { style: { display: 'flex', gap: 4 } },
@@ -0,0 +1,181 @@
1
+ import { h, useState, useEffect, Fragment, useApp, engineCall } from '../components/utils.js';
2
+ import { I } from '../components/icons.js';
3
+
4
+ export function ClusterPage() {
5
+ var app = useApp();
6
+ var toast = app.toast;
7
+ var [nodes, setNodes] = useState([]);
8
+ var [stats, setStats] = useState(null);
9
+ var [loading, setLoading] = useState(true);
10
+
11
+ var load = function() {
12
+ engineCall('/cluster/nodes').then(function(d) {
13
+ setNodes(d.nodes || []);
14
+ setStats(d.stats || null);
15
+ setLoading(false);
16
+ }).catch(function() { setLoading(false); });
17
+ };
18
+
19
+ useEffect(function() { load(); }, []);
20
+
21
+ // Real-time updates via SSE
22
+ useEffect(function() {
23
+ var es = new EventSource('/api/engine/cluster/stream');
24
+ es.onmessage = function(ev) {
25
+ try {
26
+ var d = JSON.parse(ev.data);
27
+ if (d.type === 'node') {
28
+ setNodes(function(prev) {
29
+ var idx = prev.findIndex(function(n) { return n.nodeId === d.nodeId; });
30
+ var next = prev.slice();
31
+ if (idx >= 0) {
32
+ if (d.event === 'offline') { next[idx] = Object.assign({}, next[idx], { status: 'offline' }); }
33
+ else { next[idx] = d; }
34
+ } else if (d.event === 'register' || d.event === 'snapshot') {
35
+ next.push(d);
36
+ }
37
+ return next;
38
+ });
39
+ }
40
+ } catch(e) {}
41
+ };
42
+ return function() { es.close(); };
43
+ }, []);
44
+
45
+ var removeNode = function(nodeId) {
46
+ if (!confirm('Remove worker node "' + nodeId + '"? Agents on it will become unreachable.')) return;
47
+ engineCall('/cluster/nodes/' + nodeId, { method: 'DELETE' }).then(function() {
48
+ toast('Node removed', 'success');
49
+ load();
50
+ }).catch(function(e) { toast(e.message, 'error'); });
51
+ };
52
+
53
+ var statusColor = function(s) {
54
+ return { online: 'success', degraded: 'warning', offline: 'neutral' }[s] || 'neutral';
55
+ };
56
+
57
+ var formatBytes = function(mb) {
58
+ if (mb >= 1024) return (mb / 1024).toFixed(1) + ' GB';
59
+ return mb + ' MB';
60
+ };
61
+
62
+ var timeSince = function(iso) {
63
+ if (!iso) return 'never';
64
+ var s = Math.floor((Date.now() - new Date(iso).getTime()) / 1000);
65
+ if (s < 60) return s + 's ago';
66
+ if (s < 3600) return Math.floor(s / 60) + 'm ago';
67
+ if (s < 86400) return Math.floor(s / 3600) + 'h ago';
68
+ return Math.floor(s / 86400) + 'd ago';
69
+ };
70
+
71
+ if (loading) return h('div', { style: { padding: 40, textAlign: 'center', color: 'var(--text-muted)' } }, 'Loading cluster...');
72
+
73
+ return h(Fragment, null,
74
+ h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 20 } },
75
+ h('div', null,
76
+ h('h1', { style: { fontSize: 20, fontWeight: 700 } }, 'Cluster'),
77
+ h('p', { style: { color: 'var(--text-muted)', fontSize: 13 } }, 'Manage worker nodes running agents across multiple machines')
78
+ ),
79
+ h('button', { className: 'btn btn-secondary btn-sm', onClick: load }, I.refresh(), ' Refresh')
80
+ ),
81
+
82
+ // Stats cards
83
+ stats && h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(160px, 1fr))', gap: 12, marginBottom: 20 } },
84
+ h('div', { className: 'card' }, h('div', { className: 'card-body', style: { padding: 16 } },
85
+ h('div', { style: { fontSize: 24, fontWeight: 700 } }, stats.totalNodes),
86
+ h('div', { style: { fontSize: 12, color: 'var(--text-muted)' } }, 'Total Nodes')
87
+ )),
88
+ h('div', { className: 'card' }, h('div', { className: 'card-body', style: { padding: 16 } },
89
+ h('div', { style: { fontSize: 24, fontWeight: 700, color: 'var(--accent-green)' } }, stats.onlineNodes),
90
+ h('div', { style: { fontSize: 12, color: 'var(--text-muted)' } }, 'Online')
91
+ )),
92
+ h('div', { className: 'card' }, h('div', { className: 'card-body', style: { padding: 16 } },
93
+ h('div', { style: { fontSize: 24, fontWeight: 700 } }, stats.totalAgents),
94
+ h('div', { style: { fontSize: 12, color: 'var(--text-muted)' } }, 'Running Agents')
95
+ )),
96
+ h('div', { className: 'card' }, h('div', { className: 'card-body', style: { padding: 16 } },
97
+ h('div', { style: { fontSize: 24, fontWeight: 700 } }, stats.totalCpus),
98
+ h('div', { style: { fontSize: 12, color: 'var(--text-muted)' } }, 'Total CPUs')
99
+ )),
100
+ h('div', { className: 'card' }, h('div', { className: 'card-body', style: { padding: 16 } },
101
+ h('div', { style: { fontSize: 24, fontWeight: 700 } }, formatBytes(stats.totalMemoryMb)),
102
+ h('div', { style: { fontSize: 12, color: 'var(--text-muted)' } }, 'Total Memory')
103
+ ))
104
+ ),
105
+
106
+ // Nodes
107
+ nodes.length === 0
108
+ ? h('div', { className: 'card' }, h('div', { className: 'card-body' },
109
+ h('div', { className: 'empty-state' },
110
+ I.server(),
111
+ h('h3', null, 'No worker nodes'),
112
+ h('p', null, 'Worker nodes auto-register when you deploy agents to remote machines.'),
113
+ h('div', { style: { marginTop: 16, padding: 16, background: 'var(--bg-secondary)', borderRadius: 8, textAlign: 'left', maxWidth: 500, margin: '16px auto' } },
114
+ h('div', { style: { fontWeight: 600, marginBottom: 8 } }, 'How to add a worker node:'),
115
+ h('ol', { style: { paddingLeft: 20, fontSize: 13, color: 'var(--text-muted)', lineHeight: 1.8 } },
116
+ h('li', null, 'Install on the remote machine: ', h('code', null, 'npm i -g @agenticmail/enterprise')),
117
+ h('li', null, 'Set environment variables:'),
118
+ h('pre', { style: { background: 'var(--bg-primary)', padding: 8, borderRadius: 4, fontSize: 11, overflow: 'auto', margin: '4px 0' } },
119
+ 'ENTERPRISE_URL=https://your-dashboard.agenticmail.io\nWORKER_NODE_ID=mac-mini-2\nWORKER_NAME="Office Mac Mini"\nDATABASE_URL=postgres://...'
120
+ ),
121
+ h('li', null, 'Start agent: ', h('code', null, 'agenticmail-enterprise agent --id <agent-id>')),
122
+ h('li', null, 'The node will auto-register and appear here')
123
+ )
124
+ )
125
+ )
126
+ ))
127
+ : h('div', { style: { display: 'grid', gap: 12 } },
128
+ nodes.map(function(node) {
129
+ return h('div', { key: node.nodeId, className: 'card' },
130
+ h('div', { className: 'card-body', style: { padding: 16 } },
131
+ h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' } },
132
+ h('div', null,
133
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
134
+ h('span', { style: { fontSize: 16, fontWeight: 700 } }, node.name || node.nodeId),
135
+ h('span', { className: 'badge badge-' + statusColor(node.status), style: { textTransform: 'capitalize' } }, node.status)
136
+ ),
137
+ h('div', { style: { fontSize: 12, color: 'var(--text-muted)', marginTop: 4 } },
138
+ node.host + ':' + node.port, ' | ',
139
+ node.platform + '/' + node.arch, ' | ',
140
+ 'v' + node.version
141
+ )
142
+ ),
143
+ h('button', { className: 'btn btn-ghost btn-sm', onClick: function() { removeNode(node.nodeId); }, title: 'Remove' },
144
+ I.trash()
145
+ )
146
+ ),
147
+ // Resources
148
+ h('div', { style: { display: 'flex', gap: 20, marginTop: 12 } },
149
+ h('div', null,
150
+ h('div', { style: { fontSize: 11, color: 'var(--text-muted)' } }, 'CPUs'),
151
+ h('div', { style: { fontWeight: 600 } }, node.cpuCount)
152
+ ),
153
+ h('div', null,
154
+ h('div', { style: { fontSize: 11, color: 'var(--text-muted)' } }, 'Memory'),
155
+ h('div', { style: { fontWeight: 600 } }, formatBytes(node.memoryMb))
156
+ ),
157
+ h('div', null,
158
+ h('div', { style: { fontSize: 11, color: 'var(--text-muted)' } }, 'Agents'),
159
+ h('div', { style: { fontWeight: 600 } }, node.agents ? node.agents.length : 0)
160
+ ),
161
+ h('div', null,
162
+ h('div', { style: { fontSize: 11, color: 'var(--text-muted)' } }, 'Last Heartbeat'),
163
+ h('div', { style: { fontWeight: 600, color: node.status === 'online' ? 'var(--accent-green)' : 'var(--text-muted)' } }, timeSince(node.lastHeartbeat))
164
+ )
165
+ ),
166
+ // Capabilities
167
+ node.capabilities && node.capabilities.length > 0 && h('div', { style: { display: 'flex', gap: 4, marginTop: 8 } },
168
+ node.capabilities.map(function(c) {
169
+ return h('span', { key: c, className: 'badge badge-neutral', style: { fontSize: 10 } }, c);
170
+ })
171
+ ),
172
+ // Agent list
173
+ node.agents && node.agents.length > 0 && h('div', { style: { marginTop: 8, fontSize: 12, color: 'var(--text-muted)' } },
174
+ 'Running: ', node.agents.join(', ')
175
+ )
176
+ )
177
+ );
178
+ })
179
+ )
180
+ );
181
+ }
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  import {
14
14
  provision,
15
15
  runSetupWizard
16
- } from "./chunk-RF2LGX3E.js";
16
+ } from "./chunk-SVSLIQYN.js";
17
17
  import {
18
18
  AgentRuntime,
19
19
  EmailChannel,
@@ -28,7 +28,7 @@ import {
28
28
  executeTool,
29
29
  runAgentLoop,
30
30
  toolsToDefinitions
31
- } from "./chunk-7HBGXW7Z.js";
31
+ } from "./chunk-KN3T3CTD.js";
32
32
  import {
33
33
  ValidationError,
34
34
  auditLogger,
@@ -42,7 +42,7 @@ import {
42
42
  requireRole,
43
43
  securityHeaders,
44
44
  validate
45
- } from "./chunk-YCWOCIPH.js";
45
+ } from "./chunk-GYB2WHMN.js";
46
46
  import "./chunk-DJBCRQTD.js";
47
47
  import {
48
48
  PROVIDER_REGISTRY,
@@ -82,7 +82,7 @@ import {
82
82
  init_storage_manager,
83
83
  init_tenant,
84
84
  init_workforce
85
- } from "./chunk-CAHNZGGK.js";
85
+ } from "./chunk-CQYLRIQ3.js";
86
86
  import {
87
87
  ENGINE_TABLES,
88
88
  ENGINE_TABLES_POSTGRES,