import { MediaType } from "./prompt.cjs"; //#region src/chunking.d.ts /** * A function that counts the number of tokens in a string. * * @param text The text to count tokens for. * @returns The number of tokens. */ type TokenCounter = (text: string) => number; /** * Options for {@link Chunker}. */ interface ChunkerOptions { /** * The maximum number of tokens per chunk. * * @default `4096` */ readonly maxTokens?: number; /** * A custom token counter function. If not provided, a default * implementation using js-tiktoken (cl100k_base encoding) is used. */ readonly countTokens?: TokenCounter; /** * An optional `AbortSignal` to cancel the chunking operation. */ readonly signal?: AbortSignal; } /** * Splits text into chunks for translation. * * @param text The text to split into chunks. * @param options Optional settings for the chunking operation. * @returns A promise that resolves to an array of chunks. */ type Chunker = (text: string, options?: ChunkerOptions) => Promise; /** * The type of content in a chunk. * * - `"paragraph"`: A paragraph of text. * - `"section"`: A section of the document. * - `"heading"`: A heading or title. * - `"list"`: A list of items. * - `"code"`: A code block. */ type ChunkType = "paragraph" | "section" | "heading" | "list" | "code"; /** * A chunk of text to be translated. */ interface Chunk { /** * The text content of the chunk. */ readonly content: string; /** * The type of content in the chunk. */ readonly type: ChunkType; /** * The zero-based index of the chunk in the document. */ readonly index: number; } /** * Options for {@link chunkText}. */ interface ChunkTextOptions { /** * The media type of the text. Used to select the default chunker * when {@link chunker} is not provided. * * - `"text/html"`: Uses the HTML chunker. * - `"text/markdown"`: Uses the Markdown chunker. * - `"text/plain"`: Uses the plain text chunker. * * @default `"text/markdown"` */ readonly mediaType?: MediaType; /** * A custom chunker function. If not provided, a default chunker * based on {@link mediaType} is used. Set to `null` to disable * chunking entirely (text will be returned as a single chunk). */ readonly chunker?: Chunker | null; /** * The maximum number of tokens per chunk. * * @default `4096` */ readonly maxTokens?: number; /** * A custom token counter function. If not provided, a default * implementation using js-tiktoken (cl100k_base encoding) is used. */ readonly countTokens?: TokenCounter; /** * An optional `AbortSignal` to cancel the chunking operation. */ readonly signal?: AbortSignal; } /** * Gets the default chunker based on media type. * * @param mediaType The media type of the text. * @returns A promise that resolves to the appropriate chunker for the media type. */ declare function getDefaultChunker(mediaType?: MediaType): Promise; /** * Chunks text into smaller pieces for translation. * * This is a convenience function that combines chunker selection and execution. * If chunking is disabled (chunker is `null`), the text is returned as a * single-element array. * * @param text The text to chunk. * @param options Options for chunking. * @returns A promise that resolves to an array of chunk content strings. */ declare function chunkText(text: string, options?: ChunkTextOptions): Promise; //#endregion export { Chunk, ChunkTextOptions, ChunkType, Chunker, ChunkerOptions, type MediaType, TokenCounter, chunkText, getDefaultChunker };