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 `parslee.*` namespace (Parslee platform
//! capabilities). Thin [`DaemonClient`] call — discovery runs in the daemon,
//! which holds the Parslee session and reaches api.parslee.ai / studio.parslee.ai.

use serde_json::json;

use crate::proxy::DaemonClient;

/// `parslee.capabilities` — discover what the signed-in Parslee account can do
/// (identity, m365 product entitlements, Studio reachability). Read-only.
/// Returns the daemon's JSON response serialized as a string.
pub async fn capabilities(client: &DaemonClient) -> Result<String, String> {
    client
        .call("parslee.capabilities", json!({}))
        .await
        .and_then(|v| serde_json::to_string(&v).map_err(|e| e.to_string()))
}

/// `parslee.m365.generate_document` — generate a Word document from a
/// natural-language brief and save it to the user's connected drive. Gated on
/// the `aie` entitlement. `document_type` defaults to `Report`. Returns the
/// daemon's JSON response (file id/name/url) serialized as a string.
#[allow(clippy::too_many_arguments)]
pub async fn m365_generate_document(
    client: &DaemonClient,
    content_brief: &str,
    output_file_path: &str,
    document_type: Option<&str>,
    title: Option<&str>,
    author: Option<&str>,
) -> Result<String, String> {
    let mut params = json!({
        "content_brief": content_brief,
        "output_file_path": output_file_path,
    });
    if let Some(v) = document_type {
        params["document_type"] = json!(v);
    }
    if let Some(v) = title {
        params["title"] = json!(v);
    }
    if let Some(v) = author {
        params["author"] = json!(v);
    }
    client
        .call("parslee.m365.generate_document", params)
        .await
        .and_then(|v| serde_json::to_string(&v).map_err(|e| e.to_string()))
}