dsh-knowhub 0.8.7 → 0.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -5
- package/lib/client/index.js +1 -1
- package/lib/host/review/route.js +39 -55
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
**知识库与作用域**
|
|
12
12
|
|
|
13
|
-
-
|
|
13
|
+
- 用户级知识库(跨工作区共享)与工作区级知识库(仅当前项目可见);检索与上下文注入按工作区作用域隔离,审核队列与知识库列表覆盖本地全部知识库。
|
|
14
14
|
- 每个知识库可绑定不同的模型与生成策略(economy / balanced / quality),初始化、提炼、增量都使用库绑定的模型。
|
|
15
15
|
- 创建后可修改名称、模型与策略,不影响已有知识与版本历史;编辑配置里可先「测试模型」确认该模型当前可调通。
|
|
16
16
|
- 模型输出被截断(推理模型把 token 预算消耗在思考过程)时,任务会自动加倍预算重试一次;仍失败会明确提示换用非推理模型或调高「模型使用策略」。
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
|
|
36
36
|
**审核与版本**
|
|
37
37
|
|
|
38
|
-
-
|
|
38
|
+
- 待审核队列分候选、冲突、草稿、过时四类,覆盖本地全部知识库(用户级 + 各工作区),真实计数、关键字/类型/来源筛选与排序。
|
|
39
39
|
- 支持单条与批量审批(单次最多 50 条)、编辑后批准、冲突人工合并。
|
|
40
40
|
- 候选与冲突提供文档对比页:绿色新增、红色删除,行内词元高亮,统一视图与并排视图,改动处导航。
|
|
41
41
|
- 版本历史可查看、对比与恢复,恢复同样以新版本追加,可回退。
|
|
@@ -81,7 +81,7 @@ dsh --profile knowhub --port 29961 --no-open
|
|
|
81
81
|
|
|
82
82
|
```powershell
|
|
83
83
|
# tarball
|
|
84
|
-
& dsh plugin --profile knowhub add .\dsh-knowhub-0.8.
|
|
84
|
+
& dsh plugin --profile knowhub add .\dsh-knowhub-0.8.8.tgz
|
|
85
85
|
|
|
86
86
|
# 开发期:软链到源码目录,构建后重启即生效
|
|
87
87
|
cmd /c mklink /J "$env:USERPROFILE\.dsh\profiles\knowhub\node_modules\dsh-knowhub" "C:\path\to\KnowHub"
|
|
@@ -118,7 +118,7 @@ cmd /c mklink /J "$env:USERPROFILE\.dsh\profiles\knowhub\node_modules\dsh-knowhu
|
|
|
118
118
|
| 知识卡片 | 决策 / 约定 / 问题 / 待办四类知识,类型与状态过滤,列表 + 阅读器 |
|
|
119
119
|
| 记忆 | 记忆 / 偏好两类知识,类型与状态过滤,列表 + 阅读器 |
|
|
120
120
|
| 知识库 | 知识库列表(固定列出全部:用户级 + 各工作区,不做工作区筛选)+ 详情:新建与编辑配置(含「测试模型」)、初始化与增量任务(进度 / 日志 / 取消 / 重试)、项目索引、模型调用记录、知识列表分页、导出全部、导入 Markdown、删除 |
|
|
121
|
-
| 待审核 | 候选 / 冲突 / 草稿 /
|
|
121
|
+
| 待审核 | 候选 / 冲突 / 草稿 / 过时四类队列(覆盖本地全部知识库,不按当前工作区过滤),真实计数、筛选、排序、批量审批;点「查看详情与差异」进入文档对比页;版本历史与审核日志 |
|
|
122
122
|
| 检索 | 关键词 + 标签 + 知识库 / 类型 / 状态 / 排序;显示来源、作用域、审核状态与检索模式;结果分页加载 |
|
|
123
123
|
| 设置 | 默认策略、提炼开关与阈值、审核人与自动批准、知识注入开关与预算、备份保留、排除目录、存储位置迁移、备份预览与恢复、诊断信息 |
|
|
124
124
|
|
|
@@ -139,6 +139,10 @@ cmd /c mklink /J "$env:USERPROFILE\.dsh\profiles\knowhub\node_modules\dsh-knowhu
|
|
|
139
139
|
|
|
140
140
|
自动生成、增量更新、Agent 提议、自动提炼、Markdown 导入的结果一律先落为草稿或候选,必须人工批准后才成为正式知识。这是为了避免模型臆断污染长期记忆。
|
|
141
141
|
|
|
142
|
+
**生成成功了,待审核里却什么都没有?**
|
|
143
|
+
|
|
144
|
+
先确认宿主进程已经重启:升级插件只替换磁盘文件,正在运行的进程仍用旧代码,必须完全退出并重开 DSH。0.8.8 起待审核队列覆盖本地全部知识库(用户级 + 各工作区),不再只看当前工作区;若仍为空,检查桌面版与开发实例是否指向同一份存储根(「设置 → 存储位置」),以及任务是否真的产出了草稿(知识库详情的任务日志会写明生成篇数)。
|
|
145
|
+
|
|
142
146
|
**已经批准的知识会被增量更新悄悄改掉吗?**
|
|
143
147
|
|
|
144
148
|
不会。已批准知识只会生成「更新候选」进入待审核队列,批准后才以新版本追加,旧版本仍可查看与恢复。
|
|
@@ -203,7 +207,7 @@ knowledge-center/
|
|
|
203
207
|
1. 不读取、不落盘、不打印任何明文密钥;模型调用只传 provider / model,凭据由 DSH 适配层管理。
|
|
204
208
|
2. 扫描默认排除 `.git`、`node_modules`、构建产物、缓存、`.env*`、`*.pem`、`id_rsa` 等敏感文件;不跟随符号链接;不执行被扫描仓库的任何脚本。
|
|
205
209
|
3. 文件访问限制在已注册工作区与当前工作目录内,扫描接口需 realpath 命中授权根。
|
|
206
|
-
4.
|
|
210
|
+
4. 检索与上下文注入的作用域由服务端从会话 `cwd` 反查得出,客户端参数不能扩大检索范围;审核、知识库管理与版本操作是本地单人管理视图,覆盖本地全部未删除知识库(桌面版宿主进程的 `cwd` 是应用目录,按工作区过滤会导致其它工作区的草稿不可见)。
|
|
207
211
|
5. 自动生成的知识默认待审核,批准后才成为正式知识;已批准文档不会被流水线静默覆盖。
|
|
208
212
|
6. 模型输出必须通过结构校验(JSON 解析、类型/长度/置信度范围、敏感信息清洗、绝对路径剔除)才进候选。
|
|
209
213
|
7. Git 只读调用,失败自动降级为内容哈希模式并记录原因。
|
package/lib/client/index.js
CHANGED
|
@@ -2025,7 +2025,7 @@ function ReviewView(props) {
|
|
|
2025
2025
|
const proposalCard = (item) => h('div', { key: item.id, style: styles.card }, h('div', { style: styles.cardTitle }, checkBox('proposal:' + item.id), item.title, h(Badge, { text: PROPOSAL_KIND_LABEL[item.kind] ?? item.kind, style: styles.badgeAmber }), item.docKind ? h(Badge, { text: KIND_LABEL[item.docKind] ?? item.docKind }) : null, h(Badge, { text: '候选 ' + String(item.id).slice(-6) })), h('div', { style: styles.meta }, h('span', null, '知识库:' + (item.kbName ?? item.kbId)), h('span', null, '来源:' + (item.source ?? '—')), h('span', null, '提交人:' + (item.createdBy ?? '—')), h('span', null, '创建于 ' + new Date(item.createdAt).toLocaleString('zh-CN'))), item.reason ? h('div', { style: styles.snippet }, '说明:' + item.reason) : null, h('div', { style: styles.snippet }, String(item.body ?? '').slice(0, 260) + (String(item.body ?? '').length > 260 ? '…' : '')), h('div', { style: styles.field, marginTop: '8px' }, noteInput(item.id)), h('div', { style: styles.row }, h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: () => void openDiff('proposal', item.id) }, '查看详情与差异'), h('button', { type: 'button', style: styles.primary, className: 'kh-primary', disabled: busy !== null, onClick: () => void run('批准候选', () => request('/review/proposals/' + item.id + '/approve', { method: 'POST', body: { note: noteOf(item.id) || null } })) }, '批准'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: () => setProposalEdit({ id: item.id, body: String(item.body ?? ''), title: item.title }) }, '编辑后批准'), h('button', { type: 'button', style: styles.danger, className: 'kh-danger', disabled: busy !== null, onClick: () => void run('拒绝候选', () => request('/review/proposals/' + item.id + '/reject', { method: 'POST', body: { note: noteOf(item.id) || null } })) }, '拒绝')), proposalEdit !== null && proposalEdit.id === item.id ? h('div', { style: styles.field, marginTop: '10px' }, h('label', { style: styles.label }, '修改标题'), h('input', { style: styles.input, value: proposalEdit.title, onChange: (e) => setProposalEdit({ ...proposalEdit, title: e.target.value }) }), h('label', { style: { ...styles.label, marginTop: '8px' } }, '修改正文'), h('textarea', { style: { ...styles.textarea, minHeight: '140px' }, value: proposalEdit.body, onChange: (e) => setProposalEdit({ ...proposalEdit, body: e.target.value }) }), h('div', { style: styles.row }, h('button', { type: 'button', style: styles.primary, className: 'kh-primary', disabled: busy !== null, onClick: () => void run('编辑后批准', () => request('/review/proposals/' + item.id + '/approve', { method: 'POST', body: { note: noteOf(item.id) || '编辑后批准', title: proposalEdit.title, body: proposalEdit.body } }), () => setProposalEdit(null)) }, '保存并批准'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', onClick: () => setProposalEdit(null) }, '取消编辑'))) : null);
|
|
2026
2026
|
return h('div', null, h('div', { style: { ...styles.card, display: 'flex', flexWrap: 'wrap', gap: '8px', alignItems: 'center' } }, h('select', { style: { ...styles.input, width: '200px' }, value: kbFilter, onChange: (e) => { setKbFilter(e.target.value); setPage(1); } }, h('option', { value: '' }, '全部知识库'), (knowledgeBases ?? []).map((kb) => h('option', { key: kb.id, value: kb.id }, kb.name))), h('select', { style: { ...styles.input, width: '150px' }, value: kindFilter, onChange: (e) => { setKindFilter(e.target.value); setPage(1); } }, h('option', { value: '' }, '全部候选类型'), h('option', { value: 'create' }, '新增知识'), h('option', { value: 'update' }, '更新知识'), h('option', { value: 'restore' }, '恢复知识'), h('option', { value: 'stale' }, '标记过时')), h('input', { style: { ...styles.input, width: '200px' }, value: qInput, placeholder: '关键词(标题/正文)', onChange: (e) => setQInput(e.target.value), onKeyDown: (e) => { if (e.key === 'Enter')
|
|
2027
2027
|
applyFilters(); } }), h('input', { style: { ...styles.input, width: '160px' }, value: sourceInput, placeholder: '来源,如 pipeline', onChange: (e) => setSourceInput(e.target.value), onKeyDown: (e) => { if (e.key === 'Enter')
|
|
2028
|
-
applyFilters(); } }), h('select', { style: { ...styles.input, width: '150px' }, value: sort, onChange: (e) => { setSort(e.target.value); setPage(1); } }, h('option', { value: 'newest' }, '最新提交优先'), h('option', { value: 'oldest' }, '最早提交优先'), h('option', { value: 'updated' }, '最近更新优先')), h('button', { type: 'button', style: styles.primary, className: 'kh-primary', disabled: loading, onClick: applyFilters }, '筛选'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', onClick: resetFilters }, '清空'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: loading, onClick: () => void load() }, loading ? '刷新中…' : '刷新'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: () => void openLog() }, '审核日志')), h('div', { style: { ...styles.row, alignItems: 'center', marginTop: '8px' } }, h('span', { style: styles.badgeAmber }, '待审核合计 ' + pendingTotal + ' 项'), h('span', { style: styles.hint }, filterHint + ' · 第 ' + page + ' / ' + maxPages + ' 页(每页最多 ' + LIMIT + ' 条)'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: loading || page <= 1, onClick: () => setPage(page - 1) }, '上一页'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: loading || page >= maxPages, onClick: () => setPage(page + 1) }, '下一页')), selected.length > 0 ? h('div', { style: { ...styles.card, marginTop: '8px', display: 'flex', flexWrap: 'wrap', gap: '8px', alignItems: 'center' } }, h('span', null, '已选 ' + selected.length + ' 条'), h('button', { type: 'button', style: styles.primary, className: 'kh-primary', disabled: busy !== null, onClick: () => void bulkRun('approve') }, '批量批准'), h('button', { type: 'button', style: styles.danger, className: 'kh-danger', disabled: busy !== null, onClick: () => void bulkRun('reject') }, '批量拒绝'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: clearSelection }, '清空选择'), h('span', { style: styles.hint }, '单次最多 ' + LIMIT + ' 条,执行前会二次确认')) : null, busy !== null ? h('div', { style: styles.hint }, busy + '…') : null, error !== null ? h('div', { style: styles.error, role: 'alert' }, error) : null, queue === null ? h('div', { style: styles.empty }, loading ? '正在读取待审核数据…' : '暂无数据') : h('div', null, sectionHead('候选知识', counts.proposals, 'proposal', queue.proposals ?? []), (queue.proposals ?? []).length === 0 ? h('div', { style: styles.empty }, '没有符合条件的候选。Agent 或面板提交的知识会先进入这里。') : (queue.proposals ?? []).map(proposalCard), sectionHead('版本冲突', counts.conflicts), (queue.conflicts ?? []).length === 0 ? h('div', { style: styles.empty }, '没有待处理冲突。') : (queue.conflicts ?? []).map((item) => h('div', { key: item.id, style: styles.card }, h('div', { style: styles.cardTitle }, '冲突:' + (item.proposedTitle ?? item.docId), h(Badge, { text: '待处理', style: styles.badgeAmber })), h('div', { style: styles.meta }, h('span', null, '知识库:' + (item.kbName ?? item.kbId)), h('span', null, '来源:' + (item.source ?? '—')), h('span', null, '基础版本:第 ' + item.baseVersion + ' 版 / 当前:第 ' + item.currentVersion + ' 版'), h('span', null, '检测于 ' + new Date(item.detectedAt).toLocaleString('zh-CN'))), h('div', { style: styles.snippet }, '提议内容:'), h('pre', { style: styles.pre }, String(item.proposedBody ?? '').slice(0, 1600)), h('div', { style: styles.row, marginTop: '8px' }, h('button', { type: 'button', style: styles.button, className: 'kh-hover', onClick: () => void openDiff('conflict', item.id) }, '查看差异'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: () => void run('保留当前', () => request('/review/conflicts/' + item.id + '/resolve', { method: 'POST', body: { mode: 'keep_current' } })) }, '保留当前知识'), h('button', { type: 'button', style: styles.primary, className: 'kh-primary', disabled: busy !== null, onClick: () => void run('采用新提议', () => request('/review/conflicts/' + item.id + '/resolve', { method: 'POST', body: { mode: 'use_proposed' } })) }, '采用新提议(追加合并版本)'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: () => setConflictEdit({ id: item.id, title: String(item.proposedTitle ?? ''), body: String(item.proposedBody ?? '') }) }, '人工合并…')), conflictEdit !== null && conflictEdit.id === item.id ? h('div', { style: styles.field, marginTop: '10px' }, h('label', { style: styles.label }, '合并后标题'), h('input', { style: styles.input, value: conflictEdit.title, onChange: (e) => setConflictEdit({ ...conflictEdit, title: e.target.value }) }), h('label', { style: { ...styles.label, marginTop: '8px' } }, '合并后正文(预填新提议,可自由编辑)'), h('textarea', { style: { ...styles.textarea, minHeight: '180px' }, value: conflictEdit.body, onChange: (e) => setConflictEdit({ ...conflictEdit, body: e.target.value }) }), h('div', { style: styles.row }, h('button', { type: 'button', style: styles.primary, className: 'kh-primary', disabled: busy !== null, onClick: () => void run('保存人工合并', () => request('/review/conflicts/' + item.id + '/resolve', { method: 'POST', body: { mode: 'merge', title: conflictEdit.title, body: conflictEdit.body } }), () => setConflictEdit(null)) }, '保存合并结果'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', onClick: () => setConflictEdit(null) }, '取消合并'))) : null)), sectionHead('待审核草稿', counts.drafts, 'doc', queue.drafts ?? []), (queue.drafts ?? []).length === 0 ? h('div', { style: styles.empty }, '没有符合条件的待审核草稿。') : (queue.drafts ?? []).map((item) => h('div', { key: item.id, style: styles.card }, h('div', { style: styles.cardTitle }, checkBox('doc:' + item.id), item.title, h(Badge, { text: KIND_LABEL[item.kind] ?? item.kind }), h(Badge, { text: VERIFY_LABEL[item.verifyState] ?? item.verifyState }), h(Badge, { text: '第 ' + item.currentVersion + ' 版' })), h('div', { style: styles.meta }, h('span', null, '知识库:' + (item.kbName ?? item.kbId)), h('span', null, '更新于 ' + new Date(item.updatedAt).toLocaleString('zh-CN')), h('span', null, item.path)), h('div', { style: { ...styles.row, marginTop: '8px' } }, h('div', { style: styles.field, flex: '1 1 260px' }, noteInput(item.id))), h('div', { style: styles.row }, h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: () => void openDiff('document', item.id) }, '查看详情与差异'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', onClick: () => void openVersions(item.kbId, item.id) }, '版本历史'), h('button', { type: 'button', style: styles.primary, className: 'kh-primary', disabled: busy !== null, onClick: () => void run('批准草稿', () => request('/kb/' + item.kbId + '/docs/' + item.id + '/review', { method: 'POST', body: { action: 'approve', note: noteOf(item.id) || null } })) }, '批准'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: () => void openDraftEdit(item.kbId, item.id) }, '编辑后批准'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: () => void run('标记过时', () => request('/kb/' + item.kbId + '/docs/' + item.id + '/review', { method: 'POST', body: { action: 'mark_stale', note: noteOf(item.id) || null } })) }, '标记过时'), h('button', { type: 'button', style: styles.danger, className: 'kh-danger', disabled: busy !== null, onClick: () => void run('拒绝草稿', () => request('/kb/' + item.kbId + '/docs/' + item.id + '/review', { method: 'POST', body: { action: 'reject', note: noteOf(item.id) || null } })) }, '拒绝(归档)')))), sectionHead('过时知识', counts.stale), (queue.staleDocuments ?? []).length === 0 ? h('div', { style: styles.empty }, '没有符合条件的过时知识。') : (queue.staleDocuments ?? []).map((item) => h('div', { key: item.id, style: styles.card }, h('div', { style: styles.cardTitle }, item.title, h(Badge, { text: '过时', style: styles.badgeAmber })), h('div', { style: styles.meta }, h('span', null, '知识库:' + (item.kbName ?? item.kbId)), h('span', null, '更新于 ' + new Date(item.updatedAt).toLocaleString('zh-CN'))), h('div', { style: styles.row, marginTop: '8px' }, h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: () => void openDiff('document', item.id) }, '查看详情与差异'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', onClick: () => void openVersions(item.kbId, item.id) }, '版本历史'), h('button', { type: 'button', style: styles.primary, className: 'kh-primary', disabled: busy !== null, onClick: () => void run('恢复为已批准', () => request('/kb/' + item.kbId + '/docs/' + item.id + '/review', { method: 'POST', body: { action: 'approve', note: '确认内容仍有效' } })) }, '确认仍有效(恢复已批准)')))), maxPages > 1 ? h('div', { style: { ...styles.row, marginTop: '10px' } }, h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: loading || page <= 1, onClick: () => setPage(page - 1) }, '上一页'), h('span', { style: styles.hint }, '第 ' + page + ' / ' + maxPages + ' 页'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: loading || page >= maxPages, onClick: () => setPage(page + 1) }, '下一页')) : null), draftEdit !== null ? h('div', { style: styles.divider }, h('div', { style: styles.sectionTitle }, '编辑后批准草稿(将在第 ' + Number(draftEdit.version ?? 0) + ' 版基础上生成审核版本)'), h('label', { style: styles.label }, '标题'), h('input', { style: styles.input, value: draftEdit.title, onChange: (e) => setDraftEdit({ ...draftEdit, title: e.target.value }) }), h('label', { style: { ...styles.label, marginTop: '8px' } }, '正文(Markdown)'), h('textarea', { style: { ...styles.textarea, minHeight: '220px' }, value: draftEdit.body, onChange: (e) => setDraftEdit({ ...draftEdit, body: e.target.value }) }), h('div', { style: styles.row, marginTop: '8px' }, h('button', { type: 'button', style: styles.primary, className: 'kh-primary', disabled: busy !== null, onClick: () => void run('编辑并批准草稿', () => request('/kb/' + draftEdit.kbId + '/docs/' + draftEdit.docId + '/review', { method: 'POST', body: { action: 'approve', title: draftEdit.title, body: draftEdit.body, note: '审核时编辑后批准' } }), () => setDraftEdit(null)) }, '保存并批准'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', onClick: () => setDraftEdit(null) }, '取消'))) : null, docPanel !== null ? h('div', { style: styles.divider }, h('div', { style: styles.sectionTitle }, '版本历史(共 ' + docPanel.versions.length + ' 版,当前第 ' + docPanel.currentVersion + ' 版)'), docPanel.versions.map((item) => h('div', { key: item.version, style: styles.card }, h('div', { style: styles.cardTitle }, '第 ' + item.version + ' 版', h(Badge, { text: CHANGE_KIND_LABEL[item.changeKind] ?? item.changeKind }), item.version === docPanel.currentVersion ? h(Badge, { text: '当前', style: styles.badgeGreen }) : null), h('div', { style: styles.meta }, h('span', null, '来源:' + (item.source ?? '—')), h('span', null, '操作人:' + (item.actor ?? '—')), h('span', null, '时间:' + new Date(item.createdAt).toLocaleString('zh-CN'))), item.reason ? h('div', { style: styles.snippet }, '说明:' + item.reason) : null, h('div', { style: styles.row, marginTop: '8px' }, h('button', { type: 'button', style: styles.button, className: 'kh-hover', onClick: async () => {
|
|
2028
|
+
applyFilters(); } }), h('select', { style: { ...styles.input, width: '150px' }, value: sort, onChange: (e) => { setSort(e.target.value); setPage(1); } }, h('option', { value: 'newest' }, '最新提交优先'), h('option', { value: 'oldest' }, '最早提交优先'), h('option', { value: 'updated' }, '最近更新优先')), h('button', { type: 'button', style: styles.primary, className: 'kh-primary', disabled: loading, onClick: applyFilters }, '筛选'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', onClick: resetFilters }, '清空'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: loading, onClick: () => void load() }, loading ? '刷新中…' : '刷新'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: () => void openLog() }, '审核日志')), h('div', { style: { ...styles.hint, marginTop: '8px' } }, '审核队列覆盖本地全部知识库(用户级 + 各工作区),不按当前工作区过滤;检索与上下文注入仍按工作区隔离。'), h('div', { style: { ...styles.row, alignItems: 'center', marginTop: '8px' } }, h('span', { style: styles.badgeAmber }, '待审核合计 ' + pendingTotal + ' 项'), h('span', { style: styles.hint }, filterHint + ' · 第 ' + page + ' / ' + maxPages + ' 页(每页最多 ' + LIMIT + ' 条)'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: loading || page <= 1, onClick: () => setPage(page - 1) }, '上一页'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: loading || page >= maxPages, onClick: () => setPage(page + 1) }, '下一页')), selected.length > 0 ? h('div', { style: { ...styles.card, marginTop: '8px', display: 'flex', flexWrap: 'wrap', gap: '8px', alignItems: 'center' } }, h('span', null, '已选 ' + selected.length + ' 条'), h('button', { type: 'button', style: styles.primary, className: 'kh-primary', disabled: busy !== null, onClick: () => void bulkRun('approve') }, '批量批准'), h('button', { type: 'button', style: styles.danger, className: 'kh-danger', disabled: busy !== null, onClick: () => void bulkRun('reject') }, '批量拒绝'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: clearSelection }, '清空选择'), h('span', { style: styles.hint }, '单次最多 ' + LIMIT + ' 条,执行前会二次确认')) : null, busy !== null ? h('div', { style: styles.hint }, busy + '…') : null, error !== null ? h('div', { style: styles.error, role: 'alert' }, error) : null, queue === null ? h('div', { style: styles.empty }, loading ? '正在读取待审核数据…' : '暂无数据') : h('div', null, sectionHead('候选知识', counts.proposals, 'proposal', queue.proposals ?? []), (queue.proposals ?? []).length === 0 ? h('div', { style: styles.empty }, '没有符合条件的候选。Agent 或面板提交的知识会先进入这里。') : (queue.proposals ?? []).map(proposalCard), sectionHead('版本冲突', counts.conflicts), (queue.conflicts ?? []).length === 0 ? h('div', { style: styles.empty }, '没有待处理冲突。') : (queue.conflicts ?? []).map((item) => h('div', { key: item.id, style: styles.card }, h('div', { style: styles.cardTitle }, '冲突:' + (item.proposedTitle ?? item.docId), h(Badge, { text: '待处理', style: styles.badgeAmber })), h('div', { style: styles.meta }, h('span', null, '知识库:' + (item.kbName ?? item.kbId)), h('span', null, '来源:' + (item.source ?? '—')), h('span', null, '基础版本:第 ' + item.baseVersion + ' 版 / 当前:第 ' + item.currentVersion + ' 版'), h('span', null, '检测于 ' + new Date(item.detectedAt).toLocaleString('zh-CN'))), h('div', { style: styles.snippet }, '提议内容:'), h('pre', { style: styles.pre }, String(item.proposedBody ?? '').slice(0, 1600)), h('div', { style: styles.row, marginTop: '8px' }, h('button', { type: 'button', style: styles.button, className: 'kh-hover', onClick: () => void openDiff('conflict', item.id) }, '查看差异'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: () => void run('保留当前', () => request('/review/conflicts/' + item.id + '/resolve', { method: 'POST', body: { mode: 'keep_current' } })) }, '保留当前知识'), h('button', { type: 'button', style: styles.primary, className: 'kh-primary', disabled: busy !== null, onClick: () => void run('采用新提议', () => request('/review/conflicts/' + item.id + '/resolve', { method: 'POST', body: { mode: 'use_proposed' } })) }, '采用新提议(追加合并版本)'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: () => setConflictEdit({ id: item.id, title: String(item.proposedTitle ?? ''), body: String(item.proposedBody ?? '') }) }, '人工合并…')), conflictEdit !== null && conflictEdit.id === item.id ? h('div', { style: styles.field, marginTop: '10px' }, h('label', { style: styles.label }, '合并后标题'), h('input', { style: styles.input, value: conflictEdit.title, onChange: (e) => setConflictEdit({ ...conflictEdit, title: e.target.value }) }), h('label', { style: { ...styles.label, marginTop: '8px' } }, '合并后正文(预填新提议,可自由编辑)'), h('textarea', { style: { ...styles.textarea, minHeight: '180px' }, value: conflictEdit.body, onChange: (e) => setConflictEdit({ ...conflictEdit, body: e.target.value }) }), h('div', { style: styles.row }, h('button', { type: 'button', style: styles.primary, className: 'kh-primary', disabled: busy !== null, onClick: () => void run('保存人工合并', () => request('/review/conflicts/' + item.id + '/resolve', { method: 'POST', body: { mode: 'merge', title: conflictEdit.title, body: conflictEdit.body } }), () => setConflictEdit(null)) }, '保存合并结果'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', onClick: () => setConflictEdit(null) }, '取消合并'))) : null)), sectionHead('待审核草稿', counts.drafts, 'doc', queue.drafts ?? []), (queue.drafts ?? []).length === 0 ? h('div', { style: styles.empty }, '没有符合条件的待审核草稿。') : (queue.drafts ?? []).map((item) => h('div', { key: item.id, style: styles.card }, h('div', { style: styles.cardTitle }, checkBox('doc:' + item.id), item.title, h(Badge, { text: KIND_LABEL[item.kind] ?? item.kind }), h(Badge, { text: VERIFY_LABEL[item.verifyState] ?? item.verifyState }), h(Badge, { text: '第 ' + item.currentVersion + ' 版' })), h('div', { style: styles.meta }, h('span', null, '知识库:' + (item.kbName ?? item.kbId)), h('span', null, '更新于 ' + new Date(item.updatedAt).toLocaleString('zh-CN')), h('span', null, item.path)), h('div', { style: { ...styles.row, marginTop: '8px' } }, h('div', { style: styles.field, flex: '1 1 260px' }, noteInput(item.id))), h('div', { style: styles.row }, h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: () => void openDiff('document', item.id) }, '查看详情与差异'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', onClick: () => void openVersions(item.kbId, item.id) }, '版本历史'), h('button', { type: 'button', style: styles.primary, className: 'kh-primary', disabled: busy !== null, onClick: () => void run('批准草稿', () => request('/kb/' + item.kbId + '/docs/' + item.id + '/review', { method: 'POST', body: { action: 'approve', note: noteOf(item.id) || null } })) }, '批准'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: () => void openDraftEdit(item.kbId, item.id) }, '编辑后批准'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: () => void run('标记过时', () => request('/kb/' + item.kbId + '/docs/' + item.id + '/review', { method: 'POST', body: { action: 'mark_stale', note: noteOf(item.id) || null } })) }, '标记过时'), h('button', { type: 'button', style: styles.danger, className: 'kh-danger', disabled: busy !== null, onClick: () => void run('拒绝草稿', () => request('/kb/' + item.kbId + '/docs/' + item.id + '/review', { method: 'POST', body: { action: 'reject', note: noteOf(item.id) || null } })) }, '拒绝(归档)')))), sectionHead('过时知识', counts.stale), (queue.staleDocuments ?? []).length === 0 ? h('div', { style: styles.empty }, '没有符合条件的过时知识。') : (queue.staleDocuments ?? []).map((item) => h('div', { key: item.id, style: styles.card }, h('div', { style: styles.cardTitle }, item.title, h(Badge, { text: '过时', style: styles.badgeAmber })), h('div', { style: styles.meta }, h('span', null, '知识库:' + (item.kbName ?? item.kbId)), h('span', null, '更新于 ' + new Date(item.updatedAt).toLocaleString('zh-CN'))), h('div', { style: styles.row, marginTop: '8px' }, h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: busy !== null, onClick: () => void openDiff('document', item.id) }, '查看详情与差异'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', onClick: () => void openVersions(item.kbId, item.id) }, '版本历史'), h('button', { type: 'button', style: styles.primary, className: 'kh-primary', disabled: busy !== null, onClick: () => void run('恢复为已批准', () => request('/kb/' + item.kbId + '/docs/' + item.id + '/review', { method: 'POST', body: { action: 'approve', note: '确认内容仍有效' } })) }, '确认仍有效(恢复已批准)')))), maxPages > 1 ? h('div', { style: { ...styles.row, marginTop: '10px' } }, h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: loading || page <= 1, onClick: () => setPage(page - 1) }, '上一页'), h('span', { style: styles.hint }, '第 ' + page + ' / ' + maxPages + ' 页'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', disabled: loading || page >= maxPages, onClick: () => setPage(page + 1) }, '下一页')) : null), draftEdit !== null ? h('div', { style: styles.divider }, h('div', { style: styles.sectionTitle }, '编辑后批准草稿(将在第 ' + Number(draftEdit.version ?? 0) + ' 版基础上生成审核版本)'), h('label', { style: styles.label }, '标题'), h('input', { style: styles.input, value: draftEdit.title, onChange: (e) => setDraftEdit({ ...draftEdit, title: e.target.value }) }), h('label', { style: { ...styles.label, marginTop: '8px' } }, '正文(Markdown)'), h('textarea', { style: { ...styles.textarea, minHeight: '220px' }, value: draftEdit.body, onChange: (e) => setDraftEdit({ ...draftEdit, body: e.target.value }) }), h('div', { style: styles.row, marginTop: '8px' }, h('button', { type: 'button', style: styles.primary, className: 'kh-primary', disabled: busy !== null, onClick: () => void run('编辑并批准草稿', () => request('/kb/' + draftEdit.kbId + '/docs/' + draftEdit.docId + '/review', { method: 'POST', body: { action: 'approve', title: draftEdit.title, body: draftEdit.body, note: '审核时编辑后批准' } }), () => setDraftEdit(null)) }, '保存并批准'), h('button', { type: 'button', style: styles.button, className: 'kh-hover', onClick: () => setDraftEdit(null) }, '取消'))) : null, docPanel !== null ? h('div', { style: styles.divider }, h('div', { style: styles.sectionTitle }, '版本历史(共 ' + docPanel.versions.length + ' 版,当前第 ' + docPanel.currentVersion + ' 版)'), docPanel.versions.map((item) => h('div', { key: item.version, style: styles.card }, h('div', { style: styles.cardTitle }, '第 ' + item.version + ' 版', h(Badge, { text: CHANGE_KIND_LABEL[item.changeKind] ?? item.changeKind }), item.version === docPanel.currentVersion ? h(Badge, { text: '当前', style: styles.badgeGreen }) : null), h('div', { style: styles.meta }, h('span', null, '来源:' + (item.source ?? '—')), h('span', null, '操作人:' + (item.actor ?? '—')), h('span', null, '时间:' + new Date(item.createdAt).toLocaleString('zh-CN'))), item.reason ? h('div', { style: styles.snippet }, '说明:' + item.reason) : null, h('div', { style: styles.row, marginTop: '8px' }, h('button', { type: 'button', style: styles.button, className: 'kh-hover', onClick: async () => {
|
|
2029
2029
|
setError(null);
|
|
2030
2030
|
try {
|
|
2031
2031
|
const value = await request('/kb/' + encodeURIComponent(docPanel.kbId) + '/docs/' + encodeURIComponent(docPanel.docId) + '/versions/' + item.version);
|
package/lib/host/review/route.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* M3 审核 HTTP 接口(前缀 /knowhub/api)。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* 作用域:审核是「人」对本地知识库的管理动作,因此队列、详情、差异、冲突与批量覆盖
|
|
5
|
+
* 所有未删除的知识库(用户级 + 各工作区),不按当前工作区过滤——桌面版宿主进程的 cwd 是
|
|
6
|
+
* 应用目录,反查不到工作区,按工作区过滤会让其它工作区的草稿/候选完全不可见。
|
|
7
|
+
* 检索与上下文注入仍按工作区隔离(scope.ts / search.ts),不受本文件影响。
|
|
6
8
|
*/
|
|
7
9
|
import { errorMessage, readBody, writeError, writeOk } from '../http.js';
|
|
8
10
|
import { all, openDatabase } from '../db/db.js';
|
|
@@ -16,14 +18,17 @@ import { resolveScope } from '../scope.js';
|
|
|
16
18
|
function str(value) {
|
|
17
19
|
return typeof value === 'string' ? value.trim() : '';
|
|
18
20
|
}
|
|
19
|
-
|
|
21
|
+
/** 审核覆盖本地全部知识库,这里只校验存在性(没有工作区范围限制)。 */
|
|
22
|
+
function assertKb(db, id) {
|
|
20
23
|
const kb = getKnowledgeBase(db, id);
|
|
21
24
|
if (!kb)
|
|
22
25
|
throw new ReviewError('KB_NOT_FOUND', 404, '知识库不存在:' + id);
|
|
23
|
-
if (!scopeKeys.includes(kb.scopeKey))
|
|
24
|
-
throw new ReviewError('KB_FORBIDDEN', 403, '该知识库不在当前工作区的授权作用域内:' + id);
|
|
25
26
|
return kb;
|
|
26
27
|
}
|
|
28
|
+
/** 本地全部未删除知识库的 id:审核队列与日志的统计范围。 */
|
|
29
|
+
function allKbIds(db) {
|
|
30
|
+
return all(db, 'SELECT id FROM knowledge_bases WHERE deleted_at IS NULL').map((row) => String(row.id));
|
|
31
|
+
}
|
|
27
32
|
/** 组装「当前已批准内容 → 提议内容」的行级差异,供面板对比页直接渲染。 */
|
|
28
33
|
function buildDiffPayload(input) {
|
|
29
34
|
// 新增知识没有基线正文:整体视为新增,避免与空行做 LCS 时出现「未变」的错觉。
|
|
@@ -76,12 +81,12 @@ export async function handleReviewRequest(request) {
|
|
|
76
81
|
if (method === 'GET' && path === '/review') {
|
|
77
82
|
const scope = await resolveScope(ctx, process.cwd());
|
|
78
83
|
const handle = db();
|
|
79
|
-
const kbIds =
|
|
84
|
+
const kbIds = allKbIds(handle);
|
|
80
85
|
const kbId = str(url.searchParams.get('kbId'));
|
|
81
86
|
let target = kbIds;
|
|
82
87
|
if (kbId !== '') {
|
|
83
88
|
if (!kbIds.includes(kbId))
|
|
84
|
-
throw new ReviewError('
|
|
89
|
+
throw new ReviewError('KB_NOT_FOUND', 404, '知识库不存在:' + kbId);
|
|
85
90
|
target = [kbId];
|
|
86
91
|
}
|
|
87
92
|
const queue = reviewQueue(handle, target, {
|
|
@@ -96,23 +101,21 @@ export async function handleReviewRequest(request) {
|
|
|
96
101
|
return true;
|
|
97
102
|
}
|
|
98
103
|
if (method === 'GET' && path === '/review/log') {
|
|
99
|
-
const scope = await resolveScope(ctx, process.cwd());
|
|
100
104
|
const handle = db();
|
|
101
|
-
const kbIds =
|
|
105
|
+
const kbIds = allKbIds(handle);
|
|
102
106
|
writeOk(res, { entries: listReviewLog(handle, { kbIds, limit: Number(url.searchParams.get('limit') ?? 50) || 50 }) });
|
|
103
107
|
return true;
|
|
104
108
|
}
|
|
105
109
|
const proposalDetail = /^\/review\/proposals\/([^/]+)$/.exec(path);
|
|
106
110
|
if (proposalDetail && method === 'GET') {
|
|
107
|
-
const scope = await resolveScope(ctx, process.cwd());
|
|
108
111
|
const handle = db();
|
|
109
112
|
const id = decodeURIComponent(proposalDetail[1] ?? '');
|
|
110
113
|
const proposal = getProposal(handle, id);
|
|
111
114
|
if (!proposal)
|
|
112
115
|
throw new ReviewError('PROPOSAL_NOT_FOUND', 404, '候选不存在:' + id);
|
|
113
116
|
const kb = getKnowledgeBase(handle, proposal.kbId);
|
|
114
|
-
if (!kb
|
|
115
|
-
throw new ReviewError('
|
|
117
|
+
if (!kb)
|
|
118
|
+
throw new ReviewError('KB_NOT_FOUND', 404, '候选所属知识库不存在:' + proposal.kbId);
|
|
116
119
|
const doc = proposal.docId ? getDocument(handle, proposal.docId) : null;
|
|
117
120
|
const currentDiff = doc ? diffVersions(handle, doc, null, null) : null;
|
|
118
121
|
writeOk(res, { proposal, document: doc, currentDiff });
|
|
@@ -120,15 +123,14 @@ export async function handleReviewRequest(request) {
|
|
|
120
123
|
}
|
|
121
124
|
const proposalDiff = /^\/review\/proposals\/([^/]+)\/diff$/.exec(path);
|
|
122
125
|
if (proposalDiff && method === 'GET') {
|
|
123
|
-
const scope = await resolveScope(ctx, process.cwd());
|
|
124
126
|
const handle = db();
|
|
125
127
|
const id = decodeURIComponent(proposalDiff[1] ?? '');
|
|
126
128
|
const proposal = getProposal(handle, id);
|
|
127
129
|
if (!proposal)
|
|
128
130
|
throw new ReviewError('PROPOSAL_NOT_FOUND', 404, '候选不存在:' + id);
|
|
129
131
|
const kb = getKnowledgeBase(handle, proposal.kbId);
|
|
130
|
-
if (!kb
|
|
131
|
-
throw new ReviewError('
|
|
132
|
+
if (!kb)
|
|
133
|
+
throw new ReviewError('KB_NOT_FOUND', 404, '候选所属知识库不存在:' + proposal.kbId);
|
|
132
134
|
const doc = proposal.docId ? getDocument(handle, proposal.docId) : null;
|
|
133
135
|
const payload = buildDiffPayload({
|
|
134
136
|
baseTitle: doc ? doc.title : null,
|
|
@@ -149,7 +151,6 @@ export async function handleReviewRequest(request) {
|
|
|
149
151
|
}
|
|
150
152
|
const proposalAction = /^\/review\/proposals\/([^/]+)\/(approve|reject)$/.exec(path);
|
|
151
153
|
if (proposalAction && method === 'POST') {
|
|
152
|
-
const scope = await resolveScope(ctx, process.cwd());
|
|
153
154
|
const handle = db();
|
|
154
155
|
const id = decodeURIComponent(proposalAction[1] ?? '');
|
|
155
156
|
const action = proposalAction[2] ?? '';
|
|
@@ -157,8 +158,8 @@ export async function handleReviewRequest(request) {
|
|
|
157
158
|
if (!existing)
|
|
158
159
|
throw new ReviewError('PROPOSAL_NOT_FOUND', 404, '候选不存在:' + id);
|
|
159
160
|
const kb = getKnowledgeBase(handle, existing.kbId);
|
|
160
|
-
if (!kb
|
|
161
|
-
throw new ReviewError('
|
|
161
|
+
if (!kb)
|
|
162
|
+
throw new ReviewError('KB_NOT_FOUND', 404, '候选所属知识库不存在:' + existing.kbId);
|
|
162
163
|
const body = (await readBody(req)) ?? {};
|
|
163
164
|
if (action === 'reject') {
|
|
164
165
|
const proposal = rejectProposal(handle, id, { actor: resolveActor(handle, body.actor), note: str(body.note) || null });
|
|
@@ -175,7 +176,6 @@ export async function handleReviewRequest(request) {
|
|
|
175
176
|
return true;
|
|
176
177
|
}
|
|
177
178
|
if (method === 'POST' && path === '/review/bulk') {
|
|
178
|
-
const scope = await resolveScope(ctx, process.cwd());
|
|
179
179
|
const handle = db();
|
|
180
180
|
const body = (await readBody(req)) ?? {};
|
|
181
181
|
const rawItems = Array.isArray(body.items) ? body.items : [];
|
|
@@ -189,22 +189,17 @@ export async function handleReviewRequest(request) {
|
|
|
189
189
|
const id = str(raw?.id);
|
|
190
190
|
if ((type !== 'proposal' && type !== 'doc') || id === '')
|
|
191
191
|
throw new ReviewError('BULK_INVALID_ITEM', 400, '批量项必须是 {type:"proposal"|"doc", id}');
|
|
192
|
-
// 不存在的 id 不在这里 404:交给 bulkReview 逐条记录失败,避免一条脏 id
|
|
192
|
+
// 不存在的 id 不在这里 404:交给 bulkReview 逐条记录失败,避免一条脏 id 让整批失败。
|
|
193
|
+
// 审核覆盖全部知识库,这里只做「对象存在但所属知识库已不存在」的一致性校验。
|
|
193
194
|
if (type === 'proposal') {
|
|
194
195
|
const proposal = getProposal(handle, id);
|
|
195
|
-
if (proposal)
|
|
196
|
-
|
|
197
|
-
if (!kb || !scope.scopeKeys.includes(kb.scopeKey))
|
|
198
|
-
throw new ReviewError('KB_FORBIDDEN', 403, '候选所属知识库不在授权作用域内:' + id);
|
|
199
|
-
}
|
|
196
|
+
if (proposal && !getKnowledgeBase(handle, proposal.kbId))
|
|
197
|
+
throw new ReviewError('KB_NOT_FOUND', 404, '候选所属知识库不存在:' + id);
|
|
200
198
|
}
|
|
201
199
|
else {
|
|
202
200
|
const doc = getDocument(handle, id);
|
|
203
|
-
if (doc)
|
|
204
|
-
|
|
205
|
-
if (!kb || !scope.scopeKeys.includes(kb.scopeKey))
|
|
206
|
-
throw new ReviewError('KB_FORBIDDEN', 403, '知识所属知识库不在授权作用域内:' + id);
|
|
207
|
-
}
|
|
201
|
+
if (doc && !getKnowledgeBase(handle, doc.kbId))
|
|
202
|
+
throw new ReviewError('KB_NOT_FOUND', 404, '知识所属知识库不存在:' + id);
|
|
208
203
|
}
|
|
209
204
|
items.push({ type, id });
|
|
210
205
|
}
|
|
@@ -215,15 +210,14 @@ export async function handleReviewRequest(request) {
|
|
|
215
210
|
}
|
|
216
211
|
const conflictDiff = /^\/review\/conflicts\/([^/]+)\/diff$/.exec(path);
|
|
217
212
|
if (conflictDiff && method === 'GET') {
|
|
218
|
-
const scope = await resolveScope(ctx, process.cwd());
|
|
219
213
|
const handle = db();
|
|
220
214
|
const id = decodeURIComponent(conflictDiff[1] ?? '');
|
|
221
215
|
const conflict = getConflict(handle, id);
|
|
222
216
|
if (!conflict)
|
|
223
217
|
throw new ReviewError('CONFLICT_NOT_FOUND', 404, '冲突不存在:' + id);
|
|
224
218
|
const kb = getKnowledgeBase(handle, conflict.kbId);
|
|
225
|
-
if (!kb
|
|
226
|
-
throw new ReviewError('
|
|
219
|
+
if (!kb)
|
|
220
|
+
throw new ReviewError('KB_NOT_FOUND', 404, '冲突所属知识库不存在:' + conflict.kbId);
|
|
227
221
|
const doc = getDocument(handle, conflict.docId);
|
|
228
222
|
const payload = buildDiffPayload({
|
|
229
223
|
baseTitle: doc ? doc.title : conflict.proposedTitle,
|
|
@@ -246,15 +240,14 @@ export async function handleReviewRequest(request) {
|
|
|
246
240
|
// 基线取上一版正文(只有一版时整体视为新增),目标取知识当前正文。
|
|
247
241
|
const documentDiff = /^\/review\/documents\/([^/]+)\/diff$/.exec(path);
|
|
248
242
|
if (documentDiff && method === 'GET') {
|
|
249
|
-
const scope = await resolveScope(ctx, process.cwd());
|
|
250
243
|
const handle = db();
|
|
251
244
|
const docId = decodeURIComponent(documentDiff[1] ?? '');
|
|
252
245
|
const doc = getDocument(handle, docId);
|
|
253
246
|
if (!doc)
|
|
254
247
|
throw new ReviewError('DOC_NOT_FOUND', 404, '知识不存在:' + docId);
|
|
255
248
|
const kb = getKnowledgeBase(handle, doc.kbId);
|
|
256
|
-
if (!kb
|
|
257
|
-
throw new ReviewError('
|
|
249
|
+
if (!kb)
|
|
250
|
+
throw new ReviewError('KB_NOT_FOUND', 404, '知识所属知识库不存在:' + doc.kbId);
|
|
258
251
|
const previous = doc.currentVersion > 1 ? getVersionContent(handle, doc.id, doc.currentVersion - 1) : null;
|
|
259
252
|
const payload = buildDiffPayload({
|
|
260
253
|
baseTitle: previous ? doc.title : null,
|
|
@@ -274,15 +267,14 @@ export async function handleReviewRequest(request) {
|
|
|
274
267
|
}
|
|
275
268
|
const conflictAction = /^\/review\/conflicts\/([^/]+)\/resolve$/.exec(path);
|
|
276
269
|
if (conflictAction && method === 'POST') {
|
|
277
|
-
const scope = await resolveScope(ctx, process.cwd());
|
|
278
270
|
const handle = db();
|
|
279
271
|
const id = decodeURIComponent(conflictAction[1] ?? '');
|
|
280
272
|
const conflict = getConflict(handle, id);
|
|
281
273
|
if (!conflict)
|
|
282
274
|
throw new ReviewError('CONFLICT_NOT_FOUND', 404, '冲突不存在:' + id);
|
|
283
275
|
const kb = getKnowledgeBase(handle, conflict.kbId);
|
|
284
|
-
if (!kb
|
|
285
|
-
throw new ReviewError('
|
|
276
|
+
if (!kb)
|
|
277
|
+
throw new ReviewError('KB_NOT_FOUND', 404, '冲突所属知识库不存在:' + conflict.kbId);
|
|
286
278
|
const body = (await readBody(req)) ?? {};
|
|
287
279
|
const mode = str(body.mode);
|
|
288
280
|
const result = await resolveConflict(handle, storageRoot(), id, {
|
|
@@ -298,19 +290,17 @@ export async function handleReviewRequest(request) {
|
|
|
298
290
|
}
|
|
299
291
|
const kbReview = /^\/kb\/([^/]+)\/review$/.exec(path);
|
|
300
292
|
if (kbReview && method === 'GET') {
|
|
301
|
-
const scope = await resolveScope(ctx, process.cwd());
|
|
302
293
|
const handle = db();
|
|
303
294
|
const kbId = decodeURIComponent(kbReview[1] ?? '');
|
|
304
|
-
assertKb(handle, kbId
|
|
295
|
+
assertKb(handle, kbId);
|
|
305
296
|
writeOk(res, reviewQueue(handle, [kbId], Number(url.searchParams.get('limit') ?? 50) || 50));
|
|
306
297
|
return true;
|
|
307
298
|
}
|
|
308
299
|
const kbProposals = /^\/kb\/([^/]+)\/proposals$/.exec(path);
|
|
309
300
|
if (kbProposals && method === 'POST') {
|
|
310
|
-
const scope = await resolveScope(ctx, process.cwd());
|
|
311
301
|
const handle = db();
|
|
312
302
|
const kbId = decodeURIComponent(kbProposals[1] ?? '');
|
|
313
|
-
const kb = assertKb(handle, kbId
|
|
303
|
+
const kb = assertKb(handle, kbId);
|
|
314
304
|
const body = (await readBody(req)) ?? {};
|
|
315
305
|
const proposal = createProposal(handle, kb, { ...body, source: str(body.source) || 'web', createdBy: str(body.createdBy) || resolveActor(handle, null) });
|
|
316
306
|
const auto = await autoApproveIfEligible(handle, storageRoot(), proposal, autoApproveRules(handle));
|
|
@@ -324,20 +314,18 @@ export async function handleReviewRequest(request) {
|
|
|
324
314
|
}
|
|
325
315
|
const versions = /^\/kb\/([^/]+)\/docs\/([^/]+)\/versions$/.exec(path);
|
|
326
316
|
if (versions && method === 'GET') {
|
|
327
|
-
const scope = await resolveScope(ctx, process.cwd());
|
|
328
317
|
const handle = db();
|
|
329
318
|
const kbId = decodeURIComponent(versions[1] ?? '');
|
|
330
|
-
assertKb(handle, kbId
|
|
319
|
+
assertKb(handle, kbId);
|
|
331
320
|
const doc = assertDoc(handle, kbId, decodeURIComponent(versions[2] ?? ''));
|
|
332
321
|
writeOk(res, { documentId: doc.id, currentVersion: doc.currentVersion, versions: listVersions(handle, doc.id) });
|
|
333
322
|
return true;
|
|
334
323
|
}
|
|
335
324
|
const versionContent = /^\/kb\/([^/]+)\/docs\/([^/]+)\/versions\/(\d+)$/.exec(path);
|
|
336
325
|
if (versionContent && method === 'GET') {
|
|
337
|
-
const scope = await resolveScope(ctx, process.cwd());
|
|
338
326
|
const handle = db();
|
|
339
327
|
const kbId = decodeURIComponent(versionContent[1] ?? '');
|
|
340
|
-
assertKb(handle, kbId
|
|
328
|
+
assertKb(handle, kbId);
|
|
341
329
|
const doc = assertDoc(handle, kbId, decodeURIComponent(versionContent[2] ?? ''));
|
|
342
330
|
const entry = getVersionContent(handle, doc.id, Number(versionContent[3]));
|
|
343
331
|
if (!entry)
|
|
@@ -347,10 +335,9 @@ export async function handleReviewRequest(request) {
|
|
|
347
335
|
}
|
|
348
336
|
const diff = /^\/kb\/([^/]+)\/docs\/([^/]+)\/diff$/.exec(path);
|
|
349
337
|
if (diff && method === 'GET') {
|
|
350
|
-
const scope = await resolveScope(ctx, process.cwd());
|
|
351
338
|
const handle = db();
|
|
352
339
|
const kbId = decodeURIComponent(diff[1] ?? '');
|
|
353
|
-
assertKb(handle, kbId
|
|
340
|
+
assertKb(handle, kbId);
|
|
354
341
|
const doc = assertDoc(handle, kbId, decodeURIComponent(diff[2] ?? ''));
|
|
355
342
|
const from = Number(url.searchParams.get('from') ?? '') || null;
|
|
356
343
|
const to = Number(url.searchParams.get('to') ?? '') || null;
|
|
@@ -359,10 +346,9 @@ export async function handleReviewRequest(request) {
|
|
|
359
346
|
}
|
|
360
347
|
const docReview = /^\/kb\/([^/]+)\/docs\/([^/]+)\/review$/.exec(path);
|
|
361
348
|
if (docReview && method === 'POST') {
|
|
362
|
-
const scope = await resolveScope(ctx, process.cwd());
|
|
363
349
|
const handle = db();
|
|
364
350
|
const kbId = decodeURIComponent(docReview[1] ?? '');
|
|
365
|
-
assertKb(handle, kbId
|
|
351
|
+
assertKb(handle, kbId);
|
|
366
352
|
const doc = assertDoc(handle, kbId, decodeURIComponent(docReview[2] ?? ''));
|
|
367
353
|
const body = (await readBody(req)) ?? {};
|
|
368
354
|
const action = str(body.action);
|
|
@@ -380,10 +366,9 @@ export async function handleReviewRequest(request) {
|
|
|
380
366
|
}
|
|
381
367
|
const docRestore = /^\/kb\/([^/]+)\/docs\/([^/]+)\/restore$/.exec(path);
|
|
382
368
|
if (docRestore && method === 'POST') {
|
|
383
|
-
const scope = await resolveScope(ctx, process.cwd());
|
|
384
369
|
const handle = db();
|
|
385
370
|
const kbId = decodeURIComponent(docRestore[1] ?? '');
|
|
386
|
-
assertKb(handle, kbId
|
|
371
|
+
assertKb(handle, kbId);
|
|
387
372
|
const doc = assertDoc(handle, kbId, decodeURIComponent(docRestore[2] ?? ''));
|
|
388
373
|
const body = (await readBody(req)) ?? {};
|
|
389
374
|
const version = Number(body.version);
|
|
@@ -396,10 +381,9 @@ export async function handleReviewRequest(request) {
|
|
|
396
381
|
}
|
|
397
382
|
const docEdit = /^\/kb\/([^/]+)\/docs\/([^/]+)$/.exec(path);
|
|
398
383
|
if (docEdit && method === 'PATCH') {
|
|
399
|
-
const scope = await resolveScope(ctx, process.cwd());
|
|
400
384
|
const handle = db();
|
|
401
385
|
const kbId = decodeURIComponent(docEdit[1] ?? '');
|
|
402
|
-
assertKb(handle, kbId
|
|
386
|
+
assertKb(handle, kbId);
|
|
403
387
|
const doc = assertDoc(handle, kbId, decodeURIComponent(docEdit[2] ?? ''));
|
|
404
388
|
const body = (await readBody(req)) ?? {};
|
|
405
389
|
const updated = await updateDocumentByHuman(handle, storageRoot(), doc, body, resolveActor(handle, body.actor));
|