dialekt 0.1.0 → 0.1.1
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/README.md +8 -10
- package/TESTING.md +29 -29
- package/dist/cli/main.d.mts +1 -1
- package/dist/cli/main.mjs +549 -362
- package/dist/formatters-De4Q-X1d.mjs +516 -435
- package/dist/index.d.mts +162 -25
- package/dist/index.mjs +119 -34
- package/package.json +3 -3
- package/pnpm-workspace.yaml +3 -3
- package/src/adapter/types.test.ts +57 -57
- package/src/adapter/types.ts +7 -4
- package/src/benchmark/metrics.test.ts +141 -69
- package/src/benchmark/metrics.ts +6 -6
- package/src/benchmark/report.test.ts +38 -38
- package/src/benchmark/report.ts +6 -6
- package/src/benchmark/runner.test.ts +70 -72
- package/src/benchmark/runner.ts +4 -4
- package/src/cli/commands/add.test.ts +90 -109
- package/src/cli/commands/add.ts +40 -28
- package/src/cli/commands/benchmark.test.ts +77 -64
- package/src/cli/commands/benchmark.ts +64 -41
- package/src/cli/commands/languages.test.ts +45 -42
- package/src/cli/commands/languages.ts +16 -12
- package/src/cli/commands/missing.test.ts +143 -92
- package/src/cli/commands/missing.ts +24 -17
- package/src/cli/commands/translate.test.ts +79 -79
- package/src/cli/commands/translate.ts +41 -31
- package/src/cli/commands/unused.test.ts +62 -51
- package/src/cli/commands/unused.ts +18 -14
- package/src/cli/commands/validate.test.ts +130 -72
- package/src/cli/commands/validate.ts +25 -20
- package/src/cli/config-resolution.test.ts +169 -49
- package/src/cli/config-resolution.ts +5 -7
- package/src/cli/format.test.ts +50 -50
- package/src/cli/format.ts +57 -60
- package/src/cli/formatters.test.ts +128 -106
- package/src/cli/formatters.ts +72 -95
- package/src/cli/main.ts +13 -13
- package/src/config/define-config.test.ts +44 -29
- package/src/config/define-config.ts +1 -1
- package/src/config/load-config.test.ts +21 -18
- package/src/config/load-config.ts +5 -5
- package/src/config/types.test.ts +50 -44
- package/src/config/types.ts +2 -2
- package/src/index.ts +22 -26
- package/src/keys/flatten.test.ts +52 -52
- package/src/keys/flatten.ts +7 -9
- package/src/sdk/file-io.test.ts +47 -59
- package/src/sdk/file-io.ts +2 -2
- package/src/sdk/node-layer.test.ts +18 -18
- package/src/sdk/node-layer.ts +2 -2
- package/src/sdk/php-array-reader.test.ts +49 -40
- package/src/sdk/php-array-reader.ts +5 -5
- package/src/translation/chunking.test.ts +52 -44
- package/src/translation/chunking.ts +1 -1
- package/src/translation/missing-keys.test.ts +86 -93
- package/src/translation/missing-keys.ts +4 -6
- package/src/translation/model-registry.test.ts +41 -32
- package/src/translation/model-registry.ts +9 -9
- package/src/translation/one-shot-strategy.test.ts +105 -86
- package/src/translation/one-shot-strategy.ts +10 -12
- package/src/translation/orchestrator.test.ts +90 -101
- package/src/translation/orchestrator.ts +26 -26
- package/src/translation/prompt.test.ts +76 -76
- package/src/translation/prompt.ts +2 -2
- package/src/translation/tool-loop-strategy.test.ts +134 -107
- package/src/translation/tool-loop-strategy.ts +14 -18
- package/src/translation/types.test.ts +22 -22
- package/src/translation/types.ts +3 -3
- package/tsdown.config.ts +3 -3
- package/vitest.config.ts +3 -3
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { describe, expect, it } from
|
|
2
|
-
import { Effect, Option } from
|
|
3
|
-
import { runTranslate, translateCommand } from
|
|
4
|
-
import type { DialektConfig } from
|
|
5
|
-
import type { TranslationAdapter, ResourceRef } from
|
|
6
|
-
import type { TranslationStrategy } from
|
|
7
|
-
|
|
8
|
-
describe(
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { Effect, Option } from "effect";
|
|
3
|
+
import { runTranslate, translateCommand } from "./translate.js";
|
|
4
|
+
import type { DialektConfig } from "../../config/types.js";
|
|
5
|
+
import type { TranslationAdapter, ResourceRef } from "../../adapter/types.js";
|
|
6
|
+
import type { TranslationStrategy } from "../../translation/types.js";
|
|
7
|
+
|
|
8
|
+
describe("runTranslate", () => {
|
|
9
9
|
const baseConfig: DialektConfig = {
|
|
10
|
-
sourceLocale:
|
|
11
|
-
targetLocales: [
|
|
12
|
-
strategy:
|
|
13
|
-
model: { provider:
|
|
14
|
-
fastModel: { provider:
|
|
10
|
+
sourceLocale: "en",
|
|
11
|
+
targetLocales: ["de", "fr"],
|
|
12
|
+
strategy: "one-shot",
|
|
13
|
+
model: { provider: "openai", modelId: "gpt-4o" },
|
|
14
|
+
fastModel: { provider: "openai", modelId: "gpt-4o-mini" },
|
|
15
15
|
chunking: { maxTokens: 3000, charsPerToken: 3.0, concurrency: 3 },
|
|
16
16
|
retry: { maxAttempts: 3, baseDelayMs: 1000 },
|
|
17
17
|
adapters: [],
|
|
@@ -21,22 +21,22 @@ describe('runTranslate', () => {
|
|
|
21
21
|
return {
|
|
22
22
|
name: opts.name,
|
|
23
23
|
capabilities: { canCreateResource: true, unusedKeyDetection: false },
|
|
24
|
-
listLocales: () => Effect.succeed(opts.locales ?? [
|
|
24
|
+
listLocales: () => Effect.succeed(opts.locales ?? ["en", "de"]),
|
|
25
25
|
listResources: () => Effect.succeed([]),
|
|
26
26
|
readResource: () => Effect.succeed({}),
|
|
27
27
|
writeResource: () => Effect.void,
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
it(
|
|
31
|
+
it("loads config and runs translation with default model", async () => {
|
|
32
32
|
const logs: string[] = [];
|
|
33
33
|
let translationCalls = 0;
|
|
34
|
-
const adapter = makeAdapter({ name:
|
|
35
|
-
const config = { ...baseConfig, adapters: [adapter] as unknown as DialektConfig[
|
|
34
|
+
const adapter = makeAdapter({ name: "test" });
|
|
35
|
+
const config = { ...baseConfig, adapters: [adapter] as unknown as DialektConfig["adapters"] };
|
|
36
36
|
|
|
37
37
|
const program = runTranslate(
|
|
38
38
|
{
|
|
39
|
-
config:
|
|
39
|
+
config: "./config.ts",
|
|
40
40
|
adapter: Option.none(),
|
|
41
41
|
strategy: Option.none(),
|
|
42
42
|
baseLanguage: Option.none(),
|
|
@@ -52,7 +52,7 @@ describe('runTranslate', () => {
|
|
|
52
52
|
Effect.sync(() => {
|
|
53
53
|
translationCalls++;
|
|
54
54
|
expect(opts.adapters).toHaveLength(1);
|
|
55
|
-
expect(opts.sourceLocale).toBe(
|
|
55
|
+
expect(opts.sourceLocale).toBe("en");
|
|
56
56
|
}),
|
|
57
57
|
(msg) => Effect.sync(() => logs.push(msg)),
|
|
58
58
|
);
|
|
@@ -62,17 +62,17 @@ describe('runTranslate', () => {
|
|
|
62
62
|
expect(logs).toHaveLength(1);
|
|
63
63
|
const parsed = JSON.parse(logs[0]!);
|
|
64
64
|
expect(parsed.success).toBe(true);
|
|
65
|
-
expect(parsed.message).toBe(
|
|
65
|
+
expect(parsed.message).toBe("Translation complete.");
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
it(
|
|
68
|
+
it("uses fastModel when --fast is passed", async () => {
|
|
69
69
|
let usedModel: string | undefined;
|
|
70
|
-
const adapter = makeAdapter({ name:
|
|
71
|
-
const config = { ...baseConfig, adapters: [adapter] as unknown as DialektConfig[
|
|
70
|
+
const adapter = makeAdapter({ name: "test" });
|
|
71
|
+
const config = { ...baseConfig, adapters: [adapter] as unknown as DialektConfig["adapters"] };
|
|
72
72
|
|
|
73
73
|
const program = runTranslate(
|
|
74
74
|
{
|
|
75
|
-
config:
|
|
75
|
+
config: "./config.ts",
|
|
76
76
|
adapter: Option.none(),
|
|
77
77
|
strategy: Option.none(),
|
|
78
78
|
baseLanguage: Option.none(),
|
|
@@ -93,21 +93,21 @@ describe('runTranslate', () => {
|
|
|
93
93
|
);
|
|
94
94
|
|
|
95
95
|
await Effect.runPromise(program);
|
|
96
|
-
expect(usedModel).toBe(
|
|
96
|
+
expect(usedModel).toBe("gpt-4o-mini");
|
|
97
97
|
});
|
|
98
98
|
|
|
99
|
-
it(
|
|
99
|
+
it("uses default strategy from config", async () => {
|
|
100
100
|
let strategy: TranslationStrategy | undefined;
|
|
101
|
-
const adapter = makeAdapter({ name:
|
|
101
|
+
const adapter = makeAdapter({ name: "test" });
|
|
102
102
|
const config: DialektConfig = {
|
|
103
103
|
...baseConfig,
|
|
104
|
-
strategy:
|
|
105
|
-
adapters: [adapter] as unknown as DialektConfig[
|
|
104
|
+
strategy: "tool-loop-agent",
|
|
105
|
+
adapters: [adapter] as unknown as DialektConfig["adapters"],
|
|
106
106
|
};
|
|
107
107
|
|
|
108
108
|
const program = runTranslate(
|
|
109
109
|
{
|
|
110
|
-
config:
|
|
110
|
+
config: "./config.ts",
|
|
111
111
|
adapter: Option.none(),
|
|
112
112
|
strategy: Option.none(),
|
|
113
113
|
baseLanguage: Option.none(),
|
|
@@ -128,19 +128,19 @@ describe('runTranslate', () => {
|
|
|
128
128
|
|
|
129
129
|
await Effect.runPromise(program);
|
|
130
130
|
expect(strategy).toBeDefined();
|
|
131
|
-
expect(strategy!.name).toBe(
|
|
131
|
+
expect(strategy!.name).toBe("tool-loop-agent");
|
|
132
132
|
});
|
|
133
133
|
|
|
134
|
-
it(
|
|
134
|
+
it("overrides strategy with --strategy flag", async () => {
|
|
135
135
|
let strategyName: string | undefined;
|
|
136
|
-
const adapter = makeAdapter({ name:
|
|
137
|
-
const config = { ...baseConfig, adapters: [adapter] as unknown as DialektConfig[
|
|
136
|
+
const adapter = makeAdapter({ name: "test" });
|
|
137
|
+
const config = { ...baseConfig, adapters: [adapter] as unknown as DialektConfig["adapters"] };
|
|
138
138
|
|
|
139
139
|
const program = runTranslate(
|
|
140
140
|
{
|
|
141
|
-
config:
|
|
141
|
+
config: "./config.ts",
|
|
142
142
|
adapter: Option.none(),
|
|
143
|
-
strategy: Option.some(
|
|
143
|
+
strategy: Option.some("tool-loop-agent"),
|
|
144
144
|
baseLanguage: Option.none(),
|
|
145
145
|
language: Option.none(),
|
|
146
146
|
name: Option.none(),
|
|
@@ -158,19 +158,19 @@ describe('runTranslate', () => {
|
|
|
158
158
|
);
|
|
159
159
|
|
|
160
160
|
await Effect.runPromise(program);
|
|
161
|
-
expect(strategyName).toBe(
|
|
161
|
+
expect(strategyName).toBe("tool-loop-agent");
|
|
162
162
|
});
|
|
163
163
|
|
|
164
|
-
it(
|
|
164
|
+
it("filters adapters by --adapter flag", async () => {
|
|
165
165
|
let usedAdapterName: string | undefined;
|
|
166
|
-
const a1 = makeAdapter({ name:
|
|
167
|
-
const a2 = makeAdapter({ name:
|
|
168
|
-
const config = { ...baseConfig, adapters: [a1, a2] as unknown as DialektConfig[
|
|
166
|
+
const a1 = makeAdapter({ name: "a1" });
|
|
167
|
+
const a2 = makeAdapter({ name: "a2" });
|
|
168
|
+
const config = { ...baseConfig, adapters: [a1, a2] as unknown as DialektConfig["adapters"] };
|
|
169
169
|
|
|
170
170
|
const program = runTranslate(
|
|
171
171
|
{
|
|
172
|
-
config:
|
|
173
|
-
adapter: Option.some(
|
|
172
|
+
config: "./config.ts",
|
|
173
|
+
adapter: Option.some("a2"),
|
|
174
174
|
strategy: Option.none(),
|
|
175
175
|
baseLanguage: Option.none(),
|
|
176
176
|
language: Option.none(),
|
|
@@ -189,13 +189,13 @@ describe('runTranslate', () => {
|
|
|
189
189
|
);
|
|
190
190
|
|
|
191
191
|
await Effect.runPromise(program);
|
|
192
|
-
expect(usedAdapterName).toBe(
|
|
192
|
+
expect(usedAdapterName).toBe("a2");
|
|
193
193
|
});
|
|
194
194
|
|
|
195
|
-
it(
|
|
195
|
+
it("fails when configLoader fails", async () => {
|
|
196
196
|
const program = runTranslate(
|
|
197
197
|
{
|
|
198
|
-
config:
|
|
198
|
+
config: "./missing.ts",
|
|
199
199
|
adapter: Option.none(),
|
|
200
200
|
strategy: Option.none(),
|
|
201
201
|
baseLanguage: Option.none(),
|
|
@@ -205,21 +205,21 @@ describe('runTranslate', () => {
|
|
|
205
205
|
skipLanguages: false,
|
|
206
206
|
fast: false,
|
|
207
207
|
},
|
|
208
|
-
() => Effect.fail(new Error(
|
|
208
|
+
() => Effect.fail(new Error("Config not found")),
|
|
209
209
|
() => Effect.succeed({}),
|
|
210
210
|
() => Effect.void,
|
|
211
211
|
);
|
|
212
212
|
|
|
213
|
-
await expect(Effect.runPromise(program)).rejects.toThrow(
|
|
213
|
+
await expect(Effect.runPromise(program)).rejects.toThrow("Config not found");
|
|
214
214
|
});
|
|
215
215
|
|
|
216
|
-
it(
|
|
217
|
-
const adapter = makeAdapter({ name:
|
|
218
|
-
const config = { ...baseConfig, adapters: [adapter] as unknown as DialektConfig[
|
|
216
|
+
it("fails when modelResolver fails", async () => {
|
|
217
|
+
const adapter = makeAdapter({ name: "test" });
|
|
218
|
+
const config = { ...baseConfig, adapters: [adapter] as unknown as DialektConfig["adapters"] };
|
|
219
219
|
|
|
220
220
|
const program = runTranslate(
|
|
221
221
|
{
|
|
222
|
-
config:
|
|
222
|
+
config: "./config.ts",
|
|
223
223
|
adapter: Option.none(),
|
|
224
224
|
strategy: Option.none(),
|
|
225
225
|
baseLanguage: Option.none(),
|
|
@@ -230,20 +230,20 @@ describe('runTranslate', () => {
|
|
|
230
230
|
fast: false,
|
|
231
231
|
},
|
|
232
232
|
() => Effect.succeed(config),
|
|
233
|
-
() => Effect.fail(new Error(
|
|
233
|
+
() => Effect.fail(new Error("No API key")),
|
|
234
234
|
() => Effect.void,
|
|
235
235
|
);
|
|
236
236
|
|
|
237
|
-
await expect(Effect.runPromise(program)).rejects.toThrow(
|
|
237
|
+
await expect(Effect.runPromise(program)).rejects.toThrow("No API key");
|
|
238
238
|
});
|
|
239
239
|
|
|
240
|
-
it(
|
|
241
|
-
const adapter = makeAdapter({ name:
|
|
242
|
-
const config = { ...baseConfig, adapters: [adapter] as unknown as DialektConfig[
|
|
240
|
+
it("fails when translationRunner fails", async () => {
|
|
241
|
+
const adapter = makeAdapter({ name: "test" });
|
|
242
|
+
const config = { ...baseConfig, adapters: [adapter] as unknown as DialektConfig["adapters"] };
|
|
243
243
|
|
|
244
244
|
const program = runTranslate(
|
|
245
245
|
{
|
|
246
|
-
config:
|
|
246
|
+
config: "./config.ts",
|
|
247
247
|
adapter: Option.none(),
|
|
248
248
|
strategy: Option.none(),
|
|
249
249
|
baseLanguage: Option.none(),
|
|
@@ -255,21 +255,21 @@ describe('runTranslate', () => {
|
|
|
255
255
|
},
|
|
256
256
|
() => Effect.succeed(config),
|
|
257
257
|
() => Effect.succeed({}),
|
|
258
|
-
() => Effect.fail(new Error(
|
|
258
|
+
() => Effect.fail(new Error("Translation failed")),
|
|
259
259
|
() => Effect.void,
|
|
260
260
|
);
|
|
261
261
|
|
|
262
|
-
await expect(Effect.runPromise(program)).rejects.toThrow(
|
|
262
|
+
await expect(Effect.runPromise(program)).rejects.toThrow("Translation failed");
|
|
263
263
|
});
|
|
264
264
|
|
|
265
|
-
it(
|
|
265
|
+
it("uses one-shot strategy by default", async () => {
|
|
266
266
|
let strategyName: string | undefined;
|
|
267
|
-
const adapter = makeAdapter({ name:
|
|
268
|
-
const config = { ...baseConfig, adapters: [adapter] as unknown as DialektConfig[
|
|
267
|
+
const adapter = makeAdapter({ name: "test" });
|
|
268
|
+
const config = { ...baseConfig, adapters: [adapter] as unknown as DialektConfig["adapters"] };
|
|
269
269
|
|
|
270
270
|
const program = runTranslate(
|
|
271
271
|
{
|
|
272
|
-
config:
|
|
272
|
+
config: "./config.ts",
|
|
273
273
|
adapter: Option.none(),
|
|
274
274
|
strategy: Option.none(),
|
|
275
275
|
baseLanguage: Option.none(),
|
|
@@ -289,21 +289,21 @@ describe('runTranslate', () => {
|
|
|
289
289
|
);
|
|
290
290
|
|
|
291
291
|
await Effect.runPromise(program);
|
|
292
|
-
expect(strategyName).toBe(
|
|
292
|
+
expect(strategyName).toBe("one-shot");
|
|
293
293
|
});
|
|
294
294
|
|
|
295
|
-
it(
|
|
295
|
+
it("filters target locales by --language flag", async () => {
|
|
296
296
|
let targetLocales: readonly string[] = [];
|
|
297
|
-
const adapter = makeAdapter({ name:
|
|
298
|
-
const config = { ...baseConfig, adapters: [adapter] as unknown as DialektConfig[
|
|
297
|
+
const adapter = makeAdapter({ name: "test" });
|
|
298
|
+
const config = { ...baseConfig, adapters: [adapter] as unknown as DialektConfig["adapters"] };
|
|
299
299
|
|
|
300
300
|
const program = runTranslate(
|
|
301
301
|
{
|
|
302
|
-
config:
|
|
302
|
+
config: "./config.ts",
|
|
303
303
|
adapter: Option.none(),
|
|
304
304
|
strategy: Option.none(),
|
|
305
305
|
baseLanguage: Option.none(),
|
|
306
|
-
language: Option.some(
|
|
306
|
+
language: Option.some("de"),
|
|
307
307
|
name: Option.none(),
|
|
308
308
|
skipNames: false,
|
|
309
309
|
skipLanguages: false,
|
|
@@ -319,17 +319,17 @@ describe('runTranslate', () => {
|
|
|
319
319
|
);
|
|
320
320
|
|
|
321
321
|
await Effect.runPromise(program);
|
|
322
|
-
expect(targetLocales).toEqual([
|
|
322
|
+
expect(targetLocales).toEqual(["de"]);
|
|
323
323
|
});
|
|
324
324
|
|
|
325
|
-
it(
|
|
325
|
+
it("outputs pretty when --format pretty is passed", async () => {
|
|
326
326
|
const logs: string[] = [];
|
|
327
|
-
const adapter = makeAdapter({ name:
|
|
328
|
-
const config = { ...baseConfig, adapters: [adapter] as unknown as DialektConfig[
|
|
327
|
+
const adapter = makeAdapter({ name: "test" });
|
|
328
|
+
const config = { ...baseConfig, adapters: [adapter] as unknown as DialektConfig["adapters"] };
|
|
329
329
|
|
|
330
330
|
const program = runTranslate(
|
|
331
331
|
{
|
|
332
|
-
config:
|
|
332
|
+
config: "./config.ts",
|
|
333
333
|
adapter: Option.none(),
|
|
334
334
|
strategy: Option.none(),
|
|
335
335
|
baseLanguage: Option.none(),
|
|
@@ -338,7 +338,7 @@ describe('runTranslate', () => {
|
|
|
338
338
|
skipNames: false,
|
|
339
339
|
skipLanguages: false,
|
|
340
340
|
fast: false,
|
|
341
|
-
format: Option.some(
|
|
341
|
+
format: Option.some("pretty"),
|
|
342
342
|
},
|
|
343
343
|
() => Effect.succeed(config),
|
|
344
344
|
() => Effect.succeed({}),
|
|
@@ -348,16 +348,16 @@ describe('runTranslate', () => {
|
|
|
348
348
|
|
|
349
349
|
await Effect.runPromise(program);
|
|
350
350
|
expect(logs).toHaveLength(1);
|
|
351
|
-
expect(logs[0]).toContain(
|
|
351
|
+
expect(logs[0]).toContain("Translation complete");
|
|
352
352
|
});
|
|
353
353
|
|
|
354
|
-
it(
|
|
354
|
+
it("handles empty adapters list", async () => {
|
|
355
355
|
const logs: string[] = [];
|
|
356
356
|
const config = { ...baseConfig, adapters: [] };
|
|
357
357
|
|
|
358
358
|
const program = runTranslate(
|
|
359
359
|
{
|
|
360
|
-
config:
|
|
360
|
+
config: "./config.ts",
|
|
361
361
|
adapter: Option.none(),
|
|
362
362
|
strategy: Option.none(),
|
|
363
363
|
baseLanguage: Option.none(),
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Command, Options } from
|
|
2
|
-
import { Effect, Console, Option } from
|
|
3
|
-
import { loadConfig } from
|
|
4
|
-
import { resolveEffectiveConfig } from
|
|
5
|
-
import { resolveModel } from
|
|
6
|
-
import { createOneShotStrategy } from
|
|
7
|
-
import { createToolLoopStrategy } from
|
|
8
|
-
import { runTranslation } from
|
|
9
|
-
import { detectFormat, type OutputFormat } from
|
|
10
|
-
import { formatTranslate, formatError } from
|
|
11
|
-
import type { DialektConfig } from
|
|
12
|
-
import type { TranslationStrategy } from
|
|
1
|
+
import { Command, Options } from "@effect/cli";
|
|
2
|
+
import { Effect, Console, Option } from "effect";
|
|
3
|
+
import { loadConfig } from "../../config/load-config.js";
|
|
4
|
+
import { resolveEffectiveConfig } from "../config-resolution.js";
|
|
5
|
+
import { resolveModel } from "../../translation/model-registry.js";
|
|
6
|
+
import { createOneShotStrategy } from "../../translation/one-shot-strategy.js";
|
|
7
|
+
import { createToolLoopStrategy } from "../../translation/tool-loop-strategy.js";
|
|
8
|
+
import { runTranslation } from "../../translation/orchestrator.js";
|
|
9
|
+
import { detectFormat, type OutputFormat } from "../format.js";
|
|
10
|
+
import { formatTranslate, formatError } from "../formatters.js";
|
|
11
|
+
import type { DialektConfig } from "../../config/types.js";
|
|
12
|
+
import type { TranslationStrategy } from "../../translation/types.js";
|
|
13
13
|
|
|
14
14
|
export interface TranslateFlags {
|
|
15
15
|
readonly config: string;
|
|
@@ -27,7 +27,10 @@ export interface TranslateFlags {
|
|
|
27
27
|
export function runTranslate(
|
|
28
28
|
flags: TranslateFlags,
|
|
29
29
|
configLoader: (path: string) => Effect.Effect<DialektConfig, unknown> = loadConfig,
|
|
30
|
-
modelResolver: (config: {
|
|
30
|
+
modelResolver: (config: {
|
|
31
|
+
provider: string;
|
|
32
|
+
modelId: string;
|
|
33
|
+
}) => Effect.Effect<unknown, unknown> = resolveModel,
|
|
31
34
|
translationRunner: (opts: {
|
|
32
35
|
adapters: readonly unknown[];
|
|
33
36
|
strategy: TranslationStrategy;
|
|
@@ -45,19 +48,22 @@ export function runTranslate(
|
|
|
45
48
|
language: Option.isSome(flags.language) ? [flags.language.value] : undefined,
|
|
46
49
|
adapter: Option.getOrUndefined(flags.adapter),
|
|
47
50
|
strategy:
|
|
48
|
-
Option.getOrUndefined(flags.strategy) ===
|
|
49
|
-
Option.getOrUndefined(flags.strategy) ===
|
|
50
|
-
? (Option.getOrUndefined(flags.strategy) as
|
|
51
|
+
Option.getOrUndefined(flags.strategy) === "one-shot" ||
|
|
52
|
+
Option.getOrUndefined(flags.strategy) === "tool-loop-agent"
|
|
53
|
+
? (Option.getOrUndefined(flags.strategy) as "one-shot" | "tool-loop-agent")
|
|
51
54
|
: undefined,
|
|
52
55
|
},
|
|
53
56
|
loaded,
|
|
54
57
|
);
|
|
55
58
|
|
|
56
59
|
const modelConfig = flags.fast ? effective.fastModel : effective.model;
|
|
57
|
-
const model = yield* modelResolver(modelConfig) as Effect.Effect<
|
|
60
|
+
const model = yield* modelResolver(modelConfig) as Effect.Effect<
|
|
61
|
+
import("ai").LanguageModel,
|
|
62
|
+
unknown
|
|
63
|
+
>;
|
|
58
64
|
|
|
59
65
|
const translationStrategy =
|
|
60
|
-
effective.strategy ===
|
|
66
|
+
effective.strategy === "tool-loop-agent"
|
|
61
67
|
? createToolLoopStrategy({ model, retry: effective.retry })
|
|
62
68
|
: createOneShotStrategy({ model, retry: effective.retry });
|
|
63
69
|
|
|
@@ -79,7 +85,7 @@ export function runTranslate(
|
|
|
79
85
|
formatTranslate(
|
|
80
86
|
{
|
|
81
87
|
success: true,
|
|
82
|
-
message:
|
|
88
|
+
message: "Translation complete.",
|
|
83
89
|
stats: {
|
|
84
90
|
adaptersProcessed: effective.adapters.length,
|
|
85
91
|
localesTranslated: (effective.targetLocales ?? []).length,
|
|
@@ -92,15 +98,19 @@ export function runTranslate(
|
|
|
92
98
|
});
|
|
93
99
|
}
|
|
94
100
|
|
|
95
|
-
export const translateCommand = Command.make(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
export const translateCommand = Command.make(
|
|
102
|
+
"translate",
|
|
103
|
+
{
|
|
104
|
+
config: Options.text("config").pipe(Options.withDefault("./dialekt.config.ts")),
|
|
105
|
+
adapter: Options.optional(Options.text("adapter")),
|
|
106
|
+
strategy: Options.optional(Options.text("strategy")),
|
|
107
|
+
baseLanguage: Options.optional(Options.text("base-language")),
|
|
108
|
+
language: Options.optional(Options.text("language")),
|
|
109
|
+
name: Options.optional(Options.text("name")),
|
|
110
|
+
skipNames: Options.boolean("skip-names"),
|
|
111
|
+
skipLanguages: Options.boolean("skip-languages"),
|
|
112
|
+
fast: Options.boolean("fast"),
|
|
113
|
+
format: Options.optional(Options.text("format")),
|
|
114
|
+
},
|
|
115
|
+
(flags) => runTranslate(flags),
|
|
116
|
+
);
|