use crate::client::AgentTrustClient;
use crate::error::Result;
use crate::models::{
Agent, AgentListResponse, CreateAgentRequest, CreateAgentResponse, RevokeAgentRequest,
};
pub struct AgentsAPI<'a> {
pub(crate) client: &'a AgentTrustClient,
}
impl<'a> AgentsAPI<'a> {
pub fn create(&self, req: &CreateAgentRequest) -> Result<Agent> {
let resp: CreateAgentResponse = self.client.request("POST", "/api/v1/agents", Some(req))?;
Ok(resp.into_agent())
}
pub fn get(&self, agent_id: &str) -> Result<Agent> {
let path = format!("/api/v1/agents/{}", agent_id);
let resp: Agent = self.client.request("GET", &path, None::<&()>)?;
Ok(resp)
}
pub fn list(&self, org_id: Option<&str>) -> Result<Vec<Agent>> {
let path = match org_id {
Some(id) => format!("/api/v1/agents?org_id={}", id),
None => "/api/v1/agents".to_string(),
};
let resp: AgentListResponse = self.client.request("GET", &path, None::<&()>)?;
let agents = resp.agents.into_iter().map(|ad| ad.into_agent()).collect();
Ok(agents)
}
pub fn revoke(&self, agent_id: &str, reason: &str) -> Result<()> {
let path = format!("/api/v1/agents/{}/revoke", agent_id);
let body = RevokeAgentRequest {
reason: reason.to_string(),
};
self.client.request_no_response("POST", &path, Some(&body))
}
}
impl Default for CreateAgentRequest {
fn default() -> Self {
Self {
name: String::new(),
framework: "custom".to_string(),
capabilities: Vec::new(),
metadata: serde_json::Value::Object(serde_json::Map::new()),
org_id: None,
}
}
}