@indra.ai/deva 1.1.93 → 1.1.94

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 (2) hide show
  1. package/index.js +160 -130
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -75,6 +75,132 @@ class Deva {
75
75
  }
76
76
  }
77
77
 
78
+ /**************
79
+ func: _assignBind
80
+ params: none
81
+ describe:
82
+ The assign bind function will bind the translate functions and parse functions
83
+ of the agent and bind their functionality to the state machine.
84
+ ***************/
85
+ _assignBind() {
86
+ return new Promise((resolve, reject) => {
87
+ try {
88
+ this.bind.forEach(bind => { // loop over the bind items func, method, listener...
89
+ if (this[bind]) for (let x in this[bind]) { // if the root has a bind func, method, listener
90
+ if (typeof this[bind][x] === 'function') { // check to make sure object is a fucntion
91
+ this[bind][x] = this[bind][x].bind(this); // bind the item from the bind object
92
+ }
93
+ }
94
+ });
95
+ // bind translate
96
+ const translate = this._agent && this._agent.translate && typeof this._agent.translate === 'function';
97
+ if (translate) this._agent.translate = this._agent.translate.bind(this);
98
+ // bind parser
99
+ const parse = this._agent && this._agent.parse && typeof this._agent.parse === 'function';
100
+ if (parse) this._agent.parse = this._agent.parse.bind(this);
101
+ // bind process
102
+ const process = this._agent && this._agent.process && typeof this._agent.process === 'function';
103
+ if (process) this._agent.process = this._agent.process.bind(this);
104
+ }
105
+ catch (e) {
106
+ return this.error(e, false, reject); // trigger the this.error for errors
107
+ }
108
+ finally {
109
+ return resolve(); // when the configuration is complete then return an empty resolve.
110
+ }
111
+ });
112
+ }
113
+
114
+ /**************
115
+ func: _assignListeners
116
+ params: none
117
+ describe:
118
+ Assign listeners will take the this.lisners objects and assign the appropriate
119
+ lisnter values for the event bus.
120
+ ***************/
121
+ _assignListeners() {
122
+ return new Promise((resolve, reject) => {
123
+ try {
124
+ // set the default listeners for the states of the agent.
125
+
126
+ for (let state in this._states) {
127
+ if (typeof this[state] === 'function') {
128
+ this.events.on(`${this._agent.key}:${state}`, packet => {
129
+ return this[state](packet);
130
+ });
131
+ }
132
+ }
133
+
134
+ // set the assigned listeners for the agent.
135
+ for (let listener in this.listeners) {
136
+ this.events.on(listener, packet => {
137
+ return this.listeners[listener](packet);
138
+ })
139
+ }
140
+ return resolve();
141
+ }
142
+ catch (e) {
143
+ return this.error(e, false, reject);
144
+ }
145
+ });
146
+ }
147
+
148
+ // Some elements will inherit the data of the parent. this object will loop over
149
+ // any children data that theis deva has and assign the inherited information.
150
+ /**************
151
+ func: _assignInherit
152
+ params: none
153
+ describe:
154
+ The assign inherit will make sure the Devas in the current Deva have all the
155
+ inherited properties all setup to collaborate efficiently.
156
+ ***************/
157
+ _assignInherit() {
158
+ return new Promise((resolve, reject) => {
159
+ try {
160
+ for (let d in this.devas) {
161
+ this.inherit.forEach(inherit => {
162
+ this.devas[d][inherit] = this[inherit];
163
+ });
164
+ }
165
+ return resolve();
166
+ }
167
+ catch (e) {
168
+ return this.error(e, false, reject);
169
+ }
170
+ });
171
+ }
172
+
173
+ // General handler for when a method is NOT found from a user command.
174
+ /**************
175
+ func: _methodNotFound
176
+ params:
177
+ - packet: The packet to relay when a method is not found.
178
+ describe:
179
+ The _methodNotFound function allows for additional security by firing
180
+ a specfici program functon every single time a interaction happens wehre a
181
+ method is not located. This assits in security and support by identifying
182
+ troubls or users who may be attemptng to explit features.
183
+
184
+ Then we talk a security event that watches all methods and return the packet.
185
+
186
+ This will return a not found text string preventing any furhter processing.
187
+ ***************/
188
+ _methodNotFound(packet) {
189
+ packet.a = {
190
+ id: this.uid(),
191
+ agent: this.agent() || false,
192
+ client: this.client() || false,
193
+ text: `${this._messages.method_not_found}`,
194
+ meta: {
195
+ key: this._agent.key,
196
+ method: packet.q.meta.method,
197
+ },
198
+ created: Date.now(),
199
+ };
200
+ this.state('method_not_found');
201
+ return packet;
202
+ }
203
+
78
204
  /**************
79
205
  func: Client
80
206
  params: client - client provided data.
@@ -520,131 +646,6 @@ class Deva {
520
646
  }
521
647
  });
522
648
  }
523
- /**************
524
- func: _assignBind
525
- params: none
526
- describe:
527
- The assign bind function will bind the translate functions and parse functions
528
- of the agent and bind their functionality to the state machine.
529
- ***************/
530
- _assignBind() {
531
- return new Promise((resolve, reject) => {
532
- try {
533
- this.bind.forEach(bind => { // loop over the bind items func, method, listener...
534
- if (this[bind]) for (let x in this[bind]) { // if the root has a bind func, method, listener
535
- if (typeof this[bind][x] === 'function') { // check to make sure object is a fucntion
536
- this[bind][x] = this[bind][x].bind(this); // bind the item from the bind object
537
- }
538
- }
539
- });
540
- // bind translate
541
- const translate = this._agent && this._agent.translate && typeof this._agent.translate === 'function';
542
- if (translate) this._agent.translate = this._agent.translate.bind(this);
543
- // bind parser
544
- const parse = this._agent && this._agent.parse && typeof this._agent.parse === 'function';
545
- if (parse) this._agent.parse = this._agent.parse.bind(this);
546
- // bind process
547
- const process = this._agent && this._agent.process && typeof this._agent.process === 'function';
548
- if (process) this._agent.process = this._agent.process.bind(this);
549
- }
550
- catch (e) {
551
- return this.error(e, false, reject); // trigger the this.error for errors
552
- }
553
- finally {
554
- return resolve(); // when the configuration is complete then return an empty resolve.
555
- }
556
- });
557
- }
558
-
559
- /**************
560
- func: _assignListeners
561
- params: none
562
- describe:
563
- Assign listeners will take the this.lisners objects and assign the appropriate
564
- lisnter values for the event bus.
565
- ***************/
566
- _assignListeners() {
567
- return new Promise((resolve, reject) => {
568
- try {
569
- // set the default listeners for the states of the agent.
570
-
571
- for (let state in this._states) {
572
- if (typeof this[state] === 'function') {
573
- this.events.on(`${this._agent.key}:${state}`, packet => {
574
- return this[state](packet);
575
- });
576
- }
577
- }
578
-
579
- // set the assigned listeners for the agent.
580
- for (let listener in this.listeners) {
581
- this.events.on(listener, packet => {
582
- return this.listeners[listener](packet);
583
- })
584
- }
585
- return resolve();
586
- }
587
- catch (e) {
588
- return this.error(e, false, reject);
589
- }
590
- });
591
- }
592
-
593
- // Some elements will inherit the data of the parent. this object will loop over
594
- // any children data that theis deva has and assign the inherited information.
595
- /**************
596
- func: _assignInherit
597
- params: none
598
- describe:
599
- The assign inherit will make sure the Devas in the current Deva have all the
600
- inherited properties all setup to collaborate efficiently.
601
- ***************/
602
- _assignInherit() {
603
- return new Promise((resolve, reject) => {
604
- try {
605
- for (let d in this.devas) {
606
- this.inherit.forEach(inherit => {
607
- this.devas[d][inherit] = this[inherit];
608
- });
609
- }
610
- return resolve();
611
- }
612
- catch (e) {
613
- return this.error(e, false, reject);
614
- }
615
- });
616
- }
617
-
618
- // General handler for when a method is NOT found from a user command.
619
- /**************
620
- func: _methodNotFound
621
- params:
622
- - packet: The packet to relay when a method is not found.
623
- describe:
624
- The _methodNotFound function allows for additional security by firing
625
- a specfici program functon every single time a interaction happens wehre a
626
- method is not located. This assits in security and support by identifying
627
- troubls or users who may be attemptng to explit features.
628
-
629
- Then we talk a security event that watches all methods and return the packet.
630
-
631
- This will return a not found text string preventing any furhter processing.
632
- ***************/
633
- _methodNotFound(packet) {
634
- packet.a = {
635
- id: this.uid(),
636
- agent: this.agent() || false,
637
- client: this.client() || false,
638
- text: `${this._messages.method_not_found}`,
639
- meta: {
640
- key: this._agent.key,
641
- method: packet.q.meta.method,
642
- },
643
- created: Date.now(),
644
- };
645
- this.state('method_not_found');
646
- return packet;
647
- }
648
649
 
