dsh-knowledge-library 0.1.0 → 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/CHANGELOG.md +37 -0
- package/README.md +123 -18
- package/dist/client.js +1699 -374
- package/dist/core/extract.d.ts +1 -0
- package/dist/core/extract.js +62 -5
- package/dist/core/fetch.js +82 -11
- package/dist/core/grouping.d.ts +6 -0
- package/dist/core/grouping.js +71 -0
- package/dist/core/incremental.d.ts +14 -0
- package/dist/core/incremental.js +52 -0
- package/dist/core/jobs.d.ts +1 -0
- package/dist/core/jobs.js +4 -0
- package/dist/core/knowledge.d.ts +37 -0
- package/dist/core/knowledge.js +617 -0
- package/dist/core/library.d.ts +20 -2
- package/dist/core/library.js +271 -12
- package/dist/core/page-access.d.ts +6 -0
- package/dist/core/page-access.js +38 -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 +121 -4
- package/dist/index.js +17 -5
- package/dist/knowledge-model.d.ts +18 -0
- package/dist/knowledge-model.js +116 -0
- package/dist/preview-settings.d.ts +6 -0
- package/dist/preview-settings.js +42 -0
- package/dist/public/app.css +385 -182
- package/dist/public/app.js +11 -7
- package/dist/public/index.html +1 -1
- package/dist/standalone.js +8 -3
- package/dist/tools.d.ts +2 -1
- package/dist/tools.js +10 -1
- package/dist/types.d.ts +143 -1
- package/dist/ui/App.js +244 -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/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 +4 -1
package/dist/public/index.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!doctype html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>拾页 · 本地资料库</title><link rel="stylesheet" href="/app.css"></head><body><div id="root"></div><script src="/app.js"></script></body></html>
|
|
1
|
+
<!doctype html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>拾页 · 本地资料库</title><link rel="stylesheet" href="/app.css"></head><body class="kl-preview"><div id="root"></div><script src="/app.js"></script></body></html>
|
package/dist/standalone.js
CHANGED
|
@@ -6,12 +6,17 @@ 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
8
|
import { fetchPublicPage } from './core/fetch.js';
|
|
9
|
+
import { createPreviewSettings } from './preview-settings.js';
|
|
10
|
+
import { KnowledgeQueue } from './core/knowledge.js';
|
|
11
|
+
import { previewKnowledgeModel } from './knowledge-model.js';
|
|
9
12
|
const root = resolve(process.env.KNOWLEDGE_LIBRARY_ROOT || join(homedir(), 'Documents', 'DSH-Knowledge-Library'));
|
|
10
13
|
const library = new Library(root);
|
|
11
|
-
const
|
|
14
|
+
const knowledge = new KnowledgeQueue(library, previewKnowledgeModel());
|
|
15
|
+
const settings = createPreviewSettings(library, { allowProxyFakeIp: process.env.KNOWLEDGE_LIBRARY_ALLOW_FAKE_IP === '1' });
|
|
16
|
+
const queue = new ImportQueue(library, (url, signal) => fetchPublicPage(url, signal, settings.fetchPolicy()));
|
|
12
17
|
const port = Number(process.env.PORT || 4317);
|
|
13
18
|
let origin = `http://127.0.0.1:${port}`;
|
|
14
|
-
const api = createHandler(library, queue, () => origin);
|
|
19
|
+
const api = createHandler(library, queue, () => origin, settings, knowledge);
|
|
15
20
|
const server = createServer((req, res) => {
|
|
16
21
|
if (req.url?.startsWith(API_PATH))
|
|
17
22
|
void api(req, res);
|
|
@@ -30,7 +35,7 @@ async function shutdown() {
|
|
|
30
35
|
stopping = true;
|
|
31
36
|
server.close();
|
|
32
37
|
server.closeAllConnections();
|
|
33
|
-
await queue.close();
|
|
38
|
+
await Promise.all([queue.close(), knowledge.close()]);
|
|
34
39
|
library.close();
|
|
35
40
|
}
|
|
36
41
|
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[];
|
|
@@ -38,6 +42,16 @@ export interface MaterialDetail extends Material {
|
|
|
38
42
|
segments: Segment[];
|
|
39
43
|
path: string;
|
|
40
44
|
}
|
|
45
|
+
export interface TrashSnapshot {
|
|
46
|
+
count: number;
|
|
47
|
+
pending: number;
|
|
48
|
+
token: string;
|
|
49
|
+
}
|
|
50
|
+
export interface EmptyTrashResult {
|
|
51
|
+
deleted: number;
|
|
52
|
+
pending: number;
|
|
53
|
+
errors: string[];
|
|
54
|
+
}
|
|
41
55
|
export interface CaptureFields {
|
|
42
56
|
title?: string;
|
|
43
57
|
category?: string;
|
|
@@ -52,6 +66,7 @@ export interface SearchOptions {
|
|
|
52
66
|
tag?: string;
|
|
53
67
|
collection?: string;
|
|
54
68
|
kind?: string;
|
|
69
|
+
trashed?: boolean;
|
|
55
70
|
limit?: number;
|
|
56
71
|
offset?: number;
|
|
57
72
|
}
|
|
@@ -75,4 +90,131 @@ export interface ImportJob {
|
|
|
75
90
|
attempts: number;
|
|
76
91
|
materialId?: string;
|
|
77
92
|
error?: string;
|
|
93
|
+
errorCode?: 'PAGE_REQUIRES_BROWSER';
|
|
94
|
+
}
|
|
95
|
+
export interface KnowledgeDraft {
|
|
96
|
+
title: string;
|
|
97
|
+
content: string;
|
|
98
|
+
tags: string[];
|
|
99
|
+
citations: Citation[];
|
|
100
|
+
category?: string;
|
|
101
|
+
}
|
|
102
|
+
export interface KnowledgeSource {
|
|
103
|
+
id: string;
|
|
104
|
+
title: string;
|
|
105
|
+
fingerprint: string;
|
|
106
|
+
category?: string;
|
|
107
|
+
tags?: string[];
|
|
108
|
+
}
|
|
109
|
+
export interface NoteIntegration {
|
|
110
|
+
recommendation: 'new' | 'append' | 'duplicate';
|
|
111
|
+
choice: 'new' | 'append' | 'duplicate';
|
|
112
|
+
reason: string;
|
|
113
|
+
overlaps: string[];
|
|
114
|
+
additions: string[];
|
|
115
|
+
conflicts: string[];
|
|
116
|
+
content: string;
|
|
117
|
+
search: {
|
|
118
|
+
scanned: number;
|
|
119
|
+
matched: number;
|
|
120
|
+
compared: number;
|
|
121
|
+
oversized: number;
|
|
122
|
+
};
|
|
123
|
+
target?: {
|
|
124
|
+
id: string;
|
|
125
|
+
title: string;
|
|
126
|
+
category: string;
|
|
127
|
+
revision: number;
|
|
128
|
+
fingerprint: string;
|
|
129
|
+
content: string;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export interface SourceAnalysis {
|
|
133
|
+
sourceId: string;
|
|
134
|
+
theme: string;
|
|
135
|
+
concepts: string[];
|
|
136
|
+
summary: string;
|
|
137
|
+
usage: string;
|
|
138
|
+
category: string;
|
|
139
|
+
tags: string[];
|
|
140
|
+
certainty: 'clear' | 'uncertain';
|
|
141
|
+
uncertainty: string;
|
|
142
|
+
citations: Citation[];
|
|
143
|
+
}
|
|
144
|
+
export interface KnowledgeGroup {
|
|
145
|
+
id: string;
|
|
146
|
+
title: string;
|
|
147
|
+
reason: string;
|
|
148
|
+
sourceIds: string[];
|
|
149
|
+
category: string;
|
|
150
|
+
tags: string[];
|
|
151
|
+
}
|
|
152
|
+
export interface GroupingPlan {
|
|
153
|
+
groups: KnowledgeGroup[];
|
|
154
|
+
unassigned: Array<{
|
|
155
|
+
sourceId: string;
|
|
156
|
+
reason: string;
|
|
157
|
+
}>;
|
|
158
|
+
applyClassification?: boolean;
|
|
159
|
+
}
|
|
160
|
+
export interface ClassificationStep {
|
|
161
|
+
sourceId: string;
|
|
162
|
+
before: {
|
|
163
|
+
category: string;
|
|
164
|
+
tags: string[];
|
|
165
|
+
};
|
|
166
|
+
after: {
|
|
167
|
+
category: string;
|
|
168
|
+
tags: string[];
|
|
169
|
+
};
|
|
170
|
+
done: boolean;
|
|
171
|
+
}
|
|
172
|
+
export interface ClassificationJournal {
|
|
173
|
+
apply: boolean;
|
|
174
|
+
version: number;
|
|
175
|
+
direction: 'apply' | 'rollback';
|
|
176
|
+
steps: ClassificationStep[];
|
|
177
|
+
}
|
|
178
|
+
export interface KnowledgeJob {
|
|
179
|
+
id: string;
|
|
180
|
+
sourceIds: string[];
|
|
181
|
+
sources: KnowledgeSource[];
|
|
182
|
+
topic: string;
|
|
183
|
+
status: 'queued' | 'running' | 'grouping' | 'classifying' | 'grouped' | 'draft' | 'completed' | 'failed' | 'cancelled' | 'discarded';
|
|
184
|
+
mode?: 'compose' | 'smart';
|
|
185
|
+
parentId?: string;
|
|
186
|
+
groupId?: string;
|
|
187
|
+
analyses?: SourceAnalysis[];
|
|
188
|
+
plan?: GroupingPlan;
|
|
189
|
+
planVersion?: number;
|
|
190
|
+
classification?: ClassificationJournal;
|
|
191
|
+
children?: Array<{
|
|
192
|
+
groupId: string;
|
|
193
|
+
jobId: string;
|
|
194
|
+
}>;
|
|
195
|
+
createdAt: string;
|
|
196
|
+
updatedAt: string;
|
|
197
|
+
progress: string;
|
|
198
|
+
model?: string;
|
|
199
|
+
modelCalls?: number;
|
|
200
|
+
incremental?: boolean;
|
|
201
|
+
integration?: NoteIntegration;
|
|
202
|
+
error?: string;
|
|
203
|
+
draft?: KnowledgeDraft;
|
|
204
|
+
draftVersion: number;
|
|
205
|
+
noteId?: string;
|
|
206
|
+
}
|
|
207
|
+
export interface KnowledgeState {
|
|
208
|
+
status: 'pending' | 'running' | 'grouping' | 'draft' | 'completed' | 'failed';
|
|
209
|
+
jobId?: string;
|
|
210
|
+
noteIds: string[];
|
|
211
|
+
}
|
|
212
|
+
export interface KnowledgeOverview {
|
|
213
|
+
supported: boolean;
|
|
214
|
+
smartSupported?: boolean;
|
|
215
|
+
available: boolean;
|
|
216
|
+
model?: string;
|
|
217
|
+
reason?: string;
|
|
218
|
+
jobs: KnowledgeJob[];
|
|
219
|
+
states: Record<string, KnowledgeState>;
|
|
78
220
|
}
|