pub struct InterceptorChain { /* private fields */ }Expand description
An ordered chain of A2aInterceptor instances.
Executes before_delegation in registration order (first added runs first)
and after_delegation in reverse order (last added runs first), following
the standard middleware onion model.
§Example
use adk_server::a2a::interceptor::{
A2aDelegationContext, A2aError, A2aInterceptor, InterceptorChain, InterceptorDecision,
};
use async_trait::async_trait;
struct PassthroughInterceptor;
#[async_trait]
impl A2aInterceptor for PassthroughInterceptor {
async fn before_delegation(
&self,
_ctx: &mut A2aDelegationContext,
) -> Result<InterceptorDecision, A2aError> {
Ok(InterceptorDecision::Continue)
}
async fn after_delegation(
&self,
_ctx: &A2aDelegationContext,
_response: &mut serde_json::Value,
) -> Result<(), A2aError> {
Ok(())
}
}
let chain = InterceptorChain::new()
.add(PassthroughInterceptor)
.add(PassthroughInterceptor);
let mut ctx = A2aDelegationContext {
method: "tasks/send".to_string(),
params: serde_json::json!({}),
caller_id: None,
metadata: std::collections::HashMap::new(),
};
let decision = chain.run_before(&mut ctx).await.unwrap();
assert!(matches!(decision, InterceptorDecision::Continue));
let mut response = serde_json::json!({"result": "ok"});
chain.run_after(&ctx, &mut response).await.unwrap();Implementations§
Source§impl InterceptorChain
impl InterceptorChain
Sourcepub fn add(self, interceptor: impl A2aInterceptor + 'static) -> Self
pub fn add(self, interceptor: impl A2aInterceptor + 'static) -> Self
Adds an interceptor to the end of the chain.
Interceptors are executed in the order they are added for before_delegation,
and in reverse order for after_delegation.
Sourcepub async fn run_before(
&self,
ctx: &mut A2aDelegationContext,
) -> Result<InterceptorDecision, A2aError>
pub async fn run_before( &self, ctx: &mut A2aDelegationContext, ) -> Result<InterceptorDecision, A2aError>
Runs all interceptors’ before_delegation in registration order.
Stops early if any interceptor returns InterceptorDecision::ShortCircuit
or InterceptorDecision::Reject.
§Errors
Returns A2aError if any interceptor fails.
Trait Implementations§
Source§impl Debug for InterceptorChain
impl Debug for InterceptorChain
Auto Trait Implementations§
impl !RefUnwindSafe for InterceptorChain
impl !UnwindSafe for InterceptorChain
impl Forget for InterceptorChain
impl Freeze for InterceptorChain
impl Move for InterceptorChain
impl Send for InterceptorChain
impl Sync for InterceptorChain
impl Unpin for InterceptorChain
impl UnsafeUnpin for InterceptorChain
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more