Skip to content
Developer Preview

DuplexTransport

The two-way text stream a Connection speaks MSP over.

Implement it to run the protocol over any duplex channel: yield decoded UTF-8 chunks on incoming and accept outgoing frames through write. Chunks may be empty and may split anywhere — even mid surrogate pair — the connection reassembles them. If your transport decodes bytes itself, use a streaming decoder: a multi-byte character split across two byte chunks and decoded separately becomes a replacement character before the connection ever sees it. The SDK’s spawned child-process stdio binding sets the stream encoding, so it is safe, and is one ready-made implementation.

Property Type Stability Presence Description
incoming AsyncIterable<string> required
Method Signature Stability Description
close close(flushed?: Promise<void>): void | Promise<void> flushed settles once every frame the connection had accepted when close() was called has been HANDED to write() — submission, not completion. A process-owning transport waits for it inside its own shutdown budget before ending the peer’s input, so a frame still queued on a microtask is not dropped; it is never GATED by it, because completion is exactly what a wedged peer withholds. Optional and additive: a transport that ignores it behaves as before.
write write(chunk: string): Promise<void>
Source

clients/sdk-ts/src/connection/connection.ts:36

{
"kind": "Interface",
"canonicalPath": "DuplexTransport"
}