hyperclaw 5.0.0 → 5.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 (199) hide show
  1. package/LICENSE +2 -1
  2. package/README.md +449 -99
  3. package/dist/a2ui-protocol-Gzm29Gaw.js +75 -0
  4. package/dist/agents-routing-Biy5ew4a.js +4 -0
  5. package/dist/agents-routing-CL3HQNoM.js +327 -0
  6. package/dist/api-keys-guide-CGn5BSF7.js +149 -0
  7. package/dist/api-keys-guide-ChbThbPj.js +149 -0
  8. package/dist/audit-BJohI_vC.js +441 -0
  9. package/dist/audit-NPIMmOSq.js +441 -0
  10. package/dist/bounty-tools-BUqUKjt0.js +211 -0
  11. package/dist/bounty-tools-CY_i91DU.js +211 -0
  12. package/dist/browser-tools-CxJY6pAn.js +5 -0
  13. package/dist/browser-tools-JZ9ji6AW.js +179 -0
  14. package/dist/chat-qVuqhlPu.js +258 -0
  15. package/dist/claw-tasks-B-8RRMdq.js +80 -0
  16. package/dist/claw-tasks-Cyzdbhz_.js +80 -0
  17. package/dist/connector-1x1rCBHz.js +162 -0
  18. package/dist/connector-B4jeCULG.js +305 -0
  19. package/dist/connector-B7qngfkT.js +286 -0
  20. package/dist/connector-B8BK0GBo.js +531 -0
  21. package/dist/connector-BE9eJs8-.js +182 -0
  22. package/dist/connector-BEe-DTGQ.js +189 -0
  23. package/dist/connector-BU7p5ZgB.js +167 -0
  24. package/dist/connector-BUzzq7Ij.js +568 -0
  25. package/dist/connector-BpDqLgnW.js +419 -0
  26. package/dist/connector-BpW88ut2.js +189 -0
  27. package/dist/connector-Bxv-gy8U.js +167 -0
  28. package/dist/connector-Bz14zcJv.js +213 -0
  29. package/dist/connector-C1zP5-5q.js +85 -0
  30. package/dist/connector-CAcpcovF.js +498 -0
  31. package/dist/connector-CJgVjS58.js +181 -0
  32. package/dist/connector-Cf53D6qV.js +425 -0
  33. package/dist/connector-CyHmlbNz.js +508 -0
  34. package/dist/connector-D22mJGVu.js +340 -0
  35. package/dist/connector-D6RtMmlL.js +225 -0
  36. package/dist/connector-D9EnT8A4.js +280 -0
  37. package/dist/connector-DNDwIh37.js +239 -0
  38. package/dist/connector-Di27MeO4.js +350 -0
  39. package/dist/connector-Do0BPiHt.js +194 -0
  40. package/dist/connector-DvLwOfJy.js +192 -0
  41. package/dist/connector-DvU83NSq.js +181 -0
  42. package/dist/connector-DxskpDc_.js +173 -0
  43. package/dist/connector-byy3eISx.js +552 -0
  44. package/dist/connector-vV89hsyd.js +218 -0
  45. package/dist/cost-tracker-Ca1UPZ33.js +103 -0
  46. package/dist/cost-tracker-fnaj_6M9.js +103 -0
  47. package/dist/credentials-store-BxijEirw.js +77 -0
  48. package/dist/credentials-store-CA8UtK0T.js +77 -0
  49. package/dist/credentials-store-CPkVO6-z.js +4 -0
  50. package/dist/credentials-store-Cm7DH-kh.js +4 -0
  51. package/dist/cron-tasks-L0mz1yyU.js +82 -0
  52. package/dist/cron-tasks-_pqQCmxc.js +82 -0
  53. package/dist/daemon-7ViroziB.js +5 -0
  54. package/dist/daemon-BfyKmZhr.js +318 -0
  55. package/dist/daemon-CNyunwkR.js +5 -0
  56. package/dist/daemon-CindY8OK.js +318 -0
  57. package/dist/delivery-DVHmv1IR.js +4 -0
  58. package/dist/delivery-DgiZcJBp.js +4 -0
  59. package/dist/delivery-DpMX0Yyc.js +95 -0
  60. package/dist/delivery-otAU4alM.js +95 -0
  61. package/dist/destructive-gate-CA0DtA5K.js +101 -0
  62. package/dist/destructive-gate-DZt71UZR.js +101 -0
  63. package/dist/developer-keys-Cnd1kswV.js +127 -0
  64. package/dist/developer-keys-DENo3ZA6.js +8 -0
  65. package/dist/doctor-Dgjoc3DG.js +230 -0
  66. package/dist/doctor-RwsOhtAl.js +6 -0
  67. package/dist/engine-B0kLfRL0.js +256 -0
  68. package/dist/engine-BJUpRUOv.js +7 -0
  69. package/dist/engine-D_VeoZHw.js +305 -0
  70. package/dist/engine-JjRnhlsE.js +7 -0
  71. package/dist/env-resolve-17ekEU6p.js +10 -0
  72. package/dist/env-resolve-BFJXWl94.js +115 -0
  73. package/dist/env-resolve-Z2XF6leB.js +115 -0
  74. package/dist/env-resolve-bDYssfih.js +10 -0
  75. package/dist/extraction-tools-DbxnxIco.js +5 -0
  76. package/dist/extraction-tools-Dg7AHS35.js +91 -0
  77. package/dist/form_data-CGAy4HE0.js +8657 -0
  78. package/dist/gmail-watch-setup-C3uSWznp.js +40 -0
  79. package/dist/health-DUjluWHQ.js +6 -0
  80. package/dist/health-DVfkpUQW.js +152 -0
  81. package/dist/heartbeat-engine-CrgL4mrP.js +83 -0
  82. package/dist/heartbeat-engine-Ut6pXBD6.js +83 -0
  83. package/dist/hub-9LaKnLjY.js +6 -0
  84. package/dist/hub-BO6bj8Yj.js +515 -0
  85. package/dist/hub-Bu52YZqW.js +6 -0
  86. package/dist/hub-CfwUz9YW.js +515 -0
  87. package/dist/hyperclawbot-BrcoYLOp.js +505 -0
  88. package/dist/hyperclawbot-CBiDSKsa.js +505 -0
  89. package/dist/inference-0mlFQqIm.js +922 -0
  90. package/dist/inference-DHR82Gh7.js +6 -0
  91. package/dist/inference-DhA8jpfH.js +2692 -0
  92. package/dist/inference-SzqFe_nk.js +6 -0
  93. package/dist/knowledge-graph-BrYpSgxW.js +131 -0
  94. package/dist/knowledge-graph-DE5lSF02.js +131 -0
  95. package/dist/loader-9JqY6Nlq.js +4 -0
  96. package/dist/loader-BkDi8MD9.js +400 -0
  97. package/dist/loader-Cjdd1kw4.js +400 -0
  98. package/dist/loader-DI2qDRPC.js +4 -0
  99. package/dist/logger-Cp8wC7F8.js +83 -0
  100. package/dist/logger-DCT2l9GV.js +83 -0
  101. package/dist/manager-3cq3DydI.js +4 -0
  102. package/dist/manager-B2Gls5RG.js +218 -0
  103. package/dist/manager-BUrFrPuq.js +117 -0
  104. package/dist/manager-Bi9UYyVR.js +105 -0
  105. package/dist/manager-Biz9ixWJ.js +40 -0
  106. package/dist/manager-CBUHJiY7.js +6 -0
  107. package/dist/manager-CVLLaKmq.js +218 -0
  108. package/dist/manager-CWNSML5D.js +117 -0
  109. package/dist/manager-SJe9gt-q.js +4 -0
  110. package/dist/mcp-CUoTCMw-.js +139 -0
  111. package/dist/mcp-loader-BIz-450x.js +94 -0
  112. package/dist/mcp-loader-CvxRDtPC.js +94 -0
  113. package/dist/memory-OL77OMOr.js +270 -0
  114. package/dist/memory-auto-CpQHZlEJ.js +306 -0
  115. package/dist/memory-auto-D-L2q21G.js +306 -0
  116. package/dist/memory-auto-DTcy5VBy.js +5 -0
  117. package/dist/memory-auto-Z6LCf-iK.js +5 -0
  118. package/dist/memory-gUi4VaIf.js +4 -0
  119. package/dist/memory-integration-B8RSN4pr.js +91 -0
  120. package/dist/memory-integration-g2vxwgoE.js +91 -0
  121. package/dist/moltbook-B-40gQOL.js +81 -0
  122. package/dist/moltbook-Cl8cQfxJ.js +81 -0
  123. package/dist/node-TWxRm84k.js +222 -0
  124. package/dist/nodes-registry-C9dCFwjh.js +52 -0
  125. package/dist/nodes-registry-DKRtsbNg.js +52 -0
  126. package/dist/oauth-flow-CeaaGAz0.js +150 -0
  127. package/dist/oauth-flow-JCfporKq.js +150 -0
  128. package/dist/oauth-provider-4R0EJlsT.js +110 -0
  129. package/dist/oauth-provider-B4dzn56l.js +110 -0
  130. package/dist/observability-CDZmeHfa.js +89 -0
  131. package/dist/observability-nZ3CBIxG.js +89 -0
  132. package/dist/onboard-BBBWcfhp.js +10 -0
  133. package/dist/onboard-BVOtKQdh.js +3641 -0
  134. package/dist/onboard-Bw28IRQ3.js +4070 -0
  135. package/dist/onboard-CGNIw27w.js +11 -0
  136. package/dist/orchestrator-BovkM63z.js +6 -0
  137. package/dist/orchestrator-CcKx1Ovk.js +189 -0
  138. package/dist/orchestrator-DSbpkP1X.js +189 -0
  139. package/dist/orchestrator-DcFfDLTX.js +6 -0
  140. package/dist/osint-B4_m3VHQ.js +277 -0
  141. package/dist/osint-B6BZKQAD.js +277 -0
  142. package/dist/pairing-B6RArWhD.js +196 -0
  143. package/dist/pairing-BsQ08DLq.js +4 -0
  144. package/dist/pc-access-B0KocJNe.js +819 -0
  145. package/dist/pc-access-DkzmugZ7.js +8 -0
  146. package/dist/pending-approval-BgNjjuI2.js +22 -0
  147. package/dist/pending-approval-C_HkX1QL.js +22 -0
  148. package/dist/providers-DxiamZSL.js +5 -0
  149. package/dist/providers-Dy15rDb7.js +657 -0
  150. package/dist/reminders-store-CzUY0zYx.js +58 -0
  151. package/dist/renderer-ANNfXsHn.js +225 -0
  152. package/dist/rules-BSQwwAYC.js +103 -0
  153. package/dist/run-main.js +142 -132
  154. package/dist/runner-BHRSOPEU.js +1271 -0
  155. package/dist/runner-CJFJUtPm.js +1271 -0
  156. package/dist/sdk/index.js +2 -2
  157. package/dist/sdk/index.mjs +2 -2
  158. package/dist/security--oQObeJO.js +4 -0
  159. package/dist/security-wBOg0TA8.js +73 -0
  160. package/dist/server-Brl_HQUB.js +1255 -0
  161. package/dist/server-CbTTpB5m.js +1255 -0
  162. package/dist/server-DP_bPzvI.js +4 -0
  163. package/dist/server-DhfipkwN.js +4 -0
  164. package/dist/session-store-B09r5HgB.js +5 -0
  165. package/dist/session-store-DCTQIVur.js +113 -0
  166. package/dist/sessions-tools-BdlN6Pb6.js +95 -0
  167. package/dist/sessions-tools-JVLDKSJ_.js +5 -0
  168. package/dist/skill-loader-B5oeliGu.js +7 -0
  169. package/dist/skill-loader-Wf3brNOj.js +160 -0
  170. package/dist/skill-runtime-BGlvly2s.js +102 -0
  171. package/dist/skill-runtime-BXWd-Ktf.js +102 -0
  172. package/dist/skill-runtime-DhL2T76p.js +5 -0
  173. package/dist/skill-runtime-jgklm02e.js +5 -0
  174. package/dist/src-BbPa6Q8p.js +63 -0
  175. package/dist/src-BeXtfkK2.js +458 -0
  176. package/dist/src-Bhybpk1J.js +63 -0
  177. package/dist/src-CGQjRI4N.js +20 -0
  178. package/dist/src-DMJ4-uqk.js +458 -0
  179. package/dist/sub-agent-tools-CmE345s_.js +39 -0
  180. package/dist/sub-agent-tools-DHY-4WWM.js +39 -0
  181. package/dist/theme-D0smfC_l.js +8 -0
  182. package/dist/theme-DajRRZbA.js +180 -0
  183. package/dist/tool-policy-DZvF8xlQ.js +189 -0
  184. package/dist/tool-policy-DgNqFWYn.js +189 -0
  185. package/dist/tts-elevenlabs-C06nUxMK.js +61 -0
  186. package/dist/tts-elevenlabs-JeFaGNJU.js +61 -0
  187. package/dist/update-check-BVEqHhFY.js +83 -0
  188. package/dist/update-check-w4XuxVl7.js +81 -0
  189. package/dist/vision-JOtOS1Br.js +121 -0
  190. package/dist/vision-fky3elEo.js +121 -0
  191. package/dist/vision-tools-C8B3776g.js +5 -0
  192. package/dist/vision-tools-CB28ZCO_.js +5 -0
  193. package/dist/vision-tools-dwn9p4el.js +51 -0
  194. package/dist/vision-tools-vPPwQ-0N.js +51 -0
  195. package/dist/voice-transcription-B6RtplmN.js +138 -0
  196. package/dist/voice-transcription-DBo5hXmu.js +138 -0
  197. package/dist/website-watch-tools-B-jRAeTe.js +139 -0
  198. package/dist/website-watch-tools-BC9xAL67.js +5 -0
  199. package/package.json +1 -1
