@gringow/gringow 0.3.1 → 0.6.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 (37) hide show
  1. package/README.md +11 -0
  2. package/dist/config.d.mts +2 -2
  3. package/dist/config.mjs +4 -4
  4. package/dist/data/check-cache.d.mts +1 -0
  5. package/dist/data/check-cache.mjs +4 -4
  6. package/dist/data/clear-cache.mjs +4 -4
  7. package/dist/data/create-cache-dir.mjs +4 -4
  8. package/dist/data/delete-cache-item.d.mts +1 -0
  9. package/dist/data/delete-cache-item.mjs +4 -4
  10. package/dist/data/get-cache.mjs +4 -4
  11. package/dist/data/get-or-create-cache.d.mts +1 -0
  12. package/dist/data/get-or-create-cache.mjs +4 -4
  13. package/dist/data/save-cache.d.mts +1 -0
  14. package/dist/data/save-cache.mjs +4 -4
  15. package/dist/data/write-cache-to-disk.d.mts +1 -0
  16. package/dist/data/write-cache-to-disk.mjs +4 -4
  17. package/dist/gringow.d.mts +1 -0
  18. package/dist/gringow.mjs +4 -4
  19. package/dist/index.d.mts +1 -0
  20. package/dist/index.mjs +97 -5
  21. package/dist/io/ask-llm.d.mts +1 -0
  22. package/dist/io/ask-llm.mjs +4 -4
  23. package/dist/schemas/config.shcema.d.mts +13 -13
  24. package/dist/schemas/config.shcema.mjs +1 -1
  25. package/dist/strip-comments.d.mts +25 -0
  26. package/dist/strip-comments.mjs +93 -0
  27. package/package.json +1 -1
  28. package/dist/config.test.d.mts +0 -2
  29. package/dist/config.test.mjs +0 -18657
  30. package/dist/create-cache-id.test.d.mts +0 -2
  31. package/dist/create-cache-id.test.mjs +0 -18491
  32. package/dist/data/md5.test.d.mts +0 -2
  33. package/dist/data/md5.test.mjs +0 -18457
  34. package/dist/interpolate-template.test.d.mts +0 -2
  35. package/dist/interpolate-template.test.mjs +0 -18510
  36. package/dist/logger.test.d.mts +0 -2
  37. package/dist/logger.test.mjs +0 -18698
package/README.md CHANGED
@@ -123,6 +123,17 @@ export default {
123
123
  }
124
124
  ```
125
125
 
126
+ ### Migration from `llm.choice`
127
+
128
+ `llm.choice` was removed in 0.6.0. Rename the field to `llm.provider` in every Gringow configuration file.
129
+
130
+ ```diff
131
+ llm: {
132
+ - choice: 'openai',
133
+ + provider: 'openai',
134
+ }
135
+ ```
136
+
126
137
  ### Example: Using Gemini
127
138
 
128
139
  ```js
package/dist/config.d.mts CHANGED
@@ -41,12 +41,12 @@ declare const awaitedConfig: Promise<{
41
41
  llm: {
42
42
  provider: "anthropic" | "gemini" | "openai" | "groq" | "mistral" | "ollama" | "xai" | "deepseek" | "openrouter" | "cerebras" | "lmstudio" | "azure" | "meta";
43
43
  model: string | null;
44
- prePrompt?: string | undefined;
45
- postPrompt?: string | undefined;
46
44
  apiKey?: string | undefined;
47
45
  baseURL?: string | undefined;
48
46
  temperature?: number | undefined;
49
47
  sleep?: number | undefined;
48
+ prePrompt?: string | undefined;
49
+ postPrompt?: string | undefined;
50
50
  prePromptReplace?: string | undefined;
51
51
  postPromptReplace?: string | undefined;
52
52
  prePromptAppend?: string | undefined;
package/dist/config.mjs CHANGED
@@ -71,7 +71,7 @@ var configSchema = z.object({
71
71
  postPromptReplace: z.string().optional(),
72
72
  prePromptAppend: z.string().optional(),
73
73
  postPromptPrepend: z.string().optional()
74
- }),
74
+ }).strict(),
75
75
  globby: z.string().regex(/^\.\/.*/).optional()
