hyperclaw 4.0.0 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -18
- package/dist/a2ui-protocol-CT_jDEU9.js +75 -0
- package/dist/agents-routing-683Q2JGp.js +129 -0
- package/dist/agents-routing-BpZBswBH.js +4 -0
- package/dist/api-keys-guide-Bzig1R5W.js +149 -0
- package/dist/api-keys-guide-Dq5Obbp4.js +149 -0
- package/dist/audit-BYxPlnTQ.js +248 -0
- package/dist/bounty-tools-C6LyzxM-.js +211 -0
- package/dist/browser-tools-CQBSbIuO.js +5 -0
- package/dist/browser-tools-YQmwRLLM.js +179 -0
- package/dist/claw-tasks-BRLUvFRD.js +80 -0
- package/dist/connector-3HnyH8fn.js +167 -0
- package/dist/connector-6PMZo5Ky.js +189 -0
- package/dist/connector-B6eoF3DD.js +181 -0
- package/dist/connector-B9tLG8UZ.js +196 -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-BliDVsJQ.js +239 -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-CRRWY5Wv.js +167 -0
- package/dist/connector-CXPQVGyI.js +85 -0
- package/dist/connector-Cdk1CXKi.js +194 -0
- package/dist/connector-CwlgFgjx.js +181 -0
- package/dist/connector-DFchk6l7.js +178 -0
- package/dist/connector-DKw7tRAy.js +192 -0
- package/dist/connector-DRv1ahC_.js +343 -0
- package/dist/connector-DU63KW94.js +165 -0
- package/dist/connector-Dbvb1Cj9.js +280 -0
- package/dist/connector-DcZdQcgR.js +173 -0
- package/dist/connector-DxKL8VvZ.js +182 -0
- package/dist/connector-T_YdZtzv.js +162 -0
- package/dist/connector-i4gOS9xL.js +154 -0
- package/dist/connector-rHXE1ZD2.js +167 -0
- package/dist/connector-wdUXChwa.js +172 -0
- package/dist/cost-tracker-pVE15Yq4.js +103 -0
- package/dist/credentials-store-BvnMPJwi.js +4 -0
- package/dist/credentials-store-sb-TRLwR.js +77 -0
- package/dist/cron-tasks-BvDFNyiE.js +82 -0
- package/dist/delivery-B-SJqXLn.js +95 -0
- package/dist/delivery-D5Z98EVq.js +95 -0
- package/dist/delivery-DCOXhXEO.js +5 -0
- package/dist/delivery-VgFeuu2J.js +5 -0
- package/dist/destructive-gate-m-dWqUFg.js +101 -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-Cf1XSfp9.js +4 -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-D49jnSd_.js +256 -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/form_data-B_hIUrxU.js +8657 -0
- package/dist/gmail-watch-setup-Czt8rXaX.js +40 -0
- package/dist/heartbeat-engine-CRqfPcFM.js +83 -0
- package/dist/hub-DTsqe5Bt.js +6 -0
- package/dist/hub-FrPTA33j.js +515 -0
- package/dist/hyperclawbot-D9KCtc4P.js +480 -0
- package/dist/hyperclawbot-DfMGowZC.js +480 -0
- package/dist/hyperclawbot-Dw27pJo4.js +480 -0
- package/dist/inference-CTWJeX9Q.js +922 -0
- package/dist/inference-ix607p7k.js +6 -0
- package/dist/knowledge-graph-DqA-Fztl.js +131 -0
- package/dist/loader-CISCqBto.js +400 -0
- package/dist/loader-CYMQ8VOS.js +4 -0
- package/dist/logger-8tEtAd3y.js +83 -0
- package/dist/manager-CPjeRe-6.js +4 -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/mcp-B_9Ber63.js +139 -0
- package/dist/mcp-loader-DSM5UiFG.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-auto-Bc7euou4.js +306 -0
- package/dist/memory-auto-DPfbkMVt.js +5 -0
- package/dist/memory-integration-DZExqWr4.js +91 -0
- package/dist/moltbook-B6ZeGN5_.js +81 -0
- package/dist/node-pwL6O_KX.js +222 -0
- package/dist/nodes-registry-CsPm_-CJ.js +52 -0
- package/dist/oauth-flow-CpWlgvNB.js +150 -0
- package/dist/oauth-provider-BZb6qOw5.js +110 -0
- package/dist/observability-B43YvNQV.js +89 -0
- package/dist/onboard-3q20ZyHj.js +9 -0
- package/dist/onboard-Bd_wsYdi.js +4086 -0
- package/dist/onboard-CAN7x3me.js +3026 -0
- package/dist/onboard-DnegOHMh.js +3026 -0
- 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-NJQsmiBE.js +189 -0
- package/dist/pairing-DU0_J28n.js +87 -0
- package/dist/pairing-DWllbSbO.js +4 -0
- package/dist/pc-access-Ly-uA8mn.js +8 -0
- package/dist/pc-access-NxBvTrRj.js +819 -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/renderer-pqlDRKbH.js +225 -0
- package/dist/rules-BooT_qFP.js +103 -0
- package/dist/run-main.js +366 -1109
- package/dist/runner-Bu--_RXw.js +810 -0
- package/dist/runner-D1rjuMTJ.js +810 -0
- package/dist/sdk/index.js +2 -2
- package/dist/sdk/index.mjs +2 -2
- package/dist/security-C-5URby1.js +73 -0
- package/dist/security-_xve79aq.js +4 -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 +1047 -0
- package/dist/server-DU9POoWc.js +4 -0
- package/dist/server-RBqwE_GN.js +4 -0
- package/dist/session-store-CujxByI6.js +113 -0
- package/dist/session-store-qpJUg2M1.js +5 -0
- package/dist/sessions-tools-CB2qbwIk.js +5 -0
- package/dist/sessions-tools-DHMaTZIs.js +95 -0
- package/dist/skill-loader-BkceKkIg.js +7 -0
- package/dist/skill-loader-DhgIwK4J.js +159 -0
- package/dist/skill-runtime--LqxWrp5.js +102 -0
- package/dist/skill-runtime-C5l0Tgt-.js +5 -0
- package/dist/skill-runtime-DsXK_HYG.js +102 -0
- package/dist/skill-runtime-IVTiqrMR.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-DWCUhnD4.js +20 -0
- package/dist/src-cfRTjFef.js +63 -0
- package/dist/sub-agent-tools-BD9DF8_g.js +39 -0
- package/dist/sub-agent-tools-V7b3T9_s.js +39 -0
- package/dist/tool-policy-DNvNRnve.js +189 -0
- package/dist/tts-elevenlabs-BUOGKL-k.js +61 -0
- package/dist/update-check-BD4qH7Am.js +81 -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/voice-transcription-CbQBToY0.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-DraMPxdl.js +139 -0
- package/package.json +1 -1
|
@@ -0,0 +1,267 @@
|
|
|
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/tlon/src/connector.ts
|
|
11
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "tlon-state.json");
|
|
12
|
+
var TlonConnector = class extends events.EventEmitter {
|
|
13
|
+
config;
|
|
14
|
+
cookie = null;
|
|
15
|
+
channelUid = null;
|
|
16
|
+
running = false;
|
|
17
|
+
lastEventId = 0;
|
|
18
|
+
sseAbort = null;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
super();
|
|
21
|
+
this.config = {
|
|
22
|
+
dmPolicy: "pairing",
|
|
23
|
+
allowFrom: [],
|
|
24
|
+
approvedPairings: [],
|
|
25
|
+
pendingPairings: {},
|
|
26
|
+
...config
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async connect() {
|
|
30
|
+
await this.loadState();
|
|
31
|
+
await this.login();
|
|
32
|
+
await this.openChannel();
|
|
33
|
+
await this.subscribe();
|
|
34
|
+
this.running = true;
|
|
35
|
+
console.log(chalk.default.green(` 🦅 Tlon: connected as ${this.config.ship}`));
|
|
36
|
+
this.emit("connected", { ship: this.config.ship });
|
|
37
|
+
this.listenSSE();
|
|
38
|
+
}
|
|
39
|
+
disconnect() {
|
|
40
|
+
this.running = false;
|
|
41
|
+
this.sseAbort?.abort();
|
|
42
|
+
}
|
|
43
|
+
async login() {
|
|
44
|
+
const body = `password=${encodeURIComponent(this.config.code)}`;
|
|
45
|
+
const cookie = await this.urbitReq("POST", "/~/login", body, "application/x-www-form-urlencoded");
|
|
46
|
+
if (!cookie) throw new Error("Tlon: login failed — check ship URL and code");
|
|
47
|
+
this.cookie = cookie;
|
|
48
|
+
}
|
|
49
|
+
async openChannel() {
|
|
50
|
+
this.channelUid = `hyperclaw-${Date.now()}`;
|
|
51
|
+
await this.urbitPut([]);
|
|
52
|
+
}
|
|
53
|
+
async subscribe() {
|
|
54
|
+
const actions = [];
|
|
55
|
+
actions.push({
|
|
56
|
+
id: ++this.lastEventId,
|
|
57
|
+
action: "subscribe",
|
|
58
|
+
ship: this.config.ship,
|
|
59
|
+
app: "chat-store",
|
|
60
|
+
path: "/keys"
|
|
61
|
+
});
|
|
62
|
+
if (this.config.group) {
|
|
63
|
+
const [groupShip, groupName] = this.config.group.split("/");
|
|
64
|
+
actions.push({
|
|
65
|
+
id: ++this.lastEventId,
|
|
66
|
+
action: "subscribe",
|
|
67
|
+
ship: groupShip,
|
|
68
|
+
app: "graph-store",
|
|
69
|
+
path: `/updates`
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
await this.urbitPut(actions);
|
|
73
|
+
}
|
|
74
|
+
listenSSE() {
|
|
75
|
+
this.sseAbort = new AbortController();
|
|
76
|
+
const url = new URL(`/~/channel/${this.channelUid}`, this.config.shipUrl);
|
|
77
|
+
const isHttps = url.protocol === "https:";
|
|
78
|
+
const mod = isHttps ? https.default : http.default;
|
|
79
|
+
const doRequest = () => {
|
|
80
|
+
if (!this.running) return;
|
|
81
|
+
const req = mod.request({
|
|
82
|
+
hostname: url.hostname,
|
|
83
|
+
port: url.port || (isHttps ? 443 : 80),
|
|
84
|
+
path: url.pathname,
|
|
85
|
+
method: "GET",
|
|
86
|
+
headers: {
|
|
87
|
+
"Cookie": this.cookie,
|
|
88
|
+
"Accept": "text/event-stream"
|
|
89
|
+
}
|
|
90
|
+
}, async (res) => {
|
|
91
|
+
let buf = "";
|
|
92
|
+
res.on("data", async (chunk) => {
|
|
93
|
+
buf += chunk.toString();
|
|
94
|
+
const lines = buf.split("\n");
|
|
95
|
+
buf = lines.pop() || "";
|
|
96
|
+
for (const line of lines) {
|
|
97
|
+
if (!line.startsWith("data: ")) continue;
|
|
98
|
+
try {
|
|
99
|
+
const data = JSON.parse(line.slice(6));
|
|
100
|
+
await this.handleEvent(data);
|
|
101
|
+
} catch {}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
res.on("end", () => {
|
|
105
|
+
if (this.running) setTimeout(doRequest, 3e3);
|
|
106
|
+
});
|
|
107
|
+
res.on("error", () => {
|
|
108
|
+
if (this.running) setTimeout(doRequest, 5e3);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
req.on("error", () => {
|
|
112
|
+
if (this.running) setTimeout(doRequest, 5e3);
|
|
113
|
+
});
|
|
114
|
+
req.end();
|
|
115
|
+
};
|
|
116
|
+
doRequest();
|
|
117
|
+
}
|
|
118
|
+
async handleEvent(event) {
|
|
119
|
+
if (event.id) await this.urbitDelete(event.id).catch(() => {});
|
|
120
|
+
const response = event.response;
|
|
121
|
+
if (!response || response === "poke" || response === "subscribe") return;
|
|
122
|
+
if (response === "diff" && event.json?.["chat-update"]?.["message"]) {
|
|
123
|
+
const msg = event.json["chat-update"]["message"];
|
|
124
|
+
const path$2 = msg.path || "";
|
|
125
|
+
const envelope = msg.envelope;
|
|
126
|
+
if (!envelope) return;
|
|
127
|
+
const author = envelope.author || "unknown";
|
|
128
|
+
const text = envelope.letter?.text || "";
|
|
129
|
+
if (!text || author === this.config.ship) return;
|
|
130
|
+
const allowed = await this.checkPolicy(author, path$2, text);
|
|
131
|
+
if (!allowed) return;
|
|
132
|
+
this.emit("message", {
|
|
133
|
+
id: `tlon-${envelope.uid || Date.now()}`,
|
|
134
|
+
channelId: "tlon",
|
|
135
|
+
from: author,
|
|
136
|
+
chatId: path$2,
|
|
137
|
+
text,
|
|
138
|
+
timestamp: new Date(envelope.when || Date.now()).toISOString(),
|
|
139
|
+
isDM: path$2.startsWith("/~~/dm")
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async checkPolicy(author, chatId, text) {
|
|
144
|
+
if (this.config.dmPolicy === "none") return false;
|
|
145
|
+
if (this.config.dmPolicy === "open") return true;
|
|
146
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
147
|
+
if (this.config.allowFrom.includes(author)) return true;
|
|
148
|
+
await this.sendDM(author, "🦅 You are not on the allowlist.");
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
if (this.config.dmPolicy === "pairing") {
|
|
152
|
+
if (this.config.approvedPairings.includes(author)) return true;
|
|
153
|
+
const upper = text.trim().toUpperCase();
|
|
154
|
+
if (this.config.pendingPairings[upper]) {
|
|
155
|
+
this.config.approvedPairings.push(author);
|
|
156
|
+
delete this.config.pendingPairings[upper];
|
|
157
|
+
await this.saveState();
|
|
158
|
+
await this.sendDM(author, "🦅 Paired! You can now chat with the assistant.");
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
162
|
+
this.config.pendingPairings[code] = author;
|
|
163
|
+
await this.saveState();
|
|
164
|
+
await this.sendDM(author, `🦅 Pairing required. Code: ${code}\nApprove: hyperclaw pairing approve tlon ${code}`);
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
async sendDM(ship, text) {
|
|
170
|
+
const dmPath = `/~~/dm/${ship}/`;
|
|
171
|
+
await this.poke("chat-hook", "json", { "chat-action": { "message": {
|
|
172
|
+
path: dmPath,
|
|
173
|
+
envelope: {
|
|
174
|
+
uid: Math.random().toString(36).slice(2),
|
|
175
|
+
number: Date.now(),
|
|
176
|
+
author: this.config.ship,
|
|
177
|
+
when: Date.now(),
|
|
178
|
+
letter: { text }
|
|
179
|
+
}
|
|
180
|
+
} } });
|
|
181
|
+
}
|
|
182
|
+
async sendToPath(chatPath, text) {
|
|
183
|
+
await this.poke("chat-hook", "json", { "chat-action": { "message": {
|
|
184
|
+
path: chatPath,
|
|
185
|
+
envelope: {
|
|
186
|
+
uid: Math.random().toString(36).slice(2),
|
|
187
|
+
number: Date.now(),
|
|
188
|
+
author: this.config.ship,
|
|
189
|
+
when: Date.now(),
|
|
190
|
+
letter: { text }
|
|
191
|
+
}
|
|
192
|
+
} } });
|
|
193
|
+
}
|
|
194
|
+
async poke(app, mark, json) {
|
|
195
|
+
await this.urbitPut([{
|
|
196
|
+
id: ++this.lastEventId,
|
|
197
|
+
action: "poke",
|
|
198
|
+
ship: this.config.ship,
|
|
199
|
+
app,
|
|
200
|
+
mark,
|
|
201
|
+
json
|
|
202
|
+
}]);
|
|
203
|
+
}
|
|
204
|
+
approvePairing(code) {
|
|
205
|
+
const upper = code.toUpperCase();
|
|
206
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
207
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
208
|
+
delete this.config.pendingPairings[upper];
|
|
209
|
+
this.saveState();
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
async urbitReq(method, p, body, contentType) {
|
|
213
|
+
return new Promise((resolve, reject) => {
|
|
214
|
+
const url = new URL(p, this.config.shipUrl);
|
|
215
|
+
const isHttps = url.protocol === "https:";
|
|
216
|
+
const mod = isHttps ? https.default : http.default;
|
|
217
|
+
const headers = {};
|
|
218
|
+
if (this.cookie) headers["Cookie"] = this.cookie;
|
|
219
|
+
if (body) {
|
|
220
|
+
headers["Content-Type"] = contentType || "application/json";
|
|
221
|
+
headers["Content-Length"] = String(Buffer.byteLength(body));
|
|
222
|
+
}
|
|
223
|
+
const req = mod.request({
|
|
224
|
+
hostname: url.hostname,
|
|
225
|
+
port: url.port || (isHttps ? 443 : 80),
|
|
226
|
+
path: url.pathname,
|
|
227
|
+
method,
|
|
228
|
+
headers
|
|
229
|
+
}, (res) => {
|
|
230
|
+
const setCookie = res.headers["set-cookie"]?.[0]?.split(";")[0] || null;
|
|
231
|
+
let data = "";
|
|
232
|
+
res.on("data", (c) => data += c);
|
|
233
|
+
res.on("end", () => resolve(setCookie || data || null));
|
|
234
|
+
});
|
|
235
|
+
req.on("error", reject);
|
|
236
|
+
if (body) req.write(body);
|
|
237
|
+
req.end();
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
async urbitPut(actions) {
|
|
241
|
+
const body = JSON.stringify(actions);
|
|
242
|
+
await this.urbitReq("PUT", `/~/channel/${this.channelUid}`, body);
|
|
243
|
+
}
|
|
244
|
+
async urbitDelete(eventId) {
|
|
245
|
+
await this.urbitReq("DELETE", `/~/channel/${this.channelUid}/${eventId}`);
|
|
246
|
+
}
|
|
247
|
+
async loadState() {
|
|
248
|
+
try {
|
|
249
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
250
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
251
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
252
|
+
} catch {}
|
|
253
|
+
}
|
|
254
|
+
async saveState() {
|
|
255
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
256
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
257
|
+
p: this.config.pendingPairings,
|
|
258
|
+
a: this.config.approvedPairings
|
|
259
|
+
}, { spaces: 2 });
|
|
260
|
+
}
|
|
261
|
+
isRunning() {
|
|
262
|
+
return this.running;
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
//#endregion
|
|
267
|
+
exports.TlonConnector = TlonConnector;
|
|
@@ -0,0 +1,239 @@
|
|
|
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 events = require_chunk.__toESM(require("events"));
|
|
8
|
+
|
|
9
|
+
//#region extensions/twitch/src/connector.ts
|
|
10
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "twitch-state.json");
|
|
11
|
+
const TWITCH_IRC_WS = "wss://irc-ws.chat.twitch.tv:443";
|
|
12
|
+
var TwitchConnector = class extends events.EventEmitter {
|
|
13
|
+
config;
|
|
14
|
+
ws = null;
|
|
15
|
+
running = false;
|
|
16
|
+
reconnectDelay = 1e3;
|
|
17
|
+
pingInterval = null;
|
|
18
|
+
constructor(config) {
|
|
19
|
+
super();
|
|
20
|
+
this.config = {
|
|
21
|
+
commandPrefix: "!",
|
|
22
|
+
whispers: true,
|
|
23
|
+
dmPolicy: "pairing",
|
|
24
|
+
allowFrom: [],
|
|
25
|
+
approvedPairings: [],
|
|
26
|
+
pendingPairings: {},
|
|
27
|
+
modsBypass: true,
|
|
28
|
+
...config
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async connect() {
|
|
32
|
+
await this.loadState();
|
|
33
|
+
await this.doConnect();
|
|
34
|
+
}
|
|
35
|
+
doConnect() {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
const ws$1 = new ws.WebSocket(TWITCH_IRC_WS);
|
|
38
|
+
this.ws = ws$1;
|
|
39
|
+
ws$1.once("open", () => {
|
|
40
|
+
ws$1.send("CAP REQ :twitch.tv/membership twitch.tv/tags twitch.tv/commands");
|
|
41
|
+
ws$1.send(`PASS ${this.config.oauthToken}`);
|
|
42
|
+
ws$1.send(`NICK ${this.config.username}`);
|
|
43
|
+
for (const ch of this.config.channels) ws$1.send(`JOIN #${ch.replace(/^#/, "").toLowerCase()}`);
|
|
44
|
+
this.running = true;
|
|
45
|
+
this.reconnectDelay = 1e3;
|
|
46
|
+
this.pingInterval = setInterval(() => ws$1.send("PING :tmi.twitch.tv"), 6e4);
|
|
47
|
+
console.log(chalk.default.green(` 🦅 Twitch: connected as ${this.config.username}, joined ${this.config.channels.join(", ")}`));
|
|
48
|
+
this.emit("connected", { username: this.config.username });
|
|
49
|
+
resolve();
|
|
50
|
+
});
|
|
51
|
+
ws$1.on("message", async (raw) => {
|
|
52
|
+
const lines = raw.toString().split("\r\n").filter(Boolean);
|
|
53
|
+
for (const line of lines) await this.handleLine(line);
|
|
54
|
+
});
|
|
55
|
+
ws$1.on("close", () => {
|
|
56
|
+
if (this.pingInterval) {
|
|
57
|
+
clearInterval(this.pingInterval);
|
|
58
|
+
this.pingInterval = null;
|
|
59
|
+
}
|
|
60
|
+
if (this.running) {
|
|
61
|
+
console.log(chalk.default.yellow(` ⚠ Twitch: disconnected, reconnecting in ${this.reconnectDelay}ms`));
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
this.reconnectDelay = Math.min(this.reconnectDelay * 2, 3e4);
|
|
64
|
+
this.doConnect();
|
|
65
|
+
}, this.reconnectDelay);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
ws$1.on("error", (err) => {
|
|
69
|
+
console.log(chalk.default.yellow(` ⚠ Twitch: ${err.message}`));
|
|
70
|
+
if (!this.running) reject(err);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
disconnect() {
|
|
75
|
+
this.running = false;
|
|
76
|
+
if (this.pingInterval) {
|
|
77
|
+
clearInterval(this.pingInterval);
|
|
78
|
+
this.pingInterval = null;
|
|
79
|
+
}
|
|
80
|
+
this.ws?.close();
|
|
81
|
+
this.ws = null;
|
|
82
|
+
}
|
|
83
|
+
async handleLine(line) {
|
|
84
|
+
if (line === "PING :tmi.twitch.tv") {
|
|
85
|
+
this.ws?.send("PONG :tmi.twitch.tv");
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const tags = this.parseTags(line);
|
|
89
|
+
const parsed = this.parseIRC(line);
|
|
90
|
+
if (!parsed) return;
|
|
91
|
+
const { command, prefix, params, trailing } = parsed;
|
|
92
|
+
const username = prefix?.split("!")[0]?.toLowerCase() || "";
|
|
93
|
+
if (username === this.config.username.toLowerCase()) return;
|
|
94
|
+
if (command === "PRIVMSG") {
|
|
95
|
+
const channel = params[0];
|
|
96
|
+
const text = trailing || "";
|
|
97
|
+
const isWhisper = false;
|
|
98
|
+
if (this.config.commandPrefix && !text.startsWith(this.config.commandPrefix) && !isWhisper) return;
|
|
99
|
+
const body = this.config.commandPrefix ? text.slice(this.config.commandPrefix.length).trim() : text;
|
|
100
|
+
if (!body) return;
|
|
101
|
+
const isMod = tags["mod"] === "1" || tags["badges"]?.includes("broadcaster");
|
|
102
|
+
const allowed = await this.checkPolicy(username, channel, body, isMod);
|
|
103
|
+
if (!allowed) return;
|
|
104
|
+
this.emit("message", {
|
|
105
|
+
id: tags["id"] || `twitch-${Date.now()}`,
|
|
106
|
+
channelId: "twitch",
|
|
107
|
+
from: username,
|
|
108
|
+
displayName: tags["display-name"] || username,
|
|
109
|
+
chatId: channel,
|
|
110
|
+
text: body,
|
|
111
|
+
timestamp: tags["tmi-sent-ts"] ? new Date(Number(tags["tmi-sent-ts"])).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
|
|
112
|
+
isDM: false,
|
|
113
|
+
isMod
|
|
114
|
+
});
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (command === "WHISPER" && this.config.whispers) {
|
|
118
|
+
const text = trailing || "";
|
|
119
|
+
if (!text) return;
|
|
120
|
+
const allowed = await this.checkPolicy(username, "whisper", text, false);
|
|
121
|
+
if (!allowed) return;
|
|
122
|
+
this.emit("message", {
|
|
123
|
+
id: `twitch-whisper-${Date.now()}`,
|
|
124
|
+
channelId: "twitch",
|
|
125
|
+
from: username,
|
|
126
|
+
displayName: tags["display-name"] || username,
|
|
127
|
+
chatId: `whisper:${username}`,
|
|
128
|
+
text,
|
|
129
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
130
|
+
isDM: true,
|
|
131
|
+
isMod: false
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async checkPolicy(username, chatId, text, isMod) {
|
|
136
|
+
if (this.config.dmPolicy === "none") return false;
|
|
137
|
+
if (this.config.dmPolicy === "open") return true;
|
|
138
|
+
if (this.config.modsBypass && isMod) return true;
|
|
139
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
140
|
+
if (this.config.allowFrom.includes(username)) return true;
|
|
141
|
+
await this.sendChat(chatId, `@${username} You are not on the allowlist.`);
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
if (this.config.dmPolicy === "pairing") {
|
|
145
|
+
if (this.config.approvedPairings.includes(username)) return true;
|
|
146
|
+
const upper = text.trim().toUpperCase();
|
|
147
|
+
if (this.config.pendingPairings[upper]) {
|
|
148
|
+
this.config.approvedPairings.push(username);
|
|
149
|
+
delete this.config.pendingPairings[upper];
|
|
150
|
+
await this.saveState();
|
|
151
|
+
await this.sendChat(chatId, `@${username} Paired! You can now talk to the assistant.`);
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
155
|
+
this.config.pendingPairings[code] = username;
|
|
156
|
+
await this.saveState();
|
|
157
|
+
await this.sendChat(chatId, `@${username} Pairing required. Code: ${code} — approve: hyperclaw pairing approve twitch ${code}`);
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
async sendChat(channel, text) {
|
|
163
|
+
if (!this.ws || this.ws.readyState !== ws.WebSocket.OPEN) return;
|
|
164
|
+
const ch = channel.startsWith("#") ? channel : `#${channel}`;
|
|
165
|
+
const chunks = text.match(/.{1,490}/g) || [text];
|
|
166
|
+
for (const chunk of chunks) {
|
|
167
|
+
this.ws.send(`PRIVMSG ${ch} :${chunk}`);
|
|
168
|
+
await new Promise((r) => setTimeout(r, 150));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
async sendWhisper(username, text) {
|
|
172
|
+
if (!this.ws || this.ws.readyState !== ws.WebSocket.OPEN) return;
|
|
173
|
+
const ch = `#${this.config.channels[0]?.replace(/^#/, "") || this.config.username}`;
|
|
174
|
+
this.ws.send(`PRIVMSG ${ch} :/w ${username} ${text}`);
|
|
175
|
+
}
|
|
176
|
+
approvePairing(code) {
|
|
177
|
+
const upper = code.toUpperCase();
|
|
178
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
179
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
180
|
+
delete this.config.pendingPairings[upper];
|
|
181
|
+
this.saveState();
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
parseTags(line) {
|
|
185
|
+
if (!line.startsWith("@")) return {};
|
|
186
|
+
const tagStr = line.slice(1, line.indexOf(" "));
|
|
187
|
+
const tags = {};
|
|
188
|
+
for (const part of tagStr.split(";")) {
|
|
189
|
+
const [k, v] = part.split("=");
|
|
190
|
+
if (k) tags[k] = v || "";
|
|
191
|
+
}
|
|
192
|
+
return tags;
|
|
193
|
+
}
|
|
194
|
+
parseIRC(line) {
|
|
195
|
+
let rest = line.startsWith("@") ? line.slice(line.indexOf(" ") + 1) : line;
|
|
196
|
+
let prefix;
|
|
197
|
+
if (rest.startsWith(":")) {
|
|
198
|
+
const spaceIdx = rest.indexOf(" ");
|
|
199
|
+
prefix = rest.slice(1, spaceIdx);
|
|
200
|
+
rest = rest.slice(spaceIdx + 1);
|
|
201
|
+
}
|
|
202
|
+
const trailingIdx = rest.indexOf(" :");
|
|
203
|
+
let trailing;
|
|
204
|
+
if (trailingIdx !== -1) {
|
|
205
|
+
trailing = rest.slice(trailingIdx + 2);
|
|
206
|
+
rest = rest.slice(0, trailingIdx);
|
|
207
|
+
}
|
|
208
|
+
const parts = rest.trim().split(" ");
|
|
209
|
+
const command = parts[0];
|
|
210
|
+
const params = parts.slice(1).filter(Boolean);
|
|
211
|
+
if (!command) return null;
|
|
212
|
+
return {
|
|
213
|
+
command,
|
|
214
|
+
prefix,
|
|
215
|
+
params,
|
|
216
|
+
trailing
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
async loadState() {
|
|
220
|
+
try {
|
|
221
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
222
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
223
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
224
|
+
} catch {}
|
|
225
|
+
}
|
|
226
|
+
async saveState() {
|
|
227
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
228
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
229
|
+
p: this.config.pendingPairings,
|
|
230
|
+
a: this.config.approvedPairings
|
|
231
|
+
}, { spaces: 2 });
|
|
232
|
+
}
|
|
233
|
+
isRunning() {
|
|
234
|
+
return this.running;
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
//#endregion
|
|
239
|
+
exports.TwitchConnector = TwitchConnector;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
const chalk = require_chunk.__toESM(require("chalk"));
|
|
3
|
+
const events = require_chunk.__toESM(require("events"));
|
|
4
|
+
const irc = require_chunk.__toESM(require("irc"));
|
|
5
|
+
|
|
6
|
+
//#region extensions/irc/src/connector.ts
|
|
7
|
+
var IrcConnector = class extends events.EventEmitter {
|
|
8
|
+
client = null;
|
|
9
|
+
config;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
super();
|
|
12
|
+
this.config = {
|
|
13
|
+
channels: [],
|
|
14
|
+
dmPolicy: "pairing",
|
|
15
|
+
allowFrom: [],
|
|
16
|
+
...config
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async connect() {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const channels = (this.config.channels || []).map((c) => c.startsWith("#") ? c : `#${c}`);
|
|
22
|
+
this.client = new irc.default.Client(this.config.server, this.config.nick, {
|
|
23
|
+
channels,
|
|
24
|
+
autoConnect: true,
|
|
25
|
+
debug: false,
|
|
26
|
+
showErrors: true,
|
|
27
|
+
stripColors: true
|
|
28
|
+
});
|
|
29
|
+
this.client.on("registered", () => {
|
|
30
|
+
console.log(chalk.default.green(` 🦅 IRC: ${this.config.nick} on ${this.config.server} connected`));
|
|
31
|
+
this.emit("connected", {
|
|
32
|
+
server: this.config.server,
|
|
33
|
+
nick: this.config.nick
|
|
34
|
+
});
|
|
35
|
+
resolve();
|
|
36
|
+
});
|
|
37
|
+
this.client.on("error", (err) => {
|
|
38
|
+
console.log(chalk.default.yellow(` ⚠ IRC error: ${err.message}`));
|
|
39
|
+
reject(err);
|
|
40
|
+
});
|
|
41
|
+
this.client.on("message", (from, to, message) => {
|
|
42
|
+
const isChannel = to.startsWith("#");
|
|
43
|
+
const chatId = isChannel ? to : from;
|
|
44
|
+
const text = message.trim();
|
|
45
|
+
if (!text) return;
|
|
46
|
+
if (!isChannel && this.config.dmPolicy === "none") return;
|
|
47
|
+
if (!isChannel && this.config.dmPolicy === "allowlist" && this.config.allowFrom?.length) {
|
|
48
|
+
if (!this.config.allowFrom.includes(from)) return;
|
|
49
|
+
}
|
|
50
|
+
this.emit("message", {
|
|
51
|
+
chatId,
|
|
52
|
+
text,
|
|
53
|
+
from,
|
|
54
|
+
to,
|
|
55
|
+
isChannel
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
this.client.on("pm", (from, message) => {
|
|
59
|
+
const text = message.trim();
|
|
60
|
+
if (!text) return;
|
|
61
|
+
if (this.config.dmPolicy === "allowlist" && this.config.allowFrom?.length) {
|
|
62
|
+
if (!this.config.allowFrom.includes(from)) return;
|
|
63
|
+
}
|
|
64
|
+
this.emit("message", {
|
|
65
|
+
chatId: from,
|
|
66
|
+
text,
|
|
67
|
+
from,
|
|
68
|
+
to: from,
|
|
69
|
+
isChannel: false
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async sendMessage(chatId, text) {
|
|
75
|
+
if (!this.client) throw new Error("IRC not connected");
|
|
76
|
+
const lines = text.split("\n").filter(Boolean);
|
|
77
|
+
for (const line of lines) this.client.say(chatId, line);
|
|
78
|
+
}
|
|
79
|
+
async disconnect() {
|
|
80
|
+
if (this.client) {
|
|
81
|
+
this.client.disconnect();
|
|
82
|
+
this.client = null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
exports.IrcConnector = IrcConnector;
|