@agenticmail/enterprise 0.5.415 → 0.5.417

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,286 @@
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-XRYYBBCW.js");
97
+ const { createServer } = await import("./server-JPZHMUHU.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 { startBackgroundUpdateCheck } = await import("./cli-update-P3TAXEW7.js");
110
+ startBackgroundUpdateCheck();
111
+ } catch {
112
+ }
113
+ try {
114
+ const { startPreventSleep } = await import("./screen-unlock-4RPZBHOI.js");
115
+ const adminDb = server.getAdminDb?.() || server.adminDb;
116
+ if (adminDb) {
117
+ const settings = await adminDb.getSettings?.().catch(() => null);
118
+ const screenAccess = settings?.securityConfig?.screenAccess;
119
+ if (screenAccess?.enabled && screenAccess?.preventSleep) {
120
+ startPreventSleep();
121
+ console.log("[startup] Prevent-sleep enabled \u2014 system will stay awake while agents are active");
122
+ }
123
+ }
124
+ } catch {
125
+ }
126
+ try {
127
+ await setupSystemPersistence();
128
+ } catch (e) {
129
+ console.warn("[startup] System persistence setup skipped: " + e.message);
130
+ }
131
+ const tunnelToken = process.env.CLOUDFLARED_TOKEN;
132
+ if (tunnelToken) {
133
+ try {
134
+ const { execSync, spawn } = await import("child_process");
135
+ try {
136
+ execSync(process.platform === "win32" ? "where cloudflared" : "which cloudflared", { timeout: 3e3 });
137
+ } catch {
138
+ console.log("[startup] cloudflared not found \u2014 skipping tunnel auto-start");
139
+ console.log("[startup] Install cloudflared to enable tunnel: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/");
140
+ return;
141
+ }
142
+ try {
143
+ if (process.platform === "win32") {
144
+ const tasklist = execSync('tasklist /FI "IMAGENAME eq cloudflared.exe" /NH', { encoding: "utf8", timeout: 5e3 });
145
+ if (tasklist.includes("cloudflared.exe")) {
146
+ console.log("[startup] cloudflared tunnel already running");
147
+ return;
148
+ }
149
+ } else {
150
+ execSync('pgrep -f "cloudflared.*tunnel.*run"', { timeout: 3e3 });
151
+ console.log("[startup] cloudflared tunnel already running");
152
+ return;
153
+ }
154
+ } catch {
155
+ }
156
+ const subdomain = process.env.AGENTICMAIL_SUBDOMAIN || process.env.AGENTICMAIL_DOMAIN || "";
157
+ console.log(`[startup] Starting cloudflared tunnel${subdomain ? ` for ${subdomain}.agenticmail.io` : ""}...`);
158
+ let cfBin = "cloudflared";
159
+ if (process.platform === "win32") {
160
+ try {
161
+ cfBin = execSync("where cloudflared", { encoding: "utf8", timeout: 3e3 }).trim().split("\n")[0].trim();
162
+ } catch {
163
+ const candidate = `${process.env.LOCALAPPDATA || ""}\\cloudflared\\cloudflared.exe`;
164
+ try {
165
+ (await import("fs")).statSync(candidate);
166
+ cfBin = candidate;
167
+ } catch {
168
+ }
169
+ }
170
+ }
171
+ const child = spawn(cfBin, ["tunnel", "--no-autoupdate", "run", "--token", tunnelToken], {
172
+ detached: true,
173
+ stdio: "ignore"
174
+ });
175
+ child.unref();
176
+ console.log("[startup] cloudflared tunnel started (pid " + child.pid + ")");
177
+ } catch (e) {
178
+ console.warn("[startup] Could not auto-start cloudflared: " + e.message);
179
+ }
180
+ }
181
+ }
182
+ async function setupSystemPersistence() {
183
+ const { execSync, spawnSync } = await import("child_process");
184
+ const { existsSync: exists, writeFileSync, mkdirSync } = await import("fs");
185
+ const { join: pathJoin } = await import("path");
186
+ const platform = process.platform;
187
+ if (!process.env.PM2_HOME && !process.env.pm_id) {
188
+ return;
189
+ }
190
+ const markerDir = pathJoin(homedir(), ".agenticmail");
191
+ const markerFile = pathJoin(markerDir, ".persistence-configured");
192
+ if (exists(markerFile)) {
193
+ try {
194
+ execSync("pm2 save --silent", { timeout: 1e4, stdio: "ignore" });
195
+ } catch {
196
+ }
197
+ return;
198
+ }
199
+ console.log("[startup] Configuring system persistence (one-time setup)...");
200
+ try {
201
+ if (platform === "darwin") {
202
+ const result = spawnSync("pm2", ["startup", "launchd", "--silent"], {
203
+ timeout: 15e3,
204
+ stdio: "pipe",
205
+ encoding: "utf-8"
206
+ });
207
+ const output = (result.stdout || "") + (result.stderr || "");
208
+ const sudoMatch = output.match(/sudo\s+env\s+.*pm2\s+startup.*/);
209
+ if (sudoMatch) {
210
+ console.log("[startup] PM2 startup requires sudo. Run this once:");
211
+ console.log(" " + sudoMatch[0]);
212
+ } else {
213
+ console.log("[startup] PM2 startup configured (launchd)");
214
+ }
215
+ const plistPath = pathJoin(homedir(), "Library", "LaunchAgents", `pm2.${process.env.USER || "user"}.plist`);
216
+ if (exists(plistPath)) {
217
+ try {
218
+ execSync(`launchctl load -w "${plistPath}"`, { timeout: 5e3, stdio: "ignore" });
219
+ } catch {
220
+ }
221
+ }
222
+ } else if (platform === "linux") {
223
+ const result = spawnSync("pm2", ["startup", "systemd", "--silent"], {
224
+ timeout: 15e3,
225
+ stdio: "pipe",
226
+ encoding: "utf-8"
227
+ });
228
+ const output = (result.stdout || "") + (result.stderr || "");
229
+ const sudoMatch = output.match(/sudo\s+env\s+.*pm2\s+startup.*/);
230
+ if (sudoMatch) {
231
+ try {
232
+ execSync(sudoMatch[0], { timeout: 15e3, stdio: "ignore" });
233
+ console.log("[startup] PM2 startup configured (systemd)");
234
+ } catch {
235
+ console.log("[startup] PM2 startup requires root. Run this once:");
236
+ console.log(" " + sudoMatch[0]);
237
+ }
238
+ } else {
239
+ console.log("[startup] PM2 startup configured (systemd)");
240
+ }
241
+ } else if (platform === "win32") {
242
+ try {
243
+ execSync("npm list -g pm2-windows-startup", { timeout: 1e4, stdio: "ignore" });
244
+ } catch {
245
+ console.log("[startup] Installing pm2-windows-startup...");
246
+ try {
247
+ execSync("npm install -g pm2-windows-startup", { timeout: 6e4, stdio: "ignore" });
248
+ execSync("pm2-startup install", { timeout: 15e3, stdio: "ignore" });
249
+ console.log("[startup] PM2 startup configured (Windows Service)");
250
+ } catch (e) {
251
+ console.warn("[startup] Could not install pm2-windows-startup: " + e.message);
252
+ }
253
+ }
254
+ }
255
+ } catch (e) {
256
+ console.warn("[startup] PM2 startup setup: " + e.message);
257
+ }
258
+ try {
259
+ const moduleList = execSync("pm2 ls --silent 2>/dev/null || true", { timeout: 1e4, encoding: "utf-8" });
260
+ if (!moduleList.includes("pm2-logrotate")) {
261
+ console.log("[startup] Installing pm2-logrotate...");
262
+ execSync("pm2 install pm2-logrotate --silent", { timeout: 6e4, stdio: "ignore" });
263
+ execSync("pm2 set pm2-logrotate:max_size 10M --silent", { timeout: 5e3, stdio: "ignore" });
264
+ execSync("pm2 set pm2-logrotate:retain 5 --silent", { timeout: 5e3, stdio: "ignore" });
265
+ execSync("pm2 set pm2-logrotate:compress true --silent", { timeout: 5e3, stdio: "ignore" });
266
+ console.log("[startup] Log rotation configured (10MB, 5 files)");
267
+ }
268
+ } catch {
269
+ }
270
+ try {
271
+ execSync("pm2 save --silent", { timeout: 1e4, stdio: "ignore" });
272
+ console.log("[startup] Process list saved");
273
+ } catch {
274
+ }
275
+ try {
276
+ if (!exists(markerDir)) mkdirSync(markerDir, { recursive: true });
277
+ writeFileSync(markerFile, (/* @__PURE__ */ new Date()).toISOString() + `
278
+ platform=${platform}
279
+ `, { mode: 384 });
280
+ console.log("[startup] System persistence configured successfully");
281
+ } catch {
282
+ }
283
+ }
284
+ export {
285
+ runServe
286
+ };
package/dist/cli.js CHANGED
@@ -65,14 +65,14 @@ Skill Development:
65
65
  break;
