@promptbook/markdown-utils 0.77.1 → 0.78.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. package/esm/index.es.js +858 -815
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/core.index.d.ts +10 -0
  4. package/esm/typings/src/_packages/types.index.d.ts +4 -0
  5. package/esm/typings/src/_packages/utils.index.d.ts +4 -8
  6. package/esm/typings/src/commands/_common/types/CommandType.d.ts +17 -0
  7. package/esm/typings/src/config.d.ts +14 -0
  8. package/esm/typings/src/conversion/utils/extractParameterNamesFromTask.d.ts +1 -1
  9. package/esm/typings/src/conversion/utils/{extractVariables.d.ts → extractVariablesFromScript.d.ts} +2 -2
  10. package/esm/typings/src/conversion/utils/removePipelineCommand.d.ts +22 -0
  11. package/esm/typings/src/conversion/utils/{renameParameter.d.ts → renamePipelineParameter.d.ts} +3 -3
  12. package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +6 -0
  13. package/esm/typings/src/execution/execution-report/ExecutionReportString.d.ts +1 -1
  14. package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
  15. package/esm/typings/src/pipeline/PipelineString.d.ts +1 -1
  16. package/esm/typings/src/utils/normalization/titleToName.test.d.ts +1 -0
  17. package/package.json +1 -1
  18. package/umd/index.umd.js +861 -818
  19. package/umd/index.umd.js.map +1 -1
  20. /package/esm/typings/src/conversion/utils/{extractVariables.test.d.ts → extractVariablesFromScript.test.d.ts} +0 -0
  21. /package/esm/typings/src/conversion/utils/{renameParameter.test.d.ts → removePipelineCommand.test.d.ts} +0 -0
  22. /package/esm/typings/src/conversion/utils/{titleToName.test.d.ts → renamePipelineParameter.test.d.ts} +0 -0
  23. /package/esm/typings/src/{conversion/utils → utils/normalization}/titleToName.d.ts +0 -0
package/esm/index.es.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
2
2
  import { format } from 'prettier';
3
3
  import parserHtml from 'prettier/parser-html';
4
- import { basename, join } from 'path';
5
4
  import { forTime } from 'waitasecond';
5
+ import { join, basename } from 'path';
6
6
  import { SHA256 } from 'crypto-js';
7
7
  import hexEncoder from 'crypto-js/enc-hex';
8
8
  import { lookup } from 'mime-types';
@@ -20,7 +20,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
20
20
  *
21
21
  * @see https://github.com/webgptorg/promptbook
22
22
  */
23
- var PROMPTBOOK_ENGINE_VERSION = '0.77.0';
23
+ var PROMPTBOOK_ENGINE_VERSION = '0.78.1';
24
24
  /**
25
25
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
26
26
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -619,204 +619,31 @@ function just(value) {
619
619
  }
620
620
 
621
621
  /**
622
- * @@@
623
- *
624
- * Note: `$` is used to indicate that this function is not a pure function - it mutates given object
625
- * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
626
- *
627
- * @returns The same object as the input, but deeply frozen
628
- * @public exported from `@promptbook/utils`
629
- */
630
- function $deepFreeze(objectValue) {
631
- var e_1, _a;
632
- var propertyNames = Object.getOwnPropertyNames(objectValue);
633
- try {
634
- for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
635
- var propertyName = propertyNames_1_1.value;
636
- var value = objectValue[propertyName];
637
- if (value && typeof value === 'object') {
638
- $deepFreeze(value);
639
- }
640
- }
641
- }
642
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
643
- finally {
644
- try {
645
- if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
646
- }
647
- finally { if (e_1) throw e_1.error; }
648
- }
649
- return Object.freeze(objectValue);
650
- }
651
- /**
652
- * TODO: [🧠] Is there a way how to meaningfully test this utility
653
- */
654
-
655
- /**
656
- * This error type indicates that the error should not happen and its last check before crashing with some other error
622
+ * Warning message for the generated sections and files files
657
623
  *
658
- * @public exported from `@promptbook/core`
624
+ * @private within the repository
659
625
  */
