From 229817fdc79942dd1b307ac63a873fc267f135be Mon Sep 17 00:00:00 2001 From: mariko-code-bot Date: Wed, 11 Mar 2026 22:57:47 +0000 Subject: [PATCH] fix(tts): correct return mimeType and include ok in send details --- src/agents/tools/tts-tool.test.ts | 40 +++++++++++++++++++++++++++++++ src/agents/tools/tts-tool.ts | 9 +++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/agents/tools/tts-tool.test.ts b/src/agents/tools/tts-tool.test.ts index 07284bf8105..5b07da266ae 100644 --- a/src/agents/tools/tts-tool.test.ts +++ b/src/agents/tools/tts-tool.test.ts @@ -39,10 +39,50 @@ describe("createTtsTool", () => { ok: true, deliveryMode: "return", audioPath: "/tmp/openclaw/tts-test/voice.mp3", + mimeType: "audio/mpeg", sent: false, }); }); + it("uses audio/ogg mimeType for voice-compatible return output", async () => { + textToSpeechMock.mockResolvedValueOnce({ + success: true, + audioPath: "/tmp/openclaw/tts-test/voice.opus", + provider: "openai", + voiceCompatible: true, + }); + const tool = createTtsTool(); + + const result = await tool.execute("call-voice", { + text: "hello", + channel: "telegram", + deliveryMode: "return", + }); + + expect(result.details).toMatchObject({ + ok: true, + deliveryMode: "return", + mimeType: "audio/ogg", + }); + }); + + it("includes ok=true in send mode success details", async () => { + textToSpeechMock.mockResolvedValueOnce({ + success: true, + audioPath: "/tmp/openclaw/tts-test/voice.mp3", + provider: "openai", + voiceCompatible: false, + }); + const tool = createTtsTool(); + + const result = await tool.execute("call-send", { + text: "hello", + deliveryMode: "send", + }); + + expect(result.details).toMatchObject({ ok: true, deliveryMode: "send" }); + }); + it("returns validation error for invalid deliveryMode", async () => { const tool = createTtsTool(); const result = await tool.execute("call-2", { diff --git a/src/agents/tools/tts-tool.ts b/src/agents/tools/tts-tool.ts index d313ed7140a..2d54ab8499f 100644 --- a/src/agents/tools/tts-tool.ts +++ b/src/agents/tools/tts-tool.ts @@ -72,7 +72,7 @@ export function createTtsTool(opts?: { ok: true, deliveryMode: "return", audioPath: result.audioPath, - mimeType: "audio/mpeg", + mimeType: result.voiceCompatible ? "audio/ogg" : "audio/mpeg", sent: false, provider: result.provider, }, @@ -87,7 +87,12 @@ export function createTtsTool(opts?: { lines.push(`MEDIA:${result.audioPath}`); return { content: [{ type: "text", text: lines.join("\n") }], - details: { audioPath: result.audioPath, provider: result.provider, deliveryMode: "send" }, + details: { + ok: true, + audioPath: result.audioPath, + provider: result.provider, + deliveryMode: "send", + }, }; }