hyperclaw 4.0.1 → 4.0.2

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 (148) hide show
  1. package/README.md +7 -4
  2. package/dist/a2ui-protocol-CT_jDEU9.js +75 -0
  3. package/dist/agents-routing-683Q2JGp.js +129 -0
  4. package/dist/agents-routing-BpZBswBH.js +4 -0
  5. package/dist/api-keys-guide-Dq5Obbp4.js +149 -0
  6. package/dist/audit-BYxPlnTQ.js +248 -0
  7. package/dist/bounty-tools-C6LyzxM-.js +211 -0
  8. package/dist/browser-tools-CQBSbIuO.js +5 -0
  9. package/dist/browser-tools-YQmwRLLM.js +179 -0
  10. package/dist/claw-tasks-BRLUvFRD.js +80 -0
  11. package/dist/connector-3HnyH8fn.js +167 -0
  12. package/dist/connector-6PMZo5Ky.js +189 -0
  13. package/dist/connector-B6eoF3DD.js +181 -0
  14. package/dist/connector-B9tLG8UZ.js +196 -0
  15. package/dist/connector-BOlqjXWP.js +182 -0
  16. package/dist/connector-BP8zsbP8.js +189 -0
  17. package/dist/connector-BPoSevxp.js +286 -0
  18. package/dist/connector-BRHj773i.js +163 -0
  19. package/dist/connector-BToxU-jV.js +267 -0
  20. package/dist/connector-BliDVsJQ.js +239 -0
  21. package/dist/connector-Bv6s9oP7.js +88 -0
  22. package/dist/connector-By5wWGTR.js +343 -0
  23. package/dist/connector-C1BaFFgN.js +213 -0
  24. package/dist/connector-CRRWY5Wv.js +167 -0
  25. package/dist/connector-CXPQVGyI.js +85 -0
  26. package/dist/connector-Cdk1CXKi.js +194 -0
  27. package/dist/connector-CwlgFgjx.js +181 -0
  28. package/dist/connector-DFchk6l7.js +178 -0
  29. package/dist/connector-DKw7tRAy.js +192 -0
  30. package/dist/connector-DRv1ahC_.js +2 -2
  31. package/dist/connector-DU63KW94.js +165 -0
  32. package/dist/connector-Dbvb1Cj9.js +280 -0
  33. package/dist/connector-DcZdQcgR.js +173 -0
  34. package/dist/connector-DxKL8VvZ.js +182 -0
  35. package/dist/connector-T_YdZtzv.js +162 -0
  36. package/dist/connector-i4gOS9xL.js +154 -0
  37. package/dist/connector-rHXE1ZD2.js +167 -0
  38. package/dist/connector-wdUXChwa.js +172 -0
  39. package/dist/cost-tracker-pVE15Yq4.js +103 -0
  40. package/dist/credentials-store-BvnMPJwi.js +4 -0
  41. package/dist/credentials-store-sb-TRLwR.js +77 -0
  42. package/dist/cron-tasks-BvDFNyiE.js +82 -0
  43. package/dist/delivery-D5Z98EVq.js +95 -0
  44. package/dist/delivery-DCOXhXEO.js +5 -0
  45. package/dist/destructive-gate-m-dWqUFg.js +101 -0
  46. package/dist/developer-keys-JaJK3T27.js +127 -0
  47. package/dist/developer-keys-kyqmtWK3.js +8 -0
  48. package/dist/doctor-3oi89QIc.js +175 -0
  49. package/dist/doctor-Cf1XSfp9.js +4 -0
  50. package/dist/engine-B4eMiTgl.js +7 -0
  51. package/dist/engine-B8M7dYul.js +7 -0
  52. package/dist/engine-BhT-1M9W.js +256 -0
  53. package/dist/engine-D49jnSd_.js +256 -0
  54. package/dist/env-resolve-DWOQ45jG.js +9 -0
  55. package/dist/env-resolve-szSWl0UF.js +94 -0
  56. package/dist/extraction-tools-D3qDFBJ1.js +91 -0
  57. package/dist/extraction-tools-DLr_AEwq.js +5 -0
  58. package/dist/form_data-B_hIUrxU.js +8657 -0
  59. package/dist/gmail-watch-setup-Czt8rXaX.js +40 -0
  60. package/dist/heartbeat-engine-CRqfPcFM.js +83 -0
  61. package/dist/hub-DTsqe5Bt.js +6 -0
  62. package/dist/hub-FrPTA33j.js +515 -0
  63. package/dist/hyperclawbot-D9KCtc4P.js +480 -0
  64. package/dist/hyperclawbot-Dw27pJo4.js +480 -0
  65. package/dist/inference-CTWJeX9Q.js +922 -0
  66. package/dist/inference-ix607p7k.js +6 -0
  67. package/dist/knowledge-graph-DqA-Fztl.js +131 -0
  68. package/dist/loader-CISCqBto.js +400 -0
  69. package/dist/loader-CYMQ8VOS.js +4 -0
  70. package/dist/logger-8tEtAd3y.js +83 -0
  71. package/dist/manager-CPjeRe-6.js +4 -0
  72. package/dist/manager-Cwzj7w5R.js +105 -0
  73. package/dist/manager-DLmZI-9R.js +6 -0
  74. package/dist/manager-DSGhn5i3.js +117 -0
  75. package/dist/manager-DgyF52mg.js +218 -0
  76. package/dist/manager-Dm8nrMFx.js +40 -0
  77. package/dist/mcp-B_9Ber63.js +139 -0
  78. package/dist/mcp-loader-DSM5UiFG.js +94 -0
  79. package/dist/mcp-loader-j5ZLLw5O.js +94 -0
  80. package/dist/memory-BI1kPkAN.js +4 -0
  81. package/dist/memory-BVFGkxxK.js +270 -0
  82. package/dist/memory-auto-Bc7euou4.js +306 -0
  83. package/dist/memory-auto-DPfbkMVt.js +5 -0
  84. package/dist/memory-integration-DZExqWr4.js +91 -0
  85. package/dist/moltbook-B6ZeGN5_.js +81 -0
  86. package/dist/node-pwL6O_KX.js +222 -0
  87. package/dist/nodes-registry-CsPm_-CJ.js +52 -0
  88. package/dist/oauth-flow-CpWlgvNB.js +150 -0
  89. package/dist/oauth-provider-BZb6qOw5.js +110 -0
  90. package/dist/observability-B43YvNQV.js +89 -0
  91. package/dist/onboard-Bd_wsYdi.js +4086 -0
  92. package/dist/onboard-CAN7x3me.js +3026 -0
  93. package/dist/onboard-DnegOHMh.js +4 -4
  94. package/dist/onboard-RYtDlYBw.js +9 -0
  95. package/dist/onboard-aTwlQs-4.js +9 -0
  96. package/dist/orchestrator-BSp2M5EU.js +189 -0
  97. package/dist/orchestrator-C7ko5tWa.js +6 -0
  98. package/dist/orchestrator-DfPkIx2Z.js +6 -0
  99. package/dist/orchestrator-NJQsmiBE.js +189 -0
  100. package/dist/pairing-DU0_J28n.js +87 -0
  101. package/dist/pairing-DWllbSbO.js +4 -0
  102. package/dist/pc-access-Ly-uA8mn.js +8 -0
  103. package/dist/pc-access-NxBvTrRj.js +819 -0
  104. package/dist/pending-approval-DIHvwwWS.js +22 -0
  105. package/dist/puppeteer-2o3QOwAy.js +2 -2
  106. package/dist/puppeteer-BYTMp3BI.js +2 -2
  107. package/dist/puppeteer-DQ45qwWk.js +2 -2
  108. package/dist/reminders-store-D79qdfN0.js +58 -0
  109. package/dist/renderer-pqlDRKbH.js +225 -0
  110. package/dist/rules-BooT_qFP.js +103 -0
  111. package/dist/run-main.js +289 -1031
  112. package/dist/runner-D1rjuMTJ.js +810 -0
  113. package/dist/sdk/index.js +2 -2
  114. package/dist/sdk/index.mjs +2 -2
  115. package/dist/security-C-5URby1.js +73 -0
  116. package/dist/security-_xve79aq.js +4 -0
  117. package/dist/server-0kgyELx4.js +1047 -0
  118. package/dist/server-BIuTobTC.js +4 -0
  119. package/dist/server-BRlCEjyT.js +1047 -0
  120. package/dist/server-CCI1hv45.js +2 -2
  121. package/dist/server-DU9POoWc.js +4 -0
  122. package/dist/session-store-CujxByI6.js +113 -0
  123. package/dist/session-store-qpJUg2M1.js +5 -0
  124. package/dist/sessions-tools-CB2qbwIk.js +5 -0
  125. package/dist/sessions-tools-DHMaTZIs.js +95 -0
  126. package/dist/skill-loader-BkceKkIg.js +7 -0
  127. package/dist/skill-loader-DhgIwK4J.js +159 -0
  128. package/dist/skill-runtime--LqxWrp5.js +102 -0
  129. package/dist/skill-runtime-C5l0Tgt-.js +5 -0
  130. package/dist/skill-runtime-DsXK_HYG.js +102 -0
  131. package/dist/skill-runtime-IVTiqrMR.js +5 -0
  132. package/dist/src-BEVLgaF1.js +63 -0
  133. package/dist/src-Bgu_OxTQ.js +458 -0
  134. package/dist/src-Bq-oKt7Z.js +458 -0
  135. package/dist/src-DWCUhnD4.js +20 -0
  136. package/dist/src-cfRTjFef.js +63 -0
  137. package/dist/sub-agent-tools-BD9DF8_g.js +39 -0
  138. package/dist/sub-agent-tools-V7b3T9_s.js +39 -0
  139. package/dist/tool-policy-DNvNRnve.js +189 -0
  140. package/dist/tts-elevenlabs-BUOGKL-k.js +61 -0
  141. package/dist/update-check-BD4qH7Am.js +81 -0
  142. package/dist/vision-DRq-f-Dj.js +121 -0
  143. package/dist/vision-tools-CFZEpQKm.js +5 -0
  144. package/dist/vision-tools-CQnBI9aa.js +51 -0
  145. package/dist/voice-transcription-CgWq54hn.js +138 -0
  146. package/dist/website-watch-tools-Bk_TnwuE.js +5 -0
  147. package/dist/website-watch-tools-DraMPxdl.js +139 -0
  148. package/package.json +1 -1
