feat(reply-read-aloud): project speakable reply text - #557
Conversation
|
这个 PR 不受 #565(已合并进 朗读按钮的接法。 #565 给默认助手消息加了组合槽位: <AssistantMessage message={message}>
<AssistantMessageToolbar message={message} />
</AssistantMessage>需要注意的是 投影函数的归属(非阻塞,可以合并后再动)。 投影本身的逻辑我这次没有重新逐行看,#518 review 提的两个问题——所有拉丁字母语言被判成 |
|
完整 review 了当前 head(
不过实测中发现三个建议合并前处理的问题。 P11. 链接正则灾难性回溯,能冻住 JS 线程。 projectAssistantMessageReadAloud.ts:54(同形问题在 :51 和 :53)。
触发条件很宽:消息里出现任意 修复是把两个分支改成互斥: - text = text.replace(/!\[[^\]]*\]\((?:\\.|[^)])*\)/g, '');
+ text = text.replace(/!\[[^\]]*\]\((?:[^()\\]|\\.)*\)/g, '');
text = text.replace(/!\[[^\]]*\]\[[^\]]*\]/g, '');
- text = text.replace(/\[\d+\]\((?:\\.|[^)])*\)/g, '');
- text = text.replace(/\[([^\]]+)\]\((?:\\.|[^)])*\)/g, '$1');
+ text = text.replace(/\[\d+\]\((?:[^()\\]|\\.)*\)/g, '');
+ text = text.replace(/\[([^\]]+)\]\((?:[^()\\]|\\.)*\)/g, '$1');我把这个改动打进去跑了 PR 自带的 50 个测试,全过、行为不变,同一 payload 从 943ms 降到 0.00ms。 2. 行内代码里的标识符仍然被吃掉——正是本 PR 声称修掉的缺陷,只是换到了代码跨度里。 :66 先剥掉反引号,:69 才做强调投影,于是代码跨度里的内容被当成 Markdown 强调处理。实测: 代码跨度恰恰是标识符密度最高的地方。裸文本里的 3. 第一条最严重:跨度里含 P24. 列表项 / 引用块里的围栏代码不会被移除。 :77 的 围栏行被识别到的数量是 0,代码内容原样进朗读,还带一个残留反引号。引用块里的 5. 248 行的定界符引擎没有自己的测试文件。 6. 有约 30 行复杂度可能是死的。 opener bucket 的 7. 逐块翻译会替换整条消息。 :17-34 一旦找到非空翻译就整条丢掉原文,但 8. 单个假名/谚文字符会翻转整条回复的语音。 两点说明桌面用 这三个模块目前全仓零调用方(diff 是纯新增 796 行、零删除),所以上述缺陷现在都还不可达,要等 TTS runtime 接线才生效——但也意味着现在改的成本最低。顺带一个接线时会撞上的问题:测试 fixture 用的是大写区域码( 文件归属搬得很干净:全仓 grep 写得好的部分点名: 验证方式:三个函数脱离 jest 单独执行做行为刻画,22 个 mutation 逐个实测,2×20000 样本 fuzz 差分,并把 PR 自带的 51 条断言过了一遍同一 harness 确认走的是真实代码路径。 |
…/read-aloud-projection
|
@eeee0717 感谢这轮完整 review,已按 这条评论 逐项处理,当前 head 为
最终验证:3 suites / 81 tests; |
|
@eeee0717 补充处理本轮 read-aloud projection 边界问题,已推送至
本地验证:
CI 已由新提交触发。 |
…/read-aloud-projection
…/read-aloud-projection
|
@eeee0717 最终补充:后续边界修复与 CI 稳定性处理已推送,当前 head 为
验证:相关 4 suites / 102 tests; |
…/read-aloud-projection # Conflicts: # src/frontend/features/paintings/hooks/__tests__/usePaintings.test.tsx
Summary
Why
This extracts the pure read-aloud projection layer from #518 so it can be reviewed and merged independently of the toolbar and native TTS lifecycle. It addresses review feedback about language selection, Markdown boundary handling, URL projection, and destructive delimiter cleanup.
The paintings test adjustment follows the two-stage query contract introduced by #594 and prevents the full CI suite from asserting before the image ratio query resolves.
Validation
pnpm test:app -- src/frontend/features/chat/workspace/utils/__tests__/projectAssistantMessageReadAloud.test.ts src/frontend/features/chat/workspace/utils/__tests__/projectMarkdownInlineForSpeech.test.ts src/frontend/features/chat/workspace/utils/__tests__/resolveAssistantReadAloudLanguage.test.ts src/frontend/features/paintings/hooks/__tests__/usePaintings.test.tsx --runInBand— 102 tests passedpnpm format:checkpnpm typecheckpnpm lint— 0 errors; existing repository warnings onlyThis PR has no dependency on the toolbar PR. Native TTS and UI integration will follow only after both foundations merge.