@indra.ai/deva 1.57.0 → 1.59.0

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 +50 -155
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -283,7 +283,7 @@ class Deva {
283
283
  const client = this.client() || false;
284
284
  const {meta, params} = packet.q;
285
285
  const text = `${this._messages.method_not_found} ${agent.key} ${meta.method}`
286
- packet.a = {
286
+ const packet_answer = {
287
287
  id,
288
288
  agent,
289
289
  client,
@@ -294,22 +294,11 @@ class Deva {
294
294
  },
295
295
  created: Date.now(),
296
296
  };
297
+ // set packet into packet.a after stamping it.
298
+ packet.a = this._stamp(packet_answer);
297
299
 
298
- this.action('hash', `md5:${packet.a.id.uid}`);
299
- packet.a.md5 = this.hash(packet.a, 'md5');
300
- this.action('hash', `sha256:${packet.a.id.uid}`);
301
- packet.a.sha256 = this.hash(packet.a, 'sha256');
302
- this.action('hash', `sha512:${packet.a.id.uid}`);
303
- packet.a.sha512 = this.hash(packet.a, 'sha512');
304
-
305
- delete packet.md5;
306
- delete packet.sha256;
307
- delete packet.sha512;
308
-
309
- packet.md5 = this.hash(packet, 'md5');
310
- packet.sha256 = this.hash(packet, 'sha256');
311
- packet.sha512 = this.hash(packet, 'sha512');
312
-
300
+ // stamp the packet before return
301
+ const packet_stamped = this._stamp(this._unstamp(packet), `methodNotFound:${meta.method}`, packet.id.uid);
313
302
  this.state('invalid', `${meta.method}:${packet.id.uid}`);
314
303
  return packet;
315
304
  }
@@ -355,28 +344,12 @@ class Deva {
355
344
  this.zone(key, data.id.uid);
356
345
  this.action(key, data.id.uid);
357
346
  this.state(key, data.id.uid);
358
-
359
- this.action('delete', `${key}:md5:${data.id.uid}`);
360
- delete data.md5;
361
-
362
- this.action('delete', `${key}:sha256:${data.id.uid}`);
363
- delete data.sha256;
364
-
365
- this.action('delete', `${key}:sha512:${data.id.uid}`);
366
- delete data.sha512;
367
-
347
+
368
348
  this.state('data', `${key}:date:${data.id.uid}`);
369
349
  data[key] = Date.now();// set the complete date on the whole data.
370
350
 
371
- this.action('hash', `${key}:md5:${data.id.uid}`);
372
- data.md5 = this.hash(data, 'md5');
351
+ const data_stamped = this._stamp(this._unstamp(data), key, data.id.uid);
373
352
 
374
- this.action('hash', `${key}:sha256:${data.id.uid}`)
375
- data.sha256 = this.hash(data, 'sha256');
376
-
377
- this.action('hash', `${key}:sha512:${data.id.uid}`)
378
- data.sha512 = this.hash(data, 'sha512');
379
-
380
353
  // setup the complete talk event
381
354
  this.action('talk', `${this._events[key]}:${data.id.uid}`); // action talk for the event.
382
355
  this.talk(this._events[key], this.lib.copy(data)); // talk the complete event
@@ -430,7 +403,10 @@ class Deva {
430
403
  usage: this._unstamp(data)
431
404
  ***************/
432
405
  _unstamp(data) {
433
- for (const algo of this._config.hashes) delete data[algo];
406
+ for (const algo of this._config.hashes) {
407
+ this.action('delete', `${algo}:${data.id.uid}`);
408
+ delete data[algo]
409
+ };
434
410
  return data;
435
411
  }
436
412
 
@@ -1009,18 +985,8 @@ class Deva {
1009
985
  data, // set the answer data
1010
986
  created: Date.now(), // set the created date for the answer
1011
987
  };
1012
- // create a hash for the answer and insert into answer meta.
1013
- this.action('hash', `${key}:${method}:${subkey}:md5:${id.uid}`);
1014
- packet_answer.md5 = this.hash(packet_answer, 'md5');
1015
-
1016
- this.action('hash', `${key}:${method}:${subkey}:sha256:${id.uid}`);
1017
- packet_answer.sha256 = this.hash(packet_answer, 'sha256');
1018
-
1019
- this.action('hash', `${key}:${method}:${subkey}:sha512:${id.uid}`);
1020
- packet_answer.sha512 = this.hash(packet_answer, 'sha512');
1021
-
1022
- this.state('set', `${key}:${method}:${subkey}:${id.uid}`);
1023
- packet.a = packet_answer; // set the packet.a to the packet_answer
988
+ // stamp the packet_answer into packet.a
989
+ packet.a = this._stamp(packet_answer, `${key}:${method}:${subkey}`, id.uid); // set the packet.a to the packet_answer
1024
990
 
1025
991
  this.action('talk', `${this._events.answer}:${id.uid}`);
1026
992
  this.talk(this._events.answer, this.lib.copy(packet)); // global talk event
@@ -1108,46 +1074,26 @@ class Deva {
1108
1074
  this.state('set', `${key}:${method}:${sub_key}:result:${packet.id.uid}`);
1109
1075
  packet_answer.text = result;
1110
1076
  }
1111
-
1112
- // delete previous hashes before creating new ones.
1113
- this.action('delete', `${key}:${method}:packet:md5:${packet.id.uid}`);
1114
- delete packet.md5;
1115
- this.action('delete', `${key}:${method}:packet:sha256:${packet.id.uid}`);
1116
- delete packet.sha256;
1117
- this.action('delete', `${key}:${method}:packet:sha512:${packet.id.uid}`);
1118
- delete packet.sha512;
1119
1077
 
1120
- this.action('hash', `${key}:${method}:${sub_key}:md5:${packet.id.uid}`);
1121
- packet_answer.md5 = this.hash(packet_answer, 'md5'); // md5 the answer.
1122
- this.action('hash', `${key}:${method}:${sub_key}:sha256:${packet.id.uid}`);
1123
- packet_answer.sha256 = this.hash(packet_answer, 'sha256'); // sha256 the answer.
1124
- this.action('hash', `${key}:${method}:${sub_key}:sha512:${packet.id.uid}`);
1125
- packet_answer.sha512 = this.hash(packet_answer, 'sha512'); // sha512 the answer
1078
+ // stamp the packet_answer and set it into packet.a.
1079
+ this.state('set', `${key}:${method}:packet:a:${packet.id.uid}`);
1080
+ packet.a = this._stamp(packet_answer, `${key}:${method}:packet:a`, packet.id.uid); // set the packet answer.
1126
1081
 
1127
1082
  this.state('set', `${key}:${method}:packet:q:agent:${packet.id.uid}`);
1128
1083
  packet.q.agent = agent; // set the question agent as the ask agent.
1129
-
1130
- this.state('set', `${key}:${method}:packet:a:${packet.id.uid}`);
1131
- packet.a = packet_answer; // set the packet answer.
1132
1084
 
1133
1085
  // create new hashes for the packet before return.
1134
- // delete previous hashes before creating new ones.
1135
- this.action('hash', `${key}:${method}:packet:md5:${packet.id.uid}`);
1136
- packet.md5 = this.hash(packet, 'md5');
1137
- this.action('hash', `${key}:${method}:packet:sha256:${packet.id.uid}`);
1138
- packet.sha256 = this.hash(packet, 'sha256');
1139
- this.action('hash', `${key}:${method}:packet:sha512:${packet.id.uid}`);
1140
- packet.sha512 = this.hash(packet, 'sha512');
1141
-
1086
+ const packet_stamped = this._stamp(this._unstamp(packet), `${key}:${method}:packet`, packet.id.uid);
1087
+
1142
1088
  this.action('talk', `${this._events.answer}:${key}:${method}:${packet.id.uid}`);
1143
1089
  this.state('valid', `${this._events.answer}:${key}:${method}:${packet.id.uid}`);
1144
1090
  this.intent('good', `${this._events.answer}:${key}:${method}:${packet.id.uid}`);
1145
- this.talk(this._events.answer, this.lib.copy(packet)); // global talk event
1091
+ this.talk(this._events.answer, this.lib.copy(packet_stamped)); // global talk event
1146
1092
 
1147
1093
  this.action('talk', `${agent.key}:${key}:${method}:${packet.id.uid}`);
1148
1094
  this.state('valid', `${agent.key}:${key}:${method}:${packet.id.uid}`);
1149
1095
  this.intent('good', `${agent.key}:${key}:${method}:${packet.id.uid}`);
1150
- this.talk(`${agent.key}:ask:${packet.id.uid}`, packet);
1096
+ this.talk(`${agent.key}:ask:${packet.id.uid}`, packet_stamped);
1151
1097
  }).catch(err => {
1152
1098
  this.action('talk', `${agent.key}:${key}:${method}:err:${packet.id.uid}`);
1153
1099
  this.state('catch', `${agent.key}:${key}:${method}:${packet.id.uid}`);
@@ -1571,12 +1517,10 @@ class Deva {
1571
1517
  created: Date.now(),
1572
1518
  };
1573
1519
 
1574
- data.md5 = this.hash(data, 'md5');
1575
- data.sha256 = this.hash(data, 'sha256');
1576
- data.sha512 = this.hash(data, 'sha512');
1577
-
1578
- this.talk(this._events.context, this.lib.copy(data));
1579
- return data;
1520
+ const data_stamped = this._stamp(data, `context`, id.uid);
1521
+
1522
+ this.talk(this._events.context, this.lib.copy(data_stamped));
1523
+ return data_stamped;
1580
1524
  } catch (e) {
1581
1525
  this.state('catch', `context:${value}:${id.uid}`);
1582
1526
  return this.err(e, value);
@@ -1599,15 +1543,8 @@ class Deva {
1599
1543
  created: Date.now(),
1600
1544
  };
1601
1545
 
1602
- this.action('hash', `${data.key}:md5:${data.id.uid}`);
1603
- data.md5 = this.hash(data, 'md5');
1604
- this.action('hash', `${data.key}:sha256:${data.id.uid}`);
1605
- data.sha256 = this.hash(data, 'sha256');
1606
- this.action('hash', `${data.key}:sha512:${data.id.uid}`);
1607
- data.sha512 = this.hash(data, 'sha512');
1608
-
1609
- this.state('return', `${data.key}:${id.uid}`);
1610
- return data;
1546
+ this.state('return', `${key}:${id.uid}`);
1547
+ return this._stamp(data, key, id.uid);
1611
1548
  }
1612
1549
 
1613
1550
  /**************
@@ -1666,7 +1603,7 @@ class Deva {
1666
1603
  describe: Returns a list of available actions in the system.
1667
1604
  ***************/
1668
1605
  actions() {
1669
- this._workflowItems('actions');
1606
+ return this._workflowItems('actions');
1670
1607
  }
1671
1608
 
1672
1609
  /**************
@@ -1723,7 +1660,7 @@ class Deva {
1723
1660
  describe: returns the available beliefs values.
1724
1661
  ***************/
1725
1662
  beliefs() {
1726
- return this._workflowItems('intents');
1663
+ return this._workflowItems('beliefs');
1727
1664
  }
1728
1665
 
1729
1666
  /**************
@@ -1752,11 +1689,12 @@ class Deva {
1752
1689
  client: this.client(), // set the client
1753
1690
  created: Date.now(), // set the data created date.
1754
1691
  };
1755
-
1692
+
1693
+ // manual hashing to avoid _stamp conflict at load.
1756
1694
  data.md5 = this.hash(data, 'md5');
1757
1695
  data.sha256 = this.hash(data, 'sha256');
1758
1696
  data.sha512 = this.hash(data, 'sha512');
1759
-
1697
+
1760
1698
  this.talk(this._events[key], this.lib.copy(data)); // broadcast the state event
1761
1699
  return data;
1762
1700
  } catch (e) { // catch any errors
@@ -1773,7 +1711,7 @@ class Deva {
1773
1711
  if (!this._active) return this._messages.offline;
1774
1712
  const id = this.uid(); // set the current uid
1775
1713
  this.action(key, id.uid); // set the action to the passed key
1776
- const value = this[_key]; // get the _keys value
1714
+ const value = this[`_${key}`]; // get the _keys value
1777
1715
  // set the data packet for the states
1778
1716
  this.state('data', `${key}:${id.uid}`);
1779
1717
  const data = {
@@ -1785,15 +1723,8 @@ class Deva {
1785
1723
  created: Date.now(),
1786
1724
  }
1787
1725
 
1788
- this.action('hash', `${data.key}:md5:${data.id.uid}`);
1789
- data.md5 = this.hash(data, 'md5');
1790
- this.action('hash', `${data.key}:sha256:${data.id.uid}`);
1791
- data.sha256 = this.hash(data, 'sha256');
1792
- this.action('hash', `${data.key}:sha512:${data.id.uid}`);
1793
- data.sha512 = this.hash(data, 'sha512');
1794
-
1795
1726
  this.action('return', `${data.key}:${id.uid}`);
1796
- return data;
1727
+ return this._stamp(data, data.key, id.uid);
1797
1728
  }
1798
1729
 
1799
1730
  /**************
@@ -1805,6 +1736,7 @@ class Deva {
1805
1736
  client() {
1806
1737
  if (!this._active) return this._messages.offline; // check the active status
1807
1738
  const data = this.lib.copy(this._client); // create a copy of the client data
1739
+ // manual hashing here to prevent stack overflow with this._stamp.
1808
1740
  data.md5 = this.hash(data, 'md5');
1809
1741
  data.sha256 = this.hash(data, 'sha256');
1810
1742
  data.sha512 = this.hash(data, 'sha512');
@@ -1820,6 +1752,7 @@ class Deva {
1820
1752
  agent() {
1821
1753
  if (!this._active) return this._messages.offline; // check the active status
1822
1754
  const data = this.lib.copy(this._agent); // create a copy of the agent data.
1755
+ // manual hashing here to prevent stack overflow with this._stamp.
1823
1756
  data.md5 = this.hash(data, 'md5');
1824
1757
  data.sha256 = this.hash(data, 'sha256');
1825
1758
  data.sha512 = this.hash(data, 'sha512');
@@ -2085,20 +2018,15 @@ class Deva {
2085
2018
  created: Date.now(),
2086
2019
  }
2087
2020
 
2088
- this.action('hash', `${key}:${value}:md5:${data.id.uid}`);
2089
- data.md5 = this.hash(data, 'md5'); // md5 the data packet
2090
-
2091
- this.action('hash', `${key}:${value}:sha256:${data.id.uid}`);
2092
- data.sha256 = this.hash(data, 'sha256'); // sha256 the data packet
2093
-
2094
- this.action('hash', `${key}:${value}:sha512:${data.id.uid}`);
2095
- data.sha512 = this.hash(data, 'sha512'); // sha512 the data packet
2021
+ // stamp the data
2022
+ const data_stamped = this._stamp(data, `${key}:${value}`, data.id.uid);
2096
2023
 
2024
+ // talk the prompt event to anyone listening
2097
2025
  this.action('talk', `${key}:${value}:${id.uid}`);
2098
- this.talk(this._events.prompt, data);
2026
+ this.talk(this._events.prompt, data_stamped);
2099
2027
 
2100
2028
  this.action('return', `${key}:${value}:${id.uid}`);
2101
- return data;
2029
+ return data_stamped;
2102
2030
  }
2103
2031
 
2104
2032
  /**************
@@ -2115,18 +2043,10 @@ class Deva {
2115
2043
  const data = this.lib.copy(this._core);
2116
2044
  data.id = id;
2117
2045
  data.created = Date.now();
2118
-
2119
- delete data.md5; // delete old md5 hash
2120
- delete data.sha256; // delete old sha256 hash
2121
- delete data.sha512; // delete old sha512 hash
2122
-
2123
- data.md5 = this.hash(data, 'md5');
2124
- data.sha256 = this.hash(data, 'sha256');
2125
- data.sha512 = this.hash(data, 'sha512');
2126
2046
 
2127
2047
  this.action('return', `core:${id.uid}`);
2128
2048
  this.intent('good', `core:${id.uid}`);
2129
- return data;
2049
+ return this._stamp(this._unstamp(data), 'core', data.id.uid);
2130
2050
  }
2131
2051
 
2132
2052
  // machine returns the sha256 machine fingerprint
@@ -2145,6 +2065,7 @@ class Deva {
2145
2065
  cpus: os.cpus(),
2146
2066
  created: Date.now(),
2147
2067
  };
2068
+ // machine has to do manual hashing to prevent stack overflow.
2148
2069
  data.md5 = this.hash(data, 'md5');
2149
2070
  data.sha256 = this.hash(data, 'sha256');
2150
2071
  data.sha512 = this.hash(data, 'sha512');
@@ -2161,16 +2082,9 @@ class Deva {
2161
2082
  const data = this.lib.copy(this._info);
2162
2083
  data.created = Date.now();
2163
2084
 
2164
- this.action('hash', `info:md5:${data.id}`);
2165
- data.md5 = this.hash(data, 'md5');
2166
- this.action('hash', `info:sha256:${data.id}`);
2167
- data.sha256 = this.hash(data, 'sha256');
2168
- this.action('hash', `info:sha512:${data.id}`);
2169
- data.sha512 = this.hash(data, 'sha512');
2170
-
2171
2085
  this.action('return', `info:${data.id}`);
2172
2086
  this.intent('good', `info:${data.id}`);
2173
- return data;
2087
+ return this._stamp(data, 'info', data.id);
2174
2088
  }
2175
2089
 
2176
2090
  /**************
@@ -2309,21 +2223,13 @@ class Deva {
2309
2223
  },
2310
2224
  packet,
2311
2225
  created: Date.now(),
2312
- }
2313
-
2314
- this.action('hash', `${data.key}:${data.value}:md5:${data.id.uid}`);
2315
- data.md5 = this.hash(data, 'md5'); // md5 the data packet
2316
-
2317
- this.action('hash', `${data.key}:${data.value}:sha256:${data.id.uid}`);
2318
- data.sha256 = this.hash(data, 'sha256'); // sha256 the data packet
2319
-
2320
-
2321
- this.action('hash', `${data.key}:${data.value}:sha512:${data.id.uid}`);
2322
- data.sha512 = this.hash(data, 'sha512'); // sha512 the data packet
2226
+ };
2227
+ // stamp the data before return
2228
+ const data_stamped = this._stamp(data, `${data.key}:${data.value}`, data.id.uid);
2323
2229
 
2324
2230
  // set the action to talk and emit the talk error.
2325
2231
  this.action('talk', `${this._events.error}:${data.id.uid}`);
2326
- this.talk(this._events.error, this.lib.copy(data));
2232
+ this.talk(this._events.error, this.lib.copy(data_stamped));
2327
2233
 
2328
2234
  const hasOnError = this.onError && typeof this.onError === 'function' ? true : false;
2329
2235
  // if block handles returning the onError and setting the state to hasOnError
@@ -2422,6 +2328,7 @@ class Deva {
2422
2328
  const uid = `${begin_random}${end_random}`; // set uid to local constant
2423
2329
  data.uid = uid; // set base data object.
2424
2330
  }
2331
+ // manual hashing to prevent overflow on stack calls.
2425
2332
  data.md5 = this.hash(data, 'md5'); // md5 the uid and created.
2426
2333
  data.sha256 = this.hash(data, 'sha256'); // sha256 the uid, created, md5
2427
2334
  data.sha512 = this.hash(data, 'sha512'); // sha512 the uid, created, md5, sha256.
@@ -2499,18 +2406,9 @@ class Deva {
2499
2406
  copyright,
2500
2407
  };
2501
2408
 
2502
- this.action('hash', `${data.key}:sign:md5:${data.id.uid}`);
2503
- data.md5 = this.hash(data, 'md5'); // hash data packet into md5 and inert into data.
2504
-
2505
- this.action('hash', `${data.key}:sign:sha256:${data.id.uid}`);
2506
- data.sha256 = this.hash(data, 'sha256'); // hash data into sha 256 then set in data.
2507
-
2508
- this.action('hash', `${data.key}:sign:sha512:${data.id.uid}`);
2509
- data.sha512 = this.hash(data, 'sha512'); // hash data into sha 512 then set in data.
2510
-
2511
2409
  this.action('return', `${data.key}:sign:${data.id.uid}`);
2512
2410
  this.intent('good', `${data.key}:sign:${data.id.uid}`);
2513
- return data;
2411
+ return this._stamp(data, 'sign', data.id.uid);
2514
2412
  }
2515
2413
 
2516
2414
  /**************
@@ -2550,13 +2448,10 @@ class Deva {
2550
2448
  personal: personalVLA_hash,
2551
2449
  package: packageVLA_hash,
2552
2450
  };
2553
- approved.md5 = this.hash(approved, 'md5');
2554
- approved.sha256 = this.hash(approved, 'sha256');
2555
- approved.sha512 = this.hash(approved, 'sha512');
2556
2451
 
2557
2452
  this.state('return', `license:${packageVLA.uid}`);
2558
2453
  this.intent('good', `license:${packageVLA.uid}`);
2559
- return approved;
2454
+ return this._stamp(approved, 'license_check', packageVLA.uid);
2560
2455
  }
2561
2456
 
2562
2457
  /**************
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "23221940810208468106",
3
3
  "name": "@indra.ai/deva",
4
- "version": "1.57.0",
4
+ "version": "1.59.0",
5
5
  "description": "Deva Core a Vedic-inspired Event Based Context Aware Feature, Zone, Action, and State Machine integrated Artificial Intelligence Framework",
6
6
  "main": "index.js",
7
7
  "license": "VLA:23221940810208468106 LICENSE.md",