2026-02-19 15:25:22 +00:00
|
|
|
pub mod agents;
|
2026-02-19 17:58:53 +00:00
|
|
|
pub mod agents_sse;
|
2026-02-16 16:24:21 +00:00
|
|
|
pub mod anthropic;
|
|
|
|
|
pub mod assets;
|
|
|
|
|
pub mod chat;
|
|
|
|
|
pub mod context;
|
|
|
|
|
pub mod health;
|
2026-02-16 16:50:50 +00:00
|
|
|
pub mod io;
|
2026-02-16 16:24:21 +00:00
|
|
|
pub mod model;
|
2026-02-19 12:54:04 +00:00
|
|
|
pub mod workflow;
|
2026-02-16 16:35:25 +00:00
|
|
|
|
2026-02-16 16:24:21 +00:00
|
|
|
pub mod project;
|
|
|
|
|
pub mod ws;
|
|
|
|
|
|
2026-02-19 15:25:22 +00:00
|
|
|
use agents::AgentsApi;
|
2026-02-16 16:35:25 +00:00
|
|
|
use anthropic::AnthropicApi;
|
|
|
|
|
use chat::ChatApi;
|
|
|
|
|
use context::AppContext;
|
2026-02-16 16:50:50 +00:00
|
|
|
use io::IoApi;
|
2026-02-16 16:35:25 +00:00
|
|
|
use model::ModelApi;
|
2026-02-16 16:24:21 +00:00
|
|
|
use poem::EndpointExt;
|
|
|
|
|
use poem::{Route, get};
|
2026-02-16 16:35:25 +00:00
|
|
|
use poem_openapi::OpenApiService;
|
|
|
|
|
use project::ProjectApi;
|
|
|
|
|
use std::sync::Arc;
|
2026-02-19 12:54:04 +00:00
|
|
|
use workflow::WorkflowApi;
|
2026-02-16 16:24:21 +00:00
|
|
|
|
|
|
|
|
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))
|
2026-02-19 17:58:53 +00:00
|
|
|
.at(
|
|
|
|
|
"/agents/:story_id/stream",
|
|
|
|
|
get(agents_sse::agent_stream),
|
|
|
|
|
)
|
2026-02-16 16:24:21 +00:00
|
|
|
.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)
|
|
|
|
|
}
|
2026-02-16 16:35:25 +00:00
|
|
|
|
2026-02-19 12:54:04 +00:00
|
|
|
type ApiTuple = (
|
|
|
|
|
ProjectApi,
|
|
|
|
|
ModelApi,
|
|
|
|
|
AnthropicApi,
|
|
|
|
|
IoApi,
|
|
|
|
|
ChatApi,
|
|
|
|
|
WorkflowApi,
|
2026-02-19 15:25:22 +00:00
|
|
|
AgentsApi,
|
2026-02-19 12:54:04 +00:00
|
|
|
);
|
2026-02-16 16:35:25 +00:00
|
|
|
|
|
|
|
|
type ApiService = OpenApiService<ApiTuple, ()>;
|
|
|
|
|
|
2026-02-16 16:50:50 +00:00
|
|
|
/// All HTTP methods are documented by OpenAPI at /docs
|
2026-02-16 16:35:25 +00:00
|
|
|
pub fn build_openapi_service(ctx: Arc<AppContext>) -> (ApiService, ApiService) {
|
|
|
|
|
let api = (
|
|
|
|
|
ProjectApi { ctx: ctx.clone() },
|
|
|
|
|
ModelApi { ctx: ctx.clone() },
|
|
|
|
|
AnthropicApi::new(ctx.clone()),
|
2026-02-16 16:50:50 +00:00
|
|
|
IoApi { ctx: ctx.clone() },
|
2026-02-16 16:35:25 +00:00
|
|
|
ChatApi { ctx: ctx.clone() },
|
2026-02-19 12:54:04 +00:00
|
|
|
WorkflowApi { ctx: ctx.clone() },
|
2026-02-19 15:25:22 +00:00
|
|
|
AgentsApi { ctx: ctx.clone() },
|
2026-02-16 16:35:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let api_service =
|
2026-02-19 15:30:23 +00:00
|
|
|
OpenApiService::new(api, "Story Kit API", "1.0").server("http://127.0.0.1:3001/api");
|
2026-02-16 16:35:25 +00:00
|
|
|
|
|
|
|
|
let docs_api = (
|
|
|
|
|
ProjectApi { ctx: ctx.clone() },
|
|
|
|
|
ModelApi { ctx: ctx.clone() },
|
|
|
|
|
AnthropicApi::new(ctx.clone()),
|
2026-02-16 16:50:50 +00:00
|
|
|
IoApi { ctx: ctx.clone() },
|
2026-02-19 12:54:04 +00:00
|
|
|
ChatApi { ctx: ctx.clone() },
|
2026-02-19 15:25:22 +00:00
|
|
|
WorkflowApi { ctx: ctx.clone() },
|
|
|
|
|
AgentsApi { ctx },
|
2026-02-16 16:35:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let docs_service =
|
2026-02-19 15:30:23 +00:00
|
|
|
OpenApiService::new(docs_api, "Story Kit API", "1.0").server("http://127.0.0.1:3001/api");
|
2026-02-16 16:35:25 +00:00
|
|
|
|
|
|
|
|
(api_service, docs_service)
|
|
|
|
|
}
|