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