chore(vendor): import pi 1.3.0
Imported as a linear vendor commit so forge rebases do not replay the upstream root tree. git-subtree-dir: third_party/pi git-subtree-split: 71023aec1546d6d677a65669c5665c0927ce0dd0
This commit is contained in:
35
third_party/pi/packages/coding-agent/examples/rpc-client.ts
vendored
Normal file
35
third_party/pi/packages/coding-agent/examples/rpc-client.ts
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
Reference in New Issue
Block a user