pub struct LocalBroker { /* private fields */ }Expand description
In-process credential broker. This module is the ONLY place runtime-serving
code may read auth.json, provider.<key> config values, or credential
environment variables.
Implementations§
Source§impl LocalBroker
impl LocalBroker
pub fn new(http: Client) -> LocalBroker
pub fn with_cloud_backend(self, backend: Arc<dyn CloudBackend>) -> LocalBroker
Sourcepub fn with_account_policy(self, policy: AccountPolicy) -> LocalBroker
pub fn with_account_policy(self, policy: AccountPolicy) -> LocalBroker
Pin the account policy instead of reading env + config per call.
Sourcepub fn with_auto_policy(self, policy: AutoSelectionPolicy) -> LocalBroker
pub fn with_auto_policy(self, policy: AutoSelectionPolicy) -> LocalBroker
Pin the automatic ranking policy (tests/embedding).
Sourcepub async fn access_token_auto(
&self,
provider: OAuthProviderId,
model: Option<&str>,
) -> Result<PinnedToken, BrokerError>
pub async fn access_token_auto( &self, provider: OAuthProviderId, model: Option<&str>, ) -> Result<PinnedToken, BrokerError>
Capacity-based selection for provider regardless of the configured
selector (used by the broker daemon when a remote client’s own policy
is auto). Fails closed like access_token_pinned_for.
Sourcepub fn with_max_snapshot_age(self, age: Duration) -> LocalBroker
pub fn with_max_snapshot_age(self, age: Duration) -> LocalBroker
Bound on usage-snapshot age for automatic selection.
Sourcepub fn auth_state(
&self,
query: &AuthStateQuery,
) -> Result<AuthStateReport, BrokerError>
pub fn auth_state( &self, query: &AuthStateQuery, ) -> Result<AuthStateReport, BrokerError>
What this broker remembers about the accounts query selects: no
network request, no refresh; the account list comes from the store.
With query.clear, their in-memory state is dropped first.
Sourcepub async fn plan(
&self,
provider: OAuthProviderId,
model: Option<&str>,
) -> Result<SelectionPlan, BrokerError>
pub async fn plan( &self, provider: OAuthProviderId, model: Option<&str>, ) -> Result<SelectionPlan, BrokerError>
Preview the exact ranking without vending inference credentials or changing stickiness/cooldowns. Usage reads may refresh expired OAuth tokens through the ordinary rotation-safe credential path.
Sourcepub fn with_local_base_url(
http: Client,
base_url: impl Into<String>,
) -> LocalBroker
pub fn with_local_base_url( http: Client, base_url: impl Into<String>, ) -> LocalBroker
Test/embedding seam: pin the local provider endpoint explicitly.
Trait Implementations§
Source§impl CredentialBroker for LocalBroker
impl CredentialBroker for LocalBroker
Source§fn recover_rejected_token<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cred: &'life1 CredentialRef,
rejected: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<AccessToken, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
LocalBroker: 'async_trait,
fn recover_rejected_token<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cred: &'life1 CredentialRef,
rejected: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<AccessToken, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
LocalBroker: 'async_trait,
Source§fn access_token<'life0, 'async_trait>(
&'life0 self,
provider: OAuthProviderId,
) -> Pin<Box<dyn Future<Output = Result<AccessToken, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalBroker: 'async_trait,
fn access_token<'life0, 'async_trait>(
&'life0 self,
provider: OAuthProviderId,
) -> Pin<Box<dyn Future<Output = Result<AccessToken, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalBroker: 'async_trait,
provider.Source§fn account_selector(&self, provider: OAuthProviderId) -> AccountSelector
fn account_selector(&self, provider: OAuthProviderId) -> AccountSelector
provider (env > config > injected
policy). No I/O beyond reading configuration; no secrets.Source§fn access_token_for<'life0, 'life1, 'async_trait>(
&'life0 self,
cred: &'life1 CredentialRef,
) -> Pin<Box<dyn Future<Output = Result<AccessToken, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
LocalBroker: 'async_trait,
fn access_token_for<'life0, 'life1, 'async_trait>(
&'life0 self,
cred: &'life1 CredentialRef,
) -> Pin<Box<dyn Future<Output = Result<AccessToken, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
LocalBroker: 'async_trait,
access_token);
a named slot is an error — NEVER a fallback to another account.Source§fn access_token_pinned<'life0, 'async_trait>(
&'life0 self,
provider: OAuthProviderId,
) -> Pin<Box<dyn Future<Output = Result<PinnedToken, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalBroker: 'async_trait,
fn access_token_pinned<'life0, 'async_trait>(
&'life0 self,
provider: OAuthProviderId,
) -> Pin<Box<dyn Future<Output = Result<PinnedToken, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalBroker: 'async_trait,
provider and its token. Default implementation: the default slot.Source§fn access_token_pinned_for<'life0, 'life1, 'async_trait>(
&'life0 self,
provider: OAuthProviderId,
model: Option<&'life1 str>,
) -> Pin<Box<dyn Future<Output = Result<PinnedToken, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
LocalBroker: 'async_trait,
fn access_token_pinned_for<'life0, 'life1, 'async_trait>(
&'life0 self,
provider: OAuthProviderId,
model: Option<&'life1 str>,
) -> Pin<Box<dyn Future<Output = Result<PinnedToken, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
LocalBroker: 'async_trait,
access_token_pinned: under an auto
selector only accounts with proven capacity for model are
eligible. Default implementation ignores the model.Source§fn accounts<'life0, 'async_trait>(
&'life0 self,
provider: OAuthProviderId,
) -> Pin<Box<dyn Future<Output = Result<Vec<AccountSummary>, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalBroker: 'async_trait,
fn accounts<'life0, 'async_trait>(
&'life0 self,
provider: OAuthProviderId,
) -> Pin<Box<dyn Future<Output = Result<Vec<AccountSummary>, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalBroker: 'async_trait,
provider. Default: unsupported.Source§fn usage<'life0, 'life1, 'async_trait>(
&'life0 self,
cred: &'life1 CredentialRef,
) -> Pin<Box<dyn Future<Output = Result<UsageSnapshot, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
LocalBroker: 'async_trait,
fn usage<'life0, 'life1, 'async_trait>(
&'life0 self,
cred: &'life1 CredentialRef,
) -> Pin<Box<dyn Future<Output = Result<UsageSnapshot, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
LocalBroker: 'async_trait,
Source§fn report_cooldown<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cred: &'life1 CredentialRef,
until_ms: Option<u64>,
reason: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<(), BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
LocalBroker: 'async_trait,
fn report_cooldown<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cred: &'life1 CredentialRef,
until_ms: Option<u64>,
reason: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<(), BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
LocalBroker: 'async_trait,
cred hit a provider limit so automatic selection stops
advertising it until until_ms (epoch ms; None = a short default).
Best effort; default implementation is a no-op.Source§fn proxy<'life0, 'async_trait>(
&'life0 self,
request: ProxyRequest,
) -> Pin<Box<dyn Future<Output = Result<ProxyResponse, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalBroker: 'async_trait,
fn proxy<'life0, 'async_trait>(
&'life0 self,
request: ProxyRequest,
) -> Pin<Box<dyn Future<Output = Result<ProxyResponse, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalBroker: 'async_trait,
Source§fn proxy_stream<'life0, 'async_trait>(
&'life0 self,
request: ProxyRequest,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Bytes, BrokerError>> + Send>>, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalBroker: 'async_trait,
fn proxy_stream<'life0, 'async_trait>(
&'life0 self,
request: ProxyRequest,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Bytes, BrokerError>> + Send>>, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalBroker: 'async_trait,
BrokerError.Source§fn anthropic_usage<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Value, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalBroker: 'async_trait,
fn anthropic_usage<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Value, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalBroker: 'async_trait,
Source§fn cloud_catalog<'life0, 'life1, 'async_trait>(
&'life0 self,
provider: CloudProviderId,
context_ref: &'life1 str,
allow_stale: bool,
) -> Pin<Box<dyn Future<Output = Result<Vec<CloudCatalogEntry>, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
LocalBroker: 'async_trait,
fn cloud_catalog<'life0, 'life1, 'async_trait>(
&'life0 self,
provider: CloudProviderId,
context_ref: &'life1 str,
allow_stale: bool,
) -> Pin<Box<dyn Future<Output = Result<Vec<CloudCatalogEntry>, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
LocalBroker: 'async_trait,
Source§fn cloud_invoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
provider: CloudProviderId,
context_ref: &'life1 str,
model_id: &'life2 str,
request: InvokeRequest,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<CloudEvent, BrokerError>> + Send>>, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
LocalBroker: 'async_trait,
fn cloud_invoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
provider: CloudProviderId,
context_ref: &'life1 str,
model_id: &'life2 str,
request: InvokeRequest,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<CloudEvent, BrokerError>> + Send>>, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
LocalBroker: 'async_trait,
Source§fn capabilities<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<ProviderStatus>, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalBroker: 'async_trait,
fn capabilities<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<ProviderStatus>, BrokerError>> + Send + 'async_trait>>where
'life0: 'async_trait,
LocalBroker: 'async_trait,
Auto Trait Implementations§
impl !Freeze for LocalBroker
impl !RefUnwindSafe for LocalBroker
impl !UnwindSafe for LocalBroker
impl Send for LocalBroker
impl Sync for LocalBroker
impl Unpin for LocalBroker
impl UnsafeUnpin for LocalBroker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.