Skip to main content

normalize_ai_provider

Function normalize_ai_provider 

Source
pub fn normalize_ai_provider(value: &str) -> String
Expand 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:

  1. subx config set ai.provider <value> — the persisted on-disk value is the canonical form.
  2. subx config get ai.provider — returns the canonical form.
  3. ProductionConfigService env-var loading — SUBX_AI_PROVIDER=ollama is normalized before any precedence or scoping decision (including the hosted-provider env-var carve-out for local).
  4. validate_ai_config — validation arms key off the canonical value.
  5. 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");