@indra.ai/deva 1.5.5 โ 1.5.7
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/index.js +145 -102
- package/package.json +37 -61
package/index.js
CHANGED
|
@@ -242,19 +242,20 @@ class Deva {
|
|
|
242
242
|
client presented data.
|
|
243
243
|
***************/
|
|
244
244
|
Feature(feature, resolve, reject) {
|
|
245
|
-
this.
|
|
246
|
-
this.
|
|
245
|
+
const id = this.lib.uid();
|
|
246
|
+
this.feature(feature, id);
|
|
247
|
+
this.zone(feature, id);
|
|
247
248
|
const _cl = this.client(); // set local copy of client data
|
|
248
249
|
try {
|
|
249
250
|
if (!_cl.features[feature]) return resolve(); // if no security feature goto Support
|
|
250
251
|
else {
|
|
251
|
-
this.action(feature); // set action to feature
|
|
252
|
+
this.action(feature, id); // set action to feature
|
|
252
253
|
const _fe = `_${feature}`;
|
|
253
254
|
const {id, profile, features} = _cl; // make a copy the clinet data.
|
|
254
255
|
const data = features[feature]; // make a copy the clinet data.
|
|
255
|
-
this.state('set', feature);
|
|
256
|
+
this.state('set', `feature:${id}`);
|
|
256
257
|
this[_fe] = { // set this_security with data
|
|
257
|
-
id
|
|
258
|
+
id, // uuid of the security feature
|
|
258
259
|
client_id: id, // client id for reference
|
|
259
260
|
client_name: profile.name, // client name for personalization
|
|
260
261
|
concerns: data.concerns, // any concerns for client
|
|
@@ -262,11 +263,11 @@ class Deva {
|
|
|
262
263
|
personal: data.devas[this._agent.key], // Client personal features and rules.
|
|
263
264
|
};
|
|
264
265
|
delete this._client.features[feature]; // make a copy the clinet data.
|
|
265
|
-
this.state('resolve', feature);
|
|
266
|
+
this.state('resolve', `${feature}:${id}`);
|
|
266
267
|
return resolve(feature); // resolve when done
|
|
267
268
|
}
|
|
268
269
|
} catch (e) {
|
|
269
|
-
this.state('
|
|
270
|
+
this.state('catch', `${feature}:${id}`);
|
|
270
271
|
return this.error(e, feature, reject); // run error handling if an error is caught
|
|
271
272
|
}
|
|
272
273
|
}
|
|
@@ -389,11 +390,11 @@ class Deva {
|
|
|
389
390
|
Done(resolve, reject) {
|
|
390
391
|
this.action('done');
|
|
391
392
|
try {
|
|
392
|
-
this.state('
|
|
393
|
+
this.state('done');
|
|
393
394
|
delete this._client.features; // delete the features key when done.
|
|
394
395
|
return resolve(this.client()); // resolve an empty pr
|
|
395
396
|
} catch (e) {
|
|
396
|
-
this.state('
|
|
397
|
+
this.state('catch', 'done');
|
|
397
398
|
return this.error(e, false, reject);
|
|
398
399
|
}
|
|
399
400
|
}
|
|
@@ -409,6 +410,7 @@ class Deva {
|
|
|
409
410
|
to create seamless collaboration between Devas.
|
|
410
411
|
***************/
|
|
411
412
|
talk(evt, resource=false) {
|
|
413
|
+
this.action('talk', evt);
|
|
412
414
|
return this.events.emit(evt, resource);
|
|
413
415
|
}
|
|
414
416
|
|
|
@@ -420,6 +422,7 @@ class Deva {
|
|
|
420
422
|
describe: setup a new event listener in the system.
|
|
421
423
|
***************/
|
|
422
424
|
listen(evt, callback) {
|
|
425
|
+
this.action('listen', evt);
|
|
423
426
|
this.listeners[evt] = callback;
|
|
424
427
|
return this.events.on(evt, packet => {
|
|
425
428
|
return this.listeners[evt](packet);
|
|
@@ -434,6 +437,7 @@ class Deva {
|
|
|
434
437
|
describe:
|
|
435
438
|
***************/
|
|
436
439
|
once(evt, callback) {
|
|
440
|
+
this.action('once', evt)
|
|
437
441
|
return this.events.once(evt, callback);
|
|
438
442
|
}
|
|
439
443
|
|
|
@@ -445,6 +449,7 @@ class Deva {
|
|
|
445
449
|
describe: The ignore function allow the removal of events in the listener group.
|
|
446
450
|
***************/
|
|
447
451
|
ignore(evt, callback) {
|
|
452
|
+
this.action('ignore', evt);
|
|
448
453
|
return this.events.removeListener(evt, callback);
|
|
449
454
|
}
|
|
450
455
|
|
|
@@ -458,11 +463,11 @@ class Deva {
|
|
|
458
463
|
describe:
|
|
459
464
|
***************/
|
|
460
465
|
question(TEXT=false, DATA=false) {
|
|
466
|
+
const id = this.lib.uid(); // generate a unique id for transport.
|
|
461
467
|
// check the active status
|
|
462
468
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
463
|
-
this.zone('question');
|
|
464
|
-
|
|
465
|
-
const id = this.lib.uid(); // generate a unique id for transport.
|
|
469
|
+
this.zone('question', id);
|
|
470
|
+
this.action('question', id);
|
|
466
471
|
const t_split = TEXT.split(' '); // split the text on spaces to get words.
|
|
467
472
|
const data = DATA; // set the DATA to data
|
|
468
473
|
|
|
@@ -483,12 +488,12 @@ class Deva {
|
|
|
483
488
|
let text = TEXT, // let TEXT is text for a manipulation variable
|
|
484
489
|
params = false, // params as false to build params string
|
|
485
490
|
method = 'question', // set the default method to question
|
|
486
|
-
key = this.
|
|
491
|
+
key = this.agent().key; // set a temporary key from the agent key.
|
|
487
492
|
|
|
488
493
|
return new Promise((resolve, reject) => {
|
|
489
494
|
// resolve with the no text message if the client says nothing.
|
|
490
495
|
if (!TEXT) return resolve(this._messages.notext, resolve);
|
|
491
|
-
this.state('try',
|
|
496
|
+
this.state('try', `question:${id}`);
|
|
492
497
|
try { // try to answer the question
|
|
493
498
|
if (isAsk) { // determine if hte question isAsk
|
|
494
499
|
// if:isAsk split the agent key and remove first command character
|
|
@@ -497,17 +502,17 @@ class Deva {
|
|
|
497
502
|
params = t_split[1] ? t_split[1].split(':') : false;
|
|
498
503
|
method = params[0]; // the method to check is then params index 0
|
|
499
504
|
text = t_split.slice(2).join(' ').trim(); // rejoin the text with space
|
|
500
|
-
this.state('ask', `${key}
|
|
505
|
+
this.state('ask', `${key}:${method}:${id}`);
|
|
501
506
|
}
|
|
502
507
|
else if (isCmd) { // determine if the question is a command
|
|
503
508
|
//if:isCmd use text split index 1 as the parameter block
|
|
504
509
|
params = t_split[0] ? t_split[0].split(':').slice(1) : false;
|
|
505
510
|
method = t_split[0].substring(1); // if:isCmd use the 0 index as the command
|
|
506
511
|
text = t_split.slice(1).join(' ').trim(); // if:isCmd rejoin the string on the space after removing first index
|
|
507
|
-
this.state('cmd', method); // set the state to cmd.
|
|
512
|
+
this.state('cmd', `${method}:${id}`); // set the state to cmd.
|
|
508
513
|
}
|
|
509
514
|
|
|
510
|
-
this.state('set', `question:${method}`)
|
|
515
|
+
this.state('set', `question:${method}:${id}`)
|
|
511
516
|
packet.q = { // build packet.q container
|
|
512
517
|
id: this.lib.uid(), // set the transport id for the question.
|
|
513
518
|
agent: this.agent(), // set the agent
|
|
@@ -525,22 +530,19 @@ class Deva {
|
|
|
525
530
|
// hash the question
|
|
526
531
|
packet.q.meta.hash = this.lib.hash(packet.q);
|
|
527
532
|
|
|
528
|
-
this.action('talk', config.events.question);
|
|
529
533
|
this.talk(config.events.question, this.lib.copy(packet)); // global question event make sure to copy data.
|
|
530
534
|
|
|
531
535
|
if (isAsk) { // isAsk check if the question isAsk and talk
|
|
532
536
|
// if: isAsk wait for the once event which is key'd to the packet ID for specified responses
|
|
533
|
-
this.action('talk', `${key}:ask`);
|
|
534
537
|
this.talk(`${key}:ask`, packet);
|
|
535
538
|
this.once(`${key}:ask:${packet.id}`, answer => {
|
|
536
|
-
this.action('talk', config.events.ask);
|
|
537
539
|
this.talk(config.events.ask, this.lib.copy(answer));
|
|
538
|
-
this.state('
|
|
540
|
+
this.state('return', `${key}:ask:${id}`);
|
|
539
541
|
return this.finish(answer, resolve); // if:isAsk resolve the answer from the call
|
|
540
542
|
});
|
|
541
543
|
}
|
|
542
544
|
else { // else: answer the question locally
|
|
543
|
-
this.state('answer', method); //set the answer state to the method
|
|
545
|
+
this.state('answer', `${method}:${id}`); //set the answer state to the method
|
|
544
546
|
return this.answer(packet, resolve, reject);
|
|
545
547
|
}
|
|
546
548
|
}
|
|
@@ -564,18 +566,18 @@ class Deva {
|
|
|
564
566
|
answer(packet, resolve, reject) {
|
|
565
567
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
566
568
|
this.zone('answer'); // set zone to answer
|
|
567
|
-
|
|
568
569
|
const agent = this.agent();
|
|
569
570
|
const client = this.client();
|
|
570
571
|
// check if method exists and is of type function
|
|
571
572
|
const {method,params} = packet.q.meta;
|
|
572
|
-
|
|
573
|
+
this.action('answer', method);
|
|
574
|
+
|
|
573
575
|
this.state('try', `answer:${method}`);
|
|
574
576
|
try {
|
|
575
577
|
const isMethod = this.methods[method] && typeof this.methods[method] == 'function';
|
|
576
578
|
if (!isMethod) return resolve(this._methodNotFound(packet)); // resolve method not found if check if check fails
|
|
577
579
|
|
|
578
|
-
this.action('method', method);
|
|
580
|
+
this.action('method', `answer:${method}`);
|
|
579
581
|
this.methods[method](packet).then(result => {
|
|
580
582
|
// check the result for the text, html, and data object. // this is for when answers are returned from nested Devas.
|
|
581
583
|
const text = typeof result === 'object' ? result.text : result;
|
|
@@ -599,7 +601,6 @@ class Deva {
|
|
|
599
601
|
created: Date.now(), // set the created date for the answer
|
|
600
602
|
};
|
|
601
603
|
// create a hash for the answer and insert into answer meta.
|
|
602
|
-
this.action('talk', config.events.answer)
|
|
603
604
|
packet_answer.meta.hash = this.lib.hash(packet_answer);
|
|
604
605
|
packet.a = packet_answer; // set the packet.a to the packet_answer
|
|
605
606
|
this.talk(config.events.answer, this.lib.copy(packet)); // global talk event
|
|
@@ -678,9 +679,7 @@ class Deva {
|
|
|
678
679
|
|
|
679
680
|
packet_answer.meta.hash = this.lib.hash(packet_answer);
|
|
680
681
|
packet.a = packet_answer;
|
|
681
|
-
this.action('talk', config.events.answer);
|
|
682
682
|
this.talk(config.events.answer, this.lib.copy(packet)); // global talk event
|
|
683
|
-
this.action('talk', `ask:${packet.id}`);
|
|
684
683
|
this.talk(`${agent.key}:ask:${packet.id}`, packet);
|
|
685
684
|
}).catch(err => {
|
|
686
685
|
this.talk(`${agent.key}:ask:${packet.id}`, {error:err});
|
|
@@ -847,16 +846,14 @@ class Deva {
|
|
|
847
846
|
***************/
|
|
848
847
|
ready(packet, resolve) {
|
|
849
848
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
850
|
-
this.action('ready'); // set the complete action
|
|
849
|
+
this.action('ready', packet.id); // set the complete action
|
|
851
850
|
|
|
852
851
|
packet.hash = this.lib.hash(packet);// hash the entire packet before completeing.
|
|
853
852
|
// check for agent on complete function in agent
|
|
854
853
|
const hasOnReady = this.onReady && typeof this.onReady === 'function';
|
|
855
854
|
|
|
856
|
-
// if: agent has on complete then return on complete
|
|
857
|
-
this.state('ready'); // set the finish state
|
|
858
|
-
|
|
859
855
|
// return the provided resolve function or a promise resolve.
|
|
856
|
+
this.state('ready', packet.id); // set the finish state
|
|
860
857
|
return hasOnReady ? this.onReady(packet, resolve) : resolve(packet);
|
|
861
858
|
}
|
|
862
859
|
|
|
@@ -872,15 +869,11 @@ class Deva {
|
|
|
872
869
|
***************/
|
|
873
870
|
finish(packet, resolve) {
|
|
874
871
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
875
|
-
this.action('finish'); // set the finish action
|
|
876
|
-
packet.hash = this.lib.hash(packet);// hash the entire packet before finishing.
|
|
872
|
+
this.action('finish', packet.id); // set the finish action
|
|
877
873
|
// check for agent on finish function in agent
|
|
878
874
|
const hasOnFinish = this.onFinish && typeof this.onFinish === 'function';
|
|
879
|
-
|
|
880
|
-
// if: agent has on finish then return on finish
|
|
881
|
-
this.state('finish'); // set the finish state
|
|
882
|
-
|
|
883
875
|
// return the provided resolve function or a promise resolve.
|
|
876
|
+
this.state('finish', id); // set the finish state
|
|
884
877
|
return hasOnFinish ? this.onFinish(packet, resolve) : this.complete(packet, resolve);
|
|
885
878
|
}
|
|
886
879
|
|
|
@@ -895,15 +888,15 @@ class Deva {
|
|
|
895
888
|
***************/
|
|
896
889
|
complete(packet, resolve) {
|
|
897
890
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
898
|
-
this.action('complete'); // set the complete action
|
|
891
|
+
this.action('complete', packet.id); // set the complete action
|
|
892
|
+
packet.created = Date.now();// set the complete date on the whole packet.
|
|
893
|
+
delete packet.hash;
|
|
894
|
+
packet.hash = this.lib.hash(packet);// hash the entire packet before complete.
|
|
899
895
|
|
|
900
|
-
packet.hash = this.lib.hash(packet);// hash the entire packet before completeing.
|
|
901
896
|
// check for agent on complete function in agent
|
|
902
897
|
const hasOnComplete = this.onComplete && typeof this.onComplete === 'function';
|
|
903
|
-
|
|
904
|
-
// if: agent has on complete then return on complete
|
|
905
|
-
this.state('complete'); // set the finish state
|
|
906
898
|
// return the provided resolve function or a promise resolve.
|
|
899
|
+
this.state('complete', packet.id); // set the finish state
|
|
907
900
|
return hasOnComplete ? this.onComplete(packet, resolve) : resolve(packet);
|
|
908
901
|
}
|
|
909
902
|
|
|
@@ -921,21 +914,23 @@ class Deva {
|
|
|
921
914
|
this.stop()
|
|
922
915
|
***************/
|
|
923
916
|
stop() {
|
|
924
|
-
this.
|
|
917
|
+
const id = this.lib.uid();
|
|
925
918
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
926
|
-
this.
|
|
919
|
+
this.zone('stop', id); // set the zone to stop
|
|
920
|
+
this.action('stop', id); // set the stop action
|
|
921
|
+
|
|
927
922
|
const data = { // build the stop data
|
|
928
|
-
id
|
|
929
|
-
agent: this.agent(), // set the agent
|
|
930
|
-
client: this.client(), // set the client
|
|
923
|
+
id, // set the id
|
|
931
924
|
key: 'stop', // set the key
|
|
932
925
|
value: this._messages.stop, // set the value
|
|
926
|
+
agent: this.agent(), // set the agent
|
|
927
|
+
client: this.client(), // set the client
|
|
933
928
|
created: Date.now(), // set the created date
|
|
934
929
|
}
|
|
935
|
-
this.action('stop'); // set the stop action
|
|
936
930
|
// has stop function then set hasOnStop variable
|
|
937
931
|
const hasOnStop = this.onStop && typeof this.onStop === 'function';
|
|
938
932
|
// if: has on stop then run on stop function or return exit function.
|
|
933
|
+
this.state('stop', id); // set the state to stop
|
|
939
934
|
return hasOnStop ? this.onStop(data) : this.exit()
|
|
940
935
|
}
|
|
941
936
|
|
|
@@ -951,18 +946,16 @@ class Deva {
|
|
|
951
946
|
function.
|
|
952
947
|
***************/
|
|
953
948
|
exit() {
|
|
954
|
-
this.
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
const client = this.client();
|
|
949
|
+
const id = this.lib.uid();
|
|
950
|
+
this.zone('exit', id);
|
|
951
|
+
this.action('exit', id);
|
|
958
952
|
|
|
959
|
-
this.action('exit');
|
|
960
953
|
const data = {
|
|
961
|
-
id
|
|
954
|
+
id,
|
|
962
955
|
key: 'exit',
|
|
963
956
|
value: this._messages.exit,
|
|
964
|
-
agent,
|
|
965
|
-
client,
|
|
957
|
+
agent: this.agent(),
|
|
958
|
+
client: this.client(),
|
|
966
959
|
created: Date.now(),
|
|
967
960
|
}
|
|
968
961
|
data.hash = this.lib.hash(data);
|
|
@@ -979,7 +972,7 @@ class Deva {
|
|
|
979
972
|
this._authority = false;
|
|
980
973
|
this._justice = false;
|
|
981
974
|
|
|
982
|
-
this.state('exit');
|
|
975
|
+
this.state('exit', id);
|
|
983
976
|
const hasOnExit = this.onExit && typeof this.onExit === 'function';
|
|
984
977
|
return hasOnExit ? this.onExit(data) : Promise.resolve(data)
|
|
985
978
|
}
|
|
@@ -1022,14 +1015,17 @@ class Deva {
|
|
|
1022
1015
|
describe: returns the avaiable staets values.
|
|
1023
1016
|
***************/
|
|
1024
1017
|
states() {
|
|
1025
|
-
this.
|
|
1026
|
-
this.
|
|
1027
|
-
|
|
1028
|
-
id
|
|
1018
|
+
const id = this.lib.uid();
|
|
1019
|
+
this.action('states', id);
|
|
1020
|
+
const data = {
|
|
1021
|
+
id,
|
|
1029
1022
|
key: 'states',
|
|
1030
1023
|
value: this._states,
|
|
1031
|
-
created: Date.now(),
|
|
1024
|
+
created: Date.now(),
|
|
1032
1025
|
}
|
|
1026
|
+
data.hash = this.lib.hash(data);
|
|
1027
|
+
this.state('return', `states:${id}`);
|
|
1028
|
+
return data;
|
|
1033
1029
|
}
|
|
1034
1030
|
|
|
1035
1031
|
/**************
|
|
@@ -1039,15 +1035,19 @@ class Deva {
|
|
|
1039
1035
|
describe
|
|
1040
1036
|
***************/
|
|
1041
1037
|
zone(value=false, extra=false) {
|
|
1038
|
+
const id = this.lib.uid();
|
|
1039
|
+
this.action('zone', `zone:${value}:${id}`);
|
|
1040
|
+
|
|
1042
1041
|
if (!value || !this._zones[value] || value === this._zone) return;
|
|
1042
|
+
|
|
1043
|
+
this.state('try', `zone:${value}:${id}`)
|
|
1043
1044
|
try {
|
|
1044
1045
|
this._zone = value;
|
|
1045
|
-
|
|
1046
1046
|
const lookup = this._zones[value]; // set the lookup value
|
|
1047
1047
|
const text = extra ? `${lookup} ${extra}` : lookup; // set the text value
|
|
1048
1048
|
|
|
1049
1049
|
const data = { // build the zone data
|
|
1050
|
-
id
|
|
1050
|
+
id, // set the packetid
|
|
1051
1051
|
agent: this.agent(),
|
|
1052
1052
|
client: this.client(),
|
|
1053
1053
|
key: 'zone',
|
|
@@ -1057,8 +1057,11 @@ class Deva {
|
|
|
1057
1057
|
};
|
|
1058
1058
|
data.hash = this.lib.hash(data);
|
|
1059
1059
|
this.talk(config.events.zone, data);
|
|
1060
|
+
this.state('return', `zone:${value}:${id}`);
|
|
1061
|
+
return data;
|
|
1060
1062
|
} catch (e) {
|
|
1061
|
-
|
|
1063
|
+
this.state('catch', `zone:${value}:${id}`);
|
|
1064
|
+
return this.error(e, value);
|
|
1062
1065
|
}
|
|
1063
1066
|
}
|
|
1064
1067
|
|
|
@@ -1068,10 +1071,11 @@ class Deva {
|
|
|
1068
1071
|
describe: returns a listing of zones currently in the system.
|
|
1069
1072
|
***************/
|
|
1070
1073
|
zones() {
|
|
1071
|
-
this.
|
|
1072
|
-
this.
|
|
1074
|
+
const id = this.lib.uid();
|
|
1075
|
+
this.action('zones', id);
|
|
1076
|
+
this.state('return', `zones:${id}`);
|
|
1073
1077
|
return {
|
|
1074
|
-
id
|
|
1078
|
+
id, // set the uuid of the data
|
|
1075
1079
|
agent: this.agent(), // set the agent value
|
|
1076
1080
|
cleint: this.client(), // set the client value
|
|
1077
1081
|
key: 'zones', // set the key return value
|
|
@@ -1088,6 +1092,8 @@ class Deva {
|
|
|
1088
1092
|
describe
|
|
1089
1093
|
***************/
|
|
1090
1094
|
action(value=false, extra=false) {
|
|
1095
|
+
const id = this.lib.uid();
|
|
1096
|
+
this.state('try', `action:${value}:${id}`);
|
|
1091
1097
|
try {
|
|
1092
1098
|
if (!value || !this._actions[value] || value === this._action) return;
|
|
1093
1099
|
this._action = value; // set the local action variable
|
|
@@ -1098,7 +1104,7 @@ class Deva {
|
|
|
1098
1104
|
const msg = msg_action || action; // set the correct message
|
|
1099
1105
|
const text = extra ? `${msg} ${extra}` : msg; // set the text of the action
|
|
1100
1106
|
const data = { // build the data object for the action.
|
|
1101
|
-
id
|
|
1107
|
+
id, // generate a guid for the action transmitssion.
|
|
1102
1108
|
agent: this.agent(), // the agent data to send with the action
|
|
1103
1109
|
client: this.client(), // the client data to send with the action
|
|
1104
1110
|
key: 'action', // the key for event to transmit action type
|
|
@@ -1108,8 +1114,10 @@ class Deva {
|
|
|
1108
1114
|
};
|
|
1109
1115
|
data.hash = this.lib.hash(data); // generate a hash of the action packet.
|
|
1110
1116
|
this.talk(config.events.action, data); // talk the core action event
|
|
1117
|
+
this.state('return', `action:${value}:${id}`);
|
|
1111
1118
|
return data;
|
|
1112
1119
|
} catch (e) { // catch any errors that occur
|
|
1120
|
+
this.state('catch', `action:${value}:${id}`);
|
|
1113
1121
|
return this.error(e); // return error on error catch
|
|
1114
1122
|
}
|
|
1115
1123
|
}
|
|
@@ -1120,10 +1128,10 @@ class Deva {
|
|
|
1120
1128
|
describe: Returns a list of available actions in the system.
|
|
1121
1129
|
***************/
|
|
1122
1130
|
actions() {
|
|
1123
|
-
this.
|
|
1124
|
-
this.
|
|
1131
|
+
const id = this.lib.uid();
|
|
1132
|
+
this.action('actions', id);
|
|
1125
1133
|
const data = {
|
|
1126
|
-
id
|
|
1134
|
+
id, // set the id with a uuid
|
|
1127
1135
|
agent: this.agent(), // set the agent value
|
|
1128
1136
|
client: this.client(), // set the client value
|
|
1129
1137
|
key: 'actions', // set the data key
|
|
@@ -1131,6 +1139,7 @@ class Deva {
|
|
|
1131
1139
|
created: Date.now(), // set the data created date
|
|
1132
1140
|
};
|
|
1133
1141
|
data.hash = this.lib.hash(data)
|
|
1142
|
+
this.state('return', `actions:${id}`);
|
|
1134
1143
|
return data;
|
|
1135
1144
|
}
|
|
1136
1145
|
|
|
@@ -1142,6 +1151,9 @@ class Deva {
|
|
|
1142
1151
|
describe
|
|
1143
1152
|
***************/
|
|
1144
1153
|
feature(value=false, extra=false) {
|
|
1154
|
+
const id = this.lib.uid();
|
|
1155
|
+
this.action('feature', value);
|
|
1156
|
+
this.state('try', `feature:${value}:${id}`);
|
|
1145
1157
|
try {
|
|
1146
1158
|
if (!value || !this._features[value]) return; // check feature value
|
|
1147
1159
|
|
|
@@ -1149,7 +1161,7 @@ class Deva {
|
|
|
1149
1161
|
const text = extra ? `${lookup} ${extra}` : lookup; // set the text value
|
|
1150
1162
|
|
|
1151
1163
|
const data = { // build data object
|
|
1152
|
-
id
|
|
1164
|
+
id, // set the id
|
|
1153
1165
|
agent: this.agent(), // set the agent transporting the packet.
|
|
1154
1166
|
key: 'feature', // set the key for transport
|
|
1155
1167
|
value, // set the value of the key
|
|
@@ -1158,8 +1170,10 @@ class Deva {
|
|
|
1158
1170
|
};
|
|
1159
1171
|
data.hash = this.lib.hash(data); // generate the hash value of the data packet
|
|
1160
1172
|
this.talk(config.events.feature, data); // talk the feature event with data
|
|
1173
|
+
this.state('return', `feature:${value}:${id}`);
|
|
1161
1174
|
return data;
|
|
1162
1175
|
} catch (e) { // catch any errors
|
|
1176
|
+
this.state('catch', `feature:${value}:${id}`);
|
|
1163
1177
|
return this.error(e); // retun this.error when an error is caught.
|
|
1164
1178
|
}
|
|
1165
1179
|
}
|
|
@@ -1170,9 +1184,10 @@ class Deva {
|
|
|
1170
1184
|
describe: return a list of features that are available to the system.
|
|
1171
1185
|
***************/
|
|
1172
1186
|
features() {
|
|
1173
|
-
this.
|
|
1187
|
+
const id = this.lib.uid();
|
|
1188
|
+
this.action('features', id);
|
|
1174
1189
|
const data = {
|
|
1175
|
-
id
|
|
1190
|
+
id, // set the object id
|
|
1176
1191
|
agent: this.agent(), // set the agent value.
|
|
1177
1192
|
client: this.client(), // set the client value.
|
|
1178
1193
|
key: 'features', // set the key
|
|
@@ -1180,6 +1195,7 @@ class Deva {
|
|
|
1180
1195
|
created: Date.now(), // set the created date.
|
|
1181
1196
|
};
|
|
1182
1197
|
data.hash = this.lib.hash(data);
|
|
1198
|
+
this.state('return', `features:${id}`);
|
|
1183
1199
|
return data;
|
|
1184
1200
|
}
|
|
1185
1201
|
|
|
@@ -1191,16 +1207,18 @@ class Deva {
|
|
|
1191
1207
|
describe
|
|
1192
1208
|
***************/
|
|
1193
1209
|
context(value=false, extra=false) {
|
|
1210
|
+
const id = this.lib.uid();
|
|
1211
|
+
this.action('context', value);
|
|
1194
1212
|
this.state('try', `context:${value}`);
|
|
1195
1213
|
try {
|
|
1196
1214
|
if (!value) return;
|
|
1197
|
-
this.state('set', `context:${value}`);
|
|
1215
|
+
this.state('set', `context:${value}:${id}`);
|
|
1198
1216
|
this._context = value;
|
|
1199
1217
|
const lookup = this.vars.context[value] || value;
|
|
1200
1218
|
const text = extra ? `${lookup} ${extra}` : lookup;
|
|
1201
1219
|
|
|
1202
1220
|
const data = {
|
|
1203
|
-
id
|
|
1221
|
+
id,
|
|
1204
1222
|
agent: this.agent(),
|
|
1205
1223
|
client: this.client(),
|
|
1206
1224
|
key: 'context',
|
|
@@ -1213,7 +1231,7 @@ class Deva {
|
|
|
1213
1231
|
this.state('return', `context:${value}:${data.id}`);
|
|
1214
1232
|
return data;
|
|
1215
1233
|
} catch (e) {
|
|
1216
|
-
this.state('catch', `context:${value}`);
|
|
1234
|
+
this.state('catch', `context:${value}:${id}`);
|
|
1217
1235
|
return this.error(e, value);
|
|
1218
1236
|
}
|
|
1219
1237
|
}
|
|
@@ -1367,7 +1385,7 @@ class Deva {
|
|
|
1367
1385
|
describe: This function will enable fast loading of Deva into the system.
|
|
1368
1386
|
***************/
|
|
1369
1387
|
load(key, client) {
|
|
1370
|
-
this.zone('
|
|
1388
|
+
this.zone('deva', key);
|
|
1371
1389
|
this.action('load', key);
|
|
1372
1390
|
this.state('load', key);
|
|
1373
1391
|
return this.devas[key].init(client);
|
|
@@ -1380,7 +1398,7 @@ class Deva {
|
|
|
1380
1398
|
describe: Unload a currently loaded Deva.
|
|
1381
1399
|
***************/
|
|
1382
1400
|
unload(key) {
|
|
1383
|
-
this.zone('
|
|
1401
|
+
this.zone('deva', key);
|
|
1384
1402
|
return new Promise((resolve, reject) => {
|
|
1385
1403
|
try {
|
|
1386
1404
|
this.action('uload', key);
|
|
@@ -1406,11 +1424,14 @@ class Deva {
|
|
|
1406
1424
|
usage: this.prompt('text')
|
|
1407
1425
|
***************/
|
|
1408
1426
|
prompt(text) {
|
|
1427
|
+
const id = this.lib.uid();
|
|
1428
|
+
this.action('prompt', id);
|
|
1429
|
+
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
1409
1430
|
// Talk a global prompt event for the client
|
|
1410
1431
|
const agent = this.agent();
|
|
1411
1432
|
const client = this.client();
|
|
1412
|
-
const
|
|
1413
|
-
id
|
|
1433
|
+
const data = {
|
|
1434
|
+
id,
|
|
1414
1435
|
key: 'prompt',
|
|
1415
1436
|
value: agent.key,
|
|
1416
1437
|
agent,
|
|
@@ -1418,8 +1439,10 @@ class Deva {
|
|
|
1418
1439
|
text,
|
|
1419
1440
|
created: Date.now(),
|
|
1420
1441
|
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1442
|
+
data.hash = this.lib.hash(data);
|
|
1443
|
+
this.talk(config.events.prompt, data);
|
|
1444
|
+
this.state('return', `prompt:${id}`);
|
|
1445
|
+
return data;
|
|
1423
1446
|
}
|
|
1424
1447
|
|
|
1425
1448
|
/**************
|
|
@@ -1428,11 +1451,16 @@ class Deva {
|
|
|
1428
1451
|
describe: return core data.
|
|
1429
1452
|
***************/
|
|
1430
1453
|
core() {
|
|
1431
|
-
|
|
1454
|
+
const id = this.lib.uid();
|
|
1455
|
+
this.action('core', id);
|
|
1432
1456
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
1457
|
+
|
|
1458
|
+
// check the active status
|
|
1433
1459
|
const data = this.lib.copy(this._core);
|
|
1434
|
-
data.id =
|
|
1460
|
+
data.id = id;
|
|
1461
|
+
data.created = Date.now();
|
|
1435
1462
|
data.hash = this.lib.hash(data);
|
|
1463
|
+
this.state('return', `core:${id}`);
|
|
1436
1464
|
return data;
|
|
1437
1465
|
}
|
|
1438
1466
|
|
|
@@ -1442,11 +1470,15 @@ class Deva {
|
|
|
1442
1470
|
describe: return info data.
|
|
1443
1471
|
***************/
|
|
1444
1472
|
info() {
|
|
1445
|
-
|
|
1473
|
+
const id = this.lib.uid();
|
|
1474
|
+
this.action('info', id);
|
|
1446
1475
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
1476
|
+
|
|
1447
1477
|
const data = this.lib.copy(this._info);
|
|
1448
|
-
data.id =
|
|
1478
|
+
data.id = id;
|
|
1479
|
+
data.created = Date.now();
|
|
1449
1480
|
data.hash = this.lib.hash(data);
|
|
1481
|
+
this.state('return', `info:${id}`);
|
|
1450
1482
|
return data;
|
|
1451
1483
|
}
|
|
1452
1484
|
|
|
@@ -1462,12 +1494,15 @@ class Deva {
|
|
|
1462
1494
|
usage: this.status('msg')
|
|
1463
1495
|
***************/
|
|
1464
1496
|
status() {
|
|
1497
|
+
const id = this.lib.uid();
|
|
1498
|
+
this.action('status', id);
|
|
1465
1499
|
// check the active status
|
|
1466
1500
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
1467
1501
|
|
|
1468
1502
|
// format the date since active for output.
|
|
1469
1503
|
const dateFormat = this.lib.formatDate(this._active, 'long', true);
|
|
1470
1504
|
// create the text msg string
|
|
1505
|
+
this.state('return', `status:${id}`);
|
|
1471
1506
|
return `${this._agent.profile.name} active since ${dateFormat}`; // return final text string
|
|
1472
1507
|
}
|
|
1473
1508
|
|
|
@@ -1483,28 +1518,32 @@ class Deva {
|
|
|
1483
1518
|
***************/
|
|
1484
1519
|
help(msg, help_dir) {
|
|
1485
1520
|
return new Promise((resolve, reject) => {
|
|
1521
|
+
const id = this.lib.uid();
|
|
1522
|
+
this.context('help', id);
|
|
1523
|
+
this.zone('help', id);
|
|
1524
|
+
this.feature('help', id);
|
|
1525
|
+
this.action('help', id);
|
|
1526
|
+
this.state('help', id);
|
|
1486
1527
|
if (!this._active) return resolve(this._messages.offline);
|
|
1487
1528
|
const params = msg.split(' '); // split the msg into an array by spaces.
|
|
1488
1529
|
let helpFile = 'main'; // set default help file
|
|
1489
1530
|
if (params[0]) helpFile = params[0]; // check the msg for a help file
|
|
1490
1531
|
if (params[1]) helpFile = `${params[0]}_${params[1]}`;
|
|
1491
1532
|
|
|
1492
|
-
this.context('help', helpFile);
|
|
1493
|
-
this.zone('help', helpFile);
|
|
1494
|
-
this.feature('help', helpFile);
|
|
1495
|
-
this.action('help', helpFile);
|
|
1496
|
-
this.state('help', helpFile);
|
|
1497
1533
|
|
|
1498
1534
|
const helpPath = this.lib.path.join(help_dir, 'help', `${helpFile}.feecting`);
|
|
1499
|
-
this.state('try', `help:${
|
|
1535
|
+
this.state('try', `help:${id}`);
|
|
1500
1536
|
try {
|
|
1501
1537
|
const helpExists = this.lib.fs.existsSync(helpPath); // check if help file exists
|
|
1502
|
-
if (!helpExists)
|
|
1538
|
+
if (!helpExists) {
|
|
1539
|
+
this.state('return', `${this._messages.help_not_found}:${id}`);
|
|
1540
|
+
return resolve(this._messages.help_not_found);
|
|
1541
|
+
}
|
|
1503
1542
|
const helpDoc = this.lib.fs.readFileSync(helpPath, 'utf8');
|
|
1504
|
-
this.state('
|
|
1543
|
+
this.state('return', `help:${id}`);
|
|
1505
1544
|
return resolve(helpDoc);
|
|
1506
1545
|
} catch (e) {
|
|
1507
|
-
this.state('catch', `help:${
|
|
1546
|
+
this.state('catch', `help:${id}`);
|
|
1508
1547
|
return this.error(e, msg, reject);
|
|
1509
1548
|
}
|
|
1510
1549
|
});
|
|
@@ -1521,12 +1560,16 @@ class Deva {
|
|
|
1521
1560
|
usage: this.error(err, data, reject);
|
|
1522
1561
|
***************/
|
|
1523
1562
|
error(err,data=false,reject=false) {
|
|
1524
|
-
this.
|
|
1525
|
-
this.
|
|
1563
|
+
const id = this.lib.uid();
|
|
1564
|
+
this.context('error', id);
|
|
1565
|
+
this.zone('error', id);
|
|
1566
|
+
this.action('error', id);
|
|
1567
|
+
this.state('error', id);
|
|
1568
|
+
|
|
1526
1569
|
const agent = this.agent();
|
|
1527
1570
|
const client = this.client();
|
|
1528
1571
|
const _data = {
|
|
1529
|
-
id
|
|
1572
|
+
id,
|
|
1530
1573
|
key: 'error',
|
|
1531
1574
|
value: agent.key,
|
|
1532
1575
|
agent,
|
|
@@ -1543,7 +1586,7 @@ class Deva {
|
|
|
1543
1586
|
this.talk(config.events.error, this.lib.copy(_data));
|
|
1544
1587
|
const hasOnError = this.onError && typeof this.onError === 'function' ? true : false;
|
|
1545
1588
|
|
|
1546
|
-
this.state('error
|
|
1589
|
+
this.state('return', `error:${id}`);
|
|
1547
1590
|
if (hasOnError) return this.onError(err, data, reject);
|
|
1548
1591
|
else return reject ? reject(err) : err;
|
|
1549
1592
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indra.ai/deva",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.7",
|
|
4
4
|
"description": "The Deva Core",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"copyright": "(c)2025 Quinn Michaels; All rights reserved.",
|
|
@@ -150,7 +150,6 @@
|
|
|
150
150
|
"destroy": "๐ฃ Destroy",
|
|
151
151
|
"write": "๐ Write",
|
|
152
152
|
"save": "๐พ Save",
|
|
153
|
-
"delete": "๐งจ Delete",
|
|
154
153
|
"set": "๐ Set",
|
|
155
154
|
"get": "๐ซด Get",
|
|
156
155
|
"put": "๐ค Put",
|
|
@@ -179,56 +178,19 @@
|
|
|
179
178
|
"denied": "๐ Denied",
|
|
180
179
|
"secure": "๐ Secure",
|
|
181
180
|
"try": "๐ธ Try",
|
|
182
|
-
"catch": "โพ๏ธ Catch"
|
|
183
|
-
},
|
|
184
|
-
"action": false,
|
|
185
|
-
"actions": {
|
|
186
|
-
"init": "๐ Init",
|
|
187
|
-
"wait": "โณ Waiting",
|
|
188
|
-
"start": "๐ฌ Start",
|
|
189
|
-
"enter": "๐ก Enter",
|
|
190
|
-
"exit": "๐ช Exit",
|
|
191
|
-
"stop": "๐ Stop",
|
|
192
|
-
"load": "๐ฆ Load",
|
|
193
|
-
"unload": "๐ฅก Unload",
|
|
194
|
-
"finish": "๐ Finish",
|
|
195
|
-
"complete": "โ
Complete",
|
|
196
|
-
"done": "โ๏ธ Done",
|
|
197
|
-
"ready": "๐ข Ready",
|
|
198
|
-
"question": "๐ Question",
|
|
199
|
-
"talk": "๐ข Talk",
|
|
200
|
-
"context": "๐ Context",
|
|
201
|
-
"prompt": "๐ Prompt",
|
|
202
|
-
"issue": "๐ซ Issue",
|
|
203
|
-
"find": "๐ Find",
|
|
204
|
-
"parse": "๐๏ธ Parse",
|
|
181
|
+
"catch": "โพ๏ธ Catch",
|
|
205
182
|
"view": "๐ View",
|
|
206
183
|
"insert": "๐ Insert",
|
|
207
184
|
"update": "๐ Update",
|
|
208
|
-
"delete": "๐๏ธ Delete"
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
"method": "โค๏ธโ๐ฅ Method",
|
|
213
|
-
"list": "๐ List",
|
|
214
|
-
"reply": "๐ฎ Reply",
|
|
215
|
-
"set": "๐ฝ๏ธ Set",
|
|
216
|
-
"get": "๐ค Get",
|
|
217
|
-
"send": "๐ Send",
|
|
218
|
-
"receive": "๐ฅ
Receive",
|
|
219
|
-
"return": "๐ Return",
|
|
220
|
-
"resolve": "โต๏ธ Resolve",
|
|
221
|
-
"reject": "โ Reject",
|
|
222
|
-
"write": "๐๏ธ Write",
|
|
223
|
-
"question_ask": "๐ฃ๏ธ Asked",
|
|
224
|
-
"question_ask_answer": "๐๏ธ Answered",
|
|
225
|
-
"question_cmd": "๐ช Command",
|
|
226
|
-
"question_answer": "๐ Answer",
|
|
227
|
-
"answer": "๐ก Answer",
|
|
228
|
-
"ask": "๐ฃ Ask",
|
|
185
|
+
"delete": "๐๏ธ Delete"
|
|
186
|
+
},
|
|
187
|
+
"action": false,
|
|
188
|
+
"actions": {
|
|
229
189
|
"client": "๐จ Client",
|
|
230
190
|
"agent": "๐ต๏ธโโ๏ธ Agent",
|
|
231
191
|
"security": "๐ Security",
|
|
192
|
+
"guard": "๐ Guard",
|
|
193
|
+
"defense": "๐ช Defense",
|
|
232
194
|
"support": "๐ฉน Support",
|
|
233
195
|
"services": "๐ ๏ธ Services",
|
|
234
196
|
"systems": "๐ฅ๏ธ Systems",
|
|
@@ -236,26 +198,40 @@
|
|
|
236
198
|
"legal": "๐๏ธ Legal",
|
|
237
199
|
"justice": "๐๏ธ Justice",
|
|
238
200
|
"authority": "๐ฎ Authority",
|
|
239
|
-
"
|
|
240
|
-
"
|
|
241
|
-
"
|
|
201
|
+
"talk": "๐ข Talk",
|
|
202
|
+
"listen": "๐ Listen",
|
|
203
|
+
"once": "๐ Listen Once",
|
|
204
|
+
"ignore": "๐ฆฏ Ignore",
|
|
205
|
+
"question": "๐ Question",
|
|
206
|
+
"answer": "๐ก Answer",
|
|
207
|
+
"ask": "๐ฃ Ask",
|
|
208
|
+
"init": "๐ Init",
|
|
209
|
+
"start": "๐ฌ Start",
|
|
210
|
+
"enter": "๐ก Enter",
|
|
211
|
+
"done": "โ๏ธ Done",
|
|
212
|
+
"ready": "๐ข Ready",
|
|
213
|
+
"finish": "๐ Finish",
|
|
214
|
+
"complete": "โ
Complete",
|
|
215
|
+
"stop": "๐ Stop",
|
|
216
|
+
"exit": "๐ช Exit",
|
|
242
217
|
"actions": "๐๏ธ Actions",
|
|
243
|
-
"zones": "Zones",
|
|
244
218
|
"feature": "๐ฅ Feature",
|
|
245
219
|
"features": "๐ฅ Features",
|
|
220
|
+
"context": "๐ Context",
|
|
246
221
|
"contexts": "๐ Contexts",
|
|
247
|
-
"
|
|
222
|
+
"method": "โค๏ธโ๐ฅ Method",
|
|
223
|
+
"func": "๐ฆ Func",
|
|
224
|
+
"zone": "๐ญ Zone",
|
|
225
|
+
"zones": "๐ช Zones",
|
|
226
|
+
"load": "๐ฆ Load",
|
|
227
|
+
"unload": "๐ฅก Unload",
|
|
228
|
+
"prompt": "๐ Prompt",
|
|
229
|
+
"states": "๐ States",
|
|
230
|
+
"core": "๐ Core",
|
|
231
|
+
"info": "๐โโ๏ธ Info",
|
|
232
|
+
"status": "๐ฅ Status",
|
|
248
233
|
"error": "๐ด ERROR!",
|
|
249
|
-
"
|
|
250
|
-
"unlawful": "๐ฟ Unlawful",
|
|
251
|
-
"audio": "๐ Audio",
|
|
252
|
-
"text": "๐ Text",
|
|
253
|
-
"image": "๐ Image",
|
|
254
|
-
"video": "๐ฝ๏ธ Video",
|
|
255
|
-
"signature": "โ๏ธ Signature",
|
|
256
|
-
"orders": "๐ช Orders",
|
|
257
|
-
"law": "๐ Law",
|
|
258
|
-
"decree": "๐ Decree"
|
|
234
|
+
"help": "๐ Help"
|
|
259
235
|
},
|
|
260
236
|
"feature": false,
|
|
261
237
|
"features": {
|