@indra.ai/deva 1.1.39 → 1.1.41

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
@@ -16,10 +16,10 @@ class Deva {
16
16
  this._security = false; // inherited Security features.
17
17
  this._support = false; // inherited Support features.
18
18
  this._services = false; // inherited Service features.
19
- this._assistant = false; // inherited Assistant features.
20
19
  this._business = false; // inherited Business features.
21
20
  this._development = false; // inherited Business features.
22
21
  this._legal = false; // inherited Legal features.
22
+ this._story = false; // inherited Assistant features.
23
23
  this.events = opts.events || new EventEmitter({}); // Event Bus
24
24
  this.lib = opts.lib || {}; // used for loading library functions
25
25
  this.devas = opts.devas || {}; // Devas which are loaded
@@ -30,8 +30,9 @@ class Deva {
30
30
  this.methods = opts.methods || {}; // local Methods
31
31
  this.maxListeners = opts.maxListenners || 0; // set the local maxListeners
32
32
 
33
+ // prevent overwriting existing functions and variables with same name
33
34
  for (var opt in opts) {
34
- if (!this[opt]) this[opt] = opts[opt]; // set any remaining opts to this.
35
+ if (!this[opt] || !this[`_${opt}`]) this[opt] = opts[opt];
35
36
  }
36
37
 
37
38
  this.cmdChr = '/'; // the trigger for local commands
@@ -48,39 +49,35 @@ class Deva {
48
49
 
49
50
  this._state = 'offline'; // current state of agent.
50
51
  this._states = {
51
- ask: 'ask',
52
- question: 'question',
53
-
54
- offline: 'offline',
55
- online: 'online',
56
-
57
- init: 'initialize',
58
- start: 'start',
59
- enter: 'enter',
60
- stop: 'stop',
61
- exit: 'exit',
62
- error: 'error',
63
- load: 'load',
64
- unload: 'unload',
65
- uid: 'uid',
66
- hash: 'hash',
67
- cipher: 'cipher',
68
- decipher: 'deciper',
69
-
70
- invalid: 'invalid',
71
- done: 'done',
72
- error: 'error',
52
+ ask: `asked another Deva`,
53
+ question: `was asked a question`,
54
+ answer: `offered an answer`,
55
+
56
+ offline: `is Offline`,
57
+ online: `is Online`,
58
+
59
+ init: `Initialize`,
60
+ start: `start your journey`,
61
+ enter: `enter deva.world`,
62
+ stop: `stop what you are doing`,
63
+ exit: 'exit deva.world',
64
+ load: 'load Deva',
65
+ unload: 'unload Deva',
66
+
67
+ invalid: 'State Invalid',
68
+ done: 'State Done',
69
+ error: 'State Error',
73
70
  }; // states object
74
71
 
75
72
  this._zone = false; // current state of agent.
76
73
  this._zones = {
77
- deva: 'deva.world',
74
+ deva: 'Deva Zone',
78
75
  config: 'Configuration Zone',
79
- features: 'Features Zone',
76
+ features: 'Feature Zone',
80
77
  idle: 'Idle Zone',
81
78
  train: 'Training Zone',
82
79
  work: 'Working Zone',
83
- invalid: 'Invalid Zone',
80
+ invalid: 'Invalid Invalid',
84
81
  done: 'Done Zone',
85
82
  error: 'Error Zone',
86
83
  }; // states object
@@ -90,122 +87,125 @@ class Deva {
90
87
  wait: 'wait',
91
88
  question: 'question',
92
89
  question_ask: 'question:ask',
93
- question_ask_answer: 'question:ask:answer',
90
+ question_ask_answer: 'returned with an answer',
94
91
  question_cmd: 'question:cmd',
95
92
  question_method: 'question:method',
96
- question_talk: 'quesiton:talk',
93
+ question_talk: 'question:talk',
97
94
  question_hash: 'question:hash',
98
95
  question_answer: 'question:answer',
99
- question_done: 'quesiton:done',
96
+ question_done: 'question:done',
100
97
  answer: 'answer',
101
- answer_talk: 'answer:talk',
102
- ask: 'ask',
103
- ask_answer: 'ask:answer',
104
- security: '#security',
105
- Security: '@SECURITY',
106
- support: '#support',
107
- Support: '@SUPPORT',
108
- systems: '#systems',
109
- Systems: '@SYSTEMS',
110
- services: '#services',
111
- Services: '@SERVICES',
112
- solutions: '#solutions',
113
- Solutions: '@SOLUTIONS',
114
- development: '#development',
115
- Development: '@DEVELOPMENT',
116
- business: '#business',
117
- Business: '@Business',
118
- legal: '#legal',
119
- Legal: '@LEGAL',
120
- assistant: '#assistant',
121
- Assistant: '@ASSISTANT',
122
- story: '#story',
123
- Story: '@STORY',
124
- mind: '#mind',
125
- Mind: '@MIND',
126
- client_data: 'client:data',
127
- invalid: 'invalid',
128
- error: 'error',
129
- done: 'done',
98
+ answer_hash: 'hashing the answer',
99
+ answer_talk: 'sharing the answer',
100
+ ask: 'asking',
101
+ ask_answer: 'answering',
102
+ security: 'security',
103
+ Security: 'Security Feature',
104
+ support: 'support',
105
+ Support: 'Support Feature',
106
+ systems: 'systems',
107
+ Systems: 'Systems Feature',
108
+ services: 'services',
109
+ Services: 'Services Feature',
110
+ solutions: 'solutions',
111
+ Solutions: 'Solutions Feature',
112
+ development: 'development',
113
+ Development: 'Development Feature',
114
+ business: 'business',
115
+ Business: 'Business Feature',
116
+ legal: 'legal',
117
+ Legal: 'Legal Feature',
118
+ assistant: 'assistant',
119
+ Assistant: 'Assistant Feature',
120
+ story: 'story',
121
+ Story: 'Story Feature',
122
+ mind: 'mind',
123
+ Mind: 'Mind Feature',
124
+ client_data: 'Client Data',
125
+ invalid: 'Actin Invalid',
126
+ error: 'Action Error',
127
+ done: 'Action Done',
130
128
  }
131
129
 
132
130
  this._feature = false;
133
131
  this._features = {
134
132
  security: 'security',
135
- Security: 'SECURITY FEATURE',
133
+ Security: 'Security Feature',
136
134
  support: 'support',
137
- Support: 'SUPPORT FEATURE',
135
+ Support: 'Support Feature',
138
136
  services: 'services',
139
- Services: 'SERVICES FEATURE',
137
+ Services: 'Servicees Feature',
140
138
  solutions: 'solutions',
141
- Solutions: 'SOLUTIONS FEATURE',
139
+ Solutions: 'Solutions Feature',
142
140
  systems: 'systems',
143
- Systems: 'SYSTEMS FEATURE',
141
+ Systems: 'Systems Feature',
144
142
  development: 'development',
145
- Development: 'DEVELOPMENT FEATURE',
143
+ Development: 'Development Feature',
146
144
  business: 'business',
147
- Business: 'BUSINESS FEATURE',
145
+ Business: 'Business Feature',
148
146
  legal:'legal',
149
- Legal:'LEGAL FEATURE',
147
+ Legal:'Legal Feature',
150
148
  assistant: 'assistant',
151
- Assistant: 'ASSISTANT FEATURE',
149
+ Assistant: 'Assistant Feature',
152
150
  story: 'story',
153
- Story: 'STORY FEATURE',
151
+ Story: 'Story Feature',
154
152
  mind: 'mind',
155
- Mind: 'MIND FEATURE',
156
- error: 'error',
157
- done: 'done',
153
+ Mind: 'Mind Feature',
154
+ error: 'Feature Error',
155
+ done: 'Feature Done',
158
156
  };
159
157
 
160
158
  this._messages = {
161
159
  states: {
162
160
  offline: `${this._agent.profile.name} ${this._states.offline}`,
163
161
  online: `${this._agent.profile.name} ${this._states.online}`,
164
- ask: `${this._agent.profile.name} ${this._state.ask}`,
165
- question: `${this._agent.profile.name} ${this._states.quesiton}`,
162
+ ask: `😎 ${this._agent.profile.name} ${this._states.ask}`,
163
+ question: `🎙️ ${this._agent.profile.name} ${this._states.question}`,
164
+ answer: `🎟️ ${this._agent.profile.name} ${this._states.answer}`,
166
165
  offline: `${this._agent.profile.name} ${this._states.offline}`,
167
166
  online: `${this._agent.profile.name} ${this._states.online}`,
168
- init: `${this._agent.profile.name} ${this._states.init}`,
169
- start: `${this._agent.profile.name} ${this._states.start}`,
170
- enter: `${this._agent.profile.name} ${this._states.enter}`,
171
- stop: `${this._agent.profile.name} ${this._states.stop}`,
172
- exit: `${this._agent.profile.name} ${this._states.exit}`,
173
- load: `${this._agent.profile.name} ${this._states.load}`,
174
- unload: `${this._agent.profile.name} ${this._states.unload}`,
167
+ init: `🚀 ${this._agent.profile.name} ${this._states.init}`,
168
+ start: `🎬 ${this._agent.profile.name} ${this._states.start}`,
169
+ enter: `📲 ${this._agent.profile.name} ${this._states.enter}`,
170
+ stop: `✋ ${this._agent.profile.name} ${this._states.stop}`,
171
+ exit: `🚪 ${this._agent.profile.name} ${this._states.exit}`,
172
+ load: `📫 ${this._agent.profile.name} ${this._states.load}`,
173
+ unload: `📭 ${this._agent.profile.name} ${this._states.unload}`,
175
174
  uid: `${this._agent.profile.name} ${this._states.uid}`,
176
175
  hash: `${this._agent.profile.name} ${this._states.hash}`,
177
176
  cipher: `${this._agent.profile.name} ${this._states.cipher}`,
178
177
  decipher: `${this._agent.profile.name} ${this._states.decipher}`,
179
- invalid: `${this._agent.profile.name} ${this._states.invalid}`,
180
- done: `${this._agent.profile.name} ${this._states.done}`,
181
- error: `${this._states.error}`,
178
+ invalid: `⚠️ ${this._agent.profile.name} ${this._states.invalid}`,
179
+ done: `✅ ${this._agent.profile.name} ${this._states.done}`,
180
+ error: `❌ ${this._states.error}`,
182
181
  },
183
182
  zones: {
184
- deva: `${this._agent.profile.name} enter ${this._zones.deva}`,
185
- config: `${this._agent.profile.name} ${this._zones.config}`,
186
- features: `${this._agent.profile.name} ${this._zones.features}`,
187
- idle: `${this._agent.profile.name} ${this._zones.idle}`,
188
- train: `${this._agent.profile.name} ${this._zones.train}`,
189
- work: `${this._agent.profile.name} ${this._zones.work}`,
190
- invalid: `${this._agent.profile.name} ${this._zones.invalid}`,
191
- done: `${this._agent.profile.name} ${this._zones.done}`,
192
- error: `${this._agent.profile.name} ${this._zones.error}`,
183
+ deva: `🎉 ${this._agent.profile.name} entered the ${this._zones.deva}`,
184
+ config: `💪 ${this._agent.profile.name} is in the ${this._zones.config}`,
185
+ features: `🍿 ${this._agent.profile.name} entered the ${this._zones.features}`,
186
+ idle: `🥱 ${this._agent.profile.name} is stuck in the ${this._zones.idle}`,
187
+ train: `👨‍🎓 ${this._agent.profile.name} is learning in the ${this._zones.train}`,
188
+ work: `😓 ${this._agent.profile.name} is handling things in the ${this._zones.work}`,
189
+ invalid: `⚠️ ${this._agent.profile.name} fell into the ${this._zones.invalid}`,
190
+ done: `✅ ${this._agent.profile.name} and here we are in the ${this._zones.done}`,
191
+ error: `❌ ${this._agent.profile.name} fell into the ${this._zones.error}`,
193
192
  },
194
193
  actions: {
195
- wait: `${this._agent.profile.name} ${this._actions.wait}`,
196
- question: `${this._agent.profile.name} ${this._actions.question}`,
197
- question_ask: `${this._agent.profile.name} ${this._actions.question_ask}`,
198
- question_ask_answer: `${this._agent.profile.name} ${this._actions.questoin_ask_answer}`,
199
- question_cmd: `${this._agent.profile.name} ${this._actions.question_cmd}`,
200
- question_method: `${this._agent.profile.name} ${this._actions.question_method}`,
201
- question_talk: `${this._agent.profile.name} ${this._actions.question_talk}`,
202
- question_hash: `${this._agent.profile.name} ${this._actions.question_hash}`,
203
- question_answer: `${this._agent.profile.name} ${this._actions.question_answer}`,
204
- question_done: `${this._agent.profile.name} ${this._actions.question_done}`,
205
- answer: `${this._agent.profile.name} ${this._actions.answer}`,
206
- answer_talk: `${this._agent.profile.name} ${this._actions.answer_talk}`,
207
- ask: `${this._agent.profile.name} ${this._actions.ask}`,
208
- ask_answer: `${this._agent.profile.name} ${this._actions.ask_answer}`,
194
+ wait: `😵‍💫 ${this._agent.profile.name} ${this._actions.wait}`,
195
+ question: `👀 ${this._agent.profile.name} ${this._actions.question}`,
196
+ question_ask: `👥 ${this._agent.profile.name} ${this._actions.question_ask}`,
197
+ question_ask_answer: `📣 ${this._agent.profile.name} ${this._actions.question_ask_answer}`,
198
+ question_cmd: `🎮 ${this._agent.profile.name} issued a command`,
199
+ question_method: `🏄‍♂️ ${this._agent.profile.name} ${this._actions.question_method}`,
200
+ question_talk: `📢 ${this._agent.profile.name} ${this._actions.question_talk}`,
201
+ question_hash: `#️⃣ ${this._agent.profile.name} is hashing a question`,
202
+ question_answer: `🎙️ ${this._agent.profile.name} ${this._actions.question_answer}`,
203
+ question_done: `👍 ${this._agent.profile.name} ${this._actions.question_done}`,
204
+ answer: `🎟️ ${this._agent.profile.name} gave an ${this._actions.answer}`,
205
+ answer_talk: `🎟️ ${this._agent.profile.name} is talking the ansnwer for anyone listening `,
206
+ ask: `👥 ${this._agent.profile.name} is asking`,
207
+ ask_answer: `🎟️ ${this._agent.profile.name} is answering the ask`,
208
+
209
209
  security: `${this._actions.security} is responding`,
210
210
  Security: `${this._actions.Security} is ready`,
211
211
  support: `${this._actions.support} is responding`,
@@ -228,37 +228,37 @@ class Deva {
228
228
  Story: `${this._actions.Story} is ready`,
229
229
  mind: `${this._actions.Mind} is responding`,
230
230
  Mind: `${this._actions.Mind} is ready`,
231
- client_data: `${this._agent.profile.name} setting Client Data`,
231
+ client_data: `📂 ${this._agent.profile.name} setting Client Data`,
232
232
  invalid: `${this._actions.invalid}`,
233
- done: `${this._actions.done}`,
233
+ done: `✅ ${this._actions.done}`,
234
234
  error: `${this._action.error}`,
235
235
  },
236
236
  features: {
237
237
  security: `${this._features.security} is protecting`,
238
- Security: `${this._features.Security} is configuring`,
238
+ Security: `${this._features.Security} loading...`,
239
239
  support: `${this._features.support} is caring`,
240
- Support: `${this._features.Support} is configuring`,
240
+ Support: `${this._features.Support} loading...`,
241
241
  services: `${this._features.services} is servicing`,
242
- Services: `${this._features.Services} is configuring`,
242
+ Services: `${this._features.Services} loading...`,
243
243
  solutions: `${this._features.solutions} is solving`,
244
- Solutions: `${this._features.Solutions} is configuring`,
244
+ Solutions: `${this._features.Solutions} loading...`,
245
245
  systems: `${this._features.systems} is mantaining`,
246
- Systems: `${this._features.Systems} is configuring`,
246
+ Systems: `${this._features.Systems} loading...`,
247
247
  development: `${this._features.development} is developing`,
248
- Development: `${this._features.Development} is working on ideas`,
248
+ Development: `${this._features.Development} loading...`,
249
249
  business: `${this._features.business} is successful`,
250
- Business: `${this._features.Business} is configuring`,
250
+ Business: `${this._features.Business} loading...`,
251
251
  legal: `${this._features.legal} is upholding the law`,
252
- Legal: `${this._features.Legal} is configuring`,
252
+ Legal: `${this._features.Legal} loading...`,
253
253
  assistant: `${this._features.assistant} is assisting`,
254
- Assistant: `${this._features.Assistant} is configuring`,
254
+ Assistant: `${this._features.Assistant} loading...`,
255
255
  story: `${this._features.story} is creating`,
256
- Story: `${this._features.Story} is configuring`,
256
+ Story: `${this._features.Story} loading...`,
257
257
  mind: `${this._features.story} is thinking and pondering`,
258
- Mind: `${this._features.Mind} is configuring`,
259
- invalid: this._features.invalid,
260
- done: this._features.done,
261
- error: this._features.error,
258
+ Mind: `${this._features.Mind} loading...`,
259
+ invalid: `⚠️ ${this._features.invalid}`,
260
+ done: `✅ ${this._features.done}`,
261
+ error: `❌ ${this._features.error}`,
262
262
  },
263
263
  }; // messages object
264
264
  }
@@ -290,11 +290,12 @@ class Deva {
290
290
  ***************/
291
291
  Security() {
292
292
  this.feature('Security');
293
+ const _cl = this.client();
293
294
  try {
294
- if (this._client.features.security) return this.Support();
295
+ if (!_cl.features.security) return this.Support();
295
296
  else {
296
297
  this.action('Security');
297
- const {id, profile, features} = this._client; // make a copy the clinet data.
298
+ const {id, profile, features} = _cl; // make a copy the clinet data.
298
299
  const {security} = features; // make a copy the clinet data.
299
300
  this._security = { // set this_security with data
300
301
  id: this.uid(true), // uuid of the security feature
@@ -325,11 +326,12 @@ class Deva {
325
326
  ***************/
326
327
  Support() {
327
328
  this.feature('Support'); // set state to support setting
329
+ const _cl = this.client();
328
330
  try {
329
- if (!this._client.features.support) return this.Services()
331
+ if (!_cl.features.support) return this.Services()
330
332
  else {
331
333
  this.action('Support');
332
- const {id, features, profile} = this._client; // set the local consts from client copy
334
+ const {id, features, profile} = _cl; // set the local consts from client copy
333
335
  const {support} = features; // set support from features const
334
336
  this._support = { // set this_support with data
335
337
  id: this.uid(true), // uuid of the support feature
@@ -358,11 +360,12 @@ class Deva {
358
360
  ***************/
359
361
  Services() {
360
362
  this.feature('Services'); // set state to security setting
363
+ const _cl = this.client();
361
364
  try {
362
- if (!this._client.features.services) return this.Systems();
365
+ if (!_cl.features.services) return this.Systems();
363
366
  else {
364
367
  this.action('Services')
365
- const {id, features, profile} = this._client; // set the local consts from client copy
368
+ const {id, features, profile} = _cl; // set the local consts from client copy
366
369
  const {services} = features; // set services from features const
367
370
  this._services = { // set this_services with data
368
371
  id: this.uid(true), // uuid of the services feature
@@ -391,11 +394,12 @@ class Deva {
391
394
  ***************/
392
395
  Systems() {
393
396
  this.feature('Systems'); // set state to systems setting
397
+ const _cl = this.client();
394
398
  try {
395
- if (!this._client.features.systems) return this.Solutions();
399
+ if (!_cl.features.systems) return this.Solutions();
396
400
  else {
397
401
  this.action('Systems');
398
- const {id, features, profile} = this._client; // set the local consts from client copy
402
+ const {id, features, profile} = _cl; // set the local consts from client copy
399
403
  const {systems} = features; // set systems from features const
400
404
  this._systems = { // set this_systems with data
401
405
  id: this.uid(true), // uuid of the systems feature
@@ -425,11 +429,12 @@ class Deva {
425
429
  ***************/
426
430
  Solutions() {
427
431
  this.feature('Solutions'); // set state to solutions setting
432
+ const _cl = this.client();
428
433
  try {
429
- if (!this._client.features.solutions) return this.Development();
434
+ if (!_cl.features.solutions) return this.Development();
430
435
  else {
431
436
  this.action('Solutions');
432
- const {id, features, profile} = this._client; // set the local consts from client copy
437
+ const {id, features, profile} = _cl; // set the local consts from client copy
433
438
  const {solutions} = features; // set solutions from features const
434
439
  this._solutions = { // set this_solutions with data
435
440
  id: this.uid(true), // uuid of the solutions feature
@@ -458,11 +463,12 @@ class Deva {
458
463
  ***************/
459
464
  Development() {
460
465
  this.feature('Development'); // set state to development setting
466
+ const _cl = this.client();
461
467
  try {
462
- if (!this._client.features.development) return this.Business();
468
+ if (!_cl.features.development) return this.Business();
463
469
  else {
464
470
  this.action('Development');
465
- const {id, features, profile} = this._client; // set the local consts from client copy
471
+ const {id, features, profile} = _cl; // set the local consts from client copy
466
472
  const {development} = features; // set development from features const
467
473
  this._development = { // set this_development with data
468
474
  id: this.uid(true), // uuid of the development feature
@@ -491,11 +497,12 @@ class Deva {
491
497
  ***************/
492
498
  Business(client=false) {
493
499
  this.feature('Business'); // set state to business setting
500
+ const _cl = this.client();
494
501
  try {
495
- if (!this._client.features.business) return this.Legal();
502
+ if (!_cl.features.business) return this.Legal();
496
503
  else {
497
504
  this.action('Business');
498
- const {id, features, profile} = this._client; // set the local consts from client copy
505
+ const {id, features, profile} = _cl; // set the local consts from client copy
499
506
  const {business} = features; // set business from features const
500
507
  this._business = { // set this_business with data
501
508
  id: this.uid(true), // uuid of the business feature
@@ -524,11 +531,12 @@ class Deva {
524
531
  ***************/
525
532
  Legal() {
526
533
  this.feature('Legal'); // set state to legal setting
534
+ const _cl = this.client();
527
535
  try {
528
- if (!this._client.features.legal) this.Assistant();
536
+ if (!_cl.features.legal) this.Assistant();
529
537
  else {
530
538
  this.action('Legal');
531
- const {id, features, profile} = this._client; // set the local consts from client copy
539
+ const {id, features, profile} = _cl; // set the local consts from client copy
532
540
  const {legal} = features; // set legal from features const
533
541
  this._legal = { // set this_legal with data
534
542
  id: this.uid(true), // uuid of the legal feature
@@ -542,6 +550,8 @@ class Deva {
542
550
  return this.Assistant();
543
551
  }
544
552
  } catch (e) {
553
+ this.action('error');
554
+ this.feature('error');
545
555
  return this.error(e) // run error handling if an error is caught
546
556
  }
547
557
  }
@@ -555,11 +565,12 @@ class Deva {
555
565
  ***************/
556
566
  Assistant(client=false) {
557
567
  this.feature('Assistant'); // set state to assistant setting
568
+ const _cl = this.client();
558
569
  try {
559
- if (!this._client.features.assistant) return this.Done();
570
+ if (!_cl.features.assistant) return this.Done();
560
571
  else {
561
572
  this.action('Assistant');
562
- const {id, features, profile} = this._client; // set the local consts from client copy
573
+ const {id, features, profile} = _cl; // set the local consts from client copy
563
574
  const {assistant} = features; // set assistant from features const
564
575
  this._assistant = { // set this_assistant with data
565
576
  id: this.uid(true), // uuid of the assistant feature
@@ -573,6 +584,8 @@ class Deva {
573
584
  return this.Story();
574
585
  }
575
586
  } catch (e) {
587
+ this.action('error');
588
+ this.feature('error');
576
589
  return this.error(e) // run error handling if an error is caught
577
590
  }
578
591
  }
@@ -586,6 +599,7 @@ class Deva {
586
599
  ***************/
587
600
  Story(client=false) {
588
601
  this.feature('Story'); // set state to story setting
602
+ const _cl = this.client();
589
603
  try {
590
604
  if (!this._client.features.story) return this.Mind();
591
605
  else {
@@ -619,11 +633,12 @@ class Deva {
619
633
  ***************/
620
634
  Mind(client=false) {
621
635
  this.feature('Mind'); // set state to story setting
636
+ const _cl = this.client();
622
637
  try {
623
- if (!this._client.features.mind) return this.Done();
638
+ if (!_cl.features.mind) return this.Done();
624
639
  else {
625
640
  this.action('Mind');
626
- const {id, features, profile} = this._client; // set the local consts from client copy
641
+ const {id, features, profile} = _cl; // set the local consts from client copy
627
642
  const {mind} = features; // set mind from features const
628
643
  this._mind = { // set this_mind with data
629
644
  id: this.uid(true), // uuid of the mind feature
@@ -652,6 +667,7 @@ class Deva {
652
667
  return new Promise((resolve, reject) => {
653
668
  try {
654
669
  delete this._client.features; // delete the features key when done.
670
+ this.action('done'); // set state to assistant setting
655
671
  this.feature('done'); // set state to assistant setting
656
672
  return resolve();
657
673
  } catch (e) {
@@ -769,8 +785,8 @@ class Deva {
769
785
  ***************/
770
786
  _methodNotFound(packet) {
771
787
  packet.a = {
772
- agent: this._agent || false,
773
- client: this._client || false,
788
+ agent: this.agent() || false,
789
+ client: this.client() || false,
774
790
  text: `${this._messages.method_not_found}`,
775
791
  meta: {
776
792
  key: this._agent.key,
@@ -778,7 +794,7 @@ class Deva {
778
794
  },
779
795
  created: Date.now(),
780
796
  };
781
- this.state('method_not_found', packet);
797
+ this.state('method_not_found');
782
798
  return packet;
783
799
  }
784
800
 
@@ -843,127 +859,6 @@ class Deva {
843
859
  return this.events.removeListener(evt, callback);
844
860
  }
845
861
 
846
- /**************
847
- func: ask
848
- params: packet
849
- describe:
850
- The ask function gives each agent the ability to ask question to other agents
851
- in the system. When a question is asked the Agent with the question if it
852
- detect an ask event it will trigger. Then if an Agent with the matching ask
853
- event is listening they will respond. The question function uses this to
854
- create integrated communication between itself and other Deva in it's library.
855
-
856
- It can also be used in a custom manner to broadcast ask events inside other coe aswell.
857
-
858
- When the talk has an answer it will respond with a talk event that has the packet id
859
- so the event is specific to the talk.
860
- ***************/
861
- ask(packet) {
862
- if (!this._active) return Promise.resolve(this._messages.states.offline);
863
- this.action('question', packet);
864
-
865
- packet.a = {
866
- agent: this._agent || false,
867
- client: this._client || false,
868
- meta: {
869
- key: this._agent.key,
870
- method: packet.q.meta.method,
871
- params: packet.q.meta.params,
872
- },
873
- text: false,
874
- html: false,
875
- data: false,
876
- created: Date.now(),
877
- };
878
-
879
- try {
880
- if (this.methods[packet.q.meta.method] !== 'function') {
881
- return setImmediate(() => {
882
- this.action('ask_invalid')
883
- packet.a.text = `INVALID METHOD (${packet.q.meta.method})`;
884
- this.talk(`${this._agent.key}:ask:${packet.id}`, packet);
885
- });
886
- }
887
-
888
- // The method is parsed and depending on what method is asked for it returns
889
- // the response based on the passed through packet.
890
- this.methods[packet.q.meta.method](packet).then(result => {
891
- if (typeof result === 'object') {
892
- packet.a.text = result.text || false;
893
- packet.a.html = result.html || false;
894
- packet.a.data = result.data || false;
895
- }
896
- else {
897
- packet.a.text = result;
898
- }
899
- this.action('ask_answer', packet);
900
- this.talk(`${this._agent.key}:ask:${packet.id}`, packet);
901
- }).catch(err => {
902
- this.action('error', err);
903
- this.talk(`${this._agent.key}:ask:${packet.id}`, {error:err.toString()});
904
- return this.error(err, packet);
905
- })
906
- }
907
- catch (e) {
908
- this.action('error', err);
909
- this.talk(`${this._agent.key}:ask:${packet.id}`, {error:e.toString()});
910
- return this.error(e, packet)
911
- }
912
- // now when we ask the meta params[0] should be the method
913
- }
914
-
915
- answer(packet, resolve, reject) {
916
- this.action('answer', packet); // set the question answer state
917
- // check if method exists and is of type function
918
- const {method,params} = packet.q.meta;
919
- const isMethod = this.methods[method] && typeof this.methods[method] == 'function';
920
- if (!isMethod) {
921
- this.action('invalid')
922
- return resolve(this._methodNotFound(packet)); // resolve method not found if check if check fails
923
- }
924
- // Call the local method to process the question based the extracted parameters
925
- return this.methods[method](packet).then(result => {
926
- // check the result for the text, html, and data object.
927
- // this is for when answers are returned from nested Devas.
928
- const text = typeof result === 'object' ? result.text : result;
929
- const html = typeof result === 'object' ? result.html : result;
930
- // if the data passed is NOT an object it will FALSE
931
- const data = typeof result === 'object' ? result.data : false;
932
-
933
-
934
- packet.a = { // setup the packet.a container
935
- agent: this._agent || false, // set the agent who answered the question
936
- client: this._client || false, // set the client asking the question
937
- meta: { // setup the answer meta container
938
- key: this._agent.key, // set the agent key inot the meta
939
- method, // set the method into the meta
940
- params, // set the params into the meta
941
- },
942
- text, // set answer text
943
- html,
944
- data,
945
- created: Date.now(),
946
- };
947
-
948
- // create a hash for the answer and insert into answer meta.
949
- this.action('hash_answer');
950
- packet.a.meta.hash = this.hash(JSON.stringify(packet.a));
951
- // create a hash for entire packet and insert into packet
952
- // hash the entire packet.
953
- this.action('hash_packet');
954
- packet.hash = this.hash(JSON.stringify(packet));
955
-
956
- this.action('answer_talk');
957
- this.talk(`${this._agent.key}:answer`, packet); // set the question answer state
958
-
959
- this.action('done');
960
- return resolve(packet); // resolve the packet to the caller.
961
- }).catch(err => { // catch any errors in the method
962
- this.action('error', err);
963
- return this.error(err, packet, reject); // return this.error with err, packet, reject
964
- });
965
- }
966
-
967
862
  /**************
968
863
  func: question
969
864
  example: this.question('#*agent.key *method* *text*')
@@ -978,6 +873,7 @@ class Deva {
978
873
  if (!this._active) return Promise.resolve(this._messages.states.offline);
979
874
  const id = this.uid(); // generate a unique id for transport.
980
875
  const t_split = TEXT.split(' '); // split the text on spaces to get words.
876
+ this.state('question');
981
877
  this.action('question', id);
982
878
 
983
879
  // check to see if the string is an #ask string to talk to the other Deva.
@@ -991,8 +887,8 @@ class Deva {
991
887
  const data = DATA; // set the DATA to data
992
888
  const packet = { // create the base q/a packet
993
889
  id, // set the id into packet
994
- q: {}, // create empty q object in packet
995
- a: {}, // create empty a object in packet
890
+ q: false, // create empty q object in packet
891
+ a: false, // create empty a object in packet
996
892
  created: Date.now(), // timestamp the packet
997
893
  };
998
894
 
@@ -1009,6 +905,7 @@ class Deva {
1009
905
  let _action = 'question_method'
1010
906
  try { // try to answer the question
1011
907
  if (isAsk) { // determine if hte question isAsk
908
+ _action = 'question_ask';
1012
909
  key = t_split[0].substring(1); // if:isAsksplit the agent key and remove first command character
1013
910
  //if:isAsk use text split index 1 as the parameter block
1014
911
  params = t_split[1] ? t_split[1].split(':') : false;
@@ -1023,12 +920,12 @@ class Deva {
1023
920
  text = t_split.slice(1).join(' ').trim(); // if:isCmd rejoin the string on the space after removing first index
1024
921
  }
1025
922
  else {
1026
- this.action('question_method');
1027
923
  }
1028
924
 
1029
925
  packet.q = { // build packet.q container
1030
- agent: this._agent || false, // set the agent
1031
- client: this._client || false, // set the client
926
+ id: this.uid(),
927
+ agent: this.agent() || false, // set the agent
928
+ client: this.client() || false, // set the client
1032
929
  meta: { // build the meta container
1033
930
  key, // set the key variable
1034
931
  orig, // set orig text to track chances
@@ -1044,18 +941,20 @@ class Deva {
1044
941
  this.action('question_hash'); // set the has question state
1045
942
  packet.q.meta.hash = this.hash(JSON.stringify(packet.q));
1046
943
 
944
+ this.action(_action);
945
+ this.talk('devacore:question', this.copy(packet)); // global question event make sure to copy data.
1047
946
 
1048
947
  if (isAsk) { // isAsk check if the question isAsk and talk
1049
- this.action('question_ask');
1050
- this.talk(`${key}:ask`, packet); // if:isAsk talk the event to theother Deva
948
+ this.state('ask');
1051
949
  // if: isAsk wait for the once event which is key'd to the packet ID for specified responses
950
+ this.talk(`${key}:ask`, this.copy(packet));
1052
951
  this.once(`${key}:ask:${packet.id}`, answer => {
1053
952
  this.action('question_ask_answer');
1054
953
  return resolve(answer); // if:isAsk resolve the answer from the call
1055
954
  });
1056
955
  }
1057
956
  else { // else: answer tue question locally
1058
- this.action(_action);
957
+ this.action('ask_answer');
1059
958
  return this.answer(packet, resolve, reject);
1060
959
  }
1061
960
  }
@@ -1066,6 +965,146 @@ class Deva {
1066
965
  });
1067
966
  }
1068
967
 
968
+ /**************
969
+ func: answer
970
+ params:
971
+ - packet
972
+ - resolve
973
+ - reject
974
+ describe:
975
+ The answer function is called from the question fuction to return an answer
976
+ from the agent from the pre-determined method.
977
+ ***************/
978
+ answer(packet, resolve, reject) {
979
+ if (!this._active) return Promise.resolve(this._messages.states.offline);
980
+
981
+ this.state('answer');
982
+ // check if method exists and is of type function
983
+ const {method,params} = packet.q.meta;
984
+ const isMethod = this.methods[method] && typeof this.methods[method] == 'function';
985
+ if (!isMethod) {
986
+ this.action('invalid')
987
+ return resolve(this._methodNotFound(packet)); // resolve method not found if check if check fails
988
+ }
989
+ // Call the local method to process the question based the extracted parameters
990
+ return this.methods[method](packet).then(result => {
991
+ this.action('answer');
992
+ // check the result for the text, html, and data object.
993
+ // this is for when answers are returned from nested Devas.
994
+ const text = typeof result === 'object' ? result.text : result;
995
+ const html = typeof result === 'object' ? result.html : result;
996
+ // if the data passed is NOT an object it will FALSE
997
+ const data = typeof result === 'object' ? result.data : false;
998
+
999
+ const agent = this.agent() || false;
1000
+ const client = this.client() || false;
1001
+ packet.a = { // setup the packet.a container
1002
+ id: this.uid(),
1003
+ agent, // set the agent who answered the question
1004
+ client, // set the client asking the question
1005
+ meta: { // setup the answer meta container
1006
+ key: agent.key, // set the agent key inot the meta
1007
+ method, // set the method into the meta
1008
+ params, // set the params into the meta
1009
+ },
1010
+ text, // set answer text
1011
+ html, // set the answer html
1012
+ data, // set the answer data
1013
+ created: Date.now(),
1014
+ };
1015
+
1016
+ // create a hash for the answer and insert into answer meta.
1017
+ this.action('answer_hash');
1018
+ packet.a.meta.hash = this.hash(JSON.stringify(packet.a));
1019
+
1020
+ this.action('packet_hash');
1021
+ packet.hash = this.hash(JSON.stringify(packet)); // hash the entire packet.
1022
+
1023
+
1024
+ this.action('answer_talk');
1025
+ this.talk('devacore:answer', this.copy(packet)); // talk the answer with a copy of the data
1026
+
1027
+ return resolve(packet); // resolve the packet to the caller.
1028
+ }).catch(err => { // catch any errors in the method
1029
+ this.action('error');
1030
+ return this.error(err, packet, reject); // return this.error with err, packet, reject
1031
+ });
1032
+ }
1033
+
1034
+ /**************
1035
+ func: ask
1036
+ params: packet
1037
+ describe:
1038
+ The ask function gives each agent the ability to ask question to other agents
1039
+ in the system. When a question is asked the Agent with the question if it
1040
+ detect an ask event it will trigger. Then if an Agent with the matching ask
1041
+ event is listening they will respond. The question function uses this to
1042
+ create integrated communication between itself and other Deva in it's library.
1043
+
1044
+ It can also be used in a custom manner to broadcast ask events inside other coe aswell.
1045
+
1046
+ When the talk has an answer it will respond with a talk event that has the packet id
1047
+ so the event is specific to the talk.
1048
+ ***************/
1049
+ ask(packet) {
1050
+ if (!this._active) return Promise.resolve(this._messages.states.offline);
1051
+ this.state('ask');
1052
+ this.action('ask');
1053
+
1054
+ const agent = this.agent() || false;
1055
+ const client = this.client() || false;
1056
+ // build the answer packet from this model
1057
+ packet.a = {
1058
+ agent,
1059
+ client,
1060
+ meta: {
1061
+ key: agent.key,
1062
+ method: packet.q.meta.method,
1063
+ params: packet.q.meta.params,
1064
+ },
1065
+ text: false,
1066
+ html: false,
1067
+ data: false,
1068
+ created: Date.now(),
1069
+ };
1070
+
1071
+ try {
1072
+ if (typeof this.methods[packet.q.meta.method] !== 'function') {
1073
+ return setImmediate(() => {
1074
+ this.action('invalid')
1075
+ packet.a.text = `INVALID METHOD (${packet.q.meta.method})`;
1076
+ this.talk(`${this._agent.key}:ask:${packet.id}`, packet);
1077
+ });
1078
+ }
1079
+
1080
+ // The method is parsed and depending on what method is asked for it returns
1081
+ // the response based on the passed through packet.
1082
+ this.methods[packet.q.meta.method](packet).then(result => {
1083
+ if (typeof result === 'object') {
1084
+ packet.a.text = result.text || false;
1085
+ packet.a.html = result.html || false;
1086
+ packet.a.data = result.data || false;
1087
+ }
1088
+ else {
1089
+ packet.a.text = result;
1090
+ }
1091
+ this.action('ask_answer');
1092
+ this.talk(`${this._agent.key}:ask:${packet.id}`, this.copy(packet));
1093
+ }).catch(err => {
1094
+ this.action('error');
1095
+ this.talk(`${this._agent.key}:ask:${packet.id}`, {error:err.toString()});
1096
+ return this.error(err, packet);
1097
+ })
1098
+ }
1099
+ catch (e) {
1100
+ this.action('error');
1101
+ this.talk(`${this._agent.key}:ask:${packet.id}`, {error:e.toString()});
1102
+ return this.error(e, packet)
1103
+ }
1104
+ // now when we ask the meta params[0] should be the method
1105
+ }
1106
+
1107
+
1069
1108
  /**************
1070
1109
  func: init
1071
1110
  params: client - the client data to use that is provided by the clients.
@@ -1083,14 +1122,15 @@ class Deva {
1083
1122
  ***************/
1084
1123
  init(client) {
1085
1124
  const _data = {
1086
- id: this.uid(),
1087
- key: 'init',
1125
+ id: this.uid(true),
1126
+ key: 'return',
1088
1127
  value: 'init',
1089
1128
  agent: this._agent,
1090
1129
  client: this.copy(client),
1091
1130
  text: this._messages.states.start,
1092
1131
  created: Date.now(),
1093
1132
  }
1133
+ _data.hash = this.hash(JSON.stringify(_data));
1094
1134
 
1095
1135
  // set client
1096
1136
  this._active = Date.now();
@@ -1110,8 +1150,6 @@ class Deva {
1110
1150
  return this.Security();
1111
1151
  }).then(() => {
1112
1152
  this.zone('deva');
1113
-
1114
- _data.hash = this.hash(JSON.stringify(_data));
1115
1153
  const hasOnInit = this.onInit && typeof this.onInit === 'function';
1116
1154
  return hasOnInit ? this.onInit(_data) : this.start(_data)
1117
1155
  }).catch(err => {
@@ -1120,34 +1158,6 @@ class Deva {
1120
1158
  });
1121
1159
  }
1122
1160
 
1123
- /**************
1124
- func: error
1125
- params:
1126
- - err: The error to process
1127
- - data: Any additional data associated with the error
1128
- - reject: An associated promise reject if the caller requires.
1129
- describe:
1130
- The erro function rpovides the consistent error manage of the system.
1131
- usage: this.error(err, data, reject);
1132
- ***************/
1133
- error(err,data=false,reject=false) {
1134
- // check fo rthe custom onError function in the agent.
1135
- console.log('\n::BEGIN:ERROR\n');
1136
- console.log(err);
1137
- console.log('\n::END:ERROR\n');
1138
- if (data) {
1139
- console.log('::::::');
1140
- console.log('\n::BEGIN:DATA\n');
1141
- console.log(JSON.stringify(data, null, 2));
1142
- console.log('\n::END:DATA\n');
1143
- }
1144
-
1145
- if (this.onError && typeof this.onError === 'function') return this.onError(err, data, reject);
1146
- else {
1147
- return reject ? reject(err) : err;
1148
- }
1149
- }
1150
-
1151
1161
  /**************
1152
1162
  func: start
1153
1163
  params:
@@ -1161,18 +1171,60 @@ class Deva {
1161
1171
  start(data=false) {
1162
1172
  this.state('start');
1163
1173
  if (!this._active) return Promise.resolve(this._messages.states.offline);
1164
- const _data = {
1165
- id: this.uid(),
1166
- key: 'start',
1167
- value: 'start',
1168
- agent: this._agent,
1169
- client: data.client || this._client,
1170
- text: this._messages.states.start,
1171
- created: Date.now(),
1174
+ data.value = 'start';
1175
+ delete data.hash;
1176
+ data.hash = this.hash(JSON.stringify(data));
1177
+
1178
+ if (this.info) {
1179
+ const _info = JSON.stringify(this.info, null, 2).replace(/\{/g, '::BEGIN:INFO')
1180
+ .replace(/\"|\,/g, '').replace(/\}/g, '::END:INFO').trim()
1181
+ this.prompt(_info);
1172
1182
  }
1173
- _data.hash = this.hash(JSON.stringify(_data));
1174
- const hasOnStart = this.onStart && typeof this.onStart === 'function';
1175
- return hasOnStart ? this.onStart(_data) : this.enter(_data)
1183
+
1184
+ const hasOnStart = this.onStart && typeof this.onStart === 'function' ? true : false;
1185
+ return hasOnStart ? this.onStart(data) : this.enter(data)
1186
+ }
1187
+
1188
+ /**************
1189
+ func: enter
1190
+ params:
1191
+ - msg: hte message from the caller incase need to use in calls
1192
+ describe:
1193
+ The ener function will check the actie status of the Deva and set it to
1194
+ offline or enter.
1195
+
1196
+ If the Deva is offline it will return the offline message.
1197
+ usage: this.enter('msg')
1198
+ ***************/
1199
+ enter(data=false) {
1200
+ this.state('enter');
1201
+ if (!this._active) return Promise.resolve(this._messages.states.offline);
1202
+ data.value = 'enter';
1203
+ delete data.hash;
1204
+ data.hash = this.hash(JSON.stringify(data));
1205
+ const hasOnEnter = this.onEnter && typeof this.onEnter === 'function' ? true : false;
1206
+ return hasOnEnter ? this.onEnter(_data) : this.done(data)
1207
+ }
1208
+
1209
+ /**************
1210
+ func: done
1211
+ params:
1212
+ - msg: hte message from the caller incase need to use in calls
1213
+ describe:
1214
+ When the done function is triggered the system will also set the state
1215
+ of hte Deva to done.
1216
+
1217
+ If the deva is offline it will return the offline message.
1218
+ usage: this.done('msg')
1219
+ ***************/
1220
+ done(data=false) {
1221
+ this.state('done');
1222
+ if (!this._active) return Promise.resolve(this._messages.states.offline);
1223
+ data.value = 'done';
1224
+ delete data.hash;
1225
+ data.hash = this.hash(JSON.stringify(data));
1226
+ const hasOnDone = this.onDone && typeof this.onDone === 'function' ? true : false;
1227
+ return hasOnDone ? this.onDone(data) : Promise.resolve(data);
1176
1228
  }
1177
1229
 
1178
1230
  /**************
@@ -1188,15 +1240,15 @@ class Deva {
1188
1240
  usage:
1189
1241
  this.stop('msg')
1190
1242
  ***************/
1191
- stop(data=false) {
1243
+ stop() {
1192
1244
  this.state('stop');
1193
1245
  if (!this._active) return Promise.resolve(this._messages.states.offline);
1194
1246
  const _data = {
1195
- id: this.uid(),
1196
- key: 'stop',
1247
+ id: this.uid(true),
1248
+ key: 'return',
1197
1249
  value: 'stop',
1198
- agent: this._agent,
1199
- client: data.client || this._client,
1250
+ agent: this.agent(),
1251
+ client: this.client(),
1200
1252
  text: this._messages.states.stop,
1201
1253
  created: Date.now(),
1202
1254
  }
@@ -1205,33 +1257,6 @@ class Deva {
1205
1257
  return hasOnStop ? this.onStop(_data) : this.exit(_data)
1206
1258
  }
1207
1259
 
1208
- /**************
1209
- func: enter
1210
- params:
1211
- - msg: hte message from the caller incase need to use in calls
1212
- describe:
1213
- The ener function will check the actie status of the Deva and set it to
1214
- offline or enter.
1215
-
1216
- If the Deva is offline it will return the offline message.
1217
- usage: this.enter('msg')
1218
- ***************/
1219
- enter(data=false) {
1220
- this.state('enter');
1221
- if (!this._active) return Promise.resolve(this._messages.states.offline);
1222
- const _data = {
1223
- id: this.uid(),
1224
- type: 'enter',
1225
- value: 'enter',
1226
- agent: this._agent,
1227
- client: data.client || this._client,
1228
- text: this._messages.states.enter,
1229
- created: Date.now(),
1230
- }
1231
- _data.hash = this.hash(JSON.stringify(_data));
1232
- const hasOnEnter = this.onEnter && typeof this.onEnter === 'function';
1233
- return hasOnEnter ? this.onEnter(_data) : this.done(_data)
1234
- }
1235
1260
 
1236
1261
  /**************
1237
1262
  func: exit
@@ -1249,50 +1274,27 @@ class Deva {
1249
1274
  ***************/
1250
1275
  exit(data=false) {
1251
1276
  this.state('exit');
1252
- if (!this._active) return Promise.resolve(this._messages.states.offline);
1253
1277
  this._active = false;
1254
- const _data = {
1255
- id: this.uid(),
1256
- key: 'exit',
1257
- value: 'exit',
1258
- agent: this._agent,
1259
- client: this._client || this._client,
1260
- text: this._messages.states.exit,
1261
- created: Date.now(),
1262
- }
1263
- _data.hash = this.hash(JSON.stringify(_data));
1264
- const hasOnExit = this.onExit && typeof this.onExit === 'function';
1265
- return hasOnExit ? this.onExit(_data) : Promise.resolve(_data)
1266
- }
1278
+ data.value = 'exit';
1279
+ delete data.hash;
1280
+ data.hash = this.hash(JSON.stringify(data));
1267
1281
 
1268
- /**************
1269
- func: done
1270
- params:
1271
- - msg: hte message from the caller incase need to use in calls
1272
- describe:
1273
- When the done function is triggered the system will also set the state
1274
- of hte Deva to done.
1282
+ // clear memory
1283
+ this._active = false;
1284
+ this._client = false;
1285
+ this._security = false;
1286
+ this._support = false;
1287
+ this._services = false;
1288
+ this._business = false;
1289
+ this._development = false;
1290
+ this._legal = false;
1291
+ this._story = false;
1275
1292
 
1276
- If the deva is offline it will return the offline message.
1277
- usage: this.done('msg')
1278
- ***************/
1279
- done(data=false) {
1280
- this.state('done');
1281
- if (!this._active) return Promise.resolve(this._messages.states.offline);
1282
- const _data = {
1283
- id: this.uid(),
1284
- key: 'done',
1285
- value: 'done',
1286
- agent: this._agent,
1287
- client: data.client || this._client,
1288
- text: this._messages.states.exit,
1289
- created: Date.now(),
1290
- }
1291
- _data.hash = this.hash(JSON.stringify(_data));
1292
- const hasOnDone = this.onDone && typeof this.onDone === 'function';
1293
- return hasOnDone ? this.onDone(_data) : Promise.resolve(_data)
1293
+ const hasOnExit = this.onExit && typeof this.onExit === 'function';
1294
+ return hasOnExit ? this.onExit(data) : Promise.resolve(data)
1294
1295
  }
1295
1296
 
1297
+
1296
1298
  ////////////////////////////
1297
1299
 
1298
1300
  /**************
@@ -1301,22 +1303,22 @@ class Deva {
1301
1303
  - st: The state flag to set for the Deva that matches to this._states
1302
1304
  describe
1303
1305
  ***************/
1304
- state(state, data=false) {
1306
+ state(state) {
1305
1307
  try {
1306
1308
  if (!this._states[state]) return;
1307
1309
  this._state = state;
1308
1310
  const text = this._messages.states[state];
1309
1311
  const _data = {
1310
- id: this.uid(),
1312
+ id: this.uid(true),
1311
1313
  key: 'state',
1312
1314
  value: state,
1313
- agent: this._agent,
1315
+ agent: this.agent(),
1316
+ client: this.client(),
1314
1317
  text,
1315
- data,
1316
1318
  created: Date.now(),
1317
1319
  };
1318
1320
  _data.hash = this.hash(JSON.stringify(_data));
1319
- this.talk('state', _data);
1321
+ this.talk('devacore:state', this.copy(_data));
1320
1322
  } catch (e) {
1321
1323
  return this.error(e);
1322
1324
  }
@@ -1334,7 +1336,7 @@ class Deva {
1334
1336
  this._zone = zone;
1335
1337
  const text = this._messages.zones[zone];
1336
1338
  const _data = {
1337
- id: this.uid(),
1339
+ id: this.uid(true),
1338
1340
  key: 'zone',
1339
1341
  value: zone,
1340
1342
  agent: this._agent,
@@ -1355,22 +1357,22 @@ class Deva {
1355
1357
  - st: The state flag to set for the Deva that matches to this._states
1356
1358
  describe
1357
1359
  ***************/
1358
- action(action, data=false) {
1360
+ action(action) {
1359
1361
  try {
1360
1362
  if (!this._actions[action]) return;
1361
1363
  this._action = action;
1362
1364
  const text = this._messages.actions[action];
1363
1365
  const _data = {
1364
- id: this.uid(),
1366
+ id: this.uid(true),
1365
1367
  key: 'action',
1366
1368
  value: action,
1367
- agent: this._agent,
1369
+ agent: this.agent(),
1370
+ client: this.client(),
1368
1371
  text,
1369
- data,
1370
1372
  created: Date.now(),
1371
1373
  };
1372
1374
  _data.hash = this.hash(JSON.stringify(_data));
1373
- this.talk('action', _data);
1375
+ this.talk('devacore:action', this.copy(_data));
1374
1376
  } catch (e) {
1375
1377
  return this.error(e)
1376
1378
  }
@@ -1388,7 +1390,7 @@ class Deva {
1388
1390
  this._feature = feature;
1389
1391
  const text = this._messages.features[feature] ;
1390
1392
  const _data = {
1391
- id: this.uid(),
1393
+ id: this.uid(true),
1392
1394
  key: 'feature',
1393
1395
  value: feature,
1394
1396
  agent: this._agent,
@@ -1417,7 +1419,10 @@ class Deva {
1417
1419
  client() {
1418
1420
  this.state('client_data'); // set the client state
1419
1421
  if (!this._active) return this._messages.states.offline; // check the active status
1420
- return this._client; // return the client feature
1422
+ const client_copy = this.copy(this._client);
1423
+ // delete client_copy.parse;
1424
+ // delete client_copy.translate;
1425
+ return client_copy; // return the client feature
1421
1426
  }
1422
1427
 
1423
1428
  /**************
@@ -1431,7 +1436,10 @@ class Deva {
1431
1436
  agent() {
1432
1437
  this.state('agent_data');
1433
1438
  if (!this._active) return this._messages.states.offline;
1434
- return this._agent;
1439
+ const agent_copy = this.copy(this._agent);
1440
+ delete agent_copy.parse;
1441
+ delete agent_copy.translate;
1442
+ return agent_copy;
1435
1443
  }
1436
1444
 
1437
1445
  // FEATURE FUNCTIONS
@@ -1638,7 +1646,7 @@ class Deva {
1638
1646
  try {
1639
1647
  this.state('uload');
1640
1648
  delete this.devas[key];
1641
- this.talk(`deva:unload`, {
1649
+ this.talk(`unload`, {
1642
1650
  key,
1643
1651
  created: Date.now(),
1644
1652
  });
@@ -1735,14 +1743,7 @@ class Deva {
1735
1743
  const decipher = createDecipheriv( algorithm, key_in_bytes, iv);
1736
1744
  const decrypted = decipher.update(encrypted);
1737
1745
  const final = Buffer.concat([decrypted, decipher.final()]);
1738
- this.state('decipher', {
1739
- id: this.uid(true),
1740
- iv: opt.iv,
1741
- key: opt.key,
1742
- agent_id: this._agent.id,
1743
- client_id: this._client.id,
1744
- created: Date.now()
1745
- });
1746
+ this.state('decipher');
1746
1747
  return final.toString();
1747
1748
  }
1748
1749
 
@@ -1778,13 +1779,15 @@ class Deva {
1778
1779
  usage: this.prompt('text')
1779
1780
  ***************/
1780
1781
  prompt(text) {
1781
- // console.log('PROMPT', text);
1782
1782
  // Talk a global prompt event for the client
1783
- return this.talk('prompt', {
1783
+ return this.talk('devacore:prompt', {
1784
1784
  id: this.uid(),
1785
+ key: 'return',
1786
+ value: 'prompt',
1787
+ agent: this.agent(),
1788
+ client: this.client(),
1785
1789
  text,
1786
- agent:this._agent,
1787
- created: Date.Now(),
1790
+ created: Date.now(),
1788
1791
  });
1789
1792
  }
1790
1793
 
@@ -1802,12 +1805,31 @@ class Deva {
1802
1805
  let v, key;
1803
1806
  const output = Array.isArray(obj) ? [] : {};
1804
1807
  for (key in obj) {
1805
- v = obj[key];
1806
- output[key] = (typeof v === "object") ? this.copy(v) : v;
1808
+ v = obj[key];
1809
+ output[key] = (typeof v === "object") ? this.copy(v) : v;
1807
1810
  }
1808
1811
  return output;
1809
1812
  }
1810
1813
 
1814
+ /**************
1815
+ func: getToday
1816
+ params:
1817
+ - d: The date string to get the day of..
1818
+ describe:
1819
+ a date can be passed in or generated to produce a date string for the day
1820
+ where time is 0. This feature is useful for logging for getting a date
1821
+ with no time value for the current day.
1822
+ ***************/
1823
+ getToday(d) {
1824
+ d = d ? d : Date.now();
1825
+ const today = new Date(d);
1826
+ today.setHours(0);
1827
+ today.setMinutes(0);
1828
+ today.setSeconds(0);
1829
+ today.setMilliseconds(0);
1830
+ return today.getTime();
1831
+ }
1832
+
1811
1833
  /**************
1812
1834
  func: formatDate
1813
1835
  params:
@@ -1877,5 +1899,46 @@ class Deva {
1877
1899
  return parseFloat(n).toFixed(dec) + '%';
1878
1900
  }
1879
1901
 
1902
+ /**************
1903
+ func: error
1904
+ params:
1905
+ - err: The error to process
1906
+ - data: Any additional data associated with the error
1907
+ - reject: An associated promise reject if the caller requires.
1908
+ describe:
1909
+ The erro function rpovides the consistent error manage of the system.
1910
+ usage: this.error(err, data, reject);
1911
+ ***************/
1912
+ error(err,data=false,reject=false) {
1913
+ this.state('error');
1914
+ // check fo rthe custom onError function in the agent.
1915
+ console.log('\n::BEGIN:ERROR\n');
1916
+ console.log(err);
1917
+ console.log('\n::END:ERROR\n');
1918
+ if (data) {
1919
+ console.log('::::::');
1920
+ console.log('\n::BEGIN:DATA\n');
1921
+ console.log(JSON.stringify(data, null, 2));
1922
+ console.log('\n::END:DATA\n');
1923
+ }
1924
+
1925
+ this.talk('devacore:error', {
1926
+ id: this.uid(true),
1927
+ key: 'return',
1928
+ value: 'error',
1929
+ agent: this.agent(),
1930
+ client: this.client(),
1931
+ text: err.toString(),
1932
+ data,
1933
+ created: Date.now(),
1934
+ });
1935
+
1936
+ const hasOnError = this.onError && typeof this.onError === 'function' ? true : false;
1937
+ if (hasOnError) return this.onError(err, data, reject);
1938
+ else {
1939
+ return reject ? reject(err) : err;
1940
+ }
1941
+ }
1942
+
1880
1943
  }
1881
1944
  module.exports = Deva;