/** * Token Estimator * * Provides a heuristic for estimating token counts without requiring a heavy tokenizer * dependency. Varies the byte-to-token ratio based on the content type to improve * accuracy for structured data and code. * * Ratios (empirically derived against tiktoken for GPT-4): * - Prose: ~4.0 bytes/token (standard English) * - JSON: ~2.8 bytes/token (high density of structural characters) * - Code: ~3.2 bytes/token (mixed density) * * Usage: * estimateTokens(str, contentType?) → number * estimatePayloadTokens(payload) → number (always 'json') * injectTokenEstimate(payload) → payload with _meta.tokenEstimate added */ export type ContentType = 'prose' | 'json' | 'code'; /** * Detect the content type of a string to apply the most accurate token heuristic. */ export declare function detectContentType(text: string): ContentType; /** * Estimate the number of tokens in a string using a content-type-aware heuristic. * If contentType is not provided, it is auto-detected. */ export declare function estimateTokens(text: string, contentType?: ContentType): number; /** * Estimate tokens for an arbitrary serializable value by serializing it * to JSON first. Uses the 'json' content type heuristic. */ export declare function estimatePayloadTokens(payload: unknown): number; /** * Inject a `_meta.tokenEstimate` field into a tool response payload. * Operates on a shallow copy — never mutates the original object. * * If the payload is not a plain object, returns it unchanged. * If `_meta` already exists, merges `tokenEstimate` into it. * * @param payload - Tool handler response (any shape) * @returns Payload with `_meta.tokenEstimate` added */ export declare function injectTokenEstimate(payload: unknown): unknown; //# sourceMappingURL=token-estimator.d.ts.map