Skip to main content

cortiq_server/
lib.rs

1//! Cortiq Server — OpenAI-compatible API + web management dashboard.
2
3pub mod api;
4pub mod dashboard;
5pub mod openai;
6pub mod streaming;
7
8use axum::{routing::get, Json, Router};
9use cortiq_engine::{CortiqRuntime, Pipeline};
10use std::sync::Arc;
11use tokio::sync::Mutex;
12use tower_http::cors::CorsLayer;
13
14/// Shared application state: runtime (masks, metrics) + the inference
15/// pipeline behind a Mutex (single-sequence decode; requests queue).
16pub struct AppState {
17    pub runtime: CortiqRuntime,
18    pub pipeline: Mutex<Pipeline>,
19}
20
21/// Liveness probe — returns 200 as soon as the server is accepting
22/// connections. Used by process managers that embed `cortiq serve` (e.g.
23/// a gateway spawning it as a local model server) to know when it is ready.
24async fn healthz() -> Json<serde_json::Value> {
25    Json(serde_json::json!({ "status": "ok" }))
26}
27
28/// Build the full router with all endpoints.
29pub fn build_router(state: Arc<AppState>) -> Router {
30    Router::new()
31        .route("/healthz", get(healthz))
32        .merge(openai::routes())
33        .merge(api::routes())
34        .merge(dashboard::routes())
35        .layer(CorsLayer::permissive())
36        .with_state(state)
37}