mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 13:21:25 +00:00
fix: refactor TUI stream assembly (#1202, thanks @aaronveklabs)
Co-authored-by: Aaron <aaron@vektor-labs.com>
This commit is contained in:
68
src/tui/tui-stream-assembler.test.ts
Normal file
68
src/tui/tui-stream-assembler.test.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { TuiStreamAssembler } from "./tui-stream-assembler.js";
|
||||
|
||||
describe("TuiStreamAssembler", () => {
|
||||
it("keeps thinking before content even when thinking arrives later", () => {
|
||||
const assembler = new TuiStreamAssembler();
|
||||
const first = assembler.ingestDelta(
|
||||
"run-1",
|
||||
{
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "Hello" }],
|
||||
},
|
||||
true,
|
||||
);
|
||||
expect(first).toBe("Hello");
|
||||
|
||||
const second = assembler.ingestDelta(
|
||||
"run-1",
|
||||
{
|
||||
role: "assistant",
|
||||
content: [{ type: "thinking", thinking: "Brain" }],
|
||||
},
|
||||
true,
|
||||
);
|
||||
expect(second).toBe("[thinking]\nBrain\n\nHello");
|
||||
});
|
||||
|
||||
it("omits thinking when showThinking is false", () => {
|
||||
const assembler = new TuiStreamAssembler();
|
||||
const text = assembler.ingestDelta(
|
||||
"run-2",
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "thinking", thinking: "Hidden" },
|
||||
{ type: "text", text: "Visible" },
|
||||
],
|
||||
},
|
||||
false,
|
||||
);
|
||||
|
||||
expect(text).toBe("Visible");
|
||||
});
|
||||
|
||||
it("falls back to streamed text on empty final payload", () => {
|
||||
const assembler = new TuiStreamAssembler();
|
||||
assembler.ingestDelta(
|
||||
"run-3",
|
||||
{
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "Streamed" }],
|
||||
},
|
||||
false,
|
||||
);
|
||||
|
||||
const finalText = assembler.finalize(
|
||||
"run-3",
|
||||
{
|
||||
role: "assistant",
|
||||
content: [],
|
||||
},
|
||||
false,
|
||||
);
|
||||
|
||||
expect(finalText).toBe("Streamed");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user