rho-coding-agent 3.12.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! The agent's v2 config options in v1 form, which the policy and the
//! shared select checks take ([`crate::acp_runtime::handshake::needs_setting`]).
//!
//! v2 renamed an option's `id` to `configId` and a select group's `group` to
//! `groupId`; the rest of a select, and a boolean, kept its shape.

use super::bridge;
use agent_client_protocol::{v1::schema as v1, v2::schema as v2};

/// Each of `options` in v1 form. An option of a kind v1 does not have is
/// left out, so a check of it fails as an unadvertised select.
pub(super) fn v1_options(options: &[v2::SessionConfigOption]) -> Vec<v1::SessionConfigOption> {
    options.iter().filter_map(v1_option).collect()
}

fn v1_option(option: &v2::SessionConfigOption) -> Option<v1::SessionConfigOption> {
    let kind = match &option.kind {
        v2::SessionConfigKind::Select(select) => v1::SessionConfigKind::Select(
            v1::SessionConfigSelect::new(select.current_value.to_string(), select_options(select)?),
        ),
        v2::SessionConfigKind::Boolean(boolean) => {
            v1::SessionConfigKind::Boolean(v1::SessionConfigBoolean::new(boolean.current_value))
        }
        _ => return None,
    };
    let category = match &option.category {
        Some(category) => Some(bridge(category).ok()?),
        None => None,
    };
    Some(
        v1::SessionConfigOption::new(option.config_id.to_string(), option.name.clone(), kind)
            .description(option.description.clone())
            .category(category)
            .meta(option.meta.clone()),
    )
}

fn select_options(select: &v2::SessionConfigSelect) -> Option<v1::SessionConfigSelectOptions> {
    let values = |options: &[v2::SessionConfigSelectOption]| -> Vec<_> {
        options
            .iter()
            .map(|option| {
                v1::SessionConfigSelectOption::new(option.value.to_string(), option.name.clone())
                    .description(option.description.clone())
                    .meta(option.meta.clone())
            })
            .collect()
    };
    match &select.options {
        v2::SessionConfigSelectOptions::Ungrouped(options) => Some(values(options).into()),
        v2::SessionConfigSelectOptions::Grouped(groups) => Some(
            groups
                .iter()
                .map(|group| {
                    v1::SessionConfigSelectGroup::new(
                        group.group_id.to_string(),
                        group.name.clone(),
                        values(&group.options),
                    )
                    .meta(group.meta.clone())
                })
                .collect::<Vec<_>>()
                .into(),
        ),
        _ => None,
    }
}