@promptbook/utils 0.86.10 → 0.86.30

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.30';
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
  /**
@@ -814,89 +718,6 @@
814
718
  * TODO: [🕌] When more than 2 functionalities, split into separate functions
815
719
  */
816
720
 
817
- /**
818
- * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
819
- *
820
- * @public exported from `@promptbook/core`
821
- */
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;
829
- }
830
- return ParseError;
831
- }(Error));
832
- /**
833
- * TODO: Maybe split `ParseError` and `ApplyError`
834
- */
835
-
836
- /**
837
- * Parses the given script and returns the list of all used variables that are not defined in the script
838
- *
839
- * @param script from which to extract the variables
840
- * @returns the list of variable names
841
- * @throws {ParseError} if the script is invalid
842
- * @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
843
- */
844
- function extractVariablesFromScript(script) {
845
- var variables = new Set();
846
- var originalScript = script;
847
- script = "(()=>{".concat(script, "})()");
848
- try {
849
- for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
850
- try {
851
- eval(script);
852
- }
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
- }
884
- }
885
- }
886
- catch (error) {
887
- if (!(error instanceof Error)) {
888
- throw error;
889
- }
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 "); }));
893
- }
894
- return variables;
895
- }
896
- /**
897
- * TODO: [🔣] Support for multiple languages - python, java,...
898
- */
899
-
900
721
  /**
901
722
  * This error indicates problems parsing the format value
902
723
  *
@@ -905,65 +726,53 @@
905
726
  *
906
727
  * @public exported from `@promptbook/core`
907
728
  */
908
- var AbstractFormatError = /** @class */ (function (_super) {
909
- __extends(AbstractFormatError, _super);
729
+ class AbstractFormatError extends Error {
910
730
  // Note: To allow instanceof do not put here error `name`
911
731
  // 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;
732
+ constructor(message) {
733
+ super(message);
734
+ Object.setPrototypeOf(this, AbstractFormatError.prototype);
916
735
  }
917
- return AbstractFormatError;
918
- }(Error));
736
+ }
919
737
 
920
738
  /**
921
739
  * This error indicates problem with parsing of CSV
922
740
  *
923
741
  * @public exported from `@promptbook/core`
924
742
  */
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;
743
+ class CsvFormatError extends AbstractFormatError {
744
+ constructor(message) {
745
+ super(message);
746
+ this.name = 'CsvFormatError';
747
+ Object.setPrototypeOf(this, CsvFormatError.prototype);
932
748
  }
933
- return CsvFormatError;
934
- }(AbstractFormatError));
749
+ }
935
750
 
936
751
  /**
937
752
  * This error indicates that the pipeline collection cannot be propperly loaded
938
753
  *
939
754
  * @public exported from `@promptbook/core`
940
755
  */
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;
756
+ class CollectionError extends Error {
757
+ constructor(message) {
758
+ super(message);
759
+ this.name = 'CollectionError';
760
+ Object.setPrototypeOf(this, CollectionError.prototype);
948
761
  }
949
- return CollectionError;
950
- }(Error));
762
+ }
951
763
 
952
764
  /**
953
765
  * This error type indicates that you try to use a feature that is not available in the current environment
954
766
  *
955
767
  * @public exported from `@promptbook/core`
956
768
  */
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;
769
+ class EnvironmentMismatchError extends Error {
770
+ constructor(message) {
771
+ super(message);
772
+ this.name = 'EnvironmentMismatchError';
773
+ Object.setPrototypeOf(this, EnvironmentMismatchError.prototype);
964
774
  }
965
- return EnvironmentMismatchError;
966
- }(Error));
775
+ }
967
776
 
968
777
  /**
969
778
  * This error occurs when some expectation is not met in the execution of the pipeline
@@ -973,166 +782,170 @@
973
782
  * Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
974
783
  * Note: This is a kindof subtype of PipelineExecutionError
975
784
  */
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;
785
+ class ExpectError extends Error {
786
+ constructor(message) {
787
+ super(message);
788
+ this.name = 'ExpectError';
789
+ Object.setPrototypeOf(this, ExpectError.prototype);
983
790
  }
984
- return ExpectError;
985
- }(Error));
791
+ }
986
792
 
987
793
  /**
988
794
  * This error indicates that the promptbook can not retrieve knowledge from external sources
989
795
  *
990
796
  * @public exported from `@promptbook/core`
991
797
  */
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;
798
+ class KnowledgeScrapeError extends Error {
799
+ constructor(message) {
800
+ super(message);
801
+ this.name = 'KnowledgeScrapeError';
802
+ Object.setPrototypeOf(this, KnowledgeScrapeError.prototype);
999
803
  }
1000
- return KnowledgeScrapeError;
1001
- }(Error));
804
+ }
1002
805
 
1003
806
  /**
1004
807
  * This error type indicates that some limit was reached
1005
808
  *
1006
809
  * @public exported from `@promptbook/core`
1007
810
  */
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;
811
+ class LimitReachedError extends Error {
812
+ constructor(message) {
813
+ super(message);
814
+ this.name = 'LimitReachedError';
815
+ Object.setPrototypeOf(this, LimitReachedError.prototype);
1015
816
  }
1016
- return LimitReachedError;
1017
- }(Error));
817
+ }
1018
818
 
1019
819
  /**
1020
820
  * This error type indicates that some tools are missing for pipeline execution or preparation
1021
821
  *
1022
822
  * @public exported from `@promptbook/core`
1023
823
  */
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;
824
+ class MissingToolsError extends Error {
825
+ constructor(message) {
826
+ super(spaceTrim$1.spaceTrim((block) => `
827
+ ${block(message)}
828
+
829
+ Note: You have probbably forgot to provide some tools for pipeline execution or preparation
830
+
831
+ `));
832
+ this.name = 'MissingToolsError';
833
+ Object.setPrototypeOf(this, MissingToolsError.prototype);
1031
834
  }
1032
- return MissingToolsError;
1033
- }(Error));
835
+ }
1034
836
 
