@indra.ai/deva 1.2.19 → 1.2.20

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 +5 -2
  2. package/index.js +221 -197
  3. package/package.json +1 -1
package/config.json CHANGED
@@ -37,6 +37,9 @@
37
37
  "exit": "Exit",
38
38
  "finish": "Finish",
39
39
  "done": "Done",
40
+ "question": "Question",
41
+ "ask": "Ask",
42
+ "answer": "Answer",
40
43
  "deva": "Deva",
41
44
  "client": "Client",
42
45
  "agent": "Agent",
@@ -110,6 +113,7 @@
110
113
  "push": "Push",
111
114
  "pull": "Pull",
112
115
  "set": "Set",
116
+ "response": "Response",
113
117
  "invalid": "INVALID!",
114
118
  "abort": "ABORT!",
115
119
  "error": "ERROR!",
@@ -143,6 +147,7 @@
143
147
  "list": "List items",
144
148
  "reply": "Reply",
145
149
  "set": "Set",
150
+ "get": "Get",
146
151
  "return": "Return",
147
152
 
148
153
  "question_ask": "Ask question",
@@ -154,9 +159,7 @@
154
159
  "question_done": "Question done",
155
160
 
156
161
  "answer": "Answer",
157
- "answer_talk": "Answer talk",
158
162
  "ask": "Ask",
159
- "ask_answer": "Ask answer",
160
163
 
161
164
  "security": "Get Security",
162
165
  "support": "Get Support",
package/index.js CHANGED
@@ -10,7 +10,7 @@ const { createHash, randomUUID, createCipheriv, createDecipheriv, randomBytes }
10
10
  const config = require('./config.json').DATA // load the deva core configuration data.
