pub(crate) struct ControlDispatchHandle {
writer: Arc<SharedWriter>,
can_use_tool: Option<Arc<dyn CanUseToolCallback>>,
auto_approve_tool: Option<Arc<dyn Fn(&str) -> bool + Send + Sync>>,
mcp_hosts: McpHosts,
hook_callbacks: HashMap<String, Arc<dyn ErasedHookCallback>>,
session_id: Arc<RwLock<String>>,
}Expand description
Clonable bundle of state + writer that dispatches a single
control_request. Internal - built once during
Client::spawn and cloned by the reader
task per inbound request.
Each field is Arc-backed (or Clone); cloning the handle is
cheap. Designed to be moved into a tokio::spawn’d task per
inbound control_request.
Fields§
§writer: Arc<SharedWriter>§can_use_tool: Option<Arc<dyn CanUseToolCallback>>§auto_approve_tool: Option<Arc<dyn Fn(&str) -> bool + Send + Sync>>§mcp_hosts: McpHosts§hook_callbacks: HashMap<String, Arc<dyn ErasedHookCallback>>§session_id: Arc<RwLock<String>>Implementations§
Source§impl ControlDispatchHandle
impl ControlDispatchHandle
pub(crate) fn new( writer: Arc<SharedWriter>, can_use_tool: Option<Arc<dyn CanUseToolCallback>>, auto_approve_tool: Option<Arc<dyn Fn(&str) -> bool + Send + Sync>>, mcp_hosts: McpHosts, hook_callbacks: HashMap<String, Arc<dyn ErasedHookCallback>>, session_id: Arc<RwLock<String>>, ) -> Self
Sourcepub(crate) fn capture_session_id_from(&self, msg: &Message)
pub(crate) fn capture_session_id_from(&self, msg: &Message)
Capture a session id from an incoming Message. No-op once a non-empty id has been bound. Called by the reader task on every message.
Sourcepub(crate) async fn dispatch(&self, req: ControlRequest) -> Result<(), Error>
pub(crate) async fn dispatch(&self, req: ControlRequest) -> Result<(), Error>
Dispatch one inbound control_request. Routes the request
to the right handler (MCP, hook callback, can_use_tool) and
writes the matching control_response via the cloned
SharedWriter. Safe to call from a tokio::spawn’d task -
runs to completion regardless of caller cancellation.
On handler failure the CLI is best-effort answered with an
error control_response before the error surfaces - an
unanswered request hangs the subprocess’s in-flight tool call.
§Errors
Same shape as Client::handle_control: encode/serialise
failures from Error::message_parse / Error::encode,
and write failures from the underlying writer.
Sourcepub(crate) async fn write_error_response(&self, request_id: &str, error: &str)
pub(crate) async fn write_error_response(&self, request_id: &str, error: &str)
Best-effort error control_response for a request we could not
handle. The CLI blocks on an unanswered request, so any frame
carrying a request_id must be answered even on failure.