| 231 | ) |
| 232 | |
| 233 | const keep = (b: { |
| 234 | type: string |
| 235 | id?: string |
| 236 | tool_use_id?: string |
| 237 | text?: string |
| 238 | }) => |
| 239 | b.type !== 'thinking' && |
| 240 | b.type !== 'redacted_thinking' && |
| 241 | !(b.type === 'tool_use' && !toolIdsWithSuccessfulResults.has(b.id!)) && |
| 242 | !( |
| 243 | b.type === 'tool_result' && |
| 244 | !toolIdsWithSuccessfulResults.has(b.tool_use_id!) |
| 245 | ) && |
| 246 | // Abort during speculation yields a standalone interrupt user message |
| 247 | // (query.ts createUserInterruptionMessage). Strip it so it isn't surfaced |
| 248 | // to the model as real user input. |
| 249 | !( |
| 250 | b.type === 'text' && |
| 251 | (b.text === INTERRUPT_MESSAGE || |
| 252 | b.text === INTERRUPT_MESSAGE_FOR_TOOL_USE) |
| 253 | ) |
| 254 | |
| 255 | return messages |
| 256 | .map(msg => { |