* Implements the ApiHandler countTokens interface method * Provides token counting for Anthropic content blocks * * @param content The content blocks to count tokens for * @returns A promise resolving to the token count
(content: Array<Anthropic.Messages.ContentBlockParam>)
| 204 | * @returns A promise resolving to the token count |
| 205 | */ |
| 206 | override async countTokens(content: Array<Anthropic.Messages.ContentBlockParam>): Promise<number> { |
| 207 | // Convert Anthropic content blocks to a string for VSCode LM token counting |
| 208 | let textContent = "" |
| 209 | |
| 210 | for (const block of content) { |
| 211 | if (block.type === "text") { |
| 212 | textContent += block.text || "" |
| 213 | } else if (block.type === "image") { |
| 214 | // VSCode LM doesn't support images directly, so we'll just use a placeholder |
| 215 | textContent += "[IMAGE]" |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | return this.internalCountTokens(textContent) |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Private implementation of token counting used internally by VsCodeLmHandler |
nothing calls this directly
no test coverage detected