Skip to main content
Low-level raw CBOR transport for communicating with agentd through a sandbox relay.

Constants

FLAG_TERMINAL

Frame flag: this is the last message for the given correlation id. When a frame on an open stream carries this bit, no further frames will arrive for that id.

FLAG_SESSION_START

Frame flag: this is the first message of a new session. Set it on the opening frame of a request/response RPC or a streaming session.

FLAG_SHUTDOWN

Frame flag: this message requests sandbox shutdown.

AgentClient

Low-level client for raw agent frames.

AgentClient.connectSandbox()

Connect to a running sandbox by name. Resolves the sandbox’s relay socket path and performs the core.ready handshake. Sandbox names are limited to 128 UTF-8 bytes.

Parameters

namestring
Sandbox name, up to 128 UTF-8 bytes.
Optional connect settings, e.g. handshake timeout.

Returns

Connected client.

AgentClient.connect()

Connect to an agentd relay socket by path. Use this when you already have the socket path, for example one returned by socketPath().

Parameters

pathstring
Filesystem path of the relay socket.
Optional connect settings, e.g. handshake timeout.

Returns

Connected client.

AgentClient.socketPath()

Resolve a sandbox’s agentd relay socket path without connecting. Returns the same path connectSandbox() would dial, so you can talk to agentd over a raw byte transport (for example a transparent relay that splices bytes to and from the socket) instead of this frame client. The sandbox need not be running. Sandbox names are limited to 128 UTF-8 bytes.

Parameters

namestring
Sandbox name, up to 128 UTF-8 bytes.

Returns

string
Relay socket path.

Instance methods

client.request()

Send one frame and await a single response frame. Use for request/response RPCs that produce exactly one terminal response (for example FsRequest to FsResponse).

Parameters

flagsnumber
Frame flag byte, e.g. FLAG_SESSION_START.
bodyBuffer
CBOR-encoded protocol message body.

Returns

The single response frame.

client.stream()

Open a streaming session. The returned AgentStream carries the protocol correlation id (pass it to send() for follow-up frames) and is also an async iterator of raw frames.

Parameters

flagsnumber
Frame flag byte for the opening frame, e.g. FLAG_SESSION_START.
bodyBuffer
CBOR-encoded protocol message body.

Returns

Open stream of raw frames.

client.send()

Send a follow-up frame on an existing correlation id (for example stdin, a signal, a resize, or data chunks on an open session). Use the id of the AgentStream returned by stream().

Parameters

idnumber
Correlation id of an open session.
flagsnumber
Frame flag byte.
bodyBuffer
CBOR-encoded protocol message body.

client.readyBytes()

Return the cached handshake core.ready frame body as CBOR bytes. Captured during connect, so this is a synchronous accessor with no protocol traffic.

Returns

Buffer
CBOR-encoded core.ready frame body.

client.close()

Close the connection. Idempotent: calling it more than once is safe.

AgentStream

Returned by stream()

An open raw agent stream. Implements AsyncIterableIterator<RawFrame>, so it can be driven with for await. The iterator ends after a frame carrying FLAG_TERMINAL or when the underlying stream is exhausted.

stream.id

number Protocol correlation id; pass to send() for follow-up frames

stream.next()

Pull the next frame; done once terminal or exhausted

Returns

Promise<IteratorResult<RawFrame>>

stream.close()

Release the stream handle early (idempotent)

Returns

Promise<void>

stream.return()

Async-iterator early-exit hook; closes the stream

Returns

Promise<IteratorResult<RawFrame>>

stream.Symbol.asyncIterator

Returns itself so the stream is iterable

Returns

AgentStream

Types

RawFrame

Returned by request() · iterated from AgentStream

A raw protocol frame. The body is the CBOR-encoded Message body (v, t, p) as it appeared on the wire; decode it with a CBOR library such as cbor-x.

AgentConnectOptions

Used by connectSandbox() · connect()

Options for connecting to an agent relay.