@danielsimonjr/memory-mcp 0.48.0 → 9.8.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/LICENSE +22 -0
- package/README.md +2000 -194
- package/dist/__tests__/file-path.test.js +7 -11
- package/dist/__tests__/knowledge-graph.test.js +3 -8
- package/dist/core/EntityManager.d.ts +266 -0
- package/dist/core/EntityManager.d.ts.map +1 -0
- package/dist/core/EntityManager.js +85 -133
- package/dist/core/GraphEventEmitter.d.ts +202 -0
- package/dist/core/GraphEventEmitter.d.ts.map +1 -0
- package/dist/core/GraphEventEmitter.js +346 -0
- package/dist/core/GraphStorage.d.ts +395 -0
- package/dist/core/GraphStorage.d.ts.map +1 -0
- package/dist/core/GraphStorage.js +643 -31
- package/dist/core/GraphTraversal.d.ts +141 -0
- package/dist/core/GraphTraversal.d.ts.map +1 -0
- package/dist/core/GraphTraversal.js +573 -0
- package/dist/core/HierarchyManager.d.ts +111 -0
- package/dist/core/HierarchyManager.d.ts.map +1 -0
- package/dist/{features → core}/HierarchyManager.js +14 -9
- package/dist/core/ManagerContext.d.ts +72 -0
- package/dist/core/ManagerContext.d.ts.map +1 -0
- package/dist/core/ManagerContext.js +118 -0
- package/dist/core/ObservationManager.d.ts +85 -0
- package/dist/core/ObservationManager.d.ts.map +1 -0
- package/dist/core/ObservationManager.js +51 -57
- package/dist/core/RelationManager.d.ts +131 -0
- package/dist/core/RelationManager.d.ts.map +1 -0
- package/dist/core/RelationManager.js +31 -7
- package/dist/core/SQLiteStorage.d.ts +354 -0
- package/dist/core/SQLiteStorage.d.ts.map +1 -0
- package/dist/core/SQLiteStorage.js +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 +464 -0
- package/dist/core/TransactionManager.d.ts.map +1 -0
- package/dist/core/TransactionManager.js +490 -13
- package/dist/core/index.d.ts +17 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +12 -2
- package/dist/features/AnalyticsManager.d.ts +44 -0
- package/dist/features/AnalyticsManager.d.ts.map +1 -0
- package/dist/features/AnalyticsManager.js +3 -2
- package/dist/features/ArchiveManager.d.ts +133 -0
- package/dist/features/ArchiveManager.d.ts.map +1 -0
- package/dist/features/ArchiveManager.js +221 -14
- package/dist/features/CompressionManager.d.ts +117 -0
- package/dist/features/CompressionManager.d.ts.map +1 -0
- package/dist/features/CompressionManager.js +189 -20
- package/dist/features/IOManager.d.ts +225 -0
- package/dist/features/IOManager.d.ts.map +1 -0
- package/dist/features/IOManager.js +1041 -0
- package/dist/features/StreamingExporter.d.ts +123 -0
- package/dist/features/StreamingExporter.d.ts.map +1 -0
- package/dist/features/StreamingExporter.js +203 -0
- package/dist/features/TagManager.d.ts +147 -0
- package/dist/features/TagManager.d.ts.map +1 -0
- package/dist/features/index.d.ts +12 -0
- package/dist/features/index.d.ts.map +1 -0
- package/dist/features/index.js +5 -6
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -10
- package/dist/memory.jsonl +1 -26
- package/dist/search/BasicSearch.d.ts +51 -0
- package/dist/search/BasicSearch.d.ts.map +1 -0
- package/dist/search/BasicSearch.js +9 -3
- package/dist/search/BooleanSearch.d.ts +98 -0
- package/dist/search/BooleanSearch.d.ts.map +1 -0
- package/dist/search/BooleanSearch.js +156 -9
- package/dist/search/EmbeddingService.d.ts +178 -0
- package/dist/search/EmbeddingService.d.ts.map +1 -0
- package/dist/search/EmbeddingService.js +358 -0
- package/dist/search/FuzzySearch.d.ts +118 -0
- package/dist/search/FuzzySearch.d.ts.map +1 -0
- package/dist/search/FuzzySearch.js +241 -25
- package/dist/search/QueryCostEstimator.d.ts +111 -0
- package/dist/search/QueryCostEstimator.d.ts.map +1 -0
- package/dist/search/QueryCostEstimator.js +355 -0
- package/dist/search/RankedSearch.d.ts +71 -0
- package/dist/search/RankedSearch.d.ts.map +1 -0
- package/dist/search/RankedSearch.js +54 -6
- package/dist/search/SavedSearchManager.d.ts +79 -0
- package/dist/search/SavedSearchManager.d.ts.map +1 -0
- package/dist/search/SearchFilterChain.d.ts +120 -0
- package/dist/search/SearchFilterChain.d.ts.map +1 -0
- package/dist/search/SearchFilterChain.js +2 -4
- package/dist/search/SearchManager.d.ts +326 -0
- package/dist/search/SearchManager.d.ts.map +1 -0
- package/dist/search/SearchManager.js +148 -0
- package/dist/search/SearchSuggestions.d.ts +27 -0
- package/dist/search/SearchSuggestions.d.ts.map +1 -0
- package/dist/search/SearchSuggestions.js +1 -1
- package/dist/search/SemanticSearch.d.ts +149 -0
- package/dist/search/SemanticSearch.d.ts.map +1 -0
- package/dist/search/SemanticSearch.js +323 -0
- package/dist/search/TFIDFEventSync.d.ts +85 -0
- package/dist/search/TFIDFEventSync.d.ts.map +1 -0
- package/dist/search/TFIDFEventSync.js +133 -0
- package/dist/search/TFIDFIndexManager.d.ts +151 -0
- package/dist/search/TFIDFIndexManager.d.ts.map +1 -0
- package/dist/search/TFIDFIndexManager.js +232 -17
- package/dist/search/VectorStore.d.ts +235 -0
- package/dist/search/VectorStore.d.ts.map +1 -0
- package/dist/search/VectorStore.js +311 -0
- package/dist/search/index.d.ts +21 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +12 -0
- package/dist/server/MCPServer.d.ts +21 -0
- package/dist/server/MCPServer.d.ts.map +1 -0
- package/dist/server/MCPServer.js +4 -4
- package/dist/server/responseCompressor.d.ts +94 -0
- package/dist/server/responseCompressor.d.ts.map +1 -0
- package/dist/server/responseCompressor.js +127 -0
- package/dist/server/toolDefinitions.d.ts +27 -0
- package/dist/server/toolDefinitions.d.ts.map +1 -0
- package/dist/server/toolDefinitions.js +188 -17
- package/dist/server/toolHandlers.d.ts +41 -0
- package/dist/server/toolHandlers.d.ts.map +1 -0
- package/dist/server/toolHandlers.js +467 -75
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -1
- package/dist/types/types.d.ts +1654 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +9 -0
- package/dist/utils/compressedCache.d.ts +192 -0
- package/dist/utils/compressedCache.d.ts.map +1 -0
- package/dist/utils/compressedCache.js +309 -0
- package/dist/utils/compressionUtil.d.ts +214 -0
- package/dist/utils/compressionUtil.d.ts.map +1 -0
- package/dist/utils/compressionUtil.js +247 -0
- package/dist/utils/constants.d.ts +245 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +124 -0
- package/dist/utils/entityUtils.d.ts +321 -0
- package/dist/utils/entityUtils.d.ts.map +1 -0
- package/dist/utils/entityUtils.js +434 -4
- package/dist/utils/errors.d.ts +95 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +24 -0
- package/dist/utils/formatters.d.ts +145 -0
- package/dist/utils/formatters.d.ts.map +1 -0
- package/dist/utils/{paginationUtils.js → formatters.js} +54 -3
- package/dist/utils/index.d.ts +23 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +69 -31
- package/dist/utils/indexes.d.ts +270 -0
- package/dist/utils/indexes.d.ts.map +1 -0
- package/dist/utils/indexes.js +526 -0
- package/dist/utils/logger.d.ts +24 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/operationUtils.d.ts +124 -0
- package/dist/utils/operationUtils.d.ts.map +1 -0
- package/dist/utils/operationUtils.js +175 -0
- package/dist/utils/parallelUtils.d.ts +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 +302 -2
- package/dist/utils/searchAlgorithms.d.ts +99 -0
- package/dist/utils/searchAlgorithms.d.ts.map +1 -0
- package/dist/utils/searchAlgorithms.js +167 -0
- package/dist/utils/searchCache.d.ts +108 -0
- package/dist/utils/searchCache.d.ts.map +1 -0
- package/dist/utils/taskScheduler.d.ts +290 -0
- package/dist/utils/taskScheduler.d.ts.map +1 -0
- package/dist/utils/taskScheduler.js +466 -0
- package/dist/workers/index.d.ts +12 -0
- package/dist/workers/index.d.ts.map +1 -0
- package/dist/workers/index.js +9 -0
- package/dist/workers/levenshteinWorker.d.ts +60 -0
- package/dist/workers/levenshteinWorker.d.ts.map +1 -0
- package/dist/workers/levenshteinWorker.js +98 -0
- package/package.json +17 -4
- package/dist/__tests__/edge-cases/edge-cases.test.js +0 -406
- package/dist/__tests__/integration/workflows.test.js +0 -449
- package/dist/__tests__/performance/benchmarks.test.js +0 -413
- package/dist/__tests__/unit/core/EntityManager.test.js +0 -334
- package/dist/__tests__/unit/core/GraphStorage.test.js +0 -205
- package/dist/__tests__/unit/core/RelationManager.test.js +0 -274
- package/dist/__tests__/unit/features/CompressionManager.test.js +0 -350
- package/dist/__tests__/unit/search/BasicSearch.test.js +0 -311
- package/dist/__tests__/unit/search/BooleanSearch.test.js +0 -432
- package/dist/__tests__/unit/search/FuzzySearch.test.js +0 -448
- package/dist/__tests__/unit/search/RankedSearch.test.js +0 -379
- package/dist/__tests__/unit/utils/levenshtein.test.js +0 -77
- package/dist/core/KnowledgeGraphManager.js +0 -423
- package/dist/features/BackupManager.js +0 -311
- package/dist/features/ExportManager.js +0 -305
- package/dist/features/ImportExportManager.js +0 -50
- package/dist/features/ImportManager.js +0 -328
- package/dist/memory-saved-searches.jsonl +0 -0
- package/dist/memory-tag-aliases.jsonl +0 -0
- package/dist/types/analytics.types.js +0 -6
- package/dist/types/entity.types.js +0 -7
- package/dist/types/import-export.types.js +0 -7
- package/dist/types/search.types.js +0 -7
- package/dist/types/tag.types.js +0 -6
- package/dist/utils/dateUtils.js +0 -89
- package/dist/utils/filterUtils.js +0 -155
- package/dist/utils/levenshtein.js +0 -62
- package/dist/utils/pathUtils.js +0 -115
- package/dist/utils/responseFormatter.js +0 -55
- package/dist/utils/tagUtils.js +0 -107
- package/dist/utils/tfidf.js +0 -90
- package/dist/utils/validationHelper.js +0 -99
- package/dist/utils/validationUtils.js +0 -109
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response and Pagination Formatters
|
|
3
|
+
*
|
|
4
|
+
* Consolidated module for MCP tool response formatting and pagination utilities.
|
|
5
|
+
* Centralizes response formatting for MCP tool calls to eliminate redundant patterns.
|
|
6
|
+
*
|
|
7
|
+
* @module utils/formatters
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* MCP Tool Response type - uses the exact shape expected by the SDK.
|
|
11
|
+
* The 'as const' assertion ensures the type literal is preserved.
|
|
12
|
+
*/
|
|
13
|
+
export type ToolResponse = {
|
|
14
|
+
content: Array<{
|
|
15
|
+
type: 'text';
|
|
16
|
+
text: string;
|
|
17
|
+
}>;
|
|
18
|
+
isError?: boolean;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Formats data as an MCP tool response with JSON content.
|
|
22
|
+
* Centralizes the response format to ensure consistency and reduce duplication.
|
|
23
|
+
*
|
|
24
|
+
* @param data - Any data to be JSON stringified
|
|
25
|
+
* @returns Formatted MCP tool response
|
|
26
|
+
*/
|
|
27
|
+
export declare function formatToolResponse(data: unknown): {
|
|
28
|
+
content: {
|
|
29
|
+
type: "text";
|
|
30
|
+
text: string;
|
|
31
|
+
}[];
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Formats a simple text message as an MCP tool response.
|
|
35
|
+
* Use for success messages that don't need JSON formatting.
|
|
36
|
+
*
|
|
37
|
+
* @param message - Plain text message
|
|
38
|
+
* @returns Formatted MCP tool response
|
|
39
|
+
*/
|
|
40
|
+
export declare function formatTextResponse(message: string): {
|
|
41
|
+
content: {
|
|
42
|
+
type: "text";
|
|
43
|
+
text: string;
|
|
44
|
+
}[];
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Formats raw string content as an MCP tool response.
|
|
48
|
+
* Use for export formats that return pre-formatted strings (markdown, CSV, etc.)
|
|
49
|
+
*
|
|
50
|
+
* @param content - Raw string content
|
|
51
|
+
* @returns Formatted MCP tool response
|
|
52
|
+
*/
|
|
53
|
+
export declare function formatRawResponse(content: string): {
|
|
54
|
+
content: {
|
|
55
|
+
type: "text";
|
|
56
|
+
text: string;
|
|
57
|
+
}[];
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Formats an error as an MCP tool response with isError flag.
|
|
61
|
+
*
|
|
62
|
+
* @param error - Error object or message string
|
|
63
|
+
* @returns Formatted MCP tool error response
|
|
64
|
+
*/
|
|
65
|
+
export declare function formatErrorResponse(error: Error | string): {
|
|
66
|
+
content: {
|
|
67
|
+
type: "text";
|
|
68
|
+
text: string;
|
|
69
|
+
}[];
|
|
70
|
+
isError: boolean;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Validated pagination parameters with helper methods.
|
|
74
|
+
*/
|
|
75
|
+
export interface ValidatedPagination {
|
|
76
|
+
/** Validated offset (guaranteed >= 0) */
|
|
77
|
+
offset: number;
|
|
78
|
+
/** Validated limit (guaranteed within SEARCH_LIMITS.MIN to SEARCH_LIMITS.MAX) */
|
|
79
|
+
limit: number;
|
|
80
|
+
/**
|
|
81
|
+
* Check if there are more results beyond the current page.
|
|
82
|
+
* @param totalCount - Total number of items
|
|
83
|
+
* @returns true if there are more items after this page
|
|
84
|
+
*/
|
|
85
|
+
hasMore: (totalCount: number) => boolean;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Validates and normalizes pagination parameters.
|
|
89
|
+
* Ensures offset is non-negative and limit is within configured bounds.
|
|
90
|
+
*
|
|
91
|
+
* @param offset - Starting position (default: 0)
|
|
92
|
+
* @param limit - Maximum results to return (default: SEARCH_LIMITS.DEFAULT)
|
|
93
|
+
* @returns Validated pagination parameters with helper methods
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const pagination = validatePagination(10, 50);
|
|
98
|
+
* const results = items.slice(pagination.offset, pagination.offset + pagination.limit);
|
|
99
|
+
* if (pagination.hasMore(items.length)) {
|
|
100
|
+
* console.log('More results available');
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export declare function validatePagination(offset?: number, limit?: number): ValidatedPagination;
|
|
105
|
+
/**
|
|
106
|
+
* Applies pagination to an array of items.
|
|
107
|
+
*
|
|
108
|
+
* @param items - Array to paginate
|
|
109
|
+
* @param pagination - Validated pagination parameters
|
|
110
|
+
* @returns Paginated slice of the array
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const pagination = validatePagination(offset, limit);
|
|
115
|
+
* const pageResults = applyPagination(allResults, pagination);
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function applyPagination<T>(items: T[], pagination: ValidatedPagination): T[];
|
|
119
|
+
/**
|
|
120
|
+
* Applies pagination using raw offset and limit values.
|
|
121
|
+
* Combines validation and application in one call.
|
|
122
|
+
*
|
|
123
|
+
* @param items - Array to paginate
|
|
124
|
+
* @param offset - Starting position
|
|
125
|
+
* @param limit - Maximum results
|
|
126
|
+
* @returns Paginated slice of the array
|
|
127
|
+
*/
|
|
128
|
+
export declare function paginateArray<T>(items: T[], offset?: number, limit?: number): T[];
|
|
129
|
+
/**
|
|
130
|
+
* Calculates pagination metadata for a result set.
|
|
131
|
+
*
|
|
132
|
+
* @param totalCount - Total number of items
|
|
133
|
+
* @param offset - Current offset
|
|
134
|
+
* @param limit - Current limit
|
|
135
|
+
* @returns Pagination metadata
|
|
136
|
+
*/
|
|
137
|
+
export declare function getPaginationMeta(totalCount: number, offset?: number, limit?: number): {
|
|
138
|
+
totalCount: number;
|
|
139
|
+
offset: number;
|
|
140
|
+
limit: number;
|
|
141
|
+
hasMore: boolean;
|
|
142
|
+
pageNumber: number;
|
|
143
|
+
totalPages: number;
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=formatters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../src/utils/formatters.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO;;;;;EAI/C;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM;;;;;EAIjD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM;;;;;EAIhD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;;;;;;EAMxD;AAID;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,OAAO,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,GAAE,MAAU,EAClB,KAAK,GAAE,MAA8B,GACpC,mBAAmB,CAYrB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,KAAK,EAAE,CAAC,EAAE,EACV,UAAU,EAAE,mBAAmB,GAC9B,CAAC,EAAE,CAEL;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,CAAC,EAAE,EACV,MAAM,GAAE,MAAU,EAClB,KAAK,GAAE,MAA8B,GACpC,CAAC,EAAE,CAGL;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,MAAM,GAAE,MAAU,EAClB,KAAK,GAAE,MAA8B,GACpC;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAWA"}
|
|
@@ -1,10 +1,61 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pagination
|
|
2
|
+
* Response and Pagination Formatters
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* to eliminate
|
|
4
|
+
* Consolidated module for MCP tool response formatting and pagination utilities.
|
|
5
|
+
* Centralizes response formatting for MCP tool calls to eliminate redundant patterns.
|
|
6
|
+
*
|
|
7
|
+
* @module utils/formatters
|
|
6
8
|
*/
|
|
7
9
|
import { SEARCH_LIMITS } from './constants.js';
|
|
10
|
+
/**
|
|
11
|
+
* Formats data as an MCP tool response with JSON content.
|
|
12
|
+
* Centralizes the response format to ensure consistency and reduce duplication.
|
|
13
|
+
*
|
|
14
|
+
* @param data - Any data to be JSON stringified
|
|
15
|
+
* @returns Formatted MCP tool response
|
|
16
|
+
*/
|
|
17
|
+
export function formatToolResponse(data) {
|
|
18
|
+
return {
|
|
19
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Formats a simple text message as an MCP tool response.
|
|
24
|
+
* Use for success messages that don't need JSON formatting.
|
|
25
|
+
*
|
|
26
|
+
* @param message - Plain text message
|
|
27
|
+
* @returns Formatted MCP tool response
|
|
28
|
+
*/
|
|
29
|
+
export function formatTextResponse(message) {
|
|
30
|
+
return {
|
|
31
|
+
content: [{ type: 'text', text: message }],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Formats raw string content as an MCP tool response.
|
|
36
|
+
* Use for export formats that return pre-formatted strings (markdown, CSV, etc.)
|
|
37
|
+
*
|
|
38
|
+
* @param content - Raw string content
|
|
39
|
+
* @returns Formatted MCP tool response
|
|
40
|
+
*/
|
|
41
|
+
export function formatRawResponse(content) {
|
|
42
|
+
return {
|
|
43
|
+
content: [{ type: 'text', text: content }],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Formats an error as an MCP tool response with isError flag.
|
|
48
|
+
*
|
|
49
|
+
* @param error - Error object or message string
|
|
50
|
+
* @returns Formatted MCP tool error response
|
|
51
|
+
*/
|
|
52
|
+
export function formatErrorResponse(error) {
|
|
53
|
+
const message = error instanceof Error ? error.message : error;
|
|
54
|
+
return {
|
|
55
|
+
content: [{ type: 'text', text: message }],
|
|
56
|
+
isError: true,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
8
59
|
/**
|
|
9
60
|
* Validates and normalizes pagination parameters.
|
|
10
61
|
* Ensures offset is non-negative and limit is within configured bounds.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities Module Barrel Export
|
|
3
|
+
*
|
|
4
|
+
* Centralizes all utility exports for convenient importing.
|
|
5
|
+
* Consolidated from 17 files to 9 focused modules (Phase 5 cleanup).
|
|
6
|
+
*
|
|
7
|
+
* @module utils
|
|
8
|
+
*/
|
|
9
|
+
export { KnowledgeGraphError, EntityNotFoundError, RelationNotFoundError, DuplicateEntityError, ValidationError, CycleDetectedError, InvalidImportanceError, FileOperationError, ImportError, ExportError, InsufficientEntitiesError, OperationCancelledError, } from './errors.js';
|
|
10
|
+
export { FILE_EXTENSIONS, FILE_SUFFIXES, DEFAULT_FILE_NAMES, ENV_VARS, DEFAULT_BASE_DIR, LOG_PREFIXES, SIMILARITY_WEIGHTS, DEFAULT_DUPLICATE_THRESHOLD, SEARCH_LIMITS, IMPORTANCE_RANGE, GRAPH_LIMITS, QUERY_LIMITS, COMPRESSION_CONFIG, STREAMING_CONFIG, type CompressionQuality, } from './constants.js';
|
|
11
|
+
export { compress, decompress, compressFile, decompressFile, compressToBase64, decompressFromBase64, hasBrotliExtension, getCompressionRatio, createMetadata, createUncompressedMetadata, type CompressionOptions, type CompressionResult, type CompressionMetadata, } from './compressionUtil.js';
|
|
12
|
+
export { CompressedCache, type CompressedCacheOptions, type CompressedCacheStats, } from './compressedCache.js';
|
|
13
|
+
export { logger } from './logger.js';
|
|
14
|
+
export { levenshteinDistance, calculateTF, calculateIDF, calculateIDFFromTokenSets, calculateTFIDF, tokenize, } from './searchAlgorithms.js';
|
|
15
|
+
export { NameIndex, TypeIndex, LowercaseCache, RelationIndex, } from './indexes.js';
|
|
16
|
+
export { SearchCache, searchCaches, clearAllSearchCaches, getAllCacheStats, cleanupAllCaches, type CacheStats, } from './searchCache.js';
|
|
17
|
+
export { EntitySchema, CreateEntitySchema, UpdateEntitySchema, RelationSchema, CreateRelationSchema, SearchQuerySchema, DateRangeSchema, TagAliasSchema, ExportFormatSchema, BatchCreateEntitiesSchema, BatchCreateRelationsSchema, EntityNamesSchema, DeleteRelationsSchema, AddObservationInputSchema, AddObservationsInputSchema, DeleteObservationInputSchema, DeleteObservationsInputSchema, ArchiveCriteriaSchema, SavedSearchInputSchema, SavedSearchUpdateSchema, ImportFormatSchema, ExtendedExportFormatSchema, MergeStrategySchema, ExportFilterSchema, OptionalTagsSchema, OptionalEntityNamesSchema, type EntityInput, type CreateEntityInput, type UpdateEntityInput, type RelationInput, type CreateRelationInput, type SearchQuery, type DateRange, type TagAlias, type ExportFormat, type AddObservationInput, type DeleteObservationInput, type ArchiveCriteriaInput, type SavedSearchInput, type SavedSearchUpdateInput, type ImportFormat, type ExtendedExportFormat, type MergeStrategy, type ExportFilterInput, type ValidationResult, formatZodErrors, validateWithSchema, validateSafe, validateArrayWithSchema, validateEntity, validateRelation, validateImportance, validateTags, } from './schemas.js';
|
|
18
|
+
export { formatToolResponse, formatTextResponse, formatRawResponse, formatErrorResponse, type ToolResponse, validatePagination, applyPagination, paginateArray, getPaginationMeta, type ValidatedPagination, } from './formatters.js';
|
|
19
|
+
export { findEntityByName, findEntitiesByNames, entityExists, getEntityIndex, removeEntityByName, getEntityNameSet, groupEntitiesByType, touchEntity, normalizeTag, normalizeTags, hasMatchingTag, hasAllTags, filterByTags, addUniqueTags, removeTags, isWithinDateRange, parseDateRange, isValidISODate, getCurrentTimestamp, isWithinImportanceRange, filterByImportance, filterByCreatedDate, filterByModifiedDate, filterByEntityType, entityPassesFilters, type CommonSearchFilters, validateFilePath, defaultMemoryPath, ensureMemoryFilePath, } from './entityUtils.js';
|
|
20
|
+
export { parallelMap, parallelFilter, getPoolStats, shutdownParallelUtils, } from './parallelUtils.js';
|
|
21
|
+
export { TaskPriority, TaskStatus, type Task, type TaskResult, type ProgressCallback, type BatchOptions, type QueueStats, TaskQueue, batchProcess, rateLimitedProcess, withRetry, debounce, throttle, } from './taskScheduler.js';
|
|
22
|
+
export { checkCancellation, createProgressReporter, createProgress, executeWithPhases, processBatchesWithProgress, type PhaseDefinition, } from './operationUtils.js';
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB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T,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,UAAU,EAEf,SAAS,EAET,YAAY,EACZ,kBAAkB,EAClB,SAAS,EAET,QAAQ,EACR,QAAQ,GACT,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,0BAA0B,EAC1B,KAAK,eAAe,GACrB,MAAM,qBAAqB,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -2,38 +2,76 @@
|
|
|
2
2
|
* Utilities Module Barrel Export
|
|
3
3
|
*
|
|
4
4
|
* Centralizes all utility exports for convenient importing.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Consolidated from 17 files to 9 focused modules (Phase 5 cleanup).
|
|
6
|
+
*
|
|
7
|
+
* @module utils
|
|
7
8
|
*/
|
|
8
|
-
// Error
|
|
9
|
-
export { KnowledgeGraphError, EntityNotFoundError, RelationNotFoundError, DuplicateEntityError, ValidationError, CycleDetectedError, InvalidImportanceError, FileOperationError, ImportError, ExportError, InsufficientEntitiesError, } from './errors.js';
|
|
10
|
-
//
|
|
11
|
-
export {
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
// ==================== Error Types ====================
|
|
10
|
+
export { KnowledgeGraphError, EntityNotFoundError, RelationNotFoundError, DuplicateEntityError, ValidationError, CycleDetectedError, InvalidImportanceError, FileOperationError, ImportError, ExportError, InsufficientEntitiesError, OperationCancelledError, } from './errors.js';
|
|
11
|
+
// ==================== Constants ====================
|
|
12
|
+
export { FILE_EXTENSIONS, FILE_SUFFIXES, DEFAULT_FILE_NAMES, ENV_VARS, DEFAULT_BASE_DIR, LOG_PREFIXES, SIMILARITY_WEIGHTS, DEFAULT_DUPLICATE_THRESHOLD, SEARCH_LIMITS, IMPORTANCE_RANGE, GRAPH_LIMITS, QUERY_LIMITS, COMPRESSION_CONFIG, STREAMING_CONFIG, } from './constants.js';
|
|
13
|
+
// ==================== Compression Utilities ====================
|
|
14
|
+
export { compress, decompress, compressFile, decompressFile, compressToBase64, decompressFromBase64, hasBrotliExtension, getCompressionRatio, createMetadata, createUncompressedMetadata, } from './compressionUtil.js';
|
|
15
|
+
// ==================== Compressed Cache ====================
|
|
16
|
+
export { CompressedCache, } from './compressedCache.js';
|
|
17
|
+
// ==================== Logger ====================
|
|
14
18
|
export { logger } from './logger.js';
|
|
19
|
+
// ==================== Search Algorithms ====================
|
|
20
|
+
export { levenshteinDistance, calculateTF, calculateIDF, calculateIDFFromTokenSets, calculateTFIDF, tokenize, } from './searchAlgorithms.js';
|
|
21
|
+
// ==================== Indexes ====================
|
|
22
|
+
export { NameIndex, TypeIndex, LowercaseCache, RelationIndex, } from './indexes.js';
|
|
23
|
+
// ==================== Search Cache ====================
|
|
24
|
+
export { SearchCache, searchCaches, clearAllSearchCaches, getAllCacheStats, cleanupAllCaches, } from './searchCache.js';
|
|
25
|
+
// ==================== Schemas and Validation ====================
|
|
26
|
+
// Consolidated from: schemas.ts, validationHelper.ts, validationUtils.ts
|
|
27
|
+
export {
|
|
28
|
+
// Zod schemas - Entity/Relation
|
|
29
|
+
EntitySchema, CreateEntitySchema, UpdateEntitySchema, RelationSchema, CreateRelationSchema, SearchQuerySchema, DateRangeSchema, TagAliasSchema, ExportFormatSchema, BatchCreateEntitiesSchema, BatchCreateRelationsSchema, EntityNamesSchema, DeleteRelationsSchema,
|
|
30
|
+
// Zod schemas - Observations
|
|
31
|
+
AddObservationInputSchema, AddObservationsInputSchema, DeleteObservationInputSchema, DeleteObservationsInputSchema,
|
|
32
|
+
// Zod schemas - Archive
|
|
33
|
+
ArchiveCriteriaSchema,
|
|
34
|
+
// Zod schemas - Saved Search
|
|
35
|
+
SavedSearchInputSchema, SavedSearchUpdateSchema,
|
|
36
|
+
// Zod schemas - Import/Export
|
|
37
|
+
ImportFormatSchema, ExtendedExportFormatSchema, MergeStrategySchema, ExportFilterSchema,
|
|
38
|
+
// Zod schemas - Search
|
|
39
|
+
OptionalTagsSchema, OptionalEntityNamesSchema,
|
|
40
|
+
// Zod helpers
|
|
41
|
+
formatZodErrors, validateWithSchema, validateSafe, validateArrayWithSchema,
|
|
42
|
+
// Manual validation functions
|
|
43
|
+
validateEntity, validateRelation, validateImportance, validateTags, } from './schemas.js';
|
|
44
|
+
// ==================== Formatters ====================
|
|
45
|
+
// Consolidated from: responseFormatter.ts, paginationUtils.ts
|
|
46
|
+
export {
|
|
47
|
+
// Response formatting
|
|
48
|
+
formatToolResponse, formatTextResponse, formatRawResponse, formatErrorResponse,
|
|
49
|
+
// Pagination utilities
|
|
50
|
+
validatePagination, applyPagination, paginateArray, getPaginationMeta, } from './formatters.js';
|
|
51
|
+
// ==================== Entity Utilities ====================
|
|
52
|
+
// Consolidated from: entityUtils.ts, tagUtils.ts, dateUtils.ts, filterUtils.ts, pathUtils.ts
|
|
53
|
+
export {
|
|
54
|
+
// Entity lookup
|
|
55
|
+
findEntityByName, findEntitiesByNames, entityExists, getEntityIndex, removeEntityByName, getEntityNameSet, groupEntitiesByType, touchEntity,
|
|
56
|
+
// Tag utilities
|
|
57
|
+
normalizeTag, normalizeTags, hasMatchingTag, hasAllTags, filterByTags, addUniqueTags, removeTags,
|
|
15
58
|
// Date utilities
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
|
|
59
|
+
isWithinDateRange, parseDateRange, isValidISODate, getCurrentTimestamp,
|
|
60
|
+
// Filter utilities
|
|
61
|
+
isWithinImportanceRange, filterByImportance, filterByCreatedDate, filterByModifiedDate, filterByEntityType, entityPassesFilters,
|
|
19
62
|
// Path utilities
|
|
20
|
-
|
|
21
|
-
//
|
|
22
|
-
export {
|
|
23
|
-
//
|
|
24
|
-
export {
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export { formatZodErrors, validateWithSchema, validateSafe, validateArrayWithSchema, } from './validationHelper.js';
|
|
36
|
-
// Pagination utilities (Task 1.5)
|
|
37
|
-
export { validatePagination, applyPagination, paginateArray, getPaginationMeta, } from './paginationUtils.js';
|
|
38
|
-
// Filter utilities (Task 1.6)
|
|
39
|
-
export { isWithinImportanceRange, filterByImportance, filterByCreatedDate, filterByModifiedDate, filterByEntityType, entityPassesFilters, } from './filterUtils.js';
|
|
63
|
+
validateFilePath, defaultMemoryPath, ensureMemoryFilePath, } from './entityUtils.js';
|
|
64
|
+
// ==================== Parallel Utilities ====================
|
|
65
|
+
export { parallelMap, parallelFilter, getPoolStats, shutdownParallelUtils, } from './parallelUtils.js';
|
|
66
|
+
// ==================== Task Scheduler ====================
|
|
67
|
+
export {
|
|
68
|
+
// Types and Enums
|
|
69
|
+
TaskPriority, TaskStatus,
|
|
70
|
+
// Task Queue
|
|
71
|
+
TaskQueue,
|
|
72
|
+
// Batch Processing
|
|
73
|
+
batchProcess, rateLimitedProcess, withRetry,
|
|
74
|
+
// Rate Limiting
|
|
75
|
+
debounce, throttle, } from './taskScheduler.js';
|
|
76
|
+
// ==================== Operation Utilities (Phase 9B) ====================
|
|
77
|
+
export { checkCancellation, createProgressReporter, createProgress, executeWithPhases, processBatchesWithProgress, } from './operationUtils.js';
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search Indexes
|
|
3
|
+
*
|
|
4
|
+
* Provides O(1) lookup structures to avoid repeated linear scans.
|
|
5
|
+
* - NameIndex: O(1) entity lookup by name
|
|
6
|
+
* - TypeIndex: O(1) entities by type
|
|
7
|
+
* - LowercaseCache: Pre-computed lowercase strings to avoid repeated toLowerCase()
|
|
8
|
+
* - RelationIndex: O(1) relation lookup by entity name (from/to)
|
|
9
|
+
* - ObservationIndex: O(1) observation word lookup by entity
|
|
10
|
+
*
|
|
11
|
+
* @module utils/indexes
|
|
12
|
+
*/
|
|
13
|
+
import type { Entity, LowercaseData, Relation } from '../types/index.js';
|
|
14
|
+
/**
|
|
15
|
+
* NameIndex provides O(1) entity lookup by name.
|
|
16
|
+
*
|
|
17
|
+
* Uses a Map internally for constant-time access.
|
|
18
|
+
*/
|
|
19
|
+
export declare class NameIndex {
|
|
20
|
+
private index;
|
|
21
|
+
/**
|
|
22
|
+
* Build the index from an array of entities.
|
|
23
|
+
* Clears any existing index data first.
|
|
24
|
+
*/
|
|
25
|
+
build(entities: Entity[]): void;
|
|
26
|
+
/**
|
|
27
|
+
* Get an entity by name in O(1) time.
|
|
28
|
+
*/
|
|
29
|
+
get(name: string): Entity | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Add a single entity to the index.
|
|
32
|
+
*/
|
|
33
|
+
add(entity: Entity): void;
|
|
34
|
+
/**
|
|
35
|
+
* Remove an entity from the index by name.
|
|
36
|
+
*/
|
|
37
|
+
remove(name: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Check if an entity exists in the index.
|
|
40
|
+
*/
|
|
41
|
+
has(name: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Get the number of entities in the index.
|
|
44
|
+
*/
|
|
45
|
+
get size(): number;
|
|
46
|
+
/**
|
|
47
|
+
* Clear all entries from the index.
|
|
48
|
+
*/
|
|
49
|
+
clear(): void;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* TypeIndex provides O(1) lookup of entities by type.
|
|
53
|
+
*
|
|
54
|
+
* Uses a Map<type, Set<entityName>> structure for efficient type queries.
|
|
55
|
+
* Type comparisons are case-insensitive.
|
|
56
|
+
*/
|
|
57
|
+
export declare class TypeIndex {
|
|
58
|
+
private index;
|
|
59
|
+
/**
|
|
60
|
+
* Build the index from an array of entities.
|
|
61
|
+
* Clears any existing index data first.
|
|
62
|
+
*/
|
|
63
|
+
build(entities: Entity[]): void;
|
|
64
|
+
/**
|
|
65
|
+
* Get all entity names of a given type in O(1) time.
|
|
66
|
+
* Type comparison is case-insensitive.
|
|
67
|
+
*/
|
|
68
|
+
getNames(entityType: string): Set<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Add an entity to the type index.
|
|
71
|
+
*/
|
|
72
|
+
add(entity: Entity): void;
|
|
73
|
+
/**
|
|
74
|
+
* Remove an entity from the type index.
|
|
75
|
+
* Requires the entity type to know which bucket to remove from.
|
|
76
|
+
*/
|
|
77
|
+
remove(entityName: string, entityType: string): void;
|
|
78
|
+
/**
|
|
79
|
+
* Update an entity's type in the index.
|
|
80
|
+
* Removes from old type and adds to new type.
|
|
81
|
+
*/
|
|
82
|
+
updateType(entityName: string, oldType: string, newType: string): void;
|
|
83
|
+
/**
|
|
84
|
+
* Get all unique types in the index.
|
|
85
|
+
*/
|
|
86
|
+
getTypes(): string[];
|
|
87
|
+
/**
|
|
88
|
+
* Clear all entries from the index.
|
|
89
|
+
*/
|
|
90
|
+
clear(): void;
|
|
91
|
+
private addToIndex;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* LowercaseCache pre-computes lowercase versions of all searchable fields.
|
|
95
|
+
*
|
|
96
|
+
* Eliminates the need for repeated toLowerCase() calls during search,
|
|
97
|
+
* which is expensive with many entities and observations.
|
|
98
|
+
*/
|
|
99
|
+
export declare class LowercaseCache {
|
|
100
|
+
private cache;
|
|
101
|
+
/**
|
|
102
|
+
* Build the cache from an array of entities.
|
|
103
|
+
* Clears any existing cache data first.
|
|
104
|
+
*/
|
|
105
|
+
build(entities: Entity[]): void;
|
|
106
|
+
/**
|
|
107
|
+
* Get pre-computed lowercase data for an entity.
|
|
108
|
+
*/
|
|
109
|
+
get(entityName: string): LowercaseData | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Add or update an entity in the cache.
|
|
112
|
+
*/
|
|
113
|
+
set(entity: Entity): void;
|
|
114
|
+
/**
|
|
115
|
+
* Remove an entity from the cache.
|
|
116
|
+
*/
|
|
117
|
+
remove(entityName: string): void;
|
|
118
|
+
/**
|
|
119
|
+
* Check if an entity exists in the cache.
|
|
120
|
+
*/
|
|
121
|
+
has(entityName: string): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Clear all entries from the cache.
|
|
124
|
+
*/
|
|
125
|
+
clear(): void;
|
|
126
|
+
/**
|
|
127
|
+
* Get the number of entries in the cache.
|
|
128
|
+
*/
|
|
129
|
+
get size(): number;
|
|
130
|
+
private computeLowercase;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* RelationIndex provides O(1) lookup of relations by entity name.
|
|
134
|
+
*
|
|
135
|
+
* Maintains two separate indexes for efficient directional queries:
|
|
136
|
+
* - fromIndex: Map from source entity name to its outgoing relations
|
|
137
|
+
* - toIndex: Map from target entity name to its incoming relations
|
|
138
|
+
*
|
|
139
|
+
* This eliminates O(n) array scans when looking up relations for an entity.
|
|
140
|
+
*/
|
|
141
|
+
export declare class RelationIndex {
|
|
142
|
+
/** Index of relations by source (from) entity */
|
|
143
|
+
private fromIndex;
|
|
144
|
+
/** Index of relations by target (to) entity */
|
|
145
|
+
private toIndex;
|
|
146
|
+
/**
|
|
147
|
+
* Build the index from an array of relations.
|
|
148
|
+
* Clears any existing index data first.
|
|
149
|
+
*/
|
|
150
|
+
build(relations: Relation[]): void;
|
|
151
|
+
/**
|
|
152
|
+
* Get all relations where the entity is the source (outgoing relations).
|
|
153
|
+
* Returns empty array if no relations found.
|
|
154
|
+
*/
|
|
155
|
+
getRelationsFrom(entityName: string): Relation[];
|
|
156
|
+
/**
|
|
157
|
+
* Get all relations where the entity is the target (incoming relations).
|
|
158
|
+
* Returns empty array if no relations found.
|
|
159
|
+
*/
|
|
160
|
+
getRelationsTo(entityName: string): Relation[];
|
|
161
|
+
/**
|
|
162
|
+
* Get all relations involving the entity (both incoming and outgoing).
|
|
163
|
+
* Returns empty array if no relations found.
|
|
164
|
+
*/
|
|
165
|
+
getRelationsFor(entityName: string): Relation[];
|
|
166
|
+
/**
|
|
167
|
+
* Add a single relation to the index.
|
|
168
|
+
*/
|
|
169
|
+
add(relation: Relation): void;
|
|
170
|
+
/**
|
|
171
|
+
* Remove a relation from the index.
|
|
172
|
+
* Matches by from, to, and relationType.
|
|
173
|
+
*/
|
|
174
|
+
remove(relation: Relation): void;
|
|
175
|
+
/**
|
|
176
|
+
* Remove all relations involving a specific entity.
|
|
177
|
+
* Returns the relations that were removed.
|
|
178
|
+
*/
|
|
179
|
+
removeAllForEntity(entityName: string): Relation[];
|
|
180
|
+
/**
|
|
181
|
+
* Check if any relations exist for an entity.
|
|
182
|
+
*/
|
|
183
|
+
hasRelations(entityName: string): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Get count of outgoing relations for an entity.
|
|
186
|
+
*/
|
|
187
|
+
getOutgoingCount(entityName: string): number;
|
|
188
|
+
/**
|
|
189
|
+
* Get count of incoming relations for an entity.
|
|
190
|
+
*/
|
|
191
|
+
getIncomingCount(entityName: string): number;
|
|
192
|
+
/**
|
|
193
|
+
* Get total count of unique relations in the index.
|
|
194
|
+
*/
|
|
195
|
+
get size(): number;
|
|
196
|
+
/**
|
|
197
|
+
* Clear all entries from the index.
|
|
198
|
+
*/
|
|
199
|
+
clear(): void;
|
|
200
|
+
private addToIndexes;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Inverted index mapping observation keywords to entity names.
|
|
204
|
+
* Enables O(1) lookup for 'which entities mention word X?' queries.
|
|
205
|
+
* Words are normalized to lowercase and split on whitespace/punctuation.
|
|
206
|
+
*/
|
|
207
|
+
export declare class ObservationIndex {
|
|
208
|
+
private index;
|
|
209
|
+
private entityObservations;
|
|
210
|
+
/**
|
|
211
|
+
* Add an entity's observations to the index.
|
|
212
|
+
* Tokenizes observations into words and creates reverse mapping.
|
|
213
|
+
*
|
|
214
|
+
* @param entityName - Name of the entity
|
|
215
|
+
* @param observations - Array of observation strings
|
|
216
|
+
*/
|
|
217
|
+
add(entityName: string, observations: string[]): void;
|
|
218
|
+
/**
|
|
219
|
+
* Remove an entity from the index.
|
|
220
|
+
* Cleans up all word mappings for this entity.
|
|
221
|
+
*
|
|
222
|
+
* @param entityName - Name of the entity to remove
|
|
223
|
+
*/
|
|
224
|
+
remove(entityName: string): void;
|
|
225
|
+
/**
|
|
226
|
+
* Get all entities that have observations containing the given word.
|
|
227
|
+
* Word matching is case-insensitive.
|
|
228
|
+
*
|
|
229
|
+
* @param word - Word to search for
|
|
230
|
+
* @returns Set of entity names containing this word
|
|
231
|
+
*/
|
|
232
|
+
getEntitiesWithWord(word: string): Set<string>;
|
|
233
|
+
/**
|
|
234
|
+
* Get all entities that have observations containing ANY of the given words (union).
|
|
235
|
+
*
|
|
236
|
+
* @param words - Array of words to search for
|
|
237
|
+
* @returns Set of entity names containing any of the words
|
|
238
|
+
*/
|
|
239
|
+
getEntitiesWithAnyWord(words: string[]): Set<string>;
|
|
240
|
+
/**
|
|
241
|
+
* Get all entities that have observations containing ALL of the given words (intersection).
|
|
242
|
+
*
|
|
243
|
+
* @param words - Array of words that must all be present
|
|
244
|
+
* @returns Set of entity names containing all of the words
|
|
245
|
+
*/
|
|
246
|
+
getEntitiesWithAllWords(words: string[]): Set<string>;
|
|
247
|
+
/**
|
|
248
|
+
* Clear all entries from the index.
|
|
249
|
+
*/
|
|
250
|
+
clear(): void;
|
|
251
|
+
/**
|
|
252
|
+
* Get statistics about the index.
|
|
253
|
+
*
|
|
254
|
+
* @returns Object with wordCount and entityCount
|
|
255
|
+
*/
|
|
256
|
+
getStats(): {
|
|
257
|
+
wordCount: number;
|
|
258
|
+
entityCount: number;
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Tokenize text into searchable words.
|
|
262
|
+
* Normalizes to lowercase, splits on non-alphanumeric characters,
|
|
263
|
+
* and filters out words less than 2 characters.
|
|
264
|
+
*
|
|
265
|
+
* @param text - Text to tokenize
|
|
266
|
+
* @returns Array of normalized words
|
|
267
|
+
*/
|
|
268
|
+
private tokenize;
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=indexes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexes.d.ts","sourceRoot":"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