66
66
  case "serve":
67
67
  case "start":
68
- import("./cli-serve-X4XJJ6UO.js").then((m) => m.runServe(args.slice(1))).catch(fatal);
68
+ import("./cli-serve-WIWI3XVS.js").then((m) => m.runServe(args.slice(1))).catch(fatal);
69
69
  break;
70
70
  case "agent":
71
- import("./cli-agent-KPFEVNRA.js").then((m) => m.runAgent(args.slice(1))).catch(fatal);
71
+ import("./cli-agent-XAH3IZGH.js").then((m) => m.runAgent(args.slice(1))).catch(fatal);
72
72
  break;
73
73
  case "setup":
74
74
  default:
75
- import("./setup-LZYTNKYL.js").then((m) => m.runSetupWizard()).catch(fatal);
75
+ import("./setup-QCOWFHA4.js").then((m) => m.runSetupWizard()).catch(fatal);
76
76
  break;
77
77
  }
78
78
  function fatal(err) {
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  provision,
9
9
  runSetupWizard
10
- } from "./chunk-E57FUANR.js";
10
+ } from "./chunk-D2JF3JH6.js";
11
11
  import {
12
12
  AgenticMailManager,
13
13
  GoogleEmailProvider,
@@ -28,7 +28,7 @@ import {
28
28
  executeTool,
29
29
  runAgentLoop,
30
30
  toolsToDefinitions
31
- } from "./chunk-E2YXGKPD.js";
31
+ } from "./chunk-X4LT3R5Y.js";
32
32
  import "./chunk-WPM52NBU.js";
