@indra.ai/deva 1.5.6 → 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 +48 -53
- package/package.json +2 -27
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
|
}
|
|
@@ -462,11 +463,11 @@ class Deva {
|
|
|
462
463
|
describe:
|
|
463
464
|
***************/
|
|
464
465
|
question(TEXT=false, DATA=false) {
|
|
466
|
+
const id = this.lib.uid(); // generate a unique id for transport.
|
|
465
467
|
// check the active status
|
|
466
468
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
467
|
-
this.zone('question');
|
|
468
|
-
this.action('question');
|
|
469
|
-
const id = this.lib.uid(); // generate a unique id for transport.
|
|
469
|
+
this.zone('question', id);
|
|
470
|
+
this.action('question', id);
|
|
470
471
|
const t_split = TEXT.split(' '); // split the text on spaces to get words.
|
|
471
472
|
const data = DATA; // set the DATA to data
|
|
472
473
|
|
|
@@ -492,7 +493,7 @@ class Deva {
|
|
|
492
493
|
return new Promise((resolve, reject) => {
|
|
493
494
|
// resolve with the no text message if the client says nothing.
|
|
494
495
|
if (!TEXT) return resolve(this._messages.notext, resolve);
|
|
495
|
-
this.state('try',
|
|
496
|
+
this.state('try', `question:${id}`);
|
|
496
497
|
try { // try to answer the question
|
|
497
498
|
if (isAsk) { // determine if hte question isAsk
|
|
498
499
|
// if:isAsk split the agent key and remove first command character
|
|
@@ -501,17 +502,17 @@ class Deva {
|
|
|
501
502
|
params = t_split[1] ? t_split[1].split(':') : false;
|
|
502
503
|
method = params[0]; // the method to check is then params index 0
|
|
503
504
|
text = t_split.slice(2).join(' ').trim(); // rejoin the text with space
|
|
504
|
-
this.state('ask', `${key}
|
|
505
|
+
this.state('ask', `${key}:${method}:${id}`);
|
|
505
506
|
}
|
|
506
507
|
else if (isCmd) { // determine if the question is a command
|
|
507
508
|
//if:isCmd use text split index 1 as the parameter block
|
|
508
509
|
params = t_split[0] ? t_split[0].split(':').slice(1) : false;
|
|
509
510
|
method = t_split[0].substring(1); // if:isCmd use the 0 index as the command
|
|
510
511
|
text = t_split.slice(1).join(' ').trim(); // if:isCmd rejoin the string on the space after removing first index
|
|
511
|
-
this.state('cmd', method); // set the state to cmd.
|
|
512
|
+
this.state('cmd', `${method}:${id}`); // set the state to cmd.
|
|
512
513
|
}
|
|
513
514
|
|
|
514
|
-
this.state('set', `question:${method}`)
|
|
515
|
+
this.state('set', `question:${method}:${id}`)
|
|
515
516
|
packet.q = { // build packet.q container
|
|
516
517
|
id: this.lib.uid(), // set the transport id for the question.
|
|
517
518
|
agent: this.agent(), // set the agent
|
|
@@ -536,12 +537,12 @@ class Deva {
|
|
|
536
537
|
this.talk(`${key}:ask`, packet);
|
|
537
538
|
this.once(`${key}:ask:${packet.id}`, answer => {
|
|
538
539
|
this.talk(config.events.ask, this.lib.copy(answer));
|
|
539
|
-
this.state('
|
|
540
|
+
this.state('return', `${key}:ask:${id}`);
|
|
540
541
|
return this.finish(answer, resolve); // if:isAsk resolve the answer from the call
|
|
541
542
|
});
|
|
542
543
|
}
|
|
543
544
|
else { // else: answer the question locally
|
|
544
|
-
this.state('answer', method); //set the answer state to the method
|
|
545
|
+
this.state('answer', `${method}:${id}`); //set the answer state to the method
|
|
545
546
|
return this.answer(packet, resolve, reject);
|
|
546
547
|
}
|
|
547
548
|
}
|
|
@@ -845,16 +846,14 @@ class Deva {
|
|
|
845
846
|
***************/
|
|
846
847
|
ready(packet, resolve) {
|
|
847
848
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
848
|
-
this.action('ready'); // set the complete action
|
|
849
|
+
this.action('ready', packet.id); // set the complete action
|
|
849
850
|
|
|
850
851
|
packet.hash = this.lib.hash(packet);// hash the entire packet before completeing.
|
|
851
852
|
// check for agent on complete function in agent
|
|
852
853
|
const hasOnReady = this.onReady && typeof this.onReady === 'function';
|
|
853
854
|
|
|
854
|
-
// if: agent has on complete then return on complete
|
|
855
|
-
this.state('ready'); // set the finish state
|
|
856
|
-
|
|
857
855
|
// return the provided resolve function or a promise resolve.
|
|
856
|
+
this.state('ready', packet.id); // set the finish state
|
|
858
857
|
return hasOnReady ? this.onReady(packet, resolve) : resolve(packet);
|
|
859
858
|
}
|
|
860
859
|
|
|
@@ -870,15 +869,11 @@ class Deva {
|
|
|
870
869
|
***************/
|
|
871
870
|
finish(packet, resolve) {
|
|
872
871
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
873
|
-
this.action('finish'); // set the finish action
|
|
874
|
-
packet.hash = this.lib.hash(packet);// hash the entire packet before finishing.
|
|
872
|
+
this.action('finish', packet.id); // set the finish action
|
|
875
873
|
// check for agent on finish function in agent
|
|
876
874
|
const hasOnFinish = this.onFinish && typeof this.onFinish === 'function';
|
|
877
|
-
|
|
878
|
-
// if: agent has on finish then return on finish
|
|
879
|
-
this.state('finish'); // set the finish state
|
|
880
|
-
|
|
881
875
|
// return the provided resolve function or a promise resolve.
|
|
876
|
+
this.state('finish', id); // set the finish state
|
|
882
877
|
return hasOnFinish ? this.onFinish(packet, resolve) : this.complete(packet, resolve);
|
|
883
878
|
}
|
|
884
879
|
|
|
@@ -893,15 +888,15 @@ class Deva {
|
|
|
893
888
|
***************/
|
|
894
889
|
complete(packet, resolve) {
|
|
895
890
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
896
|
-
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.
|
|
897
895
|
|
|
898
|
-
packet.hash = this.lib.hash(packet);// hash the entire packet before completeing.
|
|
899
896
|
// check for agent on complete function in agent
|
|
900
897
|
const hasOnComplete = this.onComplete && typeof this.onComplete === 'function';
|
|
901
|
-
|
|
902
|
-
// if: agent has on complete then return on complete
|
|
903
|
-
this.state('complete'); // set the finish state
|
|
904
898
|
// return the provided resolve function or a promise resolve.
|
|
899
|
+
this.state('complete', packet.id); // set the finish state
|
|
905
900
|
return hasOnComplete ? this.onComplete(packet, resolve) : resolve(packet);
|
|
906
901
|
}
|
|
907
902
|
|
|
@@ -919,21 +914,23 @@ class Deva {
|
|
|
919
914
|
this.stop()
|
|
920
915
|
***************/
|
|
921
916
|
stop() {
|
|
922
|
-
this.
|
|
917
|
+
const id = this.lib.uid();
|
|
923
918
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
924
|
-
this.
|
|
919
|
+
this.zone('stop', id); // set the zone to stop
|
|
920
|
+
this.action('stop', id); // set the stop action
|
|
921
|
+
|
|
925
922
|
const data = { // build the stop data
|
|
926
|
-
id
|
|
927
|
-
agent: this.agent(), // set the agent
|
|
928
|
-
client: this.client(), // set the client
|
|
923
|
+
id, // set the id
|
|
929
924
|
key: 'stop', // set the key
|
|
930
925
|
value: this._messages.stop, // set the value
|
|
926
|
+
agent: this.agent(), // set the agent
|
|
927
|
+
client: this.client(), // set the client
|
|
931
928
|
created: Date.now(), // set the created date
|
|
932
929
|
}
|
|
933
|
-
this.action('stop'); // set the stop action
|
|
934
930
|
// has stop function then set hasOnStop variable
|
|
935
931
|
const hasOnStop = this.onStop && typeof this.onStop === 'function';
|
|
936
932
|
// if: has on stop then run on stop function or return exit function.
|
|
933
|
+
this.state('stop', id); // set the state to stop
|
|
937
934
|
return hasOnStop ? this.onStop(data) : this.exit()
|
|
938
935
|
}
|
|
939
936
|
|
|
@@ -949,18 +946,16 @@ class Deva {
|
|
|
949
946
|
function.
|
|
950
947
|
***************/
|
|
951
948
|
exit() {
|
|
952
|
-
this.
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
const client = this.client();
|
|
949
|
+
const id = this.lib.uid();
|
|
950
|
+
this.zone('exit', id);
|
|
951
|
+
this.action('exit', id);
|
|
956
952
|
|
|
957
|
-
this.action('exit');
|
|
958
953
|
const data = {
|
|
959
|
-
id
|
|
954
|
+
id,
|
|
960
955
|
key: 'exit',
|
|
961
956
|
value: this._messages.exit,
|
|
962
|
-
agent,
|
|
963
|
-
client,
|
|
957
|
+
agent: this.agent(),
|
|
958
|
+
client: this.client(),
|
|
964
959
|
created: Date.now(),
|
|
965
960
|
}
|
|
966
961
|
data.hash = this.lib.hash(data);
|
|
@@ -977,7 +972,7 @@ class Deva {
|
|
|
977
972
|
this._authority = false;
|
|
978
973
|
this._justice = false;
|
|
979
974
|
|
|
980
|
-
this.state('exit');
|
|
975
|
+
this.state('exit', id);
|
|
981
976
|
const hasOnExit = this.onExit && typeof this.onExit === 'function';
|
|
982
977
|
return hasOnExit ? this.onExit(data) : Promise.resolve(data)
|
|
983
978
|
}
|
|
@@ -1524,11 +1519,11 @@ class Deva {
|
|
|
1524
1519
|
help(msg, help_dir) {
|
|
1525
1520
|
return new Promise((resolve, reject) => {
|
|
1526
1521
|
const id = this.lib.uid();
|
|
1527
|
-
this.context('help',
|
|
1528
|
-
this.zone('help',
|
|
1529
|
-
this.feature('help',
|
|
1530
|
-
this.action('help',
|
|
1531
|
-
this.state('help',
|
|
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);
|
|
1532
1527
|
if (!this._active) return resolve(this._messages.offline);
|
|
1533
1528
|
const params = msg.split(' '); // split the msg into an array by spaces.
|
|
1534
1529
|
let helpFile = 'main'; // set default help file
|
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.",
|
|
@@ -231,32 +231,7 @@
|
|
|
231
231
|
"info": "💁♂️ Info",
|
|
232
232
|
"status": "🚥 Status",
|
|
233
233
|
"error": "🔴 ERROR!",
|
|
234
|
-
"
|
|
235
|
-
"issue": "🎫 Issue",
|
|
236
|
-
"find": "🔎 Find",
|
|
237
|
-
"parse": "🏘️ Parse",
|
|
238
|
-
"list": "📋 List",
|
|
239
|
-
"reply": "📮 Reply",
|
|
240
|
-
"set": "🍽️ Set",
|
|
241
|
-
"get": "🤔 Get",
|
|
242
|
-
"send": "🚀 Send",
|
|
243
|
-
"receive": "🥅 Receive",
|
|
244
|
-
"return": "🎁 Return",
|
|
245
|
-
"resolve": "⛵️ Resolve",
|
|
246
|
-
"reject": "❌ Reject",
|
|
247
|
-
"write": "🖋️ Write",
|
|
248
|
-
"invalid": "❌ Invalid",
|
|
249
|
-
"help": "💜 Help",
|
|
250
|
-
"lawful": "🚓 Lawful",
|
|
251
|
-
"unlawful": "👿 Unlawful",
|
|
252
|
-
"audio": "👂 Audio",
|
|
253
|
-
"text": "📕 Text",
|
|
254
|
-
"image": "🌄 Image",
|
|
255
|
-
"video": "📽️ Video",
|
|
256
|
-
"signature": "✍️ Signature",
|
|
257
|
-
"orders": "🪖 Orders",
|
|
258
|
-
"law": "🔏 Law",
|
|
259
|
-
"decree": "📜 Decree"
|
|
234
|
+
"help": "💜 Help"
|
|
260
235
|
},
|
|
261
236
|
"feature": false,
|
|
262
237
|
"features": {
|