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,33 +60,49 @@ 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) {
if (supportsColorStderr) case "reasoning-start": {
this.write(`${styles.dim.open}${styles.italic.open}`, process.stderr); if (supportsColorStderr)
this.write("\n", process.stderr); this.write(
} else if (part.type === "reasoning-delta") { `${styles.dim.open}${styles.italic.open}`,
this.write(part.text, process.stderr); process.stderr,
reasoningWriter.write(part.text); );
this.checkContainment(part.text, process.stderr); this.write("\n", process.stderr);
} else if (part.type === "reasoning-end") { break;
if (supportsColorStderr) }
this.write( case "reasoning-delta": {
`${styles.italic.close}${styles.dim.close}`, this.write(part.text, process.stderr);
process.stderr, this.checkContainment(part.text, process.stderr);
); reasoningWriter.write(part.text);
this.moveCursor(-this.lineCount - 1, process.stderr); break;
this.clearScreenDown(process.stderr); }
this.resetCounts(); case "reasoning-end": {
reasoningWriter.end(); if (supportsColorStderr)
} else if (part.type === "text-start") { this.write(
this.write("\n"); `${styles.italic.close}${styles.dim.close}`,
} else if (part.type === "text-delta") { process.stderr,
this.write(part.text); );
this.checkContainment(part.text); this.moveCursor(-this.lineCount - 1, process.stderr);
} else if (part.type === "text-end") { this.clearScreenDown(process.stderr);
this.moveCursor(-this.lineCount - 1); this.resetCounts();
this.clearScreenDown(process.stderr); reasoningWriter.end();
this.resetCounts(); break;
}
case "text-start": {
this.write("\n");
break;
}
case "text-delta": {
this.write(part.text);
this.checkContainment(part.text);
break;
}
case "text-end": {
this.moveCursor(-this.lineCount - 1);
this.clearScreenDown(process.stderr);
this.resetCounts();
break;
}
} }
while (!this.memOk) await Bun.sleep(10); while (!this.memOk) await Bun.sleep(10);