feat: stats page, and the client becomes Chamber Go

- 全部功能 gains 统计 (Stats): ranges Today/7/30/90 days/all time, a
  project scope (reusing the shared project sheet, plus "All projects"),
  session/prompt/token/cost/active-days/streak tiles, a daily activity
  chart (weekly past 92 days), token composition, efficiency tiles, model
  ranking by tokens/cost/steps and on-request tool-call stats; data comes
  from /api/experimental/session/stats and the day buckets use the device's
  IANA zone (a small platform channel; desktop falls back to UTC)
- the model bars draw a full-width track with a left-aligned fill, so a
  small token share reads as a sliver instead of an empty bar
- AI token strings read 词元 (not 令牌) in Chinese
- the client's display name is Chamber Go (launcher, iOS, Linux window,
  About), package unchanged; pairing/login labels and the user-agent
  follow, so a newly paired device shows "Chamber Go" on the web client's
  "Connect to this server" list
- bump to 0.5.6
This commit is contained in:
blumia committed 2026-11-26 17:18:09 +08:00
1 parent a70e9290ef
commit b65498d73e
19 files changed
+1637 -25

No files matched your search

+36 -5
View File
@@ -9,6 +9,7 @@ import 'dart:typed_data';
import '../version.dart';
import 'models.dart';
import 'scheduled_tasks.dart';
import 'usage_stats.dart';
import 'shells.dart';
import 'terminal.dart';
import 'transport.dart';
@@ -21,6 +22,11 @@ class ApiError implements Exception {
String toString() => message.isEmpty ? 'HTTP $status' : message;
}
/// What the server sees in request headers; the connect page's device name
/// comes from the pairing label below, not from this.
String _userAgent() =>
'chamber-go/${appVersion.isEmpty ? '0.0' : appVersion}';
class Client {
final Uri base;
@@ -55,7 +61,7 @@ class Client {
required String pairingId,
required String secret,
required String installId,
String clientLabel = 'OpenChamber Native',
String clientLabel = 'Chamber Go',
String clientKind = 'mobile',
String? deviceName,
}) async {
@@ -78,7 +84,7 @@ class Client {
}
Future<Map<String, dynamic>> login(String password, String installId,
{String label = 'OpenChamber Native', String clientKind = 'mobile'}) async {
{String label = 'Chamber Go', String clientKind = 'mobile'}) async {
return _json('POST', '/auth/session', body: {
'password': password,
'trustDevice': true,
@@ -214,6 +220,31 @@ class Client {
await _json('DELETE', '/api/session/${Uri.encodeComponent(id)}');
}
/// The session statistics report. [from] is milliseconds since the epoch and
/// omitted for all time; [project] is the OpenCode project id (not the
/// settings row id); [timezone] is an IANA name and decides how the server
/// buckets days. Tool details cost a scan of every message, so they are only
/// read when [tools] is true.
Future<UsageStats> sessionStats({
int? from,
int? to,
String? project,
required String timezone,
bool tools = false,
String? directory,
}) async {
final r = await _json('GET', '/api/experimental/session/stats',
query: {
if (from != null) 'from': '$from',
if (to != null) 'to': '$to',
if (project != null && project.isNotEmpty) 'project': project,
'timezone': timezone,
'tools': tools ? 'detail' : 'none',
},
directory: directory);
return UsageStats.fromJson(r['data'] as Map<String, dynamic>? ?? const {});
}
Future<Page<Message>> listMessages(String id,
{int limit = 30, String? cursor, String order = 'desc', String? directory, bool partShells = true}) async {
final query = <String, String>{
@@ -693,7 +724,7 @@ class Client {
headers: {
'accept': 'text/event-stream',
'cache-control': 'no-cache',
'user-agent': 'openchamber-native/0.3',
'user-agent': _userAgent(),
if (token != null && token!.isNotEmpty) 'authorization': 'Bearer $token',
},
));
@@ -976,7 +1007,7 @@ class Client {
/// The headers the terminal socket needs (auth, and the workspace the
/// server routes the upgrade by).
Map<String, String> get eventHeaders => {
'user-agent': 'openchamber-native/0.3',
'user-agent': _userAgent(),
if (token != null && token!.isNotEmpty) 'authorization': 'Bearer $token',
};
@@ -1033,7 +1064,7 @@ class Client {
bool noCompression = false}) async {
final headers = <String, String>{
'accept': path == '/api/event' ? 'text/event-stream' : 'application/json',
'user-agent': 'openchamber-native/0.3',
'user-agent': _userAgent(),
if (token != null && token!.isNotEmpty) 'authorization': 'Bearer $token',
};
if (directory != null && directory.isNotEmpty) {