hyperclaw 5.2.7 → 5.2.9

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 (207) hide show
  1. package/dist/a2ui-protocol-DEsfqO7h.js +75 -0
  2. package/dist/agents-routing-Cee7wrfi.js +398 -0
  3. package/dist/agents-routing-ChorJKFL.js +6 -0
  4. package/dist/agents-routing-Cpg20-1e.js +398 -0
  5. package/dist/agents-routing-uNzqjgOr.js +6 -0
  6. package/dist/api-key-validation-DgOBmp8Y.js +64 -0
  7. package/dist/api-key-validation-DydlUth1.js +64 -0
  8. package/dist/api-keys-guide--73Bq0Ey.js +149 -0
  9. package/dist/api-keys-guide-DqRGa4x7.js +149 -0
  10. package/dist/audit-CX5poVMR.js +445 -0
  11. package/dist/audit-Dntx9fG9.js +445 -0
  12. package/dist/banner-B_rR7FPO.js +7 -0
  13. package/dist/banner-Bb7CderS.js +143 -0
  14. package/dist/bounty-tools-BoU1NN5N.js +211 -0
  15. package/dist/bounty-tools-Dn9Yq7V1.js +211 -0
  16. package/dist/browser-tools-CJ9M9o22.js +179 -0
  17. package/dist/browser-tools-CXxWxA1c.js +5 -0
  18. package/dist/chat-C07wF0mM.js +494 -0
  19. package/dist/chat-D1Zc73I5.js +513 -0
  20. package/dist/claw-tasks-BLqd1a0Q.js +80 -0
  21. package/dist/claw-tasks-ChqkHdFs.js +80 -0
  22. package/dist/config-BlLlJ6Er.js +7 -0
  23. package/dist/config-Bzues-G2.js +7 -0
  24. package/dist/config-DGAAJ49A.js +261 -0
  25. package/dist/config-SgDxKyfV.js +261 -0
  26. package/dist/connector-1efnZgQN.js +566 -0
  27. package/dist/connector-B5q1_srT.js +286 -0
  28. package/dist/connector-BMFLJ4fr.js +508 -0
  29. package/dist/connector-BZYv9siY.js +189 -0
  30. package/dist/connector-B_XkXm-j.js +218 -0
  31. package/dist/connector-BkY1I6gf.js +189 -0
  32. package/dist/connector-C2Z3RN1z.js +350 -0
  33. package/dist/connector-C7aYvVzU.js +225 -0
  34. package/dist/connector-CXXYOyHw.js +164 -0
  35. package/dist/connector-Ca1J23HX.js +167 -0
  36. package/dist/connector-Cjqc656I.js +181 -0
  37. package/dist/connector-CluRienN.js +425 -0
  38. package/dist/connector-CuNz2eP-.js +305 -0
  39. package/dist/connector-DHL_oeHy.js +552 -0
  40. package/dist/connector-DJ79rd1L.js +173 -0
  41. package/dist/connector-DcLE6xCZ.js +239 -0
  42. package/dist/connector-DcyQTJnJ.js +162 -0
  43. package/dist/connector-DgyX9qSc.js +192 -0
  44. package/dist/connector-DnDXXZ7L.js +182 -0
  45. package/dist/connector-DqUslg-X.js +213 -0
  46. package/dist/connector-Duc-HmRZ.js +85 -0
  47. package/dist/connector-IV0QFer8.js +498 -0
  48. package/dist/connector-OnsLxE8G.js +194 -0
  49. package/dist/connector-UYu_TS0X.js +204 -0
  50. package/dist/connector-cCA5ffmp.js +340 -0
  51. package/dist/connector-fbNfx4_L.js +568 -0
  52. package/dist/connector-fi2vlwbO.js +276 -0
  53. package/dist/connector-l3LD8IDN.js +419 -0
  54. package/dist/cost-tracker-CgEXyEtz.js +103 -0
  55. package/dist/cost-tracker-DCXDUzBI.js +103 -0
  56. package/dist/credentials-store-1LDtNReY.js +89 -0
  57. package/dist/credentials-store-BFxEJR00.js +7 -0
  58. package/dist/credentials-store-Bmm9e1SS.js +7 -0
  59. package/dist/credentials-store-D8ERbGR2.js +89 -0
  60. package/dist/cron-tasks-1E6wKpTv.js +85 -0
  61. package/dist/cron-tasks-OQbgmenS.js +85 -0
  62. package/dist/daemon-B13UIqvL.js +7 -0
  63. package/dist/daemon-CzOW-1PS.js +421 -0
  64. package/dist/daemon-aVX-WGz1.js +421 -0
  65. package/dist/daemon-iFmVBPXN.js +7 -0
  66. package/dist/delivery-B8YGmrq5.js +4 -0
  67. package/dist/delivery-DWsU6gx-.js +95 -0
  68. package/dist/delivery-Pko6sSkt.js +4 -0
  69. package/dist/delivery-hMHFRZwy.js +95 -0
  70. package/dist/destructive-gate-C2TrWsp2.js +101 -0
  71. package/dist/destructive-gate-bnkroJWG.js +101 -0
  72. package/dist/developer-keys-BWXHaWxY.js +127 -0
  73. package/dist/developer-keys-CzDxVczE.js +8 -0
  74. package/dist/device-auth-store-C1bCwXO2.js +7 -0
  75. package/dist/device-auth-store-DIZTOz4V.js +88 -0
  76. package/dist/doctor-C6nAGdH8.js +233 -0
  77. package/dist/doctor-mgWumA25.js +6 -0
  78. package/dist/engine-BGRTi0fo.js +327 -0
  79. package/dist/engine-BvCEhaUn.js +7 -0
  80. package/dist/engine-ByQ-0sWM.js +7 -0
  81. package/dist/engine-gnMjO743.js +327 -0
  82. package/dist/env-resolve-BdagnXhK.js +151 -0
  83. package/dist/env-resolve-CHxjGo8u.js +151 -0
  84. package/dist/env-resolve-NEtsGacw.js +10 -0
  85. package/dist/env-resolve-pIETNTpQ.js +10 -0
  86. package/dist/extraction-tools-BE6z_Yw5.js +91 -0
  87. package/dist/extraction-tools-CJsdyBST.js +5 -0
  88. package/dist/form_data-B2_0EoWj.js +8657 -0
  89. package/dist/gmail-watch-setup-1RGIHNdu.js +42 -0
  90. package/dist/gmail-watch-setup-Brkj94Sy.js +42 -0
  91. package/dist/health-BMUmUNoe.js +152 -0
  92. package/dist/health-C8n9RH5O.js +6 -0
  93. package/dist/heartbeat-engine-D6oSpgxx.js +89 -0
  94. package/dist/heartbeat-engine-aRbab8a5.js +89 -0
  95. package/dist/hub-BJM2KXLO.js +6 -0
  96. package/dist/hub-Bb_dYECE.js +512 -0
  97. package/dist/hyperclawbot-CgrV46DA.js +516 -0
  98. package/dist/hyperclawbot-DzP_v3iA.js +516 -0
  99. package/dist/inference-BHJFPEKL.js +8 -0
  100. package/dist/inference-CFBkvLpE.js +2854 -0
  101. package/dist/inference-G4MbdErG.js +8 -0
  102. package/dist/inference-vweXyh27.js +2854 -0
  103. package/dist/knowledge-graph-9UNrsiIY.js +134 -0
  104. package/dist/knowledge-graph-yeMPBPP8.js +134 -0
  105. package/dist/loader-BXYJl25e.js +6 -0
  106. package/dist/loader-DIPs649t.js +410 -0
  107. package/dist/loader-Dq_cDlOW.js +6 -0
  108. package/dist/loader-gTdKBwiI.js +410 -0
  109. package/dist/logger-C3ZCDSkc.js +86 -0
  110. package/dist/logger-CG38Idq4.js +86 -0
  111. package/dist/manager--wG9JdFW.js +120 -0
  112. package/dist/manager-BI3izlRG.js +120 -0
  113. package/dist/manager-BNc21xgG.js +6 -0
  114. package/dist/manager-CQ3MWNHY.js +250 -0
  115. package/dist/manager-DWJ7WZcY.js +250 -0
  116. package/dist/manager-DYfzqckn.js +35 -0
  117. package/dist/mcp-CklaYr_6.js +142 -0
  118. package/dist/mcp-SsMEvl28.js +142 -0
  119. package/dist/mcp-loader-9v8eUsNI.js +93 -0
  120. package/dist/mcp-loader-DLrp_oZJ.js +93 -0
  121. package/dist/memory-BCYvdqwo.js +273 -0
  122. package/dist/memory-BGgCBSx1.js +6 -0
  123. package/dist/memory-auto-Bh52cQJP.js +5 -0
  124. package/dist/memory-auto-Bow9u_L7.js +306 -0
  125. package/dist/memory-auto-BupvVwNd.js +306 -0
  126. package/dist/memory-auto-CgBAI8mm.js +5 -0
  127. package/dist/memory-integration-4oGqX6rr.js +91 -0
  128. package/dist/memory-integration-CveUEI3V.js +91 -0
  129. package/dist/moltbook-B3DNdh40.js +81 -0
  130. package/dist/moltbook-xP7VXKlX.js +81 -0
  131. package/dist/node-C4esBfbX.js +226 -0
  132. package/dist/node-urDjajMt.js +226 -0
  133. package/dist/nodes-registry-Cd4eWw80.js +52 -0
  134. package/dist/nodes-registry-DLUZhEMS.js +52 -0
  135. package/dist/oauth-flow-BbLQTzZk.js +148 -0
  136. package/dist/oauth-flow-Bt-LaRHV.js +148 -0
  137. package/dist/oauth-provider-CVTKgj35.js +111 -0
  138. package/dist/oauth-provider-UZyG84s7.js +111 -0
  139. package/dist/observability-BtLyuxcz.js +89 -0
  140. package/dist/observability-lwYm4aoB.js +89 -0
  141. package/dist/onboard-B3drurt-.js +3812 -0
  142. package/dist/onboard-BV5Poocl.js +13 -0
  143. package/dist/onboard-DEwuHrMj.js +14 -0
  144. package/dist/onboard-UiynbNQy.js +3909 -0
  145. package/dist/orchestrator-BXyIgAeH.js +189 -0
  146. package/dist/orchestrator-DMZkAVa5.js +189 -0
  147. package/dist/orchestrator-MLTc4NYu.js +6 -0
  148. package/dist/orchestrator-rVGu7yYr.js +6 -0
  149. package/dist/osint-Bsf6RGPv.js +283 -0
  150. package/dist/osint-chat-Ark94iFc.js +789 -0
  151. package/dist/osint-chat-Hn8qpsC1.js +836 -0
  152. package/dist/osint-f9DeXT6j.js +283 -0
  153. package/dist/pairing-2vAiDBjN.js +6 -0
  154. package/dist/pairing-B4NoBvyE.js +207 -0
  155. package/dist/pc-access-BLnc-DYp.js +858 -0
  156. package/dist/pc-access-CTNtG2LD.js +8 -0
  157. package/dist/pending-approval-C4ZaHHWl.js +22 -0
  158. package/dist/pending-approval-CHUZ_qT6.js +22 -0
  159. package/dist/reminders-store-BixTWL1h.js +58 -0
  160. package/dist/renderer-B1ToXngl.js +228 -0
  161. package/dist/rules-Cqen1Mpt.js +106 -0
  162. package/dist/run-main.js +98 -94
  163. package/dist/runner-B9xANekJ.js +1274 -0
  164. package/dist/runner-Cr1_mwnU.js +1274 -0
  165. package/dist/security--17Fxo5Z.js +4 -0
  166. package/dist/security-B4vH02lO.js +4 -0
  167. package/dist/security-DP1qtJfL.js +90 -0
  168. package/dist/security-HOOGCw5z.js +90 -0
  169. package/dist/server-CRhXiGI9.js +4 -0
  170. package/dist/server-DUDXqJSo.js +1365 -0
  171. package/dist/server-De4H45Ju.js +1365 -0
  172. package/dist/server-ha59nA8a.js +4 -0
  173. package/dist/session-store-7sEPyV16.js +5 -0
  174. package/dist/session-store-Ce2QMSL_.js +141 -0
  175. package/dist/sessions-tools-CWr_pDtp.js +5 -0
  176. package/dist/sessions-tools-DKVu9aIN.js +95 -0
  177. package/dist/skill-loader-DK19Jm4e.js +7 -0
  178. package/dist/skill-loader-Dfs9VNM-.js +160 -0
  179. package/dist/skill-runtime-BRp2D8Jb.js +5 -0
  180. package/dist/skill-runtime-BeKh2rD_.js +5 -0
  181. package/dist/skill-runtime-C8bNwKwz.js +104 -0
  182. package/dist/skill-runtime-CcpC2Zfc.js +104 -0
  183. package/dist/src-B8LzGLSY.js +63 -0
  184. package/dist/src-BxmkZ9RH.js +63 -0
  185. package/dist/src-DUoc6_kn.js +458 -0
  186. package/dist/src-DjTtmSRg.js +20 -0
  187. package/dist/src-n_46LPDi.js +458 -0
  188. package/dist/sub-agent-tools-CldaMfd5.js +39 -0
  189. package/dist/sub-agent-tools-q5JqEze_.js +39 -0
  190. package/dist/tool-policy-DtGf3Ifq.js +189 -0
  191. package/dist/tool-policy-QXF3MMxu.js +189 -0
  192. package/dist/tts-elevenlabs-1zWD3QJw.js +64 -0
  193. package/dist/tts-elevenlabs-y6HGWWDS.js +64 -0
  194. package/dist/update-check-C4te7JmY.js +6 -0
  195. package/dist/update-check-GDue_it1.js +98 -0
  196. package/dist/vision-DV2ubVjr.js +167 -0
  197. package/dist/vision-tools-Cb86uMdh.js +5 -0
  198. package/dist/vision-tools-CbVfyTZT.js +5 -0
  199. package/dist/vision-tools-DieVQp6s.js +51 -0
  200. package/dist/vision-tools-DlnxaZjg.js +51 -0
  201. package/dist/vision-u4kMThdo.js +167 -0
  202. package/dist/voice-transcription-BolTT_HG.js +170 -0
  203. package/dist/voice-transcription-DgON5qaF.js +170 -0
  204. package/dist/website-watch-tools-B8L_NgwT.js +5 -0
  205. package/dist/website-watch-tools-Drm5HjIX.js +176 -0
  206. package/package.json +4 -1
  207. package/static/chat.html +9 -3
