MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / countTokensJson

Function countTokensJson

src/utils/tokenizer.ts:109–113  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

107
108/** Count tokens for an arbitrary JSON-serializable value (tool args, etc.). */
109export function countTokensJson(value: unknown): number {
110 if (value == null) return 0;
111 if (typeof value === 'string') return countTokens(value);
112 try { return countTokens(JSON.stringify(value)); } catch { return 0; }
113}
114
115/**
116 * Pre-load the real tokenizer. Call once during startup (non-blocking — await

Callers 3

estimateTokensFunction · 0.85
estimateTokensJsonFunction · 0.85

Calls 1

countTokensFunction · 0.85

Tested by

no test coverage detected