@indra.ai/deva 1.2.20 → 1.2.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/config.json +140 -135
  2. package/index.js +85 -53
  3. package/package.json +1 -1
package/config.json CHANGED
@@ -30,169 +30,174 @@
30
30
  "context": false,
31
31
  "zone": "deva",
32
32
  "zones": {
33
- "init": "Initialize",
34
- "start": "Start",
35
- "stop": "Stop",
36
- "enter": "Enter",
37
- "exit": "Exit",
38
- "finish": "Finish",
39
- "done": "Done",
40
- "question": "Question",
41
- "ask": "Ask",
42
- "answer": "Answer",
43
- "deva": "Deva",
44
- "client": "Client",
45
- "agent": "Agent",
46
- "security": "Security",
47
- "support": "Support",
48
- "services": "Services",
49
- "systems": "Systems",
50
- "legal": "Legal",
51
- "business": "Business",
52
- "art": "Art",
53
- "music": "Music",
54
- "fun": "Fun",
55
- "party": "Party",
56
- "adventure": "Adventure",
57
- "cartoon": "Cartoon",
58
- "mystery": "Mystery",
59
- "fantasy": "Fantasy",
60
- "romance": "Romance",
61
- "comedy": "Comedy",
62
- "drama": "Drama",
63
- "scifi": "SciFi",
64
- "help": "Help",
65
- "error": "ERROR!"
33
+ "load": "🚛 Load",
34
+ "unload": "đŸ›ģ Unload",
35
+ "init": "🚀 Initialize",
36
+ "start": "đŸŽī¸ Start",
37
+ "stop": "🛑 Stop",
38
+ "enter": "🏡 Enter",
39
+ "exit": "đŸšĒ Exit",
40
+ "finish": "🏁 Finish",
41
+ "done": "✅ Done",
42
+ "question": "đŸ™‹â€â™‚ī¸ Question",
43
+ "ask": "đŸ“ĸ Ask",
44
+ "answer": "đŸ’â€â™‚ī¸ Answer",
45
+ "deva": "đŸ§žâ€â™‚ī¸ Deva",
46
+ "client": "👨‍đŸ’ŧ Client",
47
+ "agent": "🤖 Agent",
48
+ "security": "🔐 Security",
49
+ "support": "đŸ’ŧ Support",
50
+ "services": "đŸ› ī¸ Services",
51
+ "help": "💚 Help",
52
+ "error": "❌ ERROR!"
66
53
  },
67
54
  "state": "offline",
68
55
  "states": {
69
- "online": "Online",
70
- "offline": "Offline",
71
- "active": "Active",
72
- "inactive": "Inactive",
73
- "idle": "Idle",
74
- "talk": "Talk",
75
- "listen": "Listen",
76
- "ask": "Ask",
77
- "question": "Question",
78
- "cmd": "Command",
79
- "answer": "Answer",
80
- "ready": "Ready",
81
- "wait": "Waiting",
82
- "pause": "Pause",
83
- "resume": "Resume",
84
- "connect": "Connect",
85
- "disconnect": "Disconnect",
86
- "send": "Send",
87
- "receive": "Receive",
88
- "init": "Initialize",
89
- "forward": "Forward",
90
- "backward": "Backward",
91
- "start": "Start",
92
- "stop": "Stop",
93
- "open": "Open",
94
- "close": "Close",
95
- "enter": "Enter",
96
- "exit": "Exit",
97
- "begin": "Begin",
98
- "end": "End",
99
- "load": "Load",
100
- "unload": "Unload",
101
- "resolve": "Resolve",
102
- "reject": "Reject",
103
- "done": "Done",
104
- "data": "Data",
105
- "finish": "Finish",
106
- "complete": "Complete",
107
- "create": "Create",
108
- "destroy": "Destroy",
109
- "save": "Save",
110
- "delete": "Delete",
111
- "get": "Get",
112
- "put": "Put",
113
- "push": "Push",
114
- "pull": "Pull",
115
- "set": "Set",
116
- "response": "Response",
117
- "invalid": "INVALID!",
118
- "abort": "ABORT!",
119
- "error": "ERROR!",
120
- "help": "HELP!"
56
+ "online": "🤩 Online",
57
+ "offline": "😴 Offline",
58
+ "active": "😀 Active",
59
+ "inactive": "đŸĢĨ Inactive",
60
+ "idle": "🚘 Idle",
61
+ "talk": "đŸ“ĸ Talk",
62
+ "listen": "👂 Listen",
63
+ "ask": "đŸ—Ŗī¸ Ask",
64
+ "question": "đŸ’Ŧ Question",
65
+ "cmd": "đŸĒ– Command",
66
+ "answer": "💡 Answer",
67
+ "ready": "😊 Ready",
68
+ "wait": "âŗ Waiting",
69
+ "pause": "â¸ī¸ Pause",
70
+ "resume": "🚙 Resume",
71
+ "connect": "đŸ“ŗ Connect",
72
+ "disconnect": "📴 Disconnect",
73
+ "send": "đŸ“Ŧ Send",
74
+ "receive": "đŸ“Ē Receive",
75
+ "init": "🚀 Initialize",
76
+ "forward": "â­ī¸ Forward",
77
+ "backward": "âŽī¸ Backward",
78
+ "start": "🛝 Start",
79
+ "stop": "âšī¸ Stop",
80
+ "open": "đŸĨĢ Open",
81
+ "close": "đŸ“Ļ Close",
82
+ "enter": "🏡 Enter",
83
+ "exit": "đŸšĒ Exit",
84
+ "begin": "đŸ—ēī¸ Begin",
85
+ "end": "đŸŽŦ End",
86
+ "load": "🚚 Load",
87
+ "unload": "đŸ›ģ Unload",
88
+ "resolve": "đŸ”Ŧ Resolve",
89
+ "reject": "🧱 Reject",
90
+ "done": "✅ Done",
91
+ "data": "📡 Data",
92
+ "finish": "🏁 Finish",
93
+ "complete": "âŒ›ī¸ Complete",
94
+ "create": "🎨 Create",
95
+ "destroy": "đŸ’Ŗ Destroy",
96
+ "write": "📝 Write",
97
+ "save": "💾 Save",
98
+ "delete": "🧨 Delete",
99
+ "set": "🖖 Set",
100
+ "get": "👍 Get",
101
+ "put": "🤝 Put",
102
+ "push": "đŸĢ¸ Push",
103
+ "pull": "👉 Pull",
104
+ "search": "🔎 Search",
105
+ "memory": "💭 Memory",
106
+ "response": "âœī¸ Response",
107
+ "invalid": "👎 INVALID!",
108
+ "abort": "💔 ABORT!",
109
+ "error": "❌ ERROR!",
110
+ "help": "💙 Help"
121
111
  },
