@indra.ai/deva 1.1.27 โ 1.1.29
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 +27 -11
- package/examples/hello-world.js +30 -5
- package/index.js +282 -183
- 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,11 +22,12 @@
|
|
|
25
22
|
}
|
|
26
23
|
},
|
|
27
24
|
"profile": {
|
|
25
|
+
"name": "Test User",
|
|
26
|
+
"eamil": "test@example.com",
|
|
27
|
+
"describe": "The Test User",
|
|
28
28
|
"emoji": "/public/devas/test/avatar.png",
|
|
29
29
|
"avatar": "/public/devas/test/avatar.png",
|
|
30
30
|
"background": "/public/devas/test/background.png",
|
|
31
|
-
"name": "Test User",
|
|
32
|
-
"describe": "This is the Test for the Deva Examples in the Repository.",
|
|
33
31
|
"gender": "splendid",
|
|
34
32
|
"lang": "en",
|
|
35
33
|
"locale": "en-US",
|
|
@@ -38,14 +36,24 @@
|
|
|
38
36
|
"states": {},
|
|
39
37
|
"messages": {},
|
|
40
38
|
"security": {
|
|
39
|
+
"hash": "md5",
|
|
40
|
+
"cipher": {
|
|
41
|
+
"encrypt": true,
|
|
42
|
+
"algorithm": "aes-256-cbc",
|
|
43
|
+
"password": "generic password for encryption test"
|
|
44
|
+
},
|
|
41
45
|
"concerns": [],
|
|
42
46
|
"global": {},
|
|
43
|
-
"devas": {
|
|
47
|
+
"devas": {
|
|
48
|
+
"hello": {}
|
|
49
|
+
}
|
|
44
50
|
},
|
|
45
51
|
"support": {
|
|
46
52
|
"concerns": [],
|
|
47
53
|
"global": {},
|
|
48
|
-
"devas": {
|
|
54
|
+
"devas": {
|
|
55
|
+
"hello": {}
|
|
56
|
+
}
|
|
49
57
|
},
|
|
50
58
|
"services": {
|
|
51
59
|
"concerns": [],
|
|
@@ -55,22 +63,30 @@
|
|
|
55
63
|
"space": "https://deva.space",
|
|
56
64
|
"cloud": "https://deva.cloud"
|
|
57
65
|
},
|
|
58
|
-
"devas": {
|
|
66
|
+
"devas": {
|
|
67
|
+
"hello": {}
|
|
68
|
+
}
|
|
59
69
|
},
|
|
60
70
|
"systems": {
|
|
61
71
|
"concerns": [],
|
|
62
72
|
"global": {},
|
|
63
|
-
"devas": {
|
|
73
|
+
"devas": {
|
|
74
|
+
"hello": {}
|
|
75
|
+
}
|
|
64
76
|
},
|
|
65
77
|
"solutions": {
|
|
66
78
|
"concerns": [],
|
|
67
79
|
"global": {},
|
|
68
|
-
"devas": {
|
|
80
|
+
"devas": {
|
|
81
|
+
"hello": {}
|
|
82
|
+
}
|
|
69
83
|
},
|
|
70
84
|
"development": {
|
|
71
85
|
"concerns": [],
|
|
72
86
|
"global": {},
|
|
73
|
-
"devas": {
|
|
87
|
+
"devas": {
|
|
88
|
+
"hello": {}
|
|
89
|
+
}
|
|
74
90
|
}
|
|
75
91
|
}
|
|
76
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,8 +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(HelloWorld.client());
|
|
79
103
|
console.log(answer.a.text);
|
|
104
|
+
console.log(answer.a.data);
|
|
80
105
|
});
|
|
81
106
|
|
|
82
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,94 +43,102 @@ class Deva {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
set States(opts) {
|
|
46
|
-
|
|
47
|
-
uid: `๐ป ${this._agent.name} is making a new #uid`,
|
|
48
|
-
offline: `๐ป ${this._agent.name} is offline`,
|
|
49
|
-
online: `๐ก ${this._agent.name} is online`,
|
|
50
|
-
config: `โ๐ ${this._agent.name} is checking the config`,
|
|
51
|
-
client: `๐จโ๐ป ${this._agent.name} opened the ${this._client.key} profile`,
|
|
52
|
-
agent: `๐จโ๐ป ${this._agent.name} is looking at ${this._agent.key} profile`,
|
|
53
|
-
init: `๐ ${this._agent.name} is initializing`,
|
|
54
|
-
start: `๐ฌ ${this._agent.name} has started the process`,
|
|
55
|
-
enter: `๐ช ${this._agent.name} is entering the deva.world`,
|
|
56
|
-
stop: `๐ ${this._agent.name} has stopped`,
|
|
57
|
-
exit: `๐ช ${this._agent.name} found the exit`,
|
|
58
|
-
done: `๐ค ${this._agent.name} is all done time for #offerings ๐ซ๐`,
|
|
59
|
-
wait: `๐ตโ๐ซ ${this._agent.name} waiting for #stuff`,
|
|
60
|
-
data: `๐ ${this._agent.name} is receiving #data`,
|
|
61
|
-
ask: `๐โโ๏ธ ${this._agent.name} is asking a #question`,
|
|
62
|
-
cmd: `๐ ${this._agent.name}
|
|
63
|
-
question: `๐ต ${this._agent.name} is in #question mode`,
|
|
64
|
-
ask: `๐ต ${this._agent.name} is in #ask mode`,
|
|
65
|
-
talk: `๐๏ธ ${this._agent.name} is in #talk mode`,
|
|
66
|
-
listen: `๐ง ${this._agent.name} is in #listening mode`,
|
|
67
|
-
error: `โ
|
|
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
|
-
|
|
46
|
+
const _states = {
|
|
47
|
+
uid: `๐ป ${this._agent.profile.name} is making a new #uid`,
|
|
48
|
+
offline: `๐ป ${this._agent.profile.name} is offline`,
|
|
49
|
+
online: `๐ก ${this._agent.profile.name} is online`,
|
|
50
|
+
config: `โ๐ ${this._agent.profile.name} is checking the config`,
|
|
51
|
+
client: `๐จโ๐ป ${this._agent.profile.name} opened the ${this._client.key} profile`,
|
|
52
|
+
agent: `๐จโ๐ป ${this._agent.profile.name} is looking at ${this._agent.key} profile`,
|
|
53
|
+
init: `๐ ${this._agent.profile.name} is initializing for ${this._client.profile.name}`,
|
|
54
|
+
start: `๐ฌ ${this._agent.profile.name} has started the process for ${this._client.profile.name}`,
|
|
55
|
+
enter: `๐ช ${this._agent.profile.name} is entering the deva.world with${this._client.profile.name}`,
|
|
56
|
+
stop: `๐ ${this._agent.profile.name} has stopped for ${this._client.profile.name}`,
|
|
57
|
+
exit: `๐ช ${this._agent.profile.name} found the exit with ${this._client.profile.name}`,
|
|
58
|
+
done: `๐ค ${this._agent.profile.name} is all done time for #offerings ๐ซ๐`,
|
|
59
|
+
wait: `๐ตโ๐ซ ${this._agent.profile.name} waiting for #stuff from ${this._client.profile.name}`,
|
|
60
|
+
data: `๐ ${this._agent.profile.name} is receiving #data for ${this._client.profile.name}`,
|
|
61
|
+
ask: `๐โโ๏ธ ${this._agent.profile.name} is asking a #question from ${this._client.profile.name}`,
|
|
62
|
+
cmd: `๐ ${this._agent.profile.name} entered a #command from ${this._client.profile.name}`,
|
|
63
|
+
question: `๐ต ${this._agent.profile.name} is in #question mode ${this._client.profile.name}`,
|
|
64
|
+
ask: `๐ต ${this._agent.profile.name} is in #ask mode ${this._client.profile.name}`,
|
|
65
|
+
talk: `๐๏ธ ${this._agent.profile.name} is in #talk mode with ${this._client.profile.name}`,
|
|
66
|
+
listen: `๐ง ${this._agent.profile.name} is in #listening mode with ${this._client.profile.name}`,
|
|
67
|
+
error: `โ ${this._agent.profile.name} had an error. Let's have @Systems look into that.`,
|
|
68
|
+
uid: `๐ชช ${this._client.profile.name} made a #uid with ${this._agent.profile.name}`,
|
|
69
|
+
hash: `๐ ${this._client.profile.name} made a #hash with ${this._agent.profile.name}`,
|
|
70
|
+
cipher: `๐ ${this._client.profile.name} locked a #cipher with ${this._agent.profile.name}`,
|
|
71
|
+
decipher: `๐ ${this._client.profile.name} unlocked a #cipher with ${this._agent.profile.name}`,
|
|
72
|
+
story: `๐ ${this._agent.profile.name} is creating an amazing #story ${this._client.profile.name}`,
|
|
73
|
+
development: `๐จโ๐ป ${this._agent.profile.name} called for @Development assistance for ${this._client.profile.name}`,
|
|
74
|
+
security: `๐จ ${this._agent.profile.name} called for @Security assistance for ${this._client.profile.name}`,
|
|
75
|
+
support: `๐๏ธ ${this._agent.profile.name} called for @Support assistance for ${this._client.profile.name}`,
|
|
76
|
+
services: `๐๏ธ ${this._agent.profile.name} called for @Services assistance for ${this._client.profile.name}`,
|
|
77
|
+
systems: `๐ฝ ${this._agent.profile.name} called for @Systems assistance for ${this._client.profile.name}`,
|
|
78
|
+
solutions: `๐ฌ ${this._agent.profile.name} called for @Solutions assistance for ${this._client.profile.name}`,
|
|
79
|
+
devas_start: `โจ Starting all the #Devas with ${this._client.profile.name}`,
|
|
80
|
+
devas_ready: `๐ธ The #Devas are #ready and #waiitng for ${this._client.profile.name}`,
|
|
81
|
+
devas_stop: `๐ The #Devas are #stopping with ${this._client.profile.name}`,
|
|
82
|
+
devas_stopped: `๐ #Devas and ${this._client.profile.name} have #stopped, and that means time for #offerings ๐๐๐๐ง`,
|
|
83
|
+
deva_load: `โ
${this._agent.profile.name} loading for ${this._client.profile.name}`,
|
|
84
|
+
deva_loaded: `โ
${this._agent.profile.name} loaded for ${this._client.profile.name}`,
|
|
85
|
+
deva_unloaded: `โ
${this._agent.profile.name} unloaded for ${this._client.profile.name}`,
|
|
86
|
+
question_me: `๐ต ${this._client.profile.name} started with a great #question to ${this._agent.profile.name}`,
|
|
87
|
+
question_default: `๐งโโ๏ธ ${this._client.profile.name} asked a great #question to ${this._agent.profile.name}`,
|
|
88
|
+
question_ask: `๐ง ${this._agent.profile.name} is pondering what ${this._client.profile.name} asked`,
|
|
89
|
+
question_asking: `๐ง ${this._agent.profile.name} is asking another #Deva for ${this._client.profile.name}`,
|
|
90
|
+
question_aswering: `๐ง ${this._agent.profile.name} is answering the #question ${this._client.profile.name} asked`,
|
|
91
|
+
question_answer: `๐ฎ ${this._client.profile.name} received an #ansewr from ${this._agent.profile.name}`,
|
|
92
|
+
question_command: `๐งโโ๏ธ ${this._client.profile.name} issued a #command to ${this._agent.profile.name}`,
|
|
93
|
+
hash_question: `๐ ${this._agent.profile.name} created the #question #hash for ${this._client.profile.name}`,
|
|
94
|
+
hash_ask: `๐ ${this._agent.profile.name} created the #ask #hash for ${this._client.profile.name}`,
|
|
95
|
+
hash_answer: `๐ ${this._client.profile.name} #answer #hash with`,
|
|
96
|
+
hash_command: `๐ ${this._client.profile.name} #command #hash with ${this._agent.profile.name}`,
|
|
97
|
+
hash_packet: `๐ ${this._agent.profile.name} created the #packet #hash for ${this._client.profile.name}`,
|
|
98
|
+
ask_question: `๐ฝ ${this._client.profile.name} asked ${this._agent.profile.name} a great #question`,
|
|
99
|
+
ask_answer: `๐ธ ${this._client.profile.name} received a great #answer from ${this._agent.profile.name}`,
|
|
100
|
+
method_not_found: `๐ฉ ${this._client.profile.name} used a faulty #command while working with ${this._agent.profile.name}, and may need @Support`,
|
|
101
|
+
ready_security: `๐ @Security is ready`,
|
|
102
|
+
ready_support: `๐ @Support is ready`,
|
|
103
|
+
ready_support: `๐ @Support is ready`,
|
|
104
|
+
ready_services: `๐ @Services is ready`,
|
|
105
|
+
ready_systems: `๐๏ธ @Systems is ready`,
|
|
106
|
+
ready_solutions: `๐ค @Solutions is ready`,
|
|
100
107
|
alert_security: `๐จ #SECURITY ALERT`,
|
|
101
108
|
alert_support: `๐จ #SUPPORT ALERT`,
|
|
102
109
|
alert_services: `๐จ #SERVICES ALERT`,
|
|
103
110
|
alert_solutions: `๐จ #SOLUTIONS ALERT`,
|
|
104
111
|
alert_systems: `๐จ #SYSTEMS ALERT`,
|
|
105
112
|
alert_development: `๐จ #SYSTEMS ALERT`,
|
|
106
|
-
setting_client: `โ๏ธ
|
|
107
|
-
setting_development: `๐ฌ ${this._agent.name} receiving @Development`,
|
|
108
|
-
setting_security: `๐ฎโโ๏ธ ${this._agent.name} receiving @Security`,
|
|
109
|
-
setting_support: `๐จโโ๏ธ ${this._agent.name} receiving @Support`,
|
|
110
|
-
setting_services: `๐ทโโ๏ธ ${this._agent.name} receiving @Services`,
|
|
111
|
-
setting_systems: `๐๏ธ ${this._agent.name} receiving @Systems`,
|
|
112
|
-
setting_solutions: `๐ค ${this._agent.name} receiving @Solutions`,
|
|
113
|
-
}
|
|
113
|
+
setting_client: `โ๏ธ ${this._agent.profile.name} is setting the #client for ${this._client.profile.name} `,
|
|
114
|
+
setting_development: `๐ฌ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Development`,
|
|
115
|
+
setting_security: `๐ฎโโ๏ธ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Security`,
|
|
116
|
+
setting_support: `๐จโโ๏ธ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Support`,
|
|
117
|
+
setting_services: `๐ทโโ๏ธ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Services`,
|
|
118
|
+
setting_systems: `๐๏ธ ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Systems`,
|
|
119
|
+
setting_solutions: `๐ค ${this._client.profile.name} and ${this._agent.profile.name} are receiving @Solutions`,
|
|
120
|
+
}
|
|
121
|
+
this._states = _states; // The available states to work with.
|
|
114
122
|
}
|
|
115
123
|
|
|
116
124
|
set Messages(opts) {
|
|
117
125
|
this._messages = {
|
|
118
|
-
offline: `๐
โโ๏ธ ${this._agent.name} offline`,
|
|
119
|
-
init: `โ ๏ธ ${this._agent.name} init`,
|
|
120
|
-
start: `โ
${this._agent.name} start`,
|
|
121
|
-
stop: `๐ฅ ${this._agent.name} stop.`,
|
|
122
|
-
enter: `๐ ${this._agent.name} enter.`,
|
|
123
|
-
exit: `๐ช ${this._agent.name} exit.`,
|
|
124
|
-
done: `๐ ${this._agent.name} done.`,
|
|
126
|
+
offline: `๐
โโ๏ธ ${this._agent.profile.name} offline`,
|
|
127
|
+
init: `โ ๏ธ ${this._agent.profile.name} init`,
|
|
128
|
+
start: `โ
${this._agent.profile.name} start`,
|
|
129
|
+
stop: `๐ฅ ${this._agent.profile.name} stop.`,
|
|
130
|
+
enter: `๐ ${this._agent.profile.name} enter.`,
|
|
131
|
+
exit: `๐ช ${this._agent.profile.name} exit.`,
|
|
132
|
+
done: `๐ ${this._agent.profile.name} done.`,
|
|
125
133
|
devas_started: '#Devas are #online and ready for #offerings ๐ซ๐ฅ๐๐ฏ๐ง',
|
|
126
134
|
devas_stopped: '๐ #Devas have stopped',
|
|
127
|
-
notext: `โ ${this._client.name}, please provide with valid input.`,
|
|
128
|
-
method_not_found: `โ ${this._client.name} you sure messed that up!`,
|
|
135
|
+
notext: `โ ${this._client.profile.name}, please provide with valid input.`,
|
|
136
|
+
method_not_found: `โ ${this._client.profile.name} you sure messed that up!`,
|
|
129
137
|
}
|
|
130
138
|
}
|
|
131
|
-
set Client(
|
|
139
|
+
set Client(client) {
|
|
132
140
|
// copy the cl parameter into a local _client variable
|
|
133
|
-
const _client = this.copy(
|
|
141
|
+
const _client = this.copy(client);
|
|
134
142
|
|
|
135
143
|
// delete the keys used for other features.
|
|
136
144
|
if (_client.states) delete _client.states;
|
|
@@ -146,118 +154,114 @@ class Deva {
|
|
|
146
154
|
this._client = _client;
|
|
147
155
|
|
|
148
156
|
// set the states and messages after the cleint is set.
|
|
149
|
-
this.States =
|
|
150
|
-
this.Messages =
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// setup the @Development feature.
|
|
154
|
-
set Development(opt=false) {
|
|
155
|
-
this.state('setting_development');
|
|
156
|
-
if (!opt) this._security = {};
|
|
157
|
-
else {
|
|
158
|
-
this._security = {
|
|
159
|
-
concerns: opt.concerns,
|
|
160
|
-
global: opt.global,
|
|
161
|
-
items: opt.devas[this._agent.key]
|
|
162
|
-
};
|
|
163
|
-
}
|
|
157
|
+
this.States = client.states;
|
|
158
|
+
this.Messages = client.messages;
|
|
164
159
|
}
|
|
165
160
|
|
|
166
161
|
// setup the @Security feature
|
|
167
|
-
set Security(
|
|
168
|
-
this.
|
|
169
|
-
if (!opt) this._security = {};
|
|
162
|
+
set Security(client=false) {
|
|
163
|
+
if (!client) this._security = {};
|
|
170
164
|
else {
|
|
165
|
+
this.state('setting_security');
|
|
166
|
+
const _client = this.copy(client);
|
|
171
167
|
this._security = {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
168
|
+
id: this.uid(true),
|
|
169
|
+
client_id: _client.id,
|
|
170
|
+
client_name: _client.profile.name,
|
|
171
|
+
hash: _client.security.hash,
|
|
172
|
+
cipher: _client.security.cipher,
|
|
173
|
+
concerns: _client.security.concerns,
|
|
174
|
+
global: _client.security.global,
|
|
175
|
+
personal: _client.security.devas[this._agent.key]
|
|
175
176
|
};
|
|
176
177
|
}
|
|
177
178
|
}
|
|
178
179
|
|
|
179
180
|
// setup the @Support feature
|
|
180
|
-
set Support(
|
|
181
|
-
this.
|
|
182
|
-
if (!opt) this._support = {};
|
|
181
|
+
set Support(client=false) {
|
|
182
|
+
if (!client) this._support = {};
|
|
183
183
|
else {
|
|
184
|
+
this.state('setting_support');
|
|
185
|
+
const _client = this.copy(client);
|
|
184
186
|
this._support = {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
187
|
+
id: this.uid(true),
|
|
188
|
+
client_id: _client.id,
|
|
189
|
+
client_name: _client.profile.name,
|
|
190
|
+
concerns: _client.support.concerns,
|
|
191
|
+
global: _client.support.global,
|
|
192
|
+
personal: _client.support.devas[this._agent.key]
|
|
188
193
|
};
|
|
189
194
|
}
|
|
190
195
|
}
|
|
191
196
|
|
|
192
197
|
// setup the @Services feature
|
|
193
|
-
set Services(
|
|
194
|
-
this.
|
|
195
|
-
if (!opt) this._servcies = {};
|
|
198
|
+
set Services(client=false) {
|
|
199
|
+
if (!client) this._servcies = {};
|
|
196
200
|
else {
|
|
201
|
+
this.state('setting_services');
|
|
202
|
+
const _client = this.copy(client);
|
|
197
203
|
this._services = {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
204
|
+
id: this.uid(true),
|
|
205
|
+
client_id: _client.id,
|
|
206
|
+
client_name: _client.profile.name,
|
|
207
|
+
concerns: _client.services.concerns,
|
|
208
|
+
global: _client.services.global,
|
|
209
|
+
personal: _client.services.devas[this._agent.key]
|
|
201
210
|
};
|
|
202
211
|
}
|
|
203
212
|
}
|
|
204
213
|
|
|
205
214
|
// setup the @Systems feature
|
|
206
|
-
set Systems(
|
|
207
|
-
this.
|
|
208
|
-
if (!opt) this._systems = {};
|
|
215
|
+
set Systems(client=false) {
|
|
216
|
+
if (!client) this._systems = {};
|
|
209
217
|
else {
|
|
218
|
+
this.state('setting_systems');
|
|
219
|
+
const _client = this.copy(client);
|
|
210
220
|
this._systems = {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
221
|
+
id: this.uid(true),
|
|
222
|
+
client_id: _client.id,
|
|
223
|
+
client_name: _client.profile.name,
|
|
224
|
+
concerns: _client.systems.concerns,
|
|
225
|
+
global: _client.systems.global,
|
|
226
|
+
personal: _client.systems.devas[this._agent.key]
|
|
214
227
|
};
|
|
215
228
|
}
|
|
216
229
|
}
|
|
217
230
|
|
|
218
231
|
// setup the @Solutions feature
|
|
219
|
-
set Solutions(
|
|
220
|
-
this.
|
|
221
|
-
if (!opt) this._solutions = {};
|
|
232
|
+
set Solutions(client=false) {
|
|
233
|
+
if (!client) this._solutions = {};
|
|
222
234
|
else {
|
|
235
|
+
this.state('setting_solutions');
|
|
236
|
+
const _client = this.copy(client);
|
|
223
237
|
this._solutions = {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
238
|
+
id: this.uid(true),
|
|
239
|
+
client_id: _client.id,
|
|
240
|
+
client_name: _client.profile.name,
|
|
241
|
+
concerns: _client.solutions.concerns,
|
|
242
|
+
global: _client.solutions.global,
|
|
243
|
+
personal: _client.solutions.devas[this._agent.key]
|
|
227
244
|
};
|
|
228
245
|
}
|
|
229
246
|
}
|
|
230
247
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
data,
|
|
247
|
-
created: Date.now(),
|
|
248
|
-
};
|
|
249
|
-
this.prompt(this._state);
|
|
250
|
-
this.talk(`${this._agent.key}:state`, _data);
|
|
251
|
-
return this._state;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
states() {
|
|
255
|
-
return this._states;
|
|
248
|
+
// setup the @Development feature.
|
|
249
|
+
set Development(client=false) {
|
|
250
|
+
if (!client) this._development = {};
|
|
251
|
+
else {
|
|
252
|
+
this.state('setting_development');
|
|
253
|
+
const _client = this.copy(client);
|
|
254
|
+
this._development = {
|
|
255
|
+
id: this.uid(true),
|
|
256
|
+
client_id: _client.id,
|
|
257
|
+
client_name: _client.profile.name,
|
|
258
|
+
concerns: _client.development.concerns,
|
|
259
|
+
global: _client.development.global,
|
|
260
|
+
personal: _client.development.devas[this._agent.key]
|
|
261
|
+
};
|
|
262
|
+
}
|
|
256
263
|
}
|
|
257
264
|
|
|
258
|
-
// Called from the init function to bind the elements defined in the this.bind variable.
|
|
259
|
-
// the assign bind ensures that the *this* scope is available to child elements/functions.
|
|
260
|
-
|
|
261
265
|
/**************
|
|
262
266
|
func: _assignBind
|
|
263
267
|
params: none
|
|
@@ -383,6 +387,38 @@ class Deva {
|
|
|
383
387
|
return packet;
|
|
384
388
|
}
|
|
385
389
|
|
|
390
|
+
/**************
|
|
391
|
+
func: states
|
|
392
|
+
params: none
|
|
393
|
+
describe: returns the avaiable staets values.
|
|
394
|
+
***************/
|
|
395
|
+
states() {
|
|
396
|
+
return this._states;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**************
|
|
400
|
+
func: state
|
|
401
|
+
params:
|
|
402
|
+
- st: The state flag to set for the Deva that matches to this._states
|
|
403
|
+
describe
|
|
404
|
+
***************/
|
|
405
|
+
state(st, data=false) {
|
|
406
|
+
if (!Object.keys(this._states).includes(st)) return;
|
|
407
|
+
this._state = `${this._states[st]} on ${this.formatDate(Date.now(), 'short_month', true)}`;
|
|
408
|
+
const _data = {
|
|
409
|
+
id: this.uid(true),
|
|
410
|
+
client: this._client.id,
|
|
411
|
+
agent: this._agent.id,
|
|
412
|
+
st: st,
|
|
413
|
+
state: this._state,
|
|
414
|
+
data,
|
|
415
|
+
created: Date.now(),
|
|
416
|
+
};
|
|
417
|
+
this.prompt(this._state);
|
|
418
|
+
this.talk(`${this._agent.key}:state`, _data);
|
|
419
|
+
return this._state;
|
|
420
|
+
}
|
|
421
|
+
|
|
386
422
|
/**************
|
|
387
423
|
func: uid
|
|
388
424
|
params:
|
|
@@ -396,12 +432,90 @@ class Deva {
|
|
|
396
432
|
is shared.
|
|
397
433
|
***************/
|
|
398
434
|
uid(guid=false) {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
435
|
+
let id;
|
|
436
|
+
if (guid) {
|
|
437
|
+
id = randomUUID()
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
const min = Math.floor(Date.now() - (Date.now() / Math.PI));
|
|
441
|
+
const max = Math.floor(Date.now() + (Date.now() * Math.PI));
|
|
442
|
+
id = Math.floor(Math.random() * (max - min)) + min;
|
|
443
|
+
}
|
|
444
|
+
return id;
|
|
403
445
|
}
|
|
404
446
|
|
|
447
|
+
/**************
|
|
448
|
+
func: hash
|
|
449
|
+
params:
|
|
450
|
+
- texts: The text string to create a hash value for.
|
|
451
|
+
- algo: The hashing algorithm to use for hashing. md5, sha256, or sha512
|
|
452
|
+
|
|
453
|
+
describe:
|
|
454
|
+
The hash algorithm will take a string of text and produce a hash.
|
|
455
|
+
***************/
|
|
456
|
+
hash(str) {
|
|
457
|
+
const algo = this._security.hash || 'md5';
|
|
458
|
+
const the_hash = createHash(algo);
|
|
459
|
+
the_hash.update(str);
|
|
460
|
+
const _digest = the_hash.digest('base64');
|
|
461
|
+
this.state('hash', {
|
|
462
|
+
|
|
463
|
+
})
|
|
464
|
+
return ;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**************
|
|
468
|
+
func: cipher
|
|
469
|
+
params: str - string to encrypt
|
|
470
|
+
describe:
|
|
471
|
+
The encrypt function allows for the internal encryption of data based on the
|
|
472
|
+
defined client security settings.
|
|
473
|
+
***************/
|
|
474
|
+
cipher(str) {
|
|
475
|
+
const security = this._security;
|
|
476
|
+
const {password, algorithm} = security.cipher;
|
|
477
|
+
const key = createHash('sha256').update(String(password)).digest('base64');
|
|
478
|
+
const key_in_bytes = Buffer.from(key, 'base64')
|
|
479
|
+
const iv = randomBytes(16);
|
|
480
|
+
|
|
481
|
+
// create a new cipher
|
|
482
|
+
const _cipher = createCipheriv(algorithm, key_in_bytes, iv);
|
|
483
|
+
const encrypted = _cipher.update(String(str), 'utf8', 'hex') + _cipher.final('hex');
|
|
484
|
+
|
|
485
|
+
this.state('cipher', {
|
|
486
|
+
id: this.uid(true),
|
|
487
|
+
iv,
|
|
488
|
+
key,
|
|
489
|
+
agent_id: this._agent.id,
|
|
490
|
+
client_id: this._client.id,
|
|
491
|
+
created: Date.now()
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
return {
|
|
495
|
+
iv: iv.toString('base64'),
|
|
496
|
+
key,
|
|
497
|
+
encrypted,
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
decipher(opt) {
|
|
501
|
+
const iv = Buffer.from(opt.iv, 'base64');
|
|
502
|
+
const encrypted = Buffer.from(opt.encrypted, 'hex');
|
|
503
|
+
const key_in_bytes = Buffer.from(opt.key, 'base64')
|
|
504
|
+
const security = this._security;
|
|
505
|
+
const {algorithm} = security.cipher;
|
|
506
|
+
const decipher = createDecipheriv( algorithm, key_in_bytes, iv);
|
|
507
|
+
const decrypted = decipher.update(encrypted);
|
|
508
|
+
const final = Buffer.concat([decrypted, decipher.final()]);
|
|
509
|
+
this.state('decipher', {
|
|
510
|
+
id: this.uid(true),
|
|
511
|
+
iv: opt.iv,
|
|
512
|
+
key: opt.key,
|
|
513
|
+
agent_id: this._agent.id,
|
|
514
|
+
client_id: this._client.id,
|
|
515
|
+
created: Date.now()
|
|
516
|
+
});
|
|
517
|
+
return final.toString();
|
|
518
|
+
}
|
|
405
519
|
|
|
406
520
|
/**************
|
|
407
521
|
func: copy
|
|
@@ -739,12 +853,12 @@ class Deva {
|
|
|
739
853
|
}).then(() => {
|
|
740
854
|
this.state('init');
|
|
741
855
|
|
|
742
|
-
this.Security = client
|
|
743
|
-
this.Support = client
|
|
744
|
-
this.Services = client
|
|
745
|
-
this.Systems = client
|
|
746
|
-
this.Solutions = client
|
|
747
|
-
this.Development = client
|
|
856
|
+
this.Security = client;
|
|
857
|
+
this.Support = client;
|
|
858
|
+
this.Services = client;
|
|
859
|
+
this.Systems = client;
|
|
860
|
+
this.Solutions = client;
|
|
861
|
+
this.Development = client;
|
|
748
862
|
|
|
749
863
|
return this.onInit && typeof this.onInit === 'function' ? this.onInit() : this.start();
|
|
750
864
|
}).then(started => {
|
|
@@ -862,7 +976,7 @@ class Deva {
|
|
|
862
976
|
if (!this._active) return Promise.resolve(this._messages.offline);
|
|
863
977
|
const id = this.uid();
|
|
864
978
|
const dateFormat = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'medium' }).format(this._active);
|
|
865
|
-
let text = `${this._agent.name} active since ${dateFormat}`;
|
|
979
|
+
let text = `${this._agent.profile.name} active since ${dateFormat}`;
|
|
866
980
|
if (ammend) text = text + `\n${ammend}`;
|
|
867
981
|
return Promise.resolve({text});
|
|
868
982
|
}
|
|
@@ -878,21 +992,6 @@ class Deva {
|
|
|
878
992
|
return this.talk('prompt', {text, agent:this._agent});
|
|
879
993
|
}
|
|
880
994
|
|
|
881
|
-
/**************
|
|
882
|
-
func: hash
|
|
883
|
-
params:
|
|
884
|
-
- texts: The text string to create a hash value for.
|
|
885
|
-
- algo: The hashing algorithm to use for hashing. md5, sha256, or sha512
|
|
886
|
-
|
|
887
|
-
describe:
|
|
888
|
-
The hash algorithm will take a string of text and produce a hash.
|
|
889
|
-
***************/
|
|
890
|
-
hash(text, algo='md5') {
|
|
891
|
-
const the_hash = createHash(algo);
|
|
892
|
-
the_hash.update(text);
|
|
893
|
-
return the_hash.digest('hex');
|
|
894
|
-
}
|
|
895
|
-
|
|
896
995
|
/**************
|
|
897
996
|
func: client
|
|
898
997
|
params: none
|
|
@@ -1026,7 +1125,7 @@ class Deva {
|
|
|
1026
1125
|
|
|
1027
1126
|
// UTILITY FUNCTIONS
|
|
1028
1127
|
/**************
|
|
1029
|
-
func:
|
|
1128
|
+
func: formatDate
|
|
1030
1129
|
params:
|
|
1031
1130
|
- d: The date string to format.
|
|
1032
1131
|
- format: the various formats that can be selected.
|
|
@@ -1037,7 +1136,7 @@ class Deva {
|
|
|
1037
1136
|
FDate format ensures that consistent date formatting is used within the
|
|
1038
1137
|
system based on the language and locale in the client profile.
|
|
1039
1138
|
***************/
|
|
1040
|
-
|
|
1139
|
+
formatDate(d, format='long', time=false) {
|
|
1041
1140
|
if (!d) d = Date.now();
|
|
1042
1141
|
d = new Date(d);
|
|
1043
1142
|
|
|
@@ -1052,42 +1151,42 @@ class Deva {
|
|
|
1052
1151
|
log: { year: 'numeric', month: 'short', day: 'numeric' },
|
|
1053
1152
|
};
|
|
1054
1153
|
const theDate = d.toLocaleDateString(this._client.locale, formats[format]);
|
|
1055
|
-
const theTime = this.
|
|
1154
|
+
const theTime = this.formatTime(d);
|
|
1056
1155
|
return !theTime ? theDate : `${theDate} - ${theTime}`;
|
|
1057
1156
|
}
|
|
1058
1157
|
|
|
1059
1158
|
/**************
|
|
1060
|
-
func:
|
|
1159
|
+
func: formatTime
|
|
1061
1160
|
params:
|
|
1062
1161
|
- t: the time to format
|
|
1063
1162
|
describe:
|
|
1064
1163
|
The formatTime fucntion will return a consistent local time for the t
|
|
1065
1164
|
parameter based on the locale setting in the client profile..
|
|
1066
1165
|
***************/
|
|
1067
|
-
|
|
1166
|
+
formatTime(t) {
|
|
1068
1167
|
return t.toLocaleTimeString(this._client.locale);
|
|
1069
1168
|
}
|
|
1070
1169
|
|
|
1071
1170
|
/**************
|
|
1072
|
-
func:
|
|
1171
|
+
func: formatCurrency
|
|
1073
1172
|
params:
|
|
1074
1173
|
- n: is the number that you want to return the currency of.
|
|
1075
1174
|
describe:
|
|
1076
|
-
The
|
|
1175
|
+
The formatCurrency function will format a currency value based on the setting
|
|
1077
1176
|
in the client profile.
|
|
1078
1177
|
***************/
|
|
1079
|
-
|
|
1178
|
+
formatCurrency(n) {
|
|
1080
1179
|
return new Intl.NumberFormat(this._client.locale, { style: 'currency', currency: this._client.currency }).format(n);
|
|
1081
1180
|
}
|
|
1082
1181
|
|
|
1083
1182
|
/**************
|
|
1084
|
-
func:
|
|
1183
|
+
func: formatPerdent
|
|
1085
1184
|
params:
|
|
1086
1185
|
- n: is the number that you want to format as a percent.
|
|
1087
1186
|
- dec: is the number of decimal places to apply to the number.
|
|
1088
1187
|
describe:
|
|
1089
1188
|
***************/
|
|
1090
|
-
|
|
1189
|
+
formatPerdent(n, dec=2) {
|
|
1091
1190
|
return parseFloat(n).toFixed(dec) + '%';
|
|
1092
1191
|
}
|
|
1093
1192
|
|