diff --git a/server/src/http/assets.rs b/server/src/http/assets.rs index 0a837a0..6868146 100644 --- a/server/src/http/assets.rs +++ b/server/src/http/assets.rs @@ -47,17 +47,20 @@ fn serve_embedded(path: &str) -> Response { } } +/// Serve a single embedded asset from the `assets/` folder. #[handler] pub fn embedded_asset(Path(path): Path) -> Response { let asset_path = format!("assets/{path}"); serve_embedded(&asset_path) } +/// Serve an embedded file by path (falls back to `index.html` for SPA routing). #[handler] pub fn embedded_file(Path(path): Path) -> Response { serve_embedded(&path) } +/// Serve the embedded SPA entrypoint. #[handler] pub fn embedded_index() -> Response { serve_embedded("index.html") diff --git a/server/src/http/health.rs b/server/src/http/health.rs index 7eb3bd5..e5b241d 100644 --- a/server/src/http/health.rs +++ b/server/src/http/health.rs @@ -1,5 +1,8 @@ use poem::handler; +/// Health check endpoint. +/// +/// Returns a static "ok" response to indicate the server is running. #[handler] pub fn health() -> &'static str { "ok" diff --git a/server/src/http/ws.rs b/server/src/http/ws.rs index 87fb560..4875c3c 100644 --- a/server/src/http/ws.rs +++ b/server/src/http/ws.rs @@ -10,6 +10,10 @@ use tokio::sync::mpsc; #[derive(Deserialize)] #[serde(tag = "type", rename_all = "snake_case")] +/// WebSocket request messages sent by the client. +/// +/// - `chat` starts a streaming chat session. +/// - `cancel` stops the active session. enum WsRequest { Chat { messages: Vec, @@ -20,6 +24,11 @@ enum WsRequest { #[derive(Serialize)] #[serde(tag = "type", rename_all = "snake_case")] +/// WebSocket response messages sent by the server. +/// +/// - `token` streams partial model output. +/// - `update` pushes the updated message history. +/// - `error` reports a request or processing failure. enum WsResponse { Token { content: String }, Update { messages: Vec }, @@ -27,6 +36,9 @@ enum WsResponse { } #[handler] +/// WebSocket endpoint for streaming chat responses and cancellation. +/// +/// Accepts JSON `WsRequest` messages and streams `WsResponse` messages. pub async fn ws_handler(ws: WebSocket, ctx: Data<&AppContext>) -> impl poem::IntoResponse { let ctx = ctx.0.clone(); ws.on_upgrade(move |socket| async move {