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:
@@ -5,7 +5,7 @@
|
||||
* Demonstrates how to build a custom UI on top of the RPC protocol,
|
||||
* including handling extension UI requests (select, confirm, input, editor).
|
||||
*
|
||||
* Usage: npx tsx examples/rpc-extension-ui.ts
|
||||
* Usage: node examples/rpc-extension-ui.ts
|
||||
*
|
||||
* Slash commands:
|
||||
* /select - demo select dialog
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import { spawn } from "node:child_process";
|
||||
import { dirname, join } from "node:path";
|
||||
import * as readline from "node:readline";
|
||||
import { StringDecoder } from "node:string_decoder";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import {
|
||||
type Component,
|
||||
@@ -258,7 +258,7 @@ async function main() {
|
||||
|
||||
const agent = spawn(
|
||||
"node",
|
||||
[cliPath, "--mode", "rpc", "--no-session", "--no-extension", "--extension", extensionPath],
|
||||
[cliPath, "--mode", "rpc", "--no-session", "--no-extensions", "--extension", extensionPath],
|
||||
{ stdio: ["pipe", "pipe", "pipe"] },
|
||||
);
|
||||
|
||||
@@ -518,9 +518,7 @@ async function main() {
|
||||
|
||||
// -- Process agent stdout --
|
||||
|
||||
const stdoutRl = readline.createInterface({ input: agent.stdout!, terminal: false });
|
||||
|
||||
stdoutRl.on("line", (line) => {
|
||||
function handleAgentLine(line: string): void {
|
||||
let data: Record<string, unknown>;
|
||||
try {
|
||||
data = JSON.parse(line);
|
||||
@@ -583,6 +581,28 @@ async function main() {
|
||||
tui.requestRender();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const stdoutDecoder = new StringDecoder("utf8");
|
||||
let stdoutBuffer = "";
|
||||
|
||||
agent.stdout!.on("data", (chunk: Buffer) => {
|
||||
stdoutBuffer += stdoutDecoder.write(chunk);
|
||||
while (true) {
|
||||
const newlineIndex = stdoutBuffer.indexOf("\n");
|
||||
if (newlineIndex === -1) break;
|
||||
|
||||
const line = stdoutBuffer.slice(0, newlineIndex);
|
||||
stdoutBuffer = stdoutBuffer.slice(newlineIndex + 1);
|
||||
handleAgentLine(line.endsWith("\r") ? line.slice(0, -1) : line);
|
||||
}
|
||||
});
|
||||
|
||||
agent.stdout!.on("end", () => {
|
||||
stdoutBuffer += stdoutDecoder.end();
|
||||
if (stdoutBuffer.length > 0) {
|
||||
handleAgentLine(stdoutBuffer.endsWith("\r") ? stdoutBuffer.slice(0, -1) : stdoutBuffer);
|
||||
}
|
||||
});
|
||||
|
||||
// -- User input --
|
||||
|
||||
Reference in New Issue
Block a user