@xiaofanzhao/dsh-plugin-knowledge-base 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +300 -2
- package/client.js +1809 -0
- package/cordis.patch.yml +20 -0
- package/docs/DESIGN.md +662 -0
- package/docs/DETAIL.md +60 -0
- package/docs/images/architecture.svg +111 -0
- package/docs/images/ui-bigscreen.svg +59 -0
- package/docs/images/ui-overview.svg +152 -0
- package/icon.svg +13 -0
- package/index.js +131 -0
- package/lib/chunker.mjs +121 -0
- package/lib/extract.mjs +434 -0
- package/lib/index.mjs +383 -0
- package/lib/pdf.mjs +88 -0
- package/lib/pipeline.mjs +116 -0
- package/lib/preview.mjs +217 -0
- package/lib/routes.mjs +546 -0
- package/lib/settings.mjs +107 -0
- package/lib/store.mjs +445 -0
- package/lib/tools.mjs +246 -0
- package/lib/util.mjs +129 -0
- package/locale/en.json +33 -0
- package/locale/zh.json +33 -0
- package/package.json +63 -4
package/docs/DETAIL.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# 个人知识库
|
|
2
|
+
|
|
3
|
+
把本机文件整理成**树状知识库**:上传后能在应用里直接读,AI 可以检索它,也可以针对某一篇文档对话。文件只存在这台电脑上(默认 `~/.dsh/kb`,可配置)。
|
|
4
|
+
|
|
5
|
+
## 能做什么
|
|
6
|
+
|
|
7
|
+
- **多知识库 + 树状目录**:左栏「知识库」→ 新建库 / 新建文件夹 / 上传文件。**文件树栏可以收起**:顶部最左边那个箭头按钮收起(阅读区随之变宽),收起后左边留一条细条,点它再展开。**点文件夹 = 选中它并展开/收起**,之后「上传文件」「新建文件夹」都落在这个文件夹里;已有内容可以**直接拖到文件夹上**,或用行上悬停出现的「移动到…」;空文件夹会显示「(空文件夹)」提示,不会让你以为点击没反应。行上还能重命名/删除(键盘 F2 / Delete 也行)。
|
|
8
|
+
- **在线查看(原版式)**:点文档直接看原样。**Word / PPT / Excel 会先用本机 LibreOffice 转成 PDF、再逐页渲染成图片,由插件自己的阅读器显示**(不是把浏览器 PDF 阅读器塞进来)。**左侧有可点击的缩略图栏**,点哪页跳哪页、当前页高亮,工具栏最左边那个按钮可以收起/展开;顶部还有**页码输入框 + 上一页/下一页**,默认「连续」滚动(滚到哪页页码跟着变),也可以切「单页」一页一页翻;页面铺满阅读区、按页标号、滚到才加载。PDF 文件仍用浏览器阅读器,图片直接显示。第一次打开要等渲染(大文件几十秒),之后走缓存秒开;导入时也会在后台先转一份。想看更大就点「大屏」——**一页一页铺满整个窗口**(左上角页码、‹ › 翻页、也可以切「连续」),方向键 ← → 也能翻,**右上角「恢复」**(或 Esc)回到面板。桌面端不允许插件页面开新窗口,所以做成了应用内全屏;想存原件点「下载」。
|
|
9
|
+
- **文字版随时可切**:Office 文档右上角有「原版式 / 文字」开关。文字版是抽取出来的正文,用来快速读、也用来给 AI 检索。
|
|
10
|
+
- **全文检索**:右上角搜索框直接搜正文,中文两字词(如「农药」)也能命中。命中结果带片段与章节,点一下跳到正文那一段并高亮。
|
|
11
|
+
- **AI 检索**:模型有三个工具——`kb_list`(有哪些库和目录)、`kb_search`(检索片段)、`kb_read`(按偏移读正文)。任何会话里问「我的知识库里有没有…」都会自动用上。
|
|
12
|
+
- **针对文档对话**:文档页点「问 AI」,会在会话输入框里预填一段带文档 id 的提问,你补上问题发送即可;模型会先读文档再回答,并给出处。
|
|
13
|
+
|
|
14
|
+
## 支持的格式
|
|
15
|
+
|
|
16
|
+
| 类型 | 原版式预览 | 文字阅读 | 正文索引 |
|
|
17
|
+
|---|---|---|---|
|
|
18
|
+
| md / txt / csv / json / 代码等文本 | — | ✅ | ✅ |
|
|
19
|
+
| html | — | ✅ | ✅ |
|
|
20
|
+
| docx / pptx / xlsx | ✅(转 PDF) | ✅ | ✅ |
|
|
21
|
+
| doc / ppt / xls(老格式) | ✅(转 PDF) | — | 不支持(会提示) |
|
|
22
|
+
| pdf | ✅(浏览器阅读器) | — | ✅ 有文字层的 PDF;扫描件会提示"没有文字层" |
|
|
23
|
+
| png / jpg / gif / webp / bmp / svg | ✅ | — | 不索引(图片没有文字) |
|
|
24
|
+
|
|
25
|
+
## 存放位置与隐私
|
|
26
|
+
|
|
27
|
+
- 默认目录:`$DSH_HOME/kb`(Windows 上是 `C:\Users\<你>\.dsh\kb`),里面有 `kb.db`(本地 SQLite 全文索引)和 `files/`(原始文件,文件名按 id 重命名)。
|
|
28
|
+
- 想换目录:在插件配置里设置 `root`,重启后生效。**已有文件不会自动搬迁**。
|
|
29
|
+
- 不上传:除了「向量检索」(默认关闭,需要你自己填 OpenAI 兼容的 embeddings 接口)以外,插件不发任何网络请求。
|
|
30
|
+
|
|
31
|
+
## 设置
|
|
32
|
+
|
|
33
|
+
两个入口,内容一样:
|
|
34
|
+
|
|
35
|
+
- **面板内**:知识库页面右上角的齿轮按钮,直接在页面里看设置,「返回」回文档;
|
|
36
|
+
- **系统设置**:左栏最底部的「设置」(快捷键 `Mod+,` / `Mod+Alt+,`)→ 左侧导航里的「知识库」一节。
|
|
37
|
+
|
|
38
|
+
里面能看存放目录、文档/片段/向量统计,做「重建全部索引」「清理预览缓存」,还能**直接配向量检索**(接口地址 / 模型 / API Key,带「测试连接」)——保存即生效,不用重启;配完点一次「重建全部索引」给已有文档补向量。
|
|
39
|
+
|
|
40
|
+
## 看板
|
|
41
|
+
|
|
42
|
+
页面顶部「文档 / 看板」切过去就是看板,一屏看完知识库的规模与使用情况:
|
|
43
|
+
|
|
44
|
+
- **规模**:知识库数、文档数、检索片段数、总大小、向量数与覆盖率
|
|
45
|
+
- **文件类型分布**:每种后缀有多少篇、占多少空间
|
|
46
|
+
- **解析状态**:已索引 / 排队 / 解析中 / 失败,各知识库各有多少篇
|
|
47
|
+
- **最近 7 天检索**:柱状图 + 总次数、今日次数、零命中率、平均耗时、混合检索次数
|
|
48
|
+
- **热门检索词**:按出现次数排序
|
|
49
|
+
- **最近检索 / 最近添加**:最近的查询(命中数、模式、耗时)与最近上传的文档
|
|
50
|
+
|
|
51
|
+
检索记录写在本机 `kb.db` 的 `search_log` 表里,只保留最近 2000 条,不外发、不影响检索速度(写失败也不会影响结果返回)。右上角「刷新」重新拉一次。
|
|
52
|
+
|
|
53
|
+
## 已知限制
|
|
54
|
+
|
|
55
|
+
- 老版 Office(`.doc/.ppt/.xls`)能看原版式,但不抽正文,所以搜不到里面的字。
|
|
56
|
+
- 扫描版 PDF、纯图片没有文字层,搜不到内容(后续可以考虑接 OCR)。
|
|
57
|
+
- 原版式预览依赖本机的 LibreOffice 转换(DSH 自带):第一次打开大文件要等,最大输入 50 MB。转换出的 PDF 与逐页图片存在库目录里(页数多的文件会占几十 MB),源文件改了会自动重做;设置页有「清理预览缓存」可以随时清掉。
|
|
58
|
+
- 超过 200 页的文档只渲染前 200 页(会明确提示),要看完整版就点「下载」用系统里的 Office 打开。
|
|
59
|
+
- 向量检索是可选项:开启后每次检索会把查询文本发给你配置的 embeddings 服务;索引时也会把片段发过去。
|
|
60
|
+
- 文字版一次最多展示 24000 字,超长文档用「继续加载」翻页。
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 760" width="1200" height="760" role="img" aria-label="架构图">
|
|
2
|
+
<defs>
|
|
3
|
+
<style>
|
|
4
|
+
.bg{fill:#ffffff}
|
|
5
|
+
.box{fill:#f6f8fa;stroke:#d8dee4}
|
|
6
|
+
.boxAccent{fill:#eaf2ff;stroke:#a9c7f5}
|
|
7
|
+
.boxDark{fill:#f0f3f6;stroke:#c9d1d9}
|
|
8
|
+
.txt{fill:#1f2328;font-family:"Segoe UI","Microsoft YaHei",system-ui,sans-serif}
|
|
9
|
+
.sub{fill:#57606a;font-family:"Segoe UI","Microsoft YaHei",system-ui,sans-serif}
|
|
10
|
+
.mono{fill:#1f2328;font-family:"Cascadia Code",Consolas,monospace}
|
|
11
|
+
.arrow{stroke:#8c959f;stroke-width:1.6;fill:none}
|
|
12
|
+
.dash{stroke:#b6bfc9;stroke-width:1.4;fill:none;stroke-dasharray:5 4}
|
|
13
|
+
</style>
|
|
14
|
+
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
|
15
|
+
<path d="M0 0l10 5-10 5z" fill="#8c959f"/>
|
|
16
|
+
</marker>
|
|
17
|
+
</defs>
|
|
18
|
+
|
|
19
|
+
<rect class="bg" x="0" y="0" width="1200" height="760"/>
|
|
20
|
+
<text class="txt" x="40" y="48" font-size="18" font-weight="700">一个插件,两半</text>
|
|
21
|
+
<text class="sub" x="40" y="72" font-size="12.5">浏览器侧只做界面;一切读写、解析、索引都在 Host 进程里</text>
|
|
22
|
+
|
|
23
|
+
<!-- 浏览器半部 -->
|
|
24
|
+
<rect class="boxAccent" x="40" y="100" width="470" height="250" rx="12"/>
|
|
25
|
+
<text class="txt" x="62" y="130" font-size="13.5" font-weight="600">浏览器(client.js)</text>
|
|
26
|
+
<rect class="bg" x="62" y="146" width="200" height="46" rx="8" stroke="#a9c7f5"/>
|
|
27
|
+
<text class="mono" x="76" y="166" font-size="11.5">sidebar.panellist</text>
|
|
28
|
+
<text class="sub" x="76" y="182" font-size="11">左栏图标</text>
|
|
29
|
+
<rect class="bg" x="278" y="146" width="210" height="46" rx="8" stroke="#a9c7f5"/>
|
|
30
|
+
<text class="mono" x="292" y="166" font-size="11.5">main[key]</text>
|
|
31
|
+
<text class="sub" x="292" y="182" font-size="11">树 + 阅读器 + 检索</text>
|
|
32
|
+
<rect class="bg" x="62" y="204" width="200" height="46" rx="8" stroke="#a9c7f5"/>
|
|
33
|
+
<text class="mono" x="76" y="224" font-size="11.5">settings.section</text>
|
|
34
|
+
<text class="sub" x="76" y="240" font-size="11">目录 / 缓存 / 向量状态</text>
|
|
35
|
+
<rect class="bg" x="278" y="204" width="210" height="46" rx="8" stroke="#a9c7f5"/>
|
|
36
|
+
<text class="txt" x="292" y="224" font-size="12">阅读器</text>
|
|
37
|
+
<text class="sub" x="292" y="240" font-size="11">缩略图 · 页码 · 单页/连续 · 大屏</text>
|
|
38
|
+
<text class="sub" x="62" y="284" font-size="11.5">无构建步骤:window.__ModuleLoader__.load({ id, factory })</text>
|
|
39
|
+
<text class="sub" x="62" y="304" font-size="11.5">取数只走同源 HTTP,不碰数据库</text>
|
|
40
|
+
|
|
41
|
+
<!-- 传输 -->
|
|
42
|
+
<path class="arrow" d="M300 350v26" marker-end="url(#a)"/>
|
|
43
|
+
<path class="arrow" d="M330 376v-26" marker-end="url(#a)"/>
|
|
44
|
+
<text class="sub" x="352" y="370" font-size="11.5">/api/kb/v1/* (x-kb-client 头 + 启动令牌)</text>
|
|
45
|
+
|
|
46
|
+
<!-- Host 半部 -->
|
|
47
|
+
<rect class="box" x="40" y="392" width="470" height="330" rx="12"/>
|
|
48
|
+
<text class="txt" x="62" y="420" font-size="13.5" font-weight="600">Host(index.js)</text>
|
|
49
|
+
|
|
50
|
+
<rect class="bg" x="62" y="434" width="130" height="44" rx="8" stroke="#d8dee4"/>
|
|
51
|
+
<text class="mono" x="74" y="453" font-size="10.5">routes.mjs</text>
|
|
52
|
+
<text class="sub" x="74" y="468" font-size="10.5">HTTP 接口</text>
|
|
53
|
+
|
|
54
|
+
<rect class="bg" x="204" y="434" width="130" height="44" rx="8" stroke="#d8dee4"/>
|
|
55
|
+
<text class="mono" x="216" y="453" font-size="10.5">pipeline.mjs</text>
|
|
56
|
+
<text class="sub" x="216" y="468" font-size="10.5">解析队列</text>
|
|
57
|
+
|
|
58
|
+
<rect class="bg" x="346" y="434" width="142" height="44" rx="8" stroke="#d8dee4"/>
|
|
59
|
+
<text class="mono" x="358" y="453" font-size="10.5">tools.mjs</text>
|
|
60
|
+
<text class="sub" x="358" y="468" font-size="10.5">kb_list/search/read</text>
|
|
61
|
+
|
|
62
|
+
<rect class="bg" x="62" y="492" width="130" height="44" rx="8" stroke="#d8dee4"/>
|
|
63
|
+
<text class="mono" x="74" y="511" font-size="10.5">extract.mjs</text>
|
|
64
|
+
<text class="sub" x="74" y="526" font-size="10.5">docx/pptx/xlsx</text>
|
|
65
|
+
|
|
66
|
+
<rect class="bg" x="204" y="492" width="130" height="44" rx="8" stroke="#d8dee4"/>
|
|
67
|
+
<text class="mono" x="216" y="511" font-size="10.5">pdf.mjs</text>
|
|
68
|
+
<text class="sub" x="216" y="526" font-size="10.5">pdfjs 文字层</text>
|
|
69
|
+
|
|
70
|
+
<rect class="bg" x="346" y="492" width="142" height="44" rx="8" stroke="#d8dee4"/>
|
|
71
|
+
<text class="mono" x="358" y="511" font-size="10.5">chunker.mjs</text>
|
|
72
|
+
<text class="sub" x="358" y="526" font-size="10.5">正文 + 分块</text>
|
|
73
|
+
|
|
74
|
+
<rect class="bg" x="62" y="550" width="130" height="44" rx="8" stroke="#d8dee4"/>
|
|
75
|
+
<text class="mono" x="74" y="569" font-size="10.5">index.mjs</text>
|
|
76
|
+
<text class="sub" x="74" y="584" font-size="10.5">FTS5 + 向量</text>
|
|
77
|
+
|
|
78
|
+
<rect class="bg" x="204" y="550" width="130" height="44" rx="8" stroke="#d8dee4"/>
|
|
79
|
+
<text class="mono" x="216" y="569" font-size="10.5">preview.mjs</text>
|
|
80
|
+
<text class="sub" x="216" y="584" font-size="10.5">转 PDF → 出图</text>
|
|
81
|
+
|
|
82
|
+
<rect class="bg" x="346" y="550" width="142" height="44" rx="8" stroke="#d8dee4"/>
|
|
83
|
+
<text class="mono" x="358" y="569" font-size="10.5">store.mjs</text>
|
|
84
|
+
<text class="sub" x="358" y="584" font-size="10.5">库 / 树 / 正文</text>
|
|
85
|
+
|
|
86
|
+
<text class="sub" x="62" y="628" font-size="11.5">复用宿主能力:officeKit(LibreOffice 转 PDF / 渲图)、systemPrompt、tools</text>
|
|
87
|
+
<text class="sub" x="62" y="650" font-size="11.5">不新增 session 事件类型,不改 profile 配置</text>
|
|
88
|
+
|
|
89
|
+
<!-- 右侧:存储 + 模型 -->
|
|
90
|
+
<rect class="boxDark" x="560" y="392" width="600" height="150" rx="12"/>
|
|
91
|
+
<text class="txt" x="582" y="420" font-size="13" font-weight="600">本机磁盘</text>
|
|
92
|
+
<text class="mono" x="582" y="444" font-size="11.5">$DSH_HOME/kb/kb.db</text>
|
|
93
|
+
<text class="sub" x="582" y="462" font-size="11">库结构 + 正文 + 分块 + FTS5 索引(+ 可选向量)</text>
|
|
94
|
+
<text class="mono" x="582" y="490" font-size="11.5">$DSH_HOME/kb/files/<docId>.*</text>
|
|
95
|
+
<text class="sub" x="582" y="508" font-size="11">原始文件 · .preview.pdf · .pages/ 大图 · .thumbs/ 缩略图</text>
|
|
96
|
+
<text class="sub" x="582" y="528" font-size="11">卸载插件不删;设置页可一键清理预览缓存</text>
|
|
97
|
+
|
|
98
|
+
<rect class="boxAccent" x="560" y="566" width="600" height="156" rx="12"/>
|
|
99
|
+
<text class="txt" x="582" y="594" font-size="13" font-weight="600">模型侧</text>
|
|
100
|
+
<text class="sub" x="582" y="618" font-size="11.5">系统提示只在库非空时注入一段,说明怎么用这三个工具</text>
|
|
101
|
+
<rect class="bg" x="582" y="630" width="168" height="34" rx="7" stroke="#a9c7f5"/>
|
|
102
|
+
<text class="mono" x="594" y="652" font-size="11">kb_list</text>
|
|
103
|
+
<rect class="bg" x="762" y="630" width="168" height="34" rx="7" stroke="#a9c7f5"/>
|
|
104
|
+
<text class="mono" x="774" y="652" font-size="11">kb_search</text>
|
|
105
|
+
<rect class="bg" x="942" y="630" width="168" height="34" rx="7" stroke="#a9c7f5"/>
|
|
106
|
+
<text class="mono" x="954" y="652" font-size="11">kb_read</text>
|
|
107
|
+
<text class="sub" x="582" y="690" font-size="11.5">「问 AI」= 把带 docId 的提问预填进会话,不另造聊天窗,会话日志仍是唯一真相</text>
|
|
108
|
+
|
|
109
|
+
<path class="arrow" d="M510 556h30" marker-end="url(#a)"/>
|
|
110
|
+
<path class="arrow" d="M510 640h30" marker-end="url(#a)"/>
|
|
111
|
+
</svg>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 640" width="1200" height="640" role="img" aria-label="大屏放映示意图">
|
|
2
|
+
<defs>
|
|
3
|
+
<style>
|
|
4
|
+
.bg{fill:#ffffff}
|
|
5
|
+
.surface{fill:#f6f8fa}
|
|
6
|
+
.deep{fill:#eef1f4}
|
|
7
|
+
.stroke{stroke:#d8dee4}
|
|
8
|
+
.line{stroke:#d8dee4;stroke-width:1}
|
|
9
|
+
.txt{fill:#1f2328;font-family:"Segoe UI","Microsoft YaHei",system-ui,sans-serif}
|
|
10
|
+
.sub{fill:#57606a;font-family:"Segoe UI","Microsoft YaHei",system-ui,sans-serif}
|
|
11
|
+
.accent{fill:#1f6feb}
|
|
12
|
+
.btn{fill:#ffffff;stroke:#d8dee4}
|
|
13
|
+
.btnTxt{fill:#1f2328;font-family:"Segoe UI","Microsoft YaHei",system-ui,sans-serif;font-size:12px}
|
|
14
|
+
</style>
|
|
15
|
+
</defs>
|
|
16
|
+
|
|
17
|
+
<rect class="bg" x="0" y="0" width="1200" height="640"/>
|
|
18
|
+
|
|
19
|
+
<!-- 覆盖层 -->
|
|
20
|
+
<rect class="bg stroke" x="30" y="30" width="1140" height="520" rx="14"/>
|
|
21
|
+
|
|
22
|
+
<!-- 顶栏 -->
|
|
23
|
+
<rect class="bg" x="31" y="31" width="1138" height="56" rx="13"/>
|
|
24
|
+
<line class="line" x1="30" y1="88" x2="1170" y2="88"/>
|
|
25
|
+
<text class="txt" x="56" y="66" font-size="13.5" font-weight="600">示例-产品培训.pptx</text>
|
|
26
|
+
|
|
27
|
+
<rect class="btn" x="396" y="46" width="24" height="24" rx="6"/>
|
|
28
|
+
<path d="M411 52l-5 6 5 6" fill="none" stroke="#57606a" stroke-width="1.6" stroke-linecap="round"/>
|
|
29
|
+
<text class="txt" x="440" y="63" font-size="12.5" font-weight="600">4 / 123</text>
|
|
30
|
+
<rect class="btn" x="508" y="46" width="24" height="24" rx="6"/>
|
|
31
|
+
<path d="M517 52l5 6-5 6" fill="none" stroke="#57606a" stroke-width="1.6" stroke-linecap="round"/>
|
|
32
|
+
|
|
33
|
+
<rect class="btn" x="556" y="46" width="140" height="24" rx="7"/>
|
|
34
|
+
<rect class="surface" x="558" y="48" width="66" height="20" rx="5"/>
|
|
35
|
+
<text class="txt" x="576" y="62" font-size="11.5" font-weight="600">单页</text>
|
|
36
|
+
<text class="sub" x="640" y="62" font-size="11.5">连续</text>
|
|
37
|
+
|
|
38
|
+
<rect class="accent" x="1040" y="46" width="96" height="28" rx="8"/>
|
|
39
|
+
<text x="1074" y="64" font-size="12.5" fill="#ffffff" font-family="Segoe UI,Microsoft YaHei,sans-serif">恢复</text>
|
|
40
|
+
|
|
41
|
+
<!-- 舞台 -->
|
|
42
|
+
<rect class="deep" x="31" y="89" width="1138" height="460" rx="13"/>
|
|
43
|
+
<rect x="266" y="110" width="668" height="376" rx="6" fill="#ffffff" stroke="#d8dee4"/>
|
|
44
|
+
<!-- 幻灯片内容占位 -->
|
|
45
|
+
<rect x="266" y="110" width="668" height="150" rx="6" fill="#e8f0fb"/>
|
|
46
|
+
<rect x="300" y="150" width="180" height="16" rx="5" fill="#c7d9f5"/>
|
|
47
|
+
<rect x="300" y="182" width="260" height="10" rx="4" fill="#d7e3f8"/>
|
|
48
|
+
<rect x="300" y="204" width="220" height="10" rx="4" fill="#d7e3f8"/>
|
|
49
|
+
<rect x="300" y="292" width="220" height="12" rx="4" fill="#eef1f4"/>
|
|
50
|
+
<rect x="300" y="318" width="300" height="10" rx="4" fill="#eef1f4"/>
|
|
51
|
+
<rect x="540" y="292" width="360" height="150" rx="6" fill="#f6f8fa" stroke="#e6eaef"/>
|
|
52
|
+
<rect x="300" y="352" width="200" height="10" rx="4" fill="#eef1f4"/>
|
|
53
|
+
<rect x="300" y="372" width="170" height="10" rx="4" fill="#eef1f4"/>
|
|
54
|
+
<text class="sub" x="600" y="470" font-size="11.5" text-anchor="middle">object-fit: contain —— 整页装下、居中、不裁切</text>
|
|
55
|
+
|
|
56
|
+
<!-- 提示 -->
|
|
57
|
+
<text class="sub" x="30" y="586" font-size="12.5">方向键 ← → / PageUp PageDown 翻页 · Esc 或右上角「恢复」回到面板</text>
|
|
58
|
+
<text class="sub" x="30" y="612" font-size="11.5">示意图(实际界面跟随 DSH 主题与窗口宽度)</text>
|
|
59
|
+
</svg>
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 840" width="1200" height="840" role="img" aria-label="知识库面板示意图">
|
|
2
|
+
<defs>
|
|
3
|
+
<style>
|
|
4
|
+
.bg{fill:#ffffff}
|
|
5
|
+
.surface{fill:#f6f8fa}
|
|
6
|
+
.stroke{stroke:#d8dee4}
|
|
7
|
+
.line{stroke:#d8dee4;stroke-width:1}
|
|
8
|
+
.txt{fill:#1f2328;font-family:"Segoe UI","Microsoft YaHei",system-ui,sans-serif}
|
|
9
|
+
.sub{fill:#57606a;font-family:"Segoe UI","Microsoft YaHei",system-ui,sans-serif}
|
|
10
|
+
.accent{fill:#1f6feb}
|
|
11
|
+
.accentStroke{stroke:#1f6feb}
|
|
12
|
+
.btnTxt{fill:#1f2328;font-family:"Segoe UI","Microsoft YaHei",system-ui,sans-serif;font-size:12px}
|
|
13
|
+
.btnTxtWhite{fill:#ffffff;font-family:"Segoe UI","Microsoft YaHei",system-ui,sans-serif;font-size:12px}
|
|
14
|
+
.callout{fill:#1f6feb}
|
|
15
|
+
.calloutTxt{fill:#ffffff;font-family:"Segoe UI",system-ui,sans-serif;font-size:11px;font-weight:600}
|
|
16
|
+
</style>
|
|
17
|
+
</defs>
|
|
18
|
+
|
|
19
|
+
<rect class="bg" x="0" y="0" width="1200" height="840"/>
|
|
20
|
+
|
|
21
|
+
<!-- 面板外框 -->
|
|
22
|
+
<rect class="bg stroke" x="24" y="24" width="1152" height="656" rx="14"/>
|
|
23
|
+
|
|
24
|
+
<!-- 左栏图标条 -->
|
|
25
|
+
<path class="surface" d="M38 24h44v656H38a14 14 0 0 1-14-14V38a14 14 0 0 1 14-14z"/>
|
|
26
|
+
<line class="line" x1="82" y1="24" x2="82" y2="680"/>
|
|
27
|
+
<rect class="accent" x="44" y="46" width="32" height="32" rx="9"/>
|
|
28
|
+
<path d="M55 58h9a3 3 0 0 1 3 3v9h-9a3 3 0 0 1-3-3v-9z" fill="none" stroke="#ffffff" stroke-width="1.6"/>
|
|
29
|
+
<rect class="surface stroke" x="44" y="92" width="32" height="32" rx="9"/>
|
|
30
|
+
<rect x="52" y="100" width="16" height="16" rx="4" fill="none" stroke="#8c959f" stroke-width="1.6"/>
|
|
31
|
+
<rect class="surface stroke" x="44" y="138" width="32" height="32" rx="9"/>
|
|
32
|
+
<circle cx="60" cy="154" r="7" fill="none" stroke="#8c959f" stroke-width="1.6"/>
|
|
33
|
+
|
|
34
|
+
<!-- 头部 -->
|
|
35
|
+
<line class="line" x1="82" y1="90" x2="1176" y2="90"/>
|
|
36
|
+
<path d="M100 57l5 5-5 5" fill="none" stroke="#57606a" stroke-width="1.8" stroke-linecap="round"/>
|
|
37
|
+
<text class="txt" x="120" y="66" font-size="14" font-weight="600">知识库</text>
|
|
38
|
+
<rect class="surface stroke" x="176" y="42" width="150" height="30" rx="8"/>
|
|
39
|
+
<text class="txt" x="188" y="62" font-size="12.5">我的资料库 ▾</text>
|
|
40
|
+
<rect class="surface stroke" x="342" y="42" width="330" height="30" rx="8"/>
|
|
41
|
+
<circle cx="358" cy="57" r="4.5" fill="none" stroke="#8c959f" stroke-width="1.6"/>
|
|
42
|
+
<line x1="361.5" y1="60.5" x2="364.5" y2="63.5" stroke="#8c959f" stroke-width="1.6" stroke-linecap="round"/>
|
|
43
|
+
<text class="sub" x="374" y="62" font-size="12">搜索标题或正文(支持中文短词)…</text>
|
|
44
|
+
<rect class="surface stroke" x="852" y="42" width="112" height="30" rx="8"/>
|
|
45
|
+
<text class="btnTxt" x="868" y="62">新建文件夹</text>
|
|
46
|
+
<rect class="accent" x="974" y="42" width="104" height="30" rx="8"/>
|
|
47
|
+
<text class="btnTxtWhite" x="996" y="62">导入文件</text>
|
|
48
|
+
|
|
49
|
+
<!-- 文件树 -->
|
|
50
|
+
<line class="line" x1="330" y1="90" x2="330" y2="680"/>
|
|
51
|
+
<rect x="88" y="102" width="236" height="28" rx="7" fill="#f6f8fa"/>
|
|
52
|
+
<path d="M96 111l4 5-4 5" fill="none" stroke="#8c959f" stroke-width="1.5" stroke-linecap="round"/>
|
|
53
|
+
<rect x="106" y="110" width="14" height="12" rx="2.5" fill="none" stroke="#57606a" stroke-width="1.5"/>
|
|
54
|
+
<text class="txt" x="128" y="121" font-size="12.5">示例资料</text>
|
|
55
|
+
|
|
56
|
+
<path d="M118 135v20" stroke="#d8dee4" stroke-width="1.5"/>
|
|
57
|
+
<rect x="126" y="150" width="16" height="12" rx="3" fill="none" stroke="#57606a" stroke-width="1.5"/>
|
|
58
|
+
<text class="sub" x="150" y="160" font-size="12.5">产品培训.pptx</text>
|
|
59
|
+
<rect x="126" y="178" width="16" height="12" rx="3" fill="none" stroke="#57606a" stroke-width="1.5"/>
|
|
60
|
+
<text class="sub" x="150" y="188" font-size="12.5">会议纪要.docx</text>
|
|
61
|
+
<rect x="126" y="206" width="16" height="12" rx="3" fill="none" stroke="#57606a" stroke-width="1.5"/>
|
|
62
|
+
<text class="sub" x="150" y="216" font-size="12.5">出口要求.md</text>
|
|
63
|
+
|
|
64
|
+
<!-- 文档头 -->
|
|
65
|
+
<text class="txt" x="356" y="122" font-size="15" font-weight="600">示例-产品培训.pptx</text>
|
|
66
|
+
<text class="sub" x="356" y="146" font-size="12">9.2 MB · .pptx · 已索引 · 8 页 · 2 分钟前</text>
|
|
67
|
+
|
|
68
|
+
<!-- 操作按钮 -->
|
|
69
|
+
<rect class="accent" x="356" y="160" width="88" height="30" rx="8"/>
|
|
70
|
+
<text class="btnTxtWhite" x="378" y="180">✳ 问 AI</text>
|
|
71
|
+
<rect class="surface stroke" x="452" y="160" width="74" height="30" rx="8"/>
|
|
72
|
+
<text class="btnTxt" x="470" y="180">大屏</text>
|
|
73
|
+
<rect class="surface stroke" x="534" y="160" width="74" height="30" rx="8"/>
|
|
74
|
+
<text class="btnTxt" x="552" y="180">下载</text>
|
|
75
|
+
<rect class="surface stroke" x="616" y="160" width="112" height="30" rx="8"/>
|
|
76
|
+
<rect class="surface" x="619" y="163" width="52" height="24" rx="6"/>
|
|
77
|
+
<text class="txt" x="630" y="180" font-size="11.5" font-weight="600">原版式</text>
|
|
78
|
+
<text class="sub" x="682" y="180" font-size="11.5">文字</text>
|
|
79
|
+
|
|
80
|
+
<!-- 阅读器工具条 -->
|
|
81
|
+
<line class="line" x1="330" y1="204" x2="1176" y2="204"/>
|
|
82
|
+
<rect class="surface stroke" x="348" y="214" width="26" height="24" rx="6"/>
|
|
83
|
+
<rect x="354" y="220" width="9" height="12" rx="1.5" fill="none" stroke="#57606a" stroke-width="1.4"/>
|
|
84
|
+
<line x1="368" y1="222" x2="368" y2="230" stroke="#57606a" stroke-width="1.4"/>
|
|
85
|
+
<rect class="surface stroke" x="384" y="214" width="24" height="24" rx="6"/>
|
|
86
|
+
<path d="M399 220l-5 6 5 6" fill="none" stroke="#57606a" stroke-width="1.6" stroke-linecap="round"/>
|
|
87
|
+
<rect class="surface stroke" x="416" y="214" width="44" height="24" rx="6"/>
|
|
88
|
+
<text class="txt" x="434" y="231" font-size="12" text-anchor="middle">4</text>
|
|
89
|
+
<text class="sub" x="468" y="231" font-size="12">/ 123</text>
|
|
90
|
+
<rect class="surface stroke" x="502" y="214" width="24" height="24" rx="6"/>
|
|
91
|
+
<path d="M511 220l5 6-5 6" fill="none" stroke="#57606a" stroke-width="1.6" stroke-linecap="round"/>
|
|
92
|
+
<rect class="surface stroke" x="1002" y="214" width="160" height="24" rx="7"/>
|
|
93
|
+
<rect class="surface" x="1004" y="216" width="70" height="20" rx="5"/>
|
|
94
|
+
<text class="txt" x="1022" y="230" font-size="11.5" font-weight="600">单页</text>
|
|
95
|
+
<text class="sub" x="1088" y="230" font-size="11.5">连续</text>
|
|
96
|
+
|
|
97
|
+
<!-- 缩略图栏 -->
|
|
98
|
+
<rect class="surface" x="340" y="250" width="106" height="414" rx="8"/>
|
|
99
|
+
<rect x="348" y="258" width="90" height="50" rx="4" fill="#ffffff" stroke="#d8dee4"/>
|
|
100
|
+
<rect x="348" y="316" width="90" height="50" rx="4" fill="#ffffff" stroke="#d8dee4"/>
|
|
101
|
+
<rect x="346" y="374" width="94" height="54" rx="4" fill="#ffffff" stroke="#1f6feb" stroke-width="2"/>
|
|
102
|
+
<text class="accent" x="386" y="405" font-size="11" text-anchor="middle">4</text>
|
|
103
|
+
<rect x="348" y="436" width="90" height="50" rx="4" fill="#ffffff" stroke="#d8dee4"/>
|
|
104
|
+
<rect x="348" y="494" width="90" height="50" rx="4" fill="#ffffff" stroke="#d8dee4"/>
|
|
105
|
+
<rect x="348" y="552" width="90" height="50" rx="4" fill="#ffffff" stroke="#d8dee4"/>
|
|
106
|
+
|
|
107
|
+
<!-- 页面 -->
|
|
108
|
+
<rect x="458" y="250" width="702" height="414" rx="8" fill="#f0f3f6" stroke="#d8dee4"/>
|
|
109
|
+
<rect x="536" y="274" width="546" height="366" rx="4" fill="#ffffff" stroke="#d8dee4"/>
|
|
110
|
+
<rect x="572" y="310" width="200" height="14" rx="4" fill="#e6eaef"/>
|
|
111
|
+
<rect x="572" y="342" width="380" height="10" rx="4" fill="#eef1f4"/>
|
|
112
|
+
<rect x="572" y="362" width="340" height="10" rx="4" fill="#eef1f4"/>
|
|
113
|
+
<rect x="572" y="382" width="400" height="10" rx="4" fill="#eef1f4"/>
|
|
114
|
+
<rect x="572" y="418" width="368" height="120" rx="6" fill="#f6f8fa" stroke="#e6eaef"/>
|
|
115
|
+
<rect x="572" y="556" width="300" height="10" rx="4" fill="#eef1f4"/>
|
|
116
|
+
<rect x="572" y="576" width="256" height="10" rx="4" fill="#eef1f4"/>
|
|
117
|
+
<text class="sub" x="809" y="660" font-size="11.5" text-anchor="middle">96 DPI 逐页图片 · 铺满阅读区</text>
|
|
118
|
+
|
|
119
|
+
<!-- 序号标注(白色光晕压在元素角上,避免挡住文字) -->
|
|
120
|
+
<g>
|
|
121
|
+
<circle cx="176" cy="44" r="13" fill="#ffffff"/>
|
|
122
|
+
<circle class="callout" cx="176" cy="44" r="10"/><text class="calloutTxt" x="176" y="48" text-anchor="middle">1</text>
|
|
123
|
+
<circle cx="342" cy="44" r="13" fill="#ffffff"/>
|
|
124
|
+
<circle class="callout" cx="342" cy="44" r="10"/><text class="calloutTxt" x="342" y="48" text-anchor="middle">2</text>
|
|
125
|
+
<circle cx="974" cy="44" r="13" fill="#ffffff"/>
|
|
126
|
+
<circle class="callout" cx="974" cy="44" r="10"/><text class="calloutTxt" x="974" y="48" text-anchor="middle">3</text>
|
|
127
|
+
<circle cx="1002" cy="216" r="13" fill="#ffffff"/>
|
|
128
|
+
<circle class="callout" cx="1002" cy="216" r="10"/><text class="calloutTxt" x="1002" y="220" text-anchor="middle">4</text>
|
|
129
|
+
<circle cx="340" cy="252" r="13" fill="#ffffff"/>
|
|
130
|
+
<circle class="callout" cx="340" cy="252" r="10"/><text class="calloutTxt" x="340" y="256" text-anchor="middle">5</text>
|
|
131
|
+
<circle cx="452" cy="162" r="13" fill="#ffffff"/>
|
|
132
|
+
<circle class="callout" cx="452" cy="162" r="10"/><text class="calloutTxt" x="452" y="166" text-anchor="middle">6</text>
|
|
133
|
+
</g>
|
|
134
|
+
|
|
135
|
+
<!-- 图例 -->
|
|
136
|
+
<g font-size="12.5">
|
|
137
|
+
<circle class="callout" cx="40" cy="712" r="9"/><text class="calloutTxt" x="40" y="716" text-anchor="middle">1</text>
|
|
138
|
+
<text class="txt" x="58" y="716">创作/选择知识库</text>
|
|
139
|
+
<circle class="callout" cx="40" cy="742" r="9"/><text class="calloutTxt" x="40" y="746" text-anchor="middle">2</text>
|
|
140
|
+
<text class="txt" x="58" y="746">搜正文(中文两字词也能命中)</text>
|
|
141
|
+
<circle class="callout" cx="40" cy="772" r="9"/><text class="calloutTxt" x="40" y="776" text-anchor="middle">3</text>
|
|
142
|
+
<text class="txt" x="58" y="776">导入 / 新建(落在选中的文件夹)</text>
|
|
143
|
+
|
|
144
|
+
<circle class="callout" cx="620" cy="712" r="9"/><text class="calloutTxt" x="620" y="716" text-anchor="middle">4</text>
|
|
145
|
+
<text class="txt" x="638" y="716">页码跳转 + 单页/连续</text>
|
|
146
|
+
<circle class="callout" cx="620" cy="742" r="9"/><text class="calloutTxt" x="620" y="746" text-anchor="middle">5</text>
|
|
147
|
+
<text class="txt" x="638" y="746">缩略图栏:点哪页跳哪页</text>
|
|
148
|
+
<circle class="callout" cx="620" cy="772" r="9"/><text class="calloutTxt" x="620" y="776" text-anchor="middle">6</text>
|
|
149
|
+
<text class="txt" x="638" y="776">大屏放映 · 下载原件 · 问 AI</text>
|
|
150
|
+
</g>
|
|
151
|
+
<text class="sub" x="24" y="812" font-size="11.5">示意图(实际界面跟随 DSH 主题与窗口宽度)</text>
|
|
152
|
+
</svg>
|
package/icon.svg
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Knowledge base">
|
|
2
|
+
<rect x="6" y="10" width="52" height="44" rx="7" fill="#1f6feb" opacity="0.12"/>
|
|
3
|
+
<path d="M18 17h20a4 4 0 0 1 4 4v26a4 4 0 0 1-4 4H18z" fill="#1f6feb"/>
|
|
4
|
+
<path d="M18 17h20a4 4 0 0 1 4 4v26a4 4 0 0 1-4 4H18z" fill="none" stroke="#1f6feb" stroke-width="2.4"/>
|
|
5
|
+
<path d="M42 21h4a4 4 0 0 1 4 4v22a4 4 0 0 1-4 4h-4z" fill="#1277d6" opacity="0.55"/>
|
|
6
|
+
<g stroke="#ffffff" stroke-width="2.2" stroke-linecap="round" opacity="0.95">
|
|
7
|
+
<path d="M23 26h11"/>
|
|
8
|
+
<path d="M23 32h13"/>
|
|
9
|
+
<path d="M23 38h9"/>
|
|
10
|
+
</g>
|
|
11
|
+
<circle cx="46" cy="44" r="9" fill="#0f62c8"/>
|
|
12
|
+
<path d="M42.6 44.2l2.4 2.5 4.4-5" fill="none" stroke="#ffffff" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
13
|
+
</svg>
|
package/index.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// dsh-plugin-knowledge-base — Host 半部
|
|
3
|
+
//
|
|
4
|
+
// 职责:
|
|
5
|
+
// 1. 把库、树、文档存在本机($DSH_HOME/kb,可配),解析正文并建全文索引
|
|
6
|
+
// 2. 给浏览器端一组同源 HTTP 接口(树 / 上传 / 阅读 / 检索 / 预填提问)
|
|
7
|
+
// 3. 给模型三个只读工具:kb_list / kb_search / kb_read
|
|
8
|
+
// 4. 库非空时注入一小段系统提示,告诉模型怎么用这些工具
|
|
9
|
+
//
|
|
10
|
+
// 不做的事:不新增 session 事件类型、不碰 profile 配置、不把文件放进工作区。
|
|
11
|
+
// ============================================================================
|
|
12
|
+
import crypto from 'node:crypto';
|
|
13
|
+
import os from 'node:os';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import { openStore } from './lib/store.mjs';
|
|
16
|
+
import { createEmbedder, createIndex } from './lib/index.mjs';
|
|
17
|
+
import { createPipeline } from './lib/pipeline.mjs';
|
|
18
|
+
import { createPreviewer } from './lib/preview.mjs';
|
|
19
|
+
import { createKnowledgeBaseTools } from './lib/tools.mjs';
|
|
20
|
+
import { createSettingsStore } from './lib/settings.mjs';
|
|
21
|
+
import { createRoutes } from './lib/routes.mjs';
|
|
22
|
+
|
|
23
|
+
export const name = 'dsh-knowledge-base';
|
|
24
|
+
export const inject = ['webServer'];
|
|
25
|
+
|
|
26
|
+
function resolveRoot(config) {
|
|
27
|
+
const configured = typeof config?.root === 'string' ? config.root.trim() : '';
|
|
28
|
+
if (configured) return path.resolve(configured);
|
|
29
|
+
const home = process.env.DSH_HOME || path.join(os.homedir(), '.dsh');
|
|
30
|
+
return path.join(home, 'kb');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function apply(ctx, config = {}) {
|
|
34
|
+
const webServer = ctx.get('webServer');
|
|
35
|
+
if (!webServer?.register) {
|
|
36
|
+
ctx.logger?.(name)?.warn?.('[knowledge-base] webServer 不可用,插件未启动');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const logger = ctx.logger?.(name) ?? console;
|
|
40
|
+
const root = resolveRoot(config);
|
|
41
|
+
|
|
42
|
+
let store;
|
|
43
|
+
try {
|
|
44
|
+
store = openStore({ root, logger });
|
|
45
|
+
} catch (error) {
|
|
46
|
+
logger.error?.(`[knowledge-base] 打不开存储 ${root}:${error instanceof Error ? error.message : String(error)}`);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 向量配置:界面改的写进 settings.json,优先级高于插件 YAML 里的 config.embedding
|
|
51
|
+
const settings = createSettingsStore({ root, logger });
|
|
52
|
+
const resolveEmbedding = () => {
|
|
53
|
+
if (settings.hasSaved()) return settings.embedding();
|
|
54
|
+
const base = config.embedding ?? {};
|
|
55
|
+
return { enabled: Boolean(base.enabled), baseUrl: base.baseUrl ?? '', model: base.model ?? '', apiKey: base.apiKey ?? '' };
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const embedder = createEmbedder({ resolve: resolveEmbedding, logger });
|
|
59
|
+
const index = createIndex({ store, embedder });
|
|
60
|
+
// Office 原版式预览要用宿主的 officeKit(LibreOffice 转换),它可能比本插件晚加载,
|
|
61
|
+
// 所以用 getter 在调用时取。
|
|
62
|
+
const previewer = createPreviewer({ store, getOfficeKit: () => ctx.get('officeKit'), logger });
|
|
63
|
+
const pipeline = createPipeline({ store, index, embedder, logger, config, previewer });
|
|
64
|
+
|
|
65
|
+
// ── HTTP 路由 ──────────────────────────────────────────────────────────
|
|
66
|
+
// 二进制预览(<img>/<iframe>)带不了自定义头,给它一条带启动令牌的通道。
|
|
67
|
+
const token = crypto.randomUUID();
|
|
68
|
+
const { routes } = createRoutes({
|
|
69
|
+
store, index, pipeline, embedder, settings, config, logger, webServer, token, previewer,
|
|
70
|
+
});
|
|
71
|
+
for (const route of routes) {
|
|
72
|
+
ctx.effect(() => webServer.register(route), `knowledge-base: ${route.path}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ── 模型工具 ───────────────────────────────────────────────────────────
|
|
76
|
+
const tools = createKnowledgeBaseTools({ store, index, pipeline });
|
|
77
|
+
if (typeof ctx.inject === 'function') {
|
|
78
|
+
ctx.inject(['tools'], (toolCtx) => {
|
|
79
|
+
for (const definition of tools) {
|
|
80
|
+
toolCtx.effect(() => toolCtx.tools.register(definition), `knowledge-base: tool ${definition.name}`);
|
|
81
|
+
}
|
|
82
|
+
logger.info?.(`[knowledge-base] tools registered: ${tools.map((item) => item.name).join(', ')}`);
|
|
83
|
+
});
|
|
84
|
+
} else if (ctx.tools?.register) {
|
|
85
|
+
for (const definition of tools) ctx.effect(() => ctx.tools.register(definition), `knowledge-base: tool ${definition.name}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ── 系统提示(库非空时才说)─────────────────────────────────────────────
|
|
89
|
+
ctx.inject(['systemPrompt'], (promptCtx) => {
|
|
90
|
+
promptCtx.effect(() => promptCtx.systemPrompt.section({
|
|
91
|
+
name: 'personal-knowledge-base',
|
|
92
|
+
order: 60,
|
|
93
|
+
interpolate: false,
|
|
94
|
+
text: () => {
|
|
95
|
+
try {
|
|
96
|
+
const kbs = store.listKbs();
|
|
97
|
+
if (!kbs.length) return '';
|
|
98
|
+
const docs = kbs.reduce((sum, kb) => sum + kb.docs, 0);
|
|
99
|
+
const names = kbs.slice(0, 6).map((kb) => kb.name).join('、');
|
|
100
|
+
return [
|
|
101
|
+
'## 个人知识库',
|
|
102
|
+
'用户在这台机器上有一个本地知识库,可用工具:kb_list / kb_search / kb_read。',
|
|
103
|
+
'当用户提到"知识库""我的资料""我之前存的那份文档",或问题明显依赖本地资料时:',
|
|
104
|
+
'先用 kb_list 看有哪些库,用 kb_search 检索(中文短词也能命中),必要时用 kb_read 读片段周围的正文。',
|
|
105
|
+
'回答时给出处(知识库 → 目录 → 文件 → 章节/页码),文档里没有的内容不要编造。',
|
|
106
|
+
`现状:${kbs.length} 个知识库(${names}${kbs.length > 6 ? ' 等' : ''}),共 ${docs} 篇文档。`,
|
|
107
|
+
].join('\n');
|
|
108
|
+
} catch {
|
|
109
|
+
return '';
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
}), 'knowledge-base: prompt section');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// 上次进程没跑完的解析任务接着跑
|
|
116
|
+
const recovered = pipeline.recover();
|
|
117
|
+
|
|
118
|
+
// ── 卸载清理 ───────────────────────────────────────────────────────────
|
|
119
|
+
ctx.effect(() => () => {
|
|
120
|
+
try {
|
|
121
|
+
// 正在解析的文档回到 pending,下次启动会重新排队
|
|
122
|
+
store.raw.q(`UPDATE nodes SET status = 'pending' WHERE status = 'parsing'`).run();
|
|
123
|
+
} catch { /* ignore */ }
|
|
124
|
+
store.close();
|
|
125
|
+
}, 'knowledge-base: close store');
|
|
126
|
+
|
|
127
|
+
logger.info?.(`[knowledge-base] ready · root=${root} · recovered=${recovered}`
|
|
128
|
+
+ ` · embedding=${embedder.enabled ? 'on' : 'off'}`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export default { name, inject, apply };
|