@gringow/gringow 0.1.4 → 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.
- package/dist/config.d.mts +6 -8
- package/dist/config.mjs +30 -20
- package/dist/config.test.mjs +37 -25
- package/dist/constants/default-config.mjs +3 -3
- package/dist/data/check-cache.mjs +31 -63
- package/dist/data/clear-cache.mjs +30 -20
- package/dist/data/create-cache-dir.mjs +30 -20
- package/dist/data/delete-cache-item.mjs +30 -20
- package/dist/data/get-cache.mjs +30 -20
- package/dist/data/get-or-create-cache.mjs +30 -20
- package/dist/data/save-cache.mjs +30 -20
- package/dist/data/write-cache-to-disk.mjs +30 -20
- package/dist/gringow.mjs +82 -491
- package/dist/index.mjs +82 -491
- package/dist/io/ask-llm.d.mts +3 -1
- package/dist/io/ask-llm.mjs +75 -449
- package/dist/schemas/config.shcema.d.mts +35 -47
- package/dist/schemas/config.shcema.mjs +25 -15
- package/dist/types/index.d.mts +3 -25
- package/gringow.config.js.example +2 -4
- package/gringow.config.json.example +4 -2
- package/package.json +2 -5
- package/dist/io/anthropic/ask.d.mts +0 -11
- package/dist/io/anthropic/ask.mjs +0 -192
- package/dist/io/anthropic/commit-response.d.mts +0 -21
- package/dist/io/anthropic/commit-response.mjs +0 -10
- package/dist/io/anthropic/index.d.mts +0 -14
- package/dist/io/anthropic/index.mjs +0 -210
- package/dist/io/anthropic/parse.d.mts +0 -20
- package/dist/io/anthropic/parse.mjs +0 -10
- package/dist/io/gemini/ask.d.mts +0 -11
- package/dist/io/gemini/ask.mjs +0 -234
- package/dist/io/gemini/commit-response.d.mts +0 -11
- package/dist/io/gemini/commit-response.mjs +0 -7
- package/dist/io/gemini/index.d.mts +0 -14
- package/dist/io/gemini/index.mjs +0 -250
- package/dist/io/gemini/parse.d.mts +0 -20
- package/dist/io/gemini/parse.mjs +0 -11
- package/dist/io/huggingface/ask.d.mts +0 -13
- package/dist/io/huggingface/ask.mjs +0 -407
- package/dist/io/huggingface/commit-response.d.mts +0 -39
- package/dist/io/huggingface/commit-response.mjs +0 -14
- package/dist/io/huggingface/index.d.mts +0 -13
- package/dist/io/huggingface/index.mjs +0 -428
- package/dist/io/huggingface/languages-map.d.mts +0 -191
- package/dist/io/huggingface/languages-map.mjs +0 -187
- package/dist/io/huggingface/parse.d.mts +0 -20
- package/dist/io/huggingface/parse.mjs +0 -9
package/dist/config.d.mts
CHANGED
|
@@ -26,10 +26,6 @@ declare function loadUserConfig(): Promise<GringowConfig>;
|
|
|
26
26
|
* @returns The user configuration.
|
|
27
27
|
*/
|
|
28
28
|
declare const awaitedConfig: Promise<{
|
|
29
|
-
keys: {
|
|
30
|
-
anthropicApiKey?: string | undefined;
|
|
31
|
-
geminiApiKey?: string | undefined;
|
|
32
|
-
};
|
|
33
29
|
log: {
|
|
34
30
|
level: "debug" | "info" | "warn" | "error" | "trace";
|
|
35
31
|
};
|
|
@@ -43,12 +39,14 @@ declare const awaitedConfig: Promise<{
|
|
|
43
39
|
defaultLanguage: string;
|
|
44
40
|
languages: string[];
|
|
45
41
|
llm: {
|
|
46
|
-
|
|
42
|
+
provider: "anthropic" | "gemini" | "openai" | "groq" | "mistral" | "ollama" | "xai" | "deepseek" | "openrouter" | "cerebras" | "lmstudio" | "azure" | "meta";
|
|
47
43
|
model: string | null;
|
|
48
|
-
temperature?: number | undefined;
|
|
49
|
-
sleep?: number | undefined;
|
|
50
44
|
prePrompt?: string | undefined;
|
|
51
45
|
postPrompt?: string | undefined;
|
|
46
|
+
apiKey?: string | undefined;
|
|
47
|
+
baseURL?: string | undefined;
|
|
48
|
+
temperature?: number | undefined;
|
|
49
|
+
sleep?: number | undefined;
|
|
52
50
|
prePromptReplace?: string | undefined;
|
|
53
51
|
postPromptReplace?: string | undefined;
|
|
54
52
|
prePromptAppend?: string | undefined;
|
|
@@ -59,7 +57,7 @@ declare const awaitedConfig: Promise<{
|
|
|
59
57
|
}>;
|
|
60
58
|
declare function defaultPrePrompt(config: GringowConfig, extraInstructions?: string): string;
|
|
61
59
|
declare function defaultPostPrompt(_config: GringowConfig): string;
|
|
62
|
-
declare function prePrompt(config: GringowConfig,
|
|
60
|
+
declare function prePrompt(config: GringowConfig, prepend?: string, replace?: string): string;
|
|
63
61
|
declare function postPrompt(config: GringowConfig, prepend?: string, replace?: string): string;
|
|
64
62
|
|
|
65
63
|
export { awaitedConfig, defaultPostPrompt, defaultPrePrompt, getConfigSource, isLocalConfigFound, loadUserConfig, postPrompt, prePrompt };
|
package/dist/config.mjs
CHANGED
|
@@ -16,20 +16,34 @@ var defaultConfig = {
|
|
|
16
16
|
prefix: "grw",
|
|
17
17
|
write: true
|
|
18
18
|
},
|
|
19
|
-
keys: {},
|
|
20
19
|
sourceLanguage: "en-US",
|
|
21
20
|
defaultLanguage: "pt-BR",
|
|
22
21
|
languages: ["pt-BR", "fr-CA"],
|
|
23
22
|
llm: {
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
provider: "openai",
|
|
24
|
+
apiKey: void 0,
|
|
25
|
+
model: "gpt-4o-mini",
|
|
26
26
|
temperature: 1,
|
|
27
27
|
sleep: 0
|
|
28
28
|
},
|
|
29
29
|
globby: "./src/**/*.{js,jsx,ts,tsx}"
|
|
30
30
|
};
|
|
31
31
|
var languageSchema = z.string().regex(/^[a-z]{2,3}(-[A-Z]{2})?$/);
|
|
32
|
-
var
|
|
32
|
+
var llmProviderSchema = z.enum([
|
|
33
|
+
"anthropic",
|
|
34
|
+
"gemini",
|
|
35
|
+
"openai",
|
|
36
|
+
"groq",
|
|
37
|
+
"mistral",
|
|
38
|
+
"ollama",
|
|
39
|
+
"xai",
|
|
40
|
+
"deepseek",
|
|
41
|
+
"openrouter",
|
|
42
|
+
"cerebras",
|
|
43
|
+
"lmstudio",
|
|
44
|
+
"azure",
|
|
45
|
+
"meta"
|
|
46
|
+
]);
|
|
33
47
|
var configSchema = z.object({
|
|
34
48
|
debug: z.boolean().optional(),
|
|
35
49
|
log: z.object({
|
|
@@ -41,15 +55,13 @@ var configSchema = z.object({
|
|
|
41
55
|
prefix: z.string(),
|
|
42
56
|
write: z.boolean().optional()
|
|
43
57
|
}),
|
|
44
|
-
keys: z.object({
|
|
45
|
-
anthropicApiKey: z.string().optional(),
|
|
46
|
-
geminiApiKey: z.string().optional()
|
|
47
|
-
}),
|
|
48
58
|
sourceLanguage: languageSchema,
|
|
49
59
|
defaultLanguage: languageSchema,
|
|
50
60
|
languages: z.array(languageSchema),
|
|
51
61
|
llm: z.object({
|
|
52
|
-
|
|
62
|
+
provider: llmProviderSchema,
|
|
63
|
+
apiKey: z.string().optional(),
|
|
64
|
+
baseURL: z.string().optional(),
|
|
53
65
|
model: z.string().nullable(),
|
|
54
66
|
temperature: z.number().optional(),
|
|
55
67
|
sleep: z.number().optional(),
|
|
@@ -63,17 +75,15 @@ var configSchema = z.object({
|
|
|
63
75
|
globby: z.string().regex(/^\.\/.*/).optional()
|
|
64
76
|
}).refine(
|
|
65
77
|
(data) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (data.llm.choice === "anthropic" && !data.keys.anthropicApiKey) {
|
|
70
|
-
return false;
|
|
78
|
+
const noApiKeyRequired = ["ollama", "lmstudio"];
|
|
79
|
+
if (noApiKeyRequired.includes(data.llm.provider)) {
|
|
80
|
+
return true;
|
|
71
81
|
}
|
|
72
|
-
return
|
|
82
|
+
return !!data.llm.apiKey;
|
|
73
83
|
},
|
|
74
84
|
{
|
|
75
|
-
message: "The API key
|
|
76
|
-
path: ["
|
|
85
|
+
message: "The API key must be present in llm.apiKey for the chosen provider.",
|
|
86
|
+
path: ["llm", "apiKey"]
|
|
77
87
|
}
|
|
78
88
|
);
|
|
79
89
|
|
|
@@ -115,7 +125,7 @@ Your task is to translate a given text and output **only one valid JSON object**
|
|
|
115
125
|
|
|
116
126
|
Follow these rules strictly:
|
|
117
127
|
|
|
118
|
-
1. The original text is written in English.
|
|
128
|
+
1. The original text is written in English or Spanish.
|
|
119
129
|
2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
|
|
120
130
|
- Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
|
|
121
131
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
@@ -148,10 +158,10 @@ Translate the following text faithfully:
|
|
|
148
158
|
function defaultPostPrompt(_config) {
|
|
149
159
|
return "";
|
|
150
160
|
}
|
|
151
|
-
function prePrompt(config,
|
|
161
|
+
function prePrompt(config, prepend, replace) {
|
|
152
162
|
return [
|
|
153
163
|
// ...(append ? ['[SPECIFIC_INPUTS]', String(append), '[/SPECIFIC_INPUTS]'] : []),
|
|
154
|
-
replace ? String(replace) : defaultPrePrompt(config,
|
|
164
|
+
replace ? String(replace) : defaultPrePrompt(config, prepend)
|
|
155
165
|
].join(" ").trim();
|
|
156
166
|
}
|
|
157
167
|
function postPrompt(config, prepend, replace) {
|
package/dist/config.test.mjs
CHANGED
|
@@ -18133,20 +18133,34 @@ var defaultConfig = {
|
|
|
18133
18133
|
prefix: "grw",
|
|
18134
18134
|
write: true
|
|
18135
18135
|
},
|
|
18136
|
-
keys: {},
|
|
18137
18136
|
sourceLanguage: "en-US",
|
|
18138
18137
|
defaultLanguage: "pt-BR",
|
|
18139
18138
|
languages: ["pt-BR", "fr-CA"],
|
|
18140
18139
|
llm: {
|
|
18141
|
-
|
|
18142
|
-
|
|
18140
|
+
provider: "openai",
|
|
18141
|
+
apiKey: void 0,
|
|
18142
|
+
model: "gpt-4o-mini",
|
|
18143
18143
|
temperature: 1,
|
|
18144
18144
|
sleep: 0
|
|
18145
18145
|
},
|
|
18146
18146
|
globby: "./src/**/*.{js,jsx,ts,tsx}"
|
|
18147
18147
|
};
|
|
18148
18148
|
var languageSchema = z.string().regex(/^[a-z]{2,3}(-[A-Z]{2})?$/);
|
|
18149
|
-
var
|
|
18149
|
+
var llmProviderSchema = z.enum([
|
|
18150
|
+
"anthropic",
|
|
18151
|
+
"gemini",
|
|
18152
|
+
"openai",
|
|
18153
|
+
"groq",
|
|
18154
|
+
"mistral",
|
|
18155
|
+
"ollama",
|
|
18156
|
+
"xai",
|
|
18157
|
+
"deepseek",
|
|
18158
|
+
"openrouter",
|
|
18159
|
+
"cerebras",
|
|
18160
|
+
"lmstudio",
|
|
18161
|
+
"azure",
|
|
18162
|
+
"meta"
|
|
18163
|
+
]);
|
|
18150
18164
|
var configSchema = z.object({
|
|
18151
18165
|
debug: z.boolean().optional(),
|
|
18152
18166
|
log: z.object({
|
|
@@ -18158,15 +18172,13 @@ var configSchema = z.object({
|
|
|
18158
18172
|
prefix: z.string(),
|
|
18159
18173
|
write: z.boolean().optional()
|
|
18160
18174
|
}),
|
|
18161
|
-
keys: z.object({
|
|
18162
|
-
anthropicApiKey: z.string().optional(),
|
|
18163
|
-
geminiApiKey: z.string().optional()
|
|
18164
|
-
}),
|
|
18165
18175
|
sourceLanguage: languageSchema,
|
|
18166
18176
|
defaultLanguage: languageSchema,
|
|
18167
18177
|
languages: z.array(languageSchema),
|
|
18168
18178
|
llm: z.object({
|
|
18169
|
-
|
|
18179
|
+
provider: llmProviderSchema,
|
|
18180
|
+
apiKey: z.string().optional(),
|
|
18181
|
+
baseURL: z.string().optional(),
|
|
18170
18182
|
model: z.string().nullable(),
|
|
18171
18183
|
temperature: z.number().optional(),
|
|
18172
18184
|
sleep: z.number().optional(),
|
|
@@ -18180,17 +18192,15 @@ var configSchema = z.object({
|
|
|
18180
18192
|
globby: z.string().regex(/^\.\/.*/).optional()
|
|
18181
18193
|
}).refine(
|
|
18182
18194
|
(data) => {
|
|
18183
|
-
|
|
18184
|
-
|
|
18185
|
-
|
|
18186
|
-
if (data.llm.choice === "anthropic" && !data.keys.anthropicApiKey) {
|
|
18187
|
-
return false;
|
|
18195
|
+
const noApiKeyRequired = ["ollama", "lmstudio"];
|
|
18196
|
+
if (noApiKeyRequired.includes(data.llm.provider)) {
|
|
18197
|
+
return true;
|
|
18188
18198
|
}
|
|
18189
|
-
return
|
|
18199
|
+
return !!data.llm.apiKey;
|
|
18190
18200
|
},
|
|
18191
18201
|
{
|
|
18192
|
-
message: "The API key
|
|
18193
|
-
path: ["
|
|
18202
|
+
message: "The API key must be present in llm.apiKey for the chosen provider.",
|
|
18203
|
+
path: ["llm", "apiKey"]
|
|
18194
18204
|
}
|
|
18195
18205
|
);
|
|
18196
18206
|
|
|
@@ -18226,7 +18236,7 @@ Your task is to translate a given text and output **only one valid JSON object**
|
|
|
18226
18236
|
|
|
18227
18237
|
Follow these rules strictly:
|
|
18228
18238
|
|
|
18229
|
-
1. The original text is written in English.
|
|
18239
|
+
1. The original text is written in English or Spanish.
|
|
18230
18240
|
2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
|
|
18231
18241
|
- Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
|
|
18232
18242
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
@@ -18259,10 +18269,10 @@ Translate the following text faithfully:
|
|
|
18259
18269
|
function defaultPostPrompt(_config) {
|
|
18260
18270
|
return "";
|
|
18261
18271
|
}
|
|
18262
|
-
function prePrompt(config2,
|
|
18272
|
+
function prePrompt(config2, prepend, replace) {
|
|
18263
18273
|
return [
|
|
18264
18274
|
// ...(append ? ['[SPECIFIC_INPUTS]', String(append), '[/SPECIFIC_INPUTS]'] : []),
|
|
18265
|
-
replace ? String(replace) : defaultPrePrompt(config2,
|
|
18275
|
+
replace ? String(replace) : defaultPrePrompt(config2, prepend)
|
|
18266
18276
|
].join(" ").trim();
|
|
18267
18277
|
}
|
|
18268
18278
|
function postPrompt(config2, prepend, replace) {
|
|
@@ -18281,9 +18291,11 @@ describe("config", () => {
|
|
|
18281
18291
|
languages: ["pt-BR", "fr-CA", "es-ES"]
|
|
18282
18292
|
};
|
|
18283
18293
|
const result2 = defaultPrePrompt(config2);
|
|
18284
|
-
globalExpect(result2).toContain("You are a translation generator.");
|
|
18285
|
-
globalExpect(result2).toContain("Your task is to output **only one valid JSON object**");
|
|
18286
|
-
globalExpect(result2).toContain("pt-BR
|
|
18294
|
+
globalExpect(result2).toContain("You are a ultimate translation generator server api.");
|
|
18295
|
+
globalExpect(result2).toContain("Your task is to translate a given text and output **only one valid JSON object**");
|
|
18296
|
+
globalExpect(result2).toContain("pt-BR");
|
|
18297
|
+
globalExpect(result2).toContain("fr-CA");
|
|
18298
|
+
globalExpect(result2).toContain("es-ES");
|
|
18287
18299
|
globalExpect(result2).toContain('"original": "<original input text>"');
|
|
18288
18300
|
globalExpect(result2).toContain('"translation": {');
|
|
18289
18301
|
});
|
|
@@ -18321,7 +18333,7 @@ describe("config", () => {
|
|
|
18321
18333
|
};
|
|
18322
18334
|
const result2 = prePrompt(config2, "Additional instructions");
|
|
18323
18335
|
globalExpect(result2).toContain("extraInstructions: Additional instructions");
|
|
18324
|
-
globalExpect(result2).toContain("You are a translation generator.");
|
|
18336
|
+
globalExpect(result2).toContain("You are a ultimate translation generator server api.");
|
|
18325
18337
|
});
|
|
18326
18338
|
it("should use prePromptReplace and prePromptAppend together", () => {
|
|
18327
18339
|
const config2 = {
|
|
@@ -18335,7 +18347,7 @@ describe("config", () => {
|
|
|
18335
18347
|
...defaultConfig
|
|
18336
18348
|
};
|
|
18337
18349
|
const result2 = prePrompt(config2);
|
|
18338
|
-
globalExpect(result2).toContain("You are a translation generator.");
|
|
18350
|
+
globalExpect(result2).toContain("You are a ultimate translation generator server api.");
|
|
18339
18351
|
globalExpect(result2).toContain("Translate the following text faithfully:");
|
|
18340
18352
|
});
|
|
18341
18353
|
});
|
|
@@ -10,13 +10,13 @@ var defaultConfig = {
|
|
|
10
10
|
prefix: "grw",
|
|
11
11
|
write: true
|
|
12
12
|
},
|
|
13
|
-
keys: {},
|
|
14
13
|
sourceLanguage: "en-US",
|
|
15
14
|
defaultLanguage: "pt-BR",
|
|
16
15
|
languages: ["pt-BR", "fr-CA"],
|
|
17
16
|
llm: {
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
provider: "openai",
|
|
18
|
+
apiKey: void 0,
|
|
19
|
+
model: "gpt-4o-mini",
|
|
20
20
|
temperature: 1,
|
|
21
21
|
sleep: 0
|
|
22
22
|
},
|
|
@@ -19,20 +19,34 @@ var defaultConfig = {
|
|
|
19
19
|
prefix: "grw",
|
|
20
20
|
write: true
|
|
21
21
|
},
|
|
22
|
-
keys: {},
|
|
23
22
|
sourceLanguage: "en-US",
|
|
24
23
|
defaultLanguage: "pt-BR",
|
|
25
24
|
languages: ["pt-BR", "fr-CA"],
|
|
26
25
|
llm: {
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
provider: "openai",
|
|
27
|
+
apiKey: void 0,
|
|
28
|
+
model: "gpt-4o-mini",
|
|
29
29
|
temperature: 1,
|
|
30
30
|
sleep: 0
|
|
31
31
|
},
|
|
32
32
|
globby: "./src/**/*.{js,jsx,ts,tsx}"
|
|
33
33
|
};
|
|
34
34
|
var languageSchema = z.string().regex(/^[a-z]{2,3}(-[A-Z]{2})?$/);
|
|
35
|
-
var
|
|
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
|
+
]);
|
|
36
50
|
var configSchema = z.object({
|
|
37
51
|
debug: z.boolean().optional(),
|
|
38
52
|
log: z.object({
|
|
@@ -44,15 +58,13 @@ var configSchema = z.object({
|
|
|
44
58
|
prefix: z.string(),
|
|
45
59
|
write: z.boolean().optional()
|
|
46
60
|
}),
|
|
47
|
-
keys: z.object({
|
|
48
|
-
anthropicApiKey: z.string().optional(),
|
|
49
|
-
geminiApiKey: z.string().optional()
|
|
50
|
-
}),
|
|
51
61
|
sourceLanguage: languageSchema,
|
|
52
62
|
defaultLanguage: languageSchema,
|
|
53
63
|
languages: z.array(languageSchema),
|
|
54
64
|
llm: z.object({
|
|
55
|
-
|
|
65
|
+
provider: llmProviderSchema,
|
|
66
|
+
apiKey: z.string().optional(),
|
|
67
|
+
baseURL: z.string().optional(),
|
|
56
68
|
model: z.string().nullable(),
|
|
57
69
|
temperature: z.number().optional(),
|
|
58
70
|
sleep: z.number().optional(),
|
|
@@ -66,17 +78,15 @@ var configSchema = z.object({
|
|
|
66
78
|
globby: z.string().regex(/^\.\/.*/).optional()
|
|
67
79
|
}).refine(
|
|
68
80
|
(data) => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (data.llm.choice === "anthropic" && !data.keys.anthropicApiKey) {
|
|
73
|
-
return false;
|
|
81
|
+
const noApiKeyRequired = ["ollama", "lmstudio"];
|
|
82
|
+
if (noApiKeyRequired.includes(data.llm.provider)) {
|
|
83
|
+
return true;
|
|
74
84
|
}
|
|
75
|
-
return
|
|
85
|
+
return !!data.llm.apiKey;
|
|
76
86
|
},
|
|
77
87
|
{
|
|
78
|
-
message: "The API key
|
|
79
|
-
path: ["
|
|
88
|
+
message: "The API key must be present in llm.apiKey for the chosen provider.",
|
|
89
|
+
path: ["llm", "apiKey"]
|
|
80
90
|
}
|
|
81
91
|
);
|
|
82
92
|
|
|
@@ -112,7 +122,7 @@ Your task is to translate a given text and output **only one valid JSON object**
|
|
|
112
122
|
|
|
113
123
|
Follow these rules strictly:
|
|
114
124
|
|
|
115
|
-
1. The original text is written in English.
|
|
125
|
+
1. The original text is written in English or Spanish.
|
|
116
126
|
2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
|
|
117
127
|
- Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
|
|
118
128
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
@@ -145,10 +155,10 @@ Translate the following text faithfully:
|
|
|
145
155
|
function defaultPostPrompt(_config) {
|
|
146
156
|
return "";
|
|
147
157
|
}
|
|
148
|
-
function prePrompt(config,
|
|
158
|
+
function prePrompt(config, prepend, replace) {
|
|
149
159
|
return [
|
|
150
160
|
// ...(append ? ['[SPECIFIC_INPUTS]', String(append), '[/SPECIFIC_INPUTS]'] : []),
|
|
151
|
-
replace ? String(replace) : defaultPrePrompt(config,
|
|
161
|
+
replace ? String(replace) : defaultPrePrompt(config, prepend)
|
|
152
162
|
].join(" ").trim();
|
|
153
163
|
}
|
|
154
164
|
function postPrompt(config, prepend, replace) {
|
|
@@ -412,53 +422,11 @@ async function getOrCreateCache() {
|
|
|
412
422
|
return rawCache ? JSON.parse(rawCache?.toString()) : {};
|
|
413
423
|
}
|
|
414
424
|
|
|
415
|
-
// src/logger.ts
|
|
416
|
-
var Dim = "\x1B[2m";
|
|
417
|
-
var FgGreen = "\x1B[32m";
|
|
418
|
-
var FgYellow = "\x1B[33m";
|
|
419
|
-
var FgCyan = "\x1B[36m";
|
|
420
|
-
var FgWhite = "\x1B[37m";
|
|
421
|
-
var BgRed = "\x1B[41m";
|
|
422
|
-
var Clear = "\x1B[0m";
|
|
423
|
-
var Colors = {
|
|
424
|
-
debug: `${Dim}${FgGreen}`,
|
|
425
|
-
trace: `${Dim}${FgCyan}`,
|
|
426
|
-
info: `${FgCyan}`,
|
|
427
|
-
error: `${BgRed}${FgWhite}`,
|
|
428
|
-
warn: `${FgYellow}`,
|
|
429
|
-
verbose: `${FgWhite}`
|
|
430
|
-
};
|
|
431
|
-
var isProd = process.env.NODE_ENV === "production";
|
|
432
|
-
function log(level, ...params) {
|
|
433
|
-
console.log(`${!isProd ? Colors[level] : ""}${String(level).toUpperCase()} `, ...params, `${!isProd ? Clear : ""}`);
|
|
434
|
-
}
|
|
435
|
-
var logger = {
|
|
436
|
-
debug(...params) {
|
|
437
|
-
return log("debug", ...params);
|
|
438
|
-
},
|
|
439
|
-
trace(...params) {
|
|
440
|
-
return log("trace", ...params);
|
|
441
|
-
},
|
|
442
|
-
info(...params) {
|
|
443
|
-
return log("info", ...params);
|
|
444
|
-
},
|
|
445
|
-
warn(...params) {
|
|
446
|
-
return log("warn", ...params);
|
|
447
|
-
},
|
|
448
|
-
error(...params) {
|
|
449
|
-
return log("error", ...params);
|
|
450
|
-
},
|
|
451
|
-
verbose(...params) {
|
|
452
|
-
return log("verbose", ...params);
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
var logger_default = logger;
|
|
456
|
-
|
|
457
425
|
// src/data/check-cache.ts
|
|
458
426
|
async function checkCache(cacheId) {
|
|
459
427
|
const cache = await getOrCreateCache();
|
|
460
428
|
if (cache?.[cacheId]) {
|
|
461
|
-
|
|
429
|
+
console.log(`Cache hit, id:${cacheId}`);
|
|
462
430
|
return cache[cacheId];
|
|
463
431
|
}
|
|
464
432
|
return void 0;
|
|
@@ -19,20 +19,34 @@ var defaultConfig = {
|
|
|
19
19
|
prefix: "grw",
|
|
20
20
|
write: true
|
|
21
21
|
},
|
|
22
|
-
keys: {},
|
|
23
22
|
sourceLanguage: "en-US",
|
|
24
23
|
defaultLanguage: "pt-BR",
|
|
25
24
|
languages: ["pt-BR", "fr-CA"],
|
|
26
25
|
llm: {
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
provider: "openai",
|
|
27
|
+
apiKey: void 0,
|
|
28
|
+
model: "gpt-4o-mini",
|
|
29
29
|
temperature: 1,
|
|
30
30
|
sleep: 0
|
|
31
31
|
},
|
|
32
32
|
globby: "./src/**/*.{js,jsx,ts,tsx}"
|
|
33
33
|
};
|
|
34
34
|
var languageSchema = z.string().regex(/^[a-z]{2,3}(-[A-Z]{2})?$/);
|
|
35
|
-
var
|
|
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
|
+
]);
|
|
36
50
|
var configSchema = z.object({
|
|
37
51
|
debug: z.boolean().optional(),
|
|
38
52
|
log: z.object({
|
|
@@ -44,15 +58,13 @@ var configSchema = z.object({
|
|
|
44
58
|
prefix: z.string(),
|
|
45
59
|
write: z.boolean().optional()
|
|
46
60
|
}),
|
|
47
|
-
keys: z.object({
|
|
48
|
-
anthropicApiKey: z.string().optional(),
|
|
49
|
-
geminiApiKey: z.string().optional()
|
|
50
|
-
}),
|
|
51
61
|
sourceLanguage: languageSchema,
|
|
52
62
|
defaultLanguage: languageSchema,
|
|
53
63
|
languages: z.array(languageSchema),
|
|
54
64
|
llm: z.object({
|
|
55
|
-
|
|
65
|
+
provider: llmProviderSchema,
|
|
66
|
+
apiKey: z.string().optional(),
|
|
67
|
+
baseURL: z.string().optional(),
|
|
56
68
|
model: z.string().nullable(),
|
|
57
69
|
temperature: z.number().optional(),
|
|
58
70
|
sleep: z.number().optional(),
|
|
@@ -66,17 +78,15 @@ var configSchema = z.object({
|
|
|
66
78
|
globby: z.string().regex(/^\.\/.*/).optional()
|
|
67
79
|
}).refine(
|
|
68
80
|
(data) => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (data.llm.choice === "anthropic" && !data.keys.anthropicApiKey) {
|
|
73
|
-
return false;
|
|
81
|
+
const noApiKeyRequired = ["ollama", "lmstudio"];
|
|
82
|
+
if (noApiKeyRequired.includes(data.llm.provider)) {
|
|
83
|
+
return true;
|
|
74
84
|
}
|
|
75
|
-
return
|
|
85
|
+
return !!data.llm.apiKey;
|
|
76
86
|
},
|
|
77
87
|
{
|
|
78
|
-
message: "The API key
|
|
79
|
-
path: ["
|
|
88
|
+
message: "The API key must be present in llm.apiKey for the chosen provider.",
|
|
89
|
+
path: ["llm", "apiKey"]
|
|
80
90
|
}
|
|
81
91
|
);
|
|
82
92
|
|
|
@@ -112,7 +122,7 @@ Your task is to translate a given text and output **only one valid JSON object**
|
|
|
112
122
|
|
|
113
123
|
Follow these rules strictly:
|
|
114
124
|
|
|
115
|
-
1. The original text is written in English.
|
|
125
|
+
1. The original text is written in English or Spanish.
|
|
116
126
|
2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
|
|
117
127
|
- Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
|
|
118
128
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
@@ -145,10 +155,10 @@ Translate the following text faithfully:
|
|
|
145
155
|
function defaultPostPrompt(_config) {
|
|
146
156
|
return "";
|
|
147
157
|
}
|
|
148
|
-
function prePrompt(config,
|
|
158
|
+
function prePrompt(config, prepend, replace) {
|
|
149
159
|
return [
|
|
150
160
|
// ...(append ? ['[SPECIFIC_INPUTS]', String(append), '[/SPECIFIC_INPUTS]'] : []),
|
|
151
|
-
replace ? String(replace) : defaultPrePrompt(config,
|
|
161
|
+
replace ? String(replace) : defaultPrePrompt(config, prepend)
|
|
152
162
|
].join(" ").trim();
|
|
153
163
|
}
|
|
154
164
|
function postPrompt(config, prepend, replace) {
|
|
@@ -223,20 +223,34 @@ var defaultConfig = {
|
|
|
223
223
|
prefix: "grw",
|
|
224
224
|
write: true
|
|
225
225
|
},
|
|
226
|
-
keys: {},
|
|
227
226
|
sourceLanguage: "en-US",
|
|
228
227
|
defaultLanguage: "pt-BR",
|
|
229
228
|
languages: ["pt-BR", "fr-CA"],
|
|
230
229
|
llm: {
|
|
231
|
-
|
|
232
|
-
|
|
230
|
+
provider: "openai",
|
|
231
|
+
apiKey: void 0,
|
|
232
|
+
model: "gpt-4o-mini",
|
|
233
233
|
temperature: 1,
|
|
234
234
|
sleep: 0
|
|
235
235
|
},
|
|
236
236
|
globby: "./src/**/*.{js,jsx,ts,tsx}"
|
|
237
237
|
};
|
|
238
238
|
var languageSchema = z.string().regex(/^[a-z]{2,3}(-[A-Z]{2})?$/);
|
|
239
|
-
var
|
|
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
|
+
]);
|
|
240
254
|
var configSchema = z.object({
|
|
241
255
|
debug: z.boolean().optional(),
|
|
242
256
|
log: z.object({
|
|
@@ -248,15 +262,13 @@ var configSchema = z.object({
|
|
|
248
262
|
prefix: z.string(),
|
|
249
263
|
write: z.boolean().optional()
|
|
250
264
|
}),
|
|
251
|
-
keys: z.object({
|
|
252
|
-
anthropicApiKey: z.string().optional(),
|
|
253
|
-
geminiApiKey: z.string().optional()
|
|
254
|
-
}),
|
|
255
265
|
sourceLanguage: languageSchema,
|
|
256
266
|
defaultLanguage: languageSchema,
|
|
257
267
|
languages: z.array(languageSchema),
|
|
258
268
|
llm: z.object({
|
|
259
|
-
|
|
269
|
+
provider: llmProviderSchema,
|
|
270
|
+
apiKey: z.string().optional(),
|
|
271
|
+
baseURL: z.string().optional(),
|
|
260
272
|
model: z.string().nullable(),
|
|
261
273
|
temperature: z.number().optional(),
|
|
262
274
|
sleep: z.number().optional(),
|
|
@@ -270,17 +282,15 @@ var configSchema = z.object({
|
|
|
270
282
|
globby: z.string().regex(/^\.\/.*/).optional()
|
|
271
283
|
}).refine(
|
|
272
284
|
(data) => {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
if (data.llm.choice === "anthropic" && !data.keys.anthropicApiKey) {
|
|
277
|
-
return false;
|
|
285
|
+
const noApiKeyRequired = ["ollama", "lmstudio"];
|
|
286
|
+
if (noApiKeyRequired.includes(data.llm.provider)) {
|
|
287
|
+
return true;
|
|
278
288
|
}
|
|
279
|
-
return
|
|
289
|
+
return !!data.llm.apiKey;
|
|
280
290
|
},
|
|
281
291
|
{
|
|
282
|
-
message: "The API key
|
|
283
|
-
path: ["
|
|
292
|
+
message: "The API key must be present in llm.apiKey for the chosen provider.",
|
|
293
|
+
path: ["llm", "apiKey"]
|
|
284
294
|
}
|
|
285
295
|
);
|
|
286
296
|
|
|
@@ -316,7 +326,7 @@ Your task is to translate a given text and output **only one valid JSON object**
|
|
|
316
326
|
|
|
317
327
|
Follow these rules strictly:
|
|
318
328
|
|
|
319
|
-
1. The original text is written in English.
|
|
329
|
+
1. The original text is written in English or Spanish.
|
|
320
330
|
2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
|
|
321
331
|
- Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
|
|
322
332
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
@@ -349,10 +359,10 @@ Translate the following text faithfully:
|
|
|
349
359
|
function defaultPostPrompt(_config) {
|
|
350
360
|
return "";
|
|
351
361
|
}
|
|
352
|
-
function prePrompt(config,
|
|
362
|
+
function prePrompt(config, prepend, replace) {
|
|
353
363
|
return [
|
|
354
364
|
// ...(append ? ['[SPECIFIC_INPUTS]', String(append), '[/SPECIFIC_INPUTS]'] : []),
|
|
355
|
-
replace ? String(replace) : defaultPrePrompt(config,
|
|
365
|
+
replace ? String(replace) : defaultPrePrompt(config, prepend)
|
|
356
366
|
].join(" ").trim();
|
|
357
367
|
}
|
|
358
368
|
function postPrompt(config, prepend, replace) {
|