@indra.ai/deva 1.2.15 → 1.2.17

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 +32 -28
  2. package/index.js +35 -88
  3. package/package.json +1 -1
package/config.json CHANGED
@@ -30,30 +30,30 @@
30
30
  "context": false,
31
31
  "zone": "deva",
32
32
  "zones": {
33
- "deva": "#Deva",
34
- "client": "#Client",
35
- "agent": "#Agent",
36
- "security": "#Security",
37
- "support": "#Support",
38
- "services": "#Services",
39
- "systems": "#Systems",
40
- "legal": "#Legal",
41
- "business": "#Business",
42
- "art": "#Art",
43
- "music": "#Music",
44
- "fun": "#Fun",
45
- "party": "#Party",
46
- "adventure": "#Adventure",
47
- "cartoon": "#Cartoon",
48
- "mystery": "#Mystery",
49
- "fantasy": "#Fantasy",
50
- "romance": "#Romance",
51
- "comedy": "#Comedy",
52
- "drama": "#Drama",
53
- "scifi": "#SciFi",
54
- "finish": "#Finish",
55
- "help": "#Help",
56
- "error": "#Error"
33
+ "deva": "Deva",
34
+ "client": "Client",
35
+ "agent": "Agent",
36
+ "security": "Security",
37
+ "support": "Support",
38
+ "services": "Services",
39
+ "systems": "Systems",
40
+ "legal": "Legal",
41
+ "business": "Business",
42
+ "art": "Art",
43
+ "music": "Music",
44
+ "fun": "Fun",
45
+ "party": "Party",
46
+ "adventure": "Adventure",
47
+ "cartoon": "Cartoon",
48
+ "mystery": "Mystery",
49
+ "fantasy": "Fantasy",
50
+ "romance": "Romance",
51
+ "comedy": "Comedy",
52
+ "drama": "Drama",
53
+ "scifi": "SciFi",
54
+ "finish": "Finish",
55
+ "help": "Help",
56
+ "error": "Error"
57
57
  },
58
58
  "state": "offline",
59
59
  "states": {
@@ -75,9 +75,6 @@
75
75
  "disconnect": "Disconnect",
76
76
  "send": "Send",
77
77
  "receive": "Receive",
78
- "return": "Return",
79
- "resolve": "Resolve",
80
- "reject": "Reject",
81
78
  "init": "Initialize",
82
79
  "forward": "Forward",
83
80
  "backward": "Backward",
@@ -91,6 +88,8 @@
91
88
  "end": "End",
92
89
  "load": "Load",
93
90
  "unload": "Unload",
91
+ "resolve": "Resolve",
92
+ "reject": "Reject",
94
93
  "done": "Done",
95
94
  "data": "Data",
96
95
  "finish": "Finish",
@@ -125,6 +124,7 @@
125
124
  "prompt": "Prompt",
126
125
  "issue": "Issue",
127
126
  "find": "Find",
127
+ "parse": "Parse",
128
128
  "view": "View",
129
129
  "insert": "Insert",
130
130
  "update": "Update",
@@ -133,6 +133,9 @@
133
133
  "status": "Status",
134
134
  "func": "Function",
135
135
  "list": "List items",
136
+ "reply": "Reply",
137
+ "set": "Set",
138
+ "return": "Return",
136
139
 
137
140
  "question_ask": "Question ask",
138
141
  "question_ask_answer": "Question ask answer",
@@ -183,7 +186,8 @@
183
186
  "notext": "NO TEXT WAS PROVIDED",
184
187
  "nopacket": "NO PACKET WAS PROVIDED",
185
188
  "method_not_found": "METHOD NOT FOUND",
186
- "stop": "Stop Deva."
189
+ "stop": "Stop Deva.",
190
+ "exit": "Exit Deva"
187
191
  }
188
192
  }
189
193
  }
package/index.js CHANGED
@@ -20,26 +20,16 @@ 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._systems = false; // inherited Systems features.
24
23
  this.os = require('os'); // It is used to provide basic operating system related utility functions.
25
- this.buffer = require('buffer'); // It is used to provide basic operating system related utility functions.
26
- this.util = require('util'); // The supports the needs of internal APIs.
27
- this.querystring = require('querystring'); // Provides utilities for parsing and formatting URL query strings.
28
24
  this.fs = require('fs'); // this is so file system functions are in the core.
29
25
  this.path = require('path'); // this is so we can get path in the system.
30
26
  this.crypto = require('crypto'); // It is used to support cryptography for encryption and decryption.
31
27
  this.zlib = require('zlib'); // provides compression functionality using Gzip, Deflate/Inflate, and Brotli.
32
- this.console = require('console'); // It is used to write data to console.
33
- this.readline = require('readline/promises'); // It is used to write data to console.
34
28
  this.dns = require('dns'); // It is used to lookup and resolve on domain names.
