Skip to content

docs: add a COT translation adapter example - #75

Merged
aa2246740 merged 1 commit into
aa2246740:mainfrom
LingMoe404:feat/reasoning-translation
Nov 3, 2026
Merged

aa2246740 merged 1 commit into
aa2246740:mainfrom
LingMoe404:feat/reasoning-translation

Conversation

@LingMoe404

@LingMoe404 LingMoe404 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

背景

官方「思考过程机器翻译」组合包把译文注册在 conversation.chat.reasoning.body 插槽上,而阅读页用自己的卡片渲染思考,那个插槽不会渲染——所以装了翻译包,在阅读页看起来像没翻译。

#76 已经给出了正确方向:dsh-better-display.text-transform 缝,翻译由第三方插件注册。但 docs/extension-points.md 目前只有一个同步的大写示例;真实翻译要异步批次、要 subscribe、要按 blockKey 缓存、要在流式过程中只翻已完成段落——这些没有可抄的版本。

这个 PR 改了什么

  • 新增 examples/cot-translation-reader/:一个可运行的参考适配器
    • 注册 reasoning transformer,read 保持同步,请求排进微任务,完成后 subscribe 通知重绘;
    • 用 ctx.cotTranslation 的 limits() 取目标语言与单次上限,按上限切分已完成段落;
    • 按 blockKey 缓存译文,源文本变长时只请求新增段落;
    • 失败返回 undefined(保留原文),卸载时不再发布。
    • 附带 cordis.patch.yml 与独立 tsconfig.json,可以直接在本地 profile 里试。
  • docs/extension-points.md:新增「接官方思考翻译(cotTranslation)」一节,写明 limits() / translate() 的调用形状,以及四个坑(同步 read、不发半句话、按块缓存、失败回 undefined)。
  • CHANGELOG.md:Unreleased 条目。

不改 lib/,不改运行时行为,纯文档与示例。

验证

  • npx tsc -p examples/cot-translation-reader 通过
  • npm run typecheck、npm run lint、node scripts/check-agents-md.mjs 通过
  • npx vitest run --project unit:39 个文件通过;唯一失败是 tests/skill-status.test.ts 的 Windows 路径断言(本机环境问题,Linux CI 不复现)

备注

@LingMoe404
LingMoe404 requested a review from aa2246740 as a code owner October 26, 2026 13:13
The official COT translation bundle registers translated reasoning on
`conversation.chat.reasoning.body`, and the reading view replaces that view,
so enabling the bundle cannot paint translation here. aa2246740#76's text-transform
seam is the supported way in, but the docs only sketch a synchronous
uppercase example.

Add a worked adapter under `examples/cot-translation-reader/` that registers
`reasoning`, reads `ctx.cotTranslation` lazily, splits completed paragraphs
to `maxTextChars`, caches results per block, and leaves the source on screen
when a request fails. The new section in `docs/extension-points.md` records
the four traps: synchronous `read`, no half-written streaming tail, per-block
caching, and `undefined` on failure.
@LingMoe404
LingMoe404 force-pushed the feat/reasoning-translation branch from ad507bf to c734a9d Compare October 29, 2026 07:55
@LingMoe404 LingMoe404 changed the title feat: translate reasoning in the reading view docs: add a COT translation adapter example Oct 29, 2026
@aa2246740
aa2246740 merged commit 561e481 into aa2246740:main Nov 3, 2026
aa2246740 added a commit that referenced this pull request Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants