@soulcraft/brainy 2.15.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +249 -152
  3. package/dist/api/ConfigAPI.d.ts +67 -0
  4. package/dist/api/ConfigAPI.js +166 -0
  5. package/dist/api/DataAPI.d.ts +123 -0
  6. package/dist/api/DataAPI.js +391 -0
  7. package/dist/api/SecurityAPI.d.ts +50 -0
  8. package/dist/api/SecurityAPI.js +139 -0
  9. package/dist/api/UniversalImportAPI.d.ts +134 -0
  10. package/dist/api/UniversalImportAPI.js +615 -0
  11. package/dist/augmentationManager.js +12 -7
  12. package/dist/augmentationPipeline.d.ts +0 -61
  13. package/dist/augmentationPipeline.js +0 -87
  14. package/dist/augmentationRegistry.d.ts +1 -1
  15. package/dist/augmentationRegistry.js +1 -1
  16. package/dist/augmentations/apiServerAugmentation.d.ts +27 -1
  17. package/dist/augmentations/apiServerAugmentation.js +288 -7
  18. package/dist/augmentations/auditLogAugmentation.d.ts +109 -0
  19. package/dist/augmentations/auditLogAugmentation.js +358 -0
  20. package/dist/augmentations/batchProcessingAugmentation.d.ts +3 -2
  21. package/dist/augmentations/batchProcessingAugmentation.js +123 -22
  22. package/dist/augmentations/brainyAugmentation.d.ts +87 -8
  23. package/dist/augmentations/brainyAugmentation.js +159 -2
  24. package/dist/augmentations/cacheAugmentation.d.ts +6 -5
  25. package/dist/augmentations/cacheAugmentation.js +113 -17
  26. package/dist/augmentations/conduitAugmentations.d.ts +2 -2
  27. package/dist/augmentations/conduitAugmentations.js +2 -2
  28. package/dist/augmentations/configResolver.d.ts +122 -0
  29. package/dist/augmentations/configResolver.js +440 -0
  30. package/dist/augmentations/connectionPoolAugmentation.d.ts +3 -1
  31. package/dist/augmentations/connectionPoolAugmentation.js +37 -12
  32. package/dist/augmentations/defaultAugmentations.d.ts +9 -11
  33. package/dist/augmentations/defaultAugmentations.js +4 -11
  34. package/dist/augmentations/discovery/catalogDiscovery.d.ts +142 -0
  35. package/dist/augmentations/discovery/catalogDiscovery.js +249 -0
  36. package/dist/augmentations/discovery/localDiscovery.d.ts +84 -0
  37. package/dist/augmentations/discovery/localDiscovery.js +246 -0
  38. package/dist/augmentations/discovery/runtimeLoader.d.ts +97 -0
  39. package/dist/augmentations/discovery/runtimeLoader.js +337 -0
  40. package/dist/augmentations/discovery.d.ts +152 -0
  41. package/dist/augmentations/discovery.js +441 -0
  42. package/dist/augmentations/display/intelligentComputation.d.ts +1 -1
  43. package/dist/augmentations/display/intelligentComputation.js +4 -4
  44. package/dist/augmentations/entityRegistryAugmentation.d.ts +3 -1
  45. package/dist/augmentations/entityRegistryAugmentation.js +5 -1
  46. package/dist/augmentations/indexAugmentation.d.ts +3 -3
  47. package/dist/augmentations/indexAugmentation.js +2 -2
  48. package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +22 -6
  49. package/dist/augmentations/intelligentVerbScoringAugmentation.js +106 -23
  50. package/dist/augmentations/manifest.d.ts +176 -0
  51. package/dist/augmentations/manifest.js +8 -0
  52. package/dist/augmentations/marketplace/AugmentationMarketplace.d.ts +168 -0
  53. package/dist/augmentations/marketplace/AugmentationMarketplace.js +329 -0
  54. package/dist/augmentations/marketplace/cli.d.ts +47 -0
  55. package/dist/augmentations/marketplace/cli.js +265 -0
  56. package/dist/augmentations/metricsAugmentation.d.ts +3 -3
  57. package/dist/augmentations/metricsAugmentation.js +2 -2
  58. package/dist/augmentations/monitoringAugmentation.d.ts +3 -3
  59. package/dist/augmentations/monitoringAugmentation.js +2 -2
  60. package/dist/augmentations/neuralImport.d.ts +1 -1
  61. package/dist/augmentations/rateLimitAugmentation.d.ts +82 -0
  62. package/dist/augmentations/rateLimitAugmentation.js +321 -0
  63. package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +2 -2
  64. package/dist/augmentations/requestDeduplicatorAugmentation.js +1 -1
  65. package/dist/augmentations/storageAugmentation.d.ts +1 -1
  66. package/dist/augmentations/storageAugmentation.js +2 -2
  67. package/dist/augmentations/storageAugmentations.d.ts +37 -8
  68. package/dist/augmentations/storageAugmentations.js +204 -15
  69. package/dist/augmentations/synapseAugmentation.d.ts +1 -1
  70. package/dist/augmentations/synapseAugmentation.js +35 -16
  71. package/dist/augmentations/typeMatching/intelligentTypeMatcher.d.ts +39 -59
  72. package/dist/augmentations/typeMatching/intelligentTypeMatcher.js +103 -389
  73. package/dist/augmentations/universalDisplayAugmentation.d.ts +2 -2
  74. package/dist/augmentations/universalDisplayAugmentation.js +2 -2
  75. package/dist/brainy-unified.d.ts +106 -0
  76. package/dist/brainy-unified.js +327 -0
  77. package/dist/brainy.d.ts +273 -0
  78. package/dist/brainy.js +1181 -0
  79. package/dist/brainyData.d.ts +29 -72
  80. package/dist/brainyData.js +350 -304
  81. package/dist/brainyDataV3.d.ts +186 -0
  82. package/dist/brainyDataV3.js +337 -0
  83. package/dist/browserFramework.d.ts +6 -6
  84. package/dist/browserFramework.js +11 -8
  85. package/dist/browserFramework.minimal.d.ts +5 -5
  86. package/dist/browserFramework.minimal.js +11 -8
  87. package/dist/config/index.d.ts +2 -2
  88. package/dist/config/index.js +3 -3
  89. package/dist/config/modelAutoConfig.d.ts +6 -7
  90. package/dist/config/modelAutoConfig.js +17 -76
  91. package/dist/cortex/backupRestore.d.ts +2 -2
  92. package/dist/cortex/backupRestore.js +85 -27
  93. package/dist/cortex/healthCheck.d.ts +2 -2
  94. package/dist/cortex/neuralImport.d.ts +2 -2
  95. package/dist/cortex/neuralImport.js +18 -13
  96. package/dist/cortex/performanceMonitor.d.ts +2 -2
  97. package/dist/critical/model-guardian.d.ts +4 -0
  98. package/dist/critical/model-guardian.js +31 -11
  99. package/dist/demo.d.ts +4 -4
  100. package/dist/demo.js +7 -7
  101. package/dist/distributed/cacheSync.d.ts +112 -0
  102. package/dist/distributed/cacheSync.js +265 -0
  103. package/dist/distributed/coordinator.d.ts +193 -0
  104. package/dist/distributed/coordinator.js +548 -0
  105. package/dist/distributed/httpTransport.d.ts +120 -0
  106. package/dist/distributed/httpTransport.js +446 -0
  107. package/dist/distributed/index.d.ts +8 -0
  108. package/dist/distributed/index.js +5 -0
  109. package/dist/distributed/networkTransport.d.ts +132 -0
  110. package/dist/distributed/networkTransport.js +633 -0
  111. package/dist/distributed/queryPlanner.d.ts +104 -0
  112. package/dist/distributed/queryPlanner.js +327 -0
  113. package/dist/distributed/readWriteSeparation.d.ts +134 -0
  114. package/dist/distributed/readWriteSeparation.js +350 -0
  115. package/dist/distributed/shardManager.d.ts +114 -0
  116. package/dist/distributed/shardManager.js +357 -0
  117. package/dist/distributed/shardMigration.d.ts +110 -0
  118. package/dist/distributed/shardMigration.js +289 -0
  119. package/dist/distributed/storageDiscovery.d.ts +160 -0
  120. package/dist/distributed/storageDiscovery.js +551 -0
  121. package/dist/embeddings/EmbeddingManager.d.ts +0 -4
  122. package/dist/embeddings/EmbeddingManager.js +21 -26
  123. package/dist/errors/brainyError.d.ts +5 -1
  124. package/dist/errors/brainyError.js +12 -0
  125. package/dist/examples/basicUsage.js +3 -3
  126. package/dist/graph/graphAdjacencyIndex.d.ts +96 -0
  127. package/dist/graph/graphAdjacencyIndex.js +288 -0
  128. package/dist/graph/pathfinding.js +4 -2
  129. package/dist/hnsw/scaledHNSWSystem.js +11 -2
  130. package/dist/importManager.js +6 -3
  131. package/dist/index.d.ts +12 -21
  132. package/dist/index.js +14 -22
  133. package/dist/mcp/brainyMCPAdapter.d.ts +4 -4
  134. package/dist/mcp/brainyMCPAdapter.js +5 -5
  135. package/dist/mcp/brainyMCPService.d.ts +3 -3
  136. package/dist/mcp/brainyMCPService.js +3 -11
  137. package/dist/mcp/mcpAugmentationToolset.js +20 -30
  138. package/dist/neural/embeddedPatterns.d.ts +1 -1
  139. package/dist/neural/embeddedPatterns.js +2 -2
  140. package/dist/neural/entityExtractor.d.ts +65 -0
  141. package/dist/neural/entityExtractor.js +316 -0
  142. package/dist/neural/improvedNeuralAPI.js +90 -79
  143. package/dist/neural/naturalLanguageProcessor.d.ts +155 -10
  144. package/dist/neural/naturalLanguageProcessor.js +941 -66
  145. package/dist/neural/naturalLanguageProcessorStatic.d.ts +2 -2
  146. package/dist/neural/naturalLanguageProcessorStatic.js +3 -3
  147. package/dist/neural/neuralAPI.js +8 -2
  148. package/dist/neural/patternLibrary.d.ts +57 -3
  149. package/dist/neural/patternLibrary.js +348 -13
  150. package/dist/neural/staticPatternMatcher.d.ts +2 -2
  151. package/dist/neural/staticPatternMatcher.js +2 -2
  152. package/dist/shared/default-augmentations.d.ts +3 -3
  153. package/dist/shared/default-augmentations.js +5 -5
  154. package/dist/storage/adapters/fileSystemStorage.d.ts +4 -0
  155. package/dist/storage/adapters/fileSystemStorage.js +54 -1
  156. package/dist/storage/adapters/memoryStorage.js +13 -8
  157. package/dist/storage/backwardCompatibility.d.ts +10 -78
  158. package/dist/storage/backwardCompatibility.js +17 -132
  159. package/dist/storage/baseStorage.d.ts +6 -0
  160. package/dist/storage/baseStorage.js +17 -0
  161. package/dist/storage/cacheManager.js +2 -2
  162. package/dist/storage/readOnlyOptimizations.js +8 -3
  163. package/dist/streaming/pipeline.d.ts +154 -0
  164. package/dist/streaming/pipeline.js +551 -0
  165. package/dist/triple/TripleIntelligence.d.ts +25 -110
  166. package/dist/triple/TripleIntelligence.js +4 -574
  167. package/dist/triple/TripleIntelligenceSystem.d.ts +159 -0
  168. package/dist/triple/TripleIntelligenceSystem.js +519 -0
  169. package/dist/types/apiTypes.d.ts +278 -0
  170. package/dist/types/apiTypes.js +33 -0
  171. package/dist/types/brainy.types.d.ts +308 -0
  172. package/dist/types/brainy.types.js +8 -0
  173. package/dist/types/brainyDataInterface.d.ts +3 -3
  174. package/dist/types/brainyDataInterface.js +2 -2
  175. package/dist/types/graphTypes.js +2 -2
  176. package/dist/utils/cacheAutoConfig.d.ts +3 -3
  177. package/dist/utils/embedding.js +8 -14
  178. package/dist/utils/enhancedLogger.d.ts +104 -0
  179. package/dist/utils/enhancedLogger.js +232 -0
  180. package/dist/utils/index.d.ts +1 -1
  181. package/dist/utils/index.js +1 -1
  182. package/dist/utils/intelligentTypeMapper.d.ts +60 -0
  183. package/dist/utils/intelligentTypeMapper.js +349 -0
  184. package/dist/utils/metadataIndex.d.ts +118 -1
  185. package/dist/utils/metadataIndex.js +539 -16
  186. package/dist/utils/paramValidation.d.ts +39 -0
  187. package/dist/utils/paramValidation.js +192 -0
  188. package/dist/utils/rateLimiter.d.ts +160 -0
  189. package/dist/utils/rateLimiter.js +271 -0
  190. package/dist/utils/statistics.d.ts +4 -4
  191. package/dist/utils/statistics.js +3 -3
  192. package/dist/utils/structuredLogger.d.ts +146 -0
  193. package/dist/utils/structuredLogger.js +394 -0
  194. package/dist/utils/textEncoding.js +2 -1
  195. package/dist/utils/typeValidation.d.ts +34 -0
  196. package/dist/utils/typeValidation.js +247 -0
  197. package/package.json +14 -6
  198. package/scripts/download-models.cjs +6 -15
  199. package/dist/augmentations/walAugmentation.d.ts +0 -111
  200. package/dist/augmentations/walAugmentation.js +0 -519
  201. package/dist/chat/BrainyChat.d.ts +0 -121
  202. package/dist/chat/BrainyChat.js +0 -396
  203. package/dist/chat/ChatCLI.d.ts +0 -61
  204. package/dist/chat/ChatCLI.js +0 -351
