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 actix-web service.
//!
//! Run: cargo run --example with_actix
//! Then: curl -X POST localhost:8090/notify

use actix_web::{post, web, App, HttpResponse, HttpServer, Responder};
use cots::agents::{AgentClient, AgentConfig, NormalizedAction};

#[post("/notify")]
async fn notify(agent: web::Data<AgentClient>) -> impl Responder {
    let result = agent
        .guard(NormalizedAction::new("Slack", "send_slack_message"), || async {
            "sent (actix)"
        })
        .await;

    match result {
        Ok(r) => HttpResponse::Ok().json(serde_json::json!({
            "action_event_id": r.action_event_id,
            "decision": r.decision,
            "outcome": format!("{:?}", r.outcome),
        })),
        Err(e) => HttpResponse::BadGateway().body(e.to_string()),
    }
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let agent = web::Data::new(AgentClient::new(AgentConfig::new("ten_demo", "agt_demo")));

    println!("actix-web + cots::agents on http://127.0.0.1:8090");
    HttpServer::new(move || App::new().app_data(agent.clone()).service(notify))
        .bind(("127.0.0.1", 8090))?
        .run()
        .await
}