refactor: only write reasoning to file; count line overflow better
This commit is contained in:
parent
8facbb0de2
commit
993fb143a2
2 changed files with 13 additions and 15 deletions
|
|
@ -1,5 +1,9 @@
|
|||
import os from "node:os";
|
||||
import type { AsyncIterableStream, TextStreamPart, ToolSet } from "ai";
|
||||
|
||||
const home = os.homedir();
|
||||
const reasoningWriter = Bun.file(`${home}/.aicl_reasoning.md`).writer();
|
||||
|
||||
let lineCount = 0;
|
||||
let charsSinceNL = 0;
|
||||
|
||||
|
|
@ -36,12 +40,14 @@ export async function renderStream(
|
|||
write("\u001b[2m\u001b[3m\n");
|
||||
} else if (part.type === "reasoning-delta") {
|
||||
write(part.text);
|
||||
reasoningWriter.write(part.text);
|
||||
checkContainment(part.text);
|
||||
} else if (part.type === "reasoning-end") {
|
||||
write("\n\u001b[22m\u001b[23m");
|
||||
moveCursor(0, -lineCount - 2);
|
||||
clearScreenDown();
|
||||
resetCounts();
|
||||
reasoningWriter.end();
|
||||
} else if (part.type === "text-start") {
|
||||
write("\n");
|
||||
} else if (part.type === "text-delta") {
|
||||
|
|
@ -64,7 +70,7 @@ function checkContainment(text: string) {
|
|||
charsSinceNL += text.length;
|
||||
if (text.includes("\n")) {
|
||||
lineCount += text.match(/\n/g)?.length ?? 1;
|
||||
charsSinceNL = 0;
|
||||
charsSinceNL = text.length - text.lastIndexOf("\n") - 1;
|
||||
} else if (charsSinceNL >= columns) {
|
||||
lineCount++;
|
||||
charsSinceNL = charsSinceNL - columns;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue