@indra.ai/deva 1.4.23 → 1.4.24

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 +50 -45
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -530,12 +530,12 @@ class Deva {
530
530
 
531
531
  if (isAsk) { // isAsk check if the question isAsk and talk
532
532
  // if: isAsk wait for the once event which is key'd to the packet ID for specified responses
533
- this.zone('ask', key);
534
533
  this.action('talk', `${key}:ask`);
535
534
  this.talk(`${key}:ask`, packet);
536
535
  this.once(`${key}:ask:${packet.id}`, answer => {
537
536
  this.action('talk', config.events.ask);
538
537
  this.talk(config.events.ask, this.lib.copy(answer));
538
+ this.state('finish', `${key}:ask`);
539
539
  return this.finish(answer, resolve); // if:isAsk resolve the answer from the call
540
540
  });
541
541
  }
@@ -558,7 +558,7 @@ class Deva {
558
558
  - resolve
559
559
  - reject
560
560
  describe:
561
- The answer function is called from the question fuction to return an answer
561
+ The answer function is called from the question function to return an answer
562
562
  from the agent from the pre-determined method.
563
563
  ***************/
564
564
  answer(packet, resolve, reject) {
@@ -570,46 +570,50 @@ class Deva {
570
570
  // check if method exists and is of type function
571
571
  const {method,params} = packet.q.meta;
572
572
 
573
- const isMethod = this.methods[method] && typeof this.methods[method] == 'function';
574
- if (!isMethod) return resolve(this._methodNotFound(packet)); // resolve method not found if check if check fails
575
-
576
- // Call the local method to process the question based the extracted parameters
577
- this.action('method', method);
578
- this.methods[method](packet).then(result => {
579
- // check the result for the text, html, and data object.
580
- // this is for when answers are returned from nested Devas.
581
- const text = typeof result === 'object' ? result.text : result;
582
- const html = typeof result === 'object' ? result.html : result;
583
- // if the data passed is NOT an object it will FALSE
584
- const data = typeof result === 'object' ? result.data : false;
585
-
586
- this.state('set', 'answer');
587
- const packet_answer = { // setup the packet.a container
588
- id: this.lib.uid(),
589
- agent, // set the agent who answered the question
590
- client, // set the client asking the question
591
- meta: { // setup the answer meta container
592
- key: agent.key, // set the agent key inot the meta
593
- method, // set the method into the meta
594
- params, // set the params into the meta
595
- },
596
- text, // set answer text
597
- html, // set the answer html
598
- data, // set the answer data
599
- created: Date.now(), // set the created date for the answer
600
- };
601
- // create a hash for the answer and insert into answer meta.
602
- this.action('talk', config.events.answer)
603
- packet_answer.meta.hash = this.lib.hash(packet_answer);
604
- packet.a = packet_answer; // set the packet.a to the packet_answer
605
- this.talk(config.events.answer, this.lib.copy(packet)); // global talk event
606
-
607
- this.state('finish', 'answer'); // set the state resolve answer
608
- return this.finish(packet, resolve); // resolve the packet to the caller.
609
- }).catch(err => { // catch any errors in the method
610
- this.state('catch', 'answer'); // set the state reject answer
611
- return this.error(err, packet, reject); // return this.error with err, packet, reject
612
- });
573
+ this.state('try', `answer:${method}`);
574
+ try {
575
+ const isMethod = this.methods[method] && typeof this.methods[method] == 'function';
576
+ if (!isMethod) return resolve(this._methodNotFound(packet)); // resolve method not found if check if check fails
577
+
578
+ this.action('method', method);
579
+ this.methods[method](packet).then(result => {
580
+ // check the result for the text, html, and data object. // this is for when answers are returned from nested Devas.
581
+ const text = typeof result === 'object' ? result.text : result;
582
+ const html = typeof result === 'object' ? result.html : result;
583
+ // if the data passed is NOT an object it will FALSE
584
+ const data = typeof result === 'object' ? result.data : false;
585
+
586
+ this.state('set', `answer:${method}:packet_answer`);
587
+ const packet_answer = { // setup the packet.a container
588
+ id: this.lib.uid(),
589
+ agent, // set the agent who answered the question
590
+ client, // set the client asking the question
591
+ meta: { // setup the answer meta container
592
+ key: agent.key, // set the agent key inot the meta
593
+ method, // set the method into the meta
594
+ params, // set the params into the meta
595
+ },
596
+ text, // set answer text
597
+ html, // set the answer html
598
+ data, // set the answer data
599
+ created: Date.now(), // set the created date for the answer
600
+ };
601
+ // create a hash for the answer and insert into answer meta.
602
+ this.action('talk', config.events.answer)
603
+ packet_answer.meta.hash = this.lib.hash(packet_answer);
604
+ packet.a = packet_answer; // set the packet.a to the packet_answer
605
+ this.talk(config.events.answer, this.lib.copy(packet)); // global talk event
606
+
607
+ this.state('finish', `answer:${method}`); // set the state resolve answer
608
+ return this.finish(packet, resolve); // resolve the packet to the caller.
609
+ }).catch(err => { // catch any errors in the method
610
+ this.state('catch', `answer:${method}`); // set the state reject answer
611
+ return this.error(err, packet, reject); // return this.error with err, packet, reject
612
+ });
613
+ } catch (e) {
614
+ this.state('catch', `answer:${method}`);
615
+ return this.error(e, packet, reject);
616
+ }
613
617
  }
614
618
 
615
619
  /**************
@@ -635,7 +639,7 @@ class Deva {
635
639
  const agent = this.agent();
636
640
  const client = this.client();
637
641
  // build the answer packet from this model
638
- this.state('set', 'answer');
642
+ this.state('set', `ask:${method}:packet_answer`);
639
643
  const packet_answer = {
640
644
  id: this.lib.uid(),
641
645
  agent,
@@ -651,7 +655,7 @@ class Deva {
651
655
  created: Date.now(),
652
656
  };
653
657
 
654
- this.state('try', method);
658
+ this.state('try', `ask:${method}`);
655
659
  try {
656
660
  if (typeof this.methods[method] !== 'function') {
657
661
  return setImmediate(() => {
@@ -680,11 +684,12 @@ class Deva {
680
684
  this.talk(`${agent.key}:ask:${packet.id}`, packet);
681
685
  }).catch(err => {
682
686
  this.talk(`${agent.key}:ask:${packet.id}`, {error:err});
683
- this.state('catch', 'ask');
687
+ this.state('catch', `ask:${method}`);
684
688
  return this.error(err, packet);
685
689
  })
686
690
  }
687
691
  catch (e) {
692
+ this.state('catch', `ask:${method}`);
688
693
  this.talk(`${agent.key}:ask:${packet.id}`, {error:e});
689
694
  return this.error(e, packet)
690
695
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.4.23",
3
+ "version": "1.4.24",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "copyright": "(c)2025 Quinn Michaels; All rights reserved.",