hyperclaw 4.0.2 → 5.0.1

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 (194) hide show
  1. package/README.md +246 -60
  2. package/dist/a2ui-protocol-CfBI44-Q.js +75 -0
  3. package/dist/agents-routing-ChHiZp36.js +327 -0
  4. package/dist/agents-routing-ChqZ6l2S.js +4 -0
  5. package/dist/api-keys-guide-BCcOl0Q7.js +149 -0
  6. package/dist/api-keys-guide-CGn5BSF7.js +149 -0
  7. package/dist/audit-BJohI_vC.js +441 -0
  8. package/dist/audit-BaIiyWFu.js +441 -0
  9. package/dist/bounty-tools-CY_i91DU.js +211 -0
  10. package/dist/bounty-tools-DWudyZie.js +211 -0
  11. package/dist/browser-tools-BsTeGMnX.js +5 -0
  12. package/dist/browser-tools-D8_rLe2p.js +179 -0
  13. package/dist/claw-tasks-CgTsiNE8.js +80 -0
  14. package/dist/claw-tasks-Cyzdbhz_.js +80 -0
  15. package/dist/connector-5N0-X_xs.js +194 -0
  16. package/dist/connector-B3v0qcXg.js +425 -0
  17. package/dist/connector-B8R3iBY1.js +280 -0
  18. package/dist/connector-BAM-08NN.js +189 -0
  19. package/dist/connector-BC8FIVu4.js +181 -0
  20. package/dist/connector-BDmwwaVc.js +213 -0
  21. package/dist/connector-BGjbBy69.js +225 -0
  22. package/dist/connector-BO2SRzfG.js +218 -0
  23. package/dist/connector-BfXky0L3.js +167 -0
  24. package/dist/connector-BiiSJpx3.js +192 -0
  25. package/dist/connector-BnDmIhIu.js +85 -0
  26. package/dist/connector-C1HSoUyk.js +189 -0
  27. package/dist/connector-CKQHZOXg.js +568 -0
  28. package/dist/connector-CRl-iidy.js +239 -0
  29. package/dist/connector-Ci9glMD-.js +340 -0
  30. package/dist/connector-CjtZIEDj.js +181 -0
  31. package/dist/connector-Ck6JtOsX.js +531 -0
  32. package/dist/connector-D8Kelee0.js +286 -0
  33. package/dist/connector-DAnRJ0oP.js +162 -0
  34. package/dist/connector-DXTp5PE8.js +508 -0
  35. package/dist/connector-Dih6dUPP.js +173 -0
  36. package/dist/connector-DqTH_tPX.js +182 -0
  37. package/dist/connector-DrnEiiyP.js +419 -0
  38. package/dist/connector-DtR5GGTX.js +167 -0
  39. package/dist/connector-Tky_qS_K.js +350 -0
  40. package/dist/connector-ZSc3oTTy.js +305 -0
  41. package/dist/connector-sW5yhU1m.js +498 -0
  42. package/dist/connector-u3ICd3Ic.js +552 -0
  43. package/dist/cost-tracker-Ca1UPZ33.js +103 -0
  44. package/dist/cost-tracker-DD9wtWsr.js +103 -0
  45. package/dist/credentials-store-C6ir0Dae.js +4 -0
  46. package/dist/credentials-store-CA8UtK0T.js +77 -0
  47. package/dist/credentials-store-Cm7DH-kh.js +4 -0
  48. package/dist/credentials-store-H13LqOwJ.js +77 -0
  49. package/dist/cron-tasks-Bli7Kzd2.js +82 -0
  50. package/dist/cron-tasks-_pqQCmxc.js +82 -0
  51. package/dist/daemon-7ViroziB.js +5 -0
  52. package/dist/daemon-BfyKmZhr.js +318 -0
  53. package/dist/daemon-Bg4GtCmc.js +318 -0
  54. package/dist/daemon-DhmwY8k4.js +5 -0
  55. package/dist/delivery-BmIYy9VQ.js +4 -0
  56. package/dist/delivery-DVHmv1IR.js +4 -0
  57. package/dist/delivery-DpMX0Yyc.js +95 -0
  58. package/dist/delivery-pWUPBp1F.js +95 -0
  59. package/dist/destructive-gate-D6vWOdEl.js +101 -0
  60. package/dist/destructive-gate-DZt71UZR.js +101 -0
  61. package/dist/developer-keys-CPWT7Q6S.js +8 -0
  62. package/dist/developer-keys-DrrcUqFa.js +127 -0
  63. package/dist/doctor-BvCe8BBk.js +230 -0
  64. package/dist/doctor-CxyPLYsJ.js +6 -0
  65. package/dist/engine-B0kLfRL0.js +256 -0
  66. package/dist/engine-BJUpRUOv.js +7 -0
  67. package/dist/engine-CEDSqXfw.js +256 -0
  68. package/dist/engine-Da4JMNpI.js +7 -0
  69. package/dist/env-resolve-17ekEU6p.js +10 -0
  70. package/dist/env-resolve-CiXbWYwe.js +10 -0
  71. package/dist/env-resolve-CmGWhWXJ.js +115 -0
  72. package/dist/env-resolve-Z2XF6leB.js +115 -0
  73. package/dist/extraction-tools-HOZstZ0y.js +91 -0
  74. package/dist/extraction-tools-m4lmAv7l.js +5 -0
  75. package/dist/form_data-Cz040rio.js +8657 -0
  76. package/dist/gmail-watch-setup-Du7DVV7S.js +40 -0
  77. package/dist/health-B-asI__D.js +6 -0
  78. package/dist/health-Ds2YlpTB.js +152 -0
  79. package/dist/heartbeat-engine-BYT5ayQH.js +83 -0
  80. package/dist/heartbeat-engine-Ut6pXBD6.js +83 -0
  81. package/dist/hub-9LaKnLjY.js +6 -0
  82. package/dist/hub-CfwUz9YW.js +515 -0
  83. package/dist/hub-D0XwdjM-.js +515 -0
  84. package/dist/hub-LiD5Iztb.js +6 -0
  85. package/dist/hyperclawbot-CBiDSKsa.js +505 -0
  86. package/dist/hyperclawbot-zvczQgKx.js +505 -0
  87. package/dist/inference-0mlFQqIm.js +922 -0
  88. package/dist/inference-BKVkBREb.js +6 -0
  89. package/dist/inference-DCXH4Q3x.js +922 -0
  90. package/dist/inference-SzqFe_nk.js +6 -0
  91. package/dist/knowledge-graph-DE5lSF02.js +131 -0
  92. package/dist/knowledge-graph-iBG76fvm.js +131 -0
  93. package/dist/loader-BkDi8MD9.js +400 -0
  94. package/dist/loader-CC45xGpC.js +4 -0
  95. package/dist/loader-CnEdOyjT.js +400 -0
  96. package/dist/loader-DI2qDRPC.js +4 -0
  97. package/dist/logger-Cp8wC7F8.js +83 -0
  98. package/dist/logger-ybOp7VOC.js +83 -0
  99. package/dist/manager-03ipO9R0.js +105 -0
  100. package/dist/manager-B2Gls5RG.js +218 -0
  101. package/dist/manager-BpDfbDjg.js +117 -0
  102. package/dist/manager-Bxl0sqlh.js +4 -0
  103. package/dist/manager-CWNSML5D.js +117 -0
  104. package/dist/manager-CrVDn6eN.js +6 -0
  105. package/dist/manager-FCgF1plu.js +218 -0
  106. package/dist/manager-SJe9gt-q.js +4 -0
  107. package/dist/manager-rgCsaWT1.js +40 -0
  108. package/dist/mcp-CfoSU4Uz.js +139 -0
  109. package/dist/mcp-loader-CvxRDtPC.js +94 -0
  110. package/dist/mcp-loader-DkRBsLpk.js +94 -0
  111. package/dist/memory-BlHL7JCO.js +4 -0
  112. package/dist/memory-DsS_eFvJ.js +270 -0
  113. package/dist/memory-auto-BkvtSFUw.js +5 -0
  114. package/dist/memory-auto-Bnz_-1wP.js +306 -0
  115. package/dist/memory-auto-CpQHZlEJ.js +306 -0
  116. package/dist/memory-auto-Z6LCf-iK.js +5 -0
  117. package/dist/memory-integration-cSYkZyEo.js +91 -0
  118. package/dist/memory-integration-g2vxwgoE.js +91 -0
  119. package/dist/moltbook-BtLDZTfM.js +81 -0
  120. package/dist/moltbook-Cl8cQfxJ.js +81 -0
  121. package/dist/node-Dw2Gi-cP.js +222 -0
  122. package/dist/nodes-registry-B8dmrlLv.js +52 -0
  123. package/dist/nodes-registry-C9dCFwjh.js +52 -0
  124. package/dist/oauth-flow-CeaaGAz0.js +150 -0
  125. package/dist/oauth-flow-DQPvMHRH.js +150 -0
  126. package/dist/oauth-provider-B4dzn56l.js +110 -0
  127. package/dist/oauth-provider-Uo4Nib_c.js +110 -0
  128. package/dist/observability-BV-Yx0V9.js +89 -0
  129. package/dist/observability-nZ3CBIxG.js +89 -0
  130. package/dist/onboard-0WoDxbv_.js +10 -0
  131. package/dist/onboard-BBBWcfhp.js +10 -0
  132. package/dist/onboard-BXNXCQp4.js +4070 -0
  133. package/dist/onboard-Bw28IRQ3.js +4070 -0
  134. package/dist/orchestrator-BovkM63z.js +6 -0
  135. package/dist/orchestrator-DSbpkP1X.js +189 -0
  136. package/dist/orchestrator-DmnEvMaL.js +189 -0
  137. package/dist/orchestrator-RI3bpqqc.js +6 -0
  138. package/dist/osint-B4_m3VHQ.js +277 -0
  139. package/dist/pairing-6iM27aD8.js +196 -0
  140. package/dist/pairing-dGoiGepK.js +4 -0
  141. package/dist/pc-access-CgCsYrpt.js +8 -0
  142. package/dist/pc-access-_iH2aorG.js +819 -0
  143. package/dist/pending-approval-BgNjjuI2.js +22 -0
  144. package/dist/pending-approval-CUXjysAo.js +22 -0
  145. package/dist/reminders-store-Drjed_-h.js +58 -0
  146. package/dist/renderer-BVQrd0_g.js +225 -0
  147. package/dist/rules-BE4GV6cV.js +103 -0
  148. package/dist/run-main.js +1639 -460
  149. package/dist/runner-CJFJUtPm.js +1271 -0
  150. package/dist/runner-DatMMYYE.js +1271 -0
  151. package/dist/sdk/index.js +2 -2
  152. package/dist/sdk/index.mjs +2 -2
  153. package/dist/security-BqNyT4ID.js +4 -0
  154. package/dist/security-tpgqPWWH.js +73 -0
  155. package/dist/server-Brl_HQUB.js +1255 -0
  156. package/dist/server-D4wVHiX9.js +4 -0
  157. package/dist/server-Dh3JlBFB.js +1255 -0
  158. package/dist/server-DhfipkwN.js +4 -0
  159. package/dist/session-store-BUiPz0Vv.js +5 -0
  160. package/dist/session-store-is4B6qmD.js +113 -0
  161. package/dist/sessions-tools-CbUTFe4i.js +5 -0
  162. package/dist/sessions-tools-CeqD7iil.js +95 -0
  163. package/dist/skill-loader-BaNLVmJy.js +7 -0
  164. package/dist/skill-loader-HgpF6Vqs.js +159 -0
  165. package/dist/skill-runtime-BXWd-Ktf.js +102 -0
  166. package/dist/skill-runtime-CJN24QPW.js +102 -0
  167. package/dist/skill-runtime-jgklm02e.js +5 -0
  168. package/dist/skill-runtime-w1ig_lcw.js +5 -0
  169. package/dist/src-Bhybpk1J.js +63 -0
  170. package/dist/src-BxPHKO5x.js +63 -0
  171. package/dist/src-DIc-L2IG.js +20 -0
  172. package/dist/src-DMJ4-uqk.js +458 -0
  173. package/dist/src-g_rNx5rh.js +458 -0
  174. package/dist/sub-agent-tools-CHQoHz9c.js +39 -0
  175. package/dist/sub-agent-tools-DHY-4WWM.js +39 -0
  176. package/dist/theme-DcxwcUgZ.js +180 -0
  177. package/dist/theme-cx0fkgWC.js +8 -0
  178. package/dist/tool-policy-CNT-mF2Z.js +189 -0
  179. package/dist/tool-policy-DZvF8xlQ.js +189 -0
  180. package/dist/tts-elevenlabs-BRosZv-f.js +61 -0
  181. package/dist/tts-elevenlabs-C06nUxMK.js +61 -0
  182. package/dist/update-check-C2Dz85wJ.js +81 -0
  183. package/dist/update-check-w4XuxVl7.js +81 -0
  184. package/dist/vision-BMmiIKy7.js +121 -0
  185. package/dist/vision-JOtOS1Br.js +121 -0
  186. package/dist/vision-tools-CB28ZCO_.js +5 -0
  187. package/dist/vision-tools-DVuYc17I.js +51 -0
  188. package/dist/vision-tools-U3YC4L-g.js +5 -0
  189. package/dist/vision-tools-vPPwQ-0N.js +51 -0
  190. package/dist/voice-transcription-B555DbWR.js +138 -0
  191. package/dist/voice-transcription-DBo5hXmu.js +138 -0
  192. package/dist/website-watch-tools-DFMrJU-R.js +139 -0
  193. package/dist/website-watch-tools-Du3W5sN7.js +5 -0
  194. package/package.json +1 -1
