pub struct MiddlewareChain { /* private fields */ }Expand description
An ordered stack of middleware layers with onion semantics.
Cheap to clone (Arc layers); empty by default, and every consumer
(executor, tool executor, model wrapper) takes its original code path
when the chain is empty.
Implementations§
Source§impl MiddlewareChain
impl MiddlewareChain
Sourcepub fn layer<M: Middleware + 'static>(self, middleware: M) -> Self
pub fn layer<M: Middleware + 'static>(self, middleware: M) -> Self
Builder-style: append a layer (runs after the already-added layers on the way in, before them on the way out).
Sourcepub fn push(&mut self, middleware: Arc<dyn Middleware>) -> &mut Self
pub fn push(&mut self, middleware: Arc<dyn Middleware>) -> &mut Self
Append a pre-shared layer.
Sourcepub async fn run_node<F, Fut>(
&self,
call: &mut NodeCall,
op: F,
) -> Result<NodeOutput>
pub async fn run_node<F, Fut>( &self, call: &mut NodeCall, op: F, ) -> Result<NodeOutput>
Run the onion around a node invocation: before-hooks inward, op,
after-hooks outward. See the module docs for the full contract.
Sourcepub async fn run_model<F, Fut>(
&self,
call: &mut ModelCall,
op: F,
) -> Result<ChatResponse>
pub async fn run_model<F, Fut>( &self, call: &mut ModelCall, op: F, ) -> Result<ChatResponse>
Run the onion around a model call. Same contract as
MiddlewareChain::run_node.
Sourcepub async fn run_tool<F, Fut>(
&self,
call: &mut ToolInvocation,
op: F,
) -> Result<Value>
pub async fn run_tool<F, Fut>( &self, call: &mut ToolInvocation, op: F, ) -> Result<Value>
Run the onion around a tool call. Same contract as
MiddlewareChain::run_node.
Trait Implementations§
Source§impl Clone for MiddlewareChain
impl Clone for MiddlewareChain
Source§fn clone(&self) -> MiddlewareChain
fn clone(&self) -> MiddlewareChain
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MiddlewareChain
impl Debug for MiddlewareChain
Source§impl Default for MiddlewareChain
impl Default for MiddlewareChain
Source§fn default() -> MiddlewareChain
fn default() -> MiddlewareChain
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for MiddlewareChain
impl !UnwindSafe for MiddlewareChain
impl Freeze for MiddlewareChain
impl Send for MiddlewareChain
impl Sync for MiddlewareChain
impl Unpin for MiddlewareChain
impl UnsafeUnpin for MiddlewareChain
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