refactor: renderStream to use switch
This commit is contained in:
parent
4716712a92
commit
ebbdda2853
1 changed files with 43 additions and 27 deletions
|
|
@ -60,15 +60,23 @@ export default class StreamRenderer {
|
|||
this.resetCounts();
|
||||
|
||||
for await (const part of stream) {
|
||||
if (part.type === "reasoning-start") {
|
||||
switch (part.type) {
|
||||
case "reasoning-start": {
|
||||
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);
|
||||
} else if (part.type === "reasoning-delta") {
|
||||
break;
|
||||
}
|
||||
case "reasoning-delta": {
|
||||
this.write(part.text, process.stderr);
|
||||
reasoningWriter.write(part.text);
|
||||
this.checkContainment(part.text, process.stderr);
|
||||
} else if (part.type === "reasoning-end") {
|
||||
reasoningWriter.write(part.text);
|
||||
break;
|
||||
}
|
||||
case "reasoning-end": {
|
||||
if (supportsColorStderr)
|
||||
this.write(
|
||||
`${styles.italic.close}${styles.dim.close}`,
|
||||
|
|
@ -78,15 +86,23 @@ export default class StreamRenderer {
|
|||
this.clearScreenDown(process.stderr);
|
||||
this.resetCounts();
|
||||
reasoningWriter.end();
|
||||
} else if (part.type === "text-start") {
|
||||
break;
|
||||
}
|
||||
case "text-start": {
|
||||
this.write("\n");
|
||||
} else if (part.type === "text-delta") {
|
||||
break;
|
||||
}
|
||||
case "text-delta": {
|
||||
this.write(part.text);
|
||||
this.checkContainment(part.text);
|
||||
} else if (part.type === "text-end") {
|
||||
break;
|
||||
}
|
||||
case "text-end": {
|
||||
this.moveCursor(-this.lineCount - 1);
|
||||
this.clearScreenDown(process.stderr);
|
||||
this.resetCounts();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (!this.memOk) await Bun.sleep(10);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue