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,173 @@
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/messenger/src/connector.ts
11
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "messenger-state.json");
12
+ function fbReq(token, endpoint, body) {
13
+ return new Promise((resolve, reject) => {
14
+ const payload = JSON.stringify(body);
15
+ const req = https.default.request({
16
+ hostname: "graph.facebook.com",
17
+ port: 443,
18
+ path: `/v18.0${endpoint}`,
19
+ method: "POST",
20
+ headers: {
21
+ "Authorization": `Bearer ${token}`,
22
+ "Content-Type": "application/json",
23
+ "Content-Length": Buffer.byteLength(payload)
24
+ }
25
+ }, (res) => {
26
+ let data = "";
27
+ res.on("data", (c) => data += c);
28
+ res.on("end", () => {
29
+ try {
30
+ const r = JSON.parse(data);
31
+ if (r.error) reject(new Error(r.error.message));
32
+ else resolve(r);
33
+ } catch {
34
+ reject(new Error("Invalid JSON"));
35
+ }
36
+ });
37
+ });
38
+ req.on("error", reject);
39
+ req.write(payload);
40
+ req.end();
41
+ });
42
+ }
43
+ var MessengerConnector = class extends events.EventEmitter {
44
+ config;
45
+ running = false;
46
+ processedIds = /* @__PURE__ */ new Set();
47
+ constructor(config) {
48
+ super();
49
+ this.config = {
50
+ dmPolicy: "allowlist",
51
+ allowFrom: [],
52
+ approvedPairings: [],
53
+ pendingPairings: {},
54
+ ...config
55
+ };
56
+ }
57
+ async connect() {
58
+ await this.loadState();
59
+ this.running = true;
60
+ console.log(chalk.default.green(` 🦅 Messenger: page ${this.config.pageId} connected`));
61
+ this.emit("connected", { pageId: this.config.pageId });
62
+ }
63
+ disconnect() {
64
+ this.running = false;
65
+ }
66
+ verifyWebhook(mode, token, challenge) {
67
+ return mode === "subscribe" && token === this.config.verifyToken ? challenge : null;
68
+ }
69
+ verifySignature(body, signature) {
70
+ const expected = "sha256=" + crypto.default.createHmac("sha256", this.config.appSecret).update(body).digest("hex");
71
+ try {
72
+ return crypto.default.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
73
+ } catch {
74
+ return false;
75
+ }
76
+ }
77
+ async handleWebhook(body, signature) {
78
+ if (signature && !this.verifySignature(body, signature)) {
79
+ console.log(chalk.default.yellow(" ⚠ Messenger: invalid signature"));
80
+ return;
81
+ }
82
+ let payload;
83
+ try {
84
+ payload = JSON.parse(body);
85
+ } catch {
86
+ return;
87
+ }
88
+ for (const entry of payload.entry || []) for (const messaging of entry.messaging || []) {
89
+ if (!messaging.message || messaging.message.is_echo) continue;
90
+ const msgId = messaging.message.mid;
91
+ if (this.processedIds.has(msgId)) continue;
92
+ this.processedIds.add(msgId);
93
+ const senderId = messaging.sender.id;
94
+ const text = messaging.message.text;
95
+ if (!text) continue;
96
+ const allowed = await this.checkDMPolicy(senderId, text);
97
+ if (!allowed) continue;
98
+ this.emit("message", {
99
+ id: msgId,
100
+ channelId: "messenger",
101
+ from: senderId,
102
+ chatId: senderId,
103
+ text,
104
+ timestamp: new Date(messaging.timestamp).toISOString(),
105
+ isDM: true
106
+ });
107
+ }
108
+ }
109
+ async checkDMPolicy(from, text) {
110
+ if (this.config.dmPolicy === "none") return false;
111
+ if (this.config.dmPolicy === "open") return true;
112
+ if (this.config.dmPolicy === "allowlist") {
113
+ if (this.config.allowFrom.includes(from)) return true;
114
+ await this.sendMessage(from, "🦅 HyperClaw: Not on allowlist.");
115
+ return false;
116
+ }
117
+ if (this.config.dmPolicy === "pairing") {
118
+ if (this.config.approvedPairings.includes(from)) return true;
119
+ const upper = text.trim().toUpperCase();
120
+ if (this.config.pendingPairings[upper]) {
121
+ this.config.approvedPairings.push(from);
122
+ delete this.config.pendingPairings[upper];
123
+ await this.saveState();
124
+ await this.sendMessage(from, "🦅 Paired!");
125
+ this.emit("pairing:approved", {
126
+ userId: from,
127
+ channelId: "messenger"
128
+ });
129
+ return true;
130
+ }
131
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
132
+ this.config.pendingPairings[code] = from;
133
+ await this.saveState();
134
+ await this.sendMessage(from, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve messenger ${code}`);
135
+ return false;
136
+ }
137
+ return false;
138
+ }
139
+ async sendMessage(recipientId, text) {
140
+ await fbReq(this.config.pageAccessToken, "/me/messages", {
141
+ recipient: { id: recipientId },
142
+ message: { text: text.slice(0, 2e3) }
143
+ });
144
+ }
145
+ approvePairing(code) {
146
+ const upper = code.toUpperCase();
147
+ if (!this.config.pendingPairings[upper]) return false;
148
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
149
+ delete this.config.pendingPairings[upper];
150
+ this.saveState();
151
+ return true;
152
+ }
153
+ async loadState() {
154
+ try {
155
+ const s = await fs_extra.default.readJson(STATE_FILE);
156
+ if (s.p) this.config.pendingPairings = s.p;
157
+ if (s.a) this.config.approvedPairings = s.a;
158
+ } catch {}
159
+ }
160
+ async saveState() {
161
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
162
+ await fs_extra.default.writeJson(STATE_FILE, {
163
+ p: this.config.pendingPairings,
164
+ a: this.config.approvedPairings
165
+ }, { spaces: 2 });
166
+ }
167
+ isRunning() {
168
+ return this.running;
169
+ }
170
+ };
171
+
172
+ //#endregion
173
+ exports.MessengerConnector = MessengerConnector;
@@ -0,0 +1,239 @@
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 ws = require_chunk.__toESM(require("ws"));
7
+ const events = require_chunk.__toESM(require("events"));
8
+
9
+ //#region extensions/twitch/src/connector.ts
10
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "twitch-state.json");
11
+ const TWITCH_IRC_WS = "wss://irc-ws.chat.twitch.tv:443";
12
+ var TwitchConnector = class extends events.EventEmitter {
13
+ config;
14
+ ws = null;
15
+ running = false;
16
+ reconnectDelay = 1e3;
17
+ pingInterval = null;
18
+ constructor(config) {
19
+ super();
20
+ this.config = {
21
+ commandPrefix: "!",
22
+ whispers: true,
23
+ dmPolicy: "pairing",
24
+ allowFrom: [],
25
+ approvedPairings: [],
26
+ pendingPairings: {},
27
+ modsBypass: true,
28
+ ...config
29
+ };
30
+ }
31
+ async connect() {
32
+ await this.loadState();
33
+ await this.doConnect();
34
+ }
35
+ doConnect() {
36
+ return new Promise((resolve, reject) => {
37
+ const ws$1 = new ws.WebSocket(TWITCH_IRC_WS);
38
+ this.ws = ws$1;
39
+ ws$1.once("open", () => {
40
+ ws$1.send("CAP REQ :twitch.tv/membership twitch.tv/tags twitch.tv/commands");
41
+ ws$1.send(`PASS ${this.config.oauthToken}`);
42
+ ws$1.send(`NICK ${this.config.username}`);
43
+ for (const ch of this.config.channels) ws$1.send(`JOIN #${ch.replace(/^#/, "").toLowerCase()}`);
44
+ this.running = true;
45
+ this.reconnectDelay = 1e3;
46
+ this.pingInterval = setInterval(() => ws$1.send("PING :tmi.twitch.tv"), 6e4);
47
+ console.log(chalk.default.green(` 🦅 Twitch: connected as ${this.config.username}, joined ${this.config.channels.join(", ")}`));
48
+ this.emit("connected", { username: this.config.username });
49
+ resolve();
50
+ });
51
+ ws$1.on("message", async (raw) => {
52
+ const lines = raw.toString().split("\r\n").filter(Boolean);
53
+ for (const line of lines) await this.handleLine(line);
54
+ });
55
+ ws$1.on("close", () => {
56
+ if (this.pingInterval) {
57
+ clearInterval(this.pingInterval);
58
+ this.pingInterval = null;
59
+ }
60
+ if (this.running) {
61
+ console.log(chalk.default.yellow(` ⚠ Twitch: disconnected, reconnecting in ${this.reconnectDelay}ms`));
62
+ setTimeout(() => {
63
+ this.reconnectDelay = Math.min(this.reconnectDelay * 2, 3e4);
64
+ this.doConnect();
65
+ }, this.reconnectDelay);
66
+ }
67
+ });
68
+ ws$1.on("error", (err) => {
69
+ console.log(chalk.default.yellow(` ⚠ Twitch: ${err.message}`));
70
+ if (!this.running) reject(err);
71
+ });
72
+ });
73
+ }
74
+ disconnect() {
75
+ this.running = false;
76
+ if (this.pingInterval) {
77
+ clearInterval(this.pingInterval);
78
+ this.pingInterval = null;
79
+ }
80
+ this.ws?.close();
81
+ this.ws = null;
82
+ }
83
+ async handleLine(line) {
84
+ if (line === "PING :tmi.twitch.tv") {
85
+ this.ws?.send("PONG :tmi.twitch.tv");
86
+ return;
87
+ }
88
+ const tags = this.parseTags(line);
89
+ const parsed = this.parseIRC(line);
90
+ if (!parsed) return;
91
+ const { command, prefix, params, trailing } = parsed;
92
+ const username = prefix?.split("!")[0]?.toLowerCase() || "";
93
+ if (username === this.config.username.toLowerCase()) return;
94
+ if (command === "PRIVMSG") {
95
+ const channel = params[0];
96
+ const text = trailing || "";
97
+ const isWhisper = false;
98
+ if (this.config.commandPrefix && !text.startsWith(this.config.commandPrefix) && !isWhisper) return;
99
+ const body = this.config.commandPrefix ? text.slice(this.config.commandPrefix.length).trim() : text;
100
+ if (!body) return;
101
+ const isMod = tags["mod"] === "1" || tags["badges"]?.includes("broadcaster");
102
+ const allowed = await this.checkPolicy(username, channel, body, isMod);
103
+ if (!allowed) return;
104
+ this.emit("message", {
105
+ id: tags["id"] || `twitch-${Date.now()}`,
106
+ channelId: "twitch",
107
+ from: username,
108
+ displayName: tags["display-name"] || username,
109
+ chatId: channel,
110
+ text: body,
111
+ timestamp: tags["tmi-sent-ts"] ? new Date(Number(tags["tmi-sent-ts"])).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
112
+ isDM: false,
113
+ isMod
114
+ });
115
+ return;
116
+ }
117
+ if (command === "WHISPER" && this.config.whispers) {
118
+ const text = trailing || "";
119
+ if (!text) return;
120
+ const allowed = await this.checkPolicy(username, "whisper", text, false);
121
+ if (!allowed) return;
122
+ this.emit("message", {
123
+ id: `twitch-whisper-${Date.now()}`,
124
+ channelId: "twitch",
125
+ from: username,
126
+ displayName: tags["display-name"] || username,
127
+ chatId: `whisper:${username}`,
128
+ text,
129
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
130
+ isDM: true,
131
+ isMod: false
132
+ });
133
+ }
134
+ }
135
+ async checkPolicy(username, chatId, text, isMod) {
136
+ if (this.config.dmPolicy === "none") return false;
137
+ if (this.config.dmPolicy === "open") return true;
138
+ if (this.config.modsBypass && isMod) return true;
139
+ if (this.config.dmPolicy === "allowlist") {
140
+ if (this.config.allowFrom.includes(username)) return true;
141
+ await this.sendChat(chatId, `@${username} You are not on the allowlist.`);
142
+ return false;
143
+ }
144
+ if (this.config.dmPolicy === "pairing") {
145
+ if (this.config.approvedPairings.includes(username)) return true;
146
+ const upper = text.trim().toUpperCase();
147
+ if (this.config.pendingPairings[upper]) {
148
+ this.config.approvedPairings.push(username);
149
+ delete this.config.pendingPairings[upper];
150
+ await this.saveState();
151
+ await this.sendChat(chatId, `@${username} Paired! You can now talk to the assistant.`);
152
+ return true;
153
+ }
154
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
155
+ this.config.pendingPairings[code] = username;
156
+ await this.saveState();
157
+ await this.sendChat(chatId, `@${username} Pairing required. Code: ${code} — approve: hyperclaw pairing approve twitch ${code}`);
158
+ return false;
159
+ }
160
+ return false;
161
+ }
162
+ async sendChat(channel, text) {
163
+ if (!this.ws || this.ws.readyState !== ws.WebSocket.OPEN) return;
164
+ const ch = channel.startsWith("#") ? channel : `#${channel}`;
165
+ const chunks = text.match(/.{1,490}/g) || [text];
166
+ for (const chunk of chunks) {
167
+ this.ws.send(`PRIVMSG ${ch} :${chunk}`);
168
+ await new Promise((r) => setTimeout(r, 150));
169
+ }
170
+ }
171
+ async sendWhisper(username, text) {
172
+ if (!this.ws || this.ws.readyState !== ws.WebSocket.OPEN) return;
173
+ const ch = `#${this.config.channels[0]?.replace(/^#/, "") || this.config.username}`;
174
+ this.ws.send(`PRIVMSG ${ch} :/w ${username} ${text}`);
175
+ }
176
+ approvePairing(code) {
177
+ const upper = code.toUpperCase();
178
+ if (!this.config.pendingPairings[upper]) return false;
179
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
180
+ delete this.config.pendingPairings[upper];
181
+ this.saveState();
182
+ return true;
183
+ }
184
+ parseTags(line) {
185
+ if (!line.startsWith("@")) return {};
186
+ const tagStr = line.slice(1, line.indexOf(" "));
187
+ const tags = {};
188
+ for (const part of tagStr.split(";")) {
189
+ const [k, v] = part.split("=");
190
+ if (k) tags[k] = v || "";
191
+ }
192
+ return tags;
193
+ }
194
+ parseIRC(line) {
195
+ let rest = line.startsWith("@") ? line.slice(line.indexOf(" ") + 1) : line;
196
+ let prefix;
197
+ if (rest.startsWith(":")) {
198
+ const spaceIdx = rest.indexOf(" ");
199
+ prefix = rest.slice(1, spaceIdx);
200
+ rest = rest.slice(spaceIdx + 1);
201
+ }
202
+ const trailingIdx = rest.indexOf(" :");
203
+ let trailing;
204
+ if (trailingIdx !== -1) {
205
+ trailing = rest.slice(trailingIdx + 2);
206
+ rest = rest.slice(0, trailingIdx);
207
+ }
208
+ const parts = rest.trim().split(" ");
209
+ const command = parts[0];
210
+ const params = parts.slice(1).filter(Boolean);
211
+ if (!command) return null;
212
+ return {
213
+ command,
214
+ prefix,
215
+ params,
216
+ trailing
217
+ };
218
+ }
219
+ async loadState() {
220
+ try {
221
+ const s = await fs_extra.default.readJson(STATE_FILE);
222
+ if (s.p) this.config.pendingPairings = s.p;
223
+ if (s.a) this.config.approvedPairings = s.a;
224
+ } catch {}
225
+ }
226
+ async saveState() {
227
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
228
+ await fs_extra.default.writeJson(STATE_FILE, {
229
+ p: this.config.pendingPairings,
230
+ a: this.config.approvedPairings
231
+ }, { spaces: 2 });
232
+ }
233
+ isRunning() {
234
+ return this.running;
235
+ }
236
+ };
237
+
238
+ //#endregion
239
+ exports.TwitchConnector = TwitchConnector;
@@ -0,0 +1,162 @@
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/instagram/src/connector.ts
10
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "instagram-state.json");
11
+ function igReq(token, 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: "graph.facebook.com",
16
+ port: 443,
17
+ path: `/v18.0${endpoint}`,
18
+ method,
19
+ headers: {
20
+ "Authorization": `Bearer ${token}`,
21
+ ...payload ? {
22
+ "Content-Type": "application/json",
23
+ "Content-Length": Buffer.byteLength(payload)
24
+ } : {}
25
+ }
26
+ }, (res) => {
27
+ let data = "";
28
+ res.on("data", (c) => data += c);
29
+ res.on("end", () => {
30
+ try {
31
+ const r = JSON.parse(data);
32
+ if (r.error) reject(new Error(r.error.message));
33
+ else resolve(r);
34
+ } catch {
35
+ reject(new Error("Invalid JSON"));
36
+ }
37
+ });
38
+ });
39
+ req.on("error", reject);
40
+ if (payload) req.write(payload);
41
+ req.end();
42
+ });
43
+ }
44
+ var InstagramConnector = class extends events.EventEmitter {
45
+ config;
46
+ running = false;
47
+ processedIds = /* @__PURE__ */ new Set();
48
+ constructor(config) {
49
+ super();
50
+ this.config = {
51
+ dmPolicy: "allowlist",
52
+ allowFrom: [],
53
+ approvedPairings: [],
54
+ pendingPairings: {},
55
+ ...config
56
+ };
57
+ }
58
+ async connect() {
59
+ const info = await igReq(this.config.pageAccessToken, "GET", `/${this.config.instagramAccountId}?fields=name,username`);
60
+ await this.loadState();
61
+ this.running = true;
62
+ console.log(chalk.default.green(` 🦅 Instagram: @${info.username || info.name} connected`));
63
+ this.emit("connected", {
64
+ accountId: this.config.instagramAccountId,
65
+ username: info.username
66
+ });
67
+ }
68
+ disconnect() {
69
+ this.running = false;
70
+ }
71
+ verifyWebhook(mode, token, challenge) {
72
+ return mode === "subscribe" && token === this.config.verifyToken ? challenge : null;
73
+ }
74
+ async handleWebhook(body) {
75
+ let payload;
76
+ try {
77
+ payload = JSON.parse(body);
78
+ } catch {
79
+ return;
80
+ }
81
+ for (const entry of payload.entry || []) for (const messaging of entry.messaging || []) {
82
+ if (!messaging.message || messaging.message.is_echo) continue;
83
+ const msgId = messaging.message.mid;
84
+ if (this.processedIds.has(msgId)) continue;
85
+ this.processedIds.add(msgId);
86
+ const senderId = messaging.sender.id;
87
+ const text = messaging.message.text;
88
+ if (!text) continue;
89
+ const allowed = await this.checkDMPolicy(senderId, text);
90
+ if (!allowed) continue;
91
+ this.emit("message", {
92
+ id: msgId,
93
+ channelId: "instagram",
94
+ from: senderId,
95
+ chatId: senderId,
96
+ text,
97
+ timestamp: new Date(messaging.timestamp).toISOString(),
98
+ isDM: true
99
+ });
100
+ }
101
+ }
102
+ async checkDMPolicy(from, text) {
103
+ if (this.config.dmPolicy === "none") return false;
104
+ if (this.config.dmPolicy === "open") return true;
105
+ if (this.config.dmPolicy === "allowlist") {
106
+ if (this.config.allowFrom.includes(from)) return true;
107
+ await this.sendMessage(from, "🦅 HyperClaw: You are not on the allowlist.");
108
+ return false;
109
+ }
110
+ if (this.config.dmPolicy === "pairing") {
111
+ if (this.config.approvedPairings.includes(from)) return true;
112
+ const upper = text.trim().toUpperCase();
113
+ if (this.config.pendingPairings[upper]) {
114
+ this.config.approvedPairings.push(from);
115
+ delete this.config.pendingPairings[upper];
116
+ await this.saveState();
117
+ await this.sendMessage(from, "🦅 Paired! You can now send messages.");
118
+ return true;
119
+ }
120
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
121
+ this.config.pendingPairings[code] = from;
122
+ await this.saveState();
123
+ await this.sendMessage(from, `🦅 HyperClaw Pairing\nCode: ${code}\nApprove: hyperclaw pairing approve instagram ${code}`);
124
+ return false;
125
+ }
126
+ return false;
127
+ }
128
+ async sendMessage(recipientId, text) {
129
+ await igReq(this.config.pageAccessToken, "POST", `/${this.config.instagramAccountId}/messages`, {
130
+ recipient: { id: recipientId },
131
+ message: { text: text.slice(0, 2e3) }
132
+ });
133
+ }
134
+ approvePairing(code) {
135
+ const upper = code.toUpperCase();
136
+ if (!this.config.pendingPairings[upper]) return false;
137
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
138
+ delete this.config.pendingPairings[upper];
139
+ this.saveState();
140
+ return true;
141
+ }
142
+ async loadState() {
143
+ try {
144
+ const s = await fs_extra.default.readJson(STATE_FILE);
145
+ if (s.p) this.config.pendingPairings = s.p;
146
+ if (s.a) this.config.approvedPairings = s.a;
147
+ } catch {}
148
+ }
149
+ async saveState() {
150
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
151
+ await fs_extra.default.writeJson(STATE_FILE, {
152
+ p: this.config.pendingPairings,
153
+ a: this.config.approvedPairings
154
+ }, { spaces: 2 });
155
+ }
156
+ isRunning() {
157
+ return this.running;
158
+ }
159
+ };
160
+
161
+ //#endregion
162
+ exports.InstagramConnector = InstagramConnector;