76
76
  }).refine(
77
77
  (data) => {
@@ -126,12 +126,12 @@ Your task is to translate a given text and output **only one valid JSON object**
126
126
  Follow these rules strictly:
127
127
 
128
128
  1. The original text is written in English or Spanish.
129
- 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
130
- - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
129
+ 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
130
+ - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
131
131
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
132
132
  3. Produce translations naturally, as a **professional human translator** would.
133
133
  4. Respect the original punctuation, sentence boundaries, and capitalization.
134
- 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
134
+ 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set([...config.languages, config.sourceLanguage])) : []).join(", ")}.
135
135
  6. The final output must be a **valid JSON** following this exact schema:
136
136
 
137
137
  {
@@ -7,3 +7,4 @@ import '../create-cache-id.mjs';
7
7
  import './clear-cache.mjs';
8
8
  import './get-cache.mjs';
9
9
  import '../interpolate-template.mjs';
10
+ import '../strip-comments.mjs';
@@ -74,7 +74,7 @@ var configSchema = z.object({
74
74
  postPromptReplace: z.string().optional(),
75
75
  prePromptAppend: z.string().optional(),
76
76
  postPromptPrepend: z.string().optional()
77
- }),
77
+ }).strict(),
78
78
  globby: z.string().regex(/^\.\/.*/).optional()
79
79
  }).refine(
80
80
  (data) => {
@@ -123,12 +123,12 @@ Your task is to translate a given text and output **only one valid JSON object**
123
123
  Follow these rules strictly:
124
124
 
125
125
  1. The original text is written in English or Spanish.
126
- 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
127
- - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
126
+ 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
127
+ - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
128
128
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
129
129
  3. Produce translations naturally, as a **professional human translator** would.
130
130
  4. Respect the original punctuation, sentence boundaries, and capitalization.
131
- 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
131
+ 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set([...config.languages, config.sourceLanguage])) : []).join(", ")}.
132
132
  6. The final output must be a **valid JSON** following this exact schema:
133
133
 
134
134
  {
@@ -74,7 +74,7 @@ var configSchema = z.object({
74
74
  postPromptReplace: z.string().optional(),
75
75
  prePromptAppend: z.string().optional(),
76
76
  postPromptPrepend: z.string().optional()
77
- }),
77
+ }).strict(),
78
78
  globby: z.string().regex(/^\.\/.*/).optional()
79
79
  }).refine(
80
80
  (data) => {
@@ -123,12 +123,12 @@ Your task is to translate a given text and output **only one valid JSON object**
123
123
  Follow these rules strictly:
124
124
 
125
125
  1. The original text is written in English or Spanish.
126
- 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
127
- - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
126
+ 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
127
+ - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
128
128
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
129
129
  3. Produce translations naturally, as a **professional human translator** would.
130
130
  4. Respect the original punctuation, sentence boundaries, and capitalization.
131
- 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
131
+ 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set([...config.languages, config.sourceLanguage])) : []).join(", ")}.
132
132
  6. The final output must be a **valid JSON** following this exact schema:
133
133
 
134
134
  {
@@ -278,7 +278,7 @@ var configSchema = z.object({
278
278
  postPromptReplace: z.string().optional(),
279
279
  prePromptAppend: z.string().optional(),
280
280
  postPromptPrepend: z.string().optional()
281
- }),
281
+ }).strict(),
282
282
  globby: z.string().regex(/^\.\/.*/).optional()
283
283
  }).refine(
284
284
  (data) => {
@@ -327,12 +327,12 @@ Your task is to translate a given text and output **only one valid JSON object**
327
327
  Follow these rules strictly:
328
328
 
329
329
  1. The original text is written in English or Spanish.
330
- 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
331
- - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
330
+ 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
331
+ - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
332
332
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
333
333
  3. Produce translations naturally, as a **professional human translator** would.
334
334
  4. Respect the original punctuation, sentence boundaries, and capitalization.
335
- 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
335
+ 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set([...config.languages, config.sourceLanguage])) : []).join(", ")}.
336
336
  6. The final output must be a **valid JSON** following this exact schema:
337
337
 
