@soulcraft/brainy 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/CHANGELOG.md +53 -3
  2. package/README.md +427 -111
  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 +277 -0
  90. package/dist/brainy.js +1241 -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/config/distributedPresets-new.d.ts +118 -0
  96. package/dist/config/distributedPresets-new.js +318 -0
  97. package/dist/config/distributedPresets.d.ts +118 -0
  98. package/dist/config/distributedPresets.js +318 -0
  99. package/dist/config/extensibleConfig.d.ts +99 -0
  100. package/dist/config/extensibleConfig.js +268 -0
  101. package/dist/config/index.d.ts +17 -0
  102. package/dist/config/index.js +35 -0
  103. package/dist/config/modelAutoConfig.d.ts +32 -0
  104. package/dist/config/modelAutoConfig.js +139 -0
  105. package/dist/config/modelPrecisionManager.d.ts +42 -0
  106. package/dist/config/modelPrecisionManager.js +98 -0
  107. package/dist/config/sharedConfigManager.d.ts +67 -0
  108. package/dist/config/sharedConfigManager.js +215 -0
  109. package/dist/config/storageAutoConfig.d.ts +41 -0
  110. package/dist/config/storageAutoConfig.js +328 -0
  111. package/dist/config/zeroConfig.d.ts +68 -0
  112. package/dist/config/zeroConfig.js +301 -0
  113. package/dist/cortex/backupRestore.d.ts +2 -2
  114. package/dist/cortex/backupRestore.js +85 -27
  115. package/dist/cortex/healthCheck.d.ts +2 -2
  116. package/dist/cortex/neuralImport.d.ts +2 -2
  117. package/dist/cortex/neuralImport.js +18 -13
  118. package/dist/cortex/performanceMonitor.d.ts +2 -2
  119. package/dist/critical/model-guardian.d.ts +4 -0
  120. package/dist/critical/model-guardian.js +31 -11
  121. package/dist/demo.d.ts +4 -4
  122. package/dist/demo.js +7 -7
  123. package/dist/distributed/cacheSync.d.ts +112 -0
  124. package/dist/distributed/cacheSync.js +265 -0
  125. package/dist/distributed/coordinator.d.ts +193 -0
  126. package/dist/distributed/coordinator.js +548 -0
  127. package/dist/distributed/httpTransport.d.ts +120 -0
  128. package/dist/distributed/httpTransport.js +446 -0
  129. package/dist/distributed/index.d.ts +8 -0
  130. package/dist/distributed/index.js +5 -0
  131. package/dist/distributed/networkTransport.d.ts +132 -0
  132. package/dist/distributed/networkTransport.js +633 -0
  133. package/dist/distributed/queryPlanner.d.ts +104 -0
  134. package/dist/distributed/queryPlanner.js +327 -0
  135. package/dist/distributed/readWriteSeparation.d.ts +134 -0
  136. package/dist/distributed/readWriteSeparation.js +350 -0
  137. package/dist/distributed/shardManager.d.ts +114 -0
  138. package/dist/distributed/shardManager.js +357 -0
  139. package/dist/distributed/shardMigration.d.ts +110 -0
  140. package/dist/distributed/shardMigration.js +289 -0
  141. package/dist/distributed/storageDiscovery.d.ts +160 -0
  142. package/dist/distributed/storageDiscovery.js +551 -0
  143. package/dist/embeddings/CachedEmbeddings.d.ts +40 -0
  144. package/dist/embeddings/CachedEmbeddings.js +146 -0
  145. package/dist/embeddings/EmbeddingManager.d.ts +102 -0
  146. package/dist/embeddings/EmbeddingManager.js +291 -0
  147. package/dist/embeddings/SingletonModelManager.d.ts +95 -0
  148. package/dist/embeddings/SingletonModelManager.js +220 -0
  149. package/dist/embeddings/index.d.ts +12 -0
  150. package/dist/embeddings/index.js +16 -0
  151. package/dist/embeddings/lightweight-embedder.d.ts +0 -1
  152. package/dist/embeddings/lightweight-embedder.js +4 -12
  153. package/dist/embeddings/model-manager.d.ts +11 -0
  154. package/dist/embeddings/model-manager.js +43 -7
  155. package/dist/embeddings/universal-memory-manager.d.ts +1 -1
  156. package/dist/embeddings/universal-memory-manager.js +27 -67
  157. package/dist/embeddings/worker-embedding.js +4 -8
  158. package/dist/errors/brainyError.d.ts +5 -1
  159. package/dist/errors/brainyError.js +12 -0
  160. package/dist/examples/basicUsage.js +7 -4
  161. package/dist/graph/graphAdjacencyIndex.d.ts +96 -0
  162. package/dist/graph/graphAdjacencyIndex.js +288 -0
  163. package/dist/graph/pathfinding.js +4 -2
  164. package/dist/hnsw/scaledHNSWSystem.js +11 -2
  165. package/dist/importManager.js +8 -5
  166. package/dist/index.d.ts +17 -22
  167. package/dist/index.js +37 -23
  168. package/dist/mcp/brainyMCPAdapter.d.ts +4 -4
  169. package/dist/mcp/brainyMCPAdapter.js +5 -5
  170. package/dist/mcp/brainyMCPService.d.ts +3 -3
  171. package/dist/mcp/brainyMCPService.js +3 -11
  172. package/dist/mcp/mcpAugmentationToolset.js +20 -30
  173. package/dist/neural/embeddedPatterns.d.ts +1 -1
  174. package/dist/neural/embeddedPatterns.js +2 -2
  175. package/dist/neural/entityExtractor.d.ts +65 -0
  176. package/dist/neural/entityExtractor.js +316 -0
  177. package/dist/neural/improvedNeuralAPI.d.ts +357 -0
  178. package/dist/neural/improvedNeuralAPI.js +2628 -0
  179. package/dist/neural/naturalLanguageProcessor.d.ts +155 -10
  180. package/dist/neural/naturalLanguageProcessor.js +941 -66
  181. package/dist/neural/naturalLanguageProcessorStatic.d.ts +2 -2
  182. package/dist/neural/naturalLanguageProcessorStatic.js +3 -3
  183. package/dist/neural/neuralAPI.js +8 -2
  184. package/dist/neural/patternLibrary.d.ts +57 -3
  185. package/dist/neural/patternLibrary.js +348 -13
  186. package/dist/neural/staticPatternMatcher.d.ts +2 -2
  187. package/dist/neural/staticPatternMatcher.js +2 -2
  188. package/dist/neural/types.d.ts +287 -0
  189. package/dist/neural/types.js +24 -0
  190. package/dist/shared/default-augmentations.d.ts +3 -3
  191. package/dist/shared/default-augmentations.js +5 -5
  192. package/dist/storage/adapters/baseStorageAdapter.d.ts +42 -0
  193. package/dist/storage/adapters/fileSystemStorage.d.ts +26 -2
  194. package/dist/storage/adapters/fileSystemStorage.js +218 -15
  195. package/dist/storage/adapters/memoryStorage.d.ts +4 -4
  196. package/dist/storage/adapters/memoryStorage.js +17 -12
  197. package/dist/storage/adapters/opfsStorage.d.ts +2 -2
  198. package/dist/storage/adapters/opfsStorage.js +2 -2
  199. package/dist/storage/adapters/s3CompatibleStorage.d.ts +2 -2
  200. package/dist/storage/adapters/s3CompatibleStorage.js +2 -2
  201. package/dist/storage/backwardCompatibility.d.ts +10 -78
  202. package/dist/storage/backwardCompatibility.js +17 -132
  203. package/dist/storage/baseStorage.d.ts +18 -2
  204. package/dist/storage/baseStorage.js +74 -3
  205. package/dist/storage/cacheManager.js +2 -2
  206. package/dist/storage/readOnlyOptimizations.js +8 -3
  207. package/dist/streaming/pipeline.d.ts +154 -0
  208. package/dist/streaming/pipeline.js +551 -0
  209. package/dist/triple/TripleIntelligence.d.ts +25 -110
  210. package/dist/triple/TripleIntelligence.js +4 -574
  211. package/dist/triple/TripleIntelligenceSystem.d.ts +159 -0
  212. package/dist/triple/TripleIntelligenceSystem.js +519 -0
  213. package/dist/types/apiTypes.d.ts +278 -0
  214. package/dist/types/apiTypes.js +33 -0
  215. package/dist/types/brainy.types.d.ts +308 -0
  216. package/dist/types/brainy.types.js +8 -0
  217. package/dist/types/brainyDataInterface.d.ts +5 -8
  218. package/dist/types/brainyDataInterface.js +2 -2
  219. package/dist/types/graphTypes.js +2 -2
  220. package/dist/universal/crypto.d.ts +11 -1
  221. package/dist/universal/crypto.js +24 -93
  222. package/dist/universal/events.d.ts +3 -2
  223. package/dist/universal/events.js +6 -75
  224. package/dist/universal/fs.d.ts +2 -3
  225. package/dist/universal/fs.js +5 -211
  226. package/dist/universal/path.d.ts +3 -2
  227. package/dist/universal/path.js +22 -78
  228. package/dist/universal/uuid.d.ts +1 -1
  229. package/dist/universal/uuid.js +1 -1
  230. package/dist/utils/brainyTypes.d.ts +217 -0
  231. package/dist/utils/brainyTypes.js +261 -0
  232. package/dist/utils/cacheAutoConfig.d.ts +3 -3
  233. package/dist/utils/embedding.d.ts +9 -4
  234. package/dist/utils/embedding.js +89 -26
  235. package/dist/utils/enhancedLogger.d.ts +104 -0
  236. package/dist/utils/enhancedLogger.js +232 -0
  237. package/dist/utils/hybridModelManager.d.ts +19 -28
  238. package/dist/utils/hybridModelManager.js +36 -200
  239. package/dist/utils/index.d.ts +1 -1
  240. package/dist/utils/index.js +1 -1
  241. package/dist/utils/intelligentTypeMapper.d.ts +60 -0
  242. package/dist/utils/intelligentTypeMapper.js +349 -0
  243. package/dist/utils/metadataIndex.d.ts +118 -1
  244. package/dist/utils/metadataIndex.js +539 -16
  245. package/dist/utils/nodeVersionCheck.d.ts +24 -0
  246. package/dist/utils/nodeVersionCheck.js +65 -0
  247. package/dist/utils/paramValidation.d.ts +39 -0
  248. package/dist/utils/paramValidation.js +192 -0
  249. package/dist/utils/rateLimiter.d.ts +160 -0
  250. package/dist/utils/rateLimiter.js +271 -0
  251. package/dist/utils/statistics.d.ts +4 -4
  252. package/dist/utils/statistics.js +3 -3
  253. package/dist/utils/structuredLogger.d.ts +146 -0
  254. package/dist/utils/structuredLogger.js +394 -0
  255. package/dist/utils/textEncoding.js +2 -1
  256. package/dist/utils/typeValidation.d.ts +59 -0
  257. package/dist/utils/typeValidation.js +374 -0
  258. package/dist/utils/version.js +19 -3
  259. package/package.json +15 -17
  260. package/scripts/download-models.cjs +94 -20
  261. package/dist/augmentations/walAugmentation.d.ts +0 -109
  262. package/dist/augmentations/walAugmentation.js +0 -516
  263. package/dist/browserFramework.d.ts +0 -15
  264. package/dist/browserFramework.js +0 -31
  265. package/dist/browserFramework.minimal.d.ts +0 -14
  266. package/dist/browserFramework.minimal.js +0 -31
  267. package/dist/chat/BrainyChat.d.ts +0 -121
  268. package/dist/chat/BrainyChat.js +0 -396
  269. package/dist/chat/ChatCLI.d.ts +0 -61
  270. package/dist/chat/ChatCLI.js +0 -351
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Augmentation Discovery API
3
+ *
4
+ * Provides discovery and configuration capabilities for augmentations
5
+ * Enables tools like brain-cloud to dynamically discover, configure, and manage augmentations
6
+ */
7
+ import { AugmentationRegistry } from './brainyAugmentation.js';
8
+ import { AugmentationManifest, JSONSchema } from './manifest.js';
9
+ /**
10
+ * Augmentation listing with manifest and status
11
+ */
12
+ export interface AugmentationListing {
13
+ id: string;
14
+ name: string;
15
+ manifest: AugmentationManifest;
16
+ status: {
17
+ enabled: boolean;
18
+ initialized: boolean;
19
+ category: string;
20
+ priority: number;
21
+ };
22
+ config?: {
23
+ current: any;
24
+ schema?: JSONSchema;
25
+ sources?: any[];
26
+ };
27
+ }
28
+ /**
29
+ * Configuration validation result
30
+ */
31
+ export interface ConfigValidationResult {
32
+ valid: boolean;
33
+ errors?: string[];
34
+ warnings?: string[];
35
+ suggestions?: string[];
36
+ }
37
+ /**
38
+ * Discovery API options
39
+ */
40
+ export interface DiscoveryOptions {
41
+ includeConfig?: boolean;
42
+ includeSchema?: boolean;
43
+ includeSources?: boolean;
44
+ category?: string;
45
+ enabled?: boolean;
46
+ }
47
+ /**
48
+ * Augmentation Discovery API
49
+ *
50
+ * Provides a unified interface for discovering and managing augmentations
51
+ */
52
+ export declare class AugmentationDiscovery {
53
+ private registry;
54
+ constructor(registry: AugmentationRegistry);
55
+ /**
56
+ * Discover all registered augmentations with manifests
57
+ * @param options Discovery options
58
+ * @returns List of augmentation listings
59
+ */
60
+ discover(options?: DiscoveryOptions): Promise<AugmentationListing[]>;
61
+ /**
62
+ * Get a specific augmentation's manifest
63
+ * @param augId Augmentation ID
64
+ * @returns Augmentation manifest or null if not found
65
+ */
66
+ getManifest(augId: string): Promise<AugmentationManifest | null>;
67
+ /**
68
+ * Get configuration schema for an augmentation
69
+ * @param augId Augmentation ID
70
+ * @returns Configuration schema or null
71
+ */
72
+ getConfigSchema(augId: string): Promise<JSONSchema | null>;
73
+ /**
74
+ * Get current configuration for an augmentation
75
+ * @param augId Augmentation ID
76
+ * @returns Current configuration or null
77
+ */
78
+ getConfig(augId: string): Promise<any | null>;
79
+ /**
80
+ * Update configuration for an augmentation
81
+ * @param augId Augmentation ID
82
+ * @param config New configuration
83
+ * @returns Updated configuration or null on failure
84
+ */
85
+ updateConfig(augId: string, config: any): Promise<any | null>;
86
+ /**
87
+ * Validate configuration against schema
88
+ * @param augId Augmentation ID
89
+ * @param config Configuration to validate
90
+ * @returns Validation result
91
+ */
92
+ validateConfig(augId: string, config: any): Promise<ConfigValidationResult>;
93
+ /**
94
+ * Validate a property value against its schema
95
+ */
96
+ private validatePropertyValue;
97
+ /**
98
+ * Get environment variables for an augmentation
99
+ * @param augId Augmentation ID
100
+ * @returns Map of environment variable names to descriptions
101
+ */
102
+ getEnvironmentVariables(augId: string): Promise<Record<string, any> | null>;
103
+ /**
104
+ * Get configuration examples for an augmentation
105
+ * @param augId Augmentation ID
106
+ * @returns Configuration examples or empty array
107
+ */
108
+ getConfigExamples(augId: string): Promise<any[]>;
109
+ /**
110
+ * Check if an augmentation supports configuration
111
+ * @param augId Augmentation ID
112
+ * @returns True if augmentation supports configuration
113
+ */
114
+ supportsConfiguration(augId: string): Promise<boolean>;
115
+ /**
116
+ * Get augmentations by category
117
+ * @param category Category to filter by
118
+ * @returns List of augmentations in the category
119
+ */
120
+ getByCategory(category: string): Promise<AugmentationListing[]>;
121
+ /**
122
+ * Get enabled augmentations
123
+ * @returns List of enabled augmentations
124
+ */
125
+ getEnabled(): Promise<AugmentationListing[]>;
126
+ /**
127
+ * Search augmentations by keyword
128
+ * @param query Search query
129
+ * @returns Matching augmentations
130
+ */
131
+ search(query: string): Promise<AugmentationListing[]>;
132
+ /**
133
+ * Export configuration for all augmentations
134
+ * @returns Map of augmentation IDs to configurations
135
+ */
136
+ exportConfigurations(): Promise<Record<string, any>>;
137
+ /**
138
+ * Import configurations for multiple augmentations
139
+ * @param configs Map of augmentation IDs to configurations
140
+ * @returns Results of import operation
141
+ */
142
+ importConfigurations(configs: Record<string, any>): Promise<Record<string, {
143
+ success: boolean;
144
+ error?: string;
145
+ }>>;
146
+ /**
147
+ * Generate configuration documentation
148
+ * @param augId Augmentation ID
149
+ * @returns Markdown documentation
150
+ */
151
+ generateConfigDocs(augId: string): Promise<string | null>;
152
+ }
@@ -0,0 +1,441 @@
1
+ /**
2
+ * Augmentation Discovery API
3
+ *
4
+ * Provides discovery and configuration capabilities for augmentations
5
+ * Enables tools like brain-cloud to dynamically discover, configure, and manage augmentations
6
+ */
7
+ /**
8
+ * Augmentation Discovery API
9
+ *
10
+ * Provides a unified interface for discovering and managing augmentations
11
+ */
12
+ export class AugmentationDiscovery {
13
+ constructor(registry) {
14
+ this.registry = registry;
15
+ }
16
+ /**
17
+ * Discover all registered augmentations with manifests
18
+ * @param options Discovery options
19
+ * @returns List of augmentation listings
20
+ */
21
+ async discover(options = {}) {
22
+ const augmentations = this.registry.getAll();
23
+ const listings = [];
24
+ for (const aug of augmentations) {
25
+ // Check if augmentation has manifest support
26
+ const hasManifest = 'getManifest' in aug && typeof aug.getManifest === 'function';
27
+ if (!hasManifest) {
28
+ // Skip augmentations without manifest support (legacy)
29
+ continue;
30
+ }
31
+ try {
32
+ // Check if augmentation has manifest method
33
+ if (!('getManifest' in aug) || typeof aug.getManifest !== 'function') {
34
+ continue;
35
+ }
36
+ const getManifestFn = aug.getManifest;
37
+ const manifest = getManifestFn();
38
+ // Apply filters
39
+ if (options.category && manifest.category !== options.category) {
40
+ continue;
41
+ }
42
+ if (options.enabled !== undefined) {
43
+ const isEnabled = aug.enabled !== false;
44
+ if (isEnabled !== options.enabled) {
45
+ continue;
46
+ }
47
+ }
48
+ // Build listing
49
+ const listing = {
50
+ id: manifest.id,
51
+ name: manifest.name,
52
+ manifest,
53
+ status: {
54
+ enabled: aug.enabled !== false,
55
+ initialized: aug.isInitialized || false,
56
+ category: aug.category || manifest.category,
57
+ priority: aug.priority
58
+ }
59
+ };
60
+ // Include configuration if requested
61
+ if (options.includeConfig && 'getConfig' in aug) {
62
+ const getConfigFn = aug.getConfig;
63
+ listing.config = {
64
+ current: getConfigFn()
65
+ };
66
+ if (options.includeSchema) {
67
+ listing.config.schema = manifest.configSchema;
68
+ }
69
+ }
70
+ listings.push(listing);
71
+ }
72
+ catch (error) {
73
+ console.warn(`Failed to get manifest for augmentation ${aug.name}:`, error);
74
+ }
75
+ }
76
+ // Sort by priority (highest first) then by name
77
+ listings.sort((a, b) => {
78
+ const priorityDiff = b.status.priority - a.status.priority;
79
+ if (priorityDiff !== 0)
80
+ return priorityDiff;
81
+ return a.name.localeCompare(b.name);
82
+ });
83
+ return listings;
84
+ }
85
+ /**
86
+ * Get a specific augmentation's manifest
87
+ * @param augId Augmentation ID
88
+ * @returns Augmentation manifest or null if not found
89
+ */
90
+ async getManifest(augId) {
91
+ const aug = this.registry.get(augId);
92
+ if (!aug || !('getManifest' in aug)) {
93
+ return null;
94
+ }
95
+ try {
96
+ const getManifestFn = aug.getManifest;
97
+ return getManifestFn();
98
+ }
99
+ catch (error) {
100
+ console.error(`Failed to get manifest for ${augId}:`, error);
101
+ return null;
102
+ }
103
+ }
104
+ /**
105
+ * Get configuration schema for an augmentation
106
+ * @param augId Augmentation ID
107
+ * @returns Configuration schema or null
108
+ */
109
+ async getConfigSchema(augId) {
110
+ const manifest = await this.getManifest(augId);
111
+ return manifest?.configSchema || null;
112
+ }
113
+ /**
114
+ * Get current configuration for an augmentation
115
+ * @param augId Augmentation ID
116
+ * @returns Current configuration or null
117
+ */
118
+ async getConfig(augId) {
119
+ const aug = this.registry.get(augId);
120
+ if (!aug || !('getConfig' in aug)) {
121
+ return null;
122
+ }
123
+ try {
124
+ const getConfigFn = aug.getConfig;
125
+ return getConfigFn();
126
+ }
127
+ catch (error) {
128
+ console.error(`Failed to get config for ${augId}:`, error);
129
+ return null;
130
+ }
131
+ }
132
+ /**
133
+ * Update configuration for an augmentation
134
+ * @param augId Augmentation ID
135
+ * @param config New configuration
136
+ * @returns Updated configuration or null on failure
137
+ */
138
+ async updateConfig(augId, config) {
139
+ const aug = this.registry.get(augId);
140
+ if (!aug || !('updateConfig' in aug) || !('getConfig' in aug)) {
141
+ throw new Error(`Augmentation ${augId} does not support configuration updates`);
142
+ }
143
+ try {
144
+ const updateConfigFn = aug.updateConfig;
145
+ await updateConfigFn(config);
146
+ const getConfigFn = aug.getConfig;
147
+ return getConfigFn();
148
+ }
149
+ catch (error) {
150
+ throw new Error(`Failed to update config for ${augId}: ${error}`);
151
+ }
152
+ }
153
+ /**
154
+ * Validate configuration against schema
155
+ * @param augId Augmentation ID
156
+ * @param config Configuration to validate
157
+ * @returns Validation result
158
+ */
159
+ async validateConfig(augId, config) {
160
+ const schema = await this.getConfigSchema(augId);
161
+ if (!schema) {
162
+ return {
163
+ valid: true,
164
+ warnings: ['No schema available for validation']
165
+ };
166
+ }
167
+ const errors = [];
168
+ const warnings = [];
169
+ const suggestions = [];
170
+ // Check required fields
171
+ if (schema.required) {
172
+ for (const field of schema.required) {
173
+ if (config[field] === undefined) {
174
+ errors.push(`Missing required field: ${field}`);
175
+ }
176
+ }
177
+ }
178
+ // Validate properties
179
+ if (schema.properties) {
180
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
181
+ const value = config[key];
182
+ if (value === undefined) {
183
+ // Check if there's a default
184
+ if (propSchema.default !== undefined) {
185
+ suggestions.push(`Field '${key}' not provided, will use default: ${JSON.stringify(propSchema.default)}`);
186
+ }
187
+ continue;
188
+ }
189
+ // Type validation
190
+ if (propSchema.type) {
191
+ const actualType = Array.isArray(value) ? 'array' : typeof value;
192
+ if (actualType !== propSchema.type) {
193
+ errors.push(`${key}: expected ${propSchema.type}, got ${actualType}`);
194
+ }
195
+ }
196
+ // Additional validations for specific types
197
+ this.validatePropertyValue(key, value, propSchema, errors, warnings);
198
+ }
199
+ }
200
+ // Check for unknown properties
201
+ if (schema.additionalProperties === false && schema.properties) {
202
+ const allowedKeys = Object.keys(schema.properties);
203
+ for (const key of Object.keys(config)) {
204
+ if (!allowedKeys.includes(key)) {
205
+ warnings.push(`Unknown property: ${key}`);
206
+ }
207
+ }
208
+ }
209
+ return {
210
+ valid: errors.length === 0,
211
+ errors: errors.length > 0 ? errors : undefined,
212
+ warnings: warnings.length > 0 ? warnings : undefined,
213
+ suggestions: suggestions.length > 0 ? suggestions : undefined
214
+ };
215
+ }
216
+ /**
217
+ * Validate a property value against its schema
218
+ */
219
+ validatePropertyValue(key, value, schema, errors, warnings) {
220
+ // Number validations
221
+ if (schema.type === 'number') {
222
+ if (schema.minimum !== undefined && value < schema.minimum) {
223
+ errors.push(`${key}: value ${value} is less than minimum ${schema.minimum}`);
224
+ }
225
+ if (schema.maximum !== undefined && value > schema.maximum) {
226
+ errors.push(`${key}: value ${value} is greater than maximum ${schema.maximum}`);
227
+ }
228
+ }
229
+ // String validations
230
+ if (schema.type === 'string') {
231
+ if (schema.minLength !== undefined && value.length < schema.minLength) {
232
+ errors.push(`${key}: length ${value.length} is less than minimum ${schema.minLength}`);
233
+ }
234
+ if (schema.maxLength !== undefined && value.length > schema.maxLength) {
235
+ errors.push(`${key}: length ${value.length} is greater than maximum ${schema.maxLength}`);
236
+ }
237
+ if (schema.pattern) {
238
+ const regex = new RegExp(schema.pattern);
239
+ if (!regex.test(value)) {
240
+ errors.push(`${key}: value does not match pattern ${schema.pattern}`);
241
+ }
242
+ }
243
+ }
244
+ // Enum validation
245
+ if (schema.enum && !schema.enum.includes(value)) {
246
+ errors.push(`${key}: value '${value}' is not one of allowed values: ${schema.enum.join(', ')}`);
247
+ }
248
+ }
249
+ /**
250
+ * Get environment variables for an augmentation
251
+ * @param augId Augmentation ID
252
+ * @returns Map of environment variable names to descriptions
253
+ */
254
+ async getEnvironmentVariables(augId) {
255
+ const manifest = await this.getManifest(augId);
256
+ if (!manifest?.configSchema?.properties) {
257
+ return null;
258
+ }
259
+ const prefix = `BRAINY_AUG_${augId.toUpperCase()}_`;
260
+ const vars = {};
261
+ for (const [key, prop] of Object.entries(manifest.configSchema.properties)) {
262
+ const envKey = prefix + key.replace(/([A-Z])/g, '_$1').toUpperCase();
263
+ vars[envKey] = {
264
+ configKey: key,
265
+ description: prop.description,
266
+ type: prop.type,
267
+ default: prop.default,
268
+ required: manifest.configSchema.required?.includes(key),
269
+ currentValue: typeof process !== 'undefined' ? process.env?.[envKey] : undefined
270
+ };
271
+ }
272
+ return vars;
273
+ }
274
+ /**
275
+ * Get configuration examples for an augmentation
276
+ * @param augId Augmentation ID
277
+ * @returns Configuration examples or empty array
278
+ */
279
+ async getConfigExamples(augId) {
280
+ const manifest = await this.getManifest(augId);
281
+ return manifest?.configExamples || [];
282
+ }
283
+ /**
284
+ * Check if an augmentation supports configuration
285
+ * @param augId Augmentation ID
286
+ * @returns True if augmentation supports configuration
287
+ */
288
+ async supportsConfiguration(augId) {
289
+ const aug = this.registry.get(augId);
290
+ return !!(aug && 'getConfig' in aug && 'updateConfig' in aug);
291
+ }
292
+ /**
293
+ * Get augmentations by category
294
+ * @param category Category to filter by
295
+ * @returns List of augmentations in the category
296
+ */
297
+ async getByCategory(category) {
298
+ return this.discover({ category });
299
+ }
300
+ /**
301
+ * Get enabled augmentations
302
+ * @returns List of enabled augmentations
303
+ */
304
+ async getEnabled() {
305
+ return this.discover({ enabled: true });
306
+ }
307
+ /**
308
+ * Search augmentations by keyword
309
+ * @param query Search query
310
+ * @returns Matching augmentations
311
+ */
312
+ async search(query) {
313
+ const all = await this.discover();
314
+ const queryLower = query.toLowerCase();
315
+ return all.filter(listing => {
316
+ const manifest = listing.manifest;
317
+ // Search in various fields
318
+ const searchFields = [
319
+ manifest.name,
320
+ manifest.description,
321
+ manifest.longDescription,
322
+ ...(manifest.keywords || []),
323
+ manifest.category
324
+ ].filter(Boolean).map(s => s.toLowerCase());
325
+ return searchFields.some(field => field.includes(queryLower));
326
+ });
327
+ }
328
+ /**
329
+ * Export configuration for all augmentations
330
+ * @returns Map of augmentation IDs to configurations
331
+ */
332
+ async exportConfigurations() {
333
+ const configs = {};
334
+ const listings = await this.discover({ includeConfig: true });
335
+ for (const listing of listings) {
336
+ if (listing.config?.current) {
337
+ configs[listing.id] = listing.config.current;
338
+ }
339
+ }
340
+ return configs;
341
+ }
342
+ /**
343
+ * Import configurations for multiple augmentations
344
+ * @param configs Map of augmentation IDs to configurations
345
+ * @returns Results of import operation
346
+ */
347
+ async importConfigurations(configs) {
348
+ const results = {};
349
+ for (const [augId, config] of Object.entries(configs)) {
350
+ try {
351
+ // Validate before applying
352
+ const validation = await this.validateConfig(augId, config);
353
+ if (!validation.valid) {
354
+ results[augId] = {
355
+ success: false,
356
+ error: `Validation failed: ${validation.errors?.join(', ')}`
357
+ };
358
+ continue;
359
+ }
360
+ // Apply configuration
361
+ await this.updateConfig(augId, config);
362
+ results[augId] = { success: true };
363
+ }
364
+ catch (error) {
365
+ results[augId] = {
366
+ success: false,
367
+ error: error instanceof Error ? error.message : String(error)
368
+ };
369
+ }
370
+ }
371
+ return results;
372
+ }
373
+ /**
374
+ * Generate configuration documentation
375
+ * @param augId Augmentation ID
376
+ * @returns Markdown documentation
377
+ */
378
+ async generateConfigDocs(augId) {
379
+ const manifest = await this.getManifest(augId);
380
+ if (!manifest)
381
+ return null;
382
+ const schema = manifest.configSchema;
383
+ const examples = manifest.configExamples || [];
384
+ const envVars = await this.getEnvironmentVariables(augId);
385
+ let docs = `# ${manifest.name} Configuration\n\n`;
386
+ docs += `${manifest.description}\n\n`;
387
+ if (manifest.longDescription) {
388
+ docs += `## Overview\n\n${manifest.longDescription}\n\n`;
389
+ }
390
+ // Configuration options
391
+ if (schema?.properties) {
392
+ docs += `## Configuration Options\n\n`;
393
+ for (const [key, prop] of Object.entries(schema.properties)) {
394
+ const required = schema.required?.includes(key) ? ' *(required)*' : '';
395
+ docs += `### \`${key}\`${required}\n\n`;
396
+ if (prop.description) {
397
+ docs += `${prop.description}\n\n`;
398
+ }
399
+ docs += `- **Type**: ${prop.type}\n`;
400
+ if (prop.default !== undefined) {
401
+ docs += `- **Default**: \`${JSON.stringify(prop.default)}\`\n`;
402
+ }
403
+ if (prop.minimum !== undefined) {
404
+ docs += `- **Minimum**: ${prop.minimum}\n`;
405
+ }
406
+ if (prop.maximum !== undefined) {
407
+ docs += `- **Maximum**: ${prop.maximum}\n`;
408
+ }
409
+ if (prop.enum) {
410
+ docs += `- **Allowed values**: ${prop.enum.map(v => `\`${v}\``).join(', ')}\n`;
411
+ }
412
+ docs += '\n';
413
+ }
414
+ }
415
+ // Environment variables
416
+ if (envVars && Object.keys(envVars).length > 0) {
417
+ docs += `## Environment Variables\n\n`;
418
+ docs += `| Variable | Config Key | Type | Required | Default |\n`;
419
+ docs += `|----------|------------|------|----------|----------|\n`;
420
+ for (const [envKey, info] of Object.entries(envVars)) {
421
+ docs += `| \`${envKey}\` | ${info.configKey} | ${info.type} | ${info.required ? 'Yes' : 'No'} | ${info.default !== undefined ? `\`${info.default}\`` : '-'} |\n`;
422
+ }
423
+ docs += '\n';
424
+ }
425
+ // Examples
426
+ if (examples.length > 0) {
427
+ docs += `## Examples\n\n`;
428
+ for (const example of examples) {
429
+ docs += `### ${example.name}\n\n`;
430
+ if (example.description) {
431
+ docs += `${example.description}\n\n`;
432
+ }
433
+ docs += '```json\n';
434
+ docs += JSON.stringify(example.config, null, 2);
435
+ docs += '\n```\n\n';
436
+ }
437
+ }
438
+ return docs;
439
+ }
440
+ }
441
+ //# sourceMappingURL=discovery.js.map