import { LanguageModel } from 'ai'; import { Book, RebookPlugin, TextBlock } from '../core/types'; type TranslationMode = 'replace' | 'bilingual'; type ValueOrGetter = T | (() => T); type TranslationUpdate = { sectionIndex: number; blocks: TextBlock[]; }; type ProfessionalPipelinePhase = 'idle' | 'starting' | 'running' | 'ready' | 'done' | 'cancelled' | 'error'; type BackendChunkStat = { status: string; _count: { status: number; }; }; export type TranslationTermCategory = 'term' | 'person' | 'organization' | 'place' | 'concept' | 'abbreviation'; export interface TranslationTerm { source: string; target?: string; category: TranslationTermCategory; note?: string; } export interface TranslationChapterSummary { sectionIndex: number; title: string; summary: string; } export interface ProfessionalTranslationProfile { bookType: string; audience: string; styleGuide: string; terminologyRules: string[]; properNounRules: string[]; terms: TranslationTerm[]; chapterSummaries: TranslationChapterSummary[]; } export interface ProfessionalBookAnalysis { title?: string; authors: string[]; language?: string; toc: Array<{ label: string; depth: number; }>; chapters: Array<{ sectionIndex: number; title: string; structures: Array<'table' | 'code' | 'formula' | 'footnote'>; sample: string; }>; structureSamples: { tables: string[]; codeBlocks: string[]; formulas: string[]; footnotes: string[]; }; } export interface ProfessionalTranslationStatus { phase: ProfessionalPipelinePhase; message: string; bookId?: string; jobId?: string; stage?: string; progress?: number; completedChunks?: number; totalChunks?: number; chunkStats?: BackendChunkStat[]; error?: unknown; } export interface ProfessionalTranslationPipelineOptions { /** Optional book type hint, e.g. "computer science textbook". */ bookType?: string; /** Optional target reader hint. */ audience?: string; /** Optional preferred translation style. */ style?: string; /** Maximum translation review/refine loops per chunk. Defaults to the backend setting. */ maxReviewLoops?: number; } export interface BackendProfessionalTranslationOptions { /** Base URL of rebook-service, e.g. "http://127.0.0.1:8083". */ serviceBaseUrl: string; /** Server-side rebook-service book id. The book must already be uploaded/imported there. */ bookId: string; /** Existing job id to attach to. When omitted and autoStart is true, the plugin starts one. */ jobId?: string; /** Target language sent when starting a new backend job. Defaults to zh-CN. */ targetLanguage?: string; /** Optional source language sent when starting a new backend job. */ sourceLanguage?: string; /** Display mode. Defaults to bilingual. */ mode?: ValueOrGetter; /** Number of pages ahead for renderer-driven backend status/chunk refreshes. Defaults to 2. */ prefetchPages?: ValueOrGetter; /** Start a backend expert translation job when jobId is not supplied. Defaults to true. */ autoStart?: boolean; /** Poll interval for backend job/chunk refresh. Defaults to 2000ms. */ pollIntervalMs?: number; /** Extra fetch init options, useful for credentials or headers. */ requestInit?: RequestInit; /** Optional fetch implementation for non-browser runtimes. */ fetcher?: typeof fetch; /** Backend expert translation hints. */ pipeline?: ProfessionalTranslationPipelineOptions; /** Called when backend translation status changes. */ onStatus?: (status: ProfessionalTranslationStatus) => void; /** * Called when backend translated chunks have updated a section. * Readers can use this to refresh the current section. */ onUpdate?: (event: TranslationUpdate) => void; } export interface TranslationOptions { /** The language model to use for translation (from @ai-sdk/...) */ model: LanguageModel; /** Target language (default: 'zh-CN') */ targetLanguage?: string; /** * Display mode: * - 'replace': Replace original text with translated text * - 'bilingual': Show original text followed by translated text * Default: 'bilingual' */ mode?: ValueOrGetter; /** Translate table of contents labels. Defaults to false. */ translateTOC?: ValueOrGetter; /** Max concurrency for translation requests (default: 2) */ concurrency?: number; /** * Approximate maximum tokens (or characters) per translation batch. * The plugin will group as many blocks as possible until this limit is reached. * (default: 2000) */ tokensPerBatch?: number; /** Number of pages ahead for renderer-driven block prefetching. Defaults to 2. */ prefetchPages?: ValueOrGetter; /** * Called when a background translation has updated a section. * Readers can use this to refresh the current section without blocking * initial rendering on the translation request. */ onUpdate?: (event: TranslationUpdate) => void; /** Called when table of contents labels have been translated. */ onTOCUpdate?: (toc: Book['toc']) => void; } /** * A professional translation plugin backed by rebook-service. * * Expert translation no longer runs in-process. The server owns the LangGraph * workflow, glossary, review/refine loop, persistence, and progress stream. */ export declare function withProfessionalTranslation(options: BackendProfessionalTranslationOptions): RebookPlugin; /** * A plugin that translates the text blocks of a book using Vercel AI SDK. */ export declare function withTranslation(options: TranslationOptions): RebookPlugin; export {}; //# sourceMappingURL=translation.d.ts.map