car-ffi-common 0.24.1

Shared logic for FFI bindings (NAPI, PyO3) — JSON wrappers for verify, multi-agent, scheduler
//! Proxy for the daemon's `discovery.*` namespace (AgentDNS-style service
//! discovery). Thin [`DaemonClient`] calls.

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

/// `discovery.resolve` — resolve a natural-language need into ranked CAR-local
/// services, each named under the `agentdns://organization/category/name`
/// scheme. Returns `{ services: [{ identifier, name, kind, protocol, score,
/// similarity }], count }`. `limit` caps results (clamped to [1, 50]; None =
/// default 5).
pub async fn resolve(
    client: &DaemonClient,
    need: &str,
    limit: Option<u32>,
) -> Result<String, String> {
    let mut params = json!({ "need": need });
    if let Some(l) = limit {
        params["limit"] = json!(l);
    }
    client.call("discovery.resolve", params).await.and_then(to_string)
}