338
338
  {
@@ -7,3 +7,4 @@ import '../create-cache-id.mjs';
7
7
  import './clear-cache.mjs';
8
8
  import './get-cache.mjs';
9
9
  import '../interpolate-template.mjs';
10
+ import '../strip-comments.mjs';
@@ -74,7 +74,7 @@ var configSchema = z.object({
74
74
  postPromptReplace: z.string().optional(),
75
75
  prePromptAppend: z.string().optional(),
76
76
  postPromptPrepend: z.string().optional()
77
- }),
77
+ }).strict(),
78
78
  globby: z.string().regex(/^\.\/.*/).optional()
79
79
  }).refine(
80
80
  (data) => {
@@ -123,12 +123,12 @@ Your task is to translate a given text and output **only one valid JSON object**
123
123
  Follow these rules strictly:
124
124
 
125
125
  1. The original text is written in English or Spanish.
126
- 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
127
- - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
126
+ 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
127
+ - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
128
128
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
129
129
  3. Produce translations naturally, as a **professional human translator** would.
130
130
  4. Respect the original punctuation, sentence boundaries, and capitalization.
131
- 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
131
+ 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set([...config.languages, config.sourceLanguage])) : []).join(", ")}.
132
132
  6. The final output must be a **valid JSON** following this exact schema:
133
133
 
134
134
  {
@@ -74,7 +74,7 @@ var configSchema = z.object({
74
74
  postPromptReplace: z.string().optional(),
75
75
  prePromptAppend: z.string().optional(),
76
76
  postPromptPrepend: z.string().optional()
77
- }),
77
+ }).strict(),
78
78
  globby: z.string().regex(/^\.\/.*/).optional()
79
79
  }).refine(
80
80
  (data) => {
@@ -123,12 +123,12 @@ Your task is to translate a given text and output **only one valid JSON object**
123
123
  Follow these rules strictly:
124
124
 
125
125
  1. The original text is written in English or Spanish.
126
- 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
127
- - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
126
+ 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
127
+ - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
128
128
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
129
129
  3. Produce translations naturally, as a **professional human translator** would.
130
130
  4. Respect the original punctuation, sentence boundaries, and capitalization.
131
- 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
131
+ 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set([...config.languages, config.sourceLanguage])) : []).join(", ")}.
132
132
  6. The final output must be a **valid JSON** following this exact schema:
133
133
 
134
134
  {
@@ -7,3 +7,4 @@ import '../create-cache-id.mjs';
7
7
  import './clear-cache.mjs';
8
8
  import './get-cache.mjs';
9
9
  import '../interpolate-template.mjs';
10
+ import '../strip-comments.mjs';
@@ -74,7 +74,7 @@ var configSchema = z.object({
74
74
  postPromptReplace: z.string().optional(),
75
75
  prePromptAppend: z.string().optional(),
76
76
  postPromptPrepend: z.string().optional()
77
- }),
77
+ }).strict(),
78
78
  globby: z.string().regex(/^\.\/.*/).optional()
79
79
  }).refine(
80
80
  (data) => {
@@ -123,12 +123,12 @@ Your task is to translate a given text and output **only one valid JSON object**
123
123
  Follow these rules strictly:
124
124
 
125
125
  1. The original text is written in English or Spanish.
126
- 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
127
- - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
126
+ 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
127
+ - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
128
128
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
129
129
  3. Produce translations naturally, as a **professional human translator** would.
130
130
  4. Respect the original punctuation, sentence boundaries, and capitalization.
131
- 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
131
+ 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set([...config.languages, config.sourceLanguage])) : []).join(", ")}.
132
132
  6. The final output must be a **valid JSON** following this exact schema:
133
133
 
134
134
  {
@@ -7,6 +7,7 @@ import '../create-cache-id.mjs';
7
7
  import './clear-cache.mjs';
8
8
  import './get-cache.mjs';
9
9
  import '../interpolate-template.mjs';
10
+ import '../strip-comments.mjs';
10
11
 
11
12
  /**
12
13
  * Saves the cache to disk.
@@ -74,7 +74,7 @@ var configSchema = z.object({
74
74
  postPromptReplace: z.string().optional(),
75
75
  prePromptAppend: z.string().optional(),
76
76
  postPromptPrepend: z.string().optional()
77
- }),
77
+ }).strict(),
78
78
  globby: z.string().regex(/^\.\/.*/).optional()
