magi-code 0.61.0

Repository-aware CLI coding agent for terminal work
Documentation
use crate::providers::anthropic::{
    ANTHROPIC_MESSAGES_URL, anthropic_messages_body_with_system_prefix,
    anthropic_messages_body_with_system_prefix_without_cache_control,
};
use crate::{
    config::AnthropicCacheTtl, model_catalog::resolve_claude_code_model_alias,
    providers::ProviderRequest, thinking::ThinkingLevel,
};
use serde_json::Value;

pub(crate) const CLAUDE_CODE_SYSTEM_PREFIX: &str =
    "You are Claude Code, Anthropic's official CLI for Claude.";

pub(crate) const CLAUDE_CODE_BILLING_HEADER: &str =
    "x-anthropic-billing-header: cc_version=2.1.185; cc_entrypoint=sdk-cli; cch=00000;";

pub(crate) fn claude_code_messages_body(
    model: &str,
    request: &ProviderRequest,
    is_oauth: bool,
    cache_ttl: Option<AnthropicCacheTtl>,
    max_output_tokens: Option<u64>,
) -> Value {
    let resolved_model = resolve_claude_code_model_alias(model);
    let oauth_system_prefix;
    let system_prefix = if is_oauth {
        oauth_system_prefix =
            format!("{CLAUDE_CODE_BILLING_HEADER}\n\n{CLAUDE_CODE_SYSTEM_PREFIX}");
        oauth_system_prefix.as_str()
    } else {
        CLAUDE_CODE_SYSTEM_PREFIX
    };
    match cache_ttl {
        Some(cache_ttl) => anthropic_messages_body_with_system_prefix(
            &resolved_model,
            request,
            Some(system_prefix),
            cache_ttl,
            max_output_tokens,
            ThinkingLevel::Default,
        ),
        None => anthropic_messages_body_with_system_prefix_without_cache_control(
            &resolved_model,
            request,
            Some(system_prefix),
            max_output_tokens,
        ),
    }
}

pub(crate) fn messages_url() -> String {
    format!("{ANTHROPIC_MESSAGES_URL}?beta=true")
}