feat(admin): 用量记录页新增"用户 Token 排行"面板

- 在 /admin/usage 新增按用户聚合的 Token 排行表(输入/输出/缓存/总 Token、请求数、费用)
- 支持按列排序、邮箱搜索、Top N (20/50/100/200),点击行下钻到该用户
- 复用现有筛选(用户/时间/模型/分组等)与既有 KPI 卡片、逐条日志
- 后端对 /admin/dashboard/user-breakdown 做加法扩展(向后兼容):
  - UserBreakdownItem 增加 input_tokens/output_tokens/cache_tokens
  - 新增 sort_by(白名单排序,防注入,缺省仍按 actual_cost)
- 新增 sort_by 转发单元测试;更新 UsageView.spec 稳定桩

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Birditch
2026-07-09 06:04:22 -04:00
co-authored by Claude Opus 4.8
parent 64fdc11ec4
commit b062b36646
11 changed files with 277 additions and 11 deletions
+2
View File
@@ -167,6 +167,8 @@ export interface UserBreakdownParams {
endpoint?: string
endpoint_type?: 'inbound' | 'upstream' | 'path'
limit?: number
// Sort column for the ranking (allowlisted server-side; falls back to actual_cost)
sort_by?: 'total_tokens' | 'input_tokens' | 'output_tokens' | 'cache_tokens' | 'requests' | 'cost' | 'actual_cost'
// Additional filter conditions
user_id?: number
api_key_id?: number