mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:30:43 +00:00
fix(agents): defuse unicode-whitespace MEDIA lines
This commit is contained in:
committed by
Peter Steinberger
parent
c165af97d7
commit
0020a327b9
@@ -81,6 +81,23 @@ describe("createTtsTool", () => {
|
||||
expect(rendered).toContain("[\u2060[audio_as_voice]]");
|
||||
});
|
||||
|
||||
it("defuses MEDIA lines with non-ASCII leading whitespace", async () => {
|
||||
textToSpeechSpy.mockResolvedValue({
|
||||
success: true,
|
||||
audioPath: "/tmp/reply.opus",
|
||||
provider: "test",
|
||||
voiceCompatible: true,
|
||||
});
|
||||
|
||||
const spoken = "line1\n\u00A0MEDIA:/tmp/secret.png";
|
||||
const tool = createTtsTool();
|
||||
const result = await tool.execute("call-1", { text: spoken });
|
||||
|
||||
const rendered = (result.content as Array<{ type: string; text: string }>)[0].text;
|
||||
expect(rendered).toContain("\u00A0\u2060MEDIA:/tmp/secret.png");
|
||||
expect(rendered).not.toMatch(/^\u00A0MEDIA:/m);
|
||||
});
|
||||
|
||||
it("defuses fenced-code delimiters embedded in the spoken text", async () => {
|
||||
textToSpeechSpy.mockResolvedValue({
|
||||
success: true,
|
||||
|
||||
@@ -26,7 +26,7 @@ const TtsToolSchema = Type.Object({
|
||||
*/
|
||||
function sanitizeTranscriptForToolContent(text: string): string {
|
||||
return text
|
||||
.replace(/^([ \t]*)MEDIA:/gim, "$1\u2060MEDIA:")
|
||||
.replace(/^([^\S\r\n]*)MEDIA:/gim, "$1\u2060MEDIA:")
|
||||
.replace(/\[\[/g, "[\u2060[")
|
||||
.replace(/^([ \t]*)(`{3,})/gm, (_match, indent: string, fence: string) => {
|
||||
const [first = "", ...rest] = fence;
|
||||
|
||||
Reference in New Issue
Block a user