pub struct ModelRegistry { /* private fields */ }Expand description
The shared model registry (see module docs).
Implementations§
Source§impl ModelRegistry
impl ModelRegistry
Sourcepub fn new(auth: Arc<AuthStorage>, options: ModelRegistryOptions) -> Self
pub fn new(auth: Arc<AuthStorage>, options: ModelRegistryOptions) -> Self
Creates a registry and loads models.json.
Sourcepub fn in_memory(env: Arc<dyn EnvSource>) -> Self
pub fn in_memory(env: Arc<dyn EnvSource>) -> Self
In-memory credentials, no models.json, no cache, the given environment.
Sourcepub fn auth_storage(&self) -> &Arc<AuthStorage> ⓘ
pub fn auth_storage(&self) -> &Arc<AuthStorage> ⓘ
The credential store.
Sourcepub fn set_oauth_refresher(&self, refresher: Arc<dyn OAuthRefresher>)
pub fn set_oauth_refresher(&self, refresher: Arc<dyn OAuthRefresher>)
Installs the OAuth refresher (the host’s bridge to oauth-refresh exports).
Sourcepub fn set_models_json(&self, models_json: ModelsJson)
pub fn set_models_json(&self, models_json: ModelsJson)
Replaces the models.json configuration without touching the file (tests, embedders).
Sourcepub fn error(&self) -> Option<String>
pub fn error(&self) -> Option<String>
models.json load error and per-provider composition errors, joined by
blank lines.
Sourcepub fn diagnostics(&self) -> Vec<RegistryDiagnostic>
pub fn diagnostics(&self) -> Vec<RegistryDiagnostic>
Oino diagnostics: models whose API no loaded provider component implements (these
models are never available).
Sourcepub fn register_provider(
&self,
extension_id: &str,
registration: ProviderRegistration,
) -> Result<(), RegistryError>
pub fn register_provider( &self, extension_id: &str, registration: ProviderRegistration, ) -> Result<(), RegistryError>
Registers (or replaces) a provider component’s registration
registerNativeProvider). A dynamic registration starts from the cached model list.
§Errors
Sourcepub fn register_api_implementor(&self, api: &str, extension_id: &str)
pub fn register_api_implementor(&self, api: &str, extension_id: &str)
Declares that extension_id’s component implements api (manifest provides.apis).
models.json providers using api stream through it.
Sourcepub fn set_provider_models(
&self,
provider: &str,
models: &[Model],
) -> Result<(), RegistryError>
pub fn set_provider_models( &self, provider: &str, models: &[Model], ) -> Result<(), RegistryError>
Sets a dynamic provider’s models (after list-models) and writes the cache.
§Errors
Unknown or static provider; cache write failures (models are applied regardless).
Sourcepub fn register_provider_config(
&self,
provider: &str,
config: ProviderConfigOverride,
) -> Result<(), RegistryError>
pub fn register_provider_config( &self, provider: &str, config: ProviderConfigOverride, ) -> Result<(), RegistryError>
Validates the override on its own, then merges its defined fields over the previous override. The provider’s registration is kept.
§Errors
RegistryError::InvalidConfig with the composition message; nothing is stored.
Sourcepub fn unregister_provider(&self, provider: &str)
pub fn unregister_provider(&self, provider: &str)
Removes the registration and the config override (virtual models stay).
Sourcepub fn unregister_extension(&self, extension_id: &str)
pub fn unregister_extension(&self, extension_id: &str)
Removes everything extension_id registered (providers, API implementations, virtual
models), e.g. when the extension unloads.
Sourcepub fn registered_providers(&self) -> Vec<String>
pub fn registered_providers(&self) -> Vec<String>
Providers with an override or a component registration.
Sourcepub fn registration(&self, provider: &str) -> Option<ProviderRegistration>
pub fn registration(&self, provider: &str) -> Option<ProviderRegistration>
A component registration.
Sourcepub fn registered_provider_config(
&self,
provider: &str,
) -> Option<ProviderConfigOverride>
pub fn registered_provider_config( &self, provider: &str, ) -> Option<ProviderConfigOverride>
Returns the registered provider config.
Sourcepub fn available(&self) -> Vec<Model>
pub fn available(&self) -> Vec<Model>
Models whose provider has credentials and whose API a provider component implements (virtual models: provider credentials only).
Sourcepub fn find_physical(&self, provider: &str, id: &str) -> Option<Model>
pub fn find_physical(&self, provider: &str, id: &str) -> Option<Model>
A catalog model that is not virtual.
Sourcepub fn provider_ids(&self) -> Vec<String>
pub fn provider_ids(&self) -> Vec<String>
Provider ids of the catalog in order.
Sourcepub fn provider_display_name(&self, provider: &str) -> String
pub fn provider_display_name(&self, provider: &str) -> String
Returns the provider display name.
Sourcepub fn route_target(&self, model: &Model) -> Option<String>
pub fn route_target(&self, model: &Model) -> Option<String>
The extension whose component streams model (None: no implementation loaded).
Sourcepub fn check_auth(&self, provider: &str) -> Option<AuthCheck>
pub fn check_auth(&self, provider: &str) -> Option<AuthCheck>
How a provider is authenticated, None when it is not.
Sourcepub fn has_configured_auth(&self, provider: &str) -> bool
pub fn has_configured_auth(&self, provider: &str) -> bool
Returns whether configured auth is present.
Sourcepub fn is_using_oauth(&self, provider: &str) -> bool
pub fn is_using_oauth(&self, provider: &str) -> bool
Returns whether it is using oauth.
Sourcepub fn auth_status(&self, provider: &str) -> AuthStatus
pub fn auth_status(&self, provider: &str) -> AuthStatus
Returns the provider auth status.
Sourcepub fn set_runtime_api_key(&self, provider: &str, key: impl Into<String>)
pub fn set_runtime_api_key(&self, provider: &str, key: impl Into<String>)
Sets the runtime API key (--api-key).
Sourcepub fn remove_runtime_api_key(&self, provider: &str)
pub fn remove_runtime_api_key(&self, provider: &str)
R e m o v e R u n t i m e A p i K e y.
Sourcepub async fn get_auth(
&self,
provider: &str,
overrides: &AuthOverrides,
) -> Result<Option<ResolvedAuth>, AuthResolveError>
pub async fn get_auth( &self, provider: &str, overrides: &AuthOverrides, ) -> Result<Option<ResolvedAuth>, AuthResolveError>
Resolved credentials (refreshing OAuth tokens as needed).
§Errors
AuthResolveError when a configured credential cannot be resolved.
Sourcepub async fn get_api_key(&self, provider: &str) -> Option<String>
pub async fn get_api_key(&self, provider: &str) -> Option<String>
The key, or None when unconfigured or failing.
Sourcepub async fn get_api_key_and_headers(
&self,
model: &Model,
overrides: &AuthOverrides,
) -> Result<RequestAuth, RequestAuthError>
pub async fn get_api_key_and_headers( &self, model: &Model, overrides: &AuthOverrides, ) -> Result<RequestAuth, RequestAuthError>
What core passes to the provider component as
StreamOptions.apiKey + headers.
§Errors
RequestAuthError with the message.
Sourcepub fn register_virtual_model(
&self,
extension_id: &str,
definition: VirtualModelDefinition,
) -> Result<(), RegistryError>
pub fn register_virtual_model( &self, extension_id: &str, definition: VirtualModelDefinition, ) -> Result<(), RegistryError>
Sourcepub fn unregister_virtual_model(&self, provider: &str, id: &str)
pub fn unregister_virtual_model(&self, provider: &str, id: &str)
U n r e g i s t e r V i r t u a l M o d e l.
Sourcepub fn virtual_model(
&self,
provider: &str,
id: &str,
) -> Option<RegisteredVirtualModel>
pub fn virtual_model( &self, provider: &str, id: &str, ) -> Option<RegisteredVirtualModel>
A registered virtual model (definition + owning extension).
Sourcepub fn route_request(
&self,
model: &Model,
messages: Vec<Message>,
reason: RouteReason,
thinking_level: ThinkingLevel,
failed: Option<AssistantMessage>,
state: Option<JsonValue>,
) -> Result<RouteRequest, RouteError>
pub fn route_request( &self, model: &Model, messages: Vec<Message>, reason: RouteReason, thinking_level: ThinkingLevel, failed: Option<AssistantMessage>, state: Option<JsonValue>, ) -> Result<RouteRequest, RouteError>
Builds the route request for a virtual model (before the router call):
previous from the latest successful response in messages, failed from a retry.
§Errors
Sourcepub fn validate_route(
&self,
model: &Model,
result: RouteResult,
) -> Result<ModelRoute, RouteError>
pub fn validate_route( &self, model: &Model, result: RouteResult, ) -> Result<ModelRoute, RouteError>
Validates a router result (after the call): the target must be a physical catalog model with credentials; the level is clamped to it.