@soulcraft/brainy 0.41.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 +3 -2
- 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.js +248 -0
- package/dist/storage/adapters/optimizedS3Search.js.map +1 -0
- package/dist/storage/adapters/s3CompatibleStorage.js +2026 -0
- package/dist/storage/adapters/s3CompatibleStorage.js.map +1 -0
- 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 -128251
- 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.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 -18
- 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,458 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for executing functions in Worker Threads (Node.js) or Web Workers (Browser)
|
|
3
|
+
* This implementation leverages Node.js 24's improved Worker Threads API for better performance
|
|
4
|
+
*/
|
|
5
|
+
import { isBrowser, isNode } from './environment.js';
|
|
6
|
+
// Worker pool to reuse workers
|
|
7
|
+
const workerPool = new Map();
|
|
8
|
+
const MAX_POOL_SIZE = 4; // Adjust based on system capabilities
|
|
9
|
+
/**
|
|
10
|
+
* Execute a function in a separate thread
|
|
11
|
+
*
|
|
12
|
+
* @param fnString The function to execute as a string
|
|
13
|
+
* @param args The arguments to pass to the function
|
|
14
|
+
* @returns A promise that resolves with the result of the function
|
|
15
|
+
*/
|
|
16
|
+
export function executeInThread(fnString, args) {
|
|
17
|
+
if (isNode()) {
|
|
18
|
+
return executeInNodeWorker(fnString, args);
|
|
19
|
+
}
|
|
20
|
+
else if (isBrowser() && typeof window !== 'undefined' && window.Worker) {
|
|
21
|
+
return executeInWebWorker(fnString, args);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
// Fallback to main thread execution
|
|
25
|
+
try {
|
|
26
|
+
// Try different approaches to create a function from string
|
|
27
|
+
let fn;
|
|
28
|
+
try {
|
|
29
|
+
// First try with 'return' prefix
|
|
30
|
+
fn = new Function('return ' + fnString)();
|
|
31
|
+
}
|
|
32
|
+
catch (functionError) {
|
|
33
|
+
console.warn('Fallback: Error creating function with return syntax, trying alternative approaches', functionError);
|
|
34
|
+
try {
|
|
35
|
+
// Try wrapping in parentheses for function expressions
|
|
36
|
+
fn = new Function('return (' + fnString + ')')();
|
|
37
|
+
}
|
|
38
|
+
catch (wrapError) {
|
|
39
|
+
console.warn('Fallback: Error creating function with parentheses wrapping', wrapError);
|
|
40
|
+
try {
|
|
41
|
+
// Try direct approach for named functions
|
|
42
|
+
fn = new Function(fnString)();
|
|
43
|
+
}
|
|
44
|
+
catch (directError) {
|
|
45
|
+
console.warn('Fallback: Direct approach failed, trying with function wrapper', directError);
|
|
46
|
+
try {
|
|
47
|
+
// Try wrapping in a function that returns the function expression
|
|
48
|
+
fn = new Function('return function(args) { return (' + fnString + ')(args); }')();
|
|
49
|
+
}
|
|
50
|
+
catch (wrapperError) {
|
|
51
|
+
console.error('Fallback: All approaches to create function failed', wrapperError);
|
|
52
|
+
throw new Error('Failed to create function from string: ' +
|
|
53
|
+
functionError.message);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return Promise.resolve(fn(args));
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return Promise.reject(error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Execute a function in a Node.js Worker Thread
|
|
67
|
+
* Optimized for Node.js 24 with improved Worker Threads performance
|
|
68
|
+
*/
|
|
69
|
+
function executeInNodeWorker(fnString, args) {
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
try {
|
|
72
|
+
// Dynamically import worker_threads (Node.js only)
|
|
73
|
+
import('node:worker_threads')
|
|
74
|
+
.then(({ Worker, isMainThread, parentPort, workerData }) => {
|
|
75
|
+
if (!isMainThread && parentPort) {
|
|
76
|
+
// We're inside a worker, execute the function
|
|
77
|
+
const fn = new Function('return ' + workerData.fnString)();
|
|
78
|
+
const result = fn(workerData.args);
|
|
79
|
+
parentPort.postMessage({ result });
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// Get a worker from the pool or create a new one
|
|
83
|
+
const workerId = `worker-${Math.random().toString(36).substring(2, 9)}`;
|
|
84
|
+
let worker;
|
|
85
|
+
if (workerPool.size < MAX_POOL_SIZE) {
|
|
86
|
+
// Create a new worker
|
|
87
|
+
worker = new Worker(`
|
|
88
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
89
|
+
|
|
90
|
+
// Add TensorFlow.js platform patch for Node.js
|
|
91
|
+
if (typeof global !== 'undefined') {
|
|
92
|
+
try {
|
|
93
|
+
// Define a custom PlatformNode class
|
|
94
|
+
class PlatformNode {
|
|
95
|
+
constructor() {
|
|
96
|
+
// Create a util object with necessary methods
|
|
97
|
+
this.util = {
|
|
98
|
+
// Add isFloat32Array and isTypedArray directly to util
|
|
99
|
+
isFloat32Array: (arr) => {
|
|
100
|
+
return !!(
|
|
101
|
+
arr instanceof Float32Array ||
|
|
102
|
+
(arr &&
|
|
103
|
+
Object.prototype.toString.call(arr) === '[object Float32Array]')
|
|
104
|
+
);
|
|
105
|
+
},
|
|
106
|
+
isTypedArray: (arr) => {
|
|
107
|
+
return !!(ArrayBuffer.isView(arr) && !(arr instanceof DataView));
|
|
108
|
+
},
|
|
109
|
+
// Use native TextEncoder and TextDecoder
|
|
110
|
+
TextEncoder: TextEncoder,
|
|
111
|
+
TextDecoder: TextDecoder
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// Initialize encoders using native constructors
|
|
115
|
+
this.textEncoder = new TextEncoder();
|
|
116
|
+
this.textDecoder = new TextDecoder();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Define isFloat32Array directly on the instance
|
|
120
|
+
isFloat32Array(arr) {
|
|
121
|
+
return !!(
|
|
122
|
+
arr instanceof Float32Array ||
|
|
123
|
+
(arr && Object.prototype.toString.call(arr) === '[object Float32Array]')
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Define isTypedArray directly on the instance
|
|
128
|
+
isTypedArray(arr) {
|
|
129
|
+
return !!(ArrayBuffer.isView(arr) && !(arr instanceof DataView));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Assign the PlatformNode class to the global object
|
|
134
|
+
global.PlatformNode = PlatformNode;
|
|
135
|
+
|
|
136
|
+
// Also create an instance and assign it to global.platformNode
|
|
137
|
+
global.platformNode = new PlatformNode();
|
|
138
|
+
|
|
139
|
+
// Ensure global.util exists and has the necessary methods
|
|
140
|
+
if (!global.util) {
|
|
141
|
+
global.util = {};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Add isFloat32Array method if it doesn't exist
|
|
145
|
+
if (!global.util.isFloat32Array) {
|
|
146
|
+
global.util.isFloat32Array = (arr) => {
|
|
147
|
+
return !!(
|
|
148
|
+
arr instanceof Float32Array ||
|
|
149
|
+
(arr && Object.prototype.toString.call(arr) === '[object Float32Array]')
|
|
150
|
+
);
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Add isTypedArray method if it doesn't exist
|
|
155
|
+
if (!global.util.isTypedArray) {
|
|
156
|
+
global.util.isTypedArray = (arr) => {
|
|
157
|
+
return !!(ArrayBuffer.isView(arr) && !(arr instanceof DataView));
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.warn('Failed to apply TensorFlow.js platform patch:', error);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const fn = new Function('return ' + workerData.fnString)();
|
|
166
|
+
const result = fn(workerData.args);
|
|
167
|
+
parentPort.postMessage({ result });
|
|
168
|
+
`, {
|
|
169
|
+
eval: true,
|
|
170
|
+
workerData: { fnString, args }
|
|
171
|
+
});
|
|
172
|
+
workerPool.set(workerId, worker);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
// Reuse an existing worker
|
|
176
|
+
const poolKeys = Array.from(workerPool.keys());
|
|
177
|
+
const randomKey = poolKeys[Math.floor(Math.random() * poolKeys.length)];
|
|
178
|
+
worker = workerPool.get(randomKey);
|
|
179
|
+
// Terminate and recreate if the worker is busy
|
|
180
|
+
if (worker._busy) {
|
|
181
|
+
worker.terminate();
|
|
182
|
+
worker = new Worker(`
|
|
183
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
184
|
+
|
|
185
|
+
// Add TensorFlow.js platform patch for Node.js
|
|
186
|
+
if (typeof global !== 'undefined') {
|
|
187
|
+
try {
|
|
188
|
+
// Define a custom PlatformNode class
|
|
189
|
+
class PlatformNode {
|
|
190
|
+
constructor() {
|
|
191
|
+
// Create a util object with necessary methods
|
|
192
|
+
this.util = {
|
|
193
|
+
// Use native TextEncoder and TextDecoder
|
|
194
|
+
TextEncoder: TextEncoder,
|
|
195
|
+
TextDecoder: TextDecoder
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// Initialize encoders using native constructors
|
|
199
|
+
this.textEncoder = new TextEncoder();
|
|
200
|
+
this.textDecoder = new TextDecoder();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Define isFloat32Array directly on the instance
|
|
204
|
+
isFloat32Array(arr) {
|
|
205
|
+
return !!(
|
|
206
|
+
arr instanceof Float32Array ||
|
|
207
|
+
(arr && Object.prototype.toString.call(arr) === '[object Float32Array]')
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Define isTypedArray directly on the instance
|
|
212
|
+
isTypedArray(arr) {
|
|
213
|
+
return !!(ArrayBuffer.isView(arr) && !(arr instanceof DataView));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Assign the PlatformNode class to the global object
|
|
218
|
+
global.PlatformNode = PlatformNode;
|
|
219
|
+
|
|
220
|
+
// Also create an instance and assign it to global.platformNode
|
|
221
|
+
global.platformNode = new PlatformNode();
|
|
222
|
+
|
|
223
|
+
// Ensure global.util exists and has the necessary methods
|
|
224
|
+
if (!global.util) {
|
|
225
|
+
global.util = {};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Add isFloat32Array method if it doesn't exist
|
|
229
|
+
if (!global.util.isFloat32Array) {
|
|
230
|
+
global.util.isFloat32Array = (arr) => {
|
|
231
|
+
return !!(
|
|
232
|
+
arr instanceof Float32Array ||
|
|
233
|
+
(arr && Object.prototype.toString.call(arr) === '[object Float32Array]')
|
|
234
|
+
);
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Add isTypedArray method if it doesn't exist
|
|
239
|
+
if (!global.util.isTypedArray) {
|
|
240
|
+
global.util.isTypedArray = (arr) => {
|
|
241
|
+
return !!(ArrayBuffer.isView(arr) && !(arr instanceof DataView));
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
} catch (error) {
|
|
245
|
+
console.warn('Failed to apply TensorFlow.js platform patch:', error);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const fn = new Function('return ' + workerData.fnString)();
|
|
250
|
+
const result = fn(workerData.args);
|
|
251
|
+
parentPort.postMessage({ result });
|
|
252
|
+
`, {
|
|
253
|
+
eval: true,
|
|
254
|
+
workerData: { fnString, args }
|
|
255
|
+
});
|
|
256
|
+
workerPool.set(randomKey, worker);
|
|
257
|
+
}
|
|
258
|
+
worker._busy = true;
|
|
259
|
+
}
|
|
260
|
+
worker.on('message', (message) => {
|
|
261
|
+
worker._busy = false;
|
|
262
|
+
resolve(message.result);
|
|
263
|
+
});
|
|
264
|
+
worker.on('error', (err) => {
|
|
265
|
+
worker._busy = false;
|
|
266
|
+
reject(err);
|
|
267
|
+
});
|
|
268
|
+
worker.on('exit', (code) => {
|
|
269
|
+
if (code !== 0) {
|
|
270
|
+
worker._busy = false;
|
|
271
|
+
reject(new Error(`Worker stopped with exit code ${code}`));
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
})
|
|
275
|
+
.catch(reject);
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
reject(error);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Execute a function in a Web Worker (Browser environment)
|
|
284
|
+
*/
|
|
285
|
+
function executeInWebWorker(fnString, args) {
|
|
286
|
+
return new Promise((resolve, reject) => {
|
|
287
|
+
try {
|
|
288
|
+
// Use the dedicated worker.js file instead of creating a blob
|
|
289
|
+
// Try different approaches to locate the worker.js file
|
|
290
|
+
let workerPath = './worker.js';
|
|
291
|
+
try {
|
|
292
|
+
// First try to use the import.meta.url if available (modern browsers)
|
|
293
|
+
if (typeof import.meta !== 'undefined' && import.meta.url) {
|
|
294
|
+
const baseUrl = import.meta.url.substring(0, import.meta.url.lastIndexOf('/') + 1);
|
|
295
|
+
workerPath = `${baseUrl}worker.js`;
|
|
296
|
+
}
|
|
297
|
+
// Fallback to a relative path based on the unified.js location
|
|
298
|
+
else if (typeof document !== 'undefined') {
|
|
299
|
+
// Find the script tag that loaded unified.js
|
|
300
|
+
const scripts = document.getElementsByTagName('script');
|
|
301
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
302
|
+
const src = scripts[i].src;
|
|
303
|
+
if (src && src.includes('unified.js')) {
|
|
304
|
+
// Get the directory path
|
|
305
|
+
workerPath =
|
|
306
|
+
src.substring(0, src.lastIndexOf('/') + 1) + 'worker.js';
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
catch (e) {
|
|
313
|
+
console.warn('Could not determine worker path from import.meta.url, using relative path', e);
|
|
314
|
+
}
|
|
315
|
+
// If we couldn't determine the path, try some common locations
|
|
316
|
+
if (workerPath === './worker.js' && typeof window !== 'undefined') {
|
|
317
|
+
// Try to find the worker.js in the same directory as the current page
|
|
318
|
+
const pageUrl = window.location.href;
|
|
319
|
+
const pageDir = pageUrl.substring(0, pageUrl.lastIndexOf('/') + 1);
|
|
320
|
+
workerPath = `${pageDir}worker.js`;
|
|
321
|
+
// Also check for dist/worker.js
|
|
322
|
+
if (typeof document !== 'undefined') {
|
|
323
|
+
const distWorkerPath = `${pageDir}dist/worker.js`;
|
|
324
|
+
// Create a test request to see if the file exists
|
|
325
|
+
const xhr = new XMLHttpRequest();
|
|
326
|
+
xhr.open('HEAD', distWorkerPath, false);
|
|
327
|
+
try {
|
|
328
|
+
xhr.send();
|
|
329
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
330
|
+
workerPath = distWorkerPath;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
catch (e) {
|
|
334
|
+
// Ignore errors, we'll use the default path
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
console.log('Using worker path:', workerPath);
|
|
339
|
+
// Try to create a worker, but fall back to inline worker or main thread execution if it fails
|
|
340
|
+
let worker;
|
|
341
|
+
try {
|
|
342
|
+
worker = new Worker(workerPath);
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
console.warn('Failed to create Web Worker from file, trying inline worker:', error);
|
|
346
|
+
try {
|
|
347
|
+
// Create an inline worker using a Blob
|
|
348
|
+
const workerCode = `
|
|
349
|
+
// Brainy Inline Worker Script
|
|
350
|
+
console.log('Brainy Inline Worker: Started');
|
|
351
|
+
|
|
352
|
+
self.onmessage = function (e) {
|
|
353
|
+
try {
|
|
354
|
+
console.log('Brainy Inline Worker: Received message', e.data ? 'with data' : 'without data');
|
|
355
|
+
|
|
356
|
+
if (!e.data || !e.data.fnString) {
|
|
357
|
+
throw new Error('Invalid message: missing function string');
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
console.log('Brainy Inline Worker: Creating function from string');
|
|
361
|
+
const fn = new Function('return ' + e.data.fnString)();
|
|
362
|
+
|
|
363
|
+
console.log('Brainy Inline Worker: Executing function with args');
|
|
364
|
+
const result = fn(e.data.args);
|
|
365
|
+
|
|
366
|
+
console.log('Brainy Inline Worker: Function executed successfully, posting result');
|
|
367
|
+
self.postMessage({ result: result });
|
|
368
|
+
} catch (error) {
|
|
369
|
+
console.error('Brainy Inline Worker: Error executing function', error);
|
|
370
|
+
self.postMessage({
|
|
371
|
+
error: error.message,
|
|
372
|
+
stack: error.stack
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
`;
|
|
377
|
+
const blob = new Blob([workerCode], {
|
|
378
|
+
type: 'application/javascript'
|
|
379
|
+
});
|
|
380
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
381
|
+
worker = new Worker(blobUrl);
|
|
382
|
+
console.log('Created inline worker using Blob URL');
|
|
383
|
+
}
|
|
384
|
+
catch (inlineWorkerError) {
|
|
385
|
+
console.warn('Failed to create inline Web Worker, falling back to main thread execution:', inlineWorkerError);
|
|
386
|
+
// Execute in main thread as fallback
|
|
387
|
+
try {
|
|
388
|
+
const fn = new Function('return ' + fnString)();
|
|
389
|
+
resolve(fn(args));
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
catch (mainThreadError) {
|
|
393
|
+
reject(mainThreadError);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
// Set a timeout to prevent hanging
|
|
399
|
+
const timeoutId = setTimeout(() => {
|
|
400
|
+
console.warn('Web Worker execution timed out, falling back to main thread');
|
|
401
|
+
worker.terminate();
|
|
402
|
+
// Execute in main thread as fallback
|
|
403
|
+
try {
|
|
404
|
+
const fn = new Function('return ' + fnString)();
|
|
405
|
+
resolve(fn(args));
|
|
406
|
+
}
|
|
407
|
+
catch (mainThreadError) {
|
|
408
|
+
reject(mainThreadError);
|
|
409
|
+
}
|
|
410
|
+
}, 25000); // 25 second timeout (less than the 30 second test timeout)
|
|
411
|
+
worker.onmessage = function (e) {
|
|
412
|
+
clearTimeout(timeoutId);
|
|
413
|
+
if (e.data.error) {
|
|
414
|
+
reject(new Error(e.data.error));
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
resolve(e.data.result);
|
|
418
|
+
}
|
|
419
|
+
worker.terminate();
|
|
420
|
+
};
|
|
421
|
+
worker.onerror = function (e) {
|
|
422
|
+
clearTimeout(timeoutId);
|
|
423
|
+
console.warn('Web Worker error, falling back to main thread execution:', e.message);
|
|
424
|
+
worker.terminate();
|
|
425
|
+
// Execute in main thread as fallback
|
|
426
|
+
try {
|
|
427
|
+
const fn = new Function('return ' + fnString)();
|
|
428
|
+
resolve(fn(args));
|
|
429
|
+
}
|
|
430
|
+
catch (mainThreadError) {
|
|
431
|
+
reject(mainThreadError);
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
worker.postMessage({ fnString, args });
|
|
435
|
+
}
|
|
436
|
+
catch (error) {
|
|
437
|
+
reject(error);
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Clean up all worker pools
|
|
443
|
+
* This should be called when the application is shutting down
|
|
444
|
+
*/
|
|
445
|
+
export function cleanupWorkerPools() {
|
|
446
|
+
if (isNode()) {
|
|
447
|
+
import('node:worker_threads')
|
|
448
|
+
.then(({ Worker }) => {
|
|
449
|
+
for (const worker of workerPool.values()) {
|
|
450
|
+
worker.terminate();
|
|
451
|
+
}
|
|
452
|
+
workerPool.clear();
|
|
453
|
+
console.log('Worker pools cleaned up');
|
|
454
|
+
})
|
|
455
|
+
.catch(console.error);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
//# sourceMappingURL=workerUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workerUtils.js","sourceRoot":"","sources":["../../src/utils/workerUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEpD,+BAA+B;AAC/B,MAAM,UAAU,GAAqB,IAAI,GAAG,EAAE,CAAA;AAC9C,MAAM,aAAa,GAAG,CAAC,CAAA,CAAC,sCAAsC;AAE9D;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAI,QAAgB,EAAE,IAAS;IAC5D,IAAI,MAAM,EAAE,EAAE,CAAC;QACb,OAAO,mBAAmB,CAAI,QAAQ,EAAE,IAAI,CAAC,CAAA;IAC/C,CAAC;SAAM,IAAI,SAAS,EAAE,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QACzE,OAAO,kBAAkB,CAAI,QAAQ,EAAE,IAAI,CAAC,CAAA;IAC9C,CAAC;SAAM,CAAC;QACN,oCAAoC;QACpC,IAAI,CAAC;YACH,4DAA4D;YAC5D,IAAI,EAAE,CAAA;YACN,IAAI,CAAC;gBACH,iCAAiC;gBACjC,EAAE,GAAG,IAAI,QAAQ,CAAC,SAAS,GAAG,QAAQ,CAAC,EAAE,CAAA;YAC3C,CAAC;YAAC,OAAO,aAAa,EAAE,CAAC;gBACvB,OAAO,CAAC,IAAI,CACV,qFAAqF,EACrF,aAAa,CACd,CAAA;gBAED,IAAI,CAAC;oBACH,uDAAuD;oBACvD,EAAE,GAAG,IAAI,QAAQ,CAAC,UAAU,GAAG,QAAQ,GAAG,GAAG,CAAC,EAAE,CAAA;gBAClD,CAAC;gBAAC,OAAO,SAAS,EAAE,CAAC;oBACnB,OAAO,CA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AAyB,CAAC,CAAA;QACxC,CAAC,CAAC;aACD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACzB,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soulcraft/brainy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"description": "A vector graph database using HNSW indexing with Origin Private File System storage",
|
|
5
|
-
"main": "dist/
|
|
6
|
-
"module": "dist/
|
|
7
|
-
"types": "dist/
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"sideEffects": [
|
|
10
10
|
"./dist/setup.js",
|
|
@@ -14,11 +14,8 @@
|
|
|
14
14
|
],
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
|
-
"import": "./dist/
|
|
18
|
-
"types": "./dist/
|
|
19
|
-
},
|
|
20
|
-
"./min": {
|
|
21
|
-
"import": "./dist/unified.min.js"
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts"
|
|
22
19
|
},
|
|
23
20
|
"./setup": {
|
|
24
21
|
"import": "./dist/setup.js",
|
|
@@ -48,15 +45,12 @@
|
|
|
48
45
|
"engines": {
|
|
49
46
|
"node": ">=24.4.0"
|
|
50
47
|
},
|
|
51
|
-
"overrides": {
|
|
52
|
-
"form-data": "^4.0.4"
|
|
53
|
-
},
|
|
54
48
|
"scripts": {
|
|
55
49
|
"prebuild": "echo 'Prebuild step - no version generation needed'",
|
|
56
|
-
"build": "
|
|
57
|
-
"build:
|
|
58
|
-
"start": "node dist/
|
|
59
|
-
"demo": "npm run build && npm run build
|
|
50
|
+
"build": "tsc",
|
|
51
|
+
"build:framework": "tsc",
|
|
52
|
+
"start": "node dist/framework.js",
|
|
53
|
+
"demo": "npm run build && cd demo/brainy-angular-demo && npm run build && npm run serve",
|
|
60
54
|
"prepare": "npm run build",
|
|
61
55
|
"test": "vitest run",
|
|
62
56
|
"test:watch": "vitest",
|
|
@@ -74,6 +68,10 @@
|
|
|
74
68
|
"test:environments": "vitest run tests/multi-environment.test.ts",
|
|
75
69
|
"test:specialized": "vitest run tests/specialized-scenarios.test.ts",
|
|
76
70
|
"test:performance": "vitest run tests/performance.test.ts",
|
|
71
|
+
"test:install": "vitest run tests/package-install.test.ts",
|
|
72
|
+
"test:docker": "vitest run tests/custom-models-path.test.ts",
|
|
73
|
+
"test:extraction": "node tests/auto-extraction.test.js",
|
|
74
|
+
"extract-models": "node scripts/extract-models.js",
|
|
77
75
|
"test:comprehensive": "npm run test:error-handling && npm run test:edge-cases && npm run test:storage && npm run test:environments && npm run test:specialized",
|
|
78
76
|
"_generate-pdf": "node dev/scripts/generate-architecture-pdf.js",
|
|
79
77
|
"_release": "standard-version",
|
|
@@ -157,7 +155,7 @@
|
|
|
157
155
|
"node-fetch": "^3.3.2",
|
|
158
156
|
"puppeteer": "^22.15.0",
|
|
159
157
|
"rollup": "^4.13.0",
|
|
160
|
-
"rollup
|
|
158
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
161
159
|
"standard-version": "^9.5.0",
|
|
162
160
|
"tslib": "^2.6.2",
|
|
163
161
|
"typescript": "^5.4.5",
|
|
@@ -165,7 +163,6 @@
|
|
|
165
163
|
},
|
|
166
164
|
"dependencies": {
|
|
167
165
|
"@aws-sdk/client-s3": "^3.540.0",
|
|
168
|
-
"@tensorflow-models/universal-sentence-encoder": "^1.3.3",
|
|
169
166
|
"@tensorflow/tfjs": "^4.22.0",
|
|
170
167
|
"@tensorflow/tfjs-backend-cpu": "^4.22.0",
|
|
171
168
|
"@tensorflow/tfjs-backend-webgl": "^4.22.0",
|
|
@@ -175,6 +172,14 @@
|
|
|
175
172
|
"dotenv": "^16.4.5",
|
|
176
173
|
"uuid": "^9.0.1"
|
|
177
174
|
},
|
|
175
|
+
"peerDependencies": {
|
|
176
|
+
"@soulcraft/brainy-models": ">=0.7.0"
|
|
177
|
+
},
|
|
178
|
+
"peerDependenciesMeta": {
|
|
179
|
+
"@soulcraft/brainy-models": {
|
|
180
|
+
"optional": true
|
|
181
|
+
}
|
|
182
|
+
},
|
|
178
183
|
"prettier": {
|
|
179
184
|
"arrowParens": "always",
|
|
180
185
|
"bracketSameLine": true,
|