huskies: merge 950
This commit is contained in:
+9
-94
@@ -1,34 +1,18 @@
|
||||
//! HTTP server — module declarations for all REST, MCP, WebSocket, and SSE endpoints.
|
||||
/// Agent management HTTP endpoints.
|
||||
pub mod agents;
|
||||
/// Server-sent event stream for real-time agent output.
|
||||
pub mod agents_sse;
|
||||
/// Anthropic API key management endpoints.
|
||||
pub mod anthropic;
|
||||
/// Static asset serving (embedded frontend files).
|
||||
pub mod assets;
|
||||
/// Bot slash-command HTTP endpoint.
|
||||
pub mod bot_command;
|
||||
/// Bot configuration read/write endpoints.
|
||||
pub mod bot_config;
|
||||
/// Chat session HTTP endpoints.
|
||||
pub mod chat;
|
||||
/// Shared application context threaded through handlers.
|
||||
pub mod context;
|
||||
/// Server-sent event stream for pipeline/watcher events.
|
||||
pub mod events;
|
||||
/// Node identity endpoint (public key, node ID).
|
||||
pub mod identity;
|
||||
/// Filesystem I/O HTTP endpoints (read, write, list, search).
|
||||
pub mod io;
|
||||
/// Model Context Protocol (MCP) HTTP endpoint and tool modules.
|
||||
pub mod mcp;
|
||||
/// LLM model selection and listing endpoints.
|
||||
pub mod model;
|
||||
/// OAuth 2.0 PKCE flow endpoints for Anthropic authentication.
|
||||
pub mod oauth;
|
||||
/// Project settings HTTP endpoints.
|
||||
pub mod settings;
|
||||
#[cfg(test)]
|
||||
pub(crate) mod test_helpers;
|
||||
/// Workflow helpers for story/bug file operations.
|
||||
@@ -36,26 +20,13 @@ pub mod workflow;
|
||||
|
||||
/// Gateway-mode HTTP endpoints for multi-project proxy.
|
||||
pub mod gateway;
|
||||
/// Project open/close/list HTTP endpoints.
|
||||
pub mod project;
|
||||
/// Setup wizard HTTP endpoints.
|
||||
pub mod wizard;
|
||||
/// WebSocket handler for real-time frontend communication.
|
||||
pub mod ws;
|
||||
|
||||
use agents::AgentsApi;
|
||||
use anthropic::AnthropicApi;
|
||||
use bot_command::BotCommandApi;
|
||||
use bot_config::BotConfigApi;
|
||||
use chat::ChatApi;
|
||||
use context::AppContext;
|
||||
use io::IoApi;
|
||||
use model::ModelApi;
|
||||
use poem::EndpointExt;
|
||||
use poem::http::StatusCode;
|
||||
use poem::{Route, get, post};
|
||||
use poem_openapi::OpenApiService;
|
||||
use project::ProjectApi;
|
||||
use settings::SettingsApi;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -88,7 +59,13 @@ pub fn remove_port_file(path: &Path) {
|
||||
let _ = std::fs::remove_file(path);
|
||||
}
|
||||
|
||||
/// Assemble the full Poem route tree (API, WebSocket, MCP, OAuth, assets).
|
||||
/// Liveness probe — always returns 200 OK.
|
||||
#[poem::handler]
|
||||
pub fn health_handler() -> poem::Response {
|
||||
poem::Response::builder().status(StatusCode::OK).body("ok")
|
||||
}
|
||||
|
||||
/// Assemble the full Poem route tree (WebSocket, MCP, OAuth, assets, webhooks).
|
||||
pub fn build_routes(
|
||||
ctx: AppContext,
|
||||
whatsapp_ctx: Option<Arc<WhatsAppWebhookContext>>,
|
||||
@@ -98,13 +75,10 @@ pub fn build_routes(
|
||||
) -> impl poem::Endpoint {
|
||||
let ctx_arc = std::sync::Arc::new(ctx);
|
||||
|
||||
let (api_service, docs_service) = build_openapi_service(ctx_arc.clone());
|
||||
|
||||
let oauth_state = Arc::new(oauth::OAuthState::new(port));
|
||||
|
||||
let mut route = Route::new()
|
||||
.nest("/api", api_service)
|
||||
.nest("/docs", docs_service.swagger_ui())
|
||||
.at("/health", get(health_handler))
|
||||
.at("/ws", get(ws::ws_handler))
|
||||
.at("/crdt-sync", get(crate::crdt_sync::crdt_sync_handler))
|
||||
.at("/rpc", post(rpc_http_handler))
|
||||
@@ -240,58 +214,6 @@ pub fn debug_crdt_handler(req: &poem::Request) -> poem::Response {
|
||||
.body(serde_json::to_string_pretty(&body).unwrap_or_default())
|
||||
}
|
||||
|
||||
type ApiTuple = (
|
||||
ProjectApi,
|
||||
ModelApi,
|
||||
AnthropicApi,
|
||||
IoApi,
|
||||
ChatApi,
|
||||
AgentsApi,
|
||||
SettingsApi,
|
||||
BotCommandApi,
|
||||
wizard::WizardApi,
|
||||
BotConfigApi,
|
||||
);
|
||||
|
||||
type ApiService = OpenApiService<ApiTuple, ()>;
|
||||
|
||||
/// All HTTP methods are documented by OpenAPI at /docs
|
||||
pub fn build_openapi_service(ctx: Arc<AppContext>) -> (ApiService, ApiService) {
|
||||
let api = (
|
||||
ProjectApi { ctx: ctx.clone() },
|
||||
ModelApi { ctx: ctx.clone() },
|
||||
AnthropicApi::new(ctx.clone()),
|
||||
IoApi { ctx: ctx.clone() },
|
||||
ChatApi { ctx: ctx.clone() },
|
||||
AgentsApi { ctx: ctx.clone() },
|
||||
SettingsApi { ctx: ctx.clone() },
|
||||
BotCommandApi { ctx: ctx.clone() },
|
||||
wizard::WizardApi { ctx: ctx.clone() },
|
||||
BotConfigApi { ctx: ctx.clone() },
|
||||
);
|
||||
|
||||
let api_service =
|
||||
OpenApiService::new(api, "Huskies API", "1.0").server("http://127.0.0.1:3001/api");
|
||||
|
||||
let docs_api = (
|
||||
ProjectApi { ctx: ctx.clone() },
|
||||
ModelApi { ctx: ctx.clone() },
|
||||
AnthropicApi::new(ctx.clone()),
|
||||
IoApi { ctx: ctx.clone() },
|
||||
ChatApi { ctx: ctx.clone() },
|
||||
AgentsApi { ctx: ctx.clone() },
|
||||
SettingsApi { ctx: ctx.clone() },
|
||||
BotCommandApi { ctx: ctx.clone() },
|
||||
wizard::WizardApi { ctx: ctx.clone() },
|
||||
BotConfigApi { ctx },
|
||||
);
|
||||
|
||||
let docs_service =
|
||||
OpenApiService::new(docs_api, "Huskies API", "1.0").server("http://127.0.0.1:3001/api");
|
||||
|
||||
(api_service, docs_service)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -341,13 +263,6 @@ mod tests {
|
||||
assert!(port > 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_openapi_service_constructs_without_panic() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = Arc::new(context::AppContext::new_test(tmp.path().to_path_buf()));
|
||||
let (_api_service, _docs_service) = build_openapi_service(ctx);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_routes_constructs_without_panic() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user