From 673725a69c7506084a9ddfba059441a8365e6038 Mon Sep 17 00:00:00 2001 From: Elka Firmanda <74169235+elka-firmanda@users.noreply.github.com> Date: Wed, 11 Nov 2026 10:39:01 +0800 Subject: [PATCH 1/3] feat: add GPT-6 provider models Register GPT-6 and GPT-6.1 models for OpenAI and Codex, and route GPT-6 models through the Responses API. --- crates/forge_repo/src/provider/chat.rs | 33 ++++- crates/forge_repo/src/provider/provider.json | 120 +++++++++++++++++++ 2 files changed, 152 insertions(+), 1 deletion(-) diff --git a/crates/forge_repo/src/provider/chat.rs b/crates/forge_repo/src/provider/chat.rs index 9608f81868..0bc8aad833 100644 --- a/crates/forge_repo/src/provider/chat.rs +++ b/crates/forge_repo/src/provider/chat.rs @@ -141,7 +141,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) @@ -194,6 +194,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 +222,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/provider.json b/crates/forge_repo/src/provider/provider.json index d99127ce53..9a36d0fa87 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", From 653b05ec0a8d549a54e2cdc349ba4e0159e65705 Mon Sep 17 00:00:00 2001 From: Elka Firmanda <74169235+elka-firmanda@users.noreply.github.com> Date: Wed, 11 Nov 2026 10:41:24 +0800 Subject: [PATCH 2/3] feat: add Command Code provider support Register Command Code as a built-in OpenAI provider and filter models by supported endpoint, excluding models that do not serve chat completions. --- crates/forge_app/src/dto/openai/model.rs | 50 +++++++++++++++++++ crates/forge_domain/src/provider.rs | 24 +++++++++ crates/forge_repo/src/provider/openai.rs | 7 ++- crates/forge_repo/src/provider/provider.json | 9 ++++ .../forge_repo/src/provider/provider_repo.rs | 29 +++++++++++ 5 files changed, 118 insertions(+), 1 deletion(-) diff --git a/crates/forge_app/src/dto/openai/model.rs b/crates/forge_app/src/dto/openai/model.rs index 3e82d9d95c..42fbef981e 100644 --- a/crates/forge_app/src/dto/openai/model.rs +++ b/crates/forge_app/src/dto/openai/model.rs @@ -40,6 +40,9 @@ pub struct Model { pub top_provider: Option, pub per_request_limits: Option, pub supported_parameters: Option>, + /// Routes the provider serves this model on, e.g. `/chat/completions`. + /// Absent for providers that do not report per-model routes. + pub supported_endpoints: Option>, } #[derive(Debug, Deserialize, Serialize, Clone)] @@ -94,6 +97,21 @@ pub struct ListModelResponse { pub data: Vec, } +impl Model { + /// Whether the provider serves this model on the chat completions route. + /// + /// Providers that multiplex several protocols on one endpoint (e.g. + /// Command Code serves OpenAI chat and Anthropic messages from the same + /// host) report the routes each model answers in `supported_endpoints`. + /// Models that do not declare routes are assumed to support chat + /// completions, since most providers omit the field. + pub fn serves_chat_completions(&self) -> bool { + self.supported_endpoints.as_ref().is_none_or(|endpoints| { + endpoints.is_empty() || endpoints.iter().any(|e| e.ends_with("chat/completions")) + }) + } +} + impl From for forge_domain::Model { fn from(value: Model) -> Self { let has_param = |name: &str| { @@ -185,6 +203,7 @@ mod tests { top_provider: None, per_request_limits: None, supported_parameters: None, + supported_endpoints: None, }; assert_eq!(actual.id, expected.id); @@ -304,6 +323,35 @@ mod tests { assert_eq!(actual.pricing.as_ref().unwrap().prompt, Some(0.0015)); assert_eq!(actual.pricing.as_ref().unwrap().completion, Some(0.0002)); } + #[test] + fn test_serves_chat_completions() { + // Models that declare routes only serve the declared ones. + let fixture = serde_json::json!({ + "id": "claude-sonnet-5", + "supported_endpoints": ["/messages"] + }); + let actual = serde_json::from_value::(fixture) + .unwrap() + .serves_chat_completions(); + assert!(!actual); + + let fixture = serde_json::json!({ + "id": "gpt-5.4", + "supported_endpoints": ["/chat/completions", "/responses"] + }); + let actual = serde_json::from_value::(fixture) + .unwrap() + .serves_chat_completions(); + assert!(actual); + + // Providers that omit the field are assumed to serve chat. + let fixture = serde_json::json!({ "id": "some-model" }); + let actual = serde_json::from_value::(fixture) + .unwrap() + .serves_chat_completions(); + assert!(actual); + } + #[tokio::test] async fn test_model_conversion_without_supported_parameters() { let model = Model { @@ -317,6 +365,7 @@ mod tests { top_provider: None, per_request_limits: None, supported_parameters: None, // No supported_parameters field + supported_endpoints: None, }; let domain_model: forge_domain::Model = model.into(); @@ -345,6 +394,7 @@ mod tests { "reasoning".to_string(), // Note: "supports_parallel_tool_calls" is not included ]), + supported_endpoints: None, }; let domain_model: forge_domain::Model = model.into(); diff --git a/crates/forge_domain/src/provider.rs b/crates/forge_domain/src/provider.rs index 0cdff67c96..7f45753860 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())), }; @@ -839,6 +843,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/openai.rs b/crates/forge_repo/src/provider/openai.rs index ad189181d5..4a84cb1977 100644 --- a/crates/forge_repo/src/provider/openai.rs +++ b/crates/forge_repo/src/provider/openai.rs @@ -306,7 +306,12 @@ impl OpenAIProvider { let data: ListModelResponse = serde_json::from_str(&response) .with_context(|| format_http_context(None, "GET", url)) .with_context(|| "Failed to deserialize models response")?; - Ok(data.data.into_iter().map(Into::into).collect()) + Ok(data + .data + .into_iter() + .filter(|model| model.serves_chat_completions()) + .map(Into::into) + .collect()) } } } diff --git a/crates/forge_repo/src/provider/provider.json b/crates/forge_repo/src/provider/provider.json index 9a36d0fa87..abfdbd1ad3 100644 --- a/crates/forge_repo/src/provider/provider.json +++ b/crates/forge_repo/src/provider/provider.json @@ -4242,5 +4242,14 @@ } ], "auth_methods": ["api_key"] + }, + { + "id": "command_code", + "api_key_vars": "COMMAND_CODE_API_KEY", + "url_param_vars": [], + "response_type": "OpenAI", + "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..424eba00d0 100644 --- a/crates/forge_repo/src/provider/provider_repo.rs +++ b/crates/forge_repo/src/provider/provider_repo.rs @@ -1021,6 +1021,35 @@ 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::OpenAI)); + assert_eq!( + config.url.as_str(), + "https://api.commandcode.ai/provider/v1/chat/completions" + ); + // Claude models on Command Code only answer on /messages, so the + // model list is fetched and filtered by supported endpoint instead + // of being hardcoded. + 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(); From 3d074b5d673397f81608b99e535458b1b3a44297 Mon Sep 17 00:00:00 2001 From: Elka Firmanda <74169235+elka-firmanda@users.noreply.github.com> Date: Wed, 11 Nov 2026 18:40:44 +0800 Subject: [PATCH 3/3] refactor: route Command Code like OpenCode Zen Drop the supported_endpoints model capability from the shared OpenAI DTO and the resulting model filter. Command Code now gets its own response repository that routes Claude models to the Anthropic /messages endpoint and every other model to /chat/completions, mirroring how OpenCode Zen is handled. This also stops hiding the Claude models that only answer on /messages. Co-Authored-By: ForgeCode --- crates/forge_app/src/dto/openai/model.rs | 50 ------- crates/forge_config/src/config.rs | 1 + crates/forge_domain/src/provider.rs | 1 + crates/forge_repo/src/provider/chat.rs | 10 ++ .../forge_repo/src/provider/command_code.rs | 124 ++++++++++++++++++ crates/forge_repo/src/provider/mod.rs | 1 + crates/forge_repo/src/provider/openai.rs | 7 +- crates/forge_repo/src/provider/provider.json | 2 +- .../forge_repo/src/provider/provider_repo.rs | 8 +- 9 files changed, 143 insertions(+), 61 deletions(-) create mode 100644 crates/forge_repo/src/provider/command_code.rs diff --git a/crates/forge_app/src/dto/openai/model.rs b/crates/forge_app/src/dto/openai/model.rs index 42fbef981e..3e82d9d95c 100644 --- a/crates/forge_app/src/dto/openai/model.rs +++ b/crates/forge_app/src/dto/openai/model.rs @@ -40,9 +40,6 @@ pub struct Model { pub top_provider: Option, pub per_request_limits: Option, pub supported_parameters: Option>, - /// Routes the provider serves this model on, e.g. `/chat/completions`. - /// Absent for providers that do not report per-model routes. - pub supported_endpoints: Option>, } #[derive(Debug, Deserialize, Serialize, Clone)] @@ -97,21 +94,6 @@ pub struct ListModelResponse { pub data: Vec, } -impl Model { - /// Whether the provider serves this model on the chat completions route. - /// - /// Providers that multiplex several protocols on one endpoint (e.g. - /// Command Code serves OpenAI chat and Anthropic messages from the same - /// host) report the routes each model answers in `supported_endpoints`. - /// Models that do not declare routes are assumed to support chat - /// completions, since most providers omit the field. - pub fn serves_chat_completions(&self) -> bool { - self.supported_endpoints.as_ref().is_none_or(|endpoints| { - endpoints.is_empty() || endpoints.iter().any(|e| e.ends_with("chat/completions")) - }) - } -} - impl From for forge_domain::Model { fn from(value: Model) -> Self { let has_param = |name: &str| { @@ -203,7 +185,6 @@ mod tests { top_provider: None, per_request_limits: None, supported_parameters: None, - supported_endpoints: None, }; assert_eq!(actual.id, expected.id); @@ -323,35 +304,6 @@ mod tests { assert_eq!(actual.pricing.as_ref().unwrap().prompt, Some(0.0015)); assert_eq!(actual.pricing.as_ref().unwrap().completion, Some(0.0002)); } - #[test] - fn test_serves_chat_completions() { - // Models that declare routes only serve the declared ones. - let fixture = serde_json::json!({ - "id": "claude-sonnet-5", - "supported_endpoints": ["/messages"] - }); - let actual = serde_json::from_value::(fixture) - .unwrap() - .serves_chat_completions(); - assert!(!actual); - - let fixture = serde_json::json!({ - "id": "gpt-5.4", - "supported_endpoints": ["/chat/completions", "/responses"] - }); - let actual = serde_json::from_value::(fixture) - .unwrap() - .serves_chat_completions(); - assert!(actual); - - // Providers that omit the field are assumed to serve chat. - let fixture = serde_json::json!({ "id": "some-model" }); - let actual = serde_json::from_value::(fixture) - .unwrap() - .serves_chat_completions(); - assert!(actual); - } - #[tokio::test] async fn test_model_conversion_without_supported_parameters() { let model = Model { @@ -365,7 +317,6 @@ mod tests { top_provider: None, per_request_limits: None, supported_parameters: None, // No supported_parameters field - supported_endpoints: None, }; let domain_model: forge_domain::Model = model.into(); @@ -394,7 +345,6 @@ mod tests { "reasoning".to_string(), // Note: "supports_parallel_tool_calls" is not included ]), - supported_endpoints: None, }; let domain_model: forge_domain::Model = model.into(); 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 7f45753860..67343ffe5e 100644 --- a/crates/forge_domain/src/provider.rs +++ b/crates/forge_domain/src/provider.rs @@ -260,6 +260,7 @@ pub enum ProviderResponse { Bedrock, Google, OpenCode, + CommandCode, } /// Represents the source of models for a provider diff --git a/crates/forge_repo/src/provider/chat.rs b/crates/forge_repo/src/provider/chat.rs index 0bc8aad833..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 { @@ -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 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/openai.rs b/crates/forge_repo/src/provider/openai.rs index 4a84cb1977..ad189181d5 100644 --- a/crates/forge_repo/src/provider/openai.rs +++ b/crates/forge_repo/src/provider/openai.rs @@ -306,12 +306,7 @@ impl OpenAIProvider { let data: ListModelResponse = serde_json::from_str(&response) .with_context(|| format_http_context(None, "GET", url)) .with_context(|| "Failed to deserialize models response")?; - Ok(data - .data - .into_iter() - .filter(|model| model.serves_chat_completions()) - .map(Into::into) - .collect()) + Ok(data.data.into_iter().map(Into::into).collect()) } } } diff --git a/crates/forge_repo/src/provider/provider.json b/crates/forge_repo/src/provider/provider.json index abfdbd1ad3..b8f6abd1e8 100644 --- a/crates/forge_repo/src/provider/provider.json +++ b/crates/forge_repo/src/provider/provider.json @@ -4247,7 +4247,7 @@ "id": "command_code", "api_key_vars": "COMMAND_CODE_API_KEY", "url_param_vars": [], - "response_type": "OpenAI", + "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 424eba00d0..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 { @@ -1034,14 +1035,13 @@ mod tests { Some("COMMAND_CODE_API_KEY".to_string()) ); assert!(config.url_param_vars.is_empty()); - assert_eq!(config.response_type, Some(ProviderResponse::OpenAI)); + assert_eq!(config.response_type, Some(ProviderResponse::CommandCode)); assert_eq!( config.url.as_str(), "https://api.commandcode.ai/provider/v1/chat/completions" ); - // Claude models on Command Code only answer on /messages, so the - // model list is fetched and filtered by supported endpoint instead - // of being hardcoded. + // 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");