hyperclaw 4.0.1 → 5.0.0

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 (277) hide show
  1. package/README.md +58 -4
  2. package/dist/a2ui-protocol-CT_jDEU9.js +75 -0
  3. package/dist/a2ui-protocol-CfBI44-Q.js +75 -0
  4. package/dist/agents-routing-683Q2JGp.js +129 -0
  5. package/dist/agents-routing-BpZBswBH.js +4 -0
  6. package/dist/agents-routing-ChHiZp36.js +327 -0
  7. package/dist/agents-routing-ChqZ6l2S.js +4 -0
  8. package/dist/api-keys-guide-BCcOl0Q7.js +149 -0
  9. package/dist/api-keys-guide-Dq5Obbp4.js +149 -0
  10. package/dist/audit-BYxPlnTQ.js +248 -0
  11. package/dist/audit-BaIiyWFu.js +441 -0
  12. package/dist/bounty-tools-C6LyzxM-.js +211 -0
  13. package/dist/bounty-tools-DWudyZie.js +211 -0
  14. package/dist/browser-tools-BsTeGMnX.js +5 -0
  15. package/dist/browser-tools-CQBSbIuO.js +5 -0
  16. package/dist/browser-tools-D8_rLe2p.js +179 -0
  17. package/dist/browser-tools-YQmwRLLM.js +179 -0
  18. package/dist/claw-tasks-BRLUvFRD.js +80 -0
  19. package/dist/claw-tasks-CgTsiNE8.js +80 -0
  20. package/dist/connector-3HnyH8fn.js +167 -0
  21. package/dist/connector-5N0-X_xs.js +194 -0
  22. package/dist/connector-6PMZo5Ky.js +189 -0
  23. package/dist/connector-B3v0qcXg.js +425 -0
  24. package/dist/connector-B6eoF3DD.js +181 -0
  25. package/dist/connector-B8R3iBY1.js +280 -0
  26. package/dist/connector-B9tLG8UZ.js +196 -0
  27. package/dist/connector-BAM-08NN.js +189 -0
  28. package/dist/connector-BC8FIVu4.js +181 -0
  29. package/dist/connector-BDmwwaVc.js +213 -0
  30. package/dist/connector-BGjbBy69.js +225 -0
  31. package/dist/connector-BO2SRzfG.js +218 -0
  32. package/dist/connector-BOlqjXWP.js +182 -0
  33. package/dist/connector-BP8zsbP8.js +189 -0
  34. package/dist/connector-BPoSevxp.js +286 -0
  35. package/dist/connector-BRHj773i.js +163 -0
  36. package/dist/connector-BToxU-jV.js +267 -0
  37. package/dist/connector-BfXky0L3.js +167 -0
  38. package/dist/connector-BiiSJpx3.js +192 -0
  39. package/dist/connector-BliDVsJQ.js +239 -0
  40. package/dist/connector-BnDmIhIu.js +85 -0
  41. package/dist/connector-Bv6s9oP7.js +88 -0
  42. package/dist/connector-By5wWGTR.js +343 -0
  43. package/dist/connector-C1BaFFgN.js +213 -0
  44. package/dist/connector-C1HSoUyk.js +189 -0
  45. package/dist/connector-CKQHZOXg.js +568 -0
  46. package/dist/connector-CRRWY5Wv.js +167 -0
  47. package/dist/connector-CRl-iidy.js +239 -0
  48. package/dist/connector-CXPQVGyI.js +85 -0
  49. package/dist/connector-Cdk1CXKi.js +194 -0
  50. package/dist/connector-Ci9glMD-.js +340 -0
  51. package/dist/connector-CjtZIEDj.js +181 -0
  52. package/dist/connector-Ck6JtOsX.js +531 -0
  53. package/dist/connector-CwlgFgjx.js +181 -0
  54. package/dist/connector-D8Kelee0.js +286 -0
  55. package/dist/connector-DAnRJ0oP.js +162 -0
  56. package/dist/connector-DFchk6l7.js +178 -0
  57. package/dist/connector-DKw7tRAy.js +192 -0
  58. package/dist/connector-DRv1ahC_.js +2 -2
  59. package/dist/connector-DU63KW94.js +165 -0
  60. package/dist/connector-DXTp5PE8.js +508 -0
  61. package/dist/connector-Dbvb1Cj9.js +280 -0
  62. package/dist/connector-DcZdQcgR.js +173 -0
  63. package/dist/connector-Dih6dUPP.js +173 -0
  64. package/dist/connector-DqTH_tPX.js +182 -0
  65. package/dist/connector-DrnEiiyP.js +419 -0
  66. package/dist/connector-DtR5GGTX.js +167 -0
  67. package/dist/connector-DxKL8VvZ.js +182 -0
  68. package/dist/connector-T_YdZtzv.js +162 -0
  69. package/dist/connector-Tky_qS_K.js +350 -0
  70. package/dist/connector-ZSc3oTTy.js +305 -0
  71. package/dist/connector-i4gOS9xL.js +154 -0
  72. package/dist/connector-rHXE1ZD2.js +167 -0
  73. package/dist/connector-sW5yhU1m.js +498 -0
  74. package/dist/connector-u3ICd3Ic.js +552 -0
  75. package/dist/connector-wdUXChwa.js +172 -0
  76. package/dist/cost-tracker-DD9wtWsr.js +103 -0
  77. package/dist/cost-tracker-pVE15Yq4.js +103 -0
  78. package/dist/credentials-store-BvnMPJwi.js +4 -0
  79. package/dist/credentials-store-C6ir0Dae.js +4 -0
  80. package/dist/credentials-store-H13LqOwJ.js +77 -0
  81. package/dist/credentials-store-sb-TRLwR.js +77 -0
  82. package/dist/cron-tasks-Bli7Kzd2.js +82 -0
  83. package/dist/cron-tasks-BvDFNyiE.js +82 -0
  84. package/dist/daemon-Bg4GtCmc.js +318 -0
  85. package/dist/daemon-DhmwY8k4.js +5 -0
  86. package/dist/delivery-BmIYy9VQ.js +4 -0
  87. package/dist/delivery-D5Z98EVq.js +95 -0
  88. package/dist/delivery-DCOXhXEO.js +5 -0
  89. package/dist/delivery-pWUPBp1F.js +95 -0
  90. package/dist/destructive-gate-D6vWOdEl.js +101 -0
  91. package/dist/destructive-gate-m-dWqUFg.js +101 -0
  92. package/dist/developer-keys-CPWT7Q6S.js +8 -0
  93. package/dist/developer-keys-DrrcUqFa.js +127 -0
  94. package/dist/developer-keys-JaJK3T27.js +127 -0
  95. package/dist/developer-keys-kyqmtWK3.js +8 -0
  96. package/dist/doctor-3oi89QIc.js +175 -0
  97. package/dist/doctor-BvCe8BBk.js +230 -0
  98. package/dist/doctor-Cf1XSfp9.js +4 -0
  99. package/dist/doctor-CxyPLYsJ.js +6 -0
  100. package/dist/engine-B4eMiTgl.js +7 -0
  101. package/dist/engine-B8M7dYul.js +7 -0
  102. package/dist/engine-BhT-1M9W.js +256 -0
  103. package/dist/engine-CEDSqXfw.js +256 -0
  104. package/dist/engine-D49jnSd_.js +256 -0
  105. package/dist/engine-Da4JMNpI.js +7 -0
  106. package/dist/env-resolve-CiXbWYwe.js +10 -0
  107. package/dist/env-resolve-CmGWhWXJ.js +115 -0
  108. package/dist/env-resolve-DWOQ45jG.js +9 -0
  109. package/dist/env-resolve-szSWl0UF.js +94 -0
  110. package/dist/extraction-tools-D3qDFBJ1.js +91 -0
  111. package/dist/extraction-tools-DLr_AEwq.js +5 -0
  112. package/dist/extraction-tools-HOZstZ0y.js +91 -0
  113. package/dist/extraction-tools-m4lmAv7l.js +5 -0
  114. package/dist/form_data-B_hIUrxU.js +8657 -0
  115. package/dist/form_data-Cz040rio.js +8657 -0
  116. package/dist/gmail-watch-setup-Czt8rXaX.js +40 -0
  117. package/dist/gmail-watch-setup-Du7DVV7S.js +40 -0
  118. package/dist/health-B-asI__D.js +6 -0
  119. package/dist/health-Ds2YlpTB.js +152 -0
  120. package/dist/heartbeat-engine-BYT5ayQH.js +83 -0
  121. package/dist/heartbeat-engine-CRqfPcFM.js +83 -0
  122. package/dist/hub-D0XwdjM-.js +515 -0
  123. package/dist/hub-DTsqe5Bt.js +6 -0
  124. package/dist/hub-FrPTA33j.js +515 -0
  125. package/dist/hub-LiD5Iztb.js +6 -0
  126. package/dist/hyperclawbot-D9KCtc4P.js +480 -0
  127. package/dist/hyperclawbot-Dw27pJo4.js +480 -0
  128. package/dist/hyperclawbot-zvczQgKx.js +505 -0
  129. package/dist/inference-BKVkBREb.js +6 -0
  130. package/dist/inference-CTWJeX9Q.js +922 -0
  131. package/dist/inference-DCXH4Q3x.js +922 -0
  132. package/dist/inference-ix607p7k.js +6 -0
  133. package/dist/knowledge-graph-DqA-Fztl.js +131 -0
  134. package/dist/knowledge-graph-iBG76fvm.js +131 -0
  135. package/dist/loader-CC45xGpC.js +4 -0
  136. package/dist/loader-CISCqBto.js +400 -0
  137. package/dist/loader-CYMQ8VOS.js +4 -0
  138. package/dist/loader-CnEdOyjT.js +400 -0
  139. package/dist/logger-8tEtAd3y.js +83 -0
  140. package/dist/logger-ybOp7VOC.js +83 -0
  141. package/dist/manager-03ipO9R0.js +105 -0
  142. package/dist/manager-BpDfbDjg.js +117 -0
  143. package/dist/manager-Bxl0sqlh.js +4 -0
  144. package/dist/manager-CPjeRe-6.js +4 -0
  145. package/dist/manager-CrVDn6eN.js +6 -0
  146. package/dist/manager-Cwzj7w5R.js +105 -0
  147. package/dist/manager-DLmZI-9R.js +6 -0
  148. package/dist/manager-DSGhn5i3.js +117 -0
  149. package/dist/manager-DgyF52mg.js +218 -0
  150. package/dist/manager-Dm8nrMFx.js +40 -0
  151. package/dist/manager-FCgF1plu.js +218 -0
  152. package/dist/manager-rgCsaWT1.js +40 -0
  153. package/dist/mcp-B_9Ber63.js +139 -0
  154. package/dist/mcp-CfoSU4Uz.js +139 -0
  155. package/dist/mcp-loader-DSM5UiFG.js +94 -0
  156. package/dist/mcp-loader-DkRBsLpk.js +94 -0
  157. package/dist/mcp-loader-j5ZLLw5O.js +94 -0
  158. package/dist/memory-BI1kPkAN.js +4 -0
  159. package/dist/memory-BVFGkxxK.js +270 -0
  160. package/dist/memory-BlHL7JCO.js +4 -0
  161. package/dist/memory-DsS_eFvJ.js +270 -0
  162. package/dist/memory-auto-Bc7euou4.js +306 -0
  163. package/dist/memory-auto-BkvtSFUw.js +5 -0
  164. package/dist/memory-auto-Bnz_-1wP.js +306 -0
  165. package/dist/memory-auto-DPfbkMVt.js +5 -0
  166. package/dist/memory-integration-DZExqWr4.js +91 -0
  167. package/dist/memory-integration-cSYkZyEo.js +91 -0
  168. package/dist/moltbook-B6ZeGN5_.js +81 -0
  169. package/dist/moltbook-BtLDZTfM.js +81 -0
  170. package/dist/node-Dw2Gi-cP.js +222 -0
  171. package/dist/node-pwL6O_KX.js +222 -0
  172. package/dist/nodes-registry-B8dmrlLv.js +52 -0
  173. package/dist/nodes-registry-CsPm_-CJ.js +52 -0
  174. package/dist/oauth-flow-CpWlgvNB.js +150 -0
  175. package/dist/oauth-flow-DQPvMHRH.js +150 -0
  176. package/dist/oauth-provider-BZb6qOw5.js +110 -0
  177. package/dist/oauth-provider-Uo4Nib_c.js +110 -0
  178. package/dist/observability-B43YvNQV.js +89 -0
  179. package/dist/observability-BV-Yx0V9.js +89 -0
  180. package/dist/onboard-0WoDxbv_.js +10 -0
  181. package/dist/onboard-BXNXCQp4.js +4070 -0
  182. package/dist/onboard-Bd_wsYdi.js +4086 -0
  183. package/dist/onboard-CAN7x3me.js +3026 -0
  184. package/dist/onboard-DnegOHMh.js +4 -4
  185. package/dist/onboard-RYtDlYBw.js +9 -0
  186. package/dist/onboard-aTwlQs-4.js +9 -0
  187. package/dist/orchestrator-BSp2M5EU.js +189 -0
  188. package/dist/orchestrator-C7ko5tWa.js +6 -0
  189. package/dist/orchestrator-DfPkIx2Z.js +6 -0
  190. package/dist/orchestrator-DmnEvMaL.js +189 -0
  191. package/dist/orchestrator-NJQsmiBE.js +189 -0
  192. package/dist/orchestrator-RI3bpqqc.js +6 -0
  193. package/dist/pairing-6iM27aD8.js +196 -0
  194. package/dist/pairing-DU0_J28n.js +87 -0
  195. package/dist/pairing-DWllbSbO.js +4 -0
  196. package/dist/pairing-dGoiGepK.js +4 -0
  197. package/dist/pc-access-CgCsYrpt.js +8 -0
  198. package/dist/pc-access-Ly-uA8mn.js +8 -0
  199. package/dist/pc-access-NxBvTrRj.js +819 -0
  200. package/dist/pc-access-_iH2aorG.js +819 -0
  201. package/dist/pending-approval-CUXjysAo.js +22 -0
  202. package/dist/pending-approval-DIHvwwWS.js +22 -0
  203. package/dist/puppeteer-2o3QOwAy.js +2 -2
  204. package/dist/puppeteer-BYTMp3BI.js +2 -2
  205. package/dist/puppeteer-DQ45qwWk.js +2 -2
  206. package/dist/reminders-store-D79qdfN0.js +58 -0
  207. package/dist/reminders-store-Drjed_-h.js +58 -0
  208. package/dist/renderer-BVQrd0_g.js +225 -0
  209. package/dist/renderer-pqlDRKbH.js +225 -0
  210. package/dist/rules-BE4GV6cV.js +103 -0
  211. package/dist/rules-BooT_qFP.js +103 -0
  212. package/dist/run-main.js +1649 -1227
  213. package/dist/runner-D1rjuMTJ.js +810 -0
  214. package/dist/runner-DatMMYYE.js +1271 -0
  215. package/dist/sdk/index.js +2 -2
  216. package/dist/sdk/index.mjs +2 -2
  217. package/dist/security-BqNyT4ID.js +4 -0
  218. package/dist/security-C-5URby1.js +73 -0
  219. package/dist/security-_xve79aq.js +4 -0
  220. package/dist/security-tpgqPWWH.js +73 -0
  221. package/dist/server-0kgyELx4.js +1047 -0
  222. package/dist/server-BIuTobTC.js +4 -0
  223. package/dist/server-BRlCEjyT.js +1047 -0
  224. package/dist/server-CCI1hv45.js +2 -2
  225. package/dist/server-D4wVHiX9.js +4 -0
  226. package/dist/server-DU9POoWc.js +4 -0
  227. package/dist/server-Dh3JlBFB.js +1255 -0
  228. package/dist/session-store-BUiPz0Vv.js +5 -0
  229. package/dist/session-store-CujxByI6.js +113 -0
  230. package/dist/session-store-is4B6qmD.js +113 -0
  231. package/dist/session-store-qpJUg2M1.js +5 -0
  232. package/dist/sessions-tools-CB2qbwIk.js +5 -0
  233. package/dist/sessions-tools-CbUTFe4i.js +5 -0
  234. package/dist/sessions-tools-CeqD7iil.js +95 -0
  235. package/dist/sessions-tools-DHMaTZIs.js +95 -0
  236. package/dist/skill-loader-BaNLVmJy.js +7 -0
  237. package/dist/skill-loader-BkceKkIg.js +7 -0
  238. package/dist/skill-loader-DhgIwK4J.js +159 -0
  239. package/dist/skill-loader-HgpF6Vqs.js +159 -0
  240. package/dist/skill-runtime--LqxWrp5.js +102 -0
  241. package/dist/skill-runtime-C5l0Tgt-.js +5 -0
  242. package/dist/skill-runtime-CJN24QPW.js +102 -0
  243. package/dist/skill-runtime-DsXK_HYG.js +102 -0
  244. package/dist/skill-runtime-IVTiqrMR.js +5 -0
  245. package/dist/skill-runtime-w1ig_lcw.js +5 -0
  246. package/dist/src-BEVLgaF1.js +63 -0
  247. package/dist/src-Bgu_OxTQ.js +458 -0
  248. package/dist/src-Bq-oKt7Z.js +458 -0
  249. package/dist/src-BxPHKO5x.js +63 -0
  250. package/dist/src-DIc-L2IG.js +20 -0
  251. package/dist/src-DWCUhnD4.js +20 -0
  252. package/dist/src-cfRTjFef.js +63 -0
  253. package/dist/src-g_rNx5rh.js +458 -0
  254. package/dist/sub-agent-tools-BD9DF8_g.js +39 -0
  255. package/dist/sub-agent-tools-CHQoHz9c.js +39 -0
  256. package/dist/sub-agent-tools-V7b3T9_s.js +39 -0
  257. package/dist/theme-DcxwcUgZ.js +180 -0
  258. package/dist/theme-cx0fkgWC.js +8 -0
  259. package/dist/tool-policy-CNT-mF2Z.js +189 -0
  260. package/dist/tool-policy-DNvNRnve.js +189 -0
  261. package/dist/tts-elevenlabs-BRosZv-f.js +61 -0
  262. package/dist/tts-elevenlabs-BUOGKL-k.js +61 -0
  263. package/dist/update-check-BD4qH7Am.js +81 -0
  264. package/dist/update-check-C2Dz85wJ.js +81 -0
  265. package/dist/vision-BMmiIKy7.js +121 -0
  266. package/dist/vision-DRq-f-Dj.js +121 -0
  267. package/dist/vision-tools-CFZEpQKm.js +5 -0
  268. package/dist/vision-tools-CQnBI9aa.js +51 -0
  269. package/dist/vision-tools-DVuYc17I.js +51 -0
  270. package/dist/vision-tools-U3YC4L-g.js +5 -0
  271. package/dist/voice-transcription-B555DbWR.js +138 -0
  272. package/dist/voice-transcription-CgWq54hn.js +138 -0
  273. package/dist/website-watch-tools-Bk_TnwuE.js +5 -0
  274. package/dist/website-watch-tools-DFMrJU-R.js +139 -0
  275. package/dist/website-watch-tools-DraMPxdl.js +139 -0
  276. package/dist/website-watch-tools-Du3W5sN7.js +5 -0
  277. package/package.json +1 -1
