@gringow/gringow 0.0.4 → 0.0.7

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 (104) hide show
  1. package/dist/browser.d.mts +6 -0
  2. package/dist/browser.mjs +28 -0
  3. package/dist/config.d.mts +44 -0
  4. package/dist/config.mjs +154 -0
  5. package/dist/data/check-cache.d.mts +9 -0
  6. package/dist/data/check-cache.mjs +430 -0
  7. package/dist/data/clear-cache.d.mts +3 -0
  8. package/dist/data/clear-cache.mjs +379 -0
  9. package/dist/data/create-cache-dir.d.mts +3 -0
  10. package/dist/data/create-cache-dir.mjs +361 -0
  11. package/{src/data/create-cache-id.ts → dist/data/create-cache-id.d.mts} +3 -7
  12. package/dist/data/create-cache-id.mjs +10 -0
  13. package/dist/data/delete-cache-item.d.mts +9 -0
  14. package/dist/data/delete-cache-item.mjs +411 -0
  15. package/dist/data/get-cache.d.mts +3 -0
  16. package/dist/data/get-cache.mjs +374 -0
  17. package/dist/data/get-or-create-cache.d.mts +9 -0
  18. package/dist/data/get-or-create-cache.mjs +400 -0
  19. package/dist/data/save-cache.d.mts +13 -0
  20. package/dist/data/save-cache.mjs +374 -0
  21. package/dist/data/write-cache-to-disk.d.mts +9 -0
  22. package/dist/data/write-cache-to-disk.mjs +408 -0
  23. package/dist/default-config.d.mts +7 -0
  24. package/dist/default-config.mjs +25 -0
  25. package/dist/flat-template-string.d.mts +14 -0
  26. package/dist/flat-template-string.mjs +16 -0
  27. package/dist/flat-template-string.test.d.mts +2 -0
  28. package/dist/flat-template-string.test.mjs +18479 -0
  29. package/dist/gringow.d.mts +9 -0
  30. package/dist/gringow.mjs +904 -0
  31. package/dist/index.d.mts +60 -0
  32. package/dist/index.mjs +926 -0
  33. package/dist/io/anthropic/ask.d.mts +5 -0
  34. package/dist/io/anthropic/ask.mjs +181 -0
  35. package/dist/io/anthropic/commit-response.d.mts +15 -0
  36. package/dist/io/anthropic/commit-response.mjs +10 -0
  37. package/dist/io/anthropic/index.d.mts +14 -0
  38. package/dist/io/anthropic/index.mjs +199 -0
  39. package/dist/io/anthropic/parse.d.mts +14 -0
  40. package/dist/io/anthropic/parse.mjs +10 -0
  41. package/dist/io/ask-llm.d.mts +13 -0
  42. package/dist/io/ask-llm.mjs +573 -0
  43. package/dist/io/gemini/ask.d.mts +5 -0
  44. package/dist/io/gemini/ask.mjs +206 -0
  45. package/dist/io/gemini/commit-response.d.mts +5 -0
  46. package/dist/io/gemini/commit-response.mjs +7 -0
  47. package/dist/io/gemini/index.d.mts +14 -0
  48. package/dist/io/gemini/index.mjs +222 -0
  49. package/dist/io/gemini/parse.d.mts +14 -0
  50. package/dist/io/gemini/parse.mjs +11 -0
  51. package/dist/io/huggingface/ask.d.mts +13 -0
  52. package/dist/io/huggingface/ask.mjs +397 -0
  53. package/dist/io/huggingface/commit-response.d.mts +27 -0
  54. package/dist/io/huggingface/commit-response.mjs +14 -0
  55. package/dist/io/huggingface/index.d.mts +13 -0
  56. package/dist/io/huggingface/index.mjs +418 -0
  57. package/dist/io/huggingface/languagesMap.d.mts +186 -0
  58. package/dist/io/huggingface/languagesMap.mjs +187 -0
  59. package/dist/io/huggingface/parse.d.mts +14 -0
  60. package/dist/io/huggingface/parse.mjs +9 -0
  61. package/dist/logger.d.mts +24 -0
  62. package/dist/logger.mjs +21 -0
  63. package/dist/schemas/config.shcema.d.mts +199 -0
  64. package/dist/schemas/config.shcema.mjs +52 -0
  65. package/dist/types/index.d.mts +28 -0
  66. package/dist/types/index.mjs +1 -0
  67. package/package.json +10 -1
  68. package/.nvmrc +0 -1
  69. package/gringow.json +0 -12
  70. package/src/browser.ts +0 -4
  71. package/src/config.ts +0 -93
  72. package/src/data/check-cache.ts +0 -15
  73. package/src/data/clear-cache.ts +0 -5
  74. package/src/data/create-cache-dir.ts +0 -7
  75. package/src/data/delete-cache-item.ts +0 -20
  76. package/src/data/get-cache.ts +0 -17
  77. package/src/data/get-or-create-cache.ts +0 -21
  78. package/src/data/save-cache.ts +0 -17
  79. package/src/data/write-cache-to-disk.ts +0 -20
  80. package/src/default-config.ts +0 -27
  81. package/src/flat-template-string.test.ts +0 -109
  82. package/src/flat-template-string.ts +0 -27
  83. package/src/gringow.ts +0 -49
  84. package/src/index.ts +0 -37
  85. package/src/io/anthropic/ask.ts +0 -31
  86. package/src/io/anthropic/commit-response.ts +0 -11
  87. package/src/io/anthropic/index.ts +0 -3
  88. package/src/io/anthropic/parse.ts +0 -11
  89. package/src/io/ask-llm.ts +0 -44
  90. package/src/io/gemini/ask.ts +0 -65
  91. package/src/io/gemini/commit-response.ts +0 -6
  92. package/src/io/gemini/index.ts +0 -3
  93. package/src/io/gemini/parse.ts +0 -12
  94. package/src/io/huggingface/ask.ts +0 -82
  95. package/src/io/huggingface/commit-response.ts +0 -16
  96. package/src/io/huggingface/index.ts +0 -16
  97. package/src/io/huggingface/languagesMap.ts +0 -189
  98. package/src/io/huggingface/parse.ts +0 -10
  99. package/src/logger.ts +0 -25
  100. package/src/schemas/config.shcema.ts +0 -58
  101. package/src/types/index.ts +0 -22
  102. package/tsconfig.json +0 -29
  103. package/tsup.config.ts +0 -21
  104. package/vitest.config.ts +0 -8
