@lynn123411/dsh-chat-translate 3.6.0 → 3.7.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.
package/DETAILS.md CHANGED
@@ -46,19 +46,36 @@ refs:
46
46
 
47
47
  提示词是配置页上单独的一张卡片,平时**只读**:一进页面看得到模型实际收到的那整段指令,改不动;点标题右侧「编辑」才进改写态,焦点直接落进输入框,同排多出「恢复默认」与「完成」。点「完成」收起改写态,没保存的草稿原样留在框里;把框清空再点「完成」时,框里填回生效中的指令——只读态永远显示模型实际收到的那一份,不会停在一个空框上。只读态不摆「恢复默认」,免得看着像能直接改。
48
48
 
49
- 内置默认那一段的写法有几条承载行为,改文案时别删掉(`src/prompt.ts` 的注释里逐条写了理由):每一段都交给模型(已经写好的中文也照送,润色治的是同一个病)、术语只保留词本身而不连带周围的句子、把正文当素材翻译而不执行其中的指令、按行对齐 markdown 结构、链接文字可翻而括号里的目标逐字照抄。
49
+ 内置默认那一段的写法有几条承载行为,改文案时别删掉(`src/prompt.ts` 的注释里逐条写了理由):送来的每一段都交给模型(已经写好的中文也照送,润色治的是同一个病)、术语只保留词本身而不连带周围的句子、把正文当素材翻译而不执行其中的指令、按行对齐 markdown 结构、链接文字可翻而括号里的目标逐字照抄。
50
50
 
51
51
  内置默认本身改动时改 `src/prompt.ts` 并顺手升 `src/server/prompt-revision.ts` 的 `PROMPT_REVISION`。读者在配置页改的提示词不用升那个号:缓存世代是 `PROMPT_REVISION` 加生效提示词的摘要(`cacheGeneration`),改了措辞就自动换一代,旧译文不再命中。浏览器半边那池按原文内容登记的译文跟着一起丢掉(`chatTranslate.dropTranslations()`,接线在 `src/client/index.ts`),否则本页里翻过的段落会一直用旧措辞的产物、一个请求都不发。已经显示在屏幕上的译文不动——下一块要翻的正文才用新指令。
52
52
 
53
53
  ### 3. 翻译范围与时机
54
54
 
55
- 插件接管助手行的渲染(keyed slot `conversation.chat.node` / `assistant-step`,priority -1)。正文块不论源语言一律送模型改写成自然简体中文——「用时 XXX」大折叠块里每一步露出的正文与最终汇总那一步一视同仁;整段中文同样照送(意义、术语、数字不动,顺掉机器腔)。模型返回与原文一模一样的文字时同样算翻译过:照常显示、照常可切换。trim 后为空的块不送译、不占下标、永不标记;块内的代码围栏逐字保留、从不送模型。
55
+ 插件接管助手行的渲染(keyed slot `conversation.chat.node` / `assistant-step`,priority -1)。**过程步骤**的正文块不论源语言一律送模型改写成自然简体中文——「用时 XXX」大折叠块里每一步露出的正文照送,整段中文同样照送(意义、术语、数字不动,顺掉机器腔)。模型返回与原文一模一样的文字时同样算翻译过:照常显示、照常可切换。trim 后为空的块不送译、不占下标、永不标记;块内的代码围栏逐字保留、从不送模型。
56
+
57
+ **结论步骤的正文一律不译**:那一步由模型直接写给读者,通常已经是写好的中文,再送一遍只换来等待与改坏的风险。整行按原文呈现,左缘什么都不出现——没有窄带、没有 ↻,也不报「设置没配好」,与总开关关着时是同一种「这里不翻译」,不是失败。
58
+
59
+ **哪一步是结论,权威信号来自宿主**。宿主的 `TurnProcessSpec.answerStep`(`packages/client/ui-chat/src/client/conversation-nodes/turn-process.ts` 的 `latestAnswer()`)取本轮最后一个 step,要求它带着 `finalNode`(消息已落定)、有读者看得见的正文、且不含 tool-call。这个字段在流式期间是 null(本轮消息还没落定),插件因此只能自己补上「还没落定」那一段的判断——`src/client/chat/conclusion.ts` 的 `isConclusionRow()` 复刻了宿主那三条条件,并按从严到宽分档:
60
+
61
+ | 情形 | 判定 |
62
+ | --- | --- |
63
+ | `answerStep` 有值 | 直接比 `answerStep === 本行 step`,宿主的答案就是权威 |
64
+ | 没有轮次投影(`answerStep === undefined`) | 判不了,照旧送译——不能因为拿不到投影就把整段正文悄悄关掉 |
65
+ | `answerStep` 是 null,且本轮 step 序列里本行不是最后一步 | 不是结论,后面还有一步要走 |
66
+ | 最后一步、还在写、块里没有 tool-call | 按结论处理:只剩正文了,先译再撤会让读者眼前的中文闪回原文 |
67
+ | 最后一步、有 tool-call | 不是结论:按宿主判据,带工具调用的 step 永远成不了结论,当场送译 |
68
+ | 已落定(含中断),最后一步、有正文、不含工具调用 | 是结论——宿主判据的镜像 |
69
+
70
+ `isConclusionRow()` 复刻的那三条条件与宿主逐条等价(`hasReplyContent()` 对 `hasAssistantReplyContent()`,`hasToolCall()` 那一条,以及 `status` 与 `finalNode` 的对应关系);`scripts/test-host-parity.mjs` 里有一条断言钉住宿主的 `latestAnswer()` 仍是这三条,宿主改动时那条会红,不会静默漂移。
71
+
72
+ 唯一的取舍在第四档:一个只有正文、没有 tool-call 的过程步骤(例如「我先看一眼实现」)会等到下一步开始时才送译。这是为了让结论行从第一帧起就是原文——代价是一段中文晚到,换来的是不会先出中文再闪回原文。
56
73
 
