Skip to main content

atomr_agents_coding_cli_harness_web/
spa.rs

1//! Static SPA asset serving (mirrors deep-research-harness-web).
2
3use axum::body::Body;
4use axum::http::{header, StatusCode, Uri};
5use axum::response::{IntoResponse, Response};
6
7#[cfg(feature = "embed-ui")]
8#[allow(unused_imports)]
9use rust_embed::{Embed, RustEmbed};
10
11#[cfg(feature = "embed-ui")]
12#[derive(RustEmbed)]
13#[folder = "ui/"]
14struct SpaAssets;
15
16#[cfg(feature = "embed-ui")]
17pub async fn serve_embedded(uri: Uri) -> Response {
18    let mut path = uri.path().trim_start_matches('/').to_string();
19    if path.is_empty() || SpaAssets::get(&path).is_none() {
20        path = "index.html".into();
21    }
22    match SpaAssets::get(&path) {
23        Some(content) => {
24            let mime = content.metadata.mimetype();
25            Response::builder()
26                .header(header::CONTENT_TYPE, mime)
27                .body(Body::from(content.data.into_owned()))
28                .unwrap()
29        }
30        None => (StatusCode::NOT_FOUND, "not found").into_response(),
31    }
32}
33
34#[cfg(not(feature = "embed-ui"))]
35pub async fn serve_embedded(_uri: Uri) -> Response {
36    let body = serde_json::json!({
37        "ui": "not embedded",
38        "hint": "build with --features embed-ui",
39    });
40    (
41        StatusCode::OK,
42        [(header::CONTENT_TYPE, "application/json")],
43        body.to_string(),
44    )
45        .into_response()
46}