(messages []map[string]any, errorBlockMap map[string][]string)
| 86 | } |
| 87 | |
| 88 | func StripInternalElementsWithErrors(messages []map[string]any, errorBlockMap map[string][]string) []map[string]any { |
| 89 | stripTypes := map[string]struct{}{} |
| 90 | for _, blockTypes := range errorBlockMap { |
| 91 | for _, blockType := range blockTypes { |
| 92 | stripTypes[blockType] = struct{}{} |
| 93 | } |
| 94 | } |
| 95 | out := make([]map[string]any, 0, len(messages)) |
| 96 | for _, msg := range messages { |
| 97 | blocks := contentBlocks(msg["content"]) |
| 98 | if blocks == nil { |
| 99 | out = append(out, msg) |
| 100 | continue |
| 101 | } |
| 102 | filtered := make([]map[string]any, 0, len(blocks)) |
| 103 | for _, block := range blocks { |
| 104 | blockType := stringFromAny(block["type"]) |
| 105 | if _, ok := internalBlockTypes[blockType]; ok { |
| 106 | continue |
| 107 | } |
| 108 | if _, ok := stripTypes[blockType]; ok { |
| 109 | continue |
| 110 | } |
| 111 | filtered = append(filtered, block) |
| 112 | } |
| 113 | if len(filtered) == 0 { |
| 114 | continue |
| 115 | } |
| 116 | cp := copyMap(msg) |
| 117 | cp["content"] = filtered |
| 118 | out = append(out, cp) |
| 119 | } |
| 120 | return out |
| 121 | } |
| 122 | |
| 123 | func HandleThinkingBlocks(messages []map[string]any, modelFamily string, recentErrors []string) []map[string]any { |
| 124 | supports := modelSupportsThinking(modelFamily) |
no test coverage detected