@indra.ai/deva 1.1.29 → 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,98 +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) {
120
+ const {_agent, _client} = this;
46
121
  const _states = {
47
- uid: `👻 ${this._agent.profile.name} is making a new #uid`,
48
- offline: `👻 ${this._agent.profile.name} is offline`,
49
- online: `📡 ${this._agent.profile.name} is online`,
50
- config: `‍📀 ${this._agent.profile.name} is checking the config`,
51
- client: `👨‍💻 ${this._agent.profile.name} opened the ${this._client.key} profile`,
52
- agent: `👨‍💻 ${this._agent.profile.name} is looking at ${this._agent.key} profile`,
53
- init: `🚀 ${this._agent.profile.name} is initializing for ${this._client.profile.name}`,
54
- start: `🎬 ${this._agent.profile.name} has started the process for ${this._client.profile.name}`,
55
- enter: `🎪 ${this._agent.profile.name} is entering the deva.world with${this._client.profile.name}`,
56
- stop: `🛑 ${this._agent.profile.name} has stopped for ${this._client.profile.name}`,
57
- exit: `🚪 ${this._agent.profile.name} found the exit with ${this._client.profile.name}`,
58
- done: `🤝 ${this._agent.profile.name} is all done time for #offerings 🍫🍌`,
59
- wait: `😵‍💫 ${this._agent.profile.name} waiting for #stuff from ${this._client.profile.name}`,
60
- data: `📀 ${this._agent.profile.name} is receiving #data for ${this._client.profile.name}`,
61
- ask: `🙋‍♀️ ${this._agent.profile.name} is asking a #question from ${this._client.profile.name}`,
62
- cmd: `📟 ${this._agent.profile.name} entered a #command from ${this._client.profile.name}`,
63
- question: `🐵 ${this._agent.profile.name} is in #question mode ${this._client.profile.name}`,
64
- ask: `🐵 ${this._agent.profile.name} is in #ask mode ${this._client.profile.name}`,
65
- talk: `🎙️ ${this._agent.profile.name} is in #talk mode with ${this._client.profile.name}`,
66
- listen: `🎧 ${this._agent.profile.name} is in #listening mode with ${this._client.profile.name}`,
67
- error: `❌ ${this._agent.profile.name} had an error. Let's have @Systems look into that.`,
68
- uid: `🪪 ${this._client.profile.name} made a #uid with ${this._agent.profile.name}`,
69
- hash: `🔑 ${this._client.profile.name} made a #hash with ${this._agent.profile.name}`,
70
- cipher: `🔐 ${this._client.profile.name} locked a #cipher with ${this._agent.profile.name}`,
71
- decipher: `🔓 ${this._client.profile.name} unlocked a #cipher with ${this._agent.profile.name}`,
72
- story: `📓 ${this._agent.profile.name} is creating an amazing #story ${this._client.profile.name}`,
73
- development: `👨‍💻 ${this._agent.profile.name} called for @Development assistance for ${this._client.profile.name}`,
74
- security: `🚨 ${this._agent.profile.name} called for @Security assistance for ${this._client.profile.name}`,
75
- support: `🎗️ ${this._agent.profile.name} called for @Support assistance for ${this._client.profile.name}`,
76
- services: `🎖️ ${this._agent.profile.name} called for @Services assistance for ${this._client.profile.name}`,
77
- systems: `👽 ${this._agent.profile.name} called for @Systems assistance for ${this._client.profile.name}`,
78
- solutions: `🔬 ${this._agent.profile.name} called for @Solutions assistance for ${this._client.profile.name}`,
79
- devas_start: `✨ Starting all the #Devas with ${this._client.profile.name}`,
80
- devas_ready: `📸 The #Devas are #ready and #waiitng for ${this._client.profile.name}`,
81
- devas_stop: `🙈 The #Devas are #stopping with ${this._client.profile.name}`,
82
- devas_stopped: `🛑 #Devas and ${this._client.profile.name} have #stopped, and that means time for #offerings 🍎🍑🍍🧋`,
83
- deva_load: `✅ ${this._agent.profile.name} loading for ${this._client.profile.name}`,
84
- deva_loaded: `✅ ${this._agent.profile.name} loaded for ${this._client.profile.name}`,
85
- deva_unloaded: `✅ ${this._agent.profile.name} unloaded for ${this._client.profile.name}`,
86
- question_me: `🐵 ${this._client.profile.name} started with a great #question to ${this._agent.profile.name}`,
87
- question_default: `🧞‍♂️ ${this._client.profile.name} asked a great #question to ${this._agent.profile.name}`,
88
- question_ask: `🧞 ${this._agent.profile.name} is pondering what ${this._client.profile.name} asked`,
89
- question_asking: `🧞 ${this._agent.profile.name} is asking another #Deva for ${this._client.profile.name}`,
90
- question_aswering: `🧞 ${this._agent.profile.name} is answering the #question ${this._client.profile.name} asked`,
91
- question_answer: `🔮 ${this._client.profile.name} received an #ansewr from ${this._agent.profile.name}`,
92
- question_command: `🧞‍♀️ ${this._client.profile.name} issued a #command to ${this._agent.profile.name}`,
93
- hash_question: `🔑 ${this._agent.profile.name} created the #question #hash for ${this._client.profile.name}`,
94
- hash_ask: `🔑 ${this._agent.profile.name} created the #ask #hash for ${this._client.profile.name}`,
95
- hash_answer: `🔑 ${this._client.profile.name} #answer #hash with`,
96
- hash_command: `🔑 ${this._client.profile.name} #command #hash with ${this._agent.profile.name}`,
97
- hash_packet: `🔑 ${this._agent.profile.name} created the #packet #hash for ${this._client.profile.name}`,
98
- ask_question: `👽 ${this._client.profile.name} asked ${this._agent.profile.name} a great #question`,
99
- ask_answer: `🛸 ${this._client.profile.name} received a great #answer from ${this._agent.profile.name}`,
100
- method_not_found: `😩 ${this._client.profile.name} used a faulty #command while working with ${this._agent.profile.name}, and may need @Support`,
101
- ready_security: `🚓 @Security is ready`,
102
- ready_support: `🚑 @Support is ready`,
103
- ready_support: `🚑 @Support is ready`,
104
- ready_services: `🚚 @Services is ready`,
105
- ready_systems: `🏘️ @Systems is ready`,
106
- ready_solutions: `🤓 @Solutions is ready`,
107
- alert_security: `🚨 #SECURITY ALERT`,
108
- alert_support: `🚨 #SUPPORT ALERT`,
109
- alert_services: `🚨 #SERVICES ALERT`,
110
- alert_solutions: `🚨 #SOLUTIONS ALERT`,
111
- alert_systems: `🚨 #SYSTEMS ALERT`,
112
- alert_development: `🚨 #SYSTEMS ALERT`,
113
- setting_client: `⛄️ ${this._agent.profile.name} is setting the #client for ${this._client.profile.name} `,
114
- setting_development: `🔬 ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Development`,
115
- setting_security: `👮‍♂️ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Security`,
116
- setting_support: `👨‍⚕️ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Support`,
117
- setting_services: `👷‍♂️ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Services`,
118
- setting_systems: `🏘️ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Systems`,
119
- 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}`,
120
208
  }
121
- 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.
122
216
  }
123
217
 
124
- set Messages(opts) {
125
- 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 = {
126
228
  offline: `🙅‍♂️ ${this._agent.profile.name} offline`,
127
229
  init: `⚠️ ${this._agent.profile.name} init`,
128
230
  start: `✅ ${this._agent.profile.name} start`,
@@ -132,133 +234,313 @@ class Deva {
132
234
  done: `👍 ${this._agent.profile.name} done.`,
133
235
  devas_started: '#Devas are #online and ready for #offerings 🍫🥛🍚🍯🧂',
134
236
  devas_stopped: '🛑 #Devas have stopped',
135
- notext: `❌ ${this._client.profile.name}, please provide with valid input.`,
237
+ notext: `❌ ${this._client.profile.name}, Invalid input.`,
136
238
  method_not_found: `❌ ${this._client.profile.name} you sure messed that up!`,
137
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;
138
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
+ ***************/
139
258
  set Client(client) {
140
- // copy the cl parameter into a local _client variable
141
- const _client = this.copy(client);
142
-
143
- // delete the keys used for other features.
144
- if (_client.states) delete _client.states;
145
- if (_client.messages) delete _client.messages;
146
- if (_client.development) delete _client.development;
147
- if (_client.security) delete _client.security;
148
- if (_client.support) delete _client.support;
149
- if (_client.services) delete _client.services;
150
- if (_client.systems) delete _client.systems;
151
- if (_client.solutions) delete _client.solutions;
152
-
153
- // set the local client variable from the clean _client local variable.
154
- this._client = _client;
155
-
156
- // set the states and messages after the cleint is set.
157
- this.States = client.states;
158
- 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
159
266
  }
160
267
 
161
- // 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
+ ***************/
162
275
  set Security(client=false) {
163
- if (!client) this._security = {};
164
- else {
165
- this.state('setting_security');
166
- const _client = this.copy(client);
167
- this._security = {
168
- id: this.uid(true),
169
- client_id: _client.id,
170
- client_name: _client.profile.name,
171
- hash: _client.security.hash,
172
- cipher: _client.security.cipher,
173
- concerns: _client.security.concerns,
174
- global: _client.security.global,
175
- personal: _client.security.devas[this._agent.key]
176
- };
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
177
296
  }
178
297
  }
179
298
 
180
- // 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
+ ***************/
181
306
  set Support(client=false) {
182
- if (!client) this._support = {};
183
- else {
184
- this.state('setting_support');
185
- const _client = this.copy(client);
186
- this._support = {
187
- id: this.uid(true),
188
- client_id: _client.id,
189
- client_name: _client.profile.name,
190
- concerns: _client.support.concerns,
191
- global: _client.support.global,
192
- personal: _client.support.devas[this._agent.key]
193
- };
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
194
327
  }
195
328
  }
196
329
 
197
- // 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
+ ***************/
198
337
  set Services(client=false) {
199
- if (!client) this._servcies = {};
200
- else {
201
- this.state('setting_services');
202
- const _client = this.copy(client);
203
- this._services = {
204
- id: this.uid(true),
205
- client_id: _client.id,
206
- client_name: _client.profile.name,
207
- concerns: _client.services.concerns,
208
- global: _client.services.global,
209
- personal: _client.services.devas[this._agent.key]
210
- };
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
211
358
  }
212
359
  }
213
360
 
214
- // 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
+ ***************/
215
368
  set Systems(client=false) {
216
- if (!client) this._systems = {};
217
- else {
218
- this.state('setting_systems');
219
- const _client = this.copy(client);
220
- this._systems = {
221
- id: this.uid(true),
222
- client_id: _client.id,
223
- client_name: _client.profile.name,
224
- concerns: _client.systems.concerns,
225
- global: _client.systems.global,
226
- personal: _client.systems.devas[this._agent.key]
227
- };
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
228
389
  }
229
390
  }
230
391
 
231
- // 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
+ ***************/
232
399
  set Solutions(client=false) {
233
- if (!client) this._solutions = {};
234
- else {
235
- this.state('setting_solutions');
236
- const _client = this.copy(client);
237
- this._solutions = {
238
- id: this.uid(true),
239
- client_id: _client.id,
240
- client_name: _client.profile.name,
241
- concerns: _client.solutions.concerns,
242
- global: _client.solutions.global,
243
- personal: _client.solutions.devas[this._agent.key]
244
- };
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
245
420
  }
246
421
  }
247
422
 
248
- // 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
+ ***************/
249
430
  set Development(client=false) {
250
- if (!client) this._development = {};
251
- else {
252
- this.state('setting_development');
253
- const _client = this.copy(client);
254
- this._development = {
255
- id: this.uid(true),
256
- client_id: _client.id,
257
- client_name: _client.profile.name,
258
- concerns: _client.development.concerns,
259
- global: _client.development.global,
260
- personal: _client.development.devas[this._agent.key]
261
- };
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
262
544
  }
263
545
  }
264
546
 
@@ -287,7 +569,7 @@ class Deva {
287
569
  if (parse) this._agent.parse = this._agent.parse.bind(this);
288
570
  }
289
571
  catch (e) {
290
- return reject(e);
572
+ return this.error(e, false, reject);
291
573
  }
292
574
  finally {
293
575
  return resolve();
@@ -322,7 +604,7 @@ class Deva {
322
604
  }
323
605
  }
324
606
  catch (e) {
325
- return reject(e);
607
+ return this.error(e, false, reject);
326
608
  }
327
609
  finally {
328
610
  return resolve();
@@ -349,7 +631,7 @@ class Deva {
349
631
  }
350
632
  }
351
633
  catch (e) {
352
- return reject(e);
634
+ return this.error(e, false, reject);
353
635
  }
354
636
  finally {
355
637
  return resolve();
@@ -404,7 +686,7 @@ class Deva {
404
686
  ***************/
405
687
  state(st, data=false) {
406
688
  if (!Object.keys(this._states).includes(st)) return;
407
- 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)}`;
408
690
  const _data = {
409
691
  id: this.uid(true),
410
692
  client: this._client.id,
@@ -453,15 +735,19 @@ class Deva {
453
735
  describe:
454
736
  The hash algorithm will take a string of text and produce a hash.
455
737
  ***************/
456
- hash(str) {
457
- const algo = this._security.hash || 'md5';
738
+ hash(str, algo=false) {
739
+ algo = algo || this._security.hash || 'md5';
458
740
  const the_hash = createHash(algo);
459
741
  the_hash.update(str);
460
742
  const _digest = the_hash.digest('base64');
461
743
  this.state('hash', {
462
-
463
- })
464
- 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;
465
751
  }
466
752
 
467
753
  /**************
@@ -693,11 +979,11 @@ class Deva {
693
979
  describe:
694
980
  ***************/
695
981
  question(TEXT=false, DATA=false) {
982
+ // check the active status
696
983
  if (!this._active) return Promise.resolve(this._messages.offline);
697
- this.state('question_me', {text:TEXT, data:DATA});
698
-
699
- const id = this.uid(); // generate a unique transport id for the question.
700
- 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.
701
987
 
702
988
  // check to see if the string is an #ask string to talk to the other Deva.
703
989
  const isAsk = t_split[0].startsWith(this.askChr);
@@ -706,98 +992,99 @@ class Deva {
706
992
  const isCmd = t_split[0].startsWith(this.cmdChr);
707
993
 
708
994
  // Format the packet for return on the request.
709
- const orig = TEXT;
710
- const data = DATA;
711
- const packet = {
712
- id,
713
- q: {},
714
- a: {},
715
- 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
716
1002
  };
717
1003
 
718
- let text = TEXT,
719
- params = false,
720
- method = 'question',
721
- 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.
722
1008
 
723
1009
  return new Promise((resolve, reject) => {
724
- if (!TEXT) return reject(this._messages.notext);
725
- try {
726
- if (!this._active) return reject(this._messages.offline);
727
-
728
- let _state = 'question_default';
729
- let _hash = 'hash_asnwer';
730
-
731
- // *: send just a string of text
732
- // !: send a command to the local agent
733
- // #: ask another agent a question
734
- // #agent method:param1:param2 with text strings for proccessing
735
- // !method param:list:parse for the local agent
736
- // if is an ask then we format one way
737
- if (isAsk) {
738
- _state = 'question_ask'
739
- _state = 'hash_ask'
740
- 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
741
1023
  params = t_split[1] ? t_split[1].split(':') : false;
742
- method = params[0];
743
- text = t_split.slice(2).join(' ').trim();
744
-
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.
745
1026
  }
746
- else if (isCmd) {
747
- _state = 'question_command';
748
- _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
749
1031
  params = t_split[1] ? t_split[1].split(':') : false;
750
- method = t_split[0].substring(1);
751
- 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
752
1034
  }
753
1035
 
754
- packet.q = {
755
- agent: this._agent || false,
756
- client: this._client || false,
757
- meta: {
758
- key,
759
- orig,
760
- method,
761
- 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
762
1044
  },
763
- text,
764
- data,
765
- 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
766
1048
  }
767
1049
 
768
- // hash the packet and insert the hash into the packet meta object.
769
- this.state('hash_question');
1050
+ this.state('hash_question'); // set the has question state
1051
+ // hash the question
770
1052
  packet.q.meta.hash = this.hash(JSON.stringify(packet.q));
771
1053
 
772
- this.state(_state, packet);
1054
+ this.state(_state, packet); // set the state to teh _state variable
773
1055
 
774
- // If a question to another Deva with '#' then trigger events
775
- if (isAsk) {
776
- this.state('question_asking');
777
- 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
778
1060
  this.once(`${key}:ask:${packet.id}`, answer => {
779
- return resolve(answer);
1061
+ return resolve(answer); // if:isAsk resolve the answer from the call
780
1062
  });
781
1063
  }
782
1064
 
783
- // if the user sends a local command '$' then it will ask of the self.
784
- else {
1065
+ else { // else: answer tue question locally
785
1066
  this.state('question_answering');
786
- if (typeof this.methods[method] !== 'function') {
787
- 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
788
1070
  }
789
- 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.
790
1075
  const text = typeof result === 'object' ? result.text : result;
791
1076
  const html = typeof result === 'object' ? result.html : result;
1077
+ // if the data passed is NOT an object it will FALSE
792
1078
  const data = typeof result === 'object' ? result.data : false;
793
- packet.a = {
794
- agent: this._agent || false,
795
- client: this._client || false,
796
- meta: {
797
- key: this._agent.key,
798
- 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
799
1086
  },
800
- text,
1087
+ text, // set answer text
801
1088
  html,
802
1089
  data,
803
1090
  created: Date.now(),
@@ -805,21 +1092,19 @@ class Deva {
805
1092
  // create a hash for the answer and insert into answer meta.
806
1093
  this.state(_hash);
807
1094
  packet.a.meta.hash = this.hash(JSON.stringify(packet.a));
808
-
809
1095
  // create a hash for entire packet and insert into packet
810
1096
  this.state('hash_packet');
1097
+ // hash the entire packet.
811
1098
  packet.hash = this.hash(JSON.stringify(packet));
812
-
813
- this.state('question_answer', packet);
814
-
815
- return resolve(packet);
816
- }).catch(err => {
817
- 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
818
1103
  });
819
1104
  }
820
1105
  }
821
- catch(e) {
822
- 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
823
1108
  }
824
1109
  });
825
1110
  }
@@ -837,6 +1122,7 @@ class Deva {
837
1122
  5. run the onInit custom function if preset or the system start function.
838
1123
  6. The system start function will create a chain reaction of states that load.
839
1124
  7. If there is an error the init function rejects the call.
1125
+ usage: this.init(client_object)
840
1126
  ***************/
841
1127
  init(client) {
842
1128
  // set client
@@ -859,34 +1145,50 @@ class Deva {
859
1145
  this.Systems = client;
860
1146
  this.Solutions = client;
861
1147
  this.Development = client;
1148
+ this.Assistant = client;
1149
+ this.Business = client;
1150
+ this.Legal = client;
862
1151
 
863
1152
  return this.onInit && typeof this.onInit === 'function' ? this.onInit() : this.start();
864
1153
  }).then(started => {
865
1154
  return resolve(started)
866
1155
  }).catch(err => {
867
- return reject(err);
1156
+ return this.error(err, client, reject);
868
1157
  });
869
1158
  });
870
1159
  }
871
1160
 
872
- // Interface for unified error reporting within all devas.
873
- // this.error(*error*, *packet*) can be issued at time of any error.
874
- // e: is the error to pass into the interface.
875
- // packet: the packet that caused the error.
876
- error(err,packet=false,reject=false) {
877
- this.state('error', err);
878
- if (this.onError && typeof this.onError === 'function') return this.onError(err, packet, reject);
879
- console.error(err)
880
- 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
+ }
881
1181
  }
882
1182
 
883
1183
  /**************
884
1184
  func: start
885
- params: none
1185
+ params:
1186
+ - msg: the message for use when using custome flow logic to pass to onEnter
886
1187
  describe:
887
1188
  The start function begins the process by setting the state to start setting
888
1189
  the active to the current datetime and then checking for a custom onStart
889
1190
  function or running the system enter function.
1191
+ usage: this.start('msg')
890
1192
  ***************/
891
1193
  start(msg=false) {
892
1194
  if (!this._active) return Promise.resolve(this._messages.offline);
@@ -896,13 +1198,16 @@ class Deva {
896
1198
 
897
1199
  /**************
898
1200
  func: stop
899
- 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
900
1203
  describe:
901
1204
  The stop function will stop the Deva by setting the active status to false,
902
1205
  and the state to stop. From here it will check for a custom onStop function
903
1206
  for anything to run, or run the system exit function.
904
1207
 
905
1208
  If the deva is offline it will return the offline message.
1209
+ usage:
1210
+ this.stop('msg')
906
1211
  ***************/
907
1212
  stop(msg=false) {
908
1213
  if (!this._active) return Promise.resolve(this._messages.offline);
@@ -913,12 +1218,14 @@ class Deva {
913
1218
 
914
1219
  /**************
915
1220
  func: enter
916
- 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
917
1223
  describe:
918
1224
  The ener function will check the actie status of the Deva and set it to
919
1225
  offline or enter.
920
1226
 
921
1227
  If the Deva is offline it will return the offline message.
1228
+ usage: this.enter('msg')
922
1229
  ***************/
923
1230
  enter(msg=false) {
924
1231
  if (!this._active) return Promise.resolve(this._messages.offline);
@@ -928,7 +1235,8 @@ class Deva {
928
1235
 
929
1236
  /**************
930
1237
  func: exit
931
- 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
932
1240
  describe:
933
1241
  The exit state function is triggered when the Deva is exiting it's online
934
1242
  status and setting the state to exit for things like security check.
@@ -937,6 +1245,7 @@ class Deva {
937
1245
  function.
938
1246
 
939
1247
  If the deva is offline it will return the offline message.
1248
+ usage: this.exit('msg')
940
1249
  ***************/
941
1250
  exit(msg=false) {
942
1251
  if (!this._active) return Promise.resolve(this._messages.offline);
@@ -948,12 +1257,13 @@ class Deva {
948
1257
  /**************
949
1258
  func: done
950
1259
  params:
951
- - msg: The done message
1260
+ - msg: hte message from the caller incase need to use in calls
952
1261
  describe:
953
1262
  When the done function is triggered the system will also set the state
954
1263
  of hte Deva to done.
955
1264
 
956
1265
  If the deva is offline it will return the offline message.
1266
+ usage: this.done('msg')
957
1267
  ***************/
958
1268
  done(msg=false) {
959
1269
  if (!this._active) return Promise.resolve(this._messages.offline);
@@ -965,20 +1275,23 @@ class Deva {
965
1275
  /**************
966
1276
  func: status
967
1277
  params:
968
- - 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.
969
1279
  describe:
970
1280
  The status function provides an easy way to get the current status of a Deva
971
1281
  and append custom status messages that may pertain to any custom status call.
972
1282
 
973
1283
  If the deva is offline it will return the offline message.
1284
+ usage: this.status('msg')
974
1285
  ***************/
975
- status(ammend=false) {
1286
+ status(msg=false) {
1287
+ // check the active status
976
1288
  if (!this._active) return Promise.resolve(this._messages.offline);
977
- const id = this.uid();
978
- const dateFormat = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'medium' }).format(this._active);
979
- let text = `${this._agent.profile.name} active since ${dateFormat}`;
980
- if (ammend) text = text + `\n${ammend}`;
981
- 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
982
1295
  }
983
1296
 
984
1297
  /**************
@@ -987,22 +1300,26 @@ class Deva {
987
1300
  - text: The text string to send to the prompt.
988
1301
  describe:-
989
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')
990
1305
  ***************/
991
1306
  prompt(text) {
992
- 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});
993
1309
  }
994
1310
 
995
1311
  /**************
996
1312
  func: client
997
1313
  params: none
998
1314
  describe:
999
- this function allows statement management for when client prfioe is
1315
+ this function allows state management for when client prfioe is
1000
1316
  being accessed.
1317
+ usage: this.client();
1001
1318
  ***************/
1002
1319
  client() {
1003
- if (!this._active) return this._messages.offline;
1004
- this.state('client');
1005
- 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
1006
1323
  }
1007
1324
 
1008
1325
  /**************
@@ -1011,6 +1328,7 @@ class Deva {
1011
1328
  describe:
1012
1329
  this function allows statement management for when client prfioe is
1013
1330
  being accessed.
1331
+ usage: this.agent()
1014
1332
  ***************/
1015
1333
  agent() {
1016
1334
  if (!this._active) return this._messages.offline;
@@ -1020,57 +1338,62 @@ class Deva {
1020
1338
 
1021
1339
  /**************
1022
1340
  func: security
1023
- params: opts
1341
+ params: none
1024
1342
  describe: basic security features available in a Deva.
1343
+ usage: this.security()
1025
1344
  ***************/
1026
- security(opts) {
1027
- if (!this._active) return this._messages.offline;
1028
- this.state('security');
1029
- 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
1030
1349
  }
1031
1350
 
1032
1351
  /**************
1033
- func: security
1034
- params: opts
1352
+ func: support
1353
+ params: none
1035
1354
  describe: basic support features available in a Deva.
1355
+ usage: this.support()
1036
1356
  ***************/
1037
- support(opts) {
1038
- if (!this._active) return this._messages.offline;
1039
- this.state('support');
1040
- 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
1041
1361
  }
1042
1362
 
1043
1363
  /**************
1044
- func: security
1045
- params: opts
1364
+ func: services
1365
+ params: none
1046
1366
  describe: basic services features available in a Deva.
1367
+ usage: this.services()
1047
1368
  ***************/
1048
1369
  services(opts) {
1049
- if (!this._active) return this._messages.offline;
1050
- this.state('services');
1051
- 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
1052
1373
  }
1053
1374
 
1054
1375
  /**************
1055
1376
  func: systems
1056
1377
  params: opts
1057
1378
  describe: basic systems features available in a Deva.
1379
+ usage: this.systems()
1058
1380
  ***************/
1059
1381
  systems(opts) {
1060
- if (!this._active) return this._messages.offline;
1061
- this.state('systems');
1062
- 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
1063
1385
  }
1064
1386
 
1065
1387
  /**************
1066
- func: security
1388
+ func: solutions
1067
1389
  params: opts
1068
1390
  describe: basic solutions features available in a Deva.
1391
+ usage: this.solutions()
1069
1392
  ***************/
1070
1393
  solutions(opts) {
1071
- if (!this._active) return this._messages.offline;
1072
- this.state('solutions');
1073
- 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
1074
1397
  }
1075
1398
 
1076
1399
  /**************
@@ -1079,9 +1402,42 @@ class Deva {
1079
1402
  describe: basic development features available in a Deva.
1080
1403
  ***************/
1081
1404
  development(opts) {
1082
- if (!this._active) return this._messages.offline;
1083
- this.state('development');
1084
- 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
1085
1441
  }
1086
1442
 
1087
1443
  /**************
@@ -1091,16 +1447,22 @@ class Deva {
1091
1447
  Start Devas will initialize the Deva agents inside this curent Deva.
1092
1448
  ***************/
1093
1449
  startDevas(client) {
1094
- this.state('devas_start');
1450
+ const _client = this.copy(client); // copy the client data
1451
+ this.state('devas_start'); // set the devas start state
1095
1452
  return new Promise((resolve, reject) => {
1096
- const devas = [];
1453
+ const devas = []; // create devas index
1097
1454
  for (let x in this.devas) {
1098
- devas.push(this.devas[x].init(client));
1455
+ devas.push(this.devas[x].init(_client)); // push the to devas index
1099
1456
  }
1100
1457
  Promise.all(devas).then(() => {
1101
- this.state('devas_ready');
1102
- return resolve({text:this._messages.devas_started,prompt:this._agent.prompt});
1103
- }).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
+ });
1104
1466
  });
1105
1467
  }
1106
1468
  /**************
@@ -1110,16 +1472,21 @@ class Deva {
1110
1472
  stopDevas will stop all the devas running in the current Deva.
1111
1473
  ***************/
1112
1474
  stopDevas() {
1113
- this.state('devas_stop');
1475
+ this.state('devas_stop'); // set the devas stop state
1114
1476
  return new Promise((resolve, reject) => {
1115
- const devas = [];
1477
+ const devas = []; // create empty devas index
1116
1478
  for (let x in this.devas) {
1117
- devas.push(this.devas[x].stop());
1479
+ devas.push(this.devas[x].stop()); // push the deva to devas index
1118
1480
  }
1119
1481
  Promise.all(devas).then(() => {
1120
- this.state('devas_stoped');
1121
- return resolve(this._messages.devas_stopped);
1122
- }).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
+ });
1123
1490
  });
1124
1491
  }
1125
1492
 
@@ -1136,15 +1503,18 @@ class Deva {
1136
1503
  FDate format ensures that consistent date formatting is used within the
1137
1504
  system based on the language and locale in the client profile.
1138
1505
  ***************/
1139
- formatDate(d, format='long', time=false) {
1506
+ formatDate(d, format='milli', time=false) {
1140
1507
  if (!d) d = Date.now();
1141
1508
  d = new Date(d);
1142
1509
 
1510
+ if (format === 'milli') return d.getTime();
1511
+ // pre-set date formats for returning user dates.
1143
1512
  const formats = {
1144
1513
  long: { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' },
1145
1514
  long_month: { year: 'numeric', month: 'long', day: 'numeric'},
1146
1515
  short: { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric' },
1147
1516
  short_month: { year: 'numeric', month: 'short', day: 'numeric' },
1517
+ numeric: { year: 'numeric', month: 'numeric', day: 'numeric' },
1148
1518
  year: { year: 'numeric' },
1149
1519
  month: { month: 'long' },
1150
1520
  day: { day: 'long' },
@@ -1164,7 +1534,7 @@ class Deva {
1164
1534
  parameter based on the locale setting in the client profile..
1165
1535
  ***************/
1166
1536
  formatTime(t) {
1167
- return t.toLocaleTimeString(this._client.locale);
1537
+ return t.toLocaleTimeString(this._client.locale); // return the formatted time string
1168
1538
  }
1169
1539
 
1170
1540
  /**************