MCPcopy Create free account
hub / github.com/GongShichen/LuminaCode / MergeSplitMessages

Function MergeSplitMessages

agent/normalize.go:151–182  ·  view source on GitHub ↗
(messages []map[string]any)

Source from the content-addressed store, hash-verified

149}
150
151func MergeSplitMessages(messages []map[string]any) []map[string]any {
152 if len(messages) == 0 {
153 return messages
154 }
155 out := make([]map[string]any, 0, len(messages))
156 i := 0
157 for i < len(messages) {
158 msg := messages[i]
159 role := stringFromAny(msg["role"])
160 msgID := stringFromAny(msg["id"])
161 if role != "assistant" || msgID == "" {
162 out = append(out, msg)
163 i++
164 continue
165 }
166 merged := append([]map[string]any{}, contentBlocks(msg["content"])...)
167 j := i + 1
168 for j < len(messages) {
169 next := messages[j]
170 if stringFromAny(next["role"]) != "assistant" || stringFromAny(next["id"]) != msgID {
171 break
172 }
173 merged = append(merged, contentBlocks(next["content"])...)
174 j++
175 }
176 cp := copyMap(msg)
177 cp["content"] = merged
178 out = append(out, cp)
179 i = j
180 }
181 return out
182}
183
184func FixToolPairings(messages []map[string]any) []map[string]any {
185 uses := map[string]struct{}{}

Callers 1

NormalizeMessagesFunction · 0.85

Calls 3

stringFromAnyFunction · 0.70
contentBlocksFunction · 0.70
copyMapFunction · 0.70

Tested by

no test coverage detected