Skip to main content

ModelRegistry

Struct ModelRegistry 

Source
pub struct ModelRegistry { /* private fields */ }
Expand description

The shared model registry (see module docs).

Implementations§

Source§

impl ModelRegistry

Source

pub fn new(auth: Arc<AuthStorage>, options: ModelRegistryOptions) -> Self

Creates a registry and loads models.json.

Source

pub fn in_memory(env: Arc<dyn EnvSource>) -> Self

In-memory credentials, no models.json, no cache, the given environment.

Source

pub fn auth_storage(&self) -> &Arc<AuthStorage> ⓘ

The credential store.

Source

pub fn set_oauth_refresher(&self, refresher: Arc<dyn OAuthRefresher>)

Installs the OAuth refresher (the host’s bridge to oauth-refresh exports).

Source

pub fn refresh(&self)

Reloads models.json and recomposes the catalog.

Source

pub fn set_models_json(&self, models_json: ModelsJson)

Replaces the models.json configuration without touching the file (tests, embedders).

Source

pub fn error(&self) -> Option<String>

models.json load error and per-provider composition errors, joined by blank lines.

Source

pub fn diagnostics(&self) -> Vec<RegistryDiagnostic>

Oino diagnostics: models whose API no loaded provider component implements (these models are never available).

Source

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

RegistryError::EmptyProviderId.

Source

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.

Source

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).

Source

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.

Source

pub fn unregister_provider(&self, provider: &str)

Removes the registration and the config override (virtual models stay).

Source

pub fn unregister_extension(&self, extension_id: &str)

Removes everything extension_id registered (providers, API implementations, virtual models), e.g. when the extension unloads.

Source

pub fn registered_providers(&self) -> Vec<String>

Providers with an override or a component registration.

Source

pub fn registration(&self, provider: &str) -> Option<ProviderRegistration>

A component registration.

Source

pub fn registered_provider_config( &self, provider: &str, ) -> Option<ProviderConfigOverride>

Returns the registered provider config.

Source

pub fn all(&self) -> Vec<Model>

Every model, providers in registration order.

Source

pub fn available(&self) -> Vec<Model>

Models whose provider has credentials and whose API a provider component implements (virtual models: provider credentials only).

Source

pub fn find(&self, provider: &str, id: &str) -> Option<Model>

F i n d.

Source

pub fn find_physical(&self, provider: &str, id: &str) -> Option<Model>

A catalog model that is not virtual.

Source

pub fn provider_ids(&self) -> Vec<String>

Provider ids of the catalog in order.

Source

pub fn provider_display_name(&self, provider: &str) -> String

Returns the provider display name.

Source

pub fn route_target(&self, model: &Model) -> Option<String>

The extension whose component streams model (None: no implementation loaded).

Source

pub fn check_auth(&self, provider: &str) -> Option<AuthCheck>

How a provider is authenticated, None when it is not.

Source

pub fn has_configured_auth(&self, provider: &str) -> bool

Returns whether configured auth is present.

Source

pub fn is_using_oauth(&self, provider: &str) -> bool

Returns whether it is using oauth.

Source

pub fn auth_status(&self, provider: &str) -> AuthStatus

Returns the provider auth status.

Source

pub fn set_runtime_api_key(&self, provider: &str, key: impl Into<String>)

Sets the runtime API key (--api-key).

Source

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.

Source

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.

Source

pub async fn get_api_key(&self, provider: &str) -> Option<String>

The key, or None when unconfigured or failing.

Source

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.

Source

pub fn register_virtual_model( &self, extension_id: &str, definition: VirtualModelDefinition, ) -> Result<(), RegistryError>

Registers or replaces a virtual model.

§Errors

Empty ids or a physical model with the same id.

Source

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.

Source

pub fn virtual_model( &self, provider: &str, id: &str, ) -> Option<RegisteredVirtualModel>

A registered virtual model (definition + owning extension).

Source

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

RouteError::NotRegistered.

Source

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.

§Errors

RouteError::NotPhysical / RouteError::NoCredentials.

Trait Implementations§

Source§

impl Clone for ModelRegistry

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ModelRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ModelCatalog for ModelRegistry

Source§

fn all(&self) -> Vec<Model>

Every model.
Source§

fn available(&self) -> Vec<Model>

Models with usable credentials.
Source§

fn find(&self, provider: &str, id: &str) -> Option<Model>

A model by provider and id.
Source§

fn has_configured_auth(&self, provider: &str) -> bool

Whether the provider has usable credentials.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more