@indra.ai/deva 1.1.34 → 1.1.36
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 +1 -1
- package/examples/client.json +14 -0
- package/examples/hello-world.js +14 -7
- package/index.js +855 -572
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -11,15 +11,15 @@ class Deva {
|
|
|
11
11
|
this._config = opts.config || {}; // local Config Object
|
|
12
12
|
this._agent = opts.agent || false; // Agent profile object
|
|
13
13
|
this._client = {}; // this will be set on init.
|
|
14
|
-
this.
|
|
14
|
+
this._message = 'offline'; // current state of agent.
|
|
15
15
|
this._active = false; // the active/birth date.
|
|
16
16
|
this._security = false; // inherited Security features.
|
|
17
17
|
this._support = false; // inherited Support features.
|
|
18
18
|
this._services = false; // inherited Service features.
|
|
19
|
-
this._assistant = false; // inherited
|
|
20
|
-
this._business = false; // inherited
|
|
21
|
-
this._development = false;
|
|
22
|
-
this._legal = false; // inherited
|
|
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.
|
|
23
23
|
this.events = opts.events || new EventEmitter({}); // Event Bus
|
|
24
24
|
this.lib = opts.lib || {}; // used for loading library functions
|
|
25
25
|
this.devas = opts.devas || {}; // Devas which are loaded
|
|
@@ -46,202 +46,223 @@ class Deva {
|
|
|
46
46
|
"_agent"
|
|
47
47
|
];
|
|
48
48
|
|
|
49
|
+
this._state = 'offline'; // current state of agent.
|
|
50
|
+
this._states = {
|
|
51
|
+
ask: 'ask',
|
|
52
|
+
question: 'question',
|
|
53
|
+
|
|
54
|
+
offline: 'offline',
|
|
55
|
+
online: 'online',
|
|
56
|
+
|
|
57
|
+
init: 'init',
|
|
58
|
+
start: 'start',
|
|
59
|
+
enter: 'enter',
|
|
60
|
+
stop: 'stop',
|
|
61
|
+
exit: 'exit',
|
|
62
|
+
error: 'error',
|
|
63
|
+
load: 'load',
|
|
64
|
+
unload: 'unload',
|
|
65
|
+
uid: 'uid',
|
|
66
|
+
hash: 'hash',
|
|
67
|
+
cipher: 'cipher',
|
|
68
|
+
decipher: 'deciper',
|
|
69
|
+
|
|
70
|
+
invalid: 'invalid',
|
|
71
|
+
done: 'done',
|
|
72
|
+
error: 'error',
|
|
73
|
+
}; // states object
|
|
74
|
+
|
|
75
|
+
this._zone = false; // current state of agent.
|
|
76
|
+
this._zones = {
|
|
77
|
+
deva: 'deva',
|
|
78
|
+
config: 'config',
|
|
79
|
+
features: 'features',
|
|
80
|
+
idle: 'idle',
|
|
81
|
+
train: 'training',
|
|
82
|
+
work: 'working',
|
|
83
|
+
invalid: 'invalid',
|
|
84
|
+
done: 'done',
|
|
85
|
+
error: 'error',
|
|
86
|
+
}; // states object
|
|
87
|
+
|
|
88
|
+
this._action = false;
|
|
89
|
+
this._actions = {
|
|
90
|
+
wait: 'wait',
|
|
91
|
+
question: 'question',
|
|
92
|
+
question_ask: 'question:ask',
|
|
93
|
+
question_ask_answer: 'question:ask:answer',
|
|
94
|
+
question_cmd: 'question:cmd',
|
|
95
|
+
question_method: 'question:method',
|
|
96
|
+
question_talk: 'quesiton:talk',
|
|
97
|
+
question_hash: 'question:hash',
|
|
98
|
+
question_answer: 'question:answer',
|
|
99
|
+
question_done: 'quesiton:done',
|
|
100
|
+
answer: 'answer',
|
|
101
|
+
answer_talk: 'answer:talk',
|
|
102
|
+
ask: 'ask',
|
|
103
|
+
ask_answer: 'ask:answer',
|
|
104
|
+
security: '#security',
|
|
105
|
+
Security: '@SECURITY',
|
|
106
|
+
support: '#support',
|
|
107
|
+
Support: '@SUPPORT',
|
|
108
|
+
systems: '#systems',
|
|
109
|
+
Systems: '@SYSTEMS',
|
|
110
|
+
services: '#services',
|
|
111
|
+
Services: '@SERVICES',
|
|
112
|
+
solutions: '#solutions',
|
|
113
|
+
Solutions: '@SOLUTIONS',
|
|
114
|
+
development: '#development',
|
|
115
|
+
Development: '@DEVELOPMENT',
|
|
116
|
+
business: '#business',
|
|
117
|
+
Business: '@Business',
|
|
118
|
+
legal: '#legal',
|
|
119
|
+
Legal: '@LEGAL',
|
|
120
|
+
assistant: '#assistant',
|
|
121
|
+
Assistant: '@ASSISTANT',
|
|
122
|
+
story: '#story',
|
|
123
|
+
Story: '@STORY',
|
|
124
|
+
mind: '#mind',
|
|
125
|
+
Mind: '@MIND',
|
|
126
|
+
client_data: 'client:data',
|
|
127
|
+
invalid: 'invalid',
|
|
128
|
+
error: 'error',
|
|
129
|
+
done: 'done',
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
this._feature = false;
|
|
49
133
|
this._features = {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
134
|
+
security: 'security',
|
|
135
|
+
Security: '@SECURITY',
|
|
136
|
+
support: 'support',
|
|
137
|
+
Support: '@SUPPORT',
|
|
138
|
+
services: 'services',
|
|
139
|
+
Services: '@SERVICES',
|
|
140
|
+
solutions: 'solutions',
|
|
141
|
+
Solutions: '@SOLUTIONS',
|
|
142
|
+
systems: 'systems',
|
|
143
|
+
Systems: '@SYSTEMS',
|
|
144
|
+
development: 'development',
|
|
145
|
+
Development: '@DEVELOPMENT',
|
|
146
|
+
business: 'business',
|
|
147
|
+
Business: '@BUSINESS',
|
|
148
|
+
legal:'legal',
|
|
149
|
+
Legal:'@LEGAL',
|
|
150
|
+
assistant: 'assistant',
|
|
151
|
+
Assistant: '@ASSISTANT',
|
|
152
|
+
story: 'story',
|
|
153
|
+
Story: '@STORY',
|
|
154
|
+
mind: 'mind',
|
|
155
|
+
Mind: '@MIND',
|
|
156
|
+
error: 'error',
|
|
157
|
+
done: 'done',
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
this._messages = {
|
|
161
|
+
states: {
|
|
162
|
+
offline: `${this._agent.profile.name} ofline`,
|
|
163
|
+
online: `${this._agent.profile.name} online`,
|
|
164
|
+
ask: `:${this._state.ask}`,
|
|
165
|
+
question: `${this._states.quesiton}`,
|
|
166
|
+
offline: `${this._states.offline}`,
|
|
167
|
+
online: `${this._states.online}`,
|
|
168
|
+
init: `${this._agent.profile.name} initialize`,
|
|
169
|
+
start: `${this._agent.profile.name} start`,
|
|
170
|
+
enter: `${this._agent.profile.name} enter`,
|
|
171
|
+
stop: `${this._agent.profile.name} stop`,
|
|
172
|
+
exit: `${this._agent.profile.name} exit`,
|
|
173
|
+
load: `${this._agent.profile.name} load`,
|
|
174
|
+
unload: `${this._agent.profile.name} unload`,
|
|
175
|
+
uid: `${this._states.uid}`,
|
|
176
|
+
hash: `${this._states.hash}`,
|
|
177
|
+
cipher: `${this._states.cipher}`,
|
|
178
|
+
decipher: `${this._states.decipher}`,
|
|
179
|
+
invalid: `${this._states.invalid}`,
|
|
180
|
+
done: `${this._agent.profile.name} is Done`,
|
|
181
|
+
error: `${this._states.error}`,
|
|
79
182
|
},
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
183
|
+
zones: {
|
|
184
|
+
deva: 'Deva',
|
|
185
|
+
config: 'Configuration',
|
|
186
|
+
features: 'Features',
|
|
187
|
+
idle: 'Idle',
|
|
188
|
+
train: `${this._zones.train}`,
|
|
189
|
+
work: `${this._zones.work}`,
|
|
190
|
+
invalid: `${this._zones.invalid}`,
|
|
191
|
+
done: `${this._zones.done}`,
|
|
192
|
+
error: `${this._zones.error}`,
|
|
85
193
|
},
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
194
|
+
actions: {
|
|
195
|
+
wait: `${this._agent.profile.name} ${this._actions.wait}`,
|
|
196
|
+
question: `${this._agent.profile.name} ${this._actions.question}`,
|
|
197
|
+
question_ask: `${this._agent.profile.name} ${this._actions.question_ask}`,
|
|
198
|
+
question_ask_answer: `${this._agent.profile.name} ${this._actions.questoin_ask_answer}`,
|
|
199
|
+
question_cmd: `${this._agent.profile.name} ${this._actions.question_cmd}`,
|
|
200
|
+
question_method: `${this._agent.profile.name} ${this._actions.question_method}`,
|
|
201
|
+
question_talk: `${this._agent.profile.name} ${this._actions.question_talk}`,
|
|
202
|
+
question_hash: `${this._agent.profile.name} ${this._actions.question_hash}`,
|
|
203
|
+
question_answer: `${this._agent.profile.name} ${this._actions.question_answer}`,
|
|
204
|
+
question_done: `${this._agent.profile.name} ${this._actions.question_done}`,
|
|
205
|
+
answer: `${this._agent.profile.name} ${this._actions.answer}`,
|
|
206
|
+
answer_talk: `${this._agent.profile.name} ${this._actions.answer_talk}`,
|
|
207
|
+
ask: `${this._agent.profile.name} ${this._actions.ask}`,
|
|
208
|
+
ask_answer: `${this._agent.profile.name} ${this._actions.ask_answer}`,
|
|
209
|
+
security: `${this._actions.security} is responding`,
|
|
210
|
+
Security: `${this._actions.Security} is guarding`,
|
|
211
|
+
support: `${this._actions.support} is responding`,
|
|
212
|
+
Support: `${this._actions.Support} is caring`,
|
|
213
|
+
services: `${this._actions.Services} is responding`,
|
|
214
|
+
Services: `${this._actions.Services} is servicing`,
|
|
215
|
+
solutions: `${this._actions.solutions} is responding`,
|
|
216
|
+
Solutions: `${this._actions.Solutions} is providing`,
|
|
217
|
+
solutions: `${this._actions.Systems} is responding`,
|
|
218
|
+
Systems: `${this._actions.Systems} is delivering`,
|
|
219
|
+
development: `${this._actions.Development} is responding`,
|
|
220
|
+
Development: `${this._actions.Development} is building`,
|
|
221
|
+
business: `${this._actions.Business} is responding`,
|
|
222
|
+
Business: `${this._actions.Business} is successful`,
|
|
223
|
+
legal: `${this._actions.Legal} is responding`,
|
|
224
|
+
Legal: `${this._actions.Legal} is doing their job`,
|
|
225
|
+
assistant: `${this._actions.Assistant} is responding`,
|
|
226
|
+
Assistant: `${this._actions.Assistant} is helping`,
|
|
227
|
+
story: `${this._actions.Story} is responding`,
|
|
228
|
+
Story: `${this._actions.Story} is inspiring`,
|
|
229
|
+
mind: `${this._actions.Mind} is responding`,
|
|
230
|
+
Mind: `${this._actions.Mind} is thinking and pondering`,
|
|
231
|
+
client_data: `Client Data`,
|
|
232
|
+
invalid: `${this._actions.invalid}`,
|
|
233
|
+
done: `${this._actions.done}`,
|
|
234
|
+
error: `${this._action.error}`,
|
|
91
235
|
},
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
236
|
+
features: {
|
|
237
|
+
security: `${this._features.security} is protecting`,
|
|
238
|
+
Security: `${this._features.Security} is configuring`,
|
|
239
|
+
support: `${this._features.support} is caring`,
|
|
240
|
+
Support: `${this._features.Support} is configuring`,
|
|
241
|
+
services: `${this._features.services} is servicing`,
|
|
242
|
+
Services: `${this._features.Services} is configuring`,
|
|
243
|
+
solutions: `${this._features.solutions} is solving`,
|
|
244
|
+
Solutions: `${this._features.Solutions} is configuring`,
|
|
245
|
+
systems: `${this._features.systems} is mantaining`,
|
|
246
|
+
Systems: `${this._features.Systems} is configuring`,
|
|
247
|
+
development: `${this._features.development} is developing`,
|
|
248
|
+
Development: `${this._features.Development} is working on ideas`,
|
|
249
|
+
business: `${this._features.business} is successful`,
|
|
250
|
+
Business: `${this._features.Business} is configuring`,
|
|
251
|
+
legal: `${this._features.legal} is upholding the law`,
|
|
252
|
+
Legal: `${this._features.Legal} is configuring`,
|
|
253
|
+
assistant: `${this._features.assistant} is assisting`,
|
|
254
|
+
Assistant: `${this._features.Assistant} is configuring`,
|
|
255
|
+
story: `${this._features.story} is creating`,
|
|
256
|
+
Story: `${this._features.Story} is configuring`,
|
|
257
|
+
mind: `${this._features.story} is thinking and pondering`,
|
|
258
|
+
Mind: `${this._features.Mind} is configuring`,
|
|
259
|
+
invalid: this._features.invalid,
|
|
260
|
+
done: this._features.done,
|
|
261
|
+
error: this._features.error,
|
|
97
262
|
},
|
|
98
|
-
|
|
99
|
-
label: '🔧SYSTEMS',
|
|
100
|
-
name: '@SYSTEMS',
|
|
101
|
-
tag: '#SYSTEMS',
|
|
102
|
-
loc: '$SYSTEMS',
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
this._states = {}; // states object
|
|
106
|
-
this._messages = {}; // messages object
|
|
263
|
+
}; // messages object
|
|
107
264
|
}
|
|
108
265
|
|
|
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;
|
|
127
|
-
|
|
128
|
-
const _states = {
|
|
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 @${ckey} #${ckey} $${ckey}`,
|
|
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`,
|
|
216
|
-
}
|
|
217
|
-
this._states = _states; // The available states to work with.
|
|
218
|
-
}
|
|
219
|
-
|
|
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 = {
|
|
230
|
-
offline: `🙅♂️ ${this._agent.profile.name} offline`,
|
|
231
|
-
init: `⚠️ ${this._agent.profile.name} init`,
|
|
232
|
-
start: `✅ ${this._agent.profile.name} start`,
|
|
233
|
-
stop: `💥 ${this._agent.profile.name} stop.`,
|
|
234
|
-
enter: `🖖 ${this._agent.profile.name} enter.`,
|
|
235
|
-
exit: `🚪 ${this._agent.profile.name} exit.`,
|
|
236
|
-
done: `👍 ${this._agent.profile.name} done.`,
|
|
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.`,
|
|
241
|
-
method_not_found: `❌ ${this._client.profile.name} you sure messed that up!`,
|
|
242
|
-
}
|
|
243
|
-
this._messages = this.copy(_messages); // set a copy of _messages as this._messages;
|
|
244
|
-
}
|
|
245
266
|
|
|
246
267
|
/**************
|
|
247
268
|
func: Client
|
|
@@ -253,21 +274,11 @@ class Deva {
|
|
|
253
274
|
usage:
|
|
254
275
|
this.Client = {data}
|
|
255
276
|
***************/
|
|
256
|
-
|
|
277
|
+
Client(client) {
|
|
278
|
+
this.action('client_data');
|
|
257
279
|
const _client = this.copy(client); // copy the client parameter
|
|
258
280
|
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
|
|
281
|
+
return Promise.resolve();
|
|
271
282
|
}
|
|
272
283
|
|
|
273
284
|
/**************
|
|
@@ -278,10 +289,11 @@ class Deva {
|
|
|
278
289
|
client presented data.
|
|
279
290
|
***************/
|
|
280
291
|
Security() {
|
|
292
|
+
this.feature('Security');
|
|
281
293
|
try {
|
|
282
294
|
if (!this._client.features.security) return this.Support();
|
|
283
295
|
else {
|
|
284
|
-
this.
|
|
296
|
+
this.action('Security');
|
|
285
297
|
const {id, profile, features} = this._client; // make a copy the clinet data.
|
|
286
298
|
const {security} = features; // make a copy the clinet data.
|
|
287
299
|
this._security = { // set this_security with data
|
|
@@ -298,6 +310,8 @@ class Deva {
|
|
|
298
310
|
return this.Support();
|
|
299
311
|
}
|
|
300
312
|
} catch (e) {
|
|
313
|
+
this.action('error');
|
|
314
|
+
this.feature('error');
|
|
301
315
|
return this.error(e) // run error handling if an error is caught
|
|
302
316
|
}
|
|
303
317
|
}
|
|
@@ -310,10 +324,11 @@ class Deva {
|
|
|
310
324
|
client presented data.
|
|
311
325
|
***************/
|
|
312
326
|
Support() {
|
|
327
|
+
this.feature('Support'); // set state to support setting
|
|
313
328
|
try {
|
|
314
329
|
if (!this._client.features.support) return this.Services()
|
|
315
330
|
else {
|
|
316
|
-
this.
|
|
331
|
+
this.action('Support');
|
|
317
332
|
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
318
333
|
const {support} = features; // set support from features const
|
|
319
334
|
this._support = { // set this_support with data
|
|
@@ -328,6 +343,8 @@ class Deva {
|
|
|
328
343
|
return this.Services();
|
|
329
344
|
}
|
|
330
345
|
} catch (e) {
|
|
346
|
+
this.action('error');
|
|
347
|
+
this.feature('error');
|
|
331
348
|
return this.error(e) // run error handling if an error is caught
|
|
332
349
|
}
|
|
333
350
|
}
|
|
@@ -340,10 +357,11 @@ class Deva {
|
|
|
340
357
|
client presented data.
|
|
341
358
|
***************/
|
|
342
359
|
Services() {
|
|
360
|
+
this.feature('Services'); // set state to security setting
|
|
343
361
|
try {
|
|
344
362
|
if (!this._client.features.services) return this.Systems();
|
|
345
363
|
else {
|
|
346
|
-
this.
|
|
364
|
+
this.action('Services')
|
|
347
365
|
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
348
366
|
const {services} = features; // set services from features const
|
|
349
367
|
this._services = { // set this_services with data
|
|
@@ -358,6 +376,8 @@ class Deva {
|
|
|
358
376
|
return this.Systems()
|
|
359
377
|
}
|
|
360
378
|
} catch (e) {
|
|
379
|
+
this.action('error');
|
|
380
|
+
this.feature('error');
|
|
361
381
|
return this.error(e) // run error handling if an error is caught
|
|
362
382
|
}
|
|
363
383
|
}
|
|
@@ -370,10 +390,11 @@ class Deva {
|
|
|
370
390
|
client presented data.
|
|
371
391
|
***************/
|
|
372
392
|
Systems() {
|
|
393
|
+
this.feature('Systems'); // set state to systems setting
|
|
373
394
|
try {
|
|
374
395
|
if (!this._client.features.systems) return this.Solutions();
|
|
375
396
|
else {
|
|
376
|
-
this.
|
|
397
|
+
this.action('Systems');
|
|
377
398
|
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
378
399
|
const {systems} = features; // set systems from features const
|
|
379
400
|
this._systems = { // set this_systems with data
|
|
@@ -389,6 +410,8 @@ class Deva {
|
|
|
389
410
|
}
|
|
390
411
|
} catch (e) {
|
|
391
412
|
// run error handling if an error is caught
|
|
413
|
+
this.action('error');
|
|
414
|
+
this.feature('error');
|
|
392
415
|
return this.error(e)
|
|
393
416
|
}
|
|
394
417
|
}
|
|
@@ -401,10 +424,11 @@ class Deva {
|
|
|
401
424
|
client presented data.
|
|
402
425
|
***************/
|
|
403
426
|
Solutions() {
|
|
427
|
+
this.feature('Solutions'); // set state to solutions setting
|
|
404
428
|
try {
|
|
405
429
|
if (!this._client.features.solutions) return this.Development();
|
|
406
430
|
else {
|
|
407
|
-
this.
|
|
431
|
+
this.action('Solutions');
|
|
408
432
|
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
409
433
|
const {solutions} = features; // set solutions from features const
|
|
410
434
|
this._solutions = { // set this_solutions with data
|
|
@@ -419,6 +443,8 @@ class Deva {
|
|
|
419
443
|
return this.Development()
|
|
420
444
|
}
|
|
421
445
|
} catch (e) {
|
|
446
|
+
this.action('error');
|
|
447
|
+
this.feature('error');
|
|
422
448
|
return this.error(e) // run error handling if an error is caught
|
|
423
449
|
}
|
|
424
450
|
}
|
|
@@ -431,18 +457,17 @@ class Deva {
|
|
|
431
457
|
client presented data.
|
|
432
458
|
***************/
|
|
433
459
|
Development() {
|
|
460
|
+
this.feature('Development'); // set state to development setting
|
|
434
461
|
try {
|
|
435
462
|
if (!this._client.features.development) return this.Business();
|
|
436
463
|
else {
|
|
437
|
-
this.
|
|
464
|
+
this.action('Development');
|
|
438
465
|
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
439
466
|
const {development} = features; // set development from features const
|
|
440
467
|
this._development = { // set this_development with data
|
|
441
468
|
id: this.uid(true), // uuid of the development feature
|
|
442
469
|
client_id: id, // client id for reference
|
|
443
470
|
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
471
|
concerns: development.concerns, // any concerns for client
|
|
447
472
|
global: development.global, // the global policies for client
|
|
448
473
|
personal: development.devas[this._agent.key] // Client personal features and rules.
|
|
@@ -451,6 +476,8 @@ class Deva {
|
|
|
451
476
|
return this.Business()
|
|
452
477
|
}
|
|
453
478
|
} catch (e) {
|
|
479
|
+
this.action('error');
|
|
480
|
+
this.feature('error');
|
|
454
481
|
return this.error(e) // run error handling if an error is caught
|
|
455
482
|
}
|
|
456
483
|
}
|
|
@@ -463,18 +490,17 @@ class Deva {
|
|
|
463
490
|
client presented data.
|
|
464
491
|
***************/
|
|
465
492
|
Business(client=false) {
|
|
493
|
+
this.feature('Business'); // set state to business setting
|
|
466
494
|
try {
|
|
467
495
|
if (!this._client.features.business) return this.Legal();
|
|
468
496
|
else {
|
|
469
|
-
this.
|
|
497
|
+
this.action('Business');
|
|
470
498
|
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
471
499
|
const {business} = features; // set business from features const
|
|
472
500
|
this._business = { // set this_business with data
|
|
473
501
|
id: this.uid(true), // uuid of the business feature
|
|
474
502
|
client_id: id, // client id for reference
|
|
475
503
|
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
504
|
concerns: business.concerns, // any concerns for client
|
|
479
505
|
global: business.global, // the global policies for client
|
|
480
506
|
personal: business.devas[this._agent.key] // Client personal features and rules.
|
|
@@ -483,6 +509,8 @@ class Deva {
|
|
|
483
509
|
return this.Legal();
|
|
484
510
|
}
|
|
485
511
|
} catch (e) {
|
|
512
|
+
this.action('error');
|
|
513
|
+
this.feature('error');
|
|
486
514
|
return this.error(e) // run error handling if an error is caught
|
|
487
515
|
}
|
|
488
516
|
}
|
|
@@ -495,18 +523,17 @@ class Deva {
|
|
|
495
523
|
client presented data.
|
|
496
524
|
***************/
|
|
497
525
|
Legal() {
|
|
526
|
+
this.feature('Legal'); // set state to legal setting
|
|
498
527
|
try {
|
|
499
528
|
if (!this._client.features.legal) this.Assistant();
|
|
500
529
|
else {
|
|
501
|
-
this.
|
|
530
|
+
this.action('Legal');
|
|
502
531
|
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
503
532
|
const {legal} = features; // set legal from features const
|
|
504
533
|
this._legal = { // set this_legal with data
|
|
505
534
|
id: this.uid(true), // uuid of the legal feature
|
|
506
535
|
client_id: id, // client id for reference
|
|
507
536
|
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
537
|
concerns: legal.concerns, // any concerns for client
|
|
511
538
|
global: legal.global, // the global policies for client
|
|
512
539
|
personal: legal.devas[this._agent.key] // Client personal features and rules.
|
|
@@ -527,26 +554,91 @@ class Deva {
|
|
|
527
554
|
client presented data.
|
|
528
555
|
***************/
|
|
529
556
|
Assistant(client=false) {
|
|
557
|
+
this.feature('Assistant'); // set state to assistant setting
|
|
530
558
|
try {
|
|
531
559
|
if (!this._client.features.assistant) return this.Done();
|
|
532
560
|
else {
|
|
533
|
-
this.
|
|
561
|
+
this.action('Assistant');
|
|
534
562
|
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
535
563
|
const {assistant} = features; // set assistant from features const
|
|
536
564
|
this._assistant = { // set this_assistant with data
|
|
537
565
|
id: this.uid(true), // uuid of the assistant feature
|
|
538
566
|
client_id: id, // client id for reference
|
|
539
567
|
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
568
|
concerns: assistant.concerns, // any concerns for client
|
|
543
569
|
global: assistant.global, // the global policies for client
|
|
544
570
|
personal: assistant.devas[this._agent.key] // Client personal features and rules.
|
|
545
571
|
};
|
|
546
|
-
delete this._client.features.
|
|
572
|
+
delete this._client.features.assistant;
|
|
573
|
+
return this.Story();
|
|
574
|
+
}
|
|
575
|
+
} catch (e) {
|
|
576
|
+
return this.error(e) // run error handling if an error is caught
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**************
|
|
581
|
+
func: Story
|
|
582
|
+
params: client: false
|
|
583
|
+
describe:
|
|
584
|
+
The Story feature sets the correct variables and necessary rules for the
|
|
585
|
+
client presented data.
|
|
586
|
+
***************/
|
|
587
|
+
Story(client=false) {
|
|
588
|
+
this.feature('Story'); // set state to story setting
|
|
589
|
+
try {
|
|
590
|
+
if (!this._client.features.story) return this.Mind();
|
|
591
|
+
else {
|
|
592
|
+
this.action('Story');
|
|
593
|
+
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
594
|
+
const {story} = features; // set story from features const
|
|
595
|
+
this._story = { // set this_story with data
|
|
596
|
+
id: this.uid(true), // uuid of the story feature
|
|
597
|
+
client_id: id, // client id for reference
|
|
598
|
+
client_name: profile.name, // client name for personalization
|
|
599
|
+
concerns: story.concerns, // any concerns for client
|
|
600
|
+
global: story.global, // the global policies for client
|
|
601
|
+
personal: story.devas[this._agent.key] // Client personal features and rules.
|
|
602
|
+
};
|
|
603
|
+
delete this._client.features.story;
|
|
604
|
+
return this.Mind();
|
|
605
|
+
}
|
|
606
|
+
} catch (e) {
|
|
607
|
+
this.action('error');
|
|
608
|
+
this.feature('error');
|
|
609
|
+
return this.error(e) // run error handling if an error is caught
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/**************
|
|
614
|
+
func: Mind
|
|
615
|
+
params: client: false
|
|
616
|
+
describe:
|
|
617
|
+
The Mind feature sets the correct variables and necessary rules for the
|
|
618
|
+
client presented data.
|
|
619
|
+
***************/
|
|
620
|
+
Mind(client=false) {
|
|
621
|
+
this.feature('Mind'); // set state to story setting
|
|
622
|
+
try {
|
|
623
|
+
if (!this._client.features.mind) return this.Done();
|
|
624
|
+
else {
|
|
625
|
+
this.action('Mind');
|
|
626
|
+
const {id, features, profile} = this._client; // set the local consts from client copy
|
|
627
|
+
const {mind} = features; // set mind from features const
|
|
628
|
+
this._mind = { // set this_mind with data
|
|
629
|
+
id: this.uid(true), // uuid of the mind feature
|
|
630
|
+
client_id: id, // client id for reference
|
|
631
|
+
client_name: profile.name, // client name for personalization
|
|
632
|
+
concerns: mind.concerns, // any concerns for client
|
|
633
|
+
global: mind.global, // the global policies for client
|
|
634
|
+
personal: mind.devas[this._agent.key] // Client personal features and rules.
|
|
635
|
+
};
|
|
636
|
+
delete this._client.features.mind;
|
|
547
637
|
return this.Done();
|
|
548
638
|
}
|
|
549
639
|
} catch (e) {
|
|
640
|
+
this.action('error');
|
|
641
|
+
this.feature('error');
|
|
550
642
|
return this.error(e) // run error handling if an error is caught
|
|
551
643
|
}
|
|
552
644
|
}
|
|
@@ -557,12 +649,16 @@ class Deva {
|
|
|
557
649
|
describe: The end of the workflow Client Feature Workflow
|
|
558
650
|
***************/
|
|
559
651
|
Done() {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
652
|
+
return new Promise((resolve, reject) => {
|
|
653
|
+
try {
|
|
654
|
+
delete this._client.features; // delete the features key when done.
|
|
655
|
+
this.feature('done'); // set state to assistant setting
|
|
656
|
+
return resolve();
|
|
657
|
+
} catch (e) {
|
|
658
|
+
this.feature('error')
|
|
659
|
+
return this.error(e, false, reject);
|
|
660
|
+
}
|
|
661
|
+
});
|
|
566
662
|
}
|
|
567
663
|
/**************
|
|
568
664
|
func: _assignBind
|
|
@@ -608,6 +704,7 @@ class Deva {
|
|
|
608
704
|
return new Promise((resolve, reject) => {
|
|
609
705
|
try {
|
|
610
706
|
// set the default listeners for the states of the agent.
|
|
707
|
+
|
|
611
708
|
for (let state in this._states) {
|
|
612
709
|
if (typeof this[state] === 'function') {
|
|
613
710
|
this.events.on(`${this._agent.key}:${state}`, packet => {
|
|
@@ -622,13 +719,11 @@ class Deva {
|
|
|
622
719
|
return this.listeners[listener](packet);
|
|
623
720
|
})
|
|
624
721
|
}
|
|
722
|
+
return resolve();
|
|
625
723
|
}
|
|
626
724
|
catch (e) {
|
|
627
725
|
return this.error(e, false, reject);
|
|
628
726
|
}
|
|
629
|
-
finally {
|
|
630
|
-
return resolve();
|
|
631
|
-
}
|
|
632
727
|
});
|
|
633
728
|
}
|
|
634
729
|
|
|
@@ -649,13 +744,11 @@ class Deva {
|
|
|
649
744
|
this.devas[d][inherit] = this[inherit];
|
|
650
745
|
});
|
|
651
746
|
}
|
|
747
|
+
return resolve();
|
|
652
748
|
}
|
|
653
749
|
catch (e) {
|
|
654
750
|
return this.error(e, false, reject);
|
|
655
751
|
}
|
|
656
|
-
finally {
|
|
657
|
-
return resolve();
|
|
658
|
-
}
|
|
659
752
|
});
|
|
660
753
|
}
|
|
661
754
|
|
|
@@ -678,7 +771,7 @@ class Deva {
|
|
|
678
771
|
packet.a = {
|
|
679
772
|
agent: this._agent || false,
|
|
680
773
|
client: this._client || false,
|
|
681
|
-
text: `${this._messages.method_not_found}
|
|
774
|
+
text: `${this._messages.method_not_found}`,
|
|
682
775
|
meta: {
|
|
683
776
|
key: this._agent.key,
|
|
684
777
|
method: packet.q.meta.method,
|
|
@@ -698,149 +791,6 @@ class Deva {
|
|
|
698
791
|
return this._states;
|
|
699
792
|
}
|
|
700
793
|
|
|
701
|
-
/**************
|
|
702
|
-
func: state
|
|
703
|
-
params:
|
|
704
|
-
- st: The state flag to set for the Deva that matches to this._states
|
|
705
|
-
describe
|
|
706
|
-
***************/
|
|
707
|
-
state(st, data=false) {
|
|
708
|
-
if (!Object.keys(this._states).includes(st)) return;
|
|
709
|
-
this._state = `${this._states[st]} | ${this.formatDate(Date.now(), 'short_month', true)}`;
|
|
710
|
-
const _data = {
|
|
711
|
-
id: this.uid(true),
|
|
712
|
-
client: this._client.id,
|
|
713
|
-
agent: this._agent.id,
|
|
714
|
-
st: st,
|
|
715
|
-
state: this._state,
|
|
716
|
-
data,
|
|
717
|
-
created: Date.now(),
|
|
718
|
-
};
|
|
719
|
-
this.prompt(this._state);
|
|
720
|
-
this.talk(`${this._agent.key}:state`, _data);
|
|
721
|
-
return this._state;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
/**************
|
|
725
|
-
func: uid
|
|
726
|
-
params:
|
|
727
|
-
- guid: This is a true false flag for generating a guid.
|
|
728
|
-
describe:
|
|
729
|
-
The uid function can create two types of id for you.
|
|
730
|
-
1. random GUID - this is good for when you need a uinique record id returned
|
|
731
|
-
2. transport id - The transport id is a number generated to provide a
|
|
732
|
-
numerical number used for transporting records to places
|
|
733
|
-
like social networks, email, other networks where informaton
|
|
734
|
-
is shared.
|
|
735
|
-
***************/
|
|
736
|
-
uid(guid=false) {
|
|
737
|
-
let id;
|
|
738
|
-
if (guid) {
|
|
739
|
-
id = randomUUID()
|
|
740
|
-
}
|
|
741
|
-
else {
|
|
742
|
-
const min = Math.floor(Date.now() - (Date.now() / Math.PI));
|
|
743
|
-
const max = Math.floor(Date.now() + (Date.now() * Math.PI));
|
|
744
|
-
id = Math.floor(Math.random() * (max - min)) + min;
|
|
745
|
-
}
|
|
746
|
-
return id;
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
/**************
|
|
750
|
-
func: hash
|
|
751
|
-
params:
|
|
752
|
-
- texts: The text string to create a hash value for.
|
|
753
|
-
- algo: The hashing algorithm to use for hashing. md5, sha256, or sha512
|
|
754
|
-
|
|
755
|
-
describe:
|
|
756
|
-
The hash algorithm will take a string of text and produce a hash.
|
|
757
|
-
***************/
|
|
758
|
-
hash(str, algo=false) {
|
|
759
|
-
algo = algo || this._security.hash || 'md5';
|
|
760
|
-
const the_hash = createHash(algo);
|
|
761
|
-
the_hash.update(str);
|
|
762
|
-
const _digest = the_hash.digest('base64');
|
|
763
|
-
this.state('hash', {
|
|
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;
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
/**************
|
|
774
|
-
func: cipher
|
|
775
|
-
params: str - string to encrypt
|
|
776
|
-
describe:
|
|
777
|
-
The encrypt function allows for the internal encryption of data based on the
|
|
778
|
-
defined client security settings.
|
|
779
|
-
***************/
|
|
780
|
-
cipher(str) {
|
|
781
|
-
const security = this._security;
|
|
782
|
-
const {password, algorithm} = security.cipher;
|
|
783
|
-
const key = createHash('sha256').update(String(password)).digest('base64');
|
|
784
|
-
const key_in_bytes = Buffer.from(key, 'base64')
|
|
785
|
-
const iv = randomBytes(16);
|
|
786
|
-
|
|
787
|
-
// create a new cipher
|
|
788
|
-
const _cipher = createCipheriv(algorithm, key_in_bytes, iv);
|
|
789
|
-
const encrypted = _cipher.update(String(str), 'utf8', 'hex') + _cipher.final('hex');
|
|
790
|
-
|
|
791
|
-
this.state('cipher', {
|
|
792
|
-
id: this.uid(true),
|
|
793
|
-
iv,
|
|
794
|
-
key,
|
|
795
|
-
agent_id: this._agent.id,
|
|
796
|
-
client_id: this._client.id,
|
|
797
|
-
created: Date.now()
|
|
798
|
-
});
|
|
799
|
-
|
|
800
|
-
return {
|
|
801
|
-
iv: iv.toString('base64'),
|
|
802
|
-
key,
|
|
803
|
-
encrypted,
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
decipher(opt) {
|
|
807
|
-
const iv = Buffer.from(opt.iv, 'base64');
|
|
808
|
-
const encrypted = Buffer.from(opt.encrypted, 'hex');
|
|
809
|
-
const key_in_bytes = Buffer.from(opt.key, 'base64')
|
|
810
|
-
const security = this._security;
|
|
811
|
-
const {algorithm} = security.cipher;
|
|
812
|
-
const decipher = createDecipheriv( algorithm, key_in_bytes, iv);
|
|
813
|
-
const decrypted = decipher.update(encrypted);
|
|
814
|
-
const final = Buffer.concat([decrypted, decipher.final()]);
|
|
815
|
-
this.state('decipher', {
|
|
816
|
-
id: this.uid(true),
|
|
817
|
-
iv: opt.iv,
|
|
818
|
-
key: opt.key,
|
|
819
|
-
agent_id: this._agent.id,
|
|
820
|
-
client_id: this._client.id,
|
|
821
|
-
created: Date.now()
|
|
822
|
-
});
|
|
823
|
-
return final.toString();
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
/**************
|
|
827
|
-
func: copy
|
|
828
|
-
params: obj
|
|
829
|
-
describe:
|
|
830
|
-
a simple copy object to create a memory clean copy of data to
|
|
831
|
-
prevent collisions when needed. Handles clean text, array, object copy.
|
|
832
|
-
it makes the assumption tha the user is submitting either an array or object
|
|
833
|
-
for copying.
|
|
834
|
-
***************/
|
|
835
|
-
copy(obj) {
|
|
836
|
-
let v, key;
|
|
837
|
-
const output = Array.isArray(obj) ? [] : {};
|
|
838
|
-
for (key in obj) {
|
|
839
|
-
v = obj[key];
|
|
840
|
-
output[key] = (typeof v === "object") ? this.copy(v) : v;
|
|
841
|
-
}
|
|
842
|
-
return output;
|
|
843
|
-
}
|
|
844
794
|
/**************
|
|
845
795
|
func: talk
|
|
846
796
|
params:
|
|
@@ -863,7 +813,10 @@ class Deva {
|
|
|
863
813
|
describe:
|
|
864
814
|
***************/
|
|
865
815
|
listen(evt, callback) {
|
|
866
|
-
|
|
816
|
+
this.listeners[evt] = callback;
|
|
817
|
+
return this.events.on(evt, packet => {
|
|
818
|
+
return this.listeners[evt](packet);
|
|
819
|
+
});
|
|
867
820
|
}
|
|
868
821
|
|
|
869
822
|
/**************
|
|
@@ -906,8 +859,8 @@ class Deva {
|
|
|
906
859
|
so the event is specific to the talk.
|
|
907
860
|
***************/
|
|
908
861
|
ask(packet) {
|
|
909
|
-
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
910
|
-
this.
|
|
862
|
+
if (!this._active) return Promise.resolve(this._messages.states.offline);
|
|
863
|
+
this.action('question', packet);
|
|
911
864
|
|
|
912
865
|
packet.a = {
|
|
913
866
|
agent: this._agent || false,
|
|
@@ -924,8 +877,9 @@ class Deva {
|
|
|
924
877
|
};
|
|
925
878
|
|
|
926
879
|
try {
|
|
927
|
-
if (this.methods[packet.q.meta.method]
|
|
880
|
+
if (this.methods[packet.q.meta.method] !== 'function') {
|
|
928
881
|
return setImmediate(() => {
|
|
882
|
+
this.action('ask_invalid')
|
|
929
883
|
packet.a.text = `INVALID METHOD (${packet.q.meta.method})`;
|
|
930
884
|
this.talk(`${this._agent.key}:ask:${packet.id}`, packet);
|
|
931
885
|
});
|
|
@@ -942,21 +896,74 @@ class Deva {
|
|
|
942
896
|
else {
|
|
943
897
|
packet.a.text = result;
|
|
944
898
|
}
|
|
945
|
-
|
|
946
|
-
this.state('ask_answer', packet);
|
|
899
|
+
this.action('ask_answer', packet);
|
|
947
900
|
this.talk(`${this._agent.key}:ask:${packet.id}`, packet);
|
|
948
901
|
}).catch(err => {
|
|
902
|
+
this.action('error', err);
|
|
949
903
|
this.talk(`${this._agent.key}:ask:${packet.id}`, {error:err.toString()});
|
|
950
904
|
return this.error(err, packet);
|
|
951
905
|
})
|
|
952
906
|
}
|
|
953
907
|
catch (e) {
|
|
908
|
+
this.action('error', err);
|
|
954
909
|
this.talk(`${this._agent.key}:ask:${packet.id}`, {error:e.toString()});
|
|
955
910
|
return this.error(e, packet)
|
|
956
911
|
}
|
|
957
912
|
// now when we ask the meta params[0] should be the method
|
|
958
913
|
}
|
|
959
914
|
|
|
915
|
+
answer(packet, resolve, reject) {
|
|
916
|
+
this.action('answer', packet); // set the question answer state
|
|
917
|
+
// check if method exists and is of type function
|
|
918
|
+
const {method,params} = packet.q.meta;
|
|
919
|
+
const isMethod = this.methods[method] && typeof this.methods[method] == 'function';
|
|
920
|
+
if (!isMethod) {
|
|
921
|
+
this.action('invalid')
|
|
922
|
+
return resolve(this._methodNotFound(packet)); // resolve method not found if check if check fails
|
|
923
|
+
}
|
|
924
|
+
// Call the local method to process the question based the extracted parameters
|
|
925
|
+
return this.methods[method](packet).then(result => {
|
|
926
|
+
// check the result for the text, html, and data object.
|
|
927
|
+
// this is for when answers are returned from nested Devas.
|
|
928
|
+
const text = typeof result === 'object' ? result.text : result;
|
|
929
|
+
const html = typeof result === 'object' ? result.html : result;
|
|
930
|
+
// if the data passed is NOT an object it will FALSE
|
|
931
|
+
const data = typeof result === 'object' ? result.data : false;
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
packet.a = { // setup the packet.a container
|
|
935
|
+
agent: this._agent || false, // set the agent who answered the question
|
|
936
|
+
client: this._client || false, // set the client asking the question
|
|
937
|
+
meta: { // setup the answer meta container
|
|
938
|
+
key: this._agent.key, // set the agent key inot the meta
|
|
939
|
+
method, // set the method into the meta
|
|
940
|
+
params, // set the params into the meta
|
|
941
|
+
},
|
|
942
|
+
text, // set answer text
|
|
943
|
+
html,
|
|
944
|
+
data,
|
|
945
|
+
created: Date.now(),
|
|
946
|
+
};
|
|
947
|
+
|
|
948
|
+
// create a hash for the answer and insert into answer meta.
|
|
949
|
+
this.action('hash_answer');
|
|
950
|
+
packet.a.meta.hash = this.hash(JSON.stringify(packet.a));
|
|
951
|
+
// create a hash for entire packet and insert into packet
|
|
952
|
+
// hash the entire packet.
|
|
953
|
+
this.action('hash_packet');
|
|
954
|
+
packet.hash = this.hash(JSON.stringify(packet));
|
|
955
|
+
|
|
956
|
+
this.action('answer_talk');
|
|
957
|
+
this.talk(`${this._agent.key}:answer`, packet); // set the question answer state
|
|
958
|
+
|
|
959
|
+
this.action('done');
|
|
960
|
+
return resolve(packet); // resolve the packet to the caller.
|
|
961
|
+
}).catch(err => { // catch any errors in the method
|
|
962
|
+
this.action('error', err);
|
|
963
|
+
return this.error(err, packet, reject); // return this.error with err, packet, reject
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
|
|
960
967
|
/**************
|
|
961
968
|
func: question
|
|
962
969
|
example: this.question('#*agent.key *method* *text*')
|
|
@@ -968,10 +975,10 @@ class Deva {
|
|
|
968
975
|
***************/
|
|
969
976
|
question(TEXT=false, DATA=false) {
|
|
970
977
|
// check the active status
|
|
971
|
-
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
972
|
-
this.state('question_me', {text:TEXT, data:DATA}); // set the question me state text TEXT & DATA passed in.
|
|
978
|
+
if (!this._active) return Promise.resolve(this._messages.states.offline);
|
|
973
979
|
const id = this.uid(); // generate a unique id for transport.
|
|
974
980
|
const t_split = TEXT.split(' '); // split the text on spaces to get words.
|
|
981
|
+
this.action('question', id);
|
|
975
982
|
|
|
976
983
|
// check to see if the string is an #ask string to talk to the other Deva.
|
|
977
984
|
const isAsk = t_split[0].startsWith(this.askChr);
|
|
@@ -998,14 +1005,10 @@ class Deva {
|
|
|
998
1005
|
// resolve with the no text message if the client says nothing.
|
|
999
1006
|
if (!TEXT) return resolve(this._messages.notext);
|
|
1000
1007
|
// reject question if Deva offline
|
|
1001
|
-
if (!this._active) return resolve(this._messages.offline);
|
|
1002
|
-
|
|
1008
|
+
if (!this._active) return resolve(this._messages.states.offline);
|
|
1009
|
+
let _action = 'question_method'
|
|
1003
1010
|
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
1011
|
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
1012
|
key = t_split[0].substring(1); // if:isAsksplit the agent key and remove first command character
|
|
1010
1013
|
//if:isAsk use text split index 1 as the parameter block
|
|
1011
1014
|
params = t_split[1] ? t_split[1].split(':') : false;
|
|
@@ -1013,13 +1016,15 @@ class Deva {
|
|
|
1013
1016
|
text = t_split.slice(2).join(' ').trim(); // then rejoin the text with spaces.
|
|
1014
1017
|
}
|
|
1015
1018
|
else if (isCmd) { // determine if the question is a command
|
|
1016
|
-
|
|
1017
|
-
_hash = 'hash_command' // if:isCmd set hash state
|
|
1019
|
+
_action = 'question_cmd';
|
|
1018
1020
|
//if:isCmd use text split index 1 as the parameter block
|
|
1019
|
-
params = t_split[
|
|
1021
|
+
params = t_split[0] ? t_split[0].split(':').slice(1) : false;
|
|
1020
1022
|
method = t_split[0].substring(1); // if:isCmd use the 0 index as the command
|
|
1021
1023
|
text = t_split.slice(1).join(' ').trim(); // if:isCmd rejoin the string on the space after removing first index
|
|
1022
1024
|
}
|
|
1025
|
+
else {
|
|
1026
|
+
this.action('question_method');
|
|
1027
|
+
}
|
|
1023
1028
|
|
|
1024
1029
|
packet.q = { // build packet.q container
|
|
1025
1030
|
agent: this._agent || false, // set the agent
|
|
@@ -1035,63 +1040,27 @@ class Deva {
|
|
|
1035
1040
|
created: Date.now(), // timestamp the question
|
|
1036
1041
|
}
|
|
1037
1042
|
|
|
1038
|
-
this.state('hash_question'); // set the has question state
|
|
1039
1043
|
// hash the question
|
|
1044
|
+
this.action('question_hash'); // set the has question state
|
|
1040
1045
|
packet.q.meta.hash = this.hash(JSON.stringify(packet.q));
|
|
1041
1046
|
|
|
1042
|
-
this.state(_state, packet); // set the state to teh _state variable
|
|
1043
1047
|
|
|
1044
1048
|
if (isAsk) { // isAsk check if the question isAsk and talk
|
|
1045
|
-
this.
|
|
1049
|
+
this.action('question_ask');
|
|
1046
1050
|
this.talk(`${key}:ask`, packet); // if:isAsk talk the event to theother Deva
|
|
1047
1051
|
// if: isAsk wait for the once event which is key'd to the packet ID for specified responses
|
|
1048
1052
|
this.once(`${key}:ask:${packet.id}`, answer => {
|
|
1053
|
+
this.action('question_ask_answer');
|
|
1049
1054
|
return resolve(answer); // if:isAsk resolve the answer from the call
|
|
1050
1055
|
});
|
|
1051
1056
|
}
|
|
1052
|
-
|
|
1053
1057
|
else { // else: answer tue question locally
|
|
1054
|
-
this.
|
|
1055
|
-
|
|
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
|
|
1058
|
-
}
|
|
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.
|
|
1063
|
-
const text = typeof result === 'object' ? result.text : result;
|
|
1064
|
-
const html = typeof result === 'object' ? result.html : result;
|
|
1065
|
-
// if the data passed is NOT an object it will FALSE
|
|
1066
|
-
const data = typeof result === 'object' ? result.data : false;
|
|
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
|
|
1074
|
-
},
|
|
1075
|
-
text, // set answer text
|
|
1076
|
-
html,
|
|
1077
|
-
data,
|
|
1078
|
-
created: Date.now(),
|
|
1079
|
-
};
|
|
1080
|
-
// create a hash for the answer and insert into answer meta.
|
|
1081
|
-
this.state(_hash);
|
|
1082
|
-
packet.a.meta.hash = this.hash(JSON.stringify(packet.a));
|
|
1083
|
-
// create a hash for entire packet and insert into packet
|
|
1084
|
-
this.state('hash_packet');
|
|
1085
|
-
// hash the entire packet.
|
|
1086
|
-
packet.hash = this.hash(JSON.stringify(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
|
|
1091
|
-
});
|
|
1058
|
+
this.action(_action);
|
|
1059
|
+
return this.answer(packet, resolve, reject);
|
|
1092
1060
|
}
|
|
1093
1061
|
}
|
|
1094
1062
|
catch(e) { // try block error trap
|
|
1063
|
+
this.action('error');
|
|
1095
1064
|
return this.error(e); // if a overall error happens this witll call this.error
|
|
1096
1065
|
}
|
|
1097
1066
|
});
|
|
@@ -1114,7 +1083,6 @@ class Deva {
|
|
|
1114
1083
|
***************/
|
|
1115
1084
|
init(client) {
|
|
1116
1085
|
// set client
|
|
1117
|
-
this.Client = client;
|
|
1118
1086
|
this._active = Date.now();
|
|
1119
1087
|
return new Promise((resolve, reject) => {
|
|
1120
1088
|
this.events.setMaxListeners(this.maxListeners);
|
|
@@ -1124,10 +1092,15 @@ class Deva {
|
|
|
1124
1092
|
return this._assignListeners();
|
|
1125
1093
|
}).then(() => {
|
|
1126
1094
|
this.state('init');
|
|
1127
|
-
this.
|
|
1128
|
-
return this.
|
|
1129
|
-
}).then(
|
|
1130
|
-
|
|
1095
|
+
this.zone('config');
|
|
1096
|
+
return this.Client(client);
|
|
1097
|
+
}).then(() => {
|
|
1098
|
+
this.zone('features');
|
|
1099
|
+
this.action('features');
|
|
1100
|
+
return this.Security();
|
|
1101
|
+
}).then(() => {
|
|
1102
|
+
this.zone('deva');
|
|
1103
|
+
return this.start(this._messages.deva_init);
|
|
1131
1104
|
}).catch(err => {
|
|
1132
1105
|
return this.error(err, client, reject);
|
|
1133
1106
|
});
|
|
@@ -1145,13 +1118,19 @@ class Deva {
|
|
|
1145
1118
|
usage: this.error(err, data, reject);
|
|
1146
1119
|
***************/
|
|
1147
1120
|
error(err,data=false,reject=false) {
|
|
1148
|
-
this.state('error', {err, data}); // set the state to error
|
|
1149
1121
|
// check fo rthe custom onError function in the agent.
|
|
1122
|
+
console.log('\n::BEGIN:ERROR\n');
|
|
1123
|
+
console.log(err);
|
|
1124
|
+
console.log('\n::END:ERROR\n');
|
|
1125
|
+
if (data) {
|
|
1126
|
+
console.log('::::::');
|
|
1127
|
+
console.log('\n::BEGIN:DATA\n');
|
|
1128
|
+
console.log(JSON.stringify(data, null, 2));
|
|
1129
|
+
console.log('\n::END:DATA\n');
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1150
1132
|
if (this.onError && typeof this.onError === 'function') return this.onError(err, data, reject);
|
|
1151
1133
|
else {
|
|
1152
|
-
console.log('\n::BEGIN:ERROR\n');
|
|
1153
|
-
console.log(err);
|
|
1154
|
-
console.log('\n::END:ERROR\n');
|
|
1155
1134
|
return reject ? reject(err) : err;
|
|
1156
1135
|
}
|
|
1157
1136
|
}
|
|
@@ -1166,10 +1145,20 @@ class Deva {
|
|
|
1166
1145
|
function or running the system enter function.
|
|
1167
1146
|
usage: this.start('msg')
|
|
1168
1147
|
***************/
|
|
1169
|
-
start(
|
|
1170
|
-
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
1148
|
+
start(text = false) {
|
|
1171
1149
|
this.state('start');
|
|
1172
|
-
|
|
1150
|
+
if (!this._active) return Promise.resolve(this._messages.states.offline);
|
|
1151
|
+
const _data = {
|
|
1152
|
+
id: this.uid(),
|
|
1153
|
+
key: 'start',
|
|
1154
|
+
value: 'start',
|
|
1155
|
+
agent: this._agent,
|
|
1156
|
+
text: this._messages.states.start,
|
|
1157
|
+
created: Date.now(),
|
|
1158
|
+
}
|
|
1159
|
+
_data.hash = this.hash(JSON.stringify(_data));
|
|
1160
|
+
const hasOnExit = this.onExit && typeof this.onExit === 'function';
|
|
1161
|
+
return hasOnExit ? this.onExit(_data) : Promise.resolve(_data)
|
|
1173
1162
|
}
|
|
1174
1163
|
|
|
1175
1164
|
/**************
|
|
@@ -1185,11 +1174,20 @@ class Deva {
|
|
|
1185
1174
|
usage:
|
|
1186
1175
|
this.stop('msg')
|
|
1187
1176
|
***************/
|
|
1188
|
-
stop(
|
|
1189
|
-
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
1177
|
+
stop(text=false) {
|
|
1190
1178
|
this.state('stop');
|
|
1191
|
-
this._active
|
|
1192
|
-
|
|
1179
|
+
if (!this._active) return Promise.resolve(this._messages.states.offline);
|
|
1180
|
+
const _data = {
|
|
1181
|
+
id: this.uid(),
|
|
1182
|
+
key: 'stop',
|
|
1183
|
+
value: 'stop',
|
|
1184
|
+
agent: this._agent,
|
|
1185
|
+
text: this._messages.states.stop,
|
|
1186
|
+
created: Date.now(),
|
|
1187
|
+
}
|
|
1188
|
+
_data.hash = this.hash(JSON.stringify(_data));
|
|
1189
|
+
const hasOnStop = this.onStop && typeof this.onStop === 'function';
|
|
1190
|
+
return hasOnStop ? this.onStop(_data) : this.exit(_data)
|
|
1193
1191
|
}
|
|
1194
1192
|
|
|
1195
1193
|
/**************
|
|
@@ -1203,10 +1201,20 @@ class Deva {
|
|
|
1203
1201
|
If the Deva is offline it will return the offline message.
|
|
1204
1202
|
usage: this.enter('msg')
|
|
1205
1203
|
***************/
|
|
1206
|
-
enter(
|
|
1207
|
-
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
1204
|
+
enter(text=false) {
|
|
1208
1205
|
this.state('enter');
|
|
1209
|
-
|
|
1206
|
+
if (!this._active) return Promise.resolve(this._messages.states.offline);
|
|
1207
|
+
const _data = {
|
|
1208
|
+
id: this.uid(),
|
|
1209
|
+
type: 'enter',
|
|
1210
|
+
value: 'enter',
|
|
1211
|
+
agent: this._agent,
|
|
1212
|
+
text: this._messages.states.enter,
|
|
1213
|
+
created: Date.now(),
|
|
1214
|
+
}
|
|
1215
|
+
_data.hash = this.hash(JSON.stringify(_data));
|
|
1216
|
+
const hasOnEnter = this.onEnter && typeof this.onEnter === 'function';
|
|
1217
|
+
return hasOnEnter ? this.onExit(_data) : Promise.resolve(_data)
|
|
1210
1218
|
}
|
|
1211
1219
|
|
|
1212
1220
|
/**************
|
|
@@ -1223,11 +1231,21 @@ class Deva {
|
|
|
1223
1231
|
If the deva is offline it will return the offline message.
|
|
1224
1232
|
usage: this.exit('msg')
|
|
1225
1233
|
***************/
|
|
1226
|
-
exit(
|
|
1227
|
-
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
1234
|
+
exit(text=false) {
|
|
1228
1235
|
this.state('exit');
|
|
1236
|
+
if (!this._active) return Promise.resolve(this._messages.states.offline);
|
|
1229
1237
|
this._active = false;
|
|
1230
|
-
|
|
1238
|
+
const _data = {
|
|
1239
|
+
id: this.uid(),
|
|
1240
|
+
key: 'exit',
|
|
1241
|
+
value: 'exit',
|
|
1242
|
+
agent: this._agent,
|
|
1243
|
+
text: this._messages.states.exit,
|
|
1244
|
+
created: Date.now(),
|
|
1245
|
+
}
|
|
1246
|
+
_data.hash = this.hash(JSON.stringify(_data));
|
|
1247
|
+
const hasOnExit = this.onExit && typeof this.onExit === 'function';
|
|
1248
|
+
return hasOnExit ? this.onExit(_data) : Promise.resolve(_data)
|
|
1231
1249
|
}
|
|
1232
1250
|
|
|
1233
1251
|
/**************
|
|
@@ -1241,49 +1259,136 @@ class Deva {
|
|
|
1241
1259
|
If the deva is offline it will return the offline message.
|
|
1242
1260
|
usage: this.done('msg')
|
|
1243
1261
|
***************/
|
|
1244
|
-
done(
|
|
1245
|
-
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
1262
|
+
done(text=false) {
|
|
1246
1263
|
this.state('done');
|
|
1247
|
-
|
|
1248
|
-
|
|
1264
|
+
if (!this._active) return Promise.resolve(this._messages.states.offline);
|
|
1265
|
+
this._active = false;
|
|
1266
|
+
const _data = {
|
|
1267
|
+
id: this.uid(),
|
|
1268
|
+
key: 'done',
|
|
1269
|
+
value: 'done',
|
|
1270
|
+
agent: this._agent,
|
|
1271
|
+
text: this._messages.states.exit,
|
|
1272
|
+
created: Date.now(),
|
|
1273
|
+
}
|
|
1274
|
+
_data.hash = this.hash(JSON.stringify(_data));
|
|
1275
|
+
const hasOnExit = this.onExit && typeof this.onExit === 'function';
|
|
1276
|
+
return hasOnExit ? this.onExit(_data) : Promise.resolve(_data)
|
|
1249
1277
|
}
|
|
1250
1278
|
|
|
1279
|
+
////////////////////////////
|
|
1280
|
+
|
|
1251
1281
|
/**************
|
|
1252
|
-
func:
|
|
1282
|
+
func: state
|
|
1253
1283
|
params:
|
|
1254
|
-
-
|
|
1255
|
-
describe
|
|
1256
|
-
|
|
1257
|
-
|
|
1284
|
+
- st: The state flag to set for the Deva that matches to this._states
|
|
1285
|
+
describe
|
|
1286
|
+
***************/
|
|
1287
|
+
state(state, data=false) {
|
|
1288
|
+
try {
|
|
1289
|
+
if (!this._states[state]) return;
|
|
1290
|
+
this._state = state;
|
|
1291
|
+
const text = this._messages.states[state];
|
|
1292
|
+
const _data = {
|
|
1293
|
+
id: this.uid(),
|
|
1294
|
+
key: 'state',
|
|
1295
|
+
value: state,
|
|
1296
|
+
agent: this._agent,
|
|
1297
|
+
text,
|
|
1298
|
+
data,
|
|
1299
|
+
created: Date.now(),
|
|
1300
|
+
};
|
|
1301
|
+
_data.hash = this.hash(JSON.stringify(_data));
|
|
1302
|
+
this.talk('state', _data);
|
|
1303
|
+
} catch (e) {
|
|
1304
|
+
return this.error(e);
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1258
1307
|
|
|
1259
|
-
|
|
1260
|
-
|
|
1308
|
+
/**************
|
|
1309
|
+
func: zone
|
|
1310
|
+
params:
|
|
1311
|
+
- st: The zone flag to set for the Deva that matches to this._zones
|
|
1312
|
+
describe
|
|
1261
1313
|
***************/
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1314
|
+
zone(zone, data=false) {
|
|
1315
|
+
try {
|
|
1316
|
+
if (!this._zones[zone]) return;
|
|
1317
|
+
this._zone = zone;
|
|
1318
|
+
const text = this._messages.zones[zone];
|
|
1319
|
+
const _data = {
|
|
1320
|
+
id: this.uid(),
|
|
1321
|
+
key: 'zone',
|
|
1322
|
+
value: zone,
|
|
1323
|
+
agent: this._agent,
|
|
1324
|
+
text,
|
|
1325
|
+
data,
|
|
1326
|
+
created: Date.now(),
|
|
1327
|
+
};
|
|
1328
|
+
_data.hash = this.hash(JSON.stringify(_data));
|
|
1329
|
+
this.talk('zone', _data);
|
|
1330
|
+
} catch (e) {
|
|
1331
|
+
return this.error(e);
|
|
1332
|
+
}
|
|
1271
1333
|
}
|
|
1272
1334
|
|
|
1273
1335
|
/**************
|
|
1274
|
-
func:
|
|
1336
|
+
func: action
|
|
1275
1337
|
params:
|
|
1276
|
-
-
|
|
1277
|
-
describe
|
|
1278
|
-
|
|
1338
|
+
- st: The state flag to set for the Deva that matches to this._states
|
|
1339
|
+
describe
|
|
1340
|
+
***************/
|
|
1341
|
+
action(action, data=false) {
|
|
1342
|
+
try {
|
|
1343
|
+
if (!this._actions[action]) return;
|
|
1344
|
+
this._action = action;
|
|
1345
|
+
const text = this._messages.actions[action];
|
|
1346
|
+
const _data = {
|
|
1347
|
+
id: this.uid(),
|
|
1348
|
+
key: 'action',
|
|
1349
|
+
value: action,
|
|
1350
|
+
agent: this._agent,
|
|
1351
|
+
text,
|
|
1352
|
+
data,
|
|
1353
|
+
created: Date.now(),
|
|
1354
|
+
};
|
|
1355
|
+
_data.hash = this.hash(JSON.stringify(_data));
|
|
1356
|
+
this.talk('action', _data);
|
|
1357
|
+
} catch (e) {
|
|
1358
|
+
return this.error(e)
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1279
1361
|
|
|
1280
|
-
|
|
1362
|
+
/**************
|
|
1363
|
+
func: feature
|
|
1364
|
+
params:
|
|
1365
|
+
- st: The state flag to set for the Deva that matches to this._states
|
|
1366
|
+
describe
|
|
1281
1367
|
***************/
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1368
|
+
feature(feature, data=false) {
|
|
1369
|
+
try {
|
|
1370
|
+
if (!this._features[feature]) return;
|
|
1371
|
+
this._feature = feature;
|
|
1372
|
+
const text = this._messages.features[feature] ;
|
|
1373
|
+
const _data = {
|
|
1374
|
+
id: this.uid(),
|
|
1375
|
+
key: 'feature',
|
|
1376
|
+
value: feature,
|
|
1377
|
+
agent: this._agent,
|
|
1378
|
+
text,
|
|
1379
|
+
data,
|
|
1380
|
+
created: Date.now(),
|
|
1381
|
+
};
|
|
1382
|
+
_data.hash = this.hash(JSON.stringify(_data));
|
|
1383
|
+
this.talk('feature', _data);
|
|
1384
|
+
} catch (e) {
|
|
1385
|
+
return this.error(e);
|
|
1386
|
+
}
|
|
1285
1387
|
}
|
|
1286
1388
|
|
|
1389
|
+
|
|
1390
|
+
///////////////////////////
|
|
1391
|
+
|
|
1287
1392
|
/**************
|
|
1288
1393
|
func: client
|
|
1289
1394
|
params: none
|
|
@@ -1293,8 +1398,8 @@ class Deva {
|
|
|
1293
1398
|
usage: this.client();
|
|
1294
1399
|
***************/
|
|
1295
1400
|
client() {
|
|
1296
|
-
|
|
1297
|
-
this.
|
|
1401
|
+
this.state('client_data'); // set the client state
|
|
1402
|
+
if (!this._active) return this._messages.states.offline; // check the active status
|
|
1298
1403
|
return this._client; // return the client feature
|
|
1299
1404
|
}
|
|
1300
1405
|
|
|
@@ -1307,11 +1412,12 @@ class Deva {
|
|
|
1307
1412
|
usage: this.agent()
|
|
1308
1413
|
***************/
|
|
1309
1414
|
agent() {
|
|
1310
|
-
|
|
1311
|
-
this.
|
|
1415
|
+
this.state('agent_data');
|
|
1416
|
+
if (!this._active) return this._messages.states.offline;
|
|
1312
1417
|
return this._agent;
|
|
1313
1418
|
}
|
|
1314
1419
|
|
|
1420
|
+
// FEATURE FUNCTIONS
|
|
1315
1421
|
/**************
|
|
1316
1422
|
func: security
|
|
1317
1423
|
params: none
|
|
@@ -1319,9 +1425,16 @@ class Deva {
|
|
|
1319
1425
|
usage: this.security()
|
|
1320
1426
|
***************/
|
|
1321
1427
|
security() {
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1428
|
+
this.feature('security'); // set the security state
|
|
1429
|
+
try {
|
|
1430
|
+
if (!this._active) return this._messages.states.offline; // check the active status
|
|
1431
|
+
this.action('security'); // set the security state
|
|
1432
|
+
return this._security; // return the security feature
|
|
1433
|
+
} catch (e) {
|
|
1434
|
+
this.action('error'); // set the security state
|
|
1435
|
+
this.feature('error');
|
|
1436
|
+
return this.error(e);
|
|
1437
|
+
}
|
|
1325
1438
|
}
|
|
1326
1439
|
|
|
1327
1440
|
/**************
|
|
@@ -1331,9 +1444,16 @@ class Deva {
|
|
|
1331
1444
|
usage: this.support()
|
|
1332
1445
|
***************/
|
|
1333
1446
|
support() {
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1447
|
+
this.feature('support'); // set the support state
|
|
1448
|
+
try {
|
|
1449
|
+
if (!this._active) return this._messages.states.offline; // check the active status
|
|
1450
|
+
this.action('support'); // set the support state
|
|
1451
|
+
return this._support; // return the support feature
|
|
1452
|
+
} catch (e) {
|
|
1453
|
+
this.action('error'); // set the services state
|
|
1454
|
+
this.feature('error');
|
|
1455
|
+
return this.error(e);
|
|
1456
|
+
}
|
|
1337
1457
|
}
|
|
1338
1458
|
|
|
1339
1459
|
/**************
|
|
@@ -1343,9 +1463,16 @@ class Deva {
|
|
|
1343
1463
|
usage: this.services()
|
|
1344
1464
|
***************/
|
|
1345
1465
|
services(opts) {
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1466
|
+
this.feature('services'); // set the services state
|
|
1467
|
+
try {
|
|
1468
|
+
if (!this._active) return this._messages.states.offline; // check the active status
|
|
1469
|
+
this.action('services'); // set the services state
|
|
1470
|
+
return this._services; // return the services feature
|
|
1471
|
+
} catch (e) {
|
|
1472
|
+
this.action('error'); // set the services state
|
|
1473
|
+
this.feature('error');
|
|
1474
|
+
return this.error(e);
|
|
1475
|
+
}
|
|
1349
1476
|
}
|
|
1350
1477
|
|
|
1351
1478
|
/**************
|
|
@@ -1355,9 +1482,16 @@ class Deva {
|
|
|
1355
1482
|
usage: this.systems()
|
|
1356
1483
|
***************/
|
|
1357
1484
|
systems(opts) {
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1485
|
+
this.feature('systems'); // set the systems state
|
|
1486
|
+
try {
|
|
1487
|
+
if (!this._active) return this._messages.states.offline; // check the active status
|
|
1488
|
+
this.action('systems'); // set the systems state
|
|
1489
|
+
return this._systems; // return the systems feature
|
|
1490
|
+
} catch (e) {
|
|
1491
|
+
this.action('error'); // set the systems state
|
|
1492
|
+
this.feature('error');
|
|
1493
|
+
return this.error(e)
|
|
1494
|
+
}
|
|
1361
1495
|
}
|
|
1362
1496
|
|
|
1363
1497
|
/**************
|
|
@@ -1367,9 +1501,16 @@ class Deva {
|
|
|
1367
1501
|
usage: this.solutions()
|
|
1368
1502
|
***************/
|
|
1369
1503
|
solutions(opts) {
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1504
|
+
this.feature('solutions'); // set the solutions state
|
|
1505
|
+
try {
|
|
1506
|
+
if (!this._active) return this._messages.states.offline; // check the active status
|
|
1507
|
+
this.action('solutions'); // set the solutions state
|
|
1508
|
+
return this._solutions; // return the solutions feature
|
|
1509
|
+
} catch (e) {
|
|
1510
|
+
this.action('error'); // set the systems state
|
|
1511
|
+
this.feature('error');
|
|
1512
|
+
return this.error(e);
|
|
1513
|
+
}
|
|
1373
1514
|
}
|
|
1374
1515
|
|
|
1375
1516
|
/**************
|
|
@@ -1378,9 +1519,14 @@ class Deva {
|
|
|
1378
1519
|
describe: basic development features available in a Deva.
|
|
1379
1520
|
***************/
|
|
1380
1521
|
development(opts) {
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1522
|
+
try {
|
|
1523
|
+
if (!this._active) return this._messages.states.offline; // chek the active status
|
|
1524
|
+
this.feature('development'); // set the development state
|
|
1525
|
+
return this._development; // return development feature
|
|
1526
|
+
} catch (e) {
|
|
1527
|
+
this.feature('error');
|
|
1528
|
+
return this.error(e);
|
|
1529
|
+
}
|
|
1384
1530
|
}
|
|
1385
1531
|
|
|
1386
1532
|
/**************
|
|
@@ -1389,9 +1535,14 @@ class Deva {
|
|
|
1389
1535
|
describe: basic assistant features available in a Deva.
|
|
1390
1536
|
***************/
|
|
1391
1537
|
assistant(opts) {
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1538
|
+
try {
|
|
1539
|
+
if (!this._active) return this._messages.states.offline; // chek the active status
|
|
1540
|
+
this.feature('assistant'); // set the assistant state
|
|
1541
|
+
return this._assistant; // return assistant feature
|
|
1542
|
+
} catch (e) {
|
|
1543
|
+
this.feature('error');
|
|
1544
|
+
return this.error(e);
|
|
1545
|
+
}
|
|
1395
1546
|
}
|
|
1396
1547
|
|
|
1397
1548
|
/**************
|
|
@@ -1400,9 +1551,14 @@ class Deva {
|
|
|
1400
1551
|
describe: basic business features available in a Deva.
|
|
1401
1552
|
***************/
|
|
1402
1553
|
business(opts) {
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1554
|
+
try {
|
|
1555
|
+
if (!this._active) return this._messages.states.offline; // chek the active status
|
|
1556
|
+
this.feature('business'); // set the business state
|
|
1557
|
+
return this._business; // return business feature
|
|
1558
|
+
} catch (e) {
|
|
1559
|
+
this.feature('error');
|
|
1560
|
+
return this.error('error');
|
|
1561
|
+
}
|
|
1406
1562
|
}
|
|
1407
1563
|
|
|
1408
1564
|
/**************
|
|
@@ -1411,9 +1567,25 @@ class Deva {
|
|
|
1411
1567
|
describe: basic legal features available in a Deva.
|
|
1412
1568
|
***************/
|
|
1413
1569
|
legal(opts) {
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1570
|
+
try {
|
|
1571
|
+
if (!this._active) return this._messages.states.offline; // chek the active status
|
|
1572
|
+
this.feature('legal'); // set the legal state
|
|
1573
|
+
return this._legal; // return legal feature
|
|
1574
|
+
} catch (e) {
|
|
1575
|
+
this.feature('error');
|
|
1576
|
+
return this.error(e);
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
/**************
|
|
1581
|
+
func: story
|
|
1582
|
+
params: opts
|
|
1583
|
+
describe: basic story features available in a Deva.
|
|
1584
|
+
***************/
|
|
1585
|
+
story(opts) {
|
|
1586
|
+
if (!this._active) return this._messages.states.offline; // chek the active status
|
|
1587
|
+
this.feature('story'); // set the story state
|
|
1588
|
+
return this._story; // return story feature
|
|
1417
1589
|
}
|
|
1418
1590
|
|
|
1419
1591
|
/**************
|
|
@@ -1425,21 +1597,19 @@ class Deva {
|
|
|
1425
1597
|
***************/
|
|
1426
1598
|
load(key, client) {
|
|
1427
1599
|
return new Promise((resolve, reject) => {
|
|
1428
|
-
this.state('
|
|
1600
|
+
this.state('load');
|
|
1429
1601
|
this.devas[key].init(client).then(loaded => {
|
|
1430
|
-
this.state('deva_loaded');
|
|
1431
1602
|
this.talk(`deva:load`, {
|
|
1432
1603
|
key,
|
|
1433
1604
|
created: Date.now(),
|
|
1434
1605
|
});
|
|
1435
|
-
return resolve();
|
|
1606
|
+
return resolve(this._messages.states.load);
|
|
1436
1607
|
}).catch(err => {
|
|
1437
1608
|
return this.error(err, deva, reject);
|
|
1438
1609
|
})
|
|
1439
1610
|
});
|
|
1440
1611
|
}
|
|
1441
1612
|
|
|
1442
|
-
|
|
1443
1613
|
/**************
|
|
1444
1614
|
func: unload
|
|
1445
1615
|
params:
|
|
@@ -1447,67 +1617,180 @@ class Deva {
|
|
|
1447
1617
|
describe: Unload a currently loaded Deva.
|
|
1448
1618
|
***************/
|
|
1449
1619
|
unload(key) {
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1620
|
+
return new Promise((resolve, reject) => {
|
|
1621
|
+
try {
|
|
1622
|
+
this.state('uload');
|
|
1623
|
+
delete this.devas[key];
|
|
1624
|
+
this.talk(`deva:unload`, {
|
|
1625
|
+
key,
|
|
1626
|
+
created: Date.now(),
|
|
1627
|
+
});
|
|
1628
|
+
return resolve(this._messages.states.unload);
|
|
1629
|
+
} catch (e) {
|
|
1630
|
+
return reject(e, this.devas[key], reject)
|
|
1631
|
+
}
|
|
1456
1632
|
});
|
|
1457
|
-
return Promise.resolve(`unload:${deva} `);
|
|
1458
1633
|
}
|
|
1459
1634
|
|
|
1635
|
+
|
|
1636
|
+
// UTILITY FUNCTIONS
|
|
1460
1637
|
/**************
|
|
1461
|
-
func:
|
|
1462
|
-
params:
|
|
1638
|
+
func: uid
|
|
1639
|
+
params:
|
|
1640
|
+
- guid: This is a true false flag for generating a guid.
|
|
1463
1641
|
describe:
|
|
1464
|
-
|
|
1642
|
+
The uid function can create two types of id for you.
|
|
1643
|
+
1. random GUID - this is good for when you need a uinique record id returned
|
|
1644
|
+
2. transport id - The transport id is a number generated to provide a
|
|
1645
|
+
numerical number used for transporting records to places
|
|
1646
|
+
like social networks, email, other networks where informaton
|
|
1647
|
+
is shared.
|
|
1465
1648
|
***************/
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1649
|
+
uid(guid=false) {
|
|
1650
|
+
let id;
|
|
1651
|
+
if (guid) {
|
|
1652
|
+
id = randomUUID()
|
|
1653
|
+
}
|
|
1654
|
+
else {
|
|
1655
|
+
const min = Math.floor(Date.now() - (Date.now() / Math.PI));
|
|
1656
|
+
const max = Math.floor(Date.now() + (Date.now() * Math.PI));
|
|
1657
|
+
id = Math.floor(Math.random() * (max - min)) + min;
|
|
1658
|
+
}
|
|
1659
|
+
return id;
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
/**************
|
|
1663
|
+
func: hash
|
|
1664
|
+
params:
|
|
1665
|
+
- texts: The text string to create a hash value for.
|
|
1666
|
+
- algo: The hashing algorithm to use for hashing. md5, sha256, or sha512
|
|
1667
|
+
|
|
1668
|
+
describe:
|
|
1669
|
+
The hash algorithm will take a string of text and produce a hash.
|
|
1670
|
+
***************/
|
|
1671
|
+
hash(str, algo=false) {
|
|
1672
|
+
algo = algo || this._security.hash || 'md5';
|
|
1673
|
+
const the_hash = createHash(algo);
|
|
1674
|
+
the_hash.update(str);
|
|
1675
|
+
const _digest = the_hash.digest('base64');
|
|
1676
|
+
return _digest;
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
/**************
|
|
1680
|
+
func: cipher
|
|
1681
|
+
params: str - string to encrypt
|
|
1682
|
+
describe:
|
|
1683
|
+
The encrypt function allows for the internal encryption of data based on the
|
|
1684
|
+
defined client security settings.
|
|
1685
|
+
***************/
|
|
1686
|
+
cipher(str) {
|
|
1687
|
+
const security = this._security;
|
|
1688
|
+
const {password, algorithm} = security.cipher;
|
|
1689
|
+
const key = createHash('sha256').update(String(password)).digest('base64');
|
|
1690
|
+
const key_in_bytes = Buffer.from(key, 'base64')
|
|
1691
|
+
const iv = randomBytes(16);
|
|
1692
|
+
|
|
1693
|
+
// create a new cipher
|
|
1694
|
+
const _cipher = createCipheriv(algorithm, key_in_bytes, iv);
|
|
1695
|
+
const encrypted = _cipher.update(String(str), 'utf8', 'hex') + _cipher.final('hex');
|
|
1696
|
+
|
|
1697
|
+
this.state('cipher', {
|
|
1698
|
+
id: this.uid(true),
|
|
1699
|
+
iv,
|
|
1700
|
+
key,
|
|
1701
|
+
agent_id: this._agent.id,
|
|
1702
|
+
client_id: this._client.id,
|
|
1703
|
+
created: Date.now()
|
|
1704
|
+
});
|
|
1705
|
+
|
|
1706
|
+
return {
|
|
1707
|
+
iv: iv.toString('base64'),
|
|
1708
|
+
key,
|
|
1709
|
+
encrypted,
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
decipher(opt) {
|
|
1713
|
+
const iv = Buffer.from(opt.iv, 'base64');
|
|
1714
|
+
const encrypted = Buffer.from(opt.encrypted, 'hex');
|
|
1715
|
+
const key_in_bytes = Buffer.from(opt.key, 'base64')
|
|
1716
|
+
const security = this._security;
|
|
1717
|
+
const {algorithm} = security.cipher;
|
|
1718
|
+
const decipher = createDecipheriv( algorithm, key_in_bytes, iv);
|
|
1719
|
+
const decrypted = decipher.update(encrypted);
|
|
1720
|
+
const final = Buffer.concat([decrypted, decipher.final()]);
|
|
1721
|
+
this.state('decipher', {
|
|
1722
|
+
id: this.uid(true),
|
|
1723
|
+
iv: opt.iv,
|
|
1724
|
+
key: opt.key,
|
|
1725
|
+
agent_id: this._agent.id,
|
|
1726
|
+
client_id: this._client.id,
|
|
1727
|
+
created: Date.now()
|
|
1483
1728
|
});
|
|
1729
|
+
return final.toString();
|
|
1484
1730
|
}
|
|
1731
|
+
|
|
1485
1732
|
/**************
|
|
1486
|
-
func:
|
|
1487
|
-
params:
|
|
1733
|
+
func: status
|
|
1734
|
+
params:
|
|
1735
|
+
- msg: The msg is any additonal string to append to the end of hte call.
|
|
1488
1736
|
describe:
|
|
1489
|
-
|
|
1737
|
+
The status function provides an easy way to get the current status of a Deva
|
|
1738
|
+
and append custom status messages that may pertain to any custom status call.
|
|
1739
|
+
|
|
1740
|
+
If the deva is offline it will return the offline message.
|
|
1741
|
+
usage: this.status('msg')
|
|
1490
1742
|
***************/
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
return
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1743
|
+
status(msg=false) {
|
|
1744
|
+
// check the active status
|
|
1745
|
+
if (!this._active) return Promise.resolve(this._messages.states.offline);
|
|
1746
|
+
// format the date since active for output.
|
|
1747
|
+
const dateFormat = this.formatDate(this._active, 'long', true);
|
|
1748
|
+
// create the text msg string
|
|
1749
|
+
let text = `${this._agent.profile.name} active since ${dateFormat}`;
|
|
1750
|
+
if (msg) text = text + `\n${msg}`; // append the msg string if msg true.
|
|
1751
|
+
return Promise.resolve(text); // return final text string
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
/**************
|
|
1755
|
+
func: prompt
|
|
1756
|
+
params:
|
|
1757
|
+
- text: The text string to send to the prompt.
|
|
1758
|
+
describe:-
|
|
1759
|
+
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.
|
|
1760
|
+
|
|
1761
|
+
usage: this.prompt('text')
|
|
1762
|
+
***************/
|
|
1763
|
+
prompt(text) {
|
|
1764
|
+
// console.log('PROMPT', text);
|
|
1765
|
+
// Talk a global prompt event for the client
|
|
1766
|
+
return this.talk('prompt', {
|
|
1767
|
+
id: this.uid(),
|
|
1768
|
+
text,
|
|
1769
|
+
agent:this._agent,
|
|
1770
|
+
created: Date.Now(),
|
|
1507
1771
|
});
|
|
1508
1772
|
}
|
|
1509
1773
|
|
|
1510
|
-
|
|
1774
|
+
|
|
1775
|
+
/**************
|
|
1776
|
+
func: copy
|
|
1777
|
+
params: obj
|
|
1778
|
+
describe:
|
|
1779
|
+
a simple copy object to create a memory clean copy of data to
|
|
1780
|
+
prevent collisions when needed. Handles clean text, array, object copy.
|
|
1781
|
+
it makes the assumption tha the user is submitting either an array or object
|
|
1782
|
+
for copying.
|
|
1783
|
+
***************/
|
|
1784
|
+
copy(obj) {
|
|
1785
|
+
let v, key;
|
|
1786
|
+
const output = Array.isArray(obj) ? [] : {};
|
|
1787
|
+
for (key in obj) {
|
|
1788
|
+
v = obj[key];
|
|
1789
|
+
output[key] = (typeof v === "object") ? this.copy(v) : v;
|
|
1790
|
+
}
|
|
1791
|
+
return output;
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1511
1794
|
/**************
|
|
1512
1795
|
func: formatDate
|
|
1513
1796
|
params:
|