@indra.ai/deva 1.1.26 → 1.1.27

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.
@@ -25,16 +25,28 @@
25
25
  }
26
26
  },
27
27
  "profile": {
28
- "emoji": "https://quinnmichaels.com/assets/img/quinn/avatar.png",
29
- "avatar": "https://quinnmichaels.com/assets/img/quinn/avatar.png",
30
- "background": "https://quinnmichaels.com/assets/img/quinn/background.png",
28
+ "emoji": "/public/devas/test/avatar.png",
29
+ "avatar": "/public/devas/test/avatar.png",
30
+ "background": "/public/devas/test/background.png",
31
31
  "name": "Test User",
32
- "describe": "This is the Test user for the Deva Examples in the Repository.",
32
+ "describe": "This is the Test for the Deva Examples in the Repository.",
33
33
  "gender": "splendid",
34
- "lang": "en"
34
+ "lang": "en",
35
+ "locale": "en-US",
36
+ "currency": "USD"
35
37
  },
36
38
  "states": {},
37
39
  "messages": {},
40
+ "security": {
41
+ "concerns": [],
42
+ "global": {},
43
+ "devas": {}
44
+ },
45
+ "support": {
46
+ "concerns": [],
47
+ "global": {},
48
+ "devas": {}
49
+ },
38
50
  "services": {
39
51
  "concerns": [],
40
52
  "global": {
@@ -45,12 +57,17 @@
45
57
  },
46
58
  "devas": {}
47
59
  },
