feat(frontend): color-code first-token & total latency in usage views#43
Conversation
Map latency magnitude to color across the usage surfaces, on two scales: - 首字延迟 (first-token / TTFT): tight 3-step scale (<3s green / <10s amber / >=10s red) — the pre-first-byte window stays small even when upstreams are slow. - 整体延迟 (total request latency): wider 5-step scale that keeps the original 1:3:6:12 spacing (<8s emerald / <24s lime / <48s amber / <96s orange / >=96s red), since a streaming reasoning request can legitimately run well over a minute. Changes: - llm_access_shared.rs: add shared LatencyBadgeColor alias, format_latency_ms, first_token_latency_color and total_latency_color helpers + unit tests. - admin_llm_gateway.rs: the Usage tab and Usage-journal-preview tab now use the shared helpers; first-token latency is rendered as a color-coded badge instead of plain muted text. The private format_latency_ms is dropped in favor of the shared one. - llm_access_usage.rs (public /llm-access/usage): the latency cell reuses the colored-badge style and now shows first-token latency; the 账号 (account) column is removed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request refactors and standardizes latency rendering across the LLM gateway admin and public usage pages. It extracts latency formatting and color-scale logic (for both total latency and first-token latency/TTFT) into a shared module (llm_access_shared.rs), adds corresponding unit tests, and updates the UI to display styled badges for both metrics. Additionally, it removes the account column from the public usage table. No review comments were provided, so there is no feedback to address.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
背景
usage 相关视图里延迟只有数字(或仅整体延迟有颜色),不容易一眼看出快慢。本 PR 让首字延迟(首字 / TTFT)和整体延迟都按延迟高低映射到颜色,并为两者设计了不同宽度的色阶。
改动
1. 共享色阶 helper(
llm_access_shared.rs)新增
LatencyBadgeColor类型别名、format_latency_ms,以及两个色阶函数(带单元测试),供 admin 与公开页复用:<3s🟢 emerald ·<10s🟡 amber ·≥10s🔴 red<8s🟢 emerald ·<24s🟢 lime ·<48s🟡 amber ·<96s🟠 orange ·≥96s🔴 red1:3:6:12的间距比例(绿色阈值 5s → 8s,其余同比例放大)。2. Admin LLM Gateway(
admin_llm_gateway.rs)format_latency_ms,统一使用共享实现。3. 公开页
/llm-access/usage(llm_access_usage.rs)验证
cargo check -p static-flow-frontend --target wasm32-unknown-unknown✅cargo test(latency 相关用例,含新增边界测试)5 passed ✅lime/orange工具类已生成 ✅范围说明
监控(运行监控)面板里的
首字延迟 / 整体延迟是聚合 KPI 卡片(均值/最大值),并非逐条 usage 表格,因此本 PR 未改动;如需要也给这些聚合卡片上色可以再开一个 PR。🤖 Generated with Claude Code