magi-code 0.63.1

Repository-aware CLI coding agent for terminal work
Documentation
mod bodies;
mod catalog;
mod codex;
mod compatible;
mod headers;

#[cfg(test)]
mod tests;

pub use codex::OpenAiCodexProvider;
pub(crate) use codex::{CodexRefreshedAuth, codex_account_id_for, normalize_codex_model};
pub use compatible::OpenAiCompatibleProvider;

#[cfg(test)]
pub(crate) use bodies::openai_compatible_responses_body;
pub(crate) use bodies::{
    codex_responses_body, openai_compatible_chat_completions_body, response_instructions,
};
pub(crate) use catalog::fetch_model_catalog_response_text_cancellable;
#[cfg(test)]
pub(crate) use catalog::{
    extract_chatgpt_account_id, parse_codex_model_catalog_response,
    parse_openai_compatible_model_catalog_response,
};
pub(crate) use headers::{codex_sse_headers, package_user_agent};

use crate::{
    agent::cancellation::AgentCancellation,
    providers::{ProviderEvent, ProviderRequest},
};

/// ChatGPT/Codex backend compatibility version for model catalog discovery.
///
/// The Codex `/models` endpoint gates the returned account-available catalog by
/// client version. The crate package version is not a Codex client version and
/// can cause the backend to return an artificially narrow catalog.
pub(crate) const CODEX_MODEL_CATALOG_CLIENT_VERSION: &str = "0.144.0";

pub trait Provider: Send + Sync {
    #[cfg(test)]
    fn anthropic_cache_ttl_for_test(&self) -> Option<crate::config::AnthropicCacheTtl> {
        None
    }

    #[allow(dead_code)]
    fn stream(
        &self,
        request: ProviderRequest,
        on_event: &mut dyn FnMut(ProviderEvent) -> anyhow::Result<()>,
    ) -> anyhow::Result<()> {
        self.stream_cancellable(request, &AgentCancellation::default(), on_event)
    }

    fn stream_cancellable(
        &self,
        request: ProviderRequest,
        cancellation: &AgentCancellation,
        on_event: &mut dyn FnMut(ProviderEvent) -> anyhow::Result<()>,
    ) -> anyhow::Result<()>;
}