@@ -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;
@@ -0,0 +1,154 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const fs_extra = require_chunk.__toESM(require("fs-extra"));
3
+ const path = require_chunk.__toESM(require("path"));
4
+ const os = require_chunk.__toESM(require("os"));
5
+ const child_process = require_chunk.__toESM(require("child_process"));
6
+ const util = require_chunk.__toESM(require("util"));
7
+ const events = require_chunk.__toESM(require("events"));
8
+
9
+ //#region extensions/imessage-native/src/connector.ts
10
+ const execAsync = (0, util.promisify)(child_process.exec);
11
+ const IMSC_PATH = process.env.IMSG_PATH || "imsg";
12
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "imessage-native-state.json");
13
+ var IMessageNativeConnector = class extends events.EventEmitter {
14
+ config;
15
+ watchProc = null;
16
+ running = false;
17
+ lastMessageTs = 0;
18
+ constructor(config = {}) {
19
+ super();
20
+ this.config = {
21
+ dmPolicy: config.dmPolicy ?? "pairing",
22
+ allowFrom: config.allowFrom ?? [],
23
+ approvedPairings: config.approvedPairings ?? [],
24
+ pendingPairings: config.pendingPairings ?? {}
25
+ };
26
+ }
27
+ async connect() {
28
+ if (process.platform !== "darwin") throw new Error("imessage-native is macOS only. Use BlueBubbles on other platforms.");
29
+ await this.loadState();
30
+ this.running = true;
31
+ this.emit("connected", {});
32
+ this.startWatch();
33
+ }
34
+ startWatch() {
35
+ if (!this.running) return;
36
+ this.watchProc = (0, child_process.spawn)(IMSC_PATH, [
37
+ "watch",
38
+ "--output",
39
+ "json"
40
+ ], { stdio: [
41
+ "ignore",
42
+ "pipe",
43
+ "pipe"
44
+ ] });
45
+ let buf = "";
46
+ this.watchProc.stdout?.on("data", (chunk) => {
47
+ buf += chunk.toString();
48
+ const lines = buf.split("\n");
49
+ buf = lines.pop() || "";
50
+ for (const line of lines) {
51
+ if (!line.trim()) continue;
52
+ try {
53
+ const msg = JSON.parse(line);
54
+ if (msg.isFromMe) continue;
55
+ const handle = msg.handle?.address || msg.sender || msg.chatId || msg.from;
56
+ const text = msg.text || msg.body || msg.message;
57
+ if (!handle || !text) continue;
58
+ const ts = msg.dateCreated || msg.timestamp || Date.now();
59
+ if (ts <= this.lastMessageTs) continue;
60
+ this.lastMessageTs = ts;
61
+ this.saveState();
62
+ this.checkDMPolicyAndEmit(handle, text);
63
+ } catch {}
64
+ }
65
+ });
66
+ this.watchProc.stderr?.on("data", () => {});
67
+ this.watchProc.on("error", () => {});
68
+ this.watchProc.on("exit", (code) => {
69
+ this.watchProc = null;
70
+ if (this.running && code !== 0) setTimeout(() => this.startWatch(), 5e3);
71
+ });
72
+ }
73
+ async checkDMPolicyAndEmit(from, text) {
74
+ if (this.config.dmPolicy === "none") return;
75
+ if (this.config.dmPolicy === "open") {
76
+ this.emit("message", {
77
+ chatId: from,
78
+ text
79
+ });
80
+ return;
81
+ }
82
+ if (this.config.dmPolicy === "allowlist") {
83
+ if (this.config.allowFrom.includes(from)) this.emit("message", {
84
+ chatId: from,
85
+ text
86
+ });
87
+ else await this.sendMessage(from, "HyperClaw: Not on allowlist.");
88
+ return;
89
+ }
90
+ if (this.config.dmPolicy === "pairing") {
91
+ if (this.config.approvedPairings.includes(from)) {
92
+ this.emit("message", {
93
+ chatId: from,
94
+ text
95
+ });
96
+ return;
97
+ }
98
+ const code = (text.trim().toUpperCase().match(/[A-Z0-9]{6}/) || [])[0];
99
+ if (code && this.config.pendingPairings[code]) {
100
+ this.config.approvedPairings.push(from);
101
+ delete this.config.pendingPairings[code];
102
+ await this.saveState();
103
+ await this.sendMessage(from, "Paired!");
104
+ this.emit("pairing:approved", {
105
+ userId: from,
106
+ channelId: "imessage-native"
107
+ });
108
+ this.emit("message", {
109
+ chatId: from,
110
+ text
111
+ });
112
+ return;
113
+ }
114
+ const newCode = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
115
+ this.config.pendingPairings[newCode] = from;
116
+ await this.saveState();
117
+ await this.sendMessage(from, `Pairing code: ${newCode}\nApprove: hyperclaw pairing approve imessage-native ${newCode}`);
118
+ }
119
+ }
120
+ async sendMessage(chatId, text) {
121
+ const to = String(chatId).trim();
122
+ if (!to) return;
123
+ const escaped = text.replace(/"/g, "\\\"").replace(/\$/g, "\\$");
124
+ try {
125
+ await execAsync(`"${IMSC_PATH}" send --to "${to}" --text "${escaped}"`, { timeout: 15e3 });
126
+ } catch (e) {
127
+ throw new Error(`imsg send failed: ${e.message}`);
128
+ }
129
+ }
130
+ disconnect() {
131
+ this.running = false;
132
+ this.watchProc?.kill();
133
+ this.watchProc = null;
134
+ }
135
+ async loadState() {
136
+ try {
137
+ const s = await fs_extra.default.readJson(STATE_FILE);
138
+ this.lastMessageTs = s.lastTs || 0;
139
+ if (s.p) this.config.pendingPairings = s.p;
140
+ if (s.a) this.config.approvedPairings = s.a;
141
+ } catch {}
142
+ }
143
+ async saveState() {
144
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
145
+ await fs_extra.default.writeJson(STATE_FILE, {
146
+ lastTs: this.lastMessageTs,
147
+ p: this.config.pendingPairings,
148
+ a: this.config.approvedPairings
149
+ }, { spaces: 2 });
150
+ }
151
+ };
152
+
153
+ //#endregion
154
+ exports.IMessageNativeConnector = IMessageNativeConnector;
@@ -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 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 audioPath;
64
+ try {
65
+ const { downloadMediaMessage } = require("@whiskeysockets/baileys");
66
+ const buf = await downloadMediaMessage(m, "buffer", {}, { reuploadRequest: this.sock?.updateMessageSent });
67
+ const tmp = path.default.join(os.default.tmpdir(), `hyperclaw-voice-${m.key.id}.ogg`);
68
+ await fs_extra.default.writeFile(tmp, buf);
69
+ audioPath = tmp;
70
+ } catch {}
71
+ this.emit("message", {
72
+ id: m.key.id,
73
+ channelId: "whatsapp-baileys",
74
+ from,
75
+ chatId: m.key.remoteJid,
76
+ text: "[voice note]",
77
+ audioPath,
78
+ timestamp: new Date(parseInt(m.messageTimestamp || "0") * 1e3).toISOString(),
79
+ isDM: true
80
+ });
81
+ continue;
82
+ }
83
+ if (!text) continue;
84
+ const allowed = await this.checkDMPolicy(from, text);
85
+ if (!allowed) continue;
86
+ this.emit("message", {
87
+ id: m.key.id,
88
+ channelId: "whatsapp-baileys",
89
+ from,
90
+ chatId: m.key.remoteJid,
91
+ text,
92
+ timestamp: new Date(parseInt(m.messageTimestamp) * 1e3).toISOString(),
93
+ isDM: true
94
+ });
95
+ }
96
+ });
97
+ this.running = true;
98
+ }
99
+ async checkDMPolicy(from, text) {
100
+ if (this.config.dmPolicy === "none") return false;
101
+ if (this.config.dmPolicy === "open") return true;
102
+ if (this.config.dmPolicy === "allowlist") {
103
+ if (this.config.allowFrom.includes(from)) return true;
104
+ await this.sendMessage(from, "🦅 HyperClaw: Not on allowlist.").catch(() => {});
105
+ return false;
106
+ }
107
+ if (this.config.dmPolicy === "pairing") {
108
+ if (this.config.approvedPairings.includes(from)) return true;
109
+ const upper = text.trim().toUpperCase();
110
+ if (this.config.pendingPairings[upper]) {
111
+ this.config.approvedPairings.push(from);
112
+ delete this.config.pendingPairings[upper];
113
+ await this.saveState();
114
+ await this.sendMessage(from, "🦅 Paired!").catch(() => {});
115
+ this.emit("pairing:approved", {
116
+ userId: from,
117
+ channelId: "whatsapp-baileys"
118
+ });
119
+ return true;
120
+ }
121
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
122
+ this.config.pendingPairings[code] = from;
123
+ await this.saveState();
124
+ await this.sendMessage(from, `🦅 Code: ${code}\nApprove: hyperclaw pairing approve whatsapp-baileys ${code}`).catch(() => {});
125
+ return false;
126
+ }
127
+ return false;
128
+ }
129
+ async sendMessage(to, text) {
130
+ if (!this.sock) return;
131
+ const jid = to.includes("@") ? to : `${to}@s.whatsapp.net`;
132
+ await this.sock.sendMessage(jid, { text: text.slice(0, 4096) });
133
+ }
134
+ disconnect() {
135
+ this.running = false;
136
+ this.sock?.end?.();
137
+ this.sock = null;
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.WhatsAppBaileysConnector = WhatsAppBaileysConnector;
@@ -0,0 +1,172 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const chalk = require_chunk.__toESM(require("chalk"));
3
+ const fs_extra = require_chunk.__toESM(require("fs-extra"));
4
+ const path = require_chunk.__toESM(require("path"));
5
+ const os = require_chunk.__toESM(require("os"));
6
+ const http = require_chunk.__toESM(require("http"));
7
+ const https = require_chunk.__toESM(require("https"));
8
+ const events = require_chunk.__toESM(require("events"));
9
+
10
+ //#region extensions/synology-chat/src/connector.ts
11
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "synology-chat-state.json");
12
+ function httpsPost(url, body) {
13
+ return new Promise((resolve, reject) => {
14
+ const encoded = Object.entries(body).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join("&");
15
+ const u = new URL(url);
16
+ const isHttps = u.protocol === "https:";
17
+ const mod = isHttps ? https.default : http.default;
18
+ const req = mod.request({
19
+ hostname: u.hostname,
20
+ port: u.port || (isHttps ? 443 : 80),
21
+ path: u.pathname + u.search,
22
+ method: "POST",
23
+ headers: {
24
+ "Content-Type": "application/x-www-form-urlencoded",
25
+ "Content-Length": Buffer.byteLength(encoded)
26
+ }
27
+ }, (res) => {
28
+ let data = "";
29
+ res.on("data", (c) => data += c);
30
+ res.on("end", () => resolve(data));
31
+ });
32
+ req.on("error", reject);
33
+ req.write(encoded);
34
+ req.end();
35
+ });
36
+ }
37
+ var SynologyChatConnector = class extends events.EventEmitter {
38
+ config;
39
+ server = null;
40
+ running = false;
41
+ constructor(config) {
42
+ super();
43
+ this.config = {
44
+ webhookPort: 7789,
45
+ webhookPath: "/synology-hook",
46
+ dmPolicy: "pairing",
47
+ allowFrom: [],
48
+ approvedPairings: [],
49
+ pendingPairings: {},
50
+ ...config
51
+ };
52
+ }
53
+ async connect() {
54
+ await this.loadState();
55
+ await this.startWebhookServer();
56
+ this.running = true;
57
+ console.log(chalk.default.green(` 🦅 Synology Chat: webhook listening on :${this.config.webhookPort}${this.config.webhookPath}`));
58
+ this.emit("connected", { webhookPort: this.config.webhookPort });
59
+ }
60
+ disconnect() {
61
+ this.running = false;
62
+ this.server?.close();
63
+ this.server = null;
64
+ }
65
+ startWebhookServer() {
66
+ return new Promise((resolve, reject) => {
67
+ this.server = http.default.createServer(async (req, res) => {
68
+ if (req.method !== "POST" || req.url !== this.config.webhookPath) {
69
+ res.writeHead(404).end();
70
+ return;
71
+ }
72
+ let body = "";
73
+ req.on("data", (c) => body += c);
74
+ req.on("end", async () => {
75
+ try {
76
+ const params = new URLSearchParams(body);
77
+ const token = params.get("token");
78
+ const text = params.get("text") || "";
79
+ const userId = params.get("user_id") || "unknown";
80
+ const username = params.get("username") || userId;
81
+ const channelId = params.get("channel_id") || "unknown";
82
+ const channelName = params.get("channel_name") || channelId;
83
+ if (this.config.webhookToken && token !== this.config.webhookToken) {
84
+ res.writeHead(403).end("Forbidden");
85
+ return;
86
+ }
87
+ res.writeHead(200, { "Content-Type": "application/json" }).end("{}");
88
+ if (!text || !userId) return;
89
+ const allowed = await this.checkPolicy(userId, username, channelId, text);
90
+ if (!allowed) return;
91
+ this.emit("message", {
92
+ id: `syno-${Date.now()}-${Math.random().toString(36).slice(2)}`,
93
+ channelId: "synology-chat",
94
+ from: username,
95
+ chatId: channelId,
96
+ chatName: channelName,
97
+ text,
98
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
99
+ isDM: false
100
+ });
101
+ } catch (e) {
102
+ console.log(chalk.default.yellow(` ⚠ Synology Chat: ${e.message}`));
103
+ res.writeHead(500).end();
104
+ }
105
+ });
106
+ });
107
+ this.server.listen(this.config.webhookPort, () => resolve());
108
+ this.server.on("error", reject);
109
+ });
110
+ }
111
+ async checkPolicy(userId, username, channelId, text) {
112
+ if (this.config.dmPolicy === "none") return false;
113
+ if (this.config.dmPolicy === "open") return true;
114
+ if (this.config.dmPolicy === "allowlist") {
115
+ if (this.config.allowFrom.includes(userId) || this.config.allowFrom.includes(username)) return true;
116
+ await this.sendMessage(channelId, "🦅 You are not on the allowlist.");
117
+ return false;
118
+ }
119
+ if (this.config.dmPolicy === "pairing") {
120
+ if (this.config.approvedPairings.includes(userId)) return true;
121
+ const upper = text.trim().toUpperCase();
122
+ if (this.config.pendingPairings[upper]) {
123
+ this.config.approvedPairings.push(userId);
124
+ delete this.config.pendingPairings[upper];
125
+ await this.saveState();
126
+ await this.sendMessage(channelId, "🦅 Paired! You can now send messages to the assistant.");
127
+ return true;
128
+ }
129
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
130
+ this.config.pendingPairings[code] = userId;
131
+ await this.saveState();
132
+ await this.sendMessage(channelId, `🦅 Pairing required. Your code: \`${code}\`\nApprove: hyperclaw pairing approve synology-chat ${code}`);
133
+ return false;
134
+ }
135
+ return false;
136
+ }
137
+ async sendMessage(channelId, text) {
138
+ try {
139
+ await httpsPost(this.config.incomingWebhookUrl, { text });
140
+ } catch (e) {
141
+ console.log(chalk.default.yellow(` ⚠ Synology Chat send error: ${e.message}`));
142
+ }
143
+ }
144
+ approvePairing(code) {
145
+ const upper = code.toUpperCase();
146
+ if (!this.config.pendingPairings[upper]) return false;
147
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
148
+ delete this.config.pendingPairings[upper];
149
+ this.saveState();
150
+ return true;
151
+ }
152
+ async loadState() {
153
+ try {
154
+ const s = await fs_extra.default.readJson(STATE_FILE);
155
+ if (s.p) this.config.pendingPairings = s.p;
156
+ if (s.a) this.config.approvedPairings = s.a;
157
+ } catch {}
158
+ }
159
+ async saveState() {
160
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
161
+ await fs_extra.default.writeJson(STATE_FILE, {
162
+ p: this.config.pendingPairings,
163
+ a: this.config.approvedPairings
164
+ }, { spaces: 2 });
165
+ }
166
+ isRunning() {
167
+ return this.running;
168
+ }
169
+ };
170
+
171
+ //#endregion
172
+ exports.SynologyChatConnector = SynologyChatConnector;