chore(api): promote test → main — credit-spend digest cron (#634)

Merged
SW
4mo ago
+445-0

Promotes #634 (credit-spend visibility digest cron) from test to main. Net delta vs main is only #634's files.

Verified end-to-end on preview (auth gate, rpc with data + empty no-op, Telegram send) — see #634. DB function get_credit_spend_digest already live in prod (recoupable/database#28). Ensure CRON_SECRET has a real value in Production before the first cron run. Implements the digest item from recoupable/chat#1767.


Summary by cubic

Promotes the credit-spend digest cron to production. Adds a cron-triggered internal API that summarizes the last 10 minutes of credit spend and posts a top-spenders digest to Telegram.

  • New Features

    • Vercel Cron runs every 10m via vercel.json → GET /api/internal/credit-spend-digest.
    • Gated by CRON_SECRET bearer; unauthorized calls return 401.
    • Aggregates via Postgres get_credit_spend_digest and sends a Telegram digest.
    • Digest shows total spend, turns, tokens (cached noted), tool calls, main vs. subagent split, and per-model spend.
    • Top 10 accounts; empty windows are a no-op.
  • Migration

    • Set a real CRON_SECRET in Production before the first run.
    • The DB function get_credit_spend_digest is already live; no schema changes needed.

Summary by CodeRabbit

  • New Features
    • Added credit spend digest API endpoint with request validation
    • Added formatting utilities for currency amounts and token counts
    • Added credit spend aggregation and reporting functionality