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) -> Self
pub fn with_cloud_backend(self, backend: Arc<dyn CloudBackend>) -> Self
Sourcepub fn with_account_policy(self, policy: AccountPolicy) -> Self
pub fn with_account_policy(self, policy: AccountPolicy) -> Self
Pin the account policy instead of reading env + config per call.
Sourcepub fn with_auto_policy(self, policy: AutoSelectionPolicy) -> Self
pub fn with_auto_policy(self, policy: AutoSelectionPolicy) -> Self
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) -> Self
pub fn with_max_snapshot_age(self, age: Duration) -> Self
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>) -> Self
pub fn with_local_base_url(http: Client, base_url: impl Into<String>) -> Self
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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: '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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: '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
Self: 'async_trait,
'life0: 'async_trait,
fn access_token<'life0, 'async_trait>(
&'life0 self,
provider: OAuthProviderId,
) -> Pin<Box<dyn Future<Output = Result<AccessToken, BrokerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: '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
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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
Self: 'async_trait,
'life0: '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
Self: 'async_trait,
'life0: '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
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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
Self: 'async_trait,
'life0: 'async_trait,
fn accounts<'life0, 'async_trait>(
&'life0 self,
provider: OAuthProviderId,
) -> Pin<Box<dyn Future<Output = Result<Vec<AccountSummary>, BrokerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: '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
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: '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
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: '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
Self: 'async_trait,
'life0: 'async_trait,
fn proxy<'life0, 'async_trait>(
&'life0 self,
request: ProxyRequest,
) -> Pin<Box<dyn Future<Output = Result<ProxyResponse, BrokerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn proxy_stream<'life0, 'async_trait>(
&'life0 self,
request: ProxyRequest,
) -> Pin<Box<dyn Future<Output = Result<ProxyByteStream, BrokerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn proxy_stream<'life0, 'async_trait>(
&'life0 self,
request: ProxyRequest,
) -> Pin<Box<dyn Future<Output = Result<ProxyByteStream, BrokerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
BrokerError.