refactor(web_ui): share one broker_request helper; /send timeout now 409 not 500

This commit is contained in:
müde 2026-07-05 21:55:28 +02:00
commit 785a36b907
4 changed files with 86 additions and 83 deletions

View file

@ -5,10 +5,8 @@ use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use serde::Deserialize;
use crate::client;
use super::state::fetch_reminder_stats;
use super::{AppState, SOCKET_FETCH_TIMEOUT, error_response};
use super::{AppState, error_response};
#[derive(Deserialize)]
pub(super) struct StatsQuery {
@ -37,42 +35,22 @@ pub(super) async fn api_stats(
/// the `mcp__hyperhive__get_loose_ends` tool sees from inside the
/// container.
pub(super) async fn api_loose_ends(State(state): State<AppState>) -> Response {
let loose_ends: Vec<hive_sh4re::LooseEnd> = match tokio::time::timeout(
SOCKET_FETCH_TIMEOUT,
client::request::<_, hive_sh4re::Response>(
&state.socket,
&hive_sh4re::Request::GetLooseEnds { agent: None },
),
)
.await
match super::broker_request(&state.socket, &hive_sh4re::Request::GetLooseEnds { agent: None })
.await
{
Ok(Ok(hive_sh4re::Response::LooseEnds { loose_ends })) => loose_ends,
Ok(Ok(hive_sh4re::Response::Err { message })) => {
return error_response(
StatusCode::INTERNAL_SERVER_ERROR,
&format!("get_loose_ends: {message}"),
);
Ok(hive_sh4re::Response::LooseEnds { loose_ends }) => {
axum::Json(serde_json::json!({ "loose_ends": loose_ends })).into_response()
}
Ok(Ok(other)) => {
return error_response(
StatusCode::INTERNAL_SERVER_ERROR,
&format!("unexpected response: {other:?}"),
);
}
Ok(Err(e)) => {
return error_response(
StatusCode::INTERNAL_SERVER_ERROR,
&format!("transport: {e:#}"),
);
}
Err(_) => {
return error_response(
StatusCode::CONFLICT,
"get_loose_ends: timed out — hive-c0re busy, retry",
);
}
};
axum::Json(serde_json::json!({ "loose_ends": loose_ends })).into_response()
Ok(hive_sh4re::Response::Err { message }) => error_response(
StatusCode::INTERNAL_SERVER_ERROR,
&format!("get_loose_ends: {message}"),
),
Ok(other) => error_response(
StatusCode::INTERNAL_SERVER_ERROR,
&format!("get_loose_ends: unexpected response: {other:?}"),
),
Err(e) => super::broker_error_response(&e, "get_loose_ends"),
}
}
/// `GET /api/bash-tasks` — snapshot of this agent's in-flight bash tasks.