@indra.ai/deva 1.1.12 → 1.1.14

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.
Files changed (2) hide show
  1. package/index.js +17 -12
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -28,8 +28,12 @@ class Deva {
28
28
  wait: '😵‍💫 WAITING',
29
29
  data: '📀 DATA',
30
30
  ask: '🙋‍♀️ ASK',
31
+ cmd: '📟 COMMAND',
31
32
  question: '🙋‍♂️ QUESTION',
32
33
  answer: '🔮 ANSWER',
34
+ answer_ask: '🔮 ANSWER ASK',
35
+ answer_cmd: '🔮 ANSWER CMD',
36
+ answer_question: '🔮 ANSWER QUESTION',
33
37
  talk: '🎙️ TALK',
34
38
  listen: '🎧 LISTEN',
35
39
  error: '❌ ERROR',
@@ -335,7 +339,6 @@ class Deva {
335
339
  ***************/
336
340
  ask(packet) {
337
341
  if (!this._active) return Promise.resolve(this.messages.offline);
338
-
339
342
  this.state('ask');
340
343
 
341
344
  packet.a = {
@@ -372,7 +375,6 @@ class Deva {
372
375
  packet.a.text = result;
373
376
  }
374
377
  this.talk(`${this.agent.key}:ask:${packet.id}`, packet);
375
- this.state('wait');
376
378
  }).catch(err => {
377
379
  this.talk(`${this.agent.key}:ask:${packet.id}`, {error:err.toString()});
378
380
  return this.error(err, packet);
@@ -403,10 +405,10 @@ class Deva {
403
405
  const t_split = TEXT.split(' ');
404
406
 
405
407
  // check to see if the string is an #ask string to talk to the other Deva.
406
- const isAsk = t_split[0].startsWith(this.askChr) ? t_split[0].substring(1) : false;
408
+ const isAsk = t_split[0].startsWith(this.askChr);
407
409
 
408
410
  // check to see if the string is a command string to run a local method.
409
- const isCmd = t_split[0].startsWith(this.cmdChr) ? t_split[0].substring(1) : false;
411
+ const isCmd = t_split[0].startsWith(this.cmdChr);
410
412
 
411
413
  // Format the packet for return on the request.
412
414
  const orig = TEXT;
@@ -434,17 +436,21 @@ class Deva {
434
436
  // #agent method:param1:param2 with text strings for proccessing
435
437
  // !method param:list:parse for the local agent
436
438
  // if is an ask then we format one way
439
+ let _state = 'answer_question';
437
440
  if (isAsk) {
441
+ _state = 'answer_ask'
442
+ key = t_split[0]substring(1);
438
443
  params = t_split[1] ? t_split[1].split(':') : false;
439
444
  method = params[0];
440
445
  text = t_split.slice(2).join(' ').trim();
441
- key = isAsk;
442
446
  }
443
447
  else if (isCmd) {
448
+ _state = 'answer_cmd'
444
449
  params = t_split[1] ? t_split[1].split(':') : false;
445
450
  method = isCmd;
446
451
  text = t_split.slice(1).join(' ').trim()
447
452
  }
453
+ this.state(_state);
448
454
 
449
455
  packet.q = {
450
456
  agent: this.agent || false,
@@ -465,18 +471,18 @@ class Deva {
465
471
 
466
472
  // If a question to another Deva with '#' then trigger events
467
473
  if (isAsk) {
468
- this.talk(`${isAsk}:ask`, packet);
469
- this.once(`${isAsk}:ask:${packet.id}`, answer => {
474
+ this.talk(`${key}:ask`, packet);
475
+ this.once(`${key}:ask:${packet.id}`, answer => {
470
476
  return resolve(answer);
471
477
  });
472
478
  }
473
479
  // if the user sends a local command '$' then it will ask of the self.
474
480
  else {
475
- if (typeof this.methods[method] !== 'function') return resolve(this._methodNotFound(packet));
481
+ if (typeof this.methods[method] !== 'function') {
482
+ this.state('answer_cmd');
483
+ return resolve(this._methodNotFound(packet));
484
+ }
476
485
  this.methods[method](packet).then(result => {
477
-
478
- this.state('answer');
479
-
480
486
  const text = typeof result === 'object' ? result.text : result;
481
487
  const html = typeof result === 'object' ? result.html : result;
482
488
  const data = typeof result === 'object' ? result.data : false;
@@ -498,7 +504,6 @@ class Deva {
498
504
  // create a hash for entire packet and insert into packet
499
505
  packet.hash = this.hash(JSON.stringify(packet));
500
506
 
501
- this.talk(`log`, packet);
502
507
  return resolve(packet);
503
508
  }).catch(err => {
504
509
  return this.error(err, packet);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.1.12",
3
+ "version": "1.1.14",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "scripts": {