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:
@@ -5,7 +5,9 @@
|
||||
// `?hits=N` N more `release` run hits in Search;
|
||||
// `?chats=N` N chat sessions in the chat list, each opening a short
|
||||
// markdown transcript;
|
||||
// `?graph=1` run 7 carries its pinned graph (plan -> build).
|
||||
// `?graph=1` run 7 carries its pinned graph (plan -> build);
|
||||
// `?quota=claude|opencode` (with `?chats=N`) pushes a usage frame with
|
||||
// that harness's account quota after a chat subscribes.
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
|
||||
Map<String, String> _params = const {};
|
||||
@@ -16,6 +18,56 @@ int get _hits => int.tryParse(_params['hits'] ?? '') ?? 0;
|
||||
int get _chats => int.tryParse(_params['chats'] ?? '') ?? 0;
|
||||
bool get perfRunGraph => _params['graph'] == '1';
|
||||
|
||||
/// Unsolicited envelopes that follow a reply: the `?quota=` usage frame.
|
||||
List<JsonMap> perfChatFollowUps(JsonMap request) {
|
||||
final quota = _params['quota'];
|
||||
if (_chats == 0 || quota == null || request['type'] != 'chat_subscribe') {
|
||||
return const [];
|
||||
}
|
||||
final now = DateTime.now();
|
||||
int at(Duration offset) => now.add(offset).millisecondsSinceEpoch;
|
||||
final account = quota == 'opencode'
|
||||
? {'harness': 'OpenCode', 'unsupported': true}
|
||||
: {
|
||||
'harness': 'Claude Code',
|
||||
'source': 'rate_limit_event',
|
||||
'plan': 'max',
|
||||
'as_of': at(const Duration(minutes: -4)),
|
||||
'windows': [
|
||||
{
|
||||
'id': 'five_hour',
|
||||
'label': '5-hour',
|
||||
'used_percent': 42,
|
||||
'resets_at': at(
|
||||
const Duration(hours: 2, minutes: 14, seconds: 30),
|
||||
),
|
||||
},
|
||||
{
|
||||
'id': 'seven_day',
|
||||
'label': 'Weekly',
|
||||
'used_percent': 93,
|
||||
'resets_at': at(const Duration(days: 3, hours: 5)),
|
||||
},
|
||||
],
|
||||
};
|
||||
return [
|
||||
{
|
||||
'type': 'chat_event',
|
||||
'chat_event': {
|
||||
'session_id': (request['chat_subscribe'] as Map?)?['session_id'],
|
||||
'kind': 'usage',
|
||||
'usage': {
|
||||
'scope': 'session',
|
||||
'total_tokens': 132408,
|
||||
'context_tokens': 42000,
|
||||
'context_window': 200000,
|
||||
'account': account,
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/// Run 7's pinned graph for `?graph=1`.
|
||||
JsonMap perfRunGraphFixture() => {
|
||||
'name': 'Release train',
|
||||
|
||||
@@ -506,9 +506,14 @@ class _FixtureChannel implements WebSocketChannel {
|
||||
final decoded = jsonDecode(data);
|
||||
if (decoded is! Map<String, dynamic>) return;
|
||||
final reply = probeReply(decoded);
|
||||
if (reply == null) return;
|
||||
final followUps = perfChatFollowUps(decoded);
|
||||
if (reply == null && followUps.isEmpty) return;
|
||||
Future<void>.delayed(const Duration(milliseconds: 120), () {
|
||||
if (!_incoming.isClosed) _incoming.add(jsonEncode(reply));
|
||||
if (_incoming.isClosed) return;
|
||||
if (reply != null) _incoming.add(jsonEncode(reply));
|
||||
for (final frame in followUps) {
|
||||
_incoming.add(jsonEncode(frame));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user