fix(ui): revert PR #18093 directive tags (#19188)

This commit is contained in:
Seb Slight
2026-02-17 09:16:13 -05:00
committed by GitHub
parent d54e4af4a1
commit afd78133ba
2 changed files with 3 additions and 67 deletions

View File

@@ -25,48 +25,6 @@ describe("extractTextCached", () => {
});
});
describe("extractText strips directive tags from assistant messages", () => {
it("strips [[reply_to_current]]", () => {
const message = {
role: "assistant",
content: "Hello there [[reply_to_current]]",
};
expect(extractText(message)).toBe("Hello there");
});
it("strips [[reply_to:<id>]]", () => {
const message = {
role: "assistant",
content: [{ type: "text", text: "Done [[reply_to: abc123]]" }],
};
expect(extractText(message)).toBe("Done");
});
it("strips [[audio_as_voice]]", () => {
const message = {
role: "assistant",
content: "Listen up [[audio_as_voice]]",
};
expect(extractText(message)).toBe("Listen up");
});
it("does not strip tags from user messages", () => {
const message = {
role: "user",
content: "Hello [[reply_to_current]]",
};
expect(extractText(message)).toBe("Hello [[reply_to_current]]");
});
it("strips tag from .text property", () => {
const message = {
role: "assistant",
text: "Hi [[reply_to_current]]",
};
expect(extractText(message)).toBe("Hi");
});
});
describe("extractThinkingCached", () => {
it("matches extractThinking output", () => {
const message = {

View File

@@ -1,19 +1,6 @@
import { stripEnvelope } from "../../../../src/shared/chat-envelope.js";
import { stripThinkingTags } from "../format.ts";
/**
* Strip inline directive tags (`[[reply_to_current]]`, `[[reply_to:<id>]]`,
* `[[audio_as_voice]]`) that should never be rendered to the user.
* Matches the same patterns as `src/utils/directive-tags.ts`.
*/
function stripDirectiveTags(text: string): string {
return text
.replace(/\[\[\s*(?:reply_to_current|reply_to\s*:\s*[^\]\n]+|audio_as_voice)\s*\]\]/gi, "")
.replace(/[ \t]+/g, " ")
.replace(/[ \t]*\n[ \t]*/g, "\n")
.trim();
}
const textCache = new WeakMap<object, string | null>();
const thinkingCache = new WeakMap<object, string | null>();
@@ -22,10 +9,7 @@ export function extractText(message: unknown): string | null {
const role = typeof m.role === "string" ? m.role : "";
const content = m.content;
if (typeof content === "string") {
let processed = role === "assistant" ? stripThinkingTags(content) : stripEnvelope(content);
if (role === "assistant") {
processed = stripDirectiveTags(processed);
}
const processed = role === "assistant" ? stripThinkingTags(content) : stripEnvelope(content);
return processed;
}
if (Array.isArray(content)) {
@@ -40,18 +24,12 @@ export function extractText(message: unknown): string | null {
.filter((v): v is string => typeof v === "string");
if (parts.length > 0) {
const joined = parts.join("\n");
let processed = role === "assistant" ? stripThinkingTags(joined) : stripEnvelope(joined);
if (role === "assistant") {
processed = stripDirectiveTags(processed);
}
const processed = role === "assistant" ? stripThinkingTags(joined) : stripEnvelope(joined);
return processed;
}
}
if (typeof m.text === "string") {
let processed = role === "assistant" ? stripThinkingTags(m.text) : stripEnvelope(m.text);
if (role === "assistant") {
processed = stripDirectiveTags(processed);
}
const processed = role === "assistant" ? stripThinkingTags(m.text) : stripEnvelope(m.text);
return processed;
}
return null;