11
11
  class Deva {
12
12
  constructor(opts) {
13
- opts = opts || {};
13
+ opts = opts || {}; // set opts to provided opts or an empty object.
14
14
  this._id = randomUUID(); // the unique id assigned to the agent at load
15
15
  this._info = opts.info || false; // the deva information from the package file.
16
16
  this._config = opts.config || {}; // local Config Object
@@ -20,17 +20,9 @@ class Deva {
20
20
  this._security = false; // inherited Security features.
21
21
  this._support = false; // inherited Support features.
22
22
  this._services = false; // inherited Service features.
23
- this.os = require('os'); // It is used to provide basic operating system related utility functions.
24
- this.fs = require('fs'); // this is so file system functions are in the core.
25
- this.path = require('path'); // this is so we can get path in the system.
26
- this.crypto = require('crypto'); // It is used to support cryptography for encryption and decryption.
27
- this.zlib = require('zlib'); // provides compression functionality using Gzip, Deflate/Inflate, and Brotli.
28
- this.dns = require('dns'); // It is used to lookup and resolve on domain names.
29
- this.net = require('net'); // It used to create TCP server/client communicate using TCP protocol.
30
- this.http = require('http'); // It is used to create Http server and Http client.
31
- this.https = require('https'); // It is used to create Http server and Http client.
32
- this.url = require('url'); // It is used for URL resolution and parsing.
33
- this.assert = require('assert'); // It is used for testing itself.
23
+ this.os = os; // It is used to provide basic operating system related utility functions.
24
+ this.fs = fs; // this is so file system functions are in the core.
25
+ this.path = path; // this is so we can get path in the system.
34
26
  this.events = opts.events || new EventEmitter({}); // Event Bus
35
27
  this.libs = opts.libs || {}; // used for loading library functions
36
28
  this.utils = opts.utils || {}; // parse function
@@ -109,7 +101,6 @@ class Deva {
109
101
  return new Promise((resolve, reject) => {
110
102
  try {
111
103
  // set the default listeners for the states of the agent.
112
-
113
104
  for (let state in this._states) {
114
105
  if (typeof this[state] === 'function') {
115
106
  this.events.on(`${this._agent.key}:${state}`, packet => {
@@ -119,15 +110,17 @@ class Deva {
119
110
  }
120
111
 
121
112
  // set the assigned listeners for the agent.
122
- for (let listener in this.listeners) {
123
- this.events.on(listener, packet => {
124
- return this.listeners[listener](packet);
113
+ for (let listener in this.listeners) { // loop over the liteners
114
+ this.events.on(listener, packet => { // set the event listener
115
+ return this.listeners[listener](packet); // return the listener function
125
116
  })
126
117
  }
127
- return resolve();
128
118
  }
129
119
  catch (e) {
130
- return this.error(e, false, reject);
120
+ return this.error(e, false, reject); // pass errors to this.error
121
+ }
122
+ finally {
123
+ return resolve(); // resolve the function after everything is done.
131
124
  }
132
125
  });
133
126
  }
@@ -351,9 +344,9 @@ class Deva {
351
344
  /**************
352
345
  func: listen
353
346
  params:
354
- - evt: The vent label to listen for
347
+ - evt: The vent label to listen for
355
348
  - callback: The callback function to run when the event fires.
356
- describe:
349
+ describe: setup a new event listener in the system.
357
350
  ***************/
358
351
  listen(evt, callback) {
359
352
  this.listeners[evt] = callback;
@@ -365,8 +358,7 @@ class Deva {
365
358
  /**************
366
359
  func: once
367
360
  params:
368
- - evt: The event to listen to for a once call. These event are handy
369
- when waiting for a key response one time.
361
+ - evt: The event to listen to for a once call.
370
362
  - callback: The callback functoin to run when the event fires.
371
363
  describe:
372
364
  ***************/
@@ -377,10 +369,9 @@ class Deva {
377
369
  /**************
378
370
  func: ignore
379
371
  params:
380
- - evt: The event you'd like to ignore.
372
+ - evt: The event you'd like to ignore.
381
373
  - callback: a callback function to execute after removing the event from listerns.
382
- describe:
383
- The ignore function allow the removal of events that are in the existing devas lister group.
374
+ describe: The ignore function allow the removal of events in the listener group.
384
375
  ***************/
385
376
  ignore(evt, callback) {
386
377
  return this.events.removeListener(evt, callback);
@@ -398,9 +389,9 @@ class Deva {
398
389
  question(TEXT=false, DATA=false) {
399
390
  // check the active status
400
391
  if (!this._active) return Promise.resolve(this._messages.offline);
401
- this.zone('question');
402
- const id = this.uid(); // generate a unique id for transport.
403
- const t_split = TEXT.split(' '); // split the text on spaces to get words.
392
+ this.zone('question'); // set the zone to question.
393
+ const id = this.uid(); // generate a unique id for transport.
394
+ const t_split = TEXT.split(' '); // split the text on spaces to get words.
404
395
 
405
396
  // check to see if the string is an #ask string to talk to the other Deva.
406
397
  const isAsk = t_split[0].startsWith(this.askChr);
@@ -408,30 +399,27 @@ class Deva {
408
399
  // check to see if the string is a command string to run a local method.
409
400
  const isCmd = t_split[0].startsWith(this.cmdChr);
410
401
 
411
- this.state('data');
412
402
  // Format the packet for return on the request.
413
- const data = DATA; // set the DATA to data
414
- const packet = { // create the base q/a packet
415
- id, // set the id into packet
416
- q: false, // create empty q object in packet
417
- a: false, // create empty a object in packet
418
- created: Date.now(), // timestamp the packet
403
+ const data = DATA; // set the DATA to data
404
+ const packet = { // create the base q/a packet
405
+ id, // set the id into packet
406
+ q: false, // create empty q object in packet
407
+ a: false, // create empty a object in packet
408
+ created: Date.now(), // timestamp the packet
419
409
  };
420
410
 
421
- let text = TEXT, // let TEXT is text for a manipulation variable
422
- params = false, // params as false to build params string
423
- method = 'question', // set the default method to question
424
- key = this._agent.key; // set a temporary key from the agent key.
411
+ let text = TEXT, // let TEXT is text for a manipulation variable
412
+ params = false, // params as false to build params string
413
+ method = 'question', // set the default method to question
414
+ key = this._agent.key; // set a temporary key from the agent key.
425
415
 
426
416
  return new Promise((resolve, reject) => {
427
417
  // resolve with the no text message if the client says nothing.
428
418
  if (!TEXT) return this.finish(this._messages.notext, resolve);
429
- // reject question if Deva offline
430
- if (!this._active) return this.finish(this._messages.offline, resolve);
431
- let _action = 'question';
432
- this.state('question');
433
- try { // try to answer the question
434
- if (isAsk) { // determine if hte question isAsk
419
+ let _action = 'question'; // set the initial _action to question.
420
+ this.state('question'); // set the state to question
421
+ try { // try to answer the question
422
+ if (isAsk) { // determine if hte question isAsk
435
423
  this.state('ask');
436
424
  _action = 'question_ask';
437
425
  // if:isAsk split the agent key and remove first command character
@@ -442,51 +430,51 @@ class Deva {
442
430
  text = t_split.slice(2).join(' ').trim(); // rejoin the text with space
443
431
  }
444
432
  else if (isCmd) { // determine if the question is a command
445
- this.state('cmd');
433
+ this.state('cmd'); // set the state to cmd.
446
434
  _action = 'question_cmd';
447
435
  //if:isCmd use text split index 1 as the parameter block
448
436
  params = t_split[0] ? t_split[0].split(':').slice(1) : false;
449
- method = t_split[0].substring(1); // if:isCmd use the 0 index as the command
450
- text = t_split.slice(1).join(' ').trim(); // if:isCmd rejoin the string on the space after removing first index
437
+ method = t_split[0].substring(1); // if:isCmd use the 0 index as the command
438
+ text = t_split.slice(1).join(' ').trim(); // if:isCmd rejoin the string on the space after removing first index
451
439
  }
452
440
 
453
- packet.q = { // build packet.q container
454
- id: this.uid(),
455
- agent: this.agent() || false, // set the agent
456
- client: this.client() || false, // set the client
457
- meta: { // build the meta container
458
- key, // set the key variable
459
- method, // set method to track function use
460
- params, // set any params that are associated
441
+ this.state('data');
442
+ packet.q = { // build packet.q container
443
+ id: this.uid(), // set the transport id for the question.
444
+ agent: this.agent(), // set the agent
445
+ client: this.client(), // set the client
446
+ meta: { // build the meta container
447
+ key, // set the key variable
448
+ method, // set method to track function use
449
+ params, // set any params that are associated
461
450
  },
462
- text, // set the text for the packet.
463
- data, // set the data object
464
- created: Date.now(), // timestamp the question
451
+ text, // set the text for the packet.
452
+ data, // set the data object
453
+ created: Date.now(), // timestamp the question
465
454
  }
466
455
 
467
456
  // hash the question
468
457
  packet.q.meta.hash = this.hash(packet.q);
469
458
 
470
- this.action(_action);
459
+ this.action(_action); // set current action to what was defined by _action variable.
471
460
  this.talk(config.events.question, this.copy(packet)); // global question event make sure to copy data.
472
461
 
473
- if (isAsk) { // isAsk check if the question isAsk and talk
462
+ if (isAsk) { // isAsk check if the question isAsk and talk
474
463
  // if: isAsk wait for the once event which is key'd to the packet ID for specified responses
475
464
  this.talk(`${key}:ask`, packet);
476
465
  this.once(`${key}:ask:${packet.id}`, answer => {
477
466
  this.action('question_ask_answer');
478
-
479
467
  this.talk(config.events.ask, this.copy(answer));
480
- return this.finish(answer, resolve); // if:isAsk resolve the answer from the call
468
+ return this.finish(answer, resolve); // if:isAsk resolve the answer from the call
481
469
  });
482
470
  }
483
- else { // else: answer tue question locally
471
+ else { // else: answer tue question locally
484
472
  this.action('question_answer');
485
473
  return this.answer(packet, resolve, reject);
486
474
  }
487
475
  }
488
- catch(e) { // try block error trap
489
- return this.error(e); // if a overall error happens this witll call this.error
476
+ catch(e) {
477
+ return this.error(e); // if a overall error happens this witll call this.error
490
478
  }
491
479
  });
492
480
  }
@@ -503,7 +491,9 @@ class Deva {
503
491
  ***************/
504
492
  answer(packet, resolve, reject) {
505
493
  if (!this._active) return Promise.resolve(this._messages.offline);
506
- this.state('answer');
494
+ this.zone('answer');
495
+ const agent = this.agent();
496
+ const client = this.client();
507
497
  // check if method exists and is of type function
508
498
  const {method,params} = packet.q.meta;
509
499
  const isMethod = this.methods[method] && typeof this.methods[method] == 'function';
@@ -512,7 +502,7 @@ class Deva {
512
502
  }
513
503
  // Call the local method to process the question based the extracted parameters
514
504
  return this.methods[method](packet).then(result => {
515
- this.action('answer');
505
+ this.state('answer');
516
506
  // check the result for the text, html, and data object.
517
507
  // this is for when answers are returned from nested Devas.
518
508
  const text = typeof result === 'object' ? result.text : result;
@@ -520,28 +510,25 @@ class Deva {
520
510
  // if the data passed is NOT an object it will FALSE
521
511
  const data = typeof result === 'object' ? result.data : false;
522
512
 
523
- const agent = this.agent() || false;
524
- const client = this.client() || false;
525
- const packet_answer = { // setup the packet.a container
513
+ const packet_answer = { // setup the packet.a container
526
514
  id: this.uid(),
527
- agent, // set the agent who answered the question
528
- client, // set the client asking the question
529
- meta: { // setup the answer meta container
530
- key: agent.key, // set the agent key inot the meta
531
- method, // set the method into the meta
532
- params, // set the params into the meta
515
+ agent, // set the agent who answered the question
516
+ client, // set the client asking the question
517
+ meta: { // setup the answer meta container
518
+ key: agent.key, // set the agent key inot the meta
519
+ method, // set the method into the meta
520
+ params, // set the params into the meta
533
521
  },
534
- text, // set answer text
535
- html, // set the answer html
536
- data, // set the answer data
537
- created: Date.now(),
522
+ text, // set answer text
523
+ html, // set the answer html
524
+ data, // set the answer data
525
+ created: Date.now(), // set the created date for the answer
538
526
  };
539
527
 
540
528
  // create a hash for the answer and insert into answer meta.
541
529
  packet_answer.meta.hash = this.hash(packet_answer);
542
-
543
- packet.a = packet_answer;
544
- this.action('answer_talk');
530
+ packet.a = packet_answer; // set the packet.a to the packet_answer
531
+ this.action('answer'); // set the action to answer
545
532
  this.talk(config.events.answer, this.copy(packet)); // global talk event
546
533
  return this.finish(packet, resolve); // resolve the packet to the caller.
547
534
  }).catch(err => { // catch any errors in the method
@@ -567,7 +554,7 @@ class Deva {
567
554
  ask(packet) {
568
555
  if (!this._active) return Promise.resolve(this._messages.offline);
569
556
 
570
- this.state('ask');
557
+ this.zone('ask');
571
558
 
572
559
  const agent = this.agent();
573
560
  const client = this.client();
@@ -590,14 +577,14 @@ class Deva {
590
577
  try {
591
578
  if (typeof this.methods[packet.q.meta.method] !== 'function') {
592
579
  return setImmediate(() => {
593
- this.action('invalid')
580
+ this.action('invalid');
594
581
  this.talk(`${this._agent.key}:ask:${packet.id}`, this._methodNotFound(packet));
595
582
  });
596
583
  }
597
584
 
585
+ this.state('ask');
598
586
  // The method is parsed and depending on what method is asked for it returns
599
587
  // the response based on the passed through packet.
600
- this.action('ask');
601
588
  this.methods[packet.q.meta.method](packet).then(result => {
602
589
  if (typeof result === 'object') {
603
590
  packet_answer.text = result.text || false;
@@ -608,7 +595,7 @@ class Deva {
608
595
  packet_answer.text = result;
609
596
  }
610
597
  packet_answer.meta.hash = this.hash(packet_answer);
611
- this.action('ask_answer');
598
+ this.action('ask');
612
599
  packet.a = packet_answer;
613
600
  this.talk(config.events.answer, this.copy(packet)); // global talk event
614
601
  this.talk(`${agent.key}:ask:${packet.id}`, packet);
@@ -748,21 +735,25 @@ class Deva {
748
735
  params:
749
736
  - packet: the data to pass to the resolve
750
737
  - resolve: the finish resolve to pass back
751
- describe:
752
- This function is use to relay the Agent ito a finish state when resolving a
753
- question or data.
754
- usage:
755
- this.finish(data, resolve)
738
+ describe: This function is use to relay the Agent ito a finish state when
739
+ resolving a question or data.
740
+ usage: this.finish(data, resolve)
756
741
  ***************/
757
742
  finish(packet, resolve) {
758
- this.zone('finish');
743
+ this.zone('finish'); // set the zone to finish
759
744
  if (!this._active) return Promise.resolve(this._messages.offline);
760
- this.state('finish');
745
+
746
+ this.state('finish'); // set the finish state
761
747
  packet.hash = this.hash(packet);// hash the entire packet before finishing.
762
- const hasOnFinish = this.onFinish && typeof this.onFinish === 'function' ? true : false;
748
+ // check for agent on finish function in agent
749
+ const hasOnFinish = this.onFinish && typeof this.onFinish === 'function';
763
750
 
751
+ this.action('finish'); // set the finish action
752
+ // if: agent has on finish then return on finish
753
+
754
+ this.context('finish'); // set the context to finish
764
755
  if (hasOnFinish) return this.onFinish(packet, resolve);
765
- this.action('finish');
756
+ // return the provided resolve function or a promise resolve.
766
757
  return resolve ? resolve(packet) : Promise.resolve(packet);
767
758
  }
768
759
 
@@ -780,25 +771,21 @@ class Deva {
780
771
  this.stop()
781
772
  ***************/
782
773
  stop() {
783
- this.zone('stop');
774
+ this.zone('stop'); // set the zone to stop
784
775
  if (!this._active) return Promise.resolve(this._messages.offline);
785
-
786
- this.state('stop');
787
- const agent = this.agent();
788
- const client = this.client();
789
-
790
- const data = {
791
- id: this.uid(true),
792
- key: 'stop',
793
- value: this._messages.stop,
794
- agent,
795
- client,
796
- created: Date.now(),
776
+ this.state('stop'); // set the state to stop
777
+ const data = { // build the stop data
778
+ id: this.uid(), // set the id
779
+ agent: this.agent(), // set the agent
780
+ client: this.client(), // set the client
781
+ key: 'stop', // set the key
782
+ value: this._messages.stop, // set the value
783
+ created: Date.now(), // set the created date
797
784
  }
798
- data.hash = this.hash(data);
799
-
800
- this.action('stop');
785
+ this.action('stop'); // set the stop action
786
+ // has stop function then set hasOnStop variable
801
787
  const hasOnStop = this.onStop && typeof this.onStop === 'function';
788
+ // if: has on stop then run on stop function or return exit function.
802
789
  return hasOnStop ? this.onStop(data) : this.exit(data)
803
790
  }
804
791
 
@@ -852,27 +839,28 @@ class Deva {
852
839
  /**************
853
840
  func: state
854
841
  params:
855
- - st: The state flag to set for the Deva that matches to this._states
856
- describe
842
+ - value: The state value to set for the Deva that matches to this._states
843
+ - extra: any extra text to add ot the state change.
857
844
  ***************/
858
- state(state) {
845
+ state(value=false, extra=false) {
859
846
  try {
860
- if (!this._states[state]) return;
861
- this._state = state;
862
- const text = this._states[state];
863
- const data = {
864
- id: this.uid(true),
865
- key: 'state',
866
- value: state,
867
- agent: this.agent(),
868
- client: this.client(),
869
- text,
870
- created: Date.now(),
847
+ if (!value || !this._states[value]) return; // return if no matching value
848
+ this._state = value; // set the local state variable.
849
+ const lookup = this._states[value]; // set the local states lookup
850
+ const text = extra ? `${lookup} ${extra}` : lookup; // set text from lookup with extra
851
+ const data = { // build the data object
852
+ id: this.uid(), // set the data id
853
+ agent: this.agent(), // set the agent
854
+ client: this.client(), // set the client
855
+ key: 'state', // set the key to state
856
+ value, // set the value to the passed in value
857
+ text, // set the text value of the data
858
+ created: Date.now(), // set the data created date.
871
859
  };
872
- data.hash = this.hash(data);
873
- this.talk(config.events.state, data);
874
- } catch (e) {
875
- return this.error(e);
860
+ data.hash = this.hash(data); // hash the data
861
+ this.talk(config.events.state, data); // broadcasat the state event
862
+ } catch (e) { // catch any errors
863
+ return this.error(e); // return if an error happens
876
864
  }
877
865
  }
878
866
 
@@ -897,16 +885,20 @@ class Deva {
897
885
  - st: The zone flag to set for the Deva that matches to this._zones
898
886
  describe
899
887
  ***************/
900
- zone(value) {
901
- if (!this._zones[value] || value === this._zone) return;
888
+ zone(value=false, extra=false) {
889
+ if (!value || !this._zones[value] || value === this._zone) return;
902
890
  try {
903
891
  this._zone = value;
904
- const text = this._zones[value];
905
- const data = {
906
- id: this.uid(true),
892
+
893
+ const lookup = this._zones[value]; // set the lookup value
894
+ const text = extra ? `${lookup} ${extra}` : lookup; // set the text value
895
+
896
+ const data = { // build the zone data
897
+ id: this.uid(), // set the packetid
898
+ agent: this.agent(),
899
+ client: this.client(),
907
900
  key: 'zone',
908
901
  value,
909
- agent: this.agent(),
910
902
  text,
911
903
  created: Date.now(),
912
904
  };
@@ -917,35 +909,46 @@ class Deva {
917
909
  }
918
910
  }
919
911
 
912
+ /**************
913
+ func: zones
914
+ params: none
915
+ describe: returns a listing of zones currently in the system.
916
+ ***************/
920
917
  zones() {
921
- this.action('zones');
918
+ this.action('zones'); // set the action to zones
922
919
  return {
923
- id: this.uid(true),
924
- key: 'zones',
925
- value: this._zones,
926
- created: Date.now(),
920
+ id: this.uid(true), // set the uuid of the data
921
+ agent: this.agent(), // set the agent value
922
+ cleint: this.cleint(), // set the client value
923
+ key: 'zones', // set the key return value
924
+ value: this._zones, // set the list of zones
925
+ created: Date.now(), // set the created date of the object.
927
926
  }
928
927
  }
928
+
929
929
  /**************
930
930
  func: action
931
931
  params:
932
- - st: The state flag to set for the Deva that matches to this._states
932
+ - value: The state flag to set for the Deva that matches to this._states
933
+ - extra: Any extra text to send with the action value.
933
934
  describe
934
935
  ***************/
935
- action(action) {
936
+ action(value=false, extra=false) {
936
937
  try {
937
- this._action = action; // set the local action variable
938
+ if (!value) return; // check feature value
939
+ this._action = value; // set the local action variable
938
940
  // check local vars for custom actions
939
- const var_action = this.vars.actions ? this.vars.actions[action] : false;
940
- // check action messages
941
- const msg_action = this._actions[action] || var_action;
942
- const text = msg_action || action; // set the text of the action
941
+ const var_action = this.vars.actions ? this.vars.actions[value] : false;
942
+ // check the message action
943
+ const msg_action = var_action || this._actions[value];
944
+ const msg = msg_action || action; // set the correct message
945
+ const text = extra ? `${msg} ${extra}` : msg; // set the text of the action
943
946
  const data = { // build the data object for the action.
944
947
  id: this.uid(true), // generate a guid for the action transmitssion.
945
- key: 'action', // the key for event to transmit action type
946
- value: action, // the value key which is the action passed
947
948
  agent: this.agent(), // the agent data to send with the action
948
949
  client: this.client(), // the client data to send with the action
950
+ key: 'action', // the key for event to transmit action type
951
+ value, // the value key which is the action passed
949
952
  text, // text of the action to send
950
953
  created: Date.now(), // action time stamp
951
954
  };
@@ -956,71 +959,90 @@ class Deva {
956
959
  }
957
960
  }
958
961
 
962
+ /**************
963
+ func: actions
964
+ params: none
965
+ describe: Returns a list of available actions in the system.
966
+ ***************/
959
967
  actions() {
960
968
  this.action('actions');
961
969
  return {
962
- id: this.uid(true),
963
- key: 'actions',
964
- value: this._actions,
965
- created: Date.now(),
970
+ id: this.uid(true), // set the id with a uuid
971
+ agent: this.agent(), // set the agent value
972
+ client: this.client(), // set the client value
973
+ key: 'actions', // set the data key
974
+ value: this._actions, // set the value to the actions list
975
+ created: Date.now(), // set the data created date
966
976
  }
967
977
  }
968
978
 
969
979
  /**************
970
980
  func: feature
971
981
  params:
972
- - st: The state flag to set for the Deva that matches to this._states
982
+ - value: The feature flag to set for the Deva that matches to this._features
983
+ - extra: Any extra text to send with the feature value.
973
984
  describe
974
985
  ***************/
975
- feature(feature) {
986
+ feature(value=false, extra=false) {
976
987
  try {
977
- if (!this._features[feature]) return;
978
- this._feature = feature;
979
- const text = this._features[feature] ;
980
- const talk = {
981
- id: this.uid(true),
982
- key: 'feature',
983
- value: feature,
984
- agent: this._agent,
985
- text,
986
- created: Date.now(),
988
+ if (!value || !this._features[value]) return; // check feature value
989
+ this._feature = value; // set local feature variable
990
+
991
+ const lookup = this._features[value]; // set the lookup value
992
+ const text = extra ? `${lookup} ${extra}` : lookup; // set the text value
993
+
994
+ const data = { // build data object
995
+ id: this.uid(true), // set the id
996
+ agent: this.agent(), // set the agent transporting the packet.
997
+ key: 'feature', // set the key for transport
998
+ value, // set the value of the key
999
+ text, // set the text value
1000
+ created: Date.now(), // set the creation date
987
1001
  };
988
- talk.hash = this.hash(talk);
989
- this.talk(config.events.feature, talk);
990
- } catch (e) {
991
- return this.error(e);
1002
+ data.hash = this.hash(data); // generate the hash value of the data packet
1003
+ this.talk(config.events.feature, data); // talk the feature event with data
1004
+ } catch (e) { // catch any errors
1005
+ return this.error(e); // retun this.error when an error is caught.
992
1006
  }
993
1007
  }
994
1008
 
1009
+ /**************
1010
+ func: features
1011
+ params: none
1012
+ describe: return a list of features that are available to the system.
1013
+ ***************/
995
1014
  features() {
996
- this.action('features');
997
- return {
998
- id: this.uid(true),
999
- key: 'features',
1000
- value: this._features,
1001
- created: Date.now(),
1015
+ this.action('features'); // set the action to features
1016
+ return { // return the data object
1017
+ id: this.uid(true), // set the object id
1018
+ agent: this.agent(), // set the agent value.
1019
+ client: this.client(), // set the client value.
1020
+ key: 'features', // set the key
1021
+ value: this._features, // set the value to the features list
1022
+ created: Date.now(), // set the created date.
1002
1023
  }
1003
1024
  }
1004
1025
 
1005
1026
  /**************
1006
1027
  func: context
1007
1028
  params:
1008
- - st: The context flag to set for the Deva that matches to this._contexts
1029
+ - value: The context flag to set for the Deva that matches to this._contexts
1030
+ - extra: Any extra text that is sent with the context value.
1009
1031
  describe
1010
1032
  ***************/
1011
1033
  context(value=false, extra=false) {
1012
1034
  try {
1013
- if (!value) return this._context;
1035
+ if (!value) return;
1014
1036
  this._context = value;
1015
1037
  const lookup = this.vars.context[value] || value;
1016
1038
  const text = extra ? `${lookup} ${extra}` : lookup;
1017
1039
 
1018
1040
  const data = {
1019
1041
  id: this.uid(true),
1020
- key: 'context',
1021
- value,
1022
1042
  agent: this.agent(),
1023
1043
  client: this.client(),
1044
+ key: 'context',
1045
+ value,
1024
1046
  text,
1025
1047
  created: Date.now(),
1026
1048
  };
@@ -1035,6 +1057,8 @@ class Deva {
1035
1057
  this.action('contexts');
1036
1058
  return {
1037
1059
  id: this.uid(true),
1060
+ agent: this.agent(),
1061
+ client: this.client(),
1038
1062
  key: 'contexts',
1039
1063
  value: this.vars.context || false,
1040
1064
  created: Date.now(),
@@ -1044,29 +1068,25 @@ class Deva {
1044
1068
  /**************
1045
1069
  func: client
1046
1070
  params: none
1047
- describe:
1048
- this function allows state management for when client prfioe is
1049
- being accessed.
1071
+ describe: returns the current client values in the system.
1050
1072
  usage: this.client();
1051
1073
  ***************/
1052
1074
  client() {
1053
- if (!this._active) return this._messages.offline; // check the active status
1054
- const client_copy = this.copy(this._client);
1055
- return client_copy; // return the client feature
1075
+ if (!this._active) return this._messages.offline; // check the active status
1076
+ const client_copy = this.copy(this._client); // create a copy of the client data
1077
+ return client_copy; // return the copy of the client data.
1056
1078
  }
1057
1079
 
1058
1080
  /**************
1059
1081
  func: agent
1060
1082
  params: none
1061
- describe:
1062
- this function allows statement management for when client prfioe is
1063
- being accessed.
1083
+ describe: returns the current agent values in the system.
1064
1084
  usage: this.agent()
1065
1085
  ***************/
1066
1086
  agent() {
1067
- if (!this._active) return this._messages.offline;
1068
- const agent_copy = this.copy(this._agent);
1069
- return agent_copy;
1087
+ if (!this._active) return this._messages.offline; // check the active status
1088
+ const agent_copy = this.copy(this._agent); // create a copy of the agent data.
1089
+ return agent_copy; // return the copy of the agent data.
1070
1090
  }
1071
1091
 
1072
1092
  // FEATURE FUNCTIONS
@@ -1095,11 +1115,13 @@ class Deva {
1095
1115
  support() {
1096
1116
  this.feature('support'); // set the support state
1097
1117
  if (!this._active) return this._messages.offline; // check the active status
1098
- this.state('data');
1118
+ this.state('data'); // set the state to data
1099
1119
  try {
1100
- this.action('support');
1120
+ this.action('support'); // set the action to support.
1101
1121
  return this.copy(this._support); // return the support feature
1102
- } catch (e) {return this.error(e);}
1122
+ } catch (e) {
1123
+ return this.error(e); // return this.error when error catch
1124
+ }
1103
1125
  }
1104
1126
 
1105
1127
  /**************
@@ -1115,7 +1137,9 @@ class Deva {
1115
1137
  try {
1116
1138
  this.action('services'); // set the services state
1117
1139
  return this.copy(this._services); // return the services feature
1118
- } catch (e) {return this.error(e);}
1140
+ } catch (e) {
1141
+ return this.error(e); // return this.error when error catch
1142
+ }
1119
1143
  }
1120
1144
 
1121
1145
  /**************
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.2.19",
3
+ "version": "1.2.20",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "scripts": {