122
112
  "action": false,
123
113
  "actions": {
124
- "client": "get Client",
125
- "agent": "get Agent",
126
- "wait": "Waiting",
127
- "start": "Start",
128
- "enter": "Enter",
129
- "exit": "Exit",
130
- "stop": "Stop",
131
- "load": "Load",
132
- "unload": "Unload",
133
- "done": "Done",
134
- "question": "Question",
114
+ "client": "👨‍đŸ’ŧ Client",
115
+ "agent": "đŸ•ĩī¸â€â™‚ī¸ Agent",
116
+ "wait": "âŗ Waiting",
117
+ "start": "đŸŽŦ Start",
118
+ "enter": "🏡 Enter",
119
+ "exit": "đŸšĒ Exit",
120
+ "stop": "🛑 Stop",
121
+ "load": "đŸ“Ļ Load",
122
+ "unload": "đŸĨĄ Unload",
123
+ "done": "✅ Done",
124
+ "question": "🙋 Question",
135
125
  "context": "Context",
136
- "prompt": "Prompt",
137
- "issue": "Issue",
138
- "find": "Find",
139
- "parse": "Parse",
140
- "view": "View",
141
- "insert": "Insert",
142
- "update": "Update",
143
- "delete": "Delete",
144
- "info": "Information",
145
- "status": "Status",
146
- "func": "Function",
147
- "list": "List items",
148
- "reply": "Reply",
149
- "set": "Set",
150
- "get": "Get",
151
- "return": "Return",
126
+ "prompt": "🐚 Prompt",
127
+ "issue": "đŸŽĢ Issue",
128
+ "find": "🔎 Find",
129
+ "parse": "đŸ˜ī¸ Parse",
130
+ "view": "👓 View",
131
+ "insert": "👉 Insert",
132
+ "update": "👆 Update",
133
+ "delete": "đŸ—‘ī¸ Delete",
134
+ "info": "đŸ’â€â™‚ī¸ Information",
135
+ "status": "đŸšĨ Status",
136
+ "func": "đŸ”Ļ Function",
137
+ "method": "âšĄī¸ Method",
138
+ "list": "📋 List items",
139
+ "reply": "📮 Reply",
140
+ "write": "ī¸đŸ“ Write",
141
+ "set": "đŸŊī¸ Set",
142
+ "get": "🤔 Get",
143
+ "return": "🎁 Return",
144
+ "resolve": "â›ĩī¸ Resolve",
145
+ "reject": "❌ Reject",
152
146
 
153
- "question_ask": "Ask question",
154
- "question_ask_answer": "Answer question asked",
155
- "question_cmd": "Question command",
156
- "question_method": "Question method",
157
- "question_talk": "Question talk",
158
- "question_answer": "Answer question",
159
- "question_done": "Question done",
147
+ "question_ask": "đŸ—Ŗī¸ Asked",
148
+ "question_ask_answer": "đŸŽ™ī¸ Answered",
149
+ "question_cmd": "đŸĒ– Command",
150
+ "question_answer": "📞 Answer",
160
151
 
161
- "answer": "Answer",
162
- "ask": "Ask",
152
+ "answer": "💡 Answer",
153
+ "ask": "đŸ“Ŗ Ask",
163
154
 
164
155
  "security": "Get Security",
165
156
  "support": "Get Support",
166
157
  "services": "Get Services",
167
158
 
168
- "Client": "Set client",
159
+ "Client": "Set Client",
169
160
  "Security": "Set Security",
170
161
  "Support": "Set Support",
171
162
  "Systems": "Set Systems",
172
163
  "Services": "Set Services",
173
- "Done": "Done",
164
+ "Done": "✅ Done",
174
165
 
175
- "invalid": "Invalid",
176
- "states": "States",
177
- "actions": "Actions",
166
+ "invalid": "❌ Invalid",
167
+ "states": "đŸ›ģ States",
168
+ "actions": "đŸŽī¸ Actions",
178
169
  "zones": "Zones",
179
- "features": "Getting features",
180
- "contexts": "Getting contexts",
181
- "finish": "Finished action",
182
- "help": "Giving some HELP!",
183
- "error": "ERROR!"
170
+ "feature": "đŸŽĨ Feature",
171
+ "features": "đŸŽĨ Getting features",
172
+ "contexts": "🌈 Getting contexts",
173
+ "finish": "🏁 Finish",
174
+ "help": "💜 Help",
175
+ "error": "🔴 ERROR!"
184
176
  },
