Skip to content

feat(tui): show Console balance and spend in /status - #254

Merged
its-janghoon merged 1 commit into
developfrom
feat/statusbalance
Nov 13, 2026
Merged

its-janghoon merged 1 commit into
developfrom
feat/statusbalance

Conversation

@its-janghoon

Copy link
Copy Markdown
Member

What's done

  • /status replaces the plain billing link with a Console block (English and Korean): workspace balance, today's spend and this month's spend across every device, with request counts, then the billing link.
    • A complimentary workspace shows "Complimentary, nothing is charged" instead of a balance.
    • A balance under $1 is shown in the warning colour with "running low, top up below".
  • New engine route GET /experimental/console/usage?tz=<IANA> (experimental.console.usage) returns the Console's /usage/summary reply or null.
    • It sends the same key and base URL the Redrob provider sends inference with: options.apiKey, else the merged credential (REDROB_API_KEY, auth.json, launcher). The base URL is options.baseURL, else CONSOLE_URL, so REDROB_CONSOLE_URL still selects dev. The keyless "public" placeholder is treated as no key.
    • The key stays in the engine. The TUI only sees the figures. Nothing logs.
  • packages/core/src/balance.ts: the fetch and parse, 5 second timeout. Any failure (no key, 401, 400, 429, 404, timeout, unreachable, bad or partial body) returns undefined and the TUI keeps the old link.
  • The TUI fetches once when /status opens and only when the Redrob provider is present. There is no timer, because Console rate-limits the route to 60/min per workspace.
  • SDK regenerated: only the new method and its types.

Pane text, TUI run from source against prod Console (the route is already live there and matches curl with the same key):

Console
Balance    $10.54
Today      $0.10 · 3 requests
This month $181.90 · 18,158 requests
Workspace totals across every device.
Billing: https://console.redrob.ai/billing
콘솔
잔액    $10.54
오늘    $0.10 · 요청 3건
이번 달 $181.90 · 요청 18,158건
모든 기기를 합친 워크스페이스 기준이에요.
결제: https://console.redrob.ai/billing

Fallback, with REDROB_CONSOLE_URL pointing at a base where the route answers 404:

Console balance: https://console.redrob.ai/billing

What's not done

  • Not run against the dev Console: console-dev.redrob.ai is behind Vercel SSO and answers 302 to vercel.com/sso-api without a protection-bypass token. Prod already serves the route, so the live check ran there.

What to review

  • handlers/experimental.ts consoleUsage: key resolution mirrors Provider line ~1953 (options.apiKey ?? provider.key).
  • core/src/balance.ts: Effect.catchCause swallows everything on purpose, so /status can never fail because of Console.

Intentions

  • Show the workspace's real balance and spend in /status, with the local session totals kept beside it, without making /status depend on Console being reachable.

Tests

  • bun typecheck: 21/21.
  • packages/core/test/balance.test.ts (new, 6): request shape (path, tz, bearer), trailing slash, 401/429/404, unparsable and partial body, unreachable host, timeout.
  • packages/tui/test/util/usage.test.ts: 3 new tests for formatting, low balance vs complimentary, and an unknown currency code. The full TUI suite has the same 12 i18n failures as clean origin/develop.
  • packages/core full suite: the same 17 failures as clean origin/develop (ModelsDev, RedrobPlugin, privacy mask).
  • packages/redrob test/server: 345 tests, 0 fail. httpapi coverage: the new route passes, 240 pass. The 17 missing scenarios are the same as on develop.
  • Checked that the key does not appear in the engine logs or the pane captures.

/status gets a Console block: the workspace balance, today's spend and this
month's spend across every device, with request counts and the billing
link. A complimentary workspace says so instead of showing a balance, and
a balance under $1 is shown as a warning.

The engine reads it through a new GET /experimental/console/usage?tz=
route. It calls the Console's GET /usage/summary with the key and base URL
the Redrob provider already uses for inference (options.apiKey, else the
merged credential; options.baseURL, else CONSOLE_URL, so
REDROB_CONSOLE_URL still selects dev). The key never reaches the TUI and
is never logged.

The TUI fetches once when /status opens, not on a timer. The engine waits
at most 5 seconds. No key, 401, 400, 429, 404 (a Console without the
route), a timeout or a body that does not parse all return null, and the
dialog shows the plain billing link as before.
@its-janghoon

Copy link
Copy Markdown
Member Author

Self-review. The key never crosses into the TUI: the engine resolves it the same way the provider hands it to the SDK (options.apiKey, else the merged credential), skips the 'public' placeholder, and only the parsed figures go back over the local API. Balance.summary swallows every failure and caps the wait at 5 s, so /status degrades to the old billing link instead of erroring. I checked that 404 (REDROB_CONSOLE_URL pointed at a base without the route) falls back, and that live prod figures match curl with the same key. The dialog fetches once per open and only when the Redrob provider exists, which keeps it well under the Console's 60/min limit. Open points: the billing link is still the prod CONSOLE_HOME_URL even when REDROB_CONSOLE_URL points at dev, which is the existing behaviour. The $1 low-balance threshold is a constant I picked. The dev Console sits behind Vercel SSO, so the live check ran against prod.

@its-janghoon
its-janghoon merged commit 5392104 into develop Nov 13, 2026
12 checks passed
@its-janghoon
its-janghoon deleted the feat/statusbalance branch November 13, 2026 06:58
@its-janghoon its-janghoon mentioned this pull request Nov 13, 2026
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