/** * Transport interface for communicating with the qodercli process. * * A Transport abstracts the bidirectional communication channel between * the SDK and the CLI. All transports must implement this interface. * * The default implementation spawns qodercli as a subprocess and uses * stdin/stdout. Custom transports can implement this interface. */ import type { StdoutMessage } from '../types/control.js'; export interface Transport { /** * Start the underlying runtime and make the transport ready. */ initialize(): Promise; /** * Write a JSON line to the CLI process stdin. * The transport is responsible for appending the newline delimiter. * * @param data - A serialized JSON string to send to the CLI. */ write(data: string): void | Promise; /** * Close the transport and clean up all resources. * After calling close(), no further writes or reads should be attempted. * This should gracefully terminate the underlying process/connection. */ close(): void; /** * Whether the transport is ready to send and receive messages. * Returns false if the transport has not been initialized, has been * closed, or the underlying connection has been lost. */ isReady(): boolean; /** * Async generator that yields parsed JSON messages from stdout. * Each yielded value is a complete, parsed StdoutMessage object. * * The generator terminates when the CLI process exits or the * transport is closed. */ readMessages(): AsyncGenerator; /** * Signal that no more input will be sent. * Closes the stdin side of the connection without tearing down the * entire transport — the CLI may still produce output. */ endInput(): void; } /** * Provider for creating a fresh transport for each query() session. * * A transport instance is stateful: it owns stdin/stdout readers, close state, * auth payload cleanup, and runtime lifetime. Host integrations should pass a * provider rather than a reusable Transport instance so every query gets an * isolated connection. */ export interface QueryTransportProvider { create(options: TOptions): Transport; }