@indra.ai/deva 1.1.10 → 1.1.12
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/index.js +40 -30
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -7,33 +7,39 @@ const { createHash, randomUUID } = require('crypto');
|
|
|
7
7
|
class Deva {
|
|
8
8
|
constructor(opts) {
|
|
9
9
|
opts = opts || {};
|
|
10
|
-
this.
|
|
10
|
+
this._id = randomUUID(); // the unique id assigned to the agent at load
|
|
11
11
|
this._state = 'OFFLINE'; // current state of agent.
|
|
12
12
|
this._states = { // The available states to work with.
|
|
13
|
-
offline: 'OFFLINE',
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
enter: 'ENTER',
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
13
|
+
offline: '👻 OFFLINE',
|
|
14
|
+
online: '📡 ONLINE',
|
|
15
|
+
init: '🚀 INIT',
|
|
16
|
+
start: '🎬 START',
|
|
17
|
+
enter: '🎪 ENTER',
|
|
18
|
+
stop: '🛑 STOP',
|
|
19
|
+
exit: '🚪 EXIT',
|
|
20
|
+
done: '🤝 DONE',
|
|
21
|
+
devas_start: '✨ DEVAS START',
|
|
22
|
+
devas_ready: '📸 DEVAS READY',
|
|
23
|
+
devas_stop: '🙈 DEVAS STOP',
|
|
24
|
+
devas_stopped: '🛑 DEVAS STOPPED',
|
|
25
|
+
deva_load: '✅ DEVA LOAD',
|
|
26
|
+
deva_loaded: '✅ DEVA LOADED',
|
|
27
|
+
deva_unloaded: '✅ DEVA UNLOADED',
|
|
28
|
+
wait: '😵💫 WAITING',
|
|
29
|
+
data: '📀 DATA',
|
|
30
|
+
ask: '🙋♀️ ASK',
|
|
31
|
+
question: '🙋♂️ QUESTION',
|
|
32
|
+
answer: '🔮 ANSWER',
|
|
33
|
+
talk: '🎙️ TALK',
|
|
34
|
+
listen: '🎧 LISTEN',
|
|
35
|
+
error: '❌ ERROR',
|
|
36
|
+
story: '📓 STORY',
|
|
37
|
+
development: '👨💻 DEVELOPMENT',
|
|
38
|
+
security: '🚨 SECURITY',
|
|
39
|
+
support: '🎗️ SUPPORT',
|
|
40
|
+
services: '🎖️ SERVICES',
|
|
41
|
+
systems: '👽 SYSTEMS',
|
|
42
|
+
solutions: '🔬 SOLUTIONS',
|
|
37
43
|
};
|
|
38
44
|
this._active = false; // the active/birth date.
|
|
39
45
|
this.security = false; // inherited Security features.
|
|
@@ -61,8 +67,6 @@ class Deva {
|
|
|
61
67
|
this.bind = ["listeners", "methods", "func", "lib", "security", "agent", "client"];
|
|
62
68
|
this.messages = {
|
|
63
69
|
offline: 'AGENT OFFLINE',
|
|
64
|
-
loading: 'DEVAS LOADING',
|
|
65
|
-
loaded: 'DEVAS LOADED',
|
|
66
70
|
stopped: 'DEVAS STOPPED',
|
|
67
71
|
notext: 'NO TEXT',
|
|
68
72
|
notfound: 'NOT FOUND',
|
|
@@ -290,11 +294,13 @@ class Deva {
|
|
|
290
294
|
This function will enable fast loading of Deva into a system.
|
|
291
295
|
***************/
|
|
292
296
|
load(deva) {
|
|
297
|
+
this.state('deva_load');
|
|
293
298
|
this.devas[deva.key] = deva;
|
|
294
299
|
// inherit the data to the new deva.
|
|
295
300
|
this.inherit.forEach(inherit => {
|
|
296
301
|
this.devas[deva.key][inherit] = this[inherit];
|
|
297
302
|
});
|
|
303
|
+
this.state('deva_loaded');
|
|
298
304
|
return Promise.resolve();
|
|
299
305
|
}
|
|
300
306
|
|
|
@@ -306,7 +312,9 @@ class Deva {
|
|
|
306
312
|
describe: Unload a currently loaded Deva.
|
|
307
313
|
***************/
|
|
308
314
|
unload(deva) {
|
|
315
|
+
this.state('deva_unload');
|
|
309
316
|
delete this.devas[deva];
|
|
317
|
+
this.state('deva_unloaded');
|
|
310
318
|
return Promise.resolve(`unload:${deva} `);
|
|
311
319
|
}
|
|
312
320
|
|
|
@@ -682,7 +690,7 @@ class Deva {
|
|
|
682
690
|
Start Devas will initialize the Deva agents inside this curent Deva.
|
|
683
691
|
***************/
|
|
684
692
|
startDevas() {
|
|
685
|
-
this.state('
|
|
693
|
+
this.state('devas_start');
|
|
686
694
|
return new Promise((resolve, reject) => {
|
|
687
695
|
this.prompt
|
|
688
696
|
const devas = [];
|
|
@@ -690,8 +698,8 @@ class Deva {
|
|
|
690
698
|
devas.push(this.devas[x].init());
|
|
691
699
|
}
|
|
692
700
|
Promise.all(devas).then(() => {
|
|
693
|
-
this.state('
|
|
694
|
-
return resolve(this.
|
|
701
|
+
this.state('devas_ready');
|
|
702
|
+
return resolve(this._state);
|
|
695
703
|
}).catch(reject);
|
|
696
704
|
});
|
|
697
705
|
}
|
|
@@ -702,12 +710,14 @@ class Deva {
|
|
|
702
710
|
stopDevas will stop all the devas running in the current Deva.
|
|
703
711
|
***************/
|
|
704
712
|
stopDevas() {
|
|
713
|
+
this.state('devas_stop');
|
|
705
714
|
return new Promise((resolve, reject) => {
|
|
706
715
|
const devas = [];
|
|
707
716
|
for (let x in this.devas) {
|
|
708
717
|
devas.push(this.devas[x].stop());
|
|
709
718
|
}
|
|
710
719
|
Promise.all(devas).then(() => {
|
|
720
|
+
this.state('devas_stoped');
|
|
711
721
|
return resolve(this.messages.stopped);
|
|
712
722
|
}).catch(reject);
|
|
713
723
|
});
|