agentmux_srv/server/
http_layout.rs1use super::*;
8
9pub(super) async fn handle_layout(State(state): State<AppState>) -> impl IntoResponse {
13 let mut layout = service::agent_layout(&state.mstore);
14 pane_place::report_floaters(&state, &mut layout).await;
15 pane_measure::report_docked(&state, &mut layout).await;
16 Json(layout)
17}
18
19pub(super) async fn handle_list_windows(State(state): State<AppState>) -> impl IntoResponse {
21 Json(service::agent_windows(&state.mstore))
22}
23
24pub(super) async fn handle_list_workspaces(State(state): State<AppState>) -> impl IntoResponse {
26 Json(service::agent_workspaces(&state.mstore))
27}
28
29#[derive(serde::Deserialize)]
30pub(super) struct ListTabsQuery {
31 #[serde(default)]
33 pub(super) workspace_id: Option<String>,
34 #[serde(default)]
37 pub(super) block_id: Option<String>,
38}
39
40pub(super) async fn handle_list_tabs(
43 State(state): State<AppState>,
44 Query(q): Query<ListTabsQuery>,
45) -> impl IntoResponse {
46 let ws_id = q.workspace_id.filter(|w| !w.is_empty()).or_else(|| {
47 q.block_id
48 .filter(|b| !b.is_empty())
49 .and_then(|b| service::resolve_agent_context(&state.mstore, &b).ok())
50 .and_then(|ctx| ctx.workspace_id)
51 });
52 Json(service::agent_tabs(&state.mstore, ws_id.as_deref()))
53}
54
55pub(super) async fn handle_tab_activate(
58 State(state): State<AppState>,
59 Json(req): Json<TabActivateRequest>,
60) -> impl IntoResponse {
61 let tab_id = req.tab_id.trim().to_string();
62 if tab_id.is_empty() {
63 return (StatusCode::BAD_REQUEST, Json(json!({ "error": "missing tab_id" }))).into_response();
64 }
65 let ws_id = match service::workspace_id_for_tab(&state.mstore, &tab_id) {
66 Some(w) => w,
67 None => return (StatusCode::NOT_FOUND, Json(json!({ "error": format!("no workspace owns tab {tab_id}") }))).into_response(),
68 };
69 let call = crate::backend::service::WebCallType {
70 service: "workspace".to_string(),
71 method: "SetActiveTab".to_string(),
72 uicontext: None,
73 args: vec![json!(ws_id), json!(tab_id)],
74 };
75 finish_name_call(&state, call, json!({ "success": true, "tab_id": tab_id })).await
76}
77
78pub(super) async fn handle_tab_new(
82 State(state): State<AppState>,
83 Json(req): Json<TabNewRequest>,
84) -> impl IntoResponse {
85 let name = req.name.map(|n| n.trim().chars().take(128).collect::<String>()).unwrap_or_default();
86 let workspace_id = match req.workspace_id.filter(|w| !w.is_empty()) {
87 Some(w) => w,
88 None => match resolve_own(&state, req.block_id, |c| c.workspace_id.clone()) {
89 Ok(w) => w,
90 Err(resp) => return resp,
91 },
92 };
93 let call = crate::backend::service::WebCallType {
94 service: "workspace".to_string(),
95 method: "CreateTab".to_string(),
96 uicontext: None,
97 args: vec![json!(workspace_id), json!(name), json!(true)],
99 };
100 finish_name_call(&state, call, json!({ "success": true, "workspace_id": workspace_id })).await
101}
102
103pub(super) async fn handle_window_focus(
106 State(state): State<AppState>,
107 Json(req): Json<WindowFocusRequest>,
108) -> impl IntoResponse {
109 let window_id = match req.window_id.filter(|w| !w.is_empty()) {
110 Some(w) => w,
111 None => match resolve_own(&state, req.block_id, |c| c.window_id.clone()) {
112 Ok(w) => w,
113 Err(resp) => return resp,
114 },
115 };
116 let call = crate::backend::service::WebCallType {
117 service: "client".to_string(),
118 method: "FocusWindow".to_string(),
119 uicontext: None,
120 args: vec![json!(window_id)],
121 };
122 finish_name_call(&state, call, json!({ "success": true, "window_id": window_id })).await
123}