@blockrun/clawrouter 0.12.2 → 0.12.4

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 CHANGED
@@ -2295,9 +2295,15 @@ import { openSync, readSync, closeSync, fstatSync } from "fs";
2295
2295
  async function readTextFile(filePath) {
2296
2296
  const fh = await open(filePath, "r");
2297
2297
  try {
2298
- const buf = Buffer.alloc((await fh.stat()).size);
2299
- await fh.read(buf, 0, buf.length, 0);
2300
- return buf.toString("utf-8");
2298
+ const size = (await fh.stat()).size;
2299
+ const buf = Buffer.alloc(size);
2300
+ let offset = 0;
2301
+ while (offset < size) {
2302
+ const { bytesRead } = await fh.read(buf, offset, size - offset, offset);
2303
+ if (bytesRead === 0) break;
2304
+ offset += bytesRead;
2305
+ }
2306
+ return buf.subarray(0, offset).toString("utf-8");
2301
2307
  } finally {
2302
2308
  await fh.close();
2303
2309
  }
@@ -2324,18 +2330,23 @@ async function parseLogFile(filePath) {
2324
2330
  try {
2325
2331
  const content = await readTextFile(filePath);
2326
2332
  const lines = content.trim().split("\n").filter(Boolean);
2327
- return lines.map((line) => {
2328
- const entry = JSON.parse(line);
2329
- return {
2330
- timestamp: entry.timestamp || (/* @__PURE__ */ new Date()).toISOString(),
2331
- model: entry.model || "unknown",
2332
- tier: entry.tier || "UNKNOWN",
2333
- cost: entry.cost || 0,
2334
- baselineCost: entry.baselineCost || entry.cost || 0,
2335
- savings: entry.savings || 0,
2336
- latencyMs: entry.latencyMs || 0
2337
- };
2338
- });
2333
+ const entries = [];
2334
+ for (const line of lines) {
2335
+ try {
2336
+ const entry = JSON.parse(line);
2337
+ entries.push({
2338
+ timestamp: entry.timestamp || (/* @__PURE__ */ new Date()).toISOString(),
2339
+ model: entry.model || "unknown",
2340
+ tier: entry.tier || "UNKNOWN",
2341
+ cost: entry.cost || 0,
2342
+ baselineCost: entry.baselineCost || entry.cost || 0,
2343
+ savings: entry.savings || 0,
2344
+ latencyMs: entry.latencyMs || 0
2345
+ });
2346
+ } catch {
2347
+ }
2348
+ }
2349
+ return entries;
2339
2350
  } catch {
2340
2351
  return [];
2341
2352
  }