feat(gui): Implement token budget visualizer

This change adds a progress bar and label to the Provider panel to display the current history token usage against the provider's limit. The UI is updated in real-time.
This commit is contained in:
2026-02-23 13:40:04 -05:00
parent a52f3a2ef8
commit c35170786b
2 changed files with 90 additions and 0 deletions

17
gui.py
View File

@@ -769,6 +769,17 @@ class App:
total = usage["input_tokens"] + usage["output_tokens"]
dpg.set_value("ai_token_usage", f"Tokens: {total} (In: {usage['input_tokens']} Out: {usage['output_tokens']})")
def _update_telemetry_panel(self):
"""Updates the token budget visualizer in the Provider panel."""
stats = ai_client.get_history_bleed_stats()
if dpg.does_item_exist("token_budget_bar"):
percentage = stats.get("percentage", 0.0)
dpg.set_value("token_budget_bar", percentage / 100.0 if percentage else 0.0)
if dpg.does_item_exist("token_budget_label"):
current = stats.get("current", 0)
limit = stats.get("limit", 0)
dpg.set_value("token_budget_label", f"{current:,} / {limit:,}")
def _append_comms_entry(self, entry: dict, idx: int):
if not dpg.does_item_exist("comms_scroll"):
return
@@ -1870,6 +1881,11 @@ class App:
callback=self.cb_model_changed,
)
dpg.add_separator()
dpg.add_text("Telemetry")
dpg.add_text("History Token Budget:", color=_LABEL_COLOR)
dpg.add_progress_bar(tag="token_budget_bar", default_value=0.0, width=-1)
dpg.add_text("0 / 0", tag="token_budget_label")
dpg.add_separator()
dpg.add_text("Parameters")
dpg.add_input_float(tag="ai_temperature", label="Temperature", default_value=self.temperature, min_value=0.0, max_value=2.0)
dpg.add_input_int(tag="ai_max_tokens", label="Max Tokens (Output)", default_value=self.max_tokens, step=1024)
@@ -2207,6 +2223,7 @@ class App:
# Flush any comms entries queued from background threads
self._flush_pending_comms()
self._update_telemetry_panel()
dpg.render_dearpygui_frame()