feat(token-viz): Phase 2 — trim warning, Gemini/Anthropic cache status display
This commit is contained in:
35
gui_2.py
35
gui_2.py
@@ -2765,6 +2765,41 @@ class App:
|
||||
imgui.table_set_column_index(1); imgui.text(f"{tok:,}")
|
||||
imgui.table_set_column_index(2); imgui.text(f"{tok / total_tok * 100:.0f}%")
|
||||
imgui.end_table()
|
||||
if stats.get("would_trim"):
|
||||
imgui.text_colored(imgui.ImVec4(1.0, 0.3, 0.0, 1.0), "WARNING: Next call will trim history")
|
||||
trimmable = stats.get("trimmable_turns", 0)
|
||||
if trimmable:
|
||||
imgui.text_disabled(f"Trimmable turns: {trimmable}")
|
||||
msgs = stats.get("messages")
|
||||
if msgs:
|
||||
shown = 0
|
||||
for msg in msgs:
|
||||
if shown >= 3:
|
||||
break
|
||||
if msg.get("trimmable"):
|
||||
role = msg.get("role", "?")
|
||||
toks = msg.get("tokens", 0)
|
||||
imgui.text_disabled(f" [{role}] ~{toks:,} tokens")
|
||||
shown += 1
|
||||
|
||||
imgui.separator()
|
||||
if ai_client._provider == "gemini":
|
||||
if ai_client._gemini_cache is not None:
|
||||
age = time.time() - (ai_client._gemini_cache_created_at or time.time())
|
||||
ttl = ai_client._GEMINI_CACHE_TTL
|
||||
imgui.text_colored(C_LBL, f"Gemini Cache: ACTIVE | Age: {age:.0f}s / {ttl}s | Renews at: {ttl * 0.9:.0f}s")
|
||||
else:
|
||||
imgui.text_disabled("Gemini Cache: INACTIVE")
|
||||
elif ai_client._provider == "anthropic":
|
||||
with ai_client._anthropic_history_lock:
|
||||
turns = len(ai_client._anthropic_history)
|
||||
cache_reads = 0
|
||||
for entry in reversed(ai_client.get_comms_log()):
|
||||
if entry.get("kind") == "response":
|
||||
cache_reads = (entry.get("payload") or {}).get("usage", {}).get("cache_read_input_tokens") or 0
|
||||
break
|
||||
imgui.text_disabled("Anthropic: 4-breakpoint ephemeral caching (auto-managed)")
|
||||
imgui.text_disabled(f" {turns} history turns | Cache reads last call: {cache_reads:,}")
|
||||
|
||||
def _render_message_panel(self) -> None:
|
||||
# LIVE indicator
|
||||
|
||||
Reference in New Issue
Block a user