@gringow/gringow 0.1.4 → 0.2.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 +31 -36
- package/dist/config.d.mts +4 -6
- package/dist/config.mjs +30 -20
- package/dist/config.test.mjs +42 -30
- package/dist/constants/default-config.mjs +3 -3
- package/dist/create-cache-id.test.mjs +5 -5
- 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/md5.test.mjs +5 -5
- package/dist/data/save-cache.mjs +30 -20
- package/dist/data/write-cache-to-disk.mjs +30 -20
- package/dist/flat-template-string.test.mjs +5 -5
- 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/logger.test.mjs +5 -5
- package/dist/schemas/config.shcema.d.mts +23 -35
- 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/README.md
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@gringow/gringow)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
AI-powered translation library for template strings using multiple LLM providers
|
|
6
|
+
AI-powered translation library for template strings using multiple LLM providers via `multi-llm-ts`. Gringow provides smart caching, deterministic content hashing, and seamless integration for modern JavaScript/TypeScript projects.
|
|
7
7
|
|
|
8
8
|
## Features
|
|
9
9
|
|
|
10
10
|
- 🌍 **Multi-language translation** using LLM providers
|
|
11
11
|
- 🏷️ **Tagged template literal** syntax for inline translations
|
|
12
12
|
- 💾 **Smart caching** with content-based hashing
|
|
13
|
-
- 🔌 **
|
|
14
|
-
-
|
|
13
|
+
- 🔌 **Multiple LLM providers** (OpenAI default, Anthropic, Gemini, Groq, Mistral, Ollama, and more)
|
|
14
|
+
- ⚙️ **Config-driven behavior** through `gringow.config.*`
|
|
15
15
|
- 📦 **Optimized builds** via Vite/Next.js plugins
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
@@ -87,8 +87,8 @@ For client-side interpolation without Node.js dependencies:
|
|
|
87
87
|
```typescript
|
|
88
88
|
import { interpolateTemplate } from '@gringow/gringow/browser'
|
|
89
89
|
|
|
90
|
-
const template = 'Hello {name}, you have {count} messages'
|
|
91
|
-
const result = interpolateTemplate(template,
|
|
90
|
+
const template = 'Hello ${name}, you have ${count} messages'
|
|
91
|
+
const result = interpolateTemplate(template, ['Alice', 5])
|
|
92
92
|
console.log(result) // "Hello Alice, you have 5 messages"
|
|
93
93
|
```
|
|
94
94
|
|
|
@@ -109,15 +109,13 @@ export default {
|
|
|
109
109
|
prefix: 'grw',
|
|
110
110
|
write: true,
|
|
111
111
|
},
|
|
112
|
-
keys: {
|
|
113
|
-
anthropicApiKey: process.env.ANTHROPIC_API_KEY,
|
|
114
|
-
geminiApiKey: process.env.GEMINI_API_KEY,
|
|
115
|
-
},
|
|
116
112
|
sourceLanguage: 'en-US',
|
|
113
|
+
defaultLanguage: 'pt-BR',
|
|
117
114
|
languages: ['pt-BR', 'fr-CA'],
|
|
118
115
|
llm: {
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
provider: 'openai',
|
|
117
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
118
|
+
model: 'gpt-4o-mini',
|
|
121
119
|
temperature: 1.0,
|
|
122
120
|
sleep: 0,
|
|
123
121
|
},
|
|
@@ -130,11 +128,9 @@ export default {
|
|
|
130
128
|
```js
|
|
131
129
|
// gringow.config.js
|
|
132
130
|
export default {
|
|
133
|
-
keys: {
|
|
134
|
-
geminiApiKey: process.env.GEMINI_API_KEY,
|
|
135
|
-
},
|
|
136
131
|
llm: {
|
|
137
|
-
|
|
132
|
+
provider: 'gemini',
|
|
133
|
+
apiKey: process.env.GEMINI_API_KEY,
|
|
138
134
|
model: 'gemini-2.0-flash',
|
|
139
135
|
prePromptAppend: 'Please respond in a friendly tone.',
|
|
140
136
|
},
|
|
@@ -147,11 +143,9 @@ export default {
|
|
|
147
143
|
```js
|
|
148
144
|
// gringow.config.js
|
|
149
145
|
export default {
|
|
150
|
-
keys: {
|
|
151
|
-
anthropicApiKey: process.env.ANTHROPIC_API_KEY,
|
|
152
|
-
},
|
|
153
146
|
llm: {
|
|
154
|
-
|
|
147
|
+
provider: 'anthropic',
|
|
148
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
155
149
|
model: 'claude-3-5-sonnet-20241022',
|
|
156
150
|
temperature: 0.7,
|
|
157
151
|
},
|
|
@@ -165,7 +159,8 @@ Fine-tune LLM behavior with prompt options:
|
|
|
165
159
|
```js
|
|
166
160
|
export default {
|
|
167
161
|
llm: {
|
|
168
|
-
|
|
162
|
+
provider: 'openai',
|
|
163
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
169
164
|
prePrompt: 'Translate the following text:', // Default prompt prefix
|
|
170
165
|
postPrompt: 'Ensure translations are natural.', // Additional context
|
|
171
166
|
prePromptAppend: 'Use formal language.', // Appended to pre-prompt
|
|
@@ -177,22 +172,23 @@ export default {
|
|
|
177
172
|
|
|
178
173
|
## LLM Providers
|
|
179
174
|
|
|
180
|
-
###
|
|
175
|
+
### OpenAI (Default)
|
|
181
176
|
|
|
182
|
-
|
|
177
|
+
Uses OpenAI through `multi-llm-ts`. **Requires API key.**
|
|
183
178
|
|
|
184
179
|
```js
|
|
185
180
|
// gringow.config.js
|
|
186
181
|
export default {
|
|
187
182
|
llm: {
|
|
188
|
-
|
|
189
|
-
|
|
183
|
+
provider: 'openai',
|
|
184
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
185
|
+
model: 'gpt-4o-mini',
|
|
190
186
|
},
|
|
191
187
|
}
|
|
192
188
|
```
|
|
193
189
|
|
|
194
|
-
**Pros**:
|
|
195
|
-
**Cons**:
|
|
190
|
+
**Pros**: Broad model availability, simple default setup
|
|
191
|
+
**Cons**: API costs, requires internet
|
|
196
192
|
|
|
197
193
|
### Anthropic
|
|
198
194
|
|
|
@@ -201,11 +197,9 @@ Uses Claude models via Anthropic API. **Requires API key.**
|
|
|
201
197
|
```js
|
|
202
198
|
// gringow.config.js
|
|
203
199
|
export default {
|
|
204
|
-
keys: {
|
|
205
|
-
anthropicApiKey: process.env.ANTHROPIC_API_KEY,
|
|
206
|
-
},
|
|
207
200
|
llm: {
|
|
208
|
-
|
|
201
|
+
provider: 'anthropic',
|
|
202
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
209
203
|
model: 'claude-3-5-sonnet-20241022',
|
|
210
204
|
},
|
|
211
205
|
}
|
|
@@ -221,11 +215,9 @@ Uses Google's Gemini models. **Requires API key.**
|
|
|
221
215
|
```js
|
|
222
216
|
// gringow.config.js
|
|
223
217
|
export default {
|
|
224
|
-
keys: {
|
|
225
|
-
geminiApiKey: process.env.GEMINI_API_KEY,
|
|
226
|
-
},
|
|
227
218
|
llm: {
|
|
228
|
-
|
|
219
|
+
provider: 'gemini',
|
|
220
|
+
apiKey: process.env.GEMINI_API_KEY,
|
|
229
221
|
model: 'gemini-2.0-flash',
|
|
230
222
|
},
|
|
231
223
|
}
|
|
@@ -275,13 +267,16 @@ import {
|
|
|
275
267
|
import {
|
|
276
268
|
createCacheId, // Generate cache ID from string
|
|
277
269
|
flatTemplateString, // Flatten template literal to string
|
|
278
|
-
interpolateTemplate, // Browser-safe interpolation (from /browser export)
|
|
279
270
|
awaitedConfig, // Access resolved configuration
|
|
280
271
|
isLocalConfigFound, // Check if local config exists
|
|
281
272
|
getConfigSource, // Get config file path
|
|
282
273
|
} from '@gringow/gringow'
|
|
283
274
|
```
|
|
284
275
|
|
|
276
|
+
```typescript
|
|
277
|
+
import { interpolateTemplate } from '@gringow/gringow/browser'
|
|
278
|
+
```
|
|
279
|
+
|
|
285
280
|
### Type Definitions
|
|
286
281
|
|
|
287
282
|
```typescript
|
|
@@ -344,7 +339,7 @@ pnpm run test:watch
|
|
|
344
339
|
|
|
345
340
|
Gringow has official integrations for modern web frameworks:
|
|
346
341
|
|
|
347
|
-
- **[@gringow/cli](https://www.npmjs.com/package/@gringow/gringow-cli)** - Command-line interface for cache management and translations
|
|
342
|
+
- **[@gringow/gringow-cli](https://www.npmjs.com/package/@gringow/gringow-cli)** - Command-line interface for cache management and translations
|
|
348
343
|
- **[@gringow/gringow-vite](https://www.npmjs.com/package/@gringow/gringow-vite)** - Vite plugin for build-time translation extraction
|
|
349
344
|
- **[@gringow/gringow-react](https://www.npmjs.com/package/@gringow/gringow-react)** - React hooks and components
|
|
350
345
|
- **[@gringow/gringow-shadow](https://www.npmjs.com/package/@gringow/gringow-shadow)** - Web Component layer (vanilla JS)
|
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,8 +39,10 @@ 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;
|
|
44
|
+
apiKey?: string | undefined;
|
|
45
|
+
baseURL?: string | undefined;
|
|
48
46
|
temperature?: number | undefined;
|
|
49
47
|
sleep?: number | undefined;
|
|
50
48
|
prePrompt?: 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
|
@@ -13239,7 +13239,7 @@ function findTestFileStackTrace(error, each) {
|
|
|
13239
13239
|
globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now;
|
|
13240
13240
|
globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now;
|
|
13241
13241
|
|
|
13242
|
-
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.
|
|
13242
|
+
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.2_msw@2.12.8_@types+node@22.16.4_typescript@5.7.3__terser@5.44.1/node_modules/vitest/dist/chunks/utils.C8RiOc4B.js
|
|
13243
13243
|
var NAME_WORKER_STATE = "__vitest_worker__";
|
|
13244
13244
|
function getWorkerState() {
|
|
13245
13245
|
const workerState = globalThis[NAME_WORKER_STATE];
|
|
@@ -13299,7 +13299,7 @@ async function waitForImportsToResolve() {
|
|
|
13299
13299
|
await waitForImportsToResolve();
|
|
13300
13300
|
}
|
|
13301
13301
|
|
|
13302
|
-
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.
|
|
13302
|
+
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.2_msw@2.12.8_@types+node@22.16.4_typescript@5.7.3__terser@5.44.1/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.js
|
|
13303
13303
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
13304
13304
|
function getDefaultExportFromCjs2(x2) {
|
|
13305
13305
|
return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
|
|
@@ -15333,7 +15333,7 @@ var SnapshotClient = class {
|
|
|
15333
15333
|
}
|
|
15334
15334
|
};
|
|
15335
15335
|
|
|
15336
|
-
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.
|
|
15336
|
+
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.2_msw@2.12.8_@types+node@22.16.4_typescript@5.7.3__terser@5.44.1/node_modules/vitest/dist/chunks/date.W2xKR2qe.js
|
|
15337
15337
|
var RealDate = Date;
|
|
15338
15338
|
var now2 = null;
|
|
15339
15339
|
var MockDate = class _MockDate extends RealDate {
|
|
@@ -15386,7 +15386,7 @@ function resetDate() {
|
|
|
15386
15386
|
globalThis.Date = RealDate;
|
|
15387
15387
|
}
|
|
15388
15388
|
|
|
15389
|
-
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.
|
|
15389
|
+
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.2_msw@2.12.8_@types+node@22.16.4_typescript@5.7.3__terser@5.44.1/node_modules/vitest/dist/chunks/vi.DgezovHB.js
|
|
15390
15390
|
var unsupported = [
|
|
15391
15391
|
// .poll is meant to retry matchers until they succeed, and
|
|
15392
15392
|
// snapshots will always succeed as long as the poll method doesn't thow an error
|
|
@@ -18118,7 +18118,7 @@ function getImporter(name) {
|
|
|
18118
18118
|
return stack?.file || "";
|
|
18119
18119
|
}
|
|
18120
18120
|
|
|
18121
|
-
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.
|
|
18121
|
+
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.2_msw@2.12.8_@types+node@22.16.4_typescript@5.7.3__terser@5.44.1/node_modules/vitest/dist/index.js
|
|
18122
18122
|
__toESM(require_dist(), 1);
|
|
18123
18123
|
|
|
18124
18124
|
// src/constants/default-config.ts
|
|
@@ -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
|
},
|
|
@@ -13236,7 +13236,7 @@ function findTestFileStackTrace(error, each) {
|
|
|
13236
13236
|
globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now;
|
|
13237
13237
|
globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now;
|
|
13238
13238
|
|
|
13239
|
-
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.
|
|
13239
|
+
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.2_msw@2.12.8_@types+node@22.16.4_typescript@5.7.3__terser@5.44.1/node_modules/vitest/dist/chunks/utils.C8RiOc4B.js
|
|
13240
13240
|
var NAME_WORKER_STATE = "__vitest_worker__";
|
|
13241
13241
|
function getWorkerState() {
|
|
13242
13242
|
const workerState = globalThis[NAME_WORKER_STATE];
|
|
@@ -13296,7 +13296,7 @@ async function waitForImportsToResolve() {
|
|
|
13296
13296
|
await waitForImportsToResolve();
|
|
13297
13297
|
}
|
|
13298
13298
|
|
|
13299
|
-
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.
|
|
13299
|
+
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.2_msw@2.12.8_@types+node@22.16.4_typescript@5.7.3__terser@5.44.1/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.js
|
|
13300
13300
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
13301
13301
|
function getDefaultExportFromCjs2(x2) {
|
|
13302
13302
|
return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
|
|
@@ -15330,7 +15330,7 @@ var SnapshotClient = class {
|
|
|
15330
15330
|
}
|
|
15331
15331
|
};
|
|
15332
15332
|
|
|
15333
|
-
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.
|
|
15333
|
+
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.2_msw@2.12.8_@types+node@22.16.4_typescript@5.7.3__terser@5.44.1/node_modules/vitest/dist/chunks/date.W2xKR2qe.js
|
|
15334
15334
|
var RealDate = Date;
|
|
15335
15335
|
var now2 = null;
|
|
15336
15336
|
var MockDate = class _MockDate extends RealDate {
|
|
@@ -15383,7 +15383,7 @@ function resetDate() {
|
|
|
15383
15383
|
globalThis.Date = RealDate;
|
|
15384
15384
|
}
|
|
15385
15385
|
|
|
15386
|
-
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.
|
|
15386
|
+
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.2_msw@2.12.8_@types+node@22.16.4_typescript@5.7.3__terser@5.44.1/node_modules/vitest/dist/chunks/vi.DgezovHB.js
|
|
15387
15387
|
var unsupported = [
|
|
15388
15388
|
// .poll is meant to retry matchers until they succeed, and
|
|
15389
15389
|
// snapshots will always succeed as long as the poll method doesn't thow an error
|
|
@@ -18115,7 +18115,7 @@ function getImporter(name) {
|
|
|
18115
18115
|
return stack?.file || "";
|
|
18116
18116
|
}
|
|
18117
18117
|
|
|
18118
|
-
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.
|
|
18118
|
+
// ../node_modules/.pnpm/vitest@2.1.9_@types+node@22.16.4_lightningcss@1.30.2_msw@2.12.8_@types+node@22.16.4_typescript@5.7.3__terser@5.44.1/node_modules/vitest/dist/index.js
|
|
18119
18119
|
__toESM(require_dist(), 1);
|
|
18120
18120
|
|
|
18121
18121
|
// src/data/md5.ts
|