@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.
- package/CHANGELOG.md +18 -0
- package/README.md +249 -152
- package/dist/api/ConfigAPI.d.ts +67 -0
- package/dist/api/ConfigAPI.js +166 -0
- package/dist/api/DataAPI.d.ts +123 -0
- package/dist/api/DataAPI.js +391 -0
- package/dist/api/SecurityAPI.d.ts +50 -0
- package/dist/api/SecurityAPI.js +139 -0
- package/dist/api/UniversalImportAPI.d.ts +134 -0
- package/dist/api/UniversalImportAPI.js +615 -0
- package/dist/augmentationManager.js +12 -7
- package/dist/augmentationPipeline.d.ts +0 -61
- package/dist/augmentationPipeline.js +0 -87
- package/dist/augmentationRegistry.d.ts +1 -1
- package/dist/augmentationRegistry.js +1 -1
- package/dist/augmentations/apiServerAugmentation.d.ts +27 -1
- package/dist/augmentations/apiServerAugmentation.js +288 -7
- package/dist/augmentations/auditLogAugmentation.d.ts +109 -0
- package/dist/augmentations/auditLogAugmentation.js +358 -0
- package/dist/augmentations/batchProcessingAugmentation.d.ts +3 -2
- package/dist/augmentations/batchProcessingAugmentation.js +123 -22
- package/dist/augmentations/brainyAugmentation.d.ts +87 -8
- package/dist/augmentations/brainyAugmentation.js +159 -2
- package/dist/augmentations/cacheAugmentation.d.ts +6 -5
- package/dist/augmentations/cacheAugmentation.js +113 -17
- package/dist/augmentations/conduitAugmentations.d.ts +2 -2
- package/dist/augmentations/conduitAugmentations.js +2 -2
- package/dist/augmentations/configResolver.d.ts +122 -0
- package/dist/augmentations/configResolver.js +440 -0
- package/dist/augmentations/connectionPoolAugmentation.d.ts +3 -1
- package/dist/augmentations/connectionPoolAugmentation.js +37 -12
- package/dist/augmentations/defaultAugmentations.d.ts +9 -11
- package/dist/augmentations/defaultAugmentations.js +4 -11
- package/dist/augmentations/discovery/catalogDiscovery.d.ts +142 -0
- package/dist/augmentations/discovery/catalogDiscovery.js +249 -0
- package/dist/augmentations/discovery/localDiscovery.d.ts +84 -0
- package/dist/augmentations/discovery/localDiscovery.js +246 -0
- package/dist/augmentations/discovery/runtimeLoader.d.ts +97 -0
- package/dist/augmentations/discovery/runtimeLoader.js +337 -0
- package/dist/augmentations/discovery.d.ts +152 -0
- package/dist/augmentations/discovery.js +441 -0
- package/dist/augmentations/display/intelligentComputation.d.ts +1 -1
- package/dist/augmentations/display/intelligentComputation.js +4 -4
- package/dist/augmentations/entityRegistryAugmentation.d.ts +3 -1
- package/dist/augmentations/entityRegistryAugmentation.js +5 -1
- package/dist/augmentations/indexAugmentation.d.ts +3 -3
- package/dist/augmentations/indexAugmentation.js +2 -2
- package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +22 -6
- package/dist/augmentations/intelligentVerbScoringAugmentation.js +106 -23
- package/dist/augmentations/manifest.d.ts +176 -0
- package/dist/augmentations/manifest.js +8 -0
- package/dist/augmentations/marketplace/AugmentationMarketplace.d.ts +168 -0
- package/dist/augmentations/marketplace/AugmentationMarketplace.js +329 -0
- package/dist/augmentations/marketplace/cli.d.ts +47 -0
- package/dist/augmentations/marketplace/cli.js +265 -0
- package/dist/augmentations/metricsAugmentation.d.ts +3 -3
- package/dist/augmentations/metricsAugmentation.js +2 -2
- package/dist/augmentations/monitoringAugmentation.d.ts +3 -3
- package/dist/augmentations/monitoringAugmentation.js +2 -2
- package/dist/augmentations/neuralImport.d.ts +1 -1
- package/dist/augmentations/rateLimitAugmentation.d.ts +82 -0
- package/dist/augmentations/rateLimitAugmentation.js +321 -0
- package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +2 -2
- package/dist/augmentations/requestDeduplicatorAugmentation.js +1 -1
- package/dist/augmentations/storageAugmentation.d.ts +1 -1
- package/dist/augmentations/storageAugmentation.js +2 -2
- package/dist/augmentations/storageAugmentations.d.ts +37 -8
- package/dist/augmentations/storageAugmentations.js +204 -15
- package/dist/augmentations/synapseAugmentation.d.ts +1 -1
- package/dist/augmentations/synapseAugmentation.js +35 -16
- package/dist/augmentations/typeMatching/intelligentTypeMatcher.d.ts +39 -59
- package/dist/augmentations/typeMatching/intelligentTypeMatcher.js +103 -389
- package/dist/augmentations/universalDisplayAugmentation.d.ts +2 -2
- package/dist/augmentations/universalDisplayAugmentation.js +2 -2
- package/dist/brainy-unified.d.ts +106 -0
- package/dist/brainy-unified.js +327 -0
- package/dist/brainy.d.ts +273 -0
- package/dist/brainy.js +1181 -0
- package/dist/brainyData.d.ts +29 -72
- package/dist/brainyData.js +350 -304
- package/dist/brainyDataV3.d.ts +186 -0
- package/dist/brainyDataV3.js +337 -0
- package/dist/browserFramework.d.ts +6 -6
- package/dist/browserFramework.js +11 -8
- package/dist/browserFramework.minimal.d.ts +5 -5
- package/dist/browserFramework.minimal.js +11 -8
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +3 -3
- package/dist/config/modelAutoConfig.d.ts +6 -7
- package/dist/config/modelAutoConfig.js +17 -76
- package/dist/cortex/backupRestore.d.ts +2 -2
- package/dist/cortex/backupRestore.js +85 -27
- package/dist/cortex/healthCheck.d.ts +2 -2
- package/dist/cortex/neuralImport.d.ts +2 -2
- package/dist/cortex/neuralImport.js +18 -13
- package/dist/cortex/performanceMonitor.d.ts +2 -2
- package/dist/critical/model-guardian.d.ts +4 -0
- package/dist/critical/model-guardian.js +31 -11
- package/dist/demo.d.ts +4 -4
- package/dist/demo.js +7 -7
- package/dist/distributed/cacheSync.d.ts +112 -0
- package/dist/distributed/cacheSync.js +265 -0
- package/dist/distributed/coordinator.d.ts +193 -0
- package/dist/distributed/coordinator.js +548 -0
- package/dist/distributed/httpTransport.d.ts +120 -0
- package/dist/distributed/httpTransport.js +446 -0
- package/dist/distributed/index.d.ts +8 -0
- package/dist/distributed/index.js +5 -0
- package/dist/distributed/networkTransport.d.ts +132 -0
- package/dist/distributed/networkTransport.js +633 -0
- package/dist/distributed/queryPlanner.d.ts +104 -0
- package/dist/distributed/queryPlanner.js +327 -0
- package/dist/distributed/readWriteSeparation.d.ts +134 -0
- package/dist/distributed/readWriteSeparation.js +350 -0
- package/dist/distributed/shardManager.d.ts +114 -0
- package/dist/distributed/shardManager.js +357 -0
- package/dist/distributed/shardMigration.d.ts +110 -0
- package/dist/distributed/shardMigration.js +289 -0
- package/dist/distributed/storageDiscovery.d.ts +160 -0
- package/dist/distributed/storageDiscovery.js +551 -0
- package/dist/embeddings/EmbeddingManager.d.ts +0 -4
- package/dist/embeddings/EmbeddingManager.js +21 -26
- package/dist/errors/brainyError.d.ts +5 -1
- package/dist/errors/brainyError.js +12 -0
- package/dist/examples/basicUsage.js +3 -3
- package/dist/graph/graphAdjacencyIndex.d.ts +96 -0
- package/dist/graph/graphAdjacencyIndex.js +288 -0
- package/dist/graph/pathfinding.js +4 -2
- package/dist/hnsw/scaledHNSWSystem.js +11 -2
- package/dist/importManager.js +6 -3
- package/dist/index.d.ts +12 -21
- package/dist/index.js +14 -22
- package/dist/mcp/brainyMCPAdapter.d.ts +4 -4
- package/dist/mcp/brainyMCPAdapter.js +5 -5
- package/dist/mcp/brainyMCPService.d.ts +3 -3
- package/dist/mcp/brainyMCPService.js +3 -11
- package/dist/mcp/mcpAugmentationToolset.js +20 -30
- package/dist/neural/embeddedPatterns.d.ts +1 -1
- package/dist/neural/embeddedPatterns.js +2 -2
- package/dist/neural/entityExtractor.d.ts +65 -0
- package/dist/neural/entityExtractor.js +316 -0
- package/dist/neural/improvedNeuralAPI.js +90 -79
- package/dist/neural/naturalLanguageProcessor.d.ts +155 -10
- package/dist/neural/naturalLanguageProcessor.js +941 -66
- package/dist/neural/naturalLanguageProcessorStatic.d.ts +2 -2
- package/dist/neural/naturalLanguageProcessorStatic.js +3 -3
- package/dist/neural/neuralAPI.js +8 -2
- package/dist/neural/patternLibrary.d.ts +57 -3
- package/dist/neural/patternLibrary.js +348 -13
- package/dist/neural/staticPatternMatcher.d.ts +2 -2
- package/dist/neural/staticPatternMatcher.js +2 -2
- package/dist/shared/default-augmentations.d.ts +3 -3
- package/dist/shared/default-augmentations.js +5 -5
- package/dist/storage/adapters/fileSystemStorage.d.ts +4 -0
- package/dist/storage/adapters/fileSystemStorage.js +54 -1
- package/dist/storage/adapters/memoryStorage.js +13 -8
- package/dist/storage/backwardCompatibility.d.ts +10 -78
- package/dist/storage/backwardCompatibility.js +17 -132
- package/dist/storage/baseStorage.d.ts +6 -0
- package/dist/storage/baseStorage.js +17 -0
- package/dist/storage/cacheManager.js +2 -2
- package/dist/storage/readOnlyOptimizations.js +8 -3
- package/dist/streaming/pipeline.d.ts +154 -0
- package/dist/streaming/pipeline.js +551 -0
- package/dist/triple/TripleIntelligence.d.ts +25 -110
- package/dist/triple/TripleIntelligence.js +4 -574
- package/dist/triple/TripleIntelligenceSystem.d.ts +159 -0
- package/dist/triple/TripleIntelligenceSystem.js +519 -0
- package/dist/types/apiTypes.d.ts +278 -0
- package/dist/types/apiTypes.js +33 -0
- package/dist/types/brainy.types.d.ts +308 -0
- package/dist/types/brainy.types.js +8 -0
- package/dist/types/brainyDataInterface.d.ts +3 -3
- package/dist/types/brainyDataInterface.js +2 -2
- package/dist/types/graphTypes.js +2 -2
- package/dist/utils/cacheAutoConfig.d.ts +3 -3
- package/dist/utils/embedding.js +8 -14
- package/dist/utils/enhancedLogger.d.ts +104 -0
- package/dist/utils/enhancedLogger.js +232 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/intelligentTypeMapper.d.ts +60 -0
- package/dist/utils/intelligentTypeMapper.js +349 -0
- package/dist/utils/metadataIndex.d.ts +118 -1
- package/dist/utils/metadataIndex.js +539 -16
- package/dist/utils/paramValidation.d.ts +39 -0
- package/dist/utils/paramValidation.js +192 -0
- package/dist/utils/rateLimiter.d.ts +160 -0
- package/dist/utils/rateLimiter.js +271 -0
- package/dist/utils/statistics.d.ts +4 -4
- package/dist/utils/statistics.js +3 -3
- package/dist/utils/structuredLogger.d.ts +146 -0
- package/dist/utils/structuredLogger.js +394 -0
- package/dist/utils/textEncoding.js +2 -1
- package/dist/utils/typeValidation.d.ts +34 -0
- package/dist/utils/typeValidation.js +247 -0
- package/package.json +14 -6
- package/scripts/download-models.cjs +6 -15
- package/dist/augmentations/walAugmentation.d.ts +0 -111
- package/dist/augmentations/walAugmentation.js +0 -519
- package/dist/chat/BrainyChat.d.ts +0 -121
- package/dist/chat/BrainyChat.js +0 -396
- package/dist/chat/ChatCLI.d.ts +0 -61
- 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": "
|
|
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": "
|
|
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:
|
|
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
|
-
//
|
|
13
|
-
const
|
|
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:
|
|
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
|
|
37
|
-
|
|
38
|
-
|
|
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 {};
|