@indra.ai/deva 1.1.65 → 1.1.67

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 -20
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -952,12 +952,12 @@ class Deva {
952
952
  packet.q.meta.hash = this.hash(packet.q, 'sha256');
953
953
 
954
954
  this.action(_action);
955
- this.talk('devacore:question', this.copy(packet)); // global question event make sure to copy data.
955
+ this.talk('devacore:question', packet); // global question event make sure to copy data.
956
956
 
957
957
  if (isAsk) { // isAsk check if the question isAsk and talk
958
958
  this.state('ask');
959
959
  // if: isAsk wait for the once event which is key'd to the packet ID for specified responses
960
- this.talk(`${key}:ask`, this.copy(packet));
960
+ this.talk(`${key}:ask`, packet);
961
961
  this.once(`${key}:ask:${packet.id}`, answer => {
962
962
  this.action('question_ask_answer');
963
963
  return resolve(answer); // if:isAsk resolve the answer from the call
@@ -1031,7 +1031,7 @@ class Deva {
1031
1031
 
1032
1032
 
1033
1033
  this.action('answer_talk');
1034
- this.talk('devacore:answer', this.copy(packet)); // talk the answer with a copy of the data
1034
+ this.talk('devacore:answer', packet); // talk the answer with a copy of the data
1035
1035
 
1036
1036
  return resolve(packet); // resolve the packet to the caller.
1037
1037
  }).catch(err => { // catch any errors in the method
@@ -1082,7 +1082,7 @@ class Deva {
1082
1082
  return setImmediate(() => {
1083
1083
  this.action('invalid')
1084
1084
  packet.a.text = `INVALID METHOD (${packet.q.meta.method})`;
1085
- this.talk(`${this._agent.key}:ask:${packet.id}`, this.copy(packet));
1085
+ this.talk(`${this._agent.key}:ask:${packet.id}`, packet);
1086
1086
  });
1087
1087
  }
1088
1088
 
@@ -1098,7 +1098,7 @@ class Deva {
1098
1098
  packet.a.text = result;
1099
1099
  }
1100
1100
  this.action('ask_answer');
1101
- this.talk(`${this._agent.key}:ask:${packet.id}`, this.copy(packet));
1101
+ this.talk(`${this._agent.key}:ask:${packet.id}`, packet);
1102
1102
  }).catch(err => {
1103
1103
  this.action('error');
1104
1104
  this.talk(`${this._agent.key}:ask:${packet.id}`, {error:err});
@@ -1345,7 +1345,7 @@ class Deva {
1345
1345
  created: Date.now(),
1346
1346
  };
1347
1347
  _data.hash = this.hash(_data, 'sha256');
1348
- this.talk('devacore:state', this.copy(_data));
1348
+ this.talk('devacore:state', _data);
1349
1349
  } catch (e) {
1350
1350
  return this.error(e);
1351
1351
  }
@@ -1372,7 +1372,7 @@ class Deva {
1372
1372
  created: Date.now(),
1373
1373
  };
1374
1374
  _data.hash = this.hash(_data, 'sha256');
1375
- this.talk('devacore:zone', this.copy(_data));
1375
+ this.talk('devacore:zone', _data);
1376
1376
  } catch (e) {
1377
1377
  return this.error(e);
1378
1378
  }
@@ -1399,7 +1399,7 @@ class Deva {
1399
1399
  created: Date.now(),
1400
1400
  };
1401
1401
  _data.hash = this.hash(_data, 'sha256');
1402
- this.talk('devacore:action', this.copy(_data));
1402
+ this.talk('devacore:action', _data);
1403
1403
  } catch (e) {
1404
1404
  return this.error(e)
1405
1405
  }
@@ -1426,7 +1426,7 @@ class Deva {
1426
1426
  created: Date.now(),
1427
1427
  };
1428
1428
  _data.hash = this.hash(_data, 'sha256');
1429
- this.talk('devacore:feature', this.copy(_data));
1429
+ this.talk('devacore:feature', _data);
1430
1430
  } catch (e) {
1431
1431
  return this.error(e);
1432
1432
  }
@@ -1829,7 +1829,7 @@ class Deva {
1829
1829
  text,
1830
1830
  created: Date.now(),
1831
1831
  }
1832
- return this.talk('devacore:prompt', this.copy(_data));
1832
+ return this.talk('devacore:prompt', _data);
1833
1833
  }
1834
1834
 
1835
1835
 
@@ -1843,15 +1843,7 @@ class Deva {
1843
1843
  for copying.
1844
1844
  ***************/
1845
1845
  copy(obj) {
1846
- function walkData(data) {
1847
- const output = Array.isArray(data) ? [] : {};
1848
- let v, key;
1849
- for (key in data) {
1850
- v = obj[key];
1851
- output[key] = (typeof v === "object") ? walkData(v) : v;
1852
- }
1853
- }
1854
- return walkData(obj);
1846
+ return JSON.parse(JSON.stringify(obj));
1855
1847
  }
1856
1848
 
1857
1849
  /**************
@@ -1975,7 +1967,7 @@ class Deva {
1975
1967
  data,
1976
1968
  created: Date.now(),
1977
1969
  }
1978
- this.talk('devacore:error', this.copy(_data));
1970
+ this.talk('devacore:error', _data);
1979
1971
 
1980
1972
  const hasOnError = this.onError && typeof this.onError === 'function' ? true : false;
1981
1973
  if (hasOnError) return this.onError(err, data, reject);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.1.65",
3
+ "version": "1.1.67",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "scripts": {