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 fn new(active: impl Into<CompactString>) -> Self
pub fn new(active: impl Into<CompactString>) -> Self
Create an empty manager with the given active model name.
Use add_provider() or add_config() to populate.
Sourcepub async fn from_configs(configs: &[ProviderConfig]) -> Result<Self>
pub async fn from_configs(configs: &[ProviderConfig]) -> Result<Self>
Create a manager from a list of remote 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 add_provider(
&self,
name: impl Into<CompactString>,
provider: Provider,
) -> Result<()>
pub fn add_provider( &self, name: impl Into<CompactString>, provider: Provider, ) -> Result<()>
Add a pre-built provider directly (e.g. local models from registry).
Sourcepub async fn add_config(&self, config: &ProviderConfig) -> Result<()>
pub async fn add_config(&self, config: &ProviderConfig) -> Result<()>
Add a remote provider from config. Validates and builds it.
Sourcepub fn active_model_name(&self) -> Result<CompactString>
pub fn active_model_name(&self) -> Result<CompactString>
Get the model name of the active provider (also its key).
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 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) -> Result<Vec<ProviderEntry>>
pub fn list(&self) -> Result<Vec<ProviderEntry>>
List all providers with their active status.
Sourcepub async fn wait_until_ready(&self) -> Result<()>
pub async fn wait_until_ready(&self) -> Result<()>
Wait until the active provider is ready.
No-op for remote providers. For local providers, blocks until the model finishes loading.
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. Falls back to the static default if the lock is poisoned.