@blockrun/clawrouter 0.12.9 → 0.12.10
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/cli.js +26 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +40 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2317,7 +2317,7 @@ async function logUsage(entry) {
|
|
|
2317
2317
|
}
|
|
2318
2318
|
|
|
2319
2319
|
// src/stats.ts
|
|
2320
|
-
import { readdir } from "fs/promises";
|
|
2320
|
+
import { readdir, unlink } from "fs/promises";
|
|
2321
2321
|
|
|
2322
2322
|
// src/fs-read.ts
|
|
2323
2323
|
import { open } from "fs/promises";
|
|
@@ -2486,6 +2486,16 @@ async function getStats(days = 7) {
|
|
|
2486
2486
|
// How many entries have valid baseline tracking
|
|
2487
2487
|
};
|
|
2488
2488
|
}
|
|
2489
|
+
async function clearStats() {
|
|
2490
|
+
try {
|
|
2491
|
+
const files = await readdir(LOG_DIR2);
|
|
2492
|
+
const logFiles = files.filter((f) => f.startsWith("usage-") && f.endsWith(".jsonl"));
|
|
2493
|
+
await Promise.all(logFiles.map((f) => unlink(join3(LOG_DIR2, f))));
|
|
2494
|
+
return { deletedFiles: logFiles.length };
|
|
2495
|
+
} catch {
|
|
2496
|
+
return { deletedFiles: 0 };
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2489
2499
|
|
|
2490
2500
|
// src/dedup.ts
|
|
2491
2501
|
import { createHash } from "crypto";
|
|
@@ -5647,6 +5657,21 @@ async function startProxy(options) {
|
|
|
5647
5657
|
res.end(JSON.stringify(stats, null, 2));
|
|
5648
5658
|
return;
|
|
5649
5659
|
}
|
|
5660
|
+
if (req.url === "/stats" && req.method === "DELETE") {
|
|
5661
|
+
try {
|
|
5662
|
+
const result = await clearStats();
|
|
5663
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
5664
|
+
res.end(JSON.stringify({ cleared: true, deletedFiles: result.deletedFiles }));
|
|
5665
|
+
} catch (err) {
|
|
5666
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
5667
|
+
res.end(
|
|
5668
|
+
JSON.stringify({
|
|
5669
|
+
error: `Failed to clear stats: ${err instanceof Error ? err.message : String(err)}`
|
|
5670
|
+
})
|
|
5671
|
+
);
|
|
5672
|
+
}
|
|
5673
|
+
return;
|
|
5674
|
+
}
|
|
5650
5675
|
if (req.url === "/stats" || req.url?.startsWith("/stats?")) {
|
|
5651
5676
|
try {
|
|
5652
5677
|
const url = new URL(req.url, "http://localhost");
|