@soulcraft/brainy 1.5.0 → 2.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/CHANGELOG.md +188 -0
- package/LICENSE +2 -2
- package/README.md +201 -596
- package/bin/brainy-interactive.js +564 -0
- package/bin/brainy-ts.js +18 -0
- package/bin/brainy.js +672 -81
- package/dist/augmentationPipeline.d.ts +48 -220
- package/dist/augmentationPipeline.js +60 -508
- package/dist/augmentationRegistry.d.ts +22 -31
- package/dist/augmentationRegistry.js +28 -79
- package/dist/augmentations/apiServerAugmentation.d.ts +108 -0
- package/dist/augmentations/apiServerAugmentation.js +502 -0
- package/dist/augmentations/batchProcessingAugmentation.d.ts +95 -0
- package/dist/augmentations/batchProcessingAugmentation.js +567 -0
- package/dist/augmentations/brainyAugmentation.d.ts +153 -0
- package/dist/augmentations/brainyAugmentation.js +145 -0
- package/dist/augmentations/cacheAugmentation.d.ts +105 -0
- package/dist/augmentations/cacheAugmentation.js +238 -0
- package/dist/augmentations/conduitAugmentations.d.ts +54 -156
- package/dist/augmentations/conduitAugmentations.js +156 -1082
- package/dist/augmentations/connectionPoolAugmentation.d.ts +62 -0
- package/dist/augmentations/connectionPoolAugmentation.js +316 -0
- package/dist/augmentations/defaultAugmentations.d.ts +53 -0
- package/dist/augmentations/defaultAugmentations.js +88 -0
- package/dist/augmentations/entityRegistryAugmentation.d.ts +126 -0
- package/dist/augmentations/entityRegistryAugmentation.js +386 -0
- package/dist/augmentations/indexAugmentation.d.ts +117 -0
- package/dist/augmentations/indexAugmentation.js +284 -0
- package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +152 -0
- package/dist/augmentations/intelligentVerbScoringAugmentation.js +554 -0
- package/dist/augmentations/metricsAugmentation.d.ts +202 -0
- package/dist/augmentations/metricsAugmentation.js +291 -0
- package/dist/augmentations/monitoringAugmentation.d.ts +94 -0
- package/dist/augmentations/monitoringAugmentation.js +227 -0
- package/dist/augmentations/neuralImport.d.ts +50 -117
- package/dist/augmentations/neuralImport.js +255 -629
- package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +52 -0
- package/dist/augmentations/requestDeduplicatorAugmentation.js +162 -0
- package/dist/augmentations/serverSearchAugmentations.d.ts +43 -22
- package/dist/augmentations/serverSearchAugmentations.js +125 -72
- package/dist/augmentations/storageAugmentation.d.ts +54 -0
- package/dist/augmentations/storageAugmentation.js +93 -0
- package/dist/augmentations/storageAugmentations.d.ts +96 -0
- package/dist/augmentations/storageAugmentations.js +182 -0
- package/dist/augmentations/synapseAugmentation.d.ts +156 -0
- package/dist/augmentations/synapseAugmentation.js +312 -0
- package/dist/augmentations/walAugmentation.d.ts +108 -0
- package/dist/augmentations/walAugmentation.js +515 -0
- package/dist/brainyData.d.ts +404 -130
- package/dist/brainyData.js +1331 -853
- package/dist/chat/BrainyChat.d.ts +16 -8
- package/dist/chat/BrainyChat.js +60 -32
- package/dist/chat/ChatCLI.d.ts +1 -1
- package/dist/chat/ChatCLI.js +6 -6
- package/dist/cli/catalog.d.ts +3 -3
- package/dist/cli/catalog.js +116 -70
- package/dist/cli/commands/core.d.ts +61 -0
- package/dist/cli/commands/core.js +348 -0
- package/dist/cli/commands/neural.d.ts +25 -0
- package/dist/cli/commands/neural.js +508 -0
- package/dist/cli/commands/utility.d.ts +37 -0
- package/dist/cli/commands/utility.js +276 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.js +167 -0
- package/dist/cli/interactive.d.ts +164 -0
- package/dist/cli/interactive.js +542 -0
- package/dist/cortex/neuralImport.js +5 -5
- package/dist/critical/model-guardian.js +11 -4
- package/dist/embeddings/lightweight-embedder.d.ts +23 -0
- package/dist/embeddings/lightweight-embedder.js +136 -0
- package/dist/embeddings/universal-memory-manager.d.ts +38 -0
- package/dist/embeddings/universal-memory-manager.js +206 -0
- package/dist/embeddings/worker-embedding.d.ts +7 -0
- package/dist/embeddings/worker-embedding.js +77 -0
- package/dist/embeddings/worker-manager.d.ts +28 -0
- package/dist/embeddings/worker-manager.js +162 -0
- package/dist/examples/basicUsage.js +7 -7
- package/dist/graph/pathfinding.d.ts +78 -0
- package/dist/graph/pathfinding.js +393 -0
- package/dist/hnsw/hnswIndex.d.ts +13 -0
- package/dist/hnsw/hnswIndex.js +35 -0
- package/dist/hnsw/hnswIndexOptimized.d.ts +1 -0
- package/dist/hnsw/hnswIndexOptimized.js +3 -0
- package/dist/index.d.ts +9 -11
- package/dist/index.js +21 -11
- package/dist/indices/fieldIndex.d.ts +76 -0
- package/dist/indices/fieldIndex.js +357 -0
- package/dist/mcp/brainyMCPAdapter.js +3 -2
- package/dist/mcp/mcpAugmentationToolset.js +11 -17
- package/dist/neural/embeddedPatterns.d.ts +41 -0
- package/dist/neural/embeddedPatterns.js +4044 -0
- package/dist/neural/naturalLanguageProcessor.d.ts +94 -0
- package/dist/neural/naturalLanguageProcessor.js +317 -0
- package/dist/neural/naturalLanguageProcessorStatic.d.ts +64 -0
- package/dist/neural/naturalLanguageProcessorStatic.js +151 -0
- package/dist/neural/neuralAPI.d.ts +255 -0
- package/dist/neural/neuralAPI.js +612 -0
- package/dist/neural/patternLibrary.d.ts +101 -0
- package/dist/neural/patternLibrary.js +313 -0
- package/dist/neural/patterns.d.ts +27 -0
- package/dist/neural/patterns.js +68 -0
- package/dist/neural/staticPatternMatcher.d.ts +35 -0
- package/dist/neural/staticPatternMatcher.js +153 -0
- package/dist/scripts/precomputePatternEmbeddings.d.ts +19 -0
- package/dist/scripts/precomputePatternEmbeddings.js +100 -0
- package/dist/storage/adapters/fileSystemStorage.d.ts +5 -0
- package/dist/storage/adapters/fileSystemStorage.js +20 -0
- package/dist/storage/adapters/s3CompatibleStorage.d.ts +5 -0
- package/dist/storage/adapters/s3CompatibleStorage.js +16 -0
- package/dist/storage/enhancedClearOperations.d.ts +83 -0
- package/dist/storage/enhancedClearOperations.js +345 -0
- package/dist/storage/storageFactory.js +31 -27
- package/dist/triple/TripleIntelligence.d.ts +134 -0
- package/dist/triple/TripleIntelligence.js +548 -0
- package/dist/types/augmentations.d.ts +45 -344
- package/dist/types/augmentations.js +5 -2
- package/dist/types/brainyDataInterface.d.ts +20 -10
- package/dist/types/graphTypes.d.ts +46 -0
- package/dist/types/graphTypes.js +16 -2
- package/dist/utils/BoundedRegistry.d.ts +29 -0
- package/dist/utils/BoundedRegistry.js +54 -0
- package/dist/utils/embedding.js +20 -3
- package/dist/utils/hybridModelManager.js +10 -5
- package/dist/utils/metadataFilter.d.ts +33 -19
- package/dist/utils/metadataFilter.js +58 -23
- package/dist/utils/metadataIndex.d.ts +37 -6
- package/dist/utils/metadataIndex.js +427 -64
- package/dist/utils/requestDeduplicator.d.ts +10 -0
- package/dist/utils/requestDeduplicator.js +24 -0
- package/dist/utils/unifiedCache.d.ts +103 -0
- package/dist/utils/unifiedCache.js +311 -0
- package/package.json +43 -128
- package/scripts/ensure-models.js +108 -0
- package/scripts/prepare-models.js +387 -0
- package/OFFLINE_MODELS.md +0 -56
- package/dist/intelligence/neuralEngine.d.ts +0 -207
- package/dist/intelligence/neuralEngine.js +0 -706
- package/dist/utils/modelLoader.d.ts +0 -32
- package/dist/utils/modelLoader.js +0 -219
- package/dist/utils/modelManager.d.ts +0 -77
- package/dist/utils/modelManager.js +0 -219
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Synapse Augmentation
|
|
3
|
+
*
|
|
4
|
+
* Synapses are special augmentations that provide bidirectional data sync
|
|
5
|
+
* with external platforms (Notion, Salesforce, Slack, etc.)
|
|
6
|
+
*
|
|
7
|
+
* Like biological synapses that transmit signals between neurons, these
|
|
8
|
+
* connect Brainy to external data sources, enabling seamless information flow.
|
|
9
|
+
*
|
|
10
|
+
* They are managed through the Brain Cloud augmentation registry alongside
|
|
11
|
+
* other augmentations, enabling unified discovery, installation, and updates.
|
|
12
|
+
*
|
|
13
|
+
* Example synapses:
|
|
14
|
+
* - NotionSynapse: Sync pages, databases, and blocks
|
|
15
|
+
* - SalesforceSynapse: Sync contacts, leads, opportunities
|
|
16
|
+
* - SlackSynapse: Sync messages, channels, users
|
|
17
|
+
* - GoogleDriveSynapse: Sync documents, sheets, presentations
|
|
18
|
+
*/
|
|
19
|
+
import { BaseAugmentation } from './brainyAugmentation.js';
|
|
20
|
+
import { NeuralImportAugmentation } from './neuralImport.js';
|
|
21
|
+
/**
|
|
22
|
+
* Base class for all synapse augmentations
|
|
23
|
+
* Provides common functionality for external data synchronization
|
|
24
|
+
*/
|
|
25
|
+
export class SynapseAugmentation extends BaseAugmentation {
|
|
26
|
+
constructor() {
|
|
27
|
+
super(...arguments);
|
|
28
|
+
// BrainyAugmentation properties
|
|
29
|
+
this.timing = 'after';
|
|
30
|
+
this.operations = ['all'];
|
|
31
|
+
this.priority = 10;
|
|
32
|
+
// State management
|
|
33
|
+
this.syncInProgress = false;
|
|
34
|
+
this.syncStats = {
|
|
35
|
+
totalSyncs: 0,
|
|
36
|
+
totalItems: 0,
|
|
37
|
+
lastSync: undefined
|
|
38
|
+
};
|
|
39
|
+
this.useNeuralImport = true; // Enable by default
|
|
40
|
+
}
|
|
41
|
+
async onInit() {
|
|
42
|
+
// Initialize Neural Import if available
|
|
43
|
+
if (this.useNeuralImport && this.context?.brain) {
|
|
44
|
+
try {
|
|
45
|
+
// Check if neural import is already loaded
|
|
46
|
+
const existingNeuralImport = this.context.brain.augmentations?.get('neural-import');
|
|
47
|
+
if (existingNeuralImport) {
|
|
48
|
+
this.neuralImport = existingNeuralImport;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// Create a new instance for this synapse
|
|
52
|
+
this.neuralImport = new NeuralImportAugmentation();
|
|
53
|
+
// NeuralImport will be initialized when the synapse is added to BrainyData
|
|
54
|
+
// await this.neuralImport.initialize()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.warn(`[${this.synapseId}] Neural Import not available, using basic import`);
|
|
59
|
+
this.useNeuralImport = false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
await this.onInitialize();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* BrainyAugmentation execute method
|
|
66
|
+
* Intercepts operations to sync external data when relevant
|
|
67
|
+
*/
|
|
68
|
+
async execute(operation, params, next) {
|
|
69
|
+
// Execute the main operation first
|
|
70
|
+
const result = await next();
|
|
71
|
+
// After certain operations, check if we should sync
|
|
72
|
+
if (this.shouldSync(operation, params)) {
|
|
73
|
+
// Start async sync in background
|
|
74
|
+
this.backgroundSync().catch(error => {
|
|
75
|
+
console.error(`[${this.synapseId}] Background sync failed:`, error);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Determine if sync should be triggered after an operation
|
|
82
|
+
*/
|
|
83
|
+
shouldSync(operation, params) {
|
|
84
|
+
// Override in implementations for specific sync triggers
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Background sync process
|
|
89
|
+
*/
|
|
90
|
+
async backgroundSync() {
|
|
91
|
+
if (this.syncInProgress)
|
|
92
|
+
return;
|
|
93
|
+
this.syncInProgress = true;
|
|
94
|
+
try {
|
|
95
|
+
await this.incrementalSync(this.lastSyncId);
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
this.syncInProgress = false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async onShutdown() {
|
|
102
|
+
if (this.syncInProgress) {
|
|
103
|
+
await this.stopSync();
|
|
104
|
+
}
|
|
105
|
+
await this.onSynapseShutdown();
|
|
106
|
+
}
|
|
107
|
+
async onSynapseShutdown() {
|
|
108
|
+
// Override in implementations for cleanup
|
|
109
|
+
}
|
|
110
|
+
async stopSync() {
|
|
111
|
+
this.syncInProgress = false;
|
|
112
|
+
}
|
|
113
|
+
async getSynapseStatus() {
|
|
114
|
+
const connectionTest = await this.testConnection();
|
|
115
|
+
return {
|
|
116
|
+
success: true,
|
|
117
|
+
data: {
|
|
118
|
+
status: this.syncInProgress ? 'syncing' :
|
|
119
|
+
connectionTest.success ? 'connected' : 'disconnected',
|
|
120
|
+
lastSync: this.syncStats.lastSync,
|
|
121
|
+
totalSyncs: this.syncStats.totalSyncs,
|
|
122
|
+
totalItems: this.syncStats.totalItems
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Helper method to store synced data in Brainy
|
|
128
|
+
* Optionally uses Neural Import for intelligent processing
|
|
129
|
+
*/
|
|
130
|
+
async storeInBrainy(content, metadata, options = {}) {
|
|
131
|
+
if (!this.context?.brain) {
|
|
132
|
+
throw new Error('BrainyData context not initialized');
|
|
133
|
+
}
|
|
134
|
+
// Add synapse source metadata
|
|
135
|
+
const enrichedMetadata = {
|
|
136
|
+
...metadata,
|
|
137
|
+
_synapse: this.synapseId,
|
|
138
|
+
_syncedAt: new Date().toISOString()
|
|
139
|
+
};
|
|
140
|
+
// Use Neural Import for intelligent processing if available
|
|
141
|
+
if (this.neuralImport && (options.useNeuralImport ?? this.useNeuralImport)) {
|
|
142
|
+
try {
|
|
143
|
+
// Process through Neural Import for entity/relationship detection
|
|
144
|
+
const rawData = options.rawData ||
|
|
145
|
+
(typeof content === 'string' ? content : JSON.stringify(content));
|
|
146
|
+
const neuralResult = await this.neuralImport.processRawData(rawData, options.dataType || 'json', {
|
|
147
|
+
sourceSystem: this.synapseId,
|
|
148
|
+
metadata: enrichedMetadata
|
|
149
|
+
});
|
|
150
|
+
if (neuralResult.success && neuralResult.data) {
|
|
151
|
+
// Store detected nouns (entities)
|
|
152
|
+
for (const noun of neuralResult.data.nouns) {
|
|
153
|
+
await this.context.brain.addNoun(noun, {
|
|
154
|
+
...enrichedMetadata,
|
|
155
|
+
_neuralConfidence: neuralResult.data.confidence,
|
|
156
|
+
_neuralInsights: neuralResult.data.insights
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
// Store detected verbs (relationships)
|
|
160
|
+
for (const verb of neuralResult.data.verbs) {
|
|
161
|
+
// Parse verb format: "source->relation->target"
|
|
162
|
+
const parts = verb.split('->');
|
|
163
|
+
if (parts.length === 3) {
|
|
164
|
+
await this.context.brain.relate(parts[0], // source
|
|
165
|
+
parts[2], // target
|
|
166
|
+
parts[1], // verb type
|
|
167
|
+
enrichedMetadata);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Store original content with neural metadata
|
|
171
|
+
if (typeof content === 'string') {
|
|
172
|
+
await this.context.brain.add(content, {
|
|
173
|
+
...enrichedMetadata,
|
|
174
|
+
_neuralProcessed: true,
|
|
175
|
+
_neuralConfidence: neuralResult.data.confidence,
|
|
176
|
+
_detectedEntities: neuralResult.data.nouns.length,
|
|
177
|
+
_detectedRelationships: neuralResult.data.verbs.length
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return; // Successfully processed with Neural Import
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
console.warn(`[${this.synapseId}] Neural Import processing failed, falling back to basic import:`, error);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// Fallback to basic storage
|
|
188
|
+
if (typeof content === 'string') {
|
|
189
|
+
await this.context.brain.add(content, enrichedMetadata);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
// For structured data, store as JSON
|
|
193
|
+
await this.context.brain.add(JSON.stringify(content), enrichedMetadata);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Helper method to query existing synced data
|
|
198
|
+
*/
|
|
199
|
+
async queryBrainyData(filter) {
|
|
200
|
+
if (!this.context?.brain) {
|
|
201
|
+
throw new Error('BrainyData context not initialized');
|
|
202
|
+
}
|
|
203
|
+
const searchFilter = {
|
|
204
|
+
...filter,
|
|
205
|
+
_synapse: this.synapseId
|
|
206
|
+
};
|
|
207
|
+
return this.context.brain.find({
|
|
208
|
+
where: searchFilter
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Example implementation for reference
|
|
214
|
+
* Real synapses would be in Brain Cloud registry
|
|
215
|
+
*/
|
|
216
|
+
export class ExampleFileSystemSynapse extends SynapseAugmentation {
|
|
217
|
+
constructor() {
|
|
218
|
+
super(...arguments);
|
|
219
|
+
this.name = 'example-filesystem-synapse';
|
|
220
|
+
this.description = 'Example synapse for local file system with Neural Import intelligence';
|
|
221
|
+
this.synapseId = 'filesystem';
|
|
222
|
+
this.supportedTypes = ['text', 'markdown', 'json', 'csv'];
|
|
223
|
+
}
|
|
224
|
+
async onInitialize() {
|
|
225
|
+
// Initialize file system watcher, etc.
|
|
226
|
+
}
|
|
227
|
+
async testConnection() {
|
|
228
|
+
// Test if we can access the configured directory
|
|
229
|
+
return {
|
|
230
|
+
success: true,
|
|
231
|
+
data: true
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
async startSync(options) {
|
|
235
|
+
const startTime = Date.now();
|
|
236
|
+
// Example: Read files from a directory and sync to Brainy
|
|
237
|
+
// This would normally scan a directory, but here's a conceptual example:
|
|
238
|
+
const exampleFiles = [
|
|
239
|
+
{
|
|
240
|
+
path: '/data/notes.md',
|
|
241
|
+
content: '# Project Notes\nDiscuss roadmap with team\nReview Q1 metrics',
|
|
242
|
+
type: 'markdown'
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
path: '/data/contacts.json',
|
|
246
|
+
content: { name: 'John Doe', role: 'Developer', team: 'Engineering' },
|
|
247
|
+
type: 'json'
|
|
248
|
+
}
|
|
249
|
+
];
|
|
250
|
+
let synced = 0;
|
|
251
|
+
const errors = [];
|
|
252
|
+
for (const file of exampleFiles) {
|
|
253
|
+
try {
|
|
254
|
+
// Use Neural Import for intelligent processing
|
|
255
|
+
await this.storeInBrainy(file.content, {
|
|
256
|
+
path: file.path,
|
|
257
|
+
fileType: file.type,
|
|
258
|
+
syncedFrom: 'filesystem'
|
|
259
|
+
}, {
|
|
260
|
+
useNeuralImport: true, // Enable AI processing
|
|
261
|
+
dataType: file.type
|
|
262
|
+
});
|
|
263
|
+
synced++;
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
errors.push({
|
|
267
|
+
item: file.path,
|
|
268
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
this.syncStats.totalSyncs++;
|
|
273
|
+
this.syncStats.totalItems += synced;
|
|
274
|
+
this.syncStats.lastSync = new Date().toISOString();
|
|
275
|
+
return {
|
|
276
|
+
success: true,
|
|
277
|
+
data: {
|
|
278
|
+
synced,
|
|
279
|
+
failed: errors.length,
|
|
280
|
+
skipped: 0,
|
|
281
|
+
duration: Date.now() - startTime,
|
|
282
|
+
errors: errors.length > 0 ? errors : undefined
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
async incrementalSync(lastSyncId) {
|
|
287
|
+
const startTime = Date.now();
|
|
288
|
+
// Example: Check for modified files since last sync
|
|
289
|
+
return {
|
|
290
|
+
success: true,
|
|
291
|
+
data: {
|
|
292
|
+
synced: 0,
|
|
293
|
+
failed: 0,
|
|
294
|
+
skipped: 0,
|
|
295
|
+
duration: Date.now() - startTime,
|
|
296
|
+
hasMore: false
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
async previewSync(limit = 10) {
|
|
301
|
+
// Example: List files that would be synced
|
|
302
|
+
return {
|
|
303
|
+
success: true,
|
|
304
|
+
data: {
|
|
305
|
+
items: [],
|
|
306
|
+
totalCount: 0,
|
|
307
|
+
estimatedDuration: 0
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
//# sourceMappingURL=synapseAugmentation.js.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write-Ahead Log (WAL) Augmentation
|
|
3
|
+
*
|
|
4
|
+
* Provides file-based durability and atomicity for storage operations
|
|
5
|
+
* Automatically enabled for all critical storage operations
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - True file-based persistence for crash recovery
|
|
9
|
+
* - Operation replay after startup
|
|
10
|
+
* - Automatic log rotation and cleanup
|
|
11
|
+
* - Cross-platform compatibility (filesystem, OPFS, cloud)
|
|
12
|
+
*/
|
|
13
|
+
import { BaseAugmentation } from './brainyAugmentation.js';
|
|
14
|
+
interface WALConfig {
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
immediateWrites?: boolean;
|
|
17
|
+
adaptivePersistence?: boolean;
|
|
18
|
+
walPrefix?: string;
|
|
19
|
+
maxSize?: number;
|
|
20
|
+
checkpointInterval?: number;
|
|
21
|
+
autoRecover?: boolean;
|
|
22
|
+
maxRetries?: number;
|
|
23
|
+
}
|
|
24
|
+
export declare class WALAugmentation extends BaseAugmentation {
|
|
25
|
+
name: string;
|
|
26
|
+
timing: "around";
|
|
27
|
+
operations: ("addNoun" | "addVerb" | "saveNoun" | "saveVerb" | "updateMetadata" | "delete" | "deleteVerb" | "clear")[];
|
|
28
|
+
priority: number;
|
|
29
|
+
private config;
|
|
30
|
+
private currentLogId;
|
|
31
|
+
private operationCounter;
|
|
32
|
+
private checkpointTimer?;
|
|
33
|
+
private isRecovering;
|
|
34
|
+
constructor(config?: WALConfig);
|
|
35
|
+
protected onInitialize(): Promise<void>;
|
|
36
|
+
shouldExecute(operation: string, params: any): boolean;
|
|
37
|
+
execute<T = any>(operation: string, params: any, next: () => Promise<T>): Promise<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Asynchronous WAL entry logging (fire-and-forget for immediate writes)
|
|
40
|
+
*/
|
|
41
|
+
private logAsyncWALEntry;
|
|
42
|
+
/**
|
|
43
|
+
* Write WAL entry to persistent storage using storage adapter
|
|
44
|
+
*/
|
|
45
|
+
private writeWALEntry;
|
|
46
|
+
/**
|
|
47
|
+
* Recover pending operations from all existing WAL files
|
|
48
|
+
*/
|
|
49
|
+
private recoverPendingOperations;
|
|
50
|
+
/**
|
|
51
|
+
* Find all WAL files in storage
|
|
52
|
+
*/
|
|
53
|
+
private findWALFiles;
|
|
54
|
+
/**
|
|
55
|
+
* Read WAL entries from a file
|
|
56
|
+
*/
|
|
57
|
+
private readWALEntries;
|
|
58
|
+
/**
|
|
59
|
+
* Find operations that were started but not completed
|
|
60
|
+
*/
|
|
61
|
+
private findPendingOperations;
|
|
62
|
+
/**
|
|
63
|
+
* Replay an operation during recovery
|
|
64
|
+
*/
|
|
65
|
+
private replayOperation;
|
|
66
|
+
/**
|
|
67
|
+
* Create a checkpoint to mark a point in time
|
|
68
|
+
*/
|
|
69
|
+
private createCheckpoint;
|
|
70
|
+
/**
|
|
71
|
+
* Check if log rotation is needed
|
|
72
|
+
*/
|
|
73
|
+
private checkLogRotation;
|
|
74
|
+
/**
|
|
75
|
+
* Sanitize parameters for logging (remove large objects)
|
|
76
|
+
*/
|
|
77
|
+
private sanitizeParams;
|
|
78
|
+
/**
|
|
79
|
+
* Get WAL statistics
|
|
80
|
+
*/
|
|
81
|
+
getStats(): {
|
|
82
|
+
enabled: boolean;
|
|
83
|
+
currentLogId: string;
|
|
84
|
+
operationCount: number;
|
|
85
|
+
logSize: number;
|
|
86
|
+
pendingOperations: number;
|
|
87
|
+
failedOperations: number;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Manually trigger checkpoint
|
|
91
|
+
*/
|
|
92
|
+
checkpoint(): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Manually trigger log rotation
|
|
95
|
+
*/
|
|
96
|
+
rotate(): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Write WAL data directly to storage without embedding
|
|
99
|
+
* This bypasses the brain's AI processing pipeline for raw WAL data
|
|
100
|
+
*/
|
|
101
|
+
private writeWALFileDirectly;
|
|
102
|
+
/**
|
|
103
|
+
* Read WAL data directly from storage without embedding
|
|
104
|
+
*/
|
|
105
|
+
private readWALFileDirectly;
|
|
106
|
+
protected onShutdown(): Promise<void>;
|
|
107
|
+
}
|
|
108
|
+
export {};
|