185
177
  "feature": false,
186
178
  "features": {
187
- "security": "Security",
188
- "support": "Support",
189
- "services": "Services",
190
- "systems": "Systems"
179
+ "security": "🔐 Security",
180
+ "support": "đŸ’ŧ Support",
181
+ "services": "đŸ› ī¸ Services",
182
+ "cipher": "🔒 Cipher",
183
+ "decipher": "🔓 Decipher",
184
+ "promp": "đŸĒĩ Prompt",
185
+ "getToday": "📆 Get Today",
186
+ "formatDate": "📅 Date",
187
+ "formatTime": "đŸ•°ī¸ Time",
188
+ "formatCurrency": "💰 Currency",
189
+ "formatPercent": "đŸ’¯ Percent",
190
+ "trimWords": "🙊 Trim Words",
191
+ "dupes": "📋 Duplicates",
192
+ "info": "đŸ’â€â™‚ī¸ Info",
193
+ "status": "â¤ī¸ Status",
194
+ "help": "🌈 Help"
191
195
  },
192
196
  "message": "offline",
193
197
  "messages": {
194
198
  "init": "Initializing Deva",
195
199
  "offline": "The Deva is OFFLINE.",
200
+ "noid": "NO ID WAS PROVIDED",
196
201
  "notext": "NO TEXT WAS PROVIDED",
197
202
  "nopacket": "NO PACKET WAS PROVIDED",
198
203
  "method_not_found": "METHOD NOT FOUND",
package/index.js CHANGED
@@ -319,7 +319,6 @@ class Deva {
319
319
  try {
320
320
  delete this._client.features; // delete the features key when done.
321
321
  this.state('ready');
322
- this.action('wait');
323
322
  return resolve(client); // resolve an empty pr
324
323
  } catch (e) {
325
324
  return this.error(e, false, reject);
@@ -392,6 +391,7 @@ class Deva {
392
391
  this.zone('question'); // set the zone to question.
393
392
  const id = this.uid(); // generate a unique id for transport.
394
393
  const t_split = TEXT.split(' '); // split the text on spaces to get words.
394
+ const data = DATA; // set the DATA to data
395
395
 
396
396
  // check to see if the string is an #ask string to talk to the other Deva.
397
397
  const isAsk = t_split[0].startsWith(this.askChr);
@@ -400,7 +400,6 @@ class Deva {
400
400
  const isCmd = t_split[0].startsWith(this.cmdChr);
401
401
 
402
402
  // Format the packet for return on the request.
403
- const data = DATA; // set the DATA to data
404
403
  const packet = { // create the base q/a packet
405
404
  id, // set the id into packet
406
405
  q: false, // create empty q object in packet
@@ -420,7 +419,6 @@ class Deva {
420
419
  this.state('question'); // set the state to question
421
420
  try { // try to answer the question
422
421
  if (isAsk) { // determine if hte question isAsk
423
- this.state('ask');
424
422
  _action = 'question_ask';
425
423
  // if:isAsk split the agent key and remove first command character
426
424
  key = t_split[0].substring(1);
@@ -428,17 +426,17 @@ class Deva {
428
426
  params = t_split[1] ? t_split[1].split(':') : false;
429
427
  method = params[0]; // the method to check is then params index 0
430
428
  text = t_split.slice(2).join(' ').trim(); // rejoin the text with space
429
+ this.state('ask', `${key} ${method}`);
431
430
  }
432
431
  else if (isCmd) { // determine if the question is a command
433
- this.state('cmd'); // set the state to cmd.
434
432
  _action = 'question_cmd';
435
433
  //if:isCmd use text split index 1 as the parameter block
436
434
  params = t_split[0] ? t_split[0].split(':').slice(1) : false;
437
435
  method = t_split[0].substring(1); // if:isCmd use the 0 index as the command
438
436
  text = t_split.slice(1).join(' ').trim(); // if:isCmd rejoin the string on the space after removing first index
437
+ this.state('cmd', method); // set the state to cmd.
439
438
  }
440
439
 
441
- this.state('data');
442
440
  packet.q = { // build packet.q container
443
441
  id: this.uid(), // set the transport id for the question.
444
442
  agent: this.agent(), // set the agent
@@ -456,7 +454,7 @@ class Deva {
456
454
  // hash the question
457
455
  packet.q.meta.hash = this.hash(packet.q);
458
456
 
459
- this.action(_action); // set current action to what was defined by _action variable.
457
+ this.action(_action, method); // set current action to what was defined by _action variable.
460
458
  this.talk(config.events.question, this.copy(packet)); // global question event make sure to copy data.
461
459
 
462
460
  if (isAsk) { // isAsk check if the question isAsk and talk
@@ -469,7 +467,7 @@ class Deva {
469
467
  });
470
468
  }
471
469
  else { // else: answer tue question locally
472
- this.action('question_answer');
470
+ this.action('question_answer', method);
473
471
  return this.answer(packet, resolve, reject);
474
472
  }
475
473
  }
@@ -502,7 +500,7 @@ class Deva {
502
500
  }
503
501
  // Call the local method to process the question based the extracted parameters
504
502
  return this.methods[method](packet).then(result => {
505
- this.state('answer');
503
+ this.action('answer', method); // set the action to answer
506
504
  // check the result for the text, html, and data object.
507
505
  // this is for when answers are returned from nested Devas.
508
506
  const text = typeof result === 'object' ? result.text : result;
@@ -525,10 +523,10 @@ class Deva {
525
523
  created: Date.now(), // set the created date for the answer
526
524
  };
527
525
 
526
+ this.state('answer', method);
528
527
  // create a hash for the answer and insert into answer meta.
529
528
  packet_answer.meta.hash = this.hash(packet_answer);
530
529
  packet.a = packet_answer; // set the packet.a to the packet_answer
531
- this.action('answer'); // set the action to answer
532
530
  this.talk(config.events.answer, this.copy(packet)); // global talk event
533
531
  return this.finish(packet, resolve); // resolve the packet to the caller.
534
532
  }).catch(err => { // catch any errors in the method
@@ -553,8 +551,8 @@ class Deva {
553
551
  ***************/
554
552
  ask(packet) {
555
553
  if (!this._active) return Promise.resolve(this._messages.offline);
556
-
557
- this.zone('ask');
554
+ const {method, params} = packet.q.meta;
555
+ this.zone('ask', method);
558
556
 
559
557
  const agent = this.agent();
560
558
  const client = this.client();
@@ -565,8 +563,8 @@ class Deva {
565
563
  client,
566
564
  meta: {
567
565
  key: agent.key,
568
- method: packet.q.meta.method,
569
- params: packet.q.meta.params,
566
+ method,
567
+ params,
570
568
  },
571
569
  text: false,
572
570
  html: false,
@@ -574,18 +572,18 @@ class Deva {
574
572
  created: Date.now(),
575
573
  };
576
574
 
575
+ this.action('ask', method);
577
576
  try {
578
- if (typeof this.methods[packet.q.meta.method] !== 'function') {
577
+ if (typeof this.methods[method] !== 'function') {
579
578
  return setImmediate(() => {
580
- this.action('invalid');
579
+ this.action('invalid', method);
581
580
  this.talk(`${this._agent.key}:ask:${packet.id}`, this._methodNotFound(packet));
582
581
  });
583
582
  }
584
583
 
585
- this.state('ask');
586
584
  // The method is parsed and depending on what method is asked for it returns
587
585
  // the response based on the passed through packet.
588
- this.methods[packet.q.meta.method](packet).then(result => {
586
+ this.methods[method](packet).then(result => {
589
587
  if (typeof result === 'object') {
590
588
  packet_answer.text = result.text || false;
591
589
  packet_answer.html = result.html || false;
@@ -594,8 +592,9 @@ class Deva {
594
592
  else {
595
593
  packet_answer.text = result;
596
594
  }
595
+
596
+ this.state('ask', method);
597
597
  packet_answer.meta.hash = this.hash(packet_answer);
598
- this.action('ask');
599
598
  packet.a = packet_answer;
600
599
  this.talk(config.events.answer, this.copy(packet)); // global talk event
601
600
  this.talk(`${agent.key}:ask:${packet.id}`, packet);
@@ -631,6 +630,7 @@ class Deva {
631
630
  // set client
632
631
  this._active = Date.now();
633
632
  const agent = this.agent();
633
+
634
634
  const _data = {
635
635
  id: this.uid(true),
636
636
  key: 'init',
@@ -655,7 +655,9 @@ class Deva {
655
655
  }).then(() => {
656
656
  this.zone('init');
657
657
  const hasOnInit = this.onInit && typeof this.onInit === 'function';
658
- return hasOnInit ? this.onInit(_data) : this.start(_data)
658
+ return hasOnInit ? this.onInit(_data) : this.start(_data);
659
+ }).then(done => {
660
+ return resolve(done);
659
661
  }).catch(err => {
660
662
  return this.error(err, client, reject);
661
663
  });
@@ -675,12 +677,12 @@ class Deva {
675
677
  start(data) {
676
678
  this.zone('start');
677
679
  if (!this._active) return Promise.resolve(this._messages.offline);
678
- this.state('start');
680
+ this.action('start');
679
681
  data.value = 'start';
680
682
  delete data.hash;
681
683
  data.hash = this.hash(data);
682
684
  const hasOnStart = this.onStart && typeof this.onStart === 'function' ? true : false;
683
- this.action('start');
685
+ this.state('start');
684
686
  return hasOnStart ? this.onStart(data) : this.enter(data)
685
687
  }
686
688
 
@@ -698,11 +700,11 @@ class Deva {
698
700
  enter(data) {
699
701
  this.zone('enter');
700
702
  if (!this._active) return Promise.resolve(this._messages.offline);
701
- this.state('enter');
703
+ this.action('enter');
702
704
  data.value = 'enter';
703
705
  delete data.hash;
704
706
  data.hash = this.hash(data);
705
- this.action('enter');
707
+ this.state('enter');
706
708
  const hasOnEnter = this.onEnter && typeof this.onEnter === 'function' ? true : false;
707
709
  return hasOnEnter ? this.onEnter(data) : this.done(data)
708
710
  }
@@ -721,12 +723,12 @@ class Deva {
721
723
  done(data) {
722
724
  this.zone('done');
723
725
  if (!this._active) return Promise.resolve(this._messages.offline);
724
- this.state('done');
726
+ this.action('done');
725
727
  data.value = 'done';
726
728
  delete data.hash;
727
729
  data.hash = this.hash(data);
728
730
  const hasOnDone = this.onDone && typeof this.onDone === 'function' ? true : false;
729
- this.action('done')
731
+ this.state('done');
730
732
  return hasOnDone ? this.onDone(data) : Promise.resolve(data);
731
733
  }
732
734
 
@@ -751,7 +753,6 @@ class Deva {
751
753
  this.action('finish'); // set the finish action
752
754
  // if: agent has on finish then return on finish
753
755
 
754
- this.context('finish'); // set the context to finish
755
756
  if (hasOnFinish) return this.onFinish(packet, resolve);
756
757
  // return the provided resolve function or a promise resolve.
757
758
  return resolve ? resolve(packet) : Promise.resolve(packet);
@@ -807,10 +808,10 @@ class Deva {
807
808
  exit() {
808
809
  this.zone('exit');
809
810
 
810
- this.state('exit');
811
811
  const agent = this.agent();
812
812
  const client = this.client();
813
813
 
814
+ this.action('exit');
814
815
  const data = {
815
816
  id: this.uid(true),
816
817
  key: 'exit',
@@ -828,7 +829,7 @@ class Deva {
828
829
  this._support = false;
829
830
  this._services = false;
830
831
 
831
- this.action('exit');
832
+ this.state('exit');
832
833
  const hasOnExit = this.onExit && typeof this.onExit === 'function';
833
834
  return hasOnExit ? this.onExit(data) : Promise.resolve(data)
834
835
  }
@@ -870,7 +871,8 @@ class Deva {
870
871
  describe: returns the avaiable staets values.
871
872
  ***************/
872
873
  states() {
873
- this.action('states');
874
+ this.action('func', 'states');
875
+ this.state('return', 'states');
874
876
  return {
875
877
  id: this.uid(true),
876
878
  key: 'states',
@@ -915,7 +917,8 @@ class Deva {
915
917
  describe: returns a listing of zones currently in the system.
916
918
  ***************/
917
919
  zones() {
918
- this.action('zones'); // set the action to zones
920
+ this.action('func', 'zones');
921
+ this.state('return', 'zones');
919
922
  return {
920
923
  id: this.uid(true), // set the uuid of the data
921
924
  agent: this.agent(), // set the agent value
@@ -965,7 +968,8 @@ class Deva {
965
968
  describe: Returns a list of available actions in the system.
966
969
  ***************/
967
970
  actions() {
968
- this.action('actions');
971
+ this.action('func', 'actions');
972
+ this.state('return', 'actions');
969
973
  return {
970
974
  id: this.uid(true), // set the id with a uuid
971
975
  agent: this.agent(), // set the agent value
@@ -1012,7 +1016,8 @@ class Deva {
1012
1016
  describe: return a list of features that are available to the system.
1013
1017
  ***************/
1014
1018
  features() {
1015
- this.action('features'); // set the action to features
1019
+ this.action('func', 'features');
1020
+ this.state('return', 'features');
1016
1021
  return { // return the data object
1017
1022
  id: this.uid(true), // set the object id
1018
1023
  agent: this.agent(), // set the agent value.
@@ -1046,6 +1051,7 @@ class Deva {
1046
1051
  text,
1047
1052
  created: Date.now(),
1048
1053
  };
1054
+
1049
1055
  data.hash = this.hash(data);
1050
1056
  this.talk(config.events.context, data);
1051
1057
  } catch (e) {
@@ -1054,7 +1060,8 @@ class Deva {
1054
1060
  }
1055
1061
 
1056
1062
  contexts() {
1057
- this.action('contexts');
1063
+ this.action('func', 'contexts');
1064
+ this.state('return', 'contexts');
1058
1065
  return {
1059
1066
  id: this.uid(true),
1060
1067
  agent: this.agent(),
@@ -1097,11 +1104,12 @@ class Deva {
1097
1104
  usage: this.security()
1098
1105
  ***************/
1099
1106
  security() {
1107
+ this.zone('security');
1100
1108
  this.feature('security'); // set the security state
1101
1109
  if (!this._active) return this._messages.offline; // check the active status
1102
- this.state('data'); // set the security state
1110
+ this.action('feature', 'security'); // set the security state
1103
1111
  try {
1104
- this.action('security'); // set the security state
1112
+ this.state('return', 'security'); // set the security state
1105
1113
  return this.copy(this._security); // return the security feature
1106
1114
  } catch (e) {return this.error(e);}
1107
1115
  }
@@ -1113,11 +1121,12 @@ class Deva {
1113
1121
  usage: this.support()
1114
1122
  ***************/
1115
1123
  support() {
1124
+ this.zone('support');
1116
1125
  this.feature('support'); // set the support state
1117
1126
  if (!this._active) return this._messages.offline; // check the active status
1118
- this.state('data'); // set the state to data
1127
+ this.action('feature', 'support'); // set the state to data
1119
1128
  try {
1120
- this.action('support'); // set the action to support.
1129
+ this.state('return', 'support'); // set the action to support.
1121
1130
  return this.copy(this._support); // return the support feature
1122
1131
  } catch (e) {
1123
1132
  return this.error(e); // return this.error when error catch
@@ -1131,11 +1140,12 @@ class Deva {
1131
1140
  usage: this.services()
1132
1141
  ***************/
1133
1142
  services(opts) {
1143
+ this.zone('services');
1134
1144
  this.feature('services'); // set the support state
1135
1145
  if (!this._active) return this._messages.offline; // check the active status
1136
- this.state('data'); // set the services state
1146
+ this.action('feature', 'services'); // set the services state
1137
1147
  try {
1138
- this.action('services'); // set the services state
1148
+ this.state('return', 'services'); // set the services state
1139
1149
  return this.copy(this._services); // return the services feature
1140
1150
  } catch (e) {
1141
1151
  return this.error(e); // return this.error when error catch
@@ -1149,7 +1159,9 @@ class Deva {
1149
1159
  describe: This function will enable fast loading of Deva into the system.
1150
1160
  ***************/
1151
1161
  load(key, client) {
1152
- this.state('load');
1162
+ this.zone('load', key);
1163
+ this.action('load', key);
1164
+ this.state('load', key);
1153
1165
  return this.devas[key].init(client);
1154
1166
  }
1155
1167
 
@@ -1160,13 +1172,15 @@ class Deva {
1160
1172
  describe: Unload a currently loaded Deva.
1161
1173
  ***************/
1162
1174
  unload(key) {
1175
+ this.zone('unload', key);
1163
1176
  return new Promise((resolve, reject) => {
1164
1177
  try {
1165
- this.state('uload');
1178
+ this.action('uload', key);
1166
1179
  this.devas[key].stop().then(exit => {
1167
1180
  delete this.devas[key];
1168
1181
  this.talk(config.events.unload, key);
1169
1182
  });
1183
+ this.state('unload', key)
1170
1184
  return resolve(this._states.unload);
1171
1185
  } catch (e) {
1172
1186
  return this.error(e, this.devas[key], reject)
@@ -1227,6 +1241,7 @@ class Deva {
1227
1241
  defined client security settings.
1228
1242
  ***************/
1229
1243
  cipher(str) {
1244
+ this.feature('cipher');
1230
1245
  // this.action('cipher');
1231
1246
  const security = this._security;
1232
1247
  const {password, algorithm} = security.cipher;
@@ -1237,6 +1252,7 @@ class Deva {
1237
1252
  const _cipher = createCipheriv(algorithm, key_in_bytes, iv);
1238
1253
  const encrypted = _cipher.update(String(str), 'utf8', 'hex') + _cipher.final('hex');
1239
1254
 
1255
+ this.state('return', 'cipher');
1240
1256
  return {
1241
1257
  iv: iv.toString('base64'),
1242
1258
  key,
@@ -1245,6 +1261,7 @@ class Deva {
1245
1261
  }
1246
1262
 
1247
1263
  decipher(opt) {
1264
+ this.feature('decipher');
1248
1265
  // this.action('decipher');
1249
1266
  const iv = Buffer.from(opt.iv, 'base64');
1250
1267
  const encrypted = Buffer.from(opt.encrypted, 'hex');
@@ -1255,6 +1272,7 @@ class Deva {
1255
1272
  const decrypted = decipher.update(encrypted);
1256
1273
  const final = Buffer.concat([decrypted, decipher.final()]);
1257
1274
  return final.toString();
1275
+ this.state('return', 'decipher');
1258
1276
  }
1259
1277
 
1260
1278
  /**************
@@ -1267,7 +1285,7 @@ class Deva {
1267
1285
  usage: this.prompt('text')
1268
1286
  ***************/
1269
1287
  prompt(text) {
1270
- this.action('prompt');
1288
+ this.feature('prompt');
1271
1289
  // Talk a global prompt event for the client
1272
1290
  const agent = this.agent();
1273
1291
  const client = this.client();
@@ -1280,6 +1298,7 @@ class Deva {
1280
1298
  text,
1281
1299
  created: Date.now(),
1282
1300
  }
1301
+ this.state('talk', 'prompt')
1283
1302
  return this.talk(config.events.prompt, _data);
1284
1303
  }
1285
1304
 
@@ -1307,13 +1326,14 @@ class Deva {
1307
1326
  with no time value for the current day.
1308
1327
  ***************/
1309
1328
  getToday(d) {
1310
- this.action('gettoday');
1329
+ this.feature('getToday');
1311
1330
  d = d ? d : Date.now();
1312
1331
  const today = new Date(d);
1313
1332
  today.setHours(0);
1314
1333
  today.setMinutes(0);
1315
1334
  today.setSeconds(0);
1316
1335
  today.setMilliseconds(0);
1336
+ this.state('return', 'getToday');
1317
1337
  return today.getTime();
1318
1338
  }
1319
1339
 
@@ -1330,6 +1350,7 @@ class Deva {
1330
1350
  system based on the language and locale in the client profile.
1331
1351
  ***************/
1332
1352
  formatDate(d, format='milli', time=false) {
1353
+ this.feature('formatDate');
1333
1354
  if (!d) d = Date.now();
1334
1355
  d = new Date(d);
1335
1356
 
@@ -1348,6 +1369,7 @@ class Deva {
1348
1369
  };
1349
1370
  const theDate = d.toLocaleDateString(this._client.locale, formats[format]);
1350
1371
  const theTime = this.formatTime(d);
1372
+ this.state('return', 'formatDate');
1351
1373
  return !theTime ? theDate : `${theDate} - ${theTime}`;
1352
1374
  }
1353
1375
 
@@ -1360,6 +1382,7 @@ class Deva {
1360
1382
  parameter based on the locale setting in the client profile..
1361
1383
  ***************/
1362
1384
  formatTime(t) {
1385
+ this.feature('formatTime');
1363
1386
  return t.toLocaleTimeString(this._client.locale); // return the formatted time string
1364
1387
  }
1365
1388
 
@@ -1372,6 +1395,7 @@ class Deva {
1372
1395
  in the client profile.
1373
1396
  ***************/
1374
1397
  formatCurrency(n) {
1398
+ this.feature('formatCurrency');
1375
1399
  return new Intl.NumberFormat(this._client.locale, { style: 'currency', currency: this._client.currency }).format(n);
1376
1400
  }
1377
1401
 
@@ -1383,6 +1407,7 @@ class Deva {
1383
1407
  describe:
1384
1408
  ***************/
1385
1409
  formatPercent(n, dec=2) {
1410
+ this.feature('formatPercent');
1386
1411
  return parseFloat(n).toFixed(dec) + '%';
1387
1412
  }
1388
1413
 
@@ -1395,8 +1420,10 @@ class Deva {
1395
1420
  A utility function to trimText intput to a specific word count.
1396
1421
  ***************/
1397
1422
  trimWords(text, maxwords) {
1423
+ this.feature('trimWords');
1398
1424
  const splitter = text.split(' ');
1399
1425
  if (splitter < maxwords) return text;
1426
+ this.state('return', 'trimmed words');
1400
1427
  return splitter.slice(0, maxwords).join(' ');
1401
1428
  }
1402
1429
 
@@ -1406,9 +1433,10 @@ class Deva {
1406
1433
  describe: remove duplicees from an array.
1407
1434
  ***************/
1408
1435
  dupes(dupers) {
1409
- this.action('dupes');
1436
+ this.feature('dupes');
1410
1437
  if (!Array.isArray(dupers)) return dupers;
1411
1438
  const check = [];
1439
+ this.state('return', 'duplicates removed');
1412
1440
  return dupers.filter(dupe => {
1413
1441
  if (!check.includes(dupe)) {
1414
1442
  check.push(dupe);
@@ -1425,7 +1453,7 @@ class Deva {
1425
1453
  info() {
1426
1454
  // check the active status
1427
1455
  if (!this._active) return Promise.resolve(this._messages.offline);
1428
- this.action('info');
1456
+ this.feature('info');
1429
1457
  return this._info;
1430
1458
  }
1431
1459
 
@@ -1442,11 +1470,12 @@ class Deva {
1442
1470
  ***************/
1443
1471
  status(msg=false) {
1444
1472
  // check the active status
1445
- if (!this._active) return Promise.resolve(this._messages.states.offline);
1473
+ if (!this._active) return Promise.resolve(this._messages.offline);
1474
+ this.feature('status');
1475
+
1446
1476
  // format the date since active for output.
1447
1477
  const dateFormat = this.formatDate(this._active, 'long', true);
1448
1478
  // create the text msg string
1449
- this.action('status');
1450
1479
  let text = `${this._agent.profile.name} active since ${dateFormat}`;
1451
1480
  if (msg) text = text + `\n${msg}`; // append the msg string if msg true.
1452
1481
  return text; // return final text string
@@ -1463,19 +1492,21 @@ class Deva {
1463
1492
  one exists it will then present it based on the users request text input.
1464
1493
  ***************/
1465
1494
  help(msg, help_dir) {
1466
- this.zone('help');
1467
1495
  return new Promise((resolve, reject) => {
1468
- if (!this._active) return resolve(this._messages.states.offline);
1469
- this.state('data');
1496
+ if (!this._active) return resolve(this._messages.offline);
1497
+ this.feature('help');
1498
+ this.zone('help');
1499
+
1470
1500
  const params = msg.split(' ');
1471
1501
  let helpFile = 'main';
1472
1502
  if (params[0]) helpFile = params[0];
1473
1503
  if (params[1]) helpFile = `${params[0]}_${params[1]}`;
1474
1504
  helpFile = path.join(help_dir, 'help', `${helpFile}.feecting`);
1475
1505
  try {
1476
- this.action('help');
1506
+ this.state('resolve', 'help');
1477
1507
  return resolve(fs.readFileSync(helpFile, 'utf8'));
1478
1508
  } catch (e) {
1509
+ this.state('reject', 'helpFile');
1479
1510
  return reject(e)
1480
1511
  }
1481
1512
  });
@@ -1494,7 +1525,7 @@ class Deva {
1494
1525
  error(err,data=false,reject=false) {
1495
1526
  this.zone('error');
1496
1527
 
1497
- this.state('error')
1528
+ this.action('error')
1498
1529
  const agent = this.agent();
1499
1530
  const client = this.client();
1500
1531
  const _data = {
@@ -1509,7 +1540,8 @@ class Deva {
1509
1540
  }
1510
1541
  this.talk(config.events.error, this.copy(_data));
1511
1542
  const hasOnError = this.onError && typeof this.onError === 'function' ? true : false;
1512
- this.action('error');
1543
+
1544
+ this.state('error');
1513
1545
  if (hasOnError) return this.onError(err, data, reject);
1514
1546
  else return reject ? reject(err) : err;
1515
1547
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.2.20",
3
+ "version": "1.2.21",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "scripts": {