@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.
Files changed (172) hide show
  1. package/LICENSE +22 -22
  2. package/dist/core/EntityManager.d.ts +10 -15
  3. package/dist/core/EntityManager.d.ts.map +1 -1
  4. package/dist/core/EntityManager.js +21 -54
  5. package/dist/core/GraphStorage.d.ts +0 -51
  6. package/dist/core/GraphStorage.d.ts.map +1 -1
  7. package/dist/core/GraphStorage.js +2 -79
  8. package/dist/core/GraphTraversal.d.ts +2 -7
  9. package/dist/core/GraphTraversal.d.ts.map +1 -1
  10. package/dist/core/GraphTraversal.js +2 -19
  11. package/dist/core/ManagerContext.d.ts +0 -4
  12. package/dist/core/ManagerContext.d.ts.map +1 -1
  13. package/dist/core/ManagerContext.js +2 -12
  14. package/dist/core/RelationManager.d.ts.map +1 -1
  15. package/dist/core/RelationManager.js +4 -5
  16. package/dist/core/SQLiteStorage.d.ts.map +1 -1
  17. package/dist/core/SQLiteStorage.js +2 -3
  18. package/dist/core/TransactionManager.d.ts +2 -207
  19. package/dist/core/TransactionManager.d.ts.map +1 -1
  20. package/dist/core/TransactionManager.js +6 -482
  21. package/dist/core/index.d.ts +1 -2
  22. package/dist/core/index.d.ts.map +1 -1
  23. package/dist/core/index.js +1 -3
  24. package/dist/features/ArchiveManager.d.ts +2 -14
  25. package/dist/features/ArchiveManager.d.ts.map +1 -1
  26. package/dist/features/ArchiveManager.js +3 -44
  27. package/dist/features/CompressionManager.d.ts +4 -14
  28. package/dist/features/CompressionManager.d.ts.map +1 -1
  29. package/dist/features/CompressionManager.js +9 -74
  30. package/dist/features/IOManager.d.ts +2 -6
  31. package/dist/features/IOManager.d.ts.map +1 -1
  32. package/dist/features/IOManager.js +10 -105
  33. package/dist/features/StreamingExporter.d.ts +4 -27
  34. package/dist/features/StreamingExporter.d.ts.map +1 -1
  35. package/dist/features/StreamingExporter.js +4 -65
  36. package/dist/features/index.d.ts +0 -2
  37. package/dist/features/index.d.ts.map +1 -1
  38. package/dist/features/index.js +0 -3
  39. package/dist/search/EmbeddingService.d.ts +9 -108
  40. package/dist/search/EmbeddingService.d.ts.map +1 -1
  41. package/dist/search/EmbeddingService.js +15 -187
  42. package/dist/search/FuzzySearch.js +1 -1
  43. package/dist/search/SavedSearchManager.d.ts.map +1 -1
  44. package/dist/search/SavedSearchManager.js +2 -3
  45. package/dist/search/SearchManager.d.ts +1 -42
  46. package/dist/search/SearchManager.d.ts.map +1 -1
  47. package/dist/search/SearchManager.js +0 -115
  48. package/dist/search/SemanticSearch.d.ts +1 -4
  49. package/dist/search/SemanticSearch.d.ts.map +1 -1
  50. package/dist/search/SemanticSearch.js +2 -12
  51. package/dist/search/TFIDFIndexManager.d.ts +0 -88
  52. package/dist/search/TFIDFIndexManager.d.ts.map +1 -1
  53. package/dist/search/TFIDFIndexManager.js +0 -217
  54. package/dist/search/index.d.ts +1 -18
  55. package/dist/search/index.d.ts.map +1 -1
  56. package/dist/search/index.js +1 -32
  57. package/dist/server/MCPServer.d.ts.map +1 -1
  58. package/dist/server/MCPServer.js +4 -1
  59. package/dist/server/responseCompressor.js +5 -5
  60. package/dist/server/toolDefinitions.d.ts.map +1 -1
  61. package/dist/server/toolDefinitions.js +5 -1
  62. package/dist/server/toolHandlers.d.ts +9 -5
  63. package/dist/server/toolHandlers.d.ts.map +1 -1
  64. package/dist/server/toolHandlers.js +23 -8
  65. package/dist/types/index.d.ts +1 -1
  66. package/dist/types/index.d.ts.map +1 -1
  67. package/dist/types/types.d.ts +2 -579
  68. package/dist/types/types.d.ts.map +1 -1
  69. package/dist/utils/compressedCache.d.ts +0 -29
  70. package/dist/utils/compressedCache.d.ts.map +1 -1
  71. package/dist/utils/compressedCache.js +0 -39
  72. package/dist/utils/entityUtils.d.ts +1 -59
  73. package/dist/utils/entityUtils.d.ts.map +1 -1
  74. package/dist/utils/entityUtils.js +3 -113
  75. package/dist/utils/errors.d.ts +0 -18
  76. package/dist/utils/errors.d.ts.map +1 -1
  77. package/dist/utils/errors.js +0 -24
  78. package/dist/utils/index.d.ts +2 -6
  79. package/dist/utils/index.d.ts.map +1 -1
  80. package/dist/utils/index.js +2 -14
  81. package/dist/utils/logger.d.ts +0 -7
  82. package/dist/utils/logger.d.ts.map +1 -1
  83. package/dist/utils/logger.js +2 -9
  84. package/dist/utils/parallelUtils.d.ts +1 -5
  85. package/dist/utils/parallelUtils.d.ts.map +1 -1
  86. package/dist/utils/parallelUtils.js +1 -23
  87. package/dist/utils/schemas.d.ts +16 -16
  88. package/dist/utils/schemas.d.ts.map +1 -1
  89. package/dist/utils/schemas.js +12 -12
  90. package/dist/utils/taskScheduler.d.ts +0 -4
  91. package/dist/utils/taskScheduler.d.ts.map +1 -1
  92. package/dist/utils/taskScheduler.js +1 -21
  93. package/dist/workers/WorkerPool.d.ts +81 -0
  94. package/dist/workers/WorkerPool.d.ts.map +1 -0
  95. package/dist/workers/WorkerPool.js +121 -0
  96. package/dist/workers/index.d.ts +1 -1
  97. package/dist/workers/index.d.ts.map +1 -1
  98. package/dist/workers/levenshteinWorker.js +1 -1
  99. package/package.json +1 -4
  100. package/dist/__tests__/file-path.test.js +0 -119
  101. package/dist/__tests__/knowledge-graph.test.js +0 -318
  102. package/dist/core/GraphEventEmitter.d.ts +0 -202
  103. package/dist/core/GraphEventEmitter.d.ts.map +0 -1
  104. package/dist/core/GraphEventEmitter.js +0 -346
  105. package/dist/features/KeywordExtractor.d.ts +0 -61
  106. package/dist/features/KeywordExtractor.d.ts.map +0 -1
  107. package/dist/features/KeywordExtractor.js +0 -126
  108. package/dist/features/ObservationNormalizer.d.ts +0 -90
  109. package/dist/features/ObservationNormalizer.d.ts.map +0 -1
  110. package/dist/features/ObservationNormalizer.js +0 -193
  111. package/dist/memory.jsonl +0 -1
  112. package/dist/search/BM25Search.d.ts +0 -148
  113. package/dist/search/BM25Search.d.ts.map +0 -1
  114. package/dist/search/BM25Search.js +0 -339
  115. package/dist/search/EarlyTerminationManager.d.ts +0 -140
  116. package/dist/search/EarlyTerminationManager.d.ts.map +0 -1
  117. package/dist/search/EarlyTerminationManager.js +0 -279
  118. package/dist/search/EmbeddingCache.d.ts +0 -175
  119. package/dist/search/EmbeddingCache.d.ts.map +0 -1
  120. package/dist/search/EmbeddingCache.js +0 -246
  121. package/dist/search/HybridScorer.d.ts +0 -181
  122. package/dist/search/HybridScorer.d.ts.map +0 -1
  123. package/dist/search/HybridScorer.js +0 -257
  124. package/dist/search/HybridSearchManager.d.ts +0 -80
  125. package/dist/search/HybridSearchManager.d.ts.map +0 -1
  126. package/dist/search/HybridSearchManager.js +0 -187
  127. package/dist/search/IncrementalIndexer.d.ts +0 -201
  128. package/dist/search/IncrementalIndexer.d.ts.map +0 -1
  129. package/dist/search/IncrementalIndexer.js +0 -342
  130. package/dist/search/OptimizedInvertedIndex.d.ts +0 -163
  131. package/dist/search/OptimizedInvertedIndex.d.ts.map +0 -1
  132. package/dist/search/OptimizedInvertedIndex.js +0 -358
  133. package/dist/search/ParallelSearchExecutor.d.ts +0 -172
  134. package/dist/search/ParallelSearchExecutor.d.ts.map +0 -1
  135. package/dist/search/ParallelSearchExecutor.js +0 -309
  136. package/dist/search/QuantizedVectorStore.d.ts +0 -171
  137. package/dist/search/QuantizedVectorStore.d.ts.map +0 -1
  138. package/dist/search/QuantizedVectorStore.js +0 -307
  139. package/dist/search/QueryAnalyzer.d.ts +0 -76
  140. package/dist/search/QueryAnalyzer.d.ts.map +0 -1
  141. package/dist/search/QueryAnalyzer.js +0 -227
  142. package/dist/search/QueryCostEstimator.d.ts +0 -244
  143. package/dist/search/QueryCostEstimator.d.ts.map +0 -1
  144. package/dist/search/QueryCostEstimator.js +0 -652
  145. package/dist/search/QueryPlanCache.d.ts +0 -220
  146. package/dist/search/QueryPlanCache.d.ts.map +0 -1
  147. package/dist/search/QueryPlanCache.js +0 -379
  148. package/dist/search/QueryPlanner.d.ts +0 -58
  149. package/dist/search/QueryPlanner.d.ts.map +0 -1
  150. package/dist/search/QueryPlanner.js +0 -137
  151. package/dist/search/ReflectionManager.d.ts +0 -120
  152. package/dist/search/ReflectionManager.d.ts.map +0 -1
  153. package/dist/search/ReflectionManager.js +0 -231
  154. package/dist/search/SymbolicSearch.d.ts +0 -61
  155. package/dist/search/SymbolicSearch.d.ts.map +0 -1
  156. package/dist/search/SymbolicSearch.js +0 -163
  157. package/dist/search/TFIDFEventSync.d.ts +0 -85
  158. package/dist/search/TFIDFEventSync.d.ts.map +0 -1
  159. package/dist/search/TFIDFEventSync.js +0 -133
  160. package/dist/utils/BatchProcessor.d.ts +0 -271
  161. package/dist/utils/BatchProcessor.d.ts.map +0 -1
  162. package/dist/utils/BatchProcessor.js +0 -376
  163. package/dist/utils/MemoryMonitor.d.ts +0 -176
  164. package/dist/utils/MemoryMonitor.d.ts.map +0 -1
  165. package/dist/utils/MemoryMonitor.js +0 -305
  166. package/dist/utils/WorkerPoolManager.d.ts +0 -233
  167. package/dist/utils/WorkerPoolManager.d.ts.map +0 -1
  168. package/dist/utils/WorkerPoolManager.js +0 -420
  169. package/dist/utils/operationUtils.d.ts +0 -124
  170. package/dist/utils/operationUtils.d.ts.map +0 -1
  171. package/dist/utils/operationUtils.js +0 -175
  172. package/dist/vitest.config.js +0 -13
