MCPcopy Create free account
hub / github.com/continuedev/continue / countToolOutputTokens

Function countToolOutputTokens

extensions/cli/src/util/tokenizer.ts:83–99  ·  view source on GitHub ↗

* Count tokens in tool call outputs

(
  output: Array<{ content?: string; name?: string }> | undefined,
)

Source from the content-addressed store, hash-verified

81 * Count tokens in tool call outputs
82 */
83function 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

Callers 1

Calls 1

encodeFunction · 0.50

Tested by

no test coverage detected