@@ -0,0 +1,280 @@
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/telegram/src/connector.ts
10
+ function tgDownloadFile(token, filePath) {
11
+ return new Promise((resolve, reject) => {
12
+ const req = https.default.request({
13
+ hostname: "api.telegram.org",
14
+ port: 443,
15
+ path: `/file/bot${token}/${filePath}`,
16
+ method: "GET"
17
+ }, (res) => {
18
+ const chunks = [];
19
+ res.on("data", (c) => chunks.push(c));
20
+ res.on("end", () => resolve(Buffer.concat(chunks)));
21
+ });
22
+ req.on("error", reject);
23
+ req.setTimeout(3e4, () => {
24
+ req.destroy();
25
+ reject(new Error("Download timeout"));
26
+ });
27
+ req.end();
28
+ });
29
+ }
30
+ function tgRequest(token, method, body) {
31
+ return new Promise((resolve, reject) => {
32
+ const payload = body ? JSON.stringify(body) : null;
33
+ const req = https.default.request({
34
+ hostname: "api.telegram.org",
35
+ port: 443,
36
+ path: `/bot${token}/${method}`,
37
+ method: payload ? "POST" : "GET",
38
+ headers: payload ? {
39
+ "Content-Type": "application/json",
40
+ "Content-Length": Buffer.byteLength(payload)
41
+ } : {}
42
+ }, (res) => {
43
+ let data = "";
44
+ res.on("data", (c) => data += c);
45
+ res.on("end", () => {
46
+ try {
47
+ const r = JSON.parse(data);
48
+ if (r.ok) resolve(r.result);
49
+ else reject(new Error(r.description || "Telegram API error"));
50
+ } catch {
51
+ reject(new Error("Invalid JSON"));
52
+ }
53
+ });
54
+ });
55
+ req.on("error", reject);
56
+ req.setTimeout(35e3, () => {
57
+ req.destroy();
58
+ reject(new Error("Timeout"));
59
+ });
60
+ if (payload) req.write(payload);
61
+ req.end();
62
+ });
63
+ }
64
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "telegram-state.json");
65
+ function sleep(ms) {
66
+ return new Promise((r) => setTimeout(r, ms));
67
+ }
68
+ function generateCode() {
69
+ const chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
70
+ return Array.from({ length: 6 }, () => chars[Math.floor(Math.random() * chars.length)]).join("");
71
+ }
72
+ function chunkText(text, max) {
73
+ if (text.length <= max) return [text];
74
+ const chunks = [];
75
+ let i = 0;
76
+ while (i < text.length) {
77
+ let end = Math.min(i + max, text.length);
78
+ if (end < text.length) {
79
+ const nl = text.lastIndexOf("\n", end);
80
+ if (nl > i) end = nl + 1;
81
+ }
82
+ chunks.push(text.slice(i, end));
83
+ i = end;
84
+ }
85
+ return chunks;
86
+ }
87
+ var TelegramConnector = class extends events.EventEmitter {
88
+ token;
89
+ config;
90
+ offset = 0;
91
+ running = false;
92
+ botInfo = null;
93
+ constructor(token, config) {
94
+ super();
95
+ this.token = token;
96
+ this.config = {
97
+ token,
98
+ dmPolicy: "allowlist",
99
+ allowFrom: [],
100
+ pendingPairings: {},
101
+ approvedPairings: [],
102
+ ...config
103
+ };
104
+ }
105
+ async connect() {
106
+ this.botInfo = await tgRequest(this.token, "getMe");
107
+ console.log(chalk.default.green(` 🦅 Telegram: @${this.botInfo?.username} connected`));
108
+ await this.loadState();
109
+ this.running = true;
110
+ this.pollLoop();
111
+ this.emit("connected", this.botInfo);
112
+ }
113
+ async disconnect() {
114
+ this.running = false;
115
+ await this.saveState();
116
+ }
117
+ async pollLoop() {
118
+ while (this.running) try {
119
+ const updates = await tgRequest(this.token, "getUpdates", {
120
+ offset: this.offset,
121
+ timeout: 30,
122
+ allowed_updates: ["message"]
123
+ });
124
+ for (const u of updates) {
125
+ this.offset = u.update_id + 1;
126
+ await this.handleUpdate(u).catch((e) => console.log(chalk.default.yellow(` ⚠ ${e.message}`)));
127
+ }
128
+ } catch (e) {
129
+ if (this.running) {
130
+ console.log(chalk.default.yellow(` ⚠ Telegram poll: ${e.message}`));
131
+ await sleep(5e3);
132
+ }
133
+ }
134
+ }
135
+ async handleUpdate(u) {
136
+ const msg = u.message || u.edited_message;
137
+ if (!msg) return;
138
+ const text = msg.text?.trim() || "";
139
+ if (!text && !msg.voice) return;
140
+ const userId = String(msg.from?.id || "");
141
+ const isDM = msg.chat.type === "private";
142
+ const isGroup = msg.chat.type === "group" || msg.chat.type === "supergroup";
143
+ if (isDM && !await this.checkDMPolicy(userId, msg.chat.id, text || "[voice note]")) return;
144
+ let finalText = text || "[voice note]";
145
+ if (isGroup) {
146
+ const groupAllowFrom = this.config.groupAllowFrom ?? [];
147
+ if (groupAllowFrom.length > 0 && !groupAllowFrom.includes(String(msg.chat.id))) return;
148
+ const activation = this.config.groupActivation ?? "mention";
149
+ if (activation === "mention") {
150
+ const botUsername = this.botInfo?.username ? `@${this.botInfo.username}`.toLowerCase() : "";
151
+ const mentioned = botUsername && text.toLowerCase().includes(botUsername);
152
+ const isReplyToBot = msg.reply_to_message?.from?.is_bot && msg.reply_to_message.from.id === this.botInfo?.id;
153
+ if (!mentioned && !isReplyToBot) return;
154
+ if (mentioned && botUsername) finalText = text.replace(new RegExp(botUsername, "gi"), "").trim() || finalText;
155
+ }
156
+ }
157
+ let audioPath;
158
+ if (msg?.voice?.file_id) try {
159
+ const file = await tgRequest(this.token, "getFile", { file_id: msg.voice.file_id });
160
+ const buf = await tgDownloadFile(this.token, file.file_path);
161
+ const ext = (file.file_path || "").split(".").pop() || "oga";
162
+ const tmp = path.default.join(os.default.tmpdir(), `hyperclaw-tg-voice-${msg.message_id}.${ext}`);
163
+ await fs_extra.default.writeFile(tmp, buf);
164
+ audioPath = tmp;
165
+ } catch (e) {
166
+ console.log(chalk.default.yellow(` ⚠ Telegram voice download failed: ${e.message}`));
167
+ }
168
+ this.emit("message", {
169
+ id: String(msg.message_id),
170
+ channelId: "telegram",
171
+ from: userId,
172
+ fromUsername: msg.from?.username,
173
+ chatId: msg.chat.id,
174
+ text: finalText,
175
+ audioPath,
176
+ timestamp: new Date(msg.date * 1e3).toISOString(),
177
+ isDM
178
+ });
179
+ }
180
+ async checkDMPolicy(userId, chatId, text) {
181
+ if (this.config.dmPolicy === "none") return false;
182
+ if (this.config.dmPolicy === "open") return true;
183
+ if (this.config.dmPolicy === "allowlist") {
184
+ if (this.config.allowFrom.includes(userId)) return true;
185
+ await this.sendMessage(chatId, `🦅 *HyperClaw*\n\nYou are not on the allowlist.`);
186
+ return false;
187
+ }
188
+ if (this.config.dmPolicy === "pairing") {
189
+ if (this.config.approvedPairings.includes(userId)) return true;
190
+ const upper = text.trim().toUpperCase();
191
+ if (this.config.pendingPairings[upper]) {
192
+ this.config.approvedPairings.push(userId);
193
+ delete this.config.pendingPairings[upper];
194
+ await this.saveState();
195
+ await this.sendMessage(chatId, `🦅 *Paired!* You can now send messages.`);
196
+ this.emit("pairing:approved", {
197
+ userId,
198
+ channelId: "telegram"
199
+ });
200
+ return true;
201
+ }
202
+ const code = generateCode();
203
+ this.config.pendingPairings[code] = userId;
204
+ await this.saveState();
205
+ await this.sendMessage(chatId, `🦅 *HyperClaw Pairing*\n\nSend the owner this code:\n\`${code}\`\n\nApprove with:\n\`hyperclaw pairing approve telegram ${code}\``);
206
+ console.log(chalk.default.cyan(` 🦅 Telegram pairing from ${userId} — code: ${code}`));
207
+ return false;
208
+ }
209
+ return false;
210
+ }
211
+ async sendMessage(chatId, text, opts = {}) {
212
+ const chunks = chunkText(text, 4096);
213
+ let last = null;
214
+ for (const chunk of chunks) last = await tgRequest(this.token, "sendMessage", {
215
+ chat_id: chatId,
216
+ text: chunk,
217
+ parse_mode: opts.parse_mode || "Markdown",
218
+ disable_web_page_preview: opts.disable_web_page_preview ?? true,
219
+ ...opts.reply_to_message_id ? { reply_to_message_id: opts.reply_to_message_id } : {}
220
+ });
221
+ return last;
222
+ }
223
+ async sendTyping(chatId) {
224
+ await tgRequest(this.token, "sendChatAction", {
225
+ chat_id: chatId,
226
+ action: "typing"
227
+ }).catch(() => {});
228
+ }
229
+ approvePairing(code) {
230
+ const upper = code.toUpperCase();
231
+ if (!this.config.pendingPairings[upper]) return false;
232
+ const userId = this.config.pendingPairings[upper];
233
+ this.config.approvedPairings.push(userId);
234
+ delete this.config.pendingPairings[upper];
235
+ this.saveState();
236
+ return true;
237
+ }
238
+ addToAllowlist(userId) {
239
+ if (!this.config.allowFrom.includes(userId)) {
240
+ this.config.allowFrom.push(userId);
241
+ this.saveState();
242
+ }
243
+ }
244
+ listPendingPairings() {
245
+ return Object.entries(this.config.pendingPairings).map(([code, userId]) => ({
246
+ code,
247
+ userId
248
+ }));
249
+ }
250
+ handleWebhookPayload(body) {
251
+ try {
252
+ this.handleUpdate(JSON.parse(body));
253
+ } catch {}
254
+ }
255
+ async loadState() {
256
+ try {
257
+ const s = await fs_extra.default.readJson(STATE_FILE);
258
+ this.offset = s.offset || 0;
259
+ if (s.pendingPairings) this.config.pendingPairings = s.pendingPairings;
260
+ if (s.approvedPairings) this.config.approvedPairings = s.approvedPairings;
261
+ } catch {}
262
+ }
263
+ async saveState() {
264
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
265
+ await fs_extra.default.writeJson(STATE_FILE, {
266
+ offset: this.offset,
267
+ pendingPairings: this.config.pendingPairings,
268
+ approvedPairings: this.config.approvedPairings
269
+ }, { spaces: 2 });
270
+ }
271
+ isRunning() {
272
+ return this.running;
273
+ }
274
+ getBotInfo() {
275
+ return this.botInfo;
276
+ }
277
+ };
278
+
279
+ //#endregion
280
+ exports.TelegramConnector = TelegramConnector;
@@ -0,0 +1,189 @@
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/msteams/src/connector.ts
10
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "msteams-state.json");
11
+ let cachedToken = null;
12
+ async function getBotToken(appId, appPassword) {
13
+ if (cachedToken && cachedToken.expiresAt > Date.now() + 6e4) return cachedToken.token;
14
+ return new Promise((resolve, reject) => {
15
+ const body = `grant_type=client_credentials&client_id=${encodeURIComponent(appId)}&client_secret=${encodeURIComponent(appPassword)}&scope=https%3A%2F%2Fapi.botframework.com%2F.default`;
16
+ const req = https.default.request({
17
+ hostname: "login.microsoftonline.com",
18
+ port: 443,
19
+ path: "/botframework.com/oauth2/v2.0/token",
20
+ method: "POST",
21
+ headers: {
22
+ "Content-Type": "application/x-www-form-urlencoded",
23
+ "Content-Length": Buffer.byteLength(body)
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
+ cachedToken = {
32
+ token: r.access_token,
33
+ expiresAt: Date.now() + r.expires_in * 1e3
34
+ };
35
+ resolve(r.access_token);
36
+ } catch {
37
+ reject(new Error("Token parse error"));
38
+ }
39
+ });
40
+ });
41
+ req.on("error", reject);
42
+ req.write(body);
43
+ req.end();
44
+ });
45
+ }
46
+ async function sendActivity(token, serviceUrl, conversationId, activity) {
47
+ const url = new URL(`${serviceUrl}v3/conversations/${conversationId}/activities`);
48
+ return new Promise((resolve, reject) => {
49
+ const payload = JSON.stringify(activity);
50
+ const req = https.default.request({
51
+ hostname: url.hostname,
52
+ port: 443,
53
+ path: url.pathname,
54
+ method: "POST",
55
+ headers: {
56
+ "Authorization": `Bearer ${token}`,
57
+ "Content-Type": "application/json",
58
+ "Content-Length": Buffer.byteLength(payload)
59
+ }
60
+ }, (res) => {
61
+ res.on("data", () => {});
62
+ res.on("end", resolve);
63
+ });
64
+ req.on("error", reject);
65
+ req.write(payload);
66
+ req.end();
67
+ });
68
+ }
69
+ var MSTeamsConnector = class extends events.EventEmitter {
70
+ config;
71
+ running = false;
72
+ constructor(config) {
73
+ super();
74
+ this.config = {
75
+ dmPolicy: "allowlist",
76
+ allowFrom: [],
77
+ approvedPairings: [],
78
+ pendingPairings: {},
79
+ ...config
80
+ };
81
+ }
82
+ async connect() {
83
+ await getBotToken(this.config.appId, this.config.appPassword);
84
+ await this.loadState();
85
+ this.running = true;
86
+ console.log(chalk.default.green(` 🦅 MS Teams: Bot ${this.config.appId} connected`));
87
+ this.emit("connected", { appId: this.config.appId });
88
+ }
89
+ disconnect() {
90
+ this.running = false;
91
+ }
92
+ async handleWebhook(body) {
93
+ let activity;
94
+ try {
95
+ activity = JSON.parse(body);
96
+ } catch {
97
+ return;
98
+ }
99
+ if (activity.type !== "message") return;
100
+ const from = activity.from?.aadObjectId || activity.from?.id;
101
+ const text = activity.text?.replace(/<at>[^<]+<\/at>/g, "").trim();
102
+ const serviceUrl = activity.serviceUrl;
103
+ const conversationId = activity.conversation?.id;
104
+ if (!from || !text || !serviceUrl || !conversationId) return;
105
+ const allowed = await this.checkDMPolicy(from, text, serviceUrl, conversationId, activity);
106
+ if (!allowed) return;
107
+ this.emit("message", {
108
+ id: activity.id,
109
+ channelId: "msteams",
110
+ from,
111
+ chatId: conversationId,
112
+ fromName: activity.from?.name,
113
+ text,
114
+ timestamp: activity.timestamp || (/* @__PURE__ */ new Date()).toISOString(),
115
+ isDM: activity.conversation?.conversationType === "personal",
116
+ serviceUrl,
117
+ activity
118
+ });
119
+ }
120
+ async checkDMPolicy(from, text, serviceUrl, convId, activity) {
121
+ if (this.config.dmPolicy === "none") return false;
122
+ if (this.config.dmPolicy === "open") return true;
123
+ if (this.config.dmPolicy === "allowlist") {
124
+ if (this.config.allowFrom.includes(from)) return true;
125
+ await this.reply(serviceUrl, convId, activity, "🦅 HyperClaw: Not on allowlist.");
126
+ return false;
127
+ }
128
+ if (this.config.dmPolicy === "pairing") {
129
+ if (this.config.approvedPairings.includes(from)) return true;
130
+ const upper = text.trim().toUpperCase();
131
+ if (this.config.pendingPairings[upper]) {
132
+ this.config.approvedPairings.push(from);
133
+ delete this.config.pendingPairings[upper];
134
+ await this.saveState();
135
+ await this.reply(serviceUrl, convId, activity, "🦅 Paired!");
136
+ this.emit("pairing:approved", {
137
+ userId: from,
138
+ channelId: "msteams"
139
+ });
140
+ return true;
141
+ }
142
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
143
+ this.config.pendingPairings[code] = from;
144
+ await this.saveState();
145
+ await this.reply(serviceUrl, convId, activity, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve msteams ${code}`);
146
+ return false;
147
+ }
148
+ return false;
149
+ }
150
+ async reply(serviceUrl, conversationId, originalActivity, text) {
151
+ const token = await getBotToken(this.config.appId, this.config.appPassword);
152
+ await sendActivity(token, serviceUrl, conversationId, {
153
+ type: "message",
154
+ text: text.slice(0, 4e3),
155
+ replyToId: originalActivity.id,
156
+ from: { id: this.config.appId },
157
+ conversation: originalActivity.conversation,
158
+ recipient: originalActivity.from
159
+ });
160
+ }
161
+ approvePairing(code) {
162
+ const upper = code.toUpperCase();
163
+ if (!this.config.pendingPairings[upper]) return false;
164
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
165
+ delete this.config.pendingPairings[upper];
166
+ this.saveState();
167
+ return true;
168
+ }
169
+ async loadState() {
170
+ try {
171
+ const s = await fs_extra.default.readJson(STATE_FILE);
172
+ if (s.p) this.config.pendingPairings = s.p;
173
+ if (s.a) this.config.approvedPairings = s.a;
174
+ } catch {}
175
+ }
176
+ async saveState() {
177
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
178
+ await fs_extra.default.writeJson(STATE_FILE, {
179
+ p: this.config.pendingPairings,
180
+ a: this.config.approvedPairings
181
+ }, { spaces: 2 });
182
+ }
183
+ isRunning() {
184
+ return this.running;
185
+ }
186
+ };
187
+
188
+ //#endregion
189
+ exports.MSTeamsConnector = MSTeamsConnector;
@@ -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 http = require_chunk.__toESM(require("http"));
7
+ const ws = require_chunk.__toESM(require("ws"));
8
+ const https = require_chunk.__toESM(require("https"));
9
+ const events = require_chunk.__toESM(require("events"));
10
+
11
+ //#region extensions/bluebubbles/src/connector.ts
12
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "bluebubbles-state.json");
13
+ function bbReq(serverUrl, password, method, endpoint, body) {
14
+ return new Promise((resolve, reject) => {
15
+ const url = new URL(`${serverUrl}/api/v1${endpoint}`);
16
+ url.searchParams.set("password", password);
17
+ const isHttps = url.protocol === "https:";
18
+ const mod = isHttps ? https.default : http.default;
19
+ const payload = body ? JSON.stringify(body) : null;
20
+ const req = mod.request({
21
+ hostname: url.hostname,
22
+ port: url.port || (isHttps ? 443 : 1234),
23
+ path: url.pathname + url.search,
24
+ method,
25
+ headers: payload ? {
26
+ "Content-Type": "application/json",
27
+ "Content-Length": Buffer.byteLength(payload)
28
+ } : {},
29
+ rejectUnauthorized: false
30
+ }, (res) => {
31
+ let data = "";
32
+ res.on("data", (c) => data += c);
33
+ res.on("end", () => {
34
+ try {
35
+ const r = JSON.parse(data);
36
+ if (r.status !== 200) reject(new Error(r.error?.message || "BB error"));
37
+ else resolve(r.data);
38
+ } catch {
39
+ reject(new Error("Invalid JSON"));
40
+ }
41
+ });
42
+ });
43
+ req.on("error", reject);
44
+ if (payload) req.write(payload);
45
+ req.end();
46
+ });
47
+ }
48
+ var BlueBubblesConnector = class extends events.EventEmitter {
49
+ config;
50
+ running = false;
51
+ ws = null;
52
+ lastMessageTs = 0;
53
+ constructor(config) {
54
+ super();
55
+ this.config = {
56
+ dmPolicy: "allowlist",
57
+ allowFrom: [],
58
+ approvedPairings: [],
59
+ pendingPairings: {},
60
+ ...config
61
+ };
62
+ }
63
+ async connect() {
64
+ const info = await bbReq(this.config.serverUrl, this.config.password, "GET", "/server/info");
65
+ await this.loadState();
66
+ this.running = true;
67
+ console.log(chalk.default.green(` 🦅 BlueBubbles (iMessage): ${info?.os_version || "macOS"} server connected`));
68
+ this.emit("connected", { serverInfo: info });
69
+ this.connectWebSocket();
70
+ }
71
+ connectWebSocket() {
72
+ const url = new URL(this.config.serverUrl);
73
+ const wsUrl = `${url.protocol === "https:" ? "wss" : "ws"}://${url.hostname}:${url.port || 1234}`;
74
+ this.ws = new ws.WebSocket(`${wsUrl}?password=${encodeURIComponent(this.config.password)}`, { rejectUnauthorized: false });
75
+ this.ws.on("message", async (data) => {
76
+ try {
77
+ const event = JSON.parse(data.toString());
78
+ if (event.type === "new-message" || event.type === "updated-message") await this.handleMessage(event.data);
79
+ } catch {}
80
+ });
81
+ this.ws.on("close", () => {
82
+ if (this.running) setTimeout(() => this.connectWebSocket(), 5e3);
83
+ });
84
+ this.ws.on("error", () => {});
85
+ setInterval(() => {
86
+ if (this.ws?.readyState === ws.WebSocket.OPEN) this.ws.send(JSON.stringify({ type: "ping" }));
87
+ }, 3e4);
88
+ }
89
+ async handleMessage(msg) {
90
+ if (!msg || msg.isFromMe) return;
91
+ const text = msg.text;
92
+ const from = msg.handle?.address;
93
+ if (!text || !from) return;
94
+ const ts = msg.dateCreated || 0;
95
+ if (ts <= this.lastMessageTs) return;
96
+ this.lastMessageTs = ts;
97
+ await this.saveState();
98
+ const allowed = await this.checkDMPolicy(from, text);
99
+ if (!allowed) return;
100
+ this.emit("message", {
101
+ id: msg.guid,
102
+ channelId: "bluebubbles",
103
+ from,
104
+ chatId: msg.chats?.[0]?.guid || from,
105
+ text,
106
+ timestamp: new Date(ts).toISOString(),
107
+ isDM: !msg.isGroup
108
+ });
109
+ }
110
+ async checkDMPolicy(from, text) {
111
+ if (this.config.dmPolicy === "none") return false;
112
+ if (this.config.dmPolicy === "open") return true;
113
+ if (this.config.dmPolicy === "allowlist") {
114
+ if (this.config.allowFrom.includes(from)) return true;
115
+ await this.sendMessage(from, "🦅 HyperClaw: Not on allowlist.");
116
+ return false;
117
+ }
118
+ if (this.config.dmPolicy === "pairing") {
119
+ if (this.config.approvedPairings.includes(from)) return true;
120
+ const upper = text.trim().toUpperCase();
121
+ if (this.config.pendingPairings[upper]) {
122
+ this.config.approvedPairings.push(from);
123
+ delete this.config.pendingPairings[upper];
124
+ await this.saveState();
125
+ await this.sendMessage(from, "🦅 Paired!");
126
+ this.emit("pairing:approved", {
127
+ userId: from,
128
+ channelId: "bluebubbles"
129
+ });
130
+ return true;
131
+ }
132
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
133
+ this.config.pendingPairings[code] = from;
134
+ await this.saveState();
135
+ await this.sendMessage(from, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve bluebubbles ${code}`);
136
+ return false;
137
+ }
138
+ return false;
139
+ }
140
+ async sendMessage(address, text) {
141
+ await bbReq(this.config.serverUrl, this.config.password, "POST", "/message/text", {
142
+ chatGuid: `iMessage;-;${address}`,
143
+ message: text.slice(0, 65536),
144
+ method: "apple-script"
145
+ });
146
+ }
147
+ disconnect() {
148
+ this.running = false;
149
+ this.ws?.close();
150
+ }
151
+ approvePairing(code) {
152
+ const upper = code.toUpperCase();
153
+ if (!this.config.pendingPairings[upper]) return false;
154
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
155
+ delete this.config.pendingPairings[upper];
156
+ this.saveState();
157
+ return true;
158
+ }
159
+ async loadState() {
160
+ try {
161
+ const s = await fs_extra.default.readJson(STATE_FILE);
162
+ this.lastMessageTs = s.lastTs || 0;
163
+ if (s.p) this.config.pendingPairings = s.p;
164
+ if (s.a) this.config.approvedPairings = s.a;
165
+ } catch {}
166
+ }
167
+ async saveState() {
168
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
169
+ await fs_extra.default.writeJson(STATE_FILE, {
170
+ lastTs: this.lastMessageTs,
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.BlueBubblesConnector = BlueBubblesConnector;