@indra.ai/deva 1.5.11 → 1.5.13

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 +31 -27
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -562,20 +562,21 @@ class Deva {
562
562
  from the agent from the pre-determined method.
563
563
  ***************/
564
564
  answer(packet, resolve, reject) {
565
+ const id = this.lib.uid();
565
566
  if (!this._active) return Promise.resolve(this._messages.offline);
566
- this.zone('answer'); // set zone to answer
567
+ this.zone('answer', id); // set zone to answer
567
568
  const agent = this.agent();
568
569
  const client = this.client();
569
570
  // check if method exists and is of type function
570
571
  const {method,params} = packet.q.meta;
571
- this.action('answer', method);
572
+ this.action('answer', `${method}:${id}`);
572
573
 
573
- this.state('try', `answer:${method}`);
574
+ this.state('try', `answer:${method}:${id}`);
574
575
  try {
575
576
  const isMethod = this.methods[method] && typeof this.methods[method] == 'function';
576
577
  if (!isMethod) return resolve(this._methodNotFound(packet)); // resolve method not found if check if check fails
577
578
 
578
- this.action('method', `answer:${method}`);
579
+ this.action('method', `answer:${method}:${id}`);
579
580
  this.methods[method](packet).then(result => {
580
581
  // check the result for the text, html, and data object. // this is for when answers are returned from nested Devas.
581
582
  const text = typeof result === 'object' ? result.text : result;
@@ -583,9 +584,9 @@ class Deva {
583
584
  // if the data passed is NOT an object it will FALSE
584
585
  const data = typeof result === 'object' ? result.data : false;
585
586
 
586
- this.state('set', `answer:${method}:packet_answer`);
587
+ this.state('set', `answer:${method}:packet_answer:${id}`);
587
588
  const packet_answer = { // setup the packet.a container
588
- id: this.lib.uid(),
589
+ id,
589
590
  agent, // set the agent who answered the question
590
591
  client, // set the client asking the question
591
592
  meta: { // setup the answer meta container
@@ -603,14 +604,14 @@ class Deva {
603
604
  packet.a = packet_answer; // set the packet.a to the packet_answer
604
605
  this.talk(config.events.answer, this.lib.copy(packet)); // global talk event
605
606
 
606
- this.state('finish', `answer:${method}`); // set the state resolve answer
607
+ this.state('return', `answer:${method}:${id}`); // set the state resolve answer
607
608
  return this.finish(packet, resolve); // resolve the packet to the caller.
608
609
  }).catch(err => { // catch any errors in the method
609
- this.state('catch', `answer:${method}`); // set the state reject answer
610
+ this.state('catch', `answer:${method}:${id}`); // set the state reject answer
610
611
  return this.error(err, packet, reject); // return this.error with err, packet, reject
611
612
  });
612
613
  } catch (e) {
613
- this.state('catch', `answer:${method}`);
614
+ this.state('catch', `answer:${method}:${id}`);
614
615
  return this.error(e, packet, reject);
615
616
  }
616
617
  }
@@ -638,24 +639,10 @@ class Deva {
638
639
  const agent = this.agent();
639
640
  const client = this.client();
640
641
  // build the answer packet from this model
641
- this.state('set', `ask:${method}:packet_answer:${packet.id}`);
642
- const packet_answer = {
643
- id: this.lib.uid(),
644
- agent,
645
- client,
646
- meta: {
647
- key: agent.key,
648
- method,
649
- params,
650
- },
651
- text: false,
652
- html: false,
653
- data: false,
654
- created: Date.now(),
655
- };
656
642
 
657
643
  this.state('try', `ask:${method}:${packet.id}`);
658
644
  try {
645
+
659
646
  if (typeof this.methods[method] !== 'function') {
660
647
  return setImmediate(() => {
661
648
  this.state('invalid', `${method}:${packet.id}`);
@@ -663,6 +650,21 @@ class Deva {
663
650
  });
664
651
  }
665
652
 
653
+ this.state('set', `ask:${method}:packet_answer:${packet.id}`);
654
+ const packet_answer = {
655
+ id: this.lib.uid(),
656
+ agent,
657
+ client,
658
+ meta: {
659
+ key: agent.key,
660
+ method,
661
+ params,
662
+ },
663
+ text: false,
664
+ html: false,
665
+ data: false,
666
+ created: Date.now(),
667
+ };
666
668
  // The method is parsed and depending on what method is asked for it returns
667
669
  // the response based on the passed through packet.
668
670
  this.methods[method](packet).then(result => {
@@ -714,7 +716,7 @@ class Deva {
714
716
  this._active = Date.now();
715
717
  const agent = this.agent();
716
718
 
717
- const _data = {
719
+ const data = {
718
720
  id: this.lib.uid(),
719
721
  key: 'init',
720
722
  value: agent.key,
@@ -723,7 +725,7 @@ class Deva {
723
725
  text: this._messages.init,
724
726
  created: Date.now(),
725
727
  }
726
- _data.hash = this.lib.hash(_data);
728
+ data.hash = this.lib.hash(data);
727
729
  return new Promise((resolve, reject) => {
728
730
  this.events.setMaxListeners(this.maxListeners);
729
731
  this._assignInherit().then(() => {
@@ -760,8 +762,10 @@ class Deva {
760
762
  return this.Done(resolve, reject);
761
763
  }).then(() => {
762
764
  const hasOnInit = this.onInit && typeof this.onInit === 'function';
763
- return hasOnInit ? this.onInit(_data, resolve) : this.start(_data, resolve);
765
+ this.state('return', `init:${data.id}`);
766
+ return hasOnInit ? this.onInit(data, resolve) : this.start(data, resolve);
764
767
  }).catch(err => {
768
+ this.state('catch', `init:${data.id}`);
765
769
  return this.error(err, client, reject);
766
770
  });
767
771
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.5.11",
3
+ "version": "1.5.13",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "copyright": "(c)2025 Quinn Michaels; All rights reserved.",
@@ -200,7 +200,7 @@
200
200
  "authority": "👮 Authority",
201
201
  "talk": "📢 Talk",
202
202
  "listen": "👂 Listen",
203
- "once": "👂 Listen Once",
203
+ "once": "👂 Once",
204
204
  "ignore": "🦯 Ignore",
205
205
  "question": "🙋 Question",
206
206
  "answer": "💡 Answer",