1035
837
  /**
1036
838
  * This error indicates that promptbook not found in the collection
1037
839
  *
1038
840
  * @public exported from `@promptbook/core`
1039
841
  */
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;
842
+ class NotFoundError extends Error {
843
+ constructor(message) {
844
+ super(message);
845
+ this.name = 'NotFoundError';
846
+ Object.setPrototypeOf(this, NotFoundError.prototype);
1047
847
  }
1048
- return NotFoundError;
1049
- }(Error));
848
+ }
1050
849
 
1051
850
  /**
1052
851
  * This error type indicates that some part of the code is not implemented yet
1053
852
  *
1054
853
  * @public exported from `@promptbook/core`
1055
854
  */
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;
855
+ class NotYetImplementedError extends Error {
856
+ constructor(message) {
857
+ super(spaceTrim$1.spaceTrim((block) => `
858
+ ${block(message)}
859
+
860
+ Note: This feature is not implemented yet but it will be soon.
861
+
862
+ If you want speed up the implementation or just read more, look here:
863
+ https://github.com/webgptorg/promptbook
864
+
865
+ Or contact us on pavol@ptbk.io
866
+
867
+ `));
868
+ this.name = 'NotYetImplementedError';
869
+ Object.setPrototypeOf(this, NotYetImplementedError.prototype);
1063
870
  }
1064
- return NotYetImplementedError;
1065
- }(Error));
871
+ }
872
+
873
+ /**
874
+ * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
875
+ *
876
+ * @public exported from `@promptbook/core`
877
+ */
878
+ class ParseError extends Error {
879
+ constructor(message) {
880
+ super(message);
881
+ this.name = 'ParseError';
882
+ Object.setPrototypeOf(this, ParseError.prototype);
883
+ }
884
+ }
885
+ /**
886
+ * TODO: Maybe split `ParseError` and `ApplyError`
887
+ */
1066
888
 
1067
889
  /**
1068
890
  * This error indicates errors during the execution of the pipeline
1069
891
  *
1070
892
  * @public exported from `@promptbook/core`
1071
893
  */
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;
894
+ class PipelineExecutionError extends Error {
895
+ constructor(message) {
896
+ super(message);
897
+ this.name = 'PipelineExecutionError';
898
+ Object.setPrototypeOf(this, PipelineExecutionError.prototype);
1079
899
  }
1080
- return PipelineExecutionError;
1081
- }(Error));
900
+ }
1082
901
 
1083
902
  /**
1084
903
  * This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
1085
904
  *
1086
905
  * @public exported from `@promptbook/core`
1087
906
  */
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;
907
+ class PipelineLogicError extends Error {
908
+ constructor(message) {
909
+ super(message);
910
+ this.name = 'PipelineLogicError';
911
+ Object.setPrototypeOf(this, PipelineLogicError.prototype);
1095
912
  }
1096
- return PipelineLogicError;
1097
- }(Error));
913
+ }
1098
914
 
1099
915
  /**
1100
916
  * This error indicates errors in referencing promptbooks between each other
1101
917
  *
1102
918
  * @public exported from `@promptbook/core`
1103
919
  */
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;
920
+ class PipelineUrlError extends Error {
921
+ constructor(message) {
922
+ super(message);
923
+ this.name = 'PipelineUrlError';
924
+ Object.setPrototypeOf(this, PipelineUrlError.prototype);
1111
925
  }
1112
- return PipelineUrlError;
1113
- }(Error));
926
+ }
1114
927
 
1115
928
  /**
1116
929
  * Index of all custom errors
1117
930
  *
1118
931
  * @public exported from `@promptbook/core`
1119
932
  */
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,
933
+ const PROMPTBOOK_ERRORS = {
934
+ AbstractFormatError,
935
+ CsvFormatError,
936
+ CollectionError,
937
+ EnvironmentMismatchError,
938
+ ExpectError,
939
+ KnowledgeScrapeError,
940
+ LimitReachedError,
941
+ MissingToolsError,
942
+ NotFoundError,
943
+ NotYetImplementedError,
944
+ ParseError,
945
+ PipelineExecutionError,
946
+ PipelineLogicError,
947
+ PipelineUrlError,
948
+ UnexpectedError,
1136
949
  // TODO: [🪑]> VersionMismatchError,
1137
950
  };
1138
951
  /**
@@ -1140,15 +953,15 @@
1140
953
  *
1141
954
  * @private for internal usage
1142
955
  */
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,
956
+ const COMMON_JAVASCRIPT_ERRORS = {
957
+ Error,
958
+ EvalError,
959
+ RangeError,
960
+ ReferenceError,
961
+ SyntaxError,
962
+ TypeError,
963
+ URIError,
964
+ AggregateError,
1152
965
  /*
1153
966
  Note: Not widely supported
1154
967
  > InternalError,
@@ -1163,7 +976,10 @@
1163
976
  *
1164
977
  * @private for internal usage
1165
978
  */
1166
- var ALL_ERRORS = __assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
979
+ const ALL_ERRORS = {
980
+ ...PROMPTBOOK_ERRORS,
981
+ ...COMMON_JAVASCRIPT_ERRORS,
982
+ };
1167
983
  /**
1168
984
  * Note: [💞] Ignore a discrepancy between file name and entity name
1169
985
  */
@@ -1174,15 +990,20 @@
1174
990
  * @public exported from `@promptbook/utils`
1175
991
  */
1176
992
  function deserializeError(error) {
1177
- var name = error.name, stack = error.stack;
1178
- var message = error.message;
1179
- var ErrorClass = ALL_ERRORS[error.name];
993
+ const { name, stack } = error;
994
+ let { message } = error;
995
+ let ErrorClass = ALL_ERRORS[error.name];
1180
996
  if (ErrorClass === undefined) {
1181
997
  ErrorClass = Error;
1182
- message = "".concat(name, ": ").concat(message);
998
+ message = `${name}: ${message}`;
1183
999
  }
1184
1000
  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 "); });
1001
+ message = spaceTrim__default["default"]((block) => `
1002
+ ${block(message)}
1003
+
1004
+ Original stack trace:
1005
+ ${block(stack || '')}
1006
+ `);
1186
1007
  }
1187
1008
  return new ErrorClass(message);
1188
1009
  }
