@agenticmail/enterprise 0.5.324 → 0.5.326

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 (449) hide show
  1. package/dist/{agent-heartbeat-77N4OOQL.js → agent-heartbeat-ZFKA6GMI.js} +2 -2
  2. package/dist/{agent-tools-BNSTIK4P.js → agent-tools-R6RSBDJQ.js} +25 -25
  3. package/dist/{agenticmail-EDO5XOTP.js → agenticmail-QMWQNUY2.js} +1 -1
  4. package/dist/{browser-tool-JF3LNRGX.js → browser-tool-4KWE37RL.js} +4 -4
  5. package/dist/{chunk-JEGYVXYC.js → chunk-CQV7GGHT.js} +1 -1
  6. package/dist/{chunk-CQYLRIQ3.js → chunk-DWHJYAV6.js} +143 -26
  7. package/dist/{chunk-HKCKMCPY.js → chunk-G4YSECQ4.js} +2 -2
  8. package/dist/{chunk-DM7FTF7W.js → chunk-GNABVGDZ.js} +31 -32
  9. package/dist/{chunk-DMD24UFZ.js → chunk-HTT6LUPP.js} +19 -19
  10. package/dist/{chunk-3FMK32KQ.js → chunk-LHQP7QRX.js} +9 -9
  11. package/dist/{chunk-6C5PKREN.js → chunk-NOAQG5CY.js} +1 -1
  12. package/dist/{chunk-4EKXYIJF.js → chunk-PAHT4ABL.js} +4 -4
  13. package/dist/{chunk-JNMDD7JY.js → chunk-RHO7WRVJ.js} +5 -5
  14. package/dist/{chunk-BQM7MBPS.js → chunk-WYDVMFGJ.js} +5 -5
  15. package/dist/{chunk-TPLVQFXM.js → chunk-X2YL6KSY.js} +13 -13
  16. package/dist/{cli-agent-USMKX7WN.js → cli-agent-2NBPF3GN.js} +11 -11
  17. package/dist/{cli-recover-XEZ2SKPU.js → cli-recover-TTOR7CJR.js} +2 -2
  18. package/dist/{cli-serve-BDGOOOKQ.js → cli-serve-5VFU4GR4.js} +3 -3
  19. package/dist/{cli-verify-CZIITRED.js → cli-verify-WICBVLAM.js} +2 -2
  20. package/dist/cli.js +5 -5
  21. package/dist/{connection-manager-KAWEUWUR.js → connection-manager-Y7CCQK4X.js} +1 -1
  22. package/dist/dashboard/docs/cluster.html +285 -0
  23. package/dist/dashboard/pages/cluster.js +400 -69
  24. package/dist/{deployer-3YK4RPUL.js → deployer-7NG7LCJW.js} +1 -1
  25. package/dist/{factory-JFWXTAWK.js → factory-4V2W4BSV.js} +1 -1
  26. package/dist/index.js +9 -9
  27. package/dist/{integrations-TF4EBCJ7.js → integrations-V2WXFDIV.js} +13 -13
  28. package/dist/{local-6MLIZDKO.js → local-OXFH4V7E.js} +2 -2
  29. package/dist/{meeting-voice-intelligence-CJLR52YV.js → meeting-voice-intelligence-RZZCAD6G.js} +2 -2
  30. package/dist/{meetings-FJ453ENF.js → meetings-SQNTB6GD.js} +1 -1
  31. package/dist/{microsoft-2IIHDLJB.js → microsoft-2PDVV6HX.js} +3 -3
  32. package/dist/{postgres-WGUVC2S7.js → postgres-USXBPTHX.js} +2 -2
  33. package/dist/{pw-ai-IBEF6HBF.js → pw-ai-NK5GKBDG.js} +1 -1
  34. package/dist/{routes-XYR2RNEC.js → routes-T3CDAQTD.js} +4 -4
  35. package/dist/{runtime-6BULDBR3.js → runtime-X4BTVICL.js} +1 -1
  36. package/dist/{server-7NT4LMSQ.js → server-WQ6LLYGB.js} +5 -5
  37. package/dist/{setup-2JBXMUDS.js → setup-6DRKSOMH.js} +2 -2
  38. package/dist/{skills-FR7I5V7H.js → skills-EL4RTJKK.js} +1 -1
  39. package/logs/cloudflared-error.log +14 -0
  40. package/logs/enterprise-out.log +2 -0
  41. package/package.json +1 -1
  42. package/src/admin/routes.ts +1 -1
  43. package/src/agent-tools/tool-resolver.ts +1 -1
  44. package/src/agent-tools/tools/agenticmail.ts +2 -2
  45. package/src/agent-tools/tools/browser.ts +1 -1
  46. package/src/agent-tools/tools/enterprise-code-sandbox.ts +1 -1
  47. package/src/agent-tools/tools/enterprise-diff.ts +1 -1
  48. package/src/agent-tools/tools/enterprise-http.ts +1 -3
  49. package/src/agent-tools/tools/enterprise-security-scan.ts +1 -1
  50. package/src/agent-tools/tools/google/forms.ts +2 -2
  51. package/src/agent-tools/tools/google/gmail.ts +1 -1
  52. package/src/agent-tools/tools/google/maps.ts +2 -2
  53. package/src/agent-tools/tools/google/meeting-voice.ts +1 -1
  54. package/src/agent-tools/tools/google/meetings.ts +1 -1
  55. package/src/agent-tools/tools/google/slides.ts +2 -2
  56. package/src/agent-tools/tools/grep.ts +1 -1
  57. package/src/agent-tools/tools/knowledge-search.ts +1 -1
  58. package/src/agent-tools/tools/local/coding.ts +5 -5
  59. package/src/agent-tools/tools/microsoft/excel-vba.ts +1 -1
  60. package/src/agent-tools/tools/microsoft/excel.ts +1 -1
  61. package/src/agent-tools/tools/microsoft/powerpoint.ts +1 -1
  62. package/src/agent-tools/tools/visual-memory/index.ts +11 -11
  63. package/src/agent-tools/tools/visual-memory/similarity.ts +2 -2
  64. package/src/agent-tools/tools/visual-memory/storage.ts +1 -1
  65. package/src/agenticmail/providers/imap.ts +2 -2
  66. package/src/browser/enterprise-compat.ts +1 -1
  67. package/src/cli-agent.ts +3 -3
  68. package/src/cli-serve.ts +1 -1
  69. package/src/dashboard/docs/cluster.html +285 -0
  70. package/src/dashboard/pages/cluster.js +400 -69
  71. package/src/database-access/connection-manager.ts +6 -6
  72. package/src/database-access/routes.ts +0 -1
  73. package/src/db/dynamodb.ts +1 -1
  74. package/src/db/postgres.ts +2 -2
  75. package/src/deploy/fly.ts +4 -4
  76. package/src/deploy/managed.ts +0 -1
  77. package/src/engine/agent-config.ts +1 -1
  78. package/src/engine/agent-heartbeat.ts +1 -1
  79. package/src/engine/agent-hierarchy.ts +1 -1
  80. package/src/engine/agent-memory.ts +1 -1
  81. package/src/engine/agent-routes.ts +2 -2
  82. package/src/engine/chat-poller.ts +1 -1
  83. package/src/engine/cluster.ts +14 -1
  84. package/src/engine/community-registry.ts +2 -2
  85. package/src/engine/db-adapter.ts +0 -1
  86. package/src/engine/deployer.ts +8 -8
  87. package/src/engine/email-poller.ts +1 -1
  88. package/src/engine/knowledge-contribution.ts +1 -1
  89. package/src/engine/knowledge-import/import-manager.ts +2 -3
  90. package/src/engine/knowledge-import/processors/extract-github.ts +1 -1
  91. package/src/engine/knowledge-import/processors/extract-sharepoint.ts +1 -1
  92. package/src/engine/knowledge-import/processors/validate.ts +1 -1
  93. package/src/engine/lifecycle.ts +1 -1
  94. package/src/engine/meeting-monitor.ts +2 -2
  95. package/src/engine/meeting-voice-intelligence.ts +3 -3
  96. package/src/engine/messaging-poller.ts +2 -2
  97. package/src/engine/org-integration-routes.ts +2 -2
  98. package/src/engine/org-integrations.ts +1 -1
  99. package/src/engine/routes.ts +119 -1
  100. package/src/engine/skills.ts +1 -1
  101. package/src/engine/tool-catalog.ts +1 -1
  102. package/src/engine/vault-routes.ts +1 -1
  103. package/src/engine/vault.ts +1 -1
  104. package/src/mcp/adapters/adp.adapter.ts +1 -1
  105. package/src/mcp/adapters/auth0.adapter.ts +1 -1
  106. package/src/mcp/adapters/clickup.adapter.ts +1 -1
  107. package/src/mcp/adapters/close.adapter.ts +1 -1
  108. package/src/mcp/adapters/firebase.adapter.ts +1 -1
  109. package/src/mcp/adapters/google-ads.adapter.ts +1 -1
  110. package/src/mcp/adapters/kubernetes.adapter.ts +1 -1
  111. package/src/mcp/adapters/mixpanel.adapter.ts +1 -1
  112. package/src/mcp/adapters/recurly.adapter.ts +1 -1
  113. package/src/mcp/adapters/sap.adapter.ts +2 -2
  114. package/src/mcp/adapters/shortcut.adapter.ts +1 -1
  115. package/src/mcp/adapters/snowflake.adapter.ts +1 -1
  116. package/src/mcp/adapters/stripe.adapter.ts +1 -1
  117. package/src/mcp/adapters/supabase.adapter.ts +1 -1
  118. package/src/mcp/adapters/zuora.adapter.ts +1 -1
  119. package/src/middleware/request-limits.ts +1 -1
  120. package/src/runtime/agent-loop.ts +3 -3
  121. package/src/runtime/compaction.ts +2 -2
  122. package/src/runtime/followup.ts +1 -1
  123. package/src/runtime/hooks.ts +3 -3
  124. package/src/runtime/index.ts +5 -6
  125. package/src/runtime/llm-client.ts +1 -1
  126. package/src/runtime/subagent.ts +0 -1
  127. package/src/runtime/types.ts +2 -0
  128. package/src/security/brute-force.ts +1 -1
  129. package/src/security/csp.ts +1 -1
  130. package/src/security/index.ts +3 -3
  131. package/src/security/input-sanitizer.ts +1 -1
  132. package/src/security/threat-logger.ts +2 -2
  133. package/src/server.ts +2 -2
  134. package/src/setup/database.ts +1 -1
  135. package/src/setup/index.ts +1 -2
  136. package/src/setup/provision.ts +1 -1
  137. package/dist/_seed-data-FQR5PY2W.js +0 -4554
  138. package/dist/agent-heartbeat-3FWNHZFX.js +0 -510
  139. package/dist/agent-heartbeat-4RWHZR7H.js +0 -510
  140. package/dist/agent-heartbeat-6ZGB5ILY.js +0 -510
  141. package/dist/agent-heartbeat-BBINFNL4.js +0 -510
  142. package/dist/agent-heartbeat-BIVHLKFM.js +0 -510
  143. package/dist/agent-heartbeat-HGVIAHS5.js +0 -510
  144. package/dist/agent-heartbeat-HRKVFK2T.js +0 -510
  145. package/dist/agent-heartbeat-JC5GWVXD.js +0 -510
  146. package/dist/agent-heartbeat-K6A4HMHB.js +0 -510
  147. package/dist/agent-heartbeat-LCDXWFVB.js +0 -510
  148. package/dist/agent-heartbeat-P7HZCZAQ.js +0 -510
  149. package/dist/agent-heartbeat-PUIRSNIO.js +0 -510
  150. package/dist/agent-heartbeat-SN5ILQ6Y.js +0 -510
  151. package/dist/agent-heartbeat-TW5YTDYC.js +0 -510
  152. package/dist/agent-heartbeat-YCSWP54H.js +0 -510
  153. package/dist/agent-heartbeat-Z2QQXROL.js +0 -510
  154. package/dist/agent-tools-3W7XLUYA.js +0 -13949
  155. package/dist/agent-tools-54VZGT6L.js +0 -9
  156. package/dist/agent-tools-AYYDPO27.js +0 -13949
  157. package/dist/agent-tools-F2X47FKF.js +0 -13949
  158. package/dist/agent-tools-O6W3QAZL.js +0 -13949
  159. package/dist/agent-tools-OAWVZBMW.js +0 -9
  160. package/dist/agent-tools-QCCU74PN.js +0 -13949
  161. package/dist/agent-tools-QGE26U6R.js +0 -9
  162. package/dist/chunk-2LHUARN6.js +0 -4929
  163. package/dist/chunk-2WVCNCYC.js +0 -5087
  164. package/dist/chunk-3FM6YQUK.js +0 -5087
  165. package/dist/chunk-46GOWZT4.js +0 -5087
  166. package/dist/chunk-5KYJAUZV.js +0 -1519
  167. package/dist/chunk-6ZMLNEHB.js +0 -1519
  168. package/dist/chunk-7HBGXW7Z.js +0 -4929
  169. package/dist/chunk-7UCKD25B.js +0 -551
  170. package/dist/chunk-BDCFOP7O.js +0 -537
  171. package/dist/chunk-BPZQT5N5.js +0 -25652
  172. package/dist/chunk-C52OQNNY.js +0 -5087
  173. package/dist/chunk-C7HGQF4Y.js +0 -25652
  174. package/dist/chunk-CAHNZGGK.js +0 -25656
  175. package/dist/chunk-CK7R6UHE.js +0 -4945
  176. package/dist/chunk-D36RPWB7.js +0 -25652
  177. package/dist/chunk-DJK2UPFH.js +0 -4891
  178. package/dist/chunk-DXZGPUAF.js +0 -5087
  179. package/dist/chunk-F46WB5IL.js +0 -5087
  180. package/dist/chunk-F5QG5SQH.js +0 -5087
  181. package/dist/chunk-GYB2WHMN.js +0 -5101
  182. package/dist/chunk-H7GP733U.js +0 -5087
  183. package/dist/chunk-HHBXWB5U.js +0 -25640
  184. package/dist/chunk-HS5YWSGM.js +0 -3206
  185. package/dist/chunk-IMXS4N6W.js +0 -1519
  186. package/dist/chunk-JTV5LA47.js +0 -1519
  187. package/dist/chunk-KN3T3CTD.js +0 -4929
  188. package/dist/chunk-KV6G7NZX.js +0 -1519
  189. package/dist/chunk-M6ZIC5H3.js +0 -1370
  190. package/dist/chunk-MU5MEBIK.js +0 -1519
  191. package/dist/chunk-NLT5MC7X.js +0 -465
  192. package/dist/chunk-NVLYIM4J.js +0 -4945
  193. package/dist/chunk-NZY2BIZH.js +0 -4891
  194. package/dist/chunk-O42L6G67.js +0 -1519
  195. package/dist/chunk-OCNERGGM.js +0 -4891
  196. package/dist/chunk-OJSNHONE.js +0 -1519
  197. package/dist/chunk-OWTLNV4Q.js +0 -25623
  198. package/dist/chunk-PCNYEP6T.js +0 -4891
  199. package/dist/chunk-PI4AQ4Z6.js +0 -25652
  200. package/dist/chunk-PN3EGTCA.js +0 -194
  201. package/dist/chunk-PWWV2U5P.js +0 -195
  202. package/dist/chunk-Q37UKNRC.js +0 -1519
  203. package/dist/chunk-QXTC6J7H.js +0 -5087
  204. package/dist/chunk-RF2LGX3E.js +0 -1519
  205. package/dist/chunk-RH7KPWRQ.js +0 -465
  206. package/dist/chunk-RKERL5LZ.js +0 -4925
  207. package/dist/chunk-RVBK2IOX.js +0 -25652
  208. package/dist/chunk-SAKODCZ5.js +0 -4891
  209. package/dist/chunk-SALGFC5L.js +0 -4945
  210. package/dist/chunk-STGWZ2MS.js +0 -1519
  211. package/dist/chunk-SVSLIQYN.js +0 -1519
  212. package/dist/chunk-UY3ZVQDP.js +0 -25652
  213. package/dist/chunk-V6OSD62M.js +0 -5087
  214. package/dist/chunk-VP6YAHX4.js +0 -1519
  215. package/dist/chunk-WDYJOEAI.js +0 -5087
  216. package/dist/chunk-WEAFQNOS.js +0 -195
  217. package/dist/chunk-XKUSAZGP.js +0 -5087
  218. package/dist/chunk-YCWOCIPH.js +0 -5101
  219. package/dist/chunk-ZGE3XAXY.js +0 -1519
  220. package/dist/cli-agent-33GWIF2D.js +0 -2300
  221. package/dist/cli-agent-4XK6LVQQ.js +0 -2357
  222. package/dist/cli-agent-64EOV3ST.js +0 -2300
  223. package/dist/cli-agent-67WP6KKO.js +0 -2300
  224. package/dist/cli-agent-7RW5Y7C4.js +0 -2294
  225. package/dist/cli-agent-7TB2BWS6.js +0 -2370
  226. package/dist/cli-agent-AKXFFST2.js +0 -2370
  227. package/dist/cli-agent-C3YSECO4.js +0 -2344
  228. package/dist/cli-agent-DZTKLITB.js +0 -2357
  229. package/dist/cli-agent-FNMDJN7T.js +0 -2357
  230. package/dist/cli-agent-FOF7PFEP.js +0 -2357
  231. package/dist/cli-agent-FXZ6DJKP.js +0 -2357
  232. package/dist/cli-agent-H74M2ZYN.js +0 -2357
  233. package/dist/cli-agent-HG4Y657I.js +0 -2300
  234. package/dist/cli-agent-HORWVPHB.js +0 -2370
  235. package/dist/cli-agent-HSZT6SKF.js +0 -2423
  236. package/dist/cli-agent-ION2W5JF.js +0 -2441
  237. package/dist/cli-agent-JLUQ4ZU6.js +0 -2424
  238. package/dist/cli-agent-KBPWY3CB.js +0 -2302
  239. package/dist/cli-agent-MVCDH4HV.js +0 -2370
  240. package/dist/cli-agent-NZXOEPJ2.js +0 -2357
  241. package/dist/cli-agent-OO6H57UQ.js +0 -2300
  242. package/dist/cli-agent-PADN3QRC.js +0 -2357
  243. package/dist/cli-agent-QAYEX3BE.js +0 -2441
  244. package/dist/cli-agent-QT64DT5J.js +0 -2370
  245. package/dist/cli-agent-TCTRKCHN.js +0 -2300
  246. package/dist/cli-agent-TFL2M6UK.js +0 -2424
  247. package/dist/cli-agent-TSOJG7EX.js +0 -2357
  248. package/dist/cli-agent-UIKXATTD.js +0 -2357
  249. package/dist/cli-agent-UJN6FYTO.js +0 -2370
  250. package/dist/cli-agent-VIQAYVY4.js +0 -2357
  251. package/dist/cli-agent-WNWFVOFM.js +0 -2370
  252. package/dist/cli-agent-XBQX67VJ.js +0 -2423
  253. package/dist/cli-agent-ZLSC6FF4.js +0 -2357
  254. package/dist/cli-agent-ZSHUPBBN.js +0 -2357
  255. package/dist/cli-recover-T32NABFA.js +0 -487
  256. package/dist/cli-serve-2IL5DTEY.js +0 -153
  257. package/dist/cli-serve-3NGBX5ER.js +0 -140
  258. package/dist/cli-serve-47N5UKKW.js +0 -153
  259. package/dist/cli-serve-4RS4UDHC.js +0 -140
  260. package/dist/cli-serve-4XGZFUV2.js +0 -140
  261. package/dist/cli-serve-53FVANQK.js +0 -260
  262. package/dist/cli-serve-57225XWV.js +0 -140
  263. package/dist/cli-serve-63BDPSOP.js +0 -140
  264. package/dist/cli-serve-657NRUOX.js +0 -140
  265. package/dist/cli-serve-6ER7QMLR.js +0 -140
  266. package/dist/cli-serve-6OT3UEAN.js +0 -140
  267. package/dist/cli-serve-7JQ4FVUQ.js +0 -260
  268. package/dist/cli-serve-7L6EY5UH.js +0 -153
  269. package/dist/cli-serve-BFNIW2LF.js +0 -153
  270. package/dist/cli-serve-C7MN6U5Q.js +0 -153
  271. package/dist/cli-serve-CQFI3LMK.js +0 -140
  272. package/dist/cli-serve-CR3OY3IM.js +0 -153
  273. package/dist/cli-serve-DAJFRWQ7.js +0 -153
  274. package/dist/cli-serve-DTQLN5UI.js +0 -140
  275. package/dist/cli-serve-EQS2SGT3.js +0 -140
  276. package/dist/cli-serve-FW6FHFW4.js +0 -153
  277. package/dist/cli-serve-GEEOQS77.js +0 -153
  278. package/dist/cli-serve-H562I3ZK.js +0 -153
  279. package/dist/cli-serve-HDQZF4C4.js +0 -153
  280. package/dist/cli-serve-KBJNXWYJ.js +0 -140
  281. package/dist/cli-serve-LICAOMEB.js +0 -140
  282. package/dist/cli-serve-LLGYLWFS.js +0 -153
  283. package/dist/cli-serve-LMZKQ5GX.js +0 -140
  284. package/dist/cli-serve-LNTT73P2.js +0 -140
  285. package/dist/cli-serve-MQKBUZ7X.js +0 -140
  286. package/dist/cli-serve-N3OISDNB.js +0 -153
  287. package/dist/cli-serve-NBFT7B42.js +0 -140
  288. package/dist/cli-serve-RTWO3AWY.js +0 -140
  289. package/dist/cli-serve-SIHTSW5P.js +0 -140
  290. package/dist/cli-serve-SP6TEURE.js +0 -140
  291. package/dist/cli-serve-TDKZA6I5.js +0 -140
  292. package/dist/cli-serve-TF5ZVVXF.js +0 -140
  293. package/dist/cli-serve-TIZ27EVR.js +0 -153
  294. package/dist/cli-serve-TUNI2RCN.js +0 -153
  295. package/dist/cli-serve-WCU66CHX.js +0 -140
  296. package/dist/cli-serve-WNOZMAWD.js +0 -153
  297. package/dist/cli-serve-YCCKRRUY.js +0 -140
  298. package/dist/cli-serve-ZD5V7I6G.js +0 -140
  299. package/dist/cli-validate-6XDDLVVQ.js +0 -150
  300. package/dist/cli-verify-I4WGRQNT.js +0 -149
  301. package/dist/connection-manager-4ZA4XAFA.js +0 -9
  302. package/dist/db-adapter-IK2EDK2N.js +0 -7
  303. package/dist/db-adapter-IRHOUMVC.js +0 -7
  304. package/dist/dependency-manager-G6D2XXNY.js +0 -11
  305. package/dist/dependency-manager-OCUKF72T.js +0 -543
  306. package/dist/dependency-manager-YULUXN34.js +0 -511
  307. package/dist/factory-MQASIPEB.js +0 -11
  308. package/dist/google-W5AYGNUJ.js +0 -33
  309. package/dist/integrations-VWANOHQ4.js +0 -43830
  310. package/dist/local-O2FN57UN.js +0 -1128
  311. package/dist/local-S7SDOQHN.js +0 -1128
  312. package/dist/microsoft-HPLA5ZL5.js +0 -2414
  313. package/dist/microsoft-UFLZBEAC.js +0 -1619
  314. package/dist/microsoft-VREAZ7M2.js +0 -3955
  315. package/dist/microsoft-YUT6EIGP.js +0 -3400
  316. package/dist/postgres-BOTHOPDW.js +0 -875
  317. package/dist/routes-3MMLQTB6.js +0 -90
  318. package/dist/routes-4ZUIJ4HE.js +0 -90
  319. package/dist/routes-5MXHKKH4.js +0 -90
  320. package/dist/routes-64NJFK3B.js +0 -90
  321. package/dist/routes-6AKQ2LBV.js +0 -90
  322. package/dist/routes-CRRBUDO4.js +0 -90
  323. package/dist/routes-D7SMYOLT.js +0 -90
  324. package/dist/routes-DIAF3MC3.js +0 -90
  325. package/dist/routes-KMUNU6CY.js +0 -90
  326. package/dist/routes-LRRLXIZR.js +0 -90
  327. package/dist/routes-N647AJYG.js +0 -90
  328. package/dist/routes-SSSELAAR.js +0 -90
  329. package/dist/routes-STERVGKJ.js +0 -90
  330. package/dist/routes-TZMPYLHJ.js +0 -90
  331. package/dist/routes-XNK2MAVO.js +0 -90
  332. package/dist/routes-ZEZZACZP.js +0 -90
  333. package/dist/runtime-4UVCTFNQ.js +0 -45
  334. package/dist/runtime-5EQN4GFM.js +0 -45
  335. package/dist/runtime-5LP7PUD4.js +0 -45
  336. package/dist/runtime-6YEENDN3.js +0 -45
  337. package/dist/runtime-7LQFRG3B.js +0 -45
  338. package/dist/runtime-AMXJU2MB.js +0 -45
  339. package/dist/runtime-D6WSE7FG.js +0 -45
  340. package/dist/runtime-EYVN7NFJ.js +0 -45
  341. package/dist/runtime-F6RPWQVW.js +0 -45
  342. package/dist/runtime-FYMJURFC.js +0 -45
  343. package/dist/runtime-GGF4P55M.js +0 -45
  344. package/dist/runtime-H3SAMWWF.js +0 -45
  345. package/dist/runtime-H7T4I7I7.js +0 -45
  346. package/dist/runtime-HTIM7GZR.js +0 -45
  347. package/dist/runtime-JRNBL4O4.js +0 -45
  348. package/dist/runtime-K4C7NQLW.js +0 -45
  349. package/dist/runtime-MWWZCPC2.js +0 -45
  350. package/dist/runtime-N7CM2DYA.js +0 -45
  351. package/dist/runtime-OM2NIBMI.js +0 -45
  352. package/dist/runtime-OVGSOTAH.js +0 -45
  353. package/dist/runtime-QQ6LAY4U.js +0 -45
  354. package/dist/runtime-QWPVD7CY.js +0 -45
  355. package/dist/runtime-SX3B5MG3.js +0 -45
  356. package/dist/runtime-YLIIPTE4.js +0 -45
  357. package/dist/runtime-YU6P22CG.js +0 -45
  358. package/dist/runtime-ZOC337DD.js +0 -45
  359. package/dist/server-3AVWBRIF.js +0 -28
  360. package/dist/server-5BKJI5OW.js +0 -28
  361. package/dist/server-6NDO2S52.js +0 -28
  362. package/dist/server-7TD3M2BW.js +0 -28
  363. package/dist/server-AMCSXINC.js +0 -28
  364. package/dist/server-BEJ6RAGL.js +0 -28
  365. package/dist/server-BFPYDHBG.js +0 -28
  366. package/dist/server-BKEWXGVX.js +0 -28
  367. package/dist/server-BMEJZGFG.js +0 -28
  368. package/dist/server-CU6LVQS4.js +0 -28
  369. package/dist/server-DFR7FI3Q.js +0 -28
  370. package/dist/server-DFYGH2CV.js +0 -28
  371. package/dist/server-DURRN3GJ.js +0 -28
  372. package/dist/server-EELWOC3X.js +0 -28
  373. package/dist/server-EN5E2OWQ.js +0 -28
  374. package/dist/server-EXZC3OJO.js +0 -28
  375. package/dist/server-GW2HYJYI.js +0 -28
  376. package/dist/server-J25NCRWJ.js +0 -28
  377. package/dist/server-JDGNOTFV.js +0 -28
  378. package/dist/server-KA6U3YNP.js +0 -28
  379. package/dist/server-L52A2ME4.js +0 -28
  380. package/dist/server-NE5HD5DJ.js +0 -28
  381. package/dist/server-NLQAXPOG.js +0 -28
  382. package/dist/server-NQOT7W77.js +0 -28
  383. package/dist/server-OHHAA34U.js +0 -28
  384. package/dist/server-PWE5PQTR.js +0 -28
  385. package/dist/server-Q2Q32H2B.js +0 -28
  386. package/dist/server-Q77ME7TL.js +0 -28
  387. package/dist/server-QDKO6OVO.js +0 -28
  388. package/dist/server-RR6QJIXM.js +0 -28
  389. package/dist/server-T3R6BO6A.js +0 -28
  390. package/dist/server-TRIBAHDV.js +0 -28
  391. package/dist/server-TXV3ZVVR.js +0 -28
  392. package/dist/server-VHSFJP3I.js +0 -28
  393. package/dist/server-VOJF2XGU.js +0 -28
  394. package/dist/server-W76YHPEC.js +0 -28
  395. package/dist/server-WLLH4WST.js +0 -28
  396. package/dist/server-WTUJ2O3F.js +0 -28
  397. package/dist/server-X4CJTHHF.js +0 -28
  398. package/dist/server-XK3ILCJC.js +0 -28
  399. package/dist/server-ZRD3NDJE.js +0 -28
  400. package/dist/setup-2JYXGTW6.js +0 -20
  401. package/dist/setup-3XOSZEW5.js +0 -20
  402. package/dist/setup-44VBAO4J.js +0 -20
  403. package/dist/setup-4OA7QNJW.js +0 -20
  404. package/dist/setup-4ONNQBWB.js +0 -20
  405. package/dist/setup-4OSBXSCL.js +0 -20
  406. package/dist/setup-4QFGRBLZ.js +0 -20
  407. package/dist/setup-52US54Z4.js +0 -20
  408. package/dist/setup-5CY3CKKT.js +0 -20
  409. package/dist/setup-6766SGAR.js +0 -20
  410. package/dist/setup-6NUSB4XO.js +0 -20
  411. package/dist/setup-7FZJEOD4.js +0 -20
  412. package/dist/setup-7LYYXBUL.js +0 -20
  413. package/dist/setup-ADSKKBGV.js +0 -20
  414. package/dist/setup-AMV2WKVH.js +0 -20
  415. package/dist/setup-AYY24DKM.js +0 -20
  416. package/dist/setup-B34N4HPU.js +0 -20
  417. package/dist/setup-CEF4QY4L.js +0 -20
  418. package/dist/setup-E2YLC2EY.js +0 -20
  419. package/dist/setup-ER6NXTY5.js +0 -20
  420. package/dist/setup-FIOAQJ6C.js +0 -20
  421. package/dist/setup-G76S7X44.js +0 -20
  422. package/dist/setup-H2AGCBW5.js +0 -20
  423. package/dist/setup-H4JZUHH5.js +0 -20
  424. package/dist/setup-ICOZRKCX.js +0 -20
  425. package/dist/setup-JFTJH7UF.js +0 -20
  426. package/dist/setup-JJHOT2ZU.js +0 -20
  427. package/dist/setup-KEAM2BCL.js +0 -20
  428. package/dist/setup-LW4MLU2N.js +0 -20
  429. package/dist/setup-NHAZABW4.js +0 -20
  430. package/dist/setup-PRFNI6YW.js +0 -20
  431. package/dist/setup-RAHBMYHE.js +0 -20
  432. package/dist/setup-T6KYFR7O.js +0 -20
  433. package/dist/setup-TGM6L362.js +0 -20
  434. package/dist/setup-TNANAH7C.js +0 -20
  435. package/dist/setup-TXPR5UQX.js +0 -20
  436. package/dist/setup-UJSNSCLM.js +0 -20
  437. package/dist/setup-XCJMELVU.js +0 -20
  438. package/dist/setup-XIYEIFVK.js +0 -20
  439. package/dist/setup-XP2VGBEU.js +0 -20
  440. package/dist/setup-Z4PZSHBI.js +0 -20
  441. package/dist/skills-HCVBA6PK.js +0 -16
  442. package/dist/skills-HFSW74KZ.js +0 -16
  443. package/dist/system-prompts-6OUTAMH6.js +0 -41
  444. package/dist/task-queue-YP2I54IA.js +0 -9
  445. package/dist/transport-encryption-F2NQYACT.js +0 -25
  446. package/seed-data.mjs +0 -455
  447. package/src/agent-tools/tools/integrations/_seed-data.json +0 -4548
  448. package/src/agent-tools/tools/integrations/_seed-data.ts +0 -4563
  449. package/src/engine/NOTE.MD +0 -52
