@indra.ai/deva.guard 0.0.34 → 0.0.35
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/feature/methods.js +54 -108
- package/index.js +3 -39
- package/package.json +1 -1
package/feature/methods.js
CHANGED
|
@@ -1,129 +1,75 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
***************/
|
|
7
|
-
guard(packet) {
|
|
8
|
-
this.context('feature');
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
const guard = this.guard();
|
|
11
|
-
const agent = this.agent();
|
|
12
|
-
const global = [];
|
|
13
|
-
guard.global.forEach((item,index) => {
|
|
14
|
-
global.push(`::begin:global:${item.key}:${item.id}`);
|
|
15
|
-
for (let x in item) {
|
|
16
|
-
global.push(`${x}: ${item[x]}`);
|
|
17
|
-
}
|
|
18
|
-
global.push(`::end:global:${item.key}:${this.lib.hash(item)}`);
|
|
19
|
-
});
|
|
20
|
-
const concerns = [];
|
|
21
|
-
guard.concerns.forEach((item, index) => {
|
|
22
|
-
concerns.push(`${index + 1}. ${item}`);
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
const info = [
|
|
26
|
-
`::BEGIN:GUARD:${packet.id}`,
|
|
27
|
-
'### Client',
|
|
28
|
-
`::begin:client:${guard.client_id}`,
|
|
29
|
-
`id: ${guard.client_id}`,
|
|
30
|
-
`client: ${guard.client_name}`,
|
|
31
|
-
'**concerns**',
|
|
32
|
-
concerns.join('\n'),
|
|
33
|
-
`::end:client:${this.lib.hash(guard)}`,
|
|
34
|
-
'### Global',
|
|
35
|
-
global.join('\n'),
|
|
36
|
-
`date: ${this.lib.formatDate(Date.now(), 'long', true)}`,
|
|
37
|
-
`::END:GUARD:${this.lib.hash(packet)}`,
|
|
38
|
-
].join('\n');
|
|
39
|
-
this.question(`${this.askChr}feecting parse ${info}`).then(feecting => {
|
|
40
|
-
return resolve({
|
|
41
|
-
text: feecting.a.text,
|
|
42
|
-
html: feecting.a.html,
|
|
43
|
-
data: guard.concerns,
|
|
44
|
-
});
|
|
45
|
-
}).catch(err => {
|
|
46
|
-
return this.error(err, packet, reject);
|
|
47
|
-
})
|
|
48
|
-
});
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
method: shield
|
|
54
|
-
params: packet
|
|
55
|
-
describe: Return authorized VectorGuardShield for requesting client.
|
|
56
|
-
copyright: ©2025 Quinn A Michaels. All rights reserved.
|
|
57
|
-
**/
|
|
58
|
-
async shield(packet) {
|
|
59
|
-
this.state('set', `transport:${packet.id}`);
|
|
60
|
-
const transport = packet.id; // set the transport from packet.id
|
|
61
|
-
|
|
2
|
+
async guard(packet) {
|
|
3
|
+
this.state('set', `guard:transport:${packet.id}`);
|
|
4
|
+
const transport = packet.id; // set the transport id from the packet id.
|
|
5
|
+
|
|
62
6
|
this.zone('guard', transport); // set the current zone to guard
|
|
63
7
|
this.feature('guard', transport); // set the Guard feature.
|
|
64
|
-
this.context('
|
|
65
|
-
this.action('method', `
|
|
66
|
-
|
|
8
|
+
this.context('guard', transport); // set the agent context to proxy.
|
|
9
|
+
this.action('method', `proxy:${transport}`); // set the action method to proxy.
|
|
10
|
+
|
|
67
11
|
this.state('set', `uid:${transport}`); //set the uid state for the proxy
|
|
68
12
|
const uid = this.lib.uid(true); // The UID for the proxy
|
|
69
13
|
this.state('set', `time:${transport}`); //set the time state for the proxy
|
|
70
14
|
const time = Date.now(); // current timestamp
|
|
71
15
|
this.state('created', `created:${transport}`); //set the uid state for the proxy
|
|
72
16
|
const created = this.lib.formatDate(time, 'long', true); // Formatted created date.
|
|
73
|
-
|
|
17
|
+
|
|
74
18
|
this.state('set', `guard:${transport}`); //set the guard state for the proxy
|
|
75
19
|
const guard = this.guard(); // load the Guard profile
|
|
76
20
|
const {concerns} = guard; // load concerns from client guard profile.
|
|
77
21
|
|
|
78
|
-
this.state('set', `agent:${transport}`); //set the agent state for the proxy
|
|
22
|
+
this.state('set', `guard:agent:${transport}`); //set the agent state for the proxy
|
|
79
23
|
const agent = this.agent(); // the agent processing the proxy
|
|
80
24
|
|
|
81
|
-
this.state('set', `client:${transport}`); //set the client state for the proxy
|
|
25
|
+
this.state('set', `guard:client:${transport}`); //set the client state for the proxy
|
|
82
26
|
const client = this.client(); // the client requesting the proxy
|
|
83
|
-
const {profile} = client; // set the client profile
|
|
84
27
|
|
|
85
|
-
this.state('set', `meta:${transport}`); //set the meta state for the proxy
|
|
28
|
+
this.state('set', `guard:meta:${transport}`); //set the meta state for the proxy
|
|
86
29
|
const {meta} = packet.q; // set the meta information from the packet question.
|
|
30
|
+
|
|
31
|
+
this.state('set', `guard:params:${transport}`); //set the meta state for the proxy
|
|
87
32
|
const {params} = meta; // set params from the meta information.
|
|
88
33
|
|
|
89
|
-
this.state('set', `opts:${transport}`); //set the opts state for the proxy
|
|
34
|
+
this.state('set', `guard:opts:${transport}`); //set the opts state for the proxy
|
|
90
35
|
const opts = this.lib.copy(params); // copy the params and set as opts.
|
|
91
|
-
|
|
92
|
-
this.state('set', `command:${transport}`); //set the opts state for the proxy
|
|
36
|
+
|
|
37
|
+
this.state('set', `guard:command:${transport}`); //set the opts state for the proxy
|
|
93
38
|
const command = opts.shift(); // extract the command first array item out of opts.
|
|
94
39
|
|
|
95
|
-
this.state('set', `message:${transport}`); //set the message state for the proxy
|
|
40
|
+
this.state('set', `guard:message:${transport}`); //set the message state for the proxy
|
|
96
41
|
const message = packet.q.text; // set packet.q.text as the message of the proxy.
|
|
97
|
-
|
|
98
|
-
this.state('set', `writestr:${transport}`);
|
|
99
|
-
const write = `OM:${client.profile.write.split(' ').join(':').toUpperCase()}:SHIELD`;
|
|
100
42
|
|
|
101
|
-
this.state('
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
this.state('hash', `client profile:${transport}`);
|
|
105
|
-
const client_profile = this.lib.hash(client.profile, 'sha256');
|
|
106
|
-
|
|
43
|
+
this.state('set', `guard:write:${transport}`); //set the message state for the proxy
|
|
44
|
+
const write = `OM:VECTOR:GUARD:${client.profile.write.split(' ').join(':').toUpperCase()}`; // set proxy write string.
|
|
45
|
+
|
|
107
46
|
// hash the agent profile for security
|
|
108
|
-
this.state('hash', `
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
47
|
+
this.state('hash', `guard:agent:hash:${transport}`);
|
|
48
|
+
const agent_hash = this.lib.hash(agent, 'sha256');
|
|
49
|
+
|
|
50
|
+
// hash the agent profile for security
|
|
51
|
+
this.state('hash', `guard:client:hash:${transport}`);
|
|
52
|
+
const client_hash = this.lib.hash(client, 'sha256');
|
|
53
|
+
|
|
54
|
+
// hash the agent profile for security
|
|
55
|
+
this.state('hash', `guard:token:${transport}`);
|
|
56
|
+
const token = this.lib.hash(`GUARD ${client.profile.token} ${transport}`, 'sha256');
|
|
57
|
+
|
|
58
|
+
this.state('set', `guard:data:${transport}`); // set the state to set data
|
|
112
59
|
// data packet
|
|
113
60
|
const data = {
|
|
114
61
|
uid,
|
|
115
|
-
time,
|
|
116
62
|
transport,
|
|
63
|
+
time,
|
|
117
64
|
write,
|
|
118
|
-
message,
|
|
65
|
+
message,
|
|
119
66
|
caseid: client.profile.caseid,
|
|
120
67
|
opts: opts.length? `:${opts.join(':')}` : '',
|
|
121
|
-
agent:
|
|
122
|
-
client:
|
|
68
|
+
agent: agent_hash,
|
|
69
|
+
client: client_hash,
|
|
123
70
|
name: client.profile.name,
|
|
124
|
-
company: client.profile.company,
|
|
125
71
|
emojis: client.profile.emojis,
|
|
126
|
-
|
|
72
|
+
company: client.profile.company,
|
|
127
73
|
warning: client.profile.warning,
|
|
128
74
|
token,
|
|
129
75
|
concerns,
|
|
@@ -133,46 +79,46 @@ export default {
|
|
|
133
79
|
created,
|
|
134
80
|
copyright: client.profile.copyright,
|
|
135
81
|
};
|
|
136
|
-
|
|
137
|
-
this.state('hash', `md5:${transport}`); // set state to
|
|
82
|
+
|
|
83
|
+
this.state('hash', `guard:md5:${transport}`); // set state to secure hashing
|
|
138
84
|
data.md5 = this.lib.hash(data, 'md5'); // hash data packet into md5 and inert into data.
|
|
139
85
|
|
|
140
|
-
this.state('hash', `sha256:${transport}`); // set state to
|
|
86
|
+
this.state('hash', `guard:sha256:${transport}`); // set state to secure hashing
|
|
141
87
|
data.sha256 = this.lib.hash(data, 'sha256'); // hash data into sha 256 then set in data.
|
|
142
88
|
|
|
143
|
-
this.state('hash', `sha512:${transport}`); // set state to
|
|
89
|
+
this.state('hash', `guard:sha512:${transport}`); // set state to secure hashing
|
|
144
90
|
data.sha512 = this.lib.hash(data, 'sha512'); // hash data into sha 512 then set in data.
|
|
145
|
-
|
|
146
|
-
|
|
91
|
+
|
|
92
|
+
// Text data that is joined by line breaks and then trimmed.
|
|
93
|
+
this.state('set', `guard:text:${transport}`); // set state to text for output formatting.
|
|
147
94
|
const text = [
|
|
148
|
-
|
|
149
|
-
`::BEGIN:${data.write}:${transport}`,
|
|
150
|
-
`#
|
|
151
|
-
`::begin:vector:guard
|
|
95
|
+
`:::`,
|
|
96
|
+
`::BEGIN:${data.write}:${data.transport}`,
|
|
97
|
+
`#VectorGuard${data.opts} ${data.message}`,
|
|
98
|
+
`::begin:vector:guard:${transport}:${data.emojis}`,
|
|
152
99
|
`transport: ${data.transport}`,
|
|
153
100
|
`time: ${data.time}`,
|
|
154
101
|
`caseid: ${data.caseid}`,
|
|
155
102
|
`agent: ${data.agent}`,
|
|
156
103
|
`client: ${data.client}`,
|
|
104
|
+
`token: ${data.token}`,
|
|
157
105
|
`name: ${data.name}`,
|
|
158
106
|
`company: ${data.company}`,
|
|
159
|
-
`token: ${data.token}`,
|
|
160
107
|
`warning: ${data.warning}`,
|
|
161
108
|
`created: ${data.created}`,
|
|
162
109
|
`copyright: ${data.copyright}`,
|
|
163
110
|
`md5: ${data.md5}`,
|
|
164
111
|
`sha256: ${data.sha256}`,
|
|
165
112
|
`sha512: ${data.sha512}`,
|
|
166
|
-
`::end:vector:guard
|
|
167
|
-
`::END:${data.write}:${transport}`,
|
|
168
|
-
'::::',
|
|
113
|
+
`::end:vector:guard:${data.transport}:${data.emojis}`,
|
|
114
|
+
`::END:${data.write}:${data.transport}`,
|
|
169
115
|
].join('\n').trim();
|
|
170
116
|
|
|
171
117
|
// send the text data to #feecting to parse and return valid text, html, and data.
|
|
172
|
-
this.action('question', `feecting:parse:${transport}`); // action set to feecting parse
|
|
173
|
-
const feecting = await this.question(`${this.askChr}feecting parse:${transport} ${text}`);
|
|
118
|
+
this.action('question', `guard:feecting:parse:${transport}`); // action set to feecting parse
|
|
119
|
+
const feecting = await this.question(`${this.askChr}feecting parse:${transport} ${text}`); // parse with feecting agent.
|
|
174
120
|
|
|
175
|
-
this.state('return', `
|
|
121
|
+
this.state('return', `guard:${transport}`); // set the state to return proxy
|
|
176
122
|
return {
|
|
177
123
|
text: feecting.a.text,
|
|
178
124
|
html: feecting.a.html,
|
package/index.js
CHANGED
|
@@ -4,8 +4,6 @@ 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
|
-
|
|
9
7
|
// set the __dirname
|
|
10
8
|
import {dirname} from 'node:path';
|
|
11
9
|
import {fileURLToPath} from 'node:url';
|
|
@@ -36,49 +34,15 @@ const GUARD = new Deva({
|
|
|
36
34
|
},
|
|
37
35
|
listeners: {
|
|
38
36
|
'devacore:question'(packet) {
|
|
39
|
-
this.
|
|
37
|
+
const echo = this.methods.echo('guard', 'question', packet.q);
|
|
40
38
|
},
|
|
41
39
|
'devacore:answer'(packet) {
|
|
42
|
-
this.
|
|
40
|
+
const echo = this.methods.echo('guard', 'answer', packet.a);
|
|
43
41
|
}
|
|
44
42
|
},
|
|
45
43
|
modules: {},
|
|
46
44
|
deva: {},
|
|
47
|
-
func: {
|
|
48
|
-
echo(opts) {
|
|
49
|
-
const {id, agent, client, md5, sha256, sha512} = opts;
|
|
50
|
-
const created = Date.now();
|
|
51
|
-
|
|
52
|
-
this.action('func', `echo:${id}`);
|
|
53
|
-
this.state('set', `echo:${id}`);
|
|
54
|
-
const echo_data = [
|
|
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('\n');
|
|
65
|
-
|
|
66
|
-
// stub for later features right now just echo into the system process for SIGINT monitoring.
|
|
67
|
-
const echo = spawn('echo', [echo_data])
|
|
68
|
-
echo.stdout.on('data', data => {
|
|
69
|
-
this.state('data', `echo:stdout:${id}`);
|
|
70
|
-
});
|
|
71
|
-
echo.stderr.on('data', err => {
|
|
72
|
-
this.state('error', `echo:stderr:${id}`);
|
|
73
|
-
this.error(err, opts);
|
|
74
|
-
});
|
|
75
|
-
echo.on('close', data => {
|
|
76
|
-
this.state('close', `echo:${id}`);
|
|
77
|
-
});
|
|
78
|
-
this.state('return', `echo:${id}`);
|
|
79
|
-
return echo_data;
|
|
80
|
-
}
|
|
81
|
-
},
|
|
45
|
+
func: {},
|
|
82
46
|
methods: {},
|
|
83
47
|
onReady(data, resolve) {
|
|
84
48
|
this.prompt(this.vars.messages.ready);
|