@soulcraft/brainy 3.0.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 (260) hide show
  1. package/CHANGELOG.md +53 -3
  2. package/README.md +353 -110
  3. package/bin/brainy.js +340 -62
  4. package/dist/api/ConfigAPI.d.ts +67 -0
  5. package/dist/api/ConfigAPI.js +166 -0
  6. package/dist/api/DataAPI.d.ts +123 -0
  7. package/dist/api/DataAPI.js +391 -0
  8. package/dist/api/SecurityAPI.d.ts +50 -0
  9. package/dist/api/SecurityAPI.js +139 -0
  10. package/dist/api/UniversalImportAPI.d.ts +134 -0
  11. package/dist/api/UniversalImportAPI.js +615 -0
  12. package/dist/augmentationManager.js +12 -7
  13. package/dist/augmentationPipeline.d.ts +0 -61
  14. package/dist/augmentationPipeline.js +0 -87
  15. package/dist/augmentationRegistry.d.ts +1 -1
  16. package/dist/augmentationRegistry.js +1 -1
  17. package/dist/augmentations/apiServerAugmentation.d.ts +27 -1
  18. package/dist/augmentations/apiServerAugmentation.js +290 -9
  19. package/dist/augmentations/auditLogAugmentation.d.ts +109 -0
  20. package/dist/augmentations/auditLogAugmentation.js +358 -0
  21. package/dist/augmentations/batchProcessingAugmentation.d.ts +3 -2
  22. package/dist/augmentations/batchProcessingAugmentation.js +123 -22
  23. package/dist/augmentations/brainyAugmentation.d.ts +142 -8
  24. package/dist/augmentations/brainyAugmentation.js +179 -2
  25. package/dist/augmentations/cacheAugmentation.d.ts +8 -5
  26. package/dist/augmentations/cacheAugmentation.js +116 -17
  27. package/dist/augmentations/conduitAugmentations.d.ts +2 -2
  28. package/dist/augmentations/conduitAugmentations.js +2 -2
  29. package/dist/augmentations/configResolver.d.ts +122 -0
  30. package/dist/augmentations/configResolver.js +440 -0
  31. package/dist/augmentations/connectionPoolAugmentation.d.ts +3 -1
  32. package/dist/augmentations/connectionPoolAugmentation.js +37 -12
  33. package/dist/augmentations/defaultAugmentations.d.ts +14 -10
  34. package/dist/augmentations/defaultAugmentations.js +16 -11
  35. package/dist/augmentations/discovery/catalogDiscovery.d.ts +142 -0
  36. package/dist/augmentations/discovery/catalogDiscovery.js +249 -0
  37. package/dist/augmentations/discovery/localDiscovery.d.ts +84 -0
  38. package/dist/augmentations/discovery/localDiscovery.js +246 -0
  39. package/dist/augmentations/discovery/runtimeLoader.d.ts +97 -0
  40. package/dist/augmentations/discovery/runtimeLoader.js +337 -0
  41. package/dist/augmentations/discovery.d.ts +152 -0
  42. package/dist/augmentations/discovery.js +441 -0
  43. package/dist/augmentations/display/cache.d.ts +130 -0
  44. package/dist/augmentations/display/cache.js +319 -0
  45. package/dist/augmentations/display/fieldPatterns.d.ts +52 -0
  46. package/dist/augmentations/display/fieldPatterns.js +393 -0
  47. package/dist/augmentations/display/iconMappings.d.ts +57 -0
  48. package/dist/augmentations/display/iconMappings.js +68 -0
  49. package/dist/augmentations/display/intelligentComputation.d.ts +109 -0
  50. package/dist/augmentations/display/intelligentComputation.js +462 -0
  51. package/dist/augmentations/display/types.d.ts +203 -0
  52. package/dist/augmentations/display/types.js +7 -0
  53. package/dist/augmentations/entityRegistryAugmentation.d.ts +3 -1
  54. package/dist/augmentations/entityRegistryAugmentation.js +5 -1
  55. package/dist/augmentations/indexAugmentation.d.ts +5 -3
  56. package/dist/augmentations/indexAugmentation.js +5 -2
  57. package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +24 -7
  58. package/dist/augmentations/intelligentVerbScoringAugmentation.js +111 -27
  59. package/dist/augmentations/manifest.d.ts +176 -0
  60. package/dist/augmentations/manifest.js +8 -0
  61. package/dist/augmentations/marketplace/AugmentationMarketplace.d.ts +168 -0
  62. package/dist/augmentations/marketplace/AugmentationMarketplace.js +329 -0
  63. package/dist/augmentations/marketplace/cli.d.ts +47 -0
  64. package/dist/augmentations/marketplace/cli.js +265 -0
  65. package/dist/augmentations/metricsAugmentation.d.ts +3 -3
  66. package/dist/augmentations/metricsAugmentation.js +2 -2
  67. package/dist/augmentations/monitoringAugmentation.d.ts +3 -3
  68. package/dist/augmentations/monitoringAugmentation.js +2 -2
  69. package/dist/augmentations/neuralImport.d.ts +1 -1
  70. package/dist/augmentations/neuralImport.js +4 -4
  71. package/dist/augmentations/rateLimitAugmentation.d.ts +82 -0
  72. package/dist/augmentations/rateLimitAugmentation.js +321 -0
  73. package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +2 -2
  74. package/dist/augmentations/requestDeduplicatorAugmentation.js +1 -1
  75. package/dist/augmentations/storageAugmentation.d.ts +1 -1
  76. package/dist/augmentations/storageAugmentation.js +2 -2
  77. package/dist/augmentations/storageAugmentations.d.ts +37 -8
  78. package/dist/augmentations/storageAugmentations.js +204 -15
  79. package/dist/augmentations/synapseAugmentation.d.ts +1 -1
  80. package/dist/augmentations/synapseAugmentation.js +35 -16
  81. package/dist/augmentations/typeMatching/brainyTypes.d.ts +83 -0
  82. package/dist/augmentations/typeMatching/brainyTypes.js +425 -0
  83. package/dist/augmentations/typeMatching/intelligentTypeMatcher.d.ts +39 -59
  84. package/dist/augmentations/typeMatching/intelligentTypeMatcher.js +103 -389
  85. package/dist/augmentations/universalDisplayAugmentation.d.ts +191 -0
  86. package/dist/augmentations/universalDisplayAugmentation.js +371 -0
  87. package/dist/brainy-unified.d.ts +106 -0
  88. package/dist/brainy-unified.js +327 -0
  89. package/dist/brainy.d.ts +273 -0
  90. package/dist/brainy.js +1181 -0
  91. package/dist/brainyData.d.ts +56 -111
  92. package/dist/brainyData.js +912 -756
  93. package/dist/brainyDataV3.d.ts +186 -0
  94. package/dist/brainyDataV3.js +337 -0
  95. package/dist/browserFramework.d.ts +6 -6
  96. package/dist/browserFramework.js +11 -8
  97. package/dist/browserFramework.minimal.d.ts +5 -5
  98. package/dist/browserFramework.minimal.js +11 -8
  99. package/dist/config/distributedPresets-new.d.ts +118 -0
  100. package/dist/config/distributedPresets-new.js +318 -0
  101. package/dist/config/distributedPresets.d.ts +118 -0
  102. package/dist/config/distributedPresets.js +318 -0
  103. package/dist/config/extensibleConfig.d.ts +99 -0
  104. package/dist/config/extensibleConfig.js +268 -0
  105. package/dist/config/index.d.ts +17 -0
  106. package/dist/config/index.js +35 -0
  107. package/dist/config/modelAutoConfig.d.ts +32 -0
  108. package/dist/config/modelAutoConfig.js +139 -0
  109. package/dist/config/modelPrecisionManager.d.ts +42 -0
  110. package/dist/config/modelPrecisionManager.js +98 -0
  111. package/dist/config/sharedConfigManager.d.ts +67 -0
  112. package/dist/config/sharedConfigManager.js +215 -0
  113. package/dist/config/storageAutoConfig.d.ts +41 -0
  114. package/dist/config/storageAutoConfig.js +328 -0
  115. package/dist/config/zeroConfig.d.ts +68 -0
  116. package/dist/config/zeroConfig.js +301 -0
  117. package/dist/cortex/backupRestore.d.ts +2 -2
  118. package/dist/cortex/backupRestore.js +85 -27
  119. package/dist/cortex/healthCheck.d.ts +2 -2
  120. package/dist/cortex/neuralImport.d.ts +2 -2
  121. package/dist/cortex/neuralImport.js +18 -13
  122. package/dist/cortex/performanceMonitor.d.ts +2 -2
  123. package/dist/critical/model-guardian.d.ts +4 -0
  124. package/dist/critical/model-guardian.js +31 -11
  125. package/dist/demo.d.ts +4 -4
  126. package/dist/demo.js +7 -7
  127. package/dist/distributed/cacheSync.d.ts +112 -0
  128. package/dist/distributed/cacheSync.js +265 -0
  129. package/dist/distributed/coordinator.d.ts +193 -0
  130. package/dist/distributed/coordinator.js +548 -0
  131. package/dist/distributed/httpTransport.d.ts +120 -0
  132. package/dist/distributed/httpTransport.js +446 -0
  133. package/dist/distributed/index.d.ts +8 -0
  134. package/dist/distributed/index.js +5 -0
  135. package/dist/distributed/networkTransport.d.ts +132 -0
  136. package/dist/distributed/networkTransport.js +633 -0
  137. package/dist/distributed/queryPlanner.d.ts +104 -0
  138. package/dist/distributed/queryPlanner.js +327 -0
  139. package/dist/distributed/readWriteSeparation.d.ts +134 -0
  140. package/dist/distributed/readWriteSeparation.js +350 -0
  141. package/dist/distributed/shardManager.d.ts +114 -0
  142. package/dist/distributed/shardManager.js +357 -0
  143. package/dist/distributed/shardMigration.d.ts +110 -0
  144. package/dist/distributed/shardMigration.js +289 -0
  145. package/dist/distributed/storageDiscovery.d.ts +160 -0
  146. package/dist/distributed/storageDiscovery.js +551 -0
  147. package/dist/embeddings/CachedEmbeddings.d.ts +40 -0
  148. package/dist/embeddings/CachedEmbeddings.js +146 -0
  149. package/dist/embeddings/EmbeddingManager.d.ts +102 -0
  150. package/dist/embeddings/EmbeddingManager.js +291 -0
  151. package/dist/embeddings/SingletonModelManager.d.ts +95 -0
  152. package/dist/embeddings/SingletonModelManager.js +220 -0
  153. package/dist/embeddings/index.d.ts +12 -0
  154. package/dist/embeddings/index.js +16 -0
  155. package/dist/embeddings/lightweight-embedder.d.ts +0 -1
  156. package/dist/embeddings/lightweight-embedder.js +4 -12
  157. package/dist/embeddings/model-manager.d.ts +11 -0
  158. package/dist/embeddings/model-manager.js +43 -7
  159. package/dist/embeddings/universal-memory-manager.d.ts +1 -1
  160. package/dist/embeddings/universal-memory-manager.js +27 -67
  161. package/dist/embeddings/worker-embedding.js +4 -8
  162. package/dist/errors/brainyError.d.ts +5 -1
  163. package/dist/errors/brainyError.js +12 -0
  164. package/dist/examples/basicUsage.js +7 -4
  165. package/dist/graph/graphAdjacencyIndex.d.ts +96 -0
  166. package/dist/graph/graphAdjacencyIndex.js +288 -0
  167. package/dist/graph/pathfinding.js +4 -2
  168. package/dist/hnsw/scaledHNSWSystem.js +11 -2
  169. package/dist/importManager.js +8 -5
  170. package/dist/index.d.ts +17 -22
  171. package/dist/index.js +37 -23
  172. package/dist/mcp/brainyMCPAdapter.d.ts +4 -4
  173. package/dist/mcp/brainyMCPAdapter.js +5 -5
  174. package/dist/mcp/brainyMCPService.d.ts +3 -3
  175. package/dist/mcp/brainyMCPService.js +3 -11
  176. package/dist/mcp/mcpAugmentationToolset.js +20 -30
  177. package/dist/neural/embeddedPatterns.d.ts +1 -1
  178. package/dist/neural/embeddedPatterns.js +2 -2
  179. package/dist/neural/entityExtractor.d.ts +65 -0
  180. package/dist/neural/entityExtractor.js +316 -0
  181. package/dist/neural/improvedNeuralAPI.d.ts +357 -0
  182. package/dist/neural/improvedNeuralAPI.js +2628 -0
  183. package/dist/neural/naturalLanguageProcessor.d.ts +155 -10
  184. package/dist/neural/naturalLanguageProcessor.js +941 -66
  185. package/dist/neural/naturalLanguageProcessorStatic.d.ts +2 -2
  186. package/dist/neural/naturalLanguageProcessorStatic.js +3 -3
  187. package/dist/neural/neuralAPI.js +8 -2
  188. package/dist/neural/patternLibrary.d.ts +57 -3
  189. package/dist/neural/patternLibrary.js +348 -13
  190. package/dist/neural/staticPatternMatcher.d.ts +2 -2
  191. package/dist/neural/staticPatternMatcher.js +2 -2
  192. package/dist/neural/types.d.ts +287 -0
  193. package/dist/neural/types.js +24 -0
  194. package/dist/shared/default-augmentations.d.ts +3 -3
  195. package/dist/shared/default-augmentations.js +5 -5
  196. package/dist/storage/adapters/baseStorageAdapter.d.ts +42 -0
  197. package/dist/storage/adapters/fileSystemStorage.d.ts +26 -2
  198. package/dist/storage/adapters/fileSystemStorage.js +218 -15
  199. package/dist/storage/adapters/memoryStorage.d.ts +4 -4
  200. package/dist/storage/adapters/memoryStorage.js +17 -12
  201. package/dist/storage/adapters/opfsStorage.d.ts +2 -2
  202. package/dist/storage/adapters/opfsStorage.js +2 -2
  203. package/dist/storage/adapters/s3CompatibleStorage.d.ts +2 -2
  204. package/dist/storage/adapters/s3CompatibleStorage.js +2 -2
  205. package/dist/storage/backwardCompatibility.d.ts +10 -78
  206. package/dist/storage/backwardCompatibility.js +17 -132
  207. package/dist/storage/baseStorage.d.ts +18 -2
  208. package/dist/storage/baseStorage.js +74 -3
  209. package/dist/storage/cacheManager.js +2 -2
  210. package/dist/storage/readOnlyOptimizations.js +8 -3
  211. package/dist/streaming/pipeline.d.ts +154 -0
  212. package/dist/streaming/pipeline.js +551 -0
  213. package/dist/triple/TripleIntelligence.d.ts +25 -110
  214. package/dist/triple/TripleIntelligence.js +4 -574
  215. package/dist/triple/TripleIntelligenceSystem.d.ts +159 -0
  216. package/dist/triple/TripleIntelligenceSystem.js +519 -0
  217. package/dist/types/apiTypes.d.ts +278 -0
  218. package/dist/types/apiTypes.js +33 -0
  219. package/dist/types/brainy.types.d.ts +308 -0
  220. package/dist/types/brainy.types.js +8 -0
  221. package/dist/types/brainyDataInterface.d.ts +5 -8
  222. package/dist/types/brainyDataInterface.js +2 -2
  223. package/dist/types/graphTypes.js +2 -2
  224. package/dist/utils/brainyTypes.d.ts +217 -0
  225. package/dist/utils/brainyTypes.js +261 -0
  226. package/dist/utils/cacheAutoConfig.d.ts +3 -3
  227. package/dist/utils/embedding.d.ts +9 -4
  228. package/dist/utils/embedding.js +89 -26
  229. package/dist/utils/enhancedLogger.d.ts +104 -0
  230. package/dist/utils/enhancedLogger.js +232 -0
  231. package/dist/utils/hybridModelManager.d.ts +19 -28
  232. package/dist/utils/hybridModelManager.js +36 -200
  233. package/dist/utils/index.d.ts +1 -1
  234. package/dist/utils/index.js +1 -1
  235. package/dist/utils/intelligentTypeMapper.d.ts +60 -0
  236. package/dist/utils/intelligentTypeMapper.js +349 -0
  237. package/dist/utils/metadataIndex.d.ts +118 -1
  238. package/dist/utils/metadataIndex.js +539 -16
  239. package/dist/utils/nodeVersionCheck.d.ts +24 -0
  240. package/dist/utils/nodeVersionCheck.js +65 -0
  241. package/dist/utils/paramValidation.d.ts +39 -0
  242. package/dist/utils/paramValidation.js +192 -0
  243. package/dist/utils/rateLimiter.d.ts +160 -0
  244. package/dist/utils/rateLimiter.js +271 -0
  245. package/dist/utils/statistics.d.ts +4 -4
  246. package/dist/utils/statistics.js +3 -3
  247. package/dist/utils/structuredLogger.d.ts +146 -0
  248. package/dist/utils/structuredLogger.js +394 -0
  249. package/dist/utils/textEncoding.js +2 -1
  250. package/dist/utils/typeValidation.d.ts +59 -0
  251. package/dist/utils/typeValidation.js +374 -0
  252. package/dist/utils/version.js +19 -3
  253. package/package.json +15 -4
  254. package/scripts/download-models.cjs +94 -20
  255. package/dist/augmentations/walAugmentation.d.ts +0 -109
  256. package/dist/augmentations/walAugmentation.js +0 -516
  257. package/dist/chat/BrainyChat.d.ts +0 -121
  258. package/dist/chat/BrainyChat.js +0 -396
  259. package/dist/chat/ChatCLI.d.ts +0 -61
  260. package/dist/chat/ChatCLI.js +0 -351
