hyacinth-ai 0.9.11 → 0.9.12
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.
|
@@ -62,7 +62,8 @@ export interface AgentComponents {
|
|
|
62
62
|
lastQuery: string;
|
|
63
63
|
};
|
|
64
64
|
kbWatcher: KnowledgeWatcher;
|
|
65
|
-
|
|
65
|
+
/** 知识库结构化存储(懒加载,只在知识库启用时才创建) */
|
|
66
|
+
structuredStore: StructuredStore | null;
|
|
66
67
|
composeStrategy: ComposeStrategy;
|
|
67
68
|
companionSessionManager: CompanionSessionManager;
|
|
68
69
|
backgroundRegistry: BackgroundProcessRegistry;
|
package/dist/gateway/factory.js
CHANGED
|
@@ -458,8 +458,14 @@ export async function createAgent(options, supervisor) {
|
|
|
458
458
|
// ── 知识库(Zone 4,默认关闭)───────────────────────────────────────
|
|
459
459
|
const kbDir = path.join(os.homedir(), '.agent', 'knowledge');
|
|
460
460
|
const kbStorePath = path.join(kbDir, 'kb.sqlite');
|
|
461
|
-
//
|
|
462
|
-
|
|
461
|
+
// 结构化存储 — 懒加载(不启用知识库时不创建,避免缺少 better-sqlite3 时报错)
|
|
462
|
+
let _structuredStore = null;
|
|
463
|
+
function getStructuredStore() {
|
|
464
|
+
if (!_structuredStore) {
|
|
465
|
+
_structuredStore = new StructuredStore(kbStorePath);
|
|
466
|
+
}
|
|
467
|
+
return _structuredStore;
|
|
468
|
+
}
|
|
463
469
|
// 旧版文件索引(保留兼容)
|
|
464
470
|
const kbFilesDir = path.join(kbDir, 'files');
|
|
465
471
|
fs.mkdirSync(kbFilesDir, { recursive: true });
|
|
@@ -488,12 +494,12 @@ export async function createAgent(options, supervisor) {
|
|
|
488
494
|
const maxTotal = configCenter.get('kb.maxTotal') ?? 5;
|
|
489
495
|
const maxMain = configCenter.get('kb.maxMain') ?? 3;
|
|
490
496
|
const maxRefs = configCenter.get('kb.maxRefs') ?? 2;
|
|
491
|
-
return
|
|
497
|
+
return getStructuredStore().formatResults(getStructuredStore().search(q, maxTotal), maxMain, maxRefs);
|
|
492
498
|
},
|
|
493
499
|
});
|
|
494
500
|
toolRegistry.register(createKbToggleTool(knowledgeBase, contextComposer));
|
|
495
501
|
// 结构化知识库工具(4合1:add/update/delete/list)
|
|
496
|
-
toolRegistry.register(createStructuredTool(
|
|
502
|
+
toolRegistry.register(createStructuredTool(getStructuredStore, () => knowledgeBase.enabled));
|
|
497
503
|
// ── 知识库文件监控(后台自动索引 files/ 目录变更)─────────────────
|
|
498
504
|
const kbWatcher = new KnowledgeWatcher({
|
|
499
505
|
filesDir: kbFilesDir,
|
|
@@ -832,7 +838,7 @@ export async function createAgent(options, supervisor) {
|
|
|
832
838
|
knowledgeBase,
|
|
833
839
|
kbState,
|
|
834
840
|
kbWatcher,
|
|
835
|
-
structuredStore,
|
|
841
|
+
structuredStore: _structuredStore,
|
|
836
842
|
composeStrategy,
|
|
837
843
|
companionSessionManager,
|
|
838
844
|
backgroundRegistry,
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { Tool } from '../tools/interface.js';
|
|
10
10
|
import type { StructuredStore } from './structured-store.js';
|
|
11
|
-
export declare function createStructuredTool(
|
|
11
|
+
export declare function createStructuredTool(getStore: () => StructuredStore, enabled: () => boolean): Tool;
|
|
12
12
|
//# sourceMappingURL=structured-tools.d.ts.map
|
|
@@ -11,7 +11,7 @@ function guard(store, enabled) {
|
|
|
11
11
|
return '知识库未开启。请执行 /kb on。';
|
|
12
12
|
return null;
|
|
13
13
|
}
|
|
14
|
-
export function createStructuredTool(
|
|
14
|
+
export function createStructuredTool(getStore, enabled) {
|
|
15
15
|
return {
|
|
16
16
|
name: 'kb_structured',
|
|
17
17
|
description: 'Manage structured knowledge entries. Supports 4 actions:\n' +
|
|
@@ -63,20 +63,20 @@ export function createStructuredTool(store, enabled) {
|
|
|
63
63
|
required: ['action'],
|
|
64
64
|
},
|
|
65
65
|
async execute(args) {
|
|
66
|
-
const blocked = guard(
|
|
66
|
+
const blocked = guard(getStore, enabled);
|
|
67
67
|
if (blocked)
|
|
68
68
|
return blocked;
|
|
69
69
|
const action = args.action;
|
|
70
70
|
try {
|
|
71
71
|
switch (action) {
|
|
72
72
|
case 'add':
|
|
73
|
-
return handleAdd(
|
|
73
|
+
return handleAdd(getStore(), args);
|
|
74
74
|
case 'update':
|
|
75
|
-
return handleUpdate(
|
|
75
|
+
return handleUpdate(getStore(), args);
|
|
76
76
|
case 'delete':
|
|
77
|
-
return handleDelete(
|
|
77
|
+
return handleDelete(getStore(), args);
|
|
78
78
|
case 'list':
|
|
79
|
-
return handleList(
|
|
79
|
+
return handleList(getStore(), args);
|
|
80
80
|
default:
|
|
81
81
|
return `Unknown action: "${action}". Supported: add, update, delete, list.`;
|
|
82
82
|
}
|