@indra.ai/deva.guard 0.0.34 → 0.0.36

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.
@@ -1,184 +1,11 @@
1
1
  export default {
2
2
  /**************
3
- method: Guard
3
+ method: guard
4
4
  params: packet
5
- describe: The global service feature that installs with every agent
5
+ describe: The global guard feature that installs with every agent
6
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
- });
7
+ async guard(packet) {
8
+ const guard = await this.methods.sign('guard', 'default', packet);
9
+ return guard;
49
10
  },
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
-
62
- this.zone('guard', transport); // set the current zone to guard
63
- this.feature('guard', transport); // set the Guard feature.
64
- this.context('shield', transport); // set context to shield
65
- this.action('method', `shield:${transport}`); // action set to shield
66
-
67
- this.state('set', `uid:${transport}`); //set the uid state for the proxy
68
- const uid = this.lib.uid(true); // The UID for the proxy
69
- this.state('set', `time:${transport}`); //set the time state for the proxy
70
- const time = Date.now(); // current timestamp
71
- this.state('created', `created:${transport}`); //set the uid state for the proxy
72
- const created = this.lib.formatDate(time, 'long', true); // Formatted created date.
73
-
74
- this.state('set', `guard:${transport}`); //set the guard state for the proxy
75
- const guard = this.guard(); // load the Guard profile
76
- const {concerns} = guard; // load concerns from client guard profile.
77
-
78
- this.state('set', `agent:${transport}`); //set the agent state for the proxy
79
- const agent = this.agent(); // the agent processing the proxy
80
-
81
- this.state('set', `client:${transport}`); //set the client state for the proxy
82
- const client = this.client(); // the client requesting the proxy
83
- const {profile} = client; // set the client profile
84
-
85
- this.state('set', `meta:${transport}`); //set the meta state for the proxy
86
- const {meta} = packet.q; // set the meta information from the packet question.
87
- const {params} = meta; // set params from the meta information.
88
-
89
- this.state('set', `opts:${transport}`); //set the opts state for the proxy
90
- 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
93
- const command = opts.shift(); // extract the command first array item out of opts.
94
-
95
- this.state('set', `message:${transport}`); //set the message state for the proxy
96
- 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
-
101
- this.state('hash', `agent profile:${transport}`);
102
- const agent_profile = this.lib.hash(client.profile, 'sha256');
103
-
104
- this.state('hash', `client profile:${transport}`);
105
- const client_profile = this.lib.hash(client.profile, 'sha256');
106
-
107
- // hash the agent profile for security
108
- this.state('hash', `token:${transport}`);
109
- const token = this.lib.hash(`${client.profile.token} SHIELD ${transport}`, 'sha256');
110
-
111
- this.state('set', `data:${transport}`); // set the state to set data
112
- // data packet
113
- const data = {
114
- uid,
115
- time,
116
- transport,
117
- write,
118
- message,
119
- caseid: client.profile.caseid,
120
- opts: opts.length? `:${opts.join(':')}` : '',
121
- agent: agent_profile,
122
- client: client_profile,
123
- name: client.profile.name,
124
- company: client.profile.company,
125
- emojis: client.profile.emojis,
126
- token: client.profile.token,
127
- warning: client.profile.warning,
128
- token,
129
- concerns,
130
- meta,
131
- params,
132
- command,
133
- created,
134
- copyright: client.profile.copyright,
135
- };
136
-
137
- this.state('hash', `md5:${transport}`); // set state to hash hashing
138
- data.md5 = this.lib.hash(data, 'md5'); // hash data packet into md5 and inert into data.
139
-
140
- this.state('hash', `sha256:${transport}`); // set state to hash hashing
141
- data.sha256 = this.lib.hash(data, 'sha256'); // hash data into sha 256 then set in data.
142
-
143
- this.state('hash', `sha512:${transport}`); // set state to hash hashing
144
- data.sha512 = this.lib.hash(data, 'sha512'); // hash data into sha 512 then set in data.
145
-
146
- this.state('set', `text:${transport}`); // set state to text for output formatting.
147
- const text = [
148
- '::::',
149
- `::BEGIN:${data.write}:${transport}`,
150
- `#VectorGuardShield${data.opts} ${data.message}`,
151
- `::begin:vector:guard:shield:${transport}:${data.emojis}`,
152
- `transport: ${data.transport}`,
153
- `time: ${data.time}`,
154
- `caseid: ${data.caseid}`,
155
- `agent: ${data.agent}`,
156
- `client: ${data.client}`,
157
- `name: ${data.name}`,
158
- `company: ${data.company}`,
159
- `token: ${data.token}`,
160
- `warning: ${data.warning}`,
161
- `created: ${data.created}`,
162
- `copyright: ${data.copyright}`,
163
- `md5: ${data.md5}`,
164
- `sha256: ${data.sha256}`,
165
- `sha512: ${data.sha512}`,
166
- `::end:vector:guard:shield:${data.transport}:${data.emojis}`,
167
- `::END:${data.write}:${transport}`,
168
- '::::',
169
- ].join('\n').trim();
170
-
171
- // 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}`);
174
-
175
- this.state('return', `shield:${transport}`); // set the state to return proxy
176
- return {
177
- text: feecting.a.text,
178
- html: feecting.a.html,
179
- data,
180
- }
181
- },
182
-
183
-
184
11
  };
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.func.echo(packet.q);
37
+ const echo = this.methods.echo('guard', 'question', packet.q);
40
38
  },
41
39
  'devacore:answer'(packet) {
42
- this.func.echo(packet.a);
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);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": 6159528221394,
3
3
  "name": "@indra.ai/deva.guard",
4
- "version": "0.0.34",
4
+ "version": "0.0.36",
5
5
  "author": "Quinn Michaels",
6
6
  "license": "MIT",
7
7
  "copyright": "2025",