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

+20 -2
View File
@@ -8,10 +8,11 @@ use std::path::Path;
use std::process::ExitCode;
use std::sync::Arc;
use strata_ctl::api::{router_with_auth, AuthConfig, ChatService};
use strata_ctl::api::{router_with_store, AuthConfig, ChatService};
use strata_ctl::config::{Config, ConfigError};
use strata_ctl::engine::Engine;
use strata_ctl::inkling::{ChatTemplate, InklingFormatter, InklingTokenizer};
use strata_ctl::store::{SqliteStore, Store};
const USAGE: &str = "\
strata-ctl — Rust control layer for the Strata engine (OpenAI-compatible API)
@@ -175,7 +176,20 @@ async fn serve(cfg: &Config, cli_host: Option<&str>, cli_port: Option<u16>) -> E
api_key: cfg.api_key.clone(),
allowed_hosts: cfg.allowed_hosts.clone().unwrap_or_default(),
};
let app = router_with_auth(svc, auth);
// Open the GUI session store (SQLite). The web GUI + session API are mounted
// only when this succeeds; the standard /v1 API is unaffected either way.
let db_path = cfg.gui_db_path();
let store: Arc<dyn Store> = match SqliteStore::open(&db_path) {
Ok(s) => Arc::new(s),
Err(e) => {
eprintln!(
"error: cannot open session database {}: {e}",
db_path.display()
);
return ExitCode::FAILURE;
}
};
let app = router_with_store(svc, store, auth);
let host = cfg.bind_host(cli_host);
let port = cfg.bind_port(cli_port);
if !is_loopback_host(&host) && cfg.api_key.is_none() {
@@ -194,6 +208,10 @@ async fn serve(cfg: &Config, cli_host: Option<&str>, cli_port: Option<u16>) -> E
}
};
println!("listening on http://{addr} (Ctrl-C to stop)");
println!(
"web GUI: http://{addr}/ (sessions db: {})",
db_path.display()
);
let shutdown_engine = engine.clone();
let result = axum::serve(listener, app)