Add a live statistics dashboard over persistent history

Replace the four-row stats modal with a real dashboard — our own angle on
the reference's ephemeral request monitor: because our context lives in
SQLite we can aggregate over ALL history, not just the last N requests.

Backend:
- Usage carries the engine's prompt_ms/decode_ms (from DONE); a token-
  weighted in-memory PerfMeter in ChatService records every served
  request (complete + stream) and exposes decode/prefill tok/s.
- store::Stats grows total_tokens, tool_calls (json_array_length over
  assistant tool_calls_json), a per-session breakdown (busiest first)
  and a per-UTC-day token series; all over existing columns, no schema
  change, still behind the Store trait.
- GET /api/stats returns the store aggregates flattened plus a live
  engine status (model, max_context, busy) and the perf gauge.

Frontend (mobile-first, vanilla, i18n catalog):
- Overview cards: engine state dot + model + context, decode speed
  (run average) + prefill, total/prompt/completion tokens, sessions +
  messages, tool calls, requests served.
- Daily stacked prompt/completion bar chart (continuous zero-filled
  UTC window, last 30 days) and per-session token-share bars.
- Polls every 2s while open, re-renders only on change; closes via
  button, backdrop or Escape.

Tests: new store breakdown test + extended stats integration assertions
(124 passed, 2 ignored). Verified live on the real engine: decode/prefill
gauge populated from DONE timings; dashboard renders on desktop.
This commit is contained in:
adm committed 2026-11-25 17:52:38 +01:00
1 parent e79ee0e20e
commit 765c197b95
11 files changed
+642 -42

No files matched your search

+9 -6
View File
@@ -18,7 +18,7 @@
</div>
<ul id="session-list"></ul>
<div class="drawer-foot">
<button id="show-stats" class="btn ghost">Statistiche</button>
<button id="show-stats" class="btn ghost" data-i18n="stats.title">Statistiche</button>
</div>
</aside>
<div id="splitter" role="separator" aria-orientation="vertical" aria-label="Ridimensiona l'elenco delle discussioni" aria-valuemin="200" aria-valuemax="480" aria-valuenow="280" tabindex="0"></div>
@@ -49,12 +49,15 @@
</main>
</div>
<!-- Stats modal -->
<!-- Stats dashboard -->
<div id="stats-modal" hidden>
<div class="modal-card">
<h2>Statistiche</h2>
<dl id="stats-body"></dl>
<button id="close-stats" class="btn">Chiudi</button>
<div class="modal-card stats-card">
<div class="stats-head">
<h2 data-i18n="stats.title">Statistiche</h2>
<span id="stats-live" class="stats-live muted"></span>
<button id="close-stats" class="btn icon" aria-label="Chiudi">&#10005;</button>
</div>
<div id="stats-content" class="stats-content"></div>
</div>
</div>