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
//! `PhaseDriver` trait for protocol-specific execution.
//!
//! Each protocol mode (MCP server, MCP client, A2A server, A2A client,
//! AG-UI client) implements this trait to define how it sends requests,
//! opens streams, or listens for connections during a phase.
//!
//! See TJ-SPEC-013 ยง8.4 for the trait specification.
use HashMap;
use async_trait;
use ;
use CancellationToken;
use crateEngineError;
use DriveResult;
use ProtocolEvent;
// ============================================================================
// PhaseDriver
// ============================================================================
/// Protocol-specific driver for phase execution.
///
/// Defines how to execute a phase's protocol-specific work (send
/// requests, open streams, listen for connections) and how to deliver
/// protocol events to the `PhaseLoop`.
///
/// # Driver Implementation Pattern
///
/// 1. In `drive_phase()`: perform protocol I/O, emit events on `event_tx`,
/// respect `cancel` token.
/// 2. Server-mode: `extractors.borrow().clone()` per request for fresh values.
/// 3. Client-mode: `extractors.borrow().clone()` once at start.
/// 4. Response dispatch uses `oatf::select_response()` for ordered matching.
/// 5. Template interpolation uses `oatf::interpolate_template()` /
/// `oatf::interpolate_value()`.
///
/// # Errors
///
/// Implementations should return `EngineError::Driver` for protocol-level
/// failures. The `PhaseLoop` propagates these to the caller.
///
/// Implements: TJ-SPEC-013 F-001