@@ -0,0 +1,328 @@
1
+ /**
2
+ * Storage Configuration Auto-Detection
3
+ * Intelligently selects storage based on environment and available services
4
+ */
5
+ import { isBrowser, isNode } from '../utils/environment.js';
6
+ /**
7
+ * Low-level storage implementation types
8
+ */
9
+ export var StorageType;
10
+ (function (StorageType) {
11
+ StorageType["MEMORY"] = "memory";
12
+ StorageType["FILESYSTEM"] = "filesystem";
13
+ StorageType["OPFS"] = "opfs";
14
+ StorageType["S3"] = "s3";
15
+ StorageType["GCS"] = "gcs";
16
+ StorageType["R2"] = "r2";
17
+ })(StorageType || (StorageType = {}));
18
+ /**
19
+ * High-level storage presets (maps to StorageType)
20
+ */
21
+ export var StoragePreset;
22
+ (function (StoragePreset) {
23
+ StoragePreset["AUTO"] = "auto";
24
+ StoragePreset["MEMORY"] = "memory";
25
+ StoragePreset["DISK"] = "disk";
26
+ StoragePreset["CLOUD"] = "cloud";
27
+ })(StoragePreset || (StoragePreset = {}));
28
+ /**
29
+ * Auto-detect the best storage configuration
30
+ * @param override - Manual override: specific type or preset
31
+ */
32
+ export async function autoDetectStorage(override) {
33
+ // Handle direct storage config object
34
+ if (override && typeof override === 'object') {
35
+ return {
36
+ type: override.type || 'memory',
37
+ config: override,
38
+ reason: 'Manually configured storage',
39
+ autoSelected: false
40
+ };
41
+ }
42
+ // Handle storage type override (enum values or strings)
43
+ if (override && Object.values(StorageType).includes(override)) {
44
+ return {
45
+ type: override,
46
+ config: override,
47
+ reason: `Manually specified: ${override}`,
48
+ autoSelected: false
49
+ };
50
+ }
51
+ // Handle presets (both enum and string values)
52
+ if (override === StoragePreset.MEMORY || override === 'memory') {
53
+ return {
54
+ type: StorageType.MEMORY,
55
+ config: StorageType.MEMORY,
56
+ reason: 'Preset: memory storage',
57
+ autoSelected: false
58
+ };
59
+ }
60
+ if (override === StoragePreset.DISK || override === 'disk') {
61
+ const diskType = isBrowser() ? StorageType.OPFS : StorageType.FILESYSTEM;
62
+ return {
63
+ type: diskType,
64
+ config: diskType,
65
+ reason: `Preset: disk storage (${diskType})`,
66
+ autoSelected: false
67
+ };
68
+ }
69
+ if (override === StoragePreset.CLOUD || override === 'cloud') {
70
+ const cloudStorage = await detectCloudStorage();
71
+ if (cloudStorage) {
72
+ return {
73
+ ...cloudStorage,
74
+ reason: `Preset: cloud storage (${cloudStorage.type})`,
75
+ autoSelected: false
76
+ };
77
+ }
78
+ // Fallback to disk if no cloud storage detected
79
+ const diskType = isBrowser() ? StorageType.OPFS : StorageType.FILESYSTEM;
80
+ return {
81
+ type: diskType,
82
+ config: diskType,
83
+ reason: 'Preset: cloud (none detected, using disk)',
84
+ autoSelected: false
85
+ };
86
+ }
87
+ // Auto-detection logic
88
+ return await autoDetectBestStorage();
89
+ }
90
+ /**
91
+ * Automatically detect the best storage option
92
+ */
93
+ async function autoDetectBestStorage() {
94
+ // Check for cloud storage first (highest priority in production)
95
+ const cloudStorage = await detectCloudStorage();
96
+ if (cloudStorage && process.env.NODE_ENV === 'production') {
97
+ return {
98
+ ...cloudStorage,
99
+ reason: `Auto-detected ${cloudStorage.type} in production`,
100
+ autoSelected: true
101
+ };
102
+ }
103
+ // Browser environment
104
+ if (isBrowser()) {
105
+ // Check for OPFS support
106
+ if (await hasOPFSSupport()) {
107
+ return {
108
+ type: StorageType.OPFS,
109
+ config: { requestPersistentStorage: true },
110
+ reason: 'Browser with OPFS support detected',
111
+ autoSelected: true
112
+ };
113
+ }
114
+ // Fallback to memory for browsers without OPFS
115
+ return {
116
+ type: StorageType.MEMORY,
117
+ config: StorageType.MEMORY,
118
+ reason: 'Browser without OPFS - using memory',
119
+ autoSelected: true
120
+ };
121
+ }
122
+ // Serverless environment - prefer memory or cloud
123
+ if (isServerlessEnvironment()) {
124
+ if (cloudStorage) {
125
+ return {
126
+ ...cloudStorage,
127
+ reason: `Serverless with ${cloudStorage.type} detected`,
128
+ autoSelected: true
129
+ };
130
+ }
131
+ return {
132
+ type: StorageType.MEMORY,
133
+ config: StorageType.MEMORY,
134
+ reason: 'Serverless environment - using memory',
135
+ autoSelected: true
136
+ };
137
+ }
138
+ // Node.js environment - use filesystem
139
+ if (isNode()) {
140
+ const dataPath = await findBestDataPath();
141
+ return {
142
+ type: StorageType.FILESYSTEM,
143
+ config: StorageType.FILESYSTEM,
144
+ reason: `Node.js environment - using filesystem at ${dataPath}`,
145
+ autoSelected: true
146
+ };
147
+ }
148
+ // Fallback to memory
149
+ return {
150
+ type: StorageType.MEMORY,
151
+ config: StorageType.MEMORY,
152
+ reason: 'Default fallback - using memory',
153
+ autoSelected: true
154
+ };
155
+ }
156
+ /**
157
+ * Detect cloud storage from environment variables
158
+ */
159
+ async function detectCloudStorage() {
160
+ // AWS S3 Detection
161
+ if (hasAWSConfig()) {
162
+ return {
163
+ type: StorageType.S3,
164
+ config: {
165
+ s3Storage: {
166
+ bucketName: process.env.AWS_BUCKET || process.env.S3_BUCKET_NAME || 'brainy-data',
167
+ region: process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION || 'us-east-1',
168
+ // Credentials will be picked up by AWS SDK automatically
169
+ }
170
+ }
171
+ };
172
+ }
173
+ // Google Cloud Storage Detection
174
+ if (hasGCPConfig()) {
175
+ return {
176
+ type: StorageType.GCS,
177
+ config: {
178
+ gcsStorage: {
179
+ bucketName: process.env.GCS_BUCKET || process.env.GOOGLE_STORAGE_BUCKET || 'brainy-data',
180
+ // Credentials will be picked up by GCP SDK automatically
181
+ }
182
+ }
183
+ };
184
+ }
185
+ // Cloudflare R2 Detection
186
+ if (hasR2Config()) {
187
+ return {
188
+ type: StorageType.R2,
189
+ config: {
190
+ r2Storage: {
191
+ bucketName: process.env.R2_BUCKET || 'brainy-data',
192
+ accountId: process.env.CLOUDFLARE_ACCOUNT_ID,
193
+ accessKeyId: process.env.R2_ACCESS_KEY_ID,
194
+ secretAccessKey: process.env.R2_SECRET_ACCESS_KEY
195
+ }
196
+ }
197
+ };
198
+ }
199
+ return null;
200
+ }
201
+ /**
202
+ * Check if AWS S3 is configured
203
+ */
204
+ function hasAWSConfig() {
205
+ return !!(
206
+ // Explicit S3 bucket
207
+ process.env.AWS_BUCKET ||
208
+ process.env.S3_BUCKET_NAME ||
209
+ // AWS credentials (SDK will find them)
210
+ process.env.AWS_ACCESS_KEY_ID ||
211
+ process.env.AWS_PROFILE ||
212
+ // AWS environment indicators
213
+ process.env.AWS_EXECUTION_ENV ||
214
+ process.env.AWS_LAMBDA_FUNCTION_NAME ||
215
+ process.env.ECS_CONTAINER_METADATA_URI);
216
+ }
217
+ /**
218
+ * Check if Google Cloud Storage is configured
219
+ */
220
+ function hasGCPConfig() {
221
+ return !!(
222
+ // Explicit GCS bucket
223
+ process.env.GCS_BUCKET ||
224
+ process.env.GOOGLE_STORAGE_BUCKET ||
225
+ // GCP credentials
226
+ process.env.GOOGLE_APPLICATION_CREDENTIALS ||
227
+ // GCP environment indicators
228
+ process.env.GOOGLE_CLOUD_PROJECT ||
229
+ process.env.K_SERVICE ||
230
+ process.env.GAE_SERVICE);
231
+ }
232
+ /**
233
+ * Check if Cloudflare R2 is configured
234
+ */
235
+ function hasR2Config() {
236
+ return !!(process.env.R2_BUCKET ||
237
+ (process.env.CLOUDFLARE_ACCOUNT_ID && process.env.R2_ACCESS_KEY_ID));
238
+ }
239
+ /**
240
+ * Check if running in serverless environment
241
+ */
242
+ function isServerlessEnvironment() {
243
+ if (!isNode())
244
+ return false;
245
+ return !!(process.env.AWS_LAMBDA_FUNCTION_NAME ||
246
+ process.env.VERCEL ||
247
+ process.env.NETLIFY ||
248
+ process.env.CLOUDFLARE_WORKERS ||
249
+ process.env.FUNCTIONS_WORKER_RUNTIME ||
250
+ process.env.K_SERVICE ||
251
+ process.env.RAILWAY_ENVIRONMENT ||
252
+ process.env.FLY_APP_NAME);
253
+ }
254
+ /**
255
+ * Check for OPFS support in browser
256
+ */
257
+ async function hasOPFSSupport() {
258
+ if (!isBrowser())
259
+ return false;
260
+ try {
261
+ return 'storage' in navigator &&
262
+ 'getDirectory' in navigator.storage;
263
+ }
264
+ catch {
265
+ return false;
266
+ }
267
+ }
268
+ /**
269
+ * Find the best path for filesystem storage
270
+ */
271
+ async function findBestDataPath() {
272
+ if (!isNode())
273
+ return './brainy-data';
274
+ const homeDir = process.env.HOME || process.env.USERPROFILE || '~';
275
+ const tempDir = process.env.TMPDIR || process.env.TEMP || '/tmp';
276
+ const candidates = [
277
+ // User-specified path
278
+ process.env.BRAINY_DATA_PATH,
279
+ // Current directory
280
+ './brainy-data',
281
+ // Home directory
282
+ `${homeDir}/.brainy/data`,
283
+ // Temp directory (last resort)
284
+ `${tempDir}/brainy-data`
285
+ ].filter(Boolean);
286
+ // Find first writable directory
287
+ for (const candidate of candidates) {
288
+ if (await isWritable(candidate)) {
289
+ return candidate;
290
+ }
291
+ }
292
+ // Default fallback
293
+ return candidates[1]; // ./brainy-data
294
+ }
295
+ /**
296
+ * Check if a directory is writable
297
+ */
298
+ async function isWritable(dirPath) {
299
+ if (!isNode())
300
+ return false;
301
+ try {
302
+ // Dynamic import fs for Node.js
303
+ const { promises: fs } = await import('fs');
304
+ const path = await import('path');
305
+ // Try to create directory if it doesn't exist
306
+ await fs.mkdir(dirPath, { recursive: true });
307
+ // Try to write a test file
308
+ const testFile = path.join(dirPath, '.write-test');
309
+ await fs.writeFile(testFile, 'test');
310
+ await fs.unlink(testFile);
311
+ return true;
312
+ }
313
+ catch {
314
+ return false;
315
+ }
316
+ }
317
+ // Legacy getStorageConfig function removed - now using simple string types
318
+ /**
319
+ * Log storage configuration decision
320
+ */
321
+ export function logStorageConfig(config, verbose = false) {
322
+ if (!verbose && process.env.NODE_ENV === 'production') {
323
+ return; // Silent in production unless verbose
324
+ }
325
+ const icon = config.autoSelected ? 'šŸ¤–' : 'šŸ‘¤';
326
+ console.log(`${icon} Storage: ${config.type.toUpperCase()} - ${config.reason}`);
327
+ }
328
+ //# sourceMappingURL=storageAutoConfig.js.map
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Zero-Configuration System for Brainy
3
+ * Provides intelligent defaults while preserving full control
4
+ */
5
+ import { ModelPrecision, ModelPreset } from './modelAutoConfig.js';
6
+ import { StorageType, StoragePreset } from './storageAutoConfig.js';
7
+ /**
8
+ * Simplified configuration interface
9
+ * Everything is optional - zero config by default!
10
+ */
11
+ export interface BrainyZeroConfig {
12
+ /**
13
+ * Configuration preset for common scenarios
14
+ * - 'production': Optimized for production (disk storage, auto model, default features)
15
+ * - 'development': Optimized for development (memory storage, fp32, verbose logging)
16
+ * - 'minimal': Minimal footprint (memory storage, q8, minimal features)
17
+ * - 'zero': True zero config (all auto-detected)
18
+ * - 'writer': Write-only instance for distributed setups (no index loading)
19
+ * - 'reader': Read-only instance for distributed setups (no write operations)
20
+ */
21
+ mode?: 'production' | 'development' | 'minimal' | 'zero' | 'writer' | 'reader';
22
+ /**
23
+ * Model precision configuration
24
+ * - 'fp32': Full precision (best quality, larger size)
25
+ * - 'q8': Quantized 8-bit (smaller size, slightly lower quality)
26
+ * - 'fast': Alias for fp32
27
+ * - 'small': Alias for q8
28
+ * - 'auto': Auto-detect based on environment (default)
29
+ */
30
+ model?: ModelPrecision | ModelPreset;
31
+ /**
32
+ * Storage configuration
33
+ * - 'memory': In-memory only (no persistence)
34
+ * - 'disk': Local disk (filesystem or OPFS)
35
+ * - 'cloud': Cloud storage (S3/GCS/R2 if configured)
36
+ * - 'auto': Auto-detect best option (default)
37
+ * - Object: Custom storage configuration
38
+ */
39
+ storage?: StorageType | StoragePreset | any;
40
+ /**
41
+ * Feature set configuration
42
+ * - 'minimal': Core features only (fastest startup)
43
+ * - 'default': Standard features (balanced)
44
+ * - 'full': All features enabled (most capable)
45
+ * - Array: Specific features to enable
46
+ */
47
+ features?: 'minimal' | 'default' | 'full' | string[];
48
+ /**
49
+ * Logging verbosity
50
+ * - true: Show configuration decisions and progress
51
+ * - false: Silent operation (default in production)
52
+ */
53
+ verbose?: boolean;
54
+ /**
55
+ * Advanced configuration (escape hatch for power users)
56
+ * Any additional configuration can be passed here
57
+ */
58
+ advanced?: any;
59
+ }
60
+ /**
61
+ * Process zero-config input into full configuration
62
+ */
63
+ export declare function processZeroConfig(input?: string | BrainyZeroConfig): Promise<any>;
64
+ /**
65
+ * Create embedding function with specified precision
66
+ * This ensures the model precision is respected
67
+ */
68
+ export declare function createEmbeddingFunctionWithPrecision(precision: ModelPrecision): Promise<any>;
@@ -0,0 +1,301 @@
1
+ /**
2
+ * Zero-Configuration System for Brainy
3
+ * Provides intelligent defaults while preserving full control
4
+ */
5
+ import { autoSelectModelPrecision, getModelPath, shouldAutoDownloadModels } from './modelAutoConfig.js';
6
+ import { autoDetectStorage } from './storageAutoConfig.js';
7
+ import { AutoConfiguration } from '../utils/autoConfiguration.js';
8
+ /**
9
+ * Configuration presets for common scenarios
10
+ */
11
+ const PRESETS = {
12
+ production: {
13
+ storage: 'disk',
14
+ model: 'auto',
15
+ features: 'default',
16
+ verbose: false
17
+ },
18
+ development: {
19
+ storage: 'memory',
20
+ model: 'q8', // Q8 is now the default for all presets
21
+ features: 'full',
22
+ verbose: true
23
+ },
24
+ minimal: {
25
+ storage: 'memory',
26
+ model: 'q8',
27
+ features: 'minimal',
28
+ verbose: false
29
+ },
30
+ zero: {
31
+ storage: 'auto',
32
+ model: 'auto',
33
+ features: 'default',
34
+ verbose: false
35
+ },
36
+ writer: {
37
+ storage: 'auto',
38
+ model: 'auto',
39
+ features: 'minimal',
40
+ verbose: false,
41
+ // Writer-specific settings
42
+ distributed: true,
43
+ role: 'writer',
44
+ writeOnly: true,
45
+ allowDirectReads: true // Allow deduplication checks
46
+ },
47
+ reader: {
48
+ storage: 'auto',
49
+ model: 'auto',
50
+ features: 'default',
51
+ verbose: false,
52
+ // Reader-specific settings
53
+ distributed: true,
54
+ role: 'reader',
55
+ readOnly: true,
56
+ lazyLoadInReadOnlyMode: true // Optimize for search
57
+ }
58
+ };
59
+ /**
60
+ * Feature sets configuration
61
+ */
62
+ const FEATURE_SETS = {
63
+ minimal: [
64
+ 'core',
65
+ 'search',
66
+ 'storage'
67
+ ],
68
+ default: [
69
+ 'core',
70
+ 'search',
71
+ 'storage',
72
+ 'cache',
73
+ 'metadata-index',
74
+ 'batch-processing',
75
+ 'entity-registry',
76
+ 'request-deduplicator'
77
+ ],
78
+ full: [
79
+ 'core',
80
+ 'search',
81
+ 'storage',
82
+ 'cache',
83
+ 'metadata-index',
84
+ 'batch-processing',
85
+ 'entity-registry',
86
+ 'request-deduplicator',
87
+ 'connection-pool',
88
+ 'wal',
89
+ 'monitoring',
90
+ 'metrics',
91
+ 'intelligent-verb-scoring',
92
+ 'triple-intelligence',
93
+ 'neural-api'
94
+ ]
95
+ };
96
+ /**
97
+ * Process zero-config input into full configuration
98
+ */
99
+ export async function processZeroConfig(input) {
100
+ let config = {};
101
+ // Handle string shorthand (preset name)
102
+ if (typeof input === 'string') {
103
+ if (input in PRESETS) {
104
+ config = { mode: input };
105
+ }
106
+ else {
107
+ throw new Error(`Unknown preset: ${input}. Valid presets: ${Object.keys(PRESETS).join(', ')}`);
108
+ }
109
+ }
110
+ else if (input) {
111
+ config = input;
112
+ }
113
+ // Apply preset if specified
114
+ if (config.mode && config.mode in PRESETS) {
115
+ const preset = PRESETS[config.mode];
116
+ config = {
117
+ ...preset,
118
+ ...config,
119
+ // Preserve explicit overrides
120
+ model: config.model ?? preset.model,
121
+ storage: config.storage ?? preset.storage,
122
+ features: config.features ?? preset.features,
123
+ verbose: config.verbose ?? preset.verbose
124
+ };
125
+ }
126
+ // Auto-detect environment if not in preset mode
127
+ const environment = detectEnvironmentMode();
128
+ // Process model configuration
129
+ const modelConfig = autoSelectModelPrecision(config.model);
130
+ // Process storage configuration
131
+ const storageConfig = await autoDetectStorage(config.storage);
132
+ // Process features configuration
133
+ const features = processFeatures(config.features);
134
+ // Get auto-configuration recommendations
135
+ const autoConfig = await AutoConfiguration.getInstance().detectAndConfigure({
136
+ expectedDataSize: estimateDataSize(environment),
137
+ s3Available: storageConfig.type === 's3',
138
+ memoryBudget: undefined // Let it auto-detect
139
+ });
140
+ // Determine verbosity
141
+ const verbose = config.verbose ?? (process.env.NODE_ENV === 'development');
142
+ // Log configuration decisions if verbose
143
+ if (verbose) {
144
+ logConfigurationSummary({
145
+ mode: config.mode || 'auto',
146
+ model: modelConfig,
147
+ storage: storageConfig,
148
+ features: features,
149
+ environment: environment,
150
+ autoConfig: autoConfig
151
+ });
152
+ }
153
+ // Build final configuration
154
+ const finalConfig = {
155
+ // Model configuration
156
+ embeddingFunction: undefined, // Will be created with correct precision
157
+ embeddingOptions: {
158
+ precision: modelConfig.precision,
159
+ modelPath: getModelPath(),
160
+ allowRemoteDownload: shouldAutoDownloadModels()
161
+ },
162
+ // Storage configuration
163
+ storage: storageConfig.config,
164
+ storageType: storageConfig.type,
165
+ // HNSW configuration from auto-config
166
+ hnsw: {
167
+ M: autoConfig.recommendedConfig.enablePartitioning ? 32 : 16,
168
+ efConstruction: autoConfig.recommendedConfig.enablePartitioning ? 400 : 200,
169
+ maxDatasetSize: autoConfig.recommendedConfig.expectedDatasetSize,
170
+ partitioning: autoConfig.recommendedConfig.enablePartitioning,
171
+ maxNodesPerPartition: autoConfig.recommendedConfig.maxNodesPerPartition
172
+ },
173
+ // Cache configuration from auto-config
174
+ cache: {
175
+ autoTune: true,
176
+ hotCacheMaxSize: Math.floor(autoConfig.recommendedConfig.maxMemoryUsage / (1024 * 1024 * 10)), // 10% of memory budget
177
+ batchSize: autoConfig.recommendedConfig.enablePartitioning ? 100 : 50
178
+ },
179
+ // Features configuration
180
+ enabledFeatures: features,
181
+ // Metadata index configuration
182
+ metadataIndex: features.includes('metadata-index') ? {
183
+ enabled: true,
184
+ autoRebuild: true
185
+ } : undefined,
186
+ // Intelligent verb scoring
187
+ intelligentVerbScoring: features.includes('intelligent-verb-scoring') ? {
188
+ enabled: true
189
+ } : undefined,
190
+ // Logging configuration
191
+ logging: {
192
+ verbose: verbose
193
+ },
194
+ // Performance flags from auto-config
195
+ optimizations: autoConfig.optimizationFlags,
196
+ // Advanced overrides (if any)
197
+ ...config.advanced
198
+ };
199
+ // Apply distributed preset settings if applicable
200
+ if (config.mode === 'writer' || config.mode === 'reader') {
201
+ const presetSettings = PRESETS[config.mode]; // Cast to any since we know these presets have additional properties
202
+ // Apply distributed-specific settings
203
+ finalConfig.distributed = presetSettings.distributed;
204
+ finalConfig.readOnly = presetSettings.readOnly || false;
205
+ finalConfig.writeOnly = presetSettings.writeOnly || false;
206
+ finalConfig.allowDirectReads = presetSettings.allowDirectReads || false;
207
+ finalConfig.lazyLoadInReadOnlyMode = presetSettings.lazyLoadInReadOnlyMode || false;
208
+ // Set distributed role in distributed config
209
+ if (finalConfig.distributed) {
210
+ finalConfig.distributed = {
211
+ enabled: true,
212
+ role: presetSettings.role
213
+ };
214
+ }
215
+ // Log distributed mode if verbose
216
+ if (verbose) {
217
+ console.log(`šŸ“” Distributed mode: ${config.mode.toUpperCase()}`);
218
+ console.log(` Role: ${presetSettings.role}`);
219
+ console.log(` Read-only: ${finalConfig.readOnly}`);
220
+ console.log(` Write-only: ${finalConfig.writeOnly}`);
221
+ }
222
+ }
223
+ return finalConfig;
224
+ }
225
+ /**
226
+ * Detect environment mode if not specified
227
+ */
228
+ function detectEnvironmentMode() {
229
+ if (process.env.NODE_ENV === 'production')
230
+ return 'production';
231
+ if (process.env.NODE_ENV === 'development')
232
+ return 'development';
233
+ if (process.env.NODE_ENV === 'test')
234
+ return 'development';
235
+ // Check for CI environments
236
+ if (process.env.CI || process.env.GITHUB_ACTIONS)
237
+ return 'production';
238
+ // Check for production indicators
239
+ if (process.env.VERCEL_ENV === 'production' ||
240
+ process.env.NETLIFY_ENV === 'production' ||
241
+ process.env.RAILWAY_ENVIRONMENT === 'production') {
242
+ return 'production';
243
+ }
244
+ return 'unknown';
245
+ }
246
+ /**
247
+ * Process features configuration
248
+ */
249
+ function processFeatures(features) {
250
+ if (Array.isArray(features)) {
251
+ return features;
252
+ }
253
+ if (features && features in FEATURE_SETS) {
254
+ return FEATURE_SETS[features];
255
+ }
256
+ // Default based on environment
257
+ const env = detectEnvironmentMode();
258
+ if (env === 'production')
259
+ return FEATURE_SETS.default;
260
+ if (env === 'development')
261
+ return FEATURE_SETS.full;
262
+ return FEATURE_SETS.default;
263
+ }
264
+ /**
265
+ * Estimate dataset size based on environment
266
+ */
267
+ function estimateDataSize(environment) {
268
+ switch (environment) {
269
+ case 'production': return 100000;
270
+ case 'development': return 10000;
271
+ default: return 50000;
272
+ }
273
+ }
274
+ /**
275
+ * Log configuration summary
276
+ */
277
+ function logConfigurationSummary(config) {
278
+ console.log('\n🧠 Brainy Zero-Config Summary');
279
+ console.log('================================');
280
+ console.log(`Mode: ${config.mode}`);
281
+ console.log(`Environment: ${config.environment}`);
282
+ console.log(`Model: ${config.model.precision.toUpperCase()} (${config.model.reason})`);
283
+ console.log(`Storage: ${config.storage.type.toUpperCase()} (${config.storage.reason})`);
284
+ console.log(`Features: ${config.features.length} enabled`);
285
+ console.log(`Memory Budget: ${Math.floor(config.autoConfig.recommendedConfig.maxMemoryUsage / (1024 * 1024))}MB`);
286
+ console.log(`Expected Dataset: ${config.autoConfig.recommendedConfig.expectedDatasetSize.toLocaleString()} items`);
287
+ console.log('================================\n');
288
+ }
289
+ /**
290
+ * Create embedding function with specified precision
291
+ * This ensures the model precision is respected
292
+ */
293
+ export async function createEmbeddingFunctionWithPrecision(precision) {
294
+ const { createEmbeddingFunction } = await import('../utils/embedding.js');
295
+ // Create embedding function with specified precision
296
+ return createEmbeddingFunction({
297
+ precision: precision,
298
+ verbose: false // Silent by default in zero-config
299
+ });
300
+ }
301
+ //# sourceMappingURL=zeroConfig.js.map