hyperclaw 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/README.md +53 -18
  2. package/dist/a2ui-protocol-CT_jDEU9.js +75 -0
  3. package/dist/agents-routing-683Q2JGp.js +129 -0
  4. package/dist/agents-routing-BpZBswBH.js +4 -0
  5. package/dist/api-keys-guide-Bzig1R5W.js +149 -0
  6. package/dist/api-keys-guide-Dq5Obbp4.js +149 -0
  7. package/dist/audit-BYxPlnTQ.js +248 -0
  8. package/dist/bounty-tools-C6LyzxM-.js +211 -0
  9. package/dist/browser-tools-CQBSbIuO.js +5 -0
  10. package/dist/browser-tools-YQmwRLLM.js +179 -0
  11. package/dist/claw-tasks-BRLUvFRD.js +80 -0
  12. package/dist/connector-3HnyH8fn.js +167 -0
  13. package/dist/connector-6PMZo5Ky.js +189 -0
  14. package/dist/connector-B6eoF3DD.js +181 -0
  15. package/dist/connector-B9tLG8UZ.js +196 -0
  16. package/dist/connector-BOlqjXWP.js +182 -0
  17. package/dist/connector-BP8zsbP8.js +189 -0
  18. package/dist/connector-BPoSevxp.js +286 -0
  19. package/dist/connector-BRHj773i.js +163 -0
  20. package/dist/connector-BToxU-jV.js +267 -0
  21. package/dist/connector-BliDVsJQ.js +239 -0
  22. package/dist/connector-Bv6s9oP7.js +88 -0
  23. package/dist/connector-By5wWGTR.js +343 -0
  24. package/dist/connector-C1BaFFgN.js +213 -0
  25. package/dist/connector-CRRWY5Wv.js +167 -0
  26. package/dist/connector-CXPQVGyI.js +85 -0
  27. package/dist/connector-Cdk1CXKi.js +194 -0
  28. package/dist/connector-CwlgFgjx.js +181 -0
  29. package/dist/connector-DFchk6l7.js +178 -0
  30. package/dist/connector-DKw7tRAy.js +192 -0
  31. package/dist/connector-DRv1ahC_.js +343 -0
  32. package/dist/connector-DU63KW94.js +165 -0
  33. package/dist/connector-Dbvb1Cj9.js +280 -0
  34. package/dist/connector-DcZdQcgR.js +173 -0
  35. package/dist/connector-DxKL8VvZ.js +182 -0
  36. package/dist/connector-T_YdZtzv.js +162 -0
  37. package/dist/connector-i4gOS9xL.js +154 -0
  38. package/dist/connector-rHXE1ZD2.js +167 -0
  39. package/dist/connector-wdUXChwa.js +172 -0
  40. package/dist/cost-tracker-pVE15Yq4.js +103 -0
  41. package/dist/credentials-store-BvnMPJwi.js +4 -0
  42. package/dist/credentials-store-sb-TRLwR.js +77 -0
  43. package/dist/cron-tasks-BvDFNyiE.js +82 -0
  44. package/dist/delivery-B-SJqXLn.js +95 -0
  45. package/dist/delivery-D5Z98EVq.js +95 -0
  46. package/dist/delivery-DCOXhXEO.js +5 -0
  47. package/dist/delivery-VgFeuu2J.js +5 -0
  48. package/dist/destructive-gate-m-dWqUFg.js +101 -0
  49. package/dist/developer-keys-JaJK3T27.js +127 -0
  50. package/dist/developer-keys-kyqmtWK3.js +8 -0
  51. package/dist/doctor-3oi89QIc.js +175 -0
  52. package/dist/doctor-Cf1XSfp9.js +4 -0
  53. package/dist/engine-B4eMiTgl.js +7 -0
  54. package/dist/engine-B8M7dYul.js +7 -0
  55. package/dist/engine-BhT-1M9W.js +256 -0
  56. package/dist/engine-D49jnSd_.js +256 -0
  57. package/dist/env-resolve-DWOQ45jG.js +9 -0
  58. package/dist/env-resolve-szSWl0UF.js +94 -0
  59. package/dist/extraction-tools-D3qDFBJ1.js +91 -0
  60. package/dist/extraction-tools-DLr_AEwq.js +5 -0
  61. package/dist/form_data-B_hIUrxU.js +8657 -0
  62. package/dist/gmail-watch-setup-Czt8rXaX.js +40 -0
  63. package/dist/heartbeat-engine-CRqfPcFM.js +83 -0
  64. package/dist/hub-DTsqe5Bt.js +6 -0
  65. package/dist/hub-FrPTA33j.js +515 -0
  66. package/dist/hyperclawbot-D9KCtc4P.js +480 -0
  67. package/dist/hyperclawbot-DfMGowZC.js +480 -0
  68. package/dist/hyperclawbot-Dw27pJo4.js +480 -0
  69. package/dist/inference-CTWJeX9Q.js +922 -0
  70. package/dist/inference-ix607p7k.js +6 -0
  71. package/dist/knowledge-graph-DqA-Fztl.js +131 -0
  72. package/dist/loader-CISCqBto.js +400 -0
  73. package/dist/loader-CYMQ8VOS.js +4 -0
  74. package/dist/logger-8tEtAd3y.js +83 -0
  75. package/dist/manager-CPjeRe-6.js +4 -0
  76. package/dist/manager-Cwzj7w5R.js +105 -0
  77. package/dist/manager-DLmZI-9R.js +6 -0
  78. package/dist/manager-DSGhn5i3.js +117 -0
  79. package/dist/manager-DgyF52mg.js +218 -0
  80. package/dist/manager-Dm8nrMFx.js +40 -0
  81. package/dist/mcp-B_9Ber63.js +139 -0
  82. package/dist/mcp-loader-DSM5UiFG.js +94 -0
  83. package/dist/mcp-loader-j5ZLLw5O.js +94 -0
  84. package/dist/memory-BI1kPkAN.js +4 -0
  85. package/dist/memory-BVFGkxxK.js +270 -0
  86. package/dist/memory-auto-Bc7euou4.js +306 -0
  87. package/dist/memory-auto-DPfbkMVt.js +5 -0
  88. package/dist/memory-integration-DZExqWr4.js +91 -0
  89. package/dist/moltbook-B6ZeGN5_.js +81 -0
  90. package/dist/node-pwL6O_KX.js +222 -0
  91. package/dist/nodes-registry-CsPm_-CJ.js +52 -0
  92. package/dist/oauth-flow-CpWlgvNB.js +150 -0
  93. package/dist/oauth-provider-BZb6qOw5.js +110 -0
  94. package/dist/observability-B43YvNQV.js +89 -0
  95. package/dist/onboard-3q20ZyHj.js +9 -0
  96. package/dist/onboard-Bd_wsYdi.js +4086 -0
  97. package/dist/onboard-CAN7x3me.js +3026 -0
  98. package/dist/onboard-DnegOHMh.js +3026 -0
  99. package/dist/onboard-RYtDlYBw.js +9 -0
  100. package/dist/onboard-aTwlQs-4.js +9 -0
  101. package/dist/orchestrator-BSp2M5EU.js +189 -0
  102. package/dist/orchestrator-C7ko5tWa.js +6 -0
  103. package/dist/orchestrator-DfPkIx2Z.js +6 -0
  104. package/dist/orchestrator-NJQsmiBE.js +189 -0
  105. package/dist/pairing-DU0_J28n.js +87 -0
  106. package/dist/pairing-DWllbSbO.js +4 -0
  107. package/dist/pc-access-Ly-uA8mn.js +8 -0
  108. package/dist/pc-access-NxBvTrRj.js +819 -0
  109. package/dist/pending-approval-DIHvwwWS.js +22 -0
  110. package/dist/puppeteer-2o3QOwAy.js +2 -2
  111. package/dist/puppeteer-BYTMp3BI.js +2 -2
  112. package/dist/puppeteer-DQ45qwWk.js +2 -2
  113. package/dist/reminders-store-D79qdfN0.js +58 -0
  114. package/dist/renderer-pqlDRKbH.js +225 -0
  115. package/dist/rules-BooT_qFP.js +103 -0
  116. package/dist/run-main.js +366 -1109
  117. package/dist/runner-Bu--_RXw.js +810 -0
  118. package/dist/runner-D1rjuMTJ.js +810 -0
  119. package/dist/sdk/index.js +2 -2
  120. package/dist/sdk/index.mjs +2 -2
  121. package/dist/security-C-5URby1.js +73 -0
  122. package/dist/security-_xve79aq.js +4 -0
  123. package/dist/server-0kgyELx4.js +1047 -0
  124. package/dist/server-BIuTobTC.js +4 -0
  125. package/dist/server-BRlCEjyT.js +1047 -0
  126. package/dist/server-CCI1hv45.js +1047 -0
  127. package/dist/server-DU9POoWc.js +4 -0
  128. package/dist/server-RBqwE_GN.js +4 -0
  129. package/dist/session-store-CujxByI6.js +113 -0
  130. package/dist/session-store-qpJUg2M1.js +5 -0
  131. package/dist/sessions-tools-CB2qbwIk.js +5 -0
  132. package/dist/sessions-tools-DHMaTZIs.js +95 -0
  133. package/dist/skill-loader-BkceKkIg.js +7 -0
  134. package/dist/skill-loader-DhgIwK4J.js +159 -0
  135. package/dist/skill-runtime--LqxWrp5.js +102 -0
  136. package/dist/skill-runtime-C5l0Tgt-.js +5 -0
  137. package/dist/skill-runtime-DsXK_HYG.js +102 -0
  138. package/dist/skill-runtime-IVTiqrMR.js +5 -0
  139. package/dist/src-BEVLgaF1.js +63 -0
  140. package/dist/src-Bgu_OxTQ.js +458 -0
  141. package/dist/src-Bq-oKt7Z.js +458 -0
  142. package/dist/src-DWCUhnD4.js +20 -0
  143. package/dist/src-cfRTjFef.js +63 -0
  144. package/dist/sub-agent-tools-BD9DF8_g.js +39 -0
  145. package/dist/sub-agent-tools-V7b3T9_s.js +39 -0
  146. package/dist/tool-policy-DNvNRnve.js +189 -0
  147. package/dist/tts-elevenlabs-BUOGKL-k.js +61 -0
  148. package/dist/update-check-BD4qH7Am.js +81 -0
  149. package/dist/vision-DRq-f-Dj.js +121 -0
  150. package/dist/vision-tools-CFZEpQKm.js +5 -0
  151. package/dist/vision-tools-CQnBI9aa.js +51 -0
  152. package/dist/voice-transcription-CbQBToY0.js +138 -0
  153. package/dist/voice-transcription-CgWq54hn.js +138 -0
  154. package/dist/website-watch-tools-Bk_TnwuE.js +5 -0
  155. package/dist/website-watch-tools-DraMPxdl.js +139 -0
  156. 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,167 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const chalk = require_chunk.__toESM(require("chalk"));
