mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
5a35ef34ac
- Refactor channel manager with support for Sender/Receiver interfaces and hot-swappable adapters. - Implement identity routing and pre-authentication logic for inbound messages. - Update database schema to support bot pre-auth keys and extended channel session metadata. - Add Telegram and Feishu channel configuration and adapter enhancements. - Update Swagger documentation and internal handlers for channel management. Co-authored-by: Cursor <cursoragent@cursor.com>
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package chat
|
|
|
|
import "strings"
|
|
|
|
type AssistantOutput struct {
|
|
Content string
|
|
Parts []ContentPart
|
|
}
|
|
|
|
func ExtractAssistantOutputs(messages []GatewayMessage) []AssistantOutput {
|
|
if len(messages) == 0 {
|
|
return nil
|
|
}
|
|
outputs := make([]AssistantOutput, 0, len(messages))
|
|
for _, msg := range messages {
|
|
normalized := normalizeGatewayMessage(msg)
|
|
for _, item := range normalized {
|
|
if item.Role != "assistant" {
|
|
continue
|
|
}
|
|
content := strings.TrimSpace(item.Content)
|
|
parts := make([]ContentPart, 0, len(item.Parts))
|
|
for _, part := range item.Parts {
|
|
if !hasContentPartValue(part) {
|
|
continue
|
|
}
|
|
parts = append(parts, part)
|
|
}
|
|
if content == "" && len(parts) == 0 {
|
|
continue
|
|
}
|
|
outputs = append(outputs, AssistantOutput{
|
|
Content: content,
|
|
Parts: parts,
|
|
})
|
|
}
|
|
}
|
|
return outputs
|
|
}
|
|
|
|
func hasContentPartValue(part ContentPart) bool {
|
|
if strings.TrimSpace(part.Text) != "" {
|
|
return true
|
|
}
|
|
if strings.TrimSpace(part.URL) != "" {
|
|
return true
|
|
}
|
|
if strings.TrimSpace(part.Emoji) != "" {
|
|
return true
|
|
}
|
|
return false
|
|
}
|