* Count tokens in tool call outputs
(
output: Array<{ content?: string; name?: string }> | undefined,
)
| 81 | * Count tokens in tool call outputs |
| 82 | */ |
| 83 | function countToolOutputTokens( |
| 84 | output: Array<{ content?: string; name?: string }> | undefined, |
| 85 | ): number { |
| 86 | if (!output) { |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | let tokenCount = 0; |
| 91 | for (const item of output) { |
| 92 | if (item.content) { |
| 93 | tokenCount += encode(item.content).length; |
| 94 | } |
| 95 | // Note: item.name is not sent to the model, only used for internal tracking |
| 96 | tokenCount += 5; // Output structure overhead |
| 97 | } |
| 98 | return tokenCount; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Estimate the token count for a single ChatHistoryItem |
no test coverage detected