Skip to content

Commit b6b4a41

Browse files
nikomatsakisclaude
andcommitted
docs(sacp-conductor): document lazy initialization and ComponentList trait
Add comprehensive documentation for lazy component initialization feature: - Document when components are instantiated (on first Initialize request) - Show simple Vec-based usage example - Show dynamic closure-based usage example with capability inspection - Document ComponentList trait parameters and return values - Explain how this enables dynamic proxy chain construction Co-authored-by: Claude <claude@anthropic.com>
1 parent 96d9e28 commit b6b4a41

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/sacp-conductor/src/conductor.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,58 @@
5959
//!
6060
//! The message flow ensures bidirectional communication while maintaining the
6161
//! 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
62114
63115
use std::{
64116
collections::HashMap,

0 commit comments

Comments
 (0)