mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-17 13:13:35 +08:00
fix(adapters): ensure placeholder cleanup on message_complete
When all buffered text has already been flushed via periodic timer, buf.complete() calls flush(true) which returns early on empty buffer, skipping the onFlush callback that cleans up placeholder state. This causes subsequent messages to keep editing the old completed message instead of creating a new one. Add explicit placeholder cleanup in message_complete handler as a safety net, matching the same pattern used for tool_use finalization. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
824b1967ff
commit
b4ad6f15de
@ -333,6 +333,16 @@ async function handleServerMessage(chatId: string, msg: ServerMessage): Promise<
|
||||
|
||||
case 'message_complete':
|
||||
await buf.complete()
|
||||
// Ensure state is always cleaned up even if buffer was already empty
|
||||
if (state.replyMessageId) {
|
||||
const text = accumulatedText.get(chatId)
|
||||
if (text?.trim()) {
|
||||
await patchMessage(state.replyMessageId, text)
|
||||
}
|
||||
accumulatedText.delete(chatId)
|
||||
chatStates.delete(chatId)
|
||||
buffers.get(chatId)?.reset()
|
||||
}
|
||||
break
|
||||
|
||||
case 'error':
|
||||
|
||||
@ -236,6 +236,22 @@ async function handleServerMessage(chatId: string, msg: ServerMessage): Promise<
|
||||
|
||||
case 'message_complete':
|
||||
await buf.complete()
|
||||
// Ensure placeholder is always cleaned up even if buffer was already empty
|
||||
if (placeholders.has(chatId)) {
|
||||
const text = accumulatedText.get(chatId)
|
||||
if (text?.trim()) {
|
||||
try {
|
||||
const chunks = splitMessage(text, TELEGRAM_TEXT_LIMIT)
|
||||
await bot.api.editMessageText(numericChatId, placeholders.get(chatId)!.messageId, chunks[0]!)
|
||||
for (let i = 1; i < chunks.length; i++) {
|
||||
await bot.api.sendMessage(numericChatId, chunks[i]!)
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
placeholders.delete(chatId)
|
||||
accumulatedText.delete(chatId)
|
||||
buffers.get(chatId)?.reset()
|
||||
}
|
||||
break
|
||||
|
||||
case 'error':
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user