@@ -124,4 +124,251 @@ export function resetValidationStats() {
124
124
  suggestions: 0
125
125
  };
126
126
  }
127
+ // ================================================================
128
+ // INPUT VALIDATION UTILITIES
129
+ // ================================================================
130
+ // Comprehensive validation for all public API parameters
131
+ // Extends the existing type validation system
132
+ export class ValidationError extends Error {
133
+ constructor(parameter, value, constraint) {
134
+ super(`Invalid ${parameter}: ${constraint}`);
135
+ this.parameter = parameter;
136
+ this.value = value;
137
+ this.constraint = constraint;
138
+ this.name = 'ValidationError';
139
+ }
140
+ }
141
+ /**
142
+ * Validate required ID parameter
143
+ * Standard validation for all ID-based operations
144
+ */
145
+ export function validateId(id, paramName = 'id') {
146
+ if (id === null || id === undefined) {
147
+ throw new ValidationError(paramName, id, 'cannot be null or undefined');
148
+ }
149
+ if (typeof id !== 'string') {
150
+ throw new ValidationError(paramName, id, 'must be a string');
151
+ }
152
+ if (id.trim().length === 0) {
153
+ throw new ValidationError(paramName, id, 'cannot be empty string');
154
+ }
155
+ if (id.length > 512) {
156
+ throw new ValidationError(paramName, id, 'cannot exceed 512 characters');
157
+ }
158
+ return id.trim();
159
+ }
160
+ /**
161
+ * Validate search query input
162
+ * Handles string queries, vectors, and objects for search operations
163
+ */
164
+ export function validateSearchQuery(query, paramName = 'query') {
165
+ if (query === null || query === undefined) {
166
+ throw new ValidationError(paramName, query, 'cannot be null or undefined');
167
+ }
168
+ // Allow strings, arrays (vectors), or objects
169
+ if (typeof query === 'string') {
170
+ if (query.trim().length === 0) {
171
+ throw new ValidationError(paramName, query, 'query string cannot be empty');
172
+ }
173
+ if (query.length > 10000) {
174
+ throw new ValidationError(paramName, query, 'query string too long (max 10000 characters)');
175
+ }
176
+ return query.trim();
177
+ }
178
+ if (Array.isArray(query)) {
179
+ if (query.length === 0) {
180
+ throw new ValidationError(paramName, query, 'array cannot be empty');
181
+ }
182
+ // Validate vector arrays contain only numbers
183
+ if (query.every(item => typeof item === 'number')) {
184
+ if (query.some(num => !isFinite(num))) {
185
+ throw new ValidationError(paramName, query, 'vector contains invalid numbers (NaN or Infinity)');
186
+ }
187
+ }
188
+ return query;
189
+ }
190
+ if (typeof query === 'object') {
191
+ return query;
192
+ }
193
+ throw new ValidationError(paramName, query, 'must be string, array, or object');
194
+ }
195
+ /**
196
+ * Validate data input for addNoun/updateNoun operations
197
+ * Handles vectors, objects, strings, and validates structure
198
+ */
199
+ export function validateDataInput(data, paramName = 'data', allowNull = false) {
200
+ // Handle null/undefined
201
+ if (data === null) {
202
+ if (!allowNull) {
203
+ throw new ValidationError(paramName, data, 'Input cannot be null or undefined');
204
+ }
205
+ return data;
206
+ }
207
+ if (data === undefined) {
208
+ throw new ValidationError(paramName, data, 'Input cannot be null or undefined');
209
+ }
210
+ // Handle strings (including empty strings which are valid)
211
+ if (typeof data === 'string') {
212
+ // Empty strings are valid - they get converted to embeddings
213
+ // This matches the behavior in the embed function
214
+ if (data.length > 1000000) {
215
+ throw new ValidationError(paramName, data, 'string too long (max 1MB)');
216
+ }
217
+ return data;
218
+ }
219
+ // Handle arrays (vectors)
220
+ if (Array.isArray(data)) {
221
+ if (data.length === 0) {
222
+ throw new ValidationError(paramName, data, 'array cannot be empty');
223
+ }
224
+ if (data.length > 100000) {
225
+ throw new ValidationError(paramName, data, 'array too large (max 100k elements)');
226
+ }
227
+ // Validate vector arrays contain only numbers
228
+ if (data.every(item => typeof item === 'number')) {
229
+ if (data.some(num => !isFinite(num))) {
230
+ throw new ValidationError(paramName, data, 'vector contains invalid numbers (NaN or Infinity)');
231
+ }
232
+ }
233
+ return data;
234
+ }
235
+ // Handle objects
236
+ if (typeof data === 'object') {
237
+ try {
238
+ // Quick check if object can be serialized (avoids circular references)
239
+ JSON.stringify(data);
240
+ }
241
+ catch (error) {
242
+ throw new ValidationError(paramName, data, 'object contains circular references or unserializable values');
243
+ }
244
+ return data;
245
+ }
246
+ // Handle primitive types
247
+ if (typeof data === 'number') {
248
+ if (!isFinite(data)) {
249
+ throw new ValidationError(paramName, data, 'number must be finite (not NaN or Infinity)');
250
+ }
251
+ return data;
252
+ }
253
+ if (typeof data === 'boolean') {
254
+ return data;
255
+ }
256
+ throw new ValidationError(paramName, data, 'must be string, number, boolean, array, or object');
257
+ }
258
+ /**
259
+ * Validate search options
260
+ * Comprehensive validation for search API options
261
+ */
262
+ export function validateSearchOptions(options, paramName = 'options') {
263
+ if (options === null || options === undefined) {
264
+ return {}; // Default to empty options
265
+ }
266
+ if (typeof options !== 'object' || Array.isArray(options)) {
267
+ throw new ValidationError(paramName, options, 'must be an object');
268
+ }
269
+ const opts = options;
270
+ // Validate limit
271
+ if ('limit' in opts) {
272
+ const limit = opts.limit;
273
+ if (typeof limit !== 'number' || limit < 1 || limit > 10000 || !Number.isInteger(limit)) {
274
+ throw new ValidationError(`${paramName}.limit`, limit, 'must be integer between 1 and 10000');
275
+ }
276
+ }
277
+ // Validate offset
278
+ if ('offset' in opts) {
279
+ const offset = opts.offset;
280
+ if (typeof offset !== 'number' || offset < 0 || !Number.isInteger(offset)) {
281
+ throw new ValidationError(`${paramName}.offset`, offset, 'must be non-negative integer');
282
+ }
283
+ }
284
+ // Validate threshold
285
+ if ('threshold' in opts) {
286
+ const threshold = opts.threshold;
287
+ if (typeof threshold !== 'number' || threshold < 0 || threshold > 1) {
288
+ throw new ValidationError(`${paramName}.threshold`, threshold, 'must be number between 0 and 1');
289
+ }
290
+ }
291
+ // Validate timeout
292
+ if ('timeout' in opts) {
293
+ const timeout = opts.timeout;
294
+ if (typeof timeout !== 'number' || timeout < 1 || timeout > 300000 || !Number.isInteger(timeout)) {
295
+ throw new ValidationError(`${paramName}.timeout`, timeout, 'must be integer between 1 and 300000 milliseconds');
296
+ }
297
+ }
298
+ // Validate nounTypes array
299
+ if ('nounTypes' in opts) {
300
+ if (!Array.isArray(opts.nounTypes)) {
301
+ throw new ValidationError(`${paramName}.nounTypes`, opts.nounTypes, 'must be an array');
302
+ }
303
+ if (opts.nounTypes.length > 100) {
304
+ throw new ValidationError(`${paramName}.nounTypes`, opts.nounTypes, 'too many noun types (max 100)');
305
+ }
306
+ // Validate each noun type
307
+ opts.nounTypes = opts.nounTypes.map((type, index) => {
308
+ try {
309
+ return validateNounType(type);
310
+ }
311
+ catch (error) {
312
+ if (error instanceof Error) {
313
+ throw new ValidationError(`${paramName}.nounTypes[${index}]`, type, error.message);
314
+ }
315
+ throw error;
316
+ }
317
+ });
318
+ }
319
+ // Validate itemIds array
320
+ if ('itemIds' in opts) {
321
+ if (!Array.isArray(opts.itemIds)) {
322
+ throw new ValidationError(`${paramName}.itemIds`, opts.itemIds, 'must be an array');
323
+ }
324
+ if (opts.itemIds.length > 10000) {
325
+ throw new ValidationError(`${paramName}.itemIds`, opts.itemIds, 'too many item IDs (max 10000)');
326
+ }
327
+ opts.itemIds = opts.itemIds.map((id, index) => {
328
+ try {
329
+ return validateId(id, `${paramName}.itemIds[${index}]`);
330
+ }
331
+ catch (error) {
332
+ throw error; // Re-throw with proper context
333
+ }
334
+ });
335
+ }
336
+ return opts;
337
+ }
338
+ /**
339
+ * Validate ID arrays (for bulk operations)
340
+ */
341
+ export function validateIdArray(ids, paramName = 'ids') {
342
+ if (ids === null || ids === undefined) {
343
+ throw new ValidationError(paramName, ids, 'cannot be null or undefined');
344
+ }
345
+ if (!Array.isArray(ids)) {
346
+ throw new ValidationError(paramName, ids, 'must be an array');
347
+ }
348
+ if (ids.length === 0) {
349
+ throw new ValidationError(paramName, ids, 'cannot be empty');
350
+ }
351
+ if (ids.length > 10000) {
352
+ throw new ValidationError(paramName, ids, 'too large (max 10000 items)');
353
+ }
354
+ return ids.map((id, index) => {
355
+ try {
356
+ return validateId(id, `${paramName}[${index}]`);
357
+ }
358
+ catch (error) {
359
+ throw error; // Re-throw with proper array context
360
+ }
361
+ });
362
+ }
363
+ /**
364
+ * Track validation stats for monitoring
365
+ */
366
+ export function recordValidation(success) {
367
+ if (success) {
368
+ stats.validated++;
369
+ }
370
+ else {
371
+ stats.failed++;
372
+ }
373
+ }
127
374
  //# sourceMappingURL=typeValidation.js.map
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@soulcraft/brainy",
3
- "version": "2.15.0",
3
+ "version": "3.0.1",
4
4
  "description": "Universal Knowledge Protocol™ - World's first Triple Intelligence database unifying vector, graph, and document search in one API. 31 nouns × 40 verbs for infinite expressiveness.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "type": "module",
