import { Glossary, GlossaryEntry } from "./glossary.cjs"; import { MediaType, TranslationTone } from "./prompt.cjs"; import { LanguageModel, ToolSet } from "ai"; //#region src/translate.d.ts /** * Options for dynamic glossary accumulation during chunk translation. */ interface DynamicGlossaryOptions { /** * Maximum number of terms to extract from each chunk. * * @default `10` */ readonly maxTermsPerChunk?: number; /** * The model to use for extracting terms. * If not specified, the primary translation model is used. */ readonly extractorModel?: LanguageModel; } /** * Options for iterative refinement of translations. */ interface RefinementOptions { /** * The minimum acceptable quality score (0-1). Chunks with scores below * this threshold will be refined. * * @default `0.85` */ readonly qualityThreshold?: number; /** * Maximum number of refinement iterations per chunk. * * @default `3` */ readonly maxIterations?: number; } /** * Options for translating chunks. */ interface TranslateChunksOptions { /** * The target language for translation. */ readonly targetLanguage: Intl.Locale | string; /** * The source language of the input text. */ readonly sourceLanguage?: Intl.Locale | string; /** * An optional title for the input text. It's translated along with * the first chunk if provided. */ readonly title?: string; /** * The desired tone for the translated text. */ readonly tone?: TranslationTone; /** * The domain or context of the text. */ readonly domain?: string; /** * The media type of the input text. */ readonly mediaType?: MediaType; /** * Additional context for the translation. */ readonly context?: string; /** * Initial glossary for consistent terminology. */ readonly glossary?: Glossary; /** * The language models to use for translation. * If multiple models are provided, best-of-N selection is used. */ readonly models: readonly LanguageModel[]; /** * The model to use for evaluating and selecting the best translation. * If not specified, the first model in the array is used. */ readonly evaluatorModel?: LanguageModel; /** * Dynamic glossary accumulation settings. * When enabled, terms are extracted from each translated chunk * and accumulated for use in subsequent chunks. */ readonly dynamicGlossary?: DynamicGlossaryOptions | null; /** * Refinement settings for iterative translation improvement. * When enabled, chunks are evaluated and refined until they meet * the quality threshold or reach maximum iterations. */ readonly refinement?: RefinementOptions | null; /** * Optional tools for passive context sources. */ readonly tools?: ToolSet; /** * Optional abort signal. */ readonly signal?: AbortSignal; } /** * Event yielded for each translated chunk. */ interface TranslatedChunkEvent { readonly type: "chunk"; /** * The index of the chunk (0-based). */ readonly index: number; /** * The translated text for this chunk. */ readonly translation: string; /** * The number of tokens used for this chunk. */ readonly tokensUsed: number; /** * The quality score if best-of-N selection was used. */ readonly qualityScore?: number; /** * The model that produced the best translation for this chunk. */ readonly selectedModel?: LanguageModel; /** * Terms extracted from this chunk if dynamic glossary is enabled. */ readonly extractedTerms?: readonly GlossaryEntry[]; } /** * Event yielded when all chunks are translated. */ interface TranslateChunksComplete { readonly type: "complete"; /** * All translated chunks in order. */ readonly translations: readonly string[]; /** * Total tokens used across all chunks. */ readonly totalTokensUsed: number; /** * All accumulated glossary terms from dynamic extraction. */ readonly accumulatedGlossary: readonly GlossaryEntry[]; /** * Average quality score across all chunks. * Only present if best-of-N selection or refinement was used. */ readonly qualityScore?: number; /** * Total number of refinement iterations performed. * Only present if refinement was enabled. */ readonly refinementIterations?: number; } /** * Events yielded during chunk translation. */ type TranslateChunksEvent = TranslatedChunkEvent | TranslateChunksComplete; /** * Translates source chunks using the provided models and options. * * This function returns an async iterable that yields events for each * translated chunk, allowing consumers to process chunks incrementally * and track progress. * * Features: * - Per-chunk parallel translation with multiple models (best-of-N selection) * - Previous chunk context passing for consistency * - Dynamic glossary accumulation across chunks * - Streaming results via AsyncIterable * * @param sourceChunks The source text chunks to translate. * @param options Translation options. * @returns An async iterable of translation events. */ declare function translateChunks(sourceChunks: readonly string[], options: TranslateChunksOptions): AsyncIterable; //#endregion export { DynamicGlossaryOptions, RefinementOptions, TranslateChunksComplete, TranslateChunksEvent, TranslateChunksOptions, TranslatedChunkEvent, translateChunks };