@xiaofanzhao/dsh-plugin-knowledge-base 0.0.0-stage → 0.2.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/lib/tools.mjs ADDED
@@ -0,0 +1,246 @@
1
+ // ============================================================================
2
+ // 模型工具:kb_list / kb_search / kb_read(全部只读)
3
+ //
4
+ // 只依赖 ctx.tools.register 约定,不 import 任何 @deepseek-ai 包:
5
+ // { name, description, parameters, output: { schema, render }, execute, presentCall }
6
+ // parameters 只能使用 DSH 支持的 JSON Schema 子集。
7
+ // ============================================================================
8
+
9
+ const MAX_READ_CHARS = 6000;
10
+ const MAX_SEARCH_LIMIT = 20;
11
+
12
+ const HIT_SCHEMA = {
13
+ type: 'object',
14
+ additionalProperties: false,
15
+ required: ['docId', 'name', 'locator', 'snippet', 'charStart'],
16
+ properties: {
17
+ docId: { type: 'string', description: '文档 id,可直接传给 kb_read' },
18
+ name: { type: 'string', description: '文件名' },
19
+ locator: { type: 'string', description: '给人看的定位:知识库 → 目录 → 文件' },
20
+ heading: { type: 'string', description: '所在章节(可能为空)' },
21
+ snippet: { type: 'string', description: '命中片段' },
22
+ charStart: { type: 'number', description: '片段在正文里的起始字符偏移,传给 kb_read 的 offset' },
23
+ page: { type: 'number', description: '页码(PDF/PPT),没有则为 0' },
24
+ },
25
+ };
26
+
27
+ function formatBytes(bytes) {
28
+ const value = Number(bytes) || 0;
29
+ if (value < 1024) return `${value} B`;
30
+ if (value < 1048576) return `${(value / 1024).toFixed(1)} KB`;
31
+ return `${(value / 1048576).toFixed(1)} MB`;
32
+ }
33
+
34
+ export function createKnowledgeBaseTools({ store, index, pipeline }) {
35
+ // ── kb_list ────────────────────────────────────────────────────────────
36
+ const listTool = {
37
+ name: 'kb_list',
38
+ description:
39
+ '列出用户的「个人知识库」:有哪些库、每个库里的目录结构。'
40
+ + '用户提到"知识库""我的资料""我之前存的那份文档"时,先调用它确认有什么,再用 kb_search 检索。',
41
+ parameters: {
42
+ type: 'object',
43
+ additionalProperties: false,
44
+ properties: {
45
+ kbId: { type: 'string', description: '只列这个知识库;省略则列出全部库的概览' },
46
+ },
47
+ },
48
+ output: {
49
+ schema: {
50
+ type: 'object',
51
+ additionalProperties: false,
52
+ required: ['summary', 'libraries'],
53
+ properties: {
54
+ summary: { type: 'string', description: '一句话概览' },
55
+ libraries: {
56
+ type: 'array',
57
+ description: '知识库清单',
58
+ items: {
59
+ type: 'object',
60
+ additionalProperties: false,
61
+ required: ['id', 'name', 'docs'],
62
+ properties: {
63
+ id: { type: 'string', description: '知识库 id,可传给 kb_search 的 kbIds' },
64
+ name: { type: 'string', description: '知识库名称' },
65
+ docs: { type: 'number', description: '文档数' },
66
+ tree: { type: 'string', description: '缩进的目录树文本(只在该库被指定时返回)' },
67
+ },
68
+ },
69
+ },
70
+ },
71
+ },
72
+ render: (_args, value) => [{ type: 'text', text: value.summary + (value.libraries.length ? `\n${value.libraries.map((item) => item.tree || `- ${item.name}(${item.docs} 篇)`).join('\n')}` : '') }],
73
+ },
74
+ async execute(args) {
75
+ const only = typeof args.kbId === 'string' ? args.kbId.trim() : '';
76
+ const libraries = store.listKbs().filter((kb) => !only || kb.id === only);
77
+ if (!libraries.length) {
78
+ return { summary: '还没有任何知识库(用户可以在左下角「知识库」页面新建)。', libraries: [] };
79
+ }
80
+ const out = libraries.map((kb) => {
81
+ const base = { id: kb.id, name: kb.name, docs: kb.docs, tree: '' };
82
+ if (!only) return base;
83
+ const nodes = store.listNodes(kb.id);
84
+ const byParent = new Map();
85
+ for (const node of nodes) {
86
+ const key = node.parentId ?? '';
87
+ if (!byParent.has(key)) byParent.set(key, []);
88
+ byParent.get(key).push(node);
89
+ }
90
+ const lines = [`- ${kb.name}(${kb.docs} 篇)`];
91
+ const walk = (parentKey, depth) => {
92
+ if (depth > 6) return;
93
+ for (const node of byParent.get(parentKey) ?? []) {
94
+ const mark = node.kind === 'folder' ? '📁' : '📄';
95
+ const size = node.kind === 'doc' ? ` ${formatBytes(node.bytes)}` : '';
96
+ const bad = node.status === 'failed' ? '(解析失败)' : '';
97
+ lines.push(`${' '.repeat(depth)}${mark} ${node.name}${size}${bad}`);
98
+ if (node.kind === 'folder') walk(node.id, depth + 1);
99
+ }
100
+ };
101
+ walk('', 1);
102
+ return { ...base, tree: lines.join('\n') };
103
+ });
104
+ const total = out.reduce((sum, item) => sum + item.docs, 0);
105
+ return { summary: `共 ${out.length} 个知识库、${total} 篇文档。`, libraries: out };
106
+ },
107
+ };
108
+
109
+ // ── kb_search ──────────────────────────────────────────────────────────
110
+ const searchTool = {
111
+ name: 'kb_search',
112
+ description:
113
+ '在用户的个人知识库里做全文检索(中文、英文、编号都行),返回命中片段与定位。'
114
+ + '回答本地资料相关的问题前先用它;命中后可用 kb_read 读片段周围的正文。',
115
+ parameters: {
116
+ type: 'object',
117
+ additionalProperties: false,
118
+ required: ['query'],
119
+ properties: {
120
+ query: { type: 'string', description: '检索词,可以是关键词、短语或一句话' },
121
+ kbIds: {
122
+ type: 'array',
123
+ description: '只在这些知识库里搜(可选)',
124
+ items: { type: 'string' },
125
+ },
126
+ limit: { type: 'number', description: `最多返回几条(默认 8,上限 ${MAX_SEARCH_LIMIT})` },
127
+ mode: { type: 'string', enum: ['keyword', 'hybrid'], description: 'keyword=关键词;hybrid=关键词+向量(需要用户配置了向量服务)' },
128
+ },
129
+ },
130
+ output: {
131
+ schema: {
132
+ type: 'object',
133
+ additionalProperties: false,
134
+ required: ['summary', 'hits'],
135
+ properties: {
136
+ summary: { type: 'string', description: '一句话结论:命中几条、用了什么模式' },
137
+ hits: { type: 'array', description: '命中片段', items: HIT_SCHEMA },
138
+ },
139
+ },
140
+ render: (_args, value) => {
141
+ const lines = [value.summary];
142
+ value.hits.forEach((hit, index) => {
143
+ lines.push(`${index + 1}. ${hit.locator}${hit.heading ? ` · ${hit.heading}` : ''}${hit.page ? `(第 ${hit.page} 页)` : ''}`);
144
+ lines.push(` ${hit.snippet}`);
145
+ lines.push(` docId=${hit.docId} offset=${hit.charStart}`);
146
+ });
147
+ return [{ type: 'text', text: lines.join('\n') }];
148
+ },
149
+ },
150
+ async execute(args) {
151
+ const query = String(args.query ?? '').trim();
152
+ const limit = Math.min(MAX_SEARCH_LIMIT, Math.max(1, Number(args.limit) || 8));
153
+ const kbIds = Array.isArray(args.kbIds) ? args.kbIds.filter((item) => typeof item === 'string') : [];
154
+ if (!query) return { summary: '检索词为空。', hits: [] };
155
+ const result = await index.search({
156
+ query,
157
+ kbIds,
158
+ limit,
159
+ mode: args.mode === 'hybrid' ? 'hybrid' : 'keyword',
160
+ });
161
+ if (!result.hits.length) {
162
+ return {
163
+ summary: `在知识库里没有找到与「${query}」相关的内容(模式:${result.mode})。可以先 kb_list 看看有哪些库和文档。`,
164
+ hits: [],
165
+ };
166
+ }
167
+ return {
168
+ summary: `在知识库里命中 ${result.hits.length} 段与「${query}」相关的内容(模式:${result.mode})。`,
169
+ hits: result.hits.map((hit) => ({
170
+ docId: hit.nodeId,
171
+ name: hit.name,
172
+ locator: hit.locator,
173
+ heading: hit.heading || '',
174
+ snippet: hit.snippet,
175
+ charStart: hit.charStart,
176
+ page: hit.page ?? 0,
177
+ })),
178
+ };
179
+ },
180
+ };
181
+
182
+ // ── kb_read ────────────────────────────────────────────────────────────
183
+ const readTool = {
184
+ name: 'kb_read',
185
+ description:
186
+ '读取知识库里某篇文档的正文(按字符偏移分页,单次最多 6000 字)。'
187
+ + '先用 kb_search 拿到 docId 和 charStart,再用 offset 读命中位置附近的内容。',
188
+ parameters: {
189
+ type: 'object',
190
+ additionalProperties: false,
191
+ required: ['docId'],
192
+ properties: {
193
+ docId: { type: 'string', description: 'kb_search / kb_list 返回的文档 id' },
194
+ offset: { type: 'number', description: '起始字符偏移,默认 0' },
195
+ limit: { type: 'number', description: `本次最多读多少字(默认 ${MAX_READ_CHARS},上限 ${MAX_READ_CHARS})` },
196
+ },
197
+ },
198
+ output: {
199
+ schema: {
200
+ type: 'object',
201
+ additionalProperties: false,
202
+ required: ['ok', 'summary', 'text'],
203
+ properties: {
204
+ ok: { type: 'boolean', description: '是否读取成功' },
205
+ summary: { type: 'string', description: '一句话说明:哪个文件的哪一段' },
206
+ text: { type: 'string', description: '正文片段' },
207
+ next: { type: 'number', description: '下一页的 offset;为 0 表示已读完' },
208
+ totalChars: { type: 'number', description: '全文总字数' },
209
+ },
210
+ },
211
+ render: (_args, value) => [{ type: 'text', text: `${value.summary}\n\n${value.text}${value.next ? `\n\n(未完,next offset=${value.next})` : ''}` }],
212
+ },
213
+ async execute(args) {
214
+ const docId = String(args.docId ?? '').trim();
215
+ const node = docId ? store.getNode(docId) : null;
216
+ if (!node || node.kind !== 'doc') {
217
+ return { ok: false, summary: `找不到文档 ${docId || '(空)'};先用 kb_search 检索。`, text: '', next: 0, totalChars: 0 };
218
+ }
219
+ if (node.status === 'failed') {
220
+ return { ok: false, summary: `《${node.name}》解析失败:${node.error || '未知原因'}`, text: '', next: 0, totalChars: 0 };
221
+ }
222
+ if (node.status !== 'ready') {
223
+ return { ok: false, summary: `《${node.name}》还在解析中,稍后再试。`, text: '', next: 0, totalChars: 0 };
224
+ }
225
+ const full = store.getText(node.id);
226
+ if (!full) {
227
+ return { ok: false, summary: `《${node.name}》没有可读的正文。`, text: '', next: 0, totalChars: 0 };
228
+ }
229
+ const offset = Math.max(0, Math.min(full.length, Math.trunc(Number(args.offset) || 0)));
230
+ const limit = Math.min(MAX_READ_CHARS, Math.max(200, Number(args.limit) || MAX_READ_CHARS));
231
+ const end = Math.min(full.length, offset + limit);
232
+ const text = full.slice(offset, end);
233
+ const next = end < full.length ? end : 0;
234
+ const crumb = store.breadcrumb(node.id);
235
+ return {
236
+ ok: true,
237
+ summary: `《${node.name}》(${crumb})第 ${offset}-${end} 字,共 ${full.length} 字。`,
238
+ text,
239
+ next,
240
+ totalChars: full.length,
241
+ };
242
+ },
243
+ };
244
+
245
+ return [listTool, searchTool, readTool];
246
+ }
package/lib/util.mjs ADDED
@@ -0,0 +1,129 @@
1
+ // ============================================================================
2
+ // 通用小工具:id、HTTP 收发、请求体读取、跨站防护。
3
+ // 只用 Node 内置模块,不引第三方依赖。
4
+ // ============================================================================
5
+ import { createHash, randomUUID } from 'node:crypto';
6
+
7
+ export const API_BASE = '/api/kb/v1';
8
+
9
+ /** 短 id:前缀 + 10 位十六进制,便于在日志和 URL 里辨认。 */
10
+ export function newId(prefix) {
11
+ return `${prefix}_${randomUUID().replace(/-/g, '').slice(0, 10)}`;
12
+ }
13
+
14
+ export function nowMs() {
15
+ return Date.now();
16
+ }
17
+
18
+ /** 展示用时间(ISO 会被前端格式化,这里只存毫秒)。 */
19
+ export function sha256Hex(buffer) {
20
+ return createHash('sha256').update(buffer).digest('hex');
21
+ }
22
+
23
+ export function sendJson(res, status, body) {
24
+ const payload = JSON.stringify(body ?? null);
25
+ res.writeHead(status, {
26
+ 'content-type': 'application/json; charset=utf-8',
27
+ 'cache-control': 'no-store',
28
+ 'content-length': Buffer.byteLength(payload),
29
+ });
30
+ res.end(payload);
31
+ }
32
+
33
+ export function sendText(res, status, text, type = 'text/plain; charset=utf-8') {
34
+ const payload = Buffer.isBuffer(text) ? text : Buffer.from(String(text ?? ''), 'utf8');
35
+ res.writeHead(status, {
36
+ 'content-type': type,
37
+ 'cache-control': 'no-store',
38
+ 'content-length': payload.length,
39
+ });
40
+ res.end(payload);
41
+ }
42
+
43
+ export function sendBytes(res, status, buffer, type, extraHeaders = {}) {
44
+ const payload = Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer);
45
+ res.writeHead(status, {
46
+ 'content-type': type || 'application/octet-stream',
47
+ 'cache-control': 'no-store',
48
+ 'content-length': payload.length,
49
+ ...extraHeaders,
50
+ });
51
+ res.end(payload);
52
+ }
53
+
54
+ /** 读 JSON/文本请求体,带硬上限,避免恶意大包。 */
55
+ export function readBody(req, limit = 1 << 20) {
56
+ return new Promise((resolve) => {
57
+ const chunks = [];
58
+ let size = 0;
59
+ let overflow = false;
60
+ req.on('data', (chunk) => {
61
+ size += chunk.length;
62
+ if (size > limit) {
63
+ overflow = true;
64
+ return;
65
+ }
66
+ chunks.push(chunk);
67
+ });
68
+ req.on('end', () => {
69
+ if (overflow) return resolve({ ok: false, code: 'too-large' });
70
+ const buffer = Buffer.concat(chunks);
71
+ try {
72
+ const value = JSON.parse(buffer.toString('utf8') || '{}');
73
+ resolve({ ok: true, value: value && typeof value === 'object' ? value : {} });
74
+ } catch {
75
+ resolve({ ok: false, code: 'bad-json' });
76
+ }
77
+ });
78
+ req.on('error', () => resolve({ ok: false, code: 'aborted' }));
79
+ });
80
+ }
81
+
82
+ /**
83
+ * 跨站防护。
84
+ *
85
+ * webServer 的路由没有全局鉴权,用户浏览器里的任意网页都能向 127.0.0.1:<port>
86
+ * 发“简单请求”。这里要求一个自定义头(会触发预检,而我们不应答 CORS,浏览器
87
+ * 就会拦下跨站请求),并在带 Origin 时校验同源。
88
+ */
89
+ export function guard(origin, req) {
90
+ if (req.headers['x-kb-client'] !== '1') return { ok: false, code: 'forbidden' };
91
+ const from = req.headers.origin;
92
+ if (typeof from === 'string' && from && origin && from !== origin) {
93
+ return { ok: false, code: 'forbidden' };
94
+ }
95
+ return { ok: true };
96
+ }
97
+
98
+ /** 从请求头取文件名(客户端用 encodeURIComponent 编码)。 */
99
+ export function filenameFromHeader(req) {
100
+ const raw = req.headers['x-kb-filename'];
101
+ if (typeof raw !== 'string' || !raw) return '';
102
+ try {
103
+ return decodeURIComponent(raw);
104
+ } catch {
105
+ return raw;
106
+ }
107
+ }
108
+
109
+ /** 只保留安全字符,用于展示;落盘永远不用它。 */
110
+ export function sanitizeName(name, fallback = '未命名') {
111
+ const cleaned = String(name ?? '')
112
+ .replace(/[\u0000-\u001f\u007f]/g, '')
113
+ .replace(/[\\/:*?"<>|]/g, ' ')
114
+ .replace(/\s+/g, ' ')
115
+ .trim()
116
+ .slice(0, 120);
117
+ return cleaned || fallback;
118
+ }
119
+
120
+ export function extOf(name) {
121
+ const match = /\.([A-Za-z0-9]{1,12})$/.exec(String(name ?? ''));
122
+ return match ? match[1].toLowerCase() : '';
123
+ }
124
+
125
+ export function clampInt(value, min, max, fallback) {
126
+ const number = Number(value);
127
+ if (!Number.isFinite(number)) return fallback;
128
+ return Math.min(max, Math.max(min, Math.trunc(number)));
129
+ }
package/lib/vision.mjs ADDED
@@ -0,0 +1,140 @@
1
+ // ============================================================================
2
+ // 图片理解:把图片交给视觉模型,产出「结构化描述」当正文。
3
+ //
4
+ // 为什么这么做(而不是图片向量):描述文字能直接进现有的 FTS + 向量链路,
5
+ // 检索命中后 AI 还能通过 kb_read 读到图里写了什么,出处可解释。
6
+ // 失败时就当作没有正文,不影响图片本身的查看。
7
+ // ============================================================================
8
+ import fs from 'node:fs';
9
+ import path from 'node:path';
10
+
11
+ export const VISION_EXTENSIONS = new Set(['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp']);
12
+
13
+ const MIME_BY_EXT = {
14
+ png: 'image/png',
15
+ jpg: 'image/jpeg',
16
+ jpeg: 'image/jpeg',
17
+ gif: 'image/gif',
18
+ webp: 'image/webp',
19
+ bmp: 'image/bmp',
20
+ };
21
+
22
+ const PROMPT = [
23
+ '请把这张图片转成便于全文检索的文字,用中文,按下面的小标题输出,没有的部分写「无」:',
24
+ '【画面】一句话说清这是什么(照片 / 截图 / 表格 / 示意图 / 扫描件 …),主体是什么。',
25
+ '【文字】逐字抄出图中所有可读的文字、标题、按钮、标注;保持原有顺序。',
26
+ '【数据】如果图里有表格、清单、数值、日期、编号,按行整理出来。',
27
+ '【场景】这张图大概用在什么场景(培训材料 / 会议 / 资质文件 / 现场照片 …)。',
28
+ '不要编造看不到的内容;看不清的字写「(字迹不清)」。',
29
+ ].join('\n');
30
+
31
+ // 64×64 的浅灰格纹 PNG,用于「测试连接」。
32
+ // 不能用 1×1:百炼的视觉模型要求宽高都大于 10,太小会直接 400。
33
+ const PROBE_PNG = 'iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAAgElEQVR4nO3RoQ3AAAzAsP7/anH5jhiwpoUEW8rc3e5+t8MFLztc0AEt6IAWdEALOqAFHdCCDmhBB7SgA1rQAS3ogBZ0QAs6oAUd0IIOaEEHtKADWtABLeiAFnRACzqgBR3Qgg5oQQe0oANa0AEt6IAWdEALOqAFHdCCDmjB3w880FECpN+biKgAAAAASUVORK5CYII=';
34
+
35
+ const TIMEOUT_MS = 90_000;
36
+
37
+ function textOf(content) {
38
+ if (typeof content === 'string') return content.trim();
39
+ if (Array.isArray(content)) {
40
+ return content
41
+ .map((part) => (typeof part === 'string' ? part : part?.text ?? ''))
42
+ .join('\n')
43
+ .trim();
44
+ }
45
+ return '';
46
+ }
47
+
48
+ /**
49
+ * OpenAI 兼容的视觉客户端(chat/completions + image_url)。
50
+ * 配置每次调用都重新读,界面上改完即时生效。
51
+ */
52
+ export function createVisionClient({ resolve, logger }) {
53
+ function effective() {
54
+ const raw = (typeof resolve === 'function' ? resolve() : {}) || {};
55
+ const enabled = Boolean(raw.enabled);
56
+ const baseUrl = String(raw.baseUrl ?? '').replace(/\/+$/, '');
57
+ const model = String(raw.model ?? '');
58
+ const key = String(raw.apiKey || process.env.DSH_KB_VISION_KEY || '');
59
+ return { enabled, baseUrl, model, key, usable: enabled && Boolean(baseUrl) && Boolean(model) };
60
+ }
61
+
62
+ async function call(dataUrl) {
63
+ const now = effective();
64
+ if (!now.usable) throw new Error('图片理解未启用或缺少接口地址/模型');
65
+ const response = await fetch(`${now.baseUrl}/chat/completions`, {
66
+ method: 'POST',
67
+ headers: {
68
+ 'content-type': 'application/json',
69
+ ...(now.key ? { authorization: `Bearer ${now.key}` } : {}),
70
+ },
71
+ body: JSON.stringify({
72
+ model: now.model,
73
+ messages: [{
74
+ role: 'user',
75
+ content: [
76
+ { type: 'text', text: PROMPT },
77
+ { type: 'image_url', image_url: { url: dataUrl } },
78
+ ],
79
+ }],
80
+ }),
81
+ signal: AbortSignal.timeout(TIMEOUT_MS),
82
+ });
83
+ if (!response.ok) {
84
+ const detail = await response.text().catch(() => '');
85
+ throw new Error(`HTTP ${response.status}${detail ? `:${detail.slice(0, 300)}` : ''}`);
86
+ }
87
+ const data = await response.json();
88
+ const text = textOf(data?.choices?.[0]?.message?.content);
89
+ if (!text) throw new Error('模型没有返回文字内容');
90
+ return text;
91
+ }
92
+
93
+ return {
94
+ get enabled() {
95
+ return effective().usable;
96
+ },
97
+ describe() {
98
+ const now = effective();
99
+ return {
100
+ configured: now.enabled,
101
+ enabled: now.usable,
102
+ model: now.model,
103
+ baseUrl: now.baseUrl,
104
+ hasKey: Boolean(now.key),
105
+ missing: now.usable || !now.enabled ? [] : ['baseUrl', 'model'].filter((field) => !now[field]),
106
+ };
107
+ },
108
+ /** 给「测试连接」用:拿一张 1×1 图请求一次,能返回文字就算通。 */
109
+ async probe() {
110
+ const now = effective();
111
+ if (!now.usable) return { ok: false, error: '还没填完整(需要接口地址 + 模型,且已启用)' };
112
+ const startedAt = Date.now();
113
+ try {
114
+ const text = await call(`data:image/png;base64,${PROBE_PNG}`);
115
+ return { ok: true, model: now.model, ms: Date.now() - startedAt, sample: text.slice(0, 80) };
116
+ } catch (error) {
117
+ return { ok: false, error: error instanceof Error ? error.message : String(error) };
118
+ }
119
+ },
120
+ /** 把一张图描述成文字;失败抛错,由流水线记成「图片理解失败」。 */
121
+ async describeImage(buffer, ext) {
122
+ const mime = MIME_BY_EXT[ext] ?? 'image/png';
123
+ return call(`data:${mime};base64,${buffer.toString('base64')}`);
124
+ },
125
+ };
126
+ }
127
+
128
+ /** 从文件读图片并描述(流水线用)。 */
129
+ export async function describeImageFile(client, filePath, ext) {
130
+ const buffer = await fs.promises.readFile(filePath);
131
+ return client.describeImage(buffer, ext);
132
+ }
133
+
134
+ export function isVisionExtension(ext) {
135
+ return VISION_EXTENSIONS.has(String(ext || '').toLowerCase());
136
+ }
137
+
138
+ export function visionFileName(filePath) {
139
+ return path.basename(filePath);
140
+ }
package/locale/en.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "meta": {
3
+ "title": "Personal knowledge base",
4
+ "description": "Organize local files into a tree-shaped knowledge base: upload, read in the app, full-text search (PDF and Chinese included). The agent can search it and talk about a single document.",
5
+ "detail": "docs/DETAIL.md"
6
+ },
7
+ "knowledgeBase": {
8
+ "panel": "Knowledge base",
9
+ "panelTip": "Personal knowledge base",
10
+ "newKb": "New library",
11
+ "newFolder": "New folder",
12
+ "import": "Import files",
13
+ "search": "Search library",
14
+ "searchPlaceholder": "Search titles and text…",
15
+ "empty": "Nothing here yet. Drop files in, or create a library.",
16
+ "emptyKb": "This library is empty. Import files or drop them here.",
17
+ "emptySearch": "No match.",
18
+ "askAi": "Ask AI",
19
+ "reindex": "Reindex",
20
+ "remove": "Delete",
21
+ "rename": "Rename",
22
+ "openOriginal": "Original file",
23
+ "readable": "Read here",
24
+ "settings": "Knowledge base",
25
+ "root": "Storage folder",
26
+ "stats": "Statistics",
27
+ "rebuild": "Rebuild all indexes",
28
+ "indexing": "Indexing",
29
+ "ready": "Indexed",
30
+ "failed": "Failed",
31
+ "pending": "Pending"
32
+ }
33
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "meta": {
3
+ "title": "个人知识库",
4
+ "description": "把本地文件整理成树状知识库:上传、在线查看、全文检索(含 PDF 与中文),AI 可以检索这些资料,也可以针对某一篇文档对话。",
5
+ "detail": "docs/DETAIL.md"
6
+ },
7
+ "knowledgeBase": {
8
+ "panel": "知识库",
9
+ "panelTip": "个人知识库",
10
+ "newKb": "新建知识库",
11
+ "newFolder": "新建文件夹",
12
+ "import": "导入文件",
13
+ "search": "搜索知识库",
14
+ "searchPlaceholder": "搜索标题或正文…",
15
+ "empty": "还没有内容。拖文件进来,或点「新建知识库」开始。",
16
+ "emptyKb": "这个知识库还是空的。点「导入文件」或把文件拖进来。",
17
+ "emptySearch": "没有找到匹配的内容。",
18
+ "askAi": "问 AI",
19
+ "reindex": "重新索引",
20
+ "remove": "删除",
21
+ "rename": "重命名",
22
+ "openOriginal": "原文件",
23
+ "readable": "在线阅读",
24
+ "settings": "知识库",
25
+ "root": "存放目录",
26
+ "stats": "统计",
27
+ "rebuild": "重建全部索引",
28
+ "indexing": "索引中",
29
+ "ready": "已索引",
30
+ "failed": "解析失败",
31
+ "pending": "等待解析"
32
+ }
33
+ }
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@xiaofanzhao/dsh-plugin-knowledge-base",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "个人知识库:树状目录、文件上传与在线查看、全文检索(含 PDF 与中文),AI 可通过工具检索并针对文档对话。",
5
+ "type": "module",
6
+ "main": "./index.js",
7
+ "exports": {
8
+ ".": "./index.js",
9
+ "./client": "./client.js",
10
+ "./locale/*.json": "./locale/*.json",
11
+ "./icon": "./icon.svg",
12
+ "./package.json": "./package.json"
13
+ },
14
+ "files": [
15
+ "index.js",
16
+ "client.js",
17
+ "cordis.patch.yml",
18
+ "lib",
19
+ "locale",
20
+ "docs",
21
+ "icon.svg"
22
+ ],
23
+ "keywords": [
24
+ "deepseek-harness",
25
+ "dsh",
26
+ "dsh-plugin",
27
+ "knowledge-base",
28
+ "rag",
29
+ "full-text-search"
30
+ ],
31
+ "author": "FSNH",
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/FSNH/dsh-plugin-knowledge-base.git"
36
+ },
37
+ "homepage": "https://github.com/FSNH/dsh-plugin-knowledge-base#readme",
38
+ "bugs": {
39
+ "url": "https://github.com/FSNH/dsh-plugin-knowledge-base/issues"
40
+ },
41
+ "engines": {
42
+ "node": ">=24"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public",
46
+ "registry": "https://registry.npmjs.org/"
47
+ },
48
+ "dependencies": {
49
+ "pdfjs-dist": "^4.10.38"
50
+ },
51
+ "dsh": {
52
+ "manifestVersion": 1,
53
+ "bundle": {
54
+ "patch": "./cordis.patch.yml"
55
+ },
56
+ "client": {
57
+ "platform": "web",
58
+ "immediately": true,
59
+ "inject": [
60
+ "@deepseek-ai/dsh-client-ui-layout",
61
+ "@deepseek-ai/dsh-client-ui-sidebar"
62
+ ]
63
+ }
64
+ }
65
+ }