hyperclaw 4.0.1 → 5.0.0

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 (277) hide show
  1. package/README.md +58 -4
  2. package/dist/a2ui-protocol-CT_jDEU9.js +75 -0
  3. package/dist/a2ui-protocol-CfBI44-Q.js +75 -0
  4. package/dist/agents-routing-683Q2JGp.js +129 -0
  5. package/dist/agents-routing-BpZBswBH.js +4 -0
  6. package/dist/agents-routing-ChHiZp36.js +327 -0
  7. package/dist/agents-routing-ChqZ6l2S.js +4 -0
  8. package/dist/api-keys-guide-BCcOl0Q7.js +149 -0
  9. package/dist/api-keys-guide-Dq5Obbp4.js +149 -0
  10. package/dist/audit-BYxPlnTQ.js +248 -0
  11. package/dist/audit-BaIiyWFu.js +441 -0
  12. package/dist/bounty-tools-C6LyzxM-.js +211 -0
  13. package/dist/bounty-tools-DWudyZie.js +211 -0
  14. package/dist/browser-tools-BsTeGMnX.js +5 -0
  15. package/dist/browser-tools-CQBSbIuO.js +5 -0
  16. package/dist/browser-tools-D8_rLe2p.js +179 -0
  17. package/dist/browser-tools-YQmwRLLM.js +179 -0
  18. package/dist/claw-tasks-BRLUvFRD.js +80 -0
  19. package/dist/claw-tasks-CgTsiNE8.js +80 -0
  20. package/dist/connector-3HnyH8fn.js +167 -0
  21. package/dist/connector-5N0-X_xs.js +194 -0
  22. package/dist/connector-6PMZo5Ky.js +189 -0
  23. package/dist/connector-B3v0qcXg.js +425 -0
  24. package/dist/connector-B6eoF3DD.js +181 -0
  25. package/dist/connector-B8R3iBY1.js +280 -0
  26. package/dist/connector-B9tLG8UZ.js +196 -0
  27. package/dist/connector-BAM-08NN.js +189 -0
  28. package/dist/connector-BC8FIVu4.js +181 -0
  29. package/dist/connector-BDmwwaVc.js +213 -0
  30. package/dist/connector-BGjbBy69.js +225 -0
  31. package/dist/connector-BO2SRzfG.js +218 -0
  32. package/dist/connector-BOlqjXWP.js +182 -0
  33. package/dist/connector-BP8zsbP8.js +189 -0
  34. package/dist/connector-BPoSevxp.js +286 -0
  35. package/dist/connector-BRHj773i.js +163 -0
  36. package/dist/connector-BToxU-jV.js +267 -0
  37. package/dist/connector-BfXky0L3.js +167 -0
  38. package/dist/connector-BiiSJpx3.js +192 -0
  39. package/dist/connector-BliDVsJQ.js +239 -0
  40. package/dist/connector-BnDmIhIu.js +85 -0
  41. package/dist/connector-Bv6s9oP7.js +88 -0
  42. package/dist/connector-By5wWGTR.js +343 -0
  43. package/dist/connector-C1BaFFgN.js +213 -0
  44. package/dist/connector-C1HSoUyk.js +189 -0
  45. package/dist/connector-CKQHZOXg.js +568 -0
  46. package/dist/connector-CRRWY5Wv.js +167 -0
  47. package/dist/connector-CRl-iidy.js +239 -0
  48. package/dist/connector-CXPQVGyI.js +85 -0
  49. package/dist/connector-Cdk1CXKi.js +194 -0
  50. package/dist/connector-Ci9glMD-.js +340 -0
  51. package/dist/connector-CjtZIEDj.js +181 -0
  52. package/dist/connector-Ck6JtOsX.js +531 -0
  53. package/dist/connector-CwlgFgjx.js +181 -0
  54. package/dist/connector-D8Kelee0.js +286 -0
  55. package/dist/connector-DAnRJ0oP.js +162 -0
  56. package/dist/connector-DFchk6l7.js +178 -0
  57. package/dist/connector-DKw7tRAy.js +192 -0
  58. package/dist/connector-DRv1ahC_.js +2 -2
  59. package/dist/connector-DU63KW94.js +165 -0
  60. package/dist/connector-DXTp5PE8.js +508 -0
  61. package/dist/connector-Dbvb1Cj9.js +280 -0
  62. package/dist/connector-DcZdQcgR.js +173 -0
  63. package/dist/connector-Dih6dUPP.js +173 -0
  64. package/dist/connector-DqTH_tPX.js +182 -0
  65. package/dist/connector-DrnEiiyP.js +419 -0
  66. package/dist/connector-DtR5GGTX.js +167 -0
  67. package/dist/connector-DxKL8VvZ.js +182 -0
  68. package/dist/connector-T_YdZtzv.js +162 -0
  69. package/dist/connector-Tky_qS_K.js +350 -0
  70. package/dist/connector-ZSc3oTTy.js +305 -0
  71. package/dist/connector-i4gOS9xL.js +154 -0
  72. package/dist/connector-rHXE1ZD2.js +167 -0
  73. package/dist/connector-sW5yhU1m.js +498 -0
  74. package/dist/connector-u3ICd3Ic.js +552 -0
  75. package/dist/connector-wdUXChwa.js +172 -0
  76. package/dist/cost-tracker-DD9wtWsr.js +103 -0
  77. package/dist/cost-tracker-pVE15Yq4.js +103 -0
  78. package/dist/credentials-store-BvnMPJwi.js +4 -0
  79. package/dist/credentials-store-C6ir0Dae.js +4 -0
  80. package/dist/credentials-store-H13LqOwJ.js +77 -0
  81. package/dist/credentials-store-sb-TRLwR.js +77 -0
  82. package/dist/cron-tasks-Bli7Kzd2.js +82 -0
  83. package/dist/cron-tasks-BvDFNyiE.js +82 -0
  84. package/dist/daemon-Bg4GtCmc.js +318 -0
  85. package/dist/daemon-DhmwY8k4.js +5 -0
  86. package/dist/delivery-BmIYy9VQ.js +4 -0
  87. package/dist/delivery-D5Z98EVq.js +95 -0
  88. package/dist/delivery-DCOXhXEO.js +5 -0
  89. package/dist/delivery-pWUPBp1F.js +95 -0
  90. package/dist/destructive-gate-D6vWOdEl.js +101 -0
  91. package/dist/destructive-gate-m-dWqUFg.js +101 -0
  92. package/dist/developer-keys-CPWT7Q6S.js +8 -0
  93. package/dist/developer-keys-DrrcUqFa.js +127 -0
  94. package/dist/developer-keys-JaJK3T27.js +127 -0
  95. package/dist/developer-keys-kyqmtWK3.js +8 -0
  96. package/dist/doctor-3oi89QIc.js +175 -0
  97. package/dist/doctor-BvCe8BBk.js +230 -0
  98. package/dist/doctor-Cf1XSfp9.js +4 -0
  99. package/dist/doctor-CxyPLYsJ.js +6 -0
  100. package/dist/engine-B4eMiTgl.js +7 -0
  101. package/dist/engine-B8M7dYul.js +7 -0
  102. package/dist/engine-BhT-1M9W.js +256 -0
  103. package/dist/engine-CEDSqXfw.js +256 -0
  104. package/dist/engine-D49jnSd_.js +256 -0
  105. package/dist/engine-Da4JMNpI.js +7 -0
  106. package/dist/env-resolve-CiXbWYwe.js +10 -0
  107. package/dist/env-resolve-CmGWhWXJ.js +115 -0
  108. package/dist/env-resolve-DWOQ45jG.js +9 -0
  109. package/dist/env-resolve-szSWl0UF.js +94 -0
  110. package/dist/extraction-tools-D3qDFBJ1.js +91 -0
  111. package/dist/extraction-tools-DLr_AEwq.js +5 -0
  112. package/dist/extraction-tools-HOZstZ0y.js +91 -0
  113. package/dist/extraction-tools-m4lmAv7l.js +5 -0
  114. package/dist/form_data-B_hIUrxU.js +8657 -0
  115. package/dist/form_data-Cz040rio.js +8657 -0
  116. package/dist/gmail-watch-setup-Czt8rXaX.js +40 -0
  117. package/dist/gmail-watch-setup-Du7DVV7S.js +40 -0
  118. package/dist/health-B-asI__D.js +6 -0
  119. package/dist/health-Ds2YlpTB.js +152 -0
  120. package/dist/heartbeat-engine-BYT5ayQH.js +83 -0
  121. package/dist/heartbeat-engine-CRqfPcFM.js +83 -0
  122. package/dist/hub-D0XwdjM-.js +515 -0
  123. package/dist/hub-DTsqe5Bt.js +6 -0
  124. package/dist/hub-FrPTA33j.js +515 -0
  125. package/dist/hub-LiD5Iztb.js +6 -0
  126. package/dist/hyperclawbot-D9KCtc4P.js +480 -0
  127. package/dist/hyperclawbot-Dw27pJo4.js +480 -0
  128. package/dist/hyperclawbot-zvczQgKx.js +505 -0
  129. package/dist/inference-BKVkBREb.js +6 -0
  130. package/dist/inference-CTWJeX9Q.js +922 -0
  131. package/dist/inference-DCXH4Q3x.js +922 -0
  132. package/dist/inference-ix607p7k.js +6 -0
  133. package/dist/knowledge-graph-DqA-Fztl.js +131 -0
  134. package/dist/knowledge-graph-iBG76fvm.js +131 -0
  135. package/dist/loader-CC45xGpC.js +4 -0
  136. package/dist/loader-CISCqBto.js +400 -0
  137. package/dist/loader-CYMQ8VOS.js +4 -0
  138. package/dist/loader-CnEdOyjT.js +400 -0
  139. package/dist/logger-8tEtAd3y.js +83 -0
  140. package/dist/logger-ybOp7VOC.js +83 -0
  141. package/dist/manager-03ipO9R0.js +105 -0
  142. package/dist/manager-BpDfbDjg.js +117 -0
  143. package/dist/manager-Bxl0sqlh.js +4 -0
  144. package/dist/manager-CPjeRe-6.js +4 -0
  145. package/dist/manager-CrVDn6eN.js +6 -0
  146. package/dist/manager-Cwzj7w5R.js +105 -0
  147. package/dist/manager-DLmZI-9R.js +6 -0
  148. package/dist/manager-DSGhn5i3.js +117 -0
  149. package/dist/manager-DgyF52mg.js +218 -0
  150. package/dist/manager-Dm8nrMFx.js +40 -0
  151. package/dist/manager-FCgF1plu.js +218 -0
  152. package/dist/manager-rgCsaWT1.js +40 -0
  153. package/dist/mcp-B_9Ber63.js +139 -0
  154. package/dist/mcp-CfoSU4Uz.js +139 -0
  155. package/dist/mcp-loader-DSM5UiFG.js +94 -0
  156. package/dist/mcp-loader-DkRBsLpk.js +94 -0
  157. package/dist/mcp-loader-j5ZLLw5O.js +94 -0
  158. package/dist/memory-BI1kPkAN.js +4 -0
  159. package/dist/memory-BVFGkxxK.js +270 -0
  160. package/dist/memory-BlHL7JCO.js +4 -0
  161. package/dist/memory-DsS_eFvJ.js +270 -0
  162. package/dist/memory-auto-Bc7euou4.js +306 -0
  163. package/dist/memory-auto-BkvtSFUw.js +5 -0
  164. package/dist/memory-auto-Bnz_-1wP.js +306 -0
  165. package/dist/memory-auto-DPfbkMVt.js +5 -0
  166. package/dist/memory-integration-DZExqWr4.js +91 -0
  167. package/dist/memory-integration-cSYkZyEo.js +91 -0
  168. package/dist/moltbook-B6ZeGN5_.js +81 -0
  169. package/dist/moltbook-BtLDZTfM.js +81 -0
  170. package/dist/node-Dw2Gi-cP.js +222 -0
  171. package/dist/node-pwL6O_KX.js +222 -0
  172. package/dist/nodes-registry-B8dmrlLv.js +52 -0
  173. package/dist/nodes-registry-CsPm_-CJ.js +52 -0
  174. package/dist/oauth-flow-CpWlgvNB.js +150 -0
  175. package/dist/oauth-flow-DQPvMHRH.js +150 -0
  176. package/dist/oauth-provider-BZb6qOw5.js +110 -0
  177. package/dist/oauth-provider-Uo4Nib_c.js +110 -0
  178. package/dist/observability-B43YvNQV.js +89 -0
  179. package/dist/observability-BV-Yx0V9.js +89 -0
  180. package/dist/onboard-0WoDxbv_.js +10 -0
  181. package/dist/onboard-BXNXCQp4.js +4070 -0
  182. package/dist/onboard-Bd_wsYdi.js +4086 -0
  183. package/dist/onboard-CAN7x3me.js +3026 -0
  184. package/dist/onboard-DnegOHMh.js +4 -4
  185. package/dist/onboard-RYtDlYBw.js +9 -0
  186. package/dist/onboard-aTwlQs-4.js +9 -0
  187. package/dist/orchestrator-BSp2M5EU.js +189 -0
  188. package/dist/orchestrator-C7ko5tWa.js +6 -0
  189. package/dist/orchestrator-DfPkIx2Z.js +6 -0
  190. package/dist/orchestrator-DmnEvMaL.js +189 -0
  191. package/dist/orchestrator-NJQsmiBE.js +189 -0
  192. package/dist/orchestrator-RI3bpqqc.js +6 -0
  193. package/dist/pairing-6iM27aD8.js +196 -0
  194. package/dist/pairing-DU0_J28n.js +87 -0
  195. package/dist/pairing-DWllbSbO.js +4 -0
  196. package/dist/pairing-dGoiGepK.js +4 -0
  197. package/dist/pc-access-CgCsYrpt.js +8 -0
  198. package/dist/pc-access-Ly-uA8mn.js +8 -0
  199. package/dist/pc-access-NxBvTrRj.js +819 -0
  200. package/dist/pc-access-_iH2aorG.js +819 -0
  201. package/dist/pending-approval-CUXjysAo.js +22 -0
  202. package/dist/pending-approval-DIHvwwWS.js +22 -0
  203. package/dist/puppeteer-2o3QOwAy.js +2 -2
  204. package/dist/puppeteer-BYTMp3BI.js +2 -2
  205. package/dist/puppeteer-DQ45qwWk.js +2 -2
  206. package/dist/reminders-store-D79qdfN0.js +58 -0
  207. package/dist/reminders-store-Drjed_-h.js +58 -0
  208. package/dist/renderer-BVQrd0_g.js +225 -0
  209. package/dist/renderer-pqlDRKbH.js +225 -0
  210. package/dist/rules-BE4GV6cV.js +103 -0
  211. package/dist/rules-BooT_qFP.js +103 -0
  212. package/dist/run-main.js +1649 -1227
  213. package/dist/runner-D1rjuMTJ.js +810 -0
  214. package/dist/runner-DatMMYYE.js +1271 -0
  215. package/dist/sdk/index.js +2 -2
  216. package/dist/sdk/index.mjs +2 -2
  217. package/dist/security-BqNyT4ID.js +4 -0
  218. package/dist/security-C-5URby1.js +73 -0
  219. package/dist/security-_xve79aq.js +4 -0
  220. package/dist/security-tpgqPWWH.js +73 -0
  221. package/dist/server-0kgyELx4.js +1047 -0
  222. package/dist/server-BIuTobTC.js +4 -0
  223. package/dist/server-BRlCEjyT.js +1047 -0
  224. package/dist/server-CCI1hv45.js +2 -2
  225. package/dist/server-D4wVHiX9.js +4 -0
  226. package/dist/server-DU9POoWc.js +4 -0
  227. package/dist/server-Dh3JlBFB.js +1255 -0
  228. package/dist/session-store-BUiPz0Vv.js +5 -0
  229. package/dist/session-store-CujxByI6.js +113 -0
  230. package/dist/session-store-is4B6qmD.js +113 -0
  231. package/dist/session-store-qpJUg2M1.js +5 -0
  232. package/dist/sessions-tools-CB2qbwIk.js +5 -0
  233. package/dist/sessions-tools-CbUTFe4i.js +5 -0
  234. package/dist/sessions-tools-CeqD7iil.js +95 -0
  235. package/dist/sessions-tools-DHMaTZIs.js +95 -0
  236. package/dist/skill-loader-BaNLVmJy.js +7 -0
  237. package/dist/skill-loader-BkceKkIg.js +7 -0
  238. package/dist/skill-loader-DhgIwK4J.js +159 -0
  239. package/dist/skill-loader-HgpF6Vqs.js +159 -0
  240. package/dist/skill-runtime--LqxWrp5.js +102 -0
  241. package/dist/skill-runtime-C5l0Tgt-.js +5 -0
  242. package/dist/skill-runtime-CJN24QPW.js +102 -0
  243. package/dist/skill-runtime-DsXK_HYG.js +102 -0
  244. package/dist/skill-runtime-IVTiqrMR.js +5 -0
  245. package/dist/skill-runtime-w1ig_lcw.js +5 -0
  246. package/dist/src-BEVLgaF1.js +63 -0
  247. package/dist/src-Bgu_OxTQ.js +458 -0
  248. package/dist/src-Bq-oKt7Z.js +458 -0
  249. package/dist/src-BxPHKO5x.js +63 -0
  250. package/dist/src-DIc-L2IG.js +20 -0
  251. package/dist/src-DWCUhnD4.js +20 -0
  252. package/dist/src-cfRTjFef.js +63 -0
  253. package/dist/src-g_rNx5rh.js +458 -0
  254. package/dist/sub-agent-tools-BD9DF8_g.js +39 -0
  255. package/dist/sub-agent-tools-CHQoHz9c.js +39 -0
  256. package/dist/sub-agent-tools-V7b3T9_s.js +39 -0
  257. package/dist/theme-DcxwcUgZ.js +180 -0
  258. package/dist/theme-cx0fkgWC.js +8 -0
  259. package/dist/tool-policy-CNT-mF2Z.js +189 -0
  260. package/dist/tool-policy-DNvNRnve.js +189 -0
  261. package/dist/tts-elevenlabs-BRosZv-f.js +61 -0
  262. package/dist/tts-elevenlabs-BUOGKL-k.js +61 -0
  263. package/dist/update-check-BD4qH7Am.js +81 -0
  264. package/dist/update-check-C2Dz85wJ.js +81 -0
  265. package/dist/vision-BMmiIKy7.js +121 -0
  266. package/dist/vision-DRq-f-Dj.js +121 -0
  267. package/dist/vision-tools-CFZEpQKm.js +5 -0
  268. package/dist/vision-tools-CQnBI9aa.js +51 -0
  269. package/dist/vision-tools-DVuYc17I.js +51 -0
  270. package/dist/vision-tools-U3YC4L-g.js +5 -0
  271. package/dist/voice-transcription-B555DbWR.js +138 -0
  272. package/dist/voice-transcription-CgWq54hn.js +138 -0
  273. package/dist/website-watch-tools-Bk_TnwuE.js +5 -0
  274. package/dist/website-watch-tools-DFMrJU-R.js +139 -0
  275. package/dist/website-watch-tools-DraMPxdl.js +139 -0
  276. package/dist/website-watch-tools-Du3W5sN7.js +5 -0
  277. package/package.json +1 -1
