pub struct HostBridge { /* private fields */ }Expand description
A JSON-RPC 2.0 bridge to a host process over stdin/stdout.
The bridge sends requests to the host on stdout and receives responses on stdin. A background task reads stdin and dispatches responses to waiting callers by request ID. All stdout writes are serialized through a mutex to prevent interleaving.
Implementations§
Source§impl HostBridge
impl HostBridge
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new bridge and spawn the stdin reader task.
Must be called within a tokio LocalSet (uses spawn_local for the stdin reader since it’s single-threaded).
Sourcepub fn from_parts(
pending: Arc<Mutex<HashMap<u64, Sender<Value>>>>,
cancelled: Arc<AtomicBool>,
stdout_lock: Arc<Mutex<()>>,
start_id: u64,
) -> Self
pub fn from_parts( pending: Arc<Mutex<HashMap<u64, Sender<Value>>>>, cancelled: Arc<AtomicBool>, stdout_lock: Arc<Mutex<()>>, start_id: u64, ) -> Self
Create a bridge from pre-existing shared state.
Unlike new(), does not spawn a stdin reader — the caller is
responsible for dispatching responses into pending. This is used
by ACP mode which already has its own stdin reader.
Sourcepub async fn call(&self, method: &str, params: Value) -> Result<Value, VmError>
pub async fn call(&self, method: &str, params: Value) -> Result<Value, VmError>
Send a JSON-RPC request to the host and wait for the response. Times out after 5 minutes to prevent deadlocks.
Sourcepub fn notify(&self, method: &str, params: Value)
pub fn notify(&self, method: &str, params: Value)
Send a JSON-RPC notification to the host (no response expected). Serialized through the stdout mutex to prevent interleaving.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if the host has sent a cancel notification.
Sourcepub fn send_output(&self, text: &str)
pub fn send_output(&self, text: &str)
Send an output notification (for log/print in bridge mode).
Sourcepub fn send_progress(&self, phase: &str, message: &str)
pub fn send_progress(&self, phase: &str, message: &str)
Send a progress notification.