locai 2.1.2 → 2.1.3
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/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/openai.d.ts +28 -0
- 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/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/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/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/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,29 @@
|
|
|
1
|
+
export interface TranslationResult {
|
|
2
|
+
key: string;
|
|
3
|
+
translated: string | null;
|
|
4
|
+
success: boolean;
|
|
5
|
+
context: Record<string, any>;
|
|
6
|
+
error?: string;
|
|
7
|
+
fromCache?: boolean;
|
|
8
|
+
qualityChecks?: any;
|
|
9
|
+
meta?: Record<string, any>;
|
|
10
|
+
}
|
|
11
|
+
export interface TranslationContext {
|
|
12
|
+
key: string;
|
|
13
|
+
sourceText: string;
|
|
14
|
+
sourceLang: string;
|
|
15
|
+
targetLang: string;
|
|
16
|
+
options: any;
|
|
17
|
+
meta: Record<string, any>;
|
|
18
|
+
existingTranslation: any;
|
|
19
|
+
result: TranslationResult;
|
|
20
|
+
protectedText?: string;
|
|
21
|
+
termMap?: Map<string, any>;
|
|
22
|
+
translatedText?: string;
|
|
23
|
+
success?: boolean;
|
|
24
|
+
error?: string;
|
|
25
|
+
fromCache?: boolean;
|
|
26
|
+
qualityChecks?: any;
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
}
|
|
29
|
+
export declare const createTranslationContext: (key: string, sourceText: string, sourceLang: string, targetLang: string, options: any, meta?: Record<string, any>, existingTranslation?: any) => TranslationContext;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import PipelineStep from "../PipelineStep.js";
|
|
2
|
+
import { TranslationContext } from "../context.js";
|
|
3
|
+
export interface CacheStats {
|
|
4
|
+
hits: number;
|
|
5
|
+
staleHits: number;
|
|
6
|
+
misses: number;
|
|
7
|
+
stored: number;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
export interface Cache {
|
|
11
|
+
has(key: string): boolean;
|
|
12
|
+
get(key: string): any;
|
|
13
|
+
set(key: string, value: any, options?: any): void;
|
|
14
|
+
delete(key: string): void;
|
|
15
|
+
getRemainingTTL?(key: string): number;
|
|
16
|
+
}
|
|
17
|
+
declare class CacheReadStep extends PipelineStep {
|
|
18
|
+
private cache;
|
|
19
|
+
private stats;
|
|
20
|
+
private options;
|
|
21
|
+
constructor(cache: Cache, cacheStats: CacheStats, options?: any);
|
|
22
|
+
execute(context: TranslationContext, next: () => Promise<void>): Promise<void>;
|
|
23
|
+
_generateCacheKey(text: string, targetLang: string, category?: string): string;
|
|
24
|
+
}
|
|
25
|
+
export default CacheReadStep;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import PipelineStep from "../PipelineStep.js";
|
|
2
|
+
import { TranslationContext } from "../context.js";
|
|
3
|
+
import { Cache, CacheStats } from "./CacheReadStep.js";
|
|
4
|
+
declare class CacheWriteStep extends PipelineStep {
|
|
5
|
+
private cache;
|
|
6
|
+
private stats;
|
|
7
|
+
private options;
|
|
8
|
+
constructor(cache: Cache, cacheStats: CacheStats, options?: any);
|
|
9
|
+
execute(context: TranslationContext, next: () => Promise<void>): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export default CacheWriteStep;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import PipelineStep from "../PipelineStep.js";
|
|
2
|
+
import { TranslationContext } from "../context.js";
|
|
3
|
+
import { ConfidenceSettings } from "./TranslationStep.js";
|
|
4
|
+
declare class ConfidenceCheckStep extends PipelineStep {
|
|
5
|
+
private confidenceSettings;
|
|
6
|
+
private debug;
|
|
7
|
+
constructor(confidenceSettings: Partial<ConfidenceSettings>, debug?: boolean);
|
|
8
|
+
execute(context: TranslationContext, next: () => Promise<void>): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export default ConfidenceCheckStep;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import PipelineStep from "../PipelineStep.js";
|
|
2
|
+
import GlossaryManager from "../../../utils/glossary-manager.js";
|
|
3
|
+
import { TranslationContext } from "../context.js";
|
|
4
|
+
declare class GlossaryPostStep extends PipelineStep {
|
|
5
|
+
private glossaryManager?;
|
|
6
|
+
constructor(glossaryManager?: GlossaryManager | null);
|
|
7
|
+
execute(context: TranslationContext, next: () => Promise<void>): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export default GlossaryPostStep;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import PipelineStep from "../PipelineStep.js";
|
|
2
|
+
import GlossaryManager from "../../../utils/glossary-manager.js";
|
|
3
|
+
import { TranslationContext } from "../context.js";
|
|
4
|
+
declare class GlossaryPreStep extends PipelineStep {
|
|
5
|
+
private glossaryManager?;
|
|
6
|
+
constructor(glossaryManager?: GlossaryManager | null);
|
|
7
|
+
execute(context: TranslationContext, next: () => Promise<void>): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export default GlossaryPreStep;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import PipelineStep from "../PipelineStep.js";
|
|
2
|
+
import { TranslationContext } from "../context.js";
|
|
3
|
+
declare class InputValidationStep extends PipelineStep {
|
|
4
|
+
private maxKeyLength;
|
|
5
|
+
constructor(maxKeyLength?: number);
|
|
6
|
+
execute(context: TranslationContext, next: () => Promise<void>): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export default InputValidationStep;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import PipelineStep from "../PipelineStep.js";
|
|
2
|
+
import { TranslationContext } from "../context.js";
|
|
3
|
+
import QualityChecker from "../../../utils/quality/index.js";
|
|
4
|
+
declare class QualityCheckStep extends PipelineStep {
|
|
5
|
+
private qualityChecker;
|
|
6
|
+
private debug;
|
|
7
|
+
constructor(qualityChecker: QualityChecker | any, debug?: boolean);
|
|
8
|
+
execute(context: TranslationContext, next: () => Promise<void>): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export default QualityCheckStep;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import PipelineStep from "../PipelineStep.js";
|
|
2
|
+
import { TranslationContext } from "../context.js";
|
|
3
|
+
export declare class ToneCheckStep extends PipelineStep {
|
|
4
|
+
private verifier;
|
|
5
|
+
private enabled;
|
|
6
|
+
private debug;
|
|
7
|
+
constructor(config?: {
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
});
|
|
11
|
+
execute(context: TranslationContext, next: () => Promise<void>): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export default ToneCheckStep;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import PipelineStep from "../PipelineStep.js";
|
|
2
|
+
import { AIProvider } from "../../provider-factory.js";
|
|
3
|
+
import { TranslationContext } from "../context.js";
|
|
4
|
+
export interface ConfidenceSettings {
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
autoApproveThreshold: number;
|
|
7
|
+
rejectThreshold: number;
|
|
8
|
+
reviewThreshold: number;
|
|
9
|
+
saveReviewQueue: boolean;
|
|
10
|
+
reviewQueue: any[];
|
|
11
|
+
autoApprovedCount: number;
|
|
12
|
+
rejectedCount: number;
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
declare class TranslationStep extends PipelineStep {
|
|
16
|
+
private options;
|
|
17
|
+
private confidenceSettings;
|
|
18
|
+
constructor(options?: any, confidenceSettings?: Partial<ConfidenceSettings>);
|
|
19
|
+
execute(context: TranslationContext, next: () => Promise<void>): Promise<void>;
|
|
20
|
+
_getProvider(): AIProvider;
|
|
21
|
+
}
|
|
22
|
+
export default TranslationStep;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import PipelineStep from "../PipelineStep.js";
|
|
2
|
+
import { TranslationContext } from "../context.js";
|
|
3
|
+
import { VectorStore } from "../../../services/vector-store.js";
|
|
4
|
+
import { EmbeddingProvider } from "../../../services/embedding-provider.js";
|
|
5
|
+
export interface VectorMemoryStats {
|
|
6
|
+
hits: number;
|
|
7
|
+
contextUsed: number;
|
|
8
|
+
misses: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class VectorCacheReadStep extends PipelineStep {
|
|
11
|
+
private vectorStore;
|
|
12
|
+
private embeddingProvider;
|
|
13
|
+
private stats;
|
|
14
|
+
private options;
|
|
15
|
+
constructor(vectorStore: VectorStore, embeddingProvider: EmbeddingProvider, stats: VectorMemoryStats, options?: any);
|
|
16
|
+
execute(context: TranslationContext, next: () => Promise<void>): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import PipelineStep from "../PipelineStep.js";
|
|
2
|
+
import { TranslationContext } from "../context.js";
|
|
3
|
+
import { VectorStore } from "../../../services/vector-store.js";
|
|
4
|
+
import { EmbeddingProvider } from "../../../services/embedding-provider.js";
|
|
5
|
+
export declare class VectorCacheWriteStep extends PipelineStep {
|
|
6
|
+
private vectorStore;
|
|
7
|
+
private embeddingProvider;
|
|
8
|
+
private options;
|
|
9
|
+
constructor(vectorStore: VectorStore, embeddingProvider: EmbeddingProvider, options?: any);
|
|
10
|
+
execute(context: TranslationContext, next: () => Promise<void>): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ProviderConfig, TranslateOptions } from "../providers/base-provider.js";
|
|
2
|
+
export interface AIProvider {
|
|
3
|
+
translate(text: string, sourceLang: string, targetLang: string, options?: TranslateOptions): Promise<string>;
|
|
4
|
+
analyze?(prompt: string, options?: ProviderConfig): Promise<string>;
|
|
5
|
+
chat?(messages: any[], options?: ProviderConfig): Promise<string>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Factory for creating and managing AI providers.
|
|
9
|
+
* Handles provider instantiation, configuration, and fallback chains.
|
|
10
|
+
*/
|
|
11
|
+
declare class ProviderFactory {
|
|
12
|
+
/**
|
|
13
|
+
* Get provider instance with intelligent fallback support.
|
|
14
|
+
* @param {string} providerName - Name of the primary provider.
|
|
15
|
+
* @param {boolean} [useFallback=true] - Whether to use fallback chain on failure.
|
|
16
|
+
* @param {Object} [config=null] - Optional configuration overrides.
|
|
17
|
+
* @returns {AIProvider} - Provider instance or wrapped FallbackProvider.
|
|
18
|
+
* @throws {Error} If provider is not found or configured.
|
|
19
|
+
*/
|
|
20
|
+
static getProvider(providerName: string, useFallback?: boolean, config?: {
|
|
21
|
+
fallbackOrder?: string[];
|
|
22
|
+
} | null): AIProvider;
|
|
23
|
+
/**
|
|
24
|
+
* Get list of available (configured) providers.
|
|
25
|
+
* @returns {string[]} - Array of provider names with valid API keys.
|
|
26
|
+
*/
|
|
27
|
+
static getAvailableProviders(): string[];
|
|
28
|
+
/**
|
|
29
|
+
* Validate that at least one provider is configured.
|
|
30
|
+
* @returns {string[]} - Array of available providers.
|
|
31
|
+
* @throws {Error} If no providers are configured.
|
|
32
|
+
*/
|
|
33
|
+
static validateProviders(): string[];
|
|
34
|
+
/**
|
|
35
|
+
* Check if a specific provider is configured.
|
|
36
|
+
* @param {string} providerName - Name of the provider.
|
|
37
|
+
* @returns {boolean} - True if provider has an API key configured.
|
|
38
|
+
*/
|
|
39
|
+
static isProviderConfigured(providerName: string): boolean;
|
|
40
|
+
}
|
|
41
|
+
export default ProviderFactory;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export interface ProviderConfig {
|
|
2
|
+
model?: string;
|
|
3
|
+
temperature?: number;
|
|
4
|
+
maxTokens?: number;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
7
|
+
export interface TranslateOptions {
|
|
8
|
+
detectedContext?: {
|
|
9
|
+
category?: string;
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
};
|
|
12
|
+
lengthControl?: {
|
|
13
|
+
mode?: string;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
apiConfig?: Record<string, any>;
|
|
17
|
+
retryOptions?: {
|
|
18
|
+
maxRetries?: number;
|
|
19
|
+
initialDelay?: number;
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
};
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}
|
|
24
|
+
export interface ConfidenceResult {
|
|
25
|
+
score: number;
|
|
26
|
+
metrics?: any;
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
}
|
|
29
|
+
export interface TranslationResult {
|
|
30
|
+
translation: string;
|
|
31
|
+
confidence: ConfidenceResult;
|
|
32
|
+
rawResponse: any;
|
|
33
|
+
}
|
|
34
|
+
declare class BaseProvider {
|
|
35
|
+
name: string;
|
|
36
|
+
config: ProviderConfig;
|
|
37
|
+
defaultModel?: string;
|
|
38
|
+
defaultTemperature: number;
|
|
39
|
+
defaultMaxTokens: number;
|
|
40
|
+
commonHeaders: Record<string, string>;
|
|
41
|
+
constructor(name: string, config?: ProviderConfig);
|
|
42
|
+
translate(text: string, sourceLang: string, targetLang: string, _options?: TranslateOptions): Promise<string>;
|
|
43
|
+
analyze(prompt: string, options?: any): Promise<string>;
|
|
44
|
+
chat(messages: any[], options?: any): Promise<string>;
|
|
45
|
+
getApiKey(): string | undefined;
|
|
46
|
+
getEndpoint(): string;
|
|
47
|
+
validateRequest(text: string, sourceLang: string, targetLang: string): void;
|
|
48
|
+
validateResponse(response: any, providerName: string): boolean;
|
|
49
|
+
handleApiError(error: any, providerName: string): never;
|
|
50
|
+
generatePrompt(text: string, sourceLang: string, targetLang: string, options?: TranslateOptions): string;
|
|
51
|
+
getConfig(options?: ProviderConfig): {
|
|
52
|
+
model: string | undefined;
|
|
53
|
+
temperature: number;
|
|
54
|
+
maxTokens: number;
|
|
55
|
+
max_tokens: number;
|
|
56
|
+
apiKey: string;
|
|
57
|
+
endpoint: string;
|
|
58
|
+
};
|
|
59
|
+
extractTranslation(response: any, providerName: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Extract translation with confidence score
|
|
62
|
+
*/
|
|
63
|
+
extractTranslationWithConfidence(response: any, providerName: string, sourceText: string, sourceLang: string, targetLang: string, category?: string): TranslationResult;
|
|
64
|
+
sanitizeTranslation(translation: string): string;
|
|
65
|
+
}
|
|
66
|
+
export default BaseProvider;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import BaseProvider, { ProviderConfig, TranslateOptions } from "./base-provider.js";
|
|
2
|
+
/**
|
|
3
|
+
* Provider implementation for Alibaba DashScope (Qwen) models.
|
|
4
|
+
*/
|
|
5
|
+
declare class DashScopeProvider extends BaseProvider {
|
|
6
|
+
private client;
|
|
7
|
+
private generationClient;
|
|
8
|
+
/**
|
|
9
|
+
* Create a new DashScopeProvider instance.
|
|
10
|
+
* @param {ProviderConfig} config - Provider configuration.
|
|
11
|
+
*/
|
|
12
|
+
constructor(config?: ProviderConfig);
|
|
13
|
+
getApiKey(): string | undefined;
|
|
14
|
+
getEndpoint(): string;
|
|
15
|
+
getGenerationEndpoint(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Translate text using DashScope.
|
|
18
|
+
*/
|
|
19
|
+
translate(text: string, sourceLang: string, targetLang: string, options?: TranslateOptions): Promise<string>;
|
|
20
|
+
analyze(prompt: string, options?: ProviderConfig): Promise<string>;
|
|
21
|
+
}
|
|
22
|
+
declare function translate(text: string, sourceLang: string, targetLang: string, options?: TranslateOptions): Promise<string>;
|
|
23
|
+
declare function analyze(prompt: string, options?: ProviderConfig): Promise<string>;
|
|
24
|
+
export { translate, analyze, DashScopeProvider };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import BaseProvider, { ProviderConfig, TranslateOptions } from "./base-provider.js";
|
|
2
|
+
/**
|
|
3
|
+
* Provider implementation for DeepSeek API.
|
|
4
|
+
*/
|
|
5
|
+
declare class DeepSeekProvider extends BaseProvider {
|
|
6
|
+
private client;
|
|
7
|
+
/**
|
|
8
|
+
* Create a new DeepSeekProvider instance.
|
|
9
|
+
* @param {ProviderConfig} config - Provider configuration.
|
|
10
|
+
*/
|
|
11
|
+
constructor(config?: ProviderConfig);
|
|
12
|
+
getApiKey(): string | undefined;
|
|
13
|
+
getEndpoint(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Translate text using DeepSeek.
|
|
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, DeepSeekProvider };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import BaseProvider, { ProviderConfig, TranslateOptions } from "./base-provider.js";
|
|
2
|
+
/**
|
|
3
|
+
* Provider implementation for Google Gemini models.
|
|
4
|
+
*/
|
|
5
|
+
declare class GeminiProvider extends BaseProvider {
|
|
6
|
+
private client;
|
|
7
|
+
/**
|
|
8
|
+
* Create a new GeminiProvider instance.
|
|
9
|
+
* @param {ProviderConfig} config - Provider configuration.
|
|
10
|
+
*/
|
|
11
|
+
constructor(config?: ProviderConfig);
|
|
12
|
+
getApiKey(): string | undefined;
|
|
13
|
+
getEndpoint(model?: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Translate text using Gemini.
|
|
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, GeminiProvider };
|
|
@@ -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 };
|
|
@@ -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
|
+
}
|