hyperclaw 5.2.0 → 5.2.2

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 (511) hide show
  1. package/README.md +227 -3
  2. package/dist/a2ui-protocol-A2xow5Ch.js +75 -0
  3. package/dist/a2ui-protocol-dTomAnFE.js +75 -0
  4. package/dist/agents-routing-95_s2yea.js +6 -0
  5. package/dist/agents-routing-Bz3SstlK.js +398 -0
  6. package/dist/agents-routing-DHDK2axt.js +6 -0
  7. package/dist/agents-routing-DRMS8Ol-.js +6 -0
  8. package/dist/agents-routing-biXULPch.js +398 -0
  9. package/dist/agents-routing-iQmIOe3k.js +398 -0
  10. package/dist/api-key-validation-BeQ2MZAT.js +64 -0
  11. package/dist/api-key-validation-C2WQk1oM.js +64 -0
  12. package/dist/api-keys-guide-2cD5Rf-K.js +149 -0
  13. package/dist/api-keys-guide-BdT2lfX6.js +149 -0
  14. package/dist/api-keys-guide-BwCIj8qd.js +149 -0
  15. package/dist/audit-1Anq45mH.js +441 -0
  16. package/dist/audit-BAVTInWP.js +441 -0
  17. package/dist/audit-CV0gLGaL.js +444 -0
  18. package/dist/audit-Dnt0XgZD.js +441 -0
  19. package/dist/audit-DqNGdIKU.js +441 -0
  20. package/dist/bounty-tools-Cx7BXUfz.js +211 -0
  21. package/dist/bounty-tools-DWvW3yc-.js +211 -0
  22. package/dist/bounty-tools-FI7DHmsS.js +211 -0
  23. package/dist/bounty-tools-cjmA3Hgk.js +211 -0
  24. package/dist/browser-tools-BGPBCApQ.js +5 -0
  25. package/dist/browser-tools-Btu_vB2d.js +179 -0
  26. package/dist/browser-tools-DF2nQ1hi.js +5 -0
  27. package/dist/browser-tools-DYx4p13A.js +179 -0
  28. package/dist/chat-4ZistSKP.js +310 -0
  29. package/dist/chat-BqiMMQc4.js +324 -0
  30. package/dist/chat-BxxYzPaz.js +324 -0
  31. package/dist/chat-C0W8lwhh.js +324 -0
  32. package/dist/chat-CKBxDWAQ.js +324 -0
  33. package/dist/chat-CkCcCkVG.js +324 -0
  34. package/dist/chat-DCOKsydK.js +310 -0
  35. package/dist/chat-DZcZ1Uli.js +310 -0
  36. package/dist/chat-DiIra4_i.js +324 -0
  37. package/dist/chat-R_NuOa1v.js +324 -0
  38. package/dist/claw-tasks-CIkuuhga.js +80 -0
  39. package/dist/claw-tasks-CquRilLP.js +80 -0
  40. package/dist/claw-tasks-xXtZpeY0.js +80 -0
  41. package/dist/config-BEz4yNRx.js +261 -0
  42. package/dist/config-Br73VMLb.js +261 -0
  43. package/dist/config-CXqmvq_H.js +7 -0
  44. package/dist/config-D5vF0kvV.js +261 -0
  45. package/dist/config-D_6MxFk3.js +7 -0
  46. package/dist/config-b2HmFrBr.js +7 -0
  47. package/dist/connector-1H0OW1h8.js +419 -0
  48. package/dist/connector-1qpQ5L-T.js +173 -0
  49. package/dist/connector-2OVpYt0c.js +213 -0
  50. package/dist/connector-8cFkE3X4.js +552 -0
  51. package/dist/connector-B2bZD1id.js +181 -0
  52. package/dist/connector-B3W7quzD.js +568 -0
  53. package/dist/connector-B4FWhOzd.js +189 -0
  54. package/dist/connector-B5fqvoZL.js +239 -0
  55. package/dist/connector-BA8ZbhPt.js +162 -0
  56. package/dist/connector-BFl0XIwB.js +182 -0
  57. package/dist/connector-BIGRhSuN.js +419 -0
  58. package/dist/connector-BK0qVbvh.js +498 -0
  59. package/dist/connector-BMtA4KSF.js +194 -0
  60. package/dist/connector-BPIrifW-.js +218 -0
  61. package/dist/connector-BRNU-rJ4.js +225 -0
  62. package/dist/connector-BS7lvyLd.js +213 -0
  63. package/dist/connector-BZ_-UPUL.js +305 -0
  64. package/dist/connector-Bd0NZ5bT.js +189 -0
  65. package/dist/connector-BjsPwu-Y.js +531 -0
  66. package/dist/connector-BnSsjz1D.js +167 -0
  67. package/dist/connector-BrogAqVQ.js +239 -0
  68. package/dist/connector-BsVTG3U3.js +181 -0
  69. package/dist/connector-By9pLJgR.js +340 -0
  70. package/dist/connector-C7c1ASzT.js +192 -0
  71. package/dist/connector-CIj28thK.js +182 -0
  72. package/dist/connector-CJkuYNd1.js +280 -0
  73. package/dist/connector-CPcUmIHz.js +552 -0
  74. package/dist/connector-CUlP4He3.js +194 -0
  75. package/dist/connector-CZg2I8Tn.js +350 -0
  76. package/dist/connector-C_NtpthL.js +498 -0
  77. package/dist/connector-CddDB9IK.js +192 -0
  78. package/dist/connector-ChQMspky.js +167 -0
  79. package/dist/connector-ClHFpI56.js +425 -0
  80. package/dist/connector-CmhUVhMT.js +531 -0
  81. package/dist/connector-CnX7lwCt.js +425 -0
  82. package/dist/connector-D36oGwnK.js +162 -0
  83. package/dist/connector-DDJ7Nxkq.js +286 -0
  84. package/dist/connector-DDn2QDuf.js +167 -0
  85. package/dist/connector-DO_bzgJn.js +167 -0
  86. package/dist/connector-DVcRo21Y.js +568 -0
  87. package/dist/connector-DhWs2anT.js +189 -0
  88. package/dist/connector-DsY1IXMz.js +508 -0
  89. package/dist/connector-DwRF3CQg.js +218 -0
  90. package/dist/connector-HG61cV9h.js +340 -0
  91. package/dist/connector-HR28FwA5.js +181 -0
  92. package/dist/connector-K0QGRYh5.js +85 -0
  93. package/dist/connector-NliR7NZZ.js +508 -0
  94. package/dist/connector-VolY_hP4.js +350 -0
  95. package/dist/connector-Wjx9ih70.js +286 -0
  96. package/dist/connector-dfqk7NYD.js +181 -0
  97. package/dist/connector-e0W4Mpmq.js +189 -0
  98. package/dist/connector-eK6_phVW.js +280 -0
  99. package/dist/connector-l7UmCYaL.js +225 -0
  100. package/dist/connector-n2YnOJYZ.js +305 -0
  101. package/dist/connector-orobFcqE.js +531 -0
  102. package/dist/connector-r1SRYSqX.js +173 -0
  103. package/dist/connector-tZgn5_Fk.js +85 -0
  104. package/dist/connector-wm4Oe1DK.js +181 -0
  105. package/dist/cost-tracker-DHTv6zpR.js +103 -0
  106. package/dist/cost-tracker-DJ1tiKcx.js +103 -0
  107. package/dist/cost-tracker-jbK_AoIV.js +103 -0
  108. package/dist/credentials-store-C0R-pQM7.js +5 -0
  109. package/dist/credentials-store-C9HwQSY2.js +5 -0
  110. package/dist/credentials-store-D5Xw3F75.js +89 -0
  111. package/dist/credentials-store-DIPxVk51.js +86 -0
  112. package/dist/credentials-store-DU2cVTiY.js +7 -0
  113. package/dist/credentials-store-Djqi3oXC.js +5 -0
  114. package/dist/credentials-store-HwLJ3GS2.js +87 -0
  115. package/dist/credentials-store-z16XvFZ2.js +86 -0
  116. package/dist/cron-tasks-4my0PJce.js +85 -0
  117. package/dist/cron-tasks-CJkI0lo3.js +82 -0
  118. package/dist/cron-tasks-DN1YjYhK.js +82 -0
  119. package/dist/cron-tasks-DuNdK89e.js +82 -0
  120. package/dist/daemon-3xj3FVuw.js +5 -0
  121. package/dist/daemon-3zd_nupj.js +333 -0
  122. package/dist/daemon-B9-h7ryw.js +7 -0
  123. package/dist/daemon-BLC4AL9L.js +401 -0
  124. package/dist/daemon-BR1uU7jH.js +333 -0
  125. package/dist/daemon-BRdtCOoC.js +7 -0
  126. package/dist/daemon-BnmNBHY5.js +384 -0
  127. package/dist/daemon-BwspQtiu.js +7 -0
  128. package/dist/daemon-Bx5HTGjk.js +404 -0
  129. package/dist/daemon-CCxpXxSb.js +7 -0
  130. package/dist/daemon-CEUxN3SQ.js +7 -0
  131. package/dist/daemon-CHk9_ezz.js +403 -0
  132. package/dist/daemon-CgrsZ0d9.js +320 -0
  133. package/dist/daemon-Cy7iD9au.js +7 -0
  134. package/dist/daemon-DCm9RCEz.js +401 -0
  135. package/dist/daemon-DNzuDyu8.js +7 -0
  136. package/dist/daemon-DWFWCLvh.js +7 -0
  137. package/dist/daemon-DgBZaFyi.js +355 -0
  138. package/dist/daemon-Dsyjad7g.js +7 -0
  139. package/dist/daemon-DwxPYrb6.js +404 -0
  140. package/dist/daemon-DxoPIGQG.js +333 -0
  141. package/dist/daemon-MXsEPeVa.js +7 -0
  142. package/dist/daemon-rpJ-J0bv.js +403 -0
  143. package/dist/daemon-sZVjFUoX.js +7 -0
  144. package/dist/delivery-8fo4GZ-j.js +95 -0
  145. package/dist/delivery-CkxNZIsF.js +95 -0
  146. package/dist/delivery-CtbHkJbB.js +95 -0
  147. package/dist/delivery-D1z3f3KW.js +4 -0
  148. package/dist/delivery-DKGpk5M4.js +4 -0
  149. package/dist/delivery-DReKOHyM.js +95 -0
  150. package/dist/delivery-Ddn-VajP.js +4 -0
  151. package/dist/delivery-DsoxcD2z.js +4 -0
  152. package/dist/destructive-gate-CEn4BsTd.js +101 -0
  153. package/dist/destructive-gate-CgCqfKuT.js +101 -0
  154. package/dist/destructive-gate-DcEpMEqP.js +101 -0
  155. package/dist/developer-keys-7rQ8M4Qo.js +127 -0
  156. package/dist/developer-keys-BeUpyenR.js +8 -0
  157. package/dist/developer-keys-CSmzA-dl.js +127 -0
  158. package/dist/developer-keys-KFGbGuZj.js +8 -0
  159. package/dist/device-auth-store-BDhzxuPc.js +5 -0
  160. package/dist/device-auth-store-Cjyn2XeY.js +86 -0
  161. package/dist/device-auth-store-DgSabRGa.js +7 -0
  162. package/dist/device-auth-store-LKgpU74c.js +88 -0
  163. package/dist/device-auth-store-UlkrF-9_.js +5 -0
  164. package/dist/device-auth-store-yvGLuYAl.js +86 -0
  165. package/dist/doctor-BcfmNAGV.js +233 -0
  166. package/dist/doctor-CEP3UQjn.js +227 -0
  167. package/dist/doctor-CmJh0JLr.js +6 -0
  168. package/dist/doctor-CtDvddSn.js +231 -0
  169. package/dist/doctor-DPoCaXsd.js +227 -0
  170. package/dist/doctor-DPvY68XB.js +6 -0
  171. package/dist/doctor-G6EMPukm.js +6 -0
  172. package/dist/doctor-tL9TXt9y.js +6 -0
  173. package/dist/engine-1fLMFUn2.js +7 -0
  174. package/dist/engine-7lSiOc0W.js +323 -0
  175. package/dist/engine-B83pxJM4.js +318 -0
  176. package/dist/engine-B8hxtYpN.js +323 -0
  177. package/dist/engine-BXqijc79.js +7 -0
  178. package/dist/engine-BfQ-vNqE.js +321 -0
  179. package/dist/engine-BlpKw8D4.js +7 -0
  180. package/dist/engine-BmN7L0jl.js +7 -0
  181. package/dist/engine-CRagwas6.js +321 -0
  182. package/dist/engine-CppTnNbG.js +7 -0
  183. package/dist/engine-CwAfDQbD.js +7 -0
  184. package/dist/engine-D5kY4hMJ.js +7 -0
  185. package/dist/engine-DJSfl_Hc.js +323 -0
  186. package/dist/engine-DQcMDIbU.js +305 -0
  187. package/dist/engine-W1I8kkgV.js +305 -0
  188. package/dist/engine-mVrq_pfQ.js +7 -0
  189. package/dist/env-resolve-BeamD7l5.js +10 -0
  190. package/dist/env-resolve-C0otwkgN.js +10 -0
  191. package/dist/env-resolve-CC_po9t5.js +10 -0
  192. package/dist/env-resolve-COjiKYD8.js +147 -0
  193. package/dist/env-resolve-CYiFHLAi.js +145 -0
  194. package/dist/env-resolve-ClZcv5-B.js +145 -0
  195. package/dist/env-resolve-DS92g2fk.js +151 -0
  196. package/dist/env-resolve-DkBUmcI3.js +10 -0
  197. package/dist/extraction-tools-6PREYSAK.js +5 -0
  198. package/dist/extraction-tools-B8F3nsLR.js +5 -0
  199. package/dist/extraction-tools-BX5HGgko.js +91 -0
  200. package/dist/extraction-tools-Co11UJdZ.js +91 -0
  201. package/dist/form_data-DDfyO9B0.js +8657 -0
  202. package/dist/form_data-DgWnyuDn.js +8657 -0
  203. package/dist/gateway-BfHcLG6d.js +194 -0
  204. package/dist/gateway-CzI8dnlS.js +196 -0
  205. package/dist/gateway-DNv10FFg.js +194 -0
  206. package/dist/gateway-DRh5v1KI.js +4 -0
  207. package/dist/gateway-DroPtqyM.js +6 -0
  208. package/dist/gateway-DyWwV0Nu.js +4 -0
  209. package/dist/gmail-watch-setup-BV4r_lgb.js +40 -0
  210. package/dist/gmail-watch-setup-CW_5D9g-.js +40 -0
  211. package/dist/gmail-watch-setup-xG9GkPwr.js +42 -0
  212. package/dist/health-CBy1PfzC.js +152 -0
  213. package/dist/health-Cq_yE5Ln.js +6 -0
  214. package/dist/heartbeat-engine-7I0dZeea.js +83 -0
  215. package/dist/heartbeat-engine-BZUNOanp.js +84 -0
  216. package/dist/heartbeat-engine-DNm8ggAs.js +83 -0
  217. package/dist/heartbeat-engine-tgK7xXmt.js +83 -0
  218. package/dist/hub-CI4qcd1b.js +515 -0
  219. package/dist/hub-CNQaC4JI.js +515 -0
  220. package/dist/hub-Co1SbxLs.js +6 -0
  221. package/dist/hub-eUh89obm.js +6 -0
  222. package/dist/hyperclawbot-Bkncybig.js +508 -0
  223. package/dist/hyperclawbot-C37Unss3.js +505 -0
  224. package/dist/hyperclawbot-CFHXZr12.js +505 -0
  225. package/dist/hyperclawbot-DGou0MZ6.js +508 -0
  226. package/dist/hyperclawbot-DnPIyjox.js +508 -0
  227. package/dist/hyperclawbot-GYFaTEgC.js +505 -0
  228. package/dist/hyperclawbot-mcLnyJyM.js +505 -0
  229. package/dist/hyperclawbot-xcastgTV.js +508 -0
  230. package/dist/hyperclawbot-y0i_joQK.js +505 -0
  231. package/dist/inference-BvmMO9dq.js +8 -0
  232. package/dist/inference-C2HOfRf8.js +2848 -0
  233. package/dist/inference-CKvR5Ik5.js +2841 -0
  234. package/dist/inference-DVVmhQn5.js +2841 -0
  235. package/dist/inference-DoM_iai-.js +2848 -0
  236. package/dist/inference-DwgXrvBb.js +6 -0
  237. package/dist/inference-Go1G6tnF.js +8 -0
  238. package/dist/inference-_ptQe0oG.js +2841 -0
  239. package/dist/inference-gK62s15E.js +6 -0
  240. package/dist/inference-lLDvSTR9.js +6 -0
  241. package/dist/knowledge-graph-4SxFnwEm.js +131 -0
  242. package/dist/knowledge-graph-BsH-HoUJ.js +131 -0
  243. package/dist/knowledge-graph-BxrAiV2B.js +134 -0
  244. package/dist/knowledge-graph-DCa91Nz5.js +131 -0
  245. package/dist/loader-7fz2fb92.js +400 -0
  246. package/dist/loader-B2jZXMBu.js +6 -0
  247. package/dist/loader-CbS0tIrR.js +4 -0
  248. package/dist/loader-Ckvv7vHF.js +410 -0
  249. package/dist/loader-CwOXDhFQ.js +400 -0
  250. package/dist/loader-DpEOgWXZ.js +4 -0
  251. package/dist/loader-DpYgmaul.js +4 -0
  252. package/dist/loader-DtyQP7wL.js +400 -0
  253. package/dist/logger-B3AqfQWG.js +84 -0
  254. package/dist/logger-B_q8yqmA.js +84 -0
  255. package/dist/logger-BxJklsDv.js +84 -0
  256. package/dist/logger-ry2oCfdf.js +86 -0
  257. package/dist/manager-9zwhTeQ5.js +233 -0
  258. package/dist/manager-B1RbCW6C.js +31 -0
  259. package/dist/manager-B90HEHxe.js +6 -0
  260. package/dist/manager-B94UWcTs.js +233 -0
  261. package/dist/manager-BDvL_oPs.js +4 -0
  262. package/dist/manager-BEatAtIB.js +31 -0
  263. package/dist/manager-BQf9drst.js +120 -0
  264. package/dist/manager-Bau1mIqb.js +6 -0
  265. package/dist/manager-BkqHak_e.js +247 -0
  266. package/dist/manager-BoFdZm-l.js +233 -0
  267. package/dist/manager-C2bq0AXc.js +233 -0
  268. package/dist/manager-CBe3W3eG.js +117 -0
  269. package/dist/manager-CoHr8_eJ.js +117 -0
  270. package/dist/manager-CuS13QUO.js +6 -0
  271. package/dist/manager-DO0pK2OI.js +117 -0
  272. package/dist/manager-DVetfBCH.js +6 -0
  273. package/dist/manager-Jd0qSzVe.js +35 -0
  274. package/dist/manager-TxFgaHT9.js +31 -0
  275. package/dist/manager-Yo6ZAofG.js +250 -0
  276. package/dist/mcp-B_WJiTZz.js +139 -0
  277. package/dist/mcp-DVhPLprc.js +139 -0
  278. package/dist/mcp-GWnLTVi-.js +142 -0
  279. package/dist/mcp-loader-B6xz7ftt.js +94 -0
  280. package/dist/mcp-loader-BLanJREp.js +94 -0
  281. package/dist/mcp-loader-Bx7FFxAU.js +94 -0
  282. package/dist/mcp-loader-CecsT-3O.js +93 -0
  283. package/dist/mcp-loader-Cr0LRQHE.js +93 -0
  284. package/dist/mcp-loader-D0rbtV3G.js +93 -0
  285. package/dist/memory-B47nvgOq.js +271 -0
  286. package/dist/memory-D-Py-cz5.js +273 -0
  287. package/dist/memory-D991eoj7.js +6 -0
  288. package/dist/memory-DoQoaHjo.js +4 -0
  289. package/dist/memory-auto-5aBZQJQY.js +5 -0
  290. package/dist/memory-auto-BTeOoLsb.js +306 -0
  291. package/dist/memory-auto-BvjfaflZ.js +5 -0
  292. package/dist/memory-auto-CSUt3aas.js +306 -0
  293. package/dist/memory-auto-CfpACu6s.js +306 -0
  294. package/dist/memory-auto-DI9Xpd-x.js +306 -0
  295. package/dist/memory-auto-D_mPVYqI.js +5 -0
  296. package/dist/memory-auto-PmKetZuo.js +5 -0
  297. package/dist/memory-auto-_Jv-Diw_.js +306 -0
  298. package/dist/memory-auto-rLBheyC0.js +5 -0
  299. package/dist/memory-integration-UFc6CdRA.js +91 -0
  300. package/dist/memory-integration-_NOy60Fj.js +91 -0
  301. package/dist/memory-integration-nbQ8esDu.js +91 -0
  302. package/dist/moltbook-B4znBD46.js +81 -0
  303. package/dist/moltbook-CGtA7Lb3.js +81 -0
  304. package/dist/moltbook-EZOfIwcN.js +81 -0
  305. package/dist/node-BvA5_2f_.js +222 -0
  306. package/dist/node-CRaZw_av.js +225 -0
  307. package/dist/node-CSOPY84m.js +222 -0
  308. package/dist/node-FPkFXYdU.js +225 -0
  309. package/dist/nodes-registry--DkZbn41.js +52 -0
  310. package/dist/nodes-registry-DYEH1aWn.js +52 -0
  311. package/dist/nodes-registry-jK7T0THg.js +52 -0
  312. package/dist/oauth-flow-B3S4T_SJ.js +147 -0
  313. package/dist/oauth-flow-CuQHP_RD.js +150 -0
  314. package/dist/oauth-flow-D_iqT6nr.js +150 -0
  315. package/dist/oauth-flow-Du2N6B2V.js +150 -0
  316. package/dist/oauth-provider-B2RBpiXg.js +111 -0
  317. package/dist/oauth-provider-C1qk9SI-.js +110 -0
  318. package/dist/oauth-provider-CDOMIZgF.js +110 -0
  319. package/dist/observability-4CyDqBWi.js +89 -0
  320. package/dist/observability-BfhV3r9r.js +89 -0
  321. package/dist/observability-DAnU8Ung.js +89 -0
  322. package/dist/onboard-3SoScSbC.js +11 -0
  323. package/dist/onboard-BAhuTUMO.js +4240 -0
  324. package/dist/onboard-BHKBzytX.js +13 -0
  325. package/dist/onboard-BVYo6E_l.js +3865 -0
  326. package/dist/onboard-Bf3ht6ct.js +11 -0
  327. package/dist/onboard-Bmpa_pxc.js +3865 -0
  328. package/dist/onboard-BwFFnEDj.js +13 -0
  329. package/dist/onboard-C-0A7RKN.js +4211 -0
  330. package/dist/onboard-CCuETEUr.js +3865 -0
  331. package/dist/onboard-CDi3B996.js +13 -0
  332. package/dist/onboard-CcXqOCHa.js +3862 -0
  333. package/dist/onboard-Cw85LmyN.js +13 -0
  334. package/dist/onboard-DU3acWAq.js +13 -0
  335. package/dist/onboard-DVEFIFRj.js +11 -0
  336. package/dist/onboard-DW8b3EUP.js +4250 -0
  337. package/dist/onboard-DfYWM7yN.js +13 -0
  338. package/dist/onboard-DiDTuD7m.js +13 -0
  339. package/dist/onboard-DqamkA0I.js +11 -0
  340. package/dist/onboard-DtDFU4lV.js +3865 -0
  341. package/dist/onboard-IdhgSexF.js +11 -0
  342. package/dist/onboard-Qh-qibLR.js +3861 -0
  343. package/dist/onboard-T54jLovz.js +13 -0
  344. package/dist/onboard-nQerZcpc.js +3862 -0
  345. package/dist/onboard-qXuXl5An.js +4250 -0
  346. package/dist/onboard-r2hLYfsL.js +3865 -0
  347. package/dist/onboard-xsSdyO6Y.js +3865 -0
  348. package/dist/onboard-yACJiQ6A.js +4215 -0
  349. package/dist/onboard-z1K8FTgh.js +13 -0
  350. package/dist/orchestrator-BIKrbOtx.js +6 -0
  351. package/dist/orchestrator-C71UI_0E.js +189 -0
  352. package/dist/orchestrator-C9I6EVhh.js +189 -0
  353. package/dist/orchestrator-CC6vuL6m.js +6 -0
  354. package/dist/orchestrator-CExmcac2.js +189 -0
  355. package/dist/orchestrator-CQm9v71d.js +6 -0
  356. package/dist/orchestrator-CSZnojZo.js +189 -0
  357. package/dist/orchestrator-Cc-gXExz.js +189 -0
  358. package/dist/orchestrator-CxySH0n5.js +6 -0
  359. package/dist/orchestrator-Cybvh-J0.js +189 -0
  360. package/dist/orchestrator-D-9pExNB.js +189 -0
  361. package/dist/orchestrator-DG-RjZIu.js +6 -0
  362. package/dist/orchestrator-DvEjhiJR.js +6 -0
  363. package/dist/orchestrator-FFpXJwSV.js +189 -0
  364. package/dist/orchestrator-f6IjivCr.js +6 -0
  365. package/dist/orchestrator-mPfwBFvX.js +6 -0
  366. package/dist/osint-BIGH02i8.js +277 -0
  367. package/dist/osint-Cc2Ju-o4.js +277 -0
  368. package/dist/osint-Cg3-CYHx.js +278 -0
  369. package/dist/pairing-BRPzVXzQ.js +198 -0
  370. package/dist/pairing-Cm78Tsdx.js +4 -0
  371. package/dist/pairing-D4sA3-Ha.js +6 -0
  372. package/dist/pairing-ouc_v-OX.js +196 -0
  373. package/dist/pc-access-BZvlAXYN.js +819 -0
  374. package/dist/pc-access-CziyndiO.js +8 -0
  375. package/dist/pc-access-D5k6dAfU.js +819 -0
  376. package/dist/pc-access-DoPSPiAK.js +8 -0
  377. package/dist/pending-approval-BaKZ0b_s.js +22 -0
  378. package/dist/pending-approval-CBVZcFJn.js +22 -0
  379. package/dist/pending-approval-DiZ96D8v.js +22 -0
  380. package/dist/providers-CFQC39vg.js +5 -0
  381. package/dist/providers-DP8T0QCR.js +1089 -0
  382. package/dist/reminders-store-BSIw5Y5z.js +58 -0
  383. package/dist/reminders-store-Bus52SjO.js +58 -0
  384. package/dist/renderer-CmMjrkqN.js +225 -0
  385. package/dist/renderer-_Y9mEqMM.js +225 -0
  386. package/dist/renderer-h3ar94cf.js +228 -0
  387. package/dist/rules-D3GcY_lt.js +103 -0
  388. package/dist/rules-DFoset7W.js +103 -0
  389. package/dist/rules-eJw9i4RF.js +106 -0
  390. package/dist/run-main.js +461 -333
  391. package/dist/runner-C-syOqBr.js +1273 -0
  392. package/dist/runner-C73am--A.js +1273 -0
  393. package/dist/runner-DKLq9jhv.js +1273 -0
  394. package/dist/runner-Im-aCXhh.js +1273 -0
  395. package/dist/runner-NvAzKXbv.js +1273 -0
  396. package/dist/security-2DPBzs5F.js +4 -0
  397. package/dist/security-BhhX8wJx.js +73 -0
  398. package/dist/server-7tmTtdPU.js +4 -0
  399. package/dist/server-A38RPbRE.js +1291 -0
  400. package/dist/server-B0k_pCt5.js +4 -0
  401. package/dist/server-BErPWJZ5.js +4 -0
  402. package/dist/server-BKo-zifC.js +4 -0
  403. package/dist/server-Bav63Eqx.js +4 -0
  404. package/dist/server-BbWQWOH4.js +4 -0
  405. package/dist/server-BfHtA0Y2.js +1278 -0
  406. package/dist/server-BiYaxlFV.js +1287 -0
  407. package/dist/server-C6htB4FI.js +4 -0
  408. package/dist/server-CB7cjcj4.js +1278 -0
  409. package/dist/server-CNiOi5dN.js +1285 -0
  410. package/dist/server-CSC4npaT.js +1285 -0
  411. package/dist/server-CZfP2Poz.js +1278 -0
  412. package/dist/server-C_YVts3e.js +4 -0
  413. package/dist/server-CbQl0M21.js +1278 -0
  414. package/dist/server-Cj45rxn-.js +1292 -0
  415. package/dist/server-Ct7Fl3SE.js +1285 -0
  416. package/dist/server-D9q-3mLF.js +1292 -0
  417. package/dist/server-DRc26z9e.js +4 -0
  418. package/dist/server-DT7JjjVD.js +4 -0
  419. package/dist/server-DacRJyZn.js +4 -0
  420. package/dist/server-PCtHMXe2.js +1292 -0
  421. package/dist/server-wXCH_TCU.js +4 -0
  422. package/dist/session-store-7ZPOoB81.js +5 -0
  423. package/dist/session-store-BOa2y_EQ.js +5 -0
  424. package/dist/session-store-BYEr8j52.js +139 -0
  425. package/dist/session-store-Bx7lBD_a.js +141 -0
  426. package/dist/session-store-C13h7I2r.js +136 -0
  427. package/dist/session-store-CUHgJ0Xr.js +5 -0
  428. package/dist/session-store-cbtK6hx9.js +136 -0
  429. package/dist/session-store-eecMioKI.js +5 -0
  430. package/dist/sessions-tools-B5_ow-s7.js +5 -0
  431. package/dist/sessions-tools-CG2mvJo6.js +95 -0
  432. package/dist/sessions-tools-DVSejkNU.js +95 -0
  433. package/dist/sessions-tools-fOL1N3Zu.js +5 -0
  434. package/dist/skill-loader-99egKAGN.js +160 -0
  435. package/dist/skill-loader-Bl6pYxNN.js +160 -0
  436. package/dist/skill-loader-D4D5kfDu.js +7 -0
  437. package/dist/skill-loader-DwbmjEDa.js +7 -0
  438. package/dist/skill-runtime-1CrUOOGv.js +5 -0
  439. package/dist/skill-runtime-B-2O7Vgb.js +102 -0
  440. package/dist/skill-runtime-B7PutgyZ.js +5 -0
  441. package/dist/skill-runtime-BGNtPD_L.js +102 -0
  442. package/dist/skill-runtime-BUhMkMzO.js +5 -0
  443. package/dist/skill-runtime-Bv7fCCx8.js +102 -0
  444. package/dist/skill-runtime-Bx2HHcta.js +102 -0
  445. package/dist/skill-runtime-C6HVvnmN.js +5 -0
  446. package/dist/skill-runtime-CtSykP3r.js +102 -0
  447. package/dist/skill-runtime-DUAt8JM_.js +5 -0
  448. package/dist/skill-runtime-DZ6uJXGW.js +102 -0
  449. package/dist/skill-runtime-DaLnq_Jm.js +5 -0
  450. package/dist/skill-runtime-DpDbjL7y.js +102 -0
  451. package/dist/skill-runtime-acmnZSq7.js +102 -0
  452. package/dist/skill-runtime-dzuLMVSw.js +5 -0
  453. package/dist/skill-runtime-wiVnzSoJ.js +5 -0
  454. package/dist/src-B5lCcPXX.js +63 -0
  455. package/dist/src-B7Kxqi35.js +20 -0
  456. package/dist/src-B8DEmVd6.js +458 -0
  457. package/dist/src-BqbwzQQj.js +63 -0
  458. package/dist/src-C63ECu1t.js +63 -0
  459. package/dist/src-C65-5rOW.js +458 -0
  460. package/dist/src-CbTAVbeI.js +20 -0
  461. package/dist/src-Cmnclt47.js +63 -0
  462. package/dist/src-D0kptBSa.js +458 -0
  463. package/dist/src-DZtpIvWJ.js +63 -0
  464. package/dist/src-DjzS20TD.js +63 -0
  465. package/dist/src-DmPjS2Z4.js +458 -0
  466. package/dist/src-DmbIgW0O.js +63 -0
  467. package/dist/src-DsaXFru7.js +63 -0
  468. package/dist/src-Dt0TXI8r.js +458 -0
  469. package/dist/src-PPagVWuK.js +63 -0
  470. package/dist/src-rktqvEBJ.js +458 -0
  471. package/dist/src-tI8EOp6-.js +458 -0
  472. package/dist/src-zUHOCQgl.js +458 -0
  473. package/dist/src-zWhGmJSN.js +458 -0
  474. package/dist/sub-agent-tools-9k60L5mn.js +39 -0
  475. package/dist/sub-agent-tools-BBJf8oPD.js +39 -0
  476. package/dist/sub-agent-tools-BVCARpnF.js +39 -0
  477. package/dist/sub-agent-tools-Cx5BB5IO.js +39 -0
  478. package/dist/sub-agent-tools-DMT7jjBc.js +39 -0
  479. package/dist/sub-agent-tools-F-04gxf8.js +39 -0
  480. package/dist/sub-agent-tools-iBQiRKg6.js +39 -0
  481. package/dist/sub-agent-tools-kr921YOA.js +39 -0
  482. package/dist/theme-CLXvI6Hr.js +183 -0
  483. package/dist/theme-DdZT-Bq4.js +10 -0
  484. package/dist/theme-GEpjn_0G.js +180 -0
  485. package/dist/theme-hOlG-hDL.js +8 -0
  486. package/dist/tool-policy-D1zWYBKm.js +189 -0
  487. package/dist/tool-policy-TmXx_fpp.js +189 -0
  488. package/dist/tool-policy-YgysHf5s.js +189 -0
  489. package/dist/tts-elevenlabs-BT4WrEwy.js +61 -0
  490. package/dist/tts-elevenlabs-C62Wnnrg.js +61 -0
  491. package/dist/tts-elevenlabs-DmEFFeR8.js +61 -0
  492. package/dist/update-check-BeAPt4-f.js +98 -0
  493. package/dist/update-check-CaHNCDqe.js +6 -0
  494. package/dist/vision-B5DQ5hYa.js +121 -0
  495. package/dist/vision-XOSSQe4m.js +121 -0
  496. package/dist/vision-sIO3kwFy.js +121 -0
  497. package/dist/vision-tools-BHogJPuK.js +5 -0
  498. package/dist/vision-tools-BZhV8wg3.js +51 -0
  499. package/dist/vision-tools-BiDKd0UA.js +5 -0
  500. package/dist/vision-tools-CdRxilYR.js +5 -0
  501. package/dist/vision-tools-DnUjpQhI.js +51 -0
  502. package/dist/vision-tools-gtUq6d-x.js +51 -0
  503. package/dist/voice-transcription-5_iQE-0C.js +138 -0
  504. package/dist/voice-transcription-C3SuzK96.js +138 -0
  505. package/dist/voice-transcription-CYFj4Iv3.js +138 -0
  506. package/dist/voice-transcription-ygmlOkky.js +138 -0
  507. package/dist/website-watch-tools-BF-wR0UI.js +5 -0
  508. package/dist/website-watch-tools-CVh7RA5-.js +139 -0
  509. package/dist/website-watch-tools-CthBrGPP.js +5 -0
  510. package/dist/website-watch-tools-Oxf8Mv4j.js +139 -0
  511. package/package.json +1 -1