@@ -1,16 +0,0 @@
1
- import type { GringowTranslation } from '@/index'
2
- import type { AskHuggingfaceResponse } from '@/io/huggingface'
3
- import type { CommitResponse } from '@/types'
4
-
5
- export function commitResponseHuggingface(response: AskHuggingfaceResponse) {
6
- const { responses, original } = response
7
- const translation = responses.reduce((acc, curr) => {
8
- acc[curr.targetLanguage] = curr.translation_text
9
- return acc
10
- }, {} as GringowTranslation)
11
-
12
- return {
13
- translation,
14
- original,
15
- } as CommitResponse
16
- }
@@ -1,16 +0,0 @@
1
- import type { TranslationSingle } from '@huggingface/transformers'
2
-
3
- export type AskHuggingfaceResponseTranslation = TranslationSingle & {
4
- targetLanguage: string
5
- }
6
-
7
- export type AskHuggingfaceResponse = {
8
- responses: AskHuggingfaceResponseTranslation[]
9
- original: string
10
- }
11
-
12
- export type AskHuggingfaceResult = string
13
-
14
- export * from './ask'
15
- export * from './commit-response'
16
- export * from './parse'
@@ -1,189 +0,0 @@
1
- export const languagesMap = {
2
- 'en-US': 'eng_Latn',
3
- 'en-GB': 'eng_Latn',
4
- 'pt-BR': 'por_Latn',
5
- 'pt-PT': 'por_Latn',
6
- 'es-ES': 'spa_Latn',
7
- 'es-MX': 'spa_Latn',
8
- 'fr-FR': 'fra_Latn',
9
- 'fr-CA': 'fra_Latn',
10
- 'de-DE': 'deu_Latn',
11
- 'it-IT': 'ita_Latn',
12
- 'nl-NL': 'nld_Latn',
13
- 'pl-PL': 'pol_Latn',
14
- 'ru-RU': 'rus_Cyrl',
15
- 'uk-UA': 'ukr_Cyrl',
16
- 'bg-BG': 'bul_Cyrl',
17
- 'hr-HR': 'hrv_Latn',
18
- 'cs-CZ': 'ces_Latn',
19
- 'sk-SK': 'slk_Latn',
20
- 'hu-HU': 'hun_Latn',
21
- 'ro-RO': 'ron_Latn',
22
- 'fi-FI': 'fin_Latn',
23
- 'sv-SE': 'swe_Latn',
24
- 'da-DK': 'dan_Latn',
25
- 'no-NO': 'nob_Latn',
26
- 'is-IS': 'isl_Latn',
27
- 'et-EE': 'est_Latn',
28
- 'lv-LV': 'lav_Latn',
29
- 'lt-LT': 'lit_Latn',
30
- 'mt-MT': 'mlt_Latn',
31
- 'ga-IE': 'gle_Latn',
32
- 'cy-GB': 'cym_Latn',
33
- 'eu-ES': 'eus_Latn',
34
- 'ca-ES': 'cat_Latn',
35
- 'gl-ES': 'glg_Latn',
36
- 'oc-FR': 'oci_Latn',
37
- 'br-FR': 'bre_Latn',
38
- 'gd-GB': 'gla_Latn',
39
- 'kw-GB': 'cor_Latn',
40
- 'fur-IT': 'fur_Latn',
41
- 'rm-CH': 'roh_Latn',
42
- 'lb-LU': 'ltz_Latn',
43
- 'fy-NL': 'fry_Latn',
44
- 'af-ZA': 'afr_Latn',
45
-
46
- 'zh-CN': 'zho_Hans',
47
- 'zh-TW': 'zho_Hant',
48
- 'zh-HK': 'zho_Hant',
49
- 'ja-JP': 'jpn_Jpan',
50
- 'ko-KR': 'kor_Hang',
51
- 'th-TH': 'tha_Thai',
52
- 'vi-VN': 'vie_Latn',
53
- 'id-ID': 'ind_Latn',
54
- 'ms-MY': 'zsm_Latn',
55
- 'tl-PH': 'tgl_Latn',
56
- 'my-MM': 'mya_Mymr',
57
- 'km-KH': 'khm_Khmr',
58
- 'lo-LA': 'lao_Laoo',
59
- 'bn-BD': 'ben_Beng',
60
- 'bn-IN': 'ben_Beng',
61
- 'hi-IN': 'hin_Deva',
62
- 'ur-PK': 'urd_Arab',
63
- 'ur-IN': 'urd_Arab',
64
- 'pa-IN': 'pan_Guru',
65
- 'gu-IN': 'guj_Gujr',
66
- 'or-IN': 'ory_Orya',
67
- 'as-IN': 'asm_Beng',
68
- 'ml-IN': 'mal_Mlym',
69
- 'ta-IN': 'tam_Tamil',
70
- 'te-IN': 'tel_Telu',
71
- 'kn-IN': 'kan_Knda',
72
- 'si-LK': 'sin_Sinh',
73
- 'ne-NP': 'nep_Deva',
74
- 'dz-BT': 'dzo_Tibt',
75
- 'bo-CN': 'bod_Tibt',
76
- 'mn-MN': 'khk_Cyrl',
77
- 'ka-GE': 'kat_Geor',
78
- 'hy-AM': 'hye_Armn',
79
- 'az-AZ': 'azj_Latn',
80
- 'tr-TR': 'tur_Latn',
81
- 'fa-IR': 'pes_Arab',
82
- 'fa-AF': 'pes_Arab',
83
- 'ps-AF': 'pbt_Arab',
84
- 'ku-TR': 'kmr_Latn',
85
- 'he-IL': 'heb_Hebr',
86
- 'ar-SA': 'arb_Arab',
87
- 'ar-EG': 'arb_Arab',
88
- 'ar-MA': 'arb_Arab',
89
- 'ar-DZ': 'arb_Arab',
90
- 'ar-TN': 'arb_Arab',
91
- 'ar-LY': 'arb_Arab',
92
- 'ar-SD': 'arb_Arab',
93
- 'ar-IQ': 'arb_Arab',
94
- 'ar-SY': 'arb_Arab',
95
- 'ar-JO': 'arb_Arab',
96
- 'ar-LB': 'arb_Arab',
97
- 'ar-KW': 'arb_Arab',
98
- 'ar-AE': 'arb_Arab',
99
- 'ar-QA': 'arb_Arab',
100
- 'ar-BH': 'arb_Arab',
101
- 'ar-OM': 'arb_Arab',
102
- 'ar-YE': 'arb_Arab',
103
- 'ar-SO': 'arb_Arab',
104
- 'ar-DJ': 'arb_Arab',
105
- 'ar-KM': 'arb_Arab',
106
- 'ar-TD': 'arb_Arab',
107
- 'ar-ER': 'arb_Arab',
108
- 'ar-IL': 'arb_Arab',
109
- 'ar-PS': 'arb_Arab',
110
- 'ar-001': 'arb_Arab',
111
-
112
- 'sw-KE': 'swh_Latn',
113
- 'sw-TZ': 'swh_Latn',
114
- 'am-ET': 'amh_Ethi',
115
- 'om-ET': 'gaz_Latn',
116
- 'so-SO': 'som_Latn',
117
- 'ha-NG': 'hau_Latn',
118
- 'yo-NG': 'yor_Latn',
119
- 'ig-NG': 'ibo_Latn',
120
- 'zu-ZA': 'zul_Latn',
121
- 'xh-ZA': 'xho_Latn',
122
- 'rw-RW': 'kin_Latn',
123
- 'lg-UG': 'lug_Latn',
124
- 'ak-GH': 'aka_Latn',
125
- 'tw-GH': 'twi_Latn',
126
- 'ee-GH': 'ewe_Latn',
127
- 'ff-SN': 'fuv_Latn',
128
- 'wo-SN': 'wol_Latn',
129
- 'sn-ZW': 'sna_Latn',
130
- 'nd-ZW': 'nde_Latn',
131
- 'ny-MW': 'nya_Latn',
132
- 'st-ZA': 'sot_Latn',
133
- 'tn-BW': 'tsn_Latn',
134
- 'ts-ZA': 'tso_Latn',
135
- 've-ZA': 'ven_Latn',
136
- 'ss-ZA': 'ssw_Latn',
137
- 'nr-ZA': 'nbl_Latn',
138
-
139
- 'qu-PE': 'quy_Latn',
140
- 'qu-BO': 'quy_Latn',
141
- 'qu-EC': 'quy_Latn',
142
- 'ay-BO': 'aym_Latn',
143
- 'gn-PY': 'grn_Latn',
144
- 'ht-HT': 'hat_Latn',
145
- 'jv-ID': 'jav_Latn',
146
- 'su-ID': 'sun_Latn',
147
- 'ceb-PH': 'ceb_Latn',
148
- 'ilo-PH': 'ilo_Latn',
149
- 'war-PH': 'war_Latn',
150
- 'bjn-ID': 'bjn_Latn',
151
- 'ban-ID': 'ban_Latn',
152
- 'mad-ID': 'mad_Latn',
153
- 'min-ID': 'min_Latn',
154
- 'ace-ID': 'ace_Latn',
155
- 'bug-ID': 'bug_Latn',
156
- 'gor-ID': 'gor_Latn',
157
- 'mak-ID': 'mak_Latn',
158
- 'mdr-ID': 'mdr_Latn',
159
- 'sas-ID': 'sas_Latn',
160
- 'shn-MM': 'shn_Mymr',
161
- 'kac-MM': 'kac_Latn',
162
- 'lzh-CN': 'lzh_Hant',
163
- 'wuu-CN': 'wuu_Hans',
164
- 'yue-CN': 'yue_Hant',
165
- 'nan-TW': 'nan_Hant',
166
- 'hak-TW': 'hak_Hant',
167
- 'cjy-CN': 'cjy_Hans',
168
- 'cmn-CN': 'cmn_Hans',
169
- 'cmn-TW': 'cmn_Hant',
170
- 'cmn-SG': 'cmn_Hans',
171
- 'cmn-HK': 'cmn_Hant',
172
- 'cmn-MO': 'cmn_Hant',
173
- 'cmn-001': 'cmn_Hans',
174
-
175
- 'haw-US': 'haw_Latn',
176
- 'mi-NZ': 'mri_Latn',
177
- 'sm-WS': 'smo_Latn',
178
- 'to-TO': 'ton_Latn',
179
- 'fj-FJ': 'fij_Latn',
180
- 'ty-PF': 'tah_Latn',
181
- 'co-FR': 'cos_Latn',
182
- 'eu-FR': 'eus_Latn',
183
-
184
- 'kk-KZ': 'kaz_Cyrl',
185
- 'ky-KG': 'kir_Cyrl',
186
- 'uz-UZ': 'uzn_Latn',
187
- 'tg-TJ': 'tgk_Cyrl',
188
- 'tk-TM': 'tuk_Latn',
189
- }
@@ -1,10 +0,0 @@
1
- import type { GringowCacheItem } from '@/index'
2
- import type { CommitResponse } from '@/types'
3
-
4
- export function parseHuggingface(unparsed: CommitResponse): GringowCacheItem {
5
- if (typeof unparsed === 'string') {
6
- throw new Error('CommitResponse should not be a string here.')
7
- }
8
-
9
- return unparsed
10
- }
package/src/logger.ts DELETED
@@ -1,25 +0,0 @@
1
- // "error", "warn", "info", "debug", "trace"
2
- const levels = {
3
- error: 0,
4
- warn: 1,
5
- info: 2,
6
- debug: 3,
7
- trace: 4,
8
- }
9
-
10
- type Level = keyof typeof levels
11
-
12
- const currentLevel: Level = 'info'
13
- const maxLevel = levels[currentLevel]
14
-
15
- const noop = () => void 0
16
-
17
- const logger = {
18
- error: maxLevel >= levels.error ? console.error : noop,
19
- warn: maxLevel >= levels.warn ? console.warn : noop,
20
- info: maxLevel >= levels.info ? console.info : noop,
21
- debug: maxLevel >= levels.debug ? console.debug : noop,
22
- trace: maxLevel >= levels.trace ? console.trace : noop,
23
- }
24
-
25
- export default logger
@@ -1,58 +0,0 @@
1
- import { z } from 'zod'
2
-
3
- export const languageSchema = z.string().regex(/^[a-z]{2,3}(-[A-Z]{2})?$/)
4
-
5
- export const llmOptionsSchema = z.enum(['gemini', 'anthropic', 'huggingface'])
6
-
7
- export const configSchema = z
8
- .object({
9
- debug: z.boolean().optional(),
10
- log: z.object({
11
- level: z.enum(['debug', 'info', 'warn', 'error', 'trace']),
12
- }),
13
- cache: z.object({
14
- dir: z.string(),
15
- file: z.string(),
16
- prefix: z.string(),
17
- write: z.boolean().optional(),
18
- }),
19
- keys: z.object({
20
- anthropicApiKey: z.string().optional(),
21
- geminiApiKey: z.string().optional(),
22
- }),
23
- sourceLanguage: languageSchema,
24
- languages: z.array(languageSchema),
25
- llm: z.object({
26
- choice: llmOptionsSchema,
27
- model: z.string().nullable(),
28
- temperature: z.number().optional(),
29
- sleep: z.number().optional(),
30
- prePrompt: z.string().optional(),
31
- postPrompt: z.string().optional(),
32
- prePromptReplace: z.string().optional(),
33
- postPromptReplace: z.string().optional(),
34
- prePromptAppend: z.string().optional(),
35
- postPromptAppend: z.string().optional(),
36
- }),
37
- globby: z
38
- .string()
39
- .regex(/^\.\/.*/)
40
- .optional(),
41
- })
42
- .refine(
43
- (data) => {
44
- if (data.llm.choice === 'gemini' && !data.keys.geminiApiKey) {
45
- return false
46
- }
47
-
48
- if (data.llm.choice === 'anthropic' && !data.keys.anthropicApiKey) {
49
- return false
50
- }
51
-
52
- return true
53
- },
54
- {
55
- message: 'The API key corresponding to the chosen LLM must be present.',
56
- path: ['keys'],
57
- }
58
- )
@@ -1,22 +0,0 @@
1
- import type { z } from 'zod'
2
- import type { GringowCacheItem, GringowTranslation } from '@/index'
3
- import type { llmOptionsSchema } from '@/schemas/config.shcema'
4
-
5
- export type CommitResponse = string | { translation: GringowTranslation; original: string }
6
-
7
- export type Asker<T> = (message: string) => Promise<T>
8
- export type Commiter<T> = (response: T) => CommitResponse
9
- export type Parser = (unparsed: CommitResponse) => GringowCacheItem
10
-
11
- export type LLMOptions = z.infer<typeof llmOptionsSchema>
12
-
13
- export type LLMChoice<T> = {
14
- ask: Asker<T>
15
- commitResponse: Commiter<T>
16
- parse: Parser
17
- }
18
-
19
- export type LLMChoices = {
20
- // biome-ignore lint/suspicious/noExplicitAny: LLMChoice can receive any type
21
- [K in LLMOptions]: LLMChoice<any>
22
- }
package/tsconfig.json DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "lib": ["esnext", "DOM"],
4
- "allowJs": false,
5
- "skipLibCheck": true,
6
- "strict": true,
7
- "esModuleInterop": true,
8
- "module": "ESNext",
9
- "target": "ESNext",
10
- "moduleResolution": "bundler",
11
- "resolveJsonModule": true,
12
- "isolatedModules": true,
13
- "downlevelIteration": true,
14
- "outDir": "./dist",
15
- "rootDir": "./src",
16
- "forceConsistentCasingInFileNames": true,
17
- "declaration": true,
18
- "paths": {
19
- "@/*": ["./src/*"]
20
- }
21
- },
22
- "include": ["src/**/*.ts"],
23
- "exclude": ["node_modules", "dist"],
24
- "tsc-alias": {
25
- "resolveFullPaths": true,
26
- "resolveFullExtension": true,
27
- "rootDir": "./src"
28
- }
29
- }
package/tsup.config.ts DELETED
@@ -1,21 +0,0 @@
1
- import { defineConfig } from 'tsup'
2
-
3
- export default defineConfig({
4
- entry: ['src/**/*.ts'],
5
- // format: ["cjs", "esm"],
6
- format: ['esm'],
7
- dts: true,
8
- splitting: false,
9
- sourcemap: false,
10
- clean: true,
11
- treeshake: 'safest',
12
- minify: false,
13
- outDir: 'dist',
14
- target: 'esnext',
15
- outExtension({ format }) {
16
- return {
17
- js: format === 'cjs' ? '.js' : '.mjs',
18
- }
19
- },
20
- onSuccess: 'tsc-alias --verbose',
21
- })
package/vitest.config.ts DELETED
@@ -1,8 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: 'node',
7
- },
8
- })