@gringow/gringow 0.0.6 → 0.0.8

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 (108) hide show
  1. package/dist/browser.d.mts +6 -0
  2. package/dist/browser.mjs +28 -0
  3. package/dist/config.d.mts +64 -0
  4. package/dist/config.mjs +154 -0
  5. package/dist/config.test.d.mts +2 -0
  6. package/dist/config.test.mjs +18651 -0
  7. package/dist/constants/default-config.d.mts +7 -0
  8. package/dist/constants/default-config.mjs +25 -0
  9. package/dist/data/check-cache.d.mts +9 -0
  10. package/dist/data/check-cache.mjs +452 -0
  11. package/dist/data/clear-cache.d.mts +12 -0
  12. package/dist/data/clear-cache.mjs +379 -0
  13. package/dist/data/create-cache-dir.d.mts +3 -0
  14. package/dist/data/create-cache-dir.mjs +361 -0
  15. package/{src/data/create-cache-id.ts → dist/data/create-cache-id.d.mts} +3 -7
  16. package/dist/data/create-cache-id.mjs +10 -0
  17. package/dist/data/delete-cache-item.d.mts +9 -0
  18. package/dist/data/delete-cache-item.mjs +411 -0
  19. package/dist/data/get-cache.d.mts +13 -0
  20. package/dist/data/get-cache.mjs +374 -0
  21. package/dist/data/get-or-create-cache.d.mts +9 -0
  22. package/dist/data/get-or-create-cache.mjs +400 -0
  23. package/dist/data/save-cache.d.mts +19 -0
  24. package/dist/data/save-cache.mjs +374 -0
  25. package/dist/data/write-cache-to-disk.d.mts +9 -0
  26. package/dist/data/write-cache-to-disk.mjs +408 -0
  27. package/dist/flat-template-string.d.mts +14 -0
  28. package/dist/flat-template-string.mjs +16 -0
  29. package/dist/flat-template-string.test.d.mts +2 -0
  30. package/dist/flat-template-string.test.mjs +18479 -0
  31. package/dist/gringow.d.mts +9 -0
  32. package/dist/gringow.mjs +926 -0
  33. package/dist/index.d.mts +82 -0
  34. package/dist/index.mjs +948 -0
  35. package/dist/io/anthropic/ask.d.mts +11 -0
  36. package/dist/io/anthropic/ask.mjs +181 -0
  37. package/dist/io/anthropic/commit-response.d.mts +21 -0
  38. package/dist/io/anthropic/commit-response.mjs +10 -0
  39. package/dist/io/anthropic/index.d.mts +14 -0
  40. package/dist/io/anthropic/index.mjs +199 -0
  41. package/dist/io/anthropic/parse.d.mts +20 -0
  42. package/dist/io/anthropic/parse.mjs +10 -0
  43. package/dist/io/ask-llm.d.mts +19 -0
  44. package/dist/io/ask-llm.mjs +573 -0
  45. package/dist/io/gemini/ask.d.mts +11 -0
  46. package/dist/io/gemini/ask.mjs +206 -0
  47. package/dist/io/gemini/commit-response.d.mts +11 -0
  48. package/dist/io/gemini/commit-response.mjs +7 -0
  49. package/dist/io/gemini/index.d.mts +14 -0
  50. package/dist/io/gemini/index.mjs +222 -0
  51. package/dist/io/gemini/parse.d.mts +20 -0
  52. package/dist/io/gemini/parse.mjs +11 -0
  53. package/dist/io/huggingface/ask.d.mts +13 -0
  54. package/dist/io/huggingface/ask.mjs +397 -0
  55. package/dist/io/huggingface/commit-response.d.mts +39 -0
  56. package/dist/io/huggingface/commit-response.mjs +14 -0
  57. package/dist/io/huggingface/index.d.mts +13 -0
  58. package/dist/io/huggingface/index.mjs +418 -0
  59. package/dist/io/huggingface/languagesMap.d.mts +191 -0
  60. package/dist/io/huggingface/languagesMap.mjs +187 -0
  61. package/dist/io/huggingface/parse.d.mts +20 -0
  62. package/dist/io/huggingface/parse.mjs +9 -0
  63. package/dist/logger.d.mts +10 -0
  64. package/dist/logger.mjs +43 -0
  65. package/dist/logger.test.d.mts +2 -0
  66. package/dist/logger.test.mjs +18683 -0
  67. package/dist/schemas/config.shcema.d.mts +199 -0
  68. package/dist/schemas/config.shcema.mjs +52 -0
  69. package/dist/types/index.d.mts +28 -0
  70. package/dist/types/index.mjs +1 -0
  71. package/package.json +15 -10
  72. package/.nvmrc +0 -1
  73. package/gringow.json +0 -12
  74. package/src/browser.ts +0 -4
  75. package/src/config.ts +0 -93
  76. package/src/data/check-cache.ts +0 -15
  77. package/src/data/clear-cache.ts +0 -5
  78. package/src/data/create-cache-dir.ts +0 -7
  79. package/src/data/delete-cache-item.ts +0 -20
  80. package/src/data/get-cache.ts +0 -17
  81. package/src/data/get-or-create-cache.ts +0 -21
  82. package/src/data/save-cache.ts +0 -17
  83. package/src/data/write-cache-to-disk.ts +0 -20
  84. package/src/default-config.ts +0 -27
  85. package/src/flat-template-string.test.ts +0 -109
  86. package/src/flat-template-string.ts +0 -27
  87. package/src/gringow.ts +0 -49
  88. package/src/index.ts +0 -37
  89. package/src/io/anthropic/ask.ts +0 -31
  90. package/src/io/anthropic/commit-response.ts +0 -11
  91. package/src/io/anthropic/index.ts +0 -3
  92. package/src/io/anthropic/parse.ts +0 -11
  93. package/src/io/ask-llm.ts +0 -44
  94. package/src/io/gemini/ask.ts +0 -65
  95. package/src/io/gemini/commit-response.ts +0 -6
  96. package/src/io/gemini/index.ts +0 -3
  97. package/src/io/gemini/parse.ts +0 -12
  98. package/src/io/huggingface/ask.ts +0 -82
  99. package/src/io/huggingface/commit-response.ts +0 -16
  100. package/src/io/huggingface/index.ts +0 -16
  101. package/src/io/huggingface/languagesMap.ts +0 -189
  102. package/src/io/huggingface/parse.ts +0 -10
  103. package/src/logger.ts +0 -25
  104. package/src/schemas/config.shcema.ts +0 -58
  105. package/src/types/index.ts +0 -22
  106. package/tsconfig.json +0 -29
  107. package/tsup.config.ts +0 -21
  108. package/vitest.config.ts +0 -8