@@ -1193,14 +1014,20 @@
1193
1014
  * @public exported from `@promptbook/utils`
1194
1015
  */
1195
1016
  function serializeError(error) {
1196
- var name = error.name, message = error.message, stack = error.stack;
1017
+ const { name, message, stack } = error;
1197
1018
  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 "); }));
1019
+ console.error(spaceTrim__default["default"]((block) => `
1020
+
1021
+ Cannot serialize error with name "${name}"
1022
+
1023
+ ${block(stack || message)}
1024
+
1025
+ `));
1199
1026
  }
1200
1027
  return {
1201
1028
  name: name,
1202
- message: message,
1203
- stack: stack,
1029
+ message,
1030
+ stack,
1204
1031
  };
1205
1032
  }
1206
1033
 
@@ -1213,71 +1040,24 @@
1213
1040
  * @public exported from `@promptbook/utils`
1214
1041
  * @deprecated [🪂] Use queues instead
1215
1042
  */
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
- }
1043
+ async function forEachAsync(array, options, callbackfunction) {
1044
+ const { maxParallelCount = Infinity } = options;
1045
+ let index = 0;
1046
+ let runningTasks = [];
1047
+ const tasks = [];
1048
+ for (const item of array) {
1049
+ const currentIndex = index++;
1050
+ const task = callbackfunction(item, currentIndex, array);
1051
+ tasks.push(task);
1052
+ runningTasks.push(task);
1053
+ /* not await */ Promise.resolve(task).then(() => {
1054
+ runningTasks = runningTasks.filter((t) => t !== task);
1279
1055
  });
1280
- });
1056
+ if (maxParallelCount < runningTasks.length) {
1057
+ await Promise.race(runningTasks);
1058
+ }
1059
+ }
1060
+ await Promise.all(tasks);
1281
1061
  }
1282
1062
 
1283
1063
  /**
@@ -1308,8 +1088,11 @@
1308
1088
  * @public exported from `@promptbook/utils`
1309
1089
  */
1310
1090
  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);
1091
+ const { value, order } = options;
1092
+ const orderedValue = {
1093
+ ...(order === undefined ? {} : Object.fromEntries(order.map((key) => [key, undefined]))),
1094
+ ...value,
1095
+ };
1313
1096
  return orderedValue;
1314
1097
  }
1315
1098
 
@@ -1323,26 +1106,15 @@
1323
1106
  * @public exported from `@promptbook/utils`
1324
1107
  */
1325
1108
  function $deepFreeze(objectValue) {
1326
- var e_1, _a;
1327
1109
  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
- }
1110
+ return Object.freeze(objectValue.map((item) => $deepFreeze(item)));
1339
1111
  }
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);
1112
+ const propertyNames = Object.getOwnPropertyNames(objectValue);
1113
+ for (const propertyName of propertyNames) {
1114
+ const value = objectValue[propertyName];
1115
+ if (value && typeof value === 'object') {
1116
+ $deepFreeze(value);
1344
1117
  }
1345
- finally { if (e_1) throw e_1.error; }
1346
1118
  }
1347
1119
  Object.freeze(objectValue);
1348
1120
  return objectValue;
@@ -1372,10 +1144,9 @@
1372
1144
  * @public exported from `@promptbook/utils`
1373
1145
  */
1374
1146
  function checkSerializableAsJson(options) {
1375
- var e_1, _a;
1376
- var value = options.value, name = options.name, message = options.message;
1147
+ const { value, name, message } = options;
1377
1148
  if (value === undefined) {
1378
- throw new UnexpectedError("".concat(name, " is undefined"));
1149
+ throw new UnexpectedError(`${name} is undefined`);
1379
1150
  }
1380
1151
  else if (value === null) {
1381
1152
  return;
@@ -1390,49 +1161,54 @@
1390
1161
  return;
1391
1162
  }
1392
1163
  else if (typeof value === 'symbol') {
1393
- throw new UnexpectedError("".concat(name, " is symbol"));
1164
+ throw new UnexpectedError(`${name} is symbol`);
1394
1165
  }
1395
1166
  else if (typeof value === 'function') {
1396
- throw new UnexpectedError("".concat(name, " is function"));
1167
+ throw new UnexpectedError(`${name} is function`);
1397
1168
  }
1398
1169
  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 });
1170
+ for (let i = 0; i < value.length; i++) {
1171
+ checkSerializableAsJson({ name: `${name}[${i}]`, value: value[i], message });
1401
1172
  }
1402
1173
  }
1403
1174
  else if (typeof value === 'object') {
1404
1175
  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 "); }));
1176
+ throw new UnexpectedError(spaceTrim__default["default"]((block) => `
1177
+ \`${name}\` is Date
1178
+
1179
+ Use \`string_date_iso8601\` instead
1180
+
1181
+ Additional message for \`${name}\`:
1182
+ ${block(message || '(nothing)')}
1183
+ `));
1406
1184
  }
1407
1185
  else if (value instanceof Map) {
1408
- throw new UnexpectedError("".concat(name, " is Map"));
1186
+ throw new UnexpectedError(`${name} is Map`);
1409
1187
  }
1410
1188
  else if (value instanceof Set) {
1411
- throw new UnexpectedError("".concat(name, " is Set"));
1189
+ throw new UnexpectedError(`${name} is Set`);
1412
1190
  }
1413
1191
  else if (value instanceof RegExp) {
1414
- throw new UnexpectedError("".concat(name, " is RegExp"));
1192
+ throw new UnexpectedError(`${name} is RegExp`);
1415
1193
  }
