feat: erste Weboberfläche (nur lesend) mit Anmeldung über Key-Recht ui, Status-Endpunkt (#1048, #1049)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 09:29:02 +01:00
parent 3c4bb805d3
commit c90f17aef7
12 changed files with 886 additions and 5 deletions

View File

@ -14,6 +14,9 @@ pub struct Rights {
/// Darf `GET /gateway/v1/metrics` lesen. Ältere Keys ohne dieses Feld: nein.
#[serde(default)]
pub metrics: bool,
/// Darf sich an der Weboberfläche anmelden (nur lesend). Ältere Keys: nein.
#[serde(default)]
pub ui: bool,
}
impl Default for Rights {
@ -21,6 +24,7 @@ impl Default for Rights {
Self {
models: vec!["*".to_string()],
metrics: false,
ui: false,
}
}
}
@ -197,6 +201,7 @@ mod tests {
let r = Rights {
models: vec!["bonsai".to_string()],
metrics: false,
ui: false,
};
assert!(r.allows("bonsai"));
assert!(!r.allows("anderes"));

View File

@ -15,7 +15,7 @@ mod logs;
mod registry;
pub use keys::{ApiKeyRecord, Rights};
pub use logs::{AuditRow, RequestLogEntry, RequestLogRow};
pub use logs::{AuditRow, RequestLogEntry, RequestLogRow, RequestView};
pub use registry::{ModelEntry, NewLlm, StartPlan};
/// Alle Migrationen in Reihenfolge. Index 0 ergibt Schema-Version 1.

View File

@ -47,6 +47,23 @@ pub struct RequestLogRow {
pub aborted: bool,
}
/// Eine Zeile des Anfrage-Logs mit Namen statt IDs (für die Oberfläche).
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RequestView {
pub time: String,
pub correlation: String,
pub key: Option<String>,
pub model: Option<String>,
pub status: i64,
pub wait_ms: Option<i64>,
pub latency_ms: Option<i64>,
pub duration_ms: Option<i64>,
pub tokens_in: Option<i64>,
pub tokens_out: Option<i64>,
pub engine: Option<String>,
pub aborted: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AuditRow {
pub time: String,
@ -114,6 +131,40 @@ impl Store {
rows.collect::<rusqlite::Result<Vec<_>>>().map_err(db)
}
/// Die letzten `limit` Anfragen mit Key- und Modellnamen, neueste zuerst.
pub fn recent_request_view(&self, limit: u32) -> Result<Vec<RequestView>> {
let mut stmt = self
.connection()
.prepare(
"SELECT a.zeit, a.korrelation, k.name, m.name, a.status, a.wartezeit_ms, a.latenz_ms,
a.dauer_ms, a.tokens_ein, a.tokens_aus, a.engine, a.abgebrochen
FROM anfrage_log a
LEFT JOIN api_key k ON k.id = a.api_key_id
LEFT JOIN model m ON m.id = a.model_id
ORDER BY a.id DESC LIMIT ?1",
)
.map_err(db)?;
let rows = stmt
.query_map([limit], |r| {
Ok(RequestView {
time: r.get(0)?,
correlation: r.get(1)?,
key: r.get(2)?,
model: r.get(3)?,
status: r.get(4)?,
wait_ms: r.get(5)?,
latency_ms: r.get(6)?,
duration_ms: r.get(7)?,
tokens_in: r.get(8)?,
tokens_out: r.get(9)?,
engine: r.get(10)?,
aborted: r.get::<_, i64>(11)? != 0,
})
})
.map_err(db)?;
rows.collect::<rusqlite::Result<Vec<_>>>().map_err(db)
}
/// Löscht Anfrage-Log-Zeilen, die älter als `days` Tage sind. Liefert die
/// Zahl der gelöschten Zeilen. `0` Tage löscht nichts (unbegrenzt).
pub fn purge_requests_older_than(&self, days: u32) -> Result<usize> {
@ -292,4 +343,44 @@ mod tests {
assert_eq!(row.instance_id, Some(1));
assert!(row.aborted);
}
#[test]
fn ansicht_der_anfragen_zeigt_namen_statt_ids() {
let mut store = Store::open_in_memory().unwrap();
store
.register_llm(&NewLlm {
name: "bonsai".to_string(),
engine: "llama.cpp".to_string(),
path: PathBuf::from("/m/b.gguf"),
quantization: None,
size_bytes: None,
gpus: vec![0],
context: None,
vram_mb: None,
ram_mb: None,
enabled: true,
})
.unwrap();
let key = store
.create_api_key(
"client",
&Rights::default(),
Priority::Normal,
Priority::Normal,
)
.unwrap();
let key_id = store.find_api_key(&key).unwrap().unwrap().id;
store
.log_request(&eintrag(Some("bonsai"), Some(key_id)))
.unwrap();
store
.log_request(&eintrag(Some("unbekannt"), None))
.unwrap();
let v = store.recent_request_view(10).unwrap();
assert_eq!(v[0].model, None);
assert_eq!(v[0].key, None);
assert_eq!(v[1].model.as_deref(), Some("bonsai"));
assert_eq!(v[1].key.as_deref(), Some("client"));
assert_eq!(v[1].tokens_out, Some(34));
}
}