Skip to content

display token usage in channel cards via tokenStatsByChannel API#1528

Merged
looplj merged 20 commits into
looplj:unstablefrom
banlanzs:pr-dashboard-only
Apr 28, 2026
Merged

display token usage in channel cards via tokenStatsByChannel API#1528
looplj merged 20 commits into
looplj:unstablefrom
banlanzs:pr-dashboard-only

Conversation

@banlanzs

Copy link
Copy Markdown
Contributor
image

banlanzs added 18 commits April 23, 2026 14:56
…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
- 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-apps

greptile-apps Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds token usage statistics (input, output, total) to channel cards on the dashboard by introducing a channelId field to the tokenStatsByChannel GraphQL API and joining the two datasets on the GUID-based channel ID in the frontend. It also adds three new sort options for token metrics and provides full i18n coverage for both English and Simplified Chinese.

Previous concerns about name-based joining and missing i18n keys have both been addressed: the backend now groups by (channel_id, channel_name) and returns a proper objects.GUID, and all six new translation keys are present in both locale files.

Confidence Score: 5/5

Safe 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

Filename Overview
frontend/src/features/dashboard/channel-success-rates/index.tsx Adds token usage display to channel cards using channelId-keyed map; adds three new sort fields for token metrics; both i18n keys and the ID-based join are properly implemented
frontend/src/features/dashboard/data/dashboard.ts Adds channelId: z.string() to tokensByChannelSchema and channelId to the GQL query; aligns with backend GUID format used by channelSuccessRateSchema
internal/server/gql/dashboard.resolvers.go Groups by (channel_id, channel_name) and exposes channelId as objects.GUID; consistent with how ChannelSuccessRates resolver produces IDs
internal/server/gql/dashboard.graphql Adds channelId: ID! to TokenStatsByChannel type; schema change is backward-compatible (additive only)
internal/server/gql/models_gen.go Auto-generated; adds ChannelID objects.GUID field to TokenStatsByChannel struct
internal/server/gql/generated.go Auto-generated GraphQL execution layer; wires up channelId field resolver and complexity function for TokenStatsByChannel
frontend/src/locales/en/dashboard.json Adds all six new i18n keys for token sort options and token card labels in English
frontend/src/locales/zh-CN/dashboard.json Adds all six new i18n keys for token sort options and token card labels in Simplified Chinese

Sequence Diagram

sequenceDiagram
    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
Loading

Reviews (2): Last reviewed commit: "fix(dashboard): use channelId instead of..." | Re-trigger Greptile

Comment thread frontend/src/features/dashboard/channel-success-rates/index.tsx Outdated
Comment thread frontend/src/features/dashboard/channel-success-rates/index.tsx

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread frontend/src/features/dashboard/channel-success-rates/index.tsx Outdated
Comment thread frontend/src/features/dashboard/channel-success-rates/index.tsx Outdated
…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.
@looplj looplj merged commit 6a73d9d into looplj:unstable Apr 28, 2026
4 checks passed
@banlanzs banlanzs deleted the pr-dashboard-only branch May 31, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants