@indra.ai/deva 1.1.83 → 1.1.84

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 +12 -9
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -61,6 +61,7 @@ class Deva {
61
61
  this._messages = {
62
62
  notext: 'NO TEXT WAS PROVIDED',
63
63
  nopacket: 'NO PACKET WAS PROVIDED',
64
+ method_not_found: 'METHOD NOT FOUND',
64
65
  }; // set the messages from config
65
66
 
66
67
  // then here we are going to loop the messages config to make sure custom values are set
@@ -772,7 +773,8 @@ class Deva {
772
773
  packet.q.meta.hash = this.hash(packet.q);
773
774
 
774
775
  this.action(_action);
775
- this.talk(config.events.question, this.copy(packet)); // global question event make sure to copy data.
776
+ this.talk(`${key}:question`, this.copy(packet)); // key question event make sure to copy data.
777
+ this.talk(config.events.question, this.copy(packet)); // global question event make sure to copy data.
776
778
 
777
779
  if (isAsk) { // isAsk check if the question isAsk and talk
778
780
  this.state('ask');
@@ -851,7 +853,8 @@ class Deva {
851
853
 
852
854
 
853
855
  this.action('answer_talk');
854
- this.talk(config.events.answer, this.copy(packet)); // talk the answer with a copy of the data
856
+ this.talk(`${agent.key}:answer`, this.copy(packet)); // agent key answer event
857
+ this.talk(config.events.answer, this.copy(packet)); // global talk event
855
858
 
856
859
  return resolve(this.copy(packet)); // resolve the packet to the caller.
857
860
  }).catch(err => { // catch any errors in the method
@@ -880,8 +883,8 @@ class Deva {
880
883
  this.state('ask');
881
884
  this.action('ask');
882
885
 
883
- const agent = this.agent() || false;
884
- const client = this.client() || false;
886
+ const agent = this.agent();
887
+ const client = this.client();
885
888
  // build the answer packet from this model
886
889
  packet.a = {
887
890
  agent,
@@ -901,8 +904,7 @@ class Deva {
901
904
  if (typeof this.methods[packet.q.meta.method] !== 'function') {
902
905
  return setImmediate(() => {
903
906
  this.action('invalid')
904
- packet.a.text = `INVALID METHOD (${packet.q.meta.method})`;
905
- this.talk(`${this._agent.key}:ask:${packet.id}`, packet);
907
+ this.talk(`${this._agent.key}:ask:${packet.id}`, this._methodNotFound(packet));
906
908
  });
907
909
  }
908
910
 
@@ -918,16 +920,17 @@ class Deva {
918
920
  packet.a.text = result;
919
921
  }
920
922
  this.action('ask_answer');
921
- this.talk(`${this._agent.key}:ask:${packet.id}`, packet);
923
+ this.talk(`${agent.key}:answer`, this.copy(packet));
924
+ this.talk(`${agent.key}:ask:${packet.id}`, packet);
922
925
  }).catch(err => {
923
926
  this.action('error');
924
- this.talk(`${this._agent.key}:ask:${packet.id}`, {error:err});
927
+ this.talk(`${agent.key}:ask:${packet.id}`, {error:err});
925
928
  return this.error(err, packet);
926
929
  })
927
930
  }
928
931
  catch (e) {
929
932
  this.action('error');
930
- this.talk(`${this._agent.key}:ask:${packet.id}`, {error:e});
933
+ this.talk(`${agent.key}:ask:${packet.id}`, {error:e});
931
934
  return this.error(e, packet)
932
935
  }
933
936
  // now when we ask the meta params[0] should be the method
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.1.83",
3
+ "version": "1.1.84",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "scripts": {