@lynn123411/dsh-chat-translate 3.5.5 → 3.5.9

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/DETAILS.md CHANGED
@@ -76,7 +76,7 @@ refs:
76
76
 
77
77
  每片段过**形状修复**(`repairShape`):按段落块对齐,块内结构行(记号类别、表格竖线数、链接个数、缩进代码缩进)逐一对齐并把行首前缀修回原文同款(标题层级、列表符号、序号、引用深度、列表缩进的漂移就此消失),散文行自由重排(软换行渲染无感、只查整块链接总数不丢),空行布局一律取原文。修不齐的片段自动重掷一次;仍不齐则照收模型的译文(链接数不等时不回填,其余原样)。
78
78
 
79
- 同时最多一个在途请求,超时由 `aiTimeoutMs` 控制。客户端只保留一个按行登记、按**原文内容**查结果的翻译池(行以会话锚点为键,LRU 200 行;同一段原文在别处出现直接复用,不再打通道);持久缓存只有磁盘池 `~/.dsh/dsh-chat-translate/cache.json`(1000 条、7 天 LRU),文档形态是 `{ rev, entries }`,其中 `rev` 登记写入它的提示词修订号——修订号(`src/server/prompt-revision.ts` 的 `PROMPT_REVISION`,单点登记)与实际加载的提示词不符时整池作废重来,换提示词不会让旧译文串代。
79
+ 同时最多一个在途请求,超时由 `aiTimeoutMs` 控制。客户端只保留一个按行登记、按**原文内容**查结果的翻译池(行以会话锚点为键,LRU 200 行;同一段原文在别处出现直接复用,不再打通道);持久缓存只有磁盘池 `~/.dsh/dsh-chat-translate/cache.json`(1000 条 LRU),文档形态是 `{ rev, entries }`,其中 `rev` 登记写入它的提示词修订号——修订号(`src/server/prompt-revision.ts` 的 `PROMPT_REVISION`,单点登记)与实际加载的提示词不符时整池作废重来,换提示词不会让旧译文串代。作废只由修订号触发,同一修订号下命中即复用。
80
80
 
81
81
  ### 6. 通道行为
82
82
 
package/README.md CHANGED
@@ -22,7 +22,7 @@ DeepSeek Harness Web 界面的**助手回答正文翻译**插件。它接管助
22
22
  - **上游重试按块作废**:唯一让已写定的块作废的是上游模型自己重试(整次尝试清空从零重来);那时按块判断,内容一字未变的块其中文留在原地,真变了的块才重翻。
23
23
  - **单通道:OpenAI 兼容协议**:对接任意 OpenAI 兼容的 `chat/completions` 服务(OpenAI、DeepSeek、通义、Ollama、本地 vLLM 等)。Key / Base URL / 模型三者齐备才翻译,缺任何一项保持原文并如实报「设置没配好」,不做降级兜底。API Key 经 DSH 凭据服务读写 `~/.dsh/.credentials.yaml` 的 `TRANSLATE_API_KEY`。
24
24
  - **串行与超时**:同时最多一个在途请求,单次超时 `aiTimeoutMs`(默认 600000 毫秒,范围 500–900000);每行首跑与每次手点都等到真实结果。
25
- - **缓存按提示词修订号整体作废**:磁盘池 `~/.dsh/dsh-chat-translate/cache.json`(7 天 TTL、1000 条 LRU)在文档里登记 `rev`,换提示词语义后旧译文不会串代。
25
+ - **缓存按提示词修订号整体作废**:磁盘池 `~/.dsh/dsh-chat-translate/cache.json`(1000 条 LRU)在文档里登记 `rev`,换提示词语义时整池作废,同一修订号下命中即复用。
26
26
  - **跟随宿主显示设置**:Think 行的折叠摘要预览跟随「工作细节」模式(读 `ui-chat` 配置的 `transcriptView`,含旧取值映射),设置缺席时按 standard。
27
27
  - **DSH 原生配置接入**:配置就是本插件在 profile 里的插件配置——配置页经 `ctx.configForms` 读写 `dsh-chat-translate` 条目的 `config`,用户层落在当前 profile 的 patch;无任何自研配置文件,译文从不写回会话上下文。
28
28
  - **改完点保存才生效**:Base URL、模型、超时与 API Key 都是草稿——打字期间一个字都不写盘,点一次「保存」才作为一批提交上去;提交成功后自动探一次通道,把结果报在页面上(探不通不改保存结果)。空着保存等于清除该项,超时草稿不合法时保存被拦住。唯一即时生效的是总开关。
