34 lines
1.6 KiB
JavaScript
34 lines
1.6 KiB
JavaScript
// harness/tests/fake_pi/fake_pi_rpc.mjs — scripted RPC test double (LF-only JSONL).
|
|
import fs from "node:fs";
|
|
const script = JSON.parse(fs.readFileSync(process.argv[2], "utf8"));
|
|
const out = (evt) => process.stdout.write(JSON.stringify(evt) + "\n");
|
|
|
|
let buf = "";
|
|
process.stdin.on("data", (chunk) => {
|
|
buf += chunk.toString("utf8");
|
|
for (let nl; (nl = buf.indexOf("\n")) !== -1; ) {
|
|
const line = buf.slice(0, nl).replace(/\r$/, ""); buf = buf.slice(nl + 1);
|
|
if (!line) continue;
|
|
let cmd; try { cmd = JSON.parse(line); } catch { continue; }
|
|
if (cmd.type === "prompt") {
|
|
for (const step of script.on_prompt ?? []) {
|
|
if (step.ui_request_descriptor) {
|
|
const d = step.ui_request_descriptor;
|
|
out({ type: "extension_ui_request", id: d.id, method: "input", title: JSON.stringify(d) });
|
|
} else { out(step); } // eventi non-UI (text_delta, agent_end, …) passano tali e quali
|
|
}
|
|
} else if (cmd.type === "extension_ui_response") {
|
|
for (const evt of (script.on_response ?? {})[cmd.id] ?? []) out(evt);
|
|
} else if (cmd.type === "get_available_models") {
|
|
out({ type: "response", command: "get_available_models", id: cmd.id, success: true,
|
|
data: { models: script.available_models ?? [] } });
|
|
} else if (cmd.type === "steer") {
|
|
out({ type: "response", command: "steer", id: cmd.id, success: true });
|
|
} else if (cmd.type === "get_state") {
|
|
out({ type: "response", command: "get_state", id: cmd.id, success: true,
|
|
data: { sessionId: "fake", thinkingLevel: "medium", isStreaming: false } });
|
|
}
|
|
}
|
|
});
|
|
process.stdin.on("end", () => process.exit(0));
|