mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 11:01:24 +00:00
fix(media): strip audio attachments after successful transcription (openclaw#9076) thanks @nobrainer-tech
Verified: - pnpm install --frozen-lockfile - pnpm build - pnpm check - pnpm test (fails in known unrelated telegram suite) - pnpm vitest run src/auto-reply/media-note.test.ts src/auto-reply/reply.media-note.test.ts Co-authored-by: nobrainer-tech <445466+nobrainer-tech@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
a6003d6711
commit
7081dee1af
@@ -106,4 +106,93 @@ describe("buildInboundMediaNote", () => {
|
||||
});
|
||||
expect(note).toBe("[media attached: /tmp/b.png | https://example.com/b.png]");
|
||||
});
|
||||
|
||||
it("strips audio attachments when transcription succeeded via MediaUnderstanding (issue #4197)", () => {
|
||||
const note = buildInboundMediaNote({
|
||||
MediaPaths: ["/tmp/voice.ogg", "/tmp/image.png"],
|
||||
MediaUrls: ["https://example.com/voice.ogg", "https://example.com/image.png"],
|
||||
MediaTypes: ["audio/ogg", "image/png"],
|
||||
MediaUnderstanding: [
|
||||
{
|
||||
kind: "audio.transcription",
|
||||
attachmentIndex: 0,
|
||||
text: "Hello world",
|
||||
provider: "whisper",
|
||||
},
|
||||
],
|
||||
});
|
||||
// Audio attachment should be stripped (already transcribed), image should remain
|
||||
expect(note).toBe(
|
||||
"[media attached: /tmp/image.png (image/png) | https://example.com/image.png]",
|
||||
);
|
||||
});
|
||||
|
||||
it("only strips audio attachments that were transcribed", () => {
|
||||
const note = buildInboundMediaNote({
|
||||
MediaPaths: ["/tmp/voice-1.ogg", "/tmp/voice-2.ogg"],
|
||||
MediaUrls: ["https://example.com/voice-1.ogg", "https://example.com/voice-2.ogg"],
|
||||
MediaTypes: ["audio/ogg", "audio/ogg"],
|
||||
MediaUnderstanding: [
|
||||
{
|
||||
kind: "audio.transcription",
|
||||
attachmentIndex: 0,
|
||||
text: "First transcript",
|
||||
provider: "whisper",
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(note).toBe(
|
||||
"[media attached: /tmp/voice-2.ogg (audio/ogg) | https://example.com/voice-2.ogg]",
|
||||
);
|
||||
});
|
||||
|
||||
it("strips audio attachments when Transcript is present (issue #4197)", () => {
|
||||
const note = buildInboundMediaNote({
|
||||
MediaPaths: ["/tmp/voice.opus"],
|
||||
MediaTypes: ["audio/opus"],
|
||||
Transcript: "Hello world from Whisper",
|
||||
});
|
||||
// Audio should be stripped when transcript is available
|
||||
expect(note).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not strip multiple audio attachments using transcript-only fallback", () => {
|
||||
const note = buildInboundMediaNote({
|
||||
MediaPaths: ["/tmp/voice-1.ogg", "/tmp/voice-2.ogg"],
|
||||
MediaTypes: ["audio/ogg", "audio/ogg"],
|
||||
Transcript: "Transcript text without per-attachment mapping",
|
||||
});
|
||||
expect(note).toBe(
|
||||
[
|
||||
"[media attached: 2 files]",
|
||||
"[media attached 1/2: /tmp/voice-1.ogg (audio/ogg)]",
|
||||
"[media attached 2/2: /tmp/voice-2.ogg (audio/ogg)]",
|
||||
].join("\n"),
|
||||
);
|
||||
});
|
||||
|
||||
it("strips audio by extension even without mime type (issue #4197)", () => {
|
||||
const note = buildInboundMediaNote({
|
||||
MediaPaths: ["/tmp/voice_message.ogg", "/tmp/document.pdf"],
|
||||
MediaUnderstanding: [
|
||||
{
|
||||
kind: "audio.transcription",
|
||||
attachmentIndex: 0,
|
||||
text: "Transcribed audio content",
|
||||
provider: "whisper",
|
||||
},
|
||||
],
|
||||
});
|
||||
// Only PDF should remain, audio stripped by extension
|
||||
expect(note).toBe("[media attached: /tmp/document.pdf]");
|
||||
});
|
||||
|
||||
it("keeps audio attachments when no transcription available", () => {
|
||||
const note = buildInboundMediaNote({
|
||||
MediaPaths: ["/tmp/voice.ogg"],
|
||||
MediaTypes: ["audio/ogg"],
|
||||
});
|
||||
// No transcription = keep audio attachment as fallback
|
||||
expect(note).toBe("[media attached: /tmp/voice.ogg (audio/ogg)]");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user