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.
Files changed (156) hide show
  1. package/README.md +53 -18
  2. package/dist/a2ui-protocol-CT_jDEU9.js +75 -0
  3. package/dist/agents-routing-683Q2JGp.js +129 -0
  4. package/dist/agents-routing-BpZBswBH.js +4 -0
  5. package/dist/api-keys-guide-Bzig1R5W.js +149 -0
  6. package/dist/api-keys-guide-Dq5Obbp4.js +149 -0
  7. package/dist/audit-BYxPlnTQ.js +248 -0
  8. package/dist/bounty-tools-C6LyzxM-.js +211 -0
  9. package/dist/browser-tools-CQBSbIuO.js +5 -0
  10. package/dist/browser-tools-YQmwRLLM.js +179 -0
  11. package/dist/claw-tasks-BRLUvFRD.js +80 -0
  12. package/dist/connector-3HnyH8fn.js +167 -0
  13. package/dist/connector-6PMZo5Ky.js +189 -0
  14. package/dist/connector-B6eoF3DD.js +181 -0
  15. package/dist/connector-B9tLG8UZ.js +196 -0
  16. package/dist/connector-BOlqjXWP.js +182 -0
  17. package/dist/connector-BP8zsbP8.js +189 -0
  18. package/dist/connector-BPoSevxp.js +286 -0
  19. package/dist/connector-BRHj773i.js +163 -0
  20. package/dist/connector-BToxU-jV.js +267 -0
  21. package/dist/connector-BliDVsJQ.js +239 -0
  22. package/dist/connector-Bv6s9oP7.js +88 -0
  23. package/dist/connector-By5wWGTR.js +343 -0
  24. package/dist/connector-C1BaFFgN.js +213 -0
  25. package/dist/connector-CRRWY5Wv.js +167 -0
  26. package/dist/connector-CXPQVGyI.js +85 -0
  27. package/dist/connector-Cdk1CXKi.js +194 -0
  28. package/dist/connector-CwlgFgjx.js +181 -0
  29. package/dist/connector-DFchk6l7.js +178 -0
  30. package/dist/connector-DKw7tRAy.js +192 -0
  31. package/dist/connector-DRv1ahC_.js +343 -0
  32. package/dist/connector-DU63KW94.js +165 -0
  33. package/dist/connector-Dbvb1Cj9.js +280 -0
  34. package/dist/connector-DcZdQcgR.js +173 -0
  35. package/dist/connector-DxKL8VvZ.js +182 -0
  36. package/dist/connector-T_YdZtzv.js +162 -0
  37. package/dist/connector-i4gOS9xL.js +154 -0
  38. package/dist/connector-rHXE1ZD2.js +167 -0
  39. package/dist/connector-wdUXChwa.js +172 -0
  40. package/dist/cost-tracker-pVE15Yq4.js +103 -0
  41. package/dist/credentials-store-BvnMPJwi.js +4 -0
  42. package/dist/credentials-store-sb-TRLwR.js +77 -0
  43. package/dist/cron-tasks-BvDFNyiE.js +82 -0
  44. package/dist/delivery-B-SJqXLn.js +95 -0
  45. package/dist/delivery-D5Z98EVq.js +95 -0
  46. package/dist/delivery-DCOXhXEO.js +5 -0
  47. package/dist/delivery-VgFeuu2J.js +5 -0
  48. package/dist/destructive-gate-m-dWqUFg.js +101 -0
  49. package/dist/developer-keys-JaJK3T27.js +127 -0
  50. package/dist/developer-keys-kyqmtWK3.js +8 -0
  51. package/dist/doctor-3oi89QIc.js +175 -0
  52. package/dist/doctor-Cf1XSfp9.js +4 -0
  53. package/dist/engine-B4eMiTgl.js +7 -0
  54. package/dist/engine-B8M7dYul.js +7 -0
  55. package/dist/engine-BhT-1M9W.js +256 -0
  56. package/dist/engine-D49jnSd_.js +256 -0
  57. package/dist/env-resolve-DWOQ45jG.js +9 -0
  58. package/dist/env-resolve-szSWl0UF.js +94 -0
  59. package/dist/extraction-tools-D3qDFBJ1.js +91 -0
  60. package/dist/extraction-tools-DLr_AEwq.js +5 -0
  61. package/dist/form_data-B_hIUrxU.js +8657 -0
  62. package/dist/gmail-watch-setup-Czt8rXaX.js +40 -0
  63. package/dist/heartbeat-engine-CRqfPcFM.js +83 -0
  64. package/dist/hub-DTsqe5Bt.js +6 -0
  65. package/dist/hub-FrPTA33j.js +515 -0
  66. package/dist/hyperclawbot-D9KCtc4P.js +480 -0
  67. package/dist/hyperclawbot-DfMGowZC.js +480 -0
  68. package/dist/hyperclawbot-Dw27pJo4.js +480 -0
  69. package/dist/inference-CTWJeX9Q.js +922 -0
  70. package/dist/inference-ix607p7k.js +6 -0
  71. package/dist/knowledge-graph-DqA-Fztl.js +131 -0
  72. package/dist/loader-CISCqBto.js +400 -0
  73. package/dist/loader-CYMQ8VOS.js +4 -0
  74. package/dist/logger-8tEtAd3y.js +83 -0
  75. package/dist/manager-CPjeRe-6.js +4 -0
  76. package/dist/manager-Cwzj7w5R.js +105 -0
  77. package/dist/manager-DLmZI-9R.js +6 -0
  78. package/dist/manager-DSGhn5i3.js +117 -0
  79. package/dist/manager-DgyF52mg.js +218 -0
  80. package/dist/manager-Dm8nrMFx.js +40 -0
  81. package/dist/mcp-B_9Ber63.js +139 -0
  82. package/dist/mcp-loader-DSM5UiFG.js +94 -0
  83. package/dist/mcp-loader-j5ZLLw5O.js +94 -0
  84. package/dist/memory-BI1kPkAN.js +4 -0
  85. package/dist/memory-BVFGkxxK.js +270 -0
  86. package/dist/memory-auto-Bc7euou4.js +306 -0
  87. package/dist/memory-auto-DPfbkMVt.js +5 -0
  88. package/dist/memory-integration-DZExqWr4.js +91 -0
  89. package/dist/moltbook-B6ZeGN5_.js +81 -0
  90. package/dist/node-pwL6O_KX.js +222 -0
  91. package/dist/nodes-registry-CsPm_-CJ.js +52 -0
  92. package/dist/oauth-flow-CpWlgvNB.js +150 -0
  93. package/dist/oauth-provider-BZb6qOw5.js +110 -0
  94. package/dist/observability-B43YvNQV.js +89 -0
  95. package/dist/onboard-3q20ZyHj.js +9 -0
  96. package/dist/onboard-Bd_wsYdi.js +4086 -0
  97. package/dist/onboard-CAN7x3me.js +3026 -0
  98. package/dist/onboard-DnegOHMh.js +3026 -0
  99. package/dist/onboard-RYtDlYBw.js +9 -0
  100. package/dist/onboard-aTwlQs-4.js +9 -0
  101. package/dist/orchestrator-BSp2M5EU.js +189 -0
  102. package/dist/orchestrator-C7ko5tWa.js +6 -0
  103. package/dist/orchestrator-DfPkIx2Z.js +6 -0
  104. package/dist/orchestrator-NJQsmiBE.js +189 -0
  105. package/dist/pairing-DU0_J28n.js +87 -0
  106. package/dist/pairing-DWllbSbO.js +4 -0
  107. package/dist/pc-access-Ly-uA8mn.js +8 -0
  108. package/dist/pc-access-NxBvTrRj.js +819 -0
  109. package/dist/pending-approval-DIHvwwWS.js +22 -0
  110. package/dist/puppeteer-2o3QOwAy.js +2 -2
  111. package/dist/puppeteer-BYTMp3BI.js +2 -2
  112. package/dist/puppeteer-DQ45qwWk.js +2 -2
  113. package/dist/reminders-store-D79qdfN0.js +58 -0
  114. package/dist/renderer-pqlDRKbH.js +225 -0
  115. package/dist/rules-BooT_qFP.js +103 -0
  116. package/dist/run-main.js +366 -1109
  117. package/dist/runner-Bu--_RXw.js +810 -0
  118. package/dist/runner-D1rjuMTJ.js +810 -0
  119. package/dist/sdk/index.js +2 -2
  120. package/dist/sdk/index.mjs +2 -2
  121. package/dist/security-C-5URby1.js +73 -0
  122. package/dist/security-_xve79aq.js +4 -0
  123. package/dist/server-0kgyELx4.js +1047 -0
  124. package/dist/server-BIuTobTC.js +4 -0
  125. package/dist/server-BRlCEjyT.js +1047 -0
  126. package/dist/server-CCI1hv45.js +1047 -0
  127. package/dist/server-DU9POoWc.js +4 -0
  128. package/dist/server-RBqwE_GN.js +4 -0
  129. package/dist/session-store-CujxByI6.js +113 -0
  130. package/dist/session-store-qpJUg2M1.js +5 -0
  131. package/dist/sessions-tools-CB2qbwIk.js +5 -0
  132. package/dist/sessions-tools-DHMaTZIs.js +95 -0
  133. package/dist/skill-loader-BkceKkIg.js +7 -0
  134. package/dist/skill-loader-DhgIwK4J.js +159 -0
  135. package/dist/skill-runtime--LqxWrp5.js +102 -0
  136. package/dist/skill-runtime-C5l0Tgt-.js +5 -0
  137. package/dist/skill-runtime-DsXK_HYG.js +102 -0
  138. package/dist/skill-runtime-IVTiqrMR.js +5 -0
  139. package/dist/src-BEVLgaF1.js +63 -0
  140. package/dist/src-Bgu_OxTQ.js +458 -0
  141. package/dist/src-Bq-oKt7Z.js +458 -0
  142. package/dist/src-DWCUhnD4.js +20 -0
  143. package/dist/src-cfRTjFef.js +63 -0
  144. package/dist/sub-agent-tools-BD9DF8_g.js +39 -0
  145. package/dist/sub-agent-tools-V7b3T9_s.js +39 -0
  146. package/dist/tool-policy-DNvNRnve.js +189 -0
  147. package/dist/tts-elevenlabs-BUOGKL-k.js +61 -0
  148. package/dist/update-check-BD4qH7Am.js +81 -0
  149. package/dist/vision-DRq-f-Dj.js +121 -0
  150. package/dist/vision-tools-CFZEpQKm.js +5 -0
  151. package/dist/vision-tools-CQnBI9aa.js +51 -0
  152. package/dist/voice-transcription-CbQBToY0.js +138 -0
  153. package/dist/voice-transcription-CgWq54hn.js +138 -0
  154. package/dist/website-watch-tools-Bk_TnwuE.js +5 -0
  155. package/dist/website-watch-tools-DraMPxdl.js +139 -0
  156. package/package.json +1 -1
