@danielsimonjr/memoryjs 1.0.0 → 1.1.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.
Files changed (300) hide show
  1. package/README.md +385 -113
  2. package/README.md.backup-1768084780988 +266 -0
  3. package/dist/index.cjs +17364 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +12371 -0
  6. package/dist/index.d.ts +12367 -11
  7. package/dist/index.js +17102 -19
  8. package/dist/index.js.map +1 -1
  9. package/dist/workers/levenshteinWorker.cjs +102 -0
  10. package/dist/workers/levenshteinWorker.cjs.map +1 -0
  11. package/dist/workers/levenshteinWorker.js +57 -91
  12. package/dist/workers/levenshteinWorker.js.map +1 -1
  13. package/package.json +12 -6
  14. package/dist/core/EntityManager.d.ts +0 -268
  15. package/dist/core/EntityManager.d.ts.map +0 -1
  16. package/dist/core/EntityManager.js +0 -512
  17. package/dist/core/EntityManager.js.map +0 -1
  18. package/dist/core/GraphEventEmitter.d.ts +0 -202
  19. package/dist/core/GraphEventEmitter.d.ts.map +0 -1
  20. package/dist/core/GraphEventEmitter.js +0 -347
  21. package/dist/core/GraphEventEmitter.js.map +0 -1
  22. package/dist/core/GraphStorage.d.ts +0 -395
  23. package/dist/core/GraphStorage.d.ts.map +0 -1
  24. package/dist/core/GraphStorage.js +0 -786
  25. package/dist/core/GraphStorage.js.map +0 -1
  26. package/dist/core/GraphTraversal.d.ts +0 -141
  27. package/dist/core/GraphTraversal.d.ts.map +0 -1
  28. package/dist/core/GraphTraversal.js +0 -574
  29. package/dist/core/GraphTraversal.js.map +0 -1
  30. package/dist/core/HierarchyManager.d.ts +0 -111
  31. package/dist/core/HierarchyManager.d.ts.map +0 -1
  32. package/dist/core/HierarchyManager.js +0 -225
  33. package/dist/core/HierarchyManager.js.map +0 -1
  34. package/dist/core/ManagerContext.d.ts +0 -76
  35. package/dist/core/ManagerContext.d.ts.map +0 -1
  36. package/dist/core/ManagerContext.js +0 -129
  37. package/dist/core/ManagerContext.js.map +0 -1
  38. package/dist/core/ObservationManager.d.ts +0 -85
  39. package/dist/core/ObservationManager.d.ts.map +0 -1
  40. package/dist/core/ObservationManager.js +0 -124
  41. package/dist/core/ObservationManager.js.map +0 -1
  42. package/dist/core/RelationManager.d.ts +0 -131
  43. package/dist/core/RelationManager.d.ts.map +0 -1
  44. package/dist/core/RelationManager.js +0 -212
  45. package/dist/core/RelationManager.js.map +0 -1
  46. package/dist/core/SQLiteStorage.d.ts +0 -354
  47. package/dist/core/SQLiteStorage.d.ts.map +0 -1
  48. package/dist/core/SQLiteStorage.js +0 -919
  49. package/dist/core/SQLiteStorage.js.map +0 -1
  50. package/dist/core/StorageFactory.d.ts +0 -45
  51. package/dist/core/StorageFactory.d.ts.map +0 -1
  52. package/dist/core/StorageFactory.js +0 -65
  53. package/dist/core/StorageFactory.js.map +0 -1
  54. package/dist/core/TransactionManager.d.ts +0 -464
  55. package/dist/core/TransactionManager.d.ts.map +0 -1
  56. package/dist/core/TransactionManager.js +0 -869
  57. package/dist/core/TransactionManager.js.map +0 -1
  58. package/dist/core/index.d.ts +0 -17
  59. package/dist/core/index.d.ts.map +0 -1
  60. package/dist/core/index.js +0 -20
  61. package/dist/core/index.js.map +0 -1
  62. package/dist/features/AnalyticsManager.d.ts +0 -44
  63. package/dist/features/AnalyticsManager.d.ts.map +0 -1
  64. package/dist/features/AnalyticsManager.js +0 -224
  65. package/dist/features/AnalyticsManager.js.map +0 -1
  66. package/dist/features/ArchiveManager.d.ts +0 -133
  67. package/dist/features/ArchiveManager.d.ts.map +0 -1
  68. package/dist/features/ArchiveManager.js +0 -282
  69. package/dist/features/ArchiveManager.js.map +0 -1
  70. package/dist/features/CompressionManager.d.ts +0 -119
  71. package/dist/features/CompressionManager.d.ts.map +0 -1
  72. package/dist/features/CompressionManager.js +0 -470
  73. package/dist/features/CompressionManager.js.map +0 -1
  74. package/dist/features/IOManager.d.ts +0 -225
  75. package/dist/features/IOManager.d.ts.map +0 -1
  76. package/dist/features/IOManager.js +0 -1093
  77. package/dist/features/IOManager.js.map +0 -1
  78. package/dist/features/KeywordExtractor.d.ts +0 -61
  79. package/dist/features/KeywordExtractor.d.ts.map +0 -1
  80. package/dist/features/KeywordExtractor.js +0 -127
  81. package/dist/features/KeywordExtractor.js.map +0 -1
  82. package/dist/features/ObservationNormalizer.d.ts +0 -90
  83. package/dist/features/ObservationNormalizer.d.ts.map +0 -1
  84. package/dist/features/ObservationNormalizer.js +0 -194
  85. package/dist/features/ObservationNormalizer.js.map +0 -1
  86. package/dist/features/StreamingExporter.d.ts +0 -128
  87. package/dist/features/StreamingExporter.d.ts.map +0 -1
  88. package/dist/features/StreamingExporter.js +0 -212
  89. package/dist/features/StreamingExporter.js.map +0 -1
  90. package/dist/features/TagManager.d.ts +0 -147
  91. package/dist/features/TagManager.d.ts.map +0 -1
  92. package/dist/features/TagManager.js +0 -211
  93. package/dist/features/TagManager.js.map +0 -1
  94. package/dist/features/index.d.ts +0 -14
  95. package/dist/features/index.d.ts.map +0 -1
  96. package/dist/features/index.js +0 -15
  97. package/dist/features/index.js.map +0 -1
  98. package/dist/index.d.ts.map +0 -1
  99. package/dist/search/BM25Search.d.ts +0 -148
  100. package/dist/search/BM25Search.d.ts.map +0 -1
  101. package/dist/search/BM25Search.js +0 -340
  102. package/dist/search/BM25Search.js.map +0 -1
  103. package/dist/search/BasicSearch.d.ts +0 -51
  104. package/dist/search/BasicSearch.d.ts.map +0 -1
  105. package/dist/search/BasicSearch.js +0 -138
  106. package/dist/search/BasicSearch.js.map +0 -1
  107. package/dist/search/BooleanSearch.d.ts +0 -98
  108. package/dist/search/BooleanSearch.d.ts.map +0 -1
  109. package/dist/search/BooleanSearch.js +0 -431
  110. package/dist/search/BooleanSearch.js.map +0 -1
  111. package/dist/search/EarlyTerminationManager.d.ts +0 -140
  112. package/dist/search/EarlyTerminationManager.d.ts.map +0 -1
  113. package/dist/search/EarlyTerminationManager.js +0 -280
  114. package/dist/search/EarlyTerminationManager.js.map +0 -1
  115. package/dist/search/EmbeddingCache.d.ts +0 -175
  116. package/dist/search/EmbeddingCache.d.ts.map +0 -1
  117. package/dist/search/EmbeddingCache.js +0 -247
  118. package/dist/search/EmbeddingCache.js.map +0 -1
  119. package/dist/search/EmbeddingService.d.ts +0 -277
  120. package/dist/search/EmbeddingService.d.ts.map +0 -1
  121. package/dist/search/EmbeddingService.js +0 -531
  122. package/dist/search/EmbeddingService.js.map +0 -1
  123. package/dist/search/FuzzySearch.d.ts +0 -118
  124. package/dist/search/FuzzySearch.d.ts.map +0 -1
  125. package/dist/search/FuzzySearch.js +0 -313
  126. package/dist/search/FuzzySearch.js.map +0 -1
  127. package/dist/search/HybridScorer.d.ts +0 -181
  128. package/dist/search/HybridScorer.d.ts.map +0 -1
  129. package/dist/search/HybridScorer.js +0 -258
  130. package/dist/search/HybridScorer.js.map +0 -1
  131. package/dist/search/HybridSearchManager.d.ts +0 -80
  132. package/dist/search/HybridSearchManager.d.ts.map +0 -1
  133. package/dist/search/HybridSearchManager.js +0 -188
  134. package/dist/search/HybridSearchManager.js.map +0 -1
  135. package/dist/search/IncrementalIndexer.d.ts +0 -201
  136. package/dist/search/IncrementalIndexer.d.ts.map +0 -1
  137. package/dist/search/IncrementalIndexer.js +0 -343
  138. package/dist/search/IncrementalIndexer.js.map +0 -1
  139. package/dist/search/OptimizedInvertedIndex.d.ts +0 -163
  140. package/dist/search/OptimizedInvertedIndex.d.ts.map +0 -1
  141. package/dist/search/OptimizedInvertedIndex.js +0 -359
  142. package/dist/search/OptimizedInvertedIndex.js.map +0 -1
  143. package/dist/search/ParallelSearchExecutor.d.ts +0 -172
  144. package/dist/search/ParallelSearchExecutor.d.ts.map +0 -1
  145. package/dist/search/ParallelSearchExecutor.js +0 -310
  146. package/dist/search/ParallelSearchExecutor.js.map +0 -1
  147. package/dist/search/QuantizedVectorStore.d.ts +0 -171
  148. package/dist/search/QuantizedVectorStore.d.ts.map +0 -1
  149. package/dist/search/QuantizedVectorStore.js +0 -308
  150. package/dist/search/QuantizedVectorStore.js.map +0 -1
  151. package/dist/search/QueryAnalyzer.d.ts +0 -76
  152. package/dist/search/QueryAnalyzer.d.ts.map +0 -1
  153. package/dist/search/QueryAnalyzer.js +0 -228
  154. package/dist/search/QueryAnalyzer.js.map +0 -1
  155. package/dist/search/QueryCostEstimator.d.ts +0 -244
  156. package/dist/search/QueryCostEstimator.d.ts.map +0 -1
  157. package/dist/search/QueryCostEstimator.js +0 -653
  158. package/dist/search/QueryCostEstimator.js.map +0 -1
  159. package/dist/search/QueryPlanCache.d.ts +0 -220
  160. package/dist/search/QueryPlanCache.d.ts.map +0 -1
  161. package/dist/search/QueryPlanCache.js +0 -380
  162. package/dist/search/QueryPlanCache.js.map +0 -1
  163. package/dist/search/QueryPlanner.d.ts +0 -58
  164. package/dist/search/QueryPlanner.d.ts.map +0 -1
  165. package/dist/search/QueryPlanner.js +0 -138
  166. package/dist/search/QueryPlanner.js.map +0 -1
  167. package/dist/search/RankedSearch.d.ts +0 -71
  168. package/dist/search/RankedSearch.d.ts.map +0 -1
  169. package/dist/search/RankedSearch.js +0 -239
  170. package/dist/search/RankedSearch.js.map +0 -1
  171. package/dist/search/ReflectionManager.d.ts +0 -120
  172. package/dist/search/ReflectionManager.d.ts.map +0 -1
  173. package/dist/search/ReflectionManager.js +0 -232
  174. package/dist/search/ReflectionManager.js.map +0 -1
  175. package/dist/search/SavedSearchManager.d.ts +0 -79
  176. package/dist/search/SavedSearchManager.d.ts.map +0 -1
  177. package/dist/search/SavedSearchManager.js +0 -147
  178. package/dist/search/SavedSearchManager.js.map +0 -1
  179. package/dist/search/SearchFilterChain.d.ts +0 -120
  180. package/dist/search/SearchFilterChain.d.ts.map +0 -1
  181. package/dist/search/SearchFilterChain.js +0 -186
  182. package/dist/search/SearchFilterChain.js.map +0 -1
  183. package/dist/search/SearchManager.d.ts +0 -326
  184. package/dist/search/SearchManager.d.ts.map +0 -1
  185. package/dist/search/SearchManager.js +0 -454
  186. package/dist/search/SearchManager.js.map +0 -1
  187. package/dist/search/SearchSuggestions.d.ts +0 -27
  188. package/dist/search/SearchSuggestions.d.ts.map +0 -1
  189. package/dist/search/SearchSuggestions.js +0 -58
  190. package/dist/search/SearchSuggestions.js.map +0 -1
  191. package/dist/search/SemanticSearch.d.ts +0 -149
  192. package/dist/search/SemanticSearch.d.ts.map +0 -1
  193. package/dist/search/SemanticSearch.js +0 -324
  194. package/dist/search/SemanticSearch.js.map +0 -1
  195. package/dist/search/SymbolicSearch.d.ts +0 -61
  196. package/dist/search/SymbolicSearch.d.ts.map +0 -1
  197. package/dist/search/SymbolicSearch.js +0 -164
  198. package/dist/search/SymbolicSearch.js.map +0 -1
  199. package/dist/search/TFIDFEventSync.d.ts +0 -85
  200. package/dist/search/TFIDFEventSync.d.ts.map +0 -1
  201. package/dist/search/TFIDFEventSync.js +0 -134
  202. package/dist/search/TFIDFEventSync.js.map +0 -1
  203. package/dist/search/TFIDFIndexManager.d.ts +0 -151
  204. package/dist/search/TFIDFIndexManager.d.ts.map +0 -1
  205. package/dist/search/TFIDFIndexManager.js +0 -433
  206. package/dist/search/TFIDFIndexManager.js.map +0 -1
  207. package/dist/search/VectorStore.d.ts +0 -235
  208. package/dist/search/VectorStore.d.ts.map +0 -1
  209. package/dist/search/VectorStore.js +0 -312
  210. package/dist/search/VectorStore.js.map +0 -1
  211. package/dist/search/index.d.ts +0 -35
  212. package/dist/search/index.d.ts.map +0 -1
  213. package/dist/search/index.js +0 -53
  214. package/dist/search/index.js.map +0 -1
  215. package/dist/types/index.d.ts +0 -13
  216. package/dist/types/index.d.ts.map +0 -1
  217. package/dist/types/index.js +0 -13
  218. package/dist/types/index.js.map +0 -1
  219. package/dist/types/types.d.ts +0 -1811
  220. package/dist/types/types.d.ts.map +0 -1
  221. package/dist/types/types.js +0 -10
  222. package/dist/types/types.js.map +0 -1
  223. package/dist/utils/BatchProcessor.d.ts +0 -271
  224. package/dist/utils/BatchProcessor.d.ts.map +0 -1
  225. package/dist/utils/BatchProcessor.js +0 -377
  226. package/dist/utils/BatchProcessor.js.map +0 -1
  227. package/dist/utils/MemoryMonitor.d.ts +0 -176
  228. package/dist/utils/MemoryMonitor.d.ts.map +0 -1
  229. package/dist/utils/MemoryMonitor.js +0 -306
  230. package/dist/utils/MemoryMonitor.js.map +0 -1
  231. package/dist/utils/WorkerPoolManager.d.ts +0 -233
  232. package/dist/utils/WorkerPoolManager.d.ts.map +0 -1
  233. package/dist/utils/WorkerPoolManager.js +0 -421
  234. package/dist/utils/WorkerPoolManager.js.map +0 -1
  235. package/dist/utils/compressedCache.d.ts +0 -221
  236. package/dist/utils/compressedCache.d.ts.map +0 -1
  237. package/dist/utils/compressedCache.js +0 -349
  238. package/dist/utils/compressedCache.js.map +0 -1
  239. package/dist/utils/compressionUtil.d.ts +0 -214
  240. package/dist/utils/compressionUtil.d.ts.map +0 -1
  241. package/dist/utils/compressionUtil.js +0 -248
  242. package/dist/utils/compressionUtil.js.map +0 -1
  243. package/dist/utils/constants.d.ts +0 -245
  244. package/dist/utils/constants.d.ts.map +0 -1
  245. package/dist/utils/constants.js +0 -253
  246. package/dist/utils/constants.js.map +0 -1
  247. package/dist/utils/entityUtils.d.ts +0 -379
  248. package/dist/utils/entityUtils.d.ts.map +0 -1
  249. package/dist/utils/entityUtils.js +0 -649
  250. package/dist/utils/entityUtils.js.map +0 -1
  251. package/dist/utils/errors.d.ts +0 -95
  252. package/dist/utils/errors.d.ts.map +0 -1
  253. package/dist/utils/errors.js +0 -146
  254. package/dist/utils/errors.js.map +0 -1
  255. package/dist/utils/formatters.d.ts +0 -145
  256. package/dist/utils/formatters.d.ts.map +0 -1
  257. package/dist/utils/formatters.js +0 -133
  258. package/dist/utils/formatters.js.map +0 -1
  259. package/dist/utils/index.d.ts +0 -26
  260. package/dist/utils/index.d.ts.map +0 -1
  261. package/dist/utils/index.js +0 -88
  262. package/dist/utils/index.js.map +0 -1
  263. package/dist/utils/indexes.d.ts +0 -270
  264. package/dist/utils/indexes.d.ts.map +0 -1
  265. package/dist/utils/indexes.js +0 -527
  266. package/dist/utils/indexes.js.map +0 -1
  267. package/dist/utils/logger.d.ts +0 -31
  268. package/dist/utils/logger.d.ts.map +0 -1
  269. package/dist/utils/logger.js +0 -41
  270. package/dist/utils/logger.js.map +0 -1
  271. package/dist/utils/operationUtils.d.ts +0 -124
  272. package/dist/utils/operationUtils.d.ts.map +0 -1
  273. package/dist/utils/operationUtils.js +0 -176
  274. package/dist/utils/operationUtils.js.map +0 -1
  275. package/dist/utils/parallelUtils.d.ts +0 -76
  276. package/dist/utils/parallelUtils.d.ts.map +0 -1
  277. package/dist/utils/parallelUtils.js +0 -192
  278. package/dist/utils/parallelUtils.js.map +0 -1
  279. package/dist/utils/schemas.d.ts +0 -556
  280. package/dist/utils/schemas.d.ts.map +0 -1
  281. package/dist/utils/schemas.js +0 -485
  282. package/dist/utils/schemas.js.map +0 -1
  283. package/dist/utils/searchAlgorithms.d.ts +0 -99
  284. package/dist/utils/searchAlgorithms.d.ts.map +0 -1
  285. package/dist/utils/searchAlgorithms.js +0 -168
  286. package/dist/utils/searchAlgorithms.js.map +0 -1
  287. package/dist/utils/searchCache.d.ts +0 -108
  288. package/dist/utils/searchCache.d.ts.map +0 -1
  289. package/dist/utils/searchCache.js +0 -210
  290. package/dist/utils/searchCache.js.map +0 -1
  291. package/dist/utils/taskScheduler.d.ts +0 -294
  292. package/dist/utils/taskScheduler.d.ts.map +0 -1
  293. package/dist/utils/taskScheduler.js +0 -487
  294. package/dist/utils/taskScheduler.js.map +0 -1
  295. package/dist/workers/index.d.ts +0 -12
  296. package/dist/workers/index.d.ts.map +0 -1
  297. package/dist/workers/index.js +0 -10
  298. package/dist/workers/index.js.map +0 -1
  299. package/dist/workers/levenshteinWorker.d.ts +0 -60
  300. package/dist/workers/levenshteinWorker.d.ts.map +0 -1
