fix: 支持长工具调用 interrupt 与硬超时回收
This commit is contained in:
@@ -224,6 +224,29 @@ for await (const line of rl) {
|
||||
}, 50);
|
||||
continue;
|
||||
}
|
||||
if (mode === "tool-hangs-before-turn-start-response") {
|
||||
turnCounter += 1;
|
||||
const turn = { id: `turn_selftest_${turnCounter}`, status: "running" };
|
||||
notify("turn/started", { turn });
|
||||
notify("item/started", { item: { id: "tool_hang_before_response", type: "commandExecution", command: "hwpod cmd git clone", status: "running", processId: process.pid } });
|
||||
notify("item/commandExecution/outputDelta", { itemId: "tool_hang_before_response", delta: "clone started\n" });
|
||||
activeSteerTurn = { id: turn.id, completed: false, timer: setTimeout(() => undefined, 60_000) };
|
||||
continue;
|
||||
}
|
||||
if (mode === "hard-timeout-tool-progress") {
|
||||
turnCounter += 1;
|
||||
const turn = { id: `turn_selftest_${turnCounter}`, status: "running" };
|
||||
notify("turn/started", { turn });
|
||||
notify("item/started", { item: { id: "tool_hard_timeout", type: "commandExecution", command: "hwpod cmd long-running", status: "running", processId: process.pid } });
|
||||
respond(message.id, { turn });
|
||||
activeSteerTurn = { id: turn.id, completed: false, timer: null };
|
||||
let ticks = 0;
|
||||
activeSteerTurn.timer = setInterval(() => {
|
||||
ticks += 1;
|
||||
notify("item/commandExecution/outputDelta", { itemId: "tool_hard_timeout", delta: `progress ${ticks}\n` });
|
||||
}, 25);
|
||||
continue;
|
||||
}
|
||||
if (mode === "steer-waits") {
|
||||
turnCounter += 1;
|
||||
const turn = { id: `turn_selftest_${turnCounter}`, status: "running" };
|
||||
@@ -276,6 +299,16 @@ for await (const line of rl) {
|
||||
setTimeout(() => completeActiveSteerTurn("steer-applied"), 20);
|
||||
continue;
|
||||
}
|
||||
if (message.method === "turn/interrupt") {
|
||||
if ((mode !== "tool-hangs-before-turn-start-response" && mode !== "hard-timeout-tool-progress" && mode !== "steer-waits") || !activeSteerTurn) {
|
||||
respond(message.id, null, { code: -32000, message: "no active fake turn for interrupt" });
|
||||
continue;
|
||||
}
|
||||
notify("item/completed", { item: { id: "tool_interrupted", type: "commandExecution", command: "hwpod cmd interrupted", status: "cancelled" } });
|
||||
respond(message.id, { interrupted: true });
|
||||
setTimeout(() => completeActiveSteerTurn("interrupt-applied", "cancelled"), 20);
|
||||
continue;
|
||||
}
|
||||
respond(message.id, null, { code: -32601, message: `unsupported fake method ${message.method ?? "unknown"}` });
|
||||
}
|
||||
|
||||
@@ -288,11 +321,11 @@ function notify(method: string, params: unknown): void {
|
||||
process.stdout.write(`${JSON.stringify({ method, params })}\n`);
|
||||
}
|
||||
|
||||
function completeActiveSteerTurn(reason: string): void {
|
||||
function completeActiveSteerTurn(reason: string, status = "completed"): void {
|
||||
if (!activeSteerTurn || activeSteerTurn.completed) return;
|
||||
activeSteerTurn.completed = true;
|
||||
if (activeSteerTurn.timer) clearTimeout(activeSteerTurn.timer);
|
||||
const turn = { id: activeSteerTurn.id, status: "completed", reason };
|
||||
const turn = { id: activeSteerTurn.id, status, reason };
|
||||
notify("turn/completed", { turn });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user