use crate::backend::Provider;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Api {
OpenaiResponses,
OpenaiChat,
Anthropic,
Gemini,
Codex,
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."
)),
}
}
}
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;
}
}