@agenticmail/enterprise 0.5.312 → 0.5.313

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 (208) hide show
  1. package/README.md +682 -544
  2. package/dist/agent-autonomy-PSXQ4MNP.js +766 -0
  3. package/dist/agent-heartbeat-6H3YAQ32.js +510 -0
  4. package/dist/agent-heartbeat-7WS3XILF.js +510 -0
  5. package/dist/agent-heartbeat-BFGKYUUK.js +510 -0
  6. package/dist/agent-heartbeat-SSV65YTX.js +510 -0
  7. package/dist/agent-heartbeat-T5IIHVF4.js +510 -0
  8. package/dist/agent-heartbeat-X3C6FIU2.js +510 -0
  9. package/dist/agent-tools-BW6CLQQ7.js +13897 -0
  10. package/dist/agent-tools-KEA7QEWF.js +13897 -0
  11. package/dist/agent-tools-NU7V3S5N.js +13899 -0
  12. package/dist/agent-tools-WINDYRQ2.js +13897 -0
  13. package/dist/chunk-3ELH5CU6.js +4910 -0
  14. package/dist/chunk-4QYRS3MS.js +1519 -0
  15. package/dist/chunk-52REEVDW.js +1519 -0
  16. package/dist/chunk-5RZJ76YI.js +4977 -0
  17. package/dist/chunk-6L7FQI5Q.js +4909 -0
  18. package/dist/chunk-763OMGFI.js +1519 -0
  19. package/dist/chunk-7ILSXGY6.js +1519 -0
  20. package/dist/chunk-7UCKD25B.js +551 -0
  21. package/dist/chunk-A6MSR7DL.js +4977 -0
  22. package/dist/chunk-ASD2YB6O.js +1519 -0
  23. package/dist/chunk-AZOIHLLX.js +4977 -0
  24. package/dist/chunk-BDCFOP7O.js +537 -0
  25. package/dist/chunk-BSVWPG6I.js +106 -0
  26. package/dist/chunk-C46DNDZB.js +1519 -0
  27. package/dist/chunk-CFVTK4FQ.js +4977 -0
  28. package/dist/chunk-CHJAOKCJ.js +4921 -0
  29. package/dist/chunk-CYEWTXYH.js +4977 -0
  30. package/dist/chunk-D3KFSWLK.js +48 -0
  31. package/dist/chunk-DUVGNAIY.js +4977 -0
  32. package/dist/chunk-DX4XEFVE.js +25229 -0
  33. package/dist/chunk-EX6FQSEV.js +167 -0
  34. package/dist/chunk-F5VZ5EUH.js +1519 -0
  35. package/dist/chunk-FVUDSPOD.js +4977 -0
  36. package/dist/chunk-G6FTZKJX.js +4977 -0
  37. package/dist/chunk-GFEAZN6Y.js +1519 -0
  38. package/dist/chunk-HKV4FQFW.js +1519 -0
  39. package/dist/chunk-ICCPULDT.js +25217 -0
  40. package/dist/chunk-IYEM627Q.js +25216 -0
  41. package/dist/chunk-JHRJ4QJ6.js +1519 -0
  42. package/dist/chunk-K2DAUYHV.js +4977 -0
  43. package/dist/chunk-KDQDSZZQ.js +4973 -0
  44. package/dist/chunk-LDUD6AZY.js +1519 -0
  45. package/dist/chunk-LES5TJ5L.js +4909 -0
  46. package/dist/chunk-MJGGW6MC.js +106 -0
  47. package/dist/chunk-MQKIWAHQ.js +106 -0
  48. package/dist/chunk-NGA7BBPF.js +48 -0
  49. package/dist/chunk-OE3TI4IQ.js +1519 -0
  50. package/dist/chunk-OHSBIYDR.js +4977 -0
  51. package/dist/chunk-OZEYDEPB.js +1519 -0
  52. package/dist/chunk-P4PODSQH.js +1519 -0
  53. package/dist/chunk-P7UOSFIE.js +636 -0
  54. package/dist/chunk-PFN6DODU.js +4921 -0
  55. package/dist/chunk-PKDVM4IY.js +4917 -0
  56. package/dist/chunk-Q5KG3G7U.js +25115 -0
  57. package/dist/chunk-QMVNW4FJ.js +25229 -0
  58. package/dist/chunk-QZ5UPRBE.js +4977 -0
  59. package/dist/chunk-SPP23N42.js +4977 -0
  60. package/dist/chunk-SRGHNFOY.js +4921 -0
  61. package/dist/chunk-TPLVQFXM.js +2594 -0
  62. package/dist/chunk-U3XYF4QP.js +4977 -0
  63. package/dist/chunk-VRRJH2DY.js +4921 -0
  64. package/dist/chunk-WY42BS3F.js +1519 -0
  65. package/dist/chunk-XAA4VHHZ.js +1519 -0
  66. package/dist/chunk-Z5Y5KTPC.js +4977 -0
  67. package/dist/chunk-ZA4QRACH.js +4977 -0
  68. package/dist/chunk-ZHLGSTXF.js +4909 -0
  69. package/dist/cli-agent-26BUULHZ.js +2169 -0
  70. package/dist/cli-agent-2FLJWXOC.js +2169 -0
  71. package/dist/cli-agent-4NNQFLO6.js +2255 -0
  72. package/dist/cli-agent-5WV3EEPW.js +2252 -0
  73. package/dist/cli-agent-65JUT6DU.js +2193 -0
  74. package/dist/cli-agent-6HLL7A5K.js +2255 -0
  75. package/dist/cli-agent-CZ26QWUZ.js +2210 -0
  76. package/dist/cli-agent-HPVSWDNQ.js +2255 -0
  77. package/dist/cli-agent-K4SBVG5X.js +2210 -0
  78. package/dist/cli-agent-K5D424X2.js +2252 -0
  79. package/dist/cli-agent-U4OL5FGK.js +2210 -0
  80. package/dist/cli-agent-WUMPOIKQ.js +2169 -0
  81. package/dist/cli-agent-WWRGGJ2F.js +2255 -0
  82. package/dist/cli-agent-ZDBBTVGU.js +2193 -0
  83. package/dist/cli-agent-ZIZ5JP4O.js +2252 -0
  84. package/dist/cli-recover-I4KNR2OI.js +487 -0
  85. package/dist/cli-recover-IQTUKWR2.js +487 -0
  86. package/dist/cli-recover-OYJHELOR.js +487 -0
  87. package/dist/cli-recover-PVQC7UXB.js +487 -0
  88. package/dist/cli-recover-T32NABFA.js +487 -0
  89. package/dist/cli-serve-FTQJ3RUK.js +143 -0
  90. package/dist/cli-serve-G4PUCASH.js +143 -0
  91. package/dist/cli-serve-HBZYUUQ3.js +143 -0
  92. package/dist/cli-serve-L3NUROMO.js +143 -0
  93. package/dist/cli-serve-LAA5WIZK.js +143 -0
  94. package/dist/cli-serve-LV4TUSJD.js +143 -0
  95. package/dist/cli-serve-MFCTVA2L.js +140 -0
  96. package/dist/cli-serve-QCRUFI5B.js +143 -0
  97. package/dist/cli-serve-S7OGQN4P.js +143 -0
  98. package/dist/cli-serve-SI4BQRXT.js +140 -0
  99. package/dist/cli-serve-UNB7EHN4.js +143 -0
  100. package/dist/cli-serve-UV3GVDRD.js +143 -0
  101. package/dist/cli-serve-V5QICXR5.js +143 -0
  102. package/dist/cli-serve-VG6Z6GIB.js +143 -0
  103. package/dist/cli-serve-XSYHPGZI.js +143 -0
  104. package/dist/cli-serve-Y534FCRV.js +140 -0
  105. package/dist/cli-verify-CZIITRED.js +149 -0
  106. package/dist/cli-verify-N73GOKEF.js +149 -0
  107. package/dist/cli-verify-QEEBZOUZ.js +149 -0
  108. package/dist/cli-verify-RC5HI6DU.js +149 -0
  109. package/dist/cli-verify-VKBNIEAX.js +149 -0
  110. package/dist/cli.js +5 -5
  111. package/dist/dashboard/app.js +8 -2
  112. package/dist/dashboard/components/org-switcher.js +5 -1
  113. package/dist/dashboard/org-switcher.js +156 -0
  114. package/dist/dashboard/pages/login.js +160 -4
  115. package/dist/dashboard/pages/task-pipeline.js +1 -1
  116. package/dist/factory-3IWXVE37.js +9 -0
  117. package/dist/factory-5M6PTMLC.js +11 -0
  118. package/dist/factory-CSSHN7GE.js +11 -0
  119. package/dist/factory-JFWXTAWK.js +11 -0
  120. package/dist/factory-TBGUYM5X.js +9 -0
  121. package/dist/google-W5AYGNUJ.js +33 -0
  122. package/dist/index.js +6 -6
  123. package/dist/meetings-FJ453ENF.js +12 -0
  124. package/dist/postgres-BCHZWRU3.js +832 -0
  125. package/dist/postgres-BI4QVRM6.js +825 -0
  126. package/dist/postgres-BOTHOPDW.js +875 -0
  127. package/dist/postgres-JBUKR3TA.js +873 -0
  128. package/dist/postgres-Z7QYSU6K.js +861 -0
  129. package/dist/routes-7QYAQTWA.js +90 -0
  130. package/dist/routes-JCBVZU54.js +90 -0
  131. package/dist/routes-KEDEJFRE.js +90 -0
  132. package/dist/routes-WI64ADVH.js +90 -0
  133. package/dist/routes-X36OSCID.js +90 -0
  134. package/dist/runtime-75XR6KEW.js +45 -0
  135. package/dist/runtime-BNM7ZNNL.js +45 -0
  136. package/dist/runtime-ES6WCJ7D.js +45 -0
  137. package/dist/runtime-KYJTML2B.js +45 -0
  138. package/dist/runtime-LO67ZHQA.js +45 -0
  139. package/dist/runtime-VIXKKVSZ.js +45 -0
  140. package/dist/runtime-WHWJPCGK.js +45 -0
  141. package/dist/runtime-Z2Q6GUHH.js +45 -0
  142. package/dist/runtime-ZZ6CALSB.js +45 -0
  143. package/dist/server-27A4WEJC.js +28 -0
  144. package/dist/server-2CBXP4WS.js +28 -0
  145. package/dist/server-4JQAB5R4.js +28 -0
  146. package/dist/server-6BOM5U64.js +28 -0
  147. package/dist/server-FLJKNPRD.js +28 -0
  148. package/dist/server-HMIHIQ2N.js +28 -0
  149. package/dist/server-KIXXLR2D.js +28 -0
  150. package/dist/server-KSEIZTXF.js +28 -0
  151. package/dist/server-MPVW7DKZ.js +28 -0
  152. package/dist/server-PRTVRQ2D.js +28 -0
  153. package/dist/server-SYIG6HAX.js +28 -0
  154. package/dist/server-U32KDIXC.js +28 -0
  155. package/dist/server-WFN6CA4T.js +28 -0
  156. package/dist/server-XQUE3FGT.js +28 -0
  157. package/dist/server-XWT2UORK.js +28 -0
  158. package/dist/server-Y3BGNN5Q.js +28 -0
  159. package/dist/setup-352L2TPS.js +20 -0
  160. package/dist/setup-4MM645XK.js +20 -0
  161. package/dist/setup-5JPWW6IP.js +20 -0
  162. package/dist/setup-CUN6LVUV.js +20 -0
  163. package/dist/setup-D3YHPWPY.js +20 -0
  164. package/dist/setup-D4A5I6UM.js +20 -0
  165. package/dist/setup-DOPLXTB3.js +20 -0
  166. package/dist/setup-E3NSIM6B.js +20 -0
  167. package/dist/setup-E3V2D7NL.js +20 -0
  168. package/dist/setup-FSYPGI2C.js +20 -0
  169. package/dist/setup-G3RPKRG3.js +20 -0
  170. package/dist/setup-KJ77HNWK.js +20 -0
  171. package/dist/setup-LPSOY5V5.js +20 -0
  172. package/dist/setup-N3ODDSQE.js +20 -0
  173. package/dist/setup-NLDM3M2P.js +20 -0
  174. package/dist/setup-SWJMNDWF.js +20 -0
  175. package/dist/system-prompts-6OUTAMH6.js +41 -0
  176. package/dist/task-queue-YP2I54IA.js +9 -0
  177. package/dist/telegram-QRNGRT5M.js +17 -0
  178. package/dist/whatsapp-VYVINCGV.js +31 -0
  179. package/god_is_great.html +35 -0
  180. package/package.json +1 -1
  181. package/src/agent-tools/index.ts +4 -1
  182. package/src/agent-tools/tool-resolver.ts +15 -4
  183. package/src/agent-tools/tools/browser.ts +2 -2
  184. package/src/agent-tools/tools/local/dependency-manager.ts +286 -0
  185. package/src/agent-tools/tools/local/index.ts +3 -0
  186. package/src/agent-tools/tools/messaging/telegram.ts +29 -0
  187. package/src/agent-tools/tools/messaging/whatsapp.ts +59 -4
  188. package/src/auth/routes.ts +1 -1
  189. package/src/cli-agent.ts +47 -6
  190. package/src/cli-serve.ts +2 -5
  191. package/src/dashboard/app.js +8 -2
  192. package/src/dashboard/components/org-switcher.js +5 -1
  193. package/src/dashboard/pages/login.js +160 -4
  194. package/src/dashboard/pages/task-pipeline.js +1 -1
  195. package/src/db/adapter.ts +2 -0
  196. package/src/db/factory.ts +78 -0
  197. package/src/db/postgres.ts +57 -12
  198. package/src/engine/agent-autonomy.ts +1 -1
  199. package/src/engine/agent-heartbeat.ts +1 -1
  200. package/src/engine/messaging-poller.ts +146 -11
  201. package/src/engine/oauth-connect-routes.ts +23 -3
  202. package/src/engine/routes.ts +1 -1
  203. package/src/engine/task-poller.ts +54 -3
  204. package/src/engine/task-queue.ts +30 -0
  205. package/src/runtime/index.ts +2 -1
  206. package/src/runtime/types.ts +2 -0
  207. package/src/server.ts +13 -1
  208. package/src/system-prompts/triage.ts +1 -1