9
9
  "bin": {
10
- "brainy": "./bin/brainy.js"
10
+ "brainy": "bin/brainy.js"
11
11
  },
12
12
  "sideEffects": [
13
13
  "./dist/setup.js",
@@ -68,19 +68,22 @@
68
68
  "test:coverage": "vitest run --config tests/configs/vitest.unit.config.ts --coverage",
69
69
  "test:unit": "vitest run --config tests/configs/vitest.unit.config.ts",
70
70
  "test:integration": "NODE_OPTIONS='--max-old-space-size=32768' vitest run --config tests/configs/vitest.integration.config.ts",
71
+ "test:s3": "vitest run tests/integration/s3-storage.test.ts",
72
+ "test:distributed": "vitest run tests/integration/distributed.test.ts",
73
+ "test:cloud": "npm run test:s3 && npm run test:distributed",
71
74
  "test:all": "npm run test:unit && npm run test:integration",
72
75
  "test:ci-unit": "CI=true vitest run --config tests/configs/vitest.unit.config.ts",
73
76
  "test:ci-integration": "NODE_OPTIONS='--max-old-space-size=16384' CI=true vitest run --config tests/configs/vitest.integration.config.ts",
74
77
  "test:ci": "npm run test:ci-unit",
75
78
  "download-models": "node scripts/download-models.cjs",
76
- "download-models:fp32": "node scripts/download-models.cjs fp32",
77
- "download-models:q8": "node scripts/download-models.cjs q8",
78
- "download-models:both": "node scripts/download-models.cjs",
79
+ "download-models:q8": "node scripts/download-models.cjs",
79
80
  "models:verify": "node scripts/ensure-models.js",
80
81
  "lint": "eslint --ext .ts,.js src/",
81
82
  "lint:fix": "eslint --ext .ts,.js src/ --fix",
82
83
  "format": "prettier --write \"src/**/*.{ts,js}\"",
83
84
  "format:check": "prettier --check \"src/**/*.{ts,js}\"",
85
+ "migrate:logger": "tsx scripts/migrate-to-structured-logger.ts",
86
+ "migrate:logger:dry": "tsx scripts/migrate-to-structured-logger.ts --dry-run",
84
87
  "release": "standard-version",
85
88
  "release:patch": "standard-version --release-as patch",
86
89
  "release:minor": "standard-version --release-as minor",
@@ -133,12 +136,16 @@
133
136
  "@rollup/plugin-node-resolve": "^16.0.1",
134
137
  "@rollup/plugin-replace": "^6.0.2",
135
138
  "@rollup/plugin-terser": "^0.4.4",
139
+ "@testcontainers/redis": "^11.5.1",
136
140
  "@types/node": "^20.11.30",
137
141
  "@types/uuid": "^10.0.0",
142
+ "@types/ws": "^8.18.1",
138
143
  "@typescript-eslint/eslint-plugin": "^8.0.0",
139
144
  "@typescript-eslint/parser": "^8.0.0",
140
145
  "@vitest/coverage-v8": "^3.2.4",
146
+ "minio": "^8.0.5",
141
147
  "standard-version": "^9.5.0",
148
+ "testcontainers": "^11.5.1",
142
149
  "tsx": "^4.19.2",
143
150
  "typescript": "^5.4.5",
144
151
  "vitest": "^3.2.4"
@@ -153,7 +160,8 @@
153
160
  "inquirer": "^12.9.3",
154
161
  "ora": "^8.2.0",
155
162
  "prompts": "^2.4.2",
156
- "uuid": "^9.0.1"
163
+ "uuid": "^9.0.1",
164
+ "ws": "^8.18.3"
157
165
  },
