@indra.ai/deva 1.1.33 → 1.1.35

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 +29 -11
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -543,7 +543,7 @@ class Deva {
543
543
  global: assistant.global, // the global policies for client
544
544
  personal: assistant.devas[this._agent.key] // Client personal features and rules.
545
545
  };
546
- delete this._client.features.legal;
546
+ delete this._client.features.assistant;
547
547
  return this.Done();
548
548
  }
549
549
  } catch (e) {
@@ -558,6 +558,7 @@ class Deva {
558
558
  ***************/
559
559
  Done() {
560
560
  try {
561
+ delete this._client.features; // delete the features key when done.
561
562
  this.state('setting_done'); // set state to assistant setting
562
563
  return;
563
564
  } catch (e) {
@@ -678,7 +679,7 @@ class Deva {
678
679
  packet.a = {
679
680
  agent: this._agent || false,
680
681
  client: this._client || false,
681
- text: `${this._messages.method_not_found} - ${packet.q.meta.method} `,
682
+ text: `${this._messages.method_not_found}`,
682
683
  meta: {
683
684
  key: this._agent.key,
684
685
  method: packet.q.meta.method,
@@ -924,7 +925,7 @@ class Deva {
924
925
  };
925
926
 
926
927
  try {
927
- if (this.methods[packet.q.meta.method] === undefined) {
928
+ if (this.methods[packet.q.meta.method] !== 'function') {
928
929
  return setImmediate(() => {
929
930
  packet.a.text = `INVALID METHOD (${packet.q.meta.method})`;
930
931
  this.talk(`${this._agent.key}:ask:${packet.id}`, packet);
@@ -1035,9 +1036,9 @@ class Deva {
1035
1036
  created: Date.now(), // timestamp the question
1036
1037
  }
1037
1038
 
1038
- this.state('hash_question'); // set the has question state
1039
1039
  // hash the question
1040
1040
  packet.q.meta.hash = this.hash(JSON.stringify(packet.q));
1041
+ this.state('hash_question'); // set the has question state
1041
1042
 
1042
1043
  this.state(_state, packet); // set the state to teh _state variable
1043
1044
 
@@ -1078,13 +1079,15 @@ class Deva {
1078
1079
  created: Date.now(),
1079
1080
  };
1080
1081
  // create a hash for the answer and insert into answer meta.
1081
- this.state(_hash);
1082
1082
  packet.a.meta.hash = this.hash(JSON.stringify(packet.a));
1083
+ this.state(_hash);
1083
1084
  // create a hash for entire packet and insert into packet
1084
- this.state('hash_packet');
1085
1085
  // hash the entire packet.
1086
1086
  packet.hash = this.hash(JSON.stringify(packet));
1087
+ this.state('hash_packet');
1088
+
1087
1089
  this.state('question_answer', packet); // set the question answer state
1090
+ this.talk(`${this._agent.key}:answer`, packet); // set the question answer state
1088
1091
  return resolve(packet); // resolve the packet to the caller.
1089
1092
  }).catch(err => { // catch any errors in the method
1090
1093
  return this.error(err, packet, reject); // return this.error with err, packet, reject
@@ -1147,11 +1150,18 @@ class Deva {
1147
1150
  error(err,data=false,reject=false) {
1148
1151
  this.state('error', {err, data}); // set the state to error
1149
1152
  // check fo rthe custom onError function in the agent.
1153
+ console.log('\n::BEGIN:ERROR\n');
1154
+ console.log(err);
1155
+ console.log('\n::END:ERROR\n');
1156
+ if (data) {
1157
+ console.log('::::::');
1158
+ console.log('\n::BEGIN:DATA\n');
1159
+ console.log(JSON.stringify(data, null, 2));
1160
+ console.log('\n::END:DATA\n');
1161
+ }
1162
+
1150
1163
  if (this.onError && typeof this.onError === 'function') return this.onError(err, data, reject);
1151
1164
  else {
1152
- console.log('\n::BEGIN:ERROR\n');
1153
- console.log(err);
1154
- console.log('\n::END:ERROR\n');
1155
1165
  return reject ? reject(err) : err;
1156
1166
  }
1157
1167
  }
@@ -1428,6 +1438,10 @@ class Deva {
1428
1438
  this.state('deva_load');
1429
1439
  this.devas[key].init(client).then(loaded => {
1430
1440
  this.state('deva_loaded');
1441
+ this.talk(`deva:load`, {
1442
+ key,
1443
+ created: Date.now(),
1444
+ });
1431
1445
  return resolve();
1432
1446
  }).catch(err => {
1433
1447
  return this.error(err, deva, reject);
@@ -1442,10 +1456,14 @@ class Deva {
1442
1456
  - deva: The deva key to unload
1443
1457
  describe: Unload a currently loaded Deva.
1444
1458
  ***************/
1445
- unload(deva) {
1459
+ unload(key) {
1446
1460
  this.state('deva_unload');
1447
- delete this.devas[deva];
1461
+ delete this.devas[key];
1448
1462
  this.state('deva_unloaded');
1463
+ this.talk(`deva:unload`, {
1464
+ key,
1465
+ created: Date.now(),
1466
+ });
1449
1467
  return Promise.resolve(`unload:${deva} `);
1450
1468
  }
1451
1469
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.1.33",
3
+ "version": "1.1.35",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "scripts": {