@indra.ai/deva 1.1.29 → 1.1.31
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/examples/agent.json +61 -3
- package/examples/client.json +72 -51
- package/examples/hello-world.js +21 -48
- package/index.js +780 -401
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -7,16 +7,19 @@ const { createHash, randomUUID, createCipheriv, createDecipheriv, randomBytes }
|
|
|
7
7
|
class Deva {
|
|
8
8
|
constructor(opts) {
|
|
9
9
|
opts = opts || {};
|
|
10
|
-
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
15
|
-
this._state = 'OFFLINE'; // current state of agent.
|
|
10
|
+
this._id = randomUUID(); // the unique id assigned to the agent at load
|
|
11
|
+
this._config = opts.config || {}; // local Config Object
|
|
12
|
+
this._agent = opts.agent || false; // Agent profile object
|
|
13
|
+
this._client = {}; // this will be set on init.
|
|
14
|
+
this._state = 'OFFLINE'; // current state of agent.
|
|
16
15
|
this._active = false; // the active/birth date.
|
|
17
|
-
this._security =
|
|
18
|
-
this._support =
|
|
19
|
-
this._services =
|
|
16
|
+
this._security = false; // inherited Security features.
|
|
17
|
+
this._support = false; // inherited Support features.
|
|
18
|
+
this._services = false; // inherited Service features.
|
|
19
|
+
this._assistant = false; // inherited @Assistant features.
|
|
20
|
+
this._business = false; // inherited @Business features.
|
|
21
|
+
this._development = false; // inherited @Business features.
|
|
22
|
+
this._legal = false; // inherited @Legal features.
|
|
20
23
|
this.events = opts.events || new EventEmitter({}); // Event Bus
|
|
21
24
|
this.lib = opts.lib || {}; // used for loading library functions
|
|
22
25
|
this.devas = opts.devas || {}; // Devas which are loaded
|
|
@@ -31,98 +34,199 @@ class Deva {
|
|
|
31
34
|
if (!this[opt]) this[opt] = opts[opt]; // set any remaining opts to this.
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
this.cmdChr = '/';
|
|
35
|
-
this.askChr = '#';
|
|
36
|
-
|
|
37
|
-
this.
|
|
38
|
-
|
|
37
|
+
this.cmdChr = '/'; // the trigger for local commands
|
|
38
|
+
this.askChr = '#'; // the trigger for ask other DEva features
|
|
39
|
+
// index of the items
|
|
40
|
+
this.inherit = ["events", "lib"];
|
|
41
|
+
this.bind = [
|
|
42
|
+
"listeners",
|
|
43
|
+
"methods",
|
|
44
|
+
"func",
|
|
45
|
+
"lib",
|
|
46
|
+
"_agent"
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
this._features = {
|
|
50
|
+
assistant: {
|
|
51
|
+
label: '👤ASSISTANT',
|
|
52
|
+
name: '@ASSISTANT',
|
|
53
|
+
tag: '#ASSISTANT',
|
|
54
|
+
loc: '$ASSISTANT',
|
|
55
|
+
},
|
|
56
|
+
business: {
|
|
57
|
+
label: '💼BUSINESS',
|
|
58
|
+
name: '@BUSINESS',
|
|
59
|
+
tag: '#BUSINESS',
|
|
60
|
+
loc: '$BUSINESS',
|
|
61
|
+
},
|
|
62
|
+
legal: {
|
|
63
|
+
label: '👨⚖️LEGAL',
|
|
64
|
+
name: '@LEGAL',
|
|
65
|
+
tag: '#LEGAL',
|
|
66
|
+
loc:' $LEGAL',
|
|
67
|
+
},
|
|
68
|
+
development: {
|
|
69
|
+
label: '👨💻DEVELOPMENT',
|
|
70
|
+
name: '@DEVELOPMENT',
|
|
71
|
+
tag: '#DEVELOPMENT',
|
|
72
|
+
loc: '$DEVELOPMENT',
|
|
73
|
+
},
|
|
74
|
+
security: {
|
|
75
|
+
label: '🚨SECURITY',
|
|
76
|
+
name: '@SECURITY',
|
|
77
|
+
tag: '#SECURITY',
|
|
78
|
+
loc: '$SECURITY',
|
|
79
|
+
},
|
|
80
|
+
support: {
|
|
81
|
+
label: '🆘SUPPORT',
|
|
82
|
+
name: '@SUPPORT',
|
|
83
|
+
tag: '#SUPPORT',
|
|
84
|
+
loc: '$SUPPORT',
|
|
85
|
+
},
|
|
86
|
+
services: {
|
|
87
|
+
label: '📞SERVICES',
|
|
88
|
+
name: '@SERVICES',
|
|
89
|
+
tag: '#SERVICES',
|
|
90
|
+
loc: '$SERVICES',
|
|
91
|
+
},
|
|
92
|
+
solutions: {
|
|
93
|
+
label: '💡SOLUTIONS',
|
|
94
|
+
name: '@SOLUTIONS',
|
|
95
|
+
tag: '#SOLUTIONS',
|
|
96
|
+
loc: '$SOLUTIONS',
|
|
97
|
+
},
|
|
98
|
+
systems: {
|
|
99
|
+
label: '🔧SYSTEMS',
|
|
100
|
+
name: '@SYSTEMS',
|
|
101
|
+
tag: '#SYSTEMS',
|
|
102
|
+
loc: '$SYSTEMS',
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
this._states = {}; // states object
|
|
106
|
+
this._messages = {}; // messages object
|
|
39
107
|
}
|
|
40
108
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
109
|
+
/**************
|
|
110
|
+
func: States
|
|
111
|
+
params: none
|
|
112
|
+
describe:
|
|
113
|
+
The States function builds the list of states with the associated client and
|
|
114
|
+
agent variables in the place holders. This function runs after the Client
|
|
115
|
+
function to ensure that hte messages are personalized to the Client and AGent.
|
|
116
|
+
***************/
|
|
117
|
+
States() {
|
|
118
|
+
const {
|
|
119
|
+
development, security, services, support,
|
|
120
|
+
systems, solutions, assistant, business, legal
|
|
121
|
+
} = this._features;
|
|
122
|
+
|
|
123
|
+
const cp = this._client.profile;
|
|
124
|
+
const ckey = this._client.key
|
|
125
|
+
const ap = this._agent.profile;
|
|
126
|
+
const akey = this._agent.key;
|
|
44
127
|
|
|
45
|
-
set States(opts) {
|
|
46
128
|
const _states = {
|
|
47
|
-
uid:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
ask:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
129
|
+
uid: `${security.label}:UID ${cp.name} made a #uid with ${ap.name}`,
|
|
130
|
+
hash: `${security.label}:HASH ${cp.name} made a #hash with ${ap.name}`,
|
|
131
|
+
cipher: `${security.label}:CIPHER ${cp.name} locked a #cipher with ${ap.name}`,
|
|
132
|
+
decipher: `${security.label}:DECIPHER ${cp.name} unlocked a #cipher with ${ap.name}`,
|
|
133
|
+
offline: `👻 ${ap.name} is offline`,
|
|
134
|
+
online: `📡 ${ap.name} is online`,
|
|
135
|
+
config: `📀 ${ap.name} is checking the config`,
|
|
136
|
+
client: `👨💻 ${ap.name} opened the ${ckey} profile`,
|
|
137
|
+
agent: `👨💻 ${ap.name} is looking at ${akey} profile`,
|
|
138
|
+
init: `🚀 ${ap.name} is initializing for ${cp.name}`,
|
|
139
|
+
start: `🎬 ${ap.name} has started the process for ${cp.name}`,
|
|
140
|
+
enter: `🎪 ${ap.name} is entering the deva.world with ${cp.name}`,
|
|
141
|
+
stop: `🛑 ${ap.name} has stopped for ${cp.name}`,
|
|
142
|
+
exit: `🚪 ${ap.name} found the exit with ${cp.name}`,
|
|
143
|
+
done: `🤝 ${ap.name} is all done time for #offerings 🍫🍌`,
|
|
144
|
+
wait: `😵💫 ${ap.name} waiting for #stuff from ${cp.name}`,
|
|
145
|
+
data: `📀 ${ap.name} is receiving #data for ${cp.name}`,
|
|
146
|
+
ask: `🙋♀️ ${ap.name} is asking a #question from ${cp.name}`,
|
|
147
|
+
cmd: `📟 ${ap.name} entered a #command from ${cp.name}`,
|
|
148
|
+
question: `🐵 ${ap.name} is in #question mode ${cp.name}`,
|
|
149
|
+
ask: `🐵 ${ap.name} is in #ask mode ${cp.name}`,
|
|
150
|
+
talk: `🎙️ ${ap.name} is in #talk mode with ${cp.name}`,
|
|
151
|
+
listen: `🎧 ${ap.name} is in #listening mode with ${cp.name}`,
|
|
152
|
+
error: `❌ ${ap.name} had an error. Let's have @Systems look into that.`,
|
|
153
|
+
story: `📓STORY: ${cp.name} is creating an amazing #story ${cp.name}`,
|
|
154
|
+
development: `${development.label}: ${cp.name} and ${ap.name} need ${development.name} assistance`,
|
|
155
|
+
security: `${security.label}: ${cp.name} and ${ap.name} need ${security.name} assistance`,
|
|
156
|
+
support: `${support.label}: ${cp.name} and ${ap.name} need ${support.name} assistance`,
|
|
157
|
+
services: `${services.label}: ${cp.name} and ${ap.name} need ${services.name} assistance`,
|
|
158
|
+
systems: `${systems.label}: ${cp.name} and ${ap.name} need ${systems.name} assistance`,
|
|
159
|
+
solutions: `${development.label}: ${cp.name} and ${ap.name} need ${development.name} assistance`,
|
|
160
|
+
legal: `${legal.label}: ${cp.name} and ${ap.name} need ${legal.name} assistance`,
|
|
161
|
+
business: `${business.label}: ${cp.name} and ${ap.name} need ${business.name} assistance`,
|
|
162
|
+
devas_start: `🧞♂️DEVAS: Starting all the #Devas with ${cp.name}`,
|
|
163
|
+
devas_ready: `🧞♂️DEVA:READY The #Devas are #ready and #waiitng for ${cp.name} using @${cp.key} #${cp.key} $${cp.key}`,
|
|
164
|
+
devas_stop: `🧞♂️DEVA:STOPPING The #Devas are #stopping with ${cp.name}`,
|
|
165
|
+
devas_stopped: `🧞♂️DEVA:🛑STOP #Devas and ${cp.name} have #stopped, and that means time for #offerings 🍎🍑🍍🧋`,
|
|
166
|
+
deva_load: `🧞♂️DEVA:LOADING ${ap.name} loading for ${cp.name}`,
|
|
167
|
+
deva_loaded: `🧞♂️DEVA:LOADED ${ap.name} loaded for ${cp.name}`,
|
|
168
|
+
deva_unloaded: `🧞♂️DEVAS:UNLOADED ${ap.name} unloaded for ${cp.name}`,
|
|
169
|
+
question_me: `❓QUESTION:START ${cp.name} started with a great #question to ${ap.name}`,
|
|
170
|
+
question_default: `🧞♂️QUESTION:ME ${cp.name} asked a great #question to ${ap.name}`,
|
|
171
|
+
question_ask: `🧞QUESTION:ASK ${ap.name} is pondering what ${cp.name} asked`,
|
|
172
|
+
question_asking: `🧞QUESTION:ASK:ANSWER ${ap.name} is asking another #Deva for ${cp.name}`,
|
|
173
|
+
question_aswering: `🧞QUESTION:ASK:ANSWERING ${ap.name} is answering the #question ${cp.name} asked`,
|
|
174
|
+
question_answer: `🔮QUESTION:ANSWER ${cp.name} received an #ansewr from ${ap.name}`,
|
|
175
|
+
question_command: `🧞♀️QUESTION:CMD ${cp.name} issued a #command to ${ap.name}`,
|
|
176
|
+
hash_question: `${security.label}:HASH:QUESTION ${ap.name} created the #question #hash for ${cp.name}`,
|
|
177
|
+
hash_ask: `${security.label}:HASH:ASK ${ap.name} created the #ask #hash for ${cp.name}`,
|
|
178
|
+
hash_answer: `${security.label}:HASH:ANSWER ${cp.name} #answer #hash with ${ap.name}`,
|
|
179
|
+
hash_command: `${security.label}:HASH:COMMAND ${cp.name} used a #command with ${ap.name}`,
|
|
180
|
+
hash_packet: `${security.label}:HASH:PACKET ${ap.name} created the #packet #hash for ${cp.name}`,
|
|
181
|
+
ask_question: `❓QUESTION: ${cp.name} asked ${ap.name} a great #question`,
|
|
182
|
+
ask_answer: `💡ANSWER: ${cp.name} received a great #answer from ${ap.name}`,
|
|
183
|
+
method_not_found: `${security.label}:ERROR:COMMAND ${cp.name} used a #command while working with ${ap.name}, and may need from ${security.name}`,
|
|
184
|
+
|
|
185
|
+
ready_security: `${security.label}:READY - ${security.name} is ready on ${security.tag} in ${security.loc}`,
|
|
186
|
+
ready_support: `${support.label}:READY - ${support.name} is ready on ${support.tag} in ${support.loc}`,
|
|
187
|
+
ready_services: `${services.label}:READY - ${services.name} is ready on ${services.tag} in ${services.loc}`,
|
|
188
|
+
ready_systems: `${systems.label}:READY - ${systems.name} is ready on ${systems.tag} in ${systems.loc}`,
|
|
189
|
+
ready_solutions: `${solutions.label}:READY - ${solutions.name} is ready on ${solutions.tag} in ${solutions.loc}`,
|
|
190
|
+
ready_development: `${development.label}:READY - ${development.name} is ready ${development.tag} in ${development.loc}`,
|
|
191
|
+
ready_legal: `${legal.label}:READY - ${legal.name} is ready on ${legal.tag} in ${legal.loc}`,
|
|
192
|
+
ready_business: `${business.label}:READY - ${business.name} is ready ${business.tag} in ${business.loc}`,
|
|
193
|
+
ready_assistant: `${assistant.label}:READY - ${assistant.name} is ready ${assistant.tag} in ${business.loc}`,
|
|
194
|
+
|
|
195
|
+
alert_security: `${security.label}:ALERT There is an #issue with ${cp.name} and ${ap.name}.`,
|
|
196
|
+
alert_support: `${support.label}:ALERT There is an #issue with ${cp.name} and ${ap.name}.`,
|
|
197
|
+
alert_services: `${services.label}:ALERT There is an #issue with ${cp.name} and ${ap.name}.`,
|
|
198
|
+
alert_solutions: `${solutions.label}:ALERT There is an #issue with ${cp.name} and ${ap.name}.`,
|
|
199
|
+
alert_systems: `${systems.label}:ALERT There is an #issue with ${cp.name} and ${ap.name}.`,
|
|
200
|
+
alert_development: `${development.label}:ALERT There is an #issue with ${cp.name} and ${ap.name}.`,
|
|
201
|
+
alert_assistant: `${assistant.label}:ALERT There is an #issue with ${cp.name} and ${ap.name}.`,
|
|
202
|
+
alert_legal: `${legal.label}:ALERT There is an #issue with ${cp.name} and ${ap.name}.`,
|
|
203
|
+
alert_business: `${business.label}:ALERT There is an #issue with ${cp.name} and ${ap.name}.`,
|
|
204
|
+
|
|
205
|
+
setting_client: `👨CLIENT: ${ap.name} is setting #${ckey} for ${cp.name} `,
|
|
206
|
+
setting_security: `${security.label}: ${cp.name} and ${ap.name} are receiving ${security.name} on ${security.tag} in ${security.loc}`,
|
|
207
|
+
setting_development: `${development.label}: ${cp.name} and ${ap.name} are receiving ${development.name} on ${development.tag} in ${development.loc}`,
|
|
208
|
+
setting_support: `${support.label}: ${cp.name} and ${ap.name} are receiving ${support.name} on ${development.tag} in ${development.loc}`,
|
|
209
|
+
setting_services: `${services.label}: ${cp.name} and ${ap.name} are receiving ${services.name} on ${services.tag} in ${services.loc}`,
|
|
210
|
+
setting_systems: `${systems.label}: ${cp.name} and ${ap.name} are receiving ${systems.name} on ${systems.tag} in ${systems.loc}`,
|
|
211
|
+
setting_solutions: `${solutions.label}: ${cp.name} and ${ap.name} are receiving ${solutions.name} on ${solutions.tag} in ${solutions.loc}`,
|
|
212
|
+
setting_assistant: `${assistant.label}: ${cp.name} and ${ap.name} are receiving ${assistant.name} on ${assistant.tag} in ${assistant.loc}`,
|
|
213
|
+
setting_legal: `${legal.label}: ${cp.name} and ${ap.name} are receiving ${legal.name} on ${legal.tag} in ${legal.loc}`,
|
|
214
|
+
setting_business: `${business.label}: ${cp.name} and ${ap.name} are receiving ${business.name} on ${business.tag} in ${business.loc}`,
|
|
215
|
+
setting_done: `✅DONE: FEATURE SETTINGS COMPLETE`,
|
|
120
216
|
}
|
|
121
|
-
this._states = _states;
|
|
217
|
+
this._states = _states; // The available states to work with.
|
|
122
218
|
}
|
|
123
219
|
|
|
124
|
-
|
|
125
|
-
|
|
220
|
+
/**************
|
|
221
|
+
func: Messages
|
|
222
|
+
params: none
|
|
223
|
+
describe:
|
|
224
|
+
The Messages function builds the system messages, and allows for the
|
|
225
|
+
reloading of system messages when client or agent data changes.
|
|
226
|
+
***************/
|
|
227
|
+
Messages() {
|
|
228
|
+
// Default system messages
|
|
229
|
+
const _messages = {
|
|
126
230
|
offline: `🙅♂️ ${this._agent.profile.name} offline`,
|
|
127
231
|
init: `⚠️ ${this._agent.profile.name} init`,
|
|
128
232
|
start: `✅ ${this._agent.profile.name} start`,
|
|
@@ -130,138 +234,336 @@ class Deva {
|
|
|
130
234
|
enter: `🖖 ${this._agent.profile.name} enter.`,
|
|
131
235
|
exit: `🚪 ${this._agent.profile.name} exit.`,
|
|
132
236
|
done: `👍 ${this._agent.profile.name} done.`,
|
|
133
|
-
devas_started: '
|
|
134
|
-
devas_stopped: '🛑
|
|
135
|
-
notext: `❌ ${this._client.profile.name},
|
|
237
|
+
devas_started: '🍪DEVAS: #online and ready for #offerings 🍫🥛🍚🍯🧂',
|
|
238
|
+
devas_stopped: '🛑DEVAS: have stopped',
|
|
239
|
+
notext: `❌ ${this._client.profile.name}, Invalid input.`,
|
|
240
|
+
deval_already_loaded: `That #DEVA is already loaded.`,
|
|
136
241
|
method_not_found: `❌ ${this._client.profile.name} you sure messed that up!`,
|
|
137
242
|
}
|
|
243
|
+
this._messages = this.copy(_messages); // set a copy of _messages as this._messages;
|
|
138
244
|
}
|
|
245
|
+
|
|
246
|
+
/**************
|
|
247
|
+
func: Client
|
|
248
|
+
params: client - client provided data.
|
|
249
|
+
describe:
|
|
250
|
+
The Client feature sets up the client variables and removes any unnecessary
|
|
251
|
+
keys from the client object that are used in other features.
|
|
252
|
+
|
|
253
|
+
usage:
|
|
254
|
+
this.Client = {data}
|
|
255
|
+
***************/
|
|
139
256
|
set Client(client) {
|
|
140
|
-
// copy the
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
//
|
|
154
|
-
this._client = _client;
|
|
155
|
-
|
|
156
|
-
// set the states and messages after the cleint is set.
|
|
157
|
-
this.States = client.states;
|
|
158
|
-
this.Messages = client.messages;
|
|
257
|
+
const _client = this.copy(client); // copy the client parameter
|
|
258
|
+
this._client = _client; // set local _client to this scope
|
|
259
|
+
|
|
260
|
+
this.States() // set the States after the Client
|
|
261
|
+
this.Messages() // set the Messages after the Client
|
|
262
|
+
// this.Support();
|
|
263
|
+
// this.Services();
|
|
264
|
+
// this.Systems();
|
|
265
|
+
// this.Solutions();
|
|
266
|
+
// this.Development();
|
|
267
|
+
// this.Assistant();
|
|
268
|
+
// this.Business();
|
|
269
|
+
// this.Legal();
|
|
270
|
+
// if (_client.featuers) delete _client.features; // delete features key for client security
|
|
159
271
|
}
|
|
160
272
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
273
|
+
/**************
|
|
274
|
+
func: Security
|
|
275
|
+
params: client: false
|
|
276
|
+
describe:
|
|
277
|
+
The Security feature sets the correct variables and necessary rules for the
|
|
278
|
+
client presented data.
|
|
279
|
+
***************/
|
|
280
|
+
Security() {
|
|
281
|
+
try {
|
|
282
|
+
if (!this._client.features.security) return this.Support();
|
|
283
|
+
else {
|
|
284
|
+
this.state('setting_security');
|
|
285
|
+
const {id, profile, features} = this._client; // make a copy the clinet data.
|
|
286
|
+
const {security} = features; // make a copy the clinet data.
|
|
287
|
+
this._security = { // set this_security with data
|
|
288
|
+
id: this.uid(true), // uuid of the security feature
|
|
289
|
+
client_id: id, // client id for reference
|
|
290
|
+
client_name: profile.name, // client name for personalization
|
|
291
|
+
hash: security.hash, // client preferred hash algorithm
|
|
292
|
+
cipher: security.cipher, // client preferred cipher settings
|
|
293
|
+
concerns: security.concerns, // any concerns for client
|
|
294
|
+
global: security.global, // the global policies for client
|
|
295
|
+
personal: security.devas[this._agent.key] // Client personal features and rules.
|
|
296
|
+
};
|
|
297
|
+
delete this._client.features.security // make a copy the clinet data.
|
|
298
|
+
return this.Support();
|
|
299
|
+
}
|
|
300
|
+
} catch (e) {
|
|
301
|
+
return this.error(e) // run error handling if an error is caught
|
|
177
302
|
}
|
|
178
303
|
}
|
|
179
304
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
305
|
+
/**************
|
|
306
|
+
func: Support
|
|
307
|
+
params: client: false
|
|
308
|
+
describe:
|
|
309
|
+
The Support feature sets the correct variables and necessary rules for the
|
|
310
|
+
client presented data.
|
|
311
|
+
***************/
|
|
312
|
+
Support() {
|
|
313
|
+
try {
|
|
314
|
+
if (!this._client.features.support) return this.Services()
|
|
315
|
+
else {
|
|
316
|
+
this.state('setting_support'); // set state to support setting
|
|
317
|
+
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
318
|
+
const {support} = features; // set support from features const
|
|
319
|
+
this._support = { // set this_support with data
|
|
320
|
+
id: this.uid(true), // uuid of the support feature
|
|
321
|
+
client_id: id, // client id for reference
|
|
322
|
+
client_name: profile.name, // client name for personalization
|
|
323
|
+
concerns: support.concerns, // any concerns for client
|
|
324
|
+
global: support.global, // the global policies for client
|
|
325
|
+
personal: support.devas[this._agent.key] // Client personalSecurity features and rules.
|
|
326
|
+
};
|
|
327
|
+
delete this._client.features.support
|
|
328
|
+
return this.Services();
|
|
329
|
+
}
|
|
330
|
+
} catch (e) {
|
|
331
|
+
return this.error(e) // run error handling if an error is caught
|
|
194
332
|
}
|
|
195
333
|
}
|
|
196
334
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
335
|
+
/**************
|
|
336
|
+
func: Services
|
|
337
|
+
params: client: false
|
|
338
|
+
describe:
|
|
339
|
+
The Services feature sets the correct variables and necessary rules for the
|
|
340
|
+
client presented data.
|
|
341
|
+
***************/
|
|
342
|
+
Services() {
|
|
343
|
+
try {
|
|
344
|
+
if (!this._client.features.services) return this.Systems();
|
|
345
|
+
else {
|
|
346
|
+
this.state('setting_services'); // set state to security setting
|
|
347
|
+
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
348
|
+
const {services} = features; // set services from features const
|
|
349
|
+
this._services = { // set this_services with data
|
|
350
|
+
id: this.uid(true), // uuid of the services feature
|
|
351
|
+
client_id: id, // client id for reference
|
|
352
|
+
client_name: profile.name, // client name for personalization
|
|
353
|
+
concerns: services.concerns, // any concerns for client
|
|
354
|
+
global: services.global, // the global policies for client
|
|
355
|
+
personal: services.devas[this._agent.key] // Client personal features and rules.
|
|
356
|
+
};
|
|
357
|
+
delete this._client.features.services
|
|
358
|
+
return this.Systems()
|
|
359
|
+
}
|
|
360
|
+
} catch (e) {
|
|
361
|
+
return this.error(e) // run error handling if an error is caught
|
|
211
362
|
}
|
|
212
363
|
}
|
|
213
364
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
365
|
+
/**************
|
|
366
|
+
func: Systems
|
|
367
|
+
params: client: false
|
|
368
|
+
describe:
|
|
369
|
+
The Systems feature sets the correct variables and necessary rules for the
|
|
370
|
+
client presented data.
|
|
371
|
+
***************/
|
|
372
|
+
Systems() {
|
|
373
|
+
try {
|
|
374
|
+
if (!this._client.features.systems) return this.Solutions();
|
|
375
|
+
else {
|
|
376
|
+
this.state('setting_systems'); // set state to systems setting
|
|
377
|
+
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
378
|
+
const {systems} = features; // set systems from features const
|
|
379
|
+
this._systems = { // set this_systems with data
|
|
380
|
+
id: this.uid(true), // uuid of the systems feature
|
|
381
|
+
client_id: id, // client id for reference
|
|
382
|
+
client_name: profile.name, // client name for personalization
|
|
383
|
+
concerns: systems.concerns, // any concerns for client
|
|
384
|
+
global: systems.global, // the global policies for client
|
|
385
|
+
personal: systems.devas[this._agent.key] // Client personal features and rules.
|
|
386
|
+
};
|
|
387
|
+
delete this._client.features.systems
|
|
388
|
+
return this.Solutions()
|
|
389
|
+
}
|
|
390
|
+
} catch (e) {
|
|
391
|
+
// run error handling if an error is caught
|
|
392
|
+
return this.error(e)
|
|
228
393
|
}
|
|
229
394
|
}
|
|
230
395
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
396
|
+
/**************
|
|
397
|
+
func: Solutions
|
|
398
|
+
params: client: false
|
|
399
|
+
describe:
|
|
400
|
+
The Solutions feature sets the correct variables and necessary rules for the
|
|
401
|
+
client presented data.
|
|
402
|
+
***************/
|
|
403
|
+
Solutions() {
|
|
404
|
+
try {
|
|
405
|
+
if (!this._client.features.solutions) return this.Development();
|
|
406
|
+
else {
|
|
407
|
+
this.state('setting_solutions'); // set state to solutions setting
|
|
408
|
+
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
409
|
+
const {solutions} = features; // set solutions from features const
|
|
410
|
+
this._solutions = { // set this_solutions with data
|
|
411
|
+
id: this.uid(true), // uuid of the solutions feature
|
|
412
|
+
client_id: id, // client id for reference
|
|
413
|
+
client_name: profile.name, // client name for personalization
|
|
414
|
+
concerns: solutions.concerns, // any concerns for client
|
|
415
|
+
global: solutions.global, // the global policies for client
|
|
416
|
+
personal: solutions.devas[this._agent.key] // Client personal features and rules.
|
|
417
|
+
};
|
|
418
|
+
delete this._client.features.solutions
|
|
419
|
+
return this.Development()
|
|
420
|
+
}
|
|
421
|
+
} catch (e) {
|
|
422
|
+
return this.error(e) // run error handling if an error is caught
|
|
245
423
|
}
|
|
246
424
|
}
|
|
247
425
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
426
|
+
/**************
|
|
427
|
+
func: Development
|
|
428
|
+
params: client: false
|
|
429
|
+
describe:
|
|
430
|
+
The Development feature sets the correct variables and necessary rules for the
|
|
431
|
+
client presented data.
|
|
432
|
+
***************/
|
|
433
|
+
Development() {
|
|
434
|
+
try {
|
|
435
|
+
if (!this._client.features.development) return this.Business();
|
|
436
|
+
else {
|
|
437
|
+
this.state('setting_development'); // set state to development setting
|
|
438
|
+
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
439
|
+
const {development} = features; // set development from features const
|
|
440
|
+
this._development = { // set this_development with data
|
|
441
|
+
id: this.uid(true), // uuid of the development feature
|
|
442
|
+
client_id: id, // client id for reference
|
|
443
|
+
client_name: profile.name, // client name for personalization
|
|
444
|
+
hash: development.hash, // client preferred hash algorithm
|
|
445
|
+
cipher: development.cipher, // client preferred cipher settings
|
|
446
|
+
concerns: development.concerns, // any concerns for client
|
|
447
|
+
global: development.global, // the global policies for client
|
|
448
|
+
personal: development.devas[this._agent.key] // Client personal features and rules.
|
|
449
|
+
};
|
|
450
|
+
delete this._client.features.development
|
|
451
|
+
return this.Business()
|
|
452
|
+
}
|
|
453
|
+
} catch (e) {
|
|
454
|
+
return this.error(e) // run error handling if an error is caught
|
|
262
455
|
}
|
|
263
456
|
}
|
|
264
457
|
|
|
458
|
+
/**************
|
|
459
|
+
func: Business
|
|
460
|
+
params: client: false
|
|
461
|
+
describe:
|
|
462
|
+
The Business feature sets the correct variables and necessary rules for the
|
|
463
|
+
client presented data.
|
|
464
|
+
***************/
|
|
465
|
+
Business(client=false) {
|
|
466
|
+
try {
|
|
467
|
+
if (!this._client.features.business) return this.Legal();
|
|
468
|
+
else {
|
|
469
|
+
this.state('setting_business'); // set state to business setting
|
|
470
|
+
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
471
|
+
const {business} = features; // set business from features const
|
|
472
|
+
this._business = { // set this_business with data
|
|
473
|
+
id: this.uid(true), // uuid of the business feature
|
|
474
|
+
client_id: id, // client id for reference
|
|
475
|
+
client_name: profile.name, // client name for personalization
|
|
476
|
+
hash: business.hash, // client preferred hash algorithm
|
|
477
|
+
cipher: business.cipher, // client preferred cipher settings
|
|
478
|
+
concerns: business.concerns, // any concerns for client
|
|
479
|
+
global: business.global, // the global policies for client
|
|
480
|
+
personal: business.devas[this._agent.key] // Client personal features and rules.
|
|
481
|
+
};
|
|
482
|
+
delete this._client.features.business
|
|
483
|
+
return this.Legal();
|
|
484
|
+
}
|
|
485
|
+
} catch (e) {
|
|
486
|
+
return this.error(e) // run error handling if an error is caught
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**************
|
|
491
|
+
func: Legal
|
|
492
|
+
params: client: false
|
|
493
|
+
describe:
|
|
494
|
+
The Legal feature sets the correct variables and necessary rules for the
|
|
495
|
+
client presented data.
|
|
496
|
+
***************/
|
|
497
|
+
Legal() {
|
|
498
|
+
try {
|
|
499
|
+
if (!this._client.features.legal) this.Assistant();
|
|
500
|
+
else {
|
|
501
|
+
this.state('setting_legal'); // set state to legal setting
|
|
502
|
+
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
503
|
+
const {legal} = features; // set legal from features const
|
|
504
|
+
this._legal = { // set this_legal with data
|
|
505
|
+
id: this.uid(true), // uuid of the legal feature
|
|
506
|
+
client_id: id, // client id for reference
|
|
507
|
+
client_name: profile.name, // client name for personalization
|
|
508
|
+
hash: legal.hash, // client preferred hash algorithm
|
|
509
|
+
cipher: legal.cipher, // client preferred cipher settings
|
|
510
|
+
concerns: legal.concerns, // any concerns for client
|
|
511
|
+
global: legal.global, // the global policies for client
|
|
512
|
+
personal: legal.devas[this._agent.key] // Client personal features and rules.
|
|
513
|
+
};
|
|
514
|
+
delete this._client.features.legal;
|
|
515
|
+
return this.Assistant();
|
|
516
|
+
}
|
|
517
|
+
} catch (e) {
|
|
518
|
+
return this.error(e) // run error handling if an error is caught
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**************
|
|
523
|
+
func: Assistant
|
|
524
|
+
params: client: false
|
|
525
|
+
describe:
|
|
526
|
+
The Assistant feature sets the correct variables and necessary rules for the
|
|
527
|
+
client presented data.
|
|
528
|
+
***************/
|
|
529
|
+
Assistant(client=false) {
|
|
530
|
+
try {
|
|
531
|
+
if (!this._client.features.assistant) return this.Done();
|
|
532
|
+
else {
|
|
533
|
+
this.state('setting_assistant'); // set state to assistant setting
|
|
534
|
+
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
535
|
+
const {assistant} = features; // set assistant from features const
|
|
536
|
+
this._assistant = { // set this_assistant with data
|
|
537
|
+
id: this.uid(true), // uuid of the assistant feature
|
|
538
|
+
client_id: id, // client id for reference
|
|
539
|
+
client_name: profile.name, // client name for personalization
|
|
540
|
+
hash: assistant.hash, // client preferred hash algorithm
|
|
541
|
+
cipher: assistant.cipher, // client preferred cipher settings
|
|
542
|
+
concerns: assistant.concerns, // any concerns for client
|
|
543
|
+
global: assistant.global, // the global policies for client
|
|
544
|
+
personal: assistant.devas[this._agent.key] // Client personal features and rules.
|
|
545
|
+
};
|
|
546
|
+
delete this._client.features.legal;
|
|
547
|
+
return this.Done();
|
|
548
|
+
}
|
|
549
|
+
} catch (e) {
|
|
550
|
+
return this.error(e) // run error handling if an error is caught
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**************
|
|
555
|
+
func: Done
|
|
556
|
+
params: none
|
|
557
|
+
describe: The end of the workflow Client Feature Workflow
|
|
558
|
+
***************/
|
|
559
|
+
Done() {
|
|
560
|
+
try {
|
|
561
|
+
this.state('setting_done'); // set state to assistant setting
|
|
562
|
+
return;
|
|
563
|
+
} catch (e) {
|
|
564
|
+
return this.error(e);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
265
567
|
/**************
|
|
266
568
|
func: _assignBind
|
|
267
569
|
params: none
|
|
@@ -287,7 +589,7 @@ class Deva {
|
|
|
287
589
|
if (parse) this._agent.parse = this._agent.parse.bind(this);
|
|
288
590
|
}
|
|
289
591
|
catch (e) {
|
|
290
|
-
return
|
|
592
|
+
return this.error(e, false, reject);
|
|
291
593
|
}
|
|
292
594
|
finally {
|
|
293
595
|
return resolve();
|
|
@@ -322,7 +624,7 @@ class Deva {
|
|
|
322
624
|
}
|
|
323
625
|
}
|
|
324
626
|
catch (e) {
|
|
325
|
-
return
|
|
627
|
+
return this.error(e, false, reject);
|
|
326
628
|
}
|
|
327
629
|
finally {
|
|
328
630
|
return resolve();
|
|
@@ -349,7 +651,7 @@ class Deva {
|
|
|
349
651
|
}
|
|
350
652
|
}
|
|
351
653
|
catch (e) {
|
|
352
|
-
return
|
|
654
|
+
return this.error(e, false, reject);
|
|
353
655
|
}
|
|
354
656
|
finally {
|
|
355
657
|
return resolve();
|
|
@@ -404,7 +706,7 @@ class Deva {
|
|
|
404
706
|
***************/
|
|
405
707
|
state(st, data=false) {
|
|
406
708
|
if (!Object.keys(this._states).includes(st)) return;
|
|
407
|
-
this._state = `${this._states[st]}
|
|
709
|
+
this._state = `${this._states[st]} | ${this.formatDate(Date.now(), 'short_month', true)}`;
|
|
408
710
|
const _data = {
|
|
409
711
|
id: this.uid(true),
|
|
410
712
|
client: this._client.id,
|
|
@@ -453,15 +755,19 @@ class Deva {
|
|
|
453
755
|
describe:
|
|
454
756
|
The hash algorithm will take a string of text and produce a hash.
|
|
455
757
|
***************/
|
|
456
|
-
hash(str) {
|
|
457
|
-
|
|
758
|
+
hash(str, algo=false) {
|
|
759
|
+
algo = algo || this._security.hash || 'md5';
|
|
458
760
|
const the_hash = createHash(algo);
|
|
459
761
|
the_hash.update(str);
|
|
460
762
|
const _digest = the_hash.digest('base64');
|
|
461
763
|
this.state('hash', {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
764
|
+
id: this.uid(true),
|
|
765
|
+
value: _digest,
|
|
766
|
+
client_id: this._client.id,
|
|
767
|
+
agent_id: this._agent.id,
|
|
768
|
+
created: Date.now(),
|
|
769
|
+
});
|
|
770
|
+
return _digest;
|
|
465
771
|
}
|
|
466
772
|
|
|
467
773
|
/**************
|
|
@@ -584,38 +890,6 @@ class Deva {
|
|
|
584
890
|
return this.events.removeListener(evt, callback);
|
|
585
891
|
}
|
|
586
892
|
|
|
587
|
-
/**************
|
|
588
|
-
func: load
|
|
589
|
-
params:
|
|
590
|
-
-deva: The Deva model to load.
|
|
591
|
-
describe:
|
|
592
|
-
This function will enable fast loading of Deva into a system.
|
|
593
|
-
***************/
|
|
594
|
-
load(deva) {
|
|
595
|
-
this.state('deva_load');
|
|
596
|
-
this.devas[deva.key] = deva;
|
|
597
|
-
// inherit the data to the new deva.
|
|
598
|
-
this.inherit.forEach(inherit => {
|
|
599
|
-
this.devas[deva.key][inherit] = this[inherit];
|
|
600
|
-
});
|
|
601
|
-
this.state('deva_loaded');
|
|
602
|
-
return Promise.resolve();
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
/**************
|
|
607
|
-
func: unload
|
|
608
|
-
params:
|
|
609
|
-
- deva: The deva key to unload
|
|
610
|
-
describe: Unload a currently loaded Deva.
|
|
611
|
-
***************/
|
|
612
|
-
unload(deva) {
|
|
613
|
-
this.state('deva_unload');
|
|
614
|
-
delete this.devas[deva];
|
|
615
|
-
this.state('deva_unloaded');
|
|
616
|
-
return Promise.resolve(`unload:${deva} `);
|
|
617
|
-
}
|
|
618
|
-
|
|
619
893
|
/**************
|
|
620
894
|
func: ask
|
|
621
895
|
params: packet
|
|
@@ -693,11 +967,11 @@ class Deva {
|
|
|
693
967
|
describe:
|
|
694
968
|
***************/
|
|
695
969
|
question(TEXT=false, DATA=false) {
|
|
970
|
+
// check the active status
|
|
696
971
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
697
|
-
this.state('question_me', {text:TEXT, data:DATA});
|
|
698
|
-
|
|
699
|
-
const
|
|
700
|
-
const t_split = TEXT.split(' ');
|
|
972
|
+
this.state('question_me', {text:TEXT, data:DATA}); // set the question me state text TEXT & DATA passed in.
|
|
973
|
+
const id = this.uid(); // generate a unique id for transport.
|
|
974
|
+
const t_split = TEXT.split(' '); // split the text on spaces to get words.
|
|
701
975
|
|
|
702
976
|
// check to see if the string is an #ask string to talk to the other Deva.
|
|
703
977
|
const isAsk = t_split[0].startsWith(this.askChr);
|
|
@@ -706,98 +980,99 @@ class Deva {
|
|
|
706
980
|
const isCmd = t_split[0].startsWith(this.cmdChr);
|
|
707
981
|
|
|
708
982
|
// Format the packet for return on the request.
|
|
709
|
-
const orig = TEXT;
|
|
710
|
-
const data = DATA;
|
|
711
|
-
const packet = {
|
|
712
|
-
id,
|
|
713
|
-
q: {},
|
|
714
|
-
a: {},
|
|
715
|
-
created: Date.now(),
|
|
983
|
+
const orig = TEXT; // set the TEXT to orig
|
|
984
|
+
const data = DATA; // set the DATA to data
|
|
985
|
+
const packet = { // create the base q/a packet
|
|
986
|
+
id, // set the id into packet
|
|
987
|
+
q: {}, // create empty q object in packet
|
|
988
|
+
a: {}, // create empty a object in packet
|
|
989
|
+
created: Date.now(), // timestamp the packet
|
|
716
990
|
};
|
|
717
991
|
|
|
718
|
-
let text = TEXT,
|
|
719
|
-
params = false,
|
|
720
|
-
method = 'question',
|
|
721
|
-
key = this._agent.key;
|
|
992
|
+
let text = TEXT, // let TEXT is text for a manipulation variable
|
|
993
|
+
params = false, // params as false to build params string
|
|
994
|
+
method = 'question', // set the default method to question
|
|
995
|
+
key = this._agent.key; // set a temporary key from the agent key.
|
|
722
996
|
|
|
723
997
|
return new Promise((resolve, reject) => {
|
|
724
|
-
if
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
if (isAsk) {
|
|
738
|
-
_state = 'question_ask'
|
|
739
|
-
_state = 'hash_ask'
|
|
740
|
-
key = t_split[0].substring(1);
|
|
998
|
+
// resolve with the no text message if the client says nothing.
|
|
999
|
+
if (!TEXT) return resolve(this._messages.notext);
|
|
1000
|
+
// reject question if Deva offline
|
|
1001
|
+
if (!this._active) return resolve(this._messages.offline);
|
|
1002
|
+
|
|
1003
|
+
try { // try to answer the question
|
|
1004
|
+
let _state = 'question_default'; // set temporary question state variable
|
|
1005
|
+
let _hash = 'hash_asnwer'; // set emporary hash state variable
|
|
1006
|
+
if (isAsk) { // determine if hte question isAsk
|
|
1007
|
+
_state = 'question_ask' // if:isAk then set question state
|
|
1008
|
+
_state = 'hash_ask' // if:isAsk then set hash state
|
|
1009
|
+
key = t_split[0].substring(1); // if:isAsksplit the agent key and remove first command character
|
|
1010
|
+
//if:isAsk use text split index 1 as the parameter block
|
|
741
1011
|
params = t_split[1] ? t_split[1].split(':') : false;
|
|
742
|
-
method = params[0];
|
|
743
|
-
text = t_split.slice(2).join(' ').trim();
|
|
744
|
-
|
|
1012
|
+
method = params[0]; // the method to check is then params index 0
|
|
1013
|
+
text = t_split.slice(2).join(' ').trim(); // then rejoin the text with spaces.
|
|
745
1014
|
}
|
|
746
|
-
else if (isCmd) {
|
|
747
|
-
_state = 'question_command';
|
|
748
|
-
_hash = 'hash_command'
|
|
1015
|
+
else if (isCmd) { // determine if the question is a command
|
|
1016
|
+
_state = 'question_command'; // if:isCmd set question state
|
|
1017
|
+
_hash = 'hash_command' // if:isCmd set hash state
|
|
1018
|
+
//if:isCmd use text split index 1 as the parameter block
|
|
749
1019
|
params = t_split[1] ? t_split[1].split(':') : false;
|
|
750
|
-
method = t_split[0].substring(1);
|
|
751
|
-
text = t_split.slice(1).join(' ').trim()
|
|
1020
|
+
method = t_split[0].substring(1); // if:isCmd use the 0 index as the command
|
|
1021
|
+
text = t_split.slice(1).join(' ').trim(); // if:isCmd rejoin the string on the space after removing first index
|
|
752
1022
|
}
|
|
753
1023
|
|
|
754
|
-
packet.q = {
|
|
755
|
-
agent: this._agent || false,
|
|
756
|
-
client: this._client || false,
|
|
757
|
-
meta: {
|
|
758
|
-
key,
|
|
759
|
-
orig,
|
|
760
|
-
method,
|
|
761
|
-
params,
|
|
1024
|
+
packet.q = { // build packet.q container
|
|
1025
|
+
agent: this._agent || false, // set the agent
|
|
1026
|
+
client: this._client || false, // set the client
|
|
1027
|
+
meta: { // build the meta container
|
|
1028
|
+
key, // set the key variable
|
|
1029
|
+
orig, // set orig text to track chances
|
|
1030
|
+
method, // set method to track function use
|
|
1031
|
+
params, // set any params that are associated
|
|
762
1032
|
},
|
|
763
|
-
text,
|
|
764
|
-
data,
|
|
765
|
-
created: Date.now(),
|
|
1033
|
+
text, // set the text after it has been modified form orig
|
|
1034
|
+
data, // set the data object
|
|
1035
|
+
created: Date.now(), // timestamp the question
|
|
766
1036
|
}
|
|
767
1037
|
|
|
768
|
-
//
|
|
769
|
-
|
|
1038
|
+
this.state('hash_question'); // set the has question state
|
|
1039
|
+
// hash the question
|
|
770
1040
|
packet.q.meta.hash = this.hash(JSON.stringify(packet.q));
|
|
771
1041
|
|
|
772
|
-
this.state(_state, packet);
|
|
1042
|
+
this.state(_state, packet); // set the state to teh _state variable
|
|
773
1043
|
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
this.
|
|
777
|
-
|
|
1044
|
+
if (isAsk) { // isAsk check if the question isAsk and talk
|
|
1045
|
+
this.state('question_asking'); // if:isAsk set state to question asking
|
|
1046
|
+
this.talk(`${key}:ask`, packet); // if:isAsk talk the event to theother Deva
|
|
1047
|
+
// if: isAsk wait for the once event which is key'd to the packet ID for specified responses
|
|
778
1048
|
this.once(`${key}:ask:${packet.id}`, answer => {
|
|
779
|
-
return resolve(answer);
|
|
1049
|
+
return resolve(answer); // if:isAsk resolve the answer from the call
|
|
780
1050
|
});
|
|
781
1051
|
}
|
|
782
1052
|
|
|
783
|
-
//
|
|
784
|
-
else {
|
|
1053
|
+
else { // else: answer tue question locally
|
|
785
1054
|
this.state('question_answering');
|
|
786
|
-
if
|
|
787
|
-
|
|
1055
|
+
// check if method exists and is of type function
|
|
1056
|
+
if (this.methods[method] && typeof this.methods[method] !== 'function') {
|
|
1057
|
+
return resolve(this._methodNotFound(packet)); // resolve method not found if check if check fails
|
|
788
1058
|
}
|
|
789
|
-
|
|
1059
|
+
// Call the local method to process the question based the extracted parameters
|
|
1060
|
+
return this.methods[method](packet).then(result => {
|
|
1061
|
+
// check the result for the text, html, and data object.
|
|
1062
|
+
// this is for when answers are returned from nested Devas.
|
|
790
1063
|
const text = typeof result === 'object' ? result.text : result;
|
|
791
1064
|
const html = typeof result === 'object' ? result.html : result;
|
|
1065
|
+
// if the data passed is NOT an object it will FALSE
|
|
792
1066
|
const data = typeof result === 'object' ? result.data : false;
|
|
793
|
-
packet.a = {
|
|
794
|
-
agent: this._agent || false,
|
|
795
|
-
client: this._client || false,
|
|
796
|
-
meta: {
|
|
797
|
-
key: this._agent.key,
|
|
798
|
-
method,
|
|
1067
|
+
packet.a = { // setup the packet.a container
|
|
1068
|
+
agent: this._agent || false, // set the agent who answered the question
|
|
1069
|
+
client: this._client || false, // set the client asking the question
|
|
1070
|
+
meta: { // setup the answer meta container
|
|
1071
|
+
key: this._agent.key, // set the agent key inot the meta
|
|
1072
|
+
method, // set the method into the meta
|
|
1073
|
+
params, // set the params into the meta
|
|
799
1074
|
},
|
|
800
|
-
text,
|
|
1075
|
+
text, // set answer text
|
|
801
1076
|
html,
|
|
802
1077
|
data,
|
|
803
1078
|
created: Date.now(),
|
|
@@ -805,21 +1080,19 @@ class Deva {
|
|
|
805
1080
|
// create a hash for the answer and insert into answer meta.
|
|
806
1081
|
this.state(_hash);
|
|
807
1082
|
packet.a.meta.hash = this.hash(JSON.stringify(packet.a));
|
|
808
|
-
|
|
809
1083
|
// create a hash for entire packet and insert into packet
|
|
810
1084
|
this.state('hash_packet');
|
|
1085
|
+
// hash the entire packet.
|
|
811
1086
|
packet.hash = this.hash(JSON.stringify(packet));
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
return
|
|
816
|
-
}).catch(err => {
|
|
817
|
-
return this.error(err, packet);
|
|
1087
|
+
this.state('question_answer', packet); // set the question answer state
|
|
1088
|
+
return resolve(packet); // resolve the packet to the caller.
|
|
1089
|
+
}).catch(err => { // catch any errors in the method
|
|
1090
|
+
return this.error(err, packet, reject); // return this.error with err, packet, reject
|
|
818
1091
|
});
|
|
819
1092
|
}
|
|
820
1093
|
}
|
|
821
|
-
catch(e) {
|
|
822
|
-
return this.error(e);
|
|
1094
|
+
catch(e) { // try block error trap
|
|
1095
|
+
return this.error(e); // if a overall error happens this witll call this.error
|
|
823
1096
|
}
|
|
824
1097
|
});
|
|
825
1098
|
}
|
|
@@ -837,12 +1110,11 @@ class Deva {
|
|
|
837
1110
|
5. run the onInit custom function if preset or the system start function.
|
|
838
1111
|
6. The system start function will create a chain reaction of states that load.
|
|
839
1112
|
7. If there is an error the init function rejects the call.
|
|
1113
|
+
usage: this.init(client_object)
|
|
840
1114
|
***************/
|
|
841
1115
|
init(client) {
|
|
842
1116
|
// set client
|
|
843
1117
|
this.Client = client;
|
|
844
|
-
|
|
845
|
-
|
|
846
1118
|
this._active = Date.now();
|
|
847
1119
|
return new Promise((resolve, reject) => {
|
|
848
1120
|
this.events.setMaxListeners(this.maxListeners);
|
|
@@ -852,41 +1124,47 @@ class Deva {
|
|
|
852
1124
|
return this._assignListeners();
|
|
853
1125
|
}).then(() => {
|
|
854
1126
|
this.state('init');
|
|
855
|
-
|
|
856
|
-
this.Security = client;
|
|
857
|
-
this.Support = client;
|
|
858
|
-
this.Services = client;
|
|
859
|
-
this.Systems = client;
|
|
860
|
-
this.Solutions = client;
|
|
861
|
-
this.Development = client;
|
|
862
|
-
|
|
1127
|
+
this.Security();
|
|
863
1128
|
return this.onInit && typeof this.onInit === 'function' ? this.onInit() : this.start();
|
|
864
1129
|
}).then(started => {
|
|
865
1130
|
return resolve(started)
|
|
866
1131
|
}).catch(err => {
|
|
867
|
-
return
|
|
1132
|
+
return this.error(err, client, reject);
|
|
868
1133
|
});
|
|
869
1134
|
});
|
|
870
1135
|
}
|
|
871
1136
|
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
1137
|
+
/**************
|
|
1138
|
+
func: error
|
|
1139
|
+
params:
|
|
1140
|
+
- err: The error to process
|
|
1141
|
+
- data: Any additional data associated with the error
|
|
1142
|
+
- reject: An associated promise reject if the caller requires.
|
|
1143
|
+
describe:
|
|
1144
|
+
The erro function rpovides the consistent error manage of the system.
|
|
1145
|
+
usage: this.error(err, data, reject);
|
|
1146
|
+
***************/
|
|
1147
|
+
error(err,data=false,reject=false) {
|
|
1148
|
+
this.state('error', {err, data}); // set the state to error
|
|
1149
|
+
// check fo rthe custom onError function in the agent.
|
|
1150
|
+
if (this.onError && typeof this.onError === 'function') return this.onError(err, data, reject);
|
|
1151
|
+
else {
|
|
1152
|
+
console.log('\n::BEGIN:ERROR\n');
|
|
1153
|
+
console.log(err);
|
|
1154
|
+
console.log('\n::END:ERROR\n');
|
|
1155
|
+
return reject ? reject(err) : err;
|
|
1156
|
+
}
|
|
881
1157
|
}
|
|
882
1158
|
|
|
883
1159
|
/**************
|
|
884
1160
|
func: start
|
|
885
|
-
params:
|
|
1161
|
+
params:
|
|
1162
|
+
- msg: the message for use when using custome flow logic to pass to onEnter
|
|
886
1163
|
describe:
|
|
887
1164
|
The start function begins the process by setting the state to start setting
|
|
888
1165
|
the active to the current datetime and then checking for a custom onStart
|
|
889
1166
|
function or running the system enter function.
|
|
1167
|
+
usage: this.start('msg')
|
|
890
1168
|
***************/
|
|
891
1169
|
start(msg=false) {
|
|
892
1170
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
@@ -896,13 +1174,16 @@ class Deva {
|
|
|
896
1174
|
|
|
897
1175
|
/**************
|
|
898
1176
|
func: stop
|
|
899
|
-
params:
|
|
1177
|
+
params:
|
|
1178
|
+
- msg: hte message from the caller incase need to use in calls
|
|
900
1179
|
describe:
|
|
901
1180
|
The stop function will stop the Deva by setting the active status to false,
|
|
902
1181
|
and the state to stop. From here it will check for a custom onStop function
|
|
903
1182
|
for anything to run, or run the system exit function.
|
|
904
1183
|
|
|
905
1184
|
If the deva is offline it will return the offline message.
|
|
1185
|
+
usage:
|
|
1186
|
+
this.stop('msg')
|
|
906
1187
|
***************/
|
|
907
1188
|
stop(msg=false) {
|
|
908
1189
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
@@ -913,12 +1194,14 @@ class Deva {
|
|
|
913
1194
|
|
|
914
1195
|
/**************
|
|
915
1196
|
func: enter
|
|
916
|
-
params:
|
|
1197
|
+
params:
|
|
1198
|
+
- msg: hte message from the caller incase need to use in calls
|
|
917
1199
|
describe:
|
|
918
1200
|
The ener function will check the actie status of the Deva and set it to
|
|
919
1201
|
offline or enter.
|
|
920
1202
|
|
|
921
1203
|
If the Deva is offline it will return the offline message.
|
|
1204
|
+
usage: this.enter('msg')
|
|
922
1205
|
***************/
|
|
923
1206
|
enter(msg=false) {
|
|
924
1207
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
@@ -928,7 +1211,8 @@ class Deva {
|
|
|
928
1211
|
|
|
929
1212
|
/**************
|
|
930
1213
|
func: exit
|
|
931
|
-
params:
|
|
1214
|
+
params:
|
|
1215
|
+
- msg: hte message from the caller incase need to use in calls
|
|
932
1216
|
describe:
|
|
933
1217
|
The exit state function is triggered when the Deva is exiting it's online
|
|
934
1218
|
status and setting the state to exit for things like security check.
|
|
@@ -937,6 +1221,7 @@ class Deva {
|
|
|
937
1221
|
function.
|
|
938
1222
|
|
|
939
1223
|
If the deva is offline it will return the offline message.
|
|
1224
|
+
usage: this.exit('msg')
|
|
940
1225
|
***************/
|
|
941
1226
|
exit(msg=false) {
|
|
942
1227
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
@@ -948,12 +1233,13 @@ class Deva {
|
|
|
948
1233
|
/**************
|
|
949
1234
|
func: done
|
|
950
1235
|
params:
|
|
951
|
-
|
|
1236
|
+
- msg: hte message from the caller incase need to use in calls
|
|
952
1237
|
describe:
|
|
953
1238
|
When the done function is triggered the system will also set the state
|
|
954
1239
|
of hte Deva to done.
|
|
955
1240
|
|
|
956
1241
|
If the deva is offline it will return the offline message.
|
|
1242
|
+
usage: this.done('msg')
|
|
957
1243
|
***************/
|
|
958
1244
|
done(msg=false) {
|
|
959
1245
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
@@ -965,20 +1251,23 @@ class Deva {
|
|
|
965
1251
|
/**************
|
|
966
1252
|
func: status
|
|
967
1253
|
params:
|
|
968
|
-
-
|
|
1254
|
+
- msg: The msg is any additonal string to append to the end of hte call.
|
|
969
1255
|
describe:
|
|
970
1256
|
The status function provides an easy way to get the current status of a Deva
|
|
971
1257
|
and append custom status messages that may pertain to any custom status call.
|
|
972
1258
|
|
|
973
1259
|
If the deva is offline it will return the offline message.
|
|
1260
|
+
usage: this.status('msg')
|
|
974
1261
|
***************/
|
|
975
|
-
status(
|
|
1262
|
+
status(msg=false) {
|
|
1263
|
+
// check the active status
|
|
976
1264
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
977
|
-
|
|
978
|
-
const dateFormat =
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
1265
|
+
// format the date since active for output.
|
|
1266
|
+
const dateFormat = this.formatDate(this._active, 'long', true);
|
|
1267
|
+
// create the text msg string
|
|
1268
|
+
let text = `${this._features.systems.label}:STATUS ${this._agent.profile.name} active since ${dateFormat}`;
|
|
1269
|
+
if (msg) text = text + `\n${msg}`; // append the msg string if msg true.
|
|
1270
|
+
return text; // return final text string
|
|
982
1271
|
}
|
|
983
1272
|
|
|
984
1273
|
/**************
|
|
@@ -987,22 +1276,26 @@ class Deva {
|
|
|
987
1276
|
- text: The text string to send to the prompt.
|
|
988
1277
|
describe:-
|
|
989
1278
|
The prompt function is used to broadcasat a global prompt event with a string. Thsi is handy when passing events between a cli and user interface for example.
|
|
1279
|
+
|
|
1280
|
+
usage: this.prompt('text')
|
|
990
1281
|
***************/
|
|
991
1282
|
prompt(text) {
|
|
992
|
-
|
|
1283
|
+
// Talk a global prompt event for the client
|
|
1284
|
+
return this.talk(`prompt`, {text, agent:this._agent});
|
|
993
1285
|
}
|
|
994
1286
|
|
|
995
1287
|
/**************
|
|
996
1288
|
func: client
|
|
997
1289
|
params: none
|
|
998
1290
|
describe:
|
|
999
|
-
this function allows
|
|
1291
|
+
this function allows state management for when client prfioe is
|
|
1000
1292
|
being accessed.
|
|
1293
|
+
usage: this.client();
|
|
1001
1294
|
***************/
|
|
1002
1295
|
client() {
|
|
1003
|
-
if (!this._active) return this._messages.offline;
|
|
1004
|
-
this.state('client');
|
|
1005
|
-
return this._client;
|
|
1296
|
+
if (!this._active) return this._messages.offline; // check the active status
|
|
1297
|
+
this.state('client'); // set the client state
|
|
1298
|
+
return this._client; // return the client feature
|
|
1006
1299
|
}
|
|
1007
1300
|
|
|
1008
1301
|
/**************
|
|
@@ -1011,6 +1304,7 @@ class Deva {
|
|
|
1011
1304
|
describe:
|
|
1012
1305
|
this function allows statement management for when client prfioe is
|
|
1013
1306
|
being accessed.
|
|
1307
|
+
usage: this.agent()
|
|
1014
1308
|
***************/
|
|
1015
1309
|
agent() {
|
|
1016
1310
|
if (!this._active) return this._messages.offline;
|
|
@@ -1020,57 +1314,62 @@ class Deva {
|
|
|
1020
1314
|
|
|
1021
1315
|
/**************
|
|
1022
1316
|
func: security
|
|
1023
|
-
params:
|
|
1317
|
+
params: none
|
|
1024
1318
|
describe: basic security features available in a Deva.
|
|
1319
|
+
usage: this.security()
|
|
1025
1320
|
***************/
|
|
1026
|
-
security(
|
|
1027
|
-
if (!this._active) return this._messages.offline;
|
|
1028
|
-
this.state('security');
|
|
1029
|
-
return this._security;
|
|
1321
|
+
security() {
|
|
1322
|
+
if (!this._active) return this._messages.offline; // check the active status
|
|
1323
|
+
this.state('security'); // set the security state
|
|
1324
|
+
return this._security; // return the security feature
|
|
1030
1325
|
}
|
|
1031
1326
|
|
|
1032
1327
|
/**************
|
|
1033
|
-
func:
|
|
1034
|
-
params:
|
|
1328
|
+
func: support
|
|
1329
|
+
params: none
|
|
1035
1330
|
describe: basic support features available in a Deva.
|
|
1331
|
+
usage: this.support()
|
|
1036
1332
|
***************/
|
|
1037
|
-
support(
|
|
1038
|
-
if (!this._active) return this._messages.offline;
|
|
1039
|
-
this.state('support');
|
|
1040
|
-
return this._support;
|
|
1333
|
+
support() {
|
|
1334
|
+
if (!this._active) return this._messages.offline; // check the active status
|
|
1335
|
+
this.state('support'); // set the support state
|
|
1336
|
+
return this._support; // return the support feature
|
|
1041
1337
|
}
|
|
1042
1338
|
|
|
1043
1339
|
/**************
|
|
1044
|
-
func:
|
|
1045
|
-
params:
|
|
1340
|
+
func: services
|
|
1341
|
+
params: none
|
|
1046
1342
|
describe: basic services features available in a Deva.
|
|
1343
|
+
usage: this.services()
|
|
1047
1344
|
***************/
|
|
1048
1345
|
services(opts) {
|
|
1049
|
-
if (!this._active) return this._messages.offline;
|
|
1050
|
-
this.state('services');
|
|
1051
|
-
return this._services;
|
|
1346
|
+
if (!this._active) return this._messages.offline; // check the active status
|
|
1347
|
+
this.state('services'); // set the services state
|
|
1348
|
+
return this._services; // return the services feature
|
|
1052
1349
|
}
|
|
1053
1350
|
|
|
1054
1351
|
/**************
|
|
1055
1352
|
func: systems
|
|
1056
1353
|
params: opts
|
|
1057
1354
|
describe: basic systems features available in a Deva.
|
|
1355
|
+
usage: this.systems()
|
|
1058
1356
|
***************/
|
|
1059
1357
|
systems(opts) {
|
|
1060
|
-
if (!this._active) return this._messages.offline;
|
|
1061
|
-
this.state('systems');
|
|
1062
|
-
return this._systems;
|
|
1358
|
+
if (!this._active) return this._messages.offline; // check the active status
|
|
1359
|
+
this.state('systems'); // set the systems state
|
|
1360
|
+
return this._systems; // return the systems feature
|
|
1063
1361
|
}
|
|
1064
1362
|
|
|
1065
1363
|
/**************
|
|
1066
|
-
func:
|
|
1364
|
+
func: solutions
|
|
1067
1365
|
params: opts
|
|
1068
1366
|
describe: basic solutions features available in a Deva.
|
|
1367
|
+
usage: this.solutions()
|
|
1069
1368
|
***************/
|
|
1070
1369
|
solutions(opts) {
|
|
1071
|
-
if (!this._active) return this._messages.offline;
|
|
1072
|
-
this.state('solutions');
|
|
1073
|
-
return this._solutions;
|
|
1370
|
+
if (!this._active) return this._messages.offline; // check the active status
|
|
1371
|
+
this.state('solutions'); // set the solutions state
|
|
1372
|
+
return this._solutions; // return the solutions feature
|
|
1074
1373
|
}
|
|
1075
1374
|
|
|
1076
1375
|
/**************
|
|
@@ -1079,9 +1378,75 @@ class Deva {
|
|
|
1079
1378
|
describe: basic development features available in a Deva.
|
|
1080
1379
|
***************/
|
|
1081
1380
|
development(opts) {
|
|
1082
|
-
if (!this._active) return this._messages.offline;
|
|
1083
|
-
this.state('development');
|
|
1084
|
-
return this._development;
|
|
1381
|
+
if (!this._active) return this._messages.offline; // chek the active status
|
|
1382
|
+
this.state('development'); // set the development state
|
|
1383
|
+
return this._development; // return development feature
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
/**************
|
|
1387
|
+
func: assistant
|
|
1388
|
+
params: opts
|
|
1389
|
+
describe: basic assistant features available in a Deva.
|
|
1390
|
+
***************/
|
|
1391
|
+
assistant(opts) {
|
|
1392
|
+
if (!this._active) return this._messages.offline; // chek the active status
|
|
1393
|
+
this.state('assistant'); // set the assistant state
|
|
1394
|
+
return this._assistant; // return assistant feature
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
/**************
|
|
1398
|
+
func: business
|
|
1399
|
+
params: opts
|
|
1400
|
+
describe: basic business features available in a Deva.
|
|
1401
|
+
***************/
|
|
1402
|
+
business(opts) {
|
|
1403
|
+
if (!this._active) return this._messages.offline; // chek the active status
|
|
1404
|
+
this.state('business'); // set the business state
|
|
1405
|
+
return this._business; // return business feature
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
/**************
|
|
1409
|
+
func: legal
|
|
1410
|
+
params: opts
|
|
1411
|
+
describe: basic legal features available in a Deva.
|
|
1412
|
+
***************/
|
|
1413
|
+
legal(opts) {
|
|
1414
|
+
if (!this._active) return this._messages.offline; // chek the active status
|
|
1415
|
+
this.state('legal'); // set the legal state
|
|
1416
|
+
return this._legal; // return legal feature
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
/**************
|
|
1420
|
+
func: load
|
|
1421
|
+
params:
|
|
1422
|
+
-deva: The Deva model to load.
|
|
1423
|
+
describe:
|
|
1424
|
+
This function will enable fast loading of Deva into a system.
|
|
1425
|
+
***************/
|
|
1426
|
+
load(key, client) {
|
|
1427
|
+
return new Promise((resolve, reject) => {
|
|
1428
|
+
this.state('deva_load');
|
|
1429
|
+
this.devas[key].init(client).then(loaded => {
|
|
1430
|
+
this.state('deva_loaded');
|
|
1431
|
+
return resolve();
|
|
1432
|
+
}).catch(err => {
|
|
1433
|
+
return this.error(err, deva, reject);
|
|
1434
|
+
})
|
|
1435
|
+
});
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
|
|
1439
|
+
/**************
|
|
1440
|
+
func: unload
|
|
1441
|
+
params:
|
|
1442
|
+
- deva: The deva key to unload
|
|
1443
|
+
describe: Unload a currently loaded Deva.
|
|
1444
|
+
***************/
|
|
1445
|
+
unload(deva) {
|
|
1446
|
+
this.state('deva_unload');
|
|
1447
|
+
delete this.devas[deva];
|
|
1448
|
+
this.state('deva_unloaded');
|
|
1449
|
+
return Promise.resolve(`unload:${deva} `);
|
|
1085
1450
|
}
|
|
1086
1451
|
|
|
1087
1452
|
/**************
|
|
@@ -1091,16 +1456,22 @@ class Deva {
|
|
|
1091
1456
|
Start Devas will initialize the Deva agents inside this curent Deva.
|
|
1092
1457
|
***************/
|
|
1093
1458
|
startDevas(client) {
|
|
1094
|
-
this.state('devas_start');
|
|
1459
|
+
this.state('devas_start'); // set the devas start state
|
|
1095
1460
|
return new Promise((resolve, reject) => {
|
|
1096
|
-
const
|
|
1461
|
+
const loading = [];
|
|
1462
|
+
const _client = this.copy(client);
|
|
1097
1463
|
for (let x in this.devas) {
|
|
1098
|
-
|
|
1464
|
+
loading.push(this.load(x, client));
|
|
1099
1465
|
}
|
|
1100
|
-
Promise.all(
|
|
1101
|
-
this.state('devas_ready');
|
|
1102
|
-
return resolve({
|
|
1103
|
-
|
|
1466
|
+
Promise.all(loading).then(() => {
|
|
1467
|
+
this.state('devas_ready'); // set to ready state
|
|
1468
|
+
return resolve({ // return the response
|
|
1469
|
+
text:this._messages.devas_started, // include started state message
|
|
1470
|
+
prompt:this._agent.prompt, // include agent prompt settings
|
|
1471
|
+
});
|
|
1472
|
+
}).catch(err => { // catch any errors
|
|
1473
|
+
return this.error(err, client, reject); // send to error handler.
|
|
1474
|
+
});
|
|
1104
1475
|
});
|
|
1105
1476
|
}
|
|
1106
1477
|
/**************
|
|
@@ -1110,16 +1481,21 @@ class Deva {
|
|
|
1110
1481
|
stopDevas will stop all the devas running in the current Deva.
|
|
1111
1482
|
***************/
|
|
1112
1483
|
stopDevas() {
|
|
1113
|
-
this.state('devas_stop');
|
|
1484
|
+
this.state('devas_stop'); // set the devas stop state
|
|
1114
1485
|
return new Promise((resolve, reject) => {
|
|
1115
|
-
const devas = [];
|
|
1486
|
+
const devas = []; // create empty devas index
|
|
1116
1487
|
for (let x in this.devas) {
|
|
1117
|
-
devas.push(this.devas[x].stop());
|
|
1488
|
+
devas.push(this.devas[x].stop()); // push the deva to devas index
|
|
1118
1489
|
}
|
|
1119
1490
|
Promise.all(devas).then(() => {
|
|
1120
|
-
this.state('devas_stoped');
|
|
1121
|
-
return resolve(
|
|
1122
|
-
|
|
1491
|
+
this.state('devas_stoped'); // set the deva stopped state
|
|
1492
|
+
return resolve({
|
|
1493
|
+
text: this._messages.devas_stopped, // include stopped state message
|
|
1494
|
+
prompt: this._agent.prompt, // include agent prompt settings
|
|
1495
|
+
});
|
|
1496
|
+
}).catch(err => { // catch any errors
|
|
1497
|
+
return this.error(err, false, reject); // send to error handler
|
|
1498
|
+
});
|
|
1123
1499
|
});
|
|
1124
1500
|
}
|
|
1125
1501
|
|
|
@@ -1136,15 +1512,18 @@ class Deva {
|
|
|
1136
1512
|
FDate format ensures that consistent date formatting is used within the
|
|
1137
1513
|
system based on the language and locale in the client profile.
|
|
1138
1514
|
***************/
|
|
1139
|
-
formatDate(d, format='
|
|
1515
|
+
formatDate(d, format='milli', time=false) {
|
|
1140
1516
|
if (!d) d = Date.now();
|
|
1141
1517
|
d = new Date(d);
|
|
1142
1518
|
|
|
1519
|
+
if (format === 'milli') return d.getTime();
|
|
1520
|
+
// pre-set date formats for returning user dates.
|
|
1143
1521
|
const formats = {
|
|
1144
1522
|
long: { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' },
|
|
1145
1523
|
long_month: { year: 'numeric', month: 'long', day: 'numeric'},
|
|
1146
1524
|
short: { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric' },
|
|
1147
1525
|
short_month: { year: 'numeric', month: 'short', day: 'numeric' },
|
|
1526
|
+
numeric: { year: 'numeric', month: 'numeric', day: 'numeric' },
|
|
1148
1527
|
year: { year: 'numeric' },
|
|
1149
1528
|
month: { month: 'long' },
|
|
1150
1529
|
day: { day: 'long' },
|
|
@@ -1164,7 +1543,7 @@ class Deva {
|
|
|
1164
1543
|
parameter based on the locale setting in the client profile..
|
|
1165
1544
|
***************/
|
|
1166
1545
|
formatTime(t) {
|
|
1167
|
-
return t.toLocaleTimeString(this._client.locale);
|
|
1546
|
+
return t.toLocaleTimeString(this._client.locale); // return the formatted time string
|
|
1168
1547
|
}
|
|
1169
1548
|
|
|
1170
1549
|
/**************
|