diff --git a/crates/forge_config/src/config.rs b/crates/forge_config/src/config.rs index 5c7ed51f90..6b3143a2d4 100644 --- a/crates/forge_config/src/config.rs +++ b/crates/forge_config/src/config.rs @@ -21,6 +21,7 @@ pub enum ProviderResponseType { Bedrock, Google, OpenCode, + CommandCode, } /// Category of a provider. diff --git a/crates/forge_domain/src/provider.rs b/crates/forge_domain/src/provider.rs index 0cdff67c96..67343ffe5e 100644 --- a/crates/forge_domain/src/provider.rs +++ b/crates/forge_domain/src/provider.rs @@ -88,6 +88,7 @@ impl ProviderId { pub const KIMI_CODING: ProviderId = ProviderId(Cow::Borrowed("kimi_coding")); pub const MOONSHOT: ProviderId = ProviderId(Cow::Borrowed("moonshot")); pub const ALIBABA_TOKEN_PLAN: ProviderId = ProviderId(Cow::Borrowed("alibaba_token_plan")); + pub const COMMAND_CODE: ProviderId = ProviderId(Cow::Borrowed("command_code")); /// Returns all built-in provider IDs /// @@ -135,6 +136,7 @@ impl ProviderId { ProviderId::KIMI_CODING, ProviderId::MOONSHOT, ProviderId::ALIBABA_TOKEN_PLAN, + ProviderId::COMMAND_CODE, ] } @@ -160,6 +162,7 @@ impl ProviderId { "codex" => "Codex".to_string(), "opencode_zen" => "OpenCode Zen".to_string(), "opencode_go" => "OpenCode Go".to_string(), + "command_code" => "Command Code".to_string(), "fireworks-ai" => "FireworksAI".to_string(), "fireworks-ai-firepass" => "FireworksAIFirepass".to_string(), "novita" => "Novita".to_string(), @@ -235,6 +238,7 @@ impl std::str::FromStr for ProviderId { "kimi_coding" => ProviderId::KIMI_CODING, "moonshot" => ProviderId::MOONSHOT, "alibaba_token_plan" => ProviderId::ALIBABA_TOKEN_PLAN, + "command_code" => ProviderId::COMMAND_CODE, // For custom providers, use Cow::Owned to avoid memory leaks custom => ProviderId(Cow::Owned(custom.to_string())), }; @@ -256,6 +260,7 @@ pub enum ProviderResponse { Bedrock, Google, OpenCode, + CommandCode, } /// Represents the source of models for a provider @@ -839,6 +844,26 @@ mod tests { assert_eq!(actual, expected); } + #[test] + fn test_command_code_display_name() { + let actual = ProviderId::COMMAND_CODE.to_string(); + let expected = "Command Code".to_string(); + assert_eq!(actual, expected); + } + + #[test] + fn test_command_code_in_built_in_providers() { + let built_in = ProviderId::built_in_providers(); + assert!(built_in.contains(&ProviderId::COMMAND_CODE)); + } + + #[test] + fn test_command_code_from_str_roundtrip() { + let actual = ProviderId::from_str("command_code").unwrap(); + let expected = ProviderId::COMMAND_CODE; + assert_eq!(actual, expected); + } + #[test] fn test_io_intelligence() { let fixture = "test_key"; diff --git a/crates/forge_repo/src/provider/chat.rs b/crates/forge_repo/src/provider/chat.rs index 9608f81868..678bebe612 100644 --- a/crates/forge_repo/src/provider/chat.rs +++ b/crates/forge_repo/src/provider/chat.rs @@ -11,6 +11,7 @@ use url::Url; use crate::provider::anthropic::AnthropicResponseRepository; use crate::provider::bedrock::BedrockResponseRepository; +use crate::provider::command_code::CommandCodeResponseRepository; use crate::provider::google::GoogleResponseRepository; use crate::provider::openai::OpenAIResponseRepository; use crate::provider::openai_responses::OpenAIResponsesResponseRepository; @@ -42,6 +43,7 @@ impl + HttpInfra> ForgeC BedrockResponseRepository::new(Arc::new(config.retry.unwrap_or_default())); let google_repo = GoogleResponseRepository::new(infra.clone()); let opencode_zen_repo = OpenCodeZenResponseRepository::new(infra.clone()); + let command_code_repo = CommandCodeResponseRepository::new(infra.clone()); let model_cache = Arc::new(CacacheStorage::new( env.cache_dir().join("model_cache"), @@ -56,6 +58,7 @@ impl + HttpInfra> ForgeC bedrock_repo, google_repo, opencode_zen_repo, + command_code_repo, }), model_cache, bg_refresh: BgRefresh::default(), @@ -129,6 +132,7 @@ struct ProviderRouter { bedrock_repo: BedrockResponseRepository, google_repo: GoogleResponseRepository, opencode_zen_repo: OpenCodeZenResponseRepository, + command_code_repo: CommandCodeResponseRepository, } impl + Sync> ProviderRouter { @@ -141,7 +145,7 @@ impl + Sync> match provider.response { Some(ProviderResponse::OpenAI) => { // Check if model is a Codex model - if model_id.as_str().contains("gpt-5") + if uses_responses_api(model_id.as_str()) && (provider.id == ProviderId::OPENAI || provider.id == ProviderId::GITHUB_COPILOT || provider.id == ProviderId::CODEX) @@ -171,6 +175,11 @@ impl + Sync> .chat(model_id, context, provider) .await } + Some(ProviderResponse::CommandCode) => { + self.command_code_repo + .chat(model_id, context, provider) + .await + } None => Err(anyhow::anyhow!( "Provider response type not configured for provider: {}", provider.id @@ -186,6 +195,7 @@ impl + Sync> Some(ProviderResponse::Bedrock) => self.bedrock_repo.models(provider).await, Some(ProviderResponse::Google) => self.google_repo.models(provider).await, Some(ProviderResponse::OpenCode) => self.opencode_zen_repo.models(provider).await, + Some(ProviderResponse::CommandCode) => self.command_code_repo.models(provider).await, None => Err(anyhow::anyhow!( "Provider response type not configured for provider: {}", provider.id @@ -194,6 +204,12 @@ impl + Sync> } } +/// Returns `true` when an OpenAI-compatible model must be served by the +/// Responses API rather than Chat Completions. +fn uses_responses_api(model: &str) -> bool { + model.contains("gpt-5") || model.contains("gpt-6") +} + /// Tracks abort handles for background tasks and cancels them on drop. #[derive(Default)] struct BgRefresh(std::sync::Mutex>); @@ -216,3 +232,28 @@ impl Drop for BgRefresh { } } } + +#[cfg(test)] +mod tests { + use pretty_assertions::assert_eq; + + use super::*; + + #[test] + fn test_uses_responses_api() { + let fixture = [ + "gpt-5.6-luna", + "gpt-6-astra", + "gpt-6-sol", + "gpt-6-luna", + "gpt-6-cyber", + "gpt-6.1-sol", + "gpt-6.1-terra", + "openai/gpt-6-luna", + "gpt-4o", + ]; + let actual: Vec = fixture.iter().map(|m| uses_responses_api(m)).collect(); + let expected = vec![true, true, true, true, true, true, true, true, false]; + assert_eq!(actual, expected); + } +} diff --git a/crates/forge_repo/src/provider/command_code.rs b/crates/forge_repo/src/provider/command_code.rs new file mode 100644 index 0000000000..82e890d995 --- /dev/null +++ b/crates/forge_repo/src/provider/command_code.rs @@ -0,0 +1,124 @@ +use std::sync::Arc; + +use anyhow::Result; +use forge_app::domain::{ + ChatCompletionMessage, Context as ChatContext, Model, ModelId, Provider, ProviderResponse, + ResultStream, +}; +use forge_app::{EnvironmentInfra, HttpInfra}; +use forge_domain::ChatRepository; +use url::Url; + +use crate::provider::anthropic::AnthropicResponseRepository; +use crate::provider::openai::OpenAIResponseRepository; + +/// Command Code serves multiple protocols from one host: Claude models answer +/// only on the Anthropic `/messages` route, while every other model answers on +/// `/chat/completions`. Routes by model ID and derives the endpoint from the +/// configured chat completions URL. +pub struct CommandCodeResponseRepository { + openai_repo: OpenAIResponseRepository, + anthropic_repo: AnthropicResponseRepository, +} + +impl + Sync> + CommandCodeResponseRepository +{ + /// # Arguments + /// + /// * `infra` - Infrastructure providing environment and HTTP capabilities + pub fn new(infra: Arc) -> Self { + Self { + openai_repo: OpenAIResponseRepository::new(infra.clone()), + anthropic_repo: AnthropicResponseRepository::new(infra), + } + } + + pub async fn chat( + &self, + model_id: &ModelId, + context: ChatContext, + provider: Provider, + ) -> ResultStream { + let adapted_provider = build_provider(&provider, model_id); + if is_anthropic_model(model_id) { + self.anthropic_repo + .chat(model_id, context, adapted_provider) + .await + } else { + self.openai_repo + .chat(model_id, context, adapted_provider) + .await + } + } + + /// Fetches the model list from the OpenAI-compatible `/models` endpoint. + /// + /// The endpoint reports every model the account can use, including Claude + /// models that only answer on `/messages`. + pub async fn models(&self, provider: Provider) -> Result> { + self.openai_repo.models(provider).await + } +} + +/// Returns `true` when the model answers only on the Anthropic messages route. +fn is_anthropic_model(model_id: &ModelId) -> bool { + model_id.as_str().starts_with("claude-") +} + +/// Rewrites the configured chat completions URL to the Anthropic messages +/// route for Claude models. +fn build_provider(provider: &Provider, model_id: &ModelId) -> Provider { + let mut new_provider = provider.clone(); + if is_anthropic_model(model_id) { + new_provider.url = messages_url(&provider.url); + new_provider.response = Some(ProviderResponse::Anthropic); + } + new_provider +} + +/// Derives the messages endpoint from a chat completions endpoint URL. +fn messages_url(chat_url: &Url) -> Url { + let base = chat_url + .as_str() + .trim_end_matches('/') + .trim_end_matches("/chat/completions"); + Url::parse(&format!("{base}/messages")).unwrap() +} + +#[cfg(test)] +mod tests { + use pretty_assertions::assert_eq; + + use super::*; + + #[test] + fn test_model_routing() { + let fixture = [ + ("claude-opus-5", true), + ("claude-sonnet-5-5", true), + ("gpt-6-astra", false), + ("deepseek/deepseek-v4-pro", false), + ("z-ai/glm-5.3-flash", false), + ]; + + let actual: Vec = fixture + .iter() + .map(|(model_id, _)| is_anthropic_model(&ModelId::new(*model_id))) + .collect(); + let expected: Vec = fixture.iter().map(|(_, expected)| *expected).collect(); + + assert_eq!(actual, expected); + } + + #[test] + fn test_messages_url() { + let fixture = + Url::parse("https://api.commandcode.ai/provider/v1/chat/completions").unwrap(); + + let actual = messages_url(&fixture); + + let expected = Url::parse("https://api.commandcode.ai/provider/v1/messages").unwrap(); + assert_eq!(actual, expected); + } +} diff --git a/crates/forge_repo/src/provider/mod.rs b/crates/forge_repo/src/provider/mod.rs index cd24f07887..7872b65781 100644 --- a/crates/forge_repo/src/provider/mod.rs +++ b/crates/forge_repo/src/provider/mod.rs @@ -3,6 +3,7 @@ mod bedrock; mod bedrock_cache; mod bedrock_sanitize_ids; mod chat; +mod command_code; mod event; mod google; #[cfg(test)] diff --git a/crates/forge_repo/src/provider/provider.json b/crates/forge_repo/src/provider/provider.json index d99127ce53..b8f6abd1e8 100644 --- a/crates/forge_repo/src/provider/provider.json +++ b/crates/forge_repo/src/provider/provider.json @@ -548,6 +548,66 @@ "supports_parallel_tool_calls": true, "supports_reasoning": true, "input_modalities": ["text", "image"] + }, + { + "id": "gpt-6-astra", + "name": "GPT-6 Astra", + "description": "Our most capable model for the most demanding work", + "context_length": 1050000, + "tools_supported": true, + "supports_parallel_tool_calls": true, + "supports_reasoning": true, + "input_modalities": ["text", "image"] + }, + { + "id": "gpt-6-sol", + "name": "GPT-6 Sol", + "description": "Built to power complex coding and agentic workflows", + "context_length": 1050000, + "tools_supported": true, + "supports_parallel_tool_calls": true, + "supports_reasoning": true, + "input_modalities": ["text", "image"] + }, + { + "id": "gpt-6-luna", + "name": "GPT-6 Luna", + "description": "Our most efficient model for focused, high-volume tasks", + "context_length": 1050000, + "tools_supported": true, + "supports_parallel_tool_calls": true, + "supports_reasoning": true, + "input_modalities": ["text", "image"] + }, + { + "id": "gpt-6-cyber", + "name": "GPT-6 Cyber", + "description": "Cybersecurity model for authorized vulnerability research and security testing", + "context_length": 1050000, + "tools_supported": true, + "supports_parallel_tool_calls": true, + "supports_reasoning": true, + "input_modalities": ["text", "image"] + }, + { + "id": "gpt-6.1-sol", + "name": "GPT-6.1 Sol", + "description": "Near-Astra performance for complex work at a lower cost", + "context_length": 1050000, + "tools_supported": true, + "supports_parallel_tool_calls": true, + "supports_reasoning": true, + "input_modalities": ["text", "image"] + }, + { + "id": "gpt-6.1-terra", + "name": "GPT-6.1 Terra", + "description": "Fast, efficient model for visual reasoning, precise computer use, and clear writing", + "context_length": 1050000, + "tools_supported": true, + "supports_parallel_tool_calls": true, + "supports_reasoning": true, + "input_modalities": ["text", "image"] } ], "auth_methods": ["api_key"] @@ -2702,6 +2762,66 @@ "response_type": "OpenAI", "url": "https://chatgpt.com/backend-api/codex/responses", "models": [ + { + "id": "gpt-6-astra", + "name": "GPT-6 Astra", + "description": "Our most capable model for the most demanding work", + "context_length": 500000, + "tools_supported": true, + "supports_parallel_tool_calls": true, + "supports_reasoning": true, + "input_modalities": ["text", "image"] + }, + { + "id": "gpt-6-sol", + "name": "GPT-6 Sol", + "description": "Built to power complex coding and agentic workflows", + "context_length": 500000, + "tools_supported": true, + "supports_parallel_tool_calls": true, + "supports_reasoning": true, + "input_modalities": ["text", "image"] + }, + { + "id": "gpt-6-luna", + "name": "GPT-6 Luna", + "description": "Our most efficient model for focused, high-volume tasks", + "context_length": 500000, + "tools_supported": true, + "supports_parallel_tool_calls": true, + "supports_reasoning": true, + "input_modalities": ["text", "image"] + }, + { + "id": "gpt-6-cyber", + "name": "GPT-6 Cyber", + "description": "Cybersecurity model for authorized vulnerability research and security testing", + "context_length": 500000, + "tools_supported": true, + "supports_parallel_tool_calls": true, + "supports_reasoning": true, + "input_modalities": ["text", "image"] + }, + { + "id": "gpt-6.1-sol", + "name": "GPT-6.1 Sol", + "description": "Near-Astra performance for complex work at a lower cost", + "context_length": 500000, + "tools_supported": true, + "supports_parallel_tool_calls": true, + "supports_reasoning": true, + "input_modalities": ["text", "image"] + }, + { + "id": "gpt-6.1-terra", + "name": "GPT-6.1 Terra", + "description": "Fast, efficient model for visual reasoning, precise computer use, and clear writing", + "context_length": 500000, + "tools_supported": true, + "supports_parallel_tool_calls": true, + "supports_reasoning": true, + "input_modalities": ["text", "image"] + }, { "id": "gpt-5.6-luna", "name": "GPT-5.6 Luna", @@ -4122,5 +4242,14 @@ } ], "auth_methods": ["api_key"] + }, + { + "id": "command_code", + "api_key_vars": "COMMAND_CODE_API_KEY", + "url_param_vars": [], + "response_type": "CommandCode", + "url": "https://api.commandcode.ai/provider/v1/chat/completions", + "models": "https://api.commandcode.ai/provider/v1/models", + "auth_methods": ["api_key"] } ] diff --git a/crates/forge_repo/src/provider/provider_repo.rs b/crates/forge_repo/src/provider/provider_repo.rs index 7f4329315a..9c57d51255 100644 --- a/crates/forge_repo/src/provider/provider_repo.rs +++ b/crates/forge_repo/src/provider/provider_repo.rs @@ -198,6 +198,7 @@ impl From for ProviderConfig { forge_config::ProviderResponseType::Bedrock => ProviderResponse::Bedrock, forge_config::ProviderResponseType::Google => ProviderResponse::Google, forge_config::ProviderResponseType::OpenCode => ProviderResponse::OpenCode, + forge_config::ProviderResponseType::CommandCode => ProviderResponse::CommandCode, }); let models = entry.models.map(|m| match m { @@ -1021,6 +1022,34 @@ mod tests { } } + #[test] + fn test_command_code_config() { + let configs = get_provider_configs(); + let config = configs + .iter() + .find(|c| c.id == ProviderId::COMMAND_CODE) + .unwrap(); + assert_eq!(config.id, ProviderId::COMMAND_CODE); + assert_eq!( + config.api_key_vars, + Some("COMMAND_CODE_API_KEY".to_string()) + ); + assert!(config.url_param_vars.is_empty()); + assert_eq!(config.response_type, Some(ProviderResponse::CommandCode)); + assert_eq!( + config.url.as_str(), + "https://api.commandcode.ai/provider/v1/chat/completions" + ); + // The model list is discovered from the provider so new models appear + // without a release. + match config.models.as_ref().expect("models should be present") { + Models::Url(model_url) => { + assert_eq!(model_url, "https://api.commandcode.ai/provider/v1/models"); + } + other => panic!("expected URL-driven models, got {other:?}"), + } + } + #[test] fn test_alibaba_token_plan_config() { let configs = get_provider_configs();