@soulcraft/brainy 0.40.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +605 -194
- package/dist/augmentations/conduitAugmentations.js +1158 -0
- package/dist/augmentations/conduitAugmentations.js.map +1 -0
- package/dist/augmentations/memoryAugmentations.d.ts +2 -0
- package/dist/augmentations/memoryAugmentations.d.ts.map +1 -1
- package/dist/augmentations/memoryAugmentations.js +270 -0
- package/dist/augmentations/memoryAugmentations.js.map +1 -0
- package/dist/augmentations/serverSearchAugmentations.js +531 -0
- package/dist/augmentations/serverSearchAugmentations.js.map +1 -0
- package/dist/browserFramework.d.ts +15 -0
- package/dist/demo.d.ts +106 -0
- package/dist/examples/basicUsage.js +118 -0
- package/dist/examples/basicUsage.js.map +1 -0
- package/dist/hnsw/distributedSearch.js +452 -0
- package/dist/hnsw/distributedSearch.js.map +1 -0
- package/dist/hnsw/hnswIndex.js +602 -0
- package/dist/hnsw/hnswIndex.js.map +1 -0
- package/dist/hnsw/hnswIndexOptimized.js +471 -0
- package/dist/hnsw/hnswIndexOptimized.js.map +1 -0
- package/dist/hnsw/optimizedHNSWIndex.js +313 -0
- package/dist/hnsw/optimizedHNSWIndex.js.map +1 -0
- package/dist/hnsw/partitionedHNSWIndex.js +304 -0
- package/dist/hnsw/partitionedHNSWIndex.js.map +1 -0
- package/dist/hnsw/scaledHNSWSystem.js +559 -0
- package/dist/hnsw/scaledHNSWSystem.js.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +81 -0
- package/dist/mcp/brainyMCPAdapter.js +142 -0
- package/dist/mcp/brainyMCPAdapter.js.map +1 -0
- package/dist/mcp/brainyMCPService.js +248 -0
- package/dist/mcp/brainyMCPService.js.map +1 -0
- package/dist/mcp/index.js +17 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/mcpAugmentationToolset.js +180 -0
- package/dist/mcp/mcpAugmentationToolset.js.map +1 -0
- package/dist/storage/adapters/baseStorageAdapter.js +349 -0
- package/dist/storage/adapters/baseStorageAdapter.js.map +1 -0
- package/dist/storage/adapters/batchS3Operations.js +287 -0
- package/dist/storage/adapters/batchS3Operations.js.map +1 -0
- package/dist/storage/adapters/fileSystemStorage.js +846 -0
- package/dist/storage/adapters/fileSystemStorage.js.map +1 -0
- package/dist/storage/adapters/memoryStorage.js +532 -0
- package/dist/storage/adapters/memoryStorage.js.map +1 -0
- package/dist/storage/adapters/opfsStorage.d.ts.map +1 -1
- package/dist/storage/adapters/opfsStorage.js +1118 -0
- package/dist/storage/adapters/opfsStorage.js.map +1 -0
- package/dist/storage/adapters/optimizedS3Search.d.ts +79 -0
- package/dist/storage/adapters/optimizedS3Search.d.ts.map +1 -0
- package/dist/storage/adapters/optimizedS3Search.js +248 -0
- package/dist/storage/adapters/optimizedS3Search.js.map +1 -0
- package/dist/storage/adapters/s3CompatibleStorage.d.ts +21 -0
- package/dist/storage/adapters/s3CompatibleStorage.d.ts.map +1 -1
- package/dist/storage/adapters/s3CompatibleStorage.js +2026 -0
- package/dist/storage/adapters/s3CompatibleStorage.js.map +1 -0
- package/dist/storage/baseStorage.d.ts +1 -0
- package/dist/storage/baseStorage.d.ts.map +1 -1
- package/dist/storage/baseStorage.js +603 -0
- package/dist/storage/baseStorage.js.map +1 -0
- package/dist/storage/cacheManager.js +1306 -0
- package/dist/storage/cacheManager.js.map +1 -0
- package/dist/storage/enhancedCacheManager.js +520 -0
- package/dist/storage/enhancedCacheManager.js.map +1 -0
- package/dist/storage/readOnlyOptimizations.js +425 -0
- package/dist/storage/readOnlyOptimizations.js.map +1 -0
- package/dist/storage/storageFactory.d.ts +0 -1
- package/dist/storage/storageFactory.d.ts.map +1 -1
- package/dist/storage/storageFactory.js +227 -0
- package/dist/storage/storageFactory.js.map +1 -0
- package/dist/types/augmentations.js +16 -0
- package/dist/types/augmentations.js.map +1 -0
- package/dist/types/brainyDataInterface.js +8 -0
- package/dist/types/brainyDataInterface.js.map +1 -0
- package/dist/types/distributedTypes.js +6 -0
- package/dist/types/distributedTypes.js.map +1 -0
- package/dist/types/fileSystemTypes.js +8 -0
- package/dist/types/fileSystemTypes.js.map +1 -0
- package/dist/types/graphTypes.js +247 -0
- package/dist/types/graphTypes.js.map +1 -0
- package/dist/types/mcpTypes.js +22 -0
- package/dist/types/mcpTypes.js.map +1 -0
- package/dist/types/paginationTypes.js +5 -0
- package/dist/types/paginationTypes.js.map +1 -0
- package/dist/types/pipelineTypes.js +7 -0
- package/dist/types/pipelineTypes.js.map +1 -0
- package/dist/types/tensorflowTypes.js +6 -0
- package/dist/types/tensorflowTypes.js.map +1 -0
- package/dist/unified.js +52 -128048
- package/dist/utils/autoConfiguration.js +341 -0
- package/dist/utils/autoConfiguration.js.map +1 -0
- package/dist/utils/cacheAutoConfig.js +261 -0
- package/dist/utils/cacheAutoConfig.js.map +1 -0
- package/dist/utils/crypto.js +45 -0
- package/dist/utils/crypto.js.map +1 -0
- package/dist/utils/distance.js +239 -0
- package/dist/utils/distance.js.map +1 -0
- package/dist/utils/embedding.d.ts.map +1 -1
- package/dist/utils/embedding.js +702 -0
- package/dist/utils/embedding.js.map +1 -0
- package/dist/utils/environment.js +75 -0
- package/dist/utils/environment.js.map +1 -0
- package/dist/utils/fieldNameTracking.js +90 -0
- package/dist/utils/fieldNameTracking.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/jsonProcessing.js +179 -0
- package/dist/utils/jsonProcessing.js.map +1 -0
- package/dist/utils/logger.d.ts +45 -92
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +129 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/operationUtils.js +126 -0
- package/dist/utils/operationUtils.js.map +1 -0
- package/dist/utils/robustModelLoader.d.ts +14 -0
- package/dist/utils/robustModelLoader.d.ts.map +1 -1
- package/dist/utils/robustModelLoader.js +537 -0
- package/dist/utils/robustModelLoader.js.map +1 -0
- package/dist/utils/searchCache.js +248 -0
- package/dist/utils/searchCache.js.map +1 -0
- package/dist/utils/statistics.js +25 -0
- package/dist/utils/statistics.js.map +1 -0
- package/dist/utils/statisticsCollector.js +224 -0
- package/dist/utils/statisticsCollector.js.map +1 -0
- package/dist/utils/textEncoding.js +309 -0
- package/dist/utils/textEncoding.js.map +1 -0
- package/dist/utils/typeUtils.js +40 -0
- package/dist/utils/typeUtils.js.map +1 -0
- package/dist/utils/version.d.ts +15 -3
- package/dist/utils/version.d.ts.map +1 -1
- package/dist/utils/version.js +24 -0
- package/dist/utils/version.js.map +1 -0
- package/dist/utils/workerUtils.js +458 -0
- package/dist/utils/workerUtils.js.map +1 -0
- package/package.json +23 -15
- package/dist/brainy.js +0 -90220
- package/dist/brainy.min.js +0 -12511
- package/dist/patched-platform-node.d.ts +0 -17
- package/dist/statistics/statisticsManager.d.ts +0 -121
- package/dist/storage/fileSystemStorage.d.ts +0 -73
- package/dist/storage/fileSystemStorage.d.ts.map +0 -1
- package/dist/storage/opfsStorage.d.ts +0 -236
- package/dist/storage/opfsStorage.d.ts.map +0 -1
- package/dist/storage/s3CompatibleStorage.d.ts +0 -157
- package/dist/storage/s3CompatibleStorage.d.ts.map +0 -1
- package/dist/testing/prettyReporter.d.ts +0 -23
- package/dist/testing/prettySummaryReporter.d.ts +0 -22
- package/dist/unified.min.js +0 -16153
- package/dist/utils/environmentDetection.d.ts +0 -47
- package/dist/utils/environmentDetection.d.ts.map +0 -1
- package/dist/utils/tensorflowUtils.d.ts +0 -17
- package/dist/utils/tensorflowUtils.d.ts.map +0 -1
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server Search Augmentations
|
|
3
|
+
*
|
|
4
|
+
* This file implements conduit and activation augmentations for browser-server search functionality.
|
|
5
|
+
* It allows Brainy to search a server-hosted instance and store results locally.
|
|
6
|
+
*/
|
|
7
|
+
import { AugmentationType } from '../types/augmentations.js';
|
|
8
|
+
import { WebSocketConduitAugmentation } from './conduitAugmentations.js';
|
|
9
|
+
/**
|
|
10
|
+
* ServerSearchConduitAugmentation
|
|
11
|
+
*
|
|
12
|
+
* A specialized conduit augmentation that provides functionality for searching
|
|
13
|
+
* a server-hosted Brainy instance and storing results locally.
|
|
14
|
+
*/
|
|
15
|
+
export class ServerSearchConduitAugmentation extends WebSocketConduitAugmentation {
|
|
16
|
+
constructor(name = 'server-search-conduit') {
|
|
17
|
+
super(name);
|
|
18
|
+
this.localDb = null;
|
|
19
|
+
// this.description = 'Conduit augmentation for server-hosted Brainy search'
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Initialize the augmentation
|
|
23
|
+
*/
|
|
24
|
+
async initialize() {
|
|
25
|
+
if (this.isInitialized) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
// Initialize the base conduit
|
|
30
|
+
await super.initialize();
|
|
31
|
+
// Local DB must be set before initialization
|
|
32
|
+
if (!this.localDb) {
|
|
33
|
+
throw new Error('Local database not set. Call setLocalDb before initializing.');
|
|
34
|
+
}
|
|
35
|
+
this.isInitialized = true;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error(`Failed to initialize ${this.name}:`, error);
|
|
39
|
+
throw new Error(`Failed to initialize ${this.name}: ${error}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Set the local Brainy instance
|
|
44
|
+
* @param db The Brainy instance to use for local storage
|
|
45
|
+
*/
|
|
46
|
+
setLocalDb(db) {
|
|
47
|
+
this.localDb = db;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get the local Brainy instance
|
|
51
|
+
* @returns The local Brainy instance
|
|
52
|
+
*/
|
|
53
|
+
getLocalDb() {
|
|
54
|
+
return this.localDb;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Search the server-hosted Brainy instance and store results locally
|
|
58
|
+
* @param connectionId The ID of the established connection
|
|
59
|
+
* @param query The search query
|
|
60
|
+
* @param limit Maximum number of results to return
|
|
61
|
+
* @returns Search results
|
|
62
|
+
*/
|
|
63
|
+
async searchServer(connectionId, query, limit = 10) {
|
|
64
|
+
await this.ensureInitialized();
|
|
65
|
+
try {
|
|
66
|
+
// Create a search request
|
|
67
|
+
const readResult = await this.readData({
|
|
68
|
+
connectionId,
|
|
69
|
+
query: {
|
|
70
|
+
type: 'search',
|
|
71
|
+
query,
|
|
72
|
+
limit
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
if (readResult.success && readResult.data) {
|
|
76
|
+
const searchResults = readResult.data;
|
|
77
|
+
// Store the results in the local Brainy instance
|
|
78
|
+
if (this.localDb) {
|
|
79
|
+
for (const result of searchResults) {
|
|
80
|
+
// Check if the noun already exists in the local database
|
|
81
|
+
const existingNoun = await this.localDb.get(result.id);
|
|
82
|
+
if (!existingNoun) {
|
|
83
|
+
// Add the noun to the local database
|
|
84
|
+
await this.localDb.add(result.vector, result.metadata);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
success: true,
|
|
90
|
+
data: searchResults
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return {
|
|
95
|
+
success: false,
|
|
96
|
+
data: null,
|
|
97
|
+
error: readResult.error || 'Unknown error searching server'
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
console.error('Error searching server:', error);
|
|
103
|
+
return {
|
|
104
|
+
success: false,
|
|
105
|
+
data: null,
|
|
106
|
+
error: `Error searching server: ${error}`
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Search the local Brainy instance
|
|
112
|
+
* @param query The search query
|
|
113
|
+
* @param limit Maximum number of results to return
|
|
114
|
+
* @returns Search results
|
|
115
|
+
*/
|
|
116
|
+
async searchLocal(query, limit = 10) {
|
|
117
|
+
await this.ensureInitialized();
|
|
118
|
+
try {
|
|
119
|
+
if (!this.localDb) {
|
|
120
|
+
return {
|
|
121
|
+
success: false,
|
|
122
|
+
data: null,
|
|
123
|
+
error: 'Local database not initialized'
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const results = await this.localDb.searchText(query, limit);
|
|
127
|
+
return {
|
|
128
|
+
success: true,
|
|
129
|
+
data: results
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
console.error('Error searching local database:', error);
|
|
134
|
+
return {
|
|
135
|
+
success: false,
|
|
136
|
+
data: null,
|
|
137
|
+
error: `Error searching local database: ${error}`
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Search both server and local instances, combine results, and store server results locally
|
|
143
|
+
* @param connectionId The ID of the established connection
|
|
144
|
+
* @param query The search query
|
|
145
|
+
* @param limit Maximum number of results to return
|
|
146
|
+
* @returns Combined search results
|
|
147
|
+
*/
|
|
148
|
+
async searchCombined(connectionId, query, limit = 10) {
|
|
149
|
+
await this.ensureInitialized();
|
|
150
|
+
try {
|
|
151
|
+
// Search local first
|
|
152
|
+
const localSearchResult = await this.searchLocal(query, limit);
|
|
153
|
+
if (!localSearchResult.success) {
|
|
154
|
+
return localSearchResult;
|
|
155
|
+
}
|
|
156
|
+
const localResults = localSearchResult.data;
|
|
157
|
+
// If we have enough local results, return them
|
|
158
|
+
if (localResults.length >= limit) {
|
|
159
|
+
return localSearchResult;
|
|
160
|
+
}
|
|
161
|
+
// Otherwise, search server for additional results
|
|
162
|
+
const serverSearchResult = await this.searchServer(connectionId, query, limit - localResults.length);
|
|
163
|
+
if (!serverSearchResult.success) {
|
|
164
|
+
// If server search fails, return local results
|
|
165
|
+
return localSearchResult;
|
|
166
|
+
}
|
|
167
|
+
const serverResults = serverSearchResult.data;
|
|
168
|
+
// Combine results, removing duplicates
|
|
169
|
+
const combinedResults = [...localResults];
|
|
170
|
+
const localIds = new Set(localResults.map((r) => r.id));
|
|
171
|
+
for (const result of serverResults) {
|
|
172
|
+
if (!localIds.has(result.id)) {
|
|
173
|
+
combinedResults.push(result);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
success: true,
|
|
178
|
+
data: combinedResults
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
console.error('Error performing combined search:', error);
|
|
183
|
+
return {
|
|
184
|
+
success: false,
|
|
185
|
+
data: null,
|
|
186
|
+
error: `Error performing combined search: ${error}`
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Add data to both local and server instances
|
|
192
|
+
* @param connectionId The ID of the established connection
|
|
193
|
+
* @param data Text or vector to add
|
|
194
|
+
* @param metadata Metadata for the data
|
|
195
|
+
* @returns ID of the added data
|
|
196
|
+
*/
|
|
197
|
+
async addToBoth(connectionId, data, metadata = {}) {
|
|
198
|
+
await this.ensureInitialized();
|
|
199
|
+
try {
|
|
200
|
+
if (!this.localDb) {
|
|
201
|
+
return {
|
|
202
|
+
success: false,
|
|
203
|
+
data: '',
|
|
204
|
+
error: 'Local database not initialized'
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
// Add to local first
|
|
208
|
+
const id = await this.localDb.add(data, metadata);
|
|
209
|
+
// Get the vector and metadata
|
|
210
|
+
const noun = (await this.localDb.get(id));
|
|
211
|
+
if (!noun) {
|
|
212
|
+
return {
|
|
213
|
+
success: false,
|
|
214
|
+
data: '',
|
|
215
|
+
error: 'Failed to retrieve newly created noun'
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
// Add to server
|
|
219
|
+
const writeResult = await this.writeData({
|
|
220
|
+
connectionId,
|
|
221
|
+
data: {
|
|
222
|
+
type: 'addNoun',
|
|
223
|
+
vector: noun.vector,
|
|
224
|
+
metadata: noun.metadata
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
if (!writeResult.success) {
|
|
228
|
+
return {
|
|
229
|
+
success: true,
|
|
230
|
+
data: id,
|
|
231
|
+
error: `Added locally but failed to add to server: ${writeResult.error}`
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
success: true,
|
|
236
|
+
data: id
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
console.error('Error adding data to both:', error);
|
|
241
|
+
return {
|
|
242
|
+
success: false,
|
|
243
|
+
data: '',
|
|
244
|
+
error: `Error adding data to both: ${error}`
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* ServerSearchActivationAugmentation
|
|
251
|
+
*
|
|
252
|
+
* An activation augmentation that provides actions for server search functionality.
|
|
253
|
+
*/
|
|
254
|
+
export class ServerSearchActivationAugmentation {
|
|
255
|
+
constructor(name = 'server-search-activation') {
|
|
256
|
+
this.enabled = true;
|
|
257
|
+
this.isInitialized = false;
|
|
258
|
+
this.conduitAugmentation = null;
|
|
259
|
+
this.connections = new Map();
|
|
260
|
+
this.name = name;
|
|
261
|
+
this.description = 'Activation augmentation for server-hosted Brainy search';
|
|
262
|
+
}
|
|
263
|
+
getType() {
|
|
264
|
+
return AugmentationType.ACTIVATION;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Initialize the augmentation
|
|
268
|
+
*/
|
|
269
|
+
async initialize() {
|
|
270
|
+
if (this.isInitialized) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
this.isInitialized = true;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Shut down the augmentation
|
|
277
|
+
*/
|
|
278
|
+
async shutDown() {
|
|
279
|
+
this.isInitialized = false;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Get the status of the augmentation
|
|
283
|
+
*/
|
|
284
|
+
async getStatus() {
|
|
285
|
+
return this.isInitialized ? 'active' : 'inactive';
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Set the conduit augmentation to use for server search
|
|
289
|
+
* @param conduit The ServerSearchConduitAugmentation to use
|
|
290
|
+
*/
|
|
291
|
+
setConduitAugmentation(conduit) {
|
|
292
|
+
this.conduitAugmentation = conduit;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Store a connection for later use
|
|
296
|
+
* @param connectionId The ID to use for the connection
|
|
297
|
+
* @param connection The WebSocket connection
|
|
298
|
+
*/
|
|
299
|
+
storeConnection(connectionId, connection) {
|
|
300
|
+
this.connections.set(connectionId, connection);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Get a stored connection
|
|
304
|
+
* @param connectionId The ID of the connection to retrieve
|
|
305
|
+
* @returns The WebSocket connection
|
|
306
|
+
*/
|
|
307
|
+
getConnection(connectionId) {
|
|
308
|
+
return this.connections.get(connectionId);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Trigger an action based on a processed command or internal state
|
|
312
|
+
* @param actionName The name of the action to trigger
|
|
313
|
+
* @param parameters Optional parameters for the action
|
|
314
|
+
*/
|
|
315
|
+
triggerAction(actionName, parameters) {
|
|
316
|
+
if (!this.conduitAugmentation) {
|
|
317
|
+
return {
|
|
318
|
+
success: false,
|
|
319
|
+
data: null,
|
|
320
|
+
error: 'Conduit augmentation not set'
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
// Handle different actions
|
|
324
|
+
switch (actionName) {
|
|
325
|
+
case 'connectToServer':
|
|
326
|
+
return this.handleConnectToServer(parameters || {});
|
|
327
|
+
case 'searchServer':
|
|
328
|
+
return this.handleSearchServer(parameters || {});
|
|
329
|
+
case 'searchLocal':
|
|
330
|
+
return this.handleSearchLocal(parameters || {});
|
|
331
|
+
case 'searchCombined':
|
|
332
|
+
return this.handleSearchCombined(parameters || {});
|
|
333
|
+
case 'addToBoth':
|
|
334
|
+
return this.handleAddToBoth(parameters || {});
|
|
335
|
+
default:
|
|
336
|
+
return {
|
|
337
|
+
success: false,
|
|
338
|
+
data: null,
|
|
339
|
+
error: `Unknown action: ${actionName}`
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Handle the connectToServer action
|
|
345
|
+
* @param parameters Action parameters
|
|
346
|
+
*/
|
|
347
|
+
handleConnectToServer(parameters) {
|
|
348
|
+
const serverUrl = parameters.serverUrl;
|
|
349
|
+
const protocols = parameters.protocols;
|
|
350
|
+
if (!serverUrl) {
|
|
351
|
+
return {
|
|
352
|
+
success: false,
|
|
353
|
+
data: null,
|
|
354
|
+
error: 'serverUrl parameter is required'
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
// Return a promise that will be resolved when the connection is established
|
|
358
|
+
return {
|
|
359
|
+
success: true,
|
|
360
|
+
data: this.conduitAugmentation.establishConnection(serverUrl, {
|
|
361
|
+
protocols
|
|
362
|
+
})
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Handle the searchServer action
|
|
367
|
+
* @param parameters Action parameters
|
|
368
|
+
*/
|
|
369
|
+
handleSearchServer(parameters) {
|
|
370
|
+
const connectionId = parameters.connectionId;
|
|
371
|
+
const query = parameters.query;
|
|
372
|
+
const limit = parameters.limit || 10;
|
|
373
|
+
if (!connectionId) {
|
|
374
|
+
return {
|
|
375
|
+
success: false,
|
|
376
|
+
data: null,
|
|
377
|
+
error: 'connectionId parameter is required'
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
if (!query) {
|
|
381
|
+
return {
|
|
382
|
+
success: false,
|
|
383
|
+
data: null,
|
|
384
|
+
error: 'query parameter is required'
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
// Return a promise that will be resolved when the search is complete
|
|
388
|
+
return {
|
|
389
|
+
success: true,
|
|
390
|
+
data: this.conduitAugmentation.searchServer(connectionId, query, limit)
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Handle the searchLocal action
|
|
395
|
+
* @param parameters Action parameters
|
|
396
|
+
*/
|
|
397
|
+
handleSearchLocal(parameters) {
|
|
398
|
+
const query = parameters.query;
|
|
399
|
+
const limit = parameters.limit || 10;
|
|
400
|
+
if (!query) {
|
|
401
|
+
return {
|
|
402
|
+
success: false,
|
|
403
|
+
data: null,
|
|
404
|
+
error: 'query parameter is required'
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
// Return a promise that will be resolved when the search is complete
|
|
408
|
+
return {
|
|
409
|
+
success: true,
|
|
410
|
+
data: this.conduitAugmentation.searchLocal(query, limit)
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Handle the searchCombined action
|
|
415
|
+
* @param parameters Action parameters
|
|
416
|
+
*/
|
|
417
|
+
handleSearchCombined(parameters) {
|
|
418
|
+
const connectionId = parameters.connectionId;
|
|
419
|
+
const query = parameters.query;
|
|
420
|
+
const limit = parameters.limit || 10;
|
|
421
|
+
if (!connectionId) {
|
|
422
|
+
return {
|
|
423
|
+
success: false,
|
|
424
|
+
data: null,
|
|
425
|
+
error: 'connectionId parameter is required'
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
if (!query) {
|
|
429
|
+
return {
|
|
430
|
+
success: false,
|
|
431
|
+
data: null,
|
|
432
|
+
error: 'query parameter is required'
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
// Return a promise that will be resolved when the search is complete
|
|
436
|
+
return {
|
|
437
|
+
success: true,
|
|
438
|
+
data: this.conduitAugmentation.searchCombined(connectionId, query, limit)
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Handle the addToBoth action
|
|
443
|
+
* @param parameters Action parameters
|
|
444
|
+
*/
|
|
445
|
+
handleAddToBoth(parameters) {
|
|
446
|
+
const connectionId = parameters.connectionId;
|
|
447
|
+
const data = parameters.data;
|
|
448
|
+
const metadata = parameters.metadata || {};
|
|
449
|
+
if (!connectionId) {
|
|
450
|
+
return {
|
|
451
|
+
success: false,
|
|
452
|
+
data: null,
|
|
453
|
+
error: 'connectionId parameter is required'
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
if (!data) {
|
|
457
|
+
return {
|
|
458
|
+
success: false,
|
|
459
|
+
data: null,
|
|
460
|
+
error: 'data parameter is required'
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
// Return a promise that will be resolved when the add is complete
|
|
464
|
+
return {
|
|
465
|
+
success: true,
|
|
466
|
+
data: this.conduitAugmentation.addToBoth(connectionId, data, metadata)
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Generates an expressive output or response from Brainy
|
|
471
|
+
* @param knowledgeId The identifier of the knowledge to express
|
|
472
|
+
* @param format The desired output format (e.g., 'text', 'json')
|
|
473
|
+
*/
|
|
474
|
+
generateOutput(knowledgeId, format) {
|
|
475
|
+
// This method is not used for server search functionality
|
|
476
|
+
return {
|
|
477
|
+
success: false,
|
|
478
|
+
data: '',
|
|
479
|
+
error: 'generateOutput is not implemented for ServerSearchActivationAugmentation'
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Interacts with an external system or API
|
|
484
|
+
* @param systemId The identifier of the external system
|
|
485
|
+
* @param payload The data to send to the external system
|
|
486
|
+
*/
|
|
487
|
+
interactExternal(systemId, payload) {
|
|
488
|
+
// This method is not used for server search functionality
|
|
489
|
+
return {
|
|
490
|
+
success: false,
|
|
491
|
+
data: null,
|
|
492
|
+
error: 'interactExternal is not implemented for ServerSearchActivationAugmentation'
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Factory function to create server search augmentations
|
|
498
|
+
* @param serverUrl The URL of the server to connect to
|
|
499
|
+
* @param options Additional options
|
|
500
|
+
* @returns An object containing the created augmentations
|
|
501
|
+
*/
|
|
502
|
+
export async function createServerSearchAugmentations(serverUrl, options = {}) {
|
|
503
|
+
// Create the conduit augmentation
|
|
504
|
+
const conduit = new ServerSearchConduitAugmentation(options.conduitName);
|
|
505
|
+
await conduit.initialize();
|
|
506
|
+
// Set the local database if provided
|
|
507
|
+
if (options.localDb) {
|
|
508
|
+
conduit.setLocalDb(options.localDb);
|
|
509
|
+
}
|
|
510
|
+
// Create the activation augmentation
|
|
511
|
+
const activation = new ServerSearchActivationAugmentation(options.activationName);
|
|
512
|
+
await activation.initialize();
|
|
513
|
+
// Link the augmentations
|
|
514
|
+
activation.setConduitAugmentation(conduit);
|
|
515
|
+
// Connect to the server
|
|
516
|
+
const connectionResult = await conduit.establishConnection(serverUrl, {
|
|
517
|
+
protocols: options.protocols
|
|
518
|
+
});
|
|
519
|
+
if (!connectionResult.success || !connectionResult.data) {
|
|
520
|
+
throw new Error(`Failed to connect to server: ${connectionResult.error}`);
|
|
521
|
+
}
|
|
522
|
+
const connection = connectionResult.data;
|
|
523
|
+
// Store the connection in the activation augmentation
|
|
524
|
+
activation.storeConnection(connection.connectionId, connection);
|
|
525
|
+
return {
|
|
526
|
+
conduit,
|
|
527
|
+
activation,
|
|
528
|
+
connection
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
//# sourceMappingURL=serverSearchAugmentations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverSearchAugmentations.js","sourceRoot":"","sources":["../../src/augmentations/serverSearchAugmentations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,gBAAgB,EAMjB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAA;AAIxE;;;;;GAKG;AACH,MAAM,OAAO,+BAAgC,SAAQ,4BAA4B;IAG/E,YAAY,OAAe,uBAAuB;QAChD,KAAK,CAAC,IAA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AU,EAAE,CAAA;IAE1B,qCAAqC;IACrC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IACrC,CAAC;IAED,qCAAqC;IACrC,MAAM,UAAU,GAAG,IAAI,kCAAkC,CACvD,OAAO,CAAC,cAAc,CACvB,CAAA;IACD,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;IAE7B,yBAAyB;IACzB,UAAU,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAA;IAE1C,wBAAwB;IACxB,MAAM,gBAAgB,GAAG,MAAM,OAAO,CAAC,mBAAmB,CAAC,SAAS,EAAE;QACpE,SAAS,EAAE,OAAO,CAAC,SAAS;KAC7B,CAAC,CAAA;IAEF,IAAI,CAAC,gBAAgB,CAAC,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC;QACxD,MAAM,IAAI,KAAK,CAAC,gCAAgC,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAA;IAC3E,CAAC;IAED,MAAM,UAAU,GAAG,gBAAgB,CAAC,IAAI,CAAA;IAExC,sDAAsD;IACtD,UAAU,CAAC,eAAe,CAAC,UAAU,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;IAE/D,OAAO;QACL,OAAO;QACP,UAAU;QACV,UAAU;KACX,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser Framework Entry Point for Brainy
|
|
3
|
+
* Optimized for modern frameworks like Angular, React, Vue, etc.
|
|
4
|
+
* Auto-detects environment and uses optimal storage (OPFS in browsers)
|
|
5
|
+
*/
|
|
6
|
+
import { BrainyData, BrainyDataConfig } from './brainyData.js';
|
|
7
|
+
import { VerbType, NounType } from './types/graphTypes.js';
|
|
8
|
+
/**
|
|
9
|
+
* Create a BrainyData instance optimized for browser frameworks
|
|
10
|
+
* Auto-detects environment and selects optimal storage and settings
|
|
11
|
+
*/
|
|
12
|
+
export declare function createBrowserBrainyData(config?: Partial<BrainyDataConfig>): Promise<BrainyData>;
|
|
13
|
+
export { VerbType, NounType, BrainyData };
|
|
14
|
+
export type { BrainyDataConfig };
|
|
15
|
+
export default createBrowserBrainyData;
|
package/dist/demo.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Demo-specific entry point for browser environments
|
|
3
|
+
* This excludes all Node.js-specific functionality to avoid import issues
|
|
4
|
+
*/
|
|
5
|
+
import { MemoryStorage } from './storage/adapters/memoryStorage.js';
|
|
6
|
+
import { OPFSStorage } from './storage/adapters/opfsStorage.js';
|
|
7
|
+
export interface Vector extends Array<number> {
|
|
8
|
+
}
|
|
9
|
+
export interface SearchResult {
|
|
10
|
+
id: string;
|
|
11
|
+
score: number;
|
|
12
|
+
metadata: any;
|
|
13
|
+
text?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface VerbData {
|
|
16
|
+
id: string;
|
|
17
|
+
source: string;
|
|
18
|
+
target: string;
|
|
19
|
+
verb: string;
|
|
20
|
+
metadata: any;
|
|
21
|
+
timestamp: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Simplified BrainyData class for demo purposes
|
|
25
|
+
* Only includes browser-compatible functionality
|
|
26
|
+
*/
|
|
27
|
+
export declare class DemoBrainyData {
|
|
28
|
+
private storage;
|
|
29
|
+
private embedder;
|
|
30
|
+
private initialized;
|
|
31
|
+
private vectors;
|
|
32
|
+
private metadata;
|
|
33
|
+
private verbs;
|
|
34
|
+
constructor();
|
|
35
|
+
/**
|
|
36
|
+
* Initialize the database
|
|
37
|
+
*/
|
|
38
|
+
init(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Add a document to the database
|
|
41
|
+
*/
|
|
42
|
+
add(text: string, metadata?: any): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Search for similar documents
|
|
45
|
+
*/
|
|
46
|
+
searchText(query: string, limit?: number): Promise<SearchResult[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Add a relationship between two documents
|
|
49
|
+
*/
|
|
50
|
+
addVerb(sourceId: string, targetId: string, verb: string, metadata?: any): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Get relationships from a source document
|
|
53
|
+
*/
|
|
54
|
+
getVerbsBySource(sourceId: string): Promise<VerbData[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Get a document by ID
|
|
57
|
+
*/
|
|
58
|
+
get(id: string): Promise<any | null>;
|
|
59
|
+
/**
|
|
60
|
+
* Delete a document
|
|
61
|
+
*/
|
|
62
|
+
delete(id: string): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* Update document metadata
|
|
65
|
+
*/
|
|
66
|
+
updateMetadata(id: string, newMetadata: any): Promise<boolean>;
|
|
67
|
+
/**
|
|
68
|
+
* Get the number of documents
|
|
69
|
+
*/
|
|
70
|
+
size(): number;
|
|
71
|
+
/**
|
|
72
|
+
* Generate a random ID
|
|
73
|
+
*/
|
|
74
|
+
private generateId;
|
|
75
|
+
/**
|
|
76
|
+
* Get storage info
|
|
77
|
+
*/
|
|
78
|
+
getStorage(): MemoryStorage | OPFSStorage;
|
|
79
|
+
}
|
|
80
|
+
export declare const NounType: {
|
|
81
|
+
readonly Person: "Person";
|
|
82
|
+
readonly Organization: "Organization";
|
|
83
|
+
readonly Location: "Location";
|
|
84
|
+
readonly Thing: "Thing";
|
|
85
|
+
readonly Concept: "Concept";
|
|
86
|
+
readonly Event: "Event";
|
|
87
|
+
readonly Document: "Document";
|
|
88
|
+
readonly Media: "Media";
|
|
89
|
+
readonly File: "File";
|
|
90
|
+
readonly Message: "Message";
|
|
91
|
+
readonly Content: "Content";
|
|
92
|
+
};
|
|
93
|
+
export declare const VerbType: {
|
|
94
|
+
readonly RelatedTo: "related_to";
|
|
95
|
+
readonly Contains: "contains";
|
|
96
|
+
readonly PartOf: "part_of";
|
|
97
|
+
readonly LocatedAt: "located_at";
|
|
98
|
+
readonly References: "references";
|
|
99
|
+
readonly Owns: "owns";
|
|
100
|
+
readonly CreatedBy: "created_by";
|
|
101
|
+
readonly BelongsTo: "belongs_to";
|
|
102
|
+
readonly Likes: "likes";
|
|
103
|
+
readonly Follows: "follows";
|
|
104
|
+
};
|
|
105
|
+
export { DemoBrainyData as BrainyData };
|
|
106
|
+
export default DemoBrainyData;
|