fix(ui): return helpful message at /ui when inspector frontend is not embedded

This commit is contained in:
Nathan Flurry 2026-02-07 12:43:55 -08:00
parent 37247587c4
commit 52f5d07185
2 changed files with 17 additions and 4 deletions

View file

@ -235,9 +235,7 @@ pub fn build_router_with_state(shared: Arc<AppState>) -> (Router, Arc<AppState>)
.nest("/opencode", opencode_router) .nest("/opencode", opencode_router)
.merge(opencode_root_router); .merge(opencode_root_router);
if ui::is_enabled() { router = router.merge(ui::router());
router = router.merge(ui::router());
}
let http_logging = match std::env::var("SANDBOX_AGENT_LOG_HTTP") { let http_logging = match std::env::var("SANDBOX_AGENT_LOG_HTTP") {
Ok(value) if value == "0" || value.eq_ignore_ascii_case("false") => false, Ok(value) if value == "0" || value.eq_ignore_ascii_case("false") => false,

View file

@ -15,7 +15,10 @@ pub fn is_enabled() -> bool {
pub fn router() -> Router { pub fn router() -> Router {
if !INSPECTOR_ENABLED { if !INSPECTOR_ENABLED {
return Router::new(); return Router::new()
.route("/ui", get(handle_not_built))
.route("/ui/", get(handle_not_built))
.route("/ui/*path", get(handle_not_built));
} }
Router::new() Router::new()
.route("/ui", get(handle_index)) .route("/ui", get(handle_index))
@ -23,6 +26,18 @@ pub fn router() -> Router {
.route("/ui/*path", get(handle_path)) .route("/ui/*path", get(handle_path))
} }
async fn handle_not_built() -> Response {
let body = "Inspector UI was not included in this build.\n\n\
To enable it, build the frontend first:\n\n\
cd frontend/packages/inspector && pnpm install && pnpm build\n\n\
Then rebuild sandbox-agent without SANDBOX_AGENT_SKIP_INSPECTOR.\n";
Response::builder()
.status(StatusCode::NOT_FOUND)
.header(header::CONTENT_TYPE, "text/plain; charset=utf-8")
.body(Body::from(body))
.unwrap()
}
async fn handle_index() -> Response { async fn handle_index() -> Response {
serve_path("") serve_path("")
} }