@indra.ai/deva 1.6.75 → 1.6.77

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 CHANGED
@@ -1,18 +1,19 @@
1
1
  "use strict";
2
2
  // ©2025 Quinn A Michaels; All rights reserved.
3
3
  // Legal Signature Required For Lawful Use.
4
- // Distributed under VLA:33010936613959090808 LICENSE.md
4
+ // Distributed under VLA:44435048570336088519 LICENSE.md
5
5
 
6
6
  import {EventEmitter} from 'node:events';
7
7
  import {randomUUID} from 'crypto';
8
8
  import lib from './lib/index.js';
9
+ import config from './config/index.js';
9
10
  import pkg from './package.json' with {type:'json'};
10
11
 
11
- const {name,version,repository,author,bugs,homepage,license,config,VLA} = pkg;
12
+ const {name,version,repository,author,bugs,homepage,funding,license,VLA,copyright} = pkg;
12
13
  class Deva {
13
14
  constructor(opts) {
14
15
  opts = opts || {}; // set opts to provided opts or an empty object.
15
- this._core = {name,version,repository,author,bugs,homepage,license,VLA};
16
+ this._core = {name,version,repository,author,bugs,homepage,funding,license,VLA,copyright};
16
17
  this._id = opts.id || randomUUID(); // the unique id assigned to the agent at load
17
18
  this._info = opts.info || false; // the deva information from the package file.
18
19
  this._config = opts.config || {}; // local Config Object
@@ -59,24 +60,28 @@ class Deva {
59
60
  this.cmdChr = config.cmdChr; // the trigger for local commands
60
61
  this.askChr = config.askChr; // the trigger for ask other DEva features
61
62
 
62
- this.inherit = config.inherit; // set inherit from config
63
- this.bind = config.bind; // set the bind from the config
63
+ this._inherit = config.inherit; // set inherit from config data.
64
+ this._bind = config.bind; // set the bind from the config data.
64
65
 
65
- this._state = config.state; // set the current state from config
66
- this._states = config.states; // set the states from config
66
+ this._uid = config.uid; // set the uid options
67
67
 
68
- this._zone = config.zone; // set the current zone from config
69
- this._zones = config.zones; // set the zones from config
68
+
69
+ this._events = config.events; // set the core system events
70
+ this._feature = config.feature; // set the feature from config data.
71
+ this._features = config.features; // set the features from config data.
70
72
 
71
- this._action = config.action; // set the action from config
72
- this._actions = config.actions; // set the actions from config
73
+ this._zone = config.zone; // set the current zone from config data.
74
+ this._zones = config.zones; // set the zones from config data.
75
+
76
+ this._action = config.action; // set the action from config data.
77
+ this._actions = config.actions; // set the actions from config data.
73
78
 
74
- this._feature = config.feature; // set the feature from config
75
- this._features = config.features; // set the features from config
79
+ this._state = config.state; // set the current state from config data.
80
+ this._states = config.states; // set the states from options
76
81
 
77
- this._context = opts.context || false; // set the local context
82
+ this._context = config.context || false; // set the local context
78
83
 
79
- this._messages = config.messages; // set the messages from config
84
+ this._messages = config.messages; // set the messages from config data.
80
85
  }
81
86
 
82
87
  /**************
@@ -90,7 +95,7 @@ class Deva {
90
95
  _assignBind() {
91
96
  return new Promise((resolve, reject) => {
92
97
  try {
93
- this.bind.forEach(bind => { // loop over the bind items func, method, listener...
98
+ this._bind.forEach(bind => { // loop over the bind items func, method, listener...
94
99
  if (this[bind]) for (let x in this[bind]) { // if the root has a bind func, method, listener
95
100
  if (typeof this[bind][x] === 'function') { // check to make sure object is a fucntion
96
101
  this[bind][x] = this[bind][x].bind(this); // bind the item from the bind object
@@ -155,7 +160,7 @@ class Deva {
155
160
  return new Promise((resolve, reject) => {
156
161
  try {
157
162
  for (let d in this.devas) {
158
- this.inherit.forEach(inherit => {
163
+ this._inherit.forEach(inherit => {
159
164
  this.devas[d][inherit] = this[inherit];
160
165
  });
161
166
  }
@@ -243,10 +248,11 @@ class Deva {
243
248
  this.Client = {data}
244
249
  ***************/
245
250
  Client(client, resolve, reject) {
246
- this.feature('client');
247
- this.zone('client');
248
- this.action('client');
251
+ this.feature('client', `client:${client.id}`);
252
+ this.zone('client', `client:${client.id}`);
253
+ this.action('client', `client:${client.id}`);
249
254
  // setup any custom methods for the features
255
+ this.state('set', `client:feature:methods:${client.id}`);
250
256
  try {
251
257
  for (const x in client.features) {
252
258
  const methods = client.features[x].methods || false;
@@ -258,11 +264,13 @@ class Deva {
258
264
  }
259
265
  }
260
266
  const _client = this.lib.copy(client); // copy the client parameter
261
- this.state('set', 'client');
267
+ this.state('data', `client:${client.id}`);
262
268
  this._client = _client; // set local _client to this scope
263
- this.state('resolve', 'client');
269
+
270
+ this.action('return', `client:${client.id}`);
264
271
  return resolve();
265
272
  } catch (e) {
273
+ this.action('investigate', `client:${client.id}`);
266
274
  return this.err(e, false, reject);
267
275
  }
268
276
  }
@@ -598,7 +606,7 @@ class Deva {
598
606
  to create seamless collaboration between Devas.
599
607
  ***************/
600
608
  talk(evt, packet=false) {
601
- this.action('talk', `${evt}`);
609
+ this.action('talk', evt)
602
610
  return this.events.emit(evt, packet);
603
611
  }
604
612
 
@@ -720,13 +728,13 @@ class Deva {
720
728
  packet.q.sha256 = this.lib.hash(packet.q, 'sha256');
721
729
  packet.q.sha512 = this.lib.hash(packet.q, 'sha512');
722
730
 
723
- this.talk(config.events.question, this.lib.copy(packet)); // global question event make sure to copy data.
731
+ this.talk(this._events.question, this.lib.copy(packet)); // global question event make sure to copy data.
724
732
 
725
733
  if (isAsk) { // isAsk check if the question isAsk and talk
726
734
  // if: isAsk wait for the once event which is key'd to the packet ID for specified responses
727
735
  this.talk(`${key}:ask`, packet);
728
736
  this.once(`${key}:ask:${packet.id.uid}`, answer => {
729
- this.talk(config.events.ask, this.lib.copy(answer));
737
+ this.talk(this._events.ask, this.lib.copy(answer));
730
738
  this.state('return', `${key}:ask:${packet.id.uid}`);
731
739
  return this.finish(answer, resolve); // if:isAsk resolve the answer from the call
732
740
  });
@@ -797,7 +805,7 @@ class Deva {
797
805
  packet_answer.sha512 = this.lib.hash(packet_answer, 'sha512');
798
806
 
799
807
  packet.a = packet_answer; // set the packet.a to the packet_answer
800
- this.talk(config.events.answer, this.lib.copy(packet)); // global talk event
808
+ this.talk(this._events.answer, this.lib.copy(packet)); // global talk event
801
809
 
802
810
  this.state('return', `answer:${method}:${id.uid}`); // set the state resolve answer
803
811
  return this.finish(packet, resolve); // resolve the packet to the caller.
@@ -886,7 +894,7 @@ class Deva {
886
894
  packet.sha256 = this.lib.hash(packet, 'sha256');
887
895
  packet.sha512 = this.lib.hash(packet, 'sha512');
888
896
 
889
- this.talk(config.events.answer, this.lib.copy(packet)); // global talk event
897
+ this.talk(this._events.answer, this.lib.copy(packet)); // global talk event
890
898
  this.talk(`${agent.key}:ask:${packet.id.uid}`, packet);
891
899
  }).catch(err => {
892
900
  this.talk(`${agent.key}:ask:${packet.id.uid}`, {error:err});
@@ -941,8 +949,8 @@ class Deva {
941
949
 
942
950
  const license_check = this.license_check(client.VLA, pkg.VLA);
943
951
  if (!license_check) {
944
- this.prompt(config.messages.client_license_invalid);
945
- return resolve(config.messages.client_license_invalid); // return if} license check fails
952
+ this.prompt(this._messages.client_license_invalid);
953
+ return resolve(this._messages.client_license_invalid); // return if} license check fails
946
954
  }
947
955
 
948
956
  this.events.setMaxListeners(this.maxListeners);
@@ -1048,7 +1056,7 @@ class Deva {
1048
1056
  const hasOnStart = this.onStart && typeof this.onStart === 'function' ? true : false;
1049
1057
 
1050
1058
  this.state('start', data.id.uid);
1051
- this.talk(config.events.start, data);
1059
+ this.talk(this._events.start, data);
1052
1060
  return hasOnStart ? this.onStart(data, resolve) : this.enter(data, resolve)
1053
1061
  }
1054
1062
 
@@ -1081,7 +1089,7 @@ class Deva {
1081
1089
  data.sha512 = this.lib.hash(data, 'sha512');
1082
1090
 
1083
1091
  this.state('enter', data.id.uid);
1084
- this.talk(config.events.enter, data);
1092
+ this.talk(this._events.enter, data);
1085
1093
  return hasOnEnter ? this.onEnter(data, resolve) : this.done(data, resolve)
1086
1094
  }
1087
1095
 
@@ -1114,7 +1122,7 @@ class Deva {
1114
1122
  data.sha512 = this.lib.hash(data, 'sha512');
1115
1123
 
1116
1124
  this.state('done', data.id.uid);
1117
- this.talk(config.events.done, data);
1125
+ this.talk(this._events.done, data);
1118
1126
  return hasOnDone ? this.onDone(data, resolve) : this.ready(data, resolve);
1119
1127
  }
1120
1128
 
@@ -1145,7 +1153,7 @@ class Deva {
1145
1153
  data.sha512 = this.lib.hash(data, 'sha512');
1146
1154
 
1147
1155
  this.state('ready', data.id.uid);
1148
- this.talk(config.events.ready, data);
1156
+ this.talk(this._events.ready, data);
1149
1157
  return hasOnReady ? this.onReady(data, resolve) : resolve(data);
1150
1158
  }
1151
1159
 
@@ -1175,7 +1183,7 @@ class Deva {
1175
1183
  data.sha512 = this.lib.hash(data, 'sha512');
1176
1184
 
1177
1185
  this.state('finish', data.id.uid); // set finish state
1178
- this.talk(config.events.finish, data);
1186
+ this.talk(this._events.finish, data);
1179
1187
  return hasOnFinish ? this.onFinish(data, resolve) : this.complete(data, resolve);
1180
1188
  }
1181
1189
 
@@ -1205,7 +1213,7 @@ class Deva {
1205
1213
  data.sha512 = this.lib.hash(data, 'sha512');
1206
1214
 
1207
1215
  this.state('complete', data.id.uid);
1208
- this.talk(config.events.complete, data);
1216
+ this.talk(this._events.complete, data);
1209
1217
  return hasOnComplete ? this.onComplete(data, resolve) : resolve(data);
1210
1218
  }
1211
1219
 
@@ -1246,7 +1254,7 @@ class Deva {
1246
1254
  // has stop function then set hasOnStop variable
1247
1255
  // if: has on stop then run on stop function or return exit function.
1248
1256
  this.state('stop', id); // set the state to stop
1249
- this.talk(config.events.stop, data);
1257
+ this.talk(this._events.stop, data);
1250
1258
  return hasOnStop ? this.onStop(data) : this.exit()
1251
1259
  }
1252
1260
 
@@ -1282,7 +1290,7 @@ class Deva {
1282
1290
  data.sha512 = this.lib.hash(data, 'sha512');
1283
1291
 
1284
1292
  this.state('exit', id); // set the state to stop
1285
- this.talk(config.events.exit, data);
1293
+ this.talk(this._events.exit, data);
1286
1294
 
1287
1295
  // clear memory
1288
1296
  this._active = false;
@@ -1335,7 +1343,7 @@ class Deva {
1335
1343
  data.sha256 = this.lib.hash(data, 'sha256');
1336
1344
  data.sha512 = this.lib.hash(data, 'sha512');
1337
1345
 
1338
- this.talk(config.events.state, data); // broadcasat the state event
1346
+ this.talk(this._events.state, data); // broadcasat the state event
1339
1347
  return data;
1340
1348
  } catch (e) { // catch any errors
1341
1349
  return this.err(e); // return if an error happens
@@ -1394,7 +1402,7 @@ class Deva {
1394
1402
  data.sha256 = this.lib.hash(data, 'sha256');
1395
1403
  data.sha512 = this.lib.hash(data, 'sha512');
1396
1404
 
1397
- this.talk(config.events.zone, data);
1405
+ this.talk(this._events.zone, data);
1398
1406
  return data;
1399
1407
  } catch (e) {
1400
1408
  this.state('catch', `zone:${value}:${id.uid}`);
@@ -1461,7 +1469,7 @@ class Deva {
1461
1469
  data.sha256 = this.lib.hash(data, 'sha256');
1462
1470
  data.sha512 = this.lib.hash(data, 'sha512');
1463
1471
 
1464
- this.talk(config.events.action, data); // talk the core action event
1472
+ this.talk(this._events.action, data); // talk the core action event
1465
1473
  return data;
1466
1474
  } catch (e) { // catch any errors that occur
1467
1475
  this.state('catch', `action:${value}:${id.uid}`);
@@ -1522,7 +1530,7 @@ class Deva {
1522
1530
  data.sha256 = this.lib.hash(data, 'sha256');
1523
1531
  data.sha512 = this.lib.hash(data, 'sha512');
1524
1532
 
1525
- this.talk(config.events.feature, data); // talk the feature event with data
1533
+ this.talk(this._events.feature, data); // talk the feature event with data
1526
1534
  return data;
1527
1535
  } catch (e) { // catch any errors
1528
1536
  this.state('catch', `feature:${value}:${id.uid}`);
@@ -1586,7 +1594,7 @@ class Deva {
1586
1594
  data.sha256 = this.lib.hash(data, 'sha256');
1587
1595
  data.sha512 = this.lib.hash(data, 'sha512');
1588
1596
 
1589
- this.talk(config.events.context, data);
1597
+ this.talk(this._events.context, data);
1590
1598
  return data;
1591
1599
  } catch (e) {
1592
1600
  this.state('catch', `context:${value}:${id.uid}`);
@@ -1917,7 +1925,7 @@ class Deva {
1917
1925
  this.action('unload', key);
1918
1926
  this.devas[key].stop().then(exit => {
1919
1927
  delete this.devas[key];
1920
- this.talk(config.events.unload, key);
1928
+ this.talk(this._events.unload, key);
1921
1929
  });
1922
1930
  this.state('unload', key);
1923
1931
  return resolve(`${this._states.unload}:${key}`);
@@ -1958,13 +1966,15 @@ class Deva {
1958
1966
 
1959
1967
  this.state('hash', `${key}:${value}:md5:${id.uid}`)
1960
1968
  data.md5 = this.lib.hash(data); // md5 the data packet
1969
+
1961
1970
  this.state('hash', `${key}:${value}:sha256:${id.uid}`)
1962
1971
  data.sha256 = this.lib.hash(data, 'sha256'); // sha256 the data packet
1972
+
1963
1973
  this.state('hash', `${key}:${value}:sha512:${id.uid}`)
1964
1974
  data.sha512 = this.lib.hash(data, 'sha512'); // sha512 the data packet
1965
1975
 
1966
1976
  this.action('talk', `${key}:${value}:${id.uid}`);
1967
- this.talk(config.events.prompt, data);
1977
+ this.talk(this._events.prompt, data);
1968
1978
 
1969
1979
  this.action('return', `${key}:${value}:${id.uid}`);
1970
1980
  return data;
@@ -2139,7 +2149,7 @@ class Deva {
2139
2149
  data.sha256 = this.lib.hash(data, 'sha256');
2140
2150
  data.sha512 = this.lib.hash(data, 'sha512');
2141
2151
 
2142
- this.talk(config.events.error, this.lib.copy(data));
2152
+ this.talk(this._events.error, this.lib.copy(data));
2143
2153
 
2144
2154
  this.state('return', `error:${id.uid}`);
2145
2155
  this.state('error', id.uid);
@@ -2178,7 +2188,7 @@ class Deva {
2178
2188
  agent: agent_hash,
2179
2189
  pkg: pkg_hash,
2180
2190
  machine: machine_hash,
2181
- warning: config.messages.uid_warning,
2191
+ warning: this._messages.uid_warning,
2182
2192
  copyright: pkg.copyright,
2183
2193
  }
2184
2194
  if (guid) {
@@ -2189,7 +2199,7 @@ class Deva {
2189
2199
  const min = Math.floor(time - (time / Math.PI)); // generate min time from Math.PI divisor.
2190
2200
  const max = Math.ceil(time + (time * Math.PI)); // generate max time form Math.PI multiplier.
2191
2201
  const begin_random = Math.floor(Math.random() * (max - min) + min); // generate random number between min and max.
2192
- const {end_min, end_max} = config.uid; // set end min and max in to constant
2202
+ const {end_min, end_max} = this._uid; // set end min and max in to constant
2193
2203
  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.
2194
2204
 
2195
2205
  const uid = `${begin_random}${end_random}`; // set uid to local constant
@@ -2213,7 +2223,7 @@ class Deva {
2213
2223
  const opts = this.lib.copy(params); // copy the params and set as opts.
2214
2224
  const command = opts.shift();
2215
2225
 
2216
- const {invalid_agent,invalid_client} = config.messages;
2226
+ const {invalid_agent,invalid_client} = this._messages;
2217
2227
 
2218
2228
  const agent_hash = agent.sha256 === packet.q.agent.sha256 ? agent.sha256 : invalid_agent;
2219
2229
  const client_hash = client.sha256 === packet.q.client.sha256 ? client.sha256 : invalid_client;
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // ©2025 Quinn A Michaels; All rights reserved.
3
3
  // Legal Signature Required For Lawful Use.
4
- // Distributed under VLA:33010936613959090808 LICENSE.md
4
+ // Distributed under VLA:44435048570336088519 LICENSE.md
5
5
 
6
6
  import path from 'path';
7
7
  import fs from 'fs';