@indra.ai/deva 1.1.21 → 1.1.23

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.
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "CLIENT",
3
+ "describe": "CLIENT FILE",
4
+ "copyright": "Copyright ©2023 Quinn Michaels. All rights reserved.",
5
+ "DATA": {
6
+ "id": 3123155399059,
7
+ "key": "test",
8
+ "name": "Test User",
9
+ "eamil": "test@example.com",
10
+ "describe": "The Test User",
11
+ "prompt": {
12
+ "emoji": "🧪",
13
+ "text": "test",
14
+ "colors": {
15
+ "label": {
16
+ "R": 2,
17
+ "G": 229,
18
+ "B": 77
19
+ },
20
+ "text": {
21
+ "R": 2,
22
+ "G": 229,
23
+ "B": 77
24
+ }
25
+ }
26
+ },
27
+ "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
+ "name": "Test User",
32
+ "describe": "This is the Test user for the Deva Examples in the Repository.",
33
+ "gender": "splendid",
34
+ "lang": "en"
35
+ },
36
+ "states": {},
37
+ "messages": {},
38
+ "services": {
39
+ "concerns": [],
40
+ "global": {
41
+ "indra": "https://indra.ai",
42
+ "world": "https://deva.world",
43
+ "space": "https://deva.space",
44
+ "cloud": "https://deva.cloud"
45
+ },
46
+ "devas": {}
47
+ },
48
+ "security": {
49
+ "concerns": [],
50
+ "global": {},
51
+ "devas": {}
52
+ },
53
+ "support": {
54
+ "concerns": [],
55
+ "global": {},
56
+ "devas": {}
57
+ }
58
+ }
59
+ }
@@ -1,6 +1,8 @@
1
1
  // Copyright (c)2023 Quinn Michaels
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
+ const client = require('./client.json');
5
+
4
6
  const Deva = require('../index');
