@blockrun/clawrouter 0.12.283 → 0.12.284

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 (3) hide show
  1. package/README.md +3 -2
  2. package/dist/cli.js +42 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -697,8 +697,9 @@ table has drifted from the gateway's. **Charged but not in this machine's
697
697
  journal** is the one to look at hardest: money left the account for a call this
698
698
  machine did not make — expected if the same key is used on another machine or by
699
699
  another BlockRun product, and worth investigating if not. Exit code `2` in that
700
- case, so a scheduled check can alert on it. Rows still **pending pricing** are
701
- excluded from the totals rather than counted as $0.
700
+ case, so a scheduled check can alert on it, and `1` when the ledger could not be
701
+ read in full, since the unread pages could hold exactly those charges. Rows still
702
+ **pending pricing** are excluded from the totals rather than counted as $0.
702
703
 
703
704
  Your per-call sum will always be less than your card statement by exactly the
704
705
  top-up fees, which are charged at purchase and never appear as ledger rows. That
package/dist/cli.js CHANGED
@@ -101852,7 +101852,8 @@ __export(reconcile_exports, {
101852
101852
  joinRows: () => joinRows,
101853
101853
  loadGatewayRows: () => loadGatewayRows,
101854
101854
  loadLocalRows: () => loadLocalRows,
101855
- reconcile: () => reconcile
101855
+ reconcile: () => reconcile,
101856
+ reconcileExitCode: () => reconcileExitCode
101856
101857
  });
101857
101858
  import { readFile as readFile3, readdir as readdir3 } from "fs/promises";
101858
101859
  import { join as join13 } from "path";
@@ -101899,16 +101900,36 @@ async function loadLocalRows(since) {
101899
101900
  async function loadGatewayRows(apiKey, from15, maxPages = 40) {
101900
101901
  const rows = [];
101901
101902
  const unavailableDays = /* @__PURE__ */ new Set();
101903
+ const requested = /* @__PURE__ */ new Set();
101902
101904
  let cursor;
101903
101905
  for (let page = 0; page < maxPages; page++) {
101904
101906
  const result = await fetchUsagePage(apiKey, { from: from15, limit: 500, cursor });
101905
- if (!result) return page === 0 ? void 0 : { rows, unavailableDays: [...unavailableDays] };
101907
+ if (!result) {
101908
+ if (page === 0) return void 0;
101909
+ return {
101910
+ rows,
101911
+ unavailableDays: [...unavailableDays],
101912
+ incomplete: `page ${page + 1} of the ledger could not be read`
101913
+ };
101914
+ }
101906
101915
  rows.push(...result.rows);
101907
101916
  result.unavailableDays.forEach((d) => unavailableDays.add(d));
101908
- if (!result.nextCursor) break;
101917
+ if (!result.nextCursor) return { rows, unavailableDays: [...unavailableDays] };
101918
+ if (requested.has(result.nextCursor)) {
101919
+ return {
101920
+ rows,
101921
+ unavailableDays: [...unavailableDays],
101922
+ incomplete: `the ledger's page cursor stopped advancing after page ${page + 1}`
101923
+ };
101924
+ }
101909
101925
  cursor = result.nextCursor;
101926
+ requested.add(cursor);
101910
101927
  }
101911
- return { rows, unavailableDays: [...unavailableDays] };
101928
+ return {
101929
+ rows,
101930
+ unavailableDays: [...unavailableDays],
101931
+ incomplete: `the ledger has more than ${maxPages} pages for this window; try fewer --days`
101932
+ };
101912
101933
  }
101913
101934
  function joinRows(localRows, gatewayRows, unkeyed = 0, unavailableDays = []) {
101914
101935
  const localById = new Map(localRows.map((r2) => [r2.requestId, r2]));
@@ -101951,7 +101972,14 @@ async function reconcile(apiKey, days) {
101951
101972
  loadGatewayRows(apiKey, since.toISOString())
101952
101973
  ]);
101953
101974
  if (!gateway) throw new Error("Could not read the BlockRun usage ledger (GET /v1/usage).");
101954
- return joinRows(localRows, gateway.rows, unkeyed, gateway.unavailableDays);
101975
+ const result = joinRows(localRows, gateway.rows, unkeyed, gateway.unavailableDays);
101976
+ if (gateway.incomplete) result.ledgerIncomplete = gateway.incomplete;
101977
+ return result;
101978
+ }
101979
+ function reconcileExitCode(r2) {
101980
+ if (r2.chargedNotRecorded.length > 0) return 2;
101981
+ if (r2.ledgerIncomplete) return 1;
101982
+ return 0;
101955
101983
  }
101956
101984
  function formatReconcile(r2, days) {
101957
101985
  const out = [];
@@ -101959,6 +101987,13 @@ function formatReconcile(r2, days) {
101959
101987
  out.push(`
101960
101988
  BlockRun reconciliation \u2014 last ${days} day${days === 1 ? "" : "s"}
101961
101989
  `);
101990
+ if (r2.ledgerIncomplete) {
101991
+ out.push(` \u26A0 Partial ledger: ${r2.ledgerIncomplete}.`);
101992
+ out.push(` Only the ledger pages that were read are compared: the gateway total is`);
101993
+ out.push(` short, charges on the unread pages are not checked, and calls billed on`);
101994
+ out.push(` those pages show up as recorded locally with no settled ledger row.
101995
+ `);
101996
+ }
101962
101997
  out.push(
101963
101998
  ` Gateway charged: ${usd(r2.gatewayTotalUsd)} (${r2.matched.length + r2.chargedNotRecorded.length} settled calls)`
101964
101999
  );
@@ -236125,10 +236160,10 @@ async function cmdReconcile(days) {
236125
236160
  process.exit(1);
236126
236161
  }
236127
236162
  try {
236128
- const { reconcile: reconcile2, formatReconcile: formatReconcile2 } = await Promise.resolve().then(() => (init_reconcile(), reconcile_exports));
236163
+ const { reconcile: reconcile2, formatReconcile: formatReconcile2, reconcileExitCode: reconcileExitCode2 } = await Promise.resolve().then(() => (init_reconcile(), reconcile_exports));
236129
236164
  const result = await reconcile2(resolved.key, days);
236130
236165
  console.log(formatReconcile2(result, days));
236131
- process.exitCode = result.chargedNotRecorded.length > 0 ? 2 : 0;
236166
+ process.exitCode = reconcileExitCode2(result);
236132
236167
  } catch (error) {
236133
236168
  console.error(`\u2717 ${error instanceof Error ? error.message : String(error)}`);
236134
236169
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/clawrouter",
3
- "version": "0.12.283",
3
+ "version": "0.12.284",
4
4
  "description": "Smart LLM router — save 84% on inference costs. 88 models (7 free). Pay by credit card (API key) or USDC (x402 wallet).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",