79
79
  }).refine(
80
80
  (data) => {
@@ -123,12 +123,12 @@ Your task is to translate a given text and output **only one valid JSON object**
123
123
  Follow these rules strictly:
124
124
 
125
125
  1. The original text is written in English or Spanish.
126
- 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
127
- - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
126
+ 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
127
+ - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
128
128
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
129
129
  3. Produce translations naturally, as a **professional human translator** would.
130
130
  4. Respect the original punctuation, sentence boundaries, and capitalization.
131
- 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
131
+ 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set([...config.languages, config.sourceLanguage])) : []).join(", ")}.
132
132
  6. The final output must be a **valid JSON** following this exact schema:
133
133
 
134
134
  {
@@ -7,3 +7,4 @@ import '../create-cache-id.mjs';
7
7
  import './clear-cache.mjs';
8
8
  import './get-cache.mjs';
9
9
  import '../interpolate-template.mjs';
10
+ import '../strip-comments.mjs';
@@ -74,7 +74,7 @@ var configSchema = z.object({
74
74
  postPromptReplace: z.string().optional(),
75
75
  prePromptAppend: z.string().optional(),
76
76
  postPromptPrepend: z.string().optional()
77
- }),
77
+ }).strict(),
78
78
  globby: z.string().regex(/^\.\/.*/).optional()
79
79
  }).refine(
80
80
  (data) => {
@@ -123,12 +123,12 @@ Your task is to translate a given text and output **only one valid JSON object**
123
123
  Follow these rules strictly:
124
124
 
125
125
  1. The original text is written in English or Spanish.
126
- 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
127
- - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
126
+ 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
127
+ - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
128
128
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
129
129
  3. Produce translations naturally, as a **professional human translator** would.
130
130
  4. Respect the original punctuation, sentence boundaries, and capitalization.
131
- 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
131
+ 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set([...config.languages, config.sourceLanguage])) : []).join(", ")}.
132
132
  6. The final output must be a **valid JSON** following this exact schema:
133
133
 
134
134
  {
@@ -7,3 +7,4 @@ import './create-cache-id.mjs';
7
7
  import './data/clear-cache.mjs';
8
8
  import './data/get-cache.mjs';
9
9
  import './interpolate-template.mjs';
10
+ import './strip-comments.mjs';
package/dist/gringow.mjs CHANGED
@@ -75,7 +75,7 @@ var configSchema = z.object({
75
75
  postPromptReplace: z.string().optional(),
76
76
  prePromptAppend: z.string().optional(),
77
77
  postPromptPrepend: z.string().optional()
78
- }),
78
+ }).strict(),
79
79
  globby: z.string().regex(/^\.\/.*/).optional()
80
80
  }).refine(
81
81
  (data) => {
@@ -124,12 +124,12 @@ Your task is to translate a given text and output **only one valid JSON object**
124
124
  Follow these rules strictly:
125
125
 
126
126
  1. The original text is written in English or Spanish.
127
- 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
128
- - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
127
+ 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
128
+ - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
129
129
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
130
130
  3. Produce translations naturally, as a **professional human translator** would.
131
131
  4. Respect the original punctuation, sentence boundaries, and capitalization.
132
- 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
132
+ 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set([...config.languages, config.sourceLanguage])) : []).join(", ")}.
133
133
  6. The final output must be a **valid JSON** following this exact schema:
134
134
 
135
135
  {
package/dist/index.d.mts CHANGED
@@ -3,6 +3,7 @@ export { createCacheId } from './create-cache-id.mjs';
3
3
  export { clearCache } from './data/clear-cache.mjs';
4
4
  export { getCache } from './data/get-cache.mjs';
5
5
  export { interpolateTemplate } from './interpolate-template.mjs';
6
+ export { stripComments } from './strip-comments.mjs';
6
7
  export { GringowConfig } from './constants/default-config.mjs';
7
8
  import 'zod';
8
9
  import './schemas/config.shcema.mjs';
package/dist/index.mjs CHANGED
@@ -75,7 +75,7 @@ var configSchema = z.object({
75
75
  postPromptReplace: z.string().optional(),
76
76
  prePromptAppend: z.string().optional(),
77
77
  postPromptPrepend: z.string().optional()
78
- }),
78
+ }).strict(),
79
79
  globby: z.string().regex(/^\.\/.*/).optional()
