Files
huskies/server/src/http/mod.rs
T
Dave 6d57b06636 Accept story 34: Per-Project Agent Configuration and Role Definitions
Replace single [agent] config with multi-agent [[agent]] roster system.
Each agent has name, role, model, allowed_tools, max_turns, max_budget_usd,
and system_prompt fields that map to Claude CLI flags at spawn time.

- AgentConfig expanded with structured fields, validated at startup (panics
  on duplicate names, empty names, non-positive budgets/turns)
- Backwards-compatible: legacy [agent] format auto-wraps with deprecation warning
- AgentPool uses composite "story_id:agent_name" keys for concurrent agents
- agent_name added to AgentEvent variants, AgentInfo, start/stop/subscribe APIs
- GET /agents/config returns roster, POST /agents/config/reload hot-reloads
- POST /agents/start accepts optional agent_name, /agents/stop requires it
- SSE route updated to /agents/:story_id/:agent_name/stream
- Frontend: roster badges, agent selector dropdown, composite-key state
- Project root initialized to cwd at startup so config endpoints work immediately

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:46:14 +00:00

90 lines
2.3 KiB
Rust

pub mod agents;
pub mod agents_sse;
pub mod anthropic;
pub mod assets;
pub mod chat;
pub mod context;
pub mod health;
pub mod io;
pub mod model;
pub mod workflow;
pub mod project;
pub mod ws;
use agents::AgentsApi;
use anthropic::AnthropicApi;
use chat::ChatApi;
use context::AppContext;
use io::IoApi;
use model::ModelApi;
use poem::EndpointExt;
use poem::{Route, get};
use poem_openapi::OpenApiService;
use project::ProjectApi;
use std::sync::Arc;
use workflow::WorkflowApi;
pub fn build_routes(ctx: AppContext) -> impl poem::Endpoint {
let ctx_arc = std::sync::Arc::new(ctx);
let (api_service, docs_service) = build_openapi_service(ctx_arc.clone());
Route::new()
.nest("/api", api_service)
.nest("/docs", docs_service.swagger_ui())
.at("/ws", get(ws::ws_handler))
.at(
"/agents/:story_id/:agent_name/stream",
get(agents_sse::agent_stream),
)
.at("/health", get(health::health))
.at("/assets/*path", get(assets::embedded_asset))
.at("/", get(assets::embedded_index))
.at("/*path", get(assets::embedded_file))
.data(ctx_arc)
}
type ApiTuple = (
ProjectApi,
ModelApi,
AnthropicApi,
IoApi,
ChatApi,
WorkflowApi,
AgentsApi,
);
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() },
WorkflowApi { ctx: ctx.clone() },
AgentsApi { ctx: ctx.clone() },
);
let api_service =
OpenApiService::new(api, "Story Kit 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() },
WorkflowApi { ctx: ctx.clone() },
AgentsApi { ctx },
);
let docs_service =
OpenApiService::new(docs_api, "Story Kit API", "1.0").server("http://127.0.0.1:3001/api");
(api_service, docs_service)
}