mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
Web UI: strip relevant-memories scaffolding
This commit is contained in:
@@ -23,6 +23,25 @@ describe("extractTextCached", () => {
|
||||
expect(extractTextCached(message)).toBe("plain text");
|
||||
expect(extractTextCached(message)).toBe("plain text");
|
||||
});
|
||||
|
||||
it("strips assistant relevant-memories scaffolding", () => {
|
||||
const message = {
|
||||
role: "assistant",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: [
|
||||
"<relevant-memories>",
|
||||
"Internal memory context",
|
||||
"</relevant-memories>",
|
||||
"Final user answer",
|
||||
].join("\n"),
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(extractText(message)).toBe("Final user answer");
|
||||
expect(extractTextCached(message)).toBe("Final user answer");
|
||||
});
|
||||
});
|
||||
|
||||
describe("extractThinkingCached", () => {
|
||||
|
||||
@@ -68,4 +68,34 @@ describe("stripThinkingTags", () => {
|
||||
expect(stripThinkingTags("<final\nHello")).toBe("<final\nHello");
|
||||
expect(stripThinkingTags("Hello</final>")).toBe("Hello");
|
||||
});
|
||||
|
||||
it("strips <relevant-memories> blocks", () => {
|
||||
const input = [
|
||||
"<relevant-memories>",
|
||||
"The following memories may be relevant to this conversation:",
|
||||
"- Internal memory note",
|
||||
"</relevant-memories>",
|
||||
"",
|
||||
"User-visible answer",
|
||||
].join("\n");
|
||||
expect(stripThinkingTags(input)).toBe("User-visible answer");
|
||||
});
|
||||
|
||||
it("keeps relevant-memories tags in fenced code blocks", () => {
|
||||
const input = [
|
||||
"```xml",
|
||||
"<relevant-memories>",
|
||||
"sample",
|
||||
"</relevant-memories>",
|
||||
"```",
|
||||
"",
|
||||
"Visible text",
|
||||
].join("\n");
|
||||
expect(stripThinkingTags(input)).toBe(input);
|
||||
});
|
||||
|
||||
it("hides unfinished <relevant-memories> block tails", () => {
|
||||
const input = ["Hello", "<relevant-memories>", "internal-only"].join("\n");
|
||||
expect(stripThinkingTags(input)).toBe("Hello\n");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { formatDurationHuman } from "../../../src/infra/format-time/format-duration.ts";
|
||||
import { formatRelativeTimestamp } from "../../../src/infra/format-time/format-relative.ts";
|
||||
import { stripReasoningTagsFromText } from "../../../src/shared/text/reasoning-tags.js";
|
||||
import { stripAssistantInternalScaffolding } from "../../../src/shared/text/assistant-visible-text.js";
|
||||
|
||||
export { formatRelativeTimestamp, formatDurationHuman };
|
||||
|
||||
@@ -56,5 +56,5 @@ export function parseList(input: string): string[] {
|
||||
}
|
||||
|
||||
export function stripThinkingTags(value: string): string {
|
||||
return stripReasoningTagsFromText(value, { mode: "preserve", trim: "start" });
|
||||
return stripAssistantInternalScaffolding(value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user