@danielsimonjr/memory-mcp 0.48.0 → 9.8.2
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/LICENSE +22 -0
- package/README.md +2000 -194
- package/dist/__tests__/file-path.test.js +7 -11
- package/dist/__tests__/knowledge-graph.test.js +3 -8
- package/dist/core/EntityManager.d.ts +266 -0
- package/dist/core/EntityManager.d.ts.map +1 -0
- package/dist/core/EntityManager.js +89 -137
- package/dist/core/GraphEventEmitter.d.ts +202 -0
- package/dist/core/GraphEventEmitter.d.ts.map +1 -0
- package/dist/core/GraphEventEmitter.js +346 -0
- package/dist/core/GraphStorage.d.ts +395 -0
- package/dist/core/GraphStorage.d.ts.map +1 -0
- package/dist/core/GraphStorage.js +644 -31
- package/dist/core/GraphTraversal.d.ts +141 -0
- package/dist/core/GraphTraversal.d.ts.map +1 -0
- package/dist/core/GraphTraversal.js +573 -0
- package/dist/core/HierarchyManager.d.ts +111 -0
- package/dist/core/HierarchyManager.d.ts.map +1 -0
- package/dist/{features → core}/HierarchyManager.js +14 -9
- package/dist/core/ManagerContext.d.ts +72 -0
- package/dist/core/ManagerContext.d.ts.map +1 -0
- package/dist/core/ManagerContext.js +118 -0
- package/dist/core/ObservationManager.d.ts +85 -0
- package/dist/core/ObservationManager.d.ts.map +1 -0
- package/dist/core/ObservationManager.js +51 -57
- package/dist/core/RelationManager.d.ts +131 -0
- package/dist/core/RelationManager.d.ts.map +1 -0
- package/dist/core/RelationManager.js +31 -7
- package/dist/core/SQLiteStorage.d.ts +354 -0
- package/dist/core/SQLiteStorage.d.ts.map +1 -0
- package/dist/core/SQLiteStorage.js +918 -0
- package/dist/core/StorageFactory.d.ts +45 -0
- package/dist/core/StorageFactory.d.ts.map +1 -0
- package/dist/core/StorageFactory.js +64 -0
- package/dist/core/TransactionManager.d.ts +464 -0
- package/dist/core/TransactionManager.d.ts.map +1 -0
- package/dist/core/TransactionManager.js +493 -14
- package/dist/core/index.d.ts +17 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +12 -2
- package/dist/features/AnalyticsManager.d.ts +44 -0
- package/dist/features/AnalyticsManager.d.ts.map +1 -0
- package/dist/features/AnalyticsManager.js +3 -2
- package/dist/features/ArchiveManager.d.ts +133 -0
- package/dist/features/ArchiveManager.d.ts.map +1 -0
- package/dist/features/ArchiveManager.js +221 -14
- package/dist/features/CompressionManager.d.ts +117 -0
- package/dist/features/CompressionManager.d.ts.map +1 -0
- package/dist/features/CompressionManager.js +189 -20
- package/dist/features/IOManager.d.ts +225 -0
- package/dist/features/IOManager.d.ts.map +1 -0
- package/dist/features/IOManager.js +1092 -0
- package/dist/features/StreamingExporter.d.ts +128 -0
- package/dist/features/StreamingExporter.d.ts.map +1 -0
- package/dist/features/StreamingExporter.js +211 -0
- package/dist/features/TagManager.d.ts +147 -0
- package/dist/features/TagManager.d.ts.map +1 -0
- package/dist/features/index.d.ts +12 -0
- package/dist/features/index.d.ts.map +1 -0
- package/dist/features/index.js +5 -6
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -10
- package/dist/memory.jsonl +1 -26
- package/dist/search/BasicSearch.d.ts +51 -0
- package/dist/search/BasicSearch.d.ts.map +1 -0
- package/dist/search/BasicSearch.js +9 -3
- package/dist/search/BooleanSearch.d.ts +98 -0
- package/dist/search/BooleanSearch.d.ts.map +1 -0
- package/dist/search/BooleanSearch.js +156 -9
- package/dist/search/EmbeddingService.d.ts +178 -0
- package/dist/search/EmbeddingService.d.ts.map +1 -0
- package/dist/search/EmbeddingService.js +358 -0
- package/dist/search/FuzzySearch.d.ts +118 -0
- package/dist/search/FuzzySearch.d.ts.map +1 -0
- package/dist/search/FuzzySearch.js +241 -25
- package/dist/search/QueryCostEstimator.d.ts +111 -0
- package/dist/search/QueryCostEstimator.d.ts.map +1 -0
- package/dist/search/QueryCostEstimator.js +355 -0
- package/dist/search/RankedSearch.d.ts +71 -0
- package/dist/search/RankedSearch.d.ts.map +1 -0
- package/dist/search/RankedSearch.js +54 -6
- package/dist/search/SavedSearchManager.d.ts +79 -0
- package/dist/search/SavedSearchManager.d.ts.map +1 -0
- package/dist/search/SavedSearchManager.js +3 -2
- package/dist/search/SearchFilterChain.d.ts +120 -0
- package/dist/search/SearchFilterChain.d.ts.map +1 -0
- package/dist/search/SearchFilterChain.js +2 -4
- package/dist/search/SearchManager.d.ts +326 -0
- package/dist/search/SearchManager.d.ts.map +1 -0
- package/dist/search/SearchManager.js +148 -0
- package/dist/search/SearchSuggestions.d.ts +27 -0
- package/dist/search/SearchSuggestions.d.ts.map +1 -0
- package/dist/search/SearchSuggestions.js +1 -1
- package/dist/search/SemanticSearch.d.ts +149 -0
- package/dist/search/SemanticSearch.d.ts.map +1 -0
- package/dist/search/SemanticSearch.js +323 -0
- package/dist/search/TFIDFEventSync.d.ts +85 -0
- package/dist/search/TFIDFEventSync.d.ts.map +1 -0
- package/dist/search/TFIDFEventSync.js +133 -0
- package/dist/search/TFIDFIndexManager.d.ts +151 -0
- package/dist/search/TFIDFIndexManager.d.ts.map +1 -0
- package/dist/search/TFIDFIndexManager.js +232 -17
- package/dist/search/VectorStore.d.ts +235 -0
- package/dist/search/VectorStore.d.ts.map +1 -0
- package/dist/search/VectorStore.js +311 -0
- package/dist/search/index.d.ts +21 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +12 -0
- package/dist/server/MCPServer.d.ts +21 -0
- package/dist/server/MCPServer.d.ts.map +1 -0
- package/dist/server/MCPServer.js +4 -4
- package/dist/server/responseCompressor.d.ts +94 -0
- package/dist/server/responseCompressor.d.ts.map +1 -0
- package/dist/server/responseCompressor.js +127 -0
- package/dist/server/toolDefinitions.d.ts +27 -0
- package/dist/server/toolDefinitions.d.ts.map +1 -0
- package/dist/server/toolDefinitions.js +188 -17
- package/dist/server/toolHandlers.d.ts +41 -0
- package/dist/server/toolHandlers.d.ts.map +1 -0
- package/dist/server/toolHandlers.js +469 -75
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -1
- package/dist/types/types.d.ts +1654 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +9 -0
- package/dist/utils/compressedCache.d.ts +192 -0
- package/dist/utils/compressedCache.d.ts.map +1 -0
- package/dist/utils/compressedCache.js +309 -0
- package/dist/utils/compressionUtil.d.ts +214 -0
- package/dist/utils/compressionUtil.d.ts.map +1 -0
- package/dist/utils/compressionUtil.js +247 -0
- package/dist/utils/constants.d.ts +245 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +124 -0
- package/dist/utils/entityUtils.d.ts +354 -0
- package/dist/utils/entityUtils.d.ts.map +1 -0
- package/dist/utils/entityUtils.js +511 -4
- package/dist/utils/errors.d.ts +95 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +24 -0
- package/dist/utils/formatters.d.ts +145 -0
- package/dist/utils/formatters.d.ts.map +1 -0
- package/dist/utils/{paginationUtils.js → formatters.js} +54 -3
- package/dist/utils/index.d.ts +23 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +71 -31
- package/dist/utils/indexes.d.ts +270 -0
- package/dist/utils/indexes.d.ts.map +1 -0
- package/dist/utils/indexes.js +526 -0
- package/dist/utils/logger.d.ts +24 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/operationUtils.d.ts +124 -0
- package/dist/utils/operationUtils.d.ts.map +1 -0
- package/dist/utils/operationUtils.js +175 -0
- package/dist/utils/parallelUtils.d.ts +76 -0
- package/dist/utils/parallelUtils.d.ts.map +1 -0
- package/dist/utils/parallelUtils.js +191 -0
- package/dist/utils/schemas.d.ts +374 -0
- package/dist/utils/schemas.d.ts.map +1 -0
- package/dist/utils/schemas.js +307 -7
- package/dist/utils/searchAlgorithms.d.ts +99 -0
- package/dist/utils/searchAlgorithms.d.ts.map +1 -0
- package/dist/utils/searchAlgorithms.js +167 -0
- package/dist/utils/searchCache.d.ts +108 -0
- package/dist/utils/searchCache.d.ts.map +1 -0
- package/dist/utils/taskScheduler.d.ts +294 -0
- package/dist/utils/taskScheduler.d.ts.map +1 -0
- package/dist/utils/taskScheduler.js +486 -0
- package/dist/workers/index.d.ts +12 -0
- package/dist/workers/index.d.ts.map +1 -0
- package/dist/workers/index.js +9 -0
- package/dist/workers/levenshteinWorker.d.ts +60 -0
- package/dist/workers/levenshteinWorker.d.ts.map +1 -0
- package/dist/workers/levenshteinWorker.js +98 -0
- package/package.json +17 -4
- package/dist/__tests__/edge-cases/edge-cases.test.js +0 -406
- package/dist/__tests__/integration/workflows.test.js +0 -449
- package/dist/__tests__/performance/benchmarks.test.js +0 -413
- package/dist/__tests__/unit/core/EntityManager.test.js +0 -334
- package/dist/__tests__/unit/core/GraphStorage.test.js +0 -205
- package/dist/__tests__/unit/core/RelationManager.test.js +0 -274
- package/dist/__tests__/unit/features/CompressionManager.test.js +0 -350
- package/dist/__tests__/unit/search/BasicSearch.test.js +0 -311
- package/dist/__tests__/unit/search/BooleanSearch.test.js +0 -432
- package/dist/__tests__/unit/search/FuzzySearch.test.js +0 -448
- package/dist/__tests__/unit/search/RankedSearch.test.js +0 -379
- package/dist/__tests__/unit/utils/levenshtein.test.js +0 -77
- package/dist/core/KnowledgeGraphManager.js +0 -423
- package/dist/features/BackupManager.js +0 -311
- package/dist/features/ExportManager.js +0 -305
- package/dist/features/ImportExportManager.js +0 -50
- package/dist/features/ImportManager.js +0 -328
- package/dist/memory-saved-searches.jsonl +0 -0
- package/dist/memory-tag-aliases.jsonl +0 -0
- package/dist/types/analytics.types.js +0 -6
- package/dist/types/entity.types.js +0 -7
- package/dist/types/import-export.types.js +0 -7
- package/dist/types/search.types.js +0 -7
- package/dist/types/tag.types.js +0 -6
- package/dist/utils/dateUtils.js +0 -89
- package/dist/utils/filterUtils.js +0 -155
- package/dist/utils/levenshtein.js +0 -62
- package/dist/utils/pathUtils.js +0 -115
- package/dist/utils/responseFormatter.js +0 -55
- package/dist/utils/tagUtils.js +0 -107
- package/dist/utils/tfidf.js +0 -90
- package/dist/utils/validationHelper.js +0 -99
- package/dist/utils/validationUtils.js +0 -109
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hierarchy Manager
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Handles entity hierarchy operations (parent-child relationships).
|
|
5
|
+
* Extracted from EntityManager (Phase 4: Consolidate God Objects).
|
|
5
6
|
*
|
|
6
|
-
* @module
|
|
7
|
+
* @module core/HierarchyManager
|
|
7
8
|
*/
|
|
8
9
|
import { EntityNotFoundError, CycleDetectedError } from '../utils/errors.js';
|
|
9
10
|
/**
|
|
10
|
-
* Manages hierarchical
|
|
11
|
+
* Manages hierarchical relationships between entities.
|
|
11
12
|
*/
|
|
12
13
|
export class HierarchyManager {
|
|
13
14
|
storage;
|
|
@@ -28,22 +29,26 @@ export class HierarchyManager {
|
|
|
28
29
|
* @throws {CycleDetectedError} If setting parent would create a cycle
|
|
29
30
|
*/
|
|
30
31
|
async setEntityParent(entityName, parentName) {
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
32
|
+
// Use read-only graph for validation checks
|
|
33
|
+
const readGraph = await this.storage.loadGraph();
|
|
34
|
+
const entityExists = readGraph.entities.find(e => e.name === entityName);
|
|
35
|
+
if (!entityExists) {
|
|
34
36
|
throw new EntityNotFoundError(entityName);
|
|
35
37
|
}
|
|
36
38
|
// If setting a parent, validate it exists and doesn't create a cycle
|
|
37
39
|
if (parentName !== null) {
|
|
38
|
-
const parent =
|
|
40
|
+
const parent = readGraph.entities.find(e => e.name === parentName);
|
|
39
41
|
if (!parent) {
|
|
40
42
|
throw new EntityNotFoundError(parentName);
|
|
41
43
|
}
|
|
42
44
|
// Check for cycles
|
|
43
|
-
if (this.wouldCreateCycle(
|
|
45
|
+
if (this.wouldCreateCycle(readGraph, entityName, parentName)) {
|
|
44
46
|
throw new CycleDetectedError(entityName, parentName);
|
|
45
47
|
}
|
|
46
48
|
}
|
|
49
|
+
// Get mutable copy for write operation
|
|
50
|
+
const graph = await this.storage.getGraphForMutation();
|
|
51
|
+
const entity = graph.entities.find(e => e.name === entityName);
|
|
47
52
|
entity.parentId = parentName || undefined;
|
|
48
53
|
entity.lastModified = new Date().toISOString();
|
|
49
54
|
await this.storage.saveGraph(graph);
|
|
@@ -198,7 +203,7 @@ export class HierarchyManager {
|
|
|
198
203
|
*
|
|
199
204
|
* @param entityName - Entity name
|
|
200
205
|
* @returns Depth (number of ancestors)
|
|
201
|
-
* @throws
|
|
206
|
+
* @throws {EntityNotFoundError} If entity not found
|
|
202
207
|
*/
|
|
203
208
|
async getEntityDepth(entityName) {
|
|
204
209
|
const ancestors = await this.getAncestors(entityName);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manager Context
|
|
3
|
+
*
|
|
4
|
+
* Central context holding all manager instances with lazy initialization.
|
|
5
|
+
* Provides direct manager access for toolHandlers.
|
|
6
|
+
* Phase 4: Removed convenience methods - use managers directly.
|
|
7
|
+
*
|
|
8
|
+
* @module core/ManagerContext
|
|
9
|
+
*/
|
|
10
|
+
import { GraphStorage } from './GraphStorage.js';
|
|
11
|
+
import { EntityManager } from './EntityManager.js';
|
|
12
|
+
import { RelationManager } from './RelationManager.js';
|
|
13
|
+
import { ObservationManager } from './ObservationManager.js';
|
|
14
|
+
import { HierarchyManager } from './HierarchyManager.js';
|
|
15
|
+
import { GraphTraversal } from './GraphTraversal.js';
|
|
16
|
+
import { SearchManager } from '../search/SearchManager.js';
|
|
17
|
+
import { SemanticSearch } from '../search/index.js';
|
|
18
|
+
import { IOManager } from '../features/IOManager.js';
|
|
19
|
+
import { TagManager } from '../features/TagManager.js';
|
|
20
|
+
import { AnalyticsManager } from '../features/AnalyticsManager.js';
|
|
21
|
+
import { CompressionManager } from '../features/CompressionManager.js';
|
|
22
|
+
import { ArchiveManager } from '../features/ArchiveManager.js';
|
|
23
|
+
/**
|
|
24
|
+
* Context holding all manager instances with lazy initialization.
|
|
25
|
+
* Provides direct manager access for toolHandlers.
|
|
26
|
+
*/
|
|
27
|
+
export declare class ManagerContext {
|
|
28
|
+
readonly storage: GraphStorage;
|
|
29
|
+
private readonly savedSearchesFilePath;
|
|
30
|
+
private readonly tagAliasesFilePath;
|
|
31
|
+
private _entityManager?;
|
|
32
|
+
private _relationManager?;
|
|
33
|
+
private _observationManager?;
|
|
34
|
+
private _hierarchyManager?;
|
|
35
|
+
private _graphTraversal?;
|
|
36
|
+
private _searchManager?;
|
|
37
|
+
private _semanticSearch?;
|
|
38
|
+
private _ioManager?;
|
|
39
|
+
private _tagManager?;
|
|
40
|
+
private _analyticsManager?;
|
|
41
|
+
private _compressionManager?;
|
|
42
|
+
private _archiveManager?;
|
|
43
|
+
constructor(memoryFilePath: string);
|
|
44
|
+
/** EntityManager - Entity CRUD and tag operations */
|
|
45
|
+
get entityManager(): EntityManager;
|
|
46
|
+
/** RelationManager - Relation CRUD */
|
|
47
|
+
get relationManager(): RelationManager;
|
|
48
|
+
/** ObservationManager - Observation CRUD */
|
|
49
|
+
get observationManager(): ObservationManager;
|
|
50
|
+
/** HierarchyManager - Entity hierarchy operations */
|
|
51
|
+
get hierarchyManager(): HierarchyManager;
|
|
52
|
+
/** GraphTraversal - Phase 4 Sprint 6-8: Graph traversal algorithms */
|
|
53
|
+
get graphTraversal(): GraphTraversal;
|
|
54
|
+
/** SearchManager - All search operations */
|
|
55
|
+
get searchManager(): SearchManager;
|
|
56
|
+
/**
|
|
57
|
+
* SemanticSearch - Phase 4 Sprint 12: Semantic similarity search.
|
|
58
|
+
* Returns null if no embedding provider is configured.
|
|
59
|
+
*/
|
|
60
|
+
get semanticSearch(): SemanticSearch | null;
|
|
61
|
+
/** IOManager - Import, export, and backup operations */
|
|
62
|
+
get ioManager(): IOManager;
|
|
63
|
+
/** TagManager - Tag alias management */
|
|
64
|
+
get tagManager(): TagManager;
|
|
65
|
+
/** AnalyticsManager - Graph statistics and validation */
|
|
66
|
+
get analyticsManager(): AnalyticsManager;
|
|
67
|
+
/** CompressionManager - Duplicate detection and entity merging */
|
|
68
|
+
get compressionManager(): CompressionManager;
|
|
69
|
+
/** ArchiveManager - Entity archival operations */
|
|
70
|
+
get archiveManager(): ArchiveManager;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=ManagerContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ManagerContext.d.ts","sourceRoot":"","sources":["../../src/core/ManagerContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAA6C,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAG/D;;;GAGG;AACH,qBAAa,cAAc;IACzB,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAS;IAC/C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAS;IAG5C,OAAO,CAAC,cAAc,CAAC,CAAgB;IACvC,OAAO,CAAC,gBAAgB,CAAC,CAAkB;IAC3C,OAAO,CAAC,mBAAmB,CAAC,CAAqB;IACjD,OAAO,CAAC,iBAAiB,CAAC,CAAmB;IAC7C,OAAO,CAAC,eAAe,CAAC,CAAiB;IACzC,OAAO,CAAC,cAAc,CAAC,CAAgB;IACvC,OAAO,CAAC,eAAe,CAAC,CAAwB;IAChD,OAAO,CAAC,UAAU,CAAC,CAAY;IAC/B,OAAO,CAAC,WAAW,CAAC,CAAa;IACjC,OAAO,CAAC,iBAAiB,CAAC,CAAmB;IAC7C,OAAO,CAAC,mBAAmB,CAAC,CAAqB;IACjD,OAAO,CAAC,eAAe,CAAC,CAAiB;gBAE7B,cAAc,EAAE,MAAM;IAYlC,qDAAqD;IACrD,IAAI,aAAa,IAAI,aAAa,CAEjC;IAED,sCAAsC;IACtC,IAAI,eAAe,IAAI,eAAe,CAErC;IAED,4CAA4C;IAC5C,IAAI,kBAAkB,IAAI,kBAAkB,CAE3C;IAED,qDAAqD;IACrD,IAAI,gBAAgB,IAAI,gBAAgB,CAEvC;IAED,sEAAsE;IACtE,IAAI,cAAc,IAAI,cAAc,CAEnC;IAED,4CAA4C;IAC5C,IAAI,aAAa,IAAI,aAAa,CAEjC;IAED;;;OAGG;IACH,IAAI,cAAc,IAAI,cAAc,GAAG,IAAI,CAa1C;IAED,wDAAwD;IACxD,IAAI,SAAS,IAAI,SAAS,CAEzB;IAED,wCAAwC;IACxC,IAAI,UAAU,IAAI,UAAU,CAE3B;IAED,yDAAyD;IACzD,IAAI,gBAAgB,IAAI,gBAAgB,CAEvC;IAED,kEAAkE;IAClE,IAAI,kBAAkB,IAAI,kBAAkB,CAE3C;IAED,kDAAkD;IAClD,IAAI,cAAc,IAAI,cAAc,CAEnC;CACF"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manager Context
|
|
3
|
+
*
|
|
4
|
+
* Central context holding all manager instances with lazy initialization.
|
|
5
|
+
* Provides direct manager access for toolHandlers.
|
|
6
|
+
* Phase 4: Removed convenience methods - use managers directly.
|
|
7
|
+
*
|
|
8
|
+
* @module core/ManagerContext
|
|
9
|
+
*/
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import { GraphStorage } from './GraphStorage.js';
|
|
12
|
+
import { EntityManager } from './EntityManager.js';
|
|
13
|
+
import { RelationManager } from './RelationManager.js';
|
|
14
|
+
import { ObservationManager } from './ObservationManager.js';
|
|
15
|
+
import { HierarchyManager } from './HierarchyManager.js';
|
|
16
|
+
import { GraphTraversal } from './GraphTraversal.js';
|
|
17
|
+
import { SearchManager } from '../search/SearchManager.js';
|
|
18
|
+
import { SemanticSearch, createEmbeddingService, createVectorStore } from '../search/index.js';
|
|
19
|
+
import { IOManager } from '../features/IOManager.js';
|
|
20
|
+
import { TagManager } from '../features/TagManager.js';
|
|
21
|
+
import { AnalyticsManager } from '../features/AnalyticsManager.js';
|
|
22
|
+
import { CompressionManager } from '../features/CompressionManager.js';
|
|
23
|
+
import { ArchiveManager } from '../features/ArchiveManager.js';
|
|
24
|
+
import { getEmbeddingConfig } from '../utils/constants.js';
|
|
25
|
+
/**
|
|
26
|
+
* Context holding all manager instances with lazy initialization.
|
|
27
|
+
* Provides direct manager access for toolHandlers.
|
|
28
|
+
*/
|
|
29
|
+
export class ManagerContext {
|
|
30
|
+
storage;
|
|
31
|
+
savedSearchesFilePath;
|
|
32
|
+
tagAliasesFilePath;
|
|
33
|
+
// Lazy-initialized managers
|
|
34
|
+
_entityManager;
|
|
35
|
+
_relationManager;
|
|
36
|
+
_observationManager;
|
|
37
|
+
_hierarchyManager;
|
|
38
|
+
_graphTraversal;
|
|
39
|
+
_searchManager;
|
|
40
|
+
_semanticSearch;
|
|
41
|
+
_ioManager;
|
|
42
|
+
_tagManager;
|
|
43
|
+
_analyticsManager;
|
|
44
|
+
_compressionManager;
|
|
45
|
+
_archiveManager;
|
|
46
|
+
constructor(memoryFilePath) {
|
|
47
|
+
// Derive paths for saved searches and tag aliases
|
|
48
|
+
const dir = path.dirname(memoryFilePath);
|
|
49
|
+
const basename = path.basename(memoryFilePath, path.extname(memoryFilePath));
|
|
50
|
+
this.savedSearchesFilePath = path.join(dir, `${basename}-saved-searches.jsonl`);
|
|
51
|
+
this.tagAliasesFilePath = path.join(dir, `${basename}-tag-aliases.jsonl`);
|
|
52
|
+
this.storage = new GraphStorage(memoryFilePath);
|
|
53
|
+
}
|
|
54
|
+
// ==================== MANAGER ACCESSORS ====================
|
|
55
|
+
// Use these for direct manager access in toolHandlers
|
|
56
|
+
/** EntityManager - Entity CRUD and tag operations */
|
|
57
|
+
get entityManager() {
|
|
58
|
+
return (this._entityManager ??= new EntityManager(this.storage));
|
|
59
|
+
}
|
|
60
|
+
/** RelationManager - Relation CRUD */
|
|
61
|
+
get relationManager() {
|
|
62
|
+
return (this._relationManager ??= new RelationManager(this.storage));
|
|
63
|
+
}
|
|
64
|
+
/** ObservationManager - Observation CRUD */
|
|
65
|
+
get observationManager() {
|
|
66
|
+
return (this._observationManager ??= new ObservationManager(this.storage));
|
|
67
|
+
}
|
|
68
|
+
/** HierarchyManager - Entity hierarchy operations */
|
|
69
|
+
get hierarchyManager() {
|
|
70
|
+
return (this._hierarchyManager ??= new HierarchyManager(this.storage));
|
|
71
|
+
}
|
|
72
|
+
/** GraphTraversal - Phase 4 Sprint 6-8: Graph traversal algorithms */
|
|
73
|
+
get graphTraversal() {
|
|
74
|
+
return (this._graphTraversal ??= new GraphTraversal(this.storage));
|
|
75
|
+
}
|
|
76
|
+
/** SearchManager - All search operations */
|
|
77
|
+
get searchManager() {
|
|
78
|
+
return (this._searchManager ??= new SearchManager(this.storage, this.savedSearchesFilePath));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* SemanticSearch - Phase 4 Sprint 12: Semantic similarity search.
|
|
82
|
+
* Returns null if no embedding provider is configured.
|
|
83
|
+
*/
|
|
84
|
+
get semanticSearch() {
|
|
85
|
+
if (this._semanticSearch === undefined) {
|
|
86
|
+
const config = getEmbeddingConfig();
|
|
87
|
+
const embeddingService = createEmbeddingService(config);
|
|
88
|
+
if (embeddingService) {
|
|
89
|
+
const vectorStore = createVectorStore('jsonl'); // Use in-memory for now
|
|
90
|
+
this._semanticSearch = new SemanticSearch(embeddingService, vectorStore);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this._semanticSearch = null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return this._semanticSearch;
|
|
97
|
+
}
|
|
98
|
+
/** IOManager - Import, export, and backup operations */
|
|
99
|
+
get ioManager() {
|
|
100
|
+
return (this._ioManager ??= new IOManager(this.storage));
|
|
101
|
+
}
|
|
102
|
+
/** TagManager - Tag alias management */
|
|
103
|
+
get tagManager() {
|
|
104
|
+
return (this._tagManager ??= new TagManager(this.tagAliasesFilePath));
|
|
105
|
+
}
|
|
106
|
+
/** AnalyticsManager - Graph statistics and validation */
|
|
107
|
+
get analyticsManager() {
|
|
108
|
+
return (this._analyticsManager ??= new AnalyticsManager(this.storage));
|
|
109
|
+
}
|
|
110
|
+
/** CompressionManager - Duplicate detection and entity merging */
|
|
111
|
+
get compressionManager() {
|
|
112
|
+
return (this._compressionManager ??= new CompressionManager(this.storage));
|
|
113
|
+
}
|
|
114
|
+
/** ArchiveManager - Entity archival operations */
|
|
115
|
+
get archiveManager() {
|
|
116
|
+
return (this._archiveManager ??= new ArchiveManager(this.storage));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observation Manager
|
|
3
|
+
*
|
|
4
|
+
* Handles observation CRUD operations for entities.
|
|
5
|
+
* Extracted from EntityManager (Phase 4: Consolidate God Objects).
|
|
6
|
+
*
|
|
7
|
+
* @module core/ObservationManager
|
|
8
|
+
*/
|
|
9
|
+
import type { GraphStorage } from './GraphStorage.js';
|
|
10
|
+
/**
|
|
11
|
+
* Manages observation operations for entities in the knowledge graph.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ObservationManager {
|
|
14
|
+
private storage;
|
|
15
|
+
constructor(storage: GraphStorage);
|
|
16
|
+
/**
|
|
17
|
+
* Add observations to multiple entities in a single batch operation.
|
|
18
|
+
*
|
|
19
|
+
* This method performs the following operations:
|
|
20
|
+
* - Adds new observations to specified entities
|
|
21
|
+
* - Filters out duplicate observations (already present)
|
|
22
|
+
* - Updates lastModified timestamp only if new observations were added
|
|
23
|
+
* - ATOMIC: All updates are saved in a single operation
|
|
24
|
+
*
|
|
25
|
+
* @param observations - Array of entity names and observations to add
|
|
26
|
+
* @returns Promise resolving to array of results showing which observations were added
|
|
27
|
+
* @throws {EntityNotFoundError} If any entity is not found
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const manager = new ObservationManager(storage);
|
|
32
|
+
*
|
|
33
|
+
* // Add observations to multiple entities
|
|
34
|
+
* const results = await manager.addObservations([
|
|
35
|
+
* { entityName: 'Alice', contents: ['Completed project X', 'Started project Y'] },
|
|
36
|
+
* { entityName: 'Bob', contents: ['Joined team meeting'] }
|
|
37
|
+
* ]);
|
|
38
|
+
*
|
|
39
|
+
* // Check what was added (duplicates are filtered out)
|
|
40
|
+
* results.forEach(r => {
|
|
41
|
+
* console.log(`${r.entityName}: added ${r.addedObservations.length} new observations`);
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
addObservations(observations: {
|
|
46
|
+
entityName: string;
|
|
47
|
+
contents: string[];
|
|
48
|
+
}[]): Promise<{
|
|
49
|
+
entityName: string;
|
|
50
|
+
addedObservations: string[];
|
|
51
|
+
}[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Delete observations from multiple entities in a single batch operation.
|
|
54
|
+
*
|
|
55
|
+
* This method performs the following operations:
|
|
56
|
+
* - Removes specified observations from entities
|
|
57
|
+
* - Updates lastModified timestamp only if observations were deleted
|
|
58
|
+
* - Silently ignores entities that don't exist (no error thrown)
|
|
59
|
+
* - ATOMIC: All deletions are saved in a single operation
|
|
60
|
+
*
|
|
61
|
+
* @param deletions - Array of entity names and observations to delete
|
|
62
|
+
* @returns Promise that resolves when deletion is complete
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const manager = new ObservationManager(storage);
|
|
67
|
+
*
|
|
68
|
+
* // Delete observations from multiple entities
|
|
69
|
+
* await manager.deleteObservations([
|
|
70
|
+
* { entityName: 'Alice', observations: ['Old observation 1', 'Old observation 2'] },
|
|
71
|
+
* { entityName: 'Bob', observations: ['Outdated info'] }
|
|
72
|
+
* ]);
|
|
73
|
+
*
|
|
74
|
+
* // Safe to delete from non-existent entities (no error)
|
|
75
|
+
* await manager.deleteObservations([
|
|
76
|
+
* { entityName: 'NonExistent', observations: ['Some text'] }
|
|
77
|
+
* ]); // No error thrown
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
deleteObservations(deletions: {
|
|
81
|
+
entityName: string;
|
|
82
|
+
observations: string[];
|
|
83
|
+
}[]): Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=ObservationManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObservationManager.d.ts","sourceRoot":"","sources":["../../src/core/ObservationManager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGtD;;GAEG;AACH,qBAAa,kBAAkB;IACjB,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,YAAY;IAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,eAAe,CACnB,YAAY,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,GACzD,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,iBAAiB,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;IAiCjE;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,kBAAkB,CACtB,SAAS,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,GAC1D,OAAO,CAAC,IAAI,CAAC;CAyBjB"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Observation Manager
|
|
3
3
|
*
|
|
4
|
-
* Handles CRUD operations for
|
|
4
|
+
* Handles observation CRUD operations for entities.
|
|
5
|
+
* Extracted from EntityManager (Phase 4: Consolidate God Objects).
|
|
5
6
|
*
|
|
6
7
|
* @module core/ObservationManager
|
|
7
8
|
*/
|
|
8
9
|
import { EntityNotFoundError } from '../utils/errors.js';
|
|
9
10
|
/**
|
|
10
|
-
* Manages observation operations
|
|
11
|
+
* Manages observation operations for entities in the knowledge graph.
|
|
11
12
|
*/
|
|
12
13
|
export class ObservationManager {
|
|
13
14
|
storage;
|
|
@@ -18,112 +19,105 @@ export class ObservationManager {
|
|
|
18
19
|
* Add observations to multiple entities in a single batch operation.
|
|
19
20
|
*
|
|
20
21
|
* This method performs the following operations:
|
|
21
|
-
* -
|
|
22
|
-
* - Filters out duplicate observations (
|
|
23
|
-
* -
|
|
24
|
-
* -
|
|
22
|
+
* - Adds new observations to specified entities
|
|
23
|
+
* - Filters out duplicate observations (already present)
|
|
24
|
+
* - Updates lastModified timestamp only if new observations were added
|
|
25
|
+
* - ATOMIC: All updates are saved in a single operation
|
|
25
26
|
*
|
|
26
|
-
* @param observations - Array of
|
|
27
|
-
* @returns Promise resolving to array of results showing
|
|
28
|
-
* @throws {EntityNotFoundError} If any
|
|
27
|
+
* @param observations - Array of entity names and observations to add
|
|
28
|
+
* @returns Promise resolving to array of results showing which observations were added
|
|
29
|
+
* @throws {EntityNotFoundError} If any entity is not found
|
|
29
30
|
*
|
|
30
31
|
* @example
|
|
31
32
|
* ```typescript
|
|
32
33
|
* const manager = new ObservationManager(storage);
|
|
33
34
|
*
|
|
34
|
-
* // Add observations to
|
|
35
|
+
* // Add observations to multiple entities
|
|
35
36
|
* const results = await manager.addObservations([
|
|
36
|
-
* {
|
|
37
|
-
*
|
|
38
|
-
* contents: ['Works on frontend', 'Expertise in React']
|
|
39
|
-
* }
|
|
37
|
+
* { entityName: 'Alice', contents: ['Completed project X', 'Started project Y'] },
|
|
38
|
+
* { entityName: 'Bob', contents: ['Joined team meeting'] }
|
|
40
39
|
* ]);
|
|
41
|
-
* console.log(results[0].addedObservations); // ['Works on frontend', 'Expertise in React']
|
|
42
40
|
*
|
|
43
|
-
* //
|
|
44
|
-
*
|
|
45
|
-
* {
|
|
46
|
-
*
|
|
47
|
-
* ]);
|
|
48
|
-
*
|
|
49
|
-
* // Duplicate observations are filtered out
|
|
50
|
-
* await manager.addObservations([
|
|
51
|
-
* { entityName: 'Alice', contents: ['Works on frontend'] } // Already exists, won't be added
|
|
52
|
-
* ]);
|
|
41
|
+
* // Check what was added (duplicates are filtered out)
|
|
42
|
+
* results.forEach(r => {
|
|
43
|
+
* console.log(`${r.entityName}: added ${r.addedObservations.length} new observations`);
|
|
44
|
+
* });
|
|
53
45
|
* ```
|
|
54
46
|
*/
|
|
55
47
|
async addObservations(observations) {
|
|
56
|
-
|
|
48
|
+
// Get mutable graph for atomic update
|
|
49
|
+
const graph = await this.storage.getGraphForMutation();
|
|
57
50
|
const timestamp = new Date().toISOString();
|
|
58
|
-
const results =
|
|
51
|
+
const results = [];
|
|
52
|
+
let hasChanges = false;
|
|
53
|
+
for (const o of observations) {
|
|
59
54
|
const entity = graph.entities.find(e => e.name === o.entityName);
|
|
60
55
|
if (!entity) {
|
|
61
56
|
throw new EntityNotFoundError(o.entityName);
|
|
62
57
|
}
|
|
63
58
|
const newObservations = o.contents.filter(content => !entity.observations.includes(content));
|
|
64
|
-
entity.observations.push(...newObservations);
|
|
65
|
-
// Update lastModified if observations were added
|
|
66
59
|
if (newObservations.length > 0) {
|
|
60
|
+
// Add new observations directly to the entity
|
|
61
|
+
entity.observations.push(...newObservations);
|
|
67
62
|
entity.lastModified = timestamp;
|
|
63
|
+
hasChanges = true;
|
|
68
64
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
results.push({ entityName: o.entityName, addedObservations: newObservations });
|
|
66
|
+
}
|
|
67
|
+
// Save all changes in a single atomic operation
|
|
68
|
+
if (hasChanges) {
|
|
69
|
+
await this.storage.saveGraph(graph);
|
|
70
|
+
}
|
|
75
71
|
return results;
|
|
76
72
|
}
|
|
77
73
|
/**
|
|
78
|
-
* Delete
|
|
74
|
+
* Delete observations from multiple entities in a single batch operation.
|
|
79
75
|
*
|
|
80
76
|
* This method performs the following operations:
|
|
81
|
-
* - Removes specified observations from
|
|
77
|
+
* - Removes specified observations from entities
|
|
78
|
+
* - Updates lastModified timestamp only if observations were deleted
|
|
82
79
|
* - Silently ignores entities that don't exist (no error thrown)
|
|
83
|
-
* -
|
|
84
|
-
* - Automatically updates lastModified timestamp for modified entities
|
|
80
|
+
* - ATOMIC: All deletions are saved in a single operation
|
|
85
81
|
*
|
|
86
|
-
* @param deletions - Array of
|
|
82
|
+
* @param deletions - Array of entity names and observations to delete
|
|
87
83
|
* @returns Promise that resolves when deletion is complete
|
|
88
84
|
*
|
|
89
85
|
* @example
|
|
90
86
|
* ```typescript
|
|
91
87
|
* const manager = new ObservationManager(storage);
|
|
92
88
|
*
|
|
93
|
-
* // Delete
|
|
89
|
+
* // Delete observations from multiple entities
|
|
94
90
|
* await manager.deleteObservations([
|
|
95
|
-
* {
|
|
96
|
-
*
|
|
97
|
-
* observations: ['Works on frontend', 'Expertise in React']
|
|
98
|
-
* }
|
|
91
|
+
* { entityName: 'Alice', observations: ['Old observation 1', 'Old observation 2'] },
|
|
92
|
+
* { entityName: 'Bob', observations: ['Outdated info'] }
|
|
99
93
|
* ]);
|
|
100
94
|
*
|
|
101
|
-
* //
|
|
95
|
+
* // Safe to delete from non-existent entities (no error)
|
|
102
96
|
* await manager.deleteObservations([
|
|
103
|
-
* { entityName: '
|
|
104
|
-
*
|
|
105
|
-
* ]);
|
|
106
|
-
*
|
|
107
|
-
* // Safe to delete non-existent observations or from non-existent entities
|
|
108
|
-
* await manager.deleteObservations([
|
|
109
|
-
* { entityName: 'NonExistent', observations: ['Some observation'] } // No error
|
|
110
|
-
* ]);
|
|
97
|
+
* { entityName: 'NonExistent', observations: ['Some text'] }
|
|
98
|
+
* ]); // No error thrown
|
|
111
99
|
* ```
|
|
112
100
|
*/
|
|
113
101
|
async deleteObservations(deletions) {
|
|
114
|
-
|
|
102
|
+
// Get mutable graph for atomic update
|
|
103
|
+
const graph = await this.storage.getGraphForMutation();
|
|
115
104
|
const timestamp = new Date().toISOString();
|
|
105
|
+
let hasChanges = false;
|
|
116
106
|
deletions.forEach(d => {
|
|
117
107
|
const entity = graph.entities.find(e => e.name === d.entityName);
|
|
118
108
|
if (entity) {
|
|
119
109
|
const originalLength = entity.observations.length;
|
|
120
110
|
entity.observations = entity.observations.filter(o => !d.observations.includes(o));
|
|
121
|
-
// Update lastModified if observations were deleted
|
|
111
|
+
// Update lastModified timestamp if observations were deleted
|
|
122
112
|
if (entity.observations.length < originalLength) {
|
|
123
113
|
entity.lastModified = timestamp;
|
|
114
|
+
hasChanges = true;
|
|
124
115
|
}
|
|
125
116
|
}
|
|
126
117
|
});
|
|
127
|
-
|
|
118
|
+
// Save all changes in a single atomic operation
|
|
119
|
+
if (hasChanges) {
|
|
120
|
+
await this.storage.saveGraph(graph);
|
|
121
|
+
}
|
|
128
122
|
}
|
|
129
123
|
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Relation Manager
|
|
3
|
+
*
|
|
4
|
+
* Handles CRUD operations for relations in the knowledge graph.
|
|
5
|
+
*
|
|
6
|
+
* @module core/RelationManager
|
|
7
|
+
*/
|
|
8
|
+
import type { Relation } from '../types/index.js';
|
|
9
|
+
import type { GraphStorage } from './GraphStorage.js';
|
|
10
|
+
/**
|
|
11
|
+
* Manages relation operations with automatic timestamp handling.
|
|
12
|
+
*/
|
|
13
|
+
export declare class RelationManager {
|
|
14
|
+
private storage;
|
|
15
|
+
constructor(storage: GraphStorage);
|
|
16
|
+
/**
|
|
17
|
+
* Create multiple relations in a single batch operation.
|
|
18
|
+
*
|
|
19
|
+
* This method performs the following operations:
|
|
20
|
+
* - Validates that all referenced entities exist (prevents dangling relations)
|
|
21
|
+
* - Filters out duplicate relations (same from, to, and relationType)
|
|
22
|
+
* - Automatically adds createdAt and lastModified timestamps
|
|
23
|
+
*
|
|
24
|
+
* A relation is considered duplicate if another relation exists with the same:
|
|
25
|
+
* - from entity name
|
|
26
|
+
* - to entity name
|
|
27
|
+
* - relationType
|
|
28
|
+
*
|
|
29
|
+
* @param relations - Array of relations to create
|
|
30
|
+
* @returns Promise resolving to array of newly created relations (excludes duplicates)
|
|
31
|
+
* @throws {ValidationError} If any relation references non-existent entities
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const manager = new RelationManager(storage);
|
|
36
|
+
*
|
|
37
|
+
* // Create single relation
|
|
38
|
+
* const results = await manager.createRelations([{
|
|
39
|
+
* from: 'Alice',
|
|
40
|
+
* to: 'Bob',
|
|
41
|
+
* relationType: 'works_with'
|
|
42
|
+
* }]);
|
|
43
|
+
*
|
|
44
|
+
* // Create multiple relations at once
|
|
45
|
+
* await manager.createRelations([
|
|
46
|
+
* { from: 'Alice', to: 'Project_X', relationType: 'contributes_to' },
|
|
47
|
+
* { from: 'Bob', to: 'Project_X', relationType: 'leads' },
|
|
48
|
+
* { from: 'Charlie', to: 'Alice', relationType: 'reports_to' }
|
|
49
|
+
* ]);
|
|
50
|
+
*
|
|
51
|
+
* // Duplicate relations are filtered out
|
|
52
|
+
* await manager.createRelations([
|
|
53
|
+
* { from: 'Alice', to: 'Bob', relationType: 'works_with' } // Already exists, won't be added
|
|
54
|
+
* ]);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
createRelations(relations: Relation[]): Promise<Relation[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Delete multiple relations in a single batch operation.
|
|
60
|
+
*
|
|
61
|
+
* This method performs the following operations:
|
|
62
|
+
* - Removes all specified relations from the graph
|
|
63
|
+
* - Automatically updates lastModified timestamp for all affected entities
|
|
64
|
+
* - Silently ignores relations that don't exist (no error thrown)
|
|
65
|
+
*
|
|
66
|
+
* An entity is considered "affected" if it appears as either the source (from)
|
|
67
|
+
* or target (to) of any deleted relation.
|
|
68
|
+
*
|
|
69
|
+
* @param relations - Array of relations to delete. Each relation is matched by from, to, and relationType.
|
|
70
|
+
* @returns Promise that resolves when deletion is complete
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const manager = new RelationManager(storage);
|
|
75
|
+
*
|
|
76
|
+
* // Delete single relation
|
|
77
|
+
* await manager.deleteRelations([{
|
|
78
|
+
* from: 'Alice',
|
|
79
|
+
* to: 'Bob',
|
|
80
|
+
* relationType: 'works_with'
|
|
81
|
+
* }]);
|
|
82
|
+
*
|
|
83
|
+
* // Delete multiple relations at once
|
|
84
|
+
* await manager.deleteRelations([
|
|
85
|
+
* { from: 'Alice', to: 'Project_X', relationType: 'contributes_to' },
|
|
86
|
+
* { from: 'Bob', to: 'Project_X', relationType: 'leads' }
|
|
87
|
+
* ]);
|
|
88
|
+
* // Note: Alice, Bob, and Project_X will all have their lastModified timestamp updated
|
|
89
|
+
*
|
|
90
|
+
* // Safe to delete non-existent relations
|
|
91
|
+
* await manager.deleteRelations([
|
|
92
|
+
* { from: 'NonExistent', to: 'AlsoNonExistent', relationType: 'fake' } // No error
|
|
93
|
+
* ]);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
deleteRelations(relations: Relation[]): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Retrieve all relations involving a specific entity.
|
|
99
|
+
*
|
|
100
|
+
* This is a read-only operation that returns all relations where the specified
|
|
101
|
+
* entity appears as either the source (from) or target (to) of the relation.
|
|
102
|
+
* Entity names are case-sensitive.
|
|
103
|
+
*
|
|
104
|
+
* @param entityName - The unique name of the entity to find relations for
|
|
105
|
+
* @returns Promise resolving to array of Relation objects (empty array if no relations found)
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const manager = new RelationManager(storage);
|
|
110
|
+
*
|
|
111
|
+
* // Get all relations for an entity
|
|
112
|
+
* const aliceRelations = await manager.getRelations('Alice');
|
|
113
|
+
* // Returns: [
|
|
114
|
+
* // { from: 'Alice', to: 'Bob', relationType: 'works_with' },
|
|
115
|
+
* // { from: 'Alice', to: 'Project_X', relationType: 'contributes_to' },
|
|
116
|
+
* // { from: 'Charlie', to: 'Alice', relationType: 'reports_to' }
|
|
117
|
+
* // ]
|
|
118
|
+
*
|
|
119
|
+
* // Process relations by type
|
|
120
|
+
* const relations = await manager.getRelations('Alice');
|
|
121
|
+
* const outgoing = relations.filter(r => r.from === 'Alice');
|
|
122
|
+
* const incoming = relations.filter(r => r.to === 'Alice');
|
|
123
|
+
*
|
|
124
|
+
* // Handle entity with no relations
|
|
125
|
+
* const noRelations = await manager.getRelations('IsolatedEntity');
|
|
126
|
+
* console.log(noRelations); // []
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
getRelations(entityName: string): Promise<Relation[]>;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=RelationManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RelationManager.d.ts","sourceRoot":"","sources":["../../src/core/RelationManager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAKtD;;GAEG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,YAAY;IAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACG,eAAe,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAiEjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACG,eAAe,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAqC3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACG,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;CAK5D"}
|