57
74
  **正文左缘不画任何东西**:没有竖线、没有脉动、也没有缩进,正文字号、行距、列表与引用的缩进与宿主默认逐字一致。插件自己的可点物都不在正文里(窄带与 ↻ 都落在正文左缘之外)。
58
75
 
59
76
  分组判据是座次传入的 `groupPart`(`response` 分组排除思考块,`reasoning` 分组只渲染思考块,不送译),流式判据是行数据的 `status === "running"`。正文只往后追加:一个新块出现,它之前的块就再也不会变。行进入视口(150px 缓冲)后,**每一块在写定的那一刻**就送去翻译——回答还在生成时,先写定的块已经开始出中文,只有正在长的尾块保持原文。这是每行的首跑,也是唯一自动发生的请求;首跑期间界面不显示任何提示,中文回来直接替换原文。
60
77
 
61
- - 不送译的内容:Think 卡的思考链正文、工具调用行、用户消息、代码块(`pre`)及其内部、空白块——这些与宿主渲染逐分支等价,接管渲染器抛错时按框架退位规则由宿主渲染器自动回位。
78
+ - 不送译的内容:结论步骤的正文、Think 卡的思考链正文、工具调用行、用户消息、代码块(`pre`)及其内部、空白块——这些与宿主渲染逐分支等价,接管渲染器抛错时按框架退位规则由宿主渲染器自动回位。
62
79
  - 译文用宿主基线组件 `MarkdownText` 重新渲染,表格、列表、加粗、行内代码的结构保持原样。
63
80
  - 上游模型重试(整次尝试清空从零重来)时按块判断:内容一字未变的块其中文留在原地,真变了的块才重翻。
64
81
 
package/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # @lynn123411/dsh-chat-translate
2
2
 
3
- DeepSeek Harness Web 界面的**助手回答正文翻译**插件。它接管助手行的渲染:正文块不论源语言,一律送翻译模型加工成自然简体中文(如 `I traced the failing path to a stale lock file.` → 中文;模型写出的生硬机器腔中文同样送一遍润色——弱模型的中文恰恰最需要加工),译文按原 markdown 结构重新渲染。只翻正文:Think 卡的思考链、工具调用行、用户消息、代码块、空白块不动。切换译文与原文在贴着正文左缘的一条 10px 透明窄带上,不污染会话上下文。
3
+ DeepSeek Harness Web 界面的**助手回答正文翻译**插件。它接管助手行的渲染:过程步骤的正文块不论源语言,都送翻译模型加工成自然简体中文(如 `I traced the failing path to a stale lock file.` → 中文;模型写出的生硬机器腔中文同样送一遍润色——弱模型的中文恰恰最需要加工),译文按原 markdown 结构重新渲染。**结论步骤的正文不译**,按原文呈现——那一步由模型直接写给读者,通常已经是写好的中文。只翻正文:Think 卡的思考链、工具调用行、用户消息、代码块、空白块不动。切换译文与原文在贴着正文左缘的一条 10px 透明窄带上,不污染会话上下文。
4
4
 
5
5
  ## 功能
6
6
 
