From ebf238a568b40e62c06a541f7156e87335045b51 Mon Sep 17 00:00:00 2001 From: MoeMagicMango Date: Wed, 18 Mar 2026 15:19:50 +0800 Subject: [PATCH] fix(text): fix resolve emoji shown in telegram stream mode (#261) * fix(text): resolve emoji shown in telegram stream mode * chore(text): removing "reasoing" types in plain msg. * feat(conversation): add function to check for tool call content in assistant outputs --- internal/channel/adapters/telegram/stream.go | 7 ++++--- .../conversation/flow/assistant_output.go | 20 +++++++++++++++++++ internal/conversation/types.go | 4 ++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/internal/channel/adapters/telegram/stream.go b/internal/channel/adapters/telegram/stream.go index d278fdff..19d3674b 100644 --- a/internal/channel/adapters/telegram/stream.go +++ b/internal/channel/adapters/telegram/stream.go @@ -401,10 +401,11 @@ func (s *telegramOutboundStream) pushFinal(ctx context.Context, event channel.St msg := event.Final.Message finalText := bufText - if finalText == "" && !s.isPrivateChat { - finalText = strings.TrimSpace(msg.PlainText()) + if authoritative := strings.TrimSpace(msg.PlainText()); authoritative != "" { + if !s.isPrivateChat || bufText != "" { + finalText = authoritative + } } - // Convert markdown to Telegram HTML for the final message. formatted, pm := formatTelegramOutput(finalText, msg.Format) if pm != "" { diff --git a/internal/conversation/flow/assistant_output.go b/internal/conversation/flow/assistant_output.go index 2f011174..ed18ef18 100644 --- a/internal/conversation/flow/assistant_output.go +++ b/internal/conversation/flow/assistant_output.go @@ -16,6 +16,10 @@ func ExtractAssistantOutputs(messages []conversation.ModelMessage) []conversatio if msg.Role != "assistant" { continue } + // skip tool call tips content. + if hasToolCallContent(msg) { + continue + } content := strings.TrimSpace(msg.TextContent()) parts := filterContentParts(msg.ContentParts()) if content == "" && len(parts) == 0 { @@ -26,12 +30,28 @@ func ExtractAssistantOutputs(messages []conversation.ModelMessage) []conversatio return outputs } +func hasToolCallContent(msg conversation.ModelMessage) bool { + if len(msg.ToolCalls) > 0 { + return true + } + for _, p := range msg.ContentParts() { + if p.Type == "tool-call" { + return true + } + } + return false +} + func filterContentParts(parts []conversation.ContentPart) []conversation.ContentPart { if len(parts) == 0 { return nil } filtered := make([]conversation.ContentPart, 0, len(parts)) for _, p := range parts { + // Ignore Reasoning parts + if p.Type == "reasoning" { + continue + } if p.HasValue() { filtered = append(filtered, p) } diff --git a/internal/conversation/types.go b/internal/conversation/types.go index cf1cdf41..ce05005c 100644 --- a/internal/conversation/types.go +++ b/internal/conversation/types.go @@ -115,6 +115,10 @@ func (m ModelMessage) TextContent() string { if err := json.Unmarshal(m.Content, &parts); err == nil { texts := make([]string, 0, len(parts)) for _, p := range parts { + // Ignore Reasoning parts + if p.Type == "reasoning" { + continue + } if strings.TrimSpace(p.Text) != "" { texts = append(texts, p.Text) }