fix: bypass StreamConsumer — use direct sendFormatted for reliable delivery
This commit is contained in:
@@ -676,13 +676,9 @@ export async function initBot(config, api, tools, skills, agents) {
|
|||||||
await queueRequest(key, text, async () => {
|
await queueRequest(key, text, async () => {
|
||||||
await ctx.api.sendChatAction(ctx.chat.id, 'typing');
|
await ctx.api.sendChatAction(ctx.chat.id, 'typing');
|
||||||
|
|
||||||
// Create stream consumer for real-time edit-in-place
|
// Use self-correction + direct send (streaming disabled for reliability)
|
||||||
const consumer = new StreamConsumer(ctx, { editInterval: 1000 });
|
|
||||||
const runPromise = consumer.run();
|
|
||||||
|
|
||||||
// Wrap chatWithAI with self-correction + streaming
|
|
||||||
const chatWithCorrection = withSelfCorrection(async (msgs) => {
|
const chatWithCorrection = withSelfCorrection(async (msgs) => {
|
||||||
return await chatWithAI(msgs, { onDelta: (token) => consumer.onDelta(token) });
|
return await chatWithAI(msgs);
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await chatWithCorrection([
|
const result = await chatWithCorrection([
|
||||||
@@ -690,13 +686,13 @@ export async function initBot(config, api, tools, skills, agents) {
|
|||||||
{ role: 'user', content: text },
|
{ role: 'user', content: text },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Signal completion and wait for final edit
|
// Send formatted response
|
||||||
consumer.finish();
|
if (result) {
|
||||||
await runPromise;
|
logger.info(`📤 Sending response (${result.length} chars)`);
|
||||||
|
|
||||||
// If streaming failed to deliver (no message sent), fallback to plain send
|
|
||||||
if (!consumer.alreadySent && result) {
|
|
||||||
await sendFormatted(ctx, result);
|
await sendFormatted(ctx, result);
|
||||||
|
logger.info('✅ Response delivered');
|
||||||
|
} else {
|
||||||
|
logger.warn('Empty response from AI — nothing to send');
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Self-learning: extract patterns from this interaction ──
|
// ── Self-learning: extract patterns from this interaction ──
|
||||||
|
|||||||
Reference in New Issue
Block a user