mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 20:28:29 +00:00
fix(agents): restrict MEDIA: token parsing to line start in tool results (#18510)
This commit is contained in:
committed by
Peter Steinberger
parent
93fbe6482b
commit
0587e4cc73
@@ -129,4 +129,92 @@ describe("extractToolResultMediaPaths", () => {
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toEqual([]);
|
||||
});
|
||||
|
||||
it("does not match <media:audio> placeholder as a MEDIA: token", () => {
|
||||
const result = {
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "<media:audio> placeholder with successful preflight voice transcript",
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toEqual([]);
|
||||
});
|
||||
|
||||
it("does not match <media:image> placeholder as a MEDIA: token", () => {
|
||||
const result = {
|
||||
content: [{ type: "text", text: "<media:image> (2 images)" }],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toEqual([]);
|
||||
});
|
||||
|
||||
it("does not match other media placeholder variants", () => {
|
||||
for (const tag of [
|
||||
"<media:video>",
|
||||
"<media:document>",
|
||||
"<media:sticker>",
|
||||
"<media:attachment>",
|
||||
]) {
|
||||
const result = {
|
||||
content: [{ type: "text", text: `${tag} some context` }],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toEqual([]);
|
||||
}
|
||||
});
|
||||
|
||||
it("does not match mid-line MEDIA: in documentation text", () => {
|
||||
const result = {
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: 'Use MEDIA: "https://example.com/voice.ogg", asVoice: true to send voice',
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toEqual([]);
|
||||
});
|
||||
|
||||
it("still extracts MEDIA: at line start after other text lines", () => {
|
||||
const result = {
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "Generated screenshot\nMEDIA:/tmp/screenshot.png\nDone",
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toEqual(["/tmp/screenshot.png"]);
|
||||
});
|
||||
|
||||
it("extracts indented MEDIA: line", () => {
|
||||
const result = {
|
||||
content: [{ type: "text", text: " MEDIA:/tmp/indented.png" }],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toEqual(["/tmp/indented.png"]);
|
||||
});
|
||||
|
||||
it("extracts valid MEDIA: line while ignoring <media:audio> on another line", () => {
|
||||
const result = {
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "<media:audio> was transcribed\nMEDIA:/tmp/tts-output.opus\nDone",
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toEqual(["/tmp/tts-output.opus"]);
|
||||
});
|
||||
|
||||
it("extracts multiple MEDIA: lines from a single text block", () => {
|
||||
const result = {
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "MEDIA:/tmp/page1.png\nSome text\nMEDIA:/tmp/page2.png",
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(extractToolResultMediaPaths(result)).toEqual(["/tmp/page1.png", "/tmp/page2.png"]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user