Added some API doc comments

This commit is contained in:
Dave
2026-02-16 16:55:59 +00:00
parent feb05dc8d0
commit dae772e619
3 changed files with 18 additions and 0 deletions

View File

@@ -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<String>) -> 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<String>) -> Response {
serve_embedded(&path)
}
/// Serve the embedded SPA entrypoint.
#[handler]
pub fn embedded_index() -> Response {
serve_embedded("index.html")

View File

@@ -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"

View File

@@ -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<Message>,
@@ -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<Message> },
@@ -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 {