@indra.ai/deva 1.29.0 → 1.29.2

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.
Files changed (2) hide show
  1. package/index.js +29 -20
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -310,7 +310,7 @@ class Deva {
310
310
  init, start, enter, done ready, finish, complete
311
311
  usage: this.complete(data, resolve)
312
312
  ***************/
313
- _invoke(opts) {
313
+ async _invoke(opts) {
314
314
  if (!this._active) return resolve(this._messages.offline);
315
315
  const {key, data, resolve} = opts;
316
316
  const {prev_key, next_key, onfunc, clear} = config.invoke[key];
@@ -363,10 +363,12 @@ class Deva {
363
363
  return this[onfunc](data, resolve);
364
364
  }
365
365
 
366
- this.action('return', `${key}:${data.id.uid}`); // return action complete
367
- this.state('valid', `${key}:${data.id.uid}`); // return state valid
368
- this.intent('good', `${key}:${data.id.uid}`); // return intent good
369
- return next_key ? this[next_key](data, resolve) : resolve(data);
366
+ setImmediate(() => {
367
+ this.action('return', `${key}:${data.id.uid}`); // return action complete
368
+ this.state('valid', `${key}:${data.id.uid}`); // return state valid
369
+ this.intent('good', `${key}:${data.id.uid}`); // return intent good
370
+ return next_key ? this[next_key](data, resolve) : resolve(data);
371
+ });
370
372
  }
371
373
 
372
374
  /**************
@@ -1411,21 +1413,28 @@ class Deva {
1411
1413
  }
1412
1414
  // check if the entity has devas to load after everything is ready.
1413
1415
  // load the devas
1414
- if (this.devas && Object.keys(this.devas).length) {
1415
- for (let deva in this.devas) {
1416
- await this.load(deva, data.client);
1417
- // after the deva loads talk the event to set asset directory.
1418
- const id = this.devas[deva].uid();
1419
- const {dir} = this.devas[deva].info();
1420
- const {key} = this.devas[deva].agent();
1421
- this.talk(`deva:dir`, {id, key,dir});
1422
- }
1416
+ let deva;
1417
+ try {
1418
+ if (this.devas && Object.keys(this.devas).length) {
1419
+ for (deva in this.devas) {
1420
+ await this.load(deva, data.client);
1421
+ // after the deva loads talk the event to set asset directory.
1422
+ const id = this.devas[deva].uid();
1423
+ const {dir} = this.devas[deva].info();
1424
+ const {key} = this.devas[deva].agent();
1425
+ this.talk(`deva:dir`, {id, key,dir});
1426
+ }
1427
+ }
1428
+ }
1429
+ catch (err) {
1430
+ return this.err(err, deva);
1431
+ }
1432
+ finally {
1433
+ // return the invoke in a set immediate so it runs after the loop
1423
1434
  setImmediate(() => {
1424
- // return the invoke in a set immediate so it runs after the loop
1425
- return this._invoke({key,data,resolve});
1435
+ return this._invoke({key,data,resolve});
1426
1436
  });
1427
- }
1428
- return this._invoke({key,data,resolve});
1437
+ }
1429
1438
  }
1430
1439
 
1431
1440
  /**************
@@ -2153,12 +2162,12 @@ class Deva {
2153
2162
  -deva: The Deva model to load.
2154
2163
  describe: This function will enable fast loading of Deva into the system.
2155
2164
  ***************/
2156
- load(key, client) {
2165
+ async load(key, client) {
2157
2166
  this.zone('load', key);
2158
2167
  this.action('load', key);
2159
2168
  this.state('load', key);
2160
2169
  this.intent('good', `load:${key}`);
2161
- return this.devas[key].init(client);
2170
+ return await this.devas[key].init(client);
2162
2171
  }
2163
2172
 
2164
2173
  /**************
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "38159520729793885324",
3
3
  "name": "@indra.ai/deva",
4
- "version": "1.29.0",
4
+ "version": "1.29.2",
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:38159520729793885324 LICENSE.md",