@indra.ai/deva 1.1.28 → 1.1.30

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.
package/index.js CHANGED
@@ -8,15 +8,18 @@ class Deva {
8
8
  constructor(opts) {
9
9
  opts = opts || {};
10
10
 
11
- this._id = randomUUID(); // the unique id assigned to the agent at load
12
- this._config = opts.config || {}; // local Config Object
13
- this._agent = opts.agent || false; // Agent profile object
14
- this._client = {}; // this will be set on init.
15
- this._state = 'OFFLINE'; // current state of agent.
11
+ this._id = randomUUID(); // the unique id assigned to the agent at load
12
+ this._config = opts.config || {}; // local Config Object
13
+ this._agent = opts.agent || false; // Agent profile object
14
+ this._client = {}; // this will be set on init.
15
+ this._state = 'OFFLINE'; // current state of agent.
16
16
  this._active = false; // the active/birth date.
17
- this._security = {}; // inherited Security features.
18
- this._support = {}; // inherited Support features.
19
- this._services = {}; // inherited Service features.
17
+ this._security = false; // inherited Security features.
18
+ this._support = false; // inherited Support features.
19
+ this._services = false; // inherited Service features.
20
+ this._assistant = false; // inherited @Assistant features.
21
+ this._business = false; // inherited @Business features.
22
+ this._legal = false; // inherited @Legal features.
20
23
  this.events = opts.events || new EventEmitter({}); // Event Bus
21
24
  this.lib = opts.lib || {}; // used for loading library functions
22
25
  this.devas = opts.devas || {}; // Devas which are loaded
@@ -31,99 +34,197 @@ class Deva {
31
34
  if (!this[opt]) this[opt] = opts[opt]; // set any remaining opts to this.
32
35
  }
33
36
 
34
- this.cmdChr = '/';
35
- this.askChr = '#';
36
- this.inherit = ["events", "config", "lib", "security", "client"];
37
- this.bind = ["listeners", "methods", "func", "lib", "security", "agent", "client"];
38
-
37
+ this.cmdChr = '/'; // the trigger for local commands
38
+ this.askChr = '#'; // the trigger for ask other DEva features
39
+ // index of the items
40
+ this.inherit = ["events", "lib"];
41
+ this.bind = [
42
+ "listeners",
43
+ "methods",
44
+ "func",
45
+ "lib",
46
+ "_agent"
47
+ ];
48
+ this.features = {
49
+ assistant: {
50
+ label: '🤖ASSISTANT',
51
+ name: '@ASSISTANT',
52
+ tag: '#ASSISTANT',
53
+ loc: '$ASSISTANT',
54
+ },
55
+ business: {
56
+ label: '💼BUSINESS',
57
+ name: '@BUSINESS',
58
+ tag: '#BUSINESS',
59
+ loc: '$BUSINESS',
60
+ },
61
+ legal: {
62
+ label: '👨‍⚖️LEGAL',
63
+ name: '@LEGAL',
64
+ tag: '#LEGAL',
65
+ loc: '$LEGAL',
66
+ },
67
+ development: {
68
+ label: '👨‍💻DEVELOPMENT',
69
+ name: '@DEVELOPMENT',
70
+ tag: '#DEVELOPMENT',
71
+ loc: '$DEVELOPMENT',
72
+ },
73
+ security: {
74
+ label: '🚨SECURITY',
75
+ name: '@SECURITY',
76
+ tag: '#SECURITY',
77
+ loc: '$SECURITY',
78
+ },
79
+ support: {
80
+ label: '🆘SUPPORT',
81
+ name: '@SUPPORT',
82
+ tag: '#SUPPORT',
83
+ loc: '$SUPPORT',
84
+ },
85
+ services: {
86
+ label: '📞SERVICES',
87
+ name: '@SERVICES',
88
+ tag: '#SERVICES',
89
+ loc: '$SERVICES',
90
+ },
91
+ solutions: {
92
+ label: '💡SOLUTIONS',
93
+ name: '@SOLUTIONS',
94
+ tag: '#SOLUTIONS',
95
+ loc: '$SOLUTIONS',
96
+ },
97
+ systems: {
98
+ label: '🔧SYSTEMS',
99
+ name: '@SOLUTIONS',
100
+ tag: '#SOLUTIONS',
101
+ loc: '$SOLUTIONS',
102
+ },
103
+ }
39
104
  }
40
105
 
41
- set State(opt) {
42
- this.state(opt);
43
- }
106
+ /**************
107
+ func: States
108
+ params: sts - custm states object to add to the system states
109
+ describe:
110
+ The States function builds the list of states with the associated client and
111
+ agent variables in the place holders. This function runs after the Client
112
+ function to ensure that hte messages are personalized to the Client and AGent.
113
+ ***************/
114
+ set States(sts) {
115
+ const {
116
+ development, security, services, support,
117
+ systems, solutions, assistant, business, legal
118
+ } = this.features;
44
119
 
45
- set States(opts) {
46
- console.log('CLIENT', this._client.profile.name);
120
+ const {_agent, _client} = this;
47
121
  const _states = {
48
- uid: `👻 ${this._agent.profile.name} is making a new #uid`,
49
- offline: `👻 ${this._agent.profile.name} is offline`,
50
- online: `📡 ${this._agent.profile.name} is online`,
51
- config: `‍📀 ${this._agent.profile.name} is checking the config`,
52
- client: `👨‍💻 ${this._agent.profile.name} opened the ${this._client.key} profile`,
53
- agent: `👨‍💻 ${this._agent.profile.name} is looking at ${this._agent.key} profile`,
54
- init: `🚀 ${this._agent.profile.name} is initializing for ${this._client.profile.name}`,
55
- start: `🎬 ${this._agent.profile.name} has started the process for ${this._client.profile.name}`,
56
- enter: `🎪 ${this._agent.profile.name} is entering the deva.world with${this._client.profile.name}`,
57
- stop: `🛑 ${this._agent.profile.name} has stopped for ${this._client.profile.name}`,
58
- exit: `🚪 ${this._agent.profile.name} found the exit with ${this._client.profile.name}`,
59
- done: `🤝 ${this._agent.profile.name} is all done time for #offerings 🍫🍌`,
60
- wait: `😵‍💫 ${this._agent.profile.name} waiting for #stuff from ${this._client.profile.name}`,
61
- data: `📀 ${this._agent.profile.name} is receiving #data for ${this._client.profile.name}`,
62
- ask: `🙋‍♀️ ${this._agent.profile.name} is asking a #question from ${this._client.profile.name}`,
63
- cmd: `📟 ${this._agent.profile.name} entered a #command from ${this._client.profile.name}`,
64
- question: `🐵 ${this._agent.profile.name} is in #question mode ${this._client.profile.name}`,
65
- ask: `🐵 ${this._agent.profile.name} is in #ask mode ${this._client.profile.name}`,
66
- talk: `🎙️ ${this._agent.profile.name} is in #talk mode with ${this._client.profile.name}`,
67
- listen: `🎧 ${this._agent.profile.name} is in #listening mode with ${this._client.profile.name}`,
68
- error: `❌ ${this._agent.profile.name} had an error. Let's have @Systems look into that.`,
69
- uid: `🪪 ${this._client.profile.name} made a #uid with ${this._agent.profile.name}`,
70
- hash: `🔑 ${this._client.profile.name} made a #hash with ${this._agent.profile.name}`,
71
- cipher: `🔐 ${this._client.profile.name} locked a #cipher with ${this._agent.profile.name}`,
72
- decipher: `🔓 ${this._client.profile.name} unlocked a #cipher with ${this._agent.profile.name}`,
73
- story: `📓 ${this._agent.profile.name} is creating an amazing #story ${this._client.profile.name}`,
74
- development: `👨‍💻 ${this._agent.profile.name} called for @Development assistance for ${this._client.profile.name}`,
75
- security: `🚨 ${this._agent.profile.name} called for @Security assistance for ${this._client.profile.name}`,
76
- support: `🎗️ ${this._agent.profile.name} called for @Support assistance for ${this._client.profile.name}`,
77
- services: `🎖️ ${this._agent.profile.name} called for @Services assistance for ${this._client.profile.name}`,
78
- systems: `👽 ${this._agent.profile.name} called for @Systems assistance for ${this._client.profile.name}`,
79
- solutions: `🔬 ${this._agent.profile.name} called for @Solutions assistance for ${this._client.profile.name}`,
80
- devas_start: `✨ Starting all the #Devas with ${this._client.profile.name}`,
81
- devas_ready: `📸 The #Devas are #ready and #waiitng for ${this._client.profile.name}`,
82
- devas_stop: `🙈 The #Devas are #stopping with ${this._client.profile.name}`,
83
- devas_stopped: `🛑 #Devas and ${this._client.profile.name} have #stopped, and that means time for #offerings 🍎🍑🍍🧋`,
84
- deva_load: `✅ ${this._agent.profile.name} loading for ${this._client.profile.name}`,
85
- deva_loaded: `✅ ${this._agent.profile.name} loaded for ${this._client.profile.name}`,
86
- deva_unloaded: `✅ ${this._agent.profile.name} unloaded for ${this._client.profile.name}`,
87
- question_me: `🐵 ${this._client.profile.name} started with a great #question to ${this._agent.profile.name}`,
88
- question_default: `🧞‍♂️ ${this._client.profile.name} asked a great #question to ${this._agent.profile.name}`,
89
- question_ask: `🧞 ${this._agent.profile.name} is pondering what ${this._client.profile.name} asked`,
90
- question_asking: `🧞 ${this._agent.profile.name} is asking another #Deva for ${this._client.profile.name}`,
91
- question_aswering: `🧞 ${this._agent.profile.name} is answering the #question ${this._client.profile.name} asked`,
92
- question_answer: `🔮 ${this._client.profile.name} received an #ansewr from ${this._agent.profile.name}`,
93
- question_command: `🧞‍♀️ ${this._client.profile.name} issued a #command to ${this._agent.profile.name}`,
94
- hash_question: `🔑 ${this._agent.profile.name} created the #question #hash for ${this._client.profile.name}`,
95
- hash_ask: `🔑 ${this._agent.profile.name} created the #ask #hash for ${this._client.profile.name}`,
96
- hash_answer: `🔑 ${this._agent.profile.name} #answer #hash with`,
97
- hash_command: `🔑 ${this._client.profile.name} #command #hash with ${this._agent.profile.name}`,
98
- hash_packet: `🔑 ${this._agent.profile.name} created the #packet #hash for ${this._client.profile.name}`,
99
- ask_question: `👽 ${this._client.profile.name} asked ${this._agent.profile.name} a great #question`,
100
- ask_answer: `🛸 ${this._client.profile.name} received a great #answer from ${this._agent.profile.name}`,
101
- method_not_found: `😩 ${this._client.profile.name} used a faulty #command while working with ${this._agent.profile.name}, and may need @Support`,
102
- ready_security: `🚓 @Security is ready`,
103
- ready_support: `🚑 @Support is ready`,
104
- ready_support: `🚑 @Support is ready`,
105
- ready_services: `🚚 @Services is ready`,
106
- ready_systems: `🏘️ @Systems is ready`,
107
- ready_solutions: `🤓 @Solutions is ready`,
108
- alert_security: `🚨 #SECURITY ALERT`,
109
- alert_support: `🚨 #SUPPORT ALERT`,
110
- alert_services: `🚨 #SERVICES ALERT`,
111
- alert_solutions: `🚨 #SOLUTIONS ALERT`,
112
- alert_systems: `🚨 #SYSTEMS ALERT`,
113
- alert_development: `🚨 #SYSTEMS ALERT`,
114
- setting_client: `⛄️ ${this._agent.profile.name} is setting the #client for ${this._client.profile.name} `,
115
- setting_development: `🔬 ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Development`,
116
- setting_security: `👮‍♂️ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Security`,
117
- setting_support: `👨‍⚕️ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Support`,
118
- setting_services: `👷‍♂️ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Services`,
119
- setting_systems: `🏘️ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Systems`,
120
- setting_solutions: `🤓 ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Solutions`,
122
+ uid: `${security.label}:UID ${_client.profile.name} made a #uid with ${_agent.profile.name}`,
123
+ hash: `${security.label}:HASH ${_client.profile.name} made a #hash with ${_agent.profile.name}`,
124
+ cipher: `${security.label}:CIPHER ${_client.profile.name} locked a #cipher with ${_agent.profile.name}`,
125
+ decipher: `${security.label}:DECIPHER ${_client.profile.name} unlocked a #cipher with ${_agent.profile.name}`,
126
+ offline: `👻 ${_agent.profile.name} is offline`,
127
+ online: `📡 ${_agent.profile.name} is online`,
128
+ config: `‍📀 ${_agent.profile.name} is checking the config`,
129
+ client: `👨‍💻 ${_agent.profile.name} opened the ${_client.key} profile`,
130
+ agent: `👨‍💻 ${_agent.profile.name} is looking at ${_agent.key} profile`,
131
+ init: `🚀 ${_agent.profile.name} is initializing for ${_client.profile.name}`,
132
+ start: `🎬 ${_agent.profile.name} has started the process for ${_client.profile.name}`,
133
+ enter: `🎪 ${_agent.profile.name} is entering the deva.world with${_client.profile.name}`,
134
+ stop: `🛑 ${_agent.profile.name} has stopped for ${_client.profile.name}`,
135
+ exit: `🚪 ${_agent.profile.name} found the exit with ${_client.profile.name}`,
136
+ done: `🤝 ${_agent.profile.name} is all done time for #offerings 🍫🍌`,
137
+ wait: `😵‍💫 ${_agent.profile.name} waiting for #stuff from ${_client.profile.name}`,
138
+ data: `📀 ${_agent.profile.name} is receiving #data for ${_client.profile.name}`,
139
+ ask: `🙋‍♀️ ${_agent.profile.name} is asking a #question from ${_client.profile.name}`,
140
+ cmd: `📟 ${_agent.profile.name} entered a #command from ${_client.profile.name}`,
141
+ question: `🐵 ${_agent.profile.name} is in #question mode ${_client.profile.name}`,
142
+ ask: `🐵 ${_agent.profile.name} is in #ask mode ${_client.profile.name}`,
143
+ talk: `🎙️ ${_agent.profile.name} is in #talk mode with ${_client.profile.name}`,
144
+ listen: `🎧 ${_agent.profile.name} is in #listening mode with ${_client.profile.name}`,
145
+ error: `❌ ${_agent.profile.name} had an error. Let's have @Systems look into that.`,
146
+ story: `📓STORY: ${_client.profile.name} is creating an amazing #story ${_client.profile.name}`,
147
+ development: `${development.label}: ${_client.profile.name} and ${_agent.profile.name} need ${development.name} assistance`,
148
+ security: `${security.label}: ${_client.profile.name} and ${_agent.profile.name} need ${security.name} assistance`,
149
+ support: `${support.label}: ${_client.profile.name} and ${_agent.profile.name} need ${support.name} assistance`,
150
+ services: `${services.label}: ${_client.profile.name} and ${_agent.profile.name} need ${services.name} assistance`,
151
+ systems: `${systems.label}: ${_client.profile.name} and ${_agent.profile.name} need ${systems.name} assistance`,
152
+ solutions: `${development.label}: ${_client.profile.name} and ${_agent.profile.name} need ${development.name} assistance`,
153
+ legal: `${legal.label}: ${_client.profile.name} and ${_agent.profile.name} need ${legal.name} assistance`,
154
+ business: `${business.label}: ${_client.profile.name} and ${_agent.profile.name} need ${business.name} assistance`,
155
+ devas_start: `🧞‍♂️DEVAS: Starting all the #Devas with ${_client.profile.name}`,
156
+ devas_ready: `🧞‍♂️DEVA:READY The #Devas are #ready and #waiitng for ${_client.profile.name} using @${_client.profile.key} #${_client.profile.key} $${_client.profile.key}`,
157
+ devas_stop: `🧞‍♂️DEVA:STOPPING The #Devas are #stopping with ${_client.profile.name}`,
158
+ devas_stopped: `🧞‍♂️DEVA:🛑STOP #Devas and ${_client.profile.name} have #stopped, and that means time for #offerings 🍎🍑🍍🧋`,
159
+ deva_load: `🧞‍♂️DEVA:LOADING ${_agent.profile.name} loading for ${_client.profile.name}`,
160
+ deva_loaded: `🧞‍♂️DEVA:LOADED ${_agent.profile.name} loaded for ${_client.profile.name}`,
161
+ deva_unloaded: `🧞‍♂️DEVAS:UNLOADED ${_agent.profile.name} unloaded for ${_client.profile.name}`,
162
+ question_me: `❓QUESTION:START ${_client.profile.name} started with a great #question to ${_agent.profile.name}`,
163
+ question_default: `🧞‍♂️QUESTION:ME ${_client.profile.name} asked a great #question to ${_agent.profile.name}`,
164
+ question_ask: `🧞QUESTION:ASK ${_agent.profile.name} is pondering what ${_client.profile.name} asked`,
165
+ question_asking: `🧞QUESTION:ASK:ANSWER ${_agent.profile.name} is asking another #Deva for ${_client.profile.name}`,
166
+ question_aswering: `🧞QUESTION:ASK:ANSWERING ${_agent.profile.name} is answering the #question ${_client.profile.name} asked`,
167
+ question_answer: `🔮QUESTION:ANSWER ${_client.profile.name} received an #ansewr from ${_agent.profile.name}`,
168
+ question_command: `🧞‍♀️QUESTION:CMD ${_client.profile.name} issued a #command to ${_agent.profile.name}`,
169
+ hash_question: `${security.label}:HASH:QUESTION ${_agent.profile.name} created the #question #hash for ${_client.profile.name}`,
170
+ hash_ask: `${security.label}:HASH:ASK ${_agent.profile.name} created the #ask #hash for ${_client.profile.name}`,
171
+ hash_answer: `${security.label}:HASH:ANSWER ${_client.profile.name} #answer #hash with ${_agent.profile.name}`,
172
+ hash_command: `${security.label}:HASH:COMMAND ${_client.profile.name} used a #command with ${_agent.profile.name}`,
173
+ hash_packet: `${security.label}:HASH:PACKET ${_agent.profile.name} created the #packet #hash for ${_client.profile.name}`,
174
+ ask_question: `❓QUESTION: ${_client.profile.name} asked ${_agent.profile.name} a great #question`,
175
+ ask_answer: `💡ANSWER: ${_client.profile.name} received a great #answer from ${_agent.profile.name}`,
176
+ method_not_found: `${security.label}:ERROR:COMMAND ${_client.profile.name} used a #command while working with ${_agent.profile.name}, and may need from ${security.name}`,
177
+
178
+ ready_security: `${security.label}:READY - ${security.name} is ready on ${security.tag} in ${security.loc}`,
179
+ ready_support: `${support.label}:READY - ${support.name} is ready on ${support.tag} in ${support.loc}`,
180
+ ready_services: `${services.label}:READY - ${services.name} is ready on ${services.tag} in ${services.loc}`,
181
+ ready_systems: `${systems.label}:READY - ${systems.name} is ready on ${systems.tag} in ${systems.loc}`,
182
+ ready_solutions: `${solutions.label}:READY - ${solutions.name} is ready on ${solutions.tag} in ${solutions.loc}`,
183
+ ready_development: `${development.label}:READY - ${development.name} is ready ${development.tag} in ${development.loc}`,
184
+ ready_legal: `${legal.label}:READY - ${legal.name} is ready on ${legal.tag} in ${legal.loc}`,
185
+ ready_business: `${business.label}:READY - ${business.name} is ready ${business.tag} in ${business.loc}`,
186
+ ready_assistant: `${assistant.label}:READY - ${assistant.name} is ready ${assistant.tag} in ${business.loc}`,
187
+
188
+ alert_security: `${security.label}:ALERT There is an #issue with ${_client.profile.name} and ${_agent.profile.name}.`,
189
+ alert_support: `${support.label}:ALERT There is an #issue with ${_client.profile.name} and ${_agent.profile.name}.`,
190
+ alert_services: `${services.label}:ALERT There is an #issue with ${_client.profile.name} and ${_agent.profile.name}.`,
191
+ alert_solutions: `${solutions.label}:ALERT There is an #issue with ${_client.profile.name} and ${_agent.profile.name}.`,
192
+ alert_systems: `${systems.label}:ALERT There is an #issue with ${_client.profile.name} and ${_agent.profile.name}.`,
193
+ alert_development: `${development.label}:ALERT There is an #issue with ${_client.profile.name} and ${_agent.profile.name}.`,
194
+ alert_assistant: `${assistant.label}:ALERT There is an #issue with ${_client.profile.name} and ${_agent.profile.name}.`,
195
+ alert_legal: `${legal.label}:ALERT There is an #issue with ${_client.profile.name} and ${_agent.profile.name}.`,
196
+ alert_business: `${business.label}:ALERT There is an #issue with ${_client.profile.name} and ${_agent.profile.name}.`,
197
+
198
+ setting_client: `👨CLIENT: ${_agent.profile.name} is setting #${_client.key} for ${_client.profile.name} `,
199
+ setting_development: `${development.label}: ${_client.profile.name} and ${_agent.profile.name} are receiving ${development.name} on ${development.tag} in ${development.loc}`,
200
+ setting_security: `${security.label}: ${_client.profile.name} and ${_agent.profile.name} are receiving ${security.name} on ${security.tag} in ${security.loc}`,
201
+ setting_support: `${development.label}: ${_client.profile.name} and ${_agent.profile.name} are receiving ${development.name} on ${development.tag} in ${development.loc}`,
202
+ setting_services: `${services.label}: ${_client.profile.name} and ${_agent.profile.name} are receiving ${services.name} on ${services.tag} in ${services.loc}`,
203
+ setting_systems: `${systems.label}: ${_client.profile.name} and ${_agent.profile.name} are receiving ${systems.name} on ${systems.tag} in ${systems.loc}`,
204
+ setting_solutions: `${solutions.label}: ${_client.profile.name} and ${_agent.profile.name} are receiving ${solutions.name} on ${solutions.tag} in ${solutions.loc}`,
205
+ setting_assistant: `${assistant.label}: ${_client.profile.name} and ${_agent.profile.name} are receiving ${assistant.name} on ${assistant.tag} in ${assistant.loc}`,
206
+ setting_legal: `${legal.label}: ${_client.profile.name} and ${_agent.profile.name} are receiving ${legal.name} on ${legal.tag} in ${legal.loc}`,
207
+ setting_business: `${business.label}: ${_client.profile.name} and ${_agent.profile.name} are receiving ${business.name} on ${business.tag} in ${business.loc}`,
121
208
  }
122
- this._states = _states; // The available states to work with.
209
+
210
+ // determine if msgs is an object and then loop the msgs
211
+ if (sts && typeof sts === 'object') for (let x in sts) {
212
+ if (!_states[x]) _states[x] = sts[x]; // new state added if not matching _states
213
+ }
214
+ this._states = _states; // set _states as this._states;
215
+ this._states = _states; // The available states to work with.
123
216
  }
124
217
 
125
- set Messages(opts) {
126
- this._messages = {
218
+ /**************
219
+ func: Messages
220
+ params: msgs -additional messages
221
+ describe:
222
+ The Messages function builds the system messages, and allows for the
223
+ reloading of system messages when client or agent data changes.
224
+ ***************/
225
+ set Messages(msgs) {
226
+ // Default system messages
227
+ const _messages = {
127
228
  offline: `🙅‍♂️ ${this._agent.profile.name} offline`,
128
229
  init: `⚠️ ${this._agent.profile.name} init`,
129
230
  start: `✅ ${this._agent.profile.name} start`,
@@ -133,133 +234,313 @@ class Deva {
133
234
  done: `👍 ${this._agent.profile.name} done.`,
134
235
  devas_started: '#Devas are #online and ready for #offerings 🍫🥛🍚🍯🧂',
135
236
  devas_stopped: '🛑 #Devas have stopped',
136
- notext: `❌ ${this._client.profile.name}, please provide with valid input.`,
237
+ notext: `❌ ${this._client.profile.name}, Invalid input.`,
137
238
  method_not_found: `❌ ${this._client.profile.name} you sure messed that up!`,
138
239
  }
240
+
241
+ // determine if msgs is an object and then loop the msgs
242
+ if (msgs && typeof msgs === 'object') for (let x in msgs) {
243
+ if (!_messages[x]) _messages[x] = msgs[x]; // new msg added if not matching _messages
244
+ }
245
+ this._messages = this.copy(_messages); // set a copy of _messages as this._messages;
139
246
  }
247
+
248
+ /**************
249
+ func: Client
250
+ params: client - client provided data.
251
+ describe:
252
+ The Client feature sets up the client variables and removes any unnecessary
253
+ keys from the client object that are used in other features.
254
+
255
+ usage:
256
+ this.Client = {data}
257
+ ***************/
140
258
  set Client(client) {
141
- // copy the cl parameter into a local _client variable
142
- const _client = this.copy(client);
143
-
144
- // delete the keys used for other features.
145
- if (_client.states) delete _client.states;
146
- if (_client.messages) delete _client.messages;
147
- if (_client.development) delete _client.development;
148
- if (_client.security) delete _client.security;
149
- if (_client.support) delete _client.support;
150
- if (_client.services) delete _client.services;
151
- if (_client.systems) delete _client.systems;
152
- if (_client.solutions) delete _client.solutions;
153
-
154
- // set the local client variable from the clean _client local variable.
155
- this._client = _client;
156
-
157
- // set the states and messages after the cleint is set.
158
- this.States = client.states;
159
- this.Messages = client.messages;
259
+ const _client = this.copy(client); // copy the client parameter
260
+ if (_client.states) delete _client.states; // delete states key for client security
261
+ if (_client.messages) delete _client.messages; // delete messages key for client security
262
+ if (_client.featuers) delete _client.features; // delete features key for client security
263
+ this._client = _client; // set local _client to this scope
264
+ this.States = client.states; // set the States after the Client
265
+ this.Messages = client.messages; // set the Messages after the Client
160
266
  }
161
267
 
162
- // setup the @Security feature
268
+ /**************
269
+ func: Security
270
+ params: client: false
271
+ describe:
272
+ The Security feature sets the correct variables and necessary rules for the
273
+ client presented data.
274
+ ***************/
163
275
  set Security(client=false) {
164
- if (!client) this._security = {};
165
- else {
166
- this.state('setting_security');
167
- const _client = this.copy(client);
168
- this._security = {
169
- id: this.uid(true),
170
- client_id: _client.id,
171
- client_name: _client.profile.name,
172
- hash: _client.security.hash,
173
- cipher: _client.security.cipher,
174
- concerns: _client.security.concerns,
175
- global: _client.security.global,
176
- personal: _client.security.devas[this._agent.key]
177
- };
276
+ try {
277
+ if (!client) this._security = {}; // if no client then set to empty object
278
+ else {
279
+ this.state('setting_security'); // set state to security setting
280
+ const _client = this.copy(client); // make a copy the clinet data.
281
+ const {id, features, profile} = _client; // set the local consts from client copy
282
+ const {security} = features; // set security from features const
283
+ this._security = { // set this_security with data
284
+ id: this.uid(true), // uuid of the security feature
285
+ client_id: id, // client id for reference
286
+ client_name: profile.name, // client name for personalization
287
+ hash: security.hash, // client preferred hash algorithm
288
+ cipher: security.cipher, // client preferred cipher settings
289
+ concerns: security.concerns, // any concerns for client
290
+ global: security.global, // the global policies for client
291
+ personal: security.devas[this._agent.key] // Client personal features and rules.
292
+ };
293
+ }
294
+ } catch (e) {
295
+ this.error(e, client) // run error handling if an error is caught
178
296
  }
179
297
  }
180
298
 
181
- // setup the @Support feature
299
+ /**************
300
+ func: Support
301
+ params: client: false
302
+ describe:
303
+ The Support feature sets the correct variables and necessary rules for the
304
+ client presented data.
305
+ ***************/
182
306
  set Support(client=false) {
183
- if (!client) this._support = {};
184
- else {
185
- this.state('setting_support');
186
- const _client = this.copy(client);
187
- this._support = {
188
- id: this.uid(true),
189
- client_id: _client.id,
190
- client_name: _client.profile.name,
191
- concerns: _client.support.concerns,
192
- global: _client.support.global,
193
- personal: _client.support.devas[this._agent.key]
194
- };
307
+ try {
308
+ if (!client) this._support = {}; // if no client then set to empty object
309
+ else {
310
+ this.state('setting_support'); // set state to support setting
311
+ const _client = this.copy(client); // make a copy the clinet data.
312
+ const {id, features, profile} = _client; // set the local consts from client copy
313
+ const {support} = features; // set support from features const
314
+ this._support = { // set this_support with data
315
+ id: this.uid(true), // uuid of the support feature
316
+ client_id: id, // client id for reference
317
+ client_name: profile.name, // client name for personalization
318
+ hash: support.hash, // client preferred hash algorithm
319
+ cipher: support.cipher, // client preferred cipher settings
320
+ concerns: support.concerns, // any concerns for client
321
+ global: support.global, // the global policies for client
322
+ personal: support.devas[this._agent.key] // Client personalSecurity features and rules.
323
+ };
324
+ }
325
+ } catch (e) {
326
+ this.error(e, client) // run error handling if an error is caught
195
327
  }
196
328
  }
197
329
 
198
- // setup the @Services feature
330
+ /**************
331
+ func: Services
332
+ params: client: false
333
+ describe:
334
+ The Services feature sets the correct variables and necessary rules for the
335
+ client presented data.
336
+ ***************/
199
337
  set Services(client=false) {
200
- if (!client) this._servcies = {};
201
- else {
202
- this.state('setting_services');
203
- const _client = this.copy(client);
204
- this._services = {
205
- id: this.uid(true),
206
- client_id: _client.id,
207
- client_name: _client.profile.name,
208
- concerns: _client.services.concerns,
209
- global: _client.services.global,
210
- personal: _client.services.devas[this._agent.key]
211
- };
338
+ try {
339
+ if (!client) this._security = {}; // if no client then set to empty object
340
+ else {
341
+ this.state('setting_security'); // set state to security setting
342
+ const _client = this.copy(client); // make a copy the clinet data.
343
+ const {id, features, profile} = _client; // set the local consts from client copy
344
+ const {security} = features; // set security from features const
345
+ this._security = { // set this_security with data
346
+ id: this.uid(true), // uuid of the security feature
347
+ client_id: id, // client id for reference
348
+ client_name: profile.name, // client name for personalization
349
+ hash: security.hash, // client preferred hash algorithm
350
+ cipher: security.cipher, // client preferred cipher settings
351
+ concerns: security.concerns, // any concerns for client
352
+ global: security.global, // the global policies for client
353
+ personal: security.devas[this._agent.key] // Client personal features and rules.
354
+ };
355
+ }
356
+ } catch (e) {
357
+ this.error(e, client) // run error handling if an error is caught
212
358
  }
213
359
  }
214
360
 
215
- // setup the @Systems feature
361
+ /**************
362
+ func: Systems
363
+ params: client: false
364
+ describe:
365
+ The Systems feature sets the correct variables and necessary rules for the
366
+ client presented data.
367
+ ***************/
216
368
  set Systems(client=false) {
217
- if (!client) this._systems = {};
218
- else {
219
- this.state('setting_systems');
220
- const _client = this.copy(client);
221
- this._systems = {
222
- id: this.uid(true),
223
- client_id: _client.id,
224
- client_name: _client.profile.name,
225
- concerns: _client.systems.concerns,
226
- global: _client.systems.global,
227
- personal: _client.systems.devas[this._agent.key]
228
- };
369
+ try {
370
+ if (!client) this._systems = {}; // if no client then set to empty object
371
+ else {
372
+ this.state('setting_systems'); // set state to systems setting
373
+ const _client = this.copy(client); // make a copy the clinet data.
374
+ const {id, features, profile} = _client; // set the local consts from client copy
375
+ const {systems} = features; // set systems from features const
376
+ this._systems = { // set this_systems with data
377
+ id: this.uid(true), // uuid of the systems feature
378
+ client_id: id, // client id for reference
379
+ client_name: profile.name, // client name for personalization
380
+ hash: systems.hash, // client preferred hash algorithm
381
+ cipher: systems.cipher, // client preferred cipher settings
382
+ concerns: systems.concerns, // any concerns for client
383
+ global: systems.global, // the global policies for client
384
+ personal: systems.devas[this._agent.key] // Client personal features and rules.
385
+ };
386
+ }
387
+ } catch (e) {
388
+ this.error(e, client) // run error handling if an error is caught
229
389
  }
230
390
  }
231
391
 
232
- // setup the @Solutions feature
392
+ /**************
393
+ func: Solutions
394
+ params: client: false
395
+ describe:
396
+ The Solutions feature sets the correct variables and necessary rules for the
397
+ client presented data.
398
+ ***************/
233
399
  set Solutions(client=false) {
234
- if (!client) this._solutions = {};
235
- else {
236
- this.state('setting_solutions');
237
- const _client = this.copy(client);
238
- this._solutions = {
239
- id: this.uid(true),
240
- client_id: _client.id,
241
- client_name: _client.profile.name,
242
- concerns: _client.solutions.concerns,
243
- global: _client.solutions.global,
244
- personal: _client.solutions.devas[this._agent.key]
245
- };
400
+ try {
401
+ if (!client) this._solutions = {}; // if no client then set to empty object
402
+ else {
403
+ this.state('setting_solutions'); // set state to solutions setting
404
+ const _client = this.copy(client); // make a copy the clinet data.
405
+ const {id, features, profile} = _client; // set the local consts from client copy
406
+ const {solutions} = features; // set solutions from features const
407
+ this._solutions = { // set this_solutions with data
408
+ id: this.uid(true), // uuid of the solutions feature
409
+ client_id: id, // client id for reference
410
+ client_name: profile.name, // client name for personalization
411
+ hash: solutions.hash, // client preferred hash algorithm
412
+ cipher: solutions.cipher, // client preferred cipher settings
413
+ concerns: solutions.concerns, // any concerns for client
414
+ global: solutions.global, // the global policies for client
415
+ personal: solutions.devas[this._agent.key] // Client personal features and rules.
416
+ };
417
+ }
418
+ } catch (e) {
419
+ this.error(e, client) // run error handling if an error is caught
246
420
  }
247
421
  }
248
422
 
249
- // setup the @Development feature.
423
+ /**************
424
+ func: Development
425
+ params: client: false
426
+ describe:
427
+ The Development feature sets the correct variables and necessary rules for the
428
+ client presented data.
429
+ ***************/
250
430
  set Development(client=false) {
251
- if (!client) this._development = {};
252
- else {
253
- this.state('setting_development');
254
- const _client = this.copy(client);
255
- this._development = {
256
- id: this.uid(true),
257
- client_id: _client.id,
258
- client_name: _client.profile.name,
259
- concerns: _client.development.concerns,
260
- global: _client.development.global,
261
- personal: _client.development.devas[this._agent.key]
262
- };
431
+ try {
432
+ if (!client) this._development = {}; // if no client then set to empty object
433
+ else {
434
+ this.state('setting_development'); // set state to development setting
435
+ const _client = this.copy(client); // make a copy the clinet data.
436
+ const {id, features, profile} = _client; // set the local consts from client copy
437
+ const {development} = features; // set development from features const
438
+ this._development = { // set this_development with data
439
+ id: this.uid(true), // uuid of the development feature
440
+ client_id: id, // client id for reference
441
+ client_name: profile.name, // client name for personalization
442
+ hash: development.hash, // client preferred hash algorithm
443
+ cipher: development.cipher, // client preferred cipher settings
444
+ concerns: development.concerns, // any concerns for client
445
+ global: development.global, // the global policies for client
446
+ personal: development.devas[this._agent.key] // Client personal features and rules.
447
+ };
448
+ }
449
+ } catch (e) {
450
+ this.error(e, client) // run error handling if an error is caught
451
+ }
452
+ }
453
+
454
+ /**************
455
+ func: Assistant
456
+ params: client: false
457
+ describe:
458
+ The Assistant feature sets the correct variables and necessary rules for the
459
+ client presented data.
460
+ ***************/
461
+ set Assistant(client=false) {
462
+ try {
463
+ if (!client) this._assistant = {}; // if no client then set to empty object
464
+ else {
465
+ this.state('setting_assistant'); // set state to assistant setting
466
+ const _client = this.copy(client); // make a copy the clinet data.
467
+ const {id, features, profile} = _client; // set the local consts from client copy
468
+ const {assistant} = features; // set assistant from features const
469
+ this._assistant = { // set this_assistant with data
470
+ id: this.uid(true), // uuid of the assistant feature
471
+ client_id: id, // client id for reference
472
+ client_name: profile.name, // client name for personalization
473
+ hash: assistant.hash, // client preferred hash algorithm
474
+ cipher: assistant.cipher, // client preferred cipher settings
475
+ concerns: assistant.concerns, // any concerns for client
476
+ global: assistant.global, // the global policies for client
477
+ personal: assistant.devas[this._agent.key] // Client personal features and rules.
478
+ };
479
+ }
480
+ } catch (e) {
481
+ this.error(e, client) // run error handling if an error is caught
482
+ }
483
+ }
484
+
485
+ /**************
486
+ func: Business
487
+ params: client: false
488
+ describe:
489
+ The Business feature sets the correct variables and necessary rules for the
490
+ client presented data.
491
+ ***************/
492
+ set Business(client=false) {
493
+ try {
494
+ if (!client) this._business = {}; // if no client then set to empty object
495
+ else {
496
+ this.state('setting_business'); // set state to business setting
497
+ const _client = this.copy(client); // make a copy the clinet data.
498
+ const {id, features, profile} = _client; // set the local consts from client copy
499
+ const {business} = features; // set business from features const
500
+ this._business = { // set this_business with data
501
+ id: this.uid(true), // uuid of the business feature
502
+ client_id: id, // client id for reference
503
+ client_name: profile.name, // client name for personalization
504
+ hash: business.hash, // client preferred hash algorithm
505
+ cipher: business.cipher, // client preferred cipher settings
506
+ concerns: business.concerns, // any concerns for client
507
+ global: business.global, // the global policies for client
508
+ personal: business.devas[this._agent.key] // Client personal features and rules.
509
+ };
510
+ }
511
+ } catch (e) {
512
+ this.error(e, client) // run error handling if an error is caught
513
+ }
514
+ }
515
+
516
+ /**************
517
+ func: Legal
518
+ params: client: false
519
+ describe:
520
+ The Legal feature sets the correct variables and necessary rules for the
521
+ client presented data.
522
+ ***************/
523
+ set Legal(client=false) {
524
+ try {
525
+ if (!client) this._legal = {}; // if no client then set to empty object
526
+ else {
527
+ this.state('setting_legal'); // set state to legal setting
528
+ const _client = this.copy(client); // make a copy the clinet data.
529
+ const {id, features, profile} = _client; // set the local consts from client copy
530
+ const {legal} = features; // set legal from features const
531
+ this._legal = { // set this_legal with data
532
+ id: this.uid(true), // uuid of the legal feature
533
+ client_id: id, // client id for reference
534
+ client_name: profile.name, // client name for personalization
535
+ hash: legal.hash, // client preferred hash algorithm
536
+ cipher: legal.cipher, // client preferred cipher settings
537
+ concerns: legal.concerns, // any concerns for client
538
+ global: legal.global, // the global policies for client
539
+ personal: legal.devas[this._agent.key] // Client personal features and rules.
540
+ };
541
+ }
542
+ } catch (e) {
543
+ this.error(e, client) // run error handling if an error is caught
263
544
  }
264
545
  }
265
546
 
@@ -288,7 +569,7 @@ class Deva {
288
569
  if (parse) this._agent.parse = this._agent.parse.bind(this);
289
570
  }
290
571
  catch (e) {
291
- return reject(e);
572
+ return this.error(e, false, reject);
292
573
  }
293
574
  finally {
294
575
  return resolve();
@@ -323,7 +604,7 @@ class Deva {
323
604
  }
324
605
  }
325
606
  catch (e) {
326
- return reject(e);
607
+ return this.error(e, false, reject);
327
608
  }
328
609
  finally {
329
610
  return resolve();
@@ -350,7 +631,7 @@ class Deva {
350
631
  }
351
632
  }
352
633
  catch (e) {
353
- return reject(e);
634
+ return this.error(e, false, reject);
354
635
  }
355
636
  finally {
356
637
  return resolve();
@@ -405,7 +686,7 @@ class Deva {
405
686
  ***************/
406
687
  state(st, data=false) {
407
688
  if (!Object.keys(this._states).includes(st)) return;
408
- this._state = `${this._states[st]} on ${this.formatDate(Date.now(), 'short_month', true)}`;
689
+ this._state = `${this._states[st]} | ${this.formatDate(Date.now(), 'short_month', true)}`;
409
690
  const _data = {
410
691
  id: this.uid(true),
411
692
  client: this._client.id,
@@ -454,15 +735,19 @@ class Deva {
454
735
  describe:
455
736
  The hash algorithm will take a string of text and produce a hash.
456
737
  ***************/
457
- hash(str) {
458
- const algo = this._security.hash || 'md5';
738
+ hash(str, algo=false) {
739
+ algo = algo || this._security.hash || 'md5';
459
740
  const the_hash = createHash(algo);
460
741
  the_hash.update(str);
461
742
  const _digest = the_hash.digest('base64');
462
743
  this.state('hash', {
463
-
464
- })
465
- return ;
744
+ id: this.uid(true),
745
+ value: _digest,
746
+ client_id: this._client.id,
747
+ agent_id: this._agent.id,
748
+ created: Date.now(),
749
+ });
750
+ return _digest;
466
751
  }
467
752
 
468
753
  /**************
@@ -694,11 +979,11 @@ class Deva {
694
979
  describe:
695
980
  ***************/
696
981
  question(TEXT=false, DATA=false) {
982
+ // check the active status
697
983
  if (!this._active) return Promise.resolve(this._messages.offline);
698
- this.state('question_me', {text:TEXT, data:DATA});
699
-
700
- const id = this.uid(); // generate a unique transport id for the question.
701
- const t_split = TEXT.split(' ');
984
+ this.state('question_me', {text:TEXT, data:DATA}); // set the question me state text TEXT & DATA passed in.
985
+ const id = this.uid(); // generate a unique id for transport.
986
+ const t_split = TEXT.split(' '); // split the text on spaces to get words.
702
987
 
703
988
  // check to see if the string is an #ask string to talk to the other Deva.
704
989
  const isAsk = t_split[0].startsWith(this.askChr);
@@ -707,98 +992,99 @@ class Deva {
707
992
  const isCmd = t_split[0].startsWith(this.cmdChr);
708
993
 
709
994
  // Format the packet for return on the request.
710
- const orig = TEXT;
711
- const data = DATA;
712
- const packet = {
713
- id,
714
- q: {},
715
- a: {},
716
- created: Date.now(),
995
+ const orig = TEXT; // set the TEXT to orig
996
+ const data = DATA; // set the DATA to data
997
+ const packet = { // create the base q/a packet
998
+ id, // set the id into packet
999
+ q: {}, // create empty q object in packet
1000
+ a: {}, // create empty a object in packet
1001
+ created: Date.now(), // timestamp the packet
717
1002
  };
718
1003
 
719
- let text = TEXT,
720
- params = false,
721
- method = 'question',
722
- key = this._agent.key;
1004
+ let text = TEXT, // let TEXT is text for a manipulation variable
1005
+ params = false, // params as false to build params string
1006
+ method = 'question', // set the default method to question
1007
+ key = this._agent.key; // set a temporary key from the agent key.
723
1008
 
724
1009
  return new Promise((resolve, reject) => {
725
- if (!TEXT) return reject(this._messages.notext);
726
- try {
727
- if (!this._active) return reject(this._messages.offline);
728
-
729
- let _state = 'question_default';
730
- let _hash = 'hash_asnwer';
731
-
732
- // *: send just a string of text
733
- // !: send a command to the local agent
734
- // #: ask another agent a question
735
- // #agent method:param1:param2 with text strings for proccessing
736
- // !method param:list:parse for the local agent
737
- // if is an ask then we format one way
738
- if (isAsk) {
739
- _state = 'question_ask'
740
- _state = 'hash_ask'
741
- key = t_split[0].substring(1);
1010
+ // resolve with the no text message if the client says nothing.
1011
+ if (!TEXT) return resolve(this._messages.notext);
1012
+ // reject question if Deva offline
1013
+ if (!this._active) return resolve(this._messages.offline);
1014
+
1015
+ try { // try to answer the question
1016
+ let _state = 'question_default'; // set temporary question state variable
1017
+ let _hash = 'hash_asnwer'; // set emporary hash state variable
1018
+ if (isAsk) { // determine if hte question isAsk
1019
+ _state = 'question_ask' // if:isAk then set question state
1020
+ _state = 'hash_ask' // if:isAsk then set hash state
1021
+ key = t_split[0].substring(1); // if:isAsksplit the agent key and remove first command character
1022
+ //if:isAsk use text split index 1 as the parameter block
742
1023
  params = t_split[1] ? t_split[1].split(':') : false;
743
- method = params[0];
744
- text = t_split.slice(2).join(' ').trim();
745
-
1024
+ method = params[0]; // the method to check is then params index 0
1025
+ text = t_split.slice(2).join(' ').trim(); // then rejoin the text with spaces.
746
1026
  }
747
- else if (isCmd) {
748
- _state = 'question_command';
749
- _hash = 'hash_command'
1027
+ else if (isCmd) { // determine if the question is a command
1028
+ _state = 'question_command'; // if:isCmd set question state
1029
+ _hash = 'hash_command' // if:isCmd set hash state
1030
+ //if:isCmd use text split index 1 as the parameter block
750
1031
  params = t_split[1] ? t_split[1].split(':') : false;
751
- method = t_split[0].substring(1);
752
- text = t_split.slice(1).join(' ').trim()
1032
+ method = t_split[0].substring(1); // if:isCmd use the 0 index as the command
1033
+ text = t_split.slice(1).join(' ').trim(); // if:isCmd rejoin the string on the space after removing first index
753
1034
  }
754
1035
 
755
- packet.q = {
756
- agent: this._agent || false,
757
- client: this._client || false,
758
- meta: {
759
- key,
760
- orig,
761
- method,
762
- params,
1036
+ packet.q = { // build packet.q container
1037
+ agent: this._agent || false, // set the agent
1038
+ client: this._client || false, // set the client
1039
+ meta: { // build the meta container
1040
+ key, // set the key variable
1041
+ orig, // set orig text to track chances
1042
+ method, // set method to track function use
1043
+ params, // set any params that are associated
763
1044
  },
764
- text,
765
- data,
766
- created: Date.now(),
1045
+ text, // set the text after it has been modified form orig
1046
+ data, // set the data object
1047
+ created: Date.now(), // timestamp the question
767
1048
  }
768
1049
 
769
- // hash the packet and insert the hash into the packet meta object.
770
- this.state('hash_question');
1050
+ this.state('hash_question'); // set the has question state
1051
+ // hash the question
771
1052
  packet.q.meta.hash = this.hash(JSON.stringify(packet.q));
772
1053
 
773
- this.state(_state, packet);
1054
+ this.state(_state, packet); // set the state to teh _state variable
774
1055
 
775
- // If a question to another Deva with '#' then trigger events
776
- if (isAsk) {
777
- this.state('question_asking');
778
- this.talk(`${key}:ask`, packet);
1056
+ if (isAsk) { // isAsk check if the question isAsk and talk
1057
+ this.state('question_asking'); // if:isAsk set state to question asking
1058
+ this.talk(`${key}:ask`, packet); // if:isAsk talk the event to theother Deva
1059
+ // if: isAsk wait for the once event which is key'd to the packet ID for specified responses
779
1060
  this.once(`${key}:ask:${packet.id}`, answer => {
780
- return resolve(answer);
1061
+ return resolve(answer); // if:isAsk resolve the answer from the call
781
1062
  });
782
1063
  }
783
1064
 
784
- // if the user sends a local command '$' then it will ask of the self.
785
- else {
1065
+ else { // else: answer tue question locally
786
1066
  this.state('question_answering');
787
- if (typeof this.methods[method] !== 'function') {
788
- return resolve(this._methodNotFound(packet));
1067
+ // check if method exists and is of type function
1068
+ if (this.methods[method] && typeof this.methods[method] !== 'function') {
1069
+ return resolve(this._methodNotFound(packet)); // resolve method not found if check if check fails
789
1070
  }
790
- this.methods[method](packet).then(result => {
1071
+ // Call the local method to process the question based the extracted parameters
1072
+ return this.methods[method](packet).then(result => {
1073
+ // check the result for the text, html, and data object.
1074
+ // this is for when answers are returned from nested Devas.
791
1075
  const text = typeof result === 'object' ? result.text : result;
792
1076
  const html = typeof result === 'object' ? result.html : result;
1077
+ // if the data passed is NOT an object it will FALSE
793
1078
  const data = typeof result === 'object' ? result.data : false;
794
- packet.a = {
795
- agent: this._agent || false,
796
- client: this._client || false,
797
- meta: {
798
- key: this._agent.key,
799
- method,
1079
+ packet.a = { // setup the packet.a container
1080
+ agent: this._agent || false, // set the agent who answered the question
1081
+ client: this._client || false, // set the client asking the question
1082
+ meta: { // setup the answer meta container
1083
+ key: this._agent.key, // set the agent key inot the meta
1084
+ method, // set the method into the meta
1085
+ params, // set the params into the meta
800
1086
  },
801
- text,
1087
+ text, // set answer text
802
1088
  html,
803
1089
  data,
804
1090
  created: Date.now(),
@@ -806,21 +1092,19 @@ class Deva {
806
1092
  // create a hash for the answer and insert into answer meta.
807
1093
  this.state(_hash);
808
1094
  packet.a.meta.hash = this.hash(JSON.stringify(packet.a));
809
-
810
1095
  // create a hash for entire packet and insert into packet
811
1096
  this.state('hash_packet');
1097
+ // hash the entire packet.
812
1098
  packet.hash = this.hash(JSON.stringify(packet));
813
-
814
- this.state('question_answer', packet);
815
-
816
- return resolve(packet);
817
- }).catch(err => {
818
- return this.error(err, packet);
1099
+ this.state('question_answer', packet); // set the question answer state
1100
+ return resolve(packet); // resolve the packet to the caller.
1101
+ }).catch(err => { // catch any errors in the method
1102
+ return this.error(err, packet, reject); // return this.error with err, packet, reject
819
1103
  });
820
1104
  }
821
1105
  }
822
- catch(e) {
823
- return this.error(e);
1106
+ catch(e) { // try block error trap
1107
+ return this.error(e); // if a overall error happens this witll call this.error
824
1108
  }
825
1109
  });
826
1110
  }
@@ -838,6 +1122,7 @@ class Deva {
838
1122
  5. run the onInit custom function if preset or the system start function.
839
1123
  6. The system start function will create a chain reaction of states that load.
840
1124
  7. If there is an error the init function rejects the call.
1125
+ usage: this.init(client_object)
841
1126
  ***************/
842
1127
  init(client) {
843
1128
  // set client
@@ -860,34 +1145,50 @@ class Deva {
860
1145
  this.Systems = client;
861
1146
  this.Solutions = client;
862
1147
  this.Development = client;
1148
+ this.Assistant = client;
1149
+ this.Business = client;
1150
+ this.Legal = client;
863
1151
 
864
1152
  return this.onInit && typeof this.onInit === 'function' ? this.onInit() : this.start();
865
1153
  }).then(started => {
866
1154
  return resolve(started)
867
1155
  }).catch(err => {
868
- return reject(err);
1156
+ return this.error(err, client, reject);
869
1157
  });
870
1158
  });
871
1159
  }
872
1160
 
873
- // Interface for unified error reporting within all devas.
874
- // this.error(*error*, *packet*) can be issued at time of any error.
875
- // e: is the error to pass into the interface.
876
- // packet: the packet that caused the error.
877
- error(err,packet=false,reject=false) {
878
- this.state('error', err);
879
- if (this.onError && typeof this.onError === 'function') return this.onError(err, packet, reject);
880
- console.error(err)
881
- return reject ? reject(err) : err;
1161
+ /**************
1162
+ func: error
1163
+ params:
1164
+ - err: The error to process
1165
+ - data: Any additional data associated with the error
1166
+ - reject: An associated promise reject if the caller requires.
1167
+ describe:
1168
+ The erro function rpovides the consistent error manage of the system.
1169
+ usage: this.error(err, data, reject);
1170
+ ***************/
1171
+ error(err,data=false,reject=false) {
1172
+ this.state('error', {err, data}); // set the state to error
1173
+ // check fo rthe custom onError function in the agent.
1174
+ if (this.onError && typeof this.onError === 'function') return this.onError(err, data, reject);
1175
+ else {
1176
+ console.log(':::::: ERROR :::::::');
1177
+ console.log(err);
1178
+ console.log('\n::::::::::::::::::::\n');
1179
+ return reject ? reject(err) : err;
1180
+ }
882
1181
  }
883
1182
 
884
1183
  /**************
885
1184
  func: start
886
- params: none
1185
+ params:
1186
+ - msg: the message for use when using custome flow logic to pass to onEnter
887
1187
  describe:
888
1188
  The start function begins the process by setting the state to start setting
889
1189
  the active to the current datetime and then checking for a custom onStart
890
1190
  function or running the system enter function.
1191
+ usage: this.start('msg')
891
1192
  ***************/
892
1193
  start(msg=false) {
893
1194
  if (!this._active) return Promise.resolve(this._messages.offline);
@@ -897,13 +1198,16 @@ class Deva {
897
1198
 
898
1199
  /**************
899
1200
  func: stop
900
- params: msg - hte message from the caller incase need to use in calls
1201
+ params:
1202
+ - msg: hte message from the caller incase need to use in calls
901
1203
  describe:
902
1204
  The stop function will stop the Deva by setting the active status to false,
903
1205
  and the state to stop. From here it will check for a custom onStop function
904
1206
  for anything to run, or run the system exit function.
905
1207
 
906
1208
  If the deva is offline it will return the offline message.
1209
+ usage:
1210
+ this.stop('msg')
907
1211
  ***************/
908
1212
  stop(msg=false) {
909
1213
  if (!this._active) return Promise.resolve(this._messages.offline);
@@ -914,12 +1218,14 @@ class Deva {
914
1218
 
915
1219
  /**************
916
1220
  func: enter
917
- params: msg - hte message from the caller incase need to use in calls
1221
+ params:
1222
+ - msg: hte message from the caller incase need to use in calls
918
1223
  describe:
919
1224
  The ener function will check the actie status of the Deva and set it to
920
1225
  offline or enter.
921
1226
 
922
1227
  If the Deva is offline it will return the offline message.
1228
+ usage: this.enter('msg')
923
1229
  ***************/
924
1230
  enter(msg=false) {
925
1231
  if (!this._active) return Promise.resolve(this._messages.offline);
@@ -929,7 +1235,8 @@ class Deva {
929
1235
 
930
1236
  /**************
931
1237
  func: exit
932
- params: msg - hte message from the caller incase need to use in calls
1238
+ params:
1239
+ - msg: hte message from the caller incase need to use in calls
933
1240
  describe:
934
1241
  The exit state function is triggered when the Deva is exiting it's online
935
1242
  status and setting the state to exit for things like security check.
@@ -938,6 +1245,7 @@ class Deva {
938
1245
  function.
939
1246
 
940
1247
  If the deva is offline it will return the offline message.
1248
+ usage: this.exit('msg')
941
1249
  ***************/
942
1250
  exit(msg=false) {
943
1251
  if (!this._active) return Promise.resolve(this._messages.offline);
@@ -949,12 +1257,13 @@ class Deva {
949
1257
  /**************
950
1258
  func: done
951
1259
  params:
952
- - msg: The done message
1260
+ - msg: hte message from the caller incase need to use in calls
953
1261
  describe:
954
1262
  When the done function is triggered the system will also set the state
955
1263
  of hte Deva to done.
956
1264
 
957
1265
  If the deva is offline it will return the offline message.
1266
+ usage: this.done('msg')
958
1267
  ***************/
959
1268
  done(msg=false) {
960
1269
  if (!this._active) return Promise.resolve(this._messages.offline);
@@ -966,20 +1275,23 @@ class Deva {
966
1275
  /**************
967
1276
  func: status
968
1277
  params:
969
- - addto: The addto is any additonal string to append to the end of hte call.
1278
+ - msg: The msg is any additonal string to append to the end of hte call.
970
1279
  describe:
971
1280
  The status function provides an easy way to get the current status of a Deva
972
1281
  and append custom status messages that may pertain to any custom status call.
973
1282
 
974
1283
  If the deva is offline it will return the offline message.
1284
+ usage: this.status('msg')
975
1285
  ***************/
976
- status(ammend=false) {
1286
+ status(msg=false) {
1287
+ // check the active status
977
1288
  if (!this._active) return Promise.resolve(this._messages.offline);
978
- const id = this.uid();
979
- const dateFormat = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'medium' }).format(this._active);
980
- let text = `${this._agent.profile.name} active since ${dateFormat}`;
981
- if (ammend) text = text + `\n${ammend}`;
982
- return Promise.resolve({text});
1289
+ // format the date since active for output.
1290
+ const dateFormat = this.formatDate(this._active, 'long', true);
1291
+ // create the text msg string
1292
+ let text = `${this.features.systems.label}:STATUS ${this._agent.profile.name} active since ${dateFormat}`;
1293
+ if (msg) text = text + `\n${msg}`; // append the msg string if msg true.
1294
+ return text; // return final text string
983
1295
  }
984
1296
 
985
1297
  /**************
@@ -988,22 +1300,26 @@ class Deva {
988
1300
  - text: The text string to send to the prompt.
989
1301
  describe:-
990
1302
  The prompt function is used to broadcasat a global prompt event with a string. Thsi is handy when passing events between a cli and user interface for example.
1303
+
1304
+ usage: this.prompt('text')
991
1305
  ***************/
992
1306
  prompt(text) {
993
- return this.talk('prompt', {text, agent:this._agent});
1307
+ // Talk a global prompt event for the client
1308
+ return this.talk(`prompt`, {text, agent:this._agent});
994
1309
  }
995
1310
 
996
1311
  /**************
997
1312
  func: client
998
1313
  params: none
999
1314
  describe:
1000
- this function allows statement management for when client prfioe is
1315
+ this function allows state management for when client prfioe is
1001
1316
  being accessed.
1317
+ usage: this.client();
1002
1318
  ***************/
1003
1319
  client() {
1004
- if (!this._active) return this._messages.offline;
1005
- this.state('client');
1006
- return this._client;
1320
+ if (!this._active) return this._messages.offline; // check the active status
1321
+ this.state('client'); // set the client state
1322
+ return this._client; // return the client feature
1007
1323
  }
1008
1324
 
1009
1325
  /**************
@@ -1012,6 +1328,7 @@ class Deva {
1012
1328
  describe:
1013
1329
  this function allows statement management for when client prfioe is
1014
1330
  being accessed.
1331
+ usage: this.agent()
1015
1332
  ***************/
1016
1333
  agent() {
1017
1334
  if (!this._active) return this._messages.offline;
@@ -1021,57 +1338,62 @@ class Deva {
1021
1338
 
1022
1339
  /**************
1023
1340
  func: security
1024
- params: opts
1341
+ params: none
1025
1342
  describe: basic security features available in a Deva.
1343
+ usage: this.security()
1026
1344
  ***************/
1027
- security(opts) {
1028
- if (!this._active) return this._messages.offline;
1029
- this.state('security');
1030
- return this._security;
1345
+ security() {
1346
+ if (!this._active) return this._messages.offline; // check the active status
1347
+ this.state('security'); // set the security state
1348
+ return this._security; // return the security feature
1031
1349
  }
1032
1350
 
1033
1351
  /**************
1034
- func: security
1035
- params: opts
1352
+ func: support
1353
+ params: none
1036
1354
  describe: basic support features available in a Deva.
1355
+ usage: this.support()
1037
1356
  ***************/
1038
- support(opts) {
1039
- if (!this._active) return this._messages.offline;
1040
- this.state('support');
1041
- return this._support;
1357
+ support() {
1358
+ if (!this._active) return this._messages.offline; // check the active status
1359
+ this.state('support'); // set the support state
1360
+ return this._support; // return the support feature
1042
1361
  }
1043
1362
 
1044
1363
  /**************
1045
- func: security
1046
- params: opts
1364
+ func: services
1365
+ params: none
1047
1366
  describe: basic services features available in a Deva.
1367
+ usage: this.services()
1048
1368
  ***************/
1049
1369
  services(opts) {
1050
- if (!this._active) return this._messages.offline;
1051
- this.state('services');
1052
- return this._services;
1370
+ if (!this._active) return this._messages.offline; // check the active status
1371
+ this.state('services'); // set the services state
1372
+ return this._services; // return the services feature
1053
1373
  }
1054
1374
 
1055
1375
  /**************
1056
1376
  func: systems
1057
1377
  params: opts
1058
1378
  describe: basic systems features available in a Deva.
1379
+ usage: this.systems()
1059
1380
  ***************/
1060
1381
  systems(opts) {
1061
- if (!this._active) return this._messages.offline;
1062
- this.state('systems');
1063
- return this._systems;
1382
+ if (!this._active) return this._messages.offline; // check the active status
1383
+ this.state('systems'); // set the systems state
1384
+ return this._systems; // return the systems feature
1064
1385
  }
1065
1386
 
1066
1387
  /**************
1067
- func: security
1388
+ func: solutions
1068
1389
  params: opts
1069
1390
  describe: basic solutions features available in a Deva.
1391
+ usage: this.solutions()
1070
1392
  ***************/
1071
1393
  solutions(opts) {
1072
- if (!this._active) return this._messages.offline;
1073
- this.state('solutions');
1074
- return this._solutions;
1394
+ if (!this._active) return this._messages.offline; // check the active status
1395
+ this.state('solutions'); // set the solutions state
1396
+ return this._solutions; // return the solutions feature
1075
1397
  }
1076
1398
 
1077
1399
  /**************
@@ -1080,9 +1402,42 @@ class Deva {
1080
1402
  describe: basic development features available in a Deva.
1081
1403
  ***************/
1082
1404
  development(opts) {
1083
- if (!this._active) return this._messages.offline;
1084
- this.state('development');
1085
- return this._development;
1405
+ if (!this._active) return this._messages.offline; // chek the active status
1406
+ this.state('development'); // set the development state
1407
+ return this._development; // return development feature
1408
+ }
1409
+
1410
+ /**************
1411
+ func: assistant
1412
+ params: opts
1413
+ describe: basic assistant features available in a Deva.
1414
+ ***************/
1415
+ assistant(opts) {
1416
+ if (!this._active) return this._messages.offline; // chek the active status
1417
+ this.state('assistant'); // set the assistant state
1418
+ return this._assistant; // return assistant feature
1419
+ }
1420
+
1421
+ /**************
1422
+ func: business
1423
+ params: opts
1424
+ describe: basic business features available in a Deva.
1425
+ ***************/
1426
+ business(opts) {
1427
+ if (!this._active) return this._messages.offline; // chek the active status
1428
+ this.state('business'); // set the business state
1429
+ return this._business; // return business feature
1430
+ }
1431
+
1432
+ /**************
1433
+ func: legal
1434
+ params: opts
1435
+ describe: basic legal features available in a Deva.
1436
+ ***************/
1437
+ legal(opts) {
1438
+ if (!this._active) return this._messages.offline; // chek the active status
1439
+ this.state('legal'); // set the legal state
1440
+ return this._legal; // return legal feature
1086
1441
  }
1087
1442
 
1088
1443
  /**************
@@ -1092,16 +1447,22 @@ class Deva {
1092
1447
  Start Devas will initialize the Deva agents inside this curent Deva.
1093
1448
  ***************/
1094
1449
  startDevas(client) {
1095
- this.state('devas_start');
1450
+ const _client = this.copy(client); // copy the client data
1451
+ this.state('devas_start'); // set the devas start state
1096
1452
  return new Promise((resolve, reject) => {
1097
- const devas = [];
1453
+ const devas = []; // create devas index
1098
1454
  for (let x in this.devas) {
1099
- devas.push(this.devas[x].init(client));
1455
+ devas.push(this.devas[x].init(_client)); // push the to devas index
1100
1456
  }
1101
1457
  Promise.all(devas).then(() => {
1102
- this.state('devas_ready');
1103
- return resolve({text:this._messages.devas_started,prompt:this._agent.prompt});
1104
- }).catch(reject);
1458
+ this.state('devas_ready'); // set to ready state
1459
+ return resolve({ // return the response
1460
+ text:this._messages.devas_started, // include started state message
1461
+ prompt:this._agent.prompt, // include agent prompt settings
1462
+ });
1463
+ }).catch(err => { // catch any errors
1464
+ return this.error(err, client, reject); // send to error handler.
1465
+ });
1105
1466
  });
1106
1467
  }
1107
1468
  /**************
@@ -1111,16 +1472,21 @@ class Deva {
1111
1472
  stopDevas will stop all the devas running in the current Deva.
1112
1473
  ***************/
1113
1474
  stopDevas() {
1114
- this.state('devas_stop');
1475
+ this.state('devas_stop'); // set the devas stop state
1115
1476
  return new Promise((resolve, reject) => {
1116
- const devas = [];
1477
+ const devas = []; // create empty devas index
1117
1478
  for (let x in this.devas) {
1118
- devas.push(this.devas[x].stop());
1479
+ devas.push(this.devas[x].stop()); // push the deva to devas index
1119
1480
  }
1120
1481
  Promise.all(devas).then(() => {
1121
- this.state('devas_stoped');
1122
- return resolve(this._messages.devas_stopped);
1123
- }).catch(reject);
1482
+ this.state('devas_stoped'); // set the deva stopped state
1483
+ return resolve({
1484
+ text: this._messages.devas_stopped, // include stopped state message
1485
+ prompt: this._agent.prompt, // include agent prompt settings
1486
+ });
1487
+ }).catch(err => { // catch any errors
1488
+ return this.error(err, false, reject); // send to error handler
1489
+ });
1124
1490
  });
1125
1491
  }
1126
1492
 
@@ -1137,15 +1503,18 @@ class Deva {
1137
1503
  FDate format ensures that consistent date formatting is used within the
1138
1504
  system based on the language and locale in the client profile.
1139
1505
  ***************/
1140
- formatDate(d, format='long', time=false) {
1506
+ formatDate(d, format='milli', time=false) {
1141
1507
  if (!d) d = Date.now();
1142
1508
  d = new Date(d);
1143
1509
 
1510
+ if (format === 'milli') return d.getTime();
1511
+ // pre-set date formats for returning user dates.
1144
1512
  const formats = {
1145
1513
  long: { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' },
1146
1514
  long_month: { year: 'numeric', month: 'long', day: 'numeric'},
1147
1515
  short: { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric' },
1148
1516
  short_month: { year: 'numeric', month: 'short', day: 'numeric' },
1517
+ numeric: { year: 'numeric', month: 'numeric', day: 'numeric' },
1149
1518
  year: { year: 'numeric' },
1150
1519
  month: { month: 'long' },
1151
1520
  day: { day: 'long' },
@@ -1165,7 +1534,7 @@ class Deva {
1165
1534
  parameter based on the locale setting in the client profile..
1166
1535
  ***************/
1167
1536
  formatTime(t) {
1168
- return t.toLocaleTimeString(this._client.locale);
1537
+ return t.toLocaleTimeString(this._client.locale); // return the formatted time string
1169
1538
  }
1170
1539
 
1171
1540
  /**************