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