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.
- package/LICENSE +2 -1
- package/README.md +449 -99
- package/dist/a2ui-protocol-Gzm29Gaw.js +75 -0
- package/dist/agents-routing-Biy5ew4a.js +4 -0
- package/dist/agents-routing-CL3HQNoM.js +327 -0
- package/dist/api-keys-guide-CGn5BSF7.js +149 -0
- package/dist/api-keys-guide-ChbThbPj.js +149 -0
- package/dist/audit-BJohI_vC.js +441 -0
- package/dist/audit-NPIMmOSq.js +441 -0
- package/dist/bounty-tools-BUqUKjt0.js +211 -0
- package/dist/bounty-tools-CY_i91DU.js +211 -0
- package/dist/browser-tools-CxJY6pAn.js +5 -0
- package/dist/browser-tools-JZ9ji6AW.js +179 -0
- package/dist/chat-qVuqhlPu.js +258 -0
- package/dist/claw-tasks-B-8RRMdq.js +80 -0
- package/dist/claw-tasks-Cyzdbhz_.js +80 -0
- package/dist/connector-1x1rCBHz.js +162 -0
- package/dist/connector-B4jeCULG.js +305 -0
- package/dist/connector-B7qngfkT.js +286 -0
- package/dist/connector-B8BK0GBo.js +531 -0
- package/dist/connector-BE9eJs8-.js +182 -0
- package/dist/connector-BEe-DTGQ.js +189 -0
- package/dist/connector-BU7p5ZgB.js +167 -0
- package/dist/connector-BUzzq7Ij.js +568 -0
- package/dist/connector-BpDqLgnW.js +419 -0
- package/dist/connector-BpW88ut2.js +189 -0
- package/dist/connector-Bxv-gy8U.js +167 -0
- package/dist/connector-Bz14zcJv.js +213 -0
- package/dist/connector-C1zP5-5q.js +85 -0
- package/dist/connector-CAcpcovF.js +498 -0
- package/dist/connector-CJgVjS58.js +181 -0
- package/dist/connector-Cf53D6qV.js +425 -0
- package/dist/connector-CyHmlbNz.js +508 -0
- package/dist/connector-D22mJGVu.js +340 -0
- package/dist/connector-D6RtMmlL.js +225 -0
- package/dist/connector-D9EnT8A4.js +280 -0
- package/dist/connector-DNDwIh37.js +239 -0
- package/dist/connector-Di27MeO4.js +350 -0
- package/dist/connector-Do0BPiHt.js +194 -0
- package/dist/connector-DvLwOfJy.js +192 -0
- package/dist/connector-DvU83NSq.js +181 -0
- package/dist/connector-DxskpDc_.js +173 -0
- package/dist/connector-byy3eISx.js +552 -0
- package/dist/connector-vV89hsyd.js +218 -0
- package/dist/cost-tracker-Ca1UPZ33.js +103 -0
- package/dist/cost-tracker-fnaj_6M9.js +103 -0
- package/dist/credentials-store-BxijEirw.js +77 -0
- package/dist/credentials-store-CA8UtK0T.js +77 -0
- package/dist/credentials-store-CPkVO6-z.js +4 -0
- package/dist/credentials-store-Cm7DH-kh.js +4 -0
- package/dist/cron-tasks-L0mz1yyU.js +82 -0
- package/dist/cron-tasks-_pqQCmxc.js +82 -0
- package/dist/daemon-7ViroziB.js +5 -0
- package/dist/daemon-BfyKmZhr.js +318 -0
- package/dist/daemon-CNyunwkR.js +5 -0
- package/dist/daemon-CindY8OK.js +318 -0
- package/dist/delivery-DVHmv1IR.js +4 -0
- package/dist/delivery-DgiZcJBp.js +4 -0
- package/dist/delivery-DpMX0Yyc.js +95 -0
- package/dist/delivery-otAU4alM.js +95 -0
- package/dist/destructive-gate-CA0DtA5K.js +101 -0
- package/dist/destructive-gate-DZt71UZR.js +101 -0
- package/dist/developer-keys-Cnd1kswV.js +127 -0
- package/dist/developer-keys-DENo3ZA6.js +8 -0
- package/dist/doctor-Dgjoc3DG.js +230 -0
- package/dist/doctor-RwsOhtAl.js +6 -0
- package/dist/engine-B0kLfRL0.js +256 -0
- package/dist/engine-BJUpRUOv.js +7 -0
- package/dist/engine-D_VeoZHw.js +305 -0
- package/dist/engine-JjRnhlsE.js +7 -0
- package/dist/env-resolve-17ekEU6p.js +10 -0
- package/dist/env-resolve-BFJXWl94.js +115 -0
- package/dist/env-resolve-Z2XF6leB.js +115 -0
- package/dist/env-resolve-bDYssfih.js +10 -0
- package/dist/extraction-tools-DbxnxIco.js +5 -0
- package/dist/extraction-tools-Dg7AHS35.js +91 -0
- package/dist/form_data-CGAy4HE0.js +8657 -0
- package/dist/gmail-watch-setup-C3uSWznp.js +40 -0
- package/dist/health-DUjluWHQ.js +6 -0
- package/dist/health-DVfkpUQW.js +152 -0
- package/dist/heartbeat-engine-CrgL4mrP.js +83 -0
- package/dist/heartbeat-engine-Ut6pXBD6.js +83 -0
- package/dist/hub-9LaKnLjY.js +6 -0
- package/dist/hub-BO6bj8Yj.js +515 -0
- package/dist/hub-Bu52YZqW.js +6 -0
- package/dist/hub-CfwUz9YW.js +515 -0
- package/dist/hyperclawbot-BrcoYLOp.js +505 -0
- package/dist/hyperclawbot-CBiDSKsa.js +505 -0
- package/dist/inference-0mlFQqIm.js +922 -0
- package/dist/inference-DHR82Gh7.js +6 -0
- package/dist/inference-DhA8jpfH.js +2692 -0
- package/dist/inference-SzqFe_nk.js +6 -0
- package/dist/knowledge-graph-BrYpSgxW.js +131 -0
- package/dist/knowledge-graph-DE5lSF02.js +131 -0
- package/dist/loader-9JqY6Nlq.js +4 -0
- package/dist/loader-BkDi8MD9.js +400 -0
- package/dist/loader-Cjdd1kw4.js +400 -0
- package/dist/loader-DI2qDRPC.js +4 -0
- package/dist/logger-Cp8wC7F8.js +83 -0
- package/dist/logger-DCT2l9GV.js +83 -0
- package/dist/manager-3cq3DydI.js +4 -0
- package/dist/manager-B2Gls5RG.js +218 -0
- package/dist/manager-BUrFrPuq.js +117 -0
- package/dist/manager-Bi9UYyVR.js +105 -0
- package/dist/manager-Biz9ixWJ.js +40 -0
- package/dist/manager-CBUHJiY7.js +6 -0
- package/dist/manager-CVLLaKmq.js +218 -0
- package/dist/manager-CWNSML5D.js +117 -0
- package/dist/manager-SJe9gt-q.js +4 -0
- package/dist/mcp-CUoTCMw-.js +139 -0
- package/dist/mcp-loader-BIz-450x.js +94 -0
- package/dist/mcp-loader-CvxRDtPC.js +94 -0
- package/dist/memory-OL77OMOr.js +270 -0
- package/dist/memory-auto-CpQHZlEJ.js +306 -0
- package/dist/memory-auto-D-L2q21G.js +306 -0
- package/dist/memory-auto-DTcy5VBy.js +5 -0
- package/dist/memory-auto-Z6LCf-iK.js +5 -0
- package/dist/memory-gUi4VaIf.js +4 -0
- package/dist/memory-integration-B8RSN4pr.js +91 -0
- package/dist/memory-integration-g2vxwgoE.js +91 -0
- package/dist/moltbook-B-40gQOL.js +81 -0
- package/dist/moltbook-Cl8cQfxJ.js +81 -0
- package/dist/node-TWxRm84k.js +222 -0
- package/dist/nodes-registry-C9dCFwjh.js +52 -0
- package/dist/nodes-registry-DKRtsbNg.js +52 -0
- package/dist/oauth-flow-CeaaGAz0.js +150 -0
- package/dist/oauth-flow-JCfporKq.js +150 -0
- package/dist/oauth-provider-4R0EJlsT.js +110 -0
- package/dist/oauth-provider-B4dzn56l.js +110 -0
- package/dist/observability-CDZmeHfa.js +89 -0
- package/dist/observability-nZ3CBIxG.js +89 -0
- package/dist/onboard-BBBWcfhp.js +10 -0
- package/dist/onboard-BVOtKQdh.js +3641 -0
- package/dist/onboard-Bw28IRQ3.js +4070 -0
- package/dist/onboard-CGNIw27w.js +11 -0
- package/dist/orchestrator-BovkM63z.js +6 -0
- package/dist/orchestrator-CcKx1Ovk.js +189 -0
- package/dist/orchestrator-DSbpkP1X.js +189 -0
- package/dist/orchestrator-DcFfDLTX.js +6 -0
- package/dist/osint-B4_m3VHQ.js +277 -0
- package/dist/osint-B6BZKQAD.js +277 -0
- package/dist/pairing-B6RArWhD.js +196 -0
- package/dist/pairing-BsQ08DLq.js +4 -0
- package/dist/pc-access-B0KocJNe.js +819 -0
- package/dist/pc-access-DkzmugZ7.js +8 -0
- package/dist/pending-approval-BgNjjuI2.js +22 -0
- package/dist/pending-approval-C_HkX1QL.js +22 -0
- package/dist/providers-DxiamZSL.js +5 -0
- package/dist/providers-Dy15rDb7.js +657 -0
- package/dist/reminders-store-CzUY0zYx.js +58 -0
- package/dist/renderer-ANNfXsHn.js +225 -0
- package/dist/rules-BSQwwAYC.js +103 -0
- package/dist/run-main.js +142 -132
- package/dist/runner-BHRSOPEU.js +1271 -0
- package/dist/runner-CJFJUtPm.js +1271 -0
- package/dist/sdk/index.js +2 -2
- package/dist/sdk/index.mjs +2 -2
- package/dist/security--oQObeJO.js +4 -0
- package/dist/security-wBOg0TA8.js +73 -0
- package/dist/server-Brl_HQUB.js +1255 -0
- package/dist/server-CbTTpB5m.js +1255 -0
- package/dist/server-DP_bPzvI.js +4 -0
- package/dist/server-DhfipkwN.js +4 -0
- package/dist/session-store-B09r5HgB.js +5 -0
- package/dist/session-store-DCTQIVur.js +113 -0
- package/dist/sessions-tools-BdlN6Pb6.js +95 -0
- package/dist/sessions-tools-JVLDKSJ_.js +5 -0
- package/dist/skill-loader-B5oeliGu.js +7 -0
- package/dist/skill-loader-Wf3brNOj.js +160 -0
- package/dist/skill-runtime-BGlvly2s.js +102 -0
- package/dist/skill-runtime-BXWd-Ktf.js +102 -0
- package/dist/skill-runtime-DhL2T76p.js +5 -0
- package/dist/skill-runtime-jgklm02e.js +5 -0
- package/dist/src-BbPa6Q8p.js +63 -0
- package/dist/src-BeXtfkK2.js +458 -0
- package/dist/src-Bhybpk1J.js +63 -0
- package/dist/src-CGQjRI4N.js +20 -0
- package/dist/src-DMJ4-uqk.js +458 -0
- package/dist/sub-agent-tools-CmE345s_.js +39 -0
- package/dist/sub-agent-tools-DHY-4WWM.js +39 -0
- package/dist/theme-D0smfC_l.js +8 -0
- package/dist/theme-DajRRZbA.js +180 -0
- package/dist/tool-policy-DZvF8xlQ.js +189 -0
- package/dist/tool-policy-DgNqFWYn.js +189 -0
- package/dist/tts-elevenlabs-C06nUxMK.js +61 -0
- package/dist/tts-elevenlabs-JeFaGNJU.js +61 -0
- package/dist/update-check-BVEqHhFY.js +83 -0
- package/dist/update-check-w4XuxVl7.js +81 -0
- package/dist/vision-JOtOS1Br.js +121 -0
- package/dist/vision-fky3elEo.js +121 -0
- package/dist/vision-tools-C8B3776g.js +5 -0
- package/dist/vision-tools-CB28ZCO_.js +5 -0
- package/dist/vision-tools-dwn9p4el.js +51 -0
- package/dist/vision-tools-vPPwQ-0N.js +51 -0
- package/dist/voice-transcription-B6RtplmN.js +138 -0
- package/dist/voice-transcription-DBo5hXmu.js +138 -0
- package/dist/website-watch-tools-B-jRAeTe.js +139 -0
- package/dist/website-watch-tools-BC9xAL67.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,192 @@
|
|
|
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 ws = require_chunk.__toESM(require("ws"));
|
|
8
|
+
const events = require_chunk.__toESM(require("events"));
|
|
9
|
+
|
|
10
|
+
//#region extensions/nostr/src/connector.ts
|
|
11
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "nostr-state.json");
|
|
12
|
+
function getPublicKey(privKeyHex) {
|
|
13
|
+
const privKey = Buffer.from(privKeyHex, "hex");
|
|
14
|
+
const ec = crypto.default.createECDH("prime256v1");
|
|
15
|
+
return crypto.default.createHash("sha256").update(privKey).digest("hex");
|
|
16
|
+
}
|
|
17
|
+
function signEvent(event, privKeyHex) {
|
|
18
|
+
const payload = JSON.stringify(event);
|
|
19
|
+
return crypto.default.createHmac("sha256", Buffer.from(privKeyHex, "hex")).update(payload).digest("hex");
|
|
20
|
+
}
|
|
21
|
+
function nip04Decrypt(privKeyHex, senderPubKey, ciphertext) {
|
|
22
|
+
try {
|
|
23
|
+
const [encrypted, iv] = ciphertext.split("?iv=");
|
|
24
|
+
const sharedSecret = crypto.default.createHash("sha256").update(Buffer.from(privKeyHex + senderPubKey, "hex")).digest();
|
|
25
|
+
const decipher = crypto.default.createDecipheriv("aes-256-cbc", sharedSecret, Buffer.from(iv, "base64"));
|
|
26
|
+
return decipher.update(encrypted, "base64", "utf8") + decipher.final("utf8");
|
|
27
|
+
} catch {
|
|
28
|
+
return ciphertext;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function nip04Encrypt(privKeyHex, recipientPubKey, plaintext) {
|
|
32
|
+
const sharedSecret = crypto.default.createHash("sha256").update(Buffer.from(privKeyHex + recipientPubKey, "hex")).digest();
|
|
33
|
+
const iv = crypto.default.randomBytes(16);
|
|
34
|
+
const cipher = crypto.default.createCipheriv("aes-256-cbc", sharedSecret, iv);
|
|
35
|
+
const encrypted = cipher.update(plaintext, "utf8", "base64") + cipher.final("base64");
|
|
36
|
+
return `${encrypted}?iv=${iv.toString("base64")}`;
|
|
37
|
+
}
|
|
38
|
+
var NostrConnector = class extends events.EventEmitter {
|
|
39
|
+
config;
|
|
40
|
+
sockets = /* @__PURE__ */ new Map();
|
|
41
|
+
running = false;
|
|
42
|
+
pubKey;
|
|
43
|
+
seenEventIds = /* @__PURE__ */ new Set();
|
|
44
|
+
constructor(config) {
|
|
45
|
+
super();
|
|
46
|
+
this.config = {
|
|
47
|
+
relays: [
|
|
48
|
+
"wss://relay.damus.io",
|
|
49
|
+
"wss://nos.lol",
|
|
50
|
+
"wss://relay.nostr.band"
|
|
51
|
+
],
|
|
52
|
+
dmPolicy: "open",
|
|
53
|
+
allowFrom: [],
|
|
54
|
+
approvedPairings: [],
|
|
55
|
+
pendingPairings: {},
|
|
56
|
+
...config
|
|
57
|
+
};
|
|
58
|
+
this.pubKey = getPublicKey(this.config.privateKeyHex);
|
|
59
|
+
}
|
|
60
|
+
async connect() {
|
|
61
|
+
await this.loadState();
|
|
62
|
+
for (const relay of this.config.relays) this.connectRelay(relay);
|
|
63
|
+
this.running = true;
|
|
64
|
+
console.log(chalk.default.green(` 🦅 Nostr: pubkey ${this.pubKey.slice(0, 16)}... connected to ${this.config.relays.length} relays`));
|
|
65
|
+
this.emit("connected", { pubKey: this.pubKey });
|
|
66
|
+
}
|
|
67
|
+
connectRelay(url) {
|
|
68
|
+
const ws$1 = new ws.WebSocket(url);
|
|
69
|
+
this.sockets.set(url, ws$1);
|
|
70
|
+
ws$1.on("open", () => {
|
|
71
|
+
ws$1.send(JSON.stringify([
|
|
72
|
+
"REQ",
|
|
73
|
+
`hc-${Date.now()}`,
|
|
74
|
+
{
|
|
75
|
+
kinds: [4],
|
|
76
|
+
"#p": [this.pubKey],
|
|
77
|
+
limit: 10
|
|
78
|
+
}
|
|
79
|
+
]));
|
|
80
|
+
});
|
|
81
|
+
ws$1.on("message", async (data) => {
|
|
82
|
+
try {
|
|
83
|
+
const msg = JSON.parse(data.toString());
|
|
84
|
+
if (msg[0] === "EVENT") await this.handleEvent(msg[2]);
|
|
85
|
+
} catch {}
|
|
86
|
+
});
|
|
87
|
+
ws$1.on("close", () => {
|
|
88
|
+
if (this.running) setTimeout(() => this.connectRelay(url), 5e3);
|
|
89
|
+
});
|
|
90
|
+
ws$1.on("error", () => {});
|
|
91
|
+
}
|
|
92
|
+
async handleEvent(event) {
|
|
93
|
+
if (event.kind !== 4) return;
|
|
94
|
+
if (event.pubkey === this.pubKey) return;
|
|
95
|
+
if (this.seenEventIds.has(event.id)) return;
|
|
96
|
+
this.seenEventIds.add(event.id);
|
|
97
|
+
const from = event.pubkey;
|
|
98
|
+
const text = nip04Decrypt(this.config.privateKeyHex, from, event.content);
|
|
99
|
+
const allowed = await this.checkDMPolicy(from, text);
|
|
100
|
+
if (!allowed) return;
|
|
101
|
+
this.emit("message", {
|
|
102
|
+
id: event.id,
|
|
103
|
+
channelId: "nostr",
|
|
104
|
+
from,
|
|
105
|
+
chatId: from,
|
|
106
|
+
text,
|
|
107
|
+
timestamp: new Date(event.created_at * 1e3).toISOString(),
|
|
108
|
+
isDM: true
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
async checkDMPolicy(from, text) {
|
|
112
|
+
if (this.config.dmPolicy === "none") return false;
|
|
113
|
+
if (this.config.dmPolicy === "open") return true;
|
|
114
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
115
|
+
if (this.config.allowFrom.includes(from)) return true;
|
|
116
|
+
await this.sendDM(from, "🦅 HyperClaw: Not on allowlist.");
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (this.config.dmPolicy === "pairing") {
|
|
120
|
+
if (this.config.approvedPairings.includes(from)) return true;
|
|
121
|
+
const upper = text.trim().toUpperCase();
|
|
122
|
+
if (this.config.pendingPairings[upper]) {
|
|
123
|
+
this.config.approvedPairings.push(from);
|
|
124
|
+
delete this.config.pendingPairings[upper];
|
|
125
|
+
await this.saveState();
|
|
126
|
+
await this.sendDM(from, "🦅 Paired!");
|
|
127
|
+
this.emit("pairing:approved", {
|
|
128
|
+
userId: from,
|
|
129
|
+
channelId: "nostr"
|
|
130
|
+
});
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
134
|
+
this.config.pendingPairings[code] = from;
|
|
135
|
+
await this.saveState();
|
|
136
|
+
await this.sendDM(from, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve nostr ${code}`);
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
async sendDM(recipientPubKey, text) {
|
|
142
|
+
const encrypted = nip04Encrypt(this.config.privateKeyHex, recipientPubKey, text);
|
|
143
|
+
const event = {
|
|
144
|
+
pubkey: this.pubKey,
|
|
145
|
+
created_at: Math.floor(Date.now() / 1e3),
|
|
146
|
+
kind: 4,
|
|
147
|
+
tags: [["p", recipientPubKey]],
|
|
148
|
+
content: encrypted
|
|
149
|
+
};
|
|
150
|
+
const sig = signEvent(event, this.config.privateKeyHex);
|
|
151
|
+
const fullEvent = {
|
|
152
|
+
...event,
|
|
153
|
+
id: sig,
|
|
154
|
+
sig
|
|
155
|
+
};
|
|
156
|
+
const msg = JSON.stringify(["EVENT", fullEvent]);
|
|
157
|
+
for (const ws$1 of this.sockets.values()) if (ws$1.readyState === ws.WebSocket.OPEN) ws$1.send(msg);
|
|
158
|
+
}
|
|
159
|
+
disconnect() {
|
|
160
|
+
this.running = false;
|
|
161
|
+
for (const ws$1 of this.sockets.values()) ws$1.close();
|
|
162
|
+
this.sockets.clear();
|
|
163
|
+
}
|
|
164
|
+
approvePairing(code) {
|
|
165
|
+
const upper = code.toUpperCase();
|
|
166
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
167
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
168
|
+
delete this.config.pendingPairings[upper];
|
|
169
|
+
this.saveState();
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
async loadState() {
|
|
173
|
+
try {
|
|
174
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
175
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
176
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
177
|
+
} catch {}
|
|
178
|
+
}
|
|
179
|
+
async saveState() {
|
|
180
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
181
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
182
|
+
p: this.config.pendingPairings,
|
|
183
|
+
a: this.config.approvedPairings
|
|
184
|
+
}, { spaces: 2 });
|
|
185
|
+
}
|
|
186
|
+
isRunning() {
|
|
187
|
+
return this.running;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
//#endregion
|
|
192
|
+
exports.NostrConnector = NostrConnector;
|
|
@@ -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;
|
|
@@ -0,0 +1,173 @@
|
|
|
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/messenger/src/connector.ts
|
|
11
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "messenger-state.json");
|
|
12
|
+
function fbReq(token, endpoint, body) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const payload = JSON.stringify(body);
|
|
15
|
+
const req = https.default.request({
|
|
16
|
+
hostname: "graph.facebook.com",
|
|
17
|
+
port: 443,
|
|
18
|
+
path: `/v18.0${endpoint}`,
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: {
|
|
21
|
+
"Authorization": `Bearer ${token}`,
|
|
22
|
+
"Content-Type": "application/json",
|
|
23
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
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
|
+
if (r.error) reject(new Error(r.error.message));
|
|
32
|
+
else resolve(r);
|
|
33
|
+
} catch {
|
|
34
|
+
reject(new Error("Invalid JSON"));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
req.on("error", reject);
|
|
39
|
+
req.write(payload);
|
|
40
|
+
req.end();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
var MessengerConnector = class extends events.EventEmitter {
|
|
44
|
+
config;
|
|
45
|
+
running = false;
|
|
46
|
+
processedIds = /* @__PURE__ */ new Set();
|
|
47
|
+
constructor(config) {
|
|
48
|
+
super();
|
|
49
|
+
this.config = {
|
|
50
|
+
dmPolicy: "allowlist",
|
|
51
|
+
allowFrom: [],
|
|
52
|
+
approvedPairings: [],
|
|
53
|
+
pendingPairings: {},
|
|
54
|
+
...config
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async connect() {
|
|
58
|
+
await this.loadState();
|
|
59
|
+
this.running = true;
|
|
60
|
+
console.log(chalk.default.green(` 🦅 Messenger: page ${this.config.pageId} connected`));
|
|
61
|
+
this.emit("connected", { pageId: this.config.pageId });
|
|
62
|
+
}
|
|
63
|
+
disconnect() {
|
|
64
|
+
this.running = false;
|
|
65
|
+
}
|
|
66
|
+
verifyWebhook(mode, token, challenge) {
|
|
67
|
+
return mode === "subscribe" && token === this.config.verifyToken ? challenge : null;
|
|
68
|
+
}
|
|
69
|
+
verifySignature(body, signature) {
|
|
70
|
+
const expected = "sha256=" + crypto.default.createHmac("sha256", this.config.appSecret).update(body).digest("hex");
|
|
71
|
+
try {
|
|
72
|
+
return crypto.default.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
|
|
73
|
+
} catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async handleWebhook(body, signature) {
|
|
78
|
+
if (signature && !this.verifySignature(body, signature)) {
|
|
79
|
+
console.log(chalk.default.yellow(" ⚠ Messenger: invalid signature"));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
let payload;
|
|
83
|
+
try {
|
|
84
|
+
payload = JSON.parse(body);
|
|
85
|
+
} catch {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
for (const entry of payload.entry || []) for (const messaging of entry.messaging || []) {
|
|
89
|
+
if (!messaging.message || messaging.message.is_echo) continue;
|
|
90
|
+
const msgId = messaging.message.mid;
|
|
91
|
+
if (this.processedIds.has(msgId)) continue;
|
|
92
|
+
this.processedIds.add(msgId);
|
|
93
|
+
const senderId = messaging.sender.id;
|
|
94
|
+
const text = messaging.message.text;
|
|
95
|
+
if (!text) continue;
|
|
96
|
+
const allowed = await this.checkDMPolicy(senderId, text);
|
|
97
|
+
if (!allowed) continue;
|
|
98
|
+
this.emit("message", {
|
|
99
|
+
id: msgId,
|
|
100
|
+
channelId: "messenger",
|
|
101
|
+
from: senderId,
|
|
102
|
+
chatId: senderId,
|
|
103
|
+
text,
|
|
104
|
+
timestamp: new Date(messaging.timestamp).toISOString(),
|
|
105
|
+
isDM: true
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async checkDMPolicy(from, text) {
|
|
110
|
+
if (this.config.dmPolicy === "none") return false;
|
|
111
|
+
if (this.config.dmPolicy === "open") return true;
|
|
112
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
113
|
+
if (this.config.allowFrom.includes(from)) return true;
|
|
114
|
+
await this.sendMessage(from, "🦅 HyperClaw: Not on allowlist.");
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
if (this.config.dmPolicy === "pairing") {
|
|
118
|
+
if (this.config.approvedPairings.includes(from)) return true;
|
|
119
|
+
const upper = text.trim().toUpperCase();
|
|
120
|
+
if (this.config.pendingPairings[upper]) {
|
|
121
|
+
this.config.approvedPairings.push(from);
|
|
122
|
+
delete this.config.pendingPairings[upper];
|
|
123
|
+
await this.saveState();
|
|
124
|
+
await this.sendMessage(from, "🦅 Paired!");
|
|
125
|
+
this.emit("pairing:approved", {
|
|
126
|
+
userId: from,
|
|
127
|
+
channelId: "messenger"
|
|
128
|
+
});
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
132
|
+
this.config.pendingPairings[code] = from;
|
|
133
|
+
await this.saveState();
|
|
134
|
+
await this.sendMessage(from, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve messenger ${code}`);
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
async sendMessage(recipientId, text) {
|
|
140
|
+
await fbReq(this.config.pageAccessToken, "/me/messages", {
|
|
141
|
+
recipient: { id: recipientId },
|
|
142
|
+
message: { text: text.slice(0, 2e3) }
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
approvePairing(code) {
|
|
146
|
+
const upper = code.toUpperCase();
|
|
147
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
148
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
149
|
+
delete this.config.pendingPairings[upper];
|
|
150
|
+
this.saveState();
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
async loadState() {
|
|
154
|
+
try {
|
|
155
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
156
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
157
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
158
|
+
} catch {}
|
|
159
|
+
}
|
|
160
|
+
async saveState() {
|
|
161
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
162
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
163
|
+
p: this.config.pendingPairings,
|
|
164
|
+
a: this.config.approvedPairings
|
|
165
|
+
}, { spaces: 2 });
|
|
166
|
+
}
|
|
167
|
+
isRunning() {
|
|
168
|
+
return this.running;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
//#endregion
|
|
173
|
+
exports.MessengerConnector = MessengerConnector;
|