@indra.ai/deva.justice 0.0.102 → 0.0.104
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 +45 -7
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
// Justice Deva
|
|
7
7
|
import Deva from '@indra.ai/deva';
|
|
8
|
+
import { MongoClient, ObjectId } from 'mongodb';
|
|
9
|
+
|
|
8
10
|
import pkg from './package.json' with {type:'json'};
|
|
9
11
|
const {agent,vars} = pkg.data;
|
|
10
12
|
|
|
@@ -38,31 +40,67 @@ const JUSTICE = new Deva({
|
|
|
38
40
|
process(input) {return input.trim();},
|
|
39
41
|
},
|
|
40
42
|
listeners: {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
// log the exit packet when the deva exits the system
|
|
44
|
+
'devacore:exit'(packet) {
|
|
45
|
+
this.func.write_log('exit', packet);
|
|
46
|
+
},
|
|
47
|
+
// log the answer on complete of the question and answer
|
|
48
|
+
'devacore:complete'(packet) {
|
|
49
|
+
this.func.write_log('complete', packet);
|
|
43
50
|
},
|
|
44
|
-
'devacore:answer'(packet) {
|
|
45
|
-
const echo = this.methods.echo('defense', 'a', packet);
|
|
46
|
-
}
|
|
47
51
|
},
|
|
48
|
-
modules: {
|
|
49
|
-
|
|
52
|
+
modules: {
|
|
53
|
+
client: false,
|
|
54
|
+
},
|
|
55
|
+
func: {
|
|
56
|
+
/**************
|
|
57
|
+
func: write_log
|
|
58
|
+
params: type, packet
|
|
59
|
+
describe: this is the log file writer function that handles
|
|
60
|
+
writing for finish and complete for complete chain of custody.
|
|
61
|
+
***************/
|
|
62
|
+
async write_log(type, packet) {
|
|
63
|
+
let result = false;
|
|
64
|
+
try {
|
|
65
|
+
const database = this.modules.client.db(this.vars.log);
|
|
66
|
+
const collection = database.collection(type);
|
|
67
|
+
result = await collection.insertOne(packet);
|
|
68
|
+
} catch (e) {
|
|
69
|
+
return this.err(e, packet, false);
|
|
70
|
+
} finally {
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
},
|
|
50
75
|
methods: {},
|
|
51
76
|
onInit(data, resolve) {
|
|
52
77
|
const {personal} = this.license(); // get the license config
|
|
53
78
|
const agent_license = this.info().VLA; // get agent license
|
|
54
79
|
const license_check = this.license_check(personal, agent_license); // check license
|
|
55
80
|
// return this.start if license_check passes otherwise stop.
|
|
81
|
+
this.action('return', `onInit:${data.id.uid}`);
|
|
56
82
|
return license_check ? this.start(data, resolve) : this.stop(data, resolve);
|
|
57
83
|
},
|
|
58
84
|
onReady(data, resolve) {
|
|
59
85
|
const {VLA} = this.info();
|
|
86
|
+
|
|
87
|
+
this.state('get', `mongo:global:${data.id.uid}`);
|
|
88
|
+
const {uri,database, log} = this.justice().global.mongo;
|
|
89
|
+
this.state('set', `mongo:client:${data.id.uid}`);
|
|
90
|
+
this.modules.client = new MongoClient(uri);
|
|
91
|
+
this.state('set', `mongo:database:${data.id.uid}`);
|
|
92
|
+
this.vars.database = database;
|
|
93
|
+
this.state('set', `mongo:log:${data.id.uid}`);
|
|
94
|
+
this.vars.log = log;
|
|
95
|
+
|
|
60
96
|
this.prompt(`${this.vars.messages.ready} > VLA:${VLA.uid}`);
|
|
97
|
+
this.action('resolve', `onReady:${data.id.uid}`);
|
|
61
98
|
return resolve(data);
|
|
62
99
|
},
|
|
63
100
|
onError(err, data, reject) {
|
|
64
101
|
this.prompt(this.vars.messages.error);
|
|
65
102
|
console.log(err);
|
|
103
|
+
this.action('reject', `onError:${data.id.uid}`);
|
|
66
104
|
return reject(err);
|
|
67
105
|
}
|
|
68
106
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "66900525171674101536",
|
|
3
3
|
"name": "@indra.ai/deva.justice",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.104",
|
|
5
5
|
"license": "VLA:66900525171674101536 LICENSE.md",
|
|
6
6
|
"VLA": {
|
|
7
7
|
"uid": "66900525171674101536",
|
|
@@ -59,7 +59,8 @@
|
|
|
59
59
|
},
|
|
60
60
|
"homepage": "https://deva.space/devas/justice",
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@indra.ai/deva": "^1.6.100"
|
|
62
|
+
"@indra.ai/deva": "^1.6.100",
|
|
63
|
+
"mongodb": "^6.20.0"
|
|
63
64
|
},
|
|
64
65
|
"data": {
|
|
65
66
|
"agent": {
|