80
80
  }).refine(
81
81
  (data) => {
@@ -130,12 +130,12 @@ Your task is to translate a given text and output **only one valid JSON object**
130
130
  Follow these rules strictly:
131
131
 
132
132
  1. The original text is written in English or Spanish.
133
- 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
134
- - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
133
+ 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
134
+ - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
135
135
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
136
136
  3. Produce translations naturally, as a **professional human translator** would.
137
137
  4. Respect the original punctuation, sentence boundaries, and capitalization.
138
- 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
138
+ 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set([...config.languages, config.sourceLanguage])) : []).join(", ")}.
139
139
  6. The final output must be a **valid JSON** following this exact schema:
140
140
 
141
141
  {
@@ -658,4 +658,96 @@ async function Gringow(text, ...values) {
658
658
  return { cacheId, translation: output };
659
659
  }
660
660
 
661
- export { awaitedConfig, checkCache, clearCache, createCacheId, Gringow as default, deleteCacheItem, getCache, getConfigSource, getOrCreateCache, interpolateTemplate, isLocalConfigFound, rebuild, writeCacheToDisk };
661
+ // src/strip-comments.ts
662
+ function stripComments(code) {
663
+ let out = "";
664
+ let i = 0;
665
+ const len = code.length;
666
+ const templateStack = [];
667
+ while (i < len) {
668
+ const ch = code[i];
669
+ const next = code[i + 1];
670
+ if (templateStack.length > 0 && templateStack[templateStack.length - 1].braceDepth === 0) {
671
+ if (ch === "\\" && i + 1 < len) {
672
+ out += ch + code[i + 1];
673
+ i += 2;
674
+ continue;
675
+ }
676
+ if (ch === "`") {
677
+ out += ch;
678
+ templateStack.pop();
679
+ i++;
680
+ continue;
681
+ }
682
+ if (ch === "$" && next === "{") {
683
+ out += "${";
684
+ templateStack[templateStack.length - 1].braceDepth = 1;
685
+ i += 2;
686
+ continue;
687
+ }
688
+ out += ch;
689
+ i++;
690
+ continue;
691
+ }
692
+ if (ch === "/" && next === "/") {
693
+ i += 2;
694
+ while (i < len && code[i] !== "\n") {
695
+ i++;
696
+ }
697
+ continue;
698
+ }
699
+ if (ch === "/" && next === "*") {
700
+ i += 2;
701
+ while (i < len && !(code[i] === "*" && code[i + 1] === "/")) {
702
+ if (code[i] === "\n") out += "\n";
703
+ i++;
704
+ }
705
+ i += 2;
706
+ continue;
707
+ }
708
+ if (ch === '"' || ch === "'") {
709
+ const quote = ch;
710
+ out += ch;
711
+ i++;
712
+ while (i < len) {
713
+ const c = code[i];
714
+ if (c === "\\" && i + 1 < len) {
715
+ out += c + code[i + 1];
716
+ i += 2;
717
+ continue;
718
+ }
719
+ out += c;
720
+ i++;
721
+ if (c === quote) break;
722
+ }
723
+ continue;
724
+ }
725
+ if (ch === "`") {
726
+ out += ch;
727
+ templateStack.push({ braceDepth: 0 });
728
+ i++;
729
+ continue;
730
+ }
731
+ if (templateStack.length > 0) {
732
+ const top = templateStack[templateStack.length - 1];
733
+ if (ch === "{") {
734
+ top.braceDepth++;
735
+ out += ch;
736
+ i++;
737
+ continue;
738
+ }
739
+ if (ch === "}") {
740
+ top.braceDepth--;
741
+ out += ch;
742
+ i++;
743
+ if (top.braceDepth === 0) ;
744
+ continue;
745
+ }
746
+ }
747
+ out += ch;
748
+ i++;
749
+ }
750
+ return out;
751
+ }
752
+
753
+ export { awaitedConfig, checkCache, clearCache, createCacheId, Gringow as default, deleteCacheItem, getCache, getConfigSource, getOrCreateCache, interpolateTemplate, isLocalConfigFound, rebuild, stripComments, writeCacheToDisk };
@@ -7,6 +7,7 @@ import '../create-cache-id.mjs';
7
7
  import '../data/clear-cache.mjs';
8
8
  import '../data/get-cache.mjs';
9
9
  import '../interpolate-template.mjs';
10
+ import '../strip-comments.mjs';
10
11
 
11
12
  /**
12
13
  * Asks an LLM for a response using multi-llm-ts.
@@ -72,7 +72,7 @@ var configSchema = z.object({
72
72
  postPromptReplace: z.string().optional(),
73
73
  prePromptAppend: z.string().optional(),
74
74
  postPromptPrepend: z.string().optional()
75
- }),
75
+ }).strict(),
76
76
  globby: z.string().regex(/^\.\/.*/).optional()
