Skip to content

Commit 91c88a3

Browse files
author
Symbiont OSS Sync
committed
add utopia for swaggerui in http-api
1 parent 80a2bd1 commit 91c88a3

File tree

11 files changed

+366
-47
lines changed

11 files changed

+366
-47
lines changed

Cargo.lock

Lines changed: 131 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/runtime/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ tower = { version = "0.4", optional = true }
7878
tower-http = { version = "0.5", features = ["cors", "trace"], optional = true }
7979
tokio-tungstenite = { version = "0.21", optional = true }
8080
governor = { version = "0.10", optional = true }
81+
utoipa = { version = "4.2", features = ["axum_extras", "chrono"], optional = true }
82+
utoipa-swagger-ui = { version = "6.0", features = ["axum"], optional = true }
8183

8284
# Enterprise features removed for OSS build
8385

@@ -90,7 +92,7 @@ criterion = "0.5"
9092
default = ["vector-db", "keychain"]
9193
vector-db = []
9294
embedding-models = ["candle-core", "candle-nn", "candle-transformers", "tokenizers", "hf-hub"]
93-
http-api = ["axum", "tower", "tower-http", "tokio-tungstenite", "governor"]
95+
http-api = ["axum", "tower", "tower-http", "tokio-tungstenite", "governor", "utoipa", "utoipa-swagger-ui"]
9496
http-input = ["axum", "tower", "tower-http"]
9597
keychain = ["keyring", "security-framework", "secret-service", "winapi"]
9698
enterprise = [] # Enterprise feature for conditional compilation

crates/runtime/src/api/middleware.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ pub async fn auth_middleware(request: Request, next: Next) -> Result<Response, S
5555

5656
/// Global rate limiter store for per-IP rate limiting
5757
#[cfg(feature = "http-api")]
58-
static RATE_LIMITERS: OnceLock<DashMap<IpAddr, Arc<RateLimiter<NotKeyed, InMemoryState, DefaultClock>>>> = OnceLock::new();
58+
type IpRateLimiter = Arc<RateLimiter<NotKeyed, InMemoryState, DefaultClock>>;
59+
static RATE_LIMITERS: OnceLock<DashMap<IpAddr, IpRateLimiter>> = OnceLock::new();
5960

6061
/// Get or create a rate limiter for a specific IP address
6162
#[cfg(feature = "http-api")]

