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,343 @@
|
|
|
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 ws = require_chunk.__toESM(require("ws"));
|
|
7
|
+
const https = require_chunk.__toESM(require("https"));
|
|
8
|
+
const events = require_chunk.__toESM(require("events"));
|
|
9
|
+
|
|
10
|
+
//#region extensions/discord/src/connector.ts
|
|
11
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "discord-state.json");
|
|
12
|
+
const OPC = {
|
|
13
|
+
DISPATCH: 0,
|
|
14
|
+
HEARTBEAT: 1,
|
|
15
|
+
IDENTIFY: 2,
|
|
16
|
+
RESUME: 6,
|
|
17
|
+
RECONNECT: 7,
|
|
18
|
+
INVALID_SESSION: 9,
|
|
19
|
+
HELLO: 10,
|
|
20
|
+
HEARTBEAT_ACK: 11
|
|
21
|
+
};
|
|
22
|
+
const INTENTS = {
|
|
23
|
+
GUILDS: 1,
|
|
24
|
+
GUILD_MESSAGES: 512,
|
|
25
|
+
GUILD_MESSAGE_CONTENT: 32768,
|
|
26
|
+
DIRECT_MESSAGES: 4096,
|
|
27
|
+
DIRECT_MESSAGE_CONTENT: 16384
|
|
28
|
+
};
|
|
29
|
+
function discordRest(token, method, endpoint, body) {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
const payload = body ? JSON.stringify(body) : null;
|
|
32
|
+
const req = https.default.request({
|
|
33
|
+
hostname: "discord.com",
|
|
34
|
+
port: 443,
|
|
35
|
+
path: `/api/v10${endpoint}`,
|
|
36
|
+
method,
|
|
37
|
+
headers: {
|
|
38
|
+
"Authorization": `Bot ${token}`,
|
|
39
|
+
"User-Agent": "HyperClaw/4.0.2 (https://hyperclaw.ai)",
|
|
40
|
+
...payload ? {
|
|
41
|
+
"Content-Type": "application/json",
|
|
42
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
43
|
+
} : {}
|
|
44
|
+
}
|
|
45
|
+
}, (res) => {
|
|
46
|
+
let data = "";
|
|
47
|
+
res.on("data", (c) => data += c);
|
|
48
|
+
res.on("end", () => {
|
|
49
|
+
if (res.statusCode === 204) return resolve(null);
|
|
50
|
+
try {
|
|
51
|
+
const r = JSON.parse(data);
|
|
52
|
+
if (res.statusCode && res.statusCode >= 400) reject(new Error(`Discord API ${res.statusCode}: ${r.message || data}`));
|
|
53
|
+
else resolve(r);
|
|
54
|
+
} catch {
|
|
55
|
+
reject(new Error(`Invalid JSON (${res.statusCode})`));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
req.on("error", reject);
|
|
60
|
+
if (payload) req.write(payload);
|
|
61
|
+
req.end();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
var DiscordConnector = class extends events.EventEmitter {
|
|
65
|
+
token;
|
|
66
|
+
config;
|
|
67
|
+
ws = null;
|
|
68
|
+
heartbeatInterval = null;
|
|
69
|
+
lastSequence = null;
|
|
70
|
+
sessionId = null;
|
|
71
|
+
resumeGatewayUrl = null;
|
|
72
|
+
running = false;
|
|
73
|
+
botUser = null;
|
|
74
|
+
constructor(token, config) {
|
|
75
|
+
super();
|
|
76
|
+
this.token = token;
|
|
77
|
+
this.config = {
|
|
78
|
+
token,
|
|
79
|
+
dmPolicy: "allowlist",
|
|
80
|
+
allowFrom: [],
|
|
81
|
+
approvedPairings: [],
|
|
82
|
+
pendingPairings: {},
|
|
83
|
+
listenGuildIds: [],
|
|
84
|
+
commandPrefix: "!",
|
|
85
|
+
...config
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async connect() {
|
|
89
|
+
const gateway = await discordRest(this.token, "GET", "/gateway/bot");
|
|
90
|
+
const wsUrl = (gateway.url || "wss://gateway.discord.gg") + "/?v=10&encoding=json";
|
|
91
|
+
this.botUser = await discordRest(this.token, "GET", "/users/@me");
|
|
92
|
+
console.log(chalk.default.green(` 🦅 Discord: @${this.botUser?.username} connected`));
|
|
93
|
+
await this.loadState();
|
|
94
|
+
this.running = true;
|
|
95
|
+
await this.openWebSocket(wsUrl);
|
|
96
|
+
}
|
|
97
|
+
async disconnect() {
|
|
98
|
+
this.running = false;
|
|
99
|
+
if (this.heartbeatInterval) clearInterval(this.heartbeatInterval);
|
|
100
|
+
this.ws?.close(1e3);
|
|
101
|
+
await this.saveState();
|
|
102
|
+
}
|
|
103
|
+
async openWebSocket(url) {
|
|
104
|
+
this.ws = new ws.WebSocket(url, { headers: { "User-Agent": "HyperClaw/4.0.2" } });
|
|
105
|
+
this.ws.on("message", async (data) => {
|
|
106
|
+
const payload = JSON.parse(data.toString());
|
|
107
|
+
await this.handlePayload(payload);
|
|
108
|
+
});
|
|
109
|
+
this.ws.on("close", (code) => {
|
|
110
|
+
if (this.heartbeatInterval) clearInterval(this.heartbeatInterval);
|
|
111
|
+
if (!this.running) return;
|
|
112
|
+
const resumable = ![
|
|
113
|
+
1e3,
|
|
114
|
+
4004,
|
|
115
|
+
4010,
|
|
116
|
+
4011,
|
|
117
|
+
4012,
|
|
118
|
+
4013,
|
|
119
|
+
4014
|
|
120
|
+
].includes(code);
|
|
121
|
+
console.log(chalk.default.yellow(` ⚠ Discord WS closed (${code}) — ${resumable ? "resuming" : "reconnecting"} in 5s`));
|
|
122
|
+
setTimeout(() => {
|
|
123
|
+
if (this.running) {
|
|
124
|
+
const url$1 = resumable && this.resumeGatewayUrl ? this.resumeGatewayUrl + "/?v=10&encoding=json" : "wss://gateway.discord.gg/?v=10&encoding=json";
|
|
125
|
+
this.openWebSocket(url$1);
|
|
126
|
+
}
|
|
127
|
+
}, 5e3);
|
|
128
|
+
});
|
|
129
|
+
this.ws.on("error", (e) => console.log(chalk.default.yellow(` ⚠ Discord WS error: ${e.message}`)));
|
|
130
|
+
}
|
|
131
|
+
async handlePayload(payload) {
|
|
132
|
+
const { op, d, s, t } = payload;
|
|
133
|
+
if (s !== null && s !== void 0) this.lastSequence = s;
|
|
134
|
+
switch (op) {
|
|
135
|
+
case OPC.HELLO:
|
|
136
|
+
this.startHeartbeat(d.heartbeat_interval);
|
|
137
|
+
if (this.sessionId && this.lastSequence) this.resume();
|
|
138
|
+
else this.identify();
|
|
139
|
+
break;
|
|
140
|
+
case OPC.HEARTBEAT_ACK: break;
|
|
141
|
+
case OPC.HEARTBEAT:
|
|
142
|
+
this.sendWs({
|
|
143
|
+
op: OPC.HEARTBEAT,
|
|
144
|
+
d: this.lastSequence
|
|
145
|
+
});
|
|
146
|
+
break;
|
|
147
|
+
case OPC.RECONNECT:
|
|
148
|
+
this.ws?.close(4e3);
|
|
149
|
+
break;
|
|
150
|
+
case OPC.INVALID_SESSION:
|
|
151
|
+
if (d) setTimeout(() => this.resume(), 2e3);
|
|
152
|
+
else {
|
|
153
|
+
this.sessionId = null;
|
|
154
|
+
this.lastSequence = null;
|
|
155
|
+
setTimeout(() => this.identify(), 2e3);
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
case OPC.DISPATCH:
|
|
159
|
+
await this.handleEvent(t, d);
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
identify() {
|
|
164
|
+
const intents = INTENTS.GUILDS | INTENTS.GUILD_MESSAGES | INTENTS.GUILD_MESSAGE_CONTENT | INTENTS.DIRECT_MESSAGES;
|
|
165
|
+
this.sendWs({
|
|
166
|
+
op: OPC.IDENTIFY,
|
|
167
|
+
d: {
|
|
168
|
+
token: this.token,
|
|
169
|
+
intents,
|
|
170
|
+
properties: {
|
|
171
|
+
os: process.platform,
|
|
172
|
+
browser: "HyperClaw",
|
|
173
|
+
device: "HyperClaw"
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
resume() {
|
|
179
|
+
this.sendWs({
|
|
180
|
+
op: OPC.RESUME,
|
|
181
|
+
d: {
|
|
182
|
+
token: this.token,
|
|
183
|
+
session_id: this.sessionId,
|
|
184
|
+
seq: this.lastSequence
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
startHeartbeat(interval) {
|
|
189
|
+
if (this.heartbeatInterval) clearInterval(this.heartbeatInterval);
|
|
190
|
+
this.heartbeatInterval = setInterval(() => {
|
|
191
|
+
this.sendWs({
|
|
192
|
+
op: OPC.HEARTBEAT,
|
|
193
|
+
d: this.lastSequence
|
|
194
|
+
});
|
|
195
|
+
}, interval);
|
|
196
|
+
}
|
|
197
|
+
sendWs(payload) {
|
|
198
|
+
if (this.ws?.readyState === ws.WebSocket.OPEN) this.ws.send(JSON.stringify(payload));
|
|
199
|
+
}
|
|
200
|
+
async handleEvent(type, data) {
|
|
201
|
+
switch (type) {
|
|
202
|
+
case "READY":
|
|
203
|
+
this.sessionId = data.session_id;
|
|
204
|
+
this.resumeGatewayUrl = data.resume_gateway_url;
|
|
205
|
+
this.botUser = data.user;
|
|
206
|
+
await this.saveState();
|
|
207
|
+
this.emit("ready", data.user);
|
|
208
|
+
break;
|
|
209
|
+
case "RESUMED":
|
|
210
|
+
console.log(chalk.default.gray(" Discord session resumed"));
|
|
211
|
+
break;
|
|
212
|
+
case "MESSAGE_CREATE":
|
|
213
|
+
await this.handleMessage(data);
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
async handleMessage(msg) {
|
|
218
|
+
if (msg.author.id === this.botUser?.id) return;
|
|
219
|
+
if (msg.author.bot) return;
|
|
220
|
+
const isDM = !msg.channel_id.startsWith("0") && await this.isDirectMessage(msg.channel_id);
|
|
221
|
+
const userId = msg.author.id;
|
|
222
|
+
if (isDM) {
|
|
223
|
+
const allowed = await this.checkDMPolicy(userId, msg.channel_id, msg.content);
|
|
224
|
+
if (!allowed) return;
|
|
225
|
+
}
|
|
226
|
+
this.emit("message", {
|
|
227
|
+
id: msg.id,
|
|
228
|
+
channelId: "discord",
|
|
229
|
+
from: userId,
|
|
230
|
+
fromUsername: msg.author.global_name || msg.author.username,
|
|
231
|
+
chatId: msg.channel_id,
|
|
232
|
+
text: msg.content,
|
|
233
|
+
timestamp: msg.timestamp,
|
|
234
|
+
isDM
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
dmChannelCache = /* @__PURE__ */ new Set();
|
|
238
|
+
async isDirectMessage(channelId) {
|
|
239
|
+
if (this.dmChannelCache.has(channelId)) return true;
|
|
240
|
+
try {
|
|
241
|
+
const channel = await discordRest(this.token, "GET", `/channels/${channelId}`);
|
|
242
|
+
if (channel.type === 1) {
|
|
243
|
+
this.dmChannelCache.add(channelId);
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
} catch {}
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
async checkDMPolicy(userId, channelId, text) {
|
|
250
|
+
if (this.config.dmPolicy === "none") return false;
|
|
251
|
+
if (this.config.dmPolicy === "open") return true;
|
|
252
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
253
|
+
if (this.config.allowFrom.includes(userId)) return true;
|
|
254
|
+
await this.sendMessage(channelId, "🦅 **HyperClaw**\n\nYou are not on the allowlist.");
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
if (this.config.dmPolicy === "pairing") {
|
|
258
|
+
if (this.config.approvedPairings.includes(userId)) return true;
|
|
259
|
+
const upper = text.trim().toUpperCase();
|
|
260
|
+
if (this.config.pendingPairings[upper]) {
|
|
261
|
+
this.config.approvedPairings.push(userId);
|
|
262
|
+
delete this.config.pendingPairings[upper];
|
|
263
|
+
await this.saveState();
|
|
264
|
+
await this.sendMessage(channelId, "🦅 **Paired!** You can now send messages.");
|
|
265
|
+
this.emit("pairing:approved", {
|
|
266
|
+
userId,
|
|
267
|
+
channelId: "discord"
|
|
268
|
+
});
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
const code = this.generateCode();
|
|
272
|
+
this.config.pendingPairings[code] = userId;
|
|
273
|
+
await this.saveState();
|
|
274
|
+
await this.sendMessage(channelId, `🦅 **HyperClaw Pairing**\n\nSend the owner this code:\n\`${code}\`\n\nApprove with:\n\`hyperclaw pairing approve discord ${code}\``);
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
async sendMessage(channelId, content) {
|
|
280
|
+
const chunks = content.match(/.{1,2000}/gs) || [content];
|
|
281
|
+
let last = null;
|
|
282
|
+
for (const chunk of chunks) last = await discordRest(this.token, "POST", `/channels/${channelId}/messages`, { content: chunk });
|
|
283
|
+
return last;
|
|
284
|
+
}
|
|
285
|
+
async sendTyping(channelId) {
|
|
286
|
+
await discordRest(this.token, "POST", `/channels/${channelId}/typing`).catch(() => {});
|
|
287
|
+
}
|
|
288
|
+
async createDMChannel(userId) {
|
|
289
|
+
const ch = await discordRest(this.token, "POST", "/users/@me/channels", { recipient_id: userId });
|
|
290
|
+
return ch.id;
|
|
291
|
+
}
|
|
292
|
+
async sendDM(userId, content) {
|
|
293
|
+
const channelId = await this.createDMChannel(userId);
|
|
294
|
+
await this.sendMessage(channelId, content);
|
|
295
|
+
}
|
|
296
|
+
generateCode() {
|
|
297
|
+
const chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
298
|
+
return Array.from({ length: 6 }, () => chars[Math.floor(Math.random() * chars.length)]).join("");
|
|
299
|
+
}
|
|
300
|
+
approvePairing(code) {
|
|
301
|
+
const upper = code.toUpperCase();
|
|
302
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
303
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
304
|
+
delete this.config.pendingPairings[upper];
|
|
305
|
+
this.saveState();
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
addToAllowlist(userId) {
|
|
309
|
+
if (!this.config.allowFrom.includes(userId)) {
|
|
310
|
+
this.config.allowFrom.push(userId);
|
|
311
|
+
this.saveState();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
async loadState() {
|
|
315
|
+
try {
|
|
316
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
317
|
+
this.sessionId = s.sessionId || null;
|
|
318
|
+
this.lastSequence = s.lastSequence || null;
|
|
319
|
+
this.resumeGatewayUrl = s.resumeGatewayUrl || null;
|
|
320
|
+
if (s.pendingPairings) this.config.pendingPairings = s.pendingPairings;
|
|
321
|
+
if (s.approvedPairings) this.config.approvedPairings = s.approvedPairings;
|
|
322
|
+
} catch {}
|
|
323
|
+
}
|
|
324
|
+
async saveState() {
|
|
325
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
326
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
327
|
+
sessionId: this.sessionId,
|
|
328
|
+
lastSequence: this.lastSequence,
|
|
329
|
+
resumeGatewayUrl: this.resumeGatewayUrl,
|
|
330
|
+
pendingPairings: this.config.pendingPairings,
|
|
331
|
+
approvedPairings: this.config.approvedPairings
|
|
332
|
+
}, { spaces: 2 });
|
|
333
|
+
}
|
|
334
|
+
isRunning() {
|
|
335
|
+
return this.running;
|
|
336
|
+
}
|
|
337
|
+
getBotUser() {
|
|
338
|
+
return this.botUser;
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
//#endregion
|
|
343
|
+
exports.DiscordConnector = DiscordConnector;
|
|
@@ -0,0 +1,213 @@
|
|
|
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/feishu/src/connector.ts
|
|
10
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "feishu-state.json");
|
|
11
|
+
let feishuToken = null;
|
|
12
|
+
async function getAccessToken(appId, appSecret) {
|
|
13
|
+
if (feishuToken && feishuToken.expiresAt > Date.now() + 6e4) return feishuToken.token;
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const payload = JSON.stringify({
|
|
16
|
+
app_id: appId,
|
|
17
|
+
app_secret: appSecret
|
|
18
|
+
});
|
|
19
|
+
const req = https.default.request({
|
|
20
|
+
hostname: "open.feishu.cn",
|
|
21
|
+
port: 443,
|
|
22
|
+
path: "/open-apis/auth/v3/tenant_access_token/internal",
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: {
|
|
25
|
+
"Content-Type": "application/json",
|
|
26
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
27
|
+
}
|
|
28
|
+
}, (res) => {
|
|
29
|
+
let data = "";
|
|
30
|
+
res.on("data", (c) => data += c);
|
|
31
|
+
res.on("end", () => {
|
|
32
|
+
try {
|
|
33
|
+
const r = JSON.parse(data);
|
|
34
|
+
feishuToken = {
|
|
35
|
+
token: r.tenant_access_token,
|
|
36
|
+
expiresAt: Date.now() + r.expire * 1e3
|
|
37
|
+
};
|
|
38
|
+
resolve(r.tenant_access_token);
|
|
39
|
+
} catch {
|
|
40
|
+
reject(new Error("Token error"));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
req.on("error", reject);
|
|
45
|
+
req.write(payload);
|
|
46
|
+
req.end();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function feishuReq(token, method, endpoint, body) {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
const payload = body ? JSON.stringify(body) : null;
|
|
52
|
+
const req = https.default.request({
|
|
53
|
+
hostname: "open.feishu.cn",
|
|
54
|
+
port: 443,
|
|
55
|
+
path: `/open-apis${endpoint}`,
|
|
56
|
+
method,
|
|
57
|
+
headers: {
|
|
58
|
+
"Authorization": `Bearer ${token}`,
|
|
59
|
+
...payload ? {
|
|
60
|
+
"Content-Type": "application/json",
|
|
61
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
62
|
+
} : {}
|
|
63
|
+
}
|
|
64
|
+
}, (res) => {
|
|
65
|
+
let data = "";
|
|
66
|
+
res.on("data", (c) => data += c);
|
|
67
|
+
res.on("end", () => {
|
|
68
|
+
try {
|
|
69
|
+
const r = JSON.parse(data);
|
|
70
|
+
if (r.code !== 0) reject(new Error(r.msg));
|
|
71
|
+
else resolve(r);
|
|
72
|
+
} catch {
|
|
73
|
+
reject(new Error("Invalid JSON"));
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
req.on("error", reject);
|
|
78
|
+
if (payload) req.write(payload);
|
|
79
|
+
req.end();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
var FeishuConnector = class extends events.EventEmitter {
|
|
83
|
+
config;
|
|
84
|
+
running = false;
|
|
85
|
+
botOpenId = "";
|
|
86
|
+
constructor(config) {
|
|
87
|
+
super();
|
|
88
|
+
this.config = {
|
|
89
|
+
dmPolicy: "allowlist",
|
|
90
|
+
allowFrom: [],
|
|
91
|
+
approvedPairings: [],
|
|
92
|
+
pendingPairings: {},
|
|
93
|
+
...config
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async connect() {
|
|
97
|
+
const token = await getAccessToken(this.config.appId, this.config.appSecret);
|
|
98
|
+
const botInfo = await feishuReq(token, "GET", "/bot/v3/info");
|
|
99
|
+
this.botOpenId = botInfo.bot?.open_id || "";
|
|
100
|
+
await this.loadState();
|
|
101
|
+
this.running = true;
|
|
102
|
+
console.log(chalk.default.green(` 🦅 Feishu: ${botInfo.bot?.app_name || this.config.appId} connected`));
|
|
103
|
+
this.emit("connected", { openId: this.botOpenId });
|
|
104
|
+
}
|
|
105
|
+
disconnect() {
|
|
106
|
+
this.running = false;
|
|
107
|
+
}
|
|
108
|
+
handleChallenge(body) {
|
|
109
|
+
try {
|
|
110
|
+
const r = JSON.parse(body);
|
|
111
|
+
if (r.type === "url_verification") return JSON.stringify({ challenge: r.challenge });
|
|
112
|
+
} catch {}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
async handleWebhook(body) {
|
|
116
|
+
let payload;
|
|
117
|
+
try {
|
|
118
|
+
payload = JSON.parse(body);
|
|
119
|
+
} catch {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const event = payload.event;
|
|
123
|
+
if (!event || payload.header?.event_type !== "im.message.receive_v1") return;
|
|
124
|
+
const senderId = event.sender?.sender_id?.open_id;
|
|
125
|
+
const msgType = event.message?.message_type;
|
|
126
|
+
if (msgType !== "text" || !senderId) return;
|
|
127
|
+
let text = "";
|
|
128
|
+
try {
|
|
129
|
+
text = JSON.parse(event.message.content).text;
|
|
130
|
+
} catch {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (!text) return;
|
|
134
|
+
const chatId = event.message?.chat_id || senderId;
|
|
135
|
+
const allowed = await this.checkDMPolicy(senderId, text, chatId);
|
|
136
|
+
if (!allowed) return;
|
|
137
|
+
this.emit("message", {
|
|
138
|
+
id: event.message?.message_id,
|
|
139
|
+
channelId: "feishu",
|
|
140
|
+
from: senderId,
|
|
141
|
+
chatId,
|
|
142
|
+
text,
|
|
143
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
144
|
+
isDM: true
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
async checkDMPolicy(from, text, chatId) {
|
|
148
|
+
if (this.config.dmPolicy === "none") return false;
|
|
149
|
+
if (this.config.dmPolicy === "open") return true;
|
|
150
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
151
|
+
if (this.config.allowFrom.includes(from)) return true;
|
|
152
|
+
await this.sendMessage(chatId, "🦅 HyperClaw: Not on allowlist.");
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
if (this.config.dmPolicy === "pairing") {
|
|
156
|
+
if (this.config.approvedPairings.includes(from)) return true;
|
|
157
|
+
const upper = text.trim().toUpperCase();
|
|
158
|
+
if (this.config.pendingPairings[upper]) {
|
|
159
|
+
this.config.approvedPairings.push(from);
|
|
160
|
+
delete this.config.pendingPairings[upper];
|
|
161
|
+
await this.saveState();
|
|
162
|
+
await this.sendMessage(chatId, "🦅 Paired!");
|
|
163
|
+
this.emit("pairing:approved", {
|
|
164
|
+
userId: from,
|
|
165
|
+
channelId: "feishu"
|
|
166
|
+
});
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
170
|
+
this.config.pendingPairings[code] = from;
|
|
171
|
+
await this.saveState();
|
|
172
|
+
await this.sendMessage(chatId, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve feishu ${code}`);
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
async sendMessage(chatId, text) {
|
|
178
|
+
const token = await getAccessToken(this.config.appId, this.config.appSecret);
|
|
179
|
+
await feishuReq(token, "POST", "/im/v1/messages?receive_id_type=chat_id", {
|
|
180
|
+
receive_id: chatId,
|
|
181
|
+
msg_type: "text",
|
|
182
|
+
content: JSON.stringify({ text: text.slice(0, 4e3) })
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
approvePairing(code) {
|
|
186
|
+
const upper = code.toUpperCase();
|
|
187
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
188
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
189
|
+
delete this.config.pendingPairings[upper];
|
|
190
|
+
this.saveState();
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
async loadState() {
|
|
194
|
+
try {
|
|
195
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
196
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
197
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
198
|
+
} catch {}
|
|
199
|
+
}
|
|
200
|
+
async saveState() {
|
|
201
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
202
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
203
|
+
p: this.config.pendingPairings,
|
|
204
|
+
a: this.config.approvedPairings
|
|
205
|
+
}, { spaces: 2 });
|
|
206
|
+
}
|
|
207
|
+
isRunning() {
|
|
208
|
+
return this.running;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
//#endregion
|
|
213
|
+
exports.FeishuConnector = FeishuConnector;
|