Repository navigation
feat(tui): show Console balance and spend in /status - #254
Conversation
/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.
|
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. |
What's done
/statusreplaces 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.GET /experimental/console/usage?tz=<IANA>(experimental.console.usage) returns the Console's/usage/summaryreply ornull.options.apiKey, else the merged credential (REDROB_API_KEY,auth.json, launcher). The base URL isoptions.baseURL, elseCONSOLE_URL, soREDROB_CONSOLE_URLstill selects dev. The keyless"public"placeholder is treated as no key.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) returnsundefinedand the TUI keeps the old link./statusopens and only when the Redrob provider is present. There is no timer, because Console rate-limits the route to 60/min per workspace.Pane text, TUI run from source against prod Console (the route is already live there and matches
curlwith the same key):Fallback, with
REDROB_CONSOLE_URLpointing at a base where the route answers 404:What's not done
console-dev.redrob.aiis behind Vercel SSO and answers 302 tovercel.com/sso-apiwithout a protection-bypass token. Prod already serves the route, so the live check ran there.What to review
handlers/experimental.tsconsoleUsage: key resolution mirrorsProviderline ~1953 (options.apiKey ?? provider.key).core/src/balance.ts:Effect.catchCauseswallows everything on purpose, so/statuscan never fail because of Console.Intentions
/status, with the local session totals kept beside it, without making/statusdepend 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 cleanorigin/develop.packages/corefull suite: the same 17 failures as cleanorigin/develop(ModelsDev, RedrobPlugin, privacy mask).packages/redrobtest/server: 345 tests, 0 fail. httpapi coverage: the new route passes, 240 pass. The 17 missing scenarios are the same as on develop.