github vava-nessa/free-coding-models v0.5.59

latest releases: v0.5.99, v0.5.98, v0.5.97...
3 months ago

Added

  • ๐Ÿ“Š Live quota from response headers (t2) โ€” every chat-completion response already carries x-ratelimit-* headers. The daemon parses them passively on every routed request (and even on health-check pings), exposing live per-provider quota on the TUI footer and Web Dashboard. Zero extra network requests, zero quota waste.

    • 8 header variants supported in priority order:
      • x-ratelimit-remaining-requests / -limit-requests (SambaNova-style)
      • x-ratelimit-remaining / -limit (Mistral / generic)
      • ratelimit-remaining-requests / ratelimit-limit-requests (proxy-stripped)
      • ratelimit-remaining / ratelimit-limit (proxy-stripped generic)
      • x-ratelimit-remaining-requests-day / -limit-requests-day (SambaNova daily)
      • x-ratelimit-remaining-day / -limit-day (generic daily)
      • x-ratelimit-remaining-tokens / -limit-tokens (Cerebras tokens)
      • x-ratelimit-remaining-tokens-minute / -limit-tokens-minute (Cerebras token-minute)
    • First-match-wins priority โ€” when multiple pairs are present, the most-specific wins (e.g. daily variant beats generic).
    • Case-insensitive โ€” some proxies vary casing; we handle X-RateLimit-Remaining and x-ratelimit-remaining identically.
    • Garbage-safe โ€” limit: 0, non-numeric values, or missing pairs return null (no crash, no div-by-zero).
    • Staleness 5 min โ€” snapshots older than STALENESS_MS are excluded from getAllQuotas() so the consumer only sees fresh data. The existing active /api/v1/key fetcher stays as the fallback for idle providers.
    • Merge with active fetcher โ€” getQuota(providerKey) returns whichever is freshest, so quota is always live when traffic flows.
  • ๐Ÿ›ฐ๏ธ TUI footer chip โ€” ๐Ÿ“Š groq 78% ยท sambanova 41% (top 5 most-depleted first; icon escalation ๐Ÿ“Š healthy โ†’ โš ๏ธ โ‰ค 25% โ†’ ๐Ÿšจ โ‰ค 10%). Renders on the same footer line as the existing probe-cache chip.

  • ๐ŸŒ Web Dashboard Provider Quota section โ€” per-provider card with source icon (๐Ÿ›ฐ๏ธ passive header vs ๐Ÿ”Œ active fetcher fallback), provider key, animated progress bar (green โ‰ฅ 25% / amber 10โ€“25% / red โ‰ค 10%), and percent label. Auto-sorted most-depleted first. Updated every /api/router/stats poll (5 s).

  • ๐Ÿ“‹ Daemon /api/router/stats exposes quota โ€” { providerKey: { remaining, limit, percent, windowType, source, lastUpdated } }. The source field tells you whether the value came from a passive header ('header') or the active fetcher ('endpoint') โ€” useful for debugging why a provider shows the number it does.

  • ๐Ÿงช processResponseHeaders(providerKey, headers) โ€” drop-in hook for any future surface (Tauri Desktop, scripts, IDE plugins) that wants to feed the passive map.

Changed

  • ๐Ÿฉบ Daemon reverse proxy (buildUpstreamMeta in src/core/router-daemon.js) now calls processResponseHeaders(providerKey, response.headers) for every routed upstream response, both streaming and non-streaming. Zero new code paths, zero new dependencies.

  • ๐Ÿ“ก Health-check pings (src/core/ping.js) also call processResponseHeaders(providerKey, resp.headers), so even the CLI-only flow (no daemon) shows live quota after the first ping cycle.

  • ๐Ÿ”ง Internal refactor โ€” the existing extractQuotaPercent in src/core/ping.js now uses the shared extractQuota() from provider-quota-fetchers.js. Same 8-variant parser, single source of truth, no behaviour change for existing callers.

Maintenance

  • ๐Ÿงช +37 unit tests (test/passive-quota.test.js, new file): HEADER_PAIRS structure, STALENESS_MS, all 8 header pairs parse correctly, robustness (missing fields, NaN, limit=0, negative limit, empty object, null/undefined headers), first-pair-wins priority, case-insensitivity, Fetch Headers object support, processResponseHeaders writes/overwrites/ignores bad providerKey, getQuota passive fresh/stale/custom maxAgeMs, getAllQuotas unions both stores / excludes stale, formatQuotaStatus healthy/low/critical + day window + stale/missing.
  • ๐Ÿงช 632 โ†’ 671 tests passing (pnpm test), 118 โ†’ 125 suites.
  • ๐Ÿงน vite build succeeds.
  • ๐Ÿ“– README updated with a new ๐Ÿ“Š Live quota from response headers section (8 variants table, where it shows up, /stats.quota JSON shape).

Inspiration

This implementation is informed by apmantza/pi-free's lib/quota-monitor.ts (which itself credits us: "Inspired by free-coding-models' extractQuotaPercent"). The inspiration flows both ways โ€” we extend their 6-pair design to 8 variants (adding the Cerebras tokens / token-minute pairs we already supported) and ship a Web Dashboard renderer that surfaces them as live progress bars instead of just CLI text.

Files

  • Modified: src/core/provider-quota-fetchers.js (+228 lines: new pure-logic section), src/core/ping.js (call processResponseHeaders on every ping), src/core/router-daemon.js (call on every routed response + expose quota in /stats), src/tui/render-table.js (new footer chip), src/tui/app.js (thread quota through), web/src/components/router/RouterView.jsx (new Provider Quota section), web/src/components/router/RouterView.module.css (7 new classes), README.md, tasks/t2.md, package.json (test script).
  • New: test/passive-quota.test.js (340 lines, 37 tests), changelog/v0.5.59.md.

Don't miss a new free-coding-models release

NewReleases is sending notifications on new releases.