use super::types::OpenCodeProviderType;
#[must_use]
pub fn strip_model_flag_prefix(model_flag: &str) -> &str {
let s = model_flag.trim();
if let Some(rest) = s.strip_prefix("-m=") {
return rest.trim();
}
if let Some(rest) = s.strip_prefix("--model=") {
return rest.trim();
}
if s == "-m" {
return "";
}
if let Some(rest) = s.strip_prefix("-m ") {
return rest.trim();
}
if let Some(rest) = s.strip_prefix("-m\t") {
return rest.trim();
}
if s == "--model" {
return "";
}
if let Some(rest) = s.strip_prefix("--model ") {
return rest.trim();
}
if let Some(rest) = s.strip_prefix("--model\t") {
return rest.trim();
}
s
}
impl OpenCodeProviderType {
#[must_use]
pub fn from_model_flag(model_flag: &str) -> Self {
let model = strip_model_flag_prefix(model_flag);
let prefix = model.split('/').next().unwrap_or("").to_lowercase();
match prefix.as_str() {
"opencode" => Self::OpenCodeZen,
"zai" | "zhipuai" => Self::ZaiDirect,
"zai-coding" | "zai-plan" => Self::ZaiCodingPlan,
"moonshot" | "kimi" => Self::Moonshot,
"minimax" => Self::MiniMax,
"anthropic" => Self::Anthropic,
"openai" => Self::OpenAI,
"google" => Self::Google,
"google-vertex" | "vertex" => Self::GoogleVertex,
"amazon-bedrock" | "bedrock" => Self::AmazonBedrock,
"azure-openai" | "azure" => Self::AzureOpenAI,
"copilot" | "github-copilot" => Self::GithubCopilot,
"groq" => Self::Groq,
"together" => Self::Together,
"fireworks" => Self::Fireworks,
"cerebras" => Self::Cerebras,
"sambanova" => Self::SambaNova,
"deep-infra" | "deepinfra" => Self::DeepInfra,
"openrouter" => Self::OpenRouter,
"cloudflare" | "cf" => Self::Cloudflare,
"vercel" => Self::Vercel,
"helicone" => Self::Helicone,
"zenmux" => Self::ZenMux,
"deepseek" => Self::DeepSeek,
"xai" | "grok" => Self::Xai,
"mistral" => Self::Mistral,
"cohere" => Self::Cohere,
"perplexity" => Self::Perplexity,
"ai21" => Self::AI21,
"venice-ai" | "venice" => Self::VeniceAI,
"huggingface" | "hf" => Self::HuggingFace,
"replicate" => Self::Replicate,
"baseten" => Self::Baseten,
"cortecs" => Self::Cortecs,
"scaleway" => Self::Scaleway,
"ovhcloud" | "ovh" => Self::OVHcloud,
"io-net" | "ionet" => Self::IONet,
"nebius" => Self::Nebius,
"sap-ai-core" | "sap" => Self::SapAICore,
"azure-cognitive-services" | "azure-cognitive" => Self::AzureCognitiveServices,
"ollama" => Self::Ollama,
"lmstudio" => Self::LMStudio,
"ollama-cloud" => Self::OllamaCloud,
"llama.cpp" | "llamacpp" | "llama-cpp" => Self::LlamaCpp,
_ => Self::Custom,
}
}
}