48
- "security": {
60
+ "systems": {
49
61
  "concerns": [],
50
62
  "global": {},
51
63
  "devas": {}
52
64
  },
53
- "support": {
65
+ "solutions": {
66
+ "concerns": [],
67
+ "global": {},
68
+ "devas": {}
69
+ },
70
+ "development": {
54
71
  "concerns": [],
55
72
  "global": {},
56
73
  "devas": {}
@@ -75,7 +75,8 @@ HelloWorld.init(client.DATA).then(done => {
75
75
  // console.log(done);
76
76
  return HelloWorld.question('/state')
77
77
  }).then(answer => {
78
- console.log('THE ANSWER: ', answer.a.text);
78
+ // console.log(HelloWorld.client());
79
+ console.log(answer.a.text);
79
80
  });
80
81
 
81
82
 
package/index.js CHANGED
@@ -55,28 +55,28 @@ class Deva {
55
55
  enter: `🎪 ${this._agent.name} is entering the deva.world`,
56
56
  stop: `🛑 ${this._agent.name} has stopped`,
57
57
  exit: `🚪 ${this._agent.name} found the exit`,
58
- done: `🤝 ${this._agent.name} is all done`,
59
- wait: `😵‍💫 ${this._agent.name} waiting for something to do`,
60
- data: `📀 ${this._agent.name} is receiving data`,
61
- ask: `🙋‍♀️ ${this._agent.name} is asking a question`,
62
- cmd: `📟 ${this._agent.name} is using a command`,
63
- question: `🐵 ${this._agent.name} question`,
64
- ask: `🐵 ${this._agent.name} asking`,
65
- talk: `🎙️ ${this._agent.name} is talking`,
66
- listen: `🎧 ${this._agent.name} is listening`,
67
- error: `❌ ${this._agent.name} had an error`,
68
- story: `📓 ${this._agent.name} telling a story`,
69
- development: `👨‍💻 ${this._agent.name} needs @Development`,
70
- security: `🚨 ${this._agent.name} needs @Security`,
71
- support: `🎗️ ${this._agent.name} needs @Support`,
72
- services: `🎖️ ${this._agent.name} needs @Services`,
73
- systems: `👽 ${this._agent.name} needs @Systems`,
74
- solutions: `🔬 ${this._agent.name} needs @Solutions`,
75
- devas_start: `✨ Starting all the #Devas...`,
76
- devas_ready: `📸 The #Devas are ready and waiitng`,
77
- devas_stop: `🙈 The #Devas are stopping`,
78
- devas_stopped: `🛑 #Devas have stopped`,
79
- deva_load: `✅ ${this._agent.name} load`,
58
+ done: `🤝 ${this._agent.name} is all done time for #offerings 🍫🍌`,
59
+ wait: `😵‍💫 ${this._agent.name} waiting for #stuff`,
60
+ data: `📀 ${this._agent.name} is receiving #data`,
61
+ ask: `🙋‍♀️ ${this._agent.name} is asking a #question`,
62
+ cmd: `📟 ${this._agent.name} is using a #command`,
63
+ question: `🐵 ${this._agent.name} is in #question mode`,
64
+ ask: `🐵 ${this._agent.name} is in #ask mode`,
65
+ talk: `🎙️ ${this._agent.name} is in #talk mode`,
66
+ listen: `🎧 ${this._agent.name} is in #listening mode`,
67
+ error: `❌ Looks like ${this._agent.name} had an error. Let's have @Systems look into that.`,
68
+ story: `📓 ${this._agent.name} is creating an amazing #story`,
69
+ development: `👨‍💻 ${this._agent.name} called for @Development assistance`,
70
+ security: `🚨 ${this._agent.name} called for @Security assistance`,
71
+ support: `🎗️ ${this._agent.name} called for @Support assistance`,
72
+ services: `🎖️ ${this._agent.name} called for @Services assistance`,
73
+ systems: `👽 ${this._agent.name} called for @Systems assistance`,
74
+ solutions: `🔬 ${this._agent.name} called for @Solutions assistance`,
75
+ devas_start: `✨ Starting all the #Devas`,
76
+ devas_ready: `📸 The #Devas are #ready and #waiitng`,
77
+ devas_stop: `🙈 The #Devas are #stopping`,
78
+ devas_stopped: `🛑 #Devas have #stopped, and that means time for #offerings 🍎🍑🍍🧋`,
79
+ deva_load: `✅ ${this._agent.name} loading`,
80
80
  deva_loaded: `✅ ${this._agent.name} loaded`,
81
81
  deva_unloaded: `✅ ${this._agent.name} unloaded`,
82
82
  question_me: `🐵 ${this._client.name} ask ${this._agent.name} a #question`,
@@ -84,24 +84,32 @@ class Deva {
84
84
  question_ask: `🧞 ${this._agent.name} is pondering what ${this._client.name} asked`,
85
85
  question_asking: `🧞 ${this._agent.name} is asking another #Deva what ${this._client.name} asked`,
86
86
  question_aswering: `🧞 ${this._agent.name} is answering the #question ${this._client.name} asked`,
87
- question_answer: `🔮 #${this._agent.name} gave #${this._client.name} the answer`,
88
- question_cmd: `🧞‍♀️ ${this._agent.name} then ran a #command for #${this._client.name}`,
89
- hash_question: `🔐 ${this._agent.name} created the #question hash`,
90
- hash_answer: `🔐 ${this._agent.name} created the #answer hash`,
91
- hash_answer: `🔐 ${this._agent.name} created the #packet hash`,
87
+ question_answer: `🔮 #${this._agent.name} gave #${this._client.name} the #answer`,
88
+ question_command: `🧞‍♀️ ${this._agent.name} then ran a #command for #${this._client.name}`,
89
+ hash_question: `🔐 ${this._agent.name} created the #question #hash`,
90
+ hash_ask: `🔐 ${this._agent.name} created the #ask #hash`,
91
+ hash_answer: `🔐 ${this._agent.name} created the #answer #hash`,
92
+ hash_command: `🔐 ${this._agent.name} created the #command #hash`,
93
+ hash_packet: `🔐 ${this._agent.name} created the #packet #hash`,
92
94
  ask_question: `👽 ${this._client.name} asked ${this._agent.name} a #question`,
93
- ask_answer: `🛸 ${this._agent.name} answered ${this._client.name}`,
94
- method_not_found: `😩 ${this._agent.name} used a bad #command, and may need help.`,
95
+ ask_answer: `🛸 ${this._agent.name} answered the #question from ${this._client.name}`,
96
+ method_not_found: `😩 ${this._agent.name} used a faulty #command, and may needs @Solutions to assist`,
95
97
  security_ready: `🚓 @Security is ready`,
96
98
  support_ready: `🚑 @Support is ready`,
97
99
  services_ready: `🚚 @Services is ready`,
98
- security_alert: `🚨 #SECURITY 🚨 SETTTINGS`,
99
- support_alert: `🚨 #SUPPORT 🚨 SETTTINGS`,
100
- services_alert: `🚨 #SERVICES 🚨 SETTTINGS`,
100
+ alert_security: `🚨 #SECURITY ALERT`,
101
+ alert_support: `🚨 #SUPPORT ALERT`,
102
+ alert_services: `🚨 #SERVICES ALERT`,
103
+ alert_solutions: `🚨 #SOLUTIONS ALERT`,
104
+ alert_systems: `🚨 #SYSTEMS ALERT`,
105
+ alert_development: `🚨 #SYSTEMS ALERT`,
101
106
  setting_client: `⛄️ Setting the #client for ${this._agent.name}`,
102
- setting_security: `👮‍♂️ ${this._agent.name} given #security`,
103
- setting_support: `👨‍⚕️ ${this._agent.name} given #support`,
104
- setting_services: `👷‍♂️ ${this._agent.name} given #services`,
107
+ setting_development: `🔬 ${this._agent.name} receiving @Development`,
108
+ setting_security: `👮‍♂️ ${this._agent.name} receiving @Security`,
109
+ setting_support: `👨‍⚕️ ${this._agent.name} receiving @Support`,
110
+ setting_services: `👷‍♂️ ${this._agent.name} receiving @Services`,
111
+ setting_systems: `🏘️ ${this._agent.name} receiving @Systems`,
112
+ setting_solutions: `🤓 ${this._agent.name} receiving @Solutions`,
105
113
  };
106
114
  }
107
115
 
@@ -114,27 +122,48 @@ class Deva {
114
122
  enter: `🖖 ${this._agent.name} enter.`,
115
123
  exit: `🚪 ${this._agent.name} exit.`,
116
124
  done: `👍 ${this._agent.name} done.`,
117
- devas_started: '🧞‍♂️🧞🧞‍♀️ #Devas are all doing their thing',
125
+ devas_started: '#Devas are #online and ready for #offerings 🍫🥛🍚🍯🧂',
118
126
  devas_stopped: '🛑 #Devas have stopped',
119
127
  notext: `❌ ${this._client.name}, please provide with valid input.`,
120
128
  method_not_found: `❌ ${this._client.name} you sure messed that up!`,
121
129
  }
122
130
  }
123
131
  set Client(cl) {
124
- // delete the services key to move and move to services.
132
+ // copy the cl parameter into a local _client variable
125
133
  const _client = this.copy(cl);
134
+
135
+ // delete the keys used for other features.
126
136
  if (_client.states) delete _client.states;
127
137
  if (_client.messages) delete _client.messages;
138
+ if (_client.development) delete _client.development;
128
139
  if (_client.security) delete _client.security;
129
140
  if (_client.support) delete _client.support;
130
141
  if (_client.services) delete _client.services;
142
+ if (_client.systems) delete _client.systems;
143
+ if (_client.solutions) delete _client.solutions;
144
+
145
+ // set the local client variable from the clean _client local variable.
146
+ this._client = _client;
131
147
 
132
- this._client = cl;
148
+ // set the states and messages after the cleint is set.
149
+ this.States = cl.states;
150
+ this.Messages = cl.messages;
151
+ }
133
152
 
134
- this.States = _client.states;
135
- this.Messages = _client.messages;
153
+ // setup the @Development feature.
154
+ set Development(opt=false) {
155
+ this.state('setting_development');
156
+ if (!opt) this._security = {};
157
+ else {
158
+ this._security = {
159
+ concerns: opt.concerns,
160
+ global: opt.global,
161
+ items: opt.devas[this._agent.key]
162
+ };
163
+ }
136
164
  }
137
165
 
166
+ // setup the @Security feature
138
167
  set Security(opt=false) {
139
168
  this.state('setting_security');
140
169
  if (!opt) this._security = {};
@@ -142,11 +171,12 @@ class Deva {
142
171
  this._security = {
143
172
  concerns: opt.concerns,
144
173
  global: opt.global,
145
- things: opt.devas[this._agent.key]
174
+ items: opt.devas[this._agent.key]
146
175
  };
147
176
  }
148
177
  }
149
178
 
179
+ // setup the @Support feature
150
180
  set Support(opt=false) {
151
181
  this.state('setting_support');
152
182
  if (!opt) this._support = {};
@@ -154,11 +184,12 @@ class Deva {
154
184
  this._support = {
155
185
  concerns: opt.concerns,
156
186
  global: opt.global,
157
- things: opt.devas[this._agent.key]
187
+ items: opt.devas[this._agent.key]
158
188
  };
159
189
  }
160
190
  }
161
191
 
192
+ // setup the @Services feature
162
193
  set Services(opt=false) {
163
194
  this.state('setting_services');
164
195
  if (!opt) this._servcies = {};
@@ -166,7 +197,33 @@ class Deva {
166
197
  this._services = {
167
198
  concerns: opt.concerns,
168
199
  global: opt.global,
169
- things: opt.devas[this._agent.key]
200
+ items: opt.devas[this._agent.key]
201
+ };
202
+ }
203
+ }
204
+
205
+ // setup the @Systems feature
206
+ set Systems(opt=false) {
207
+ this.state('setting_systems');
208
+ if (!opt) this._systems = {};
209
+ else {
210
+ this._systems = {
211
+ concerns: opt.concerns,
212
+ global: opt.global,
213
+ items: opt.devas[this._agent.key]
214
+ };
215
+ }
216
+ }
217
+
218
+ // setup the @Solutions feature
219
+ set Solutions(opt=false) {
220
+ this.state('setting_solutions');
221
+ if (!opt) this._solutions = {};
222
+ else {
223
+ this._solutions = {
224
+ concerns: opt.concerns,
225
+ global: opt.global,
226
+ items: opt.devas[this._agent.key]
170
227
  };
171
228
  }
172
229
  }
@@ -179,7 +236,7 @@ class Deva {
179
236
  ***************/
180
237
  state(st, data=false) {
181
238
  if (!Object.keys(this._states).includes(st)) return;
182
- this._state = this._states[st];
239
+ this._state = `${this._states[st]} on ${this.fDate(Date.now(), 'short_month', true)}`;
183
240
  const _data = {
184
241
  id: this.uid(true),
185
242
  client: this._client.id,
@@ -554,15 +611,18 @@ class Deva {
554
611
  try {
555
612
  if (!this._active) return reject(this._messages.offline);
556
613
 
614
+ let _state = 'question_default';
615
+ let _hash = 'hash_asnwer';
616
+
557
617
  // *: send just a string of text
558
618
  // !: send a command to the local agent
559
619
  // #: ask another agent a question
560
620
  // #agent method:param1:param2 with text strings for proccessing
561
621
  // !method param:list:parse for the local agent
562
622
  // if is an ask then we format one way
563
- let _state = 'question_default';
564
623
  if (isAsk) {
565
624
  _state = 'question_ask'
625
+ _state = 'hash_ask'
566
626
  key = t_split[0].substring(1);
567
627
  params = t_split[1] ? t_split[1].split(':') : false;
568
628
  method = params[0];
@@ -570,7 +630,8 @@ class Deva {
570
630
 
571
631
  }
572
632
  else if (isCmd) {
573
- _state = 'question_cmd'
633
+ _state = 'question_command';
634
+ _hash = 'hash_command'
574
635
  params = t_split[1] ? t_split[1].split(':') : false;
575
636
  method = t_split[0].substring(1);
576
637
  text = t_split.slice(1).join(' ').trim()
@@ -599,7 +660,6 @@ class Deva {
599
660
  // If a question to another Deva with '#' then trigger events
600
661
  if (isAsk) {
601
662
  this.state('question_asking');
602
- this.prompt(`sending key ${key}`);
603
663
  this.talk(`${key}:ask`, packet);
604
664
  this.once(`${key}:ask:${packet.id}`, answer => {
605
665
  return resolve(answer);
@@ -629,7 +689,7 @@ class Deva {
629
689
  created: Date.now(),
630
690
  };
631
691
  // create a hash for the answer and insert into answer meta.
632
- this.state('hash_answer');
692
+ this.state(_hash);
633
693
  packet.a.meta.hash = this.hash(JSON.stringify(packet.a));
634
694
 
635
695
  // create a hash for entire packet and insert into packet
@@ -682,6 +742,9 @@ class Deva {
682
742
  this.Security = client.security;
683
743
  this.Support = client.support;
684
744
  this.Services = client.services;
745
+ this.Systems = client.systems;
746
+ this.Solutions = client.solutions;
747
+ this.Development = client.development;
685
748
 
686
749
  return this.onInit && typeof this.onInit === 'function' ? this.onInit() : this.start();
687
750
  }).then(started => {
@@ -838,7 +901,7 @@ class Deva {
838
901
  being accessed.
839
902
  ***************/
840
903
  client() {
841
- if (!this._active) return Promise.resolve(this._messages.offline);
904
+ if (!this._active) return this._messages.offline;
842
905
  this.state('client');
843
906
  return this._client;
844
907
  }
@@ -851,7 +914,7 @@ class Deva {
851
914
  being accessed.
852
915
  ***************/
853
916
  agent() {
854
- if (!this._active) return Promise.resolve(this._messages.offline);
917
+ if (!this._active) return this._messages.offline;
855
918
  this.state('agent');
856
919
  return this._agent;
857
920
  }
@@ -861,21 +924,66 @@ class Deva {
861
924
  params: opts
862
925
  describe: basic security features available in a Deva.
863
926
  ***************/
864
- security(opts) {}
927
+ security(opts) {
928
+ if (!this._active) return this._messages.offline;
929
+ this.state('security');
930
+ return this._security;
931
+ }
865
932
 
866
933
  /**************
867
934
  func: security
868
935
  params: opts
869
936
  describe: basic support features available in a Deva.
870
937
  ***************/
871
- support(opts) {}
938
+ support(opts) {
939
+ if (!this._active) return this._messages.offline;
940
+ this.state('support');
941
+ return this._support;
942
+ }
872
943
 
873
944
  /**************
874
945
  func: security
875
946
  params: opts
876
947
  describe: basic services features available in a Deva.
877
948
  ***************/
878
- services(opts) {}
949
+ services(opts) {
950
+ if (!this._active) return this._messages.offline;
951
+ this.state('services');
952
+ return this._services;
953
+ }
954
+
955
+ /**************
956
+ func: systems
957
+ params: opts
958
+ describe: basic systems features available in a Deva.
959
+ ***************/
960
+ systems(opts) {
961
+ if (!this._active) return this._messages.offline;
962
+ this.state('systems');
963
+ return this._systems;
964
+ }
965
+
966
+ /**************
967
+ func: security
968
+ params: opts
969
+ describe: basic solutions features available in a Deva.
970
+ ***************/
971
+ solutions(opts) {
972
+ if (!this._active) return this._messages.offline;
973
+ this.state('solutions');
974
+ return this._solutions;
975
+ }
976
+
977
+ /**************
978
+ func: development
979
+ params: opts
980
+ describe: basic development features available in a Deva.
981
+ ***************/
982
+ development(opts) {
983
+ if (!this._active) return this._messages.offline;
984
+ this.state('development');
985
+ return this._development;
986
+ }
879
987
 
880
988
  /**************
881
989
  func: startDevas
@@ -915,5 +1023,73 @@ class Deva {
915
1023
  }).catch(reject);
916
1024
  });
917
1025
  }
1026
+
1027
+ // UTILITY FUNCTIONS
1028
+ /**************
1029
+ func: fDate
1030
+ params:
1031
+ - d: The date string to format.
1032
+ - format: the various formats that can be selected.
1033
+ - time: boolean flag to include the time stampt iwth the date.
1034
+ - locale: The locale formatting of the date to return.
1035
+ describe:
1036
+ formats: long, long_month, short, short_month, year, month, day
1037
+ FDate format ensures that consistent date formatting is used within the
1038
+ system based on the language and locale in the client profile.
1039
+ ***************/
1040
+ fDate(d, format='long', time=false) {
1041
+ if (!d) d = Date.now();
1042
+ d = new Date(d);
1043
+
1044
+ const formats = {
1045
+ long: { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' },
1046
+ long_month: { year: 'numeric', month: 'long', day: 'numeric'},
1047
+ short: { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric' },
1048
+ short_month: { year: 'numeric', month: 'short', day: 'numeric' },
1049
+ year: { year: 'numeric' },
1050
+ month: { month: 'long' },
1051
+ day: { day: 'long' },
1052
+ log: { year: 'numeric', month: 'short', day: 'numeric' },
1053
+ };
1054
+ const theDate = d.toLocaleDateString(this._client.locale, formats[format]);
1055
+ const theTime = this.fTime(d);
1056
+ return !theTime ? theDate : `${theDate} - ${theTime}`;
1057
+ }
1058
+
1059
+ /**************
1060
+ func: fTime
1061
+ params:
1062
+ - t: the time to format
1063
+ describe:
1064
+ The formatTime fucntion will return a consistent local time for the t
1065
+ parameter based on the locale setting in the client profile..
1066
+ ***************/
1067
+ fTime(t) {
1068
+ return t.toLocaleTimeString(this._client.locale);
1069
+ }
1070
+
1071
+ /**************
1072
+ func: fCurrency
1073
+ params:
1074
+ - n: is the number that you want to return the currency of.
1075
+ describe:
1076
+ The fCurrency function will format a currency value based on the setting
1077
+ in the client profile.
1078
+ ***************/
1079
+ fCurrency(n) {
1080
+ return new Intl.NumberFormat(this._client.locale, { style: 'currency', currency: this._client.currency }).format(n);
1081
+ }
1082
+
1083
+ /**************
1084
+ func: fPercent
1085
+ params:
1086
+ - n: is the number that you want to format as a percent.
1087
+ - dec: is the number of decimal places to apply to the number.
1088
+ describe:
1089
+ ***************/
1090
+ fPercent(n, dec=2) {
1091
+ return parseFloat(n).toFixed(dec) + '%';
1092
+ }
1093
+
918
1094
  }
919
1095
  module.exports = Deva;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.1.26",
3
+ "version": "1.1.27",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "scripts": {