/** * useTokenCount Hook * * React hook for estimating token counts. * * @module */ /** * Token count options. */ export interface UseTokenCountOptions { /** Text to count tokens for */ text?: string; /** Model to use for estimation */ model?: string; /** Custom tokenizer function */ tokenizer?: (text: string) => number; /** Debounce delay in ms */ debounceMs?: number; } /** * Token count return value. */ export interface UseTokenCountReturn { /** Estimated token count */ tokenCount: number; /** Characters count */ characterCount: number; /** Word count */ wordCount: number; /** Whether estimation is in progress */ isEstimating: boolean; /** Count tokens for text */ countTokens: (text: string) => number; } /** * useTokenCount - React hook for estimating token counts. * * Provides real-time token estimation for text input, * useful for staying within model context limits. * * @example * ```tsx * import { useTokenCount } from 'ai.matey.react.hooks'; * * function TokenCounter() { * const [text, setText] = useState(''); * const { tokenCount, characterCount, wordCount } = useTokenCount({ text }); * * return ( *