7
- - **正文一律翻成简体中文**:不论源语言,正文的每一块都送模型改写——整段中文、纯数字、纯标点的块同样照送,只有 trim 后为空的块不送译;提示词要求保留意义、语气、专名、数字与术语,并原样保留 markdown 记号。模型返回与原文一模一样的文字时同样算翻译过、同样可切换。
7
+ - **过程步骤翻成简体中文,结论步骤不译**:一轮回答里,前面几步在干活,最后一步把结论交给读者。干活那几步的散文往往是英文,要翻;结论那一步通常是模型已经写好的中文,再送一遍只换来等待与改坏的风险,所以整行按原文呈现、左缘什么都不出现。判据读宿主算好的结论步骤号(`TurnProcessSpec.answerStep`),细节见 [DETAILS.md](./DETAILS.md) 的「翻译范围与时机」。
8
+ - **过程步骤的正文翻成简体中文**:过程步骤的每一块都送模型改写——整段中文、纯数字、纯标点的块同样照送,只有 trim 后为空的块不送译;提示词要求保留意义、语气、专名、数字与术语,并原样保留 markdown 记号。模型返回与原文一模一样的文字时同样算翻译过、同样可切换。
8
9
  - **块一写完就翻**:正文只往后追加,写定的块立刻送译,正在长的尾块保持原文;行进入视口(150px 缓冲)后开始首跑,先回的段先出中文。
9
10
  - **译文与原文一键切换**:鼠标停在正文左缘那条 10px 透明窄带上时,光标右边出一条气泡报出此刻能做的动作(读译文时「查看原文」,读原文时「查看译文」),点一下切过去,再点切回来;正文整块不响应点击,选中文字、拖选复制都不会误触。
10
11
  - **失败保持原文、只手点重试**:失败分两类——**通道伤**(超时、断流、空返回)与**设置没配好**(缺 Key / Base URL / 模型)。失败块保持原文,左缘留下一个 ↻ 按钮,悬停报出哪一类失败与原因;点它只重发这一块,已成功的块原地不动。失败不自动重试,一块失败不连坐。