5
7
  const HelloWorld = new Deva({
6
8
  client: {
@@ -39,35 +41,41 @@ const HelloWorld = new Deva({
39
41
  },
40
42
  listeners: {
41
43
  'hello:state'(packet) {
42
- console.log(packet.state);
44
+ // console.log(packet.state);
43
45
  },
44
- 'prompt'(text) {
45
- console.log(text);
46
+ 'prompt'(packet) {
47
+ console.log(packet.text);
46
48
  }
47
49
  },
48
50
  deva: {},
49
51
  modules: {},
50
52
  func: {
53
+ getclient(packet) {
54
+ return Promise.resolve(this._client);
55
+ },
51
56
  state(packet) {
52
57
  const ret = `${this._state} ${this.uid(true)} ${this.uid()} ${this.hash(JSON.stringify(packet), 'sha256')}`;
53
58
  return Promise.resolve(ret);
54
59
  }
55
60
  },
56
61
  methods: {
62
+ getclient(packet) {
63
+ return this._client;
64
+ },
57
65
  state(packet) {
58
66
  return this.func.state(packet);
59
67
  }
60
68
  },
61
69
  onError(e, packet) {
62
- console.log('ERROR\n\n', e, packet);
70
+ console.log('ERROR\n\n', e);
63
71
  }
64
72
  });
65
73
 
66
- HelloWorld.init().then(done => {
67
- return HelloWorld.question('/state how are you')
74
+ HelloWorld.init(client.DATA).then(done => {
75
+ // console.log(done);
76
+ return HelloWorld.question('/state')
68
77
  }).then(answer => {
69
- // console.log(answer);
70
- console.log(answer.a.text);
78
+ console.log('THE ANSWER: ', answer.a.text);
71
79
  });
72
80
 
73
81
 
package/index.js CHANGED
@@ -7,16 +7,18 @@ const { createHash, randomUUID } = require('crypto');
7
7
  class Deva {
8
8
  constructor(opts) {
9
9
  opts = opts || {};
10
+
10
11
  this._id = randomUUID(); // the unique id assigned to the agent at load
12
+ this._config = opts.config || {}; // local Config Object
13
+ this._agent = opts.agent || false; // Agent profile object
14
+ this._client = {}; // this will be set on init.
11
15
  this._state = 'OFFLINE'; // current state of agent.
12
16
  this._active = false; // the active/birth date.
13
- this.security = false; // inherited Security features.
14
- this.support = false; // inherited Support features.
15
- this.config = opts.config || {}; // local Config Object
17
+ this._security = {}; // inherited Security features.
18
+ this._support = {}; // inherited Support features.
19
+ this._services = {}; // inherited Service features.
16
20
  this.events = opts.events || new EventEmitter({}); // Event Bus
17
21
  this.lib = opts.lib || {}; // used for loading library functions
18
- this.agent = opts.agent || false; // Agent profile object
19
- this.client = opts.client || false; // Client profile object
20
22
  this.devas = opts.devas || {}; // Devas which are loaded
21
23
  this.vars = opts.vars || {}; // Variables object
22
24
  this.listeners = opts.listeners || {}; // local Listeners
@@ -33,63 +35,141 @@ class Deva {
33
35
  this.askChr = '#';
34
36
  this.inherit = ["events", "config", "lib", "security", "client"];
35
37
  this.bind = ["listeners", "methods", "func", "lib", "security", "agent", "client"];
38
+
39
+ }
40
+
41
+ set State(opt) {
42
+ this.state(opt);
43
+ }
44
+
45
+ set States(opts) {
36
46
  this._states = { // The available states to work with.
37
- offline: '👻 OFFLINE',
38
- online: '📡 ONLINE',
39
- init: '🚀 INIT',
40
- start: '🎬 START',
41
- enter: '🎪 ENTER',
42
- stop: '🛑 STOP',
43
- exit: '🚪 EXIT',
44
- done: '🤝 DONE',
45
- devas_start: '✨ DEVAS START',
46
- devas_ready: '📸 DEVAS READY',
47
- devas_stop: '🙈 DEVAS STOP',
48
- devas_stopped: '🛑 DEVAS STOPPED',
49
- deva_load: '✅ DEVA LOAD',
50
- deva_loaded: '✅ DEVA LOADED',
51
- deva_unloaded: '✅ DEVA UNLOADED',
52
- wait: '😵‍💫 WAITING',
53
- data: '📀 DATA',
54
- ask: '🙋‍♀️ ASK',
55
- cmd: '📟 COMMAND',
56
- question: '🐵 QUESTION',
57
- question_me: '🐵 QUESTION',
58
- question_ask: '🧙‍♂️ QUESTION ASK',
59
- question_cmd: '🪄 QUESTION CMD',
60
- question_answer: '🔮 QUESTION ANSWER',
61
- ask_question: '👽 ASK QUESTION',
62
- ask_answer: '🛸 ASK ANSWER',
63
- method_not_found: '😩 METHOD NOT FOUND',
64
- talk: '🎙️ TALK',
65
- listen: '🎧 LISTEN',
66
- error: '❌ ERROR',
67
- story: '📓 STORY',
68
- development: '👨‍💻 DEVELOPMENT',
69
- security: '🚨 SECURITY',
70
- support: '🎗️ SUPPORT',
71
- services: '🎖️ SERVICES',
72
- systems: '👽 SYSTEMS',
73
- solutions: '🔬 SOLUTIONS',
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`,
59
+ wait: `😵‍💫 ${this._agent.name} waiting for something to do`,
60
+ data: `📀 ${this._agent.name} is receiving data`,
61
+ ask: `🙋‍♀️ ${this._agent.name} is asking a question`,
62
+ cmd: `📟 ${this._agent.name} is using a command`,
63
+ question: `🐵 ${this._agent.name} question`,
64
+ ask: `🐵 ${this._agent.name} asking`,
65
+ talk: `🎙️ ${this._agent.name} is talking`,
66
+ listen: `🎧 ${this._agent.name} is listening`,
67
+ error: `❌ ${this._agent.name} had an error`,
68
+ story: `📓 ${this._agent.name} telling a story`,
69
+ development: `👨‍💻 ${this._agent.name} needs @Development`,
70
+ security: `🚨 ${this._agent.name} needs @Security`,
71
+ support: `🎗️ ${this._agent.name} needs @Support`,
72
+ services: `🎖️ ${this._agent.name} needs @Services`,
73
+ systems: `👽 ${this._agent.name} needs @Systems`,
74
+ solutions: `🔬 ${this._agent.name} needs @Solutions`,
75
+ devas_start: `✨ Starting all the #Devas...`,
76
+ devas_ready: `📸 The #Devas are ready and waiitng`,
77
+ devas_stop: `🙈 The #Devas are stopping`,
78
+ devas_stopped: `🛑 #Devas have stopped`,
79
+ deva_load: `✅ ${this._agent.name} load`,
80
+ deva_loaded: `✅ ${this._agent.name} loaded`,
81
+ deva_unloaded: `✅ ${this._agent.name} unloaded`,
82
+ question_me: `🐵 ${this._client.name} ask ${this._agent.name} a #question`,
83
+ question_default: `🧞‍♂️ ${this._client.id} sent ${this._agent.name} a #question`,
84
+ question_ask: `🧞 ${this._agent.name} is pondering what ${this._client.name} asked`,
85
+ question_asking: `🧞 ${this._agent.name} is asking another #Deva what ${this._client.name} asked`,
86
+ question_aswering: `🧞 ${this._agent.name} is answering the #question ${this._client.name} asked`,
87
+ question_answer: `🔮 #${this._agent.name} gave #${this._client.name} the answer`,
88
+ question_cmd: `🧞‍♀️ ${this._agent.name} then ran a #command for #${this._client.name}`,
89
+ hash_question: `🔐 ${this._agent.name} created the #question hash`,
90
+ hash_answer: `🔐 ${this._agent.name} created the #answer hash`,
91
+ hash_answer: `🔐 ${this._agent.name} created the #packet hash`,
92
+ ask_question: `👽 ${this._client.name} asked ${this._agent.name} a #question`,
93
+ ask_answer: `🛸 ${this._agent.name} answered ${this._client.name}`,
94
+ method_not_found: `😩 ${this._agent.name} used a bad #command, and may need help.`,
95
+ security_ready: `🚓 @Security is ready`,
96
+ support_ready: `🚑 @Support is ready`,
97
+ services_ready: `🚚 @Services is ready`,
98
+ security_alert: `🚨 #SECURITY 🚨 SETTTINGS`,
99
+ support_alert: `🚨 #SUPPORT 🚨 SETTTINGS`,
100
+ services_alert: `🚨 #SERVICES 🚨 SETTTINGS`,
101
+ setting_client: `⛄️ Setting the #client for ${this._agent.name}`,
102
+ setting_security: `👮‍♂️ ${this._agent.name} given #security`,
103
+ setting_support: `👨‍⚕️ ${this._agent.name} given #support`,
104
+ setting_services: `👷‍♂️ ${this._agent.name} given #services`,
74
105
  };
106
+ }
107
+
108
+ set Messages(opts) {
75
109
  this._messages = {
76
- offline: '🙅‍♂️ DEVA OFFLINE',
77
- init: '✅ DEVA INITIALIZED',
78
- start: '✅ DEVA STARTED',
79
- stop: '💥 DEVA STOPPED',
80
- enter: '🖖 DEVA ENTERED',
81
- exit: '🚪 DEVA EXITED',
82
- done: '👍 DEVA DONE',
83
- devas_started: '🤝 DEVAS STARTED',
84
- devas_stopped: '🛑 DEVAS STOPPED',
85
- notext: '❌ NO TEXT',
86
- method_not_found: '❌ THAT IS NOT GONNA WORK!',
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: '🤝 Devas have started',
118
+ 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!`,
121
+ }
122
+ }
123
+ set Client(cl) {
124
+ // delete the services key to move and move to services.
125
+ const _client = this.copy(cl);
126
+ if (_client.states) delete _client.states;
127
+ if (_client.messages) delete _client.messages;
128
+ if (_client.security) delete _client.security;
129
+ if (_client.support) delete _client.support;
130
+ if (_client.services) delete _client.services;
131
+
132
+ this._client = cl;
133
+
134
+ this.States = _client.states;
135
+ this.Messages = _client.messages;
136
+ }
137
+
138
+ set Security(opt=false) {
139
+ this.state('setting_security');
140
+ if (!opt) this._security = {};
141
+ else {
142
+ this._security = {
143
+ concerns: opt.concerns,
144
+ global: opt.global,
145
+ things: opt.devas[this._agent.key]
146
+ };
87
147
  }
88
148
  }
89
149
 
90
- // set the state of the agent with the passed value to match the valid keys.
91
- // this will also talk a global state event with the agent data and state.
92
- // then security can watch all the glorious state change events.
150
+ set Support(opt=false) {
151
+ this.state('setting_support');
152
+ if (!opt) this._support = {};
153
+ else {
154
+ this._support = {
155
+ concerns: opt.concerns,
156
+ global: opt.global,
157
+ things: opt.devas[this._agent.key]
158
+ };
159
+ }
160
+ }
161
+
162
+ set Services(opt=false) {
163
+ this.state('setting_services');
164
+ if (!opt) this._servcies = {};
165
+ else {
166
+ this._services = {
167
+ concerns: opt.concerns,
168
+ global: opt.global,
169
+ things: opt.devas[this._agent.key]
170
+ };
171
+ }
172
+ }
93
173
 
94
174
  /**************
95
175
  func: state
@@ -102,15 +182,15 @@ class Deva {
102
182
  this._state = this._states[st];
103
183
  const _data = {
104
184
  id: this.uid(true),
105
- client: this.client.id,
106
- agent: this.agent.id,
185
+ client: this._client.id,
186
+ agent: this._agent.id,
107
187
  st: st,
108
188
  state: this._state,
109
189
  data,
110
190
  created: Date.now(),
111
191
  };
112
192
  this.prompt(this._state);
113
- this.talk(`${this.agent.key}:state`, _data);
193
+ this.talk(`${this._agent.key}:state`, _data);
114
194
  return this._state;
115
195
  }
116
196
 
@@ -139,11 +219,11 @@ class Deva {
139
219
  }
140
220
  });
141
221
  // bind translate
142
- const translate = this.agent && this.agent.translate && typeof this.agent.translate === 'function';
143
- if (translate) this.agent.translate = this.agent.translate.bind(this);
222
+ const translate = this._agent && this._agent.translate && typeof this._agent.translate === 'function';
223
+ if (translate) this._agent.translate = this._agent.translate.bind(this);
144
224
  // bind parser
145
- const parse = this.agent && this.agent.parse && typeof this.agent.parse === 'function';
146
- if (parse) this.agent.parse = this.agent.parse.bind(this);
225
+ const parse = this._agent && this._agent.parse && typeof this._agent.parse === 'function';
226
+ if (parse) this._agent.parse = this._agent.parse.bind(this);
147
227
  }
148
228
  catch (e) {
149
229
  return reject(e);
@@ -164,15 +244,17 @@ class Deva {
164
244
  _assignListeners() {
165
245
  return new Promise((resolve, reject) => {
166
246
  try {
167
- // set the assigned listeners for the agent.
168
- for (let listener in this.listeners) {
169
- // set the default listeners for the states of the agent.
170
- for (let state in this._states) {
171
- this.events.on(`${this.agent.key}:${state}`, packet => {
247
+ // set the default listeners for the states of the agent.
248
+ for (let state in this._states) {
249
+ if (typeof this[state] === 'function') {
250
+ this.events.on(`${this._agent.key}:${state}`, packet => {
172
251
  return this[state](packet);
173
- })
252
+ });
174
253
  }
254
+ }
175
255
 
256
+ // set the assigned listeners for the agent.
257
+ for (let listener in this.listeners) {
176
258
  this.events.on(listener, packet => {
177
259
  return this.listeners[listener](packet);
178
260
  })
@@ -231,11 +313,11 @@ class Deva {
231
313
  ***************/
232
314
  _methodNotFound(packet) {
233
315
  packet.a = {
234
- agent: this.agent || false,
235
- client: this.client || false,
316
+ agent: this._agent || false,
317
+ client: this._client || false,
236
318
  text: `${this._messages.method_not_found} - ${packet.q.meta.method} `,
237
319
  meta: {
238
- key: this.agent.key,
320
+ key: this._agent.key,
239
321
  method: packet.q.meta.method,
240
322
  },
241
323
  created: Date.now(),
@@ -244,11 +326,6 @@ class Deva {
244
326
  return packet;
245
327
  }
246
328
 
247
- // A simple interface to generate a unique id for the agent. As agents will
248
- // quite oftne have to key their transactions. This will provide all agents
249
- // with the same key generator which can also be modified to link into a remote
250
- // generator or some other solution if needed.
251
-
252
329
  /**************
253
330
  func: uid
254
331
  params:
@@ -268,6 +345,25 @@ class Deva {
268
345
  return Math.floor(Math.random() * (max - min)) + min;
269
346
  }
270
347
 
348
+
349
+ /**************
350
+ func: copy
351
+ params: obj
352
+ describe:
353
+ a simple copy object to create a memory clean copy of data to
354
+ prevent collisions when needed. Handles clean text, array, object copy.
355
+ it makes the assumption tha the user is submitting either an array or object
356
+ for copying.
357
+ ***************/
358
+ copy(obj) {
359
+ let v, key;
360
+ const output = Array.isArray(obj) ? [] : {};
361
+ for (key in obj) {
362
+ v = obj[key];
363
+ output[key] = (typeof v === "object") ? this.copy(v) : v;
364
+ }
365
+ return output;
366
+ }
271
367
  /**************
272
368
  func: talk
273
369
  params:
@@ -369,10 +465,10 @@ class Deva {
369
465
  this.state('ask_question', packet);
370
466
 
371
467
  packet.a = {
372
- agent: this.agent || false,
373
- client: this.client || false,
468
+ agent: this._agent || false,
469
+ client: this._client || false,
374
470
  meta: {
375
- key: this.agent.key,
471
+ key: this._agent.key,
376
472
  method: packet.q.meta.method,
377
473
  params: packet.q.meta.params,
378
474
  },
@@ -386,7 +482,7 @@ class Deva {
386
482
  if (this.methods[packet.q.meta.method] === undefined) {
387
483
  return setImmediate(() => {
388
484
  packet.a.text = `INVALID METHOD (${packet.q.meta.method})`;
389
- this.talk(`${this.agent.key}:ask:${packet.id}`, packet);
485
+ this.talk(`${this._agent.key}:ask:${packet.id}`, packet);
390
486
  });
391
487
  }
392
488
 
@@ -403,14 +499,14 @@ class Deva {
403
499
  }
404
500
 
405
501
  this.state('ask_answer', packet);
406
- this.talk(`${this.agent.key}:ask:${packet.id}`, packet);
502
+ this.talk(`${this._agent.key}:ask:${packet.id}`, packet);
407
503
  }).catch(err => {
408
- this.talk(`${this.agent.key}:ask:${packet.id}`, {error:err.toString()});
504
+ this.talk(`${this._agent.key}:ask:${packet.id}`, {error:err.toString()});
409
505
  return this.error(err, packet);
410
506
  })
411
507
  }
412
508
  catch (e) {
413
- this.talk(`${this.agent.key}:ask:${packet.id}`, {error:e.toString()});
509
+ this.talk(`${this._agent.key}:ask:${packet.id}`, {error:e.toString()});
414
510
  return this.error(e, packet)
415
511
  }
416
512
  // now when we ask the meta params[0] should be the method
@@ -427,6 +523,7 @@ class Deva {
427
523
  ***************/
428
524
  question(TEXT=false, DATA=false) {
429
525
  if (!this._active) return Promise.resolve(this._messages.offline);
526
+ this.state('question_me', {text:TEXT, data:DATA});
430
527
 
431
528
  const id = this.uid(); // generate a unique transport id for the question.
432
529
  const t_split = TEXT.split(' ');
@@ -450,7 +547,7 @@ class Deva {
450
547
  let text = TEXT,
451
548
  params = false,
452
549
  method = 'question',
453
- key = this.agent.key;
550
+ key = this._agent.key;
454
551
 
455
552
  return new Promise((resolve, reject) => {
456
553
  if (!TEXT) return reject(this._messages.notext);
@@ -463,13 +560,14 @@ class Deva {
463
560
  // #agent method:param1:param2 with text strings for proccessing
464
561
  // !method param:list:parse for the local agent
465
562
  // if is an ask then we format one way
466
- let _state = 'question_me';
563
+ let _state = 'question_default';
467
564
  if (isAsk) {
468
565
  _state = 'question_ask'
469
566
  key = t_split[0].substring(1);
470
567
  params = t_split[1] ? t_split[1].split(':') : false;
471
568
  method = params[0];
472
569
  text = t_split.slice(2).join(' ').trim();
570
+
473
571
  }
474
572
  else if (isCmd) {
475
573
  _state = 'question_cmd'
@@ -479,8 +577,8 @@ class Deva {
479
577
  }
480
578
 
481
579
  packet.q = {
482
- agent: this.agent || false,
483
- client: this.client || false,
580
+ agent: this._agent || false,
581
+ client: this._client || false,
484
582
  meta: {
485
583
  key,
486
584
  orig,
@@ -493,18 +591,24 @@ class Deva {
493
591
  }
494
592
 
495
593
  // hash the packet and insert the hash into the packet meta object.
594
+ this.state('hash_question');
496
595
  packet.q.meta.hash = this.hash(JSON.stringify(packet.q));
596
+
497
597
  this.state(_state, packet);
498
598
 
499
599
  // If a question to another Deva with '#' then trigger events
500
600
  if (isAsk) {
601
+ this.state('question_asking');
602
+ this.prompt(`sending key ${key}`);
501
603
  this.talk(`${key}:ask`, packet);
502
604
  this.once(`${key}:ask:${packet.id}`, answer => {
503
605
  return resolve(answer);
504
606
  });
505
607
  }
608
+
506
609
  // if the user sends a local command '$' then it will ask of the self.
507
610
  else {
611
+ this.state('question_answering');
508
612
  if (typeof this.methods[method] !== 'function') {
509
613
  return resolve(this._methodNotFound(packet));
510
614
  }
@@ -513,10 +617,10 @@ class Deva {
513
617
  const html = typeof result === 'object' ? result.html : result;
514
618
  const data = typeof result === 'object' ? result.data : false;
515
619
  packet.a = {
516
- agent: this.agent || false,
517
- client: this.client || false,
620
+ agent: this._agent || false,
621
+ client: this._client || false,
518
622
  meta: {
519
- key: this.agent.key,
623
+ key: this._agent.key,
520
624
  method,
521
625
  },
522
626
  text,
@@ -525,10 +629,13 @@ class Deva {
525
629
  created: Date.now(),
526
630
  };
527
631
  // create a hash for the answer and insert into answer meta.
632
+ this.state('hash_answer');
528
633
  packet.a.meta.hash = this.hash(JSON.stringify(packet.a));
529
634
 
530
635
  // create a hash for entire packet and insert into packet
636
+ this.state('hash_packet');
531
637
  packet.hash = this.hash(JSON.stringify(packet));
638
+
532
639
  this.state('question_answer', packet);
533
640
 
534
641
  return resolve(packet);
@@ -545,7 +652,7 @@ class Deva {
545
652
 
546
653
  /**************
547
654
  func: init
548
- params: none
655
+ params: client - the client data to use that is provided by the clients.
549
656
  describe:
550
657
  The main init interface where the chain begins. Where the states fire for
551
658
  each process of setting:
@@ -557,9 +664,12 @@ class Deva {
557
664
  6. The system start function will create a chain reaction of states that load.
558
665
  7. If there is an error the init function rejects the call.
559
666
  ***************/
560
- init() {
561
- this._active = Date.now();
667
+ init(client) {
562
668
  // set client
669
+ this.Client = client;
670
+
671
+
672
+ this._active = Date.now();
563
673
  return new Promise((resolve, reject) => {
564
674
  this.events.setMaxListeners(this.maxListeners);
565
675
  this._assignInherit().then(() => {
@@ -568,6 +678,11 @@ class Deva {
568
678
  return this._assignListeners();
569
679
  }).then(() => {
570
680
  this.state('init');
681
+
682
+ this.Security = client.security;
683
+ this.Support = client.support;
684
+ this.Services = client.services;
685
+
571
686
  return this.onInit && typeof this.onInit === 'function' ? this.onInit() : this.start();
572
687
  }).then(started => {
573
688
  return resolve(started)
@@ -684,7 +799,7 @@ class Deva {
684
799
  if (!this._active) return Promise.resolve(this._messages.offline);
685
800
  const id = this.uid();
686
801
  const dateFormat = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'medium' }).format(this._active);
687
- let text = `${this.agent.name} is ONLINE since ${dateFormat}`;
802
+ let text = `${this._agent.name} active since ${dateFormat}`;
688
803
  if (ammend) text = text + `\n${ammend}`;
689
804
  return Promise.resolve({text});
690
805
  }
@@ -697,7 +812,7 @@ class Deva {
697
812
  The prompt function is used to broadcasat a global prompt event with a string. Thsi is handy when passing events between a cli and user interface for example.
698
813
  ***************/
699
814
  prompt(text) {
700
- return this.talk('prompt', {text, agent:this.agent});
815
+ return this.talk('prompt', {text, agent:this._agent});
701
816
  }
702
817
 
703
818
  /**************
@@ -715,18 +830,65 @@ class Deva {
715
830
  return the_hash.digest('hex');
716
831
  }
717
832
 
833
+ /**************
834
+ func: client
835
+ params: none
836
+ describe:
837
+ this function allows statement management for when client prfioe is
838
+ being accessed.
839
+ ***************/
840
+ client() {
841
+ if (!this._active) return Promise.resolve(this._messages.offline);
842
+ this.state('client');
843
+ return this._client;
844
+ }
845
+
846
+ /**************
847
+ func: agent
848
+ params: none
849
+ describe:
850
+ this function allows statement management for when client prfioe is
851
+ being accessed.
852
+ ***************/
853
+ agent() {
854
+ if (!this._active) return Promise.resolve(this._messages.offline);
855
+ this.state('agent');
856
+ return this._agent;
857
+ }
858
+
859
+ /**************
860
+ func: security
861
+ params: opts
862
+ describe: basic security features available in a Deva.
863
+ ***************/
864
+ security(opts) {}
865
+
866
+ /**************
867
+ func: security
868
+ params: opts
869
+ describe: basic support features available in a Deva.
870
+ ***************/
871
+ support(opts) {}
872
+
873
+ /**************
874
+ func: security
875
+ params: opts
876
+ describe: basic services features available in a Deva.
877
+ ***************/
878
+ services(opts) {}
879
+
718
880
  /**************
719
881
  func: startDevas
720
882
  params: none
721
883
  describe:
722
884
  Start Devas will initialize the Deva agents inside this curent Deva.
723
885
  ***************/
724
- startDevas() {
886
+ startDevas(client) {
725
887
  this.state('devas_start');
726
888
  return new Promise((resolve, reject) => {
727
889
  const devas = [];
728
890
  for (let x in this.devas) {
729
- devas.push(this.devas[x].init());
891
+ devas.push(this.devas[x].init(client));
730
892
  }
731
893
  Promise.all(devas).then(() => {
732
894
  this.state('devas_ready');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.1.21",
3
+ "version": "1.1.23",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "scripts": {