@@ -0,0 +1,1278 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const chalk = require_chunk.__toESM(require("chalk"));
3
+ const fs_extra = require_chunk.__toESM(require("fs-extra"));
4
+ const path = require_chunk.__toESM(require("path"));
5
+ const crypto = require_chunk.__toESM(require("crypto"));
6
+ const child_process = require_chunk.__toESM(require("child_process"));
7
+ const http = require_chunk.__toESM(require("http"));
8
+ const ws = require_chunk.__toESM(require("ws"));
9
+
10
+ //#region packages/gateway/src/server.ts
11
+ let activeServer = null;
12
+ /**
13
+
14
+ * Thrown when the gateway cannot bind its WebSocket port.
15
+
16
+ *
17
+
18
+ * Most common cause: another gateway instance is already running on the same
19
+
20
+ * port (EADDRINUSE). The OS releases the port automatically on any exit,
21
+
22
+ * including crashes and SIGKILL — no separate lock file or cleanup is needed.
23
+
24
+ *
25
+
26
+ * To run a second gateway on the same host, use an isolated profile and a
27
+
28
+ * unique port (leave at least 20 ports between base ports):
29
+
30
+ * hyperclaw --profile rescue gateway --port 19001
31
+
32
+ */
33
+ var GatewayLockError = class extends Error {
34
+ code;
35
+ constructor(message, code = "GATEWAY_LOCK") {
36
+ super(message);
37
+ this.name = "GatewayLockError";
38
+ this.code = code;
39
+ }
40
+ };
41
+ var GatewayServer = class {
42
+ wss = null;
43
+ httpServer = null;
44
+ sessions = /* @__PURE__ */ new Map();
45
+ transcripts = /* @__PURE__ */ new Map();
46
+ sessionStore = null;
47
+ config;
48
+ startedAt = "";
49
+ stopCron = null;
50
+ channelRunner = null;
51
+ configWatcher = null;
52
+ configReloadDebounce = null;
53
+ constructor(config) {
54
+ this.config = config;
55
+ }
56
+ /** Start watching the config file for changes and hot-apply safe settings. */
57
+ startConfigWatcher() {
58
+ const mode = this.config.reloadMode ?? "hybrid";
59
+ if (mode === "off") return;
60
+ const configPath = this.config.deps.getConfigPath?.() ?? "";
61
+ if (!configPath) return;
62
+ const fsNode = require("fs");
63
+ const debounceMs = this.config.reloadDebounceMs ?? 300;
64
+ const tryWatch = () => {
65
+ try {
66
+ const watcher = fsNode.watch(configPath, { persistent: false }, (_event) => {
67
+ if (this.configReloadDebounce) clearTimeout(this.configReloadDebounce);
68
+ this.configReloadDebounce = setTimeout(() => void this.hotReloadConfig(), debounceMs);
69
+ });
70
+ this.configWatcher = watcher;
71
+ console.log(chalk.default.gray(` ⚙ Config watcher active (mode: ${mode}) — ${configPath}`));
72
+ } catch {
73
+ const dir = require("path").dirname(configPath);
74
+ try {
75
+ const dirWatcher = fsNode.watch(dir, { persistent: false }, (_event, filename) => {
76
+ if (filename && configPath.endsWith(filename) && fsNode.existsSync(configPath)) {
77
+ dirWatcher.close();
78
+ tryWatch();
79
+ }
80
+ });
81
+ } catch {}
82
+ }
83
+ };
84
+ tryWatch();
85
+ }
86
+ /** Hot-apply safe config changes without restarting. */
87
+ async hotReloadConfig() {
88
+ try {
89
+ const fs$1 = require("fs-extra");
90
+ const configPath = this.config.deps.getConfigPath?.() ?? "";
91
+ if (!configPath) return;
92
+ const raw = await fs$1.readJson(configPath).catch(() => null);
93
+ if (!raw) return;
94
+ const restartRequired = raw.gateway?.port !== this.config.port || raw.gateway?.bind !== this.config.bind;
95
+ if (restartRequired) {
96
+ console.log(chalk.default.yellow("\n ⚙ Config change requires gateway restart — restarting...\n"));
97
+ for (const s of this.sessions.values()) if (s.socket.readyState === 1) s.socket.send(JSON.stringify({
98
+ type: "gateway:reloading",
99
+ reason: "config-change"
100
+ }));
101
+ try {
102
+ const { DaemonManager } = await Promise.resolve().then(() => require("./daemon-CCxpXxSb.js"));
103
+ await new DaemonManager().restart?.();
104
+ } catch {}
105
+ return;
106
+ }
107
+ if (raw.gateway?.hooks !== void 0) this.config.hooks = raw.gateway.hooks;
108
+ if (raw.gateway?.enabledChannels !== void 0) this.config.enabledChannels = raw.gateway.enabledChannels;
109
+ const newDm = raw.gateway?.dmScope ?? raw.session?.dmScope;
110
+ if (newDm !== void 0) this.config.dmScope = newDm === "main" ? "global" : newDm === "per-peer" ? "per-channel" : newDm;
111
+ if (typeof this.config.deps.onConfigReloaded === "function") this.config.deps.onConfigReloaded(raw);
112
+ const reloadMsg = JSON.stringify({
113
+ type: "gateway:config-reloaded",
114
+ ts: (/* @__PURE__ */ new Date()).toISOString()
115
+ });
116
+ for (const s of this.sessions.values()) if (s.socket.readyState === 1) s.socket.send(reloadMsg);
117
+ console.log(chalk.default.green(" ⚙ Config hot-reloaded (no restart needed)"));
118
+ } catch (e) {
119
+ console.log(chalk.default.yellow(` ⚙ Config reload failed: ${e.message}`));
120
+ }
121
+ }
122
+ async start() {
123
+ this.httpServer = http.default.createServer((req, res) => {
124
+ this.handleHttp(req, res);
125
+ });
126
+ this.wss = new ws.WebSocketServer({ server: this.httpServer });
127
+ this.wss.on("connection", this.handleConnection.bind(this));
128
+ await new Promise((resolve, reject) => {
129
+ this.httpServer.listen(this.config.port, this.config.bind, () => resolve());
130
+ this.httpServer.on("error", (err) => {
131
+ if (err.code === "EADDRINUSE") reject(new GatewayLockError(`another gateway instance is already listening on ws://${this.config.bind}:${this.config.port}`, "EADDRINUSE"));
132
+ else reject(new GatewayLockError(`failed to bind gateway socket on ws://${this.config.bind}:${this.config.port}: ${err.message}`, err.code || "BIND_ERROR"));
133
+ });
134
+ });
135
+ this.startedAt = (/* @__PURE__ */ new Date()).toISOString();
136
+ activeServer = this;
137
+ try {
138
+ this.sessionStore = await this.config.deps.createSessionStore(this.config.deps.getHyperClawDir());
139
+ } catch (_) {
140
+ this.sessionStore = null;
141
+ }
142
+ const icon = this.config.daemonMode ? "🩸" : "🦅";
143
+ const color = this.config.daemonMode ? chalk.default.red.bind(chalk.default) : chalk.default.hex("#06b6d4");
144
+ console.log(color(`\n ${icon} Gateway started: ws://${this.config.bind}:${this.config.port}\n`));
145
+ this.channelRunner = await this.config.deps.startChannelRunners({
146
+ port: this.config.port,
147
+ bind: this.config.bind,
148
+ authToken: this.config.deps.resolveGatewayToken(this.config.authToken)
149
+ });
150
+ if (this.config.hooks && this.config.deps.createHookLoader) {
151
+ const loader = this.config.deps.createHookLoader();
152
+ loader.execute("gateway:start", {}).catch(() => {});
153
+ this.stopCron = loader.startCronScheduler();
154
+ }
155
+ this.startConfigWatcher();
156
+ }
157
+ async stop() {
158
+ if (this.configWatcher) {
159
+ this.configWatcher.close();
160
+ this.configWatcher = null;
161
+ }
162
+ if (this.configReloadDebounce) clearTimeout(this.configReloadDebounce);
163
+ if (this.channelRunner) {
164
+ await this.channelRunner.stop();
165
+ this.channelRunner = null;
166
+ }
167
+ if (this.stopCron) {
168
+ this.stopCron();
169
+ this.stopCron = null;
170
+ }
171
+ for (const s of this.sessions.values()) s.socket.close(1001, "Gateway shutting down");
172
+ this.sessions.clear();
173
+ this.wss?.close();
174
+ await new Promise((resolve) => this.httpServer?.close(() => resolve()));
175
+ activeServer = null;
176
+ }
177
+ /** Returns false and sends 401 if auth required but missing/invalid. */
178
+ async requireAuth(req, res) {
179
+ const token = this.config.deps.resolveGatewayToken(this.config.authToken);
180
+ const auth = req.headers.authorization;
181
+ if (!token && !auth) return true;
182
+ if (!auth || !auth.startsWith("Bearer ")) {
183
+ res.writeHead(401, { "Content-Type": "application/json" });
184
+ res.end(JSON.stringify({
185
+ error: "Unauthorized",
186
+ hint: "Authorization: Bearer <gateway_token_or_developer_key>"
187
+ }));
188
+ return false;
189
+ }
190
+ const bearer = auth.slice(7);
191
+ if (token && bearer === token) return true;
192
+ if (this.config.deps.validateApiAuth) {
193
+ const ok = await this.config.deps.validateApiAuth(bearer);
194
+ if (ok) return true;
195
+ }
196
+ res.writeHead(401, { "Content-Type": "application/json" });
197
+ res.end(JSON.stringify({
198
+ error: "Unauthorized",
199
+ hint: "Authorization: Bearer <gateway_token_or_developer_key>"
200
+ }));
201
+ return false;
202
+ }
203
+ /** Resolve real client IP, honouring X-Forwarded-For only when the socket peer is a trusted proxy. */
204
+ resolveClientIp(req) {
205
+ const socketIp = req.socket.remoteAddress ?? "127.0.0.1";
206
+ const trusted = this.config.trustedProxies ?? [];
207
+ if (trusted.length === 0) return socketIp;
208
+ const isTrusted = trusted.some((proxy) => {
209
+ if (proxy === socketIp) return true;
210
+ if (proxy.includes("/")) try {
211
+ const [base, bits] = proxy.split("/");
212
+ const mask = ~((1 << 32 - parseInt(bits, 10)) - 1);
213
+ const ipToNum = (ip) => ip.split(".").reduce((acc, octet) => (acc << 8) + parseInt(octet, 10), 0);
214
+ return (ipToNum(socketIp) & mask) === (ipToNum(base) & mask);
215
+ } catch {
216
+ return false;
217
+ }
218
+ return false;
219
+ });
220
+ if (!isTrusted) return socketIp;
221
+ const xff = req.headers["x-forwarded-for"];
222
+ return xff ? xff.split(",")[0].trim() : socketIp;
223
+ }
224
+ configRpcRateLimit = /* @__PURE__ */ new Map();
225
+ CONFIG_RPC_MAX = 3;
226
+ CONFIG_RPC_WINDOW_MS = 6e4;
227
+ checkConfigRpcRateLimit(key) {
228
+ const now = Date.now();
229
+ let entry = this.configRpcRateLimit.get(key);
230
+ if (!entry || now - entry.windowStart > this.CONFIG_RPC_WINDOW_MS) entry = {
231
+ count: 0,
232
+ windowStart: now
233
+ };
234
+ entry.count++;
235
+ this.configRpcRateLimit.set(key, entry);
236
+ if (entry.count > this.CONFIG_RPC_MAX) {
237
+ const retryAfterMs = this.CONFIG_RPC_WINDOW_MS - (now - entry.windowStart);
238
+ return {
239
+ ok: false,
240
+ retryAfterMs
241
+ };
242
+ }
243
+ return { ok: true };
244
+ }
245
+ async handleHttp(req, res) {
246
+ const url = (req.url || "/").split("?")[0];
247
+ res.setHeader("Access-Control-Allow-Origin", "*");
248
+ res.setHeader("Content-Type", "application/json");
249
+ if (req.method === "OPTIONS") {
250
+ res.writeHead(204);
251
+ res.end();
252
+ return;
253
+ }
254
+ if (url === "/api/v1/check") {
255
+ res.writeHead(200);
256
+ res.end(JSON.stringify({
257
+ ok: true,
258
+ service: "hyperclaw",
259
+ version: "5.2.0"
260
+ }));
261
+ return;
262
+ }
263
+ if ((url === "/api/v1/config/apply" || url === "/api/v1/config/patch") && req.method === "POST") {
264
+ if (!await this.requireAuth(req, res)) return;
265
+ const clientIp = this.resolveClientIp(req);
266
+ const deviceId = req.headers["x-hyperclaw-device"] || "anon";
267
+ const rlKey = `${deviceId}:${clientIp}`;
268
+ const rl = this.checkConfigRpcRateLimit(rlKey);
269
+ if (!rl.ok) {
270
+ res.writeHead(429, { "Retry-After": String(Math.ceil((rl.retryAfterMs ?? 6e4) / 1e3)) });
271
+ res.end(JSON.stringify({
272
+ error: "UNAVAILABLE",
273
+ retryAfterMs: rl.retryAfterMs,
274
+ hint: "Config RPC is rate-limited to 3 requests per 60 seconds."
275
+ }));
276
+ return;
277
+ }
278
+ let body = "";
279
+ req.on("data", (c) => body += c);
280
+ req.on("end", async () => {
281
+ try {
282
+ const payload = JSON.parse(body || "{}");
283
+ const configPath = this.config.deps.getConfigPath();
284
+ const current = await fs_extra.default.readJson(configPath).catch(() => ({}));
285
+ let next;
286
+ if (url.endsWith("/apply")) next = payload;
287
+ else next = {
288
+ ...current,
289
+ ...payload
290
+ };
291
+ await fs_extra.default.writeJson(configPath, next, { spaces: 2 });
292
+ res.writeHead(200);
293
+ res.end(JSON.stringify({
294
+ ok: true,
295
+ action: url.endsWith("/apply") ? "apply" : "patch"
296
+ }));
297
+ } catch (e) {
298
+ res.writeHead(400);
299
+ res.end(JSON.stringify({ error: e.message }));
300
+ }
301
+ });
302
+ return;
303
+ }
304
+ if (url === "/api/v1/pi" && req.method === "POST") {
305
+ if (!await this.requireAuth(req, res)) return;
306
+ let body = "";
307
+ req.on("data", (c) => body += c);
308
+ req.on("end", async () => {
309
+ try {
310
+ const handler = this.config.deps.createPiRPCHandler((msg, opts) => this.callAgent(msg, {
311
+ currentSessionId: opts?.currentSessionId,
312
+ source: opts?.source
313
+ }), () => this.getSessionsList());
314
+ const rpcReq = JSON.parse(body || "{}");
315
+ const rpcRes = await handler(rpcReq);
316
+ res.writeHead(200);
317
+ res.end(JSON.stringify(rpcRes));
318
+ } catch (e) {
319
+ res.writeHead(500);
320
+ res.end(JSON.stringify({
321
+ jsonrpc: "2.0",
322
+ error: {
323
+ code: -32700,
324
+ message: e.message || "Parse error"
325
+ }
326
+ }));
327
+ }
328
+ });
329
+ return;
330
+ }
331
+ if (url === "/api/status") {
332
+ const cfg = this.loadConfig();
333
+ res.writeHead(200);
334
+ res.end(JSON.stringify({
335
+ running: true,
336
+ port: this.config.port,
337
+ channels: this.config.enabledChannels,
338
+ model: cfg?.provider?.modelId || "unknown",
339
+ agentName: cfg?.identity?.agentName || "Hyper",
340
+ sessions: this.sessions.size,
341
+ uptime: this.startedAt ? `${Math.round((Date.now() - new Date(this.startedAt).getTime()) / 1e3)}s` : "0s"
342
+ }));
343
+ return;
344
+ }
345
+ if (url === "/api/traces" && req.method === "GET") {
346
+ if (!await this.requireAuth(req, res)) return;
347
+ (async () => {
348
+ const params = new URL(req.url || "", "http://localhost").searchParams;
349
+ const limit = Math.min(100, parseInt(params.get("limit") || "50", 10) || 50);
350
+ try {
351
+ const traces = this.config.deps.listTraces ? await this.config.deps.listTraces(this.config.deps.getHyperClawDir(), limit) : [];
352
+ res.writeHead(200);
353
+ res.end(JSON.stringify({ traces }));
354
+ } catch {
355
+ res.writeHead(500);
356
+ res.end(JSON.stringify({ error: "Failed to list traces" }));
357
+ }
358
+ })();
359
+ return;
360
+ }
361
+ if (url === "/api/costs" && req.method === "GET") {
362
+ if (!await this.requireAuth(req, res)) return;
363
+ (async () => {
364
+ const params = new URL(req.url || "", "http://localhost").searchParams;
365
+ const sessionId = params.get("sessionId");
366
+ const hcDir = this.config.deps.getHyperClawDir();
367
+ try {
368
+ if (sessionId && this.config.deps.getSessionSummary) {
369
+ const summary = await this.config.deps.getSessionSummary(hcDir, sessionId);
370
+ res.writeHead(200);
371
+ res.end(JSON.stringify({
372
+ sessionId,
373
+ summary
374
+ }));
375
+ } else if (this.config.deps.getGlobalSummary) {
376
+ const summary = await this.config.deps.getGlobalSummary(this.config.deps.getHyperClawDir());
377
+ res.writeHead(200);
378
+ res.end(JSON.stringify({ summary }));
379
+ }
380
+ } catch (e) {
381
+ res.writeHead(500);
382
+ res.end(JSON.stringify({ error: e.message }));
383
+ }
384
+ })();
385
+ return;
386
+ }
387
+ if (url === "/api/remote/restart" && req.method === "POST") {
388
+ const auth = req.headers.authorization;
389
+ const token = this.config.deps.resolveGatewayToken(this.config.authToken);
390
+ if (token && auth !== `Bearer ${token}`) {
391
+ res.writeHead(401);
392
+ res.end(JSON.stringify({ error: "Unauthorized" }));
393
+ return;
394
+ }
395
+ (async () => {
396
+ const hcDir = this.config.deps.getHyperClawDir();
397
+ const pidFile = path.default.join(hcDir, "gateway.pid");
398
+ let didSpawn = false;
399
+ try {
400
+ if (await fs_extra.default.pathExists(pidFile)) {
401
+ const storedPid = parseInt(await fs_extra.default.readFile(pidFile, "utf8"), 10);
402
+ if (storedPid === process.pid && this.config.daemonMode) {
403
+ const runMainPath = this.config.deps.getRunMainPath?.() || process.argv[1] || require.main?.filename || path.default.resolve(process.cwd(), "dist/run-main.js");
404
+ const child = (0, child_process.spawn)(process.execPath, [
405
+ runMainPath,
406
+ "daemon",
407
+ "restart"
408
+ ], {
409
+ detached: true,
410
+ stdio: "ignore",
411
+ env: process.env,
412
+ cwd: process.cwd()
413
+ });
414
+ child.unref();
415
+ didSpawn = true;
416
+ }
417
+ }
418
+ } catch {}
419
+ res.writeHead(200);
420
+ res.end(JSON.stringify({
421
+ accepted: true,
422
+ message: didSpawn ? "Restarting daemon..." : "Gateway does not run as daemon. Run: hyperclaw daemon start, or from remote: ssh user@host \"hyperclaw daemon restart\"",
423
+ restarted: didSpawn
424
+ }));
425
+ })();
426
+ return;
427
+ }
428
+ if (url === "/api/v1/tts" && req.method === "POST") {
429
+ if (!await this.requireAuth(req, res)) return;
430
+ let body = "";
431
+ req.on("data", (c) => body += c);
432
+ req.on("end", async () => {
433
+ try {
434
+ const { text } = JSON.parse(body || "{}");
435
+ const cfg = this.loadConfig();
436
+ const apiKey = cfg?.talkMode?.apiKey || process.env.ELEVENLABS_API_KEY;
437
+ if (!apiKey || !text) {
438
+ res.writeHead(400);
439
+ res.end(JSON.stringify({ error: "Missing text or ELEVENLABS_API_KEY" }));
440
+ return;
441
+ }
442
+ const audio = this.config.deps.textToSpeech ? await this.config.deps.textToSpeech(text.slice(0, 4e3), {
443
+ apiKey,
444
+ voiceId: cfg?.talkMode?.voiceId,
445
+ modelId: cfg?.talkMode?.modelId
446
+ }) : null;
447
+ if (!audio) {
448
+ res.writeHead(502);
449
+ res.end(JSON.stringify({ error: "TTS failed" }));
450
+ return;
451
+ }
452
+ res.writeHead(200, { "Content-Type": "application/json" });
453
+ res.end(JSON.stringify({
454
+ format: "mp3",
455
+ data: audio
456
+ }));
457
+ } catch (e) {
458
+ res.writeHead(500);
459
+ res.end(JSON.stringify({ error: e.message }));
460
+ }
461
+ });
462
+ return;
463
+ }
464
+ if (url === "/api/nodes" && req.method === "GET") {
465
+ if (!await this.requireAuth(req, res)) return;
466
+ try {
467
+ const NR = this.config.deps.NodeRegistry;
468
+ const nodes = NR ? NR.getNodes().map((n) => ({
469
+ nodeId: n.nodeId,
470
+ platform: n.platform,
471
+ capabilities: n.capabilities,
472
+ deviceName: n.deviceName,
473
+ connectedAt: n.connectedAt,
474
+ lastSeenAt: n.lastSeenAt
475
+ })) : [];
476
+ res.writeHead(200);
477
+ res.end(JSON.stringify({ nodes }));
478
+ } catch (e) {
479
+ res.writeHead(500);
480
+ res.end(JSON.stringify({ error: e.message }));
481
+ }
482
+ return;
483
+ }
484
+ if (url === "/api/chat" && req.method === "POST") {
485
+ if (!await this.requireAuth(req, res)) return;
486
+ let body = "";
487
+ req.on("data", (c) => body += c);
488
+ req.on("end", async () => {
489
+ try {
490
+ const parsed = JSON.parse(body);
491
+ const { message } = parsed;
492
+ const agentId = parsed.agentId;
493
+ const sessionKey = parsed.sessionKey;
494
+ const source = req.headers["x-hyperclaw-source"] || "unknown";
495
+ const response = await this.callAgent(message, {
496
+ source,
497
+ agentId,
498
+ sessionKey
499
+ });
500
+ res.writeHead(200);
501
+ res.end(JSON.stringify({ response }));
502
+ } catch (e) {
503
+ res.writeHead(500);
504
+ res.end(JSON.stringify({ error: e.message }));
505
+ }
506
+ });
507
+ return;
508
+ }
509
+ if (url === "/api/webhook/inbound" && req.method === "POST") {
510
+ if (!await this.requireAuth(req, res)) return;
511
+ let body = "";
512
+ req.on("data", (c) => body += c);
513
+ req.on("end", async () => {
514
+ try {
515
+ const parsed = typeof body === "string" ? JSON.parse(body || "{}") : {};
516
+ const message = parsed.message || parsed.text || parsed.prompt || String(parsed);
517
+ if (!message || typeof message !== "string") {
518
+ res.writeHead(400);
519
+ res.end(JSON.stringify({ error: "Body must include \"message\" or \"text\" or \"prompt\"" }));
520
+ return;
521
+ }
522
+ const response = await this.callAgent(message, { source: "webhook:inbound" });
523
+ res.writeHead(200);
524
+ res.end(JSON.stringify({
525
+ ok: true,
526
+ response
527
+ }));
528
+ } catch (e) {
529
+ res.writeHead(500);
530
+ res.end(JSON.stringify({ error: e.message }));
531
+ }
532
+ });
533
+ return;
534
+ }
535
+ if (url === "/api/canvas/state" && req.method === "GET") {
536
+ if (!await this.requireAuth(req, res)) return;
537
+ const getState = this.config.deps.getCanvasState;
538
+ if (getState) getState().then((canvas) => {
539
+ res.writeHead(200, { "Content-Type": "application/json" });
540
+ res.end(JSON.stringify(canvas));
541
+ }).catch((e) => {
542
+ res.writeHead(500);
543
+ res.end(JSON.stringify({ error: e.message }));
544
+ });
545
+ else Promise.resolve().then(() => require("./renderer-CmMjrkqN.js")).then(({ CanvasRenderer }) => {
546
+ const renderer = new CanvasRenderer();
547
+ renderer.getOrCreate().then((canvas) => {
548
+ res.writeHead(200, { "Content-Type": "application/json" });
549
+ res.end(JSON.stringify(canvas));
550
+ }).catch((e) => {
551
+ res.writeHead(500);
552
+ res.end(JSON.stringify({ error: e.message }));
553
+ });
554
+ }).catch((e) => {
555
+ res.writeHead(500);
556
+ res.end(JSON.stringify({ error: e.message }));
557
+ });
558
+ return;
559
+ }
560
+ if (url === "/api/canvas/a2ui" && req.method === "GET") {
561
+ if (!await this.requireAuth(req, res)) return;
562
+ const getA2UI = this.config.deps.getCanvasA2UI;
563
+ if (getA2UI) getA2UI().then((jsonl) => {
564
+ res.setHeader("Content-Type", "application/x-ndjson");
565
+ res.setHeader("Cache-Control", "no-cache");
566
+ res.writeHead(200);
567
+ res.end(jsonl + "\n");
568
+ }).catch((e) => {
569
+ res.writeHead(500);
570
+ res.end(JSON.stringify({ error: e.message }));
571
+ });
572
+ else Promise.resolve().then(() => require("./renderer-CmMjrkqN.js")).then(({ CanvasRenderer }) => {
573
+ Promise.resolve().then(() => require("./a2ui-protocol-dTomAnFE.js")).then(({ toBeginRendering, toJSONL }) => {
574
+ const renderer = new CanvasRenderer();
575
+ renderer.getOrCreate().then((canvas) => {
576
+ const msg = toBeginRendering(canvas);
577
+ res.setHeader("Content-Type", "application/x-ndjson");
578
+ res.setHeader("Cache-Control", "no-cache");
579
+ res.writeHead(200);
580
+ res.end(toJSONL([msg]) + "\n");
581
+ }).catch((e) => {
582
+ res.writeHead(500);
583
+ res.end(JSON.stringify({ error: e.message }));
584
+ });
585
+ });
586
+ }).catch((e) => {
587
+ res.writeHead(500);
588
+ res.end(JSON.stringify({ error: e.message }));
589
+ });
590
+ return;
591
+ }
592
+ if (url === "/chat" || url === "/chat/") {
593
+ res.setHeader("Content-Type", "text/html");
594
+ const fp = path.default.join(process.cwd(), "static", "chat.html");
595
+ if (fs_extra.default.pathExistsSync(fp)) res.end(fs_extra.default.readFileSync(fp, "utf8"));
596
+ else res.end("<!DOCTYPE html><html><body><p>Chat UI: <a href=\"/\">apps/web</a></p></body></html>");
597
+ return;
598
+ }
599
+ if (url === "/dashboard" || url === "/dashboard/") {
600
+ res.setHeader("Content-Type", "text/html");
601
+ const fp = path.default.join(process.cwd(), "static", "dashboard.html");
602
+ if (fs_extra.default.pathExistsSync(fp)) res.end(fs_extra.default.readFileSync(fp, "utf8"));
603
+ else res.end("<!DOCTYPE html><html><body><p>Dashboard: <a href=\"/api/status\">status</a></p></body></html>");
604
+ return;
605
+ }
606
+ if (url === "/" || url === "") {
607
+ res.writeHead(302, { Location: "/dashboard" });
608
+ res.end();
609
+ return;
610
+ }
611
+ if (url.startsWith("/webhook/")) {
612
+ const channelId = url.split("/")[2];
613
+ if (req.method === "GET") {
614
+ const params = new URL(url, "http://x").searchParams;
615
+ if (channelId === "twitter") {
616
+ const crcToken = params.get("crc_token");
617
+ if (crcToken) {
618
+ const verified$1 = this.channelRunner?.verifyWebhook?.(channelId, "crc", crcToken, "");
619
+ if (verified$1) {
620
+ res.writeHead(200, { "Content-Type": "application/json" });
621
+ res.end(verified$1);
622
+ return;
623
+ }
624
+ }
625
+ }
626
+ const mode = params.get("hub.mode") || "";
627
+ const token = params.get("hub.verify_token") || "";
628
+ const challenge = params.get("hub.challenge") || "";
629
+ const verified = this.channelRunner?.verifyWebhook?.(channelId, mode, token, challenge);
630
+ if (verified !== null && verified !== void 0) {
631
+ res.writeHead(200, { "Content-Type": "text/plain" });
632
+ res.end(verified);
633
+ } else {
634
+ res.writeHead(200);
635
+ res.end(JSON.stringify({ ok: true }));
636
+ }
637
+ return;
638
+ }
639
+ if (req.method === "POST") {
640
+ let body = "";
641
+ req.on("data", (c) => body += c);
642
+ req.on("end", async () => {
643
+ const host = req.headers["host"] || "localhost";
644
+ const baseUrl = `${req.headers["x-forwarded-proto"] === "https" ? "https" : "http"}://${host}`;
645
+ let opts;
646
+ if (channelId === "slack") opts = {
647
+ signature: req.headers["x-slack-signature"] || "",
648
+ timestamp: req.headers["x-slack-request-timestamp"] || ""
649
+ };
650
+ else if (channelId === "line") opts = { signature: req.headers["x-line-signature"] || "" };
651
+ else if (channelId === "sms") opts = {
652
+ twilioSignature: req.headers["x-twilio-signature"] || "",
653
+ webhookUrl: `${baseUrl}${req.url}`
654
+ };
655
+ else if (channelId === "instagram" || channelId === "messenger") opts = { signature: req.headers["x-hub-signature-256"] || "" };
656
+ else if (channelId === "viber") opts = { signature: req.headers["x-viber-signature"] || "" };
657
+ let challenge = void 0;
658
+ if (this.channelRunner?.handleWebhook) challenge = await this.channelRunner.handleWebhook(channelId, body, opts).catch(() => void 0);
659
+ this.broadcast({
660
+ type: "webhook:received",
661
+ channelId,
662
+ payload: body
663
+ });
664
+ if (typeof challenge === "string") {
665
+ const contentType = challenge.trim().startsWith("{") ? "application/json" : "text/plain";
666
+ res.writeHead(200, { "Content-Type": contentType });
667
+ res.end(challenge);
668
+ } else {
669
+ res.writeHead(200);
670
+ res.end(JSON.stringify({ ok: true }));
671
+ }
672
+ });
673
+ return;
674
+ }
675
+ }
676
+ res.writeHead(404);
677
+ res.end(JSON.stringify({ error: "Not found" }));
678
+ }
679
+ handleConnection(ws$1, req) {
680
+ const id = crypto.default.randomBytes(8).toString("hex");
681
+ const source = req.headers["x-hyperclaw-source"] || "unknown";
682
+ const authToken = this.config.deps.resolveGatewayToken(this.config.authToken);
683
+ const session = {
684
+ id,
685
+ socket: ws$1,
686
+ authenticated: !authToken,
687
+ source,
688
+ connectedAt: (/* @__PURE__ */ new Date()).toISOString(),
689
+ lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
690
+ };
691
+ this.sessions.set(id, session);
692
+ this.broadcast({
693
+ type: "presence:join",
694
+ sessionId: id,
695
+ source
696
+ }, id);
697
+ console.log(chalk.default.gray(` [gateway] +connect ${source} ${id}`));
698
+ if (authToken && !session.authenticated) this.send(session, {
699
+ type: "connect.challenge",
700
+ sessionId: id
701
+ });
702
+ else {
703
+ this.send(session, {
704
+ type: "connect.ok",
705
+ sessionId: id,
706
+ version: "5.2.0",
707
+ heartbeatInterval: 3e4
708
+ });
709
+ if (this.config.hooks && this.config.deps.createHookLoader) this.config.deps.createHookLoader().execute("session:start", { sessionId: id }).catch(() => {});
710
+ }
711
+ ws$1.on("message", (data) => {
712
+ session.lastActiveAt = (/* @__PURE__ */ new Date()).toISOString();
713
+ try {
714
+ this.handleMessage(session, JSON.parse(data.toString()));
715
+ } catch {
716
+ this.send(session, {
717
+ type: "error",
718
+ message: "Invalid JSON"
719
+ });
720
+ }
721
+ });
722
+ ws$1.on("close", () => {
723
+ const s = this.sessions.get(id);
724
+ if (s?.nodeId && this.config.deps.NodeRegistry) {
725
+ this.config.deps.NodeRegistry.unregister(s.nodeId);
726
+ console.log(chalk.default.gray(` [gateway] -node ${s.nodeId}`));
727
+ }
728
+ if (this.config.hooks && !s?.nodeId && this.config.deps.createHookLoader) {
729
+ const turnCount = this.transcripts.get(id)?.length ?? 0;
730
+ this.config.deps.createHookLoader().execute("session:end", {
731
+ sessionId: id,
732
+ turnCount
733
+ }).catch(() => {});
734
+ }
735
+ this.transcripts.delete(id);
736
+ this.sessions.delete(id);
737
+ this.broadcast({
738
+ type: "presence:leave",
739
+ sessionId: id
740
+ });
741
+ console.log(chalk.default.gray(` [gateway] -disconnect ${id}`));
742
+ });
743
+ ws$1.on("error", (e) => console.log(chalk.default.yellow(` [gateway] error ${id}: ${e.message}`)));
744
+ }
745
+ handleMessage(session, msg) {
746
+ if (msg.type === "node_register") {
747
+ const nodeId = msg.nodeId || `node-${session.id}`;
748
+ const platform = msg.platform === "ios" || msg.platform === "android" ? msg.platform : "ios";
749
+ const capabilities = msg.capabilities || {};
750
+ const authToken = this.config.deps.resolveGatewayToken(this.config.authToken);
751
+ if (authToken && msg.token !== authToken) {
752
+ this.send(session, {
753
+ type: "node:error",
754
+ message: "Invalid token"
755
+ });
756
+ session.socket.close(4001, "Unauthorized");
757
+ return;
758
+ }
759
+ const NR = this.config.deps.NodeRegistry;
760
+ if (!NR) {
761
+ this.send(session, {
762
+ type: "node:error",
763
+ message: "Node registry not available"
764
+ });
765
+ return;
766
+ }
767
+ const cmdIdToResolve = /* @__PURE__ */ new Map();
768
+ session._nodePending = cmdIdToResolve;
769
+ const node = {
770
+ nodeId,
771
+ platform,
772
+ capabilities,
773
+ deviceName: msg.deviceName,
774
+ connectedAt: (/* @__PURE__ */ new Date()).toISOString(),
775
+ lastSeenAt: (/* @__PURE__ */ new Date()).toISOString(),
776
+ send: async (cmd) => {
777
+ return new Promise((resolve) => {
778
+ const timeout = setTimeout(() => {
779
+ cmdIdToResolve.delete(cmd.id);
780
+ resolve({
781
+ ok: false,
782
+ error: "Timeout"
783
+ });
784
+ }, 3e4);
785
+ cmdIdToResolve.set(cmd.id, { resolve: (r) => {
786
+ clearTimeout(timeout);
787
+ resolve(r);
788
+ } });
789
+ this.send(session, {
790
+ type: "node:command",
791
+ id: cmd.id,
792
+ command: cmd.type,
793
+ params: cmd.params
794
+ });
795
+ });
796
+ }
797
+ };
798
+ const protocolVersion = msg.protocolVersion ?? 1;
799
+ NR.register(node);
800
+ session.nodeId = nodeId;
801
+ session.authenticated = true;
802
+ session.source = `node:${platform}`;
803
+ this.send(session, {
804
+ type: "node:registered",
805
+ nodeId,
806
+ sessionId: session.id,
807
+ protocolVersion: Math.min(protocolVersion, 2),
808
+ heartbeatInterval: 3e4,
809
+ capabilities: Object.keys(capabilities)
810
+ });
811
+ console.log(chalk.default.gray(` [gateway] +node ${nodeId} (${platform})`));
812
+ return;
813
+ }
814
+ if (msg.type === "node:unregister" && session.nodeId && this.config.deps.NodeRegistry) {
815
+ this.config.deps.NodeRegistry.unregister(session.nodeId);
816
+ session.nodeId = void 0;
817
+ this.send(session, { type: "node:unregistered" });
818
+ return;
819
+ }
820
+ if (msg.type === "node:command_response" && session._nodePending) {
821
+ const r = session._nodePending.get(msg.id);
822
+ if (r) {
823
+ session._nodePending.delete(msg.id);
824
+ r.resolve({
825
+ ok: msg.ok,
826
+ data: msg.data,
827
+ error: msg.error
828
+ });
829
+ }
830
+ return;
831
+ }
832
+ if (msg.type === "session:restore" && (msg.restoreKey ?? msg.previousSessionId)) {
833
+ const key = String(msg.restoreKey ?? msg.previousSessionId);
834
+ session.restoreKey = key;
835
+ if (this.sessionStore) this.sessionStore.get(key).then((state) => {
836
+ if (state?.transcript?.length) {
837
+ const arr = this.transcripts.get(session.id) || [];
838
+ for (const t of state.transcript) if (!arr.some((x) => x.role === t.role && x.content === t.content)) arr.push(t);
839
+ if (arr.length > 100) arr.splice(0, arr.length - 80);
840
+ this.transcripts.set(session.id, arr);
841
+ this.send(session, {
842
+ type: "session:restored",
843
+ transcript: state.transcript
844
+ });
845
+ }
846
+ }).catch(() => {});
847
+ return;
848
+ }
849
+ if (msg.type === "auth") {
850
+ const resolved = this.config.deps.resolveGatewayToken(this.config.authToken);
851
+ if (resolved && msg.token === resolved) {
852
+ session.authenticated = true;
853
+ this.send(session, {
854
+ type: "auth.ok",
855
+ sessionId: session.id
856
+ });
857
+ } else session.socket.close(4001, "Unauthorized");
858
+ return;
859
+ }
860
+ if (!session.authenticated) {
861
+ this.send(session, {
862
+ type: "error",
863
+ message: "Not authenticated"
864
+ });
865
+ return;
866
+ }
867
+ switch (msg.type) {
868
+ case "ping": {
869
+ if (session.nodeId && this.config.deps.NodeRegistry) this.config.deps.NodeRegistry.updateLastSeen?.(session.nodeId);
870
+ this.send(session, {
871
+ type: "pong",
872
+ ts: Date.now()
873
+ });
874
+ break;
875
+ }
876
+ case "talk:enable":
877
+ session.talkMode = true;
878
+ this.send(session, {
879
+ type: "talk:ok",
880
+ enabled: true
881
+ });
882
+ break;
883
+ case "talk:disable":
884
+ session.talkMode = false;
885
+ this.send(session, {
886
+ type: "talk:ok",
887
+ enabled: false
888
+ });
889
+ break;
890
+ case "elevated:enable": {
891
+ const cfg = this.loadConfig();
892
+ const allowFrom = (cfg?.tools?.elevated)?.allowFrom ?? [];
893
+ const enabled = (cfg?.tools?.elevated)?.enabled === true;
894
+ if (!enabled) {
895
+ this.send(session, {
896
+ type: "error",
897
+ message: "Elevated mode disabled in config"
898
+ });
899
+ break;
900
+ }
901
+ if (allowFrom.length && !allowFrom.includes(session.source) && !allowFrom.includes("*")) {
902
+ this.send(session, {
903
+ type: "error",
904
+ message: "Source not in elevated allowFrom"
905
+ });
906
+ break;
907
+ }
908
+ session.elevated = true;
909
+ this.send(session, {
910
+ type: "elevated:ok",
911
+ enabled: true
912
+ });
913
+ break;
914
+ }
915
+ case "elevated:disable":
916
+ session.elevated = false;
917
+ this.send(session, {
918
+ type: "elevated:ok",
919
+ enabled: false
920
+ });
921
+ break;
922
+ case "chat:message": {
923
+ const content = typeof msg.content === "string" ? msg.content : String(msg.content ?? "");
924
+ if (this.config.hooks && this.config.deps.createHookLoader) this.config.deps.createHookLoader().execute("message:received", { sessionId: session.id }).catch(() => {});
925
+ const onDone = (response) => {
926
+ this.send(session, {
927
+ type: "chat:response",
928
+ content: response
929
+ });
930
+ if (session.talkMode && response) this.synthesizeAndSendAudio(session, response).catch(() => {});
931
+ if (this.config.hooks && this.config.deps.createHookLoader) this.config.deps.createHookLoader().execute("message:sent", {
932
+ sessionId: session.id,
933
+ message: content,
934
+ response
935
+ }).catch(() => {});
936
+ };
937
+ this.callAgent(content, {
938
+ currentSessionId: session.id,
939
+ onToken: (token) => this.send(session, {
940
+ type: "chat:chunk",
941
+ content: token
942
+ }),
943
+ onDone
944
+ }).catch((e) => this.send(session, {
945
+ type: "chat:response",
946
+ content: `Error: ${e.message}`
947
+ }));
948
+ break;
949
+ }
950
+ case "gateway:status":
951
+ this.send(session, {
952
+ type: "gateway:status",
953
+ sessions: this.sessions.size,
954
+ uptime: this.startedAt
955
+ });
956
+ break;
957
+ case "presence:list":
958
+ this.send(session, {
959
+ type: "presence:list",
960
+ sessions: Array.from(this.sessions.entries()).map(([sid, s]) => ({
961
+ id: sid,
962
+ source: s.source
963
+ }))
964
+ });
965
+ break;
966
+ case "config:get":
967
+ this.send(session, {
968
+ type: "config:data",
969
+ config: this.scrubConfig(this.loadConfig())
970
+ });
971
+ break;
972
+ }
973
+ }
974
+ async callAgent(message, opts) {
975
+ const sid = opts?.currentSessionId;
976
+ const sess = sid ? this.sessions.get(sid) : void 0;
977
+ const confirmTriggers = [
978
+ "confirm",
979
+ "yes",
980
+ "ok",
981
+ "elevate"
982
+ ];
983
+ if (sid && confirmTriggers.includes(message.trim().toLowerCase())) {
984
+ const getPending = this.config.deps.getPending;
985
+ const clearPending = this.config.deps.clearPending;
986
+ if (getPending && clearPending) {
987
+ const pending = getPending(sid);
988
+ if (pending) {
989
+ clearPending(sid);
990
+ try {
991
+ const result$1 = await pending.execute();
992
+ opts?.onDone?.(result$1);
993
+ return result$1;
994
+ } catch (e) {
995
+ const err = `Error: ${e.message}`;
996
+ opts?.onDone?.(err);
997
+ return err;
998
+ }
999
+ }
1000
+ }
1001
+ }
1002
+ const cfg = this.loadConfig();
1003
+ const elevated = sess?.elevated && (cfg?.tools?.elevated)?.enabled === true;
1004
+ const source = opts?.source || sess?.source;
1005
+ const hcDir = this.config.deps.getHyperClawDir();
1006
+ const runOpts = {
1007
+ sessionId: sid,
1008
+ source,
1009
+ elevated,
1010
+ onToken: opts?.onToken,
1011
+ onDone: opts?.onDone,
1012
+ daemonMode: this.config.daemonMode,
1013
+ appendTranscript: (s, role, content) => this.appendTranscript(s, role, content),
1014
+ activeServer: activeServer ?? this,
1015
+ ...opts?.agentId ? { agentId: opts.agentId } : {},
1016
+ ...opts?.sessionKey ? { sessionKey: opts.sessionKey } : {}
1017
+ };
1018
+ if ((cfg?.observability)?.traces && this.config.deps.createRunTracer && this.config.deps.writeTraceToFile) {
1019
+ const tracer = this.config.deps.createRunTracer(sid, source);
1020
+ runOpts.onToolCall = tracer.onToolCall;
1021
+ runOpts.onToolResult = tracer.onToolResult;
1022
+ runOpts.onRunEnd = (usage, err) => {
1023
+ tracer.onRunEnd(usage, err);
1024
+ this.config.deps.writeTraceToFile(hcDir, tracer.trace).catch(() => {});
1025
+ };
1026
+ }
1027
+ const baseOnRunEnd = runOpts.onRunEnd;
1028
+ const recordUsage = this.config.deps.recordUsage;
1029
+ runOpts.onRunEnd = (usage, err) => {
1030
+ baseOnRunEnd?.(usage, err);
1031
+ if (sid && usage && recordUsage) recordUsage(hcDir, sid, usage, {
1032
+ source,
1033
+ model: cfg?.provider?.modelId ?? void 0
1034
+ }).catch(() => {});
1035
+ };
1036
+ const result = await this.config.deps.runAgentEngine(message, runOpts);
1037
+ return result.text;
1038
+ }
1039
+ appendTranscript(sessionId, role, content) {
1040
+ let arr = this.transcripts.get(sessionId);
1041
+ if (!arr) {
1042
+ arr = [];
1043
+ this.transcripts.set(sessionId, arr);
1044
+ }
1045
+ arr.push({
1046
+ role,
1047
+ content
1048
+ });
1049
+ if (arr.length > 100) arr.splice(0, arr.length - 80);
1050
+ const sess = this.sessions.get(sessionId);
1051
+ const storeKey = sess?.restoreKey || sessionId;
1052
+ if (this.sessionStore) this.sessionStore.append(storeKey, role, content, sess?.source).catch(() => {});
1053
+ }
1054
+ getSessionsList() {
1055
+ return Array.from(this.sessions.entries()).map(([id, s]) => ({
1056
+ id,
1057
+ source: s.source,
1058
+ connectedAt: s.connectedAt
1059
+ }));
1060
+ }
1061
+ sendToSession(sessionId, msg) {
1062
+ const s = this.sessions.get(sessionId);
1063
+ if (!s || s.socket.readyState !== ws.WebSocket.OPEN) return false;
1064
+ this.send(s, msg);
1065
+ return true;
1066
+ }
1067
+ getSessionHistory(sessionId, limit = 20) {
1068
+ const arr = this.transcripts.get(sessionId) ?? [];
1069
+ return arr.slice(-limit);
1070
+ }
1071
+ send(session, msg) {
1072
+ if (session.socket.readyState === ws.WebSocket.OPEN) session.socket.send(JSON.stringify(msg));
1073
+ }
1074
+ broadcast(msg, excludeId) {
1075
+ for (const [id, s] of this.sessions) if (id !== excludeId && s.authenticated) this.send(s, msg);
1076
+ }
1077
+ async synthesizeAndSendAudio(session, text) {
1078
+ const cfg = this.loadConfig();
1079
+ const talk = cfg?.talkMode;
1080
+ const apiKey = talk?.apiKey || process.env.ELEVENLABS_API_KEY;
1081
+ if (!apiKey) return;
1082
+ const textToSpeech = this.config.deps.textToSpeech;
1083
+ if (!textToSpeech) return;
1084
+ const audio = await textToSpeech(text.slice(0, 4e3), {
1085
+ apiKey,
1086
+ voiceId: talk?.voiceId,
1087
+ modelId: talk?.modelId || "eleven_multilingual_v2"
1088
+ });
1089
+ if (audio) this.send(session, {
1090
+ type: "chat:audio",
1091
+ format: "mp3",
1092
+ data: audio
1093
+ });
1094
+ }
1095
+ loadConfig() {
1096
+ if (this.config.deps.loadConfig) return this.config.deps.loadConfig();
1097
+ try {
1098
+ return fs_extra.default.readJsonSync(this.config.deps.getConfigPath());
1099
+ } catch {
1100
+ return null;
1101
+ }
1102
+ }
1103
+ scrubConfig(cfg) {
1104
+ if (!cfg) return null;
1105
+ const s = JSON.parse(JSON.stringify(cfg));
1106
+ if (s.provider?.apiKey) s.provider.apiKey = "***";
1107
+ if (s.gateway?.authToken) s.gateway.authToken = "***";
1108
+ return s;
1109
+ }
1110
+ getStatus() {
1111
+ return {
1112
+ running: true,
1113
+ port: this.config.port,
1114
+ sessions: this.sessions.size,
1115
+ startedAt: this.startedAt
1116
+ };
1117
+ }
1118
+ };
1119
+ const DEFAULT_PORT = 18789;
1120
+ async function startGateway(opts) {
1121
+ const deps = opts.deps;
1122
+ let base;
1123
+ let fullCfg = {};
1124
+ try {
1125
+ fullCfg = fs_extra.default.readJsonSync(deps.getConfigPath());
1126
+ base = fullCfg.gateway ?? {};
1127
+ } catch {
1128
+ base = {
1129
+ port: DEFAULT_PORT,
1130
+ bind: "127.0.0.1",
1131
+ authToken: "",
1132
+ runtime: "node",
1133
+ enabledChannels: [],
1134
+ hooks: true
1135
+ };
1136
+ }
1137
+ const portEnv = process.env.PORT || process.env.HYPERCLAW_PORT;
1138
+ const port = portEnv ? parseInt(portEnv, 10) || base.port : base.port;
1139
+ const sessionDm = fullCfg?.session?.dmScope;
1140
+ const gwDm = base.dmScope ?? sessionDm;
1141
+ const dmScope = gwDm === "main" ? "global" : gwDm === "per-peer" ? "per-channel" : gwDm;
1142
+ const cfg = {
1143
+ ...base,
1144
+ port: port ?? DEFAULT_PORT,
1145
+ bind: base.bind ?? "127.0.0.1",
1146
+ authToken: deps.resolveGatewayToken(base.authToken ?? "") ?? base.authToken ?? "",
1147
+ runtime: base.runtime ?? "node",
1148
+ enabledChannels: base.enabledChannels ?? [],
1149
+ hooks: base.hooks ?? true,
1150
+ dmScope: dmScope ?? base.dmScope,
1151
+ daemonMode: opts.daemonMode,
1152
+ deps
1153
+ };
1154
+ const server = new GatewayServer(cfg);
1155
+ await server.start();
1156
+ return server;
1157
+ }
1158
+ function getActiveServer() {
1159
+ return activeServer;
1160
+ }
1161
+ GatewayServer.prototype.getSessionsList = function() {
1162
+ const out = [];
1163
+ for (const [id, s] of this.sessions) out.push({
1164
+ id,
1165
+ source: s.source,
1166
+ connectedAt: s.connectedAt,
1167
+ lastActiveAt: s.lastActiveAt,
1168
+ talkMode: s.talkMode ?? false,
1169
+ nodeId: s.nodeId ?? null
1170
+ });
1171
+ return out;
1172
+ };
1173
+ GatewayServer.prototype.sendToSession = function(id, msg) {
1174
+ const session = this.sessions.get(id);
1175
+ if (!session || session.socket.readyState !== 1) return false;
1176
+ try {
1177
+ session.socket.send(JSON.stringify(msg));
1178
+ return true;
1179
+ } catch {
1180
+ return false;
1181
+ }
1182
+ };
1183
+ GatewayServer.prototype.getSessionHistory = function(id, limit) {
1184
+ const history = this.transcripts.get(id);
1185
+ if (!history) return [];
1186
+ return history.slice(-limit);
1187
+ };
1188
+
1189
+ //#endregion
1190
+ //#region src/gateway/deps-provider.ts
1191
+ async function createDefaultGatewayDeps() {
1192
+ const [paths, envResolve, sessionStore, channelRunner, hookLoader, core, devKeys, pendingApproval, observability, costTracker, tts, nodesRegistry, canvasRenderer, a2ui] = await Promise.all([
1193
+ Promise.resolve().then(() => require("./paths-D-QecARF.js")),
1194
+ Promise.resolve().then(() => require("./env-resolve-DkBUmcI3.js")),
1195
+ Promise.resolve().then(() => require("./session-store-eecMioKI.js")),
1196
+ Promise.resolve().then(() => require("./runner-Im-aCXhh.js")),
1197
+ Promise.resolve().then(() => require("./loader-DpYgmaul.js")),
1198
+ Promise.resolve().then(() => require("./src-BqbwzQQj.js")),
1199
+ Promise.resolve().then(() => require("./developer-keys-BeUpyenR.js")),
1200
+ Promise.resolve().then(() => require("./pending-approval-DiZ96D8v.js")),
1201
+ Promise.resolve().then(() => require("./observability-4CyDqBWi.js")),
1202
+ Promise.resolve().then(() => require("./cost-tracker-jbK_AoIV.js")),
1203
+ Promise.resolve().then(() => require("./tts-elevenlabs-BT4WrEwy.js")),
1204
+ Promise.resolve().then(() => require("./nodes-registry--DkZbn41.js")),
1205
+ Promise.resolve().then(() => require("./renderer-CmMjrkqN.js")),
1206
+ Promise.resolve().then(() => require("./a2ui-protocol-dTomAnFE.js"))
1207
+ ]);
1208
+ const createSessionStore = async (baseDir) => {
1209
+ const store = await sessionStore.createFileSessionStore(baseDir);
1210
+ return store;
1211
+ };
1212
+ const createHookLoader = () => new hookLoader.HookLoader();
1213
+ const getCanvasState = async () => {
1214
+ const renderer = new canvasRenderer.CanvasRenderer();
1215
+ const canvas = await renderer.getOrCreate();
1216
+ return canvas;
1217
+ };
1218
+ const getCanvasA2UI = async () => {
1219
+ const renderer = new canvasRenderer.CanvasRenderer();
1220
+ const canvas = await renderer.getOrCreate();
1221
+ const msg = a2ui.toBeginRendering(canvas);
1222
+ return a2ui.toJSONL([msg]);
1223
+ };
1224
+ return {
1225
+ getHyperClawDir: paths.getHyperClawDir,
1226
+ getConfigPath: paths.getConfigPath,
1227
+ resolveGatewayToken: envResolve.resolveGatewayToken,
1228
+ validateApiAuth: async (bearer) => (await devKeys.validateDeveloperKey(bearer)).valid,
1229
+ createSessionStore,
1230
+ startChannelRunners: channelRunner.startChannelRunners,
1231
+ createHookLoader,
1232
+ runAgentEngine: core.runAgentEngine,
1233
+ createPiRPCHandler: core.createPiRPCHandler,
1234
+ listTraces: observability.listTraces,
1235
+ getSessionSummary: costTracker.getSessionSummary,
1236
+ getGlobalSummary: costTracker.getGlobalSummary,
1237
+ recordUsage: costTracker.recordUsage,
1238
+ textToSpeech: tts.textToSpeech,
1239
+ getPending: pendingApproval.getPending,
1240
+ clearPending: pendingApproval.clearPending,
1241
+ createRunTracer: observability.createRunTracer,
1242
+ writeTraceToFile: observability.writeTraceToFile,
1243
+ NodeRegistry: nodesRegistry.NodeRegistry,
1244
+ getCanvasState,
1245
+ getCanvasA2UI
1246
+ };
1247
+ }
1248
+
1249
+ //#endregion
1250
+ //#region src/gateway/server.ts
1251
+ /** Start gateway with default deps (paths, channels, hooks, etc.). */
1252
+ async function startGateway$1(opts) {
1253
+ const deps = await createDefaultGatewayDeps();
1254
+ return startGateway({
1255
+ ...opts,
1256
+ deps
1257
+ });
1258
+ }
1259
+
1260
+ //#endregion
1261
+ Object.defineProperty(exports, 'GatewayServer', {
1262
+ enumerable: true,
1263
+ get: function () {
1264
+ return GatewayServer;
1265
+ }
1266
+ });
1267
+ Object.defineProperty(exports, 'getActiveServer', {
1268
+ enumerable: true,
1269
+ get: function () {
1270
+ return getActiveServer;
1271
+ }
1272
+ });
1273
+ Object.defineProperty(exports, 'startGateway', {
1274
+ enumerable: true,
1275
+ get: function () {
1276
+ return startGateway$1;
1277
+ }
1278
+ });