hyperclaw 4.0.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -3
- package/dist/a2ui-protocol-CfBI44-Q.js +75 -0
- package/dist/agents-routing-ChHiZp36.js +327 -0
- package/dist/agents-routing-ChqZ6l2S.js +4 -0
- package/dist/api-keys-guide-BCcOl0Q7.js +149 -0
- package/dist/audit-BaIiyWFu.js +441 -0
- package/dist/bounty-tools-DWudyZie.js +211 -0
- package/dist/browser-tools-BsTeGMnX.js +5 -0
- package/dist/browser-tools-D8_rLe2p.js +179 -0
- package/dist/claw-tasks-CgTsiNE8.js +80 -0
- package/dist/connector-5N0-X_xs.js +194 -0
- package/dist/connector-B3v0qcXg.js +425 -0
- package/dist/connector-B8R3iBY1.js +280 -0
- package/dist/connector-BAM-08NN.js +189 -0
- package/dist/connector-BC8FIVu4.js +181 -0
- package/dist/connector-BDmwwaVc.js +213 -0
- package/dist/connector-BGjbBy69.js +225 -0
- package/dist/connector-BO2SRzfG.js +218 -0
- package/dist/connector-BfXky0L3.js +167 -0
- package/dist/connector-BiiSJpx3.js +192 -0
- package/dist/connector-BnDmIhIu.js +85 -0
- package/dist/connector-C1HSoUyk.js +189 -0
- package/dist/connector-CKQHZOXg.js +568 -0
- package/dist/connector-CRl-iidy.js +239 -0
- package/dist/connector-Ci9glMD-.js +340 -0
- package/dist/connector-CjtZIEDj.js +181 -0
- package/dist/connector-Ck6JtOsX.js +531 -0
- package/dist/connector-D8Kelee0.js +286 -0
- package/dist/connector-DAnRJ0oP.js +162 -0
- package/dist/connector-DXTp5PE8.js +508 -0
- package/dist/connector-Dih6dUPP.js +173 -0
- package/dist/connector-DqTH_tPX.js +182 -0
- package/dist/connector-DrnEiiyP.js +419 -0
- package/dist/connector-DtR5GGTX.js +167 -0
- package/dist/connector-Tky_qS_K.js +350 -0
- package/dist/connector-ZSc3oTTy.js +305 -0
- package/dist/connector-sW5yhU1m.js +498 -0
- package/dist/connector-u3ICd3Ic.js +552 -0
- package/dist/cost-tracker-DD9wtWsr.js +103 -0
- package/dist/credentials-store-C6ir0Dae.js +4 -0
- package/dist/credentials-store-H13LqOwJ.js +77 -0
- package/dist/cron-tasks-Bli7Kzd2.js +82 -0
- package/dist/daemon-Bg4GtCmc.js +318 -0
- package/dist/daemon-DhmwY8k4.js +5 -0
- package/dist/delivery-BmIYy9VQ.js +4 -0
- package/dist/delivery-pWUPBp1F.js +95 -0
- package/dist/destructive-gate-D6vWOdEl.js +101 -0
- package/dist/developer-keys-CPWT7Q6S.js +8 -0
- package/dist/developer-keys-DrrcUqFa.js +127 -0
- package/dist/doctor-BvCe8BBk.js +230 -0
- package/dist/doctor-CxyPLYsJ.js +6 -0
- package/dist/engine-CEDSqXfw.js +256 -0
- package/dist/engine-Da4JMNpI.js +7 -0
- package/dist/env-resolve-CiXbWYwe.js +10 -0
- package/dist/env-resolve-CmGWhWXJ.js +115 -0
- package/dist/extraction-tools-HOZstZ0y.js +91 -0
- package/dist/extraction-tools-m4lmAv7l.js +5 -0
- package/dist/form_data-Cz040rio.js +8657 -0
- package/dist/gmail-watch-setup-Du7DVV7S.js +40 -0
- package/dist/health-B-asI__D.js +6 -0
- package/dist/health-Ds2YlpTB.js +152 -0
- package/dist/heartbeat-engine-BYT5ayQH.js +83 -0
- package/dist/hub-D0XwdjM-.js +515 -0
- package/dist/hub-LiD5Iztb.js +6 -0
- package/dist/hyperclawbot-zvczQgKx.js +505 -0
- package/dist/inference-BKVkBREb.js +6 -0
- package/dist/inference-DCXH4Q3x.js +922 -0
- package/dist/knowledge-graph-iBG76fvm.js +131 -0
- package/dist/loader-CC45xGpC.js +4 -0
- package/dist/loader-CnEdOyjT.js +400 -0
- package/dist/logger-ybOp7VOC.js +83 -0
- package/dist/manager-03ipO9R0.js +105 -0
- package/dist/manager-BpDfbDjg.js +117 -0
- package/dist/manager-Bxl0sqlh.js +4 -0
- package/dist/manager-CrVDn6eN.js +6 -0
- package/dist/manager-FCgF1plu.js +218 -0
- package/dist/manager-rgCsaWT1.js +40 -0
- package/dist/mcp-CfoSU4Uz.js +139 -0
- package/dist/mcp-loader-DkRBsLpk.js +94 -0
- package/dist/memory-BlHL7JCO.js +4 -0
- package/dist/memory-DsS_eFvJ.js +270 -0
- package/dist/memory-auto-BkvtSFUw.js +5 -0
- package/dist/memory-auto-Bnz_-1wP.js +306 -0
- package/dist/memory-integration-cSYkZyEo.js +91 -0
- package/dist/moltbook-BtLDZTfM.js +81 -0
- package/dist/node-Dw2Gi-cP.js +222 -0
- package/dist/nodes-registry-B8dmrlLv.js +52 -0
- package/dist/oauth-flow-DQPvMHRH.js +150 -0
- package/dist/oauth-provider-Uo4Nib_c.js +110 -0
- package/dist/observability-BV-Yx0V9.js +89 -0
- package/dist/onboard-0WoDxbv_.js +10 -0
- package/dist/onboard-BXNXCQp4.js +4070 -0
- package/dist/orchestrator-DmnEvMaL.js +189 -0
- package/dist/orchestrator-RI3bpqqc.js +6 -0
- package/dist/pairing-6iM27aD8.js +196 -0
- package/dist/pairing-dGoiGepK.js +4 -0
- package/dist/pc-access-CgCsYrpt.js +8 -0
- package/dist/pc-access-_iH2aorG.js +819 -0
- package/dist/pending-approval-CUXjysAo.js +22 -0
- package/dist/reminders-store-Drjed_-h.js +58 -0
- package/dist/renderer-BVQrd0_g.js +225 -0
- package/dist/rules-BE4GV6cV.js +103 -0
- package/dist/run-main.js +1607 -443
- package/dist/runner-DatMMYYE.js +1271 -0
- package/dist/sdk/index.js +2 -2
- package/dist/sdk/index.mjs +2 -2
- package/dist/security-BqNyT4ID.js +4 -0
- package/dist/security-tpgqPWWH.js +73 -0
- package/dist/server-D4wVHiX9.js +4 -0
- package/dist/server-Dh3JlBFB.js +1255 -0
- package/dist/session-store-BUiPz0Vv.js +5 -0
- package/dist/session-store-is4B6qmD.js +113 -0
- package/dist/sessions-tools-CbUTFe4i.js +5 -0
- package/dist/sessions-tools-CeqD7iil.js +95 -0
- package/dist/skill-loader-BaNLVmJy.js +7 -0
- package/dist/skill-loader-HgpF6Vqs.js +159 -0
- package/dist/skill-runtime-CJN24QPW.js +102 -0
- package/dist/skill-runtime-w1ig_lcw.js +5 -0
- package/dist/src-BxPHKO5x.js +63 -0
- package/dist/src-DIc-L2IG.js +20 -0
- package/dist/src-g_rNx5rh.js +458 -0
- package/dist/sub-agent-tools-CHQoHz9c.js +39 -0
- package/dist/theme-DcxwcUgZ.js +180 -0
- package/dist/theme-cx0fkgWC.js +8 -0
- package/dist/tool-policy-CNT-mF2Z.js +189 -0
- package/dist/tts-elevenlabs-BRosZv-f.js +61 -0
- package/dist/update-check-C2Dz85wJ.js +81 -0
- package/dist/vision-BMmiIKy7.js +121 -0
- package/dist/vision-tools-DVuYc17I.js +51 -0
- package/dist/vision-tools-U3YC4L-g.js +5 -0
- package/dist/voice-transcription-B555DbWR.js +138 -0
- package/dist/website-watch-tools-DFMrJU-R.js +139 -0
- package/dist/website-watch-tools-Du3W5sN7.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,192 @@
|
|
|
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 ws = require_chunk.__toESM(require("ws"));
|
|
8
|
+
const events = require_chunk.__toESM(require("events"));
|
|
9
|
+
|
|
10
|
+
//#region extensions/nostr/src/connector.ts
|
|
11
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "nostr-state.json");
|
|
12
|
+
function getPublicKey(privKeyHex) {
|
|
13
|
+
const privKey = Buffer.from(privKeyHex, "hex");
|
|
14
|
+
const ec = crypto.default.createECDH("prime256v1");
|
|
15
|
+
return crypto.default.createHash("sha256").update(privKey).digest("hex");
|
|
16
|
+
}
|
|
17
|
+
function signEvent(event, privKeyHex) {
|
|
18
|
+
const payload = JSON.stringify(event);
|
|
19
|
+
return crypto.default.createHmac("sha256", Buffer.from(privKeyHex, "hex")).update(payload).digest("hex");
|
|
20
|
+
}
|
|
21
|
+
function nip04Decrypt(privKeyHex, senderPubKey, ciphertext) {
|
|
22
|
+
try {
|
|
23
|
+
const [encrypted, iv] = ciphertext.split("?iv=");
|
|
24
|
+
const sharedSecret = crypto.default.createHash("sha256").update(Buffer.from(privKeyHex + senderPubKey, "hex")).digest();
|
|
25
|
+
const decipher = crypto.default.createDecipheriv("aes-256-cbc", sharedSecret, Buffer.from(iv, "base64"));
|
|
26
|
+
return decipher.update(encrypted, "base64", "utf8") + decipher.final("utf8");
|
|
27
|
+
} catch {
|
|
28
|
+
return ciphertext;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function nip04Encrypt(privKeyHex, recipientPubKey, plaintext) {
|
|
32
|
+
const sharedSecret = crypto.default.createHash("sha256").update(Buffer.from(privKeyHex + recipientPubKey, "hex")).digest();
|
|
33
|
+
const iv = crypto.default.randomBytes(16);
|
|
34
|
+
const cipher = crypto.default.createCipheriv("aes-256-cbc", sharedSecret, iv);
|
|
35
|
+
const encrypted = cipher.update(plaintext, "utf8", "base64") + cipher.final("base64");
|
|
36
|
+
return `${encrypted}?iv=${iv.toString("base64")}`;
|
|
37
|
+
}
|
|
38
|
+
var NostrConnector = class extends events.EventEmitter {
|
|
39
|
+
config;
|
|
40
|
+
sockets = /* @__PURE__ */ new Map();
|
|
41
|
+
running = false;
|
|
42
|
+
pubKey;
|
|
43
|
+
seenEventIds = /* @__PURE__ */ new Set();
|
|
44
|
+
constructor(config) {
|
|
45
|
+
super();
|
|
46
|
+
this.config = {
|
|
47
|
+
relays: [
|
|
48
|
+
"wss://relay.damus.io",
|
|
49
|
+
"wss://nos.lol",
|
|
50
|
+
"wss://relay.nostr.band"
|
|
51
|
+
],
|
|
52
|
+
dmPolicy: "open",
|
|
53
|
+
allowFrom: [],
|
|
54
|
+
approvedPairings: [],
|
|
55
|
+
pendingPairings: {},
|
|
56
|
+
...config
|
|
57
|
+
};
|
|
58
|
+
this.pubKey = getPublicKey(this.config.privateKeyHex);
|
|
59
|
+
}
|
|
60
|
+
async connect() {
|
|
61
|
+
await this.loadState();
|
|
62
|
+
for (const relay of this.config.relays) this.connectRelay(relay);
|
|
63
|
+
this.running = true;
|
|
64
|
+
console.log(chalk.default.green(` 🦅 Nostr: pubkey ${this.pubKey.slice(0, 16)}... connected to ${this.config.relays.length} relays`));
|
|
65
|
+
this.emit("connected", { pubKey: this.pubKey });
|
|
66
|
+
}
|
|
67
|
+
connectRelay(url) {
|
|
68
|
+
const ws$1 = new ws.WebSocket(url);
|
|
69
|
+
this.sockets.set(url, ws$1);
|
|
70
|
+
ws$1.on("open", () => {
|
|
71
|
+
ws$1.send(JSON.stringify([
|
|
72
|
+
"REQ",
|
|
73
|
+
`hc-${Date.now()}`,
|
|
74
|
+
{
|
|
75
|
+
kinds: [4],
|
|
76
|
+
"#p": [this.pubKey],
|
|
77
|
+
limit: 10
|
|
78
|
+
}
|
|
79
|
+
]));
|
|
80
|
+
});
|
|
81
|
+
ws$1.on("message", async (data) => {
|
|
82
|
+
try {
|
|
83
|
+
const msg = JSON.parse(data.toString());
|
|
84
|
+
if (msg[0] === "EVENT") await this.handleEvent(msg[2]);
|
|
85
|
+
} catch {}
|
|
86
|
+
});
|
|
87
|
+
ws$1.on("close", () => {
|
|
88
|
+
if (this.running) setTimeout(() => this.connectRelay(url), 5e3);
|
|
89
|
+
});
|
|
90
|
+
ws$1.on("error", () => {});
|
|
91
|
+
}
|
|
92
|
+
async handleEvent(event) {
|
|
93
|
+
if (event.kind !== 4) return;
|
|
94
|
+
if (event.pubkey === this.pubKey) return;
|
|
95
|
+
if (this.seenEventIds.has(event.id)) return;
|
|
96
|
+
this.seenEventIds.add(event.id);
|
|
97
|
+
const from = event.pubkey;
|
|
98
|
+
const text = nip04Decrypt(this.config.privateKeyHex, from, event.content);
|
|
99
|
+
const allowed = await this.checkDMPolicy(from, text);
|
|
100
|
+
if (!allowed) return;
|
|
101
|
+
this.emit("message", {
|
|
102
|
+
id: event.id,
|
|
103
|
+
channelId: "nostr",
|
|
104
|
+
from,
|
|
105
|
+
chatId: from,
|
|
106
|
+
text,
|
|
107
|
+
timestamp: new Date(event.created_at * 1e3).toISOString(),
|
|
108
|
+
isDM: true
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
async checkDMPolicy(from, text) {
|
|
112
|
+
if (this.config.dmPolicy === "none") return false;
|
|
113
|
+
if (this.config.dmPolicy === "open") return true;
|
|
114
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
115
|
+
if (this.config.allowFrom.includes(from)) return true;
|
|
116
|
+
await this.sendDM(from, "🦅 HyperClaw: Not on allowlist.");
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (this.config.dmPolicy === "pairing") {
|
|
120
|
+
if (this.config.approvedPairings.includes(from)) return true;
|
|
121
|
+
const upper = text.trim().toUpperCase();
|
|
122
|
+
if (this.config.pendingPairings[upper]) {
|
|
123
|
+
this.config.approvedPairings.push(from);
|
|
124
|
+
delete this.config.pendingPairings[upper];
|
|
125
|
+
await this.saveState();
|
|
126
|
+
await this.sendDM(from, "🦅 Paired!");
|
|
127
|
+
this.emit("pairing:approved", {
|
|
128
|
+
userId: from,
|
|
129
|
+
channelId: "nostr"
|
|
130
|
+
});
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
134
|
+
this.config.pendingPairings[code] = from;
|
|
135
|
+
await this.saveState();
|
|
136
|
+
await this.sendDM(from, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve nostr ${code}`);
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
async sendDM(recipientPubKey, text) {
|
|
142
|
+
const encrypted = nip04Encrypt(this.config.privateKeyHex, recipientPubKey, text);
|
|
143
|
+
const event = {
|
|
144
|
+
pubkey: this.pubKey,
|
|
145
|
+
created_at: Math.floor(Date.now() / 1e3),
|
|
146
|
+
kind: 4,
|
|
147
|
+
tags: [["p", recipientPubKey]],
|
|
148
|
+
content: encrypted
|
|
149
|
+
};
|
|
150
|
+
const sig = signEvent(event, this.config.privateKeyHex);
|
|
151
|
+
const fullEvent = {
|
|
152
|
+
...event,
|
|
153
|
+
id: sig,
|
|
154
|
+
sig
|
|
155
|
+
};
|
|
156
|
+
const msg = JSON.stringify(["EVENT", fullEvent]);
|
|
157
|
+
for (const ws$1 of this.sockets.values()) if (ws$1.readyState === ws.WebSocket.OPEN) ws$1.send(msg);
|
|
158
|
+
}
|
|
159
|
+
disconnect() {
|
|
160
|
+
this.running = false;
|
|
161
|
+
for (const ws$1 of this.sockets.values()) ws$1.close();
|
|
162
|
+
this.sockets.clear();
|
|
163
|
+
}
|
|
164
|
+
approvePairing(code) {
|
|
165
|
+
const upper = code.toUpperCase();
|
|
166
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
167
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
168
|
+
delete this.config.pendingPairings[upper];
|
|
169
|
+
this.saveState();
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
async loadState() {
|
|
173
|
+
try {
|
|
174
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
175
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
176
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
177
|
+
} catch {}
|
|
178
|
+
}
|
|
179
|
+
async saveState() {
|
|
180
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
181
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
182
|
+
p: this.config.pendingPairings,
|
|
183
|
+
a: this.config.approvedPairings
|
|
184
|
+
}, { spaces: 2 });
|
|
185
|
+
}
|
|
186
|
+
isRunning() {
|
|
187
|
+
return this.running;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
//#endregion
|
|
192
|
+
exports.NostrConnector = NostrConnector;
|
|
@@ -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,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;
|