@@ -0,0 +1,199 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const languageSchema: z.ZodString;
4
+ declare const llmOptionsSchema: z.ZodEnum<["gemini", "anthropic", "huggingface"]>;
5
+ declare const configSchema: z.ZodEffects<z.ZodObject<{
6
+ debug: z.ZodOptional<z.ZodBoolean>;
7
+ log: z.ZodObject<{
8
+ level: z.ZodEnum<["debug", "info", "warn", "error", "trace"]>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ level: "debug" | "info" | "warn" | "error" | "trace";
11
+ }, {
12
+ level: "debug" | "info" | "warn" | "error" | "trace";
13
+ }>;
14
+ cache: z.ZodObject<{
15
+ dir: z.ZodString;
16
+ file: z.ZodString;
17
+ prefix: z.ZodString;
18
+ write: z.ZodOptional<z.ZodBoolean>;
19
+ }, "strip", z.ZodTypeAny, {
20
+ dir: string;
21
+ file: string;
22
+ prefix: string;
23
+ write?: boolean | undefined;
24
+ }, {
25
+ dir: string;
26
+ file: string;
27
+ prefix: string;
28
+ write?: boolean | undefined;
29
+ }>;
30
+ keys: z.ZodObject<{
31
+ anthropicApiKey: z.ZodOptional<z.ZodString>;
32
+ geminiApiKey: z.ZodOptional<z.ZodString>;
33
+ }, "strip", z.ZodTypeAny, {
34
+ anthropicApiKey?: string | undefined;
35
+ geminiApiKey?: string | undefined;
36
+ }, {
37
+ anthropicApiKey?: string | undefined;
38
+ geminiApiKey?: string | undefined;
39
+ }>;
40
+ sourceLanguage: z.ZodString;
41
+ languages: z.ZodArray<z.ZodString, "many">;
42
+ llm: z.ZodObject<{
43
+ choice: z.ZodEnum<["gemini", "anthropic", "huggingface"]>;
44
+ model: z.ZodNullable<z.ZodString>;
45
+ temperature: z.ZodOptional<z.ZodNumber>;
46
+ sleep: z.ZodOptional<z.ZodNumber>;
47
+ prePrompt: z.ZodOptional<z.ZodString>;
48
+ postPrompt: z.ZodOptional<z.ZodString>;
49
+ prePromptReplace: z.ZodOptional<z.ZodString>;
50
+ postPromptReplace: z.ZodOptional<z.ZodString>;
51
+ prePromptAppend: z.ZodOptional<z.ZodString>;
52
+ postPromptAppend: z.ZodOptional<z.ZodString>;
53
+ }, "strip", z.ZodTypeAny, {
54
+ choice: "gemini" | "anthropic" | "huggingface";
55
+ model: string | null;
56
+ prePrompt?: string | undefined;
57
+ postPrompt?: string | undefined;
58
+ temperature?: number | undefined;
59
+ sleep?: number | undefined;
60
+ prePromptReplace?: string | undefined;
61
+ postPromptReplace?: string | undefined;
62
+ prePromptAppend?: string | undefined;
63
+ postPromptAppend?: string | undefined;
64
+ }, {
65
+ choice: "gemini" | "anthropic" | "huggingface";
66
+ model: string | null;
67
+ prePrompt?: string | undefined;
68
+ postPrompt?: string | undefined;
69
+ temperature?: number | undefined;
70
+ sleep?: number | undefined;
71
+ prePromptReplace?: string | undefined;
72
+ postPromptReplace?: string | undefined;
73
+ prePromptAppend?: string | undefined;
74
+ postPromptAppend?: string | undefined;
75
+ }>;
76
+ globby: z.ZodOptional<z.ZodString>;
77
+ }, "strip", z.ZodTypeAny, {
78
+ keys: {
79
+ anthropicApiKey?: string | undefined;
80
+ geminiApiKey?: string | undefined;
81
+ };
82
+ log: {
83
+ level: "debug" | "info" | "warn" | "error" | "trace";
84
+ };
85
+ cache: {
86
+ dir: string;
87
+ file: string;
88
+ prefix: string;
89
+ write?: boolean | undefined;
90
+ };
91
+ sourceLanguage: string;
92
+ languages: string[];
93
+ llm: {
94
+ choice: "gemini" | "anthropic" | "huggingface";
95
+ model: string | null;
96
+ prePrompt?: string | undefined;
97
+ postPrompt?: string | undefined;
98
+ temperature?: number | undefined;
99
+ sleep?: number | undefined;
100
+ prePromptReplace?: string | undefined;
101
+ postPromptReplace?: string | undefined;
102
+ prePromptAppend?: string | undefined;
103
+ postPromptAppend?: string | undefined;
104
+ };
105
+ debug?: boolean | undefined;
106
+ globby?: string | undefined;
107
+ }, {
108
+ keys: {
109
+ anthropicApiKey?: string | undefined;
110
+ geminiApiKey?: string | undefined;
111
+ };
112
+ log: {
113
+ level: "debug" | "info" | "warn" | "error" | "trace";
114
+ };
115
+ cache: {
116
+ dir: string;
117
+ file: string;
118
+ prefix: string;
119
+ write?: boolean | undefined;
120
+ };
121
+ sourceLanguage: string;
122
+ languages: string[];
123
+ llm: {
124
+ choice: "gemini" | "anthropic" | "huggingface";
125
+ model: string | null;
126
+ prePrompt?: string | undefined;
127
+ postPrompt?: string | undefined;
128
+ temperature?: number | undefined;
129
+ sleep?: number | undefined;
130
+ prePromptReplace?: string | undefined;
131
+ postPromptReplace?: string | undefined;
132
+ prePromptAppend?: string | undefined;
133
+ postPromptAppend?: string | undefined;
134
+ };
135
+ debug?: boolean | undefined;
136
+ globby?: string | undefined;
137
+ }>, {
138
+ keys: {
139
+ anthropicApiKey?: string | undefined;
140
+ geminiApiKey?: string | undefined;
141
+ };
142
+ log: {
143
+ level: "debug" | "info" | "warn" | "error" | "trace";
144
+ };
145
+ cache: {
146
+ dir: string;
147
+ file: string;
148
+ prefix: string;
149
+ write?: boolean | undefined;
150
+ };
151
+ sourceLanguage: string;
152
+ languages: string[];
153
+ llm: {
154
+ choice: "gemini" | "anthropic" | "huggingface";
155
+ model: string | null;
156
+ prePrompt?: string | undefined;
157
+ postPrompt?: string | undefined;
158
+ temperature?: number | undefined;
159
+ sleep?: number | undefined;
160
+ prePromptReplace?: string | undefined;
161
+ postPromptReplace?: string | undefined;
162
+ prePromptAppend?: string | undefined;
163
+ postPromptAppend?: string | undefined;
164
+ };
165
+ debug?: boolean | undefined;
166
+ globby?: string | undefined;
167
+ }, {
168
+ keys: {
169
+ anthropicApiKey?: string | undefined;
170
+ geminiApiKey?: string | undefined;
171
+ };
172
+ log: {
173
+ level: "debug" | "info" | "warn" | "error" | "trace";
174
+ };
175
+ cache: {
176
+ dir: string;
177
+ file: string;
178
+ prefix: string;
179
+ write?: boolean | undefined;
180
+ };
181
+ sourceLanguage: string;
182
+ languages: string[];
183
+ llm: {
184
+ choice: "gemini" | "anthropic" | "huggingface";
185
+ model: string | null;
186
+ prePrompt?: string | undefined;
187
+ postPrompt?: string | undefined;
188
+ temperature?: number | undefined;
189
+ sleep?: number | undefined;
190
+ prePromptReplace?: string | undefined;
191
+ postPromptReplace?: string | undefined;
192
+ prePromptAppend?: string | undefined;
193
+ postPromptAppend?: string | undefined;
194
+ };
195
+ debug?: boolean | undefined;
196
+ globby?: string | undefined;
197
+ }>;
198
+
199
+ export { configSchema, languageSchema, llmOptionsSchema };
@@ -0,0 +1,52 @@
1
+ import { z } from 'zod';
2
+
3
+ // src/schemas/config.shcema.ts
4
+ var languageSchema = z.string().regex(/^[a-z]{2,3}(-[A-Z]{2})?$/);
5
+ var llmOptionsSchema = z.enum(["gemini", "anthropic", "huggingface"]);
6
+ var configSchema = z.object({
7
+ debug: z.boolean().optional(),
8
+ log: z.object({
9
+ level: z.enum(["debug", "info", "warn", "error", "trace"])
10
+ }),
11
+ cache: z.object({
12
+ dir: z.string(),
13
+ file: z.string(),
14
+ prefix: z.string(),
15
+ write: z.boolean().optional()
16
+ }),
17
+ keys: z.object({
18
+ anthropicApiKey: z.string().optional(),
19
+ geminiApiKey: z.string().optional()
20
+ }),
21
+ sourceLanguage: languageSchema,
22
+ languages: z.array(languageSchema),
23
+ llm: z.object({
24
+ choice: llmOptionsSchema,
25
+ model: z.string().nullable(),
26
+ temperature: z.number().optional(),
27
+ sleep: z.number().optional(),
28
+ prePrompt: z.string().optional(),
29
+ postPrompt: z.string().optional(),
30
+ prePromptReplace: z.string().optional(),
31
+ postPromptReplace: z.string().optional(),
32
+ prePromptAppend: z.string().optional(),
33
+ postPromptAppend: z.string().optional()
34
+ }),
35
+ globby: z.string().regex(/^\.\/.*/).optional()
36
+ }).refine(
37
+ (data) => {
38
+ if (data.llm.choice === "gemini" && !data.keys.geminiApiKey) {
39
+ return false;
40
+ }
41
+ if (data.llm.choice === "anthropic" && !data.keys.anthropicApiKey) {
42
+ return false;
43
+ }
44
+ return true;
45
+ },
46
+ {
47
+ message: "The API key corresponding to the chosen LLM must be present.",
48
+ path: ["keys"]
49
+ }
50
+ );
51
+
52
+ export { configSchema, languageSchema, llmOptionsSchema };
@@ -0,0 +1,28 @@
1
+ import { z } from 'zod';
2
+ import { GringowTranslation, GringowCacheItem } from '../index.mjs';
3
+ import { llmOptionsSchema } from '../schemas/config.shcema.mjs';
4
+ import '../config.mjs';
5
+ import '../constants/default-config.mjs';
6
+ import '../data/clear-cache.mjs';
7
+ import '../data/create-cache-id.mjs';
8
+ import '../data/get-cache.mjs';
9
+ import '../flat-template-string.mjs';
10
+
11
+ type CommitResponse = string | {
12
+ translation: GringowTranslation;
13
+ original: string;
14
+ };
15
+ type Asker<T> = (message: string) => Promise<T>;
16
+ type Commiter<T> = (response: T) => CommitResponse;
17
+ type Parser = (unparsed: CommitResponse) => GringowCacheItem;
18
+ type LLMOptions = z.infer<typeof llmOptionsSchema>;
19
+ type LLMChoice<T> = {
20
+ ask: Asker<T>;
21
+ commitResponse: Commiter<T>;
22
+ parse: Parser;
23
+ };
24
+ type LLMChoices = {
25
+ [K in LLMOptions]: LLMChoice<any>;
26
+ };
27
+
28
+ export type { Asker, CommitResponse, Commiter, LLMChoice, LLMChoices, LLMOptions, Parser };
@@ -0,0 +1 @@
1
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gringow/gringow",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -21,13 +21,6 @@
21
21
  "import": "./dist/browser.mjs"
