dsh-knowledge-library 0.1.1 → 0.3.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/CHANGELOG.md +40 -0
- package/README.md +133 -14
- package/dist/client.js +1654 -304
- package/dist/core/extract.d.ts +5 -0
- package/dist/core/extract.js +78 -8
- package/dist/core/fetch.d.ts +5 -0
- package/dist/core/fetch.js +102 -25
- package/dist/core/grouping.d.ts +6 -0
- package/dist/core/grouping.js +71 -0
- package/dist/core/image-capture.d.ts +33 -0
- package/dist/core/image-capture.js +196 -0
- package/dist/core/incremental.d.ts +14 -0
- package/dist/core/incremental.js +52 -0
- package/dist/core/jobs.d.ts +21 -1
- package/dist/core/jobs.js +101 -12
- package/dist/core/knowledge.d.ts +37 -0
- package/dist/core/knowledge.js +619 -0
- package/dist/core/library.d.ts +36 -2
- package/dist/core/library.js +363 -17
- package/dist/core/page-access.d.ts +6 -0
- package/dist/core/page-access.js +38 -0
- package/dist/core/page-images.d.ts +15 -0
- package/dist/core/page-images.js +97 -0
- package/dist/core/purge.d.ts +20 -0
- package/dist/core/purge.js +106 -0
- package/dist/directory-settings.d.ts +18 -0
- package/dist/directory-settings.js +92 -0
- package/dist/http.d.ts +3 -1
- package/dist/http.js +152 -4
- package/dist/index.js +22 -7
- package/dist/knowledge-model.d.ts +30 -0
- package/dist/knowledge-model.js +194 -0
- package/dist/preview-settings.d.ts +6 -0
- package/dist/preview-settings.js +42 -0
- package/dist/public/app.css +145 -2
- package/dist/public/app.js +10 -6
- package/dist/standalone.js +12 -4
- package/dist/tools.d.ts +2 -1
- package/dist/tools.js +10 -1
- package/dist/types.d.ts +199 -1
- package/dist/ui/App.js +248 -47
- package/dist/ui/Dialog.d.ts +7 -0
- package/dist/ui/Dialog.js +32 -0
- package/dist/ui/Grouping.d.ts +12 -0
- package/dist/ui/Grouping.js +93 -0
- package/dist/ui/ImageCapture.d.ts +18 -0
- package/dist/ui/ImageCapture.js +76 -0
- package/dist/ui/Knowledge.d.ts +26 -0
- package/dist/ui/Knowledge.js +106 -0
- package/dist/ui/api.d.ts +7 -0
- package/dist/ui/api.js +16 -0
- package/dist/ui/icons.js +2 -0
- package/package.json +5 -1
package/dist/standalone.js
CHANGED
|
@@ -5,13 +5,21 @@ import { join } from 'node:path';
|
|
|
5
5
|
import { Library } from './core/library.js';
|
|
6
6
|
import { ImportQueue } from './core/jobs.js';
|
|
7
7
|
import { API_PATH, createHandler, serveAsset } from './http.js';
|
|
8
|
-
import { fetchPublicPage } from './core/fetch.js';
|
|
8
|
+
import { fetchPublicImage, fetchPublicPage } from './core/fetch.js';
|
|
9
|
+
import { ImageCapture } from './core/image-capture.js';
|
|
10
|
+
import { createPreviewSettings } from './preview-settings.js';
|
|
11
|
+
import { KnowledgeQueue } from './core/knowledge.js';
|
|
12
|
+
import { previewKnowledgeModel } from './knowledge-model.js';
|
|
9
13
|
const root = resolve(process.env.KNOWLEDGE_LIBRARY_ROOT || join(homedir(), 'Documents', 'DSH-Knowledge-Library'));
|
|
10
14
|
const library = new Library(root);
|
|
11
|
-
const
|
|
15
|
+
const model = previewKnowledgeModel();
|
|
16
|
+
const knowledge = new KnowledgeQueue(library, model);
|
|
17
|
+
const settings = createPreviewSettings(library, { allowProxyFakeIp: process.env.KNOWLEDGE_LIBRARY_ALLOW_FAKE_IP === '1' });
|
|
18
|
+
const images = new ImageCapture(library, model, (url, signal, _policy, referer) => fetchPublicImage(url, signal, settings.fetchPolicy(), referer));
|
|
19
|
+
const queue = new ImportQueue(library, (url, signal) => fetchPublicPage(url, signal, settings.fetchPolicy()), images);
|
|
12
20
|
const port = Number(process.env.PORT || 4317);
|
|
13
21
|
let origin = `http://127.0.0.1:${port}`;
|
|
14
|
-
const api = createHandler(library, queue, () => origin);
|
|
22
|
+
const api = createHandler(library, queue, () => origin, settings, knowledge);
|
|
15
23
|
const server = createServer((req, res) => {
|
|
16
24
|
if (req.url?.startsWith(API_PATH))
|
|
17
25
|
void api(req, res);
|
|
@@ -30,7 +38,7 @@ async function shutdown() {
|
|
|
30
38
|
stopping = true;
|
|
31
39
|
server.close();
|
|
32
40
|
server.closeAllConnections();
|
|
33
|
-
await queue.close();
|
|
41
|
+
await Promise.all([queue.close(), knowledge.close()]);
|
|
34
42
|
library.close();
|
|
35
43
|
}
|
|
36
44
|
process.on('SIGINT', () => void shutdown());
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ToolDefinition } from '@deepseek-ai/dsh-tools';
|
|
2
2
|
import type { Library } from './core/library.js';
|
|
3
3
|
import type { ImportQueue } from './core/jobs.js';
|
|
4
|
-
|
|
4
|
+
import type { KnowledgeQueue } from './core/knowledge.js';
|
|
5
|
+
export declare function createTools(library: Library, queue: ImportQueue, knowledge?: KnowledgeQueue): ToolDefinition[];
|
package/dist/tools.js
CHANGED
|
@@ -12,7 +12,7 @@ function resultSummary(result) {
|
|
|
12
12
|
const { content, segments, path, ...material } = result.material;
|
|
13
13
|
return { ...material, duplicate: result.duplicate, segmentCount: segments.length, path };
|
|
14
14
|
}
|
|
15
|
-
export function createTools(library, queue) {
|
|
15
|
+
export function createTools(library, queue, knowledge) {
|
|
16
16
|
const tool = (name, description, parameters, execute, readOnly = false) => defineTool({
|
|
17
17
|
name, description, parameters,
|
|
18
18
|
output: { schema: { type: 'json' }, render: (_args, value) => [{ type: 'text', text: JSON.stringify(value) }] },
|
|
@@ -58,5 +58,14 @@ export function createTools(library, queue) {
|
|
|
58
58
|
retryId: { type: 'string' },
|
|
59
59
|
}, args => args.retryId ? queue.retry(args.retryId) : queue.list()),
|
|
60
60
|
tool('library_overview', '查看资料库统计、分类、专题、标签和索引警告。', {}, () => library.stats(), true),
|
|
61
|
+
...(knowledge ? [
|
|
62
|
+
tool('library_knowledge_generate', '选择1至10份原始资料。多篇默认smart:逐篇分析、智能分组,等待用户确认分类后按组生成独立草稿;单篇默认compose直接生成草稿。已知同主题也可显式compose。正式笔记均待用户确认,不自动发布。', {
|
|
63
|
+
sourceIds: { type: 'array', required: true, items: { type: 'string' } }, topic: { type: 'string', description: '围绕什么问题整理,可选' },
|
|
64
|
+
mode: { type: 'string', enum: ['smart', 'compose'], description: 'smart智能分组,compose同主题直接综合;省略时多篇smart、单篇compose' },
|
|
65
|
+
}, args => knowledge.add(args.sourceIds, args.topic, args.mode)),
|
|
66
|
+
tool('library_knowledge_status', '查看知识整理状态、失败原因和待确认草稿;提醒用户到资料库确认保存,不代替用户确认。', {
|
|
67
|
+
id: { type: 'string', description: '知识整理任务ID;省略查看总览' },
|
|
68
|
+
}, args => args.id ? knowledge.get(args.id) : knowledge.overview(), true),
|
|
69
|
+
] : []),
|
|
61
70
|
];
|
|
62
71
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -24,10 +24,14 @@ export interface Material {
|
|
|
24
24
|
author?: string;
|
|
25
25
|
createdAt: string;
|
|
26
26
|
updatedAt: string;
|
|
27
|
+
deletedAt?: string;
|
|
28
|
+
deletionId?: string;
|
|
29
|
+
knowledgeJobId?: string;
|
|
30
|
+
knowledgeUpdateJobIds?: string[];
|
|
27
31
|
contentHash: string;
|
|
28
32
|
textChecksum?: string;
|
|
29
33
|
segmentsChecksum?: string;
|
|
30
|
-
revision:
|
|
34
|
+
revision: number;
|
|
31
35
|
originalName?: string;
|
|
32
36
|
originalFile?: string;
|
|
33
37
|
citations: Citation[];
|
|
@@ -37,6 +41,61 @@ export interface MaterialDetail extends Material {
|
|
|
37
41
|
content: string;
|
|
38
42
|
segments: Segment[];
|
|
39
43
|
path: string;
|
|
44
|
+
images?: PageImageView[];
|
|
45
|
+
}
|
|
46
|
+
export interface PageImageCandidate {
|
|
47
|
+
url: string;
|
|
48
|
+
alt: string;
|
|
49
|
+
}
|
|
50
|
+
export interface PageImageRecord extends PageImageCandidate {
|
|
51
|
+
id: string;
|
|
52
|
+
status: 'pending' | 'downloading' | 'recognizing' | 'completed' | 'failed' | 'skipped';
|
|
53
|
+
attempts: number;
|
|
54
|
+
error?: string;
|
|
55
|
+
fileName?: string;
|
|
56
|
+
checksum?: string;
|
|
57
|
+
mediaType?: 'image/png' | 'image/jpeg' | 'image/webp' | 'image/gif';
|
|
58
|
+
width?: number;
|
|
59
|
+
height?: number;
|
|
60
|
+
bytes?: number;
|
|
61
|
+
finalUrl?: string;
|
|
62
|
+
text?: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
uncertainty?: string;
|
|
65
|
+
}
|
|
66
|
+
export interface PageImageManifest {
|
|
67
|
+
schemaVersion: 1;
|
|
68
|
+
model: string;
|
|
69
|
+
limit: number;
|
|
70
|
+
excluded: number;
|
|
71
|
+
records: PageImageRecord[];
|
|
72
|
+
}
|
|
73
|
+
export type PageImageView = Omit<PageImageRecord, 'text' | 'description' | 'fileName' | 'checksum'> & {
|
|
74
|
+
segmentId?: string;
|
|
75
|
+
originalAvailable: boolean;
|
|
76
|
+
model: string;
|
|
77
|
+
};
|
|
78
|
+
export interface ImageCaptureSettings {
|
|
79
|
+
enabled: boolean;
|
|
80
|
+
maxImages: number;
|
|
81
|
+
model?: string;
|
|
82
|
+
version: number;
|
|
83
|
+
}
|
|
84
|
+
export interface ImageCaptureStatus extends ImageCaptureSettings {
|
|
85
|
+
supported: boolean;
|
|
86
|
+
available: boolean;
|
|
87
|
+
currentModel?: string;
|
|
88
|
+
reason?: string;
|
|
89
|
+
}
|
|
90
|
+
export interface TrashSnapshot {
|
|
91
|
+
count: number;
|
|
92
|
+
pending: number;
|
|
93
|
+
token: string;
|
|
94
|
+
}
|
|
95
|
+
export interface EmptyTrashResult {
|
|
96
|
+
deleted: number;
|
|
97
|
+
pending: number;
|
|
98
|
+
errors: string[];
|
|
40
99
|
}
|
|
41
100
|
export interface CaptureFields {
|
|
42
101
|
title?: string;
|
|
@@ -52,6 +111,7 @@ export interface SearchOptions {
|
|
|
52
111
|
tag?: string;
|
|
53
112
|
collection?: string;
|
|
54
113
|
kind?: string;
|
|
114
|
+
trashed?: boolean;
|
|
55
115
|
limit?: number;
|
|
56
116
|
offset?: number;
|
|
57
117
|
}
|
|
@@ -75,4 +135,142 @@ export interface ImportJob {
|
|
|
75
135
|
attempts: number;
|
|
76
136
|
materialId?: string;
|
|
77
137
|
error?: string;
|
|
138
|
+
errorCode?: 'PAGE_REQUIRES_BROWSER';
|
|
139
|
+
progress?: string;
|
|
140
|
+
imageCapture?: {
|
|
141
|
+
model: string;
|
|
142
|
+
maxImages: number;
|
|
143
|
+
};
|
|
144
|
+
imageSummary?: {
|
|
145
|
+
total: number;
|
|
146
|
+
completed: number;
|
|
147
|
+
failed: number;
|
|
148
|
+
skipped: number;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
export interface KnowledgeDraft {
|
|
152
|
+
title: string;
|
|
153
|
+
content: string;
|
|
154
|
+
tags: string[];
|
|
155
|
+
citations: Citation[];
|
|
156
|
+
category?: string;
|
|
157
|
+
}
|
|
158
|
+
export interface KnowledgeSource {
|
|
159
|
+
id: string;
|
|
160
|
+
title: string;
|
|
161
|
+
fingerprint: string;
|
|
162
|
+
category?: string;
|
|
163
|
+
tags?: string[];
|
|
164
|
+
}
|
|
165
|
+
export interface NoteIntegration {
|
|
166
|
+
recommendation: 'new' | 'append' | 'duplicate';
|
|
167
|
+
choice: 'new' | 'append' | 'duplicate';
|
|
168
|
+
reason: string;
|
|
169
|
+
overlaps: string[];
|
|
170
|
+
additions: string[];
|
|
171
|
+
conflicts: string[];
|
|
172
|
+
content: string;
|
|
173
|
+
search: {
|
|
174
|
+
scanned: number;
|
|
175
|
+
matched: number;
|
|
176
|
+
compared: number;
|
|
177
|
+
oversized: number;
|
|
178
|
+
};
|
|
179
|
+
target?: {
|
|
180
|
+
id: string;
|
|
181
|
+
title: string;
|
|
182
|
+
category: string;
|
|
183
|
+
revision: number;
|
|
184
|
+
fingerprint: string;
|
|
185
|
+
content: string;
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
export interface SourceAnalysis {
|
|
189
|
+
sourceId: string;
|
|
190
|
+
theme: string;
|
|
191
|
+
concepts: string[];
|
|
192
|
+
summary: string;
|
|
193
|
+
usage: string;
|
|
194
|
+
category: string;
|
|
195
|
+
tags: string[];
|
|
196
|
+
certainty: 'clear' | 'uncertain';
|
|
197
|
+
uncertainty: string;
|
|
198
|
+
citations: Citation[];
|
|
199
|
+
}
|
|
200
|
+
export interface KnowledgeGroup {
|
|
201
|
+
id: string;
|
|
202
|
+
title: string;
|
|
203
|
+
reason: string;
|
|
204
|
+
sourceIds: string[];
|
|
205
|
+
category: string;
|
|
206
|
+
tags: string[];
|
|
207
|
+
}
|
|
208
|
+
export interface GroupingPlan {
|
|
209
|
+
groups: KnowledgeGroup[];
|
|
210
|
+
unassigned: Array<{
|
|
211
|
+
sourceId: string;
|
|
212
|
+
reason: string;
|
|
213
|
+
}>;
|
|
214
|
+
applyClassification?: boolean;
|
|
215
|
+
}
|
|
216
|
+
export interface ClassificationStep {
|
|
217
|
+
sourceId: string;
|
|
218
|
+
before: {
|
|
219
|
+
category: string;
|
|
220
|
+
tags: string[];
|
|
221
|
+
};
|
|
222
|
+
after: {
|
|
223
|
+
category: string;
|
|
224
|
+
tags: string[];
|
|
225
|
+
};
|
|
226
|
+
done: boolean;
|
|
227
|
+
}
|
|
228
|
+
export interface ClassificationJournal {
|
|
229
|
+
apply: boolean;
|
|
230
|
+
version: number;
|
|
231
|
+
direction: 'apply' | 'rollback';
|
|
232
|
+
steps: ClassificationStep[];
|
|
233
|
+
}
|
|
234
|
+
export interface KnowledgeJob {
|
|
235
|
+
id: string;
|
|
236
|
+
sourceIds: string[];
|
|
237
|
+
sources: KnowledgeSource[];
|
|
238
|
+
topic: string;
|
|
239
|
+
status: 'queued' | 'running' | 'grouping' | 'classifying' | 'grouped' | 'draft' | 'completed' | 'failed' | 'cancelled' | 'discarded';
|
|
240
|
+
mode?: 'compose' | 'smart';
|
|
241
|
+
parentId?: string;
|
|
242
|
+
groupId?: string;
|
|
243
|
+
analyses?: SourceAnalysis[];
|
|
244
|
+
plan?: GroupingPlan;
|
|
245
|
+
planVersion?: number;
|
|
246
|
+
classification?: ClassificationJournal;
|
|
247
|
+
children?: Array<{
|
|
248
|
+
groupId: string;
|
|
249
|
+
jobId: string;
|
|
250
|
+
}>;
|
|
251
|
+
createdAt: string;
|
|
252
|
+
updatedAt: string;
|
|
253
|
+
progress: string;
|
|
254
|
+
model?: string;
|
|
255
|
+
modelCalls?: number;
|
|
256
|
+
incremental?: boolean;
|
|
257
|
+
integration?: NoteIntegration;
|
|
258
|
+
error?: string;
|
|
259
|
+
draft?: KnowledgeDraft;
|
|
260
|
+
draftVersion: number;
|
|
261
|
+
noteId?: string;
|
|
262
|
+
}
|
|
263
|
+
export interface KnowledgeState {
|
|
264
|
+
status: 'pending' | 'running' | 'grouping' | 'draft' | 'completed' | 'failed';
|
|
265
|
+
jobId?: string;
|
|
266
|
+
noteIds: string[];
|
|
267
|
+
}
|
|
268
|
+
export interface KnowledgeOverview {
|
|
269
|
+
supported: boolean;
|
|
270
|
+
smartSupported?: boolean;
|
|
271
|
+
available: boolean;
|
|
272
|
+
model?: string;
|
|
273
|
+
reason?: string;
|
|
274
|
+
jobs: KnowledgeJob[];
|
|
275
|
+
states: Record<string, KnowledgeState>;
|
|
78
276
|
}
|