@danielsimonjr/memory-mcp 11.0.1 → 11.1.1
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 -22
- package/dist/core/EntityManager.d.ts +10 -15
- package/dist/core/EntityManager.d.ts.map +1 -1
- package/dist/core/EntityManager.js +21 -54
- package/dist/core/GraphStorage.d.ts +0 -51
- package/dist/core/GraphStorage.d.ts.map +1 -1
- package/dist/core/GraphStorage.js +2 -79
- package/dist/core/GraphTraversal.d.ts +2 -7
- package/dist/core/GraphTraversal.d.ts.map +1 -1
- package/dist/core/GraphTraversal.js +2 -19
- package/dist/core/ManagerContext.d.ts +0 -4
- package/dist/core/ManagerContext.d.ts.map +1 -1
- package/dist/core/ManagerContext.js +2 -12
- package/dist/core/RelationManager.d.ts.map +1 -1
- package/dist/core/RelationManager.js +4 -5
- package/dist/core/SQLiteStorage.d.ts.map +1 -1
- package/dist/core/SQLiteStorage.js +2 -3
- package/dist/core/TransactionManager.d.ts +2 -207
- package/dist/core/TransactionManager.d.ts.map +1 -1
- package/dist/core/TransactionManager.js +6 -482
- package/dist/core/index.d.ts +1 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -3
- package/dist/features/ArchiveManager.d.ts +2 -14
- package/dist/features/ArchiveManager.d.ts.map +1 -1
- package/dist/features/ArchiveManager.js +3 -44
- package/dist/features/CompressionManager.d.ts +4 -14
- package/dist/features/CompressionManager.d.ts.map +1 -1
- package/dist/features/CompressionManager.js +9 -74
- package/dist/features/IOManager.d.ts +2 -6
- package/dist/features/IOManager.d.ts.map +1 -1
- package/dist/features/IOManager.js +10 -105
- package/dist/features/StreamingExporter.d.ts +4 -27
- package/dist/features/StreamingExporter.d.ts.map +1 -1
- package/dist/features/StreamingExporter.js +4 -65
- package/dist/features/index.d.ts +0 -2
- package/dist/features/index.d.ts.map +1 -1
- package/dist/features/index.js +0 -3
- package/dist/search/EmbeddingService.d.ts +9 -108
- package/dist/search/EmbeddingService.d.ts.map +1 -1
- package/dist/search/EmbeddingService.js +15 -187
- package/dist/search/FuzzySearch.js +1 -1
- package/dist/search/SavedSearchManager.d.ts.map +1 -1
- package/dist/search/SavedSearchManager.js +2 -3
- package/dist/search/SearchManager.d.ts +1 -42
- package/dist/search/SearchManager.d.ts.map +1 -1
- package/dist/search/SearchManager.js +0 -115
- package/dist/search/SemanticSearch.d.ts +1 -4
- package/dist/search/SemanticSearch.d.ts.map +1 -1
- package/dist/search/SemanticSearch.js +2 -12
- package/dist/search/TFIDFIndexManager.d.ts +0 -88
- package/dist/search/TFIDFIndexManager.d.ts.map +1 -1
- package/dist/search/TFIDFIndexManager.js +0 -217
- package/dist/search/index.d.ts +1 -18
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/index.js +1 -32
- package/dist/server/MCPServer.d.ts.map +1 -1
- package/dist/server/MCPServer.js +4 -1
- package/dist/server/responseCompressor.js +5 -5
- package/dist/server/toolDefinitions.d.ts.map +1 -1
- package/dist/server/toolDefinitions.js +5 -1
- package/dist/server/toolHandlers.d.ts +9 -5
- package/dist/server/toolHandlers.d.ts.map +1 -1
- package/dist/server/toolHandlers.js +23 -8
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +2 -579
- package/dist/types/types.d.ts.map +1 -1
- package/dist/utils/compressedCache.d.ts +0 -29
- package/dist/utils/compressedCache.d.ts.map +1 -1
- package/dist/utils/compressedCache.js +0 -39
- package/dist/utils/entityUtils.d.ts +1 -59
- package/dist/utils/entityUtils.d.ts.map +1 -1
- package/dist/utils/entityUtils.js +3 -113
- package/dist/utils/errors.d.ts +0 -18
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +0 -24
- package/dist/utils/index.d.ts +2 -6
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -14
- package/dist/utils/logger.d.ts +0 -7
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +2 -9
- package/dist/utils/parallelUtils.d.ts +1 -5
- package/dist/utils/parallelUtils.d.ts.map +1 -1
- package/dist/utils/parallelUtils.js +1 -23
- package/dist/utils/schemas.d.ts +16 -16
- package/dist/utils/schemas.d.ts.map +1 -1
- package/dist/utils/schemas.js +12 -12
- package/dist/utils/taskScheduler.d.ts +0 -4
- package/dist/utils/taskScheduler.d.ts.map +1 -1
- package/dist/utils/taskScheduler.js +1 -21
- package/dist/workers/WorkerPool.d.ts +81 -0
- package/dist/workers/WorkerPool.d.ts.map +1 -0
- package/dist/workers/WorkerPool.js +121 -0
- package/dist/workers/index.d.ts +1 -1
- package/dist/workers/index.d.ts.map +1 -1
- package/dist/workers/levenshteinWorker.js +1 -1
- package/package.json +1 -4
- package/dist/__tests__/file-path.test.js +0 -119
- package/dist/__tests__/knowledge-graph.test.js +0 -318
- package/dist/core/GraphEventEmitter.d.ts +0 -202
- package/dist/core/GraphEventEmitter.d.ts.map +0 -1
- package/dist/core/GraphEventEmitter.js +0 -346
- package/dist/features/KeywordExtractor.d.ts +0 -61
- package/dist/features/KeywordExtractor.d.ts.map +0 -1
- package/dist/features/KeywordExtractor.js +0 -126
- package/dist/features/ObservationNormalizer.d.ts +0 -90
- package/dist/features/ObservationNormalizer.d.ts.map +0 -1
- package/dist/features/ObservationNormalizer.js +0 -193
- package/dist/memory.jsonl +0 -1
- package/dist/search/BM25Search.d.ts +0 -148
- package/dist/search/BM25Search.d.ts.map +0 -1
- package/dist/search/BM25Search.js +0 -339
- package/dist/search/EarlyTerminationManager.d.ts +0 -140
- package/dist/search/EarlyTerminationManager.d.ts.map +0 -1
- package/dist/search/EarlyTerminationManager.js +0 -279
- package/dist/search/EmbeddingCache.d.ts +0 -175
- package/dist/search/EmbeddingCache.d.ts.map +0 -1
- package/dist/search/EmbeddingCache.js +0 -246
- package/dist/search/HybridScorer.d.ts +0 -181
- package/dist/search/HybridScorer.d.ts.map +0 -1
- package/dist/search/HybridScorer.js +0 -257
- package/dist/search/HybridSearchManager.d.ts +0 -80
- package/dist/search/HybridSearchManager.d.ts.map +0 -1
- package/dist/search/HybridSearchManager.js +0 -187
- package/dist/search/IncrementalIndexer.d.ts +0 -201
- package/dist/search/IncrementalIndexer.d.ts.map +0 -1
- package/dist/search/IncrementalIndexer.js +0 -342
- package/dist/search/OptimizedInvertedIndex.d.ts +0 -163
- package/dist/search/OptimizedInvertedIndex.d.ts.map +0 -1
- package/dist/search/OptimizedInvertedIndex.js +0 -358
- package/dist/search/ParallelSearchExecutor.d.ts +0 -172
- package/dist/search/ParallelSearchExecutor.d.ts.map +0 -1
- package/dist/search/ParallelSearchExecutor.js +0 -309
- package/dist/search/QuantizedVectorStore.d.ts +0 -171
- package/dist/search/QuantizedVectorStore.d.ts.map +0 -1
- package/dist/search/QuantizedVectorStore.js +0 -307
- package/dist/search/QueryAnalyzer.d.ts +0 -76
- package/dist/search/QueryAnalyzer.d.ts.map +0 -1
- package/dist/search/QueryAnalyzer.js +0 -227
- package/dist/search/QueryCostEstimator.d.ts +0 -244
- package/dist/search/QueryCostEstimator.d.ts.map +0 -1
- package/dist/search/QueryCostEstimator.js +0 -652
- package/dist/search/QueryPlanCache.d.ts +0 -220
- package/dist/search/QueryPlanCache.d.ts.map +0 -1
- package/dist/search/QueryPlanCache.js +0 -379
- package/dist/search/QueryPlanner.d.ts +0 -58
- package/dist/search/QueryPlanner.d.ts.map +0 -1
- package/dist/search/QueryPlanner.js +0 -137
- package/dist/search/ReflectionManager.d.ts +0 -120
- package/dist/search/ReflectionManager.d.ts.map +0 -1
- package/dist/search/ReflectionManager.js +0 -231
- package/dist/search/SymbolicSearch.d.ts +0 -61
- package/dist/search/SymbolicSearch.d.ts.map +0 -1
- package/dist/search/SymbolicSearch.js +0 -163
- package/dist/search/TFIDFEventSync.d.ts +0 -85
- package/dist/search/TFIDFEventSync.d.ts.map +0 -1
- package/dist/search/TFIDFEventSync.js +0 -133
- package/dist/utils/BatchProcessor.d.ts +0 -271
- package/dist/utils/BatchProcessor.d.ts.map +0 -1
- package/dist/utils/BatchProcessor.js +0 -376
- package/dist/utils/MemoryMonitor.d.ts +0 -176
- package/dist/utils/MemoryMonitor.d.ts.map +0 -1
- package/dist/utils/MemoryMonitor.js +0 -305
- package/dist/utils/WorkerPoolManager.d.ts +0 -233
- package/dist/utils/WorkerPoolManager.d.ts.map +0 -1
- package/dist/utils/WorkerPoolManager.js +0 -420
- package/dist/utils/operationUtils.d.ts +0 -124
- package/dist/utils/operationUtils.d.ts.map +0 -1
- package/dist/utils/operationUtils.js +0 -175
- package/dist/vitest.config.js +0 -13
package/LICENSE
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Anthropic, PBC (Original Memory MCP Server)
|
|
4
|
-
Copyright (c) 2025 Daniel Simon Jr. (Phase 1-4 Enhancements)
|
|
5
|
-
|
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
in the Software without restriction, including without limitation the rights
|
|
9
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
furnished to do so, subject to the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Anthropic, PBC (Original Memory MCP Server)
|
|
4
|
+
Copyright (c) 2025 Daniel Simon Jr. (Phase 1-4 Enhancements)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -6,8 +6,16 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @module core/EntityManager
|
|
8
8
|
*/
|
|
9
|
-
import type { Entity
|
|
9
|
+
import type { Entity } from '../types/index.js';
|
|
10
10
|
import type { GraphStorage } from './GraphStorage.js';
|
|
11
|
+
/**
|
|
12
|
+
* Minimum importance value (least important).
|
|
13
|
+
*/
|
|
14
|
+
export declare const MIN_IMPORTANCE = 0;
|
|
15
|
+
/**
|
|
16
|
+
* Maximum importance value (most important).
|
|
17
|
+
*/
|
|
18
|
+
export declare const MAX_IMPORTANCE = 10;
|
|
11
19
|
/**
|
|
12
20
|
* Manages entity operations with automatic timestamp handling.
|
|
13
21
|
*/
|
|
@@ -23,13 +31,9 @@ export declare class EntityManager {
|
|
|
23
31
|
* - Normalizes all tags to lowercase for consistent searching
|
|
24
32
|
* - Validates importance values (must be between 0-10)
|
|
25
33
|
*
|
|
26
|
-
* Phase 9B: Supports progress tracking and cancellation via LongRunningOperationOptions.
|
|
27
|
-
*
|
|
28
34
|
* @param entities - Array of entities to create. Each entity must have a unique name.
|
|
29
|
-
* @param options - Optional progress/cancellation options (Phase 9B)
|
|
30
35
|
* @returns Promise resolving to array of newly created entities (excludes duplicates)
|
|
31
36
|
* @throws {InvalidImportanceError} If any entity has importance outside the valid range [0-10]
|
|
32
|
-
* @throws {OperationCancelledError} If operation is cancelled via signal (Phase 9B)
|
|
33
37
|
*
|
|
34
38
|
* @example
|
|
35
39
|
* ```typescript
|
|
@@ -49,16 +53,9 @@ export declare class EntityManager {
|
|
|
49
53
|
* { name: 'Bob', entityType: 'person', observations: [] },
|
|
50
54
|
* { name: 'Charlie', entityType: 'person', observations: [] }
|
|
51
55
|
* ]);
|
|
52
|
-
*
|
|
53
|
-
* // With progress tracking and cancellation (Phase 9B)
|
|
54
|
-
* const controller = new AbortController();
|
|
55
|
-
* const results = await manager.createEntities(largeEntityArray, {
|
|
56
|
-
* signal: controller.signal,
|
|
57
|
-
* onProgress: (p) => console.log(`${p.percentage}% complete`),
|
|
58
|
-
* });
|
|
59
56
|
* ```
|
|
60
57
|
*/
|
|
61
|
-
createEntities(entities: Entity[]
|
|
58
|
+
createEntities(entities: Entity[]): Promise<Entity[]>;
|
|
62
59
|
/**
|
|
63
60
|
* Delete multiple entities by name in a single batch operation.
|
|
64
61
|
*
|
|
@@ -228,8 +225,6 @@ export declare class EntityManager {
|
|
|
228
225
|
/**
|
|
229
226
|
* Add tags to multiple entities in a single operation.
|
|
230
227
|
*
|
|
231
|
-
* OPTIMIZED: Uses Map for O(1) entity lookups instead of O(n) find() per entity.
|
|
232
|
-
*
|
|
233
228
|
* @param entityNames - Names of entities to tag
|
|
234
229
|
* @param tags - Tags to add to each entity
|
|
235
230
|
* @returns Array of results showing which tags were added to each entity
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityManager.d.ts","sourceRoot":"","sources":["../../src/core/EntityManager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"EntityManager.d.ts","sourceRoot":"","sources":["../../src/core/EntityManager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAKtD;;GAEG;AACH,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC;;GAEG;AACH,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC;;GAEG;AACH,qBAAa,aAAa;IACZ,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,YAAY;IAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACG,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA0D3D;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB1D;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;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AE,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAuBxG;;;;;;;;;;OAUG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,gBAAgB,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAmCvH"}
|
|
@@ -7,18 +7,16 @@
|
|
|
7
7
|
* @module core/EntityManager
|
|
8
8
|
*/
|
|
9
9
|
import { EntityNotFoundError, InvalidImportanceError, ValidationError } from '../utils/errors.js';
|
|
10
|
-
import { BatchCreateEntitiesSchema, UpdateEntitySchema, EntityNamesSchema
|
|
10
|
+
import { BatchCreateEntitiesSchema, UpdateEntitySchema, EntityNamesSchema } from '../utils/index.js';
|
|
11
11
|
import { GRAPH_LIMITS } from '../utils/constants.js';
|
|
12
12
|
/**
|
|
13
13
|
* Minimum importance value (least important).
|
|
14
|
-
* Note: Use IMPORTANCE_RANGE from constants.ts for external access.
|
|
15
14
|
*/
|
|
16
|
-
const MIN_IMPORTANCE = 0;
|
|
15
|
+
export const MIN_IMPORTANCE = 0;
|
|
17
16
|
/**
|
|
18
17
|
* Maximum importance value (most important).
|
|
19
|
-
* Note: Use IMPORTANCE_RANGE from constants.ts for external access.
|
|
20
18
|
*/
|
|
21
|
-
const MAX_IMPORTANCE = 10;
|
|
19
|
+
export const MAX_IMPORTANCE = 10;
|
|
22
20
|
/**
|
|
23
21
|
* Manages entity operations with automatic timestamp handling.
|
|
24
22
|
*/
|
|
@@ -36,13 +34,9 @@ export class EntityManager {
|
|
|
36
34
|
* - Normalizes all tags to lowercase for consistent searching
|
|
37
35
|
* - Validates importance values (must be between 0-10)
|
|
38
36
|
*
|
|
39
|
-
* Phase 9B: Supports progress tracking and cancellation via LongRunningOperationOptions.
|
|
40
|
-
*
|
|
41
37
|
* @param entities - Array of entities to create. Each entity must have a unique name.
|
|
42
|
-
* @param options - Optional progress/cancellation options (Phase 9B)
|
|
43
38
|
* @returns Promise resolving to array of newly created entities (excludes duplicates)
|
|
44
39
|
* @throws {InvalidImportanceError} If any entity has importance outside the valid range [0-10]
|
|
45
|
-
* @throws {OperationCancelledError} If operation is cancelled via signal (Phase 9B)
|
|
46
40
|
*
|
|
47
41
|
* @example
|
|
48
42
|
* ```typescript
|
|
@@ -62,28 +56,15 @@ export class EntityManager {
|
|
|
62
56
|
* { name: 'Bob', entityType: 'person', observations: [] },
|
|
63
57
|
* { name: 'Charlie', entityType: 'person', observations: [] }
|
|
64
58
|
* ]);
|
|
65
|
-
*
|
|
66
|
-
* // With progress tracking and cancellation (Phase 9B)
|
|
67
|
-
* const controller = new AbortController();
|
|
68
|
-
* const results = await manager.createEntities(largeEntityArray, {
|
|
69
|
-
* signal: controller.signal,
|
|
70
|
-
* onProgress: (p) => console.log(`${p.percentage}% complete`),
|
|
71
|
-
* });
|
|
72
59
|
* ```
|
|
73
60
|
*/
|
|
74
|
-
async createEntities(entities
|
|
75
|
-
// Check for early cancellation
|
|
76
|
-
checkCancellation(options?.signal, 'createEntities');
|
|
61
|
+
async createEntities(entities) {
|
|
77
62
|
// Validate input
|
|
78
63
|
const validation = BatchCreateEntitiesSchema.safeParse(entities);
|
|
79
64
|
if (!validation.success) {
|
|
80
65
|
const errors = validation.error.issues.map((e) => `${e.path.join('.')}: ${e.message}`);
|
|
81
66
|
throw new ValidationError('Invalid entity data', errors);
|
|
82
67
|
}
|
|
83
|
-
// Setup progress reporter
|
|
84
|
-
const reportProgress = createProgressReporter(options?.onProgress);
|
|
85
|
-
const total = entities.length;
|
|
86
|
-
reportProgress?.(createProgress(0, total, 'createEntities'));
|
|
87
68
|
// Use read-only graph for checking existing entities
|
|
88
69
|
const readGraph = await this.storage.loadGraph();
|
|
89
70
|
const timestamp = new Date().toISOString();
|
|
@@ -92,13 +73,8 @@ export class EntityManager {
|
|
|
92
73
|
if (readGraph.entities.length + entitiesToAdd.length > GRAPH_LIMITS.MAX_ENTITIES) {
|
|
93
74
|
throw new ValidationError('Graph size limit exceeded', [`Adding ${entitiesToAdd.length} entities would exceed maximum of ${GRAPH_LIMITS.MAX_ENTITIES} entities`]);
|
|
94
75
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const newEntities = [];
|
|
98
|
-
let processed = 0;
|
|
99
|
-
for (const e of entitiesToAdd) {
|
|
100
|
-
// Check for cancellation periodically
|
|
101
|
-
checkCancellation(options?.signal, 'createEntities');
|
|
76
|
+
const newEntities = entitiesToAdd
|
|
77
|
+
.map(e => {
|
|
102
78
|
const entity = {
|
|
103
79
|
...e,
|
|
104
80
|
createdAt: e.createdAt || timestamp,
|
|
@@ -115,10 +91,8 @@ export class EntityManager {
|
|
|
115
91
|
}
|
|
116
92
|
entity.importance = e.importance;
|
|
117
93
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
reportProgress?.(createProgress(processed, entitiesToAdd.length, 'createEntities'));
|
|
121
|
-
}
|
|
94
|
+
return entity;
|
|
95
|
+
});
|
|
122
96
|
// OPTIMIZED: Use append for single entity, bulk save for multiple
|
|
123
97
|
// (N individual appends is slower than one bulk write)
|
|
124
98
|
if (newEntities.length === 1) {
|
|
@@ -129,8 +103,6 @@ export class EntityManager {
|
|
|
129
103
|
graph.entities.push(...newEntities);
|
|
130
104
|
await this.storage.saveGraph(graph);
|
|
131
105
|
}
|
|
132
|
-
// Report completion
|
|
133
|
-
reportProgress?.(createProgress(entitiesToAdd.length, entitiesToAdd.length, 'createEntities'));
|
|
134
106
|
return newEntities;
|
|
135
107
|
}
|
|
136
108
|
/**
|
|
@@ -250,8 +222,8 @@ export class EntityManager {
|
|
|
250
222
|
if (!entity) {
|
|
251
223
|
throw new EntityNotFoundError(name);
|
|
252
224
|
}
|
|
253
|
-
// Apply updates
|
|
254
|
-
Object.assign(entity,
|
|
225
|
+
// Apply updates
|
|
226
|
+
Object.assign(entity, updates);
|
|
255
227
|
entity.lastModified = new Date().toISOString();
|
|
256
228
|
await this.storage.saveGraph(graph);
|
|
257
229
|
return entity;
|
|
@@ -310,8 +282,8 @@ export class EntityManager {
|
|
|
310
282
|
throw new EntityNotFoundError(name);
|
|
311
283
|
}
|
|
312
284
|
const entity = graph.entities[idx];
|
|
313
|
-
// Apply updates
|
|
314
|
-
Object.assign(entity,
|
|
285
|
+
// Apply updates
|
|
286
|
+
Object.assign(entity, updateData);
|
|
315
287
|
entity.lastModified = timestamp;
|
|
316
288
|
updatedEntities.push(entity);
|
|
317
289
|
}
|
|
@@ -357,8 +329,9 @@ export class EntityManager {
|
|
|
357
329
|
* @throws {EntityNotFoundError} If entity is not found
|
|
358
330
|
*/
|
|
359
331
|
async removeTags(entityName, tags) {
|
|
360
|
-
|
|
361
|
-
const
|
|
332
|
+
const graph = await this.storage.getGraphForMutation();
|
|
333
|
+
const timestamp = new Date().toISOString();
|
|
334
|
+
const entity = graph.entities.find(e => e.name === entityName);
|
|
362
335
|
if (!entity) {
|
|
363
336
|
throw new EntityNotFoundError(entityName);
|
|
364
337
|
}
|
|
@@ -371,13 +344,14 @@ export class EntityManager {
|
|
|
371
344
|
// Capture existing tags (lowercase) BEFORE filtering to accurately track removals
|
|
372
345
|
const existingTagsLower = entity.tags.map(t => t.toLowerCase());
|
|
373
346
|
// Filter out the tags to remove
|
|
374
|
-
|
|
347
|
+
entity.tags = entity.tags.filter(tag => !normalizedTags.includes(tag.toLowerCase()));
|
|
375
348
|
// A tag was removed if it existed in the original tags
|
|
376
349
|
const removedTags = normalizedTags.filter(tag => existingTagsLower.includes(tag));
|
|
377
|
-
// Update
|
|
378
|
-
if (
|
|
379
|
-
|
|
350
|
+
// Update lastModified timestamp if tags were removed
|
|
351
|
+
if (entity.tags.length < originalLength) {
|
|
352
|
+
entity.lastModified = timestamp;
|
|
380
353
|
}
|
|
354
|
+
await this.storage.saveGraph(graph);
|
|
381
355
|
return { entityName, removedTags };
|
|
382
356
|
}
|
|
383
357
|
/**
|
|
@@ -406,8 +380,6 @@ export class EntityManager {
|
|
|
406
380
|
/**
|
|
407
381
|
* Add tags to multiple entities in a single operation.
|
|
408
382
|
*
|
|
409
|
-
* OPTIMIZED: Uses Map for O(1) entity lookups instead of O(n) find() per entity.
|
|
410
|
-
*
|
|
411
383
|
* @param entityNames - Names of entities to tag
|
|
412
384
|
* @param tags - Tags to add to each entity
|
|
413
385
|
* @returns Array of results showing which tags were added to each entity
|
|
@@ -417,13 +389,8 @@ export class EntityManager {
|
|
|
417
389
|
const timestamp = new Date().toISOString();
|
|
418
390
|
const normalizedTags = tags.map(tag => tag.toLowerCase());
|
|
419
391
|
const results = [];
|
|
420
|
-
// OPTIMIZED: Build Map for O(1) lookups instead of O(n) find() per entity
|
|
421
|
-
const entityMap = new Map();
|
|
422
|
-
for (const e of graph.entities) {
|
|
423
|
-
entityMap.set(e.name, e);
|
|
424
|
-
}
|
|
425
392
|
for (const entityName of entityNames) {
|
|
426
|
-
const entity =
|
|
393
|
+
const entity = graph.entities.find(e => e.name === entityName);
|
|
427
394
|
if (!entity) {
|
|
428
395
|
continue; // Skip non-existent entities
|
|
429
396
|
}
|
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
* @module core/GraphStorage
|
|
8
8
|
*/
|
|
9
9
|
import type { KnowledgeGraph, Entity, Relation, ReadonlyKnowledgeGraph, IGraphStorage, LowercaseData } from '../types/index.js';
|
|
10
|
-
import { BatchTransaction } from './TransactionManager.js';
|
|
11
|
-
import { GraphEventEmitter } from './GraphEventEmitter.js';
|
|
12
10
|
/**
|
|
13
11
|
* GraphStorage manages persistence of the knowledge graph to disk.
|
|
14
12
|
*
|
|
@@ -74,38 +72,12 @@ export declare class GraphStorage implements IGraphStorage {
|
|
|
74
72
|
* Maps words in observations to entity names.
|
|
75
73
|
*/
|
|
76
74
|
private observationIndex;
|
|
77
|
-
/**
|
|
78
|
-
* Phase 10 Sprint 2: Event emitter for graph change notifications.
|
|
79
|
-
* Allows external systems to subscribe to graph changes.
|
|
80
|
-
*/
|
|
81
|
-
private eventEmitter;
|
|
82
75
|
/**
|
|
83
76
|
* Create a new GraphStorage instance.
|
|
84
77
|
*
|
|
85
78
|
* @param memoryFilePath - Absolute path to the JSONL file
|
|
86
79
|
*/
|
|
87
80
|
constructor(memoryFilePath: string);
|
|
88
|
-
/**
|
|
89
|
-
* Get the event emitter for subscribing to graph changes.
|
|
90
|
-
*
|
|
91
|
-
* @returns GraphEventEmitter instance
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```typescript
|
|
95
|
-
* const storage = new GraphStorage('/data/memory.jsonl');
|
|
96
|
-
*
|
|
97
|
-
* // Subscribe to entity creation events
|
|
98
|
-
* storage.events.on('entity:created', (event) => {
|
|
99
|
-
* console.log(`Entity ${event.entity.name} created`);
|
|
100
|
-
* });
|
|
101
|
-
*
|
|
102
|
-
* // Subscribe to all events
|
|
103
|
-
* storage.events.onAny((event) => {
|
|
104
|
-
* console.log(`Graph event: ${event.type}`);
|
|
105
|
-
* });
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
get events(): GraphEventEmitter;
|
|
109
81
|
/**
|
|
110
82
|
* Write content to file with fsync for durability.
|
|
111
83
|
*
|
|
@@ -368,28 +340,5 @@ export declare class GraphStorage implements IGraphStorage {
|
|
|
368
340
|
wordCount: number;
|
|
369
341
|
entityCount: number;
|
|
370
342
|
};
|
|
371
|
-
/**
|
|
372
|
-
* Create a new batch transaction for atomic operations.
|
|
373
|
-
*
|
|
374
|
-
* Returns a BatchTransaction instance that can be used to queue multiple
|
|
375
|
-
* operations and execute them atomically with a single save operation.
|
|
376
|
-
*
|
|
377
|
-
* @returns A new BatchTransaction instance
|
|
378
|
-
*
|
|
379
|
-
* @example
|
|
380
|
-
* ```typescript
|
|
381
|
-
* const storage = new GraphStorage('/data/memory.jsonl');
|
|
382
|
-
*
|
|
383
|
-
* // Create and execute a batch transaction
|
|
384
|
-
* const result = await storage.transaction()
|
|
385
|
-
* .createEntity({ name: 'Alice', entityType: 'person', observations: ['Developer'] })
|
|
386
|
-
* .createEntity({ name: 'Bob', entityType: 'person', observations: ['Designer'] })
|
|
387
|
-
* .createRelation({ from: 'Alice', to: 'Bob', relationType: 'knows' })
|
|
388
|
-
* .execute();
|
|
389
|
-
*
|
|
390
|
-
* console.log(`Batch completed: ${result.operationsExecuted} operations`);
|
|
391
|
-
* ```
|
|
392
|
-
*/
|
|
393
|
-
transaction(): BatchTransaction;
|
|
394
343
|
}
|
|
395
344
|
//# sourceMappingURL=GraphStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphStorage.d.ts","sourceRoot":"","sources":["../../src/core/GraphStorage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIhI
|
|
1
|
+
{"version":3,"file":"GraphStorage.d.ts","sourceRoot":"","sources":["../../src/core/GraphStorage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIhI;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,YAAa,YAAW,aAAa;IA+DpC,OAAO,CAAC,cAAc;IA9DlC;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAe;IAE5B;;;OAGG;IACH,OAAO,CAAC,KAAK,CAA+B;IAE5C;;;OAGG;IACH,OAAO,CAAC,cAAc,CAAa;IAEnC;;;;;;;;OAQG;IACH,OAAO,KAAK,mBAAmB,GAE9B;IAED;;OAEG;IACH,OAAO,CAAC,SAAS,CAA8B;IAE/C;;OAEG;IACH,OAAO,CAAC,SAAS,CAA8B;IAE/C;;OAEG;IACH,OAAO,CAAC,cAAc,CAA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M,GAAG,MAAM,GAAG,SAAS;IAIjD;;;;;OAKG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIhC;;;;;;;;OAQG;IACH,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE;IAY/C;;;;;;;OAOG;IACH,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAI5D;;;;OAIG;IACH,cAAc,IAAI,MAAM,EAAE;IAM1B;;;;;;;OAOG;IACH,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,EAAE;IAIhD;;;;;;;OAOG;IACH,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,EAAE;IAI9C;;;;;;;OAOG;IACH,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,EAAE;IAI/C;;;;;OAKG;IACH,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAMzC;;;;;;;;;OASG;IACH,4BAA4B,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAIvD;;;;;;;;OAQG;IACH,+BAA+B,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;IAI7D;;;;;;;;OAQG;IACH,gCAAgC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;IAI9D;;;;OAIG;IACH,wBAAwB,IAAI;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE;CAGvE"}
|
|
@@ -10,9 +10,6 @@ import { promises as fs } from 'fs';
|
|
|
10
10
|
import { Mutex } from 'async-mutex';
|
|
11
11
|
import { clearAllSearchCaches } from '../utils/searchCache.js';
|
|
12
12
|
import { NameIndex, TypeIndex, LowercaseCache, RelationIndex, ObservationIndex } from '../utils/indexes.js';
|
|
13
|
-
import { sanitizeObject } from '../utils/index.js';
|
|
14
|
-
import { BatchTransaction } from './TransactionManager.js';
|
|
15
|
-
import { GraphEventEmitter } from './GraphEventEmitter.js';
|
|
16
13
|
/**
|
|
17
14
|
* GraphStorage manages persistence of the knowledge graph to disk.
|
|
18
15
|
*
|
|
@@ -80,11 +77,6 @@ export class GraphStorage {
|
|
|
80
77
|
* Maps words in observations to entity names.
|
|
81
78
|
*/
|
|
82
79
|
observationIndex = new ObservationIndex();
|
|
83
|
-
/**
|
|
84
|
-
* Phase 10 Sprint 2: Event emitter for graph change notifications.
|
|
85
|
-
* Allows external systems to subscribe to graph changes.
|
|
86
|
-
*/
|
|
87
|
-
eventEmitter = new GraphEventEmitter();
|
|
88
80
|
/**
|
|
89
81
|
* Create a new GraphStorage instance.
|
|
90
82
|
*
|
|
@@ -93,30 +85,6 @@ export class GraphStorage {
|
|
|
93
85
|
constructor(memoryFilePath) {
|
|
94
86
|
this.memoryFilePath = memoryFilePath;
|
|
95
87
|
}
|
|
96
|
-
// ==================== Phase 10 Sprint 2: Event Emitter Access ====================
|
|
97
|
-
/**
|
|
98
|
-
* Get the event emitter for subscribing to graph changes.
|
|
99
|
-
*
|
|
100
|
-
* @returns GraphEventEmitter instance
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* const storage = new GraphStorage('/data/memory.jsonl');
|
|
105
|
-
*
|
|
106
|
-
* // Subscribe to entity creation events
|
|
107
|
-
* storage.events.on('entity:created', (event) => {
|
|
108
|
-
* console.log(`Entity ${event.entity.name} created`);
|
|
109
|
-
* });
|
|
110
|
-
*
|
|
111
|
-
* // Subscribe to all events
|
|
112
|
-
* storage.events.onAny((event) => {
|
|
113
|
-
* console.log(`Graph event: ${event.type}`);
|
|
114
|
-
* });
|
|
115
|
-
* ```
|
|
116
|
-
*/
|
|
117
|
-
get events() {
|
|
118
|
-
return this.eventEmitter;
|
|
119
|
-
}
|
|
120
88
|
// ==================== Durable File Operations ====================
|
|
121
89
|
/**
|
|
122
90
|
* Write content to file with fsync for durability.
|
|
@@ -243,16 +211,12 @@ export class GraphStorage {
|
|
|
243
211
|
// Build indexes from loaded data
|
|
244
212
|
this.buildEntityIndexes(graph.entities);
|
|
245
213
|
this.buildRelationIndex(graph.relations);
|
|
246
|
-
// Phase 10 Sprint 2: Emit graph:loaded event
|
|
247
|
-
this.eventEmitter.emitGraphLoaded(graph.entities.length, graph.relations.length);
|
|
248
214
|
}
|
|
249
215
|
catch (error) {
|
|
250
216
|
// File doesn't exist - create empty graph
|
|
251
217
|
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
|
|
252
218
|
this.cache = { entities: [], relations: [] };
|
|
253
219
|
this.clearIndexes();
|
|
254
|
-
// Phase 10 Sprint 2: Emit graph:loaded event for empty graph
|
|
255
|
-
this.eventEmitter.emitGraphLoaded(0, 0);
|
|
256
220
|
return;
|
|
257
221
|
}
|
|
258
222
|
throw error;
|
|
@@ -357,8 +321,6 @@ export class GraphStorage {
|
|
|
357
321
|
this.pendingAppends++;
|
|
358
322
|
// Clear search caches
|
|
359
323
|
clearAllSearchCaches();
|
|
360
|
-
// Phase 10 Sprint 2: Emit entity:created event
|
|
361
|
-
this.eventEmitter.emitEntityCreated(entity);
|
|
362
324
|
// Trigger compaction if threshold reached
|
|
363
325
|
if (this.pendingAppends >= this.compactionThreshold) {
|
|
364
326
|
await this.compactInternal();
|
|
@@ -407,8 +369,6 @@ export class GraphStorage {
|
|
|
407
369
|
this.pendingAppends++;
|
|
408
370
|
// Clear search caches
|
|
409
371
|
clearAllSearchCaches();
|
|
410
|
-
// Phase 10 Sprint 2: Emit relation:created event
|
|
411
|
-
this.eventEmitter.emitRelationCreated(relation);
|
|
412
372
|
// Trigger compaction if threshold reached
|
|
413
373
|
if (this.pendingAppends >= this.compactionThreshold) {
|
|
414
374
|
await this.compactInternal();
|
|
@@ -487,8 +447,6 @@ export class GraphStorage {
|
|
|
487
447
|
this.pendingAppends = 0;
|
|
488
448
|
// Clear all search caches since graph data has changed
|
|
489
449
|
clearAllSearchCaches();
|
|
490
|
-
// Phase 10 Sprint 2: Emit graph:saved event
|
|
491
|
-
this.eventEmitter.emitGraphSaved(graph.entities.length, graph.relations.length);
|
|
492
450
|
}
|
|
493
451
|
/**
|
|
494
452
|
* Get the current pending appends count.
|
|
@@ -521,13 +479,6 @@ export class GraphStorage {
|
|
|
521
479
|
const entity = this.cache.entities[entityIndex];
|
|
522
480
|
const oldType = entity.entityType;
|
|
523
481
|
const timestamp = new Date().toISOString();
|
|
524
|
-
// Phase 10 Sprint 2: Capture previous values for event
|
|
525
|
-
const previousValues = {};
|
|
526
|
-
for (const key of Object.keys(updates)) {
|
|
527
|
-
if (key in entity) {
|
|
528
|
-
previousValues[key] = entity[key];
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
482
|
// Build the updated entity data for file write BEFORE modifying cache
|
|
532
483
|
// This ensures cache consistency if file write fails
|
|
533
484
|
const updatedEntity = {
|
|
@@ -563,8 +514,8 @@ export class GraphStorage {
|
|
|
563
514
|
throw error;
|
|
564
515
|
}
|
|
565
516
|
}
|
|
566
|
-
// File write succeeded - NOW update cache in-place
|
|
567
|
-
Object.assign(entity,
|
|
517
|
+
// File write succeeded - NOW update cache in-place
|
|
518
|
+
Object.assign(entity, updates);
|
|
568
519
|
entity.lastModified = timestamp;
|
|
569
520
|
// Update indexes
|
|
570
521
|
this.nameIndex.add(entity); // Update reference
|
|
@@ -579,8 +530,6 @@ export class GraphStorage {
|
|
|
579
530
|
this.pendingAppends++;
|
|
580
531
|
// Clear search caches
|
|
581
532
|
clearAllSearchCaches();
|
|
582
|
-
// Phase 10 Sprint 2: Emit entity:updated event
|
|
583
|
-
this.eventEmitter.emitEntityUpdated(entityName, updates, previousValues);
|
|
584
533
|
// Trigger compaction if threshold reached
|
|
585
534
|
if (this.pendingAppends >= this.compactionThreshold) {
|
|
586
535
|
await this.compactInternal();
|
|
@@ -756,30 +705,4 @@ export class GraphStorage {
|
|
|
756
705
|
getObservationIndexStats() {
|
|
757
706
|
return this.observationIndex.getStats();
|
|
758
707
|
}
|
|
759
|
-
// ==================== Phase 10 Sprint 1: Transaction Factory ====================
|
|
760
|
-
/**
|
|
761
|
-
* Create a new batch transaction for atomic operations.
|
|
762
|
-
*
|
|
763
|
-
* Returns a BatchTransaction instance that can be used to queue multiple
|
|
764
|
-
* operations and execute them atomically with a single save operation.
|
|
765
|
-
*
|
|
766
|
-
* @returns A new BatchTransaction instance
|
|
767
|
-
*
|
|
768
|
-
* @example
|
|
769
|
-
* ```typescript
|
|
770
|
-
* const storage = new GraphStorage('/data/memory.jsonl');
|
|
771
|
-
*
|
|
772
|
-
* // Create and execute a batch transaction
|
|
773
|
-
* const result = await storage.transaction()
|
|
774
|
-
* .createEntity({ name: 'Alice', entityType: 'person', observations: ['Developer'] })
|
|
775
|
-
* .createEntity({ name: 'Bob', entityType: 'person', observations: ['Designer'] })
|
|
776
|
-
* .createRelation({ from: 'Alice', to: 'Bob', relationType: 'knows' })
|
|
777
|
-
* .execute();
|
|
778
|
-
*
|
|
779
|
-
* console.log(`Batch completed: ${result.operationsExecuted} operations`);
|
|
780
|
-
* ```
|
|
781
|
-
*/
|
|
782
|
-
transaction() {
|
|
783
|
-
return new BatchTransaction(this);
|
|
784
|
-
}
|
|
785
708
|
}
|
|
@@ -60,18 +60,13 @@ export declare class GraphTraversal {
|
|
|
60
60
|
/**
|
|
61
61
|
* Find all paths between two entities up to a maximum depth.
|
|
62
62
|
*
|
|
63
|
-
* Phase 9B: Supports cancellation via AbortSignal in options.
|
|
64
|
-
*
|
|
65
63
|
* @param source - Source entity name
|
|
66
64
|
* @param target - Target entity name
|
|
67
65
|
* @param maxDepth - Maximum path length (default: 5)
|
|
68
|
-
* @param options - Traversal options
|
|
66
|
+
* @param options - Traversal options
|
|
69
67
|
* @returns Array of PathResult objects for all found paths
|
|
70
|
-
* @throws {OperationCancelledError} If operation is cancelled via signal (Phase 9B)
|
|
71
68
|
*/
|
|
72
|
-
findAllPaths(source: string, target: string, maxDepth?: number, options?: TraversalOptions
|
|
73
|
-
signal?: AbortSignal;
|
|
74
|
-
}): Promise<PathResult[]>;
|
|
69
|
+
findAllPaths(source: string, target: string, maxDepth?: number, options?: TraversalOptions): Promise<PathResult[]>;
|
|
75
70
|
/**
|
|
76
71
|
* Find all connected components in the graph.
|
|
77
72
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphTraversal.d.ts","sourceRoot":"","sources":["../../src/core/GraphTraversal.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAEV,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,yBAAyB,EACzB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"GraphTraversal.d.ts","sourceRoot":"","sources":["../../src/core/GraphTraversal.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAEV,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,yBAAyB,EACzB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAYtD;;;;;GAKG;AACH,qBAAa,cAAc;IACb,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,YAAY;IAIzC;;;;;;OAMG;IACH,yBAAyB,CACvB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,gBAAqB,GAC7B,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,QAAQ,CAAA;KAAE,CAAC;IA4ClD;;;;;;OAMG;IACH,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,eAAe;IAwCzE;;;;;;OAMG;IACH,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,eA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import { checkCancellation } from '../utils/index.js';
|
|
10
9
|
/**
|
|
11
10
|
* Phase 4 Sprint 6: Default traversal options.
|
|
12
11
|
*/
|
|
@@ -226,41 +225,25 @@ export class GraphTraversal {
|
|
|
226
225
|
/**
|
|
227
226
|
* Find all paths between two entities up to a maximum depth.
|
|
228
227
|
*
|
|
229
|
-
* Phase 9B: Supports cancellation via AbortSignal in options.
|
|
230
|
-
*
|
|
231
228
|
* @param source - Source entity name
|
|
232
229
|
* @param target - Target entity name
|
|
233
230
|
* @param maxDepth - Maximum path length (default: 5)
|
|
234
|
-
* @param options - Traversal options
|
|
231
|
+
* @param options - Traversal options
|
|
235
232
|
* @returns Array of PathResult objects for all found paths
|
|
236
|
-
* @throws {OperationCancelledError} If operation is cancelled via signal (Phase 9B)
|
|
237
233
|
*/
|
|
238
234
|
async findAllPaths(source, target, maxDepth = 5, options = {}) {
|
|
239
|
-
// Check for early cancellation
|
|
240
|
-
const { signal, ...traversalOptions } = options;
|
|
241
|
-
checkCancellation(signal, 'findAllPaths');
|
|
242
235
|
// Ensure graph is loaded to populate indexes
|
|
243
236
|
await this.storage.loadGraph();
|
|
244
|
-
// Check for cancellation after load
|
|
245
|
-
checkCancellation(signal, 'findAllPaths');
|
|
246
237
|
// Validate entities exist
|
|
247
238
|
if (!this.storage.hasEntity(source) || !this.storage.hasEntity(target)) {
|
|
248
239
|
return [];
|
|
249
240
|
}
|
|
250
|
-
const opts = { ...DEFAULT_OPTIONS, ...
|
|
241
|
+
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
251
242
|
const allPaths = [];
|
|
252
243
|
const currentPath = [source];
|
|
253
244
|
const currentRelations = [];
|
|
254
245
|
const visited = new Set([source]);
|
|
255
|
-
// Track iterations for periodic cancellation checks
|
|
256
|
-
let iterationCount = 0;
|
|
257
|
-
const CANCELLATION_CHECK_INTERVAL = 100;
|
|
258
246
|
const dfsAllPaths = (current, depth) => {
|
|
259
|
-
// Periodic cancellation check
|
|
260
|
-
iterationCount++;
|
|
261
|
-
if (iterationCount % CANCELLATION_CHECK_INTERVAL === 0) {
|
|
262
|
-
checkCancellation(signal, 'findAllPaths');
|
|
263
|
-
}
|
|
264
247
|
if (depth > maxDepth)
|
|
265
248
|
return;
|
|
266
249
|
if (current === target && depth > 0) {
|
|
@@ -14,7 +14,6 @@ import { ObservationManager } from './ObservationManager.js';
|
|
|
14
14
|
import { HierarchyManager } from './HierarchyManager.js';
|
|
15
15
|
import { GraphTraversal } from './GraphTraversal.js';
|
|
16
16
|
import { SearchManager } from '../search/SearchManager.js';
|
|
17
|
-
import { RankedSearch } from '../search/RankedSearch.js';
|
|
18
17
|
import { SemanticSearch } from '../search/index.js';
|
|
19
18
|
import { IOManager } from '../features/IOManager.js';
|
|
20
19
|
import { TagManager } from '../features/TagManager.js';
|
|
@@ -36,7 +35,6 @@ export declare class ManagerContext {
|
|
|
36
35
|
private _graphTraversal?;
|
|
37
36
|
private _searchManager?;
|
|
38
37
|
private _semanticSearch?;
|
|
39
|
-
private _rankedSearch?;
|
|
40
38
|
private _ioManager?;
|
|
41
39
|
private _tagManager?;
|
|
42
40
|
private _analyticsManager?;
|
|
@@ -60,8 +58,6 @@ export declare class ManagerContext {
|
|
|
60
58
|
* Returns null if no embedding provider is configured.
|
|
61
59
|
*/
|
|
62
60
|
get semanticSearch(): SemanticSearch | null;
|
|
63
|
-
/** RankedSearch - Phase 11: TF-IDF/BM25 ranked search for hybrid search */
|
|
64
|
-
get rankedSearch(): RankedSearch;
|
|
65
61
|
/** IOManager - Import, export, and backup operations */
|
|
66
62
|
get ioManager(): IOManager;
|
|
67
63
|
/** TagManager - Tag alias management */
|