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