fix(knowledge): 修复 PDF 转 Markdown 图片未提取持久化 + 前端渲染增强 - #540
Merged
Conversation
MCP 工具 parse_pdf_to_markdown 返回的图片数据位于 structuredContent.image_assets 中(含 resource_uri), 但提取管线未处理此来源,导致图片从未上传至 GCS。 - mcp_client: 扫描 structuredContent.image_assets[].resource_uri 加入资源解析队列,通过 resources/read 同会话拉取 - extraction: 新增 _extract_structured_image_assets 函数, 从 payload.image_assets 提取资产并匹配 resolved_resources 中的二进制数据,集成到资产合并链 🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
- 图片组件三态管理(loading/loaded/error),失败时显示占位符 含图标和 alt text,替代原来的 display:none 隐藏 - 图片加载状态 spinner 指示器和 figcaption 标题显示 - 添加 rehype-highlight 代码块语法高亮支持 - 表格外层添加 border 和圆角,提升视觉层次 🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
1. 将 rehypeHighlight 从共享 defaultRehypePlugins 移至 DocumentMarkdownRenderer 局部, 避免对 MessageBubble/McpServerCard 等其他 Markdown 渲染组件产生不必要的副作用; 2. 新增 highlight-theme.css,在 @import github.css 基础上补充 .dark 作用域的暗色覆写, 修复暗色模式下 .hljs { color: #24292e } 导致深色文字在深色背景上不可见的问题。 🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
将 highlight.js 由 rehype-highlight 的传递依赖提升为直接依赖。 原因:highlight-theme.css 内部 @import 'highlight.js/styles/github.css', 经 PostCSS/Turbopack 解析时仅查找顶层 node_modules/highlight.js, 而 pnpm 默认不提升传递依赖,导致 CI 构建报 Can't resolve。 显式声明为直接依赖后顶层软链生效,本地 next build 验证通过。 🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
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.
Summary
parse_pdf_to_markdown返回的图片数据位于structuredContent.image_assets(含resource_uri),但提取管线未处理此来源,导致图片从未上传至 GCS背景
ASSET_NOT_FOUND),代码块无语法着色,图片失败时被display:none直接隐藏核心变更
后端(图片提取修复)
mcp_client.py:在资源解析阶段扫描structuredContent.image_assets[].resource_uri,加入resources/read同会话拉取队列extraction.py:新增_extract_structured_image_assets函数,从payload.image_assets提取资产元数据并匹配resolved_resources中的二进制载荷,集成到四层资产合并链前端(渲染增强)
DocumentMarkdownRenderer.tsx:提取DocumentImage为独立 React 组件,实现 loading/loaded/error 三态管理,图片失败时显示图标 + alt text 占位符markdown-plugins.ts:添加rehype-highlight实现代码块语法高亮风险与回滚
resource_uri(如perceives://pdf/...)的时效性取决于 MCP 会话生命周期;若resources/read失败,图片会标记resource_read_failed并显示前端占位符git revert即可;已提取的文档可通过 "Re-Parse from GCS" 按钮重新触发验证证据
test_extraction_image_assets.py全部 60 个用例通过影响范围
DocumentMarkdownRenderer、markdown-plugins、package.json(新增 rehype-highlight)mcp_client.py(资源解析扩展)、extraction.py(新增提取函数 + 合并链集成)Test plan
uv run pytest tests/unit_tests/knowledge/test_extraction_image_assets.py🤖 Generated with Claude Code, CodeX, Gemini