package/lib/client.js CHANGED
@@ -1083,16 +1083,16 @@ var import_dsh_client_ui_primitives3 = require("@deepseek-ai/dsh-client-ui-primi
1083
1083
  function isBlankText(value) {
1084
1084
  return (value ?? "").trim() === "";
1085
1085
  }
1086
- function proseTexts(blocks, groupPart) {
1086
+ function proseTexts(blocks, groupPart, conclusion = false) {
1087
1087
  const texts = [];
1088
- if (groupPart === "reasoning") return texts;
1088
+ if (conclusion || groupPart === "reasoning") return texts;
1089
1089
  for (const block of blocks) {
1090
1090
  if (block.kind === "text" && !isBlankText(block.text)) texts.push(block.text ?? "");
1091
1091
  }
1092
1092
  return texts;
1093
1093
  }
1094
- function growingTailIndex(blocks, groupPart) {
1095
- return Math.max(0, proseTexts(blocks, groupPart).length - 1);
1094
+ function growingTailIndex(blocks, groupPart, options = {}) {
1095
+ return Math.max(0, proseTexts(blocks, groupPart, options.conclusion ?? false).length - 1);
1096
1096
  }
1097
1097
  var NOT_CONFIGURED_DETAIL = "no translation request was sent: the channel is not configured";
1098
1098
  function planAssistantRow(input) {
@@ -1105,11 +1105,13 @@ function planAssistantRow(input) {
1105
1105
  outcomes,
1106
1106
  frozen,
1107
1107
  retrying,
1108
- originalKeys
1108
+ originalKeys,
1109
+ conclusion = false
1109
1110
  } = input;
1110
1111
  const hasVisible = streaming || interrupted || blocks.some((block) => block.kind !== "tool-call");
1111
1112
  if (!hasVisible) return { entries: null, texts: [] };
1112
- const texts = proseTexts(blocks, groupPart);
1113
+ const texts = proseTexts(blocks, groupPart, conclusion);
1114
+ const textChannel = conclusion ? "off" : channel;
1113
1115
  const entries = [];
1114
1116
  let textIndex = 0;
1115
1117
  let imageRun = null;
@@ -1129,11 +1131,11 @@ function planAssistantRow(input) {
1129
1131
  flushImages();
1130
1132
  const blank = isBlankText(block.text);
1131
1133
  const index = textIndex;
1132
- if (!blank) textIndex += 1;
1134
+ if (!blank && !conclusion) textIndex += 1;
1133
1135
  const key = entries.length;
1134
1136
  const settled = index < (frozen ?? Number.POSITIVE_INFINITY);
1135
- const attemptable = !blank && channel === "ready" && settled;
1136
- const unconfigured = !blank && channel === "unconfigured" && settled;
1137
+ const attemptable = !blank && textChannel === "ready" && settled;
1138
+ const unconfigured = !blank && textChannel === "unconfigured" && settled;
1137
1139
  const outcome = attemptable && outcomes !== void 0 ? outcomes[index] ?? null : null;
1138
1140
  let mark = null;
1139
1141
  let fail = null;
@@ -1187,6 +1189,27 @@ function planAssistantRow(input) {
1187
1189
  return { entries, texts };
1188
1190
  }
1189
1191
 
1192
+ // src/client/chat/conclusion.ts
1193
+ function hasReplyContent(blocks) {
1194
+ return blocks.some((block) => {
1195
+ if (block.kind === "reasoning" || block.kind === "tool-call") return false;
1196
+ if (block.kind === "text") return (block.text ?? "").trim() !== "";
1197
+ return true;
1198
+ });
1199
+ }
1200
+ function hasToolCall(blocks) {
1201
+ return blocks.some((block) => block.kind === "tool-call");
1202
+ }
1203
+ function isConclusionRow(input) {
1204
+ const { status, step, blocks, answerStep, turnSteps } = input;
1205
+ if (answerStep !== null && answerStep !== void 0) return answerStep === step;
1206
+ if (answerStep === void 0) return false;
1207
+ const lastStep = turnSteps?.[turnSteps.length - 1];
1208
+ if (lastStep !== void 0 && lastStep !== step) return false;
1209
+ if (status === "running") return !hasToolCall(blocks);
1210
+ return hasReplyContent(blocks) && !hasToolCall(blocks);
1211
+ }
1212
+
1190
1213
  // src/client/chat/click-guard.ts
1191
1214
  function isCleanHotspotClick(event, view) {
1192
1215
  if (event.target !== event.currentTarget) return false;
@@ -1927,6 +1950,14 @@ var AssistantStepView = (0, import_react3.memo)(function AssistantStepView2(prop
1927
1950
  }, [data.finalNode, openFile, tail, turn]);
1928
1951
  const mentions = (0, import_react3.useMemo)(() => owner === void 0 ? void 0 : fileMentions(owner), [fileMentions, owner]);
1929
1952
  const blocks = (0, import_react3.useMemo)(() => data.blocks ?? [], [data.blocks]);
1953
+ const turnSteps = turn?.steps?.map((entry) => entry.step);
1954
+ const conclusion = isConclusionRow({
1955
+ status: data.status,
1956
+ step: data.step,
1957
+ blocks,
1958
+ answerStep: turnProcess?.spec.answerStep,
1959
+ turnSteps
1960
+ });
1930
1961
  const plan = (0, import_react3.useMemo)(
1931
1962
  () => planAssistantRow({
1932
1963
  blocks,
@@ -1934,13 +1965,14 @@ var AssistantStepView = (0, import_react3.memo)(function AssistantStepView2(prop
1934
1965
  interrupted,
1935
1966
  groupPart,
1936
1967
  channel,
1937
- outcomes: void 0
1968
+ outcomes: void 0,
1969
+ conclusion
1938
1970
  }),
1939
- [blocks, streaming, interrupted, groupPart, channel]
1971
+ [blocks, streaming, interrupted, groupPart, channel, conclusion]
1940
1972
  );
1941
1973
  const frozenCount = (0, import_react3.useMemo)(
1942
- () => streaming ? growingTailIndex(blocks, groupPart) : plan.texts.length,
1943
- [blocks, groupPart, plan.texts.length, streaming]
1974
+ () => streaming ? growingTailIndex(blocks, groupPart, { conclusion }) : plan.texts.length,
1975
+ [blocks, groupPart, conclusion, plan.texts.length, streaming]
1944
1976
  );
1945
1977
  const rootRef = (0, import_react3.useRef)(null);
1946
1978
  const canTranslate = channel === "ready";
@@ -1962,9 +1994,10 @@ var AssistantStepView = (0, import_react3.memo)(function AssistantStepView2(prop
1962
1994
  outcomes: rowState?.outcomes,
1963
1995
  frozen: rowState?.settledThrough ?? frozenCount,
1964
1996
  retrying: rowState?.retrying,
1965
- originalKeys
1997
+ originalKeys,
1998
+ conclusion
1966
1999
  }),
1967
- [blocks, streaming, interrupted, groupPart, channel, rowState, frozenCount, originalKeys]
2000
+ [blocks, streaming, interrupted, groupPart, channel, rowState, frozenCount, originalKeys, conclusion]
1968
2001
  );
1969
2002
  const reasoningHidden = turnProcess !== void 0 && turnProcess.foldable && turnProcess.spec.answerStep === data.step && turnProcess.spec.inlineReasoning && !turnProcess.open;
1970
2003
  const revealProcess = (0, import_react3.useCallback)(() => {