use serde_json::{json, Value};
use crate::proxy::DaemonClient;
fn to_string(v: Value) -> Result<String, String> {
serde_json::to_string(&v).map_err(|e| e.to_string())
}
pub async fn list(client: &DaemonClient) -> Result<String, String> {
client.call("declagents.list", json!({})).await.and_then(to_string)
}
pub async fn get(client: &DaemonClient, id: &str) -> Result<String, String> {
client
.call("declagents.get", json!({ "id": id }))
.await
.and_then(to_string)
}
pub async fn remove(client: &DaemonClient, id: &str) -> Result<String, String> {
client
.call("declagents.remove", json!({ "id": id }))
.await
.and_then(to_string)
}
pub async fn set_enabled(client: &DaemonClient, id: &str, enabled: bool) -> Result<String, String> {
client
.call("declagents.set_enabled", json!({ "id": id, "enabled": enabled }))
.await
.and_then(to_string)
}
pub async fn invoke(client: &DaemonClient, id: &str, input: &str) -> Result<String, String> {
client
.call("declagents.invoke", json!({ "id": id, "input": input }))
.await
.and_then(to_string)
}
pub async fn route(client: &DaemonClient, need: &str, invoke: bool) -> Result<String, String> {
client
.call("declagents.route", json!({ "need": need, "invoke": invoke }))
.await
.and_then(to_string)
}
pub async fn route_split(
client: &DaemonClient,
need: &str,
invoke: bool,
max_subtasks: Option<u32>,
) -> Result<String, String> {
let mut params = json!({ "need": need, "invoke": invoke });
if let Some(m) = max_subtasks {
params["max_subtasks"] = json!(m);
}
client.call("declagents.route_split", params).await.and_then(to_string)
}
pub async fn routing_stats(client: &DaemonClient) -> Result<String, String> {
client
.call("declagents.routing_stats", json!({}))
.await
.and_then(to_string)
}