fix: harden telegram streaming state
This commit is contained in:
@@ -302,4 +302,5 @@ export function handleMessageEnd(
|
||||
ctx.state.blockState.final = false;
|
||||
ctx.state.blockState.inlineCode = createInlineCodeState();
|
||||
ctx.state.lastStreamedAssistant = undefined;
|
||||
ctx.state.lastStreamedAssistantCleaned = undefined;
|
||||
}
|
||||
|
||||
@@ -70,11 +70,12 @@ export const dispatchTelegramMessage = async ({
|
||||
|
||||
const isPrivateChat = msg.chat.type === "private";
|
||||
const messageThreadId = (msg as { message_thread_id?: number }).message_thread_id;
|
||||
const draftThreadId = replyThreadId ?? messageThreadId;
|
||||
const draftMaxChars = Math.min(textLimit, 4096);
|
||||
const canStreamDraft =
|
||||
streamMode !== "off" &&
|
||||
isPrivateChat &&
|
||||
typeof messageThreadId === "number" &&
|
||||
typeof draftThreadId === "number" &&
|
||||
(await resolveBotTopicsEnabled(primaryCtx));
|
||||
const draftStream = canStreamDraft
|
||||
? createTelegramDraftStream({
|
||||
@@ -82,7 +83,7 @@ export const dispatchTelegramMessage = async ({
|
||||
chatId,
|
||||
draftId: msg.message_id || Date.now(),
|
||||
maxChars: draftMaxChars,
|
||||
messageThreadId: replyThreadId,
|
||||
messageThreadId: draftThreadId,
|
||||
log: logVerbose,
|
||||
warn: logVerbose,
|
||||
})
|
||||
|
||||
@@ -74,13 +74,17 @@ export function createTelegramDraftStream(params: {
|
||||
return;
|
||||
}
|
||||
const text = pendingText;
|
||||
const trimmed = text.trim();
|
||||
if (!trimmed) {
|
||||
if (pendingText === text) {
|
||||
pendingText = "";
|
||||
if (!text.trim()) {
|
||||
}
|
||||
if (pendingText) {
|
||||
schedule();
|
||||
}
|
||||
return;
|
||||
}
|
||||
pendingText = "";
|
||||
inFlight = true;
|
||||
try {
|
||||
await sendDraft(text);
|
||||
|
||||
Reference in New Issue
Block a user