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>,
decomposition_mode: Option<&str>,
sad_hints: Option<u32>,
sad_iterations: Option<u32>,
sad_convergence_jaccard: Option<f64>,
) -> Result<String, String> {
let mut params = json!({ "need": need, "invoke": invoke });
if let Some(m) = max_subtasks {
params["max_subtasks"] = json!(m);
}
if let Some(mode) = decomposition_mode {
params["decomposition_mode"] = json!(mode);
}
if let Some(h) = sad_hints {
params["sad_hints"] = json!(h);
}
if let Some(i) = sad_iterations {
params["sad_iterations"] = json!(i);
}
if let Some(j) = sad_convergence_jaccard {
params["sad_convergence_jaccard"] = json!(j);
}
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)
}