huskies: merge 771
This commit is contained in:
@@ -134,9 +134,22 @@ export const gatewayApi = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Fetch pipeline status from all registered projects.
|
/// Fetch pipeline status from all registered projects via the pipeline.get read-RPC.
|
||||||
getAllProjectsPipeline(): Promise<AllProjectsPipeline> {
|
async getAllProjectsPipeline(): Promise<AllProjectsPipeline> {
|
||||||
return gatewayRequest<AllProjectsPipeline>("/api/gateway/pipeline");
|
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.
|
/// Switch the active project.
|
||||||
|
|||||||
@@ -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("/bot-config", poem::get(gateway_bot_config_page_handler))
|
||||||
.at("/api/gateway", poem::get(gateway_api_handler))
|
.at("/api/gateway", poem::get(gateway_api_handler))
|
||||||
.at("/api/gateway/switch", poem::post(gateway_switch_handler))
|
.at("/api/gateway/switch", poem::post(gateway_switch_handler))
|
||||||
.at(
|
|
||||||
"/api/gateway/pipeline",
|
|
||||||
poem::get(gateway_all_pipeline_handler),
|
|
||||||
)
|
|
||||||
.at(
|
.at(
|
||||||
"/api/gateway/projects",
|
"/api/gateway/projects",
|
||||||
poem::post(gateway_add_project_handler),
|
poem::post(gateway_add_project_handler),
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ pub async fn gateway_mcp_post_handler(
|
|||||||
Ok(resp) => to_json_response(resp),
|
Ok(resp) => to_json_response(resp),
|
||||||
Err(e) => to_json_response(JsonRpcResponse::error(rpc.id, -32603, e)),
|
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" => {
|
"tools/call" => {
|
||||||
let tool_name = rpc
|
let tool_name = rpc
|
||||||
.params
|
.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 }))
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ mod websocket;
|
|||||||
|
|
||||||
pub use mcp::{gateway_mcp_get_handler, gateway_mcp_post_handler};
|
pub use mcp::{gateway_mcp_get_handler, gateway_mcp_post_handler};
|
||||||
pub use rest::{
|
pub use rest::{
|
||||||
gateway_add_project_handler, gateway_all_pipeline_handler, gateway_api_handler,
|
gateway_add_project_handler, gateway_api_handler, gateway_assign_agent_handler,
|
||||||
gateway_assign_agent_handler, gateway_bot_config_get_handler, gateway_bot_config_page_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_bot_config_save_handler, gateway_generate_token_handler, gateway_list_agents_handler,
|
||||||
gateway_mode_handler, gateway_remove_project_handler, gateway_switch_handler,
|
gateway_mode_handler, gateway_remove_project_handler, gateway_switch_handler,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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 crate::service::gateway::{self, GatewayState};
|
||||||
use poem::handler;
|
use poem::handler;
|
||||||
@@ -8,7 +8,6 @@ use poem::web::{Data, Json};
|
|||||||
use poem::{Body, Response};
|
use poem::{Body, Response};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{Value, json};
|
use serde_json::{Value, json};
|
||||||
use std::collections::BTreeMap;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
// ── Agent REST handlers ───────────────────────────────────────────────────────
|
// ── 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 ───────────────────────────────────────────────────────────
|
// ── Bot config page ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
/// Self-contained HTML page for bot configuration.
|
/// Self-contained HTML page for bot configuration.
|
||||||
|
|||||||
Reference in New Issue
Block a user