@indra.ai/deva 1.5.10 → 1.5.12
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 +37 -35
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -407,9 +407,9 @@ class Deva {
|
|
|
407
407
|
to and make a response. talk events can be then returned with a talk even id
|
|
408
408
|
to create seamless collaboration between Devas.
|
|
409
409
|
***************/
|
|
410
|
-
talk(evt,
|
|
411
|
-
this.action('talk', evt);
|
|
412
|
-
return this.events.emit(evt,
|
|
410
|
+
talk(evt, packet=false) {
|
|
411
|
+
this.action('talk', `${evt}:${packet.id}`);
|
|
412
|
+
return this.events.emit(evt, packet);
|
|
413
413
|
}
|
|
414
414
|
|
|
415
415
|
/**************
|
|
@@ -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
|
|
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('
|
|
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
|
}
|
|
@@ -633,36 +634,37 @@ class Deva {
|
|
|
633
634
|
ask(packet) {
|
|
634
635
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
635
636
|
const {method, params} = packet.q.meta;
|
|
636
|
-
this.zone('ask', method);
|
|
637
|
+
this.zone('ask', `${method}:${packet.id}`);
|
|
637
638
|
|
|
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`);
|
|
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
|
-
this.state('try', `ask:${method}`);
|
|
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
|
-
this.state('invalid', method);
|
|
648
|
+
this.state('invalid', `${method}:${packet.id}`);
|
|
662
649
|
this.talk(`${this._agent.key}:ask:${packet.id}`, this._methodNotFound(packet));
|
|
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 => {
|
|
@@ -681,12 +683,12 @@ class Deva {
|
|
|
681
683
|
this.talk(`${agent.key}:ask:${packet.id}`, packet);
|
|
682
684
|
}).catch(err => {
|
|
683
685
|
this.talk(`${agent.key}:ask:${packet.id}`, {error:err});
|
|
684
|
-
this.state('catch', `ask:${method}`);
|
|
686
|
+
this.state('catch', `ask:${method}:${packet.id}`);
|
|
685
687
|
return this.error(err, packet);
|
|
686
688
|
})
|
|
687
689
|
}
|
|
688
690
|
catch (e) {
|
|
689
|
-
this.state('catch', `ask:${method}`);
|
|
691
|
+
this.state('catch', `ask:${method}:${packet.id}`);
|
|
690
692
|
this.talk(`${agent.key}:ask:${packet.id}`, {error:e});
|
|
691
693
|
return this.error(e, packet)
|
|
692
694
|
}
|
|
@@ -1206,8 +1208,8 @@ class Deva {
|
|
|
1206
1208
|
***************/
|
|
1207
1209
|
context(value=false, extra=false) {
|
|
1208
1210
|
const id = this.lib.uid();
|
|
1209
|
-
this.action('context', value);
|
|
1210
|
-
this.state('try', `context:${value}`);
|
|
1211
|
+
this.action('context', `${value}:${id}`);
|
|
1212
|
+
this.state('try', `context:${value}:${id}`);
|
|
1211
1213
|
try {
|
|
1212
1214
|
if (!value) return;
|
|
1213
1215
|
this.state('set', `context:${value}:${id}`);
|
|
@@ -1226,7 +1228,7 @@ class Deva {
|
|
|
1226
1228
|
};
|
|
1227
1229
|
data.hash = this.lib.hash(data);
|
|
1228
1230
|
this.talk(config.events.context, data);
|
|
1229
|
-
this.state('return', `context:${value}:${
|
|
1231
|
+
this.state('return', `context:${value}:${id}`);
|
|
1230
1232
|
return data;
|
|
1231
1233
|
} catch (e) {
|
|
1232
1234
|
this.state('catch', `context:${value}:${id}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indra.ai/deva",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.12",
|
|
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": "👂
|
|
203
|
+
"once": "👂 Once",
|
|
204
204
|
"ignore": "🦯 Ignore",
|
|
205
205
|
"question": "🙋 Question",
|
|
206
206
|
"answer": "💡 Answer",
|