@gringow/gringow 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +279 -43
  2. package/dist/config.d.mts +7 -8
  3. package/dist/config.mjs +32 -20
  4. package/dist/config.test.mjs +39 -25
  5. package/dist/constants/default-config.mjs +4 -3
  6. package/dist/data/check-cache.mjs +33 -63
  7. package/dist/data/clear-cache.mjs +32 -20
  8. package/dist/data/create-cache-dir.mjs +32 -20
  9. package/dist/data/delete-cache-item.mjs +32 -20
  10. package/dist/data/get-cache.mjs +32 -20
  11. package/dist/data/get-or-create-cache.mjs +32 -20
  12. package/dist/data/save-cache.mjs +32 -20
  13. package/dist/data/write-cache-to-disk.mjs +32 -20
  14. package/dist/gringow.mjs +84 -491
  15. package/dist/index.mjs +84 -491
  16. package/dist/io/ask-llm.d.mts +3 -1
  17. package/dist/io/ask-llm.mjs +77 -449
  18. package/dist/schemas/config.shcema.d.mts +40 -47
  19. package/dist/schemas/config.shcema.mjs +26 -15
  20. package/dist/types/index.d.mts +3 -25
  21. package/gringow.config.js.example +2 -4
  22. package/gringow.config.json.example +4 -2
  23. package/package.json +2 -5
  24. package/dist/io/anthropic/ask.d.mts +0 -11
  25. package/dist/io/anthropic/ask.mjs +0 -190
  26. package/dist/io/anthropic/commit-response.d.mts +0 -21
  27. package/dist/io/anthropic/commit-response.mjs +0 -10
  28. package/dist/io/anthropic/index.d.mts +0 -14
  29. package/dist/io/anthropic/index.mjs +0 -208
  30. package/dist/io/anthropic/parse.d.mts +0 -20
  31. package/dist/io/anthropic/parse.mjs +0 -10
  32. package/dist/io/gemini/ask.d.mts +0 -11
  33. package/dist/io/gemini/ask.mjs +0 -232
  34. package/dist/io/gemini/commit-response.d.mts +0 -11
  35. package/dist/io/gemini/commit-response.mjs +0 -7
  36. package/dist/io/gemini/index.d.mts +0 -14
  37. package/dist/io/gemini/index.mjs +0 -248
  38. package/dist/io/gemini/parse.d.mts +0 -20
  39. package/dist/io/gemini/parse.mjs +0 -11
  40. package/dist/io/huggingface/ask.d.mts +0 -13
  41. package/dist/io/huggingface/ask.mjs +0 -405
  42. package/dist/io/huggingface/commit-response.d.mts +0 -39
  43. package/dist/io/huggingface/commit-response.mjs +0 -14
  44. package/dist/io/huggingface/index.d.mts +0 -13
  45. package/dist/io/huggingface/index.mjs +0 -426
  46. package/dist/io/huggingface/languages-map.d.mts +0 -191
  47. package/dist/io/huggingface/languages-map.mjs +0 -187
  48. package/dist/io/huggingface/parse.d.mts +0 -20
  49. package/dist/io/huggingface/parse.mjs +0 -9
@@ -19,19 +19,34 @@ var defaultConfig = {
19
19
  prefix: "grw",
20
20
  write: true
21
21
  },
22
- keys: {},
23
22
  sourceLanguage: "en-US",
23
+ defaultLanguage: "pt-BR",
24
24
  languages: ["pt-BR", "fr-CA"],
25
25
  llm: {
26
- choice: "huggingface",
27
- model: "Xenova/nllb-200-distilled-600M",
26
+ provider: "openai",
27
+ apiKey: void 0,
28
+ model: "gpt-4o-mini",
28
29
  temperature: 1,
29
30
  sleep: 0
30
31
  },
31
32
  globby: "./src/**/*.{js,jsx,ts,tsx}"
32
33
  };
33
34
  var languageSchema = z.string().regex(/^[a-z]{2,3}(-[A-Z]{2})?$/);
