@indra.ai/deva 1.1.26 โ 1.1.28
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/examples/agent.json +38 -0
- package/examples/client.json +46 -13
- package/examples/hello-world.js +31 -5
- package/index.js +428 -152
- package/package.json +1 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "AGENT",
|
|
3
|
+
"describe": "AGENT FILE",
|
|
4
|
+
"copyright": "Copyright (c)2023 Quinn Michaels. All rights reserved.",
|
|
5
|
+
"DATA": {
|
|
6
|
+
"id": 5380514963421,
|
|
7
|
+
"key": "deva",
|
|
8
|
+
"name": "@Deva",
|
|
9
|
+
"describe": "The Deva interface into deva.world.",
|
|
10
|
+
"prompt": {
|
|
11
|
+
"emoji": "๐",
|
|
12
|
+
"text": "deva",
|
|
13
|
+
"colors": {
|
|
14
|
+
"label": {
|
|
15
|
+
"R": 0,
|
|
16
|
+
"G": 150,
|
|
17
|
+
"B": 255
|
|
18
|
+
},
|
|
19
|
+
"text": {
|
|
20
|
+
"R": 101,
|
|
21
|
+
"G": 192,
|
|
22
|
+
"B": 255
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"voice": {
|
|
27
|
+
"speech": "Alex",
|
|
28
|
+
"speed": 1
|
|
29
|
+
},
|
|
30
|
+
"profile": {
|
|
31
|
+
"emoji": "/public/devas/deva/emoji.png",
|
|
32
|
+
"avatar": "/public/devas/deva/avatar.png",
|
|
33
|
+
"background": "/public/devas/deva/background.png",
|
|
34
|
+
"describe": "The Deva Project",
|
|
35
|
+
"gender": "M"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
package/examples/client.json
CHANGED
|
@@ -5,9 +5,6 @@
|
|
|
5
5
|
"DATA": {
|
|
6
6
|
"id": 3123155399059,
|
|
7
7
|
"key": "test",
|
|
8
|
-
"name": "Test User",
|
|
9
|
-
"eamil": "test@example.com",
|
|
10
|
-
"describe": "The Test User",
|
|
11
8
|
"prompt": {
|
|
12
9
|
"emoji": "๐งช",
|
|
13
10
|
"text": "test",
|
|
@@ -25,16 +22,39 @@
|
|
|
25
22
|
}
|
|
26
23
|
},
|
|
27
24
|
"profile": {
|
|
28
|
-
"emoji": "https://quinnmichaels.com/assets/img/quinn/avatar.png",
|
|
29
|
-
"avatar": "https://quinnmichaels.com/assets/img/quinn/avatar.png",
|
|
30
|
-
"background": "https://quinnmichaels.com/assets/img/quinn/background.png",
|
|
31
25
|
"name": "Test User",
|
|
32
|
-
"
|
|
26
|
+
"eamil": "test@example.com",
|
|
27
|
+
"describe": "The Test User",
|
|
28
|
+
"emoji": "/public/devas/test/avatar.png",
|
|
29
|
+
"avatar": "/public/devas/test/avatar.png",
|
|
30
|
+
"background": "/public/devas/test/background.png",
|
|
33
31
|
"gender": "splendid",
|
|
34
|
-
"lang": "en"
|
|
32
|
+
"lang": "en",
|
|
33
|
+
"locale": "en-US",
|
|
34
|
+
"currency": "USD"
|
|
35
35
|
},
|
|
36
36
|
"states": {},
|
|
37
37
|
"messages": {},
|
|
38
|
+
"security": {
|
|
39
|
+
"hash": "md5",
|
|
40
|
+
"cipher": {
|
|
41
|
+
"encrypt": true,
|
|
42
|
+
"algorithm": "aes-256-cbc",
|
|
43
|
+
"password": "generic password for encryption test"
|
|
44
|
+
},
|
|
45
|
+
"concerns": [],
|
|
46
|
+
"global": {},
|
|
47
|
+
"devas": {
|
|
48
|
+
"hello": {}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"support": {
|
|
52
|
+
"concerns": [],
|
|
53
|
+
"global": {},
|
|
54
|
+
"devas": {
|
|
55
|
+
"hello": {}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
38
58
|
"services": {
|
|
39
59
|
"concerns": [],
|
|
40
60
|
"global": {
|
|
@@ -43,17 +63,30 @@
|
|
|
43
63
|
"space": "https://deva.space",
|
|
44
64
|
"cloud": "https://deva.cloud"
|
|
45
65
|
},
|
|
46
|
-
"devas": {
|
|
66
|
+
"devas": {
|
|
67
|
+
"hello": {}
|
|
68
|
+
}
|
|
47
69
|
},
|
|
48
|
-
"
|
|
70
|
+
"systems": {
|
|
49
71
|
"concerns": [],
|
|
50
72
|
"global": {},
|
|
51
|
-
"devas": {
|
|
73
|
+
"devas": {
|
|
74
|
+
"hello": {}
|
|
75
|
+
}
|
|
52
76
|
},
|
|
53
|
-
"
|
|
77
|
+
"solutions": {
|
|
54
78
|
"concerns": [],
|
|
55
79
|
"global": {},
|
|
56
|
-
"devas": {
|
|
80
|
+
"devas": {
|
|
81
|
+
"hello": {}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"development": {
|
|
85
|
+
"concerns": [],
|
|
86
|
+
"global": {},
|
|
87
|
+
"devas": {
|
|
88
|
+
"hello": {}
|
|
89
|
+
}
|
|
57
90
|
}
|
|
58
91
|
}
|
|
59
92
|
}
|
package/examples/hello-world.js
CHANGED
|
@@ -12,8 +12,6 @@ const HelloWorld = new Deva({
|
|
|
12
12
|
agent: {
|
|
13
13
|
id: 101,
|
|
14
14
|
key: 'hello',
|
|
15
|
-
name: 'Hello World',
|
|
16
|
-
description: 'The most over complex Hello World in the Universe',
|
|
17
15
|
prompt: {
|
|
18
16
|
emoji: '๐ถ',
|
|
19
17
|
text: 'hello',
|
|
@@ -24,6 +22,8 @@ const HelloWorld = new Deva({
|
|
|
24
22
|
speed: 1
|
|
25
23
|
},
|
|
26
24
|
profile: {
|
|
25
|
+
name: 'Hello World',
|
|
26
|
+
description: 'The most over complex Hello World in the Universe',
|
|
27
27
|
avatar: '',
|
|
28
28
|
background: '',
|
|
29
29
|
describe: 'Hello World Deva',
|
|
@@ -54,8 +54,33 @@ const HelloWorld = new Deva({
|
|
|
54
54
|
return Promise.resolve(this._client);
|
|
55
55
|
},
|
|
56
56
|
state(packet) {
|
|
57
|
-
const
|
|
58
|
-
|
|
57
|
+
const text = this._state
|
|
58
|
+
const id = this.uid();
|
|
59
|
+
const uuid = this.uid(true);
|
|
60
|
+
|
|
61
|
+
const created = this.formatDate(Date.now(), 'long', true)
|
|
62
|
+
const md5 = this.hash(JSON.stringify(packet));
|
|
63
|
+
const sha256 = this.hash(JSON.stringify(packet), 'sha256');
|
|
64
|
+
const sha512 = this.hash(JSON.stringify(packet), 'sha512');
|
|
65
|
+
const cipher = this.cipher(JSON.stringify(packet));
|
|
66
|
+
const decipher = this.decipher(cipher);
|
|
67
|
+
|
|
68
|
+
const data = {
|
|
69
|
+
id,
|
|
70
|
+
uuid,
|
|
71
|
+
hash: {
|
|
72
|
+
md5,
|
|
73
|
+
sha256,
|
|
74
|
+
sha512,
|
|
75
|
+
created,
|
|
76
|
+
},
|
|
77
|
+
cipher,
|
|
78
|
+
decipher
|
|
79
|
+
}
|
|
80
|
+
return Promise.resolve({
|
|
81
|
+
text: 'state return see data',
|
|
82
|
+
data,
|
|
83
|
+
});
|
|
59
84
|
}
|
|
60
85
|
},
|
|
61
86
|
methods: {
|
|
@@ -75,7 +100,8 @@ HelloWorld.init(client.DATA).then(done => {
|
|
|
75
100
|
// console.log(done);
|
|
76
101
|
return HelloWorld.question('/state')
|
|
77
102
|
}).then(answer => {
|
|
78
|
-
console.log(
|
|
103
|
+
console.log(answer.a.text);
|
|
104
|
+
console.log(answer.a.data);
|
|
79
105
|
});
|
|
80
106
|
|
|
81
107
|
|
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Distributed under the MIT software license, see the accompanying
|
|
3
3
|
// file LICENSE.md or http://www.opensource.org/licenses/mit-license.php.
|
|
4
4
|
const {EventEmitter} = require('events');
|
|
5
|
-
const { createHash, randomUUID } = require('crypto');
|
|
5
|
+
const { createHash, randomUUID, createCipheriv, createDecipheriv, randomBytes } = require('crypto');
|
|
6
6
|
|
|
7
7
|
class Deva {
|
|
8
8
|
constructor(opts) {
|
|
@@ -43,163 +43,225 @@ class Deva {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
set States(opts) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
46
|
+
console.log('CLIENT', this._client.profile.name);
|
|
47
|
+
const _states = {
|
|
48
|
+
uid: `๐ป ${this._agent.profile.name} is making a new #uid`,
|
|
49
|
+
offline: `๐ป ${this._agent.profile.name} is offline`,
|
|
50
|
+
online: `๐ก ${this._agent.profile.name} is online`,
|
|
51
|
+
config: `โ๐ ${this._agent.profile.name} is checking the config`,
|
|
52
|
+
client: `๐จโ๐ป ${this._agent.profile.name} opened the ${this._client.key} profile`,
|
|
53
|
+
agent: `๐จโ๐ป ${this._agent.profile.name} is looking at ${this._agent.key} profile`,
|
|
54
|
+
init: `๐ ${this._agent.profile.name} is initializing for ${this._client.profile.name}`,
|
|
55
|
+
start: `๐ฌ ${this._agent.profile.name} has started the process for ${this._client.profile.name}`,
|
|
56
|
+
enter: `๐ช ${this._agent.profile.name} is entering the deva.world with${this._client.profile.name}`,
|
|
57
|
+
stop: `๐ ${this._agent.profile.name} has stopped for ${this._client.profile.name}`,
|
|
58
|
+
exit: `๐ช ${this._agent.profile.name} found the exit with ${this._client.profile.name}`,
|
|
59
|
+
done: `๐ค ${this._agent.profile.name} is all done time for #offerings ๐ซ๐`,
|
|
60
|
+
wait: `๐ตโ๐ซ ${this._agent.profile.name} waiting for #stuff from ${this._client.profile.name}`,
|
|
61
|
+
data: `๐ ${this._agent.profile.name} is receiving #data for ${this._client.profile.name}`,
|
|
62
|
+
ask: `๐โโ๏ธ ${this._agent.profile.name} is asking a #question from ${this._client.profile.name}`,
|
|
63
|
+
cmd: `๐ ${this._agent.profile.name} entered a #command from ${this._client.profile.name}`,
|
|
64
|
+
question: `๐ต ${this._agent.profile.name} is in #question mode ${this._client.profile.name}`,
|
|
65
|
+
ask: `๐ต ${this._agent.profile.name} is in #ask mode ${this._client.profile.name}`,
|
|
66
|
+
talk: `๐๏ธ ${this._agent.profile.name} is in #talk mode with ${this._client.profile.name}`,
|
|
67
|
+
listen: `๐ง ${this._agent.profile.name} is in #listening mode with ${this._client.profile.name}`,
|
|
68
|
+
error: `โ ${this._agent.profile.name} had an error. Let's have @Systems look into that.`,
|
|
69
|
+
uid: `๐ชช ${this._client.profile.name} made a #uid with ${this._agent.profile.name}`,
|
|
70
|
+
hash: `๐ ${this._client.profile.name} made a #hash with ${this._agent.profile.name}`,
|
|
71
|
+
cipher: `๐ ${this._client.profile.name} locked a #cipher with ${this._agent.profile.name}`,
|
|
72
|
+
decipher: `๐ ${this._client.profile.name} unlocked a #cipher with ${this._agent.profile.name}`,
|
|
73
|
+
story: `๐ ${this._agent.profile.name} is creating an amazing #story ${this._client.profile.name}`,
|
|
74
|
+
development: `๐จโ๐ป ${this._agent.profile.name} called for @Development assistance for ${this._client.profile.name}`,
|
|
75
|
+
security: `๐จ ${this._agent.profile.name} called for @Security assistance for ${this._client.profile.name}`,
|
|
76
|
+
support: `๐๏ธ ${this._agent.profile.name} called for @Support assistance for ${this._client.profile.name}`,
|
|
77
|
+
services: `๐๏ธ ${this._agent.profile.name} called for @Services assistance for ${this._client.profile.name}`,
|
|
78
|
+
systems: `๐ฝ ${this._agent.profile.name} called for @Systems assistance for ${this._client.profile.name}`,
|
|
79
|
+
solutions: `๐ฌ ${this._agent.profile.name} called for @Solutions assistance for ${this._client.profile.name}`,
|
|
80
|
+
devas_start: `โจ Starting all the #Devas with ${this._client.profile.name}`,
|
|
81
|
+
devas_ready: `๐ธ The #Devas are #ready and #waiitng for ${this._client.profile.name}`,
|
|
82
|
+
devas_stop: `๐ The #Devas are #stopping with ${this._client.profile.name}`,
|
|
83
|
+
devas_stopped: `๐ #Devas and ${this._client.profile.name} have #stopped, and that means time for #offerings ๐๐๐๐ง`,
|
|
84
|
+
deva_load: `โ
${this._agent.profile.name} loading for ${this._client.profile.name}`,
|
|
85
|
+
deva_loaded: `โ
${this._agent.profile.name} loaded for ${this._client.profile.name}`,
|
|
86
|
+
deva_unloaded: `โ
${this._agent.profile.name} unloaded for ${this._client.profile.name}`,
|
|
87
|
+
question_me: `๐ต ${this._client.profile.name} started with a great #question to ${this._agent.profile.name}`,
|
|
88
|
+
question_default: `๐งโโ๏ธ ${this._client.profile.name} asked a great #question to ${this._agent.profile.name}`,
|
|
89
|
+
question_ask: `๐ง ${this._agent.profile.name} is pondering what ${this._client.profile.name} asked`,
|
|
90
|
+
question_asking: `๐ง ${this._agent.profile.name} is asking another #Deva for ${this._client.profile.name}`,
|
|
91
|
+
question_aswering: `๐ง ${this._agent.profile.name} is answering the #question ${this._client.profile.name} asked`,
|
|
92
|
+
question_answer: `๐ฎ ${this._client.profile.name} received an #ansewr from ${this._agent.profile.name}`,
|
|
93
|
+
question_command: `๐งโโ๏ธ ${this._client.profile.name} issued a #command to ${this._agent.profile.name}`,
|
|
94
|
+
hash_question: `๐ ${this._agent.profile.name} created the #question #hash for ${this._client.profile.name}`,
|
|
95
|
+
hash_ask: `๐ ${this._agent.profile.name} created the #ask #hash for ${this._client.profile.name}`,
|
|
96
|
+
hash_answer: `๐ ${this._agent.profile.name} #answer #hash with`,
|
|
97
|
+
hash_command: `๐ ${this._client.profile.name} #command #hash with ${this._agent.profile.name}`,
|
|
98
|
+
hash_packet: `๐ ${this._agent.profile.name} created the #packet #hash for ${this._client.profile.name}`,
|
|
99
|
+
ask_question: `๐ฝ ${this._client.profile.name} asked ${this._agent.profile.name} a great #question`,
|
|
100
|
+
ask_answer: `๐ธ ${this._client.profile.name} received a great #answer from ${this._agent.profile.name}`,
|
|
101
|
+
method_not_found: `๐ฉ ${this._client.profile.name} used a faulty #command while working with ${this._agent.profile.name}, and may need @Support`,
|
|
102
|
+
ready_security: `๐ @Security is ready`,
|
|
103
|
+
ready_support: `๐ @Support is ready`,
|
|
104
|
+
ready_support: `๐ @Support is ready`,
|
|
105
|
+
ready_services: `๐ @Services is ready`,
|
|
106
|
+
ready_systems: `๐๏ธ @Systems is ready`,
|
|
107
|
+
ready_solutions: `๐ค @Solutions is ready`,
|
|
108
|
+
alert_security: `๐จ #SECURITY ALERT`,
|
|
109
|
+
alert_support: `๐จ #SUPPORT ALERT`,
|
|
110
|
+
alert_services: `๐จ #SERVICES ALERT`,
|
|
111
|
+
alert_solutions: `๐จ #SOLUTIONS ALERT`,
|
|
112
|
+
alert_systems: `๐จ #SYSTEMS ALERT`,
|
|
113
|
+
alert_development: `๐จ #SYSTEMS ALERT`,
|
|
114
|
+
setting_client: `โ๏ธ ${this._agent.profile.name} is setting the #client for ${this._client.profile.name} `,
|
|
115
|
+
setting_development: `๐ฌ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Development`,
|
|
116
|
+
setting_security: `๐ฎโโ๏ธ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Security`,
|
|
117
|
+
setting_support: `๐จโโ๏ธ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Support`,
|
|
118
|
+
setting_services: `๐ทโโ๏ธ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Services`,
|
|
119
|
+
setting_systems: `๐๏ธ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Systems`,
|
|
120
|
+
setting_solutions: `๐ค ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Solutions`,
|
|
121
|
+
}
|
|
122
|
+
this._states = _states; // The available states to work with.
|
|
106
123
|
}
|
|
107
124
|
|
|
108
125
|
set Messages(opts) {
|
|
109
126
|
this._messages = {
|
|
110
|
-
offline: `๐
โโ๏ธ ${this._agent.name} offline`,
|
|
111
|
-
init: `โ ๏ธ ${this._agent.name} init`,
|
|
112
|
-
start: `โ
${this._agent.name} start`,
|
|
113
|
-
stop: `๐ฅ ${this._agent.name} stop.`,
|
|
114
|
-
enter: `๐ ${this._agent.name} enter.`,
|
|
115
|
-
exit: `๐ช ${this._agent.name} exit.`,
|
|
116
|
-
done: `๐ ${this._agent.name} done.`,
|
|
117
|
-
devas_started: '
|
|
127
|
+
offline: `๐
โโ๏ธ ${this._agent.profile.name} offline`,
|
|
128
|
+
init: `โ ๏ธ ${this._agent.profile.name} init`,
|
|
129
|
+
start: `โ
${this._agent.profile.name} start`,
|
|
130
|
+
stop: `๐ฅ ${this._agent.profile.name} stop.`,
|
|
131
|
+
enter: `๐ ${this._agent.profile.name} enter.`,
|
|
132
|
+
exit: `๐ช ${this._agent.profile.name} exit.`,
|
|
133
|
+
done: `๐ ${this._agent.profile.name} done.`,
|
|
134
|
+
devas_started: '#Devas are #online and ready for #offerings ๐ซ๐ฅ๐๐ฏ๐ง',
|
|
118
135
|
devas_stopped: '๐ #Devas have stopped',
|
|
119
|
-
notext: `โ ${this._client.name}, please provide with valid input.`,
|
|
120
|
-
method_not_found: `โ ${this._client.name} you sure messed that up!`,
|
|
136
|
+
notext: `โ ${this._client.profile.name}, please provide with valid input.`,
|
|
137
|
+
method_not_found: `โ ${this._client.profile.name} you sure messed that up!`,
|
|
121
138
|
}
|
|
122
139
|
}
|
|
123
|
-
set Client(
|
|
124
|
-
//
|
|
125
|
-
const _client = this.copy(
|
|
140
|
+
set Client(client) {
|
|
141
|
+
// copy the cl parameter into a local _client variable
|
|
142
|
+
const _client = this.copy(client);
|
|
143
|
+
|
|
144
|
+
// delete the keys used for other features.
|
|
126
145
|
if (_client.states) delete _client.states;
|
|
127
146
|
if (_client.messages) delete _client.messages;
|
|
147
|
+
if (_client.development) delete _client.development;
|
|
128
148
|
if (_client.security) delete _client.security;
|
|
129
149
|
if (_client.support) delete _client.support;
|
|
130
150
|
if (_client.services) delete _client.services;
|
|
151
|
+
if (_client.systems) delete _client.systems;
|
|
152
|
+
if (_client.solutions) delete _client.solutions;
|
|
131
153
|
|
|
132
|
-
|
|
154
|
+
// set the local client variable from the clean _client local variable.
|
|
155
|
+
this._client = _client;
|
|
133
156
|
|
|
134
|
-
|
|
135
|
-
this.
|
|
157
|
+
// set the states and messages after the cleint is set.
|
|
158
|
+
this.States = client.states;
|
|
159
|
+
this.Messages = client.messages;
|
|
136
160
|
}
|
|
137
161
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (!
|
|
162
|
+
// setup the @Security feature
|
|
163
|
+
set Security(client=false) {
|
|
164
|
+
if (!client) this._security = {};
|
|
141
165
|
else {
|
|
166
|
+
this.state('setting_security');
|
|
167
|
+
const _client = this.copy(client);
|
|
142
168
|
this._security = {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
169
|
+
id: this.uid(true),
|
|
170
|
+
client_id: _client.id,
|
|
171
|
+
client_name: _client.profile.name,
|
|
172
|
+
hash: _client.security.hash,
|
|
173
|
+
cipher: _client.security.cipher,
|
|
174
|
+
concerns: _client.security.concerns,
|
|
175
|
+
global: _client.security.global,
|
|
176
|
+
personal: _client.security.devas[this._agent.key]
|
|
146
177
|
};
|
|
147
178
|
}
|
|
148
179
|
}
|
|
149
180
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (!
|
|
181
|
+
// setup the @Support feature
|
|
182
|
+
set Support(client=false) {
|
|
183
|
+
if (!client) this._support = {};
|
|
153
184
|
else {
|
|
185
|
+
this.state('setting_support');
|
|
186
|
+
const _client = this.copy(client);
|
|
154
187
|
this._support = {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
188
|
+
id: this.uid(true),
|
|
189
|
+
client_id: _client.id,
|
|
190
|
+
client_name: _client.profile.name,
|
|
191
|
+
concerns: _client.support.concerns,
|
|
192
|
+
global: _client.support.global,
|
|
193
|
+
personal: _client.support.devas[this._agent.key]
|
|
158
194
|
};
|
|
159
195
|
}
|
|
160
196
|
}
|
|
161
197
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (!
|
|
198
|
+
// setup the @Services feature
|
|
199
|
+
set Services(client=false) {
|
|
200
|
+
if (!client) this._servcies = {};
|
|
165
201
|
else {
|
|
202
|
+
this.state('setting_services');
|
|
203
|
+
const _client = this.copy(client);
|
|
166
204
|
this._services = {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
205
|
+
id: this.uid(true),
|
|
206
|
+
client_id: _client.id,
|
|
207
|
+
client_name: _client.profile.name,
|
|
208
|
+
concerns: _client.services.concerns,
|
|
209
|
+
global: _client.services.global,
|
|
210
|
+
personal: _client.services.devas[this._agent.key]
|
|
170
211
|
};
|
|
171
212
|
}
|
|
172
213
|
}
|
|
173
214
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
data,
|
|
190
|
-
created: Date.now(),
|
|
191
|
-
};
|
|
192
|
-
this.prompt(this._state);
|
|
193
|
-
this.talk(`${this._agent.key}:state`, _data);
|
|
194
|
-
return this._state;
|
|
215
|
+
// setup the @Systems feature
|
|
216
|
+
set Systems(client=false) {
|
|
217
|
+
if (!client) this._systems = {};
|
|
218
|
+
else {
|
|
219
|
+
this.state('setting_systems');
|
|
220
|
+
const _client = this.copy(client);
|
|
221
|
+
this._systems = {
|
|
222
|
+
id: this.uid(true),
|
|
223
|
+
client_id: _client.id,
|
|
224
|
+
client_name: _client.profile.name,
|
|
225
|
+
concerns: _client.systems.concerns,
|
|
226
|
+
global: _client.systems.global,
|
|
227
|
+
personal: _client.systems.devas[this._agent.key]
|
|
228
|
+
};
|
|
229
|
+
}
|
|
195
230
|
}
|
|
196
231
|
|
|
197
|
-
|
|
198
|
-
|
|
232
|
+
// setup the @Solutions feature
|
|
233
|
+
set Solutions(client=false) {
|
|
234
|
+
if (!client) this._solutions = {};
|
|
235
|
+
else {
|
|
236
|
+
this.state('setting_solutions');
|
|
237
|
+
const _client = this.copy(client);
|
|
238
|
+
this._solutions = {
|
|
239
|
+
id: this.uid(true),
|
|
240
|
+
client_id: _client.id,
|
|
241
|
+
client_name: _client.profile.name,
|
|
242
|
+
concerns: _client.solutions.concerns,
|
|
243
|
+
global: _client.solutions.global,
|
|
244
|
+
personal: _client.solutions.devas[this._agent.key]
|
|
245
|
+
};
|
|
246
|
+
}
|
|
199
247
|
}
|
|
200
248
|
|
|
201
|
-
//
|
|
202
|
-
|
|
249
|
+
// setup the @Development feature.
|
|
250
|
+
set Development(client=false) {
|
|
251
|
+
if (!client) this._development = {};
|
|
252
|
+
else {
|
|
253
|
+
this.state('setting_development');
|
|
254
|
+
const _client = this.copy(client);
|
|
255
|
+
this._development = {
|
|
256
|
+
id: this.uid(true),
|
|
257
|
+
client_id: _client.id,
|
|
258
|
+
client_name: _client.profile.name,
|
|
259
|
+
concerns: _client.development.concerns,
|
|
260
|
+
global: _client.development.global,
|
|
261
|
+
personal: _client.development.devas[this._agent.key]
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
}
|
|
203
265
|
|
|
204
266
|
/**************
|
|
205
267
|
func: _assignBind
|
|
@@ -326,6 +388,38 @@ class Deva {
|
|
|
326
388
|
return packet;
|
|
327
389
|
}
|
|
328
390
|
|
|
391
|
+
/**************
|
|
392
|
+
func: states
|
|
393
|
+
params: none
|
|
394
|
+
describe: returns the avaiable staets values.
|
|
395
|
+
***************/
|
|
396
|
+
states() {
|
|
397
|
+
return this._states;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**************
|
|
401
|
+
func: state
|
|
402
|
+
params:
|
|
403
|
+
- st: The state flag to set for the Deva that matches to this._states
|
|
404
|
+
describe
|
|
405
|
+
***************/
|
|
406
|
+
state(st, data=false) {
|
|
407
|
+
if (!Object.keys(this._states).includes(st)) return;
|
|
408
|
+
this._state = `${this._states[st]} on ${this.formatDate(Date.now(), 'short_month', true)}`;
|
|
409
|
+
const _data = {
|
|
410
|
+
id: this.uid(true),
|
|
411
|
+
client: this._client.id,
|
|
412
|
+
agent: this._agent.id,
|
|
413
|
+
st: st,
|
|
414
|
+
state: this._state,
|
|
415
|
+
data,
|
|
416
|
+
created: Date.now(),
|
|
417
|
+
};
|
|
418
|
+
this.prompt(this._state);
|
|
419
|
+
this.talk(`${this._agent.key}:state`, _data);
|
|
420
|
+
return this._state;
|
|
421
|
+
}
|
|
422
|
+
|
|
329
423
|
/**************
|
|
330
424
|
func: uid
|
|
331
425
|
params:
|
|
@@ -339,12 +433,90 @@ class Deva {
|
|
|
339
433
|
is shared.
|
|
340
434
|
***************/
|
|
341
435
|
uid(guid=false) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
436
|
+
let id;
|
|
437
|
+
if (guid) {
|
|
438
|
+
id = randomUUID()
|
|
439
|
+
}
|
|
440
|
+
else {
|
|
441
|
+
const min = Math.floor(Date.now() - (Date.now() / Math.PI));
|
|
442
|
+
const max = Math.floor(Date.now() + (Date.now() * Math.PI));
|
|
443
|
+
id = Math.floor(Math.random() * (max - min)) + min;
|
|
444
|
+
}
|
|
445
|
+
return id;
|
|
346
446
|
}
|
|
347
447
|
|
|
448
|
+
/**************
|
|
449
|
+
func: hash
|
|
450
|
+
params:
|
|
451
|
+
- texts: The text string to create a hash value for.
|
|
452
|
+
- algo: The hashing algorithm to use for hashing. md5, sha256, or sha512
|
|
453
|
+
|
|
454
|
+
describe:
|
|
455
|
+
The hash algorithm will take a string of text and produce a hash.
|
|
456
|
+
***************/
|
|
457
|
+
hash(str) {
|
|
458
|
+
const algo = this._security.hash || 'md5';
|
|
459
|
+
const the_hash = createHash(algo);
|
|
460
|
+
the_hash.update(str);
|
|
461
|
+
const _digest = the_hash.digest('base64');
|
|
462
|
+
this.state('hash', {
|
|
463
|
+
|
|
464
|
+
})
|
|
465
|
+
return ;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**************
|
|
469
|
+
func: cipher
|
|
470
|
+
params: str - string to encrypt
|
|
471
|
+
describe:
|
|
472
|
+
The encrypt function allows for the internal encryption of data based on the
|
|
473
|
+
defined client security settings.
|
|
474
|
+
***************/
|
|
475
|
+
cipher(str) {
|
|
476
|
+
const security = this._security;
|
|
477
|
+
const {password, algorithm} = security.cipher;
|
|
478
|
+
const key = createHash('sha256').update(String(password)).digest('base64');
|
|
479
|
+
const key_in_bytes = Buffer.from(key, 'base64')
|
|
480
|
+
const iv = randomBytes(16);
|
|
481
|
+
|
|
482
|
+
// create a new cipher
|
|
483
|
+
const _cipher = createCipheriv(algorithm, key_in_bytes, iv);
|
|
484
|
+
const encrypted = _cipher.update(String(str), 'utf8', 'hex') + _cipher.final('hex');
|
|
485
|
+
|
|
486
|
+
this.state('cipher', {
|
|
487
|
+
id: this.uid(true),
|
|
488
|
+
iv,
|
|
489
|
+
key,
|
|
490
|
+
agent_id: this._agent.id,
|
|
491
|
+
client_id: this._client.id,
|
|
492
|
+
created: Date.now()
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
return {
|
|
496
|
+
iv: iv.toString('base64'),
|
|
497
|
+
key,
|
|
498
|
+
encrypted,
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
decipher(opt) {
|
|
502
|
+
const iv = Buffer.from(opt.iv, 'base64');
|
|
503
|
+
const encrypted = Buffer.from(opt.encrypted, 'hex');
|
|
504
|
+
const key_in_bytes = Buffer.from(opt.key, 'base64')
|
|
505
|
+
const security = this._security;
|
|
506
|
+
const {algorithm} = security.cipher;
|
|
507
|
+
const decipher = createDecipheriv( algorithm, key_in_bytes, iv);
|
|
508
|
+
const decrypted = decipher.update(encrypted);
|
|
509
|
+
const final = Buffer.concat([decrypted, decipher.final()]);
|
|
510
|
+
this.state('decipher', {
|
|
511
|
+
id: this.uid(true),
|
|
512
|
+
iv: opt.iv,
|
|
513
|
+
key: opt.key,
|
|
514
|
+
agent_id: this._agent.id,
|
|
515
|
+
client_id: this._client.id,
|
|
516
|
+
created: Date.now()
|
|
517
|
+
});
|
|
518
|
+
return final.toString();
|
|
519
|
+
}
|
|
348
520
|
|
|
349
521
|
/**************
|
|
350
522
|
func: copy
|
|
@@ -554,15 +726,18 @@ class Deva {
|
|
|
554
726
|
try {
|
|
555
727
|
if (!this._active) return reject(this._messages.offline);
|
|
556
728
|
|
|
729
|
+
let _state = 'question_default';
|
|
730
|
+
let _hash = 'hash_asnwer';
|
|
731
|
+
|
|
557
732
|
// *: send just a string of text
|
|
558
733
|
// !: send a command to the local agent
|
|
559
734
|
// #: ask another agent a question
|
|
560
735
|
// #agent method:param1:param2 with text strings for proccessing
|
|
561
736
|
// !method param:list:parse for the local agent
|
|
562
737
|
// if is an ask then we format one way
|
|
563
|
-
let _state = 'question_default';
|
|
564
738
|
if (isAsk) {
|
|
565
739
|
_state = 'question_ask'
|
|
740
|
+
_state = 'hash_ask'
|
|
566
741
|
key = t_split[0].substring(1);
|
|
567
742
|
params = t_split[1] ? t_split[1].split(':') : false;
|
|
568
743
|
method = params[0];
|
|
@@ -570,7 +745,8 @@ class Deva {
|
|
|
570
745
|
|
|
571
746
|
}
|
|
572
747
|
else if (isCmd) {
|
|
573
|
-
_state = '
|
|
748
|
+
_state = 'question_command';
|
|
749
|
+
_hash = 'hash_command'
|
|
574
750
|
params = t_split[1] ? t_split[1].split(':') : false;
|
|
575
751
|
method = t_split[0].substring(1);
|
|
576
752
|
text = t_split.slice(1).join(' ').trim()
|
|
@@ -599,7 +775,6 @@ class Deva {
|
|
|
599
775
|
// If a question to another Deva with '#' then trigger events
|
|
600
776
|
if (isAsk) {
|
|
601
777
|
this.state('question_asking');
|
|
602
|
-
this.prompt(`sending key ${key}`);
|
|
603
778
|
this.talk(`${key}:ask`, packet);
|
|
604
779
|
this.once(`${key}:ask:${packet.id}`, answer => {
|
|
605
780
|
return resolve(answer);
|
|
@@ -629,7 +804,7 @@ class Deva {
|
|
|
629
804
|
created: Date.now(),
|
|
630
805
|
};
|
|
631
806
|
// create a hash for the answer and insert into answer meta.
|
|
632
|
-
this.state(
|
|
807
|
+
this.state(_hash);
|
|
633
808
|
packet.a.meta.hash = this.hash(JSON.stringify(packet.a));
|
|
634
809
|
|
|
635
810
|
// create a hash for entire packet and insert into packet
|
|
@@ -679,9 +854,12 @@ class Deva {
|
|
|
679
854
|
}).then(() => {
|
|
680
855
|
this.state('init');
|
|
681
856
|
|
|
682
|
-
this.Security = client
|
|
683
|
-
this.Support = client
|
|
684
|
-
this.Services = client
|
|
857
|
+
this.Security = client;
|
|
858
|
+
this.Support = client;
|
|
859
|
+
this.Services = client;
|
|
860
|
+
this.Systems = client;
|
|
861
|
+
this.Solutions = client;
|
|
862
|
+
this.Development = client;
|
|
685
863
|
|
|
686
864
|
return this.onInit && typeof this.onInit === 'function' ? this.onInit() : this.start();
|
|
687
865
|
}).then(started => {
|
|
@@ -799,7 +977,7 @@ class Deva {
|
|
|
799
977
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
800
978
|
const id = this.uid();
|
|
801
979
|
const dateFormat = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'medium' }).format(this._active);
|
|
802
|
-
let text = `${this._agent.name} active since ${dateFormat}`;
|
|
980
|
+
let text = `${this._agent.profile.name} active since ${dateFormat}`;
|
|
803
981
|
if (ammend) text = text + `\n${ammend}`;
|
|
804
982
|
return Promise.resolve({text});
|
|
805
983
|
}
|
|
@@ -815,21 +993,6 @@ class Deva {
|
|
|
815
993
|
return this.talk('prompt', {text, agent:this._agent});
|
|
816
994
|
}
|
|
817
995
|
|
|
818
|
-
/**************
|
|
819
|
-
func: hash
|
|
820
|
-
params:
|
|
821
|
-
- texts: The text string to create a hash value for.
|
|
822
|
-
- algo: The hashing algorithm to use for hashing. md5, sha256, or sha512
|
|
823
|
-
|
|
824
|
-
describe:
|
|
825
|
-
The hash algorithm will take a string of text and produce a hash.
|
|
826
|
-
***************/
|
|
827
|
-
hash(text, algo='md5') {
|
|
828
|
-
const the_hash = createHash(algo);
|
|
829
|
-
the_hash.update(text);
|
|
830
|
-
return the_hash.digest('hex');
|
|
831
|
-
}
|
|
832
|
-
|
|
833
996
|
/**************
|
|
834
997
|
func: client
|
|
835
998
|
params: none
|
|
@@ -838,7 +1001,7 @@ class Deva {
|
|
|
838
1001
|
being accessed.
|
|
839
1002
|
***************/
|
|
840
1003
|
client() {
|
|
841
|
-
if (!this._active) return
|
|
1004
|
+
if (!this._active) return this._messages.offline;
|
|
842
1005
|
this.state('client');
|
|
843
1006
|
return this._client;
|
|
844
1007
|
}
|
|
@@ -851,7 +1014,7 @@ class Deva {
|
|
|
851
1014
|
being accessed.
|
|
852
1015
|
***************/
|
|
853
1016
|
agent() {
|
|
854
|
-
if (!this._active) return
|
|
1017
|
+
if (!this._active) return this._messages.offline;
|
|
855
1018
|
this.state('agent');
|
|
856
1019
|
return this._agent;
|
|
857
1020
|
}
|
|
@@ -861,21 +1024,66 @@ class Deva {
|
|
|
861
1024
|
params: opts
|
|
862
1025
|
describe: basic security features available in a Deva.
|
|
863
1026
|
***************/
|
|
864
|
-
security(opts) {
|
|
1027
|
+
security(opts) {
|
|
1028
|
+
if (!this._active) return this._messages.offline;
|
|
1029
|
+
this.state('security');
|
|
1030
|
+
return this._security;
|
|
1031
|
+
}
|
|
865
1032
|
|
|
866
1033
|
/**************
|
|
867
1034
|
func: security
|
|
868
1035
|
params: opts
|
|
869
1036
|
describe: basic support features available in a Deva.
|
|
870
1037
|
***************/
|
|
871
|
-
support(opts) {
|
|
1038
|
+
support(opts) {
|
|
1039
|
+
if (!this._active) return this._messages.offline;
|
|
1040
|
+
this.state('support');
|
|
1041
|
+
return this._support;
|
|
1042
|
+
}
|
|
872
1043
|
|
|
873
1044
|
/**************
|
|
874
1045
|
func: security
|
|
875
1046
|
params: opts
|
|
876
1047
|
describe: basic services features available in a Deva.
|
|
877
1048
|
***************/
|
|
878
|
-
services(opts) {
|
|
1049
|
+
services(opts) {
|
|
1050
|
+
if (!this._active) return this._messages.offline;
|
|
1051
|
+
this.state('services');
|
|
1052
|
+
return this._services;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/**************
|
|
1056
|
+
func: systems
|
|
1057
|
+
params: opts
|
|
1058
|
+
describe: basic systems features available in a Deva.
|
|
1059
|
+
***************/
|
|
1060
|
+
systems(opts) {
|
|
1061
|
+
if (!this._active) return this._messages.offline;
|
|
1062
|
+
this.state('systems');
|
|
1063
|
+
return this._systems;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
/**************
|
|
1067
|
+
func: security
|
|
1068
|
+
params: opts
|
|
1069
|
+
describe: basic solutions features available in a Deva.
|
|
1070
|
+
***************/
|
|
1071
|
+
solutions(opts) {
|
|
1072
|
+
if (!this._active) return this._messages.offline;
|
|
1073
|
+
this.state('solutions');
|
|
1074
|
+
return this._solutions;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
/**************
|
|
1078
|
+
func: development
|
|
1079
|
+
params: opts
|
|
1080
|
+
describe: basic development features available in a Deva.
|
|
1081
|
+
***************/
|
|
1082
|
+
development(opts) {
|
|
1083
|
+
if (!this._active) return this._messages.offline;
|
|
1084
|
+
this.state('development');
|
|
1085
|
+
return this._development;
|
|
1086
|
+
}
|
|
879
1087
|
|
|
880
1088
|
/**************
|
|
881
1089
|
func: startDevas
|
|
@@ -915,5 +1123,73 @@ class Deva {
|
|
|
915
1123
|
}).catch(reject);
|
|
916
1124
|
});
|
|
917
1125
|
}
|
|
1126
|
+
|
|
1127
|
+
// UTILITY FUNCTIONS
|
|
1128
|
+
/**************
|
|
1129
|
+
func: formatDate
|
|
1130
|
+
params:
|
|
1131
|
+
- d: The date string to format.
|
|
1132
|
+
- format: the various formats that can be selected.
|
|
1133
|
+
- time: boolean flag to include the time stampt iwth the date.
|
|
1134
|
+
- locale: The locale formatting of the date to return.
|
|
1135
|
+
describe:
|
|
1136
|
+
formats: long, long_month, short, short_month, year, month, day
|
|
1137
|
+
FDate format ensures that consistent date formatting is used within the
|
|
1138
|
+
system based on the language and locale in the client profile.
|
|
1139
|
+
***************/
|
|
1140
|
+
formatDate(d, format='long', time=false) {
|
|
1141
|
+
if (!d) d = Date.now();
|
|
1142
|
+
d = new Date(d);
|
|
1143
|
+
|
|
1144
|
+
const formats = {
|
|
1145
|
+
long: { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' },
|
|
1146
|
+
long_month: { year: 'numeric', month: 'long', day: 'numeric'},
|
|
1147
|
+
short: { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric' },
|
|
1148
|
+
short_month: { year: 'numeric', month: 'short', day: 'numeric' },
|
|
1149
|
+
year: { year: 'numeric' },
|
|
1150
|
+
month: { month: 'long' },
|
|
1151
|
+
day: { day: 'long' },
|
|
1152
|
+
log: { year: 'numeric', month: 'short', day: 'numeric' },
|
|
1153
|
+
};
|
|
1154
|
+
const theDate = d.toLocaleDateString(this._client.locale, formats[format]);
|
|
1155
|
+
const theTime = this.formatTime(d);
|
|
1156
|
+
return !theTime ? theDate : `${theDate} - ${theTime}`;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
/**************
|
|
1160
|
+
func: formatTime
|
|
1161
|
+
params:
|
|
1162
|
+
- t: the time to format
|
|
1163
|
+
describe:
|
|
1164
|
+
The formatTime fucntion will return a consistent local time for the t
|
|
1165
|
+
parameter based on the locale setting in the client profile..
|
|
1166
|
+
***************/
|
|
1167
|
+
formatTime(t) {
|
|
1168
|
+
return t.toLocaleTimeString(this._client.locale);
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
/**************
|
|
1172
|
+
func: formatCurrency
|
|
1173
|
+
params:
|
|
1174
|
+
- n: is the number that you want to return the currency of.
|
|
1175
|
+
describe:
|
|
1176
|
+
The formatCurrency function will format a currency value based on the setting
|
|
1177
|
+
in the client profile.
|
|
1178
|
+
***************/
|
|
1179
|
+
formatCurrency(n) {
|
|
1180
|
+
return new Intl.NumberFormat(this._client.locale, { style: 'currency', currency: this._client.currency }).format(n);
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
/**************
|
|
1184
|
+
func: formatPerdent
|
|
1185
|
+
params:
|
|
1186
|
+
- n: is the number that you want to format as a percent.
|
|
1187
|
+
- dec: is the number of decimal places to apply to the number.
|
|
1188
|
+
describe:
|
|
1189
|
+
***************/
|
|
1190
|
+
formatPerdent(n, dec=2) {
|
|
1191
|
+
return parseFloat(n).toFixed(dec) + '%';
|
|
1192
|
+
}
|
|
1193
|
+
|
|
918
1194
|
}
|
|
919
1195
|
module.exports = Deva;
|