@soulcraft/brainy 0.43.0 → 0.44.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/dist/augmentationFactory.d.ts.map +1 -0
- package/dist/augmentationFactory.js +342 -0
- package/dist/augmentationFactory.js.map +1 -0
- package/dist/augmentationPipeline.d.ts.map +1 -0
- package/dist/augmentationPipeline.js +472 -0
- package/dist/augmentationPipeline.js.map +1 -0
- package/dist/augmentationRegistry.d.ts.map +1 -0
- package/dist/augmentationRegistry.js +105 -0
- package/dist/augmentationRegistry.js.map +1 -0
- package/dist/augmentationRegistryLoader.d.ts.map +1 -0
- package/dist/augmentationRegistryLoader.js +213 -0
- package/dist/augmentationRegistryLoader.js.map +1 -0
- package/dist/brainyData.d.ts.map +1 -0
- package/dist/brainyData.js +3999 -0
- package/dist/brainyData.js.map +1 -0
- package/dist/browserFramework.d.ts.map +1 -0
- package/dist/browserFramework.js +31 -0
- package/dist/browserFramework.js.map +1 -0
- package/dist/coreTypes.d.ts.map +1 -0
- package/dist/coreTypes.js +5 -0
- package/dist/coreTypes.js.map +1 -0
- package/dist/demo.d.ts.map +1 -0
- package/dist/demo.js +201 -0
- package/dist/demo.js.map +1 -0
- package/dist/distributed/configManager.d.ts.map +1 -0
- package/dist/distributed/configManager.js +322 -0
- package/dist/distributed/configManager.js.map +1 -0
- package/dist/distributed/domainDetector.d.ts.map +1 -0
- package/dist/distributed/domainDetector.js +307 -0
- package/dist/distributed/domainDetector.js.map +1 -0
- package/dist/distributed/hashPartitioner.d.ts.map +1 -0
- package/dist/distributed/hashPartitioner.js +146 -0
- package/dist/distributed/hashPartitioner.js.map +1 -0
- package/dist/distributed/healthMonitor.d.ts.map +1 -0
- package/dist/distributed/healthMonitor.js +244 -0
- package/dist/distributed/healthMonitor.js.map +1 -0
- package/dist/distributed/index.d.ts.map +1 -0
- package/dist/distributed/index.js +9 -0
- package/dist/distributed/index.js.map +1 -0
- package/dist/distributed/operationalModes.d.ts.map +1 -0
- package/dist/distributed/operationalModes.js +201 -0
- package/dist/distributed/operationalModes.js.map +1 -0
- package/dist/errors/brainyError.d.ts.map +1 -0
- package/dist/errors/brainyError.js +113 -0
- package/dist/errors/brainyError.js.map +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/pipeline.js +590 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/sequentialPipeline.d.ts.map +1 -0
- package/dist/sequentialPipeline.js +417 -0
- package/dist/sequentialPipeline.js.map +1 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +46 -0
- package/dist/setup.js.map +1 -0
- package/dist/unified.d.ts.map +1 -0
- package/dist/unified.js.map +1 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +54 -0
- package/dist/worker.js.map +1 -0
- package/package.json +8 -12
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sequential Augmentation Pipeline
|
|
3
|
+
*
|
|
4
|
+
* This module provides a pipeline for executing augmentations in a specific sequence:
|
|
5
|
+
* ISense -> IMemory -> ICognition -> IConduit -> IActivation -> IPerception
|
|
6
|
+
*
|
|
7
|
+
* It supports high-performance streaming data from WebSockets without blocking.
|
|
8
|
+
* Optimized for Node.js 23.11+ using native WebStreams API.
|
|
9
|
+
*/
|
|
10
|
+
import { AugmentationType } from './types/augmentations.js';
|
|
11
|
+
import { BrainyData } from './brainyData.js';
|
|
12
|
+
import { augmentationPipeline } from './augmentationPipeline.js';
|
|
13
|
+
// Use the browser's built-in WebStreams API or Node.js native WebStreams API
|
|
14
|
+
// This approach ensures compatibility with both environments
|
|
15
|
+
let TransformStream, ReadableStream, WritableStream;
|
|
16
|
+
// Function to initialize the stream classes
|
|
17
|
+
const initializeStreamClasses = () => {
|
|
18
|
+
// Try to use the browser's built-in WebStreams API first
|
|
19
|
+
if (typeof globalThis.TransformStream !== 'undefined' &&
|
|
20
|
+
typeof globalThis.ReadableStream !== 'undefined' &&
|
|
21
|
+
typeof globalThis.WritableStream !== 'undefined') {
|
|
22
|
+
TransformStream = globalThis.TransformStream;
|
|
23
|
+
ReadableStream = globalThis.ReadableStream;
|
|
24
|
+
WritableStream = globalThis.WritableStream;
|
|
25
|
+
return Promise.resolve();
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
// In Node.js environment, try to import from node:stream/web
|
|
29
|
+
// This will be executed in Node.js but not in browsers
|
|
30
|
+
return import('node:stream/web')
|
|
31
|
+
.then(streamWebModule => {
|
|
32
|
+
TransformStream = streamWebModule.TransformStream;
|
|
33
|
+
ReadableStream = streamWebModule.ReadableStream;
|
|
34
|
+
WritableStream = streamWebModule.WritableStream;
|
|
35
|
+
})
|
|
36
|
+
.catch(error => {
|
|
37
|
+
console.error('Failed to import WebStreams API:', error);
|
|
38
|
+
// Provide fallback implementations or throw a more helpful error
|
|
39
|
+
throw new Error('WebStreams API is not available in this environment. Please use a modern browser or Node.js 18+.');
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
// Initialize immediately but don't block module execution
|
|
44
|
+
const streamClassesPromise = initializeStreamClasses();
|
|
45
|
+
/**
|
|
46
|
+
* Default pipeline options
|
|
47
|
+
*/
|
|
48
|
+
const DEFAULT_SEQUENTIAL_PIPELINE_OPTIONS = {
|
|
49
|
+
timeout: 30000,
|
|
50
|
+
stopOnError: false
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* SequentialPipeline class
|
|
54
|
+
*
|
|
55
|
+
* Executes augmentations in a specific sequence:
|
|
56
|
+
* ISense -> IMemory -> ICognition -> IConduit -> IActivation -> IPerception
|
|
57
|
+
*/
|
|
58
|
+
export class SequentialPipeline {
|
|
59
|
+
/**
|
|
60
|
+
* Create a new sequential pipeline
|
|
61
|
+
*
|
|
62
|
+
* @param options Options for the pipeline
|
|
63
|
+
*/
|
|
64
|
+
constructor(options = {}) {
|
|
65
|
+
this.brainyData = options.brainyData || new BrainyData();
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Ensure stream classes are initialized
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
async ensureStreamClassesInitialized() {
|
|
72
|
+
await streamClassesPromise;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Initialize the pipeline
|
|
76
|
+
*
|
|
77
|
+
* @returns A promise that resolves when initialization is complete
|
|
78
|
+
*/
|
|
79
|
+
async initialize() {
|
|
80
|
+
// Initialize stream classes and BrainyData in parallel
|
|
81
|
+
await Promise.all([
|
|
82
|
+
this.ensureStreamClassesInitialized(),
|
|
83
|
+
this.brainyData.init()
|
|
84
|
+
]);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Process data through the sequential pipeline
|
|
88
|
+
*
|
|
89
|
+
* @param rawData The raw data to process
|
|
90
|
+
* @param dataType The type of data (e.g., 'text', 'image', 'audio')
|
|
91
|
+
* @param options Options for pipeline execution
|
|
92
|
+
* @returns A promise that resolves with the pipeline result
|
|
93
|
+
*/
|
|
94
|
+
async processData(rawData, dataType, options = {}) {
|
|
95
|
+
const opts = { ...DEFAULT_SEQUENTIAL_PIPELINE_OPTIONS, ...options };
|
|
96
|
+
const result = {
|
|
97
|
+
success: true,
|
|
98
|
+
data: null,
|
|
99
|
+
stageResults: {}
|
|
100
|
+
};
|
|
101
|
+
try {
|
|
102
|
+
// Step 1: Process raw data with ISense augmentations
|
|
103
|
+
const senseResults = await augmentationPipeline.executeSensePipeline('processRawData', [rawData, dataType], { timeout: opts.timeout, stopOnError: opts.stopOnError });
|
|
104
|
+
// Get the first successful result
|
|
105
|
+
let senseResult = null;
|
|
106
|
+
for (const resultPromise of senseResults) {
|
|
107
|
+
const res = await resultPromise;
|
|
108
|
+
if (res.success) {
|
|
109
|
+
senseResult = res;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!senseResult || !senseResult.success) {
|
|
114
|
+
return {
|
|
115
|
+
success: false,
|
|
116
|
+
data: null,
|
|
117
|
+
error: 'Failed to process raw data with ISense augmentations',
|
|
118
|
+
stageResults: { sense: senseResult || { success: false, data: null, error: 'No sense augmentations available' } }
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
result.stageResults.sense = senseResult;
|
|
122
|
+
// Step 2: Store data in BrainyData using IMemory augmentations
|
|
123
|
+
const memoryAugmentations = augmentationPipeline.getAugmentationsByType(AugmentationType.MEMORY);
|
|
124
|
+
if (memoryAugmentations.length === 0) {
|
|
125
|
+
return {
|
|
126
|
+
success: false,
|
|
127
|
+
data: null,
|
|
128
|
+
error: 'No memory augmentations available',
|
|
129
|
+
stageResults: result.stageResults
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
// Use the first available memory augmentation
|
|
133
|
+
const memoryAugmentation = memoryAugmentations[0];
|
|
134
|
+
// Generate a key for the data
|
|
135
|
+
const dataKey = `data_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
|
136
|
+
// Store the data
|
|
137
|
+
const memoryResult = await memoryAugmentation.storeData(dataKey, {
|
|
138
|
+
rawData,
|
|
139
|
+
dataType,
|
|
140
|
+
nouns: senseResult.data.nouns,
|
|
141
|
+
verbs: senseResult.data.verbs,
|
|
142
|
+
timestamp: Date.now()
|
|
143
|
+
});
|
|
144
|
+
if (!memoryResult.success) {
|
|
145
|
+
return {
|
|
146
|
+
success: false,
|
|
147
|
+
data: null,
|
|
148
|
+
error: `Failed to store data: ${memoryResult.error}`,
|
|
149
|
+
stageResults: { ...result.stageResults, memory: memoryResult }
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
result.stageResults.memory = memoryResult;
|
|
153
|
+
// Step 3: Trigger ICognition augmentations to analyze the data
|
|
154
|
+
const cognitionResults = await augmentationPipeline.executeCognitionPipeline('reason', [`Analyze data with key ${dataKey}`, { dataKey }], { timeout: opts.timeout, stopOnError: opts.stopOnError });
|
|
155
|
+
// Get the first successful result
|
|
156
|
+
let cognitionResult = null;
|
|
157
|
+
for (const resultPromise of cognitionResults) {
|
|
158
|
+
const res = await resultPromise;
|
|
159
|
+
if (res.success) {
|
|
160
|
+
cognitionResult = res;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (cognitionResult) {
|
|
165
|
+
result.stageResults.cognition = cognitionResult;
|
|
166
|
+
}
|
|
167
|
+
// Step 4: Send notifications to IConduit augmentations
|
|
168
|
+
const conduitResults = await augmentationPipeline.executeConduitPipeline('writeData', [{ dataKey, nouns: senseResult.data.nouns, verbs: senseResult.data.verbs }], { timeout: opts.timeout, stopOnError: opts.stopOnError });
|
|
169
|
+
// Get the first successful result
|
|
170
|
+
let conduitResult = null;
|
|
171
|
+
for (const resultPromise of conduitResults) {
|
|
172
|
+
const res = await resultPromise;
|
|
173
|
+
if (res.success) {
|
|
174
|
+
conduitResult = res;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (conduitResult) {
|
|
179
|
+
result.stageResults.conduit = conduitResult;
|
|
180
|
+
}
|
|
181
|
+
// Step 5: Send notifications to IActivation augmentations
|
|
182
|
+
const activationResults = await augmentationPipeline.executeActivationPipeline('triggerAction', ['dataProcessed', { dataKey }], { timeout: opts.timeout, stopOnError: opts.stopOnError });
|
|
183
|
+
// Get the first successful result
|
|
184
|
+
let activationResult = null;
|
|
185
|
+
for (const resultPromise of activationResults) {
|
|
186
|
+
const res = await resultPromise;
|
|
187
|
+
if (res.success) {
|
|
188
|
+
activationResult = res;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (activationResult) {
|
|
193
|
+
result.stageResults.activation = activationResult;
|
|
194
|
+
}
|
|
195
|
+
// Step 6: Send notifications to IPerception augmentations
|
|
196
|
+
const perceptionResults = await augmentationPipeline.executePerceptionPipeline('interpret', [senseResult.data.nouns, senseResult.data.verbs, { dataKey }], { timeout: opts.timeout, stopOnError: opts.stopOnError });
|
|
197
|
+
// Get the first successful result
|
|
198
|
+
let perceptionResult = null;
|
|
199
|
+
for (const resultPromise of perceptionResults) {
|
|
200
|
+
const res = await resultPromise;
|
|
201
|
+
if (res.success) {
|
|
202
|
+
perceptionResult = res;
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (perceptionResult) {
|
|
207
|
+
result.stageResults.perception = perceptionResult;
|
|
208
|
+
result.data = perceptionResult.data;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
// If no perception result, use the cognition result as the final data
|
|
212
|
+
result.data = cognitionResult ? cognitionResult.data : { dataKey };
|
|
213
|
+
}
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
return {
|
|
218
|
+
success: false,
|
|
219
|
+
data: null,
|
|
220
|
+
error: `Pipeline execution failed: ${error}`,
|
|
221
|
+
stageResults: result.stageResults
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Process WebSocket data through the sequential pipeline
|
|
227
|
+
*
|
|
228
|
+
* @param connection The WebSocket connection
|
|
229
|
+
* @param dataType The type of data (e.g., 'text', 'image', 'audio')
|
|
230
|
+
* @param options Options for pipeline execution
|
|
231
|
+
* @returns A function to handle incoming WebSocket messages
|
|
232
|
+
*/
|
|
233
|
+
async createWebSocketHandler(connection, dataType, options = {}) {
|
|
234
|
+
// Ensure stream classes are initialized
|
|
235
|
+
await this.ensureStreamClassesInitialized();
|
|
236
|
+
// Create a transform stream for processing data
|
|
237
|
+
const transformStream = new TransformStream({
|
|
238
|
+
transform: async (chunk, controller) => {
|
|
239
|
+
try {
|
|
240
|
+
const data = typeof chunk === 'string' ? chunk : JSON.stringify(chunk);
|
|
241
|
+
const result = await this.processData(data, dataType, options);
|
|
242
|
+
if (result.success) {
|
|
243
|
+
controller.enqueue(result);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
console.warn('Pipeline processing failed:', result.error);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
console.error('Error in transform stream:', error);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
// Create a writable stream that will be the sink for our data
|
|
255
|
+
const writableStream = new WritableStream({
|
|
256
|
+
write: async (result) => {
|
|
257
|
+
// Handle the processed result if needed
|
|
258
|
+
if (connection.send && typeof connection.send === 'function') {
|
|
259
|
+
try {
|
|
260
|
+
// Only send back results if the connection supports it
|
|
261
|
+
await connection.send(JSON.stringify(result));
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
console.error('Error sending result back to WebSocket:', error);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
// Connect the transform stream to the writable stream
|
|
270
|
+
transformStream.readable.pipeTo(writableStream).catch((error) => {
|
|
271
|
+
console.error('Error in pipeline stream:', error);
|
|
272
|
+
});
|
|
273
|
+
// Return a function that writes to the transform stream
|
|
274
|
+
return (data) => {
|
|
275
|
+
try {
|
|
276
|
+
// Write to the transform stream's writable side
|
|
277
|
+
const writer = transformStream.writable.getWriter();
|
|
278
|
+
writer.write(data).catch((error) => {
|
|
279
|
+
console.error('Error writing to stream:', error);
|
|
280
|
+
}).finally(() => {
|
|
281
|
+
writer.releaseLock();
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
console.error('Error getting writer for transform stream:', error);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Set up a WebSocket connection to process data through the pipeline
|
|
291
|
+
*
|
|
292
|
+
* @param url The WebSocket URL to connect to
|
|
293
|
+
* @param dataType The type of data (e.g., 'text', 'image', 'audio')
|
|
294
|
+
* @param options Options for pipeline execution
|
|
295
|
+
* @returns A promise that resolves with the WebSocket connection and associated streams
|
|
296
|
+
*/
|
|
297
|
+
async setupWebSocketPipeline(url, dataType, options = {}) {
|
|
298
|
+
// Ensure stream classes are initialized
|
|
299
|
+
await this.ensureStreamClassesInitialized();
|
|
300
|
+
// Get WebSocket-supporting augmentations
|
|
301
|
+
const webSocketAugmentations = augmentationPipeline.getWebSocketAugmentations();
|
|
302
|
+
if (webSocketAugmentations.length === 0) {
|
|
303
|
+
throw new Error('No WebSocket-supporting augmentations available');
|
|
304
|
+
}
|
|
305
|
+
// Use the first available WebSocket augmentation
|
|
306
|
+
const webSocketAugmentation = webSocketAugmentations[0];
|
|
307
|
+
// Connect to the WebSocket
|
|
308
|
+
const connection = await webSocketAugmentation.connectWebSocket(url);
|
|
309
|
+
// Create a readable stream from the WebSocket messages
|
|
310
|
+
const readableStream = new ReadableStream({
|
|
311
|
+
start: (controller) => {
|
|
312
|
+
// Define a message handler that writes to the stream
|
|
313
|
+
const messageHandler = (event) => {
|
|
314
|
+
try {
|
|
315
|
+
const data = typeof event.data === 'string'
|
|
316
|
+
? event.data
|
|
317
|
+
: event.data instanceof Blob
|
|
318
|
+
? new Promise(resolve => {
|
|
319
|
+
const reader = new FileReader();
|
|
320
|
+
reader.onload = () => resolve(reader.result);
|
|
321
|
+
reader.readAsText(event.data);
|
|
322
|
+
})
|
|
323
|
+
: JSON.stringify(event.data);
|
|
324
|
+
// Handle both string data and promises
|
|
325
|
+
if (data instanceof Promise) {
|
|
326
|
+
data.then(resolvedData => {
|
|
327
|
+
controller.enqueue(resolvedData);
|
|
328
|
+
}).catch((error) => {
|
|
329
|
+
console.error('Error processing blob data:', error);
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
controller.enqueue(data);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
catch (error) {
|
|
337
|
+
console.error('Error processing WebSocket message:', error);
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
// Create a wrapper function that adapts the event-based handler to the data-based callback
|
|
341
|
+
const messageHandlerWrapper = (data) => {
|
|
342
|
+
messageHandler({ data });
|
|
343
|
+
};
|
|
344
|
+
// Store both handlers for later cleanup
|
|
345
|
+
connection._streamMessageHandler = messageHandler;
|
|
346
|
+
connection._messageHandlerWrapper = messageHandlerWrapper;
|
|
347
|
+
webSocketAugmentation.onWebSocketMessage(connection.connectionId, messageHandlerWrapper).catch((error) => {
|
|
348
|
+
console.error('Error registering WebSocket message handler:', error);
|
|
349
|
+
controller.error(error);
|
|
350
|
+
});
|
|
351
|
+
},
|
|
352
|
+
cancel: () => {
|
|
353
|
+
// Clean up the message handler when the stream is cancelled
|
|
354
|
+
if (connection._messageHandlerWrapper) {
|
|
355
|
+
webSocketAugmentation.offWebSocketMessage(connection.connectionId, connection._messageHandlerWrapper).catch((error) => {
|
|
356
|
+
console.error('Error removing WebSocket message handler:', error);
|
|
357
|
+
});
|
|
358
|
+
delete connection._streamMessageHandler;
|
|
359
|
+
delete connection._messageHandlerWrapper;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
// Create a handler for processing the data
|
|
364
|
+
const handlerPromise = this.createWebSocketHandler(connection, dataType, options);
|
|
365
|
+
// Create a writable stream that sends data to the WebSocket
|
|
366
|
+
const writableStream = new WritableStream({
|
|
367
|
+
write: async (chunk) => {
|
|
368
|
+
if (connection.send && typeof connection.send === 'function') {
|
|
369
|
+
try {
|
|
370
|
+
const data = typeof chunk === 'string' ? chunk : JSON.stringify(chunk);
|
|
371
|
+
await connection.send(data);
|
|
372
|
+
}
|
|
373
|
+
catch (error) {
|
|
374
|
+
console.error('Error sending data to WebSocket:', error);
|
|
375
|
+
throw error;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
throw new Error('WebSocket connection does not support sending data');
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
close: () => {
|
|
383
|
+
// Close the WebSocket connection when the stream is closed
|
|
384
|
+
if (connection.close && typeof connection.close === 'function') {
|
|
385
|
+
connection.close().catch((error) => {
|
|
386
|
+
console.error('Error closing WebSocket connection:', error);
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
// Pipe the readable stream through our processing pipeline
|
|
392
|
+
readableStream
|
|
393
|
+
.pipeThrough(new TransformStream({
|
|
394
|
+
transform: async (chunk, controller) => {
|
|
395
|
+
// Process each chunk through our handler
|
|
396
|
+
const handler = await handlerPromise;
|
|
397
|
+
handler(chunk);
|
|
398
|
+
// Pass through the original data
|
|
399
|
+
controller.enqueue(chunk);
|
|
400
|
+
}
|
|
401
|
+
}))
|
|
402
|
+
.pipeTo(new WritableStream({
|
|
403
|
+
write: () => { },
|
|
404
|
+
abort: (error) => {
|
|
405
|
+
console.error('Error in WebSocket pipeline:', error);
|
|
406
|
+
}
|
|
407
|
+
}));
|
|
408
|
+
// Attach the streams to the connection object for convenience
|
|
409
|
+
const enhancedConnection = connection;
|
|
410
|
+
enhancedConnection.readableStream = readableStream;
|
|
411
|
+
enhancedConnection.writableStream = writableStream;
|
|
412
|
+
return enhancedConnection;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
// Create and export a default instance of the sequential pipeline
|
|
416
|
+
export const sequentialPipeline = new SequentialPipeline();
|
|
417
|
+
//# sourceMappingURL=sequentialPipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sequentialPipeline.js","sourceRoot":"","sources":["../src/sequentialPipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,gBAAgB,EAWjB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,6EAA6E;AAC7E,6DAA6D;AAC7D,IAAI,eAAoB,EAAE,cAAmB,EAAE,cAAmB,CAAC;AAEnE,4CAA4C;AAC5C,MAAM,uBAAuB,GAAG,GAAG,EAA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+
/**
|
|
2
|
+
* CRITICAL: This file is imported for its side effects to patch the environment
|
|
3
|
+
* for TensorFlow.js before any other library code runs.
|
|
4
|
+
*
|
|
5
|
+
* It ensures that by the time TensorFlow.js is imported by any other
|
|
6
|
+
* module, the necessary compatibility fixes for the current Node.js
|
|
7
|
+
* environment are already in place.
|
|
8
|
+
*
|
|
9
|
+
* This file MUST be imported as the first import in unified.ts to prevent
|
|
10
|
+
* race conditions with TensorFlow.js initialization. Failure to do so will
|
|
11
|
+
* result in errors like "TextEncoder is not a constructor" when the package
|
|
12
|
+
* is used in Node.js environments.
|
|
13
|
+
*
|
|
14
|
+
* The package.json file marks this file as having side effects to prevent
|
|
15
|
+
* tree-shaking by bundlers, ensuring the patch is always applied.
|
|
16
|
+
*/
|
|
17
|
+
// Get the appropriate global object for the current environment
|
|
18
|
+
const globalObj = (() => {
|
|
19
|
+
if (typeof globalThis !== 'undefined')
|
|
20
|
+
return globalThis;
|
|
21
|
+
if (typeof global !== 'undefined')
|
|
22
|
+
return global;
|
|
23
|
+
if (typeof self !== 'undefined')
|
|
24
|
+
return self;
|
|
25
|
+
return null; // No global object available
|
|
26
|
+
})();
|
|
27
|
+
// Define TextEncoder and TextDecoder globally to make sure they're available
|
|
28
|
+
// Now works across all environments: Node.js, serverless, and other server environments
|
|
29
|
+
if (globalObj) {
|
|
30
|
+
if (!globalObj.TextEncoder) {
|
|
31
|
+
globalObj.TextEncoder = TextEncoder;
|
|
32
|
+
}
|
|
33
|
+
if (!globalObj.TextDecoder) {
|
|
34
|
+
globalObj.TextDecoder = TextDecoder;
|
|
35
|
+
}
|
|
36
|
+
// Create a special global constructor that TensorFlow can use safely
|
|
37
|
+
;
|
|
38
|
+
globalObj.__TextEncoder__ = TextEncoder;
|
|
39
|
+
globalObj.__TextDecoder__ = TextDecoder;
|
|
40
|
+
}
|
|
41
|
+
// Also import normally for ES modules environments
|
|
42
|
+
import { applyTensorFlowPatch } from './utils/textEncoding.js';
|
|
43
|
+
// Apply the TensorFlow.js platform patch
|
|
44
|
+
applyTensorFlowPatch();
|
|
45
|
+
console.log('Applied TensorFlow.js patch via ES modules in setup.ts');
|
|
46
|
+
//# sourceMappingURL=setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,gEAAgE;AAChE,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE;IACtB,IAAI,OAAO,UAAU,KAAK,WAAW;QAAE,OAAO,UAAU,CAAA;IACxD,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,MAAM,CAAA;IAChD,IAAI,OAAO,IAAI,KAAK,WAAW;QAAE,OAAO,IAAI,CAAA;IAC5C,OAAO,IAAI,CAAA,CAAC,6BAA6B;AAC3C,CAAC,CAAC,EAAE,CAAA;AAEJ,6EAA6E;AAC7E,wFAAwF;AACxF,IAAI,SAAS,EAAE,CAAC;IACd,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;QAC3B,SAAS,CAAC,WAAW,GAAG,WAAW,CAAA;IACrC,CAAC;IACD,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;QAC3B,SAAS,CAAC,WAAW,GAAG,WAAW,CAAA;IACrC,CAAC;IAED,qEAAqE;IACrE,CAAC;IAAC,SAAiB,CAAC,eAAe,GAAG,WAAW,CAChD;IAAC,SAAiB,CAAC,eAAe,GAAG,WAAW,CAAA;AACnD,CAAC;AAED,mDAAmD;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAE9D,yCAAyC;AACzC,oBAAoB,EAAE,CAAA;AACtB,OAAO,CAAC,GAAG,CAAC,wDAAwD,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unified.d.ts","sourceRoot":"","sources":["../src/unified.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH,OAAO,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ACE,WAAW,CAAC,SAAS;IACnB,CAAC,CAAC,SAAS;IACX,CAAC,CAAC,WAAW,CAAC,MAAM;QAClB,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,oBACR,cAAc,CACf,CAAA;AAED,qCAAqC;AACrC,cAAc,YAAY,CAAA;AAE1B,kEAAkE;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":""}
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Brainy Worker Script
|
|
2
|
+
// This script is used by the workerUtils.js file to execute functions in a separate thread
|
|
3
|
+
// Note: TensorFlow.js platform patch is applied in setup.ts
|
|
4
|
+
// Worker scripts should import setup.ts if they need TensorFlow.js functionality
|
|
5
|
+
// Log that the worker has started
|
|
6
|
+
console.log('Brainy Worker: Started');
|
|
7
|
+
// Define the message handler with proper TypeScript typing
|
|
8
|
+
self.onmessage = function (e) {
|
|
9
|
+
try {
|
|
10
|
+
console.log('Brainy Worker: Received message', e.data ? 'with data' : 'without data');
|
|
11
|
+
if (!e.data || !e.data.fnString) {
|
|
12
|
+
throw new Error('Invalid message: missing function string');
|
|
13
|
+
}
|
|
14
|
+
console.log('Brainy Worker: Creating function from string');
|
|
15
|
+
// Use Function constructor to create a function from the string
|
|
16
|
+
let fn;
|
|
17
|
+
try {
|
|
18
|
+
// First try with 'return' prefix
|
|
19
|
+
fn = new Function('return ' + e.data.fnString)();
|
|
20
|
+
}
|
|
21
|
+
catch (functionError) {
|
|
22
|
+
console.warn('Brainy Worker: Error creating function with return syntax, trying alternative approaches', functionError);
|
|
23
|
+
try {
|
|
24
|
+
// Try wrapping in parentheses for function expressions
|
|
25
|
+
fn = new Function('return (' + e.data.fnString + ')')();
|
|
26
|
+
}
|
|
27
|
+
catch (wrapError) {
|
|
28
|
+
console.warn('Brainy Worker: Error creating function with parentheses wrapping', wrapError);
|
|
29
|
+
try {
|
|
30
|
+
// Try direct approach for named functions
|
|
31
|
+
fn = new Function(e.data.fnString)();
|
|
32
|
+
}
|
|
33
|
+
catch (directError) {
|
|
34
|
+
console.error('Brainy Worker: All approaches to create function failed', directError);
|
|
35
|
+
throw new Error('Failed to create function from string: ' +
|
|
36
|
+
functionError.message);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
console.log('Brainy Worker: Executing function with args');
|
|
41
|
+
const result = fn(e.data.args);
|
|
42
|
+
console.log('Brainy Worker: Function executed successfully, posting result');
|
|
43
|
+
self.postMessage({ result: result });
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error('Brainy Worker: Error executing function', error);
|
|
47
|
+
self.postMessage({
|
|
48
|
+
error: error.message,
|
|
49
|
+
stack: error.stack
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA,uBAAuB;AACvB,2FAA2F;AAE3F,4DAA4D;AAC5D,iFAAiF;AAEjF,kCAAkC;AAClC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;AAErC,2DAA2D;AAC3D,IAAI,CAAC,SAAS,GAAG,UAAU,CAAe;IACxC,IAAI,CAAC;QACH,OAAO,CAAC,GAAG,CACT,iCAAiC,EACjC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,cAAc,CACtC,CAAA;QAED,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAA;QAC7D,CAAC;QAED,OAAO,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AAE,KAAK,CAAC,CAAA;QAC/D,IAAI,CAAC,WAAW,CAAC;YACf,KAAK,EAAE,KAAK,CAAC,OAAO;YACpB,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soulcraft/brainy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0",
|
|
4
4
|
"description": "A vector graph database using HNSW indexing with Origin Private File System storage",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -118,18 +118,14 @@
|
|
|
118
118
|
"url": "git+https://github.com/soulcraft-research/brainy.git"
|
|
119
119
|
},
|
|
120
120
|
"files": [
|
|
121
|
-
"dist
|
|
122
|
-
"dist
|
|
123
|
-
"dist/brainy.js",
|
|
124
|
-
"dist/brainy.min.js",
|
|
121
|
+
"dist/**/*.js",
|
|
122
|
+
"dist/**/*.js.map",
|
|
125
123
|
"dist/**/*.d.ts",
|
|
126
|
-
"dist
|
|
127
|
-
"dist/
|
|
128
|
-
"dist/
|
|
129
|
-
"dist/
|
|
130
|
-
"dist/
|
|
131
|
-
"dist/storage/",
|
|
132
|
-
"dist/utils/",
|
|
124
|
+
"dist/**/*.d.ts.map",
|
|
125
|
+
"!dist/framework.js",
|
|
126
|
+
"!dist/framework.js.map",
|
|
127
|
+
"!dist/framework.min.js",
|
|
128
|
+
"!dist/framework.min.js.map",
|
|
133
129
|
"LICENSE",
|
|
134
130
|
"README.md",
|
|
135
131
|
"brainy.png"
|