649
650
  /**************
650
651
  func: talk
@@ -1162,7 +1163,6 @@ class Deva {
1162
1163
  describe
1163
1164
  ***************/
1164
1165
  state(state) {
1165
- console.log('STATE', state);
1166
1166
  try {
1167
1167
  if (!this._states[state]) return;
1168
1168
  this._state = state;
@@ -1279,16 +1279,16 @@ class Deva {
1279
1279
  - st: The context flag to set for the Deva that matches to this._contexts
1280
1280
  describe
1281
1281
  ***************/
1282
- context(text) {
1282
+ context(value) {
1283
1283
  try {
1284
- this._context = text;
1284
+ this._context = value;
1285
1285
  const _data = {
1286
1286
  id: this.uid(true),
1287
1287
  key: 'context',
1288
- value: 'context',
1288
+ value,
1289
1289
  agent: this.agent(),
1290
1290
  client: this.client(),
1291
- text,
1291
+ text: this.vars.context[value] || value,
1292
1292
  created: Date.now(),
1293
1293
  };
1294
1294
  _data.hash = this.hash(_data);
@@ -1829,6 +1829,11 @@ class Deva {
1829
1829
  return splitter.slice(0, maxwords).join(' ');
1830
1830
  }
1831
1831
 
1832
+ /**************
1833
+ func: dupes
1834
+ params: dupers
1835
+ describe: remove duplicees from an array.
1836
+ ***************/
1832
1837
  dupes(dupers) {
1833
1838
  if (!Array.isArray(dupers)) return dupers;
1834
1839
  const check = [];
@@ -1840,6 +1845,31 @@ class Deva {
1840
1845
  });
1841
1846
  }
1842
1847
 
1848
+ /**************
1849
+ func: help
1850
+ params:
1851
+ - msg: the help msg to search against
1852
+ - help_dir: base directory of the deva help files.
1853
+ describe:
1854
+ the help utility makes it easy to create help files for your deva. the utility
1855
+ checks the existence of a help file in the passed in directory then if
1856
+ one exists it will then present it based on the users request text input.
1857
+ ***************/
1858
+ help(msg, help_dir) {
1859
+ return new Promise((resolve, reject) => {
1860
+ const params = msg.split(' ');
1861
+ let helpFile = 'main';
1862
+ if (params[0]) helpFile = params[0];
1863
+ if (params[1]) helpFile = `${params[0]}_${params[1]}`;
1864
+ helpFile = path.join(help_dir, 'help', `${helpFile}.feecting`);
1865
+ try {
1866
+ return resolve(fs.readFileSync(helpFile, 'utf8'))
1867
+ } catch (e) {
1868
+ return reject(e)
1869
+ }
1870
+ });
1871
+ }
1872
+
1843
1873
  /**************
1844
1874
  func: error
1845
1875
  params:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.1.93",
3
+ "version": "1.1.94",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -27,8 +27,8 @@
27
27
  }
28
28
  },
29
29
  "engines": {
30
- "npm": ">=6.0.0",
31
- "node": ">=10.0.0"
30
+ "npm": ">=9.5.1",
31
+ "node": ">=18.16.0"
32
32
  },
33
33
  "dependencies": {}
34
34
  }