35
29
  this.net = require('net'); // It used to create TCP server/client communicate using TCP protocol.
36
30
  this.http = require('http'); // It is used to create Http server and Http client.
37
31
  this.https = require('https'); // It is used to create Http server and Http client.
38
- this.stream = require('stream/promises'); // It is used to stream data between two entities.
39
32
  this.url = require('url'); // It is used for URL resolution and parsing.
40
- this.vm = require('vm'); // It provides an access to virtual machine to compile and execute code.
41
- this.inspector = require('inspector'); // It is used to stream data between two entities.
42
- this.cluster = require('cluster'); // used to take advantage of multi-core systems.
43
33
  this.assert = require('assert'); // It is used for testing itself.
44
34
  this.events = opts.events || new EventEmitter({}); // Event Bus
45
35
  this.libs = opts.libs || {}; // used for loading library functions
@@ -303,7 +293,7 @@ class Deva {
303
293
  this.zone('services')
304
294
  const _cl = this.client(); // set local client
305
295
  try {
306
- if (!_cl.features.services) return this.Systems(); // move to Systems if no Services feature
296
+ if (!_cl.features.services) return this.Done(); // move to Done if no Services feature
307
297
  else {
308
298
  this.state('data');
309
299
  const {id, features, profile} = _cl; // set the local consts from client copy
@@ -318,47 +308,13 @@ class Deva {
318
308
  };
319
309
  delete this._client.features.services; // delete the services key for isolation
320
310
  this.action('Services');
321
- return this.Systems(); // go to Systems when done
311
+ return this.Done(); // go to Done
322
312
  }
323
313
  } catch (e) {
324
314
  return this.error(e); // run error handling if an error is caught
325
315
  }
326
316
  }
327
317
 
328
- /**************
329
- func: Systems
330
- params: client: false
331
- describe:
332
- The Systems feature sets the correct variables and necessary rules for the
333
- client presented data.
334
- ***************/
335
- Systems() {
336
- this.zone('systems');
337
- const _cl = this.client();
338
- try {
339
- if (!_cl.features.systems) return this.Done(); // move to Done if no systems feature
340
- else {
341
- this.state('data');
342
- const {id, features, profile} = _cl; // set the local consts from client copy
343
- const {systems} = features; // set systems from features const
344
- this._systems = { // set this_systems with data
345
- id: this.uid(true), // uuid of the systems feature
346
- client_id: id, // client id for reference
347
- client_name: profile.name, // client name for personalization
348
- concerns: systems.concerns, // any concerns for client
349
- global: systems.global, // the global policies for client
350
- personal: systems.devas[this._agent.key], // Client personal features and rules.
351
- };
352
- delete this._client.features.systems;
353
- this.action('Systems');
354
- return this.Done();
355
- }
356
- } catch (e) {
357
- return this.error(e); // run error handling if an error is caught
358
- }
359
- }
360
-
361
-
362
318
  /**************
363
319
  func: Done
364
320
  params: none
@@ -676,8 +632,8 @@ class Deva {
676
632
  2. Assign the Interited Properties
677
633
  3. Assign binding functions and methods to 'this' scoe.
678
634
  4. Assign any listeners for additional functionality.
679
- 5. run the onInit custom function if preset or the system start function.
680
- 6. The system start function will create a chain reaction of states that load.
635
+ 5. run the onInit custom function if preset or the start function.
636
+ 6. The start function will create a chain reaction of states that load.
681
637
  7. If there is an error the init function rejects the call.
682
638
  usage: this.init(client_object)
683
639
  ***************/
