Repository navigation
fix: 用户消息里的 @ / / 引用恢复成 chip,并且能点开 - #4
Conversation
This view replaces the host's user row, so it inherits that row's duties. It was drawing the message as one joined string, and the string is the smallest part of what a user message is: `@file` and session mentions only become chips, and only become clickable, inside the host's user-content renderer, which parses the text against its reference rules and wires each chip to its own open action. Rendering the text directly showed the same characters with none of that — references arrived as plain text, and clicking them did nothing. The message now goes through `conversation.chat.user.content` with the input the host itself passes: content split the way the host splits it (text blocks concatenated, `image` and `file` attachments in their original order, anything else as an extra block), `referenceLabels` on the content for the summary line and `sessionLabels` in `facts` where the rules read them, `skillNames` in `facts` for `/skill` chips, the session-authorized `loadImage`, and `interactive: true`. `renderFactorySlot` is taken from the props the seat already hands this renderer, so no extra injection is needed. Two things kept the old path alive, because it is what a host that predates this factory gets: - the factory is probed per render and a throw falls back to the plain bubble rather than failing the row, so a host that is still booting — or one without the factory at all — still shows the message, and a later render picks the factory up instead of latching it off; - `.mtx-bubble` and its image placeholder remain the fallback branch only, so the host's bubble is never wrapped in a second one of ours. Attachments also stop being guessed at on hosts that have the factory: the host's own gallery and file cards draw them, in order, including file attachments the old renderer ignored entirely. Text blocks now concatenate without an inserted separator, which is what the host does and what copy and edit should therefore match. `.mtx-content` is the only CSS added — the host's column, inside the row's width cap. The graph's click-to-flash animation targets the host bubble through `[data-message-bubble]` as well, since `.mtx-bubble` no longer exists on the host path. test/client-references.test.mjs holds the delegation to the factory input, and the two fallbacks. Verified on a real host as well: a message reading `@README.md what does this file say?` renders a file chip whose click opens the file in the sidebar, where 1.2.3 showed the literal text and no chip.
The host draws its own caps as percentages of the column it is given
(`UserContent`: `max-width: min(calc(var(--dsh-chat-content-width, 748px)
* 0.702), 82%)`). Inside the row we replaced, the content sat in two
shrink-to-fit boxes (`.mtx-line`, `.mtx-content`), so that percentage
became cyclic and Chrome resolved it against the message's own
max-content: the bubble topped out at 82% of the words it held. A short
message collapsed to one character per line ("继续" drawn as "继" /
"续"), and a long one broke at 82% of its own single-line width.
The host path now spans the row and lets the host's own cap do the
limiting, so the numbers match a native row (measured on a live
instance: 24 CJK characters 344px/1 line instead of 282px/2 lines;
long text caps at 593px, the host's 82%). The plain-text fallback keeps
its shrink-to-fit bubble because it never consults the host.
Two assertions pin the contract: the host path must carry the
full-width class and the stylesheet must define it; the fallback must
not.
增补(2026-11-16):宿主路径的容器宽度PR #4 的宿主路径引出另一个可见缺陷:短消息在奇怪的地方折行,例如「继续」显示成 根因仍然在这一层的容器上:宿主的 修复:宿主路径给容器一个确定宽度
|
|
@nohappiness 谢谢你的 PR,也谢谢把「谁接管了哪一行」写清楚,验收省了很多时间。 本地验收(2026-11-16,Windows / Node 24.21.0,HEAD
CI 也绿了(run #68,9 个 job 全过,含 6 个 一处我不打算让你再改: 未验证的部分:真机浏览器里引用 chip 是否可点击,我没有复现;CI 的 合并了。谢谢。 |
现象
装上本插件后,用户消息(也就是本插件接管的那一格)里的引用全部退回纯文本:
@文件/@会话显示成裸字符串,没有 chip 外观;对比同一个 DSH 上不装本插件的原生渲染:原生那条消息里
@README.md是一个带文件图标的按钮,点一下右侧栏打开该文件。根因
本插件用
priority: -1接管了conversation.chat.node的user键(plugin.client.js,slots.inject('conversation.chat.node', …)),于是宿主的UserMessageNodeView不再渲染这一行。但接管之后,气泡里画的是自己拼出来的字符串:而引用 chip 并不在这条路径上。宿主那边的完整链条是:
@引用只有在最后那一步才会变成 chip 并接上点击动作;只画文本,就等于把「样式」和「可点击」一起丢掉了。referenceLabels(会话引用的标签)和skillNames(/skill的 chip 来源)同样是在这一步从facts里读出来的,所以这两类也一起消失。改动
plugin.client.js:renderFactorySlot调conversation.chat.user.content,输入按宿主自己的口径准备:content:文本块按宿主的方式拼接(不加分隔符),image与file附件按原始顺序进attachments,其余块进extraBlocks(以前直接丢掉了file附件和未知块);referenceLabels进 content(气泡下方那行引用小结用),同时进facts.sessionLabels(rule 解析用);skillNames进facts;loadImage透传(宿主的图片槽要用这个被授权的 loader);interactive: true—— 引用就是要能点的。.mtx-bubble不再出现,宿主画的气泡由.mtx-content(宿主自己的列方向,加在本行的宽度上限里)承载;.mtx-bubble只作为 fallback 分支存在。.mtx-content [data-message-bubble]),否则切到宿主路径后闪烁会失效。\n),保证"看到的"和"复制到的"一致。兼容
cordis.patch.yml、不动任何持久格式(message-tree/version/ sidecar / 浏览器偏好都没变),按仓库的版本策略属于 patch。conversation.chat.user.contentfactory 时行为与 1.2.3 完全一致。conversation.chat.user.before这个座位(消息来源标记,例如子代理来源)仍然不会渲染 —— 它要求注册项声明children,而同一 key 上宿主的注册项已经声明过一次,两个注册项同时声明同一个子槽会在 slot 台账里互相覆盖。这条不在本 PR 的范围,需要单独设计(例如只在宿主条目缺席时才声明)。修复前这条也是丢的,所以本 PR 不会让它变差。验证
npm test:新增test/client-references.test.mjs(9 条),覆盖 factory 的输入(文本拼接、附件顺序含 file、referenceLabels双写、skillNames、extraBlocks、interactive、loadImage透传)、无 factory 时的纯文本 fallback、factory 抛错时仍可读且控件还在。全量 150 项除qa-resolve的 3 项外全部通过;这 3 项在未改动的main上同样失败(它们按本机安装树布局解析真实包,与本次改动无关)。npm run check:package:通过,21 个文件。DSH_HOME+ 官方 0.2.2-rc.1 运行时 + 离线模型夹具,会话首条消息为@README.md what does this file say?):<div class="mtx-bubble">@README.md what does this file say?</div>,[data-ref-chip]= 0,点击无反应;.mtx-content [data-message-bubble]内是<button data-ref-chip="file" title="@README.md">(带文件图标),点击后右侧栏打开该文件(标签页显示完整路径与内容)。