package/lib/client.js CHANGED
@@ -33,7 +33,6 @@ var index_exports = {};
33
33
  __export(index_exports, {
34
34
  AssistantStepView: () => AssistantStepView,
35
35
  ComposerTranslateToggle: () => ComposerTranslateToggle,
36
- POLICY_BY_MODE: () => POLICY_BY_MODE,
37
36
  apply: () => apply,
38
37
  chatPresentation: () => chatPresentation,
39
38
  chatTranslate: () => chatTranslate,
@@ -43,6 +42,7 @@ __export(index_exports, {
43
42
  inject: () => inject,
44
43
  name: () => name,
45
44
  planAssistantRow: () => planAssistantRow,
45
+ policyForMode: () => policyForMode,
46
46
  settingsStore: () => settingsStore,
47
47
  setupComposerToggle: () => setupComposerToggle,
48
48
  setupSettingsUi: () => setupSettingsUi
@@ -81,12 +81,7 @@ function describeError(err) {
81
81
 
82
82
  // src/client/translate/api.ts
83
83
  async function requestTranslateReply(blocks) {
84
- const fallback = () => blocks.map((block) => ({
85
- original: block,
86
- translated: block,
87
- ok: false,
88
- cached: false
89
- }));
84
+ const fallback = () => blocks.map((block) => ({ translated: block, ok: false }));
90
85
  if (!Array.isArray(blocks) || blocks.length === 0) return [];
91
86
  try {
92
87
  const res = await fetch("/api/dsh-chat-translate/translate-reply", {
@@ -162,7 +157,6 @@ var SettingsStore = class {
162
157
  credentials = null;
163
158
  unsubscribeForm = null;
164
159
  keyConfigured = false;
165
- probeFn = null;
166
160
  /**
167
161
  * Bind the DSH services. Called once from the settings UI setup; re-binding
168
162
  * (e.g. after a reconnect) detaches the previous subscription first.
@@ -180,10 +174,6 @@ var SettingsStore = class {
180
174
  }
181
175
  void this.refreshKeyStatus();
182
176
  }
183
- /** Inject the probe the settings page's save runs (the translate route). */
184
- useProbe(fn) {
185
- this.probeFn = fn;
186
- }
187
177
  getState() {
188
178
  return this.state;
189
179
  }
@@ -324,7 +314,7 @@ var SettingsStore = class {
324
314
  } else if (typeof timeout === "number" && timeout !== this.state.committed.aiTimeoutMs) {
325
315
  ops.push({ op: "set", path: ["aiTimeoutMs"], value: timeout });
326
316
  }
327
- this.state = { ...this.state, saving: true, saveFailed: false, message: void 0, probe: void 0 };
317
+ this.state = { ...this.state, saving: true, saveFailed: false, probe: void 0 };
328
318
  this.notify();
329
319
  let landed = true;
330
320
  if (ops.length > 0 && form) {
@@ -346,10 +336,10 @@ var SettingsStore = class {
346
336
  probe: { running: true }
347
337
  };
348
338
  this.notify();
349
- const probe = this.probeFn ? await this.probeFn() : null;
339
+ const probe = await testServerChannel("openai");
350
340
  this.state = {
351
341
  ...this.state,
352
- probe: probe === null ? void 0 : { running: false, ok: probe.ok, message: probe.error }
342
+ probe: { running: false, ok: probe.ok, message: probe.error }
353
343
  };
354
344
  this.deriveDrafts();
355
345
  }
@@ -365,10 +355,6 @@ var SettingsStore = class {
365
355
  } catch {
366
356
  }
367
357
  }
368
- /** Probe the translation channel; the settings page's test button. */
369
- async testChannel(channel) {
370
- return testServerChannel(channel);
371
- }
372
358
  /**
373
359
  * Write (or clear) the API key through the credentials Remote API.
374
360
  *
@@ -399,7 +385,6 @@ var SettingsStore = class {
399
385
  }
400
386
  this.form = null;
401
387
  this.credentials = null;
402
- this.probeFn = null;
403
388
  this.listeners.clear();
404
389
  }
405
390
  notify() {
@@ -838,7 +823,6 @@ function setupSettingsUi(ctx) {
838
823
  const remoteCredentials = ctx.remote?.credentials ?? null;
839
824
  try {
840
825
  settingsStore.attach(configForms.get(SETTINGS_NAMESPACE), remoteCredentials);
841
- settingsStore.useProbe(() => testServerChannel("openai"));
842
826
  } catch (err) {
843
827
  console.warn("[dsh-chat-translate] Failed to bind the configuration form:", err);
844
828
  }
@@ -907,7 +891,7 @@ function setupComposerToggle(ctx) {
907
891
  {
908
892
  name: "conversation.composer.dock",
909
893
  id: "dsh-chat-translate-toggle",
910
- // -2 排在 dsh-a6api 胶囊(-1)的左侧,整行最左;官方统计胶囊是 0。
894
+ // -2 是整行最左;官方统计胶囊是 0。
911
895
  order: -2,
912
896
  locale: NS
913
897
  },
@@ -1004,8 +988,7 @@ function planAssistantRow(input) {
1004
988
  showingOriginal: outcome !== null && outcome.ok && (originalKeys?.has(key) ?? false),
1005
989
  fail,
1006
990
  failKind,
1007
- retryBusy,
1008
- frozen: settled
991
+ retryBusy
1009
992
  });
1010
993
  break;
1011
994
  }
@@ -1220,13 +1203,6 @@ var ChatTranslateStore = class {
1220
1203
  fetch;
1221
1204
  /** 已送达的译文,按原文内容寻址:跨行、跨代复用同一段文本的结果。 */
1222
1205
  translated = /* @__PURE__ */ new Map();
1223
- /** 每行写定到哪个下标为止;null(缺席)= 还没有登记过。 */
1224
- settled = /* @__PURE__ */ new Map();
1225
- /**
1226
- * 每行在途的那一轮请求,登记的是**这一轮认领的那份文本数组**。登记换代时旧
1227
- * 一轮的写入按它丢弃:`live.texts` 与它不再同一个数组就说明行已经换代。
1228
- */
1229
- active = /* @__PURE__ */ new Map();
1230
1206
  /**
1231
1207
  * 每行**在飞的块**:下标 → 那一轮请求认领的原文。流式期间新代接手它们的结果位
1232
1208
  * 而不重发,等结果回来按当时登记的原文落账(文本没变才算同一块)。
@@ -1253,10 +1229,6 @@ var ChatTranslateStore = class {
1253
1229
  this.rows.set(rowKey, state);
1254
1230
  return state;
1255
1231
  }
1256
- /** 按原文内容查已送达的译文;null = 还没有结果。 */
1257
- lookup(text) {
1258
- return this.translated.get(cacheKey(text)) ?? null;
1259
- }
1260
1232
  /**
1261
1233
  * 确保该行按当前文本被翻译。
1262
1234
  * @param rowKey - 行键(会话内锚点)。
@@ -1269,7 +1241,7 @@ var ChatTranslateStore = class {
1269
1241
  const frozen = clampFrozen(options.frozen ?? next.length, next.length);
1270
1242
  const retries = normalizeRetries(options.retries);
1271
1243
  const current = this.rows.get(rowKey);
1272
- const settledThrough = this.settled.get(rowKey) ?? 0;
1244
+ const settledThrough = current?.settledThrough ?? 0;
1273
1245
  let seed = null;
1274
1246
  let previousFrozen = 0;
1275
1247
  const sameGeneration = current !== void 0 && sameTexts(current.texts, next);
@@ -1294,14 +1266,12 @@ var ChatTranslateStore = class {
1294
1266
  status: work || inflight !== void 0 && inflight.texts.size > 0 ? "pending" : "settled",
1295
1267
  texts: next,
1296
1268
  outcomes: plan.outcomes,
1297
- settledThrough: frozen,
1269
+ settledThrough: settleThrough(settledThrough, frozen),
1298
1270
  retrying: work ? plan.retrying : []
1299
1271
  });
1300
- this.settled.set(rowKey, Math.max(settledThrough, frozen));
1301
1272
  this.prune();
1302
1273
  this.bump();
1303
1274
  if (!work) return false;
1304
- this.active.set(rowKey, { texts: next });
1305
1275
  void this.run(rowKey, next, frozen, plan.indexes, plan.sending);
1306
1276
  return true;
1307
1277
  }
@@ -1412,12 +1382,11 @@ var ChatTranslateStore = class {
1412
1382
  const retrying = finish ? [] : indexes.filter((index) => inflight.texts.has(index));
1413
1383
  const done = finish && inflight.texts.size === 0;
1414
1384
  if (done) this.pending.delete(rowKey);
1415
- if (done) this.active.delete(rowKey);
1416
1385
  this.rows.set(rowKey, {
1417
1386
  status: done ? "settled" : "pending",
1418
1387
  texts: live.texts,
1419
1388
  outcomes,
1420
- settledThrough: Math.max(live.settledThrough, frozen),
1389
+ settledThrough: settleThrough(live.settledThrough, frozen),
1421
1390
  retrying
1422
1391
  });
1423
1392
  this.bump();
@@ -1427,7 +1396,6 @@ var ChatTranslateStore = class {
1427
1396
  const oldest = this.rows.keys().next().value;
1428
1397
  if (oldest === void 0) break;
1429
1398
  this.rows.delete(oldest);
1430
- this.settled.delete(oldest);
1431
1399
  }
1432
1400
  }
1433
1401
  bump() {
@@ -1443,6 +1411,9 @@ var ChatTranslateStore = class {
1443
1411
  function cacheKey(text) {
1444
1412
  return text.trim().toLowerCase();
1445
1413
  }
1414
+ function settleThrough(current, frozen) {
1415
+ return Math.max(current, frozen);
1416
+ }
1446
1417
  function clampFrozen(frozen, length) {
1447
1418
  if (!Number.isFinite(frozen) || frozen < 0) return 0;
1448
1419
  return Math.min(Math.floor(frozen), length);
@@ -1571,7 +1542,7 @@ var ReasoningRow = (0, import_react3.memo)(function ReasoningRow2({
1571
1542
  const summaryText = running ? latestCompletedParagraphFirstLine(text) : firstLine(text);
1572
1543
  const summary = (0, import_react3.useMemo)(() => summaryText.replaceAll("**", ""), [summaryText]);
1573
1544
  const preview = usePresentation(
1574
- (policy2) => !expanded && summary !== "" && (running || policy2.settledReasoningPreview)
1545
+ (policy) => !expanded && summary !== "" && (running || policy.settledReasoningPreview)
1575
1546
  );
1576
1547
  const collapsedContent = (0, import_react3.useMemo)(
1577
1548
  () => React.createElement(
@@ -1911,27 +1882,22 @@ function ProcessReasoning(props) {
1911
1882
  }
1912
1883
 
1913
1884
  // src/client/chat/presentation.ts
1914
- function policy(mode, foldCompletedTurns, stepGrouping, liveProcessDetail, settledReasoningPreview) {
1915
- return Object.freeze({ mode, foldCompletedTurns, stepGrouping, liveProcessDetail, settledReasoningPreview });
1916
- }
1917
- var POLICY_BY_MODE = Object.freeze({
1918
- compact: policy("compact", true, "collapsed", false, false),
1919
- standard: policy("standard", true, "collapsed", true, true),
1920
- detailed: policy("detailed", true, "history", true, true),
1921
- verbose: policy("verbose", false, "none", false, true),
1922
- normal: policy("standard", true, "collapsed", true, true),
1923
- expanded: policy("detailed", true, "history", true, true)
1924
- });
1885
+ var NO_PREVIEW_MODE = "compact";
1925
1886
  var DEFAULT_MODE = "standard";
1887
+ var WITH_PREVIEW = Object.freeze({ settledReasoningPreview: true });
1888
+ var WITHOUT_PREVIEW = Object.freeze({ settledReasoningPreview: false });
1889
+ function policyForMode(mode) {
1890
+ return mode === NO_PREVIEW_MODE ? WITHOUT_PREVIEW : WITH_PREVIEW;
1891
+ }
1926
1892
  var ChatPresentation = class {
1927
- policy = POLICY_BY_MODE[DEFAULT_MODE];
1893
+ policy = policyForMode(DEFAULT_MODE);
1928
1894
  listeners = /* @__PURE__ */ new Set();
1929
1895
  form = null;
1930
1896
  unsubscribe = null;
1931
1897
  attach(form) {
1932
1898
  this.detach();
1933
1899
  if (!form) {
1934
- this.policy = POLICY_BY_MODE[DEFAULT_MODE];
1900
+ this.policy = policyForMode(DEFAULT_MODE);
1935
1901
  return;
1936
1902
  }
1937
1903
  this.form = form;
@@ -1961,7 +1927,7 @@ var ChatPresentation = class {
1961
1927
  value = void 0;
1962
1928
  }
1963
1929
  const raw = typeof value?.transcriptView === "string" ? value.transcriptView : "";
1964
- const next = POLICY_BY_MODE[raw] ?? POLICY_BY_MODE[DEFAULT_MODE];
1930
+ const next = policyForMode(raw);
1965
1931
  if (next !== this.policy) {
1966
1932
  this.policy = next;
1967
1933
  for (const listener of [...this.listeners]) {