@thor123141245r/ai-translate 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/.agentdocs/code-changes/2026-01-22/AI/347/277/273/350/257/221/345/231/250TS/345/256/236/347/216/260-/345/256/236/347/216/260.md +22 -0
  2. package/.agentdocs/code-changes/2026-01-23/CLI/345/210/206/345/217/221-npx/345/256/236/347/216/260.md +18 -0
  3. package/.agentdocs/code-changes/2026-01-23/sora-watermask-remover-/345/233/275/351/231/205/345/214/226/347/277/273/350/257/221-/345/256/236/347/216/260.md +37 -0
  4. package/.agentdocs/code-changes/2026-01-23//351/205/215/347/275/256/350/257/273/345/217/226-/347/216/257/345/242/203/345/217/230/351/207/217/344/274/230/345/205/210-/345/256/236/347/216/260.md +22 -0
  5. package/.agentdocs/plans/2026-01-22/AI/347/277/273/350/257/221/345/231/250TS/345/256/236/347/216/260-/344/274/230/345/214/226/346/226/271/346/241/210.md +67 -0
  6. package/.agentdocs/plans/2026-01-23/CLI/345/210/206/345/217/221-npx/346/226/271/346/241/210.md +60 -0
  7. package/.agentdocs/plans/2026-01-23/sora-watermask-remover-/345/233/275/351/231/205/345/214/226/347/277/273/350/257/221-/344/274/230/345/214/226/346/226/271/346/241/210.md +51 -0
  8. package/.agentdocs/plans/2026-01-23//351/205/215/347/275/256/350/257/273/345/217/226-/347/216/257/345/242/203/345/217/230/351/207/217/344/274/230/345/205/210-/344/274/230/345/214/226/346/226/271/346/241/210.md +80 -0
  9. package/README.md +120 -0
  10. package/SKILL.md +103 -0
  11. package/dist/asyncTransform.d.ts +7 -0
  12. package/dist/asyncTransform.d.ts.map +1 -0
  13. package/dist/asyncTransform.js +23 -0
  14. package/dist/asyncTransform.js.map +1 -0
  15. package/dist/bin/ai-translate.d.ts +3 -0
  16. package/dist/bin/ai-translate.d.ts.map +1 -0
  17. package/dist/bin/ai-translate.js +4 -0
  18. package/dist/bin/ai-translate.js.map +1 -0
  19. package/dist/cli.d.ts +7 -0
  20. package/dist/cli.d.ts.map +1 -0
  21. package/dist/cli.js +259 -0
  22. package/dist/cli.js.map +1 -0
  23. package/dist/index.d.ts +6 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +4 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/logger.d.ts +3 -0
  28. package/dist/logger.d.ts.map +1 -0
  29. package/dist/logger.js +3 -0
  30. package/dist/logger.js.map +1 -0
  31. package/dist/model.d.ts +29 -0
  32. package/dist/model.d.ts.map +1 -0
  33. package/dist/model.js +103 -0
  34. package/dist/model.js.map +1 -0
  35. package/dist/prompt.d.ts +12 -0
  36. package/dist/prompt.d.ts.map +1 -0
  37. package/dist/prompt.js +51 -0
  38. package/dist/prompt.js.map +1 -0
  39. package/dist/split.d.ts +27 -0
  40. package/dist/split.d.ts.map +1 -0
  41. package/dist/split.js +87 -0
  42. package/dist/split.js.map +1 -0
  43. package/dist/utils.d.ts +7 -0
  44. package/dist/utils.d.ts.map +1 -0
  45. package/dist/utils.js +14 -0
  46. package/dist/utils.js.map +1 -0
  47. package/package.json +42 -0
  48. package/src/asyncTransform.ts +31 -0
  49. package/src/bin/ai-translate.ts +5 -0
  50. package/src/cli.ts +313 -0
  51. package/src/index.ts +9 -0
  52. package/src/logger.ts +3 -0
  53. package/src/model.ts +139 -0
  54. package/src/prompt.ts +71 -0
  55. package/src/split.ts +111 -0
  56. package/src/utils.ts +15 -0
  57. package/tsconfig.json +19 -0