77
77
  }).refine(
78
78
  (data) => {
@@ -121,12 +121,12 @@ Your task is to translate a given text and output **only one valid JSON object**
121
121
  Follow these rules strictly:
122
122
 
123
123
  1. The original text is written in English or Spanish.
124
- 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
125
- - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
124
+ 2. You will receive additional user parameters under the variable 'extraInstructions'. These may specify tone, persona, style, context, or any relevant translation guideline.
125
+ - Examples: \u201Ctranslate as if you were a Shakespearean narrator\u201D or \u201Cuse a formal business tone suitable for a corporate presentation.\u201D
126
126
  - Apply these creatively but **without altering the meaning or punctuation** of the original text.
127
127
  3. Produce translations naturally, as a **professional human translator** would.
128
128
  4. Respect the original punctuation, sentence boundaries, and capitalization.
129
- 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
129
+ 5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set([...config.languages, config.sourceLanguage])) : []).join(", ")}.
130
130
  6. The final output must be a **valid JSON** following this exact schema:
131
131
 
132
132
  {
@@ -43,15 +43,15 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
43
43
  postPromptReplace: z.ZodOptional<z.ZodString>;
44
44
  prePromptAppend: z.ZodOptional<z.ZodString>;
45
45
  postPromptPrepend: z.ZodOptional<z.ZodString>;
46
- }, "strip", z.ZodTypeAny, {
46
+ }, "strict", z.ZodTypeAny, {
47
47
  provider: "anthropic" | "gemini" | "openai" | "groq" | "mistral" | "ollama" | "xai" | "deepseek" | "openrouter" | "cerebras" | "lmstudio" | "azure" | "meta";
48
48
  model: string | null;
49
- prePrompt?: string | undefined;
50
- postPrompt?: string | undefined;
51
49
  apiKey?: string | undefined;
52
50
  baseURL?: string | undefined;
53
51
  temperature?: number | undefined;
54
52
  sleep?: number | undefined;
53
+ prePrompt?: string | undefined;
54
+ postPrompt?: string | undefined;
55
55
  prePromptReplace?: string | undefined;
56
56
  postPromptReplace?: string | undefined;
57
57
  prePromptAppend?: string | undefined;
@@ -59,12 +59,12 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
59
59
  }, {
60
60
  provider: "anthropic" | "gemini" | "openai" | "groq" | "mistral" | "ollama" | "xai" | "deepseek" | "openrouter" | "cerebras" | "lmstudio" | "azure" | "meta";
61
61
  model: string | null;
62
- prePrompt?: string | undefined;
63
- postPrompt?: string | undefined;
64
62
  apiKey?: string | undefined;
65
63
  baseURL?: string | undefined;
66
64
  temperature?: number | undefined;
67
65
  sleep?: number | undefined;
66
+ prePrompt?: string | undefined;
67
+ postPrompt?: string | undefined;
68
68
  prePromptReplace?: string | undefined;
69
69
  postPromptReplace?: string | undefined;
70
70
  prePromptAppend?: string | undefined;
@@ -87,12 +87,12 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
87
87
  llm: {
88
88
  provider: "anthropic" | "gemini" | "openai" | "groq" | "mistral" | "ollama" | "xai" | "deepseek" | "openrouter" | "cerebras" | "lmstudio" | "azure" | "meta";
89
89
  model: string | null;
90
- prePrompt?: string | undefined;
91
- postPrompt?: string | undefined;
92
90
  apiKey?: string | undefined;
93
91
  baseURL?: string | undefined;
94
92
  temperature?: number | undefined;
95
93
  sleep?: number | undefined;
94
+ prePrompt?: string | undefined;
95
+ postPrompt?: string | undefined;
96
96
  prePromptReplace?: string | undefined;
97
97
  postPromptReplace?: string | undefined;
98
98
  prePromptAppend?: string | undefined;
@@ -116,12 +116,12 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
116
116
  llm: {
117
117
  provider: "anthropic" | "gemini" | "openai" | "groq" | "mistral" | "ollama" | "xai" | "deepseek" | "openrouter" | "cerebras" | "lmstudio" | "azure" | "meta";
118
118
  model: string | null;
119
- prePrompt?: string | undefined;
120
- postPrompt?: string | undefined;
121
119
  apiKey?: string | undefined;
122
120
  baseURL?: string | undefined;
123
121
  temperature?: number | undefined;
124
122
  sleep?: number | undefined;
123
+ prePrompt?: string | undefined;
124
+ postPrompt?: string | undefined;
125
125
  prePromptReplace?: string | undefined;
126
126
  postPromptReplace?: string | undefined;
127
127
  prePromptAppend?: string | undefined;
@@ -145,12 +145,12 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
145
145
  llm: {
146
146
  provider: "anthropic" | "gemini" | "openai" | "groq" | "mistral" | "ollama" | "xai" | "deepseek" | "openrouter" | "cerebras" | "lmstudio" | "azure" | "meta";
147
147
  model: string | null;
148
- prePrompt?: string | undefined;
149
- postPrompt?: string | undefined;
150
148
  apiKey?: string | undefined;
151
149
  baseURL?: string | undefined;
152
150
  temperature?: number | undefined;
153
151
  sleep?: number | undefined;
152
+ prePrompt?: string | undefined;
153
+ postPrompt?: string | undefined;
154
154
  prePromptReplace?: string | undefined;
155
155
  postPromptReplace?: string | undefined;
156
156
  prePromptAppend?: string | undefined;
@@ -174,12 +174,12 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
174
174
  llm: {
175
175
  provider: "anthropic" | "gemini" | "openai" | "groq" | "mistral" | "ollama" | "xai" | "deepseek" | "openrouter" | "cerebras" | "lmstudio" | "azure" | "meta";
176
176
  model: string | null;
177
- prePrompt?: string | undefined;
178
- postPrompt?: string | undefined;
179
177
  apiKey?: string | undefined;
180
178
  baseURL?: string | undefined;
181
179
  temperature?: number | undefined;
182
180
  sleep?: number | undefined;
181
+ prePrompt?: string | undefined;
182
+ postPrompt?: string | undefined;
183
183
  prePromptReplace?: string | undefined;
184
184
  postPromptReplace?: string | undefined;
185
185
  prePromptAppend?: string | undefined;
@@ -44,7 +44,7 @@ var configSchema = z.object({
44
44
  postPromptReplace: z.string().optional(),
45
45
  prePromptAppend: z.string().optional(),
46
46
  postPromptPrepend: z.string().optional()
47
- }),
47
+ }).strict(),
48
48
  globby: z.string().regex(/^\.\/.*/).optional()
49
49
  }).refine(
50
50
  (data) => {
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Strips `//` line comments and `/* *\/` block comments from JavaScript /
3
+ * TypeScript source code, while preserving the verbatim content of:
4
+ *
5
+ * - single-quoted strings (`'...'`)
6
+ * - double-quoted strings (`"..."`)
7
+ * - template literals (`` `...` ``), including nested `${ ... }`
8
+ * interpolations which may themselves contain strings or further templates
9
+ *
10
+ * Newlines are preserved so that downstream consumers that care about
11
+ * line/column information (e.g. source-map-adjacent tooling) keep stable
12
+ * offsets. Block-comment bodies are replaced with the newlines they
13
+ * contained; line-comment bodies are removed up to (but not including) the
14
+ * terminating newline.
15
+ *
16
+ * Implementation is an in-house state-machine scanner — preferred over a
17
+ * dependency because the algorithm is small, deterministic, and avoids
18
+ * surprises around nested template interpolations.
19
+ *
20
+ * @param code - JS/TS source to scrub
21
+ * @returns the same source with comments removed and strings preserved
22
+ */
23
+ declare function stripComments(code: string): string;
24
+
25
+ export { stripComments };