@lynn123411/dsh-chat-translate 3.3.1 → 3.4.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/README.md +15 -6
- package/docs//351/205/215/347/275/256.md +5 -5
- package/lib/client.js +118 -106
- package/lib/client.js.map +3 -3
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/types/client/chat/assistant-step.d.ts +7 -7
- package/lib/types/client/chat/click-guard.d.ts +7 -7
- package/lib/types/client/chat/row-plan.d.ts +24 -19
- package/lib/types/client/chat/styles.d.ts +31 -47
- package/lib/types/client/chat/translate-store.d.ts +9 -6
- package/lib/types/client/locales.d.ts +13 -8
- package/lib/types/server/dispatcher.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
# @lynn123411/dsh-chat-translate
|
|
2
2
|
|
|
3
|
-
DeepSeek Harness Web 界面的**助手回答正文翻译**插件。它接管助手行的渲染:正文块不论源语言,一律送翻译模型加工成自然简体中文(如 `I traced the failing path to a stale lock file.` → 中文;模型写出的生硬机器腔中文同样送一遍润色——弱模型的中文恰恰最需要加工),译文按原 markdown 结构重新渲染。只翻正文:Think
|
|
3
|
+
DeepSeek Harness Web 界面的**助手回答正文翻译**插件。它接管助手行的渲染:正文块不论源语言,一律送翻译模型加工成自然简体中文(如 `I traced the failing path to a stale lock file.` → 中文;模型写出的生硬机器腔中文同样送一遍润色——弱模型的中文恰恰最需要加工),译文按原 markdown 结构重新渲染。只翻正文:Think 卡的思考链、工具调用行、用户消息、代码块、空白块不动。正文的排版与宿主原生完全一致,左缘不画任何标记。切换译文/原文在**贴着正文左缘的那条 6px 透明窄带**上(鼠标移上去变手型,点一下切双语,再点切回来),翻译失败时那一段保持原文、左缘只留一个小 ↻(悬停报通道细节,点它整行重译,等待期间原地转圈);正文整块不响应点击——选中文字、拖选复制都不会误触。不污染会话上下文。开关有两个入口:输入框下方那一行的「译」胶囊与本插件配置页的总开关,同一个状态两处同步。配置详见 [docs/配置.md](./docs/配置.md)。
|
|
4
4
|
|
|
5
5
|
## 特性
|
|
6
6
|
|
|
7
7
|
- **接管助手行渲染**:经 keyed slot `conversation.chat.node`(key `assistant-step`,priority -1)替换宿主的助手行渲染器。正文块从数据层拿**原始 markdown**(`AssistantBlock.text`),译文同样以 markdown 交给宿主公开的基线组件 `MarkdownText`(micromark + GFM + KaTeX)重渲染——表格、列表、加粗、行内代码、公式的结构由官方渲染器保证,插件不自拼 markup。接管渲染器抛错时按框架退位规则退出该 cell,宿主原渲染器自动回位。
|
|
8
|
-
- **一律送译,不判源语言**:正文的每一块都进模型,包括整段中文、纯数字、纯标点的块;只有 trim
|
|
8
|
+
- **一律送译,不判源语言**:正文的每一块都进模型,包括整段中文、纯数字、纯标点的块;只有 trim 后为空的块不送译、永不标记(它没送过模型,重试也永远不会成,标记只会留下消不掉的东西)。提示词要求模型把每一段都改写成自然、地道的简体中文——意义、语气、专名、数字与术语不动,不增不删;同时要求 markdown 记号原样保留。模型判断某段已经最好而返回一模一样的文字时,同样算翻译过、同样可切换(标记传达的是「这段过了模型」)。
|
|
9
9
|
- **除正文外与宿主逐分支等价**:Think 折叠行(含工作细节策略下的摘要预览、Turn-process 折叠隐藏与页内搜索揭示)、连续图片组交回宿主渲染、工具调用行由宿主独立渲染、未知内容块落 JSON 展示、中断前缀行尾带「已停止」——这些 chrome 文案复用宿主 `chat` 词典,两侧逐字一致。
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
10
|
+
- **正文排版原生,左缘不画任何东西**:正文没有竖线、没有缩进——文字位置、列表与引用的缩进与宿主默认逐字一致。插件自己的两个可点物都落在正文左缘**之外**:成功块是一条 6px 宽的透明窄带(不占正文一个像素),失败块是一个 ↻ 按钮。窄带看不见,鼠标移上去变手型;它没有焦点框,键盘可以 Tab 到它但没有可见标记。可翻译与不可翻译时排版完全相同。
|
|
11
|
+
- **切换译文/原文**:有译文的块,左缘那条窄带点一下切原文、再点一下切回译文。切回原文后界面上不会有任何提示说「这里其实有一份译文」——那段仍然能再切回来,只是标记不变(标记只说「这段过了模型」)。
|
|
12
|
+
- **落定才翻、进视口才翻**:回答流式期间整行按原文渲染;`data-streaming` 落定且行进入视口(150px 缓冲)后,整行正文按估算 token 预算切批、逐批顺序请求——先回的段先出中文,按阅读顺序逐段呈现。历史会话因此只在真的被读到时才花请求。这是每行的首跑,也是唯一自动发生的请求。首跑期间界面不显示任何提示,中文回来直接替换原文。
|
|
13
|
+
- **失败只有一种:通道伤**:块级失败不进缓存、保持原文,左缘留下一个 ↻ 按钮(`dsh-ct-retry`,一直看得见,不靠悬停显形),它是失败段**唯一**的点击目标——失败段不放窄带,一段落只对应一个动作。鼠标停在 ↻ 上出气泡报出通道细节(超时、断流、空返回),读屏也读得到。点它整行重译:已成功的块保持显示不打扰,失败的块原地转圈(同一个按钮元素,不重挂载,键盘焦点不掉),转圈期间不能重复点。译文的结构漂移不再是失败理由(见下条)。通道失败不自动重试:一行首跑一次,落定即终态,救活只由 ↻ 发起。失败仍在控制台留一条警告。
|
|
13
14
|
- **按行幂等的翻译池**:客户端按会话锚点键登记整行结果,同文本重复渲染不重发请求;行内容换代则整行重译,迟到的旧代结果作废。
|
|
14
|
-
- **结构重装配,形状问题只修不拒**:宿主先把块按 markdown 结构切段——代码围栏与纯空白段**逐字保留、永不送模型**——散文段再按输入上限切片(单段超限按空行、单行、句末切开)、相邻片段打包成一个请求(输入上限 4096 估算 token、输出上限 8192 token)。回来的译文过**形状修复**(`repairShape`):按段落块对齐,块内结构行(记号类别、表格竖线数、链接个数、缩进代码缩进)逐一对齐并把行首前缀修回原文同款(`##`→`###`、`-`→`*`、序号、引用深度、列表缩进的漂移就此消失),散文行自由重排(软换行渲染无感),空行布局一律取原文,`[文字](URL)` 的 URL
|
|
15
|
+
- **结构重装配,形状问题只修不拒**:宿主先把块按 markdown 结构切段——代码围栏与纯空白段**逐字保留、永不送模型**——散文段再按输入上限切片(单段超限按空行、单行、句末切开)、相邻片段打包成一个请求(输入上限 4096 估算 token、输出上限 8192 token)。回来的译文过**形状修复**(`repairShape`):按段落块对齐,块内结构行(记号类别、表格竖线数、链接个数、缩进代码缩进)逐一对齐并把行首前缀修回原文同款(`##`→`###`、`-`→`*`、序号、引用深度、列表缩进的漂移就此消失),散文行自由重排(软换行渲染无感),空行布局一律取原文,`[文字](URL)` 的 URL 按出现序逐字拼回。修不齐的片段自动重掷一次;仍不齐就照收模型的译文——原文一键可回,可读的译文优先于失败标记。反引号、行内代码内容一律不拦:是样式不是骨架。
|
|
15
16
|
- **单通道:AI 翻译(OpenAI 兼容协议)**:对接任意 OpenAI 兼容的 `chat/completions` 服务(OpenAI、DeepSeek、通义、Ollama、本地 vLLM 等)。Key / Base URL / 模型三者齐备才翻译,缺任何一项保持原文,不做降级兜底。API Key 经 DSH 凭据服务读写 `~/.dsh/.credentials.yaml` 的 `TRANSLATE_API_KEY`;Base URL 与模型在本插件的配置页配置。
|
|
16
17
|
- **串行与超时**:同时最多一个在途请求,单次超时 `aiTimeoutMs`(默认 600000 毫秒,范围 500–900000)——每行首跑与每次手点都等到真实结果,嫌等就把超时调小。磁盘缓存池 `~/.dsh/dsh-chat-translate/cache.json`(7 天 TTL、1000 条 LRU)**按提示词修订号整体作废**:文档里登记 `rev`,换提示词语义后旧译文不会串代。
|
|
17
18
|
- **跟随宿主显示设置**:Think 行的折叠摘要预览跟随「工作细节」模式(读 `ui-chat` 配置的 `transcriptView`,含 legacy 取值映射);设置缺席时按 standard。
|
|
18
19
|
- **DSH 原生配置接入**:配置就是本插件在 profile 里的插件配置——配置页经 `ctx.configForms` 读写条目 `dsh-chat-translate` 的 `config`,用户层落在当前 profile 的 patch;无任何自研配置文件,译文从不写回会话上下文。
|
|
19
20
|
- **配置页挂在宿主「插件」页**:配置卡片注册进 `plugins.bundle.config`(key 为包名 `@lynn123411/dsh-chat-translate`),路径是「插件」→本插件详情页 —— 配置直接铺在描述之下、行列表之上。页面由宿主画标题、图标与面包屑,卡片提供总开关、API Key、Base URL、模型、单次请求超时与「测试 AI 通道」;设置页里不再有任何本插件的入口。做法与约束见仓库 `docs/rules/plugin-config-page.md`。
|
|
20
21
|
|
|
22
|
+
## 校验
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
cd plugins/dsh-chat-translate && pnpm check
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`check` 串起类型检查、构建、七份测试与产物门禁(`lib/` 不被索引跟踪)。测试覆盖:行渲染计划与宿主 `AssistantMarkdown` 的分支等价、翻译呈现单点(成功/失败两种标记、失败原因与补跑在途)、翻译池(同代幂等、换代重发、逐批落定、手动补跑、LRU)、配置面策略跟随,以及真 react + jsdom 的渲染自检——窄带切换、拖选与点正文不误触、失败段 ↻ 是唯一可点物、补跑在途原地转圈且不重挂载(键盘焦点不掉)、服务端败因进 ↻ 自己的读屏标签。服务端半边另有结构重装配、缓存与通道契约的回归。
|
|
29
|
+
|
|
21
30
|
## 安装
|
|
22
31
|
|
|
23
32
|
```bash
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
|
|
26
26
|
目标语言固定为简体中文,没有配置项。
|
|
27
27
|
|
|
28
|
-
3. **翻译范围与时机**:插件接管助手行的渲染(keyed slot `conversation.chat.node` / `assistant-step`,priority -1)。正文块不论源语言一律送模型改写成自然简体中文——「用时 XXX」大折叠块里每一步露出的正文与最终汇总那一步一视同仁;整段中文同样照送(意义、术语、数字不动,顺掉机器腔)。模型返回与原文一模一样的文字时同样算翻译过:照常显示、照常可切换。trim
|
|
28
|
+
3. **翻译范围与时机**:插件接管助手行的渲染(keyed slot `conversation.chat.node` / `assistant-step`,priority -1)。正文块不论源语言一律送模型改写成自然简体中文——「用时 XXX」大折叠块里每一步露出的正文与最终汇总那一步一视同仁;整段中文同样照送(意义、术语、数字不动,顺掉机器腔)。模型返回与原文一模一样的文字时同样算翻译过:照常显示、照常可切换。trim 后为空的块不送译、不占下标、永不标记;块内的代码围栏逐字保留、从不送模型。**正文左缘不画任何东西**:没有竖线、没有脉动、也没有缩进,正文字号、行距、列表与引用的缩进与宿主默认逐字一致。插件自己的两个可点物都落在正文左缘**之外**,详见下条。分组判据是座次传入的 `groupPart`(`response` 分组排除思考块,`reasoning` 分组只渲染思考块,不送译),流式判据是行数据的 `status === "running"`。流式期间整行按原文渲染;落定且该行进入视口(150px 缓冲)后,整行正文按估算 token 预算切批、逐批顺序请求,先回的段先出中文——这是每行的首跑,也是唯一自动发生的请求。首跑期间界面不显示任何提示,中文回来直接替换原文。
|
|
29
29
|
|
|
30
30
|
- 不送译的内容:Think 卡的思考链正文、工具调用行、用户消息、代码块(`pre`)及其内部、空白块——这些与宿主渲染逐分支等价,接管渲染器抛错时按框架退位规则由宿主渲染器自动回位。
|
|
31
31
|
- 译文用宿主基线组件 `MarkdownText` 重新渲染,表格、列表、加粗、行内代码的结构保持原样。
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
32
|
+
- 失败只有一种(通道伤)、悬停报细节,重试归手点:块内任一片段通道失败(超时、断流、空返回)就整块按原文渲染、左缘留下一个 ↻ 按钮(`.dsh-ct-retry`);鼠标停在这个按钮上出 Tooltip,报服务端原样带回的技术一句(如展开后的 fetch 报错、`channel timed out after 20000ms`),读屏也读同一句。**译文的结构漂移不是失败理由**——它由形状修复消化(见下条),修不齐的自动重掷一次、仍不齐则照收,永不因格式留下失败标记。控制台各留一条通道失败警告。失败结果不进缓存,一批失败只败在这一批;通道失败**不自动重试**——滚动、重挂载都不会重发已落定的行,救活由点击发起:点失败块的 ↻ = 整行手动补跑,无限次不设额度,已成功的结果整体保留(宿主磁盘缓存让它们秒回、不花模型调用)。补跑在途时 ↻ **原地转圈**(同一个按钮元素,只换属性,不重挂载——键盘焦点不掉),且不能重复点。
|
|
33
|
+
- 左缘之外有两个可点物,各自是所在段落的唯一入口:**成功块**是一条**宽 6px 的透明窄带**(`.dsh-ct-hotspot`,`left:-6px;width:6px`,随块高铺满),整条落在正文左缘之外、不占正文一个像素、不参与排版;点它时读译文切原文、读原文切译文(键盘聚焦后 Enter/Space 同样),块与块互不影响。**失败块**是一个真的 ↻ 按钮(`.dsh-ct-retry`,官方 `IconRefreshOutlineRegular`,`left:-18px` 浮在正文左侧的空隙里),失败段**不放窄带**——一段落只对应一个动作,两种点击目标不叠在同一小片地方。正文整块不响应点击——选中文字、拖选复制都不会误触;在窄带上按下、往右拖进正文再松手算选字,不触发切换。悬停不改任何视觉(鼠标移到窄带或 ↻ 上才变手型),键盘聚焦不给任何可见标记(明说的取舍:键盘能操作,但界面不加标记)。关闭总开关即全部回到原文,两个可点物一并消失。
|
|
34
|
+
- **排版**:插件不给正文加任何 padding、margin 或 border——可翻译与不可翻译时排版完全相同。两个可点物都在正文左缘之外,宿主正文列左侧恒定有 32px(侧栏嵌入 24px)内边距,因此它们落在空白里、不压任何宿主元素。已知的小重叠:两位以上序号的有序列表(`10.`、`100.`)的序号会往左伸出正文左缘,与那条 6px 窄带重叠——点那几像素会切换译文而不是选中文字(刻意接受,优先保证排版原生)。
|
|
35
35
|
|
|
36
|
-
4. **请求方式**:按行请求——落定的助手行把它全部正文块一次送出。宿主先按 markdown 结构切段:代码围栏与纯空白段逐字保留、永不送模型;散文段超过输入上限(4096 估算 token)时按空行、单行、句末依次切开,相邻片段打包成一个请求(输出上限 8192 token),译回后按原结构拼回——片段头尾的空行由拆下的部分补回,`[文字](URL)` 的 URL 按出现序逐字拼回。每片段过**形状修复**(`repairShape
|
|
36
|
+
4. **请求方式**:按行请求——落定的助手行把它全部正文块一次送出。宿主先按 markdown 结构切段:代码围栏与纯空白段逐字保留、永不送模型;散文段超过输入上限(4096 估算 token)时按空行、单行、句末依次切开,相邻片段打包成一个请求(输出上限 8192 token),译回后按原结构拼回——片段头尾的空行由拆下的部分补回,`[文字](URL)` 的 URL 按出现序逐字拼回。每片段过**形状修复**(`repairShape`):按段落块对齐,块内结构行(记号类别、表格竖线数、链接个数、缩进代码缩进)逐一对齐并把行首前缀修回原文同款(标题层级、列表符号、序号、引用深度、列表缩进的漂移就此消失),散文行自由重排(软换行渲染无感、只查整块链接总数不丢),空行布局一律取原文。修不齐的片段自动重掷一次;仍不齐则照收模型的译文(链接数不等时不回填,其余原样)——形状问题永不否决内容,失败标记只留给通道伤。同时最多一个在途请求,超时由 `aiTimeoutMs` 控制(默认 600000 毫秒,范围 500–900000)——每行首跑与每次手点都等到真实结果,嫌等就调小超时。客户端只保留一个按行的内存翻译池(会话锚点为键,LRU 200 行);持久缓存只有宿主的磁盘池 `~/.dsh/dsh-chat-translate/cache.json`(1000 条、7 天 LRU),文档形态是 `{ rev, entries }`,其中 `rev` 登记写入它的提示词修订号——修订号(`src/server/prompt-revision.ts` 的 `PROMPT_REVISION`,单点登记)与实际加载的提示词不符时整池作废重来,换提示词不会让旧译文串代。
|
|
37
37
|
|
|
38
38
|
5. **通道行为**:只有一条通道——Key / Base URL / 模型三者齐备才翻译,缺任何一项都保持原文,不做降级兜底。
|
package/lib/client.js
CHANGED
|
@@ -416,7 +416,7 @@ var NS = "settings.chatTranslate";
|
|
|
416
416
|
var zh = {
|
|
417
417
|
masterTitle: "\u7FFB\u8BD1\u603B\u5F00\u5173",
|
|
418
418
|
enableTranslation: "\u542F\u7528\u7FFB\u8BD1",
|
|
419
|
-
masterDesc: "\u81EA\u52A8\u628A\u52A9\u624B\u56DE\u7B54\u6B63\u6587\u7FFB\u6210\u4E2D\u6587\uFF08\u5982 {example}\uFF09\uFF1A\u6298\u53E0\u5757\u91CC\u7684\u8FC7\u7A0B\u6B63\u6587\u4E0E\u6700\u7EC8\u6C47\u603B\u4E00\u89C6\u540C\u4EC1\uFF0C\u6574\u6BB5\u4E2D\u6587\u7684\u5757\u4E5F\u7167\u9001\uFF0C\u7531\u6A21\u578B\u4E00\u5E76\u6539\u5199\u6210\u81EA\u7136\u4E2D\u6587\u3001\u987A\u6389\u673A\u5668\u8154\u3002Think \u5361\u4E0E\u5DE5\u5177\u8C03\u7528\u884C\u4E0D\u7FFB\uFF0C\u4EE3\u7801\u5757\u539F\u6837\u4FDD\u7559\u3002\u6B63\u6587\
|
|
419
|
+
masterDesc: "\u81EA\u52A8\u628A\u52A9\u624B\u56DE\u7B54\u6B63\u6587\u7FFB\u6210\u4E2D\u6587\uFF08\u5982 {example}\uFF09\uFF1A\u6298\u53E0\u5757\u91CC\u7684\u8FC7\u7A0B\u6B63\u6587\u4E0E\u6700\u7EC8\u6C47\u603B\u4E00\u89C6\u540C\u4EC1\uFF0C\u6574\u6BB5\u4E2D\u6587\u7684\u5757\u4E5F\u7167\u9001\uFF0C\u7531\u6A21\u578B\u4E00\u5E76\u6539\u5199\u6210\u81EA\u7136\u4E2D\u6587\u3001\u987A\u6389\u673A\u5668\u8154\u3002Think \u5361\u4E0E\u5DE5\u5177\u8C03\u7528\u884C\u4E0D\u7FFB\uFF0C\u4EE3\u7801\u5757\u539F\u6837\u4FDD\u7559\u3002\u6B63\u6587\u7684\u6392\u7248\u4E0E\u539F\u751F\u5B8C\u5168\u4E00\u81F4\uFF0C\u5DE6\u7F18\u4E0D\u753B\u4EFB\u4F55\u6807\u8BB0\u3002\u5207\u6362\u4E0D\u5728\u6B63\u6587\u4E0A\uFF1A\u8D34\u7740\u6B63\u6587\u5DE6\u7F18\u7684\u4E00\u6761\u900F\u660E\u7A84\u5E26\u624D\u662F\u64CD\u4F5C\u533A\uFF0C\u9F20\u6807\u79FB\u5230\u5B83\u4E0A\u9762\u53D8\u624B\u578B\uFF0C\u70B9\u4E00\u4E0B\u5728\u8BD1\u6587\u4E0E\u539F\u6587\u95F4\u5207\u6362\uFF0C\u518D\u70B9\u4E00\u4E0B\u5207\u56DE\u6765\u2014\u2014\u6B63\u6587\u6574\u5757\u4E0D\u54CD\u5E94\u70B9\u51FB\uFF0C\u9009\u5B57\u3001\u62D6\u9009\u590D\u5236\u90FD\u4E0D\u4F1A\u8BEF\u89E6\uFF1B\u6A21\u578B\u8BA4\u4E3A\u539F\u6837\u6700\u597D\u3001\u8FD4\u56DE\u4E00\u6A21\u4E00\u6837\u7684\u6587\u5B57\u65F6\u540C\u6837\u7B97\u7FFB\u8BD1\u8FC7\u3001\u540C\u6837\u53EF\u5207\u3002\u7FFB\u8BD1\u5931\u8D25\u65F6\u8FD9\u4E00\u6BB5\u4FDD\u6301\u539F\u6587\uFF0C\u5DE6\u7F18\u53EA\u7559\u4E0B\u4E00\u4E2A\u5C0F \u21BB\uFF1A\u9F20\u6807\u505C\u4E0A\u53BB\u51FA\u6C14\u6CE1\u62A5\u51FA\u901A\u9053\u7EC6\u8282\uFF08\u8D85\u65F6\u3001\u65AD\u6D41\u6216\u7A7A\u8FD4\u56DE\uFF09\uFF0C\u70B9\u5B83\u6574\u884C\u91CD\u65B0\u7FFB\u8BD1\uFF0C\u7B49\u5F85\u671F\u95F4\u5B83\u539F\u5730\u8F6C\u5708\u4E14\u4E0D\u80FD\u91CD\u590D\u70B9\uFF1B\u5DF2\u7ECF\u6210\u529F\u7684\u6BB5\u843D\u4FDD\u6301\u663E\u793A\u4E0D\u6253\u6270\u3002\u901A\u9053\u5931\u8D25\u4E0D\u81EA\u52A8\u91CD\u8BD5\uFF0C\u6062\u590D\u540E\u7531\u4F60\u70B9 \u21BB \u6551\u6D3B\u3002\u8BD1\u6587\u6309\u539F markdown \u683C\u5F0F\u91CD\u65B0\u6E32\u67D3\uFF0C\u8868\u683C\u3001\u5217\u8868\u3001\u52A0\u7C97\u4E0E\u884C\u5185\u4EE3\u7801\u4FDD\u6301\u7ED3\u6784\u3002\u56DE\u7B54\u8FD8\u5728\u6D41\u5F0F\u8F93\u51FA\u65F6\u4E0D\u7FFB\uFF0C\u843D\u5B9A\u540E\u6309\u9605\u8BFB\u987A\u5E8F\u9010\u6BB5\u51FA\u4E2D\u6587\u3002\u53EA\u4F5C\u7528\u4E8E\u5F53\u524D\u67E5\u770B\u7684\u4F1A\u8BDD\uFF0C\u8BD1\u6587\u4E0D\u5199\u56DE\u4F1A\u8BDD\u4E0A\u4E0B\u6587\u3002\u8F93\u5165\u6846\u4E0B\u65B9\u90A3\u4E00\u884C\u6709\u540C\u6B3E\u5F00\u5173\uFF0C\u4E24\u5904\u72B6\u6001\u540C\u6B65\u3002",
|
|
420
420
|
aiTitle: "AI \u7FFB\u8BD1\uFF08OpenAI \u517C\u5BB9\u534F\u8BAE\uFF09",
|
|
421
421
|
aiRule: "\u53EA\u6709\u8FD9\u4E00\u6761\u901A\u9053\uFF1AKey / Base URL / \u6A21\u578B\u9F50\u5907\u624D\u4F1A\u7FFB\u8BD1\uFF0C\u7F3A\u4EFB\u4F55\u4E00\u9879\u90FD\u4FDD\u6301\u539F\u6587\u3002",
|
|
422
422
|
badgeConfigured: "\u5DF2\u914D\u7F6E",
|
|
@@ -441,20 +441,20 @@ var zh = {
|
|
|
441
441
|
testOk: "\u8FDE\u63A5\u6B63\u5E38\uFF0C\u5EF6\u8FDF {latency}ms",
|
|
442
442
|
testFail: "\u5931\u8D25\uFF1A{error}",
|
|
443
443
|
behaviorTitle: "\u7FFB\u8BD1\u8303\u56F4",
|
|
444
|
-
behaviorRule: "\u52A9\u624B\u56DE\u7B54\u6B63\u6587\u4E00\u5F8B\u7FFB\u8BD1\uFF0C\u5305\u62EC\u6700\u7EC8\u6C47\u603B\u4E0E\u6574\u6BB5\u4E2D\u6587\u7684\u5757\uFF1A\u4E2D\u6587\u5757\u540C\u6837\u4EA4\u7ED9\u6A21\u578B\u6539\u5199\u6210\u81EA\u7136\u4E2D\u6587\uFF0C\u610F\u4E49\u3001\u672F\u8BED\u4E0E\u6570\u5B57\u4E0D\u53D8\uFF1B\u7A7A\u767D\u5757\u4E0D\u9001\u8BD1\u3001\u4E0D\
|
|
444
|
+
behaviorRule: "\u52A9\u624B\u56DE\u7B54\u6B63\u6587\u4E00\u5F8B\u7FFB\u8BD1\uFF0C\u5305\u62EC\u6700\u7EC8\u6C47\u603B\u4E0E\u6574\u6BB5\u4E2D\u6587\u7684\u5757\uFF1A\u4E2D\u6587\u5757\u540C\u6837\u4EA4\u7ED9\u6A21\u578B\u6539\u5199\u6210\u81EA\u7136\u4E2D\u6587\uFF0C\u610F\u4E49\u3001\u672F\u8BED\u4E0E\u6570\u5B57\u4E0D\u53D8\uFF1B\u7A7A\u767D\u5757\u4E0D\u9001\u8BD1\u3001\u5DE6\u7F18\u4E0D\u51FA\u73B0\u4EFB\u4F55\u6807\u8BB0\u3002\u601D\u8003\u94FE\u6B63\u6587\u3001\u5DE5\u5177\u8C03\u7528\u6807\u9898\u4E0E\u6298\u53E0\u6458\u8981\u4E0D\u7FFB\u8BD1\uFF0C\u4EE3\u7801\u5757\u53CA\u5176\u5185\u90E8\u539F\u6837\u4FDD\u7559\u3002",
|
|
445
445
|
dockLabel: "\u8BD1",
|
|
446
446
|
dockOn: "\u6B63\u6587\u7FFB\u8BD1\u5DF2\u5F00\u542F\uFF0C\u70B9\u51FB\u5173\u95ED",
|
|
447
447
|
dockOff: "\u6B63\u6587\u7FFB\u8BD1\u5DF2\u5173\u95ED\uFF0C\u70B9\u51FB\u5F00\u542F",
|
|
448
448
|
failTitle: "\u7FFB\u8BD1\u5931\u8D25",
|
|
449
|
-
retryAria: "\u7FFB\u8BD1\u5931\u8D25\uFF0C\u70B9\
|
|
449
|
+
retryAria: "\u7FFB\u8BD1\u5931\u8D25\uFF0C\u70B9\u8FD9\u4E2A\u6309\u94AE\u91CD\u65B0\u7FFB\u8BD1\u6574\u884C",
|
|
450
|
+
retryBusyAria: "\u6B63\u5728\u91CD\u65B0\u7FFB\u8BD1\uFF0C\u8BF7\u7B49\u5F85",
|
|
450
451
|
toggleToOriginalAria: "\u67E5\u770B\u539F\u6587",
|
|
451
|
-
toggleToTranslatedAria: "\u67E5\u770B\u8BD1\u6587"
|
|
452
|
-
inflightAria: "\u7FFB\u8BD1\u4E2D\uFF0C\u6B64\u5904\u6682\u65E0\u52A8\u4F5C"
|
|
452
|
+
toggleToTranslatedAria: "\u67E5\u770B\u8BD1\u6587"
|
|
453
453
|
};
|
|
454
454
|
var en = {
|
|
455
455
|
masterTitle: "Translation master switch",
|
|
456
456
|
enableTranslation: "Enable translation",
|
|
457
|
-
masterDesc: "Automatically translates assistant reply prose (e.g. {example}) into Chinese: text inside disclosure blocks and the final summary are treated alike, and blocks written entirely in Chinese go through the model too, which rewrites them into natural Chinese and smooths out machine-flavored phrasing. Think cards and tool-call rows are never translated, and code blocks stay untouched.
|
|
457
|
+
masterDesc: "Automatically translates assistant reply prose (e.g. {example}) into Chinese: text inside disclosure blocks and the final summary are treated alike, and blocks written entirely in Chinese go through the model too, which rewrites them into natural Chinese and smooths out machine-flavored phrasing. Think cards and tool-call rows are never translated, and code blocks stay untouched. Prose keeps the host's own layout \u2014 nothing is drawn at its left edge. Switching does not live on the prose: a transparent slim strip hugging its left edge is the control \u2014 the pointer turns into a hand over it, and one click swaps translation and original, another swaps back, while the prose itself never reacts to clicks, so selecting or drag-copying text never triggers a swap by accident. A reply the model returned unchanged still counts as translated and stays switchable. When a block fails to translate it stays in its original language with a small \u21BB left beside it: hover that button for the channel detail (a timeout, a broken stream or an empty return), click it to re-run the whole row, and while it waits the icon spins in place and cannot be clicked again; blocks that already succeeded stay on screen undisturbed. Channel failures are never retried automatically: once the channel recovers, a click on \u21BB revives the row. Translations are re-rendered as Markdown, so tables, lists, bold runs and inline code keep their structure. A reply that is still streaming is left alone until it settles, then prose turns to Chinese paragraph by paragraph in reading order. Applies to the session you are viewing only; translations never enter the conversation context. The same switch sits on the row below the composer, sharing its state.",
|
|
458
458
|
aiTitle: "AI translation (OpenAI-compatible)",
|
|
459
459
|
aiRule: "This is the only channel: translation runs when Key, Base URL and model are all present; missing any one leaves the text as it is.",
|
|
460
460
|
badgeConfigured: "Configured",
|
|
@@ -484,10 +484,10 @@ var en = {
|
|
|
484
484
|
dockOn: "Translation is on; click to turn it off",
|
|
485
485
|
dockOff: "Translation is off; click to turn it on",
|
|
486
486
|
failTitle: "Translation failed",
|
|
487
|
-
retryAria: "Translation failed \u2014
|
|
487
|
+
retryAria: "Translation failed \u2014 press this button to translate the whole row again",
|
|
488
|
+
retryBusyAria: "Translating again, please wait",
|
|
488
489
|
toggleToOriginalAria: "Show the original",
|
|
489
|
-
toggleToTranslatedAria: "Show the translation"
|
|
490
|
-
inflightAria: "Translating; Enter does nothing yet"
|
|
490
|
+
toggleToTranslatedAria: "Show the translation"
|
|
491
491
|
};
|
|
492
492
|
var rowT = (key) => zh[key] ?? key;
|
|
493
493
|
function bindRowCopy(locale) {
|
|
@@ -497,15 +497,13 @@ function bindRowCopy(locale) {
|
|
|
497
497
|
}
|
|
498
498
|
}
|
|
499
499
|
function rowCopy() {
|
|
500
|
+
const withDetail = (label, detail) => detail === void 0 || detail === "" || detail === null ? label : `${label} \u2014 ${detail}`;
|
|
500
501
|
return {
|
|
501
|
-
retryAria: rowT("retryAria"),
|
|
502
|
+
retryAria: (detail) => withDetail(rowT("retryAria"), detail),
|
|
503
|
+
retryBusyAria: (detail) => withDetail(rowT("retryBusyAria"), detail),
|
|
502
504
|
toggleToOriginalAria: rowT("toggleToOriginalAria"),
|
|
503
505
|
toggleToTranslatedAria: rowT("toggleToTranslatedAria"),
|
|
504
|
-
|
|
505
|
-
failTitle: (detail) => {
|
|
506
|
-
const label = rowT("failTitle");
|
|
507
|
-
return detail === void 0 || detail === "" || detail === null ? label : `${label} \u2014 ${detail}`;
|
|
508
|
-
}
|
|
506
|
+
failTitle: (detail) => withDetail(rowT("failTitle"), detail)
|
|
509
507
|
};
|
|
510
508
|
}
|
|
511
509
|
|
|
@@ -801,7 +799,16 @@ function isBlankText(value) {
|
|
|
801
799
|
return (value ?? "").trim() === "";
|
|
802
800
|
}
|
|
803
801
|
function planAssistantRow(input) {
|
|
804
|
-
const {
|
|
802
|
+
const {
|
|
803
|
+
blocks,
|
|
804
|
+
streaming,
|
|
805
|
+
interrupted,
|
|
806
|
+
groupPart,
|
|
807
|
+
canTranslate,
|
|
808
|
+
outcomes,
|
|
809
|
+
rowRetrying,
|
|
810
|
+
originalKeys
|
|
811
|
+
} = input;
|
|
805
812
|
const hasVisible = streaming || interrupted || blocks.some((block) => block.kind !== "tool-call");
|
|
806
813
|
if (!hasVisible) return { entries: null, texts: [] };
|
|
807
814
|
const texts = [];
|
|
@@ -835,13 +842,13 @@ function planAssistantRow(input) {
|
|
|
835
842
|
const outcome = attemptable && outcomes !== void 0 ? outcomes[index] ?? null : null;
|
|
836
843
|
let mark = null;
|
|
837
844
|
let fail = null;
|
|
845
|
+
let retryBusy = false;
|
|
838
846
|
if (outcome !== null && outcome.ok) {
|
|
839
|
-
mark =
|
|
847
|
+
mark = "translated";
|
|
840
848
|
} else if (outcome !== null) {
|
|
841
849
|
mark = "failed";
|
|
842
850
|
fail = outcome.detail ?? null;
|
|
843
|
-
|
|
844
|
-
mark = "inflight";
|
|
851
|
+
retryBusy = rowRetrying === true;
|
|
845
852
|
}
|
|
846
853
|
entries.push({
|
|
847
854
|
type: "prose",
|
|
@@ -849,7 +856,9 @@ function planAssistantRow(input) {
|
|
|
849
856
|
text: block.text ?? "",
|
|
850
857
|
translated: outcome !== null && outcome.ok ? outcome.translated : null,
|
|
851
858
|
mark,
|
|
852
|
-
|
|
859
|
+
showingOriginal: outcome !== null && outcome.ok && (originalKeys?.has(key) ?? false),
|
|
860
|
+
fail,
|
|
861
|
+
retryBusy
|
|
853
862
|
});
|
|
854
863
|
break;
|
|
855
864
|
}
|
|
@@ -897,42 +906,30 @@ var ASSISTANT_CSS = [
|
|
|
897
906
|
".dsh-ct-body .md-table-wide>table{z-index:1;position:relative}",
|
|
898
907
|
// ---- 已停止标记(宿主 .hWmORq_stopped 等价) ----
|
|
899
908
|
".dsh-ct-stopped{border-radius:var(--dsw-radius-sm);background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-tertiary);align-self:flex-start;padding:0 6px;font-size:11px;line-height:18px}",
|
|
900
|
-
// ----
|
|
901
|
-
//
|
|
909
|
+
// ---- 正文块:排版与宿主默认逐字一致(无 padding、无 border),只做两件事——
|
|
910
|
+
// 当窄带与 ↻ 的定位父级,以及承载一个纯语义的状态类 ----
|
|
902
911
|
".dsh-ct-prose{position:relative}",
|
|
903
|
-
|
|
904
|
-
//
|
|
905
|
-
//
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
".dsh-ct-
|
|
909
|
-
//
|
|
910
|
-
// prefers-reduced-motion 降级为静态灰线 ----
|
|
911
|
-
".dsh-ct-prose-inflight{border-left:1px solid var(--dsw-alias-border-l2);animation:1.4s ease-in-out infinite alternate dsh-ct-prose-inflight-pulse}",
|
|
912
|
-
"@keyframes dsh-ct-prose-inflight-pulse{from{border-left-color:var(--dsw-alias-border-l2)}to{border-left-color:color-mix(in srgb, var(--dsw-alias-border-l2) 20%, transparent)}}",
|
|
913
|
-
"@media (prefers-reduced-motion:reduce){.dsh-ct-prose-inflight{animation:none}}",
|
|
914
|
-
// ---- 左缘热区:随块高铺满的一条透明窄带。绝对定位的偏移以 padding box 为
|
|
915
|
-
// 基准、而线画在 border 上,所以线的左缘在 -1px:`left:-5px` 给出线外侧
|
|
916
|
-
// 4px,`width:17px` 让右缘落在正文第一个字上(12px 缩进),不吃正文。
|
|
917
|
-
// 切换与补跑只由它承载;正文整块不再是点击目标,选中/复制不再误触。
|
|
918
|
-
// z-index 压过宽表格的透明出血层(那条规则给 table 挂了 z-index:1);
|
|
919
|
-
// 出血区是透明 padding,正文格子的起点仍在缩进之外 ----
|
|
920
|
-
".dsh-ct-hotspot{position:absolute;left:-5px;top:0;bottom:0;width:17px;margin:0;padding:0;border:0;background:0 0;cursor:pointer;z-index:2;-webkit-appearance:none;appearance:none}",
|
|
921
|
-
// 在途只剩「已在跑」这一答复:热区保留(键盘焦点不掉),但光标不承诺能点。
|
|
922
|
-
".dsh-ct-hotspot[data-idle]{cursor:default}",
|
|
923
|
-
// 热区没有自己的外形:它是透明的一层。focus-visible 只对键盘聚焦成立(指针
|
|
924
|
-
// 点出来的焦点不匹配),下面的 :has 规则把线加亮——粗细始终只表示译文/原文。
|
|
912
|
+
// ---- 左缘窄带:从正文左缘往外 6px 的一条透明带子,整条在正文之外。绝对定位
|
|
913
|
+
// 的偏移以 padding box 为基准,而正文从 padding box 左缘起排;`left:-6px`
|
|
914
|
+
// + `width:6px` 于是恰好落在 [-6px,0),一个字都不压,也不占排版。
|
|
915
|
+
// z-index 压过宽表格的透明出血层(那条规则给 table 挂了 z-index:1)。
|
|
916
|
+
// 宿主正文列左侧恒定有 32px(侧栏嵌入 24px)内边距,这条带子落在空白里。 ----
|
|
917
|
+
".dsh-ct-hotspot{position:absolute;left:-6px;top:0;bottom:0;width:6px;margin:0;padding:0;border:0;background:0 0;cursor:pointer;z-index:2;-webkit-appearance:none;appearance:none}",
|
|
918
|
+
// 键盘可聚焦,但不加任何可见标记:没有 outline,也没有别的变化。
|
|
925
919
|
".dsh-ct-hotspot:focus-visible{outline:none}",
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
//
|
|
931
|
-
".dsh-ct-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
//
|
|
935
|
-
|
|
920
|
+
// ---- 失败块的 ↻:真按钮,常驻在正文左侧的空隙里(`left:-18px` + 16px 宽,
|
|
921
|
+
// 右缘距正文 2px,覆盖不到任何文字)。它是失败段唯一的点击目标——失败
|
|
922
|
+
// 块不放窄带,一段落只对应一个动作。 ----
|
|
923
|
+
".dsh-ct-retry{position:absolute;left:-18px;top:2px;width:16px;height:20px;display:flex;align-items:center;justify-content:center;margin:0;padding:0;border:0;background:0 0;color:var(--dsw-alias-state-error-primary);cursor:pointer;z-index:3;-webkit-appearance:none;appearance:none}",
|
|
924
|
+
// 补跑在途:原位转圈(同一个节点,不重挂载——键盘焦点不掉),并停止承诺重复点。
|
|
925
|
+
".dsh-ct-retry[data-busy]{cursor:default}",
|
|
926
|
+
".dsh-ct-retry[data-busy] .dsh-ct-retry-spin{animation:0.9s linear infinite dsh-ct-retry-spin}",
|
|
927
|
+
"@keyframes dsh-ct-retry-spin{to{transform:rotate(360deg)}}",
|
|
928
|
+
// 尊重 reduced-motion:不转圈,但「按下去没用」这件事必须仍然看得见——否则
|
|
929
|
+
// 关掉动画后按钮就只剩「点不动又没提示」。用静态的变淡替代旋转。
|
|
930
|
+
"@media (prefers-reduced-motion:reduce){.dsh-ct-retry-spin{animation:none}.dsh-ct-retry[data-busy]{opacity:.45}}",
|
|
931
|
+
// 键盘同样可以聚焦 ↻,但界面不给任何可见标记(与窄带一致)。
|
|
932
|
+
".dsh-ct-retry:focus-visible{outline:none}",
|
|
936
933
|
// ---- ReasoningRow(宿主 lcKema_* 等价,前缀换成 dsh-ct-think) ----
|
|
937
934
|
".dsh-ct-think-root{flex-direction:column;display:flex}",
|
|
938
935
|
".dsh-ct-think-root:not([data-expanded]){contain:size layout;height:calc(24px + var(--dsh-content-font-delta,0px))}",
|
|
@@ -956,25 +953,23 @@ var ASSISTANT_CSS = [
|
|
|
956
953
|
].join("");
|
|
957
954
|
var PROSE_BY_MARK = {
|
|
958
955
|
translated: { className: "dsh-ct-prose-translated", action: "toggle" },
|
|
959
|
-
|
|
960
|
-
failed: { className: "dsh-ct-prose-failed", action: "retry" },
|
|
961
|
-
// 在途有线、有热区,但 action 为 null:按下去是空操作(脉动已是「已在跑」
|
|
962
|
-
// 的答复),热区保留只是为了让键盘焦点不掉回页面。
|
|
963
|
-
inflight: { className: "dsh-ct-prose-inflight", action: null }
|
|
956
|
+
failed: { className: "dsh-ct-prose-failed", action: "retry" }
|
|
964
957
|
};
|
|
965
958
|
var PROSE_BASE_CLASS = "dsh-ct-prose";
|
|
966
959
|
function prosePresentation(mark) {
|
|
967
|
-
return mark === null ?
|
|
960
|
+
return mark === null ? null : PROSE_BY_MARK[mark];
|
|
968
961
|
}
|
|
969
|
-
function
|
|
970
|
-
|
|
971
|
-
return line === null ? void 0 : `${PROSE_BASE_CLASS} ${line}`;
|
|
962
|
+
function proseAction(mark) {
|
|
963
|
+
return prosePresentation(mark)?.action ?? null;
|
|
972
964
|
}
|
|
973
|
-
function
|
|
974
|
-
|
|
965
|
+
function proseClassNames(mark) {
|
|
966
|
+
const presentation = prosePresentation(mark);
|
|
967
|
+
return presentation === null ? void 0 : `${PROSE_BASE_CLASS} ${presentation.className}`;
|
|
975
968
|
}
|
|
976
969
|
var HOTSPOT_CLASS = "dsh-ct-hotspot";
|
|
977
|
-
var
|
|
970
|
+
var RETRY_CLASS = "dsh-ct-retry";
|
|
971
|
+
var RETRY_BUSY_ATTR = "data-busy";
|
|
972
|
+
var RETRY_SPIN_CLASS = "dsh-ct-retry-spin";
|
|
978
973
|
function ensureAssistantStyles() {
|
|
979
974
|
if (typeof document === "undefined") return;
|
|
980
975
|
const selector = `style[data-plugin-css=${JSON.stringify(STYLE_TAG_ID)}]`;
|
|
@@ -1045,7 +1040,7 @@ var ChatTranslateStore = class {
|
|
|
1045
1040
|
}
|
|
1046
1041
|
/**
|
|
1047
1042
|
* 确保该行按当前文本被翻译。
|
|
1048
|
-
* @param manual -
|
|
1043
|
+
* @param manual - 用户点击失败块的 ↻ 发起的补跑:已落定的同代行只有这条路会重发。
|
|
1049
1044
|
* @returns 是否发出了新的请求。
|
|
1050
1045
|
*/
|
|
1051
1046
|
ensure(rowKey, texts, manual = false) {
|
|
@@ -1054,23 +1049,24 @@ var ChatTranslateStore = class {
|
|
|
1054
1049
|
if (current !== void 0 && sameTexts(current.texts, texts)) {
|
|
1055
1050
|
if (current.status === "pending") return false;
|
|
1056
1051
|
if (!manual) return false;
|
|
1057
|
-
seed = current.outcomes.map((outcome) => outcome
|
|
1052
|
+
seed = current.outcomes.map((outcome) => outcome === null ? null : { ...outcome });
|
|
1058
1053
|
}
|
|
1059
1054
|
const snapshot = [...texts];
|
|
1060
1055
|
const seedOutcomes = seed ?? snapshot.map(() => null);
|
|
1061
1056
|
const next = {
|
|
1062
1057
|
status: "pending",
|
|
1063
1058
|
texts: snapshot,
|
|
1064
|
-
outcomes: seedOutcomes
|
|
1059
|
+
outcomes: seedOutcomes,
|
|
1060
|
+
retrying: manual
|
|
1065
1061
|
};
|
|
1066
1062
|
this.rows.delete(rowKey);
|
|
1067
1063
|
this.rows.set(rowKey, next);
|
|
1068
1064
|
this.prune();
|
|
1069
1065
|
this.bump();
|
|
1070
|
-
if (snapshot.length > 0) void this.run(rowKey, snapshot, seedOutcomes);
|
|
1066
|
+
if (snapshot.length > 0) void this.run(rowKey, snapshot, seedOutcomes, manual);
|
|
1071
1067
|
return true;
|
|
1072
1068
|
}
|
|
1073
|
-
async run(rowKey, texts, initial) {
|
|
1069
|
+
async run(rowKey, texts, initial, retrying) {
|
|
1074
1070
|
const outcomes = initial.map((o) => o);
|
|
1075
1071
|
let offset = 0;
|
|
1076
1072
|
for (const batch of chunkTexts(texts)) {
|
|
@@ -1099,7 +1095,8 @@ var ChatTranslateStore = class {
|
|
|
1099
1095
|
this.rows.set(rowKey, {
|
|
1100
1096
|
status: "pending",
|
|
1101
1097
|
texts: live.texts,
|
|
1102
|
-
outcomes: [...outcomes]
|
|
1098
|
+
outcomes: [...outcomes],
|
|
1099
|
+
retrying
|
|
1103
1100
|
});
|
|
1104
1101
|
this.bump();
|
|
1105
1102
|
}
|
|
@@ -1108,7 +1105,8 @@ var ChatTranslateStore = class {
|
|
|
1108
1105
|
this.rows.set(rowKey, {
|
|
1109
1106
|
status: "settled",
|
|
1110
1107
|
texts: state.texts,
|
|
1111
|
-
outcomes: [...outcomes]
|
|
1108
|
+
outcomes: [...outcomes],
|
|
1109
|
+
retrying: false
|
|
1112
1110
|
});
|
|
1113
1111
|
this.bump();
|
|
1114
1112
|
}
|
|
@@ -1311,65 +1309,78 @@ function ProseBlock({
|
|
|
1311
1309
|
text,
|
|
1312
1310
|
translated,
|
|
1313
1311
|
mark,
|
|
1312
|
+
showingOriginal,
|
|
1314
1313
|
fail,
|
|
1314
|
+
retryBusy,
|
|
1315
1315
|
onToggle,
|
|
1316
1316
|
onRetry,
|
|
1317
|
-
canTranslate,
|
|
1318
1317
|
streaming,
|
|
1319
1318
|
labels,
|
|
1320
1319
|
mentions,
|
|
1321
1320
|
pathImages
|
|
1322
1321
|
}) {
|
|
1323
|
-
const
|
|
1324
|
-
const
|
|
1325
|
-
const retrying = action === "retry";
|
|
1326
|
-
const handler = retrying ? onRetry : onToggle;
|
|
1327
|
-
const source = mark === "translated" ? translated : text;
|
|
1322
|
+
const action = proseAction(mark);
|
|
1323
|
+
const source = mark === "translated" && !showingOriginal ? translated : text;
|
|
1328
1324
|
const copy = rowCopy();
|
|
1329
|
-
const className =
|
|
1330
|
-
const hotspot =
|
|
1325
|
+
const className = proseClassNames(mark) ?? PROSE_BASE_CLASS;
|
|
1326
|
+
const hotspot = action !== "toggle" ? null : React.createElement("button", {
|
|
1331
1327
|
type: "button",
|
|
1332
1328
|
className: HOTSPOT_CLASS,
|
|
1333
|
-
//
|
|
1334
|
-
"aria-label":
|
|
1335
|
-
...mark === "inflight" ? { [HOTSPOT_IDLE_ATTR]: "true" } : {},
|
|
1329
|
+
// 窄带是覆盖层,读屏只应听到它的动作,正文仍由 MarkdownText 读。
|
|
1330
|
+
"aria-label": showingOriginal ? copy.toggleToTranslatedAria : copy.toggleToOriginalAria,
|
|
1336
1331
|
tabIndex: 0,
|
|
1337
1332
|
// button 自己会按 Enter/Space 合成 click,若不接管就会与这段键盘处理
|
|
1338
1333
|
// 叠加成两次动作:这里两个键都走 keydown 并 preventDefault,合成被掐掉。
|
|
1339
|
-
onKeyDown:
|
|
1334
|
+
onKeyDown: (event) => {
|
|
1340
1335
|
if (event.key !== "Enter" && event.key !== " ") return;
|
|
1341
1336
|
event.preventDefault();
|
|
1342
|
-
|
|
1343
|
-
}
|
|
1344
|
-
onClick:
|
|
1337
|
+
onToggle();
|
|
1338
|
+
},
|
|
1339
|
+
onClick: (event) => {
|
|
1345
1340
|
if (isCleanHotspotClick(
|
|
1346
1341
|
{ target: event.target, currentTarget: event.currentTarget },
|
|
1347
1342
|
typeof window === "undefined" ? void 0 : window
|
|
1348
1343
|
)) {
|
|
1349
|
-
|
|
1344
|
+
onToggle();
|
|
1350
1345
|
}
|
|
1351
|
-
}
|
|
1346
|
+
}
|
|
1352
1347
|
});
|
|
1353
|
-
const
|
|
1354
|
-
"
|
|
1355
|
-
{
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1348
|
+
const retryButton = React.createElement(
|
|
1349
|
+
"button",
|
|
1350
|
+
{
|
|
1351
|
+
type: "button",
|
|
1352
|
+
className: RETRY_CLASS,
|
|
1353
|
+
// 败因进按钮自己的读屏标签:气泡只在 openOnClick 时才挂 aria-describedby,
|
|
1354
|
+
// 读屏用户不悬停,标签是他们唯一能听到「超时 / 断流 / 空返回」的地方。
|
|
1355
|
+
"aria-label": retryBusy ? copy.retryBusyAria(fail) : copy.retryAria(fail),
|
|
1356
|
+
...retryBusy ? { [RETRY_BUSY_ATTR]: "true" } : {},
|
|
1357
|
+
tabIndex: 0,
|
|
1358
|
+
onKeyDown: (event) => {
|
|
1359
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
1360
|
+
event.preventDefault();
|
|
1361
|
+
if (!retryBusy) onRetry();
|
|
1362
|
+
},
|
|
1363
|
+
onClick: retryBusy ? void 0 : () => {
|
|
1364
|
+
onRetry();
|
|
1365
|
+
}
|
|
1366
|
+
},
|
|
1367
|
+
React.createElement(
|
|
1368
|
+
"span",
|
|
1369
|
+
{ className: RETRY_SPIN_CLASS, "aria-hidden": true },
|
|
1370
|
+
React.createElement(import_dsh_client_ui_primitives3.IconRefreshOutlineRegular, { size: 10 })
|
|
1371
|
+
)
|
|
1372
|
+
);
|
|
1373
|
+
const retry = action !== "retry" ? null : React.createElement(import_dsh_client_ui_primitives3.Tooltip, {
|
|
1359
1374
|
label: () => copy.failTitle(fail),
|
|
1360
1375
|
side: "top",
|
|
1361
1376
|
portal: true,
|
|
1362
|
-
|
|
1363
|
-
children: hotspot
|
|
1377
|
+
children: retryButton
|
|
1364
1378
|
});
|
|
1365
1379
|
return React.createElement(
|
|
1366
1380
|
"div",
|
|
1367
|
-
{
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
},
|
|
1371
|
-
retryIcon,
|
|
1372
|
-
anchor,
|
|
1381
|
+
{ className },
|
|
1382
|
+
retry,
|
|
1383
|
+
hotspot,
|
|
1373
1384
|
React.createElement(import_dsh_client_ui_primitives3.MarkdownText, {
|
|
1374
1385
|
text: source,
|
|
1375
1386
|
streaming,
|
|
@@ -1432,7 +1443,7 @@ var AssistantStepView = (0, import_react3.memo)(function AssistantStepView2(prop
|
|
|
1432
1443
|
groupPart,
|
|
1433
1444
|
canTranslate,
|
|
1434
1445
|
outcomes: rowState?.outcomes,
|
|
1435
|
-
|
|
1446
|
+
rowRetrying: rowState?.retrying,
|
|
1436
1447
|
originalKeys
|
|
1437
1448
|
}),
|
|
1438
1449
|
[blocks, streaming, interrupted, groupPart, canTranslate, rowState, originalKeys]
|
|
@@ -1464,10 +1475,11 @@ var AssistantStepView = (0, import_react3.memo)(function AssistantStepView2(prop
|
|
|
1464
1475
|
text: entry.text,
|
|
1465
1476
|
translated: entry.translated,
|
|
1466
1477
|
mark: entry.mark,
|
|
1478
|
+
showingOriginal: entry.showingOriginal,
|
|
1467
1479
|
fail: entry.fail,
|
|
1480
|
+
retryBusy: entry.retryBusy,
|
|
1468
1481
|
onToggle: () => toggleBlock(entry.key),
|
|
1469
1482
|
onRetry: retryRow,
|
|
1470
|
-
canTranslate,
|
|
1471
1483
|
streaming,
|
|
1472
1484
|
labels,
|
|
1473
1485
|
mentions,
|