@indra.ai/deva 1.56.3 → 1.57.0
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/config/index.js +1 -0
- package/index.js +39 -13
- package/package.json +1 -1
package/config/index.js
CHANGED
package/index.js
CHANGED
|
@@ -18,6 +18,7 @@ class Deva {
|
|
|
18
18
|
this._id = opts.id || randomUUID(); // the unique id assigned to the agent at load
|
|
19
19
|
this._info = opts.info || false; // the deva information from the package file.
|
|
20
20
|
this._config = opts.config || {}; // local Config Object
|
|
21
|
+
this._config.hashes = config.hashes; // set hashes array from config for stamping.
|
|
21
22
|
this._config.ready_hash = config.ready_hash; // items to hash at ready
|
|
22
23
|
this._config.timeout = {...config.timeout, ...this._config.timeout}; // add timeout values to _config.
|
|
23
24
|
|
|
@@ -71,6 +72,7 @@ class Deva {
|
|
|
71
72
|
this._events = config.events; // set the core system events
|
|
72
73
|
this._bound = new Map(); // evt -> wrapper registered on the shared bus
|
|
73
74
|
this._pending = new Set(); // pending asks: {evt, handler, timer}
|
|
75
|
+
this._stateBound = []; // [event, handler] pairs for the state listeners
|
|
74
76
|
|
|
75
77
|
this._feature = config.feature; // set the feature from config data.
|
|
76
78
|
this._features = config.features; // set the features from config data.
|
|
@@ -174,12 +176,14 @@ class Deva {
|
|
|
174
176
|
_assignListeners() {
|
|
175
177
|
return new Promise((resolve, reject) => {
|
|
176
178
|
try {
|
|
179
|
+
|
|
177
180
|
// set the default listeners for the states of the agent.
|
|
178
181
|
for (let state in this._states) {
|
|
179
182
|
if (typeof this[state] === 'function') {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
const evt = `${this._agent.key}:${state}`;
|
|
184
|
+
const handler = packet => this[state](packet);
|
|
185
|
+
this._stateBound.push([evt, handler]); // keep it so shutdown can remove it
|
|
186
|
+
this.events.on(evt, handler);
|
|
183
187
|
}
|
|
184
188
|
}
|
|
185
189
|
|
|
@@ -211,6 +215,8 @@ class Deva {
|
|
|
211
215
|
if (handler) this.ignore(evt, handler); // ignore() already calls events.removeListener
|
|
212
216
|
}
|
|
213
217
|
this._bound.clear();
|
|
218
|
+
for (const [evt, handler] of this._stateBound) this.ignore(evt, handler); // state listeners from _assignListeners
|
|
219
|
+
this._stateBound = [];
|
|
214
220
|
return this._clearPending(); // pending asks go in the same pass
|
|
215
221
|
}
|
|
216
222
|
|
|
@@ -400,6 +406,34 @@ class Deva {
|
|
|
400
406
|
return next_key ? this[next_key](data, resolve) : resolve(data);
|
|
401
407
|
}
|
|
402
408
|
|
|
409
|
+
/**************
|
|
410
|
+
func: _stamp
|
|
411
|
+
params:
|
|
412
|
+
- data: the data to stamp
|
|
413
|
+
- label: the label for the hash action.
|
|
414
|
+
describe: the stamp function will take a data object and apply the hashes from the this._config.hashes array.
|
|
415
|
+
usage: this._stamp(data, 'value')
|
|
416
|
+
***************/
|
|
417
|
+
_stamp(data, label='', uid='') {
|
|
418
|
+
for (const algo of this._config.hashes) {
|
|
419
|
+
if (label) this.action('hash', `${label}:${algo}:${uid}`);
|
|
420
|
+
data[algo] = this.hash(data, algo);
|
|
421
|
+
}
|
|
422
|
+
return data;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**************
|
|
426
|
+
func: _unstamp
|
|
427
|
+
params:
|
|
428
|
+
- data: the data to unstamp
|
|
429
|
+
describe: the unstamp function will take a data object and remove the hashes over the this._hashes array.
|
|
430
|
+
usage: this._unstamp(data)
|
|
431
|
+
***************/
|
|
432
|
+
_unstamp(data) {
|
|
433
|
+
for (const algo of this._config.hashes) delete data[algo];
|
|
434
|
+
return data;
|
|
435
|
+
}
|
|
436
|
+
|
|
403
437
|
/**************
|
|
404
438
|
func: Client
|
|
405
439
|
params: client - client provided data.
|
|
@@ -840,16 +874,8 @@ class Deva {
|
|
|
840
874
|
created: Date.now(), // timestamp the question
|
|
841
875
|
}
|
|
842
876
|
|
|
843
|
-
//
|
|
844
|
-
|
|
845
|
-
this.action('hash', `${method}:md5:${id.uid}`);
|
|
846
|
-
packet.q.md5 = this.hash(packet.q, 'md5');
|
|
847
|
-
|
|
848
|
-
this.action('hash', `${method}:sha256:${id.uid}`)
|
|
849
|
-
packet.q.sha256 = this.hash(packet.q, 'sha256');
|
|
850
|
-
|
|
851
|
-
this.action('hash', `${method}:sha512:${id.uid}`)
|
|
852
|
-
packet.q.sha512 = this.hash(packet.q, 'sha512');
|
|
877
|
+
// stamp the question
|
|
878
|
+
packet.q = this._stamp(packet.q, method, id.uid);
|
|
853
879
|
|
|
854
880
|
this.action('talk', `${this._events.question}:${id.uid}`);
|
|
855
881
|
this.intent('good', `${this._events.question}:${id.uid}`);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "23221940810208468106",
|
|
3
3
|
"name": "@indra.ai/deva",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.57.0",
|
|
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",
|