feat(models): show OpenCode Go provider usage quota - #844
Open
TiAmo-chen wants to merge 1 commit into
Open
TiAmo-chen wants to merge 1 commit into
TiAmo-chen wants to merge 1 commit into
Conversation
PROVIDER_USAGE_IDS gains opencode-go with an adapter for GET https://opencode.ai/zen/go/v1/usage (rolling/weekly/monthly used percent plus reset time). The provider's base URL lives on its models, not on the provider, so queryProviderUsage() falls back to the first model's baseUrl before the official-origin check. Custom origins stay rejected.
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.
Summary
Adds an OpenCode Go usage adapter so the provider usage card works for
opencode-go(the provider added by the pi model catalog; it is already listed in the app, with icon, and authenticated throughauth.json).Today the request is rejected before any network call:
With this change the card shows the plan's rolling / weekly / monthly usage with their reset times.
Changes
lib/provider-usage-ids.ts— addopencode-gotoPROVIDER_USAGE_IDS.ProviderUsageSummarygates rendering on this list, so no UI change is needed.lib/provider-usage.tshttps://opencode.ai/zen/go/v1/usageand display nameOpenCode Go;normalizeOpenCodeGo()mapsusage.{rolling,weekly,monthly}.percent→remainingand the ISOresetsAt→ epoch seconds (the client rendersnew Date(1000 * resetsAt));queryProviderUsage()falls back to the first model'sbaseUrlwhen the provider itself has none (see below).lib/provider-usage.test.mjs— coverage for the new adapter, the id predicate and the origin guard.Why the
baseUrlfallback is requiredopencode-gois a catalog provider whose base URL is defined per model, soprovider.baseUrlisundefinedand the existing guard fails even after whitelisting:The
auth.baseUrlcheck insidefetchJson()is untouched, so pointing the provider at a custom origin is still rejected for official queries.Response shape
Only the used percentage and a reset timestamp are reported (no dollar amounts), so this produces three
unit: "percent"buckets and no metrics.Verification
node --experimental-strip-types --test lib/provider-usage.test.mjs→ 5/5 pass, including the newnormalizes OpenCode Go windows into remaining percentages and reset times.queryProviderUsage("opencode-go")on this branch:status: "ready"withRolling 95% / Weekly 98% / Monthly 2%remaining and reset timestamps.round-trip of
/api/provider-usage/query, plus regression checks thatdeepseekstill returns itsbalances and that unsupported ids still answer
400 Unsupported provider.Notes
auth.json. Setups that rotate a key pool will only see thatsingle key; per-key rows could be a follow-up if wanted.
resetsAt, so the buckets carry nowindowMinutes.status(ok/ rate-limited) is currently unused; it could later map onto theexisting
period: "Unlimited"/ rate-limit affordances.