|
63 | 63 | //! Components are instantiated lazily when the first `initialize` request is received |
64 | 64 | //! from the editor. This enables dynamic proxy chain construction based on client capabilities. |
65 | 65 | //! |
66 | | -//! ### Simple Usage |
| 66 | +//! ### Fixed Chains |
67 | 67 | //! |
68 | | -//! Pass a Vec of components that implement `Component`: |
| 68 | +//! Use [`ProxiesAndAgent`] to assemble a conductor that presents as an agent: |
69 | 69 | //! |
70 | 70 | //! ```ignore |
71 | | -//! let conductor = Conductor::new( |
| 71 | +//! use agent_client_protocol_conductor::{ConductorImpl, ProxiesAndAgent}; |
| 72 | +//! |
| 73 | +//! let conductor = ConductorImpl::new_agent( |
72 | 74 | //! "my-conductor", |
73 | | -//! vec![proxy1, proxy2, agent], |
74 | | -//! None, |
| 75 | +//! ProxiesAndAgent::new(agent) |
| 76 | +//! .proxy(proxy1) |
| 77 | +//! .proxy(proxy2), |
75 | 78 | //! ); |
76 | 79 | //! ``` |
77 | 80 | //! |
78 | | -//! All components are spawned in order when the editor sends the first `initialize` request. |
| 81 | +//! A conductor that presents as a proxy takes only its internal proxies; its |
| 82 | +//! final successor is supplied when the conductor is connected: |
79 | 83 | //! |
80 | | -//! ### Dynamic Component Selection |
| 84 | +//! ```ignore |
| 85 | +//! use agent_client_protocol_conductor::ConductorImpl; |
81 | 86 | //! |
82 | | -//! Pass a closure to examine the `InitializeRequest` and dynamically construct the chain: |
| 87 | +//! let conductor = ConductorImpl::new_proxy("my-proxy-conductor", vec![proxy]); |
| 88 | +//! ``` |
83 | 89 | //! |
84 | | -//! ```ignore |
85 | | -//! let conductor = Conductor::new( |
86 | | -//! "my-conductor", |
87 | | -//! |cx, conductor_tx, init_req| async move { |
88 | | -//! // Examine capabilities |
89 | | -//! let needs_auth = has_auth_capability(&init_req); |
| 90 | +//! ### Dynamic Chain Selection |
90 | 91 | //! |
91 | | -//! let mut components = Vec::new(); |
92 | | -//! if needs_auth { |
93 | | -//! components.push(spawn_auth_proxy(&cx, &conductor_tx)?); |
94 | | -//! } |
95 | | -//! components.push(spawn_agent(&cx, &conductor_tx)?); |
| 92 | +//! Both constructors also accept an instantiator closure. The closure receives |
| 93 | +//! the `InitializeRequest` and returns the possibly modified request together |
| 94 | +//! with type-erased connectors for the selected chain: |
96 | 95 | //! |
97 | | -//! // Return (potentially modified) request and component list |
98 | | -//! Ok((init_req, components)) |
99 | | -//! }, |
100 | | -//! None, |
101 | | -//! ); |
102 | | -//! ``` |
| 96 | +//! ```ignore |
| 97 | +//! use agent_client_protocol::{Client, Conductor, DynConnectTo}; |
| 98 | +//! use agent_client_protocol_conductor::ConductorImpl; |
103 | 99 | //! |
104 | | -//! The closure receives: |
105 | | -//! - `cx: &ConnectionTo` - Connection context for spawning components |
106 | | -//! - `conductor_tx: &mpsc::Sender<ConductorMessage>` - Channel for message routing |
107 | | -//! - `init_req: InitializeRequest` - The Initialize request from the editor |
| 100 | +//! let conductor = ConductorImpl::new_agent("my-conductor", |init_req| async move { |
| 101 | +//! let mut proxies: Vec<DynConnectTo<Conductor>> = Vec::new(); |
| 102 | +//! if has_auth_capability(&init_req) { |
| 103 | +//! proxies.push(DynConnectTo::new(make_auth_proxy())); |
| 104 | +//! } |
108 | 105 | //! |
109 | | -//! And returns: |
110 | | -//! - Modified `InitializeRequest` to forward downstream |
111 | | -//! - `Vec<ConnectionTo>` of spawned components |
| 106 | +//! let agent: DynConnectTo<Client> = DynConnectTo::new(make_agent()); |
| 107 | +//! Ok((init_req, proxies, agent)) |
| 108 | +//! }); |
| 109 | +//! ``` |
112 | 110 |
|
113 | 111 | use std::sync::Arc; |
114 | 112 |
|
|
0 commit comments