cots 0.2.0

Cots.ai SDK for Rust. cots::agents::AgentClient — configure once with tenant_id/agent_id, then guard() every governed action through the PEP/PDP before executing it.
Documentation
//! Proves `cots::agents` works inside an axum service.
//!
//! Run: cargo run --example with_axum
//! Then: curl -X POST localhost:8091/notify

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();
}