812bd189596cb287f9eb456ab2858585fd9c7dc2

Author
TheEdgeOfRage <git@theedgeofrage.com>
Committer
TheEdgeOfRage <git@theedgeofrage.com>
Date

Message

Only send final message when it's different from intermediate ones

Diff

 1diff --git a/src/telegram.ts b/src/telegram.ts
 2index bfb3266c7b1e0d55dc01cca36c0bcaeea91f4133..e96a807edd7eac71fe35b8491aca2b36599bda45 100644
 3--- a/src/telegram.ts
 4+++ b/src/telegram.ts
 5@@ -379,9 +379,21 @@ export function createBot(token: string, allowedUsers: number[]): Bot {
 6       sendPrompt(sessionId, userText, activeAgent)
 7         .then(async (parts) => {
 8           cleanup();
 9-          // Send final text as separate new message(s)
10+          // Final edit of the thinking message with full content (tools + text)
11+          const fullContent = formatParts(parts);
12+          if (fullContent) {
13+            const editText =
14+              fullContent.length > 4000
15+                ? fullContent.slice(0, 4000) + escapeMarkdownV2("...")
16+                : fullContent;
17+            const editToSend =
18+              channelChatId !== null ? formatAsQuote(editText) : editText;
19+            await editMessage(ctx, responseMsgId, editToSend);
20+          }
21+          // Send final summary (text-only) as new message, but only if it
22+          // differs from what's already in the edited message
23           const textContent = formatTextParts(parts);
24-          if (textContent) {
25+          if (textContent && textContent !== fullContent) {
26             const chunks = splitMessage(textContent);
27             log.info(
28               `[prompt] done session=${sessionId} chunks=${chunks.length}`,