@indra.ai/deva 1.4.14 â 1.4.15
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 +18 -12
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -477,6 +477,7 @@ class Deva {
|
|
|
477
477
|
return new Promise((resolve, reject) => {
|
|
478
478
|
// resolve with the no text message if the client says nothing.
|
|
479
479
|
if (!TEXT) return resolve(this._messages.notext, resolve);
|
|
480
|
+
this.state('try', 'question');
|
|
480
481
|
try { // try to answer the question
|
|
481
482
|
if (isAsk) { // determine if hte question isAsk
|
|
482
483
|
// if:isAsk split the agent key and remove first command character
|
|
@@ -526,13 +527,13 @@ class Deva {
|
|
|
526
527
|
return this.finish(answer, resolve); // if:isAsk resolve the answer from the call
|
|
527
528
|
});
|
|
528
529
|
}
|
|
529
|
-
else { // else: answer
|
|
530
|
-
this.state('answer',
|
|
530
|
+
else { // else: answer the question locally
|
|
531
|
+
this.state('answer', method); //set the answer state to the method
|
|
531
532
|
return this.answer(packet, resolve, reject);
|
|
532
533
|
}
|
|
533
534
|
}
|
|
534
535
|
catch(e) {
|
|
535
|
-
this.state('
|
|
536
|
+
this.state('catch', 'question');
|
|
536
537
|
return this.error(e); // if a overall error happens this witll call this.error
|
|
537
538
|
}
|
|
538
539
|
});
|
|
@@ -550,6 +551,7 @@ class Deva {
|
|
|
550
551
|
***************/
|
|
551
552
|
answer(packet, resolve, reject) {
|
|
552
553
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
554
|
+
this.zone('answer', method);
|
|
553
555
|
const agent = this.agent();
|
|
554
556
|
const client = this.client();
|
|
555
557
|
// check if method exists and is of type function
|
|
@@ -558,7 +560,7 @@ class Deva {
|
|
|
558
560
|
if (!isMethod) return resolve(this._methodNotFound(packet)); // resolve method not found if check if check fails
|
|
559
561
|
|
|
560
562
|
// Call the local method to process the question based the extracted parameters
|
|
561
|
-
this.
|
|
563
|
+
this.action('method', method);
|
|
562
564
|
this.methods[method](packet).then(result => {
|
|
563
565
|
// check the result for the text, html, and data object.
|
|
564
566
|
// this is for when answers are returned from nested Devas.
|
|
@@ -567,7 +569,7 @@ class Deva {
|
|
|
567
569
|
// if the data passed is NOT an object it will FALSE
|
|
568
570
|
const data = typeof result === 'object' ? result.data : false;
|
|
569
571
|
|
|
570
|
-
this.state('set', 'answer')
|
|
572
|
+
this.state('set', 'answer');
|
|
571
573
|
const packet_answer = { // setup the packet.a container
|
|
572
574
|
id: this.lib.uid(),
|
|
573
575
|
agent, // set the agent who answered the question
|
|
@@ -582,16 +584,16 @@ class Deva {
|
|
|
582
584
|
data, // set the answer data
|
|
583
585
|
created: Date.now(), // set the created date for the answer
|
|
584
586
|
};
|
|
585
|
-
|
|
586
587
|
// create a hash for the answer and insert into answer meta.
|
|
588
|
+
this.action('talk', config.events.answer)
|
|
587
589
|
packet_answer.meta.hash = this.lib.hash(packet_answer);
|
|
588
590
|
packet.a = packet_answer; // set the packet.a to the packet_answer
|
|
589
|
-
this.action('talk', config.events.answer)
|
|
590
591
|
this.talk(config.events.answer, this.lib.copy(packet)); // global talk event
|
|
591
|
-
|
|
592
|
+
|
|
593
|
+
this.state('finish', 'answer'); // set the state resolve answer
|
|
592
594
|
return this.finish(packet, resolve); // resolve the packet to the caller.
|
|
593
595
|
}).catch(err => { // catch any errors in the method
|
|
594
|
-
this.state('
|
|
596
|
+
this.state('catch', 'answer'); // set the state reject answer
|
|
595
597
|
return this.error(err, packet, reject); // return this.error with err, packet, reject
|
|
596
598
|
});
|
|
597
599
|
}
|
|
@@ -619,6 +621,7 @@ class Deva {
|
|
|
619
621
|
const agent = this.agent();
|
|
620
622
|
const client = this.client();
|
|
621
623
|
// build the answer packet from this model
|
|
624
|
+
this.state('set', 'answer');
|
|
622
625
|
const packet_answer = {
|
|
623
626
|
id: this.lib.uid(),
|
|
624
627
|
agent,
|
|
@@ -634,6 +637,7 @@ class Deva {
|
|
|
634
637
|
created: Date.now(),
|
|
635
638
|
};
|
|
636
639
|
|
|
640
|
+
this.state('try', method);
|
|
637
641
|
try {
|
|
638
642
|
if (typeof this.methods[method] !== 'function') {
|
|
639
643
|
return setImmediate(() => {
|
|
@@ -654,13 +658,15 @@ class Deva {
|
|
|
654
658
|
packet_answer.text = result;
|
|
655
659
|
}
|
|
656
660
|
|
|
657
|
-
this.state('set', `ask:${method}`);
|
|
658
661
|
packet_answer.meta.hash = this.lib.hash(packet_answer);
|
|
659
662
|
packet.a = packet_answer;
|
|
663
|
+
this.action('talk', config.events.answer);
|
|
660
664
|
this.talk(config.events.answer, this.lib.copy(packet)); // global talk event
|
|
665
|
+
this.action('talk', `ask:${packet.id}`);
|
|
661
666
|
this.talk(`${agent.key}:ask:${packet.id}`, packet);
|
|
662
667
|
}).catch(err => {
|
|
663
668
|
this.talk(`${agent.key}:ask:${packet.id}`, {error:err});
|
|
669
|
+
this.state('catch', 'ask');
|
|
664
670
|
return this.error(err, packet);
|
|
665
671
|
})
|
|
666
672
|
}
|
|
@@ -968,7 +974,7 @@ class Deva {
|
|
|
968
974
|
***************/
|
|
969
975
|
state(value=false, extra=false) {
|
|
970
976
|
try {
|
|
971
|
-
if (!value || !this._states[value]) return; // return if no matching value
|
|
977
|
+
if (!value || !this._states[value] || value === this._state) return; // return if no matching value
|
|
972
978
|
this._state = value; // set the local state variable.
|
|
973
979
|
const lookup = this._states[value]; // set the local states lookup
|
|
974
980
|
const text = extra ? `${lookup} ${extra}` : lookup; // set text from lookup with extra
|
|
@@ -1062,7 +1068,7 @@ class Deva {
|
|
|
1062
1068
|
***************/
|
|
1063
1069
|
action(value=false, extra=false) {
|
|
1064
1070
|
try {
|
|
1065
|
-
if (!value
|
|
1071
|
+
if (!value || !this._actions[value] || value === this._action) return;
|
|
1066
1072
|
this._action = value; // set the local action variable
|
|
1067
1073
|
// check local vars for custom actions
|
|
1068
1074
|
const var_action = this.vars.actions ? this.vars.actions[value] : false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indra.ai/deva",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.15",
|
|
4
4
|
"description": "The Deva Core",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -125,8 +125,6 @@
|
|
|
125
125
|
"send": "đŦ Send",
|
|
126
126
|
"receive": "đĒ Receive",
|
|
127
127
|
"init": "đ Init",
|
|
128
|
-
"forward": "âī¸ Forward",
|
|
129
|
-
"backward": "âŽī¸ Backward",
|
|
130
128
|
"start": "đ Start",
|
|
131
129
|
"stop": "âšī¸ Stop",
|
|
132
130
|
"open": "đĨĢ Open",
|
|
@@ -155,7 +153,7 @@
|
|
|
155
153
|
"pull": "đ Pull",
|
|
156
154
|
"search": "đ Search",
|
|
157
155
|
"memory": "đ Memory",
|
|
158
|
-
"signature": "
|
|
156
|
+
"signature": "âī¸ī¸ Signature",
|
|
159
157
|
"invalid": "đ INVALID!",
|
|
160
158
|
"valid": "đ VALID!",
|
|
161
159
|
"abort": "đ ABORT!",
|
|
@@ -174,7 +172,9 @@
|
|
|
174
172
|
"unofficial": "đ¤Ĩ Unofficial",
|
|
175
173
|
"approved": "đī¸ Approved",
|
|
176
174
|
"denied": "đ Denied",
|
|
177
|
-
"secure": "đ Secure"
|
|
175
|
+
"secure": "đ Secure",
|
|
176
|
+
"try": "đ¸ Try",
|
|
177
|
+
"catch": "âžī¸ Catch"
|
|
178
178
|
},
|
|
179
179
|
"action": false,
|
|
180
180
|
"actions": {
|