hyperclaw 4.0.1 → 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 +7 -4
- 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-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 +2 -2
- 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-D5Z98EVq.js +95 -0
- package/dist/delivery-DCOXhXEO.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-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-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-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 +289 -1031
- 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 +2 -2
- package/dist/server-DU9POoWc.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-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,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 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/signal/src/connector.ts
|
|
11
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "signal-state.json");
|
|
12
|
+
function cliReq(baseUrl, method, endpoint, body) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const url = new URL(baseUrl + endpoint);
|
|
15
|
+
const isHttps = url.protocol === "https:";
|
|
16
|
+
const mod = isHttps ? https.default : http.default;
|
|
17
|
+
const payload = body ? JSON.stringify(body) : null;
|
|
18
|
+
const req = mod.request({
|
|
19
|
+
hostname: url.hostname,
|
|
20
|
+
port: url.port || (isHttps ? 443 : 8080),
|
|
21
|
+
path: url.pathname,
|
|
22
|
+
method,
|
|
23
|
+
headers: payload ? {
|
|
24
|
+
"Content-Type": "application/json",
|
|
25
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
26
|
+
} : {}
|
|
27
|
+
}, (res) => {
|
|
28
|
+
let data = "";
|
|
29
|
+
res.on("data", (c) => data += c);
|
|
30
|
+
res.on("end", () => {
|
|
31
|
+
if (!data.trim()) {
|
|
32
|
+
resolve({});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
resolve(JSON.parse(data));
|
|
37
|
+
} catch {
|
|
38
|
+
resolve({ raw: data });
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
req.on("error", reject);
|
|
43
|
+
if (payload) req.write(payload);
|
|
44
|
+
req.end();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
var SignalConnector = class extends events.EventEmitter {
|
|
48
|
+
config;
|
|
49
|
+
running = false;
|
|
50
|
+
pollTimer = null;
|
|
51
|
+
constructor(config) {
|
|
52
|
+
super();
|
|
53
|
+
this.config = {
|
|
54
|
+
dmPolicy: "allowlist",
|
|
55
|
+
allowFrom: [],
|
|
56
|
+
approvedPairings: [],
|
|
57
|
+
pendingPairings: {},
|
|
58
|
+
pollIntervalMs: 3e3,
|
|
59
|
+
...config
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async connect() {
|
|
63
|
+
await cliReq(this.config.signalCliUrl, "GET", `/v1/accounts`);
|
|
64
|
+
await this.loadState();
|
|
65
|
+
this.running = true;
|
|
66
|
+
console.log(chalk.default.green(` 🦅 Signal: ${this.config.phoneNumber} connected via signal-cli`));
|
|
67
|
+
this.emit("connected", { number: this.config.phoneNumber });
|
|
68
|
+
this.startPolling();
|
|
69
|
+
}
|
|
70
|
+
disconnect() {
|
|
71
|
+
this.running = false;
|
|
72
|
+
if (this.pollTimer) clearInterval(this.pollTimer);
|
|
73
|
+
}
|
|
74
|
+
startPolling() {
|
|
75
|
+
this.poll();
|
|
76
|
+
this.pollTimer = setInterval(() => this.poll(), this.config.pollIntervalMs);
|
|
77
|
+
}
|
|
78
|
+
async poll() {
|
|
79
|
+
try {
|
|
80
|
+
const messages = await cliReq(this.config.signalCliUrl, "GET", `/v1/receive/${encodeURIComponent(this.config.phoneNumber)}`);
|
|
81
|
+
if (!Array.isArray(messages)) return;
|
|
82
|
+
for (const envelope of messages) {
|
|
83
|
+
const dm = envelope.envelope?.dataMessage;
|
|
84
|
+
const from = envelope.envelope?.source;
|
|
85
|
+
if (!dm?.message || !from) continue;
|
|
86
|
+
const allowed = await this.checkDMPolicy(from, dm.message);
|
|
87
|
+
if (!allowed) continue;
|
|
88
|
+
this.emit("message", {
|
|
89
|
+
id: envelope.envelope?.timestamp?.toString(),
|
|
90
|
+
channelId: "signal",
|
|
91
|
+
from,
|
|
92
|
+
chatId: from,
|
|
93
|
+
text: dm.message,
|
|
94
|
+
timestamp: new Date(envelope.envelope.timestamp).toISOString(),
|
|
95
|
+
isDM: true
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
} catch (e) {
|
|
99
|
+
if (this.running) console.log(chalk.default.yellow(` ⚠ Signal poll: ${e.message}`));
|
|
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: Not on 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!");
|
|
118
|
+
this.emit("pairing:approved", {
|
|
119
|
+
userId: from,
|
|
120
|
+
channelId: "signal"
|
|
121
|
+
});
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
125
|
+
this.config.pendingPairings[code] = from;
|
|
126
|
+
await this.saveState();
|
|
127
|
+
await this.sendMessage(from, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve signal ${code}`);
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
async sendMessage(recipient, text) {
|
|
133
|
+
await cliReq(this.config.signalCliUrl, "POST", `/v2/send`, {
|
|
134
|
+
number: this.config.phoneNumber,
|
|
135
|
+
recipients: [recipient],
|
|
136
|
+
message: text.slice(0, 5e4)
|
|
137
|
+
});
|
|
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.SignalConnector = SignalConnector;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
const chalk = require_chunk.__toESM(require("chalk"));
|
|
3
|
+
const http = require_chunk.__toESM(require("http"));
|
|
4
|
+
const events = require_chunk.__toESM(require("events"));
|
|
5
|
+
|
|
6
|
+
//#region extensions/google-chat/src/connector.ts
|
|
7
|
+
var GoogleChatConnector = class extends events.EventEmitter {
|
|
8
|
+
config;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
super();
|
|
11
|
+
this.config = config;
|
|
12
|
+
}
|
|
13
|
+
async connect() {
|
|
14
|
+
console.log(chalk.default.green(` 🦅 Google Chat: HTTP app listening at ${this.config.baseUrl}/webhook/gchat`));
|
|
15
|
+
this.emit("connected", {});
|
|
16
|
+
}
|
|
17
|
+
disconnect() {}
|
|
18
|
+
/**
|
|
19
|
+
|
|
20
|
+
* Handle incoming Chat event. Returns JSON string for sync reply, or void.
|
|
21
|
+
|
|
22
|
+
*/
|
|
23
|
+
async handleWebhook(body) {
|
|
24
|
+
let event;
|
|
25
|
+
try {
|
|
26
|
+
event = JSON.parse(body);
|
|
27
|
+
} catch {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const type = event.type;
|
|
31
|
+
if (type === "ADDED_TO_SPACE" || type === "REMOVED_FROM_SPACE") return JSON.stringify({ text: type === "ADDED_TO_SPACE" ? "🦅 HyperClaw connected." : "Goodbye." });
|
|
32
|
+
if (type !== "MESSAGE") return;
|
|
33
|
+
const msg = event.message;
|
|
34
|
+
const text = (msg?.argumentText || msg?.text || "").trim();
|
|
35
|
+
if (!text) return JSON.stringify({ text: "" });
|
|
36
|
+
const spaceName = event.space?.name || "unknown";
|
|
37
|
+
const userName = event.user?.displayName || event.user?.name || "User";
|
|
38
|
+
try {
|
|
39
|
+
const response = await this.postChat(text);
|
|
40
|
+
return JSON.stringify({ text: response || "(no response)" });
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.error(chalk.default.yellow(` ⚠ Google Chat: ${e.message}`));
|
|
43
|
+
return JSON.stringify({ text: `Error: ${e.message}` });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
postChat(message) {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
const payload = JSON.stringify({ message });
|
|
49
|
+
const url = new URL(`${this.config.baseUrl}/api/chat`);
|
|
50
|
+
const req = http.default.request({
|
|
51
|
+
hostname: url.hostname,
|
|
52
|
+
port: url.port || 80,
|
|
53
|
+
path: url.pathname,
|
|
54
|
+
method: "POST",
|
|
55
|
+
headers: {
|
|
56
|
+
"Content-Type": "application/json",
|
|
57
|
+
"Content-Length": String(Buffer.byteLength(payload)),
|
|
58
|
+
"X-HyperClaw-Source": "gchat"
|
|
59
|
+
}
|
|
60
|
+
}, (res) => {
|
|
61
|
+
let data = "";
|
|
62
|
+
res.on("data", (c) => data += c);
|
|
63
|
+
res.on("end", () => {
|
|
64
|
+
try {
|
|
65
|
+
const j = JSON.parse(data);
|
|
66
|
+
if (j.error) reject(new Error(j.error));
|
|
67
|
+
else resolve(j.response || "");
|
|
68
|
+
} catch {
|
|
69
|
+
reject(new Error("Invalid response"));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
req.on("error", reject);
|
|
74
|
+
req.setTimeout(6e4, () => {
|
|
75
|
+
req.destroy();
|
|
76
|
+
reject(new Error("Timeout"));
|
|
77
|
+
});
|
|
78
|
+
req.write(payload);
|
|
79
|
+
req.end();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
exports.GoogleChatConnector = GoogleChatConnector;
|
|
@@ -0,0 +1,194 @@
|
|
|
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/whatsapp/src/connector.ts
|
|
10
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "whatsapp-state.json");
|
|
11
|
+
const GRAPH_API = "graph.facebook.com";
|
|
12
|
+
const API_VERSION = "v18.0";
|
|
13
|
+
function graphReq(token, method, endpoint, body) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const payload = body ? JSON.stringify(body) : null;
|
|
16
|
+
const req = https.default.request({
|
|
17
|
+
hostname: GRAPH_API,
|
|
18
|
+
port: 443,
|
|
19
|
+
path: `/${API_VERSION}${endpoint}`,
|
|
20
|
+
method,
|
|
21
|
+
headers: {
|
|
22
|
+
"Authorization": `Bearer ${token}`,
|
|
23
|
+
...payload ? {
|
|
24
|
+
"Content-Type": "application/json",
|
|
25
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
26
|
+
} : {}
|
|
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
|
+
if (r.error) reject(new Error(`${r.error.code}: ${r.error.message}`));
|
|
35
|
+
else resolve(r);
|
|
36
|
+
} catch {
|
|
37
|
+
reject(new Error("Invalid JSON"));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
req.on("error", reject);
|
|
42
|
+
if (payload) req.write(payload);
|
|
43
|
+
req.end();
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
var WhatsAppConnector = class extends events.EventEmitter {
|
|
47
|
+
config;
|
|
48
|
+
running = false;
|
|
49
|
+
constructor(config) {
|
|
50
|
+
super();
|
|
51
|
+
this.config = {
|
|
52
|
+
dmPolicy: "allowlist",
|
|
53
|
+
allowFrom: [],
|
|
54
|
+
approvedPairings: [],
|
|
55
|
+
pendingPairings: {},
|
|
56
|
+
...config
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async connect() {
|
|
60
|
+
const info = await graphReq(this.config.accessToken, "GET", `/${this.config.phoneNumberId}`);
|
|
61
|
+
await this.loadState();
|
|
62
|
+
this.running = true;
|
|
63
|
+
console.log(chalk.default.green(` 🦅 WhatsApp: ${info.display_phone_number || this.config.phoneNumberId} connected`));
|
|
64
|
+
this.emit("connected", {
|
|
65
|
+
phoneNumberId: this.config.phoneNumberId,
|
|
66
|
+
number: info.display_phone_number
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
disconnect() {
|
|
70
|
+
this.running = false;
|
|
71
|
+
}
|
|
72
|
+
verifyWebhook(mode, token, challenge) {
|
|
73
|
+
if (mode === "subscribe" && token === this.config.verifyToken) return challenge;
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
async handleWebhook(body) {
|
|
77
|
+
let payload;
|
|
78
|
+
try {
|
|
79
|
+
payload = JSON.parse(body);
|
|
80
|
+
} catch {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const entry = payload.entry?.[0];
|
|
84
|
+
const changes = entry?.changes?.[0];
|
|
85
|
+
const value = changes?.value;
|
|
86
|
+
if (!value?.messages) return;
|
|
87
|
+
for (const msg of value.messages) {
|
|
88
|
+
if (msg.type !== "text") continue;
|
|
89
|
+
const from = msg.from;
|
|
90
|
+
const text = msg.text?.body;
|
|
91
|
+
if (!text) continue;
|
|
92
|
+
await this.markRead(msg.id).catch(() => {});
|
|
93
|
+
const allowed = await this.checkDMPolicy(from, text);
|
|
94
|
+
if (!allowed) continue;
|
|
95
|
+
this.emit("message", {
|
|
96
|
+
id: msg.id,
|
|
97
|
+
channelId: "whatsapp",
|
|
98
|
+
from,
|
|
99
|
+
chatId: from,
|
|
100
|
+
text,
|
|
101
|
+
timestamp: new Date(parseInt(msg.timestamp) * 1e3).toISOString(),
|
|
102
|
+
isDM: true,
|
|
103
|
+
name: value.contacts?.[0]?.profile?.name
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async checkDMPolicy(from, text) {
|
|
108
|
+
if (this.config.dmPolicy === "none") return false;
|
|
109
|
+
if (this.config.dmPolicy === "open") return true;
|
|
110
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
111
|
+
if (this.config.allowFrom.includes(from)) return true;
|
|
112
|
+
await this.sendMessage(from, "🦅 HyperClaw: You are not on the allowlist.");
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
if (this.config.dmPolicy === "pairing") {
|
|
116
|
+
if (this.config.approvedPairings.includes(from)) return true;
|
|
117
|
+
const upper = text.trim().toUpperCase();
|
|
118
|
+
if (this.config.pendingPairings[upper]) {
|
|
119
|
+
this.config.approvedPairings.push(from);
|
|
120
|
+
delete this.config.pendingPairings[upper];
|
|
121
|
+
await this.saveState();
|
|
122
|
+
await this.sendMessage(from, "🦅 *Paired!* You can now send messages.");
|
|
123
|
+
this.emit("pairing:approved", {
|
|
124
|
+
userId: from,
|
|
125
|
+
channelId: "whatsapp"
|
|
126
|
+
});
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
130
|
+
this.config.pendingPairings[code] = from;
|
|
131
|
+
await this.saveState();
|
|
132
|
+
await this.sendMessage(from, `🦅 HyperClaw Pairing\n\nCode: *${code}*\nAsk owner: hyperclaw pairing approve whatsapp ${code}`);
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
async sendMessage(to, text) {
|
|
138
|
+
await graphReq(this.config.accessToken, "POST", `/${this.config.phoneNumberId}/messages`, {
|
|
139
|
+
messaging_product: "whatsapp",
|
|
140
|
+
to,
|
|
141
|
+
type: "text",
|
|
142
|
+
text: {
|
|
143
|
+
body: text.slice(0, 4096),
|
|
144
|
+
preview_url: false
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
async markRead(messageId) {
|
|
149
|
+
await graphReq(this.config.accessToken, "POST", `/${this.config.phoneNumberId}/messages`, {
|
|
150
|
+
messaging_product: "whatsapp",
|
|
151
|
+
status: "read",
|
|
152
|
+
message_id: messageId
|
|
153
|
+
}).catch(() => {});
|
|
154
|
+
}
|
|
155
|
+
async sendTemplate(to, templateName, languageCode = "en_US") {
|
|
156
|
+
await graphReq(this.config.accessToken, "POST", `/${this.config.phoneNumberId}/messages`, {
|
|
157
|
+
messaging_product: "whatsapp",
|
|
158
|
+
to,
|
|
159
|
+
type: "template",
|
|
160
|
+
template: {
|
|
161
|
+
name: templateName,
|
|
162
|
+
language: { code: languageCode }
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
approvePairing(code) {
|
|
167
|
+
const upper = code.toUpperCase();
|
|
168
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
169
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
170
|
+
delete this.config.pendingPairings[upper];
|
|
171
|
+
this.saveState();
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
async loadState() {
|
|
175
|
+
try {
|
|
176
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
177
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
178
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
179
|
+
} catch {}
|
|
180
|
+
}
|
|
181
|
+
async saveState() {
|
|
182
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
183
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
184
|
+
p: this.config.pendingPairings,
|
|
185
|
+
a: this.config.approvedPairings
|
|
186
|
+
}, { spaces: 2 });
|
|
187
|
+
}
|
|
188
|
+
isRunning() {
|
|
189
|
+
return this.running;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
//#endregion
|
|
194
|
+
exports.WhatsAppConnector = WhatsAppConnector;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
const chalk = require_chunk.__toESM(require("chalk"));
|
|
3
|
+
const fs_extra = require_chunk.__toESM(require("fs-extra"));
|
|
4
|
+
const path = require_chunk.__toESM(require("path"));
|
|
5
|
+
const os = require_chunk.__toESM(require("os"));
|
|
6
|
+
const crypto = require_chunk.__toESM(require("crypto"));
|
|
7
|
+
const https = require_chunk.__toESM(require("https"));
|
|
8
|
+
const events = require_chunk.__toESM(require("events"));
|
|
9
|
+
|
|
10
|
+
//#region extensions/twitter/src/connector.ts
|
|
11
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "twitter-state.json");
|
|
12
|
+
function oauthSign(method, url, config) {
|
|
13
|
+
const nonce = crypto.default.randomBytes(16).toString("hex");
|
|
14
|
+
const ts = Math.floor(Date.now() / 1e3).toString();
|
|
15
|
+
const op = {
|
|
16
|
+
oauth_consumer_key: config.apiKey,
|
|
17
|
+
oauth_nonce: nonce,
|
|
18
|
+
oauth_signature_method: "HMAC-SHA1",
|
|
19
|
+
oauth_timestamp: ts,
|
|
20
|
+
oauth_token: config.accessToken,
|
|
21
|
+
oauth_version: "1.0"
|
|
22
|
+
};
|
|
23
|
+
const sorted = Object.keys(op).sort().map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(op[k])}`).join("&");
|
|
24
|
+
const base = `${method}&${encodeURIComponent(url)}&${encodeURIComponent(sorted)}`;
|
|
25
|
+
const key = `${encodeURIComponent(config.apiSecret)}&${encodeURIComponent(config.accessTokenSecret)}`;
|
|
26
|
+
op.oauth_signature = crypto.default.createHmac("sha1", key).update(base).digest("base64");
|
|
27
|
+
return "OAuth " + Object.keys(op).sort().map((k) => `${encodeURIComponent(k)}="${encodeURIComponent(op[k])}"`).join(", ");
|
|
28
|
+
}
|
|
29
|
+
function xReq(method, url, body, auth) {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
const payload = body ? JSON.stringify(body) : null;
|
|
32
|
+
const u = new URL(url);
|
|
33
|
+
const req = https.default.request({
|
|
34
|
+
hostname: u.hostname,
|
|
35
|
+
path: u.pathname + u.search,
|
|
36
|
+
method,
|
|
37
|
+
headers: {
|
|
38
|
+
"Authorization": auth,
|
|
39
|
+
...payload ? {
|
|
40
|
+
"Content-Type": "application/json",
|
|
41
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
42
|
+
} : {}
|
|
43
|
+
}
|
|
44
|
+
}, (res) => {
|
|
45
|
+
let data = "";
|
|
46
|
+
res.on("data", (c) => data += c);
|
|
47
|
+
res.on("end", () => {
|
|
48
|
+
try {
|
|
49
|
+
resolve(JSON.parse(data));
|
|
50
|
+
} catch {
|
|
51
|
+
resolve({ raw: data });
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
req.on("error", reject);
|
|
56
|
+
if (payload) req.write(payload);
|
|
57
|
+
req.end();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
var TwitterConnector = class extends events.EventEmitter {
|
|
61
|
+
config;
|
|
62
|
+
running = false;
|
|
63
|
+
myUserId = "";
|
|
64
|
+
constructor(config) {
|
|
65
|
+
super();
|
|
66
|
+
this.config = {
|
|
67
|
+
dmPolicy: "allowlist",
|
|
68
|
+
allowFrom: [],
|
|
69
|
+
approvedPairings: [],
|
|
70
|
+
pendingPairings: {},
|
|
71
|
+
...config
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async connect() {
|
|
75
|
+
const url = "https://api.twitter.com/2/users/me";
|
|
76
|
+
const me = await xReq("GET", url, null, oauthSign("GET", url, this.config));
|
|
77
|
+
this.myUserId = me.data?.id || "";
|
|
78
|
+
await this.loadState();
|
|
79
|
+
this.running = true;
|
|
80
|
+
console.log(chalk.default.green(` 🦅 Twitter/X: @${me.data?.username} connected`));
|
|
81
|
+
this.emit("connected", {
|
|
82
|
+
userId: me.data?.id,
|
|
83
|
+
username: me.data?.username
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
disconnect() {
|
|
87
|
+
this.running = false;
|
|
88
|
+
}
|
|
89
|
+
handleCRC(crcToken) {
|
|
90
|
+
const hash = crypto.default.createHmac("sha256", this.config.apiSecret).update(crcToken).digest("base64");
|
|
91
|
+
return JSON.stringify({ response_token: `sha256=${hash}` });
|
|
92
|
+
}
|
|
93
|
+
async handleWebhook(body) {
|
|
94
|
+
let payload;
|
|
95
|
+
try {
|
|
96
|
+
payload = JSON.parse(body);
|
|
97
|
+
} catch {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
for (const event of payload.direct_message_events || []) {
|
|
101
|
+
if (event.type !== "message_create") continue;
|
|
102
|
+
const senderId = event.message_create?.sender_id;
|
|
103
|
+
if (senderId === this.myUserId) continue;
|
|
104
|
+
const text = event.message_create?.message_data?.text;
|
|
105
|
+
if (!text) continue;
|
|
106
|
+
const allowed = await this.checkDMPolicy(senderId, text);
|
|
107
|
+
if (!allowed) continue;
|
|
108
|
+
this.emit("message", {
|
|
109
|
+
id: event.id,
|
|
110
|
+
channelId: "twitter",
|
|
111
|
+
from: senderId,
|
|
112
|
+
chatId: senderId,
|
|
113
|
+
text,
|
|
114
|
+
timestamp: new Date(parseInt(event.created_timestamp)).toISOString(),
|
|
115
|
+
isDM: true
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async checkDMPolicy(from, text) {
|
|
120
|
+
if (this.config.dmPolicy === "none") return false;
|
|
121
|
+
if (this.config.dmPolicy === "open") return true;
|
|
122
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
123
|
+
if (this.config.allowFrom.includes(from)) return true;
|
|
124
|
+
await this.sendDM(from, "🦅 HyperClaw: Not on allowlist.");
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
if (this.config.dmPolicy === "pairing") {
|
|
128
|
+
if (this.config.approvedPairings.includes(from)) return true;
|
|
129
|
+
const upper = text.trim().toUpperCase();
|
|
130
|
+
if (this.config.pendingPairings[upper]) {
|
|
131
|
+
this.config.approvedPairings.push(from);
|
|
132
|
+
delete this.config.pendingPairings[upper];
|
|
133
|
+
await this.saveState();
|
|
134
|
+
await this.sendDM(from, "🦅 Paired!");
|
|
135
|
+
this.emit("pairing:approved", {
|
|
136
|
+
userId: from,
|
|
137
|
+
channelId: "twitter"
|
|
138
|
+
});
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
142
|
+
this.config.pendingPairings[code] = from;
|
|
143
|
+
await this.saveState();
|
|
144
|
+
await this.sendDM(from, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve twitter ${code}`);
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
async sendDM(recipientId, text) {
|
|
150
|
+
const url = `https://api.twitter.com/2/dm_conversations/with/${recipientId}/messages`;
|
|
151
|
+
await xReq("POST", url, { text: text.slice(0, 1e4) }, oauthSign("POST", url, this.config));
|
|
152
|
+
}
|
|
153
|
+
approvePairing(code) {
|
|
154
|
+
const upper = code.toUpperCase();
|
|
155
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
156
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
157
|
+
delete this.config.pendingPairings[upper];
|
|
158
|
+
this.saveState();
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
async loadState() {
|
|
162
|
+
try {
|
|
163
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
164
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
165
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
166
|
+
} catch {}
|
|
167
|
+
}
|
|
168
|
+
async saveState() {
|
|
169
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
170
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
171
|
+
p: this.config.pendingPairings,
|
|
172
|
+
a: this.config.approvedPairings
|
|
173
|
+
}, { spaces: 2 });
|
|
174
|
+
}
|
|
175
|
+
isRunning() {
|
|
176
|
+
return this.running;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
//#endregion
|
|
181
|
+
exports.TwitterConnector = TwitterConnector;
|