@indra.ai/deva 1.0.31 → 1.0.33

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/README.md CHANGED
@@ -1,15 +1,26 @@
1
1
  # deva
2
2
 
3
- Deva is a class object that provides events and object management with inherited properties.
4
-
5
- [Back to indra.ai](https://indra.ai)
6
-
7
- ## Install
3
+ Deva is a class object that provides structure, events, and object management with inherited properties.
4
+
5
+ ## contents
6
+ - [install](#install) - How to install the deva core.
7
+ - [structure](#structure) - Basic structure of `deva`.
8
+ - [agent](#agent) - The `agent` object stores the Agent Profile.
9
+ - [vars](#vars) - Variables are stored in the `this.vars` object.
10
+ - [listeners](#listeners) - Listeners are setup to allow a deva trigger events.
11
+ - [devas](#listeners) - This is where sub-devas are loaded into the current deva.
12
+ - [modules](#modules) - A `deva` can add modules to add to their functionality.
13
+ - [func](#func) - A `deva` the internal functionality is written here.
14
+ - [methods](#methods) - Methods expose the `deva` abilities to external commands/calls.
15
+ - [states](#states) - There are various states that triger when a `deva` is doing things.
16
+ - [utility](#utility) - Interal to a `deva` there are utility functions available to make actions easier like getting a unique id or status.
17
+
18
+ ## install
8
19
  ```bash
9
20
  $ npm i @indra.ai/deva --save-dev
10
21
  ```
11
22
 
12
- ## Basic Structure
23
+ ## structure
13
24
  ```javascript
14
25
  // include the main Deva class
15
26
  const Deva = require('feecting/deva');
@@ -63,13 +74,14 @@ deva.init();
63
74
 
64
75
  ```
65
76
 
66
- ## Breakdown
67
- ### Agent
77
+ ## agent
78
+
68
79
  ```javascript
69
80
  this.agent
70
81
  ```
71
82
  The "me" object contains the profile information for the DEVA.
72
- ##### Data Attributes
83
+
84
+ ### Data Attributes
73
85
  - **uid:** The unique id for the Deva.
74
86
  - **key:** The unique key for the Deva.
75
87
  - **name:** The name of the Deva.
@@ -88,17 +100,18 @@ The "me" object contains the profile information for the DEVA.
88
100
  - **gender:** The gender of the Deva
89
101
  - **describe:** A short description of the deva 100 characters or less.
90
102
 
91
- ### Vars
103
+ ## vars
104
+
92
105
  ```javascript
93
106
  this.vars
94
107
  ```
108
+
95
109
  The vars can be use to set local variables for the deva that need to be used in your program.
96
110
 
97
111
  There are no default variables, so the scope is for you and your imagination to figure out.
98
112
 
99
- ##### Example
113
+ ### example
100
114
  ```javascript
101
- ...
102
115
  vars: {
103
116
  foo: 'bar',
104
117
  steps: 10,
@@ -112,64 +125,57 @@ There are no default variables, so the scope is for you and your imagination to
112
125
  'value 2',
113
126
  ]
114
127
  }
115
- ...
116
-
117
128
  ```
118
- ### Listeners
129
+
130
+ ## listeners
119
131
  Listeners are what you setup that allow your Deva to communicate with other Deva or parts of your application/system.
120
132
 
121
133
  ```javascript
122
134
  this.listeners
123
135
  ```
124
136
 
125
- #### Default Listeners
137
+ ### default
126
138
 
127
139
  Each Deva comes with a set of default listeners to provide basic functionality.
128
140
 
129
- ##### Question
130
- The question event is the functionality that exposes the methods to the outside world. When a deva asks a question the string is parsed into a question format so that commands to access various methods can be exposed.
131
-
132
- ```javascript
133
- const question = await this.question(`#*agent_key* *method*:*params* *question string*`);
134
- ```
135
-
136
- ##### Start
141
+ ### start
137
142
  This will trigger an event to start the Deva.
138
143
 
139
144
  ```javascript
140
145
  this.talk(`*agent_key*:start`);
141
146
  ```
142
147
 
143
- ##### Stop
148
+ ### stop
144
149
  This will trigger an event to stop the Deva.
145
150
 
146
151
  ```javascript
147
152
  this.talk(`*agent_key*:stop`);
148
153
  ```
149
154
 
150
- ##### Status
155
+ ### status
151
156
  This will trigger an event to broadcast the Deva status.
152
157
 
153
158
  ```javascript
154
159
  this.talk(`*agent_key*:status`);
155
160
  ```
156
161
 
157
- ### Deva
162
+ ## devas
163
+
158
164
  ```javascript
159
- this.deva
165
+ this.devas
160
166
  ```
161
167
 
162
168
  The main object for Deva that are bwlow this Deva.
163
169
 
164
- ### Modules
170
+ ## modules
171
+
165
172
  The external modules that your Deva might require to function.
166
173
 
167
174
  ```javascript
168
175
  this.modules
169
176
  ```
170
177
 
171
-
172
- ### Func
178
+ ## func
173
179
  The functions that your deva uses to operate. Functions are not exposed through
174
180
  the api to public access.
175
181
 
@@ -177,17 +183,18 @@ the api to public access.
177
183
  this.func
178
184
  ```
179
185
 
180
- ### Methods
186
+ ### methods
181
187
  ```javascript
182
188
  this.methods
183
189
  ```
190
+
184
191
  The methods are exposed publicly through the question event that parses a string
185
192
  and sends a request to the question method that then interacts with functions, modules, and variables.
186
193
 
187
- ### State Functions
194
+ ## states
188
195
  Provided are a set of state functions that trigger when a Deva is at various states of starting/stopping.
189
196
 
190
- #### onStart()
197
+ ### onStart()
191
198
 
192
199
  The `onStart()` function runs after the `start` function has completed.
193
200
 
@@ -197,7 +204,7 @@ this.onStart() {
197
204
  }
198
205
  ```
199
206
 
200
- #### onStop()
207
+ ### onStop()
201
208
 
202
209
  The `onStop()` function runs after the `stop` function has completed.
203
210
 
@@ -207,8 +214,7 @@ this.onStop() {
207
214
  }
208
215
  ```
209
216
 
210
-
211
- #### onEnter()
217
+ ### onEnter()
212
218
 
213
219
  The `onEnter()` function runs after the `enter` event has fired.
214
220
 
@@ -218,8 +224,7 @@ this.onEnter() {
218
224
  }
219
225
  ```
220
226
 
221
-
222
- #### onExit()
227
+ ### onExit()
223
228
 
224
229
  The `onExit()`function runs after the `exit` event has fired.
225
230
 
@@ -229,7 +234,7 @@ this.onExit() {
229
234
  }
230
235
  ```
231
236
 
232
- #### onDone()
237
+ ### onDone()
233
238
 
234
239
  The `onDone()`function runs after the `done` event has fired.
235
240
 
@@ -239,8 +244,7 @@ this.onDone() {
239
244
  }
240
245
  ```
241
246
 
242
-
243
- #### onInit()
247
+ ### onInit()
244
248
 
245
249
  The `onInit()` function runs after the `init()` function has completed.
246
250
 
@@ -250,14 +254,36 @@ this.onInit() {
250
254
  }
251
255
  ```
252
256
 
253
- ## Utility Functions
257
+ ## utility
258
+
259
+ ### question
260
+
261
+ The question event is the functionality that exposes the methods to the outside world. When a deva asks a question the string is parsed into a question format so that commands to access various methods can be exposed.
262
+
263
+ The `question(packet)` function is a default function that allows the system to ask questions of itself or other Deva.
264
+
265
+ The function checks the beginning of a string for a `#` to determine wether to issue a command to run a specific method.
266
+
267
+ See [Question Listener](#question) for usage.
268
+
269
+
270
+ ```javascript
271
+ // async await
272
+ const question = await this.question('#*agent_key* *method*:*params* *question string*');
273
+
274
+ // promises
275
+ this.question('#*agent_key* *method*:*params* *question string*').then(response => {
276
+ ...
277
+ }).catch(err => {
278
+ ...
279
+ })
280
+ ```
254
281
 
255
282
  ### uid()
256
283
  Generates a unique ID that is used in packet transfer and other various ways.
257
284
 
258
285
  ```javascript
259
286
  this.uid() // inside the object
260
- deva.uid() // outside the object
261
287
 
262
288
  // example
263
289
  this.vars.id = this.uid()
@@ -334,13 +360,13 @@ this.func.listener = packet => {
334
360
  ```
335
361
 
336
362
 
337
- ### Load(agent, opts)
363
+ ### load(agent, opts)
338
364
 
339
365
  To add a Deva dynamically use the `load()` function. This can be utilized to add Deva to an existing Deva after the object has already been created.
340
366
 
341
367
  ```javascript
342
368
  const opts = {
343
- me: {...},
369
+ agent: {...},
344
370
  vars: {...},
345
371
  listeners: {...},
346
372
  deva: {...},
@@ -362,18 +388,6 @@ this.unload('deva-key');
362
388
 
363
389
  ```
364
390
 
365
- ### question(packet)
366
- The `question(packet)` function is a default function that allows the system to ask questions of itself or other Deva.
367
-
368
- The function checks the beginning of a string for a `#` to determine wether to issue a command to run a specific method.
369
-
370
- See [Question Listener](#question) for usage.
371
-
372
- ```bash
373
- #deva method:params message
374
- ```
375
-
376
-
377
391
  ### status()
378
392
  The `status()` function will return the running status of the current Deva.
379
393
 
@@ -389,6 +403,8 @@ The `init()` function will initialize the Deva and run the `onInit()` state func
389
403
  ### initDeva()
390
404
  The `initDeva()` function will initialize the Deva located under the current Deva set. To be used in instances of a main Deva parent situation.
391
405
 
392
- -
406
+ ---
407
+
408
+ [Github Repo](https://github.com/indraai/deva)
393
409
  [Back to indra.ai](https://indra.ai)
394
410
  ©2021 Quinn Michaels; All Rights Reserved.
package/_config.yml ADDED
@@ -0,0 +1,7 @@
1
+ # Copyright 2022 Quinn Michaels.
2
+
3
+ author:
4
+ name: Quinn Michaels
5
+ email: "qce@indra.ai"
6
+
7
+ google_analytics: UA-126646842-1
package/index.js CHANGED
@@ -472,12 +472,12 @@ class Deva {
472
472
  return Promise.resolve({text});
473
473
  }
474
474
 
475
- // universal prompt emitter
475
+ // prompt emitter
476
476
  prompt(text) {
477
- this.talk('prompt', {text, prompt:this.agent.prompt});
477
+ this.talk('prompt', {text, agent:this.agent});
478
478
  }
479
479
 
480
- // universal hash builder
480
+ // hash builder
481
481
  hash(packet) {
482
482
  if (!this.vars.hash) this.vars.hash = '0x';
483
483
  // setup basic hashing
@@ -500,9 +500,9 @@ class Deva {
500
500
  });
501
501
  });
502
502
  }
503
- // initDeva interface is to initialize devas that this deva is a parent of.
503
+ // startDevas interface is to initialize devas that this deva is a parent of.
504
504
  // This feature allows a Deva to be a parent of a parent of a parent etc....
505
- initDevas() {
505
+ startDevas() {
506
506
  return new Promise((resolve, reject) => {
507
507
  const devas = [];
508
508
  for (let x in this.devas) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indra.ai/deva",
3
- "version": "1.0.31",
3
+ "version": "1.0.33",
4
4
  "description": "The Deva Core",
5
5
  "main": "index.js",
6
6
  "scripts": {