1416
1194
  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 "); }));
1195
+ throw new UnexpectedError(spaceTrim__default["default"]((block) => `
1196
+ \`${name}\` is unserialized Error
1197
+
1198
+ Use function \`serializeError\`
1199
+
1200
+ Additional message for \`${name}\`:
1201
+ ${block(message || '(nothing)')}
1202
+
1203
+ `));
1418
1204
  }
1419
1205
  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);
1206
+ for (const [subName, subValue] of Object.entries(value)) {
1207
+ if (subValue === undefined) {
1208
+ // Note: undefined in object is serializable - it is just omited
1209
+ continue;
1434
1210
  }
1435
- finally { if (e_1) throw e_1.error; }
1211
+ checkSerializableAsJson({ name: `${name}.${subName}`, value: subValue, message });
1436
1212
  }
1437
1213
  try {
1438
1214
  JSON.stringify(value); // <- TODO: [0]
@@ -1441,7 +1217,14 @@
1441
1217
  if (!(error instanceof Error)) {
1442
1218
  throw error;
1443
1219
  }
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 "); }));
1220
+ throw new UnexpectedError(spaceTrim__default["default"]((block) => `
1221
+ \`${name}\` is not serializable
1222
+
1223
+ ${block(error.stack || error.message)}
1224
+
1225
+ Additional message for \`${name}\`:
1226
+ ${block(message || '(nothing)')}
1227
+ `));
1445
1228
  }
1446
1229
  /*
1447
1230
  TODO: [0] Is there some more elegant way to check circular references?
@@ -1466,7 +1249,12 @@
1466
1249
  }
1467
1250
  }
1468
1251
  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 "); }));
1252
+ throw new UnexpectedError(spaceTrim__default["default"]((block) => `
1253
+ \`${name}\` is unknown type
1254
+
1255
+ Additional message for \`${name}\`:
1256
+ ${block(message || '(nothing)')}
1257
+ `));
1470
1258
  }
1471
1259
  }
1472
1260
  /**
@@ -1512,9 +1300,9 @@
1512
1300
  * @public exported from `@promptbook/utils`
1513
1301
  */
1514
1302
  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 =
1303
+ const { name, value, order, message } = options;
1304
+ checkSerializableAsJson({ name, value, message });
1305
+ const orderedValue =
1518
1306
  // TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
1519
1307
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1520
1308
  // @ts-ignore
@@ -1537,19 +1325,19 @@
1537
1325
  *
1538
1326
  * @private within the repository
1539
1327
  */
1540
- var REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
1328
+ const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
1541
1329
  /**
1542
1330
  * @@@
1543
1331
  *
1544
1332
  * @private within the repository
1545
1333
  */
1546
- var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
1334
+ const RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
1547
1335
  /**
1548
1336
  * @@@
1549
1337
  *
1550
1338
  * @private within the repository
1551
1339
  */
1552
- var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
1340
+ const RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
1553
1341
  /**
1554
1342
  * The names of the parameters that are reserved for special purposes
1555
1343
  *
@@ -1557,7 +1345,7 @@
1557
1345
  */
1558
1346
  exportJson({
1559
1347
  name: 'RESERVED_PARAMETER_NAMES',
1560
- message: "The names of the parameters that are reserved for special purposes",
1348
+ message: `The names of the parameters that are reserved for special purposes`,
1561
1349
  value: [
1562
1350
  'content',
1563
1351
  'context',
@@ -1592,9 +1380,9 @@
1592
1380
  else if (value === -Infinity) {
1593
1381
  return VALUE_STRINGS.negativeInfinity;
1594
1382
  }
1595
- for (var exponent = 0; exponent < 15; exponent++) {
1596
- var factor = Math.pow(10, exponent);
1597
- var valueRounded = Math.round(value * factor) / factor;
1383
+ for (let exponent = 0; exponent < 15; exponent++) {
1384
+ const factor = 10 ** exponent;
1385
+ const valueRounded = Math.round(value * factor) / factor;
1598
1386
  if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
1599
1387
  return valueRounded.toFixed(exponent);
1600
1388
  }
@@ -1662,47 +1450,38 @@
1662
1450
  * @public exported from `@promptbook/utils`
1663
1451
  */
1664
1452
  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
- }
1453
+ for (const [parameterName, parameterValue] of Object.entries(parameters)) {
1454
+ if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
1455
+ throw new UnexpectedError(`Parameter \`{${parameterName}}\` has missing value`);
1676
1456
  }
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);
1457
+ else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
1458
+ // TODO: [🍵]
1459
+ throw new UnexpectedError(`Parameter \`{${parameterName}}\` is restricted to use`);
1682
1460
  }
1683
- finally { if (e_1) throw e_1.error; }
1684
1461
  }
1685
- var replacedTemplates = template;
1686
- var match;
1687
- var loopLimit = LOOP_LIMIT;
1688
- var _loop_1 = function () {
1462
+ let replacedTemplates = template;
1463
+ let match;
1464
+ let loopLimit = LOOP_LIMIT;
1465
+ while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
1466
+ .exec(replacedTemplates))) {
1689
1467
  if (loopLimit-- < 0) {
1690
1468
  throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
1691
1469
  }
1692
- var precol = match.groups.precol;
1693
- var parameterName = match.groups.parameterName;
1470
+ const precol = match.groups.precol;
1471
+ const parameterName = match.groups.parameterName;
1694
1472
  if (parameterName === '') {
1695
- return "continue";
1473
+ // Note: Skip empty placeholders. It's used to avoid confusion with JSON-like strings
1474
+ continue;
1696
1475
  }
1697
1476
  if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
1698
1477
  throw new PipelineExecutionError('Parameter is already opened or not closed');
1699
1478
  }
1700
1479
  if (parameters[parameterName] === undefined) {
1701
- throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
1480
+ throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
1702
1481
  }
