Skip to main content

HostBridge

Struct HostBridge 

Source
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

Source

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).

Source

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.

Source

pub fn set_session_id(&self, id: &str)

Set the ACP session ID for session-scoped notifications.

Source

pub fn set_script_name(&self, name: &str)

Set the currently executing script name (without .harn suffix).

Source

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.

Source

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.

Source

pub fn is_cancelled(&self) -> bool

Check if the host has sent a cancel notification.

Source

pub fn send_output(&self, text: &str)

Send an output notification (for log/print in bridge mode).

Source

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.

Source

pub fn send_log(&self, level: &str, message: &str, fields: Option<Value>)

Send a structured log notification.

Source

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.

Source

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.

Source

pub fn send_call_end( &self, call_id: &str, call_type: &str, name: &str, duration_ms: u64, status: &str, metadata: Value, )

Send a session/update with call_end — signals completion of a call.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more