fix(channel): strip agent tags from content parts in outbound messages

StripAgentTags was only applied to the merged content string but not to
individual ContentParts. On channels that don't support RichText (e.g.
Telegram), buildChannelMessage joins part texts directly, causing raw
<attachments>/<reactions>/<speech> blocks to appear in the final message.
This commit is contained in:
Acbox
2026-04-04 17:17:35 +08:00
parent 24a1d515ea
commit a5f59ea6a5
@@ -30,6 +30,7 @@ func ExtractAssistantOutputs(messages []conversation.ModelMessage) []conversatio
continue
}
content = agent.StripAgentTags(content)
parts = stripAgentTagsFromParts(parts)
outputs = append(outputs, conversation.AssistantOutput{Content: content, Parts: parts})
}
return outputs
@@ -87,6 +88,22 @@ func visibleContentText(parts []conversation.ContentPart) string {
return strings.TrimSpace(strings.Join(texts, "\n"))
}
func stripAgentTagsFromParts(parts []conversation.ContentPart) []conversation.ContentPart {
if len(parts) == 0 {
return nil
}
result := make([]conversation.ContentPart, 0, len(parts))
for _, p := range parts {
if strings.TrimSpace(p.Text) != "" {
p.Text = agent.StripAgentTags(p.Text)
}
if p.HasValue() {
result = append(result, p)
}
}
return result
}
func visibleContentPartText(part conversation.ContentPart) string {
if strings.TrimSpace(part.Text) != "" {
return part.Text