@@ -0,0 +1,172 @@
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/synology-chat/src/connector.ts
11
+ const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "synology-chat-state.json");
12
+ function httpsPost(url, body) {
13
+ return new Promise((resolve, reject) => {
14
+ const encoded = Object.entries(body).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join("&");
15
+ const u = new URL(url);
16
+ const isHttps = u.protocol === "https:";
17
+ const mod = isHttps ? https.default : http.default;
18
+ const req = mod.request({
19
+ hostname: u.hostname,
20
+ port: u.port || (isHttps ? 443 : 80),
21
+ path: u.pathname + u.search,
22
+ method: "POST",
23
+ headers: {
24
+ "Content-Type": "application/x-www-form-urlencoded",
25
+ "Content-Length": Buffer.byteLength(encoded)
26
+ }
27
+ }, (res) => {
28
+ let data = "";
29
+ res.on("data", (c) => data += c);
30
+ res.on("end", () => resolve(data));
31
+ });
32
+ req.on("error", reject);
33
+ req.write(encoded);
34
+ req.end();
35
+ });
36
+ }
37
+ var SynologyChatConnector = class extends events.EventEmitter {
38
+ config;
39
+ server = null;
40
+ running = false;
41
+ constructor(config) {
42
+ super();
43
+ this.config = {
44
+ webhookPort: 7789,
45
+ webhookPath: "/synology-hook",
46
+ dmPolicy: "pairing",
47
+ allowFrom: [],
48
+ approvedPairings: [],
49
+ pendingPairings: {},
50
+ ...config
51
+ };
52
+ }
53
+ async connect() {
54
+ await this.loadState();
55
+ await this.startWebhookServer();
56
+ this.running = true;
57
+ console.log(chalk.default.green(` 🦅 Synology Chat: webhook listening on :${this.config.webhookPort}${this.config.webhookPath}`));
58
+ this.emit("connected", { webhookPort: this.config.webhookPort });
59
+ }
60
+ disconnect() {
61
+ this.running = false;
62
+ this.server?.close();
63
+ this.server = null;
64
+ }
65
+ startWebhookServer() {
66
+ return new Promise((resolve, reject) => {
67
+ this.server = http.default.createServer(async (req, res) => {
68
+ if (req.method !== "POST" || req.url !== this.config.webhookPath) {
69
+ res.writeHead(404).end();
70
+ return;
71
+ }
72
+ let body = "";
73
+ req.on("data", (c) => body += c);
74
+ req.on("end", async () => {
75
+ try {
76
+ const params = new URLSearchParams(body);
77
+ const token = params.get("token");
78
+ const text = params.get("text") || "";
79
+ const userId = params.get("user_id") || "unknown";
80
+ const username = params.get("username") || userId;
81
+ const channelId = params.get("channel_id") || "unknown";
82
+ const channelName = params.get("channel_name") || channelId;
83
+ if (this.config.webhookToken && token !== this.config.webhookToken) {
84
+ res.writeHead(403).end("Forbidden");
85
+ return;
86
+ }
87
+ res.writeHead(200, { "Content-Type": "application/json" }).end("{}");
88
+ if (!text || !userId) return;
89
+ const allowed = await this.checkPolicy(userId, username, channelId, text);
90
+ if (!allowed) return;
91
+ this.emit("message", {
92
+ id: `syno-${Date.now()}-${Math.random().toString(36).slice(2)}`,
93
+ channelId: "synology-chat",
94
+ from: username,
95
+ chatId: channelId,
96
+ chatName: channelName,
97
+ text,
98
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
99
+ isDM: false
100
+ });
101
+ } catch (e) {
102
+ console.log(chalk.default.yellow(` ⚠ Synology Chat: ${e.message}`));
103
+ res.writeHead(500).end();
104
+ }
105
+ });
106
+ });
107
+ this.server.listen(this.config.webhookPort, () => resolve());
108
+ this.server.on("error", reject);
109
+ });
110
+ }
111
+ async checkPolicy(userId, username, channelId, 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(userId) || this.config.allowFrom.includes(username)) return true;
116
+ await this.sendMessage(channelId, "🦅 You are not on the allowlist.");
117
+ return false;
118
+ }
119
+ if (this.config.dmPolicy === "pairing") {
120
+ if (this.config.approvedPairings.includes(userId)) return true;
121
+ const upper = text.trim().toUpperCase();
122
+ if (this.config.pendingPairings[upper]) {
123
+ this.config.approvedPairings.push(userId);
124
+ delete this.config.pendingPairings[upper];
125
+ await this.saveState();
126
+ await this.sendMessage(channelId, "🦅 Paired! You can now send messages to the assistant.");
127
+ return true;
128
+ }
129
+ const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
130
+ this.config.pendingPairings[code] = userId;
131
+ await this.saveState();
132
+ await this.sendMessage(channelId, `🦅 Pairing required. Your code: \`${code}\`\nApprove: hyperclaw pairing approve synology-chat ${code}`);
133
+ return false;
134
+ }
135
+ return false;
136
+ }
137
+ async sendMessage(channelId, text) {
138
+ try {
139
+ await httpsPost(this.config.incomingWebhookUrl, { text });
140
+ } catch (e) {
141
+ console.log(chalk.default.yellow(` ⚠ Synology Chat send error: ${e.message}`));
142
+ }
143
+ }
144
+ approvePairing(code) {
145
+ const upper = code.toUpperCase();
146
+ if (!this.config.pendingPairings[upper]) return false;
147
+ this.config.approvedPairings.push(this.config.pendingPairings[upper]);
148
+ delete this.config.pendingPairings[upper];
149
+ this.saveState();
150
+ return true;
151
+ }
152
+ async loadState() {
153
+ try {
154
+ const s = await fs_extra.default.readJson(STATE_FILE);
155
+ if (s.p) this.config.pendingPairings = s.p;
156
+ if (s.a) this.config.approvedPairings = s.a;
157
+ } catch {}
158
+ }
159
+ async saveState() {
160
+ await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
161
+ await fs_extra.default.writeJson(STATE_FILE, {
162
+ p: this.config.pendingPairings,
163
+ a: this.config.approvedPairings
164
+ }, { spaces: 2 });
165
+ }
166
+ isRunning() {
167
+ return this.running;
168
+ }
169
+ };
170
+
171
+ //#endregion
172
+ exports.SynologyChatConnector = SynologyChatConnector;
@@ -0,0 +1,103 @@
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
+
5
+ //#region src/infra/cost-tracker.ts
6
+ /** Rough cost per 1M tokens by provider/model (Claude Sonnet ballpark). */
7
+ const DEFAULT_COST_PER_1M_INPUT = 3;
8
+ const DEFAULT_COST_PER_1M_OUTPUT = 15;
9
+ function estimateCost(usage, model) {
10
+ if (!usage) return 0;
11
+ const inp = (usage.input || 0) + (usage.cacheRead || 0);
12
+ const inputCost = inp / 1e6 * DEFAULT_COST_PER_1M_INPUT;
13
+ const outputCost = (usage.output || 0) / 1e6 * DEFAULT_COST_PER_1M_OUTPUT;
14
+ return inputCost + outputCost;
15
+ }
16
+ /** Path to cost log file for a session. */
17
+ function getCostLogPath(baseDir, sessionId) {
18
+ return path.default.join(baseDir, "costs", `session-${sessionId}.jsonl`);
19
+ }
20
+ /** Append a cost entry for a session. */
21
+ async function recordUsage(baseDir, sessionId, usage, opts) {
22
+ const costUsd = estimateCost(usage, opts?.model);
23
+ const entry = {
24
+ sessionId,
25
+ source: opts?.source,
26
+ tenantId: opts?.tenantId,
27
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
28
+ usage,
29
+ costUsd,
30
+ model: opts?.model
31
+ };
32
+ const dir = path.default.join(baseDir, "costs");
33
+ await fs_extra.default.ensureDir(dir);
34
+ const fp = getCostLogPath(baseDir, sessionId);
35
+ await fs_extra.default.appendFile(fp, JSON.stringify(entry) + "\n");
36
+ }
37
+ /** Read and aggregate all entries for a session. */
38
+ async function getSessionSummary(baseDir, sessionId) {
39
+ const fp = getCostLogPath(baseDir, sessionId);
40
+ if (!await fs_extra.default.pathExists(fp)) return {
41
+ input: 0,
42
+ output: 0,
43
+ cacheRead: 0,
44
+ costUsd: 0,
45
+ runs: 0
46
+ };
47
+ const lines = (await fs_extra.default.readFile(fp, "utf8")).trim().split("\n").filter(Boolean);
48
+ let input = 0, output = 0, cacheRead = 0, costUsd = 0;
49
+ for (const line of lines) try {
50
+ const e = JSON.parse(line);
51
+ input += e.usage.input || 0;
52
+ output += e.usage.output || 0;
53
+ cacheRead += e.usage.cacheRead || 0;
54
+ costUsd += e.costUsd || 0;
55
+ } catch {}
56
+ return {
57
+ input,
58
+ output,
59
+ cacheRead,
60
+ costUsd,
61
+ runs: lines.length
62
+ };
63
+ }
64
+ /** Get global summary across all sessions. */
65
+ async function getGlobalSummary(baseDir) {
66
+ const dir = path.default.join(baseDir, "costs");
67
+ if (!await fs_extra.default.pathExists(dir)) return {
68
+ sessions: 0,
69
+ totalInput: 0,
70
+ totalOutput: 0,
71
+ totalCacheRead: 0,
72
+ totalCostUsd: 0,
73
+ totalRuns: 0
74
+ };
75
+ const files = (await fs_extra.default.readdir(dir)).filter((f) => f.startsWith("session-") && f.endsWith(".jsonl"));
76
+ let totalInput = 0, totalOutput = 0, totalCacheRead = 0, totalCostUsd = 0, totalRuns = 0;
77
+ for (const f of files) {
78
+ const fp = path.default.join(dir, f);
79
+ const content = await fs_extra.default.readFile(fp, "utf8").catch(() => "");
80
+ for (const line of content.trim().split("\n").filter(Boolean)) try {
81
+ const e = JSON.parse(line);
82
+ totalInput += e.usage.input || 0;
83
+ totalOutput += e.usage.output || 0;
84
+ totalCacheRead += e.usage.cacheRead || 0;
85
+ totalCostUsd += e.costUsd || 0;
86
+ totalRuns++;
87
+ } catch {}
88
+ }
89
+ return {
90
+ sessions: files.length,
91
+ totalInput,
92
+ totalOutput,
93
+ totalCacheRead,
94
+ totalCostUsd,
95
+ totalRuns
96
+ };
97
+ }
98
+
99
+ //#endregion
100
+ exports.estimateCost = estimateCost;
101
+ exports.getGlobalSummary = getGlobalSummary;
102
+ exports.getSessionSummary = getSessionSummary;
103
+ exports.recordUsage = recordUsage;
@@ -0,0 +1,4 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const require_credentials_store = require('./credentials-store-sb-TRLwR.js');
3
+
4
+ exports.CredentialsStore = require_credentials_store.CredentialsStore;
@@ -0,0 +1,77 @@
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
+
7
+ //#region src/secrets/credentials-store.ts
8
+ var CredentialsStore = class {
9
+ credsDir;
10
+ constructor(baseDir) {
11
+ this.credsDir = path.default.join(baseDir || path.default.join(os.default.homedir(), ".hyperclaw"), "credentials");
12
+ }
13
+ filePath(providerId) {
14
+ const safe = providerId.replace(/[^a-zA-Z0-9_-]/g, "_");
15
+ return path.default.join(this.credsDir, `${safe}.json`);
16
+ }
17
+ async set(providerId, creds) {
18
+ await fs_extra.default.ensureDir(this.credsDir);
19
+ await fs_extra.default.chmod(this.credsDir, 448);
20
+ const record = {
21
+ ...creds,
22
+ providerId,
23
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
24
+ };
25
+ const fpath = this.filePath(providerId);
26
+ await fs_extra.default.writeJson(fpath, record, { spaces: 2 });
27
+ await fs_extra.default.chmod(fpath, 384);
28
+ }
29
+ async get(providerId) {
30
+ const fpath = this.filePath(providerId);
31
+ if (!await fs_extra.default.pathExists(fpath)) return null;
32
+ const stat = await fs_extra.default.stat(fpath);
33
+ if ((stat.mode & 63) !== 0) {
34
+ console.log(chalk.default.yellow(` ⚠ Unsafe permissions on credentials/${providerId}.json — fixing...`));
35
+ await fs_extra.default.chmod(fpath, 384);
36
+ }
37
+ return fs_extra.default.readJson(fpath);
38
+ }
39
+ async remove(providerId) {
40
+ const fpath = this.filePath(providerId);
41
+ await fs_extra.default.remove(fpath);
42
+ console.log(chalk.default.green(` ✔ Credentials removed: ${providerId}`));
43
+ }
44
+ async list() {
45
+ if (!await fs_extra.default.pathExists(this.credsDir)) return [];
46
+ const files = await fs_extra.default.readdir(this.credsDir);
47
+ return files.filter((f) => f.endsWith(".json")).map((f) => f.replace(".json", ""));
48
+ }
49
+ async showList() {
50
+ const providers = await this.list();
51
+ console.log(chalk.default.bold.cyan("\n 🔐 CREDENTIALS\n"));
52
+ if (providers.length === 0) {
53
+ console.log(chalk.default.gray(" No credentials stored.\n"));
54
+ console.log(chalk.default.gray(" Add with: hyperclaw auth add <service_id> (for any API key)\n"));
55
+ console.log(chalk.default.gray(" Or: hyperclaw secrets set KEY=value (for .env vars)\n"));
56
+ return;
57
+ }
58
+ for (const p of providers) {
59
+ const cred = await this.get(p);
60
+ const hasKey = !!cred?.apiKey;
61
+ const hasRefresh = !!cred?.refreshToken;
62
+ const expiry = cred?.expiresAt ? new Date(cred.expiresAt) > /* @__PURE__ */ new Date() ? chalk.default.green("valid") : chalk.default.red("expired") : chalk.default.gray("no expiry");
63
+ console.log(` ${chalk.default.green("●")} ${chalk.default.white(p.padEnd(20))} ${hasKey ? chalk.default.cyan("api_key") : ""}${hasRefresh ? chalk.default.yellow(" refresh_token") : ""} ${expiry}`);
64
+ console.log(` ${chalk.default.gray(`Updated: ${cred?.updatedAt ? new Date(cred.updatedAt).toLocaleString() : "unknown"}`)}`);
65
+ console.log();
66
+ }
67
+ console.log(chalk.default.gray(" credentials/ — stored at ~/.hyperclaw/credentials/*.json (mode 0600)\n"));
68
+ }
69
+ };
70
+
71
+ //#endregion
72
+ Object.defineProperty(exports, 'CredentialsStore', {
73
+ enumerable: true,
74
+ get: function () {
75
+ return CredentialsStore;
76
+ }
77
+ });
@@ -0,0 +1,82 @@
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
+
6
+ //#region src/services/cron-tasks.ts
7
+ const CRON_TASKS_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "cron-tasks.json");
8
+ let tasks = [];
9
+ async function loadCronTasks() {
10
+ try {
11
+ tasks = await fs_extra.default.readJson(CRON_TASKS_FILE);
12
+ } catch {
13
+ tasks = [];
14
+ }
15
+ return tasks;
16
+ }
17
+ async function saveCronTasks() {
18
+ await fs_extra.default.ensureDir(path.default.dirname(CRON_TASKS_FILE));
19
+ await fs_extra.default.writeJson(CRON_TASKS_FILE, tasks, { spaces: 2 });
20
+ }
21
+ function addCronTask(schedule, prompt, name) {
22
+ const id = `task-${Date.now().toString(36)}`;
23
+ const task = {
24
+ id,
25
+ schedule,
26
+ prompt,
27
+ name,
28
+ enabled: true,
29
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
30
+ };
31
+ tasks.push(task);
32
+ return task;
33
+ }
34
+ function removeCronTask(id) {
35
+ const i = tasks.findIndex((t) => t.id === id);
36
+ if (i >= 0) {
37
+ tasks.splice(i, 1);
38
+ return true;
39
+ }
40
+ return false;
41
+ }
42
+ async function runCronTask(task, port = 18789) {
43
+ const http = await import("http");
44
+ return new Promise((resolve, reject) => {
45
+ const payload = JSON.stringify({ message: task.prompt });
46
+ const req = http.request({
47
+ hostname: "127.0.0.1",
48
+ port,
49
+ path: "/api/webhook/inbound",
50
+ method: "POST",
51
+ headers: {
52
+ "Content-Type": "application/json",
53
+ "Content-Length": Buffer.byteLength(payload)
54
+ }
55
+ }, (res) => {
56
+ let data = "";
57
+ res.on("data", (c) => data += c);
58
+ res.on("end", async () => {
59
+ task.lastRunAt = (/* @__PURE__ */ new Date()).toISOString();
60
+ await saveCronTasks().catch(() => {});
61
+ resolve();
62
+ });
63
+ });
64
+ req.on("error", (e) => {
65
+ console.error(`[cron] task ${task.id} failed:`, e.message);
66
+ resolve();
67
+ });
68
+ req.setTimeout(6e4, () => {
69
+ req.destroy();
70
+ resolve();
71
+ });
72
+ req.write(payload);
73
+ req.end();
74
+ });
75
+ }
76
+
77
+ //#endregion
78
+ exports.addCronTask = addCronTask;
79
+ exports.loadCronTasks = loadCronTasks;
80
+ exports.removeCronTask = removeCronTask;
81
+ exports.runCronTask = runCronTask;
82
+ exports.saveCronTasks = saveCronTasks;
@@ -0,0 +1,95 @@
1
+
2
+ //#region src/channels/delivery.ts
3
+ /**
4
+
5
+ * src/channels/delivery.ts
6
+
7
+ * Delivery pipeline: queue retry, per-channel chunking, media handling.
8
+
9
+ */
10
+ const CHANNEL_MAX_LENGTH = {
11
+ telegram: 4096,
12
+ discord: 2e3,
13
+ whatsapp: 4096,
14
+ "whatsapp-baileys": 4096,
15
+ slack: 4e4,
16
+ googlechat: 4096,
17
+ msteams: 28e3,
18
+ matrix: 32768,
19
+ irc: 512,
20
+ mattermost: 16383,
21
+ signal: 4096,
22
+ line: 2e3,
23
+ twitch: 490,
24
+ viber: 7e3,
25
+ default: 4e3
26
+ };
27
+ function chunkForChannel(text, channelId) {
28
+ const max = CHANNEL_MAX_LENGTH[channelId] ?? CHANNEL_MAX_LENGTH.default;
29
+ if (text.length <= max) return [text];
30
+ const chunks = [];
31
+ let i = 0;
32
+ while (i < text.length) {
33
+ let end = Math.min(i + max, text.length);
34
+ if (end < text.length) {
35
+ const nl = text.lastIndexOf("\n", end);
36
+ if (nl > i) end = nl + 1;
37
+ }
38
+ chunks.push(text.slice(i, end));
39
+ i = end;
40
+ }
41
+ return chunks;
42
+ }
43
+ const DEFAULT_RETRIES = 3;
44
+ const DEFAULT_BACKOFF_MS = 1e3;
45
+ async function withRetry(fn, opts) {
46
+ const retries = opts?.retries ?? DEFAULT_RETRIES;
47
+ const backoff = opts?.backoffMs ?? DEFAULT_BACKOFF_MS;
48
+ let lastErr = null;
49
+ for (let i = 0; i <= retries; i++) try {
50
+ return await fn();
51
+ } catch (e) {
52
+ lastErr = e;
53
+ opts?.onRetry?.(i + 1, lastErr);
54
+ if (i < retries) await new Promise((r) => setTimeout(r, backoff * Math.pow(2, i)));
55
+ }
56
+ throw lastErr;
57
+ }
58
+ /** Enrich message text from voice note (transcribe if audioPath provided). */
59
+ async function enrichVoiceNote(msg) {
60
+ if (!msg.audioPath) return msg.text;
61
+ if (msg.text && msg.text !== "[voice note]") return msg.text;
62
+ try {
63
+ const { transcribeVoiceNote } = await Promise.resolve().then(() => require("./voice-transcription-CbQBToY0.js"));
64
+ const text = await transcribeVoiceNote(msg.audioPath);
65
+ return text || msg.text;
66
+ } catch (e) {
67
+ return `[Voice note — transcription failed: ${e.message}]`;
68
+ }
69
+ }
70
+
71
+ //#endregion
72
+ Object.defineProperty(exports, 'CHANNEL_MAX_LENGTH', {
73
+ enumerable: true,
74
+ get: function () {
75
+ return CHANNEL_MAX_LENGTH;
76
+ }
77
+ });
78
+ Object.defineProperty(exports, 'chunkForChannel', {
79
+ enumerable: true,
80
+ get: function () {
81
+ return chunkForChannel;
82
+ }
83
+ });
84
+ Object.defineProperty(exports, 'enrichVoiceNote', {
85
+ enumerable: true,
86
+ get: function () {
87
+ return enrichVoiceNote;
88
+ }
89
+ });
90
+ Object.defineProperty(exports, 'withRetry', {
91
+ enumerable: true,
92
+ get: function () {
93
+ return withRetry;
94
+ }
95
+ });
@@ -0,0 +1,95 @@
1
+
2
+ //#region src/channels/delivery.ts
3
+ /**
4
+
5
+ * src/channels/delivery.ts
6
+
7
+ * Delivery pipeline: queue retry, per-channel chunking, media handling.
8
+
9
+ */
10
+ const CHANNEL_MAX_LENGTH = {
11
+ telegram: 4096,
12
+ discord: 2e3,
13
+ whatsapp: 4096,
14
+ "whatsapp-baileys": 4096,
15
+ slack: 4e4,
16
+ googlechat: 4096,
17
+ msteams: 28e3,
18
+ matrix: 32768,
19
+ irc: 512,
20
+ mattermost: 16383,
21
+ signal: 4096,
22
+ line: 2e3,
23
+ twitch: 490,
24
+ viber: 7e3,
25
+ default: 4e3
26
+ };
27
+ function chunkForChannel(text, channelId) {
28
+ const max = CHANNEL_MAX_LENGTH[channelId] ?? CHANNEL_MAX_LENGTH.default;
29
+ if (text.length <= max) return [text];
30
+ const chunks = [];
31
+ let i = 0;
32
+ while (i < text.length) {
33
+ let end = Math.min(i + max, text.length);
34
+ if (end < text.length) {
35
+ const nl = text.lastIndexOf("\n", end);
36
+ if (nl > i) end = nl + 1;
37
+ }
38
+ chunks.push(text.slice(i, end));
39
+ i = end;
40
+ }
41
+ return chunks;
42
+ }
43
+ const DEFAULT_RETRIES = 3;
44
+ const DEFAULT_BACKOFF_MS = 1e3;
45
+ async function withRetry(fn, opts) {
46
+ const retries = opts?.retries ?? DEFAULT_RETRIES;
47
+ const backoff = opts?.backoffMs ?? DEFAULT_BACKOFF_MS;
48
+ let lastErr = null;
49
+ for (let i = 0; i <= retries; i++) try {
50
+ return await fn();
51
+ } catch (e) {
52
+ lastErr = e;
53
+ opts?.onRetry?.(i + 1, lastErr);
54
+ if (i < retries) await new Promise((r) => setTimeout(r, backoff * Math.pow(2, i)));
55
+ }
56
+ throw lastErr;
57
+ }
58
+ /** Enrich message text from voice note (transcribe if audioPath provided). */
59
+ async function enrichVoiceNote(msg) {
60
+ if (!msg.audioPath) return msg.text;
61
+ if (msg.text && msg.text !== "[voice note]") return msg.text;
62
+ try {
63
+ const { transcribeVoiceNote } = await Promise.resolve().then(() => require("./voice-transcription-CgWq54hn.js"));
64
+ const text = await transcribeVoiceNote(msg.audioPath);
65
+ return text || msg.text;
66
+ } catch (e) {
67
+ return `[Voice note — transcription failed: ${e.message}]`;
68
+ }
69
+ }
70
+
71
+ //#endregion
72
+ Object.defineProperty(exports, 'CHANNEL_MAX_LENGTH', {
73
+ enumerable: true,
74
+ get: function () {
75
+ return CHANNEL_MAX_LENGTH;
76
+ }
77
+ });
78
+ Object.defineProperty(exports, 'chunkForChannel', {
79
+ enumerable: true,
80
+ get: function () {
81
+ return chunkForChannel;
82
+ }
83
+ });
84
+ Object.defineProperty(exports, 'enrichVoiceNote', {
85
+ enumerable: true,
86
+ get: function () {
87
+ return enrichVoiceNote;
88
+ }
89
+ });
90
+ Object.defineProperty(exports, 'withRetry', {
91
+ enumerable: true,
92
+ get: function () {
93
+ return withRetry;
94
+ }
95
+ });
@@ -0,0 +1,5 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const require_delivery = require('./delivery-D5Z98EVq.js');
3
+
4
+ exports.enrichVoiceNote = require_delivery.enrichVoiceNote;
5
+ exports.withRetry = require_delivery.withRetry;
@@ -0,0 +1,5 @@
1
+ const require_chunk = require('./chunk-jS-bbMI5.js');
2
+ const require_delivery = require('./delivery-B-SJqXLn.js');
3
+
4
+ exports.enrichVoiceNote = require_delivery.enrichVoiceNote;
5
+ exports.withRetry = require_delivery.withRetry;