@indra.ai/deva 1.1.108 → 1.1.110

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 -155
  2. package/index.js +25 -59
  3. package/package.json +1 -1
package/config.json CHANGED
@@ -32,7 +32,7 @@
32
32
  "question": "asked a question",
33
33
  "answer": "gave an answer",
34
34
  "offline": "offline",
35
- "online": "online",
35
+ "ready": "ready for tasking",
36
36
  "init": "initializing",
37
37
  "start": "starting",
38
38
  "enter": "entering deva.world",
@@ -47,52 +47,44 @@
47
47
  },
48
48
  "zone": false,
49
49
  "zones": {
50
- "deva": "Deva Zone",
51
- "config": "Configuration Zone",
52
- "features": "Feature Zone",
53
- "idle": "Idle Zone",
54
- "training": "Training Zone",
55
- "school": "School Zone",
56
- "work": "Work Zone",
57
- "fun": "Fun Zone",
58
- "adventure": "Adventure Zone",
59
- "party": "Party Zone",
60
- "invalid": "Invalid Invalid",
61
- "done": "Done Zone",
62
- "error": "Error Zone",
50
+ "deva": "The Deva Zone",
51
+ "config": "The Configuration Zone",
52
+ "features": "The Feature Zone",
53
+ "idle": "The Idle Zone",
54
+ "training": "The Training Zone",
55
+ "school": "The School Zone",
56
+ "work": "The Work Zone",
57
+ "fun": "The Fun Zone",
58
+ "adventure": "The Adventure Zone",
59
+ "party": "The Party Zone",
60
+ "invalid": "The Invalid Zone",
61
+ "done": "The Done Zone",
63
62
  "help": "Help Zone"
64
63
  },
65
64
  "action": false,
66
65
  "actions": {
67
- "wait": "::agent.name:: is waiting",
68
- "help": "::agent.name:: giving help",
69
- "start": "::agent.name:: has started",
70
- "enter": "::agent.name:: has entered deva.world",
71
- "exit": "::agent.name:: has exited deva.world",
72
- "stop": "::agent.name:: is stopped",
73
- "load": "::agent.name:: is loaded",
74
- "unload": "::agent.name:: is unloaded",
75
- "question": "::agent.name:: was received a question",
76
- "context": "::agent.name:: context change",
77
- "question_ask": "::agent.name:: was asked a question",
78
- "question_ask_answer": "::agent.name:: answered the question that was asked",
79
- "question_cmd": "::agent.name:: processed a command",
80
- "question_method": "::agent.name:: processed a method",
81
- "question_talk": "::agent.name:: broadcasted the question",
82
- "question_answer": "::agent.name:: has answered the question",
83
- "question_done": "::agent.name:: is done with the question",
84
- "answer": "::agent.name:: has given an answer",
85
- "answer_talk": "::agent.name:: broadcasted the answer",
86
- "ask": "::agent.name:: is being asked a question",
87
- "ask_answer": "::agent.name:: is answering the question that was asked",
88
- "status": "::agent.name:: returned their status",
89
- "get-today": "::agent.name:: getting the value of today",
90
- "format-date": "::agent.name:: format date",
91
- "format-time": "::agent.name:: format time",
92
- "format-currency": "::agent.name:: format currency",
93
- "format-percent": "::agent.name:: format percent",
94
- "trimmer": "::agent.name:: is trimming a word count",
95
- "dupes": "::agent.name:: is removing duplicates",
66
+ "wait": "waiting",
67
+ "help": "giving help",
68
+ "start": "has started",
69
+ "enter": "has entered deva.world",
70
+ "exit": "has exited deva.world",
71
+ "stop": "stopped",
72
+ "load": "loaded",
73
+ "unload": "unloaded",
74
+ "question": "received a question",
75
+ "context": "context change",
76
+ "question_ask": "asked a question",
77
+ "question_ask_answer": "answered the ask",
78
+ "question_cmd": "command",
79
+ "question_method": "method",
80
+ "question_talk": "talk question",
81
+ "question_answer": "answer question",
82
+ "question_done": "question done",
83
+ "answer": "has given an answer",
84
+ "answer_talk": "broadcasted the answer",
85
+ "ask": "is being asked a question",
86
+ "ask_answer": "answer ask",
87
+
96
88
  "security": "SECURITY",
97
89
  "support": "SUPPORT",
98
90
  "systems": "SYSTMS",
@@ -104,28 +96,26 @@
104
96
  "legal": "LEGAL",
105
97
  "assistant": "ASSISTANT",
106
98
  "artist": "ARTIST",
107
- "mind": "MIND",
108
- "Client": "::agent.name:: configure #client",
109
- "Security": "::agent.name:: configure #security",
110
- "Support": "::agent.name:: configure #support",
111
- "Systems": "::agent.name:: configure #systems",
112
- "Services": "::agent.name:: ocnfigure #services",
113
- "Solutions": "::agent.name:: configure #solutions",
114
- "Research": "::agent.name:: configure #research",
115
- "Development": "::agent.name:: configure #development",
116
- "Legal": "::agent.name:: configure #legal",
117
- "Business": "::agent.name:: configure #business",
118
- "Assistant": "::agent.name:: configure #assistant",
119
- "Artist": "::agent.name:: configure #artist",
120
- "Mind": "::agent.name:: configure #mind",
121
- "Done": "::agent.name:: configure #done",
122
- "invalid": "::agent.name:: invalid",
123
- "states": "::agent.name:: getting states",
124
- "actions": "::agent.name:: getting actions",
125
- "zones": "::agent.name:: getting zones",
126
- "features": "::agent.name:: Getting features",
127
- "contexs": "::agent.name:: Getting contexts",
128
- "finish": "::agent.name:: finished"
99
+ "Client": "configure client",
100
+ "Security": "configure security",
101
+ "Support": "configure support",
102
+ "Systems": "configure systems",
103
+ "Services": "ocnfigure services",
104
+ "Solutions": "configure solutions",
105
+ "Research": "configure research",
106
+ "Development": "configure development",
107
+ "Legal": "configure legal",
108
+ "Business": "configure business",
109
+ "Assistant": "configure assistant",
110
+ "Artist": "configure artist",
111
+ "Done": "configure done",
112
+ "invalid": "invalid",
113
+ "states": "getting states",
114
+ "actions": "getting actions",
115
+ "zones": "getting zones",
116
+ "features": "Getting features",
117
+ "contexs": "Getting contexts",
118
+ "finish": "finished"
129
119
  },