34
- var llmOptionsSchema = z.enum(["gemini", "anthropic", "huggingface"]);
35
+ var llmProviderSchema = z.enum([
36
+ "anthropic",
37
+ "gemini",
38
+ "openai",
39
+ "groq",
40
+ "mistral",
41
+ "ollama",
42
+ "xai",
43
+ "deepseek",
44
+ "openrouter",
45
+ "cerebras",
46
+ "lmstudio",
47
+ "azure",
48
+ "meta"
49
+ ]);
35
50
  var configSchema = z.object({
36
51
  debug: z.boolean().optional(),
37
52
  log: z.object({
@@ -43,14 +58,13 @@ var configSchema = z.object({
43
58
  prefix: z.string(),
44
59
  write: z.boolean().optional()
45
60
  }),
46
- keys: z.object({
47
- anthropicApiKey: z.string().optional(),
48
- geminiApiKey: z.string().optional()
49
- }),
50
61
  sourceLanguage: languageSchema,
62
+ defaultLanguage: languageSchema,
51
63
  languages: z.array(languageSchema),
52
64
  llm: z.object({
53
- choice: llmOptionsSchema,
65
+ provider: llmProviderSchema,
66
+ apiKey: z.string().optional(),
67
+ baseURL: z.string().optional(),
54
68
  model: z.string().nullable(),
55
69
  temperature: z.number().optional(),
56
70
  sleep: z.number().optional(),
@@ -64,17 +78,15 @@ var configSchema = z.object({
64
78
  globby: z.string().regex(/^\.\/.*/).optional()
65
79
  }).refine(
66
80
  (data) => {
67
- if (data.llm.choice === "gemini" && !data.keys.geminiApiKey) {
68
- return false;
69
- }
70
- if (data.llm.choice === "anthropic" && !data.keys.anthropicApiKey) {
71
- return false;
81
+ const noApiKeyRequired = ["ollama", "lmstudio"];
82
+ if (noApiKeyRequired.includes(data.llm.provider)) {
83
+ return true;
72
84
  }
73
- return true;
85
+ return !!data.llm.apiKey;
74
86
  },
75
87
  {
76
- message: "The API key corresponding to the chosen LLM must be present.",
77
- path: ["keys"]
88
+ message: "The API key must be present in llm.apiKey for the chosen provider.",
89
+ path: ["llm", "apiKey"]
78
90
  }
79
91
  );
80
92
 
@@ -110,7 +122,7 @@ Your task is to translate a given text and output **only one valid JSON object**
110
122
 
111
123
  Follow these rules strictly:
112
124
 
113
- 1. The original text is written in English.
125
+ 1. The original text is written in English or Spanish.
114
126
  2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
115
127
  - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
116
128
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
@@ -143,10 +155,10 @@ Translate the following text faithfully:
143
155
  function defaultPostPrompt(_config) {
144
156
  return "";
145
157
  }
146
- function prePrompt(config, append, replace) {
158
+ function prePrompt(config, prepend, replace) {
147
159
  return [
148
160
  // ...(append ? ['[SPECIFIC_INPUTS]', String(append), '[/SPECIFIC_INPUTS]'] : []),
149
- replace ? String(replace) : defaultPrePrompt(config, append)
161
+ replace ? String(replace) : defaultPrePrompt(config, prepend)
150
162
  ].join(" ").trim();
151
163
  }
152
164
  function postPrompt(config, prepend, replace) {
@@ -410,53 +422,11 @@ async function getOrCreateCache() {
410
422
  return rawCache ? JSON.parse(rawCache?.toString()) : {};
411
423
  }
412
424
 
413
- // src/logger.ts
414
- var Dim = "\x1B[2m";
415
- var FgGreen = "\x1B[32m";
416
- var FgYellow = "\x1B[33m";
417
- var FgCyan = "\x1B[36m";
418
- var FgWhite = "\x1B[37m";
419
- var BgRed = "\x1B[41m";
420
- var Clear = "\x1B[0m";
421
- var Colors = {
422
- debug: `${Dim}${FgGreen}`,
423
- trace: `${Dim}${FgCyan}`,
424
- info: `${FgCyan}`,
425
- error: `${BgRed}${FgWhite}`,
426
- warn: `${FgYellow}`,
427
- verbose: `${FgWhite}`
428
- };
429
- var isProd = process.env.NODE_ENV === "production";
430
- function log(level, ...params) {
431
- console.log(`${!isProd ? Colors[level] : ""}${String(level).toUpperCase()} `, ...params, `${!isProd ? Clear : ""}`);
432
- }
433
- var logger = {
434
- debug(...params) {
435
- return log("debug", ...params);
436
- },
437
- trace(...params) {
438
- return log("trace", ...params);
439
- },
440
- info(...params) {
441
- return log("info", ...params);
442
- },
443
- warn(...params) {
444
- return log("warn", ...params);
445
- },
446
- error(...params) {
447
- return log("error", ...params);
448
- },
449
- verbose(...params) {
450
- return log("verbose", ...params);
451
- }
452
- };
453
- var logger_default = logger;
454
-
455
425
  // src/data/check-cache.ts
456
426
  async function checkCache(cacheId) {
457
427
  const cache = await getOrCreateCache();
458
428
  if (cache?.[cacheId]) {
459
- logger_default.debug(`Cache hit, id:${cacheId}`);
429
+ console.log(`Cache hit, id:${cacheId}`);
460
430
  return cache[cacheId];
461
431
  }
462
432
  return void 0;
@@ -19,19 +19,34 @@ var defaultConfig = {
19
19
  prefix: "grw",
20
20
  write: true
21
21
  },
22
- keys: {},
23
22
  sourceLanguage: "en-US",
23
+ defaultLanguage: "pt-BR",
24
24
  languages: ["pt-BR", "fr-CA"],
25
25
  llm: {
26
- choice: "huggingface",
27
- model: "Xenova/nllb-200-distilled-600M",
26
+ provider: "openai",
27
+ apiKey: void 0,
28
+ model: "gpt-4o-mini",
28
29
  temperature: 1,
29
30
  sleep: 0
30
31
  },
31
32
  globby: "./src/**/*.{js,jsx,ts,tsx}"
32
33
  };
33
34
  var languageSchema = z.string().regex(/^[a-z]{2,3}(-[A-Z]{2})?$/);
34
- var llmOptionsSchema = z.enum(["gemini", "anthropic", "huggingface"]);
35
+ var llmProviderSchema = z.enum([
36
+ "anthropic",
37
+ "gemini",
38
+ "openai",
39
+ "groq",
40
+ "mistral",
41
+ "ollama",
42
+ "xai",
43
+ "deepseek",
44
+ "openrouter",
45
+ "cerebras",
46
+ "lmstudio",
47
+ "azure",
48
+ "meta"
49
+ ]);
35
50
  var configSchema = z.object({
36
51
  debug: z.boolean().optional(),
37
52
  log: z.object({
@@ -43,14 +58,13 @@ var configSchema = z.object({
43
58
  prefix: z.string(),
44
59
  write: z.boolean().optional()
45
60
  }),
46
- keys: z.object({
47
- anthropicApiKey: z.string().optional(),
48
- geminiApiKey: z.string().optional()
49
- }),
50
61
  sourceLanguage: languageSchema,
62
+ defaultLanguage: languageSchema,
51
63
  languages: z.array(languageSchema),
52
64
  llm: z.object({
53
- choice: llmOptionsSchema,
65
+ provider: llmProviderSchema,
66
+ apiKey: z.string().optional(),
67
+ baseURL: z.string().optional(),
54
68
  model: z.string().nullable(),
55
69
  temperature: z.number().optional(),
56
70
  sleep: z.number().optional(),
@@ -64,17 +78,15 @@ var configSchema = z.object({
64
78
  globby: z.string().regex(/^\.\/.*/).optional()
65
79
  }).refine(
66
80
  (data) => {
67
- if (data.llm.choice === "gemini" && !data.keys.geminiApiKey) {
68
- return false;
69
- }
70
- if (data.llm.choice === "anthropic" && !data.keys.anthropicApiKey) {
71
- return false;
81
+ const noApiKeyRequired = ["ollama", "lmstudio"];
82
+ if (noApiKeyRequired.includes(data.llm.provider)) {
83
+ return true;
72
84
  }
73
- return true;
85
+ return !!data.llm.apiKey;
74
86
  },
75
87
  {
76
- message: "The API key corresponding to the chosen LLM must be present.",
77
- path: ["keys"]
88
+ message: "The API key must be present in llm.apiKey for the chosen provider.",
89
+ path: ["llm", "apiKey"]
78
90
  }
79
91
  );
80
92
 
@@ -110,7 +122,7 @@ Your task is to translate a given text and output **only one valid JSON object**
110
122
 
111
123
  Follow these rules strictly:
112
124
 
113
- 1. The original text is written in English.
125
+ 1. The original text is written in English or Spanish.
114
126
  2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
115
127
  - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
116
128
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
@@ -143,10 +155,10 @@ Translate the following text faithfully:
143
155
  function defaultPostPrompt(_config) {
144
156
  return "";
145
157
  }
146
- function prePrompt(config, append, replace) {
158
+ function prePrompt(config, prepend, replace) {
147
159
  return [
148
160
  // ...(append ? ['[SPECIFIC_INPUTS]', String(append), '[/SPECIFIC_INPUTS]'] : []),
149
- replace ? String(replace) : defaultPrePrompt(config, append)
161
+ replace ? String(replace) : defaultPrePrompt(config, prepend)
150
162
  ].join(" ").trim();
151
163
  }
152
164
  function postPrompt(config, prepend, replace) {
@@ -223,19 +223,34 @@ var defaultConfig = {
223
223
  prefix: "grw",
224
224
  write: true
225
225
  },
226
- keys: {},
227
226
  sourceLanguage: "en-US",
227
+ defaultLanguage: "pt-BR",
228
228
  languages: ["pt-BR", "fr-CA"],
229
229
  llm: {
230
- choice: "huggingface",
231
- model: "Xenova/nllb-200-distilled-600M",
230
+ provider: "openai",
231
+ apiKey: void 0,
232
+ model: "gpt-4o-mini",
232
233
  temperature: 1,
233
234
  sleep: 0
234
235
  },
235
236
  globby: "./src/**/*.{js,jsx,ts,tsx}"
236
237
  };
237
238
  var languageSchema = z.string().regex(/^[a-z]{2,3}(-[A-Z]{2})?$/);
238
- var llmOptionsSchema = z.enum(["gemini", "anthropic", "huggingface"]);
239
+ var llmProviderSchema = z.enum([
240
+ "anthropic",
241
+ "gemini",
242
+ "openai",
243
+ "groq",
244
+ "mistral",
245
+ "ollama",
246
+ "xai",
247
+ "deepseek",
248
+ "openrouter",
249
+ "cerebras",
250
+ "lmstudio",
251
+ "azure",
252
+ "meta"
253
+ ]);
239
254
  var configSchema = z.object({
240
255
  debug: z.boolean().optional(),
241
256
  log: z.object({
@@ -247,14 +262,13 @@ var configSchema = z.object({
247
262
  prefix: z.string(),
248
263
  write: z.boolean().optional()
249
264
  }),
250
- keys: z.object({
251
- anthropicApiKey: z.string().optional(),
252
- geminiApiKey: z.string().optional()
253
- }),
254
265
  sourceLanguage: languageSchema,
266
+ defaultLanguage: languageSchema,
255
267
  languages: z.array(languageSchema),
256
268
  llm: z.object({
257
- choice: llmOptionsSchema,
269
+ provider: llmProviderSchema,
270
+ apiKey: z.string().optional(),
271
+ baseURL: z.string().optional(),
258
272
  model: z.string().nullable(),
259
273
  temperature: z.number().optional(),
260
274
  sleep: z.number().optional(),
@@ -268,17 +282,15 @@ var configSchema = z.object({
268
282
  globby: z.string().regex(/^\.\/.*/).optional()
269
283
  }).refine(
270
284
  (data) => {
271
- if (data.llm.choice === "gemini" && !data.keys.geminiApiKey) {
272
- return false;
273
- }
274
- if (data.llm.choice === "anthropic" && !data.keys.anthropicApiKey) {
275
- return false;
285
+ const noApiKeyRequired = ["ollama", "lmstudio"];
286
+ if (noApiKeyRequired.includes(data.llm.provider)) {
287
+ return true;
276
288
  }
277
- return true;
289
+ return !!data.llm.apiKey;
278
290
  },
279
291
  {
280
- message: "The API key corresponding to the chosen LLM must be present.",
281
- path: ["keys"]
292
+ message: "The API key must be present in llm.apiKey for the chosen provider.",
293
+ path: ["llm", "apiKey"]
282
294
  }
283
295
  );
284
296
 
@@ -314,7 +326,7 @@ Your task is to translate a given text and output **only one valid JSON object**
314
326
 
315
327
  Follow these rules strictly:
316
328
 
317
- 1. The original text is written in English.
329
+ 1. The original text is written in English or Spanish.
318
330
  2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
319
331
  - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
320
332
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
@@ -347,10 +359,10 @@ Translate the following text faithfully:
347
359
  function defaultPostPrompt(_config) {
348
360
  return "";
349
361
  }
350
- function prePrompt(config, append, replace) {
362
+ function prePrompt(config, prepend, replace) {
351
363
  return [
352
364
  // ...(append ? ['[SPECIFIC_INPUTS]', String(append), '[/SPECIFIC_INPUTS]'] : []),
353
- replace ? String(replace) : defaultPrePrompt(config, append)
365
+ replace ? String(replace) : defaultPrePrompt(config, prepend)
354
366
  ].join(" ").trim();
355
367
  }
356
368
  function postPrompt(config, prepend, replace) {
@@ -19,19 +19,34 @@ var defaultConfig = {
19
19
  prefix: "grw",
20
20
  write: true
21
21
  },
22
- keys: {},
23
22
  sourceLanguage: "en-US",
23
+ defaultLanguage: "pt-BR",
24
24
  languages: ["pt-BR", "fr-CA"],
25
25
  llm: {
26
- choice: "huggingface",
27
- model: "Xenova/nllb-200-distilled-600M",
26
+ provider: "openai",
27
+ apiKey: void 0,
28
+ model: "gpt-4o-mini",
28
29
  temperature: 1,
29
30
  sleep: 0
30
31
  },
31
32
  globby: "./src/**/*.{js,jsx,ts,tsx}"
32
33
  };
33
34
  var languageSchema = z.string().regex(/^[a-z]{2,3}(-[A-Z]{2})?$/);
34
- var llmOptionsSchema = z.enum(["gemini", "anthropic", "huggingface"]);
35
+ var llmProviderSchema = z.enum([
36
+ "anthropic",
37
+ "gemini",
38
+ "openai",
39
+ "groq",
40
+ "mistral",
41
+ "ollama",
42
+ "xai",
43
+ "deepseek",
44
+ "openrouter",
45
+ "cerebras",
46
+ "lmstudio",
47
+ "azure",
48
+ "meta"
49
+ ]);
35
50
  var configSchema = z.object({
36
51
  debug: z.boolean().optional(),
37
52
  log: z.object({
@@ -43,14 +58,13 @@ var configSchema = z.object({
43
58
  prefix: z.string(),
44
59
  write: z.boolean().optional()
45
60
  }),
46
- keys: z.object({
47
- anthropicApiKey: z.string().optional(),
48
- geminiApiKey: z.string().optional()
49
- }),
50
61
  sourceLanguage: languageSchema,
62
+ defaultLanguage: languageSchema,
51
63
  languages: z.array(languageSchema),
52
64
  llm: z.object({
53
- choice: llmOptionsSchema,
65
+ provider: llmProviderSchema,
66
+ apiKey: z.string().optional(),
67
+ baseURL: z.string().optional(),
54
68
  model: z.string().nullable(),
55
69
  temperature: z.number().optional(),
56
70
  sleep: z.number().optional(),
@@ -64,17 +78,15 @@ var configSchema = z.object({
64
78
  globby: z.string().regex(/^\.\/.*/).optional()
65
79
  }).refine(
66
80
  (data) => {
67
- if (data.llm.choice === "gemini" && !data.keys.geminiApiKey) {
68
- return false;
69
- }
70
- if (data.llm.choice === "anthropic" && !data.keys.anthropicApiKey) {
71
- return false;
81
+ const noApiKeyRequired = ["ollama", "lmstudio"];
82
+ if (noApiKeyRequired.includes(data.llm.provider)) {
83
+ return true;
72
84
  }
73
- return true;
85
+ return !!data.llm.apiKey;
74
86
  },
75
87
  {
76
- message: "The API key corresponding to the chosen LLM must be present.",
77
- path: ["keys"]
88
+ message: "The API key must be present in llm.apiKey for the chosen provider.",
89
+ path: ["llm", "apiKey"]
78
90
  }
79
91
  );
80
92
 
@@ -110,7 +122,7 @@ Your task is to translate a given text and output **only one valid JSON object**
110
122
 
111
123
  Follow these rules strictly:
112
124
 
113
- 1. The original text is written in English.
125
+ 1. The original text is written in English or Spanish.
114
126
  2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
115
127
  - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
116
128
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
@@ -143,10 +155,10 @@ Translate the following text faithfully:
143
155
  function defaultPostPrompt(_config) {
144
156
  return "";
145
157
  }
146
- function prePrompt(config, append, replace) {
158
+ function prePrompt(config, prepend, replace) {
147
159
  return [
148
160
  // ...(append ? ['[SPECIFIC_INPUTS]', String(append), '[/SPECIFIC_INPUTS]'] : []),
149
- replace ? String(replace) : defaultPrePrompt(config, append)
161
+ replace ? String(replace) : defaultPrePrompt(config, prepend)
150
162
  ].join(" ").trim();
151
163
  }
152
164
  function postPrompt(config, prepend, replace) {
@@ -19,19 +19,34 @@ var defaultConfig = {
19
19
  prefix: "grw",
20
20
  write: true
21
21
  },
22
- keys: {},
23
22
  sourceLanguage: "en-US",
23
+ defaultLanguage: "pt-BR",
24
24
  languages: ["pt-BR", "fr-CA"],
25
25
  llm: {
26
- choice: "huggingface",
27
- model: "Xenova/nllb-200-distilled-600M",
26
+ provider: "openai",
27
+ apiKey: void 0,
28
+ model: "gpt-4o-mini",
28
29
  temperature: 1,
29
30
  sleep: 0
30
31
  },
31
32
  globby: "./src/**/*.{js,jsx,ts,tsx}"
32
33
  };
33
34
  var languageSchema = z.string().regex(/^[a-z]{2,3}(-[A-Z]{2})?$/);
34
- var llmOptionsSchema = z.enum(["gemini", "anthropic", "huggingface"]);
35
+ var llmProviderSchema = z.enum([
36
+ "anthropic",
37
+ "gemini",
38
+ "openai",
39
+ "groq",
40
+ "mistral",
41
+ "ollama",
42
+ "xai",
43
+ "deepseek",
44
+ "openrouter",
45
+ "cerebras",
46
+ "lmstudio",
47
+ "azure",
48
+ "meta"
49
+ ]);
35
50
  var configSchema = z.object({
36
51
  debug: z.boolean().optional(),
37
52
  log: z.object({
@@ -43,14 +58,13 @@ var configSchema = z.object({
43
58
  prefix: z.string(),
44
59
  write: z.boolean().optional()
45
60
  }),
46
- keys: z.object({
47
- anthropicApiKey: z.string().optional(),
48
- geminiApiKey: z.string().optional()
49
- }),
50
61
  sourceLanguage: languageSchema,
62
+ defaultLanguage: languageSchema,
51
63
  languages: z.array(languageSchema),
52
64
  llm: z.object({
53
- choice: llmOptionsSchema,
65
+ provider: llmProviderSchema,
66
+ apiKey: z.string().optional(),
67
+ baseURL: z.string().optional(),
54
68
  model: z.string().nullable(),
55
69
  temperature: z.number().optional(),
56
70
  sleep: z.number().optional(),
@@ -64,17 +78,15 @@ var configSchema = z.object({
64
78
  globby: z.string().regex(/^\.\/.*/).optional()
65
79
  }).refine(
66
80
  (data) => {
67
- if (data.llm.choice === "gemini" && !data.keys.geminiApiKey) {
68
- return false;
69
- }
70
- if (data.llm.choice === "anthropic" && !data.keys.anthropicApiKey) {
71
- return false;
81
+ const noApiKeyRequired = ["ollama", "lmstudio"];
82
+ if (noApiKeyRequired.includes(data.llm.provider)) {
83
+ return true;
72
84
  }
73
- return true;
85
+ return !!data.llm.apiKey;
74
86
  },
75
87
  {
76
- message: "The API key corresponding to the chosen LLM must be present.",
77
- path: ["keys"]
88
+ message: "The API key must be present in llm.apiKey for the chosen provider.",
89
+ path: ["llm", "apiKey"]
78
90
  }
79
91
  );
80
92
 
@@ -110,7 +122,7 @@ Your task is to translate a given text and output **only one valid JSON object**
110
122
 
111
123
  Follow these rules strictly:
112
124
 
113
- 1. The original text is written in English.
125
+ 1. The original text is written in English or Spanish.
114
126
  2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
115
127
  - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
116
128
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
@@ -143,10 +155,10 @@ Translate the following text faithfully:
143
155
  function defaultPostPrompt(_config) {
144
156
  return "";
145
157
  }
146
- function prePrompt(config, append, replace) {
158
+ function prePrompt(config, prepend, replace) {
147
159
  return [
148
160
  // ...(append ? ['[SPECIFIC_INPUTS]', String(append), '[/SPECIFIC_INPUTS]'] : []),
149
- replace ? String(replace) : defaultPrePrompt(config, append)
161
+ replace ? String(replace) : defaultPrePrompt(config, prepend)
150
162
  ].join(" ").trim();
151
163
  }
152
164
  function postPrompt(config, prepend, replace) {
@@ -19,19 +19,34 @@ var defaultConfig = {
19
19
  prefix: "grw",
20
20
  write: true
21
21
  },
22
- keys: {},
23
22
  sourceLanguage: "en-US",
23
+ defaultLanguage: "pt-BR",
24
24
  languages: ["pt-BR", "fr-CA"],
25
25
  llm: {
26
- choice: "huggingface",
27
- model: "Xenova/nllb-200-distilled-600M",
26
+ provider: "openai",
27
+ apiKey: void 0,
28
+ model: "gpt-4o-mini",
28
29
  temperature: 1,
29
30
  sleep: 0
30
31
  },
31
32
  globby: "./src/**/*.{js,jsx,ts,tsx}"
32
33
  };
33
34
  var languageSchema = z.string().regex(/^[a-z]{2,3}(-[A-Z]{2})?$/);
34
- var llmOptionsSchema = z.enum(["gemini", "anthropic", "huggingface"]);
35
+ var llmProviderSchema = z.enum([
36
+ "anthropic",
37
+ "gemini",
38
+ "openai",
39
+ "groq",
40
+ "mistral",
41
+ "ollama",
42
+ "xai",
43
+ "deepseek",
44
+ "openrouter",
45
+ "cerebras",
46
+ "lmstudio",
47
+ "azure",
48
+ "meta"
49
+ ]);
35
50
  var configSchema = z.object({
36
51
  debug: z.boolean().optional(),
37
52
  log: z.object({
@@ -43,14 +58,13 @@ var configSchema = z.object({
43
58
  prefix: z.string(),
44
59
  write: z.boolean().optional()
45
60
  }),
46
- keys: z.object({
47
- anthropicApiKey: z.string().optional(),
48
- geminiApiKey: z.string().optional()
49
- }),
50
61
  sourceLanguage: languageSchema,
62
+ defaultLanguage: languageSchema,
51
63
  languages: z.array(languageSchema),
52
64
  llm: z.object({
53
- choice: llmOptionsSchema,
65
+ provider: llmProviderSchema,
66
+ apiKey: z.string().optional(),
67
+ baseURL: z.string().optional(),
54
68
  model: z.string().nullable(),
55
69
  temperature: z.number().optional(),
56
70
  sleep: z.number().optional(),
@@ -64,17 +78,15 @@ var configSchema = z.object({
64
78
  globby: z.string().regex(/^\.\/.*/).optional()
65
79
  }).refine(
66
80
  (data) => {
67
- if (data.llm.choice === "gemini" && !data.keys.geminiApiKey) {
68
- return false;
69
- }
70
- if (data.llm.choice === "anthropic" && !data.keys.anthropicApiKey) {
71
- return false;
81
+ const noApiKeyRequired = ["ollama", "lmstudio"];
82
+ if (noApiKeyRequired.includes(data.llm.provider)) {
83
+ return true;
72
84
  }
73
- return true;
85
+ return !!data.llm.apiKey;
74
86
  },
75
87
  {
76
- message: "The API key corresponding to the chosen LLM must be present.",
77
- path: ["keys"]
88
+ message: "The API key must be present in llm.apiKey for the chosen provider.",
89
+ path: ["llm", "apiKey"]
78
90
  }
79
91
  );
80
92
 
@@ -110,7 +122,7 @@ Your task is to translate a given text and output **only one valid JSON object**
110
122
 
111
123
  Follow these rules strictly:
112
124
 
113
- 1. The original text is written in English.
125
+ 1. The original text is written in English or Spanish.
114
126
  2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
115
127
  - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
116
128
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
@@ -143,10 +155,10 @@ Translate the following text faithfully:
143
155
  function defaultPostPrompt(_config) {
144
156
  return "";
145
157
  }
146
- function prePrompt(config, append, replace) {
158
+ function prePrompt(config, prepend, replace) {
147
159
  return [
148
160
  // ...(append ? ['[SPECIFIC_INPUTS]', String(append), '[/SPECIFIC_INPUTS]'] : []),
149
- replace ? String(replace) : defaultPrePrompt(config, append)
161
+ replace ? String(replace) : defaultPrePrompt(config, prepend)
150
162
  ].join(" ").trim();
151
163
  }
152
164
  function postPrompt(config, prepend, replace) {