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