Add mobile-first web GUI with a server-side session store (SQLite)

- store: a swappable Store trait + bundled-SQLite implementation (WAL,
  sessions/messages with per-turn token usage, cascade delete). The standard
  /v1 API stays stateless; conversation context lives server-side so
  multi-session, statistics and advanced settings can grow on top. DB path
  configurable (db_path, default ~/.config/strata-ctl/sessions.db).
- api::sessions: session-aware GUI API — session CRUD, history, POST .../chat
  (loads stored context, reuses the completion service, persists new turns with
  usage; streaming accumulates the assistant turn and persists before [DONE]),
  and /api/stats.
- api::web + web/: a mobile-first chat GUI (vanilla ES modules, no build step),
  embedded via rust-embed and served at GET / (same-origin, offline, single
  binary). Off-canvas session drawer on phones, persistent sidebar on wide
  screens; live streaming with a collapsible thinking panel; model output is
  inserted via textContent only.
- router_with_store mounts the GUI + session API only when a store is configured;
  router()/router_with_auth() are unchanged (API-only).
- Fix: a global [hidden]{display:none!important} reset so an author display rule
  (the stats modal's display:flex) cannot defeat the hidden attribute.

7 new tests (2 store unit + 4 session HTTP end-to-end + 1 config); 94 green +
2 ignored; clippy/fmt clean. Validated live on engine 0.1.67 (context retention,
streaming, stats) and via a browser check (modal, send/render, stats open/close).
Future: the Store backend is intended to move to ArangoDB (multi-model).
This commit is contained in:
adm committed 2026-11-24 20:38:24 +01:00
1 parent 9e6d44fa1a
commit 1e13caa4ed
15 files changed
+1922 -23

No files matched your search

+37 -8
View File
@@ -85,6 +85,30 @@ Operational hardening:
- Blocking image I/O runs off the async event loop; temp files are cleaned on every
exit path; image fetches have a timeout, a size cap and a basic SSRF guard.
## Web GUI
A minimal, **mobile-first** chat GUI is served by the same binary at `GET /` (assets
under `/assets/...`, embedded via `rust-embed` — no Node, no build step, works
offline, same-origin so no CORS). It is a thin client over a **session-aware API**:
- `GET /` — the chat shell (responsive: an off-canvas session drawer on phones, a
persistent sidebar on wide screens; streaming answers with a collapsible
"thinking" panel; touch-friendly targets and safe-area insets).
- `POST /api/sessions`, `GET /api/sessions`, `GET/PATCH/DELETE /api/sessions/{id}`,
`GET /api/sessions/{id}/messages` — session CRUD and history.
- `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).
The standard `/v1` API stays **stateless**; conversation context lives server-side
in an embedded **SQLite** database (default `~/.config/strata-ctl/sessions.db`,
override with `db_path`). Storage sits behind a `Store` trait so it can be swapped
(the planned direction is **ArangoDB**, multi-model: KV / documents / graphs / vector
indexes) or complemented by another DBMS for advanced analytics later, without
touching the API or the GUI. This is the foundation for multi-session, statistics and
advanced settings to grow on top.
## Architecture
```
@@ -100,7 +124,10 @@ shared JSON config ──► InklingFormatter ──► Engine supervisor ──
- `engine` — a pure protocol parser plus a supervisor that owns the child process,
serializes requests on its single control stream, and handles STOP/drain/QUIT.
- `api` — request/response types, the `Formatter`/`Decoder` seam, the completion
service (stream + non-stream) and the axum router.
service (stream + non-stream), the axum router, the session-aware GUI API and the
embedded web assets.
- `store` — the persistent session/context store: a `Store` trait with a bundled
SQLite implementation (WAL), used by the GUI API.
## Building and running
@@ -124,22 +151,24 @@ uses `tracing`; set `RUST_LOG` to control verbosity (default `info`).
The config is the same JSON the other Strata tools use. Keys acted on here include
`exe`, `args`, `cwd`, `tokenizer`, `model_name`, `host`, `port`, `reasoning_effort`,
`sampling`, `api_key`, `allowed_hosts`, and the optional `startup_timeout_secs` /
`silence_timeout_secs`. Everything else (`arch`, `mcp_servers`, `cors_origins`, …)
is preserved untouched and reported as ignored — unknown keys never break startup.
`sampling`, `api_key`, `allowed_hosts`, `db_path` (GUI session database), and the
optional `startup_timeout_secs` / `silence_timeout_secs`. Everything else (`arch`,
`mcp_servers`, `cors_origins`, …) is preserved untouched and reported as ignored —
unknown keys never break startup.
## Status
Working and tested (87 tests, plus 2 real-file tests run on demand). Text, images
and the full client-side tool loop have been validated live against the real
Inkling engine.
Working and tested (94 tests, plus 2 real-file tests run on demand). Text, images,
the full client-side tool loop, the Anthropic endpoint and the web GUI (session
context, streaming, stats) have been validated live against the real Inkling engine.
Not yet implemented (honest gaps): forced `tool_choice` (`required` / named function
returns a clear 400), multi-slot batching, logprobs / structured output, automatic
engine restart after a crash, a full SSRF guard against DNS rebinding, and the
OpenAI Responses native endpoint. The Anthropic adapter covers the core cases but
not yet the `defer_loading` / `tool_addition` / `tool_reference` tool machinery, the
thinking `budget_tokens` mapping, or prompt-cache token accounting.
thinking `budget_tokens` mapping, or prompt-cache token accounting. The GUI is
text-chat first: images, tools and advanced settings in the GUI are still to come.
## License and credits