( content: string | Anthropic.Messages.ContentBlockParam[], )
| 69 | * @returns The transformed content with tool blocks converted to text blocks |
| 70 | */ |
| 71 | export function convertToolBlocksToText( |
| 72 | content: string | Anthropic.Messages.ContentBlockParam[], |
| 73 | ): string | Anthropic.Messages.ContentBlockParam[] { |
| 74 | if (typeof content === "string") { |
| 75 | return content |
| 76 | } |
| 77 | |
| 78 | return content.map((block) => { |
| 79 | if (block.type === "tool_use") { |
| 80 | return { |
| 81 | type: "text" as const, |
| 82 | text: toolUseToText(block), |
| 83 | } |
| 84 | } |
| 85 | if (block.type === "tool_result") { |
| 86 | return { |
| 87 | type: "text" as const, |
| 88 | text: toolResultToText(block), |
| 89 | } |
| 90 | } |
| 91 | return block |
| 92 | }) |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Transforms all messages by converting tool_use and tool_result blocks to text representations. |
no test coverage detected