( message: AssistantMessage, )
| 181 | * Note: signature_delta is excluded from streaming counts (not model output). |
| 182 | */ |
| 183 | export function getAssistantMessageContentLength( |
| 184 | message: AssistantMessage, |
| 185 | ): number { |
| 186 | let contentLength = 0 |
| 187 | for (const block of message.message.content) { |
| 188 | if (block.type === 'text') { |
| 189 | contentLength += block.text.length |
| 190 | } else if (block.type === 'thinking') { |
| 191 | contentLength += block.thinking.length |
| 192 | } else if (block.type === 'redacted_thinking') { |
| 193 | contentLength += block.data.length |
| 194 | } else if (block.type === 'tool_use') { |
| 195 | contentLength += jsonStringify(block.input).length |
| 196 | } |
| 197 | } |
| 198 | return contentLength |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Get the current context window size in tokens. |
no test coverage detected