1703
- var parameterValue = parameters[parameterName];
1482
+ let parameterValue = parameters[parameterName];
1704
1483
  if (parameterValue === undefined) {
1705
- throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
1484
+ throw new PipelineExecutionError(`Parameter \`{${parameterName}}\` is not defined`);
1706
1485
  }
1707
1486
  parameterValue = valueToString(parameterValue);
1708
1487
  // Escape curly braces in parameter values to prevent prompt-injection
@@ -1710,17 +1489,13 @@
1710
1489
  if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
1711
1490
  parameterValue = parameterValue
1712
1491
  .split('\n')
1713
- .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
1492
+ .map((line, index) => (index === 0 ? line : `${precol}${line}`))
1714
1493
  .join('\n');
1715
1494
  }
1716
1495
  replacedTemplates =
1717
1496
  replacedTemplates.substring(0, match.index + precol.length) +
1718
1497
  parameterValue +
1719
1498
  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
1499
  }
1725
1500
  // [💫] Check if there are parameters that are not closed properly
1726
1501
  if (/{\w+$/.test(replacedTemplates)) {
@@ -1746,26 +1521,19 @@
1746
1521
  * @returns the prompt string
1747
1522
  * @public exported from `@promptbook/utils`
1748
1523
  */
1749
- function prompt(strings) {
1750
- var values = [];
1751
- for (var _i = 1; _i < arguments.length; _i++) {
1752
- values[_i - 1] = arguments[_i];
1753
- }
1524
+ function prompt(strings, ...values) {
1754
1525
  if (values.length === 0) {
1755
1526
  return spaceTrim__default["default"](strings.join(''));
1756
1527
  }
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]; }));
1528
+ const stringsWithHiddenParameters = strings.map((stringsItem) =>
1529
+ // TODO: [0] DRY
1530
+ stringsItem.split('{').join(`${REPLACING_NONCE}beginbracket`).split('}').join(`${REPLACING_NONCE}endbracket`));
1531
+ const placeholderParameterNames = values.map((value, i) => `${REPLACING_NONCE}${i}`);
1532
+ const parameters = Object.fromEntries(values.map((value, i) => [placeholderParameterNames[i], value]));
1763
1533
  // 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
- }, '');
1534
+ let pipelineString = stringsWithHiddenParameters.reduce((result, stringsItem, i) => placeholderParameterNames[i] === undefined
1535
+ ? `${result}${stringsItem}`
1536
+ : `${result}${stringsItem}{${placeholderParameterNames[i]}}`, '');
1769
1537
  pipelineString = spaceTrim__default["default"](pipelineString);
1770
1538
  try {
1771
1539
  pipelineString = templateParameters(pipelineString, parameters);
@@ -1774,14 +1542,19 @@
1774
1542
  if (!(error instanceof PipelineExecutionError)) {
1775
1543
  throw error;
1776
1544
  }
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 "); }));
1545
+ console.error({ pipelineString, parameters, placeholderParameterNames, error });
1546
+ throw new UnexpectedError(spaceTrim__default["default"]((block) => `
1547
+ Internal error in prompt template literal
1548
+
1549
+ ${block(JSON.stringify({ strings, values }, null, 4))}}
1550
+
1551
+ `));
1779
1552
  }
1780
1553
  // TODO: [0] DRY
1781
1554
  pipelineString = pipelineString
1782
- .split("".concat(REPLACING_NONCE, "beginbracket"))
1555
+ .split(`${REPLACING_NONCE}beginbracket`)
1783
1556
  .join('{')
1784
- .split("".concat(REPLACING_NONCE, "endbracket"))
1557
+ .split(`${REPLACING_NONCE}endbracket`)
1785
1558
  .join('}');
1786
1559
  return pipelineString;
1787
1560
  }
@@ -1796,7 +1569,7 @@
1796
1569
  * @alias prompt
1797
1570
  * @public exported from `@promptbook/utils`
1798
1571
  */
1799
- var promptTemplate = prompt;
1572
+ const promptTemplate = prompt;
1800
1573
  /**
1801
1574
  * TODO: [🧠][🈴] Where is the best location for this file
1802
1575
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1821,7 +1594,13 @@
1821
1594
  *
1822
1595
  * @public exported from `@promptbook/utils`
1823
1596
  */
1824
- var $isRunningInBrowser = new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
1597
+ const $isRunningInBrowser = new Function(`
1598
+ try {
1599
+ return this === window;
1600
+ } catch (e) {
1601
+ return false;
1602
+ }
1603
+ `);
1825
1604
  /**
1826
1605
  * TODO: [🎺]
1827
1606
  */
@@ -1833,7 +1612,13 @@
1833
1612
  *
1834
1613
  * @public exported from `@promptbook/utils`
1835
1614
  */
1836
- var $isRunningInJest = new Function("\n try {\n return process.env.JEST_WORKER_ID !== undefined;\n } catch (e) {\n return false;\n }\n");
1615
+ const $isRunningInJest = new Function(`
1616
+ try {
1617
+ return process.env.JEST_WORKER_ID !== undefined;
1618
+ } catch (e) {
1619
+ return false;
1620
+ }
1621
+ `);
1837
1622
  /**
1838
1623
  * TODO: [🎺]
1839
1624
  */
@@ -1845,7 +1630,13 @@
1845
1630
  *
1846
1631
  * @public exported from `@promptbook/utils`
1847
1632
  */
1848
- var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
1633
+ const $isRunningInNode = new Function(`
1634
+ try {
1635
+ return this === global;
1636
+ } catch (e) {
1637
+ return false;
1638
+ }
1639
+ `);
1849
1640
  /**
1850
1641
  * TODO: [🎺]
1851
1642
  */
@@ -1857,7 +1648,17 @@
1857
1648
  *
1858
1649
  * @public exported from `@promptbook/utils`
