@llm-translate/cli 1.0.0-next.1 → 1.0.0-next.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llm-translate/cli",
3
- "version": "1.0.0-next.1",
3
+ "version": "1.0.0-next.3",
4
4
  "description": "CLI-based document translation tool powered by LLMs with glossary enforcement and quality-aware refinement",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -11,6 +11,7 @@ export interface ServeCommandOptions {
11
11
  auth?: boolean; // Commander's --no-auth sets this to false
12
12
  cors?: boolean;
13
13
  json?: boolean;
14
+ cacheDir?: string;
14
15
  }
15
16
 
16
17
  // ============================================================================
@@ -28,6 +29,11 @@ export const serveCommand = new Command('serve')
28
29
  .option('--no-auth', 'Disable API key authentication')
29
30
  .option('--cors', 'Enable CORS for browser clients')
30
31
  .option('--json', 'Use JSON logging format (for containers)')
32
+ .option(
33
+ '--cache-dir <path>',
34
+ 'Cache directory path (env: TRANSLATE_CACHE_DIR)',
35
+ process.env['TRANSLATE_CACHE_DIR']
36
+ )
31
37
  .action((options: ServeCommandOptions) => {
32
38
  const port = parseInt(options.port ?? '3000', 10);
33
39
  const host = options.host ?? '0.0.0.0';
@@ -56,5 +62,6 @@ export const serveCommand = new Command('serve')
56
62
  enableCors: options.cors ?? false,
57
63
  apiKey: process.env['TRANSLATE_API_KEY'],
58
64
  jsonLogging: options.json ?? false,
65
+ cachePath: options.cacheDir,
59
66
  });
60
67
  });
@@ -35,6 +35,8 @@ export interface TranslationEngineOptions {
35
35
  verbose?: boolean;
36
36
  /** Disable caching (--no-cache mode) */
37
37
  noCache?: boolean;
38
+ /** External CacheManager instance (for server mode shared cache) */
39
+ cacheManager?: CacheManager;
38
40
  }
39
41
 
40
42
  export interface TranslateFileOptions {
@@ -83,20 +85,29 @@ export class TranslationEngine {
83
85
  }
84
86
 
85
87
  // Initialize cache
86
- const cacheDisabled = options.noCache || !this.config.paths?.cache;
87
- if (cacheDisabled) {
88
- this.cache = createNullCacheManager();
89
- if (this.verbose && options.noCache) {
90
- logger.info('Cache disabled (--no-cache)');
91
- }
92
- } else {
93
- this.cache = createCacheManager({
94
- cacheDir: this.config.paths.cache!,
95
- verbose: this.verbose,
96
- });
88
+ if (options.cacheManager) {
89
+ // Use externally provided cache manager (e.g., server mode)
90
+ this.cache = options.cacheManager;
97
91
  if (this.verbose) {
98
92
  const stats = this.cache.getStats();
99
- logger.info(`Cache initialized: ${stats.entries} entries`);
93
+ logger.info(`Using shared cache: ${stats.entries} entries`);
94
+ }
95
+ } else {
96
+ const cacheDisabled = options.noCache || !this.config.paths?.cache;
97
+ if (cacheDisabled) {
98
+ this.cache = createNullCacheManager();
99
+ if (this.verbose && options.noCache) {
100
+ logger.info('Cache disabled (--no-cache)');
101
+ }
102
+ } else {
103
+ this.cache = createCacheManager({
104
+ cacheDir: this.config.paths.cache!,
105
+ verbose: this.verbose,
106
+ });
107
+ if (this.verbose) {
108
+ const stats = this.cache.getStats();
109
+ logger.info(`Cache initialized: ${stats.entries} entries`);
110
+ }
100
111
  }
101
112
  }
102
113
  }
@@ -19,6 +19,14 @@ import type { ServerConfig, ErrorResponse, HonoVariables } from './types.js';
19
19
  export function createApp(options: ServerConfig) {
20
20
  const app = new Hono<{ Variables: HonoVariables }>();
21
21
 
22
+ // Inject cachePath into context for all routes
23
+ if (options.cachePath) {
24
+ app.use('*', async (c, next) => {
25
+ c.set('cachePath', options.cachePath);
26
+ await next();
27
+ });
28
+ }
29
+
22
30
  // Request logging (first middleware)
23
31
  app.use('*', createLoggerMiddleware({
24
32
  json: options.jsonLogging ?? false,
@@ -113,6 +121,7 @@ export function startServer(options: ServerConfig): ServerType {
113
121
  console.log(` - Translate: http://${options.host}:${options.port}/translate`);
114
122
  console.log(` - Auth: ${options.enableAuth ? 'enabled' : 'disabled'}`);
115
123
  console.log(` - CORS: ${options.enableCors ? 'enabled' : 'disabled'}`);
124
+ console.log(` - Cache: ${options.cachePath ?? 'disabled'}`);
116
125
  console.log('');
117
126
 
118
127
  // Graceful shutdown handlers
@@ -55,6 +55,9 @@ translateRouter.post(
55
55
  // Get mode presets
56
56
  const modeConfig = MODE_PRESETS[body.mode ?? 'balanced'];
57
57
 
58
+ // Get cache path from context (if configured via --cache-dir)
59
+ const cachePath = c.get('cachePath');
60
+
58
61
  // Build config with overrides
59
62
  const config = {
60
63
  ...baseConfig,
@@ -73,13 +76,17 @@ translateRouter.post(
73
76
  threshold: body.qualityThreshold ?? modeConfig.qualityThreshold,
74
77
  maxIterations: body.maxIterations ?? modeConfig.maxIterations,
75
78
  },
79
+ paths: {
80
+ ...baseConfig.paths,
81
+ cache: cachePath,
82
+ },
76
83
  };
77
84
 
78
- // Create engine (API mode doesn't use file cache)
85
+ // Create engine
79
86
  const engine = createTranslationEngine({
80
87
  config,
81
88
  verbose: false,
82
- noCache: true,
89
+ noCache: !cachePath,
83
90
  });
84
91
 
85
92
  // Convert inline glossary to resolved format if provided
@@ -108,6 +108,7 @@ export interface ServerConfig {
108
108
  enableCors: boolean;
109
109
  apiKey?: string;
110
110
  jsonLogging?: boolean;
111
+ cachePath?: string;
111
112
  }
112
113
 
113
114
  // ============================================================================
@@ -119,6 +120,7 @@ export interface ServerConfig {
119
120
  */
120
121
  export interface HonoVariables {
121
122
  requestId: string;
123
+ cachePath?: string;
122
124
  }
123
125
 
124
126
  // ============================================================================