@indra.ai/deva 1.54.10 → 1.54.17
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 +3 -0
- package/config/msgs.json +2 -0
- package/index.js +48 -9
- package/package.json +1 -1
package/config/index.js
CHANGED
package/config/msgs.json
CHANGED
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
"nodata": "⛔️ NO DATA PROVIDED",
|
|
19
19
|
"nokey": "⛔️ NO KEY PROVIDED",
|
|
20
20
|
"invalidkey": "⛔️ INVALID KEY PROVIDED",
|
|
21
|
+
"asktimeout": "⛔️ ASK TIMEOUT",
|
|
22
|
+
"noask": "⛔️ NO ASK PROVIDED",
|
|
21
23
|
"method_not_found": "⛔️ METHOD NOT FOUND",
|
|
22
24
|
"help_not_found": "⛔️ HELP NOT FOUND",
|
|
23
25
|
"invalid_agent": "⛔️ Agent Hash Invalid",
|
package/index.js
CHANGED
|
@@ -19,6 +19,8 @@ class Deva {
|
|
|
19
19
|
this._info = opts.info || false; // the deva information from the package file.
|
|
20
20
|
this._config = opts.config || {}; // local Config Object
|
|
21
21
|
this._config.ready_hash = config.ready_hash; // items to hash at ready
|
|
22
|
+
if (!this._config.timeout) this._config.timeout = config.timeout; // add timeout values to _config.
|
|
23
|
+
|
|
22
24
|
this._agent = opts.agent || false; // Agent profile object
|
|
23
25
|
this._client = {}; // this will be set on init.
|
|
24
26
|
this._active = false; // the active/birth date.
|
|
@@ -67,6 +69,9 @@ class Deva {
|
|
|
67
69
|
this._uid = config.uid; // set the uid options
|
|
68
70
|
|
|
69
71
|
this._events = config.events; // set the core system events
|
|
72
|
+
this._bound = new Map(); // evt -> wrapper registered on the shared bus
|
|
73
|
+
this._pending = new Set(); // pending asks: {evt, handler, timer}
|
|
74
|
+
|
|
70
75
|
this._feature = config.feature; // set the feature from config data.
|
|
71
76
|
this._features = config.features; // set the features from config data.
|
|
72
77
|
|
|
@@ -179,10 +184,10 @@ class Deva {
|
|
|
179
184
|
}
|
|
180
185
|
|
|
181
186
|
// set the assigned listeners for the agent.
|
|
182
|
-
for (let listener in this.listeners) { // loop over the
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
187
|
+
for (let listener in this.listeners) { // loop over the listeners
|
|
188
|
+
const handler = packet => this.listeners[listener](packet);
|
|
189
|
+
this._bound.set(listener, handler);
|
|
190
|
+
this.events.on(listener, handler);
|
|
186
191
|
}
|
|
187
192
|
return resolve(); // resolve the function after everything is done.
|
|
188
193
|
}
|
|
@@ -192,8 +197,41 @@ class Deva {
|
|
|
192
197
|
});
|
|
193
198
|
}
|
|
194
199
|
|
|
200
|
+
/**************
|
|
201
|
+
func: _removeListeners
|
|
202
|
+
params: none
|
|
203
|
+
describe:
|
|
204
|
+
Remove listeners will take the this.lisners objects and remove the appropriate
|
|
205
|
+
listener values for the event bus.
|
|
206
|
+
***************/
|
|
207
|
+
_removeListeners() {
|
|
208
|
+
if (!this.events || !this.listeners) return;
|
|
209
|
+
for (const evt in this.listeners) {
|
|
210
|
+
const handler = this._bound.get(evt);
|
|
211
|
+
if (handler) this.ignore(evt, handler); // ignore() already calls events.removeListener
|
|
212
|
+
}
|
|
213
|
+
this._bound.clear();
|
|
214
|
+
return this._clearPending(); // pending asks go in the same pass
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**************
|
|
218
|
+
func: _clearPending
|
|
219
|
+
params: none
|
|
220
|
+
describe:
|
|
221
|
+
Clears the timer and removes the listener for every pending ask so a
|
|
222
|
+
shutdown leaves nothing behind on the shared event bus.
|
|
223
|
+
***************/
|
|
224
|
+
_clearPending() {
|
|
225
|
+
if (!this._pending) return;
|
|
226
|
+
for (const pending of this._pending) {
|
|
227
|
+
clearTimeout(pending.timer);
|
|
228
|
+
if (this.events) this.ignore(pending.evt, pending.handler);
|
|
229
|
+
}
|
|
230
|
+
this._pending.clear();
|
|
231
|
+
}
|
|
232
|
+
|
|
195
233
|
// Some elements will inherit the data of the parent. this object will loop over
|
|
196
|
-
// any children data that
|
|
234
|
+
// any children data that this deva has and assign the inherited information.
|
|
197
235
|
/**************
|
|
198
236
|
func: _assignInherit
|
|
199
237
|
params: none
|
|
@@ -339,7 +377,8 @@ class Deva {
|
|
|
339
377
|
|
|
340
378
|
if (clear) {
|
|
341
379
|
this.state('loop', `${key}:clear:${data.id.uid}`);
|
|
342
|
-
for (let item of
|
|
380
|
+
for (let item of clear) {
|
|
381
|
+
if (item === 'listeners') this._removeListeners();
|
|
343
382
|
this[item] = false;
|
|
344
383
|
}
|
|
345
384
|
}
|
|
@@ -693,9 +732,9 @@ class Deva {
|
|
|
693
732
|
this.action('listen', evt);
|
|
694
733
|
this.intent('good', `listen:${evt}`);
|
|
695
734
|
this.listeners[evt] = callback;
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
735
|
+
const handler = packet => this.listeners[evt](packet);
|
|
736
|
+
this._bound.set(evt, handler);
|
|
737
|
+
return this.events.on(evt, handler);
|
|
699
738
|
}
|
|
700
739
|
|
|
701
740
|
/**************
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "23221940810208468106",
|
|
3
3
|
"name": "@indra.ai/deva",
|
|
4
|
-
"version": "1.54.
|
|
4
|
+
"version": "1.54.17",
|
|
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",
|