@soulcraft/brainy 1.5.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +188 -0
- package/LICENSE +2 -2
- package/README.md +200 -595
- 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 +40 -125
- 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,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage Augmentation Base Classes
|
|
3
|
+
*
|
|
4
|
+
* Unifies storage adapters and augmentations into a single system.
|
|
5
|
+
* All storage backends are now augmentations for consistency and extensibility.
|
|
6
|
+
*/
|
|
7
|
+
import { BaseAugmentation, BrainyAugmentation, AugmentationContext } from './brainyAugmentation.js';
|
|
8
|
+
import { StorageAdapter } from '../coreTypes.js';
|
|
9
|
+
/**
|
|
10
|
+
* Base class for all storage augmentations
|
|
11
|
+
* Provides the storage adapter to the brain during initialization
|
|
12
|
+
*/
|
|
13
|
+
export declare abstract class StorageAugmentation extends BaseAugmentation implements BrainyAugmentation {
|
|
14
|
+
readonly timing: "replace";
|
|
15
|
+
operations: ("storage")[];
|
|
16
|
+
readonly priority = 100;
|
|
17
|
+
protected storageAdapter: StorageAdapter | null;
|
|
18
|
+
constructor();
|
|
19
|
+
/**
|
|
20
|
+
* Provide the storage adapter before full initialization
|
|
21
|
+
* This is called during the storage resolution phase
|
|
22
|
+
*/
|
|
23
|
+
abstract provideStorage(): Promise<StorageAdapter>;
|
|
24
|
+
/**
|
|
25
|
+
* Initialize the augmentation with context
|
|
26
|
+
* Called after storage has been resolved
|
|
27
|
+
*/
|
|
28
|
+
initialize(context: AugmentationContext): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Execute storage operations
|
|
31
|
+
* For storage augmentations, this replaces the default storage
|
|
32
|
+
*/
|
|
33
|
+
execute<T = any>(operation: string, params: any, next: () => Promise<T>): Promise<T>;
|
|
34
|
+
/**
|
|
35
|
+
* Shutdown and cleanup
|
|
36
|
+
*/
|
|
37
|
+
shutdown(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Dynamic storage augmentation that wraps any storage adapter
|
|
41
|
+
* Used for backward compatibility and zero-config
|
|
42
|
+
*/
|
|
43
|
+
export declare class DynamicStorageAugmentation extends StorageAugmentation {
|
|
44
|
+
private adapter;
|
|
45
|
+
readonly name = "dynamic-storage";
|
|
46
|
+
constructor(adapter: StorageAdapter);
|
|
47
|
+
provideStorage(): Promise<StorageAdapter>;
|
|
48
|
+
protected onInitialize(): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create a storage augmentation from configuration
|
|
52
|
+
* Maintains backward compatibility with existing storage config
|
|
53
|
+
*/
|
|
54
|
+
export declare function createStorageAugmentationFromConfig(config: any): Promise<StorageAugmentation | null>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage Augmentation Base Classes
|
|
3
|
+
*
|
|
4
|
+
* Unifies storage adapters and augmentations into a single system.
|
|
5
|
+
* All storage backends are now augmentations for consistency and extensibility.
|
|
6
|
+
*/
|
|
7
|
+
import { BaseAugmentation } from './brainyAugmentation.js';
|
|
8
|
+
/**
|
|
9
|
+
* Base class for all storage augmentations
|
|
10
|
+
* Provides the storage adapter to the brain during initialization
|
|
11
|
+
*/
|
|
12
|
+
export class StorageAugmentation extends BaseAugmentation {
|
|
13
|
+
// Storage augmentations must provide their name via readonly property
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this.timing = 'replace';
|
|
17
|
+
this.operations = ['storage']; // Make mutable for TypeScript compatibility
|
|
18
|
+
this.priority = 100; // High priority for storage
|
|
19
|
+
this.storageAdapter = null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Initialize the augmentation with context
|
|
23
|
+
* Called after storage has been resolved
|
|
24
|
+
*/
|
|
25
|
+
async initialize(context) {
|
|
26
|
+
await super.initialize(context);
|
|
27
|
+
// Storage adapter should already be provided
|
|
28
|
+
if (!this.storageAdapter) {
|
|
29
|
+
this.storageAdapter = await this.provideStorage();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Execute storage operations
|
|
34
|
+
* For storage augmentations, this replaces the default storage
|
|
35
|
+
*/
|
|
36
|
+
async execute(operation, params, next) {
|
|
37
|
+
if (operation === 'storage') {
|
|
38
|
+
// Return our storage adapter
|
|
39
|
+
return this.storageAdapter;
|
|
40
|
+
}
|
|
41
|
+
// Pass through all other operations
|
|
42
|
+
return next();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Shutdown and cleanup
|
|
46
|
+
*/
|
|
47
|
+
async shutdown() {
|
|
48
|
+
// Cleanup storage adapter if needed
|
|
49
|
+
if (this.storageAdapter && typeof this.storageAdapter.close === 'function') {
|
|
50
|
+
await this.storageAdapter.close();
|
|
51
|
+
}
|
|
52
|
+
await super.shutdown();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Dynamic storage augmentation that wraps any storage adapter
|
|
57
|
+
* Used for backward compatibility and zero-config
|
|
58
|
+
*/
|
|
59
|
+
export class DynamicStorageAugmentation extends StorageAugmentation {
|
|
60
|
+
constructor(adapter) {
|
|
61
|
+
super();
|
|
62
|
+
this.adapter = adapter;
|
|
63
|
+
this.name = 'dynamic-storage';
|
|
64
|
+
this.storageAdapter = adapter;
|
|
65
|
+
}
|
|
66
|
+
async provideStorage() {
|
|
67
|
+
return this.adapter;
|
|
68
|
+
}
|
|
69
|
+
async onInitialize() {
|
|
70
|
+
// Adapter is already provided in constructor
|
|
71
|
+
await this.adapter.init();
|
|
72
|
+
this.log(`${this.name} initialized`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Create a storage augmentation from configuration
|
|
77
|
+
* Maintains backward compatibility with existing storage config
|
|
78
|
+
*/
|
|
79
|
+
export async function createStorageAugmentationFromConfig(config) {
|
|
80
|
+
// Import storage factory dynamically to avoid circular deps
|
|
81
|
+
const { createStorage } = await import('../storage/storageFactory.js');
|
|
82
|
+
try {
|
|
83
|
+
// Create storage adapter from config
|
|
84
|
+
const adapter = await createStorage(config);
|
|
85
|
+
// Wrap in augmentation
|
|
86
|
+
return new DynamicStorageAugmentation(adapter);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.warn('Failed to create storage augmentation from config:', error);
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=storageAugmentation.js.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage Augmentations - Concrete Implementations
|
|
3
|
+
*
|
|
4
|
+
* These augmentations provide different storage backends for Brainy.
|
|
5
|
+
* Each wraps an existing storage adapter for backward compatibility.
|
|
6
|
+
*/
|
|
7
|
+
import { StorageAugmentation } from './storageAugmentation.js';
|
|
8
|
+
import { StorageAdapter } from '../coreTypes.js';
|
|
9
|
+
/**
|
|
10
|
+
* Memory Storage Augmentation - Fast in-memory storage
|
|
11
|
+
*/
|
|
12
|
+
export declare class MemoryStorageAugmentation extends StorageAugmentation {
|
|
13
|
+
readonly name = "memory-storage";
|
|
14
|
+
constructor();
|
|
15
|
+
provideStorage(): Promise<StorageAdapter>;
|
|
16
|
+
protected onInitialize(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* FileSystem Storage Augmentation - Node.js persistent storage
|
|
20
|
+
*/
|
|
21
|
+
export declare class FileSystemStorageAugmentation extends StorageAugmentation {
|
|
22
|
+
readonly name = "filesystem-storage";
|
|
23
|
+
private rootDirectory;
|
|
24
|
+
constructor(rootDirectory?: string);
|
|
25
|
+
provideStorage(): Promise<StorageAdapter>;
|
|
26
|
+
protected onInitialize(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* OPFS Storage Augmentation - Browser persistent storage
|
|
30
|
+
*/
|
|
31
|
+
export declare class OPFSStorageAugmentation extends StorageAugmentation {
|
|
32
|
+
readonly name = "opfs-storage";
|
|
33
|
+
private requestPersistent;
|
|
34
|
+
constructor(requestPersistent?: boolean);
|
|
35
|
+
provideStorage(): Promise<StorageAdapter>;
|
|
36
|
+
protected onInitialize(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* S3 Storage Augmentation - Amazon S3 cloud storage
|
|
40
|
+
*/
|
|
41
|
+
export declare class S3StorageAugmentation extends StorageAugmentation {
|
|
42
|
+
readonly name = "s3-storage";
|
|
43
|
+
private config;
|
|
44
|
+
constructor(config: {
|
|
45
|
+
bucketName: string;
|
|
46
|
+
region?: string;
|
|
47
|
+
accessKeyId: string;
|
|
48
|
+
secretAccessKey: string;
|
|
49
|
+
sessionToken?: string;
|
|
50
|
+
cacheConfig?: any;
|
|
51
|
+
operationConfig?: any;
|
|
52
|
+
});
|
|
53
|
+
provideStorage(): Promise<StorageAdapter>;
|
|
54
|
+
protected onInitialize(): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* R2 Storage Augmentation - Cloudflare R2 storage
|
|
58
|
+
*/
|
|
59
|
+
export declare class R2StorageAugmentation extends StorageAugmentation {
|
|
60
|
+
readonly name = "r2-storage";
|
|
61
|
+
private config;
|
|
62
|
+
constructor(config: {
|
|
63
|
+
bucketName: string;
|
|
64
|
+
accountId: string;
|
|
65
|
+
accessKeyId: string;
|
|
66
|
+
secretAccessKey: string;
|
|
67
|
+
cacheConfig?: any;
|
|
68
|
+
});
|
|
69
|
+
provideStorage(): Promise<StorageAdapter>;
|
|
70
|
+
protected onInitialize(): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* GCS Storage Augmentation - Google Cloud Storage
|
|
74
|
+
*/
|
|
75
|
+
export declare class GCSStorageAugmentation extends StorageAugmentation {
|
|
76
|
+
readonly name = "gcs-storage";
|
|
77
|
+
private config;
|
|
78
|
+
constructor(config: {
|
|
79
|
+
bucketName: string;
|
|
80
|
+
region?: string;
|
|
81
|
+
accessKeyId: string;
|
|
82
|
+
secretAccessKey: string;
|
|
83
|
+
endpoint?: string;
|
|
84
|
+
cacheConfig?: any;
|
|
85
|
+
});
|
|
86
|
+
provideStorage(): Promise<StorageAdapter>;
|
|
87
|
+
protected onInitialize(): Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Auto-select the best storage augmentation for the environment
|
|
91
|
+
* Maintains zero-config philosophy
|
|
92
|
+
*/
|
|
93
|
+
export declare function createAutoStorageAugmentation(options?: {
|
|
94
|
+
rootDirectory?: string;
|
|
95
|
+
requestPersistentStorage?: boolean;
|
|
96
|
+
}): Promise<StorageAugmentation>;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage Augmentations - Concrete Implementations
|
|
3
|
+
*
|
|
4
|
+
* These augmentations provide different storage backends for Brainy.
|
|
5
|
+
* Each wraps an existing storage adapter for backward compatibility.
|
|
6
|
+
*/
|
|
7
|
+
import { StorageAugmentation } from './storageAugmentation.js';
|
|
8
|
+
import { MemoryStorage } from '../storage/adapters/memoryStorage.js';
|
|
9
|
+
import { OPFSStorage } from '../storage/adapters/opfsStorage.js';
|
|
10
|
+
import { S3CompatibleStorage, R2Storage } from '../storage/adapters/s3CompatibleStorage.js';
|
|
11
|
+
/**
|
|
12
|
+
* Memory Storage Augmentation - Fast in-memory storage
|
|
13
|
+
*/
|
|
14
|
+
export class MemoryStorageAugmentation extends StorageAugmentation {
|
|
15
|
+
constructor() {
|
|
16
|
+
super();
|
|
17
|
+
this.name = 'memory-storage';
|
|
18
|
+
}
|
|
19
|
+
async provideStorage() {
|
|
20
|
+
const storage = new MemoryStorage();
|
|
21
|
+
this.storageAdapter = storage;
|
|
22
|
+
return storage;
|
|
23
|
+
}
|
|
24
|
+
async onInitialize() {
|
|
25
|
+
await this.storageAdapter.init();
|
|
26
|
+
this.log('Memory storage initialized');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* FileSystem Storage Augmentation - Node.js persistent storage
|
|
31
|
+
*/
|
|
32
|
+
export class FileSystemStorageAugmentation extends StorageAugmentation {
|
|
33
|
+
constructor(rootDirectory = './brainy-data') {
|
|
34
|
+
super();
|
|
35
|
+
this.name = 'filesystem-storage';
|
|
36
|
+
this.rootDirectory = rootDirectory;
|
|
37
|
+
}
|
|
38
|
+
async provideStorage() {
|
|
39
|
+
try {
|
|
40
|
+
// Dynamically import for Node.js environments
|
|
41
|
+
const { FileSystemStorage } = await import('../storage/adapters/fileSystemStorage.js');
|
|
42
|
+
const storage = new FileSystemStorage(this.rootDirectory);
|
|
43
|
+
this.storageAdapter = storage;
|
|
44
|
+
return storage;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
this.log('FileSystemStorage not available, falling back to memory', 'warn');
|
|
48
|
+
// Fall back to memory storage
|
|
49
|
+
const storage = new MemoryStorage();
|
|
50
|
+
this.storageAdapter = storage;
|
|
51
|
+
return storage;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async onInitialize() {
|
|
55
|
+
await this.storageAdapter.init();
|
|
56
|
+
this.log(`FileSystem storage initialized at ${this.rootDirectory}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* OPFS Storage Augmentation - Browser persistent storage
|
|
61
|
+
*/
|
|
62
|
+
export class OPFSStorageAugmentation extends StorageAugmentation {
|
|
63
|
+
constructor(requestPersistent = false) {
|
|
64
|
+
super();
|
|
65
|
+
this.name = 'opfs-storage';
|
|
66
|
+
this.requestPersistent = requestPersistent;
|
|
67
|
+
}
|
|
68
|
+
async provideStorage() {
|
|
69
|
+
const storage = new OPFSStorage();
|
|
70
|
+
if (!storage.isOPFSAvailable()) {
|
|
71
|
+
this.log('OPFS not available, falling back to memory', 'warn');
|
|
72
|
+
const memStorage = new MemoryStorage();
|
|
73
|
+
this.storageAdapter = memStorage;
|
|
74
|
+
return memStorage;
|
|
75
|
+
}
|
|
76
|
+
this.storageAdapter = storage;
|
|
77
|
+
return storage;
|
|
78
|
+
}
|
|
79
|
+
async onInitialize() {
|
|
80
|
+
await this.storageAdapter.init();
|
|
81
|
+
if (this.requestPersistent && this.storageAdapter instanceof OPFSStorage) {
|
|
82
|
+
const granted = await this.storageAdapter.requestPersistentStorage();
|
|
83
|
+
this.log(`Persistent storage ${granted ? 'granted' : 'denied'}`);
|
|
84
|
+
}
|
|
85
|
+
this.log('OPFS storage initialized');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* S3 Storage Augmentation - Amazon S3 cloud storage
|
|
90
|
+
*/
|
|
91
|
+
export class S3StorageAugmentation extends StorageAugmentation {
|
|
92
|
+
constructor(config) {
|
|
93
|
+
super();
|
|
94
|
+
this.name = 's3-storage';
|
|
95
|
+
this.config = config;
|
|
96
|
+
}
|
|
97
|
+
async provideStorage() {
|
|
98
|
+
const storage = new S3CompatibleStorage({
|
|
99
|
+
...this.config,
|
|
100
|
+
serviceType: 's3'
|
|
101
|
+
});
|
|
102
|
+
this.storageAdapter = storage;
|
|
103
|
+
return storage;
|
|
104
|
+
}
|
|
105
|
+
async onInitialize() {
|
|
106
|
+
await this.storageAdapter.init();
|
|
107
|
+
this.log(`S3 storage initialized with bucket ${this.config.bucketName}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* R2 Storage Augmentation - Cloudflare R2 storage
|
|
112
|
+
*/
|
|
113
|
+
export class R2StorageAugmentation extends StorageAugmentation {
|
|
114
|
+
constructor(config) {
|
|
115
|
+
super();
|
|
116
|
+
this.name = 'r2-storage';
|
|
117
|
+
this.config = config;
|
|
118
|
+
}
|
|
119
|
+
async provideStorage() {
|
|
120
|
+
const storage = new R2Storage({
|
|
121
|
+
...this.config,
|
|
122
|
+
serviceType: 'r2'
|
|
123
|
+
});
|
|
124
|
+
this.storageAdapter = storage;
|
|
125
|
+
return storage;
|
|
126
|
+
}
|
|
127
|
+
async onInitialize() {
|
|
128
|
+
await this.storageAdapter.init();
|
|
129
|
+
this.log(`R2 storage initialized with bucket ${this.config.bucketName}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* GCS Storage Augmentation - Google Cloud Storage
|
|
134
|
+
*/
|
|
135
|
+
export class GCSStorageAugmentation extends StorageAugmentation {
|
|
136
|
+
constructor(config) {
|
|
137
|
+
super();
|
|
138
|
+
this.name = 'gcs-storage';
|
|
139
|
+
this.config = config;
|
|
140
|
+
}
|
|
141
|
+
async provideStorage() {
|
|
142
|
+
const storage = new S3CompatibleStorage({
|
|
143
|
+
...this.config,
|
|
144
|
+
endpoint: this.config.endpoint || 'https://storage.googleapis.com',
|
|
145
|
+
serviceType: 'gcs'
|
|
146
|
+
});
|
|
147
|
+
this.storageAdapter = storage;
|
|
148
|
+
return storage;
|
|
149
|
+
}
|
|
150
|
+
async onInitialize() {
|
|
151
|
+
await this.storageAdapter.init();
|
|
152
|
+
this.log(`GCS storage initialized with bucket ${this.config.bucketName}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Auto-select the best storage augmentation for the environment
|
|
157
|
+
* Maintains zero-config philosophy
|
|
158
|
+
*/
|
|
159
|
+
export async function createAutoStorageAugmentation(options = {}) {
|
|
160
|
+
// Detect environment
|
|
161
|
+
const isNodeEnv = globalThis.__ENV__?.isNode || (typeof process !== 'undefined' &&
|
|
162
|
+
process.versions != null &&
|
|
163
|
+
process.versions.node != null);
|
|
164
|
+
if (isNodeEnv) {
|
|
165
|
+
// Node.js environment - use FileSystem
|
|
166
|
+
return new FileSystemStorageAugmentation(options.rootDirectory || './brainy-data');
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
// Browser environment - try OPFS, fall back to memory
|
|
170
|
+
const opfsAug = new OPFSStorageAugmentation(options.requestPersistentStorage || false);
|
|
171
|
+
// Test if OPFS is available
|
|
172
|
+
const testStorage = new OPFSStorage();
|
|
173
|
+
if (testStorage.isOPFSAvailable()) {
|
|
174
|
+
return opfsAug;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
// Fall back to memory
|
|
178
|
+
return new MemoryStorageAugmentation();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=storageAugmentations.js.map
|
|
@@ -0,0 +1,156 @@
|
|
|
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 { AugmentationResponse } from '../types/augmentations.js';
|
|
20
|
+
import { BaseAugmentation } from './brainyAugmentation.js';
|
|
21
|
+
import { NeuralImportAugmentation } from './neuralImport.js';
|
|
22
|
+
/**
|
|
23
|
+
* Base class for all synapse augmentations
|
|
24
|
+
* Provides common functionality for external data synchronization
|
|
25
|
+
*/
|
|
26
|
+
export declare abstract class SynapseAugmentation extends BaseAugmentation {
|
|
27
|
+
readonly timing: "after";
|
|
28
|
+
readonly operations: ("all")[];
|
|
29
|
+
readonly priority = 10;
|
|
30
|
+
abstract readonly synapseId: string;
|
|
31
|
+
abstract readonly supportedTypes: string[];
|
|
32
|
+
protected syncInProgress: boolean;
|
|
33
|
+
protected lastSyncId?: string;
|
|
34
|
+
protected syncStats: {
|
|
35
|
+
totalSyncs: number;
|
|
36
|
+
totalItems: number;
|
|
37
|
+
lastSync: string | undefined;
|
|
38
|
+
};
|
|
39
|
+
protected neuralImport?: NeuralImportAugmentation;
|
|
40
|
+
protected useNeuralImport: boolean;
|
|
41
|
+
protected onInit(): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Synapse-specific initialization
|
|
44
|
+
* Override this in implementations
|
|
45
|
+
*/
|
|
46
|
+
protected abstract onInitialize(): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* BrainyAugmentation execute method
|
|
49
|
+
* Intercepts operations to sync external data when relevant
|
|
50
|
+
*/
|
|
51
|
+
execute<T = any>(operation: string, params: any, next: () => Promise<T>): Promise<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Determine if sync should be triggered after an operation
|
|
54
|
+
*/
|
|
55
|
+
protected shouldSync(operation: string, params: any): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Background sync process
|
|
58
|
+
*/
|
|
59
|
+
protected backgroundSync(): Promise<void>;
|
|
60
|
+
protected onShutdown(): Promise<void>;
|
|
61
|
+
protected onSynapseShutdown(): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* ISynapseAugmentation methods
|
|
64
|
+
*/
|
|
65
|
+
abstract testConnection(): Promise<AugmentationResponse<boolean>>;
|
|
66
|
+
abstract startSync(options?: Record<string, unknown>): Promise<AugmentationResponse<{
|
|
67
|
+
synced: number;
|
|
68
|
+
failed: number;
|
|
69
|
+
skipped: number;
|
|
70
|
+
duration: number;
|
|
71
|
+
errors?: Array<{
|
|
72
|
+
item: string;
|
|
73
|
+
error: string;
|
|
74
|
+
}>;
|
|
75
|
+
}>>;
|
|
76
|
+
stopSync(): Promise<void>;
|
|
77
|
+
abstract incrementalSync(lastSyncId?: string): Promise<AugmentationResponse<{
|
|
78
|
+
synced: number;
|
|
79
|
+
failed: number;
|
|
80
|
+
skipped: number;
|
|
81
|
+
duration: number;
|
|
82
|
+
hasMore: boolean;
|
|
83
|
+
nextSyncId?: string;
|
|
84
|
+
}>>;
|
|
85
|
+
abstract previewSync(limit?: number): Promise<AugmentationResponse<{
|
|
86
|
+
items: Array<{
|
|
87
|
+
type: string;
|
|
88
|
+
title: string;
|
|
89
|
+
preview: string;
|
|
90
|
+
}>;
|
|
91
|
+
totalCount: number;
|
|
92
|
+
estimatedDuration: number;
|
|
93
|
+
}>>;
|
|
94
|
+
getSynapseStatus(): Promise<AugmentationResponse<{
|
|
95
|
+
status: 'connected' | 'disconnected' | 'syncing' | 'error';
|
|
96
|
+
lastSync?: string;
|
|
97
|
+
nextSync?: string;
|
|
98
|
+
totalSyncs: number;
|
|
99
|
+
totalItems: number;
|
|
100
|
+
}>>;
|
|
101
|
+
/**
|
|
102
|
+
* Helper method to store synced data in Brainy
|
|
103
|
+
* Optionally uses Neural Import for intelligent processing
|
|
104
|
+
*/
|
|
105
|
+
protected storeInBrainy(content: string | Record<string, any>, metadata: Record<string, any>, options?: {
|
|
106
|
+
useNeuralImport?: boolean;
|
|
107
|
+
dataType?: string;
|
|
108
|
+
rawData?: Buffer | string;
|
|
109
|
+
}): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Helper method to query existing synced data
|
|
112
|
+
*/
|
|
113
|
+
protected queryBrainyData(filter: {
|
|
114
|
+
connector?: string;
|
|
115
|
+
[key: string]: any;
|
|
116
|
+
}): Promise<any[]>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Example implementation for reference
|
|
120
|
+
* Real synapses would be in Brain Cloud registry
|
|
121
|
+
*/
|
|
122
|
+
export declare class ExampleFileSystemSynapse extends SynapseAugmentation {
|
|
123
|
+
readonly name = "example-filesystem-synapse";
|
|
124
|
+
readonly description = "Example synapse for local file system with Neural Import intelligence";
|
|
125
|
+
readonly synapseId = "filesystem";
|
|
126
|
+
readonly supportedTypes: string[];
|
|
127
|
+
protected onInitialize(): Promise<void>;
|
|
128
|
+
testConnection(): Promise<AugmentationResponse<boolean>>;
|
|
129
|
+
startSync(options?: Record<string, unknown>): Promise<AugmentationResponse<{
|
|
130
|
+
synced: number;
|
|
131
|
+
failed: number;
|
|
132
|
+
skipped: number;
|
|
133
|
+
duration: number;
|
|
134
|
+
errors?: Array<{
|
|
135
|
+
item: string;
|
|
136
|
+
error: string;
|
|
137
|
+
}>;
|
|
138
|
+
}>>;
|
|
139
|
+
incrementalSync(lastSyncId?: string): Promise<AugmentationResponse<{
|
|
140
|
+
synced: number;
|
|
141
|
+
failed: number;
|
|
142
|
+
skipped: number;
|
|
143
|
+
duration: number;
|
|
144
|
+
hasMore: boolean;
|
|
145
|
+
nextSyncId?: string;
|
|
146
|
+
}>>;
|
|
147
|
+
previewSync(limit?: number): Promise<AugmentationResponse<{
|
|
148
|
+
items: Array<{
|
|
149
|
+
type: string;
|
|
150
|
+
title: string;
|
|
151
|
+
preview: string;
|
|
152
|
+
}>;
|
|
153
|
+
totalCount: number;
|
|
154
|
+
estimatedDuration: number;
|
|
155
|
+
}>>;
|
|
156
|
+
}
|