pub struct MiddlewareChain { /* private fields */ }Expand description
一组中间件,按 onion 顺序驱动。运行时持有它并在各钩子点调用。
Implementations§
Source§impl MiddlewareChain
impl MiddlewareChain
pub fn new() -> Self
pub fn push(&mut self, middleware: Arc<dyn Middleware>)
pub fn with(self, middleware: Arc<dyn Middleware>) -> Self
pub fn is_empty(&self) -> bool
Sourcepub async fn before_model(
&self,
ctx: &MiddlewareCtx<'_>,
req: &mut LLMRequest,
) -> Result<(), String>
pub async fn before_model( &self, ctx: &MiddlewareCtx<'_>, req: &mut LLMRequest, ) -> Result<(), String>
正序执行所有 before_model。出错时用中间件 name() 标注是谁挂的。
Sourcepub async fn after_model(
&self,
ctx: &MiddlewareCtx<'_>,
msg: &mut Message,
) -> Result<(), String>
pub async fn after_model( &self, ctx: &MiddlewareCtx<'_>, msg: &mut Message, ) -> Result<(), String>
逆序执行所有 after_model。出错时用中间件 name() 标注是谁挂的。
Sourcepub async fn before_tool(
&self,
ctx: &MiddlewareCtx<'_>,
call: &ToolCall,
) -> Result<ToolDecision, String>
pub async fn before_tool( &self, ctx: &MiddlewareCtx<'_>, call: &ToolCall, ) -> Result<ToolDecision, String>
正序询问 before_tool,第一个返回 ShortCircuit 的中间件胜出。
出错时用中间件 name() 标注是谁挂的。
Sourcepub async fn after_tool(
&self,
ctx: &MiddlewareCtx<'_>,
call: &ToolCall,
result: &mut ContentBlock,
) -> Result<(), String>
pub async fn after_tool( &self, ctx: &MiddlewareCtx<'_>, call: &ToolCall, result: &mut ContentBlock, ) -> Result<(), String>
逆序执行所有 after_tool。出错时用中间件 name() 标注是谁挂的。
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 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