@indra.ai/deva 1.2.22 → 1.2.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.
Files changed (3) hide show
  1. package/config.json +8 -4
  2. package/index.js +34 -23
  3. package/package.json +1 -1
package/config.json CHANGED
@@ -123,6 +123,7 @@
123
123
  "unload": "🥡 Unload",
124
124
  "done": "✅ Done",
125
125
  "question": "🙋 Question",
126
+ "talk": "📢 Talk",
126
127
  "context": "Context",
127
128
  "prompt": "🐚 Prompt",
128
129
  "issue": "🎫 Issue",
@@ -141,6 +142,8 @@
141
142
  "write": "️📝 Write",
142
143
  "set": "🍽️ Set",
143
144
  "get": "🤔 Get",
145
+ "send": "🚀 Send",
146
+ "receive": "🥅 Receive",
144
147
  "return": "🎁 Return",
145
148
  "resolve": "⛵️ Resolve",
146
149
  "reject": "❌ Reject",
@@ -184,10 +187,11 @@
184
187
  "decipher": "🔓 Decipher",
185
188
  "promp": "🪵 Prompt",
186
189
  "getToday": "📆 Get Today",
187
- "formatDate": "📅 Date",
188
- "formatTime": "🕰️ Time",
189
- "formatCurrency": "💰 Currency",
190
- "formatPercent": "💯 Percent",
190
+ "formatDate": "📅 Format Date",
191
+ "formatTime": "🕰️ Format Time",
192
+ "formatCurrency": "💰 Format Currency",
193
+ "formatPercent": "% Format Percent",
194
+ "formatNumbert": "# Format Number",
191
195
  "trimWords": "🙊 Trim Words",
192
196
  "dupes": "📋 Duplicates",
193
197
  "info": "💁‍♂️ Info",
