fix(conductor): Apply review suggestions for track 'event_driven_metrics_20260223'
This commit is contained in:
33
gui.py
33
gui.py
@@ -829,11 +829,13 @@ class App:
|
||||
|
||||
def _on_api_event(self, *args, **kwargs):
|
||||
"""Callback for ai_client events. Queues a telemetry refresh on the main thread."""
|
||||
payload = kwargs.get("payload", {})
|
||||
with self._pending_gui_tasks_lock:
|
||||
self._pending_gui_tasks.append({"action": "refresh_api_metrics"})
|
||||
self._pending_gui_tasks.append({"action": "refresh_api_metrics", "payload": payload})
|
||||
|
||||
def _refresh_api_metrics(self):
|
||||
def _refresh_api_metrics(self, payload: dict = None):
|
||||
"""Updates the token budget and cache stats visualizers."""
|
||||
payload = payload or {}
|
||||
self._last_bleed_update_time = time.time()
|
||||
|
||||
# History bleed
|
||||
@@ -846,21 +848,20 @@ class App:
|
||||
limit = stats.get("limit", 0)
|
||||
dpg.set_value("token_budget_label", f"{current:,} / {limit:,}")
|
||||
|
||||
# Gemini cache
|
||||
# Gemini cache - Use payload data to avoid blocking the main thread with network calls
|
||||
if dpg.does_item_exist("gemini_cache_label"):
|
||||
if self.current_provider == "gemini":
|
||||
try:
|
||||
cache_stats = ai_client.get_gemini_cache_stats()
|
||||
count = cache_stats.get("cache_count", 0)
|
||||
size_bytes = cache_stats.get("total_size_bytes", 0)
|
||||
size_kb = size_bytes / 1024.0
|
||||
text = f"Gemini Caches: {count} ({size_kb:.1f} KB)"
|
||||
dpg.set_value("gemini_cache_label", text)
|
||||
dpg.configure_item("gemini_cache_label", show=True)
|
||||
except Exception:
|
||||
dpg.configure_item("gemini_cache_label", show=False)
|
||||
else:
|
||||
cache_stats = payload.get("cache_stats")
|
||||
if cache_stats:
|
||||
count = cache_stats.get("cache_count", 0)
|
||||
size_bytes = cache_stats.get("total_size_bytes", 0)
|
||||
size_kb = size_bytes / 1024.0
|
||||
text = f"Gemini Caches: {count} ({size_kb:.1f} KB)"
|
||||
dpg.set_value("gemini_cache_label", text)
|
||||
dpg.configure_item("gemini_cache_label", show=True)
|
||||
elif self.current_provider != "gemini":
|
||||
dpg.configure_item("gemini_cache_label", show=False)
|
||||
# Note: We don't hide it if no stats are in payload,
|
||||
# to avoid flickering during tool/chunk events that don't include stats.
|
||||
|
||||
def _update_performance_diagnostics(self):
|
||||
"""Updates performance diagnostics displays (throttled)."""
|
||||
@@ -2254,7 +2255,7 @@ class App:
|
||||
if cb:
|
||||
cb()
|
||||
elif action == "refresh_api_metrics":
|
||||
self._refresh_api_metrics()
|
||||
self._refresh_api_metrics(task.get("payload", {}))
|
||||
except Exception as e:
|
||||
print(f"Error executing GUI hook task: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user