33
33
  import {
34
34
  ValidationError,
@@ -43,7 +43,7 @@ import {
43
43
  requireRole,
44
44
  securityHeaders,
45
45
  validate
46
- } from "./chunk-52WD6CN6.js";
46
+ } from "./chunk-MYTMRPMI.js";
47
47
  import "./chunk-DJBCRQTD.js";
48
48
  import {
49
49
  PROVIDER_REGISTRY,
@@ -0,0 +1,46 @@
1
+ import {
2
+ AgentRuntime,
3
+ EmailChannel,
4
+ FollowUpScheduler,
5
+ SessionManager,
6
+ SubAgentManager,
7
+ ToolRegistry,
8
+ callLLM,
9
+ createAgentRuntime,
10
+ createNoopHooks,
11
+ createRuntimeHooks,
12
+ estimateMessageTokens,
13
+ estimateTokens,
14
+ executeTool,
15
+ runAgentLoop,
16
+ toolsToDefinitions
17
+ } from "./chunk-X4LT3R5Y.js";
18
+ import "./chunk-WPM52NBU.js";
19
+ import {
20
+ PROVIDER_REGISTRY,
21
+ listAllProviders,
22
+ resolveApiKeyForProvider,
23
+ resolveProvider
24
+ } from "./chunk-UF3ZJMJO.js";
25
+ import "./chunk-KFQGP6VL.js";
26
+ export {
27
+ AgentRuntime,
28
+ EmailChannel,
29
+ FollowUpScheduler,
30
+ PROVIDER_REGISTRY,
31
+ SessionManager,
32
+ SubAgentManager,
33
+ ToolRegistry,
34
+ callLLM,
35
+ createAgentRuntime,
36
+ createNoopHooks,
37
+ createRuntimeHooks,
38
+ estimateMessageTokens,
39
+ estimateTokens,
40
+ executeTool,
41
+ listAllProviders,
42
+ resolveApiKeyForProvider,
43
+ resolveProvider,
44
+ runAgentLoop,
45
+ toolsToDefinitions
46
+ };
@@ -0,0 +1,28 @@
1
+ import {
2
+ createServer
3
+ } from "./chunk-MYTMRPMI.js";
4
+ import "./chunk-DJBCRQTD.js";
5
+ import "./chunk-UF3ZJMJO.js";
6
+ import "./chunk-ZZQWXIAX.js";
7
+ import "./chunk-WYDVMFGJ.js";
8
+ import "./chunk-3UAFHUEC.js";
9
+ import "./chunk-E6B4W3WG.js";
10
+ import "./chunk-Z7NVD3OQ.js";
11
+ import "./chunk-VSBC4SWO.js";
12
+ import "./chunk-AF3WSNVX.js";
13
+ import "./chunk-74ZCQKYU.js";
14
+ import "./chunk-ZNLABJCS.js";
15
+ import "./chunk-C6JP5NR6.js";
16
+ import "./chunk-WUAWWKTN.js";
17
+ import "./chunk-E5QPDR3O.js";
18
+ import "./chunk-YDD5TC5Q.js";
19
+ import "./chunk-37ABTUFU.js";
20
+ import "./chunk-NU657BBQ.js";
21
+ import "./chunk-PGAU3W3M.js";
22
+ import "./chunk-FLQ5FLHW.js";
23
+ import "./chunk-YZRJHYKB.js";
24
+ import "./chunk-22U7TZPN.js";
25
+ import "./chunk-KFQGP6VL.js";
26
+ export {
27
+ createServer
28
+ };
@@ -0,0 +1,20 @@
1
+ import {
2
+ promptCompanyInfo,
3
+ promptDatabase,
4
+ promptDeployment,
5
+ promptDomain,
6
+ promptRegistration,
7
+ provision,
8
+ runSetupWizard
9
+ } from "./chunk-D2JF3JH6.js";
10
+ import "./chunk-P6W565WH.js";
11
+ import "./chunk-KFQGP6VL.js";
12
+ export {
13
+ promptCompanyInfo,
14
+ promptDatabase,
15
+ promptDeployment,
16
+ promptDomain,
17
+ promptRegistration,
18
+ provision,
19
+ runSetupWizard
20
+ };
@@ -305,3 +305,15 @@
305
305
  2026-03-06 21:11:37: 2026-03-06T20:11:37Z ERR error="unexpected EOF" connIndex=2 event=1 ingressRule=0 originService=http://localhost:3100
306
306
  2026-03-06 21:11:37: 2026-03-06T20:11:37Z ERR Request failed error="unexpected EOF" connIndex=2 dest=https://enterprise.agenticmail.io/api/engine/agent-status-stream?agentId=3eecd57d-03ae-440d-8945-5b35f43a8d90 event=0 ip=198.41.192.47 type=http
307
307
  2026-03-06 21:11:37: 2026-03-06T20:11:37Z ERR Request failed error="unexpected EOF" connIndex=2 dest=https://enterprise.agenticmail.io/api/engine/agent-status-stream?agentId=3eecd57d-03ae-440d-8945-5b35f43a8d90 event=0 ip=198.41.192.47 type=http
308
+ 2026-03-06 21:19:15: 2026-03-06T20:19:15Z ERR error="unexpected EOF" connIndex=0 event=1 ingressRule=0 originService=http://localhost:3100
309
+ 2026-03-06 21:19:15: 2026-03-06T20:19:15Z ERR error="unexpected EOF" connIndex=0 event=1 ingressRule=0 originService=http://localhost:3100
310
+ 2026-03-06 21:19:15: 2026-03-06T20:19:15Z ERR Request failed error="unexpected EOF" connIndex=0 dest=https://enterprise.agenticmail.io/api/engine/agent-status-stream?agentId=3eecd57d-03ae-440d-8945-5b35f43a8d90 event=0 ip=198.41.200.43 type=http
311
+ 2026-03-06 21:19:15: 2026-03-06T20:19:15Z ERR Request failed error="unexpected EOF" connIndex=0 dest=https://enterprise.agenticmail.io/api/engine/agent-status-stream?agentId=3eecd57d-03ae-440d-8945-5b35f43a8d90 event=0 ip=198.41.200.43 type=http
312
+ 2026-03-06 21:25:44: 2026-03-06T20:25:44Z ERR error="unexpected EOF" connIndex=0 event=1 ingressRule=0 originService=http://localhost:3100
313
+ 2026-03-06 21:25:44: 2026-03-06T20:25:44Z ERR error="unexpected EOF" connIndex=0 event=1 ingressRule=0 originService=http://localhost:3100
314
+ 2026-03-06 21:25:44: 2026-03-06T20:25:44Z ERR Request failed error="unexpected EOF" connIndex=0 dest=https://enterprise.agenticmail.io/api/engine/agent-status-stream?agentId=3eecd57d-03ae-440d-8945-5b35f43a8d90 event=0 ip=198.41.200.43 type=http
315
+ 2026-03-06 21:25:44: 2026-03-06T20:25:44Z ERR Request failed error="unexpected EOF" connIndex=0 dest=https://enterprise.agenticmail.io/api/engine/agent-status-stream?agentId=3eecd57d-03ae-440d-8945-5b35f43a8d90 event=0 ip=198.41.200.43 type=http
316
+ 2026-03-06 21:34:22: 2026-03-06T20:34:22Z ERR error="stream 2389 canceled by remote with error code 0" connIndex=2 event=1 ingressRule=0 originService=http://localhost:3100
317
+ 2026-03-06 21:34:22: 2026-03-06T20:34:22Z ERR error="stream 2385 canceled by remote with error code 0" connIndex=2 event=1 ingressRule=0 originService=http://localhost:3100
318
+ 2026-03-06 21:34:22: 2026-03-06T20:34:22Z ERR Request failed error="stream 2389 canceled by remote with error code 0" connIndex=2 dest=https://enterprise.agenticmail.io/api/engine/agent-status-stream?agentId=3eecd57d-03ae-440d-8945-5b35f43a8d90 event=0 ip=198.41.192.47 type=http
319
+ 2026-03-06 21:34:22: 2026-03-06T20:34:22Z ERR Request failed error="stream 2385 canceled by remote with error code 0" connIndex=2 dest=https://enterprise.agenticmail.io/api/engine/agent-status-stream?agentId=3eecd57d-03ae-440d-8945-5b35f43a8d90 event=0 ip=198.41.192.47 type=http
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenticmail/enterprise",
3
- "version": "0.5.415",
3
+ "version": "0.5.417",
4
4
  "description": "AgenticMail Enterprise — cloud-hosted AI agent identity, email, auth & compliance for organizations",
5
5
  "type": "module",
6
6
  "bin": {