1859
1650
  */
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");
1651
+ const $isRunningInWebWorker = new Function(`
1652
+ try {
1653
+ if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
1654
+ return true;
1655
+ } else {
1656
+ return false;
1657
+ }
1658
+ } catch (e) {
1659
+ return false;
1660
+ }
1661
+ `);
1861
1662
  /**
1862
1663
  * TODO: [🎺]
1863
1664
  */
@@ -1867,13 +1668,13 @@
1867
1668
  *
1868
1669
  * @public exported from `@promptbook/utils`
1869
1670
  */
1870
- var CHARACTERS_PER_STANDARD_LINE = 63;
1671
+ const CHARACTERS_PER_STANDARD_LINE = 63;
1871
1672
  /**
1872
1673
  * Number of lines per standard A4 page with 11pt Arial font size and standard margins and spacing.
1873
1674
  *
1874
1675
  * @public exported from `@promptbook/utils`
1875
1676
  */
1876
- var LINES_PER_STANDARD_PAGE = 44;
1677
+ const LINES_PER_STANDARD_PAGE = 44;
1877
1678
  /**
1878
1679
  * TODO: [🧠] Should be this `constants.ts` or `config.ts`?
1879
1680
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1904,8 +1705,8 @@
1904
1705
  function countLines(text) {
1905
1706
  text = text.replace('\r\n', '\n');
1906
1707
  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);
1708
+ const lines = text.split('\n');
1709
+ return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
1909
1710
  }
1910
1711
 
1911
1712
  /**
@@ -1925,7 +1726,7 @@
1925
1726
  * @public exported from `@promptbook/utils`
1926
1727
  */
1927
1728
  function countParagraphs(text) {
1928
- return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
1729
+ return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
1929
1730
  }
1930
1731
 
1931
1732
  /**
@@ -1934,7 +1735,7 @@
1934
1735
  * @public exported from `@promptbook/utils`
1935
1736
  */
1936
1737
  function splitIntoSentences(text) {
1937
- return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
1738
+ return text.split(/[.!?]+/).filter((sentence) => sentence.trim() !== '');
1938
1739
  }
1939
1740
  /**
1940
1741
  * Counts number of sentences in the text
@@ -1953,7 +1754,9 @@
1953
1754
  function countWords(text) {
1954
1755
  text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
1955
1756
  text = removeDiacritics(text);
1956
- return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
1757
+ // Add spaces before uppercase letters preceded by lowercase letters (for camelCase)
1758
+ text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
1759
+ return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
1957
1760
  }
1958
1761
 
1959
1762
  /**
@@ -1961,7 +1764,7 @@
1961
1764
  *
1962
1765
  * @public exported from `@promptbook/utils`
1963
1766
  */
1964
- var CountUtils = {
1767
+ const CountUtils = {
1965
1768
  CHARACTERS: countCharacters,
1966
1769
  WORDS: countWords,
1967
1770
  SENTENCES: countSentences,
@@ -2002,46 +1805,35 @@
2002
1805
  * @public exported from `@promptbook/utils`
2003
1806
  */
2004
1807
  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;
1808
+ let charType;
1809
+ let lastCharType = 'OTHER';
1810
+ let normalizedName = '';
1811
+ for (const char of text) {
1812
+ let normalizedChar;
1813
+ if (/^[a-z]$/.test(char)) {
1814
+ charType = 'LOWERCASE';
1815
+ normalizedChar = char.toUpperCase();
1816
+ }
1817
+ else if (/^[A-Z]$/.test(char)) {
1818
+ charType = 'UPPERCASE';
1819
+ normalizedChar = char;
1820
+ }
1821
+ else if (/^[0-9]$/.test(char)) {
1822
+ charType = 'NUMBER';
1823
+ normalizedChar = char;
2037
1824
  }
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);
1825
+ else {
1826
+ charType = 'OTHER';
1827
+ normalizedChar = '_';
1828
+ }
1829
+ if (charType !== lastCharType &&
1830
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1831
+ !(lastCharType === 'NUMBER') &&
1832
+ !(charType === 'NUMBER')) {
1833
+ normalizedName += '_';
2043
1834
  }
2044
- finally { if (e_1) throw e_1.error; }
1835
+ normalizedName += normalizedChar;
1836
+ lastCharType = charType;
2045
1837
  }
2046
1838
  normalizedName = normalizedName.replace(/_+/g, '_');
2047
1839
  normalizedName = normalizedName.replace(/_?\/_?/g, '/');
@@ -2066,10 +1858,10 @@
2066
1858
  * @public exported from `@promptbook/utils`
2067
1859
  */
2068
1860
  function parseKeywordsFromString(input) {
2069
- var keywords = normalizeTo_SCREAMING_CASE(removeDiacritics(input))
1861
+ const keywords = normalizeTo_SCREAMING_CASE(removeDiacritics(input))
2070
1862
  .toLowerCase()
2071
1863
  .split(/[^a-z0-9]+/gs)
2072
- .filter(function (value) { return value; });
1864
+ .filter((value) => value);
2073
1865
  return new Set(keywords);
2074
1866
  }
2075
1867
 
@@ -2082,12 +1874,12 @@
2082
1874
  * @public exported from `@promptbook/utils`
2083
1875
  */
2084
1876
  function isValidKeyword(keyword) {
2085
- var keywordParsed = parseKeywordsFromString(keyword);
1877
+ const keywordParsed = parseKeywordsFromString(keyword);
2086
1878
  if (keywordParsed.size !== 1) {
2087
1879
  return false;
2088
1880
  }
2089
- var keywordParsedArray = Array.from(keywordParsed);
2090
- var keywordParsedFirst = keywordParsedArray[0];
1881
+ const keywordParsedArray = Array.from(keywordParsed);
1882
+ const keywordParsedFirst = keywordParsedArray[0];
2091
1883
  return keywordParsedFirst === keyword;
2092
1884
  }
2093
1885
 
@@ -2100,7 +1892,7 @@
2100
1892
  * @public exported from `@promptbook/utils`
2101
1893
  */
2102
1894
  function nameToUriPart(name) {
2103
- var uriPart = name;
1895
+ let uriPart = name;
2104
1896
  uriPart = uriPart.toLowerCase();
2105
1897
  uriPart = removeDiacritics(uriPart);
2106
1898
  uriPart = uriPart.replace(/[^a-zA-Z0-9]+/g, '-');
@@ -2120,7 +1912,7 @@
2120
1912
  function nameToUriParts(name) {
2121
1913
  return nameToUriPart(name)
2122
1914
  .split('-')
2123
- .filter(function (value) { return value !== ''; });
1915
+ .filter((value) => value !== '');
2124
1916
  }
2125
1917
 
2126
1918
  /**
@@ -2172,7 +1964,7 @@
2172
1964
  }
2173
1965
  else if (typeof input === 'object') {
2174
1966
  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());
1967
+ return input.map(parseKeywords).reduce((a, b) => new Set([...a, ...b]), new Set());
2176
1968
  }
2177
1969
  else if (input === null) {
2178
1970
  return new Set();
@@ -2199,26 +1991,10 @@
2199
1991
  * @public exported from `@promptbook/utils`
2200
1992
  */
2201
1993
  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);
1994
+ for (const needleWord of needle) {
1995
+ if (![...haystack].some((haystackWord) => haystackWord.substring(0, needleWord.length) === needleWord)) {
1996
+ return false;
2220
1997
  }
2221
- finally { if (e_1) throw e_1.error; }
2222
1998
  }
2223
1999
  return true;
2224
2000
  }
