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:
@ -18,6 +18,7 @@ mod models;
|
||||
mod runtime;
|
||||
mod state;
|
||||
mod tap;
|
||||
mod ui;
|
||||
mod usage;
|
||||
|
||||
use std::sync::Arc;
|
||||
@ -45,6 +46,8 @@ pub fn router(state: Arc<AppState>) -> Router {
|
||||
.route("/v1/chat/completions", post(chat::completions))
|
||||
.route("/gateway/v1/health", get(health))
|
||||
.route("/gateway/v1/metrics", get(metrics_endpoint))
|
||||
.route("/gateway/v1/status", get(status_endpoint))
|
||||
.merge(ui::routes())
|
||||
.fallback(not_found)
|
||||
.layer(DefaultBodyLimit::max(MAX_BODY_BYTES))
|
||||
.layer(middleware::from_fn_with_state(
|
||||
@ -76,6 +79,50 @@ async fn metrics_endpoint(
|
||||
))
|
||||
}
|
||||
|
||||
/// Zustand des Gateways als JSON (für die Oberfläche und Skripte); für Keys
|
||||
/// mit dem Recht `metrics` oder `ui`.
|
||||
async fn status_endpoint(
|
||||
axum::extract::State(state): axum::extract::State<Arc<AppState>>,
|
||||
auth::Authed(key): auth::Authed,
|
||||
) -> Result<impl IntoResponse, ApiError> {
|
||||
if !key.rights.metrics && !key.rights.ui {
|
||||
return Err(ApiError::new(
|
||||
StatusCode::FORBIDDEN,
|
||||
"invalid_request_error",
|
||||
"permission_denied",
|
||||
"Dieser Key hat weder das Recht \"metrics\" noch \"ui\".",
|
||||
));
|
||||
}
|
||||
let instances = state.runtime.metrics.instances();
|
||||
let models: Vec<serde_json::Value> = {
|
||||
let store = state.store();
|
||||
store
|
||||
.list_models(false)
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(|m| {
|
||||
let plan = store.start_plan(&m.name).ok().flatten();
|
||||
serde_json::json!({
|
||||
"name": m.name,
|
||||
"enabled": m.enabled,
|
||||
"engine": plan.as_ref().map(|p| p.engine_name.clone()),
|
||||
"gpus": plan.as_ref().map(|p| p.gpus.clone()),
|
||||
"context": plan.as_ref().and_then(|p| p.context),
|
||||
"loaded": instances.iter().any(|i| i.model == m.name),
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
Ok(axum::Json(serde_json::json!({
|
||||
"version": nexus_core::VERSION,
|
||||
"uptime_s": state.started.elapsed().as_secs(),
|
||||
"totals": state.runtime.metrics.totals(),
|
||||
"instances": instances,
|
||||
"gpus": state.runtime.metrics.gpus(),
|
||||
"models": models,
|
||||
})))
|
||||
}
|
||||
|
||||
async fn health() -> impl IntoResponse {
|
||||
axum::Json(serde_json::json!({ "status": "ok", "version": nexus_core::VERSION }))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user