@gringow/gringow 0.1.2 → 0.1.3
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 +82 -40
- package/dist/browser.d.mts +2 -1
- package/dist/browser.mjs +61 -4
- package/dist/config.mjs +3 -3
- package/dist/config.test.mjs +50 -67
- package/dist/{data/create-cache-id.d.mts → create-cache-id.d.mts} +2 -2
- package/dist/create-cache-id.mjs +54 -0
- package/dist/create-cache-id.test.d.mts +2 -0
- package/dist/create-cache-id.test.mjs +18464 -0
- package/dist/data/check-cache.d.mts +1 -1
- package/dist/data/check-cache.mjs +12 -7
- package/dist/data/clear-cache.mjs +12 -7
- package/dist/data/create-cache-dir.mjs +3 -3
- package/dist/data/delete-cache-item.d.mts +1 -1
- package/dist/data/delete-cache-item.mjs +12 -7
- package/dist/data/get-cache.mjs +3 -3
- package/dist/data/get-or-create-cache.d.mts +1 -1
- package/dist/data/get-or-create-cache.mjs +12 -7
- package/dist/data/md5.d.mts +13 -0
- package/dist/data/md5.mjs +47 -0
- package/dist/data/md5.test.d.mts +2 -0
- package/dist/data/md5.test.mjs +18457 -0
- package/dist/data/save-cache.d.mts +2 -2
- package/dist/data/save-cache.mjs +12 -7
- package/dist/data/write-cache-to-disk.d.mts +1 -1
- package/dist/data/write-cache-to-disk.mjs +12 -7
- package/dist/flat-template-string.test.mjs +10 -10
- package/dist/gringow.d.mts +1 -1
- package/dist/gringow.mjs +98 -35
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +98 -35
- package/dist/interpolate-template.d.mts +3 -0
- package/dist/interpolate-template.mjs +14 -0
- package/dist/io/anthropic/ask.mjs +3 -3
- package/dist/io/anthropic/commit-response.d.mts +1 -1
- package/dist/io/anthropic/index.d.mts +1 -1
- package/dist/io/anthropic/index.mjs +3 -3
- package/dist/io/anthropic/parse.d.mts +1 -1
- package/dist/io/ask-llm.d.mts +1 -1
- package/dist/io/ask-llm.mjs +36 -25
- package/dist/io/gemini/ask.mjs +36 -25
- package/dist/io/gemini/index.d.mts +1 -1
- package/dist/io/gemini/index.mjs +36 -25
- package/dist/io/gemini/parse.d.mts +1 -1
- package/dist/io/huggingface/ask.d.mts +1 -1
- package/dist/io/huggingface/ask.mjs +3 -3
- package/dist/io/huggingface/commit-response.d.mts +1 -1
- package/dist/io/huggingface/index.d.mts +1 -1
- package/dist/io/huggingface/index.mjs +3 -3
- package/dist/io/huggingface/parse.d.mts +1 -1
- package/dist/logger.test.mjs +10 -10
- package/dist/types/index.d.mts +1 -1
- package/package.json +10 -10
- package/dist/data/create-cache-id.mjs +0 -10
|
@@ -3,7 +3,7 @@ import '../config.mjs';
|
|
|
3
3
|
import '../constants/default-config.mjs';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import '../schemas/config.shcema.mjs';
|
|
6
|
+
import '../create-cache-id.mjs';
|
|
6
7
|
import './clear-cache.mjs';
|
|
7
|
-
import './create-cache-id.mjs';
|
|
8
8
|
import './get-cache.mjs';
|
|
9
9
|
import '../flat-template-string.mjs';
|
|
@@ -104,9 +104,9 @@ async function loadUserConfig() {
|
|
|
104
104
|
var awaitedConfig = loadUserConfig();
|
|
105
105
|
function defaultPrePrompt(config, extraInstructions) {
|
|
106
106
|
return `
|
|
107
|
-
You are a translation generator.
|
|
107
|
+
You are a ultimate translation generator server api.
|
|
108
108
|
|
|
109
|
-
Your task is to output **only one valid JSON object**, with **no text, explanations, or formatting
|
|
109
|
+
Your task is to translate a given text and output **only one valid JSON object**, with **no text, explanations, or formatting than the JSON**.
|
|
110
110
|
|
|
111
111
|
Follow these rules strictly:
|
|
112
112
|
|
|
@@ -116,7 +116,7 @@ Follow these rules strictly:
|
|
|
116
116
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
117
117
|
3. Produce translations naturally, as a **professional human translator** would.
|
|
118
118
|
4. Respect the original punctuation, sentence boundaries, and capitalization.
|
|
119
|
-
5. Consider only the following target languages: ${(config?.languages ? config.languages : []).join(", ")}.
|
|
119
|
+
5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
|
|
120
120
|
6. The final output must be a **valid JSON** following this exact schema:
|
|
121
121
|
|
|
122
122
|
{
|
|
@@ -378,12 +378,17 @@ async function getCache() {
|
|
|
378
378
|
throw error;
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
|
+
var savingQueue = Promise.resolve();
|
|
381
382
|
async function saveCache(cache) {
|
|
382
383
|
try {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
384
|
+
savingQueue = savingQueue.then(async () => {
|
|
385
|
+
const config = await awaitedConfig;
|
|
386
|
+
await createCacheDir();
|
|
387
|
+
const contents = JSON.stringify(cache, null, 2);
|
|
388
|
+
await fs.writeFile(`${config.cache.dir}/${config.cache.file}`, contents);
|
|
389
|
+
});
|
|
390
|
+
await savingQueue;
|
|
391
|
+
return cache;
|
|
387
392
|
} catch (error) {
|
|
388
393
|
throw error;
|
|
389
394
|
}
|
|
@@ -104,9 +104,9 @@ async function loadUserConfig() {
|
|
|
104
104
|
var awaitedConfig = loadUserConfig();
|
|
105
105
|
function defaultPrePrompt(config, extraInstructions) {
|
|
106
106
|
return `
|
|
107
|
-
You are a translation generator.
|
|
107
|
+
You are a ultimate translation generator server api.
|
|
108
108
|
|
|
109
|
-
Your task is to output **only one valid JSON object**, with **no text, explanations, or formatting
|
|
109
|
+
Your task is to translate a given text and output **only one valid JSON object**, with **no text, explanations, or formatting than the JSON**.
|
|
110
110
|
|
|
111
111
|
Follow these rules strictly:
|
|
112
112
|
|
|
@@ -116,7 +116,7 @@ Follow these rules strictly:
|
|
|
116
116
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
117
117
|
3. Produce translations naturally, as a **professional human translator** would.
|
|
118
118
|
4. Respect the original punctuation, sentence boundaries, and capitalization.
|
|
119
|
-
5. Consider only the following target languages: ${(config?.languages ? config.languages : []).join(", ")}.
|
|
119
|
+
5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
|
|
120
120
|
6. The final output must be a **valid JSON** following this exact schema:
|
|
121
121
|
|
|
122
122
|
{
|
|
@@ -368,12 +368,17 @@ async function createCacheDir() {
|
|
|
368
368
|
}
|
|
369
369
|
|
|
370
370
|
// src/data/save-cache.ts
|
|
371
|
+
var savingQueue = Promise.resolve();
|
|
371
372
|
async function saveCache(cache) {
|
|
372
373
|
try {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
374
|
+
savingQueue = savingQueue.then(async () => {
|
|
375
|
+
const config = await awaitedConfig;
|
|
376
|
+
await createCacheDir();
|
|
377
|
+
const contents = JSON.stringify(cache, null, 2);
|
|
378
|
+
await fs.writeFile(`${config.cache.dir}/${config.cache.file}`, contents);
|
|
379
|
+
});
|
|
380
|
+
await savingQueue;
|
|
381
|
+
return cache;
|
|
377
382
|
} catch (error) {
|
|
378
383
|
throw error;
|
|
379
384
|
}
|
|
@@ -308,9 +308,9 @@ async function loadUserConfig() {
|
|
|
308
308
|
var awaitedConfig = loadUserConfig();
|
|
309
309
|
function defaultPrePrompt(config, extraInstructions) {
|
|
310
310
|
return `
|
|
311
|
-
You are a translation generator.
|
|
311
|
+
You are a ultimate translation generator server api.
|
|
312
312
|
|
|
313
|
-
Your task is to output **only one valid JSON object**, with **no text, explanations, or formatting
|
|
313
|
+
Your task is to translate a given text and output **only one valid JSON object**, with **no text, explanations, or formatting than the JSON**.
|
|
314
314
|
|
|
315
315
|
Follow these rules strictly:
|
|
316
316
|
|
|
@@ -320,7 +320,7 @@ Follow these rules strictly:
|
|
|
320
320
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
321
321
|
3. Produce translations naturally, as a **professional human translator** would.
|
|
322
322
|
4. Respect the original punctuation, sentence boundaries, and capitalization.
|
|
323
|
-
5. Consider only the following target languages: ${(config?.languages ? config.languages : []).join(", ")}.
|
|
323
|
+
5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
|
|
324
324
|
6. The final output must be a **valid JSON** following this exact schema:
|
|
325
325
|
|
|
326
326
|
{
|
|
@@ -3,7 +3,7 @@ import '../config.mjs';
|
|
|
3
3
|
import '../constants/default-config.mjs';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import '../schemas/config.shcema.mjs';
|
|
6
|
+
import '../create-cache-id.mjs';
|
|
6
7
|
import './clear-cache.mjs';
|
|
7
|
-
import './create-cache-id.mjs';
|
|
8
8
|
import './get-cache.mjs';
|
|
9
9
|
import '../flat-template-string.mjs';
|
|
@@ -104,9 +104,9 @@ async function loadUserConfig() {
|
|
|
104
104
|
var awaitedConfig = loadUserConfig();
|
|
105
105
|
function defaultPrePrompt(config, extraInstructions) {
|
|
106
106
|
return `
|
|
107
|
-
You are a translation generator.
|
|
107
|
+
You are a ultimate translation generator server api.
|
|
108
108
|
|
|
109
|
-
Your task is to output **only one valid JSON object**, with **no text, explanations, or formatting
|
|
109
|
+
Your task is to translate a given text and output **only one valid JSON object**, with **no text, explanations, or formatting than the JSON**.
|
|
110
110
|
|
|
111
111
|
Follow these rules strictly:
|
|
112
112
|
|
|
@@ -116,7 +116,7 @@ Follow these rules strictly:
|
|
|
116
116
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
117
117
|
3. Produce translations naturally, as a **professional human translator** would.
|
|
118
118
|
4. Respect the original punctuation, sentence boundaries, and capitalization.
|
|
119
|
-
5. Consider only the following target languages: ${(config?.languages ? config.languages : []).join(", ")}.
|
|
119
|
+
5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
|
|
120
120
|
6. The final output must be a **valid JSON** following this exact schema:
|
|
121
121
|
|
|
122
122
|
{
|
|
@@ -378,12 +378,17 @@ async function getCache() {
|
|
|
378
378
|
throw error;
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
|
+
var savingQueue = Promise.resolve();
|
|
381
382
|
async function saveCache(cache) {
|
|
382
383
|
try {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
384
|
+
savingQueue = savingQueue.then(async () => {
|
|
385
|
+
const config = await awaitedConfig;
|
|
386
|
+
await createCacheDir();
|
|
387
|
+
const contents = JSON.stringify(cache, null, 2);
|
|
388
|
+
await fs.writeFile(`${config.cache.dir}/${config.cache.file}`, contents);
|
|
389
|
+
});
|
|
390
|
+
await savingQueue;
|
|
391
|
+
return cache;
|
|
387
392
|
} catch (error) {
|
|
388
393
|
throw error;
|
|
389
394
|
}
|
package/dist/data/get-cache.mjs
CHANGED
|
@@ -104,9 +104,9 @@ async function loadUserConfig() {
|
|
|
104
104
|
var awaitedConfig = loadUserConfig();
|
|
105
105
|
function defaultPrePrompt(config, extraInstructions) {
|
|
106
106
|
return `
|
|
107
|
-
You are a translation generator.
|
|
107
|
+
You are a ultimate translation generator server api.
|
|
108
108
|
|
|
109
|
-
Your task is to output **only one valid JSON object**, with **no text, explanations, or formatting
|
|
109
|
+
Your task is to translate a given text and output **only one valid JSON object**, with **no text, explanations, or formatting than the JSON**.
|
|
110
110
|
|
|
111
111
|
Follow these rules strictly:
|
|
112
112
|
|
|
@@ -116,7 +116,7 @@ Follow these rules strictly:
|
|
|
116
116
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
117
117
|
3. Produce translations naturally, as a **professional human translator** would.
|
|
118
118
|
4. Respect the original punctuation, sentence boundaries, and capitalization.
|
|
119
|
-
5. Consider only the following target languages: ${(config?.languages ? config.languages : []).join(", ")}.
|
|
119
|
+
5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
|
|
120
120
|
6. The final output must be a **valid JSON** following this exact schema:
|
|
121
121
|
|
|
122
122
|
{
|
|
@@ -3,7 +3,7 @@ import '../config.mjs';
|
|
|
3
3
|
import '../constants/default-config.mjs';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import '../schemas/config.shcema.mjs';
|
|
6
|
+
import '../create-cache-id.mjs';
|
|
6
7
|
import './clear-cache.mjs';
|
|
7
|
-
import './create-cache-id.mjs';
|
|
8
8
|
import './get-cache.mjs';
|
|
9
9
|
import '../flat-template-string.mjs';
|
|
@@ -104,9 +104,9 @@ async function loadUserConfig() {
|
|
|
104
104
|
var awaitedConfig = loadUserConfig();
|
|
105
105
|
function defaultPrePrompt(config, extraInstructions) {
|
|
106
106
|
return `
|
|
107
|
-
You are a translation generator.
|
|
107
|
+
You are a ultimate translation generator server api.
|
|
108
108
|
|
|
109
|
-
Your task is to output **only one valid JSON object**, with **no text, explanations, or formatting
|
|
109
|
+
Your task is to translate a given text and output **only one valid JSON object**, with **no text, explanations, or formatting than the JSON**.
|
|
110
110
|
|
|
111
111
|
Follow these rules strictly:
|
|
112
112
|
|
|
@@ -116,7 +116,7 @@ Follow these rules strictly:
|
|
|
116
116
|
- Apply these creatively but **without altering the meaning or punctuation** of the original text.
|
|
117
117
|
3. Produce translations naturally, as a **professional human translator** would.
|
|
118
118
|
4. Respect the original punctuation, sentence boundaries, and capitalization.
|
|
119
|
-
5. Consider only the following target languages: ${(config?.languages ? config.languages : []).join(", ")}.
|
|
119
|
+
5. Consider only the following target languages: ${(config?.languages ? Array.from(/* @__PURE__ */ new Set(["es-ES", ...config.languages, config.sourceLanguage])) : []).join(", ")}.
|
|
120
120
|
6. The final output must be a **valid JSON** following this exact schema:
|
|
121
121
|
|
|
122
122
|
{
|
|
@@ -378,12 +378,17 @@ async function getCache() {
|
|
|
378
378
|
throw error;
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
|
+
var savingQueue = Promise.resolve();
|
|
381
382
|
async function saveCache(cache) {
|
|
382
383
|
try {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
384
|
+
savingQueue = savingQueue.then(async () => {
|
|
385
|
+
const config = await awaitedConfig;
|
|
386
|
+
await createCacheDir();
|
|
387
|
+
const contents = JSON.stringify(cache, null, 2);
|
|
388
|
+
await fs.writeFile(`${config.cache.dir}/${config.cache.file}`, contents);
|
|
389
|
+
});
|
|
390
|
+
await savingQueue;
|
|
391
|
+
return cache;
|
|
387
392
|
} catch (error) {
|
|
388
393
|
throw error;
|
|
389
394
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a deterministic 128-bit hexadecimal signature for the provided input.
|
|
3
|
+
*
|
|
4
|
+
* The implementation deliberately skips cryptographic guarantees, focusing instead
|
|
5
|
+
* on stability and speed so that identical strings always return the same 32-char
|
|
6
|
+
* lowercase hex output (without prefixes or separators).
|
|
7
|
+
*
|
|
8
|
+
* @param input - Text to hash
|
|
9
|
+
* @returns 32-character lowercase hexadecimal digest
|
|
10
|
+
*/
|
|
11
|
+
declare function md5(input: string): string;
|
|
12
|
+
|
|
13
|
+
export { md5 };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/data/md5.ts
|
|
2
|
+
var INITIAL_STATE = [1831565813, 461845907, 2246822507, 3266489909];
|
|
3
|
+
var MULTIPLIERS = [668265261, 374761393, 2654435769, 2496678331];
|
|
4
|
+
var AVA_MULT1 = 2146121005;
|
|
5
|
+
var AVA_MULT2 = 2221713035;
|
|
6
|
+
function seedState(input) {
|
|
7
|
+
const state = [...INITIAL_STATE];
|
|
8
|
+
for (const char of input) {
|
|
9
|
+
const codePoint = char.codePointAt(0) ?? 0;
|
|
10
|
+
for (let i = 0; i < state.length; i++) {
|
|
11
|
+
state[i] = Math.imul(state[i] ^ codePoint, MULTIPLIERS[i]);
|
|
12
|
+
state[i] = rotateLeft(state[i], (i + 1) * 3);
|
|
13
|
+
}
|
|
14
|
+
state[0] ^= state[3] >>> 11;
|
|
15
|
+
state[1] ^= state[0] << 7;
|
|
16
|
+
state[2] ^= state[1] >>> 13;
|
|
17
|
+
state[3] ^= state[2] << 5;
|
|
18
|
+
}
|
|
19
|
+
return state;
|
|
20
|
+
}
|
|
21
|
+
function rotateLeft(value, shift) {
|
|
22
|
+
return value << shift | value >>> 32 - shift;
|
|
23
|
+
}
|
|
24
|
+
function avalanche(value) {
|
|
25
|
+
value ^= value >>> 16;
|
|
26
|
+
value = Math.imul(value, AVA_MULT1);
|
|
27
|
+
value ^= value >>> 15;
|
|
28
|
+
value = Math.imul(value, AVA_MULT2);
|
|
29
|
+
value ^= value >>> 16;
|
|
30
|
+
return value >>> 0;
|
|
31
|
+
}
|
|
32
|
+
function toHex(value) {
|
|
33
|
+
return (value >>> 0).toString(16).padStart(8, "0");
|
|
34
|
+
}
|
|
35
|
+
function mixState([h1, h2, h3, h4]) {
|
|
36
|
+
h1 = avalanche(h1 ^ h3);
|
|
37
|
+
h2 = avalanche(h2 ^ h4);
|
|
38
|
+
h3 = avalanche(h3 ^ h1);
|
|
39
|
+
h4 = avalanche(h4 ^ h2);
|
|
40
|
+
return [h1, h2, h3, h4];
|
|
41
|
+
}
|
|
42
|
+
function md5(input) {
|
|
43
|
+
const state = mixState(seedState(input));
|
|
44
|
+
return state.map(toHex).join("");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { md5 };
|