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