feat(ui): show context-usage pie chart on the clear-context button - #3079
feat(ui): show context-usage pie chart on the clear-context button#3079sufan721 wants to merge 1 commit into
Conversation
Add a hover pie chart next to the clear-context button in both the Electron desktop and the web console, breaking the live context window down into system prompt / tool definitions / conversation / free.
|
Really like this — surfacing context usage on the clear button is exactly the right place for it, and the implementation is careful: reusing the existing A few notes before merge:
Overall solid work — happy to see it land once rebased. |
Add a hover pie chart next to the clear-context button in both the Electron desktop and the web console, breaking the live context window down into system prompt / tool definitions / conversation / free.
What does this PR do?
Clearing context used to be a blind operation — users couldn't see how much of the context window was occupied, or by what. This PR adds a hover pie chart to the clear-context button in both the Electron desktop app and the web console, breaking the live context down into four slices:
The donut center shows the used percentage, with per-slice token counts and a
used X / Yfooter.The backend had no context-usage endpoint at all (token estimation existed but was never surfaced —
Agent.last_usageis dead code), so this also adds a read-only endpoint:GET /api/sessions/{id}/context_usage(SessionContextUsageHandler)Agent.get_context_usage()— reuses the existing_estimate_*estimators; the input budget mirrors_trim_messagesAgentBridge.peek_agent()— a side-effect-free lookup of the live instance, so hovering never spins up MCP/skills; returnsavailable: falsewhen the session has no live contextbuild_tools_schema()extracted from the request path for reuse by the estimator (no behavior change)Frontend (no chart library added — hand-rolled SVG donut):
ContextUsageDonut+ContextUsagePopover(body portal), wired intoChatInput;getContextUsageadded to the API clientinstallContextUsagePopover(), olddata-tooltipremoved from the button so the two don't overlap, i18n keys for zh / zh-Hant / enType of change
Checklist