locai 2.1.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/cli.d.ts +2 -0
  2. package/dist/commands/review.d.ts +109 -0
  3. package/dist/commands/translator.d.ts +23 -0
  4. package/dist/config/index.d.ts +145 -0
  5. package/dist/core/adapters/base-adapter.d.ts +20 -0
  6. package/dist/core/adapters/factory.d.ts +16 -0
  7. package/dist/core/adapters/json-adapter.d.ts +9 -0
  8. package/dist/core/adapters/po-adapter.d.ts +9 -0
  9. package/dist/core/adapters/properties-adapter.d.ts +9 -0
  10. package/dist/core/adapters/yaml-adapter.d.ts +9 -0
  11. package/dist/core/context-processor.d.ts +81 -0
  12. package/dist/core/detection/framework-detector.d.ts +9 -0
  13. package/dist/core/detection/structure-detector.d.ts +9 -0
  14. package/dist/core/fallback-provider.d.ts +54 -0
  15. package/dist/core/orchestrator.d.ts +101 -0
  16. package/dist/core/pipeline/Pipeline.d.ts +23 -0
  17. package/dist/core/pipeline/PipelineStep.d.ts +18 -0
  18. package/dist/core/pipeline/context.d.ts +29 -0
  19. package/dist/core/pipeline/steps/CacheReadStep.d.ts +25 -0
  20. package/dist/core/pipeline/steps/CacheWriteStep.d.ts +11 -0
  21. package/dist/core/pipeline/steps/ConfidenceCheckStep.d.ts +10 -0
  22. package/dist/core/pipeline/steps/GlossaryPostStep.d.ts +9 -0
  23. package/dist/core/pipeline/steps/GlossaryPreStep.d.ts +9 -0
  24. package/dist/core/pipeline/steps/InputValidationStep.d.ts +8 -0
  25. package/dist/core/pipeline/steps/QualityCheckStep.d.ts +10 -0
  26. package/dist/core/pipeline/steps/ToneCheckStep.d.ts +13 -0
  27. package/dist/core/pipeline/steps/TranslationStep.d.ts +22 -0
  28. package/dist/core/pipeline/steps/VectorCacheReadStep.d.ts +17 -0
  29. package/dist/core/pipeline/steps/VectorCacheWriteStep.d.ts +11 -0
  30. package/dist/core/pipeline/steps/__tests__/ToneCheckStep.test.d.ts +1 -0
  31. package/dist/core/provider-factory.d.ts +41 -0
  32. package/dist/core/provider-factory.js +4 -0
  33. package/dist/providers/anthropic.d.ts +25 -0
  34. package/dist/providers/anthropic.js +178 -0
  35. package/dist/providers/base-provider.d.ts +66 -0
  36. package/dist/providers/dashscope.d.ts +24 -0
  37. package/dist/providers/deepseek.d.ts +22 -0
  38. package/dist/providers/gemini.d.ts +22 -0
  39. package/dist/providers/gemini.js +3 -3
  40. package/dist/providers/openai.d.ts +28 -0
  41. package/dist/providers/openai.js +3 -3
  42. package/dist/providers/xai.d.ts +22 -0
  43. package/dist/services/embedding-provider.d.ts +26 -0
  44. package/dist/services/translation-service.d.ts +138 -0
  45. package/dist/services/vector-store.d.ts +26 -0
  46. package/dist/utils/ai-context-analyzer.d.ts +73 -0
  47. package/dist/utils/confidence-scorer.d.ts +77 -0
  48. package/dist/utils/error-helper.d.ts +87 -0
  49. package/dist/utils/error-helper.js +3 -1
  50. package/dist/utils/file-manager.d.ts +129 -0
  51. package/dist/utils/glossary-manager.d.ts +69 -0
  52. package/dist/utils/graceful-shutdown.d.ts +22 -0
  53. package/dist/utils/input-validator.d.ts +227 -0
  54. package/dist/utils/input-validator.js +8 -1
  55. package/dist/utils/logger.d.ts +134 -0
  56. package/dist/utils/object-transformer.d.ts +38 -0
  57. package/dist/utils/progress-tracker.d.ts +63 -0
  58. package/dist/utils/prompt-templates.d.ts +37 -0
  59. package/dist/utils/prompt-templates.js +18 -0
  60. package/dist/utils/quality/__tests__/tone-verifier.test.d.ts +1 -0
  61. package/dist/utils/quality/base-checker.d.ts +79 -0
  62. package/dist/utils/quality/code-block-checker.d.ts +64 -0
  63. package/dist/utils/quality/html-tag-checker.d.ts +33 -0
  64. package/dist/utils/quality/index.d.ts +39 -0
  65. package/dist/utils/quality/length-checker.d.ts +70 -0
  66. package/dist/utils/quality/markdown-checker.d.ts +63 -0
  67. package/dist/utils/quality/placeholder-checker.d.ts +42 -0
  68. package/dist/utils/quality/punctuation-checker.d.ts +31 -0
  69. package/dist/utils/quality/quote-balance-checker.d.ts +37 -0
  70. package/dist/utils/quality/special-characters-checker.d.ts +66 -0
  71. package/dist/utils/quality/style-guide-checker.d.ts +71 -0
  72. package/dist/utils/quality/text-sanitizer.d.ts +51 -0
  73. package/dist/utils/quality/tone-verifier.d.ts +14 -0
  74. package/dist/utils/rate-limiter.d.ts +73 -0
  75. package/dist/utils/rate-limiter.js +6 -0
  76. package/dist/utils/retry-helper.d.ts +49 -0
  77. package/dist/utils/state-manager.d.ts +62 -0
  78. package/dist/utils/statistics-manager.d.ts +47 -0
  79. package/dist/utils/ui-manager.d.ts +21 -0
  80. package/package.json +13 -5
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Glossary Manager
3
+ * Manages brand terminology and ensures consistent translations
4
+ */
5
+ export interface GlossaryEntry {
6
+ term: string;
7
+ translation: string;
8
+ caseSensitive?: boolean;
9
+ languages?: string[];
10
+ }
11
+ export interface ProtectedTerm {
12
+ original: string;
13
+ translation: string;
14
+ term: string;
15
+ }
16
+ export interface GlossaryConfig {
17
+ glossary?: Record<string, string | Partial<GlossaryEntry> | Record<string, string>>;
18
+ enabled?: boolean;
19
+ caseSensitive?: boolean;
20
+ preserveFormatting?: boolean;
21
+ }
22
+ declare class GlossaryManager {
23
+ private glossary;
24
+ enabled: boolean;
25
+ private caseSensitive;
26
+ private preserveFormatting;
27
+ constructor(config?: GlossaryConfig);
28
+ /**
29
+ * Apply glossary terms to source text before translation
30
+ * Replaces terms with protected tokens to preserve them
31
+ */
32
+ protectTerms(text: string, sourceLang: string, targetLang: string): {
33
+ protectedText: string;
34
+ termMap: Map<string, ProtectedTerm>;
35
+ };
36
+ /**
37
+ * Restore protected terms in translated text
38
+ */
39
+ restoreTerms(translatedText: string, termMap: Map<string, ProtectedTerm>): string;
40
+ /**
41
+ * Get applicable glossary entries for language pair
42
+ */
43
+ getApplicableEntries(sourceLang: string, targetLang: string): GlossaryEntry[];
44
+ /**
45
+ * Match formatting (capitalization) from original to translation
46
+ */
47
+ matchFormatting(original: string, translation: string): string;
48
+ /**
49
+ * Escape special regex characters
50
+ */
51
+ escapeRegex(string: string): string;
52
+ /**
53
+ * Validate glossary configuration
54
+ */
55
+ validate(): {
56
+ valid: boolean;
57
+ errors: string[];
58
+ warnings: string[];
59
+ };
60
+ /**
61
+ * Get statistics about glossary
62
+ */
63
+ getStats(): any;
64
+ /**
65
+ * Load glossary from file
66
+ */
67
+ static loadFromFile(filePath: string): Promise<GlossaryManager>;
68
+ }
69
+ export default GlossaryManager;
@@ -0,0 +1,22 @@
1
+ export type ShutdownCallback = () => Promise<void> | void;
2
+ export interface ShutdownOptions {
3
+ shutdownTimeout?: number;
4
+ waitForPending?: boolean;
5
+ logger?: Console | any;
6
+ }
7
+ declare class GracefulShutdown {
8
+ private options;
9
+ private isShuttingDown;
10
+ private shutdownCallbacks;
11
+ private logger;
12
+ constructor(options?: ShutdownOptions);
13
+ registerCallback(callback: ShutdownCallback): void;
14
+ unregisterCallback(callback: ShutdownCallback): void;
15
+ init(): void;
16
+ handleSignal(signal: string): Promise<void>;
17
+ shutdown(exitCode?: number): Promise<void>;
18
+ performShutdown(): Promise<void>;
19
+ waitForPendingOperations(): Promise<void>;
20
+ }
21
+ declare const gracefulShutdown: GracefulShutdown;
22
+ export default gracefulShutdown;
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Input validation utility for security and data integrity.
3
+ * Defines regex patterns, limits, and validation methods.
4
+ */
5
+ export interface ApiProviderConfig {
6
+ temperature?: number;
7
+ maxTokens?: number;
8
+ [key: string]: any;
9
+ }
10
+ export interface RateLimiterProviderLimit {
11
+ rpm?: number;
12
+ concurrency?: number;
13
+ }
14
+ export interface RateLimiterConfig {
15
+ queueStrategy?: "fifo" | "priority";
16
+ queueTimeout?: number;
17
+ providerLimits?: Record<string, RateLimiterProviderLimit>;
18
+ }
19
+ export interface RetryOptions {
20
+ maxRetries?: number;
21
+ initialDelay?: number;
22
+ maxDelay?: number;
23
+ }
24
+ export interface ContextConfig {
25
+ aiProvider?: string;
26
+ minTextLength?: number;
27
+ detection?: {
28
+ threshold?: number;
29
+ minConfidence?: number;
30
+ };
31
+ categories?: Record<string, any>;
32
+ }
33
+ export interface QualityChecksConfig {
34
+ rules?: Record<string, any>;
35
+ enabled?: boolean;
36
+ autoFix?: boolean;
37
+ }
38
+ export interface LengthControlConfig {
39
+ mode?: "strict" | "flexible" | "exact" | "relaxed" | "smart";
40
+ rules?: Record<string, any>;
41
+ }
42
+ export interface AdvancedConfig {
43
+ timeoutMs?: number;
44
+ maxKeyLength?: number;
45
+ maxBatchSize?: number;
46
+ }
47
+ export interface AppConfig {
48
+ source: string;
49
+ targets: string[];
50
+ localesDir: string;
51
+ apiProvider?: string;
52
+ fallbackOrder?: string[];
53
+ concurrencyLimit?: number;
54
+ cacheSize?: number;
55
+ cacheTTL?: number;
56
+ apiConfig?: Record<string, ApiProviderConfig>;
57
+ rateLimiter?: RateLimiterConfig;
58
+ retryOptions?: RetryOptions;
59
+ context?: ContextConfig;
60
+ qualityChecks?: QualityChecksConfig;
61
+ lengthControl?: LengthControlConfig;
62
+ advanced?: AdvancedConfig;
63
+ fileOperations?: Record<string, any>;
64
+ debug?: boolean;
65
+ verbose?: boolean;
66
+ [key: string]: any;
67
+ }
68
+ declare class InputValidator {
69
+ static LANGUAGE_CODE_PATTERN: RegExp;
70
+ static VALID_PROVIDERS: string[];
71
+ static MAX_TEXT_LENGTH: number;
72
+ static MAX_KEY_LENGTH: number;
73
+ static MAX_PATH_LENGTH: number;
74
+ static MAX_CONFIG_DEPTH: number;
75
+ static DANGEROUS_PATTERNS: RegExp[];
76
+ private static _requestCounts?;
77
+ /**
78
+ * Validate and sanitize language code.
79
+ * @param {string} langCode - Language code to validate.
80
+ * @param {string} [paramName="language"] - Parameter name for error messages.
81
+ * @returns {string} - Sanitized language code.
82
+ * @throws {Error} If validation fails.
83
+ */
84
+ static validateLanguageCode(langCode: string, paramName?: string): string;
85
+ /**
86
+ * Validate array of language codes.
87
+ * @param {string[]} langCodes - Array of language codes.
88
+ * @param {string} [paramName="languages"] - Parameter name for errors.
89
+ * @returns {string[]} - Sanitized array of language codes.
90
+ * @throws {Error} If array is empty or contains invalid codes.
91
+ */
92
+ static validateLanguageCodes(langCodes: string[], paramName?: string): string[];
93
+ /**
94
+ * Validate and sanitize directory path.
95
+ * @param {string} dirPath - Directory path.
96
+ * @param {string} [paramName="directory"] - Parameter name for errors.
97
+ * @returns {string} - Resolved and validated absolute path.
98
+ * @throws {Error} If path is invalid or outside working directory.
99
+ */
100
+ static validateDirectoryPath(dirPath: string, paramName?: string): string;
101
+ /**
102
+ * Validate translation text.
103
+ * @param {string} text - Text to validate.
104
+ * @param {string} [paramName="text"] - Parameter name for errors.
105
+ * @returns {string} - Validated text.
106
+ * @throws {Error} If text is invalid or too long.
107
+ */
108
+ static validateText(text: string, paramName?: string): string;
109
+ /**
110
+ * Validate translation key.
111
+ * @param {string} key - Key to validate.
112
+ * @param {string} [paramName="key"] - Parameter name.
113
+ * @returns {string} - Validated key.
114
+ * @throws {Error} If key is invalid, too long, or contains traversal.
115
+ */
116
+ static validateKey(key: string, paramName?: string): string;
117
+ /**
118
+ * Validate API provider name.
119
+ * @param {string} provider - Provider name.
120
+ * @param {string} [fieldName="API provider"] - Parameter name.
121
+ * @returns {string} - Normalized provider name.
122
+ * @throws {Error} If provider is unknown.
123
+ */
124
+ static validateProvider(provider: string, fieldName?: string): string;
125
+ /**
126
+ * Sanitize filename to prevent path traversal.
127
+ * @param {string} filename - Filename to sanitize.
128
+ * @param {string|null} [extension=null] - Optional extension to enforce.
129
+ * @returns {string} - Sanitized filename.
130
+ * @throws {Error} If filename is invalid.
131
+ */
132
+ static sanitizeFilename(filename: string, extension?: string | null): string;
133
+ /**
134
+ * Create safe file path within a directory.
135
+ * @param {string} baseDir - Base directory.
136
+ * @param {string} filename - Filename.
137
+ * @returns {string} - Safe full path.
138
+ * @throws {Error} If path escapes base directory.
139
+ */
140
+ static createSafeFilePath(baseDir: string, filename: string): string;
141
+ /**
142
+ * Validate configuration object.
143
+ * @param {any} config - Configuration object to validate.
144
+ * @returns {AppConfig} - Validated configuration.
145
+ * @throws {Error} If configuration is invalid.
146
+ */
147
+ static validateConfig(config: any): AppConfig;
148
+ /**
149
+ * Validate API config for each provider.
150
+ * @param {Record<string, ApiProviderConfig>} apiConfig - API configuration object.
151
+ * @param {string[]} errors - Array to push errors to.
152
+ * @param {string[]} warnings - Array to push warnings to.
153
+ */
154
+ static validateApiConfig(apiConfig: Record<string, ApiProviderConfig>, errors: string[], warnings: string[]): void;
155
+ /**
156
+ * Validate rate limiter configuration.
157
+ * @param {RateLimiterConfig} rateLimiter - Rate limiter configuration.
158
+ * @param {string[]} errors - Array to push errors to.
159
+ * @param {string[]} warnings - Array to push warnings to.
160
+ */
161
+ static validateRateLimiterConfig(rateLimiter: RateLimiterConfig, errors: string[], _warnings: string[]): void;
162
+ /**
163
+ * Validate retry options.
164
+ * @param {RetryOptions} retryOptions - Retry options.
165
+ * @param {string[]} errors - Array to push errors to.
166
+ * @param {string[]} warnings - Array to push warnings to.
167
+ */
168
+ static validateRetryOptions(retryOptions: RetryOptions, errors: string[], _warnings: string[]): void;
169
+ /**
170
+ * Validate context configuration.
171
+ * @param {ContextConfig} context - Context configuration.
172
+ * @param {string[]} errors - Array to push errors to.
173
+ * @param {string[]} warnings - Array to push warnings to.
174
+ */
175
+ static validateContextConfig(context: ContextConfig, errors: string[], warnings: string[]): void;
176
+ /**
177
+ * Validate quality checks configuration.
178
+ * @param {QualityChecksConfig} qualityChecks - Quality checks configuration.
179
+ * @param {string[]} errors - Array to push errors to.
180
+ * @param {string[]} warnings - Array to push warnings to.
181
+ */
182
+ static validateQualityChecks(qualityChecks: QualityChecksConfig, errors: string[], warnings: string[]): void;
183
+ /**
184
+ * Validate length control configuration.
185
+ * @param {LengthControlConfig} lengthControl - Length control configuration.
186
+ * @param {string[]} errors - Array to push errors to.
187
+ */
188
+ static validateLengthControl(lengthControl: LengthControlConfig, errors: string[]): void;
189
+ /**
190
+ * Validate advanced configuration.
191
+ * @param {AdvancedConfig} advanced - Advanced configuration.
192
+ * @param {string[]} errors - Array to push errors to.
193
+ */
194
+ static validateAdvancedConfig(advanced: AdvancedConfig, errors: string[]): void;
195
+ /**
196
+ * Sanitize translation text for security.
197
+ * @param {string | null} text - Text to sanitize.
198
+ * @returns {string | null} - Sanitized text.
199
+ */
200
+ static sanitizeTranslationText(text: string | null): string | null;
201
+ /**
202
+ * Validate API key format.
203
+ * @param {string} apiKey - API key to validate.
204
+ * @param {string} providerName - Provider name.
205
+ * @returns {boolean} - True if valid.
206
+ * @throws {Error} If key is invalid.
207
+ */
208
+ static validateApiKeyFormat(apiKey: string, providerName: string): boolean;
209
+ /**
210
+ * Validate object depth to prevent circular references and deep nesting.
211
+ * @param {any} obj - Object to validate.
212
+ * @param {number} [maxDepth=10] - Maximum depth.
213
+ * @param {number} [currentDepth=0] - Current depth.
214
+ * @returns {boolean} - True if valid.
215
+ * @throws {Error} If depth exceeded.
216
+ */
217
+ static validateObjectDepth(obj: any, maxDepth?: number, currentDepth?: number): boolean;
218
+ /**
219
+ * Validate request rate for an identifier.
220
+ * @param {string} identifier - Identifier (e.g., user ID or IP).
221
+ * @param {number} [maxRequestsPerMinute=60] - Max requests per minute.
222
+ * @returns {boolean} - True if allowed.
223
+ * @throws {Error} If rate limit exceeded.
224
+ */
225
+ static validateRequestRate(identifier: string, maxRequestsPerMinute?: number): boolean;
226
+ }
227
+ export default InputValidator;
@@ -5,7 +5,14 @@
5
5
  import path from "path";
