Refactored and documented the HTTP API

This commit is contained in:
Dave
2026-02-16 16:50:50 +00:00
parent f76376b203
commit feb05dc8d0
9 changed files with 148 additions and 136 deletions

View File

@@ -2,26 +2,22 @@ pub mod anthropic;
pub mod assets;
pub mod chat;
pub mod context;
pub mod fs;
pub mod health;
pub mod io;
pub mod model;
pub mod project;
pub mod search;
pub mod shell;
pub mod ws;
use anthropic::AnthropicApi;
use chat::ChatApi;
use context::AppContext;
use fs::FsApi;
use io::IoApi;
use model::ModelApi;
use poem::EndpointExt;
use poem::{Route, get};
use poem_openapi::OpenApiService;
use project::ProjectApi;
use search::SearchApi;
use shell::ShellApi;
use std::sync::Arc;
pub fn build_routes(ctx: AppContext) -> impl poem::Endpoint {
@@ -40,26 +36,17 @@ pub fn build_routes(ctx: AppContext) -> impl poem::Endpoint {
.data(ctx_arc)
}
type ApiTuple = (
ProjectApi,
ModelApi,
AnthropicApi,
FsApi,
SearchApi,
ShellApi,
ChatApi,
);
type ApiTuple = (ProjectApi, ModelApi, AnthropicApi, IoApi, ChatApi);
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()),
FsApi { ctx: ctx.clone() },
SearchApi { ctx: ctx.clone() },
ShellApi { ctx: ctx.clone() },
IoApi { ctx: ctx.clone() },
ChatApi { ctx: ctx.clone() },
);
@@ -70,9 +57,7 @@ pub fn build_openapi_service(ctx: Arc<AppContext>) -> (ApiService, ApiService) {
ProjectApi { ctx: ctx.clone() },
ModelApi { ctx: ctx.clone() },
AnthropicApi::new(ctx.clone()),
FsApi { ctx: ctx.clone() },
SearchApi { ctx: ctx.clone() },
ShellApi { ctx: ctx.clone() },
IoApi { ctx: ctx.clone() },
ChatApi { ctx },
);