hyperclaw 5.2.7 → 5.2.8
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/dist/agents-routing-Cee7wrfi.js +398 -0
- package/dist/agents-routing-uNzqjgOr.js +6 -0
- package/dist/api-key-validation-DydlUth1.js +64 -0
- package/dist/api-keys-guide-DqRGa4x7.js +149 -0
- package/dist/audit-CX5poVMR.js +445 -0
- package/dist/bounty-tools-BoU1NN5N.js +211 -0
- package/dist/chat-C07wF0mM.js +494 -0
- package/dist/claw-tasks-BLqd1a0Q.js +80 -0
- package/dist/config-BlLlJ6Er.js +7 -0
- package/dist/config-SgDxKyfV.js +261 -0
- package/dist/cost-tracker-CgEXyEtz.js +103 -0
- package/dist/credentials-store-1LDtNReY.js +89 -0
- package/dist/credentials-store-BFxEJR00.js +7 -0
- package/dist/cron-tasks-1E6wKpTv.js +85 -0
- package/dist/daemon-B13UIqvL.js +7 -0
- package/dist/daemon-CzOW-1PS.js +421 -0
- package/dist/delivery-B8YGmrq5.js +4 -0
- package/dist/delivery-DWsU6gx-.js +95 -0
- package/dist/destructive-gate-bnkroJWG.js +101 -0
- package/dist/engine-ByQ-0sWM.js +7 -0
- package/dist/engine-gnMjO743.js +327 -0
- package/dist/env-resolve-BdagnXhK.js +151 -0
- package/dist/env-resolve-NEtsGacw.js +10 -0
- package/dist/gmail-watch-setup-Brkj94Sy.js +42 -0
- package/dist/heartbeat-engine-D6oSpgxx.js +89 -0
- package/dist/hyperclawbot-DzP_v3iA.js +516 -0
- package/dist/inference-BHJFPEKL.js +8 -0
- package/dist/inference-vweXyh27.js +2854 -0
- package/dist/knowledge-graph-yeMPBPP8.js +134 -0
- package/dist/loader-BXYJl25e.js +6 -0
- package/dist/loader-gTdKBwiI.js +410 -0
- package/dist/logger-C3ZCDSkc.js +86 -0
- package/dist/manager-BI3izlRG.js +120 -0
- package/dist/manager-CQ3MWNHY.js +250 -0
- package/dist/mcp-CklaYr_6.js +142 -0
- package/dist/mcp-loader-9v8eUsNI.js +93 -0
- package/dist/memory-auto-Bow9u_L7.js +306 -0
- package/dist/memory-auto-CgBAI8mm.js +5 -0
- package/dist/memory-integration-CveUEI3V.js +91 -0
- package/dist/moltbook-xP7VXKlX.js +81 -0
- package/dist/node-urDjajMt.js +226 -0
- package/dist/nodes-registry-Cd4eWw80.js +52 -0
- package/dist/oauth-flow-Bt-LaRHV.js +148 -0
- package/dist/oauth-provider-CVTKgj35.js +111 -0
- package/dist/observability-lwYm4aoB.js +89 -0
- package/dist/onboard-BV5Poocl.js +13 -0
- package/dist/onboard-UiynbNQy.js +3909 -0
- package/dist/orchestrator-DMZkAVa5.js +189 -0
- package/dist/orchestrator-rVGu7yYr.js +6 -0
- package/dist/osint-chat-Hn8qpsC1.js +836 -0
- package/dist/osint-f9DeXT6j.js +283 -0
- package/dist/pending-approval-CHUZ_qT6.js +22 -0
- package/dist/run-main.js +68 -65
- package/dist/runner-B9xANekJ.js +1274 -0
- package/dist/security--17Fxo5Z.js +4 -0
- package/dist/security-DP1qtJfL.js +90 -0
- package/dist/server-DUDXqJSo.js +1365 -0
- package/dist/server-ha59nA8a.js +4 -0
- package/dist/skill-runtime-BRp2D8Jb.js +5 -0
- package/dist/skill-runtime-C8bNwKwz.js +104 -0
- package/dist/src-B8LzGLSY.js +63 -0
- package/dist/src-DUoc6_kn.js +458 -0
- package/dist/sub-agent-tools-CldaMfd5.js +39 -0
- package/dist/tool-policy-DtGf3Ifq.js +189 -0
- package/dist/tts-elevenlabs-1zWD3QJw.js +64 -0
- package/dist/vision-DV2ubVjr.js +167 -0
- package/dist/vision-tools-Cb86uMdh.js +5 -0
- package/dist/vision-tools-DlnxaZjg.js +51 -0
- package/dist/voice-transcription-BolTT_HG.js +170 -0
- package/package.json +4 -1
- package/static/chat.html +9 -3
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
const require_paths = require('./paths-AIyBxIzm.js');
|
|
3
|
+
const require_paths$1 = require('./paths-DPovhojT.js');
|
|
4
|
+
const require_env_resolve = require('./env-resolve-BdagnXhK.js');
|
|
5
|
+
const chalk = require_chunk.__toESM(require("chalk"));
|
|
6
|
+
const fs_extra = require_chunk.__toESM(require("fs-extra"));
|
|
7
|
+
|
|
8
|
+
//#region src/cli/config.ts
|
|
9
|
+
require_paths$1.init_paths();
|
|
10
|
+
require_env_resolve.init_env_resolve();
|
|
11
|
+
const getHC_DIR = () => require_paths.getHyperClawDir();
|
|
12
|
+
const getCFG_FILE = () => require_paths.getConfigPath();
|
|
13
|
+
var ConfigStore = class {
|
|
14
|
+
/** Load raw config from disk (no hydration). Use for persistence to avoid writing resolved secrets back. */
|
|
15
|
+
async loadRaw() {
|
|
16
|
+
try {
|
|
17
|
+
return await fs_extra.default.readJson(getCFG_FILE());
|
|
18
|
+
} catch (e) {
|
|
19
|
+
if (e?.code === "ENOENT") return {};
|
|
20
|
+
console.error("[config] Failed to load config:", e?.message ?? String(e));
|
|
21
|
+
throw e;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Load config with env/credentials hydration for runtime use. Do NOT pass the result to save — use patch/save with explicit values only. */
|
|
25
|
+
async load() {
|
|
26
|
+
try {
|
|
27
|
+
const cfg = await fs_extra.default.readJson(getCFG_FILE());
|
|
28
|
+
if (cfg.channelConfigs) for (const [chId, ch] of Object.entries(cfg.channelConfigs)) {
|
|
29
|
+
const tok = require_env_resolve.resolveChannelToken(chId, ch?.token || ch?.botToken);
|
|
30
|
+
if (tok && !ch?.token) ch.token = tok;
|
|
31
|
+
if (tok && !ch?.botToken) ch.botToken = tok;
|
|
32
|
+
}
|
|
33
|
+
if (cfg.provider && !cfg.provider.apiKey) {
|
|
34
|
+
const key = await require_env_resolve.getProviderCredentialAsync(cfg);
|
|
35
|
+
if (key) cfg.provider.apiKey = key;
|
|
36
|
+
}
|
|
37
|
+
return cfg;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
if (e?.code === "ENOENT") return {};
|
|
40
|
+
console.error("[config] Failed to load config:", e?.message ?? String(e));
|
|
41
|
+
throw e;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async save(cfg) {
|
|
45
|
+
const target = getCFG_FILE();
|
|
46
|
+
const tmp = target + ".tmp";
|
|
47
|
+
await fs_extra.default.ensureDir(getHC_DIR());
|
|
48
|
+
await fs_extra.default.writeJson(tmp, cfg, { spaces: 2 });
|
|
49
|
+
await fs_extra.default.chmod(tmp, 384);
|
|
50
|
+
await fs_extra.default.rename(tmp, target);
|
|
51
|
+
}
|
|
52
|
+
/** Merge patch into raw config and save. Uses loadRaw() so hydrated secrets from env/store are never written back. */
|
|
53
|
+
async patch(patch) {
|
|
54
|
+
const raw = await this.loadRaw();
|
|
55
|
+
await this.save(deepMerge(raw, patch));
|
|
56
|
+
}
|
|
57
|
+
async setProviderKey(providerId, apiKey) {
|
|
58
|
+
const cfg = await this.load();
|
|
59
|
+
await this.patch({ provider: {
|
|
60
|
+
...cfg.provider,
|
|
61
|
+
providerId,
|
|
62
|
+
apiKey
|
|
63
|
+
} });
|
|
64
|
+
console.log(chalk.default.green(` ✅ API key saved for ${providerId}`));
|
|
65
|
+
}
|
|
66
|
+
async setModel(modelId) {
|
|
67
|
+
const cfg = await this.load();
|
|
68
|
+
await this.patch({ provider: {
|
|
69
|
+
...cfg.provider,
|
|
70
|
+
modelId
|
|
71
|
+
} });
|
|
72
|
+
console.log(chalk.default.green(` ✅ Model: ${modelId}`));
|
|
73
|
+
}
|
|
74
|
+
async setServiceApiKey(serviceId, apiKey) {
|
|
75
|
+
const cfg = await this.load();
|
|
76
|
+
const apiKeys = {
|
|
77
|
+
...cfg.skills?.apiKeys || {},
|
|
78
|
+
[serviceId]: apiKey
|
|
79
|
+
};
|
|
80
|
+
await this.patch({ skills: {
|
|
81
|
+
...cfg.skills,
|
|
82
|
+
installed: cfg.skills?.installed || [],
|
|
83
|
+
apiKeys
|
|
84
|
+
} });
|
|
85
|
+
console.log(chalk.default.green(` ✅ Service API key saved for ${serviceId}`));
|
|
86
|
+
}
|
|
87
|
+
async enableChannel(channelId, channelConfig) {
|
|
88
|
+
const cfg = await this.load();
|
|
89
|
+
const gwBase = cfg.gateway ?? {
|
|
90
|
+
port: 18789,
|
|
91
|
+
bind: "127.0.0.1",
|
|
92
|
+
authToken: "",
|
|
93
|
+
runtime: "node",
|
|
94
|
+
enabledChannels: [],
|
|
95
|
+
hooks: true,
|
|
96
|
+
tailscaleExposure: "off"
|
|
97
|
+
};
|
|
98
|
+
const channels = gwBase.enabledChannels ?? [];
|
|
99
|
+
if (!channels.includes(channelId)) channels.push(channelId);
|
|
100
|
+
const patch = { gateway: {
|
|
101
|
+
...gwBase,
|
|
102
|
+
enabledChannels: channels
|
|
103
|
+
} };
|
|
104
|
+
if (channelConfig) patch.channelConfigs = {
|
|
105
|
+
...cfg.channelConfigs,
|
|
106
|
+
[channelId]: channelConfig
|
|
107
|
+
};
|
|
108
|
+
await this.patch(patch);
|
|
109
|
+
console.log(chalk.default.green(` ✅ Channel enabled: ${channelId}`));
|
|
110
|
+
}
|
|
111
|
+
async disableChannel(channelId) {
|
|
112
|
+
const cfg = await this.load();
|
|
113
|
+
const gwBase = cfg.gateway ?? {
|
|
114
|
+
port: 18789,
|
|
115
|
+
bind: "127.0.0.1",
|
|
116
|
+
authToken: "",
|
|
117
|
+
runtime: "node",
|
|
118
|
+
enabledChannels: [],
|
|
119
|
+
hooks: true,
|
|
120
|
+
tailscaleExposure: "off"
|
|
121
|
+
};
|
|
122
|
+
const channels = (gwBase.enabledChannels ?? []).filter((c) => c !== channelId);
|
|
123
|
+
await this.patch({ gateway: {
|
|
124
|
+
...gwBase,
|
|
125
|
+
enabledChannels: channels
|
|
126
|
+
} });
|
|
127
|
+
console.log(chalk.default.green(` ✅ Channel disabled: ${channelId}`));
|
|
128
|
+
}
|
|
129
|
+
async setGatewayPort(port) {
|
|
130
|
+
const cfg = await this.load();
|
|
131
|
+
const gwBase = cfg.gateway ?? {
|
|
132
|
+
port: 18789,
|
|
133
|
+
bind: "127.0.0.1",
|
|
134
|
+
authToken: "",
|
|
135
|
+
runtime: "node",
|
|
136
|
+
enabledChannels: [],
|
|
137
|
+
hooks: true,
|
|
138
|
+
tailscaleExposure: "off"
|
|
139
|
+
};
|
|
140
|
+
await this.patch({ gateway: {
|
|
141
|
+
...gwBase,
|
|
142
|
+
port
|
|
143
|
+
} });
|
|
144
|
+
}
|
|
145
|
+
async setGatewayBind(bind) {
|
|
146
|
+
const cfg = await this.load();
|
|
147
|
+
const gwBase = cfg.gateway ?? {
|
|
148
|
+
port: 18789,
|
|
149
|
+
bind: "127.0.0.1",
|
|
150
|
+
authToken: "",
|
|
151
|
+
runtime: "node",
|
|
152
|
+
enabledChannels: [],
|
|
153
|
+
hooks: true,
|
|
154
|
+
tailscaleExposure: "off"
|
|
155
|
+
};
|
|
156
|
+
await this.patch({ gateway: {
|
|
157
|
+
...gwBase,
|
|
158
|
+
bind
|
|
159
|
+
} });
|
|
160
|
+
}
|
|
161
|
+
async generateToken() {
|
|
162
|
+
const token = require("crypto").randomBytes(32).toString("base64url");
|
|
163
|
+
const cfg = await this.load();
|
|
164
|
+
const gwBase = cfg.gateway ?? {
|
|
165
|
+
port: 18789,
|
|
166
|
+
bind: "127.0.0.1",
|
|
167
|
+
authToken: "",
|
|
168
|
+
runtime: "node",
|
|
169
|
+
enabledChannels: [],
|
|
170
|
+
hooks: true,
|
|
171
|
+
tailscaleExposure: "off"
|
|
172
|
+
};
|
|
173
|
+
await this.patch({ gateway: {
|
|
174
|
+
...gwBase,
|
|
175
|
+
authToken: token
|
|
176
|
+
} });
|
|
177
|
+
return token;
|
|
178
|
+
}
|
|
179
|
+
async show(scrub = true) {
|
|
180
|
+
const cfg = await this.load();
|
|
181
|
+
const display = scrub ? scrubSecrets(cfg) : cfg;
|
|
182
|
+
console.log(chalk.default.bold.cyan("\n 🦅 HYPERCLAW CONFIGURATION\n"));
|
|
183
|
+
printSection("Provider", display.provider);
|
|
184
|
+
printSection("Gateway", display.gateway);
|
|
185
|
+
printSection("Identity", display.identity);
|
|
186
|
+
printSection("PC Access", display.pcAccess);
|
|
187
|
+
if (display.channelConfigs && Object.keys(display.channelConfigs).length > 0) {
|
|
188
|
+
console.log(chalk.default.bold.white(" Channel Configs:"));
|
|
189
|
+
for (const [ch, v] of Object.entries(display.channelConfigs)) {
|
|
190
|
+
const scrubbed = scrubChannelConfig(v);
|
|
191
|
+
console.log(` ${chalk.default.cyan(ch)}: ${JSON.stringify(scrubbed).slice(0, 80)}`);
|
|
192
|
+
}
|
|
193
|
+
console.log();
|
|
194
|
+
}
|
|
195
|
+
if (display.skills?.installed?.length) {
|
|
196
|
+
console.log(chalk.default.bold.white(" Skills:"));
|
|
197
|
+
display.skills.installed.forEach((s) => console.log(` • ${s}`));
|
|
198
|
+
console.log();
|
|
199
|
+
}
|
|
200
|
+
console.log(chalk.default.gray(` Config file: ${getCFG_FILE()}`));
|
|
201
|
+
console.log();
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
function deepMerge(base, patch) {
|
|
205
|
+
const result = { ...base };
|
|
206
|
+
for (const key of Object.keys(patch || {})) {
|
|
207
|
+
if (patch[key] === void 0) continue;
|
|
208
|
+
if (patch[key] !== null && typeof patch[key] === "object" && !Array.isArray(patch[key])) result[key] = deepMerge(base[key] || {}, patch[key]);
|
|
209
|
+
else result[key] = patch[key];
|
|
210
|
+
}
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
function scrubSecrets(cfg) {
|
|
214
|
+
const s = JSON.parse(JSON.stringify(cfg));
|
|
215
|
+
if (s.provider?.apiKey) s.provider.apiKey = "●●●●●●●●";
|
|
216
|
+
if (Array.isArray(s.providers)) for (const p of s.providers) {
|
|
217
|
+
if (p.apiKey) p.apiKey = "●●●●●●●●";
|
|
218
|
+
if (Array.isArray(p.apiKeys)) p.apiKeys = p.apiKeys.map(() => "●●●●●●●●");
|
|
219
|
+
}
|
|
220
|
+
if (s.gateway?.authToken) s.gateway.authToken = "●●●●●●●●";
|
|
221
|
+
if (s.gateway?.remote?.token) s.gateway.remote.token = "●●●●●●●●";
|
|
222
|
+
if (s.gateway?.remote?.password) s.gateway.remote.password = "●●●●●●●●";
|
|
223
|
+
if (s.talkMode?.apiKey) s.talkMode.apiKey = "●●●●●●●●";
|
|
224
|
+
if (s.skills?.apiKeys) {
|
|
225
|
+
const keys = Object.keys(s.skills.apiKeys);
|
|
226
|
+
s.skills.apiKeys = Object.fromEntries(keys.map((k) => [k, "●●●●●●●●"]));
|
|
227
|
+
}
|
|
228
|
+
return s;
|
|
229
|
+
}
|
|
230
|
+
function scrubChannelConfig(ch) {
|
|
231
|
+
const s = { ...ch };
|
|
232
|
+
const secretFields = [
|
|
233
|
+
"token",
|
|
234
|
+
"accessToken",
|
|
235
|
+
"apiKey",
|
|
236
|
+
"appSecret",
|
|
237
|
+
"appPassword",
|
|
238
|
+
"signingSecret",
|
|
239
|
+
"channelSecret",
|
|
240
|
+
"secretKey",
|
|
241
|
+
"password",
|
|
242
|
+
"verifyToken"
|
|
243
|
+
];
|
|
244
|
+
for (const f of secretFields) if (s[f]) s[f] = "●●●●●●●●";
|
|
245
|
+
return s;
|
|
246
|
+
}
|
|
247
|
+
function printSection(label, data) {
|
|
248
|
+
if (!data || Object.keys(data).length === 0) return;
|
|
249
|
+
console.log(chalk.default.bold.white(` ${label}:`));
|
|
250
|
+
for (const [k, v] of Object.entries(data)) if (Array.isArray(v)) console.log(` ${chalk.default.gray(k)}: ${v.join(", ") || "(none)"}`);
|
|
251
|
+
else console.log(` ${chalk.default.gray(k)}: ${v}`);
|
|
252
|
+
console.log();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
//#endregion
|
|
256
|
+
Object.defineProperty(exports, 'ConfigStore', {
|
|
257
|
+
enumerable: true,
|
|
258
|
+
get: function () {
|
|
259
|
+
return ConfigStore;
|
|
260
|
+
}
|
|
261
|
+
});
|
|
@@ -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,89 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
const require_paths = require('./paths-AIyBxIzm.js');
|
|
3
|
+
const require_paths$1 = require('./paths-DPovhojT.js');
|
|
4
|
+
const chalk = require_chunk.__toESM(require("chalk"));
|
|
5
|
+
const fs_extra = require_chunk.__toESM(require("fs-extra"));
|
|
6
|
+
const path = require_chunk.__toESM(require("path"));
|
|
7
|
+
|
|
8
|
+
//#region src/secrets/credentials-store.ts
|
|
9
|
+
var CredentialsStore;
|
|
10
|
+
var init_credentials_store = require_chunk.__esm({ "src/secrets/credentials-store.ts"() {
|
|
11
|
+
require_paths$1.init_paths();
|
|
12
|
+
CredentialsStore = class {
|
|
13
|
+
credsDir;
|
|
14
|
+
constructor(baseDir) {
|
|
15
|
+
const base = baseDir ?? require_paths.getHyperClawDir();
|
|
16
|
+
this.credsDir = path.default.join(base, "credentials");
|
|
17
|
+
}
|
|
18
|
+
filePath(providerId) {
|
|
19
|
+
const safe = providerId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
20
|
+
return path.default.join(this.credsDir, `${safe}.json`);
|
|
21
|
+
}
|
|
22
|
+
async set(providerId, creds) {
|
|
23
|
+
await fs_extra.default.ensureDir(this.credsDir);
|
|
24
|
+
await fs_extra.default.chmod(this.credsDir, 448);
|
|
25
|
+
const record = {
|
|
26
|
+
...creds,
|
|
27
|
+
providerId,
|
|
28
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
29
|
+
};
|
|
30
|
+
const fpath = this.filePath(providerId);
|
|
31
|
+
await fs_extra.default.writeJson(fpath, record, { spaces: 2 });
|
|
32
|
+
await fs_extra.default.chmod(fpath, 384);
|
|
33
|
+
}
|
|
34
|
+
async get(providerId) {
|
|
35
|
+
const fpath = this.filePath(providerId);
|
|
36
|
+
if (!await fs_extra.default.pathExists(fpath)) return null;
|
|
37
|
+
const stat = await fs_extra.default.stat(fpath);
|
|
38
|
+
if (process.platform !== "win32" && (stat.mode & 63) !== 0) {
|
|
39
|
+
console.log(chalk.default.yellow(` ⚠ Unsafe permissions on credentials/${providerId}.json — fixing...`));
|
|
40
|
+
await fs_extra.default.chmod(fpath, 384);
|
|
41
|
+
}
|
|
42
|
+
return fs_extra.default.readJson(fpath);
|
|
43
|
+
}
|
|
44
|
+
async remove(providerId) {
|
|
45
|
+
const fpath = this.filePath(providerId);
|
|
46
|
+
await fs_extra.default.remove(fpath);
|
|
47
|
+
console.log(chalk.default.green(` ✔ Credentials removed: ${providerId}`));
|
|
48
|
+
}
|
|
49
|
+
async list() {
|
|
50
|
+
if (!await fs_extra.default.pathExists(this.credsDir)) return [];
|
|
51
|
+
const files = await fs_extra.default.readdir(this.credsDir);
|
|
52
|
+
return files.filter((f) => f.endsWith(".json")).map((f) => f.replace(".json", ""));
|
|
53
|
+
}
|
|
54
|
+
async showList() {
|
|
55
|
+
const providers = await this.list();
|
|
56
|
+
console.log(chalk.default.bold.cyan("\n 🔐 CREDENTIALS\n"));
|
|
57
|
+
if (providers.length === 0) {
|
|
58
|
+
console.log(chalk.default.gray(" No credentials stored.\n"));
|
|
59
|
+
console.log(chalk.default.gray(" Add with: hyperclaw auth add <service_id> (for any API key)\n"));
|
|
60
|
+
console.log(chalk.default.gray(" Or: hyperclaw secrets set KEY=value (for .env vars)\n"));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
for (const p of providers) {
|
|
64
|
+
const cred = await this.get(p);
|
|
65
|
+
const hasKey = !!cred?.apiKey;
|
|
66
|
+
const hasRefresh = !!cred?.refreshToken;
|
|
67
|
+
const expiry = cred?.expiresAt ? new Date(cred.expiresAt) > /* @__PURE__ */ new Date() ? chalk.default.green("valid") : chalk.default.red("expired") : chalk.default.gray("no expiry");
|
|
68
|
+
console.log(` ${chalk.default.green("●")} ${chalk.default.white(p.padEnd(20))} ${hasKey ? chalk.default.cyan("api_key") : ""}${hasRefresh ? chalk.default.yellow(" refresh_token") : ""} ${expiry}`);
|
|
69
|
+
console.log(` ${chalk.default.gray(`Updated: ${cred?.updatedAt ? new Date(cred.updatedAt).toLocaleString() : "unknown"}`)}`);
|
|
70
|
+
console.log();
|
|
71
|
+
}
|
|
72
|
+
console.log(chalk.default.gray(" credentials/ — stored at ~/.hyperclaw/credentials/*.json (mode 0600)\n"));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
} });
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
Object.defineProperty(exports, 'CredentialsStore', {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return CredentialsStore;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports, 'init_credentials_store', {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return init_credentials_store;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
require('./paths-AIyBxIzm.js');
|
|
3
|
+
require('./paths-DPovhojT.js');
|
|
4
|
+
const require_credentials_store = require('./credentials-store-1LDtNReY.js');
|
|
5
|
+
|
|
6
|
+
require_credentials_store.init_credentials_store();
|
|
7
|
+
exports.CredentialsStore = require_credentials_store.CredentialsStore;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
const require_paths = require('./paths-AIyBxIzm.js');
|
|
3
|
+
const require_paths$1 = require('./paths-DPovhojT.js');
|
|
4
|
+
const fs_extra = require_chunk.__toESM(require("fs-extra"));
|
|
5
|
+
const path = require_chunk.__toESM(require("path"));
|
|
6
|
+
|
|
7
|
+
//#region src/services/cron-tasks.ts
|
|
8
|
+
require_paths$1.init_paths();
|
|
9
|
+
const getCronTasksFile = () => path.default.join(require_paths.getHyperClawDir(), "cron-tasks.json");
|
|
10
|
+
let tasks = [];
|
|
11
|
+
async function loadCronTasks() {
|
|
12
|
+
try {
|
|
13
|
+
tasks = await fs_extra.default.readJson(getCronTasksFile());
|
|
14
|
+
} catch {
|
|
15
|
+
tasks = [];
|
|
16
|
+
}
|
|
17
|
+
return tasks;
|
|
18
|
+
}
|
|
19
|
+
async function saveCronTasks() {
|
|
20
|
+
const f = getCronTasksFile();
|
|
21
|
+
await fs_extra.default.ensureDir(path.default.dirname(f));
|
|
22
|
+
await fs_extra.default.writeJson(f, tasks, { spaces: 2 });
|
|
23
|
+
}
|
|
24
|
+
function addCronTask(schedule, prompt, name) {
|
|
25
|
+
const id = `task-${Date.now().toString(36)}`;
|
|
26
|
+
const task = {
|
|
27
|
+
id,
|
|
28
|
+
schedule,
|
|
29
|
+
prompt,
|
|
30
|
+
name,
|
|
31
|
+
enabled: true,
|
|
32
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
33
|
+
};
|
|
34
|
+
tasks.push(task);
|
|
35
|
+
return task;
|
|
36
|
+
}
|
|
37
|
+
function removeCronTask(id) {
|
|
38
|
+
const i = tasks.findIndex((t) => t.id === id);
|
|
39
|
+
if (i >= 0) {
|
|
40
|
+
tasks.splice(i, 1);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
async function runCronTask(task, port = 18789) {
|
|
46
|
+
const http = await import("http");
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
const payload = JSON.stringify({ message: task.prompt });
|
|
49
|
+
const req = http.request({
|
|
50
|
+
hostname: "127.0.0.1",
|
|
51
|
+
port,
|
|
52
|
+
path: "/api/webhook/inbound",
|
|
53
|
+
method: "POST",
|
|
54
|
+
headers: {
|
|
55
|
+
"Content-Type": "application/json",
|
|
56
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
57
|
+
}
|
|
58
|
+
}, (res) => {
|
|
59
|
+
let data = "";
|
|
60
|
+
res.on("data", (c) => data += c);
|
|
61
|
+
res.on("end", async () => {
|
|
62
|
+
task.lastRunAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
63
|
+
await saveCronTasks().catch(() => {});
|
|
64
|
+
resolve();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
req.on("error", (e) => {
|
|
68
|
+
console.error(`[cron] task ${task.id} failed:`, e.message);
|
|
69
|
+
resolve();
|
|
70
|
+
});
|
|
71
|
+
req.setTimeout(6e4, () => {
|
|
72
|
+
req.destroy();
|
|
73
|
+
resolve();
|
|
74
|
+
});
|
|
75
|
+
req.write(payload);
|
|
76
|
+
req.end();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
exports.addCronTask = addCronTask;
|
|
82
|
+
exports.loadCronTasks = loadCronTasks;
|
|
83
|
+
exports.removeCronTask = removeCronTask;
|
|
84
|
+
exports.runCronTask = runCronTask;
|
|
85
|
+
exports.saveCronTasks = saveCronTasks;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
require('./paths-AIyBxIzm.js');
|
|
3
|
+
require('./paths-DPovhojT.js');
|
|
4
|
+
require('./server-DUDXqJSo.js');
|
|
5
|
+
const require_daemon = require('./daemon-CzOW-1PS.js');
|
|
6
|
+
|
|
7
|
+
exports.DaemonManager = require_daemon.DaemonManager;
|