Skip to content

Commit f4dee99

Browse files
zhangguiping-xydtobviyus
authored andcommitted
fix(telegram): clear progress draft before tool artifacts
1 parent db33402 commit f4dee99

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

extensions/telegram/src/bot-message-dispatch.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,6 +2689,34 @@ describe("dispatchTelegramMessage draft streaming", () => {
26892689
);
26902690
});
26912691

2692+
it("clears progress drafts before visible tool artifacts", async () => {
2693+
const { answerDraftStream } = setupDraftStreams({ answerMessageId: 2001 });
2694+
dispatchReplyWithBufferedBlockDispatcher.mockImplementation(
2695+
async ({ dispatcherOptions, replyOptions }) => {
2696+
await replyOptions?.onToolStart?.({ name: "exec", phase: "start" });
2697+
await dispatcherOptions.deliver(
2698+
{ mediaUrl: "https://example.com/validation.txt" },
2699+
{ kind: "tool" },
2700+
);
2701+
await dispatcherOptions.deliver({ text: "Final answer" }, { kind: "final" });
2702+
return { queuedFinal: true };
2703+
},
2704+
);
2705+
2706+
await dispatchWithContext({
2707+
context: createContext(),
2708+
streamMode: "progress",
2709+
telegramCfg: { streaming: { mode: "progress", progress: { label: "Shelling" } } },
2710+
});
2711+
2712+
expect(answerDraftStream.update).toHaveBeenCalledWith("Shelling\n\n`🛠️ Exec`");
2713+
expectDeliveredReply(0, { mediaUrl: "https://example.com/validation.txt" });
2714+
expectDeliveredReply(0, { text: "Final answer" }, 1);
2715+
expect(answerDraftStream.clear.mock.invocationCallOrder[0]).toBeLessThan(
2716+
deliverReplies.mock.invocationCallOrder[0],
2717+
);
2718+
});
2719+
26922720
it("does not stream text-only tool results into progress drafts", async () => {
26932721
const { answerDraftStream } = setupDraftStreams({ answerMessageId: 2001 });
26942722
dispatchReplyWithBufferedBlockDispatcher.mockImplementation(

extensions/telegram/src/bot-message-dispatch.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,6 +2276,9 @@ export const dispatchTelegramMessage = async ({
22762276
}
22772277
return;
22782278
}
2279+
if (streamMode === "progress" && info.kind === "tool") {
2280+
await rotateAnswerLaneAfterToolProgress();
2281+
}
22792282
const delivered = await sendPayload(effectivePayload, {
22802283
durable: info.kind === "final",
22812284
});

0 commit comments

Comments
 (0)