fix(chat): 修复本地文件链接跨平台路径解析 - #422
Merged
Merged
Conversation
三个独立问题导致聊天里模型输出的本地文件链接"可点击但必报错": 1. URL 风格盘符路径 /D:/work/a.zip:裸路径分支缺少 file-url 分支 已有的前导斜杠剥离,Windows 端 Path::is_absolute() 为 false, 报 "The linked path is not valid on this device."。 补 URL_STYLE_DRIVE_PATH_PATTERN 剥离(parse 与 decode 两处)。 2. macOS 家目录路径 ~/release/a.zip:此前判为 relative,Rust 端 join 出 <workdir>/~/... 报 "does not exist"。前端将 ~ 锚定路径 归为 absolute,Rust 端 absolute/file-url 源经 expand_tilde_path 展开;relative 源保持字面量,工作区内名为 "~" 的目录不受影响。 3. 压缩包(zip/7z/tar/gz 等)不在任何动作名单,双平台一律 "cannot be opened safely"。新增 ARCHIVE_EXTENSIONS 归入 reveal(文件管理器定位,不执行)。 chatFileLinks.ts 两端镜像逐字节同步;双端前端测试与 Rust 测试 补齐 /D:/、/d:/、~/、压缩包及字面 "~" 目录回归用例。
StackCairn
marked this pull request as draft
August 10, 2026 09:25
Contributor
|
PR governance checks failed — this PR has been converted to draft.
Fix the items above, then click Ready for review to re-run the checks. |
chatFileLinks.ts 此前在 agent-gui 与 gateway/web 各存一份、 靠人工逐字节同步。迁移到 crates/agent-ui/src/lib/chat/(共享 代码唯一归宿),两端宿主与 agent-ui 内部引用统一改为 @liveagent/ui/lib/chat/chatFileLinks,宿主副本删除。 - agent-ui 内 Markdown/ThinkingActivity/openChatFileLink 改 相对导入,不再经 @liveagent/app 反查宿主 - 双端 chat-file-links 测试改为加载共享模块(按惯例测试保留 双份,守护各自宿主的 prop 链)
Member
Author
|
追加 23472bf:
|
…oss-platform-paths # Conflicts: # crates/agent-gui/src/pages/chat/components/assistant-bubble/RoundContent.tsx # crates/agent-ui/src/components/chat/AssistantBubble.tsx # crates/agent-ui/src/components/chat/assistant-bubble/RoundContent.tsx
yyg-max
approved these changes
Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #421
问题
聊天里模型输出的本地文件引用,三类常见写法点击必报错(详见 issue):
[下载](/D:/workspace/.../a.zip)[查看](~/Desktop/report.pdf).zip/.tar.gz/.7z等压缩包修改
前端
chatFileLinks.ts(agent-gui 与 gateway/web 两端镜像,逐字节同步)URL_STYLE_DRIVE_PATH_PATTERN:裸路径分支与 payload decode 分支补/D:/... → D:/...前导斜杠剥离,与 file-url 分支既有行为对齐HOME_ANCHORED_PATH_PATTERN:~/~/...归类为absolute(在会话归属设备上解析,由 host 展开)Rust
chat_file_links.rsabsolute/file-url源的链接路径经expand_tilde_path展开;relative源保持字面量,工作区内名为~的目录仍按相对路径 join,不受影响ARCHIVE_EXTENSIONS(zip、7z、rar、tar、gz、tgz、bz2、xz、zst 等):归入revealed动作,在文件管理器中定位而非执行,也不再兜底拒绝安全性
^\/[a-zA-Z]:\/精确形态,C:drive-relative.txt(盘符相对路径)仍被拒绝,拒绝测试集不变open -R/explorer /select,),不 launch;EXECUTABLE 语义未动~展开只在 absolute/file-url 源生效,relative 源行为与之前完全一致测试
crates/agent-gateway/web:node --test test/*.test.mjs→ 326 passcrates/agent-gui:node --test test/chat/*.test.mjs→ 567 passcargo test --lib chat_file_links→ 9 pass(新增压缩包 reveal、~展开 + 字面~目录回归)tsc --noEmit、biome、rustfmt 均通过/D:/...、/d:/...(小写盘符)、~/release/a.zip、~/work/a.ts:12已知不修(有意)
%USERPROFILE%/$HOME环境变量形态不展开(注入面大、收益低),维持 "does not exist"D:/...报 "not valid on this device" 是正确语义(文件确实不在该设备)