@hyperfixation/core 0.1.7 → 0.1.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/status.d.ts CHANGED
@@ -12,6 +12,7 @@ export interface QueueStatus {
12
12
  export interface PeriodStatus {
13
13
  period: string;
14
14
  budgetUsd: string;
15
+ /** The period counter, printed at the ledger's scale — six decimals, like the two below. */
15
16
  spentUsd: string;
16
17
  /** `SUM(cost_usd)` of the period's `ok` rows, for the drift below. */
17
18
  ledgerUsd: string;
package/dist/status.js CHANGED
@@ -27,11 +27,18 @@ const QUEUES_STATEMENT = "SELECT q.name, COALESCE(q.concurrency, -1)::int AS glo
27
27
  * Per-period spend against budget, with the exact drift `reconcile()` reports and never
28
28
  * corrects: a call is billed to the period stamped on its own row, so this comparison is not
29
29
  * an estimate.
30
+ *
31
+ * The subtraction happens in Postgres at the scale both sides are stored in, so the drift of a
32
+ * period whose counter agrees with its ledger is exactly `0.000000` — no float, no tolerance.
30
33
  */
31
- const BUDGET_STATEMENT = "SELECT b.period, b.budget_usd::text AS budget_usd, b.spent_usd::text AS spent_usd, " +
32
- "COALESCE((SELECT SUM(l.cost_usd) FROM hf_llm_call l " +
33
- "WHERE l.period = b.period AND l.status = 'ok'), 0)::text AS ledger_usd " +
34
- "FROM hf_budget_period b WHERE b.period = ANY($1::text[])";
34
+ const BUDGET_STATEMENT = "SELECT b.period, b.budget_usd::text AS budget_usd, " +
35
+ "b.spent_usd::numeric(12,6)::text AS spent_usd, " +
36
+ "l.ledger::numeric(12,6)::text AS ledger_usd, " +
37
+ "(b.spent_usd - l.ledger)::numeric(12,6)::text AS drift_usd " +
38
+ "FROM hf_budget_period b CROSS JOIN LATERAL (" +
39
+ "SELECT COALESCE(SUM(c.cost_usd), 0) AS ledger FROM hf_llm_call c " +
40
+ "WHERE c.period = b.period AND c.status = 'ok') l " +
41
+ "WHERE b.period = ANY($1::text[])";
35
42
  /**
36
43
  * `reconcile()`'s step (1) invariant violation, counted live rather than accumulated: a
37
44
  * `running` run with no `dbos.workflow_status` row at all cannot happen, because every path
@@ -65,7 +72,7 @@ export async function appStatus(pool, options) {
65
72
  budgetUsd: row.budget_usd,
66
73
  spentUsd: row.spent_usd,
67
74
  ledgerUsd: row.ledger_usd,
68
- driftUsd: (Number(row.spent_usd) - Number(row.ledger_usd)).toFixed(6),
75
+ driftUsd: row.drift_usd,
69
76
  };
70
77
  };
71
78
  const budgetStatus = { current: periodStatus(current), previous: periodStatus(previous) };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperfixation/core",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "license": "MIT",
5
5
  "description": "defineApp, registries, resolution, records, activity, tasks, labels, outcomes, and the status endpoint",
6
6
  "repository": {
@@ -29,13 +29,13 @@
29
29
  ],
30
30
  "dependencies": {
31
31
  "@dbos-inc/dbos-sdk": "4.27.6",
32
- "@hyperfixation/db": "0.1.7",
33
- "@hyperfixation/workflows": "0.1.7",
32
+ "@hyperfixation/db": "0.1.8",
33
+ "@hyperfixation/workflows": "0.1.8",
34
34
  "pg": "^8.23.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@hyperfixation/eslint-config": "0.1.7",
38
- "@hyperfixation/testing": "0.1.7",
37
+ "@hyperfixation/eslint-config": "0.1.8",
38
+ "@hyperfixation/testing": "0.1.8",
39
39
  "@microsoft/api-extractor": "^7.59.1",
40
40
  "@types/pg": "^8.23.1",
41
41
  "eslint": "^10.10.0",