@@ -1,15 +1,12 @@
1-import * as c from "yoctocolors";
21 import { renderLine } from "./markdown.ts";
32 import { G, write, writeln } from "./output.ts";
43 import type { Spinner } from "./spinner.ts";
54
65 export class StreamRenderContent {
76 private inText = false;
8- private inReasoning = false;
97 private rawBuffer = "";
108 private streamedChars = 0;
119 private inFence = false;
12- private reasoningBlankLineRun = 0;
1310 private accumulatedText = "";
1411 private accumulatedReasoning = "";
1512
@@ -24,13 +21,10 @@ export class StreamRenderContent {
2421 }
2522
2623 hasOpenContent(): boolean {
27- return this.inText || this.inReasoning;
24+ return this.inText;
2825 }
2926
3027 appendTextDelta(delta: string): void {
31- if (this.inReasoning) {
32- this.flushOpenContent();
33- }
3428 if (!this.inText) {
3529 this.spinner.stop();
3630 write(`${G.reply} `);
@@ -42,49 +36,22 @@ export class StreamRenderContent {
4236 this.streamPartialRemainder();
4337 }
4438
45- appendReasoningDelta(delta: string, showReasoning: boolean): void {
39+ appendReasoningDelta(delta: string): void {
4640 this.accumulatedReasoning += delta;
47- if (!showReasoning) return;
48-
49- if (!this.inReasoning) {
50- if (this.inText) {
51- this.flushOpenContent();
52- }
53- this.spinner.stop();
54- writeln(`${G.info} ${c.dim("reasoning")}`);
55- this.inReasoning = true;
56- this.inFence = false;
57- }
58- this.rawBuffer += delta;
59- this.flushCompleteLines();
60- this.streamPartialRemainder();
6141 }
6242
6343 flushOpenContent(): void {
64- if (!this.inText && !this.inReasoning) return;
44+ if (!this.inText) return;
6545 this.streamPartialRemainder();
6646 writeln();
6747 this.inText = false;
68- this.inReasoning = false;
6948 this.inFence = false;
70- this.reasoningBlankLineRun = 0;
7149 this.rawBuffer = "";
7250 this.streamedChars = 0;
7351 }
7452
75- private renderSingleLine(raw: string): string | null {
76- const source = this.inReasoning ? raw.replace(/[ \t]+$/g, "") : raw;
77- if (this.inReasoning && source.trim() === "") {
78- this.reasoningBlankLineRun += 1;
79- if (this.reasoningBlankLineRun > 1) return null;
80- } else if (this.inReasoning) {
81- this.reasoningBlankLineRun = 0;
82- }
83-
84- if (this.inReasoning) {
85- return ` ${c.dim(source)}`;
86- }
87- const rendered = renderLine(source, this.inFence);
53+ private renderSingleLine(raw: string): string {
54+ const rendered = renderLine(raw, this.inFence);
8855 this.inFence = rendered.inFence;
8956 return rendered.output;
9057 }
@@ -105,8 +72,7 @@ export class StreamRenderContent {
10572 }
10673 writeln();
10774 } else {
108- if (rendered !== null) writeln(rendered);
109- else writeln();
75+ writeln(rendered);
11076 }
11177
11278 this.rawBuffer = this.rawBuffer.slice(boundary + 1);
@@ -124,11 +90,6 @@ export class StreamRenderContent {
12490
12591 private writePartial(text: string): void {
12692 if (!text) return;
127- if (this.inReasoning) {
128- const prefix = this.streamedChars === 0 ? " " : "";
129- write(`${prefix}${c.dim(text)}`);
130- return;
131- }
13293 write(text);
13394 }
13495 }