@@ -0,0 +1,164 @@
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 events = require_chunk.__toESM(require("events"));
7
+
8
+ //#region extensions/whatsapp-baileys/src/connector.ts
9
+ const AUTH_DIR = path.default.join(os.default.homedir(), ".hyperclaw", "baileys-auth");
10
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "whatsapp-baileys-state.json");
11
+ var WhatsAppBaileysConnector = class extends events.EventEmitter {
12
+ config;
13
+ sock = null;
14
+ running = false;
15
+ qrCallback;
16
+ constructor(config = {}) {
17
+ super();
18
+ this.config = {
19
+ dmPolicy: "allowlist",
20
+ allowFrom: [],
21
+ approvedPairings: [],
22
+ pendingPairings: {},
23
+ ...config
24
+ };
25
+ }
26
+ onQR(cb) {
27
+ this.qrCallback = cb;
28
+ }
29
+ async connect() {
30
+ try {
31
+ const makeWASocket$1 = require("@whiskeysockets/baileys");
32
+ const { useMultiFileAuthState: useMultiFileAuthState$1 } = require("@whiskeysockets/baileys");
33
+ } catch {
34
+ throw new Error("Baileys not installed. Run: npm install @whiskeysockets/baileys");
35
+ }
36
+ const makeWASocket = require("@whiskeysockets/baileys").default;
37
+ const { useMultiFileAuthState } = require("@whiskeysockets/baileys");
38
+ await fs_extra.default.ensureDir(AUTH_DIR);
39
+ const { state, saveCreds } = await useMultiFileAuthState(AUTH_DIR);
40
+ await this.loadState();
41
+ this.sock = makeWASocket({
42
+ auth: state,
43
+ printQRInTerminal: true,
44
+ generateHighQualityLinkPreview: false
45
+ });
46
+ this.sock.ev.on("creds.update", saveCreds);
47
+ this.sock.ev.on("connection.update", (upd) => {
48
+ if (upd.qr) this.qrCallback?.(upd.qr);
49
+ if (upd.connection === "open") {
50
+ console.log(chalk.default.green(" 🦅 WhatsApp Baileys: connected"));
51
+ this.emit("connected", {});
52
+ }
53
+ if (upd.connection === "close") this.emit("disconnected", upd);
54
+ });
55
+ this.sock.ev.on("messages.upsert", async ({ messages }) => {
56
+ for (const m of messages) {
57
+ if (m.key.fromMe) continue;
58
+ const msg = m.message;
59
+ if (!msg) continue;
60
+ let text = msg.conversation || msg.extendedTextMessage?.text || "";
61
+ const from = (m.key.remoteJid || "").replace(/@.*/, "");
62
+ if (msg.audioMessage || msg.pttMessage) {
63
+ let audioBuffer;
64
+ try {
65
+ const { downloadMediaMessage } = require("@whiskeysockets/baileys");
66
+ audioBuffer = await downloadMediaMessage(m, "buffer", {}, { reuploadRequest: this.sock?.updateMessageSent });
67
+ } catch {}
68
+ this.emit("message", {
69
+ id: m.key.id,
70
+ channelId: "whatsapp-baileys",
71
+ from,
72
+ chatId: m.key.remoteJid,
73
+ text: "[voice note]",
74
+ audioBuffer,
75
+ timestamp: new Date(parseInt(m.messageTimestamp || "0") * 1e3).toISOString(),
76
+ isDM: true
77
+ });
78
+ continue;
79
+ }
80
+ if (!text) continue;
81
+ const allowed = await this.checkDMPolicy(from, text);
82
+ if (!allowed) continue;
83
+ this.emit("message", {
84
+ id: m.key.id,
85
+ channelId: "whatsapp-baileys",
86
+ from,
87
+ chatId: m.key.remoteJid,
88
+ text,
89
+ timestamp: new Date(parseInt(m.messageTimestamp) * 1e3).toISOString(),
90
+ isDM: true
91
+ });
92
+ }
93
+ });
94
+ this.running = true;
95
+ }
96
+ async checkDMPolicy(from, text) {
97
+ if (this.config.dmPolicy === "none") return false;
98
+ if (this.config.dmPolicy === "open") return true;
99
+ if (this.config.dmPolicy === "allowlist") {
100
+ if (this.config.allowFrom.includes(from)) return true;
101
+ await this.sendMessage(from, "🦅 HyperClaw: Not on allowlist.").catch(() => {});
102
+ return false;
103
+ }
104
+ if (this.config.dmPolicy === "pairing") {
105
+ if (this.config.approvedPairings.includes(from)) return true;
106
+ const upper = text.trim().toUpperCase();
107
+ if (this.config.pendingPairings[upper]) {
108
+ this.config.approvedPairings.push(from);
109
+ delete this.config.pendingPairings[upper];
110
+ await this.saveState();
111
+ await this.sendMessage(from, "🦅 Paired!").catch(() => {});
112
+ this.emit("pairing:approved", {
113
+ userId: from,
114
+ channelId: "whatsapp-baileys"
115
+ });
116
+ return true;
117
+ }
118
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
119
+ this.config.pendingPairings[code] = from;
120
+ await this.saveState();
121
+ await this.sendMessage(from, `🦅 Code: ${code}\nApprove: hyperclaw pairing approve whatsapp-baileys ${code}`).catch(() => {});
122
+ return false;
123
+ }
124
+ return false;
125
+ }
126
+ async sendMessage(to, text) {
127
+ if (!this.sock) return;
128
+ const jid = to.includes("@") ? to : `${to}@s.whatsapp.net`;
129
+ await this.sock.sendMessage(jid, { text: text.slice(0, 4096) });
130
+ }
131
+ disconnect() {
132
+ this.running = false;
133
+ this.sock?.end?.();
134
+ this.sock = null;
135
+ }
136
+ approvePairing(code) {
137
+ const upper = code.toUpperCase();
138
+ if (!this.config.pendingPairings[upper]) return false;
139
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
140
+ delete this.config.pendingPairings[upper];
141
+ this.saveState();
142
+ return true;
143
+ }
144
+ async loadState() {
145
+ try {
146
+ const s = await fs_extra.default.readJson(STATE_FILE);
147
+ if (s.p) this.config.pendingPairings = s.p;
148
+ if (s.a) this.config.approvedPairings = s.a;
149
+ } catch {}
150
+ }
151
+ async saveState() {
152
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
153
+ await fs_extra.default.writeJson(STATE_FILE, {
154
+ p: this.config.pendingPairings,
155
+ a: this.config.approvedPairings
156
+ }, { spaces: 2 });
157
+ }
158
+ isRunning() {
159
+ return this.running;
160
+ }
161
+ };
162
+
163
+ //#endregion
164
+ exports.WhatsAppBaileysConnector = WhatsAppBaileysConnector;
@@ -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,181 @@
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 https = require_chunk.__toESM(require("https"));
8
+ const events = require_chunk.__toESM(require("events"));
9
+
10
+ //#region extensions/twitter/src/connector.ts
11
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "twitter-state.json");
12
+ function oauthSign(method, url, config) {
13
+ const nonce = crypto.default.randomBytes(16).toString("hex");
14
+ const ts = Math.floor(Date.now() / 1e3).toString();
15
+ const op = {
16
+ oauth_consumer_key: config.apiKey,
17
+ oauth_nonce: nonce,
18
+ oauth_signature_method: "HMAC-SHA1",
19
+ oauth_timestamp: ts,
20
+ oauth_token: config.accessToken,
21
+ oauth_version: "1.0"
22
+ };
23
+ const sorted = Object.keys(op).sort().map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(op[k])}`).join("&");
24
+ const base = `${method}&${encodeURIComponent(url)}&${encodeURIComponent(sorted)}`;
25
+ const key = `${encodeURIComponent(config.apiSecret)}&${encodeURIComponent(config.accessTokenSecret)}`;
26
+ op.oauth_signature = crypto.default.createHmac("sha1", key).update(base).digest("base64");
27
+ return "OAuth " + Object.keys(op).sort().map((k) => `${encodeURIComponent(k)}="${encodeURIComponent(op[k])}"`).join(", ");
28
+ }
29
+ function xReq(method, url, body, auth) {
30
+ return new Promise((resolve, reject) => {
31
+ const payload = body ? JSON.stringify(body) : null;
32
+ const u = new URL(url);
33
+ const req = https.default.request({
34
+ hostname: u.hostname,
35
+ path: u.pathname + u.search,
36
+ method,
37
+ headers: {
38
+ "Authorization": auth,
39
+ ...payload ? {
40
+ "Content-Type": "application/json",
41
+ "Content-Length": Buffer.byteLength(payload)
42
+ } : {}
43
+ }
44
+ }, (res) => {
45
+ let data = "";
46
+ res.on("data", (c) => data += c);
47
+ res.on("end", () => {
48
+ try {
49
+ resolve(JSON.parse(data));
50
+ } catch {
51
+ resolve({ raw: data });
52
+ }
53
+ });
54
+ });
55
+ req.on("error", reject);
56
+ if (payload) req.write(payload);
57
+ req.end();
58
+ });
59
+ }
60
+ var TwitterConnector = class extends events.EventEmitter {
61
+ config;
62
+ running = false;
63
+ myUserId = "";
64
+ constructor(config) {
65
+ super();
66
+ this.config = {
67
+ dmPolicy: "allowlist",
68
+ allowFrom: [],
69
+ approvedPairings: [],
70
+ pendingPairings: {},
71
+ ...config
72
+ };
73
+ }
74
+ async connect() {
75
+ const url = "https://api.twitter.com/2/users/me";
76
+ const me = await xReq("GET", url, null, oauthSign("GET", url, this.config));
77
+ this.myUserId = me.data?.id || "";
78
+ await this.loadState();
79
+ this.running = true;
80
+ console.log(chalk.default.green(` 🦅 Twitter/X: @${me.data?.username} connected`));
81
+ this.emit("connected", {
82
+ userId: me.data?.id,
83
+ username: me.data?.username
84
+ });
85
+ }
86
+ disconnect() {
87
+ this.running = false;
88
+ }
89
+ handleCRC(crcToken) {
90
+ const hash = crypto.default.createHmac("sha256", this.config.apiSecret).update(crcToken).digest("base64");
91
+ return JSON.stringify({ response_token: `sha256=${hash}` });
92
+ }
93
+ async handleWebhook(body) {
94
+ let payload;
95
+ try {
96
+ payload = JSON.parse(body);
97
+ } catch {
98
+ return;
99
+ }
100
+ for (const event of payload.direct_message_events || []) {
101
+ if (event.type !== "message_create") continue;
102
+ const senderId = event.message_create?.sender_id;
103
+ if (senderId === this.myUserId) continue;
104
+ const text = event.message_create?.message_data?.text;
105
+ if (!text) continue;
106
+ const allowed = await this.checkDMPolicy(senderId, text);
107
+ if (!allowed) continue;
108
+ this.emit("message", {
109
+ id: event.id,
110
+ channelId: "twitter",
111
+ from: senderId,
112
+ chatId: senderId,
113
+ text,
114
+ timestamp: new Date(parseInt(event.created_timestamp)).toISOString(),
115
+ isDM: true
116
+ });
117
+ }
118
+ }
119
+ async checkDMPolicy(from, text) {
120
+ if (this.config.dmPolicy === "none") return false;
121
+ if (this.config.dmPolicy === "open") return true;
122
+ if (this.config.dmPolicy === "allowlist") {
123
+ if (this.config.allowFrom.includes(from)) return true;
124
+ await this.sendDM(from, "🦅 HyperClaw: Not on allowlist.");
125
+ return false;
126
+ }
127
+ if (this.config.dmPolicy === "pairing") {
128
+ if (this.config.approvedPairings.includes(from)) return true;
129
+ const upper = text.trim().toUpperCase();
130
+ if (this.config.pendingPairings[upper]) {
131
+ this.config.approvedPairings.push(from);
132
+ delete this.config.pendingPairings[upper];
133
+ await this.saveState();
134
+ await this.sendDM(from, "🦅 Paired!");
135
+ this.emit("pairing:approved", {
136
+ userId: from,
137
+ channelId: "twitter"
138
+ });
139
+ return true;
140
+ }
141
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
142
+ this.config.pendingPairings[code] = from;
143
+ await this.saveState();
144
+ await this.sendDM(from, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve twitter ${code}`);
145
+ return false;
146
+ }
147
+ return false;
148
+ }
149
+ async sendDM(recipientId, text) {
150
+ const url = `https://api.twitter.com/2/dm_conversations/with/${recipientId}/messages`;
151
+ await xReq("POST", url, { text: text.slice(0, 1e4) }, oauthSign("POST", url, this.config));
152
+ }
153
+ approvePairing(code) {
154
+ const upper = code.toUpperCase();
155
+ if (!this.config.pendingPairings[upper]) return false;
156
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
157
+ delete this.config.pendingPairings[upper];
158
+ this.saveState();
159
+ return true;
160
+ }
161
+ async loadState() {
162
+ try {
163
+ const s = await fs_extra.default.readJson(STATE_FILE);
164
+ if (s.p) this.config.pendingPairings = s.p;
165
+ if (s.a) this.config.approvedPairings = s.a;
166
+ } catch {}
167
+ }
168
+ async saveState() {
169
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
170
+ await fs_extra.default.writeJson(STATE_FILE, {
171
+ p: this.config.pendingPairings,
172
+ a: this.config.approvedPairings
173
+ }, { spaces: 2 });
174
+ }
175
+ isRunning() {
176
+ return this.running;
177
+ }
178
+ };
179
+
180
+ //#endregion
181
+ exports.TwitterConnector = TwitterConnector;