Skip to content

feat(usage): record events + daily aggregates (Task #6)#22

Open
lubobill1990 wants to merge 1 commit into
feat/05-usage-normalizerfrom
feat/06-usage-recorder
Open

feat(usage): record events + daily aggregates (Task #6)#22
lubobill1990 wants to merge 1 commit into
feat/05-usage-normalizerfrom
feat/06-usage-recorder

Conversation

@lubobill1990
Copy link
Copy Markdown
Collaborator

Summary

  • recordUsage(input) inserts a usage_events row and atomically upserts usage_daily in one transaction
  • pricing snapshot copied from model_pricing at write time; missing rows leave snapshots NULL
  • recorder errors are swallowed; response path never breaks
  • isInternal: true short-circuits to support x-internal-pricing-sync

Test plan

  • 5 new tests; 76 total pass

Refs #6

🤖 Generated with Claude Code

- src/lib/usage-recorder.ts: recordUsage(input) inserts one usage_events row and atomically upserts the matching usage_daily row using SQLite's date(?/1000,'unixepoch','localtime') for the day boundary. Pricing snapshots are pulled from model_pricing at write time; missing rows leave snapshots NULL. premium_request_count = premium_multiplier (or 0). Errors are caught and logged so the response path is never broken. isInternal=true short-circuits the write entirely (for x-internal-pricing-sync calls).

Tests: single insert, increment, missing pricing, isInternal, swallowed errors.

Refs #6

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant