@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.
Files changed (2) hide show
  1. package/index.js +28 -22
  2. package/package.json +5 -5
package/index.js CHANGED
@@ -182,7 +182,7 @@ class Deva {
182
182
  return packet;
183
183
  }
184
184
 
185
- _feature(key, value) {
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 tue question locally
530
- this.state('answer', `question:${method}`);
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('reject', 'question');
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.zone('answer', method);
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
- this.state('resovle', 'answer');
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('reject', 'answer');
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) return; // check feature 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._feature('security', this._security);
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._feature('defense', this._defense);
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._feature('support', this._support);
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._feature('services', this._services);
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._feature('systems', this._systems);
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._feature('networks', this._networks);
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._feature('legal', this._legal);
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._feature('legal', this._legal);
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._feature('authority', this._authority);
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.13",
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": "â›‘ī¸ Response",
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": {