@@ -723,7 +679,7 @@ class Deva {
723
679
  describe:
724
680
  The start function begins the process by setting the state to start setting
725
681
  the active to the current datetime and then checking for a custom onStart
726
- function or running the system enter function.
682
+ function or running the enter function.
727
683
  usage: this.start('msg')
728
684
  ***************/
729
685
  start(data) {
@@ -810,33 +766,31 @@ class Deva {
810
766
  describe:
811
767
  The stop function will stop the Deva by setting the active status to false,
812
768
  and the state to stop. From here it will check for a custom onStop function
813
- for anything to run, or run the system exit function.
769
+ for anything to run, or run the exit function.
814
770
 
815
771
  If the deva is offline it will return the offline message.
816
772
  usage:
817
- this.stop('msg')
773
+ this.stop()
818
774
  ***************/
819
775
  stop() {
820
776
  if (!this._active) return Promise.resolve(this._messages.offline);
821
777
 
822
- this.state('stop');
778
+ this.action('stop');
823
779
  const agent = this.agent();
824
780
  const client = this.client();
825
781
 
826
782
  const data = {
827
783
  id: this.uid(true),
828
784
  key: 'stop',
829
- value: agent.key,
785
+ value: this._messages.stop,
830
786
  agent,
831
787
  client,
832
- text: this._messages.stop,
833
788
  created: Date.now(),
834
789
  }
835
-
836
790
  data.hash = this.hash(data);
837
- const hasOnStop = this.onStop && typeof this.onStop === 'function';
838
791
 
839
- this.action('stop');
792
+ this.state('stop');
793
+ const hasOnStop = this.onStop && typeof this.onStop === 'function';
840
794
  return hasOnStop ? this.onStop(data) : this.exit(data)
841
795
  }
842
796
 
@@ -849,31 +803,38 @@ class Deva {
849
803
  The exit state function is triggered when the Deva is exiting it's online
850
804
  status and setting the state to exit for things like security check.
851
805
 
852
- The return will check for a custom onExit function or run the system done
806
+ The return will check for a custom onExit function or run the done
853
807
  function.
854
808
 
855
809
  If the deva is offline it will return the offline message.
856
810
  usage: this.exit('msg')
857
811
  ***************/
858
- exit(data) {
812
+ exit() {
813
+ this.zone('exit');
859
814
  this._active = false;
860
- data.value = 'exit';
861
- delete data.hash;
815
+
816
+ this.action('exit');
817
+ const agent = this.agent();
818
+ const client = this.client();
819
+
820
+ const data = {
821
+ id: this.uid(true),
822
+ key: 'exit',
823
+ value: this._messages.exit,
824
+ agent,
825
+ client,
826
+ created: Date.now(),
827
+ }
862
828
  data.hash = this.hash(data);
863
829
 
864
- this.state('exit');
865
830
  // clear memory
866
831
  this._active = false;
867
832
  this._client = false;
868
833
  this._security = false;
869
834
  this._support = false;
870
835
  this._services = false;
871
- this._business = false;
872
- this._development = false;
873
- this._legal = false;
874
- this._assistant = false;
875
836
 
876
- this.action('exit');
837
+ this.state('exit');
877
838
  const hasOnExit = this.onExit && typeof this.onExit === 'function';
878
839
  return hasOnExit ? this.onExit(data) : Promise.resolve(data)
879
840
  }
@@ -969,7 +930,7 @@ class Deva {
969
930
  this._action = action; // set the local action variable
970
931
  // check local vars for custom actions
971
932
  const var_action = this.vars.actions ? this.vars.actions[action] : false;
972
- // check system action messages
933
+ // check action messages
973
934
  const msg_action = this._actions[action] || var_action;
974
935
  const text = msg_action || action; // set the text of the action
975
936
  const data = { // build the data object for the action.
@@ -1005,7 +966,6 @@ class Deva {
1005
966
  describe
1006
967
  ***************/
1007
968
  feature(feature) {
1008
- this.action('feature');
1009
969
  try {
1010
970
  if (!this._features[feature]) return;
1011
971
  this._feature = feature;
@@ -1041,17 +1001,20 @@ class Deva {
1041
1001
  - st: The context flag to set for the Deva that matches to this._contexts
1042
1002
  describe
1043
1003
  ***************/
1044
- context(value=false) {
1004
+ context(value=false, extra=false) {
1045
1005
  try {
1046
1006
  if (!value) return this._context;
1047
1007
  this._context = value;
1008
+ const lookup = this.vars.context[value] || value;
1009
+ const text = extra ? `${lookup} ${extra}` : lookup;
1010
+
1048
1011
  const data = {
1049
1012
  id: this.uid(true),
1050
1013
  key: 'context',
1051
1014
  value,
1052
1015
  agent: this.agent(),
1053
1016
  client: this.client(),
1054
- text: this.vars.context[value] || value,
1017
+ text,
1055
1018
  created: Date.now(),
1056
1019
  };
1057
1020
  data.hash = this.hash(data);
@@ -1148,27 +1111,11 @@ class Deva {
1148
1111
  } catch (e) {return this.error(e);}
1149
1112
  }
1150
1113
 
1151
- /**************
1152
- func: systems
1153
- params: opts
1154
- describe: basic systems features available in a Deva.
1155
- usage: this.systems()
1156
- ***************/
1157
- systems(opts) {
1158
- this.feature('systems'); // set the systems state
1159
- if (!this._active) return this._messages.offline; // check the active status
1160
- this.state('data');
1161
- try {
1162
- this.action('systems'); // set the systems state
1163
- return this.copy(this._systems); // return the systems feature
1164
- } catch (e) {return this.error(e);}
1165
- }
1166
-
1167
1114
  /**************
1168
1115
  func: load
1169
1116
  params:
1170
1117
  -deva: The Deva model to load.
1171
- describe: This function will enable fast loading of Deva into a system.
1118
+ describe: This function will enable fast loading of Deva into the system.
1172
1119
  ***************/
1173
1120
  load(key, client) {
1174
1121
  this.state('load');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.2.15",
3
+ "version": "1.2.17",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "scripts": {