@octopi-agent/engine 0.58.0 → 0.70.7
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/dist/config-schema/context.d.ts +1 -1
- package/dist/config-schema/context.js +1 -1
- package/dist/config-schema/engine.d.ts +122 -1
- package/dist/config-schema/engine.js +4 -1
- package/dist/config-schema/substrate.d.ts +123 -0
- package/dist/config-schema/substrate.js +161 -0
- package/dist/config.d.ts +101 -1
- package/dist/harness/agent/builder.d.ts +15 -1
- package/dist/harness/agent/builder.js +41 -4
- package/dist/harness/agent/config-bridge.js +17 -4
- package/dist/harness/{context/capabilities → capabilities}/document/backends/docx.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/backends/docx.js +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/backends/office-parser.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/backends/office-parser.js +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/backends/pdf.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/backends/pdf.js +13 -3
- package/dist/harness/{context/capabilities → capabilities}/document/backends/plain.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/backends/plain.js +13 -4
- package/dist/harness/{context/capabilities → capabilities}/document/backends/sheet.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/backends/sheet.js +25 -5
- package/dist/harness/{context/capabilities → capabilities}/document/backends/xmind.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/backends/xmind.js +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/errors.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/errors.js +1 -1
- package/dist/harness/capabilities/document/factory.d.ts +33 -0
- package/dist/harness/capabilities/document/factory.js +37 -0
- package/dist/harness/{context/capabilities → capabilities}/document/format.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/format.js +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/html-to-md.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/html-to-md.js +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/index.d.ts +3 -1
- package/dist/harness/{context/capabilities → capabilities}/document/index.js +2 -1
- package/dist/harness/{context/capabilities → capabilities}/document/legacy/factory.d.ts +3 -1
- package/dist/harness/{context/capabilities → capabilities}/document/legacy/factory.js +3 -1
- package/dist/harness/{context/capabilities → capabilities}/document/legacy/soffice.d.ts +3 -1
- package/dist/harness/{context/capabilities → capabilities}/document/legacy/soffice.js +44 -1
- package/dist/harness/{context/capabilities → capabilities}/document/port.d.ts +1 -1
- package/dist/harness/{context/capabilities → capabilities}/document/port.js +4 -4
- package/dist/harness/{context/capabilities → capabilities}/document/types.d.ts +11 -1
- package/dist/harness/{context/capabilities → capabilities}/document/types.js +1 -1
- package/dist/harness/capabilities/document/worker-port.d.ts +13 -0
- package/dist/harness/capabilities/document/worker-port.js +78 -0
- package/dist/harness/context/capabilities/index.d.ts +2 -2
- package/dist/harness/context/capabilities/index.js +2 -2
- package/dist/harness/context/capabilities/summary/gate.js +2 -2
- package/dist/harness/context/capabilities/summary/policies.js +5 -5
- package/dist/harness/context/capabilities/summary/registry.js +29 -24
- package/dist/harness/context/layer-health.js +3 -2
- package/dist/harness/context/layers.d.ts +27 -13
- package/dist/harness/context/layers.js +76 -66
- package/dist/harness/context/system-prompt-assembler.d.ts +3 -0
- package/dist/harness/context/system-prompt-assembler.js +11 -1
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.js +3 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.d.ts +56 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.js +281 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +98 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +250 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/stream.d.ts +124 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/stream.js +372 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.d.ts +109 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.js +8 -0
- package/dist/harness/extension/plugin-ecosystem/index.d.ts +1 -0
- package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.d.ts +10 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +102 -5
- package/dist/harness/extension/plugin-ecosystem/tools/memory.d.ts +11 -1
- package/dist/harness/extension/plugin-ecosystem/tools/memory.js +14 -0
- package/dist/harness/index.d.ts +8 -5
- package/dist/harness/index.js +4 -2
- package/dist/harness/knowledge/adapters.d.ts +8 -5
- package/dist/harness/knowledge/adapters.js +53 -13
- package/dist/harness/knowledge/client.d.ts +197 -0
- package/dist/harness/knowledge/client.js +237 -0
- package/dist/harness/knowledge/connector-fetcher.d.ts +2 -2
- package/dist/harness/knowledge/connectors.d.ts +3 -3
- package/dist/harness/knowledge/connectors.js +14 -8
- package/dist/harness/knowledge/db.d.ts +40 -5
- package/dist/harness/knowledge/db.js +441 -113
- package/dist/harness/knowledge/document-extract-worker.js +55 -12
- package/dist/harness/knowledge/embed-runner.d.ts +53 -0
- package/dist/harness/knowledge/embed-runner.js +171 -0
- package/dist/harness/knowledge/engine-thread.d.ts +1 -0
- package/dist/harness/knowledge/engine-thread.js +302 -0
- package/dist/harness/knowledge/extract-document.d.ts +21 -5
- package/dist/harness/knowledge/extract-document.js +32 -8
- package/dist/harness/knowledge/fetchers.d.ts +14 -3
- package/dist/harness/knowledge/fetchers.js +52 -16
- package/dist/harness/knowledge/file-identity.d.ts +53 -0
- package/dist/harness/knowledge/file-identity.js +172 -0
- package/dist/harness/knowledge/file-index-store.d.ts +50 -0
- package/dist/harness/knowledge/file-index-store.js +132 -0
- package/dist/harness/knowledge/file-limits.d.ts +86 -0
- package/dist/harness/knowledge/file-limits.js +175 -0
- package/dist/harness/knowledge/fts.d.ts +60 -0
- package/dist/harness/knowledge/fts.js +218 -0
- package/dist/harness/knowledge/grounding.d.ts +3 -2
- package/dist/harness/knowledge/http-app.d.ts +50 -0
- package/dist/harness/knowledge/http-app.js +652 -0
- package/dist/harness/knowledge/http-bridge.d.ts +49 -0
- package/dist/harness/knowledge/http-bridge.js +17 -0
- package/dist/harness/knowledge/index-store.d.ts +158 -93
- package/dist/harness/knowledge/index-store.js +982 -441
- package/dist/harness/knowledge/index.d.ts +45 -5
- package/dist/harness/knowledge/index.js +23 -2
- package/dist/harness/knowledge/ingest.d.ts +262 -87
- package/dist/harness/knowledge/ingest.js +1072 -480
- package/dist/harness/knowledge/job-control-state.d.ts +29 -0
- package/dist/harness/knowledge/job-control-state.js +44 -0
- package/dist/harness/knowledge/job-control.d.ts +35 -0
- package/dist/harness/knowledge/job-control.js +86 -0
- package/dist/harness/knowledge/job-queue.d.ts +62 -0
- package/dist/harness/knowledge/job-queue.js +173 -0
- package/dist/harness/knowledge/knowledge-serve-child.d.ts +1 -0
- package/dist/harness/knowledge/knowledge-serve-child.js +100 -0
- package/dist/harness/knowledge/local-stack.d.ts +27 -0
- package/dist/harness/knowledge/local-stack.js +63 -0
- package/dist/harness/knowledge/membership-store.d.ts +65 -0
- package/dist/harness/knowledge/membership-store.js +198 -0
- package/dist/harness/knowledge/network-guard.d.ts +11 -2
- package/dist/harness/knowledge/network-guard.js +130 -85
- package/dist/harness/knowledge/parse-text-in-worker.d.ts +32 -0
- package/dist/harness/knowledge/parse-text-in-worker.js +158 -0
- package/dist/harness/knowledge/query-service.d.ts +272 -0
- package/dist/harness/knowledge/query-service.js +326 -0
- package/dist/harness/knowledge/query-worker-client.d.ts +96 -0
- package/dist/harness/knowledge/query-worker-client.js +207 -0
- package/dist/harness/knowledge/query-worker.d.ts +1 -0
- package/dist/harness/knowledge/query-worker.js +186 -0
- package/dist/harness/knowledge/read-http.d.ts +35 -0
- package/dist/harness/knowledge/read-http.js +373 -0
- package/dist/harness/knowledge/retriever.d.ts +22 -5
- package/dist/harness/knowledge/retriever.js +66 -35
- package/dist/harness/knowledge/secret-scan.d.ts +13 -2
- package/dist/harness/knowledge/secret-scan.js +25 -2
- package/dist/harness/knowledge/serve.d.ts +48 -0
- package/dist/harness/knowledge/serve.js +336 -0
- package/dist/harness/knowledge/source-store.d.ts +97 -19
- package/dist/harness/knowledge/source-store.js +166 -94
- package/dist/harness/knowledge/start-service-process.d.ts +49 -0
- package/dist/harness/knowledge/start-service-process.js +158 -0
- package/dist/harness/knowledge/text-parse-worker.d.ts +1 -0
- package/dist/harness/knowledge/text-parse-worker.js +54 -0
- package/dist/harness/knowledge/types.d.ts +1 -1
- package/dist/harness/knowledge/types.js +1 -1
- package/dist/harness/knowledge/vector-ann.d.ts +42 -0
- package/dist/harness/knowledge/vector-ann.js +68 -0
- package/dist/harness/knowledge/writer-lock.d.ts +13 -0
- package/dist/harness/knowledge/writer-lock.js +71 -0
- package/dist/harness/knowledge/writer-service.d.ts +194 -0
- package/dist/harness/knowledge/writer-service.js +355 -0
- package/dist/harness/knowledge/writer-worker-client.d.ts +102 -0
- package/dist/harness/knowledge/writer-worker-client.js +381 -0
- package/dist/harness/knowledge/writer-worker.d.ts +1 -0
- package/dist/harness/knowledge/writer-worker.js +189 -0
- package/dist/harness/memory/cognition-decay.d.ts +36 -0
- package/dist/harness/memory/cognition-decay.js +55 -0
- package/dist/harness/memory/cognition-gates.d.ts +60 -0
- package/dist/harness/memory/cognition-gates.js +191 -0
- package/dist/harness/memory/cognition-trigger.d.ts +30 -0
- package/dist/harness/memory/cognition-trigger.js +41 -0
- package/dist/harness/memory/cognition-types.d.ts +1 -1
- package/dist/harness/memory/cognition.d.ts +40 -8
- package/dist/harness/memory/cognition.js +432 -79
- package/dist/harness/memory/conceptualizer.d.ts +66 -0
- package/dist/harness/memory/conceptualizer.js +246 -0
- package/dist/harness/memory/index.d.ts +16 -2
- package/dist/harness/memory/index.js +11 -1
- package/dist/harness/memory/sqlite/agent-db.d.ts +9 -0
- package/dist/harness/memory/sqlite/agent-db.js +118 -15
- package/dist/harness/memory/sqlite/cognition-store.d.ts +55 -16
- package/dist/harness/memory/sqlite/cognition-store.js +591 -144
- package/dist/harness/memory/sqlite/embedding.d.ts +5 -2
- package/dist/harness/memory/sqlite/embedding.js +109 -16
- package/dist/harness/memory/sqlite/keyword-search.d.ts +21 -0
- package/dist/harness/memory/sqlite/keyword-search.js +64 -0
- package/dist/harness/memory/sqlite/wisdom-store.d.ts +33 -14
- package/dist/harness/memory/sqlite/wisdom-store.js +257 -44
- package/dist/harness/memory/types.d.ts +331 -16
- package/dist/harness/memory/types.js +49 -0
- package/dist/harness/memory/wisdom-formation.d.ts +101 -0
- package/dist/harness/memory/wisdom-formation.js +304 -0
- package/dist/harness/memory/wisdom-gates.d.ts +50 -0
- package/dist/harness/memory/wisdom-gates.js +204 -0
- package/dist/harness/memory/wisdom-policy.d.ts +107 -0
- package/dist/harness/memory/wisdom-policy.js +220 -0
- package/dist/harness/memory/wisdom-types.d.ts +3 -2
- package/dist/harness/memory/wisdom-types.js +2 -2
- package/dist/harness/memory/wisdom.d.ts +27 -0
- package/dist/harness/memory/wisdom.js +181 -0
- package/dist/harness/run/agent/agent.d.ts +9 -0
- package/dist/harness/run/agent/agent.js +19 -0
- package/dist/harness/run/reliability/run-agent.js +6 -2
- package/dist/harness/run/runner.js +2 -1
- package/dist/harness/session/attachments/service.d.ts +1 -1
- package/dist/harness/session/attachments/service.js +1 -1
- package/dist/harness/session/index.d.ts +1 -0
- package/dist/harness/session/index.js +1 -0
- package/dist/harness/session/title.d.ts +86 -0
- package/dist/harness/session/title.js +268 -0
- package/dist/harness/shared/events/agent-event-map.d.ts +8 -0
- package/dist/harness/shared/events/agent-event-map.js +1 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +3 -1
- package/dist/subsystems/cognition-steward/conceptualize/SUBSYSTEM.md +43 -0
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +50 -0
- package/dist/subsystems/cognition-steward/conceptualize/handler.d.ts +9 -0
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +125 -0
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +6 -0
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +54 -0
- package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +12 -0
- package/dist/subsystems/cognition-steward/consolidate/handler.js +93 -0
- package/dist/subsystems/wisdom-steward/evaluate/config.yaml +50 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.d.ts +18 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.js +91 -0
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +42 -0
- package/dist/subsystems/wisdom-steward/formation/config.yaml +54 -0
- package/dist/subsystems/wisdom-steward/formation/handler.d.ts +18 -0
- package/dist/subsystems/wisdom-steward/formation/handler.js +212 -0
- package/dist/subsystems/wisdom-steward/govern/config.yaml +55 -0
- package/dist/subsystems/wisdom-steward/govern/handler.d.ts +17 -0
- package/dist/subsystems/wisdom-steward/govern/handler.js +68 -0
- package/dist/worker-path.d.ts +8 -0
- package/dist/worker-path.js +15 -0
- package/package.json +2 -2
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* startKnowledgeServiceProcess — fork 独立子进程托管 Knowledge Service
|
|
3
|
+
*
|
|
4
|
+
* 为什么是进程而不是 Worker:知识索引重且稳定不可控,不得与 Gateway 共命运。
|
|
5
|
+
* Worker 仍共享堆/OOM 与进程生命周期,只是把 event loop 挪开,不是故障隔离。
|
|
6
|
+
*
|
|
7
|
+
* fork 根因约束(与 `octopi serve` daemon 同款):
|
|
8
|
+
* - `execArgv: []`:禁止继承父进程 loader/inspect/NODE_OPTIONS 钩子
|
|
9
|
+
* - 剥离 `NODE_CHANNEL_*`:父进程若是 IPC 子进程(vitest / daemon),继承会错绑通道
|
|
10
|
+
* - `stdio` 不用 `inherit`:Windows 管道句柄继承会干扰 IPC
|
|
11
|
+
* - Electron 宿主:`ELECTRON_RUN_AS_NODE=1` + **保持** `process.execPath`。
|
|
12
|
+
* 换成捆绑 node.exe 当 execPath 会切断 Windows 上的 fork IPC。
|
|
13
|
+
*/
|
|
14
|
+
import { fork } from 'node:child_process';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
import { mkdtemp, writeFile, rm } from 'node:fs/promises';
|
|
17
|
+
import { tmpdir } from 'node:os';
|
|
18
|
+
import { join } from 'node:path';
|
|
19
|
+
import { resolveWorkerUrl } from '../../worker-path.js';
|
|
20
|
+
function isElectronHost() {
|
|
21
|
+
return (Boolean(process.versions.electron) ||
|
|
22
|
+
/electron|MiMo\.exe/i.test(process.execPath));
|
|
23
|
+
}
|
|
24
|
+
function childNodeEnv() {
|
|
25
|
+
const env = { ...process.env };
|
|
26
|
+
// 父进程可能是 IPC 子进程(vitest worker / octopi serve daemon):不得把通道句柄带进孙进程
|
|
27
|
+
delete env.NODE_CHANNEL_FD;
|
|
28
|
+
delete env.NODE_CHANNEL_SERIALIZATION;
|
|
29
|
+
delete env.NODE_UNIQUE_ID;
|
|
30
|
+
if (isElectronHost()) {
|
|
31
|
+
env.ELECTRON_RUN_AS_NODE = '1';
|
|
32
|
+
}
|
|
33
|
+
return env;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 在独立子进程启动 Knowledge HTTP Service。
|
|
37
|
+
*
|
|
38
|
+
* @param opts - 与 startKnowledgeService 同构 + embeddingModels(子进程内重建 provider)
|
|
39
|
+
* @returns child + 端口 + stop
|
|
40
|
+
*/
|
|
41
|
+
export async function startKnowledgeServiceProcess(opts) {
|
|
42
|
+
const entry = fileURLToPath(resolveWorkerUrl('./knowledge-serve-child.js', import.meta.url));
|
|
43
|
+
const bootDir = await mkdtemp(join(tmpdir(), 'octopi-kn-boot-'));
|
|
44
|
+
const bootPath = join(bootDir, 'boot.json');
|
|
45
|
+
await writeFile(bootPath, JSON.stringify({
|
|
46
|
+
dbPath: opts.dbPath,
|
|
47
|
+
host: opts.host,
|
|
48
|
+
port: opts.port ?? 18280,
|
|
49
|
+
tokens: opts.tokens,
|
|
50
|
+
documentConfig: opts.documentConfig ?? null,
|
|
51
|
+
embed: opts.embed,
|
|
52
|
+
sqliteVecExtensionPath: opts.sqliteVecExtensionPath,
|
|
53
|
+
embeddingModels: opts.embeddingModels ?? null,
|
|
54
|
+
}), 'utf8');
|
|
55
|
+
// @types/node 的 ForkOptions 未声明 windowsHide 等字段,运行时有效
|
|
56
|
+
// execPath 必须保持 process.execPath:Electron 下换捆绑 node 会切断 IPC
|
|
57
|
+
const forkOpts = {
|
|
58
|
+
stdio: ['ignore', 'ignore', 'ignore', 'ipc'],
|
|
59
|
+
windowsHide: true,
|
|
60
|
+
execArgv: [],
|
|
61
|
+
env: childNodeEnv(),
|
|
62
|
+
};
|
|
63
|
+
const child = fork(entry, [bootPath], forkOpts);
|
|
64
|
+
const startTimeoutMs = opts.startTimeoutMs ?? 30_000;
|
|
65
|
+
try {
|
|
66
|
+
const port = await new Promise((resolve, reject) => {
|
|
67
|
+
const timer = setTimeout(() => reject(new Error('knowledge_process_start_timeout')), startTimeoutMs);
|
|
68
|
+
const settle = (fn) => {
|
|
69
|
+
clearTimeout(timer);
|
|
70
|
+
child.off('message', onMsg);
|
|
71
|
+
fn();
|
|
72
|
+
};
|
|
73
|
+
const onMsg = (msg) => {
|
|
74
|
+
if (msg?.type === 'ready' && typeof msg.port === 'number') {
|
|
75
|
+
const port = msg.port;
|
|
76
|
+
settle(() => resolve(port));
|
|
77
|
+
}
|
|
78
|
+
else if (msg?.type === 'error') {
|
|
79
|
+
settle(() => reject(new Error(msg.error ?? 'knowledge_process_start_failed')));
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
child.on('message', onMsg);
|
|
83
|
+
child.once('error', (err) => {
|
|
84
|
+
settle(() => reject(err));
|
|
85
|
+
});
|
|
86
|
+
child.once('exit', (code, signal) => {
|
|
87
|
+
settle(() => reject(new Error(signal
|
|
88
|
+
? `knowledge_process_signal_${signal}`
|
|
89
|
+
: `knowledge_process_exit_${code ?? 'unknown'}`)));
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
child,
|
|
94
|
+
port,
|
|
95
|
+
stop: async () => {
|
|
96
|
+
await stopChild(child);
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
await rm(bootDir, { recursive: true, force: true }).catch(() => undefined);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function stopChild(child) {
|
|
105
|
+
if (child.exitCode != null || child.signalCode != null)
|
|
106
|
+
return;
|
|
107
|
+
await new Promise((resolve) => {
|
|
108
|
+
const timer = setTimeout(() => {
|
|
109
|
+
try {
|
|
110
|
+
child.kill('SIGTERM');
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
/* already gone */
|
|
114
|
+
}
|
|
115
|
+
const hard = setTimeout(() => {
|
|
116
|
+
try {
|
|
117
|
+
child.kill('SIGKILL');
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
/* ignore */
|
|
121
|
+
}
|
|
122
|
+
resolve();
|
|
123
|
+
}, 2_000);
|
|
124
|
+
hard.unref?.();
|
|
125
|
+
}, 3_000);
|
|
126
|
+
child.once('exit', () => {
|
|
127
|
+
clearTimeout(timer);
|
|
128
|
+
resolve();
|
|
129
|
+
});
|
|
130
|
+
try {
|
|
131
|
+
if (child.connected) {
|
|
132
|
+
child.send({ type: 'close' }, () => {
|
|
133
|
+
/* send callback only observes channel errors; exit path resolves */
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
clearTimeout(timer);
|
|
138
|
+
try {
|
|
139
|
+
child.kill('SIGTERM');
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
/* ignore */
|
|
143
|
+
}
|
|
144
|
+
resolve();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
clearTimeout(timer);
|
|
149
|
+
try {
|
|
150
|
+
child.kill('SIGTERM');
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
/* ignore */
|
|
154
|
+
}
|
|
155
|
+
resolve();
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text parse worker — 读盘 + hash + 切块 + FTS token 全在独立线程
|
|
3
|
+
*
|
|
4
|
+
* 主线程/Service 事件循环不得做多 MB 文本的 CPU 切块与 CJK 二元组。
|
|
5
|
+
*/
|
|
6
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
7
|
+
import { readFile } from 'node:fs/promises';
|
|
8
|
+
import { createHash } from 'node:crypto';
|
|
9
|
+
import { FormatAdapterRegistry, htmlAdapter, markdownAdapter, textAdapter, } from './adapters.js';
|
|
10
|
+
import { buildFtsTokens } from './fts.js';
|
|
11
|
+
function adapterById(id) {
|
|
12
|
+
if (id === 'html')
|
|
13
|
+
return htmlAdapter;
|
|
14
|
+
if (id === 'markdown')
|
|
15
|
+
return markdownAdapter;
|
|
16
|
+
if (id === 'text')
|
|
17
|
+
return textAdapter;
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
async function main() {
|
|
21
|
+
const job = workerData;
|
|
22
|
+
const content = job.inlineText != null ? job.inlineText : await readFile(job.path, 'utf8');
|
|
23
|
+
const contentHash = createHash('sha256').update(content).digest('hex');
|
|
24
|
+
const registry = new FormatAdapterRegistry();
|
|
25
|
+
let adapter = registry.match(job.path) ?? adapterById(job.adapterId);
|
|
26
|
+
if (!adapter) {
|
|
27
|
+
// 虚拟文档常无扩展名:退 text,而不是整源 no_adapter
|
|
28
|
+
adapter = textAdapter;
|
|
29
|
+
}
|
|
30
|
+
const maxTextChars = job.maxTextChars ?? 2_000_000;
|
|
31
|
+
const text = job.sizeDecision === 'partial' && content.length > maxTextChars
|
|
32
|
+
? `${content.slice(0, maxTextChars)}\n\ntruncated: ${content.length - maxTextChars} chars omitted]`
|
|
33
|
+
: content;
|
|
34
|
+
const chunks = adapter.chunk(text, job.path);
|
|
35
|
+
for (const c of chunks) {
|
|
36
|
+
c.ftsToks = buildFtsTokens(c.text, job.path);
|
|
37
|
+
}
|
|
38
|
+
parentPort?.postMessage({
|
|
39
|
+
ok: true,
|
|
40
|
+
contentHash,
|
|
41
|
+
contentLength: content.length,
|
|
42
|
+
adapterId: adapter.id,
|
|
43
|
+
chunks,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
main().catch((err) => {
|
|
47
|
+
parentPort?.postMessage({
|
|
48
|
+
ok: false,
|
|
49
|
+
error: {
|
|
50
|
+
name: err instanceof Error ? err.name : 'Error',
|
|
51
|
+
message: err instanceof Error ? err.message : String(err),
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Knowledge 源模型 — 外生语料登记(arch/knowledge-layer.md)
|
|
3
3
|
*
|
|
4
4
|
* Scope:Global(默认可见可屏蔽)/ Project(显式挂载)/ Session(临时)。
|
|
5
|
-
* 无 Agent
|
|
5
|
+
* 无 Agent 级源。此处是源类型与可见性契约;Index 投影在 index-store/db。
|
|
6
6
|
*/
|
|
7
7
|
/** 不透明 branded id(跨边界防混用;AGENTS:Brand opaque IDs) */
|
|
8
8
|
export type Branded<T, B extends string> = T & {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Knowledge 源模型 — 外生语料登记(arch/knowledge-layer.md)
|
|
3
3
|
*
|
|
4
4
|
* Scope:Global(默认可见可屏蔽)/ Project(显式挂载)/ Session(临时)。
|
|
5
|
-
* 无 Agent
|
|
5
|
+
* 无 Agent 级源。此处是源类型与可见性契约;Index 投影在 index-store/db。
|
|
6
6
|
*/
|
|
7
7
|
/** 从外部输入收窄为 SourceId(仅边界处使用) */
|
|
8
8
|
export function asSourceId(id) {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VectorAnn — 无 sqlite-vec 时的近似候选裁剪(IVF-lite 桶分区)
|
|
3
|
+
*
|
|
4
|
+
* 目标:把 JS 余弦从 O(全库) 降到 O(候选桶)。桶 = 向量粗量化哈希;
|
|
5
|
+
* 查询先扫同桶,不足再扩桶,最后才全扫。sqlite-vec 可用时仍优先 KNN。
|
|
6
|
+
* Index 非权威:bucket 可由 embedding 重算重建。
|
|
7
|
+
*/
|
|
8
|
+
/** 桶数(256:粗量化后碰撞可控,SQL IN 列表也短) */
|
|
9
|
+
export declare const VECTOR_BUCKETS = 256;
|
|
10
|
+
/**
|
|
11
|
+
* 向量 → 桶 id(粗量化:取前若干维 × 8 档,混合成 0..255)
|
|
12
|
+
*
|
|
13
|
+
* @param embedding - 浮点向量
|
|
14
|
+
*/
|
|
15
|
+
export declare function vectorBucket(embedding: number[] | Float32Array): number;
|
|
16
|
+
/** 查询侧:主桶 + 邻桶(汉明距离 1 的 8 个变体) */
|
|
17
|
+
export declare function queryBuckets(embedding: number[]): number[];
|
|
18
|
+
export interface AnnCandidateRow {
|
|
19
|
+
id: string;
|
|
20
|
+
embedding: number[] | null;
|
|
21
|
+
}
|
|
22
|
+
export interface AnnScoredHit {
|
|
23
|
+
id: string;
|
|
24
|
+
score: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 桶裁剪 + 余弦打分(不加载 text)
|
|
28
|
+
*
|
|
29
|
+
* @param queryEmbedding - 查询向量
|
|
30
|
+
* @param rows - 候选行(调用方已按 sourceIds 过滤;可先按 bucket 预取)
|
|
31
|
+
* @param limit - top-k
|
|
32
|
+
* @returns 按分数降序的 id+score
|
|
33
|
+
*/
|
|
34
|
+
export declare function scoreAnnCandidates(queryEmbedding: number[], rows: AnnCandidateRow[], limit: number): AnnScoredHit[];
|
|
35
|
+
/**
|
|
36
|
+
* 由桶分组排序候选:主桶优先,再邻桶,最后其余(供分阶段扫)
|
|
37
|
+
*
|
|
38
|
+
* @param queryEmbedding - 查询向量
|
|
39
|
+
* @param bucketOf - chunkId → bucket
|
|
40
|
+
* @returns 按优先级排序的 bucket id 列表
|
|
41
|
+
*/
|
|
42
|
+
export declare function bucketScanOrder(queryEmbedding: number[]): number[];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VectorAnn — 无 sqlite-vec 时的近似候选裁剪(IVF-lite 桶分区)
|
|
3
|
+
*
|
|
4
|
+
* 目标:把 JS 余弦从 O(全库) 降到 O(候选桶)。桶 = 向量粗量化哈希;
|
|
5
|
+
* 查询先扫同桶,不足再扩桶,最后才全扫。sqlite-vec 可用时仍优先 KNN。
|
|
6
|
+
* Index 非权威:bucket 可由 embedding 重算重建。
|
|
7
|
+
*/
|
|
8
|
+
import { cosineSimilarity } from '../memory/sqlite/vector-search.js';
|
|
9
|
+
/** 桶数(256:粗量化后碰撞可控,SQL IN 列表也短) */
|
|
10
|
+
export const VECTOR_BUCKETS = 256;
|
|
11
|
+
/**
|
|
12
|
+
* 向量 → 桶 id(粗量化:取前若干维 × 8 档,混合成 0..255)
|
|
13
|
+
*
|
|
14
|
+
* @param embedding - 浮点向量
|
|
15
|
+
*/
|
|
16
|
+
export function vectorBucket(embedding) {
|
|
17
|
+
if (!embedding?.length)
|
|
18
|
+
return 0;
|
|
19
|
+
const n = Math.min(8, embedding.length);
|
|
20
|
+
let h = 0;
|
|
21
|
+
for (let i = 0; i < n; i++) {
|
|
22
|
+
// 量化到 [-4, 3] 共 8 档,降低浮点噪声
|
|
23
|
+
const q = Math.max(-4, Math.min(3, Math.floor(Number(embedding[i]) * 2)));
|
|
24
|
+
h = (h * 8 + (q + 4)) & 0xff;
|
|
25
|
+
}
|
|
26
|
+
return h;
|
|
27
|
+
}
|
|
28
|
+
/** 查询侧:主桶 + 邻桶(汉明距离 1 的 8 个变体) */
|
|
29
|
+
export function queryBuckets(embedding) {
|
|
30
|
+
const primary = vectorBucket(embedding);
|
|
31
|
+
const out = new Set([primary]);
|
|
32
|
+
for (let bit = 0; bit < 8; bit++) {
|
|
33
|
+
out.add(primary ^ (1 << bit));
|
|
34
|
+
}
|
|
35
|
+
return [...out];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 桶裁剪 + 余弦打分(不加载 text)
|
|
39
|
+
*
|
|
40
|
+
* @param queryEmbedding - 查询向量
|
|
41
|
+
* @param rows - 候选行(调用方已按 sourceIds 过滤;可先按 bucket 预取)
|
|
42
|
+
* @param limit - top-k
|
|
43
|
+
* @returns 按分数降序的 id+score
|
|
44
|
+
*/
|
|
45
|
+
export function scoreAnnCandidates(queryEmbedding, rows, limit) {
|
|
46
|
+
const hits = [];
|
|
47
|
+
for (const row of rows) {
|
|
48
|
+
const emb = row.embedding;
|
|
49
|
+
if (!emb?.length || emb.length !== queryEmbedding.length)
|
|
50
|
+
continue;
|
|
51
|
+
const sim = cosineSimilarity(queryEmbedding, emb);
|
|
52
|
+
if (sim <= 0)
|
|
53
|
+
continue;
|
|
54
|
+
hits.push({ id: row.id, score: sim });
|
|
55
|
+
}
|
|
56
|
+
hits.sort((a, b) => b.score - a.score);
|
|
57
|
+
return hits.slice(0, limit);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 由桶分组排序候选:主桶优先,再邻桶,最后其余(供分阶段扫)
|
|
61
|
+
*
|
|
62
|
+
* @param queryEmbedding - 查询向量
|
|
63
|
+
* @param bucketOf - chunkId → bucket
|
|
64
|
+
* @returns 按优先级排序的 bucket id 列表
|
|
65
|
+
*/
|
|
66
|
+
export function bucketScanOrder(queryEmbedding) {
|
|
67
|
+
return queryBuckets(queryEmbedding);
|
|
68
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface WriterLockHolder {
|
|
2
|
+
lockPath: string;
|
|
3
|
+
/** 释放锁文件(仅仍属本 PID 时) */
|
|
4
|
+
release(): void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 独占创建 writer.lock;持有者死亡则回收。
|
|
8
|
+
*
|
|
9
|
+
* @param dbPath - knowledge.db 绝对路径
|
|
10
|
+
* @returns lock 路径与 release
|
|
11
|
+
* @throws 已有存活持有者时抛错
|
|
12
|
+
*/
|
|
13
|
+
export declare function acquireKnowledgeWriterLock(dbPath: string): Promise<WriterLockHolder>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge.db writer lock — sole writer process (Knowledge Service child)
|
|
3
|
+
*
|
|
4
|
+
* The lock MUST be held by the process that opens knowledge.db, not by Gateway.
|
|
5
|
+
*/
|
|
6
|
+
import { readFileSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
7
|
+
async function isPidAlive(pid) {
|
|
8
|
+
try {
|
|
9
|
+
process.kill(pid, 0);
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 独占创建 writer.lock;持有者死亡则回收。
|
|
18
|
+
*
|
|
19
|
+
* @param dbPath - knowledge.db 绝对路径
|
|
20
|
+
* @returns lock 路径与 release
|
|
21
|
+
* @throws 已有存活持有者时抛错
|
|
22
|
+
*/
|
|
23
|
+
export async function acquireKnowledgeWriterLock(dbPath) {
|
|
24
|
+
const lockPath = `${dbPath}.writer.lock`;
|
|
25
|
+
const tryWrite = () => {
|
|
26
|
+
writeFileSync(lockPath, JSON.stringify({ pid: process.pid, at: Date.now() }), { encoding: 'utf8', flag: 'wx' });
|
|
27
|
+
};
|
|
28
|
+
try {
|
|
29
|
+
tryWrite();
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
let holderPid;
|
|
33
|
+
try {
|
|
34
|
+
const lock = JSON.parse(readFileSync(lockPath, 'utf8'));
|
|
35
|
+
holderPid = lock.pid;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
holderPid = undefined;
|
|
39
|
+
}
|
|
40
|
+
const holderAlive = holderPid != null && holderPid !== process.pid && (await isPidAlive(holderPid));
|
|
41
|
+
if (holderAlive) {
|
|
42
|
+
throw new Error(`knowledge.db already locked by PID ${holderPid} (${lockPath}); stop the other Knowledge Service or use remote baseUrl`);
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
unlinkSync(lockPath);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
/* ignore */
|
|
49
|
+
}
|
|
50
|
+
tryWrite();
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
lockPath,
|
|
54
|
+
release() {
|
|
55
|
+
try {
|
|
56
|
+
const lock = JSON.parse(readFileSync(lockPath, 'utf8'));
|
|
57
|
+
if (lock.pid !== process.pid)
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
unlinkSync(lockPath);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
/* ignore */
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KnowledgeWriteService — 唯一写者端口(API 线程不得直接摸 SQLite)
|
|
3
|
+
*
|
|
4
|
+
* 生产:Writer Worker 持有 knowledge.db + ingest;API 经 RPC 调用。
|
|
5
|
+
* 测试 / :memory::LocalKnowledgeWriteService 同进程实现(同一接口)。
|
|
6
|
+
*/
|
|
7
|
+
import type { KnowledgeDatabase } from './db.js';
|
|
8
|
+
import { KnowledgeSourceStore } from './source-store.js';
|
|
9
|
+
import { KnowledgeIndexStore } from './index-store.js';
|
|
10
|
+
import { MembershipStore } from './membership-store.js';
|
|
11
|
+
import { KnowledgeIngest, type IngestProgressEvent } from './ingest.js';
|
|
12
|
+
import type { KnowledgeSource } from './types.js';
|
|
13
|
+
import type { KnowledgeJobControlState } from './job-control-state.js';
|
|
14
|
+
import type { DocumentCapabilityConfig } from '../capabilities/document/factory.js';
|
|
15
|
+
import type { EmbeddingProvider } from '../memory/sqlite/embedding.js';
|
|
16
|
+
export interface WriteIdentity {
|
|
17
|
+
tenantId: string;
|
|
18
|
+
gatewayId: string;
|
|
19
|
+
}
|
|
20
|
+
export interface WriteAbortStats {
|
|
21
|
+
cancelledQueued: number;
|
|
22
|
+
abortedRunning: number;
|
|
23
|
+
runningJobs: number;
|
|
24
|
+
}
|
|
25
|
+
export interface WriteResumeStats {
|
|
26
|
+
restoredCancelled: number;
|
|
27
|
+
embedQueued: number;
|
|
28
|
+
}
|
|
29
|
+
export interface WriteRegisterResult extends KnowledgeSource {
|
|
30
|
+
registeredBy: string;
|
|
31
|
+
}
|
|
32
|
+
export interface WriteDescribeResult {
|
|
33
|
+
generatedDescription: string;
|
|
34
|
+
source: string;
|
|
35
|
+
}
|
|
36
|
+
export interface WriteReprocessResult {
|
|
37
|
+
queued: number;
|
|
38
|
+
alreadyActive: number;
|
|
39
|
+
cleanedNonFiles: number;
|
|
40
|
+
resumed: boolean;
|
|
41
|
+
rejected: number;
|
|
42
|
+
}
|
|
43
|
+
/** API → Writer 的变更面。读走 KnowledgeQueryService。 */
|
|
44
|
+
export interface KnowledgeWriteService {
|
|
45
|
+
upsertPrincipal(identity: WriteIdentity, agentId: string, body: {
|
|
46
|
+
displayName?: string;
|
|
47
|
+
status?: string;
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
/** autoRegister=true 且缺失则写入;否则缺失抛 principal_not_registered */
|
|
50
|
+
ensurePrincipal(identity: WriteIdentity, agentId: string, autoRegister: boolean): Promise<void>;
|
|
51
|
+
assertOwnPrincipal(identity: WriteIdentity, agentId: string): Promise<void>;
|
|
52
|
+
createProject(identity: WriteIdentity, input: {
|
|
53
|
+
projectKey: string;
|
|
54
|
+
displayName?: string;
|
|
55
|
+
visibility?: string;
|
|
56
|
+
}): Promise<{
|
|
57
|
+
projectKey: string;
|
|
58
|
+
displayName: string | null;
|
|
59
|
+
registeredBy: string;
|
|
60
|
+
visibility: 'public' | 'private';
|
|
61
|
+
}>;
|
|
62
|
+
removeProject(identity: WriteIdentity, projectKey: string): Promise<{
|
|
63
|
+
projectKey: string;
|
|
64
|
+
removed: boolean;
|
|
65
|
+
}>;
|
|
66
|
+
registerSource(identity: WriteIdentity, input: Record<string, unknown>): Promise<WriteRegisterResult>;
|
|
67
|
+
updateSource(identity: WriteIdentity, sourceId: string, patch: Record<string, unknown>): Promise<KnowledgeSource | null>;
|
|
68
|
+
removeSource(identity: WriteIdentity, sourceId: string): Promise<{
|
|
69
|
+
id: string;
|
|
70
|
+
purgedFiles: number;
|
|
71
|
+
}>;
|
|
72
|
+
describeSource(identity: WriteIdentity, sourceId: string): Promise<WriteDescribeResult | null>;
|
|
73
|
+
reindexSource(sourceId: string): Promise<void>;
|
|
74
|
+
/** 按路径强制重解析(中止态自动 resume) */
|
|
75
|
+
reprocessFiles(sourceId: string, paths: string[]): Promise<WriteReprocessResult>;
|
|
76
|
+
reprocessByFilter(sourceId: string, filter?: {
|
|
77
|
+
status?: string;
|
|
78
|
+
ext?: string;
|
|
79
|
+
q?: string;
|
|
80
|
+
}): Promise<WriteReprocessResult>;
|
|
81
|
+
abortSource(sourceId: string): Promise<WriteAbortStats & KnowledgeJobControlState>;
|
|
82
|
+
resumeSource(sourceId: string): Promise<KnowledgeJobControlState>;
|
|
83
|
+
abortAllOwned(identity: WriteIdentity): Promise<WriteAbortStats>;
|
|
84
|
+
resumeAllOwned(identity: WriteIdentity): Promise<WriteResumeStats>;
|
|
85
|
+
assignProject(identity: WriteIdentity, agentId: string, projectKey: string): Promise<void>;
|
|
86
|
+
unassignProject(identity: WriteIdentity, agentId: string, projectKey: string): Promise<void>;
|
|
87
|
+
hideSource(identity: WriteIdentity, agentId: string, sourceId: string): Promise<void>;
|
|
88
|
+
unhideSource(identity: WriteIdentity, agentId: string, sourceId: string): Promise<void>;
|
|
89
|
+
replaceSessionVisibility(identity: WriteIdentity, agentId: string, sessionId: string, items: Array<{
|
|
90
|
+
targetType: string;
|
|
91
|
+
targetId: string;
|
|
92
|
+
op: string;
|
|
93
|
+
}>): Promise<number>;
|
|
94
|
+
setSessionVisibilityItem(identity: WriteIdentity, sessionId: string, item: {
|
|
95
|
+
targetType: 'project' | 'source';
|
|
96
|
+
targetId: string;
|
|
97
|
+
op: 'include' | 'exclude';
|
|
98
|
+
}): Promise<void>;
|
|
99
|
+
clearSessionVisibility(identity: WriteIdentity, sessionId: string, target?: {
|
|
100
|
+
targetType: 'project' | 'source';
|
|
101
|
+
targetId: string;
|
|
102
|
+
}): Promise<void>;
|
|
103
|
+
isSourceOwner(sourceId: string, gatewayId: string): Promise<boolean>;
|
|
104
|
+
sourceVisibleToGateway(sourceId: string, gatewayId: string): Promise<boolean>;
|
|
105
|
+
startIngestRuntime(): Promise<void>;
|
|
106
|
+
onProgress(cb: (evt: IngestProgressEvent) => void): () => void;
|
|
107
|
+
dispose(): Promise<void>;
|
|
108
|
+
}
|
|
109
|
+
export interface LocalWriteDeps {
|
|
110
|
+
db: KnowledgeDatabase;
|
|
111
|
+
documentConfig?: DocumentCapabilityConfig | null;
|
|
112
|
+
embeddingProvider?: EmbeddingProvider | null;
|
|
113
|
+
embed?: {
|
|
114
|
+
enabled?: boolean;
|
|
115
|
+
embedBatch?: number;
|
|
116
|
+
embedMinIntervalMs?: number;
|
|
117
|
+
embedConcurrency?: number;
|
|
118
|
+
embedSecretPolicy?: 'allow' | 'redact' | 'skip';
|
|
119
|
+
} | null;
|
|
120
|
+
}
|
|
121
|
+
/** 进程内唯一写者(测试 / :memory:)。 */
|
|
122
|
+
export declare class LocalKnowledgeWriteService implements KnowledgeWriteService {
|
|
123
|
+
private readonly deps;
|
|
124
|
+
readonly sources: KnowledgeSourceStore;
|
|
125
|
+
readonly index: KnowledgeIndexStore;
|
|
126
|
+
readonly memberships: MembershipStore;
|
|
127
|
+
readonly ingest: KnowledgeIngest;
|
|
128
|
+
private readonly progressCbs;
|
|
129
|
+
constructor(deps: LocalWriteDeps);
|
|
130
|
+
private get db();
|
|
131
|
+
upsertPrincipal(identity: WriteIdentity, agentId: string, body: {
|
|
132
|
+
displayName?: string;
|
|
133
|
+
status?: string;
|
|
134
|
+
}): Promise<void>;
|
|
135
|
+
ensurePrincipal(identity: WriteIdentity, agentId: string, autoRegister: boolean): Promise<void>;
|
|
136
|
+
assertOwnPrincipal(identity: WriteIdentity, agentId: string): Promise<void>;
|
|
137
|
+
createProject(identity: WriteIdentity, input: {
|
|
138
|
+
projectKey: string;
|
|
139
|
+
displayName?: string;
|
|
140
|
+
visibility?: string;
|
|
141
|
+
}): Promise<{
|
|
142
|
+
projectKey: string;
|
|
143
|
+
displayName: string | null;
|
|
144
|
+
registeredBy: string;
|
|
145
|
+
visibility: 'public' | 'private';
|
|
146
|
+
}>;
|
|
147
|
+
removeProject(identity: WriteIdentity, projectKey: string): Promise<{
|
|
148
|
+
projectKey: string;
|
|
149
|
+
removed: boolean;
|
|
150
|
+
}>;
|
|
151
|
+
registerSource(identity: WriteIdentity, rawInput: Record<string, unknown>): Promise<WriteRegisterResult>;
|
|
152
|
+
updateSource(identity: WriteIdentity, sourceId: string, patch: Record<string, unknown>): Promise<KnowledgeSource | null>;
|
|
153
|
+
removeSource(identity: WriteIdentity, sourceId: string): Promise<{
|
|
154
|
+
id: string;
|
|
155
|
+
purgedFiles: number;
|
|
156
|
+
}>;
|
|
157
|
+
describeSource(identity: WriteIdentity, sourceId: string): Promise<WriteDescribeResult | null>;
|
|
158
|
+
private assertSourceOwner;
|
|
159
|
+
reindexSource(sourceId: string): Promise<void>;
|
|
160
|
+
reprocessFiles(sourceId: string, paths: string[]): Promise<WriteReprocessResult>;
|
|
161
|
+
reprocessByFilter(sourceId: string, filter?: {
|
|
162
|
+
status?: string;
|
|
163
|
+
ext?: string;
|
|
164
|
+
q?: string;
|
|
165
|
+
}): Promise<WriteReprocessResult>;
|
|
166
|
+
abortSource(sourceId: string): Promise<WriteAbortStats & KnowledgeJobControlState>;
|
|
167
|
+
resumeSource(sourceId: string): Promise<KnowledgeJobControlState>;
|
|
168
|
+
abortAllOwned(identity: WriteIdentity): Promise<WriteAbortStats>;
|
|
169
|
+
resumeAllOwned(identity: WriteIdentity): Promise<WriteResumeStats>;
|
|
170
|
+
private isOwnerRow;
|
|
171
|
+
assignProject(identity: WriteIdentity, agentId: string, projectKey: string): Promise<void>;
|
|
172
|
+
unassignProject(identity: WriteIdentity, agentId: string, projectKey: string): Promise<void>;
|
|
173
|
+
hideSource(identity: WriteIdentity, agentId: string, sourceId: string): Promise<void>;
|
|
174
|
+
unhideSource(identity: WriteIdentity, agentId: string, sourceId: string): Promise<void>;
|
|
175
|
+
replaceSessionVisibility(identity: WriteIdentity, _agentId: string, sessionId: string, items: Array<{
|
|
176
|
+
targetType: string;
|
|
177
|
+
targetId: string;
|
|
178
|
+
op: string;
|
|
179
|
+
}>): Promise<number>;
|
|
180
|
+
setSessionVisibilityItem(identity: WriteIdentity, sessionId: string, item: {
|
|
181
|
+
targetType: 'project' | 'source';
|
|
182
|
+
targetId: string;
|
|
183
|
+
op: 'include' | 'exclude';
|
|
184
|
+
}): Promise<void>;
|
|
185
|
+
clearSessionVisibility(identity: WriteIdentity, sessionId: string, target?: {
|
|
186
|
+
targetType: 'project' | 'source';
|
|
187
|
+
targetId: string;
|
|
188
|
+
}): Promise<void>;
|
|
189
|
+
isSourceOwner(sourceId: string, gatewayId: string): Promise<boolean>;
|
|
190
|
+
sourceVisibleToGateway(sourceId: string, gatewayId: string): Promise<boolean>;
|
|
191
|
+
startIngestRuntime(): Promise<void>;
|
|
192
|
+
onProgress(cb: (evt: IngestProgressEvent) => void): () => void;
|
|
193
|
+
dispose(): Promise<void>;
|
|
194
|
+
}
|