@promptbook/pdf 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.
- package/esm/index.es.js +837 -795
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +10 -0
- package/esm/typings/src/_packages/types.index.d.ts +4 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -8
- package/esm/typings/src/commands/_common/types/CommandType.d.ts +17 -0
- package/esm/typings/src/config.d.ts +14 -0
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTask.d.ts +1 -1
- package/esm/typings/src/conversion/utils/{extractVariables.d.ts → extractVariablesFromScript.d.ts} +2 -2
- package/esm/typings/src/conversion/utils/removePipelineCommand.d.ts +22 -0
- package/esm/typings/src/conversion/utils/{renameParameter.d.ts → renamePipelineParameter.d.ts} +3 -3
- package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +6 -0
- package/esm/typings/src/execution/execution-report/ExecutionReportString.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineString.d.ts +1 -1
- package/esm/typings/src/utils/normalization/titleToName.test.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +840 -798
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/conversion/utils/{extractVariables.test.d.ts → extractVariablesFromScript.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/utils/{renameParameter.test.d.ts → removePipelineCommand.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/utils/{titleToName.test.d.ts → renamePipelineParameter.test.d.ts} +0 -0
- /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('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-pdf"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.
|
|
5
|
-
})(this, (function (exports, spaceTrim, prettier, parserHtml,
|
|
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-pdf"] = {}, 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.
|
|
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
|
|
@@ -448,198 +448,25 @@
|
|
|
448
448
|
}
|
|
449
449
|
|
|
450
450
|
/**
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
454
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
451
|
+
* Name for the Promptbook
|
|
455
452
|
*
|
|
456
|
-
*
|
|
457
|
-
* @public exported from `@promptbook/utils`
|
|
458
|
-
*/
|
|
459
|
-
function $deepFreeze(objectValue) {
|
|
460
|
-
var e_1, _a;
|
|
461
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
462
|
-
try {
|
|
463
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
464
|
-
var propertyName = propertyNames_1_1.value;
|
|
465
|
-
var value = objectValue[propertyName];
|
|
466
|
-
if (value && typeof value === 'object') {
|
|
467
|
-
$deepFreeze(value);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
472
|
-
finally {
|
|
473
|
-
try {
|
|
474
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
475
|
-
}
|
|
476
|
-
finally { if (e_1) throw e_1.error; }
|
|
477
|
-
}
|
|
478
|
-
return Object.freeze(objectValue);
|
|
479
|
-
}
|
|
480
|
-
/**
|
|
481
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
482
|
-
*/
|
|
483
|
-
|
|
484
|
-
/**
|
|
485
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
453
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
486
454
|
*
|
|
487
455
|
* @public exported from `@promptbook/core`
|
|
488
456
|
*/
|
|
489
|
-
var
|
|
490
|
-
__extends(UnexpectedError, _super);
|
|
491
|
-
function UnexpectedError(message) {
|
|
492
|
-
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;
|
|
493
|
-
_this.name = 'UnexpectedError';
|
|
494
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
495
|
-
return _this;
|
|
496
|
-
}
|
|
497
|
-
return UnexpectedError;
|
|
498
|
-
}(Error));
|
|
499
|
-
|
|
457
|
+
var NAME = "Promptbook";
|
|
500
458
|
/**
|
|
501
|
-
*
|
|
502
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
503
|
-
*
|
|
504
|
-
* - Almost all primitives are serializable BUT:
|
|
505
|
-
* - `undefined` is not serializable
|
|
506
|
-
* - `NaN` is not serializable
|
|
507
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
508
|
-
* - Functions are not serializable
|
|
509
|
-
* - Circular references are not serializable
|
|
510
|
-
* - `Date` objects are not serializable
|
|
511
|
-
* - `Map` and `Set` objects are not serializable
|
|
512
|
-
* - `RegExp` objects are not serializable
|
|
513
|
-
* - `Error` objects are not serializable
|
|
514
|
-
* - `Symbol` objects are not serializable
|
|
515
|
-
* - And much more...
|
|
459
|
+
* Email of the responsible person
|
|
516
460
|
*
|
|
517
|
-
* @
|
|
518
|
-
* @public exported from `@promptbook/utils`
|
|
519
|
-
*/
|
|
520
|
-
function checkSerializableAsJson(name, value) {
|
|
521
|
-
var e_1, _a;
|
|
522
|
-
if (value === undefined) {
|
|
523
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
524
|
-
}
|
|
525
|
-
else if (value === null) {
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
else if (typeof value === 'boolean') {
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
else if (typeof value === 'string') {
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
else if (typeof value === 'symbol') {
|
|
538
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
539
|
-
}
|
|
540
|
-
else if (typeof value === 'function') {
|
|
541
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
542
|
-
}
|
|
543
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
544
|
-
for (var i = 0; i < value.length; i++) {
|
|
545
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
else if (typeof value === 'object') {
|
|
549
|
-
if (value instanceof Date) {
|
|
550
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
551
|
-
}
|
|
552
|
-
else if (value instanceof Map) {
|
|
553
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
554
|
-
}
|
|
555
|
-
else if (value instanceof Set) {
|
|
556
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
557
|
-
}
|
|
558
|
-
else if (value instanceof RegExp) {
|
|
559
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
560
|
-
}
|
|
561
|
-
else if (value instanceof Error) {
|
|
562
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
563
|
-
}
|
|
564
|
-
else {
|
|
565
|
-
try {
|
|
566
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
567
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
568
|
-
if (subValue === undefined) {
|
|
569
|
-
// Note: undefined in object is serializable - it is just omited
|
|
570
|
-
continue;
|
|
571
|
-
}
|
|
572
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
576
|
-
finally {
|
|
577
|
-
try {
|
|
578
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
579
|
-
}
|
|
580
|
-
finally { if (e_1) throw e_1.error; }
|
|
581
|
-
}
|
|
582
|
-
try {
|
|
583
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
584
|
-
}
|
|
585
|
-
catch (error) {
|
|
586
|
-
if (!(error instanceof Error)) {
|
|
587
|
-
throw error;
|
|
588
|
-
}
|
|
589
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
590
|
-
}
|
|
591
|
-
/*
|
|
592
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
593
|
-
const seen = new Set();
|
|
594
|
-
const stack = [{ value }];
|
|
595
|
-
while (stack.length > 0) {
|
|
596
|
-
const { value } = stack.pop()!;
|
|
597
|
-
if (typeof value === 'object' && value !== null) {
|
|
598
|
-
if (seen.has(value)) {
|
|
599
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
600
|
-
}
|
|
601
|
-
seen.add(value);
|
|
602
|
-
if (Array.isArray(value)) {
|
|
603
|
-
stack.push(...value.map((value) => ({ value })));
|
|
604
|
-
} else {
|
|
605
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
*/
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
else {
|
|
614
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
619
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
620
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
461
|
+
* @public exported from `@promptbook/core`
|
|
621
462
|
*/
|
|
622
|
-
|
|
463
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
623
464
|
/**
|
|
624
|
-
*
|
|
625
|
-
* @@@
|
|
626
|
-
*
|
|
627
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
465
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
628
466
|
*
|
|
629
|
-
* @
|
|
630
|
-
* @param objectValue - Object to be deeply frozen
|
|
631
|
-
* @returns The same object as the input, but deeply frozen
|
|
632
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
633
|
-
*/
|
|
634
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
635
|
-
checkSerializableAsJson(name, objectValue);
|
|
636
|
-
return $deepFreeze(objectValue);
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
640
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
467
|
+
* @public exported from `@promptbook/core`
|
|
641
468
|
*/
|
|
642
|
-
|
|
469
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
643
470
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
644
471
|
/**
|
|
645
472
|
* The maximum number of iterations for a loops
|
|
@@ -691,7 +518,8 @@
|
|
|
691
518
|
*
|
|
692
519
|
* @public exported from `@promptbook/core`
|
|
693
520
|
*/
|
|
694
|
-
var RESERVED_PARAMETER_NAMES =
|
|
521
|
+
var RESERVED_PARAMETER_NAMES =
|
|
522
|
+
/* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
|
|
695
523
|
'content',
|
|
696
524
|
'context',
|
|
697
525
|
'knowledge',
|
|
@@ -701,7 +529,7 @@
|
|
|
701
529
|
// <- TODO: list here all command names
|
|
702
530
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
703
531
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
704
|
-
]
|
|
532
|
+
];
|
|
705
533
|
/**
|
|
706
534
|
* @@@
|
|
707
535
|
*
|
|
@@ -788,6 +616,40 @@
|
|
|
788
616
|
return PipelineLogicError;
|
|
789
617
|
}(Error));
|
|
790
618
|
|
|
619
|
+
/**
|
|
620
|
+
* Make error report URL for the given error
|
|
621
|
+
*
|
|
622
|
+
* @private !!!!!!
|
|
623
|
+
*/
|
|
624
|
+
function getErrorReportUrl(error) {
|
|
625
|
+
var report = {
|
|
626
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
627
|
+
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 "); }),
|
|
628
|
+
};
|
|
629
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
630
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
631
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
632
|
+
reportUrl.searchParams.set('title', report.title);
|
|
633
|
+
reportUrl.searchParams.set('body', report.body);
|
|
634
|
+
return reportUrl;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
639
|
+
*
|
|
640
|
+
* @public exported from `@promptbook/core`
|
|
641
|
+
*/
|
|
642
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
643
|
+
__extends(UnexpectedError, _super);
|
|
644
|
+
function UnexpectedError(message) {
|
|
645
|
+
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;
|
|
646
|
+
_this.name = 'UnexpectedError';
|
|
647
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
648
|
+
return _this;
|
|
649
|
+
}
|
|
650
|
+
return UnexpectedError;
|
|
651
|
+
}(Error));
|
|
652
|
+
|
|
791
653
|
/**
|
|
792
654
|
* Tests if given string is valid semantic version
|
|
793
655
|
*
|
|
@@ -1269,36 +1131,213 @@
|
|
|
1269
1131
|
}
|
|
1270
1132
|
|
|
1271
1133
|
/**
|
|
1272
|
-
*
|
|
1134
|
+
* @@@
|
|
1273
1135
|
*
|
|
1274
|
-
*
|
|
1136
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
1137
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1138
|
+
*
|
|
1139
|
+
* @returns The same object as the input, but deeply frozen
|
|
1140
|
+
* @public exported from `@promptbook/utils`
|
|
1275
1141
|
*/
|
|
1276
|
-
function
|
|
1277
|
-
var
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1142
|
+
function $deepFreeze(objectValue) {
|
|
1143
|
+
var e_1, _a;
|
|
1144
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1145
|
+
try {
|
|
1146
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
1147
|
+
var propertyName = propertyNames_1_1.value;
|
|
1148
|
+
var value = objectValue[propertyName];
|
|
1149
|
+
if (value && typeof value === 'object') {
|
|
1150
|
+
$deepFreeze(value);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1155
|
+
finally {
|
|
1156
|
+
try {
|
|
1157
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
1158
|
+
}
|
|
1159
|
+
finally { if (e_1) throw e_1.error; }
|
|
1160
|
+
}
|
|
1161
|
+
return Object.freeze(objectValue);
|
|
1289
1162
|
}
|
|
1290
1163
|
/**
|
|
1291
|
-
* TODO: [
|
|
1292
|
-
* TODO: Write tests for `preparePipeline`
|
|
1293
|
-
* TODO: [🍙] Make some standard order of json properties
|
|
1164
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1294
1165
|
*/
|
|
1295
1166
|
|
|
1296
1167
|
/**
|
|
1297
|
-
*
|
|
1298
|
-
*
|
|
1168
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
1169
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
1299
1170
|
*
|
|
1300
|
-
*
|
|
1301
|
-
*
|
|
1171
|
+
* - Almost all primitives are serializable BUT:
|
|
1172
|
+
* - `undefined` is not serializable
|
|
1173
|
+
* - `NaN` is not serializable
|
|
1174
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
1175
|
+
* - Functions are not serializable
|
|
1176
|
+
* - Circular references are not serializable
|
|
1177
|
+
* - `Date` objects are not serializable
|
|
1178
|
+
* - `Map` and `Set` objects are not serializable
|
|
1179
|
+
* - `RegExp` objects are not serializable
|
|
1180
|
+
* - `Error` objects are not serializable
|
|
1181
|
+
* - `Symbol` objects are not serializable
|
|
1182
|
+
* - And much more...
|
|
1183
|
+
*
|
|
1184
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
1185
|
+
* @public exported from `@promptbook/utils`
|
|
1186
|
+
*/
|
|
1187
|
+
function checkSerializableAsJson(name, value) {
|
|
1188
|
+
var e_1, _a;
|
|
1189
|
+
if (value === undefined) {
|
|
1190
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
1191
|
+
}
|
|
1192
|
+
else if (value === null) {
|
|
1193
|
+
return;
|
|
1194
|
+
}
|
|
1195
|
+
else if (typeof value === 'boolean') {
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1198
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
1199
|
+
return;
|
|
1200
|
+
}
|
|
1201
|
+
else if (typeof value === 'string') {
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
1204
|
+
else if (typeof value === 'symbol') {
|
|
1205
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
1206
|
+
}
|
|
1207
|
+
else if (typeof value === 'function') {
|
|
1208
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
1209
|
+
}
|
|
1210
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
1211
|
+
for (var i = 0; i < value.length; i++) {
|
|
1212
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
else if (typeof value === 'object') {
|
|
1216
|
+
if (value instanceof Date) {
|
|
1217
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
1218
|
+
}
|
|
1219
|
+
else if (value instanceof Map) {
|
|
1220
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
1221
|
+
}
|
|
1222
|
+
else if (value instanceof Set) {
|
|
1223
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
1224
|
+
}
|
|
1225
|
+
else if (value instanceof RegExp) {
|
|
1226
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
1227
|
+
}
|
|
1228
|
+
else if (value instanceof Error) {
|
|
1229
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
1230
|
+
}
|
|
1231
|
+
else {
|
|
1232
|
+
try {
|
|
1233
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1234
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
1235
|
+
if (subValue === undefined) {
|
|
1236
|
+
// Note: undefined in object is serializable - it is just omited
|
|
1237
|
+
continue;
|
|
1238
|
+
}
|
|
1239
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1243
|
+
finally {
|
|
1244
|
+
try {
|
|
1245
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1246
|
+
}
|
|
1247
|
+
finally { if (e_1) throw e_1.error; }
|
|
1248
|
+
}
|
|
1249
|
+
try {
|
|
1250
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
1251
|
+
}
|
|
1252
|
+
catch (error) {
|
|
1253
|
+
if (!(error instanceof Error)) {
|
|
1254
|
+
throw error;
|
|
1255
|
+
}
|
|
1256
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
1257
|
+
}
|
|
1258
|
+
/*
|
|
1259
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
1260
|
+
const seen = new Set();
|
|
1261
|
+
const stack = [{ value }];
|
|
1262
|
+
while (stack.length > 0) {
|
|
1263
|
+
const { value } = stack.pop()!;
|
|
1264
|
+
if (typeof value === 'object' && value !== null) {
|
|
1265
|
+
if (seen.has(value)) {
|
|
1266
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
1267
|
+
}
|
|
1268
|
+
seen.add(value);
|
|
1269
|
+
if (Array.isArray(value)) {
|
|
1270
|
+
stack.push(...value.map((value) => ({ value })));
|
|
1271
|
+
} else {
|
|
1272
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
*/
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
else {
|
|
1281
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1286
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
1287
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
1288
|
+
*/
|
|
1289
|
+
|
|
1290
|
+
/**
|
|
1291
|
+
* @@@
|
|
1292
|
+
* @@@
|
|
1293
|
+
*
|
|
1294
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1295
|
+
*
|
|
1296
|
+
* @param name - Name of the object for debugging purposes
|
|
1297
|
+
* @param objectValue - Object to be deeply frozen
|
|
1298
|
+
* @returns The same object as the input, but deeply frozen
|
|
1299
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
1300
|
+
*/
|
|
1301
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
1302
|
+
checkSerializableAsJson(name, objectValue);
|
|
1303
|
+
return $deepFreeze(objectValue);
|
|
1304
|
+
}
|
|
1305
|
+
/**
|
|
1306
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1307
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1308
|
+
*/
|
|
1309
|
+
|
|
1310
|
+
/**
|
|
1311
|
+
* Unprepare just strips the preparation data of the pipeline
|
|
1312
|
+
*
|
|
1313
|
+
* @public exported from `@promptbook/core`
|
|
1314
|
+
*/
|
|
1315
|
+
function unpreparePipeline(pipeline) {
|
|
1316
|
+
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, tasks = pipeline.tasks;
|
|
1317
|
+
personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
|
|
1318
|
+
knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
|
|
1319
|
+
tasks = tasks.map(function (task) {
|
|
1320
|
+
var dependentParameterNames = task.dependentParameterNames;
|
|
1321
|
+
var parameterNames = extractParameterNames(task.preparedContent || '');
|
|
1322
|
+
dependentParameterNames = dependentParameterNames.filter(function (dependentParameterName) { return !parameterNames.has(dependentParameterName); });
|
|
1323
|
+
var taskUnprepared = __assign(__assign({}, task), { dependentParameterNames: dependentParameterNames });
|
|
1324
|
+
delete taskUnprepared.preparedContent;
|
|
1325
|
+
return taskUnprepared;
|
|
1326
|
+
});
|
|
1327
|
+
return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { tasks: tasks, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
|
|
1328
|
+
}
|
|
1329
|
+
/**
|
|
1330
|
+
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
1331
|
+
* TODO: Write tests for `preparePipeline`
|
|
1332
|
+
* TODO: [🍙] Make some standard order of json properties
|
|
1333
|
+
*/
|
|
1334
|
+
|
|
1335
|
+
/**
|
|
1336
|
+
* Library of pipelines that groups together pipelines for an application.
|
|
1337
|
+
* This implementation is a very thin wrapper around the Array / Map of pipelines.
|
|
1338
|
+
*
|
|
1339
|
+
* @private internal function of `createCollectionFromJson`, use `createCollectionFromJson` instead
|
|
1340
|
+
* @see https://github.com/webgptorg/pipeline#pipeline-collection
|
|
1302
1341
|
*/
|
|
1303
1342
|
var SimplePipelineCollection = /** @class */ (function () {
|
|
1304
1343
|
/**
|
|
@@ -1398,483 +1437,94 @@
|
|
|
1398
1437
|
return new (SimplePipelineCollection.bind.apply(SimplePipelineCollection, __spreadArray([void 0], __read(promptbooks), false)))();
|
|
1399
1438
|
}
|
|
1400
1439
|
|
|
1401
|
-
var defaultDiacriticsRemovalMap = [
|
|
1402
|
-
{
|
|
1403
|
-
base: 'A',
|
|
1404
|
-
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',
|
|
1405
|
-
},
|
|
1406
|
-
{ base: 'AA', letters: '\uA732' },
|
|
1407
|
-
{ base: 'AE', letters: '\u00C6\u01FC\u01E2' },
|
|
1408
|
-
{ base: 'AO', letters: '\uA734' },
|
|
1409
|
-
{ base: 'AU', letters: '\uA736' },
|
|
1410
|
-
{ base: 'AV', letters: '\uA738\uA73A' },
|
|
1411
|
-
{ base: 'AY', letters: '\uA73C' },
|
|
1412
|
-
{
|
|
1413
|
-
base: 'B',
|
|
1414
|
-
letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
|
|
1415
|
-
},
|
|
1416
|
-
{
|
|
1417
|
-
base: 'C',
|
|
1418
|
-
letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
|
|
1419
|
-
},
|
|
1420
|
-
{
|
|
1421
|
-
base: 'D',
|
|
1422
|
-
letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
|
|
1423
|
-
},
|
|
1424
|
-
{ base: 'DZ', letters: '\u01F1\u01C4' },
|
|
1425
|
-
{ base: 'Dz', letters: '\u01F2\u01C5' },
|
|
1426
|
-
{
|
|
1427
|
-
base: 'E',
|
|
1428
|
-
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',
|
|
1429
|
-
},
|
|
1430
|
-
{ base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
|
|
1431
|
-
{
|
|
1432
|
-
base: 'G',
|
|
1433
|
-
letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
|
|
1434
|
-
},
|
|
1435
|
-
{
|
|
1436
|
-
base: 'H',
|
|
1437
|
-
letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
|
|
1438
|
-
},
|
|
1439
|
-
{
|
|
1440
|
-
base: 'I',
|
|
1441
|
-
letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
|
|
1442
|
-
},
|
|
1443
|
-
{ base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
|
|
1444
|
-
{
|
|
1445
|
-
base: 'K',
|
|
1446
|
-
letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
|
|
1447
|
-
},
|
|
1448
|
-
{
|
|
1449
|
-
base: 'L',
|
|
1450
|
-
letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
|
|
1451
|
-
},
|
|
1452
|
-
{ base: 'LJ', letters: '\u01C7' },
|
|
1453
|
-
{ base: 'Lj', letters: '\u01C8' },
|
|
1454
|
-
{ base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
|
|
1455
|
-
{
|
|
1456
|
-
base: 'N',
|
|
1457
|
-
letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
|
|
1458
|
-
},
|
|
1459
|
-
{ base: 'NJ', letters: '\u01CA' },
|
|
1460
|
-
{ base: 'Nj', letters: '\u01CB' },
|
|
1461
|
-
{
|
|
1462
|
-
base: 'O',
|
|
1463
|
-
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',
|
|
1464
|
-
},
|
|
1465
|
-
{ base: 'OI', letters: '\u01A2' },
|
|
1466
|
-
{ base: 'OO', letters: '\uA74E' },
|
|
1467
|
-
{ base: 'OU', letters: '\u0222' },
|
|
1468
|
-
{ base: 'OE', letters: '\u008C\u0152' },
|
|
1469
|
-
{ base: 'oe', letters: '\u009C\u0153' },
|
|
1470
|
-
{
|
|
1471
|
-
base: 'P',
|
|
1472
|
-
letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
|
|
1473
|
-
},
|
|
1474
|
-
{ base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
|
|
1475
|
-
{
|
|
1476
|
-
base: 'R',
|
|
1477
|
-
letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
|
|
1478
|
-
},
|
|
1479
|
-
{
|
|
1480
|
-
base: 'S',
|
|
1481
|
-
letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
|
|
1482
|
-
},
|
|
1483
|
-
{
|
|
1484
|
-
base: 'T',
|
|
1485
|
-
letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
|
|
1486
|
-
},
|
|
1487
|
-
{ base: 'TZ', letters: '\uA728' },
|
|
1488
|
-
{
|
|
1489
|
-
base: 'U',
|
|
1490
|
-
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',
|
|
1491
|
-
},
|
|
1492
|
-
{ base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
|
|
1493
|
-
{ base: 'VY', letters: '\uA760' },
|
|
1494
|
-
{
|
|
1495
|
-
base: 'W',
|
|
1496
|
-
letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
|
|
1497
|
-
},
|
|
1498
|
-
{ base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
|
|
1499
|
-
{
|
|
1500
|
-
base: 'Y',
|
|
1501
|
-
letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
|
|
1502
|
-
},
|
|
1503
|
-
{
|
|
1504
|
-
base: 'Z',
|
|
1505
|
-
letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
|
|
1506
|
-
},
|
|
1507
|
-
{
|
|
1508
|
-
base: 'a',
|
|
1509
|
-
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',
|
|
1510
|
-
},
|
|
1511
|
-
{ base: 'aa', letters: '\uA733' },
|
|
1512
|
-
{ base: 'ae', letters: '\u00E6\u01FD\u01E3' },
|
|
1513
|
-
{ base: 'ao', letters: '\uA735' },
|
|
1514
|
-
{ base: 'au', letters: '\uA737' },
|
|
1515
|
-
{ base: 'av', letters: '\uA739\uA73B' },
|
|
1516
|
-
{ base: 'ay', letters: '\uA73D' },
|
|
1517
|
-
{
|
|
1518
|
-
base: 'b',
|
|
1519
|
-
letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
|
|
1520
|
-
},
|
|
1521
|
-
{
|
|
1522
|
-
base: 'c',
|
|
1523
|
-
letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
|
|
1524
|
-
},
|
|
1525
|
-
{
|
|
1526
|
-
base: 'd',
|
|
1527
|
-
letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
|
|
1528
|
-
},
|
|
1529
|
-
{ base: 'dz', letters: '\u01F3\u01C6' },
|
|
1530
|
-
{
|
|
1531
|
-
base: 'e',
|
|
1532
|
-
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',
|
|
1533
|
-
},
|
|
1534
|
-
{ base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
|
|
1535
|
-
{
|
|
1536
|
-
base: 'g',
|
|
1537
|
-
letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
|
|
1538
|
-
},
|
|
1539
|
-
{
|
|
1540
|
-
base: 'h',
|
|
1541
|
-
letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
|
|
1542
|
-
},
|
|
1543
|
-
{ base: 'hv', letters: '\u0195' },
|
|
1544
|
-
{
|
|
1545
|
-
base: 'i',
|
|
1546
|
-
letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
|
|
1547
|
-
},
|
|
1548
|
-
{ base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
|
|
1549
|
-
{
|
|
1550
|
-
base: 'k',
|
|
1551
|
-
letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
|
|
1552
|
-
},
|
|
1553
|
-
{
|
|
1554
|
-
base: 'l',
|
|
1555
|
-
letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
|
|
1556
|
-
},
|
|
1557
|
-
{ base: 'lj', letters: '\u01C9' },
|
|
1558
|
-
{ base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
|
|
1559
|
-
{
|
|
1560
|
-
base: 'n',
|
|
1561
|
-
letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
|
|
1562
|
-
},
|
|
1563
|
-
{ base: 'nj', letters: '\u01CC' },
|
|
1564
|
-
{
|
|
1565
|
-
base: 'o',
|
|
1566
|
-
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',
|
|
1567
|
-
},
|
|
1568
|
-
{ base: 'oi', letters: '\u01A3' },
|
|
1569
|
-
{ base: 'ou', letters: '\u0223' },
|
|
1570
|
-
{ base: 'oo', letters: '\uA74F' },
|
|
1571
|
-
{
|
|
1572
|
-
base: 'p',
|
|
1573
|
-
letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
|
|
1574
|
-
},
|
|
1575
|
-
{ base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
|
|
1576
|
-
{
|
|
1577
|
-
base: 'r',
|
|
1578
|
-
letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
|
|
1579
|
-
},
|
|
1580
|
-
{
|
|
1581
|
-
base: 's',
|
|
1582
|
-
letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
|
|
1583
|
-
},
|
|
1584
|
-
{
|
|
1585
|
-
base: 't',
|
|
1586
|
-
letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
|
|
1587
|
-
},
|
|
1588
|
-
{ base: 'tz', letters: '\uA729' },
|
|
1589
|
-
{
|
|
1590
|
-
base: 'u',
|
|
1591
|
-
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',
|
|
1592
|
-
},
|
|
1593
|
-
{ base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
|
|
1594
|
-
{ base: 'vy', letters: '\uA761' },
|
|
1595
|
-
{
|
|
1596
|
-
base: 'w',
|
|
1597
|
-
letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
|
|
1598
|
-
},
|
|
1599
|
-
{ base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
|
|
1600
|
-
{
|
|
1601
|
-
base: 'y',
|
|
1602
|
-
letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
|
|
1603
|
-
},
|
|
1604
|
-
{
|
|
1605
|
-
base: 'z',
|
|
1606
|
-
letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
|
|
1607
|
-
},
|
|
1608
|
-
];
|
|
1609
1440
|
/**
|
|
1610
|
-
*
|
|
1611
|
-
* Contains lowercase and uppercase separatelly
|
|
1612
|
-
*
|
|
1613
|
-
* > "á" => "a"
|
|
1614
|
-
* > "ě" => "e"
|
|
1615
|
-
* > "Ă" => "A"
|
|
1616
|
-
* > ...
|
|
1441
|
+
* This error type indicates that some tools are missing for pipeline execution or preparation
|
|
1617
1442
|
*
|
|
1618
|
-
* @public exported from `@promptbook/
|
|
1443
|
+
* @public exported from `@promptbook/core`
|
|
1619
1444
|
*/
|
|
1620
|
-
var
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1445
|
+
var MissingToolsError = /** @class */ (function (_super) {
|
|
1446
|
+
__extends(MissingToolsError, _super);
|
|
1447
|
+
function MissingToolsError(message) {
|
|
1448
|
+
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;
|
|
1449
|
+
_this.name = 'MissingToolsError';
|
|
1450
|
+
Object.setPrototypeOf(_this, MissingToolsError.prototype);
|
|
1451
|
+
return _this;
|
|
1627
1452
|
}
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
/*
|
|
1631
|
-
@see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
|
|
1632
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
1633
|
-
you may not use this file except in compliance with the License.
|
|
1634
|
-
You may obtain a copy of the License at
|
|
1453
|
+
return MissingToolsError;
|
|
1454
|
+
}(Error));
|
|
1635
1455
|
|
|
1636
|
-
|
|
1456
|
+
/**
|
|
1457
|
+
* This error indicates errors during the execution of the pipeline
|
|
1458
|
+
*
|
|
1459
|
+
* @public exported from `@promptbook/core`
|
|
1460
|
+
*/
|
|
1461
|
+
var PipelineExecutionError = /** @class */ (function (_super) {
|
|
1462
|
+
__extends(PipelineExecutionError, _super);
|
|
1463
|
+
function PipelineExecutionError(message) {
|
|
1464
|
+
var _this = _super.call(this, message) || this;
|
|
1465
|
+
_this.name = 'PipelineExecutionError';
|
|
1466
|
+
Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
|
|
1467
|
+
return _this;
|
|
1468
|
+
}
|
|
1469
|
+
return PipelineExecutionError;
|
|
1470
|
+
}(Error));
|
|
1637
1471
|
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1472
|
+
/**
|
|
1473
|
+
* This error indicates problems parsing the format value
|
|
1474
|
+
*
|
|
1475
|
+
* For example, when the format value is not a valid JSON or CSV
|
|
1476
|
+
* This is not thrown directly but in extended classes
|
|
1477
|
+
*
|
|
1478
|
+
* @public exported from `@promptbook/core`
|
|
1479
|
+
*/
|
|
1480
|
+
var AbstractFormatError = /** @class */ (function (_super) {
|
|
1481
|
+
__extends(AbstractFormatError, _super);
|
|
1482
|
+
// Note: To allow instanceof do not put here error `name`
|
|
1483
|
+
// public readonly name = 'AbstractFormatError';
|
|
1484
|
+
function AbstractFormatError(message) {
|
|
1485
|
+
var _this = _super.call(this, message) || this;
|
|
1486
|
+
Object.setPrototypeOf(_this, AbstractFormatError.prototype);
|
|
1487
|
+
return _this;
|
|
1488
|
+
}
|
|
1489
|
+
return AbstractFormatError;
|
|
1490
|
+
}(Error));
|
|
1644
1491
|
|
|
1645
1492
|
/**
|
|
1646
|
-
*
|
|
1493
|
+
* This error indicates problem with parsing of CSV
|
|
1647
1494
|
*
|
|
1648
|
-
* @
|
|
1649
|
-
* @returns @@@
|
|
1650
|
-
* @public exported from `@promptbook/utils`
|
|
1495
|
+
* @public exported from `@promptbook/core`
|
|
1651
1496
|
*/
|
|
1652
|
-
function
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1497
|
+
var CsvFormatError = /** @class */ (function (_super) {
|
|
1498
|
+
__extends(CsvFormatError, _super);
|
|
1499
|
+
function CsvFormatError(message) {
|
|
1500
|
+
var _this = _super.call(this, message) || this;
|
|
1501
|
+
_this.name = 'CsvFormatError';
|
|
1502
|
+
Object.setPrototypeOf(_this, CsvFormatError.prototype);
|
|
1503
|
+
return _this;
|
|
1504
|
+
}
|
|
1505
|
+
return CsvFormatError;
|
|
1506
|
+
}(AbstractFormatError));
|
|
1507
|
+
|
|
1658
1508
|
/**
|
|
1659
|
-
*
|
|
1509
|
+
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
1510
|
+
*
|
|
1511
|
+
* @public exported from `@promptbook/core`
|
|
1660
1512
|
*/
|
|
1513
|
+
var CollectionError = /** @class */ (function (_super) {
|
|
1514
|
+
__extends(CollectionError, _super);
|
|
1515
|
+
function CollectionError(message) {
|
|
1516
|
+
var _this = _super.call(this, message) || this;
|
|
1517
|
+
_this.name = 'CollectionError';
|
|
1518
|
+
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
1519
|
+
return _this;
|
|
1520
|
+
}
|
|
1521
|
+
return CollectionError;
|
|
1522
|
+
}(Error));
|
|
1661
1523
|
|
|
1662
1524
|
/**
|
|
1663
|
-
*
|
|
1525
|
+
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
1664
1526
|
*
|
|
1665
|
-
* @
|
|
1666
|
-
* @returns @@@
|
|
1667
|
-
* @example 'hello-world'
|
|
1668
|
-
* @example 'i-love-promptbook'
|
|
1669
|
-
* @public exported from `@promptbook/utils`
|
|
1670
|
-
*/
|
|
1671
|
-
function normalizeToKebabCase(text) {
|
|
1672
|
-
var e_1, _a;
|
|
1673
|
-
text = removeDiacritics(text);
|
|
1674
|
-
var charType;
|
|
1675
|
-
var lastCharType = 'OTHER';
|
|
1676
|
-
var normalizedName = '';
|
|
1677
|
-
try {
|
|
1678
|
-
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
1679
|
-
var char = text_1_1.value;
|
|
1680
|
-
var normalizedChar = void 0;
|
|
1681
|
-
if (/^[a-z]$/.test(char)) {
|
|
1682
|
-
charType = 'LOWERCASE';
|
|
1683
|
-
normalizedChar = char;
|
|
1684
|
-
}
|
|
1685
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
1686
|
-
charType = 'UPPERCASE';
|
|
1687
|
-
normalizedChar = char.toLowerCase();
|
|
1688
|
-
}
|
|
1689
|
-
else if (/^[0-9]$/.test(char)) {
|
|
1690
|
-
charType = 'NUMBER';
|
|
1691
|
-
normalizedChar = char;
|
|
1692
|
-
}
|
|
1693
|
-
else {
|
|
1694
|
-
charType = 'OTHER';
|
|
1695
|
-
normalizedChar = '-';
|
|
1696
|
-
}
|
|
1697
|
-
if (charType !== lastCharType &&
|
|
1698
|
-
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
1699
|
-
!(lastCharType === 'NUMBER') &&
|
|
1700
|
-
!(charType === 'NUMBER')) {
|
|
1701
|
-
normalizedName += '-';
|
|
1702
|
-
}
|
|
1703
|
-
normalizedName += normalizedChar;
|
|
1704
|
-
lastCharType = charType;
|
|
1705
|
-
}
|
|
1706
|
-
}
|
|
1707
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1708
|
-
finally {
|
|
1709
|
-
try {
|
|
1710
|
-
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
1711
|
-
}
|
|
1712
|
-
finally { if (e_1) throw e_1.error; }
|
|
1713
|
-
}
|
|
1714
|
-
normalizedName = normalizedName.split(/-+/g).join('-');
|
|
1715
|
-
normalizedName = normalizedName.split(/-?\/-?/g).join('/');
|
|
1716
|
-
normalizedName = normalizedName.replace(/^-/, '');
|
|
1717
|
-
normalizedName = normalizedName.replace(/-$/, '');
|
|
1718
|
-
return normalizedName;
|
|
1719
|
-
}
|
|
1720
|
-
/**
|
|
1721
|
-
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1722
|
-
*/
|
|
1723
|
-
|
|
1724
|
-
/**
|
|
1725
|
-
* Removes emojis from a string and fix whitespaces
|
|
1726
|
-
*
|
|
1727
|
-
* @param text with emojis
|
|
1728
|
-
* @returns text without emojis
|
|
1729
|
-
* @public exported from `@promptbook/utils`
|
|
1730
|
-
*/
|
|
1731
|
-
function removeEmojis(text) {
|
|
1732
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
1733
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
1734
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
1735
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
1736
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
1737
|
-
return text;
|
|
1738
|
-
}
|
|
1739
|
-
|
|
1740
|
-
/**
|
|
1741
|
-
* Tests if given string is valid URL.
|
|
1742
|
-
*
|
|
1743
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
1744
|
-
* @public exported from `@promptbook/utils`
|
|
1745
|
-
*/
|
|
1746
|
-
function isValidFilePath(filename) {
|
|
1747
|
-
if (typeof filename !== 'string') {
|
|
1748
|
-
return false;
|
|
1749
|
-
}
|
|
1750
|
-
var filenameSlashes = filename.split('\\').join('/');
|
|
1751
|
-
// Absolute Unix path: /hello.txt
|
|
1752
|
-
if (/^(\/)/i.test(filenameSlashes)) {
|
|
1753
|
-
return true;
|
|
1754
|
-
}
|
|
1755
|
-
// Absolute Windows path: /hello.txt
|
|
1756
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
1757
|
-
return true;
|
|
1758
|
-
}
|
|
1759
|
-
// Relative path: ./hello.txt
|
|
1760
|
-
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
1761
|
-
return true;
|
|
1762
|
-
}
|
|
1763
|
-
return false;
|
|
1764
|
-
}
|
|
1765
|
-
|
|
1766
|
-
/**
|
|
1767
|
-
* @@@
|
|
1768
|
-
*
|
|
1769
|
-
* @param value @@@
|
|
1770
|
-
* @returns @@@
|
|
1771
|
-
* @example @@@
|
|
1772
|
-
* @public exported from `@promptbook/utils`
|
|
1773
|
-
*/
|
|
1774
|
-
function titleToName(value) {
|
|
1775
|
-
if (isValidUrl(value)) {
|
|
1776
|
-
value = value.replace(/^https?:\/\//, '');
|
|
1777
|
-
value = value.replace(/\.html$/, '');
|
|
1778
|
-
}
|
|
1779
|
-
else if (isValidFilePath(value)) {
|
|
1780
|
-
value = path.basename(value);
|
|
1781
|
-
// Note: Keeping extension in the name
|
|
1782
|
-
}
|
|
1783
|
-
value = value.split('/').join('-');
|
|
1784
|
-
value = removeEmojis(value);
|
|
1785
|
-
value = normalizeToKebabCase(value);
|
|
1786
|
-
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
1787
|
-
return value;
|
|
1788
|
-
}
|
|
1789
|
-
|
|
1790
|
-
/**
|
|
1791
|
-
* This error type indicates that some tools are missing for pipeline execution or preparation
|
|
1792
|
-
*
|
|
1793
|
-
* @public exported from `@promptbook/core`
|
|
1794
|
-
*/
|
|
1795
|
-
var MissingToolsError = /** @class */ (function (_super) {
|
|
1796
|
-
__extends(MissingToolsError, _super);
|
|
1797
|
-
function MissingToolsError(message) {
|
|
1798
|
-
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;
|
|
1799
|
-
_this.name = 'MissingToolsError';
|
|
1800
|
-
Object.setPrototypeOf(_this, MissingToolsError.prototype);
|
|
1801
|
-
return _this;
|
|
1802
|
-
}
|
|
1803
|
-
return MissingToolsError;
|
|
1804
|
-
}(Error));
|
|
1805
|
-
|
|
1806
|
-
/**
|
|
1807
|
-
* This error indicates errors during the execution of the pipeline
|
|
1808
|
-
*
|
|
1809
|
-
* @public exported from `@promptbook/core`
|
|
1810
|
-
*/
|
|
1811
|
-
var PipelineExecutionError = /** @class */ (function (_super) {
|
|
1812
|
-
__extends(PipelineExecutionError, _super);
|
|
1813
|
-
function PipelineExecutionError(message) {
|
|
1814
|
-
var _this = _super.call(this, message) || this;
|
|
1815
|
-
_this.name = 'PipelineExecutionError';
|
|
1816
|
-
Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
|
|
1817
|
-
return _this;
|
|
1818
|
-
}
|
|
1819
|
-
return PipelineExecutionError;
|
|
1820
|
-
}(Error));
|
|
1821
|
-
|
|
1822
|
-
/**
|
|
1823
|
-
* This error indicates problems parsing the format value
|
|
1824
|
-
*
|
|
1825
|
-
* For example, when the format value is not a valid JSON or CSV
|
|
1826
|
-
* This is not thrown directly but in extended classes
|
|
1827
|
-
*
|
|
1828
|
-
* @public exported from `@promptbook/core`
|
|
1829
|
-
*/
|
|
1830
|
-
var AbstractFormatError = /** @class */ (function (_super) {
|
|
1831
|
-
__extends(AbstractFormatError, _super);
|
|
1832
|
-
// Note: To allow instanceof do not put here error `name`
|
|
1833
|
-
// public readonly name = 'AbstractFormatError';
|
|
1834
|
-
function AbstractFormatError(message) {
|
|
1835
|
-
var _this = _super.call(this, message) || this;
|
|
1836
|
-
Object.setPrototypeOf(_this, AbstractFormatError.prototype);
|
|
1837
|
-
return _this;
|
|
1838
|
-
}
|
|
1839
|
-
return AbstractFormatError;
|
|
1840
|
-
}(Error));
|
|
1841
|
-
|
|
1842
|
-
/**
|
|
1843
|
-
* This error indicates problem with parsing of CSV
|
|
1844
|
-
*
|
|
1845
|
-
* @public exported from `@promptbook/core`
|
|
1846
|
-
*/
|
|
1847
|
-
var CsvFormatError = /** @class */ (function (_super) {
|
|
1848
|
-
__extends(CsvFormatError, _super);
|
|
1849
|
-
function CsvFormatError(message) {
|
|
1850
|
-
var _this = _super.call(this, message) || this;
|
|
1851
|
-
_this.name = 'CsvFormatError';
|
|
1852
|
-
Object.setPrototypeOf(_this, CsvFormatError.prototype);
|
|
1853
|
-
return _this;
|
|
1854
|
-
}
|
|
1855
|
-
return CsvFormatError;
|
|
1856
|
-
}(AbstractFormatError));
|
|
1857
|
-
|
|
1858
|
-
/**
|
|
1859
|
-
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
1860
|
-
*
|
|
1861
|
-
* @public exported from `@promptbook/core`
|
|
1862
|
-
*/
|
|
1863
|
-
var CollectionError = /** @class */ (function (_super) {
|
|
1864
|
-
__extends(CollectionError, _super);
|
|
1865
|
-
function CollectionError(message) {
|
|
1866
|
-
var _this = _super.call(this, message) || this;
|
|
1867
|
-
_this.name = 'CollectionError';
|
|
1868
|
-
Object.setPrototypeOf(_this, CollectionError.prototype);
|
|
1869
|
-
return _this;
|
|
1870
|
-
}
|
|
1871
|
-
return CollectionError;
|
|
1872
|
-
}(Error));
|
|
1873
|
-
|
|
1874
|
-
/**
|
|
1875
|
-
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
1876
|
-
*
|
|
1877
|
-
* @public exported from `@promptbook/core`
|
|
1527
|
+
* @public exported from `@promptbook/core`
|
|
1878
1528
|
*/
|
|
1879
1529
|
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
1880
1530
|
__extends(EnvironmentMismatchError, _super);
|
|
@@ -2920,148 +2570,471 @@
|
|
|
2920
2570
|
return $Register;
|
|
2921
2571
|
}());
|
|
2922
2572
|
|
|
2923
|
-
/**
|
|
2924
|
-
* @@@
|
|
2925
|
-
*
|
|
2926
|
-
* Note: `$` is used to indicate that this interacts with the global scope
|
|
2927
|
-
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
2928
|
-
* @public exported from `@promptbook/core`
|
|
2929
|
-
*/
|
|
2930
|
-
var $scrapersMetadataRegister = new $Register('scrapers_metadata');
|
|
2931
|
-
/**
|
|
2932
|
-
* TODO: [®] DRY Register logic
|
|
2933
|
-
*/
|
|
2573
|
+
/**
|
|
2574
|
+
* @@@
|
|
2575
|
+
*
|
|
2576
|
+
* Note: `$` is used to indicate that this interacts with the global scope
|
|
2577
|
+
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
2578
|
+
* @public exported from `@promptbook/core`
|
|
2579
|
+
*/
|
|
2580
|
+
var $scrapersMetadataRegister = new $Register('scrapers_metadata');
|
|
2581
|
+
/**
|
|
2582
|
+
* TODO: [®] DRY Register logic
|
|
2583
|
+
*/
|
|
2584
|
+
|
|
2585
|
+
/**
|
|
2586
|
+
* @@@
|
|
2587
|
+
*
|
|
2588
|
+
* Note: `$` is used to indicate that this interacts with the global scope
|
|
2589
|
+
* @singleton Only one instance of each register is created per build, but thare can be more @@@
|
|
2590
|
+
* @public exported from `@promptbook/core`
|
|
2591
|
+
*/
|
|
2592
|
+
var $scrapersRegister = new $Register('scraper_constructors');
|
|
2593
|
+
/**
|
|
2594
|
+
* TODO: [®] DRY Register logic
|
|
2595
|
+
*/
|
|
2596
|
+
|
|
2597
|
+
/**
|
|
2598
|
+
* Creates a message with all registered scrapers
|
|
2599
|
+
*
|
|
2600
|
+
* Note: This function is used to create a (error) message when there is no scraper for particular mime type
|
|
2601
|
+
*
|
|
2602
|
+
* @private internal function of `createScrapersFromConfiguration` and `createScrapersFromEnv`
|
|
2603
|
+
*/
|
|
2604
|
+
function $registeredScrapersMessage(availableScrapers) {
|
|
2605
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
2606
|
+
/**
|
|
2607
|
+
* Mixes registered scrapers from $scrapersMetadataRegister and $scrapersRegister
|
|
2608
|
+
*/
|
|
2609
|
+
var all = [];
|
|
2610
|
+
var _loop_1 = function (packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser) {
|
|
2611
|
+
if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
|
|
2612
|
+
return "continue";
|
|
2613
|
+
}
|
|
2614
|
+
all.push({ packageName: packageName, className: className, mimeTypes: mimeTypes, documentationUrl: documentationUrl, isAvilableInBrowser: isAvilableInBrowser });
|
|
2615
|
+
};
|
|
2616
|
+
try {
|
|
2617
|
+
for (var _d = __values($scrapersMetadataRegister.list()), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2618
|
+
var _f = _e.value, packageName = _f.packageName, className = _f.className, mimeTypes = _f.mimeTypes, documentationUrl = _f.documentationUrl, isAvilableInBrowser = _f.isAvilableInBrowser;
|
|
2619
|
+
_loop_1(packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser);
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2623
|
+
finally {
|
|
2624
|
+
try {
|
|
2625
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
2626
|
+
}
|
|
2627
|
+
finally { if (e_1) throw e_1.error; }
|
|
2628
|
+
}
|
|
2629
|
+
var _loop_2 = function (packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser) {
|
|
2630
|
+
if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
|
|
2631
|
+
return "continue";
|
|
2632
|
+
}
|
|
2633
|
+
all.push({ packageName: packageName, className: className, mimeTypes: mimeTypes, documentationUrl: documentationUrl, isAvilableInBrowser: isAvilableInBrowser });
|
|
2634
|
+
};
|
|
2635
|
+
try {
|
|
2636
|
+
for (var _g = __values($scrapersRegister.list()), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
2637
|
+
var _j = _h.value, packageName = _j.packageName, className = _j.className, mimeTypes = _j.mimeTypes, documentationUrl = _j.documentationUrl, isAvilableInBrowser = _j.isAvilableInBrowser;
|
|
2638
|
+
_loop_2(packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser);
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2642
|
+
finally {
|
|
2643
|
+
try {
|
|
2644
|
+
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
2645
|
+
}
|
|
2646
|
+
finally { if (e_2) throw e_2.error; }
|
|
2647
|
+
}
|
|
2648
|
+
try {
|
|
2649
|
+
for (var availableScrapers_1 = __values(availableScrapers), availableScrapers_1_1 = availableScrapers_1.next(); !availableScrapers_1_1.done; availableScrapers_1_1 = availableScrapers_1.next()) {
|
|
2650
|
+
var metadata_1 = availableScrapers_1_1.value.metadata;
|
|
2651
|
+
all.push(metadata_1);
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
2655
|
+
finally {
|
|
2656
|
+
try {
|
|
2657
|
+
if (availableScrapers_1_1 && !availableScrapers_1_1.done && (_c = availableScrapers_1.return)) _c.call(availableScrapers_1);
|
|
2658
|
+
}
|
|
2659
|
+
finally { if (e_3) throw e_3.error; }
|
|
2660
|
+
}
|
|
2661
|
+
var metadata = all.map(function (metadata) {
|
|
2662
|
+
var isMetadataAviailable = $scrapersMetadataRegister
|
|
2663
|
+
.list()
|
|
2664
|
+
.find(function (_a) {
|
|
2665
|
+
var packageName = _a.packageName, className = _a.className;
|
|
2666
|
+
return metadata.packageName === packageName && metadata.className === className;
|
|
2667
|
+
});
|
|
2668
|
+
var isInstalled = $scrapersRegister
|
|
2669
|
+
.list()
|
|
2670
|
+
.find(function (_a) {
|
|
2671
|
+
var packageName = _a.packageName, className = _a.className;
|
|
2672
|
+
return metadata.packageName === packageName && metadata.className === className;
|
|
2673
|
+
});
|
|
2674
|
+
var isAvilableInTools = availableScrapers.some(function (_a) {
|
|
2675
|
+
var _b = _a.metadata, packageName = _b.packageName, className = _b.className;
|
|
2676
|
+
return metadata.packageName === packageName && metadata.className === className;
|
|
2677
|
+
});
|
|
2678
|
+
return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled, isAvilableInTools: isAvilableInTools });
|
|
2679
|
+
});
|
|
2680
|
+
if (metadata.length === 0) {
|
|
2681
|
+
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 ");
|
|
2682
|
+
}
|
|
2683
|
+
return spaceTrim__default["default"](function (block) { return "\n Available scrapers are:\n ".concat(block(metadata
|
|
2684
|
+
.map(function (_a, i) {
|
|
2685
|
+
var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled, mimeTypes = _a.mimeTypes, isAvilableInBrowser = _a.isAvilableInBrowser, isAvilableInTools = _a.isAvilableInTools;
|
|
2686
|
+
var more = [];
|
|
2687
|
+
// TODO: [🧠] Maybe use `documentationUrl`
|
|
2688
|
+
if (isMetadataAviailable) {
|
|
2689
|
+
more.push("\u2B1C Metadata registered");
|
|
2690
|
+
} // not else
|
|
2691
|
+
if (isInstalled) {
|
|
2692
|
+
more.push("\uD83D\uDFE9 Installed");
|
|
2693
|
+
} // not else
|
|
2694
|
+
if (isAvilableInTools) {
|
|
2695
|
+
more.push("\uD83D\uDFE6 Available in tools");
|
|
2696
|
+
} // not else
|
|
2697
|
+
if (!isMetadataAviailable && isInstalled) {
|
|
2698
|
+
more.push("When no metadata registered but scraper is installed, it is an unexpected behavior");
|
|
2699
|
+
} // not else
|
|
2700
|
+
if (!isInstalled && isAvilableInTools) {
|
|
2701
|
+
more.push("When the scraper is not installed but available in tools, it is an unexpected compatibility behavior");
|
|
2702
|
+
} // not else
|
|
2703
|
+
if (!isAvilableInBrowser) {
|
|
2704
|
+
more.push("Not usable in browser");
|
|
2705
|
+
}
|
|
2706
|
+
var moreText = more.length === 0 ? '' : " *(".concat(more.join('; '), ")*");
|
|
2707
|
+
return "".concat(i + 1, ") `").concat(className, "` from `").concat(packageName, "` compatible to scrape ").concat(mimeTypes
|
|
2708
|
+
.map(function (mimeType) { return "\"".concat(mimeType, "\""); })
|
|
2709
|
+
.join(', ')).concat(moreText);
|
|
2710
|
+
})
|
|
2711
|
+
.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 "); });
|
|
2712
|
+
}
|
|
2713
|
+
/**
|
|
2714
|
+
* TODO: [®] DRY Register logic
|
|
2715
|
+
*/
|
|
2716
|
+
|
|
2717
|
+
var defaultDiacriticsRemovalMap = [
|
|
2718
|
+
{
|
|
2719
|
+
base: 'A',
|
|
2720
|
+
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',
|
|
2721
|
+
},
|
|
2722
|
+
{ base: 'AA', letters: '\uA732' },
|
|
2723
|
+
{ base: 'AE', letters: '\u00C6\u01FC\u01E2' },
|
|
2724
|
+
{ base: 'AO', letters: '\uA734' },
|
|
2725
|
+
{ base: 'AU', letters: '\uA736' },
|
|
2726
|
+
{ base: 'AV', letters: '\uA738\uA73A' },
|
|
2727
|
+
{ base: 'AY', letters: '\uA73C' },
|
|
2728
|
+
{
|
|
2729
|
+
base: 'B',
|
|
2730
|
+
letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
|
|
2731
|
+
},
|
|
2732
|
+
{
|
|
2733
|
+
base: 'C',
|
|
2734
|
+
letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
|
|
2735
|
+
},
|
|
2736
|
+
{
|
|
2737
|
+
base: 'D',
|
|
2738
|
+
letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
|
|
2739
|
+
},
|
|
2740
|
+
{ base: 'DZ', letters: '\u01F1\u01C4' },
|
|
2741
|
+
{ base: 'Dz', letters: '\u01F2\u01C5' },
|
|
2742
|
+
{
|
|
2743
|
+
base: 'E',
|
|
2744
|
+
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',
|
|
2745
|
+
},
|
|
2746
|
+
{ base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
|
|
2747
|
+
{
|
|
2748
|
+
base: 'G',
|
|
2749
|
+
letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
|
|
2750
|
+
},
|
|
2751
|
+
{
|
|
2752
|
+
base: 'H',
|
|
2753
|
+
letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
|
|
2754
|
+
},
|
|
2755
|
+
{
|
|
2756
|
+
base: 'I',
|
|
2757
|
+
letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
|
|
2758
|
+
},
|
|
2759
|
+
{ base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
|
|
2760
|
+
{
|
|
2761
|
+
base: 'K',
|
|
2762
|
+
letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
|
|
2763
|
+
},
|
|
2764
|
+
{
|
|
2765
|
+
base: 'L',
|
|
2766
|
+
letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
|
|
2767
|
+
},
|
|
2768
|
+
{ base: 'LJ', letters: '\u01C7' },
|
|
2769
|
+
{ base: 'Lj', letters: '\u01C8' },
|
|
2770
|
+
{ base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
|
|
2771
|
+
{
|
|
2772
|
+
base: 'N',
|
|
2773
|
+
letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
|
|
2774
|
+
},
|
|
2775
|
+
{ base: 'NJ', letters: '\u01CA' },
|
|
2776
|
+
{ base: 'Nj', letters: '\u01CB' },
|
|
2777
|
+
{
|
|
2778
|
+
base: 'O',
|
|
2779
|
+
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',
|
|
2780
|
+
},
|
|
2781
|
+
{ base: 'OI', letters: '\u01A2' },
|
|
2782
|
+
{ base: 'OO', letters: '\uA74E' },
|
|
2783
|
+
{ base: 'OU', letters: '\u0222' },
|
|
2784
|
+
{ base: 'OE', letters: '\u008C\u0152' },
|
|
2785
|
+
{ base: 'oe', letters: '\u009C\u0153' },
|
|
2786
|
+
{
|
|
2787
|
+
base: 'P',
|
|
2788
|
+
letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
|
|
2789
|
+
},
|
|
2790
|
+
{ base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
|
|
2791
|
+
{
|
|
2792
|
+
base: 'R',
|
|
2793
|
+
letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
|
|
2794
|
+
},
|
|
2795
|
+
{
|
|
2796
|
+
base: 'S',
|
|
2797
|
+
letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
|
|
2798
|
+
},
|
|
2799
|
+
{
|
|
2800
|
+
base: 'T',
|
|
2801
|
+
letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
|
|
2802
|
+
},
|
|
2803
|
+
{ base: 'TZ', letters: '\uA728' },
|
|
2804
|
+
{
|
|
2805
|
+
base: 'U',
|
|
2806
|
+
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',
|
|
2807
|
+
},
|
|
2808
|
+
{ base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
|
|
2809
|
+
{ base: 'VY', letters: '\uA760' },
|
|
2810
|
+
{
|
|
2811
|
+
base: 'W',
|
|
2812
|
+
letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
|
|
2813
|
+
},
|
|
2814
|
+
{ base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
|
|
2815
|
+
{
|
|
2816
|
+
base: 'Y',
|
|
2817
|
+
letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
|
|
2818
|
+
},
|
|
2819
|
+
{
|
|
2820
|
+
base: 'Z',
|
|
2821
|
+
letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
|
|
2822
|
+
},
|
|
2823
|
+
{
|
|
2824
|
+
base: 'a',
|
|
2825
|
+
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',
|
|
2826
|
+
},
|
|
2827
|
+
{ base: 'aa', letters: '\uA733' },
|
|
2828
|
+
{ base: 'ae', letters: '\u00E6\u01FD\u01E3' },
|
|
2829
|
+
{ base: 'ao', letters: '\uA735' },
|
|
2830
|
+
{ base: 'au', letters: '\uA737' },
|
|
2831
|
+
{ base: 'av', letters: '\uA739\uA73B' },
|
|
2832
|
+
{ base: 'ay', letters: '\uA73D' },
|
|
2833
|
+
{
|
|
2834
|
+
base: 'b',
|
|
2835
|
+
letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
|
|
2836
|
+
},
|
|
2837
|
+
{
|
|
2838
|
+
base: 'c',
|
|
2839
|
+
letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
|
|
2840
|
+
},
|
|
2841
|
+
{
|
|
2842
|
+
base: 'd',
|
|
2843
|
+
letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
|
|
2844
|
+
},
|
|
2845
|
+
{ base: 'dz', letters: '\u01F3\u01C6' },
|
|
2846
|
+
{
|
|
2847
|
+
base: 'e',
|
|
2848
|
+
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',
|
|
2849
|
+
},
|
|
2850
|
+
{ base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
|
|
2851
|
+
{
|
|
2852
|
+
base: 'g',
|
|
2853
|
+
letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
|
|
2854
|
+
},
|
|
2855
|
+
{
|
|
2856
|
+
base: 'h',
|
|
2857
|
+
letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
|
|
2858
|
+
},
|
|
2859
|
+
{ base: 'hv', letters: '\u0195' },
|
|
2860
|
+
{
|
|
2861
|
+
base: 'i',
|
|
2862
|
+
letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
|
|
2863
|
+
},
|
|
2864
|
+
{ base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
|
|
2865
|
+
{
|
|
2866
|
+
base: 'k',
|
|
2867
|
+
letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
|
|
2868
|
+
},
|
|
2869
|
+
{
|
|
2870
|
+
base: 'l',
|
|
2871
|
+
letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
|
|
2872
|
+
},
|
|
2873
|
+
{ base: 'lj', letters: '\u01C9' },
|
|
2874
|
+
{ base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
|
|
2875
|
+
{
|
|
2876
|
+
base: 'n',
|
|
2877
|
+
letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
|
|
2878
|
+
},
|
|
2879
|
+
{ base: 'nj', letters: '\u01CC' },
|
|
2880
|
+
{
|
|
2881
|
+
base: 'o',
|
|
2882
|
+
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',
|
|
2883
|
+
},
|
|
2884
|
+
{ base: 'oi', letters: '\u01A3' },
|
|
2885
|
+
{ base: 'ou', letters: '\u0223' },
|
|
2886
|
+
{ base: 'oo', letters: '\uA74F' },
|
|
2887
|
+
{
|
|
2888
|
+
base: 'p',
|
|
2889
|
+
letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
|
|
2890
|
+
},
|
|
2891
|
+
{ base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
|
|
2892
|
+
{
|
|
2893
|
+
base: 'r',
|
|
2894
|
+
letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
|
|
2895
|
+
},
|
|
2896
|
+
{
|
|
2897
|
+
base: 's',
|
|
2898
|
+
letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
|
|
2899
|
+
},
|
|
2900
|
+
{
|
|
2901
|
+
base: 't',
|
|
2902
|
+
letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
|
|
2903
|
+
},
|
|
2904
|
+
{ base: 'tz', letters: '\uA729' },
|
|
2905
|
+
{
|
|
2906
|
+
base: 'u',
|
|
2907
|
+
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',
|
|
2908
|
+
},
|
|
2909
|
+
{ base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
|
|
2910
|
+
{ base: 'vy', letters: '\uA761' },
|
|
2911
|
+
{
|
|
2912
|
+
base: 'w',
|
|
2913
|
+
letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
|
|
2914
|
+
},
|
|
2915
|
+
{ base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
|
|
2916
|
+
{
|
|
2917
|
+
base: 'y',
|
|
2918
|
+
letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
|
|
2919
|
+
},
|
|
2920
|
+
{
|
|
2921
|
+
base: 'z',
|
|
2922
|
+
letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
|
|
2923
|
+
},
|
|
2924
|
+
];
|
|
2925
|
+
/**
|
|
2926
|
+
* Map of letters from diacritic variant to diacritless variant
|
|
2927
|
+
* Contains lowercase and uppercase separatelly
|
|
2928
|
+
*
|
|
2929
|
+
* > "á" => "a"
|
|
2930
|
+
* > "ě" => "e"
|
|
2931
|
+
* > "Ă" => "A"
|
|
2932
|
+
* > ...
|
|
2933
|
+
*
|
|
2934
|
+
* @public exported from `@promptbook/utils`
|
|
2935
|
+
*/
|
|
2936
|
+
var DIACRITIC_VARIANTS_LETTERS = {};
|
|
2937
|
+
// tslint:disable-next-line: prefer-for-of
|
|
2938
|
+
for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
2939
|
+
var letters = defaultDiacriticsRemovalMap[i].letters;
|
|
2940
|
+
// tslint:disable-next-line: prefer-for-of
|
|
2941
|
+
for (var j = 0; j < letters.length; j++) {
|
|
2942
|
+
DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
// <- TODO: [🍓] Put to maker function to save execution time if not needed
|
|
2946
|
+
/*
|
|
2947
|
+
@see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
|
|
2948
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
2949
|
+
you may not use this file except in compliance with the License.
|
|
2950
|
+
You may obtain a copy of the License at
|
|
2951
|
+
|
|
2952
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
2953
|
+
|
|
2954
|
+
Unless required by applicable law or agreed to in writing, software
|
|
2955
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
2956
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2957
|
+
See the License for the specific language governing permissions and
|
|
2958
|
+
limitations under the License.
|
|
2959
|
+
*/
|
|
2934
2960
|
|
|
2935
2961
|
/**
|
|
2936
2962
|
* @@@
|
|
2937
2963
|
*
|
|
2938
|
-
*
|
|
2939
|
-
* @
|
|
2940
|
-
* @public exported from `@promptbook/
|
|
2964
|
+
* @param input @@@
|
|
2965
|
+
* @returns @@@
|
|
2966
|
+
* @public exported from `@promptbook/utils`
|
|
2941
2967
|
*/
|
|
2942
|
-
|
|
2968
|
+
function removeDiacritics(input) {
|
|
2969
|
+
/*eslint no-control-regex: "off"*/
|
|
2970
|
+
return input.replace(/[^\u0000-\u007E]/g, function (a) {
|
|
2971
|
+
return DIACRITIC_VARIANTS_LETTERS[a] || a;
|
|
2972
|
+
});
|
|
2973
|
+
}
|
|
2943
2974
|
/**
|
|
2944
|
-
* TODO: [
|
|
2975
|
+
* TODO: [Ж] Variant for cyrillic (and in general non-latin) letters
|
|
2945
2976
|
*/
|
|
2946
2977
|
|
|
2947
2978
|
/**
|
|
2948
|
-
*
|
|
2949
|
-
*
|
|
2950
|
-
* Note: This function is used to create a (error) message when there is no scraper for particular mime type
|
|
2979
|
+
* @@@
|
|
2951
2980
|
*
|
|
2952
|
-
* @
|
|
2981
|
+
* @param text @@@
|
|
2982
|
+
* @returns @@@
|
|
2983
|
+
* @example 'hello-world'
|
|
2984
|
+
* @example 'i-love-promptbook'
|
|
2985
|
+
* @public exported from `@promptbook/utils`
|
|
2953
2986
|
*/
|
|
2954
|
-
function
|
|
2955
|
-
var e_1, _a
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
var
|
|
2960
|
-
var _loop_1 = function (packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser) {
|
|
2961
|
-
if (all.some(function (item) { return item.packageName === packageName && item.className === className; })) {
|
|
2962
|
-
return "continue";
|
|
2963
|
-
}
|
|
2964
|
-
all.push({ packageName: packageName, className: className, mimeTypes: mimeTypes, documentationUrl: documentationUrl, isAvilableInBrowser: isAvilableInBrowser });
|
|
2965
|
-
};
|
|
2987
|
+
function normalizeToKebabCase(text) {
|
|
2988
|
+
var e_1, _a;
|
|
2989
|
+
text = removeDiacritics(text);
|
|
2990
|
+
var charType;
|
|
2991
|
+
var lastCharType = 'OTHER';
|
|
2992
|
+
var normalizedName = '';
|
|
2966
2993
|
try {
|
|
2967
|
-
for (var
|
|
2968
|
-
var
|
|
2969
|
-
|
|
2994
|
+
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
2995
|
+
var char = text_1_1.value;
|
|
2996
|
+
var normalizedChar = void 0;
|
|
2997
|
+
if (/^[a-z]$/.test(char)) {
|
|
2998
|
+
charType = 'LOWERCASE';
|
|
2999
|
+
normalizedChar = char;
|
|
3000
|
+
}
|
|
3001
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
3002
|
+
charType = 'UPPERCASE';
|
|
3003
|
+
normalizedChar = char.toLowerCase();
|
|
3004
|
+
}
|
|
3005
|
+
else if (/^[0-9]$/.test(char)) {
|
|
3006
|
+
charType = 'NUMBER';
|
|
3007
|
+
normalizedChar = char;
|
|
3008
|
+
}
|
|
3009
|
+
else {
|
|
3010
|
+
charType = 'OTHER';
|
|
3011
|
+
normalizedChar = '-';
|
|
3012
|
+
}
|
|
3013
|
+
if (charType !== lastCharType &&
|
|
3014
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
3015
|
+
!(lastCharType === 'NUMBER') &&
|
|
3016
|
+
!(charType === 'NUMBER')) {
|
|
3017
|
+
normalizedName += '-';
|
|
3018
|
+
}
|
|
3019
|
+
normalizedName += normalizedChar;
|
|
3020
|
+
lastCharType = charType;
|
|
2970
3021
|
}
|
|
2971
3022
|
}
|
|
2972
3023
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2973
3024
|
finally {
|
|
2974
3025
|
try {
|
|
2975
|
-
if (
|
|
3026
|
+
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
2976
3027
|
}
|
|
2977
3028
|
finally { if (e_1) throw e_1.error; }
|
|
2978
3029
|
}
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
};
|
|
2985
|
-
try {
|
|
2986
|
-
for (var _g = __values($scrapersRegister.list()), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
2987
|
-
var _j = _h.value, packageName = _j.packageName, className = _j.className, mimeTypes = _j.mimeTypes, documentationUrl = _j.documentationUrl, isAvilableInBrowser = _j.isAvilableInBrowser;
|
|
2988
|
-
_loop_2(packageName, className, mimeTypes, documentationUrl, isAvilableInBrowser);
|
|
2989
|
-
}
|
|
2990
|
-
}
|
|
2991
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2992
|
-
finally {
|
|
2993
|
-
try {
|
|
2994
|
-
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
2995
|
-
}
|
|
2996
|
-
finally { if (e_2) throw e_2.error; }
|
|
2997
|
-
}
|
|
2998
|
-
try {
|
|
2999
|
-
for (var availableScrapers_1 = __values(availableScrapers), availableScrapers_1_1 = availableScrapers_1.next(); !availableScrapers_1_1.done; availableScrapers_1_1 = availableScrapers_1.next()) {
|
|
3000
|
-
var metadata_1 = availableScrapers_1_1.value.metadata;
|
|
3001
|
-
all.push(metadata_1);
|
|
3002
|
-
}
|
|
3003
|
-
}
|
|
3004
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
3005
|
-
finally {
|
|
3006
|
-
try {
|
|
3007
|
-
if (availableScrapers_1_1 && !availableScrapers_1_1.done && (_c = availableScrapers_1.return)) _c.call(availableScrapers_1);
|
|
3008
|
-
}
|
|
3009
|
-
finally { if (e_3) throw e_3.error; }
|
|
3010
|
-
}
|
|
3011
|
-
var metadata = all.map(function (metadata) {
|
|
3012
|
-
var isMetadataAviailable = $scrapersMetadataRegister
|
|
3013
|
-
.list()
|
|
3014
|
-
.find(function (_a) {
|
|
3015
|
-
var packageName = _a.packageName, className = _a.className;
|
|
3016
|
-
return metadata.packageName === packageName && metadata.className === className;
|
|
3017
|
-
});
|
|
3018
|
-
var isInstalled = $scrapersRegister
|
|
3019
|
-
.list()
|
|
3020
|
-
.find(function (_a) {
|
|
3021
|
-
var packageName = _a.packageName, className = _a.className;
|
|
3022
|
-
return metadata.packageName === packageName && metadata.className === className;
|
|
3023
|
-
});
|
|
3024
|
-
var isAvilableInTools = availableScrapers.some(function (_a) {
|
|
3025
|
-
var _b = _a.metadata, packageName = _b.packageName, className = _b.className;
|
|
3026
|
-
return metadata.packageName === packageName && metadata.className === className;
|
|
3027
|
-
});
|
|
3028
|
-
return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled, isAvilableInTools: isAvilableInTools });
|
|
3029
|
-
});
|
|
3030
|
-
if (metadata.length === 0) {
|
|
3031
|
-
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 ");
|
|
3032
|
-
}
|
|
3033
|
-
return spaceTrim__default["default"](function (block) { return "\n Available scrapers are:\n ".concat(block(metadata
|
|
3034
|
-
.map(function (_a, i) {
|
|
3035
|
-
var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled, mimeTypes = _a.mimeTypes, isAvilableInBrowser = _a.isAvilableInBrowser, isAvilableInTools = _a.isAvilableInTools;
|
|
3036
|
-
var more = [];
|
|
3037
|
-
// TODO: [🧠] Maybe use `documentationUrl`
|
|
3038
|
-
if (isMetadataAviailable) {
|
|
3039
|
-
more.push("\u2B1C Metadata registered");
|
|
3040
|
-
} // not else
|
|
3041
|
-
if (isInstalled) {
|
|
3042
|
-
more.push("\uD83D\uDFE9 Installed");
|
|
3043
|
-
} // not else
|
|
3044
|
-
if (isAvilableInTools) {
|
|
3045
|
-
more.push("\uD83D\uDFE6 Available in tools");
|
|
3046
|
-
} // not else
|
|
3047
|
-
if (!isMetadataAviailable && isInstalled) {
|
|
3048
|
-
more.push("When no metadata registered but scraper is installed, it is an unexpected behavior");
|
|
3049
|
-
} // not else
|
|
3050
|
-
if (!isInstalled && isAvilableInTools) {
|
|
3051
|
-
more.push("When the scraper is not installed but available in tools, it is an unexpected compatibility behavior");
|
|
3052
|
-
} // not else
|
|
3053
|
-
if (!isAvilableInBrowser) {
|
|
3054
|
-
more.push("Not usable in browser");
|
|
3055
|
-
}
|
|
3056
|
-
var moreText = more.length === 0 ? '' : " *(".concat(more.join('; '), ")*");
|
|
3057
|
-
return "".concat(i + 1, ") `").concat(className, "` from `").concat(packageName, "` compatible to scrape ").concat(mimeTypes
|
|
3058
|
-
.map(function (mimeType) { return "\"".concat(mimeType, "\""); })
|
|
3059
|
-
.join(', ')).concat(moreText);
|
|
3060
|
-
})
|
|
3061
|
-
.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 "); });
|
|
3030
|
+
normalizedName = normalizedName.split(/-+/g).join('-');
|
|
3031
|
+
normalizedName = normalizedName.split(/-?\/-?/g).join('/');
|
|
3032
|
+
normalizedName = normalizedName.replace(/^-/, '');
|
|
3033
|
+
normalizedName = normalizedName.replace(/-$/, '');
|
|
3034
|
+
return normalizedName;
|
|
3062
3035
|
}
|
|
3063
3036
|
/**
|
|
3064
|
-
*
|
|
3037
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
3065
3038
|
*/
|
|
3066
3039
|
|
|
3067
3040
|
/**
|
|
@@ -3140,6 +3113,32 @@
|
|
|
3140
3113
|
* TODO: [🖇] What about symlinks?
|
|
3141
3114
|
*/
|
|
3142
3115
|
|
|
3116
|
+
/**
|
|
3117
|
+
* Tests if given string is valid URL.
|
|
3118
|
+
*
|
|
3119
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
3120
|
+
* @public exported from `@promptbook/utils`
|
|
3121
|
+
*/
|
|
3122
|
+
function isValidFilePath(filename) {
|
|
3123
|
+
if (typeof filename !== 'string') {
|
|
3124
|
+
return false;
|
|
3125
|
+
}
|
|
3126
|
+
var filenameSlashes = filename.split('\\').join('/');
|
|
3127
|
+
// Absolute Unix path: /hello.txt
|
|
3128
|
+
if (/^(\/)/i.test(filenameSlashes)) {
|
|
3129
|
+
return true;
|
|
3130
|
+
}
|
|
3131
|
+
// Absolute Windows path: /hello.txt
|
|
3132
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
3133
|
+
return true;
|
|
3134
|
+
}
|
|
3135
|
+
// Relative path: ./hello.txt
|
|
3136
|
+
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
3137
|
+
return true;
|
|
3138
|
+
}
|
|
3139
|
+
return false;
|
|
3140
|
+
}
|
|
3141
|
+
|
|
3143
3142
|
/**
|
|
3144
3143
|
* @@@
|
|
3145
3144
|
*
|
|
@@ -3601,10 +3600,11 @@
|
|
|
3601
3600
|
* @param script from which to extract the variables
|
|
3602
3601
|
* @returns the list of variable names
|
|
3603
3602
|
* @throws {ParseError} if the script is invalid
|
|
3604
|
-
* @public exported from `@promptbook/utils`
|
|
3603
|
+
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
3605
3604
|
*/
|
|
3606
|
-
function
|
|
3605
|
+
function extractVariablesFromScript(script) {
|
|
3607
3606
|
var variables = new Set();
|
|
3607
|
+
var originalScript = script;
|
|
3608
3608
|
script = "(()=>{".concat(script, "})()");
|
|
3609
3609
|
try {
|
|
3610
3610
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
@@ -3636,7 +3636,9 @@
|
|
|
3636
3636
|
if (!(error instanceof Error)) {
|
|
3637
3637
|
throw error;
|
|
3638
3638
|
}
|
|
3639
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n
|
|
3639
|
+
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)
|
|
3640
|
+
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
3641
|
+
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
3640
3642
|
}
|
|
3641
3643
|
return variables;
|
|
3642
3644
|
}
|
|
@@ -3650,7 +3652,7 @@
|
|
|
3650
3652
|
* @param task the task with used parameters
|
|
3651
3653
|
* @returns the set of parameter names
|
|
3652
3654
|
* @throws {ParseError} if the script is invalid
|
|
3653
|
-
* @public exported from `@promptbook/
|
|
3655
|
+
* @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
|
|
3654
3656
|
*/
|
|
3655
3657
|
function extractParameterNamesFromTask(task) {
|
|
3656
3658
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
@@ -3671,7 +3673,7 @@
|
|
|
3671
3673
|
}
|
|
3672
3674
|
if (taskType === 'SCRIPT_TASK') {
|
|
3673
3675
|
try {
|
|
3674
|
-
for (var _g = __values(
|
|
3676
|
+
for (var _g = __values(extractVariablesFromScript(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
3675
3677
|
var parameterName = _h.value;
|
|
3676
3678
|
parameterNames.add(parameterName);
|
|
3677
3679
|
}
|
|
@@ -5580,6 +5582,46 @@
|
|
|
5580
5582
|
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
5581
5583
|
*/
|
|
5582
5584
|
|
|
5585
|
+
/**
|
|
5586
|
+
* Removes emojis from a string and fix whitespaces
|
|
5587
|
+
*
|
|
5588
|
+
* @param text with emojis
|
|
5589
|
+
* @returns text without emojis
|
|
5590
|
+
* @public exported from `@promptbook/utils`
|
|
5591
|
+
*/
|
|
5592
|
+
function removeEmojis(text) {
|
|
5593
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
5594
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
5595
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
5596
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
5597
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
5598
|
+
return text;
|
|
5599
|
+
}
|
|
5600
|
+
|
|
5601
|
+
/**
|
|
5602
|
+
* @@@
|
|
5603
|
+
*
|
|
5604
|
+
* @param value @@@
|
|
5605
|
+
* @returns @@@
|
|
5606
|
+
* @example @@@
|
|
5607
|
+
* @public exported from `@promptbook/utils`
|
|
5608
|
+
*/
|
|
5609
|
+
function titleToName(value) {
|
|
5610
|
+
if (isValidUrl(value)) {
|
|
5611
|
+
value = value.replace(/^https?:\/\//, '');
|
|
5612
|
+
value = value.replace(/\.html$/, '');
|
|
5613
|
+
}
|
|
5614
|
+
else if (isValidFilePath(value)) {
|
|
5615
|
+
value = path.basename(value);
|
|
5616
|
+
// Note: Keeping extension in the name
|
|
5617
|
+
}
|
|
5618
|
+
value = value.split('/').join('-');
|
|
5619
|
+
value = removeEmojis(value);
|
|
5620
|
+
value = normalizeToKebabCase(value);
|
|
5621
|
+
// TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
|
|
5622
|
+
return value;
|
|
5623
|
+
}
|
|
5624
|
+
|
|
5583
5625
|
/**
|
|
5584
5626
|
* Metadata of the scraper
|
|
5585
5627
|
*
|