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,196 @@
|
|
|
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/slack/src/connector.ts
|
|
11
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "slack-state.json");
|
|
12
|
+
function slackApi(token, method, body = {}) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const payload = JSON.stringify(body);
|
|
15
|
+
const req = https.default.request({
|
|
16
|
+
hostname: "slack.com",
|
|
17
|
+
port: 443,
|
|
18
|
+
path: `/api/${method}`,
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: {
|
|
21
|
+
"Authorization": `Bearer ${token}`,
|
|
22
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
23
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
24
|
+
}
|
|
25
|
+
}, (res) => {
|
|
26
|
+
let data = "";
|
|
27
|
+
res.on("data", (c) => data += c);
|
|
28
|
+
res.on("end", () => {
|
|
29
|
+
try {
|
|
30
|
+
const r = JSON.parse(data);
|
|
31
|
+
if (!r.ok) reject(new Error(r.error || "Slack API error"));
|
|
32
|
+
else resolve(r);
|
|
33
|
+
} catch {
|
|
34
|
+
reject(new Error("Invalid JSON"));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
req.on("error", reject);
|
|
39
|
+
req.write(payload);
|
|
40
|
+
req.end();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
var SlackConnector = class extends events.EventEmitter {
|
|
44
|
+
config;
|
|
45
|
+
botUserId = "";
|
|
46
|
+
teamName = "";
|
|
47
|
+
constructor(config) {
|
|
48
|
+
super();
|
|
49
|
+
this.config = {
|
|
50
|
+
dmPolicy: "allowlist",
|
|
51
|
+
allowFrom: [],
|
|
52
|
+
approvedPairings: {},
|
|
53
|
+
pendingPairings: {},
|
|
54
|
+
appMentionOnly: false,
|
|
55
|
+
...config
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async connect() {
|
|
59
|
+
const auth = await slackApi(this.config.botToken, "auth.test");
|
|
60
|
+
this.botUserId = auth.user_id;
|
|
61
|
+
this.teamName = auth.team;
|
|
62
|
+
await this.loadState();
|
|
63
|
+
console.log(chalk.default.green(` 🦅 Slack: @${auth.user} in ${auth.team} connected`));
|
|
64
|
+
this.emit("connected", {
|
|
65
|
+
userId: auth.user_id,
|
|
66
|
+
team: auth.team
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async handleWebhook(body, signature, timestamp) {
|
|
70
|
+
if (!this.verifySignature(body, signature, timestamp)) {
|
|
71
|
+
console.log(chalk.default.yellow(" ⚠ Slack: invalid signature"));
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const payload = JSON.parse(body);
|
|
75
|
+
if (payload.type === "url_verification") return payload.challenge;
|
|
76
|
+
if (payload.type === "event_callback") await this.handleEvent(payload.event);
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
verifySignature(body, signature, timestamp) {
|
|
80
|
+
const ts = parseInt(timestamp);
|
|
81
|
+
if (Math.abs(Date.now() / 1e3 - ts) > 300) return false;
|
|
82
|
+
const baseString = `v0:${timestamp}:${body}`;
|
|
83
|
+
const hash = "v0=" + crypto.default.createHmac("sha256", this.config.signingSecret).update(baseString).digest("hex");
|
|
84
|
+
try {
|
|
85
|
+
return crypto.default.timingSafeEqual(Buffer.from(hash), Buffer.from(signature));
|
|
86
|
+
} catch {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async handleEvent(event) {
|
|
91
|
+
if (event.bot_id || event.user === this.botUserId) return;
|
|
92
|
+
if (!event.text || !event.user || !event.channel) return;
|
|
93
|
+
const isDM = event.channel_type === "im";
|
|
94
|
+
const isAppMention = event.type === "app_mention";
|
|
95
|
+
if (!isDM && this.config.appMentionOnly && !isAppMention) return;
|
|
96
|
+
if (!isDM && !isAppMention && event.type !== "message") return;
|
|
97
|
+
const text = event.text.replace(/<@[A-Z0-9]+>/g, "").trim();
|
|
98
|
+
if (isDM) {
|
|
99
|
+
const allowed = await this.checkDMPolicy(event.user, event.channel, text);
|
|
100
|
+
if (!allowed) return;
|
|
101
|
+
}
|
|
102
|
+
this.emit("message", {
|
|
103
|
+
id: event.ts,
|
|
104
|
+
channelId: "slack",
|
|
105
|
+
from: event.user,
|
|
106
|
+
chatId: event.channel,
|
|
107
|
+
text,
|
|
108
|
+
timestamp: new Date(parseFloat(event.ts || "0") * 1e3).toISOString(),
|
|
109
|
+
isDM,
|
|
110
|
+
threadTs: event.thread_ts
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
async checkDMPolicy(userId, channelId, text) {
|
|
114
|
+
if (this.config.dmPolicy === "none") return false;
|
|
115
|
+
if (this.config.dmPolicy === "open") return true;
|
|
116
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
117
|
+
if (this.config.allowFrom.includes(userId)) return true;
|
|
118
|
+
await this.sendMessage(channelId, "🦅 *HyperClaw*\n\nYou are not on the allowlist.");
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
if (this.config.dmPolicy === "pairing") {
|
|
122
|
+
if (this.config.approvedPairings.includes(userId)) return true;
|
|
123
|
+
const upper = text.trim().toUpperCase();
|
|
124
|
+
if (this.config.pendingPairings[upper]) {
|
|
125
|
+
this.config.approvedPairings.push(userId);
|
|
126
|
+
delete this.config.pendingPairings[upper];
|
|
127
|
+
await this.saveState();
|
|
128
|
+
await this.sendMessage(channelId, "🦅 *Paired!* You can now send messages.");
|
|
129
|
+
this.emit("pairing:approved", {
|
|
130
|
+
userId,
|
|
131
|
+
channelId: "slack"
|
|
132
|
+
});
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
const code = this.generateCode();
|
|
136
|
+
this.config.pendingPairings[code] = userId;
|
|
137
|
+
await this.saveState();
|
|
138
|
+
await this.sendMessage(channelId, `🦅 *HyperClaw Pairing*\n\nSend the owner this code: \`${code}\`\n\nApprove with: \`hyperclaw pairing approve slack ${code}\``);
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
async sendMessage(channel, text, threadTs) {
|
|
144
|
+
const chunks = text.match(/.{1,3000}/gs) || [text];
|
|
145
|
+
for (const chunk of chunks) await slackApi(this.config.botToken, "chat.postMessage", {
|
|
146
|
+
channel,
|
|
147
|
+
text: chunk,
|
|
148
|
+
mrkdwn: true,
|
|
149
|
+
...threadTs ? { thread_ts: threadTs } : {}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
async sendTyping(channelId) {}
|
|
153
|
+
async openDM(userId) {
|
|
154
|
+
const r = await slackApi(this.config.botToken, "conversations.open", { users: userId });
|
|
155
|
+
return r.channel.id;
|
|
156
|
+
}
|
|
157
|
+
async sendDM(userId, text) {
|
|
158
|
+
const channelId = await this.openDM(userId);
|
|
159
|
+
await this.sendMessage(channelId, text);
|
|
160
|
+
}
|
|
161
|
+
generateCode() {
|
|
162
|
+
const chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
163
|
+
return Array.from({ length: 6 }, () => chars[Math.floor(Math.random() * chars.length)]).join("");
|
|
164
|
+
}
|
|
165
|
+
approvePairing(code) {
|
|
166
|
+
const upper = code.toUpperCase();
|
|
167
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
168
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
169
|
+
delete this.config.pendingPairings[upper];
|
|
170
|
+
this.saveState();
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
addToAllowlist(userId) {
|
|
174
|
+
if (!this.config.allowFrom.includes(userId)) {
|
|
175
|
+
this.config.allowFrom.push(userId);
|
|
176
|
+
this.saveState();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async loadState() {
|
|
180
|
+
try {
|
|
181
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
182
|
+
if (s.pendingPairings) this.config.pendingPairings = s.pendingPairings;
|
|
183
|
+
if (s.approvedPairings) this.config.approvedPairings = s.approvedPairings;
|
|
184
|
+
} catch {}
|
|
185
|
+
}
|
|
186
|
+
async saveState() {
|
|
187
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
188
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
189
|
+
pendingPairings: this.config.pendingPairings,
|
|
190
|
+
approvedPairings: this.config.approvedPairings
|
|
191
|
+
}, { spaces: 2 });
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
//#endregion
|
|
196
|
+
exports.SlackConnector = SlackConnector;
|
|
@@ -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 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/viber/src/connector.ts
|
|
11
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "viber-state.json");
|
|
12
|
+
function viberReq(token, endpoint, body) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const payload = JSON.stringify(body);
|
|
15
|
+
const req = https.default.request({
|
|
16
|
+
hostname: "chatapi.viber.com",
|
|
17
|
+
port: 443,
|
|
18
|
+
path: `/pa${endpoint}`,
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: {
|
|
21
|
+
"X-Viber-Auth-Token": token,
|
|
22
|
+
"Content-Type": "application/json",
|
|
23
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
24
|
+
}
|
|
25
|
+
}, (res) => {
|
|
26
|
+
let data = "";
|
|
27
|
+
res.on("data", (c) => data += c);
|
|
28
|
+
res.on("end", () => {
|
|
29
|
+
try {
|
|
30
|
+
const r = JSON.parse(data);
|
|
31
|
+
if (r.status !== 0) reject(new Error(r.status_message));
|
|
32
|
+
else resolve(r);
|
|
33
|
+
} catch {
|
|
34
|
+
reject(new Error("Invalid JSON"));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
req.on("error", reject);
|
|
39
|
+
req.write(payload);
|
|
40
|
+
req.end();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
var ViberConnector = class extends events.EventEmitter {
|
|
44
|
+
config;
|
|
45
|
+
running = false;
|
|
46
|
+
constructor(config) {
|
|
47
|
+
super();
|
|
48
|
+
this.config = {
|
|
49
|
+
dmPolicy: "allowlist",
|
|
50
|
+
allowFrom: [],
|
|
51
|
+
approvedPairings: [],
|
|
52
|
+
pendingPairings: {},
|
|
53
|
+
...config
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async connect() {
|
|
57
|
+
await viberReq(this.config.authToken, "/set_webhook", {
|
|
58
|
+
url: this.config.webhookUrl,
|
|
59
|
+
event_types: [
|
|
60
|
+
"delivered",
|
|
61
|
+
"seen",
|
|
62
|
+
"failed",
|
|
63
|
+
"subscribed",
|
|
64
|
+
"unsubscribed",
|
|
65
|
+
"conversation_started"
|
|
66
|
+
],
|
|
67
|
+
send_name: true
|
|
68
|
+
});
|
|
69
|
+
const info = await viberReq(this.config.authToken, "/get_account_info", {});
|
|
70
|
+
await this.loadState();
|
|
71
|
+
this.running = true;
|
|
72
|
+
console.log(chalk.default.green(` 🦅 Viber: ${info.name || this.config.botName} connected`));
|
|
73
|
+
this.emit("connected", { name: info.name });
|
|
74
|
+
}
|
|
75
|
+
disconnect() {
|
|
76
|
+
this.running = false;
|
|
77
|
+
}
|
|
78
|
+
verifySignature(body, signature) {
|
|
79
|
+
const expected = crypto.default.createHmac("sha256", this.config.authToken).update(body).digest("hex");
|
|
80
|
+
try {
|
|
81
|
+
return crypto.default.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
|
|
82
|
+
} catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async handleWebhook(body, signature) {
|
|
87
|
+
if (signature && !this.verifySignature(body, signature)) {
|
|
88
|
+
console.log(chalk.default.yellow(" ⚠ Viber: invalid signature"));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
let payload;
|
|
92
|
+
try {
|
|
93
|
+
payload = JSON.parse(body);
|
|
94
|
+
} catch {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (payload.event === "message") {
|
|
98
|
+
const userId = payload.sender?.id;
|
|
99
|
+
const text = payload.message?.text;
|
|
100
|
+
if (!userId || !text) return;
|
|
101
|
+
const allowed = await this.checkDMPolicy(userId, text);
|
|
102
|
+
if (!allowed) return;
|
|
103
|
+
this.emit("message", {
|
|
104
|
+
id: payload.message_token?.toString(),
|
|
105
|
+
channelId: "viber",
|
|
106
|
+
from: userId,
|
|
107
|
+
chatId: userId,
|
|
108
|
+
text,
|
|
109
|
+
senderName: payload.sender?.name,
|
|
110
|
+
timestamp: new Date(payload.timestamp).toISOString(),
|
|
111
|
+
isDM: true
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (payload.event === "conversation_started") await this.sendMessage(payload.user?.id, `🦅 Hi ${payload.user?.name || "there"}! I'm HyperClaw.`);
|
|
115
|
+
}
|
|
116
|
+
async checkDMPolicy(from, text) {
|
|
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(from)) return true;
|
|
121
|
+
await this.sendMessage(from, "🦅 HyperClaw: Not on allowlist.");
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
if (this.config.dmPolicy === "pairing") {
|
|
125
|
+
if (this.config.approvedPairings.includes(from)) return true;
|
|
126
|
+
const upper = text.trim().toUpperCase();
|
|
127
|
+
if (this.config.pendingPairings[upper]) {
|
|
128
|
+
this.config.approvedPairings.push(from);
|
|
129
|
+
delete this.config.pendingPairings[upper];
|
|
130
|
+
await this.saveState();
|
|
131
|
+
await this.sendMessage(from, "🦅 Paired!");
|
|
132
|
+
this.emit("pairing:approved", {
|
|
133
|
+
userId: from,
|
|
134
|
+
channelId: "viber"
|
|
135
|
+
});
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
139
|
+
this.config.pendingPairings[code] = from;
|
|
140
|
+
await this.saveState();
|
|
141
|
+
await this.sendMessage(from, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve viber ${code}`);
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
async sendMessage(userId, text) {
|
|
147
|
+
await viberReq(this.config.authToken, "/send_message", {
|
|
148
|
+
receiver: userId,
|
|
149
|
+
type: "text",
|
|
150
|
+
sender: { name: this.config.botName },
|
|
151
|
+
text: text.slice(0, 7e3)
|
|
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.p) this.config.pendingPairings = s.p;
|
|
166
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
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
|
+
p: this.config.pendingPairings,
|
|
173
|
+
a: this.config.approvedPairings
|
|
174
|
+
}, { spaces: 2 });
|
|
175
|
+
}
|
|
176
|
+
isRunning() {
|
|
177
|
+
return this.running;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
//#endregion
|
|
182
|
+
exports.ViberConnector = ViberConnector;
|
|
@@ -0,0 +1,189 @@
|
|
|
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/sms/src/connector.ts
|
|
11
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "sms-state.json");
|
|
12
|
+
function twilioRequest(accountSid, authToken, method, endpoint, body) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const auth = Buffer.from(`${accountSid}:${authToken}`).toString("base64");
|
|
15
|
+
const payload = body ? Object.entries(body).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join("&") : null;
|
|
16
|
+
const req = https.default.request({
|
|
17
|
+
hostname: "api.twilio.com",
|
|
18
|
+
port: 443,
|
|
19
|
+
path: `/2010-04-01/Accounts/${accountSid}${endpoint}.json`,
|
|
20
|
+
method,
|
|
21
|
+
headers: {
|
|
22
|
+
"Authorization": `Basic ${auth}`,
|
|
23
|
+
...payload ? {
|
|
24
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
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 (res.statusCode && res.statusCode >= 400) reject(new Error(r.message || `Twilio ${res.statusCode}`));
|
|
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 SMSConnector = 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
|
+
await twilioRequest(this.config.accountSid, this.config.authToken, "GET", "");
|
|
61
|
+
await this.loadState();
|
|
62
|
+
this.running = true;
|
|
63
|
+
console.log(chalk.default.green(` 🦅 SMS: ${this.config.fromNumber} connected via Twilio`));
|
|
64
|
+
this.emit("connected", { number: this.config.fromNumber });
|
|
65
|
+
}
|
|
66
|
+
disconnect() {
|
|
67
|
+
this.running = false;
|
|
68
|
+
}
|
|
69
|
+
async handleWebhook(body, twilioSignature, webhookUrl) {
|
|
70
|
+
const params = Object.fromEntries(body.split("&").map((p) => {
|
|
71
|
+
const [k, v] = p.split("=");
|
|
72
|
+
return [decodeURIComponent(k), decodeURIComponent(v || "").replace(/\+/g, " ")];
|
|
73
|
+
}));
|
|
74
|
+
const from = params.From;
|
|
75
|
+
const text = params.Body;
|
|
76
|
+
const messageSid = params.MessageSid;
|
|
77
|
+
if (!from || !text) return;
|
|
78
|
+
if (twilioSignature && !this.verifySignature(body, twilioSignature, webhookUrl)) {
|
|
79
|
+
console.log(chalk.default.yellow(" ⚠ SMS: invalid Twilio signature"));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const allowed = await this.checkDMPolicy(from, text);
|
|
83
|
+
if (!allowed) return;
|
|
84
|
+
this.emit("message", {
|
|
85
|
+
id: messageSid,
|
|
86
|
+
channelId: "sms",
|
|
87
|
+
from,
|
|
88
|
+
chatId: from,
|
|
89
|
+
text,
|
|
90
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
91
|
+
isDM: true
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
verifySignature(body, signature, url) {
|
|
95
|
+
const params = Object.fromEntries(body.split("&").map((p) => {
|
|
96
|
+
const [k, v] = p.split("=");
|
|
97
|
+
return [decodeURIComponent(k), decodeURIComponent(v || "").replace(/\+/g, " ")];
|
|
98
|
+
}));
|
|
99
|
+
const sortedParams = Object.keys(params).sort().map((k) => `${k}${params[k]}`).join("");
|
|
100
|
+
const expected = crypto.default.createHmac("sha1", this.config.authToken).update(url + sortedParams).digest("base64");
|
|
101
|
+
try {
|
|
102
|
+
return crypto.default.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
|
|
103
|
+
} catch {
|
|
104
|
+
return false;
|
|
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, "🦅 HyperClaw: Paired! You can now send messages.");
|
|
123
|
+
this.emit("pairing:approved", {
|
|
124
|
+
userId: from,
|
|
125
|
+
channelId: "sms"
|
|
126
|
+
});
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
const code = this.generateCode();
|
|
130
|
+
this.config.pendingPairings[code] = from;
|
|
131
|
+
await this.saveState();
|
|
132
|
+
await this.sendMessage(from, `🦅 HyperClaw Pairing: send this code to the owner: ${code}\nThey can approve with: hyperclaw pairing approve sms ${code}`);
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
async sendMessage(to, text) {
|
|
138
|
+
await twilioRequest(this.config.accountSid, this.config.authToken, "POST", "/Messages", {
|
|
139
|
+
From: this.config.fromNumber,
|
|
140
|
+
To: to,
|
|
141
|
+
Body: text.slice(0, 1600)
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
async getStatus(messageSid) {
|
|
145
|
+
const r = await twilioRequest(this.config.accountSid, this.config.authToken, "GET", `/Messages/${messageSid}`);
|
|
146
|
+
return r.status;
|
|
147
|
+
}
|
|
148
|
+
async broadcast(numbers, text) {
|
|
149
|
+
for (const num of numbers) await this.sendMessage(num, text).catch((e) => console.log(chalk.default.yellow(` ⚠ SMS broadcast failed to ${num}: ${e.message}`)));
|
|
150
|
+
}
|
|
151
|
+
generateCode() {
|
|
152
|
+
const chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
153
|
+
return Array.from({ length: 6 }, () => chars[Math.floor(Math.random() * chars.length)]).join("");
|
|
154
|
+
}
|
|
155
|
+
approvePairing(code) {
|
|
156
|
+
const upper = code.toUpperCase();
|
|
157
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
158
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
159
|
+
delete this.config.pendingPairings[upper];
|
|
160
|
+
this.saveState();
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
addToAllowlist(number) {
|
|
164
|
+
if (!this.config.allowFrom.includes(number)) {
|
|
165
|
+
this.config.allowFrom.push(number);
|
|
166
|
+
this.saveState();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async loadState() {
|
|
170
|
+
try {
|
|
171
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
172
|
+
if (s.pendingPairings) this.config.pendingPairings = s.pendingPairings;
|
|
173
|
+
if (s.approvedPairings) this.config.approvedPairings = s.approvedPairings;
|
|
174
|
+
} catch {}
|
|
175
|
+
}
|
|
176
|
+
async saveState() {
|
|
177
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
178
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
179
|
+
pendingPairings: this.config.pendingPairings,
|
|
180
|
+
approvedPairings: this.config.approvedPairings
|
|
181
|
+
}, { spaces: 2 });
|
|
182
|
+
}
|
|
183
|
+
isRunning() {
|
|
184
|
+
return this.running;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
//#endregion
|
|
189
|
+
exports.SMSConnector = SMSConnector;
|