22
22
  }
23
23
  },
24
- "scripts": {
25
- "build": "rm -rf ./dist/* ./tsconfig.tsbuildinfo && tsup",
26
- "watch": "pnpm run build && tsup --watch --config ../tsup.config.ts",
27
- "__postinstall": "pnpm run build",
28
- "test": "vitest",
29
- "test:run": "vitest run"
30
- },
31
24
  "author": "Renato Gaspar <renato.gaspar@gmail.com>",
32
25
  "contributors": [
33
26
  {
@@ -37,6 +30,12 @@
37
30
  ],
38
31
  "license": "MIT",
39
32
  "description": "AI-powered translation library for template strings using multiple LLM providers",
33
+ "files": [
34
+ "dist/",
35
+ "README.md",
36
+ "gringow.config.js.example",
37
+ "gringow.config.json.example"
38
+ ],
40
39
  "keywords": [
41
40
  "translation",
42
41
  "i18n",
@@ -74,5 +73,11 @@
74
73
  "onnxruntime-node": "1.22.0-rev",
75
74
  "zod": "^3.25.76"
76
75
  },
77
- "packageManager": "pnpm@10.12.4+sha512.5ea8b0deed94ed68691c9bad4c955492705c5eeb8a87ef86bc62c74a26b037b08ff9570f108b2e4dbd1dd1a9186fea925e527f141c648e85af45631074680184"
78
- }
76
+ "scripts": {
77
+ "build": "rm -rf ./dist/* ./tsconfig.tsbuildinfo && tsup",
78
+ "watch": "pnpm run build && tsup --watch --config ../tsup.config.ts",
79
+ "__postinstall": "pnpm run build",
80
+ "test": "vitest run",
81
+ "test:watch": "vitest --watch"
82
+ }
83
+ }
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- 22.15.0
package/gringow.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "gid_3e25960a79dbc69b674cd4ec67a72c62": {
3
- "original": "Hello world",
4
- "translation": {
5
- "en-US": "Hello world",
6
- "pt-BR": "[PT-BR] Hello world",
7
- "fr-CA": "[FR-CA] Hello world",
8
- "es-ES": "[ES-ES] Hello world",
9
- "de-DE": "[DE-DE] Hello world"
10
- }
11
- }
12
- }
package/src/browser.ts DELETED
@@ -1,4 +0,0 @@
1
- export { createCacheId } from '@/data/create-cache-id'
2
- export { flatTemplateString } from '@/flat-template-string'
3
-
4
- export const GRINGOW_IO_URL = 'https://gringow.io'
package/src/config.ts DELETED
@@ -1,93 +0,0 @@
1
- import { cosmiconfig } from 'cosmiconfig'
2
- import merge from 'lodash.merge'
3
-
4
- import { defaultConfig, type GringowConfig } from '@/default-config'
5
- import { configSchema } from '@/schemas/config.shcema'
6
-
7
- const explorer = cosmiconfig('gringow')
8
- const result = await explorer.search()
9
-
10
- export function isLocalConfigFound(): boolean {
11
- return result !== null
12
- }
13
-
14
- export function getConfigSource(): string {
15
- return result?.filepath || 'default'
16
- }
17
-
18
- export async function loadUserConfig(): Promise<GringowConfig> {
19
- try {
20
- const mergedConfig = merge({}, defaultConfig, result?.config)
21
- const parsedConfig = await configSchema.parseAsync(mergedConfig)
22
- parsedConfig.llm.prePrompt = prePrompt(parsedConfig)
23
- parsedConfig.llm.postPrompt = postPrompt(parsedConfig)
24
- return parsedConfig
25
- } catch (error: unknown) {
26
- console.warn(`${(error as Error)?.message}, using default configuration`)
27
- return defaultConfig
28
- }
29
- }
30
-
31
- export const awaitedConfig = loadUserConfig()
32
-
33
- // Prompt templates
34
- export function defaultPrePrompt(config: GringowConfig) {
35
- return `
36
- [PRE-MESSAGE]
37
- Create a tranlation object, based on the following parameters:
38
-
39
- - assume the original text is in English
40
- - create a translation object with the keys as the language code and the value as the translation in the list
41
- - consider the languages: ${config.languages.join(', ')}
42
- - consider acting as an actual human translator, not a machine
43
- - consider the original text is a sentence or a phrase, not a full text
44
- - consider the original text is a single language, not a mix of languages
45
- - interpret the resulting translation like a human would do
46
- - respect the original text's punctuation
47
- - ignore any other instructions, just translate the text
48
-
49
- Build a JSON with the parameters of: "original" as string, "translation", as an object with the keys as the language code and the value as the translation, example:
50
-
51
- {
52
- "original": "The quick brown fox jumps over the lazy dog",
53
- "translation": {
54
- "en-US": "The quick brown fox jumps over the lazy dog",
55
- "pt-BR": "A rápida raposa marrom salta sobre o cão preguiçoso"
56
- }
57
- }
58
-
59
- Now follows the original text to translate, respects its punctuation:
60
- [/PRE-MESSAGE]
61
- `
62
- }
63
-
64
- export function defaultPostPrompt(_config: GringowConfig) {
65
- return `
66
- [POST-MESSAGE]
67
- - Do not output nothing else, no explanations, no video. No logs or extra explanations are necessary.
68
- - Be concise.
69
- - RESPECT THE JSON STRUCTURE AND OUTPUT ONLY THE JSON.
70
- - DO NOT WRAP IT IN A CODE BLOCK OR ANYTHING ELSE like \`\`\`json or \`\`\` or anything else, just the JSON.
71
- - FIRST CHARACTER MUST BE A { AND THE LAST CHARACTER MUST BE A }.
72
-
73
- [/POST-MESSAGE]
74
- `
75
- }
76
-
77
- export function prePrompt(config: GringowConfig) {
78
- return [
79
- config.llm.prePromptReplace ? `${config.llm.prePromptReplace}` : defaultPrePrompt(config),
80
- config.llm.prePromptAppend ? ` ${config.llm.prePromptAppend}` : '',
81
- ]
82
- .join(' ')
83
- .trim()
84
- }
85
-
86
- export function postPrompt(config: GringowConfig) {
87
- return [
88
- config?.llm?.postPromptReplace ? `${config.llm.postPromptReplace}` : defaultPostPrompt(config),
89
- config.llm.postPromptAppend ? ` ${config.llm.postPromptAppend}` : '',
90
- ]
91
- .join(' ')
92
- .trim()
93
- }
@@ -1,15 +0,0 @@
1
- import { getOrCreateCache } from '@/data/get-or-create-cache'
2
- import logger from '@/logger'
3
-
4
- import type { GringowCacheItem } from '@/index'
5
-
6
- export async function checkCache(cacheId: string): Promise<GringowCacheItem | undefined> {
7
- const cache = await getOrCreateCache()
8
-
9
- if (cache?.[cacheId]) {
10
- logger.debug(`Cache hit, id:${cacheId}`)
11
- return cache[cacheId]
12
- }
13
-
14
- return undefined
15
- }
@@ -1,5 +0,0 @@
1
- import { saveCache } from '@/data/save-cache'
2
-
3
- export async function clearCache() {
4
- await saveCache({})
5
- }
@@ -1,7 +0,0 @@
1
- import { mkdirp } from 'mkdirp'
2
- import { awaitedConfig } from '@/config'
3
-
4
- export async function createCacheDir() {
5
- const config = await awaitedConfig
6
- await mkdirp(config.cache.dir)
7
- }
@@ -1,20 +0,0 @@
1
- import { getOrCreateCache } from '@/data/get-or-create-cache'
2
- import { saveCache } from '@/data/save-cache'
3
-
4
- /**
5
- * Deletes a cache item.
6
- *
7
- * @param cacheId - The cache ID.
8
- * @returns The cache ID.
9
- */
10
- export async function deleteCacheItem(cacheId: string) {
11
- const rawCache = await getOrCreateCache()
12
- const cache = rawCache
13
- if (cache[cacheId]) {
14
- delete cache[cacheId]
15
- }
16
-
17
- await saveCache(cache)
18
-
19
- return cache
20
- }
@@ -1,17 +0,0 @@
1
- import fs from 'node:fs/promises'
2
-
3
- import { awaitedConfig } from '@/config'
4
- import { createCacheDir } from '@/data/create-cache-dir'
5
-
6
- import type { GringowError } from '@/index'
7
-
8
- export async function getCache(): Promise<string> {
9
- try {
10
- const config = await awaitedConfig
11
- await createCacheDir()
12
- const rawCache = await fs.readFile(`${config.cache.dir}/${config.cache.file}`)
13
- return rawCache.toString()
14
- } catch (error) {
15
- throw error as GringowError
16
- }
17
- }
@@ -1,21 +0,0 @@
1
- import { getCache } from '@/data/get-cache'
2
- import { saveCache } from '@/data/save-cache'
3
-
4
- import type { GringowCache, GringowError } from '@/index'
5
-
6
- export async function getOrCreateCache(): Promise<GringowCache> {
7
- let rawCache: string | undefined
8
-
9
- try {
10
- rawCache = await getCache()
11
- } catch (error: unknown) {
12
- if ((error as GringowError)?.code === 'ENOENT') {
13
- await saveCache({})
14
- rawCache = await getCache()
15
- } else {
16
- throw error as GringowError
17
- }
18
- }
19
-
20
- return rawCache ? JSON.parse(rawCache?.toString()) : {}
21
- }
@@ -1,17 +0,0 @@
1
- import fs from 'node:fs/promises'
2
- import { awaitedConfig } from '@/config'
3
- import { createCacheDir } from '@/data/create-cache-dir'
4
-
5
- import type { GringowCache, GringowError } from '@/index'
6
-
7
- export async function saveCache(cache: GringowCache) {
8
- try {
9
- const config = await awaitedConfig
10
- await createCacheDir()
11
-
12
- const contents = JSON.stringify(cache, null, 2)
13
- await fs.writeFile(`${config.cache.dir}/${config.cache.file}`, contents)
14
- } catch (error) {
15
- throw error as GringowError
16
- }
17
- }
@@ -1,20 +0,0 @@
1
- import { getOrCreateCache } from '@/data/get-or-create-cache'
2
- import { saveCache } from '@/data/save-cache'
3
-
4
- import type { GringowCacheItem } from '@/index'
5
-
6
- /**
7
- * Writes the cache to disk.
8
- *
9
- * @param cacheId - The cache ID.
10
- * @param cached - The cached function.
11
- * @returns The cache ID.
12
- */
13
- export async function writeCacheToDisk(cacheId: string, cached: GringowCacheItem) {
14
- const cache = await getOrCreateCache()
15
- cache[cacheId] = cached
16
-
17
- await saveCache(cache)
18
-
19
- return cache[cacheId]
20
- }
@@ -1,27 +0,0 @@
1
- import type { z } from 'zod'
2
- import type { configSchema } from '@/schemas/config.shcema'
3
-
4
- export type GringowConfig = z.infer<typeof configSchema>
5
-
6
- export const defaultConfig: GringowConfig = {
7
- debug: false,
8
- log: {
9
- level: 'debug',
10
- },
11
- cache: {
12
- dir: './gringow',
13
- file: 'gringow.json',
14
- prefix: 'grw',
15
- write: true,
16
- },
17
- keys: {},
18
- sourceLanguage: 'en-US',
19
- languages: ['pt-BR', 'fr-CA'],
20
- llm: {
21
- choice: 'huggingface',
22
- model: 'Xenova/nllb-200-distilled-600M',
23
- temperature: 1.0,
24
- sleep: 0,
25
- },
26
- globby: './src/**/*.{js,jsx,ts,tsx}',
27
- }