MCPcopy Index your code
hub / github.com/continuedev/continue / countParameterFieldTokens

Function countParameterFieldTokens

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

* Count tokens for a single parameter field in a tool definition. * @param fields The field definition object * @returns Token count for this field

(
  fields: Record<string, unknown> | undefined,
)

Source from the content-addressed store, hash-verified

210 * @returns Token count for this field
211 */
212function countParameterFieldTokens(
213 fields: Record<string, unknown> | undefined,
214): number {
215 if (!fields) {
216 return 0;
217 }
218
219 let tokens = 0;
220 const fieldType = fields["type"];
221 const fieldDesc = fields["description"];
222 const fieldEnum = fields["enum"];
223
224 if (fieldType && typeof fieldType === "string") {
225 tokens += 2; // Structure overhead for type
226 tokens += encode(fieldType).length;
227 }
228
229 if (fieldDesc && typeof fieldDesc === "string") {
230 tokens += 2; // Structure overhead for description
231 tokens += encode(fieldDesc).length;
232 }
233
234 if (fieldEnum && Array.isArray(fieldEnum) && fieldEnum.length > 0) {
235 tokens -= 3;
236 for (const e of fieldEnum) {
237 tokens += 3;
238 tokens += typeof e === "string" ? encode(e).length : 5;
239 }
240 }
241
242 return tokens;
243}
244
245/**
246 * Count tokens for a single tool's function definition.

Callers 1

countSingleToolTokensFunction · 0.85

Calls 1

encodeFunction · 0.50

Tested by

no test coverage detected