fix: rpc stream

This commit is contained in:
Cristina Poncela Cubeiro
2026-06-22 15:11:14 +02:00
parent 555ab2e548
commit 13a18600c6
2 changed files with 10 additions and 4 deletions
+1 -1
View File
@@ -72,6 +72,7 @@ export async function startIpcServer(handler: IpcRequestHandler): Promise<Server
return; return;
} }
socket.removeAllListeners("data");
const rpcStream = handler.openRpcStream( const rpcStream = handler.openRpcStream(
request.instanceId, request.instanceId,
(response) => { (response) => {
@@ -92,7 +93,6 @@ export async function startIpcServer(handler: IpcRequestHandler): Promise<Server
} }
socket.write(encodeMessage(response)); socket.write(encodeMessage(response));
socket.removeAllListeners("data");
socket.on("data", (rpcChunk: Buffer | string) => { socket.on("data", (rpcChunk: Buffer | string) => {
buffer += rpcChunk.toString(); buffer += rpcChunk.toString();
for (;;) { for (;;) {
+9 -3
View File
@@ -1,6 +1,8 @@
import { type ChildProcess, spawn } from "node:child_process"; import { type ChildProcess, spawn } from "node:child_process";
import { randomUUID } from "node:crypto"; import { randomUUID } from "node:crypto";
import { createRequire } from "node:module"; import { existsSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import type { import type {
AgentSessionEvent, AgentSessionEvent,
RpcCommand, RpcCommand,
@@ -25,8 +27,12 @@ export interface RpcProcessInstance {
} }
function resolveCodingAgentCli(): string { function resolveCodingAgentCli(): string {
const require = createRequire(import.meta.url); const packageDir = dirname(fileURLToPath(import.meta.url));
return require.resolve("@earendil-works/pi-coding-agent/dist/cli.js"); const workspaceCli = join(packageDir, "../../coding-agent/dist/cli.js");
if (existsSync(workspaceCli)) {
return workspaceCli;
}
throw new Error(`Unable to find coding-agent RPC CLI: ${workspaceCli}`);
} }
function toError(error: unknown): Error { function toError(error: unknown): Error {