@indra.ai/deva 1.5.53 β 1.5.55
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 +111 -53
- package/lib/index.js +29 -11
- package/package.json +31 -13
- package/tests/agent.json +14 -3
- package/tests/client.json +11 -1
- package/tests/index.js +48 -13
package/index.js
CHANGED
|
@@ -18,6 +18,9 @@ class Deva {
|
|
|
18
18
|
this._client = {}; // this will be set on init.
|
|
19
19
|
this._active = false; // the active/birth date.
|
|
20
20
|
this._vector = false; // inherited Vector features.
|
|
21
|
+
this._veda = false; // inherited Veda features.
|
|
22
|
+
this._god = false; // inherited God features.
|
|
23
|
+
this._king = false; // inherited King features.
|
|
21
24
|
this._treasury = false; // inherited Vector features.
|
|
22
25
|
this._security = false; // inherited Security features.
|
|
23
26
|
this._guard = false; // inherited Guard features.
|
|
@@ -32,7 +35,7 @@ class Deva {
|
|
|
32
35
|
this._systems = false; // inherited Systems features.
|
|
33
36
|
this._networks = false; // inherited Systems features.
|
|
34
37
|
this.events = opts.events || new EventEmitter({}); // Event Bus
|
|
35
|
-
this.lib = new lib({}); // used for loading library functions
|
|
38
|
+
this.lib = new lib({config}); // used for loading library functions
|
|
36
39
|
this.utils = opts.utils || {}; // parse function
|
|
37
40
|
this.devas = opts.devas || {}; // Devas which are loaded
|
|
38
41
|
this.vars = opts.vars || {}; // Variables object
|
|
@@ -202,7 +205,7 @@ class Deva {
|
|
|
202
205
|
packet.sha256 = this.lib.hash(packet, 'sha256');
|
|
203
206
|
packet.sha512 = this.lib.hash(packet, 'sha512');
|
|
204
207
|
|
|
205
|
-
this.state('invalid', `${meta.method}:${packet.id}`);
|
|
208
|
+
this.state('invalid', `${meta.method}:${packet.id.uid}`);
|
|
206
209
|
return packet;
|
|
207
210
|
}
|
|
208
211
|
|
|
@@ -265,19 +268,19 @@ class Deva {
|
|
|
265
268
|
***************/
|
|
266
269
|
Feature(feature, resolve, reject) {
|
|
267
270
|
const _id = this.lib.uid();
|
|
268
|
-
this.feature(feature, _id);
|
|
269
|
-
this.zone(feature, _id);
|
|
271
|
+
this.feature(feature, _id.uid);
|
|
272
|
+
this.zone(feature, _id.uid);
|
|
270
273
|
const _cl = this.client(); // set local copy of client data
|
|
271
274
|
try {
|
|
272
275
|
if (!_cl.features[feature]) return resolve(); // if no security feature goto Support
|
|
273
276
|
else {
|
|
274
|
-
this.action(feature, _id); // set action to feature
|
|
277
|
+
this.action(feature, _id.uid); // set action to feature
|
|
275
278
|
const _fe = `_${feature}`;
|
|
276
279
|
const {id, profile, features} = _cl; // make a copy the clinet data.
|
|
277
280
|
const data = features[feature]; // make a copy the clinet data.
|
|
278
281
|
this.state('set', `feature:${id}`);
|
|
279
|
-
this[_fe] = { // set
|
|
280
|
-
id: _id, //
|
|
282
|
+
this[_fe] = { // set this feature with data
|
|
283
|
+
id: _id, // uid of the feature
|
|
281
284
|
client_id: id, // client id for reference
|
|
282
285
|
client_name: profile.name, // client name for personalization
|
|
283
286
|
concerns: data.concerns, // any concerns for client
|
|
@@ -286,11 +289,11 @@ class Deva {
|
|
|
286
289
|
created: Date.now(),
|
|
287
290
|
};
|
|
288
291
|
delete this._client.features[feature]; // make a copy the clinet data.
|
|
289
|
-
this.state('resolve', `${feature}:${_id}`);
|
|
292
|
+
this.state('resolve', `${feature}:${_id.uid}`);
|
|
290
293
|
return resolve(feature); // resolve when done
|
|
291
294
|
}
|
|
292
295
|
} catch (e) {
|
|
293
|
-
this.state('catch', `${feature}:${_id}`);
|
|
296
|
+
this.state('catch', `${feature}:${_id.uid}`);
|
|
294
297
|
return this.error(e, feature, reject); // run error handling if an error is caught
|
|
295
298
|
}
|
|
296
299
|
}
|
|
@@ -298,6 +301,17 @@ class Deva {
|
|
|
298
301
|
/**************
|
|
299
302
|
func: Vector
|
|
300
303
|
params: resolve, reject
|
|
304
|
+
describe:
|
|
305
|
+
The Vector feature sets the correct variables and necessary rules for the
|
|
306
|
+
client presented data.
|
|
307
|
+
***************/
|
|
308
|
+
Vector(resolve, reject) {
|
|
309
|
+
return this.Feature('vector', resolve, reject);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**************
|
|
313
|
+
func: Veda
|
|
314
|
+
params: resolve, reject
|
|
301
315
|
describe:
|
|
302
316
|
The Veda feature sets the correct variables and necessary rules for the
|
|
303
317
|
client presented data.
|
|
@@ -307,14 +321,25 @@ class Deva {
|
|
|
307
321
|
}
|
|
308
322
|
|
|
309
323
|
/**************
|
|
310
|
-
func:
|
|
324
|
+
func: God
|
|
311
325
|
params: resolve, reject
|
|
312
326
|
describe:
|
|
313
|
-
The
|
|
327
|
+
The God feature sets the correct variables and necessary rules for the
|
|
314
328
|
client presented data.
|
|
315
329
|
***************/
|
|
316
|
-
|
|
317
|
-
return this.Feature('
|
|
330
|
+
God(resolve, reject) {
|
|
331
|
+
return this.Feature('god', resolve, reject);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**************
|
|
335
|
+
func: King
|
|
336
|
+
params: resolve, reject
|
|
337
|
+
describe:
|
|
338
|
+
The King feature sets the correct variables and necessary rules for the
|
|
339
|
+
client presented data.
|
|
340
|
+
***************/
|
|
341
|
+
King(resolve, reject) {
|
|
342
|
+
return this.Feature('king', resolve, reject);
|
|
318
343
|
}
|
|
319
344
|
|
|
320
345
|
/**************
|
|
@@ -497,7 +522,7 @@ class Deva {
|
|
|
497
522
|
to create seamless collaboration between Devas.
|
|
498
523
|
***************/
|
|
499
524
|
talk(evt, packet=false) {
|
|
500
|
-
this.action('talk', `${evt}:${packet.id}`);
|
|
525
|
+
this.action('talk', `${evt}:${packet.id.uid}`);
|
|
501
526
|
return this.events.emit(evt, packet);
|
|
502
527
|
}
|
|
503
528
|
|
|
@@ -624,14 +649,14 @@ class Deva {
|
|
|
624
649
|
if (isAsk) { // isAsk check if the question isAsk and talk
|
|
625
650
|
// if: isAsk wait for the once event which is key'd to the packet ID for specified responses
|
|
626
651
|
this.talk(`${key}:ask`, packet);
|
|
627
|
-
this.once(`${key}:ask:${packet.id}`, answer => {
|
|
652
|
+
this.once(`${key}:ask:${packet.id.uid}`, answer => {
|
|
628
653
|
this.talk(config.events.ask, this.lib.copy(answer));
|
|
629
|
-
this.state('return', `${key}:ask:${id}`);
|
|
654
|
+
this.state('return', `${key}:ask:${packet.id.uid}`);
|
|
630
655
|
return this.finish(answer, resolve); // if:isAsk resolve the answer from the call
|
|
631
656
|
});
|
|
632
657
|
}
|
|
633
658
|
else { // else: answer the question locally
|
|
634
|
-
this.state('answer', `${method}:${id}`); //set the answer state to the method
|
|
659
|
+
this.state('answer', `${method}:${id.uid}`); //set the answer state to the method
|
|
635
660
|
return this.answer(packet, resolve, reject);
|
|
636
661
|
}
|
|
637
662
|
}
|
|
@@ -730,18 +755,18 @@ class Deva {
|
|
|
730
755
|
const agent = this.agent();
|
|
731
756
|
const client = this.client();
|
|
732
757
|
const {method, params} = packet.q.meta;
|
|
733
|
-
this.zone('ask', `${method}:${packet.id}`);
|
|
734
|
-
this.action('ask', `${method}:${packet.id}`);
|
|
758
|
+
this.zone('ask', `${method}:${packet.id.uid}`);
|
|
759
|
+
this.action('ask', `${method}:${packet.id.uid}`);
|
|
735
760
|
// build the answer packet from this model
|
|
736
|
-
this.state('try', `ask:${method}:${packet.id}`);
|
|
761
|
+
this.state('try', `ask:${method}:${packet.id.uid}`);
|
|
737
762
|
try {
|
|
738
763
|
if (typeof this.methods[method] !== 'function') {
|
|
739
764
|
return setImmediate(() => {
|
|
740
|
-
this.talk(`${this._agent.key}:ask:${packet.id}`, this._methodNotFound(packet));
|
|
765
|
+
this.talk(`${this._agent.key}:ask:${packet.id.uid}`, this._methodNotFound(packet));
|
|
741
766
|
});
|
|
742
767
|
}
|
|
743
768
|
|
|
744
|
-
this.state('set', `ask:${method}:packet_answer:${packet.id}`);
|
|
769
|
+
this.state('set', `ask:${method}:packet_answer:${packet.id.uid}`);
|
|
745
770
|
const packet_answer = {
|
|
746
771
|
id: this.lib.uid(),
|
|
747
772
|
agent,
|
|
@@ -774,16 +799,16 @@ class Deva {
|
|
|
774
799
|
|
|
775
800
|
packet.a = packet_answer;
|
|
776
801
|
this.talk(config.events.answer, this.lib.copy(packet)); // global talk event
|
|
777
|
-
this.talk(`${agent.key}:ask:${packet.id}`, packet);
|
|
802
|
+
this.talk(`${agent.key}:ask:${packet.id.uid}`, packet);
|
|
778
803
|
}).catch(err => {
|
|
779
|
-
this.talk(`${agent.key}:ask:${packet.id}`, {error:err});
|
|
780
|
-
this.state('catch', `ask:${method}:${packet.id}`);
|
|
804
|
+
this.talk(`${agent.key}:ask:${packet.id.uid}`, {error:err});
|
|
805
|
+
this.state('catch', `ask:${method}:${packet.id.uid}`);
|
|
781
806
|
return this.error(err, packet);
|
|
782
807
|
})
|
|
783
808
|
}
|
|
784
809
|
catch (e) {
|
|
785
|
-
this.state('catch', `ask:${method}:${packet.id}`);
|
|
786
|
-
this.talk(`${agent.key}:ask:${packet.id}`, {error:e});
|
|
810
|
+
this.state('catch', `ask:${method}:${packet.id.uid}`);
|
|
811
|
+
this.talk(`${agent.key}:ask:${packet.id.uid}`, {error:e});
|
|
787
812
|
return this.error(e, packet)
|
|
788
813
|
}
|
|
789
814
|
// now when we ask the meta params[0] should be the method
|
|
@@ -835,10 +860,14 @@ class Deva {
|
|
|
835
860
|
this.action('init');
|
|
836
861
|
this.state('init');
|
|
837
862
|
return this.Client(client, resolve, reject);
|
|
863
|
+
}).then(() => {
|
|
864
|
+
return this.Vector(resolve, reject);
|
|
838
865
|
}).then(() => {
|
|
839
866
|
return this.Veda(resolve, reject);
|
|
840
867
|
}).then(() => {
|
|
841
|
-
return this.
|
|
868
|
+
return this.God(resolve, reject);
|
|
869
|
+
}).then(() => {
|
|
870
|
+
return this.King(resolve, reject);
|
|
842
871
|
}).then(() => {
|
|
843
872
|
return this.Treasury(resolve, reject);
|
|
844
873
|
}).then(() => {
|
|
@@ -871,10 +900,10 @@ class Deva {
|
|
|
871
900
|
return this.Done(resolve, reject);
|
|
872
901
|
}).then(() => {
|
|
873
902
|
const hasOnInit = this.onInit && typeof this.onInit === 'function';
|
|
874
|
-
this.state('return', `init:${data.id}`);
|
|
903
|
+
this.state('return', `init:${data.id.uid}`);
|
|
875
904
|
return hasOnInit ? this.onInit(data, resolve) : this.start(data, resolve);
|
|
876
905
|
}).catch(err => {
|
|
877
|
-
this.state('catch', `init:${data.id}`);
|
|
906
|
+
this.state('catch', `init:${data.id.uid}`);
|
|
878
907
|
return this.error(err, client, reject);
|
|
879
908
|
});
|
|
880
909
|
});
|
|
@@ -891,10 +920,10 @@ class Deva {
|
|
|
891
920
|
usage: this.start('msg')
|
|
892
921
|
***************/
|
|
893
922
|
start(data, resolve) {
|
|
894
|
-
this.zone('start', data.id);
|
|
923
|
+
this.zone('start', data.id.uid);
|
|
895
924
|
if (!this._active) return resolve(this._messages.offline);
|
|
896
925
|
|
|
897
|
-
this.action('start', data.id);
|
|
926
|
+
this.action('start', data.id.uid);
|
|
898
927
|
const id = this.lib.uid();
|
|
899
928
|
|
|
900
929
|
delete data.md5;
|
|
@@ -909,26 +938,27 @@ class Deva {
|
|
|
909
938
|
|
|
910
939
|
const hasOnStart = this.onStart && typeof this.onStart === 'function' ? true : false;
|
|
911
940
|
|
|
912
|
-
this.state('start', data.id);
|
|
941
|
+
this.state('start', data.id.uid);
|
|
942
|
+
this.talk(config.events.start, data);
|
|
913
943
|
return hasOnStart ? this.onStart(data, resolve) : this.enter(data, resolve)
|
|
914
944
|
}
|
|
915
945
|
|
|
916
946
|
/**************
|
|
917
947
|
func: enter
|
|
918
948
|
params:
|
|
919
|
-
- msg:
|
|
949
|
+
- msg: the message from the caller incase need to use in calls
|
|
920
950
|
describe:
|
|
921
|
-
The
|
|
951
|
+
The enter function will check the active status of the Deva and set it to
|
|
922
952
|
offline or enter.
|
|
923
953
|
|
|
924
954
|
If the Deva is offline it will return the offline message.
|
|
925
955
|
usage: this.enter('msg')
|
|
926
956
|
***************/
|
|
927
957
|
enter(data, resolve) {
|
|
928
|
-
this.zone('enter', data.id);
|
|
958
|
+
this.zone('enter', data.id.uid);
|
|
929
959
|
if (!this._active) return resolve(this._messages.offline);
|
|
930
960
|
|
|
931
|
-
this.action('enter', data.id);
|
|
961
|
+
this.action('enter', data.id.uid);
|
|
932
962
|
const hasOnEnter = this.onEnter && typeof this.onEnter === 'function' ? true : false;
|
|
933
963
|
|
|
934
964
|
delete data.md5;
|
|
@@ -941,7 +971,8 @@ class Deva {
|
|
|
941
971
|
data.sha256 = this.lib.hash(data, 'sha256');
|
|
942
972
|
data.sha512 = this.lib.hash(data, 'sha512');
|
|
943
973
|
|
|
944
|
-
this.state('enter', data.id);
|
|
974
|
+
this.state('enter', data.id.uid);
|
|
975
|
+
this.talk(config.events.enter, data);
|
|
945
976
|
return hasOnEnter ? this.onEnter(data, resolve) : this.done(data, resolve)
|
|
946
977
|
}
|
|
947
978
|
|
|
@@ -957,10 +988,10 @@ class Deva {
|
|
|
957
988
|
usage: this.done('msg')
|
|
958
989
|
***************/
|
|
959
990
|
done(data, resolve) {
|
|
960
|
-
this.zone('done', data.id);
|
|
991
|
+
this.zone('done', data.id.uid);
|
|
961
992
|
if (!this._active) return resolve(this._messages.offline);
|
|
962
993
|
|
|
963
|
-
this.action('done', data.id);
|
|
994
|
+
this.action('done', data.id.uid);
|
|
964
995
|
const hasOnDone = this.onDone && typeof this.onDone === 'function' ? true : false;
|
|
965
996
|
|
|
966
997
|
delete data.md5;
|
|
@@ -973,7 +1004,8 @@ class Deva {
|
|
|
973
1004
|
data.sha256 = this.lib.hash(data, 'sha256');
|
|
974
1005
|
data.sha512 = this.lib.hash(data, 'sha512');
|
|
975
1006
|
|
|
976
|
-
this.state('done', data.id);
|
|
1007
|
+
this.state('done', data.id.uid);
|
|
1008
|
+
this.talk(config.events.done, data);
|
|
977
1009
|
return hasOnDone ? this.onDone(data, resolve) : this.ready(data, resolve);
|
|
978
1010
|
}
|
|
979
1011
|
|
|
@@ -986,10 +1018,10 @@ class Deva {
|
|
|
986
1018
|
usage: this.ready(data, resolve)
|
|
987
1019
|
***************/
|
|
988
1020
|
ready(data, resolve) {
|
|
989
|
-
this.zone('ready', data.id);
|
|
1021
|
+
this.zone('ready', data.id.uid);
|
|
990
1022
|
if (!this._active) return resolve(this._messages.offline);
|
|
991
1023
|
|
|
992
|
-
this.action('ready', data.id);
|
|
1024
|
+
this.action('ready', data.id.uid);
|
|
993
1025
|
const hasOnReady = this.onReady && typeof this.onReady === 'function';
|
|
994
1026
|
|
|
995
1027
|
delete data.md5;
|
|
@@ -1002,7 +1034,8 @@ class Deva {
|
|
|
1002
1034
|
data.sha256 = this.lib.hash(data, 'sha256');
|
|
1003
1035
|
data.sha512 = this.lib.hash(data, 'sha512');
|
|
1004
1036
|
|
|
1005
|
-
this.state('ready', data.id);
|
|
1037
|
+
this.state('ready', data.id.uid);
|
|
1038
|
+
this.talk(config.events.ready, data);
|
|
1006
1039
|
return hasOnReady ? this.onReady(data, resolve) : resolve(data);
|
|
1007
1040
|
}
|
|
1008
1041
|
|
|
@@ -1017,10 +1050,10 @@ class Deva {
|
|
|
1017
1050
|
usage: this.finish(data, resolve)
|
|
1018
1051
|
***************/
|
|
1019
1052
|
finish(data, resolve) {
|
|
1020
|
-
this.zone('finish', data.id); // enter finish zone
|
|
1053
|
+
this.zone('finish', data.id.uid); // enter finish zone
|
|
1021
1054
|
if (!this._active) return resolve(this._messages.offline); //
|
|
1022
1055
|
|
|
1023
|
-
this.action('finish', data.id); // start finish action
|
|
1056
|
+
this.action('finish', data.id.uid); // start finish action
|
|
1024
1057
|
const hasOnFinish = this.onFinish && typeof this.onFinish === 'function';
|
|
1025
1058
|
|
|
1026
1059
|
delete data.md5;
|
|
@@ -1033,7 +1066,8 @@ class Deva {
|
|
|
1033
1066
|
data.sha256 = this.lib.hash(data, 'sha256');
|
|
1034
1067
|
data.sha512 = this.lib.hash(data, 'sha512');
|
|
1035
1068
|
|
|
1036
|
-
this.state('finish', data.id); // set finish state
|
|
1069
|
+
this.state('finish', data.id.uid); // set finish state
|
|
1070
|
+
this.talk(config.events.finish, data);
|
|
1037
1071
|
return hasOnFinish ? this.onFinish(data, resolve) : this.complete(data, resolve);
|
|
1038
1072
|
}
|
|
1039
1073
|
|
|
@@ -1047,10 +1081,10 @@ class Deva {
|
|
|
1047
1081
|
usage: this.complete(data, resolve)
|
|
1048
1082
|
***************/
|
|
1049
1083
|
complete(data, resolve) {
|
|
1050
|
-
this.zone('complete', data.id);
|
|
1084
|
+
this.zone('complete', data.id.uid);
|
|
1051
1085
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
1052
1086
|
|
|
1053
|
-
this.action('complete', data.id);
|
|
1087
|
+
this.action('complete', data.id.uid);
|
|
1054
1088
|
const hasOnComplete = this.onComplete && typeof this.onComplete === 'function';
|
|
1055
1089
|
|
|
1056
1090
|
delete data.md5;
|
|
@@ -1062,7 +1096,8 @@ class Deva {
|
|
|
1062
1096
|
data.sha256 = this.lib.hash(data, 'sha256');
|
|
1063
1097
|
data.sha512 = this.lib.hash(data, 'sha512');
|
|
1064
1098
|
|
|
1065
|
-
this.state('complete', data.id);
|
|
1099
|
+
this.state('complete', data.id.uid);
|
|
1100
|
+
this.talk(config.events.complete, data);
|
|
1066
1101
|
return hasOnComplete ? this.onComplete(data, resolve) : resolve(data);
|
|
1067
1102
|
}
|
|
1068
1103
|
|
|
@@ -1103,6 +1138,7 @@ class Deva {
|
|
|
1103
1138
|
// has stop function then set hasOnStop variable
|
|
1104
1139
|
// if: has on stop then run on stop function or return exit function.
|
|
1105
1140
|
this.state('stop', id); // set the state to stop
|
|
1141
|
+
this.talk(config.events.stop, data);
|
|
1106
1142
|
return hasOnStop ? this.onStop(data) : this.exit()
|
|
1107
1143
|
}
|
|
1108
1144
|
|
|
@@ -1138,6 +1174,8 @@ class Deva {
|
|
|
1138
1174
|
data.sha512 = this.lib.hash(data, 'sha512');
|
|
1139
1175
|
|
|
1140
1176
|
this.state('exit', id); // set the state to stop
|
|
1177
|
+
this.talk(config.events.exit, data);
|
|
1178
|
+
|
|
1141
1179
|
// clear memory
|
|
1142
1180
|
this._active = false;
|
|
1143
1181
|
this._client = false;
|
|
@@ -1442,7 +1480,7 @@ class Deva {
|
|
|
1442
1480
|
this.talk(config.events.context, data);
|
|
1443
1481
|
return data;
|
|
1444
1482
|
} catch (e) {
|
|
1445
|
-
this.state('catch', `context:${value}:${id}`);
|
|
1483
|
+
this.state('catch', `context:${value}:${id.guid}`);
|
|
1446
1484
|
return this.error(e, value);
|
|
1447
1485
|
}
|
|
1448
1486
|
}
|
|
@@ -1515,6 +1553,26 @@ class Deva {
|
|
|
1515
1553
|
return this._getFeature('veda', this._vector);
|
|
1516
1554
|
}
|
|
1517
1555
|
|
|
1556
|
+
/**************
|
|
1557
|
+
func: god
|
|
1558
|
+
params: none
|
|
1559
|
+
describe: basic god features available in a Deva.
|
|
1560
|
+
usage: this.god()
|
|
1561
|
+
***************/
|
|
1562
|
+
god() {
|
|
1563
|
+
return this._getFeature('god', this._vector);
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
/**************
|
|
1567
|
+
func: king
|
|
1568
|
+
params: none
|
|
1569
|
+
describe: basic king features available in a Deva.
|
|
1570
|
+
usage: this.king()
|
|
1571
|
+
***************/
|
|
1572
|
+
king() {
|
|
1573
|
+
return this._getFeature('king', this._vector);
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1518
1576
|
/**************
|
|
1519
1577
|
func: vector
|
|
1520
1578
|
params: none
|
|
@@ -1753,7 +1811,7 @@ class Deva {
|
|
|
1753
1811
|
data.sha256 = this.lib.hash(data, 'sha256');
|
|
1754
1812
|
data.sha512 = this.lib.hash(data, 'sha512');
|
|
1755
1813
|
|
|
1756
|
-
this.state('return', `core:${id}`);
|
|
1814
|
+
this.state('return', `core:${id.uid}`);
|
|
1757
1815
|
return data;
|
|
1758
1816
|
}
|
|
1759
1817
|
|
|
@@ -1775,7 +1833,7 @@ class Deva {
|
|
|
1775
1833
|
data.sha256 = this.lib.hash(data, 'sha256');
|
|
1776
1834
|
data.sha512 = this.lib.hash(data, 'sha512');
|
|
1777
1835
|
|
|
1778
|
-
this.state('return', `info:${id}`);
|
|
1836
|
+
this.state('return', `info:${id.uid}`);
|
|
1779
1837
|
return data;
|
|
1780
1838
|
}
|
|
1781
1839
|
|
package/lib/index.js
CHANGED
|
@@ -15,6 +15,7 @@ class Node {
|
|
|
15
15
|
}
|
|
16
16
|
class LIB {
|
|
17
17
|
constructor(opts) {
|
|
18
|
+
this.config = opts.config || {};
|
|
18
19
|
this.lang = opts.lang || 'en';
|
|
19
20
|
this.locale = opts.locale || 'en-US';
|
|
20
21
|
this.currency = opts.currency || 'USD';
|
|
@@ -48,22 +49,39 @@ class LIB {
|
|
|
48
49
|
describe:
|
|
49
50
|
The uid function can create two types of id for you.
|
|
50
51
|
1. random GUID - this is good for when you need a uinique record id returned
|
|
51
|
-
2. transport
|
|
52
|
-
numerical number used for transporting records
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
2. transport uid - The transport id is a number generated to provide a
|
|
53
|
+
secure numerical number used for transporting records
|
|
54
|
+
across networks without collision or needing to store system uuid.
|
|
55
|
+
3. the uid is then returned with a created, md5, sha256, and sha512 hash of the value
|
|
56
|
+
copyright: 2025 Quinn A Michaels. All rights reserved.
|
|
55
57
|
***************/
|
|
56
|
-
uid(guid=false) {
|
|
57
|
-
|
|
58
|
+
uid(guid=false) {
|
|
59
|
+
const time = Date.now();
|
|
58
60
|
if (guid) {
|
|
59
|
-
|
|
61
|
+
const uid = randomUUID(); // set uid into local constant.
|
|
62
|
+
const created = Date.now(); // set created into local constant.
|
|
63
|
+
const data = {uid,created}; // set base data object.
|
|
64
|
+
data.md5 = this.hash(data, 'md5'); // md5 the uid and created.
|
|
65
|
+
data.sha256 = this.hash(data, 'sha256'); // sha256 the uid, created, md5
|
|
66
|
+
data.sha512 = this.hash(data, 'sha512'); // sha512 the uid, created, md5, sha256.
|
|
67
|
+
return data; // return the data.
|
|
60
68
|
}
|
|
61
69
|
else {
|
|
62
|
-
const min =
|
|
63
|
-
const max =
|
|
64
|
-
|
|
70
|
+
const min = Math.floor(time - (time / Math.PI)); // generate min time from Math.PI divisor.
|
|
71
|
+
const max = Math.ceil(time + (time * Math.PI)); // generate max time form Math.PI multiplier.
|
|
72
|
+
const begin_random = Math.floor(Math.random() * (max - min) + min); // generate random number between min and max.
|
|
73
|
+
const {end_min, end_max} = this.config.uid; // set end min and max in to constant
|
|
74
|
+
const end_random = Math.ceil(Math.random() * (end_max - end_min) + end_min); // generate the 5 digit end salt on the number for added randomness.
|
|
75
|
+
|
|
76
|
+
const uid = `${begin_random}${end_random}`; // set uid to local constant
|
|
77
|
+
const created = Date.now(); // set created to local constant
|
|
78
|
+
|
|
79
|
+
const data = {uid,created}; // set base data object.
|
|
80
|
+
data.md5 = this.hash(data, 'md5'); // md5 the uid and created.
|
|
81
|
+
data.sha256 = this.hash(data, 'sha256'); // sha256 the uid, created, md5
|
|
82
|
+
data.sha512 = this.hash(data, 'sha512'); // sha512 the uid, created, md5, sha256.
|
|
83
|
+
return data; // return the complete uid data.
|
|
65
84
|
}
|
|
66
|
-
return id;
|
|
67
85
|
}
|
|
68
86
|
|
|
69
87
|
/**************
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "9f0bc743-d720-4320-832e-cf5edc3b7cf",
|
|
3
3
|
"name": "@indra.ai/deva",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.55",
|
|
5
5
|
"description": "The Deva Core",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"copyright": "(c)2025 Quinn Michaels; All rights reserved.",
|
|
@@ -53,6 +53,10 @@
|
|
|
53
53
|
"config": {
|
|
54
54
|
"cmdChr": "/",
|
|
55
55
|
"askChr": "#",
|
|
56
|
+
"uid": {
|
|
57
|
+
"end_min": 1000000,
|
|
58
|
+
"end_max": 9999999
|
|
59
|
+
},
|
|
56
60
|
"inherit": [
|
|
57
61
|
"events",
|
|
58
62
|
"lib",
|
|
@@ -68,6 +72,14 @@
|
|
|
68
72
|
"events": {
|
|
69
73
|
"prompt": "devacore:prompt",
|
|
70
74
|
"error": "devacore:error",
|
|
75
|
+
"start": "devacore:start",
|
|
76
|
+
"enter": "devacore:enter",
|
|
77
|
+
"done": "devacore:done",
|
|
78
|
+
"ready": "devacore:ready",
|
|
79
|
+
"finish": "devacore:finish",
|
|
80
|
+
"complete": "devacore:complete",
|
|
81
|
+
"stop": "devacore:stop",
|
|
82
|
+
"exit": "devacore:exit",
|
|
71
83
|
"question": "devacore:question",
|
|
72
84
|
"answer": "devacore:answer",
|
|
73
85
|
"ask": "devacore:ask",
|
|
@@ -87,10 +99,10 @@
|
|
|
87
99
|
"ask": "π£ Ask",
|
|
88
100
|
"load": "π Load",
|
|
89
101
|
"unload": "π» Unload",
|
|
90
|
-
"init": "π
|
|
102
|
+
"init": "π Init",
|
|
91
103
|
"start": "π’ Start",
|
|
92
104
|
"enter": "πͺ Enter",
|
|
93
|
-
"done": "
|
|
105
|
+
"done": "βοΈ Done",
|
|
94
106
|
"ready": "βοΈ Ready",
|
|
95
107
|
"finish": "π Finish",
|
|
96
108
|
"complete": "β
Complete",
|
|
@@ -99,8 +111,10 @@
|
|
|
99
111
|
"deva": "β‘οΈ Deva",
|
|
100
112
|
"agent": "π€ Agent",
|
|
101
113
|
"client": "π¨ Client",
|
|
102
|
-
"veda": "ποΈ Veda",
|
|
103
114
|
"vector": "π€οΈ Vector",
|
|
115
|
+
"god": "π« God",
|
|
116
|
+
"veda": "ποΈ Veda",
|
|
117
|
+
"king": "ποΈ King",
|
|
104
118
|
"treasury": "π¦οΈ Treasury",
|
|
105
119
|
"security": "π¨ Security",
|
|
106
120
|
"guard": "π Guard",
|
|
@@ -138,10 +152,10 @@
|
|
|
138
152
|
"disconnect": "π΄ Disconnect",
|
|
139
153
|
"send": "π¬ Send",
|
|
140
154
|
"receive": "πͺ Receive",
|
|
141
|
-
"init": "π
|
|
155
|
+
"init": "π Init",
|
|
142
156
|
"start": "π’ Start",
|
|
143
157
|
"enter": "πͺ Enter",
|
|
144
|
-
"done": "
|
|
158
|
+
"done": "βοΈ Done",
|
|
145
159
|
"ready": "βοΈ Ready",
|
|
146
160
|
"finish": "π Finish",
|
|
147
161
|
"complete": "β
Complete",
|
|
@@ -175,7 +189,7 @@
|
|
|
175
189
|
"help": "π Help",
|
|
176
190
|
"authorized": "π Authorized",
|
|
177
191
|
"unauthorized": "π΄ββ οΈ Unauthorized",
|
|
178
|
-
"Done": "βοΈ
|
|
192
|
+
"Done": "βοΈ Done",
|
|
179
193
|
"glitch": "π‘ Glitch",
|
|
180
194
|
"intruder": "π¦ΉββοΈ Intruder",
|
|
181
195
|
"snooper": "π Snooper",
|
|
@@ -200,8 +214,10 @@
|
|
|
200
214
|
"actions": {
|
|
201
215
|
"client": "π¨ Client",
|
|
202
216
|
"agent": "π΅οΈββοΈ Agent",
|
|
203
|
-
"veda": "ποΈ Veda",
|
|
204
217
|
"vector": "π½ Vector",
|
|
218
|
+
"god": "π« God",
|
|
219
|
+
"veda": "ποΈ Veda",
|
|
220
|
+
"king": "ποΈ King",
|
|
205
221
|
"security": "π¨ Security",
|
|
206
222
|
"guard": "π Guard",
|
|
207
223
|
"shield": "π‘οΈ Shield",
|
|
@@ -223,7 +239,7 @@
|
|
|
223
239
|
"question": "π Question",
|
|
224
240
|
"answer": "π‘ Answer",
|
|
225
241
|
"ask": "π£ Ask",
|
|
226
|
-
"init": "π
|
|
242
|
+
"init": "π Init",
|
|
227
243
|
"start": "π’ Start",
|
|
228
244
|
"enter": "πͺ Enter",
|
|
229
245
|
"finish": "π Finish",
|
|
@@ -243,17 +259,19 @@
|
|
|
243
259
|
"status": "π₯ Status",
|
|
244
260
|
"error": "π£ Error",
|
|
245
261
|
"help": "π Help",
|
|
246
|
-
"done": "
|
|
262
|
+
"done": "βοΈ Done",
|
|
247
263
|
"ready": "βοΈ Ready",
|
|
248
264
|
"complete": "β
Complete"
|
|
249
265
|
},
|
|
250
266
|
"feature": false,
|
|
251
267
|
"features": {
|
|
252
|
-
"init": "π
|
|
268
|
+
"init": "π Init",
|
|
253
269
|
"agent": "π¦Ύ Agent",
|
|
254
270
|
"client": "πͺ Client",
|
|
255
|
-
"veda": "ποΈ Veda",
|
|
256
271
|
"vector": "π€οΈ Vector",
|
|
272
|
+
"god": "π« God",
|
|
273
|
+
"veda": "ποΈ Veda",
|
|
274
|
+
"king": "ποΈ King",
|
|
257
275
|
"treasury": "π¦ Treasury",
|
|
258
276
|
"security": "π¨ Security",
|
|
259
277
|
"guard": "π Guard",
|
|
@@ -274,7 +292,7 @@
|
|
|
274
292
|
"init": "π INIT",
|
|
275
293
|
"start": "π’ START",
|
|
276
294
|
"enter": "π΅ ENTER",
|
|
277
|
-
"done": "
|
|
295
|
+
"done": "βοΈ DONE",
|
|
278
296
|
"ready": "βοΈ READY",
|
|
279
297
|
"stop": "π΄ STOP",
|
|
280
298
|
"exit": "πͺ EXIT",
|
package/tests/agent.json
CHANGED
|
@@ -30,6 +30,12 @@
|
|
|
30
30
|
"gender": "M"
|
|
31
31
|
},
|
|
32
32
|
"features": {
|
|
33
|
+
"vector": {
|
|
34
|
+
"label": "π€οΈVECTOR",
|
|
35
|
+
"name": "@VECTOR",
|
|
36
|
+
"tag": "#VECTOR",
|
|
37
|
+
"loc": "$VECTOR"
|
|
38
|
+
},
|
|
33
39
|
"security": {
|
|
34
40
|
"label": "π¨SECURITY",
|
|
35
41
|
"name": "@SECURITY",
|
|
@@ -88,11 +94,16 @@
|
|
|
88
94
|
"vars": {
|
|
89
95
|
"hello": "Hellow World",
|
|
90
96
|
"context": {
|
|
91
|
-
"
|
|
97
|
+
"start": "ποΈ Start",
|
|
98
|
+
"enter": "πͺοΈ Enter",
|
|
99
|
+
"done": "β
Done",
|
|
100
|
+
"ready": "π Ready",
|
|
101
|
+
"finish": "π Finish",
|
|
102
|
+
"complete": "π€ Complete",
|
|
92
103
|
"test": "πΏ Test Data",
|
|
93
104
|
"prompt": "π» Prompt",
|
|
94
|
-
"feature": "πΏ
|
|
95
|
-
"zone": "π»
|
|
105
|
+
"feature": "πΏ Feature",
|
|
106
|
+
"zone": "π» Zone"
|
|
96
107
|
}
|
|
97
108
|
}
|
|
98
109
|
}
|
package/tests/client.json
CHANGED
|
@@ -34,12 +34,22 @@
|
|
|
34
34
|
"currency": "USD"
|
|
35
35
|
},
|
|
36
36
|
"features": {
|
|
37
|
+
"vector": {
|
|
38
|
+
"concerns": [],
|
|
39
|
+
"global": [],
|
|
40
|
+
"devas": {}
|
|
41
|
+
},
|
|
37
42
|
"veda": {
|
|
38
43
|
"concerns": [],
|
|
39
44
|
"global": [],
|
|
40
45
|
"devas": {}
|
|
41
46
|
},
|
|
42
|
-
"
|
|
47
|
+
"god": {
|
|
48
|
+
"concerns": [],
|
|
49
|
+
"global": [],
|
|
50
|
+
"devas": {}
|
|
51
|
+
},
|
|
52
|
+
"king": {
|
|
43
53
|
"concerns": [],
|
|
44
54
|
"global": [],
|
|
45
55
|
"devas": {}
|
package/tests/index.js
CHANGED
|
@@ -57,6 +57,24 @@ const DevaTest = new Deva({
|
|
|
57
57
|
'devacore:question'(packet) {
|
|
58
58
|
console.log(`πββοΈοΈ question: ${packet.text}`);
|
|
59
59
|
},
|
|
60
|
+
'devacore:start'(packet) {
|
|
61
|
+
console.log(`π’ start: ${packet.text}`);
|
|
62
|
+
},
|
|
63
|
+
'devacore:enter'(packet) {
|
|
64
|
+
console.log(`πͺ enter: ${packet.text}`);
|
|
65
|
+
},
|
|
66
|
+
'devacore:done'(packet) {
|
|
67
|
+
console.log(`βοΈ done: ${packet.text}`);
|
|
68
|
+
},
|
|
69
|
+
'devacore:ready'(packet) {
|
|
70
|
+
console.log(`βοΈ ready: ${packet.text}`);
|
|
71
|
+
},
|
|
72
|
+
'devacore:finish'(packet) {
|
|
73
|
+
console.log(`π finish: ${packet.text}`);
|
|
74
|
+
},
|
|
75
|
+
'devacore:complete'(packet) {
|
|
76
|
+
console.log(`β
complete: ${packet.text}`);
|
|
77
|
+
},
|
|
60
78
|
'devacore:answer'(packet) {
|
|
61
79
|
console.log(`π¨βπ¬ answer: ${packet.text}`);
|
|
62
80
|
},
|
|
@@ -73,12 +91,11 @@ const DevaTest = new Deva({
|
|
|
73
91
|
console.log(`π₯ action: ${packet.text}`);
|
|
74
92
|
},
|
|
75
93
|
'devacore:feature'(packet) {
|
|
76
|
-
console.log(`---`);
|
|
77
94
|
this.context('feature');
|
|
78
95
|
console.log(`πΏ feature: ${packet.text}`);
|
|
79
96
|
},
|
|
80
97
|
'devacore:context'(packet) {
|
|
81
|
-
console.log(
|
|
98
|
+
console.log(`\nπΉ context: ${packet.text}`);
|
|
82
99
|
},
|
|
83
100
|
'devacore:error'(packet) {
|
|
84
101
|
console.log(`β error: ${packet.text}`);
|
|
@@ -89,21 +106,16 @@ const DevaTest = new Deva({
|
|
|
89
106
|
func: {
|
|
90
107
|
test(packet) {
|
|
91
108
|
const text = this._state
|
|
92
|
-
const id = this.lib.uid();
|
|
93
|
-
const uid = this.lib.uid(true);
|
|
94
109
|
const core = this.core();
|
|
95
110
|
const info = this.info();
|
|
96
|
-
const date = Date.now();
|
|
97
|
-
const hashstr = `${id}${uid}${date}`;
|
|
98
|
-
const proxy = this.proxy(hashstr);
|
|
99
111
|
const data = [
|
|
100
112
|
'π§ͺ TEST RESULTS',
|
|
101
|
-
`::BEGIN:CORE:${core.id}`,
|
|
113
|
+
`::BEGIN:CORE:${core.id.uid}`,
|
|
102
114
|
JSON.stringify(core,null,2),
|
|
103
|
-
`::END:CORE:${core.id}`,
|
|
104
|
-
`::BEGIN:INFO:${info.id}`,
|
|
115
|
+
`::END:CORE:${core.id.uid}`,
|
|
116
|
+
`::BEGIN:INFO:${info.id.uid}`,
|
|
105
117
|
JSON.stringify(info,null,2),
|
|
106
|
-
`::END:INFO:${info.id}`,
|
|
118
|
+
`::END:INFO:${info.id.uid}`,
|
|
107
119
|
];
|
|
108
120
|
return {
|
|
109
121
|
text: data.join('\n'),
|
|
@@ -117,9 +129,32 @@ const DevaTest = new Deva({
|
|
|
117
129
|
return this.func.test(packet);
|
|
118
130
|
}
|
|
119
131
|
},
|
|
132
|
+
onStart(data, resolve) {
|
|
133
|
+
this.context('start', data.id.uid);
|
|
134
|
+
return this.enter(data, resolve);
|
|
135
|
+
},
|
|
136
|
+
onEnter(data, resolve) {
|
|
137
|
+
this.context('enter', data.id.uid);
|
|
138
|
+
return this.done(data, resolve);
|
|
139
|
+
},
|
|
140
|
+
onDone(data, resolve) {
|
|
141
|
+
this.context('done', data.id.uid);
|
|
142
|
+
return this.ready(data, resolve);
|
|
143
|
+
},
|
|
120
144
|
onReady(data, resolve) {
|
|
121
|
-
this.context('ready');
|
|
122
|
-
this.
|
|
145
|
+
this.context('ready', data.id.uid);
|
|
146
|
+
const test = this.methods.test(data);
|
|
147
|
+
this.prompt(test.text);
|
|
148
|
+
setTimeout(() => {
|
|
149
|
+
return resolve(data);
|
|
150
|
+
}, 10000);
|
|
151
|
+
},
|
|
152
|
+
onFinish(data, resolve) {
|
|
153
|
+
this.context('finish', data.id.uid);
|
|
154
|
+
return this.complete(data, resolve);
|
|
155
|
+
},
|
|
156
|
+
onComplete(data, resolve) {
|
|
157
|
+
this.context('complete', data.id.uid);
|
|
123
158
|
return resolve(data);
|
|
124
159
|
},
|
|
125
160
|
onError(e) {
|