crates/runtime/src/api/routes.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ use axum::{
1212
#[cfg(feature = "http-api")]
1313
use std::sync::Arc;
1414

15+
#[cfg(feature = "http-api")]
16+
use utoipa;
17+
1518
#[cfg(feature = "http-api")]
1619
use super::traits::RuntimeApiProvider;
1720

@@ -23,6 +26,16 @@ use crate::types::AgentId;
2326

2427
/// Workflow execution endpoint handler
2528
#[cfg(feature = "http-api")]
29+
#[utoipa::path(
30+
post,
31+
path = "/api/v1/workflows/execute",
32+
request_body = WorkflowExecutionRequest,
33+
responses(
34+
(status = 200, description = "Workflow executed successfully", body = serde_json::Value),
35+
(status = 500, description = "Internal server error", body = ErrorResponse)
36+
),
37+
tag = "workflows"
38+
)]
2639
pub async fn execute_workflow(
2740
State(provider): State<Arc<dyn RuntimeApiProvider>>,
2841
Json(request): Json<WorkflowExecutionRequest>,
@@ -42,6 +55,18 @@ pub async fn execute_workflow(
4255

4356
/// Agent status endpoint handler
4457
#[cfg(feature = "http-api")]
58+
#[utoipa::path(
59+
get,
60+
path = "/api/v1/agents/{id}/status",
61+
params(
62+
("id" = AgentId, Path, description = "Agent identifier")
63+
),
64+
responses(
65+
(status = 200, description = "Agent status retrieved successfully", body = AgentStatusResponse),
66+
(status = 404, description = "Agent not found", body = ErrorResponse)
67+
),
68+
tag = "agents"
69+
)]
4570
pub async fn get_agent_status(
4671
State(provider): State<Arc<dyn RuntimeApiProvider>>,
4772
Path(agent_id): Path<AgentId>,
@@ -61,6 +86,15 @@ pub async fn get_agent_status(
6186

6287
/// List agents endpoint handler
6388
#[cfg(feature = "http-api")]
89+
#[utoipa::path(
90+
get,
91+
path = "/api/v1/agents",
92+
responses(
93+
(status = 200, description = "Agents listed successfully", body = Vec<String>),
94+
(status = 500, description = "Internal server error", body = ErrorResponse)
95+
),
96+
tag = "agents"
97+
)]
6498
pub async fn list_agents(
6599
State(provider): State<Arc<dyn RuntimeApiProvider>>,
66100
) -> Result<Json<Vec<String>>, (StatusCode, Json<ErrorResponse>)> {
@@ -82,6 +116,15 @@ pub async fn list_agents(
82116

83117
/// System metrics endpoint handler
84118
#[cfg(feature = "http-api")]
119+
#[utoipa::path(
120+
get,
121+
path = "/api/v1/metrics",
122+
responses(
123+
(status = 200, description = "Metrics retrieved successfully", body = serde_json::Value),
124+
(status = 500, description = "Internal server error", body = ErrorResponse)
125+
),
126+
tag = "system"
127+
)]
85128
pub async fn get_metrics(
86129
State(provider): State<Arc<dyn RuntimeApiProvider>>,
87130
) -> Result<Json<serde_json::Value>, (StatusCode, Json<ErrorResponse>)> {
@@ -100,6 +143,16 @@ pub async fn get_metrics(
100143

101144
/// Create agent endpoint handler
102145
#[cfg(feature = "http-api")]
146+
#[utoipa::path(
147+
post,
148+
path = "/api/v1/agents",
149+
request_body = CreateAgentRequest,
150+
responses(
151+
(status = 200, description = "Agent created successfully", body = CreateAgentResponse),
152+
(status = 500, description = "Internal server error", body = ErrorResponse)
153+
),
154+
tag = "agents"
155+
)]
103156
pub async fn create_agent(
104157
State(provider): State<Arc<dyn RuntimeApiProvider>>,
105158
Json(request): Json<CreateAgentRequest>,
@@ -119,6 +172,19 @@ pub async fn create_agent(
119172

120173
/// Update agent endpoint handler
121174
#[cfg(feature = "http-api")]
175+
#[utoipa::path(
176+
put,
177+
path = "/api/v1/agents/{id}",
178+
params(
179+
("id" = AgentId, Path, description = "Agent identifier")
180+
),
181+
request_body = UpdateAgentRequest,
182+
responses(
183+
(status = 200, description = "Agent updated successfully", body = UpdateAgentResponse),
184+
(status = 500, description = "Internal server error", body = ErrorResponse)
185+
),
186+
tag = "agents"
187+
)]
122188
pub async fn update_agent(
123189
State(provider): State<Arc<dyn RuntimeApiProvider>>,
124190
Path(agent_id): Path<AgentId>,
@@ -139,6 +205,18 @@ pub async fn update_agent(
139205

140206
/// Delete agent endpoint handler
141207
#[cfg(feature = "http-api")]
208+
#[utoipa::path(
209+
delete,
210+
path = "/api/v1/agents/{id}",
211+
params(
212+
("id" = AgentId, Path, description = "Agent identifier")
213+
),
214+
responses(
215+
(status = 200, description = "Agent deleted successfully", body = DeleteAgentResponse),
216+
(status = 500, description = "Internal server error", body = ErrorResponse)
217+
),
218+
tag = "agents"
219+
)]
142220
pub async fn delete_agent(
143221
State(provider): State<Arc<dyn RuntimeApiProvider>>,
144222
Path(agent_id): Path<AgentId>,
@@ -158,6 +236,19 @@ pub async fn delete_agent(
158236

159237
/// Execute agent endpoint handler
160238
#[cfg(feature = "http-api")]
239+
#[utoipa::path(
240+
post,
241+
path = "/api/v1/agents/{id}/execute",
242+
params(
243+
("id" = AgentId, Path, description = "Agent identifier")
244+
),
245+
request_body = ExecuteAgentRequest,
246+
responses(
247+
(status = 200, description = "Agent executed successfully", body = ExecuteAgentResponse),
248+
(status = 500, description = "Internal server error", body = ErrorResponse)
249+
),
250+
tag = "agents"
251+
)]
161252
pub async fn execute_agent(
162253
State(provider): State<Arc<dyn RuntimeApiProvider>>,
163254
Path(agent_id): Path<AgentId>,
@@ -178,6 +269,18 @@ pub async fn execute_agent(
178269

179270
/// Get agent execution history endpoint handler
180271
#[cfg(feature = "http-api")]
272+
#[utoipa::path(
273+
get,
274+
path = "/api/v1/agents/{id}/history",
275+
params(
276+
("id" = AgentId, Path, description = "Agent identifier")
277+
),
278+
responses(
279+
(status = 200, description = "Agent history retrieved successfully", body = GetAgentHistoryResponse),
280+
(status = 500, description = "Internal server error", body = ErrorResponse)
281+
),
282+
tag = "agents"
283+
)]
181284
pub async fn get_agent_history(
182285
State(provider): State<Arc<dyn RuntimeApiProvider>>,
183286
Path(agent_id): Path<AgentId>,

0 commit comments

Comments
 (0)