hyperclaw 4.0.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -4
- package/dist/a2ui-protocol-CT_jDEU9.js +75 -0
- package/dist/a2ui-protocol-CfBI44-Q.js +75 -0
- package/dist/agents-routing-683Q2JGp.js +129 -0
- package/dist/agents-routing-BpZBswBH.js +4 -0
- package/dist/agents-routing-ChHiZp36.js +327 -0
- package/dist/agents-routing-ChqZ6l2S.js +4 -0
- package/dist/api-keys-guide-BCcOl0Q7.js +149 -0
- package/dist/api-keys-guide-Dq5Obbp4.js +149 -0
- package/dist/audit-BYxPlnTQ.js +248 -0
- package/dist/audit-BaIiyWFu.js +441 -0
- package/dist/bounty-tools-C6LyzxM-.js +211 -0
- package/dist/bounty-tools-DWudyZie.js +211 -0
- package/dist/browser-tools-BsTeGMnX.js +5 -0
- package/dist/browser-tools-CQBSbIuO.js +5 -0
- package/dist/browser-tools-D8_rLe2p.js +179 -0
- package/dist/browser-tools-YQmwRLLM.js +179 -0
- package/dist/claw-tasks-BRLUvFRD.js +80 -0
- package/dist/claw-tasks-CgTsiNE8.js +80 -0
- package/dist/connector-3HnyH8fn.js +167 -0
- package/dist/connector-5N0-X_xs.js +194 -0
- package/dist/connector-6PMZo5Ky.js +189 -0
- package/dist/connector-B3v0qcXg.js +425 -0
- package/dist/connector-B6eoF3DD.js +181 -0
- package/dist/connector-B8R3iBY1.js +280 -0
- package/dist/connector-B9tLG8UZ.js +196 -0
- package/dist/connector-BAM-08NN.js +189 -0
- package/dist/connector-BC8FIVu4.js +181 -0
- package/dist/connector-BDmwwaVc.js +213 -0
- package/dist/connector-BGjbBy69.js +225 -0
- package/dist/connector-BO2SRzfG.js +218 -0
- package/dist/connector-BOlqjXWP.js +182 -0
- package/dist/connector-BP8zsbP8.js +189 -0
- package/dist/connector-BPoSevxp.js +286 -0
- package/dist/connector-BRHj773i.js +163 -0
- package/dist/connector-BToxU-jV.js +267 -0
- package/dist/connector-BfXky0L3.js +167 -0
- package/dist/connector-BiiSJpx3.js +192 -0
- package/dist/connector-BliDVsJQ.js +239 -0
- package/dist/connector-BnDmIhIu.js +85 -0
- package/dist/connector-Bv6s9oP7.js +88 -0
- package/dist/connector-By5wWGTR.js +343 -0
- package/dist/connector-C1BaFFgN.js +213 -0
- package/dist/connector-C1HSoUyk.js +189 -0
- package/dist/connector-CKQHZOXg.js +568 -0
- package/dist/connector-CRRWY5Wv.js +167 -0
- package/dist/connector-CRl-iidy.js +239 -0
- package/dist/connector-CXPQVGyI.js +85 -0
- package/dist/connector-Cdk1CXKi.js +194 -0
- package/dist/connector-Ci9glMD-.js +340 -0
- package/dist/connector-CjtZIEDj.js +181 -0
- package/dist/connector-Ck6JtOsX.js +531 -0
- package/dist/connector-CwlgFgjx.js +181 -0
- package/dist/connector-D8Kelee0.js +286 -0
- package/dist/connector-DAnRJ0oP.js +162 -0
- package/dist/connector-DFchk6l7.js +178 -0
- package/dist/connector-DKw7tRAy.js +192 -0
- package/dist/connector-DRv1ahC_.js +2 -2
- package/dist/connector-DU63KW94.js +165 -0
- package/dist/connector-DXTp5PE8.js +508 -0
- package/dist/connector-Dbvb1Cj9.js +280 -0
- package/dist/connector-DcZdQcgR.js +173 -0
- package/dist/connector-Dih6dUPP.js +173 -0
- package/dist/connector-DqTH_tPX.js +182 -0
- package/dist/connector-DrnEiiyP.js +419 -0
- package/dist/connector-DtR5GGTX.js +167 -0
- package/dist/connector-DxKL8VvZ.js +182 -0
- package/dist/connector-T_YdZtzv.js +162 -0
- package/dist/connector-Tky_qS_K.js +350 -0
- package/dist/connector-ZSc3oTTy.js +305 -0
- package/dist/connector-i4gOS9xL.js +154 -0
- package/dist/connector-rHXE1ZD2.js +167 -0
- package/dist/connector-sW5yhU1m.js +498 -0
- package/dist/connector-u3ICd3Ic.js +552 -0
- package/dist/connector-wdUXChwa.js +172 -0
- package/dist/cost-tracker-DD9wtWsr.js +103 -0
- package/dist/cost-tracker-pVE15Yq4.js +103 -0
- package/dist/credentials-store-BvnMPJwi.js +4 -0
- package/dist/credentials-store-C6ir0Dae.js +4 -0
- package/dist/credentials-store-H13LqOwJ.js +77 -0
- package/dist/credentials-store-sb-TRLwR.js +77 -0
- package/dist/cron-tasks-Bli7Kzd2.js +82 -0
- package/dist/cron-tasks-BvDFNyiE.js +82 -0
- package/dist/daemon-Bg4GtCmc.js +318 -0
- package/dist/daemon-DhmwY8k4.js +5 -0
- package/dist/delivery-BmIYy9VQ.js +4 -0
- package/dist/delivery-D5Z98EVq.js +95 -0
- package/dist/delivery-DCOXhXEO.js +5 -0
- package/dist/delivery-pWUPBp1F.js +95 -0
- package/dist/destructive-gate-D6vWOdEl.js +101 -0
- package/dist/destructive-gate-m-dWqUFg.js +101 -0
- package/dist/developer-keys-CPWT7Q6S.js +8 -0
- package/dist/developer-keys-DrrcUqFa.js +127 -0
- package/dist/developer-keys-JaJK3T27.js +127 -0
- package/dist/developer-keys-kyqmtWK3.js +8 -0
- package/dist/doctor-3oi89QIc.js +175 -0
- package/dist/doctor-BvCe8BBk.js +230 -0
- package/dist/doctor-Cf1XSfp9.js +4 -0
- package/dist/doctor-CxyPLYsJ.js +6 -0
- package/dist/engine-B4eMiTgl.js +7 -0
- package/dist/engine-B8M7dYul.js +7 -0
- package/dist/engine-BhT-1M9W.js +256 -0
- package/dist/engine-CEDSqXfw.js +256 -0
- package/dist/engine-D49jnSd_.js +256 -0
- package/dist/engine-Da4JMNpI.js +7 -0
- package/dist/env-resolve-CiXbWYwe.js +10 -0
- package/dist/env-resolve-CmGWhWXJ.js +115 -0
- package/dist/env-resolve-DWOQ45jG.js +9 -0
- package/dist/env-resolve-szSWl0UF.js +94 -0
- package/dist/extraction-tools-D3qDFBJ1.js +91 -0
- package/dist/extraction-tools-DLr_AEwq.js +5 -0
- package/dist/extraction-tools-HOZstZ0y.js +91 -0
- package/dist/extraction-tools-m4lmAv7l.js +5 -0
- package/dist/form_data-B_hIUrxU.js +8657 -0
- package/dist/form_data-Cz040rio.js +8657 -0
- package/dist/gmail-watch-setup-Czt8rXaX.js +40 -0
- package/dist/gmail-watch-setup-Du7DVV7S.js +40 -0
- package/dist/health-B-asI__D.js +6 -0
- package/dist/health-Ds2YlpTB.js +152 -0
- package/dist/heartbeat-engine-BYT5ayQH.js +83 -0
- package/dist/heartbeat-engine-CRqfPcFM.js +83 -0
- package/dist/hub-D0XwdjM-.js +515 -0
- package/dist/hub-DTsqe5Bt.js +6 -0
- package/dist/hub-FrPTA33j.js +515 -0
- package/dist/hub-LiD5Iztb.js +6 -0
- package/dist/hyperclawbot-D9KCtc4P.js +480 -0
- package/dist/hyperclawbot-Dw27pJo4.js +480 -0
- package/dist/hyperclawbot-zvczQgKx.js +505 -0
- package/dist/inference-BKVkBREb.js +6 -0
- package/dist/inference-CTWJeX9Q.js +922 -0
- package/dist/inference-DCXH4Q3x.js +922 -0
- package/dist/inference-ix607p7k.js +6 -0
- package/dist/knowledge-graph-DqA-Fztl.js +131 -0
- package/dist/knowledge-graph-iBG76fvm.js +131 -0
- package/dist/loader-CC45xGpC.js +4 -0
- package/dist/loader-CISCqBto.js +400 -0
- package/dist/loader-CYMQ8VOS.js +4 -0
- package/dist/loader-CnEdOyjT.js +400 -0
- package/dist/logger-8tEtAd3y.js +83 -0
- package/dist/logger-ybOp7VOC.js +83 -0
- package/dist/manager-03ipO9R0.js +105 -0
- package/dist/manager-BpDfbDjg.js +117 -0
- package/dist/manager-Bxl0sqlh.js +4 -0
- package/dist/manager-CPjeRe-6.js +4 -0
- package/dist/manager-CrVDn6eN.js +6 -0
- package/dist/manager-Cwzj7w5R.js +105 -0
- package/dist/manager-DLmZI-9R.js +6 -0
- package/dist/manager-DSGhn5i3.js +117 -0
- package/dist/manager-DgyF52mg.js +218 -0
- package/dist/manager-Dm8nrMFx.js +40 -0
- package/dist/manager-FCgF1plu.js +218 -0
- package/dist/manager-rgCsaWT1.js +40 -0
- package/dist/mcp-B_9Ber63.js +139 -0
- package/dist/mcp-CfoSU4Uz.js +139 -0
- package/dist/mcp-loader-DSM5UiFG.js +94 -0
- package/dist/mcp-loader-DkRBsLpk.js +94 -0
- package/dist/mcp-loader-j5ZLLw5O.js +94 -0
- package/dist/memory-BI1kPkAN.js +4 -0
- package/dist/memory-BVFGkxxK.js +270 -0
- package/dist/memory-BlHL7JCO.js +4 -0
- package/dist/memory-DsS_eFvJ.js +270 -0
- package/dist/memory-auto-Bc7euou4.js +306 -0
- package/dist/memory-auto-BkvtSFUw.js +5 -0
- package/dist/memory-auto-Bnz_-1wP.js +306 -0
- package/dist/memory-auto-DPfbkMVt.js +5 -0
- package/dist/memory-integration-DZExqWr4.js +91 -0
- package/dist/memory-integration-cSYkZyEo.js +91 -0
- package/dist/moltbook-B6ZeGN5_.js +81 -0
- package/dist/moltbook-BtLDZTfM.js +81 -0
- package/dist/node-Dw2Gi-cP.js +222 -0
- package/dist/node-pwL6O_KX.js +222 -0
- package/dist/nodes-registry-B8dmrlLv.js +52 -0
- package/dist/nodes-registry-CsPm_-CJ.js +52 -0
- package/dist/oauth-flow-CpWlgvNB.js +150 -0
- package/dist/oauth-flow-DQPvMHRH.js +150 -0
- package/dist/oauth-provider-BZb6qOw5.js +110 -0
- package/dist/oauth-provider-Uo4Nib_c.js +110 -0
- package/dist/observability-B43YvNQV.js +89 -0
- package/dist/observability-BV-Yx0V9.js +89 -0
- package/dist/onboard-0WoDxbv_.js +10 -0
- package/dist/onboard-BXNXCQp4.js +4070 -0
- package/dist/onboard-Bd_wsYdi.js +4086 -0
- package/dist/onboard-CAN7x3me.js +3026 -0
- package/dist/onboard-DnegOHMh.js +4 -4
- package/dist/onboard-RYtDlYBw.js +9 -0
- package/dist/onboard-aTwlQs-4.js +9 -0
- package/dist/orchestrator-BSp2M5EU.js +189 -0
- package/dist/orchestrator-C7ko5tWa.js +6 -0
- package/dist/orchestrator-DfPkIx2Z.js +6 -0
- package/dist/orchestrator-DmnEvMaL.js +189 -0
- package/dist/orchestrator-NJQsmiBE.js +189 -0
- package/dist/orchestrator-RI3bpqqc.js +6 -0
- package/dist/pairing-6iM27aD8.js +196 -0
- package/dist/pairing-DU0_J28n.js +87 -0
- package/dist/pairing-DWllbSbO.js +4 -0
- package/dist/pairing-dGoiGepK.js +4 -0
- package/dist/pc-access-CgCsYrpt.js +8 -0
- package/dist/pc-access-Ly-uA8mn.js +8 -0
- package/dist/pc-access-NxBvTrRj.js +819 -0
- package/dist/pc-access-_iH2aorG.js +819 -0
- package/dist/pending-approval-CUXjysAo.js +22 -0
- package/dist/pending-approval-DIHvwwWS.js +22 -0
- package/dist/puppeteer-2o3QOwAy.js +2 -2
- package/dist/puppeteer-BYTMp3BI.js +2 -2
- package/dist/puppeteer-DQ45qwWk.js +2 -2
- package/dist/reminders-store-D79qdfN0.js +58 -0
- package/dist/reminders-store-Drjed_-h.js +58 -0
- package/dist/renderer-BVQrd0_g.js +225 -0
- package/dist/renderer-pqlDRKbH.js +225 -0
- package/dist/rules-BE4GV6cV.js +103 -0
- package/dist/rules-BooT_qFP.js +103 -0
- package/dist/run-main.js +1649 -1227
- package/dist/runner-D1rjuMTJ.js +810 -0
- package/dist/runner-DatMMYYE.js +1271 -0
- package/dist/sdk/index.js +2 -2
- package/dist/sdk/index.mjs +2 -2
- package/dist/security-BqNyT4ID.js +4 -0
- package/dist/security-C-5URby1.js +73 -0
- package/dist/security-_xve79aq.js +4 -0
- package/dist/security-tpgqPWWH.js +73 -0
- package/dist/server-0kgyELx4.js +1047 -0
- package/dist/server-BIuTobTC.js +4 -0
- package/dist/server-BRlCEjyT.js +1047 -0
- package/dist/server-CCI1hv45.js +2 -2
- package/dist/server-D4wVHiX9.js +4 -0
- package/dist/server-DU9POoWc.js +4 -0
- package/dist/server-Dh3JlBFB.js +1255 -0
- package/dist/session-store-BUiPz0Vv.js +5 -0
- package/dist/session-store-CujxByI6.js +113 -0
- package/dist/session-store-is4B6qmD.js +113 -0
- package/dist/session-store-qpJUg2M1.js +5 -0
- package/dist/sessions-tools-CB2qbwIk.js +5 -0
- package/dist/sessions-tools-CbUTFe4i.js +5 -0
- package/dist/sessions-tools-CeqD7iil.js +95 -0
- package/dist/sessions-tools-DHMaTZIs.js +95 -0
- package/dist/skill-loader-BaNLVmJy.js +7 -0
- package/dist/skill-loader-BkceKkIg.js +7 -0
- package/dist/skill-loader-DhgIwK4J.js +159 -0
- package/dist/skill-loader-HgpF6Vqs.js +159 -0
- package/dist/skill-runtime--LqxWrp5.js +102 -0
- package/dist/skill-runtime-C5l0Tgt-.js +5 -0
- package/dist/skill-runtime-CJN24QPW.js +102 -0
- package/dist/skill-runtime-DsXK_HYG.js +102 -0
- package/dist/skill-runtime-IVTiqrMR.js +5 -0
- package/dist/skill-runtime-w1ig_lcw.js +5 -0
- package/dist/src-BEVLgaF1.js +63 -0
- package/dist/src-Bgu_OxTQ.js +458 -0
- package/dist/src-Bq-oKt7Z.js +458 -0
- package/dist/src-BxPHKO5x.js +63 -0
- package/dist/src-DIc-L2IG.js +20 -0
- package/dist/src-DWCUhnD4.js +20 -0
- package/dist/src-cfRTjFef.js +63 -0
- package/dist/src-g_rNx5rh.js +458 -0
- package/dist/sub-agent-tools-BD9DF8_g.js +39 -0
- package/dist/sub-agent-tools-CHQoHz9c.js +39 -0
- package/dist/sub-agent-tools-V7b3T9_s.js +39 -0
- package/dist/theme-DcxwcUgZ.js +180 -0
- package/dist/theme-cx0fkgWC.js +8 -0
- package/dist/tool-policy-CNT-mF2Z.js +189 -0
- package/dist/tool-policy-DNvNRnve.js +189 -0
- package/dist/tts-elevenlabs-BRosZv-f.js +61 -0
- package/dist/tts-elevenlabs-BUOGKL-k.js +61 -0
- package/dist/update-check-BD4qH7Am.js +81 -0
- package/dist/update-check-C2Dz85wJ.js +81 -0
- package/dist/vision-BMmiIKy7.js +121 -0
- package/dist/vision-DRq-f-Dj.js +121 -0
- package/dist/vision-tools-CFZEpQKm.js +5 -0
- package/dist/vision-tools-CQnBI9aa.js +51 -0
- package/dist/vision-tools-DVuYc17I.js +51 -0
- package/dist/vision-tools-U3YC4L-g.js +5 -0
- package/dist/voice-transcription-B555DbWR.js +138 -0
- package/dist/voice-transcription-CgWq54hn.js +138 -0
- package/dist/website-watch-tools-Bk_TnwuE.js +5 -0
- package/dist/website-watch-tools-DFMrJU-R.js +139 -0
- package/dist/website-watch-tools-DraMPxdl.js +139 -0
- package/dist/website-watch-tools-Du3W5sN7.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;
|
|
@@ -36,7 +36,7 @@ function discordRest(token, method, endpoint, body) {
|
|
|
36
36
|
method,
|
|
37
37
|
headers: {
|
|
38
38
|
"Authorization": `Bot ${token}`,
|
|
39
|
-
"User-Agent": "HyperClaw/4.0.
|
|
39
|
+
"User-Agent": "HyperClaw/4.0.2 (https://hyperclaw.ai)",
|
|
40
40
|
...payload ? {
|
|
41
41
|
"Content-Type": "application/json",
|
|
42
42
|
"Content-Length": Buffer.byteLength(payload)
|
|
@@ -101,7 +101,7 @@ var DiscordConnector = class extends events.EventEmitter {
|
|
|
101
101
|
await this.saveState();
|
|
102
102
|
}
|
|
103
103
|
async openWebSocket(url) {
|
|
104
|
-
this.ws = new ws.WebSocket(url, { headers: { "User-Agent": "HyperClaw/4.0.
|
|
104
|
+
this.ws = new ws.WebSocket(url, { headers: { "User-Agent": "HyperClaw/4.0.2" } });
|
|
105
105
|
this.ws.on("message", async (data) => {
|
|
106
106
|
const payload = JSON.parse(data.toString());
|
|
107
107
|
await this.handlePayload(payload);
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
const chalk = require_chunk.__toESM(require("chalk"));
|
|
3
|
+
const fs_extra = require_chunk.__toESM(require("fs-extra"));
|
|
4
|
+
const path = require_chunk.__toESM(require("path"));
|
|
5
|
+
const os = require_chunk.__toESM(require("os"));
|
|
6
|
+
const http = require_chunk.__toESM(require("http"));
|
|
7
|
+
const https = require_chunk.__toESM(require("https"));
|
|
8
|
+
const events = require_chunk.__toESM(require("events"));
|
|
9
|
+
|
|
10
|
+
//#region extensions/matrix/src/connector.ts
|
|
11
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "matrix-state.json");
|
|
12
|
+
function matrixReq(homeserver, token, method, apiPath, body) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const url = new URL(homeserver);
|
|
15
|
+
const isHttps = url.protocol === "https:";
|
|
16
|
+
const mod = isHttps ? https.default : http.default;
|
|
17
|
+
const payload = body ? JSON.stringify(body) : null;
|
|
18
|
+
const req = mod.request({
|
|
19
|
+
hostname: url.hostname,
|
|
20
|
+
port: url.port || (isHttps ? 443 : 80),
|
|
21
|
+
path: `/_matrix/client/r0${apiPath}?access_token=${token}`,
|
|
22
|
+
method,
|
|
23
|
+
headers: payload ? {
|
|
24
|
+
"Content-Type": "application/json",
|
|
25
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
26
|
+
} : {}
|
|
27
|
+
}, (res) => {
|
|
28
|
+
let data = "";
|
|
29
|
+
res.on("data", (c) => data += c);
|
|
30
|
+
res.on("end", () => {
|
|
31
|
+
try {
|
|
32
|
+
const r = JSON.parse(data);
|
|
33
|
+
if (r.errcode) reject(new Error(r.error));
|
|
34
|
+
else resolve(r);
|
|
35
|
+
} catch {
|
|
36
|
+
reject(new Error("Invalid JSON"));
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
req.on("error", reject);
|
|
41
|
+
if (payload) req.write(payload);
|
|
42
|
+
req.end();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
var MatrixConnector = class extends events.EventEmitter {
|
|
46
|
+
config;
|
|
47
|
+
running = false;
|
|
48
|
+
nextBatch = null;
|
|
49
|
+
constructor(config) {
|
|
50
|
+
super();
|
|
51
|
+
this.config = {
|
|
52
|
+
dmPolicy: "allowlist",
|
|
53
|
+
allowFrom: [],
|
|
54
|
+
approvedPairings: [],
|
|
55
|
+
pendingPairings: {},
|
|
56
|
+
...config
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async connect() {
|
|
60
|
+
const whoami = await matrixReq(this.config.homeserver, this.config.accessToken, "GET", "/account/whoami");
|
|
61
|
+
await this.loadState();
|
|
62
|
+
this.running = true;
|
|
63
|
+
console.log(chalk.default.green(` 🦅 Matrix: ${whoami.user_id} connected`));
|
|
64
|
+
this.emit("connected", { userId: whoami.user_id });
|
|
65
|
+
this.syncLoop();
|
|
66
|
+
}
|
|
67
|
+
disconnect() {
|
|
68
|
+
this.running = false;
|
|
69
|
+
}
|
|
70
|
+
async syncLoop() {
|
|
71
|
+
while (this.running) try {
|
|
72
|
+
const since = this.nextBatch ? `&since=${this.nextBatch}&timeout=30000` : "";
|
|
73
|
+
const sync = await matrixReq(this.config.homeserver, this.config.accessToken, "GET", `/sync?${since}`);
|
|
74
|
+
this.nextBatch = sync.next_batch;
|
|
75
|
+
await this.saveState();
|
|
76
|
+
const rooms = sync.rooms?.join || {};
|
|
77
|
+
for (const [roomId, rd] of Object.entries(rooms)) for (const event of rd.timeline?.events || []) if (event.type === "m.room.message" && event.sender !== this.config.userId) await this.handleRoomEvent(roomId, event);
|
|
78
|
+
for (const [roomId] of Object.entries(sync.rooms?.invite || {})) await matrixReq(this.config.homeserver, this.config.accessToken, "POST", `/rooms/${roomId}/join`, {});
|
|
79
|
+
} catch (e) {
|
|
80
|
+
if (this.running) {
|
|
81
|
+
console.log(chalk.default.yellow(` ⚠ Matrix: ${e.message}`));
|
|
82
|
+
await new Promise((r) => setTimeout(r, 5e3));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async handleRoomEvent(roomId, event) {
|
|
87
|
+
const text = event.content?.body;
|
|
88
|
+
const sender = event.sender;
|
|
89
|
+
if (!text || !sender) return;
|
|
90
|
+
if (this.config.dmPolicy !== "open") {
|
|
91
|
+
const allowed = await this.checkPolicy(sender, roomId, text);
|
|
92
|
+
if (!allowed) return;
|
|
93
|
+
}
|
|
94
|
+
this.emit("message", {
|
|
95
|
+
id: event.event_id,
|
|
96
|
+
channelId: "matrix",
|
|
97
|
+
from: sender,
|
|
98
|
+
chatId: roomId,
|
|
99
|
+
text,
|
|
100
|
+
timestamp: new Date(event.origin_server_ts || Date.now()).toISOString(),
|
|
101
|
+
isDM: true
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
async checkPolicy(sender, roomId, text) {
|
|
105
|
+
if (this.config.dmPolicy === "none") return false;
|
|
106
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
107
|
+
if (this.config.allowFrom.includes(sender)) return true;
|
|
108
|
+
await this.sendMessage(roomId, "🦅 Not on allowlist.");
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
if (this.config.dmPolicy === "pairing") {
|
|
112
|
+
if (this.config.approvedPairings.includes(sender)) return true;
|
|
113
|
+
const upper = text.trim().toUpperCase();
|
|
114
|
+
if (this.config.pendingPairings[upper]) {
|
|
115
|
+
this.config.approvedPairings.push(sender);
|
|
116
|
+
delete this.config.pendingPairings[upper];
|
|
117
|
+
await this.saveState();
|
|
118
|
+
await this.sendMessage(roomId, "🦅 Paired!");
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
122
|
+
this.config.pendingPairings[code] = sender;
|
|
123
|
+
await this.saveState();
|
|
124
|
+
await this.sendMessage(roomId, `🦅 Pairing code: \`${code}\`\nApprove: hyperclaw pairing approve matrix ${code}`);
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
async sendMessage(roomId, text) {
|
|
130
|
+
await matrixReq(this.config.homeserver, this.config.accessToken, "PUT", `/rooms/${roomId}/send/m.room.message/${Date.now()}`, {
|
|
131
|
+
msgtype: "m.text",
|
|
132
|
+
body: text
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
approvePairing(code) {
|
|
136
|
+
const upper = code.toUpperCase();
|
|
137
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
138
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
139
|
+
delete this.config.pendingPairings[upper];
|
|
140
|
+
this.saveState();
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
async loadState() {
|
|
144
|
+
try {
|
|
145
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
146
|
+
this.nextBatch = s.nextBatch || null;
|
|
147
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
148
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
149
|
+
} catch {}
|
|
150
|
+
}
|
|
151
|
+
async saveState() {
|
|
152
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
153
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
154
|
+
nextBatch: this.nextBatch,
|
|
155
|
+
p: this.config.pendingPairings,
|
|
156
|
+
a: this.config.approvedPairings
|
|
157
|
+
}, { spaces: 2 });
|
|
158
|
+
}
|
|
159
|
+
isRunning() {
|
|
160
|
+
return this.running;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
//#endregion
|
|
165
|
+
exports.MatrixConnector = MatrixConnector;
|