dsh-ai-subtitle 0.3.2 → 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/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-05b'
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ai-subtitle",
3
- "version": "0.3.2",
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/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 lines = stripFence(raw)
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 = []