big-spender 0.3.0 → 0.6.0

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.
@@ -1,5 +1,5 @@
1
1
  import { createHash, timingSafeEqual } from 'node:crypto';
2
- import { usageSnapshotSchema } from '../schema.js';
2
+ import { CURSOR_DEVICE_ID, usageSnapshotSchema } from '../schema.js';
3
3
  // Collectors POST one device's full snapshot here (optionally gzip-encoded).
4
4
  const MAX_BODY_BYTES = 2 * 1024 * 1024;
5
5
  const MAX_DECODED_BYTES = 16 * 1024 * 1024;
@@ -80,7 +80,14 @@ export function createIngest({ store, token, onStored }) {
80
80
  .map((i) => `${i.path.join('.') || '(root)'}: ${i.message}`);
81
81
  return Response.json({ error: 'invalid snapshot', issues }, { status: 422 });
82
82
  }
83
- const result = await store.save(parsed.data);
83
+ // Checked here, not in the schema: a stored file from before the reservation must still load.
84
+ const snap = parsed.data;
85
+ if (snap.deviceId === CURSOR_DEVICE_ID &&
86
+ (snap.pricingSource !== 'cursor' || snap.hourly.some((r) => r.provider !== 'cursor'))) {
87
+ const issues = [`deviceId: "${CURSOR_DEVICE_ID}" is reserved for Cursor usage`];
88
+ return Response.json({ error: 'invalid snapshot', issues }, { status: 422 });
89
+ }
90
+ const result = await store.save(snap);
84
91
  if (result === 'stored')
85
92
  onStored();
86
93
  return Response.json({
package/dist/summary.js CHANGED
@@ -119,10 +119,11 @@ function summarizeRange(range, snapshots, now, resolved) {
119
119
  // that has usage inside this window, so an offline device's old sessions drop out.
120
120
  if (counts) {
121
121
  for (const id of active) {
122
- if (!counts[id])
122
+ const n = counts[id];
123
+ if (!n)
123
124
  continue;
124
- sessions += counts[id];
125
- provider(id).sessions += counts[id];
125
+ sessions += n;
126
+ provider(id).sessions += n;
126
127
  }
127
128
  }
128
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "big-spender",
3
- "version": "0.3.0",
3
+ "version": "0.6.0",
4
4
  "description": "Track what your AI coding agents would cost at API prices, across all your machines.",
5
5
  "keywords": [
6
6
  "ai",
@@ -7,3 +7,6 @@ BIG_SPENDER_DEVICE_ID=
7
7
  BIG_SPENDER_INGEST_URL=
8
8
  # Same value as BIG_SPENDER_INGEST_TOKEN on the server.
9
9
  BIG_SPENDER_INGEST_TOKEN=
10
+ # Optional, on one machine only: a Cursor user API key. The collector then reads the account's
11
+ # usage from Cursor's API and sends it as the device "cursor". Set by `big-spender install --cursor`.
12
+ # BIG_SPENDER_CURSOR_API_KEY=