@indra.ai/deva 1.1.42 → 1.1.44

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 +27 -22
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -997,7 +997,7 @@ class Deva {
997
997
 
998
998
  const agent = this.agent() || false;
999
999
  const client = this.client() || false;
1000
- packet.a = { // setup the packet.a container
1000
+ const packet_answer = { // setup the packet.a container
1001
1001
  id: this.uid(),
1002
1002
  agent, // set the agent who answered the question
1003
1003
  client, // set the client asking the question
@@ -1014,8 +1014,9 @@ class Deva {
1014
1014
 
1015
1015
  // create a hash for the answer and insert into answer meta.
1016
1016
  this.action('answer_hash');
1017
- packet.a.meta.hash = this.hash(JSON.stringify(packet.a));
1017
+ packet_answer.meta.hash = this.hash(JSON.stringify(packet_answer));
1018
1018
 
1019
+ packet.a = this.copy(packet_answer);
1019
1020
  this.action('packet_hash');
1020
1021
  packet.hash = this.hash(JSON.stringify(packet)); // hash the entire packet.
1021
1022
 
@@ -1072,7 +1073,7 @@ class Deva {
1072
1073
  return setImmediate(() => {
1073
1074
  this.action('invalid')
1074
1075
  packet.a.text = `INVALID METHOD (${packet.q.meta.method})`;
1075
- this.talk(`${this._agent.key}:ask:${packet.id}`, packet);
1076
+ this.talk(`${this._agent.key}:ask:${packet.id}`, this.copy(packet));
1076
1077
  });
1077
1078
  }
1078
1079
 
@@ -1091,13 +1092,13 @@ class Deva {
1091
1092
  this.talk(`${this._agent.key}:ask:${packet.id}`, this.copy(packet));
1092
1093
  }).catch(err => {
1093
1094
  this.action('error');
1094
- this.talk(`${this._agent.key}:ask:${packet.id}`, {error:err.toString()});
1095
+ this.talk(`${this._agent.key}:ask:${packet.id}`, {error:err});
1095
1096
  return this.error(err, packet);
1096
1097
  })
1097
1098
  }
1098
1099
  catch (e) {
1099
1100
  this.action('error');
1100
- this.talk(`${this._agent.key}:ask:${packet.id}`, {error:e.toString()});
1101
+ this.talk(`${this._agent.key}:ask:${packet.id}`, {error:e});
1101
1102
  return this.error(e, packet)
1102
1103
  }
1103
1104
  // now when we ask the meta params[0] should be the method
@@ -1362,7 +1363,7 @@ class Deva {
1362
1363
  created: Date.now(),
1363
1364
  };
1364
1365
  _data.hash = this.hash(JSON.stringify(_data));
1365
- this.talk('zone', _data);
1366
+ this.talk('devacore:zone', this.copy(_data));
1366
1367
  } catch (e) {
1367
1368
  return this.error(e);
1368
1369
  }
@@ -1416,7 +1417,7 @@ class Deva {
1416
1417
  created: Date.now(),
1417
1418
  };
1418
1419
  _data.hash = this.hash(JSON.stringify(_data));
1419
- this.talk('feature', _data);
1420
+ this.talk('devacore:feature', this.copy(_data));
1420
1421
  } catch (e) {
1421
1422
  return this.error(e);
1422
1423
  }
@@ -1641,7 +1642,8 @@ class Deva {
1641
1642
  return new Promise((resolve, reject) => {
1642
1643
  this.state('load');
1643
1644
  this.devas[key].init(client).then(loaded => {
1644
- this.talk(`deva:load`, {
1645
+ this.talk(`devacore:load`, {
1646
+ id:this.uid(true),
1645
1647
  key,
1646
1648
  created: Date.now(),
1647
1649
  });
@@ -1662,14 +1664,17 @@ class Deva {
1662
1664
  return new Promise((resolve, reject) => {
1663
1665
  try {
1664
1666
  this.state('uload');
1665
- delete this.devas[key];
1666
- this.talk(`unload`, {
1667
- key,
1668
- created: Date.now(),
1667
+ this.devas[key].stop().then(exit => {
1668
+ delete this.devas[key];
1669
+ this.talk(`devacore:unload`, {
1670
+ id:this.uid(true),
1671
+ key,
1672
+ created: Date.now(),
1673
+ });
1669
1674
  });
1670
1675
  return resolve(this._messages.states.unload);
1671
1676
  } catch (e) {
1672
- return reject(e, this.devas[key], reject)
1677
+ return this.error(e, this.devas[key], reject)
1673
1678
  }
1674
1679
  });
1675
1680
  }
@@ -1797,15 +1802,16 @@ class Deva {
1797
1802
  ***************/
1798
1803
  prompt(text) {
1799
1804
  // Talk a global prompt event for the client
1800
- return this.talk('devacore:prompt', {
1801
- id: this.uid(),
1805
+ const _data = {
1806
+ id: this.uid(true),
1802
1807
  key: 'return',
1803
1808
  value: 'prompt',
1804
1809
  agent: this.agent(),
1805
1810
  client: this.client(),
1806
1811
  text,
1807
1812
  created: Date.now(),
1808
- });
1813
+ }
1814
+ return this.talk('devacore:prompt', this.copy(_data));
1809
1815
  }
1810
1816
 
1811
1817
 
@@ -1939,22 +1945,21 @@ class Deva {
1939
1945
  console.log('\n::END:DATA\n');
1940
1946
  }
1941
1947
 
1942
- this.talk('devacore:error', {
1948
+ const _data = {
1943
1949
  id: this.uid(true),
1944
1950
  key: 'return',
1945
1951
  value: 'error',
1946
1952
  agent: this.agent(),
1947
1953
  client: this.client(),
1948
- text: err.toString(),
1954
+ error: err,
1949
1955
  data,
1950
1956
  created: Date.now(),
1951
- });
1957
+ }
1958
+ this.talk('devacore:error', this.copy(_data));
1952
1959
 
1953
1960
  const hasOnError = this.onError && typeof this.onError === 'function' ? true : false;
1954
1961
  if (hasOnError) return this.onError(err, data, reject);
1955
- else {
1956
- return reject ? reject(err) : err;
1957
- }
1962
+ else return reject ? reject(err) : err;
1958
1963
  }
1959
1964
 
1960
1965
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.1.42",
3
+ "version": "1.1.44",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "scripts": {