pub struct EdgeState { /* private fields */ }Expand description
Cheap-to-clone application state.
Implementations§
Source§impl EdgeState
impl EdgeState
Sourcepub fn new(config: EdgeConfig) -> Self
pub fn new(config: EdgeConfig) -> Self
The self-host default: bearer passthrough, no metering, no BYOK.
Sourcepub fn with_ports(
config: EdgeConfig,
resolver: Arc<dyn CredentialResolver>,
meter: Arc<dyn MeteringSink>,
) -> Self
pub fn with_ports( config: EdgeConfig, resolver: Arc<dyn CredentialResolver>, meter: Arc<dyn MeteringSink>, ) -> Self
Build state with an injected resolver + metering sink (the hosted gateway path). The gateway passes an API-key resolver and its analytics sink.
Sourcepub fn with_llm_credentials(
self,
store: Arc<dyn LlmCredentialStore>,
keyring: Arc<KeyRing>,
) -> Self
pub fn with_llm_credentials( self, store: Arc<dyn LlmCredentialStore>, keyring: Arc<KeyRing>, ) -> Self
Install the BYOK pieces: where sealed credentials live, and the keys that seal them.
Separate from Self::with_ports so the existing two-port constructor
keeps working unchanged and BYOK is opt-in. A deployment that never
calls this has no KEK, so Self::seal_llm_key refuses — the edge
will not fall back to storing a provider key in the clear.
Sourcepub fn byok_enabled(&self) -> bool
pub fn byok_enabled(&self) -> bool
True when a KEK is configured, i.e. BYOK is usable on this edge.
Sourcepub fn seal_llm_key(
&self,
plaintext: &str,
binding: SecretBinding<'_>,
) -> Result<SealedSecret, ApiError>
pub fn seal_llm_key( &self, plaintext: &str, binding: SecretBinding<'_>, ) -> Result<SealedSecret, ApiError>
Seal a plaintext provider key for namespace/provider.
The plaintext is borrowed and never stored; only the returned
SealedSecret crosses the store boundary.
§Errors
501 when no KEK is configured — storing the key would mean writing it
in the clear, so the edge declines instead. 500 if sealing fails.
Sourcepub fn open_llm_key(
&self,
sealed: &SealedSecret,
binding: SecretBinding<'_>,
) -> Result<Zeroizing<Vec<u8>>, ApiError>
pub fn open_llm_key( &self, sealed: &SealedSecret, binding: SecretBinding<'_>, ) -> Result<Zeroizing<Vec<u8>>, ApiError>
Open a sealed provider key. The plaintext is wiped when dropped.
§Errors
501 when no KEK is configured; 500 when the ciphertext does not open
(wrong key, tampering, or a binding that does not match).
Sourcepub fn llm_credentials(&self) -> Option<&Arc<dyn LlmCredentialStore>>
pub fn llm_credentials(&self) -> Option<&Arc<dyn LlmCredentialStore>>
The sealed-credential store, when BYOK is configured.
None without a keyring: a store with nothing to seal with could only
ever hold plaintext, so there is deliberately no way to reach one.
Sourcepub async fn resolve(
&self,
headers: &HeaderMap,
) -> Result<ResolvedCredential, ApiError>
pub async fn resolve( &self, headers: &HeaderMap, ) -> Result<ResolvedCredential, ApiError>
Resolve a request to a Brain credential via the injected resolver.
§Errors
Propagates the resolver’s 401/403 when no valid credential is present.
Sourcepub fn record(&self, op: &str, ident: &ResolvedCredential, outcome: Outcome)
pub fn record(&self, op: &str, ident: &ResolvedCredential, outcome: Outcome)
Record one op’s outcome via the injected sink (fire-and-forget).
Sourcepub async fn client_for(
&self,
credential: &str,
) -> Result<Arc<BrainClient>, ApiError>
pub async fn client_for( &self, credential: &str, ) -> Result<Arc<BrainClient>, ApiError>
Sourcepub fn pool(&self) -> &BrainPool
pub fn pool(&self) -> &BrainPool
The shared Brain connection pool (for the background idle sweeper and readiness probing).
Sourcepub fn meter(&self) -> Arc<dyn MeteringSink> ⓘ
pub fn meter(&self) -> Arc<dyn MeteringSink> ⓘ
The injected metering sink, shared. The wire proxy reuses it so wire-path ops meter through the same sink as the HTTP data plane.