1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//! The `CallInterceptor` port: before/after middleware around A2A calls.
//!
//! An interceptor is a cross-cutting hook that runs *around* every A2A call —
//! the chain-of-responsibility analogue of the official SDK's `CallInterceptor`.
//! It is a **port** (a capability the application needs from the edge), so the
//! trait lives here and concrete interceptors (logging, metrics, auth-token
//! injection) are adapters. The same trait is wired into both the client
//! transport ([`JsonRpcClient`](crate::adapter::JsonRpcClient)) and the server
//! transport ([`JsonRpcAdapter`](crate::adapter::JsonRpcAdapter)); the
//! [`CallContext::side`] tells an interceptor which direction it is observing.
//!
//! Chains run `before` hooks in registration order, dispatch the call, then run
//! `after` hooks in reverse order — the conventional onion ordering, so an
//! interceptor's `after` wraps everything its `before` set up. A `before` that
//! returns `Err` short-circuits the call (the dispatch never happens) but its
//! `after` still runs, observing the error.
//!
//! The hooks see call *metadata* (method name, side), not the typed
//! request/response — those differ per method and would force the trait generic.
//! Metadata is enough for the canonical uses (logging, metrics, tracing spans,
//! header/auth propagation handled by the adapter around the chain).
use Arc;
use async_trait;
use crateA2AError;
/// Which side of the wire an interceptor chain is running on.
/// Metadata about an in-flight A2A call, passed to each interceptor hook.
/// A before/after hook around an A2A call (auth, logging, metrics, tracing).
///
/// Both hooks have default no-op bodies, so an interceptor overrides only the
/// side it cares about.
/// Run a chain's `before` hooks in registration order; the first `Err`
/// short-circuits and is returned without invoking the remaining hooks.
pub async
/// Run a chain's `after` hooks in reverse registration order (onion unwinding).
pub async