( content: NonNullable<ToolResultBlockParam['content']>, )
| 535 | } |
| 536 | |
| 537 | function contentSize( |
| 538 | content: NonNullable<ToolResultBlockParam['content']>, |
| 539 | ): number { |
| 540 | if (typeof content === 'string') return content.length |
| 541 | // Sum text-block lengths directly. Slightly under-counts vs serialized |
| 542 | // (no JSON framing), but the budget is a rough token heuristic anyway. |
| 543 | // Avoids allocating a content-sized string every enforcement pass. |
| 544 | return content.reduce( |
| 545 | (sum, b) => sum + (b.type === 'text' ? b.text.length : 0), |
| 546 | 0, |
| 547 | ) |
| 548 | } |
| 549 | |
| 550 | /** |
| 551 | * Walk messages and build tool_use_id → tool_name from assistant tool_use |
no outgoing calls
no test coverage detected