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,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 events = require_chunk.__toESM(require("events"));
|
|
7
|
+
|
|
8
|
+
//#region extensions/whatsapp-baileys/src/connector.ts
|
|
9
|
+
const AUTH_DIR = path.default.join(os.default.homedir(), ".hyperclaw", "baileys-auth");
|
|
10
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "whatsapp-baileys-state.json");
|
|
11
|
+
var WhatsAppBaileysConnector = class extends events.EventEmitter {
|
|
12
|
+
config;
|
|
13
|
+
sock = null;
|
|
14
|
+
running = false;
|
|
15
|
+
qrCallback;
|
|
16
|
+
constructor(config = {}) {
|
|
17
|
+
super();
|
|
18
|
+
this.config = {
|
|
19
|
+
dmPolicy: "allowlist",
|
|
20
|
+
allowFrom: [],
|
|
21
|
+
approvedPairings: [],
|
|
22
|
+
pendingPairings: {},
|
|
23
|
+
...config
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
onQR(cb) {
|
|
27
|
+
this.qrCallback = cb;
|
|
28
|
+
}
|
|
29
|
+
async connect() {
|
|
30
|
+
try {
|
|
31
|
+
const makeWASocket$1 = require("@whiskeysockets/baileys");
|
|
32
|
+
const { useMultiFileAuthState: useMultiFileAuthState$1 } = require("@whiskeysockets/baileys");
|
|
33
|
+
} catch {
|
|
34
|
+
throw new Error("Baileys not installed. Run: npm install @whiskeysockets/baileys");
|
|
35
|
+
}
|
|
36
|
+
const makeWASocket = require("@whiskeysockets/baileys").default;
|
|
37
|
+
const { useMultiFileAuthState } = require("@whiskeysockets/baileys");
|
|
38
|
+
await fs_extra.default.ensureDir(AUTH_DIR);
|
|
39
|
+
const { state, saveCreds } = await useMultiFileAuthState(AUTH_DIR);
|
|
40
|
+
await this.loadState();
|
|
41
|
+
this.sock = makeWASocket({
|
|
42
|
+
auth: state,
|
|
43
|
+
printQRInTerminal: true,
|
|
44
|
+
generateHighQualityLinkPreview: false
|
|
45
|
+
});
|
|
46
|
+
this.sock.ev.on("creds.update", saveCreds);
|
|
47
|
+
this.sock.ev.on("connection.update", (upd) => {
|
|
48
|
+
if (upd.qr) this.qrCallback?.(upd.qr);
|
|
49
|
+
if (upd.connection === "open") {
|
|
50
|
+
console.log(chalk.default.green(" 🦅 WhatsApp Baileys: connected"));
|
|
51
|
+
this.emit("connected", {});
|
|
52
|
+
}
|
|
53
|
+
if (upd.connection === "close") this.emit("disconnected", upd);
|
|
54
|
+
});
|
|
55
|
+
this.sock.ev.on("messages.upsert", async ({ messages }) => {
|
|
56
|
+
for (const m of messages) {
|
|
57
|
+
if (m.key.fromMe) continue;
|
|
58
|
+
const msg = m.message;
|
|
59
|
+
if (!msg) continue;
|
|
60
|
+
let text = msg.conversation || msg.extendedTextMessage?.text || "";
|
|
61
|
+
const from = (m.key.remoteJid || "").replace(/@.*/, "");
|
|
62
|
+
if (msg.audioMessage || msg.pttMessage) {
|
|
63
|
+
let audioPath;
|
|
64
|
+
try {
|
|
65
|
+
const { downloadMediaMessage } = require("@whiskeysockets/baileys");
|
|
66
|
+
const buf = await downloadMediaMessage(m, "buffer", {}, { reuploadRequest: this.sock?.updateMessageSent });
|
|
67
|
+
const tmp = path.default.join(os.default.tmpdir(), `hyperclaw-voice-${m.key.id}.ogg`);
|
|
68
|
+
await fs_extra.default.writeFile(tmp, buf);
|
|
69
|
+
audioPath = tmp;
|
|
70
|
+
} catch {}
|
|
71
|
+
this.emit("message", {
|
|
72
|
+
id: m.key.id,
|
|
73
|
+
channelId: "whatsapp-baileys",
|
|
74
|
+
from,
|
|
75
|
+
chatId: m.key.remoteJid,
|
|
76
|
+
text: "[voice note]",
|
|
77
|
+
audioPath,
|
|
78
|
+
timestamp: new Date(parseInt(m.messageTimestamp || "0") * 1e3).toISOString(),
|
|
79
|
+
isDM: true
|
|
80
|
+
});
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (!text) continue;
|
|
84
|
+
const allowed = await this.checkDMPolicy(from, text);
|
|
85
|
+
if (!allowed) continue;
|
|
86
|
+
this.emit("message", {
|
|
87
|
+
id: m.key.id,
|
|
88
|
+
channelId: "whatsapp-baileys",
|
|
89
|
+
from,
|
|
90
|
+
chatId: m.key.remoteJid,
|
|
91
|
+
text,
|
|
92
|
+
timestamp: new Date(parseInt(m.messageTimestamp) * 1e3).toISOString(),
|
|
93
|
+
isDM: true
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
this.running = true;
|
|
98
|
+
}
|
|
99
|
+
async checkDMPolicy(from, text) {
|
|
100
|
+
if (this.config.dmPolicy === "none") return false;
|
|
101
|
+
if (this.config.dmPolicy === "open") return true;
|
|
102
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
103
|
+
if (this.config.allowFrom.includes(from)) return true;
|
|
104
|
+
await this.sendMessage(from, "🦅 HyperClaw: Not on allowlist.").catch(() => {});
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
if (this.config.dmPolicy === "pairing") {
|
|
108
|
+
if (this.config.approvedPairings.includes(from)) return true;
|
|
109
|
+
const upper = text.trim().toUpperCase();
|
|
110
|
+
if (this.config.pendingPairings[upper]) {
|
|
111
|
+
this.config.approvedPairings.push(from);
|
|
112
|
+
delete this.config.pendingPairings[upper];
|
|
113
|
+
await this.saveState();
|
|
114
|
+
await this.sendMessage(from, "🦅 Paired!").catch(() => {});
|
|
115
|
+
this.emit("pairing:approved", {
|
|
116
|
+
userId: from,
|
|
117
|
+
channelId: "whatsapp-baileys"
|
|
118
|
+
});
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
122
|
+
this.config.pendingPairings[code] = from;
|
|
123
|
+
await this.saveState();
|
|
124
|
+
await this.sendMessage(from, `🦅 Code: ${code}\nApprove: hyperclaw pairing approve whatsapp-baileys ${code}`).catch(() => {});
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
async sendMessage(to, text) {
|
|
130
|
+
if (!this.sock) return;
|
|
131
|
+
const jid = to.includes("@") ? to : `${to}@s.whatsapp.net`;
|
|
132
|
+
await this.sock.sendMessage(jid, { text: text.slice(0, 4096) });
|
|
133
|
+
}
|
|
134
|
+
disconnect() {
|
|
135
|
+
this.running = false;
|
|
136
|
+
this.sock?.end?.();
|
|
137
|
+
this.sock = null;
|
|
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.WhatsAppBaileysConnector = WhatsAppBaileysConnector;
|
|
@@ -0,0 +1,182 @@
|
|
|
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/mattermost/src/connector.ts
|
|
11
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "mattermost-state.json");
|
|
12
|
+
function mattermostApi(serverUrl, token, method, path$2, body) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const base = serverUrl.startsWith("https") ? serverUrl : `https://${serverUrl.replace(/^https?:\/\//, "")}`;
|
|
15
|
+
const url = new URL(path$2.startsWith("/") ? path$2 : "/" + path$2, base);
|
|
16
|
+
const payload = body ? JSON.stringify(body) : null;
|
|
17
|
+
const client = url.protocol === "https:" ? https.default : http.default;
|
|
18
|
+
const req = client.request({
|
|
19
|
+
hostname: url.hostname,
|
|
20
|
+
port: url.port || (url.protocol === "https:" ? 443 : 80),
|
|
21
|
+
path: url.pathname,
|
|
22
|
+
method,
|
|
23
|
+
headers: {
|
|
24
|
+
"Authorization": `Bearer ${token}`,
|
|
25
|
+
...payload ? {
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
28
|
+
} : {}
|
|
29
|
+
}
|
|
30
|
+
}, (res) => {
|
|
31
|
+
let data = "";
|
|
32
|
+
res.on("data", (c) => data += c);
|
|
33
|
+
res.on("end", () => {
|
|
34
|
+
try {
|
|
35
|
+
const r = data ? JSON.parse(data) : {};
|
|
36
|
+
const ok = res.statusCode && res.statusCode >= 200 && res.statusCode < 300;
|
|
37
|
+
if (ok) resolve(r);
|
|
38
|
+
else reject(new Error(r.message || r.error || `HTTP ${res.statusCode}`));
|
|
39
|
+
} catch (e) {
|
|
40
|
+
reject(e || new Error("Parse error"));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
req.on("error", reject);
|
|
45
|
+
if (payload) req.write(payload);
|
|
46
|
+
req.end();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
var MattermostConnector = class extends events.EventEmitter {
|
|
50
|
+
config;
|
|
51
|
+
running = false;
|
|
52
|
+
constructor(config) {
|
|
53
|
+
super();
|
|
54
|
+
this.config = {
|
|
55
|
+
dmPolicy: "allowlist",
|
|
56
|
+
allowFrom: [],
|
|
57
|
+
approvedPairings: [],
|
|
58
|
+
pendingPairings: {},
|
|
59
|
+
...config
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async connect() {
|
|
63
|
+
const base = this.config.serverUrl.replace(/\/$/, "");
|
|
64
|
+
await mattermostApi(base, this.config.token, "GET", "/api/v4/users/me");
|
|
65
|
+
await this.loadState();
|
|
66
|
+
this.running = true;
|
|
67
|
+
console.log(chalk.default.green(` 🦅 Mattermost: connected to ${base}`));
|
|
68
|
+
this.emit("connected", { serverUrl: base });
|
|
69
|
+
}
|
|
70
|
+
disconnect() {
|
|
71
|
+
this.running = false;
|
|
72
|
+
}
|
|
73
|
+
/** Parse outgoing webhook payload (form-urlencoded or JSON) */
|
|
74
|
+
async handleWebhook(body, _opts) {
|
|
75
|
+
let params;
|
|
76
|
+
const trimmed = (body || "").trim();
|
|
77
|
+
if (trimmed.startsWith("{")) try {
|
|
78
|
+
params = JSON.parse(trimmed);
|
|
79
|
+
} catch {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
params = {};
|
|
84
|
+
for (const pair of body.split("&")) {
|
|
85
|
+
const eq = pair.indexOf("=");
|
|
86
|
+
const k = eq >= 0 ? decodeURIComponent(pair.slice(0, eq).replace(/\+/g, " ")) : decodeURIComponent(pair.replace(/\+/g, " "));
|
|
87
|
+
const v = eq >= 0 ? decodeURIComponent((pair.slice(eq + 1) || "").replace(/\+/g, " ")) : "";
|
|
88
|
+
if (k) params[k] = v;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const token = params.token;
|
|
92
|
+
if (token !== this.config.webhookToken) {
|
|
93
|
+
console.log(chalk.default.yellow(" ⚠ Mattermost: invalid webhook token"));
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const channelId = params.channel_id;
|
|
97
|
+
const userId = params.user_id;
|
|
98
|
+
const userName = params.user_name || "";
|
|
99
|
+
let text = (params.text || "").trim();
|
|
100
|
+
const triggerWord = params.trigger_word || "";
|
|
101
|
+
if (triggerWord && text.startsWith(triggerWord)) text = text.slice(triggerWord.length).trim();
|
|
102
|
+
if (!channelId || !userId || !text) return;
|
|
103
|
+
const allowed = await this.checkDMPolicy(userId, text, channelId);
|
|
104
|
+
if (!allowed) return;
|
|
105
|
+
this.emit("message", {
|
|
106
|
+
id: params.post_id || `${channelId}-${Date.now()}`,
|
|
107
|
+
channelId: "mattermost",
|
|
108
|
+
from: userId,
|
|
109
|
+
chatId: channelId,
|
|
110
|
+
text,
|
|
111
|
+
timestamp: params.timestamp ? new Date(parseInt(params.timestamp) * 1e3).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
|
|
112
|
+
isDM: false,
|
|
113
|
+
userName
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
async checkDMPolicy(userId, text, channelId) {
|
|
117
|
+
if (this.config.dmPolicy === "none") return false;
|
|
118
|
+
if (this.config.dmPolicy === "open") return true;
|
|
119
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
120
|
+
if (this.config.allowFrom.includes(userId)) return true;
|
|
121
|
+
await this.sendMessage(channelId, "🦅 HyperClaw: Not on allowlist.");
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
if (this.config.dmPolicy === "pairing") {
|
|
125
|
+
if (this.config.approvedPairings.includes(userId)) return true;
|
|
126
|
+
const upper = text.trim().toUpperCase();
|
|
127
|
+
if (this.config.pendingPairings[upper]) {
|
|
128
|
+
this.config.approvedPairings.push(userId);
|
|
129
|
+
delete this.config.pendingPairings[upper];
|
|
130
|
+
await this.saveState();
|
|
131
|
+
await this.sendMessage(channelId, "🦅 Paired!");
|
|
132
|
+
this.emit("pairing:approved", {
|
|
133
|
+
userId,
|
|
134
|
+
channelId: "mattermost"
|
|
135
|
+
});
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
139
|
+
this.config.pendingPairings[code] = userId;
|
|
140
|
+
await this.saveState();
|
|
141
|
+
await this.sendMessage(channelId, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve mattermost ${code}`);
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
async sendMessage(channelId, text) {
|
|
147
|
+
const base = this.config.serverUrl.replace(/\/$/, "");
|
|
148
|
+
const chunks = text.match(/.{1,4000}/gs) || [text];
|
|
149
|
+
for (const chunk of chunks) await mattermostApi(base, this.config.token, "POST", "/api/v4/posts", {
|
|
150
|
+
channel_id: channelId,
|
|
151
|
+
message: chunk.slice(0, 16383)
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
approvePairing(code) {
|
|
155
|
+
const upper = code.toUpperCase();
|
|
156
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
157
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
158
|
+
delete this.config.pendingPairings[upper];
|
|
159
|
+
this.saveState();
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
async loadState() {
|
|
163
|
+
try {
|
|
164
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
165
|
+
if (s.pendingPairings) this.config.pendingPairings = s.pendingPairings;
|
|
166
|
+
if (s.approvedPairings) this.config.approvedPairings = s.approvedPairings;
|
|
167
|
+
} catch {}
|
|
168
|
+
}
|
|
169
|
+
async saveState() {
|
|
170
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
171
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
172
|
+
pendingPairings: this.config.pendingPairings,
|
|
173
|
+
approvedPairings: this.config.approvedPairings
|
|
174
|
+
}, { spaces: 2 });
|
|
175
|
+
}
|
|
176
|
+
isRunning() {
|
|
177
|
+
return this.running;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
//#endregion
|
|
182
|
+
exports.MattermostConnector = MattermostConnector;
|
|
@@ -0,0 +1,162 @@
|
|
|
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/instagram/src/connector.ts
|
|
10
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "instagram-state.json");
|
|
11
|
+
function igReq(token, 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: "graph.facebook.com",
|
|
16
|
+
port: 443,
|
|
17
|
+
path: `/v18.0${endpoint}`,
|
|
18
|
+
method,
|
|
19
|
+
headers: {
|
|
20
|
+
"Authorization": `Bearer ${token}`,
|
|
21
|
+
...payload ? {
|
|
22
|
+
"Content-Type": "application/json",
|
|
23
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
24
|
+
} : {}
|
|
25
|
+
}
|
|
26
|
+
}, (res) => {
|
|
27
|
+
let data = "";
|
|
28
|
+
res.on("data", (c) => data += c);
|
|
29
|
+
res.on("end", () => {
|
|
30
|
+
try {
|
|
31
|
+
const r = JSON.parse(data);
|
|
32
|
+
if (r.error) reject(new Error(r.error.message));
|
|
33
|
+
else resolve(r);
|
|
34
|
+
} catch {
|
|
35
|
+
reject(new Error("Invalid JSON"));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
req.on("error", reject);
|
|
40
|
+
if (payload) req.write(payload);
|
|
41
|
+
req.end();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
var InstagramConnector = class extends events.EventEmitter {
|
|
45
|
+
config;
|
|
46
|
+
running = false;
|
|
47
|
+
processedIds = /* @__PURE__ */ new Set();
|
|
48
|
+
constructor(config) {
|
|
49
|
+
super();
|
|
50
|
+
this.config = {
|
|
51
|
+
dmPolicy: "allowlist",
|
|
52
|
+
allowFrom: [],
|
|
53
|
+
approvedPairings: [],
|
|
54
|
+
pendingPairings: {},
|
|
55
|
+
...config
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async connect() {
|
|
59
|
+
const info = await igReq(this.config.pageAccessToken, "GET", `/${this.config.instagramAccountId}?fields=name,username`);
|
|
60
|
+
await this.loadState();
|
|
61
|
+
this.running = true;
|
|
62
|
+
console.log(chalk.default.green(` 🦅 Instagram: @${info.username || info.name} connected`));
|
|
63
|
+
this.emit("connected", {
|
|
64
|
+
accountId: this.config.instagramAccountId,
|
|
65
|
+
username: info.username
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
disconnect() {
|
|
69
|
+
this.running = false;
|
|
70
|
+
}
|
|
71
|
+
verifyWebhook(mode, token, challenge) {
|
|
72
|
+
return mode === "subscribe" && token === this.config.verifyToken ? challenge : null;
|
|
73
|
+
}
|
|
74
|
+
async handleWebhook(body) {
|
|
75
|
+
let payload;
|
|
76
|
+
try {
|
|
77
|
+
payload = JSON.parse(body);
|
|
78
|
+
} catch {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
for (const entry of payload.entry || []) for (const messaging of entry.messaging || []) {
|
|
82
|
+
if (!messaging.message || messaging.message.is_echo) continue;
|
|
83
|
+
const msgId = messaging.message.mid;
|
|
84
|
+
if (this.processedIds.has(msgId)) continue;
|
|
85
|
+
this.processedIds.add(msgId);
|
|
86
|
+
const senderId = messaging.sender.id;
|
|
87
|
+
const text = messaging.message.text;
|
|
88
|
+
if (!text) continue;
|
|
89
|
+
const allowed = await this.checkDMPolicy(senderId, text);
|
|
90
|
+
if (!allowed) continue;
|
|
91
|
+
this.emit("message", {
|
|
92
|
+
id: msgId,
|
|
93
|
+
channelId: "instagram",
|
|
94
|
+
from: senderId,
|
|
95
|
+
chatId: senderId,
|
|
96
|
+
text,
|
|
97
|
+
timestamp: new Date(messaging.timestamp).toISOString(),
|
|
98
|
+
isDM: true
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async checkDMPolicy(from, text) {
|
|
103
|
+
if (this.config.dmPolicy === "none") return false;
|
|
104
|
+
if (this.config.dmPolicy === "open") return true;
|
|
105
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
106
|
+
if (this.config.allowFrom.includes(from)) return true;
|
|
107
|
+
await this.sendMessage(from, "🦅 HyperClaw: You are not on the allowlist.");
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (this.config.dmPolicy === "pairing") {
|
|
111
|
+
if (this.config.approvedPairings.includes(from)) return true;
|
|
112
|
+
const upper = text.trim().toUpperCase();
|
|
113
|
+
if (this.config.pendingPairings[upper]) {
|
|
114
|
+
this.config.approvedPairings.push(from);
|
|
115
|
+
delete this.config.pendingPairings[upper];
|
|
116
|
+
await this.saveState();
|
|
117
|
+
await this.sendMessage(from, "🦅 Paired! You can now send messages.");
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
121
|
+
this.config.pendingPairings[code] = from;
|
|
122
|
+
await this.saveState();
|
|
123
|
+
await this.sendMessage(from, `🦅 HyperClaw Pairing\nCode: ${code}\nApprove: hyperclaw pairing approve instagram ${code}`);
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
async sendMessage(recipientId, text) {
|
|
129
|
+
await igReq(this.config.pageAccessToken, "POST", `/${this.config.instagramAccountId}/messages`, {
|
|
130
|
+
recipient: { id: recipientId },
|
|
131
|
+
message: { text: text.slice(0, 2e3) }
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
approvePairing(code) {
|
|
135
|
+
const upper = code.toUpperCase();
|
|
136
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
137
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
138
|
+
delete this.config.pendingPairings[upper];
|
|
139
|
+
this.saveState();
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
async loadState() {
|
|
143
|
+
try {
|
|
144
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
145
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
146
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
147
|
+
} catch {}
|
|
148
|
+
}
|
|
149
|
+
async saveState() {
|
|
150
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
151
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
152
|
+
p: this.config.pendingPairings,
|
|
153
|
+
a: this.config.approvedPairings
|
|
154
|
+
}, { spaces: 2 });
|
|
155
|
+
}
|
|
156
|
+
isRunning() {
|
|
157
|
+
return this.running;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
//#endregion
|
|
162
|
+
exports.InstagramConnector = InstagramConnector;
|