nanbujiwanfeng
deepseek-harness-translation
Bidirectional Chinese↔English conversation translation for deepseek-harness: Chinese-speaking users converse in Chinese, each message is auto-translated to English for the agent, and English replies return as Chinese with bilingual rows in the Web Client.
- Stars
- 1
- Language
- TypeScript
- Created
- Aug 15, 2026
- Updated
- Aug 15, 2026
Introduction
dsh-translation-plugin
deepseek-harness 的对话翻译插件(面向中国用户):用户用中文对话,插件自动把中文翻译成英文交给 agent 执行;agent 的英文回复自动回译成中文显示。页面同时展示「原文(中文)」和「中文翻译」双语行。
目录结构
| 路径 | 说明 |
|---|---|
packages/session/conversation-translator/ | 宿主插件:翻译管线(zh2en 改写、双语记录、en2zh 回译、失败兜底) |
packages/client/ui-translation/ | 客户端插件:页面双语行渲染 |
examples/web-cordis/translator.cordis.yml | 启用配置(--patch overlay) |
apps/web/tests/translation-rows.e2e.ts | 端到端测试(可选) |
harness-integration.patch | 对 harness 的接线改动(tsconfig、bundle 清单等) |
sync-to-harness.mjs | 一键安装/同步脚本 |
前置要求
- deepseek-harness 源码 checkout,版本锁定 commit 47f943859b(v0.1.0-rc.5)
- Node.js 20+、pnpm
- 可用的 DeepSeek API 配置(翻译会真实调用模型,消耗你自己的配额;不额外指定时直接复用 agent 的 provider/model 路由)
安装(首次)
在任意目录执行(harness 仓库路径换成你自己的):
node <本仓库路径>/sync-to-harness.mjs <harness 仓库路径>
cd <harness 仓库路径>
pnpm install
npm run build
npm run dsh -- web --patch examples/web-cordis/translator.cordis.yml
打开 http://127.0.0.1:3080 ,用中文对话即可。用户消息旁会显示「原文(中文)」行,agent 回复下方会显示「中文翻译」行。
更新同步
插件作者推送更新后:
git pull # 拉取插件仓库更新
node sync-to-harness.mjs <harness 仓库路径> # 重跑同步(幂等,可放心重复执行)
pnpm install && npm run build
手动安装(不用脚本)
- 把
packages/session/conversation-translator、packages/client/ui-translation拷进 harness 仓库对应目录 - 把
examples/web-cordis/translator.cordis.yml拷到对应位置 - 把
apps/web/tests/translation-rows.e2e.ts拷到对应位置 - 在 harness 仓库根目录执行
git apply <本仓库路径>/harness-integration.patch pnpm install && npm run build
配置项
见 examples/web-cordis/translator.cordis.yml 中的注释。所有字段都有默认值:
| 字段 | 默认 | 含义 |
|---|---|---|
enabled | true | 双向翻译总开关 |
provider / model | 空 | 留空 = 复用 agent 自己的模型路由;成对填写可指定独立翻译模型 |
timeoutMs | 30000 | 单次翻译调用的超时 |
maxTokens | 4096 | 单次翻译的输出 token 上限 |
temperature | 0.1 | 翻译是客观任务,默认低温度保证确定性 |
翻译失败不影响主流程:原始消息照常交给 agent 执行,控制台只打 warning。
验证
# 宿主单元测试(28 个用例)
npx vitest run packages/session/conversation-translator/tests/translator.spec.ts
# 浏览器端到端测试(可选,需要 Playwright;未下载浏览器时可用系统 Edge)
DSH_PLAYWRIGHT_EXECUTABLE_PATH="C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe" \
npx vitest run --config vitest.web.config.ts apps/web/tests/translation-rows.e2e.ts
升级 harness 注意
harness-integration.patch 基于 commit 47f943859b 生成。如果之后升级 harness 本身,补丁可能冲突失效,需要插件作者针对新版本重新生成补丁(插件源码部分不受影响)。
常见问题
- 翻译没触发:用户消息需含中文字符才会翻译;纯英文消息直接放行(本来就无需翻译)。
- 端口被占:默认 3080,被占用时参考 harness 文档指定其他端口(
--patch一个覆盖 webserver.port 的 yml 即可)。 - 想要关闭某一方向:删掉
translator.cordis.yml里对应的那一行 insert 即可(宿主行关翻译管线,客户端行关页面展示)。
许可
MIT(基于 deepseek-harness,Copyright (c) 2026 DeepSeek)。