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,340 @@
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 http = require_chunk.__toESM(require("http"));
8
+ const https = require_chunk.__toESM(require("https"));
9
+ const events = require_chunk.__toESM(require("events"));
10
+
11
+ //#region extensions/nextcloud/src/connector.ts
12
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "nextcloud-talk-state.json");
13
+ const DEFAULT_PORT = 8788;
14
+ const DEFAULT_HOST = "0.0.0.0";
15
+ const DEFAULT_PATH = "/nextcloud-talk-webhook";
16
+ const DEFAULT_CHUNK = 32e3;
17
+ function ocsReq(baseUrl, user, password, method, apiPath, body) {
18
+ return new Promise((resolve, reject) => {
19
+ const url = new URL(`${baseUrl}/ocs/v2.php/apps/spreed/api/v4${apiPath}`);
20
+ const isHttps = url.protocol === "https:";
21
+ const mod = isHttps ? https.default : http.default;
22
+ const auth = Buffer.from(`${user}:${password}`).toString("base64");
23
+ const payload = body ? JSON.stringify(body) : null;
24
+ const req = mod.request({
25
+ hostname: url.hostname,
26
+ port: url.port || (isHttps ? 443 : 80),
27
+ path: url.pathname + url.search,
28
+ method,
29
+ headers: {
30
+ Authorization: `Basic ${auth}`,
31
+ "OCS-APIRequest": "true",
32
+ Accept: "application/json",
33
+ ...payload ? {
34
+ "Content-Type": "application/json",
35
+ "Content-Length": Buffer.byteLength(payload)
36
+ } : {}
37
+ }
38
+ }, (res) => {
39
+ let data = "";
40
+ res.on("data", (c) => data += c);
41
+ res.on("end", () => {
42
+ try {
43
+ const parsed = JSON.parse(data);
44
+ const ocs = parsed?.ocs;
45
+ if (ocs?.meta?.statuscode >= 400) reject(new Error(ocs.meta.message || "OCS error"));
46
+ else resolve(ocs?.data ?? parsed);
47
+ } catch {
48
+ reject(new Error("Nextcloud: invalid JSON"));
49
+ }
50
+ });
51
+ });
52
+ req.on("error", reject);
53
+ if (payload) req.write(payload);
54
+ req.end();
55
+ });
56
+ }
57
+ /** Send a message via the Talk bot API (X-Nextcloud-Talk-Bot-Secret auth). */
58
+ function botSend(baseUrl, secret, token, message, referenceId) {
59
+ return new Promise((resolve, reject) => {
60
+ const url = new URL(`${baseUrl}/ocs/v2.php/apps/spreed/api/v1/bot/${token}/message`);
61
+ const isHttps = url.protocol === "https:";
62
+ const mod = isHttps ? https.default : http.default;
63
+ const payload = JSON.stringify({
64
+ message,
65
+ referenceId: referenceId || crypto.default.randomBytes(8).toString("hex")
66
+ });
67
+ const req = mod.request({
68
+ hostname: url.hostname,
69
+ port: url.port || (isHttps ? 443 : 80),
70
+ path: url.pathname,
71
+ method: "POST",
72
+ headers: {
73
+ "X-Nextcloud-Talk-Bot-Secret": secret,
74
+ "OCS-APIRequest": "true",
75
+ "Content-Type": "application/json",
76
+ "Content-Length": Buffer.byteLength(payload)
77
+ }
78
+ }, (res) => {
79
+ let data = "";
80
+ res.on("data", (c) => data += c);
81
+ res.on("end", () => {
82
+ try {
83
+ resolve(JSON.parse(data));
84
+ } catch {
85
+ resolve({});
86
+ }
87
+ });
88
+ });
89
+ req.on("error", reject);
90
+ req.write(payload);
91
+ req.end();
92
+ });
93
+ }
94
+ function chunkText(text, limit, mode) {
95
+ if (mode === "newline") {
96
+ const paras = text.split(/\n\n+/);
97
+ const chunks$1 = [];
98
+ let cur = "";
99
+ for (const p of paras) if ((cur + "\n\n" + p).length > limit && cur) {
100
+ chunks$1.push(cur.trim());
101
+ cur = p;
102
+ } else cur = cur ? cur + "\n\n" + p : p;
103
+ if (cur) chunks$1.push(cur.trim());
104
+ return chunks$1.filter(Boolean);
105
+ }
106
+ const chunks = [];
107
+ for (let i = 0; i < text.length; i += limit) chunks.push(text.slice(i, i + limit));
108
+ return chunks.length ? chunks : [""];
109
+ }
110
+ var NextcloudTalkConnector = class extends events.EventEmitter {
111
+ config;
112
+ server = null;
113
+ running = false;
114
+ resolvedSecret = "";
115
+ resolvedApiPassword = "";
116
+ /** Cache: room token → isDM (room.type === 1) */
117
+ roomTypeCache = /* @__PURE__ */ new Map();
118
+ constructor(config) {
119
+ super();
120
+ this.config = {
121
+ dmPolicy: "pairing",
122
+ allowFrom: [],
123
+ groupPolicy: "allowlist",
124
+ groupAllowFrom: [],
125
+ rooms: {},
126
+ approvedPairings: [],
127
+ pendingPairings: {},
128
+ ...config
129
+ };
130
+ }
131
+ async resolveCredentials() {
132
+ this.resolvedSecret = this.config.botSecret || (this.config.botSecretFile ? (await fs_extra.default.readFile(this.config.botSecretFile, "utf8")).trim() : "");
133
+ if (!this.resolvedSecret) throw new Error("nextcloud-talk: botSecret or botSecretFile is required");
134
+ this.resolvedApiPassword = this.config.apiPassword || (this.config.apiPasswordFile ? (await fs_extra.default.readFile(this.config.apiPasswordFile, "utf8")).trim() : "");
135
+ }
136
+ async connect() {
137
+ await this.resolveCredentials();
138
+ await this.loadState();
139
+ this.running = true;
140
+ await this.startWebhookServer();
141
+ const port = this.config.webhookPort ?? DEFAULT_PORT;
142
+ const wPath = this.config.webhookPath ?? DEFAULT_PATH;
143
+ const publicUrl = this.config.webhookPublicUrl || `http://localhost:${port}${wPath}`;
144
+ console.log(chalk.default.green(` ☁️ Nextcloud Talk: webhook listening at ${publicUrl}`));
145
+ this.emit("connected", { webhookUrl: publicUrl });
146
+ }
147
+ disconnect() {
148
+ this.running = false;
149
+ this.server?.close();
150
+ this.server = null;
151
+ }
152
+ startWebhookServer() {
153
+ return new Promise((resolve, reject) => {
154
+ this.server = http.default.createServer((req, res) => {
155
+ const wPath = this.config.webhookPath ?? DEFAULT_PATH;
156
+ if (req.url !== wPath || req.method !== "POST") {
157
+ res.writeHead(404);
158
+ res.end();
159
+ return;
160
+ }
161
+ let body = "";
162
+ req.on("data", (c) => body += c.toString());
163
+ req.on("end", () => {
164
+ const random = req.headers["x-nextcloud-talk-random"];
165
+ const sig = req.headers["x-nextcloud-talk-signature"];
166
+ if (!this.verifySignature(random || "", body, sig || "")) {
167
+ console.log(chalk.default.yellow(" ⚠ Nextcloud Talk: invalid webhook signature"));
168
+ res.writeHead(401);
169
+ res.end();
170
+ return;
171
+ }
172
+ res.writeHead(200);
173
+ res.end();
174
+ this.handlePayload(body).catch((e) => console.error(`[nextcloud-talk] handler error: ${e.message}`));
175
+ });
176
+ });
177
+ const port = this.config.webhookPort ?? DEFAULT_PORT;
178
+ const host = this.config.webhookHost ?? DEFAULT_HOST;
179
+ this.server.listen(port, host, () => resolve());
180
+ this.server.on("error", reject);
181
+ });
182
+ }
183
+ verifySignature(random, body, signature) {
184
+ if (!this.resolvedSecret) return false;
185
+ const expected = crypto.default.createHmac("sha256", this.resolvedSecret).update(random + body).digest("hex");
186
+ try {
187
+ return crypto.default.timingSafeEqual(Buffer.from(signature.toLowerCase()), Buffer.from(expected.toLowerCase()));
188
+ } catch {
189
+ return false;
190
+ }
191
+ }
192
+ async handlePayload(raw) {
193
+ let payload;
194
+ try {
195
+ payload = JSON.parse(raw);
196
+ } catch {
197
+ return;
198
+ }
199
+ const objectType = payload?.object?.type || "";
200
+ const actorId = payload?.actor?.id || "";
201
+ const actorName = payload?.actor?.name || actorId;
202
+ const token = payload?.target?.id || "";
203
+ if (!token || !actorId) return;
204
+ switch (objectType) {
205
+ case "chat-message": {
206
+ const msgContent = payload.object?.content;
207
+ const text = (typeof msgContent === "object" ? msgContent?.message : msgContent) || payload.object?.name || "";
208
+ if (!text) return;
209
+ await this.routeMessage(token, actorId, actorName, text);
210
+ break;
211
+ }
212
+ case "reaction": {
213
+ const emoji = payload.object?.name || payload.object?.content || "";
214
+ const reactedId = String(payload.object?.id || "");
215
+ if (!emoji) return;
216
+ const text = `[reaction:${emoji}:${reactedId}]`;
217
+ await this.routeMessage(token, actorId, actorName, text);
218
+ break;
219
+ }
220
+ default: break;
221
+ }
222
+ }
223
+ async routeMessage(token, userId, displayName, text) {
224
+ const isDM = await this.detectDM(token);
225
+ if (isDM) {
226
+ const allowed = await this.checkDMPolicy(userId, text, token);
227
+ if (!allowed) return;
228
+ } else if (!this.checkGroupPolicy(token, userId, text)) return;
229
+ this.emit("message", {
230
+ channelId: "nextcloud-talk",
231
+ chatId: token,
232
+ from: userId,
233
+ displayName,
234
+ text,
235
+ isDM
236
+ });
237
+ }
238
+ /** Look up whether a room token is a DM (type=1). Caches results. */
239
+ async detectDM(token) {
240
+ if (this.roomTypeCache.has(token)) return this.roomTypeCache.get(token);
241
+ if (!this.config.apiUser || !this.resolvedApiPassword) {
242
+ this.roomTypeCache.set(token, false);
243
+ return false;
244
+ }
245
+ try {
246
+ const room = await ocsReq(this.config.baseUrl, this.config.apiUser, this.resolvedApiPassword, "GET", `/room/${token}`);
247
+ const isDM = room?.type === 1;
248
+ this.roomTypeCache.set(token, isDM);
249
+ return isDM;
250
+ } catch {
251
+ this.roomTypeCache.set(token, false);
252
+ return false;
253
+ }
254
+ }
255
+ async checkDMPolicy(userId, text, token) {
256
+ switch (this.config.dmPolicy) {
257
+ case "disabled": return false;
258
+ case "open": return true;
259
+ case "allowlist":
260
+ if (this.config.allowFrom.includes(userId) || this.config.allowFrom.includes("*")) return true;
261
+ await this.sendMessage(token, "HyperClaw: Not on allowlist.");
262
+ return false;
263
+ case "pairing": {
264
+ if (this.config.approvedPairings.includes(userId)) return true;
265
+ const upper = text.trim().toUpperCase().match(/[A-Z0-9]{6}/)?.[0];
266
+ if (upper && this.config.pendingPairings[upper]) {
267
+ this.config.approvedPairings.push(userId);
268
+ delete this.config.pendingPairings[upper];
269
+ await this.saveState();
270
+ await this.sendMessage(token, "Paired!");
271
+ this.emit("pairing:approved", {
272
+ userId,
273
+ channelId: "nextcloud-talk"
274
+ });
275
+ return true;
276
+ }
277
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
278
+ this.config.pendingPairings[code] = userId;
279
+ await this.saveState();
280
+ await this.sendMessage(token, `Pairing code: ${code}\nApprove: hyperclaw pairing approve nextcloud-talk ${code}`);
281
+ return false;
282
+ }
283
+ }
284
+ return false;
285
+ }
286
+ checkGroupPolicy(token, userId, text) {
287
+ const policy = this.config.groupPolicy;
288
+ if (policy === "disabled") return false;
289
+ const roomCfg = this.config.rooms[token];
290
+ if (policy === "open") {
291
+ if (roomCfg?.allowFrom?.length && !roomCfg.allowFrom.includes(userId)) return false;
292
+ const global$1 = this.config.groupAllowFrom;
293
+ if (global$1.length && !global$1.includes(userId)) return false;
294
+ return true;
295
+ }
296
+ if (!roomCfg) return false;
297
+ const global = this.config.groupAllowFrom;
298
+ if (global.length && !global.includes(userId)) return false;
299
+ if (roomCfg.allowFrom?.length && !roomCfg.allowFrom.includes(userId)) return false;
300
+ if (roomCfg.requireMention !== false) {
301
+ if (!text.includes("@HyperClaw") && !text.startsWith("!")) return false;
302
+ }
303
+ return true;
304
+ }
305
+ async sendMessage(token, text) {
306
+ const limit = this.config.textChunkLimit ?? DEFAULT_CHUNK;
307
+ const mode = this.config.chunkMode ?? "length";
308
+ const chunks = chunkText(text, limit, mode);
309
+ for (const chunk of chunks) if (this.config.apiUser && this.resolvedApiPassword) await ocsReq(this.config.baseUrl, this.config.apiUser, this.resolvedApiPassword, "POST", `/chat/${token}`, { message: chunk });
310
+ else await botSend(this.config.baseUrl, this.resolvedSecret, token, chunk);
311
+ }
312
+ approvePairing(code) {
313
+ const upper = code.toUpperCase();
314
+ if (!this.config.pendingPairings[upper]) return false;
315
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
316
+ delete this.config.pendingPairings[upper];
317
+ this.saveState();
318
+ return true;
319
+ }
320
+ async loadState() {
321
+ try {
322
+ const s = await fs_extra.default.readJson(STATE_FILE);
323
+ if (s.p) this.config.pendingPairings = s.p;
324
+ if (s.a) this.config.approvedPairings = s.a;
325
+ } catch {}
326
+ }
327
+ async saveState() {
328
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
329
+ await fs_extra.default.writeJson(STATE_FILE, {
330
+ p: this.config.pendingPairings,
331
+ a: this.config.approvedPairings
332
+ }, { spaces: 2 });
333
+ }
334
+ isRunning() {
335
+ return this.running;
336
+ }
337
+ };
338
+
339
+ //#endregion
340
+ exports.NextcloudTalkConnector = NextcloudTalkConnector;
@@ -0,0 +1,225 @@
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 events = require_chunk.__toESM(require("events"));
7
+
8
+ //#region extensions/imessage-native/src/connector.ts
9
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "imessage-native-state.json");
10
+ const PAIRING_TTL_MS = 60 * 60 * 1e3;
11
+ var IMessageNativeConnector = class extends events.EventEmitter {
12
+ config;
13
+ rpcProc = null;
14
+ running = false;
15
+ lastMessageTs = 0;
16
+ rpcSeq = 1;
17
+ pending = /* @__PURE__ */ new Map();
18
+ buf = "";
19
+ constructor(config = {}) {
20
+ super();
21
+ this.config = {
22
+ cliPath: config.cliPath || process.env.IMSG_PATH || "imsg",
23
+ dbPath: config.dbPath || path.default.join(os.default.homedir(), "Library", "Messages", "chat.db"),
24
+ dmPolicy: config.dmPolicy ?? "pairing",
25
+ allowFrom: config.allowFrom ?? [],
26
+ approvedPairings: config.approvedPairings ?? [],
27
+ pendingPairings: config.pendingPairings ?? {},
28
+ pendingPairingTs: config.pendingPairingTs ?? {}
29
+ };
30
+ }
31
+ async connect() {
32
+ if (process.platform !== "darwin") throw new Error("imessage-native is macOS only. For new deployments use BlueBubbles.");
33
+ await this.loadState();
34
+ this.running = true;
35
+ this.emit("connected", {});
36
+ this.startRpc();
37
+ }
38
+ startRpc() {
39
+ if (!this.running) return;
40
+ const bin = this.config.cliPath;
41
+ const args = ["rpc"];
42
+ if (this.config.dbPath) args.push("--db", this.config.dbPath);
43
+ this.rpcProc = (0, child_process.spawn)(bin, args, { stdio: [
44
+ "pipe",
45
+ "pipe",
46
+ "pipe"
47
+ ] });
48
+ this.rpcProc.stdout?.on("data", (chunk) => {
49
+ this.buf += chunk.toString();
50
+ const lines = this.buf.split("\n");
51
+ this.buf = lines.pop() || "";
52
+ for (const line of lines) {
53
+ if (!line.trim()) continue;
54
+ try {
55
+ this.handleRpcLine(JSON.parse(line));
56
+ } catch {}
57
+ }
58
+ });
59
+ this.rpcProc.stderr?.on("data", () => {});
60
+ this.rpcProc.on("error", () => {});
61
+ this.rpcProc.on("exit", (code) => {
62
+ this.rpcProc = null;
63
+ this.buf = "";
64
+ for (const [, cb] of this.pending) cb.reject(new Error("imsg rpc exited"));
65
+ this.pending.clear();
66
+ if (this.running && code !== 0) setTimeout(() => this.startRpc(), 5e3);
67
+ });
68
+ this.rpcSend("messages.watch", {}).catch(() => {});
69
+ }
70
+ handleRpcLine(msg) {
71
+ if (!msg.id && msg.method === "message" && msg.params) {
72
+ this.onIncomingMessage(msg.params);
73
+ return;
74
+ }
75
+ if (msg.id != null) {
76
+ const cb = this.pending.get(msg.id);
77
+ if (!cb) return;
78
+ this.pending.delete(msg.id);
79
+ if (msg.error) cb.reject(new Error(msg.error.message));
80
+ else cb.resolve(msg.result);
81
+ }
82
+ }
83
+ onIncomingMessage(params) {
84
+ if (params.isFromMe) return;
85
+ const handle = params.handle?.address || params.sender || params.chatId || params.from;
86
+ const text = params.text || params.body || params.message;
87
+ if (!handle || !text) return;
88
+ const ts = params.dateCreated || params.timestamp || Date.now();
89
+ if (ts <= this.lastMessageTs) return;
90
+ this.lastMessageTs = ts;
91
+ this.saveState();
92
+ this.checkDMPolicyAndEmit(handle, text);
93
+ }
94
+ pruneExpiredCodes() {
95
+ const now = Date.now();
96
+ const ts = this.config.pendingPairingTs;
97
+ for (const code of Object.keys(ts)) if (now - ts[code] > PAIRING_TTL_MS) {
98
+ delete this.config.pendingPairings[code];
99
+ delete ts[code];
100
+ }
101
+ }
102
+ async checkDMPolicyAndEmit(from, text) {
103
+ if (this.config.dmPolicy === "disabled") return;
104
+ if (this.config.dmPolicy === "open") {
105
+ this.emit("message", {
106
+ chatId: from,
107
+ text
108
+ });
109
+ return;
110
+ }
111
+ if (this.config.dmPolicy === "allowlist") {
112
+ if (this.config.allowFrom.includes(from)) this.emit("message", {
113
+ chatId: from,
114
+ text
115
+ });
116
+ else await this.sendMessage(from, "HyperClaw: Not on allowlist.");
117
+ return;
118
+ }
119
+ this.pruneExpiredCodes();
120
+ if (this.config.approvedPairings.includes(from)) {
121
+ this.emit("message", {
122
+ chatId: from,
123
+ text
124
+ });
125
+ return;
126
+ }
127
+ const code = (text.trim().toUpperCase().match(/[A-Z0-9]{6}/) || [])[0];
128
+ if (code && this.config.pendingPairings[code]) {
129
+ this.config.approvedPairings.push(from);
130
+ delete this.config.pendingPairings[code];
131
+ delete this.config.pendingPairingTs[code];
132
+ await this.saveState();
133
+ await this.sendMessage(from, "Paired!");
134
+ this.emit("pairing:approved", {
135
+ userId: from,
136
+ channelId: "imessage-native"
137
+ });
138
+ this.emit("message", {
139
+ chatId: from,
140
+ text
141
+ });
142
+ return;
143
+ }
144
+ const newCode = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
145
+ this.config.pendingPairings[newCode] = from;
146
+ this.config.pendingPairingTs[newCode] = Date.now();
147
+ await this.saveState();
148
+ await this.sendMessage(from, `Pairing code: ${newCode}\nApprove: hyperclaw pairing approve imessage-native ${newCode}\n(expires in 1 hour)`);
149
+ }
150
+ async sendMessage(chatId, text) {
151
+ const to = String(chatId).trim();
152
+ if (!to) return;
153
+ if (!this.rpcProc) throw new Error("imsg rpc not running");
154
+ await this.rpcSend("messages.send", {
155
+ to,
156
+ text
157
+ });
158
+ }
159
+ rpcSend(method, params) {
160
+ return new Promise((resolve, reject) => {
161
+ if (!this.rpcProc?.stdin) {
162
+ reject(new Error("imsg rpc stdin unavailable"));
163
+ return;
164
+ }
165
+ const id = this.rpcSeq++;
166
+ const req = {
167
+ jsonrpc: "2.0",
168
+ id,
169
+ method,
170
+ params
171
+ };
172
+ this.pending.set(id, {
173
+ resolve,
174
+ reject
175
+ });
176
+ this.rpcProc.stdin.write(JSON.stringify(req) + "\n");
177
+ const timer = setTimeout(() => {
178
+ if (this.pending.has(id)) {
179
+ this.pending.delete(id);
180
+ reject(new Error(`imsg rpc timeout for method ${method}`));
181
+ }
182
+ }, 15e3);
183
+ const orig = this.pending.get(id);
184
+ this.pending.set(id, {
185
+ resolve: (v) => {
186
+ clearTimeout(timer);
187
+ orig.resolve(v);
188
+ },
189
+ reject: (e) => {
190
+ clearTimeout(timer);
191
+ orig.reject(e);
192
+ }
193
+ });
194
+ });
195
+ }
196
+ disconnect() {
197
+ this.running = false;
198
+ this.rpcProc?.kill();
199
+ this.rpcProc = null;
200
+ this.buf = "";
201
+ for (const [, cb] of this.pending) cb.reject(new Error("disconnected"));
202
+ this.pending.clear();
203
+ }
204
+ async loadState() {
205
+ try {
206
+ const s = await fs_extra.default.readJson(STATE_FILE);
207
+ this.lastMessageTs = s.lastTs || 0;
208
+ if (s.p) this.config.pendingPairings = s.p;
209
+ if (s.a) this.config.approvedPairings = s.a;
210
+ if (s.pts) this.config.pendingPairingTs = s.pts;
211
+ } catch {}
212
+ }
213
+ async saveState() {
214
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
215
+ await fs_extra.default.writeJson(STATE_FILE, {
216
+ lastTs: this.lastMessageTs,
217
+ p: this.config.pendingPairings,
218
+ a: this.config.approvedPairings,
219
+ pts: this.config.pendingPairingTs
220
+ }, { spaces: 2 });
221
+ }
222
+ };
223
+
224
+ //#endregion
225
+ exports.IMessageNativeConnector = IMessageNativeConnector;