* In thecontent[] list on a UserMessage, tool_result blocks much come first * to avoid "tool result must follow tool use" API errors.
(content: ContentBlockParam[])
| 2468 | * to avoid "tool result must follow tool use" API errors. |
| 2469 | */ |
| 2470 | function hoistToolResults(content: ContentBlockParam[]): ContentBlockParam[] { |
| 2471 | const toolResults: ContentBlockParam[] = [] |
| 2472 | const otherBlocks: ContentBlockParam[] = [] |
| 2473 | |
| 2474 | for (const block of content) { |
| 2475 | if (block.type === 'tool_result') { |
| 2476 | toolResults.push(block) |
| 2477 | } else { |
| 2478 | otherBlocks.push(block) |
| 2479 | } |
| 2480 | } |
| 2481 | |
| 2482 | return [...toolResults, ...otherBlocks] |
| 2483 | } |
| 2484 | |
| 2485 | function normalizeUserTextContent( |
| 2486 | a: string | ContentBlockParam[], |
no test coverage detected