@soulcraft/brainy 0.63.0 → 1.0.0-rc.2
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 +296 -95
- package/bin/brainy.js +1121 -1409
- package/dist/brainyData.d.ts +185 -44
- package/dist/brainyData.js +727 -40
- package/dist/chat/BrainyChat.js +5 -11
- package/dist/cortex/neuralImport.js +1 -3
- package/dist/index.d.ts +3 -4
- package/dist/index.js +5 -6
- package/dist/pipeline.d.ts +15 -271
- package/dist/pipeline.js +25 -586
- package/package.json +3 -1
- package/dist/augmentations/cortexSense.d.ts +0 -196
- package/dist/augmentations/cortexSense.js +0 -747
- package/dist/chat/brainyChat.d.ts +0 -42
- package/dist/chat/brainyChat.js +0 -340
- package/dist/cortex/cliWrapper.d.ts +0 -32
- package/dist/cortex/cliWrapper.js +0 -209
- package/dist/cortex/cortex-legacy.d.ts +0 -269
- package/dist/cortex/cortex-legacy.js +0 -2523
- package/dist/cortex/cortex.d.ts +0 -264
- package/dist/cortex/cortex.js +0 -2463
- package/dist/cortex/serviceIntegration.d.ts +0 -156
- package/dist/cortex/serviceIntegration.js +0 -384
- package/dist/sequentialPipeline.d.ts +0 -113
- package/dist/sequentialPipeline.js +0 -417
- package/dist/utils/modelLoader.d.ts +0 -12
- package/dist/utils/modelLoader.js +0 -88
package/dist/pipeline.js
CHANGED
|
@@ -1,590 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Pipeline - Clean Re-export of Cortex
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* and the simplified execution API of the streamlined pipeline.
|
|
4
|
+
* After the Great Cleanup: Pipeline IS Cortex. No delegation, no complexity.
|
|
5
|
+
* ONE way to do everything.
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
stopOnError: false,
|
|
31
|
-
forceThreading: false,
|
|
32
|
-
disableThreading: false
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Pipeline class
|
|
36
|
-
*
|
|
37
|
-
* Manages multiple augmentations of each type and provides methods to execute them.
|
|
38
|
-
* Implements the IPipeline interface to avoid circular dependencies.
|
|
39
|
-
*/
|
|
40
|
-
export class Pipeline {
|
|
41
|
-
constructor() {
|
|
42
|
-
this.registry = {
|
|
43
|
-
sense: [],
|
|
44
|
-
conduit: [],
|
|
45
|
-
cognition: [],
|
|
46
|
-
memory: [],
|
|
47
|
-
perception: [],
|
|
48
|
-
dialog: [],
|
|
49
|
-
activation: [],
|
|
50
|
-
webSocket: []
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Register an augmentation with the pipeline
|
|
55
|
-
*
|
|
56
|
-
* @param augmentation The augmentation to register
|
|
57
|
-
* @returns The pipeline instance for chaining
|
|
58
|
-
*/
|
|
59
|
-
register(augmentation) {
|
|
60
|
-
let registered = false;
|
|
61
|
-
// Check for specific augmentation types
|
|
62
|
-
if (this.isAugmentationType(augmentation, 'processRawData', 'listenToFeed')) {
|
|
63
|
-
this.registry.sense.push(augmentation);
|
|
64
|
-
registered = true;
|
|
65
|
-
}
|
|
66
|
-
else if (this.isAugmentationType(augmentation, 'establishConnection', 'readData', 'writeData', 'monitorStream')) {
|
|
67
|
-
this.registry.conduit.push(augmentation);
|
|
68
|
-
registered = true;
|
|
69
|
-
}
|
|
70
|
-
else if (this.isAugmentationType(augmentation, 'reason', 'infer', 'executeLogic')) {
|
|
71
|
-
this.registry.cognition.push(augmentation);
|
|
72
|
-
registered = true;
|
|
73
|
-
}
|
|
74
|
-
else if (this.isAugmentationType(augmentation, 'storeData', 'retrieveData', 'updateData', 'deleteData', 'listDataKeys')) {
|
|
75
|
-
this.registry.memory.push(augmentation);
|
|
76
|
-
registered = true;
|
|
77
|
-
}
|
|
78
|
-
else if (this.isAugmentationType(augmentation, 'interpret', 'organize', 'generateVisualization')) {
|
|
79
|
-
this.registry.perception.push(augmentation);
|
|
80
|
-
registered = true;
|
|
81
|
-
}
|
|
82
|
-
else if (this.isAugmentationType(augmentation, 'processUserInput', 'generateResponse', 'manageContext')) {
|
|
83
|
-
this.registry.dialog.push(augmentation);
|
|
84
|
-
registered = true;
|
|
85
|
-
}
|
|
86
|
-
else if (this.isAugmentationType(augmentation, 'triggerAction', 'generateOutput', 'interactExternal')) {
|
|
87
|
-
this.registry.activation.push(augmentation);
|
|
88
|
-
registered = true;
|
|
89
|
-
}
|
|
90
|
-
// Check if the augmentation supports WebSocket
|
|
91
|
-
if (this.isAugmentationType(augmentation, 'connectWebSocket', 'sendWebSocketMessage', 'onWebSocketMessage', 'closeWebSocket')) {
|
|
92
|
-
this.registry.webSocket.push(augmentation);
|
|
93
|
-
registered = true;
|
|
94
|
-
}
|
|
95
|
-
// If the augmentation wasn't registered as any known type, throw an error
|
|
96
|
-
if (!registered) {
|
|
97
|
-
throw new Error(`Unknown augmentation type: ${augmentation.name}`);
|
|
98
|
-
}
|
|
99
|
-
return this;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Unregister an augmentation from the pipeline
|
|
103
|
-
*
|
|
104
|
-
* @param augmentationName The name of the augmentation to unregister
|
|
105
|
-
* @returns The pipeline instance for chaining
|
|
106
|
-
*/
|
|
107
|
-
unregister(augmentationName) {
|
|
108
|
-
let found = false;
|
|
109
|
-
// Remove from all registries
|
|
110
|
-
for (const type in this.registry) {
|
|
111
|
-
const typedRegistry = this.registry[type];
|
|
112
|
-
const index = typedRegistry.findIndex(aug => aug.name === augmentationName);
|
|
113
|
-
if (index !== -1) {
|
|
114
|
-
typedRegistry.splice(index, 1);
|
|
115
|
-
found = true;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return this;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Initialize all registered augmentations
|
|
122
|
-
*
|
|
123
|
-
* @returns A promise that resolves when all augmentations are initialized
|
|
124
|
-
*/
|
|
125
|
-
async initialize() {
|
|
126
|
-
const allAugmentations = this.getAllAugmentations();
|
|
127
|
-
await Promise.all(allAugmentations.map(augmentation => augmentation.initialize().catch(error => {
|
|
128
|
-
console.error(`Failed to initialize augmentation ${augmentation.name}:`, error);
|
|
129
|
-
})));
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Shut down all registered augmentations
|
|
133
|
-
*
|
|
134
|
-
* @returns A promise that resolves when all augmentations are shut down
|
|
135
|
-
*/
|
|
136
|
-
async shutDown() {
|
|
137
|
-
const allAugmentations = this.getAllAugmentations();
|
|
138
|
-
await Promise.all(allAugmentations.map(augmentation => augmentation.shutDown().catch(error => {
|
|
139
|
-
console.error(`Failed to shut down augmentation ${augmentation.name}:`, error);
|
|
140
|
-
})));
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Get all registered augmentations
|
|
144
|
-
*
|
|
145
|
-
* @returns An array of all registered augmentations
|
|
146
|
-
*/
|
|
147
|
-
getAllAugmentations() {
|
|
148
|
-
// Create a Set to avoid duplicates (an augmentation might be in multiple registries)
|
|
149
|
-
const allAugmentations = new Set([
|
|
150
|
-
...this.registry.sense,
|
|
151
|
-
...this.registry.conduit,
|
|
152
|
-
...this.registry.cognition,
|
|
153
|
-
...this.registry.memory,
|
|
154
|
-
...this.registry.perception,
|
|
155
|
-
...this.registry.dialog,
|
|
156
|
-
...this.registry.activation,
|
|
157
|
-
...this.registry.webSocket
|
|
158
|
-
]);
|
|
159
|
-
// Convert back to array
|
|
160
|
-
return Array.from(allAugmentations);
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Get all augmentations of a specific type
|
|
164
|
-
*
|
|
165
|
-
* @param type The type of augmentation to get
|
|
166
|
-
* @returns An array of all augmentations of the specified type
|
|
167
|
-
*/
|
|
168
|
-
getAugmentationsByType(type) {
|
|
169
|
-
switch (type) {
|
|
170
|
-
case AugmentationType.SENSE:
|
|
171
|
-
return [...this.registry.sense];
|
|
172
|
-
case AugmentationType.CONDUIT:
|
|
173
|
-
return [...this.registry.conduit];
|
|
174
|
-
case AugmentationType.COGNITION:
|
|
175
|
-
return [...this.registry.cognition];
|
|
176
|
-
case AugmentationType.MEMORY:
|
|
177
|
-
return [...this.registry.memory];
|
|
178
|
-
case AugmentationType.PERCEPTION:
|
|
179
|
-
return [...this.registry.perception];
|
|
180
|
-
case AugmentationType.DIALOG:
|
|
181
|
-
return [...this.registry.dialog];
|
|
182
|
-
case AugmentationType.ACTIVATION:
|
|
183
|
-
return [...this.registry.activation];
|
|
184
|
-
case AugmentationType.WEBSOCKET:
|
|
185
|
-
return [...this.registry.webSocket];
|
|
186
|
-
default:
|
|
187
|
-
return [];
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Get all available augmentation types
|
|
192
|
-
*
|
|
193
|
-
* @returns An array of all augmentation types that have at least one registered augmentation
|
|
194
|
-
*/
|
|
195
|
-
getAvailableAugmentationTypes() {
|
|
196
|
-
const availableTypes = [];
|
|
197
|
-
if (this.registry.sense.length > 0)
|
|
198
|
-
availableTypes.push(AugmentationType.SENSE);
|
|
199
|
-
if (this.registry.conduit.length > 0)
|
|
200
|
-
availableTypes.push(AugmentationType.CONDUIT);
|
|
201
|
-
if (this.registry.cognition.length > 0)
|
|
202
|
-
availableTypes.push(AugmentationType.COGNITION);
|
|
203
|
-
if (this.registry.memory.length > 0)
|
|
204
|
-
availableTypes.push(AugmentationType.MEMORY);
|
|
205
|
-
if (this.registry.perception.length > 0)
|
|
206
|
-
availableTypes.push(AugmentationType.PERCEPTION);
|
|
207
|
-
if (this.registry.dialog.length > 0)
|
|
208
|
-
availableTypes.push(AugmentationType.DIALOG);
|
|
209
|
-
if (this.registry.activation.length > 0)
|
|
210
|
-
availableTypes.push(AugmentationType.ACTIVATION);
|
|
211
|
-
if (this.registry.webSocket.length > 0)
|
|
212
|
-
availableTypes.push(AugmentationType.WEBSOCKET);
|
|
213
|
-
return availableTypes;
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Get all WebSocket-supporting augmentations
|
|
217
|
-
*
|
|
218
|
-
* @returns An array of all augmentations that support WebSocket connections
|
|
219
|
-
*/
|
|
220
|
-
getWebSocketAugmentations() {
|
|
221
|
-
return [...this.registry.webSocket];
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Check if an augmentation is of a specific type
|
|
225
|
-
*
|
|
226
|
-
* @param augmentation The augmentation to check
|
|
227
|
-
* @param methods The methods that should be present on the augmentation
|
|
228
|
-
* @returns True if the augmentation is of the specified type
|
|
229
|
-
*/
|
|
230
|
-
isAugmentationType(augmentation, ...methods) {
|
|
231
|
-
// First check that the augmentation has all the required base methods
|
|
232
|
-
const baseMethodsExist = [
|
|
233
|
-
'initialize',
|
|
234
|
-
'shutDown',
|
|
235
|
-
'getStatus'
|
|
236
|
-
].every(method => typeof augmentation[method] === 'function');
|
|
237
|
-
if (!baseMethodsExist) {
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
240
|
-
// Then check that it has all the specific methods for this type
|
|
241
|
-
return methods.every(method => typeof augmentation[method] === 'function');
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Determines if threading should be used based on options and environment
|
|
245
|
-
*
|
|
246
|
-
* @param options The pipeline options
|
|
247
|
-
* @returns True if threading should be used, false otherwise
|
|
248
|
-
*/
|
|
249
|
-
shouldUseThreading(options) {
|
|
250
|
-
// If threading is explicitly disabled, don't use it
|
|
251
|
-
if (options.disableThreading) {
|
|
252
|
-
return false;
|
|
253
|
-
}
|
|
254
|
-
// If threading is explicitly forced, use it if available
|
|
255
|
-
if (options.forceThreading) {
|
|
256
|
-
return isThreadingAvailable();
|
|
257
|
-
}
|
|
258
|
-
// If in THREADED mode, use threading if available
|
|
259
|
-
if (options.mode === ExecutionMode.THREADED) {
|
|
260
|
-
return isThreadingAvailable();
|
|
261
|
-
}
|
|
262
|
-
// Otherwise, don't use threading
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Executes a method on multiple augmentations using the specified execution mode
|
|
267
|
-
*
|
|
268
|
-
* @param augmentations The augmentations to execute the method on
|
|
269
|
-
* @param method The method to execute
|
|
270
|
-
* @param args The arguments to pass to the method
|
|
271
|
-
* @param options Options for the execution
|
|
272
|
-
* @returns A promise that resolves with the results
|
|
273
|
-
*/
|
|
274
|
-
async execute(augmentations, method, args = [], options = {}) {
|
|
275
|
-
const opts = { ...DEFAULT_PIPELINE_OPTIONS, ...options };
|
|
276
|
-
const enabledAugmentations = augmentations.filter(aug => aug.enabled !== false);
|
|
277
|
-
if (enabledAugmentations.length === 0) {
|
|
278
|
-
return { results: [], errors: [], successful: [] };
|
|
279
|
-
}
|
|
280
|
-
const result = {
|
|
281
|
-
results: [],
|
|
282
|
-
errors: [],
|
|
283
|
-
successful: []
|
|
284
|
-
};
|
|
285
|
-
// Create a function to execute with timeout
|
|
286
|
-
const executeWithTimeout = async (augmentation) => {
|
|
287
|
-
try {
|
|
288
|
-
// Create a timeout promise if a timeout is specified
|
|
289
|
-
if (opts.timeout) {
|
|
290
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
291
|
-
setTimeout(() => {
|
|
292
|
-
reject(new Error(`Timeout executing ${method} on ${augmentation.name}`));
|
|
293
|
-
}, opts.timeout);
|
|
294
|
-
});
|
|
295
|
-
// Check if threading should be used
|
|
296
|
-
const useThreading = this.shouldUseThreading(opts);
|
|
297
|
-
// Execute the method on the augmentation, using threading if appropriate
|
|
298
|
-
let methodPromise;
|
|
299
|
-
if (useThreading) {
|
|
300
|
-
// Execute in a separate thread
|
|
301
|
-
try {
|
|
302
|
-
// Create a function that can be serialized and executed in a worker
|
|
303
|
-
const workerFn = (...workerArgs) => {
|
|
304
|
-
// This function will be stringified and executed in the worker
|
|
305
|
-
// It needs to be self-contained
|
|
306
|
-
const augFn = augmentation[method];
|
|
307
|
-
return augFn.apply(augmentation, workerArgs);
|
|
308
|
-
};
|
|
309
|
-
methodPromise = executeInThread(workerFn.toString(), args);
|
|
310
|
-
}
|
|
311
|
-
catch (threadError) {
|
|
312
|
-
console.warn(`Failed to execute in thread, falling back to main thread: ${threadError}`);
|
|
313
|
-
// Fall back to executing in the main thread
|
|
314
|
-
methodPromise = Promise.resolve(augmentation[method](...args));
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
// Execute in the main thread
|
|
319
|
-
methodPromise = Promise.resolve(augmentation[method](...args));
|
|
320
|
-
}
|
|
321
|
-
// Race the method promise against the timeout promise
|
|
322
|
-
return await Promise.race([methodPromise, timeoutPromise]);
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
325
|
-
// No timeout, just execute the method
|
|
326
|
-
return await executeAugmentation(augmentation, method, ...args);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
catch (error) {
|
|
330
|
-
result.errors.push(error instanceof Error ? error : new Error(String(error)));
|
|
331
|
-
return {
|
|
332
|
-
success: false,
|
|
333
|
-
data: null,
|
|
334
|
-
error: error instanceof Error ? error.message : String(error)
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
// Execute based on the specified mode
|
|
339
|
-
switch (opts.mode) {
|
|
340
|
-
case ExecutionMode.PARALLEL:
|
|
341
|
-
case ExecutionMode.THREADED:
|
|
342
|
-
// Execute all augmentations in parallel
|
|
343
|
-
result.results = await Promise.all(enabledAugmentations.map((aug) => executeWithTimeout(aug)));
|
|
344
|
-
break;
|
|
345
|
-
case ExecutionMode.FIRST_SUCCESS:
|
|
346
|
-
// Execute augmentations sequentially until one succeeds
|
|
347
|
-
for (const augmentation of enabledAugmentations) {
|
|
348
|
-
const response = await executeWithTimeout(augmentation);
|
|
349
|
-
result.results.push(response);
|
|
350
|
-
if (response.success) {
|
|
351
|
-
break;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
break;
|
|
355
|
-
case ExecutionMode.FIRST_RESULT:
|
|
356
|
-
// Execute augmentations sequentially until one returns a non-null result
|
|
357
|
-
for (const augmentation of enabledAugmentations) {
|
|
358
|
-
const response = await executeWithTimeout(augmentation);
|
|
359
|
-
result.results.push(response);
|
|
360
|
-
if (response.success &&
|
|
361
|
-
response.data !== null &&
|
|
362
|
-
response.data !== undefined) {
|
|
363
|
-
break;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
break;
|
|
367
|
-
case ExecutionMode.SEQUENTIAL:
|
|
368
|
-
default:
|
|
369
|
-
// Execute augmentations sequentially
|
|
370
|
-
for (const augmentation of enabledAugmentations) {
|
|
371
|
-
const response = await executeWithTimeout(augmentation);
|
|
372
|
-
result.results.push(response);
|
|
373
|
-
// Check if we need to stop on error
|
|
374
|
-
if (opts.stopOnError && !response.success) {
|
|
375
|
-
break;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
break;
|
|
379
|
-
}
|
|
380
|
-
// Filter successful results
|
|
381
|
-
result.successful = result.results.filter((r) => r.success);
|
|
382
|
-
return result;
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Executes a method on augmentations of a specific type
|
|
386
|
-
*
|
|
387
|
-
* @param type The type of augmentations to execute the method on
|
|
388
|
-
* @param method The method to execute
|
|
389
|
-
* @param args The arguments to pass to the method
|
|
390
|
-
* @param options Options for the execution
|
|
391
|
-
* @returns A promise that resolves with the results
|
|
392
|
-
*/
|
|
393
|
-
async executeByType(type, method, args = [], options = {}) {
|
|
394
|
-
const augmentations = this.getAugmentationsByType(type);
|
|
395
|
-
return this.execute(augmentations, method, args, options);
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Executes a method on a single augmentation with automatic error handling
|
|
399
|
-
*
|
|
400
|
-
* @param augmentation The augmentation to execute the method on
|
|
401
|
-
* @param method The method to execute
|
|
402
|
-
* @param args The arguments to pass to the method
|
|
403
|
-
* @returns A promise that resolves with the result
|
|
404
|
-
*/
|
|
405
|
-
async executeSingle(augmentation, method, ...args) {
|
|
406
|
-
return executeAugmentation(augmentation, method, ...args);
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* Process static data through a pipeline of augmentations
|
|
410
|
-
*
|
|
411
|
-
* @param data The data to process
|
|
412
|
-
* @param pipeline An array of processing steps, each with an augmentation, method, and optional args transformer
|
|
413
|
-
* @param options Options for the execution
|
|
414
|
-
* @returns A promise that resolves with the final result
|
|
415
|
-
*/
|
|
416
|
-
async processStaticData(data, pipeline, options = {}) {
|
|
417
|
-
let currentData = data;
|
|
418
|
-
let prevResult = undefined;
|
|
419
|
-
for (const step of pipeline) {
|
|
420
|
-
// Transform args if a transformer is provided, otherwise use the current data as the only arg
|
|
421
|
-
const args = step.transformArgs
|
|
422
|
-
? step.transformArgs(currentData, prevResult)
|
|
423
|
-
: [currentData];
|
|
424
|
-
// Execute the method
|
|
425
|
-
const result = await this.executeSingle(step.augmentation, step.method, ...args);
|
|
426
|
-
// If the step failed, return the error
|
|
427
|
-
if (!result.success) {
|
|
428
|
-
return result;
|
|
429
|
-
}
|
|
430
|
-
// Update the current data for the next step
|
|
431
|
-
currentData = result.data;
|
|
432
|
-
prevResult = result;
|
|
433
|
-
}
|
|
434
|
-
// Return the final result
|
|
435
|
-
return prevResult;
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Process streaming data through a pipeline of augmentations
|
|
439
|
-
*
|
|
440
|
-
* @param source The source augmentation that provides the data stream
|
|
441
|
-
* @param sourceMethod The method on the source augmentation that provides the data stream
|
|
442
|
-
* @param sourceArgs The arguments to pass to the source method
|
|
443
|
-
* @param pipeline An array of processing steps, each with an augmentation, method, and optional args transformer
|
|
444
|
-
* @param callback Function to call with the results of processing each data item
|
|
445
|
-
* @param options Options for the execution
|
|
446
|
-
* @returns A promise that resolves when the pipeline is set up
|
|
447
|
-
*/
|
|
448
|
-
async processStreamingData(source, sourceMethod, sourceArgs, pipeline, callback, options = {}) {
|
|
449
|
-
// Create a chain of processors
|
|
450
|
-
const processData = async (data) => {
|
|
451
|
-
let currentData = data;
|
|
452
|
-
let prevResult = undefined;
|
|
453
|
-
for (const step of pipeline) {
|
|
454
|
-
// Transform args if a transformer is provided, otherwise use the current data as the only arg
|
|
455
|
-
const args = step.transformArgs
|
|
456
|
-
? step.transformArgs(currentData, prevResult)
|
|
457
|
-
: [currentData];
|
|
458
|
-
// Execute the method
|
|
459
|
-
const result = await this.executeSingle(step.augmentation, step.method, ...args);
|
|
460
|
-
// If the step failed, return the error
|
|
461
|
-
if (!result.success) {
|
|
462
|
-
callback(result);
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
// Update the current data for the next step
|
|
466
|
-
currentData = result.data;
|
|
467
|
-
prevResult = result;
|
|
468
|
-
}
|
|
469
|
-
// Call the callback with the final result
|
|
470
|
-
callback(prevResult);
|
|
471
|
-
};
|
|
472
|
-
// The last argument to the source method should be a callback that receives the data
|
|
473
|
-
const dataCallback = (data) => {
|
|
474
|
-
processData(data).catch((error) => {
|
|
475
|
-
console.error('Error processing streaming data:', error);
|
|
476
|
-
callback({
|
|
477
|
-
success: false,
|
|
478
|
-
data: null,
|
|
479
|
-
error: error instanceof Error ? error.message : String(error)
|
|
480
|
-
});
|
|
481
|
-
});
|
|
482
|
-
};
|
|
483
|
-
// Execute the source method with the provided args and the data callback
|
|
484
|
-
await this.executeSingle(source, sourceMethod, ...sourceArgs, dataCallback);
|
|
485
|
-
}
|
|
486
|
-
/**
|
|
487
|
-
* Create a reusable pipeline for processing data
|
|
488
|
-
*
|
|
489
|
-
* @param pipeline An array of processing steps
|
|
490
|
-
* @param options Options for the execution
|
|
491
|
-
* @returns A function that processes data through the pipeline
|
|
492
|
-
*/
|
|
493
|
-
createPipeline(pipeline, options = {}) {
|
|
494
|
-
return (data) => this.processStaticData(data, pipeline, options);
|
|
495
|
-
}
|
|
496
|
-
/**
|
|
497
|
-
* Create a reusable streaming pipeline
|
|
498
|
-
*
|
|
499
|
-
* @param source The source augmentation
|
|
500
|
-
* @param sourceMethod The method on the source augmentation
|
|
501
|
-
* @param pipeline An array of processing steps
|
|
502
|
-
* @param options Options for the execution
|
|
503
|
-
* @returns A function that sets up the streaming pipeline
|
|
504
|
-
*/
|
|
505
|
-
createStreamingPipeline(source, sourceMethod, pipeline, options = {}) {
|
|
506
|
-
return (sourceArgs, callback) => this.processStreamingData(source, sourceMethod, sourceArgs, pipeline, callback, options);
|
|
507
|
-
}
|
|
508
|
-
// Legacy methods for backward compatibility
|
|
509
|
-
/**
|
|
510
|
-
* Execute a sense pipeline (legacy method)
|
|
511
|
-
*/
|
|
512
|
-
async executeSensePipeline(method, args, options = {}) {
|
|
513
|
-
const result = await this.executeByType(AugmentationType.SENSE, method, args, options);
|
|
514
|
-
return result.results.map(r => Promise.resolve(r));
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Execute a conduit pipeline (legacy method)
|
|
518
|
-
*/
|
|
519
|
-
async executeConduitPipeline(method, args, options = {}) {
|
|
520
|
-
const result = await this.executeByType(AugmentationType.CONDUIT, method, args, options);
|
|
521
|
-
return result.results.map(r => Promise.resolve(r));
|
|
522
|
-
}
|
|
523
|
-
/**
|
|
524
|
-
* Execute a cognition pipeline (legacy method)
|
|
525
|
-
*/
|
|
526
|
-
async executeCognitionPipeline(method, args, options = {}) {
|
|
527
|
-
const result = await this.executeByType(AugmentationType.COGNITION, method, args, options);
|
|
528
|
-
return result.results.map(r => Promise.resolve(r));
|
|
529
|
-
}
|
|
530
|
-
/**
|
|
531
|
-
* Execute a memory pipeline (legacy method)
|
|
532
|
-
*/
|
|
533
|
-
async executeMemoryPipeline(method, args, options = {}) {
|
|
534
|
-
const result = await this.executeByType(AugmentationType.MEMORY, method, args, options);
|
|
535
|
-
return result.results.map(r => Promise.resolve(r));
|
|
536
|
-
}
|
|
537
|
-
/**
|
|
538
|
-
* Execute a perception pipeline (legacy method)
|
|
539
|
-
*/
|
|
540
|
-
async executePerceptionPipeline(method, args, options = {}) {
|
|
541
|
-
const result = await this.executeByType(AugmentationType.PERCEPTION, method, args, options);
|
|
542
|
-
return result.results.map(r => Promise.resolve(r));
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* Execute a dialog pipeline (legacy method)
|
|
546
|
-
*/
|
|
547
|
-
async executeDialogPipeline(method, args, options = {}) {
|
|
548
|
-
const result = await this.executeByType(AugmentationType.DIALOG, method, args, options);
|
|
549
|
-
return result.results.map(r => Promise.resolve(r));
|
|
550
|
-
}
|
|
551
|
-
/**
|
|
552
|
-
* Execute an activation pipeline (legacy method)
|
|
553
|
-
*/
|
|
554
|
-
async executeActivationPipeline(method, args, options = {}) {
|
|
555
|
-
const result = await this.executeByType(AugmentationType.ACTIVATION, method, args, options);
|
|
556
|
-
return result.results.map(r => Promise.resolve(r));
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
// Create and export a default instance of the pipeline
|
|
560
|
-
export const pipeline = new Pipeline();
|
|
561
|
-
// Set the default pipeline instance for the augmentation registry
|
|
562
|
-
// This breaks the circular dependency between pipeline.ts and augmentationRegistry.ts
|
|
563
|
-
setDefaultPipeline(pipeline);
|
|
564
|
-
// Re-export the legacy pipeline for backward compatibility
|
|
565
|
-
export const augmentationPipeline = pipeline;
|
|
566
|
-
// Re-export the streamlined execution functions for backward compatibility
|
|
567
|
-
export const executeStreamlined = (augmentations, method, args = [], options = {}) => {
|
|
568
|
-
return pipeline.execute(augmentations, method, args, options);
|
|
569
|
-
};
|
|
570
|
-
export const executeByType = (type, method, args = [], options = {}) => {
|
|
571
|
-
return pipeline.executeByType(type, method, args, options);
|
|
572
|
-
};
|
|
573
|
-
export const executeSingle = (augmentation, method, ...args) => {
|
|
574
|
-
return pipeline.executeSingle(augmentation, method, ...args);
|
|
575
|
-
};
|
|
576
|
-
export const processStaticData = (data, pipelineSteps, options = {}) => {
|
|
577
|
-
return pipeline.processStaticData(data, pipelineSteps, options);
|
|
578
|
-
};
|
|
579
|
-
export const processStreamingData = (source, sourceMethod, sourceArgs, pipelineSteps, callback, options = {}) => {
|
|
580
|
-
return pipeline.processStreamingData(source, sourceMethod, sourceArgs, pipelineSteps, callback, options);
|
|
581
|
-
};
|
|
582
|
-
export const createPipeline = (pipelineSteps, options = {}) => {
|
|
583
|
-
return pipeline.createPipeline(pipelineSteps, options);
|
|
584
|
-
};
|
|
585
|
-
export const createStreamingPipeline = (source, sourceMethod, pipelineSteps, options = {}) => {
|
|
586
|
-
return pipeline.createStreamingPipeline(source, sourceMethod, pipelineSteps, options);
|
|
587
|
-
};
|
|
588
|
-
// For backward compatibility with StreamlinedExecutionMode
|
|
589
|
-
export const StreamlinedExecutionMode = ExecutionMode;
|
|
7
|
+
// Export the ONE consolidated Cortex class as Pipeline for those who prefer the name
|
|
8
|
+
export { Cortex as Pipeline, cortex as pipeline, ExecutionMode } from './augmentationPipeline.js';
|
|
9
|
+
// Re-export for backward compatibility in imports
|
|
10
|
+
export { cortex as augmentationPipeline, Cortex } from './augmentationPipeline.js';
|
|
11
|
+
// Simple factory functions
|
|
12
|
+
export const createPipeline = async () => {
|
|
13
|
+
const { Cortex } = await import('./augmentationPipeline.js');
|
|
14
|
+
return new Cortex();
|
|
15
|
+
};
|
|
16
|
+
export const createStreamingPipeline = async () => {
|
|
17
|
+
const { Cortex } = await import('./augmentationPipeline.js');
|
|
18
|
+
return new Cortex();
|
|
19
|
+
};
|
|
20
|
+
// Execution mode alias
|
|
21
|
+
export var StreamlinedExecutionMode;
|
|
22
|
+
(function (StreamlinedExecutionMode) {
|
|
23
|
+
StreamlinedExecutionMode["SEQUENTIAL"] = "sequential";
|
|
24
|
+
StreamlinedExecutionMode["PARALLEL"] = "parallel";
|
|
25
|
+
StreamlinedExecutionMode["FIRST_SUCCESS"] = "firstSuccess";
|
|
26
|
+
StreamlinedExecutionMode["FIRST_RESULT"] = "firstResult";
|
|
27
|
+
StreamlinedExecutionMode["THREADED"] = "threaded";
|
|
28
|
+
})(StreamlinedExecutionMode || (StreamlinedExecutionMode = {}));
|
|
590
29
|
//# sourceMappingURL=pipeline.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soulcraft/brainy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-rc.2",
|
|
4
4
|
"description": "Multi-Dimensional AI Database - Vector similarity, graph relationships, metadata facets with HNSW indexing and OPFS storage",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -120,6 +120,8 @@
|
|
|
120
120
|
"test:extraction": "node tests/auto-extraction.test.js",
|
|
121
121
|
"extract-models": "node scripts/extract-models.js",
|
|
122
122
|
"test:comprehensive": "npm run test:error-handling && npm run test:edge-cases && npm run test:storage && npm run test:environments && npm run test:specialized",
|
|
123
|
+
"test:release": "npm run build && vitest run tests/release-validation.test.ts tests/regression.test.ts tests/unified-api.test.ts tests/core.test.ts --reporter=verbose",
|
|
124
|
+
"test:1.0": "vitest run tests/unified-api.test.ts tests/cli.test.ts --reporter=verbose",
|
|
123
125
|
"_generate-pdf": "node dev/scripts/generate-architecture-pdf.js",
|
|
124
126
|
"_release": "standard-version",
|
|
125
127
|
"_release:patch": "standard-version --release-as patch",
|