MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / countTokens

Method countTokens

src/api/providers/vscode-lm.ts:206–220  ·  view source on GitHub ↗

* 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>)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

internalCountTokensMethod · 0.95

Tested by

no test coverage detected