pub fn normalize_ai_provider(value: &str) -> StringExpand description
Normalize an ai.provider value to its canonical form.
This is the single alias-resolution point in the codebase. It
lowercases and trims its input and maps the alias "ollama" to the
canonical identifier "local". All other recognized providers
(openai, openrouter, azure-openai, local) pass through after
trimming and lowercasing. Unknown values pass through unchanged so
downstream allow-list validation still rejects them.
Every component that reads or writes ai.provider SHALL invoke this
helper before using the value:
subx config set ai.provider <value>— the persisted on-disk value is the canonical form.subx config get ai.provider— returns the canonical form.ProductionConfigServiceenv-var loading —SUBX_AI_PROVIDER=ollamais normalized before any precedence or scoping decision (including the hosted-provider env-var carve-out forlocal).validate_ai_config— validation arms key off the canonical value.ComponentFactory::create_ai_provider— the dispatch match arm uses the canonical value.
§Examples
use subx_cli::config::field_validator::normalize_ai_provider;
assert_eq!(normalize_ai_provider("ollama"), "local");
assert_eq!(normalize_ai_provider("OLLAMA"), "local");
assert_eq!(normalize_ai_provider(" ollama "), "local");
assert_eq!(normalize_ai_provider("openai"), "openai");
assert_eq!(normalize_ai_provider("Azure-OpenAI"), "azure-openai");
// Unknown values are returned trimmed+lowercased so the allow-list
// can still reject them with the existing error.
assert_eq!(normalize_ai_provider("grok"), "grok");