@indra.ai/deva 1.1.17 → 1.1.19
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 +18 -11
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -190,6 +190,13 @@ class Deva {
|
|
|
190
190
|
***************/
|
|
191
191
|
_assignInherit() {
|
|
192
192
|
return new Promise((resolve, reject) => {
|
|
193
|
+
// set the default listeners for the states of the agent.
|
|
194
|
+
for (let state in this._states) {
|
|
195
|
+
this.events.on(`${this.agent.key}:${state}`, packet => {
|
|
196
|
+
return this[state](packet);
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
|
|
193
200
|
try {
|
|
194
201
|
for (let d in this.devas) {
|
|
195
202
|
this.inherit.forEach(inherit => {
|
|
@@ -560,7 +567,7 @@ class Deva {
|
|
|
560
567
|
return this._assignListeners();
|
|
561
568
|
}).then(() => {
|
|
562
569
|
this.state('init');
|
|
563
|
-
return this.onInit && typeof this.onInit === 'function' ? this.onInit() : this.start(
|
|
570
|
+
return this.onInit && typeof this.onInit === 'function' ? this.onInit() : this.start();
|
|
564
571
|
}).then(started => {
|
|
565
572
|
return resolve(started)
|
|
566
573
|
}).catch(err => {
|
|
@@ -588,15 +595,15 @@ class Deva {
|
|
|
588
595
|
the active to the current datetime and then checking for a custom onStart
|
|
589
596
|
function or running the system enter function.
|
|
590
597
|
***************/
|
|
591
|
-
start() {
|
|
592
|
-
if (!this._active) return;
|
|
598
|
+
start(msg=false) {
|
|
599
|
+
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
593
600
|
this.state('start');
|
|
594
601
|
return this.onStart && typeof this.onStart === 'function' ? this.onStart() : this.enter(this._messages.start);
|
|
595
602
|
}
|
|
596
603
|
|
|
597
604
|
/**************
|
|
598
605
|
func: stop
|
|
599
|
-
params:
|
|
606
|
+
params: msg - hte message from the caller incase need to use in calls
|
|
600
607
|
describe:
|
|
601
608
|
The stop function will stop the Deva by setting the active status to false,
|
|
602
609
|
and the state to stop. From here it will check for a custom onStop function
|
|
@@ -604,7 +611,7 @@ class Deva {
|
|
|
604
611
|
|
|
605
612
|
If the deva is offline it will return the offline message.
|
|
606
613
|
***************/
|
|
607
|
-
stop() {
|
|
614
|
+
stop(msg=false) {
|
|
608
615
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
609
616
|
this.state('stop');
|
|
610
617
|
this._active = false;
|
|
@@ -613,14 +620,14 @@ class Deva {
|
|
|
613
620
|
|
|
614
621
|
/**************
|
|
615
622
|
func: enter
|
|
616
|
-
params:
|
|
623
|
+
params: msg - hte message from the caller incase need to use in calls
|
|
617
624
|
describe:
|
|
618
625
|
The ener function will check the actie status of the Deva and set it to
|
|
619
626
|
offline or enter.
|
|
620
627
|
|
|
621
628
|
If the Deva is offline it will return the offline message.
|
|
622
629
|
***************/
|
|
623
|
-
enter() {
|
|
630
|
+
enter(msg=false) {
|
|
624
631
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
625
632
|
this.state('enter');
|
|
626
633
|
return this.onEnter && typeof this.onEnter === 'function' ? this.onEnter() : this.done(this._messages.enter)
|
|
@@ -628,7 +635,7 @@ class Deva {
|
|
|
628
635
|
|
|
629
636
|
/**************
|
|
630
637
|
func: exit
|
|
631
|
-
params:
|
|
638
|
+
params: msg - hte message from the caller incase need to use in calls
|
|
632
639
|
describe:
|
|
633
640
|
The exit state function is triggered when the Deva is exiting it's online
|
|
634
641
|
status and setting the state to exit for things like security check.
|
|
@@ -638,7 +645,7 @@ class Deva {
|
|
|
638
645
|
|
|
639
646
|
If the deva is offline it will return the offline message.
|
|
640
647
|
***************/
|
|
641
|
-
exit() {
|
|
648
|
+
exit(msg=false) {
|
|
642
649
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
643
650
|
this.state('exit');
|
|
644
651
|
this._active = false;
|
|
@@ -672,12 +679,12 @@ class Deva {
|
|
|
672
679
|
|
|
673
680
|
If the deva is offline it will return the offline message.
|
|
674
681
|
***************/
|
|
675
|
-
status(
|
|
682
|
+
status(ammend=false) {
|
|
676
683
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
677
684
|
const id = this.uid();
|
|
678
685
|
const dateFormat = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'medium' }).format(this._active);
|
|
679
686
|
let text = `${this.agent.name} is ONLINE since ${dateFormat}`;
|
|
680
|
-
if (
|
|
687
|
+
if (ammend) text = text + `\n${ammend}`;
|
|
681
688
|
return Promise.resolve({text});
|
|
682
689
|
}
|
|
683
690
|
|