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
@@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart';
import '../../../core/api_gateway.dart';
import '../data/chat_repository.dart';
import '../domain/chat_account_usage.dart';
import '../domain/chat_sessions.dart';
import '../domain/chat_transcript.dart';
import 'chat_server_queue.dart';
@@ -73,6 +74,7 @@ class ChatThreadController extends ChangeNotifier {
String? _liveAssistantMessageId;
String? _awaitingResponseOperation;
JsonMap? _usage;
ChatAccountUsage? _accountUsage;
String? _error;
bool _subscribed = false;
@@ -147,6 +149,10 @@ class ChatThreadController extends ChangeNotifier {
/// Unknown fields stay null, so a viewer can distinguish them from zero.
JsonMap? get usage => _usage;
/// The harness account's latest reported quota, or null while unknown. It
/// is account state: a frame without one keeps the last known value.
ChatAccountUsage? get accountUsage => _accountUsage;
String? get error => _error;
bool get subscribed => _subscribed;
String? get subscriptionError => _subscriptionError;
@@ -348,8 +354,14 @@ class ChatThreadController extends ChangeNotifier {
// Usage replaces the last snapshot and never adds a message, runs a turn
// or admits a queued prompt. An unusable snapshot keeps the previous
// recorded values instead of replacing them with fabricated zeros.
final usage = chatUsageSnapshot(body['usage']);
if (usage == null || !_reportedUsage(usage)) return;
final raw = body['usage'];
final account = chatAccountUsage(raw is Map ? raw['account'] : null);
if (account != null) _accountUsage = account;
final usage = chatUsageSnapshot(raw);
if (usage == null || !_reportedUsage(usage)) {
if (account != null) _notify(transcript: false);
return;
}
_usage = usage;
_notify(transcript: false);
return;