mirror of
https://github.com/andrewyng/openworker.git
synced 2026-09-11 14:50:14 +00:00
Keep interrupted partial streams in the transcript
GUI flushes the streaming buffer into a durable item on interrupted/error. Engine persists partial text on the provider-error path like the stop path. e2e red-green verified; full suites pass.
This commit is contained in:
@@ -567,6 +567,7 @@ export async function mockApi(page: import("@playwright/test").Page) {
|
||||
ws.send(JSON.stringify({ type, data }));
|
||||
send("ready");
|
||||
let pendingTool = "run_shell"; // which proposal the next approval decision resolves
|
||||
let epicTimer: ReturnType<typeof setInterval> | null = null; // the slow stream, stoppable via interrupt
|
||||
ws.onMessage((raw) => {
|
||||
const msg = JSON.parse(String(raw));
|
||||
if (msg.type === "user_message") {
|
||||
@@ -651,11 +652,12 @@ export async function mockApi(page: import("@playwright/test").Page) {
|
||||
if (/stream the epic/i.test(msg.text)) {
|
||||
let ticks = 0;
|
||||
const line = "The epic scrolls ever onward, line upon line upon line. ";
|
||||
const timer = setInterval(() => {
|
||||
epicTimer = setInterval(() => {
|
||||
ticks += 1;
|
||||
send("assistant_delta", { text: line.repeat(3) + "\n\n" });
|
||||
if (ticks >= 40) {
|
||||
clearInterval(timer);
|
||||
clearInterval(epicTimer!);
|
||||
epicTimer = null;
|
||||
send("assistant_message", { text: ("The epic concludes. " + line).repeat(20) });
|
||||
send("turn_done");
|
||||
}
|
||||
@@ -686,6 +688,15 @@ export async function mockApi(page: import("@playwright/test").Page) {
|
||||
send("assistant_message", { text: `Done via ${pendingTool} [decision=${msg.decision}]` });
|
||||
}
|
||||
send("turn_done");
|
||||
} else if (msg.type === "interrupt") {
|
||||
// Stop mid-stream: like the real engine, end the turn with `interrupted` and
|
||||
// NO assistant_message — the client owns promoting the partial into the transcript.
|
||||
if (epicTimer) {
|
||||
clearInterval(epicTimer);
|
||||
epicTimer = null;
|
||||
}
|
||||
send("interrupted", {});
|
||||
send("turn_done");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user