@indra.ai/deva 1.2.17 → 1.2.19
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/config.json +17 -10
- package/index.js +21 -23
- package/package.json +1 -1
package/config.json
CHANGED
|
@@ -30,6 +30,13 @@
|
|
|
30
30
|
"context": false,
|
|
31
31
|
"zone": "deva",
|
|
32
32
|
"zones": {
|
|
33
|
+
"init": "Initialize",
|
|
34
|
+
"start": "Start",
|
|
35
|
+
"stop": "Stop",
|
|
36
|
+
"enter": "Enter",
|
|
37
|
+
"exit": "Exit",
|
|
38
|
+
"finish": "Finish",
|
|
39
|
+
"done": "Done",
|
|
33
40
|
"deva": "Deva",
|
|
34
41
|
"client": "Client",
|
|
35
42
|
"agent": "Agent",
|
|
@@ -51,9 +58,8 @@
|
|
|
51
58
|
"comedy": "Comedy",
|
|
52
59
|
"drama": "Drama",
|
|
53
60
|
"scifi": "SciFi",
|
|
54
|
-
"finish": "Finish",
|
|
55
61
|
"help": "Help",
|
|
56
|
-
"error": "
|
|
62
|
+
"error": "ERROR!"
|
|
57
63
|
},
|
|
58
64
|
"state": "offline",
|
|
59
65
|
"states": {
|
|
@@ -66,6 +72,7 @@
|
|
|
66
72
|
"listen": "Listen",
|
|
67
73
|
"ask": "Ask",
|
|
68
74
|
"question": "Question",
|
|
75
|
+
"cmd": "Command",
|
|
69
76
|
"answer": "Answer",
|
|
70
77
|
"ready": "Ready",
|
|
71
78
|
"wait": "Waiting",
|
|
@@ -102,6 +109,7 @@
|
|
|
102
109
|
"put": "Put",
|
|
103
110
|
"push": "Push",
|
|
104
111
|
"pull": "Pull",
|
|
112
|
+
"set": "Set",
|
|
105
113
|
"invalid": "INVALID!",
|
|
106
114
|
"abort": "ABORT!",
|
|
107
115
|
"error": "ERROR!",
|
|
@@ -137,12 +145,12 @@
|
|
|
137
145
|
"set": "Set",
|
|
138
146
|
"return": "Return",
|
|
139
147
|
|
|
140
|
-
"question_ask": "
|
|
141
|
-
"question_ask_answer": "
|
|
148
|
+
"question_ask": "Ask question",
|
|
149
|
+
"question_ask_answer": "Answer question asked",
|
|
142
150
|
"question_cmd": "Question command",
|
|
143
151
|
"question_method": "Question method",
|
|
144
152
|
"question_talk": "Question talk",
|
|
145
|
-
"question_answer": "
|
|
153
|
+
"question_answer": "Answer question",
|
|
146
154
|
"question_done": "Question done",
|
|
147
155
|
|
|
148
156
|
"answer": "Answer",
|
|
@@ -150,10 +158,9 @@
|
|
|
150
158
|
"ask": "Ask",
|
|
151
159
|
"ask_answer": "Ask answer",
|
|
152
160
|
|
|
153
|
-
"security": "
|
|
154
|
-
"support": "
|
|
155
|
-
"
|
|
156
|
-
"services": "SERVICES",
|
|
161
|
+
"security": "Get Security",
|
|
162
|
+
"support": "Get Support",
|
|
163
|
+
"services": "Get Services",
|
|
157
164
|
|
|
158
165
|
"Client": "Set client",
|
|
159
166
|
"Security": "Set Security",
|
|
@@ -170,7 +177,7 @@
|
|
|
170
177
|
"contexts": "Getting contexts",
|
|
171
178
|
"finish": "Finished action",
|
|
172
179
|
"help": "Giving some HELP!",
|
|
173
|
-
"error": "
|
|
180
|
+
"error": "ERROR!"
|
|
174
181
|
},
|
|
175
182
|
"feature": false,
|
|
176
183
|
"features": {
|
package/index.js
CHANGED
|
@@ -208,7 +208,6 @@ class Deva {
|
|
|
208
208
|
if (isFunc) this.methods[y] = methods[y].bind(this);
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
|
-
// console.log('CLINET BEFORE COPY', client);
|
|
212
211
|
const _client = this.copy(client); // copy the client parameter
|
|
213
212
|
this._client = _client; // set local _client to this scope
|
|
214
213
|
return Promise.resolve();
|
|
@@ -399,8 +398,7 @@ class Deva {
|
|
|
399
398
|
question(TEXT=false, DATA=false) {
|
|
400
399
|
// check the active status
|
|
401
400
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
402
|
-
|
|
403
|
-
this.state('question');
|
|
401
|
+
this.zone('question');
|
|
404
402
|
const id = this.uid(); // generate a unique id for transport.
|
|
405
403
|
const t_split = TEXT.split(' '); // split the text on spaces to get words.
|
|
406
404
|
|
|
@@ -410,6 +408,7 @@ class Deva {
|
|
|
410
408
|
// check to see if the string is a command string to run a local method.
|
|
411
409
|
const isCmd = t_split[0].startsWith(this.cmdChr);
|
|
412
410
|
|
|
411
|
+
this.state('data');
|
|
413
412
|
// Format the packet for return on the request.
|
|
414
413
|
const data = DATA; // set the DATA to data
|
|
415
414
|
const packet = { // create the base q/a packet
|
|
@@ -429,17 +428,21 @@ class Deva {
|
|
|
429
428
|
if (!TEXT) return this.finish(this._messages.notext, resolve);
|
|
430
429
|
// reject question if Deva offline
|
|
431
430
|
if (!this._active) return this.finish(this._messages.offline, resolve);
|
|
432
|
-
let _action = 'question'
|
|
431
|
+
let _action = 'question';
|
|
432
|
+
this.state('question');
|
|
433
433
|
try { // try to answer the question
|
|
434
434
|
if (isAsk) { // determine if hte question isAsk
|
|
435
|
+
this.state('ask');
|
|
435
436
|
_action = 'question_ask';
|
|
436
|
-
|
|
437
|
+
// if:isAsk split the agent key and remove first command character
|
|
438
|
+
key = t_split[0].substring(1);
|
|
437
439
|
//if:isAsk use text split index 1 as the parameter block
|
|
438
440
|
params = t_split[1] ? t_split[1].split(':') : false;
|
|
439
|
-
method = params[0];
|
|
440
|
-
text = t_split.slice(2).join(' ').trim();
|
|
441
|
+
method = params[0]; // the method to check is then params index 0
|
|
442
|
+
text = t_split.slice(2).join(' ').trim(); // rejoin the text with space
|
|
441
443
|
}
|
|
442
|
-
else if (isCmd) {
|
|
444
|
+
else if (isCmd) { // determine if the question is a command
|
|
445
|
+
this.state('cmd');
|
|
443
446
|
_action = 'question_cmd';
|
|
444
447
|
//if:isCmd use text split index 1 as the parameter block
|
|
445
448
|
params = t_split[0] ? t_split[0].split(':').slice(1) : false;
|
|
@@ -652,7 +655,6 @@ class Deva {
|
|
|
652
655
|
}
|
|
653
656
|
_data.hash = this.hash(_data);
|
|
654
657
|
|
|
655
|
-
this.state('init');
|
|
656
658
|
return new Promise((resolve, reject) => {
|
|
657
659
|
this.events.setMaxListeners(this.maxListeners);
|
|
658
660
|
this._assignInherit().then(() => {
|
|
@@ -664,6 +666,7 @@ class Deva {
|
|
|
664
666
|
}).then(() => {
|
|
665
667
|
return this.Security();
|
|
666
668
|
}).then(() => {
|
|
669
|
+
this.zone('init');
|
|
667
670
|
const hasOnInit = this.onInit && typeof this.onInit === 'function';
|
|
668
671
|
return hasOnInit ? this.onInit(_data) : this.start(_data)
|
|
669
672
|
}).catch(err => {
|
|
@@ -683,6 +686,7 @@ class Deva {
|
|
|
683
686
|
usage: this.start('msg')
|
|
684
687
|
***************/
|
|
685
688
|
start(data) {
|
|
689
|
+
this.zone('start');
|
|
686
690
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
687
691
|
this.state('start');
|
|
688
692
|
data.value = 'start';
|
|
@@ -705,6 +709,7 @@ class Deva {
|
|
|
705
709
|
usage: this.enter('msg')
|
|
706
710
|
***************/
|
|
707
711
|
enter(data) {
|
|
712
|
+
this.zone('enter');
|
|
708
713
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
709
714
|
this.state('enter');
|
|
710
715
|
data.value = 'enter';
|
|
@@ -727,6 +732,7 @@ class Deva {
|
|
|
727
732
|
usage: this.done('msg')
|
|
728
733
|
***************/
|
|
729
734
|
done(data) {
|
|
735
|
+
this.zone('done');
|
|
730
736
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
731
737
|
this.state('done');
|
|
732
738
|
data.value = 'done';
|
|
@@ -749,6 +755,7 @@ class Deva {
|
|
|
749
755
|
this.finish(data, resolve)
|
|
750
756
|
***************/
|
|
751
757
|
finish(packet, resolve) {
|
|
758
|
+
this.zone('finish');
|
|
752
759
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
753
760
|
this.state('finish');
|
|
754
761
|
packet.hash = this.hash(packet);// hash the entire packet before finishing.
|
|
@@ -773,9 +780,10 @@ class Deva {
|
|
|
773
780
|
this.stop()
|
|
774
781
|
***************/
|
|
775
782
|
stop() {
|
|
783
|
+
this.zone('stop');
|
|
776
784
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
777
785
|
|
|
778
|
-
this.
|
|
786
|
+
this.state('stop');
|
|
779
787
|
const agent = this.agent();
|
|
780
788
|
const client = this.client();
|
|
781
789
|
|
|
@@ -789,7 +797,7 @@ class Deva {
|
|
|
789
797
|
}
|
|
790
798
|
data.hash = this.hash(data);
|
|
791
799
|
|
|
792
|
-
this.
|
|
800
|
+
this.action('stop');
|
|
793
801
|
const hasOnStop = this.onStop && typeof this.onStop === 'function';
|
|
794
802
|
return hasOnStop ? this.onStop(data) : this.exit(data)
|
|
795
803
|
}
|
|
@@ -811,9 +819,8 @@ class Deva {
|
|
|
811
819
|
***************/
|
|
812
820
|
exit() {
|
|
813
821
|
this.zone('exit');
|
|
814
|
-
this._active = false;
|
|
815
822
|
|
|
816
|
-
this.
|
|
823
|
+
this.state('exit');
|
|
817
824
|
const agent = this.agent();
|
|
818
825
|
const client = this.client();
|
|
819
826
|
|
|
@@ -834,7 +841,7 @@ class Deva {
|
|
|
834
841
|
this._support = false;
|
|
835
842
|
this._services = false;
|
|
836
843
|
|
|
837
|
-
this.
|
|
844
|
+
this.action('exit');
|
|
838
845
|
const hasOnExit = this.onExit && typeof this.onExit === 'function';
|
|
839
846
|
return hasOnExit ? this.onExit(data) : Promise.resolve(data)
|
|
840
847
|
}
|
|
@@ -1462,15 +1469,6 @@ class Deva {
|
|
|
1462
1469
|
***************/
|
|
1463
1470
|
error(err,data=false,reject=false) {
|
|
1464
1471
|
this.zone('error');
|
|
1465
|
-
// check fo rthe custom onError function in the agent.
|
|
1466
|
-
console.log('\n::BEGIN:ERROR\n');
|
|
1467
|
-
console.log(err);
|
|
1468
|
-
console.log('\n::END:ERROR\n');
|
|
1469
|
-
if (data) {
|
|
1470
|
-
console.log('\n::BEGIN:DATA\n');
|
|
1471
|
-
console.log(JSON.stringify(data, null, 2));
|
|
1472
|
-
console.log('\n::END:DATA\n');
|
|
1473
|
-
}
|
|
1474
1472
|
|
|
1475
1473
|
this.state('error')
|
|
1476
1474
|
const agent = this.agent();
|