dsh-ai-subtitle 0.3.1 → 0.3.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.en.md +3 -1
- package/README.ja.md +2 -1
- package/README.ko.md +2 -1
- package/README.md +1 -0
- package/client.js +14 -1
- package/index.js +14 -1
- package/package.json +1 -1
- package/src/admission.js +57 -0
- package/src/api.js +13 -1
- package/src/llm.js +8 -2
- package/src/review.js +19 -0
package/README.en.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://www.npmjs.com/package/dsh-ai-subtitle)
|
|
8
8
|
[](https://nodejs.org/)
|
|
9
9
|
|
|
10
|
-
<!-- translated-from: README.md sha256:
|
|
10
|
+
<!-- translated-from: README.md sha256:f3562069ca01 -->
|
|
11
11
|
|
|
12
12
|
A subtitle plugin for DeepSeek Harness (DSH) that turns Japanese video into bilingual
|
|
13
13
|
Japanese/Chinese SRT files. The plugin installs every runtime component it needs
|
|
@@ -79,6 +79,8 @@ and exports the same format.
|
|
|
79
79
|
- projects default to `Documents\\DshSubtitle\\projects` and can be changed or opened from
|
|
80
80
|
the panel;
|
|
81
81
|
- hour-long videos take a while to transcribe; transcribe first, then translate in batches;
|
|
82
|
+
- the panel API accepts only same-origin requests from the DSH page; another program calling
|
|
83
|
+
it directly is refused;
|
|
82
84
|
- deleting a project offers "remove from list" or "delete the local files"; the second
|
|
83
85
|
cannot be undone.
|
|
84
86
|
|
package/README.ja.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://www.npmjs.com/package/dsh-ai-subtitle)
|
|
8
8
|
[](https://nodejs.org/)
|
|
9
9
|
|
|
10
|
-
<!-- translated-from: README.md sha256:
|
|
10
|
+
<!-- translated-from: README.md sha256:f3562069ca01 -->
|
|
11
11
|
|
|
12
12
|
DeepSeek Harness(DSH)の字幕プラグインです。日本語動画を日中バイリンガルの SRT に変換します。必要なランタイム(ffmpeg、CPython、PyTorch、transformers)は指定ディレクトリにすべて導入されるため、Python・ffmpeg・モデルを事前に用意する必要はありません。
|
|
13
13
|
|
|
@@ -54,6 +54,7 @@ DeepSeek Harness(DSH)の字幕プラグインです。日本語動画を日
|
|
|
54
54
|
- API key は保存しません(認証情報は DSH が管理);
|
|
55
55
|
- プロジェクトは既定で「ドキュメント\\DshSubtitle\\projects」。パネルから変更・オープンできます;
|
|
56
56
|
- 数時間の動画は時間がかかるため、先に文字起こしを済ませてから分割して翻訳するのがおすすめです;
|
|
57
|
+
- パネルの API は DSH ページからの同一オリジン要求のみ受け付けます。他のプログラムからの直接呼び出しは拒否されます。
|
|
57
58
|
- プロジェクト削除は「一覧から外す」と「ローカルファイルも削除」を選べます。後者は元に戻せません。
|
|
58
59
|
|
|
59
60
|
## 導入
|
package/README.ko.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://www.npmjs.com/package/dsh-ai-subtitle)
|
|
8
8
|
[](https://nodejs.org/)
|
|
9
9
|
|
|
10
|
-
<!-- translated-from: README.md sha256:
|
|
10
|
+
<!-- translated-from: README.md sha256:f3562069ca01 -->
|
|
11
11
|
|
|
12
12
|
DeepSeek Harness(DSH)용 자막 플러그인으로, 일본어 영상을 일중 이중 언어 SRT로 변환합니다. 필요한 런타임(ffmpeg, CPython, PyTorch, transformers)은 지정한 디렉터리에 모두 설치되므로 Python, ffmpeg, 모델을 미리 준비할 필요가 없습니다.
|
|
13
13
|
|
|
@@ -54,6 +54,7 @@ DeepSeek Harness(DSH)용 자막 플러그인으로, 일본어 영상을 일중
|
|
|
54
54
|
- API key를 저장하지 않습니다(자격 증명은 DSH가 관리);
|
|
55
55
|
- 프로젝트 기본 위치는 「문서\\DshSubtitle\\projects」이며 패널에서 변경하거나 열 수 있습니다;
|
|
56
56
|
- 몇 시간짜리 영상은 전사에 시간이 걸리므로 먼저 전사한 뒤 여러 배치로 나눠 번역하는 편이 좋습니다;
|
|
57
|
+
- 패널 API는 DSH 페이지의 동일 출처 요청만 허용합니다. 다른 프로그램이 직접 호출하면 거부됩니다.
|
|
57
58
|
- 프로젝트 삭제 시 「목록에서 제거」와 「로컬 파일까지 삭제」를 고를 수 있으며 후자는 되돌릴 수 없습니다.
|
|
58
59
|
|
|
59
60
|
## 설치
|
package/README.md
CHANGED
package/client.js
CHANGED
|
@@ -10,7 +10,7 @@ window.__ModuleLoader__.load({
|
|
|
10
10
|
const PANEL_ID = 'subtitle-studio-panel'
|
|
11
11
|
const API = '/dsh-ai-subtitle/api'
|
|
12
12
|
// Bump whenever the bundle needs to be distinguishable in the running page.
|
|
13
|
-
const BUILD = 'ui-2026-12-
|
|
13
|
+
const BUILD = 'ui-2026-12-05c'
|
|
14
14
|
function trace(message) {
|
|
15
15
|
try {
|
|
16
16
|
const payload = JSON.stringify({ msg: String(message).slice(0, 300) })
|
|
@@ -448,6 +448,7 @@ window.__ModuleLoader__.load({
|
|
|
448
448
|
const [translateBusy, setTranslateBusy] = useState(false)
|
|
449
449
|
const [translateJobId, setTranslateJobId] = useState('')
|
|
450
450
|
const [translateNotice, setTranslateNotice] = useState('')
|
|
451
|
+
const [translateError, setTranslateError] = useState('')
|
|
451
452
|
const [hints, setHints] = useState({ tags: [], note: '' })
|
|
452
453
|
const [tagDraft, setTagDraft] = useState('')
|
|
453
454
|
const [contextDialog, setContextDialog] = useState(false)
|
|
@@ -829,6 +830,7 @@ window.__ModuleLoader__.load({
|
|
|
829
830
|
if (!detail) return
|
|
830
831
|
setTranslateBusy(true)
|
|
831
832
|
setTranslateNotice('翻译中…')
|
|
833
|
+
setTranslateError('')
|
|
832
834
|
try {
|
|
833
835
|
const payload = { dir: detail.dir, mode: proofread ? 'proofread' : 'translate' }
|
|
834
836
|
if (all) payload.all = true
|
|
@@ -840,6 +842,7 @@ window.__ModuleLoader__.load({
|
|
|
840
842
|
const result = await callApi('/review/translate', { method: 'POST', body: JSON.stringify(payload) })
|
|
841
843
|
if (result.error) {
|
|
842
844
|
setNotice('翻译失败:' + result.error)
|
|
845
|
+
setTranslateError(result.error)
|
|
843
846
|
return
|
|
844
847
|
}
|
|
845
848
|
if (result.jobId) {
|
|
@@ -860,6 +863,7 @@ window.__ModuleLoader__.load({
|
|
|
860
863
|
}
|
|
861
864
|
if (job.status === 'failed') {
|
|
862
865
|
setNotice('翻译失败:' + (job.error || '未知错误'))
|
|
866
|
+
setTranslateError(job.error || '未知错误')
|
|
863
867
|
break
|
|
864
868
|
}
|
|
865
869
|
if (job.status === 'cancelled') {
|
|
@@ -877,6 +881,7 @@ window.__ModuleLoader__.load({
|
|
|
877
881
|
setNotice('已翻译批次 ' + result.batch + '(' + result.route + '),写入 ' + result.cues + ' 条' + (result.jpChanged ? ',校正日文 ' + result.jpChanged + ' 条' : ''))
|
|
878
882
|
setFeedbackDraft({})
|
|
879
883
|
setBatchNote('')
|
|
884
|
+
setTranslateError('')
|
|
880
885
|
await openProject(detail)
|
|
881
886
|
} finally {
|
|
882
887
|
setTranslateBusy(false)
|
|
@@ -1021,6 +1026,7 @@ window.__ModuleLoader__.load({
|
|
|
1021
1026
|
setReview(null)
|
|
1022
1027
|
setFeedbackDraft({})
|
|
1023
1028
|
setBatchNote('')
|
|
1029
|
+
setTranslateError('')
|
|
1024
1030
|
loadRoute()
|
|
1025
1031
|
loadHints(next.dir)
|
|
1026
1032
|
loadReview(next.dir)
|
|
@@ -1611,6 +1617,13 @@ window.__ModuleLoader__.load({
|
|
|
1611
1617
|
'同时校正日文识别',
|
|
1612
1618
|
),
|
|
1613
1619
|
),
|
|
1620
|
+
translateError
|
|
1621
|
+
? h(
|
|
1622
|
+
'div',
|
|
1623
|
+
{ style: { marginTop: 8, padding: 8, borderRadius: 6, border: '1px solid ' + tokens.danger, color: tokens.danger, fontSize: 11, lineHeight: 1.6, userSelect: 'text' } },
|
|
1624
|
+
'翻译失败:' + translateError,
|
|
1625
|
+
)
|
|
1626
|
+
: null,
|
|
1614
1627
|
reviewBatch && reviewBatch.cues && reviewBatch.cues.length > 0
|
|
1615
1628
|
? h(
|
|
1616
1629
|
'div',
|
package/index.js
CHANGED
|
@@ -66,10 +66,23 @@ export function apply(ctx, config = {}) {
|
|
|
66
66
|
return llmCtx
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
// The panel routes must not be reachable from another origin, so the API
|
|
70
|
+
// defers to the Host's connection admission when the composition provides it.
|
|
71
|
+
let connectionCtx = null
|
|
72
|
+
ctx.inject(['connection'], (scoped) => {
|
|
73
|
+
scoped.effect(() => {
|
|
74
|
+
connectionCtx = scoped
|
|
75
|
+
return () => {
|
|
76
|
+
connectionCtx = null
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
const connectionService = () => (connectionCtx ? connectionCtx.connection : undefined)
|
|
81
|
+
|
|
69
82
|
// The sidebar panel talks to the Host over these local JSON routes. The
|
|
70
83
|
// plugin still works without a web server (headless profiles just skip it).
|
|
71
84
|
ctx.inject(['webServer'], (scoped) => {
|
|
72
|
-
scoped.effect(() => registerApi(scoped, runtimeFor, modelContext))
|
|
85
|
+
scoped.effect(() => registerApi(scoped, runtimeFor, modelContext, connectionService))
|
|
73
86
|
})
|
|
74
87
|
|
|
75
88
|
ctx.tools.register(defineTool({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ai-subtitle",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Japanese video to bilingual JP/zh subtitles inside DeepSeek Harness: a self-installing ffmpeg, Python and Whisper runtime, cue editing and SRT export.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
package/src/admission.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admission guard for the panel's HTTP routes.
|
|
3
|
+
*
|
|
4
|
+
* The routes live on the same origin as the DSH web GUI, so the browser sends
|
|
5
|
+
* the host's auth cookie with every panel request. `ctx.connection` owns that
|
|
6
|
+
* check (Host/Origin trust plus browser authentication); when a host exposes
|
|
7
|
+
* it, the plugin defers to it. Older or headless compositions without the
|
|
8
|
+
* service fall back to the request-header checks below, which stop a page on
|
|
9
|
+
* another origin from driving the routes through the browser.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Fallback rejection for hosts without `connection.requestRejection`.
|
|
14
|
+
* @param headers - request headers (node:http lower-cased record or Headers).
|
|
15
|
+
* @returns 403 for a cross-site or foreign-origin request, undefined otherwise.
|
|
16
|
+
*/
|
|
17
|
+
export function fallbackRejection(headers) {
|
|
18
|
+
const read = (name) => {
|
|
19
|
+
if (!headers) return undefined
|
|
20
|
+
if (typeof headers.get === 'function') return headers.get(name)
|
|
21
|
+
const value = headers[name]
|
|
22
|
+
return Array.isArray(value) ? value[0] : value
|
|
23
|
+
}
|
|
24
|
+
const site = String(read('sec-fetch-site') || '').toLowerCase()
|
|
25
|
+
if (site === 'cross-site') return 403
|
|
26
|
+
const origin = read('origin')
|
|
27
|
+
if (origin) {
|
|
28
|
+
const host = read('host')
|
|
29
|
+
if (!host) return 403
|
|
30
|
+
try {
|
|
31
|
+
if (new URL(origin).host !== host) return 403
|
|
32
|
+
} catch {
|
|
33
|
+
return 403
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return undefined
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Decide whether one request may reach the panel API.
|
|
41
|
+
* @param connection - `ctx.connection`, when the composition provides it.
|
|
42
|
+
* @param request - node:http request carrying headers.
|
|
43
|
+
* @returns rejection status (401/403) or null when the request may proceed.
|
|
44
|
+
*/
|
|
45
|
+
export function rejectRequest(connection, request) {
|
|
46
|
+
if (connection && typeof connection.requestRejection === 'function') {
|
|
47
|
+
try {
|
|
48
|
+
const status = connection.requestRejection(request)
|
|
49
|
+
return status === undefined ? null : status
|
|
50
|
+
} catch {
|
|
51
|
+
// A failing trust check must never fail open.
|
|
52
|
+
return 403
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const status = fallbackRejection(request && request.headers ? request.headers : undefined)
|
|
56
|
+
return status === undefined ? null : status
|
|
57
|
+
}
|
package/src/api.js
CHANGED
|
@@ -7,6 +7,7 @@ import { DEFAULT_MODEL } from './installer.js'
|
|
|
7
7
|
import { buildRows, cueStats, deriveCueTimes, describeCoverageErrors, toSrt, validateCues } from './cues.js'
|
|
8
8
|
import { forgetProject, loadRegistry, patchProject } from './registry.js'
|
|
9
9
|
import { defaultProjectsDir } from './paths.js'
|
|
10
|
+
import { rejectRequest } from './admission.js'
|
|
10
11
|
import { recentMedia, rememberMedia } from './recent.js'
|
|
11
12
|
import { chooseSources, sourcesFromState } from './sources.js'
|
|
12
13
|
import { applyBatch, batchState, loadProject, nextBatch, planBatches, renderBatch, reviewStatus } from './review.js'
|
|
@@ -357,8 +358,19 @@ function projectDetail(dir, limit = 300) {
|
|
|
357
358
|
* Local JSON API for the studio panel. Registered as a handler route because the
|
|
358
359
|
* panel needs POST for install, transcribe, import, save and export.
|
|
359
360
|
*/
|
|
360
|
-
export function registerApi(ctx, runtimeFor, modelContext) {
|
|
361
|
+
export function registerApi(ctx, runtimeFor, modelContext, connectionFor) {
|
|
361
362
|
const handler = async (request, response) => {
|
|
363
|
+
// Same-origin panel requests carry the host's auth cookie; anything else is
|
|
364
|
+
// refused before it can reach a route that changes files.
|
|
365
|
+
const connection = typeof connectionFor === 'function'
|
|
366
|
+
? connectionFor()
|
|
367
|
+
: typeof ctx.get === 'function' ? ctx.get('connection') : undefined
|
|
368
|
+
const rejection = rejectRequest(connection, request)
|
|
369
|
+
if (rejection !== null) {
|
|
370
|
+
response.writeHead(rejection, { 'content-type': 'text/plain; charset=utf-8' })
|
|
371
|
+
response.end(rejection === 401 ? 'unauthorized' : 'forbidden')
|
|
372
|
+
return
|
|
373
|
+
}
|
|
362
374
|
const url = new URL(request.url || '/', 'http://local')
|
|
363
375
|
const path = url.pathname.slice(PREFIX.length) || '/'
|
|
364
376
|
const runtime = runtimeFor(url.searchParams.get('installDir') || undefined)
|
package/src/llm.js
CHANGED
|
@@ -3,7 +3,7 @@ import { join } from 'node:path'
|
|
|
3
3
|
import { feedbackForBatch } from './feedback.js'
|
|
4
4
|
import { loadHints } from './hints.js'
|
|
5
5
|
import { glossaryPath, loadGlossary, termsInText } from './glossary.js'
|
|
6
|
-
import { applyBatch, loadProject, nextBatch, planBatches, renderBatch } from './review.js'
|
|
6
|
+
import { applyBatch, loadProject, nextBatch, planBatches, renderBatch, salvageLines } from './review.js'
|
|
7
7
|
|
|
8
8
|
const SYSTEM_PROMPT = [
|
|
9
9
|
'你是专业的日语视频字幕翻译,把日文逐条翻译成简体中文。',
|
|
@@ -155,7 +155,13 @@ export async function translateBatch(ctx, projectDir, options = {}) {
|
|
|
155
155
|
const route = options.route || (await resolveRoute(ctx, { ...options, projectDir }))
|
|
156
156
|
const prompt = buildPrompt(projectDir, batch, fragments, cues, glossary, feedback, undefined, options.mode)
|
|
157
157
|
const raw = await completeText(ctx, route, { prompt, signal: options.signal })
|
|
158
|
-
const
|
|
158
|
+
const text = stripFence(raw)
|
|
159
|
+
const lines = salvageLines(text)
|
|
160
|
+
if (!lines) {
|
|
161
|
+
throw new Error(
|
|
162
|
+
`模型没有按格式返回(${route.provider}/${route.model})。原始回复的前 200 字:${text.slice(0, 200)}`,
|
|
163
|
+
)
|
|
164
|
+
}
|
|
159
165
|
const applied = applyBatch(projectDir, { batch: batch.id, lines })
|
|
160
166
|
saveRoute(projectDir, route)
|
|
161
167
|
return { ...applied, route: `${route.provider}/${route.model}`, feedback: feedback.length }
|
package/src/review.js
CHANGED
|
@@ -97,6 +97,25 @@ export function renderBatch(batch, fragments, cues, glossary, hints) {
|
|
|
97
97
|
return lines.join('\n')
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Keep only the lines that look like batch rows, so a model that wraps its answer
|
|
102
|
+
* in prose or a numbered list still lands. Returns '' when nothing matches.
|
|
103
|
+
* @param text - raw model output.
|
|
104
|
+
* @returns the salvaged row text, one row per line.
|
|
105
|
+
*/
|
|
106
|
+
export function salvageLines(text) {
|
|
107
|
+
const kept = []
|
|
108
|
+
for (const raw of String(text || '').split(/\r?\n/)) {
|
|
109
|
+
let line = raw.trim()
|
|
110
|
+
if (!line) continue
|
|
111
|
+
line = line.replace(/^[-*•]\s+/, '').replace(/^\d+[.)]\s+(?=\d)/, '')
|
|
112
|
+
line = line.replace(/^(\d+(?:\s*-\s*\d+)?)\s*\|\s*/, '$1|')
|
|
113
|
+
line = line.replace(/\s*\|\s*/g, '|')
|
|
114
|
+
if (BATCH_LINE.test(line)) kept.push(line)
|
|
115
|
+
}
|
|
116
|
+
return kept.join('\n')
|
|
117
|
+
}
|
|
118
|
+
|
|
100
119
|
export function parseLines(text) {
|
|
101
120
|
const rows = []
|
|
102
121
|
const errors = []
|