Repository navigation
feat(usage): track the DeepInfra credit balance in the status bar - #270
Merged
Merged
Conversation
DeepInfra publishes no percentage quota, so the status bar gains a money readout for it, alongside DeepSeek and Fireworks.ai: - Settings -> AI Provider Accounts gains a DeepInfra row: an API key in the existing encrypted credential store (never GlobalSettings), with the usage switch, console link and Forget-key control every fork provider has. - The readout is the remaining balance in USD: the account credit minus the usage incurred since the last invoice, which is the figure DeepInfra's own dashboard shows. That unbilled usage is broken out beneath it, and an exhausted or suspended account stays visible (available: false) so it can be topped up instead of vanishing. The balance comes from GET /payment/checklist, the billing route the dashboard itself reads; it is not under /v1. Route, bearer auth and field names were confirmed against DeepInfra's public OpenAPI spec and a live response. Adds 'deepinfra' to the provider union, RateLimitState (slot plus deepinfraApiKeyConfigured), the status-bar item set and its one-shot default-on migration, and a single-key host-settings replication port. The service lane mirrors DeepSeek's: generation stamping so a pasted key cannot be overwritten by an in-flight result, stale policy so a transient failure keeps the last balance on screen, and disabled-provider gating. Adds an 'unbilled' credits item key for the usage-since-invoice breakdown, and folds the four fork API-key config resolvers onto one helper, which is what keeps service-fetch-targets.ts under its line cap.
…lling_type
Review findings on the DeepInfra provider (R1):
- getState() reads the DeepInfra key store, so every rate-limit service suite
now reached the user's real credential file (a chmod, and the adoption marker)
unless it mocked that store. Adds the store to the harness's unmocked-module
guard and the mock to the fourteen suites, matching what DeepSeek already had.
- `available` now depends on `billing_type`: only a prepaid ('balance') account
stops working at zero credit, so an invoice-billed account running at about
zero no longer gets a "cannot fund further calls" warning. `suspended` still
wins in both cases.
- Money is summed in integer nanos and rounded once at display time, so the
readout cannot sit a cent away from the dashboard's own figure (rounding
-20.004 and 0.005 to cents separately answered $19.99 for $20.00).
- A payload carrying neither amount is now a parse error rather than a confident
$0.00: this API answers plain JSON, which writes a zero as 0 rather than
omitting it, so neither field means the shape changed.
- Coverage: the 'unbilled' label, an `ok` DeepInfra snapshot reaching the bar,
an invoice-billed account at about zero, and the sub-unit negative branch.
- Drops the Accounts-description rekey, which had orphaned its ten existing
translations and left an empty object in the catalog.
… in the pane blurb Round-2 delta re-check MINORs: - `isPrepaid` now means what its comment says: only an explicit `'balance'` billing type is prepaid, so an unrecognized type claims nothing about exhaustion instead of guessing in either direction. Test covers it. - The Accounts-pane description names DeepInfra again, but through the existing `b1c2f8b0ac` key rather than a new one, so the ten locale files that tombstone that key keep working and nothing is orphaned. - An unbilled amount under half a cent no longer renders as a "Unbilled usage $0.00" line.
…iles The fork-comment ratchet refuses new comment lines above upstream's code, and this branch had added eleven: the rationale for the shared API-key config resolver, the DeepInfra credential type, the prepaid rule, and the new provider flags. The rationale belongs in this commit and the PR body, not in a file upstream edits, so it is removed and the ratchet reads 6051/6051 again. No behaviour change.
Upstream's c827ed5 ("run full native mobile typechecks without compiler caches") turned on the strict mobile typecheck, which rejects indexing Record<TuiAgent, …> with the `string` that Object.entries widens to. The fork's own override table relied on noImplicitAny being off there, so `Mobile verify` has been red on nplez1/main since that landed. Merges through a string-keyed working copy instead: a string index signature is assignable back to the narrow record, so no type assertion is needed and the repo's consistent-type-assertions rule stays satisfied. Verified: mobile/tsconfig.json typecheck clean (3,510 files), mobile tests typecheck ratchet OK, pnpm tc:node clean, changed-code-quality pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Adds DeepInfra as a first-class usage provider in the fork, matching the shape DeepSeek and Fireworks.ai already have: a row in Settings → AI Provider Accounts (API key in the encrypted credential store, usage switch, console link, Forget-key) and a status-bar meter showing dollars remaining.
The readout is the remaining balance in USD — the account credit minus the usage incurred since the last invoice, which is the figure DeepInfra's own dashboard shows. Unbilled usage is broken out beneath it, and an exhausted or suspended account stays visible (
available: false) so it can be topped up rather than vanishing from the bar.Balance source:
GET https://api.deepinfra.com/payment/checklistwith the API key as a bearer token — the billing route the dashboard itself reads, and notably not under/v1. Route, auth and field names were confirmed against DeepInfra's public OpenAPI spec and a live response; the remaining figure mirrors the dashboard's own-(stripe_balance + recent).Reviewed by Opus 5.5, high: R1 (2 SHOULD-FIX fixed, no blocking), delta re-check clean on R2
R3 and R4 (
3feda4a,a53487b) apply the delta round's two one-hunk MINORs and move the rationale out of upstream-owned files so the fork-comment ratchet reads its baseline again. The reviewer's verdict on the delta was that neither needed a further round. The branch was then rebased ontonplez1/main(bc4afd9), andnplez1/mainwas merged in again at2c6b888— both clean, andgit show --remerge-diffon the merge shows no resolver-chosen hunks, so the reviewed content is byte-identical to what is pushed.Verification
Run in this worktree on the pushed head
eb9ddbe:Unit gate @eb9ddbeb0f (clean): PASS — 142468 passed; 0 failed (0 allowlisted, 0 unexpected); 0 flaky re-run passed; 0 unhandled error headline(s); 588 s.Mobile verify,Mobile native fingerprint,changes,fork-pr-gates: changed lines,fork-pr-gates: typecheck,persistenceon ubuntu-22.04 / windows-2022 / windows-11-arm).pnpm tc— clean (node, cli, web).pnpm run check:code-quality:changed— 0 new findings.deepinfra-fetcher.test.ts(16),service-deepinfra-usage.test.ts(7),provider-credits-format.test.ts(14),status-bar-provider-visibility.test.ts(43),status-bar-usage-projection.test.ts(2),provider-accounts-sections.test.ts(5),register-fork-handlers.test.ts(3), the harness's unmocked-module guard (1),ui-hydration-workspace-preferences.test.ts(53), plus the fourteen rate-limit service suites,AccountsPane*,AppearancePane,UsageRosterPanel,tooltip,usage-error-copy,provider-segment-balance,host-settings-api-key-port/replication-*,wsl-move-renderer-store-keys,web-preload-api-*andfork-catalog-overlay.verify:localization-catalogandverify:localization-coverage— pass./payment/checklistpayload parsed toUSD 19.18 availablewithUSD 0.82 unbilled, matching the dashboard.One foreign red fixed on the way
Mobile verifywas red before this branch's first push, and red onnplez1/mainitself: upstream'sc827ed5324eturned on the strict mobile typecheck, which rejects indexingRecord<TuiAgent, …>with thestringthatObject.entrieswidens to — and the fork's ownsrc/shared/tui-agent-config-np.tshad relied onnoImplicitAnybeing off there.eb9ddbemerges through a string-keyed working copy, which needs no type assertion, soMobile verifyand the mobile tests typecheck ratchet are green. Reproduced and verified locally againstmobile/tsconfig.json(3,510 files) at bothorigin/nplez1/mainand this head.Lint gate: 42/44 green, 2 foreign reds still on main
orca-queue node local/gate-lint.mjsreports 42 green, 2 failing, and neither is in this diff:check-upstream-file-comments— 6180 vs baseline 6051, every file undersrc/renderer/src/components/right-sidebar/**.check:focus-read-ratchet— three files undersrc/renderer/src/components/right-sidebar/**.Both reproduce at
bc4afd97030and at2c6b8882eefwith none of this work present, and came in with #267. This branch touches noright-sidebarfile, and I did not raise the baselines or add lint-known-red entries: raising a comment baseline would permanently accept 129 foreign comment lines, which is that feature's debt to pay.Review findings not fixed, listed per the gate
describeCreditscopy as "-$1.25 available". That wording is pre-existing and shared with DeepSeek/Fireworks, so changing it here would change three providers' copy.deepinfra-api-key-store.test.tsordeepinfra-credentials.test.ts. DeepSeek has neither, so this is parity rather than a gap this branch introduces; the fetcher, the service lane and the IPC shape are covered.mobile/src/components/accounts-snapshot.tsgains'deepinfra'in its provider enum; the mobile lanes that cover it now pass in CI.Assumption
"AI Provider (in the settings list)" is read as the AI Provider Accounts section plus the status-bar meter — the surface DeepSeek and Fireworks occupy — rather than DeepInfra as a model backend for agents.