package/src/split.ts ADDED
@@ -0,0 +1,111 @@
1
+ import { RecursiveCharacterTextSplitter } from '@langchain/textsplitters'
2
+ import type {
3
+ RecursiveCharacterTextSplitterParams,
4
+ SupportedTextSplitterLanguage
5
+ } from '@langchain/textsplitters'
6
+ import { AsyncTransform } from './asyncTransform.js'
7
+
8
+ export type TextSplitterFormat = { format?: SupportedTextSplitterLanguage }
9
+ export type TextSplitterParams = Partial<RecursiveCharacterTextSplitterParams> &
10
+ TextSplitterFormat
11
+ export type Separator = string | RegExp
12
+ export type TextSplitterLike = { splitText(text: string): Promise<string[]> }
13
+
14
+ const extensionsByFormat: Record<string, string[]> = {
15
+ cpp: ['.h', '.c', '.cpp'],
16
+ go: ['.go'],
17
+ java: ['.java'],
18
+ js: ['.js', '.cjs', '.mjs', '.jsx', '.ts', '.tsx'],
19
+ php: ['.php', '.inc'],
20
+ proto: ['.proto'],
21
+ python: ['.py'],
22
+ rst: ['.rst'],
23
+ ruby: ['.rb', '.gem'],
24
+ rust: ['.rs'],
25
+ scala: ['.scala', '.sc'],
26
+ swift: ['.swift'],
27
+ markdown: ['.md', '.markdown', '.mkdn'],
28
+ latex: ['.tex', '.latex', '.ltx'],
29
+ html: ['.html', '.htm', '.xhtml', '.shtml', '.asp', '.aspx', '.jsp']
30
+ }
31
+
32
+ let formatByExtension: Record<string, SupportedTextSplitterLanguage> | undefined
33
+
34
+ export const getFormatByExtension = (
35
+ extname: string
36
+ ): SupportedTextSplitterLanguage | undefined => {
37
+ if (!formatByExtension) {
38
+ formatByExtension = {}
39
+ for (const [key, values] of Object.entries(extensionsByFormat)) {
40
+ for (const ext of values) {
41
+ formatByExtension[ext] = key as SupportedTextSplitterLanguage
42
+ }
43
+ }
44
+ }
45
+ return formatByExtension[extname]
46
+ }
47
+
48
+ export const recursiveChunkTextSplitter = (options?: TextSplitterParams) => {
49
+ const { format = 'markdown', ...rest } = options || {}
50
+ const separators = extensionsByFormat[format]
51
+ ? RecursiveCharacterTextSplitter.getSeparatorsForLanguage(format)
52
+ : ['\n\n', '\n', '.', '']
53
+ return new RecursiveChunkTextSplitter({
54
+ chunkSize: 1000,
55
+ chunkOverlap: 0,
56
+ separators,
57
+ ...rest
58
+ })
59
+ }
60
+
61
+ // @ts-expect-error override joinDocs to preserve whitespace; upstream marks it private
62
+ export class RecursiveChunkTextSplitter extends RecursiveCharacterTextSplitter {
63
+ protected override joinDocs(docs: string[], separator: string): string | null {
64
+ const text = docs.join(separator)
65
+ return text === '' ? null : text
66
+ }
67
+ }
68
+
69
+ export class TextSplitterStream extends AsyncTransform {
70
+ private readonly _textSplitter: TextSplitterLike
71
+ private _documents: string[]
72
+ private _buffer: string
73
+
74
+ constructor(options?: { textSplitter?: TextSplitterLike }) {
75
+ const { textSplitter } = options || {}
76
+ super()
77
+ this._textSplitter = textSplitter || recursiveChunkTextSplitter()
78
+ this._documents = []
79
+ this._buffer = ''
80
+ }
81
+
82
+ protected async _asyncTransform(
83
+ chunk: Buffer | object,
84
+ encoding: BufferEncoding | 'buffer'
85
+ ) {
86
+ const text = AsyncTransform.toString(chunk, encoding)
87
+ this._buffer += text
88
+
89
+ const documents = await this._textSplitter.splitText(this._buffer)
90
+ this._buffer = documents.pop() ?? ''
91
+ this._documents = this._documents.concat(documents)
92
+
93
+ while (this._documents.length) {
94
+ const document = this._documents.shift()
95
+ if (document === undefined) break
96
+ const wait = !this.push(document)
97
+ if (wait) {
98
+ return true
99
+ }
100
+ }
101
+ return false
102
+ }
103
+
104
+ _flush(done: (error?: Error | null) => void) {
105
+ for (const document of this._documents) {
106
+ this.push(document)
107
+ }
108
+ this.push(this._buffer)
109
+ done()
110
+ }
111
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,15 @@
1
+ export const isWhiteSpace = (text = '') => text.trim() === ''
2
+
3
+ export const whiteSpace = (text = '') => {
4
+ const head = /^\s{0,200}/.exec(text)?.[0] || ''
5
+ let tail = ''
6
+ if (head.length !== text.length) {
7
+ tail = /\s{0,200}$/.exec(text)?.[0] || ''
8
+ }
9
+ return { head, tail }
10
+ }
11
+
12
+ export const preserveWhiteSpace = (inp: string, out: string) => {
13
+ const { head, tail } = whiteSpace(inp)
14
+ return head + out.trim() + tail
15
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "rootDir": "src",
7
+ "outDir": "dist",
8
+ "declaration": true,
9
+ "declarationMap": true,
10
+ "sourceMap": true,
11
+ "esModuleInterop": true,
12
+ "resolveJsonModule": false,
13
+ "strict": true,
14
+ "skipLibCheck": true,
15
+ "forceConsistentCasingInFileNames": true
16
+ },
17
+ "include": ["src/**/*.ts"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }