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

+15 -2
View File
@@ -100,7 +100,9 @@ offline, same-origin so no CORS). It is a thin client over a **session-aware API
- `POST /api/sessions/{id}/chat` — append a turn; the server loads the stored
context, runs inference (streaming SSE or not) and persists the new turns with
their token usage.
- `GET /api/stats` — aggregate counters (sessions, messages, prompt/completion tokens).
- `GET /api/stats` — the stats dashboard payload: persistent totals (sessions,
messages, prompt/completion/total tokens, tool calls), per-session and per-day
breakdowns, plus live engine status and a since-startup decode/prefill speed gauge.
- `GET/PUT /api/settings/defaults` — the global default settings template.
- `POST /api/uploads` — store an uploaded file (base64) in the shared upload dir;
returns metadata (kind, token count, path). Attach the returned id to a chat turn.
@@ -128,6 +130,17 @@ tokenizer) is inlined; **large text and binaries** are handed to the agent as a
with a reminder to inspect them selectively via `shell_exec` — binaries never enter
the context directly. The `shell_exec` output cap is a second safety net.
**Statistics.** The "Statistiche" button opens a live dashboard over the
*persistent* history — our angle on the reference's ephemeral request monitor:
overview cards (engine model / context window / idle-busy, token-weighted **decode
speed** and prefill speed since startup, total/prompt/completion tokens, sessions,
messages, tool calls), a **daily token chart** (stacked prompt/completion per UTC
day) and a **per-session breakdown** with relative token-share bars. `GET /api/stats`
returns the store aggregates plus a live engine status and an in-memory performance
gauge (token-weighted over the requests served since startup, from the engine's
`DONE` timings); the view polls every 2s while open. History totals survive
restarts; the speed gauge resets with the process.
The standard `/v1` API stays **stateless**; conversation context lives server-side
in an embedded **SQLite** database (default `~/.strata-ctl/data/sessions.db`,
override with `db_path`). Storage sits behind a `Store` trait so it can be swapped
@@ -232,7 +245,7 @@ later adaptation round.
## Status
Working and tested (123 tests, plus 2 real-file tests run on demand). Text, images,
Working and tested (124 tests, plus 2 real-file tests run on demand). Text, images,
the full client-side tool loop, the Anthropic endpoint, the web GUI (session
context, streaming, stats, **file/image upload**) and **agent mode** (the model
using `shell_exec` on the host) have been validated live against the real Inkling