@@ -0,0 +1,143 @@
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 } = await import("./factory-NUY5F26A.js");
97
+ const { createServer } = await import("./server-XWT2UORK.js");
98
+ const db = await createAdapter({
99
+ type: DATABASE_URL.startsWith("postgres") ? "postgres" : "sqlite",
100
+ connectionString: DATABASE_URL
101
+ });
102
+ await db.migrate();
103
+ const server = createServer({
104
+ port: PORT,
105
+ db,
106
+ jwtSecret: JWT_SECRET,
107
+ corsOrigins: ["*"]
108
+ });
109
+ await server.start();
110
+ console.log(`AgenticMail Enterprise server running on :${PORT}`);
111
+ const tunnelToken = process.env.CLOUDFLARED_TOKEN;
112
+ if (tunnelToken) {
113
+ try {
114
+ const { execSync, spawn } = await import("child_process");
115
+ try {
116
+ execSync("which cloudflared", { timeout: 3e3 });
117
+ } catch {
118
+ console.log("[startup] cloudflared not found \u2014 skipping tunnel auto-start");
119
+ console.log("[startup] Install cloudflared to enable tunnel: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/");
120
+ return;
121
+ }
122
+ try {
123
+ execSync('pgrep -f "cloudflared.*tunnel.*run"', { timeout: 3e3 });
124
+ console.log("[startup] cloudflared tunnel already running");
125
+ return;
126
+ } catch {
127
+ }
128
+ const subdomain = process.env.AGENTICMAIL_SUBDOMAIN || process.env.AGENTICMAIL_DOMAIN || "";
129
+ console.log(`[startup] Starting cloudflared tunnel${subdomain ? ` for ${subdomain}.agenticmail.io` : ""}...`);
130
+ const child = spawn("cloudflared", ["tunnel", "--no-autoupdate", "run", "--token", tunnelToken], {
131
+ detached: true,
132
+ stdio: "ignore"
133
+ });
134
+ child.unref();
135
+ console.log("[startup] cloudflared tunnel started (pid " + child.pid + ")");
136
+ } catch (e) {
137
+ console.warn("[startup] Could not auto-start cloudflared: " + e.message);
138
+ }
139
+ }
140
+ }
141
+ export {
142
+ runServe
143
+ };
@@ -0,0 +1,143 @@
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 } = await import("./factory-NUY5F26A.js");
97
+ const { createServer } = await import("./server-6BOM5U64.js");
98
+ const db = await createAdapter({
99
+ type: DATABASE_URL.startsWith("postgres") ? "postgres" : "sqlite",
100
+ connectionString: DATABASE_URL
101
+ });
102
+ await db.migrate();
103
+ const server = createServer({
104
+ port: PORT,
105
+ db,
106
+ jwtSecret: JWT_SECRET,
107
+ corsOrigins: ["*"]
108
+ });
109
+ await server.start();
110
+ console.log(`AgenticMail Enterprise server running on :${PORT}`);
111
+ const tunnelToken = process.env.CLOUDFLARED_TOKEN;
112
+ if (tunnelToken) {
113
+ try {
114
+ const { execSync, spawn } = await import("child_process");
115
+ try {
116
+ execSync("which cloudflared", { timeout: 3e3 });
117
+ } catch {
118
+ console.log("[startup] cloudflared not found \u2014 skipping tunnel auto-start");
119
+ console.log("[startup] Install cloudflared to enable tunnel: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/");
120
+ return;
121
+ }
122
+ try {
123
+ execSync('pgrep -f "cloudflared.*tunnel.*run"', { timeout: 3e3 });
124
+ console.log("[startup] cloudflared tunnel already running");
125
+ return;
126
+ } catch {
127
+ }
128
+ const subdomain = process.env.AGENTICMAIL_SUBDOMAIN || process.env.AGENTICMAIL_DOMAIN || "";
129
+ console.log(`[startup] Starting cloudflared tunnel${subdomain ? ` for ${subdomain}.agenticmail.io` : ""}...`);
130
+ const child = spawn("cloudflared", ["tunnel", "--no-autoupdate", "run", "--token", tunnelToken], {
131
+ detached: true,
132
+ stdio: "ignore"
133
+ });
134
+ child.unref();
135
+ console.log("[startup] cloudflared tunnel started (pid " + child.pid + ")");
136
+ } catch (e) {
137
+ console.warn("[startup] Could not auto-start cloudflared: " + e.message);
138
+ }
139
+ }
140
+ }
141
+ export {
142
+ runServe
143
+ };
@@ -0,0 +1,140 @@
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-JFWXTAWK.js");
97
+ const { createServer } = await import("./server-XQUE3FGT.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
+ const tunnelToken = process.env.CLOUDFLARED_TOKEN;
109
+ if (tunnelToken) {
110
+ try {
111
+ const { execSync, spawn } = await import("child_process");
112
+ try {
113
+ execSync("which cloudflared", { timeout: 3e3 });
114
+ } catch {
115
+ console.log("[startup] cloudflared not found \u2014 skipping tunnel auto-start");
116
+ console.log("[startup] Install cloudflared to enable tunnel: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/");
117
+ return;
118
+ }
119
+ try {
120
+ execSync('pgrep -f "cloudflared.*tunnel.*run"', { timeout: 3e3 });
121
+ console.log("[startup] cloudflared tunnel already running");
122
+ return;
123
+ } catch {
124
+ }
125
+ const subdomain = process.env.AGENTICMAIL_SUBDOMAIN || process.env.AGENTICMAIL_DOMAIN || "";
126
+ console.log(`[startup] Starting cloudflared tunnel${subdomain ? ` for ${subdomain}.agenticmail.io` : ""}...`);
127
+ const child = spawn("cloudflared", ["tunnel", "--no-autoupdate", "run", "--token", tunnelToken], {
128
+ detached: true,
129
+ stdio: "ignore"
130
+ });
131
+ child.unref();
132
+ console.log("[startup] cloudflared tunnel started (pid " + child.pid + ")");
133
+ } catch (e) {
134
+ console.warn("[startup] Could not auto-start cloudflared: " + e.message);
135
+ }
136
+ }
137
+ }
138
+ export {
139
+ runServe
140
+ };
@@ -0,0 +1,149 @@
1
+ import {
2
+ DomainLock
3
+ } from "./chunk-UPU23ZRG.js";
4
+ import "./chunk-KFQGP6VL.js";
5
+
6
+ // src/domain-lock/cli-verify.ts
7
+ function getFlag(args, name) {
8
+ const idx = args.indexOf(name);
9
+ if (idx !== -1 && args[idx + 1]) return args[idx + 1];
10
+ return void 0;
11
+ }
12
+ function hasFlag(args, name) {
13
+ return args.includes(name);
14
+ }
15
+ function detectDbType(url) {
16
+ const u = url.toLowerCase().trim();
17
+ if (u.startsWith("postgres") || u.startsWith("pg:")) return "postgres";
18
+ if (u.startsWith("mysql")) return "mysql";
19
+ if (u.startsWith("mongodb")) return "mongodb";
20
+ if (u.startsWith("libsql") || u.includes(".turso.io")) return "turso";
21
+ if (u.endsWith(".db") || u.endsWith(".sqlite") || u.endsWith(".sqlite3") || u.startsWith("file:")) return "sqlite";
22
+ return "postgres";
23
+ }
24
+ async function runVerifyDomain(args) {
25
+ const { default: chalk } = await import("chalk");
26
+ const { default: ora } = await import("ora");
27
+ console.log("");
28
+ console.log(chalk.bold(" AgenticMail Enterprise \u2014 Domain Verification"));
29
+ console.log("");
30
+ let domain = getFlag(args, "--domain");
31
+ let dnsChallenge;
32
+ let db = null;
33
+ let dbConnected = false;
34
+ const envDbUrl = process.env.DATABASE_URL;
35
+ if (envDbUrl) {
36
+ const dbType = detectDbType(envDbUrl);
37
+ const spinner = ora(`Connecting to database (${dbType})...`).start();
38
+ try {
39
+ const { createAdapter } = await import("./factory-JFWXTAWK.js");
40
+ db = await createAdapter({ type: dbType, connectionString: envDbUrl });
41
+ await db.migrate();
42
+ const settings = await db.getSettings();
43
+ if (!domain && settings?.domain) domain = settings.domain;
44
+ if (settings?.domainDnsChallenge) dnsChallenge = settings.domainDnsChallenge;
45
+ dbConnected = true;
46
+ spinner.succeed(`Connected to ${dbType} database` + (domain ? ` (domain: ${domain})` : ""));
47
+ } catch (err) {
48
+ spinner.warn(`Could not connect via DATABASE_URL: ${err.message}`);
49
+ db = null;
50
+ }
51
+ }
52
+ if (!dbConnected) {
53
+ const dbPath = getFlag(args, "--db");
54
+ const dbType = getFlag(args, "--db-type") || "sqlite";
55
+ if (dbPath) {
56
+ const spinner = ora(`Connecting to ${dbType} database...`).start();
57
+ try {
58
+ const { createAdapter } = await import("./factory-JFWXTAWK.js");
59
+ db = await createAdapter({ type: dbType, connectionString: dbPath });
60
+ await db.migrate();
61
+ const settings = await db.getSettings();
62
+ if (!domain && settings?.domain) domain = settings.domain;
63
+ if (settings?.domainDnsChallenge) dnsChallenge = settings.domainDnsChallenge;
64
+ dbConnected = true;
65
+ spinner.succeed(`Connected to ${dbType} database`);
66
+ } catch {
67
+ spinner.warn("Could not read local database");
68
+ }
69
+ }
70
+ }
71
+ if (!domain) {
72
+ const { default: inquirer } = await import("inquirer");
73
+ const answer = await inquirer.prompt([{
74
+ type: "input",
75
+ name: "domain",
76
+ message: "Domain to verify:",
77
+ suffix: chalk.dim(" (e.g. agents.yourcompany.com)"),
78
+ validate: (v) => v.includes(".") || "Enter a valid domain",
79
+ filter: (v) => v.trim().toLowerCase()
80
+ }]);
81
+ domain = answer.domain;
82
+ }
83
+ const lock = new DomainLock();
84
+ const maxAttempts = hasFlag(args, "--poll") ? 5 : 1;
85
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
86
+ const spinner = ora(
87
+ maxAttempts > 1 ? `Checking DNS verification (attempt ${attempt}/${maxAttempts})...` : "Checking DNS verification..."
88
+ ).start();
89
+ try {
90
+ const result = await lock.checkVerification(domain);
91
+ if (!result.success) {
92
+ spinner.fail("Verification check failed");
93
+ console.log("");
94
+ console.error(chalk.red(` ${result.error}`));
95
+ console.log("");
96
+ if (db) await db.disconnect();
97
+ process.exit(1);
98
+ }
99
+ if (result.verified) {
100
+ spinner.succeed("Domain verified!");
101
+ if (dbConnected && db) {
102
+ try {
103
+ await db.updateSettings({
104
+ domainStatus: "verified",
105
+ domainVerifiedAt: (/* @__PURE__ */ new Date()).toISOString()
106
+ });
107
+ console.log(chalk.dim(" Database updated with verified status."));
108
+ } catch {
109
+ }
110
+ }
111
+ console.log("");
112
+ console.log(chalk.green.bold(` \u2713 ${domain} is verified and protected.`));
113
+ console.log(chalk.dim(" Your deployment domain is locked. No other instance can claim it."));
114
+ console.log(chalk.dim(" The system now operates 100% offline \u2014 no outbound calls are made."));
115
+ console.log("");
116
+ if (db) await db.disconnect();
117
+ return;
118
+ }
119
+ } catch (err) {
120
+ spinner.warn(`Check failed: ${err.message}`);
121
+ }
122
+ if (attempt < maxAttempts) {
123
+ const waitSpinner = ora(`DNS record not found yet. Retrying in 10 seconds...`).start();
124
+ await new Promise((r) => setTimeout(r, 1e4));
125
+ waitSpinner.stop();
126
+ }
127
+ }
128
+ console.log("");
129
+ console.log(chalk.yellow(" DNS record not detected yet."));
130
+ console.log("");
131
+ console.log(chalk.bold(" Make sure this TXT record exists at your DNS provider:"));
132
+ console.log("");
133
+ console.log(` ${chalk.bold("Host:")} ${chalk.cyan(`_agenticmail-verify.${domain}`)}`);
134
+ console.log(` ${chalk.bold("Type:")} ${chalk.cyan("TXT")}`);
135
+ if (dnsChallenge) {
136
+ console.log(` ${chalk.bold("Value:")} ${chalk.cyan(dnsChallenge)}`);
137
+ } else {
138
+ console.log(` ${chalk.bold("Value:")} ${chalk.dim("(check your dashboard or setup output)")}`);
139
+ }
140
+ console.log("");
141
+ console.log(chalk.dim(" DNS propagation can take up to 48 hours."));
142
+ console.log(chalk.dim(" Run with --poll to retry automatically:"));
143
+ console.log(chalk.dim(` npx @agenticmail/enterprise verify-domain --domain ${domain} --poll`));
144
+ console.log("");
145
+ if (db) await db.disconnect();
146
+ }
147
+ export {
148
+ runVerifyDomain
149
+ };