@@ -0,0 +1,508 @@
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 os = require_chunk.__toESM(require("os"));
6
+ const child_process = require_chunk.__toESM(require("child_process"));
7
+ const http = require_chunk.__toESM(require("http"));
8
+ const https = require_chunk.__toESM(require("https"));
9
+ const events = require_chunk.__toESM(require("events"));
10
+
11
+ //#region extensions/signal/src/connector.ts
12
+ const STATE_DIR = path.default.join(os.default.homedir(), ".hyperclaw");
13
+ const PAIRING_EXPIRY_MS = 60 * 60 * 1e3;
14
+ const SSE_RECONNECT_DELAY_MS = 5e3;
15
+ function cliReq(daemonUrl, method, endpoint, body) {
16
+ return new Promise((resolve, reject) => {
17
+ const base = daemonUrl.replace(/\/$/, "");
18
+ const url = new URL(endpoint.startsWith("/") ? endpoint : `/${endpoint}`, base);
19
+ const isHttps = url.protocol === "https:";
20
+ const mod = isHttps ? https.default : http.default;
21
+ const payload = body ? JSON.stringify(body) : null;
22
+ const req = mod.request({
23
+ hostname: url.hostname,
24
+ port: parseInt(url.port || (isHttps ? "443" : "8080"), 10),
25
+ path: url.pathname + (url.search || ""),
26
+ method,
27
+ headers: payload ? {
28
+ "Content-Type": "application/json",
29
+ "Content-Length": Buffer.byteLength(payload)
30
+ } : {}
31
+ }, (res) => {
32
+ let data = "";
33
+ res.on("data", (c) => data += c.toString());
34
+ res.on("end", () => {
35
+ if (!data.trim()) {
36
+ resolve({});
37
+ return;
38
+ }
39
+ try {
40
+ resolve(JSON.parse(data));
41
+ } catch {
42
+ resolve({ raw: data });
43
+ }
44
+ });
45
+ });
46
+ req.on("error", reject);
47
+ if (payload) req.write(payload);
48
+ req.end();
49
+ });
50
+ }
51
+ function chunkText(text, limit, mode) {
52
+ if (mode === "newline") {
53
+ const paragraphs = text.split(/\n\s*\n/);
54
+ const result = [];
55
+ let buf = "";
56
+ for (const p of paragraphs) if ((buf + (buf ? "\n\n" : "") + p).length > limit) {
57
+ if (buf) {
58
+ result.push(buf);
59
+ buf = "";
60
+ }
61
+ if (p.length > limit) {
62
+ const subs = p.match(new RegExp(`.{1,${limit}}`, "gs")) || [p];
63
+ result.push(...subs.slice(0, -1));
64
+ buf = subs[subs.length - 1];
65
+ } else buf = p;
66
+ } else buf = buf ? `${buf}\n\n${p}` : p;
67
+ if (buf) result.push(buf);
68
+ return result;
69
+ }
70
+ return text.match(new RegExp(`.{1,${limit}}`, "gs")) || [text];
71
+ }
72
+ function normalizeSender(source, sourceUuid) {
73
+ if (sourceUuid) return `uuid:${sourceUuid}`;
74
+ return source ?? "";
75
+ }
76
+ function senderAllowed(sender, allowList) {
77
+ if (!allowList.length) return false;
78
+ return allowList.some((p) => {
79
+ if (p === "*") return true;
80
+ if (p === sender) return true;
81
+ if (p.startsWith("uuid:") && sender === p) return true;
82
+ if (!p.startsWith("uuid:") && sender === `uuid:${p}`) return true;
83
+ return false;
84
+ });
85
+ }
86
+ function resolveAccount(id, raw, state) {
87
+ const host = raw.httpHost ?? "127.0.0.1";
88
+ const port = raw.httpPort ?? 8080;
89
+ const daemonUrl = raw.httpUrl ?? `http://${host}:${port}`;
90
+ const hasExternalUrl = !!raw.httpUrl;
91
+ return {
92
+ id,
93
+ name: raw.name ?? id,
94
+ account: raw.account ?? "",
95
+ cliPath: raw.cliPath ?? "signal-cli",
96
+ daemonUrl,
97
+ autoStart: raw.autoStart ?? !hasExternalUrl,
98
+ startupTimeoutMs: Math.min(raw.startupTimeoutMs ?? 15e3, 12e4),
99
+ receiveMode: raw.receiveMode ?? "on-start",
100
+ dmPolicy: raw.dmPolicy ?? "pairing",
101
+ allowFrom: raw.allowFrom ?? [],
102
+ groupPolicy: raw.groupPolicy ?? "allowlist",
103
+ groupAllowFrom: raw.groupAllowFrom ?? [],
104
+ historyLimit: raw.historyLimit ?? 50,
105
+ dmHistoryLimit: raw.dmHistoryLimit ?? 50,
106
+ textChunkLimit: raw.textChunkLimit ?? 4e3,
107
+ chunkMode: raw.chunkMode ?? "length",
108
+ mediaMaxMb: raw.mediaMaxMb ?? 8,
109
+ ignoreAttachments: raw.ignoreAttachments ?? false,
110
+ ignoreStories: raw.ignoreStories ?? false,
111
+ sendReadReceipts: raw.sendReadReceipts ?? false,
112
+ configWrites: raw.configWrites ?? true,
113
+ actions: {
114
+ reactions: true,
115
+ ...raw.actions
116
+ },
117
+ reactionLevel: raw.reactionLevel ?? "minimal",
118
+ approvedPairings: state.approved,
119
+ pendingPairings: state.pending
120
+ };
121
+ }
122
+ var SingleAccountConnector = class extends events.EventEmitter {
123
+ acc;
124
+ daemon = null;
125
+ sseActive = false;
126
+ sseReconnect = false;
127
+ constructor(acc) {
128
+ super();
129
+ this.acc = acc;
130
+ }
131
+ async connect() {
132
+ if (this.acc.autoStart) await this._spawnDaemon();
133
+ await cliReq(this.acc.daemonUrl, "GET", "/v1/accounts");
134
+ await this._loadState();
135
+ console.log(chalk.default.green(` 🦅 Signal[${this.acc.id}]: ${this.acc.account || "linked"} connected via ${this.acc.daemonUrl}`));
136
+ this.emit("connected", {
137
+ accountId: this.acc.id,
138
+ account: this.acc.account,
139
+ daemonUrl: this.acc.daemonUrl
140
+ });
141
+ if (this.acc.receiveMode === "on-start") this._startSSE();
142
+ }
143
+ disconnect() {
144
+ this.sseReconnect = false;
145
+ this.sseActive = false;
146
+ if (this.daemon) {
147
+ this.daemon.kill();
148
+ this.daemon = null;
149
+ }
150
+ }
151
+ async _spawnDaemon() {
152
+ const { cliPath, account, httpHost, httpPort } = {
153
+ cliPath: this.acc.cliPath,
154
+ account: this.acc.account,
155
+ httpHost: new URL(this.acc.daemonUrl).hostname,
156
+ httpPort: parseInt(new URL(this.acc.daemonUrl).port || "8080", 10)
157
+ };
158
+ if (!account) throw new Error(`Signal[${this.acc.id}]: 'account' (phone number) is required for autoStart`);
159
+ console.log(chalk.default.gray(` Signal[${this.acc.id}]: spawning daemon ${cliPath} -a ${account} daemon --http...`));
160
+ this.daemon = (0, child_process.spawn)(cliPath, [
161
+ "-a",
162
+ account,
163
+ "daemon",
164
+ "--http",
165
+ `--port=${httpPort}`,
166
+ `--http-host=${httpHost}`
167
+ ], {
168
+ detached: false,
169
+ stdio: [
170
+ "ignore",
171
+ "pipe",
172
+ "pipe"
173
+ ]
174
+ });
175
+ this.daemon.stderr?.on("data", (d) => {
176
+ const line = d.toString().trim();
177
+ if (line) console.log(chalk.default.gray(` [signal-cli] ${line}`));
178
+ });
179
+ this.daemon.on("exit", (code) => {
180
+ console.log(chalk.default.yellow(` ⚠ Signal[${this.acc.id}]: daemon exited (code ${code})`));
181
+ });
182
+ const deadline = Date.now() + this.acc.startupTimeoutMs;
183
+ while (Date.now() < deadline) try {
184
+ await cliReq(this.acc.daemonUrl, "GET", "/v1/accounts");
185
+ return;
186
+ } catch {
187
+ await new Promise((r) => setTimeout(r, 500));
188
+ }
189
+ throw new Error(`Signal[${this.acc.id}]: daemon did not start within ${this.acc.startupTimeoutMs}ms`);
190
+ }
191
+ _startSSE() {
192
+ this.sseReconnect = true;
193
+ this._connectSSE();
194
+ }
195
+ _connectSSE() {
196
+ if (!this.sseReconnect) return;
197
+ const url = new URL("/v1/events", this.acc.daemonUrl);
198
+ if (this.acc.account) url.searchParams.set("account", this.acc.account);
199
+ const isHttps = url.protocol === "https:";
200
+ const mod = isHttps ? https.default : http.default;
201
+ const req = mod.request({
202
+ hostname: url.hostname,
203
+ port: parseInt(url.port || (isHttps ? "443" : "8080"), 10),
204
+ path: url.pathname + url.search,
205
+ method: "GET",
206
+ headers: {
207
+ Accept: "text/event-stream",
208
+ "Cache-Control": "no-cache"
209
+ }
210
+ }, (res) => {
211
+ this.sseActive = true;
212
+ let buf = "";
213
+ res.on("data", (chunk) => {
214
+ buf += chunk.toString();
215
+ const lines = buf.split("\n");
216
+ buf = lines.pop() ?? "";
217
+ let dataLine = "";
218
+ for (const line of lines) if (line.startsWith("data:")) dataLine = line.slice(5).trim();
219
+ else if (line === "" && dataLine) {
220
+ try {
221
+ this._handleEnvelope(JSON.parse(dataLine));
222
+ } catch {}
223
+ dataLine = "";
224
+ }
225
+ });
226
+ res.on("end", () => {
227
+ this.sseActive = false;
228
+ if (this.sseReconnect) {
229
+ console.log(chalk.default.yellow(` Signal[${this.acc.id}]: SSE disconnected, reconnecting...`));
230
+ setTimeout(() => this._connectSSE(), SSE_RECONNECT_DELAY_MS);
231
+ }
232
+ });
233
+ res.on("error", () => {
234
+ this.sseActive = false;
235
+ if (this.sseReconnect) setTimeout(() => this._connectSSE(), SSE_RECONNECT_DELAY_MS);
236
+ });
237
+ });
238
+ req.on("error", () => {
239
+ if (this.sseReconnect) setTimeout(() => this._connectSSE(), SSE_RECONNECT_DELAY_MS);
240
+ });
241
+ req.end();
242
+ }
243
+ _handleEnvelope(ev) {
244
+ const envelope = ev.envelope ?? ev;
245
+ if (!envelope) return;
246
+ if (this.acc.ignoreStories && envelope.storyMessage) return;
247
+ const dataMessage = envelope.dataMessage ?? envelope.syncMessage?.sentMessage?.dataMessage;
248
+ if (!dataMessage) return;
249
+ if (!dataMessage.message && !dataMessage.attachments?.length) return;
250
+ const source = envelope.source;
251
+ const sourceUuid = envelope.sourceUuid;
252
+ const from = normalizeSender(source, sourceUuid);
253
+ const timestamp = envelope.timestamp ?? Date.now();
254
+ const msgId = String(timestamp);
255
+ const text = dataMessage.message?.trim() ?? "";
256
+ const groupInfo = dataMessage.groupInfo ?? dataMessage.groupV2;
257
+ if (groupInfo?.groupId) this._routeGroup(from, groupInfo.groupId, text, msgId, dataMessage);
258
+ else this._routeDM(from, text, msgId, dataMessage);
259
+ }
260
+ async _routeDM(from, text, msgId, dataMessage) {
261
+ const acc = this.acc;
262
+ if (acc.dmPolicy === "disabled") return;
263
+ if (acc.sendReadReceipts) this._sendReadReceipt(from, parseInt(msgId, 10)).catch(() => {});
264
+ if (acc.dmPolicy === "open") {
265
+ this._emitMessage(from, from, text, msgId, true, void 0, dataMessage);
266
+ return;
267
+ }
268
+ if (acc.dmPolicy === "allowlist") {
269
+ if (!senderAllowed(from, acc.allowFrom)) {
270
+ console.log(chalk.default.gray(` signal[${acc.id}]: drop DM from ${from} (dmPolicy=allowlist)`));
271
+ return;
272
+ }
273
+ this._emitMessage(from, from, text, msgId, true, void 0, dataMessage);
274
+ return;
275
+ }
276
+ if (acc.dmPolicy === "pairing") {
277
+ const now = Date.now();
278
+ for (const [code$1, entry] of Object.entries(acc.pendingPairings)) if (entry.expiresAt < now) delete acc.pendingPairings[code$1];
279
+ if (acc.approvedPairings.includes(from) || senderAllowed(from, acc.allowFrom)) {
280
+ this._emitMessage(from, from, text, msgId, true, void 0, dataMessage);
281
+ return;
282
+ }
283
+ const upper = text.trim().toUpperCase();
284
+ const existing = Object.entries(acc.pendingPairings).find(([code$1]) => code$1 === upper);
285
+ if (existing && existing[1].sender === from) {
286
+ acc.approvedPairings.push(from);
287
+ delete acc.pendingPairings[upper];
288
+ await this._saveState();
289
+ await this.sendMessage(from, "🦅 Paired!");
290
+ this.emit("pairing:approved", {
291
+ accountId: acc.id,
292
+ sender: from
293
+ });
294
+ return;
295
+ }
296
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
297
+ acc.pendingPairings[code] = {
298
+ sender: from,
299
+ expiresAt: now + PAIRING_EXPIRY_MS
300
+ };
301
+ await this._saveState();
302
+ await this.sendMessage(from, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve signal ${code}\n(Expires in 1 hour)`);
303
+ }
304
+ }
305
+ _routeGroup(from, groupId, text, msgId, dataMessage) {
306
+ const acc = this.acc;
307
+ if (acc.groupPolicy === "disabled") return;
308
+ if (acc.groupPolicy === "allowlist") {
309
+ const combined = [...acc.groupAllowFrom ?? [], ...acc.allowFrom ?? []];
310
+ if (combined.length && !senderAllowed(from, combined)) {
311
+ console.log(chalk.default.gray(` signal[${acc.id}]: drop group msg from ${from} in ${groupId} (allowlist)`));
312
+ return;
313
+ }
314
+ }
315
+ const chatId = `signal:group:${groupId}`;
316
+ this._emitMessage(from, chatId, text, msgId, false, groupId, dataMessage);
317
+ }
318
+ _emitMessage(from, chatId, text, msgId, isDM, groupId, dataMessage) {
319
+ const attachments = [];
320
+ if (!this.acc.ignoreAttachments && Array.isArray(dataMessage?.attachments)) for (const att of dataMessage.attachments) {
321
+ const sizeMb = (att.size ?? 0) / (1024 * 1024);
322
+ if (sizeMb <= this.acc.mediaMaxMb) attachments.push(att.id ?? att.filename ?? "");
323
+ }
324
+ const payload = {
325
+ accountId: this.acc.id,
326
+ id: msgId,
327
+ from,
328
+ chatId,
329
+ text,
330
+ timestamp: new Date(parseInt(msgId, 10)).toISOString(),
331
+ isDM,
332
+ ...groupId ? { groupId } : {},
333
+ ...attachments.length ? { attachments } : {}
334
+ };
335
+ this.emit("message", payload);
336
+ }
337
+ async sendMessage(recipient, text, groupId) {
338
+ const chunks = chunkText(text, this.acc.textChunkLimit, this.acc.chunkMode);
339
+ for (const chunk of chunks) {
340
+ const body = {
341
+ number: this.acc.account,
342
+ message: chunk
343
+ };
344
+ if (groupId) body.group_id = groupId;
345
+ else {
346
+ const resolvedRecipient = recipient.startsWith("uuid:") ? void 0 : recipient;
347
+ const resolvedUuid = recipient.startsWith("uuid:") ? recipient.slice(5) : void 0;
348
+ if (resolvedUuid) body.recipients = [{ uuid: resolvedUuid }];
349
+ else body.recipients = [resolvedRecipient];
350
+ }
351
+ await cliReq(this.acc.daemonUrl, "POST", "/v2/send", body);
352
+ }
353
+ }
354
+ async sendTyping(recipient, groupId, stop = false) {
355
+ try {
356
+ const body = {
357
+ number: this.acc.account,
358
+ stop
359
+ };
360
+ if (groupId) body.group_id = groupId;
361
+ else body.recipient = recipient.startsWith("uuid:") ? { uuid: recipient.slice(5) } : recipient;
362
+ await cliReq(this.acc.daemonUrl, "PUT", "/v1/typing", body);
363
+ } catch {}
364
+ }
365
+ async _sendReadReceipt(sender, timestamp) {
366
+ const body = {
367
+ number: this.acc.account,
368
+ receipt_type: "read",
369
+ timestamps: [timestamp]
370
+ };
371
+ if (sender.startsWith("uuid:")) body.recipient = { uuid: sender.slice(5) };
372
+ else body.recipient = sender;
373
+ await cliReq(this.acc.daemonUrl, "POST", "/v1/receipts", body);
374
+ }
375
+ async addReaction(recipient, emoji, targetTimestamp, targetAuthor, groupId) {
376
+ if (!this.acc.actions.reactions || this.acc.reactionLevel === "off" || this.acc.reactionLevel === "ack") return;
377
+ const body = {
378
+ number: this.acc.account,
379
+ emoji,
380
+ target_author: targetAuthor ?? recipient,
381
+ timestamp: targetTimestamp,
382
+ remove: false
383
+ };
384
+ if (groupId) body.group_id = groupId;
385
+ else body.recipient = recipient.startsWith("uuid:") ? { uuid: recipient.slice(5) } : recipient;
386
+ await cliReq(this.acc.daemonUrl, "POST", `/v1/reactions/${encodeURIComponent(this.acc.account)}`, body);
387
+ }
388
+ async removeReaction(recipient, emoji, targetTimestamp, targetAuthor, groupId) {
389
+ if (!this.acc.actions.reactions) return;
390
+ const body = {
391
+ number: this.acc.account,
392
+ emoji,
393
+ target_author: targetAuthor ?? recipient,
394
+ timestamp: targetTimestamp,
395
+ remove: true
396
+ };
397
+ if (groupId) body.group_id = groupId;
398
+ else body.recipient = recipient.startsWith("uuid:") ? { uuid: recipient.slice(5) } : recipient;
399
+ await cliReq(this.acc.daemonUrl, "POST", `/v1/reactions/${encodeURIComponent(this.acc.account)}`, body);
400
+ }
401
+ approvePairing(code) {
402
+ const upper = code.toUpperCase();
403
+ const entry = this.acc.pendingPairings[upper];
404
+ if (!entry) return false;
405
+ if (Date.now() > entry.expiresAt) {
406
+ delete this.acc.pendingPairings[upper];
407
+ this._saveState();
408
+ return false;
409
+ }
410
+ this.acc.approvedPairings.push(entry.sender);
411
+ delete this.acc.pendingPairings[upper];
412
+ this._saveState();
413
+ return true;
414
+ }
415
+ listPendingPairings() {
416
+ const now = Date.now();
417
+ const result = {};
418
+ for (const [code, entry] of Object.entries(this.acc.pendingPairings)) if (entry.expiresAt > now) result[code] = entry.sender;
419
+ return result;
420
+ }
421
+ _stateFile() {
422
+ return path.default.join(STATE_DIR, `signal-state-${this.acc.id}.json`);
423
+ }
424
+ async _saveState() {
425
+ await fs_extra.default.ensureDir(STATE_DIR);
426
+ await fs_extra.default.writeJson(this._stateFile(), {
427
+ approvedPairings: this.acc.approvedPairings,
428
+ pendingPairings: this.acc.pendingPairings
429
+ }, { spaces: 2 });
430
+ }
431
+ async _loadState() {
432
+ try {
433
+ const s = await fs_extra.default.readJson(this._stateFile());
434
+ if (Array.isArray(s.approvedPairings)) this.acc.approvedPairings = s.approvedPairings;
435
+ if (s.pendingPairings && typeof s.pendingPairings === "object") this.acc.pendingPairings = s.pendingPairings;
436
+ } catch {}
437
+ }
438
+ };
439
+ var SignalConnector = class extends events.EventEmitter {
440
+ accounts = /* @__PURE__ */ new Map();
441
+ rawConfig;
442
+ constructor(config) {
443
+ super();
444
+ this.rawConfig = config;
445
+ }
446
+ async connect() {
447
+ const cfg = this.rawConfig;
448
+ const accountDefs = cfg.accounts ?? { default: cfg };
449
+ for (const [id, rawAcc] of Object.entries(accountDefs)) {
450
+ const merged = {
451
+ ...cfg,
452
+ ...rawAcc
453
+ };
454
+ const state = {
455
+ approved: cfg.approvedPairings ?? [],
456
+ pending: cfg.pendingPairings ?? {}
457
+ };
458
+ const acc = resolveAccount(id, merged, state);
459
+ if (!acc.account && acc.autoStart) {
460
+ console.log(chalk.default.yellow(` ⚠ Signal[${id}]: 'account' required for autoStart — skipping`));
461
+ continue;
462
+ }
463
+ const conn = new SingleAccountConnector(acc);
464
+ await conn._loadState();
465
+ conn.on("message", (msg) => this.emit("message", msg));
466
+ conn.on("connected", (info) => this.emit("connected", info));
467
+ conn.on("pairing:approved", (info) => this.emit("pairing:approved", info));
468
+ await conn.connect();
469
+ this.accounts.set(id, conn);
470
+ }
471
+ }
472
+ disconnect() {
473
+ for (const conn of this.accounts.values()) conn.disconnect();
474
+ this.accounts.clear();
475
+ }
476
+ _acc(accountId = "default") {
477
+ const conn = this.accounts.get(accountId);
478
+ if (!conn) throw new Error(`Signal: account '${accountId}' not found`);
479
+ return conn;
480
+ }
481
+ async sendMessage(recipient, text, groupId, accountId) {
482
+ return this._acc(accountId).sendMessage(recipient, text, groupId);
483
+ }
484
+ async sendTyping(recipient, groupId, stop, accountId) {
485
+ return this._acc(accountId).sendTyping(recipient, groupId, stop);
486
+ }
487
+ async addReaction(recipient, emoji, targetTimestamp, targetAuthor, groupId, accountId) {
488
+ return this._acc(accountId).addReaction(recipient, emoji, targetTimestamp, targetAuthor, groupId);
489
+ }
490
+ async removeReaction(recipient, emoji, targetTimestamp, targetAuthor, groupId, accountId) {
491
+ return this._acc(accountId).removeReaction(recipient, emoji, targetTimestamp, targetAuthor, groupId);
492
+ }
493
+ approvePairing(code, accountId) {
494
+ return this._acc(accountId).approvePairing(code);
495
+ }
496
+ listPendingPairings(accountId) {
497
+ return this._acc(accountId).listPendingPairings();
498
+ }
499
+ getAccountIds() {
500
+ return Array.from(this.accounts.keys());
501
+ }
502
+ isRunning() {
503
+ return this.accounts.size > 0;
504
+ }
505
+ };
506
+
507
+ //#endregion
508
+ exports.SignalConnector = SignalConnector;