@indra.ai/deva 1.6.96 → 1.6.97

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.
@@ -47,6 +47,7 @@
47
47
  "exit": "🚪 Exit",
48
48
  "method": "❤️‍🔥 Method",
49
49
  "func": "🔦 Func",
50
+ "onfunc": "🎚️ onFunction",
50
51
  "actions": "🏎️ Actions",
51
52
  "features": "🎥 Features",
52
53
  "contexts": "🌈 Contexts",
@@ -114,6 +114,7 @@
114
114
  "real": "😲 Real",
115
115
  "mature": "🧓 Mature",
116
116
  "immature": "🧒 Immature",
117
- "consent": "✍️ Consent"
117
+ "consent": "✍️ Consent",
118
+ "onfunc": "🎚️ onFunction"
118
119
  }
119
120
  }
package/index.js CHANGED
@@ -1055,7 +1055,10 @@ class Deva {
1055
1055
  return this.Done(resolve, reject);
1056
1056
  }).then(() => {
1057
1057
  const hasOnInit = this.onInit && typeof this.onInit === 'function';
1058
- if (hasOnInit) this.state('set', `hasOnInit:${data.id.uid}`); // state set to watch onInit
1058
+ if (hasOnInit) {
1059
+ this.action('onfunc', `hasOnInit:${data.id.uid}`); // state set to watch onInit
1060
+ this.state('onfunc', `hasOnInit:${data.id.uid}`); // state set to watch onInit
1061
+ }
1059
1062
  this.action('return', `init:${data.id.uid}`);
1060
1063
  return hasOnInit ? this.onInit(data, resolve) : this.start(data, resolve);
1061
1064
  }).catch(err => {
@@ -1104,7 +1107,10 @@ class Deva {
1104
1107
  this.talk(this._events.start, data);
1105
1108
 
1106
1109
  const hasOnStart = this.onStart && typeof this.onStart === 'function' ? true : false;
1107
- if (hasOnStart) this.state('set', `hasOnStart:${data.id.uid}`); // state set to watch OnFinish
1110
+ if (hasOnStart) {
1111
+ this.action('onfunc', `hasOnStart:${data.id.uid}`); // set action to onfunc
1112
+ this.state('onfunc', `hasOnStart:${data.id.uid}`); // set state to onfunc
1113
+ }
1108
1114
 
1109
1115
  this.action('return', `start:${data.id.uid}`); // return action finish
1110
1116
  return hasOnStart ? this.onStart(data, resolve) : this.enter(data, resolve)
@@ -1149,7 +1155,10 @@ class Deva {
1149
1155
  this.talk(this._events.enter, data);
1150
1156
 
1151
1157
  const hasOnEnter = this.onEnter && typeof this.onEnter === 'function' ? true : false;
1152
- if (hasOnEnter) this.state('set', `hasOnEnter:${data.id.uid}`); // state set to watch OnFinish
1158
+ if (hasOnEnter) {
1159
+ this.action('onfunc', `hasOnEnter:${data.id.uid}`); // action onfunc set
1160
+ this.state('onfunc', `hasOnEnter:${data.id.uid}`); // state onfunc set
1161
+ }
1153
1162
 
1154
1163
  this.action('return', `enter:${data.id.uid}`); // return action finish
1155
1164
  return hasOnEnter ? this.onEnter(data, resolve) : this.done(data, resolve)
@@ -1194,7 +1203,10 @@ class Deva {
1194
1203
  this.talk(this._events.done, data);
1195
1204
 
1196
1205
  const hasOnDone = this.onDone && typeof this.onDone === 'function' ? true : false;
1197
- if (hasOnDone) this.state('set', `hasOnDone:${data.id.uid}`); // state set to watch OnFinish
1206
+ if (hasOnDone) {
1207
+ this.action('onfunc', `hasOnDone:${data.id.uid}`); // state onfunc
1208
+ this.state('onfunc', `hasOnDone:${data.id.uid}`); // state onfunc
1209
+ }
1198
1210
 
1199
1211
  this.action('return', `done:${data.id.uid}`); // return action finish
1200
1212
  return hasOnDone ? this.onDone(data, resolve) : this.ready(data, resolve);
@@ -1237,7 +1249,10 @@ class Deva {
1237
1249
  this.talk(this._events.ready, data);
1238
1250
 
1239
1251
  const hasOnReady = this.onReady && typeof this.onReady === 'function';
1240
- if (hasOnReady) this.state('set', `hasOnReady:${data.id.uid}`); // state set to watch OnFinish
1252
+ if (hasOnReady) {
1253
+ this.action('onfunc', `hasOnReady:${data.id.uid}`); // action onfunc
1254
+ this.state('onfunc', `hasOnReady:${data.id.uid}`); // state onfunc
1255
+ }
1241
1256
 
1242
1257
  this.action('resolve', `ready:${data.id.uid}`); // return action ready
1243
1258
  return hasOnReady ? this.onReady(data, resolve) : resolve(data);
@@ -1280,7 +1295,10 @@ class Deva {
1280
1295
  this.talk(this._events.finish, data);
1281
1296
 
1282
1297
  const hasOnFinish = this.onFinish && typeof this.onFinish === 'function';
1283
- if (hasOnFinish) this.state('set', `hasOnFinish:${data.id.uid}`); // state set to watch OnFinish
1298
+ if (hasOnFinish) {
1299
+ this.action('onfunc', `hasOnFinish:${data.id.uid}`); // action onfunc
1300
+ this.state('onfunc', `hasOnFinish:${data.id.uid}`); // state onfunc
1301
+ }
1284
1302
 
1285
1303
  this.action('return', `finish:${data.id.uid}`); // return action finish
1286
1304
  return hasOnFinish ? this.onFinish(data, resolve) : this.complete(data, resolve);
@@ -1326,7 +1344,10 @@ class Deva {
1326
1344
 
1327
1345
  // determine if there is an onComplete function for the entity.
1328
1346
  const hasOnComplete = this.onComplete && typeof this.onComplete === 'function';
1329
- if (hasOnComplete) this.state('set', `hasOnComplete:${data.id.uid}`); // state set to watch OnFinish
1347
+ if (hasOnComplete) {
1348
+ this.action('onfunc', `hasOnComplete:${data.id.uid}`); // action onfunc
1349
+ this.state('onfunc', `hasOnComplete:${data.id.uid}`); // state onfunc
1350
+ }
1330
1351
 
1331
1352
  this.action('return', `complete:${data.id.uid}`); // return action complete
1332
1353
  return hasOnComplete ? this.onComplete(data, resolve) : resolve(data);
@@ -1383,7 +1404,10 @@ class Deva {
1383
1404
 
1384
1405
  // determine if there is an onComplete function for the entity.
1385
1406
  const hasOnStop = this.onStop && typeof this.onStop === 'function';
1386
- if (hasOnStop) this.state('set', `hasOnStop:${data.id.uid}`); // state set to watch OnFinish
1407
+ if (hasOnStop) {
1408
+ this.action('onfunc', `hasOnStop:${data.id.uid}`); // action onfunc
1409
+ this.state('onfunc', `hasOnStop:${data.id.uid}`); // state onfunc
1410
+ }
1387
1411
  return hasOnStop ? this.onStop(data) : this.exit(data)
1388
1412
  }
1389
1413
 
@@ -1451,7 +1475,10 @@ class Deva {
1451
1475
  this.talk(this._events.exit, data);
1452
1476
 
1453
1477
  const hasOnExit = this.onExit && typeof this.onExit === 'function';
1454
- if (hasOnExit) this.state('set', `hasOnExit:${data.id.uid}`); // state set to watch OnFinish
1478
+ if (hasOnExit) {
1479
+ this.action('onfunc', `hasOnExit:${data.id.uid}`); // action onfunc
1480
+ this.state('onfunc', `hasOnExit:${data.id.uid}`); // state onfunc
1481
+ }
1455
1482
 
1456
1483
  this.action('resolve', `exit:${data.uid}`);
1457
1484
  return hasOnExit ? this.onExit(data) : Promise.resolve(data)
@@ -2275,27 +2302,28 @@ class Deva {
2275
2302
  if (!this._active) return resolve(this._messages.offline);
2276
2303
  let helpDoc = false;
2277
2304
  const id = this.uid();
2278
- this.zone('help', id);
2305
+ const key = 'help';
2306
+ this.zone(key, id);
2279
2307
 
2280
- this.feature('help', id.uid);
2281
- this.action('help', id.uid);
2282
- this.state('help', id.uid);
2283
- this.context('help', id.uid);
2308
+ this.feature(key, id.uid);
2309
+ this.action(key, id.uid);
2310
+ this.state(key, id.uid);
2311
+ this.context(key, id.uid);
2284
2312
  const params = msg.split(' '); // split the msg into an array by spaces.
2285
2313
 
2286
2314
  const splitText = params[0].split(':');
2287
2315
  const part = splitText[1] ? splitText[1].toUpperCase() : 'MAIN';
2288
2316
  const helpFile = splitText[0] ? splitText[0] : 'main';
2289
2317
 
2290
- const helpPath = this.lib.path.join(help_dir, 'help', `${helpFile}.feecting`);
2318
+ const helpPath = this.lib.path.join(help_dir, key, `${helpFile}.feecting`);
2291
2319
 
2292
2320
  try {
2293
- this.state('try', `help:${id.uid}`);
2321
+ this.state('try', `${key}:${id.uid}`);
2294
2322
 
2295
2323
  // check if help file exists first and resolve if no file
2296
2324
  const helpExists = this.lib.fs.existsSync(helpPath); // check if help file exists
2297
2325
  if (!helpExists) {
2298
- this.state('return', `${this._messages.help_not_found}:${id.uid}`);
2326
+ this.action('resolve', `${key}:not:found:${id.uid}`);
2299
2327
  return resolve(this._messages.help_not_found);
2300
2328
  }
2301
2329
 
@@ -2303,7 +2331,7 @@ class Deva {
2303
2331
  const helpFile = this.lib.fs.readFileSync(helpPath, 'utf8');
2304
2332
  const helpPart = helpFile.split(`::BEGIN:${part}`);
2305
2333
  if (!helpPart[1]) {
2306
- this.state('return', `${this._messages.help_not_found}:${id.uid}`);
2334
+ this.action('resolve', `${this._messages.help_not_found}:${id.uid}`);
2307
2335
  resolve(this._messages.help_not_found);
2308
2336
  }
2309
2337
 
@@ -2311,11 +2339,11 @@ class Deva {
2311
2339
  helpDoc = helpFile.split(`::BEGIN:${part}`)[1].split(`::END:${part}`)[0];
2312
2340
  }
2313
2341
  catch(e) {
2314
- this.state('catch', `help:${id.uid}`);
2342
+ this.state('catch', `${key}:${id.uid}`);
2315
2343
  return this.err(e, msg, reject);
2316
2344
  }
2317
2345
  finally {
2318
- this.state('return', `help:${id.uid}`);
2346
+ this.action('resolve', `help:${id.uid}`);
2319
2347
  return resolve(helpDoc);
2320
2348
  }
2321
2349
  });
@@ -2333,18 +2361,20 @@ class Deva {
2333
2361
  ***************/
2334
2362
  err(err,packet,reject=false) {
2335
2363
  const id = this.uid();
2336
- this.zone('error', id.uid);
2337
- this.feature('error', id.uid);
2364
+ const key = 'error';
2365
+ this.context(key, id.uid);
2366
+ this.feature(key, id.uid);
2367
+ this.zone(key, id.uid);
2368
+ this.action(key, id.uid);
2369
+ this.state(key, id.uid);
2338
2370
 
2339
2371
  const agent = this.agent();
2340
2372
  const client = this.client();
2341
-
2342
- this.action('error', id.uid);
2343
- const hasOnError = this.onError && typeof this.onError === 'function' ? true : false;
2344
-
2373
+
2374
+ this.state('data', `${key}:${id.uid}`);
2345
2375
  const data = {
2346
2376
  id,
2347
- key: 'error',
2377
+ key,
2348
2378
  value: agent.key,
2349
2379
  agent,
2350
2380
  client,
@@ -2356,17 +2386,33 @@ class Deva {
2356
2386
  packet,
2357
2387
  created: Date.now(),
2358
2388
  }
2359
- data.md5 = this.hash(data, 'md5');
2360
- data.sha256 = this.hash(data, 'sha256');
2361
- data.sha512 = this.hash(data, 'sha512');
2389
+
2390
+ this.action('hash', `${data.key}:${data.value}:md5:${data.id.uid}`);
2391
+ data.md5 = this.hash(data, 'md5'); // md5 the data packet
2392
+
2393
+ this.action('hash', `${data.key}:${data.value}:sha256:${data.id.uid}`);
2394
+ data.sha256 = this.hash(data, 'sha256'); // sha256 the data packet
2395
+
2396
+
2397
+ this.action('hash', `${data.key}:${data.value}:sha512:${data.id.uid}`);
2398
+ data.sha512 = this.hash(data, 'sha512'); // sha512 the data packet
2362
2399
 
2400
+ // set the action to talk and emit the talk error.
2401
+ this.action('talk', `${this._events.error}:${data.id.uid}`);
2363
2402
  this.talk(this._events.error, this.lib.copy(data));
2364
2403
 
2365
- this.state('return', `error:${id.uid}`);
2366
- this.state('error', id.uid);
2367
- this.context('error', id.uid);
2368
- if (hasOnError) return this.onError(err, packet, reject);
2369
- else return reject ? reject(err) : Promise.reject(err);
2404
+ const hasOnError = this.onError && typeof this.onError === 'function' ? true : false;
2405
+ // if block handles returning the onError and setting the state to hasOnError
2406
+ if (hasOnError) {
2407
+ this.action('onfunc', `hasOnError:${data.value}:${data.id.uid}`);
2408
+ this.state('onfunc', `hasOnError:${data.value}:${data.id.uid}`);
2409
+ return this.onError(err, packet, reject);
2410
+ }
2411
+ // else block handled the reject if there is no onError function.
2412
+ else {
2413
+ this.action('reject', `${data.value}:${id.uid}`);
2414
+ return reject ? reject(err) : Promise.reject(err);
2415
+ }
2370
2416
  }
2371
2417
 
2372
2418
  /**************
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "44091450722329207445",
3
3
  "name": "@indra.ai/deva",
4
- "version": "1.6.96",
4
+ "version": "1.6.97",
5
5
  "description": "Deva Core a Vedic-inspired Event Based Context Aware Feature, Zone, Action, and State Machine integrated Artificial Intelligence Framework",
6
6
  "main": "index.js",
7
7
  "license": "VLA:44091450722329207445 LICENSE.md",
package/tests/index.js CHANGED
@@ -168,9 +168,18 @@ const DevaTest = new Deva({
168
168
  return test;
169
169
  },
170
170
  },
171
+ onInit(data, resolve) {
172
+ return this.start(data, resolve);
173
+ },
174
+ onStart(data, resolve) {
175
+ return this.enter(data, resolve);
176
+ },
177
+ onEnter(data, resolve) {
178
+ return this.ready(data, resolve);
179
+ },
171
180
  onReady(data, resolve) {
172
181
  const test = this.methods.test(data);
173
- this.prompt(test.text);
182
+ this.prompt(this._messages.ready);
174
183
  return resolve(data);
175
184
  },
176
185
  onComplete(data, resolve) {