/** * Estimate the number of tokens in `text` for the given model. * Heuristic only — for exact counts, use the provider's tokenizer. * * @example * ```ts * if (estimateTokens(prompt, 'gpt-4o') > 100_000) { * throw new Error('prompt too long; consider chunking') * } * ``` */ export declare function estimateTokens(text: string, model?: string): number; /** * Estimate total tokens for a chat-completion request: sum of * every message's content plus a fixed per-message overhead * (matches the rough "+4 per message + 2 for the conversation" * heuristic OpenAI's docs publish). */ export declare function estimateMessageTokens(messages: Array<{ role: string, content: string | unknown }>, model?: string): number; /** * Inspect `text` for common prompt-injection patterns. Returns * `{ ok, matched, cleaned }`. Apps decide what to do with the * result — reject the request (`if (!result.ok) throw...`), pass * the cleaned text on (`useText(result.cleaned)`), or just log * for audit while letting the original through. * * **Limits:** this is heuristic. Adversarial inputs can paraphrase * around any specific pattern. Use as a cheap first filter; for * real defense, isolate the user input from the system prompt * structurally (different roles, JSON-mode for the system layer) * and guard the output side too. * * @example * ```ts * const check = sanitizePrompt(userInput) * if (!check.ok) { * log.warn('possible injection attempt', { patterns: check.matched }) * // option A: reject * throw new HttpError(400, 'invalid input') * // option B: pass cleaned * await chat([{ role: 'user', content: check.cleaned }]) * } * ``` */ export declare function sanitizePrompt(text: string): SanitizeResult; export declare interface SanitizeResult { ok: boolean matched: string[] cleaned: string }