feat: 用户侧用量仪表盘 - #9
Merged
Merged
Conversation
Balances only ever went down on the account page with no explanation of where they went, even though RequestLog and the quota ledger already held everything needed. Adds GET /api/account/usage, scoped to the session user (an admin sees their own usage here, not the installation's). The view is a KPI row plus two single-series charts: daily spend as columns and a per-model breakdown. Costs are one series, so every mark wears the theme accent (--blue, verified at 4.02:1 light / 4.24:1 dark against the card surface) - never a value ramp, which would re-encode bar length as colour. The range control scopes both charts and the model ranking. Rendering the real component in a headless browser caught three defects that neither the type checker nor the tests would have: - a zero-cost day still drew a 2px stub, so a day with no spend showed a mark - the axis only had 1/2/5/10 steps, so a 2.47 peak was charted against 5.00 and used barely half the plot; adds 1.5/2.5/3/4/6/8 and maps the axis to 88% of the plot so the peak's label keeps headroom - the hover tooltip was anchored above the plot, where it covered the block heading; it now sits inside the card above the tick band Also makes clean:dist fail loudly instead of silently leaving old bundles behind. Removed 51MB of accumulated stale bundles this way once already, and the same silent partial delete recurred here while the API server held the files - the build now exits non-zero rather than shipping a dist/ that still contains superseded assets. Co-Authored-By: Claude Code <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
账户页只显示余额,从不说明钱花到哪去了 —— 而
RequestLog和额度流水里其实已经有全部数据,只是没有出口。改动
新增
GET /api/account/usage,按会话用户聚合(管理员在这里看到的也是自己的用量,不是整站的,那是/api/overview):前端是 KPI 区块 + 两张单系列图:每日消费用柱(离散日、允许为零,折线会在零值间画出误导性的连续),模型拆分用横向条。时间范围控制同时作用于两张图和模型排名。
配色
消费是单一序列,所以所有标记只用主题蓝
--blue—— 不做值阶梯着色,那会把柱长已经表达的信息再用颜色编码一遍。对比度用校验器实测(非目测):渲染验证
在无头浏览器里跑真实组件(注入 30 天真实日志、登录、切换主题、悬停),这抓到了三个类型检查和单测都发现不了的缺陷:
顺带修复
clean:dist改为失败即报错。之前它静默留下旧产物(已清理过一次 51MB 陈旧 bundle),这次构建时 API 服务正持有文件,同样的静默部分删除再次复现。现在清理不干净会以非零退出,而不是把含有被取代资源的dist/发出去。验证
TestAccountUsageAggregatesOwnLogsOnly:只统计本人日志(他人那笔 999 不计入)、今日/昨日分桶、成功率、空缺日补零、模型榜受范围约束go test ./...全绿