@indra.ai/deva 1.1.2 → 1.1.4
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 +14 -13
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -323,7 +323,7 @@ class Deva {
|
|
|
323
323
|
so the event is specific to the talk.
|
|
324
324
|
***************/
|
|
325
325
|
ask(packet) {
|
|
326
|
-
if (!this.
|
|
326
|
+
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
327
327
|
|
|
328
328
|
this.state('ask');
|
|
329
329
|
|
|
@@ -384,7 +384,7 @@ class Deva {
|
|
|
384
384
|
describe:
|
|
385
385
|
***************/
|
|
386
386
|
question(TEXT=false, DATA=false) {
|
|
387
|
-
if (!this.
|
|
387
|
+
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
388
388
|
|
|
389
389
|
this.state('question'); // set the state to question.
|
|
390
390
|
|
|
@@ -415,7 +415,7 @@ class Deva {
|
|
|
415
415
|
return new Promise((resolve, reject) => {
|
|
416
416
|
if (!TEXT) return reject(this.messages.notext);
|
|
417
417
|
try {
|
|
418
|
-
if (!this.
|
|
418
|
+
if (!this._active) return reject(this.messages.offline);
|
|
419
419
|
|
|
420
420
|
// *: send just a string of text
|
|
421
421
|
// !: send a command to the local agent
|
|
@@ -488,6 +488,7 @@ class Deva {
|
|
|
488
488
|
packet.hash = this.hash(JSON.stringify(packet));
|
|
489
489
|
|
|
490
490
|
this.state('wait');
|
|
491
|
+
this.talk(`${this.agent.id}:log`, packet);
|
|
491
492
|
return resolve(packet);
|
|
492
493
|
}).catch(err => {
|
|
493
494
|
return this.error(err, packet);
|
|
@@ -515,7 +516,7 @@ class Deva {
|
|
|
515
516
|
7. If there is an error the init function rejects the call.
|
|
516
517
|
***************/
|
|
517
518
|
init() {
|
|
518
|
-
this.
|
|
519
|
+
this._active = Date.now();
|
|
519
520
|
// set client
|
|
520
521
|
return new Promise((resolve, reject) => {
|
|
521
522
|
this.events.setMaxListeners(this.maxListeners);
|
|
@@ -554,7 +555,7 @@ class Deva {
|
|
|
554
555
|
function or running the system enter function.
|
|
555
556
|
***************/
|
|
556
557
|
start() {
|
|
557
|
-
if (!this.
|
|
558
|
+
if (!this._active) return;
|
|
558
559
|
this.state('start');
|
|
559
560
|
return this.onStart && typeof this.onStart === 'function' ? this.onStart() : this.enter();
|
|
560
561
|
}
|
|
@@ -570,9 +571,9 @@ class Deva {
|
|
|
570
571
|
If the deva is offline it will return the offline message.
|
|
571
572
|
***************/
|
|
572
573
|
stop() {
|
|
573
|
-
if (!this.
|
|
574
|
+
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
574
575
|
this.state('stop');
|
|
575
|
-
this.
|
|
576
|
+
this._active = false;
|
|
576
577
|
return this.onStop && typeof this.onStop === 'function' ? this.onStop() : this.exit();
|
|
577
578
|
}
|
|
578
579
|
|
|
@@ -586,7 +587,7 @@ class Deva {
|
|
|
586
587
|
If the Deva is offline it will return the offline message.
|
|
587
588
|
***************/
|
|
588
589
|
enter() {
|
|
589
|
-
if (!this.
|
|
590
|
+
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
590
591
|
this.state('enter');
|
|
591
592
|
return this.onEnter && typeof this.onEnter === 'function' ? this.onEnter() : this.done(this.state)
|
|
592
593
|
}
|
|
@@ -604,9 +605,9 @@ class Deva {
|
|
|
604
605
|
If the deva is offline it will return the offline message.
|
|
605
606
|
***************/
|
|
606
607
|
exit() {
|
|
607
|
-
if (!this.
|
|
608
|
+
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
608
609
|
this.state('exit');
|
|
609
|
-
this.
|
|
610
|
+
this._active = false;
|
|
610
611
|
return this.onExit && typeof this.onExit === 'function' ? this.onExit() : Promise.resolve(this._state)
|
|
611
612
|
}
|
|
612
613
|
|
|
@@ -621,7 +622,7 @@ class Deva {
|
|
|
621
622
|
If the deva is offline it will return the offline message.
|
|
622
623
|
***************/
|
|
623
624
|
done(msg=false) {
|
|
624
|
-
if (!this.
|
|
625
|
+
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
625
626
|
this.state('done');
|
|
626
627
|
msg = msg ? msg : this._state;
|
|
627
628
|
return this.onDone && typeof this.onDone === 'function' ? this.onDone() : Promise.resolve(this._state)
|
|
@@ -638,9 +639,9 @@ class Deva {
|
|
|
638
639
|
If the deva is offline it will return the offline message.
|
|
639
640
|
***************/
|
|
640
641
|
status(addto=false) {
|
|
641
|
-
if (!this.
|
|
642
|
+
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
642
643
|
const id = this.uid();
|
|
643
|
-
const dateFormat = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'medium' }).format(this.
|
|
644
|
+
const dateFormat = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'medium' }).format(this._active);
|
|
644
645
|
let text = `${this.agent.name} is ONLINE since ${dateFormat}`;
|
|
645
646
|
if (addto) text = text + `\n${addto}`;
|
|
646
647
|
return Promise.resolve({text});
|