@@ -1,163 +0,0 @@
1
- /**
2
- * Symbolic Search Layer
3
- *
4
- * Phase 11: Provides metadata-based filtering using structured predicates.
5
- * Part of the three-layer hybrid search architecture.
6
- *
7
- * @module search/SymbolicSearch
8
- */
9
- /**
10
- * Symbolic Search provides metadata-based filtering.
11
- *
12
- * Filters entities using structured predicates on tags, types,
13
- * dates, importance, and hierarchy.
14
- *
15
- * @example
16
- * ```typescript
17
- * const symbolic = new SymbolicSearch();
18
- * const results = symbolic.search(entities, {
19
- * tags: ['important'],
20
- * entityTypes: ['person'],
21
- * importance: { min: 5 }
22
- * });
23
- * ```
24
- */
25
- export class SymbolicSearch {
26
- /**
27
- * Filter entities using structured metadata predicates.
28
- * All filters are AND-combined.
29
- *
30
- * @param entities - Entities to filter
31
- * @param filters - Symbolic filter criteria
32
- * @returns Filtered entities with match scores
33
- */
34
- search(entities, filters) {
35
- const results = [];
36
- for (const entity of entities) {
37
- const { matches, score, matchedFilters } = this.evaluateFilters(entity, filters);
38
- if (matches) {
39
- results.push({ entity, score, matchedFilters });
40
- }
41
- }
42
- // Sort by score descending
43
- return results.sort((a, b) => b.score - a.score);
44
- }
45
- /**
46
- * Evaluate all filters against an entity.
47
- */
48
- evaluateFilters(entity, filters) {
49
- const matchedFilters = [];
50
- let totalFilters = 0;
51
- let matchedCount = 0;
52
- // Tag filter
53
- if (filters.tags && filters.tags.length > 0) {
54
- totalFilters++;
55
- const entityTags = entity.tags ?? [];
56
- const matchingTags = filters.tags.filter((t) => entityTags.some((et) => et.toLowerCase() === t.toLowerCase()));
57
- if (matchingTags.length > 0) {
58
- matchedCount++;
59
- matchedFilters.push(`tags:${matchingTags.join(',')}`);
60
- }
61
- else {
62
- return { matches: false, score: 0, matchedFilters: [] };
63
- }
64
- }
65
- // Entity type filter
66
- if (filters.entityTypes && filters.entityTypes.length > 0) {
67
- totalFilters++;
68
- if (filters.entityTypes.some((t) => t.toLowerCase() === entity.entityType.toLowerCase())) {
69
- matchedCount++;
70
- matchedFilters.push(`type:${entity.entityType}`);
71
- }
72
- else {
73
- return { matches: false, score: 0, matchedFilters: [] };
74
- }
75
- }
76
- // Date range filter
77
- if (filters.dateRange) {
78
- totalFilters++;
79
- const entityDate = entity.createdAt || entity.lastModified;
80
- if (!entityDate) {
81
- // Entities without dates are excluded when date filter is applied
82
- return { matches: false, score: 0, matchedFilters: [] };
83
- }
84
- const date = new Date(entityDate);
85
- const start = filters.dateRange.start ? new Date(filters.dateRange.start) : null;
86
- const end = filters.dateRange.end ? new Date(filters.dateRange.end) : null;
87
- const inRange = (!start || date >= start) && (!end || date <= end);
88
- if (inRange) {
89
- matchedCount++;
90
- matchedFilters.push('dateRange');
91
- }
92
- else {
93
- return { matches: false, score: 0, matchedFilters: [] };
94
- }
95
- }
96
- // Importance filter
97
- if (filters.importance) {
98
- totalFilters++;
99
- const importance = entity.importance ?? 5;
100
- const { min, max } = filters.importance;
101
- const inRange = (min === undefined || importance >= min) &&
102
- (max === undefined || importance <= max);
103
- if (inRange) {
104
- matchedCount++;
105
- matchedFilters.push(`importance:${importance}`);
106
- }
107
- else {
108
- return { matches: false, score: 0, matchedFilters: [] };
109
- }
110
- }
111
- // Parent filter
112
- if (filters.parentId !== undefined) {
113
- totalFilters++;
114
- if (entity.parentId === filters.parentId) {
115
- matchedCount++;
116
- matchedFilters.push(`parent:${filters.parentId}`);
117
- }
118
- else {
119
- return { matches: false, score: 0, matchedFilters: [] };
120
- }
121
- }
122
- // Has observations filter
123
- if (filters.hasObservations !== undefined) {
124
- totalFilters++;
125
- const hasObs = entity.observations.length > 0;
126
- if (hasObs === filters.hasObservations) {
127
- matchedCount++;
128
- matchedFilters.push('hasObservations');
129
- }
130
- else {
131
- return { matches: false, score: 0, matchedFilters: [] };
132
- }
133
- }
134
- // If no filters specified, match all with base score
135
- if (totalFilters === 0) {
136
- return { matches: true, score: 0.5, matchedFilters: [] };
137
- }
138
- // Score based on proportion of filters matched
139
- const score = matchedCount / totalFilters;
140
- return { matches: true, score, matchedFilters };
141
- }
142
- /**
143
- * Get entities matching a specific tag.
144
- */
145
- byTag(entities, tag) {
146
- return entities.filter(e => e.tags?.some(t => t.toLowerCase() === tag.toLowerCase()));
147
- }
148
- /**
149
- * Get entities of a specific type.
150
- */
151
- byType(entities, entityType) {
152
- return entities.filter(e => e.entityType.toLowerCase() === entityType.toLowerCase());
153
- }
154
- /**
155
- * Get entities within importance range.
156
- */
157
- byImportance(entities, min, max) {
158
- return entities.filter(e => {
159
- const imp = e.importance ?? 5;
160
- return imp >= min && imp <= max;
161
- });
162
- }
163
- }
@@ -1,85 +0,0 @@
1
- /**
2
- * TF-IDF Event Sync
3
- *
4
- * Phase 10 Sprint 3: Hooks TFIDFIndexManager to graph events for automatic
5
- * incremental index updates when entities change.
6
- *
7
- * @module search/TFIDFEventSync
8
- */
9
- import type { GraphEventEmitter } from '../core/GraphEventEmitter.js';
10
- import type { TFIDFIndexManager } from './TFIDFIndexManager.js';
11
- import type { IGraphStorage } from '../types/index.js';
12
- /**
13
- * Phase 10 Sprint 3: Synchronizes TF-IDF index with graph changes via events.
14
- *
15
- * Listens to graph events and triggers incremental index updates automatically.
16
- * More efficient than rebuilding the entire index on every change.
17
- *
18
- * @example
19
- * ```typescript
20
- * const storage = new GraphStorage('/data/memory.jsonl');
21
- * const indexManager = new TFIDFIndexManager('/data');
22
- *
23
- * // Load or build index
24
- * await indexManager.loadIndex();
25
- *
26
- * // Enable automatic sync
27
- * const sync = new TFIDFEventSync(indexManager, storage.events, storage);
28
- * sync.enable();
29
- *
30
- * // Now entities added to storage will automatically update the index
31
- * await storage.appendEntity({ name: 'New', entityType: 'test', observations: [] });
32
- *
33
- * // Disable when done
34
- * sync.disable();
35
- * ```
36
- */
37
- export declare class TFIDFEventSync {
38
- private indexManager;
39
- private eventEmitter;
40
- private storage;
41
- private unsubscribers;
42
- private enabled;
43
- /**
44
- * Create a new TFIDFEventSync instance.
45
- *
46
- * @param indexManager - TFIDFIndexManager to sync
47
- * @param eventEmitter - GraphEventEmitter to listen to
48
- * @param storage - Storage to fetch entity data from (for updates)
49
- */
50
- constructor(indexManager: TFIDFIndexManager, eventEmitter: GraphEventEmitter, storage: IGraphStorage);
51
- /**
52
- * Enable automatic index synchronization.
53
- *
54
- * Subscribes to entity:created, entity:updated, and entity:deleted events.
55
- */
56
- enable(): void;
57
- /**
58
- * Disable automatic index synchronization.
59
- *
60
- * Unsubscribes from all events.
61
- */
62
- disable(): void;
63
- /**
64
- * Check if synchronization is enabled.
65
- *
66
- * @returns True if enabled
67
- */
68
- isEnabled(): boolean;
69
- /**
70
- * Handle entity:created event.
71
- * @private
72
- */
73
- private handleEntityCreated;
74
- /**
75
- * Handle entity:updated event.
76
- * @private
77
- */
78
- private handleEntityUpdated;
79
- /**
80
- * Handle entity:deleted event.
81
- * @private
82
- */
83
- private handleEntityDeleted;
84
- }
85
- //# sourceMappingURL=TFIDFEventSync.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TFIDFEventSync.d.ts","sourceRoot":"","sources":["../../src/search/TFIDFEventSync.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAOvD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,aAAa,CAAyB;IAC9C,OAAO,CAAC,OAAO,CAAkB;IAEjC;;;;;;OAMG;gBAED,YAAY,EAAE,iBAAiB,EAC/B,YAAY,EAAE,iBAAiB,EAC/B,OAAO,EAAE,aAAa;IAOxB;;;;OAIG;IACH,MAAM,IAAI,IAAI;IAqBd;;;;OAIG;IACH,OAAO,IAAI,IAAI;IAYf;;;;OAIG;IACH,SAAS,IAAI,OAAO;IAIpB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAY3B;;;OAGG;YACW,mBAAmB;IAkBjC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;CAO5B"}
@@ -1,133 +0,0 @@
1
- /**
2
- * TF-IDF Event Sync
3
- *
4
- * Phase 10 Sprint 3: Hooks TFIDFIndexManager to graph events for automatic
5
- * incremental index updates when entities change.
6
- *
7
- * @module search/TFIDFEventSync
8
- */
9
- /**
10
- * Phase 10 Sprint 3: Synchronizes TF-IDF index with graph changes via events.
11
- *
12
- * Listens to graph events and triggers incremental index updates automatically.
13
- * More efficient than rebuilding the entire index on every change.
14
- *
15
- * @example
16
- * ```typescript
17
- * const storage = new GraphStorage('/data/memory.jsonl');
18
- * const indexManager = new TFIDFIndexManager('/data');
19
- *
20
- * // Load or build index
21
- * await indexManager.loadIndex();
22
- *
23
- * // Enable automatic sync
24
- * const sync = new TFIDFEventSync(indexManager, storage.events, storage);
25
- * sync.enable();
26
- *
27
- * // Now entities added to storage will automatically update the index
28
- * await storage.appendEntity({ name: 'New', entityType: 'test', observations: [] });
29
- *
30
- * // Disable when done
31
- * sync.disable();
32
- * ```
33
- */
34
- export class TFIDFEventSync {
35
- indexManager;
36
- eventEmitter;
37
- storage;
38
- unsubscribers = [];
39
- enabled = false;
40
- /**
41
- * Create a new TFIDFEventSync instance.
42
- *
43
- * @param indexManager - TFIDFIndexManager to sync
44
- * @param eventEmitter - GraphEventEmitter to listen to
45
- * @param storage - Storage to fetch entity data from (for updates)
46
- */
47
- constructor(indexManager, eventEmitter, storage) {
48
- this.indexManager = indexManager;
49
- this.eventEmitter = eventEmitter;
50
- this.storage = storage;
51
- }
52
- /**
53
- * Enable automatic index synchronization.
54
- *
55
- * Subscribes to entity:created, entity:updated, and entity:deleted events.
56
- */
57
- enable() {
58
- if (this.enabled) {
59
- return;
60
- }
61
- // Subscribe to entity events
62
- this.unsubscribers.push(this.eventEmitter.on('entity:created', this.handleEntityCreated.bind(this)));
63
- this.unsubscribers.push(this.eventEmitter.on('entity:updated', this.handleEntityUpdated.bind(this)));
64
- this.unsubscribers.push(this.eventEmitter.on('entity:deleted', this.handleEntityDeleted.bind(this)));
65
- this.enabled = true;
66
- }
67
- /**
68
- * Disable automatic index synchronization.
69
- *
70
- * Unsubscribes from all events.
71
- */
72
- disable() {
73
- if (!this.enabled) {
74
- return;
75
- }
76
- for (const unsubscribe of this.unsubscribers) {
77
- unsubscribe();
78
- }
79
- this.unsubscribers = [];
80
- this.enabled = false;
81
- }
82
- /**
83
- * Check if synchronization is enabled.
84
- *
85
- * @returns True if enabled
86
- */
87
- isEnabled() {
88
- return this.enabled;
89
- }
90
- /**
91
- * Handle entity:created event.
92
- * @private
93
- */
94
- handleEntityCreated(event) {
95
- if (!this.indexManager.isInitialized()) {
96
- return;
97
- }
98
- this.indexManager.addDocument({
99
- name: event.entity.name,
100
- entityType: event.entity.entityType,
101
- observations: event.entity.observations,
102
- });
103
- }
104
- /**
105
- * Handle entity:updated event.
106
- * @private
107
- */
108
- async handleEntityUpdated(event) {
109
- if (!this.indexManager.isInitialized()) {
110
- return;
111
- }
112
- // Fetch the current entity state
113
- const graph = await this.storage.loadGraph();
114
- const entity = graph.entities.find(e => e.name === event.entityName);
115
- if (entity) {
116
- this.indexManager.updateDocument({
117
- name: entity.name,
118
- entityType: entity.entityType,
119
- observations: entity.observations,
120
- });
121
- }
122
- }
123
- /**
124
- * Handle entity:deleted event.
125
- * @private
126
- */
127
- handleEntityDeleted(event) {
128
- if (!this.indexManager.isInitialized()) {
129
- return;
130
- }
131
- this.indexManager.removeDocument(event.entityName);
132
- }
133
- }
@@ -1,271 +0,0 @@
1
- /**
2
- * Batch Processor
3
- *
4
- * Phase 12 Sprint 2: Generic batch processing utility with parallel execution,
5
- * retry logic, progress callbacks, and error collection.
6
- *
7
- * @module utils/BatchProcessor
8
- */
9
- /**
10
- * Progress information for batch processing.
11
- */
12
- export interface BatchProgress {
13
- /** Number of items completed (successfully or failed) */
14
- completed: number;
15
- /** Total number of items to process */
16
- total: number;
17
- /** Completion percentage (0-100) */
18
- percentage: number;
19
- /** Number of successful items */
20
- succeeded: number;
21
- /** Number of failed items */
22
- failed: number;
23
- /** Current item being processed (if applicable) */
24
- currentItem?: unknown;
25
- /** Current batch index */
26
- batchIndex: number;
27
- /** Total number of batches */
28
- totalBatches: number;
29
- }
30
- /**
31
- * Progress callback function type.
32
- */
33
- export type BatchProgressCallback = (progress: BatchProgress) => void;
34
- /**
35
- * Result for a single item in the batch.
36
- */
37
- export interface BatchItemResult<T> {
38
- /** Index of the item in the original array */
39
- index: number;
40
- /** Whether the processing succeeded */
41
- success: boolean;
42
- /** Result value if successful */
43
- result?: T;
44
- /** Error if failed */
45
- error?: Error;
46
- /** Number of attempts made */
47
- attempts: number;
48
- /** Processing time in milliseconds */
49
- durationMs: number;
50
- }
51
- /**
52
- * Overall result of batch processing.
53
- */
54
- export interface BatchProcessResult<T> {
55
- /** Results for each item */
56
- results: BatchItemResult<T>[];
57
- /** Number of successful items */
58
- succeeded: number;
59
- /** Number of failed items */
60
- failed: number;
61
- /** Total processing time in milliseconds */
62
- totalTimeMs: number;
63
- /** Whether all items succeeded */
64
- allSucceeded: boolean;
65
- /** Errors encountered (indexed by item position) */
66
- errors: Map<number, Error>;
67
- }
68
- /**
69
- * Options for batch processing.
70
- */
71
- export interface BatchProcessorOptions {
72
- /** Number of items to process concurrently (default: 4) */
73
- concurrency?: number;
74
- /** Size of each batch for progress reporting (default: equals concurrency) */
75
- batchSize?: number;
76
- /** Maximum retry attempts per item (default: 0 - no retries) */
77
- maxRetries?: number;
78
- /** Initial delay between retries in milliseconds (default: 1000) */
79
- retryDelayMs?: number;
80
- /** Exponential backoff multiplier (default: 2) */
81
- retryBackoffMultiplier?: number;
82
- /** Maximum retry delay in milliseconds (default: 30000) */
83
- maxRetryDelayMs?: number;
84
- /** Whether to continue processing on item failure (default: true) */
85
- continueOnError?: boolean;
86
- /** Progress callback function */
87
- onProgress?: BatchProgressCallback;
88
- /** Timeout per item in milliseconds (default: no timeout) */
89
- itemTimeoutMs?: number;
90
- /** Optional abort signal for cancellation */
91
- signal?: AbortSignal;
92
- }
93
- /**
94
- * BatchProcessor - Generic batch processing with parallel execution
95
- *
96
- * Provides a flexible utility for processing arrays of items with:
97
- * - Configurable concurrency
98
- * - Automatic retry with exponential backoff
99
- * - Progress callbacks for monitoring
100
- * - Error collection without failing the entire batch
101
- * - Cancellation support via AbortSignal
102
- *
103
- * @example
104
- * ```typescript
105
- * const processor = new BatchProcessor<string, number>({
106
- * concurrency: 4,
107
- * maxRetries: 3,
108
- * onProgress: (p) => console.log(`${p.percentage.toFixed(1)}% complete`),
109
- * });
110
- *
111
- * const result = await processor.process(
112
- * ['item1', 'item2', 'item3'],
113
- * async (item) => {
114
- * const response = await fetchData(item);
115
- * return response.value;
116
- * }
117
- * );
118
- *
119
- * console.log(`Succeeded: ${result.succeeded}, Failed: ${result.failed}`);
120
- * ```
121
- */
122
- export declare class BatchProcessor<TInput, TOutput> {
123
- private options;
124
- constructor(options?: BatchProcessorOptions);
125
- /**
126
- * Process all items in batches with the specified processor function.
127
- *
128
- * @param items - Array of items to process
129
- * @param processor - Async function to process each item
130
- * @returns Batch processing result with all item results and statistics
131
- */
132
- process(items: TInput[], processor: (item: TInput, index: number) => Promise<TOutput>): Promise<BatchProcessResult<TOutput>>;
133
- /**
134
- * Process a single item with retry logic.
135
- */
136
- private processItem;
137
- /**
138
- * Calculate delay for retry with exponential backoff.
139
- */
140
- private calculateRetryDelay;
141
- /**
142
- * Create a timeout promise.
143
- */
144
- private createTimeout;
145
- /**
146
- * Sleep for the specified duration.
147
- */
148
- private sleep;
149
- /**
150
- * Get the configured options.
151
- */
152
- getOptions(): BatchProcessorOptions;
153
- }
154
- /**
155
- * Process items in parallel batches (convenience function).
156
- *
157
- * @template TInput - Input item type
158
- * @template TOutput - Output result type
159
- * @param items - Array of items to process
160
- * @param processor - Async function to process each item
161
- * @param options - Batch processing options
162
- * @returns Batch processing result
163
- *
164
- * @example
165
- * ```typescript
166
- * const result = await processBatch(
167
- * urls,
168
- * async (url) => fetch(url).then(r => r.json()),
169
- * { concurrency: 5, maxRetries: 2 }
170
- * );
171
- * ```
172
- */
173
- export declare function processBatch<TInput, TOutput>(items: TInput[], processor: (item: TInput, index: number) => Promise<TOutput>, options?: BatchProcessorOptions): Promise<BatchProcessResult<TOutput>>;
174
- /**
175
- * Process items with automatic retry on failure (convenience function).
176
- *
177
- * @template TInput - Input item type
178
- * @template TOutput - Output result type
179
- * @param items - Array of items to process
180
- * @param processor - Async function to process each item
181
- * @param maxRetries - Maximum retry attempts (default: 3)
182
- * @param onProgress - Optional progress callback
183
- * @returns Batch processing result
184
- *
185
- * @example
186
- * ```typescript
187
- * const result = await processWithRetry(
188
- * items,
189
- * async (item) => unreliableOperation(item),
190
- * 3,
191
- * (p) => console.log(`${p.percentage}%`)
192
- * );
193
- * ```
194
- */
195
- export declare function processWithRetry<TInput, TOutput>(items: TInput[], processor: (item: TInput, index: number) => Promise<TOutput>, maxRetries?: number, onProgress?: BatchProgressCallback): Promise<BatchProcessResult<TOutput>>;
196
- /**
197
- * Chunk an array into smaller arrays of specified size.
198
- *
199
- * @template T - Item type
200
- * @param array - Array to chunk
201
- * @param size - Size of each chunk
202
- * @returns Array of chunks
203
- *
204
- * @example
205
- * ```typescript
206
- * const chunks = chunkArray([1, 2, 3, 4, 5], 2);
207
- * // [[1, 2], [3, 4], [5]]
208
- * ```
209
- */
210
- export declare function chunkArray<T>(array: T[], size: number): T[][];
211
- /**
212
- * Execute async functions in parallel with a concurrency limit.
213
- *
214
- * @template T - Result type
215
- * @param tasks - Array of async functions to execute
216
- * @param concurrency - Maximum concurrent executions
217
- * @returns Array of results (successful results or errors)
218
- *
219
- * @example
220
- * ```typescript
221
- * const tasks = urls.map(url => () => fetch(url));
222
- * const results = await parallelLimit(tasks, 5);
223
- * ```
224
- */
225
- export declare function parallelLimit<T>(tasks: Array<() => Promise<T>>, concurrency: number): Promise<Array<{
226
- success: true;
227
- value: T;
228
- } | {
229
- success: false;
230
- error: Error;
231
- }>>;
232
- /**
233
- * Map over items in parallel with a concurrency limit.
234
- *
235
- * @template TInput - Input item type
236
- * @template TOutput - Output result type
237
- * @param items - Array of items to map
238
- * @param mapper - Async mapping function
239
- * @param concurrency - Maximum concurrent operations (default: 4)
240
- * @returns Array of results (in order)
241
- *
242
- * @example
243
- * ```typescript
244
- * const results = await mapParallel(
245
- * ids,
246
- * async (id) => fetchUser(id),
247
- * 10
248
- * );
249
- * ```
250
- */
251
- export declare function mapParallel<TInput, TOutput>(items: TInput[], mapper: (item: TInput, index: number) => Promise<TOutput>, concurrency?: number): Promise<TOutput[]>;
252
- /**
253
- * Filter items in parallel with a concurrency limit.
254
- *
255
- * @template T - Item type
256
- * @param items - Array of items to filter
257
- * @param predicate - Async predicate function
258
- * @param concurrency - Maximum concurrent operations (default: 4)
259
- * @returns Filtered array (in order)
260
- *
261
- * @example
262
- * ```typescript
263
- * const validItems = await filterParallel(
264
- * items,
265
- * async (item) => validateItem(item),
266
- * 10
267
- * );
268
- * ```
269
- */
270
- export declare function filterParallel<T>(items: T[], predicate: (item: T, index: number) => Promise<boolean>, concurrency?: number): Promise<T[]>;
271
- //# sourceMappingURL=BatchProcessor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BatchProcessor.d.ts","sourceRoot":"","sources":["../../src/utils/BatchProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,0BAA0B;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,8BAA8B;IAC9B,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAI,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,uCAAuC;IACvC,OAAO,EAAE,OAAO,CAAC;IACjB,iCAAiC;IACjC,MAAM,CAAC,EAAE,CAAC,CAAC;IACX,sBAAsB;I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