AppState (app/state.rs) is now lifecycle + EngineLink (client port, control channel, worker status, pool, queue timeout) + HttpPolicy (api key, CORS, trusted origins) + ModelView (name, aliases, tokenizer, template, vision port, prefix-cache and memory views) + Services (response store, monitor, MCP port, settings, clock, started_at). Field uses were rewritten mechanically (state.worker -> state.engine.worker, ...); no handler logic changed. The old impl_default_for_appstate.rs, which held the route table and the admin handlers, is app/routes.rs, app/admin_routes.rs and app/readiness.rs. main.rs (1156 lines: an 840-line argument match, the serve function, two helpers) is now 8 lines. The argument match is split into command groups under src/cli/ (operations, model_fetch, model_inspect, model_ensure, model_prepare, kar_inspect, kar_verify, kar_overlay, model_text; each owns its arms in their old order and answers Ok(false) for a line it does not own), serve() and shutdown_signal() are src/serve.rs (the composition root), the usage text is cli/usage.rs. The binary name and every command line are unchanged. Architecture gate: control-plane/src/main.rs leaves the oversize list (1156 -> 8). --allow-increase was used because the type change forces the AppState struct literals in seven already-oversize test/example files to nest by group: cp_replay.rs +7, responses/tests.rs +11, backend_worker_http.rs +14, mcp_hub.rs +3, memory_gate_http.rs +7, vision_http.rs +6, desktop-core api_over_runtime.rs +6 (55 lines in all, against 1148 lines removed from main.rs). Test outcomes are unchanged (597 ok / 2 ignored before and after, 14 new tests from S16).
52 lines
1.1 KiB
Rust
52 lines
1.1 KiB
Rust
use axum::{
|
|
Json, Router,
|
|
extract::{DefaultBodyLimit, RawQuery, State},
|
|
http::{HeaderMap, StatusCode},
|
|
middleware,
|
|
response::{IntoResponse, Response},
|
|
routing::{get, post},
|
|
};
|
|
use serde::Serialize;
|
|
|
|
use crate::{
|
|
responses,
|
|
worker::{WorkerState, WorkerStatus},
|
|
};
|
|
|
|
#[derive(Serialize)]
|
|
struct HealthResponse {
|
|
status: &'static str,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
struct StatusResponse {
|
|
service: &'static str,
|
|
server_pid: u32,
|
|
model: Option<String>,
|
|
version: &'static str,
|
|
worker: WorkerState,
|
|
ready: bool,
|
|
max_context: Option<usize>,
|
|
}
|
|
|
|
/// The generations shown by default in `requests` (the Python Monitor shows twelve).
|
|
const RECENT_REQUESTS: usize = 12;
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|
|
|
|
mod state;
|
|
pub use state::{AppState, EngineLink, HttpPolicy, ModelView, Services};
|
|
mod routes;
|
|
#[allow(unused_imports)]
|
|
pub use routes::*;
|
|
mod admin_routes;
|
|
#[allow(unused_imports)]
|
|
pub use admin_routes::*;
|
|
mod readiness;
|
|
#[allow(unused_imports)]
|
|
pub use readiness::*;
|
|
mod metrics_document;
|
|
#[allow(unused_imports)]
|
|
pub use metrics_document::*;
|