@@ -2229,8 +2005,8 @@
2229
2005
  * @public exported from `@promptbook/utils`
2230
2006
  */
2231
2007
  function suffixUrl(value, suffix) {
2232
- var baseUrl = value.href.endsWith('/') ? value.href.slice(0, -1) : value.href;
2233
- var normalizedSuffix = suffix.replace(/\/+/g, '/');
2008
+ const baseUrl = value.href.endsWith('/') ? value.href.slice(0, -1) : value.href;
2009
+ const normalizedSuffix = suffix.replace(/\/+/g, '/');
2234
2010
  return (baseUrl + normalizedSuffix);
2235
2011
  }
2236
2012
 
@@ -2243,7 +2019,7 @@
2243
2019
  * @public exported from `@promptbook/utils`
2244
2020
  * @see https://github.com/hejny/spacetrim#usage
2245
2021
  */
2246
- var spaceTrim = spaceTrim$1.spaceTrim;
2022
+ const spaceTrim = spaceTrim$1.spaceTrim;
2247
2023
 
2248
2024
  /**
2249
2025
  * Parses the task and returns the list of all parameter names
@@ -2253,22 +2029,11 @@
2253
2029
  * @public exported from `@promptbook/utils`
2254
2030
  */
2255
2031
  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; }
2032
+ const matches = template.matchAll(/{\w+}/g);
2033
+ const parameterNames = new Set();
2034
+ for (const match of matches) {
2035
+ const parameterName = match[0].slice(1, -1);
2036
+ parameterNames.add(parameterName);
2272
2037
  }
2273
2038
  return parameterNames;
2274
2039
  }
@@ -2285,7 +2050,7 @@
2285
2050
  * @public exported from `@promptbook/utils`
2286
2051
  */
2287
2052
  function parseNumber(value) {
2288
- var originalValue = value;
2053
+ const originalValue = value;
2289
2054
  if (typeof value === 'number') {
2290
2055
  value = value.toString(); // <- TODO: Maybe more efficient way to do this
2291
2056
  }
@@ -2297,7 +2062,7 @@
2297
2062
  return parseNumber(value.substring(1));
2298
2063
  }
2299
2064
  if (value.startsWith('-')) {
2300
- var number = parseNumber(value.substring(1));
2065
+ const number = parseNumber(value.substring(1));
2301
2066
  if (number === 0) {
2302
2067
  return 0; // <- Note: To prevent -0
2303
2068
  }
@@ -2312,11 +2077,11 @@
2312
2077
  return Infinity;
2313
2078
  }
2314
2079
  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_);
2080
+ const [numerator_, denominator_] = value.split('/');
2081
+ const numerator = parseNumber(numerator_);
2082
+ const denominator = parseNumber(denominator_);
2318
2083
  if (denominator === 0) {
2319
- throw new ParseError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
2084
+ throw new ParseError(`Unable to parse number from "${originalValue}" because denominator is zero`);
2320
2085
  }
2321
2086
  return numerator / denominator;
2322
2087
  }
@@ -2324,15 +2089,15 @@
2324
2089
  return 0;
2325
2090
  }
2326
2091
  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));
2092
+ const [significand, exponent] = value.split('E');
2093
+ return parseNumber(significand) * 10 ** parseNumber(exponent);
2329
2094
  }
2330
2095
  if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
2331
- throw new ParseError("Unable to parse number from \"".concat(originalValue, "\""));
2096
+ throw new ParseError(`Unable to parse number from "${originalValue}"`);
2332
2097
  }
2333
- var num = parseFloat(value);
2098
+ const num = parseFloat(value);
2334
2099
  if (isNaN(num)) {
2335
- throw new ParseError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
2100
+ throw new ParseError(`Unexpected NaN when parsing number from "${originalValue}"`);
2336
2101
  }
2337
2102
  return num;
2338
2103
  }
@@ -2374,21 +2139,21 @@
2374
2139
  */
2375
2140
  function clonePipeline(pipeline) {
2376
2141
  // 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;
2142
+ const { pipelineUrl, sourceFile, title, bookVersion, description, formfactorName, parameters, tasks, knowledgeSources, knowledgePieces, personas, preparations, sources, } = pipeline;
2378
2143
  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,
2144
+ pipelineUrl,
2145
+ sourceFile,
2146
+ title,
2147
+ bookVersion,
2148
+ description,
2149
+ formfactorName,
2150
+ parameters,
2151
+ tasks,
2152
+ knowledgeSources,
2153
+ knowledgePieces,
2154
+ personas,
2155
+ preparations,
2156
+ sources,
2392
2157
  };
