Chat info: account quota per harness (Claude rate_limit_event, Codex account/rateLimits, OpenCode unsupported)

Usage frames carry optional usage.account {harness, source, plan, as_of,
windows[{id,label,used_percent,resets_at}], unsupported}. Claude Code quota
comes from its rate_limit_event stream lines and the initialize account
(plan), shared across chats on the same account. Codex reads
account/rateLimits/read once per connection (re-read when a chat opens after
5 min) and merges account/rateLimits/updated. OpenCode exposes no quota API
and says so. The app's chat info sheet shows an Account usage section with a
progress bar and reset countdown per window, Material and Cupertino.
This commit is contained in:
2026-11-02 18:57:13 +00:00
parent 8a402c1114
commit 10049b8062
26 changed files with 1469 additions and 19 deletions
+13 -3
View File
@@ -40,6 +40,16 @@ func tokenSum(values ...*int64) *int64 {
return &total
}
// openCodeAccount says OpenCode reports no account quota. OpenCode 2.0.32's
// API (provider, integration, model and session routes) has no plan, usage or
// quota read, and its only rate-limit data is the x-ratelimit-* headers of a
// failed provider request (AI.Error.RateLimit), which is neither a plan quota
// nor available before a limit is hit. That covers the OpenCode Go and Zen
// subscriptions too. Nothing is estimated in its place.
func openCodeAccount() *protocol.ChatAccountUsage {
return &protocol.ChatAccountUsage{Harness: "OpenCode", Unsupported: true}
}
func decodeUsageSnapshot(data []byte) *protocol.ChatUsage {
var record struct {
Tokens usageTokens `json:"tokens"`
@@ -48,9 +58,9 @@ func decodeUsageSnapshot(data []byte) *protocol.ChatUsage {
Output int `json:"outputTokens"`
}
if json.Unmarshal(data, &record) != nil {
return &protocol.ChatUsage{Scope: "session"}
return &protocol.ChatUsage{Scope: "session", Account: openCodeAccount()}
}
u := &protocol.ChatUsage{Scope: "session", InputTokens: record.Input, OutputTokens: record.Output}
u := &protocol.ChatUsage{Scope: "session", InputTokens: record.Input, OutputTokens: record.Output, Account: openCodeAccount()}
if record.Tokens.Input != nil {
u.InputTokens = int(*record.Tokens.Input)
}
@@ -96,7 +106,7 @@ func (c *Chat) Usage(ctx context.Context, id string) (*protocol.ChatUsage, error
return nil, fmt.Errorf("invalid OpenCode session id")
}
if c.conn.Backend == "v1" {
return &protocol.ChatUsage{Scope: "session"}, nil
return &protocol.ChatUsage{Scope: "session", Account: openCodeAccount()}, nil
}
data, err := c.call(ctx, "get", "/api/session/"+id, nil)
if err != nil {