@@ -0,0 +1,350 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const chalk = require_chunk.__toESM(require("chalk"));
3
+ const fs_extra = require_chunk.__toESM(require("fs-extra"));
4
+ const path = require_chunk.__toESM(require("path"));
5
+ const os = require_chunk.__toESM(require("os"));
6
+ const crypto = require_chunk.__toESM(require("crypto"));
7
+ const https = require_chunk.__toESM(require("https"));
8
+ const events = require_chunk.__toESM(require("events"));
9
+
10
+ //#region extensions/line/src/connector.ts
11
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "line-state.json");
12
+ const TEXT_CHUNK = 5e3;
13
+ const DEFAULT_MEDIA_MAX_MB = 10;
14
+ function lineReq(token, endpoint, body) {
15
+ return new Promise((resolve, reject) => {
16
+ const payload = JSON.stringify(body);
17
+ const req = https.default.request({
18
+ hostname: "api.line.me",
19
+ port: 443,
20
+ path: endpoint,
21
+ method: "POST",
22
+ headers: {
23
+ Authorization: `Bearer ${token}`,
24
+ "Content-Type": "application/json",
25
+ "Content-Length": Buffer.byteLength(payload)
26
+ }
27
+ }, (res) => {
28
+ let data = "";
29
+ res.on("data", (c) => data += c);
30
+ res.on("end", () => {
31
+ try {
32
+ resolve(JSON.parse(data));
33
+ } catch {
34
+ resolve({});
35
+ }
36
+ });
37
+ });
38
+ req.on("error", reject);
39
+ req.write(payload);
40
+ req.end();
41
+ });
42
+ }
43
+ /** Start the LINE loading indicator for a chat. */
44
+ function lineLoadingIndicator(token, chatId) {
45
+ return lineReq(token, "/v2/bot/chat/loading/start", {
46
+ chatId,
47
+ loadingSeconds: 20
48
+ }).catch(() => {});
49
+ }
50
+ /**
51
+ * Strip markdown for plain-text delivery.
52
+ * Code blocks and tables are converted to Flex cards when channelData allows;
53
+ * for plain-text paths they become preformatted text.
54
+ */
55
+ function stripMarkdown(text) {
56
+ return text.replace(/```[\s\S]*?```/g, (m) => m.replace(/```\w*\n?/g, "").trim()).replace(/`([^`]+)`/g, "$1").replace(/^#{1,6}\s+/gm, "").replace(/\*\*(.+?)\*\*/g, "$1").replace(/\*(.+?)\*/g, "$1").replace(/~~(.+?)~~/g, "$1").replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/^\s*[-*+]\s+/gm, "• ").replace(/^\s*\d+\.\s+/gm, (m) => m.trimStart());
57
+ }
58
+ function buildQuickReply(items) {
59
+ return { items: items.slice(0, 13).map((label) => ({
60
+ type: "action",
61
+ action: {
62
+ type: "message",
63
+ label: label.slice(0, 20),
64
+ text: label
65
+ }
66
+ })) };
67
+ }
68
+ function buildMessages(text, channelData) {
69
+ const msgs = [];
70
+ const plain = stripMarkdown(text);
71
+ const qr = channelData?.quickReplies?.length ? buildQuickReply(channelData.quickReplies) : void 0;
72
+ if (channelData?.location) {
73
+ const loc = channelData.location;
74
+ msgs.push({
75
+ type: "location",
76
+ title: loc.title,
77
+ address: loc.address,
78
+ latitude: loc.latitude,
79
+ longitude: loc.longitude
80
+ });
81
+ }
82
+ if (channelData?.flexMessage) {
83
+ msgs.push({
84
+ type: "flex",
85
+ altText: channelData.flexMessage.altText,
86
+ contents: channelData.flexMessage.contents,
87
+ ...qr ? { quickReply: qr } : {}
88
+ });
89
+ return msgs;
90
+ }
91
+ if (channelData?.templateMessage) {
92
+ const t = channelData.templateMessage;
93
+ msgs.push({
94
+ type: "template",
95
+ altText: t.text,
96
+ template: {
97
+ type: "confirm",
98
+ text: t.text,
99
+ actions: [{
100
+ type: "postback",
101
+ label: t.confirmLabel,
102
+ data: t.confirmData
103
+ }, {
104
+ type: "postback",
105
+ label: t.cancelLabel,
106
+ data: t.cancelData
107
+ }]
108
+ },
109
+ ...qr ? { quickReply: qr } : {}
110
+ });
111
+ return msgs;
112
+ }
113
+ const chunks = chunkText(plain);
114
+ chunks.forEach((chunk, i) => {
115
+ const isLast = i === chunks.length - 1;
116
+ msgs.push({
117
+ type: "text",
118
+ text: chunk,
119
+ ...isLast && qr ? { quickReply: qr } : {}
120
+ });
121
+ });
122
+ return msgs;
123
+ }
124
+ function chunkText(text) {
125
+ const chunks = [];
126
+ for (let i = 0; i < text.length; i += TEXT_CHUNK) chunks.push(text.slice(i, i + TEXT_CHUNK));
127
+ return chunks.length ? chunks : [""];
128
+ }
129
+ var LINEConnector = class extends events.EventEmitter {
130
+ config;
131
+ running = false;
132
+ _token = "";
133
+ _secret = "";
134
+ constructor(config) {
135
+ super();
136
+ this.config = {
137
+ dmPolicy: "pairing",
138
+ allowFrom: [],
139
+ groupPolicy: "allowlist",
140
+ groupAllowFrom: [],
141
+ approvedPairings: [],
142
+ pendingPairings: {},
143
+ mediaMaxMb: DEFAULT_MEDIA_MAX_MB,
144
+ ...config
145
+ };
146
+ }
147
+ /** Resolve token and secret (inline value takes priority over file). */
148
+ async resolveCredentials() {
149
+ this._token = this.config.channelAccessToken || (this.config.tokenFile ? (await fs_extra.default.readFile(this.config.tokenFile, "utf8")).trim() : "");
150
+ this._secret = this.config.channelSecret || (this.config.secretFile ? (await fs_extra.default.readFile(this.config.secretFile, "utf8")).trim() : "");
151
+ if (!this._token || !this._secret) throw new Error("LINE: channelAccessToken and channelSecret are required (or set tokenFile/secretFile).");
152
+ }
153
+ async connect() {
154
+ await this.resolveCredentials();
155
+ await this.loadState();
156
+ this.running = true;
157
+ const wPath = this.config.webhookPath || "/line/webhook";
158
+ console.log(chalk.default.green(` 🟩 LINE: connected (webhook mode — ${wPath})`));
159
+ this.emit("connected", {});
160
+ }
161
+ disconnect() {
162
+ this.running = false;
163
+ }
164
+ verifySignature(rawBody, signature) {
165
+ const expected = crypto.default.createHmac("sha256", this._secret).update(rawBody).digest("base64");
166
+ try {
167
+ return crypto.default.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
168
+ } catch {
169
+ return false;
170
+ }
171
+ }
172
+ async handleWebhook(rawBody, signature) {
173
+ if (!this.verifySignature(rawBody, signature)) {
174
+ console.log(chalk.default.yellow(" ⚠ LINE: invalid signature — check channelSecret"));
175
+ return;
176
+ }
177
+ let payload;
178
+ try {
179
+ payload = JSON.parse(rawBody);
180
+ } catch {
181
+ return;
182
+ }
183
+ for (const event of payload.events || []) await this.handleEvent(event);
184
+ }
185
+ async handleEvent(event) {
186
+ const src = event.source || {};
187
+ const sourceType = src.type || "user";
188
+ const userId = src.userId || "";
189
+ const groupId = src.groupId || src.roomId || "";
190
+ const replyToken = event.replyToken || "";
191
+ const isGroup = sourceType === "group" || sourceType === "room";
192
+ if (event.type === "postback") {
193
+ const data = event.postback?.data || "";
194
+ if (!data || !userId) return;
195
+ if (isGroup) {
196
+ if (!this.isGroupAllowed(groupId, userId)) return;
197
+ } else if (!await this.checkDMPolicy(userId, data, replyToken)) return;
198
+ this.emit("message", {
199
+ channelId: "line",
200
+ chatId: isGroup ? groupId : userId,
201
+ from: userId,
202
+ text: data,
203
+ replyToken,
204
+ isDM: !isGroup
205
+ });
206
+ return;
207
+ }
208
+ if (event.type !== "message") return;
209
+ const msgType = event.message?.type || "";
210
+ const messageId = event.message?.id || "";
211
+ let text = "";
212
+ switch (msgType) {
213
+ case "text":
214
+ text = event.message.text || "";
215
+ break;
216
+ case "location":
217
+ text = [
218
+ event.message.title,
219
+ event.message.address,
220
+ `${event.message.latitude},${event.message.longitude}`
221
+ ].filter(Boolean).join(" | ");
222
+ break;
223
+ case "sticker":
224
+ text = `[sticker:${event.message.packageId}/${event.message.stickerId}]`;
225
+ break;
226
+ case "image":
227
+ case "video":
228
+ case "audio":
229
+ case "file": {
230
+ const maxBytes = (this.config.mediaMaxMb ?? DEFAULT_MEDIA_MAX_MB) * 1024 * 1024;
231
+ const contentUrl = `/v2/bot/message/${messageId}/content`;
232
+ text = `[${msgType}:${contentUrl} max:${maxBytes}b]`;
233
+ break;
234
+ }
235
+ default: return;
236
+ }
237
+ if (!userId || !text) return;
238
+ if (isGroup) {
239
+ if (!this.isGroupAllowed(groupId, userId)) return;
240
+ lineLoadingIndicator(this._token, groupId);
241
+ this.emit("message", {
242
+ channelId: "line",
243
+ chatId: groupId,
244
+ from: userId,
245
+ text,
246
+ replyToken,
247
+ isDM: false
248
+ });
249
+ } else {
250
+ const allowed = await this.checkDMPolicy(userId, text, replyToken);
251
+ if (!allowed) return;
252
+ lineLoadingIndicator(this._token, userId);
253
+ this.emit("message", {
254
+ channelId: "line",
255
+ chatId: userId,
256
+ from: userId,
257
+ text,
258
+ replyToken,
259
+ isDM: true,
260
+ timestamp: new Date(event.timestamp).toISOString()
261
+ });
262
+ }
263
+ }
264
+ isGroupAllowed(groupId, userId) {
265
+ if (this.config.groupPolicy === "disabled") return false;
266
+ if (this.config.groupPolicy === "open") return true;
267
+ const perGroup = this.config.groups?.[groupId]?.allowFrom;
268
+ const list = perGroup ?? this.config.groupAllowFrom;
269
+ return list.includes(userId) || list.includes(groupId);
270
+ }
271
+ async checkDMPolicy(from, text, replyToken) {
272
+ switch (this.config.dmPolicy) {
273
+ case "disabled": return false;
274
+ case "open": return true;
275
+ case "allowlist":
276
+ if (this.config.allowFrom.includes(from)) return true;
277
+ await this.replyMessage(replyToken, "HyperClaw: Not on allowlist.");
278
+ return false;
279
+ case "pairing": {
280
+ if (this.config.approvedPairings.includes(from)) return true;
281
+ const upper = text.trim().toUpperCase();
282
+ if (this.config.pendingPairings[upper]) {
283
+ this.config.approvedPairings.push(from);
284
+ delete this.config.pendingPairings[upper];
285
+ await this.saveState();
286
+ await this.replyMessage(replyToken, "Paired!");
287
+ this.emit("pairing:approved", {
288
+ userId: from,
289
+ channelId: "line"
290
+ });
291
+ return true;
292
+ }
293
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
294
+ this.config.pendingPairings[code] = from;
295
+ await this.saveState();
296
+ await this.replyMessage(replyToken, `Pairing code: ${code}\nApprove: hyperclaw pairing approve line ${code}`);
297
+ return false;
298
+ }
299
+ default: return false;
300
+ }
301
+ }
302
+ async replyMessage(replyToken, text, channelData) {
303
+ const messages = buildMessages(text, channelData).slice(0, 5);
304
+ await lineReq(this._token, "/v2/bot/message/reply", {
305
+ replyToken,
306
+ messages
307
+ });
308
+ }
309
+ async pushMessage(to, text, channelData) {
310
+ const messages = buildMessages(text, channelData).slice(0, 5);
311
+ await lineReq(this._token, "/v2/bot/message/push", {
312
+ to,
313
+ messages
314
+ });
315
+ }
316
+ /** Unified send — uses replyToken when available, falls back to push. */
317
+ async sendMessage(chatId, text, replyToken, channelData) {
318
+ const id = String(chatId);
319
+ if (replyToken) await this.replyMessage(replyToken, text, channelData);
320
+ else await this.pushMessage(id, text, channelData);
321
+ }
322
+ approvePairing(code) {
323
+ const upper = code.toUpperCase();
324
+ if (!this.config.pendingPairings[upper]) return false;
325
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
326
+ delete this.config.pendingPairings[upper];
327
+ this.saveState();
328
+ return true;
329
+ }
330
+ async loadState() {
331
+ try {
332
+ const s = await fs_extra.default.readJson(STATE_FILE);
333
+ if (s.p) this.config.pendingPairings = s.p;
334
+ if (s.a) this.config.approvedPairings = s.a;
335
+ } catch {}
336
+ }
337
+ async saveState() {
338
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
339
+ await fs_extra.default.writeJson(STATE_FILE, {
340
+ p: this.config.pendingPairings,
341
+ a: this.config.approvedPairings
342
+ }, { spaces: 2 });
343
+ }
344
+ isRunning() {
345
+ return this.running;
346
+ }
347
+ };
348
+
349
+ //#endregion
350
+ exports.LINEConnector = LINEConnector;
@@ -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;