huskies: merge 771

This commit is contained in:
dave
2026-04-28 12:03:16 +00:00
parent e879d6f602
commit e9ed58502a
5 changed files with 38 additions and 33 deletions
+16 -3
View File
@@ -134,9 +134,22 @@ export const gatewayApi = {
});
},
/// Fetch pipeline status from all registered projects.
getAllProjectsPipeline(): Promise<AllProjectsPipeline> {
return gatewayRequest<AllProjectsPipeline>("/api/gateway/pipeline");
/// Fetch pipeline status from all registered projects via the pipeline.get read-RPC.
async getAllProjectsPipeline(): Promise<AllProjectsPipeline> {
const res = await fetch("/mcp", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "pipeline.get", params: {} }),
});
if (!res.ok) {
const text = await res.text();
throw new Error(text || `Request failed (${res.status})`);
}
const rpc = await res.json() as { result?: AllProjectsPipeline; error?: { message: string } };
if (rpc.error) {
throw new Error(rpc.error.message);
}
return rpc.result!;
},
/// Switch the active project.
-4
View File
@@ -27,10 +27,6 @@ pub fn build_gateway_route(state_arc: Arc<GatewayState>) -> impl poem::Endpoint
.at("/bot-config", poem::get(gateway_bot_config_page_handler))
.at("/api/gateway", poem::get(gateway_api_handler))
.at("/api/gateway/switch", poem::post(gateway_switch_handler))
.at(
"/api/gateway/pipeline",
poem::get(gateway_all_pipeline_handler),
)
.at(
"/api/gateway/projects",
poem::post(gateway_add_project_handler),
+19
View File
@@ -143,6 +143,7 @@ pub async fn gateway_mcp_post_handler(
Ok(resp) => to_json_response(resp),
Err(e) => to_json_response(JsonRpcResponse::error(rpc.id, -32603, e)),
},
"pipeline.get" => to_json_response(handle_pipeline_get(&state, rpc.id).await),
"tools/call" => {
let tool_name = rpc
.params
@@ -424,3 +425,21 @@ async fn handle_aggregate_pipeline_status_tool(
}),
)
}
/// Handle the `pipeline.get` read-RPC — returns the same shape as the old
/// `GET /api/gateway/pipeline` endpoint: `{ "active": "...", "projects": {...} }`.
async fn handle_pipeline_get(state: &GatewayState, id: Option<Value>) -> JsonRpcResponse {
let project_urls: BTreeMap<String, String> = state
.projects
.read()
.await
.iter()
.map(|(n, e)| (n.clone(), e.url.clone()))
.collect();
let results =
gateway::io::fetch_all_project_pipeline_statuses(&project_urls, &state.client).await;
let active = state.active_project.read().await.clone();
JsonRpcResponse::success(id, json!({ "active": active, "projects": results }))
}
+2 -2
View File
@@ -16,8 +16,8 @@ mod websocket;
pub use mcp::{gateway_mcp_get_handler, gateway_mcp_post_handler};
pub use rest::{
gateway_add_project_handler, gateway_all_pipeline_handler, gateway_api_handler,
gateway_assign_agent_handler, gateway_bot_config_get_handler, gateway_bot_config_page_handler,
gateway_add_project_handler, gateway_api_handler, gateway_assign_agent_handler,
gateway_bot_config_get_handler, gateway_bot_config_page_handler,
gateway_bot_config_save_handler, gateway_generate_token_handler, gateway_list_agents_handler,
gateway_mode_handler, gateway_remove_project_handler, gateway_switch_handler,
};
+1 -24
View File
@@ -1,4 +1,4 @@
//! REST HTTP handlers for the gateway: agents, projects, bot configuration, and pipeline.
//! REST HTTP handlers for the gateway: agents, projects, and bot configuration.
use crate::service::gateway::{self, GatewayState};
use poem::handler;
@@ -8,7 +8,6 @@ use poem::web::{Data, Json};
use poem::{Body, Response};
use serde::{Deserialize, Serialize};
use serde_json::{Value, json};
use std::collections::BTreeMap;
use std::sync::Arc;
// ── Agent REST handlers ───────────────────────────────────────────────────────
@@ -257,28 +256,6 @@ pub async fn gateway_bot_config_save_handler(
}
}
/// `GET /api/gateway/pipeline` — fetch pipeline status from all registered projects.
#[handler]
pub async fn gateway_all_pipeline_handler(state: Data<&Arc<GatewayState>>) -> Response {
let project_urls: BTreeMap<String, String> = state
.projects
.read()
.await
.iter()
.map(|(n, e)| (n.clone(), e.url.clone()))
.collect();
let results =
gateway::io::fetch_all_project_pipeline_statuses(&project_urls, &state.client).await;
let active = state.active_project.read().await.clone();
let body = json!({ "active": active, "projects": results });
Response::builder()
.status(StatusCode::OK)
.header("Content-Type", "application/json")
.body(Body::from(serde_json::to_vec(&body).unwrap_or_default()))
}
// ── Bot config page ───────────────────────────────────────────────────────────
/// Self-contained HTML page for bot configuration.