UNPKG

dadeumi

Version:

Dadeumi - An AI-powered literary translation workflow inspired by the Korean method of iterative textile refinement

122 lines (121 loc) 3.31 kB
import { TranslationConfig } from "../types"; /** * Main translation workflow class * Orchestrates the multi-stage translation process */ export declare class TranslationWorkflow { private conversation; private config; private intermediatesDir; private spinner; private totalTokens; private totalInputTokens; private totalOutputTokens; private estimatedCost; private xmlProcessor; private translationSteps; private outputFiles; private stepCounter; private conversationJsonPath; private conversationTextPath; private metricsPath; private sourceMetrics; private translationMetrics; private finalOutputPath; private aiService; private logger; private spinnerStartTime; private spinnerInterval; private continuationAttempts; private previousTranslationLength; private minimumMeaningfulProgress; private previousSourceLine; constructor(config: TranslationConfig); /** * Try to resume a previous translation session */ private tryResume; /** * Initialize a new conversation */ private initializeNewConversation; /** * Main execution method */ execute(): Promise<void>; /** * Save conversation history */ private saveConversationHistory; /** * Save translation metrics */ private saveTranslationMetrics; /** * Call AI service with retry logic */ private callAiService; /** * Update cost calculations */ private updateCost; /** * Display source metrics */ private displaySourceMetrics; /** * Display comparison with source text */ private displayComparisonWithSource; /** * Save the latest translation on error */ saveLatestTranslationOnError(): void; /** * Start spinner with elapsed time tracking */ private startSpinnerWithTimer; /** * Clear spinner interval */ private clearSpinnerInterval; /** * Stop spinner and clear interval */ private stopSpinner; /** * Succeed spinner and clear interval */ private succeedSpinner; /** * Fail spinner and clear interval */ private failSpinner; /** * Manage conversation context to prevent exceeding token limits */ private manageConversationContext; /** * Handle translation continuation for potentially incomplete translations * @param sourceText Original source text * @param translationText Current translation (potentially incomplete) * @param translationPath Path to save the translation * @param tag XML tag name used in the translation * @param forceCheck Force continuation regardless of completion check (for known truncation) * @returns Completed translation or the original if no continuation needed */ private handleTranslationContinuation; private extractAndContinueTagContent; /** * Clean translation content by removing XML tags and continuation markers */ private cleanTranslationContent; /** * Get the final translation output path */ getFinalOutputPath(): string; /** * Display human-readable token estimation (helper) */ private displayTokenEstimation; }