@indra.ai/deva 1.1.41 → 1.1.43
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 +29 -11
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -8,6 +8,7 @@ class Deva {
|
|
|
8
8
|
constructor(opts) {
|
|
9
9
|
opts = opts || {};
|
|
10
10
|
this._id = randomUUID(); // the unique id assigned to the agent at load
|
|
11
|
+
this._info = opts.info || false; // the deva information from the package file.
|
|
11
12
|
this._config = opts.config || {}; // local Config Object
|
|
12
13
|
this._agent = opts.agent || false; // Agent profile object
|
|
13
14
|
this._client = {}; // this will be set on init.
|
|
@@ -919,8 +920,6 @@ class Deva {
|
|
|
919
920
|
method = t_split[0].substring(1); // if:isCmd use the 0 index as the command
|
|
920
921
|
text = t_split.slice(1).join(' ').trim(); // if:isCmd rejoin the string on the space after removing first index
|
|
921
922
|
}
|
|
922
|
-
else {
|
|
923
|
-
}
|
|
924
923
|
|
|
925
924
|
packet.q = { // build packet.q container
|
|
926
925
|
id: this.uid(),
|
|
@@ -998,7 +997,7 @@ class Deva {
|
|
|
998
997
|
|
|
999
998
|
const agent = this.agent() || false;
|
|
1000
999
|
const client = this.client() || false;
|
|
1001
|
-
|
|
1000
|
+
const packet_answer = { // setup the packet.a container
|
|
1002
1001
|
id: this.uid(),
|
|
1003
1002
|
agent, // set the agent who answered the question
|
|
1004
1003
|
client, // set the client asking the question
|
|
@@ -1015,14 +1014,15 @@ class Deva {
|
|
|
1015
1014
|
|
|
1016
1015
|
// create a hash for the answer and insert into answer meta.
|
|
1017
1016
|
this.action('answer_hash');
|
|
1018
|
-
|
|
1017
|
+
packet_answer.meta.hash = this.hash(JSON.stringify(packet_answer));
|
|
1019
1018
|
|
|
1019
|
+
packet.a = this.copy(packet_answer);
|
|
1020
1020
|
this.action('packet_hash');
|
|
1021
1021
|
packet.hash = this.hash(JSON.stringify(packet)); // hash the entire packet.
|
|
1022
1022
|
|
|
1023
1023
|
|
|
1024
1024
|
this.action('answer_talk');
|
|
1025
|
-
this.talk('devacore:answer',
|
|
1025
|
+
this.talk('devacore:answer', packet); // talk the answer with a copy of the data
|
|
1026
1026
|
|
|
1027
1027
|
return resolve(packet); // resolve the packet to the caller.
|
|
1028
1028
|
}).catch(err => { // catch any errors in the method
|
|
@@ -1158,6 +1158,25 @@ class Deva {
|
|
|
1158
1158
|
});
|
|
1159
1159
|
}
|
|
1160
1160
|
|
|
1161
|
+
info(id=false) {
|
|
1162
|
+
id = id || this._id;
|
|
1163
|
+
const agent = this.agent();
|
|
1164
|
+
if (this._info) {
|
|
1165
|
+
const _info = [
|
|
1166
|
+
`::begin:info:${id}`,
|
|
1167
|
+
`## ${this._agent.profile.name} (#${agent.key})`,
|
|
1168
|
+
];
|
|
1169
|
+
for (let x in this._info) {
|
|
1170
|
+
_info.push(`- ${x}: ${this._info[x]}`);
|
|
1171
|
+
}
|
|
1172
|
+
_info.push(`::end:info:${this.hash(JSON.stringify(this._info))}`);
|
|
1173
|
+
return _info.join('\n');
|
|
1174
|
+
}
|
|
1175
|
+
else {
|
|
1176
|
+
return '';
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1161
1180
|
/**************
|
|
1162
1181
|
func: start
|
|
1163
1182
|
params:
|
|
@@ -1176,8 +1195,7 @@ class Deva {
|
|
|
1176
1195
|
data.hash = this.hash(JSON.stringify(data));
|
|
1177
1196
|
|
|
1178
1197
|
if (this.info) {
|
|
1179
|
-
const _info =
|
|
1180
|
-
.replace(/\"|\,/g, '').replace(/\}/g, '::END:INFO').trim()
|
|
1198
|
+
const _info = this.info(data.id);
|
|
1181
1199
|
this.prompt(_info);
|
|
1182
1200
|
}
|
|
1183
1201
|
|
|
@@ -1399,7 +1417,7 @@ class Deva {
|
|
|
1399
1417
|
created: Date.now(),
|
|
1400
1418
|
};
|
|
1401
1419
|
_data.hash = this.hash(JSON.stringify(_data));
|
|
1402
|
-
this.talk('feature', _data);
|
|
1420
|
+
this.talk('devacore:feature', _data);
|
|
1403
1421
|
} catch (e) {
|
|
1404
1422
|
return this.error(e);
|
|
1405
1423
|
}
|
|
@@ -1624,7 +1642,7 @@ class Deva {
|
|
|
1624
1642
|
return new Promise((resolve, reject) => {
|
|
1625
1643
|
this.state('load');
|
|
1626
1644
|
this.devas[key].init(client).then(loaded => {
|
|
1627
|
-
this.talk(`
|
|
1645
|
+
this.talk(`devacore:load`, {
|
|
1628
1646
|
key,
|
|
1629
1647
|
created: Date.now(),
|
|
1630
1648
|
});
|
|
@@ -1646,7 +1664,7 @@ class Deva {
|
|
|
1646
1664
|
try {
|
|
1647
1665
|
this.state('uload');
|
|
1648
1666
|
delete this.devas[key];
|
|
1649
|
-
this.talk(`unload`, {
|
|
1667
|
+
this.talk(`devacore:unload`, {
|
|
1650
1668
|
key,
|
|
1651
1669
|
created: Date.now(),
|
|
1652
1670
|
});
|
|
@@ -1698,7 +1716,7 @@ class Deva {
|
|
|
1698
1716
|
const the_hash = createHash(algo);
|
|
1699
1717
|
the_hash.update(str);
|
|
1700
1718
|
const _digest = the_hash.digest('base64');
|
|
1701
|
-
return _digest
|
|
1719
|
+
return `${algo}:${_digest}`;
|
|
1702
1720
|
}
|
|
1703
1721
|
|
|
1704
1722
|
/**************
|