feat(docwall): .univer 产物文稿视图预览——内嵌 univer-office Viewer - #95
Merged
Merged
Conversation
document-preview 的 Univer Viewer 渲染器需要文件系统绝对路径作 file key (univer-office Gateway 以绝对路径 base64url 定位 .univer 文件)。 不走内容寻址快照目录(无后缀 Gateway 拒收),统一解析节点工作区原始文件: 已结束运行沿 artifactIndex 的 relativePath 定位(断点续跑沿 resumedFrom 祖先链回退), 运行中按 file 名解析;路径校验(resolveInside + realpath)与 /wf1/api/artifact 同款, 仅 .univer 后缀,防止暴露任意工作区文件路径。
注册 univer kind(application/x-univer),新增 renderers/univer.jsx: /univer-api/status 发现 Gateway(端口漂移所以现查不缓存)→ /wf1/api/univer/resolve 换绝对路径 → /uf/<key>/worktrees 选 worktree (draft 最新优先)→ mode=embedded iframe 打开。纯 URL 集成不 import univer-office 任何值,构建纯度门无感;未装插件时 404 降级为提示 + 现有下载路径。 纯函数(fileKeyOf/pickWorktree/resolveEndpointOf)抽到 univer-core.js 供 node --test 直测。实机 E2E:真实工作流产出的支出表 .univer 在 iframe 完整渲染 (公式/格式/合计全对)。
自审发现两处缺陷: 1. fileKeyOf 用了 Node Buffer——该代码跑在浏览器,Vite 不注入,运行时 ReferenceError。改纯 Web API(TextEncoder + btoa),测试补中文名路径。 2. dsh 重启后 Gateway 是 stopped,/univer-api/status 不拉起,首次点击必报 「Gateway 未运行」。改为先 POST /univer-api/gateway/start(幂等,运行中 reused=true)再取地址,dsh 重启后首次点击即可用。 浏览器上下文实机复验:重启 dsh → Gateway stopped → renderer 同款代码链路 (resolve → start → worktrees → iframe)渲染支出表成功。
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.
背景
dsh-univer-office 集成调研(#无 issue,会话决策)确认:agent 节点可零代码使用 univer_* 工具产出 .univer 办公文档,但文稿视图对 .univer 只能下载不能预览。本 PR 打通最后一环:点开 .univer 产物直接内嵌 univer-office 自带 Viewer 预览/编辑。
方案
纯 URL/iframe 集成,零跨插件依赖(构建纯度门无感):
GET /wf1/api/univer/resolve,按 run+node+file 把 .univer 产物解析为节点工作区原始文件的绝对路径(Viewer file key = 绝对路径 base64url)。已结束运行沿 artifactIndex.relativePath 精确定位,断点续跑沿 resumedFrom 祖先链回退,运行中按名解析。路径校验与 /wf1/api/artifact 同款(resolveInside + realpath),仅 .univer 后缀。univerkind;新渲染器三步拼 Viewer URL——/univer-api/status发现 Gateway(端口会漂移,现查不缓存)→ resolve 换绝对路径 → Gateway/uf/<key>/worktrees选 worktree(draft 最新优先;实测不带 worktree 显示「空文件」,因 agent 产物在 draft 未合入 trunk)→mode=embeddediframe。未装 univer-office 时 404 降级为提示 + 现有下载路径。验证
build-web.sh双构建 ✅风险与边界