|
59 | 59 | //! |
60 | 60 | //! The message flow ensures bidirectional communication while maintaining the |
61 | 61 | //! abstraction that each component only knows about its immediate successor. |
| 62 | +//! |
| 63 | +//! ## Lazy Component Initialization |
| 64 | +//! |
| 65 | +//! Components are instantiated lazily when the first `initialize` request is received |
| 66 | +//! from the editor. This enables dynamic proxy chain construction based on client capabilities. |
| 67 | +//! |
| 68 | +//! ### Simple Usage |
| 69 | +//! |
| 70 | +//! Pass a Vec of components that implement `IntoJrTransport`: |
| 71 | +//! |
| 72 | +//! ```ignore |
| 73 | +//! let conductor = Conductor::new( |
| 74 | +//! "my-conductor", |
| 75 | +//! vec![proxy1, proxy2, agent], |
| 76 | +//! None, |
| 77 | +//! ); |
| 78 | +//! ``` |
| 79 | +//! |
| 80 | +//! All components are spawned in order when the editor sends the first `initialize` request. |
| 81 | +//! |
| 82 | +//! ### Dynamic Component Selection |
| 83 | +//! |
| 84 | +//! Pass a closure to examine the `InitializeRequest` and dynamically construct the chain: |
| 85 | +//! |
| 86 | +//! ```ignore |
| 87 | +//! let conductor = Conductor::new( |
| 88 | +//! "my-conductor", |
| 89 | +//! |cx, conductor_tx, init_req| async move { |
| 90 | +//! // Examine capabilities |
| 91 | +//! let needs_auth = has_auth_capability(&init_req); |
| 92 | +//! |
| 93 | +//! let mut components = Vec::new(); |
| 94 | +//! if needs_auth { |
| 95 | +//! components.push(spawn_auth_proxy(&cx, &conductor_tx)?); |
| 96 | +//! } |
| 97 | +//! components.push(spawn_agent(&cx, &conductor_tx)?); |
| 98 | +//! |
| 99 | +//! // Return (potentially modified) request and component list |
| 100 | +//! Ok((init_req, components)) |
| 101 | +//! }, |
| 102 | +//! None, |
| 103 | +//! ); |
| 104 | +//! ``` |
| 105 | +//! |
| 106 | +//! The closure receives: |
| 107 | +//! - `cx: &JrConnectionCx` - Connection context for spawning components |
| 108 | +//! - `conductor_tx: &mpsc::Sender<ConductorMessage>` - Channel for message routing |
| 109 | +//! - `init_req: InitializeRequest` - The Initialize request from the editor |
| 110 | +//! |
| 111 | +//! And returns: |
| 112 | +//! - Modified `InitializeRequest` to forward downstream |
| 113 | +//! - `Vec<JrConnectionCx>` of spawned components |
62 | 114 |
|
63 | 115 | use std::{ |
64 | 116 | collections::HashMap, |
|
0 commit comments