pub struct MiddlewareStack { /* private fields */ }Expand description
A stack of ProviderMiddleware layers wrapping a base LlmProvider.
Implements LlmProvider itself, enabling transparent composition.
Middlewares execute outside-in: the outermost (last added) runs first.
Implementations§
Source§impl MiddlewareStack
impl MiddlewareStack
Sourcepub fn new(base: impl LlmProvider) -> Self
pub fn new(base: impl LlmProvider) -> Self
Create a new stack wrapping the given base provider.
Sourcepub fn with(self, middleware: impl ProviderMiddleware) -> Self
pub fn with(self, middleware: impl ProviderMiddleware) -> Self
Add a middleware layer. Returns self for chaining.
Layers execute outside-in: the last added runs first.
Trait Implementations§
Source§impl LlmProvider for MiddlewareStack
impl LlmProvider for MiddlewareStack
Source§fn complete(
&self,
messages: &[Message],
tools: &[ToolSchema],
) -> Pin<Box<dyn Future<Output = Result<LlmResponse, PeError>> + Send + '_>>
fn complete( &self, messages: &[Message], tools: &[ToolSchema], ) -> Pin<Box<dyn Future<Output = Result<LlmResponse, PeError>> + Send + '_>>
Non-streaming completion. Returns the full response. Read more
Source§fn stream(&self, messages: &[Message], tools: &[ToolSchema]) -> StreamFuture<'_>
fn stream(&self, messages: &[Message], tools: &[ToolSchema]) -> StreamFuture<'_>
Streaming completion. Yields tokens (and tool call deltas) as they arrive. Read more
Source§fn embed(
&self,
text: &str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, PeError>> + Send + '_>>
fn embed( &self, text: &str, ) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, PeError>> + Send + '_>>
Embed text into a vector. Used for semantic routing and memory search.
Source§fn provider_name(&self) -> &'static str
fn provider_name(&self) -> &'static str
Human-readable provider name for logging (“openai”, “anthropic”, “mock”).
Auto Trait Implementations§
impl Freeze for MiddlewareStack
impl !RefUnwindSafe for MiddlewareStack
impl Send for MiddlewareStack
impl Sync for MiddlewareStack
impl Unpin for MiddlewareStack
impl UnsafeUnpin for MiddlewareStack
impl !UnwindSafe for MiddlewareStack
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
Mutably borrows from an owned value. Read more