display token usage in channel cards via tokenStatsByChannel API#1528
Conversation
banlanzs
commented
Apr 28, 2026
…es with UI checkbox support - Add bailian_anthropic (Anthropic format) at https://dashscope.aliyuncs.com/apps/anthropic - Add moonshot_coding (Kimi Coding endpoint) at https://api.kimi.com/coding - Both use anthropic/messages format with anthropic.PlatformDirect transformer - Implement checkbox UI pattern (like Gemini Vertex/Anthropic AWS) for Kimi Coding selection - Fix handleKimiCodingChange to properly update form.type and form.baseURL on toggle - Add English/Chinese i18n keys for new channel types and Kimi Coding checkbox - Update Ent schema, channel configs, provider mappings, and generated code Follows dual/triple-channel pattern used by Minimax, Moonshot, Doubao providers.
- Reset useKimiCoding on provider change, initialRow change, and dialog open/close - Merge TypeBailianAnthropic and TypeMoonshotCoding switch cases
…ix ContentSection import
- Change navigate({ to: '/dashboard' }) to navigate({ to: '/' })
- Dashboard is at root route, not /dashboard
- Fixes broken navigation when clicking '返回仪表盘' button
- Add missing ContentSection import in channel-success-rates page - Replace useMemo with useEffect for page reset side effect - Internationalize hardcoded Chinese labels (今天/本周/本月) - Replace <a> with Link component for SPA navigation in dashboard
The dist directory is gitignored but go:embed all:dist/* requires at least one file to compile. Add .gitkeep to fix CI build failures while keeping frontend artifacts untracked.
Extend ChannelSuccessRate with token fields and aggregate per-channel usage from usage logs. Update dashboard channel success rate UI to display and sort by token consumption, with i18n labels.
ChannelSuccessRates showed success/failure counts for soft-deleted channels but token stats were zeroed because the token query filtered deleted_at=0. Align channel coverage by removing that filter from the token aggregation.
Token usage data is now served by the existing tokenStatsByChannel API instead of being embedded in the channelSuccessRates response, avoiding a redundant usage_log query on every success-rate request.
…yChannel API Reuse existing tokenStatsByChannel API instead of embedding token fields in channelSuccessRates response. Match by channelName to display token consumption in channel success rate cards.
Greptile SummaryThis PR adds token usage statistics (input, output, total) to channel cards on the dashboard by introducing a Previous concerns about name-based joining and missing i18n keys have both been addressed: the backend now groups by Confidence Score: 5/5Safe to merge — all previous concerns are resolved and no new P0/P1 issues were found. Both prior review findings (name-based join and missing i18n sort keys) have been fully addressed. The backend now exposes a stable channelId GUID, the frontend joins on it correctly, and all six new locale keys are present in both locale files. No logic bugs, security issues, or data-integrity problems were identified. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant UI as ChannelSuccessRates (React)
participant CSR as useChannelSuccessRates hook
participant TBC as useTokensByChannel hook
participant GQL as GraphQL API
UI->>CSR: fetch(timeWindow)
UI->>TBC: fetch(timeWindow)
CSR->>GQL: channelSuccessRates(timeWindow)
TBC->>GQL: tokenStatsByChannel(timeWindow)
GQL-->>CSR: [{channelId: GUID, channelName, successRate, ...}]
GQL-->>TBC: [{channelId: GUID, channelName, inputTokens, outputTokens, totalTokens, ...}]
CSR-->>UI: channels[]
TBC-->>UI: tokenData[]
UI->>UI: build tokenByChannel Map(channelId -> TokensByChannel)
UI->>UI: sort channels by selected field (incl. token fields via map lookup)
UI->>UI: render cards - show token row only when totalTokens > 0
Reviews (2): Last reviewed commit: "fix(dashboard): use channelId instead of..." | Re-trigger Greptile |
There was a problem hiding this comment.
Code Review
This pull request integrates token consumption metrics into the channel success rates dashboard, allowing users to view and sort by input, output, and total tokens. The changes involve fetching token data via a new hook, updating the sorting logic, and displaying token stats within the channel list. Review feedback recommends using internationalization for the new sort labels and refactoring the conditional rendering logic to replace the IIFE with a more idiomatic React pattern for improved readability.
…ess rates Replace hardcoded English sort labels with t() calls and add missing locale keys for input/output/total token sort options. Also replace IIFE conditional rendering with idiomatic showTokens && pattern.
…join Add channelId field to TokenStatsByChannel API and group by channel ID instead of channel name to ensure reliable matching even when channels share the same display name or get renamed.