agentmux_srv/server/
browser_scroll.rs1use axum::extract::State;
8use axum::http::StatusCode;
9use axum::response::IntoResponse;
10use axum::Json;
11use serde_json::json;
12
13use crate::server::ui_handlers::{err_response, get_host_ipc, proxy_to_host_timeout, target_block_id};
14use crate::server::AppState;
15
16const HOST_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(15);
18
19pub(crate) async fn handle_ui_browser_scroll(
20 State(state): State<AppState>,
21 caller: Option<axum::Extension<crate::server::caller::Caller>>,
22 Json(req): Json<agentmux_common::browser_control_types::UiBrowserScrollRequest>,
23) -> impl IntoResponse {
24 let block_id = match target_block_id(&state, caller.as_deref(), &req.auth, req.pane.as_deref()) {
25 Ok(b) => b,
26 Err((code, e)) => return err_response(code, e),
27 };
28 let host = match get_host_ipc(&state).await {
29 Ok(h) => h,
30 Err(e) => return err_response(StatusCode::SERVICE_UNAVAILABLE, e),
31 };
32 let body = json!({ "block_id": block_id, "ref": req.ref_, "dx": req.dx, "dy": req.dy });
33 let host_resp = match proxy_to_host_timeout(&state, &host, "scroll", body, Some(HOST_TIMEOUT)).await {
34 Ok(v) => v,
35 Err(e) => return err_response(StatusCode::BAD_GATEWAY, e),
36 };
37 if host_resp.get("ok").and_then(|v| v.as_bool()) != Some(true) {
38 let err = host_resp.get("error").and_then(|v| v.as_str()).unwrap_or("unknown host error").to_string();
39 return err_response(StatusCode::BAD_REQUEST, err);
40 }
41 tracing::info!(agent_id = %req.auth.agent_id, block_id = %block_id, "[ui-automation] browser scroll");
42 (StatusCode::OK, Json(json!({ "ok": true, "data": host_resp.get("data").cloned().unwrap_or_default() }))).into_response()
43}