6
6
  class InputValidator {
7
7
  static LANGUAGE_CODE_PATTERN = /^[a-z]{2}(-[a-z]{2})?$/;
8
- static VALID_PROVIDERS = ["dashscope", "xai", "openai", "deepseek", "gemini"];
8
+ static VALID_PROVIDERS = [
9
+ "dashscope",
10
+ "xai",
11
+ "openai",
12
+ "deepseek",
13
+ "gemini",
14
+ "anthropic",
15
+ ];
9
16
  static MAX_TEXT_LENGTH = 10000;
10
17
  static MAX_KEY_LENGTH = 500;
11
18
  static MAX_PATH_LENGTH = 1000;
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Advanced Logging System.
3
+ * Implements saveErrorLogs, logDirectory, logRotation, and other logging features.
4
+ */
5
+ export interface LogRotationConfig {
6
+ enabled: boolean;
7
+ maxFiles: number;
8
+ maxSize: number;
9
+ }
10
+ export interface LoggerConfig {
11
+ verbose?: boolean;
12
+ diagnosticsLevel?: "minimal" | "normal" | "detailed";
13
+ outputFormat?: "pretty" | "json" | "simple";
14
+ saveErrorLogs?: boolean;
15
+ logDirectory?: string;
16
+ includeTimestamps?: boolean;
17
+ logRotation?: Partial<LogRotationConfig>;
18
+ }
19
+ interface InternalLoggerConfig extends Required<Omit<LoggerConfig, "logRotation">> {
20
+ logRotation: LogRotationConfig;
21
+ }
22
+ interface LogStats {
23
+ size: number;
24
+ sizeFormatted: string;
25
+ modified: Date | null;
26
+ }
27
+ declare class Logger {
28
+ config: InternalLoggerConfig;
29
+ logFiles: Record<string, string>;
30
+ currentLogSizes: Record<string, number>;
31
+ private initialized;
32
+ /**
33
+ * Create a new Logger instance.
34
+ * @param config - Logger configuration.
35
+ */
36
+ constructor(config?: LoggerConfig);
37
+ /**
38
+ * Initialize logger (create directories, check rotation).
39
+ */
40
+ initialize(): Promise<void>;
41
+ /**
42
+ * Parse size string (e.g., "10MB") to bytes.
43
+ * @param sizeStr - Size string to parse.
44
+ */
45
+ parseSize(sizeStr: any): number;
46
+ /**
47
+ * Check and rotate logs if needed.
48
+ */
49
+ checkAndRotateLogs(): Promise<void>;
50
+ /**
51
+ * Rotate a log file.
52
+ * @param logPath - Path to the log file.
53
+ */
54
+ rotateLog(logPath: string): Promise<void>;
55
+ /**
56
+ * Clean up old log files.
57
+ * @param dir - Directory containing log files.
58
+ * @param basename - Basename of the log file.
59
+ */
60
+ cleanupOldLogs(dir: string, basename: string): Promise<void>;
61
+ /**
62
+ * Format log message.
63
+ * @param level - Log level.
64
+ * @param message - Log message.
65
+ * @param data - Additional data to log.
66
+ */
67
+ formatMessage(level: string, message: string, data?: any): string;
68
+ /**
69
+ * Write to log file.
70
+ * @param level - Log level.
71
+ * @param message - Log message.
72
+ * @param data - Additional data to log.
73
+ */
74
+ writeToFile(level: string, message: string, data?: any): Promise<void>;
75
+ /**
76
+ * Simple console log with debug awareness.
77
+ * @param message - Message to log
78
+ * @param debugOnly - Only log if debug mode is enabled
79
+ */
80
+ log(message: string, debugOnly?: boolean): Promise<void>;
81
+ /**
82
+ * Log error.
83
+ * @param message - Error message.
84
+ * @param data - Additional data.
85
+ */
86
+ error(message: string, data?: any): Promise<void>;
87
+ /**
88
+ * Log warning.
89
+ * @param message - Warning message.
90
+ * @param data - Additional data.
91
+ */
92
+ warn(message: string, data?: any): Promise<void>;
93
+ /**
94
+ * Log info.
95
+ * @param message - Info message.
96
+ * @param data - Additional data.
97
+ */
98
+ info(message: string, data?: any): Promise<void>;
99
+ /**
100
+ * Log debug.
101
+ * @param message - Debug message.
102
+ * @param data - Additional data.
103
+ */
104
+ debug(message: string, data?: any): Promise<void>;
105
+ /**
106
+ * Log based on diagnostics level.
107
+ * @param level - Log level.
108
+ * @param message - Log message.
109
+ * @param data - Additional data.
110
+ */
111
+ diagnostics(level: string, message: string, data?: any): Promise<void>;
112
+ /**
113
+ * Get log statistics.
114
+ * @returns Object containing log stats.
115
+ */
116
+ getLogStats(): Promise<Record<string, LogStats>>;
117
+ /**
118
+ * Format size to human-readable.
119
+ * @param bytes - Size in bytes.
120
+ */
121
+ formatSize(bytes: number): string;
122
+ /**
123
+ * Clear all logs.
124
+ */
125
+ clearLogs(): Promise<void>;
126
+ }
127
+ export declare function getLogger(config?: LoggerConfig | null): Logger;
128
+ /**
129
+ * Quick debug-aware logging helper.
130
+ * @param message - Message to log.
131
+ * @param debugOnly - Only log in debug/verbose mode.
132
+ */
133
+ export declare function log(message: string, debugOnly?: boolean): void;
134
+ export default Logger;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Utility class for object manipulation.
3
+ */
4
+ export interface TransformedObject {
5
+ [key: string]: any;
6
+ }
7
+ declare class ObjectTransformer {
8
+ /**
9
+ * Flatten a nested object into a single-level object with dot notation keys.
10
+ * @param obj - The object to flatten.
11
+ * @param prefix - Prefix for keys (used internally).
12
+ * @param maxDepth - Maximum recursion depth.
13
+ * @returns Flattened object.
14
+ */
15
+ static flatten(obj: TransformedObject, prefix?: string, maxDepth?: number): Record<string, string | number | boolean | null>;
16
+ /**
17
+ * Unflatten an object with dot notation keys into a nested object.
18
+ * @param obj - The flattened object.
19
+ * @returns Nested object.
20
+ */
21
+ static unflatten(obj: Record<string, any>): TransformedObject;
22
+ /**
23
+ * Create a deep copy of an object.
24
+ * @param obj - The object to clone.
25
+ * @param seen - Internal set to track circular references.
26
+ * @returns Deep copy of the object.
27
+ */
28
+ static deepClone<T>(obj: T, seen?: WeakSet<object>): T;
29
+ /**
30
+ * deeply merge two objects.
31
+ * @param target - The target object.
32
+ * @param source - The source object.
33
+ * @param overwriteArrays - Whether to overwrite arrays or merge them.
34
+ * @returns Merged object.
35
+ */
36
+ static mergeObjects(target: TransformedObject, source: TransformedObject, overwriteArrays?: boolean): TransformedObject;
37
+ }
38
+ export default ObjectTransformer;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Progress tracking for translation operations
3
+ */
4
+ export interface ProgressOptions {
5
+ logToConsole?: boolean;
6
+ logFrequency?: number;
7
+ }
8
+ export interface ProgressStatistics {
9
+ avgTimePerItem: number;
10
+ recentAvgTimePerItem?: number;
11
+ totalTime: number;
12
+ estimatedTimeRemaining: number;
13
+ itemsPerSecond: number;
14
+ percentComplete: number;
15
+ successRate: number;
16
+ startTime?: string;
17
+ estimatedEndTime?: string;
18
+ }
19
+ export interface ProgressStatus {
20
+ total: number;
21
+ completed: number;
22
+ success: number;
23
+ failed: number;
24
+ language: string | null;
25
+ inProgress: boolean;
26
+ statistics: ProgressStatistics;
27
+ }
28
+ declare class ProgressTracker {
29
+ private logToConsole;
30
+ private logFrequency;
31
+ private _isUpdating;
32
+ private _pendingUpdates;
33
+ private _spinnerInterval;
34
+ private _spinnerIndex;
35
+ private _spinnerFrames;
36
+ private total;
37
+ private completed;
38
+ private success;
39
+ private failed;
40
+ private startTime;
41
+ private endTime;
42
+ private lastUpdateTime;
43
+ private recentOperationTimes;
44
+ private language;
45
+ private isCompleted;
46
+ private statistics;
47
+ constructor(options?: ProgressOptions);
48
+ reset(): void;
49
+ start(total: number, language?: string | null): void;
50
+ increment(type?: string): void;
51
+ private _processUpdate;
52
+ private _ensureDataConsistency;
53
+ private _processPendingUpdates;
54
+ private _shouldLog;
55
+ private _startSpinner;
56
+ private _stopSpinner;
57
+ private _renderProgress;
58
+ private _updateStatistics;
59
+ private _finalReport;
60
+ getStatus(): ProgressStatus;
61
+ setLogToConsole(value: boolean): void;
62
+ }
63
+ export default ProgressTracker;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Prompt template utilities for translation and analysis
3
+ */
4
+ export interface PromptOptions {
5
+ mode?: "smart" | "strict" | "flexible" | "exact" | "relaxed";
6
+ lengthControl?: any;
7
+ targetLang?: string;
8
+ detectedContext?: {
9
+ category?: string;
10
+ confidence?: number;
11
+ prompt?: string;
12
+ existingTranslation?: string;
13
+ similarTranslation?: {
14
+ source: string;
15
+ target: string;
16
+ similarity: number;
17
+ };
18
+ };
19
+ styleGuide?: {
20
+ formality?: string;
21
+ toneOfVoice?: string;
22
+ };
23
+ categories?: Record<string, any>;
24
+ allowNewCategories?: boolean;
25
+ model?: string;
26
+ temperature?: number;
27
+ maxTokens?: number;
28
+ }
29
+ /**
30
+ * Get translation prompt
31
+ */
32
+ declare const getPrompt: (provider: string, sourceLang: string, targetLang: string, text: string, options?: PromptOptions) => any;
33
+ /**
34
+ * Get analysis prompt
35
+ */
36
+ declare const getAnalysisPrompt: (provider: string, text: string, options?: PromptOptions) => any;
37
+ export { getPrompt, getAnalysisPrompt };
@@ -236,6 +236,15 @@ Original Text: "${text}"`,
236
236
  },
237
237
  ],
238
238
  }),
239
+ anthropic: (sourceLang, targetLang, text, options) => ({
240
+ system: baseTranslationPromptTemplate(sourceLang, targetLang, text, options),
241
+ messages: [
242
+ {
243
+ role: "user",
244
+ content: text,
245
+ },
246
+ ],
247
+ }),
239
248
  deepseek: (sourceLang, targetLang, text, options) => ({
240
249
  messages: [
241
250
  {
@@ -317,6 +326,15 @@ const analysisPrompts = {
317
326
  max_tokens: options.maxTokens || 1000,
318
327
  },
319
328
  }),
329
+ anthropic: (text, options) => ({
330
+ system: "You are a context analysis assistant that helps identify the category and context of text.",
331
+ messages: [
332
+ {
333
+ role: "user",
334
+ content: baseAnalysisPromptTemplate(text, options),
335
+ },
336
+ ],
337
+ }),
320
338
  deepseek: (text, options) => ({
321
339
  messages: [
322
340
  {