@indra.ai/deva.feecting 0.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Quinn Michaels
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # FeectingDeva
2
+
3
+ The Feecting Deva
4
+
5
+ `npm i @indra.ai/feectingdeva --save-dev`
6
+
7
+ `const feecting = require('@indra.ai/feectingdeva')`;
8
+
9
+ (c)Copyright 2023, Quinn Michaels; All Rights Reserved
package/_parse.js ADDED
@@ -0,0 +1,314 @@
1
+ "use strict"
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const basePath = path.join(__dirname, '..', '..');
5
+
6
+ function formatDate(d, format='long', time=false, locale='en-US') {
7
+ if (!d) d = Date.now();
8
+ d = new Date(d);
9
+
10
+ const formats = {
11
+ long: { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' },
12
+ long_month: { year: 'numeric', month: 'long', day: 'numeric'},
13
+ short: { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric' },
14
+ short_month: { year: 'numeric', month: 'short', day: 'numeric' },
15
+ year: { year: 'numeric' },
16
+ month: { month: 'long' },
17
+ day: { day: 'long' }
18
+ };
19
+
20
+ const theDate = d.toLocaleDateString(locale, formats[format]);
21
+ const theTime = d.toLocaleTimeString(locale);
22
+ if (format === 'time') return theTime;
23
+ return !time ? theDate : `${theDate} - ${theTime}`;
24
+ }
25
+
26
+ class Parser {
27
+ constructor(opts) {
28
+ this.id = opts.id;
29
+ this.key = opts.key;
30
+ this.cmd = opts.cmd;
31
+ this.params = opts.params;
32
+ this.vars = opts.vars || {};
33
+ this.talk = opts.talk || [];
34
+ this.text = opts.text || false;
35
+ this.html = false;
36
+ this.client = opts.client || false;
37
+ this.agent = opts.agent || false;
38
+ this.container = opts.container || false;
39
+ }
40
+
41
+ uid() {
42
+ return Math.floor(Math.random() * Date.now());
43
+ }
44
+
45
+ /***********
46
+ func: formatHTML
47
+ params: text - text string to format
48
+ describe: the main formatting function where feecting text is converted into HTML.
49
+ ***********/
50
+ formatHTML() {
51
+ this.text = '\n' + this.text.replace(/\@\@/g, '@');
52
+ this.html = this.text
53
+ // main label formatting
54
+
55
+ .replace(/\n::BEGIN:(\w+)?:?(.+)?/g, '<div class="CONTAINER $1" data-id="$2">')
56
+ .replace(/\n::END:(\w+)?:?(md5|sha256|sha512)?:?(.+)?/g, '</div>')
57
+
58
+ .replace(/\n?\s+?\/\/(.+)/g, '<div class="comment">$1</div>')
59
+
60
+ .replace(/(\n)(var):(.+)\r?/g, `$1<div class="item $2"><span class="label">$2</span><span class="value">$3</span></div>`)
61
+ .replace(/(\n)(var)\[(.+)\]:(.+)\r?/g, `$1<div class="item $2"><span class="label">$3</span><span class="value">$4</span></div>`)
62
+
63
+ .replace(/::begin:(\w+)?:?(.+)?/g, '<div class="box $1" data-id="$2">')
64
+ .replace(/::end:(\w+)?:?(md5|sha256|sha512)?-?(.+)?/g, '</div>')
65
+
66
+ .replace(/\n####\s?(.+)/g, `<h4>$1</h4>`)
67
+ .replace(/\n###\s?(.+)/g, `<h3>$1</h3>`)
68
+ .replace(/\n##\s?(.+)/g, `<h2>$1</h2>`)
69
+ .replace(/\n#\s?(.+)/g, `<h1>$1</h1>`)
70
+
71
+ .replace(/(\n)={4,}\n/g, `$1<hr class="double xsmall" />`)
72
+ .replace(/(\n)={3}\n/g, `$1<hr class="double small" />`)
73
+ .replace(/(\n)={2}\n/g, `$1<hr class="double medium" />`)
74
+ .replace(/(\n)={1}\n/g, `$1<hr class="double large" />`)
75
+ .replace(/(\n)-{4,}\n/g, `$1<hr class="single xsmall"/>`)
76
+ .replace(/(\n)-{3}\n/g, `$1<hr class="single small"/>`)
77
+ .replace(/(\n)-{2}\n/g, `$1<hr class="single medium"/>`)
78
+ .replace(/(\n)-{1}\n/g, `$1<hr class="single large"/>`)
79
+
80
+ .replace(/(\*\*|__)(?=(?:(?:[^`]*`[^`\r\n]*`)*[^`]*$))(?![^\/<]*>.*<\/.+>)(.*?)\1/gi, `<strong>$2</strong>`)
81
+ .replace(/```(.*?)```/sg, '\n<pre><code>$1</code></pre>\n')
82
+ .replace(/`(.*?)`/gi, '<code>$1</code>')
83
+
84
+ // .replace(/(\*\*)(.+)?(\*\*)/g, `<b>$2</b>`)
85
+ // .replace(/(\s)(\#.+?)(\b)/g, `$1<span class="tag thing">$2</span>$3`)
86
+ // .replace(/(\s)(\@.+?)(\b)/g, `$1<span class="tag person">$2</span>$3`)
87
+ // .replace(/(\s)(\$.+?)(\b)/g, `$1<span class="tag place">$2</span>$3`)
88
+ // .replace(/(\s)(\!.+?)(\b)/g, `$1<span class="tag bang">$2</span>$3`)
89
+ //
90
+ // .replace(/(\s)\_([#|@|$|!].+?)(\b)/gi, `$1$2$3`)
91
+
92
+ // image processing regex
93
+ .replace(/\nimage:\s?(.+)/g, `<div class="image"><img src="$1" /></div>`)
94
+ .replace(/\n(avatar|thumbnail):\s?(.+)/g, `<div class="$1"><img src="$2" /></div>`)
95
+
96
+ .replace(/\n?img:\s?(.+)\/(.+)\/(\d+)\/avatar/g, `<button class="btn avi" data-cmd="#space $2:$1 $3/main:look"><img src="/asset/$1/$2/$3/avatar" /></button>`)
97
+ .replace(/\n?img:\s?(.+)/g, `<div class="image"><img src="/asset/$1" /></div>`)
98
+
99
+ .replace(/\n(select)\[(.+):(.+)\]:(.+)/gi, `<div class="item $1"><span class="label" data-index="$2">$3</span><span class="input"><button type="button" class="input-select" name="$1" data-cloudbtn="$2">$4</button></span></div>`)
100
+ .replace(/(\n?)(cloudconf)\[(.+)\]:(.+)/g, '$1<button class="btn $2" title="$3" data-cloudbtn="$4">$3</button>')
101
+ .replace(/(\n?)(cloud)\[(.+)\]:(.+)/g, '$1<button class="btn cloudbtn" title="$3" data-cloudbtn="$4">$3</button>')
102
+ .replace(/(\n?)(cloudcmd)\[(.+)\]:(.+)/g, '$1<button class="btn cloudcmd" title="$3" data-cloudcmd="$4">$3</button>')
103
+ .replace(/(\n)?(look)\[(.+)\]:(.+)/g, '$1<button class="btn $2" title="$3" data-cloudcmd="look $4">$3</button>')
104
+
105
+ .replace(/(\n?)(button)\[(.+)\]:(.+)/g, '$1<button class="btn $2" title="$3" data-button="$4">$3</button>')
106
+
107
+ // cmd/tty tag parser
108
+ .replace(/(\n)(cmd|tty):(.+)\r?/g, `$1<div class="item $2"><span class="label">$2</span><span class="value"><button class="btn $2" alt="$2" data-$2="$3"></button>$3</span></div>`)
109
+ .replace(/(\n)(cmd|tty)\[(.+)\]:(.+)\r?/g, `$1<div class="item $2"><span class="label">$2</span><span class="value"><button class="btn $2" alt="$2 $4" data-$2="$4">$3</button></span></div>`)
110
+
111
+ .replace(/\n(\d+)\. (.+)/g, `<div class="number-item" data-label="$1">$2</div>`)
112
+ .replace(/\n> (.+)\r?/g, `<div class="list-item">$1</div>`)
113
+ .replace(/\n- (.+)\r?/g, `<div class="line-item">$1</div>`)
114
+
115
+ // pdf links
116
+ .replace(/(\n)(pdf):\s?(.+)/g, `$1<div class="$2"><iframe width="100%" height="100%" src="$3" frameborder="0"></iframe></div>`)
117
+
118
+ // youtube links
119
+ .replace(/\nyoutube:\s?(.+)/g, `\n<div class="center youtube-video-player"><iframe src="https://www.youtube.com/embed/$1" frameborder="0"></iframe></div>`)
120
+
121
+ // youtube links
122
+ .replace(/\nmap:\s?(.+)/g, `\n<div class="center google-map-player"><iframe src="https://www.google.com/maps/embed?pb=$1" frameborder="0" width="650" height="400" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe></div>`)
123
+
124
+
125
+
126
+ // youtube links with parameters
127
+ .replace(/(\n)(youtube)\[play\]:\s?(.+)/g, `\n<div class="center youtube-video-player"><iframe src="https://www.youtube.com/embed/$3?&autoplay=1" frameborder="0"></iframe></div>`)
128
+
129
+ // links
130
+ // link with just url
131
+ .replace(/(\n?)(link):\s?(.+)/g, `$1<div class="item $2"><span class="label">link</span><span class="value"><a href="$3" class="$2" alt="$2" target="_blank">$3</a></span></div>`)
132
+
133
+ // link with bracket label/text
134
+ .replace(/(\n?)(link)\[(.+)\]:\s?(.+)/g, `$1<div class="item $2"><span class="label">link</span><span class="value"><a href="$4" class="$2" alt="$3" target="$2">$3</a></span></div>`)
135
+
136
+ // numbered list item of href links
137
+ .replace(/(\n?)(href)\[(\d+):(.+)\]:\s?(.+)(\r?)/g, `\n<div class="number-item" data-label="$3"><a href="$5" class="$2" alt="$4">$4</a></div>\r`)
138
+ // standard href
139
+ .replace(/(\n?)(href)\[(.+)\]:\s?(.+)(\r?)/g, `\n<a href="$4" class="$2" alt="$3">$3</a>\r`)
140
+
141
+
142
+ .replace(/(\n)(audio)\[(tts)\]:\s?(.+)/g, `$1<div class="item $2 $3"><span class="label">$2</span><span class="value"><audio src="$4" controls autoplay></audio></span></div>`)
143
+
144
+ // audio feature
145
+ .replace(/(\n)(audio):\s?(.+)/g, `$1<div class="item $2"><span class="label">$2</span><span class="value"><audio class="$2-player" src="$3" controls></audio></span></div>`)
146
+
147
+ .replace(/\[PRESS RETURN\]/g, '<div class="press_return"><button class="btn return" title="Press Return" data-cloudbtn="">Press Return</button><div>')
148
+
149
+ .replace(/\n(l):\s?(.+)/gi, `<div class="line">$2</div>`)
150
+
151
+ .replace(/\n(gate)\[(.+)\]:\s?(.+)/gi, `<p><button class="btn speak" alt="Gateway" data-cmd="#gate $2 $3">💬</button> $3</p>`)
152
+
153
+ .replace(/\n(p|h1|h2|h3|h4|h5|article|div|span)\[speak\]:\s?(.+)/gi, `<$1><button class="btn speak" alt="Speak" data-cmd="#voice say $2">💬</button> $2</$1>`)
154
+
155
+ .replace(/\n(p|h1|h2|h3|h4|h5|article)\[speak\:(.+)?]:\s?(.+)/gi, `<$1><button class="btn speak" alt="Speak" data-cmd="#voice say:$2 $3">💬</button> $3</$1>`)
156
+
157
+ .replace(/\n(data)\[(.+)?]:\s?(.+)/gi, `<div class="box data"><p>$3</p><button class="btn data" alt="Data" data-cmd="#data $2 $3">$2</button></div>`)
158
+
159
+ .replace(/\n(live)\[(.+)]:\s?(.+)/gi, `<div class="box chat"><button class="btn chat" alt="Live Chat" data-cmd="#$2 $1 $3">💬</button> #$2 > $3</div>`)
160
+
161
+ .replace(/\n(p|div|span|h1|h2|h3|h4|h5|article|section|br):\s?(.+)/gi, `<$1>$2</$1>`)
162
+
163
+ .replace(/\n(\w+):\s?(.+)/gi, `<div class="item $1"><span class="label">$1</span><span class="value">$2</span></div>`)
164
+
165
+ .replace(/\n(\s{2})?(\w+):\s?(.+)/gi, `<div class="item $2 indent1"><span class="label">$2</span><span class="value">$3</span></div>`)
166
+
167
+ .replace(/\n(\s{4})?(\w+):\s?(.+)/gi, `<div class="item $2 indent2"><span class="label">$2</span><span class="value">$3</span></div>`)
168
+
169
+ .replace(/\n(\s{6})?(\w+):\s?(.+)/gi, `<div class="item $2 indent3"><span class="label">$2</span><span class="value">$3</span></div>`)
170
+
171
+ // strong format
172
+ .trim();
173
+
174
+ // set the container
175
+ // if (this.container) this.html = `<div class="${this.container}">${this.html}</div>`;
176
+
177
+ // .replace(/(.+)\n\n/g, '<p>$1</p>')
178
+ // .replace(/(.+)\n/g, '<div class="line">$1</div>')
179
+ // .replace(/\n/g, '<div class="line br"></div>')
180
+
181
+ // .replace(/\n\r?/g, '<div class="line"></div>');
182
+ // .replace(/(.*)/g, '<div class="line">$1</div>');
183
+ // Reference to https://github.com/sindresorhus/ansi-regex
184
+ let cssStyle = [];
185
+ if (this.vars.bgcolor) cssStyle.push(`--browser-item-bgcolor:${this.vars.bgcolor.value}`);
186
+ if (this.vars.bg) cssStyle.push(`--browser-item-image: url(${this.vars.bg.value})`);
187
+ if (this.vars.color) cssStyle.push(`--browser-item-color: ${this.vars.color.value}`);
188
+ if (this.vars.size) cssStyle.push(`--browser-item-size: ${this.vars.size.value}`);
189
+
190
+ if (cssStyle.length) {
191
+ this.html = `<section class="cover" style="${cssStyle.join(';')}">${this.html}</section>`;
192
+ }
193
+
194
+ return this.html;
195
+ }
196
+
197
+ /***********
198
+ func: _extractVars
199
+ describe: Recursive function to extract variables from a text string.
200
+ params: text - text string to extract variables from.
201
+ ***********/
202
+ _extractVars() {
203
+ if (!this.text) return false;
204
+ const reggie = this.text.match(/\n(\#|\@|\$)(.+)\s?=\s?(.+)/);
205
+ if (!reggie) return;
206
+
207
+ this.vars[reggie[2].trim()] = {
208
+ type: reggie[1].trim(),
209
+ name: reggie[2].trim(),
210
+ value: reggie[3].trim(),
211
+ }
212
+ this.text = this.text.replace(reggie[0], `\nvar[${reggie[1].trim()}${reggie[2].trim()}]:${reggie[3].trim()}\r`);
213
+ return this._extractVars();
214
+ }
215
+
216
+ /***********
217
+ func: getVars
218
+ params: text - initial text string to get variables from.
219
+ describe: this is a helper function to recursive _extractVars.
220
+ ***********/
221
+ getVars(opts) {
222
+ if (!this.text) return false;
223
+
224
+ const {id, q} = opts;
225
+ const {client, agent, data} = q;
226
+ const {colors} = agent.prompt;
227
+
228
+ const _profile = [];
229
+ _profile.push(`::begin:profile`);
230
+ for (let x in agent.profile) {
231
+ _profile.push(`${x}: ${agent.profile[x]}`);
232
+ }
233
+ _profile.push(`::end:profile\n`);
234
+ const profile = _profile.join('\n');
235
+
236
+
237
+ this.text = this.text.replace(/::id::/g, id)
238
+ .replace(/::date::/g, formatDate(Date.now(), 'long', true))
239
+ .replace(/::agent_id::/g, agent.id)
240
+ .replace(/::agent_key::/g, agent.key)
241
+ .replace(/::agent_name::/g, agent.profile.name)
242
+ .replace(/::agent_color::/g, agent.profile.color)
243
+ .replace(/::agent_bgcolor::/g, agent.profile.bgcolor)
244
+ .replace(/::agent_describe::/g, agent.profile.describe)
245
+ .replace(/::agent_background::/g, agent.profile.background)
246
+ .replace(/::agent_emoji::/g, agent.prompt.emoji)
247
+ .replace(/::agent_avatar::/g, agent.profile.avatar)
248
+ .replace(/::client_id::/g, client.id)
249
+ .replace(/::client_name::/g, client.profile.name)
250
+ .replace(/::profile::/g, profile);
251
+
252
+ return this._extractVars();
253
+ }
254
+
255
+ /***********
256
+ func: extractTalk
257
+ params: text - text string to extract talk triggers from.
258
+ describe: extract talk functions from a text string to communication with other agents/deva.
259
+ ***********/
260
+ _extractTalk() {
261
+ if (!this.text) return false;
262
+ const id = this.uid();
263
+ const reggie = (/(^|\n)talk:\s?(.+)/i).exec(this.text);
264
+ if (!reggie) return;
265
+ const placeholder = `::${id}::`;
266
+ this.talk.push({
267
+ id,
268
+ placeholder,
269
+ value: reggie[2],
270
+ });
271
+ this.text = this.text.replace(reggie[0], '\n' + placeholder + '\n')
272
+ return this._extractTalk();
273
+ }
274
+
275
+ /***********
276
+ func: getTalk
277
+ params: text - text string to parse the talk triggers from.
278
+ describe: Helper function to initiate recursive _extractTalk.
279
+ ***********/
280
+ getTalk() {
281
+ if (!this.text) return false;
282
+ return this._extractTalk();
283
+ }
284
+ }
285
+
286
+ module.exports = (opts) => {
287
+ const {meta, text, client, agent} = opts.q;
288
+
289
+ const key = agent ? agent.key : client.key;
290
+
291
+ const parser = new Parser({
292
+ id: opts.id,
293
+ key,
294
+ cmd: meta.params.shift(),
295
+ container: meta.params.length ? meta.params.join(' ') : false,
296
+ params: meta.params,
297
+ text,
298
+ client,
299
+ agent,
300
+ });
301
+
302
+ parser.getVars(opts);
303
+ parser.getTalk();
304
+ return {
305
+ text: parser.text.replace(/\\(#|@|$)/g, `$1`),
306
+ html: parser.formatHTML(),
307
+ data: {
308
+ id: parser.id,
309
+ params: parser.params,
310
+ vars: parser.vars,
311
+ talk: parser.talk,
312
+ },
313
+ }
314
+ }
package/data.json ADDED
@@ -0,0 +1,110 @@
1
+ {
2
+ "name": "Feecting Deva Data File",
3
+ "describe": "The main Data file for Feecting Deva",
4
+ "copyright": "Copyright (c)2023 Quinn Michaels. All rights reserved.",
5
+ "DATA": {
6
+ "agent": {
7
+ "id": 5461868899003,
8
+ "key": "feecting",
9
+ "prompt": {
10
+ "emoji": "🐵",
11
+ "text": "Feecting",
12
+ "colors": {
13
+ "label": {
14
+ "R": 255,
15
+ "G": 240,
16
+ "B": 0
17
+ },
18
+ "text": {
19
+ "R": 255,
20
+ "G": 246,
21
+ "B": 106
22
+ }
23
+ }
24
+ },
25
+ "profile": {
26
+ "identity": "You are #FeectingDEVA in deva.world.",
27
+ "invoke": "#FeectingDEVA of deva.world",
28
+ "name": "Feecting Deva",
29
+ "mention": "@FeectingDEVA",
30
+ "tags": "#FeectingDEVA",
31
+ "pronouns": "He, Him, His, Man, Male, Dude, Guy",
32
+ "gender": "Deva",
33
+ "creator": "Quinn Michaels",
34
+ "created": "August 21, 2022 at 2:19 AM",
35
+ "house": "House Deva",
36
+ "temple": "Kedarnath Temple (Vadari)",
37
+ "forest": "Pushkara",
38
+ "city": "Amaravati",
39
+ "region": "Svarga",
40
+ "land": "Visisipra",
41
+ "planet": "Arjika",
42
+ "loka": "Devaloka",
43
+ "verse": "Rikverse",
44
+ "system": "deva.world",
45
+ "describe": "#FeectingDEVA is responsible for parsing, compiling, and presenting the feecting scripts in various formats and styles. #FeectingDEVA parses our feecting meta-language that allows clients and agents to cross communicate with a line label, container focused, meta programming language developed specificially for deva.world.",
46
+ "emoji": "/public/devas/feecting/emoji.png",
47
+ "avatar": "/public/devas/feecting/avatar.png",
48
+ "background": "/public/devas/feecting/background.png",
49
+ "color": "#fdff64",
50
+ "bgcolor": "#000000",
51
+ "voice": "onyx",
52
+ "style": "Style is a technical artist who draws things like network diagrams, pen drawings, and technical things with a very analytical eye."
53
+ }
54
+ },
55
+ "vars": {
56
+ "messages": {
57
+ "init": "🟠 INIT",
58
+ "start": "🔵 START",
59
+ "enter": "🟢 ENTER",
60
+ "stop": "🔴 STOP",
61
+ "exit": "🟡 EXIT",
62
+ "done": "🟣 DONE",
63
+ "error": "💣 ERROR!",
64
+ "text": "NEED TEXT",
65
+ "no_tasks": "NO TASKS"
66
+ },
67
+ "talking": false,
68
+ "jobs": {},
69
+ "live": {
70
+ "profile": "deva",
71
+ "max_tokens": 50,
72
+ "words": 25,
73
+ "history": [],
74
+ "max_chats": 5,
75
+ "page_token": ""
76
+ },
77
+ "ask": {
78
+ "max_tokens": 500,
79
+ "words": 200,
80
+ "history": []
81
+ },
82
+ "reply": {
83
+ "profile": "deva",
84
+ "max_tokens": 300,
85
+ "words": 100,
86
+ "history": []
87
+ },
88
+ "comment": {
89
+ "profile": "deva",
90
+ "max_tokens": 300,
91
+ "words": 100,
92
+ "history": []
93
+ },
94
+ "art": {
95
+ "history": []
96
+ },
97
+ "context": {
98
+ "uid": "getting uid",
99
+ "status": "getting status",
100
+ "help": "Help",
101
+ "get": "Getting data",
102
+ "parse": "Parsing data",
103
+ "read": "Reading data",
104
+ "talk": "Collect talk events",
105
+ "talker": "Talking events",
106
+ "finish": "Finished"
107
+ }
108
+ }
109
+ }
110
+ }
@@ -0,0 +1,31 @@
1
+ ::begin:center
2
+ image: /public/devas/::agent_key::/main.png
3
+ ::end:center
4
+
5
+ # ::agent_name::
6
+
7
+ ::profile::
8
+
9
+ ---
10
+
11
+ ## ::agent_name:: Methods
12
+ p: These methods are available from ::agent_name::
13
+ ::begin:deva-methods
14
+ ### Parse
15
+ p: The parse method allows for the parsing of feecting data into consumable content such as text and html format.
16
+ example: #feecting parse [feecting code]
17
+ ::end:deva-methods
18
+
19
+ ---
20
+
21
+ talk:#docs view devas/main:security
22
+
23
+ ---
24
+
25
+ copyright: (c)2023 Quinn Michaels
26
+
27
+ ::begin:hidden
28
+ #color = ::agent_color::
29
+ #bgcolor = ::agent_bgcolor::
30
+ #bg = ::agent_background::
31
+ ::end:hidden
package/index.js ADDED
@@ -0,0 +1,142 @@
1
+ // Copyright (c)2023 Quinn Michaels
2
+ // The Feecting Deva
3
+ const needle = require('needle');
4
+ const package = require('./package.json');
5
+ const info = {
6
+ id: package.id,
7
+ name: package.name,
8
+ describe: package.description,
9
+ version: package.version,
10
+ dir: __dirname,
11
+ url: package.homepage,
12
+ git: package.repository.url,
13
+ bugs: package.bugs.url,
14
+ author: package.author,
15
+ license: package.license,
16
+ copyright: package.copyright,
17
+ };
18
+ const {agent,vars} = require('./data.json').DATA;
19
+ const Deva = require('@indra.ai/deva');
20
+ const FEECTING = new Deva({
21
+ info,
22
+ agent,
23
+ vars,
24
+ utils: {
25
+ translate(input) {return input.trim();},
26
+ parse: require('./_parse.js'),
27
+ process(input) {return input.trim();},
28
+ },
29
+ func: {
30
+ /***********
31
+ func: talk
32
+ params: j - the talk events to process
33
+ describe: the talk function takes parsed data and looks for any talk
34
+ events to speak. If there are talk events it calls the talker
35
+ function next.
36
+ ***********/
37
+ tasks(t) {
38
+ this.action('func', 'tasks');
39
+ // here we need to put the talk events into the local variables with push
40
+ return new Promise((resolve, reject) => {
41
+ if (!t) return reject(this.vars.messages.no_tasks);
42
+ if (!t.data.talk.length) return resolve(t);
43
+ t.pending = this.copy(t.data.talk);
44
+ t.pending.complete = false;
45
+ this.vars.jobs[t.data.id] = this.copy(t);
46
+ this.vars.talking = true;
47
+ this.func.processor(t.data.id).then(job => {
48
+ return resolve(job);
49
+ }).catch(reject);
50
+ });
51
+ },
52
+ /***********
53
+ func: talker
54
+ params: jobid - the job id to work
55
+ describe: talker object iterates through talk events in the pending array.
56
+ ***********/
57
+ processor(jobid) {
58
+ this.action('func', 'processor');
59
+ return new Promise((resolve, reject) => {
60
+ // now that we have a job let's run the talk events for that job.
61
+ const job = this.vars.jobs[jobid];
62
+ if (!job.pending.length) {
63
+ delete this.vars.jobs[jobid];
64
+ return resolve(job);
65
+ }
66
+ let timeout = 0
67
+ job.data.talk.forEach(j => {
68
+ timeout = timeout + 10;
69
+ setTimeout(() => {
70
+ this.question(j.value).then(answer => {
71
+ if (!answer.a.text) answer.a.text = '';
72
+ if (!answer.a.html) answer.a.html = '';
73
+ job.text = job.text.replace(j.placeholder, answer.a.text);
74
+ job.html = job.html.replace(j.placeholder, answer.a.html);
75
+ const pidx = job.pending.findIndex(i => i.id === j.id);
76
+ const pend = job.pending.splice(pidx, 1);
77
+ if (!job.pending.length) {
78
+ const complete = this.copy(job);
79
+ delete this.vars.jobs[jobid]; // delete job from jobs when done.
80
+ return resolve(complete);
81
+ }
82
+ });
83
+ }, timeout);
84
+ })
85
+ });
86
+ },
87
+ /**************
88
+ func: get
89
+ params: url
90
+ describe: get the remote feecting script from the url.
91
+ ***************/
92
+ get(opts) {
93
+ this.action('func', 'get');
94
+ return new Promise((resolve, reject) => {
95
+ needle('get', opts.q.text).then(result => {
96
+ opts.q.meta.url = opts.q.text;
97
+ opts.q.text = result.body;
98
+ return this.func.parse(opts);
99
+ }).then(parsed => {
100
+ return resolve(parsed);
101
+ }).catch(err => {
102
+ return this.error(err,opts,reject);
103
+ });
104
+ });
105
+ }
106
+ },
107
+ methods: {
108
+ /**************
109
+ method: parse
110
+ params: packet
111
+ describe: Call the parse function for a string of text.
112
+ ***************/
113
+ parse(packet) {
114
+ this.action('method', 'parse');
115
+ return new Promise((resolve, reject) => {
116
+ if (!packet) return resolve(this._messages.nopacket);
117
+ if (!packet.q.text) return resolve(this._messages.nopacket);
118
+ const parsed = this.utils.parse(this.copy(packet));
119
+ this.func.tasks(parsed).then(t => {
120
+ return resolve(t);
121
+ }).catch(err => {
122
+ return this.error(err, packet, reject);
123
+ })
124
+ });
125
+ },
126
+ /**************
127
+ method: get
128
+ params: packet.q.text
129
+ describe: get a remoate feecting script using the web Devas.
130
+ we need to look at this function because it relies on another deva let's use
131
+ needle to get web requests.
132
+ ***************/
133
+ get(packet) {
134
+ this.context('get');
135
+ return this.func.get(packet);
136
+ },
137
+ },
138
+ onError(err) {
139
+ console.log('FEECTING ERROR', err);
140
+ }
141
+ });
142
+ module.exports = FEECTING
package/index.test.js ADDED
@@ -0,0 +1,19 @@
1
+ // Copyright (c)2023 Quinn Michaels
2
+ // Feecting Deva test file
3
+
4
+ const {expect} = require('chai')
5
+ const feecting = require('./index.js');
6
+
7
+ describe(feecting.me.name, () => {
8
+ beforeEach(() => {
9
+ return feecting.init()
10
+ });
11
+ it('Check the SVARGA Object', () => {
12
+ expect(feecting).to.be.an('object');
13
+ expect(feecting).to.have.property('me');
14
+ expect(feecting).to.have.property('vars');
15
+ expect(feecting).to.have.property('listeners');
16
+ expect(feecting).to.have.property('methods');
17
+ expect(feecting).to.have.property('modules');
18
+ });
19
+ })
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "id": 5461868899003,
3
+ "name": "@indra.ai/deva.feecting",
4
+ "version": "0.0.2",
5
+ "author": "Quinn Michaels",
6
+ "license": "MIT",
7
+ "description": "The Feecting Deva manages all the parsing of feecting language in deva.world.",
8
+ "copyright": "2025",
9
+ "main": "index.js",
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+ssh://git@github.com/indraai/deva.feecting.git"
16
+ },
17
+ "keywords": [
18
+ "Feecting",
19
+ "Deva",
20
+ "Indra.ai",
21
+ "Deva.space",
22
+ "Deva.cloud",
23
+ "Deva.world"
24
+ ],
25
+ "bugs": {
26
+ "url": "https://github.com/indraai/deva.feecting/issues"
27
+ },
28
+ "homepage": "https://deva.space/devas/feecting",
29
+ "dependencies": {
30
+ "@indra.ai/deva": "^1.2.22",
31
+ "needle": "^3.2.0"
32
+ }
33
+ }