@danielsimonjr/memory-mcp 12.5.2 → 12.7.0
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/README.md +158 -14
- package/dist/core/EntityManager.d.ts +263 -0
- package/dist/core/EntityManager.d.ts.map +1 -0
- package/dist/core/EntityManager.js +478 -0
- package/dist/core/GraphStorage.d.ts +344 -0
- package/dist/core/GraphStorage.d.ts.map +1 -0
- package/dist/core/GraphStorage.js +708 -0
- package/dist/core/GraphTraversal.d.ts +136 -0
- package/dist/core/GraphTraversal.d.ts.map +1 -0
- package/dist/core/GraphTraversal.js +556 -0
- package/dist/core/HierarchyManager.d.ts +111 -0
- package/dist/core/HierarchyManager.d.ts.map +1 -0
- package/dist/core/HierarchyManager.js +224 -0
- 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 +123 -0
- package/dist/core/RelationManager.d.ts +131 -0
- package/dist/core/RelationManager.d.ts.map +1 -0
- package/dist/core/RelationManager.js +210 -0
- package/dist/core/SQLiteStorage.d.ts +354 -0
- package/dist/core/SQLiteStorage.d.ts.map +1 -0
- package/dist/core/SQLiteStorage.js +917 -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 +259 -0
- package/dist/core/TransactionManager.d.ts.map +1 -0
- package/dist/core/TransactionManager.js +392 -0
- package/dist/core/index.d.ts +16 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +17 -0
- package/dist/features/AnalyticsManager.d.ts +44 -0
- package/dist/features/AnalyticsManager.d.ts.map +1 -0
- package/dist/features/AnalyticsManager.js +223 -0
- package/dist/features/ArchiveManager.d.ts +121 -0
- package/dist/features/ArchiveManager.d.ts.map +1 -0
- package/dist/features/ArchiveManager.js +240 -0
- package/dist/features/CompressionManager.d.ts +109 -0
- package/dist/features/CompressionManager.d.ts.map +1 -0
- package/dist/features/CompressionManager.js +404 -0
- package/dist/features/IOManager.d.ts +221 -0
- package/dist/features/IOManager.d.ts.map +1 -0
- package/dist/features/IOManager.js +997 -0
- package/dist/features/StreamingExporter.d.ts +105 -0
- package/dist/features/StreamingExporter.d.ts.map +1 -0
- package/dist/features/StreamingExporter.js +150 -0
- package/dist/features/TagManager.d.ts +147 -0
- package/dist/features/TagManager.d.ts.map +1 -0
- package/dist/features/TagManager.js +210 -0
- package/dist/features/index.d.ts +12 -0
- package/dist/features/index.d.ts.map +1 -0
- package/dist/features/index.js +11 -0
- package/dist/index.js +8 -2
- package/dist/search/BasicSearch.d.ts +51 -0
- package/dist/search/BasicSearch.d.ts.map +1 -0
- package/dist/search/BasicSearch.js +137 -0
- package/dist/search/BooleanSearch.d.ts +98 -0
- package/dist/search/BooleanSearch.d.ts.map +1 -0
- package/dist/search/BooleanSearch.js +430 -0
- 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 +312 -0
- package/dist/search/RankedSearch.d.ts +71 -0
- package/dist/search/RankedSearch.d.ts.map +1 -0
- package/dist/search/RankedSearch.js +238 -0
- package/dist/search/SavedSearchManager.d.ts +79 -0
- package/dist/search/SavedSearchManager.d.ts.map +1 -0
- package/dist/search/SavedSearchManager.js +145 -0
- package/dist/search/SearchFilterChain.d.ts +120 -0
- package/dist/search/SearchFilterChain.d.ts.map +1 -0
- package/dist/search/SearchFilterChain.js +185 -0
- package/dist/search/SearchManager.d.ts +285 -0
- package/dist/search/SearchManager.d.ts.map +1 -0
- package/dist/search/SearchManager.js +338 -0
- package/dist/search/SearchSuggestions.d.ts +27 -0
- package/dist/search/SearchSuggestions.d.ts.map +1 -0
- package/dist/search/SearchSuggestions.js +57 -0
- package/dist/search/SemanticSearch.d.ts +146 -0
- package/dist/search/SemanticSearch.d.ts.map +1 -0
- package/dist/search/SemanticSearch.js +313 -0
- package/dist/search/TFIDFIndexManager.d.ts +63 -0
- package/dist/search/TFIDFIndexManager.d.ts.map +1 -0
- package/dist/search/TFIDFIndexManager.js +215 -0
- 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 +18 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +21 -0
- package/dist/server/MCPServer.d.ts.map +1 -1
- package/dist/server/toolDefinitions.d.ts +1 -1
- package/dist/server/toolDefinitions.d.ts.map +1 -1
- package/dist/server/toolDefinitions.js +254 -2
- package/dist/server/toolHandlers.d.ts.map +1 -1
- package/dist/server/toolHandlers.js +241 -25
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +12 -0
- package/dist/types/types.d.ts +1234 -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 +252 -0
- package/dist/utils/entityUtils.d.ts +321 -0
- package/dist/utils/entityUtils.d.ts.map +1 -0
- package/dist/utils/entityUtils.js +538 -0
- package/dist/utils/errors.d.ts +77 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +121 -0
- package/dist/utils/formatters.d.ts +145 -0
- package/dist/utils/formatters.d.ts.map +1 -0
- package/dist/utils/formatters.js +132 -0
- package/dist/utils/index.d.ts +22 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +75 -0
- 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/logger.js +33 -0
- package/dist/utils/parallelUtils.d.ts +72 -0
- package/dist/utils/parallelUtils.d.ts.map +1 -0
- package/dist/utils/parallelUtils.js +169 -0
- package/dist/utils/schemas.d.ts +374 -0
- package/dist/utils/schemas.d.ts.map +1 -0
- package/dist/utils/schemas.js +484 -0
- 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/searchCache.js +209 -0
- package/dist/utils/taskScheduler.d.ts +290 -0
- package/dist/utils/taskScheduler.d.ts.map +1 -0
- package/dist/utils/taskScheduler.js +466 -0
- 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 +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 +7 -7
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @module server/toolHandlers
|
|
9
9
|
*/
|
|
10
10
|
import path from 'node:path';
|
|
11
|
-
import { formatToolResponse, formatTextResponse, formatRawResponse, validateWithSchema, validateFilePath, BatchCreateEntitiesSchema, BatchCreateRelationsSchema, EntityNamesSchema, DeleteRelationsSchema, AddObservationsInputSchema, DeleteObservationsInputSchema, ArchiveCriteriaSchema, SavedSearchInputSchema, SavedSearchUpdateSchema, ImportFormatSchema, ExtendedExportFormatSchema, MergeStrategySchema, ExportFilterSchema, SearchQuerySchema, HybridSearchManager, QueryAnalyzer, QueryPlanner, ReflectionManager, ObservationNormalizer, RefIndex,
|
|
11
|
+
import { formatToolResponse, formatTextResponse, formatRawResponse, validateWithSchema, validateFilePath, BatchCreateEntitiesSchema, BatchCreateRelationsSchema, EntityNamesSchema, DeleteRelationsSchema, AddObservationsInputSchema, DeleteObservationsInputSchema, ArchiveCriteriaSchema, SavedSearchInputSchema, SavedSearchUpdateSchema, ImportFormatSchema, ExtendedExportFormatSchema, MergeStrategySchema, ExportFilterSchema, SearchQuerySchema, HybridSearchManager, QueryAnalyzer, QueryPlanner, ReflectionManager, ObservationNormalizer, RefIndex, FreshnessManager, ArtifactManager, CollaborativeSynthesis, FailureDistillation, CognitiveLoadAnalyzer, ConsolidationScheduler, DreamEngine, DistillationPipeline, DefaultDistillationPolicy, NoOpDistillationPolicy, computeEntropy, passesEntropyFilter, EntropyFilterStage, getRoleProfile, listRoleProfiles, QueryCostEstimator, ContradictionDetector, PiiRedactor, DecisionManager, RankedSearch, RelationConsolidator, clearAllSearchCaches, getAllCacheStats, } from '@danielsimonjr/memoryjs';
|
|
12
12
|
import { promises as fs } from 'node:fs';
|
|
13
13
|
import { performance } from 'node:perf_hooks';
|
|
14
14
|
import { z } from 'zod';
|
|
@@ -17,8 +17,6 @@ import { maybeCompressResponse } from './responseCompressor.js';
|
|
|
17
17
|
// WeakMap-based singletons keyed on ManagerContext to avoid re-instantiation per request.
|
|
18
18
|
// These managers are not on ManagerContext directly, so we wire them up once per ctx.
|
|
19
19
|
const refIndexMap = new WeakMap();
|
|
20
|
-
const auditLogMap = new WeakMap();
|
|
21
|
-
const governanceMap = new WeakMap();
|
|
22
20
|
const freshnessMap = new WeakMap();
|
|
23
21
|
const artifactManagerMap = new WeakMap();
|
|
24
22
|
const distillationPipelineMap = new WeakMap();
|
|
@@ -42,6 +40,14 @@ function getStorageFilePath(ctx) {
|
|
|
42
40
|
const storage = ctx.storage;
|
|
43
41
|
return storage.memoryFilePath ?? storage.filePath ?? 'memory.jsonl';
|
|
44
42
|
}
|
|
43
|
+
// Sidecar path for the serialized Cue–Tag–Content graph, following the
|
|
44
|
+
// library's `<basename>-<suffix>` convention (memory.jsonl → memory-reconstructive.json).
|
|
45
|
+
function reconstructiveSidecarPath(ctx) {
|
|
46
|
+
const storagePath = getStorageFilePath(ctx);
|
|
47
|
+
const ext = path.extname(storagePath);
|
|
48
|
+
const base = ext ? storagePath.slice(0, -ext.length) : storagePath;
|
|
49
|
+
return `${base}-reconstructive.json`;
|
|
50
|
+
}
|
|
45
51
|
function getRefIndex(ctx) {
|
|
46
52
|
if (!refIndexMap.has(ctx)) {
|
|
47
53
|
const storagePath = getStorageFilePath(ctx);
|
|
@@ -50,22 +56,6 @@ function getRefIndex(ctx) {
|
|
|
50
56
|
}
|
|
51
57
|
return refIndexMap.get(ctx);
|
|
52
58
|
}
|
|
53
|
-
function getAuditLog(ctx) {
|
|
54
|
-
if (!auditLogMap.has(ctx)) {
|
|
55
|
-
const storagePath = getStorageFilePath(ctx);
|
|
56
|
-
const dir = path.dirname(storagePath);
|
|
57
|
-
auditLogMap.set(ctx, new AuditLog(path.join(dir, 'memory-audit.jsonl')));
|
|
58
|
-
}
|
|
59
|
-
return auditLogMap.get(ctx);
|
|
60
|
-
}
|
|
61
|
-
function getGovernanceManager(ctx) {
|
|
62
|
-
if (!governanceMap.has(ctx)) {
|
|
63
|
-
// GovernanceManager constructor accepts GraphStorage; ctx.storage is GraphStorage
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
-
governanceMap.set(ctx, new GovernanceManager(ctx.storage, getAuditLog(ctx)));
|
|
66
|
-
}
|
|
67
|
-
return governanceMap.get(ctx);
|
|
68
|
-
}
|
|
69
59
|
function getFreshnessManager(ctx) {
|
|
70
60
|
if (!freshnessMap.has(ctx)) {
|
|
71
61
|
freshnessMap.set(ctx, new FreshnessManager(ctx.storage));
|
|
@@ -438,7 +428,33 @@ export const toolHandlers = {
|
|
|
438
428
|
const limit = args.limit !== undefined
|
|
439
429
|
? validateWithSchema(args.limit, z.number().int().positive().max(200), 'Invalid limit')
|
|
440
430
|
: 10;
|
|
441
|
-
const
|
|
431
|
+
const graphWeight = args.graphWeight !== undefined
|
|
432
|
+
? validateWithSchema(args.graphWeight, z.number().min(0).max(1), 'Invalid graphWeight')
|
|
433
|
+
: undefined;
|
|
434
|
+
const expandNeighborsArgs = args.expandNeighbors !== undefined
|
|
435
|
+
? validateWithSchema(args.expandNeighbors, z.object({
|
|
436
|
+
topK: z.number().int().positive().max(100).optional(),
|
|
437
|
+
damping: z.number().min(0).max(1).optional(),
|
|
438
|
+
}).strict(), 'Invalid expandNeighbors')
|
|
439
|
+
: undefined;
|
|
440
|
+
// Only 1-hop expansion is supported by memoryjs, so `hops` is fixed here
|
|
441
|
+
// rather than exposed in the tool schema.
|
|
442
|
+
const expandNeighbors = expandNeighborsArgs !== undefined
|
|
443
|
+
? { hops: 1, ...expandNeighborsArgs }
|
|
444
|
+
: undefined;
|
|
445
|
+
const explain = args.explain !== undefined
|
|
446
|
+
? validateWithSchema(args.explain, z.boolean(), 'Invalid explain flag')
|
|
447
|
+
: undefined;
|
|
448
|
+
const lookFor = args.lookFor !== undefined
|
|
449
|
+
? validateWithSchema(args.lookFor, z.string().min(1), 'Invalid lookFor')
|
|
450
|
+
: undefined;
|
|
451
|
+
// ctx.hybridSearchManager only attaches the GraphRankPrior when
|
|
452
|
+
// MEMORY_HYBRID_GRAPH_WEIGHT is set; per-call graph options need the prior
|
|
453
|
+
// wired explicitly or they would be silently inert.
|
|
454
|
+
const wantsGraphChannel = (graphWeight !== undefined && graphWeight > 0) || expandNeighbors !== undefined;
|
|
455
|
+
const hybridSearch = wantsGraphChannel
|
|
456
|
+
? new HybridSearchManager(ctx.semanticSearch, ctx.rankedSearch, ctx.graphRankPrior)
|
|
457
|
+
: ctx.hybridSearchManager;
|
|
442
458
|
const graph = await ctx.storage.loadGraph();
|
|
443
459
|
const results = await hybridSearch.searchWithEntities(graph, query, {
|
|
444
460
|
semanticWeight: weights?.semantic ?? 0.5,
|
|
@@ -456,6 +472,10 @@ export const toolHandlers = {
|
|
|
456
472
|
}
|
|
457
473
|
: undefined,
|
|
458
474
|
limit,
|
|
475
|
+
graphWeight,
|
|
476
|
+
expandNeighbors,
|
|
477
|
+
explain,
|
|
478
|
+
lookFor,
|
|
459
479
|
});
|
|
460
480
|
return formatToolResponse({
|
|
461
481
|
query,
|
|
@@ -463,6 +483,7 @@ export const toolHandlers = {
|
|
|
463
483
|
semantic: weights?.semantic ?? 0.5,
|
|
464
484
|
lexical: weights?.lexical ?? 0.3,
|
|
465
485
|
symbolic: weights?.symbolic ?? 0.2,
|
|
486
|
+
...(graphWeight !== undefined ? { graph: graphWeight } : {}),
|
|
466
487
|
},
|
|
467
488
|
resultCount: results.length,
|
|
468
489
|
results: results.map((r) => ({
|
|
@@ -472,6 +493,9 @@ export const toolHandlers = {
|
|
|
472
493
|
matchedLayers: r.matchedLayers,
|
|
473
494
|
observations: r.entity.observations.slice(0, 3),
|
|
474
495
|
tags: r.entity.tags,
|
|
496
|
+
...(r.evidencePaths !== undefined ? { evidencePaths: r.evidencePaths } : {}),
|
|
497
|
+
...(r.evidenceTruncated !== undefined ? { evidenceTruncated: r.evidenceTruncated } : {}),
|
|
498
|
+
...(r.lookForScore !== undefined ? { lookForScore: r.lookForScore } : {}),
|
|
475
499
|
})),
|
|
476
500
|
});
|
|
477
501
|
},
|
|
@@ -512,7 +536,7 @@ export const toolHandlers = {
|
|
|
512
536
|
const planner = new QueryPlanner();
|
|
513
537
|
plan = planner.createPlan(query, analysis);
|
|
514
538
|
}
|
|
515
|
-
const hybridSearch =
|
|
539
|
+
const hybridSearch = ctx.hybridSearchManager;
|
|
516
540
|
const reflection = new ReflectionManager(hybridSearch, analyzer);
|
|
517
541
|
const graph = await ctx.storage.loadGraph();
|
|
518
542
|
const result = await reflection.retrieveWithReflection(graph, query, {
|
|
@@ -1076,7 +1100,7 @@ export const toolHandlers = {
|
|
|
1076
1100
|
},
|
|
1077
1101
|
// ==================== GOVERNANCE HANDLERS ====================
|
|
1078
1102
|
set_governance_policy: async (ctx, args) => {
|
|
1079
|
-
const gm =
|
|
1103
|
+
const gm = ctx.governanceManager;
|
|
1080
1104
|
// GovernancePolicy uses function callbacks; we translate boolean args into allow/deny functions
|
|
1081
1105
|
const allowCreate = args.canCreate !== undefined
|
|
1082
1106
|
? validateWithSchema(args.canCreate, z.boolean(), 'Invalid canCreate')
|
|
@@ -1115,20 +1139,20 @@ export const toolHandlers = {
|
|
|
1115
1139
|
const limit = args.limit !== undefined
|
|
1116
1140
|
? validateWithSchema(args.limit, z.number().int().min(1).max(1000), 'Invalid limit')
|
|
1117
1141
|
: 50;
|
|
1118
|
-
const al =
|
|
1142
|
+
const al = ctx.governanceManager.auditLog;
|
|
1119
1143
|
let entries = await al.query(filter);
|
|
1120
1144
|
entries = entries.slice(0, limit);
|
|
1121
1145
|
return formatToolResponse({ entries, count: entries.length });
|
|
1122
1146
|
},
|
|
1123
1147
|
audit_history: async (ctx, args) => {
|
|
1124
1148
|
const entityName = validateWithSchema(args.entityName, z.string().min(1), 'Invalid entityName');
|
|
1125
|
-
const al =
|
|
1149
|
+
const al = ctx.governanceManager.auditLog;
|
|
1126
1150
|
const entries = await al.getHistory(entityName);
|
|
1127
1151
|
return formatToolResponse({ entityName, entries, count: entries.length });
|
|
1128
1152
|
},
|
|
1129
1153
|
rollback_operation: async (ctx, args) => {
|
|
1130
1154
|
const auditEntryId = validateWithSchema(args.auditEntryId, z.string().min(1), 'Invalid auditEntryId');
|
|
1131
|
-
const gm =
|
|
1155
|
+
const gm = ctx.governanceManager;
|
|
1132
1156
|
await gm.rollback(auditEntryId);
|
|
1133
1157
|
return formatTextResponse(`Operation "${auditEntryId}" rolled back successfully`);
|
|
1134
1158
|
},
|
|
@@ -2745,6 +2769,198 @@ export const toolHandlers = {
|
|
|
2745
2769
|
inDegree: incoming.length,
|
|
2746
2770
|
});
|
|
2747
2771
|
},
|
|
2772
|
+
// ==================== EVENT MEMORY HANDLERS (memoryjs v3.0.0) ====================
|
|
2773
|
+
record_event: async (ctx, args) => {
|
|
2774
|
+
const input = validateWithSchema(args, z.object({
|
|
2775
|
+
action: z.string().min(1),
|
|
2776
|
+
actor: z.string().min(1),
|
|
2777
|
+
target: z.string().min(1).optional(),
|
|
2778
|
+
context: z.string().min(1).optional(),
|
|
2779
|
+
participants: z.array(z.string().min(1)).optional(),
|
|
2780
|
+
occurredAt: z.string().min(1).optional(),
|
|
2781
|
+
flowKey: z.string().min(1).optional(),
|
|
2782
|
+
detail: z.array(z.string()).optional(),
|
|
2783
|
+
importance: z.number().optional(),
|
|
2784
|
+
}).strict(), 'Invalid event input');
|
|
2785
|
+
const event = await ctx.eventManager.recordEvent(input);
|
|
2786
|
+
return formatToolResponse({ event });
|
|
2787
|
+
},
|
|
2788
|
+
get_event: async (ctx, args) => {
|
|
2789
|
+
const name = validateWithSchema(args.name, z.string().min(1), 'Invalid event name');
|
|
2790
|
+
const event = await ctx.eventManager.getEvent(name);
|
|
2791
|
+
if (!event) {
|
|
2792
|
+
return formatTextResponse(`Event "${name}" not found`);
|
|
2793
|
+
}
|
|
2794
|
+
return formatToolResponse({ event });
|
|
2795
|
+
},
|
|
2796
|
+
query_events: async (ctx, args) => {
|
|
2797
|
+
const filter = validateWithSchema(args, z.object({
|
|
2798
|
+
actor: z.string().min(1).optional(),
|
|
2799
|
+
target: z.string().min(1).optional(),
|
|
2800
|
+
action: z.string().min(1).optional(),
|
|
2801
|
+
flowKey: z.string().min(1).optional(),
|
|
2802
|
+
timeRange: z.object({
|
|
2803
|
+
start: z.string().min(1).optional(),
|
|
2804
|
+
end: z.string().min(1).optional(),
|
|
2805
|
+
}).strict().optional(),
|
|
2806
|
+
limit: z.number().int().positive().max(1000).optional(),
|
|
2807
|
+
}).strict(), 'Invalid event filter');
|
|
2808
|
+
const events = await ctx.eventManager.queryEvents(filter);
|
|
2809
|
+
return formatToolResponse({ events, count: events.length });
|
|
2810
|
+
},
|
|
2811
|
+
get_event_flow: async (ctx, args) => {
|
|
2812
|
+
const flowKey = validateWithSchema(args.flowKey, z.string().min(1), 'Invalid flowKey');
|
|
2813
|
+
const events = await ctx.eventManager.getFlow(flowKey);
|
|
2814
|
+
return formatToolResponse({ flowKey, events, count: events.length });
|
|
2815
|
+
},
|
|
2816
|
+
who_did_what: async (ctx, args) => {
|
|
2817
|
+
const filter = validateWithSchema(args, z.object({
|
|
2818
|
+
target: z.string().min(1).optional(),
|
|
2819
|
+
context: z.string().min(1).optional(),
|
|
2820
|
+
timeRange: z.object({
|
|
2821
|
+
start: z.string().min(1).optional(),
|
|
2822
|
+
end: z.string().min(1).optional(),
|
|
2823
|
+
}).strict().optional(),
|
|
2824
|
+
limit: z.number().int().positive().max(1000).optional(),
|
|
2825
|
+
}).strict(), 'Invalid filter');
|
|
2826
|
+
const entries = await ctx.eventManager.whoDidWhat(filter);
|
|
2827
|
+
return formatToolResponse({ entries, count: entries.length });
|
|
2828
|
+
},
|
|
2829
|
+
// ==================== RECONSTRUCTIVE MEMORY HANDLERS (memoryjs v3.0.0) ====================
|
|
2830
|
+
ingest_dialogue: async (ctx, args) => {
|
|
2831
|
+
const turns = validateWithSchema(args.turns, z.array(z.object({
|
|
2832
|
+
id: z.string().min(1),
|
|
2833
|
+
speaker: z.string().optional(),
|
|
2834
|
+
text: z.string().min(1),
|
|
2835
|
+
timestamp: z.string().optional(),
|
|
2836
|
+
}).strict()).min(1), 'Invalid dialogue turns');
|
|
2837
|
+
const rm = ctx.reconstructiveMemory();
|
|
2838
|
+
const result = await rm.ingest(turns);
|
|
2839
|
+
return formatToolResponse({
|
|
2840
|
+
distillation: result,
|
|
2841
|
+
persisted: rm.lastPersistResult,
|
|
2842
|
+
stats: rm.stats(),
|
|
2843
|
+
});
|
|
2844
|
+
},
|
|
2845
|
+
reconstruct_memory: async (ctx, args) => {
|
|
2846
|
+
const query = validateWithSchema(args.query, z.string().min(1), 'Invalid query');
|
|
2847
|
+
const options = validateWithSchema({
|
|
2848
|
+
maxSteps: args.maxSteps,
|
|
2849
|
+
perStepBudget: args.perStepBudget,
|
|
2850
|
+
evidenceTarget: args.evidenceTarget,
|
|
2851
|
+
}, z.object({
|
|
2852
|
+
maxSteps: z.number().int().positive().max(32).optional(),
|
|
2853
|
+
perStepBudget: z.number().int().positive().max(100).optional(),
|
|
2854
|
+
evidenceTarget: z.number().int().positive().max(100).optional(),
|
|
2855
|
+
}), 'Invalid reconstruction options');
|
|
2856
|
+
const result = await ctx.reconstructiveMemory().reconstruct(query, options);
|
|
2857
|
+
return formatToolResponse(result);
|
|
2858
|
+
},
|
|
2859
|
+
reconstructive_memory_stats: async (ctx) => {
|
|
2860
|
+
return formatToolResponse(ctx.reconstructiveMemory().stats());
|
|
2861
|
+
},
|
|
2862
|
+
// ==================== RELATION CONSOLIDATION HANDLERS (memoryjs v3.0.0) ====================
|
|
2863
|
+
analyze_relation_duplicates: async (ctx) => {
|
|
2864
|
+
const consolidator = new RelationConsolidator(ctx.relationManager, ctx.entityManager, {
|
|
2865
|
+
embedding: ctx.semanticSearch?.getEmbeddingService(),
|
|
2866
|
+
});
|
|
2867
|
+
const report = await consolidator.analyze();
|
|
2868
|
+
return formatToolResponse(report);
|
|
2869
|
+
},
|
|
2870
|
+
consolidate_relations: async (ctx, args) => {
|
|
2871
|
+
const apply = args.apply !== undefined
|
|
2872
|
+
? validateWithSchema(args.apply, z.boolean(), 'Invalid apply flag')
|
|
2873
|
+
: false;
|
|
2874
|
+
const consolidator = new RelationConsolidator(ctx.relationManager, ctx.entityManager, {
|
|
2875
|
+
embedding: ctx.semanticSearch?.getEmbeddingService(),
|
|
2876
|
+
});
|
|
2877
|
+
const result = await consolidator.consolidate({ apply });
|
|
2878
|
+
return formatToolResponse(result);
|
|
2879
|
+
},
|
|
2880
|
+
// ==================== AGENT REFLECTION HANDLERS (memoryjs v3.0.0) ====================
|
|
2881
|
+
create_reflection: async (ctx, args) => {
|
|
2882
|
+
const parsed = validateWithSchema(args, z.object({
|
|
2883
|
+
scope: z.enum(['session', 'project', 'global']),
|
|
2884
|
+
summary: z.string().min(1),
|
|
2885
|
+
evidence: z.array(z.string().min(1)).min(1),
|
|
2886
|
+
generalizationConfidence: z.number().min(0).max(1),
|
|
2887
|
+
keyInsights: z.array(z.string().min(1)).max(5).optional(),
|
|
2888
|
+
experienceType: z.string().min(1).optional(),
|
|
2889
|
+
sourceSessionId: z.string().min(1).optional(),
|
|
2890
|
+
sourceProjectId: z.string().min(1).optional(),
|
|
2891
|
+
importance: z.number().optional(),
|
|
2892
|
+
agentId: z.string().min(1).optional(),
|
|
2893
|
+
}).strict(), 'Invalid reflection input');
|
|
2894
|
+
const reflection = await ctx.reflectionManager.create({
|
|
2895
|
+
scope: parsed.scope,
|
|
2896
|
+
summary: parsed.summary,
|
|
2897
|
+
evidence: parsed.evidence,
|
|
2898
|
+
generalization_confidence: parsed.generalizationConfidence,
|
|
2899
|
+
keyInsights: parsed.keyInsights,
|
|
2900
|
+
experienceType: parsed.experienceType,
|
|
2901
|
+
sourceSessionId: parsed.sourceSessionId,
|
|
2902
|
+
sourceProjectId: parsed.sourceProjectId,
|
|
2903
|
+
}, { importance: parsed.importance, agentId: parsed.agentId });
|
|
2904
|
+
return formatToolResponse({ reflection });
|
|
2905
|
+
},
|
|
2906
|
+
list_reflections: async (ctx, args) => {
|
|
2907
|
+
const options = validateWithSchema(args, z.object({
|
|
2908
|
+
scope: z.enum(['session', 'project', 'global']).optional(),
|
|
2909
|
+
sourceSessionId: z.string().min(1).optional(),
|
|
2910
|
+
sourceProjectId: z.string().min(1).optional(),
|
|
2911
|
+
minConfidence: z.number().min(0).max(1).optional(),
|
|
2912
|
+
includeArchived: z.boolean().optional(),
|
|
2913
|
+
limit: z.number().int().positive().max(1000).optional(),
|
|
2914
|
+
}).strict(), 'Invalid list options');
|
|
2915
|
+
const reflections = await ctx.reflectionManager.list(options);
|
|
2916
|
+
return formatToolResponse({ reflections, count: reflections.length });
|
|
2917
|
+
},
|
|
2918
|
+
get_relevant_reflections: async (ctx, args) => {
|
|
2919
|
+
const sessionId = validateWithSchema(args.sessionId, z.string().min(1), 'Invalid sessionId');
|
|
2920
|
+
const options = validateWithSchema({
|
|
2921
|
+
sessionEntityNames: args.sessionEntityNames,
|
|
2922
|
+
minConfidence: args.minConfidence,
|
|
2923
|
+
limit: args.limit,
|
|
2924
|
+
}, z.object({
|
|
2925
|
+
sessionEntityNames: z.array(z.string().min(1)).optional(),
|
|
2926
|
+
minConfidence: z.number().min(0).max(1).optional(),
|
|
2927
|
+
limit: z.number().int().positive().max(1000).optional(),
|
|
2928
|
+
}), 'Invalid relevance options');
|
|
2929
|
+
const reflections = await ctx.reflectionManager.getRelevantForSession(sessionId, options);
|
|
2930
|
+
return formatToolResponse({ sessionId, reflections, count: reflections.length });
|
|
2931
|
+
},
|
|
2932
|
+
archive_reflection: async (ctx, args) => {
|
|
2933
|
+
const id = validateWithSchema(args.id, z.string().min(1), 'Invalid reflection id');
|
|
2934
|
+
const result = await ctx.reflectionManager.archive(id);
|
|
2935
|
+
return formatToolResponse(result);
|
|
2936
|
+
},
|
|
2937
|
+
// ==================== RECONSTRUCTIVE MEMORY PERSISTENCE HANDLERS (memoryjs v3.0.0) ====================
|
|
2938
|
+
save_reconstructive_memory: async (ctx) => {
|
|
2939
|
+
const rm = ctx.reconstructiveMemory();
|
|
2940
|
+
const snapshot = rm.toSnapshot();
|
|
2941
|
+
const sidecarPath = reconstructiveSidecarPath(ctx);
|
|
2942
|
+
await fs.writeFile(sidecarPath, JSON.stringify(snapshot), 'utf-8');
|
|
2943
|
+
return formatToolResponse({ path: sidecarPath, stats: rm.stats() });
|
|
2944
|
+
},
|
|
2945
|
+
load_reconstructive_memory: async (ctx) => {
|
|
2946
|
+
const sidecarPath = reconstructiveSidecarPath(ctx);
|
|
2947
|
+
let raw;
|
|
2948
|
+
try {
|
|
2949
|
+
raw = await fs.readFile(sidecarPath, 'utf-8');
|
|
2950
|
+
}
|
|
2951
|
+
catch {
|
|
2952
|
+
throw new Error(`No reconstructive memory snapshot at "${sidecarPath}" — run save_reconstructive_memory first`);
|
|
2953
|
+
}
|
|
2954
|
+
const snapshot = validateWithSchema(JSON.parse(raw), z.object({
|
|
2955
|
+
cues: z.array(z.unknown()),
|
|
2956
|
+
tags: z.array(z.unknown()),
|
|
2957
|
+
contents: z.array(z.unknown()),
|
|
2958
|
+
triples: z.array(z.unknown()),
|
|
2959
|
+
}), `Invalid reconstructive memory snapshot at "${sidecarPath}"`);
|
|
2960
|
+
const rm = ctx.reconstructiveMemory();
|
|
2961
|
+
rm.loadSnapshot(snapshot);
|
|
2962
|
+
return formatToolResponse({ path: sidecarPath, stats: rm.stats() });
|
|
2963
|
+
},
|
|
2748
2964
|
};
|
|
2749
2965
|
/**
|
|
2750
2966
|
* Handle a tool call by dispatching to the appropriate handler.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types Module - Barrel Export
|
|
3
|
+
*
|
|
4
|
+
* Central export point for all type definitions used throughout the
|
|
5
|
+
* Memory MCP Server. All types are consolidated in types.ts (Phase 5 cleanup).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { Entity, Relation, KnowledgeGraph, SearchResult } from './types/index.js';
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export type { Entity, Relation, KnowledgeGraph, ReadonlyKnowledgeGraph, SearchResult, SavedSearch, BooleanQueryNode, DocumentVector, TFIDFIndex, FuzzyCacheKey, BooleanCacheEntry, PaginatedCacheEntry, TokenizedEntity, GraphStats, ValidationReport, ValidationIssue, ValidationWarning, CacheCompressionStats, ArchiveResultExtended, ExportFilter, ExportOptions, ExportResult, ImportResult, CompressionResult, BackupOptions, BackupResult, RestoreResult, BackupMetadataExtended, BackupInfoExtended, TagAlias, IGraphStorage, StorageConfig, LowercaseData, TraversalOptions, TraversalResult, PathResult, ConnectedComponentsResult, CentralityResult, WeightedRelation, EmbeddingService, SemanticSearchResult, IVectorStore, VectorSearchResult, EmbeddingConfig, SemanticIndexOptions, } from './types.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,YAAY,EAEV,MAAM,EACN,QAAQ,EACR,cAAc,EACd,sBAAsB,EAEtB,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,UAAU,EAEV,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EAEf,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EAErB,qBAAqB,EAErB,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,iBAAiB,EAEjB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,sBAAsB,EACtB,kBAAkB,EAElB,QAAQ,EAER,aAAa,EACb,aAAa,EACb,aAAa,EAEb,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,yBAAyB,EACzB,gBAAgB,EAChB,gBAAgB,EAEhB,gBAAgB,EAChB,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types Module - Barrel Export
|
|
3
|
+
*
|
|
4
|
+
* Central export point for all type definitions used throughout the
|
|
5
|
+
* Memory MCP Server. All types are consolidated in types.ts (Phase 5 cleanup).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { Entity, Relation, KnowledgeGraph, SearchResult } from './types/index.js';
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export {};
|