refactor: renderStream to use switch

This commit is contained in:
mitchell 2026-04-17 03:28:51 -04:00
parent 4716712a92
commit ebbdda2853

View file

@ -60,15 +60,23 @@ export default class StreamRenderer {
this.resetCounts(); this.resetCounts();
for await (const part of stream) { for await (const part of stream) {
if (part.type === "reasoning-start") { switch (part.type) {
case "reasoning-start": {
if (supportsColorStderr) if (supportsColorStderr)
this.write(`${styles.dim.open}${styles.italic.open}`, process.stderr); this.write(
`${styles.dim.open}${styles.italic.open}`,
process.stderr,
);
this.write("\n", process.stderr); this.write("\n", process.stderr);
} else if (part.type === "reasoning-delta") { break;
}
case "reasoning-delta": {
this.write(part.text, process.stderr); this.write(part.text, process.stderr);
reasoningWriter.write(part.text);
this.checkContainment(part.text, process.stderr); this.checkContainment(part.text, process.stderr);
} else if (part.type === "reasoning-end") { reasoningWriter.write(part.text);
break;
}
case "reasoning-end": {
if (supportsColorStderr) if (supportsColorStderr)
this.write( this.write(
`${styles.italic.close}${styles.dim.close}`, `${styles.italic.close}${styles.dim.close}`,
@ -78,15 +86,23 @@ export default class StreamRenderer {
this.clearScreenDown(process.stderr); this.clearScreenDown(process.stderr);
this.resetCounts(); this.resetCounts();
reasoningWriter.end(); reasoningWriter.end();
} else if (part.type === "text-start") { break;
}
case "text-start": {
this.write("\n"); this.write("\n");
} else if (part.type === "text-delta") { break;
}
case "text-delta": {
this.write(part.text); this.write(part.text);
this.checkContainment(part.text); this.checkContainment(part.text);
} else if (part.type === "text-end") { break;
}
case "text-end": {
this.moveCursor(-this.lineCount - 1); this.moveCursor(-this.lineCount - 1);
this.clearScreenDown(process.stderr); this.clearScreenDown(process.stderr);
this.resetCounts(); this.resetCounts();
break;
}
} }
while (!this.memOk) await Bun.sleep(10); while (!this.memOk) await Bun.sleep(10);