@adminforth/text-complete 1.2.0 → 1.2.1

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/build.log CHANGED
@@ -9,5 +9,5 @@ custom/package-lock.json
9
9
  custom/package.json
10
10
  custom/tsconfig.json
11
11
 
12
- sent 16,559 bytes received 96 bytes 33,310.00 bytes/sec
12
+ sent 16,564 bytes received 96 bytes 33,320.00 bytes/sec
13
13
  total size is 16,206 speedup is 0.97
package/dist/index.js CHANGED
@@ -92,7 +92,18 @@ export default class TextCompletePlugin extends AdminForthPlugin {
92
92
  }
93
93
  else {
94
94
  if (this.options.initialPrompt) {
95
- content = `${this.options.initialPrompt}\n` +
95
+ // initial prompt might have mustache syntax for current record value (several fields)
96
+ // use regex to replace it with current record value
97
+ const regex = /{{([^}]+)}}/g;
98
+ const interpretedPrompt = this.options.initialPrompt.replace(regex, (match, p1) => {
99
+ const fieldName = p1.trim();
100
+ const fieldValue = record[fieldName];
101
+ if (fieldValue) {
102
+ return fieldValue;
103
+ }
104
+ return match;
105
+ });
106
+ content = `${interpretedPrompt}\n` +
96
107
  "No quotes. Don't talk to me. Just write text\n";
97
108
  }
98
109
  else {
package/index.ts CHANGED
@@ -121,7 +121,20 @@ export default class TextCompletePlugin extends AdminForthPlugin {
121
121
  } else {
122
122
 
123
123
  if (this.options.initialPrompt) {
124
- content = `${this.options.initialPrompt}\n` +
124
+ // initial prompt might have mustache syntax for current record value (several fields)
125
+ // use regex to replace it with current record value
126
+ const regex = /{{([^}]+)}}/g;
127
+ const interpretedPrompt = this.options.initialPrompt.replace(regex, (match, p1) => {
128
+ const fieldName = p1.trim();
129
+ const fieldValue = record[fieldName];
130
+ if (fieldValue) {
131
+ return fieldValue;
132
+ }
133
+ return match;
134
+ });
135
+
136
+
137
+ content = `${interpretedPrompt}\n` +
125
138
  "No quotes. Don't talk to me. Just write text\n";
126
139
  } else {
127
140
  content = `Fill text/string field "${this.options.fieldName}" in the table "${resLabel}"\n` +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/text-complete",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Text completion plugin for adminforth",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",