UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

56 lines • 2.03 kB
import { PassThrough } from "node:stream"; import { ConnectError } from "./errors.js"; /** * A project transport resolves again at EVERY spawn, including an era probe's * fallback restart of the same transport object. SDK private spawn parameters * are never mutated; each start owns a newly constructed SDK transport. */ export class ProjectStdioTransport { #resolve; #create; #current; #epoch; constructor(resolve, create) { this.stderr = new PassThrough(); this.#epoch = 0; this.#resolve = resolve; this.#create = create; } get pid() { return this.#current?.pid ?? null; } async start() { const epoch = this.#epoch; const spec = await this.#resolve(); if (epoch !== this.#epoch) throw new ConnectError("Project MCP spawn was invalidated; retry", { phase: "create", retriable: true, }); const transport = this.#create(spec); this.#current = transport; transport.onmessage = (message) => this.onmessage?.(message); transport.onclose = () => this.onclose?.(); transport.onerror = (error) => this.onerror?.(error); transport.stderr?.pipe(this.stderr, { end: false }); await transport.start(); if (epoch !== this.#epoch) { await transport.close(); throw new ConnectError("Project MCP spawn was invalidated; retry", { phase: "create", retriable: true }); } } async send(message, _options) { if (this.#current === undefined) throw new ConnectError("Project MCP transport has not started", { phase: "send", retriable: true, }); // The stdio SDK transport takes only the message; send options are an HTTP concern. await this.#current.send(message); } async close() { this.#epoch++; await this.#current?.close(); } } //# sourceMappingURL=project-stdio-transport.js.map