@promptbook/utils 0.86.10 → 0.86.22

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/umd/index.umd.js CHANGED
@@ -15,14 +15,14 @@
15
15
  * @generated
16
16
  * @see https://github.com/webgptorg/book
17
17
  */
18
- var BOOK_LANGUAGE_VERSION = '1.0.0';
18
+ const BOOK_LANGUAGE_VERSION = '1.0.0';
19
19
  /**
20
20
  * The version of the Promptbook engine
21
21
  *
22
22
  * @generated
23
23
  * @see https://github.com/webgptorg/promptbook
24
24
  */
25
- var PROMPTBOOK_ENGINE_VERSION = '0.86.10';
25
+ const PROMPTBOOK_ENGINE_VERSION = '0.86.22';
26
26
  /**
27
27
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
28
28
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -35,32 +35,32 @@
35
35
  *
36
36
  * @public exported from `@promptbook/core`
37
37
  */
38
- var NAME = "Promptbook";
38
+ const NAME = `Promptbook`;
39
39
  /**
40
40
  * Email of the responsible person
41
41
  *
42
42
  * @public exported from `@promptbook/core`
43
43
  */
44
- var ADMIN_EMAIL = 'pavol@ptbk.io';
44
+ const ADMIN_EMAIL = 'pavol@ptbk.io';
45
45
  /**
46
46
  * Name of the responsible person for the Promptbook on GitHub
47
47
  *
48
48
  * @public exported from `@promptbook/core`
49
49
  */
50
- var ADMIN_GITHUB_NAME = 'hejny';
50
+ const ADMIN_GITHUB_NAME = 'hejny';
51
51
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
52
52
  /**
53
53
  * The maximum number of iterations for a loops
54
54
  *
55
55
  * @private within the repository - too low-level in comparison with other `MAX_...`
56
56
  */
57
- var LOOP_LIMIT = 1000;
57
+ const LOOP_LIMIT = 1000;
58
58
  /**
59
59
  * Strings to represent various values in the context of parameter values
60
60
  *
61
61
  * @public exported from `@promptbook/utils`
62
62
  */
