feat(transport): introduce transport abstraction and socket-mode support for RustBridge

This commit is contained in:
2026-02-26 08:44:28 +00:00
parent 0c39e157c2
commit deda8cc4ee
14 changed files with 1064 additions and 150 deletions

View File

@@ -0,0 +1,26 @@
import type * as plugins from '../plugins.js';
/**
* Abstract transport for communicating with a Rust process.
* Both stdio and socket transports implement this interface.
*
* Events emitted:
* - 'line' (line: string) — a complete newline-terminated JSON line received
* - 'error' (err: Error) — transport-level error
* - 'close' (...args: any[]) — transport has closed/disconnected
* - 'stderr' (line: string) — stderr output (stdio transport only)
* - 'reconnected' () — transport reconnected after unexpected disconnect (socket only)
*/
export interface IRustTransport extends plugins.events.EventEmitter {
/** Connect the transport (spawn process or connect to socket). Resolves when I/O channel is open. */
connect(): Promise<void>;
/** Write a string to the transport. Handles backpressure. */
write(data: string): Promise<void>;
/** Disconnect the transport. For stdio: kills the process. For socket: closes the connection. */
disconnect(): void;
/** Whether the transport is currently connected and writable. */
readonly connected: boolean;
}