@indra.ai/deva.feecting 0.11.30 → 0.11.32

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/_parse.js +51 -32
  2. package/package.json +2 -2
package/_parse.js CHANGED
@@ -178,25 +178,6 @@ class Parser {
178
178
  return this.html;
179
179
  }
180
180
 
181
- /***********
182
- func: _extractVars
183
- describe: Recursive function to extract variables from a text string.
184
- params: text - text string to extract variables from.
185
- ***********/
186
- _extractVars() {
187
- if (!this.text) return false;
188
- const reggie = this.text.match(/\n\s*(\#|\@|\$)(.+)\s?=\s?(.+)/);
189
- if (!reggie) return;
190
-
191
- this.vars[reggie[2].trim()] = {
192
- type: reggie[1].trim(),
193
- name: reggie[2].trim(),
194
- value: reggie[3].trim(),
195
- }
196
- this.text = this.text.replace(reggie[0], `\nvar[${reggie[1].trim()}${reggie[2].trim()}]:${reggie[3].trim()}\r`);
197
- return this._extractVars();
198
- }
199
-
200
181
  /***********
201
182
  func: getVars
202
183
  params: text - initial text string to get variables from.
@@ -216,22 +197,59 @@ class Parser {
216
197
  }
217
198
  _profile.push(`::end:profile\n`);
218
199
  const profile = _profile.join('\n');
200
+
201
+ const lookup = {
202
+ client,
203
+ agent,
204
+ prompt: agent.prompt,
205
+ profile: agent.profile,
206
+ vars: data.vars,
207
+ }
219
208
 
220
-
209
+ function processVars(token, data) {
210
+ // first we split the token on the dot notation.
211
+ const token_arr = token.split('.');
212
+ // then if the token is only one length just return the value
213
+ let current = data;
214
+ token_arr.forEach(item => {
215
+ if (!current[item]) return false;
216
+ current = current[item];
217
+ });
218
+
219
+ current = current.replace(/\{\{(client|agent|profile|prompt|vars)\.(.+?)\}\}/g, (match, scope, token) => {
220
+ return processVars(token, lookup[scope]);
221
+ });
222
+
223
+ return current;
224
+ }
225
+
221
226
  this.text = this.text.replace(/\{\{id\}\}/g, id)
222
- .replace(/\{\{today\}\}/g, formatDate(Date.now(), 'long', true))
223
-
224
- .replace(/\{\{client\.(\w+)\}\}/g, (match,token) => {
225
- return client[token] || false;
226
- }).replace(/\{\{agent\.(\w+)\}\}/g, (match,token) => {
227
- return agent[token] || false;
228
- }).replace(/\{\{profile\.(\w+)\}\}/g, (match,token) => {
229
- return agent.profile[token] || false;
230
- }).replace(/\{\{prompt\.(\w+)\}\}/g, (match,token) => {
231
- return agent.prompt[token] || false;
227
+ .replace(/\{\{today\}\}/g, formatDate(Date.now(), 'long', true))
228
+ .replace(/\{\{(client|agent|profile|prompt|vars)\.(.+?)\}\}/g, (match, scope, token) => {
229
+ return processVars(token, lookup[scope]);
232
230
  }).replace(/\{\{profile\}\}/g, (match,token) => {
233
231
  return profile || false;
234
232
  });
233
+ // when all the default variables and values are set then extract the vars in the local text.
234
+ return this._extractVars();
235
+ }
236
+
237
+ /***********
238
+ func: _extractVars
239
+ describe: Recursive function to extract variables from a text string.
240
+ params: text - text string to extract variables from.
241
+ ***********/
242
+ _extractVars() {
243
+ if (!this.text) return false;
244
+ const reggie = this.text.match(/\n\s*(\#|\@|\$)(.+)\s?=\s?(.+)/);
245
+ if (!reggie) return;
246
+
247
+ this.vars[reggie[2].trim()] = {
248
+ type: reggie[1].trim(),
249
+ name: reggie[2].trim(),
250
+ value: reggie[3].trim(),
251
+ }
252
+ this.text = this.text.replace(reggie[0], `\nvar[${reggie[1].trim()}${reggie[2].trim()}]:${reggie[3].trim()}\r`);
235
253
  return this._extractVars();
236
254
  }
237
255
 
@@ -267,8 +285,8 @@ class Parser {
267
285
  }
268
286
 
269
287
  export default (opts) => {
270
- const {meta, text, client, agent} = opts.q;
271
-
288
+ const {meta, text, client, agent, data} = opts.q;
289
+ const vars = data.vars || {};
272
290
  const key = agent ? agent.key : client.key;
273
291
 
274
292
  const parser = new Parser({
@@ -280,6 +298,7 @@ export default (opts) => {
280
298
  text: text.replace(/(\n)(\s*)(\W|\b)/g, '$1$3'),
281
299
  client,
282
300
  agent,
301
+ vars,
283
302
  });
284
303
 
285
304
  parser.getVars(opts);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "52583635952527737176",
3
3
  "name": "@indra.ai/deva.feecting",
4
- "version": "0.11.30",
4
+ "version": "0.11.32",
5
5
  "license": "VLA:52583635952527737176 LICENSE.md",
6
6
  "VLA": {
7
7
  "uid": "52583635952527737176",
@@ -57,7 +57,7 @@
57
57
  },
58
58
  "homepage": "https://indra.ai",
59
59
  "dependencies": {
60
- "@indra.ai/deva": "^1.29.28",
60
+ "@indra.ai/deva": "^1.29.31",
61
61
  "needle": "^3.2.0"
62
62
  },
63
63
  "data": {