use std::sync::Arc;
use axum::{extract::State, routing::post, Json, Router};
use cots::agents::{AgentClient, AgentConfig, NormalizedAction};
async fn notify(State(agent): State<Arc<AgentClient>>) -> Json<serde_json::Value> {
let result = agent
.guard(NormalizedAction::new("Slack", "send_slack_message"), || async {
"sent (axum)"
})
.await;
match result {
Ok(r) => Json(serde_json::json!({
"action_event_id": r.action_event_id,
"decision": r.decision,
"outcome": format!("{:?}", r.outcome),
})),
Err(e) => Json(serde_json::json!({ "error": e.to_string() })),
}
}
#[tokio::main]
async fn main() {
let agent = Arc::new(AgentClient::new(AgentConfig::new("ten_demo", "agt_demo")));
let app = Router::new().route("/notify", post(notify)).with_state(agent);
let listener = tokio::net::TcpListener::bind("127.0.0.1:8091").await.unwrap();
println!("axum + cots::agents on http://127.0.0.1:8091");
axum::serve(listener, app).await.unwrap();
}