@@ -1,1519 +0,0 @@
1
- import {
2
- getSupportedDatabases
3
- } from "./chunk-4EKXYIJF.js";
4
-
5
- // src/setup/index.ts
6
- import { execSync as execSync2 } from "child_process";
7
- import { createRequire } from "module";
8
- import { join as join2 } from "path";
9
-
10
- // src/setup/company.ts
11
- function toSlug(name) {
12
- return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 63);
13
- }
14
- function generateAlternatives(companyName) {
15
- const base = toSlug(companyName);
16
- const words = companyName.trim().split(/\s+/).map((w) => w.toLowerCase().replace(/[^a-z0-9]/g, "")).filter(Boolean);
17
- const suggestions = /* @__PURE__ */ new Set();
18
- suggestions.add(base);
19
- if (words.length >= 2) {
20
- const initials = words.map((w) => w[0]).join("");
21
- if (initials.length >= 2) suggestions.add(initials);
22
- }
23
- if (words[0] && words[0] !== base) {
24
- suggestions.add(words[0]);
25
- }
26
- if (words.length >= 3) {
27
- suggestions.add(`${words[0]}-${words[words.length - 1]}`);
28
- }
29
- suggestions.add(`team-${base}`);
30
- suggestions.add(`app-${base}`);
31
- suggestions.add(`mail-${words[0] || base}`);
32
- suggestions.add(`ai-${words[0] || base}`);
33
- suggestions.add(`${words[0] || base}-hq`);
34
- suggestions.delete(base);
35
- return [...suggestions].map((s) => s.slice(0, 63)).slice(0, 5);
36
- }
37
- function validateSubdomain(v) {
38
- const s = v.trim();
39
- if (!s) return "Subdomain is required";
40
- if (s.length < 2) return "Subdomain must be at least 2 characters";
41
- if (s.length > 63) return "Subdomain must be 63 characters or fewer";
42
- if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(s)) {
43
- return "Subdomain must be lowercase letters, numbers, and hyphens (cannot start or end with a hyphen)";
44
- }
45
- return true;
46
- }
47
- async function promptCompanyInfo(inquirer, chalk) {
48
- console.log(chalk.bold.cyan(" Step 1 of 5: Company Info"));
49
- console.log(chalk.dim(" Tell us about your organization.\n"));
50
- const { companyName, adminEmail, adminPassword } = await inquirer.prompt([
51
- {
52
- type: "input",
53
- name: "companyName",
54
- message: "Company name:",
55
- validate: (v) => {
56
- if (!v.trim()) return "Company name is required";
57
- if (v.length > 100) return "Company name must be under 100 characters";
58
- return true;
59
- }
60
- },
61
- {
62
- type: "input",
63
- name: "adminEmail",
64
- message: "Admin email:",
65
- validate: (v) => {
66
- if (!v.includes("@") || !v.includes(".")) return "Enter a valid email address";
67
- return true;
68
- }
69
- },
70
- {
71
- type: "password",
72
- name: "adminPassword",
73
- message: "Admin password:",
74
- mask: "*",
75
- validate: (v) => {
76
- if (v.length < 8) return "Password must be at least 8 characters";
77
- if (!/[A-Z]/.test(v) && !/[0-9]/.test(v)) {
78
- return "Password should contain at least one uppercase letter or number";
79
- }
80
- return true;
81
- }
82
- }
83
- ]);
84
- const suggested = toSlug(companyName);
85
- const alternatives = generateAlternatives(companyName);
86
- console.log("");
87
- console.log(chalk.bold(" Subdomain"));
88
- console.log(chalk.dim(" Used for your dashboard URL and internal routing.\n"));
89
- const choices = [
90
- { name: `${suggested} ${chalk.dim("(recommended)")}`, value: suggested },
91
- ...alternatives.map((alt) => ({ name: alt, value: alt })),
92
- new inquirer.Separator(),
93
- { name: `${chalk.italic("Enter my own...")}`, value: "__custom__" },
94
- { name: `${chalk.italic("Generate more suggestions")}`, value: "__regenerate__" }
95
- ];
96
- let subdomain = suggested;
97
- let choosing = true;
98
- while (choosing) {
99
- const { subdomainChoice } = await inquirer.prompt([{
100
- type: "list",
101
- name: "subdomainChoice",
102
- message: "Choose a subdomain:",
103
- choices
104
- }]);
105
- if (subdomainChoice === "__custom__") {
106
- const { custom } = await inquirer.prompt([{
107
- type: "input",
108
- name: "custom",
109
- message: "Custom subdomain:",
110
- suffix: chalk.dim(" (lowercase, letters/numbers/hyphens)"),
111
- validate: validateSubdomain,
112
- filter: (v) => v.trim().toLowerCase()
113
- }]);
114
- subdomain = custom;
115
- choosing = false;
116
- } else if (subdomainChoice === "__regenerate__") {
117
- const base = toSlug(companyName);
118
- const words = companyName.trim().split(/\s+/).map((w2) => w2.toLowerCase().replace(/[^a-z0-9]/g, "")).filter(Boolean);
119
- const w = words[0] || base;
120
- const rand = () => Math.random().toString(36).slice(2, 5);
121
- const fresh = [
122
- `${w}-${rand()}`,
123
- `${base}-${rand()}`,
124
- `${w}-agents`,
125
- `${w}-mail`,
126
- `${w}-platform`
127
- ];
128
- choices.splice(
129
- 1,
130
- alternatives.length,
131
- ...fresh.map((alt) => ({ name: alt, value: alt }))
132
- );
133
- } else {
134
- subdomain = subdomainChoice;
135
- choosing = false;
136
- }
137
- }
138
- console.log(chalk.dim(` Your subdomain: ${chalk.white(subdomain)}
139
- `));
140
- return { companyName, adminEmail, adminPassword, subdomain };
141
- }
142
-
143
- // src/setup/database.ts
144
- var CONNECTION_HINTS = {
145
- postgres: "postgresql://user:pass@host:5432/dbname",
146
- mysql: "mysql://user:pass@host:3306/dbname",
147
- mongodb: "mongodb+srv://user:pass@cluster.mongodb.net/dbname",
148
- supabase: "postgresql://postgres:pass@db.xxxx.supabase.co:5432/postgres",
149
- neon: "postgresql://user:pass@ep-xxx.us-east-1.aws.neon.tech/dbname?sslmode=require",
150
- planetscale: 'mysql://user:pass@aws.connect.psdb.cloud/dbname?ssl={"rejectUnauthorized":true}',
151
- cockroachdb: "postgresql://user:pass@cluster.cockroachlabs.cloud:26257/dbname?sslmode=verify-full"
152
- };
153
- async function promptDatabase(inquirer, chalk) {
154
- console.log("");
155
- console.log(chalk.bold.cyan(" Step 2 of 4: Database"));
156
- console.log(chalk.dim(" Where should your data live?\n"));
157
- const databases = getSupportedDatabases();
158
- const supabaseIdx = databases.findIndex((d) => d.type === "supabase");
159
- const choices = databases.map((d, i) => ({
160
- name: d.type === "supabase" ? `${d.label} ${chalk.green("\u2190 recommended (free tier)")} ${chalk.dim("(cloud)")}` : `${d.label} ${chalk.dim(`(${d.group})`)}`,
161
- value: d.type
162
- }));
163
- if (supabaseIdx > 0) {
164
- const [sb] = choices.splice(supabaseIdx, 1);
165
- choices.unshift(sb);
166
- }
167
- const { dbType } = await inquirer.prompt([
168
- {
169
- type: "list",
170
- name: "dbType",
171
- message: "Database backend:",
172
- choices
173
- }
174
- ]);
175
- if (dbType === "supabase") {
176
- console.log("");
177
- console.log(chalk.bold(" Supabase \u2014 Free PostgreSQL Database"));
178
- console.log("");
179
- console.log(chalk.dim(" If you don't have a Supabase account yet:"));
180
- console.log("");
181
- console.log(` 1. Go to ${chalk.cyan.underline("https://supabase.com/dashboard")}`);
182
- console.log(` 2. Click ${chalk.bold('"Start your project"')} \u2014 sign up with GitHub or email`);
183
- console.log(` 3. Create a new project (any name, choose a strong password)`);
184
- console.log(` 4. Go to ${chalk.bold("Settings \u2192 Database \u2192 Connection string")}`);
185
- console.log(` 5. Select ${chalk.bold('"URI"')} and copy the connection string`);
186
- console.log(` 6. Replace ${chalk.yellow("[YOUR-PASSWORD]")} with your project password`);
187
- console.log("");
188
- console.log(chalk.dim(" Free tier includes: 500MB storage, unlimited API requests, 2 projects"));
189
- console.log(chalk.dim(" The connection string looks like:"));
190
- console.log(chalk.dim(" postgresql://postgres.[ref]:[password]@aws-0-[region].pooler.supabase.com:6543/postgres"));
191
- console.log("");
192
- }
193
- if (dbType === "sqlite") {
194
- const { dbPath } = await inquirer.prompt([{
195
- type: "input",
196
- name: "dbPath",
197
- message: "Database file path:",
198
- default: "./agenticmail-enterprise.db"
199
- }]);
200
- return { type: dbType, connectionString: dbPath };
201
- }
202
- if (dbType === "dynamodb") {
203
- const answers = await inquirer.prompt([
204
- {
205
- type: "input",
206
- name: "region",
207
- message: "AWS Region:",
208
- default: "us-east-1"
209
- },
210
- {
211
- type: "input",
212
- name: "accessKeyId",
213
- message: "AWS Access Key ID:",
214
- validate: (v) => v.length > 0 || "Required"
215
- },
216
- {
217
- type: "password",
218
- name: "secretAccessKey",
219
- message: "AWS Secret Access Key:",
220
- mask: "*",
221
- validate: (v) => v.length > 0 || "Required"
222
- }
223
- ]);
224
- return { type: dbType, ...answers };
225
- }
226
- if (dbType === "turso") {
227
- const answers = await inquirer.prompt([
228
- {
229
- type: "input",
230
- name: "connectionString",
231
- message: "Turso database URL:",
232
- suffix: chalk.dim(" (e.g. libsql://db-org.turso.io)"),
233
- validate: (v) => v.length > 0 || "Required"
234
- },
235
- {
236
- type: "password",
237
- name: "authToken",
238
- message: "Turso auth token:",
239
- mask: "*",
240
- validate: (v) => v.length > 0 || "Required"
241
- }
242
- ]);
243
- return { type: dbType, connectionString: answers.connectionString, authToken: answers.authToken };
244
- }
245
- const hint = CONNECTION_HINTS[dbType] || "";
246
- const { connectionString } = await inquirer.prompt([{
247
- type: "input",
248
- name: "connectionString",
249
- message: "Connection string:",
250
- suffix: hint ? chalk.dim(` (e.g. ${hint})`) : "",
251
- validate: (v) => v.length > 0 || "Connection string is required"
252
- }]);
253
- return { type: dbType, connectionString };
254
- }
255
-
256
- // src/setup/deployment.ts
257
- import { execSync, exec as execCb } from "child_process";
258
- import { promisify } from "util";
259
- import { existsSync, writeFileSync, readFileSync } from "fs";
260
- import { join } from "path";
261
- import { homedir, platform, arch } from "os";
262
- var execP = promisify(execCb);
263
- var SUBDOMAIN_REGISTRY_URL = process.env.AGENTICMAIL_SUBDOMAIN_REGISTRY_URL || "https://registry.agenticmail.io";
264
- async function promptDeployment(inquirer, chalk) {
265
- console.log("");
266
- console.log(chalk.bold.cyan(" Step 3 of 4: Deployment"));
267
- console.log(chalk.dim(" Where should your dashboard run?\n"));
268
- const { deployTarget } = await inquirer.prompt([{
269
- type: "list",
270
- name: "deployTarget",
271
- message: "Deploy to:",
272
- choices: [
273
- {
274
- name: `AgenticMail Cloud ${chalk.green("\u2190 recommended")} ${chalk.dim("(instant URL, zero config)")}`,
275
- value: "cloud"
276
- },
277
- {
278
- name: `Cloudflare Tunnel ${chalk.dim("(self-hosted, free, no ports)")}`,
279
- value: "cloudflare-tunnel"
280
- },
281
- {
282
- name: `Fly.io ${chalk.dim("(your account)")}`,
283
- value: "fly"
284
- },
285
- {
286
- name: `Railway ${chalk.dim("(your account)")}`,
287
- value: "railway"
288
- },
289
- {
290
- name: `Docker ${chalk.dim("(self-hosted)")}`,
291
- value: "docker"
292
- },
293
- {
294
- name: `Local ${chalk.dim("(dev/testing, runs here)")}`,
295
- value: "local"
296
- }
297
- ]
298
- }]);
299
- if (deployTarget === "cloud") {
300
- const cloud = await runCloudSetup(inquirer, chalk);
301
- return { target: deployTarget, cloud };
302
- }
303
- if (deployTarget === "cloudflare-tunnel") {
304
- const tunnel = await runTunnelSetup(inquirer, chalk);
305
- return { target: deployTarget, tunnel };
306
- }
307
- return { target: deployTarget };
308
- }
309
- async function runCloudSetup(inquirer, chalk) {
310
- console.log("");
311
- console.log(chalk.bold(" AgenticMail Cloud Setup"));
312
- console.log(chalk.dim(" Get a free subdomain on agenticmail.io \u2014 no Cloudflare account needed."));
313
- console.log(chalk.dim(" Your instance will be live at https://yourname.agenticmail.io\n"));
314
- let subdomain = "";
315
- let claimResult = null;
316
- while (!subdomain) {
317
- const { name } = await inquirer.prompt([{
318
- type: "input",
319
- name: "name",
320
- message: "Choose your subdomain:",
321
- suffix: chalk.dim(".agenticmail.io"),
322
- validate: (input) => {
323
- const cleaned2 = input.toLowerCase().trim();
324
- if (cleaned2.length < 3) return "Must be at least 3 characters";
325
- if (cleaned2.length > 32) return "Must be 32 characters or fewer";
326
- if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(cleaned2)) return "Only lowercase letters, numbers, and hyphens allowed";
327
- return true;
328
- }
329
- }]);
330
- const cleaned = name.toLowerCase().trim();
331
- process.stdout.write(chalk.dim(` Checking ${cleaned}.agenticmail.io... `));
332
- try {
333
- const checkResp = await fetch(`${SUBDOMAIN_REGISTRY_URL}/check?name=${encodeURIComponent(cleaned)}`);
334
- const checkData = await checkResp.json();
335
- if (!checkData.available) {
336
- console.log(chalk.red("\u2717 " + (checkData.reason || "Not available")));
337
- continue;
338
- }
339
- console.log(chalk.green("\u2713 Available!"));
340
- } catch (err) {
341
- console.log(chalk.yellow("\u26A0 Could not check availability: " + err.message));
342
- console.log(chalk.dim(" Proceeding anyway \u2014 the claim step will verify.\n"));
343
- }
344
- const { confirmed } = await inquirer.prompt([{
345
- type: "confirm",
346
- name: "confirmed",
347
- message: `Claim ${chalk.bold(cleaned + ".agenticmail.io")}?`,
348
- default: true
349
- }]);
350
- if (!confirmed) continue;
351
- const { createHash, randomUUID: randomUUID2 } = await import("crypto");
352
- let vaultKey = process.env.AGENTICMAIL_VAULT_KEY;
353
- if (!vaultKey) {
354
- vaultKey = randomUUID2() + randomUUID2();
355
- process.env.AGENTICMAIL_VAULT_KEY = vaultKey;
356
- }
357
- const vaultKeyHash = createHash("sha256").update(vaultKey).digest("hex");
358
- process.stdout.write(chalk.dim(" Provisioning subdomain... "));
359
- try {
360
- const claimResp = await fetch(`${SUBDOMAIN_REGISTRY_URL}/claim`, {
361
- method: "POST",
362
- headers: { "Content-Type": "application/json" },
363
- body: JSON.stringify({ name: cleaned, vaultKeyHash })
364
- });
365
- claimResult = await claimResp.json();
366
- if (claimResult.error) {
367
- console.log(chalk.red("\u2717 " + claimResult.error));
368
- if (claimResult.error.includes("already has subdomain")) {
369
- const { wantsRecover } = await inquirer.prompt([{
370
- type: "confirm",
371
- name: "wantsRecover",
372
- message: "Recover your existing subdomain instead?",
373
- default: true
374
- }]);
375
- if (wantsRecover) {
376
- const recoverResp = await fetch(`${SUBDOMAIN_REGISTRY_URL}/recover`, {
377
- method: "POST",
378
- headers: { "Content-Type": "application/json" },
379
- body: JSON.stringify({ vaultKeyHash })
380
- });
381
- claimResult = await recoverResp.json();
382
- if (claimResult.success) {
383
- subdomain = claimResult.subdomain;
384
- console.log(chalk.green(`\u2713 Recovered: ${claimResult.fqdn}`));
385
- } else {
386
- console.log(chalk.red("\u2717 Recovery failed: " + (claimResult.error || "Unknown error")));
387
- }
388
- }
389
- }
390
- continue;
391
- }
392
- if (claimResult.success) {
393
- subdomain = claimResult.subdomain || cleaned;
394
- if (claimResult.recovered) {
395
- console.log(chalk.green("\u2713 Recovered existing subdomain"));
396
- } else {
397
- console.log(chalk.green("\u2713 Subdomain claimed!"));
398
- }
399
- }
400
- } catch (err) {
401
- console.log(chalk.red("\u2717 Failed: " + err.message));
402
- console.log(chalk.dim(" Check your internet connection and try again.\n"));
403
- }
404
- }
405
- console.log("");
406
- console.log(chalk.bold(" Installing cloudflared connector..."));
407
- let cloudflaredPath = "";
408
- try {
409
- cloudflaredPath = execSync("which cloudflared", { encoding: "utf8" }).trim();
410
- console.log(chalk.green(` \u2713 cloudflared found at ${cloudflaredPath}`));
411
- } catch {
412
- console.log(chalk.dim(" cloudflared not found \u2014 installing..."));
413
- try {
414
- const os = platform();
415
- if (os === "darwin") {
416
- execSync("brew install cloudflared", { stdio: "pipe" });
417
- } else if (os === "linux") {
418
- const archStr = arch() === "arm64" ? "arm64" : "amd64";
419
- execSync(`curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-${archStr} -o /usr/local/bin/cloudflared && chmod +x /usr/local/bin/cloudflared`, { stdio: "pipe" });
420
- } else {
421
- console.log(chalk.yellow(" Please install cloudflared manually: https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation/"));
422
- }
423
- cloudflaredPath = execSync("which cloudflared", { encoding: "utf8" }).trim();
424
- console.log(chalk.green(` \u2713 cloudflared installed at ${cloudflaredPath}`));
425
- } catch (e) {
426
- console.log(chalk.yellow(" \u26A0 Could not auto-install cloudflared."));
427
- console.log(chalk.dim(" Install manually: https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation/"));
428
- }
429
- }
430
- const port = 3100;
431
- const fqdn = claimResult?.fqdn || `${subdomain}.agenticmail.io`;
432
- const tunnelToken = claimResult?.tunnelToken;
433
- const tunnelId = claimResult?.tunnelId;
434
- console.log("");
435
- console.log(chalk.bold.green(" \u2713 Setup Complete!"));
436
- console.log("");
437
- console.log(` Your dashboard: ${chalk.bold.cyan("https://" + fqdn)}`);
438
- console.log("");
439
- console.log(chalk.bgYellow.black.bold(" \u26A0 BACK UP ~/.agenticmail/.env \u26A0 "));
440
- console.log("");
441
- console.log(chalk.yellow(" This file contains EVERYTHING needed to recover if your machine crashes:"));
442
- console.log("");
443
- console.log(chalk.yellow(" DATABASE_URL \u2014 your database connection"));
444
- console.log(chalk.yellow(" JWT_SECRET \u2014 login session signing key"));
445
- console.log(chalk.yellow(" AGENTICMAIL_VAULT_KEY \u2014 encrypted credentials + subdomain recovery"));
446
- console.log(chalk.yellow(" CLOUDFLARED_TOKEN \u2014 tunnel connection token"));
447
- console.log(chalk.yellow(" PORT \u2014 server port"));
448
- console.log("");
449
- console.log(chalk.bold.yellow(" Copy this file to a safe place (password manager, cloud drive, etc.)"));
450
- console.log(chalk.bold.yellow(" Without it, you CANNOT recover your subdomain or encrypted data."));
451
- console.log("");
452
- console.log(chalk.dim(" To recover on a new machine:"));
453
- console.log(chalk.cyan(" npx @agenticmail/enterprise recover --cloud"));
454
- console.log("");
455
- console.log("");
456
- console.log(chalk.dim(" To start your instance, run these two processes:"));
457
- console.log("");
458
- console.log(` ${chalk.cyan("cloudflared tunnel --no-autoupdate run --token " + (tunnelToken || "<your-tunnel-token>"))}`);
459
- console.log(` ${chalk.cyan("npx @agenticmail/enterprise start")}`);
460
- console.log("");
461
- console.log(chalk.dim(" Or let the setup wizard start them with PM2 (next step).\n"));
462
- const envPath = join(homedir(), ".agenticmail", ".env");
463
- try {
464
- let envContent = "";
465
- if (existsSync(envPath)) {
466
- envContent = readFileSync(envPath, "utf8");
467
- }
468
- if (tunnelToken && !envContent.includes("CLOUDFLARED_TOKEN=")) {
469
- envContent += `
470
- CLOUDFLARED_TOKEN=${tunnelToken}
471
- `;
472
- }
473
- if (!envContent.includes("AGENTICMAIL_SUBDOMAIN=")) {
474
- envContent += `AGENTICMAIL_SUBDOMAIN=${subdomain}
475
- `;
476
- }
477
- if (!envContent.includes("AGENTICMAIL_DOMAIN=")) {
478
- envContent += `AGENTICMAIL_DOMAIN=${fqdn}
479
- `;
480
- }
481
- const { mkdirSync } = await import("fs");
482
- mkdirSync(join(homedir(), ".agenticmail"), { recursive: true });
483
- writeFileSync(envPath, envContent, { mode: 384 });
484
- } catch {
485
- }
486
- return {
487
- subdomain,
488
- fqdn,
489
- tunnelId: tunnelId || "",
490
- tunnelToken: tunnelToken || "",
491
- port
492
- };
493
- }
494
- async function runTunnelSetup(inquirer, chalk) {
495
- console.log("");
496
- console.log(chalk.bold(" Cloudflare Tunnel Setup"));
497
- console.log(chalk.dim(" Exposes your local server to the internet via Cloudflare."));
498
- console.log(chalk.dim(" No open ports, free TLS, auto-DNS.\n"));
499
- console.log(chalk.bold(" 1. Cloudflared CLI"));
500
- let installed = false;
501
- let version = "";
502
- try {
503
- version = execSync("cloudflared --version 2>&1", { encoding: "utf8", timeout: 5e3 }).trim();
504
- installed = true;
505
- } catch {
506
- }
507
- if (installed) {
508
- console.log(chalk.green(` \u2713 Installed (${version})
509
- `));
510
- } else {
511
- console.log(chalk.yellow(" Not installed."));
512
- const { doInstall } = await inquirer.prompt([{
513
- type: "confirm",
514
- name: "doInstall",
515
- message: "Install cloudflared now?",
516
- default: true
517
- }]);
518
- if (!doInstall) {
519
- console.log(chalk.red("\n cloudflared is required for tunnel deployment."));
520
- console.log(chalk.dim(" Install it manually: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/\n"));
521
- process.exit(1);
522
- }
523
- console.log(chalk.dim(" Installing..."));
524
- try {
525
- await installCloudflared();
526
- version = execSync("cloudflared --version 2>&1", { encoding: "utf8", timeout: 5e3 }).trim();
527
- console.log(chalk.green(` \u2713 Installed (${version})
528
- `));
529
- } catch (err) {
530
- console.log(chalk.red(` \u2717 Installation failed: ${err.message}`));
531
- console.log(chalk.dim(" Install manually and re-run setup.\n"));
532
- process.exit(1);
533
- }
534
- }
535
- console.log(chalk.bold(" 2. Cloudflare Authentication"));
536
- const cfDir = join(homedir(), ".cloudflared");
537
- const certPath = join(cfDir, "cert.pem");
538
- const loggedIn = existsSync(certPath);
539
- if (loggedIn) {
540
- console.log(chalk.green(" \u2713 Already authenticated\n"));
541
- } else {
542
- console.log(chalk.dim(" This will open your browser to authorize Cloudflare.\n"));
543
- const { doLogin } = await inquirer.prompt([{
544
- type: "confirm",
545
- name: "doLogin",
546
- message: "Open browser to login to Cloudflare?",
547
- default: true
548
- }]);
549
- if (!doLogin) {
550
- console.log(chalk.red("\n Cloudflare auth is required. Run `cloudflared tunnel login` manually.\n"));
551
- process.exit(1);
552
- }
553
- console.log(chalk.dim(" Waiting for browser authorization..."));
554
- try {
555
- await execP("cloudflared tunnel login", { timeout: 12e4 });
556
- console.log(chalk.green(" \u2713 Authenticated\n"));
557
- } catch (err) {
558
- console.log(chalk.red(` \u2717 Login failed or timed out: ${err.message}`));
559
- console.log(chalk.dim(" Complete the browser authorization and try again.\n"));
560
- process.exit(1);
561
- }
562
- }
563
- console.log(chalk.bold(" 3. Tunnel Configuration"));
564
- const { domain, port, tunnelName } = await inquirer.prompt([
565
- {
566
- type: "input",
567
- name: "domain",
568
- message: "Domain (e.g. dashboard.yourcompany.com):",
569
- validate: (v) => v.includes(".") ? true : "Enter a valid domain"
570
- },
571
- {
572
- type: "number",
573
- name: "port",
574
- message: "Local port:",
575
- default: 3200
576
- },
577
- {
578
- type: "input",
579
- name: "tunnelName",
580
- message: "Tunnel name:",
581
- default: "agenticmail-enterprise"
582
- }
583
- ]);
584
- console.log("");
585
- console.log(chalk.bold(" 4. Deploying"));
586
- let tunnelId = "";
587
- try {
588
- console.log(chalk.dim(" Creating tunnel..."));
589
- const out = execSync(`cloudflared tunnel create ${tunnelName} 2>&1`, { encoding: "utf8", timeout: 3e4 });
590
- const match = out.match(/Created tunnel .+ with id ([a-f0-9-]+)/);
591
- tunnelId = match?.[1] || "";
592
- console.log(chalk.green(` \u2713 Tunnel created: ${tunnelName} (${tunnelId})`));
593
- } catch (e) {
594
- if (e.message?.includes("already exists") || e.stderr?.includes("already exists")) {
595
- try {
596
- const listOut = execSync("cloudflared tunnel list --output json 2>&1", { encoding: "utf8", timeout: 15e3 });
597
- const tunnels = JSON.parse(listOut);
598
- const existing = tunnels.find((t) => t.name === tunnelName);
599
- if (existing) {
600
- tunnelId = existing.id;
601
- console.log(chalk.green(` \u2713 Using existing tunnel: ${tunnelName} (${tunnelId})`));
602
- }
603
- } catch {
604
- console.log(chalk.red(` \u2717 Tunnel "${tunnelName}" exists but couldn't read its ID`));
605
- process.exit(1);
606
- }
607
- } else {
608
- console.log(chalk.red(` \u2717 Failed to create tunnel: ${e.message}`));
609
- process.exit(1);
610
- }
611
- }
612
- if (!tunnelId) {
613
- console.log(chalk.red(" \u2717 Could not determine tunnel ID"));
614
- process.exit(1);
615
- }
616
- const config = [
617
- `tunnel: ${tunnelId}`,
618
- `credentials-file: ${join(cfDir, tunnelId + ".json")}`,
619
- "",
620
- "ingress:",
621
- ` - hostname: ${domain}`,
622
- ` service: http://localhost:${port}`,
623
- " - service: http_status:404"
624
- ].join("\n");
625
- writeFileSync(join(cfDir, "config.yml"), config);
626
- console.log(chalk.green(` \u2713 Config written: ${domain} \u2192 localhost:${port}`));
627
- try {
628
- execSync(`cloudflared tunnel route dns ${tunnelId} ${domain} 2>&1`, { encoding: "utf8", timeout: 3e4 });
629
- console.log(chalk.green(` \u2713 DNS CNAME created: ${domain}`));
630
- } catch (e) {
631
- if (e.message?.includes("already exists") || e.stderr?.includes("already exists")) {
632
- console.log(chalk.green(` \u2713 DNS CNAME already exists for ${domain}`));
633
- } else {
634
- console.log(chalk.yellow(` \u26A0 DNS routing failed \u2014 add CNAME manually: ${domain} \u2192 ${tunnelId}.cfargotunnel.com`));
635
- }
636
- }
637
- let started = false;
638
- try {
639
- execSync("which pm2", { timeout: 3e3 });
640
- try {
641
- execSync("pm2 delete cloudflared 2>/dev/null", { timeout: 5e3 });
642
- } catch {
643
- }
644
- execSync(`pm2 start cloudflared --name cloudflared -- tunnel run`, { encoding: "utf8", timeout: 15e3 });
645
- try {
646
- execSync("pm2 save 2>/dev/null", { timeout: 5e3 });
647
- } catch {
648
- }
649
- try {
650
- const startupOut = execSync("pm2 startup 2>&1", { encoding: "utf8", timeout: 15e3 });
651
- const sudoMatch = startupOut.match(/sudo .+$/m);
652
- if (sudoMatch) try {
653
- execSync(sudoMatch[0], { timeout: 15e3, stdio: "pipe" });
654
- } catch {
655
- }
656
- } catch {
657
- }
658
- console.log(chalk.green(" \u2713 Tunnel running via PM2 (auto-restarts on crash + reboot)"));
659
- started = true;
660
- } catch {
661
- }
662
- if (!started) {
663
- try {
664
- console.log(chalk.dim(" Installing PM2 for process management..."));
665
- execSync("npm install -g pm2", { timeout: 6e4, stdio: "pipe" });
666
- try {
667
- execSync("pm2 delete cloudflared 2>/dev/null", { timeout: 5e3 });
668
- } catch {
669
- }
670
- execSync(`pm2 start cloudflared --name cloudflared -- tunnel run`, { encoding: "utf8", timeout: 15e3 });
671
- try {
672
- execSync("pm2 save 2>/dev/null", { timeout: 5e3 });
673
- } catch {
674
- }
675
- try {
676
- const startupOut = execSync("pm2 startup 2>&1", { encoding: "utf8", timeout: 15e3 });
677
- const sudoMatch = startupOut.match(/sudo .+$/m);
678
- if (sudoMatch) try {
679
- execSync(sudoMatch[0], { timeout: 15e3, stdio: "pipe" });
680
- } catch {
681
- }
682
- } catch {
683
- }
684
- console.log(chalk.green(" \u2713 PM2 installed + tunnel running (auto-restarts on crash + reboot)"));
685
- started = true;
686
- } catch {
687
- console.log(chalk.yellow(" \u26A0 PM2 not available \u2014 tunnel started in background"));
688
- console.log(chalk.dim(" Install PM2 for auto-restart: npm install -g pm2"));
689
- try {
690
- const { spawn } = await import("child_process");
691
- const child = spawn("cloudflared", ["tunnel", "run"], { detached: true, stdio: "ignore" });
692
- child.unref();
693
- started = true;
694
- } catch {
695
- }
696
- }
697
- }
698
- console.log("");
699
- console.log(chalk.green.bold(` \u2713 Tunnel deployed! Your dashboard will be at https://${domain}`));
700
- console.log("");
701
- return { tunnelId, domain, port, tunnelName };
702
- }
703
- async function installCloudflared() {
704
- const plat = platform();
705
- const a = arch();
706
- if (plat === "darwin") {
707
- try {
708
- execSync("which brew", { timeout: 3e3 });
709
- execSync("brew install cloudflared 2>&1", { encoding: "utf8", timeout: 12e4 });
710
- return;
711
- } catch {
712
- }
713
- const cfArch = a === "arm64" ? "arm64" : "amd64";
714
- execSync(
715
- `curl -L -o /usr/local/bin/cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-darwin-${cfArch} && chmod +x /usr/local/bin/cloudflared`,
716
- { timeout: 6e4 }
717
- );
718
- } else if (plat === "linux") {
719
- const cfArch = a === "arm64" ? "arm64" : "amd64";
720
- execSync(
721
- `curl -L -o /usr/local/bin/cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-${cfArch} && chmod +x /usr/local/bin/cloudflared`,
722
- { timeout: 6e4 }
723
- );
724
- } else {
725
- throw new Error("Unsupported platform: " + plat);
726
- }
727
- }
728
-
729
- // src/setup/domain.ts
730
- async function promptDomain(inquirer, chalk, deployTarget) {
731
- if (deployTarget === "local") {
732
- return {};
733
- }
734
- console.log("");
735
- console.log(chalk.bold.cyan(" Step 4 of 5: Custom Domain"));
736
- console.log(chalk.dim(" Configure how your team will access the dashboard.\n"));
737
- const targetHints = {
738
- cloud: "By default, your dashboard is at <subdomain>.agenticmail.io. Add a custom domain for a branded URL.",
739
- docker: "Configure your reverse proxy (nginx, Caddy, etc.) to route your domain to the Docker container.",
740
- fly: "After deploying, run `fly certs add <domain>` to provision TLS for your domain.",
741
- railway: "Add your domain in Railway project settings after deploying."
742
- };
743
- if (targetHints[deployTarget]) {
744
- console.log(chalk.dim(` ${targetHints[deployTarget]}`));
745
- console.log("");
746
- }
747
- const { domainMode } = await inquirer.prompt([{
748
- type: "list",
749
- name: "domainMode",
750
- message: "Domain setup:",
751
- choices: [
752
- {
753
- name: `Use default subdomain only ${chalk.dim("(<subdomain>.agenticmail.io)")}`,
754
- value: "subdomain_only"
755
- },
756
- {
757
- name: `Add a custom subdomain ${chalk.dim("(e.g. agents.yourcompany.com)")}`,
758
- value: "custom_subdomain"
759
- },
760
- {
761
- name: `Deploy on my root domain ${chalk.dim("(e.g. yourcompany.com \u2014 no subdomain)")}`,
762
- value: "root_domain"
763
- }
764
- ]
765
- }]);
766
- if (domainMode === "subdomain_only") {
767
- return {};
768
- }
769
- const isRoot = domainMode === "root_domain";
770
- const { domain } = await inquirer.prompt([{
771
- type: "input",
772
- name: "domain",
773
- message: isRoot ? "Your domain:" : "Custom domain:",
774
- suffix: isRoot ? chalk.dim(" (e.g. yourcompany.com)") : chalk.dim(" (e.g. agents.yourcompany.com)"),
775
- validate: (v) => {
776
- const d = v.trim().toLowerCase();
777
- if (!d.includes(".")) return "Enter a valid domain (e.g. yourcompany.com)";
778
- if (d.startsWith("http")) return "Enter just the domain, not a URL";
779
- if (d.endsWith(".")) return "Do not include a trailing dot";
780
- return true;
781
- },
782
- filter: (v) => v.trim().toLowerCase()
783
- }]);
784
- if (isRoot) {
785
- console.log("");
786
- console.log(chalk.bold(" Root Domain Deployment"));
787
- console.log(chalk.dim(` Your dashboard will be accessible at: ${chalk.white("https://" + domain)}`));
788
- console.log(chalk.dim(" This means the entire domain is dedicated to your AgenticMail deployment."));
789
- console.log("");
790
- }
791
- console.log("");
792
- console.log(chalk.dim(" After setup, you will need DNS records for this domain:"));
793
- console.log("");
794
- if (isRoot) {
795
- console.log(chalk.dim(` 1. ${chalk.white("A record")} \u2014 point ${domain} to your server IP`));
796
- console.log(chalk.dim(` (or CNAME if your provider allows it at the apex)`));
797
- } else {
798
- console.log(chalk.dim(` 1. ${chalk.white("CNAME or A record")} \u2014 routes traffic to your server`));
799
- }
800
- console.log(chalk.dim(` 2. ${chalk.white("TXT record")} \u2014 proves domain ownership (next step)`));
801
- console.log("");
802
- return {
803
- customDomain: domain,
804
- useRootDomain: isRoot || void 0
805
- };
806
- }
807
-
808
- // src/setup/registration.ts
809
- import { randomBytes } from "crypto";
810
- var REGISTRY_BASE_URL = process.env.AGENTICMAIL_REGISTRY_URL || "https://agenticmail.io/enterprise/v1";
811
- async function promptRegistration(inquirer, chalk, ora, domain, companyName, adminEmail) {
812
- if (!domain) {
813
- return { registered: false, verificationStatus: "skipped" };
814
- }
815
- console.log("");
816
- console.log(chalk.bold.cyan(" Step 5 of 5: Domain Registration"));
817
- console.log(chalk.dim(" Protect your deployment from unauthorized duplication.\n"));
818
- const { wantsRegistration } = await inquirer.prompt([{
819
- type: "confirm",
820
- name: "wantsRegistration",
821
- message: `Register ${chalk.bold(domain)} with AgenticMail?`,
822
- default: true
823
- }]);
824
- if (!wantsRegistration) {
825
- console.log(chalk.dim(" Skipped. You can register later from the dashboard.\n"));
826
- return { registered: false, verificationStatus: "skipped" };
827
- }
828
- const spinner = ora("Generating deployment key...").start();
829
- const { createHash } = await import("crypto");
830
- const plaintextKey = randomBytes(32).toString("hex");
831
- const keyHash = createHash("sha256").update(plaintextKey).digest("hex");
832
- spinner.succeed("Deployment key generated");
833
- spinner.start("Registering domain with AgenticMail registry...");
834
- const registryUrl = REGISTRY_BASE_URL.replace(/\/$/, "");
835
- let registrationId;
836
- let dnsChallenge;
837
- try {
838
- const res = await fetch(`${registryUrl}/domains/register`, {
839
- method: "POST",
840
- headers: { "Content-Type": "application/json" },
841
- body: JSON.stringify({
842
- domain: domain.toLowerCase().trim(),
843
- keyHash,
844
- sha256Hash: keyHash,
845
- orgName: companyName,
846
- contactEmail: adminEmail
847
- }),
848
- signal: AbortSignal.timeout(15e3)
849
- });
850
- const data = await res.json().catch(() => ({}));
851
- if (res.status === 409) {
852
- spinner.info("Domain already registered \u2014 verifying ownership");
853
- console.log("");
854
- console.log(chalk.yellow(" This domain is already registered and verified."));
855
- console.log(chalk.dim(" Enter your deployment key to prove ownership and continue.\n"));
856
- const { deploymentKey } = await inquirer.prompt([{
857
- type: "password",
858
- name: "deploymentKey",
859
- message: "Deployment key:",
860
- mask: "*",
861
- validate: (v) => v.length === 64 || "Deployment key should be 64 hex characters"
862
- }]);
863
- const recoverSpinner = ora("Verifying deployment key...").start();
864
- try {
865
- const recoverRes = await fetch(`${registryUrl}/domains/recover`, {
866
- method: "POST",
867
- headers: { "Content-Type": "application/json" },
868
- body: JSON.stringify({
869
- domain: domain.toLowerCase().trim(),
870
- deploymentKey
871
- }),
872
- signal: AbortSignal.timeout(15e3)
873
- });
874
- const recoverData = await recoverRes.json().catch(() => ({}));
875
- if (recoverRes.status === 403) {
876
- recoverSpinner.fail("Invalid deployment key");
877
- console.log("");
878
- console.log(chalk.red(" The deployment key does not match this domain."));
879
- console.log("");
880
- const { continueAnyway } = await inquirer.prompt([{
881
- type: "confirm",
882
- name: "continueAnyway",
883
- message: "Continue setup without registration?",
884
- default: true
885
- }]);
886
- if (continueAnyway) {
887
- return { registered: false, verificationStatus: "skipped" };
888
- }
889
- process.exit(1);
890
- }
891
- if (!recoverRes.ok) {
892
- throw new Error(recoverData.error || `HTTP ${recoverRes.status}`);
893
- }
894
- recoverSpinner.succeed("Ownership verified \u2014 domain recovered");
895
- registrationId = recoverData.registrationId;
896
- dnsChallenge = recoverData.dnsChallenge;
897
- const verifyRes = await fetch(`${registryUrl}/domains/verify`, {
898
- method: "POST",
899
- headers: { "Content-Type": "application/json" },
900
- body: JSON.stringify({ domain: domain.toLowerCase().trim() }),
901
- signal: AbortSignal.timeout(15e3)
902
- });
903
- const verifyData = await verifyRes.json().catch(() => ({}));
904
- const { createHash: createHash2 } = await import("crypto");
905
- const localKeyHash = createHash2("sha256").update(deploymentKey).digest("hex");
906
- return {
907
- registered: true,
908
- deploymentKeyHash: localKeyHash,
909
- dnsChallenge,
910
- registrationId,
911
- verificationStatus: verifyData?.verified ? "verified" : "pending_dns"
912
- };
913
- } catch (err) {
914
- recoverSpinner.fail(`Recovery failed: ${err.message}`);
915
- const { continueAnyway } = await inquirer.prompt([{
916
- type: "confirm",
917
- name: "continueAnyway",
918
- message: "Continue setup without registration?",
919
- default: true
920
- }]);
921
- if (continueAnyway) {
922
- return { registered: false, verificationStatus: "skipped" };
923
- }
924
- process.exit(1);
925
- }
926
- }
927
- if (!res.ok) {
928
- throw new Error(data.error || `HTTP ${res.status}`);
929
- }
930
- registrationId = data.registrationId;
931
- dnsChallenge = data.dnsChallenge;
932
- spinner.succeed("Domain registered");
933
- } catch (err) {
934
- spinner.warn("Registry unavailable");
935
- console.log("");
936
- console.log(chalk.yellow(` Could not reach registry: ${err.message}`));
937
- console.log(chalk.dim(" You can register later with: npx @agenticmail/enterprise verify-domain"));
938
- console.log("");
939
- const { continueAnyway } = await inquirer.prompt([{
940
- type: "confirm",
941
- name: "continueAnyway",
942
- message: "Continue setup without registration?",
943
- default: true
944
- }]);
945
- if (continueAnyway) {
946
- return { registered: false, verificationStatus: "skipped" };
947
- }
948
- process.exit(1);
949
- }
950
- console.log("");
951
- console.log(chalk.red.bold(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"));
952
- console.log(chalk.red.bold(" \u2551") + chalk.white.bold(" DEPLOYMENT KEY \u2014 SAVE THIS NOW ") + chalk.red.bold("\u2551"));
953
- console.log(chalk.red.bold(" \u2551") + " " + chalk.red.bold("\u2551"));
954
- console.log(chalk.red.bold(" \u2551") + ` ${chalk.green.bold(plaintextKey)} ` + chalk.red.bold("\u2551"));
955
- console.log(chalk.red.bold(" \u2551") + " " + chalk.red.bold("\u2551"));
956
- console.log(chalk.red.bold(" \u2551") + chalk.dim(" This key is shown ONCE. Store it securely (password manager, ") + chalk.red.bold("\u2551"));
957
- console.log(chalk.red.bold(" \u2551") + chalk.dim(" vault, printed backup). You need it to recover this domain. ") + chalk.red.bold("\u2551"));
958
- console.log(chalk.red.bold(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"));
959
- console.log("");
960
- console.log(chalk.bold(" Add this DNS TXT record to prove domain ownership:"));
961
- console.log("");
962
- console.log(` ${chalk.bold("Host:")} ${chalk.cyan(`_agenticmail-verify.${domain}`)}`);
963
- console.log(` ${chalk.bold("Type:")} ${chalk.cyan("TXT")}`);
964
- console.log(` ${chalk.bold("Value:")} ${chalk.cyan(dnsChallenge)}`);
965
- console.log("");
966
- console.log(chalk.dim(" DNS changes can take up to 48 hours to propagate."));
967
- console.log("");
968
- await inquirer.prompt([{
969
- type: "confirm",
970
- name: "keySaved",
971
- message: "I have saved my deployment key",
972
- default: false
973
- }]);
974
- const { checkNow } = await inquirer.prompt([{
975
- type: "confirm",
976
- name: "checkNow",
977
- message: "Check DNS verification now?",
978
- default: false
979
- }]);
980
- let verificationStatus = "pending_dns";
981
- if (checkNow) {
982
- for (let attempt = 1; attempt <= 5; attempt++) {
983
- spinner.start(`Checking DNS (attempt ${attempt}/5)...`);
984
- try {
985
- const res = await fetch(`${registryUrl}/domains/verify`, {
986
- method: "POST",
987
- headers: { "Content-Type": "application/json" },
988
- body: JSON.stringify({ domain: domain.toLowerCase().trim() }),
989
- signal: AbortSignal.timeout(15e3)
990
- });
991
- const data = await res.json().catch(() => ({}));
992
- if (data.verified) {
993
- spinner.succeed("Domain verified!");
994
- verificationStatus = "verified";
995
- break;
996
- }
997
- } catch {
998
- }
999
- if (attempt < 5) {
1000
- spinner.text = `DNS record not found yet. Retrying in 10s (attempt ${attempt}/5)...`;
1001
- await new Promise((r) => setTimeout(r, 1e4));
1002
- } else {
1003
- spinner.info("DNS record not found yet");
1004
- console.log(chalk.dim(" Run later: npx @agenticmail/enterprise verify-domain"));
1005
- }
1006
- }
1007
- } else {
1008
- console.log(chalk.dim(" Run when ready: npx @agenticmail/enterprise verify-domain"));
1009
- }
1010
- console.log("");
1011
- return {
1012
- registered: true,
1013
- deploymentKeyHash: keyHash,
1014
- dnsChallenge,
1015
- registrationId,
1016
- verificationStatus
1017
- };
1018
- }
1019
-
1020
- // src/setup/provision.ts
1021
- import { randomUUID, randomBytes as randomBytes2 } from "crypto";
1022
- function generateOrgId() {
1023
- const chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
1024
- const bytes = randomBytes2(10);
1025
- let id = "";
1026
- for (let i = 0; i < 10; i++) id += chars[bytes[i] % chars.length];
1027
- return id;
1028
- }
1029
- async function provision(config, ora, chalk) {
1030
- const spinner = ora("Connecting to database...").start();
1031
- const jwtSecret = randomUUID() + randomUUID();
1032
- const vaultKey = randomUUID() + randomUUID();
1033
- try {
1034
- const { createAdapter } = await import("./factory-MQASIPEB.js");
1035
- const db = await createAdapter({
1036
- type: config.database.type,
1037
- connectionString: config.database.connectionString,
1038
- region: config.database.region,
1039
- accessKeyId: config.database.accessKeyId,
1040
- secretAccessKey: config.database.secretAccessKey,
1041
- authToken: config.database.authToken
1042
- });
1043
- spinner.text = "Running migrations...";
1044
- await db.migrate();
1045
- spinner.succeed("Database ready");
1046
- const engineDbInterface = db.getEngineDB();
1047
- if (engineDbInterface) {
1048
- spinner.start("Initializing engine...");
1049
- const { EngineDatabase } = await import("./db-adapter-2T56ORSD.js");
1050
- const dialectMap = {
1051
- sqlite: "sqlite",
1052
- postgres: "postgres",
1053
- supabase: "postgres",
1054
- neon: "postgres",
1055
- cockroachdb: "postgres",
1056
- mysql: "mysql",
1057
- planetscale: "mysql",
1058
- turso: "turso"
1059
- };
1060
- const engineDialect = dialectMap[db.getDialect()] || db.getDialect();
1061
- const engineDb = new EngineDatabase(engineDbInterface, engineDialect);
1062
- const migResult = await engineDb.migrate();
1063
- spinner.succeed(`Engine ready (${migResult.applied} migrations applied)`);
1064
- }
1065
- spinner.start("Creating company...");
1066
- const orgId = generateOrgId();
1067
- const corsOrigins = [];
1068
- if (config.domain.customDomain) {
1069
- corsOrigins.push(`https://${config.domain.customDomain}`);
1070
- }
1071
- if (config.company.subdomain) {
1072
- corsOrigins.push(`https://${config.company.subdomain}.agenticmail.io`);
1073
- }
1074
- if (config.deployTarget === "local") {
1075
- corsOrigins.push("http://localhost:3000", "http://localhost:8080", "http://127.0.0.1:3000", "http://127.0.0.1:8080");
1076
- }
1077
- await db.updateSettings({
1078
- name: config.company.companyName,
1079
- subdomain: config.company.subdomain,
1080
- domain: config.domain.customDomain,
1081
- orgId,
1082
- ...corsOrigins.length > 0 ? {
1083
- firewallConfig: {
1084
- network: { corsOrigins }
1085
- }
1086
- } : {}
1087
- });
1088
- spinner.succeed(`Company created (org: ${orgId})`);
1089
- if (config.registration?.registered) {
1090
- spinner.start("Saving domain registration...");
1091
- await db.updateSettings({
1092
- deploymentKeyHash: config.registration.deploymentKeyHash,
1093
- domainRegistrationId: config.registration.registrationId,
1094
- domainDnsChallenge: config.registration.dnsChallenge,
1095
- domainRegisteredAt: (/* @__PURE__ */ new Date()).toISOString(),
1096
- domainStatus: config.registration.verificationStatus === "verified" ? "verified" : "pending_dns",
1097
- ...config.registration.verificationStatus === "verified" ? { domainVerifiedAt: (/* @__PURE__ */ new Date()).toISOString() } : {}
1098
- });
1099
- spinner.succeed("Domain registration saved");
1100
- }
1101
- spinner.start("Creating admin account...");
1102
- let admin;
1103
- try {
1104
- admin = await db.createUser({
1105
- email: config.company.adminEmail,
1106
- name: "Admin",
1107
- role: "owner",
1108
- password: config.company.adminPassword
1109
- });
1110
- } catch (err) {
1111
- if (err.message?.includes("duplicate key") || err.message?.includes("UNIQUE constraint") || err.code === "23505") {
1112
- admin = await db.getUserByEmail(config.company.adminEmail);
1113
- if (!admin) throw err;
1114
- spinner.text = "Admin account already exists, reusing...";
1115
- } else {
1116
- throw err;
1117
- }
1118
- }
1119
- await db.logEvent({
1120
- actor: admin.id,
1121
- actorType: "system",
1122
- action: "setup.complete",
1123
- resource: `company:${config.company.subdomain}`,
1124
- details: {
1125
- dbType: config.database.type,
1126
- deployTarget: config.deployTarget,
1127
- companyName: config.company.companyName
1128
- }
1129
- });
1130
- spinner.succeed("Admin account created");
1131
- try {
1132
- const { writeFileSync: writeFileSync2, existsSync: existsSync2, mkdirSync } = await import("fs");
1133
- const { join: join3 } = await import("path");
1134
- const { homedir: homedir2 } = await import("os");
1135
- const envDir = join3(homedir2(), ".agenticmail");
1136
- if (!existsSync2(envDir)) mkdirSync(envDir, { recursive: true });
1137
- const port = config.tunnel?.port || (config.deployTarget === "local" ? 3e3 : void 0) || (config.deployTarget === "docker" ? 3e3 : void 0) || 3200;
1138
- let existingEnv = "";
1139
- const envFilePath = join3(envDir, ".env");
1140
- if (existsSync2(envFilePath)) {
1141
- try {
1142
- existingEnv = (await import("fs")).readFileSync(envFilePath, "utf8");
1143
- } catch {
1144
- }
1145
- }
1146
- const envMap = /* @__PURE__ */ new Map();
1147
- for (const line of existingEnv.split("\n")) {
1148
- const t = line.trim();
1149
- if (!t || t.startsWith("#")) continue;
1150
- const eq = t.indexOf("=");
1151
- if (eq > 0) envMap.set(t.slice(0, eq).trim(), t.slice(eq + 1).trim());
1152
- }
1153
- envMap.set("DATABASE_URL", config.database.connectionString || "");
1154
- envMap.set("JWT_SECRET", jwtSecret);
1155
- envMap.set("AGENTICMAIL_VAULT_KEY", vaultKey);
1156
- envMap.set("PORT", String(port));
1157
- if (config.cloud?.tunnelToken) envMap.set("CLOUDFLARED_TOKEN", config.cloud.tunnelToken);
1158
- if (config.cloud?.subdomain) envMap.set("AGENTICMAIL_SUBDOMAIN", config.cloud.subdomain);
1159
- if (config.cloud?.fqdn) envMap.set("AGENTICMAIL_DOMAIN", config.cloud.fqdn);
1160
- const envContent = [
1161
- "# AgenticMail Enterprise \u2014 auto-generated by setup wizard",
1162
- "# BACK UP THIS FILE! You need it to recover on a new machine.",
1163
- ...Array.from(envMap.entries()).map(([k, v]) => `${k}=${v}`)
1164
- ].join("\n") + "\n";
1165
- writeFileSync2(join3(envDir, ".env"), envContent, { mode: 384 });
1166
- spinner.succeed(`Config saved to ~/.agenticmail/.env`);
1167
- } catch {
1168
- }
1169
- const result = await deploy(config, db, jwtSecret, vaultKey, spinner, chalk);
1170
- return {
1171
- success: true,
1172
- url: result.url,
1173
- jwtSecret,
1174
- db,
1175
- serverClose: result.close
1176
- };
1177
- } catch (err) {
1178
- spinner.fail(`Setup failed: ${err.message}`);
1179
- return {
1180
- success: false,
1181
- error: err.message,
1182
- jwtSecret,
1183
- db: null
1184
- };
1185
- }
1186
- }
1187
- async function deploy(config, db, jwtSecret, vaultKey, spinner, chalk) {
1188
- const { deployTarget, company, database, domain, tunnel, cloud } = config;
1189
- if (deployTarget === "cloudflare-tunnel" && tunnel) {
1190
- spinner.start(`Starting local server on port ${tunnel.port}...`);
1191
- const { createServer: createServer2 } = await import("./server-6NDO2S52.js");
1192
- const server2 = createServer2({ port: tunnel.port, db, jwtSecret });
1193
- const handle2 = await server2.start();
1194
- spinner.succeed("Server running");
1195
- console.log("");
1196
- console.log(chalk.green.bold(" AgenticMail Enterprise is live!"));
1197
- console.log("");
1198
- console.log(` ${chalk.bold("Public URL:")} ${chalk.cyan("https://" + tunnel.domain)}`);
1199
- console.log(` ${chalk.bold("Local:")} ${chalk.cyan("http://localhost:" + tunnel.port)}`);
1200
- console.log(` ${chalk.bold("Tunnel:")} ${tunnel.tunnelName} (${tunnel.tunnelId})`);
1201
- console.log(` ${chalk.bold("Admin:")} ${company.adminEmail}`);
1202
- console.log("");
1203
- console.log(chalk.dim(" Tunnel is managed by PM2 \u2014 auto-restarts on crash."));
1204
- console.log(chalk.dim(" Manage: pm2 status | pm2 logs cloudflared | pm2 restart cloudflared"));
1205
- console.log(chalk.dim(" Press Ctrl+C to stop the server"));
1206
- return { url: "https://" + tunnel.domain, close: handle2.close };
1207
- }
1208
- if (deployTarget === "cloud" && cloud) {
1209
- spinner.start("Configuring agenticmail.io deployment...");
1210
- try {
1211
- const pm2 = await import("pm2");
1212
- await new Promise((resolve, reject) => {
1213
- pm2.connect((err) => {
1214
- if (err) {
1215
- reject(err);
1216
- return;
1217
- }
1218
- pm2.start({
1219
- name: "cloudflared",
1220
- script: "cloudflared",
1221
- args: `tunnel --no-autoupdate run --token ${cloud.tunnelToken}`,
1222
- interpreter: "none",
1223
- autorestart: true
1224
- }, (e) => {
1225
- if (e) console.warn(`PM2 cloudflared start: ${e.message}`);
1226
- pm2.start({
1227
- name: "enterprise",
1228
- script: "npx",
1229
- args: "@agenticmail/enterprise start",
1230
- env: {
1231
- PORT: String(cloud.port || 3100),
1232
- DATABASE_URL: database.connectionString || "",
1233
- JWT_SECRET: jwtSecret,
1234
- AGENTICMAIL_VAULT_KEY: vaultKey,
1235
- AGENTICMAIL_DOMAIN: cloud.fqdn
1236
- },
1237
- autorestart: true
1238
- }, (e2) => {
1239
- pm2.disconnect();
1240
- if (e2) reject(e2);
1241
- else resolve();
1242
- });
1243
- });
1244
- });
1245
- });
1246
- try {
1247
- const { execSync: execSync3 } = await import("child_process");
1248
- execSync3("pm2 save", { timeout: 1e4, stdio: "pipe" });
1249
- try {
1250
- const startupOut = execSync3("pm2 startup 2>&1", { encoding: "utf8", timeout: 15e3 });
1251
- const sudoMatch = startupOut.match(/sudo .+$/m);
1252
- if (sudoMatch) {
1253
- try {
1254
- execSync3(sudoMatch[0], { timeout: 15e3, stdio: "pipe" });
1255
- } catch {
1256
- }
1257
- }
1258
- } catch {
1259
- }
1260
- } catch {
1261
- }
1262
- spinner.succeed(`Live at https://${cloud.fqdn}`);
1263
- console.log(chalk.dim(" PM2 will auto-restart on crash and survive reboots."));
1264
- } catch (e) {
1265
- spinner.warn(`PM2 setup failed: ${e.message}`);
1266
- console.log(` Start manually:`);
1267
- console.log(` cloudflared tunnel --no-autoupdate run --token ${cloud.tunnelToken}`);
1268
- console.log(` npx @agenticmail/enterprise start`);
1269
- }
1270
- console.log("");
1271
- console.log(` Dashboard: https://${cloud.fqdn}`);
1272
- console.log(` To recover on a new machine, keep your AGENTICMAIL_VAULT_KEY safe.`);
1273
- console.log("");
1274
- return { url: `https://${cloud.fqdn}` };
1275
- }
1276
- if (deployTarget === "docker") {
1277
- const { generateDockerCompose, generateEnvFile } = await import("./managed-T2RBYB2W.js");
1278
- const compose = generateDockerCompose({ port: 3e3 });
1279
- const envFile = generateEnvFile({
1280
- dbType: database.type,
1281
- dbConnectionString: database.connectionString || "",
1282
- jwtSecret,
1283
- vaultKey
1284
- });
1285
- const { writeFileSync: writeFileSync2, existsSync: existsSync2, appendFileSync } = await import("fs");
1286
- writeFileSync2("docker-compose.yml", compose);
1287
- writeFileSync2(".env", envFile);
1288
- if (existsSync2(".gitignore")) {
1289
- const content = await import("fs").then((f) => f.readFileSync(".gitignore", "utf-8"));
1290
- if (!content.includes(".env")) {
1291
- appendFileSync(".gitignore", "\n# Secrets\n.env\n");
1292
- }
1293
- } else {
1294
- writeFileSync2(".gitignore", "# Secrets\n.env\nnode_modules/\n");
1295
- }
1296
- spinner.succeed("docker-compose.yml + .env generated");
1297
- console.log("");
1298
- console.log(chalk.green.bold(" Docker deployment ready!"));
1299
- console.log("");
1300
- console.log(` Run: ${chalk.cyan("docker compose up -d")}`);
1301
- console.log(` Dashboard: ${chalk.cyan("http://localhost:3000")}`);
1302
- console.log(chalk.dim(" Secrets stored in .env \u2014 do not commit to git"));
1303
- if (domain.customDomain) {
1304
- printCustomDomainInstructions(chalk, domain.customDomain, "docker");
1305
- }
1306
- return { url: "http://localhost:3000" };
1307
- }
1308
- if (deployTarget === "fly") {
1309
- const { generateFlyToml } = await import("./managed-T2RBYB2W.js");
1310
- const flyToml = generateFlyToml(`am-${company.subdomain}`, "iad");
1311
- const { writeFileSync: writeFileSync2 } = await import("fs");
1312
- writeFileSync2("fly.toml", flyToml);
1313
- spinner.succeed("fly.toml generated");
1314
- console.log("");
1315
- console.log(chalk.green.bold(" Fly.io deployment ready!"));
1316
- console.log("");
1317
- console.log(` 1. ${chalk.cyan("fly launch --copy-config")}`);
1318
- console.log(` 2. ${chalk.cyan(`fly secrets set DATABASE_URL="${database.connectionString}" JWT_SECRET="${jwtSecret}" AGENTICMAIL_VAULT_KEY="${vaultKey}"`)}`);
1319
- console.log(` 3. ${chalk.cyan("fly deploy")}`);
1320
- if (domain.customDomain) {
1321
- console.log(` 4. ${chalk.cyan(`fly certs add ${domain.customDomain}`)}`);
1322
- printCustomDomainInstructions(chalk, domain.customDomain, "fly", `am-${company.subdomain}.fly.dev`);
1323
- }
1324
- return {};
1325
- }
1326
- if (deployTarget === "railway") {
1327
- const { generateRailwayConfig } = await import("./managed-T2RBYB2W.js");
1328
- const railwayConfig = generateRailwayConfig();
1329
- const { writeFileSync: writeFileSync2 } = await import("fs");
1330
- writeFileSync2("railway.toml", railwayConfig);
1331
- spinner.succeed("railway.toml generated");
1332
- console.log("");
1333
- console.log(chalk.green.bold(" Railway deployment ready!"));
1334
- console.log("");
1335
- console.log(` 1. ${chalk.cyan("railway init")}`);
1336
- console.log(` 2. ${chalk.cyan("railway link")}`);
1337
- console.log(` 3. ${chalk.cyan("railway up")}`);
1338
- if (domain.customDomain) {
1339
- printCustomDomainInstructions(chalk, domain.customDomain, "railway");
1340
- }
1341
- return {};
1342
- }
1343
- spinner.start("Starting local server...");
1344
- const { createServer } = await import("./server-6NDO2S52.js");
1345
- const server = createServer({ port: 3e3, db, jwtSecret });
1346
- const handle = await server.start();
1347
- spinner.succeed("Server running");
1348
- console.log("");
1349
- console.log(chalk.green.bold(" AgenticMail Enterprise is running!"));
1350
- console.log("");
1351
- console.log(` ${chalk.bold("Dashboard:")} ${chalk.cyan("http://localhost:3000")}`);
1352
- console.log(` ${chalk.bold("API:")} ${chalk.cyan("http://localhost:3000/api")}`);
1353
- console.log(` ${chalk.bold("Admin:")} ${company.adminEmail}`);
1354
- console.log("");
1355
- console.log(chalk.dim(" Press Ctrl+C to stop"));
1356
- return { url: "http://localhost:3000", close: handle.close };
1357
- }
1358
- function printCustomDomainInstructions(chalk, domain, target, cnameTarget) {
1359
- console.log("");
1360
- console.log(chalk.bold(" Custom Domain DNS Setup"));
1361
- console.log(chalk.dim(` Route ${chalk.white(domain)} to your deployment.
1362
- `));
1363
- if (target === "cloud" && cnameTarget) {
1364
- console.log(chalk.bold(" Add this DNS record at your domain registrar:"));
1365
- console.log("");
1366
- console.log(` ${chalk.bold("Type:")} ${chalk.cyan("CNAME")}`);
1367
- console.log(` ${chalk.bold("Host:")} ${chalk.cyan(domain)}`);
1368
- console.log(` ${chalk.bold("Value:")} ${chalk.cyan(cnameTarget)}`);
1369
- } else if (target === "fly" && cnameTarget) {
1370
- console.log(chalk.bold(" Add this DNS record at your domain registrar:"));
1371
- console.log("");
1372
- console.log(` ${chalk.bold("Type:")} ${chalk.cyan("CNAME")}`);
1373
- console.log(` ${chalk.bold("Host:")} ${chalk.cyan(domain)}`);
1374
- console.log(` ${chalk.bold("Value:")} ${chalk.cyan(cnameTarget)}`);
1375
- console.log("");
1376
- console.log(chalk.dim(" Fly.io will automatically provision a TLS certificate."));
1377
- } else if (target === "railway") {
1378
- console.log(chalk.bold(" After deploying:"));
1379
- console.log("");
1380
- console.log(` 1. Open your Railway project dashboard`);
1381
- console.log(` 2. Go to ${chalk.bold("Settings")} \u2192 ${chalk.bold("Domains")}`);
1382
- console.log(` 3. Add ${chalk.cyan(domain)} as a custom domain`);
1383
- console.log(` 4. Railway will show you a ${chalk.bold("CNAME")} target \u2014 add it at your DNS provider`);
1384
- } else if (target === "docker") {
1385
- console.log(chalk.bold(" Configure your reverse proxy to route traffic:"));
1386
- console.log("");
1387
- console.log(` ${chalk.bold("Domain:")} ${chalk.cyan(domain)}`);
1388
- console.log(` ${chalk.bold("Target:")} ${chalk.cyan("localhost:3000")} ${chalk.dim("(or your Docker host IP)")}`);
1389
- console.log("");
1390
- console.log(chalk.dim(" Example with nginx:"));
1391
- console.log(chalk.dim(""));
1392
- console.log(chalk.dim(" server {"));
1393
- console.log(chalk.dim(` server_name ${domain};`));
1394
- console.log(chalk.dim(" location / {"));
1395
- console.log(chalk.dim(" proxy_pass http://localhost:3000;"));
1396
- console.log(chalk.dim(" proxy_set_header Host $host;"));
1397
- console.log(chalk.dim(" proxy_set_header X-Real-IP $remote_addr;"));
1398
- console.log(chalk.dim(" }"));
1399
- console.log(chalk.dim(" }"));
1400
- console.log("");
1401
- console.log(chalk.dim(" Then add a DNS A record pointing to your server IP,"));
1402
- console.log(chalk.dim(" or a CNAME if you have an existing hostname."));
1403
- }
1404
- console.log("");
1405
- console.log(chalk.dim(" Note: This CNAME/A record routes traffic. A separate TXT record"));
1406
- console.log(chalk.dim(" for domain verification was (or will be) configured in Step 5."));
1407
- console.log("");
1408
- }
1409
-
1410
- // src/setup/index.ts
1411
- var DB_DRIVER_MAP = {
1412
- postgres: ["pg"],
1413
- supabase: ["pg"],
1414
- neon: ["pg"],
1415
- cockroachdb: ["pg"],
1416
- mysql: ["mysql2"],
1417
- planetscale: ["mysql2"],
1418
- mongodb: ["mongodb"],
1419
- sqlite: ["better-sqlite3"],
1420
- turso: ["@libsql/client"],
1421
- dynamodb: ["@aws-sdk/client-dynamodb", "@aws-sdk/lib-dynamodb"]
1422
- };
1423
- async function ensureDbDriver(dbType, ora, chalk) {
1424
- const packages = DB_DRIVER_MAP[dbType];
1425
- if (!packages?.length) return;
1426
- const missing = [];
1427
- for (const pkg of packages) {
1428
- let found = false;
1429
- try {
1430
- await import(pkg);
1431
- found = true;
1432
- } catch {
1433
- }
1434
- if (!found) {
1435
- try {
1436
- const req = createRequire(join2(process.cwd(), "index.js"));
1437
- req.resolve(pkg);
1438
- found = true;
1439
- } catch {
1440
- }
1441
- }
1442
- if (!found) {
1443
- try {
1444
- const globalPrefix = execSync2("npm prefix -g", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
1445
- const req = createRequire(join2(globalPrefix, "lib", "node_modules", ".package-lock.json"));
1446
- req.resolve(pkg);
1447
- found = true;
1448
- } catch {
1449
- }
1450
- }
1451
- if (!found) missing.push(pkg);
1452
- }
1453
- if (!missing.length) return;
1454
- const spinner = ora(`Installing database driver: ${missing.join(", ")}...`).start();
1455
- try {
1456
- execSync2(`npm install --no-save ${missing.join(" ")}`, {
1457
- stdio: "pipe",
1458
- timeout: 12e4,
1459
- cwd: process.cwd()
1460
- });
1461
- spinner.succeed(`Database driver installed: ${missing.join(", ")}`);
1462
- } catch (err) {
1463
- spinner.fail(`Failed to install ${missing.join(", ")}`);
1464
- console.error(chalk.red(`
1465
- Run manually: npm install ${missing.join(" ")}
1466
- `));
1467
- process.exit(1);
1468
- }
1469
- }
1470
- async function runSetupWizard() {
1471
- const { default: inquirer } = await import("inquirer");
1472
- const { default: ora } = await import("ora");
1473
- const { default: chalk } = await import("chalk");
1474
- console.log("");
1475
- console.log(chalk.bold(" AgenticMail Enterprise"));
1476
- console.log(chalk.dim(" AI Agent Identity & Email for Organizations"));
1477
- console.log("");
1478
- console.log(chalk.dim(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
1479
- console.log("");
1480
- const company = await promptCompanyInfo(inquirer, chalk);
1481
- const database = await promptDatabase(inquirer, chalk);
1482
- const deploymentResult = await promptDeployment(inquirer, chalk);
1483
- const deployTarget = deploymentResult.target;
1484
- const domain = deploymentResult.tunnel ? { customDomain: deploymentResult.tunnel.domain } : deploymentResult.cloud ? { customDomain: deploymentResult.cloud.fqdn } : await promptDomain(inquirer, chalk, deployTarget);
1485
- const registration = deploymentResult.tunnel || deploymentResult.cloud ? { registered: true, verificationStatus: "verified" } : await promptRegistration(
1486
- inquirer,
1487
- chalk,
1488
- ora,
1489
- domain.customDomain,
1490
- company.companyName,
1491
- company.adminEmail
1492
- );
1493
- await ensureDbDriver(database.type, ora, chalk);
1494
- console.log("");
1495
- console.log(chalk.dim(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
1496
- console.log("");
1497
- const result = await provision(
1498
- { company, database, deployTarget, domain, registration, tunnel: deploymentResult.tunnel, cloud: deploymentResult.cloud },
1499
- ora,
1500
- chalk
1501
- );
1502
- if (!result.success) {
1503
- console.error("");
1504
- console.error(chalk.red(` Setup failed: ${result.error}`));
1505
- console.error(chalk.dim(" Check your database connection and try again."));
1506
- process.exit(1);
1507
- }
1508
- console.log("");
1509
- }
1510
-
1511
- export {
1512
- promptCompanyInfo,
1513
- promptDatabase,
1514
- promptDeployment,
1515
- promptDomain,
1516
- promptRegistration,
1517
- provision,
1518
- runSetupWizard
1519
- };