2393
2158
  }
2394
2159
  /**
@@ -2417,7 +2182,7 @@
2417
2182
  */
2418
2183
  function isSerializableAsJson(value) {
2419
2184
  try {
2420
- checkSerializableAsJson({ value: value });
2185
+ checkSerializableAsJson({ value });
2421
2186
  return true;
2422
2187
  }
2423
2188
  catch (error) {
@@ -2435,27 +2200,12 @@
2435
2200
  * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2436
2201
  * @public exported from `@promptbook/utils`
2437
2202
  */
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); })) {
2203
+ function difference(a, b, isEqual = (a, b) => a === b) {
2204
+ const diff = new Set();
2205
+ for (const itemA of Array.from(a)) {
2206
+ if (!Array.from(b).some((itemB) => isEqual(itemA, itemB))) {
2444
2207
  diff.add(itemA);
2445
2208
  }
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
2209
  }
2460
2210
  return diff;
2461
2211
  }
@@ -2469,35 +2219,20 @@
2469
2219
  * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2470
2220
  * @public exported from `@promptbook/utils`
2471
2221
  */
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();
2222
+ function intersection(...sets) {
2223
+ const intersection = new Set();
2479
2224
  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);
2225
+ for (const item of Array.from(sets[0])) {
2226
+ let isPresentInAllSets = true;
2227
+ for (let i = 1; i < sets.length; i++) {
2228
+ if (sets[i] !== undefined && !sets[i].has(item)) {
2229
+ isPresentInAllSets = false;
2230
+ break;
2492
2231
  }
2493
2232
  }
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);
2233
+ if (isPresentInAllSets) {
2234
+ intersection.add(item);
2499
2235
  }
2500
- finally { if (e_1) throw e_1.error; }
2501
2236
  }
2502
2237
  }
2503
2238
  return intersection;
@@ -2509,37 +2244,12 @@
2509
2244
  * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2510
2245
  * @public exported from `@promptbook/utils`
2511
2246
  */
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);
2247
+ function union(...sets) {
2248
+ const union = new Set();
2249
+ for (const set of sets) {
2250
+ for (const item of Array.from(set)) {
2251
+ union.add(item);
2541
2252
  }
2542
- finally { if (e_1) throw e_1.error; }
2543
2253
  }
2544
2254
  return union;
2545
2255
  }
@@ -2592,15 +2302,15 @@
2592
2302
  * @public exported from `@promptbook/utils`
2593
2303
  */
2594
2304
  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;
2305
+ const { isTrimmed = true, isIntroduceSentenceRemoved = true } = options || {};
2306
+ let trimmedText = text;
2597
2307
  // Remove leading and trailing spaces and newlines
2598
2308
  if (isTrimmed) {
2599
2309
  trimmedText = spaceTrim$1.spaceTrim(trimmedText);
2600
2310
  }
2601
- var processedText = trimmedText;
2311
+ let processedText = trimmedText;
2602
2312
  if (isIntroduceSentenceRemoved) {
2603
- var introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
2313
+ const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
2604
2314
  if (introduceSentenceRegex.test(text)) {
2605
2315
  // Remove the introduce sentence and quotes by replacing it with an empty string
2606
2316
  processedText = processedText.replace(introduceSentenceRegex, '');
@@ -2614,7 +2324,7 @@
2614
2324
  return trimmedText;
2615
2325
  }
2616
2326
  // Remove the quotes by extracting the substring without the first and last characters
2617
- var unquotedText = processedText.slice(1, -1);
2327
+ const unquotedText = processedText.slice(1, -1);
2618
2328
  // Check if the text starts and ends with quotes
2619
2329
  if ([
2620
2330
  ['"', '"'],
@@ -2624,8 +2334,7 @@
2624
2334
  ['_', '_'],
2625
2335
  ['„', '“'],
2626
2336
  ['«', '»'] /* <- QUOTES to config */,
2627
- ].some(function (_a) {
2628
- var _b = __read(_a, 2), startQuote = _b[0], endQuote = _b[1];
2337
+ ].some(([startQuote, endQuote]) => {
2629
2338
  if (!processedText.startsWith(startQuote)) {
2630
2339
  return false;
2631
2340
  }
@@ -2761,12 +2470,12 @@
2761
2470
  }
2762
2471
  if (hostname.includes(':')) {
2763
2472
  // IPv6
2764
- var ipParts = hostname.split(':');
2473
+ const ipParts = hostname.split(':');
2765
2474
  return ipParts[0] === 'fc00' || ipParts[0] === 'fd00' || ipParts[0] === 'fe80';
2766
2475
  }
2767
2476
  else {
2768
2477
  // IPv4
2769
- var ipParts = hostname.split('.').map(function (part) { return Number.parseInt(part, 10); });
2478
+ const ipParts = hostname.split('.').map((part) => Number.parseInt(part, 10));
2770
2479
  return (ipParts[0] === 10 ||
2771
2480
  (ipParts[0] === 172 && ipParts[1] >= 16 && ipParts[1] <= 31) ||
2772
2481
  (ipParts[0] === 192 && ipParts[1] === 168));
@@ -2864,7 +2573,6 @@
2864
2573
  exports.difference = difference;
2865
2574
  exports.exportJson = exportJson;
2866
2575
  exports.extractParameterNames = extractParameterNames;
2867
- exports.extractVariablesFromScript = extractVariablesFromScript;
2868
2576
  exports.forEachAsync = forEachAsync;
2869
2577
  exports.intersection = intersection;
2870
2578
  exports.isHostnameOnPrivateNetwork = isHostnameOnPrivateNetwork;