@indra.ai/deva.guard 0.0.31 → 0.0.32
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 +39 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4,6 +4,8 @@ import Deva from '@indra.ai/deva';
|
|
|
4
4
|
import pkg from './package.json' with {type:'json'};
|
|
5
5
|
const {agent,vars} = pkg.data;
|
|
6
6
|
|
|
7
|
+
import {exec, spawn} from 'node:child_process';
|
|
8
|
+
|
|
7
9
|
// set the __dirname
|
|
8
10
|
import {dirname} from 'node:path';
|
|
9
11
|
import {fileURLToPath} from 'node:url';
|
|
@@ -32,10 +34,45 @@ const GUARD = new Deva({
|
|
|
32
34
|
parse(input) {return input.trim();},
|
|
33
35
|
process(input) {return input.trim();},
|
|
34
36
|
},
|
|
35
|
-
listeners: {
|
|
37
|
+
listeners: {
|
|
38
|
+
'devacore:question'(packet) {
|
|
39
|
+
this.func.echostr(packet.q);
|
|
40
|
+
},
|
|
41
|
+
'devacore:answer'(packet) {
|
|
42
|
+
this.func.echostr(packet.a);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
36
45
|
modules: {},
|
|
37
46
|
deva: {},
|
|
38
|
-
func: {
|
|
47
|
+
func: {
|
|
48
|
+
echostr(opts) {
|
|
49
|
+
const {id, agent, client, md5, sha256, sha512} = opts;
|
|
50
|
+
const created = Date.now();
|
|
51
|
+
|
|
52
|
+
this.action('func', `echostr:${id}`);
|
|
53
|
+
this.state('set', `echostr:${id}`);
|
|
54
|
+
const echostr = [
|
|
55
|
+
`::begin:guard:${id}`,
|
|
56
|
+
`transport: ${id}`,
|
|
57
|
+
`client: ${client.profile.id}`,
|
|
58
|
+
`agent: ${agent.profile.id}`,
|
|
59
|
+
`created: ${created}`,
|
|
60
|
+
`md5: ${md5}`,
|
|
61
|
+
`sha256:${sha256}`,
|
|
62
|
+
`sha512:${sha512}`,
|
|
63
|
+
`::end:guard:${id}`,
|
|
64
|
+
].join('\nliek');
|
|
65
|
+
|
|
66
|
+
// stub for later features right now just echo into the system process for SIGINT monitoring.
|
|
67
|
+
const echo = spawn('echo', [echostr])
|
|
68
|
+
echo.stderr.on('data', err => {
|
|
69
|
+
this.error(err, opts);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
this.state('return', `echostr:${id}`);
|
|
73
|
+
return echostr;
|
|
74
|
+
}
|
|
75
|
+
},
|
|
39
76
|
methods: {},
|
|
40
77
|
onReady(data, resolve) {
|
|
41
78
|
this.prompt(this.vars.messages.ready);
|