( content: NonNullable<ToolResultBlockParam['content']>, )
| 516 | } |
| 517 | |
| 518 | function contentSize( |
| 519 | content: NonNullable<ToolResultBlockParam['content']>, |
| 520 | ): number { |
| 521 | if (typeof content === 'string') return content.length |
| 522 | // Sum text-block lengths directly. Slightly under-counts vs serialized |
| 523 | // (no JSON framing), but the budget is a rough token heuristic anyway. |
| 524 | // Avoids allocating a content-sized string every enforcement pass. |
| 525 | return content.reduce( |
| 526 | (sum, b) => sum + (b.type === 'text' ? b.text.length : 0), |
| 527 | 0, |
| 528 | ) |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * Walk messages and build tool_use_id → tool_name from assistant tool_use |
no outgoing calls
no test coverage detected