3
+ const fs_extra = require_chunk.__toESM(require("fs-extra"));
4
+ const path = require_chunk.__toESM(require("path"));
5
+ const os = require_chunk.__toESM(require("os"));
6
+ const https = require_chunk.__toESM(require("https"));
7
+ const events = require_chunk.__toESM(require("events"));
8
+
9
+ //#region extensions/zalo-personal/src/connector.ts
10
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "zalo-personal-state.json");
11
+ function zaloWebReq(cookie, 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: "chat.zalo.me",
16
+ port: 443,
17
+ path: `/api${endpoint}`,
18
+ method,
19
+ headers: {
20
+ "Cookie": cookie,
21
+ "Referer": "https://chat.zalo.me/",
22
+ "User-Agent": "Mozilla/5.0 (compatible; HyperClaw/4.0)",
23
+ ...payload ? {
24
+ "Content-Type": "application/json",
25
+ "Content-Length": Buffer.byteLength(payload)
26
+ } : {}
27
+ }
28
+ }, (res) => {
29
+ let data = "";
30
+ res.on("data", (c) => data += c);
31
+ res.on("end", () => {
32
+ try {
33
+ resolve(JSON.parse(data));
34
+ } catch {
35
+ resolve({ raw: data });
36
+ }
37
+ });
38
+ });
39
+ req.on("error", reject);
40
+ if (payload) req.write(payload);
41
+ req.end();
42
+ });
43
+ }
44
+ var ZaloPersonalConnector = class extends events.EventEmitter {
45
+ config;
46
+ running = false;
47
+ ws = null;
48
+ userId = "";
49
+ constructor(config) {
50
+ super();
51
+ this.config = {
52
+ imei: require("crypto").randomUUID(),
53
+ dmPolicy: "allowlist",
54
+ allowFrom: [],
55
+ approvedPairings: [],
56
+ pendingPairings: {},
57
+ ...config
58
+ };
59
+ }
60
+ async connect() {
61
+ const profile = await zaloWebReq(this.config.cookie, "GET", "/profile");
62
+ this.userId = profile?.data?.userId || profile?.userId || "";
63
+ await this.loadState();
64
+ this.running = true;
65
+ console.log(chalk.default.green(` 🦅 Zalo Personal: ${profile?.data?.displayName || this.userId} connected`));
66
+ this.emit("connected", { userId: this.userId });
67
+ this.startPolling();
68
+ }
69
+ async startPolling() {
70
+ while (this.running) try {
71
+ const msgs = await zaloWebReq(this.config.cookie, "GET", `/message/fetchlatestmsg?last_msg_id=0&limit=20`);
72
+ for (const msg of msgs?.data?.msgs || []) {
73
+ if (msg.fromUid === this.userId) continue;
74
+ if (!msg.msgId || !msg.content) continue;
75
+ const from = msg.fromUid;
76
+ const text = msg.content;
77
+ const allowed = await this.checkDMPolicy(from, text);
78
+ if (!allowed) continue;
79
+ this.emit("message", {
80
+ id: msg.msgId,
81
+ channelId: "zalo-personal",
82
+ from,
83
+ chatId: msg.toUid || from,
84
+ text,
85
+ timestamp: new Date(parseInt(msg.ts || "0")).toISOString(),
86
+ isDM: true
87
+ });
88
+ }
89
+ await new Promise((r) => setTimeout(r, 3e3));
90
+ } catch (e) {
91
+ if (this.running) {
92
+ console.log(chalk.default.yellow(` ⚠ Zalo Personal: ${e.message}`));
93
+ await new Promise((r) => setTimeout(r, 5e3));
94
+ }
95
+ }
96
+ }
97
+ async checkDMPolicy(from, text) {
98
+ if (this.config.dmPolicy === "none") return false;
99
+ if (this.config.dmPolicy === "open") return true;
100
+ if (this.config.dmPolicy === "allowlist") {
101
+ if (this.config.allowFrom.includes(from)) return true;
102
+ await this.sendMessage(from, "🦅 HyperClaw: Not on allowlist.");
103
+ return false;
104
+ }
105
+ if (this.config.dmPolicy === "pairing") {
106
+ if (this.config.approvedPairings.includes(from)) return true;
107
+ const upper = text.trim().toUpperCase();
108
+ if (this.config.pendingPairings[upper]) {
109
+ this.config.approvedPairings.push(from);
110
+ delete this.config.pendingPairings[upper];
111
+ await this.saveState();
112
+ await this.sendMessage(from, "🦅 Paired!");
113
+ this.emit("pairing:approved", {
114
+ userId: from,
115
+ channelId: "zalo-personal"
116
+ });
117
+ return true;
118
+ }
119
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
120
+ this.config.pendingPairings[code] = from;
121
+ await this.saveState();
122
+ await this.sendMessage(from, `🦅 Mã ghép đôi: ${code}\nXác nhận: hyperclaw pairing approve zalo-personal ${code}`);
123
+ return false;
124
+ }
125
+ return false;
126
+ }
127
+ async sendMessage(toUid, text) {
128
+ await zaloWebReq(this.config.cookie, "POST", "/message/sendmsg", {
129
+ toid: toUid,
130
+ msg: text.slice(0, 2e3),
131
+ imei: this.config.imei,
132
+ type: 1
133
+ });
134
+ }
135
+ disconnect() {
136
+ this.running = false;
137
+ this.ws?.close();
138
+ }
139
+ approvePairing(code) {
140
+ const upper = code.toUpperCase();
141
+ if (!this.config.pendingPairings[upper]) return false;
142
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
143
+ delete this.config.pendingPairings[upper];
144
+ this.saveState();
145
+ return true;
146
+ }
147
+ async loadState() {
148
+ try {
149
+ const s = await fs_extra.default.readJson(STATE_FILE);
150
+ if (s.p) this.config.pendingPairings = s.p;
151
+ if (s.a) this.config.approvedPairings = s.a;
152
+ } catch {}
153
+ }
154
+ async saveState() {
155
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
156
+ await fs_extra.default.writeJson(STATE_FILE, {
157
+ p: this.config.pendingPairings,
158
+ a: this.config.approvedPairings
159
+ }, { spaces: 2 });
160
+ }
161
+ isRunning() {
162
+ return this.running;
163
+ }
164
+ };
165
+
166
+ //#endregion
167
+ exports.ZaloPersonalConnector = ZaloPersonalConnector;
@@ -0,0 +1,189 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const chalk = require_chunk.__toESM(require("chalk"));
3
+ const fs_extra = require_chunk.__toESM(require("fs-extra"));
4
+ const path = require_chunk.__toESM(require("path"));
5
+ const os = require_chunk.__toESM(require("os"));
6
+ const https = require_chunk.__toESM(require("https"));
7
+ const events = require_chunk.__toESM(require("events"));
8
+
9
+ //#region extensions/msteams/src/connector.ts
10
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "msteams-state.json");
11
+ let cachedToken = null;
12
+ async function getBotToken(appId, appPassword) {
13
+ if (cachedToken && cachedToken.expiresAt > Date.now() + 6e4) return cachedToken.token;
14
+ return new Promise((resolve, reject) => {
15
+ const body = `grant_type=client_credentials&client_id=${encodeURIComponent(appId)}&client_secret=${encodeURIComponent(appPassword)}&scope=https%3A%2F%2Fapi.botframework.com%2F.default`;
16
+ const req = https.default.request({
17
+ hostname: "login.microsoftonline.com",
18
+ port: 443,
19
+ path: "/botframework.com/oauth2/v2.0/token",
20
+ method: "POST",
21
+ headers: {
22
+ "Content-Type": "application/x-www-form-urlencoded",
23
+ "Content-Length": Buffer.byteLength(body)
24
+ }
25
+ }, (res) => {
26
+ let data = "";
27
+ res.on("data", (c) => data += c);
28
+ res.on("end", () => {
29
+ try {
30
+ const r = JSON.parse(data);
31
+ cachedToken = {
32
+ token: r.access_token,
33
+ expiresAt: Date.now() + r.expires_in * 1e3
34
+ };
35
+ resolve(r.access_token);
36
+ } catch {
37
+ reject(new Error("Token parse error"));
38
+ }
39
+ });
40
+ });
41
+ req.on("error", reject);
42
+ req.write(body);
43
+ req.end();
44
+ });
45
+ }
46
+ async function sendActivity(token, serviceUrl, conversationId, activity) {
47
+ const url = new URL(`${serviceUrl}v3/conversations/${conversationId}/activities`);
48
+ return new Promise((resolve, reject) => {
49
+ const payload = JSON.stringify(activity);
50
+ const req = https.default.request({
51
+ hostname: url.hostname,
52
+ port: 443,
53
+ path: url.pathname,
54
+ method: "POST",
55
+ headers: {
56
+ "Authorization": `Bearer ${token}`,
57
+ "Content-Type": "application/json",
58
+ "Content-Length": Buffer.byteLength(payload)
59
+ }
60
+ }, (res) => {
61
+ res.on("data", () => {});
62
+ res.on("end", resolve);
63
+ });
64
+ req.on("error", reject);
65
+ req.write(payload);
66
+ req.end();
67
+ });
68
+ }
69
+ var MSTeamsConnector = class extends events.EventEmitter {
70
+ config;
71
+ running = false;
72
+ constructor(config) {
73
+ super();
74
+ this.config = {
75
+ dmPolicy: "allowlist",
76
+ allowFrom: [],
77
+ approvedPairings: [],
78
+ pendingPairings: {},
79
+ ...config
80
+ };
81
+ }
82
+ async connect() {
83
+ await getBotToken(this.config.appId, this.config.appPassword);
84
+ await this.loadState();
85
+ this.running = true;
86
+ console.log(chalk.default.green(` 🦅 MS Teams: Bot ${this.config.appId} connected`));
87
+ this.emit("connected", { appId: this.config.appId });
88
+ }
89
+ disconnect() {
90
+ this.running = false;
91
+ }
92
+ async handleWebhook(body) {
93
+ let activity;
94
+ try {
95
+ activity = JSON.parse(body);
96
+ } catch {
97
+ return;
98
+ }
99
+ if (activity.type !== "message") return;
100
+ const from = activity.from?.aadObjectId || activity.from?.id;
101
+ const text = activity.text?.replace(/<at>[^<]+<\/at>/g, "").trim();
102
+ const serviceUrl = activity.serviceUrl;
103
+ const conversationId = activity.conversation?.id;
104
+ if (!from || !text || !serviceUrl || !conversationId) return;
105
+ const allowed = await this.checkDMPolicy(from, text, serviceUrl, conversationId, activity);
106
+ if (!allowed) return;
107
+ this.emit("message", {
108
+ id: activity.id,
109
+ channelId: "msteams",
110
+ from,
111
+ chatId: conversationId,
112
+ fromName: activity.from?.name,
113
+ text,
114
+ timestamp: activity.timestamp || (/* @__PURE__ */ new Date()).toISOString(),
115
+ isDM: activity.conversation?.conversationType === "personal",
116
+ serviceUrl,
117
+ activity
118
+ });
119
+ }
120
+ async checkDMPolicy(from, text, serviceUrl, convId, activity) {
121
+ if (this.config.dmPolicy === "none") return false;
122
+ if (this.config.dmPolicy === "open") return true;
123
+ if (this.config.dmPolicy === "allowlist") {
124
+ if (this.config.allowFrom.includes(from)) return true;
125
+ await this.reply(serviceUrl, convId, activity, "🦅 HyperClaw: Not on allowlist.");
126
+ return false;
127
+ }
128
+ if (this.config.dmPolicy === "pairing") {
129
+ if (this.config.approvedPairings.includes(from)) return true;
130
+ const upper = text.trim().toUpperCase();
131
+ if (this.config.pendingPairings[upper]) {
132
+ this.config.approvedPairings.push(from);
133
+ delete this.config.pendingPairings[upper];
134
+ await this.saveState();
135
+ await this.reply(serviceUrl, convId, activity, "🦅 Paired!");
136
+ this.emit("pairing:approved", {
137
+ userId: from,
138
+ channelId: "msteams"
139
+ });
140
+ return true;
141
+ }
142
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
143
+ this.config.pendingPairings[code] = from;
144
+ await this.saveState();
145
+ await this.reply(serviceUrl, convId, activity, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve msteams ${code}`);
146
+ return false;
147
+ }
148
+ return false;
149
+ }
150
+ async reply(serviceUrl, conversationId, originalActivity, text) {
151
+ const token = await getBotToken(this.config.appId, this.config.appPassword);
152
+ await sendActivity(token, serviceUrl, conversationId, {
153
+ type: "message",
154
+ text: text.slice(0, 4e3),
155
+ replyToId: originalActivity.id,
156
+ from: { id: this.config.appId },
157
+ conversation: originalActivity.conversation,
158
+ recipient: originalActivity.from
159
+ });
160
+ }
161
+ approvePairing(code) {
162
+ const upper = code.toUpperCase();
163
+ if (!this.config.pendingPairings[upper]) return false;
164
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
165
+ delete this.config.pendingPairings[upper];
166
+ this.saveState();
167
+ return true;
168
+ }
169
+ async loadState() {
170
+ try {
171
+ const s = await fs_extra.default.readJson(STATE_FILE);
172
+ if (s.p) this.config.pendingPairings = s.p;
173
+ if (s.a) this.config.approvedPairings = s.a;
174
+ } catch {}
175
+ }
176
+ async saveState() {
177
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
178
+ await fs_extra.default.writeJson(STATE_FILE, {
179
+ p: this.config.pendingPairings,
180
+ a: this.config.approvedPairings
181
+ }, { spaces: 2 });
182
+ }
183
+ isRunning() {
184
+ return this.running;
185
+ }
186
+ };
187
+
188
+ //#endregion
189
+ exports.MSTeamsConnector = MSTeamsConnector;
@@ -0,0 +1,181 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const chalk = require_chunk.__toESM(require("chalk"));
3
+ const fs_extra = require_chunk.__toESM(require("fs-extra"));
4
+ const path = require_chunk.__toESM(require("path"));
5
+ const os = require_chunk.__toESM(require("os"));
6
+ const http = require_chunk.__toESM(require("http"));
7
+ const ws = require_chunk.__toESM(require("ws"));
8
+ const https = require_chunk.__toESM(require("https"));
9
+ const events = require_chunk.__toESM(require("events"));
10
+
11
+ //#region extensions/bluebubbles/src/connector.ts
12
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "bluebubbles-state.json");
13
+ function bbReq(serverUrl, password, method, endpoint, body) {
14
+ return new Promise((resolve, reject) => {
15
+ const url = new URL(`${serverUrl}/api/v1${endpoint}`);
16
+ url.searchParams.set("password", password);
17
+ const isHttps = url.protocol === "https:";
18
+ const mod = isHttps ? https.default : http.default;
19
+ const payload = body ? JSON.stringify(body) : null;
20
+ const req = mod.request({
21
+ hostname: url.hostname,
22
+ port: url.port || (isHttps ? 443 : 1234),
23
+ path: url.pathname + url.search,
24
+ method,
25
+ headers: payload ? {
26
+ "Content-Type": "application/json",
27
+ "Content-Length": Buffer.byteLength(payload)
28
+ } : {},
29
+ rejectUnauthorized: false
30
+ }, (res) => {
31
+ let data = "";
32
+ res.on("data", (c) => data += c);
33
+ res.on("end", () => {
34
+ try {
35
+ const r = JSON.parse(data);
36
+ if (r.status !== 200) reject(new Error(r.error?.message || "BB error"));
37
+ else resolve(r.data);
38
+ } catch {
39
+ reject(new Error("Invalid JSON"));
40
+ }
41
+ });
42
+ });
43
+ req.on("error", reject);
44
+ if (payload) req.write(payload);
45
+ req.end();
46
+ });
47
+ }
48
+ var BlueBubblesConnector = class extends events.EventEmitter {
49
+ config;
50
+ running = false;
51
+ ws = null;
52
+ lastMessageTs = 0;
53
+ constructor(config) {
54
+ super();
55
+ this.config = {
56
+ dmPolicy: "allowlist",
57
+ allowFrom: [],
58
+ approvedPairings: [],
59
+ pendingPairings: {},
60
+ ...config
61
+ };
62
+ }
63
+ async connect() {
64
+ const info = await bbReq(this.config.serverUrl, this.config.password, "GET", "/server/info");
65
+ await this.loadState();
66
+ this.running = true;
67
+ console.log(chalk.default.green(` 🦅 BlueBubbles (iMessage): ${info?.os_version || "macOS"} server connected`));
68
+ this.emit("connected", { serverInfo: info });
69
+ this.connectWebSocket();
70
+ }
71
+ connectWebSocket() {
72
+ const url = new URL(this.config.serverUrl);
73
+ const wsUrl = `${url.protocol === "https:" ? "wss" : "ws"}://${url.hostname}:${url.port || 1234}`;
74
+ this.ws = new ws.WebSocket(`${wsUrl}?password=${encodeURIComponent(this.config.password)}`, { rejectUnauthorized: false });
75
+ this.ws.on("message", async (data) => {
76
+ try {
77
+ const event = JSON.parse(data.toString());
78
+ if (event.type === "new-message" || event.type === "updated-message") await this.handleMessage(event.data);
79
+ } catch {}
80
+ });
81
+ this.ws.on("close", () => {
82
+ if (this.running) setTimeout(() => this.connectWebSocket(), 5e3);
83
+ });
84
+ this.ws.on("error", () => {});
85
+ setInterval(() => {
86
+ if (this.ws?.readyState === ws.WebSocket.OPEN) this.ws.send(JSON.stringify({ type: "ping" }));
87
+ }, 3e4);
88
+ }
89
+ async handleMessage(msg) {
90
+ if (!msg || msg.isFromMe) return;
91
+ const text = msg.text;
92
+ const from = msg.handle?.address;
93
+ if (!text || !from) return;
94
+ const ts = msg.dateCreated || 0;
95
+ if (ts <= this.lastMessageTs) return;
96
+ this.lastMessageTs = ts;
97
+ await this.saveState();
98
+ const allowed = await this.checkDMPolicy(from, text);
99
+ if (!allowed) return;
100
+ this.emit("message", {
101
+ id: msg.guid,
102
+ channelId: "bluebubbles",
103
+ from,
104
+ chatId: msg.chats?.[0]?.guid || from,
105
+ text,
106
+ timestamp: new Date(ts).toISOString(),
107
+ isDM: !msg.isGroup
108
+ });
109
+ }
110
+ async checkDMPolicy(from, text) {
111
+ if (this.config.dmPolicy === "none") return false;
112
+ if (this.config.dmPolicy === "open") return true;
113
+ if (this.config.dmPolicy === "allowlist") {
114
+ if (this.config.allowFrom.includes(from)) return true;
115
+ await this.sendMessage(from, "🦅 HyperClaw: Not on allowlist.");
116
+ return false;
117
+ }
118
+ if (this.config.dmPolicy === "pairing") {
119
+ if (this.config.approvedPairings.includes(from)) return true;
120
+ const upper = text.trim().toUpperCase();
121
+ if (this.config.pendingPairings[upper]) {
122
+ this.config.approvedPairings.push(from);
123
+ delete this.config.pendingPairings[upper];
124
+ await this.saveState();
125
+ await this.sendMessage(from, "🦅 Paired!");
126
+ this.emit("pairing:approved", {
127
+ userId: from,
128
+ channelId: "bluebubbles"
129
+ });
130
+ return true;
131
+ }
132
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
133
+ this.config.pendingPairings[code] = from;
134
+ await this.saveState();
135
+ await this.sendMessage(from, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve bluebubbles ${code}`);
136
+ return false;
137
+ }
138
+ return false;
139
+ }
140
+ async sendMessage(address, text) {
141
+ await bbReq(this.config.serverUrl, this.config.password, "POST", "/message/text", {
142
+ chatGuid: `iMessage;-;${address}`,
143
+ message: text.slice(0, 65536),
144
+ method: "apple-script"
145
+ });
146
+ }
147
+ disconnect() {
148
+ this.running = false;
149
+ this.ws?.close();
150
+ }
151
+ approvePairing(code) {
152
+ const upper = code.toUpperCase();
153
+ if (!this.config.pendingPairings[upper]) return false;
154
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
155
+ delete this.config.pendingPairings[upper];
156
+ this.saveState();
157
+ return true;
158
+ }
159
+ async loadState() {
160
+ try {
161
+ const s = await fs_extra.default.readJson(STATE_FILE);
162
+ this.lastMessageTs = s.lastTs || 0;
163
+ if (s.p) this.config.pendingPairings = s.p;
164
+ if (s.a) this.config.approvedPairings = s.a;
165
+ } catch {}
166
+ }
167
+ async saveState() {
168
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
169
+ await fs_extra.default.writeJson(STATE_FILE, {
170
+ lastTs: this.lastMessageTs,
171
+ p: this.config.pendingPairings,
172
+ a: this.config.approvedPairings
173
+ }, { spaces: 2 });
174
+ }
175
+ isRunning() {
176
+ return this.running;
177
+ }
178
+ };
179
+
180
+ //#endregion
181
+ exports.BlueBubblesConnector = BlueBubblesConnector;