package/index.js CHANGED
@@ -11,7 +11,7 @@ const config = require('./config.json').DATA // load the deva core configuration
11
11
  class Deva {
12
12
  constructor(opts) {
13
13
  opts = opts || {}; // set opts to provided opts or an empty object.
14
- this._id = randomUUID(); // the unique id assigned to the agent at load
14
+ this._id = opts.id || randomUUID(); // the unique id assigned to the agent at load
15
15
  this._info = opts.info || false; // the deva information from the package file.
16
16
  this._config = opts.config || {}; // local Config Object
17
17
  this._agent = opts.agent || false; // Agent profile object
@@ -35,7 +35,7 @@ class Deva {
35
35
  this.maxListeners = opts.maxListenners || 0; // set the local maxListeners
36
36
 
37
37
  // prevent overwriting existing functions and variables with same name
38
- for (var opt in opts) {
38
+ for (const opt in opts) {
39
39
  if (!this[opt] || !this[`_${opt}`]) this[opt] = opts[opt];
40
40
  }
41
41
 
@@ -395,7 +395,8 @@ class Deva {
395
395
  question(TEXT=false, DATA=false) {
396
396
  // check the active status
397
397
  if (!this._active) return Promise.resolve(this._messages.offline);
398
- this.action('question');
398
+ this.zone('question');
399
+
399
400
  const id = this.uid(); // generate a unique id for transport.
400
401
  const t_split = TEXT.split(' '); // split the text on spaces to get words.
401
402
  const data = DATA; // set the DATA to data
@@ -458,14 +459,15 @@ class Deva {
458
459
  // hash the question
459
460
  packet.q.meta.hash = this.hash(packet.q);
460
461
 
461
- this.state('talk', config.events.question); // set current action to what was defined by _action variable.
462
+ this.action('talk', config.events.question);
462
463
  this.talk(config.events.question, this.copy(packet)); // global question event make sure to copy data.
463
464
 
464
465
  if (isAsk) { // isAsk check if the question isAsk and talk
465
466
  // if: isAsk wait for the once event which is key'd to the packet ID for specified responses
467
+ this.action('talk', `${key}:ask`);
466
468
  this.talk(`${key}:ask`, packet);
467
469
  this.once(`${key}:ask:${packet.id}`, answer => {
468
- this.state('talk', config.events.ask);
470
+ this.action('talk', config.events.ask);
469
471
  this.talk(config.events.ask, this.copy(answer));
470
472
  return this.finish(answer, resolve); // if:isAsk resolve the answer from the call
471
473
  });
@@ -499,11 +501,10 @@ class Deva {
499
501
  // check if method exists and is of type function
500
502
  const {method,params} = packet.q.meta;
501
503
  const isMethod = this.methods[method] && typeof this.methods[method] == 'function';
502
- if (!isMethod) {
503
- return resolve(this._methodNotFound(packet)); // resolve method not found if check if check fails
504
- }
504
+ if (!isMethod) return resolve(this._methodNotFound(packet)); // resolve method not found if check if check fails
505
+
505
506
  // Call the local method to process the question based the extracted parameters
506
- this.action('answer', method);
507
+ this.zone('answer', method);
507
508
  this.methods[method](packet).then(result => {
508
509
  // check the result for the text, html, and data object.
509
510
  // this is for when answers are returned from nested Devas.
@@ -531,7 +532,7 @@ class Deva {
531
532
  // create a hash for the answer and insert into answer meta.
532
533
  packet_answer.meta.hash = this.hash(packet_answer);
533
534
  packet.a = packet_answer; // set the packet.a to the packet_answer
534
- this.state('talk', config.events.answer);
535
+ this.action('talk', config.events.answer)
535
536
  this.talk(config.events.answer, this.copy(packet)); // global talk event
536
537
  this.state('resovle', 'answer')
537
538
  return this.finish(packet, resolve); // resolve the packet to the caller.
@@ -559,7 +560,7 @@ class Deva {
559
560
  ask(packet) {
560
561
  if (!this._active) return Promise.resolve(this._messages.offline);
561
562
  const {method, params} = packet.q.meta;
562
- this.action('ask', method);
563
+ this.zone('ask', method);
563
564
 
564
565
  const agent = this.agent();
565
566
  const client = this.client();
@@ -602,7 +603,6 @@ class Deva {
602
603
  this.state('set', `ask:${method}`);
603
604
  packet_answer.meta.hash = this.hash(packet_answer);
604
605
  packet.a = packet_answer;
605
- this.state('talk', config.events.answer);
606
606
  this.talk(config.events.answer, this.copy(packet)); // global talk event
607
607
  this.talk(`${agent.key}:ask:${packet.id}`, packet);
608
608
  }).catch(err => {
@@ -750,7 +750,7 @@ class Deva {
750
750
  ***************/
751
751
  finish(packet, resolve) {
752
752
  if (!this._active) return Promise.resolve(this._messages.offline);
753
- this.action('finish'); // set the finish action
753
+ this.zone('finish'); // set the finish action
754
754
 
755
755
  packet.hash = this.hash(packet);// hash the entire packet before finishing.
756
756
  // check for agent on finish function in agent
@@ -1009,7 +1009,6 @@ class Deva {
1009
1009
  created: Date.now(), // set the creation date
1010
1010
  };
1011
1011
  data.hash = this.hash(data); // generate the hash value of the data packet
1012
- this.state('talk', 'feature');
1013
1012
  this.talk(config.events.feature, data); // talk the feature event with data
1014
1013
  } catch (e) { // catch any errors
1015
1014
  return this.error(e); // retun this.error when an error is caught.
@@ -1058,7 +1057,6 @@ class Deva {
1058
1057
  };
1059
1058
 
1060
1059
  data.hash = this.hash(data);
1061
- this.state('talk', 'context');
1062
1060
  this.talk(config.events.context, data);
1063
1061
  } catch (e) {
1064
1062
  return this.error(e);
@@ -1301,7 +1299,6 @@ class Deva {
1301
1299
  text,
1302
1300
  created: Date.now(),
1303
1301
  }
1304
- this.state('talk', 'prompt')
1305
1302
  return this.talk(config.events.prompt, _data);
1306
1303
  }
1307
1304
 
@@ -1370,8 +1367,8 @@ class Deva {
1370
1367
  day: { day: 'long' },
1371
1368
  log: { year: 'numeric', month: 'short', day: 'numeric' },
1372
1369
  };
1373
- const theDate = d.toLocaleDateString(this._client.locale, formats[format]);
1374
- const theTime = this.formatTime(d);
1370
+ const theDate = d.toLocaleDateString(this._client.profile.locale, formats[format]);
1371
+ const theTime = time ? this.formatTime(d) : false;
1375
1372
  this.state('return', 'formatDate');
1376
1373
  return !theTime ? theDate : `${theDate} - ${theTime}`;
1377
1374
  }
@@ -1386,7 +1383,7 @@ class Deva {
1386
1383
  ***************/
1387
1384
  formatTime(t) {
1388
1385
  this.feature('formatTime');
1389
- return t.toLocaleTimeString(this._client.locale); // return the formatted time string
1386
+ return t.toLocaleTimeString(this._client.profile.locale); // return the formatted time string
1390
1387
  }
1391
1388
 
1392
1389
  /**************
@@ -1397,13 +1394,27 @@ class Deva {
1397
1394
  The formatCurrency function will format a currency value based on the setting
1398
1395
  in the client profile.
1399
1396
  ***************/
1400
- formatCurrency(n) {
1397
+ formatCurrency(n, cur=false) {
1401
1398
  this.feature('formatCurrency');
1402
- return new Intl.NumberFormat(this._client.locale, { style: 'currency', currency: this._client.currency }).format(n);
1399
+ const currency = cur || this._client.profile.currency;
1400
+ return new Intl.NumberFormat(this._client.profile.locale, { style: 'currency', currency: currency }).format(n);
1401
+ }
1402
+
1403
+ /**************
1404
+ func: formatCurrency
1405
+ params:
1406
+ - n: is the number that you want to return the currency of.
1407
+ describe:
1408
+ The formatCurrency function will format a currency value based on the setting
1409
+ in the client profile.
1410
+ ***************/
1411
+ formatNumber(n) {
1412
+ this.feature('formatNumber');
1413
+ return new Intl.NumberFormat(this._client.profile.locale).format(n);
1403
1414
  }
1404
1415
 
1405
1416
  /**************
1406
- func: formatPerdent
1417
+ func: formatPercent
1407
1418
  params:
1408
1419
  - n: is the number that you want to format as a percent.
1409
1420
  - dec: is the number of decimal places to apply to the number.
@@ -1415,7 +1426,7 @@ class Deva {
1415
1426
  }
1416
1427
 
1417
1428
  /**************
1418
- func: trimText
1429
+ func: trimWords
1419
1430
  params:
1420
1431
  - text: The text to trim.
1421
1432
  - maxwords: The number of words to max.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.2.22",
3
+ "version": "1.2.23",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "scripts": {