@@ -1,253 +0,0 @@
1
- /**
2
- * Application Constants
3
- *
4
- * Centralized configuration constants for file paths, extensions, and default values.
5
- *
6
- * @module utils/constants
7
- */
8
- /**
9
- * File extensions used by the memory system.
10
- */
11
- export const FILE_EXTENSIONS = {
12
- /** JSONL format for line-delimited JSON storage */
13
- JSONL: '.jsonl',
14
- /** Legacy JSON format (backward compatibility) */
15
- JSON: '.json',
16
- };
17
- /**
18
- * File name suffixes for auxiliary data files.
19
- * These suffixes are appended to the base memory file name.
20
- */
21
- export const FILE_SUFFIXES = {
22
- /** Suffix for saved searches file */
23
- SAVED_SEARCHES: '-saved-searches',
24
- /** Suffix for tag aliases file */
25
- TAG_ALIASES: '-tag-aliases',
26
- };
27
- /**
28
- * Default file names used by the memory system.
29
- */
30
- export const DEFAULT_FILE_NAMES = {
31
- /** Default memory file name */
32
- MEMORY: 'memory',
33
- /** Legacy memory file name (for backward compatibility) */
34
- MEMORY_LEGACY: 'memory',
35
- };
36
- /**
37
- * Environment variable names used for configuration.
38
- */
39
- export const ENV_VARS = {
40
- /** Environment variable for custom memory file path */
41
- MEMORY_FILE_PATH: 'MEMORY_FILE_PATH',
42
- };
43
- /**
44
- * Default base directory relative to the compiled code.
45
- */
46
- export const DEFAULT_BASE_DIR = '../';
47
- /**
48
- * Log message prefixes for consistent logging.
49
- */
50
- export const LOG_PREFIXES = {
51
- /** Informational message prefix */
52
- INFO: '[INFO]',
53
- /** Error message prefix */
54
- ERROR: '[ERROR]',
55
- /** Warning message prefix */
56
- WARN: '[WARN]',
57
- };
58
- /**
59
- * Similarity scoring weights for duplicate detection.
60
- * These weights determine the relative importance of each factor
61
- * when calculating entity similarity for duplicate detection.
62
- * Total weights must sum to 1.0 (100%).
63
- */
64
- export const SIMILARITY_WEIGHTS = {
65
- /** Name similarity weight (40%) - Uses Levenshtein distance */
66
- NAME: 0.4,
67
- /** Entity type match weight (20%) - Exact match required */
68
- TYPE: 0.2,
69
- /** Observation overlap weight (30%) - Uses Jaccard similarity */
70
- OBSERVATIONS: 0.3,
71
- /** Tag overlap weight (10%) - Uses Jaccard similarity */
72
- TAGS: 0.1,
73
- };
74
- /**
75
- * Default threshold for duplicate detection (80% similarity required).
76
- */
77
- export const DEFAULT_DUPLICATE_THRESHOLD = 0.8;
78
- /**
79
- * Search result limits to prevent resource exhaustion.
80
- */
81
- export const SEARCH_LIMITS = {
82
- /** Default number of results to return */
83
- DEFAULT: 50,
84
- /** Maximum number of results allowed */
85
- MAX: 200,
86
- /** Minimum number of results (must be at least 1) */
87
- MIN: 1,
88
- };
89
- /**
90
- * Entity importance range validation constants.
91
- * Importance is used to prioritize entities (0 = lowest, 10 = highest).
92
- */
93
- export const IMPORTANCE_RANGE = {
94
- /** Minimum importance value */
95
- MIN: 0,
96
- /** Maximum importance value */
97
- MAX: 10,
98
- };
99
- /**
100
- * Graph size limits to prevent resource exhaustion and ensure performance.
101
- * These limits help maintain system stability and responsiveness.
102
- */
103
- export const GRAPH_LIMITS = {
104
- /** Maximum number of entities in the graph */
105
- MAX_ENTITIES: 100000,
106
- /** Maximum number of relations in the graph */
107
- MAX_RELATIONS: 1000000,
108
- /** Maximum graph file size in megabytes */
109
- MAX_FILE_SIZE_MB: 500,
110
- /** Maximum observations per entity */
111
- MAX_OBSERVATIONS_PER_ENTITY: 1000,
112
- /** Maximum tags per entity */
113
- MAX_TAGS_PER_ENTITY: 100,
114
- };
115
- /**
116
- * Query complexity limits to prevent expensive query operations.
117
- * These limits protect against denial-of-service through complex queries.
118
- */
119
- export const QUERY_LIMITS = {
120
- /** Maximum nesting depth for boolean queries */
121
- MAX_DEPTH: 10,
122
- /** Maximum number of terms in a single query */
123
- MAX_TERMS: 50,
124
- /** Maximum number of boolean operators (AND/OR/NOT) */
125
- MAX_OPERATORS: 20,
126
- /** Maximum query string length */
127
- MAX_QUERY_LENGTH: 5000,
128
- };
129
- /**
130
- * Brotli compression configuration constants.
131
- * Brotli is built into Node.js >=11.7.0 via the zlib module.
132
- * No external dependencies required.
133
- *
134
- * Quality levels determine compression ratio vs speed tradeoff:
135
- * - Lower values (0-4): Faster compression, lower ratio
136
- * - Higher values (9-11): Slower compression, higher ratio
137
- */
138
- export const COMPRESSION_CONFIG = {
139
- // Quality levels (0-11)
140
- /** Fast compression for real-time entity writes (quality 4) */
141
- BROTLI_QUALITY_REALTIME: 4,
142
- /** Balanced compression for exports and imports (quality 6) */
143
- BROTLI_QUALITY_BATCH: 6,
144
- /** Maximum compression for backups and archives (quality 11) */
145
- BROTLI_QUALITY_ARCHIVE: 11,
146
- /** Fast decompress for cache compression (quality 5) */
147
- BROTLI_QUALITY_CACHE: 5,
148
- // Auto-compression thresholds (in bytes)
149
- /** Auto-compress exports larger than 100KB */
150
- AUTO_COMPRESS_EXPORT_SIZE: 100 * 1024,
151
- /** Auto-compress MCP responses larger than 256KB */
152
- AUTO_COMPRESS_RESPONSE_SIZE: 256 * 1024,
153
- /** Always compress backups by default */
154
- AUTO_COMPRESS_BACKUP: true,
155
- // File extension for compressed files
156
- /** Brotli compressed file extension */
157
- BROTLI_EXTENSION: '.br',
158
- // Performance tuning
159
- /** Chunk size for streaming compression (64KB) */
160
- COMPRESSION_CHUNK_SIZE: 65536,
161
- /** Default window size for brotli (lgwin parameter) */
162
- COMPRESSION_WINDOW_SIZE: 22,
163
- };
164
- // ==================== Semantic Search Configuration (Phase 4 Sprint 10-12) ====================
165
- /**
166
- * Environment variable names for embedding configuration.
167
- */
168
- export const EMBEDDING_ENV_VARS = {
169
- /** Embedding provider: 'openai', 'local', or 'none' (default: 'none') */
170
- PROVIDER: 'MEMORY_EMBEDDING_PROVIDER',
171
- /** OpenAI API key (required when provider is 'openai') */
172
- OPENAI_API_KEY: 'MEMORY_OPENAI_API_KEY',
173
- /** Optional model override for the embedding service */
174
- MODEL: 'MEMORY_EMBEDDING_MODEL',
175
- /** Auto-index entities on creation: 'true' or 'false' (default: 'false') */
176
- AUTO_INDEX: 'MEMORY_AUTO_INDEX_EMBEDDINGS',
177
- };
178
- /**
179
- * Default embedding configuration values.
180
- */
181
- export const EMBEDDING_DEFAULTS = {
182
- /** Default provider (disabled by default) */
183
- PROVIDER: 'none',
184
- /** Default OpenAI model for embeddings (1536 dimensions) */
185
- OPENAI_MODEL: 'text-embedding-3-small',
186
- /** Default local model for embeddings (384 dimensions) */
187
- LOCAL_MODEL: 'Xenova/all-MiniLM-L6-v2',
188
- /** OpenAI embedding dimensions for text-embedding-3-small */
189
- OPENAI_DIMENSIONS: 1536,
190
- /** Local embedding dimensions for all-MiniLM-L6-v2 */
191
- LOCAL_DIMENSIONS: 384,
192
- /** Maximum texts per batch for OpenAI */
193
- OPENAI_MAX_BATCH_SIZE: 2048,
194
- /** Default batch size for embedding operations */
195
- DEFAULT_BATCH_SIZE: 100,
196
- /** Whether to auto-index entities by default */
197
- AUTO_INDEX: false,
198
- };
199
- /**
200
- * Semantic search configuration limits.
201
- */
202
- export const SEMANTIC_SEARCH_LIMITS = {
203
- /** Default number of results for semantic search */
204
- DEFAULT_LIMIT: 10,
205
- /** Maximum number of results for semantic search */
206
- MAX_LIMIT: 100,
207
- /** Minimum similarity score for results (0.0-1.0) */
208
- MIN_SIMILARITY: 0.0,
209
- };
210
- /**
211
- * OpenAI API configuration.
212
- */
213
- export const OPENAI_API_CONFIG = {
214
- /** Base URL for OpenAI API */
215
- BASE_URL: 'https://api.openai.com/v1',
216
- /** Embeddings endpoint */
217
- EMBEDDINGS_ENDPOINT: '/embeddings',
218
- /** Maximum retries for rate limiting */
219
- MAX_RETRIES: 3,
220
- /** Initial backoff delay in milliseconds */
221
- INITIAL_BACKOFF_MS: 1000,
222
- /** Maximum backoff delay in milliseconds */
223
- MAX_BACKOFF_MS: 10000,
224
- };
225
- /**
226
- * Get embedding configuration from environment variables.
227
- *
228
- * @returns EmbeddingConfig object with values from environment or defaults
229
- */
230
- export function getEmbeddingConfig() {
231
- const provider = (process.env[EMBEDDING_ENV_VARS.PROVIDER] || EMBEDDING_DEFAULTS.PROVIDER);
232
- const apiKey = process.env[EMBEDDING_ENV_VARS.OPENAI_API_KEY];
233
- const model = process.env[EMBEDDING_ENV_VARS.MODEL];
234
- const autoIndex = process.env[EMBEDDING_ENV_VARS.AUTO_INDEX] === 'true';
235
- return { provider, apiKey, model, autoIndex };
236
- }
237
- // ==================== Streaming Export Configuration (Phase 7 Sprint 1) ====================
238
- /**
239
- * Streaming export configuration.
240
- *
241
- * Controls when to use streaming mode and buffer sizes for optimal memory usage.
242
- */
243
- export const STREAMING_CONFIG = {
244
- /** Minimum entity count to trigger streaming mode */
245
- STREAMING_THRESHOLD: 5000,
246
- /** Chunk size for batched streaming operations */
247
- CHUNK_SIZE: 500,
248
- /** High water mark for stream buffers (bytes) */
249
- HIGH_WATER_MARK: 64 * 1024,
250
- /** Flush interval for long-running streams (ms) */
251
- FLUSH_INTERVAL_MS: 100,
252
- };
253
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,mDAAmD;IACnD,KAAK,EAAE,QAAQ;IACf,kDAAkD;IAClD,IAAI,EAAE,OAAO;CACL,CAAC;AAEX;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,qCAAqC;IACrC,cAAc,EAAE,iBAAiB;IACjC,kCAAkC;IAClC,WAAW,EAAE,cAAc;CACnB,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,+BAA+B;IAC/B,MAAM,EAAE,QAAQ;IAChB,2DAA2D;IAC3D,aAAa,EAAE,QAAQ;CACf,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,uDAAuD;IACvD,gBAAgB,EAAE,kBAAkB;CAC5B,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAEtC;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,mCAAmC;IACnC,IAAI,EAA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Aa,EAAE,EAAE;IACjB,oDAAoD;IACpD,SAAS,EAAE,GAAG;IACd,qDAAqD;IACrD,cAAc,EAAE,GAAG;CACX,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAM1B;IACF,8BAA8B;IAC9B,QAAQ,EAAE,2BAA2B;IACrC,0BAA0B;IAC1B,mBAAmB,EAAE,aAAa;IAClC,wCAAwC;IACxC,WAAW,EAAE,CAAC;IACd,4CAA4C;IAC5C,kBAAkB,EAAE,IAAI;IACxB,4CAA4C;IAC5C,cAAc,EAAE,KAAK;CACtB,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,kBAAkB;IAMhC,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,QAAQ,CAAC,IAAI,kBAAkB,CAAC,QAAQ,CAAgC,CAAC;IAC1H,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAC;IAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACpD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,UAAU,CAAC,KAAK,MAAM,CAAC;IAExE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAChD,CAAC;AAED,8FAA8F;AAE9F;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,qDAAqD;IACrD,mBAAmB,EAAE,IAAI;IACzB,kDAAkD;IAClD,UAAU,EAAE,GAAG;IACf,iDAAiD;IACjD,eAAe,EAAE,EAAE,GAAG,IAAI;IAC1B,mDAAmD;IACnD,iBAAiB,EAAE,GAAG;CACd,CAAC"}
@@ -1,379 +0,0 @@
1
- /**
2
- * Entity Utilities
3
- *
4
- * Consolidated module for entity-related utilities including:
5
- * - Entity lookup and manipulation functions
6
- * - Tag normalization and matching
7
- * - Date parsing and validation
8
- * - Entity filtering by various criteria
9
- * - Path utilities and validation
10
- *
11
- * @module utils/entityUtils
12
- */
13
- import type { Entity, KnowledgeGraph } from '../types/index.js';
14
- /**
15
- * FNV-1a hash function for fast string hashing.
16
- *
17
- * This is a non-cryptographic hash function that provides good distribution
18
- * for bucketing and deduplication purposes. It's optimized for speed
19
- * and produces a 32-bit unsigned integer.
20
- *
21
- * FNV-1a has the following properties:
22
- * - Fast computation (single pass through string)
23
- * - Good distribution for hash table use
24
- * - Deterministic output for same input
25
- *
26
- * @param text - The string to hash
27
- * @returns A 32-bit unsigned integer hash value
28
- *
29
- * @example
30
- * ```typescript
31
- * const hash = fnv1aHash('hello');
32
- * console.log(hash); // 1335831723
33
- *
34
- * // Use for bucketing similar entities
35
- * const bucket = fnv1aHash(entity.name.toLowerCase()) % numBuckets;
36
- * ```
37
- */
38
- export declare function fnv1aHash(text: string): number;
39
- /**
40
- * Finds an entity by name in the graph.
41
- * Overloaded to provide type-safe returns based on throwIfNotFound parameter.
42
- *
43
- * @param graph - The knowledge graph to search
44
- * @param name - The entity name to find
45
- * @param throwIfNotFound - Whether to throw if entity doesn't exist (default: true)
46
- * @returns The entity if found, null if not found and throwIfNotFound is false
47
- * @throws EntityNotFoundError if entity not found and throwIfNotFound is true
48
- */
49
- export declare function findEntityByName(graph: KnowledgeGraph, name: string, throwIfNotFound: true): Entity;
50
- export declare function findEntityByName(graph: KnowledgeGraph, name: string, throwIfNotFound: false): Entity | null;
51
- export declare function findEntityByName(graph: KnowledgeGraph, name: string, throwIfNotFound?: boolean): Entity | null;
52
- /**
53
- * Finds multiple entities by name.
54
- *
55
- * @param graph - The knowledge graph to search
56
- * @param names - Array of entity names to find
57
- * @param throwIfAnyNotFound - Whether to throw if any entity doesn't exist (default: true)
58
- * @returns Array of found entities (may be shorter than names if throwIfAnyNotFound is false)
59
- * @throws EntityNotFoundError if any entity not found and throwIfAnyNotFound is true
60
- */
61
- export declare function findEntitiesByNames(graph: KnowledgeGraph, names: string[], throwIfAnyNotFound?: boolean): Entity[];
62
- /**
63
- * Checks if an entity exists in the graph.
64
- *
65
- * @param graph - The knowledge graph to search
66
- * @param name - The entity name to check
67
- * @returns true if entity exists, false otherwise
68
- */
69
- export declare function entityExists(graph: KnowledgeGraph, name: string): boolean;
70
- /**
71
- * Gets the index of an entity in the graph's entities array.
72
- *
73
- * @param graph - The knowledge graph to search
74
- * @param name - The entity name to find
75
- * @returns The index if found, -1 otherwise
76
- */
77
- export declare function getEntityIndex(graph: KnowledgeGraph, name: string): number;
78
- /**
79
- * Removes an entity from the graph by name.
80
- * Mutates the graph's entities array in place.
81
- *
82
- * @param graph - The knowledge graph to modify
83
- * @param name - The entity name to remove
84
- * @returns true if entity was removed, false if not found
85
- */
86
- export declare function removeEntityByName(graph: KnowledgeGraph, name: string): boolean;
87
- /**
88
- * Gets all entity names as a Set for fast lookup.
89
- *
90
- * @param graph - The knowledge graph
91
- * @returns Set of all entity names
92
- */
93
- export declare function getEntityNameSet(graph: KnowledgeGraph): Set<string>;
94
- /**
95
- * Groups entities by their type.
96
- *
97
- * @param entities - Array of entities to group
98
- * @returns Map of entity type to array of entities
99
- */
100
- export declare function groupEntitiesByType(entities: Entity[]): Map<string, Entity[]>;
101
- /**
102
- * Updates the lastModified timestamp on an entity.
103
- * Mutates the entity in place.
104
- *
105
- * @param entity - The entity to update
106
- * @returns The updated entity (same reference)
107
- */
108
- export declare function touchEntity(entity: Entity): Entity;
109
- /**
110
- * Normalizes a single tag to lowercase and trimmed.
111
- *
112
- * @param tag - Tag to normalize
113
- * @returns Normalized tag
114
- */
115
- export declare function normalizeTag(tag: string): string;
116
- /**
117
- * Normalizes an array of tags to lowercase.
118
- * Handles undefined/null input gracefully.
119
- *
120
- * @param tags - Array of tags to normalize, or undefined
121
- * @returns Normalized tags array, or empty array if input is undefined/null
122
- */
123
- export declare function normalizeTags(tags: string[] | undefined | null): string[];
124
- /**
125
- * Checks if an entity's tags include any of the specified search tags.
126
- * Both inputs are normalized before comparison.
127
- *
128
- * @param entityTags - Tags on the entity (may be undefined)
129
- * @param searchTags - Tags to search for (may be undefined)
130
- * @returns true if any search tag matches any entity tag, false if no match or either is empty
131
- */
132
- export declare function hasMatchingTag(entityTags: string[] | undefined, searchTags: string[] | undefined): boolean;
133
- /**
134
- * Checks if entity tags include ALL of the specified required tags.
135
- *
136
- * @param entityTags - Tags on the entity (may be undefined)
137
- * @param requiredTags - All tags that must be present
138
- * @returns true if all required tags are present
139
- */
140
- export declare function hasAllTags(entityTags: string[] | undefined, requiredTags: string[]): boolean;
141
- /**
142
- * Filters entities by tag match.
143
- * Returns all entities if searchTags is empty or undefined.
144
- *
145
- * @param entities - Array of entities with optional tags property
146
- * @param searchTags - Tags to filter by
147
- * @returns Filtered entities that have at least one matching tag
148
- */
149
- export declare function filterByTags<T extends {
150
- tags?: string[];
151
- }>(entities: T[], searchTags: string[] | undefined): T[];
152
- /**
153
- * Adds new tags to an existing tag array, avoiding duplicates.
154
- * All tags are normalized to lowercase.
155
- *
156
- * @param existingTags - Current tags (may be undefined)
157
- * @param newTags - Tags to add
158
- * @returns Combined tags array with no duplicates
159
- */
160
- export declare function addUniqueTags(existingTags: string[] | undefined, newTags: string[]): string[];
161
- /**
162
- * Removes specified tags from an existing tag array.
163
- * Comparison is case-insensitive.
164
- *
165
- * @param existingTags - Current tags (may be undefined)
166
- * @param tagsToRemove - Tags to remove
167
- * @returns Tags array with specified tags removed
168
- */
169
- export declare function removeTags(existingTags: string[] | undefined, tagsToRemove: string[]): string[];
170
- /**
171
- * Check if a date falls within a specified range.
172
- *
173
- * @param date - ISO 8601 date string to check (may be undefined)
174
- * @param start - Optional start date (inclusive)
175
- * @param end - Optional end date (inclusive)
176
- * @returns True if date is within range or no filters are set
177
- *
178
- * @example
179
- * ```typescript
180
- * isWithinDateRange('2024-06-15T00:00:00Z', '2024-01-01T00:00:00Z', '2024-12-31T23:59:59Z'); // true
181
- * isWithinDateRange('2024-06-15T00:00:00Z', '2024-07-01T00:00:00Z'); // false
182
- * isWithinDateRange(undefined); // true (no filters)
183
- * isWithinDateRange(undefined, '2024-01-01T00:00:00Z'); // false (has filter but no date)
184
- * ```
185
- */
186
- export declare function isWithinDateRange(date: string | undefined, start?: string, end?: string): boolean;
187
- /**
188
- * Parse and validate date range strings.
189
- *
190
- * @param startDate - Optional ISO 8601 start date
191
- * @param endDate - Optional ISO 8601 end date
192
- * @returns Parsed Date objects or null
193
- */
194
- export declare function parseDateRange(startDate?: string, endDate?: string): {
195
- start: Date | null;
196
- end: Date | null;
197
- };
198
- /**
199
- * Validate if a string is a valid ISO 8601 date.
200
- *
201
- * @param date - Date string to validate
202
- * @returns True if valid ISO 8601 date
203
- */
204
- export declare function isValidISODate(date: string): boolean;
205
- /**
206
- * Get current timestamp in ISO 8601 format.
207
- *
208
- * @returns Current timestamp string
209
- */
210
- export declare function getCurrentTimestamp(): string;
211
- /**
212
- * Checks if an entity's importance is within the specified range.
213
- * Entities without importance are treated as not matching if any filter is set.
214
- *
215
- * @param importance - The entity's importance value (may be undefined)
216
- * @param minImportance - Minimum importance filter (inclusive)
217
- * @param maxImportance - Maximum importance filter (inclusive)
218
- * @returns true if importance is within range or no filters are set
219
- *
220
- * @example
221
- * ```typescript
222
- * // Check if entity passes importance filter
223
- * if (isWithinImportanceRange(entity.importance, 5, 10)) {
224
- * // Entity has importance between 5 and 10
225
- * }
226
- * ```
227
- */
228
- export declare function isWithinImportanceRange(importance: number | undefined, minImportance?: number, maxImportance?: number): boolean;
229
- /**
230
- * Filters entities by importance range.
231
- * Returns all entities if no importance filters are specified.
232
- *
233
- * @param entities - Array of entities to filter
234
- * @param minImportance - Minimum importance filter (inclusive)
235
- * @param maxImportance - Maximum importance filter (inclusive)
236
- * @returns Filtered entities within the importance range
237
- */
238
- export declare function filterByImportance(entities: Entity[], minImportance?: number, maxImportance?: number): Entity[];
239
- /**
240
- * Filters entities by creation date range.
241
- *
242
- * @param entities - Array of entities to filter
243
- * @param startDate - Start of date range (inclusive)
244
- * @param endDate - End of date range (inclusive)
245
- * @returns Filtered entities created within the date range
246
- */
247
- export declare function filterByCreatedDate(entities: Entity[], startDate?: string, endDate?: string): Entity[];
248
- /**
249
- * Filters entities by last modified date range.
250
- *
251
- * @param entities - Array of entities to filter
252
- * @param startDate - Start of date range (inclusive)
253
- * @param endDate - End of date range (inclusive)
254
- * @returns Filtered entities modified within the date range
255
- */
256
- export declare function filterByModifiedDate(entities: Entity[], startDate?: string, endDate?: string): Entity[];
257
- /**
258
- * Filters entities by entity type.
259
- *
260
- * @param entities - Array of entities to filter
261
- * @param entityType - Entity type to filter by (case-sensitive)
262
- * @returns Filtered entities of the specified type
263
- */
264
- export declare function filterByEntityType(entities: Entity[], entityType?: string): Entity[];
265
- /**
266
- * Common search filters that can be applied to entities.
267
- */
268
- export interface CommonSearchFilters {
269
- tags?: string[];
270
- minImportance?: number;
271
- maxImportance?: number;
272
- entityType?: string;
273
- createdAfter?: string;
274
- createdBefore?: string;
275
- modifiedAfter?: string;
276
- modifiedBefore?: string;
277
- }
278
- /**
279
- * Checks if an entity passes all the specified filters.
280
- * Short-circuits on first failing filter for performance.
281
- *
282
- * Note: Tag filtering should be handled separately using hasMatchingTag
283
- * as it requires special normalization logic.
284
- *
285
- * @param entity - Entity to check
286
- * @param filters - Filters to apply
287
- * @returns true if entity passes all filters
288
- */
289
- export declare function entityPassesFilters(entity: Entity, filters: Omit<CommonSearchFilters, 'tags'>): boolean;
290
- /**
291
- * Sanitizes an object by removing potentially dangerous keys.
292
- * This prevents prototype pollution attacks when using Object.assign() or spread operators.
293
- *
294
- * @param obj - The object to sanitize
295
- * @returns A new object with dangerous keys removed
296
- *
297
- * @example
298
- * ```typescript
299
- * // Safe usage with Object.assign
300
- * const updates = sanitizeObject(userInput);
301
- * Object.assign(entity, updates);
302
- *
303
- * // Protects against prototype pollution
304
- * const malicious = { __proto__: { admin: true } };
305
- * const safe = sanitizeObject(malicious); // { }
306
- * ```
307
- */
308
- export declare function sanitizeObject<T extends Record<string, unknown>>(obj: T): Partial<T>;
309
- /**
310
- * Escapes a CSV field to prevent formula injection attacks.
311
- * Prepends a single quote to values that start with dangerous characters.
312
- *
313
- * @param field - The field value to escape
314
- * @returns Escaped field value safe for CSV export
315
- *
316
- * @example
317
- * ```typescript
318
- * escapeCsvFormula('=SUM(A1:A10)'); // "'=SUM(A1:A10)"
319
- * escapeCsvFormula('normal text'); // 'normal text'
320
- * ```
321
- */
322
- export declare function escapeCsvFormula(field: string | undefined | null): string;
323
- /**
324
- * Validate and normalize a file path to prevent path traversal attacks.
325
- *
326
- * This function:
327
- * - Normalizes the path to canonical form
328
- * - Converts relative paths to absolute paths
329
- * - Detects and prevents path traversal attempts (..)
330
- *
331
- * @param filePath - The file path to validate
332
- * @param baseDir - Optional base directory for relative paths (defaults to process.cwd())
333
- * @returns Validated absolute file path
334
- * @throws {FileOperationError} If path traversal is detected or path is invalid
335
- *
336
- * @example
337
- * ```typescript
338
- * // Valid paths
339
- * validateFilePath('/var/data/memory.jsonl'); // Returns absolute path
340
- * validateFilePath('data/memory.jsonl'); // Returns absolute path from cwd
341
- *
342
- * // Invalid paths (throws FileOperationError)
343
- * validateFilePath('../../../etc/passwd'); // Path traversal detected
344
- * validateFilePath('/var/data/../../../etc/passwd'); // Path traversal detected
345
- * ```
346
- */
347
- export declare function validateFilePath(filePath: string, baseDir?: string): string;
348
- /**
349
- * Default memory file path (in project root directory, outside dist/).
350
- */
351
- export declare const defaultMemoryPath: string;
352
- /**
353
- * Ensure memory file path with backward compatibility migration.
354
- *
355
- * Handles:
356
- * 1. Custom MEMORY_FILE_PATH environment variable (with path traversal protection)
357
- * 2. Backward compatibility: migrates memory.json to memory.jsonl
358
- * 3. Absolute vs relative path resolution
359
- *
360
- * @returns Resolved and validated memory file path
361
- * @throws {FileOperationError} If path traversal is detected in MEMORY_FILE_PATH
362
- *
363
- * @example
364
- * ```typescript
365
- * // Use environment variable
366
- * process.env.MEMORY_FILE_PATH = '/data/memory.jsonl';
367
- * const path = await ensureMemoryFilePath(); // '/data/memory.jsonl'
368
- *
369
- * // Use default path
370
- * delete process.env.MEMORY_FILE_PATH;
371
- * const path = await ensureMemoryFilePath(); // './memory.jsonl'
372
- *
373
- * // Invalid path (throws error)
374
- * process.env.MEMORY_FILE_PATH = '../../../etc/passwd';
375
- * await ensureMemoryFilePath(); // Throws FileOperationError
376
- * ```
377
- */
378
- export declare function ensureMemoryFilePath(): Promise<string>;
379
- //# sourceMappingURL=entityUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"entityUtils.d.ts","sourceRoot":"","sources":["../../src/utils/entityUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAKhE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO9C;AAID;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,cAAc,EACrB,IAAI,EAAE,MAAM,EACZ,eAAe,EAAE,IAAI,GACpB,MAAM,CAAC;AACV,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,cAAc,EACrB,IAAI,EAAE,MAAM,EACZ,eAAe,EAAE,KAAK,GACrB,MAAM,GAAG,IAAI,CAAC;AACjB,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,cAAc,EACrB,IAAI,EAAE,MAAM,EACZ,eAAe,CAAC,EAAE,OAAO,GACxB,MAAM,GAAG,IAAI,CAAC;AAajB;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,MAAM,EAAE,EACf,kBAAkB,GAAE,OAAc,GACjC,MAAM,EAAE,CAaV;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,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