@indra.ai/deva 1.57.0 → 1.59.2

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 +51 -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,11 @@ 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
+ const id = data.id?.uid || this._messages.noid; // check for proper id in the data.
407
+ for (const algo of this._config.hashes) {
408
+ this.action('delete', `${algo}:${id}`);
409
+ delete data[algo]
410
+ };
434
411
  return data;
435
412
  }
436
413
 
@@ -1009,18 +986,8 @@ class Deva {
1009
986
  data, // set the answer data
1010
987
  created: Date.now(), // set the created date for the answer
1011
988
  };
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
989
+ // stamp the packet_answer into packet.a
990
+ packet.a = this._stamp(packet_answer, `${key}:${method}:${subkey}`, id.uid); // set the packet.a to the packet_answer
1024
991
 
1025
992
  this.action('talk', `${this._events.answer}:${id.uid}`);
1026
993
  this.talk(this._events.answer, this.lib.copy(packet)); // global talk event
@@ -1108,46 +1075,26 @@ class Deva {
1108
1075
  this.state('set', `${key}:${method}:${sub_key}:result:${packet.id.uid}`);
1109
1076
  packet_answer.text = result;
1110
1077
  }
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
1078
 
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
1079
+ // stamp the packet_answer and set it into packet.a.
1080
+ this.state('set', `${key}:${method}:packet:a:${packet.id.uid}`);
1081
+ packet.a = this._stamp(packet_answer, `${key}:${method}:packet:a`, packet.id.uid); // set the packet answer.
1126
1082
 
1127
1083
  this.state('set', `${key}:${method}:packet:q:agent:${packet.id.uid}`);
1128
1084
  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
1085
 
1133
1086
  // 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
-
1087
+ const packet_stamped = this._stamp(this._unstamp(packet), `${key}:${method}:packet`, packet.id.uid);
1088
+
1142
1089
  this.action('talk', `${this._events.answer}:${key}:${method}:${packet.id.uid}`);
1143
1090
  this.state('valid', `${this._events.answer}:${key}:${method}:${packet.id.uid}`);
1144
1091
  this.intent('good', `${this._events.answer}:${key}:${method}:${packet.id.uid}`);
1145
- this.talk(this._events.answer, this.lib.copy(packet)); // global talk event
1092
+ this.talk(this._events.answer, this.lib.copy(packet_stamped)); // global talk event
1146
1093
 
1147
1094
  this.action('talk', `${agent.key}:${key}:${method}:${packet.id.uid}`);
1148
1095
  this.state('valid', `${agent.key}:${key}:${method}:${packet.id.uid}`);
1149
1096
  this.intent('good', `${agent.key}:${key}:${method}:${packet.id.uid}`);
