hyacinth-ai 0.9.11 → 0.9.13
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.
|
@@ -61,8 +61,9 @@ export interface AgentComponents {
|
|
|
61
61
|
kbState: {
|
|
62
62
|
lastQuery: string;
|
|
63
63
|
};
|
|
64
|
-
kbWatcher: KnowledgeWatcher;
|
|
65
|
-
|
|
64
|
+
kbWatcher: KnowledgeWatcher | null;
|
|
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,19 +494,25 @@ 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
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
+
// 懒创建 — 只在知识库启用后才启动
|
|
505
|
+
let _kbWatcher = null;
|
|
506
|
+
function getWatcher() {
|
|
507
|
+
if (!_kbWatcher) {
|
|
508
|
+
_kbWatcher = new KnowledgeWatcher({
|
|
509
|
+
filesDir: kbFilesDir,
|
|
510
|
+
retriever: knowledgeBase.retriever,
|
|
511
|
+
});
|
|
512
|
+
_kbWatcher.start().catch(() => { });
|
|
513
|
+
}
|
|
514
|
+
return _kbWatcher;
|
|
515
|
+
}
|
|
504
516
|
// ── Command Registry(斜杠命令外部配置化,支持模型修改 + 热重载) ──
|
|
505
517
|
CommandRegistry.getInstance(cwd);
|
|
506
518
|
// ── AgentLoop ─────────────────────────────────────────────────────
|
|
@@ -831,8 +843,8 @@ export async function createAgent(options, supervisor) {
|
|
|
831
843
|
providerConfigLoader,
|
|
832
844
|
knowledgeBase,
|
|
833
845
|
kbState,
|
|
834
|
-
kbWatcher,
|
|
835
|
-
structuredStore,
|
|
846
|
+
kbWatcher: _kbWatcher,
|
|
847
|
+
structuredStore: _structuredStore,
|
|
836
848
|
composeStrategy,
|
|
837
849
|
companionSessionManager,
|
|
838
850
|
backgroundRegistry,
|
|
@@ -7,10 +7,13 @@
|
|
|
7
7
|
import type { Retriever, KbDocument, KbSearchResult } from './retriever.js';
|
|
8
8
|
export type { KbDocument as KbDoc, KbSearchResult as KbResult } from './retriever.js';
|
|
9
9
|
export declare class KnowledgeBase {
|
|
10
|
-
|
|
10
|
+
private _retriever;
|
|
11
|
+
private _dbPath;
|
|
11
12
|
private _enabled;
|
|
12
13
|
private _zone4Enabled;
|
|
13
14
|
constructor(dbPathOrRetriever: string | Retriever);
|
|
15
|
+
/** 懒加载 retriever,仅在首次访问时创建 Fts5Retriever */
|
|
16
|
+
get retriever(): Retriever;
|
|
14
17
|
get enabled(): boolean;
|
|
15
18
|
enable(): void;
|
|
16
19
|
disable(): void;
|
package/dist/knowledge/store.js
CHANGED
|
@@ -6,17 +6,25 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { Fts5Retriever } from './fts5-retriever.js';
|
|
8
8
|
export class KnowledgeBase {
|
|
9
|
-
|
|
9
|
+
_retriever = null;
|
|
10
|
+
_dbPath;
|
|
10
11
|
_enabled = false;
|
|
11
12
|
_zone4Enabled = true; // Zone 4 默认开启
|
|
12
13
|
constructor(dbPathOrRetriever) {
|
|
13
14
|
if (typeof dbPathOrRetriever === 'string') {
|
|
14
|
-
this.
|
|
15
|
+
this._dbPath = dbPathOrRetriever;
|
|
15
16
|
}
|
|
16
17
|
else {
|
|
17
|
-
this.
|
|
18
|
+
this._retriever = dbPathOrRetriever;
|
|
18
19
|
}
|
|
19
20
|
}
|
|
21
|
+
/** 懒加载 retriever,仅在首次访问时创建 Fts5Retriever */
|
|
22
|
+
get retriever() {
|
|
23
|
+
if (!this._retriever) {
|
|
24
|
+
this._retriever = new Fts5Retriever(this._dbPath);
|
|
25
|
+
}
|
|
26
|
+
return this._retriever;
|
|
27
|
+
}
|
|
20
28
|
// ── 状态管理 ──────────────────────────────────────────────────────
|
|
21
29
|
get enabled() {
|
|
22
30
|
return this._enabled && this._zone4Enabled;
|
|
@@ -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
|
}
|