@soulcraft/brainy 0.43.0 → 0.45.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/utils/robustModelLoader.js +60 -25
- package/dist/utils/robustModelLoader.js.map +1 -1
- 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,472 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Augmentation Event Pipeline
|
|
3
|
+
*
|
|
4
|
+
* This module provides a pipeline for managing and executing multiple augmentations
|
|
5
|
+
* of each type. It allows registering multiple augmentations and executing them
|
|
6
|
+
* in sequence or in parallel.
|
|
7
|
+
*/
|
|
8
|
+
import { AugmentationType } from './types/augmentations.js';
|
|
9
|
+
import { isThreadingAvailable } from './utils/environment.js';
|
|
10
|
+
import { executeInThread } from './utils/workerUtils.js';
|
|
11
|
+
/**
|
|
12
|
+
* Execution mode for the pipeline
|
|
13
|
+
*/
|
|
14
|
+
export var ExecutionMode;
|
|
15
|
+
(function (ExecutionMode) {
|
|
16
|
+
ExecutionMode["SEQUENTIAL"] = "sequential";
|
|
17
|
+
ExecutionMode["PARALLEL"] = "parallel";
|
|
18
|
+
ExecutionMode["FIRST_SUCCESS"] = "firstSuccess";
|
|
19
|
+
ExecutionMode["FIRST_RESULT"] = "firstResult";
|
|
20
|
+
ExecutionMode["THREADED"] = "threaded"; // Execute in separate threads when available
|
|
21
|
+
})(ExecutionMode || (ExecutionMode = {}));
|
|
22
|
+
/**
|
|
23
|
+
* Default pipeline options
|
|
24
|
+
*/
|
|
25
|
+
const DEFAULT_PIPELINE_OPTIONS = {
|
|
26
|
+
mode: ExecutionMode.SEQUENTIAL,
|
|
27
|
+
timeout: 30000,
|
|
28
|
+
stopOnError: false,
|
|
29
|
+
forceThreading: false,
|
|
30
|
+
disableThreading: false
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* AugmentationPipeline class
|
|
34
|
+
*
|
|
35
|
+
* Manages multiple augmentations of each type and provides methods to execute them.
|
|
36
|
+
*/
|
|
37
|
+
export class AugmentationPipeline {
|
|
38
|
+
constructor() {
|
|
39
|
+
this.registry = {
|
|
40
|
+
sense: [],
|
|
41
|
+
conduit: [],
|
|
42
|
+
cognition: [],
|
|
43
|
+
memory: [],
|
|
44
|
+
perception: [],
|
|
45
|
+
dialog: [],
|
|
46
|
+
activation: [],
|
|
47
|
+
webSocket: []
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Register an augmentation with the pipeline
|
|
52
|
+
*
|
|
53
|
+
* @param augmentation The augmentation to register
|
|
54
|
+
* @returns The pipeline instance for chaining
|
|
55
|
+
*/
|
|
56
|
+
register(augmentation) {
|
|
57
|
+
let registered = false;
|
|
58
|
+
// Check for specific augmentation types
|
|
59
|
+
if (this.isAugmentationType(augmentation, 'processRawData', 'listenToFeed')) {
|
|
60
|
+
this.registry.sense.push(augmentation);
|
|
61
|
+
registered = true;
|
|
62
|
+
}
|
|
63
|
+
else if (this.isAugmentationType(augmentation, 'establishConnection', 'readData', 'writeData', 'monitorStream')) {
|
|
64
|
+
this.registry.conduit.push(augmentation);
|
|
65
|
+
registered = true;
|
|
66
|
+
}
|
|
67
|
+
else if (this.isAugmentationType(augmentation, 'reason', 'infer', 'executeLogic')) {
|
|
68
|
+
this.registry.cognition.push(augmentation);
|
|
69
|
+
registered = true;
|
|
70
|
+
}
|
|
71
|
+
else if (this.isAugmentationType(augmentation, 'storeData', 'retrieveData', 'updateData', 'deleteData', 'listDataKeys')) {
|
|
72
|
+
this.registry.memory.push(augmentation);
|
|
73
|
+
registered = true;
|
|
74
|
+
}
|
|
75
|
+
else if (this.isAugmentationType(augmentation, 'interpret', 'organize', 'generateVisualization')) {
|
|
76
|
+
this.registry.perception.push(augmentation);
|
|
77
|
+
registered = true;
|
|
78
|
+
}
|
|
79
|
+
else if (this.isAugmentationType(augmentation, 'processUserInput', 'generateResponse', 'manageContext')) {
|
|
80
|
+
this.registry.dialog.push(augmentation);
|
|
81
|
+
registered = true;
|
|
82
|
+
}
|
|
83
|
+
else if (this.isAugmentationType(augmentation, 'triggerAction', 'generateOutput', 'interactExternal')) {
|
|
84
|
+
this.registry.activation.push(augmentation);
|
|
85
|
+
registered = true;
|
|
86
|
+
}
|
|
87
|
+
// Check if the augmentation supports WebSocket
|
|
88
|
+
if (this.isAugmentationType(augmentation, 'connectWebSocket', 'sendWebSocketMessage', 'onWebSocketMessage', 'closeWebSocket')) {
|
|
89
|
+
this.registry.webSocket.push(augmentation);
|
|
90
|
+
registered = true;
|
|
91
|
+
}
|
|
92
|
+
// If the augmentation wasn't registered as any known type, throw an error
|
|
93
|
+
if (!registered) {
|
|
94
|
+
throw new Error(`Unknown augmentation type: ${augmentation.name}`);
|
|
95
|
+
}
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Unregister an augmentation from the pipeline
|
|
100
|
+
*
|
|
101
|
+
* @param augmentationName The name of the augmentation to unregister
|
|
102
|
+
* @returns The pipeline instance for chaining
|
|
103
|
+
*/
|
|
104
|
+
unregister(augmentationName) {
|
|
105
|
+
let found = false;
|
|
106
|
+
// Remove from all registries
|
|
107
|
+
for (const type in this.registry) {
|
|
108
|
+
const typedRegistry = this.registry[type];
|
|
109
|
+
const index = typedRegistry.findIndex((aug) => aug.name === augmentationName);
|
|
110
|
+
if (index !== -1) {
|
|
111
|
+
typedRegistry.splice(index, 1);
|
|
112
|
+
found = true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Initialize all registered augmentations
|
|
119
|
+
*
|
|
120
|
+
* @returns A promise that resolves when all augmentations are initialized
|
|
121
|
+
*/
|
|
122
|
+
async initialize() {
|
|
123
|
+
const allAugmentations = this.getAllAugmentations();
|
|
124
|
+
await Promise.all(allAugmentations.map((augmentation) => augmentation.initialize().catch((error) => {
|
|
125
|
+
console.error(`Failed to initialize augmentation ${augmentation.name}:`, error);
|
|
126
|
+
})));
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Shut down all registered augmentations
|
|
130
|
+
*
|
|
131
|
+
* @returns A promise that resolves when all augmentations are shut down
|
|
132
|
+
*/
|
|
133
|
+
async shutDown() {
|
|
134
|
+
const allAugmentations = this.getAllAugmentations();
|
|
135
|
+
await Promise.all(allAugmentations.map((augmentation) => augmentation.shutDown().catch((error) => {
|
|
136
|
+
console.error(`Failed to shut down augmentation ${augmentation.name}:`, error);
|
|
137
|
+
})));
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Execute a sense pipeline
|
|
141
|
+
*
|
|
142
|
+
* @param method The method to execute on each sense augmentation
|
|
143
|
+
* @param args The arguments to pass to the method
|
|
144
|
+
* @param options The pipeline execution options
|
|
145
|
+
* @returns A promise that resolves with the results from all augmentations
|
|
146
|
+
*/
|
|
147
|
+
async executeSensePipeline(method, args, options = {}) {
|
|
148
|
+
const opts = { ...DEFAULT_PIPELINE_OPTIONS, ...options };
|
|
149
|
+
return this.executeTypedPipeline(this.registry.sense, method, args, opts);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Execute a conduit pipeline
|
|
153
|
+
*
|
|
154
|
+
* @param method The method to execute on each conduit augmentation
|
|
155
|
+
* @param args The arguments to pass to the method
|
|
156
|
+
* @param options The pipeline execution options
|
|
157
|
+
* @returns A promise that resolves with the results from all augmentations
|
|
158
|
+
*/
|
|
159
|
+
async executeConduitPipeline(method, args, options = {}) {
|
|
160
|
+
const opts = { ...DEFAULT_PIPELINE_OPTIONS, ...options };
|
|
161
|
+
return this.executeTypedPipeline(this.registry.conduit, method, args, opts);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Execute a cognition pipeline
|
|
165
|
+
*
|
|
166
|
+
* @param method The method to execute on each cognition augmentation
|
|
167
|
+
* @param args The arguments to pass to the method
|
|
168
|
+
* @param options The pipeline execution options
|
|
169
|
+
* @returns A promise that resolves with the results from all augmentations
|
|
170
|
+
*/
|
|
171
|
+
async executeCognitionPipeline(method, args, options = {}) {
|
|
172
|
+
const opts = { ...DEFAULT_PIPELINE_OPTIONS, ...options };
|
|
173
|
+
return this.executeTypedPipeline(this.registry.cognition, method, args, opts);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Execute a memory pipeline
|
|
177
|
+
*
|
|
178
|
+
* @param method The method to execute on each memory augmentation
|
|
179
|
+
* @param args The arguments to pass to the method
|
|
180
|
+
* @param options The pipeline execution options
|
|
181
|
+
* @returns A promise that resolves with the results from all augmentations
|
|
182
|
+
*/
|
|
183
|
+
async executeMemoryPipeline(method, args, options = {}) {
|
|
184
|
+
const opts = { ...DEFAULT_PIPELINE_OPTIONS, ...options };
|
|
185
|
+
return this.executeTypedPipeline(this.registry.memory, method, args, opts);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Execute a perception pipeline
|
|
189
|
+
*
|
|
190
|
+
* @param method The method to execute on each perception augmentation
|
|
191
|
+
* @param args The arguments to pass to the method
|
|
192
|
+
* @param options The pipeline execution options
|
|
193
|
+
* @returns A promise that resolves with the results from all augmentations
|
|
194
|
+
*/
|
|
195
|
+
async executePerceptionPipeline(method, args, options = {}) {
|
|
196
|
+
const opts = { ...DEFAULT_PIPELINE_OPTIONS, ...options };
|
|
197
|
+
return this.executeTypedPipeline(this.registry.perception, method, args, opts);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Execute a dialog pipeline
|
|
201
|
+
*
|
|
202
|
+
* @param method The method to execute on each dialog augmentation
|
|
203
|
+
* @param args The arguments to pass to the method
|
|
204
|
+
* @param options The pipeline execution options
|
|
205
|
+
* @returns A promise that resolves with the results from all augmentations
|
|
206
|
+
*/
|
|
207
|
+
async executeDialogPipeline(method, args, options = {}) {
|
|
208
|
+
const opts = { ...DEFAULT_PIPELINE_OPTIONS, ...options };
|
|
209
|
+
return this.executeTypedPipeline(this.registry.dialog, method, args, opts);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Execute an activation pipeline
|
|
213
|
+
*
|
|
214
|
+
* @param method The method to execute on each activation augmentation
|
|
215
|
+
* @param args The arguments to pass to the method
|
|
216
|
+
* @param options The pipeline execution options
|
|
217
|
+
* @returns A promise that resolves with the results from all augmentations
|
|
218
|
+
*/
|
|
219
|
+
async executeActivationPipeline(method, args, options = {}) {
|
|
220
|
+
const opts = { ...DEFAULT_PIPELINE_OPTIONS, ...options };
|
|
221
|
+
return this.executeTypedPipeline(this.registry.activation, method, args, opts);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Get all registered augmentations
|
|
225
|
+
*
|
|
226
|
+
* @returns An array of all registered augmentations
|
|
227
|
+
*/
|
|
228
|
+
getAllAugmentations() {
|
|
229
|
+
// Create a Set to avoid duplicates (an augmentation might be in multiple registries)
|
|
230
|
+
const allAugmentations = new Set([
|
|
231
|
+
...this.registry.sense,
|
|
232
|
+
...this.registry.conduit,
|
|
233
|
+
...this.registry.cognition,
|
|
234
|
+
...this.registry.memory,
|
|
235
|
+
...this.registry.perception,
|
|
236
|
+
...this.registry.dialog,
|
|
237
|
+
...this.registry.activation,
|
|
238
|
+
...this.registry.webSocket
|
|
239
|
+
]);
|
|
240
|
+
// Convert back to array
|
|
241
|
+
return Array.from(allAugmentations);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Get all augmentations of a specific type
|
|
245
|
+
*
|
|
246
|
+
* @param type The type of augmentation to get
|
|
247
|
+
* @returns An array of all augmentations of the specified type
|
|
248
|
+
*/
|
|
249
|
+
getAugmentationsByType(type) {
|
|
250
|
+
switch (type) {
|
|
251
|
+
case AugmentationType.SENSE:
|
|
252
|
+
return [...this.registry.sense];
|
|
253
|
+
case AugmentationType.CONDUIT:
|
|
254
|
+
return [...this.registry.conduit];
|
|
255
|
+
case AugmentationType.COGNITION:
|
|
256
|
+
return [...this.registry.cognition];
|
|
257
|
+
case AugmentationType.MEMORY:
|
|
258
|
+
return [...this.registry.memory];
|
|
259
|
+
case AugmentationType.PERCEPTION:
|
|
260
|
+
return [...this.registry.perception];
|
|
261
|
+
case AugmentationType.DIALOG:
|
|
262
|
+
return [...this.registry.dialog];
|
|
263
|
+
case AugmentationType.ACTIVATION:
|
|
264
|
+
return [...this.registry.activation];
|
|
265
|
+
case AugmentationType.WEBSOCKET:
|
|
266
|
+
return [...this.registry.webSocket];
|
|
267
|
+
default:
|
|
268
|
+
return [];
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Get all available augmentation types
|
|
273
|
+
*
|
|
274
|
+
* @returns An array of all augmentation types that have at least one registered augmentation
|
|
275
|
+
*/
|
|
276
|
+
getAvailableAugmentationTypes() {
|
|
277
|
+
const availableTypes = [];
|
|
278
|
+
if (this.registry.sense.length > 0)
|
|
279
|
+
availableTypes.push(AugmentationType.SENSE);
|
|
280
|
+
if (this.registry.conduit.length > 0)
|
|
281
|
+
availableTypes.push(AugmentationType.CONDUIT);
|
|
282
|
+
if (this.registry.cognition.length > 0)
|
|
283
|
+
availableTypes.push(AugmentationType.COGNITION);
|
|
284
|
+
if (this.registry.memory.length > 0)
|
|
285
|
+
availableTypes.push(AugmentationType.MEMORY);
|
|
286
|
+
if (this.registry.perception.length > 0)
|
|
287
|
+
availableTypes.push(AugmentationType.PERCEPTION);
|
|
288
|
+
if (this.registry.dialog.length > 0)
|
|
289
|
+
availableTypes.push(AugmentationType.DIALOG);
|
|
290
|
+
if (this.registry.activation.length > 0)
|
|
291
|
+
availableTypes.push(AugmentationType.ACTIVATION);
|
|
292
|
+
if (this.registry.webSocket.length > 0)
|
|
293
|
+
availableTypes.push(AugmentationType.WEBSOCKET);
|
|
294
|
+
return availableTypes;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Get all WebSocket-supporting augmentations
|
|
298
|
+
*
|
|
299
|
+
* @returns An array of all augmentations that support WebSocket connections
|
|
300
|
+
*/
|
|
301
|
+
getWebSocketAugmentations() {
|
|
302
|
+
return [...this.registry.webSocket];
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Check if an augmentation is of a specific type
|
|
306
|
+
*
|
|
307
|
+
* @param augmentation The augmentation to check
|
|
308
|
+
* @param methods The methods that should be present on the augmentation
|
|
309
|
+
* @returns True if the augmentation is of the specified type
|
|
310
|
+
*/
|
|
311
|
+
isAugmentationType(augmentation, ...methods) {
|
|
312
|
+
// First check that the augmentation has all the required base methods
|
|
313
|
+
const baseMethodsExist = ['initialize', 'shutDown', 'getStatus'].every((method) => typeof augmentation[method] === 'function');
|
|
314
|
+
if (!baseMethodsExist) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
// Then check that it has all the specific methods for this type
|
|
318
|
+
return methods.every((method) => typeof augmentation[method] === 'function');
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Determines if threading should be used based on options and environment
|
|
322
|
+
*
|
|
323
|
+
* @param options The pipeline options
|
|
324
|
+
* @returns True if threading should be used, false otherwise
|
|
325
|
+
*/
|
|
326
|
+
shouldUseThreading(options) {
|
|
327
|
+
// If threading is explicitly disabled, don't use it
|
|
328
|
+
if (options.disableThreading) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
// If threading is explicitly forced, use it if available
|
|
332
|
+
if (options.forceThreading) {
|
|
333
|
+
return isThreadingAvailable();
|
|
334
|
+
}
|
|
335
|
+
// If in THREADED mode, use threading if available
|
|
336
|
+
if (options.mode === ExecutionMode.THREADED) {
|
|
337
|
+
return isThreadingAvailable();
|
|
338
|
+
}
|
|
339
|
+
// Otherwise, don't use threading
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Execute a pipeline for a specific augmentation type
|
|
344
|
+
*
|
|
345
|
+
* @param augmentations The augmentations to execute
|
|
346
|
+
* @param method The method to execute on each augmentation
|
|
347
|
+
* @param args The arguments to pass to the method
|
|
348
|
+
* @param options The pipeline execution options
|
|
349
|
+
* @returns A promise that resolves with the results from all augmentations
|
|
350
|
+
*/
|
|
351
|
+
async executeTypedPipeline(augmentations, method, args, options) {
|
|
352
|
+
// Filter out disabled augmentations
|
|
353
|
+
const enabledAugmentations = augmentations.filter((aug) => aug.enabled !== false);
|
|
354
|
+
if (enabledAugmentations.length === 0) {
|
|
355
|
+
return [];
|
|
356
|
+
}
|
|
357
|
+
// Create a function to execute the method on an augmentation
|
|
358
|
+
const executeMethod = async (augmentation) => {
|
|
359
|
+
try {
|
|
360
|
+
// Create a timeout promise if a timeout is specified
|
|
361
|
+
const timeoutPromise = options.timeout
|
|
362
|
+
? new Promise((_, reject) => {
|
|
363
|
+
setTimeout(() => {
|
|
364
|
+
reject(new Error(`Timeout executing ${String(method)} on ${augmentation.name}`));
|
|
365
|
+
}, options.timeout);
|
|
366
|
+
})
|
|
367
|
+
: null;
|
|
368
|
+
// Check if threading should be used
|
|
369
|
+
const useThreading = this.shouldUseThreading(options);
|
|
370
|
+
// Execute the method on the augmentation, using threading if appropriate
|
|
371
|
+
let methodPromise;
|
|
372
|
+
if (useThreading) {
|
|
373
|
+
// Execute in a separate thread
|
|
374
|
+
try {
|
|
375
|
+
// Create a function that can be serialized and executed in a worker
|
|
376
|
+
const workerFn = (...workerArgs) => {
|
|
377
|
+
// This function will be stringified and executed in the worker
|
|
378
|
+
// It needs to be self-contained
|
|
379
|
+
const augFn = augmentation[method];
|
|
380
|
+
return augFn.apply(augmentation, workerArgs);
|
|
381
|
+
};
|
|
382
|
+
methodPromise = executeInThread(workerFn.toString(), args);
|
|
383
|
+
}
|
|
384
|
+
catch (threadError) {
|
|
385
|
+
console.warn(`Failed to execute in thread, falling back to main thread: ${threadError}`);
|
|
386
|
+
// Fall back to executing in the main thread
|
|
387
|
+
methodPromise = Promise.resolve(augmentation[method](...args));
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
// Execute in the main thread
|
|
392
|
+
methodPromise = Promise.resolve(augmentation[method](...args));
|
|
393
|
+
}
|
|
394
|
+
// Race the method promise against the timeout promise if a timeout is specified
|
|
395
|
+
const result = timeoutPromise
|
|
396
|
+
? await Promise.race([methodPromise, timeoutPromise])
|
|
397
|
+
: await methodPromise;
|
|
398
|
+
return result;
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
console.error(`Error executing ${String(method)} on ${augmentation.name}:`, error);
|
|
402
|
+
return {
|
|
403
|
+
success: false,
|
|
404
|
+
data: null,
|
|
405
|
+
error: error instanceof Error ? error.message : String(error)
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
// Execute the pipeline based on the specified mode
|
|
410
|
+
switch (options.mode) {
|
|
411
|
+
case ExecutionMode.PARALLEL:
|
|
412
|
+
// Execute all augmentations in parallel
|
|
413
|
+
return enabledAugmentations.map(executeMethod);
|
|
414
|
+
case ExecutionMode.THREADED:
|
|
415
|
+
// Execute all augmentations in parallel with threading enabled
|
|
416
|
+
// Force threading for this mode
|
|
417
|
+
const threadedOptions = { ...options, forceThreading: true };
|
|
418
|
+
// Create a new executeMethod function that uses the threaded options
|
|
419
|
+
const executeMethodThreaded = async (augmentation) => {
|
|
420
|
+
// Save the original options
|
|
421
|
+
const originalOptions = options;
|
|
422
|
+
// Set the options to the threaded options
|
|
423
|
+
options = threadedOptions;
|
|
424
|
+
// Execute the method
|
|
425
|
+
const result = await executeMethod(augmentation);
|
|
426
|
+
// Restore the original options
|
|
427
|
+
options = originalOptions;
|
|
428
|
+
return result;
|
|
429
|
+
};
|
|
430
|
+
return enabledAugmentations.map(executeMethodThreaded);
|
|
431
|
+
case ExecutionMode.FIRST_SUCCESS:
|
|
432
|
+
// Execute augmentations sequentially until one succeeds
|
|
433
|
+
for (const augmentation of enabledAugmentations) {
|
|
434
|
+
const resultPromise = executeMethod(augmentation);
|
|
435
|
+
const result = await resultPromise;
|
|
436
|
+
if (result.success) {
|
|
437
|
+
return [resultPromise];
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return [];
|
|
441
|
+
case ExecutionMode.FIRST_RESULT:
|
|
442
|
+
// Execute augmentations sequentially until one returns a result
|
|
443
|
+
for (const augmentation of enabledAugmentations) {
|
|
444
|
+
const resultPromise = executeMethod(augmentation);
|
|
445
|
+
const result = await resultPromise;
|
|
446
|
+
if (result.success && result.data) {
|
|
447
|
+
return [resultPromise];
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return [];
|
|
451
|
+
case ExecutionMode.SEQUENTIAL:
|
|
452
|
+
default:
|
|
453
|
+
// Execute augmentations sequentially
|
|
454
|
+
const results = [];
|
|
455
|
+
for (const augmentation of enabledAugmentations) {
|
|
456
|
+
const resultPromise = executeMethod(augmentation);
|
|
457
|
+
results.push(resultPromise);
|
|
458
|
+
// Check if we need to stop on error
|
|
459
|
+
if (options.stopOnError) {
|
|
460
|
+
const result = await resultPromise;
|
|
461
|
+
if (!result.success) {
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return results;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
// Create and export a default instance of the pipeline
|
|
471
|
+
export const augmentationPipeline = new AugmentationPipeline();
|
|
472
|
+
//# sourceMappingURL=augmentationPipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"augmentationPipeline.js","sourceRoot":"","sources":["../src/augmentationPipeline.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAKL,gBAAgB,EACjB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,oBAAoB,EAAqB,MAAM,wBAAwB,CAAA;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAgBxD;;GAEG;AACH,MAAM,CAAN,IAAY,aAMX;AAND,WAAY,aAAa;IACvB,0CAAyB,CAAA;IACzB,sCAAqB,CAAA;IACrB,+CAA8B,CAAA;IAC9B,6CAA4B,CAAA;IAC5B,sCAAqB,CAAA,CAAC,6CAA6C;AACrE,CAAC,EANW,aAAa,KAAb,aAAa,QAMxB;AAaD;;GAEG;AACH,MAAM,wBAAwB,GAAoB;IAChD,IAAI,EAAE,aAAa,CAAC,UAAU;IAC9B,OAAO,EAAE,KAAK;IACd,WAAW,EAAE,KAAK;IAClB,cAAc,EAAE,KAAK;IACrB,gBAAgB,EAAE,KAAK;CACxB,CAAA;AAED;;;;GAIG;AACH,MAAM,OAAO,oBAAoB;IAAjC;QACU,aAAQ,GAAyB;YACvC,KAAK,EAAE,EAAE;YACT,OAAO,EAAE,EAAE;YACX,SAAS,EAAE,EAAE;YACb,MAAM,EAAE,EAAE;YACV,UAAU,EAAE,EAAE;YACd,MAAM,EAAE,EAAE;YACV,UAAU,EAAE,EAAE;YACd,SAAS,EAAE,EAAE;SACd,CAAA;IAwwBH,CAAC;IAtwBC;;;;;OAKG;IACI,QAAQ,CACb,YAAe;QAEf,IAAI,UAAU,GAAG,KAAK,CAAA;QAEtB,wCAAwC;QACxC,IACE,IAAI,CAAC,kBAAkB,CACrB,YAAY,EACZ,gBAAgB,EAChB,cAAc,CACf,EACD,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;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gB,8BAA8B,CAC5C,gBAAgB,CAAC,EAAE,SAAS,GAC3B,SAAS,CAgBX;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAS9E;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,gBAAgB,GAAG,aAAa,EAAE,CAyB9E"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Augmentation Registry
|
|
3
|
+
*
|
|
4
|
+
* This module provides a registry for augmentations that are loaded at build time.
|
|
5
|
+
* It replaces the dynamic loading mechanism in pluginLoader.ts.
|
|
6
|
+
*/
|
|
7
|
+
import { AugmentationType } from './types/augmentations.js';
|
|
8
|
+
// Forward declaration of the pipeline instance to avoid circular dependency
|
|
9
|
+
// The actual pipeline will be provided when initializeAugmentationPipeline is called
|
|
10
|
+
let defaultPipeline = null;
|
|
11
|
+
/**
|
|
12
|
+
* Sets the default pipeline instance
|
|
13
|
+
* This function should be called from pipeline.ts after the pipeline is created
|
|
14
|
+
*/
|
|
15
|
+
export function setDefaultPipeline(pipeline) {
|
|
16
|
+
defaultPipeline = pipeline;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Registry of all available augmentations
|
|
20
|
+
*/
|
|
21
|
+
export const availableAugmentations = [];
|
|
22
|
+
/**
|
|
23
|
+
* Registers an augmentation with the registry
|
|
24
|
+
*
|
|
25
|
+
* @param augmentation The augmentation to register
|
|
26
|
+
* @returns The augmentation that was registered
|
|
27
|
+
*/
|
|
28
|
+
export function registerAugmentation(augmentation) {
|
|
29
|
+
// Set enabled to true by default if not specified
|
|
30
|
+
if (augmentation.enabled === undefined) {
|
|
31
|
+
augmentation.enabled = true;
|
|
32
|
+
}
|
|
33
|
+
// Add to the registry
|
|
34
|
+
availableAugmentations.push(augmentation);
|
|
35
|
+
return augmentation;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Initializes the augmentation pipeline with all registered augmentations
|
|
39
|
+
*
|
|
40
|
+
* @param pipeline Optional custom pipeline to use instead of the default
|
|
41
|
+
* @returns The pipeline that was initialized
|
|
42
|
+
* @throws Error if no pipeline is provided and the default pipeline hasn't been set
|
|
43
|
+
*/
|
|
44
|
+
export function initializeAugmentationPipeline(pipelineInstance) {
|
|
45
|
+
// Use the provided pipeline or fall back to the default
|
|
46
|
+
const pipeline = pipelineInstance || defaultPipeline;
|
|
47
|
+
if (!pipeline) {
|
|
48
|
+
throw new Error('No pipeline provided and default pipeline not set. Call setDefaultPipeline first.');
|
|
49
|
+
}
|
|
50
|
+
// Register all augmentations with the pipeline
|
|
51
|
+
for (const augmentation of availableAugmentations) {
|
|
52
|
+
if (augmentation.enabled) {
|
|
53
|
+
pipeline.register(augmentation);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return pipeline;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Enables or disables an augmentation by name
|
|
60
|
+
*
|
|
61
|
+
* @param name The name of the augmentation to enable/disable
|
|
62
|
+
* @param enabled Whether to enable or disable the augmentation
|
|
63
|
+
* @returns True if the augmentation was found and updated, false otherwise
|
|
64
|
+
*/
|
|
65
|
+
export function setAugmentationEnabled(name, enabled) {
|
|
66
|
+
const augmentation = availableAugmentations.find(aug => aug.name === name);
|
|
67
|
+
if (augmentation) {
|
|
68
|
+
augmentation.enabled = enabled;
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Gets all augmentations of a specific type
|
|
75
|
+
*
|
|
76
|
+
* @param type The type of augmentation to get
|
|
77
|
+
* @returns An array of all augmentations of the specified type
|
|
78
|
+
*/
|
|
79
|
+
export function getAugmentationsByType(type) {
|
|
80
|
+
return availableAugmentations.filter(aug => {
|
|
81
|
+
// Check if the augmentation is of the specified type
|
|
82
|
+
// This is a simplified check and may need to be updated based on how types are determined
|
|
83
|
+
switch (type) {
|
|
84
|
+
case AugmentationType.SENSE:
|
|
85
|
+
return 'processRawData' in aug && 'listenToFeed' in aug;
|
|
86
|
+
case AugmentationType.CONDUIT:
|
|
87
|
+
return 'establishConnection' in aug && 'readData' in aug && 'writeData' in aug;
|
|
88
|
+
case AugmentationType.COGNITION:
|
|
89
|
+
return 'reason' in aug && 'infer' in aug && 'executeLogic' in aug;
|
|
90
|
+
case AugmentationType.MEMORY:
|
|
91
|
+
return 'storeData' in aug && 'retrieveData' in aug && 'updateData' in aug;
|
|
92
|
+
case AugmentationType.PERCEPTION:
|
|
93
|
+
return 'interpret' in aug && 'organize' in aug && 'generateVisualization' in aug;
|
|
94
|
+
case AugmentationType.DIALOG:
|
|
95
|
+
return 'processUserInput' in aug && 'generateResponse' in aug && 'manageContext' in aug;
|
|
96
|
+
case AugmentationType.ACTIVATION:
|
|
97
|
+
return 'triggerAction' in aug && 'generateOutput' in aug && 'interactExternal' in aug;
|
|
98
|
+
case AugmentationType.WEBSOCKET:
|
|
99
|
+
return 'connectWebSocket' in aug && 'sendWebSocketMessage' in aug && 'onWebSocketMessage' in aug;
|
|
100
|
+
default:
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=augmentationRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"augmentationRegistry.js","sourceRoot":"","sources":["../src/augmentationRegistry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,gBAAgB,EAAiB,MAAM,0BAA0B,CAAA;AAE1E,4EAA4E;AAC5E,qFAAqF;AACrF,IAAI,eAAe,GAAqB,IAAI,CAAA;AAE5C;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAmB;IACpD,eAAe,GAAG,QAAQ,CAAA;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAoB,EAA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