@indra.ai/deva 1.5.16 → 1.5.18

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.
Files changed (2) hide show
  1. package/index.js +38 -61
  2. package/package.json +3 -13
package/index.js CHANGED
@@ -179,6 +179,9 @@ class Deva {
179
179
  },
180
180
  created: Date.now(),
181
181
  };
182
+ delete packet.hash;
183
+ packet.hash = this.lib.hash(packet);
184
+ this.state('invalid', `${method}:${packet.id}`);
182
185
  return packet;
183
186
  }
184
187
 
@@ -386,13 +389,11 @@ class Deva {
386
389
  describe: The end of the workflow Client Feature Workflow
387
390
  ***************/
388
391
  Done(resolve, reject) {
389
- this.action('done');
390
392
  try {
391
- this.state('done');
392
393
  delete this._client.features; // delete the features key when done.
393
394
  return resolve(this.client()); // resolve an empty pr
394
395
  } catch (e) {
395
- this.state('catch', 'done');
396
+ this.state('catch', 'Done');
396
397
  return this.error(e, false, reject);
397
398
  }
398
399
  }
@@ -633,19 +634,16 @@ class Deva {
633
634
  ***************/
634
635
  ask(packet) {
635
636
  if (!this._active) return Promise.resolve(this._messages.offline);
636
- const {method, params} = packet.q.meta;
637
- this.zone('ask', `${method}:${packet.id}`);
638
-
639
637
  const agent = this.agent();
640
638
  const client = this.client();
639
+ const {method, params} = packet.q.meta;
640
+ this.zone('ask', `${method}:${packet.id}`);
641
+ this.action('ask', `${method}:${packet.id}`);
641
642
  // build the answer packet from this model
642
-
643
643
  this.state('try', `ask:${method}:${packet.id}`);
644
644
  try {
645
-
646
645
  if (typeof this.methods[method] !== 'function') {
647
646
  return setImmediate(() => {
648
- this.state('invalid', `${method}:${packet.id}`);
649
647
  this.talk(`${this._agent.key}:ask:${packet.id}`, this._methodNotFound(packet));
650
648
  });
651
649
  }
@@ -781,16 +779,16 @@ class Deva {
781
779
  function or running the enter function.
782
780
  usage: this.start('msg')
783
781
  ***************/
784
- start(data, resolve) {
782
+ start(packet, resolve) {
785
783
  this.zone('start');
786
784
  if (!this._active) return Promise.resolve(this._messages.offline);
787
785
  this.action('start');
788
- data.value = 'start';
789
- delete data.hash;
790
- data.hash = this.lib.hash(data);
786
+ packet.value = 'start';
787
+ delete packet.hash;
788
+ packet.hash = this.lib.hash(packet);
791
789
  const hasOnStart = this.onStart && typeof this.onStart === 'function' ? true : false;
792
790
  this.state('start');
793
- return hasOnStart ? this.onStart(data, resolve) : this.enter(data, resolve)
791
+ return hasOnStart ? this.onStart(packet, resolve) : this.enter(packet, resolve)
794
792
  }
795
793
 
796
794
  /**************
@@ -804,22 +802,22 @@ class Deva {
804
802
  If the Deva is offline it will return the offline message.
805
803
  usage: this.enter('msg')
806
804
  ***************/
807
- enter(data, resolve) {
805
+ enter(packet, resolve) {
808
806
  this.zone('deva');
809
807
  if (!this._active) return Promise.resolve(this._messages.offline);
810
808
  this.action('enter');
811
- data.value = 'enter';
812
- delete data.hash;
813
- data.hash = this.lib.hash(data);
809
+ packet.value = 'enter';
810
+ delete packet.hash;
811
+ packet.hash = this.lib.hash(packet);
814
812
  this.state('enter');
815
813
  const hasOnEnter = this.onEnter && typeof this.onEnter === 'function' ? true : false;
816
- return hasOnEnter ? this.onEnter(data, resolve) : this.done(data, resolve)
814
+ return hasOnEnter ? this.onEnter(packet, resolve) : this.done(packet, resolve)
817
815
  }
818
816
 
819
817
  /**************
820
818
  func: done
821
819
  params:
822
- - msg: hte message from the caller incase need to use in calls
820
+ - data: hte message from the caller incase need to use in calls
823
821
  describe:
824
822
  When the done function is triggered the system will also set the state
825
823
  of hte Deva to done.
@@ -827,33 +825,30 @@ class Deva {
827
825
  If the deva is offline it will return the offline message.
828
826
  usage: this.done('msg')
829
827
  ***************/
830
- done(data, resolve) {
828
+ done(packet, resolve) {
831
829
  if (!this._active) return Promise.resolve(this._messages.offline);
832
- this.action('done');
833
- data.value = 'done';
834
- delete data.hash;
835
- data.hash = this.lib.hash(data);
830
+ packet.value = 'done';
831
+ delete packet.hash;
832
+ packet.hash = this.lib.hash(packet);
836
833
  const hasOnDone = this.onDone && typeof this.onDone === 'function' ? true : false;
837
- this.state('done');
838
- return hasOnDone ? this.onDone(data, resolve) : this.ready(data, resolve);
834
+ this.state('done', packet.id);
835
+ return hasOnDone ? this.onDone(packet, resolve) : this.ready(packet, resolve);
839
836
  }
840
837
 
841
838
  /**************
842
839
  func: ready
843
840
  params:
844
- - packet: the data to pass to the resolve
841
+ - data: the data to pass to the resolve
845
842
  - resolve: the complete resolve to pass back
846
843
  describe: This function is use to relay the to the ready state.
847
844
  usage: this.ready(data, resolve)
848
845
  ***************/
849
846
  ready(packet, resolve) {
850
847
  if (!this._active) return Promise.resolve(this._messages.offline);
851
- this.action('ready', packet.id); // set the complete action
852
-
848
+ delete packet.hash;
853
849
  packet.hash = this.lib.hash(packet);// hash the entire packet before completeing.
854
850
  // check for agent on complete function in agent
855
- const hasOnReady = this.onReady && typeof this.onReady === 'function';
856
-
851
+ const hasOnReady = this.onReady && typeof this.onReady === 'function';
857
852
  // return the provided resolve function or a promise resolve.
858
853
  this.state('ready', packet.id); // set the finish state
859
854
  return hasOnReady ? this.onReady(packet, resolve) : resolve(packet);
@@ -864,14 +859,13 @@ class Deva {
864
859
  /**************
865
860
  func: finish
866
861
  params:
867
- - packet: the data to pass to the resolve
862
+ - data: the data to pass to the resolve
868
863
  - resolve: the finish resolve to pass back
869
864
  describe: This function is used to relay into the finish state when resolving a question or data.
870
865
  usage: this.finish(data, resolve)
871
866
  ***************/
872
867
  finish(packet, resolve) {
873
868
  if (!this._active) return Promise.resolve(this._messages.offline);
874
- this.action('finish', packet.id); // set the finish action
875
869
  // check for agent on finish function in agent
876
870
  const hasOnFinish = this.onFinish && typeof this.onFinish === 'function';
877
871
  // return the provided resolve function or a promise resolve.
@@ -882,7 +876,7 @@ class Deva {
882
876
  /**************
883
877
  func: complete
884
878
  params:
885
- - packet: the data to pass to the resolve
879
+ - data: the data to pass to the resolve
886
880
  - resolve: the complete resolve to pass back
887
881
  describe: This function is use to relay into a complete state when
888
882
  resolving a question or data.
@@ -890,7 +884,6 @@ class Deva {
890
884
  ***************/
891
885
  complete(packet, resolve) {
892
886
  if (!this._active) return Promise.resolve(this._messages.offline);
893
- this.action('complete', packet.id); // set the complete action
894
887
  packet.created = Date.now();// set the complete date on the whole packet.
895
888
  delete packet.hash;
896
889
  packet.hash = this.lib.hash(packet);// hash the entire packet before complete.
@@ -918,8 +911,6 @@ class Deva {
918
911
  stop() {
919
912
  const id = this.lib.uid();
920
913
  if (!this._active) return Promise.resolve(this._messages.offline);
921
- this.zone('stop', id); // set the zone to stop
922
- this.action('stop', id); // set the stop action
923
914
 
924
915
  const data = { // build the stop data
925
916
  id, // set the id
@@ -949,9 +940,6 @@ class Deva {
949
940
  ***************/
950
941
  exit() {
951
942
  const id = this.lib.uid();
952
- this.zone('exit', id);
953
- this.action('exit', id);
954
-
955
943
  const data = {
956
944
  id,
957
945
  key: 'exit',
@@ -1038,11 +1026,8 @@ class Deva {
1038
1026
  ***************/
1039
1027
  zone(value=false, extra=false) {
1040
1028
  const id = this.lib.uid();
1041
- this.action('zone', `zone:${value}:${id}`);
1042
-
1043
1029
  if (!value || !this._zones[value] || value === this._zone) return;
1044
1030
 
1045
- this.state('try', `zone:${value}:${id}`)
1046
1031
  try {
1047
1032
  this._zone = value;
1048
1033
  const lookup = this._zones[value]; // set the lookup value
@@ -1059,7 +1044,6 @@ class Deva {
1059
1044
  };
1060
1045
  data.hash = this.lib.hash(data);
1061
1046
  this.talk(config.events.zone, data);
1062
- this.state('return', `zone:${value}:${id}`);
1063
1047
  return data;
1064
1048
  } catch (e) {
1065
1049
  this.state('catch', `zone:${value}:${id}`);
@@ -1095,7 +1079,6 @@ class Deva {
1095
1079
  ***************/
1096
1080
  action(value=false, extra=false) {
1097
1081
  const id = this.lib.uid();
1098
- this.state('try', `action:${value}:${id}`);
1099
1082
  try {
1100
1083
  if (!value || !this._actions[value] || value === this._action) return;
1101
1084
  this._action = value; // set the local action variable
@@ -1116,7 +1099,6 @@ class Deva {
1116
1099
  };
1117
1100
  data.hash = this.lib.hash(data); // generate a hash of the action packet.
1118
1101
  this.talk(config.events.action, data); // talk the core action event
1119
- this.state('return', `action:${value}:${id}`);
1120
1102
  return data;
1121
1103
  } catch (e) { // catch any errors that occur
1122
1104
  this.state('catch', `action:${value}:${id}`);
@@ -1154,8 +1136,6 @@ class Deva {
1154
1136
  ***************/
1155
1137
  feature(value=false, extra=false) {
1156
1138
  const id = this.lib.uid();
1157
- this.action('feature', value);
1158
- this.state('try', `feature:${value}:${id}`);
1159
1139
  try {
1160
1140
  if (!value || !this._features[value]) return; // check feature value
1161
1141
 
@@ -1172,7 +1152,6 @@ class Deva {
1172
1152
  };
1173
1153
  data.hash = this.lib.hash(data); // generate the hash value of the data packet
1174
1154
  this.talk(config.events.feature, data); // talk the feature event with data
1175
- this.state('return', `feature:${value}:${id}`);
1176
1155
  return data;
1177
1156
  } catch (e) { // catch any errors
1178
1157
  this.state('catch', `feature:${value}:${id}`);
@@ -1210,11 +1189,8 @@ class Deva {
1210
1189
  ***************/
1211
1190
  context(value=false, extra=false) {
1212
1191
  const id = this.lib.uid();
1213
- this.action('context', `${value}:${id}`);
1214
- this.state('try', `context:${value}:${id}`);
1215
1192
  try {
1216
1193
  if (!value) return;
1217
- this.state('set', `context:${value}:${id}`);
1218
1194
  this._context = value;
1219
1195
  const lookup = this.vars.context[value] || value;
1220
1196
  const text = extra ? `${lookup} ${extra}` : lookup;
@@ -1230,7 +1206,6 @@ class Deva {
1230
1206
  };
1231
1207
  data.hash = this.lib.hash(data);
1232
1208
  this.talk(config.events.context, data);
1233
- this.state('return', `context:${value}:${id}`);
1234
1209
  return data;
1235
1210
  } catch (e) {
1236
1211
  this.state('catch', `context:${value}:${id}`);
@@ -1239,16 +1214,20 @@ class Deva {
1239
1214
  }
1240
1215
 
1241
1216
  contexts() {
1217
+ const id = this.lib.uid();
1218
+ this.action('contexts', id);
1242
1219
  if (!this._active) return this._messages.offline; // check the active status
1243
- this.state('return', 'contexts');
1244
- return {
1245
- id: this.lib.uid(),
1220
+ const data = {
1221
+ id,
1246
1222
  agent: this.agent(),
1247
1223
  client: this.client(),
1248
1224
  key: 'contexts',
1249
1225
  value: this.vars.context || false,
1250
- created: Date.now(),
1251
- }
1226
+ created: Date.now(),
1227
+ };
1228
+ data.hash = this.lib.hash(data);
1229
+ this.state('return', `contexts:${id}`);
1230
+ return data;
1252
1231
  }
1253
1232
 
1254
1233
  /**************
@@ -1427,7 +1406,6 @@ class Deva {
1427
1406
  ***************/
1428
1407
  prompt(text) {
1429
1408
  const id = this.lib.uid();
1430
- this.action('prompt', id);
1431
1409
  if (!this._active) return Promise.resolve(this._messages.offline);
1432
1410
  // Talk a global prompt event for the client
1433
1411
  const agent = this.agent();
@@ -1443,7 +1421,6 @@ class Deva {
1443
1421
  }
1444
1422
  data.hash = this.lib.hash(data);
1445
1423
  this.talk(config.events.prompt, data);
1446
- this.state('return', `prompt:${id}`);
1447
1424
  return data;
1448
1425
  }
1449
1426
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.5.16",
3
+ "version": "1.5.18",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "copyright": "(c)2025 Quinn Michaels; All rights reserved.",
@@ -88,9 +88,7 @@
88
88
  "unload": "🛻 Unload",
89
89
  "init": "🚀 Init",
90
90
  "start": "🏎️ Start",
91
- "stop": "🛑 Stop",
92
91
  "enter": "🏡 Enter",
93
- "exit": "🚪 Exit",
94
92
  "finish": "🏁 Finish",
95
93
  "deva": "⚡️ Deva",
96
94
  "client": "👨 Client",
@@ -209,24 +207,16 @@
209
207
  "init": "🚀 Init",
210
208
  "start": "🎬 Start",
211
209
  "enter": "🏡 Enter",
212
- "done": "☑️ Done",
213
- "ready": "🟢 Ready",
214
210
  "finish": "🏁 Finish",
215
- "complete": "✅ Complete",
216
211
  "stop": "🛑 Stop",
217
- "exit": "🚪 Exit",
212
+ "method": "❤️‍🔥 Method",
213
+ "func": "🔦 Func",
218
214
  "actions": "🏎️ Actions",
219
- "feature": "🎥 Feature",
220
215
  "features": "🎥 Features",
221
- "context": "📇 Context",
222
216
  "contexts": "🌈 Contexts",
223
- "method": "❤️‍🔥 Method",
224
- "func": "🔦 Func",
225
- "zone": "🔭 Zone",
226
217
  "zones": "🪐 Zones",
227
218
  "load": "📦 Load",
228
219
  "unload": "🥡 Unload",
229
- "prompt": "🐚 Prompt",
230
220
  "states": "🍜 States",
231
221
  "core": "🍎 Core",
232
222
  "info": "💁‍♂️ Info",