mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
979ff00cc3
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package messageutil
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/sipeed/picoclaw/pkg/providers/protocoltypes"
|
|
)
|
|
|
|
// IsTransientAssistantThoughtMessage reports whether msg is an invalid
|
|
// reasoning-only assistant history record. These "hanging" thought messages
|
|
// are not a canonical persisted format and should be discarded instead of
|
|
// replayed or reconstructed.
|
|
func IsTransientAssistantThoughtMessage(msg protocoltypes.Message) bool {
|
|
return msg.Role == "assistant" &&
|
|
strings.TrimSpace(msg.Content) == "" &&
|
|
strings.TrimSpace(msg.ReasoningContent) != "" &&
|
|
len(msg.ToolCalls) == 0 &&
|
|
len(msg.Media) == 0 &&
|
|
len(msg.Attachments) == 0 &&
|
|
strings.TrimSpace(msg.ToolCallID) == ""
|
|
}
|
|
|
|
// FilterInvalidHistoryMessages removes invalid persisted history records such
|
|
// as transient assistant thought-only messages.
|
|
func FilterInvalidHistoryMessages(history []protocoltypes.Message) []protocoltypes.Message {
|
|
if len(history) == 0 {
|
|
return []protocoltypes.Message{}
|
|
}
|
|
|
|
filtered := make([]protocoltypes.Message, 0, len(history))
|
|
for _, msg := range history {
|
|
if IsTransientAssistantThoughtMessage(msg) {
|
|
continue
|
|
}
|
|
filtered = append(filtered, msg)
|
|
}
|
|
return filtered
|
|
}
|