63
- var VALUE_STRINGS = {
63
+ const VALUE_STRINGS = {
64
64
  empty: '(nothing; empty string)',
65
65
  null: '(no value; null)',
66
66
  undefined: '(unknown value; undefined)',
@@ -74,7 +74,7 @@
74
74
  *
75
75
  * @public exported from `@promptbook/utils`
76
76
  */
77
- var SMALL_NUMBER = 0.001;
77
+ const SMALL_NUMBER = 0.001;
78
78
  // <- TODO: [🧜‍♂️]
79
79
  /**
80
80
  * @@@
@@ -92,136 +92,43 @@
92
92
  * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
93
93
  */
94
94
 
95
- /*! *****************************************************************************
96
- Copyright (c) Microsoft Corporation.
97
-
98
- Permission to use, copy, modify, and/or distribute this software for any
99
- purpose with or without fee is hereby granted.
100
-
101
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
102
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
103
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
104
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
105
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
106
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
107
- PERFORMANCE OF THIS SOFTWARE.
108
- ***************************************************************************** */
109
- /* global Reflect, Promise */
110
-
111
- var extendStatics = function(d, b) {
112
- extendStatics = Object.setPrototypeOf ||
113
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
114
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
115
- return extendStatics(d, b);
116
- };
117
-
118
- function __extends(d, b) {
119
- if (typeof b !== "function" && b !== null)
120
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
121
- extendStatics(d, b);
122
- function __() { this.constructor = d; }
123
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
124
- }
125
-
126
- var __assign = function() {
127
- __assign = Object.assign || function __assign(t) {
128
- for (var s, i = 1, n = arguments.length; i < n; i++) {
129
- s = arguments[i];
130
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
131
- }
132
- return t;
133
- };
134
- return __assign.apply(this, arguments);
135
- };
136
-
137
- function __awaiter(thisArg, _arguments, P, generator) {
138
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
139
- return new (P || (P = Promise))(function (resolve, reject) {
140
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
141
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
142
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
143
- step((generator = generator.apply(thisArg, _arguments || [])).next());
144
- });
145
- }
146
-
147
- function __generator(thisArg, body) {
148
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
149
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
150
- function verb(n) { return function (v) { return step([n, v]); }; }
151
- function step(op) {
152
- if (f) throw new TypeError("Generator is already executing.");
153
- while (_) try {
154
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
155
- if (y = 0, t) op = [op[0] & 2, t.value];
156
- switch (op[0]) {
157
- case 0: case 1: t = op; break;
158
- case 4: _.label++; return { value: op[1], done: false };
159
- case 5: _.label++; y = op[1]; op = [0]; continue;
160
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
161
- default:
162
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
163
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
164
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
165
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
166
- if (t[2]) _.ops.pop();
167
- _.trys.pop(); continue;
168
- }
169
- op = body.call(thisArg, _);
170
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
171
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
172
- }
173
- }
174
-
175
- function __values(o) {
176
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
177
- if (m) return m.call(o);
178
- if (o && typeof o.length === "number") return {
179
- next: function () {
180
- if (o && i >= o.length) o = void 0;
181
- return { value: o && o[i++], done: !o };
182
- }
183
- };
184
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
185
- }
186
-
187
- function __read(o, n) {
188
- var m = typeof Symbol === "function" && o[Symbol.iterator];
189
- if (!m) return o;
190
- var i = m.call(o), r, ar = [], e;
191
- try {
192
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
193
- }
194
- catch (error) { e = { error: error }; }
195
- finally {
196
- try {
197
- if (r && !r.done && (m = i["return"])) m.call(i);
198
- }
199
- finally { if (e) throw e.error; }
200
- }
201
- return ar;
202
- }
203
-
204
- function __spreadArray(to, from, pack) {
205
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
206
- if (ar || !(i in from)) {
207
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
208
- ar[i] = from[i];
209
- }
210
- }
211
- return to.concat(ar || Array.prototype.slice.call(from));
212
- }
213
-
214
95
  /**
215
96
  * Make error report URL for the given error
216
97
  *
217
98
  * @private private within the repository
218
99
  */
219
100
  function getErrorReportUrl(error) {
220
- var report = {
221
- title: "\uD83D\uDC1C Error report from ".concat(NAME),
222
- body: spaceTrim__default["default"](function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
101
+ const report = {
102
+ title: `🐜 Error report from ${NAME}`,
103
+ body: spaceTrim__default["default"]((block) => `
104
+
105
+
106
+ \`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
107
+
108
+ \`\`\`
109
+ ${block(error.message || '(no error message)')}
110
+ \`\`\`
111
+
112
+
113
+ ## More info:
114
+
115
+ - **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
116
+ - **Book language version:** ${BOOK_LANGUAGE_VERSION}
117
+ - **Time:** ${new Date().toISOString()}
118
+
119
+ <details>
120
+ <summary>Stack trace:</summary>
121
+
122
+ ## Stack trace:
123
+
124
+ \`\`\`stacktrace
125
+ ${block(error.stack || '(empty)')}
126
+ \`\`\`
127
+ </details>
128
+
129
+ `),
223
130
  };
224
- var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
131
+ const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
225
132
  reportUrl.searchParams.set('labels', 'bug');
226
133
  reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
227
134
  reportUrl.searchParams.set('title', report.title);
@@ -234,16 +141,24 @@
234
141
  *
235
142
  * @public exported from `@promptbook/core`
236
143
  */
237
- var UnexpectedError = /** @class */ (function (_super) {
238
- __extends(UnexpectedError, _super);
239
- function UnexpectedError(message) {
240
- var _this = _super.call(this, spaceTrim$1.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
241
- _this.name = 'UnexpectedError';
242
- Object.setPrototypeOf(_this, UnexpectedError.prototype);
243
- return _this;
144
+ class UnexpectedError extends Error {
145
+ constructor(message) {
146
+ super(spaceTrim$1.spaceTrim((block) => `
147
+ ${block(message)}
148
+
149
+ Note: This error should not happen.
150
+ It's probbably a bug in the pipeline collection
151
+
152
+ Please report issue:
153
+ ${block(getErrorReportUrl(new Error(message)).href)}
154
+
155
+ Or contact us on ${ADMIN_EMAIL}
156
+
157
+ `));
158
+ this.name = 'UnexpectedError';
159
+ Object.setPrototypeOf(this, UnexpectedError.prototype);
244
160
  }
245
- return UnexpectedError;
246
- }(Error));
161
+ }
247
162
 
248
163
  /**
249
164
  * @@@
@@ -255,53 +170,41 @@
255
170
  * @example 'iLovePromptbook'
256
171
  * @public exported from `@promptbook/utils`
257
172
  */
258
- function normalizeTo_camelCase(text, _isFirstLetterCapital) {
259
- var e_1, _a;
260
- if (_isFirstLetterCapital === void 0) { _isFirstLetterCapital = false; }
261
- var charType;
262
- var lastCharType = null;
263
- var normalizedName = '';
264
- try {
265
- for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
266
- var char = text_1_1.value;
267
- var normalizedChar = void 0;
268
- if (/^[a-z]$/.test(char)) {
269
- charType = 'LOWERCASE';
270
- normalizedChar = char;
271
- }
272
- else if (/^[A-Z]$/.test(char)) {
273
- charType = 'UPPERCASE';
274
- normalizedChar = char.toLowerCase();
275
- }
276
- else if (/^[0-9]$/.test(char)) {
277
- charType = 'NUMBER';
278
- normalizedChar = char;
279
- }
280
- else {
281
- charType = 'OTHER';
282
- normalizedChar = '';
283
- }
284
- if (!lastCharType) {
285
- if (_isFirstLetterCapital) {
286
- normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
287
- }
288
- }
289
- else if (charType !== lastCharType &&
290
- !(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
291
- !(lastCharType === 'NUMBER') &&
292
- !(charType === 'NUMBER')) {
293
- normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
173
+ function normalizeTo_camelCase(text, _isFirstLetterCapital = false) {
174
+ let charType;
175
+ let lastCharType = null;
176
+ let normalizedName = '';
177
+ for (const char of text) {
178
+ let normalizedChar;
179
+ if (/^[a-z]$/.test(char)) {
180
+ charType = 'LOWERCASE';
181
+ normalizedChar = char;
182
+ }
183
+ else if (/^[A-Z]$/.test(char)) {
184
+ charType = 'UPPERCASE';
185
+ normalizedChar = char.toLowerCase();
186
+ }
187
+ else if (/^[0-9]$/.test(char)) {
188
+ charType = 'NUMBER';
189
+ normalizedChar = char;
190
+ }
191
+ else {
192
+ charType = 'OTHER';
193
+ normalizedChar = '';
194
+ }
195
+ if (!lastCharType) {
196
+ if (_isFirstLetterCapital) {
197
+ normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
294
198
  }
295
- normalizedName += normalizedChar;
296
- lastCharType = charType;
297
199
  }
298
- }
299
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
300
- finally {
301
- try {
302
- if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
200
+ else if (charType !== lastCharType &&
201
+ !(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
202
+ !(lastCharType === 'NUMBER') &&
203
+ !(charType === 'NUMBER')) {
204
+ normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
303
205
  }
304
- finally { if (e_1) throw e_1.error; }
206
+ normalizedName += normalizedChar;
207
+ lastCharType = charType;
305
208
  }
306
209
  return normalizedName;
307
210
  }
@@ -342,7 +245,7 @@
342
245
  5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
343
246
  return false;
344
247
  }
345
- var filenameSlashes = filename.split('\\').join('/');
248
+ const filenameSlashes = filename.split('\\').join('/');
346
249
  // Absolute Unix path: /hello.txt
347
250
  if (/^(\/)/i.test(filenameSlashes)) {
348
251
  // console.log(filename, 'Absolute Unix path: /hello.txt');
@@ -392,7 +295,7 @@
392
295
  if (url.startsWith('blob:')) {
393
296
  url = url.replace(/^blob:/, '');
394
297
  }
395
- var urlObject = new URL(url /* because fail is handled */);
298
+ const urlObject = new URL(url /* because fail is handled */);
396
299
  if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
397
300
  return false;
398
301
  }
@@ -403,7 +306,7 @@
403
306
  }
404
307
  }
405
308
 
406
- var defaultDiacriticsRemovalMap = [
309
+ const defaultDiacriticsRemovalMap = [
407
310
  {
408
311
  base: 'A',
409
312
  letters: '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F',
@@ -622,12 +525,12 @@
622
525
  *
623
526
  * @public exported from `@promptbook/utils`
624
527
  */
625
- var DIACRITIC_VARIANTS_LETTERS = {};
528
+ const DIACRITIC_VARIANTS_LETTERS = {};
626
529
  // tslint:disable-next-line: prefer-for-of
627
- for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
628
- var letters = defaultDiacriticsRemovalMap[i].letters;
530
+ for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
531
+ const letters = defaultDiacriticsRemovalMap[i].letters;
629
532
  // tslint:disable-next-line: prefer-for-of
630
- for (var j = 0; j < letters.length; j++) {
533
+ for (let j = 0; j < letters.length; j++) {
631
534
  DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
632
535
  }
633
536
  }
@@ -656,7 +559,7 @@
656
559
  */
657
560
  function removeDiacritics(input) {
658
561
  /*eslint no-control-regex: "off"*/
659
- return input.replace(/[^\u0000-\u007E]/g, function (a) {
562
+ return input.replace(/[^\u0000-\u007E]/g, (a) => {
660
563
  return DIACRITIC_VARIANTS_LETTERS[a] || a;
661
564
  });
662
565
  }
@@ -674,47 +577,36 @@
674
577
  * @public exported from `@promptbook/utils`
675
578
  */
676
579
  function normalizeToKebabCase(text) {
677
- var e_1, _a;
678
580
  text = removeDiacritics(text);
679
- var charType;
680
- var lastCharType = 'OTHER';
681
- var normalizedName = '';
682
- try {
683
- for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
684
- var char = text_1_1.value;
685
- var normalizedChar = void 0;
686
- if (/^[a-z]$/.test(char)) {
687
- charType = 'LOWERCASE';
688
- normalizedChar = char;
689
- }
690
- else if (/^[A-Z]$/.test(char)) {
691
- charType = 'UPPERCASE';
692
- normalizedChar = char.toLowerCase();
693
- }
694
- else if (/^[0-9]$/.test(char)) {
695
- charType = 'NUMBER';
696
- normalizedChar = char;
697
- }
698
- else {
699
- charType = 'OTHER';
700
- normalizedChar = '-';
701
- }
702
- if (charType !== lastCharType &&
703
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
704
- !(lastCharType === 'NUMBER') &&
705
- !(charType === 'NUMBER')) {
706
- normalizedName += '-';
707
- }
708
- normalizedName += normalizedChar;
709
- lastCharType = charType;
581
+ let charType;
582
+ let lastCharType = 'OTHER';
583
+ let normalizedName = '';
584
+ for (const char of text) {
585
+ let normalizedChar;
586
+ if (/^[a-z]$/.test(char)) {
587
+ charType = 'LOWERCASE';
588
+ normalizedChar = char;
589
+ }
590
+ else if (/^[A-Z]$/.test(char)) {
591
+ charType = 'UPPERCASE';
592
+ normalizedChar = char.toLowerCase();
593
+ }
594
+ else if (/^[0-9]$/.test(char)) {
595
+ charType = 'NUMBER';
596
+ normalizedChar = char;
710
597
  }
711
- }
712
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
713
- finally {
714
- try {
715
- if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
598
+ else {
599
+ charType = 'OTHER';
600
+ normalizedChar = '-';
601
+ }
602
+ if (charType !== lastCharType &&
603
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
604
+ !(lastCharType === 'NUMBER') &&
605
+ !(charType === 'NUMBER')) {
606
+ normalizedName += '-';
716
607
  }
717
- finally { if (e_1) throw e_1.error; }
608
+ normalizedName += normalizedChar;
609
+ lastCharType = charType;
718
610
  }
719
611
  normalizedName = normalizedName.split(/-+/g).join('-');
720
612
  normalizedName = normalizedName.split(/-?\/-?/g).join('/');
@@ -758,52 +650,64 @@
758
650
  * @public exported from `@promptbook/utils`
759
651
  */
760
652
  function renderPromptbookMermaid(pipelineJson, options) {
761
- var _a = (options || {}).linkTask, linkTask = _a === void 0 ? function () { return null; } : _a;
762
- var parameterNameToTaskName = function (parameterName) {
763
- var parameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
653
+ const { linkTask = () => null } = options || {};
654
+ const parameterNameToTaskName = (parameterName) => {
655
+ const parameter = pipelineJson.parameters.find((parameter) => parameter.name === parameterName);
764
656
  if (!parameter) {
765
- throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
657
+ throw new UnexpectedError(`Could not find {${parameterName}}`);
766
658
  // <- TODO: !!6 This causes problems when {knowledge} and other reserved parameters are used
767
659
  }
768
660
  if (parameter.isInput) {
769
661
  return 'input';
770
662
  }
771
- var task = pipelineJson.tasks.find(function (task) { return task.resultingParameterName === parameterName; });
663
+ const task = pipelineJson.tasks.find((task) => task.resultingParameterName === parameterName);
772
664
  if (!task) {
773
- throw new Error("Could not find task for {".concat(parameterName, "}"));
665
+ throw new Error(`Could not find task for {${parameterName}}`);
774
666
  }
775
667
  return task.name || normalizeTo_camelCase('task-' + titleToName(task.title));
776
668
  };
777
- var promptbookMermaid = spaceTrim$1.spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.tasks
778
- .flatMap(function (_a) {
779
- var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
780
- return __spreadArray([
781
- "".concat(parameterNameToTaskName(resultingParameterName), "(\"").concat(title, "\")")
782
- ], __read(dependentParameterNames.map(function (dependentParameterName) {
783
- return "".concat(parameterNameToTaskName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTaskName(resultingParameterName));
784
- })), false);
785
- })
786
- .join('\n')), "\n\n ").concat(block(pipelineJson.parameters
787
- .filter(function (_a) {
788
- var isOutput = _a.isOutput;
789
- return isOutput;
790
- })
791
- .map(function (_a) {
792
- var name = _a.name;
793
- return "".concat(parameterNameToTaskName(name), "--\"{").concat(name, "}\"-->output");
794
- })
795
- .join('\n')), "\n output((Output)):::output\n\n ").concat(block(pipelineJson.tasks
796
- .map(function (task) {
797
- var link = linkTask(task);
798
- if (link === null) {
799
- return '';
800
- }
801
- var href = link.href, title = link.title;
802
- var taskName = parameterNameToTaskName(task.resultingParameterName);
803
- return "click ".concat(taskName, " href \"").concat(href, "\" \"").concat(title, "\";");
804
- })
805
- .filter(function (line) { return line !== ''; })
806
- .join('\n')), "\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
669
+ const promptbookMermaid = spaceTrim$1.spaceTrim((block) => `
670
+
671
+ %% 🔮 Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually
672
+
673
+ flowchart LR
674
+ subgraph "${pipelineJson.title}"
675
+
676
+ direction TB
677
+
678
+ input((Input)):::input
679
+ ${block(pipelineJson.tasks
680
+ .flatMap(({ title, dependentParameterNames, resultingParameterName }) => [
681
+ `${parameterNameToTaskName(resultingParameterName)}("${title}")`,
682
+ ...dependentParameterNames.map((dependentParameterName) => `${parameterNameToTaskName(dependentParameterName)}--"{${dependentParameterName}}"-->${parameterNameToTaskName(resultingParameterName)}`),
683
+ ])
684
+ .join('\n'))}
685
+
686
+ ${block(pipelineJson.parameters
687
+ .filter(({ isOutput }) => isOutput)
688
+ .map(({ name }) => `${parameterNameToTaskName(name)}--"{${name}}"-->output`)
689
+ .join('\n'))}
690
+ output((Output)):::output
691
+
692
+ ${block(pipelineJson.tasks
693
+ .map((task) => {
694
+ const link = linkTask(task);
695
+ if (link === null) {
696
+ return '';
697
+ }
698
+ const { href, title } = link;
699
+ const taskName = parameterNameToTaskName(task.resultingParameterName);
700
+ return `click ${taskName} href "${href}" "${title}";`;
701
+ })
702
+ .filter((line) => line !== '')
703
+ .join('\n'))}
704
+
705
+ classDef input color: grey;
706
+ classDef output color: grey;
707
+
708
+ end;
709
+
710
+ `);
807
711
  return promptbookMermaid;
808
712
  }
809
713
  /**
@@ -819,77 +723,146 @@
819
723
  *
820
724
  * @public exported from `@promptbook/core`
821
725
  */
822
- var ParseError = /** @class */ (function (_super) {
823
- __extends(ParseError, _super);
824
- function ParseError(message) {
825
- var _this = _super.call(this, message) || this;
826
- _this.name = 'ParseError';
827
- Object.setPrototypeOf(_this, ParseError.prototype);
828
- return _this;
726
+ class ParseError extends Error {
727
+ constructor(message) {
728
+ super(message);
729
+ this.name = 'ParseError';
730
+ Object.setPrototypeOf(this, ParseError.prototype);
829
731
  }
830
- return ParseError;
831
- }(Error));
732
+ }
832
733
  /**
833
734
  * TODO: Maybe split `ParseError` and `ApplyError`
834
735
  */
835
736
 
836
737
  /**
837
- * Parses the given script and returns the list of all used variables that are not defined in the script
738
+ * Extract all used variable names from ginen JavaScript/TypeScript script
838
739
  *
839
- * @param script from which to extract the variables
840
- * @returns the list of variable names
740
+ * @param script JavaScript/TypeScript script
741
+ * @returns Set of variable names
841
742
  * @throws {ParseError} if the script is invalid
842
743
  * @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
843
744
  */
844
745
  function extractVariablesFromScript(script) {
845
- var variables = new Set();
846
- var originalScript = script;
847
- script = "(()=>{".concat(script, "})()");
746
+ if (script.trim() === '') {
747
+ return new Set();
748
+ }
749
+ const variables = new Set();
750
+ // JS keywords and builtins to exclude
751
+ const exclude = new Set([
752
+ // Keywords
753
+ 'break',
754
+ 'case',
755
+ 'catch',
756
+ 'class',
757
+ 'const',
758
+ 'continue',
759
+ 'debugger',
760
+ 'default',
761
+ 'delete',
762
+ 'do',
763
+ 'else',
764
+ 'export',
765
+ 'extends',
766
+ 'false',
767
+ 'finally',
768
+ 'for',
769
+ 'function',
770
+ 'if',
771
+ 'import',
772
+ 'in',
773
+ 'instanceof',
774
+ 'let',
775
+ 'new',
776
+ 'null',
777
+ 'return',
778
+ 'super',
779
+ 'switch',
780
+ 'this',
781
+ 'throw',
782
+ 'true',
783
+ 'try',
784
+ 'typeof',
785
+ 'var',
786
+ 'void',
787
+ 'while',
788
+ 'with',
789
+ 'yield',
790
+ // Common globals
791
+ 'console',
792
+ 'JSON',
793
+ 'Error',
794
+ // Typescript types
795
+ 'string',
796
+ 'number',
797
+ 'boolean',
798
+ 'object',
799
+ 'symbol',
800
+ // Common methods on built-in objects
801
+ 'test',
802
+ 'match',
803
+ 'exec',
804
+ 'replace',
805
+ 'search',
806
+ 'split',
807
+ ]);
848
808
  try {
849
- for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
850
- try {
851
- eval(script);
809
+ // Note: Extract variables from template literals like ${variable}
810
+ const templateRegex = /\$\{([a-zA-Z_$][a-zA-Z0-9_$]*)\}/g;
811
+ let match;
812
+ while ((match = templateRegex.exec(script)) !== null) {
813
+ const varName = match[1];
814
+ if (!exclude.has(varName)) {
815
+ variables.add(varName);
852
816
  }
853
- catch (error) {
854
- if (!(error instanceof ReferenceError)) {
855
- throw error;
856
- }
857
- /*
858
- Note: Parsing the error
859
- 🌟 Most devices:
860
- [PipelineUrlError: thing is not defined]
861
-
862
- 🍏 iPhone`s Safari:
863
- [PipelineUrlError: Can't find variable: thing]
864
- */
865
- var variableName = undefined;
866
- if (error.message.startsWith("Can't")) {
867
- // 🍏 Case
868
- variableName = error.message.split(' ').pop();
869
- }
870
- else {
871
- // 🌟 Case
872
- variableName = error.message.split(' ').shift();
873
- }
874
- if (variableName === undefined) {
875
- throw error;
876
- }
877
- if (script.includes(variableName + '(')) {
878
- script = "const ".concat(variableName, " = ()=>'';") + script;
879
- }
880
- else {
881
- variables.add(variableName);
882
- script = "const ".concat(variableName, " = '';") + script;
883
- }
817
+ }
818
+ // Note: Process the script to handle normal variable usage
819
+ const processedScript = script
820
+ .replace(/'(?:\\.|[^'\\])*'/g, "''") // <- Note: Remove string literals
821
+ .replace(/"(?:\\.|[^"\\])*"/g, '""')
822
+ .replace(/`(?:\\.|[^`\\])*`/g, '``')
823
+ .replace(/\/(?:\\.|[^/\\])*\/[gimsuy]*/g, '{}'); // <- Note: Remove regex literals
824
+ // Note: Find identifiers in function arguments
825
+ const funcArgRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/g;
826
+ const funcNames = new Set();
827
+ while ((match = funcArgRegex.exec(processedScript)) !== null) {
828
+ funcNames.add(match[1]);
829
+ }
830
+ // Find variable declarations to exclude them
831
+ const declaredVars = new Set();
832
+ const declRegex = /\b(const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
833
+ while ((match = declRegex.exec(processedScript)) !== null) {
834
+ declaredVars.add(match[2]);
835
+ }
836
+ // Note: Find identifiers in the script
837
+ const identifierRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
838
+ while ((match = identifierRegex.exec(processedScript)) !== null) {
839
+ const name = match[1];
840
+ // Add if not excluded, not a function name, and not a declared variable
841
+ if (!exclude.has(name) && !funcNames.has(name) && !declaredVars.has(name)) {
842
+ variables.add(name);
884
843
  }
844
+ }
885
845
  }
886
846
  catch (error) {
887
847
  if (!(error instanceof Error)) {
888
848
  throw error;
889
849
  }
890
- throw new ParseError(spaceTrim$1.spaceTrim(function (block) { return "\n Can not extract variables from the script\n ".concat(block(error.stack || error.message), "\n\n Found variables:\n ").concat(Array.from(variables)
891
- .map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
892
- .join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
850
+ throw new ParseError(spaceTrim__default["default"]((block) => `
851
+ Can not extract variables from the script
852
+ ${block(error.stack || error.message)}
853
+
854
+ Found variables:
855
+ ${Array.from(variables)
856
+ .map((variableName, i) => `${i + 1}) ${variableName}`)
857
+ .join('\n')}
858
+
859
+
860
+ The script:
861
+
862
+ \`\`\`javascript
863
+ ${block(script)}
864
+ \`\`\`
865
+ `));
893
866
  }
894
867
  return variables;
895
868
  }
@@ -905,65 +878,53 @@
905
878
  *
906
879
  * @public exported from `@promptbook/core`
907
880
  */
908
- var AbstractFormatError = /** @class */ (function (_super) {
909
- __extends(AbstractFormatError, _super);
881
+ class AbstractFormatError extends Error {
910
882
  // Note: To allow instanceof do not put here error `name`
911
883
  // public readonly name = 'AbstractFormatError';
912
- function AbstractFormatError(message) {
913
- var _this = _super.call(this, message) || this;
914
- Object.setPrototypeOf(_this, AbstractFormatError.prototype);
915
- return _this;
884
+ constructor(message) {
885
+ super(message);
886
+ Object.setPrototypeOf(this, AbstractFormatError.prototype);
916
887
  }
917
- return AbstractFormatError;
918
- }(Error));
888
+ }
919
889
 
920
890
  /**
921
891
  * This error indicates problem with parsing of CSV
922
892
  *
923
893
  * @public exported from `@promptbook/core`
924
894
  */
925
- var CsvFormatError = /** @class */ (function (_super) {
926
- __extends(CsvFormatError, _super);
927
- function CsvFormatError(message) {
928
- var _this = _super.call(this, message) || this;
929
- _this.name = 'CsvFormatError';
930
- Object.setPrototypeOf(_this, CsvFormatError.prototype);
931
- return _this;
895
+ class CsvFormatError extends AbstractFormatError {
896
+ constructor(message) {
897
+ super(message);
898
+ this.name = 'CsvFormatError';
899
+ Object.setPrototypeOf(this, CsvFormatError.prototype);
932
900
  }
933
- return CsvFormatError;
934
- }(AbstractFormatError));
901
+ }
935
902
 
936
903
  /**
937
904
  * This error indicates that the pipeline collection cannot be propperly loaded
938
905
  *
939
906
  * @public exported from `@promptbook/core`
940
907
  */
941
- var CollectionError = /** @class */ (function (_super) {
942
- __extends(CollectionError, _super);
943
- function CollectionError(message) {
944
- var _this = _super.call(this, message) || this;
945
- _this.name = 'CollectionError';
946
- Object.setPrototypeOf(_this, CollectionError.prototype);
947
- return _this;
908
+ class CollectionError extends Error {
909
+ constructor(message) {
910
+ super(message);
911
+ this.name = 'CollectionError';
912
+ Object.setPrototypeOf(this, CollectionError.prototype);
948
913
  }
949
- return CollectionError;
950
- }(Error));
914
+ }
951
915
 
952
916
  /**
953
917
  * This error type indicates that you try to use a feature that is not available in the current environment
954
918
  *
955
919
  * @public exported from `@promptbook/core`
956
920
  */
957
- var EnvironmentMismatchError = /** @class */ (function (_super) {
958
- __extends(EnvironmentMismatchError, _super);
959
- function EnvironmentMismatchError(message) {
960
- var _this = _super.call(this, message) || this;
961
- _this.name = 'EnvironmentMismatchError';
962
- Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
963
- return _this;
921
+ class EnvironmentMismatchError extends Error {
922
+ constructor(message) {
923
+ super(message);
924
+ this.name = 'EnvironmentMismatchError';
925
+ Object.setPrototypeOf(this, EnvironmentMismatchError.prototype);
964
926
  }
965
- return EnvironmentMismatchError;
966
- }(Error));
927
+ }
967
928
 
968
929
  /**
969
930
  * This error occurs when some expectation is not met in the execution of the pipeline
@@ -973,166 +934,154 @@
973
934
  * Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
974
935
  * Note: This is a kindof subtype of PipelineExecutionError
975
936
  */
976
- var ExpectError = /** @class */ (function (_super) {
977
- __extends(ExpectError, _super);
978
- function ExpectError(message) {
979
- var _this = _super.call(this, message) || this;
980
- _this.name = 'ExpectError';
981
- Object.setPrototypeOf(_this, ExpectError.prototype);
982
- return _this;
937
+ class ExpectError extends Error {
938
+ constructor(message) {
939
+ super(message);
940
+ this.name = 'ExpectError';
941
+ Object.setPrototypeOf(this, ExpectError.prototype);
983
942
  }
984
- return ExpectError;
985
- }(Error));
943
+ }
986
944
 
987
945
  /**
988
946
  * This error indicates that the promptbook can not retrieve knowledge from external sources
989
947
  *
990
948
  * @public exported from `@promptbook/core`
991
949
  */
992
- var KnowledgeScrapeError = /** @class */ (function (_super) {
993
- __extends(KnowledgeScrapeError, _super);
994
- function KnowledgeScrapeError(message) {
995
- var _this = _super.call(this, message) || this;
996
- _this.name = 'KnowledgeScrapeError';
997
- Object.setPrototypeOf(_this, KnowledgeScrapeError.prototype);
998
- return _this;
950
+ class KnowledgeScrapeError extends Error {
951
+ constructor(message) {
952
+ super(message);
953
+ this.name = 'KnowledgeScrapeError';
954
+ Object.setPrototypeOf(this, KnowledgeScrapeError.prototype);
999
955
  }
1000
- return KnowledgeScrapeError;
1001
- }(Error));
956
+ }
1002
957
 
1003
958
  /**
1004
959
  * This error type indicates that some limit was reached
1005
960
  *
1006
961
  * @public exported from `@promptbook/core`
1007
962
  */
1008
- var LimitReachedError = /** @class */ (function (_super) {
1009
- __extends(LimitReachedError, _super);
1010
- function LimitReachedError(message) {
1011
- var _this = _super.call(this, message) || this;
1012
- _this.name = 'LimitReachedError';
1013
- Object.setPrototypeOf(_this, LimitReachedError.prototype);
1014
- return _this;
963
+ class LimitReachedError extends Error {
964
+ constructor(message) {
965
+ super(message);
966
+ this.name = 'LimitReachedError';
967
+ Object.setPrototypeOf(this, LimitReachedError.prototype);
1015
968
  }
1016
- return LimitReachedError;
1017
- }(Error));
969
+ }
1018
970
 
1019
971
  /**
1020
972
  * This error type indicates that some tools are missing for pipeline execution or preparation
1021
973
  *
1022
974
  * @public exported from `@promptbook/core`
1023
975
  */
1024
- var MissingToolsError = /** @class */ (function (_super) {
1025
- __extends(MissingToolsError, _super);
1026
- function MissingToolsError(message) {
1027
- var _this = _super.call(this, spaceTrim$1.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: You have probbably forgot to provide some tools for pipeline execution or preparation\n\n "); })) || this;
1028
- _this.name = 'MissingToolsError';
1029
- Object.setPrototypeOf(_this, MissingToolsError.prototype);
1030
- return _this;
976
+ class MissingToolsError extends Error {
977
+ constructor(message) {
978
+ super(spaceTrim$1.spaceTrim((block) => `
979
+ ${block(message)}
980
+
981
+ Note: You have probbably forgot to provide some tools for pipeline execution or preparation
982
+
983
+ `));
984
+ this.name = 'MissingToolsError';
985
+ Object.setPrototypeOf(this, MissingToolsError.prototype);
1031
986
  }
1032
- return MissingToolsError;
1033
- }(Error));
987
+ }
1034
988
 
1035
989
  /**
1036
990
  * This error indicates that promptbook not found in the collection
1037
991
  *
1038
992
  * @public exported from `@promptbook/core`
1039
993
  */
1040
- var NotFoundError = /** @class */ (function (_super) {
1041
- __extends(NotFoundError, _super);
1042
- function NotFoundError(message) {
1043
- var _this = _super.call(this, message) || this;
1044
- _this.name = 'NotFoundError';
1045
- Object.setPrototypeOf(_this, NotFoundError.prototype);
1046
- return _this;
994
+ class NotFoundError extends Error {
995
+ constructor(message) {
996
+ super(message);
997
+ this.name = 'NotFoundError';
998
+ Object.setPrototypeOf(this, NotFoundError.prototype);
1047
999
  }
1048
- return NotFoundError;
1049
- }(Error));
1000
+ }
1050
1001
 
1051
1002
  /**
1052
1003
  * This error type indicates that some part of the code is not implemented yet
1053
1004
  *
1054
1005
  * @public exported from `@promptbook/core`
1055
1006
  */
1056
- var NotYetImplementedError = /** @class */ (function (_super) {
1057
- __extends(NotYetImplementedError, _super);
1058
- function NotYetImplementedError(message) {
1059
- var _this = _super.call(this, spaceTrim$1.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on pavol@ptbk.io\n\n "); })) || this;
1060
- _this.name = 'NotYetImplementedError';
1061
- Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
1062
- return _this;
1007
+ class NotYetImplementedError extends Error {
1008
+ constructor(message) {
1009
+ super(spaceTrim$1.spaceTrim((block) => `
1010
+ ${block(message)}
1011
+
1012
+ Note: This feature is not implemented yet but it will be soon.
1013
+
1014
+ If you want speed up the implementation or just read more, look here:
1015
+ https://github.com/webgptorg/promptbook
1016
+
1017
+ Or contact us on pavol@ptbk.io
1018
+
1019
+ `));
1020
+ this.name = 'NotYetImplementedError';
1021
+ Object.setPrototypeOf(this, NotYetImplementedError.prototype);
1063
1022
  }
1064
- return NotYetImplementedError;
1065
- }(Error));
1023
+ }
1066
1024
 
1067
1025
  /**
1068
1026
  * This error indicates errors during the execution of the pipeline
1069
1027
  *
1070
1028
  * @public exported from `@promptbook/core`
1071
1029
  */
1072
- var PipelineExecutionError = /** @class */ (function (_super) {
1073
- __extends(PipelineExecutionError, _super);
1074
- function PipelineExecutionError(message) {
1075
- var _this = _super.call(this, message) || this;
1076
- _this.name = 'PipelineExecutionError';
1077
- Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
1078
- return _this;
1030
+ class PipelineExecutionError extends Error {
1031
+ constructor(message) {
1032
+ super(message);
1033
+ this.name = 'PipelineExecutionError';
1034
+ Object.setPrototypeOf(this, PipelineExecutionError.prototype);
1079
1035
  }
1080
- return PipelineExecutionError;
1081
- }(Error));
1036
+ }
1082
1037
 
1083
1038
  /**
1084
1039
  * This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
1085
1040
  *
1086
1041
  * @public exported from `@promptbook/core`
1087
1042
  */
1088
- var PipelineLogicError = /** @class */ (function (_super) {
1089
- __extends(PipelineLogicError, _super);
1090
- function PipelineLogicError(message) {
1091
- var _this = _super.call(this, message) || this;
1092
- _this.name = 'PipelineLogicError';
1093
- Object.setPrototypeOf(_this, PipelineLogicError.prototype);
1094
- return _this;
1043
+ class PipelineLogicError extends Error {
1044
+ constructor(message) {
1045
+ super(message);
1046
+ this.name = 'PipelineLogicError';
1047
+ Object.setPrototypeOf(this, PipelineLogicError.prototype);
1095
1048
  }
1096
- return PipelineLogicError;
1097
- }(Error));
1049
+ }
1098
1050
 
1099
1051
  /**
1100
1052
  * This error indicates errors in referencing promptbooks between each other
1101
1053
  *
1102
1054
  * @public exported from `@promptbook/core`
1103
1055
  */
1104
- var PipelineUrlError = /** @class */ (function (_super) {
1105
- __extends(PipelineUrlError, _super);
1106
- function PipelineUrlError(message) {
1107
- var _this = _super.call(this, message) || this;
1108
- _this.name = 'PipelineUrlError';
1109
- Object.setPrototypeOf(_this, PipelineUrlError.prototype);
1110
- return _this;
1056
+ class PipelineUrlError extends Error {
1057
+ constructor(message) {
1058
+ super(message);
1059
+ this.name = 'PipelineUrlError';
1060
+ Object.setPrototypeOf(this, PipelineUrlError.prototype);
1111
1061
  }
1112
- return PipelineUrlError;
1113
- }(Error));
1062
+ }
1114
1063
 
1115
1064
  /**
1116
1065
  * Index of all custom errors
1117
1066
  *
1118
1067
  * @public exported from `@promptbook/core`
1119
1068
  */
1120
- var PROMPTBOOK_ERRORS = {
1121
- AbstractFormatError: AbstractFormatError,
1122
- CsvFormatError: CsvFormatError,
1123
- CollectionError: CollectionError,
1124
- EnvironmentMismatchError: EnvironmentMismatchError,
1125
- ExpectError: ExpectError,
1126
- KnowledgeScrapeError: KnowledgeScrapeError,
1127
- LimitReachedError: LimitReachedError,
1128
- MissingToolsError: MissingToolsError,
1129
- NotFoundError: NotFoundError,
1130
- NotYetImplementedError: NotYetImplementedError,
1131
- ParseError: ParseError,
1132
- PipelineExecutionError: PipelineExecutionError,
1133
- PipelineLogicError: PipelineLogicError,
1134
- PipelineUrlError: PipelineUrlError,
1135
- UnexpectedError: UnexpectedError,
1069
+ const PROMPTBOOK_ERRORS = {
1070
+ AbstractFormatError,
1071
+ CsvFormatError,
1072
+ CollectionError,
1073
+ EnvironmentMismatchError,
1074
+ ExpectError,
1075
+ KnowledgeScrapeError,
1076
+ LimitReachedError,
1077
+ MissingToolsError,
1078
+ NotFoundError,
1079
+ NotYetImplementedError,
1080
+ ParseError,
1081
+ PipelineExecutionError,
1082
+ PipelineLogicError,
1083
+ PipelineUrlError,
1084
+ UnexpectedError,
1136
1085
  // TODO: [🪑]> VersionMismatchError,
1137
1086
  };
1138
1087
  /**
@@ -1140,15 +1089,15 @@
1140
1089
  *
1141
1090
  * @private for internal usage
1142
1091
  */
1143
- var COMMON_JAVASCRIPT_ERRORS = {
1144
- Error: Error,
1145
- EvalError: EvalError,
1146
- RangeError: RangeError,
1147
- ReferenceError: ReferenceError,
1148
- SyntaxError: SyntaxError,
1149
- TypeError: TypeError,
1150
- URIError: URIError,
1151
- AggregateError: AggregateError,
1092
+ const COMMON_JAVASCRIPT_ERRORS = {
1093
+ Error,
1094
+ EvalError,
1095
+ RangeError,
1096
+ ReferenceError,
1097
+ SyntaxError,
1098
+ TypeError,
1099
+ URIError,
1100
+ AggregateError,
1152
1101
  /*
1153
1102
  Note: Not widely supported
1154
1103
  > InternalError,
@@ -1163,7 +1112,10 @@
1163
1112
  *
1164
1113
  * @private for internal usage
1165
1114
  */
1166
- var ALL_ERRORS = __assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
1115
+ const ALL_ERRORS = {
1116
+ ...PROMPTBOOK_ERRORS,
1117
+ ...COMMON_JAVASCRIPT_ERRORS,
1118
+ };
1167
1119
  /**
1168
1120
  * Note: [💞] Ignore a discrepancy between file name and entity name
1169
1121
  */
@@ -1174,15 +1126,20 @@
1174
1126
  * @public exported from `@promptbook/utils`
1175
1127
  */
1176
1128
  function deserializeError(error) {
1177
- var name = error.name, stack = error.stack;
1178
- var message = error.message;
1179
- var ErrorClass = ALL_ERRORS[error.name];
1129
+ const { name, stack } = error;
1130
+ let { message } = error;
1131
+ let ErrorClass = ALL_ERRORS[error.name];
1180
1132
  if (ErrorClass === undefined) {
1181
1133
  ErrorClass = Error;
1182
- message = "".concat(name, ": ").concat(message);
1134
+ message = `${name}: ${message}`;
1183
1135
  }
1184
1136
  if (stack !== undefined && stack !== '') {
1185
- message = spaceTrim__default["default"](function (block) { return "\n ".concat(block(message), "\n\n Original stack trace:\n ").concat(block(stack || ''), "\n "); });
1137
+ message = spaceTrim__default["default"]((block) => `
1138
+ ${block(message)}
1139
+
1140
+ Original stack trace:
1141
+ ${block(stack || '')}
1142
+ `);
1186
1143
  }
1187
1144
  return new ErrorClass(message);
1188
1145
  }
@@ -1193,14 +1150,20 @@
1193
1150
  * @public exported from `@promptbook/utils`
1194
1151
  */
1195
1152
  function serializeError(error) {
1196
- var name = error.name, message = error.message, stack = error.stack;
1153
+ const { name, message, stack } = error;
1197
1154
  if (!Object.keys(ALL_ERRORS).includes(name)) {
1198
- console.error(spaceTrim__default["default"](function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
1155
+ console.error(spaceTrim__default["default"]((block) => `
1156
+
1157
+ Cannot serialize error with name "${name}"
1158
+
1159
+ ${block(stack || message)}
1160
+
1161
+ `));
1199
1162
  }
1200
1163
  return {
1201
1164
  name: name,
1202
- message: message,
1203
- stack: stack,
1165
+ message,
1166
+ stack,
1204
1167
  };
1205
1168
  }
1206
1169
 
@@ -1213,71 +1176,24 @@
1213
1176
  * @public exported from `@promptbook/utils`
1214
1177
  * @deprecated [🪂] Use queues instead
1215
1178
  */
1216
- function forEachAsync(array, options, callbackfunction) {
1217
- return __awaiter(this, void 0, void 0, function () {
1218
- var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
1219
- var e_1, _d;
1220
- return __generator(this, function (_e) {
1221
- switch (_e.label) {
1222
- case 0:
1223
- _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
1224
- index = 0;
1225
- runningTasks = [];
1226
- tasks = [];
1227
- _loop_1 = function (item) {
1228
- var currentIndex, task;
1229
- return __generator(this, function (_f) {
1230
- switch (_f.label) {
1231
- case 0:
1232
- currentIndex = index++;
1233
- task = callbackfunction(item, currentIndex, array);
1234
- tasks.push(task);
1235
- runningTasks.push(task);
1236
- /* not await */ Promise.resolve(task).then(function () {
1237
- runningTasks = runningTasks.filter(function (t) { return t !== task; });
1238
- });
1239
- if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
1240
- return [4 /*yield*/, Promise.race(runningTasks)];
1241
- case 1:
1242
- _f.sent();
1243
- _f.label = 2;
1244
- case 2: return [2 /*return*/];
1245
- }
1246
- });
1247
- };
1248
- _e.label = 1;
1249
- case 1:
1250
- _e.trys.push([1, 6, 7, 8]);
1251
- _b = __values(array), _c = _b.next();
1252
- _e.label = 2;
1253
- case 2:
1254
- if (!!_c.done) return [3 /*break*/, 5];
1255
- item = _c.value;
1256
- return [5 /*yield**/, _loop_1(item)];
1257
- case 3:
1258
- _e.sent();
1259
- _e.label = 4;
1260
- case 4:
1261
- _c = _b.next();
1262
- return [3 /*break*/, 2];
1263
- case 5: return [3 /*break*/, 8];
1264
- case 6:
1265
- e_1_1 = _e.sent();
1266
- e_1 = { error: e_1_1 };
1267
- return [3 /*break*/, 8];
1268
- case 7:
1269
- try {
1270
- if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
1271
- }
1272
- finally { if (e_1) throw e_1.error; }
1273
- return [7 /*endfinally*/];
1274
- case 8: return [4 /*yield*/, Promise.all(tasks)];
1275
- case 9:
1276
- _e.sent();
1277
- return [2 /*return*/];
1278
- }
1179
+ async function forEachAsync(array, options, callbackfunction) {
1180
+ const { maxParallelCount = Infinity } = options;
1181
+ let index = 0;
1182
+ let runningTasks = [];
1183
+ const tasks = [];
1184
+ for (const item of array) {
1185
+ const currentIndex = index++;
1186
+ const task = callbackfunction(item, currentIndex, array);
1187
+ tasks.push(task);
1188
+ runningTasks.push(task);
1189
+ /* not await */ Promise.resolve(task).then(() => {
1190
+ runningTasks = runningTasks.filter((t) => t !== task);
1279
1191
  });
1280
- });
1192
+ if (maxParallelCount < runningTasks.length) {
1193
+ await Promise.race(runningTasks);
1194
+ }
1195
+ }
1196
+ await Promise.all(tasks);
1281
1197
  }
1282
1198
 
1283
1199
  /**
@@ -1308,8 +1224,11 @@
1308
1224
  * @public exported from `@promptbook/utils`
1309
1225
  */
1310
1226
  function orderJson(options) {
1311
- var value = options.value, order = options.order;
1312
- var orderedValue = __assign(__assign({}, (order === undefined ? {} : Object.fromEntries(order.map(function (key) { return [key, undefined]; })))), value);
1227
+ const { value, order } = options;
1228
+ const orderedValue = {
1229
+ ...(order === undefined ? {} : Object.fromEntries(order.map((key) => [key, undefined]))),
1230
+ ...value,
1231
+ };
1313
1232
  return orderedValue;
1314
1233
  }
1315
1234
 
@@ -1323,26 +1242,15 @@
1323
1242
  * @public exported from `@promptbook/utils`
1324
1243
  */
1325
1244
  function $deepFreeze(objectValue) {
1326
- var e_1, _a;
1327
1245
  if (Array.isArray(objectValue)) {
1328
- return Object.freeze(objectValue.map(function (item) { return $deepFreeze(item); }));
1329
- }
1330
- var propertyNames = Object.getOwnPropertyNames(objectValue);
1331
- try {
1332
- for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
1333
- var propertyName = propertyNames_1_1.value;
1334
- var value = objectValue[propertyName];
1335
- if (value && typeof value === 'object') {
1336
- $deepFreeze(value);
1337
- }
1338
- }
1246
+ return Object.freeze(objectValue.map((item) => $deepFreeze(item)));
1339
1247
  }
1340
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1341
- finally {
1342
- try {
1343
- if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
1248
+ const propertyNames = Object.getOwnPropertyNames(objectValue);
1249
+ for (const propertyName of propertyNames) {
1250
+ const value = objectValue[propertyName];
1251
+ if (value && typeof value === 'object') {
1252
+ $deepFreeze(value);
1344
1253
  }
1345
- finally { if (e_1) throw e_1.error; }
1346
1254
  }
1347
1255
  Object.freeze(objectValue);
1348
1256
  return objectValue;
@@ -1372,10 +1280,9 @@
1372
1280
  * @public exported from `@promptbook/utils`
1373
1281
  */
1374
1282
  function checkSerializableAsJson(options) {
1375
- var e_1, _a;
1376
- var value = options.value, name = options.name, message = options.message;
1283
+ const { value, name, message } = options;
1377
1284
  if (value === undefined) {
1378
- throw new UnexpectedError("".concat(name, " is undefined"));
1285
+ throw new UnexpectedError(`${name} is undefined`);
1379
1286
  }
1380
1287
  else if (value === null) {
1381
1288
  return;
@@ -1390,49 +1297,54 @@
1390
1297
  return;
1391
1298
  }
1392
1299
  else if (typeof value === 'symbol') {
1393
- throw new UnexpectedError("".concat(name, " is symbol"));
1300
+ throw new UnexpectedError(`${name} is symbol`);
1394
1301
  }
1395
1302
  else if (typeof value === 'function') {
1396
- throw new UnexpectedError("".concat(name, " is function"));
1303
+ throw new UnexpectedError(`${name} is function`);
1397
1304
  }
1398
1305
  else if (typeof value === 'object' && Array.isArray(value)) {
1399
- for (var i = 0; i < value.length; i++) {
1400
- checkSerializableAsJson({ name: "".concat(name, "[").concat(i, "]"), value: value[i], message: message });
1306
+ for (let i = 0; i < value.length; i++) {
1307
+ checkSerializableAsJson({ name: `${name}[${i}]`, value: value[i], message });
1401
1308
  }
1402
1309
  }
1403
1310
  else if (typeof value === 'object') {
1404
1311
  if (value instanceof Date) {
1405
- throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is Date\n\n Use `string_date_iso8601` instead\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
1312
+ throw new UnexpectedError(spaceTrim__default["default"]((block) => `
1313
+ \`${name}\` is Date
1314
+
1315
+ Use \`string_date_iso8601\` instead
1316
+
1317
+ Additional message for \`${name}\`:
1318
+ ${block(message || '(nothing)')}
1319
+ `));
1406
1320
  }
1407
1321
  else if (value instanceof Map) {
1408
- throw new UnexpectedError("".concat(name, " is Map"));
1322
+ throw new UnexpectedError(`${name} is Map`);
1409
1323
  }
1410
1324
  else if (value instanceof Set) {
1411
- throw new UnexpectedError("".concat(name, " is Set"));
1325
+ throw new UnexpectedError(`${name} is Set`);
1412
1326
  }
1413
1327
  else if (value instanceof RegExp) {
1414
- throw new UnexpectedError("".concat(name, " is RegExp"));
1328
+ throw new UnexpectedError(`${name} is RegExp`);
1415
1329
  }
1416
1330
  else if (value instanceof Error) {
1417
- throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is unserialized Error\n\n Use function `serializeError`\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n\n "); }));
1331
+ throw new UnexpectedError(spaceTrim__default["default"]((block) => `
1332
+ \`${name}\` is unserialized Error
1333
+
1334
+ Use function \`serializeError\`
1335
+
1336
+ Additional message for \`${name}\`:
1337
+ ${block(message || '(nothing)')}
1338
+
1339
+ `));
1418
1340
  }
1419
1341
  else {
1420
- try {
1421
- for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
1422
- var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
1423
- if (subValue === undefined) {
1424
- // Note: undefined in object is serializable - it is just omited
1425
- continue;
1426
- }
1427
- checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message });
1428
- }
1429
- }
1430
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1431
- finally {
1432
- try {
1433
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1342
+ for (const [subName, subValue] of Object.entries(value)) {
1343
+ if (subValue === undefined) {
1344
+ // Note: undefined in object is serializable - it is just omited
1345
+ continue;
1434
1346
  }
1435
- finally { if (e_1) throw e_1.error; }
1347
+ checkSerializableAsJson({ name: `${name}.${subName}`, value: subValue, message });
1436
1348
  }
1437
1349
  try {
1438
1350
  JSON.stringify(value); // <- TODO: [0]
@@ -1441,7 +1353,14 @@
1441
1353
  if (!(error instanceof Error)) {
1442
1354
  throw error;
1443
1355
  }
1444
- throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.stack || error.message), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
1356
+ throw new UnexpectedError(spaceTrim__default["default"]((block) => `
1357
+ \`${name}\` is not serializable
1358
+
1359
+ ${block(error.stack || error.message)}
1360
+
1361
+ Additional message for \`${name}\`:
1362
+ ${block(message || '(nothing)')}
1363
+ `));
1445
1364
  }
1446
1365
  /*
1447
1366
  TODO: [0] Is there some more elegant way to check circular references?
@@ -1466,7 +1385,12 @@
1466
1385
  }
1467
1386
  }
1468
1387
  else {
1469
- throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is unknown type\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
1388
+ throw new UnexpectedError(spaceTrim__default["default"]((block) => `
1389
+ \`${name}\` is unknown type
1390
+
1391
+ Additional message for \`${name}\`:
1392
+ ${block(message || '(nothing)')}
1393
+ `));
1470
1394
  }
1471
1395
  }
1472
1396
  /**
@@ -1512,9 +1436,9 @@
1512
1436
  * @public exported from `@promptbook/utils`
1513
1437
  */
1514
1438
  function exportJson(options) {
1515
- var name = options.name, value = options.value, order = options.order, message = options.message;
1516
- checkSerializableAsJson({ name: name, value: value, message: message });
1517
- var orderedValue =
1439
+ const { name, value, order, message } = options;
1440
+ checkSerializableAsJson({ name, value, message });
1441
+ const orderedValue =
1518
1442
  // TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
1519
1443
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1520
1444
  // @ts-ignore
@@ -1537,19 +1461,19 @@
1537
1461
  *
1538
1462
  * @private within the repository
1539
1463
  */
1540
- var REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
1464
+ const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
1541
1465
  /**
1542
1466
  * @@@
1543
1467
  *
1544
1468
  * @private within the repository
1545
1469
  */
1546
- var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
1470
+ const RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
1547
1471
  /**
1548
1472
  * @@@
1549
1473
  *
1550
1474
  * @private within the repository
1551
1475
  */
1552
- var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
1476
+ const RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
1553
1477
  /**
1554
1478
  * The names of the parameters that are reserved for special purposes
1555
1479
  *
@@ -1557,7 +1481,7 @@
1557
1481
  */
1558
1482
  exportJson({
1559
1483
  name: 'RESERVED_PARAMETER_NAMES',
1560
- message: "The names of the parameters that are reserved for special purposes",
1484
+ message: `The names of the parameters that are reserved for special purposes`,
1561
1485
  value: [
1562
1486
  'content',
1563
1487
  'context',
@@ -1592,9 +1516,9 @@
1592
1516
  else if (value === -Infinity) {
1593
1517
  return VALUE_STRINGS.negativeInfinity;
1594
1518
  }
1595
- for (var exponent = 0; exponent < 15; exponent++) {
1596
- var factor = Math.pow(10, exponent);
1597
- var valueRounded = Math.round(value * factor) / factor;
1519
+ for (let exponent = 0; exponent < 15; exponent++) {
1520
+ const factor = 10 ** exponent;
1521
+ const valueRounded = Math.round(value * factor) / factor;
1598
1522
  if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
1599
1523
  return valueRounded.toFixed(exponent);
1600
1524
  }
@@ -1662,47 +1586,38 @@
1662
1586
  * @public exported from `@promptbook/utils`
1663
1587
  */
1664
1588
  function templateParameters(template, parameters) {
1665
- var e_1, _a;
1666
- try {
1667
- for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
1668
- var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
1669
- if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
1670
- throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
1671
- }
1672
- else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
1673
- // TODO: [🍵]
1674
- throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
1675
- }
1589
+ for (const [parameterName, parameterValue] of Object.entries(parameters)) {
1590
+ if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
1591
+ throw new UnexpectedError(`Parameter \`{${parameterName}}\` has missing value`);
1676
1592
  }
1677
- }
1678
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1679
- finally {
1680
- try {
1681
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1593
+ else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
1594
+ // TODO: [🍵]
1595
+ throw new UnexpectedError(`Parameter \`{${parameterName}}\` is restricted to use`);
1682
1596
  }
1683
- finally { if (e_1) throw e_1.error; }
1684
1597
  }
1685
- var replacedTemplates = template;
1686
- var match;
1687
- var loopLimit = LOOP_LIMIT;
1688
- var _loop_1 = function () {
1598
+ let replacedTemplates = template;
1599
+ let match;
1600
+ let loopLimit = LOOP_LIMIT;
1601
+ while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
1602
+ .exec(replacedTemplates))) {
1689
1603
  if (loopLimit-- < 0) {
1690
1604
  throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
1691
1605
  }
1692
- var precol = match.groups.precol;
1693
- var parameterName = match.groups.parameterName;
1606
+ const precol = match.groups.precol;
1607
+ const parameterName = match.groups.parameterName;
1694
1608
  if (parameterName === '') {
1695
- return "continue";
1609
+ // Note: Skip empty placeholders. It's used to avoid confusion with JSON-like strings
1610
+ continue;
1696
1611
  }
1697
1612
  if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
1698
1613
  throw new PipelineExecutionError('Parameter is already opened or not closed');
1699
1614
  }
1700
1615
  if (parameters[parameterName] === undefined) {
1701
- throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
1616
+ throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
1702
1617
  }
1703
- var parameterValue = parameters[parameterName];
1618
+ let parameterValue = parameters[parameterName];
1704
1619
  if (parameterValue === undefined) {
1705
- throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
1620
+ throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
1706
1621
  }
1707
1622
  parameterValue = valueToString(parameterValue);
1708
1623
  // Escape curly braces in parameter values to prevent prompt-injection
@@ -1710,17 +1625,13 @@
1710
1625
  if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
1711
1626
  parameterValue = parameterValue
1712
1627
  .split('\n')
1713
- .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
1628
+ .map((line, index) => (index === 0 ? line : `${precol}${line}`))
1714
1629
  .join('\n');
1715
1630
  }
1716
1631
  replacedTemplates =
1717
1632
  replacedTemplates.substring(0, match.index + precol.length) +
1718
1633
  parameterValue +
1719
1634
  replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
1720
- };
1721
- while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
1722
- .exec(replacedTemplates))) {
1723
- _loop_1();
1724
1635
  }
1725
1636
  // [💫] Check if there are parameters that are not closed properly
1726
1637
  if (/{\w+$/.test(replacedTemplates)) {
@@ -1746,26 +1657,19 @@
1746
1657
  * @returns the prompt string
1747
1658
  * @public exported from `@promptbook/utils`
1748
1659
  */
1749
- function prompt(strings) {
1750
- var values = [];
1751
- for (var _i = 1; _i < arguments.length; _i++) {
1752
- values[_i - 1] = arguments[_i];
1753
- }
1660
+ function prompt(strings, ...values) {
1754
1661
  if (values.length === 0) {
1755
1662
  return spaceTrim__default["default"](strings.join(''));
1756
1663
  }
1757
- var stringsWithHiddenParameters = strings.map(function (stringsItem) {
1758
- // TODO: [0] DRY
1759
- return stringsItem.split('{').join("".concat(REPLACING_NONCE, "beginbracket")).split('}').join("".concat(REPLACING_NONCE, "endbracket"));
1760
- });
1761
- var placeholderParameterNames = values.map(function (value, i) { return "".concat(REPLACING_NONCE).concat(i); });
1762
- var parameters = Object.fromEntries(values.map(function (value, i) { return [placeholderParameterNames[i], value]; }));
1664
+ const stringsWithHiddenParameters = strings.map((stringsItem) =>
1665
+ // TODO: [0] DRY
1666
+ stringsItem.split('{').join(`${REPLACING_NONCE}beginbracket`).split('}').join(`${REPLACING_NONCE}endbracket`));
1667
+ const placeholderParameterNames = values.map((value, i) => `${REPLACING_NONCE}${i}`);
1668
+ const parameters = Object.fromEntries(values.map((value, i) => [placeholderParameterNames[i], value]));
1763
1669
  // Combine strings and values
1764
- var pipelineString = stringsWithHiddenParameters.reduce(function (result, stringsItem, i) {
1765
- return placeholderParameterNames[i] === undefined
1766
- ? "".concat(result).concat(stringsItem)
1767
- : "".concat(result).concat(stringsItem, "{").concat(placeholderParameterNames[i], "}");
1768
- }, '');
1670
+ let pipelineString = stringsWithHiddenParameters.reduce((result, stringsItem, i) => placeholderParameterNames[i] === undefined
1671
+ ? `${result}${stringsItem}`
1672
+ : `${result}${stringsItem}{${placeholderParameterNames[i]}}`, '');
1769
1673
  pipelineString = spaceTrim__default["default"](pipelineString);
1770
1674
  try {
1771
1675
  pipelineString = templateParameters(pipelineString, parameters);
@@ -1774,14 +1678,19 @@
1774
1678
  if (!(error instanceof PipelineExecutionError)) {
1775
1679
  throw error;
1776
1680
  }
1777
- console.error({ pipelineString: pipelineString, parameters: parameters, placeholderParameterNames: placeholderParameterNames, error: error });
1778
- throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n Internal error in prompt template literal\n \n ".concat(block(JSON.stringify({ strings: strings, values: values }, null, 4)), "}\n \n "); }));
1681
+ console.error({ pipelineString, parameters, placeholderParameterNames, error });
1682
+ throw new UnexpectedError(spaceTrim__default["default"]((block) => `
1683
+ Internal error in prompt template literal
1684
+
1685
+ ${block(JSON.stringify({ strings, values }, null, 4))}}
1686
+
1687
+ `));
1779
1688
  }
1780
1689
  // TODO: [0] DRY
1781
1690
  pipelineString = pipelineString
1782
- .split("".concat(REPLACING_NONCE, "beginbracket"))
1691
+ .split(`${REPLACING_NONCE}beginbracket`)
1783
1692
  .join('{')
1784
- .split("".concat(REPLACING_NONCE, "endbracket"))
1693
+ .split(`${REPLACING_NONCE}endbracket`)
1785
1694
  .join('}');
1786
1695
  return pipelineString;
1787
1696
  }
@@ -1796,7 +1705,7 @@
1796
1705
  * @alias prompt
1797
1706
  * @public exported from `@promptbook/utils`
1798
1707
  */
1799
- var promptTemplate = prompt;
1708
+ const promptTemplate = prompt;
1800
1709
  /**
1801
1710
  * TODO: [🧠][🈴] Where is the best location for this file
1802
1711
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1821,7 +1730,13 @@
1821
1730
  *
1822
1731
  * @public exported from `@promptbook/utils`
1823
1732
  */
1824
- var $isRunningInBrowser = new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
1733
+ const $isRunningInBrowser = new Function(`
1734
+ try {
1735
+ return this === window;
1736
+ } catch (e) {
1737
+ return false;
1738
+ }
1739
+ `);
1825
1740
  /**
1826
1741
  * TODO: [🎺]
1827
1742
  */
@@ -1833,7 +1748,13 @@
1833
1748
  *
1834
1749
  * @public exported from `@promptbook/utils`
1835
1750
  */
1836
- var $isRunningInJest = new Function("\n try {\n return process.env.JEST_WORKER_ID !== undefined;\n } catch (e) {\n return false;\n }\n");
1751
+ const $isRunningInJest = new Function(`
1752
+ try {
1753
+ return process.env.JEST_WORKER_ID !== undefined;
1754
+ } catch (e) {
1755
+ return false;
1756
+ }
1757
+ `);
1837
1758
  /**
1838
1759
  * TODO: [🎺]
1839
1760
  */
@@ -1845,7 +1766,13 @@
1845
1766
  *
1846
1767
  * @public exported from `@promptbook/utils`
1847
1768
  */
1848
- var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
1769
+ const $isRunningInNode = new Function(`
1770
+ try {
1771
+ return this === global;
1772
+ } catch (e) {
1773
+ return false;
1774
+ }
1775
+ `);
1849
1776
  /**
1850
1777
  * TODO: [🎺]
1851
1778
  */
@@ -1857,7 +1784,17 @@
1857
1784
  *
1858
1785
  * @public exported from `@promptbook/utils`
1859
1786
  */
1860
- var $isRunningInWebWorker = new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
1787
+ const $isRunningInWebWorker = new Function(`
1788
+ try {
1789
+ if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
1790
+ return true;
1791
+ } else {
1792
+ return false;
1793
+ }
1794
+ } catch (e) {
1795
+ return false;
1796
+ }
1797
+ `);
1861
1798
  /**
1862
1799
  * TODO: [🎺]
1863
1800
  */
@@ -1867,13 +1804,13 @@
1867
1804
  *
1868
1805
  * @public exported from `@promptbook/utils`
1869
1806
  */
1870
- var CHARACTERS_PER_STANDARD_LINE = 63;
1807
+ const CHARACTERS_PER_STANDARD_LINE = 63;
1871
1808
  /**
1872
1809
  * Number of lines per standard A4 page with 11pt Arial font size and standard margins and spacing.
1873
1810
  *
1874
1811
  * @public exported from `@promptbook/utils`
1875
1812
  */
1876
- var LINES_PER_STANDARD_PAGE = 44;
1813
+ const LINES_PER_STANDARD_PAGE = 44;
1877
1814
  /**
1878
1815
  * TODO: [🧠] Should be this `constants.ts` or `config.ts`?
1879
1816
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1904,8 +1841,8 @@
1904
1841
  function countLines(text) {
1905
1842
  text = text.replace('\r\n', '\n');
1906
1843
  text = text.replace('\r', '\n');
1907
- var lines = text.split('\n');
1908
- return lines.reduce(function (count, line) { return count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE); }, 0);
1844
+ const lines = text.split('\n');
1845
+ return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
1909
1846
  }
1910
1847
 
1911
1848
  /**
@@ -1925,7 +1862,7 @@
1925
1862
  * @public exported from `@promptbook/utils`
1926
1863
  */
1927
1864
  function countParagraphs(text) {
1928
- return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
1865
+ return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
1929
1866
  }
1930
1867
 
1931
1868
  /**
@@ -1934,7 +1871,7 @@
1934
1871
  * @public exported from `@promptbook/utils`
1935
1872
  */
1936
1873
  function splitIntoSentences(text) {
1937
- return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
1874
+ return text.split(/[.!?]+/).filter((sentence) => sentence.trim() !== '');
1938
1875
  }
1939
1876
  /**
1940
1877
  * Counts number of sentences in the text
@@ -1953,7 +1890,9 @@
1953
1890
  function countWords(text) {
1954
1891
  text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
1955
1892
  text = removeDiacritics(text);
1956
- return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
1893
+ // Add spaces before uppercase letters preceded by lowercase letters (for camelCase)
1894
+ text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
1895
+ return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
1957
1896
  }
1958
1897
 
1959
1898
  /**
@@ -1961,7 +1900,7 @@
1961
1900
  *
1962
1901
  * @public exported from `@promptbook/utils`
1963
1902
  */
1964
- var CountUtils = {
1903
+ const CountUtils = {
1965
1904
  CHARACTERS: countCharacters,
1966
1905
  WORDS: countWords,
1967
1906
  SENTENCES: countSentences,
@@ -2002,46 +1941,35 @@
2002
1941
  * @public exported from `@promptbook/utils`
2003
1942
  */
2004
1943
  function normalizeTo_SCREAMING_CASE(text) {
2005
- var e_1, _a;
2006
- var charType;
2007
- var lastCharType = 'OTHER';
2008
- var normalizedName = '';
2009
- try {
2010
- for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
2011
- var char = text_1_1.value;
2012
- var normalizedChar = void 0;
2013
- if (/^[a-z]$/.test(char)) {
2014
- charType = 'LOWERCASE';
2015
- normalizedChar = char.toUpperCase();
2016
- }
2017
- else if (/^[A-Z]$/.test(char)) {
2018
- charType = 'UPPERCASE';
2019
- normalizedChar = char;
2020
- }
2021
- else if (/^[0-9]$/.test(char)) {
2022
- charType = 'NUMBER';
2023
- normalizedChar = char;
2024
- }
2025
- else {
2026
- charType = 'OTHER';
2027
- normalizedChar = '_';
2028
- }
2029
- if (charType !== lastCharType &&
2030
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
2031
- !(lastCharType === 'NUMBER') &&
2032
- !(charType === 'NUMBER')) {
2033
- normalizedName += '_';
2034
- }
2035
- normalizedName += normalizedChar;
2036
- lastCharType = charType;
1944
+ let charType;
1945
+ let lastCharType = 'OTHER';
1946
+ let normalizedName = '';
1947
+ for (const char of text) {
1948
+ let normalizedChar;
1949
+ if (/^[a-z]$/.test(char)) {
1950
+ charType = 'LOWERCASE';
1951
+ normalizedChar = char.toUpperCase();
1952
+ }
1953
+ else if (/^[A-Z]$/.test(char)) {
1954
+ charType = 'UPPERCASE';
1955
+ normalizedChar = char;
1956
+ }
1957
+ else if (/^[0-9]$/.test(char)) {
1958
+ charType = 'NUMBER';
1959
+ normalizedChar = char;
2037
1960
  }
2038
- }
2039
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2040
- finally {
2041
- try {
2042
- if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
1961
+ else {
1962
+ charType = 'OTHER';
1963
+ normalizedChar = '_';
1964
+ }
1965
+ if (charType !== lastCharType &&
1966
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1967
+ !(lastCharType === 'NUMBER') &&
1968
+ !(charType === 'NUMBER')) {
1969
+ normalizedName += '_';
2043
1970
  }
2044
- finally { if (e_1) throw e_1.error; }
1971
+ normalizedName += normalizedChar;
1972
+ lastCharType = charType;
2045
1973
  }
2046
1974
  normalizedName = normalizedName.replace(/_+/g, '_');
2047
1975
  normalizedName = normalizedName.replace(/_?\/_?/g, '/');
@@ -2066,10 +1994,10 @@
2066
1994
  * @public exported from `@promptbook/utils`
2067
1995
  */
2068
1996
  function parseKeywordsFromString(input) {
2069
- var keywords = normalizeTo_SCREAMING_CASE(removeDiacritics(input))
1997
+ const keywords = normalizeTo_SCREAMING_CASE(removeDiacritics(input))
2070
1998
  .toLowerCase()
2071
1999
  .split(/[^a-z0-9]+/gs)
2072
- .filter(function (value) { return value; });
2000
+ .filter((value) => value);
2073
2001
  return new Set(keywords);
2074
2002
  }
2075
2003
 
@@ -2082,12 +2010,12 @@
2082
2010
  * @public exported from `@promptbook/utils`
2083
2011
  */
2084
2012
  function isValidKeyword(keyword) {
2085
- var keywordParsed = parseKeywordsFromString(keyword);
2013
+ const keywordParsed = parseKeywordsFromString(keyword);
2086
2014
  if (keywordParsed.size !== 1) {
2087
2015
  return false;
2088
2016
  }
2089
- var keywordParsedArray = Array.from(keywordParsed);
2090
- var keywordParsedFirst = keywordParsedArray[0];
2017
+ const keywordParsedArray = Array.from(keywordParsed);
2018
+ const keywordParsedFirst = keywordParsedArray[0];
2091
2019
  return keywordParsedFirst === keyword;
2092
2020
  }
2093
2021
 
@@ -2100,7 +2028,7 @@
2100
2028
  * @public exported from `@promptbook/utils`
2101
2029
  */
2102
2030
  function nameToUriPart(name) {
2103
- var uriPart = name;
2031
+ let uriPart = name;
2104
2032
  uriPart = uriPart.toLowerCase();
2105
2033
  uriPart = removeDiacritics(uriPart);
2106
2034
  uriPart = uriPart.replace(/[^a-zA-Z0-9]+/g, '-');
@@ -2120,7 +2048,7 @@
2120
2048
  function nameToUriParts(name) {
2121
2049
  return nameToUriPart(name)
2122
2050
  .split('-')
2123
- .filter(function (value) { return value !== ''; });
2051
+ .filter((value) => value !== '');
2124
2052
  }
2125
2053
 
2126
2054
  /**
@@ -2172,7 +2100,7 @@
2172
2100
  }
2173
2101
  else if (typeof input === 'object') {
2174
2102
  if (Array.isArray(input)) {
2175
- return input.map(parseKeywords).reduce(function (a, b) { return new Set(__spreadArray(__spreadArray([], __read(a), false), __read(b), false)); }, new Set());
2103
+ return input.map(parseKeywords).reduce((a, b) => new Set([...a, ...b]), new Set());
2176
2104
  }
2177
2105
  else if (input === null) {
2178
2106
  return new Set();
@@ -2199,26 +2127,10 @@
2199
2127
  * @public exported from `@promptbook/utils`
2200
2128
  */
2201
2129
  function searchKeywords(haystack, needle) {
2202
- var e_1, _a;
2203
- var _loop_1 = function (needleWord) {
2204
- if (!__spreadArray([], __read(haystack), false).some(function (haystackWord) { return haystackWord.substring(0, needleWord.length) === needleWord; })) {
2205
- return { value: false };
2206
- }
2207
- };
2208
- try {
2209
- for (var needle_1 = __values(needle), needle_1_1 = needle_1.next(); !needle_1_1.done; needle_1_1 = needle_1.next()) {
2210
- var needleWord = needle_1_1.value;
2211
- var state_1 = _loop_1(needleWord);
2212
- if (typeof state_1 === "object")
2213
- return state_1.value;
2214
- }
2215
- }
2216
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2217
- finally {
2218
- try {
2219
- if (needle_1_1 && !needle_1_1.done && (_a = needle_1.return)) _a.call(needle_1);
2130
+ for (const needleWord of needle) {
2131
+ if (![...haystack].some((haystackWord) => haystackWord.substring(0, needleWord.length) === needleWord)) {
2132
+ return false;
2220
2133
  }
2221
- finally { if (e_1) throw e_1.error; }
2222
2134
  }
2223
2135
  return true;
2224
2136
  }
@@ -2229,8 +2141,8 @@
2229
2141
  * @public exported from `@promptbook/utils`
2230
2142
  */
2231
2143
  function suffixUrl(value, suffix) {
2232
- var baseUrl = value.href.endsWith('/') ? value.href.slice(0, -1) : value.href;
2233
- var normalizedSuffix = suffix.replace(/\/+/g, '/');
2144
+ const baseUrl = value.href.endsWith('/') ? value.href.slice(0, -1) : value.href;
2145
+ const normalizedSuffix = suffix.replace(/\/+/g, '/');
2234
2146
  return (baseUrl + normalizedSuffix);
2235
2147
  }
2236
2148
 
@@ -2243,7 +2155,7 @@
2243
2155
  * @public exported from `@promptbook/utils`
2244
2156
  * @see https://github.com/hejny/spacetrim#usage
2245
2157
  */
2246
- var spaceTrim = spaceTrim$1.spaceTrim;
2158
+ const spaceTrim = spaceTrim$1.spaceTrim;
2247
2159
 
2248
2160
  /**
2249
2161
  * Parses the task and returns the list of all parameter names
@@ -2253,22 +2165,11 @@
2253
2165
  * @public exported from `@promptbook/utils`
2254
2166
  */
2255
2167
  function extractParameterNames(template) {
2256
- var e_1, _a;
2257
- var matches = template.matchAll(/{\w+}/g);
2258
- var parameterNames = new Set();
2259
- try {
2260
- for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
2261
- var match = matches_1_1.value;
2262
- var parameterName = match[0].slice(1, -1);
2263
- parameterNames.add(parameterName);
2264
- }
2265
- }
2266
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2267
- finally {
2268
- try {
2269
- if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
2270
- }
2271
- finally { if (e_1) throw e_1.error; }
2168
+ const matches = template.matchAll(/{\w+}/g);
2169
+ const parameterNames = new Set();
2170
+ for (const match of matches) {
2171
+ const parameterName = match[0].slice(1, -1);
2172
+ parameterNames.add(parameterName);
2272
2173
  }
2273
2174
  return parameterNames;
2274
2175
  }
@@ -2285,7 +2186,7 @@
2285
2186
  * @public exported from `@promptbook/utils`
2286
2187
  */
2287
2188
  function parseNumber(value) {
2288
- var originalValue = value;
2189
+ const originalValue = value;
2289
2190
  if (typeof value === 'number') {
2290
2191
  value = value.toString(); // <- TODO: Maybe more efficient way to do this
2291
2192
  }
@@ -2297,7 +2198,7 @@
2297
2198
  return parseNumber(value.substring(1));
2298
2199
  }
2299
2200
  if (value.startsWith('-')) {
2300
- var number = parseNumber(value.substring(1));
2201
+ const number = parseNumber(value.substring(1));
2301
2202
  if (number === 0) {
2302
2203
  return 0; // <- Note: To prevent -0
2303
2204
  }
@@ -2312,11 +2213,11 @@
2312
2213
  return Infinity;
2313
2214
  }
2314
2215
  if (value.includes('/')) {
2315
- var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
2316
- var numerator = parseNumber(numerator_);
2317
- var denominator = parseNumber(denominator_);
2216
+ const [numerator_, denominator_] = value.split('/');
2217
+ const numerator = parseNumber(numerator_);
2218
+ const denominator = parseNumber(denominator_);
2318
2219
  if (denominator === 0) {
2319
- throw new ParseError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
2220
+ throw new ParseError(`Unable to parse number from "${originalValue}" because denominator is zero`);
2320
2221
  }
2321
2222
  return numerator / denominator;
2322
2223
  }
@@ -2324,15 +2225,15 @@
2324
2225
  return 0;
2325
2226
  }
2326
2227
  if (value.includes('E')) {
2327
- var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
2328
- return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
2228
+ const [significand, exponent] = value.split('E');
2229
+ return parseNumber(significand) * 10 ** parseNumber(exponent);
2329
2230
  }
2330
2231
  if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
2331
- throw new ParseError("Unable to parse number from \"".concat(originalValue, "\""));
2232
+ throw new ParseError(`Unable to parse number from "${originalValue}"`);
2332
2233
  }
2333
- var num = parseFloat(value);
2234
+ const num = parseFloat(value);
2334
2235
  if (isNaN(num)) {
2335
- throw new ParseError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
2236
+ throw new ParseError(`Unexpected NaN when parsing number from "${originalValue}"`);
2336
2237
  }
2337
2238
  return num;
2338
2239
  }
@@ -2374,21 +2275,21 @@
2374
2275
  */
2375
2276
  function clonePipeline(pipeline) {
2376
2277
  // Note: Not using spread operator (...) because @@@
2377
- var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations, sources = pipeline.sources;
2278
+ const { pipelineUrl, sourceFile, title, bookVersion, description, formfactorName, parameters, tasks, knowledgeSources, knowledgePieces, personas, preparations, sources, } = pipeline;
2378
2279
  return {
2379
- pipelineUrl: pipelineUrl,
2380
- sourceFile: sourceFile,
2381
- title: title,
2382
- bookVersion: bookVersion,
2383
- description: description,
2384
- formfactorName: formfactorName,
2385
- parameters: parameters,
2386
- tasks: tasks,
2387
- knowledgeSources: knowledgeSources,
2388
- knowledgePieces: knowledgePieces,
2389
- personas: personas,
2390
- preparations: preparations,
2391
- sources: sources,
2280
+ pipelineUrl,
2281
+ sourceFile,
2282
+ title,
2283
+ bookVersion,
2284
+ description,
2285
+ formfactorName,
2286
+ parameters,
2287
+ tasks,
2288
+ knowledgeSources,
2289
+ knowledgePieces,
2290
+ personas,
2291
+ preparations,
2292
+ sources,
2392
2293
  };
2393
2294
  }
2394
2295
  /**
@@ -2417,7 +2318,7 @@
2417
2318
  */
2418
2319
  function isSerializableAsJson(value) {
2419
2320
  try {
2420
- checkSerializableAsJson({ value: value });
2321
+ checkSerializableAsJson({ value });
2421
2322
  return true;
2422
2323
  }
2423
2324
  catch (error) {
@@ -2435,27 +2336,12 @@
2435
2336
  * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2436
2337
  * @public exported from `@promptbook/utils`
2437
2338
  */
2438
- function difference(a, b, isEqual) {
2439
- var e_1, _a;
2440
- if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
2441
- var diff = new Set();
2442
- var _loop_1 = function (itemA) {
2443
- if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
2339
+ function difference(a, b, isEqual = (a, b) => a === b) {
2340
+ const diff = new Set();
2341
+ for (const itemA of Array.from(a)) {
2342
+ if (!Array.from(b).some((itemB) => isEqual(itemA, itemB))) {
2444
2343
  diff.add(itemA);
2445
2344
  }
2446
- };
2447
- try {
2448
- for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
2449
- var itemA = _c.value;
2450
- _loop_1(itemA);
2451
- }
2452
- }
2453
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2454
- finally {
2455
- try {
2456
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2457
- }
2458
- finally { if (e_1) throw e_1.error; }
2459
2345
  }
2460
2346
  return diff;
2461
2347
  }
@@ -2469,35 +2355,20 @@
2469
2355
  * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2470
2356
  * @public exported from `@promptbook/utils`
2471
2357
  */
2472
- function intersection() {
2473
- var e_1, _a;
2474
- var sets = [];
2475
- for (var _i = 0; _i < arguments.length; _i++) {
2476
- sets[_i] = arguments[_i];
2477
- }
2478
- var intersection = new Set();
2358
+ function intersection(...sets) {
2359
+ const intersection = new Set();
2479
2360
  if (sets[0]) {
2480
- try {
2481
- for (var _b = __values(Array.from(sets[0])), _c = _b.next(); !_c.done; _c = _b.next()) {
2482
- var item = _c.value;
2483
- var isPresentInAllSets = true;
2484
- for (var i = 1; i < sets.length; i++) {
2485
- if (sets[i] !== undefined && !sets[i].has(item)) {
2486
- isPresentInAllSets = false;
2487
- break;
2488
- }
2489
- }
2490
- if (isPresentInAllSets) {
2491
- intersection.add(item);
2361
+ for (const item of Array.from(sets[0])) {
2362
+ let isPresentInAllSets = true;
2363
+ for (let i = 1; i < sets.length; i++) {
2364
+ if (sets[i] !== undefined && !sets[i].has(item)) {
2365
+ isPresentInAllSets = false;
2366
+ break;
2492
2367
  }
2493
2368
  }
2494
- }
2495
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2496
- finally {
2497
- try {
2498
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2369
+ if (isPresentInAllSets) {
2370
+ intersection.add(item);
2499
2371
  }
2500
- finally { if (e_1) throw e_1.error; }
2501
2372
  }
2502
2373
  }
2503
2374
  return intersection;
@@ -2509,37 +2380,12 @@
2509
2380
  * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2510
2381
  * @public exported from `@promptbook/utils`
2511
2382
  */
2512
- function union() {
2513
- var e_1, _a, e_2, _b;
2514
- var sets = [];
2515
- for (var _i = 0; _i < arguments.length; _i++) {
2516
- sets[_i] = arguments[_i];
2517
- }
2518
- var union = new Set();
2519
- try {
2520
- for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
2521
- var set = sets_1_1.value;
2522
- try {
2523
- for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
2524
- var item = _d.value;
2525
- union.add(item);
2526
- }
2527
- }
2528
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
2529
- finally {
2530
- try {
2531
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
2532
- }
2533
- finally { if (e_2) throw e_2.error; }
2534
- }
2535
- }
2536
- }
2537
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2538
- finally {
2539
- try {
2540
- if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
2383
+ function union(...sets) {
2384
+ const union = new Set();
2385
+ for (const set of sets) {
2386
+ for (const item of Array.from(set)) {
2387
+ union.add(item);
2541
2388
  }
2542
- finally { if (e_1) throw e_1.error; }
2543
2389
  }
2544
2390
  return union;
2545
2391
  }
@@ -2592,15 +2438,15 @@
2592
2438
  * @public exported from `@promptbook/utils`
2593
2439
  */
2594
2440
  function unwrapResult(text, options) {
2595
- var _a = options || {}, _b = _a.isTrimmed, isTrimmed = _b === void 0 ? true : _b, _c = _a.isIntroduceSentenceRemoved, isIntroduceSentenceRemoved = _c === void 0 ? true : _c;
2596
- var trimmedText = text;
2441
+ const { isTrimmed = true, isIntroduceSentenceRemoved = true } = options || {};
2442
+ let trimmedText = text;
2597
2443
  // Remove leading and trailing spaces and newlines
2598
2444
  if (isTrimmed) {
2599
2445
  trimmedText = spaceTrim$1.spaceTrim(trimmedText);
2600
2446
  }
2601
- var processedText = trimmedText;
2447
+ let processedText = trimmedText;
2602
2448
  if (isIntroduceSentenceRemoved) {
2603
- var introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
2449
+ const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
2604
2450
  if (introduceSentenceRegex.test(text)) {
2605
2451
  // Remove the introduce sentence and quotes by replacing it with an empty string
2606
2452
  processedText = processedText.replace(introduceSentenceRegex, '');
@@ -2614,7 +2460,7 @@
2614
2460
  return trimmedText;
2615
2461
  }
2616
2462
  // Remove the quotes by extracting the substring without the first and last characters
2617
- var unquotedText = processedText.slice(1, -1);
2463
+ const unquotedText = processedText.slice(1, -1);
2618
2464
  // Check if the text starts and ends with quotes
2619
2465
  if ([
2620
2466
  ['"', '"'],
@@ -2624,8 +2470,7 @@
2624
2470
  ['_', '_'],
2625
2471
  ['„', '“'],
2626
2472
  ['«', '»'] /* <- QUOTES to config */,
2627
- ].some(function (_a) {
2628
- var _b = __read(_a, 2), startQuote = _b[0], endQuote = _b[1];
2473
+ ].some(([startQuote, endQuote]) => {
2629
2474
  if (!processedText.startsWith(startQuote)) {
2630
2475
  return false;
2631
2476
  }
@@ -2761,12 +2606,12 @@
2761
2606
  }
2762
2607
  if (hostname.includes(':')) {
2763
2608
  // IPv6
2764
- var ipParts = hostname.split(':');
2609
+ const ipParts = hostname.split(':');
2765
2610
  return ipParts[0] === 'fc00' || ipParts[0] === 'fd00' || ipParts[0] === 'fe80';
2766
2611
  }
2767
2612
  else {
2768
2613
  // IPv4
2769
- var ipParts = hostname.split('.').map(function (part) { return Number.parseInt(part, 10); });
2614
+ const ipParts = hostname.split('.').map((part) => Number.parseInt(part, 10));
2770
2615
  return (ipParts[0] === 10 ||
2771
2616
  (ipParts[0] === 172 && ipParts[1] >= 16 && ipParts[1] <= 31) ||
2772
2617
  (ipParts[0] === 192 && ipParts[1] === 168));