mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-24 23:51:48 +00:00
fix(tui): narrow stream/final merge fallback
This commit is contained in:
committed by
Peter Steinberger
parent
674a6765c5
commit
cc93254742
@@ -141,4 +141,27 @@ describe("TuiStreamAssembler", () => {
|
||||
|
||||
expect(finalText).toBe("Before tool call\nAfter tool call");
|
||||
});
|
||||
|
||||
it("prefers non-empty final payload when it is not a dropped block regression", () => {
|
||||
const assembler = new TuiStreamAssembler();
|
||||
assembler.ingestDelta(
|
||||
"run-7",
|
||||
{
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "NOT OK" }],
|
||||
},
|
||||
false,
|
||||
);
|
||||
|
||||
const finalText = assembler.finalize(
|
||||
"run-7",
|
||||
{
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "OK" }],
|
||||
},
|
||||
false,
|
||||
);
|
||||
|
||||
expect(finalText).toBe("OK");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,8 +23,17 @@ function mergeTextPreferRicher(currentText: string, nextText: string): string {
|
||||
if (next.includes(current)) {
|
||||
return next;
|
||||
}
|
||||
if (current.includes(next)) {
|
||||
return current;
|
||||
// Keep streamed text only when the newer payload looks like a dropped
|
||||
// leading/trailing block (the known regression shape), not any substring.
|
||||
const currentLines = current.split("\n");
|
||||
const nextLines = next.split("\n");
|
||||
if (currentLines.length > nextLines.length) {
|
||||
const isDroppedLeadingBlock =
|
||||
currentLines.slice(currentLines.length - nextLines.length).join("\n") === next;
|
||||
const isDroppedTrailingBlock = currentLines.slice(0, nextLines.length).join("\n") === next;
|
||||
if (isDroppedLeadingBlock || isDroppedTrailingBlock) {
|
||||
return current;
|
||||
}
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user