1150
- this.talk(`${agent.key}:ask:${packet.id.uid}`, packet);
1097
+ this.talk(`${agent.key}:ask:${packet.id.uid}`, packet_stamped);
1151
1098
  }).catch(err => {
1152
1099
  this.action('talk', `${agent.key}:${key}:${method}:err:${packet.id.uid}`);
1153
1100
  this.state('catch', `${agent.key}:${key}:${method}:${packet.id.uid}`);
@@ -1571,12 +1518,10 @@ class Deva {
1571
1518
  created: Date.now(),
1572
1519
  };
1573
1520
 
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;
1521
+ const data_stamped = this._stamp(data, `context`, id.uid);
1522
+
1523
+ this.talk(this._events.context, this.lib.copy(data_stamped));
1524
+ return data_stamped;
1580
1525
  } catch (e) {
1581
1526
  this.state('catch', `context:${value}:${id.uid}`);
1582
1527
  return this.err(e, value);
@@ -1599,15 +1544,8 @@ class Deva {
1599
1544
  created: Date.now(),
1600
1545
  };
1601
1546
 
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;
1547
+ this.state('return', `${key}:${id.uid}`);
1548
+ return this._stamp(data, key, id.uid);
1611
1549
  }
1612
1550
 
1613
1551
  /**************
@@ -1666,7 +1604,7 @@ class Deva {
1666
1604
  describe: Returns a list of available actions in the system.
1667
1605
  ***************/
1668
1606
  actions() {
1669
- this._workflowItems('actions');
1607
+ return this._workflowItems('actions');
1670
1608
  }
1671
1609
 
1672
1610
  /**************
@@ -1723,7 +1661,7 @@ class Deva {
1723
1661
  describe: returns the available beliefs values.
1724
1662
  ***************/
1725
1663
  beliefs() {
1726
- return this._workflowItems('intents');
1664
+ return this._workflowItems('beliefs');
1727
1665
  }
1728
1666
 
1729
1667
  /**************
@@ -1752,11 +1690,12 @@ class Deva {
1752
1690
  client: this.client(), // set the client
1753
1691
  created: Date.now(), // set the data created date.
1754
1692
  };
1755
-
1693
+
1694
+ // manual hashing to avoid _stamp conflict at load.
1756
1695
  data.md5 = this.hash(data, 'md5');
1757
1696
  data.sha256 = this.hash(data, 'sha256');
1758
1697
  data.sha512 = this.hash(data, 'sha512');
1759
-
1698
+
1760
1699
  this.talk(this._events[key], this.lib.copy(data)); // broadcast the state event
1761
1700
  return data;
1762
1701
  } catch (e) { // catch any errors
@@ -1773,7 +1712,7 @@ class Deva {
1773
1712
  if (!this._active) return this._messages.offline;
1774
1713
  const id = this.uid(); // set the current uid
1775
1714
  this.action(key, id.uid); // set the action to the passed key
1776
- const value = this[_key]; // get the _keys value
1715
+ const value = this[`_${key}`]; // get the _keys value
1777
1716
  // set the data packet for the states
1778
1717
  this.state('data', `${key}:${id.uid}`);
1779
1718
  const data = {
@@ -1785,15 +1724,8 @@ class Deva {
1785
1724
  created: Date.now(),
1786
1725
  }
1787
1726
 
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
1727
  this.action('return', `${data.key}:${id.uid}`);
1796
- return data;
1728
+ return this._stamp(data, data.key, id.uid);
1797
1729
  }
1798
1730
 
1799
1731
  /**************
@@ -1805,6 +1737,7 @@ class Deva {
1805
1737
  client() {
1806
1738
  if (!this._active) return this._messages.offline; // check the active status
1807
1739
  const data = this.lib.copy(this._client); // create a copy of the client data
1740
+ // manual hashing here to prevent stack overflow with this._stamp.
1808
1741
  data.md5 = this.hash(data, 'md5');
1809
1742
  data.sha256 = this.hash(data, 'sha256');
1810
1743
  data.sha512 = this.hash(data, 'sha512');
@@ -1820,6 +1753,7 @@ class Deva {
1820
1753
  agent() {
1821
1754
  if (!this._active) return this._messages.offline; // check the active status
1822
1755
  const data = this.lib.copy(this._agent); // create a copy of the agent data.
1756
+ // manual hashing here to prevent stack overflow with this._stamp.
1823
1757
  data.md5 = this.hash(data, 'md5');
1824
1758
  data.sha256 = this.hash(data, 'sha256');
1825
1759
  data.sha512 = this.hash(data, 'sha512');
@@ -2085,20 +2019,15 @@ class Deva {
2085
2019
  created: Date.now(),
2086
2020
  }
2087
2021
 
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
2022
+ // stamp the data
2023
+ const data_stamped = this._stamp(data, `${key}:${value}`, data.id.uid);
2096
2024
 
2025
+ // talk the prompt event to anyone listening
2097
2026
  this.action('talk', `${key}:${value}:${id.uid}`);
2098
- this.talk(this._events.prompt, data);
2027
+ this.talk(this._events.prompt, data_stamped);
2099
2028
 
2100
2029
  this.action('return', `${key}:${value}:${id.uid}`);
2101
- return data;
2030
+ return data_stamped;
2102
2031
  }
2103
2032
 
2104
2033
  /**************
@@ -2115,18 +2044,10 @@ class Deva {
2115
2044
  const data = this.lib.copy(this._core);
2116
2045
  data.id = id;
2117
2046
  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
2047
 
2127
2048
  this.action('return', `core:${id.uid}`);
2128
2049
  this.intent('good', `core:${id.uid}`);
2129
- return data;
2050
+ return this._stamp(this._unstamp(data), 'core', data.id.uid);
2130
2051
  }
2131
2052
 
2132
2053
  // machine returns the sha256 machine fingerprint
@@ -2145,6 +2066,7 @@ class Deva {
2145
2066
  cpus: os.cpus(),
2146
2067
  created: Date.now(),
2147
2068
  };
2069
+ // machine has to do manual hashing to prevent stack overflow.
2148
2070
  data.md5 = this.hash(data, 'md5');
2149
2071
  data.sha256 = this.hash(data, 'sha256');
2150
2072
  data.sha512 = this.hash(data, 'sha512');
@@ -2161,16 +2083,9 @@ class Deva {
2161
2083
  const data = this.lib.copy(this._info);
2162
2084
  data.created = Date.now();
2163
2085
 
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
2086
  this.action('return', `info:${data.id}`);
2172
2087
  this.intent('good', `info:${data.id}`);
2173
- return data;
2088
+ return this._stamp(data, 'info', data.id);
2174
2089
  }
2175
2090
 
2176
2091
  /**************
@@ -2309,21 +2224,13 @@ class Deva {
2309
2224
  },
2310
2225
  packet,
2311
2226
  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
2227
+ };
2228
+ // stamp the data before return
2229
+ const data_stamped = this._stamp(data, `${data.key}:${data.value}`, data.id.uid);
2323
2230
 
2324
2231
  // set the action to talk and emit the talk error.
2325
2232
  this.action('talk', `${this._events.error}:${data.id.uid}`);
2326
- this.talk(this._events.error, this.lib.copy(data));
2233
+ this.talk(this._events.error, this.lib.copy(data_stamped));
2327
2234
 
2328
2235
  const hasOnError = this.onError && typeof this.onError === 'function' ? true : false;
2329
2236
  // if block handles returning the onError and setting the state to hasOnError
@@ -2422,6 +2329,7 @@ class Deva {
2422
2329
  const uid = `${begin_random}${end_random}`; // set uid to local constant
2423
2330
  data.uid = uid; // set base data object.
2424
2331
  }
2332
+ // manual hashing to prevent overflow on stack calls.
2425
2333
  data.md5 = this.hash(data, 'md5'); // md5 the uid and created.
2426
2334
  data.sha256 = this.hash(data, 'sha256'); // sha256 the uid, created, md5
2427
2335
  data.sha512 = this.hash(data, 'sha512'); // sha512 the uid, created, md5, sha256.
@@ -2499,18 +2407,9 @@ class Deva {
2499
2407
  copyright,
2500
2408
  };
2501
2409
 
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
2410
  this.action('return', `${data.key}:sign:${data.id.uid}`);
2512
2411
  this.intent('good', `${data.key}:sign:${data.id.uid}`);
2513
- return data;
2412
+ return this._stamp(data, 'sign', data.id.uid);
2514
2413
  }
2515
2414
 
2516
2415
  /**************
@@ -2550,13 +2449,10 @@ class Deva {
2550
2449
  personal: personalVLA_hash,
2551
2450
  package: packageVLA_hash,
2552
2451
  };
2553
- approved.md5 = this.hash(approved, 'md5');
2554
- approved.sha256 = this.hash(approved, 'sha256');
2555
- approved.sha512 = this.hash(approved, 'sha512');
2556
2452
 
2557
2453
  this.state('return', `license:${packageVLA.uid}`);
2558
2454
  this.intent('good', `license:${packageVLA.uid}`);
2559
- return approved;
2455
+ return this._stamp(approved, 'license_check', packageVLA.uid);
2560
2456
  }
2561
2457
 
2562
2458
  /**************
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.2",
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",