@indra.ai/deva 1.5.34 → 1.5.36
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 +36 -5
- package/package.json +1 -1
- package/tests/index.js +4 -8
package/index.js
CHANGED
|
@@ -507,8 +507,8 @@ class Deva {
|
|
|
507
507
|
}
|
|
508
508
|
else if (isCmd) { // determine if the question is a command
|
|
509
509
|
//if:isCmd use text split index 1 as the parameter block
|
|
510
|
-
params = t_split[0] ? t_split[0].split(':')
|
|
511
|
-
method = t_split[0].substring(1); // if:isCmd use the 0 index as the command
|
|
510
|
+
params = t_split[0] ? t_split[0].split(':') : false;
|
|
511
|
+
method = t_split[0].split(':')[0].substring(1); // if:isCmd use the 0 index as the command
|
|
512
512
|
text = t_split.slice(1).join(' ').trim(); // if:isCmd rejoin the string on the space after removing first index
|
|
513
513
|
this.state('cmd', `${method}:${id}`); // set the state to cmd.
|
|
514
514
|
}
|
|
@@ -1515,7 +1515,33 @@ class Deva {
|
|
|
1515
1515
|
this.state('return', `status:${id}`);
|
|
1516
1516
|
return `${this._agent.profile.name} active since ${dateFormat}`; // return final text string
|
|
1517
1517
|
}
|
|
1518
|
+
|
|
1519
|
+
/******
|
|
1520
|
+
func: signature
|
|
1521
|
+
params:
|
|
1522
|
+
- data: the data to sign
|
|
1523
|
+
describe: function to provide a digital signature to data.
|
|
1524
|
+
******/
|
|
1525
|
+
signature(data) {
|
|
1526
|
+
if (!this._active) return this._messages.offline;
|
|
1527
|
+
const id = this.lib.uid();
|
|
1528
|
+
this.action('signature', id);
|
|
1518
1529
|
|
|
1530
|
+
const client = this.client();
|
|
1531
|
+
const agent = this.agent();
|
|
1532
|
+
this.state('set', `signature:${id}`);
|
|
1533
|
+
const signature = {
|
|
1534
|
+
id,
|
|
1535
|
+
uid: this.lib.uid(true),
|
|
1536
|
+
name: client.profile.name,
|
|
1537
|
+
md5: this.lib.hash(data),
|
|
1538
|
+
sha256: this.lib.hash(data, 'sha256'),
|
|
1539
|
+
sha512: this.lib.hash(data, 'sha512'),
|
|
1540
|
+
date: Date.now(),
|
|
1541
|
+
};
|
|
1542
|
+
this.state('return', `signature:${id}`);
|
|
1543
|
+
return signature;
|
|
1544
|
+
}
|
|
1519
1545
|
/**************
|
|
1520
1546
|
func: help
|
|
1521
1547
|
params:
|
|
@@ -1528,18 +1554,22 @@ class Deva {
|
|
|
1528
1554
|
***************/
|
|
1529
1555
|
help(msg, help_dir) {
|
|
1530
1556
|
return new Promise((resolve, reject) => {
|
|
1557
|
+
const id = this.lib.uid();
|
|
1531
1558
|
this.zone('help', id);
|
|
1532
1559
|
if (!this._active) return resolve(this._messages.offline);
|
|
1533
|
-
|
|
1560
|
+
|
|
1534
1561
|
this.feature('help', id);
|
|
1535
1562
|
this.action('help', id);
|
|
1536
1563
|
this.state('help', id);
|
|
1537
1564
|
this.context('help', id);
|
|
1538
1565
|
const params = msg.split(' '); // split the msg into an array by spaces.
|
|
1539
|
-
let helpFile = 'main'; // set default help file
|
|
1566
|
+
let helpFile = 'main', helpDoc = false; // set default help file
|
|
1540
1567
|
if (params[0]) helpFile = params[0]; // check the msg for a help file
|
|
1541
1568
|
if (params[1]) helpFile = `${params[0]}_${params[1]}`;
|
|
1542
1569
|
|
|
1570
|
+
const splitText = msg.split(':');
|
|
1571
|
+
const part = splitText[1] ? splitText[1].toUpperCase() : 'MAIN';
|
|
1572
|
+
|
|
1543
1573
|
|
|
1544
1574
|
const helpPath = this.lib.path.join(help_dir, 'help', `${helpFile}.feecting`);
|
|
1545
1575
|
this.state('try', `help:${id}`);
|
|
@@ -1549,7 +1579,8 @@ class Deva {
|
|
|
1549
1579
|
this.state('return', `${this._messages.help_not_found}:${id}`);
|
|
1550
1580
|
return resolve(this._messages.help_not_found);
|
|
1551
1581
|
}
|
|
1552
|
-
|
|
1582
|
+
helpDoc = this.lib.fs.readFileSync(helpPath, 'utf8');
|
|
1583
|
+
helpDoc = helpDoc.split(`::BEGIN:${part}`)[1].split(`::END:${part}`)[0];
|
|
1553
1584
|
this.state('return', `help:${id}`);
|
|
1554
1585
|
return resolve(helpDoc);
|
|
1555
1586
|
} catch (e) {
|
package/package.json
CHANGED
package/tests/index.js
CHANGED
|
@@ -93,6 +93,7 @@ const DevaTest = new Deva({
|
|
|
93
93
|
const info = this.info();
|
|
94
94
|
const date = Date.now();
|
|
95
95
|
const hashstr = `${id}${uid}${date}`;
|
|
96
|
+
const signature = this.signature(hashstr);
|
|
96
97
|
const data = [
|
|
97
98
|
'🧪 TEST RESULTS',
|
|
98
99
|
`::BEGIN:CORE:${core.id}`,
|
|
@@ -101,14 +102,9 @@ const DevaTest = new Deva({
|
|
|
101
102
|
`::BEGIN:INFO:${info.id}`,
|
|
102
103
|
JSON.stringify(info,null,2),
|
|
103
104
|
`::END:INFO:${info.hash}`,
|
|
104
|
-
`::BEGIN:
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
`md5: ${this.lib.hash(hashstr)}`,
|
|
108
|
-
`sha256: ${this.lib.hash(hashstr, 'sha256')}`,
|
|
109
|
-
`sha512: ${this.lib.hash(hashstr, 'sha512')}`,
|
|
110
|
-
`date: ${this.lib.formatDate(date, 'long', true)}`,
|
|
111
|
-
`::END:RESULTS:${this.lib.hash(hashstr)}`,
|
|
105
|
+
`::BEGIN:SIGNATURE:${signature.id}`,
|
|
106
|
+
JSON.stringify(signature, null, 2),
|
|
107
|
+
`::END:SIGNATURE:${signature.md5}`,
|
|
112
108
|
];
|
|
113
109
|
return {
|
|
114
110
|
text: data.join('\n'),
|