(value: unknown)
| 107 | |
| 108 | /** Count tokens for an arbitrary JSON-serializable value (tool args, etc.). */ |
| 109 | export 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 |
no test coverage detected