@indra.ai/deva 1.4.22 → 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.
- package/index.js +50 -44
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -535,6 +535,7 @@ class Deva {
|
|
|
535
535
|
this.once(`${key}:ask:${packet.id}`, answer => {
|
|
536
536
|
this.action('talk', config.events.ask);
|
|
537
537
|
this.talk(config.events.ask, this.lib.copy(answer));
|
|
538
|
+
this.state('finish', `${key}:ask`);
|
|
538
539
|
return this.finish(answer, resolve); // if:isAsk resolve the answer from the call
|
|
539
540
|
});
|
|
540
541
|
}
|
|
@@ -557,7 +558,7 @@ class Deva {
|
|
|
557
558
|
- resolve
|
|
558
559
|
- reject
|
|
559
560
|
describe:
|
|
560
|
-
The answer function is called from the question
|
|
561
|
+
The answer function is called from the question function to return an answer
|
|
561
562
|
from the agent from the pre-determined method.
|
|
562
563
|
***************/
|
|
563
564
|
answer(packet, resolve, reject) {
|
|
@@ -569,46 +570,50 @@ class Deva {
|
|
|
569
570
|
// check if method exists and is of type function
|
|
570
571
|
const {method,params} = packet.q.meta;
|
|
571
572
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
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
|
+
}
|
|
612
617
|
}
|
|
613
618
|
|
|
614
619
|
/**************
|
|
@@ -634,7 +639,7 @@ class Deva {
|
|
|
634
639
|
const agent = this.agent();
|
|
635
640
|
const client = this.client();
|
|
636
641
|
// build the answer packet from this model
|
|
637
|
-
this.state('set',
|
|
642
|
+
this.state('set', `ask:${method}:packet_answer`);
|
|
638
643
|
const packet_answer = {
|
|
639
644
|
id: this.lib.uid(),
|
|
640
645
|
agent,
|
|
@@ -650,7 +655,7 @@ class Deva {
|
|
|
650
655
|
created: Date.now(),
|
|
651
656
|
};
|
|
652
657
|
|
|
653
|
-
this.state('try', method);
|
|
658
|
+
this.state('try', `ask:${method}`);
|
|
654
659
|
try {
|
|
655
660
|
if (typeof this.methods[method] !== 'function') {
|
|
656
661
|
return setImmediate(() => {
|
|
@@ -679,11 +684,12 @@ class Deva {
|
|
|
679
684
|
this.talk(`${agent.key}:ask:${packet.id}`, packet);
|
|
680
685
|
}).catch(err => {
|
|
681
686
|
this.talk(`${agent.key}:ask:${packet.id}`, {error:err});
|
|
682
|
-
this.state('catch',
|
|
687
|
+
this.state('catch', `ask:${method}`);
|
|
683
688
|
return this.error(err, packet);
|
|
684
689
|
})
|
|
685
690
|
}
|
|
686
691
|
catch (e) {
|
|
692
|
+
this.state('catch', `ask:${method}`);
|
|
687
693
|
this.talk(`${agent.key}:ask:${packet.id}`, {error:e});
|
|
688
694
|
return this.error(e, packet)
|
|
689
695
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indra.ai/deva",
|
|
3
|
-
"version": "1.4.
|
|
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.",
|
|
@@ -82,7 +82,8 @@
|
|
|
82
82
|
"zone": "deva",
|
|
83
83
|
"zones": {
|
|
84
84
|
"question": "🙋♂️ Question",
|
|
85
|
-
"answer": "👨🏫
|
|
85
|
+
"answer": "👨🏫 Answer",
|
|
86
|
+
"ask": "📣 Ask",
|
|
86
87
|
"load": "🚛 Load",
|
|
87
88
|
"unload": "🛻 Unload",
|
|
88
89
|
"init": "🚀 Init",
|