@soulcraft/brainy 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.demo.md +59 -0
  3. package/README.md +1257 -0
  4. package/brainy.png +0 -0
  5. package/cli-wrapper.js +56 -0
  6. package/dist/augmentationFactory.d.ts +87 -0
  7. package/dist/augmentationPipeline.d.ts +205 -0
  8. package/dist/augmentationRegistry.d.ts +48 -0
  9. package/dist/augmentationRegistryLoader.d.ts +147 -0
  10. package/dist/augmentations/conduitAugmentations.d.ts +173 -0
  11. package/dist/augmentations/memoryAugmentations.d.ts +71 -0
  12. package/dist/augmentations/serverSearchAugmentations.d.ts +168 -0
  13. package/dist/brainy.js +116929 -0
  14. package/dist/brainy.min.js +16107 -0
  15. package/dist/brainyData.d.ts +507 -0
  16. package/dist/cli.d.ts +7 -0
  17. package/dist/coreTypes.d.ts +131 -0
  18. package/dist/examples/basicUsage.d.ts +5 -0
  19. package/dist/hnsw/hnswIndex.d.ts +96 -0
  20. package/dist/hnsw/hnswIndexOptimized.d.ts +167 -0
  21. package/dist/index.d.ts +49 -0
  22. package/dist/mcp/brainyMCPAdapter.d.ts +69 -0
  23. package/dist/mcp/brainyMCPService.d.ts +99 -0
  24. package/dist/mcp/index.d.ts +14 -0
  25. package/dist/mcp/mcpAugmentationToolset.d.ts +68 -0
  26. package/dist/pipeline.d.ts +281 -0
  27. package/dist/sequentialPipeline.d.ts +114 -0
  28. package/dist/storage/fileSystemStorage.d.ts +123 -0
  29. package/dist/storage/opfsStorage.d.ts +244 -0
  30. package/dist/storage/s3CompatibleStorage.d.ts +158 -0
  31. package/dist/types/augmentations.d.ts +324 -0
  32. package/dist/types/augmentations.d.ts.map +1 -0
  33. package/dist/types/brainyDataInterface.d.ts +51 -0
  34. package/dist/types/brainyDataInterface.d.ts.map +1 -0
  35. package/dist/types/fileSystemTypes.d.ts +6 -0
  36. package/dist/types/fileSystemTypes.d.ts.map +1 -0
  37. package/dist/types/graphTypes.d.ts +134 -0
  38. package/dist/types/graphTypes.d.ts.map +1 -0
  39. package/dist/types/mcpTypes.d.ts +140 -0
  40. package/dist/types/mcpTypes.d.ts.map +1 -0
  41. package/dist/types/pipelineTypes.d.ts +27 -0
  42. package/dist/types/pipelineTypes.d.ts.map +1 -0
  43. package/dist/types/tensorflowTypes.d.ts +7 -0
  44. package/dist/types/tensorflowTypes.d.ts.map +1 -0
  45. package/dist/unified.d.ts +12 -0
  46. package/dist/unified.js +117122 -0
  47. package/dist/unified.min.js +16107 -0
  48. package/dist/utils/distance.d.ts +32 -0
  49. package/dist/utils/embedding.d.ts +55 -0
  50. package/dist/utils/environment.d.ts +28 -0
  51. package/dist/utils/index.d.ts +3 -0
  52. package/dist/utils/version.d.ts +6 -0
  53. package/dist/utils/workerUtils.d.ts +28 -0
  54. package/package.json +156 -0