158
166
  "prettier": {
159
167
  "arrowParens": "always",
@@ -9,10 +9,8 @@ const path = require('path')
9
9
  const MODEL_NAME = 'Xenova/all-MiniLM-L6-v2'
10
10
  const OUTPUT_DIR = './models'
11
11
 
12
- // Parse command line arguments for model type selection
13
- const args = process.argv.slice(2)
14
- const downloadType = args.includes('fp32') ? 'fp32' :
15
- args.includes('q8') ? 'q8' : 'both'
12
+ // Always download Q8 model only
13
+ const downloadType = 'q8'
16
14
 
17
15
  async function downloadModels() {
18
16
  // Use dynamic import for ES modules in CommonJS
@@ -26,23 +24,16 @@ async function downloadModels() {
26
24
  console.log('🧠 Brainy Model Downloader v2.8.0')
27
25
  console.log('===================================')
28
26
  console.log(` Model: ${MODEL_NAME}`)
29
- console.log(` Type: ${downloadType} (fp32, q8, or both)`)
27
+ console.log(` Type: Q8 (optimized, 99% accuracy)`)
30
28
  console.log(` Cache: ${env.cacheDir}`)
31
29
  console.log('')
32
30
 
33
31
  // Create output directory
34
32
  await fs.mkdir(OUTPUT_DIR, { recursive: true })
35
33
 
36
- // Download models based on type
37
- if (downloadType === 'both' || downloadType === 'fp32') {
38
- console.log('📥 Downloading FP32 model (full precision, 90MB)...')
39
- await downloadModelVariant('fp32')
40
- }
41
-
42
- if (downloadType === 'both' || downloadType === 'q8') {
43
- console.log('📥 Downloading Q8 model (quantized, 23MB)...')
44
- await downloadModelVariant('q8')
45
- }
34
+ // Download Q8 model only
35
+ console.log('📥 Downloading Q8 model (quantized, 33MB, 99% accuracy)...')
36
+ await downloadModelVariant('q8')
46
37
 
47
38
  // Copy ALL model files from cache to our models directory
48
39
  console.log('📋 Copying model files to bundle directory...')
@@ -1,111 +0,0 @@
1
- /**
2
- * Write-Ahead Log (WAL) Augmentation
3
- *
4
- * Provides file-based durability and atomicity for storage operations
5
- * Automatically enabled for all critical storage operations
6
- *
7
- * Features:
8
- * - True file-based persistence for crash recovery
9
- * - Operation replay after startup
10
- * - Automatic log rotation and cleanup
11
- * - Cross-platform compatibility (filesystem, OPFS, cloud)
12
- */
13
- import { BaseAugmentation } from './brainyAugmentation.js';
14
- interface WALConfig {
15
- enabled?: boolean;
16
- immediateWrites?: boolean;
17
- adaptivePersistence?: boolean;
18
- walPrefix?: string;
19
- maxSize?: number;
20
- checkpointInterval?: number;
21
- autoRecover?: boolean;
22
- maxRetries?: number;
23
- }
24
- export declare class WALAugmentation extends BaseAugmentation {
25
- name: string;
26
- timing: "around";
27
- metadata: "readonly";
28
- operations: ("addNoun" | "addVerb" | "saveNoun" | "saveVerb" | "updateMetadata" | "delete" | "deleteVerb" | "clear")[];
29
- priority: number;
30
- readonly category: "internal";
31
- readonly description = "Write-ahead logging for durability and crash recovery";
32
- private config;
33
- private currentLogId;
34
- private operationCounter;
35
- private checkpointTimer?;
36
- private isRecovering;
37
- constructor(config?: WALConfig);
38
- protected onInitialize(): Promise<void>;
39
- shouldExecute(operation: string, params: any): boolean;
40
- execute<T = any>(operation: string, params: any, next: () => Promise<T>): Promise<T>;
41
- /**
42
- * Asynchronous WAL entry logging (fire-and-forget for immediate writes)
43
- */
44
- private logAsyncWALEntry;
45
- /**
46
- * Write WAL entry to persistent storage using storage adapter
47
- */
48
- private writeWALEntry;
49
- /**
50
- * Recover pending operations from all existing WAL files
51
- */
52
- private recoverPendingOperations;
53
- /**
54
- * Find all WAL files in storage
55
- */
56
- private findWALFiles;
57
- /**
58
- * Read WAL entries from a file
59
- */
60
- private readWALEntries;
61
- /**
62
- * Find operations that were started but not completed
63
- */
64
- private findPendingOperations;
65
- /**
66
- * Replay an operation during recovery
67
- */
68
- private replayOperation;
69
- /**
70
- * Create a checkpoint to mark a point in time
71
- */
72
- private createCheckpoint;
73
- /**
74
- * Check if log rotation is needed
75
- */
76
- private checkLogRotation;
77
- /**
78
- * Sanitize parameters for logging (remove large objects)
79
- */
80
- private sanitizeParams;
81
- /**
82
- * Get WAL statistics
83
- */
84
- getStats(): {
85
- enabled: boolean;
86
- currentLogId: string;
87
- operationCount: number;
88
- logSize: number;
89
- pendingOperations: number;
90
- failedOperations: number;
91
- };
92
- /**
93
- * Manually trigger checkpoint
94
- */
95
- checkpoint(): Promise<void>;
96
- /**
97
- * Manually trigger log rotation
98
- */
99
- rotate(): Promise<void>;
100
- /**
101
- * Write WAL data directly to storage without embedding
102
- * This bypasses the brain's AI processing pipeline for raw WAL data
103
- */
104
- private writeWALFileDirectly;
105
- /**
106
- * Read WAL data directly from storage without embedding
107
- */
108
- private readWALFileDirectly;
109
- protected onShutdown(): Promise<void>;
110
- }
111
- export {};