tokenburn-web 0.1.8

TokenBurn — local AI token/cost usage web dashboard (Topcoat)
Documentation
//! JSON and static routes.

use topcoat::{
    Result,
    context::Cx,
    router::{
        content::{Css, Json},
        query_params, route,
    },
};

use crate::{data::load, params::UsageParams, style::CSS};

/// The same report as JSON: `/api/report?tool=pi&bucket=daily`.
#[route(GET "/api/report")]
async fn report(cx: &Cx) -> Result<Json<Vec<tokenburn_core::ReportRow>>> {
    let query = query_params::<UsageParams>(cx)?.to_query();
    Ok(Json(
        load(query, &Default::default(), tokenburn_core::Currency::USD)
            .await
            .report,
    ))
}

/// Liveness probe.
#[route(GET "/api/health")]
async fn health() -> Result<Json<&'static str>> {
    Ok(Json("ok"))
}

/// Every colour theme with its palette (the same ones the TUI and GUI offer).
#[route(GET "/api/themes")]
async fn themes() -> Result<Json<serde_json::Value>> {
    Ok(Json(crate::theme::catalogue()))
}

#[route(GET "/style.css")]
async fn style() -> Result<Css<&'static str>> {
    Ok(Css(CSS))
}