660
- var UnexpectedError = /** @class */ (function (_super) {
661
- __extends(UnexpectedError, _super);
662
- function UnexpectedError(message) {
663
- var _this = _super.call(this, spaceTrim$1(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 https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
664
- _this.name = 'UnexpectedError';
665
- Object.setPrototypeOf(_this, UnexpectedError.prototype);
666
- return _this;
667
- }
668
- return UnexpectedError;
669
- }(Error));
670
-
626
+ var GENERATOR_WARNING = "\u26A0\uFE0F WARNING: This code has been generated so that any manual changes will be overwritten";
671
627
  /**
672
- * Checks if the value is [🚉] serializable as JSON
673
- * If not, throws an UnexpectedError with a rich error message and tracking
628
+ * Name for the Promptbook
674
629
  *
675
- * - Almost all primitives are serializable BUT:
676
- * - `undefined` is not serializable
677
- * - `NaN` is not serializable
678
- * - Objects and arrays are serializable if all their properties are serializable
679
- * - Functions are not serializable
680
- * - Circular references are not serializable
681
- * - `Date` objects are not serializable
682
- * - `Map` and `Set` objects are not serializable
683
- * - `RegExp` objects are not serializable
684
- * - `Error` objects are not serializable
685
- * - `Symbol` objects are not serializable
686
- * - And much more...
630
+ * TODO: [🗽] Unite branding and make single place for it
687
631
  *
688
- * @throws UnexpectedError if the value is not serializable as JSON
689
- * @public exported from `@promptbook/utils`
690
- */
691
- function checkSerializableAsJson(name, value) {
692
- var e_1, _a;
693
- if (value === undefined) {
694
- throw new UnexpectedError("".concat(name, " is undefined"));
695
- }
696
- else if (value === null) {
697
- return;
698
- }
699
- else if (typeof value === 'boolean') {
700
- return;
701
- }
702
- else if (typeof value === 'number' && !isNaN(value)) {
703
- return;
704
- }
705
- else if (typeof value === 'string') {
706
- return;
707
- }
708
- else if (typeof value === 'symbol') {
709
- throw new UnexpectedError("".concat(name, " is symbol"));
710
- }
711
- else if (typeof value === 'function') {
712
- throw new UnexpectedError("".concat(name, " is function"));
713
- }
714
- else if (typeof value === 'object' && Array.isArray(value)) {
715
- for (var i = 0; i < value.length; i++) {
716
- checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
717
- }
718
- }
719
- else if (typeof value === 'object') {
720
- if (value instanceof Date) {
721
- throw new UnexpectedError(spaceTrim("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
722
- }
723
- else if (value instanceof Map) {
724
- throw new UnexpectedError("".concat(name, " is Map"));
725
- }
726
- else if (value instanceof Set) {
727
- throw new UnexpectedError("".concat(name, " is Set"));
728
- }
729
- else if (value instanceof RegExp) {
730
- throw new UnexpectedError("".concat(name, " is RegExp"));
731
- }
732
- else if (value instanceof Error) {
733
- throw new UnexpectedError(spaceTrim("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
734
- }
735
- else {
736
- try {
737
- for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
738
- var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
739
- if (subValue === undefined) {
740
- // Note: undefined in object is serializable - it is just omited
741
- continue;
742
- }
743
- checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
744
- }
745
- }
746
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
747
- finally {
748
- try {
749
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
750
- }
751
- finally { if (e_1) throw e_1.error; }
752
- }
753
- try {
754
- JSON.stringify(value); // <- TODO: [0]
755
- }
756
- catch (error) {
757
- if (!(error instanceof Error)) {
758
- throw error;
759
- }
760
- throw new UnexpectedError(spaceTrim(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
761
- }
762
- /*
763
- TODO: [0] Is there some more elegant way to check circular references?
764
- const seen = new Set();
765
- const stack = [{ value }];
766
- while (stack.length > 0) {
767
- const { value } = stack.pop()!;
768
- if (typeof value === 'object' && value !== null) {
769
- if (seen.has(value)) {
770
- throw new UnexpectedError(`${name} has circular reference`);
771
- }
772
- seen.add(value);
773
- if (Array.isArray(value)) {
774
- stack.push(...value.map((value) => ({ value })));
775
- } else {
776
- stack.push(...Object.values(value).map((value) => ({ value })));
777
- }
778
- }
779
- }
780
- */
781
- return;
782
- }
783
- }
784
- else {
785
- throw new UnexpectedError("".concat(name, " is unknown"));
786
- }
787
- }
788
- /**
789
- * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
790
- * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
791
- * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
632
+ * @public exported from `@promptbook/core`
792
633
  */
793
-
634
+ var NAME = "Promptbook";
794
635
  /**
795
- * @@@
796
- * @@@
797
- *
798
- * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
636
+ * Email of the responsible person
799
637
  *
800
- * @param name - Name of the object for debugging purposes
801
- * @param objectValue - Object to be deeply frozen
802
- * @returns The same object as the input, but deeply frozen
803
- * @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
804
- */
805
- function $asDeeplyFrozenSerializableJson(name, objectValue) {
806
- checkSerializableAsJson(name, objectValue);
807
- return $deepFreeze(objectValue);
808
- }
809
- /**
810
- * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
811
- * TODO: [🧠] Is there a way how to meaningfully test this utility
638
+ * @public exported from `@promptbook/core`
812
639
  */
813
-
640
+ var ADMIN_EMAIL = 'me@pavolhejny.com';
814
641
  /**
815
- * Warning message for the generated sections and files files
642
+ * Name of the responsible person for the Promptbook on GitHub
816
643
  *
817
- * @private within the repository
644
+ * @public exported from `@promptbook/core`
818
645
  */
819
- var GENERATOR_WARNING = "\u26A0\uFE0F WARNING: This code has been generated so that any manual changes will be overwritten";
646
+ var ADMIN_GITHUB_NAME = 'hejny';
820
647
  /**
821
648
  * When the title is not provided, the default title is used
822
649
  *
@@ -874,7 +701,8 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
874
701
  *
875
702
  * @public exported from `@promptbook/core`
876
703
  */
877
- var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
704
+ var RESERVED_PARAMETER_NAMES =
705
+ /* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
878
706
  'content',
879
707
  'context',
880
708
  'knowledge',
@@ -884,7 +712,7 @@ var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMET
884
712
  // <- TODO: list here all command names
885
713
  // <- TODO: Add more like 'date', 'modelName',...
886
714
  // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
887
- ]);
715
+ ];
888
716
  /**
889
717
  * @@@
890
718
  *
@@ -952,6 +780,40 @@ var PipelineLogicError = /** @class */ (function (_super) {
952
780
  return PipelineLogicError;
953
781
  }(Error));
954
782
 
783
+ /**
784
+ * Make error report URL for the given error
785
+ *
786
+ * @private !!!!!!
787
+ */
788
+ function getErrorReportUrl(error) {
789
+ var report = {
790
+ title: "\uD83D\uDC1C Error report from ".concat(NAME),
791
+ body: spaceTrim(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 "); }),
792
+ };
793
+ var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
794
+ reportUrl.searchParams.set('labels', 'bug');
795
+ reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
796
+ reportUrl.searchParams.set('title', report.title);
797
+ reportUrl.searchParams.set('body', report.body);
798
+ return reportUrl;
799
+ }
800
+
801
+ /**
802
+ * This error type indicates that the error should not happen and its last check before crashing with some other error
803
+ *
804
+ * @public exported from `@promptbook/core`
805
+ */
806
+ var UnexpectedError = /** @class */ (function (_super) {
807
+ __extends(UnexpectedError, _super);
808
+ function UnexpectedError(message) {
809
+ var _this = _super.call(this, spaceTrim$1(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;
810
+ _this.name = 'UnexpectedError';
811
+ Object.setPrototypeOf(_this, UnexpectedError.prototype);
812
+ return _this;
813
+ }
814
+ return UnexpectedError;
815
+ }(Error));
816
+
955
817
  /**
956
818
  * Tests if given string is valid semantic version
957
819
  *
@@ -1433,27 +1295,204 @@ function extractParameterNames(template) {
1433
1295
  }
1434
1296
 
1435
1297
  /**
1436
- * Unprepare just strips the preparation data of the pipeline
1298
+ * @@@
1437
1299
  *
1438
- * @public exported from `@promptbook/core`
1300
+ * Note: `$` is used to indicate that this function is not a pure function - it mutates given object
1301
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
1302
+ *
1303
+ * @returns The same object as the input, but deeply frozen
1304
+ * @public exported from `@promptbook/utils`
1439
1305
  */
1440
- function unpreparePipeline(pipeline) {
1441
- var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, tasks = pipeline.tasks;
1442
- personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
1443
- knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
1444
- tasks = tasks.map(function (task) {
1445
- var dependentParameterNames = task.dependentParameterNames;
1446
- var parameterNames = extractParameterNames(task.preparedContent || '');
1447
- dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
1448
- var taskUnprepared = __assign(__assign({}, task), { dependentParameterNames: dependentParameterNames });
1449
- delete taskUnprepared.preparedContent;
1450
- return taskUnprepared;
1451
- });
1452
- return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { tasks: tasks, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
1306
+ function $deepFreeze(objectValue) {
1307
+ var e_1, _a;
1308
+ var propertyNames = Object.getOwnPropertyNames(objectValue);
1309
+ try {
1310
+ for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
1311
+ var propertyName = propertyNames_1_1.value;
1312
+ var value = objectValue[propertyName];
1313
+ if (value && typeof value === 'object') {
1314
+ $deepFreeze(value);
1315
+ }
1316
+ }
1317
+ }
1318
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1319
+ finally {
1320
+ try {
1321
+ if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
1322
+ }
1323
+ finally { if (e_1) throw e_1.error; }
1324
+ }
1325
+ return Object.freeze(objectValue);
1453
1326
  }
1454
1327
  /**
1455
- * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
1456
- * TODO: Write tests for `preparePipeline`
1328
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
1329
+ */
1330
+
1331
+ /**
1332
+ * Checks if the value is [🚉] serializable as JSON
1333
+ * If not, throws an UnexpectedError with a rich error message and tracking
1334
+ *
1335
+ * - Almost all primitives are serializable BUT:
1336
+ * - `undefined` is not serializable
1337
+ * - `NaN` is not serializable
1338
+ * - Objects and arrays are serializable if all their properties are serializable
1339
+ * - Functions are not serializable
1340
+ * - Circular references are not serializable
1341
+ * - `Date` objects are not serializable
1342
+ * - `Map` and `Set` objects are not serializable
1343
+ * - `RegExp` objects are not serializable
1344
+ * - `Error` objects are not serializable
1345
+ * - `Symbol` objects are not serializable
1346
+ * - And much more...
1347
+ *
1348
+ * @throws UnexpectedError if the value is not serializable as JSON
1349
+ * @public exported from `@promptbook/utils`
1350
+ */
1351
+ function checkSerializableAsJson(name, value) {
1352
+ var e_1, _a;
1353
+ if (value === undefined) {
1354
+ throw new UnexpectedError("".concat(name, " is undefined"));
1355
+ }
1356
+ else if (value === null) {
1357
+ return;
1358
+ }
1359
+ else if (typeof value === 'boolean') {
1360
+ return;
1361
+ }
1362
+ else if (typeof value === 'number' && !isNaN(value)) {
1363
+ return;
1364
+ }
1365
+ else if (typeof value === 'string') {
1366
+ return;
1367
+ }
1368
+ else if (typeof value === 'symbol') {
1369
+ throw new UnexpectedError("".concat(name, " is symbol"));
1370
+ }
1371
+ else if (typeof value === 'function') {
1372
+ throw new UnexpectedError("".concat(name, " is function"));
1373
+ }
1374
+ else if (typeof value === 'object' && Array.isArray(value)) {
1375
+ for (var i = 0; i < value.length; i++) {
1376
+ checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
1377
+ }
1378
+ }
1379
+ else if (typeof value === 'object') {
1380
+ if (value instanceof Date) {
1381
+ throw new UnexpectedError(spaceTrim("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
1382
+ }
1383
+ else if (value instanceof Map) {
1384
+ throw new UnexpectedError("".concat(name, " is Map"));
1385
+ }
1386
+ else if (value instanceof Set) {
1387
+ throw new UnexpectedError("".concat(name, " is Set"));
1388
+ }
1389
+ else if (value instanceof RegExp) {
1390
+ throw new UnexpectedError("".concat(name, " is RegExp"));
1391
+ }
1392
+ else if (value instanceof Error) {
1393
+ throw new UnexpectedError(spaceTrim("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
1394
+ }
1395
+ else {
1396
+ try {
1397
+ for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
1398
+ var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
1399
+ if (subValue === undefined) {
1400
+ // Note: undefined in object is serializable - it is just omited
1401
+ continue;
1402
+ }
1403
+ checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
1404
+ }
1405
+ }
1406
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1407
+ finally {
1408
+ try {
1409
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1410
+ }
1411
+ finally { if (e_1) throw e_1.error; }
1412
+ }
1413
+ try {
1414
+ JSON.stringify(value); // <- TODO: [0]
1415
+ }
1416
+ catch (error) {
1417
+ if (!(error instanceof Error)) {
1418
+ throw error;
1419
+ }
1420
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
1421
+ }
1422
+ /*
1423
+ TODO: [0] Is there some more elegant way to check circular references?
1424
+ const seen = new Set();
1425
+ const stack = [{ value }];
1426
+ while (stack.length > 0) {
1427
+ const { value } = stack.pop()!;
1428
+ if (typeof value === 'object' && value !== null) {
1429
+ if (seen.has(value)) {
1430
+ throw new UnexpectedError(`${name} has circular reference`);
1431
+ }
1432
+ seen.add(value);
1433
+ if (Array.isArray(value)) {
1434
+ stack.push(...value.map((value) => ({ value })));
1435
+ } else {
1436
+ stack.push(...Object.values(value).map((value) => ({ value })));
1437
+ }
1438
+ }
1439
+ }
1440
+ */
1441
+ return;
1442
+ }
1443
+ }
1444
+ else {
1445
+ throw new UnexpectedError("".concat(name, " is unknown"));
1446
+ }
1447
+ }
1448
+ /**
1449
+ * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
1450
+ * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
1451
+ * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
1452
+ */
1453
+
1454
+ /**
1455
+ * @@@
1456
+ * @@@
1457
+ *
1458
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
1459
+ *
1460
+ * @param name - Name of the object for debugging purposes
1461
+ * @param objectValue - Object to be deeply frozen
1462
+ * @returns The same object as the input, but deeply frozen
1463
+ * @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
1464
+ */
1465
+ function $asDeeplyFrozenSerializableJson(name, objectValue) {
1466
+ checkSerializableAsJson(name, objectValue);
1467
+ return $deepFreeze(objectValue);
1468
+ }
1469
+ /**
1470
+ * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
1471
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
1472
+ */
1473
+
1474
+ /**
1475
+ * Unprepare just strips the preparation data of the pipeline
1476
+ *
1477
+ * @public exported from `@promptbook/core`
1478
+ */
1479
+ function unpreparePipeline(pipeline) {
1480
+ var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, tasks = pipeline.tasks;
1481
+ personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
1482
+ knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
1483
+ tasks = tasks.map(function (task) {
1484
+ var dependentParameterNames = task.dependentParameterNames;
1485
+ var parameterNames = extractParameterNames(task.preparedContent || '');
1486
+ dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
1487
+ var taskUnprepared = __assign(__assign({}, task), { dependentParameterNames: dependentParameterNames });
1488
+ delete taskUnprepared.preparedContent;
1489
+ return taskUnprepared;
1490
+ });
1491
+ return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { tasks: tasks, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
1492
+ }
1493
+ /**
1494
+ * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
1495
+ * TODO: Write tests for `preparePipeline`
1457
1496
  * TODO: [🍙] Make some standard order of json properties
1458
1497
  */
1459
1498
 
@@ -1562,502 +1601,113 @@ function createCollectionFromJson() {
1562
1601
  return new (SimplePipelineCollection.bind.apply(SimplePipelineCollection, __spreadArray([void 0], __read(promptbooks), false)))();
1563
1602
  }
1564
1603
 
1565
- var defaultDiacriticsRemovalMap = [
1566
- {
1567
- base: 'A',
1568
- 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',
1569
- },
1570
- { base: 'AA', letters: '\uA732' },
1571
- { base: 'AE', letters: '\u00C6\u01FC\u01E2' },
1572
- { base: 'AO', letters: '\uA734' },
1573
- { base: 'AU', letters: '\uA736' },
1574
- { base: 'AV', letters: '\uA738\uA73A' },
1575
- { base: 'AY', letters: '\uA73C' },
1576
- {
1577
- base: 'B',
1578
- letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
1579
- },
1580
- {
1581
- base: 'C',
1582
- letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
1583
- },
1584
- {
1585
- base: 'D',
1586
- letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
1587
- },
1588
- { base: 'DZ', letters: '\u01F1\u01C4' },
1589
- { base: 'Dz', letters: '\u01F2\u01C5' },
1590
- {
1591
- base: 'E',
1592
- letters: '\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E',
1593
- },
1594
- { base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
1595
- {
1596
- base: 'G',
1597
- letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
1598
- },
1599
- {
1600
- base: 'H',
1601
- letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
1602
- },
1603
- {
1604
- base: 'I',
1605
- letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
1606
- },
1607
- { base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
1608
- {
1609
- base: 'K',
1610
- letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
1611
- },
1612
- {
1613
- base: 'L',
1614
- letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
1615
- },
1616
- { base: 'LJ', letters: '\u01C7' },
1617
- { base: 'Lj', letters: '\u01C8' },
1618
- { base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
1619
- {
1620
- base: 'N',
1621
- letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
1622
- },
1623
- { base: 'NJ', letters: '\u01CA' },
1624
- { base: 'Nj', letters: '\u01CB' },
1625
- {
1626
- base: 'O',
1627
- letters: '\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C',
1628
- },
1629
- { base: 'OI', letters: '\u01A2' },
1630
- { base: 'OO', letters: '\uA74E' },
1631
- { base: 'OU', letters: '\u0222' },
1632
- { base: 'OE', letters: '\u008C\u0152' },
1633
- { base: 'oe', letters: '\u009C\u0153' },
1634
- {
1635
- base: 'P',
1636
- letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
1637
- },
1638
- { base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
1639
- {
1640
- base: 'R',
1641
- letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
1642
- },
1643
- {
1644
- base: 'S',
1645
- letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
1646
- },
1647
- {
1648
- base: 'T',
1649
- letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
1650
- },
1651
- { base: 'TZ', letters: '\uA728' },
1652
- {
1653
- base: 'U',
1654
- letters: '\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244',
1655
- },
1656
- { base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
1657
- { base: 'VY', letters: '\uA760' },
1658
- {
1659
- base: 'W',
1660
- letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
1661
- },
1662
- { base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
1663
- {
1664
- base: 'Y',
1665
- letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
1666
- },
1667
- {
1668
- base: 'Z',
1669
- letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
1670
- },
1671
- {
1672
- base: 'a',
1673
- letters: '\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250',
1674
- },
1675
- { base: 'aa', letters: '\uA733' },
1676
- { base: 'ae', letters: '\u00E6\u01FD\u01E3' },
1677
- { base: 'ao', letters: '\uA735' },
1678
- { base: 'au', letters: '\uA737' },
1679
- { base: 'av', letters: '\uA739\uA73B' },
1680
- { base: 'ay', letters: '\uA73D' },
1681
- {
1682
- base: 'b',
1683
- letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
1684
- },
1685
- {
1686
- base: 'c',
1687
- letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
1688
- },
1689
- {
1690
- base: 'd',
1691
- letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
1692
- },
1693
- { base: 'dz', letters: '\u01F3\u01C6' },
1694
- {
1695
- base: 'e',
1696
- letters: '\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD',
1697
- },
1698
- { base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
1699
- {
1700
- base: 'g',
1701
- letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
1702
- },
1703
- {
1704
- base: 'h',
1705
- letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
1706
- },
1707
- { base: 'hv', letters: '\u0195' },
1708
- {
1709
- base: 'i',
1710
- letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
1711
- },
1712
- { base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
1713
- {
1714
- base: 'k',
1715
- letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
1716
- },
1717
- {
1718
- base: 'l',
1719
- letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
1720
- },
1721
- { base: 'lj', letters: '\u01C9' },
1722
- { base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
1723
- {
1724
- base: 'n',
1725
- letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
1726
- },
1727
- { base: 'nj', letters: '\u01CC' },
1728
- {
1729
- base: 'o',
1730
- letters: '\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275',
1731
- },
1732
- { base: 'oi', letters: '\u01A3' },
1733
- { base: 'ou', letters: '\u0223' },
1734
- { base: 'oo', letters: '\uA74F' },
1735
- {
1736
- base: 'p',
1737
- letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
1738
- },
1739
- { base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
1740
- {
1741
- base: 'r',
1742
- letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
1743
- },
1744
- {
1745
- base: 's',
1746
- letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
1747
- },
1748
- {
1749
- base: 't',
1750
- letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
1751
- },
1752
- { base: 'tz', letters: '\uA729' },
1753
- {
1754
- base: 'u',
1755
- letters: '\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289',
1756
- },
1757
- { base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
1758
- { base: 'vy', letters: '\uA761' },
1759
- {
1760
- base: 'w',
1761
- letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
1762
- },
1763
- { base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
1764
- {
1765
- base: 'y',
1766
- letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
1767
- },
1768
- {
1769
- base: 'z',
1770
- letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
1771
- },
1772
- ];
1773
1604
  /**
1774
- * Map of letters from diacritic variant to diacritless variant
1775
- * Contains lowercase and uppercase separatelly
1605
+ * This error type indicates that some tools are missing for pipeline execution or preparation
1776
1606
  *
1777
- * > "á" => "a"
1778
- * > "ě" => "e"
1779
- * > "Ă" => "A"
1780
- * > ...
1607
+ * @public exported from `@promptbook/core`
1608
+ */
1609
+ var MissingToolsError = /** @class */ (function (_super) {
1610
+ __extends(MissingToolsError, _super);
1611
+ function MissingToolsError(message) {
1612
+ var _this = _super.call(this, spaceTrim$1(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;
1613
+ _this.name = 'MissingToolsError';
1614
+ Object.setPrototypeOf(_this, MissingToolsError.prototype);
1615
+ return _this;
1616
+ }
1617
+ return MissingToolsError;
1618
+ }(Error));
1619
+
1620
+ /**
1621
+ * This error indicates errors during the execution of the pipeline
1781
1622
  *
1782
- * @public exported from `@promptbook/utils`
1623
+ * @public exported from `@promptbook/core`
1783
1624
  */
1784
- var DIACRITIC_VARIANTS_LETTERS = {};
1785
- // tslint:disable-next-line: prefer-for-of
1786
- for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
1787
- var letters = defaultDiacriticsRemovalMap[i].letters;
1788
- // tslint:disable-next-line: prefer-for-of
1789
- for (var j = 0; j < letters.length; j++) {
1790
- DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
1625
+ var PipelineExecutionError = /** @class */ (function (_super) {
1626
+ __extends(PipelineExecutionError, _super);
1627
+ function PipelineExecutionError(message) {
1628
+ var _this = _super.call(this, message) || this;
1629
+ _this.name = 'PipelineExecutionError';
1630
+ Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
1631
+ return _this;
1791
1632
  }
1792
- }
1793
- // <- TODO: [🍓] Put to maker function to save execution time if not needed
1794
- /*
1795
- @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
1796
- Licensed under the Apache License, Version 2.0 (the "License");
1797
- you may not use this file except in compliance with the License.
1798
- You may obtain a copy of the License at
1633
+ return PipelineExecutionError;
1634
+ }(Error));
1799
1635
 
1800
- http://www.apache.org/licenses/LICENSE-2.0
1636
+ /**
1637
+ * This error indicates problems parsing the format value
1638
+ *
1639
+ * For example, when the format value is not a valid JSON or CSV
1640
+ * This is not thrown directly but in extended classes
1641
+ *
1642
+ * @public exported from `@promptbook/core`
1643
+ */
1644
+ var AbstractFormatError = /** @class */ (function (_super) {
1645
+ __extends(AbstractFormatError, _super);
1646
+ // Note: To allow instanceof do not put here error `name`
1647
+ // public readonly name = 'AbstractFormatError';
1648
+ function AbstractFormatError(message) {
1649
+ var _this = _super.call(this, message) || this;
1650
+ Object.setPrototypeOf(_this, AbstractFormatError.prototype);
1651
+ return _this;
1652
+ }
1653
+ return AbstractFormatError;
1654
+ }(Error));
1801
1655
 
1802
- Unless required by applicable law or agreed to in writing, software
1803
- distributed under the License is distributed on an "AS IS" BASIS,
1804
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1805
- See the License for the specific language governing permissions and
1806
- limitations under the License.
1807
- */
1656
+ /**
1657
+ * This error indicates problem with parsing of CSV
1658
+ *
1659
+ * @public exported from `@promptbook/core`
1660
+ */
1661
+ var CsvFormatError = /** @class */ (function (_super) {
1662
+ __extends(CsvFormatError, _super);
1663
+ function CsvFormatError(message) {
1664
+ var _this = _super.call(this, message) || this;
1665
+ _this.name = 'CsvFormatError';
1666
+ Object.setPrototypeOf(_this, CsvFormatError.prototype);
1667
+ return _this;
1668
+ }
1669
+ return CsvFormatError;
1670
+ }(AbstractFormatError));
1808
1671
 
1809
1672
  /**
1810
- * @@@
1673
+ * This error indicates that the pipeline collection cannot be propperly loaded
1811
1674
  *
1812
- * @param input @@@
1813
- * @returns @@@
1814
- * @public exported from `@promptbook/utils`
1675
+ * @public exported from `@promptbook/core`
1815
1676
  */
1816
- function removeDiacritics(input) {
1817
- /*eslint no-control-regex: "off"*/
1818
- return input.replace(/[^\u0000-\u007E]/g, function (a) {
1819
- return DIACRITIC_VARIANTS_LETTERS[a] || a;
1820
- });
1821
- }
1677
+ var CollectionError = /** @class */ (function (_super) {
1678
+ __extends(CollectionError, _super);
1679
+ function CollectionError(message) {
1680
+ var _this = _super.call(this, message) || this;
1681
+ _this.name = 'CollectionError';
1682
+ Object.setPrototypeOf(_this, CollectionError.prototype);
1683
+ return _this;
1684
+ }
1685
+ return CollectionError;
1686
+ }(Error));
1687
+
1822
1688
  /**
1823
- * TODO: [Ж] Variant for cyrillic (and in general non-latin) letters
1689
+ * This error type indicates that you try to use a feature that is not available in the current environment
1690
+ *
1691
+ * @public exported from `@promptbook/core`
1824
1692
  */
1693
+ var EnvironmentMismatchError = /** @class */ (function (_super) {
1694
+ __extends(EnvironmentMismatchError, _super);
1695
+ function EnvironmentMismatchError(message) {
1696
+ var _this = _super.call(this, message) || this;
1697
+ _this.name = 'EnvironmentMismatchError';
1698
+ Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
1699
+ return _this;
1700
+ }
1701
+ return EnvironmentMismatchError;
1702
+ }(Error));
1825
1703
 
1826
1704
  /**
1827
- * @@@
1705
+ * This error occurs when some expectation is not met in the execution of the pipeline
1828
1706
  *
1829
- * @param text @@@
1830
- * @returns @@@
1831
- * @example 'hello-world'
1832
- * @example 'i-love-promptbook'
1833
- * @public exported from `@promptbook/utils`
1834
- */
1835
- function normalizeToKebabCase(text) {
1836
- var e_1, _a;
1837
- text = removeDiacritics(text);
1838
- var charType;
1839
- var lastCharType = 'OTHER';
1840
- var normalizedName = '';
1841
- try {
1842
- for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
1843
- var char = text_1_1.value;
1844
- var normalizedChar = void 0;
1845
- if (/^[a-z]$/.test(char)) {
1846
- charType = 'LOWERCASE';
1847
- normalizedChar = char;
1848
- }
1849
- else if (/^[A-Z]$/.test(char)) {
1850
- charType = 'UPPERCASE';
1851
- normalizedChar = char.toLowerCase();
1852
- }
1853
- else if (/^[0-9]$/.test(char)) {
1854
- charType = 'NUMBER';
1855
- normalizedChar = char;
1856
- }
1857
- else {
1858
- charType = 'OTHER';
1859
- normalizedChar = '-';
1860
- }
1861
- if (charType !== lastCharType &&
1862
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1863
- !(lastCharType === 'NUMBER') &&
1864
- !(charType === 'NUMBER')) {
1865
- normalizedName += '-';
1866
- }
1867
- normalizedName += normalizedChar;
1868
- lastCharType = charType;
1869
- }
1870
- }
1871
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1872
- finally {
1873
- try {
1874
- if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
1875
- }
1876
- finally { if (e_1) throw e_1.error; }
1877
- }
1878
- normalizedName = normalizedName.split(/-+/g).join('-');
1879
- normalizedName = normalizedName.split(/-?\/-?/g).join('/');
1880
- normalizedName = normalizedName.replace(/^-/, '');
1881
- normalizedName = normalizedName.replace(/-$/, '');
1882
- return normalizedName;
1883
- }
1884
- /**
1885
- * Note: [💞] Ignore a discrepancy between file name and entity name
1886
- */
1887
-
1888
- /**
1889
- * Removes emojis from a string and fix whitespaces
1890
- *
1891
- * @param text with emojis
1892
- * @returns text without emojis
1893
- * @public exported from `@promptbook/utils`
1894
- */
1895
- function removeEmojis(text) {
1896
- // Replace emojis (and also ZWJ sequence) with hyphens
1897
- text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
1898
- text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
1899
- text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
1900
- text = text.replace(/\p{Extended_Pictographic}/gu, '');
1901
- return text;
1902
- }
1903
-
1904
- /**
1905
- * Tests if given string is valid URL.
1906
- *
1907
- * Note: This does not check if the file exists only if the path is valid
1908
- * @public exported from `@promptbook/utils`
1909
- */
1910
- function isValidFilePath(filename) {
1911
- if (typeof filename !== 'string') {
1912
- return false;
1913
- }
1914
- var filenameSlashes = filename.split('\\').join('/');
1915
- // Absolute Unix path: /hello.txt
1916
- if (/^(\/)/i.test(filenameSlashes)) {
1917
- return true;
1918
- }
1919
- // Absolute Windows path: /hello.txt
1920
- if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
1921
- return true;
1922
- }
1923
- // Relative path: ./hello.txt
1924
- if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
1925
- return true;
1926
- }
1927
- return false;
1928
- }
1929
-
1930
- /**
1931
- * @@@
1932
- *
1933
- * @param value @@@
1934
- * @returns @@@
1935
- * @example @@@
1936
- * @public exported from `@promptbook/utils`
1937
- */
1938
- function titleToName(value) {
1939
- if (isValidUrl(value)) {
1940
- value = value.replace(/^https?:\/\//, '');
1941
- value = value.replace(/\.html$/, '');
1942
- }
1943
- else if (isValidFilePath(value)) {
1944
- value = basename(value);
1945
- // Note: Keeping extension in the name
1946
- }
1947
- value = value.split('/').join('-');
1948
- value = removeEmojis(value);
1949
- value = normalizeToKebabCase(value);
1950
- // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
1951
- return value;
1952
- }
1953
-
1954
- /**
1955
- * This error type indicates that some tools are missing for pipeline execution or preparation
1956
- *
1957
- * @public exported from `@promptbook/core`
1958
- */
1959
- var MissingToolsError = /** @class */ (function (_super) {
1960
- __extends(MissingToolsError, _super);
1961
- function MissingToolsError(message) {
1962
- var _this = _super.call(this, spaceTrim$1(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;
1963
- _this.name = 'MissingToolsError';
1964
- Object.setPrototypeOf(_this, MissingToolsError.prototype);
1965
- return _this;
1966
- }
1967
- return MissingToolsError;
1968
- }(Error));
1969
-
1970
- /**
1971
- * This error indicates errors during the execution of the pipeline
1972
- *
1973
- * @public exported from `@promptbook/core`
1974
- */
1975
- var PipelineExecutionError = /** @class */ (function (_super) {
1976
- __extends(PipelineExecutionError, _super);
1977
- function PipelineExecutionError(message) {
1978
- var _this = _super.call(this, message) || this;
1979
- _this.name = 'PipelineExecutionError';
1980
- Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
1981
- return _this;
1982
- }
1983
- return PipelineExecutionError;
1984
- }(Error));
1985
-
1986
- /**
1987
- * This error indicates problems parsing the format value
1988
- *
1989
- * For example, when the format value is not a valid JSON or CSV
1990
- * This is not thrown directly but in extended classes
1991
- *
1992
- * @public exported from `@promptbook/core`
1993
- */
1994
- var AbstractFormatError = /** @class */ (function (_super) {
1995
- __extends(AbstractFormatError, _super);
1996
- // Note: To allow instanceof do not put here error `name`
1997
- // public readonly name = 'AbstractFormatError';
1998
- function AbstractFormatError(message) {
1999
- var _this = _super.call(this, message) || this;
2000
- Object.setPrototypeOf(_this, AbstractFormatError.prototype);
2001
- return _this;
2002
- }
2003
- return AbstractFormatError;
2004
- }(Error));
2005
-
2006
- /**
2007
- * This error indicates problem with parsing of CSV
2008
- *
2009
- * @public exported from `@promptbook/core`
2010
- */
2011
- var CsvFormatError = /** @class */ (function (_super) {
2012
- __extends(CsvFormatError, _super);
2013
- function CsvFormatError(message) {
2014
- var _this = _super.call(this, message) || this;
2015
- _this.name = 'CsvFormatError';
2016
- Object.setPrototypeOf(_this, CsvFormatError.prototype);
2017
- return _this;
2018
- }
2019
- return CsvFormatError;
2020
- }(AbstractFormatError));
2021
-
2022
- /**
2023
- * This error indicates that the pipeline collection cannot be propperly loaded
2024
- *
2025
- * @public exported from `@promptbook/core`
2026
- */
2027
- var CollectionError = /** @class */ (function (_super) {
2028
- __extends(CollectionError, _super);
2029
- function CollectionError(message) {
2030
- var _this = _super.call(this, message) || this;
2031
- _this.name = 'CollectionError';
2032
- Object.setPrototypeOf(_this, CollectionError.prototype);
2033
- return _this;
2034
- }
2035
- return CollectionError;
2036
- }(Error));
2037
-
2038
- /**
2039
- * This error type indicates that you try to use a feature that is not available in the current environment
2040
- *
2041
- * @public exported from `@promptbook/core`
2042
- */
2043
- var EnvironmentMismatchError = /** @class */ (function (_super) {
2044
- __extends(EnvironmentMismatchError, _super);
2045
- function EnvironmentMismatchError(message) {
2046
- var _this = _super.call(this, message) || this;
2047
- _this.name = 'EnvironmentMismatchError';
2048
- Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
2049
- return _this;
2050
- }
2051
- return EnvironmentMismatchError;
2052
- }(Error));
2053
-
2054
- /**
2055
- * This error occurs when some expectation is not met in the execution of the pipeline
2056
- *
2057
- * @public exported from `@promptbook/core`
2058
- * Note: Do not throw this error, its reserved for `checkExpectations` and `createPipelineExecutor` and public ONLY to be serializable through remote server
2059
- * Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
2060
- * Note: This is a kindof subtype of PipelineExecutionError
1707
+ * @public exported from `@promptbook/core`
1708
+ * Note: Do not throw this error, its reserved for `checkExpectations` and `createPipelineExecutor` and public ONLY to be serializable through remote server
1709
+ * Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
1710
+ * Note: This is a kindof subtype of PipelineExecutionError
2061
1711
  */
2062
1712
  var ExpectError = /** @class */ (function (_super) {
2063
1713
  __extends(ExpectError, _super);
@@ -3100,148 +2750,471 @@ var $Register = /** @class */ (function () {
3100
2750
  return $Register;
3101
2751
  }());
3102
2752
 
3103
- /**
3104
- * @@@
3105
- *
3106
- * Note: `$` is used to indicate that this interacts with the global scope
3107
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
3108
- * @public exported from `@promptbook/core`
3109
- */
3110
- var $scrapersMetadataRegister = new $Register('scrapers_metadata');
3111
- /**
3112
- * TODO: [®] DRY Register logic
3113
- */
2753
+ /**
2754
+ * @@@
2755
+ *
2756
+ * Note: `$` is used to indicate that this interacts with the global scope
2757
+ * @singleton Only one instance of each register is created per build, but thare can be more @@@
2758
+ * @public exported from `@promptbook/core`
2759
+ */
2760
+ var $scrapersMetadataRegister = new $Register('scrapers_metadata');
2761
+ /**
2762
+ * TODO: [®] DRY Register logic
2763
+ */
2764
+
2765
+ /**
2766
+ * @@@
2767
+ *
2768
+ * Note: `$` is used to indicate that this interacts with the global scope
2769
+ * @singleton Only one instance of each register is created per build, but thare can be more @@@
2770
+ * @public exported from `@promptbook/core`
2771
+ */
2772
+ var $scrapersRegister = new $Register('scraper_constructors');
2773
+ /**
2774
+ * TODO: [®] DRY Register logic
2775
+ */
2776
+
2777
+ /**
2778
+ * Creates a message with all registered scrapers
2779
+ *
2780
+ * Note: This function is used to create a (error) message when there is no scraper for particular mime type
2781
+ *
2782
+ * @private internal function of `createScrapersFromConfiguration` and `createScrapersFromEnv`
2783
+ */
2784
+ function $registeredScrapersMessage(availableScrapers) {
2785
+ var e_1, _a, e_2, _b, e_3, _c;
2786
+ /**
2787
+ * Mixes registered scrapers from $scrapersMetadataRegister and $scrapersRegister
2788
+ */
2789
+ var all = [];
2790
+ var _loop_1 = function (packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser) {
2791
+ if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
2792
+ return "continue";
2793
+ }
2794
+ all.push({ packageName: packageName, className: className, mimeTypes: mimeTypes, documentationUrl: documentationUrl, isAvilableInBrowser: isAvilableInBrowser });
2795
+ };
2796
+ try {
2797
+ for (var _d = __values($scrapersMetadataRegister.list()), _e = _d.next(); !_e.done; _e = _d.next()) {
2798
+ var _f = _e.value, packageName = _f.packageName, className = _f.className, mimeTypes = _f.mimeTypes, documentationUrl = _f.documentationUrl, isAvilableInBrowser = _f.isAvilableInBrowser;
2799
+ _loop_1(packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser);
2800
+ }
2801
+ }
2802
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2803
+ finally {
2804
+ try {
2805
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
2806
+ }
2807
+ finally { if (e_1) throw e_1.error; }
2808
+ }
2809
+ var _loop_2 = function (packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser) {
2810
+ if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
2811
+ return "continue";
2812
+ }
2813
+ all.push({ packageName: packageName, className: className, mimeTypes: mimeTypes, documentationUrl: documentationUrl, isAvilableInBrowser: isAvilableInBrowser });
2814
+ };
2815
+ try {
2816
+ for (var _g = __values($scrapersRegister.list()), _h = _g.next(); !_h.done; _h = _g.next()) {
2817
+ var _j = _h.value, packageName = _j.packageName, className = _j.className, mimeTypes = _j.mimeTypes, documentationUrl = _j.documentationUrl, isAvilableInBrowser = _j.isAvilableInBrowser;
2818
+ _loop_2(packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser);
2819
+ }
2820
+ }
2821
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2822
+ finally {
2823
+ try {
2824
+ if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
2825
+ }
2826
+ finally { if (e_2) throw e_2.error; }
2827
+ }
2828
+ try {
2829
+ for (var availableScrapers_1 = __values(availableScrapers), availableScrapers_1_1 = availableScrapers_1.next(); !availableScrapers_1_1.done; availableScrapers_1_1 = availableScrapers_1.next()) {
2830
+ var metadata_1 = availableScrapers_1_1.value.metadata;
2831
+ all.push(metadata_1);
2832
+ }
2833
+ }
2834
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
2835
+ finally {
2836
+ try {
2837
+ if (availableScrapers_1_1 && !availableScrapers_1_1.done && (_c = availableScrapers_1.return)) _c.call(availableScrapers_1);
2838
+ }
2839
+ finally { if (e_3) throw e_3.error; }
2840
+ }
2841
+ var metadata = all.map(function (metadata) {
2842
+ var isMetadataAviailable = $scrapersMetadataRegister
2843
+ .list()
2844
+ .find(function (_a) {
2845
+ var packageName = _a.packageName, className = _a.className;
2846
+ return metadata.packageName === packageName && metadata.className === className;
2847
+ });
2848
+ var isInstalled = $scrapersRegister
2849
+ .list()
2850
+ .find(function (_a) {
2851
+ var packageName = _a.packageName, className = _a.className;
2852
+ return metadata.packageName === packageName && metadata.className === className;
2853
+ });
2854
+ var isAvilableInTools = availableScrapers.some(function (_a) {
2855
+ var _b = _a.metadata, packageName = _b.packageName, className = _b.className;
2856
+ return metadata.packageName === packageName && metadata.className === className;
2857
+ });
2858
+ return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled, isAvilableInTools: isAvilableInTools });
2859
+ });
2860
+ if (metadata.length === 0) {
2861
+ return spaceTrim("\n **No scrapers are available**\n\n This is a unexpected behavior, you are probably using some broken version of Promptbook\n At least there should be available the metadata of the scrapers\n ");
2862
+ }
2863
+ return spaceTrim(function (block) { return "\n Available scrapers are:\n ".concat(block(metadata
2864
+ .map(function (_a, i) {
2865
+ var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled, mimeTypes = _a.mimeTypes, isAvilableInBrowser = _a.isAvilableInBrowser, isAvilableInTools = _a.isAvilableInTools;
2866
+ var more = [];
2867
+ // TODO: [🧠] Maybe use `documentationUrl`
2868
+ if (isMetadataAviailable) {
2869
+ more.push("\u2B1C Metadata registered");
2870
+ } // not else
2871
+ if (isInstalled) {
2872
+ more.push("\uD83D\uDFE9 Installed");
2873
+ } // not else
2874
+ if (isAvilableInTools) {
2875
+ more.push("\uD83D\uDFE6 Available in tools");
2876
+ } // not else
2877
+ if (!isMetadataAviailable && isInstalled) {
2878
+ more.push("When no metadata registered but scraper is installed, it is an unexpected behavior");
2879
+ } // not else
2880
+ if (!isInstalled && isAvilableInTools) {
2881
+ more.push("When the scraper is not installed but available in tools, it is an unexpected compatibility behavior");
2882
+ } // not else
2883
+ if (!isAvilableInBrowser) {
2884
+ more.push("Not usable in browser");
2885
+ }
2886
+ var moreText = more.length === 0 ? '' : " *(".concat(more.join('; '), ")*");
2887
+ return "".concat(i + 1, ") `").concat(className, "` from `").concat(packageName, "` compatible to scrape ").concat(mimeTypes
2888
+ .map(function (mimeType) { return "\"".concat(mimeType, "\""); })
2889
+ .join(', ')).concat(moreText);
2890
+ })
2891
+ .join('\n')), "\n\n Legend:\n - \u2B1C **Metadata registered** means that Promptbook knows about the scraper, it is similar to registration in some registry\n - \uD83D\uDFE9 **Installed** means that you have imported package with particular scraper\n - \uD83D\uDFE6 **Available in tools** means that you have passed scraper as dependency into prepare or execution process\n\n "); });
2892
+ }
2893
+ /**
2894
+ * TODO: [®] DRY Register logic
2895
+ */
2896
+
2897
+ var defaultDiacriticsRemovalMap = [
2898
+ {
2899
+ base: 'A',
2900
+ 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',
2901
+ },
2902
+ { base: 'AA', letters: '\uA732' },
2903
+ { base: 'AE', letters: '\u00C6\u01FC\u01E2' },
2904
+ { base: 'AO', letters: '\uA734' },
2905
+ { base: 'AU', letters: '\uA736' },
2906
+ { base: 'AV', letters: '\uA738\uA73A' },
2907
+ { base: 'AY', letters: '\uA73C' },
2908
+ {
2909
+ base: 'B',
2910
+ letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
2911
+ },
2912
+ {
2913
+ base: 'C',
2914
+ letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
2915
+ },
2916
+ {
2917
+ base: 'D',
2918
+ letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
2919
+ },
2920
+ { base: 'DZ', letters: '\u01F1\u01C4' },
2921
+ { base: 'Dz', letters: '\u01F2\u01C5' },
2922
+ {
2923
+ base: 'E',
2924
+ letters: '\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E',
2925
+ },
2926
+ { base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
2927
+ {
2928
+ base: 'G',
2929
+ letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
2930
+ },
2931
+ {
2932
+ base: 'H',
2933
+ letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
2934
+ },
2935
+ {
2936
+ base: 'I',
2937
+ letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
2938
+ },
2939
+ { base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
2940
+ {
2941
+ base: 'K',
2942
+ letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
2943
+ },
2944
+ {
2945
+ base: 'L',
2946
+ letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
2947
+ },
2948
+ { base: 'LJ', letters: '\u01C7' },
2949
+ { base: 'Lj', letters: '\u01C8' },
2950
+ { base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
2951
+ {
2952
+ base: 'N',
2953
+ letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
2954
+ },
2955
+ { base: 'NJ', letters: '\u01CA' },
2956
+ { base: 'Nj', letters: '\u01CB' },
2957
+ {
2958
+ base: 'O',
2959
+ letters: '\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C',
2960
+ },
2961
+ { base: 'OI', letters: '\u01A2' },
2962
+ { base: 'OO', letters: '\uA74E' },
2963
+ { base: 'OU', letters: '\u0222' },
2964
+ { base: 'OE', letters: '\u008C\u0152' },
2965
+ { base: 'oe', letters: '\u009C\u0153' },
2966
+ {
2967
+ base: 'P',
2968
+ letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
2969
+ },
2970
+ { base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
2971
+ {
2972
+ base: 'R',
2973
+ letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
2974
+ },
2975
+ {
2976
+ base: 'S',
2977
+ letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
2978
+ },
2979
+ {
2980
+ base: 'T',
2981
+ letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
2982
+ },
2983
+ { base: 'TZ', letters: '\uA728' },
2984
+ {
2985
+ base: 'U',
2986
+ letters: '\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244',
2987
+ },
2988
+ { base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
2989
+ { base: 'VY', letters: '\uA760' },
2990
+ {
2991
+ base: 'W',
2992
+ letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
2993
+ },
2994
+ { base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
2995
+ {
2996
+ base: 'Y',
2997
+ letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
2998
+ },
2999
+ {
3000
+ base: 'Z',
3001
+ letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
3002
+ },
3003
+ {
3004
+ base: 'a',
3005
+ letters: '\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250',
3006
+ },
3007
+ { base: 'aa', letters: '\uA733' },
3008
+ { base: 'ae', letters: '\u00E6\u01FD\u01E3' },
3009
+ { base: 'ao', letters: '\uA735' },
3010
+ { base: 'au', letters: '\uA737' },
3011
+ { base: 'av', letters: '\uA739\uA73B' },
3012
+ { base: 'ay', letters: '\uA73D' },
3013
+ {
3014
+ base: 'b',
3015
+ letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
3016
+ },
3017
+ {
3018
+ base: 'c',
3019
+ letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
3020
+ },
3021
+ {
3022
+ base: 'd',
3023
+ letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
3024
+ },
3025
+ { base: 'dz', letters: '\u01F3\u01C6' },
3026
+ {
3027
+ base: 'e',
3028
+ letters: '\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD',
3029
+ },
3030
+ { base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
3031
+ {
3032
+ base: 'g',
3033
+ letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
3034
+ },
3035
+ {
3036
+ base: 'h',
3037
+ letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
3038
+ },
3039
+ { base: 'hv', letters: '\u0195' },
3040
+ {
3041
+ base: 'i',
3042
+ letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
3043
+ },
3044
+ { base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
3045
+ {
3046
+ base: 'k',
3047
+ letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
3048
+ },
3049
+ {
3050
+ base: 'l',
3051
+ letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
3052
+ },
3053
+ { base: 'lj', letters: '\u01C9' },
3054
+ { base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
3055
+ {
3056
+ base: 'n',
3057
+ letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
3058
+ },
3059
+ { base: 'nj', letters: '\u01CC' },
3060
+ {
3061
+ base: 'o',
3062
+ letters: '\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275',
3063
+ },
3064
+ { base: 'oi', letters: '\u01A3' },
3065
+ { base: 'ou', letters: '\u0223' },
3066
+ { base: 'oo', letters: '\uA74F' },
3067
+ {
3068
+ base: 'p',
3069
+ letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
3070
+ },
3071
+ { base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
3072
+ {
3073
+ base: 'r',
3074
+ letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
3075
+ },
3076
+ {
3077
+ base: 's',
3078
+ letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
3079
+ },
3080
+ {
3081
+ base: 't',
3082
+ letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
3083
+ },
3084
+ { base: 'tz', letters: '\uA729' },
3085
+ {
3086
+ base: 'u',
3087
+ letters: '\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289',
3088
+ },
3089
+ { base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
3090
+ { base: 'vy', letters: '\uA761' },
3091
+ {
3092
+ base: 'w',
3093
+ letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
3094
+ },
3095
+ { base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
3096
+ {
3097
+ base: 'y',
3098
+ letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
3099
+ },
3100
+ {
3101
+ base: 'z',
3102
+ letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
3103
+ },
3104
+ ];
3105
+ /**
3106
+ * Map of letters from diacritic variant to diacritless variant
3107
+ * Contains lowercase and uppercase separatelly
3108
+ *
3109
+ * > "á" => "a"
3110
+ * > "ě" => "e"
3111
+ * > "Ă" => "A"
3112
+ * > ...
3113
+ *
3114
+ * @public exported from `@promptbook/utils`
3115
+ */
3116
+ var DIACRITIC_VARIANTS_LETTERS = {};
3117
+ // tslint:disable-next-line: prefer-for-of
3118
+ for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
3119
+ var letters = defaultDiacriticsRemovalMap[i].letters;
3120
+ // tslint:disable-next-line: prefer-for-of
3121
+ for (var j = 0; j < letters.length; j++) {
3122
+ DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
3123
+ }
3124
+ }
3125
+ // <- TODO: [🍓] Put to maker function to save execution time if not needed
3126
+ /*
3127
+ @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
3128
+ Licensed under the Apache License, Version 2.0 (the "License");
3129
+ you may not use this file except in compliance with the License.
3130
+ You may obtain a copy of the License at
3131
+
3132
+ http://www.apache.org/licenses/LICENSE-2.0
3133
+
3134
+ Unless required by applicable law or agreed to in writing, software
3135
+ distributed under the License is distributed on an "AS IS" BASIS,
3136
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3137
+ See the License for the specific language governing permissions and
3138
+ limitations under the License.
3139
+ */
3114
3140
 
3115
3141
  /**
3116
3142
  * @@@
3117
3143
  *
3118
- * Note: `$` is used to indicate that this interacts with the global scope
3119
- * @singleton Only one instance of each register is created per build, but thare can be more @@@
3120
- * @public exported from `@promptbook/core`
3144
+ * @param input @@@
3145
+ * @returns @@@
3146
+ * @public exported from `@promptbook/utils`
3121
3147
  */
3122
- var $scrapersRegister = new $Register('scraper_constructors');
3148
+ function removeDiacritics(input) {
3149
+ /*eslint no-control-regex: "off"*/
3150
+ return input.replace(/[^\u0000-\u007E]/g, function (a) {
3151
+ return DIACRITIC_VARIANTS_LETTERS[a] || a;
3152
+ });
3153
+ }
3123
3154
  /**
3124
- * TODO: [®] DRY Register logic
3155
+ * TODO: [Ж] Variant for cyrillic (and in general non-latin) letters
3125
3156
  */
3126
3157
 
3127
3158
  /**
3128
- * Creates a message with all registered scrapers
3129
- *
3130
- * Note: This function is used to create a (error) message when there is no scraper for particular mime type
3159
+ * @@@
3131
3160
  *
3132
- * @private internal function of `createScrapersFromConfiguration` and `createScrapersFromEnv`
3161
+ * @param text @@@
3162
+ * @returns @@@
3163
+ * @example 'hello-world'
3164
+ * @example 'i-love-promptbook'
3165
+ * @public exported from `@promptbook/utils`
3133
3166
  */
3134
- function $registeredScrapersMessage(availableScrapers) {
3135
- var e_1, _a, e_2, _b, e_3, _c;
3136
- /**
3137
- * Mixes registered scrapers from $scrapersMetadataRegister and $scrapersRegister
3138
- */
3139
- var all = [];
3140
- var _loop_1 = function (packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser) {
3141
- if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
3142
- return "continue";
3143
- }
3144
- all.push({ packageName: packageName, className: className, mimeTypes: mimeTypes, documentationUrl: documentationUrl, isAvilableInBrowser: isAvilableInBrowser });
3145
- };
3167
+ function normalizeToKebabCase(text) {
3168
+ var e_1, _a;
3169
+ text = removeDiacritics(text);
3170
+ var charType;
3171
+ var lastCharType = 'OTHER';
3172
+ var normalizedName = '';
3146
3173
  try {
3147
- for (var _d = __values($scrapersMetadataRegister.list()), _e = _d.next(); !_e.done; _e = _d.next()) {
3148
- var _f = _e.value, packageName = _f.packageName, className = _f.className, mimeTypes = _f.mimeTypes, documentationUrl = _f.documentationUrl, isAvilableInBrowser = _f.isAvilableInBrowser;
3149
- _loop_1(packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser);
3174
+ for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
3175
+ var char = text_1_1.value;
3176
+ var normalizedChar = void 0;
3177
+ if (/^[a-z]$/.test(char)) {
3178
+ charType = 'LOWERCASE';
3179
+ normalizedChar = char;
3180
+ }
3181
+ else if (/^[A-Z]$/.test(char)) {
3182
+ charType = 'UPPERCASE';
3183
+ normalizedChar = char.toLowerCase();
3184
+ }
3185
+ else if (/^[0-9]$/.test(char)) {
3186
+ charType = 'NUMBER';
3187
+ normalizedChar = char;
3188
+ }
3189
+ else {
3190
+ charType = 'OTHER';
3191
+ normalizedChar = '-';
3192
+ }
3193
+ if (charType !== lastCharType &&
3194
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
3195
+ !(lastCharType === 'NUMBER') &&
3196
+ !(charType === 'NUMBER')) {
3197
+ normalizedName += '-';
3198
+ }
3199
+ normalizedName += normalizedChar;
3200
+ lastCharType = charType;
3150
3201
  }
3151
3202
  }
3152
3203
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
3153
3204
  finally {
3154
3205
  try {
3155
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
3206
+ if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
3156
3207
  }
3157
3208
  finally { if (e_1) throw e_1.error; }
3158
3209
  }
3159
- var _loop_2 = function (packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser) {
3160
- if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
3161
- return "continue";
3162
- }
3163
- all.push({ packageName: packageName, className: className, mimeTypes: mimeTypes, documentationUrl: documentationUrl, isAvilableInBrowser: isAvilableInBrowser });
3164
- };
3165
- try {
3166
- for (var _g = __values($scrapersRegister.list()), _h = _g.next(); !_h.done; _h = _g.next()) {
3167
- var _j = _h.value, packageName = _j.packageName, className = _j.className, mimeTypes = _j.mimeTypes, documentationUrl = _j.documentationUrl, isAvilableInBrowser = _j.isAvilableInBrowser;
3168
- _loop_2(packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser);
3169
- }
3170
- }
3171
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
3172
- finally {
3173
- try {
3174
- if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
3175
- }
3176
- finally { if (e_2) throw e_2.error; }
3177
- }
3178
- try {
3179
- for (var availableScrapers_1 = __values(availableScrapers), availableScrapers_1_1 = availableScrapers_1.next(); !availableScrapers_1_1.done; availableScrapers_1_1 = availableScrapers_1.next()) {
3180
- var metadata_1 = availableScrapers_1_1.value.metadata;
3181
- all.push(metadata_1);
3182
- }
3183
- }
3184
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
3185
- finally {
3186
- try {
3187
- if (availableScrapers_1_1 && !availableScrapers_1_1.done && (_c = availableScrapers_1.return)) _c.call(availableScrapers_1);
3188
- }
3189
- finally { if (e_3) throw e_3.error; }
3190
- }
3191
- var metadata = all.map(function (metadata) {
3192
- var isMetadataAviailable = $scrapersMetadataRegister
3193
- .list()
3194
- .find(function (_a) {
3195
- var packageName = _a.packageName, className = _a.className;
3196
- return metadata.packageName === packageName && metadata.className === className;
3197
- });
3198
- var isInstalled = $scrapersRegister
3199
- .list()
3200
- .find(function (_a) {
3201
- var packageName = _a.packageName, className = _a.className;
3202
- return metadata.packageName === packageName && metadata.className === className;
3203
- });
3204
- var isAvilableInTools = availableScrapers.some(function (_a) {
3205
- var _b = _a.metadata, packageName = _b.packageName, className = _b.className;
3206
- return metadata.packageName === packageName && metadata.className === className;
3207
- });
3208
- return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled, isAvilableInTools: isAvilableInTools });
3209
- });
3210
- if (metadata.length === 0) {
3211
- return spaceTrim("\n **No scrapers are available**\n\n This is a unexpected behavior, you are probably using some broken version of Promptbook\n At least there should be available the metadata of the scrapers\n ");
3212
- }
3213
- return spaceTrim(function (block) { return "\n Available scrapers are:\n ".concat(block(metadata
3214
- .map(function (_a, i) {
3215
- var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled, mimeTypes = _a.mimeTypes, isAvilableInBrowser = _a.isAvilableInBrowser, isAvilableInTools = _a.isAvilableInTools;
3216
- var more = [];
3217
- // TODO: [🧠] Maybe use `documentationUrl`
3218
- if (isMetadataAviailable) {
3219
- more.push("\u2B1C Metadata registered");
3220
- } // not else
3221
- if (isInstalled) {
3222
- more.push("\uD83D\uDFE9 Installed");
3223
- } // not else
3224
- if (isAvilableInTools) {
3225
- more.push("\uD83D\uDFE6 Available in tools");
3226
- } // not else
3227
- if (!isMetadataAviailable && isInstalled) {
3228
- more.push("When no metadata registered but scraper is installed, it is an unexpected behavior");
3229
- } // not else
3230
- if (!isInstalled && isAvilableInTools) {
3231
- more.push("When the scraper is not installed but available in tools, it is an unexpected compatibility behavior");
3232
- } // not else
3233
- if (!isAvilableInBrowser) {
3234
- more.push("Not usable in browser");
3235
- }
3236
- var moreText = more.length === 0 ? '' : " *(".concat(more.join('; '), ")*");
3237
- return "".concat(i + 1, ") `").concat(className, "` from `").concat(packageName, "` compatible to scrape ").concat(mimeTypes
3238
- .map(function (mimeType) { return "\"".concat(mimeType, "\""); })
3239
- .join(', ')).concat(moreText);
3240
- })
3241
- .join('\n')), "\n\n Legend:\n - \u2B1C **Metadata registered** means that Promptbook knows about the scraper, it is similar to registration in some registry\n - \uD83D\uDFE9 **Installed** means that you have imported package with particular scraper\n - \uD83D\uDFE6 **Available in tools** means that you have passed scraper as dependency into prepare or execution process\n\n "); });
3210
+ normalizedName = normalizedName.split(/-+/g).join('-');
3211
+ normalizedName = normalizedName.split(/-?\/-?/g).join('/');
3212
+ normalizedName = normalizedName.replace(/^-/, '');
3213
+ normalizedName = normalizedName.replace(/-$/, '');
3214
+ return normalizedName;
3242
3215
  }
3243
3216
  /**
3244
- * TODO: [®] DRY Register logic
3217
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3245
3218
  */
3246
3219
 
3247
3220
  /**
@@ -3320,6 +3293,32 @@ function isFileExisting(filename, fs) {
3320
3293
  * TODO: [🖇] What about symlinks?
3321
3294
  */
3322
3295
 
3296
+ /**
3297
+ * Tests if given string is valid URL.
3298
+ *
3299
+ * Note: This does not check if the file exists only if the path is valid
3300
+ * @public exported from `@promptbook/utils`
3301
+ */
3302
+ function isValidFilePath(filename) {
3303
+ if (typeof filename !== 'string') {
3304
+ return false;
3305
+ }
3306
+ var filenameSlashes = filename.split('\\').join('/');
3307
+ // Absolute Unix path: /hello.txt
3308
+ if (/^(\/)/i.test(filenameSlashes)) {
3309
+ return true;
3310
+ }
3311
+ // Absolute Windows path: /hello.txt
3312
+ if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
3313
+ return true;
3314
+ }
3315
+ // Relative path: ./hello.txt
3316
+ if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
3317
+ return true;
3318
+ }
3319
+ return false;
3320
+ }
3321
+
3323
3322
  /**
3324
3323
  * @@@
3325
3324
  *
@@ -3781,10 +3780,11 @@ function preparePipeline(pipeline, tools, options) {
3781
3780
  * @param script from which to extract the variables
3782
3781
  * @returns the list of variable names
3783
3782
  * @throws {ParseError} if the script is invalid
3784
- * @public exported from `@promptbook/utils`
3783
+ * @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
3785
3784
  */
3786
- function extractVariables(script) {
3785
+ function extractVariablesFromScript(script) {
3787
3786
  var variables = new Set();
3787
+ var originalScript = script;
3788
3788
  script = "(()=>{".concat(script, "})()");
3789
3789
  try {
3790
3790
  for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
@@ -3816,7 +3816,9 @@ function extractVariables(script) {
3816
3816
  if (!(error instanceof Error)) {
3817
3817
  throw error;
3818
3818
  }
3819
- throw new ParseError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
3819
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n\n\n Found variables:\n\n ").concat(Array.from(variables)
3820
+ .map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
3821
+ .join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
3820
3822
  }
3821
3823
  return variables;
3822
3824
  }
@@ -3830,7 +3832,7 @@ function extractVariables(script) {
3830
3832
  * @param task the task with used parameters
3831
3833
  * @returns the set of parameter names
3832
3834
  * @throws {ParseError} if the script is invalid
3833
- * @public exported from `@promptbook/utils`
3835
+ * @public exported from `@promptbook/core` <- Note: [👖] This utility is so tightly interconnected with the Promptbook that it is not exported as util but in core
3834
3836
  */
3835
3837
  function extractParameterNamesFromTask(task) {
3836
3838
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
@@ -3851,7 +3853,7 @@ function extractParameterNamesFromTask(task) {
3851
3853
  }
3852
3854
  if (taskType === 'SCRIPT_TASK') {
3853
3855
  try {
3854
- for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
3856
+ for (var _g = __values(extractVariablesFromScript(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
3855
3857
  var parameterName = _h.value;
3856
3858
  parameterNames.add(parameterName);
3857
3859
  }
@@ -5623,6 +5625,46 @@ function createPipelineExecutor(options) {
5623
5625
  * TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
5624
5626
  */
5625
5627
 
5628
+ /**
5629
+ * Removes emojis from a string and fix whitespaces
5630
+ *
5631
+ * @param text with emojis
5632
+ * @returns text without emojis
5633
+ * @public exported from `@promptbook/utils`
5634
+ */
5635
+ function removeEmojis(text) {
5636
+ // Replace emojis (and also ZWJ sequence) with hyphens
5637
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
5638
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
5639
+ text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
5640
+ text = text.replace(/\p{Extended_Pictographic}/gu, '');
5641
+ return text;
5642
+ }
5643
+
5644
+ /**
5645
+ * @@@
5646
+ *
5647
+ * @param value @@@
5648
+ * @returns @@@
5649
+ * @example @@@
5650
+ * @public exported from `@promptbook/utils`
5651
+ */
5652
+ function titleToName(value) {
5653
+ if (isValidUrl(value)) {
5654
+ value = value.replace(/^https?:\/\//, '');
5655
+ value = value.replace(/\.html$/, '');
5656
+ }
5657
+ else if (isValidFilePath(value)) {
5658
+ value = basename(value);
5659
+ // Note: Keeping extension in the name
5660
+ }
5661
+ value = value.split('/').join('-');
5662
+ value = removeEmojis(value);
5663
+ value = normalizeToKebabCase(value);
5664
+ // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
5665
+ return value;
5666
+ }
5667
+
5626
5668
  /**
5627
5669
  * Metadata of the scraper
5628
5670
  *
@@ -5875,11 +5917,11 @@ function addAutoGeneratedSection(content, options) {
5875
5917
  var placeForSection = removeContentComments(content).match(/^##.*$/im);
5876
5918
  if (placeForSection !== null) {
5877
5919
  var _a = __read(placeForSection, 1), heading_1 = _a[0];
5878
- return content.replace(heading_1, spaceTrim$1(function (block) { return "\n ".concat(block(contentToInsert), "\n \n ").concat(block(heading_1), "\n "); }));
5920
+ return content.replace(heading_1, spaceTrim$1(function (block) { return "\n ".concat(block(contentToInsert), "\n\n ").concat(block(heading_1), "\n "); }));
5879
5921
  }
5880
5922
  console.warn("No place where to put the section <!--".concat(sectionName, "-->, using the end of the file"));
5881
- // <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
5882
- return spaceTrim$1(function (block) { return "\n ".concat(block(content), "\n \n ").concat(block(contentToInsert), "\n "); });
5923
+ // <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
5924
+ return spaceTrim$1(function (block) { return "\n ".concat(block(content), "\n\n ").concat(block(contentToInsert), "\n "); });
5883
5925
  }
5884
5926
  /**
5885
5927
  * TODO: [🏛] This can be part of markdown builder
@@ -6060,6 +6102,7 @@ function splitMarkdownIntoSections(markdown) {
6060
6102
  var e_1, _a;
6061
6103
  var lines = markdown.split('\n');
6062
6104
  var sections = [];
6105
+ // TODO: [🧽] DRY
6063
6106
  var currentType = 'MARKDOWN';
6064
6107
  var buffer = [];
6065
6108
  var finishSection = function () {