UI Enhancements

dsh-think-translate

onfire-07/dsh-think-translate · ★ 1

onfire-07

DeepSeek Harness (DSH) Web plugin: click a Think row to open a floating window that live-translates the reasoning steps into Simplified Chinese.

README body is shown in Chinese.

License
MIT
Added
2026-08-16
Maintenance
active
Install kind
github
Manifest details
Manifest status
Declared
Manifest path
package.json#dsh
Manifest checked
2026-08-19
Lifecycle scripts
None found

Static manifest checks report declarations only; they are not compatibility or security review.

安装

dsh plugin --profile web add github:onfire-07/dsh-think-translate

GitHub 源码安装:首次需按提示配置 allowBuilds 构建授权后重试

For install and environment setup, plus plugin development tutorials, see DSH community docs ↗

README

Source README · body: zh · Read Chinese README

Table of contents
  1. 效果
  2. 安装
  3. 1. 安装包到 profile
  4. 2. 在 profile 补丁层注册插件行
  5. 3. 刷新页面
  6. 工作原理
  7. 宿主路由
  8. 目录结构
  9. 测试
  10. 常见问题
  11. License

DeepSeek Harness(DSH)Web 插件:点击聊天中的 Think 思考行时,会在右上角额外弹出一个浮动窗口,把该思考步骤的英文实时同步翻译成中文。

  • 流式输出期间:增量翻译,窗口跟随思考内容持续更新(「同步中…」)
  • 思考结束:自动做一次完整润色翻译(「已同步」)
  • 支持查看原文对照、关闭、失败重试
  • 主题色自适应(浅色/深色)
  • 翻译走 DSH 当前配置的模型,不需要额外的翻译 API Key

效果

  1. 在聊天里点击任意一条消息的 Think 行(标题为 "Think" 的折叠行)
  2. 右上角弹出「思考翻译」窗口,状态依次为:等待思考内容… → 翻译中… → 同步中… → 已同步
  3. 思考还在流式输出时,窗口会持续跟随更新;结束后做一次完整润色
  4. 顶部按钮:查看原文 / 只看翻译(底部对照区)、关闭;翻译失败时显示错误并给出重试

安装

本插件是一个 DSH 双面(dual-face)插件包:宿主半在 Node 进程注册翻译路由,浏览器半注入浮动窗口 UI。安装到你的 web profile 即可永久生效(每次启动自动加载)。

1. 安装包到 profile

DSH_HOME/profiles/web/node_modules/
└── dsh-think-translate/          ← 把本仓库(除 .git/README 外)拷到这里
    ├── package.json
    └── lib/
        ├── index.js              ← 宿主半(注册 POST /think-translate)
        └── client.js             ← 浏览器半(浮动窗口 + 点击拦截)

Windows 下 DSH_HOME 默认为 C:\Users\<你>\.dsh。

2. 在 profile 补丁层注册插件行

编辑 DSH_HOME/profiles/web/cordis.patch.yml(顶层是一个 YAML 数组),追加:

- insert:
    - id: think-translator
      name: dsh-think-translate

补丁层被 DSH 热监视:保存后插件行立即挂载;客户端 bundle 会出现在启动清单里。

3. 刷新页面

刷新浏览器页面即可(若浏览器半未出现,重启一次 dsh web 再刷新)。

工作原理

Think 行点击 (浏览器半, document 级捕获 [data-variant="think"])
        │
        ▼
浮动窗口每 500ms 轮询该行的思考文本(展开后的正文/折叠时的摘要)
        │  文字稳定约 1s 后发起翻译
        ▼
POST /think-translate  ──►  宿主半(webServer 精确路由)
{ text, mode, context }          │
        ▲                        ▼
        │                llm.stream(当前模型, system 提示词=翻译引擎)
        │                        │
        └──── { ok, text } ◄─────┘
  • 增量翻译(mode: "delta"):流式期间只翻译新增片段,带上前后文尾巴保证连贯,省 token
  • 完整翻译(mode: "full"):首次翻译、增量拼接超过一次后的最终润色、以及原文非前缀增长时的兜底
  • 缓存:宿主持 100 条 LRU 缓存,同一段文本重复点击不重复调模型
  • 防护:请求体 200KB 上限、文本 10 万字符上限、非法 JSON 返回 400、非 POST 返回 405

宿主路由

路径 方法 说明
/think-translate POST 请求体 { "text": string, "mode": "full" | "delta", "context"?: { previousEnglishTail, previousChineseTail } },返回 { "ok": true, "text": "…" } 或 { "ok": false, "error": "…" }

目录结构

├── lib/
│   ├── index.js    # 宿主半:webServer 路由 + llm 翻译(缓存/队列/限长)
│   └── client.js   # 浏览器半:shell.overlay 窗口 + Think 行点击拦截 + 轮询同步
├── tests/
│   └── smoke-test.mjs   # 宿主半冒烟测试(node tests/smoke-test.mjs)
├── package.json    # dsh.client 声明 + exports["./client"]
└── README.md

测试

node tests/smoke-test.mjs

覆盖:路由注册恰好一次且存活到卸载、请求→响应 JSON、llm 调用参数形状、缓存命中、非 POST 405、卸载时注销路由。

常见问题

  • 点击后窗口一直「等待思考内容…」:思考行还在折叠状态且正在流式输出。点击行本身会展开它;展开后(或思考结束后)即开始翻译。
  • 翻译失败:检查 DSH 的模型配置(插件使用当前选中的 provider/model);点窗口里的「重试」。
  • 修改包代码后不生效:DSH 进程内 ESM 模块缓存,包代码改动需重启 dsh web(补丁 YAML 本身是热生效的)。

License

MIT