@indra.ai/deva 1.1.94 → 1.1.96

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 +99 -79
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -780,16 +780,15 @@ class Deva {
780
780
  this.talk(config.events.question, this.copy(packet)); // global question event make sure to copy data.
781
781
 
782
782
  if (isAsk) { // isAsk check if the question isAsk and talk
783
- this.state('ask');
784
783
  // if: isAsk wait for the once event which is key'd to the packet ID for specified responses
785
784
  this.talk(`${key}:ask`, packet);
786
785
  this.once(`${key}:ask:${packet.id}`, answer => {
787
786
  this.action('question_ask_answer');
788
- return resolve(answer); // if:isAsk resolve the answer from the call
787
+ return this.finish(answer, resolve); // if:isAsk resolve the answer from the call
789
788
  });
790
789
  }
791
790
  else { // else: answer tue question locally
792
- this.action('ask_answer');
791
+ this.action('question_answer');
793
792
  return this.answer(packet, resolve, reject);
794
793
  }
795
794
  }
@@ -938,26 +937,6 @@ class Deva {
938
937
  // now when we ask the meta params[0] should be the method
939
938
  }
940
939
 
941
- info(id=false) {
942
- id = id || this._id;
943
- const agent = this.agent();
944
- if (this._info) {
945
- const _info = [
946
- `::begin:info:${id}`,
947
- `## ${this._agent.profile.name} (#${agent.key})`,
948
- ];
949
- for (let x in this._info) {
950
- _info.push(`- ${x}: ${this._info[x]}`);
951
- }
952
- _info.push(`::end:info:${this.hash(this._info)}`);
953
- return _info.join('\n');
954
- }
955
- else {
956
- return '';
957
- }
958
- }
959
-
960
-
961
940
 
962
941
  /**************
963
942
  func: init
@@ -1024,8 +1003,8 @@ class Deva {
1024
1003
  usage: this.start('msg')
1025
1004
  ***************/
