Skip to content

fix(auth): show live subscription plan in whoami - #63

Open
syf2211 wants to merge 2 commits into
KlaatAI:mainfrom
syf2211:fix/whoami-plan-from-usage
Open

fix(auth): show live subscription plan in whoami#63
syf2211 wants to merge 2 commits into
KlaatAI:mainfrom
syf2211:fix/whoami-plan-from-usage

Conversation

@syf2211

@syf2211 syf2211 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Summary

klaatai whoami now resolves the user's subscription plan from the authenticated /v1/me/usage endpoint instead of an unused credentials.json field.

Motivation

Fixes #24Credentials.plan was never written at login and whoami only called /health, so every signed-in user saw plan: null.

Changes

  • getUsageStats() extracts plan from X-KlaatAI-Quota-Plan (or legacy header) and optional JSON plan
  • runWhoami() fetches usage in parallel with the health check and prefers live plan over stored credentials
  • OAuth browser callback captures plan when the web redirect includes it (forward-compatible)

Tests

  • bun run typecheck — pass
  • bun test — 449/449 pass
  • bun run build — pass
  • Added unit tests for usage plan parsing and whoami plan resolution (JSON + text mode)

Notes

  • Requires the backend to expose plan on /v1/me/usage (header or JSON) for users who have not chatted yet; OAuth plan param is an additional path when the web login redirect adds it.
  • REPL /whoami still uses chat quota headers — possible follow-up, out of scope here.

Fixes #24

Fetch plan from authenticated /v1/me/usage (quota headers or JSON body)
instead of relying on an unpopulated credentials field. Also capture plan
from the OAuth callback when the web redirect includes it.

Fixes KlaatAI#24
Extract mergeUsagePlan static helper and unit-test it directly so
login.test.ts module mocks do not break getUsageStats coverage in CI.
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.

whoami always reports plan: null — Credentials.plan is never populated

1 participant