@gringow/gringow 0.3.1 → 0.5.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 +2 -2
- package/dist/config.mjs +3 -3
- package/dist/data/check-cache.d.mts +1 -0
- package/dist/data/check-cache.mjs +3 -3
- package/dist/data/clear-cache.mjs +3 -3
- package/dist/data/create-cache-dir.mjs +3 -3
- package/dist/data/delete-cache-item.d.mts +1 -0
- package/dist/data/delete-cache-item.mjs +3 -3
- package/dist/data/get-cache.mjs +3 -3
- package/dist/data/get-or-create-cache.d.mts +1 -0
- package/dist/data/get-or-create-cache.mjs +3 -3
- package/dist/data/save-cache.d.mts +1 -0
- package/dist/data/save-cache.mjs +3 -3
- package/dist/data/write-cache-to-disk.d.mts +1 -0
- package/dist/data/write-cache-to-disk.mjs +3 -3
- package/dist/gringow.d.mts +1 -0
- package/dist/gringow.mjs +3 -3
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +96 -4
- package/dist/io/ask-llm.d.mts +1 -0
- package/dist/io/ask-llm.mjs +3 -3
- package/dist/schemas/config.shcema.d.mts +12 -12
- package/dist/strip-comments.d.mts +25 -0
- package/dist/strip-comments.mjs +93 -0
- package/package.json +1 -1
- package/dist/config.test.d.mts +0 -2
- package/dist/config.test.mjs +0 -18657
- package/dist/create-cache-id.test.d.mts +0 -2
- package/dist/create-cache-id.test.mjs +0 -18491
- package/dist/data/md5.test.d.mts +0 -2
- package/dist/data/md5.test.mjs +0 -18457
- package/dist/interpolate-template.test.d.mts +0 -2
- package/dist/interpolate-template.test.mjs +0 -18510
- package/dist/logger.test.d.mts +0 -2
- package/dist/logger.test.mjs +0 -18698
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
|
@@ -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([
|
|
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
|
{
|
|
@@ -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([
|
|
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
|
{
|
|
@@ -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([
|
|
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
|
{
|
|
@@ -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([
|
|
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
|
{
|
|
@@ -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([
|
|
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
|
{
|
package/dist/data/get-cache.mjs
CHANGED
|
@@ -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([
|
|
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
|
{
|
|
@@ -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([
|
|
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
|
{
|
package/dist/data/save-cache.mjs
CHANGED
|
@@ -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([
|
|
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
|
{
|
|
@@ -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([
|
|
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
|
{
|
package/dist/gringow.d.mts
CHANGED
package/dist/gringow.mjs
CHANGED
|
@@ -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([
|
|
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
|
@@ -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([
|
|
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
|
-
|
|
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 };
|
package/dist/io/ask-llm.d.mts
CHANGED
package/dist/io/ask-llm.mjs
CHANGED
|
@@ -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([
|
|
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
|
{
|
|
@@ -46,12 +46,12 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
|
|
|
46
46
|
}, "strip", 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;
|
|
@@ -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 };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// src/strip-comments.ts
|
|
2
|
+
function stripComments(code) {
|
|
3
|
+
let out = "";
|
|
4
|
+
let i = 0;
|
|
5
|
+
const len = code.length;
|
|
6
|
+
const templateStack = [];
|
|
7
|
+
while (i < len) {
|
|
8
|
+
const ch = code[i];
|
|
9
|
+
const next = code[i + 1];
|
|
10
|
+
if (templateStack.length > 0 && templateStack[templateStack.length - 1].braceDepth === 0) {
|
|
11
|
+
if (ch === "\\" && i + 1 < len) {
|
|
12
|
+
out += ch + code[i + 1];
|
|
13
|
+
i += 2;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (ch === "`") {
|
|
17
|
+
out += ch;
|
|
18
|
+
templateStack.pop();
|
|
19
|
+
i++;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (ch === "$" && next === "{") {
|
|
23
|
+
out += "${";
|
|
24
|
+
templateStack[templateStack.length - 1].braceDepth = 1;
|
|
25
|
+
i += 2;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
out += ch;
|
|
29
|
+
i++;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (ch === "/" && next === "/") {
|
|
33
|
+
i += 2;
|
|
34
|
+
while (i < len && code[i] !== "\n") {
|
|
35
|
+
i++;
|
|
36
|
+
}
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (ch === "/" && next === "*") {
|
|
40
|
+
i += 2;
|
|
41
|
+
while (i < len && !(code[i] === "*" && code[i + 1] === "/")) {
|
|
42
|
+
if (code[i] === "\n") out += "\n";
|
|
43
|
+
i++;
|
|
44
|
+
}
|
|
45
|
+
i += 2;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (ch === '"' || ch === "'") {
|
|
49
|
+
const quote = ch;
|
|
50
|
+
out += ch;
|
|
51
|
+
i++;
|
|
52
|
+
while (i < len) {
|
|
53
|
+
const c = code[i];
|
|
54
|
+
if (c === "\\" && i + 1 < len) {
|
|
55
|
+
out += c + code[i + 1];
|
|
56
|
+
i += 2;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
out += c;
|
|
60
|
+
i++;
|
|
61
|
+
if (c === quote) break;
|
|
62
|
+
}
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (ch === "`") {
|
|
66
|
+
out += ch;
|
|
67
|
+
templateStack.push({ braceDepth: 0 });
|
|
68
|
+
i++;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (templateStack.length > 0) {
|
|
72
|
+
const top = templateStack[templateStack.length - 1];
|
|
73
|
+
if (ch === "{") {
|
|
74
|
+
top.braceDepth++;
|
|
75
|
+
out += ch;
|
|
76
|
+
i++;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (ch === "}") {
|
|
80
|
+
top.braceDepth--;
|
|
81
|
+
out += ch;
|
|
82
|
+
i++;
|
|
83
|
+
if (top.braceDepth === 0) ;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
out += ch;
|
|
88
|
+
i++;
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { stripComments };
|
package/package.json
CHANGED
package/dist/config.test.d.mts
DELETED