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 fn set_session_id(&self, id: &str)
pub fn set_session_id(&self, id: &str)
Set the ACP session ID for session-scoped notifications.
Sourcepub fn set_script_name(&self, name: &str)
pub fn set_script_name(&self, name: &str)
Set the currently executing script name (without .harn suffix).
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,
progress: Option<i64>,
total: Option<i64>,
data: Option<Value>,
)
pub fn send_progress( &self, phase: &str, message: &str, progress: Option<i64>, total: Option<i64>, data: Option<Value>, )
Send a progress notification with optional numeric progress and structured data.
Sourcepub fn send_log(&self, level: &str, message: &str, fields: Option<Value>)
pub fn send_log(&self, level: &str, message: &str, fields: Option<Value>)
Send a structured log notification.
Sourcepub fn send_call_start(
&self,
call_id: &str,
call_type: &str,
name: &str,
metadata: Value,
)
pub fn send_call_start( &self, call_id: &str, call_type: &str, name: &str, metadata: Value, )
Send a session/update with call_start — signals the beginning of
an LLM call, tool call, or builtin call for observability.
Sourcepub fn send_call_progress(
&self,
call_id: &str,
delta: &str,
accumulated_tokens: u64,
)
pub fn send_call_progress( &self, call_id: &str, delta: &str, accumulated_tokens: u64, )
Send a session/update with call_progress — a streaming token delta
from an in-flight LLM call.