@indra.ai/deva 1.2.21 → 1.2.22

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 (3) hide show
  1. package/config.json +1 -0
  2. package/index.js +50 -47
  3. package/package.json +1 -1
package/config.json CHANGED
@@ -105,6 +105,7 @@
105
105
  "memory": "💭 Memory",
106
106
  "response": "✍️ Response",
107
107
  "invalid": "👎 INVALID!",
108
+ "valid": "👍 VALID!",
108
109
  "abort": "💔 ABORT!",
109
110
  "error": "❌ ERROR!",
110
111
  "help": "💙 Help"
package/index.js CHANGED
@@ -215,11 +215,12 @@ class Deva {
215
215
  ***************/
216
216
  Security() {
217
217
  this.zone('security');
218
+ this.action('Security'); // set action to Security
218
219
  const _cl = this.client(); // set local copy of client data
219
220
  try {
220
221
  if (!_cl.features.security) return this.Support(); // if no security feature goto Support
221
222
  else {
222
- this.state('data');
223
+ this.state('set', 'Security');
223
224
  const {id, profile, features} = _cl; // make a copy the clinet data.
224
225
  const {security} = features; // make a copy the clinet data.
225
226
  this._security = { // set this_security with data
@@ -233,10 +234,11 @@ class Deva {
233
234
  personal: security.devas[this._agent.key], // Client personal features and rules.
234
235
  };
235
236
  delete this._client.features.security; // make a copy the clinet data.
236
- this.action('Security'); // set action to Security
237
+ this.state('resolve', 'Support');
237
238
  return this.Support(); // goto Support when done with Security
238
239
  }
239
240
  } catch (e) {
241
+ this.state('reject', 'Support');
240
242
  return this.error(e); // run error handling if an error is caught
241
243
  }
242
244
  }
@@ -250,11 +252,12 @@ class Deva {
250
252
  ***************/
251
253
  Support() {
252
254
  this.zone('support');
255
+ this.action('Support');
253
256
  const _cl = this.client(); // set the local client variable
254
257
  try {
255
258
  if (!_cl.features.support) return this.Services() // move to Services if no support feature
256
259
  else {
257
- this.state('data');
260
+ this.state('set', 'Support');
258
261
  const {id, features, profile} = _cl; // set the local consts from client copy
259
262
  const {support} = features; // set support from features const
260
263
  this._support = { // set this_support with data
@@ -266,10 +269,11 @@ class Deva {
266
269
  personal: support.devas[this._agent.key], // Client personalSecurity features and rules.
267
270
  };
268
271
  delete this._client.features.support; // delete the support key from the client
269
- this.action('Support');
272
+ this.state('resolve', 'Services');
270
273
  return this.Services(); // when done move to Services
271
274
  }
272
275
  } catch (e) {
276
+ this.state('reject', 'Services');
273
277
  return this.error(e); // run error handling if an error is caught
274
278
  }
275
279
  }
@@ -283,11 +287,12 @@ class Deva {
283
287
  ***************/
284
288
  Services() {
285
289
  this.zone('services')
290
+ this.action('Services');
286
291
  const _cl = this.client(); // set local client
287
292
  try {
288
293
  if (!_cl.features.services) return this.Done(); // move to Done if no Services feature
289
294
  else {
290
- this.state('data');
295
+ this.state('set', 'Services');
291
296
  const {id, features, profile} = _cl; // set the local consts from client copy
292
297
  const {services} = features; // set services from features const
293
298
  this._services = { // set this_services with data
@@ -299,10 +304,11 @@ class Deva {
299
304
  personal: services.devas[this._agent.key], // Client personal features and rules.
300
305
  };
301
306
  delete this._client.features.services; // delete the services key for isolation
302
- this.action('Services');
307
+ this.state('resolve', 'Services');
303
308
  return this.Done(); // go to Done
304
309
  }
305
310
  } catch (e) {
311
+ this.state('reject', 'Services');
306
312
  return this.error(e); // run error handling if an error is caught
307
313
  }
308
314
  }
@@ -313,14 +319,15 @@ class Deva {
313
319
  describe: The end of the workflow Client Feature Workflow
314
320
  ***************/
315
321
  Done(client) {
316
- this.state('done');
317
322
  this.action('done');
318
323
  return new Promise((resolve, reject) => {
319
324
  try {
325
+ this.state('done');
320
326
  delete this._client.features; // delete the features key when done.
321
- this.state('ready');
327
+ this.state('resolve', 'done');
322
328
  return resolve(client); // resolve an empty pr
323
329
  } catch (e) {
330
+ this.state('reject', 'done');
324
331
  return this.error(e, false, reject);
325
332
  }
326
333
  });
@@ -388,7 +395,7 @@ class Deva {
388
395
  question(TEXT=false, DATA=false) {
389
396
  // check the active status
390
397
  if (!this._active) return Promise.resolve(this._messages.offline);
391
- this.zone('question'); // set the zone to question.
398
+ this.action('question');
392
399
  const id = this.uid(); // generate a unique id for transport.
393
400
  const t_split = TEXT.split(' '); // split the text on spaces to get words.
394
401
  const data = DATA; // set the DATA to data
@@ -415,11 +422,8 @@ class Deva {
415
422
  return new Promise((resolve, reject) => {
416
423
  // resolve with the no text message if the client says nothing.
417
424
  if (!TEXT) return this.finish(this._messages.notext, resolve);
418
- let _action = 'question'; // set the initial _action to question.
419
- this.state('question'); // set the state to question
420
425
  try { // try to answer the question
421
426
  if (isAsk) { // determine if hte question isAsk
422
- _action = 'question_ask';
423
427
  // if:isAsk split the agent key and remove first command character
424
428
  key = t_split[0].substring(1);
425
429
  //if:isAsk use text split index 1 as the parameter block
@@ -429,7 +433,6 @@ class Deva {
429
433
  this.state('ask', `${key} ${method}`);
430
434
  }
431
435
  else if (isCmd) { // determine if the question is a command
432
- _action = 'question_cmd';
433
436
  //if:isCmd use text split index 1 as the parameter block
434
437
  params = t_split[0] ? t_split[0].split(':').slice(1) : false;
435
438
  method = t_split[0].substring(1); // if:isCmd use the 0 index as the command
@@ -437,41 +440,43 @@ class Deva {
437
440
  this.state('cmd', method); // set the state to cmd.
438
441
  }
439
442
 
443
+ this.state('set', `question:${method}`)
440
444
  packet.q = { // build packet.q container
441
- id: this.uid(), // set the transport id for the question.
442
- agent: this.agent(), // set the agent
443
- client: this.client(), // set the client
444
- meta: { // build the meta container
445
- key, // set the key variable
446
- method, // set method to track function use
447
- params, // set any params that are associated
448
- },
449
- text, // set the text for the packet.
450
- data, // set the data object
451
- created: Date.now(), // timestamp the question
445
+ id: this.uid(), // set the transport id for the question.
446
+ agent: this.agent(), // set the agent
447
+ client: this.client(), // set the client
448
+ meta: { // build the meta container
449
+ key, // set the key variable
450
+ method, // set method to track function use
451
+ params, // set any params that are associated
452
+ },
453
+ text, // set the text for the packet.
454
+ data, // set the data object
455
+ created: Date.now(), // timestamp the question
452
456
  }
453
457
 
454
458
  // hash the question
455
459
  packet.q.meta.hash = this.hash(packet.q);
456
460
 
457
- this.action(_action, method); // set current action to what was defined by _action variable.
461
+ this.state('talk', config.events.question); // set current action to what was defined by _action variable.
458
462
  this.talk(config.events.question, this.copy(packet)); // global question event make sure to copy data.
459
463
 
460
464
  if (isAsk) { // isAsk check if the question isAsk and talk
461
465
  // if: isAsk wait for the once event which is key'd to the packet ID for specified responses
462
466
  this.talk(`${key}:ask`, packet);
463
467
  this.once(`${key}:ask:${packet.id}`, answer => {
464
- this.action('question_ask_answer');
468
+ this.state('talk', config.events.ask);
465
469
  this.talk(config.events.ask, this.copy(answer));
466
470
  return this.finish(answer, resolve); // if:isAsk resolve the answer from the call
467
471
  });
468
472
  }
469
473
  else { // else: answer tue question locally
470
- this.action('question_answer', method);
474
+ this.state('answer', `question:${method}`);
471
475
  return this.answer(packet, resolve, reject);
472
476
  }
473
477
  }
474
478
  catch(e) {
479
+ this.state('reject', 'question');
475
480
  return this.error(e); // if a overall error happens this witll call this.error
476
481
  }
477
482
  });
@@ -489,7 +494,6 @@ class Deva {
489
494
  ***************/
490
495
  answer(packet, resolve, reject) {
491
496
  if (!this._active) return Promise.resolve(this._messages.offline);
492
- this.zone('answer');
493
497
  const agent = this.agent();
494
498
  const client = this.client();
495
499
  // check if method exists and is of type function
@@ -499,8 +503,8 @@ class Deva {
499
503
  return resolve(this._methodNotFound(packet)); // resolve method not found if check if check fails
500
504
  }
501
505
  // Call the local method to process the question based the extracted parameters
502
- return this.methods[method](packet).then(result => {
503
- this.action('answer', method); // set the action to answer
506
+ this.action('answer', method);
507
+ this.methods[method](packet).then(result => {
504
508
  // check the result for the text, html, and data object.
505
509
  // this is for when answers are returned from nested Devas.
506
510
  const text = typeof result === 'object' ? result.text : result;
@@ -508,6 +512,7 @@ class Deva {
508
512
  // if the data passed is NOT an object it will FALSE
509
513
  const data = typeof result === 'object' ? result.data : false;
510
514
 
515
+ this.state('set', 'answer')
511
516
  const packet_answer = { // setup the packet.a container
512
517
  id: this.uid(),
513
518
  agent, // set the agent who answered the question
@@ -523,13 +528,15 @@ class Deva {
523
528
  created: Date.now(), // set the created date for the answer
524
529
  };
525
530
 
526
- this.state('answer', method);
527
531
  // create a hash for the answer and insert into answer meta.
528
532
  packet_answer.meta.hash = this.hash(packet_answer);
529
533
  packet.a = packet_answer; // set the packet.a to the packet_answer
534
+ this.state('talk', config.events.answer);
530
535
  this.talk(config.events.answer, this.copy(packet)); // global talk event
536
+ this.state('resovle', 'answer')
531
537
  return this.finish(packet, resolve); // resolve the packet to the caller.
532
538
  }).catch(err => { // catch any errors in the method
539
+ this.state('reject', 'answer');
533
540
  return this.error(err, packet, reject); // return this.error with err, packet, reject
534
541
  });
535
542
  }
@@ -552,7 +559,7 @@ class Deva {
552
559
  ask(packet) {
553
560
  if (!this._active) return Promise.resolve(this._messages.offline);
554
561
  const {method, params} = packet.q.meta;
555
- this.zone('ask', method);
562
+ this.action('ask', method);
556
563
 
557
564
  const agent = this.agent();
558
565
  const client = this.client();
@@ -572,11 +579,10 @@ class Deva {
572
579
  created: Date.now(),
573
580
  };
574
581
 
575
- this.action('ask', method);
576
582
  try {
577
583
  if (typeof this.methods[method] !== 'function') {
578
584
  return setImmediate(() => {
579
- this.action('invalid', method);
585
+ this.state('invalid', method);
580
586
  this.talk(`${this._agent.key}:ask:${packet.id}`, this._methodNotFound(packet));
581
587
  });
582
588
  }
@@ -593,9 +599,10 @@ class Deva {
593
599
  packet_answer.text = result;
594
600
  }
595
601
 
596
- this.state('ask', method);
602
+ this.state('set', `ask:${method}`);
597
603
  packet_answer.meta.hash = this.hash(packet_answer);
598
604
  packet.a = packet_answer;
605
+ this.state('talk', config.events.answer);
599
606
  this.talk(config.events.answer, this.copy(packet)); // global talk event
600
607
  this.talk(`${agent.key}:ask:${packet.id}`, packet);
601
608
  }).catch(err => {
@@ -742,17 +749,15 @@ class Deva {
742
749
  usage: this.finish(data, resolve)
743
750
  ***************/
744
751
  finish(packet, resolve) {
745
- this.zone('finish'); // set the zone to finish
746
752
  if (!this._active) return Promise.resolve(this._messages.offline);
753
+ this.action('finish'); // set the finish action
747
754
 
748
- this.state('finish'); // set the finish state
749
755
  packet.hash = this.hash(packet);// hash the entire packet before finishing.
750
756
  // check for agent on finish function in agent
751
757
  const hasOnFinish = this.onFinish && typeof this.onFinish === 'function';
752
758
 
753
- this.action('finish'); // set the finish action
754
759
  // if: agent has on finish then return on finish
755
-
760
+ this.state('finish'); // set the finish state
756
761
  if (hasOnFinish) return this.onFinish(packet, resolve);
757
762
  // return the provided resolve function or a promise resolve.
758
763
  return resolve ? resolve(packet) : Promise.resolve(packet);
@@ -1004,6 +1009,7 @@ class Deva {
1004
1009
  created: Date.now(), // set the creation date
1005
1010
  };
1006
1011
  data.hash = this.hash(data); // generate the hash value of the data packet
1012
+ this.state('talk', 'feature');
1007
1013
  this.talk(config.events.feature, data); // talk the feature event with data
1008
1014
  } catch (e) { // catch any errors
1009
1015
  return this.error(e); // retun this.error when an error is caught.
@@ -1016,7 +1022,6 @@ class Deva {
1016
1022
  describe: return a list of features that are available to the system.
1017
1023
  ***************/
1018
1024
  features() {
1019
- this.action('func', 'features');
1020
1025
  this.state('return', 'features');
1021
1026
  return { // return the data object
1022
1027
  id: this.uid(true), // set the object id
@@ -1053,6 +1058,7 @@ class Deva {
1053
1058
  };
1054
1059
 
1055
1060
  data.hash = this.hash(data);
1061
+ this.state('talk', 'context');
1056
1062
  this.talk(config.events.context, data);
1057
1063
  } catch (e) {
1058
1064
  return this.error(e);
@@ -1060,7 +1066,7 @@ class Deva {
1060
1066
  }
1061
1067
 
1062
1068
  contexts() {
1063
- this.action('func', 'contexts');
1069
+ if (!this._active) return this._messages.offline; // check the active status
1064
1070
  this.state('return', 'contexts');
1065
1071
  return {
1066
1072
  id: this.uid(true),
@@ -1104,10 +1110,9 @@ class Deva {
1104
1110
  usage: this.security()
1105
1111
  ***************/
1106
1112
  security() {
1113
+ if (!this._active) return this._messages.offline; // check the active status
1107
1114
  this.zone('security');
1108
1115
  this.feature('security'); // set the security state
1109
- if (!this._active) return this._messages.offline; // check the active status
1110
- this.action('feature', 'security'); // set the security state
1111
1116
  try {
1112
1117
  this.state('return', 'security'); // set the security state
1113
1118
  return this.copy(this._security); // return the security feature
@@ -1121,10 +1126,9 @@ class Deva {
1121
1126
  usage: this.support()
1122
1127
  ***************/
1123
1128
  support() {
1129
+ if (!this._active) return this._messages.offline; // check the active status
1124
1130
  this.zone('support');
1125
1131
  this.feature('support'); // set the support state
1126
- if (!this._active) return this._messages.offline; // check the active status
1127
- this.action('feature', 'support'); // set the state to data
1128
1132
  try {
1129
1133
  this.state('return', 'support'); // set the action to support.
1130
1134
  return this.copy(this._support); // return the support feature
@@ -1140,10 +1144,9 @@ class Deva {
1140
1144
  usage: this.services()
1141
1145
  ***************/
1142
1146
  services(opts) {
1147
+ if (!this._active) return this._messages.offline; // check the active status
1143
1148
  this.zone('services');
1144
1149
  this.feature('services'); // set the support state
1145
- if (!this._active) return this._messages.offline; // check the active status
1146
- this.action('feature', 'services'); // set the services state
1147
1150
  try {
1148
1151
  this.state('return', 'services'); // set the services state
1149
1152
  return this.copy(this._services); // return the services feature
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.2.21",
3
+ "version": "1.2.22",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "scripts": {