(messages []map[string]any, modelFamily string, recentErrors []string)
| 121 | } |
| 122 | |
| 123 | func HandleThinkingBlocks(messages []map[string]any, modelFamily string, recentErrors []string) []map[string]any { |
| 124 | supports := modelSupportsThinking(modelFamily) |
| 125 | out := make([]map[string]any, 0, len(messages)) |
| 126 | for _, msg := range messages { |
| 127 | blocks := contentBlocks(msg["content"]) |
| 128 | if blocks == nil { |
| 129 | out = append(out, msg) |
| 130 | continue |
| 131 | } |
| 132 | role := stringFromAny(msg["role"]) |
| 133 | stripThinking := role == "user" || !supports |
| 134 | filtered := make([]map[string]any, 0, len(blocks)) |
| 135 | for _, block := range blocks { |
| 136 | if _, ok := thinkingBlockTypes[stringFromAny(block["type"])]; ok && stripThinking { |
| 137 | continue |
| 138 | } |
| 139 | filtered = append(filtered, block) |
| 140 | } |
| 141 | if len(filtered) == 0 { |
| 142 | continue |
| 143 | } |
| 144 | cp := copyMap(msg) |
| 145 | cp["content"] = filtered |
| 146 | out = append(out, cp) |
| 147 | } |
| 148 | return out |
| 149 | } |
| 150 | |
| 151 | func MergeSplitMessages(messages []map[string]any) []map[string]any { |
| 152 | if len(messages) == 0 { |
no test coverage detected