@indra.ai/deva 1.6.96 → 1.6.98
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/config/actions.json +1 -0
- package/config/states.json +2 -1
- package/index.js +82 -37
- package/package.json +1 -1
- package/tests/index.js +10 -1
package/config/actions.json
CHANGED
package/config/states.json
CHANGED
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)
|
|
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)
|
|
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)
|
|
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)
|
|
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)
|
|
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)
|
|
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)
|
|
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)
|
|
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)
|
|
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)
|
|
@@ -2107,7 +2134,6 @@ class Deva {
|
|
|
2107
2134
|
this.zone('unload', key);
|
|
2108
2135
|
this.action('unload', key);
|
|
2109
2136
|
this.state('unload', key);
|
|
2110
|
-
|
|
2111
2137
|
this.state('try', `unload:${key}`);
|
|
2112
2138
|
try {
|
|
2113
2139
|
this.devas[key].stop().then(exit => {
|
|
@@ -2116,7 +2142,7 @@ class Deva {
|
|
|
2116
2142
|
this.talk(this._events.unload, key);
|
|
2117
2143
|
});
|
|
2118
2144
|
this.action('resolve', `unload:${key}`);
|
|
2119
|
-
return resolve(
|
|
2145
|
+
return resolve(`${this._messages.unload}:${key}`);
|
|
2120
2146
|
} catch (e) {
|
|
2121
2147
|
this.state('catch', `unload:${key}`);
|
|
2122
2148
|
return this.err(e, this.devas[key], reject)
|
|
@@ -2275,27 +2301,28 @@ class Deva {
|
|
|
2275
2301
|
if (!this._active) return resolve(this._messages.offline);
|
|
2276
2302
|
let helpDoc = false;
|
|
2277
2303
|
const id = this.uid();
|
|
2278
|
-
|
|
2304
|
+
const key = 'help';
|
|
2305
|
+
this.zone(key, id);
|
|
2279
2306
|
|
|
2280
|
-
this.feature(
|
|
2281
|
-
this.action(
|
|
2282
|
-
this.state(
|
|
2283
|
-
this.context(
|
|
2307
|
+
this.feature(key, id.uid);
|
|
2308
|
+
this.action(key, id.uid);
|
|
2309
|
+
this.state(key, id.uid);
|
|
2310
|
+
this.context(key, id.uid);
|
|
2284
2311
|
const params = msg.split(' '); // split the msg into an array by spaces.
|
|
2285
2312
|
|
|
2286
2313
|
const splitText = params[0].split(':');
|
|
2287
2314
|
const part = splitText[1] ? splitText[1].toUpperCase() : 'MAIN';
|
|
2288
2315
|
const helpFile = splitText[0] ? splitText[0] : 'main';
|
|
2289
2316
|
|
|
2290
|
-
const helpPath = this.lib.path.join(help_dir,
|
|
2317
|
+
const helpPath = this.lib.path.join(help_dir, key, `${helpFile}.feecting`);
|
|
2291
2318
|
|
|
2292
2319
|
try {
|
|
2293
|
-
this.state('try',
|
|
2320
|
+
this.state('try', `${key}:${id.uid}`);
|
|
2294
2321
|
|
|
2295
2322
|
// check if help file exists first and resolve if no file
|
|
2296
2323
|
const helpExists = this.lib.fs.existsSync(helpPath); // check if help file exists
|
|
2297
2324
|
if (!helpExists) {
|
|
2298
|
-
this.
|
|
2325
|
+
this.action('resolve', `${key}:not:found:${id.uid}`);
|
|
2299
2326
|
return resolve(this._messages.help_not_found);
|
|
2300
2327
|
}
|
|
2301
2328
|
|
|
@@ -2303,7 +2330,7 @@ class Deva {
|
|
|
2303
2330
|
const helpFile = this.lib.fs.readFileSync(helpPath, 'utf8');
|
|
2304
2331
|
const helpPart = helpFile.split(`::BEGIN:${part}`);
|
|
2305
2332
|
if (!helpPart[1]) {
|
|
2306
|
-
this.
|
|
2333
|
+
this.action('resolve', `${this._messages.help_not_found}:${id.uid}`);
|
|
2307
2334
|
resolve(this._messages.help_not_found);
|
|
2308
2335
|
}
|
|
2309
2336
|
|
|
@@ -2311,11 +2338,11 @@ class Deva {
|
|
|
2311
2338
|
helpDoc = helpFile.split(`::BEGIN:${part}`)[1].split(`::END:${part}`)[0];
|
|
2312
2339
|
}
|
|
2313
2340
|
catch(e) {
|
|
2314
|
-
this.state('catch',
|
|
2341
|
+
this.state('catch', `${key}:${id.uid}`);
|
|
2315
2342
|
return this.err(e, msg, reject);
|
|
2316
2343
|
}
|
|
2317
2344
|
finally {
|
|
2318
|
-
this.
|
|
2345
|
+
this.action('resolve', `help:${id.uid}`);
|
|
2319
2346
|
return resolve(helpDoc);
|
|
2320
2347
|
}
|
|
2321
2348
|
});
|
|
@@ -2333,18 +2360,20 @@ class Deva {
|
|
|
2333
2360
|
***************/
|
|
2334
2361
|
err(err,packet,reject=false) {
|
|
2335
2362
|
const id = this.uid();
|
|
2336
|
-
|
|
2337
|
-
this.
|
|
2363
|
+
const key = 'error';
|
|
2364
|
+
this.context(key, id.uid);
|
|
2365
|
+
this.feature(key, id.uid);
|
|
2366
|
+
this.zone(key, id.uid);
|
|
2367
|
+
this.action(key, id.uid);
|
|
2368
|
+
this.state(key, id.uid);
|
|
2338
2369
|
|
|
2339
2370
|
const agent = this.agent();
|
|
2340
2371
|
const client = this.client();
|
|
2341
|
-
|
|
2342
|
-
this.
|
|
2343
|
-
const hasOnError = this.onError && typeof this.onError === 'function' ? true : false;
|
|
2344
|
-
|
|
2372
|
+
|
|
2373
|
+
this.state('data', `${key}:${id.uid}`);
|
|
2345
2374
|
const data = {
|
|
2346
2375
|
id,
|
|
2347
|
-
key
|
|
2376
|
+
key,
|
|
2348
2377
|
value: agent.key,
|
|
2349
2378
|
agent,
|
|
2350
2379
|
client,
|
|
@@ -2356,17 +2385,33 @@ class Deva {
|
|
|
2356
2385
|
packet,
|
|
2357
2386
|
created: Date.now(),
|
|
2358
2387
|
}
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
data.
|
|
2388
|
+
|
|
2389
|
+
this.action('hash', `${data.key}:${data.value}:md5:${data.id.uid}`);
|
|
2390
|
+
data.md5 = this.hash(data, 'md5'); // md5 the data packet
|
|
2391
|
+
|
|
2392
|
+
this.action('hash', `${data.key}:${data.value}:sha256:${data.id.uid}`);
|
|
2393
|
+
data.sha256 = this.hash(data, 'sha256'); // sha256 the data packet
|
|
2394
|
+
|
|
2395
|
+
|
|
2396
|
+
this.action('hash', `${data.key}:${data.value}:sha512:${data.id.uid}`);
|
|
2397
|
+
data.sha512 = this.hash(data, 'sha512'); // sha512 the data packet
|
|
2362
2398
|
|
|
2399
|
+
// set the action to talk and emit the talk error.
|
|
2400
|
+
this.action('talk', `${this._events.error}:${data.id.uid}`);
|
|
2363
2401
|
this.talk(this._events.error, this.lib.copy(data));
|
|
2364
2402
|
|
|
2365
|
-
this.
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2403
|
+
const hasOnError = this.onError && typeof this.onError === 'function' ? true : false;
|
|
2404
|
+
// if block handles returning the onError and setting the state to hasOnError
|
|
2405
|
+
if (hasOnError) {
|
|
2406
|
+
this.action('onfunc', `hasOnError:${data.value}:${data.id.uid}`);
|
|
2407
|
+
this.state('onfunc', `hasOnError:${data.value}:${data.id.uid}`);
|
|
2408
|
+
return this.onError(err, packet, reject);
|
|
2409
|
+
}
|
|
2410
|
+
// else block handled the reject if there is no onError function.
|
|
2411
|
+
else {
|
|
2412
|
+
this.action('reject', `${data.value}:${id.uid}`);
|
|
2413
|
+
return reject ? reject(err) : Promise.reject(err);
|
|
2414
|
+
}
|
|
2370
2415
|
}
|
|
2371
2416
|
|
|
2372
2417
|
/**************
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "44091450722329207445",
|
|
3
3
|
"name": "@indra.ai/deva",
|
|
4
|
-
"version": "1.6.
|
|
4
|
+
"version": "1.6.98",
|
|
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(
|
|
182
|
+
this.prompt(this._messages.ready);
|
|
174
183
|
return resolve(data);
|
|
175
184
|
},
|
|
176
185
|
onComplete(data, resolve) {
|