feat: 支持运行中 steer command
This commit is contained in:
@@ -7,6 +7,7 @@ if (process.env.AGENTRUN_FAKE_CODEX_START_FILE) appendFileSync(process.env.AGENT
|
||||
let threadCounter = 0;
|
||||
let turnCounter = 0;
|
||||
let observedThreadModel = false;
|
||||
let activeSteerTurn: { id: string; completed: boolean; timer: NodeJS.Timeout | null } | null = null;
|
||||
|
||||
for await (const line of rl) {
|
||||
const trimmed = String(line).trim();
|
||||
@@ -148,6 +149,18 @@ for await (const line of rl) {
|
||||
}, 50);
|
||||
continue;
|
||||
}
|
||||
if (mode === "steer-waits") {
|
||||
turnCounter += 1;
|
||||
const turn = { id: `turn_selftest_${turnCounter}`, status: "running" };
|
||||
notify("turn/started", { turn });
|
||||
activeSteerTurn = {
|
||||
id: turn.id,
|
||||
completed: false,
|
||||
timer: setTimeout(() => completeActiveSteerTurn("timeout-no-steer"), 2_000),
|
||||
};
|
||||
respond(message.id, { turn });
|
||||
continue;
|
||||
}
|
||||
if (mode === "noisy-reasoning-events") {
|
||||
turnCounter += 1;
|
||||
const turn = { id: `turn_selftest_${turnCounter}`, status: "completed" };
|
||||
@@ -176,6 +189,18 @@ for await (const line of rl) {
|
||||
respond(message.id, { turn });
|
||||
continue;
|
||||
}
|
||||
if (message.method === "turn/steer") {
|
||||
if (mode !== "steer-waits" || !activeSteerTurn) {
|
||||
respond(message.id, null, { code: -32000, message: "no active fake turn for steer" });
|
||||
continue;
|
||||
}
|
||||
const text = steerText(message.params?.input);
|
||||
notify("item/agentMessage/delta", { itemId: "msg_steer", delta: `steered:${text}` });
|
||||
notify("item/completed", { item: { id: "msg_steer", type: "agentMessage", text: `steered:${text}` } });
|
||||
respond(message.id, { accepted: true });
|
||||
setTimeout(() => completeActiveSteerTurn("steer-applied"), 20);
|
||||
continue;
|
||||
}
|
||||
respond(message.id, null, { code: -32601, message: `unsupported fake method ${message.method ?? "unknown"}` });
|
||||
}
|
||||
|
||||
@@ -187,3 +212,20 @@ function respond(id: number | undefined, result: unknown, error?: unknown): void
|
||||
function notify(method: string, params: unknown): void {
|
||||
process.stdout.write(`${JSON.stringify({ method, params })}\n`);
|
||||
}
|
||||
|
||||
function completeActiveSteerTurn(reason: string): void {
|
||||
if (!activeSteerTurn || activeSteerTurn.completed) return;
|
||||
activeSteerTurn.completed = true;
|
||||
if (activeSteerTurn.timer) clearTimeout(activeSteerTurn.timer);
|
||||
const turn = { id: activeSteerTurn.id, status: "completed", reason };
|
||||
notify("turn/completed", { turn });
|
||||
}
|
||||
|
||||
function steerText(input: unknown): string {
|
||||
if (!Array.isArray(input)) return "";
|
||||
return input.flatMap((item) => {
|
||||
if (typeof item !== "object" || item === null || Array.isArray(item)) return [];
|
||||
const text = (item as Record<string, unknown>).text;
|
||||
return typeof text === "string" ? [text] : [];
|
||||
}).join("");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user