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,267 @@
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 http = require_chunk.__toESM(require("http"));
7
+ const https = require_chunk.__toESM(require("https"));
8
+ const events = require_chunk.__toESM(require("events"));
9
+
10
+ //#region extensions/tlon/src/connector.ts
11
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "tlon-state.json");
12
+ var TlonConnector = class extends events.EventEmitter {
13
+ config;
14
+ cookie = null;
15
+ channelUid = null;
16
+ running = false;
17
+ lastEventId = 0;
18
+ sseAbort = null;
19
+ constructor(config) {
20
+ super();
21
+ this.config = {
22
+ dmPolicy: "pairing",
23
+ allowFrom: [],
24
+ approvedPairings: [],
25
+ pendingPairings: {},
26
+ ...config
27
+ };
28
+ }
29
+ async connect() {
30
+ await this.loadState();
31
+ await this.login();
32
+ await this.openChannel();
33
+ await this.subscribe();
34
+ this.running = true;
35
+ console.log(chalk.default.green(` 🦅 Tlon: connected as ${this.config.ship}`));
36
+ this.emit("connected", { ship: this.config.ship });
37
+ this.listenSSE();
38
+ }
39
+ disconnect() {
40
+ this.running = false;
41
+ this.sseAbort?.abort();
42
+ }
43
+ async login() {
44
+ const body = `password=${encodeURIComponent(this.config.code)}`;
45
+ const cookie = await this.urbitReq("POST", "/~/login", body, "application/x-www-form-urlencoded");
46
+ if (!cookie) throw new Error("Tlon: login failed — check ship URL and code");
47
+ this.cookie = cookie;
48
+ }
49
+ async openChannel() {
50
+ this.channelUid = `hyperclaw-${Date.now()}`;
51
+ await this.urbitPut([]);
52
+ }
53
+ async subscribe() {
54
+ const actions = [];
55
+ actions.push({
56
+ id: ++this.lastEventId,
57
+ action: "subscribe",
58
+ ship: this.config.ship,
59
+ app: "chat-store",
60
+ path: "/keys"
61
+ });
62
+ if (this.config.group) {
63
+ const [groupShip, groupName] = this.config.group.split("/");
64
+ actions.push({
65
+ id: ++this.lastEventId,
66
+ action: "subscribe",
67
+ ship: groupShip,
68
+ app: "graph-store",
69
+ path: `/updates`
70
+ });
71
+ }
72
+ await this.urbitPut(actions);
73
+ }
74
+ listenSSE() {
75
+ this.sseAbort = new AbortController();
76
+ const url = new URL(`/~/channel/${this.channelUid}`, this.config.shipUrl);
77
+ const isHttps = url.protocol === "https:";
78
+ const mod = isHttps ? https.default : http.default;
79
+ const doRequest = () => {
80
+ if (!this.running) return;
81
+ const req = mod.request({
82
+ hostname: url.hostname,
83
+ port: url.port || (isHttps ? 443 : 80),
84
+ path: url.pathname,
85
+ method: "GET",
86
+ headers: {
87
+ "Cookie": this.cookie,
88
+ "Accept": "text/event-stream"
89
+ }
90
+ }, async (res) => {
91
+ let buf = "";
92
+ res.on("data", async (chunk) => {
93
+ buf += chunk.toString();
94
+ const lines = buf.split("\n");
95
+ buf = lines.pop() || "";
96
+ for (const line of lines) {
97
+ if (!line.startsWith("data: ")) continue;
98
+ try {
99
+ const data = JSON.parse(line.slice(6));
100
+ await this.handleEvent(data);
101
+ } catch {}
102
+ }
103
+ });
104
+ res.on("end", () => {
105
+ if (this.running) setTimeout(doRequest, 3e3);
106
+ });
107
+ res.on("error", () => {
108
+ if (this.running) setTimeout(doRequest, 5e3);
109
+ });
110
+ });
111
+ req.on("error", () => {
112
+ if (this.running) setTimeout(doRequest, 5e3);
113
+ });
114
+ req.end();
115
+ };
116
+ doRequest();
117
+ }
118
+ async handleEvent(event) {
119
+ if (event.id) await this.urbitDelete(event.id).catch(() => {});
120
+ const response = event.response;
121
+ if (!response || response === "poke" || response === "subscribe") return;
122
+ if (response === "diff" && event.json?.["chat-update"]?.["message"]) {
123
+ const msg = event.json["chat-update"]["message"];
124
+ const path$2 = msg.path || "";
125
+ const envelope = msg.envelope;
126
+ if (!envelope) return;
127
+ const author = envelope.author || "unknown";
128
+ const text = envelope.letter?.text || "";
129
+ if (!text || author === this.config.ship) return;
130
+ const allowed = await this.checkPolicy(author, path$2, text);
131
+ if (!allowed) return;
132
+ this.emit("message", {
133
+ id: `tlon-${envelope.uid || Date.now()}`,
134
+ channelId: "tlon",
135
+ from: author,
136
+ chatId: path$2,
137
+ text,
138
+ timestamp: new Date(envelope.when || Date.now()).toISOString(),
139
+ isDM: path$2.startsWith("/~~/dm")
140
+ });
141
+ }
142
+ }
143
+ async checkPolicy(author, chatId, text) {
144
+ if (this.config.dmPolicy === "none") return false;
145
+ if (this.config.dmPolicy === "open") return true;
146
+ if (this.config.dmPolicy === "allowlist") {
147
+ if (this.config.allowFrom.includes(author)) return true;
148
+ await this.sendDM(author, "🦅 You are not on the allowlist.");
149
+ return false;
150
+ }
151
+ if (this.config.dmPolicy === "pairing") {
152
+ if (this.config.approvedPairings.includes(author)) return true;
153
+ const upper = text.trim().toUpperCase();
154
+ if (this.config.pendingPairings[upper]) {
155
+ this.config.approvedPairings.push(author);
156
+ delete this.config.pendingPairings[upper];
157
+ await this.saveState();
158
+ await this.sendDM(author, "🦅 Paired! You can now chat with the assistant.");
159
+ return true;
160
+ }
161
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
162
+ this.config.pendingPairings[code] = author;
163
+ await this.saveState();
164
+ await this.sendDM(author, `🦅 Pairing required. Code: ${code}\nApprove: hyperclaw pairing approve tlon ${code}`);
165
+ return false;
166
+ }
167
+ return false;
168
+ }
169
+ async sendDM(ship, text) {
170
+ const dmPath = `/~~/dm/${ship}/`;
171
+ await this.poke("chat-hook", "json", { "chat-action": { "message": {
172
+ path: dmPath,
173
+ envelope: {
174
+ uid: Math.random().toString(36).slice(2),
175
+ number: Date.now(),
176
+ author: this.config.ship,
177
+ when: Date.now(),
178
+ letter: { text }
179
+ }
180
+ } } });
181
+ }
182
+ async sendToPath(chatPath, text) {
183
+ await this.poke("chat-hook", "json", { "chat-action": { "message": {
184
+ path: chatPath,
185
+ envelope: {
186
+ uid: Math.random().toString(36).slice(2),
187
+ number: Date.now(),
188
+ author: this.config.ship,
189
+ when: Date.now(),
190
+ letter: { text }
191
+ }
192
+ } } });
193
+ }
194
+ async poke(app, mark, json) {
195
+ await this.urbitPut([{
196
+ id: ++this.lastEventId,
197
+ action: "poke",
198
+ ship: this.config.ship,
199
+ app,
200
+ mark,
201
+ json
202
+ }]);
203
+ }
204
+ approvePairing(code) {
205
+ const upper = code.toUpperCase();
206
+ if (!this.config.pendingPairings[upper]) return false;
207
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
208
+ delete this.config.pendingPairings[upper];
209
+ this.saveState();
210
+ return true;
211
+ }
212
+ async urbitReq(method, p, body, contentType) {
213
+ return new Promise((resolve, reject) => {
214
+ const url = new URL(p, this.config.shipUrl);
215
+ const isHttps = url.protocol === "https:";
216
+ const mod = isHttps ? https.default : http.default;
217
+ const headers = {};
218
+ if (this.cookie) headers["Cookie"] = this.cookie;
219
+ if (body) {
220
+ headers["Content-Type"] = contentType || "application/json";
221
+ headers["Content-Length"] = String(Buffer.byteLength(body));
222
+ }
223
+ const req = mod.request({
224
+ hostname: url.hostname,
225
+ port: url.port || (isHttps ? 443 : 80),
226
+ path: url.pathname,
227
+ method,
228
+ headers
229
+ }, (res) => {
230
+ const setCookie = res.headers["set-cookie"]?.[0]?.split(";")[0] || null;
231
+ let data = "";
232
+ res.on("data", (c) => data += c);
233
+ res.on("end", () => resolve(setCookie || data || null));
234
+ });
235
+ req.on("error", reject);
236
+ if (body) req.write(body);
237
+ req.end();
238
+ });
239
+ }
240
+ async urbitPut(actions) {
241
+ const body = JSON.stringify(actions);
242
+ await this.urbitReq("PUT", `/~/channel/${this.channelUid}`, body);
243
+ }
244
+ async urbitDelete(eventId) {
245
+ await this.urbitReq("DELETE", `/~/channel/${this.channelUid}/${eventId}`);
246
+ }
247
+ async loadState() {
248
+ try {
249
+ const s = await fs_extra.default.readJson(STATE_FILE);
250
+ if (s.p) this.config.pendingPairings = s.p;
251
+ if (s.a) this.config.approvedPairings = s.a;
252
+ } catch {}
253
+ }
254
+ async saveState() {
255
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
256
+ await fs_extra.default.writeJson(STATE_FILE, {
257
+ p: this.config.pendingPairings,
258
+ a: this.config.approvedPairings
259
+ }, { spaces: 2 });
260
+ }
261
+ isRunning() {
262
+ return this.running;
263
+ }
264
+ };
265
+
266
+ //#endregion
267
+ exports.TlonConnector = TlonConnector;
@@ -0,0 +1,167 @@
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 https = require_chunk.__toESM(require("https"));
7
+ const events = require_chunk.__toESM(require("events"));
8
+
9
+ //#region extensions/zalo-personal/src/connector.ts
10
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "zalo-personal-state.json");
11
+ function zaloWebReq(cookie, method, endpoint, body) {
12
+ return new Promise((resolve, reject) => {
13
+ const payload = body ? JSON.stringify(body) : null;
14
+ const req = https.default.request({
15
+ hostname: "chat.zalo.me",
16
+ port: 443,
17
+ path: `/api${endpoint}`,
18
+ method,
19
+ headers: {
20
+ "Cookie": cookie,
21
+ "Referer": "https://chat.zalo.me/",
22
+ "User-Agent": "Mozilla/5.0 (compatible; HyperClaw/4.0)",
23
+ ...payload ? {
24
+ "Content-Type": "application/json",
25
+ "Content-Length": Buffer.byteLength(payload)
26
+ } : {}
27
+ }
28
+ }, (res) => {
29
+ let data = "";
30
+ res.on("data", (c) => data += c);
31
+ res.on("end", () => {
32
+ try {
33
+ resolve(JSON.parse(data));
34
+ } catch {
35
+ resolve({ raw: data });
36
+ }
37
+ });
38
+ });
39
+ req.on("error", reject);
40
+ if (payload) req.write(payload);
41
+ req.end();
42
+ });
43
+ }
44
+ var ZaloPersonalConnector = class extends events.EventEmitter {
45
+ config;
46
+ running = false;
47
+ ws = null;
48
+ userId = "";
49
+ constructor(config) {
50
+ super();
51
+ this.config = {
52
+ imei: require("crypto").randomUUID(),
53
+ dmPolicy: "allowlist",
54
+ allowFrom: [],
55
+ approvedPairings: [],
56
+ pendingPairings: {},
57
+ ...config
58
+ };
59
+ }
60
+ async connect() {
61
+ const profile = await zaloWebReq(this.config.cookie, "GET", "/profile");
62
+ this.userId = profile?.data?.userId || profile?.userId || "";
63
+ await this.loadState();
64
+ this.running = true;
65
+ console.log(chalk.default.green(` 🦅 Zalo Personal: ${profile?.data?.displayName || this.userId} connected`));
66
+ this.emit("connected", { userId: this.userId });
67
+ this.startPolling();
68
+ }
69
+ async startPolling() {
70
+ while (this.running) try {
71
+ const msgs = await zaloWebReq(this.config.cookie, "GET", `/message/fetchlatestmsg?last_msg_id=0&limit=20`);
72
+ for (const msg of msgs?.data?.msgs || []) {
73
+ if (msg.fromUid === this.userId) continue;
74
+ if (!msg.msgId || !msg.content) continue;
75
+ const from = msg.fromUid;
76
+ const text = msg.content;
77
+ const allowed = await this.checkDMPolicy(from, text);
78
+ if (!allowed) continue;
79
+ this.emit("message", {
80
+ id: msg.msgId,
81
+ channelId: "zalo-personal",
82
+ from,
83
+ chatId: msg.toUid || from,
84
+ text,
85
+ timestamp: new Date(parseInt(msg.ts || "0")).toISOString(),
86
+ isDM: true
87
+ });
88
+ }
89
+ await new Promise((r) => setTimeout(r, 3e3));
90
+ } catch (e) {
91
+ if (this.running) {
92
+ console.log(chalk.default.yellow(` ⚠ Zalo Personal: ${e.message}`));
93
+ await new Promise((r) => setTimeout(r, 5e3));
94
+ }
95
+ }
96
+ }
97
+ async checkDMPolicy(from, text) {
98
+ if (this.config.dmPolicy === "none") return false;
99
+ if (this.config.dmPolicy === "open") return true;
100
+ if (this.config.dmPolicy === "allowlist") {
101
+ if (this.config.allowFrom.includes(from)) return true;
102
+ await this.sendMessage(from, "🦅 HyperClaw: Not on allowlist.");
103
+ return false;
104
+ }
105
+ if (this.config.dmPolicy === "pairing") {
106
+ if (this.config.approvedPairings.includes(from)) return true;
107
+ const upper = text.trim().toUpperCase();
108
+ if (this.config.pendingPairings[upper]) {
109
+ this.config.approvedPairings.push(from);
110
+ delete this.config.pendingPairings[upper];
111
+ await this.saveState();
112
+ await this.sendMessage(from, "🦅 Paired!");
113
+ this.emit("pairing:approved", {
114
+ userId: from,
115
+ channelId: "zalo-personal"
116
+ });
117
+ return true;
118
+ }
119
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
120
+ this.config.pendingPairings[code] = from;
121
+ await this.saveState();
122
+ await this.sendMessage(from, `🦅 Mã ghép đôi: ${code}\nXác nhận: hyperclaw pairing approve zalo-personal ${code}`);
123
+ return false;
124
+ }
125
+ return false;
126
+ }
127
+ async sendMessage(toUid, text) {
128
+ await zaloWebReq(this.config.cookie, "POST", "/message/sendmsg", {
129
+ toid: toUid,
130
+ msg: text.slice(0, 2e3),
131
+ imei: this.config.imei,
132
+ type: 1
133
+ });
134
+ }
135
+ disconnect() {
136
+ this.running = false;
137
+ this.ws?.close();
138
+ }
139
+ approvePairing(code) {
140
+ const upper = code.toUpperCase();
141
+ if (!this.config.pendingPairings[upper]) return false;
142
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
143
+ delete this.config.pendingPairings[upper];
144
+ this.saveState();
145
+ return true;
146
+ }
147
+ async loadState() {
148
+ try {
149
+ const s = await fs_extra.default.readJson(STATE_FILE);
150
+ if (s.p) this.config.pendingPairings = s.p;
151
+ if (s.a) this.config.approvedPairings = s.a;
152
+ } catch {}
153
+ }
154
+ async saveState() {
155
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
156
+ await fs_extra.default.writeJson(STATE_FILE, {
157
+ p: this.config.pendingPairings,
158
+ a: this.config.approvedPairings
159
+ }, { spaces: 2 });
160
+ }
161
+ isRunning() {
162
+ return this.running;
163
+ }
164
+ };
165
+
166
+ //#endregion
167
+ exports.ZaloPersonalConnector = ZaloPersonalConnector;
@@ -0,0 +1,192 @@
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 crypto = require_chunk.__toESM(require("crypto"));
7
+ const ws = require_chunk.__toESM(require("ws"));
8
+ const events = require_chunk.__toESM(require("events"));
9
+
10
+ //#region extensions/nostr/src/connector.ts
11
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "nostr-state.json");
12
+ function getPublicKey(privKeyHex) {
13
+ const privKey = Buffer.from(privKeyHex, "hex");
14
+ const ec = crypto.default.createECDH("prime256v1");
15
+ return crypto.default.createHash("sha256").update(privKey).digest("hex");
16
+ }
17
+ function signEvent(event, privKeyHex) {
18
+ const payload = JSON.stringify(event);
19
+ return crypto.default.createHmac("sha256", Buffer.from(privKeyHex, "hex")).update(payload).digest("hex");
20
+ }
21
+ function nip04Decrypt(privKeyHex, senderPubKey, ciphertext) {
22
+ try {
23
+ const [encrypted, iv] = ciphertext.split("?iv=");
24
+ const sharedSecret = crypto.default.createHash("sha256").update(Buffer.from(privKeyHex + senderPubKey, "hex")).digest();
25
+ const decipher = crypto.default.createDecipheriv("aes-256-cbc", sharedSecret, Buffer.from(iv, "base64"));
26
+ return decipher.update(encrypted, "base64", "utf8") + decipher.final("utf8");
27
+ } catch {
28
+ return ciphertext;
29
+ }
30
+ }
31
+ function nip04Encrypt(privKeyHex, recipientPubKey, plaintext) {
32
+ const sharedSecret = crypto.default.createHash("sha256").update(Buffer.from(privKeyHex + recipientPubKey, "hex")).digest();
33
+ const iv = crypto.default.randomBytes(16);
34
+ const cipher = crypto.default.createCipheriv("aes-256-cbc", sharedSecret, iv);
35
+ const encrypted = cipher.update(plaintext, "utf8", "base64") + cipher.final("base64");
36
+ return `${encrypted}?iv=${iv.toString("base64")}`;
37
+ }
38
+ var NostrConnector = class extends events.EventEmitter {
39
+ config;
40
+ sockets = /* @__PURE__ */ new Map();
41
+ running = false;
42
+ pubKey;
43
+ seenEventIds = /* @__PURE__ */ new Set();
44
+ constructor(config) {
45
+ super();
46
+ this.config = {
47
+ relays: [
48
+ "wss://relay.damus.io",
49
+ "wss://nos.lol",
50
+ "wss://relay.nostr.band"
51
+ ],
52
+ dmPolicy: "open",
53
+ allowFrom: [],
54
+ approvedPairings: [],
55
+ pendingPairings: {},
56
+ ...config
57
+ };
58
+ this.pubKey = getPublicKey(this.config.privateKeyHex);
59
+ }
60
+ async connect() {
61
+ await this.loadState();
62
+ for (const relay of this.config.relays) this.connectRelay(relay);
63
+ this.running = true;
64
+ console.log(chalk.default.green(` 🦅 Nostr: pubkey ${this.pubKey.slice(0, 16)}... connected to ${this.config.relays.length} relays`));
65
+ this.emit("connected", { pubKey: this.pubKey });
66
+ }
67
+ connectRelay(url) {
68
+ const ws$1 = new ws.WebSocket(url);
69
+ this.sockets.set(url, ws$1);
70
+ ws$1.on("open", () => {
71
+ ws$1.send(JSON.stringify([
72
+ "REQ",
73
+ `hc-${Date.now()}`,
74
+ {
75
+ kinds: [4],
76
+ "#p": [this.pubKey],
77
+ limit: 10
78
+ }
79
+ ]));
80
+ });
81
+ ws$1.on("message", async (data) => {
82
+ try {
83
+ const msg = JSON.parse(data.toString());
84
+ if (msg[0] === "EVENT") await this.handleEvent(msg[2]);
85
+ } catch {}
86
+ });
87
+ ws$1.on("close", () => {
88
+ if (this.running) setTimeout(() => this.connectRelay(url), 5e3);
89
+ });
90
+ ws$1.on("error", () => {});
91
+ }
92
+ async handleEvent(event) {
93
+ if (event.kind !== 4) return;
94
+ if (event.pubkey === this.pubKey) return;
95
+ if (this.seenEventIds.has(event.id)) return;
96
+ this.seenEventIds.add(event.id);
97
+ const from = event.pubkey;
98
+ const text = nip04Decrypt(this.config.privateKeyHex, from, event.content);
99
+ const allowed = await this.checkDMPolicy(from, text);
100
+ if (!allowed) return;
101
+ this.emit("message", {
102
+ id: event.id,
103
+ channelId: "nostr",
104
+ from,
105
+ chatId: from,
106
+ text,
107
+ timestamp: new Date(event.created_at * 1e3).toISOString(),
108
+ isDM: true
109
+ });
110
+ }
111
+ async checkDMPolicy(from, text) {
112
+ if (this.config.dmPolicy === "none") return false;
113
+ if (this.config.dmPolicy === "open") return true;
114
+ if (this.config.dmPolicy === "allowlist") {
115
+ if (this.config.allowFrom.includes(from)) return true;
116
+ await this.sendDM(from, "🦅 HyperClaw: Not on allowlist.");
117
+ return false;
118
+ }
119
+ if (this.config.dmPolicy === "pairing") {
120
+ if (this.config.approvedPairings.includes(from)) return true;
121
+ const upper = text.trim().toUpperCase();
122
+ if (this.config.pendingPairings[upper]) {
123
+ this.config.approvedPairings.push(from);
124
+ delete this.config.pendingPairings[upper];
125
+ await this.saveState();
126
+ await this.sendDM(from, "🦅 Paired!");
127
+ this.emit("pairing:approved", {
128
+ userId: from,
129
+ channelId: "nostr"
130
+ });
131
+ return true;
132
+ }
133
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
134
+ this.config.pendingPairings[code] = from;
135
+ await this.saveState();
136
+ await this.sendDM(from, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve nostr ${code}`);
137
+ return false;
138
+ }
139
+ return false;
140
+ }
141
+ async sendDM(recipientPubKey, text) {
142
+ const encrypted = nip04Encrypt(this.config.privateKeyHex, recipientPubKey, text);
143
+ const event = {
144
+ pubkey: this.pubKey,
145
+ created_at: Math.floor(Date.now() / 1e3),
146
+ kind: 4,
147
+ tags: [["p", recipientPubKey]],
148
+ content: encrypted
149
+ };
150
+ const sig = signEvent(event, this.config.privateKeyHex);
151
+ const fullEvent = {
152
+ ...event,
153
+ id: sig,
154
+ sig
155
+ };
156
+ const msg = JSON.stringify(["EVENT", fullEvent]);
157
+ for (const ws$1 of this.sockets.values()) if (ws$1.readyState === ws.WebSocket.OPEN) ws$1.send(msg);
158
+ }
159
+ disconnect() {
160
+ this.running = false;
161
+ for (const ws$1 of this.sockets.values()) ws$1.close();
162
+ this.sockets.clear();
163
+ }
164
+ approvePairing(code) {
165
+ const upper = code.toUpperCase();
166
+ if (!this.config.pendingPairings[upper]) return false;
167
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
168
+ delete this.config.pendingPairings[upper];
169
+ this.saveState();
170
+ return true;
171
+ }
172
+ async loadState() {
173
+ try {
174
+ const s = await fs_extra.default.readJson(STATE_FILE);
175
+ if (s.p) this.config.pendingPairings = s.p;
176
+ if (s.a) this.config.approvedPairings = s.a;
177
+ } catch {}
178
+ }
179
+ async saveState() {
180
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
181
+ await fs_extra.default.writeJson(STATE_FILE, {
182
+ p: this.config.pendingPairings,
183
+ a: this.config.approvedPairings
184
+ }, { spaces: 2 });
185
+ }
186
+ isRunning() {
187
+ return this.running;
188
+ }
189
+ };
190
+
191
+ //#endregion
192
+ exports.NostrConnector = NostrConnector;