telegram streaming: finalize placeholder when response suppressed

This commit is contained in:
DBT
2026-02-26 12:55:53 +00:00
parent 818408962d
commit 4f5fb0e6cf
2 changed files with 15 additions and 1 deletions

View File

@@ -324,6 +324,9 @@ func (al *AgentLoop) processInbound(ctx context.Context, msg bus.InboundMessage)
suppressed = true
}
}
if msg.Channel == "telegram" && suppressed {
al.bus.PublishOutbound(bus.OutboundMessage{Channel: msg.Channel, ChatID: msg.ChatID, Action: "finalize"})
}
al.audit.Record(trigger, msg.Channel, msg.SessionKey, suppressed, err)
}

View File

@@ -48,7 +48,7 @@ type TelegramChannel struct {
func (c *TelegramChannel) SupportsAction(action string) bool {
switch strings.ToLower(strings.TrimSpace(action)) {
case "", "send", "stream", "edit", "delete", "react":
case "", "send", "stream", "finalize", "edit", "delete", "react":
return true
default:
return false
@@ -268,6 +268,17 @@ func (c *TelegramChannel) Send(ctx context.Context, msg bus.OutboundMessage) err
safeCloseSignal(stop)
}
}
if action == "finalize" {
if stop, ok := c.stopThinking.LoadAndDelete(msg.ChatID); ok {
safeCloseSignal(stop)
}
if pID, ok := c.placeholders.LoadAndDelete(msg.ChatID); ok {
delCtx, cancel := withTelegramAPITimeout(ctx)
_ = c.bot.DeleteMessage(delCtx, &telego.DeleteMessageParams{ChatID: chatID, MessageID: pID.(int)})
cancel()
}
return nil
}
if action != "send" && action != "stream" {
return c.handleAction(ctx, chatIDInt, action, msg)
}