refactor: unify token usage stats across all session types (#274)

- Rewrite SQL queries to join bot_history_messages with bot_sessions,
  supporting chat/heartbeat/schedule usage from a single source
- Update Go handler and CLI command to use unified queries
- Fix daily chart stacking: each session type gets its own bar group
- Add total input/output trend lines to the daily token chart
- Fix summary cards reactivity by restricting aggregation to allDays range
- Fix cache chart reactive dependency tracking by inlining data access
- Add i18n keys for schedule, totalInput, totalOutput
- Default time range changed to 7 days
- Regenerate sqlc, swagger, and SDK
This commit is contained in:
Acbox Liu
2026-03-21 19:14:37 +08:00
committed by GitHub
parent 7d7d0e4b51
commit 80b36f79f3
13 changed files with 320 additions and 410 deletions
+9 -1
View File
@@ -4676,7 +4676,7 @@
},
"/bots/{bot_id}/token-usage": {
"get": {
"description": "Get daily aggregated token usage for a bot, split by chat and heartbeat, with optional model filter and per-model breakdown",
"description": "Get daily aggregated token usage for a bot, split by chat, heartbeat, and schedule session types, with optional model filter and per-model breakdown",
"tags": [
"token-usage"
],
@@ -11183,6 +11183,12 @@
"items": {
"$ref": "#/definitions/handlers.DailyTokenUsage"
}
},
"schedule": {
"type": "array",
"items": {
"$ref": "#/definitions/handlers.DailyTokenUsage"
}
}
}
},
@@ -11909,11 +11915,13 @@
"enum": [
"ok",
"auth_error",
"model_not_supported",
"error"
],
"x-enum-varnames": [
"TestStatusOK",
"TestStatusAuthError",
"TestStatusModelNotSupported",
"TestStatusError"
]
},