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.
- package/dist/cli.d.ts +2 -0
- package/dist/commands/review.d.ts +109 -0
- package/dist/commands/translator.d.ts +23 -0
- package/dist/config/index.d.ts +145 -0
- package/dist/core/adapters/base-adapter.d.ts +20 -0
- package/dist/core/adapters/factory.d.ts +16 -0
- package/dist/core/adapters/json-adapter.d.ts +9 -0
- package/dist/core/adapters/po-adapter.d.ts +9 -0
- package/dist/core/adapters/properties-adapter.d.ts +9 -0
- package/dist/core/adapters/yaml-adapter.d.ts +9 -0
- package/dist/core/context-processor.d.ts +81 -0
- package/dist/core/detection/framework-detector.d.ts +9 -0
- package/dist/core/detection/structure-detector.d.ts +9 -0
- package/dist/core/fallback-provider.d.ts +54 -0
- package/dist/core/orchestrator.d.ts +101 -0
- package/dist/core/pipeline/Pipeline.d.ts +23 -0
- package/dist/core/pipeline/PipelineStep.d.ts +18 -0
- package/dist/core/pipeline/context.d.ts +29 -0
- package/dist/core/pipeline/steps/CacheReadStep.d.ts +25 -0
- package/dist/core/pipeline/steps/CacheWriteStep.d.ts +11 -0
- package/dist/core/pipeline/steps/ConfidenceCheckStep.d.ts +10 -0
- package/dist/core/pipeline/steps/GlossaryPostStep.d.ts +9 -0
- package/dist/core/pipeline/steps/GlossaryPreStep.d.ts +9 -0
- package/dist/core/pipeline/steps/InputValidationStep.d.ts +8 -0
- package/dist/core/pipeline/steps/QualityCheckStep.d.ts +10 -0
- package/dist/core/pipeline/steps/ToneCheckStep.d.ts +13 -0
- package/dist/core/pipeline/steps/TranslationStep.d.ts +22 -0
- package/dist/core/pipeline/steps/VectorCacheReadStep.d.ts +17 -0
- package/dist/core/pipeline/steps/VectorCacheWriteStep.d.ts +11 -0
- package/dist/core/pipeline/steps/__tests__/ToneCheckStep.test.d.ts +1 -0
- package/dist/core/provider-factory.d.ts +41 -0
- package/dist/core/provider-factory.js +4 -0
- package/dist/providers/anthropic.d.ts +25 -0
- package/dist/providers/anthropic.js +178 -0
- package/dist/providers/base-provider.d.ts +66 -0
- package/dist/providers/dashscope.d.ts +24 -0
- package/dist/providers/deepseek.d.ts +22 -0
- package/dist/providers/gemini.d.ts +22 -0
- package/dist/providers/gemini.js +3 -3
- package/dist/providers/openai.d.ts +28 -0
- package/dist/providers/openai.js +3 -3
- package/dist/providers/xai.d.ts +22 -0
- package/dist/services/embedding-provider.d.ts +26 -0
- package/dist/services/translation-service.d.ts +138 -0
- package/dist/services/vector-store.d.ts +26 -0
- package/dist/utils/ai-context-analyzer.d.ts +73 -0
- package/dist/utils/confidence-scorer.d.ts +77 -0
- package/dist/utils/error-helper.d.ts +87 -0
- package/dist/utils/error-helper.js +3 -1
- package/dist/utils/file-manager.d.ts +129 -0
- package/dist/utils/glossary-manager.d.ts +69 -0
- package/dist/utils/graceful-shutdown.d.ts +22 -0
- package/dist/utils/input-validator.d.ts +227 -0
- package/dist/utils/input-validator.js +8 -1
- package/dist/utils/logger.d.ts +134 -0
- package/dist/utils/object-transformer.d.ts +38 -0
- package/dist/utils/progress-tracker.d.ts +63 -0
- package/dist/utils/prompt-templates.d.ts +37 -0
- package/dist/utils/prompt-templates.js +18 -0
- package/dist/utils/quality/__tests__/tone-verifier.test.d.ts +1 -0
- package/dist/utils/quality/base-checker.d.ts +79 -0
- package/dist/utils/quality/code-block-checker.d.ts +64 -0
- package/dist/utils/quality/html-tag-checker.d.ts +33 -0
- package/dist/utils/quality/index.d.ts +39 -0
- package/dist/utils/quality/length-checker.d.ts +70 -0
- package/dist/utils/quality/markdown-checker.d.ts +63 -0
- package/dist/utils/quality/placeholder-checker.d.ts +42 -0
- package/dist/utils/quality/punctuation-checker.d.ts +31 -0
- package/dist/utils/quality/quote-balance-checker.d.ts +37 -0
- package/dist/utils/quality/special-characters-checker.d.ts +66 -0
- package/dist/utils/quality/style-guide-checker.d.ts +71 -0
- package/dist/utils/quality/text-sanitizer.d.ts +51 -0
- package/dist/utils/quality/tone-verifier.d.ts +14 -0
- package/dist/utils/rate-limiter.d.ts +73 -0
- package/dist/utils/rate-limiter.js +6 -0
- package/dist/utils/retry-helper.d.ts +49 -0
- package/dist/utils/state-manager.d.ts +62 -0
- package/dist/utils/statistics-manager.d.ts +47 -0
- package/dist/utils/ui-manager.d.ts +21 -0
- package/package.json +13 -5
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import BaseProvider, { ProviderConfig, TranslateOptions } from "./base-provider.js";
|
|
2
|
+
/**
|
|
3
|
+
* Provider implementation for OpenAI (GPT) models.
|
|
4
|
+
*/
|
|
5
|
+
declare class OpenAIProvider extends BaseProvider {
|
|
6
|
+
private client;
|
|
7
|
+
/**
|
|
8
|
+
* Create a new OpenAIProvider instance.
|
|
9
|
+
* @param {ProviderConfig} config - Provider configuration.
|
|
10
|
+
*/
|
|
11
|
+
constructor(config?: ProviderConfig);
|
|
12
|
+
getApiKey(): string | undefined;
|
|
13
|
+
getEndpoint(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Translate text using OpenAI.
|
|
16
|
+
*/
|
|
17
|
+
translate(text: string, sourceLang: string, targetLang: string, options?: TranslateOptions): Promise<string>;
|
|
18
|
+
analyze(prompt: string, options?: ProviderConfig): Promise<string>;
|
|
19
|
+
chat(messages: any[], options?: ProviderConfig): Promise<string>;
|
|
20
|
+
embed(text: string, options?: ProviderConfig): Promise<number[]>;
|
|
21
|
+
embedBatch(texts: string[], options?: ProviderConfig): Promise<number[][]>;
|
|
22
|
+
}
|
|
23
|
+
declare function translate(text: string, sourceLang: string, targetLang: string, options?: TranslateOptions): Promise<string>;
|
|
24
|
+
declare function analyze(prompt: string, options?: ProviderConfig): Promise<string>;
|
|
25
|
+
declare function chat(messages: any[], options?: ProviderConfig): Promise<string>;
|
|
26
|
+
declare function embed(text: string, options?: ProviderConfig): Promise<number[]>;
|
|
27
|
+
declare function embedBatch(texts: string[], options?: ProviderConfig): Promise<number[][]>;
|
|
28
|
+
export { translate, analyze, chat, embed, embedBatch, OpenAIProvider };
|
package/dist/providers/openai.js
CHANGED
|
@@ -40,7 +40,7 @@ class OpenAIProvider extends BaseProvider {
|
|
|
40
40
|
return RetryHelper.withRetry(async () => {
|
|
41
41
|
try {
|
|
42
42
|
const response = await this.client.post(this.getEndpoint(), {
|
|
43
|
-
model: config.model || "gpt-
|
|
43
|
+
model: config.model || "gpt-5.2-chat-latest",
|
|
44
44
|
...promptData,
|
|
45
45
|
temperature: config.temperature,
|
|
46
46
|
max_completion_tokens: config.maxTokens || config.max_tokens,
|
|
@@ -65,7 +65,7 @@ class OpenAIProvider extends BaseProvider {
|
|
|
65
65
|
}
|
|
66
66
|
async analyze(prompt, options = {}) {
|
|
67
67
|
const config = this.getConfig({
|
|
68
|
-
model: options.model || "gpt-
|
|
68
|
+
model: options.model || "gpt-5.2-chat-latest",
|
|
69
69
|
temperature: options.temperature || 0.2,
|
|
70
70
|
maxTokens: options.maxTokens || 1000,
|
|
71
71
|
});
|
|
@@ -94,7 +94,7 @@ class OpenAIProvider extends BaseProvider {
|
|
|
94
94
|
}
|
|
95
95
|
async chat(messages, options = {}) {
|
|
96
96
|
const config = this.getConfig({
|
|
97
|
-
model: options.model || "gpt-
|
|
97
|
+
model: options.model || "gpt-5.2-chat-latest",
|
|
98
98
|
temperature: options.temperature || 0.3,
|
|
99
99
|
maxTokens: options.maxTokens || 2000,
|
|
100
100
|
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import BaseProvider, { ProviderConfig, TranslateOptions } from "./base-provider.js";
|
|
2
|
+
/**
|
|
3
|
+
* Provider implementation for X.AI (Grok) models.
|
|
4
|
+
*/
|
|
5
|
+
declare class XAIProvider extends BaseProvider {
|
|
6
|
+
private client;
|
|
7
|
+
/**
|
|
8
|
+
* Create a new XAIProvider instance.
|
|
9
|
+
* @param {ProviderConfig} config - Provider configuration.
|
|
10
|
+
*/
|
|
11
|
+
constructor(config?: ProviderConfig);
|
|
12
|
+
getApiKey(): string | undefined;
|
|
13
|
+
getEndpoint(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Translate text using X.AI.
|
|
16
|
+
*/
|
|
17
|
+
translate(text: string, sourceLang: string, targetLang: string, options?: TranslateOptions): Promise<string>;
|
|
18
|
+
analyze(prompt: string, options?: ProviderConfig): Promise<string>;
|
|
19
|
+
}
|
|
20
|
+
declare function translate(text: string, sourceLang: string, targetLang: string, options?: TranslateOptions): Promise<string>;
|
|
21
|
+
declare function analyze(prompt: string, options?: ProviderConfig): Promise<string>;
|
|
22
|
+
export { translate, analyze, XAIProvider };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for embedding providers
|
|
3
|
+
*/
|
|
4
|
+
export interface IEmbeddingProvider {
|
|
5
|
+
getEmbedding(text: string): Promise<number[]>;
|
|
6
|
+
getEmbeddings(texts: string[]): Promise<number[][]>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Service to generate embeddings for text
|
|
10
|
+
*/
|
|
11
|
+
export declare class EmbeddingProvider implements IEmbeddingProvider {
|
|
12
|
+
private provider;
|
|
13
|
+
private model;
|
|
14
|
+
constructor(config?: {
|
|
15
|
+
provider?: string;
|
|
16
|
+
model?: string;
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Get embedding for a single text
|
|
20
|
+
*/
|
|
21
|
+
getEmbedding(text: string): Promise<number[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Get embeddings for multiple texts (batch)
|
|
24
|
+
*/
|
|
25
|
+
getEmbeddings(texts: string[]): Promise<number[][]>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import Orchestrator from "../core/orchestrator.js";
|
|
2
|
+
import { OrchestratorOptions } from "../core/orchestrator.js";
|
|
3
|
+
import StateManager from "../utils/state-manager.js";
|
|
4
|
+
export interface TranslationOptions extends OrchestratorOptions {
|
|
5
|
+
source: string;
|
|
6
|
+
targets?: string[];
|
|
7
|
+
localesDir?: string;
|
|
8
|
+
debug?: boolean;
|
|
9
|
+
forceUpdate?: boolean;
|
|
10
|
+
syncOptions?: {
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
removeDeletedKeys?: boolean;
|
|
13
|
+
};
|
|
14
|
+
concurrencyLimit?: number;
|
|
15
|
+
saveReviewQueue?: boolean;
|
|
16
|
+
minConfidence?: number;
|
|
17
|
+
fileExtensions?: string[];
|
|
18
|
+
}
|
|
19
|
+
export interface GlobalStats {
|
|
20
|
+
total: number;
|
|
21
|
+
success: number;
|
|
22
|
+
failed: number;
|
|
23
|
+
skipped: number;
|
|
24
|
+
languages: Record<string, any>;
|
|
25
|
+
byCategory: Record<string, number>;
|
|
26
|
+
details: Record<string, {
|
|
27
|
+
totalConfidence: number;
|
|
28
|
+
samples: number;
|
|
29
|
+
}>;
|
|
30
|
+
error?: {
|
|
31
|
+
message: string;
|
|
32
|
+
time: string;
|
|
33
|
+
stack?: string;
|
|
34
|
+
};
|
|
35
|
+
orchestrators: any[];
|
|
36
|
+
endTime?: string;
|
|
37
|
+
totalDuration?: number;
|
|
38
|
+
totalTime: number;
|
|
39
|
+
startTime: string;
|
|
40
|
+
}
|
|
41
|
+
interface LanguageProcessResult {
|
|
42
|
+
status: any;
|
|
43
|
+
savedMessage?: string;
|
|
44
|
+
error?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Service for handling file translation operations.
|
|
48
|
+
* Orchestrates the translation process including state management,
|
|
49
|
+
* verification, and statistics collection.
|
|
50
|
+
*/
|
|
51
|
+
declare class TranslationService {
|
|
52
|
+
/**
|
|
53
|
+
* Check if text only contains placeholders and whitespace.
|
|
54
|
+
* @param {string} text - Text to check.
|
|
55
|
+
* @returns {boolean} - True if text only contains placeholders.
|
|
56
|
+
*/
|
|
57
|
+
isPlaceholderOnlyText(text: string): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Main translator function to process source file and create translations.
|
|
60
|
+
* @param {string} file - Path to source file.
|
|
61
|
+
* @param {TranslationOptions} options - Translation options.
|
|
62
|
+
* @returns {Promise<GlobalStats>} - Global statistics object.
|
|
63
|
+
* @throws {Error} If validation fails or translation process errors.
|
|
64
|
+
*/
|
|
65
|
+
translateFile(file: string, options: TranslationOptions): Promise<GlobalStats>;
|
|
66
|
+
/**
|
|
67
|
+
* Validate input parameters for translation process.
|
|
68
|
+
* @param {string} file - Path to source file.
|
|
69
|
+
* @param {TranslationOptions} options - Translation options.
|
|
70
|
+
* @returns {Promise<string>} - Resolved absolute path to source file.
|
|
71
|
+
* @throws {Error} If inputs are invalid.
|
|
72
|
+
*/
|
|
73
|
+
validateTranslationInputs(file: string, options: TranslationOptions): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Initialize translation state and sync analysis.
|
|
76
|
+
* @param {string} resolvedFile - Path to resolved source file.
|
|
77
|
+
* @param {Record<string, any>} flattenedSource - Flattened source content.
|
|
78
|
+
* @param {TranslationOptions} options - Translation options.
|
|
79
|
+
* @returns {Promise<Object>} - Initialized state components.
|
|
80
|
+
*/
|
|
81
|
+
initializeTranslationState(resolvedFile: string, flattenedSource: Record<string, any>, options: TranslationOptions): Promise<{
|
|
82
|
+
stateManager: StateManager;
|
|
83
|
+
projectRoot: string;
|
|
84
|
+
currentState: Record<string, string>;
|
|
85
|
+
comparison: import("../utils/state-manager.js").StateComparison;
|
|
86
|
+
}>;
|
|
87
|
+
/**
|
|
88
|
+
* Process all target languages with concurrency.
|
|
89
|
+
* @param {string} resolvedFile - Path to source file.
|
|
90
|
+
* @param {Record<string, any>} flattenedSource - Flattened source content.
|
|
91
|
+
* @param {TranslationOptions} options - Translation options.
|
|
92
|
+
* @param {GlobalStats} globalStats - Global statistics object to update.
|
|
93
|
+
* @param {any} comparison - State comparison result.
|
|
94
|
+
*/
|
|
95
|
+
processAllLanguages(resolvedFile: string, flattenedSource: Record<string, any>, options: TranslationOptions, globalStats: GlobalStats, comparison: any): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Process a single language translation.
|
|
98
|
+
* @param {string} targetLang - Target language code.
|
|
99
|
+
* @param {string} sourceFile - Path to source file.
|
|
100
|
+
* @param {Record<string, any>} flattenedSource - Flattened source content.
|
|
101
|
+
* @param {Orchestrator} orchestrator - Orchestrator instance.
|
|
102
|
+
* @param {TranslationOptions} options - Translation options.
|
|
103
|
+
* @param {GlobalStats} globalStats - Global statistics object.
|
|
104
|
+
* @param {any} comparison - State comparison result.
|
|
105
|
+
* @returns {Promise<LanguageProcessResult>} - Status and messages for this language.
|
|
106
|
+
*/
|
|
107
|
+
processLanguage(targetLang: string, sourceFile: string, flattenedSource: Record<string, any>, orchestrator: Orchestrator, options: TranslationOptions, globalStats: GlobalStats, comparison: any): Promise<LanguageProcessResult>;
|
|
108
|
+
/**
|
|
109
|
+
* Finalize translation process and save state.
|
|
110
|
+
* @param {StateManager} stateManager - State manager instance.
|
|
111
|
+
* @param {string} projectRoot - Project root directory.
|
|
112
|
+
* @param {any} currentState - Current state object.
|
|
113
|
+
* @param {GlobalStats} globalStats - Global statistics object.
|
|
114
|
+
* @param {number} startTime - Process start timestamp.
|
|
115
|
+
* @param {TranslationOptions} options - Translation options.
|
|
116
|
+
*/
|
|
117
|
+
finalizeTranslation(stateManager: StateManager, projectRoot: string, currentState: any, globalStats: GlobalStats, startTime: number, options: TranslationOptions): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* Remove deleted keys from all target language files.
|
|
120
|
+
* @param {string} sourceFile - Path to source file.
|
|
121
|
+
* @param {string[]} deletedKeys - Array of keys to delete.
|
|
122
|
+
* @param {TranslationOptions} options - Translation options.
|
|
123
|
+
*/
|
|
124
|
+
removeDeletedKeysFromTargets(sourceFile: string, deletedKeys: string[], options: TranslationOptions): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Validate and fix existing translations that have length issues.
|
|
127
|
+
* @param {string} file - Path to source file.
|
|
128
|
+
* @param {TranslationOptions} options - Translation options.
|
|
129
|
+
* @throws {Error} If validation process fails.
|
|
130
|
+
*/
|
|
131
|
+
validateAndFixExistingTranslations(file: string, options: TranslationOptions): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Find locale files
|
|
134
|
+
*/
|
|
135
|
+
findLocaleFiles(localesDir: string, sourceLang: string): Promise<string[]>;
|
|
136
|
+
}
|
|
137
|
+
declare const _default: TranslationService;
|
|
138
|
+
export default _default;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface VectorStoreConfig {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
vectorDbPath: string;
|
|
4
|
+
similarityThreshold?: number;
|
|
5
|
+
exactMatchThreshold?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface SearchResult {
|
|
8
|
+
item: {
|
|
9
|
+
text: string;
|
|
10
|
+
translation: string;
|
|
11
|
+
sourceLang: string;
|
|
12
|
+
targetLang: string;
|
|
13
|
+
metadata?: any;
|
|
14
|
+
};
|
|
15
|
+
score: number;
|
|
16
|
+
}
|
|
17
|
+
export declare class VectorStore {
|
|
18
|
+
private index;
|
|
19
|
+
private config;
|
|
20
|
+
private initialized;
|
|
21
|
+
private readonly DIMENSION;
|
|
22
|
+
constructor(config: VectorStoreConfig);
|
|
23
|
+
initialize(): Promise<void>;
|
|
24
|
+
addItem(text: string, translation: string, sourceLang: string, targetLang: string, embedding: number[], metadata?: any): Promise<void>;
|
|
25
|
+
search(embedding: number[], targetLang: string, limit?: number): Promise<SearchResult[]>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export interface AnalysisResult {
|
|
2
|
+
category: string;
|
|
3
|
+
confidence: number;
|
|
4
|
+
keywords: string[];
|
|
5
|
+
explanation: string;
|
|
6
|
+
prompt: string;
|
|
7
|
+
method?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ContextConfig {
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
useAI?: boolean;
|
|
12
|
+
minTextLength?: number;
|
|
13
|
+
cacheSize?: number;
|
|
14
|
+
cacheTTL?: number;
|
|
15
|
+
categories?: Record<string, any>;
|
|
16
|
+
detection?: {
|
|
17
|
+
threshold?: number;
|
|
18
|
+
minConfidence?: number;
|
|
19
|
+
};
|
|
20
|
+
allowNewCategories?: boolean;
|
|
21
|
+
fallback?: {
|
|
22
|
+
category?: string;
|
|
23
|
+
prompt?: string;
|
|
24
|
+
};
|
|
25
|
+
analysisOptions?: {
|
|
26
|
+
maxTokens?: number;
|
|
27
|
+
timeout?: number;
|
|
28
|
+
retries?: number;
|
|
29
|
+
};
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
}
|
|
32
|
+
export interface Stats {
|
|
33
|
+
totalAnalyzed: number;
|
|
34
|
+
aiCalls: number;
|
|
35
|
+
cacheHits: number;
|
|
36
|
+
keywordMatches: number;
|
|
37
|
+
newCategories: number;
|
|
38
|
+
errors: number;
|
|
39
|
+
}
|
|
40
|
+
declare class AIContextAnalyzer {
|
|
41
|
+
private config;
|
|
42
|
+
private cache;
|
|
43
|
+
private categoryKeywords;
|
|
44
|
+
private stats;
|
|
45
|
+
constructor(config: ContextConfig);
|
|
46
|
+
analyzeBatch(texts: (string | null)[], apiProvider?: string): Promise<(AnalysisResult | null)[]>;
|
|
47
|
+
analyzeContext(text: string, apiProvider?: string): Promise<AnalysisResult | null>;
|
|
48
|
+
_batchAIAnalysis(texts: string[], apiProvider: string): Promise<(AnalysisResult | null)[]>;
|
|
49
|
+
_createBatchAnalysisPrompt(texts: string[]): string;
|
|
50
|
+
_createAnalysisPrompt(text: string): string;
|
|
51
|
+
_createSimplifiedAnalysisPrompt(text: string): string;
|
|
52
|
+
_parseBatchAnalysisResult(result: string, expectedCount: number): (AnalysisResult | null)[];
|
|
53
|
+
_parseAnalysisResult(result: string): AnalysisResult | null;
|
|
54
|
+
_fastKeywordMatch(text: string): AnalysisResult | null;
|
|
55
|
+
_getDefaultContext(): AnalysisResult;
|
|
56
|
+
_findClosestCategory(suggestedCategory: string, keywords: string[]): string;
|
|
57
|
+
_saveNewCategory(category: string, keywords: string[]): void;
|
|
58
|
+
/**
|
|
59
|
+
* Generate a collision-resistant cache key for text
|
|
60
|
+
*/
|
|
61
|
+
_getCacheKey(text: string): string;
|
|
62
|
+
getStats(): Stats & {
|
|
63
|
+
cacheSize: number;
|
|
64
|
+
cacheCapacity: number;
|
|
65
|
+
hitRate: number;
|
|
66
|
+
aiUsageRate: number;
|
|
67
|
+
keywordMatchRate: number;
|
|
68
|
+
errorRate: number;
|
|
69
|
+
};
|
|
70
|
+
resetStats(): void;
|
|
71
|
+
clearCache(): void;
|
|
72
|
+
}
|
|
73
|
+
export default AIContextAnalyzer;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quality Confidence Scoring System
|
|
3
|
+
* Calculates confidence scores for translations based on AI response and quality checks
|
|
4
|
+
*/
|
|
5
|
+
export interface ConfidenceIssue {
|
|
6
|
+
type: string;
|
|
7
|
+
severity: "critical" | "warning" | "error";
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ConfidenceOptions {
|
|
11
|
+
aiConfidence?: number;
|
|
12
|
+
sourceText: string;
|
|
13
|
+
translation: string;
|
|
14
|
+
sourceLang: string;
|
|
15
|
+
targetLang: string;
|
|
16
|
+
provider: string;
|
|
17
|
+
category?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ConfidenceResult {
|
|
20
|
+
score: number;
|
|
21
|
+
level: "high" | "medium" | "low" | "very_low";
|
|
22
|
+
aiConfidence: number;
|
|
23
|
+
qualityScore: number;
|
|
24
|
+
details: {
|
|
25
|
+
categoryAdjustment: number;
|
|
26
|
+
languageFactor: number;
|
|
27
|
+
providerReliability: number;
|
|
28
|
+
};
|
|
29
|
+
issues: ConfidenceIssue[];
|
|
30
|
+
needsReview: boolean;
|
|
31
|
+
autoApprove: boolean;
|
|
32
|
+
}
|
|
33
|
+
declare class ConfidenceScorer {
|
|
34
|
+
/**
|
|
35
|
+
* Calculate final confidence score
|
|
36
|
+
* @param {ConfidenceOptions} options
|
|
37
|
+
* @returns {ConfidenceResult} { score, details, issues }
|
|
38
|
+
*/
|
|
39
|
+
static calculateConfidence(options: ConfidenceOptions): ConfidenceResult;
|
|
40
|
+
/**
|
|
41
|
+
* Calculate quality score based on internal checks
|
|
42
|
+
*/
|
|
43
|
+
private static _calculateQualityScore;
|
|
44
|
+
/**
|
|
45
|
+
* Get category-specific adjustment
|
|
46
|
+
*/
|
|
47
|
+
private static _getCategoryAdjustment;
|
|
48
|
+
/**
|
|
49
|
+
* Get language pair complexity factor
|
|
50
|
+
*/
|
|
51
|
+
private static _getLanguagePairFactor;
|
|
52
|
+
/**
|
|
53
|
+
* Get provider reliability for specific tasks
|
|
54
|
+
*/
|
|
55
|
+
private static _getProviderReliability;
|
|
56
|
+
/**
|
|
57
|
+
* Determine confidence level from score
|
|
58
|
+
*/
|
|
59
|
+
private static _getConfidenceLevel;
|
|
60
|
+
/**
|
|
61
|
+
* Detect specific issues with translation
|
|
62
|
+
*/
|
|
63
|
+
private static _detectIssues;
|
|
64
|
+
/**
|
|
65
|
+
* Get confidence color for terminal display
|
|
66
|
+
*/
|
|
67
|
+
static getConfidenceColor(score: number): string;
|
|
68
|
+
/**
|
|
69
|
+
* Format confidence for display
|
|
70
|
+
*/
|
|
71
|
+
static formatConfidence(score: number): string;
|
|
72
|
+
/**
|
|
73
|
+
* Extract AI confidence from provider response
|
|
74
|
+
*/
|
|
75
|
+
static extractAIConfidence(response: any, provider: string): number;
|
|
76
|
+
}
|
|
77
|
+
export default ConfidenceScorer;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized Error Handling System
|
|
3
|
+
* Provides detailed, actionable error messages with context and solutions
|
|
4
|
+
*/
|
|
5
|
+
export interface HelperError extends Error {
|
|
6
|
+
code?: string;
|
|
7
|
+
type?: string;
|
|
8
|
+
details?: Record<string, any>;
|
|
9
|
+
solutions?: string[];
|
|
10
|
+
context?: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface ErrorDetails {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
declare class ErrorHelper {
|
|
16
|
+
static ErrorCodes: {
|
|
17
|
+
API_RATE_LIMIT: string;
|
|
18
|
+
API_AUTH_FAILED: string;
|
|
19
|
+
API_SERVER_ERROR: string;
|
|
20
|
+
API_NETWORK: string;
|
|
21
|
+
API_TIMEOUT: string;
|
|
22
|
+
API_INVALID_KEY: string;
|
|
23
|
+
API_QUOTA_EXCEEDED: string;
|
|
24
|
+
API_RESPONSE_ERROR: string;
|
|
25
|
+
CONFIG_NOT_FOUND: string;
|
|
26
|
+
CONFIG_INVALID: string;
|
|
27
|
+
CONFIG_VALIDATION: string;
|
|
28
|
+
CONFIG_MISSING_FIELD: string;
|
|
29
|
+
FILE_NOT_FOUND: string;
|
|
30
|
+
FILE_READ_ERROR: string;
|
|
31
|
+
FILE_WRITE_ERROR: string;
|
|
32
|
+
FILE_PERMISSION: string;
|
|
33
|
+
VALIDATION_LANGUAGE: string;
|
|
34
|
+
VALIDATION_TEXT: string;
|
|
35
|
+
VALIDATION_PROVIDER: string;
|
|
36
|
+
VALIDATION_CONCURRENCY: string;
|
|
37
|
+
TRANSLATION_FAILED: string;
|
|
38
|
+
TRANSLATION_QUALITY: string;
|
|
39
|
+
TRANSLATION_TIMEOUT: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Create a detailed error with context and solutions
|
|
43
|
+
*/
|
|
44
|
+
static createError(type: string, details?: ErrorDetails): HelperError;
|
|
45
|
+
/**
|
|
46
|
+
* Format error for display
|
|
47
|
+
*/
|
|
48
|
+
static formatError(error: HelperError, options?: {
|
|
49
|
+
showDebug?: boolean;
|
|
50
|
+
showSolutions?: boolean;
|
|
51
|
+
showContext?: boolean;
|
|
52
|
+
}): string;
|
|
53
|
+
/**
|
|
54
|
+
* Get error information based on type
|
|
55
|
+
*/
|
|
56
|
+
private static _getErrorInfo;
|
|
57
|
+
/**
|
|
58
|
+
* Build rate limit message with details
|
|
59
|
+
*/
|
|
60
|
+
private static _buildRateLimitMessage;
|
|
61
|
+
/**
|
|
62
|
+
* Get environment variable name for provider
|
|
63
|
+
*/
|
|
64
|
+
private static _getEnvKeyName;
|
|
65
|
+
/**
|
|
66
|
+
* Get provider console URL
|
|
67
|
+
*/
|
|
68
|
+
private static _getProviderConsoleUrl;
|
|
69
|
+
/**
|
|
70
|
+
* Suggest fallback provider
|
|
71
|
+
*/
|
|
72
|
+
private static _suggestFallbackProvider;
|
|
73
|
+
/**
|
|
74
|
+
* Quick error creators for common cases
|
|
75
|
+
*/
|
|
76
|
+
static rateLimitError(provider: string, details?: ErrorDetails): HelperError;
|
|
77
|
+
static authError(provider: string, statusCode?: number | string, apiMessage?: string): HelperError;
|
|
78
|
+
static serverError(provider: string, statusCode?: number | string, apiMessage?: string): HelperError;
|
|
79
|
+
static networkError(provider: string): HelperError;
|
|
80
|
+
static timeoutError(provider: string, timeout?: number): HelperError;
|
|
81
|
+
static configNotFoundError(): HelperError;
|
|
82
|
+
static configValidationError(validationErrors: string[]): HelperError;
|
|
83
|
+
static fileNotFoundError(filePath: string, expectedSource?: string): HelperError;
|
|
84
|
+
static translationError(key: string, language: string, reason?: string): HelperError;
|
|
85
|
+
static languageValidationError(langCode: string, field?: string): HelperError;
|
|
86
|
+
}
|
|
87
|
+
export default ErrorHelper;
|
|
@@ -321,6 +321,7 @@ class ErrorHelper {
|
|
|
321
321
|
deepseek: "DEEPSEEK_API_KEY",
|
|
322
322
|
dashscope: "DASHSCOPE_API_KEY",
|
|
323
323
|
xai: "XAI_API_KEY",
|
|
324
|
+
anthropic: "ANTHROPIC_API_KEY",
|
|
324
325
|
};
|
|
325
326
|
return envMap[provider?.toLowerCase()] || `${provider?.toUpperCase()}_API_KEY`;
|
|
326
327
|
}
|
|
@@ -334,6 +335,7 @@ class ErrorHelper {
|
|
|
334
335
|
deepseek: "https://platform.deepseek.com/api-keys",
|
|
335
336
|
dashscope: "https://dashscope.console.aliyun.com/",
|
|
336
337
|
xai: "https://console.x.ai/",
|
|
338
|
+
anthropic: "https://console.anthropic.com/settings/keys",
|
|
337
339
|
};
|
|
338
340
|
return urlMap[provider?.toLowerCase()] || "provider console";
|
|
339
341
|
}
|
|
@@ -341,7 +343,7 @@ class ErrorHelper {
|
|
|
341
343
|
* Suggest fallback provider
|
|
342
344
|
*/
|
|
343
345
|
static _suggestFallbackProvider(currentProvider) {
|
|
344
|
-
const fallbackOrder = ["openai", "gemini", "deepseek", "dashscope", "xai"];
|
|
346
|
+
const fallbackOrder = ["openai", "anthropic", "gemini", "deepseek", "dashscope", "xai"];
|
|
345
347
|
const current = currentProvider?.toLowerCase();
|
|
346
348
|
const index = fallbackOrder.indexOf(current);
|
|
347
349
|
if (index === -1 || index === fallbackOrder.length - 1) {
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
export interface FileOptions {
|
|
2
|
+
atomic?: boolean;
|
|
3
|
+
createMissingDirs?: boolean;
|
|
4
|
+
backupFiles?: boolean;
|
|
5
|
+
backupDir?: string;
|
|
6
|
+
encoding?: BufferEncoding;
|
|
7
|
+
jsonIndent?: number;
|
|
8
|
+
compact?: boolean;
|
|
9
|
+
indent?: number;
|
|
10
|
+
format?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ValidationResult {
|
|
13
|
+
valid: boolean;
|
|
14
|
+
filePath?: string;
|
|
15
|
+
error?: string;
|
|
16
|
+
position?: {
|
|
17
|
+
position: number | null;
|
|
18
|
+
line: number | null;
|
|
19
|
+
} | null;
|
|
20
|
+
key?: string;
|
|
21
|
+
value?: any;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* FileManager - Modern asynchronous file operations
|
|
25
|
+
* Handles multiple file formats via Adapter pattern.
|
|
26
|
+
*/
|
|
27
|
+
declare class FileManager {
|
|
28
|
+
/**
|
|
29
|
+
* Default options for file operations
|
|
30
|
+
*/
|
|
31
|
+
static defaultOptions: Required<Omit<FileOptions, "compact" | "indent" | "format">>;
|
|
32
|
+
private static options;
|
|
33
|
+
/**
|
|
34
|
+
* Configure global options for file operations
|
|
35
|
+
* @param options - File operation options
|
|
36
|
+
*/
|
|
37
|
+
static configure(options: FileOptions): void;
|
|
38
|
+
/**
|
|
39
|
+
* Get current configuration
|
|
40
|
+
* @returns Current configuration
|
|
41
|
+
*/
|
|
42
|
+
static getConfig(): FileOptions;
|
|
43
|
+
/**
|
|
44
|
+
* Find locale files in the specified directory
|
|
45
|
+
* @param localesDir - Directory containing locale files
|
|
46
|
+
* @param sourceLang - Source language code
|
|
47
|
+
* @returns Array of file paths
|
|
48
|
+
*/
|
|
49
|
+
static findLocaleFiles(localesDir: string, sourceLang: string): Promise<string[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Read structured data file asynchronously (JSON, YAML, etc.)
|
|
52
|
+
* @param filePath - Path to the file
|
|
53
|
+
* @param options - Options for reading
|
|
54
|
+
* @returns Parsed data
|
|
55
|
+
*/
|
|
56
|
+
static readFile(filePath: string, options?: FileOptions): Promise<any>;
|
|
57
|
+
/**
|
|
58
|
+
* Write data to file asynchronously
|
|
59
|
+
* @param filePath - Path to write the file
|
|
60
|
+
* @param data - Data to write
|
|
61
|
+
* @param options - Options for writing
|
|
62
|
+
* @returns Success status
|
|
63
|
+
*/
|
|
64
|
+
static writeFile(filePath: string, data: any, options?: FileOptions): Promise<boolean>;
|
|
65
|
+
static readJSON(filePath: string, options?: FileOptions): Promise<any>;
|
|
66
|
+
static writeJSON(filePath: string, data: any, options?: FileOptions): Promise<boolean>;
|
|
67
|
+
/**
|
|
68
|
+
* Generate a unique temporary file path
|
|
69
|
+
*/
|
|
70
|
+
static _generateTempFilePath(filePath: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Ensure directory exists
|
|
73
|
+
*/
|
|
74
|
+
static ensureDir(dir: string): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Scan for locale files
|
|
77
|
+
*/
|
|
78
|
+
static scanLocaleFiles(localesDir: string, pattern?: RegExp): Promise<string[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Get file modification time
|
|
81
|
+
*/
|
|
82
|
+
static getModifiedTime(filePath: string): Promise<Date>;
|
|
83
|
+
/**
|
|
84
|
+
* Check if file exists
|
|
85
|
+
*/
|
|
86
|
+
static exists(filePath: string): Promise<boolean>;
|
|
87
|
+
/**
|
|
88
|
+
* Delete file
|
|
89
|
+
* @param filePath - Path to the file
|
|
90
|
+
* @param options - Options for deletion
|
|
91
|
+
* @returns Success status
|
|
92
|
+
*/
|
|
93
|
+
static deleteFile(filePath: string, options?: FileOptions): Promise<boolean>;
|
|
94
|
+
/**
|
|
95
|
+
* Validate JSON file structure
|
|
96
|
+
* @param filePath - Path to the JSON file
|
|
97
|
+
* @returns Validation result
|
|
98
|
+
*/
|
|
99
|
+
static validateJSONFile(filePath: string): Promise<ValidationResult>;
|
|
100
|
+
/**
|
|
101
|
+
* Extract error position from JSON parse error
|
|
102
|
+
* @param error - JSON parse error
|
|
103
|
+
* @returns Error position details
|
|
104
|
+
*/
|
|
105
|
+
static _extractErrorPosition(error: any): {
|
|
106
|
+
position: number | null;
|
|
107
|
+
line: number | null;
|
|
108
|
+
} | null;
|
|
109
|
+
/**
|
|
110
|
+
* Validate translation value can be safely added to JSON
|
|
111
|
+
* @param key - Translation key
|
|
112
|
+
* @param value - Translation value
|
|
113
|
+
* @returns Validation result
|
|
114
|
+
*/
|
|
115
|
+
static validateTranslationValue(key: string, value: any): ValidationResult;
|
|
116
|
+
/**
|
|
117
|
+
* List files in a directory
|
|
118
|
+
* @param dirPath - Directory path
|
|
119
|
+
* @returns Array of file paths
|
|
120
|
+
*/
|
|
121
|
+
static listFiles(dirPath: string): Promise<string[]>;
|
|
122
|
+
/**
|
|
123
|
+
* Ensure directory exists, create if it doesn't
|
|
124
|
+
* @param dirPath - Directory path
|
|
125
|
+
* @returns True if directory exists or was created
|
|
126
|
+
*/
|
|
127
|
+
static ensureDirectoryExists(dirPath: string): Promise<boolean>;
|
|
128
|
+
}
|
|
129
|
+
export { FileManager };
|