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

+31 -1
View File
@@ -20,5 +20,35 @@
"settings.error": "Errore: {msg}",
"attach.title": "Allega file o immagini",
"attach.remove": "Rimuovi allegato",
"attach.error": "Caricamento fallito: {msg}"
"attach.error": "Caricamento fallito: {msg}",
"stats.title": "Statistiche",
"stats.close": "Chiudi",
"stats.updated": "Aggiornato {time}",
"stats.disconnected": "Disconnesso · riprovo",
"stats.engine": "Motore",
"stats.engine.idle": "Inattivo",
"stats.engine.busy": "In uso",
"stats.context": "{n} token di contesto",
"stats.decode": "Velocità decode",
"stats.decode.sub": "media dall'avvio",
"stats.prefill": "prefill {n} tok/s",
"stats.tokens": "Token totali",
"stats.tokens.sub": "{p} prompt · {c} completati",
"stats.sessions": "Sessioni",
"stats.messages.sub": "{n} messaggi",
"stats.tools": "Chiamate tool",
"stats.tools.sub": "nella cronologia",
"stats.requests": "Richieste servite",
"stats.requests.sub": "dall'avvio",
"stats.daily": "Attività giornaliera",
"stats.daily.sub": "token per giorno (UTC)",
"stats.daily.empty": "Nessuna attività registrata.",
"stats.legend.prompt": "Prompt",
"stats.legend.completion": "Completati",
"stats.perSession": "Per sessione",
"stats.perSession.sub": "quota di token per chat",
"stats.perSession.empty": "Nessuna sessione.",
"stats.session.updated": "aggiornato {when}",
"stats.tps": "{n} tok/s",
"stats.na": "—"
}