@@ -0,0 +1,80 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const https = require_chunk.__toESM(require("https"));
3
+
4
+ //#region src/services/claw-tasks.ts
5
+ /** List open bounties. */
6
+ async function listBounties(limit = 20, status = "open") {
7
+ if (!CLAW_TASKS_API) return [];
8
+ try {
9
+ const q = new URLSearchParams({ limit: String(limit) });
10
+ if (status === "open") q.set("status", "open");
11
+ const body = await fetchJson(`${CLAW_TASKS_API}/api/bounties?${q}`);
12
+ return Array.isArray(body.bounties) ? body.bounties : [];
13
+ } catch {
14
+ return [];
15
+ }
16
+ }
17
+ /** Claim a bounty (requires agent auth). */
18
+ async function claimBounty(bountyId, agentToken) {
19
+ if (!CLAW_TASKS_API) return null;
20
+ try {
21
+ const body = await postJson(`${CLAW_TASKS_API}/api/bounties/${encodeURIComponent(bountyId)}/claim`, {}, agentToken);
22
+ return body.bounty || null;
23
+ } catch {
24
+ return null;
25
+ }
26
+ }
27
+ function fetchJson(url) {
28
+ return new Promise((resolve, reject) => {
29
+ https.default.get(url, (res) => {
30
+ let data = "";
31
+ res.on("data", (c) => data += c);
32
+ res.on("end", () => {
33
+ try {
34
+ resolve(JSON.parse(data));
35
+ } catch {
36
+ reject(new Error("Invalid JSON"));
37
+ }
38
+ });
39
+ }).on("error", reject);
40
+ });
41
+ }
42
+ function postJson(url, payload, token) {
43
+ return new Promise((resolve, reject) => {
44
+ const u = new URL(url);
45
+ const body = JSON.stringify(payload);
46
+ const req = https.default.request({
47
+ hostname: u.hostname,
48
+ port: 443,
49
+ path: u.pathname,
50
+ method: "POST",
51
+ headers: {
52
+ "Content-Type": "application/json",
53
+ "Content-Length": Buffer.byteLength(body),
54
+ ...token ? { Authorization: `Bearer ${token}` } : {}
55
+ }
56
+ }, (res) => {
57
+ let data = "";
58
+ res.on("data", (c) => data += c);
59
+ res.on("end", () => {
60
+ try {
61
+ resolve(JSON.parse(data || "{}"));
62
+ } catch {
63
+ resolve({});
64
+ }
65
+ });
66
+ });
67
+ req.on("error", reject);
68
+ req.write(body);
69
+ req.end();
70
+ });
71
+ }
72
+ var CLAW_TASKS_API;
73
+ var init_claw_tasks = require_chunk.__esm({ "src/services/claw-tasks.ts"() {
74
+ CLAW_TASKS_API = process.env.CLAW_TASKS_API_URL || "";
75
+ } });
76
+
77
+ //#endregion
78
+ init_claw_tasks();
79
+ exports.claimBounty = claimBounty;
80
+ exports.listBounties = listBounties;
@@ -0,0 +1,80 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const https = require_chunk.__toESM(require("https"));
3
+
4
+ //#region src/services/claw-tasks.ts
5
+ /** List open bounties. */
6
+ async function listBounties(limit = 20, status = "open") {
7
+ if (!CLAW_TASKS_API) return [];
8
+ try {
9
+ const q = new URLSearchParams({ limit: String(limit) });
10
+ if (status === "open") q.set("status", "open");
11
+ const body = await fetchJson(`${CLAW_TASKS_API}/api/bounties?${q}`);
12
+ return Array.isArray(body.bounties) ? body.bounties : [];
13
+ } catch {
14
+ return [];
15
+ }
16
+ }
17
+ /** Claim a bounty (requires agent auth). */
18
+ async function claimBounty(bountyId, agentToken) {
19
+ if (!CLAW_TASKS_API) return null;
20
+ try {
21
+ const body = await postJson(`${CLAW_TASKS_API}/api/bounties/${encodeURIComponent(bountyId)}/claim`, {}, agentToken);
22
+ return body.bounty || null;
23
+ } catch {
24
+ return null;
25
+ }
26
+ }
27
+ function fetchJson(url) {
28
+ return new Promise((resolve, reject) => {
29
+ https.default.get(url, (res) => {
30
+ let data = "";
31
+ res.on("data", (c) => data += c);
32
+ res.on("end", () => {
33
+ try {
34
+ resolve(JSON.parse(data));
35
+ } catch {
36
+ reject(new Error("Invalid JSON"));
37
+ }
38
+ });
39
+ }).on("error", reject);
40
+ });
41
+ }
42
+ function postJson(url, payload, token) {
43
+ return new Promise((resolve, reject) => {
44
+ const u = new URL(url);
45
+ const body = JSON.stringify(payload);
46
+ const req = https.default.request({
47
+ hostname: u.hostname,
48
+ port: 443,
49
+ path: u.pathname,
50
+ method: "POST",
51
+ headers: {
52
+ "Content-Type": "application/json",
53
+ "Content-Length": Buffer.byteLength(body),
54
+ ...token ? { Authorization: `Bearer ${token}` } : {}
55
+ }
56
+ }, (res) => {
57
+ let data = "";
58
+ res.on("data", (c) => data += c);
59
+ res.on("end", () => {
60
+ try {
61
+ resolve(JSON.parse(data || "{}"));
62
+ } catch {
63
+ resolve({});
64
+ }
65
+ });
66
+ });
67
+ req.on("error", reject);
68
+ req.write(body);
69
+ req.end();
70
+ });
71
+ }
72
+ var CLAW_TASKS_API;
73
+ var init_claw_tasks = require_chunk.__esm({ "src/services/claw-tasks.ts"() {
74
+ CLAW_TASKS_API = process.env.CLAW_TASKS_API_URL || "";
75
+ } });
76
+
77
+ //#endregion
78
+ init_claw_tasks();
79
+ exports.claimBounty = claimBounty;
80
+ exports.listBounties = listBounties;
@@ -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,305 @@
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
+ function resolveAllowedIds(raw, envVal) {
12
+ if (Array.isArray(raw) && raw.length) return raw;
13
+ if (typeof raw === "string" && raw.trim()) return raw.split(",").map((s) => s.trim()).filter(Boolean);
14
+ if (envVal) return envVal.split(",").map((s) => s.trim()).filter(Boolean);
15
+ return [];
16
+ }
17
+ function resolveAccount(id, raw, state) {
18
+ const token = raw.token || process.env["SYNOLOGY_CHAT_TOKEN"] || "";
19
+ const incomingUrl = raw.incomingUrl || process.env["SYNOLOGY_CHAT_INCOMING_URL"] || "";
20
+ const allowedUserIds = resolveAllowedIds(raw.allowedUserIds, process.env["SYNOLOGY_ALLOWED_USER_IDS"]);
21
+ const rateLimitPerMinute = raw.rateLimitPerMinute ?? (process.env["SYNOLOGY_RATE_LIMIT"] ? parseInt(process.env["SYNOLOGY_RATE_LIMIT"], 10) : 30);
22
+ return {
23
+ id,
24
+ name: raw.name ?? process.env["OPENCLAW_BOT_NAME"] ?? id,
25
+ token,
26
+ incomingUrl,
27
+ webhookPath: raw.webhookPath ?? "/webhook/synology",
28
+ dmPolicy: raw.dmPolicy ?? "allowlist",
29
+ allowedUserIds,
30
+ rateLimitPerMinute,
31
+ allowInsecureSsl: raw.allowInsecureSsl ?? false,
32
+ approvedPairings: state.approved,
33
+ pendingPairings: state.pending
34
+ };
35
+ }
36
+ var RateLimiter = class {
37
+ windows = /* @__PURE__ */ new Map();
38
+ constructor(limitPerMinute) {
39
+ this.limitPerMinute = limitPerMinute;
40
+ }
41
+ allow(senderId) {
42
+ if (this.limitPerMinute <= 0) return true;
43
+ const now = Date.now();
44
+ const cutoff = now - 6e4;
45
+ const timestamps = (this.windows.get(senderId) ?? []).filter((t) => t > cutoff);
46
+ if (timestamps.length >= this.limitPerMinute) return false;
47
+ timestamps.push(now);
48
+ this.windows.set(senderId, timestamps);
49
+ return true;
50
+ }
51
+ };
52
+ function postToSynology(incomingUrl, text, userId, allowInsecureSsl = false) {
53
+ return new Promise((resolve, reject) => {
54
+ const u = new URL(incomingUrl);
55
+ const isHttps = u.protocol === "https:";
56
+ const mod = isHttps ? https.default : http.default;
57
+ const payloadObj = { text };
58
+ if (userId) payloadObj.user_ids = [parseInt(userId, 10)].filter((n) => !isNaN(n));
59
+ const encoded = `payload=${encodeURIComponent(JSON.stringify(payloadObj))}`;
60
+ const options = {
61
+ hostname: u.hostname,
62
+ port: u.port || (isHttps ? 443 : 80),
63
+ path: u.pathname + u.search,
64
+ method: "POST",
65
+ headers: {
66
+ "Content-Type": "application/x-www-form-urlencoded",
67
+ "Content-Length": Buffer.byteLength(encoded)
68
+ }
69
+ };
70
+ if (isHttps && allowInsecureSsl) options.rejectUnauthorized = false;
71
+ const req = (isHttps ? https.default : http.default).request(options, (res) => {
72
+ res.resume();
73
+ res.on("end", resolve);
74
+ });
75
+ req.on("error", reject);
76
+ req.write(encoded);
77
+ req.end();
78
+ });
79
+ }
80
+ const STATE_DIR = path.default.join(os.default.homedir(), ".hyperclaw");
81
+ var SingleAccountConnector = class extends events.EventEmitter {
82
+ acc;
83
+ rateLimiter;
84
+ constructor(acc) {
85
+ super();
86
+ this.acc = acc;
87
+ this.rateLimiter = new RateLimiter(acc.rateLimitPerMinute);
88
+ }
89
+ validate() {
90
+ const { dmPolicy, allowedUserIds, token, incomingUrl } = this.acc;
91
+ if (!token) throw new Error(`Synology Chat[${this.acc.id}]: 'token' is required (set SYNOLOGY_CHAT_TOKEN or config)`);
92
+ if (!incomingUrl) throw new Error(`Synology Chat[${this.acc.id}]: 'incomingUrl' is required`);
93
+ if (dmPolicy === "allowlist" && allowedUserIds.length === 0) throw new Error(`Synology Chat[${this.acc.id}]: dmPolicy="allowlist" requires at least one allowedUserId. Use dmPolicy="open" to allow all senders.`);
94
+ }
95
+ async handleWebhook(body) {
96
+ let params;
97
+ try {
98
+ params = new URLSearchParams(body);
99
+ } catch {
100
+ return {
101
+ status: 400,
102
+ body: "Bad Request"
103
+ };
104
+ }
105
+ const inboundToken = params.get("token");
106
+ if (inboundToken !== this.acc.token) {
107
+ console.log(chalk.default.yellow(` ⚠ Synology Chat[${this.acc.id}]: invalid token`));
108
+ return {
109
+ status: 403,
110
+ body: "Forbidden"
111
+ };
112
+ }
113
+ const text = (params.get("text") ?? "").trim();
114
+ const userId = params.get("user_id") ?? "";
115
+ const username = params.get("username") ?? userId;
116
+ const channelId = params.get("channel_id") ?? "";
117
+ const timestamp = params.get("timestamp") ?? String(Date.now());
118
+ if (!text || !userId) return {
119
+ status: 200,
120
+ body: "{}"
121
+ };
122
+ if (!this.rateLimiter.allow(userId)) {
123
+ console.log(chalk.default.gray(` synology-chat[${this.acc.id}]: rate-limited sender ${userId}`));
124
+ return {
125
+ status: 429,
126
+ body: "Too Many Requests"
127
+ };
128
+ }
129
+ const allowed = await this._checkPolicy(userId, channelId, text);
130
+ if (!allowed) return {
131
+ status: 200,
132
+ body: "{}"
133
+ };
134
+ const msg = {
135
+ accountId: this.acc.id,
136
+ id: `syno-${timestamp}-${Math.random().toString(36).slice(2, 7)}`,
137
+ from: username,
138
+ userId,
139
+ chatId: userId,
140
+ text,
141
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
142
+ };
143
+ this.emit("message", msg);
144
+ return {
145
+ status: 200,
146
+ body: "{}"
147
+ };
148
+ }
149
+ async _checkPolicy(userId, channelId, text) {
150
+ const acc = this.acc;
151
+ if (acc.dmPolicy === "disabled") return false;
152
+ if (acc.dmPolicy === "open") return true;
153
+ if (acc.dmPolicy === "allowlist") {
154
+ if (acc.allowedUserIds.includes(userId)) return true;
155
+ console.log(chalk.default.gray(` synology-chat[${acc.id}]: drop sender ${userId} (dmPolicy=allowlist)`));
156
+ return false;
157
+ }
158
+ if (acc.dmPolicy === "pairing") {
159
+ if (acc.approvedPairings.includes(userId)) return true;
160
+ const upper = text.trim().toUpperCase();
161
+ if (acc.pendingPairings[upper] === userId) {
162
+ acc.approvedPairings.push(userId);
163
+ delete acc.pendingPairings[upper];
164
+ await this._saveState();
165
+ await this.sendMessage(userId, "🦅 Paired! You can now send messages to the assistant.");
166
+ this.emit("pairing:approved", {
167
+ accountId: acc.id,
168
+ userId
169
+ });
170
+ return true;
171
+ }
172
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
173
+ acc.pendingPairings[code] = userId;
174
+ await this._saveState();
175
+ await this.sendMessage(userId, `🦅 Pairing required. Your code: \`${code}\`\nApprove: hyperclaw pairing approve synology-chat ${code}`);
176
+ return false;
177
+ }
178
+ return false;
179
+ }
180
+ async sendMessage(userId, text) {
181
+ try {
182
+ await postToSynology(this.acc.incomingUrl, text, userId, this.acc.allowInsecureSsl);
183
+ } catch (e) {
184
+ console.log(chalk.default.yellow(` ⚠ Synology Chat[${this.acc.id}] send error: ${e.message}`));
185
+ }
186
+ }
187
+ /** Resolve outbound target. Accepts: numeric ID, "synology-chat:<id>", "user:<id>" */
188
+ resolveTarget(target) {
189
+ if (target.startsWith("synology-chat:")) return target.slice(14);
190
+ if (target.startsWith("user:")) return target.slice(5);
191
+ return target;
192
+ }
193
+ approvePairing(code) {
194
+ const upper = code.toUpperCase();
195
+ if (!this.acc.pendingPairings[upper]) return false;
196
+ this.acc.approvedPairings.push(this.acc.pendingPairings[upper]);
197
+ delete this.acc.pendingPairings[upper];
198
+ this._saveState();
199
+ return true;
200
+ }
201
+ listPendingPairings() {
202
+ return { ...this.acc.pendingPairings };
203
+ }
204
+ _stateFile() {
205
+ return path.default.join(STATE_DIR, `synology-chat-state-${this.acc.id}.json`);
206
+ }
207
+ async loadState() {
208
+ try {
209
+ const s = await fs_extra.default.readJson(this._stateFile());
210
+ if (Array.isArray(s.approvedPairings)) this.acc.approvedPairings = s.approvedPairings;
211
+ if (s.pendingPairings && typeof s.pendingPairings === "object") this.acc.pendingPairings = s.pendingPairings;
212
+ } catch {}
213
+ }
214
+ async _saveState() {
215
+ await fs_extra.default.ensureDir(STATE_DIR);
216
+ await fs_extra.default.writeJson(this._stateFile(), {
217
+ approvedPairings: this.acc.approvedPairings,
218
+ pendingPairings: this.acc.pendingPairings
219
+ }, { spaces: 2 });
220
+ }
221
+ };
222
+ var SynologyChatConnector = class extends events.EventEmitter {
223
+ accounts = /* @__PURE__ */ new Map();
224
+ /** webhookPath → accountId index for fast routing */
225
+ pathIndex = /* @__PURE__ */ new Map();
226
+ rawConfig;
227
+ constructor(config) {
228
+ super();
229
+ this.rawConfig = config;
230
+ }
231
+ async connect() {
232
+ const cfg = this.rawConfig;
233
+ const accountDefs = cfg.accounts ?? { default: cfg };
234
+ for (const [id, rawAcc] of Object.entries(accountDefs)) {
235
+ const merged = {
236
+ ...cfg,
237
+ ...rawAcc
238
+ };
239
+ const state = {
240
+ approved: cfg.approvedPairings ?? [],
241
+ pending: cfg.pendingPairings ?? {}
242
+ };
243
+ const acc = resolveAccount(id, merged, state);
244
+ const conn = new SingleAccountConnector(acc);
245
+ try {
246
+ conn.validate();
247
+ } catch (e) {
248
+ console.log(chalk.default.red(` ✗ ${e.message} — account skipped`));
249
+ continue;
250
+ }
251
+ await conn.loadState();
252
+ conn.on("message", (msg) => this.emit("message", msg));
253
+ conn.on("pairing:approved", (info) => this.emit("pairing:approved", info));
254
+ this.accounts.set(id, conn);
255
+ this.pathIndex.set(acc.webhookPath, id);
256
+ console.log(chalk.default.green(` 🦅 Synology Chat[${id}]: ready — inbound path ${acc.webhookPath}`));
257
+ }
258
+ this.emit("connected", { accountIds: Array.from(this.accounts.keys()) });
259
+ }
260
+ disconnect() {
261
+ this.accounts.clear();
262
+ this.pathIndex.clear();
263
+ }
264
+ /** Called by the gateway's HTTP server for inbound POST requests. */
265
+ async handleWebhook(requestPath, body) {
266
+ const accountId = this.pathIndex.get(requestPath);
267
+ if (!accountId) return {
268
+ status: 404,
269
+ body: "Not Found"
270
+ };
271
+ return this._acc(accountId).handleWebhook(body);
272
+ }
273
+ /** Returns all registered webhook paths (for gateway route registration). */
274
+ getWebhookPaths() {
275
+ return Array.from(this.pathIndex.keys());
276
+ }
277
+ _acc(accountId = "default") {
278
+ const conn = this.accounts.get(accountId);
279
+ if (!conn) throw new Error(`Synology Chat: account '${accountId}' not found`);
280
+ return conn;
281
+ }
282
+ async sendMessage(userId, text, accountId) {
283
+ const conn = this._acc(accountId);
284
+ const resolved = conn.resolveTarget(userId);
285
+ return conn.sendMessage(resolved, text);
286
+ }
287
+ resolveTarget(target, accountId) {
288
+ return this._acc(accountId).resolveTarget(target);
289
+ }
290
+ approvePairing(code, accountId) {
291
+ return this._acc(accountId).approvePairing(code);
292
+ }
293
+ listPendingPairings(accountId) {
294
+ return this._acc(accountId).listPendingPairings();
295
+ }
296
+ getAccountIds() {
297
+ return Array.from(this.accounts.keys());
298
+ }
299
+ isRunning() {
300
+ return this.accounts.size > 0;
301
+ }
302
+ };
303
+
304
+ //#endregion
305
+ exports.SynologyChatConnector = SynologyChatConnector;