Skip to content

Commit 48bea40

Browse files
fix(telegram): clear progress draft before tool artifacts
1 parent 40b3e7e commit 48bea40

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
@@ -2436,6 +2436,34 @@ describe("dispatchTelegramMessage draft streaming", () => {
24362436
);
24372437
});
24382438

2439+
it("clears progress drafts before visible tool artifacts", async () => {
2440+
const { answerDraftStream } = setupDraftStreams({ answerMessageId: 2001 });
2441+
dispatchReplyWithBufferedBlockDispatcher.mockImplementation(
2442+
async ({ dispatcherOptions, replyOptions }) => {
2443+
await replyOptions?.onToolStart?.({ name: "exec", phase: "start" });
2444+
await dispatcherOptions.deliver(
2445+
{ mediaUrl: "https://example.com/validation.txt" },
2446+
{ kind: "tool" },
2447+
);
2448+
await dispatcherOptions.deliver({ text: "Final answer" }, { kind: "final" });
2449+
return { queuedFinal: true };
2450+
},
2451+
);
2452+
2453+
await dispatchWithContext({
2454+
context: createContext(),
2455+
streamMode: "progress",
2456+
telegramCfg: { streaming: { mode: "progress", progress: { label: "Shelling" } } },
2457+
});
2458+
2459+
expect(answerDraftStream.update).toHaveBeenCalledWith("Shelling\n\n`🛠️ Exec`");
2460+
expectDeliveredReply(0, { mediaUrl: "https://example.com/validation.txt" });
2461+
expectDeliveredReply(0, { text: "Final answer" }, 1);
2462+
expect(answerDraftStream.clear.mock.invocationCallOrder[0]).toBeLessThan(
2463+
deliverReplies.mock.invocationCallOrder[0],
2464+
);
2465+
});
2466+
24392467
it("does not stream text-only tool results into progress drafts", async () => {
24402468
const { answerDraftStream } = setupDraftStreams({ answerMessageId: 2001 });
24412469
dispatchReplyWithBufferedBlockDispatcher.mockImplementation(

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,9 @@ export const dispatchTelegramMessage = async ({
21362136
}
21372137
return;
21382138
}
2139+
if (streamMode === "progress" && info.kind === "tool") {
2140+
await rotateAnswerLaneAfterToolProgress();
2141+
}
21392142
const delivered = await sendPayload(effectivePayload, {
21402143
durable: info.kind === "final",
21412144
});

0 commit comments

Comments
 (0)