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

Function partitionExchanges

agentContext/collapse.go:41–67  ·  view source on GitHub ↗
(messages []map[string]any)

Source from the content-addressed store, hash-verified

39}
40
41func partitionExchanges(messages []map[string]any) [][]map[string]any {
42 if len(messages) == 0 {
43 return [][]map[string]any{}
44 }
45 var exchanges [][]map[string]any
46 current := []map[string]any{messages[0]}
47 lastRole, ok := messages[0]["role"].(string)
48 if !ok {
49 lastRole = ""
50 }
51 for _, msg := range messages[1:] {
52 role, ok := msg["role"].(string)
53 if !ok {
54 role = ""
55 }
56 if role != lastRole && current != nil {
57 exchanges = append(exchanges, current)
58 current = []map[string]any{msg}
59 } else {
60 current = append(current, msg)
61 }
62 }
63 if current != nil && len(current) > 0 {
64 exchanges = append(exchanges, current)
65 }
66 return exchanges
67}
68
69func projectExchange(exchange []map[string]any) *ProjectedExchange {
70 if len(exchange) == 0 {

Callers 2

CollapseMessagesFunction · 0.85
ApplyCollapseIfNeedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected