@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.
Files changed (2) hide show
  1. package/index.js +18 -12
  2. 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 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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.4.14",
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": {