fix: keep typing indicator alive during entire response (not just until first token)
The old logic stopped typing on first stream token, leaving tool execution gaps (30s+) with zero visual feedback. Now typing persists until the full response + streaming edits are complete.
This commit is contained in:
@@ -1087,13 +1087,10 @@ export async function initBot(config, api, tools, skills, agents) {
|
||||
logger.info(`${prefix} ${user}: ${text.substring(0, 80)}…`);
|
||||
|
||||
await queueRequest(key, text, async () => {
|
||||
// ── Typing indicator: keep pinging until first stream token arrives ──
|
||||
let firstTokenArrived = false;
|
||||
// ── Typing indicator: keep pinging until response is fully complete ──
|
||||
const typingInterval = setInterval(async () => {
|
||||
if (firstTokenArrived) return;
|
||||
try {
|
||||
await ctx.api.sendChatAction(ctx.chat.id, 'typing');
|
||||
logger.debug('⌨️ typing ping');
|
||||
} catch (e) { logger.warn(`⌨️ typing error: ${e.message}`); }
|
||||
}, 4000); // Telegram typing expires after 5s, refresh every 4s
|
||||
try {
|
||||
@@ -1121,7 +1118,6 @@ export async function initBot(config, api, tools, skills, agents) {
|
||||
// Wrap chatWithAI with self-correction + streaming
|
||||
const chatWithCorrection = withSelfCorrection(async (msgs) => {
|
||||
return await chatWithAI(msgs, { onDelta: (token) => {
|
||||
if (!firstTokenArrived) firstTokenArrived = true;
|
||||
consumer.onDelta(token);
|
||||
}});
|
||||
});
|
||||
@@ -1133,7 +1129,6 @@ export async function initBot(config, api, tools, skills, agents) {
|
||||
if (result) await conversation.add(chatKey, 'assistant', result);
|
||||
|
||||
// Stop typing indicator
|
||||
firstTokenArrived = true;
|
||||
clearInterval(typingInterval);
|
||||
logger.info('⌨️ typing stopped (response complete)');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user