130
120
  "feature": false,
131
121
  "features": {
@@ -139,107 +129,104 @@
139
129
  "business": "Business",
140
130
  "legal": "Legal",
141
131
  "assistant": "Assistant",
142
- "artist": "Artist",
143
- "mind": "Mind"
132
+ "artist": "Artist"
144
133
  },
145
134
  "message": "offline",
146
135
  "messages": {
147
136
  "states": {
148
- "offline": "::agent.name:: is offline",
149
- "online": "::agent.name:: is online",
150
- "ask": "::agent.name:: asked a question",
151
- "question": "::agent.name:: received a question",
152
- "answer": "::agent.name:: answered the question",
153
- "init": "::agent.name:: is initializing",
154
- "start": "::agent.name:: is starting",
155
- "enter": "::agent.name:: has entered deva.world",
156
- "stop": "::agent.name:: is stopping",
157
- "exit": "::agent.name:: has exited deva.world",
158
- "load": "::agent.name:: is loading",
159
- "unload": "::agent.name:: is is unloading",
160
- "invalid": "::agent.name:: seems to be invalid",
161
- "finish": "::agent.name:: finish state",
162
- "done": "::agent.name:: is done",
163
- "error": "::agent.name:: appears to have had an error",
164
- "help": "::agent.name:: is getting help"
137
+ "offline": "offline",
138
+ "online": "online",
139
+ "ask": "asked a question",
140
+ "question": "received a question",
141
+ "answer": "answered the question",
142
+ "init": "initializing",
143
+ "start": "starting",
144
+ "enter": "has entered deva.world",
145
+ "stop": "stopping",
146
+ "exit": "has exited deva.world",
147
+ "load": "loading",
148
+ "unload": "is unloading",
149
+ "invalid": "seems to be invalid",
150
+ "finish": "finish state",
151
+ "done": "done",
152
+ "error": "appears to have had an error",
153
+ "help": "getting help"
165
154
  },
166
155
  "zones": {
167
- "deva": "::agent.name:: is in the Deva Zone",
168
- "config": "::agent.name:: is in the Config Zone",
169
- "features": "::agent.name:: is in the Features Zone",
170
- "idle": "::agent.name:: is in the Idle Zone",
171
- "training": "::agent.name:: is in the Training Zone",
172
- "school": "::agent.name:: is in the School Zone",
173
- "work": "::agent.name:: is in the Work Zone",
174
- "danger": "::agent.name:: is in the Danger Zone",
175
- "invalid": "::agent.name:: is in the Invalid Zone",
176
- "done": "::agent.name:: is in the Done Zone",
177
- "error": "::agent.name:: is in the Error Zone",
178
- "help": "::agent.name:: is in the Help Zone"
156
+ "deva": "The Deva Zone",
157
+ "config": "The Config Zone",
158
+ "features": "The Features Zone",
159
+ "idle": "The Idle Zone",
160
+ "training": "The Training Zone",
161
+ "school": "The School Zone",
162
+ "work": "The Work Zone",
163
+ "danger": "The Danger Zone",
164
+ "invalid": "The Invalid Zone",
165
+ "done": "The Done Zone",
166
+ "error": "The Error Zone",
167
+ "help": "The Help Zone"
179
168
  },
180
169
  "actions": {
181
- "wait": "::agent.name:: is waiting",
182
- "start": "::agent.name:: has started",
183
- "enter": "::agent.name:: has entered deva.world",
184
- "exit": "::agent.name:: has exited deva.world",
185
- "stop": "::agent.name:: is stopped",
186
- "load": "::agent.name:: is loaded",
187
- "unload": "::agent.name:: is unloaded",
188
- "question": "::agent.name:: received a question",
189
- "question_ask": "::agent.name:: is asking another Deva",
190
- "question_ask_answer": "::agent.name:: answered what they were asked",
191
- "question_cmd": "::agent.name:: is running a command",
192
- "question_method": "::agent.name:: is running a method",
193
- "question_talk": "::agent.name:: is broadcasting the question",
194
- "question_answer": "::agent.name:: answered the question",
195
- "question_done": "::agent.name:: the question is done",
196
- "answer": "::agent.name:: is generating an answer",
197
- "answer_talk": "::agent.name:: is talking an answer",
198
- "ask": "::agent.name:: is asking a question",
199
- "ask_answer": "::agent.name:: is answering a question",
170
+ "wait": "waiting",
171
+ "start": "started",
172
+ "enter": "entered deva.world",
173
+ "exit": "exited deva.world",
174
+ "stop": "stopped",
175
+ "load": "loaded",
176
+ "unload": "unloaded",
177
+ "question": "received a question",
178
+ "question_ask": "asking another Deva",
179
+ "question_ask_answer": "answered what they were asked",
180
+ "question_cmd": "running a command",
181
+ "question_method": "running a method",
182
+ "question_talk": "broadcasting the question",
183
+ "question_answer": "answered the question",
184
+ "question_done": "the question is done",
185
+ "answer": "generating an answer",
186
+ "answer_talk": "talking an answer",
187
+ "ask": "asking a question",
188
+ "ask_answer": "answering a question",
200
189
 
201
- "security": "::agent.name:: is accessing the #security feature",
202
- "Security": "::agent.name:: is loading the Security Feature",
203
- "support": "::agent.name:: is accessing the #support feature",
204
- "Support": "::agent.name:: is loading the Support Feature",
205
- "services": "::agent.name:: is accessing the #services feature",
206
- "Services": "::agent.name:: is loading the Services Feature",
207
- "solutions": "::agent.name:: is accessing the #services feature",
208
- "Solutions": "::agent.name:: is loading the Services Feature",
209
- "systems": "::agent.name:: is accing #systems",
210
- "Systems": "::agent.name:: is loading the Systems Feature",
211
- "research": "::agent.name:: is accessing the #research feature",
212
- "Research": "::agent.name:: is loading the Research Feature",
213
- "development": "::agent.name:: is accessing the #development feature",
214
- "Development": "::agent.name:: is loading the Development Feature",
215
- "business": "::agent.name:: is accessing the #business feature",
216
- "Business": "::agent.name:: is loading the Business Feature",
217
- "legal": "::agent.name:: is accessing the #legal feature",
218
- "Legal": "::agent.name:: is loading the Legal Feature",
219
- "assistant": "::agent.name:: is accessing the #assistant feature",
220
- "Assistant": "::agent.name:: is loading the Assistant Feature",
221
- "artist": "::agent.name:: is accessing the #artist feature",
222
- "Artist": "::agent.name:: is loading the Artist Feature",
223
- "mind": "::agent.name:: is accessing the #mind feature",
224
- "Mind": "::agent.name:: is loading the Mind Feature",
225
- "client_data": "::agent.name:: configure",
226
- "invalid": "::agent.name:: invalid",
227
- "finish": "::agent.name:: has finished the action",
228
- "done": "::agent.name:: done",
229
- "error": "::agent.name:: error",
230
- "help": "::agent.name:: providing help",
231
- "states": "::agent.name:: is listing the states",
232
- "actions": "::agent.name:: is listing the actions",
233
- "zones": "::agent.name:: is listing the zones",
234
- "features": "::agent.name:: is listing the features",
235
- "contexts": "::agent.name:: is listing the contexts"
190
+ "security": "accessing the #security feature",
191
+ "Security": "loading the Security Feature",
192
+ "support": "accessing the #support feature",
193
+ "Support": "loading the Support Feature",
194
+ "services": "accessing the #services feature",
195
+ "Services": "loading the Services Feature",
196
+ "solutions": "accessing the #services feature",
197
+ "Solutions": "loading the Services Feature",
198
+ "systems": "accing #systems",
199
+ "Systems": "loading the Systems Feature",
200
+ "research": "accessing the #research feature",
201
+ "Research": "loading the Research Feature",
202
+ "development": "accessing the #development feature",
203
+ "Development": "loading the Development Feature",
204
+ "business": "accessing the #business feature",
205
+ "Business": "loading the Business Feature",
206
+ "legal": "accessing the #legal feature",
207
+ "Legal": "loading the Legal Feature",
208
+ "assistant": "accessing the #assistant feature",
209
+ "Assistant": "loading the Assistant Feature",
210
+ "artist": "accessing the #artist feature",
211
+ "Artist": "loading the Artist Feature",
212
+ "client_data": "configure client data",
213
+ "invalid": "invalid action",
214
+ "finish": "finished",
215
+ "done": "done",
216
+ "error": "error",
217
+ "help": "providing help",
218
+ "states": "listing the states",
219
+ "actions": "listing the actions",
220
+ "zones": "listing the zones",
221
+ "features": "listing the features",
222
+ "contexts": "listing the contexts"
236
223
  },
237
224
  "features": {
238
- "security": "::agent.name:: accessing #security feature",
225
+ "security": "accessing #security feature",
239
226
  "Security": "Security configure",
240
- "support": "::agent.name:: accessing #support feature",
227
+ "support": "accessing #support feature",
241
228
  "Support": "Support configure",
242
- "services": "::agent.name:: accessing #services feature",
229
+ "services": "accessing #services feature",
243
230
  "Services": "Services configure",
244
231
  "solutions": "solutions feature",
245
232
  "Solutions": "Solutions configure",
@@ -257,8 +244,6 @@
257
244
  "Assistant": "Assistant configure",
258
245
  "artist": "artist feature",
259
246
  "Artist": "Artist configure",
260
- "mind": "mind feature",
261
- "Mind": "Mind configure",
262
247
  "invalid": "feature invalid",
263
248
  "done": "feature done",
264
249
  "error": "feature error"
package/index.js CHANGED
@@ -543,7 +543,7 @@ class Deva {
543
543
  Artist() {
544
544
  const _cl = this.client(); // set local client variable
545
545
  try {
546
- if (!this._client.features.artist) return this.Mind(); // if no artist goto Mind
546
+ if (!this._client.features.artist) return this.Done(); // if no artist goto Done
547
547
  else {
548
548
  this.action('Artist'); // set action to Artist
549
549
  const {id, features, profile} = this._client; // set the local consts from client copy
@@ -557,38 +557,7 @@ class Deva {
557
557
  personal: artist.devas[this._agent.key], // Client personal features and rules.
558
558
  };
559
559
  delete this._client.features.artist; // delete artist object from client
560
- return this.Mind(); // when done with artist goto Mind
561
- }
562
- } catch (e) {
563
- return this.error(e); // run error handling if an error is caught
564
- }
565
- }
566
-
567
- /**************
568
- func: Mind
569
- params: client: false
570
- describe:
571
- The Mind feature sets the correct variables and necessary rules for the
572
- client presented data.
573
- ***************/
574
- Mind() {
575
- const _cl = this.client();
576
- try {
577
- if (!_cl.features.mind) return this.Done();
578
- else {
579
- this.action('Mind');
580
- const {id, features, profile} = _cl; // set the local consts from client copy
581
- const {mind} = features; // set mind from features const
582
- this._mind = { // set this_mind with data
583
- id: this.uid(true), // uuid of the mind feature
584
- client_id: id, // client id for reference
585
- client_name: profile.name, // client name for personalization
586
- concerns: mind.concerns, // any concerns for client
587
- global: mind.global, // the global policies for client
588
- personal: mind.devas[this._agent.key], // Client personal features and rules.
589
- };
590
- delete this._client.features.mind; // delete the mind feature from client data
591
- return this.Done(); // when complete then move to the done feature.
560
+ return this.Done(); // when done with artist goto Done
592
561
  }
593
562
  } catch (e) {
594
563
  return this.error(e); // run error handling if an error is caught
@@ -811,13 +780,9 @@ class Deva {
811
780
  // create a hash for the answer and insert into answer meta.
812
781
  packet_answer.meta.hash = this.hash(packet_answer);
813
782
 
814
- packet.a = this.copy(packet_answer);
815
- packet.hash = this.hash(packet); // hash the entire packet.
816
-
817
-
818
783
  this.action('answer_talk');
784
+ packet.a = packet_answer;
819
785
  this.talk(config.events.answer, this.copy(packet)); // global talk event
820
-
821
786
  return this.finish(packet, resolve) // resolve the packet to the caller.
822
787
  }).catch(err => { // catch any errors in the method
823
788
  return this.error(err, packet, reject); // return this.error with err, packet, reject
@@ -847,7 +812,7 @@ class Deva {
847
812
  const agent = this.agent();
848
813
  const client = this.client();
849
814
  // build the answer packet from this model
850
- packet.a = {
815
+ const packet_answer = {
851
816
  id: this.uid(),
852
817
  agent,
853
818
  client,
@@ -874,14 +839,16 @@ class Deva {
874
839
  // the response based on the passed through packet.
875
840
  this.methods[packet.q.meta.method](packet).then(result => {
876
841
  if (typeof result === 'object') {
877
- packet.a.text = result.text || false;
878
- packet.a.html = result.html || false;
879
- packet.a.data = result.data || false;
842
+ packet_answer.text = result.text || false;
843
+ packet_answer.html = result.html || false;
844
+ packet_answer.data = result.data || false;
880
845
  }
881
846
  else {
882
- packet.a.text = result;
847
+ packet_answer.text = result;
883
848
  }
849
+ packet_answer.meta.hash = this.hash(packet_answer);
884
850
  this.action('ask_answer');
851
+ packet.a = packet_answer;
885
852
  this.talk(`${agent.key}:ask:${packet.id}`, packet);
886
853
  }).catch(err => {
887
854
  this.talk(`${agent.key}:ask:${packet.id}`, {error:err});
@@ -938,7 +905,6 @@ class Deva {
938
905
  return this.Client(client);
939
906
  }).then(() => {
940
907
  this.zone('features');
941
- this.action('features');
942
908
  return this.Security();
943
909
  }).then(() => {
944
910
  this.zone('deva');
@@ -1013,6 +979,7 @@ class Deva {
1013
979
  data.hash = this.hash(data);
1014
980
  this.action(data.value)
1015
981
  const hasOnDone = this.onDone && typeof this.onDone === 'function' ? true : false;
982
+ this.state('online');
1016
983
  return hasOnDone ? this.onDone(data) : Promise.resolve(data);
1017
984
  }
1018
985
 
@@ -1030,6 +997,8 @@ class Deva {
1030
997
  finish(packet, resolve) {
1031
998
  if (!this._active) return Promise.resolve(this._messages.states.offline);
1032
999
  this.action('finish');
1000
+ this.state('online');
1001
+ packet.hash = this.hash(packet);// hash the entire packet before finishing.
1033
1002
  const hasOnFinish = this.onFinish && typeof this.onFinish === 'function' ? true : false;
1034
1003
  if (hasOnFinish) return this.onFinish(packet, resolve);
1035
1004
  else if (resolve) return resolve(packet);
@@ -1160,21 +1129,21 @@ class Deva {
1160
1129
  - st: The zone flag to set for the Deva that matches to this._zones
1161
1130
  describe
1162
1131
  ***************/
1163
- zone(zone) {
1132
+ zone(value) {
1133
+ if (!this._zones[value] || value === this._zone) return;
1164
1134
  try {
1165
- if (!this._zones[zone]) return;
1166
- this._zone = zone;
1167
- const text = this._messages.zones[zone];
1168
- const talk = {
1135
+ this._zone = value;
1136
+ const text = this._messages.zones[value];
1137
+ const data = {
1169
1138
  id: this.uid(true),
1170
1139
  key: 'zone',
1171
- value: zone,
1172
- agent: this._agent,
1140
+ value,
1141
+ agent: this.agent(),
1173
1142
  text,
1174
1143
  created: Date.now(),
1175
1144
  };
1176
- talk.hash = this.hash(talk);
1177
- this.talk(config.events.zone, talk);
1145
+ data.hash = this.hash(data);
1146
+ this.talk(config.events.zone, data);
1178
1147
  } catch (e) {
1179
1148
  return this.error(e);
1180
1149
  }
@@ -1594,7 +1563,7 @@ class Deva {
1594
1563
  // this.action('hash');
1595
1564
  algo = algo || this._security.hash || 'md5';
1596
1565
  const the_hash = createHash(algo);
1597
- the_hash.update(str.toString());
1566
+ the_hash.update(JSON.stringify(str));
1598
1567
  const _digest = the_hash.digest('base64');
1599
1568
  return `${algo}:${_digest}`;
1600
1569
  }
@@ -1759,7 +1728,7 @@ class Deva {
1759
1728
  - dec: is the number of decimal places to apply to the number.
1760
1729
  describe:
1761
1730
  ***************/
1762
- formatPerdent(n, dec=2) {
1731
+ formatPercent(n, dec=2) {
1763
1732
  return parseFloat(n).toFixed(dec) + '%';
1764
1733
  }
1765
1734
 
@@ -1831,6 +1800,7 @@ class Deva {
1831
1800
  status(msg=false) {
1832
1801
  // check the active status
1833
1802
  if (!this._active) return Promise.resolve(this._messages.states.offline);
1803
+ this.action('status');
1834
1804
  // format the date since active for output.
1835
1805
  const dateFormat = this.formatDate(this._active, 'long', true);
1836
1806
  // create the text msg string
@@ -1852,7 +1822,6 @@ class Deva {
1852
1822
  help(msg, help_dir) {
1853
1823
  return new Promise((resolve, reject) => {
1854
1824
  if (!this._active) return resolve(this._messages.states.offline);
1855
- this.state('help');
1856
1825
  this.zone('help');
1857
1826
  this.action('help');
1858
1827
  const params = msg.split(' ');
@@ -1863,9 +1832,6 @@ class Deva {
1863
1832
  try {
1864
1833
  return resolve(fs.readFileSync(helpFile, 'utf8'));
1865
1834
  } catch (e) {
1866
- this.action('help');
1867
- this.zone('help');
1868
- this.state('help');
1869
1835
  return reject(e)
1870
1836
  }
1871
1837
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.1.108",
3
+ "version": "1.1.110",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "scripts": {