(messages []map[string]any)
| 39 | } |
| 40 | |
| 41 | func 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 | |
| 69 | func projectExchange(exchange []map[string]any) *ProjectedExchange { |
| 70 | if len(exchange) == 0 { |
no outgoing calls
no test coverage detected