MCPcopy Create free account
hub / github.com/WJX20/claude-code / roughTokenCountEstimationForContent

Function roughTokenCountEstimationForContent

src/services/tokenEstimation.ts:371–389  ·  view source on GitHub ↗
(
  content:
    | string
    | Array<Anthropic.ContentBlock>
    | Array<Anthropic.ContentBlockParam>
    | undefined,
)

Source from the content-addressed store, hash-verified

369}
370
371function roughTokenCountEstimationForContent(
372 content:
373 | string
374 | Array<Anthropic.ContentBlock>
375 | Array<Anthropic.ContentBlockParam>
376 | undefined,
377): number {
378 if (!content) {
379 return 0
380 }
381 if (typeof content === 'string') {
382 return roughTokenCountEstimation(content)
383 }
384 let totalTokens = 0
385 for (const block of content) {
386 totalTokens += roughTokenCountEstimationForBlock(block)
387 }
388 return totalTokens
389}
390
391function roughTokenCountEstimationForBlock(
392 block: string | Anthropic.ContentBlock | Anthropic.ContentBlockParam,

Calls 2

Tested by

no test coverage detected