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