1026
1005
  start(data) {
1027
- this.state('start');
1028
1006
  if (!this._active) return Promise.resolve(this._messages.states.offline);
1007
+ this.state('start');
1029
1008
  data.value = 'start';
1030
1009
  delete data.hash;
1031
1010
  data.hash = this.hash(data);
@@ -1052,8 +1031,8 @@ class Deva {
1052
1031
  usage: this.enter('msg')
1053
1032
  ***************/
1054
1033
  enter(data) {
1055
- this.state('enter');
1056
1034
  if (!this._active) return Promise.resolve(this._messages.states.offline);
1035
+ this.state('enter');
1057
1036
  data.value = 'enter';
1058
1037
  delete data.hash;
1059
1038
  data.hash = this.hash(data);
@@ -1073,9 +1052,28 @@ class Deva {
1073
1052
  If the deva is offline it will return the offline message.
1074
1053
  usage: this.done('msg')
1075
1054
  ***************/
1076
- done(data=false) {
1055
+ done(data) {
1056
+ if (!this._active) return Promise.resolve(this._messages.states.offline);
1077
1057
  this.state('done');
1058
+ data.value = 'done';
1059
+ delete data.hash;
1060
+ data.hash = this.hash(data);
1061
+ this.action(data.value)
1062
+ const hasOnDone = this.onDone && typeof this.onDone === 'function' ? true : false;
1063
+ return hasOnDone ? this.onDone(data) : Promise.resolve(data);
1064
+ }
1065
+
1066
+ /**************
1067
+ func: finish
1068
+ params:
1069
+ - data: the data to pass to the resolve
1070
+ - resolve: the finish resolve to pass back
1071
+ If the deva is offline it will return the offline message.
1072
+ usage: this.finish(data, resolve)
1073
+ ***************/
1074
+ done(data) {
1078
1075
  if (!this._active) return Promise.resolve(this._messages.states.offline);
1076
+ this.state('finish');
1079
1077
  data.value = 'done';
1080
1078
  delete data.hash;
1081
1079
  data.hash = this.hash(data);
@@ -1098,8 +1096,8 @@ class Deva {
1098
1096
  this.stop('msg')
1099
1097
  ***************/
1100
1098
  stop() {
1101
- this.state('stop');
1102
1099
  if (!this._active) return Promise.resolve(this._messages.states.offline);
1100
+ this.state('stop');
1103
1101
  const data = {
1104
1102
  id: this.uid(true),
1105
1103
  key: 'return',
@@ -1167,7 +1165,7 @@ class Deva {
1167
1165
  if (!this._states[state]) return;
1168
1166
  this._state = state;
1169
1167
  const text = this._messages.states[state];
1170
- const _data = {
1168
+ const data = {
1171
1169
  id: this.uid(true),
1172
1170
  key: 'state',
1173
1171
  value: state,
@@ -1176,8 +1174,8 @@ class Deva {
1176
1174
  text,
1177
1175
  created: Date.now(),
1178
1176
  };
1179
- _data.hash = this.hash(_data);
1180
- this.talk(config.events.state, _data);
1177
+ data.hash = this.hash(data);
1178
+ this.talk(config.events.state, data);
1181
1179
  } catch (e) {
1182
1180
  return this.error(e);
1183
1181
  }
@@ -1203,7 +1201,7 @@ class Deva {
1203
1201
  if (!this._zones[zone]) return;
1204
1202
  this._zone = zone;
1205
1203
  const text = this._messages.zones[zone];
1206
- const _data = {
1204
+ const data = {
1207
1205
  id: this.uid(true),
1208
1206
  key: 'zone',
1209
1207
  value: zone,
@@ -1212,8 +1210,8 @@ class Deva {
1212
1210
  data,
1213
1211
  created: Date.now(),
1214
1212
  };
1215
- _data.hash = this.hash(_data);
1216
- this.talk(config.events.zone, _data);
1213
+ data.hash = this.hash(data);
1214
+ this.talk(config.events.zone, data);
1217
1215
  } catch (e) {
1218
1216
  return this.error(e);
1219
1217
  }
@@ -1230,7 +1228,7 @@ class Deva {
1230
1228
  if (!this._actions[action]) return;
1231
1229
  this._action = action;
1232
1230
  const text = this._messages.actions[action];
1233
- const _data = {
1231
+ const data = {
1234
1232
  id: this.uid(true),
1235
1233
  key: 'action',
1236
1234
  value: action,
@@ -1239,8 +1237,8 @@ class Deva {
1239
1237
  text,
1240
1238
  created: Date.now(),
1241
1239
  };
1242
- _data.hash = this.hash(_data);
1243
- this.talk(config.events.action, _data);
1240
+ data.hash = this.hash(data);
1241
+ this.talk(config.events.action, data);
1244
1242
  } catch (e) {
1245
1243
  return this.error(e)
1246
1244
  }
@@ -1257,7 +1255,7 @@ class Deva {
1257
1255
  if (!this._features[feature]) return;
1258
1256
  this._feature = feature;
1259
1257
  const text = this._messages.features[feature] ;
1260
- const _data = {
1258
+ const data = {
1261
1259
  id: this.uid(true),
1262
1260
  key: 'feature',
1263
1261
  value: feature,
@@ -1266,8 +1264,8 @@ class Deva {
1266
1264
  data,
1267
1265
  created: Date.now(),
1268
1266
  };
1269
- _data.hash = this.hash(_data);
1270
- this.talk(config.events.feature, _data);
1267
+ data.hash = this.hash(data);
1268
+ this.talk(config.events.feature, data);
1271
1269
  } catch (e) {
1272
1270
  return this.error(e);
1273
1271
  }
@@ -1282,7 +1280,7 @@ class Deva {
1282
1280
  context(value) {
1283
1281
  try {
1284
1282
  this._context = value;
1285
- const _data = {
1283
+ const data = {
1286
1284
  id: this.uid(true),
1287
1285
  key: 'context',
1288
1286
  value,
@@ -1291,8 +1289,8 @@ class Deva {
1291
1289
  text: this.vars.context[value] || value,
1292
1290
  created: Date.now(),
1293
1291
  };
1294
- _data.hash = this.hash(_data);
1295
- this.talk(config.events.context, _data);
1292
+ data.hash = this.hash(data);
1293
+ this.talk(config.events.context, data);
1296
1294
  } catch (e) {
1297
1295
  return this.error(e);
1298
1296
  }
@@ -1310,8 +1308,8 @@ class Deva {
1310
1308
  usage: this.client();
1311
1309
  ***************/
1312
1310
  client() {
1313
- this.state('client_data'); // set the client state
1314
1311
  if (!this._active) return this._messages.states.offline; // check the active status
1312
+ this.state('client_data'); // set the client state
1315
1313
  const client_copy = this.copy(this._client);
1316
1314
  // delete client_copy.parse;
1317
1315
  // delete client_copy.translate;
@@ -1327,8 +1325,8 @@ class Deva {
1327
1325
  usage: this.agent()
1328
1326
  ***************/
1329
1327
  agent() {
1330
- this.state('agent_data');
1331
1328
  if (!this._active) return this._messages.states.offline;
1329
+ this.state('agent_data');
1332
1330
  const agent_copy = this.copy(this._agent);
1333
1331
  delete agent_copy.parse;
1334
1332
  delete agent_copy.translate;
@@ -1344,9 +1342,9 @@ class Deva {
1344
1342
  usage: this.security()
1345
1343
  ***************/
1346
1344
  security() {
1345
+ if (!this._active) return this._messages.states.offline; // check the active status
1347
1346
  this.feature('security'); // set the security state
1348
1347
  try {
1349
- if (!this._active) return this._messages.states.offline; // check the active status
1350
1348
  this.action('security'); // set the security state
1351
1349
  return this.copy(this._security); // return the security feature
1352
1350
  } catch (e) {
@@ -1363,9 +1361,9 @@ class Deva {
1363
1361
  usage: this.support()
1364
1362
  ***************/
1365
1363
  support() {
1364
+ if (!this._active) return this._messages.states.offline; // check the active status
1366
1365
  this.feature('support'); // set the support state
1367
1366
  try {
1368
- if (!this._active) return this._messages.states.offline; // check the active status
1369
1367
  this.action('support');
1370
1368
  return this.copy(this._support); // return the support feature
1371
1369
  } catch (e) {
@@ -1382,9 +1380,9 @@ class Deva {
1382
1380
  usage: this.services()
1383
1381
  ***************/
1384
1382
  services(opts) {
1383
+ if (!this._active) return this._messages.states.offline; // check the active status
1385
1384
  this.feature('services'); // set the services state
1386
1385
  try {
1387
- if (!this._active) return this._messages.states.offline; // check the active status
1388
1386
  this.action('services'); // set the services state
1389
1387
  return this.copy(this._services); // return the services feature
1390
1388
  } catch (e) {
@@ -1401,9 +1399,9 @@ class Deva {
1401
1399
  usage: this.systems()
1402
1400
  ***************/
1403
1401
  systems(opts) {
1402
+ if (!this._active) return this._messages.states.offline; // check the active status
1404
1403
  this.feature('systems'); // set the systems state
1405
1404
  try {
1406
- if (!this._active) return this._messages.states.offline; // check the active status
1407
1405
  this.action('systems'); // set the systems state
1408
1406
  return this.copy(this._systems); // return the systems feature
1409
1407
  } catch (e) {
@@ -1420,9 +1418,9 @@ class Deva {
1420
1418
  usage: this.solutions()
1421
1419
  ***************/
1422
1420
  solutions(opts) {
1421
+ if (!this._active) return this._messages.states.offline; // check the active status
1423
1422
  this.feature('solutions'); // set the solutions state
1424
1423
  try {
1425
- if (!this._active) return this._messages.states.offline; // check the active status
1426
1424
  this.action('solutions'); // set the solutions state
1427
1425
  return this.copy(this._solutions); // return the solutions feature
1428
1426
  } catch (e) {
@@ -1438,9 +1436,9 @@ class Deva {
1438
1436
  describe: basic research features available in a Deva.
1439
1437
  ***************/
1440
1438
  research(opts) {
1439
+ if (!this._active) return this._messages.states.offline; // chek the active status
1441
1440
  this.feature('research'); // set the research state
1442
1441
  try {
1443
- if (!this._active) return this._messages.states.offline; // chek the active status
1444
1442
  this.action('research'); // set the research state
1445
1443
  return this.copy(this._research); // return research feature
1446
1444
  } catch (e) {
@@ -1456,9 +1454,9 @@ class Deva {
1456
1454
  describe: basic development features available in a Deva.
1457
1455
  ***************/
1458
1456
  development(opts) {
1457
+ if (!this._active) return this._messages.states.offline; // chek the active status
1459
1458
  this.feature('development'); // set the development state
1460
1459
  try {
1461
- if (!this._active) return this._messages.states.offline; // chek the active status
1462
1460
  this.action('development'); // set the development state
1463
1461
  return this.copy(this._development); // return development feature
1464
1462
  } catch (e) {
@@ -1474,9 +1472,9 @@ class Deva {
1474
1472
  describe: basic assistant features available in a Deva.
1475
1473
  ***************/
1476
1474
  assistant(opts) {
1475
+ if (!this._active) return this._messages.states.offline; // chek the active status
1477
1476
  this.feature('assistant'); // set the assistant state
1478
1477
  try {
1479
- if (!this._active) return this._messages.states.offline; // chek the active status
1480
1478
  this.action('assistant'); // set the assistant state
1481
1479
  return this.copy(this._assistant); // return assistant feature
1482
1480
  } catch (e) {
@@ -1492,9 +1490,9 @@ class Deva {
1492
1490
  describe: basic business features available in a Deva.
1493
1491
  ***************/
1494
1492
  business(opts) {
1493
+ if (!this._active) return this._messages.states.offline; // chek the active status
1495
1494
  this.feature('business'); // set the business state
1496
1495
  try {
1497
- if (!this._active) return this._messages.states.offline; // chek the active status
1498
1496
  this.action('business');
1499
1497
  return this.copy(this._business); // return business feature
1500
1498
  } catch (e) {
@@ -1510,9 +1508,9 @@ class Deva {
1510
1508
  describe: basic legal features available in a Deva.
1511
1509
  ***************/
1512
1510
  legal(opts) {
1511
+ if (!this._active) return this._messages.states.offline; // chek the active status
1513
1512
  this.feature('legal'); // set the legal state
1514
1513
  try {
1515
- if (!this._active) return this._messages.states.offline; // chek the active status
1516
1514
  this.action('legal');
1517
1515
  return this.copy(this._legal); // return legal feature
1518
1516
  } catch (e) {
@@ -1528,9 +1526,9 @@ class Deva {
1528
1526
  describe: basic story features available in a Deva.
1529
1527
  ***************/
1530
1528
  story(opts) {
1529
+ if (!this._active) return this._messages.states.offline; // chek the active status
1531
1530
  this.feature('story'); // set the story state
1532
1531
  try {
1533
- if (!this._active) return this._messages.states.offline; // chek the active status
1534
1532
  this.action('story');
1535
1533
  return this.story(this._story); // return story feature
1536
1534
  } catch (e) {
@@ -1643,12 +1641,10 @@ class Deva {
1643
1641
  const key = createHash('sha256').update(String(password)).digest('base64');
1644
1642
  const key_in_bytes = Buffer.from(key, 'base64')
1645
1643
  const iv = randomBytes(16);
1646
-
1647
1644
  // create a new cipher
1648
1645
  const _cipher = createCipheriv(algorithm, key_in_bytes, iv);
1649
1646
  const encrypted = _cipher.update(String(str), 'utf8', 'hex') + _cipher.final('hex');
1650
1647
 
1651
-
1652
1648
  return {
1653
1649
  iv: iv.toString('base64'),
1654
1650
  key,
@@ -1668,28 +1664,6 @@ class Deva {
1668
1664
  return final.toString();
1669
1665
  }
1670
1666
 
1671
- /**************
1672
- func: status
1673
- params:
1674
- - msg: The msg is any additonal string to append to the end of hte call.
1675
- describe:
1676
- The status function provides an easy way to get the current status of a Deva
1677
- and append custom status messages that may pertain to any custom status call.
1678
-
1679
- If the deva is offline it will return the offline message.
1680
- usage: this.status('msg')
1681
- ***************/
1682
- status(msg=false) {
1683
- // check the active status
1684
- if (!this._active) return Promise.resolve(this._messages.states.offline);
1685
- // format the date since active for output.
1686
- const dateFormat = this.formatDate(this._active, 'long', true);
1687
- // create the text msg string
1688
- let text = `${this._agent.profile.name} active since ${dateFormat}`;
1689
- if (msg) text = text + `\n${msg}`; // append the msg string if msg true.
1690
- return Promise.resolve(text); // return final text string
1691
- }
1692
-
1693
1667
  /**************
1694
1668
  func: prompt
1695
1669
  params:
@@ -1845,6 +1819,52 @@ class Deva {
1845
1819
  });
1846
1820
  }
1847
1821
 
1822
+ /**************
1823
+ func: info
1824
+ params: id
1825
+ describe: return info data.
1826
+ ***************/
1827
+ info(id=false) {
1828
+ id = id || this._id;
1829
+ const agent = this.agent();
1830
+ if (this._info) {
1831
+ const _info = [
1832
+ `::begin:info:${id}`,
1833
+ `## ${this._agent.profile.name} (#${agent.key})`,
1834
+ ];
1835
+ for (let x in this._info) {
1836
+ _info.push(`- ${x}: ${this._info[x]}`);
1837
+ }
1838
+ _info.push(`::end:info:${this.hash(this._info)}`);
1839
+ return _info.join('\n');
1840
+ }
1841
+ else {
1842
+ return '';
1843
+ }
1844
+ }
1845
+
1846
+ /**************
1847
+ func: status
1848
+ params:
1849
+ - msg: The msg is any additonal string to append to the end of hte call.
1850
+ describe:
1851
+ The status function provides an easy way to get the current status of a Deva
1852
+ and append custom status messages that may pertain to any custom status call.
1853
+
1854
+ If the deva is offline it will return the offline message.
1855
+ usage: this.status('msg')
1856
+ ***************/
1857
+ status(msg=false) {
1858
+ // check the active status
1859
+ if (!this._active) return Promise.resolve(this._messages.states.offline);
1860
+ // format the date since active for output.
1861
+ const dateFormat = this.formatDate(this._active, 'long', true);
1862
+ // create the text msg string
1863
+ let text = `${this._agent.profile.name} active since ${dateFormat}`;
1864
+ if (msg) text = text + `\n${msg}`; // append the msg string if msg true.
1865
+ return text; // return final text string
1866
+ }
1867
+
1848
1868
  /**************
1849
1869
  func: help
1850
1870
  params:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.1.94",
3
+ "version": "1.1.96",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "scripts": {