Skip to content

Commit 54ab69d

Browse files
committed
fix(telegram): exclude reasoning blocks from TTS fallback
1 parent 8ba7e44 commit 54ab69d

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/auto-reply/reply/dispatch-from-config.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7380,6 +7380,38 @@ describe("dispatchReplyFromConfig", () => {
73807380
expect(blockReplySentTexts).toContain("The answer is 42");
73817381
});
73827382

7383+
it("keeps Telegram isReasoning block replies out of final TTS fallback", async () => {
7384+
setNoAbort();
7385+
ttsMocks.state.synthesizeFinalAudio = true;
7386+
const dispatcher = createDispatcher();
7387+
const ctx = buildTestCtx({ Provider: "telegram", Surface: "telegram" });
7388+
const blockReplySentTexts: string[] = [];
7389+
const replyResolver = async (
7390+
_ctx: MsgContext,
7391+
opts?: GetReplyOptions,
7392+
): Promise<ReplyPayload | undefined> => {
7393+
await opts?.onBlockReply?.({ text: "thinking...", isReasoning: true });
7394+
await opts?.onBlockReply?.({ text: "The answer is 42" });
7395+
return undefined;
7396+
};
7397+
(dispatcher.sendBlockReply as ReturnType<typeof vi.fn>).mockImplementation(
7398+
(payload: ReplyPayload) => {
7399+
if (payload.text) {
7400+
blockReplySentTexts.push(payload.text);
7401+
}
7402+
return true;
7403+
},
7404+
);
7405+
7406+
await dispatchReplyFromConfig({ ctx, cfg: emptyConfig, dispatcher, replyResolver });
7407+
7408+
expect(blockReplySentTexts).toEqual(["thinking...", "The answer is 42"]);
7409+
const ttsCall = ttsMocks.maybeApplyTtsToPayload.mock.calls
7410+
.map(([call]) => call as { kind?: unknown; payload?: ReplyPayload })
7411+
.find((call) => call.kind === "final");
7412+
expect(ttsCall?.payload).toEqual({ text: "The answer is 42" });
7413+
});
7414+
73837415
it("strips split TTS directives from streamed block text before delivery", async () => {
73847416
setNoAbort();
73857417
ttsMocks.state.synthesizeFinalAudio = true;

src/auto-reply/reply/dispatch-from-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3113,7 +3113,7 @@ export async function dispatchReplyFromConfig(
31133113
// Exclude status notices — they are informational UI signals
31143114
// and must not be synthesised into the spoken reply.
31153115
const isStatusNotice = isReplyPayloadStatusNotice(payload);
3116-
if (payload.text && !isStatusNotice) {
3116+
if (payload.text && !isStatusNotice && payload.isReasoning !== true) {
31173117
const joinsBufferedTtsDirective =
31183118
cleanBlockTtsDirectiveText?.hasBufferedDirectiveText() === true;
31193119
if (accumulatedBlockText.length > 0) {

0 commit comments

Comments
 (0)