* Check if messages contain thinking blocks
( messages: Anthropic.Beta.Messages.BetaMessageParam[], )
| 43 | * Check if messages contain thinking blocks |
| 44 | */ |
| 45 | function hasThinkingBlocks( |
| 46 | messages: Anthropic.Beta.Messages.BetaMessageParam[], |
| 47 | ): boolean { |
| 48 | for (const message of messages) { |
| 49 | if (message.role === 'assistant' && Array.isArray(message.content)) { |
| 50 | for (const block of message.content) { |
| 51 | if ( |
| 52 | typeof block === 'object' && |
| 53 | block !== null && |
| 54 | 'type' in block && |
| 55 | (block.type === 'thinking' || block.type === 'redacted_thinking') |
| 56 | ) { |
| 57 | return true |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | return false |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Strip tool search-specific fields from messages before sending for token counting. |
no outgoing calls
no test coverage detected