huskies: merge 770
This commit is contained in:
@@ -82,6 +82,7 @@ pub fn build_routes(
|
||||
.nest("/docs", docs_service.swagger_ui())
|
||||
.at("/ws", get(ws::ws_handler))
|
||||
.at("/crdt-sync", get(crate::crdt_sync::crdt_sync_handler))
|
||||
.at("/rpc", post(rpc_http_handler))
|
||||
.at(
|
||||
"/agents/:story_id/:agent_name/stream",
|
||||
get(agents_sse::agent_stream),
|
||||
@@ -133,6 +134,28 @@ pub fn build_routes(
|
||||
route.data(ctx_arc)
|
||||
}
|
||||
|
||||
/// HTTP bridge for the read-RPC protocol.
|
||||
///
|
||||
/// Accepts a JSON [`RpcFrame::RpcRequest`] body and returns the corresponding
|
||||
/// [`RpcFrame::RpcResponse`]. This allows HTTP clients (e.g. the frontend) to
|
||||
/// call read-RPC methods without maintaining a `/crdt-sync` WebSocket connection.
|
||||
#[poem::handler]
|
||||
pub async fn rpc_http_handler(body: poem::web::Json<serde_json::Value>) -> poem::Response {
|
||||
let text = serde_json::to_string(&body.0).unwrap_or_default();
|
||||
match crate::crdt_sync::try_handle_rpc_text(&text) {
|
||||
Some(response) => {
|
||||
let json = serde_json::to_string(&response).unwrap_or_default();
|
||||
poem::Response::builder()
|
||||
.status(poem::http::StatusCode::OK)
|
||||
.header(poem::http::header::CONTENT_TYPE, "application/json")
|
||||
.body(json)
|
||||
}
|
||||
None => poem::Response::builder()
|
||||
.status(poem::http::StatusCode::BAD_REQUEST)
|
||||
.body("Invalid RPC request"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Debug HTTP endpoint: `GET /debug/crdt[?story_id=<id>]`
|
||||
///
|
||||
/// Returns the raw in-memory CRDT state as JSON. Accepts an optional
|
||||
|
||||
Reference in New Issue
Block a user