@soulcraft/brainy 2.4.0 → 2.6.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.
- package/README.md +60 -0
- package/bin/brainy.js +340 -62
- package/dist/augmentations/brainyAugmentation.d.ts +55 -0
- package/dist/augmentations/brainyAugmentation.js +20 -0
- package/dist/augmentations/cacheAugmentation.d.ts +2 -0
- package/dist/augmentations/cacheAugmentation.js +3 -0
- package/dist/augmentations/defaultAugmentations.d.ts +6 -0
- package/dist/augmentations/defaultAugmentations.js +12 -0
- package/dist/augmentations/display/cache.d.ts +130 -0
- package/dist/augmentations/display/cache.js +319 -0
- package/dist/augmentations/display/fieldPatterns.d.ts +52 -0
- package/dist/augmentations/display/fieldPatterns.js +393 -0
- package/dist/augmentations/display/iconMappings.d.ts +57 -0
- package/dist/augmentations/display/iconMappings.js +68 -0
- package/dist/augmentations/display/intelligentComputation.d.ts +109 -0
- package/dist/augmentations/display/intelligentComputation.js +462 -0
- package/dist/augmentations/display/types.d.ts +203 -0
- package/dist/augmentations/display/types.js +7 -0
- package/dist/augmentations/indexAugmentation.d.ts +2 -0
- package/dist/augmentations/indexAugmentation.js +3 -0
- package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +2 -1
- package/dist/augmentations/intelligentVerbScoringAugmentation.js +5 -4
- package/dist/augmentations/universalDisplayAugmentation.d.ts +191 -0
- package/dist/augmentations/universalDisplayAugmentation.js +371 -0
- package/dist/augmentations/walAugmentation.d.ts +2 -0
- package/dist/augmentations/walAugmentation.js +3 -0
- package/dist/brainyData.d.ts +1 -1
- package/dist/brainyData.js +11 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -294,6 +294,66 @@ brainy chat
|
|
|
294
294
|
brainy export --format json > backup.json
|
|
295
295
|
```
|
|
296
296
|
|
|
297
|
+
## 🧠 Neural API - Advanced AI Features
|
|
298
|
+
|
|
299
|
+
Brainy includes a powerful Neural API for advanced semantic analysis:
|
|
300
|
+
|
|
301
|
+
### Clustering & Analysis
|
|
302
|
+
```javascript
|
|
303
|
+
// Access via brain.neural
|
|
304
|
+
const neural = brain.neural
|
|
305
|
+
|
|
306
|
+
// Automatic semantic clustering
|
|
307
|
+
const clusters = await neural.clusters()
|
|
308
|
+
// Returns groups of semantically similar items
|
|
309
|
+
|
|
310
|
+
// Cluster with options
|
|
311
|
+
const clusters = await neural.clusters({
|
|
312
|
+
algorithm: 'kmeans', // or 'hierarchical', 'sample'
|
|
313
|
+
maxClusters: 5, // Maximum number of clusters
|
|
314
|
+
threshold: 0.8 // Similarity threshold
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
// Calculate similarity between any items
|
|
318
|
+
const similarity = await neural.similar('item1', 'item2')
|
|
319
|
+
// Returns 0-1 score
|
|
320
|
+
|
|
321
|
+
// Find nearest neighbors
|
|
322
|
+
const neighbors = await neural.neighbors('item-id', 10)
|
|
323
|
+
|
|
324
|
+
// Build semantic hierarchy
|
|
325
|
+
const hierarchy = await neural.hierarchy('item-id')
|
|
326
|
+
|
|
327
|
+
// Detect outliers
|
|
328
|
+
const outliers = await neural.outliers(0.3)
|
|
329
|
+
|
|
330
|
+
// Generate visualization data for D3/Cytoscape
|
|
331
|
+
const vizData = await neural.visualize({
|
|
332
|
+
maxNodes: 100,
|
|
333
|
+
dimensions: 3,
|
|
334
|
+
algorithm: 'force'
|
|
335
|
+
})
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Real-World Examples
|
|
339
|
+
```javascript
|
|
340
|
+
// Group customer feedback into themes
|
|
341
|
+
const feedbackClusters = await neural.clusters()
|
|
342
|
+
for (const cluster of feedbackClusters) {
|
|
343
|
+
console.log(`Theme: ${cluster.label}`)
|
|
344
|
+
console.log(`Items: ${cluster.members.length}`)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// Find related documents
|
|
348
|
+
const docId = await brain.addNoun("Machine learning guide")
|
|
349
|
+
const similar = await neural.neighbors(docId, 5)
|
|
350
|
+
// Returns 5 most similar documents
|
|
351
|
+
|
|
352
|
+
// Detect anomalies in data
|
|
353
|
+
const anomalies = await neural.outliers(0.2)
|
|
354
|
+
console.log(`Found ${anomalies.length} outliers`)
|
|
355
|
+
```
|
|
356
|
+
|
|
297
357
|
## 🔌 Augmentations
|
|
298
358
|
|
|
299
359
|
Extend Brainy with powerful augmentations:
|
package/bin/brainy.js
CHANGED
|
@@ -61,6 +61,200 @@ const initBrainy = async () => {
|
|
|
61
61
|
return new BrainyData()
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Enhanced result formatting using display augmentation
|
|
66
|
+
* @param {any} result - The result object from search/get/find
|
|
67
|
+
* @param {number} index - Result index for numbering
|
|
68
|
+
* @returns {Promise<string>} Formatted result string
|
|
69
|
+
*/
|
|
70
|
+
const formatResultWithDisplay = async (result, index) => {
|
|
71
|
+
try {
|
|
72
|
+
// Check if result has display capabilities (enhanced by display augmentation)
|
|
73
|
+
if (result.getDisplay && typeof result.getDisplay === 'function') {
|
|
74
|
+
const displayFields = await result.getDisplay()
|
|
75
|
+
|
|
76
|
+
// Format with enhanced display fields (clean, no icons)
|
|
77
|
+
let output = colors.primary(`\n${index + 1}. ${displayFields.title}`)
|
|
78
|
+
|
|
79
|
+
if (displayFields.type) {
|
|
80
|
+
output += colors.dim(` (${displayFields.type})`)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (result.score) {
|
|
84
|
+
output += colors.info(`\n 🎯 Relevance: ${(result.score * 100).toFixed(1)}%`)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (result.fusionScore) {
|
|
88
|
+
output += colors.info(`\n 🧠 AI Score: ${(result.fusionScore * 100).toFixed(1)}%`)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (displayFields.description && displayFields.description !== displayFields.title) {
|
|
92
|
+
output += colors.info(`\n 📄 ${displayFields.description}`)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (displayFields.tags && displayFields.tags.length > 0) {
|
|
96
|
+
output += colors.cyan(`\n 🏷️ ${displayFields.tags.join(', ')}`)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Show relationship info for verbs
|
|
100
|
+
if (displayFields.relationship) {
|
|
101
|
+
output += colors.yellow(`\n 🔗 ${displayFields.relationship}`)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Show metadata only if there's additional useful info
|
|
105
|
+
if (result.metadata && Object.keys(result.metadata).length > 0) {
|
|
106
|
+
const filteredMetadata = Object.fromEntries(
|
|
107
|
+
Object.entries(result.metadata).filter(([key]) =>
|
|
108
|
+
!key.startsWith('_') && !['type', 'title', 'description', 'icon'].includes(key)
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
if (Object.keys(filteredMetadata).length > 0) {
|
|
112
|
+
output += colors.dim(`\n 📝 ${JSON.stringify(filteredMetadata)}`)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return output
|
|
117
|
+
}
|
|
118
|
+
} catch (error) {
|
|
119
|
+
// Fallback silently to basic formatting if display augmentation fails
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Fallback: Basic formatting without display augmentation
|
|
123
|
+
let output = colors.primary(`\n${index + 1}. ${result.content || result.id}`)
|
|
124
|
+
|
|
125
|
+
if (result.score) {
|
|
126
|
+
output += colors.info(`\n Relevance: ${(result.score * 100).toFixed(1)}%`)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (result.fusionScore) {
|
|
130
|
+
output += colors.info(`\n AI Score: ${(result.fusionScore * 100).toFixed(1)}%`)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (result.type) {
|
|
134
|
+
output += colors.info(`\n Type: ${result.type}`)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (result.metadata && Object.keys(result.metadata).length > 0) {
|
|
138
|
+
output += colors.dim(`\n Metadata: ${JSON.stringify(result.metadata)}`)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return output
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Enhanced single item formatting for get command
|
|
146
|
+
* @param {any} item - The item object
|
|
147
|
+
* @param {string} format - Output format (json, table, plain)
|
|
148
|
+
* @returns {Promise<string>} Formatted item string
|
|
149
|
+
*/
|
|
150
|
+
const formatItemWithDisplay = async (item, format = 'plain') => {
|
|
151
|
+
if (format === 'json') {
|
|
152
|
+
return JSON.stringify(item, null, 2)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
// Check if item has display capabilities
|
|
157
|
+
if (item.getDisplay && typeof item.getDisplay === 'function') {
|
|
158
|
+
const displayFields = await item.getDisplay()
|
|
159
|
+
|
|
160
|
+
if (format === 'table') {
|
|
161
|
+
const table = new Table({
|
|
162
|
+
head: [colors.brain('Property'), colors.brain('Value')],
|
|
163
|
+
style: { head: [], border: [] }
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
table.push(['ID', colors.primary(item.id)])
|
|
167
|
+
table.push(['Title', colors.primary(displayFields.title)])
|
|
168
|
+
table.push(['Type', colors.info(displayFields.type)])
|
|
169
|
+
table.push(['Description', colors.info(displayFields.description)])
|
|
170
|
+
|
|
171
|
+
if (displayFields.tags && displayFields.tags.length > 0) {
|
|
172
|
+
table.push(['Tags', colors.cyan(displayFields.tags.join(', '))])
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (displayFields.relationship) {
|
|
176
|
+
table.push(['Relationship', colors.yellow(displayFields.relationship)])
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (item.content && item.content !== displayFields.title) {
|
|
180
|
+
table.push(['Content', colors.dim(item.content)])
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Add non-internal metadata
|
|
184
|
+
if (item.metadata) {
|
|
185
|
+
Object.entries(item.metadata).forEach(([key, value]) => {
|
|
186
|
+
if (!key.startsWith('_') && !['type', 'title', 'description', 'icon'].includes(key)) {
|
|
187
|
+
table.push([key, colors.dim(JSON.stringify(value))])
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return table.toString()
|
|
193
|
+
} else {
|
|
194
|
+
// Plain format with display enhancement
|
|
195
|
+
let output = colors.primary(`ID: ${item.id}`)
|
|
196
|
+
output += colors.primary(`\nTitle: ${displayFields.title}`)
|
|
197
|
+
output += colors.info(`\nType: ${displayFields.type}`)
|
|
198
|
+
output += colors.info(`\nDescription: ${displayFields.description}`)
|
|
199
|
+
|
|
200
|
+
if (displayFields.tags && displayFields.tags.length > 0) {
|
|
201
|
+
output += colors.cyan(`\nTags: ${displayFields.tags.join(', ')}`)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (displayFields.relationship) {
|
|
205
|
+
output += colors.yellow(`\nRelationship: ${displayFields.relationship}`)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (item.content && item.content !== displayFields.title) {
|
|
209
|
+
output += colors.dim(`\nOriginal Content: ${item.content}`)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Show additional metadata
|
|
213
|
+
if (item.metadata) {
|
|
214
|
+
const additionalMetadata = Object.fromEntries(
|
|
215
|
+
Object.entries(item.metadata).filter(([key]) =>
|
|
216
|
+
!key.startsWith('_') && !['type', 'title', 'description', 'icon'].includes(key)
|
|
217
|
+
)
|
|
218
|
+
)
|
|
219
|
+
if (Object.keys(additionalMetadata).length > 0) {
|
|
220
|
+
output += colors.dim(`\nAdditional Metadata: ${JSON.stringify(additionalMetadata, null, 2)}`)
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return output
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
} catch (error) {
|
|
228
|
+
// Fallback silently to basic formatting
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Fallback: Basic formatting
|
|
232
|
+
if (format === 'table') {
|
|
233
|
+
const table = new Table({
|
|
234
|
+
head: [colors.brain('Property'), colors.brain('Value')],
|
|
235
|
+
style: { head: [], border: [] }
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
table.push(['ID', colors.primary(item.id)])
|
|
239
|
+
table.push(['Content', colors.info(item.content || 'N/A')])
|
|
240
|
+
if (item.metadata) {
|
|
241
|
+
Object.entries(item.metadata).forEach(([key, value]) => {
|
|
242
|
+
table.push([key, colors.dim(JSON.stringify(value))])
|
|
243
|
+
})
|
|
244
|
+
}
|
|
245
|
+
return table.toString()
|
|
246
|
+
} else {
|
|
247
|
+
let output = colors.primary(`ID: ${item.id}`)
|
|
248
|
+
if (item.content) {
|
|
249
|
+
output += colors.info(`\nContent: ${item.content}`)
|
|
250
|
+
}
|
|
251
|
+
if (item.metadata && Object.keys(item.metadata).length > 0) {
|
|
252
|
+
output += colors.info(`\nMetadata: ${JSON.stringify(item.metadata, null, 2)}`)
|
|
253
|
+
}
|
|
254
|
+
return output
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
64
258
|
const wrapAction = (fn) => {
|
|
65
259
|
return async (...args) => {
|
|
66
260
|
try {
|
|
@@ -675,18 +869,12 @@ program
|
|
|
675
869
|
}
|
|
676
870
|
|
|
677
871
|
console.log(colors.success(`✅ Found ${results.length} intelligent results:`))
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
console.log(colors.info(` AI Score: ${(result.fusionScore * 100).toFixed(1)}%`))
|
|
685
|
-
}
|
|
686
|
-
if (result.metadata && Object.keys(result.metadata).length > 0) {
|
|
687
|
-
console.log(colors.dim(` Metadata: ${JSON.stringify(result.metadata)}`))
|
|
688
|
-
}
|
|
689
|
-
})
|
|
872
|
+
|
|
873
|
+
// Use enhanced formatting with display augmentation
|
|
874
|
+
for (let i = 0; i < results.length; i++) {
|
|
875
|
+
const formattedResult = await formatResultWithDisplay(results[i], i)
|
|
876
|
+
console.log(formattedResult)
|
|
877
|
+
}
|
|
690
878
|
}))
|
|
691
879
|
|
|
692
880
|
// Command 4: SEARCH - Triple-power search
|
|
@@ -777,15 +965,12 @@ program
|
|
|
777
965
|
}
|
|
778
966
|
|
|
779
967
|
console.log(colors.success(`✅ Found ${results.length} results:`))
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
console.log(colors.info(` Type: ${result.type}`))
|
|
787
|
-
}
|
|
788
|
-
})
|
|
968
|
+
|
|
969
|
+
// Use enhanced formatting with display augmentation
|
|
970
|
+
for (let i = 0; i < results.length; i++) {
|
|
971
|
+
const formattedResult = await formatResultWithDisplay(results[i], i)
|
|
972
|
+
console.log(formattedResult)
|
|
973
|
+
}
|
|
789
974
|
}))
|
|
790
975
|
|
|
791
976
|
// Command 4: GET - Retrieve specific data by ID
|
|
@@ -793,6 +978,7 @@ program
|
|
|
793
978
|
.command('get [id]')
|
|
794
979
|
.description('Get a specific item by ID')
|
|
795
980
|
.option('-f, --format <format>', 'Output format (json, table, plain)', 'plain')
|
|
981
|
+
.option('--display-debug', 'Show debug information about display augmentation')
|
|
796
982
|
.action(wrapAction(async (id, options) => {
|
|
797
983
|
if (!id) {
|
|
798
984
|
console.log(colors.primary('🔍 Interactive Get Mode'))
|
|
@@ -826,31 +1012,52 @@ program
|
|
|
826
1012
|
return
|
|
827
1013
|
}
|
|
828
1014
|
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
head: [colors.brain('Property'), colors.brain('Value')],
|
|
834
|
-
style: { head: [], border: [] }
|
|
835
|
-
})
|
|
1015
|
+
// Show display debug information if requested
|
|
1016
|
+
if (options.displayDebug) {
|
|
1017
|
+
console.log(colors.primary('🔍 Display Augmentation Debug Information'))
|
|
1018
|
+
console.log('=' .repeat(50))
|
|
836
1019
|
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
1020
|
+
try {
|
|
1021
|
+
if (item.getDisplay && typeof item.getDisplay === 'function') {
|
|
1022
|
+
console.log(colors.success('✅ Display augmentation active'))
|
|
1023
|
+
|
|
1024
|
+
const displayFields = await item.getDisplay()
|
|
1025
|
+
console.log(colors.info('\n🎨 Computed Display Fields:'))
|
|
1026
|
+
Object.entries(displayFields).forEach(([key, value]) => {
|
|
1027
|
+
console.log(colors.cyan(` ${key}: ${JSON.stringify(value)}`))
|
|
1028
|
+
})
|
|
1029
|
+
|
|
1030
|
+
// Show available fields
|
|
1031
|
+
if (item.getAvailableFields && typeof item.getAvailableFields === 'function') {
|
|
1032
|
+
const availableFields = item.getAvailableFields('display')
|
|
1033
|
+
console.log(colors.info('\n📋 Available Display Fields:'))
|
|
1034
|
+
availableFields.forEach(field => {
|
|
1035
|
+
console.log(colors.dim(` - ${field}`))
|
|
1036
|
+
})
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
// Show augmentation info
|
|
1040
|
+
if (item.getAvailableAugmentations && typeof item.getAvailableAugmentations === 'function') {
|
|
1041
|
+
const augs = item.getAvailableAugmentations()
|
|
1042
|
+
console.log(colors.info('\n🔌 Available Augmentations:'))
|
|
1043
|
+
augs.forEach(aug => {
|
|
1044
|
+
console.log(colors.dim(` - ${aug}`))
|
|
1045
|
+
})
|
|
1046
|
+
}
|
|
1047
|
+
} else {
|
|
1048
|
+
console.log(colors.warning('⚠️ Display augmentation not active or not enhanced'))
|
|
1049
|
+
console.log(colors.dim(' Item does not have getDisplay() method'))
|
|
1050
|
+
}
|
|
1051
|
+
} catch (error) {
|
|
1052
|
+
console.log(colors.error(`❌ Display debug error: ${error.message}`))
|
|
852
1053
|
}
|
|
1054
|
+
|
|
1055
|
+
console.log('\n' + '=' .repeat(50))
|
|
853
1056
|
}
|
|
1057
|
+
|
|
1058
|
+
// Use enhanced formatting with display augmentation
|
|
1059
|
+
const formattedItem = await formatItemWithDisplay(item, options.format)
|
|
1060
|
+
console.log(formattedItem)
|
|
854
1061
|
}))
|
|
855
1062
|
|
|
856
1063
|
// Command 5: UPDATE - Update existing data
|
|
@@ -875,9 +1082,21 @@ program
|
|
|
875
1082
|
|
|
876
1083
|
if (recent.length > 0) {
|
|
877
1084
|
console.log(colors.cyan('Recent items:'))
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
1085
|
+
|
|
1086
|
+
// Enhanced display for recent items
|
|
1087
|
+
for (let i = 0; i < Math.min(recent.length, 10); i++) {
|
|
1088
|
+
const item = recent[i]
|
|
1089
|
+
try {
|
|
1090
|
+
if (item.getDisplay && typeof item.getDisplay === 'function') {
|
|
1091
|
+
const displayFields = await item.getDisplay()
|
|
1092
|
+
console.log(colors.info(` ${i + 1}. ${item.id} - ${displayFields.title}`))
|
|
1093
|
+
} else {
|
|
1094
|
+
console.log(colors.info(` ${i + 1}. ${item.id} - ${item.content?.substring(0, 50)}...`))
|
|
1095
|
+
}
|
|
1096
|
+
} catch {
|
|
1097
|
+
console.log(colors.info(` ${i + 1}. ${item.id} - ${item.content?.substring(0, 50)}...`))
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
881
1100
|
console.log()
|
|
882
1101
|
}
|
|
883
1102
|
|
|
@@ -953,9 +1172,21 @@ program
|
|
|
953
1172
|
|
|
954
1173
|
if (recent.length > 0) {
|
|
955
1174
|
console.log(colors.cyan('Recent items:'))
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
1175
|
+
|
|
1176
|
+
// Enhanced display for recent items
|
|
1177
|
+
for (let i = 0; i < Math.min(recent.length, 10); i++) {
|
|
1178
|
+
const item = recent[i]
|
|
1179
|
+
try {
|
|
1180
|
+
if (item.getDisplay && typeof item.getDisplay === 'function') {
|
|
1181
|
+
const displayFields = await item.getDisplay()
|
|
1182
|
+
console.log(colors.info(` ${i + 1}. ${item.id} - ${displayFields.title}`))
|
|
1183
|
+
} else {
|
|
1184
|
+
console.log(colors.info(` ${i + 1}. ${item.id} - ${item.content?.substring(0, 50)}...`))
|
|
1185
|
+
}
|
|
1186
|
+
} catch {
|
|
1187
|
+
console.log(colors.info(` ${i + 1}. ${item.id} - ${item.content?.substring(0, 50)}...`))
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
959
1190
|
console.log()
|
|
960
1191
|
}
|
|
961
1192
|
|
|
@@ -1150,9 +1381,21 @@ program
|
|
|
1150
1381
|
const recent = await brainyInstance.search('*', { limit: 10, sortBy: 'timestamp' })
|
|
1151
1382
|
if (recent.length > 0) {
|
|
1152
1383
|
console.log(colors.cyan('Recent items (source):'))
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1384
|
+
|
|
1385
|
+
// Enhanced display for recent items
|
|
1386
|
+
for (let i = 0; i < Math.min(recent.length, 10); i++) {
|
|
1387
|
+
const item = recent[i]
|
|
1388
|
+
try {
|
|
1389
|
+
if (item.getDisplay && typeof item.getDisplay === 'function') {
|
|
1390
|
+
const displayFields = await item.getDisplay()
|
|
1391
|
+
console.log(colors.info(` ${i + 1}. ${displayFields.icon} ${item.id} - ${displayFields.title}`))
|
|
1392
|
+
} else {
|
|
1393
|
+
console.log(colors.info(` ${i + 1}. ${item.id} - ${item.content?.substring(0, 40)}...`))
|
|
1394
|
+
}
|
|
1395
|
+
} catch {
|
|
1396
|
+
console.log(colors.info(` ${i + 1}. ${item.id} - ${item.content?.substring(0, 40)}...`))
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1156
1399
|
console.log()
|
|
1157
1400
|
}
|
|
1158
1401
|
|
|
@@ -1202,9 +1445,21 @@ program
|
|
|
1202
1445
|
const recent = await brainyInstance.search('*', { limit: 10, sortBy: 'timestamp' })
|
|
1203
1446
|
if (recent.length > 0) {
|
|
1204
1447
|
console.log(colors.cyan('\nRecent items (target):'))
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1448
|
+
|
|
1449
|
+
// Enhanced display for recent items
|
|
1450
|
+
for (let i = 0; i < Math.min(recent.length, 10); i++) {
|
|
1451
|
+
const item = recent[i]
|
|
1452
|
+
try {
|
|
1453
|
+
if (item.getDisplay && typeof item.getDisplay === 'function') {
|
|
1454
|
+
const displayFields = await item.getDisplay()
|
|
1455
|
+
console.log(colors.info(` ${i + 1}. ${displayFields.icon} ${item.id} - ${displayFields.title}`))
|
|
1456
|
+
} else {
|
|
1457
|
+
console.log(colors.info(` ${i + 1}. ${item.id} - ${item.content?.substring(0, 40)}...`))
|
|
1458
|
+
}
|
|
1459
|
+
} catch {
|
|
1460
|
+
console.log(colors.info(` ${i + 1}. ${item.id} - ${item.content?.substring(0, 40)}...`))
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1208
1463
|
console.log()
|
|
1209
1464
|
}
|
|
1210
1465
|
|
|
@@ -1365,16 +1620,39 @@ program
|
|
|
1365
1620
|
|
|
1366
1621
|
// Active Augmentations
|
|
1367
1622
|
console.log(colors.primary('🔌 Active Augmentations'))
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1623
|
+
try {
|
|
1624
|
+
// Check for display augmentation specifically
|
|
1625
|
+
const displayAugmentation = (brainy as any).augmentations?.get('display')
|
|
1626
|
+
if (displayAugmentation) {
|
|
1627
|
+
console.log(colors.success(` ✅ display - Universal Display Augmentation`))
|
|
1628
|
+
console.log(colors.info(` 🎨 AI-powered titles and descriptions`))
|
|
1629
|
+
|
|
1630
|
+
// Get display augmentation stats if available
|
|
1631
|
+
if (displayAugmentation.getStats) {
|
|
1632
|
+
const stats = displayAugmentation.getStats()
|
|
1633
|
+
if (stats.totalComputations > 0) {
|
|
1634
|
+
console.log(colors.dim(` 📊 ${stats.totalComputations} computations, ${(stats.cacheHitRatio * 100).toFixed(1)}% cache hit rate`))
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
// Show other augmentations
|
|
1640
|
+
const otherAugs = (brainy as any).augmentations ?
|
|
1641
|
+
Array.from((brainy as any).augmentations.values()).filter((aug: any) => aug.name !== 'display') :
|
|
1642
|
+
[]
|
|
1643
|
+
|
|
1644
|
+
otherAugs.forEach((aug: any) => {
|
|
1373
1645
|
console.log(colors.success(` ✅ ${aug.name}`))
|
|
1374
|
-
if (aug.
|
|
1375
|
-
console.log(colors.info(` ${aug.description}`))
|
|
1646
|
+
if (aug.version) {
|
|
1647
|
+
console.log(colors.info(` v${aug.version} - ${aug.description || 'No description'}`))
|
|
1376
1648
|
}
|
|
1377
1649
|
})
|
|
1650
|
+
|
|
1651
|
+
if (!displayAugmentation && otherAugs.length === 0) {
|
|
1652
|
+
console.log(colors.warning(' No augmentations currently active'))
|
|
1653
|
+
}
|
|
1654
|
+
} catch (error) {
|
|
1655
|
+
console.log(colors.warning(' Augmentation status unavailable'))
|
|
1378
1656
|
}
|
|
1379
1657
|
console.log()
|
|
1380
1658
|
|
|
@@ -77,6 +77,28 @@ export interface BrainyAugmentation {
|
|
|
77
77
|
* Optional: Cleanup when BrainyData is destroyed
|
|
78
78
|
*/
|
|
79
79
|
shutdown?(): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Optional: Computed fields this augmentation provides
|
|
82
|
+
* Used for discovery, TypeScript support, and API documentation
|
|
83
|
+
*/
|
|
84
|
+
computedFields?: {
|
|
85
|
+
[namespace: string]: {
|
|
86
|
+
[field: string]: {
|
|
87
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
88
|
+
description: string;
|
|
89
|
+
confidence?: number;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Optional: Compute fields for a result entity
|
|
95
|
+
* Called when user accesses getDisplay(), getSchema(), etc.
|
|
96
|
+
*
|
|
97
|
+
* @param result - The result entity (VectorDocument, GraphVerb, etc.)
|
|
98
|
+
* @param namespace - The namespace being requested ('display', 'schema', etc.)
|
|
99
|
+
* @returns Computed fields for the namespace
|
|
100
|
+
*/
|
|
101
|
+
computeFields?(result: any, namespace: string): Promise<Record<string, any>> | Record<string, any>;
|
|
80
102
|
}
|
|
81
103
|
/**
|
|
82
104
|
* Context provided to augmentations
|
|
@@ -108,6 +130,9 @@ export declare abstract class BaseAugmentation implements BrainyAugmentation {
|
|
|
108
130
|
abstract metadata: 'none' | 'readonly' | MetadataAccess;
|
|
109
131
|
abstract operations: ('add' | 'addNoun' | 'addVerb' | 'saveNoun' | 'saveVerb' | 'updateMetadata' | 'delete' | 'deleteVerb' | 'clear' | 'get' | 'search' | 'searchText' | 'searchByNounTypes' | 'findSimilar' | 'searchWithCursor' | 'relate' | 'getConnections' | 'storage' | 'backup' | 'restore' | 'all')[];
|
|
110
132
|
abstract priority: number;
|
|
133
|
+
category: 'internal' | 'core' | 'premium' | 'community' | 'external';
|
|
134
|
+
description: string;
|
|
135
|
+
enabled: boolean;
|
|
111
136
|
protected context?: AugmentationContext;
|
|
112
137
|
protected isInitialized: boolean;
|
|
113
138
|
initialize(context: AugmentationContext): Promise<void>;
|
|
@@ -122,6 +147,25 @@ export declare abstract class BaseAugmentation implements BrainyAugmentation {
|
|
|
122
147
|
* Override this in subclasses for cleanup logic
|
|
123
148
|
*/
|
|
124
149
|
protected onShutdown(): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Optional computed fields declaration (override in subclasses)
|
|
152
|
+
*/
|
|
153
|
+
computedFields?: {
|
|
154
|
+
[namespace: string]: {
|
|
155
|
+
[field: string]: {
|
|
156
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
157
|
+
description: string;
|
|
158
|
+
confidence?: number;
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Optional computed fields implementation (override in subclasses)
|
|
164
|
+
* @param result The result entity
|
|
165
|
+
* @param namespace The requested namespace
|
|
166
|
+
* @returns Computed fields for the namespace
|
|
167
|
+
*/
|
|
168
|
+
computeFields?(result: any, namespace: string): Promise<Record<string, any>> | Record<string, any>;
|
|
125
169
|
/**
|
|
126
170
|
* Log a message with the augmentation name
|
|
127
171
|
*/
|
|
@@ -158,6 +202,17 @@ export declare class AugmentationRegistry {
|
|
|
158
202
|
* Get all registered augmentations
|
|
159
203
|
*/
|
|
160
204
|
getAll(): BrainyAugmentation[];
|
|
205
|
+
/**
|
|
206
|
+
* Get augmentation info for listing
|
|
207
|
+
*/
|
|
208
|
+
getInfo(): Array<{
|
|
209
|
+
name: string;
|
|
210
|
+
type: string;
|
|
211
|
+
enabled: boolean;
|
|
212
|
+
description: string;
|
|
213
|
+
category: string;
|
|
214
|
+
priority: number;
|
|
215
|
+
}>;
|
|
161
216
|
/**
|
|
162
217
|
* Get augmentations by name
|
|
163
218
|
*/
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
*/
|
|
17
17
|
export class BaseAugmentation {
|
|
18
18
|
constructor() {
|
|
19
|
+
// Metadata for augmentation listing and management
|
|
20
|
+
this.category = 'core';
|
|
21
|
+
this.description = '';
|
|
22
|
+
this.enabled = true;
|
|
19
23
|
this.isInitialized = false;
|
|
20
24
|
}
|
|
21
25
|
async initialize(context) {
|
|
@@ -124,6 +128,22 @@ export class AugmentationRegistry {
|
|
|
124
128
|
getAll() {
|
|
125
129
|
return [...this.augmentations];
|
|
126
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Get augmentation info for listing
|
|
133
|
+
*/
|
|
134
|
+
getInfo() {
|
|
135
|
+
return this.augmentations.map(aug => {
|
|
136
|
+
const baseAug = aug;
|
|
137
|
+
return {
|
|
138
|
+
name: aug.name,
|
|
139
|
+
type: baseAug.category || 'core',
|
|
140
|
+
enabled: baseAug.enabled !== false,
|
|
141
|
+
description: baseAug.description || `${aug.name} augmentation`,
|
|
142
|
+
category: baseAug.category || 'core',
|
|
143
|
+
priority: aug.priority
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
}
|
|
127
147
|
/**
|
|
128
148
|
* Get augmentations by name
|
|
129
149
|
*/
|
|
@@ -31,6 +31,8 @@ export declare class CacheAugmentation extends BaseAugmentation {
|
|
|
31
31
|
readonly metadata: "none";
|
|
32
32
|
operations: ("search" | "add" | "delete" | "clear" | "all")[];
|
|
33
33
|
readonly priority = 50;
|
|
34
|
+
readonly category: "core";
|
|
35
|
+
readonly description = "Transparent search result caching with automatic invalidation";
|
|
34
36
|
private searchCache;
|
|
35
37
|
private config;
|
|
36
38
|
constructor(config?: CacheConfig);
|
|
@@ -26,6 +26,9 @@ export class CacheAugmentation extends BaseAugmentation {
|
|
|
26
26
|
this.metadata = 'none'; // Cache doesn't access metadata
|
|
27
27
|
this.operations = ['search', 'add', 'delete', 'clear', 'all'];
|
|
28
28
|
this.priority = 50; // Mid-priority, runs after data operations
|
|
29
|
+
// Augmentation metadata
|
|
30
|
+
this.category = 'core';
|
|
31
|
+
this.description = 'Transparent search result caching with automatic invalidation';
|
|
29
32
|
this.searchCache = null;
|
|
30
33
|
this.config = {
|
|
31
34
|
maxSize: 1000,
|