@indra.ai/deva 1.4.13 â 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 +28 -22
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -182,7 +182,7 @@ class Deva {
|
|
|
182
182
|
return packet;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
_getFeature(key, value) {
|
|
186
186
|
if (!this._active) return this._messages.offline; // check the active status
|
|
187
187
|
this.zone(key);
|
|
188
188
|
this.feature(key); // set the security state
|
|
@@ -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;
|
|
@@ -1236,7 +1242,7 @@ class Deva {
|
|
|
1236
1242
|
usage: this.security()
|
|
1237
1243
|
***************/
|
|
1238
1244
|
security() {
|
|
1239
|
-
return this.
|
|
1245
|
+
return this._getFeature('security', this._security);
|
|
1240
1246
|
}
|
|
1241
1247
|
|
|
1242
1248
|
/**************
|
|
@@ -1246,7 +1252,7 @@ class Deva {
|
|
|
1246
1252
|
usage: this.defense()
|
|
1247
1253
|
***************/
|
|
1248
1254
|
defense() {
|
|
1249
|
-
return this.
|
|
1255
|
+
return this._getFeature('defense', this._defense);
|
|
1250
1256
|
}
|
|
1251
1257
|
|
|
1252
1258
|
/**************
|
|
@@ -1256,7 +1262,7 @@ class Deva {
|
|
|
1256
1262
|
usage: this.support()
|
|
1257
1263
|
***************/
|
|
1258
1264
|
support() {
|
|
1259
|
-
return this.
|
|
1265
|
+
return this._getFeature('support', this._support);
|
|
1260
1266
|
}
|
|
1261
1267
|
|
|
1262
1268
|
/**************
|
|
@@ -1266,7 +1272,7 @@ class Deva {
|
|
|
1266
1272
|
usage: this.services()
|
|
1267
1273
|
***************/
|
|
1268
1274
|
services() {
|
|
1269
|
-
return this.
|
|
1275
|
+
return this._getFeature('services', this._services);
|
|
1270
1276
|
}
|
|
1271
1277
|
|
|
1272
1278
|
/**************
|
|
@@ -1276,7 +1282,7 @@ class Deva {
|
|
|
1276
1282
|
usage: this.systems()
|
|
1277
1283
|
***************/
|
|
1278
1284
|
systems() {
|
|
1279
|
-
return this.
|
|
1285
|
+
return this._getFeature('systems', this._systems);
|
|
1280
1286
|
}
|
|
1281
1287
|
|
|
1282
1288
|
/**************
|
|
@@ -1286,7 +1292,7 @@ class Deva {
|
|
|
1286
1292
|
usage: this.networks()
|
|
1287
1293
|
***************/
|
|
1288
1294
|
networks() {
|
|
1289
|
-
return this.
|
|
1295
|
+
return this._getFeature('networks', this._networks);
|
|
1290
1296
|
}
|
|
1291
1297
|
|
|
1292
1298
|
/**************
|
|
@@ -1296,7 +1302,7 @@ class Deva {
|
|
|
1296
1302
|
usage: this.systems()
|
|
1297
1303
|
***************/
|
|
1298
1304
|
legal() {
|
|
1299
|
-
return this.
|
|
1305
|
+
return this._getFeature('legal', this._legal);
|
|
1300
1306
|
}
|
|
1301
1307
|
|
|
1302
1308
|
/**************
|
|
@@ -1306,7 +1312,7 @@ class Deva {
|
|
|
1306
1312
|
usage: this.systems()
|
|
1307
1313
|
***************/
|
|
1308
1314
|
justice() {
|
|
1309
|
-
return this.
|
|
1315
|
+
return this._getFeature('legal', this._legal);
|
|
1310
1316
|
}
|
|
1311
1317
|
|
|
1312
1318
|
/**************
|
|
@@ -1316,7 +1322,7 @@ class Deva {
|
|
|
1316
1322
|
usage: this.systems()
|
|
1317
1323
|
***************/
|
|
1318
1324
|
authority() {
|
|
1319
|
-
return this.
|
|
1325
|
+
return this._getFeature('authority', this._authority);
|
|
1320
1326
|
}
|
|
1321
1327
|
|
|
1322
1328
|
/**************
|
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": {
|