@indra.ai/deva 1.1.1 → 1.1.3
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
|
@@ -78,6 +78,7 @@ class Deva {
|
|
|
78
78
|
***************/
|
|
79
79
|
state(st) {
|
|
80
80
|
this._state = this._states[st];
|
|
81
|
+
this.prompt(this._state);
|
|
81
82
|
this.talk(`${this.agent.id}:state`, this._state);
|
|
82
83
|
}
|
|
83
84
|
|
|
@@ -322,7 +323,7 @@ class Deva {
|
|
|
322
323
|
so the event is specific to the talk.
|
|
323
324
|
***************/
|
|
324
325
|
ask(packet) {
|
|
325
|
-
if (!this.
|
|
326
|
+
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
326
327
|
|
|
327
328
|
this.state('ask');
|
|
328
329
|
|
|
@@ -383,7 +384,7 @@ class Deva {
|
|
|
383
384
|
describe:
|
|
384
385
|
***************/
|
|
385
386
|
question(TEXT=false, DATA=false) {
|
|
386
|
-
if (!this.
|
|
387
|
+
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
387
388
|
|
|
388
389
|
this.state('question'); // set the state to question.
|
|
389
390
|
|
|
@@ -414,7 +415,7 @@ class Deva {
|
|
|
414
415
|
return new Promise((resolve, reject) => {
|
|
415
416
|
if (!TEXT) return reject(this.messages.notext);
|
|
416
417
|
try {
|
|
417
|
-
if (!this.
|
|
418
|
+
if (!this._active) return reject(this.messages.offline);
|
|
418
419
|
|
|
419
420
|
// *: send just a string of text
|
|
420
421
|
// !: send a command to the local agent
|
|
@@ -514,7 +515,7 @@ class Deva {
|
|
|
514
515
|
7. If there is an error the init function rejects the call.
|
|
515
516
|
***************/
|
|
516
517
|
init() {
|
|
517
|
-
this.
|
|
518
|
+
this._active = Date.now();
|
|
518
519
|
// set client
|
|
519
520
|
return new Promise((resolve, reject) => {
|
|
520
521
|
this.events.setMaxListeners(this.maxListeners);
|
|
@@ -553,7 +554,7 @@ class Deva {
|
|
|
553
554
|
function or running the system enter function.
|
|
554
555
|
***************/
|
|
555
556
|
start() {
|
|
556
|
-
if (!this.
|
|
557
|
+
if (!this._active) return;
|
|
557
558
|
this.state('start');
|
|
558
559
|
return this.onStart && typeof this.onStart === 'function' ? this.onStart() : this.enter();
|
|
559
560
|
}
|
|
@@ -569,9 +570,9 @@ class Deva {
|
|
|
569
570
|
If the deva is offline it will return the offline message.
|
|
570
571
|
***************/
|
|
571
572
|
stop() {
|
|
572
|
-
if (!this.
|
|
573
|
+
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
573
574
|
this.state('stop');
|
|
574
|
-
this.
|
|
575
|
+
this._active = false;
|
|
575
576
|
return this.onStop && typeof this.onStop === 'function' ? this.onStop() : this.exit();
|
|
576
577
|
}
|
|
577
578
|
|
|
@@ -585,7 +586,7 @@ class Deva {
|
|
|
585
586
|
If the Deva is offline it will return the offline message.
|
|
586
587
|
***************/
|
|
587
588
|
enter() {
|
|
588
|
-
if (!this.
|
|
589
|
+
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
589
590
|
this.state('enter');
|
|
590
591
|
return this.onEnter && typeof this.onEnter === 'function' ? this.onEnter() : this.done(this.state)
|
|
591
592
|
}
|
|
@@ -603,9 +604,9 @@ class Deva {
|
|
|
603
604
|
If the deva is offline it will return the offline message.
|
|
604
605
|
***************/
|
|
605
606
|
exit() {
|
|
606
|
-
if (!this.
|
|
607
|
+
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
607
608
|
this.state('exit');
|
|
608
|
-
this.
|
|
609
|
+
this._active = false;
|
|
609
610
|
return this.onExit && typeof this.onExit === 'function' ? this.onExit() : Promise.resolve(this._state)
|
|
610
611
|
}
|
|
611
612
|
|
|
@@ -620,7 +621,7 @@ class Deva {
|
|
|
620
621
|
If the deva is offline it will return the offline message.
|
|
621
622
|
***************/
|
|
622
623
|
done(msg=false) {
|
|
623
|
-
if (!this.
|
|
624
|
+
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
624
625
|
this.state('done');
|
|
625
626
|
msg = msg ? msg : this._state;
|
|
626
627
|
return this.onDone && typeof this.onDone === 'function' ? this.onDone() : Promise.resolve(this._state)
|
|
@@ -637,9 +638,9 @@ class Deva {
|
|
|
637
638
|
If the deva is offline it will return the offline message.
|
|
638
639
|
***************/
|
|
639
640
|
status(addto=false) {
|
|
640
|
-
if (!this.
|
|
641
|
+
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
641
642
|
const id = this.uid();
|
|
642
|
-
const dateFormat = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'medium' }).format(this.
|
|
643
|
+
const dateFormat = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'medium' }).format(this._active);
|
|
643
644
|
let text = `${this.agent.name} is ONLINE since ${dateFormat}`;
|
|
644
645
|
if (addto) text = text + `\n${addto}`;
|
|
645
646
|
return Promise.resolve({text});
|