1use super::*;
8use super::agent_only;
9use super::route_table::declared_routes;
10use agentmux_common::AUTH_KEY_HEADER;
11
12pub struct SrvRouters {
19 pub full: Router,
20 pub lan: Router,
21 pub container: Router,
25}
26
27#[cfg(test)]
29pub fn build_router(state: AppState) -> Router {
30 build_routers(state).full
31}
32
33pub fn build_routers(state: AppState) -> SrvRouters {
35 build_routers_with(state, crate::headless::frontend_dir())
36}
37
38pub(crate) fn build_routers_with(state: AppState, frontend_dir: Option<&std::path::Path>) -> SrvRouters {
41 let cors = cors_layer();
42
43 super::remote_ops::receive::mark_started();
44 let lan_forward_routes = lan_forward_routes(&state);
45 let authed_routes = authed_routes(&state);
46
47 let health = root_health_route().merge(health_route());
51 let full_health = if frontend_dir.is_some() { health_route() } else { health.clone() };
52
53 let whatsapp_webhooks = whatsapp_webhooks();
64
65 let version_for_header = state.version.clone();
74 let version_header = axum::middleware::from_fn(move |req: axum::extract::Request, next: axum::middleware::Next| {
75 let version = version_for_header.clone();
76 async move {
77 let mut response = next.run(req).await;
78 if let Ok(value) = axum::http::HeaderValue::from_str(&version) {
79 response.headers_mut().insert("x-agentmux-srv-version", value);
80 }
81 response
82 }
83 });
84
85 let lan = Router::new()
86 .merge(health.clone())
87 .merge(whatsapp_webhooks.clone())
88 .merge(lan_forward_routes.clone())
89 .layer(version_header.clone())
90 .layer(cors.clone())
91 .with_state(state.clone());
92
93 let widget_files = widget_files_routes();
97
98 let model_gateway = model_gateway_route();
101
102 let sign_in = if super::local_session_routes::enabled() { super::local_session_routes::routes() } else { Router::new() };
104
105 let local_hook = local_hook_route();
108
109 let full = Router::new()
110 .merge(full_health)
111 .merge(local_hook)
112 .merge(sign_in)
113 .merge(widget_files)
114 .merge(model_gateway)
115 .merge(whatsapp_webhooks)
116 .merge(lan_forward_routes)
117 .merge(authed_routes);
118 let full = match frontend_dir {
122 Some(dir) => with_frontend(full, dir),
123 None => full,
124 };
125 let full = full.layer(version_header).layer(cors).with_state(state.clone());
126 let container = crate::backend::container::listener::layer_reporting(
127 full.clone(),
128 crate::backend::container::listener::current_subnet,
129 super::model_gateway_key::foreign_use_reporter(state),
130 super::route_table::serves,
131 );
132
133 SrvRouters { full, lan, container }
134}
135
136declared_routes! {
137 fn root_health_route, ROOT_HEALTH_ROUTE;
139 GET "/" => health_handler;
140}
141
142declared_routes! {
143 fn health_route, HEALTH_ROUTE;
145 GET "/health" => health_handler;
146}
147
148declared_routes! {
149 fn model_gateway_route, MODEL_GATEWAY_ROUTE;
151 ANY "/api/v1/model/:route/*tail" => super::model_gateway_handlers::handle_model_gateway;
152}
153
154declared_routes! {
155 fn local_hook_route, LOCAL_HOOK_ROUTE;
157 POST "/agentmux/hook/:job", Always => super::hook_handlers::handle_hook, layer(axum::extract::DefaultBodyLimit::max(crate::backend::jobs::webhook_local::MAX_BODY));
158}
159
160fn cors_layer() -> CorsLayer {
162 use tower_http::cors::AllowOrigin;
179 CorsLayer::new()
180 .allow_origin(AllowOrigin::predicate(|origin, _req| {
181 origin.to_str().is_ok_and(is_allowed_origin)
182 }))
183 .allow_methods(Any)
184 .allow_headers(vec![
185 header::CONTENT_TYPE,
186 header::AUTHORIZATION,
187 header::ACCEPT,
188 "X-Session-Id".parse().unwrap(),
189 AUTH_KEY_HEADER.parse().unwrap(),
190 "X-Requested-With".parse().unwrap(),
191 "x-vercel-ai-ui-message-stream".parse().unwrap(),
192 header::RANGE,
196 ])
197 .expose_headers(vec!["X-ZoneFileInfo".parse().unwrap(), "X-ZoneFileOffset".parse().unwrap(), header::CONTENT_RANGE])
219}
220
221declared_routes! {
222 fn lan_forward_routes_declared, LAN_FORWARD_ROUTES;
224 POST "/agentmux/reactive/inject", Handler => reactive::handle_reactive_inject;
225 POST "/agentmux/remote/op", Always => super::remote_ops::receive::handle_remote_op;
228 POST "/agentmux/reactive/inject-files", Handler => super::jekt_files::handle_reactive_inject_files;
231 GET "/agentmux/reactive/agent" => reactive::handle_reactive_agent;
232 GET "/agentmux/reactive/agent-names" => reactive::handle_reactive_agent_names;
236 GET "/agentmux/agent/holding" => agent_takeover::handle_agent_holding;
238 GET "/agentmux/fleet" => handle_fleet;
241 GET "/agentmux/fleet/events" => handle_fleet_events;
242}
243
244fn lan_forward_routes(state: &AppState) -> Router<AppState> {
255 lan_forward_routes_declared()
256 .route_layer(middleware::from_fn_with_state(state.clone(), super::http_action::record_action))
258 .route_layer(middleware::from_fn_with_state(state.clone(), caller::caller_middleware))
261 .route_layer(middleware::from_fn_with_state(state.clone(), lan_or_full_auth_middleware))
262 .route_layer(middleware::from_fn_with_state(state.clone(), super::lan_watch::watch))
265}
266
267declared_routes! {
268 fn reactive_routes, REACTIVE_ROUTES;
277 GET "/agentmux/reactive/agents" => reactive::handle_reactive_agents;
278 GET "/agentmux/reactive/audit" => reactive::handle_reactive_audit;
279 POST "/agentmux/audit/own", Never => app_api::audit_query::handle_audit_own;
284 POST "/agentmux/reactive/register", Always => reactive::handle_reactive_register;
285 POST "/agentmux/agent/release", Always => agent_takeover::handle_agent_release;
287 POST "/agentmux/reactive/unregister", Always => pane_binding::handle_unregister;
288 POST "/agentmux/agents/resolve", Never => name_resolution::handle_resolve_agent_name;
291 POST "/agentmux/reactive/ensure-signing-key", Always => reactive::handle_reactive_ensure_signing_key;
292 GET "/agentmux/reactive/poller/stats" => reactive::handle_reactive_poller_stats;
293 POST "/agentmux/reactive/poller/config", Always => reactive::handle_reactive_poller_config;
294 GET "/agentmux/reactive/poller/status" => reactive::handle_reactive_poller_status;
295 GET "/agentmux/reactive/transcript" => reactive::handle_reactive_transcript;
296 GET "/agentmux/reactive/history/search" => reactive::handle_reactive_history_search;
302}
303
304declared_routes! {
305 fn agent_routes_declared, AGENT_ROUTES;
307 POST "/agentmux/jobs", Always => cron::handle_cron_create;
308 DELETE "/agentmux/jobs/:id", Always => cron::handle_cron_delete;
309 PATCH "/agentmux/jobs/:id", Always => cron::handle_cron_patch;
310 POST "/agentmux/jobs/:id/run", Always => cron::handle_cron_run_now;
311 POST "/agentmux/jobs/runs/:run_id/report", Always => cron::handle_cron_report;
312 POST "/agentmux/cron", Always => cron::handle_cron_create;
313 DELETE "/agentmux/cron/:id", Always => cron::handle_cron_delete;
314 PATCH "/agentmux/cron/:id", Always => cron::handle_cron_patch;
315 POST "/agentmux/cron/:id/run", Always => cron::handle_cron_run_now;
316 POST "/agentmux/cron/runs/:run_id/report", Always => cron::handle_cron_report;
317 POST "/agentmux/work", Always => work_queue::handle_work_enqueue;
318 POST "/agentmux/work/claim", Always => bulletin_handlers::handle_work_claim_with_bulletins;
319 POST "/agentmux/work/boards", Always => work_boards::handle_boards_act;
320 POST "/agentmux/work/:id/heartbeat", Always => work_queue::handle_work_heartbeat;
321 POST "/agentmux/work/:id/complete", Always => work_queue::handle_work_complete;
322 POST "/agentmux/work/:id/release", Always => work_queue::handle_work_release;
323 POST "/agentmux/work/:id/update", Always => work_tasks::handle_work_update;
324 POST "/agentmux/work/:id/ask", Always => work_tasks::handle_work_ask;
325 POST "/agentmux/work/:id/submit", Always => work_tasks::handle_work_submit;
326 POST "/agentmux/work/:id/hold", Always => work_tasks::handle_work_hold;
327 POST "/agentmux/work/:id/unhold", Always => work_tasks::handle_work_unhold;
328 POST "/agentmux/work/act", Always => work_act::handle_work_act;
329 POST "/api/v1/sensitive/:action", Always => sensitive_handlers::handle_sensitive;
332 POST "/api/v1/drone/:action", Always => drone_agent::handle_drone;
335 POST "/api/v1/ui/zoom/:action", Always => zoom::handle_zoom;
337 POST "/api/v1/work-claims", Always => work_claims_handlers::handle_claim_work;
340 POST "/api/v1/work-claims/release", Always => work_claims_handlers::handle_release_work;
341 POST "/api/v1/agent/status", Always => agent_status_handlers::handle_agent_status;
343 POST "/api/v1/agent/keep-running", Always => app_api::workspace_stop::handle_keep_running;
345 POST "/api/v1/coord/posts", Always => coord_channel_handlers::handle_post_to_channel;
346 POST "/api/v1/bulletin", Always => bulletin_handlers::handle_post_bulletin;
347 GET "/api/v1/bulletin" => bulletin_handlers::handle_read_bulletin;
348 POST "/api/v1/quota-mode", Always => quota_mode_handler::handle_set_quota_mode;
349 GET "/api/v1/quota-mode" => quota_mode_handler::handle_get_quota_mode;
350}
351
352fn agent_routes(state: &AppState) -> Router<AppState> {
360 agent_routes_declared()
361 .route_layer(middleware::from_fn_with_state(state.clone(), agent_only::require_agent_token))
362}
363
364declared_routes! {
365 fn bus_routes, BUS_ROUTES;
367 POST "/api/bus/register", Always => messagebus::handle_register;
368 POST "/api/bus/send", Always => messagebus::handle_send;
369 POST "/api/bus/inject", Always => messagebus::handle_inject;
370 POST "/api/bus/broadcast", Always => messagebus::handle_broadcast;
371 GET "/api/bus/messages" => messagebus::handle_read_messages;
372 POST "/api/bus/messages/delete", Always => messagebus::handle_delete_messages;
373 GET "/api/bus/agents" => messagebus::handle_list_agents;
374}
375
376declared_routes! {
377 fn os_link_routes, OS_LINK_ROUTES;
380 POST "/api/v1/host/deeplink_open", Handler => super::deeplink_os::handle_os_open_link;
382}
383
384fn authed_routes(state: &AppState) -> Router<AppState> {
386 Router::new()
387 .merge(service_shell_and_vault_routes())
388 .merge(streamed_browser_routes())
389 .merge(agent_api_routes())
390 .merge(muxspect_routes())
391 .merge(memory_and_identity_routes())
392 .merge(ui_and_host_routes())
393 .merge(agent_self_and_fleet_routes())
394 .merge(forward_messaging_and_work_routes())
395 .merge(bus_routes())
396 .merge(os_link_routes())
397 .merge(agent_routes(state))
398 .merge(reactive_routes())
399 .route_layer(middleware::from_fn_with_state(state.clone(), super::http_action::record_action))
400 .route_layer(middleware::from_fn_with_state(
402 state.clone(),
403 caller::caller_middleware,
404 ))
405 .route_layer(middleware::from_fn_with_state(
406 state.clone(),
407 auth_middleware,
408 ))
409}
410
411declared_routes! {
412 fn streamed_browser_routes, STREAMED_BROWSER_ROUTES;
414 GET "/agentmux/streamed-browser" => super::streamed_browser::handle, route_layer(middleware::from_fn(ws_origin_guard));
415}
416
417declared_routes! {
418 fn service_shell_and_vault_routes_declared, SERVICE_SHELL_AND_VAULT_ROUTES;
420 GET "/ws" => websocket::handle_ws, route_layer(middleware::from_fn(ws_origin_guard));
421 POST "/agentmux/service", Plumbing => service::handle_service;
422 GET "/agentmux/file" => files::handle_mux_file;
423 GET "/agentmux/stream-file" => stub_501;
424 GET "/agentmux/stream-file/*path" => stub_501;
425 GET "/agentmux/stream-local-file" => files::handle_stream_local_file;
426 GET "/agentmux/file-icon" => super::file_icons::handle_file_icon;
427 GET "/api/post-chat-message" => stub_501;
428 POST "/api/post-chat-message", Never => stub_501;
429 GET "/docsite/*path" => files::handle_docsite;
430 GET "/schema/*path" => files::handle_schema;
431 GET "/api/lan-instances" => handle_lan_instances;
432 GET "/agentmux/discovery" => super::live_facts::handler::handle;
433 GET "/agentmux/old-versions" => super::old_versions_handlers::handle_get;
434 POST "/agentmux/old-versions", Always => super::old_versions_handlers::handle_post;
435 GET "/agentmux/reactive/availability" => super::availability_view::handle_availability;
436 GET "/agentmux/diag/sagas" => handle_diag_sagas;
437 POST "/agentmux/wps/publish", Never => handle_wps_publish;
443 POST "/api/v1/agent/tool-chunk", Never => container_tool_chunk::handle_container_tool_chunk, layer(axum::extract::DefaultBodyLimit::max(container_tool_chunk::MAX_BODY_BYTES));
446 POST "/api/v1/agent/compaction-started", Never => container_compaction_started::handle_container_compaction_started, layer(axum::extract::DefaultBodyLimit::max(container_compaction_started::MAX_BODY_BYTES));
448 POST "/api/v1/shell/create", Always => handle_shell_create;
453 POST "/api/v1/shell/stop", Always => handle_shell_stop;
456 POST "/api/v1/shell/input", Always => handle_shell_input;
458 POST "/api/v1/shell/status", Never => handle_shell_status;
460 POST "/api/v1/shell/output", Never => handle_shell_output;
461 POST "/api/v1/ptyshell/create", Always => handle_pty_shell_create;
466 POST "/api/v1/ptyshell/input", Always => handle_pty_shell_input;
467 POST "/api/v1/ptyshell/resize", Always => handle_pty_shell_resize;
468 POST "/api/v1/ptyshell/read", Never => handle_pty_shell_read;
469 POST "/api/v1/ptyshell/status", Never => handle_pty_shell_status;
470 POST "/api/v1/ptyshell/stop", Always => handle_pty_shell_stop;
471 POST "/api/v1/pane/open", Always => handle_pane_open;
476 POST "/api/v1/pane/open_link", Handler => super::deeplink_guard::handle_pane_open_link;
481 GET "/api/v1/widgets" => super::widget_agent_handlers::handle_widgets_list;
484 POST "/api/v1/widgets/install", Always => super::widget_agent_handlers::handle_widgets_install;
485 POST "/api/v1/ui/browser/vault_fill", Always => super::browser_vault_fill::handle_vault_fill;
487 POST "/api/v1/ui/browser/signin", Always => super::browser_signin::handle_signin;
489 POST "/api/v1/ui/browser/generate_password", Always => super::browser_account::handle_generate_password;
491 POST "/api/v1/ui/browser/capture", Always => super::browser_capture::handle_capture;
492}
493
494fn service_shell_and_vault_routes() -> Router<AppState> {
496 service_shell_and_vault_routes_declared()
497 .merge(super::vault_routes::vault_routes())
499 .merge(google_agent_routes())
500}
501
502declared_routes! {
503 fn agent_api_routes, AGENT_API_ROUTES;
505 POST "/api/v1/agent/open", Always => handle_agent_open;
514 POST "/api/v1/agent/open_view", Always => app_api::remote_pane_view::handle_agent_open_view;
516 POST "/api/v1/agent/spawn", Always => app_api::agent_spawn::handle_agent_spawn;
520 POST "/api/v1/agent/spawn_many", Always => app_api::agent_spawn::handle_agent_spawn_many;
521 POST "/api/v1/agent/create", Always => app_api::agent_spawn::handle_agent_create;
522 POST "/api/v1/agent/import", Handler => app_api::agent_spawn::handle_agent_import;
523 POST "/api/v1/agent/open_many", Always => app_api::agent_open_many::handle_agent_open_many;
524 POST "/api/v1/agent/container/update", Always => app_api::container_update::handle_update_container;
527 POST "/api/v1/agent/container/limits", Always => app_api::container_limits::handle_container_limits;
529 POST "/api/v1/agent/container/caches", Always => app_api::container_caches::handle_container_caches;
531 POST "/api/v1/agent/workers", Never => app_api::agent_spawn::handle_agent_workers;
533 POST "/api/v1/agent/routes", Never => app_api::agent_routes::handle_agent_routes;
534 POST "/api/v1/agent/start", Always => app_api::agent_lifecycle::handle_agent_start;
536 POST "/api/v1/agent/stop", Always => app_api::agent_lifecycle::handle_agent_stop;
537 POST "/api/v1/agent/mute-quiet", Always => app_api::agent_mute_quiet::handle_agent_mute_quiet;
539 POST "/api/v1/agent/detach", Always => app_api::agent_lifecycle::handle_agent_detach;
540 POST "/api/v1/agent/rotate-token", Always => app_api::agent_rotate_token::handle_agent_rotate_token;
541 POST "/api/v1/agent/delete", Always => app_api::agent_lifecycle::handle_agent_delete;
543 POST "/api/v1/agent/watch", Never => app_api::agent_watch::handle_agent_watch;
545 POST "/api/v1/agent/takeover", Always => pane_binding::handle_takeover;
547 POST "/api/v1/voice/transcribe", Plumbing => voice::handle_voice_transcribe;
552 GET "/api/v1/voice/status" => voice::handle_voice_status;
553 POST "/api/v1/attachments/upload", Plumbing => attachments::handle_attachment_upload;
557 GET "/api/v1/attachments/:id/:kind" => attachments::handle_attachment_file;
558 POST "/agentmux/work/media", Always => work_media::handle_work_media_upload;
562 GET "/api/v1/self" => handle_self;
567 GET "/api/v1/conn/list" => app_api::connections::handle_conn_list;
570 POST "/api/v1/askpass", Never => app_api::connections::handle_askpass;
573 POST "/api/v1/window/name", Always => handle_window_name;
574 POST "/api/v1/tab/name", Always => handle_tab_name;
578 POST "/api/v1/pane/title", Always => handle_pane_title;
579 POST "/api/v1/workspace/name", Always => handle_workspace_name;
580 POST "/api/v1/file/rename", Always => handle_file_rename;
583 GET "/api/v1/layout" => handle_layout;
587 GET "/api/v1/windows" => handle_list_windows;
588 GET "/api/v1/workspaces" => handle_list_workspaces;
589 GET "/api/v1/tabs" => handle_list_tabs;
590 POST "/api/v1/tab/activate", Always => handle_tab_activate;
594 POST "/api/v1/tab/new", Always => handle_tab_new;
595 POST "/api/v1/window/focus", Always => handle_window_focus;
596 POST "/api/v1/pane/place", Always => super::pane_place::handle_pane_place;
599}
600
601declared_routes! {
602 fn muxspect_routes_declared, MUXSPECT_ROUTES;
604 GET "/api/v1/muxspect/instances" => muxspect_instances::handle_muxspect_instances;
607 GET "/api/v1/muxspect/find" => muxspect_handlers::handle_muxspect_find;
613 POST "/api/v1/muxspect/dock/clear", Always => muxspect_handlers::handle_muxspect_dock_clear;
616 GET "/api/v1/muxspect/migrations" => muxspect_handlers::handle_muxspect_migrations;
620 GET "/api/v1/muxspect/memory" => super::muxspect_memory::handle_muxspect_memory;
623 GET "/api/v1/muxspect/conversations" => muxspect_handlers::handle_muxspect_conversations;
627 GET "/api/v1/work-facts" => work_facts_handlers::handle_work_facts;
630 GET "/api/v1/work-facts/who" => work_facts_handlers::handle_who_is_working_on;
631 GET "/api/v1/message-stats" => message_stats_handler::handle_message_stats;
633 GET "/api/v1/message-flow" => message_flow_handler::handle_message_flow;
635 GET "/api/v1/containers" => containers_handler::handle_containers;
637 GET "/api/v1/task-flow" => task_flow_handler::handle_task_flow;
639 GET "/api/v1/pr-flow" => pr_flow_handler::handle_pr_flow;
642 GET "/api/v1/reviews" => reviews_handler::handle_reviews;
644 GET "/api/v1/coord/posts" => coord_channel_handlers::handle_read_channel;
649}
650
651fn muxspect_routes() -> Router<AppState> {
653 muxspect_routes_declared()
654 .merge(forwardable_muxspect_routes())
655}
656
657declared_routes! {
658 fn forwardable_muxspect_routes_declared, FORWARDABLE_MUXSPECT_ROUTES;
660 GET "/api/v1/muxspect/list" => muxspect_handlers::handle_muxspect_list;
664 GET "/api/v1/muxspect/layout" => muxspect_handlers::handle_muxspect_layout;
665 GET "/api/v1/muxspect/describe" => muxspect_handlers::handle_muxspect_describe;
666 GET "/api/v1/muxspect/browsers" => muxspect_browsers::handle_muxspect_browsers;
668 GET "/api/v1/muxspect/dock" => muxspect_handlers::handle_muxspect_dock;
670 GET "/api/v1/muxspect/background-tasks" => muxspect_handlers::handle_muxspect_background_tasks;
672 GET "/api/v1/muxspect/verify-sender" => muxspect_handlers::handle_muxspect_verify_sender;
674}
675
676fn forwardable_muxspect_routes() -> Router<AppState> {
681 forwardable_muxspect_routes_declared()
682 .route_layer(axum::middleware::from_fn(muxspect_instances::forward_to_channel))
683}
684
685declared_routes! {
686 fn memory_and_identity_routes, MEMORY_AND_IDENTITY_ROUTES;
688 GET "/api/v1/agent/memory/list" => handle_agent_memory_list;
697 GET "/api/v1/agent/memory/read" => handle_agent_memory_read;
698 POST "/api/v1/agent/memory/write", Always => handle_agent_memory_write;
699 GET "/api/v1/agent/memory/history" => handle_agent_memory_history;
700 GET "/api/v1/agent/memory/diff" => handle_agent_memory_diff;
701 POST "/api/v1/agent/memory/revert", Always => handle_agent_memory_revert;
702 POST "/api/v1/agent/globalmemory/write", Always => handle_agent_globalmemory_write;
711 GET "/api/v1/agent/globalmemory/list" => handle_agent_globalmemory_list;
712 GET "/api/v1/agent/globalmemory/read" => handle_agent_globalmemory_read;
713 POST "/api/v1/agent/globalmemory/remove", Always => handle_agent_globalmemory_remove;
714 POST "/api/v1/agent/globalmemory/reach", Always => handle_agent_globalmemory_reach;
715 GET "/api/v1/agent/globalmemory/history" => handle_agent_globalmemory_history;
721 GET "/api/v1/agent/globalmemory/diff" => handle_agent_globalmemory_diff;
722 POST "/api/v1/agent/globalmemory/revert", Always => handle_agent_globalmemory_revert;
723 POST "/api/v1/agent/memory/session-start/part", Never => memory_delivery_handlers::handle_session_start_part;
729 POST "/api/v1/agent/memory/session-start/ack", Never => memory_delivery_handlers::handle_session_start_ack;
730 GET "/api/v1/agent/preset/list" => handle_agent_preset_list;
731 GET "/api/v1/agent/preset/get" => handle_agent_preset_get;
732 GET "/api/v1/agent/identity/accounts" => handle_agent_identity_accounts;
733 POST "/api/v1/agent/identity/validate", Always => handle_agent_identity_validate;
734 POST "/api/v1/agent/identity/switch", Always => handle_agent_identity_switch;
735 POST "/api/v1/agent/identity/check-limits", Always => handle_agent_identity_check_limits;
736 POST "/api/v1/agent/identity/signin/notice", Always => signin_notice::handle_agent_signin_notice;
737 POST "/api/v1/agent/skill", Always => handle_agent_skill;
738}
739
740declared_routes! {
741 fn external_host_routes, EXTERNAL_HOST_ROUTES;
744 POST "/api/v1/host/external_nonce", Plumbing => super::external_host::handle_nonce;
745 POST "/api/v1/host/external_attest", Plumbing => super::external_host::handle_attest;
746 POST "/api/v1/host/external_revoke", Plumbing => super::external_host::handle_revoke;
747 POST "/api/v1/host/activity", Plumbing => super::host_control::handle_activity;
748 POST "/api/v1/host/shutdown", Plumbing => super::host_control::handle_shutdown;
749 POST "/api/v1/host/notice", Plumbing => super::host_control::handle_notice;
750}
751
752declared_routes! {
753 fn ui_and_host_routes_declared, UI_AND_HOST_ROUTES;
755 POST "/api/v1/ui/screenshot", Never => ui_handlers::handle_ui_screenshot;
760 POST "/api/v1/ui/capture_mask", Never => super::capture_mask_route::handle_capture_mask;
765 POST "/api/v1/ui/record", Never => ui_record::handle_ui_record;
766 POST "/api/v1/ui/click", Always => ui_handlers::handle_ui_click;
767 POST "/api/v1/ui/query", Never => ui_handlers::handle_ui_query;
768 POST "/api/v1/ui/shortcuts/list", Never => ui_shortcuts::handle_ui_shortcuts_list;
771 POST "/api/v1/ui/shortcuts/run", Always => ui_shortcuts::handle_ui_run_command;
772 POST "/api/v1/ui/shortcuts/press", Always => ui_shortcuts::handle_ui_press_keys;
773 POST "/api/v1/ui/shortcuts/set", Always => ui_shortcuts::handle_ui_set_shortcut;
774 POST "/api/v1/ui/shortcuts/reset", Always => ui_shortcuts::handle_ui_reset_shortcuts;
775 POST "/api/v1/ui/browser/open", Always => ui_handlers::handle_ui_browser_open;
781 POST "/api/v1/ui/browser/snapshot", Never => ui_handlers::handle_ui_browser_snapshot;
782 POST "/api/v1/ui/browser/find", Never => crate::server::browser_find::handle_ui_browser_find;
783 POST "/api/v1/ui/browser/locate", Never => crate::server::browser_locate::handle_ui_browser_locate;
784 POST "/api/v1/ui/browser/act", Always => ui_handlers::handle_ui_browser_act;
785 POST "/api/v1/ui/browser/set_files", Always => ui_handlers::handle_ui_browser_set_files;
786 POST "/api/v1/ui/browser/wait_for", Never => ui_handlers::handle_ui_browser_wait_for;
787 POST "/api/v1/host/browser_attention", Plumbing => ui_handlers::handle_host_browser_attention;
788 POST "/api/v1/ui/browser/request_bypass", Always => crate::server::browser_bypass_routes::handle_ui_browser_request_bypass;
789 POST "/api/v1/ui/browser/end_bypass", Always => crate::server::browser_bypass_routes::handle_ui_browser_end_bypass;
790 POST "/api/v1/ui/browser/close", Always => crate::server::browser_close_route::handle_ui_browser_close;
791 POST "/api/v1/ui/browser/terminal", Always => crate::server::browser_terminal::handle_ui_browser_terminal;
792 POST "/api/v1/host/browser_bypass", Plumbing => crate::server::browser_bypass_routes::handle_host_browser_bypass;
793 POST "/api/v1/ui/browser/actions", Never => crate::server::browser_actions::handle_ui_browser_actions;
795 POST "/api/v1/host/browser_pause", Plumbing => crate::server::browser_actions::handle_host_browser_pause;
796 POST "/api/v1/host/widget_approval", Plumbing => super::widget_handlers::handle_host_widget_approval;
797 POST "/api/v1/host/job_templates", Plumbing => super::job_template_handlers::handle_host_job_templates;
798 POST "/api/v1/host/jobs", Plumbing => super::cron::handle_host_jobs;
799 POST "/api/v1/host/vault", Plumbing => super::vault_handlers::handle_host_vault;
801 POST "/api/v1/host/google", Plumbing => super::google_handlers::handle_host_google;
803 POST "/api/v1/host/app_update", Plumbing => app_api::app_update::handle_host_app_update;
806 POST "/api/v1/host/upgrade_request", Plumbing => app_api::app_update::handle_host_upgrade_request;
807 POST "/api/v1/host/desktop_request", Plumbing => app_api::desktop::handle_host_request;
810 POST "/api/v1/host/desktop_stop", Plumbing => app_api::desktop::handle_host_stop;
811 POST "/api/v1/host/operator_attest", Plumbing => super::operator_proof::handle_host_attest;
813 POST "/api/v1/host/browser_navigation", Plumbing => crate::server::browser_allowlist::handle_host_browser_navigation;
814 POST "/api/v1/host/browser_dialog", Plumbing => crate::server::browser_dialog::handle_host_browser_dialog;
815 POST "/api/v1/host/browser_permission", Plumbing => crate::server::browser_permission::handle_host_browser_permission;
816 POST "/api/v1/ui/browser/dialogs", Never => crate::server::browser_dialog::handle_ui_browser_dialogs;
817 POST "/api/v1/ui/browser/zoom", Always => crate::server::browser_zoom::handle_ui_browser_zoom;
818 POST "/api/v1/ui/browser/scroll", Always => crate::server::browser_scroll::handle_ui_browser_scroll;
819 POST "/api/v1/ui/browser/list", Never => crate::server::browser_sessions::handle_ui_browser_list;
820 POST "/api/v1/ui/browser/show", Always => crate::server::browser_sessions::handle_ui_browser_show;
821 POST "/api/v1/ui/browser/hide", Always => crate::server::browser_sessions::handle_ui_browser_hide;
822 POST "/api/v1/host/browser_popup", Plumbing => ui_handlers::handle_host_browser_popup;
823 POST "/api/v1/host/browser_popup_window", Plumbing => ui_handlers::handle_host_browser_popup_window;
824 POST "/api/v1/ui/browser/navigate", Always => ui_handlers::handle_ui_browser_navigate;
825 POST "/api/v1/ui/browser/back", Always => ui_handlers::handle_ui_browser_back;
826 POST "/api/v1/ui/browser/forward", Always => ui_handlers::handle_ui_browser_forward;
827 POST "/api/v1/ui/browser/reload", Always => ui_handlers::handle_ui_browser_reload;
828 POST "/api/v1/ui/browser/eval", Always => ui_handlers::handle_ui_browser_eval;
829 POST "/api/v1/ui/browser/dispatch_key", Always => ui_handlers::handle_ui_browser_dispatch_key;
830 POST "/api/v1/ui/browser/focus_element", Always => ui_handlers::handle_ui_browser_focus_element;
831 POST "/api/v1/ui/browser/focus_info", Never => ui_handlers::handle_ui_browser_focus_info;
832 POST "/api/v1/agent/pane/close", Always => app_api::pane::handle_close_pane;
840 POST "/api/v1/agent/self/quit", Always => app_api::pane::handle_quit_self;
841 GET "/api/v1/app/update-status" => app_api::app_update::handle_update_status;
844 POST "/api/v1/agent/remote/op", Always => super::remote_ops::send::handle_agent_remote_op;
846 GET "/api/v1/app/connectivity" => app_api::connectivity::handle_status;
847 GET "/api/v1/app/health" => super::remote_ops::app_ops::handle_health;
848 GET "/api/v1/app/workspace" => app_api::workspace_stop::handle_workspace;
850 GET "/api/v1/app/logs" => super::remote_ops::log_ops::handle_local_logs;
851 GET "/api/v1/app/record" => app_api::record_read::handle_record;
853 POST "/api/v1/agent/self/upgrade", Always => app_api::app_update::handle_request_upgrade;
854}
855
856fn ui_and_host_routes() -> Router<AppState> {
858 ui_and_host_routes_declared()
859 .merge(browser_control_routes())
860 .merge(external_host_routes())
861}
862
863declared_routes! {
864 fn agent_self_and_fleet_routes_declared, AGENT_SELF_AND_FLEET_ROUTES;
866 POST "/api/v1/agent/desktop/policy", Always => app_api::desktop::handle_policy;
869 POST "/api/v1/agent/desktop/authorize", Always => app_api::desktop::handle_authorize;
870 POST "/api/v1/agent/desktop/record", Always => app_api::desktop::handle_record;
871 POST "/api/v1/agent/desktop/release", Always => app_api::desktop::handle_release;
872 POST "/api/v1/agent/self/mcp-health", Never => app_api::mcp_health::handle_mcp_health;
874 POST "/api/v1/agent/self/mcp-heal", Always => app_api::mcp_health::handle_mcp_heal;
875 POST "/api/v1/agent/self/mcp-beat", Never => app_api::mcp_health::handle_mcp_beat;
876 POST "/api/v1/agent/self/context", Never => app_api::agent_context::handle_context_self;
878 POST "/api/v1/agent/self/compact", Always => app_api::agent_context::handle_compact_self;
879 POST "/api/v1/agent/self/fresh", Always => app_api::agent_context::handle_fresh_self;
880 POST "/api/v1/agent/self/ready", Always => crate::server::prep::handle_ready_self;
882 POST "/api/v1/agent/env", Handler => app_api::agent_env::handle_agent_env;
884 POST "/api/v1/github/token", Always => app_api::github_token::handle_github_token;
887 POST "/api/v1/github/push-scan", Always => app_api::push_scan::handle_push_scan, layer(axum::extract::DefaultBodyLimit::max(app_api::push_scan::MAX_BODY_BYTES));
889 POST "/api/v1/github/pr-merge", Always => app_api::pr_merge::handle_pr_merge;
891 POST "/api/v1/aws/credentials", Never => app_api::aws_credentials::handle_aws_credentials;
894 GET "/api/v1/aws/grants" => app_api::aws_grants::handle_aws_grants;
896 POST "/api/v1/aws/grants/decide", Always => app_api::aws_grants::handle_aws_grant_decide;
897 POST "/api/v1/agent/history/reclaim", Always => app_api::agent_history_reclaim::handle_history_reclaim;
900 GET "/api/v1/agent/history/reclaim" => app_api::agent_history_reclaim::handle_history_reclaim_status;
901 GET "/api/v1/agent/shutdown/:request_id" => app_api::pane::handle_shutdown_status;
905 POST "/api/v1/agent/dev_server/register", Always => app_api::dev_server::handle_register_dev_server;
911 POST "/api/v1/fleet/bulk-stop", Always => handle_fleet_bulk_stop;
923 POST "/agentmux/agent/stop", Always => handle_agent_stop_forward;
933}
934
935fn agent_self_and_fleet_routes() -> Router<AppState> {
937 agent_self_and_fleet_routes_declared()
938 .merge(agent_definition_routes())
940}
941
942declared_routes! {
943 fn forward_messaging_and_work_routes, FORWARD_MESSAGING_AND_WORK_ROUTES;
945 POST super::jobs_remote_stop::STOP_RUN_PATH, Always => super::jobs_remote_stop::handle_jobs_stop_run;
948 POST "/agentmux/agent/broadcast", Always => handle_agent_broadcast_forward;
953 POST "/agentmux/agent/broadcast/confirm", Never => handle_agent_broadcast_confirm;
957 POST "/agentmux/agent/stop-pending", Always => handle_agent_stop_pending_forward;
960 GET "/api/messaging/status" => messaging_handlers::handle_status;
961 POST "/api/messaging/discord/send", Always => messaging_handlers::handle_discord_send;
962 POST "/api/messaging/telegram/send", Always => messaging_handlers::handle_telegram_send;
963 POST "/api/messaging/slack/send", Always => messaging_handlers::handle_slack_send;
964 POST "/api/messaging/whatsapp/send", Always => messaging_handlers::handle_whatsapp_send;
965 GET "/agentmux/jobs" => cron::handle_cron_list;
967 GET "/agentmux/jobs/:id/runs" => cron::handle_cron_runs;
968 GET "/agentmux/cron" => cron::handle_cron_list;
969 GET "/agentmux/cron/:id/runs" => cron::handle_cron_runs;
970 GET "/agentmux/identity/fallbacks" => caller::handle_identity_fallbacks;
971 GET "/agentmux/agents/self/keys" => agent_self_keys::handle_agent_self_keys;
972 GET "/agentmux/quit-question" => super::quit_question::handle_quit_question;
974 GET "/agentmux/work" => work_queue::handle_work_list;
975 GET "/agentmux/work/boards" => work_boards::handle_boards_list;
976 GET "/agentmux/work/:id" => work_tasks::handle_work_get;
977 GET "/agentmux/work/:id/tokens" => work_tasks::handle_work_tokens;
978 POST "/agentmux/work/:id/accept", Always => work_delegate::handle_work_accept;
980 POST "/agentmux/work/:id/send_back", Always => work_delegate::handle_work_send_back;
981}
982
983declared_routes! {
984 fn whatsapp_webhooks, WHATSAPP_WEBHOOKS;
987 GET "/webhook/whatsapp" => crate::messaging::whatsapp::handle_verify;
988 POST "/webhook/whatsapp", Never => crate::messaging::whatsapp::handle_inbound;
989}
990
991declared_routes! {
992 fn widget_files_routes, WIDGET_FILES_ROUTES;
994 GET "/agentmux/widget-files/:id/:hash/:key/*path" => super::widget_handlers::handle_widget_file;
995 GET "/agentmux/widget-sdk/:file" => super::widget_handlers::handle_widget_sdk;
996}
997
998declared_routes! {
999 fn browser_control_routes, BROWSER_CONTROL_ROUTES;
1001 POST "/api/v1/ui/browser/handoff", Always => ui_handlers::handle_ui_browser_handoff;
1002 POST "/api/v1/ui/browser/handoff_status", Never => crate::server::browser_retake::handle_ui_browser_handoff_status;
1003 POST "/api/v1/ui/browser/request", Never => crate::server::browser_waiting::handle_ui_browser_request;
1004 POST "/api/v1/ui/browser/retake", Always => crate::server::browser_retake::handle_ui_browser_retake;
1005 POST "/api/v1/ui/browser/take_control", Always => crate::server::browser_control::handle_ui_browser_take_control;
1006 POST "/api/v1/ui/browser/release", Always => crate::server::browser_control::handle_ui_browser_release;
1007}
1008
1009declared_routes! {
1010 fn agent_definition_routes, AGENT_DEFINITION_ROUTES;
1013 POST "/api/v1/agent/seats", Handler => app_api::agent_seats::handle_agent_seats;
1014 POST "/api/v1/agent/folder-overlap-ask", Handler => app_api::folder_overlap_ask::handle_folder_overlap_ask;
1015 POST "/api/v1/agent/pin-ask", Handler => app_api::pin_ask::handle_pin_ask;
1016 POST "/api/v1/agent/migrate-ids", Handler => app_api::agent_migrate_ids::handle_agent_migrate_ids;
1017 POST "/api/v1/agent/rename", Handler => app_api::agent_rename::handle_agent_rename;
1018 POST "/api/v1/agent/export", Handler => app_api::agent_export::handle_agent_export;
1019 POST "/api/v1/agent/bring_back", Handler => app_api::agent_handover::handle_agent_bring_back;
1020 POST "/api/v1/agent/move", Handler => app_api::agent_move::handle_agent_move;
1021 POST "/api/v1/agent/move_status", Handler => app_api::agent_handover::handle_agent_move_status;
1022 POST "/api/v1/agent/update", Handler => app_api::agent_definition::handle_agent_update;
1023 POST "/api/v1/agent/bundles", Handler => app_api::agent_definition::handle_agent_bundles;
1024 POST "/api/v1/agent/hide", Handler => app_api::agent_definition::handle_agent_hide;
1025 POST "/api/v1/agent/unhide", Handler => app_api::agent_definition::handle_agent_unhide;
1026}
1027
1028declared_routes! {
1029 fn google_agent_routes, GOOGLE_AGENT_ROUTES;
1032 GET "/api/v1/google/self/services" => super::google_handlers::handle_google_self_services;
1033 GET "/api/v1/google/status" => super::google_handlers::handle_google_status;
1034 POST "/api/v1/google/grant", Always => super::google_handlers::handle_google_grant;
1035 POST "/api/v1/google/disconnect", Always => super::google_handlers::handle_google_disconnect;
1036 POST "/api/v1/google/connect", Always => super::google_handlers::connect::handle_google_connect;
1037 POST "/api/v1/google/connect/status", Always => super::google_handlers::connect::handle_google_connect_status;
1038 POST "/api/v1/google/connect/cancel", Always => super::google_handlers::connect::handle_google_connect_cancel;
1039 POST "/api/v1/google/calendar", Always => super::google_handlers::handle_google_calendar;
1040 POST "/api/v1/google/drive", Always => super::google_handlers::handle_google_drive;
1041 POST "/api/v1/google/gmail", Always => super::google_handlers::handle_google_gmail;
1042}
1043
1044pub(super) fn with_frontend(router: Router<AppState>, dir: &std::path::Path) -> Router<AppState> {
1049 use tower_http::services::{ServeDir, ServeFile};
1050 let index = ServeFile::new(dir.join("index.html"));
1051 let files = Router::new()
1053 .fallback_service(ServeDir::new(dir).fallback(index))
1054 .layer(middleware::from_fn(super::ui_cache::ui_cache))
1056 .layer(middleware::from_fn(super::local_session_routes::ui_headers));
1057 router.fallback_service(files)
1058}
1059
1060#[cfg(test)]
1061#[path = "tests/routes_shape_tests.rs"]
1062mod routes_shape_tests;