@indra.ai/deva 1.1.14 → 1.1.15
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 +22 -22
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -29,11 +29,12 @@ class Deva {
|
|
|
29
29
|
data: '📀 DATA',
|
|
30
30
|
ask: '🙋♀️ ASK',
|
|
31
31
|
cmd: '📟 COMMAND',
|
|
32
|
-
question: '
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
question: '🤖 QUESTION',
|
|
33
|
+
question_ask: '🤖 SEND QUEATION TO ASK',
|
|
34
|
+
question_cmd: '🤖 SEND QUESTION TO CMD',
|
|
35
|
+
queation_answer: '🔮 ANSWER QUESTION',
|
|
36
|
+
ask_question: '🤖 ASK QUESTION',
|
|
37
|
+
ask_answer: '🔮 ASK ANSWER',
|
|
37
38
|
talk: '🎙️ TALK',
|
|
38
39
|
listen: '🎧 LISTEN',
|
|
39
40
|
error: '❌ ERROR',
|
|
@@ -87,10 +88,10 @@ class Deva {
|
|
|
87
88
|
- st: The state flag to set for the Deva that matches to this._states
|
|
88
89
|
describe
|
|
89
90
|
***************/
|
|
90
|
-
state(st) {
|
|
91
|
+
state(st, data=false) {
|
|
91
92
|
this._state = this._states[st];
|
|
92
93
|
this.prompt(this._state);
|
|
93
|
-
this.talk(`${this.agent.
|
|
94
|
+
this.talk(`${this.agent.key}:state`, data);
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
// Called from the init function to bind the elements defined in the this.bind variable.
|
|
@@ -339,7 +340,7 @@ class Deva {
|
|
|
339
340
|
***************/
|
|
340
341
|
ask(packet) {
|
|
341
342
|
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
342
|
-
this.state('
|
|
343
|
+
this.state('ask_question', packet);
|
|
343
344
|
|
|
344
345
|
packet.a = {
|
|
345
346
|
agent: this.agent || false,
|
|
@@ -374,6 +375,8 @@ class Deva {
|
|
|
374
375
|
else {
|
|
375
376
|
packet.a.text = result;
|
|
376
377
|
}
|
|
378
|
+
|
|
379
|
+
this.state('ask_answer', packet);
|
|
377
380
|
this.talk(`${this.agent.key}:ask:${packet.id}`, packet);
|
|
378
381
|
}).catch(err => {
|
|
379
382
|
this.talk(`${this.agent.key}:ask:${packet.id}`, {error:err.toString()});
|
|
@@ -399,8 +402,6 @@ class Deva {
|
|
|
399
402
|
question(TEXT=false, DATA=false) {
|
|
400
403
|
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
401
404
|
|
|
402
|
-
this.state('question'); // set the state to question.
|
|
403
|
-
|
|
404
405
|
const id = this.uid(); // generate a unique transport id for the question.
|
|
405
406
|
const t_split = TEXT.split(' ');
|
|
406
407
|
|
|
@@ -436,21 +437,20 @@ class Deva {
|
|
|
436
437
|
// #agent method:param1:param2 with text strings for proccessing
|
|
437
438
|
// !method param:list:parse for the local agent
|
|
438
439
|
// if is an ask then we format one way
|
|
439
|
-
let _state = '
|
|
440
|
+
let _state = 'question';
|
|
440
441
|
if (isAsk) {
|
|
441
|
-
_state = '
|
|
442
|
+
_state = 'question_ask'
|
|
442
443
|
key = t_split[0]substring(1);
|
|
443
444
|
params = t_split[1] ? t_split[1].split(':') : false;
|
|
444
445
|
method = params[0];
|
|
445
446
|
text = t_split.slice(2).join(' ').trim();
|
|
446
447
|
}
|
|
447
448
|
else if (isCmd) {
|
|
448
|
-
_state = '
|
|
449
|
+
_state = 'question_cmd'
|
|
449
450
|
params = t_split[1] ? t_split[1].split(':') : false;
|
|
450
451
|
method = isCmd;
|
|
451
452
|
text = t_split.slice(1).join(' ').trim()
|
|
452
453
|
}
|
|
453
|
-
this.state(_state);
|
|
454
454
|
|
|
455
455
|
packet.q = {
|
|
456
456
|
agent: this.agent || false,
|
|
@@ -468,6 +468,7 @@ class Deva {
|
|
|
468
468
|
|
|
469
469
|
// hash the packet and insert the hash into the packet meta object.
|
|
470
470
|
packet.q.meta.hash = this.hash(JSON.stringify(packet.q));
|
|
471
|
+
this.state(_state, packet);
|
|
471
472
|
|
|
472
473
|
// If a question to another Deva with '#' then trigger events
|
|
473
474
|
if (isAsk) {
|
|
@@ -479,7 +480,6 @@ class Deva {
|
|
|
479
480
|
// if the user sends a local command '$' then it will ask of the self.
|
|
480
481
|
else {
|
|
481
482
|
if (typeof this.methods[method] !== 'function') {
|
|
482
|
-
this.state('answer_cmd');
|
|
483
483
|
return resolve(this._methodNotFound(packet));
|
|
484
484
|
}
|
|
485
485
|
this.methods[method](packet).then(result => {
|
|
@@ -541,7 +541,7 @@ class Deva {
|
|
|
541
541
|
return this._assignListeners();
|
|
542
542
|
}).then(() => {
|
|
543
543
|
this.state('init');
|
|
544
|
-
return this.onInit && typeof this.onInit === 'function' ? this.onInit() : this.start();
|
|
544
|
+
return this.onInit && typeof this.onInit === 'function' ? this.onInit() : this.start(this._state);
|
|
545
545
|
}).then(started => {
|
|
546
546
|
return resolve(started)
|
|
547
547
|
}).catch(err => {
|
|
@@ -555,10 +555,10 @@ class Deva {
|
|
|
555
555
|
// e: is the error to pass into the interface.
|
|
556
556
|
// packet: the packet that caused the error.
|
|
557
557
|
error(err,packet=false,reject=false) {
|
|
558
|
-
this.state('error');
|
|
558
|
+
this.state('error', err);
|
|
559
|
+
if (this.onError && typeof this.onError === 'function') ? return this.onError(err, packet, reject);
|
|
559
560
|
console.error(err)
|
|
560
|
-
|
|
561
|
-
return reject ? reject(err) : false;
|
|
561
|
+
return reject ? reject(err) : err;
|
|
562
562
|
}
|
|
563
563
|
|
|
564
564
|
/**************
|
|
@@ -572,7 +572,7 @@ class Deva {
|
|
|
572
572
|
start() {
|
|
573
573
|
if (!this._active) return;
|
|
574
574
|
this.state('start');
|
|
575
|
-
return this.onStart && typeof this.onStart === 'function' ? this.onStart() : this.enter();
|
|
575
|
+
return this.onStart && typeof this.onStart === 'function' ? this.onStart() : this.enter(this._state);
|
|
576
576
|
}
|
|
577
577
|
|
|
578
578
|
/**************
|
|
@@ -589,7 +589,7 @@ class Deva {
|
|
|
589
589
|
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
590
590
|
this.state('stop');
|
|
591
591
|
this._active = false;
|
|
592
|
-
return this.onStop && typeof this.onStop === 'function' ? this.onStop() : this.exit();
|
|
592
|
+
return this.onStop && typeof this.onStop === 'function' ? this.onStop() : this.exit(this._state);
|
|
593
593
|
}
|
|
594
594
|
|
|
595
595
|
/**************
|
|
@@ -604,7 +604,7 @@ class Deva {
|
|
|
604
604
|
enter() {
|
|
605
605
|
if (!this._active) return Promise.resolve(this.messages.offline);
|
|
606
606
|
this.state('enter');
|
|
607
|
-
return this.onEnter && typeof this.onEnter === 'function' ? this.onEnter() : this.done(this.
|
|
607
|
+
return this.onEnter && typeof this.onEnter === 'function' ? this.onEnter() : this.done(this._state)
|
|
608
608
|
}
|
|
609
609
|
|
|
610
610
|
/**************
|