agentic_server/handler/http/
conversations.rs1use axum::extract::{Request, State};
2use axum::response::{IntoResponse, Response};
3use serde_json::json;
4
5use agentic_core::executor::{ExecutorError, create_conversation};
6
7use super::super::common::{executor_error_response, extract_store, read_bytes};
8use crate::app::AppState;
9
10pub async fn conversations(State(state): State<AppState>, req: Request) -> Response {
11 let (_, body) = req.into_parts();
12 let bytes = match read_bytes(body).await {
13 Ok(b) => b,
14 Err(e) => return e,
15 };
16
17 if !extract_store(&bytes) {
18 return executor_error_response(ExecutorError::InvalidRequest("conversations require store=true".into()));
19 }
20
21 match create_conversation(&state.exec_ctx).await {
22 Ok(data) => axum::Json(json!({
23 "id": data.conversation_id,
24 "created_at": data.created_at,
25 "object": "conversation",
26 "metadata": {}
27 }))
28 .into_response(),
29 Err(e) => executor_error_response(e),
30 }
31}