@thor123141245r/ai-translate 0.0.0 → 1.0.1
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 +161 -71
- package/README.zh-CN.md +194 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +77 -0
- package/dist/cli.js.map +1 -1
- package/dist/i18n/align.d.ts +3 -0
- package/dist/i18n/align.d.ts.map +1 -0
- package/dist/i18n/align.js +46 -0
- package/dist/i18n/align.js.map +1 -0
- package/dist/i18n/cache.d.ts +14 -0
- package/dist/i18n/cache.d.ts.map +1 -0
- package/dist/i18n/cache.js +36 -0
- package/dist/i18n/cache.js.map +1 -0
- package/dist/i18n/command.d.ts +7 -0
- package/dist/i18n/command.d.ts.map +1 -0
- package/dist/i18n/command.js +84 -0
- package/dist/i18n/command.js.map +1 -0
- package/dist/i18n/extract.d.ts +7 -0
- package/dist/i18n/extract.d.ts.map +1 -0
- package/dist/i18n/extract.js +24 -0
- package/dist/i18n/extract.js.map +1 -0
- package/dist/i18n/json-path.d.ts +7 -0
- package/dist/i18n/json-path.d.ts.map +1 -0
- package/dist/i18n/json-path.js +61 -0
- package/dist/i18n/json-path.js.map +1 -0
- package/dist/i18n/parse.d.ts +6 -0
- package/dist/i18n/parse.d.ts.map +1 -0
- package/dist/i18n/parse.js +44 -0
- package/dist/i18n/parse.js.map +1 -0
- package/dist/i18n/placeholders.d.ts +7 -0
- package/dist/i18n/placeholders.d.ts.map +1 -0
- package/dist/i18n/placeholders.js +44 -0
- package/dist/i18n/placeholders.js.map +1 -0
- package/dist/i18n/prompt.d.ts +13 -0
- package/dist/i18n/prompt.d.ts.map +1 -0
- package/dist/i18n/prompt.js +37 -0
- package/dist/i18n/prompt.js.map +1 -0
- package/dist/i18n/translate.d.ts +29 -0
- package/dist/i18n/translate.d.ts.map +1 -0
- package/dist/i18n/translate.js +199 -0
- package/dist/i18n/translate.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +6 -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 +0 -22
- package/.agentdocs/code-changes/2026-01-23/CLI/345/210/206/345/217/221-npx/345/256/236/347/216/260.md +0 -18
- 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 +0 -37
- 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 +0 -22
- 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 +0 -67
- package/.agentdocs/plans/2026-01-23/CLI/345/210/206/345/217/221-npx/346/226/271/346/241/210.md +0 -60
- 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 +0 -51
- 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 +0 -80
- package/SKILL.md +0 -103
- package/src/asyncTransform.ts +0 -31
- package/src/bin/ai-translate.ts +0 -5
- package/src/cli.ts +0 -313
- package/src/index.ts +0 -9
- package/src/logger.ts +0 -3
- package/src/model.ts +0 -139
- package/src/prompt.ts +0 -71
- package/src/split.ts +0 -111
- package/src/utils.ts +0 -15
- package/tsconfig.json +0 -19
package/src/split.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|