artifactize-harness 0.27.0

The Agent evaluation harness for Artifactize.
Documentation
//! The wire APIs artifactize speaks, and what each accepts.

use crate::backend::Provider;

/// The API a review's requests use: a built-in provider's, or a custom endpoint's.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Api {
    OpenaiResponses,
    OpenaiChat,
    Anthropic,
    Gemini,
    Codex,
    /// The user's own Claude Code, run as a subprocess (`llm::claude_agent`).
    ClaudeAgent,
}

impl From<Provider> for Api {
    fn from(provider: Provider) -> Self {
        match provider {
            Provider::Openai => Self::OpenaiResponses,
            Provider::Anthropic => Self::Anthropic,
            Provider::Gemini => Self::Gemini,
            Provider::Codex => Self::Codex,
            Provider::ClaudeAgent => Self::ClaudeAgent,
        }
    }
}

pub use artifactize_provider::llm::EndpointApi;

use artifactize_provider::llm::Api as HttpApi;

impl From<HttpApi> for Api {
    fn from(api: HttpApi) -> Self {
        match api {
            HttpApi::OpenaiResponses => Self::OpenaiResponses,
            HttpApi::OpenaiChat => Self::OpenaiChat,
            HttpApi::Anthropic => Self::Anthropic,
            HttpApi::Gemini => Self::Gemini,
            HttpApi::Codex => Self::Codex,
        }
    }
}

impl From<EndpointApi> for Api {
    fn from(api: EndpointApi) -> Self {
        Self::from(HttpApi::from(api))
    }
}

impl Api {
    fn http(self) -> Option<HttpApi> {
        Some(match self {
            Self::OpenaiResponses => HttpApi::OpenaiResponses,
            Self::OpenaiChat => HttpApi::OpenaiChat,
            Self::Anthropic => HttpApi::Anthropic,
            Self::Gemini => HttpApi::Gemini,
            Self::Codex => HttpApi::Codex,
            Self::ClaudeAgent => return None,
        })
    }

    pub fn validate_reasoning(self, reasoning: &str) -> Result<(), String> {
        match self.http() {
            Some(api) => api.validate_reasoning(reasoning),
            None if matches!(reasoning, "low" | "medium" | "high" | "xhigh" | "max") => Ok(()),
            None => Err(format!(
                "Unsupported reasoning {reasoning:?} for {self:?}; effort is never remapped."
            )),
        }
    }
}

/// Checked request parameters, shared by reviews and their follow-ups.
pub fn parameters(
    api: Api,
    reasoning: Option<&str>,
    session: &str,
) -> Result<serde_json::Value, String> {
    if let Some(reasoning) = reasoning {
        api.validate_reasoning(reasoning)?;
    }
    Ok(parameters_unchecked(api, reasoning, session))
}

pub fn parameters_unchecked(api: Api, reasoning: Option<&str>, session: &str) -> serde_json::Value {
    use serde_json::json;
    if let Some(api) = api.http() {
        return artifactize_provider::llm::Client::parameters_unchecked(api, reasoning, session);
    }
    let mut value = json!({"thinking":"adaptive", "thinkingDisplay":"summarized"});
    if let Some(effort) = reasoning {
        value["effort"] = json!(effort);
    }
    value
}

pub fn output_format(api: Api, parameters: &mut serde_json::Value, schema: serde_json::Value) {
    if let Some(api) = api.http() {
        artifactize_provider::llm::Client::output_format(
            api,
            parameters,
            "artifactize_verdict",
            schema,
        );
    } else {
        parameters["jsonSchema"] = schema;
    }
}