pub struct ProviderManager { /* private fields */ }Expand description
Manages a set of named providers with an active selection.
All methods that read or mutate the inner state acquire the RwLock.
active() returns a clone of the current Provider — callers do not
hold the lock while performing LLM calls.
Implementations§
Source§impl ProviderManager
impl ProviderManager
Sourcepub async fn from_configs(configs: &[ProviderConfig]) -> Result<Self>
pub async fn from_configs(configs: &[ProviderConfig]) -> Result<Self>
Create a new manager from a list of provider configs.
The first element becomes the active provider. Returns an error if the slice is empty, any config fails validation, or any provider fails to build.
Sourcepub fn single(config: ProviderConfig, provider: Provider) -> Self
pub fn single(config: ProviderConfig, provider: Provider) -> Self
Create a manager with a single provider.
Sourcepub fn active_model(&self) -> CompactString
pub fn active_model(&self) -> CompactString
Get the model name of the active provider (also its key).
Sourcepub fn active_config(&self) -> ProviderConfig
pub fn active_config(&self) -> ProviderConfig
Get a clone of the active provider’s config.
Sourcepub fn switch(&self, model: &str) -> Result<()>
pub fn switch(&self, model: &str) -> Result<()>
Switch to a different provider by model name. Returns an error if the name is not found.
Sourcepub async fn add(&self, config: &ProviderConfig) -> Result<()>
pub async fn add(&self, config: &ProviderConfig) -> Result<()>
Add a new provider. Validates config first. Replaces any existing provider with the same model name.
Sourcepub fn remove(&self, model: &str) -> Result<()>
pub fn remove(&self, model: &str) -> Result<()>
Remove a provider by model name. Fails if the provider is currently active.
Sourcepub fn list(&self) -> Vec<ProviderEntry>
pub fn list(&self) -> Vec<ProviderEntry>
List all providers with their active status.
Sourcepub fn context_limit(&self, model: &str) -> usize
pub fn context_limit(&self, model: &str) -> usize
Resolve the context limit for a model.
Resolution chain: provider reports limit → static map → 8192 default.