@soulcraft/brainy 2.1.0 → 3.0.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/dist/augmentations/AugmentationMetadataContract.d.ts +94 -0
- package/dist/augmentations/AugmentationMetadataContract.js +306 -0
- package/dist/augmentations/apiServerAugmentation.d.ts +1 -0
- package/dist/augmentations/apiServerAugmentation.js +1 -0
- package/dist/augmentations/batchProcessingAugmentation.d.ts +1 -0
- package/dist/augmentations/batchProcessingAugmentation.js +1 -0
- package/dist/augmentations/brainyAugmentation.d.ts +16 -0
- package/dist/augmentations/cacheAugmentation.d.ts +1 -0
- package/dist/augmentations/cacheAugmentation.js +1 -0
- package/dist/augmentations/conduitAugmentations.d.ts +1 -0
- package/dist/augmentations/conduitAugmentations.js +1 -0
- package/dist/augmentations/connectionPoolAugmentation.d.ts +1 -0
- package/dist/augmentations/connectionPoolAugmentation.js +1 -0
- package/dist/augmentations/entityRegistryAugmentation.d.ts +2 -0
- package/dist/augmentations/entityRegistryAugmentation.js +2 -0
- package/dist/augmentations/indexAugmentation.d.ts +1 -0
- package/dist/augmentations/indexAugmentation.js +1 -0
- package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +4 -0
- package/dist/augmentations/intelligentVerbScoringAugmentation.js +4 -0
- package/dist/augmentations/metadataEnforcer.d.ts +20 -0
- package/dist/augmentations/metadataEnforcer.js +171 -0
- package/dist/augmentations/metricsAugmentation.d.ts +2 -7
- package/dist/augmentations/metricsAugmentation.js +1 -0
- package/dist/augmentations/monitoringAugmentation.d.ts +1 -0
- package/dist/augmentations/monitoringAugmentation.js +1 -0
- package/dist/augmentations/neuralImport.d.ts +4 -0
- package/dist/augmentations/neuralImport.js +4 -0
- package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +1 -0
- package/dist/augmentations/requestDeduplicatorAugmentation.js +1 -0
- package/dist/augmentations/serverSearchAugmentations.d.ts +2 -0
- package/dist/augmentations/serverSearchAugmentations.js +2 -0
- package/dist/augmentations/storageAugmentation.d.ts +1 -0
- package/dist/augmentations/storageAugmentation.js +1 -0
- package/dist/augmentations/synapseAugmentation.d.ts +4 -0
- package/dist/augmentations/synapseAugmentation.js +4 -0
- package/dist/augmentations/walAugmentation.d.ts +1 -0
- package/dist/augmentations/walAugmentation.js +1 -0
- package/dist/brainyData.d.ts +28 -1
- package/dist/brainyData.js +229 -83
- package/dist/embeddings/model-manager.d.ts +9 -8
- package/dist/embeddings/model-manager.js +105 -85
- package/dist/triple/TripleIntelligence.d.ts +4 -0
- package/dist/triple/TripleIntelligence.js +39 -9
- package/dist/utils/deletedItemsIndex.d.ts +59 -0
- package/dist/utils/deletedItemsIndex.js +98 -0
- package/dist/utils/ensureDeleted.d.ts +38 -0
- package/dist/utils/ensureDeleted.js +79 -0
- package/dist/utils/metadataFilter.js +5 -0
- package/dist/utils/metadataIndex.d.ts +4 -0
- package/dist/utils/metadataIndex.js +45 -0
- package/dist/utils/metadataNamespace.d.ts +113 -0
- package/dist/utils/metadataNamespace.js +162 -0
- package/dist/utils/periodicCleanup.d.ts +87 -0
- package/dist/utils/periodicCleanup.js +219 -0
- package/package.json +9 -3
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Augmentation Metadata Contract System
|
|
3
|
+
*
|
|
4
|
+
* Prevents accidental metadata corruption while allowing intentional enrichment
|
|
5
|
+
* Each augmentation declares its metadata intentions upfront
|
|
6
|
+
*/
|
|
7
|
+
export interface AugmentationMetadataContract {
|
|
8
|
+
name: string;
|
|
9
|
+
version: string;
|
|
10
|
+
reads?: {
|
|
11
|
+
userFields?: string[];
|
|
12
|
+
internalFields?: string[];
|
|
13
|
+
augmentationFields?: string[];
|
|
14
|
+
};
|
|
15
|
+
writes?: {
|
|
16
|
+
userFields?: Array<{
|
|
17
|
+
field: string;
|
|
18
|
+
type: 'create' | 'update' | 'merge' | 'delete';
|
|
19
|
+
description: string;
|
|
20
|
+
example?: any;
|
|
21
|
+
}>;
|
|
22
|
+
augmentationFields?: Array<{
|
|
23
|
+
field: string;
|
|
24
|
+
description: string;
|
|
25
|
+
}>;
|
|
26
|
+
internalFields?: Array<{
|
|
27
|
+
field: string;
|
|
28
|
+
permission: 'granted' | 'requested';
|
|
29
|
+
reason: string;
|
|
30
|
+
}>;
|
|
31
|
+
};
|
|
32
|
+
conflictResolution?: {
|
|
33
|
+
strategy: 'error' | 'warn' | 'merge' | 'skip' | 'override';
|
|
34
|
+
priority?: number;
|
|
35
|
+
};
|
|
36
|
+
guarantees?: {
|
|
37
|
+
preservesExisting?: boolean;
|
|
38
|
+
reversible?: boolean;
|
|
39
|
+
idempotent?: boolean;
|
|
40
|
+
validatesTypes?: boolean;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Runtime metadata safety enforcer
|
|
45
|
+
*/
|
|
46
|
+
export declare class MetadataSafetyEnforcer {
|
|
47
|
+
private contracts;
|
|
48
|
+
private modifications;
|
|
49
|
+
/**
|
|
50
|
+
* Register an augmentation's contract
|
|
51
|
+
*/
|
|
52
|
+
registerContract(contract: AugmentationMetadataContract): void;
|
|
53
|
+
/**
|
|
54
|
+
* Check if an augmentation can modify a field
|
|
55
|
+
*/
|
|
56
|
+
canModifyField(augName: string, field: string, value: any): {
|
|
57
|
+
allowed: boolean;
|
|
58
|
+
reason?: string;
|
|
59
|
+
warnings?: string[];
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Create safe metadata proxy for an augmentation
|
|
63
|
+
*/
|
|
64
|
+
createSafeProxy(metadata: any, augName: string): any;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Example augmentation contracts
|
|
68
|
+
*/
|
|
69
|
+
export declare const EXAMPLE_CONTRACTS: Record<string, AugmentationMetadataContract>;
|
|
70
|
+
/**
|
|
71
|
+
* Augmentation base class with safety
|
|
72
|
+
*/
|
|
73
|
+
export declare abstract class SafeAugmentation {
|
|
74
|
+
protected enforcer: MetadataSafetyEnforcer;
|
|
75
|
+
protected contract: AugmentationMetadataContract;
|
|
76
|
+
constructor(contract: AugmentationMetadataContract);
|
|
77
|
+
/**
|
|
78
|
+
* Get safe metadata proxy
|
|
79
|
+
*/
|
|
80
|
+
protected getSafeMetadata(metadata: any): any;
|
|
81
|
+
/**
|
|
82
|
+
* Abstract method to implement augmentation logic
|
|
83
|
+
*/
|
|
84
|
+
abstract execute(metadata: any): Promise<any>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Example: Category enricher implementation
|
|
88
|
+
*/
|
|
89
|
+
export declare class CategoryEnricherAugmentation extends SafeAugmentation {
|
|
90
|
+
constructor();
|
|
91
|
+
execute(metadata: any): Promise<any>;
|
|
92
|
+
private detectCategory;
|
|
93
|
+
private detectSubcategories;
|
|
94
|
+
}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Augmentation Metadata Contract System
|
|
3
|
+
*
|
|
4
|
+
* Prevents accidental metadata corruption while allowing intentional enrichment
|
|
5
|
+
* Each augmentation declares its metadata intentions upfront
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Runtime metadata safety enforcer
|
|
9
|
+
*/
|
|
10
|
+
export class MetadataSafetyEnforcer {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.contracts = new Map();
|
|
13
|
+
this.modifications = new Map(); // field -> augmentations that modify it
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Register an augmentation's contract
|
|
17
|
+
*/
|
|
18
|
+
registerContract(contract) {
|
|
19
|
+
this.contracts.set(contract.name, contract);
|
|
20
|
+
// Track which augmentations modify which fields
|
|
21
|
+
if (contract.writes?.userFields) {
|
|
22
|
+
for (const fieldDef of contract.writes.userFields) {
|
|
23
|
+
if (!this.modifications.has(fieldDef.field)) {
|
|
24
|
+
this.modifications.set(fieldDef.field, new Set());
|
|
25
|
+
}
|
|
26
|
+
this.modifications.get(fieldDef.field).add(contract.name);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Check if an augmentation can modify a field
|
|
32
|
+
*/
|
|
33
|
+
canModifyField(augName, field, value) {
|
|
34
|
+
const contract = this.contracts.get(augName);
|
|
35
|
+
if (!contract) {
|
|
36
|
+
return {
|
|
37
|
+
allowed: false,
|
|
38
|
+
reason: `Augmentation '${augName}' has no registered contract`
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// Check if field is in user namespace
|
|
42
|
+
if (!field.startsWith('_brainy.') && !field.startsWith('_augmentations.')) {
|
|
43
|
+
// It's a user field
|
|
44
|
+
const declaredField = contract.writes?.userFields?.find(f => f.field === field);
|
|
45
|
+
if (!declaredField) {
|
|
46
|
+
return {
|
|
47
|
+
allowed: false,
|
|
48
|
+
reason: `Augmentation '${augName}' did not declare intent to modify '${field}'`
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// Check for conflicts
|
|
52
|
+
const modifiers = this.modifications.get(field);
|
|
53
|
+
if (modifiers && modifiers.size > 1) {
|
|
54
|
+
const others = Array.from(modifiers).filter(a => a !== augName);
|
|
55
|
+
return {
|
|
56
|
+
allowed: true, // Still allowed but with warning
|
|
57
|
+
warnings: [`Field '${field}' is also modified by: ${others.join(', ')}`]
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return { allowed: true };
|
|
61
|
+
}
|
|
62
|
+
// Check internal fields
|
|
63
|
+
if (field.startsWith('_brainy.')) {
|
|
64
|
+
const internalField = contract.writes?.internalFields?.find(f => field === `_brainy.${f.field}`);
|
|
65
|
+
if (!internalField) {
|
|
66
|
+
return {
|
|
67
|
+
allowed: false,
|
|
68
|
+
reason: `Augmentation '${augName}' cannot modify internal field '${field}'`
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (internalField.permission !== 'granted') {
|
|
72
|
+
return {
|
|
73
|
+
allowed: false,
|
|
74
|
+
reason: `Permission not granted for internal field '${field}'`
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return { allowed: true };
|
|
78
|
+
}
|
|
79
|
+
// Check augmentation namespace
|
|
80
|
+
if (field.startsWith('_augmentations.')) {
|
|
81
|
+
const parts = field.split('.');
|
|
82
|
+
const targetAug = parts[1];
|
|
83
|
+
// Can only modify own namespace
|
|
84
|
+
if (targetAug !== augName) {
|
|
85
|
+
return {
|
|
86
|
+
allowed: false,
|
|
87
|
+
reason: `Cannot modify another augmentation's namespace: ${targetAug}`
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return { allowed: true };
|
|
91
|
+
}
|
|
92
|
+
return { allowed: true };
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create safe metadata proxy for an augmentation
|
|
96
|
+
*/
|
|
97
|
+
createSafeProxy(metadata, augName) {
|
|
98
|
+
const self = this;
|
|
99
|
+
return new Proxy(metadata, {
|
|
100
|
+
set(target, prop, value) {
|
|
101
|
+
const field = String(prop);
|
|
102
|
+
// Check permission
|
|
103
|
+
const permission = self.canModifyField(augName, field, value);
|
|
104
|
+
if (!permission.allowed) {
|
|
105
|
+
throw new Error(`[${augName}] ${permission.reason}`);
|
|
106
|
+
}
|
|
107
|
+
if (permission.warnings) {
|
|
108
|
+
console.warn(`[${augName}] Warning:`, ...permission.warnings);
|
|
109
|
+
}
|
|
110
|
+
// Track modification for audit
|
|
111
|
+
if (!target._audit) {
|
|
112
|
+
target._audit = [];
|
|
113
|
+
}
|
|
114
|
+
target._audit.push({
|
|
115
|
+
augmentation: augName,
|
|
116
|
+
field,
|
|
117
|
+
oldValue: target[prop],
|
|
118
|
+
newValue: value,
|
|
119
|
+
timestamp: Date.now()
|
|
120
|
+
});
|
|
121
|
+
target[prop] = value;
|
|
122
|
+
return true;
|
|
123
|
+
},
|
|
124
|
+
deleteProperty(target, prop) {
|
|
125
|
+
const field = String(prop);
|
|
126
|
+
const permission = self.canModifyField(augName, field, undefined);
|
|
127
|
+
if (!permission.allowed) {
|
|
128
|
+
throw new Error(`[${augName}] Cannot delete field: ${permission.reason}`);
|
|
129
|
+
}
|
|
130
|
+
delete target[prop];
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Example augmentation contracts
|
|
138
|
+
*/
|
|
139
|
+
export const EXAMPLE_CONTRACTS = {
|
|
140
|
+
// Enrichment augmentation that adds categories
|
|
141
|
+
categoryEnricher: {
|
|
142
|
+
name: 'categoryEnricher',
|
|
143
|
+
version: '1.0.0',
|
|
144
|
+
reads: {
|
|
145
|
+
userFields: ['title', 'description', 'content']
|
|
146
|
+
},
|
|
147
|
+
writes: {
|
|
148
|
+
userFields: [
|
|
149
|
+
{
|
|
150
|
+
field: 'category',
|
|
151
|
+
type: 'create',
|
|
152
|
+
description: 'Auto-detected category',
|
|
153
|
+
example: 'technology'
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
field: 'subcategories',
|
|
157
|
+
type: 'create',
|
|
158
|
+
description: 'List of relevant subcategories',
|
|
159
|
+
example: ['web', 'framework']
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
augmentationFields: [
|
|
163
|
+
{
|
|
164
|
+
field: 'confidence',
|
|
165
|
+
description: 'Confidence score of categorization'
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
},
|
|
169
|
+
guarantees: {
|
|
170
|
+
preservesExisting: true,
|
|
171
|
+
idempotent: true
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
// Translation augmentation
|
|
175
|
+
translator: {
|
|
176
|
+
name: 'translator',
|
|
177
|
+
version: '1.0.0',
|
|
178
|
+
reads: {
|
|
179
|
+
userFields: ['title', 'description']
|
|
180
|
+
},
|
|
181
|
+
writes: {
|
|
182
|
+
userFields: [
|
|
183
|
+
{
|
|
184
|
+
field: 'translations',
|
|
185
|
+
type: 'merge',
|
|
186
|
+
description: 'Translations in multiple languages',
|
|
187
|
+
example: { es: 'Título', fr: 'Titre' }
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
field: 'detectedLanguage',
|
|
191
|
+
type: 'create',
|
|
192
|
+
description: 'Detected source language',
|
|
193
|
+
example: 'en'
|
|
194
|
+
}
|
|
195
|
+
]
|
|
196
|
+
},
|
|
197
|
+
conflictResolution: {
|
|
198
|
+
strategy: 'merge',
|
|
199
|
+
priority: 10
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
// Sentiment analyzer
|
|
203
|
+
sentimentAnalyzer: {
|
|
204
|
+
name: 'sentimentAnalyzer',
|
|
205
|
+
version: '1.0.0',
|
|
206
|
+
reads: {
|
|
207
|
+
userFields: ['content', 'description', 'reviews']
|
|
208
|
+
},
|
|
209
|
+
writes: {
|
|
210
|
+
userFields: [
|
|
211
|
+
{
|
|
212
|
+
field: 'sentiment',
|
|
213
|
+
type: 'update',
|
|
214
|
+
description: 'Overall sentiment score',
|
|
215
|
+
example: { score: 0.8, label: 'positive' }
|
|
216
|
+
}
|
|
217
|
+
],
|
|
218
|
+
augmentationFields: [
|
|
219
|
+
{
|
|
220
|
+
field: 'analysis',
|
|
221
|
+
description: 'Detailed sentiment breakdown'
|
|
222
|
+
}
|
|
223
|
+
]
|
|
224
|
+
},
|
|
225
|
+
guarantees: {
|
|
226
|
+
reversible: true,
|
|
227
|
+
validatesTypes: true
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
// System augmentation with internal access
|
|
231
|
+
garbageCollector: {
|
|
232
|
+
name: 'garbageCollector',
|
|
233
|
+
version: '1.0.0',
|
|
234
|
+
reads: {
|
|
235
|
+
internalFields: ['_brainy.createdAt', '_brainy.lastAccessed']
|
|
236
|
+
},
|
|
237
|
+
writes: {
|
|
238
|
+
internalFields: [
|
|
239
|
+
{
|
|
240
|
+
field: 'deleted',
|
|
241
|
+
permission: 'granted',
|
|
242
|
+
reason: 'Soft delete expired items'
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
field: 'archived',
|
|
246
|
+
permission: 'granted',
|
|
247
|
+
reason: 'Archive old items'
|
|
248
|
+
}
|
|
249
|
+
]
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Augmentation base class with safety
|
|
255
|
+
*/
|
|
256
|
+
export class SafeAugmentation {
|
|
257
|
+
constructor(contract) {
|
|
258
|
+
this.contract = contract;
|
|
259
|
+
this.enforcer = new MetadataSafetyEnforcer();
|
|
260
|
+
this.enforcer.registerContract(contract);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Get safe metadata proxy
|
|
264
|
+
*/
|
|
265
|
+
getSafeMetadata(metadata) {
|
|
266
|
+
return this.enforcer.createSafeProxy(metadata, this.contract.name);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Example: Category enricher implementation
|
|
271
|
+
*/
|
|
272
|
+
export class CategoryEnricherAugmentation extends SafeAugmentation {
|
|
273
|
+
constructor() {
|
|
274
|
+
super(EXAMPLE_CONTRACTS.categoryEnricher);
|
|
275
|
+
}
|
|
276
|
+
async execute(metadata) {
|
|
277
|
+
const safe = this.getSafeMetadata(metadata);
|
|
278
|
+
// Read declared fields
|
|
279
|
+
const title = safe.title;
|
|
280
|
+
const description = safe.description;
|
|
281
|
+
// Analyze and categorize
|
|
282
|
+
const category = this.detectCategory(title, description);
|
|
283
|
+
const subcategories = this.detectSubcategories(title, description);
|
|
284
|
+
// Write to declared fields (will be checked by proxy)
|
|
285
|
+
safe.category = category; // ✅ Allowed - declared in contract
|
|
286
|
+
safe.subcategories = subcategories; // ✅ Allowed
|
|
287
|
+
// Try to write undeclared field
|
|
288
|
+
// safe.randomField = 'test' // ❌ Would throw error!
|
|
289
|
+
// Write to our augmentation namespace
|
|
290
|
+
if (!safe._augmentations)
|
|
291
|
+
safe._augmentations = {};
|
|
292
|
+
if (!safe._augmentations.categoryEnricher) {
|
|
293
|
+
safe._augmentations.categoryEnricher = {};
|
|
294
|
+
}
|
|
295
|
+
safe._augmentations.categoryEnricher.confidence = 0.95; // ✅ Allowed
|
|
296
|
+
return safe;
|
|
297
|
+
}
|
|
298
|
+
detectCategory(title, description) {
|
|
299
|
+
// Simplified logic
|
|
300
|
+
return 'technology';
|
|
301
|
+
}
|
|
302
|
+
detectSubcategories(title, description) {
|
|
303
|
+
return ['web', 'framework'];
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
//# sourceMappingURL=AugmentationMetadataContract.js.map
|
|
@@ -42,6 +42,7 @@ export interface APIServerConfig {
|
|
|
42
42
|
export declare class APIServerAugmentation extends BaseAugmentation {
|
|
43
43
|
readonly name = "api-server";
|
|
44
44
|
readonly timing: "after";
|
|
45
|
+
readonly metadata: "readonly";
|
|
45
46
|
readonly operations: ("all")[];
|
|
46
47
|
readonly priority = 5;
|
|
47
48
|
private config;
|
|
@@ -23,6 +23,7 @@ export class APIServerAugmentation extends BaseAugmentation {
|
|
|
23
23
|
super();
|
|
24
24
|
this.name = 'api-server';
|
|
25
25
|
this.timing = 'after';
|
|
26
|
+
this.metadata = 'readonly'; // API server reads metadata to serve data
|
|
26
27
|
this.operations = ['all'];
|
|
27
28
|
this.priority = 5; // Low priority, runs after other augmentations
|
|
28
29
|
this.clients = new Map();
|
|
@@ -29,6 +29,7 @@ interface BatchMetrics {
|
|
|
29
29
|
adaptiveAdjustments: number;
|
|
30
30
|
}
|
|
31
31
|
export declare class BatchProcessingAugmentation extends BaseAugmentation {
|
|
32
|
+
readonly metadata: "readonly";
|
|
32
33
|
name: string;
|
|
33
34
|
timing: "around";
|
|
34
35
|
operations: ("add" | "addNoun" | "addVerb" | "saveNoun" | "saveVerb" | "storage")[];
|
|
@@ -11,6 +11,7 @@ import { BaseAugmentation } from './brainyAugmentation.js';
|
|
|
11
11
|
export class BatchProcessingAugmentation extends BaseAugmentation {
|
|
12
12
|
constructor(config = {}) {
|
|
13
13
|
super();
|
|
14
|
+
this.metadata = 'readonly'; // Reads metadata for batching decisions
|
|
14
15
|
this.name = 'BatchProcessing';
|
|
15
16
|
this.timing = 'around';
|
|
16
17
|
this.operations = ['add', 'addNoun', 'addVerb', 'saveNoun', 'saveVerb', 'storage'];
|
|
@@ -11,6 +11,14 @@
|
|
|
11
11
|
* - IntelligentVerbScoring: Enhances relationship analysis
|
|
12
12
|
* - StreamingPipeline: Enables unlimited data processing
|
|
13
13
|
*/
|
|
14
|
+
/**
|
|
15
|
+
* Metadata access declaration for augmentations
|
|
16
|
+
*/
|
|
17
|
+
export interface MetadataAccess {
|
|
18
|
+
reads?: string[] | '*';
|
|
19
|
+
writes?: string[] | '*';
|
|
20
|
+
namespace?: string;
|
|
21
|
+
}
|
|
14
22
|
export interface BrainyAugmentation {
|
|
15
23
|
/**
|
|
16
24
|
* Unique identifier for the augmentation
|
|
@@ -24,6 +32,13 @@ export interface BrainyAugmentation {
|
|
|
24
32
|
* - 'replace': Replace the main operation entirely
|
|
25
33
|
*/
|
|
26
34
|
timing: 'before' | 'after' | 'around' | 'replace';
|
|
35
|
+
/**
|
|
36
|
+
* Metadata access contract - REQUIRED
|
|
37
|
+
* - 'none': No metadata access at all
|
|
38
|
+
* - 'readonly': Can read any metadata but cannot write
|
|
39
|
+
* - MetadataAccess: Specific fields to read/write
|
|
40
|
+
*/
|
|
41
|
+
metadata: 'none' | 'readonly' | MetadataAccess;
|
|
27
42
|
/**
|
|
28
43
|
* Which operations this augmentation applies to
|
|
29
44
|
* Granular operation matching for precise augmentation targeting
|
|
@@ -90,6 +105,7 @@ export interface AugmentationContext {
|
|
|
90
105
|
export declare abstract class BaseAugmentation implements BrainyAugmentation {
|
|
91
106
|
abstract name: string;
|
|
92
107
|
abstract timing: 'before' | 'after' | 'around' | 'replace';
|
|
108
|
+
abstract metadata: 'none' | 'readonly' | MetadataAccess;
|
|
93
109
|
abstract operations: ('add' | 'addNoun' | 'addVerb' | 'saveNoun' | 'saveVerb' | 'updateMetadata' | 'delete' | 'deleteVerb' | 'clear' | 'get' | 'search' | 'searchText' | 'searchByNounTypes' | 'findSimilar' | 'searchWithCursor' | 'relate' | 'getConnections' | 'storage' | 'backup' | 'restore' | 'all')[];
|
|
94
110
|
abstract priority: number;
|
|
95
111
|
protected context?: AugmentationContext;
|
|
@@ -28,6 +28,7 @@ export interface CacheConfig {
|
|
|
28
28
|
export declare class CacheAugmentation extends BaseAugmentation {
|
|
29
29
|
readonly name = "cache";
|
|
30
30
|
readonly timing: "around";
|
|
31
|
+
readonly metadata: "none";
|
|
31
32
|
operations: ("search" | "add" | "delete" | "clear" | "all")[];
|
|
32
33
|
readonly priority = 50;
|
|
33
34
|
private searchCache;
|
|
@@ -23,6 +23,7 @@ export class CacheAugmentation extends BaseAugmentation {
|
|
|
23
23
|
super();
|
|
24
24
|
this.name = 'cache';
|
|
25
25
|
this.timing = 'around';
|
|
26
|
+
this.metadata = 'none'; // Cache doesn't access metadata
|
|
26
27
|
this.operations = ['search', 'add', 'delete', 'clear', 'all'];
|
|
27
28
|
this.priority = 50; // Mid-priority, runs after data operations
|
|
28
29
|
this.searchCache = null;
|
|
@@ -17,6 +17,7 @@ export interface WebSocketConnection {
|
|
|
17
17
|
*/
|
|
18
18
|
declare abstract class BaseConduitAugmentation extends BaseAugmentation {
|
|
19
19
|
readonly timing: "after";
|
|
20
|
+
readonly metadata: "readonly";
|
|
20
21
|
readonly operations: ("addNoun" | "delete" | "addVerb")[];
|
|
21
22
|
readonly priority = 20;
|
|
22
23
|
protected connections: Map<string, any>;
|
|
@@ -14,6 +14,7 @@ class BaseConduitAugmentation extends BaseAugmentation {
|
|
|
14
14
|
constructor() {
|
|
15
15
|
super(...arguments);
|
|
16
16
|
this.timing = 'after'; // Conduits run after operations to sync
|
|
17
|
+
this.metadata = 'readonly'; // Conduits read metadata to pass to external systems
|
|
17
18
|
this.operations = ['addNoun', 'delete', 'addVerb'];
|
|
18
19
|
this.priority = 20; // Medium-low priority
|
|
19
20
|
this.connections = new Map();
|
|
@@ -11,6 +11,7 @@ export class ConnectionPoolAugmentation extends BaseAugmentation {
|
|
|
11
11
|
super();
|
|
12
12
|
this.name = 'ConnectionPool';
|
|
13
13
|
this.timing = 'around';
|
|
14
|
+
this.metadata = 'none'; // Connection pooling doesn't access metadata
|
|
14
15
|
this.operations = ['storage'];
|
|
15
16
|
this.priority = 95; // Very high priority for storage operations
|
|
16
17
|
this.connections = new Map();
|
|
@@ -46,6 +46,7 @@ export interface EntityMapping {
|
|
|
46
46
|
* Optimized for streaming data scenarios like Bluesky firehose processing
|
|
47
47
|
*/
|
|
48
48
|
export declare class EntityRegistryAugmentation extends BaseAugmentation {
|
|
49
|
+
readonly metadata: "readonly";
|
|
49
50
|
readonly name = "entity-registry";
|
|
50
51
|
readonly description = "Fast external-ID to internal-UUID mapping for streaming data";
|
|
51
52
|
readonly timing: 'before' | 'after' | 'around' | 'replace';
|
|
@@ -114,6 +115,7 @@ export declare class EntityRegistryAugmentation extends BaseAugmentation {
|
|
|
114
115
|
private estimateMemoryUsage;
|
|
115
116
|
}
|
|
116
117
|
export declare class AutoRegisterEntitiesAugmentation extends BaseAugmentation {
|
|
118
|
+
readonly metadata: "readonly";
|
|
117
119
|
readonly name = "auto-register-entities";
|
|
118
120
|
readonly description = "Automatically register entities in the registry when added";
|
|
119
121
|
readonly timing: 'before' | 'after' | 'around' | 'replace';
|
|
@@ -11,6 +11,7 @@ import { BaseAugmentation } from './brainyAugmentation.js';
|
|
|
11
11
|
export class EntityRegistryAugmentation extends BaseAugmentation {
|
|
12
12
|
constructor(config = {}) {
|
|
13
13
|
super();
|
|
14
|
+
this.metadata = 'readonly'; // Reads metadata to register entities
|
|
14
15
|
this.name = 'entity-registry';
|
|
15
16
|
this.description = 'Fast external-ID to internal-UUID mapping for streaming data';
|
|
16
17
|
this.timing = 'before';
|
|
@@ -355,6 +356,7 @@ export class EntityRegistryAugmentation extends BaseAugmentation {
|
|
|
355
356
|
export class AutoRegisterEntitiesAugmentation extends BaseAugmentation {
|
|
356
357
|
constructor() {
|
|
357
358
|
super(...arguments);
|
|
359
|
+
this.metadata = 'readonly'; // Reads metadata for auto-registration
|
|
358
360
|
this.name = 'auto-register-entities';
|
|
359
361
|
this.description = 'Automatically register entities in the registry when added';
|
|
360
362
|
this.timing = 'after';
|
|
@@ -27,6 +27,7 @@ export interface IndexConfig {
|
|
|
27
27
|
* - Zero-config with smart defaults
|
|
28
28
|
*/
|
|
29
29
|
export declare class IndexAugmentation extends BaseAugmentation {
|
|
30
|
+
readonly metadata: "readonly";
|
|
30
31
|
readonly name = "index";
|
|
31
32
|
readonly timing: "after";
|
|
32
33
|
operations: ("add" | "updateMetadata" | "delete" | "clear" | "all")[];
|
|
@@ -21,6 +21,7 @@ import { MetadataIndexManager } from '../utils/metadataIndex.js';
|
|
|
21
21
|
export class IndexAugmentation extends BaseAugmentation {
|
|
22
22
|
constructor(config = {}) {
|
|
23
23
|
super();
|
|
24
|
+
this.metadata = 'readonly'; // Reads metadata to build indexes
|
|
24
25
|
this.name = 'index';
|
|
25
26
|
this.timing = 'after';
|
|
26
27
|
this.operations = ['add', 'updateMetadata', 'delete', 'clear', 'all'];
|
|
@@ -51,6 +51,10 @@ interface ScoringMetrics {
|
|
|
51
51
|
export declare class IntelligentVerbScoringAugmentation extends BaseAugmentation {
|
|
52
52
|
name: string;
|
|
53
53
|
timing: "around";
|
|
54
|
+
readonly metadata: {
|
|
55
|
+
reads: string[];
|
|
56
|
+
writes: string[];
|
|
57
|
+
};
|
|
54
58
|
operations: ("addVerb" | "relate")[];
|
|
55
59
|
priority: number;
|
|
56
60
|
get enabled(): boolean;
|
|
@@ -20,6 +20,10 @@ export class IntelligentVerbScoringAugmentation extends BaseAugmentation {
|
|
|
20
20
|
super();
|
|
21
21
|
this.name = 'IntelligentVerbScoring';
|
|
22
22
|
this.timing = 'around';
|
|
23
|
+
this.metadata = {
|
|
24
|
+
reads: ['type', 'verb', 'source', 'target'],
|
|
25
|
+
writes: ['weight', 'confidence', 'intelligentScoring']
|
|
26
|
+
}; // Adds scoring metadata to verbs
|
|
23
27
|
this.operations = ['addVerb', 'relate'];
|
|
24
28
|
this.priority = 10; // Enhancement feature - runs after core operations
|
|
25
29
|
this.relationshipStats = new Map();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime enforcement of metadata contracts
|
|
3
|
+
* Ensures augmentations only access declared fields
|
|
4
|
+
*/
|
|
5
|
+
import { BrainyAugmentation } from './brainyAugmentation.js';
|
|
6
|
+
export declare class MetadataEnforcer {
|
|
7
|
+
/**
|
|
8
|
+
* Enforce metadata access based on augmentation contract
|
|
9
|
+
* Returns a wrapped metadata object that enforces the contract
|
|
10
|
+
*/
|
|
11
|
+
static enforce(augmentation: BrainyAugmentation, metadata: any, operation?: 'read' | 'write'): any;
|
|
12
|
+
/**
|
|
13
|
+
* Validate that an augmentation's actual behavior matches its contract
|
|
14
|
+
* Used in testing to verify contracts are accurate
|
|
15
|
+
*/
|
|
16
|
+
static validateContract(augmentation: BrainyAugmentation, testMetadata?: any): Promise<{
|
|
17
|
+
valid: boolean;
|
|
18
|
+
violations: string[];
|
|
19
|
+
}>;
|
|
20
|
+
}
|