Added some API doc comments
This commit is contained in:
@@ -47,17 +47,20 @@ fn serve_embedded(path: &str) -> Response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Serve a single embedded asset from the `assets/` folder.
|
||||||
#[handler]
|
#[handler]
|
||||||
pub fn embedded_asset(Path(path): Path<String>) -> Response {
|
pub fn embedded_asset(Path(path): Path<String>) -> Response {
|
||||||
let asset_path = format!("assets/{path}");
|
let asset_path = format!("assets/{path}");
|
||||||
serve_embedded(&asset_path)
|
serve_embedded(&asset_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Serve an embedded file by path (falls back to `index.html` for SPA routing).
|
||||||
#[handler]
|
#[handler]
|
||||||
pub fn embedded_file(Path(path): Path<String>) -> Response {
|
pub fn embedded_file(Path(path): Path<String>) -> Response {
|
||||||
serve_embedded(&path)
|
serve_embedded(&path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Serve the embedded SPA entrypoint.
|
||||||
#[handler]
|
#[handler]
|
||||||
pub fn embedded_index() -> Response {
|
pub fn embedded_index() -> Response {
|
||||||
serve_embedded("index.html")
|
serve_embedded("index.html")
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
use poem::handler;
|
use poem::handler;
|
||||||
|
|
||||||
|
/// Health check endpoint.
|
||||||
|
///
|
||||||
|
/// Returns a static "ok" response to indicate the server is running.
|
||||||
#[handler]
|
#[handler]
|
||||||
pub fn health() -> &'static str {
|
pub fn health() -> &'static str {
|
||||||
"ok"
|
"ok"
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ use tokio::sync::mpsc;
|
|||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(tag = "type", rename_all = "snake_case")]
|
#[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 {
|
enum WsRequest {
|
||||||
Chat {
|
Chat {
|
||||||
messages: Vec<Message>,
|
messages: Vec<Message>,
|
||||||
@@ -20,6 +24,11 @@ enum WsRequest {
|
|||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(tag = "type", rename_all = "snake_case")]
|
#[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 {
|
enum WsResponse {
|
||||||
Token { content: String },
|
Token { content: String },
|
||||||
Update { messages: Vec<Message> },
|
Update { messages: Vec<Message> },
|
||||||
@@ -27,6 +36,9 @@ enum WsResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[handler]
|
#[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 {
|
pub async fn ws_handler(ws: WebSocket, ctx: Data<&AppContext>) -> impl poem::IntoResponse {
|
||||||
let ctx = ctx.0.clone();
|
let ctx = ctx.0.clone();
|
||||||
ws.on_upgrade(move |socket| async move {
|
ws.on_upgrade(move |socket| async move {
|
||||||
|
|||||||
Reference in New Issue
Block a user