(
content:
| string
| Array<Anthropic.ContentBlock>
| Array<Anthropic.ContentBlockParam>
| undefined,
)
| 376 | } |
| 377 | |
| 378 | function roughTokenCountEstimationForContent( |
| 379 | content: |
| 380 | | string |
| 381 | | Array<Anthropic.ContentBlock> |
| 382 | | Array<Anthropic.ContentBlockParam> |
| 383 | | undefined, |
| 384 | ): number { |
| 385 | if (!content) { |
| 386 | return 0 |
| 387 | } |
| 388 | if (typeof content === 'string') { |
| 389 | return roughTokenCountEstimation(content) |
| 390 | } |
| 391 | let totalTokens = 0 |
| 392 | for (const block of content) { |
| 393 | totalTokens += roughTokenCountEstimationForBlock(block) |
| 394 | } |
| 395 | return totalTokens |
| 396 | } |
| 397 | |
| 398 | function roughTokenCountEstimationForBlock( |
| 399 | block: string | Anthropic.ContentBlock | Anthropic.ContentBlockParam, |
no test coverage detected