rho-coding-agent 3.11.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! A person's answer to a secret ask (`mcp_request_secret`): the daemon
//! stores the value where `rho/mcp/secret/set` does, then tells the turn
//! only that it stored it, so the value never reaches the session, its
//! transcript, its hooks, or other clients.

use std::sync::Arc;

use rho_protocol::{InputRequestId, RpcError, SecretValue};

use super::{inputs::invalid, LoadedSession};
use crate::app::daemon_host::mcp_secrets;

/// Stores `value` for secret ask `request`, which stays open while it is
/// stored and is answered once it is. An empty value, or a request that is
/// not an open secret ask, leaves the request as it was. A store that fails
/// fails the answer and leaves the request open, so the person may give the
/// value again or decline.
pub(super) async fn answer(
    session: &Arc<LoadedSession>,
    request: InputRequestId,
    value: SecretValue,
) -> Result<(), RpcError> {
    if value.expose().is_empty() {
        return Err(invalid("a secret must not be empty"));
    }
    let slot = session.change_inputs(|inputs| inputs.begin_secret(request))?;
    let stored = mcp_secrets::store(slot.server, slot.name, value.expose().to_owned()).await;
    session.change_inputs(|inputs| inputs.end_secret(request, stored.is_ok()));
    stored
}