mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 09:30:20 +00:00
fix: prefer final-answer text in web chat previews
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { extractFirstTextBlock } from "./chat-message-content.js";
|
||||
import { extractAssistantVisibleText, extractFirstTextBlock } from "./chat-message-content.js";
|
||||
|
||||
describe("shared/chat-message-content", () => {
|
||||
it("extracts the first text block from array content", () => {
|
||||
@@ -47,3 +47,66 @@ describe("shared/chat-message-content", () => {
|
||||
expect(extractFirstTextBlock({ content: [{ text: 1 }, { text: "later" }] })).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("extractAssistantVisibleText", () => {
|
||||
it("prefers final_answer text over commentary text", () => {
|
||||
expect(
|
||||
extractAssistantVisibleText({
|
||||
role: "assistant",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "thinking like caveman",
|
||||
textSignature: JSON.stringify({ v: 1, id: "msg_commentary", phase: "commentary" }),
|
||||
},
|
||||
{
|
||||
type: "text",
|
||||
text: "Actual final answer",
|
||||
textSignature: JSON.stringify({ v: 1, id: "msg_final", phase: "final_answer" }),
|
||||
},
|
||||
],
|
||||
}),
|
||||
).toBe("Actual final answer");
|
||||
});
|
||||
|
||||
it("does not fall back to commentary-only text", () => {
|
||||
expect(
|
||||
extractAssistantVisibleText({
|
||||
role: "assistant",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "thinking like caveman",
|
||||
textSignature: JSON.stringify({ v: 1, id: "msg_commentary", phase: "commentary" }),
|
||||
},
|
||||
],
|
||||
}),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("falls back to unphased legacy text", () => {
|
||||
expect(
|
||||
extractAssistantVisibleText({
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "Legacy answer" }],
|
||||
}),
|
||||
).toBe("Legacy answer");
|
||||
});
|
||||
|
||||
it("does not mix unphased legacy text into final_answer output", () => {
|
||||
expect(
|
||||
extractAssistantVisibleText({
|
||||
role: "assistant",
|
||||
phase: "final_answer",
|
||||
content: [
|
||||
{ type: "text", text: "Legacy answer" },
|
||||
{
|
||||
type: "text",
|
||||
text: "Actual final answer",
|
||||
textSignature: JSON.stringify({ v: 1, id: "msg_final", phase: "final_answer" }),
|
||||
},
|
||||
],
|
||||
}),
|
||||
).toBe("Actual final answer");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user