Skip to content

feat: add OpenCode Go usage support - #3

Open
JairajSustained wants to merge 1 commit into
iefnaf:masterfrom
JairajSustained:feat/opencode-go-usage
Open

JairajSustained wants to merge 1 commit into
iefnaf:masterfrom
JairajSustained:feat/opencode-go-usage

Conversation

@JairajSustained

Copy link
Copy Markdown

Adds OpenCode Go to /usage.

  • New provider key opencode-go (detects model.provider opencode-go/opencode)
  • fetchOpencodeGoUsage() via GET https://opencode.ai/zen/go/v1/usage with Bearer API key (no OAuth refresh, no cookie scraping)
  • Maps rolling (5h) -> session, weekly -> weekly, monthly -> monthly (new optional UsageData fields + Monthly bar in panel)
  • Shows Rolling/Weekly/Monthly with resets in panel; Daily/Weekly unchanged for other providers
  • Auth check via hasAuth(opencode-go); verified live (5%/27%/13%)
  • Tests for detect + fetch + HTTP error; README updated

@iefnaf iefnaf left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR — nice work overall! I verified the core implementation and it holds up well:

  • opencode-go is a real provider in pi-ai (id: "opencode-go", name "OpenCode Go", API-key auth), so the auth lookup id is correct — pi stores API-key providers in auth.json under their provider id.
  • ✅ The endpoint is real (I confirmed https://opencode.ai/zen/go/v1/usage returns HTTP 401 without auth).
  • ✅ All 6 tests pass, and the defensive field fallbacks + readPercentCandidate handle garbage responses safely.

Two issues to fix before merging:

1. The "opencode" alias in detectProvider is incorrect

if (provider === "opencode-go" || provider === "opencode") return "opencode-go";

pi-ai registers two distinct providers: opencode (OpenCode Zen — the BYO-key marketplace, per-token billing) and opencode-go (the Go subscription plan). They have separate credentials (auth.json["opencode"] vs auth.json["opencode-go"]) and separate usage APIs — /zen/go/v1/usage only reports Go subscription quota.

With this alias, a Zen-only user running /usage gets routed down the Go branch, the key lookup under "opencode-go" fails, and they see "No OpenCode Go API key found (connect OpenCode Go to get a key)" — confusing, since they do have a working key, it's just stored under the other id. It's like routing Anthropic Console API users to the Claude Pro subscription panel.

Please drop the alias and match strictly:

if (provider === "opencode-go") return "opencode-go";

(The test using { provider: "opencode", id: "glm-5.2" } would need updating too.) Zen usage/credits would be a separate feature with its own endpoint if we ever want it.

2. Needs rebase — conflicts with master

This is based on the old master. 7b8ddea (add Kimi, drop Anthropic/Gemini/Antigravity) conflicts in all 4 files — ProviderKey, detectProvider, PROVIDER_LABELS, and canShowForProvider all need reworking onto the new provider list. Also note the imports are still @mariozechner/*; coordinate with #2 (the scope migration) for merge order or fold that in during the rebase.

Minor (non-blocking)

  • Missing a test for the "unrecognized response shape" branch (e.g. response without usage or non-numeric percents).
  • In canShowForProvider, the (auth as AuthData) casts are redundant — AuthData already declares the "opencode-go" field.

The core of the feature is solid — with the alias removed and rebased onto current master, this should be good to go.

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.

2 participants