@@ -0,0 +1,244 @@
1
+ /**
2
+ * OPFS (Origin Private File System) Storage Adapter
3
+ * Provides persistent storage for the vector database using the Origin Private File System API
4
+ */
5
+ import { GraphVerb, HNSWNoun, StorageAdapter } from '../coreTypes.js';
6
+ import '../types/fileSystemTypes.js';
7
+ declare global {
8
+ interface FileSystemDirectoryHandle {
9
+ entries(): AsyncIterableIterator<[string, FileSystemHandle]>;
10
+ }
11
+ }
12
+ type HNSWNode = HNSWNoun;
13
+ type Edge = GraphVerb;
14
+ export declare class OPFSStorage implements StorageAdapter {
15
+ private rootDir;
16
+ private nounsDir;
17
+ private verbsDir;
18
+ private metadataDir;
19
+ private personDir;
20
+ private placeDir;
21
+ private thingDir;
22
+ private eventDir;
23
+ private conceptDir;
24
+ private contentDir;
25
+ private defaultDir;
26
+ private isInitialized;
27
+ private isAvailable;
28
+ private isPersistentRequested;
29
+ private isPersistentGranted;
30
+ constructor();
31
+ /**
32
+ * Initialize the storage adapter
33
+ */
34
+ init(): Promise<void>;
35
+ /**
36
+ * Check if OPFS is available in the current environment
37
+ */
38
+ isOPFSAvailable(): boolean;
39
+ /**
40
+ * Request persistent storage permission from the user
41
+ * @returns Promise that resolves to true if permission was granted, false otherwise
42
+ */
43
+ requestPersistentStorage(): Promise<boolean>;
44
+ /**
45
+ * Check if persistent storage is granted
46
+ * @returns Promise that resolves to true if persistent storage is granted, false otherwise
47
+ */
48
+ isPersistent(): Promise<boolean>;
49
+ /**
50
+ * Save a noun to storage
51
+ */
52
+ saveNoun(noun: HNSWNoun): Promise<void>;
53
+ /**
54
+ * Get a noun from storage
55
+ */
56
+ getNoun(id: string): Promise<HNSWNoun | null>;
57
+ /**
58
+ * Get nouns by noun type
59
+ * @param nounType The noun type to filter by
60
+ * @returns Promise that resolves to an array of nouns of the specified noun type
61
+ */
62
+ getNounsByNounType(nounType: string): Promise<HNSWNoun[]>;
63
+ /**
64
+ * Get all nouns from storage
65
+ */
66
+ getAllNouns(): Promise<HNSWNoun[]>;
67
+ /**
68
+ * Delete a noun from storage
69
+ */
70
+ deleteNoun(id: string): Promise<void>;
71
+ /**
72
+ * Save a verb to storage
73
+ */
74
+ saveVerb(verb: GraphVerb): Promise<void>;
75
+ /**
76
+ * Get a verb from storage
77
+ */
78
+ getVerb(id: string): Promise<GraphVerb | null>;
79
+ /**
80
+ * Get all edges from storage
81
+ */
82
+ getAllEdges(): Promise<Edge[]>;
83
+ /**
84
+ * Get all verbs from storage (alias for getAllEdges)
85
+ */
86
+ getAllVerbs(): Promise<GraphVerb[]>;
87
+ /**
88
+ * Delete an edge from storage
89
+ */
90
+ deleteEdge(id: string): Promise<void>;
91
+ /**
92
+ * Delete a verb from storage (alias for deleteEdge)
93
+ */
94
+ deleteVerb(id: string): Promise<void>;
95
+ /**
96
+ * Get edges by source node ID
97
+ */
98
+ getEdgesBySource(sourceId: string): Promise<Edge[]>;
99
+ /**
100
+ * Get verbs by source node ID (alias for getEdgesBySource)
101
+ */
102
+ getVerbsBySource(sourceId: string): Promise<GraphVerb[]>;
103
+ /**
104
+ * Get edges by target node ID
105
+ */
106
+ getEdgesByTarget(targetId: string): Promise<Edge[]>;
107
+ /**
108
+ * Get verbs by target node ID (alias for getEdgesByTarget)
109
+ */
110
+ getVerbsByTarget(targetId: string): Promise<GraphVerb[]>;
111
+ /**
112
+ * Get edges by type
113
+ */
114
+ getEdgesByType(type: string): Promise<Edge[]>;
115
+ /**
116
+ * Get verbs by type (alias for getEdgesByType)
117
+ */
118
+ getVerbsByType(type: string): Promise<GraphVerb[]>;
119
+ /**
120
+ * Save metadata for a node
121
+ */
122
+ saveMetadata(id: string, metadata: any): Promise<void>;
123
+ /**
124
+ * Get metadata for a node
125
+ */
126
+ getMetadata(id: string): Promise<any | null>;
127
+ /**
128
+ * Clear all data from storage
129
+ */
130
+ clear(): Promise<void>;
131
+ /**
132
+ * Ensure the storage adapter is initialized
133
+ */
134
+ private ensureInitialized;
135
+ /**
136
+ * Convert a Map to a plain object for serialization
137
+ */
138
+ private mapToObject;
139
+ /**
140
+ * Get the appropriate directory for a node based on its metadata
141
+ */
142
+ private getNodeDirectory;
143
+ /**
144
+ * Get information about storage usage and capacity
145
+ */
146
+ getStorageStatus(): Promise<{
147
+ type: string;
148
+ used: number;
149
+ quota: number | null;
150
+ details?: Record<string, any>;
151
+ }>;
152
+ }
153
+ /**
154
+ * In-memory storage adapter for environments where OPFS is not available
155
+ */
156
+ export declare class MemoryStorage implements StorageAdapter {
157
+ private nouns;
158
+ private verbs;
159
+ private metadata;
160
+ constructor();
161
+ saveNoun(noun: HNSWNoun): Promise<void>;
162
+ getNoun(id: string): Promise<HNSWNoun | null>;
163
+ getAllNouns(): Promise<HNSWNoun[]>;
164
+ getNounsByNounType(nounType: string): Promise<HNSWNoun[]>;
165
+ deleteNoun(id: string): Promise<void>;
166
+ saveVerb(verb: GraphVerb): Promise<void>;
167
+ getVerb(id: string): Promise<GraphVerb | null>;
168
+ getAllVerbs(): Promise<GraphVerb[]>;
169
+ getVerbsBySource(sourceId: string): Promise<GraphVerb[]>;
170
+ getVerbsByTarget(targetId: string): Promise<GraphVerb[]>;
171
+ getVerbsByType(type: string): Promise<GraphVerb[]>;
172
+ deleteVerb(id: string): Promise<void>;
173
+ init(): Promise<void>;
174
+ /**
175
+ * Get the appropriate node type for a node based on its metadata
176
+ */
177
+ private getNodeType;
178
+ saveNode(node: HNSWNode): Promise<void>;
179
+ getNode(id: string): Promise<HNSWNode | null>;
180
+ /**
181
+ * Get nodes by noun type
182
+ * @param nounType The noun type to filter by
183
+ * @returns Promise that resolves to an array of nodes of the specified noun type
184
+ */
185
+ getNodesByNounType(nounType: string): Promise<HNSWNode[]>;
186
+ getAllNodes(): Promise<HNSWNode[]>;
187
+ deleteNode(id: string): Promise<void>;
188
+ saveMetadata(id: string, metadata: any): Promise<void>;
189
+ getMetadata(id: string): Promise<any | null>;
190
+ saveEdge(edge: Edge): Promise<void>;
191
+ getEdge(id: string): Promise<Edge | null>;
192
+ getAllEdges(): Promise<Edge[]>;
193
+ getEdgesBySource(sourceId: string): Promise<Edge[]>;
194
+ getEdgesByTarget(targetId: string): Promise<Edge[]>;
195
+ getEdgesByType(type: string): Promise<Edge[]>;
196
+ deleteEdge(id: string): Promise<void>;
197
+ clear(): Promise<void>;
198
+ /**
199
+ * Get information about storage usage and capacity
200
+ */
201
+ getStorageStatus(): Promise<{
202
+ type: string;
203
+ used: number;
204
+ quota: number | null;
205
+ details?: Record<string, any>;
206
+ }>;
207
+ }
208
+ /**
209
+ * Factory function to create the appropriate storage adapter based on the environment
210
+ * @param options Configuration options for storage
211
+ * @returns Promise that resolves to a StorageAdapter instance
212
+ */
213
+ export declare function createStorage(options?: {
214
+ requestPersistentStorage?: boolean;
215
+ r2Storage?: {
216
+ bucketName?: string;
217
+ accountId?: string;
218
+ accessKeyId?: string;
219
+ secretAccessKey?: string;
220
+ };
221
+ s3Storage?: {
222
+ bucketName?: string;
223
+ accessKeyId?: string;
224
+ secretAccessKey?: string;
225
+ region?: string;
226
+ };
227
+ gcsStorage?: {
228
+ bucketName?: string;
229
+ accessKeyId?: string;
230
+ secretAccessKey?: string;
231
+ endpoint?: string;
232
+ };
233
+ customS3Storage?: {
234
+ bucketName?: string;
235
+ accessKeyId?: string;
236
+ secretAccessKey?: string;
237
+ endpoint?: string;
238
+ region?: string;
239
+ };
240
+ forceFileSystemStorage?: boolean;
241
+ forceMemoryStorage?: boolean;
242
+ }): Promise<StorageAdapter>;
243
+ export {};
244
+ //# sourceMappingURL=opfsStorage.d.ts.map
@@ -0,0 +1,158 @@
1
+ import { GraphVerb, HNSWNoun, StorageAdapter } from '../coreTypes.js';
2
+ type HNSWNode = HNSWNoun;
3
+ type Edge = GraphVerb;
4
+ export { S3CompatibleStorage as R2Storage };
5
+ /**
6
+ * S3-compatible storage adapter for server environments
7
+ * Uses the AWS S3 client to interact with S3-compatible storage services
8
+ * including Amazon S3, Cloudflare R2, and Google Cloud Storage
9
+ *
10
+ * To use this adapter with Cloudflare R2, you need to provide:
11
+ * - bucketName: Your bucket name
12
+ * - accountId: Your Cloudflare account ID
13
+ * - accessKeyId: R2 access key ID
14
+ * - secretAccessKey: R2 secret access key
15
+ * - serviceType: 'r2'
16
+ *
17
+ * To use this adapter with Amazon S3, you need to provide:
18
+ * - bucketName: Your S3 bucket name
19
+ * - accessKeyId: AWS access key ID
20
+ * - secretAccessKey: AWS secret access key
21
+ * - region: AWS region (e.g., 'us-east-1')
22
+ * - serviceType: 's3'
23
+ *
24
+ * To use this adapter with Google Cloud Storage, you need to provide:
25
+ * - bucketName: Your GCS bucket name
26
+ * - accessKeyId: HMAC access key
27
+ * - secretAccessKey: HMAC secret
28
+ * - endpoint: GCS endpoint (e.g., 'https://storage.googleapis.com')
29
+ * - serviceType: 'gcs'
30
+ *
31
+ * For other S3-compatible services, provide:
32
+ * - bucketName: Your bucket name
33
+ * - accessKeyId: Access key ID
34
+ * - secretAccessKey: Secret access key
35
+ * - endpoint: Service endpoint URL
36
+ * - region: Region (if required)
37
+ * - serviceType: 'custom'
38
+ */
39
+ export declare class S3CompatibleStorage implements StorageAdapter {
40
+ private bucketName;
41
+ private accessKeyId;
42
+ private secretAccessKey;
43
+ private endpoint?;
44
+ private region?;
45
+ private accountId?;
46
+ private serviceType;
47
+ private s3Client;
48
+ private isInitialized;
49
+ saveNoun(noun: HNSWNoun): Promise<void>;
50
+ getNoun(id: string): Promise<HNSWNoun | null>;
51
+ getAllNouns(): Promise<HNSWNoun[]>;
52
+ getNounsByNounType(nounType: string): Promise<HNSWNoun[]>;
53
+ deleteNoun(id: string): Promise<void>;
54
+ saveVerb(verb: GraphVerb): Promise<void>;
55
+ getVerb(id: string): Promise<GraphVerb | null>;
56
+ getAllVerbs(): Promise<GraphVerb[]>;
57
+ getVerbsBySource(sourceId: string): Promise<GraphVerb[]>;
58
+ getVerbsByTarget(targetId: string): Promise<GraphVerb[]>;
59
+ getVerbsByType(type: string): Promise<GraphVerb[]>;
60
+ deleteVerb(id: string): Promise<void>;
61
+ constructor(options: {
62
+ bucketName: string;
63
+ accessKeyId: string;
64
+ secretAccessKey: string;
65
+ serviceType: 'r2' | 's3' | 'gcs' | 'custom';
66
+ accountId?: string;
67
+ region?: string;
68
+ endpoint?: string;
69
+ });
70
+ /**
71
+ * Initialize the storage adapter
72
+ */
73
+ init(): Promise<void>;
74
+ /**
75
+ * Save a node to storage
76
+ */
77
+ saveNode(node: HNSWNode): Promise<void>;
78
+ /**
79
+ * Get a node from storage
80
+ */
81
+ getNode(id: string): Promise<HNSWNode | null>;
82
+ /**
83
+ * Get nodes by noun type
84
+ * @param nounType The noun type to filter by
85
+ * @returns Promise that resolves to an array of nodes of the specified noun type
86
+ */
87
+ getNodesByNounType(nounType: string): Promise<HNSWNode[]>;
88
+ /**
89
+ * Get all nodes from storage
90
+ */
91
+ getAllNodes(): Promise<HNSWNode[]>;
92
+ /**
93
+ * Delete a node from storage
94
+ */
95
+ deleteNode(id: string): Promise<void>;
96
+ /**
97
+ * Save an edge to storage
98
+ */
99
+ saveEdge(edge: Edge): Promise<void>;
100
+ /**
101
+ * Get an edge from storage
102
+ */
103
+ getEdge(id: string): Promise<Edge | null>;
104
+ /**
105
+ * Get all edges from storage
106
+ */
107
+ getAllEdges(): Promise<Edge[]>;
108
+ /**
109
+ * Get edges by source node ID
110
+ */
111
+ getEdgesBySource(sourceId: string): Promise<Edge[]>;
112
+ /**
113
+ * Get edges by target node ID
114
+ */
115
+ getEdgesByTarget(targetId: string): Promise<Edge[]>;
116
+ /**
117
+ * Get edges by type
118
+ */
119
+ getEdgesByType(type: string): Promise<Edge[]>;
120
+ /**
121
+ * Delete an edge from storage
122
+ */
123
+ deleteEdge(id: string): Promise<void>;
124
+ /**
125
+ * Save metadata to storage
126
+ */
127
+ saveMetadata(id: string, metadata: any): Promise<void>;
128
+ /**
129
+ * Get metadata from storage
130
+ */
131
+ getMetadata(id: string): Promise<any | null>;
132
+ /**
133
+ * Clear all data from storage
134
+ */
135
+ clear(): Promise<void>;
136
+ /**
137
+ * Get information about storage usage and capacity
138
+ */
139
+ getStorageStatus(): Promise<{
140
+ type: string;
141
+ used: number;
142
+ quota: number | null;
143
+ details?: Record<string, any>;
144
+ }>;
145
+ /**
146
+ * Ensure the storage adapter is initialized
147
+ */
148
+ private ensureInitialized;
149
+ /**
150
+ * Get the appropriate prefix for a node based on its metadata
151
+ */
152
+ private getNodePrefix;
153
+ /**
154
+ * Convert a Map to a plain object for serialization
155
+ */
156
+ private mapToObject;
157
+ }
158
+ //# sourceMappingURL=s3CompatibleStorage.d.ts.map