Files
pi/packages/coding-agent/examples/rpc-client.ts
T
Armin Ronacher ca7460d16b feat: build with TypeScript 7 and run sources with plain node
Replace the tsgo native preview with typescript@7.0.2 and port the check scripts to the TS 7 API. Target ES2024, drop useDefineForClassFields: false and unused decorator options, and enable verbatimModuleSyntax. Replace tsx with node plus the source resolver hook, passed to --import as a file URL.

closes #9965
2026-09-25 13:14:33 +02:00

36 lines
1.0 KiB
TypeScript

/**
* Run one prompt through a Pi RPC child process.
*
* Build the coding-agent package first, then run:
* node examples/rpc-client.ts "Explain this repository"
*/
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { RpcClient } from "@earendil-works/pi-coding-agent";
const exampleDirectory = dirname(fileURLToPath(import.meta.url));
const prompt = process.argv.slice(2).join(" ") || "Explain this repository in one paragraph.";
const client = new RpcClient({
cliPath: join(exampleDirectory, "../dist/cli.js"),
args: ["--no-session"],
});
const unsubscribe = client.onEvent((event) => {
if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
process.stdout.write(event.assistantMessageEvent.delta);
} else if (event.type === "tool_execution_start") {
process.stderr.write(`\n[tool: ${event.toolName}]\n`);
}
});
try {
await client.start();
await client.promptAndWait(prompt);
process.stdout.write("\n");
} finally {
unsubscribe();
await client.stop();
}