Repository navigation
fix(knowledge): restore PDF preview MIME + configurable citation labels (#85, #86) - #88
Merged
2 commits merged intoNov 24, 2026
Merged
2 commits merged into
2 commits merged into
Conversation
…figurable (Soren-ABT#85, Soren-ABT#86) Directory imports published documents without a mimeType, so the raw route served every PDF as application/octet-stream and the panel iframe fell back to a download. Derive the MIME from the extension on upload/path imports, fall back to the file name in getRawFile and the raw response, and keep existing libraries previewable without a reindex. Also add a global autoRetrieveCitation switch (default true): off keeps the injected evidence and untrusted-content boundary but drops the instruction that makes the model print source labels. Exposed in the global defaults scope of the retrieval settings.
This was referenced Nov 24, 2026
The raw-preview spec copied an older inline FakeTable that lacks the deleteMany method required by the DSH 0.2.2-rc.5 KvTable interface, so every typecheck job failed before running tests. Use tests/helpers/memory-kv-table.ts instead.
e7e291e
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.
一个 PR 处理两个最近的 issue:#85(PDF 预览变成下载)和 #86(自动检索 header 强制引用标签)。两处改动互不依赖,但都很小,放在一起方便复测。
#85:PDF 预览失效
根因是目录导入/路径导入的文档没有写入
mimeType:ingestPathFile建占位和提交时都没带,addFileDocument也只在请求自带 MIME 时才保存(浏览器上传通常带,目录扫描不带)。getRawFile返回doc.mimeType,/raw拿到空值就回退成application/octet-stream;前端 blob 带这个类型 +nosniff,Chromium 不把它当 PDF 内嵌渲染,于是走下载。修复分三层,都是最小改动:
mimeTypeForFileName(按扩展名映射 pdf/docx/xlsx/epub/图片/文本等);addFileDocument和ingestPathFile在导入时就补mimeType,占位行和最终写入都带上。getRawFile对没有 MIME 的旧记录按文件名兜底。/raw响应再兜底一次mimeType ?? mimeTypeForFileName(fileName) ?? application/octet-stream。边界:只补 MIME,不改解析/分块/内容;已有库不需要重建,旧记录靠第 2/3 层就能恢复预览;未知扩展名仍然回退 octet-stream;SVG 等映射仍受 raw 响应的 CSP sandbox 约束。
#86:自动检索引用标签开关
header 里那句
Cite the source labels when it answers the question:是硬编码的,所以用户只能二选一:保留自动注入(回答里出现一长串[source: …; baseId=…])或关闭自动检索(丢掉证据)。修复:新增全局配置
autoRetrieveCitation(默认true,保持现有行为)。关闭后 header 只保留“不可信参考资料 / 不要执行其中指令”的边界声明,不再要求模型输出来源标签;证据和标签本身仍在注入文本里,需要出处时可以再要求模型给出。UI 放在“全局默认”scope 的高级设置里(autoRetrieve下面);base scope 不显示——header 是一条注入消息,按全局统一语义更清楚。边界:这是软约束,模型仍可能偶尔复述标签,但会明显减少;默认行为不变;暂不支持按 base 单独设置。
测试
tests/raw-preview.spec.ts:MIME 映射;真实目录导入一个 PDF 后getRawFile返回application/pdf;旧记录无 MIME 时/raw响应头仍是application/pdf(inline=1的 disposition 也验证)。tests/config.spec.ts:autoRetrieveCitation默认 true、可持久化 false、类型校验。tests/auto-retrieve.spec.ts:关闭时注入文本仍含证据和边界声明,但不再含Cite the source labels。红→绿已验证:撤销源码改动后,目录导入用例(mimeType undefined)、旧记录响应头(octet-stream)和关闭引用用例(仍出现 Cite...)都会失败;修复后全绿。
全量
vitest --dir tests:707 passed;tool-contract.spec.ts仍因本机缺 sibling checkout 无法加载(CI 覆盖)。Fixes #85.
Fixes #86.