@promptbook/utils 0.77.0 → 0.78.0-0
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/README.md +4 -0
- package/esm/index.es.js +127 -238
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +8 -2
- 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/cli/test/ptbk.d.ts +1 -1
- package/esm/typings/src/commands/_common/types/CommandType.d.ts +17 -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/0-index.d.ts +46 -1
- package/esm/typings/src/errors/utils/ErrorJson.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/titleToName.test.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +127 -240
- 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/README.md
CHANGED
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
+
<blockquote style="color: #ff8811">
|
|
27
|
+
<b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
|
|
28
|
+
</blockquote>
|
|
29
|
+
|
|
26
30
|
## 📦 Package `@promptbook/utils`
|
|
27
31
|
|
|
28
32
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
package/esm/index.es.js
CHANGED
|
@@ -13,7 +13,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
13
13
|
*
|
|
14
14
|
* @see https://github.com/webgptorg/promptbook
|
|
15
15
|
*/
|
|
16
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.77.
|
|
16
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.77.1';
|
|
17
17
|
/**
|
|
18
18
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
19
19
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -218,6 +218,48 @@ function normalizeTo_camelCase(text, _isFirstLetterCapital) {
|
|
|
218
218
|
* TODO: [🌺] Use some intermediate util splitWords
|
|
219
219
|
*/
|
|
220
220
|
|
|
221
|
+
/**
|
|
222
|
+
* Removes emojis from a string and fix whitespaces
|
|
223
|
+
*
|
|
224
|
+
* @param text with emojis
|
|
225
|
+
* @returns text without emojis
|
|
226
|
+
* @public exported from `@promptbook/utils`
|
|
227
|
+
*/
|
|
228
|
+
function removeEmojis(text) {
|
|
229
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
230
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
231
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
232
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
233
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
234
|
+
return text;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Tests if given string is valid URL.
|
|
239
|
+
*
|
|
240
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
241
|
+
* @public exported from `@promptbook/utils`
|
|
242
|
+
*/
|
|
243
|
+
function isValidFilePath(filename) {
|
|
244
|
+
if (typeof filename !== 'string') {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
var filenameSlashes = filename.split('\\').join('/');
|
|
248
|
+
// Absolute Unix path: /hello.txt
|
|
249
|
+
if (/^(\/)/i.test(filenameSlashes)) {
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
// Absolute Windows path: /hello.txt
|
|
253
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
// Relative path: ./hello.txt
|
|
257
|
+
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
|
|
221
263
|
/**
|
|
222
264
|
* Tests if given string is valid URL.
|
|
223
265
|
*
|
|
@@ -570,48 +612,6 @@ function normalizeToKebabCase(text) {
|
|
|
570
612
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
571
613
|
*/
|
|
572
614
|
|
|
573
|
-
/**
|
|
574
|
-
* Removes emojis from a string and fix whitespaces
|
|
575
|
-
*
|
|
576
|
-
* @param text with emojis
|
|
577
|
-
* @returns text without emojis
|
|
578
|
-
* @public exported from `@promptbook/utils`
|
|
579
|
-
*/
|
|
580
|
-
function removeEmojis(text) {
|
|
581
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
582
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
583
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
584
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
585
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
586
|
-
return text;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
/**
|
|
590
|
-
* Tests if given string is valid URL.
|
|
591
|
-
*
|
|
592
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
593
|
-
* @public exported from `@promptbook/utils`
|
|
594
|
-
*/
|
|
595
|
-
function isValidFilePath(filename) {
|
|
596
|
-
if (typeof filename !== 'string') {
|
|
597
|
-
return false;
|
|
598
|
-
}
|
|
599
|
-
var filenameSlashes = filename.split('\\').join('/');
|
|
600
|
-
// Absolute Unix path: /hello.txt
|
|
601
|
-
if (/^(\/)/i.test(filenameSlashes)) {
|
|
602
|
-
return true;
|
|
603
|
-
}
|
|
604
|
-
// Absolute Windows path: /hello.txt
|
|
605
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
606
|
-
return true;
|
|
607
|
-
}
|
|
608
|
-
// Relative path: ./hello.txt
|
|
609
|
-
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
610
|
-
return true;
|
|
611
|
-
}
|
|
612
|
-
return false;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
615
|
/**
|
|
616
616
|
* @@@
|
|
617
617
|
*
|
|
@@ -658,7 +658,7 @@ function renderPromptbookMermaid(pipelineJson, options) {
|
|
|
658
658
|
if (!task) {
|
|
659
659
|
throw new Error("Could not find task for {".concat(parameterName, "}"));
|
|
660
660
|
}
|
|
661
|
-
return normalizeTo_camelCase('task-' + titleToName(task.title));
|
|
661
|
+
return task.name || normalizeTo_camelCase('task-' + titleToName(task.title));
|
|
662
662
|
};
|
|
663
663
|
var promptbookMermaid = spaceTrim$1(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.tasks
|
|
664
664
|
.flatMap(function (_a) {
|
|
@@ -700,34 +700,6 @@ function renderPromptbookMermaid(pipelineJson, options) {
|
|
|
700
700
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
701
701
|
*/
|
|
702
702
|
|
|
703
|
-
/**
|
|
704
|
-
* Parses the task and returns the list of all parameter names
|
|
705
|
-
*
|
|
706
|
-
* @param template the string template with parameters in {curly} braces
|
|
707
|
-
* @returns the list of parameter names
|
|
708
|
-
* @public exported from `@promptbook/utils`
|
|
709
|
-
*/
|
|
710
|
-
function extractParameterNames(template) {
|
|
711
|
-
var e_1, _a;
|
|
712
|
-
var matches = template.matchAll(/{\w+}/g);
|
|
713
|
-
var parameterNames = new Set();
|
|
714
|
-
try {
|
|
715
|
-
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
716
|
-
var match = matches_1_1.value;
|
|
717
|
-
var parameterName = match[0].slice(1, -1);
|
|
718
|
-
parameterNames.add(parameterName);
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
722
|
-
finally {
|
|
723
|
-
try {
|
|
724
|
-
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
725
|
-
}
|
|
726
|
-
finally { if (e_1) throw e_1.error; }
|
|
727
|
-
}
|
|
728
|
-
return parameterNames;
|
|
729
|
-
}
|
|
730
|
-
|
|
731
703
|
/**
|
|
732
704
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
733
705
|
*
|
|
@@ -753,9 +725,9 @@ var ParseError = /** @class */ (function (_super) {
|
|
|
753
725
|
* @param script from which to extract the variables
|
|
754
726
|
* @returns the list of variable names
|
|
755
727
|
* @throws {ParseError} if the script is invalid
|
|
756
|
-
* @public exported from `@promptbook/utils`
|
|
728
|
+
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
757
729
|
*/
|
|
758
|
-
function
|
|
730
|
+
function extractVariablesFromScript(script) {
|
|
759
731
|
var variables = new Set();
|
|
760
732
|
script = "(()=>{".concat(script, "})()");
|
|
761
733
|
try {
|
|
@@ -796,162 +768,6 @@ function extractVariables(script) {
|
|
|
796
768
|
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
797
769
|
*/
|
|
798
770
|
|
|
799
|
-
/**
|
|
800
|
-
* Parses the task and returns the set of all used parameters
|
|
801
|
-
*
|
|
802
|
-
* @param task the task with used parameters
|
|
803
|
-
* @returns the set of parameter names
|
|
804
|
-
* @throws {ParseError} if the script is invalid
|
|
805
|
-
* @public exported from `@promptbook/utils`
|
|
806
|
-
*/
|
|
807
|
-
function extractParameterNamesFromTask(task) {
|
|
808
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
809
|
-
var title = task.title, description = task.description, taskType = task.taskType, content = task.content, preparedContent = task.preparedContent, jokerParameterNames = task.jokerParameterNames, foreach = task.foreach;
|
|
810
|
-
var parameterNames = new Set();
|
|
811
|
-
try {
|
|
812
|
-
for (var _e = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameterNames(title)), false), __read(extractParameterNames(description || '')), false), __read(extractParameterNames(content)), false), __read(extractParameterNames(preparedContent || '')), false)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
813
|
-
var parameterName = _f.value;
|
|
814
|
-
parameterNames.add(parameterName);
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
818
|
-
finally {
|
|
819
|
-
try {
|
|
820
|
-
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
821
|
-
}
|
|
822
|
-
finally { if (e_1) throw e_1.error; }
|
|
823
|
-
}
|
|
824
|
-
if (taskType === 'SCRIPT_TASK') {
|
|
825
|
-
try {
|
|
826
|
-
for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
827
|
-
var parameterName = _h.value;
|
|
828
|
-
parameterNames.add(parameterName);
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
832
|
-
finally {
|
|
833
|
-
try {
|
|
834
|
-
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
835
|
-
}
|
|
836
|
-
finally { if (e_2) throw e_2.error; }
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
try {
|
|
840
|
-
for (var _j = __values(jokerParameterNames || []), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
841
|
-
var jokerName = _k.value;
|
|
842
|
-
parameterNames.add(jokerName);
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
846
|
-
finally {
|
|
847
|
-
try {
|
|
848
|
-
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
849
|
-
}
|
|
850
|
-
finally { if (e_3) throw e_3.error; }
|
|
851
|
-
}
|
|
852
|
-
parameterNames.delete('content');
|
|
853
|
-
// <- Note {websiteContent} is used in `preparedContent`
|
|
854
|
-
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
855
|
-
if (foreach !== undefined) {
|
|
856
|
-
try {
|
|
857
|
-
for (var _l = __values(foreach.inputSubparameterNames), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
858
|
-
var subparameterName = _m.value;
|
|
859
|
-
if (parameterNames.has(subparameterName)) {
|
|
860
|
-
parameterNames.delete(subparameterName);
|
|
861
|
-
parameterNames.add(foreach.parameterName);
|
|
862
|
-
// <- TODO: [🚎] Warn/logic error when `subparameterName` not used
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
867
|
-
finally {
|
|
868
|
-
try {
|
|
869
|
-
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
|
|
870
|
-
}
|
|
871
|
-
finally { if (e_4) throw e_4.error; }
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
return parameterNames;
|
|
875
|
-
}
|
|
876
|
-
/**
|
|
877
|
-
* TODO: [🔣] If script require contentLanguage
|
|
878
|
-
*/
|
|
879
|
-
|
|
880
|
-
/**
|
|
881
|
-
* This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
|
|
882
|
-
*
|
|
883
|
-
* @public exported from `@promptbook/core`
|
|
884
|
-
*/
|
|
885
|
-
var PipelineLogicError = /** @class */ (function (_super) {
|
|
886
|
-
__extends(PipelineLogicError, _super);
|
|
887
|
-
function PipelineLogicError(message) {
|
|
888
|
-
var _this = _super.call(this, message) || this;
|
|
889
|
-
_this.name = 'PipelineLogicError';
|
|
890
|
-
Object.setPrototypeOf(_this, PipelineLogicError.prototype);
|
|
891
|
-
return _this;
|
|
892
|
-
}
|
|
893
|
-
return PipelineLogicError;
|
|
894
|
-
}(Error));
|
|
895
|
-
|
|
896
|
-
/**
|
|
897
|
-
* Function `renameParameter` will find all usable parameters for given task
|
|
898
|
-
* In other words, it will find all parameters that are not used in the task itseld and all its dependencies
|
|
899
|
-
*
|
|
900
|
-
* @throws {PipelineLogicError} If the new parameter name is already used in the pipeline
|
|
901
|
-
* @public exported from `@promptbook/utils`
|
|
902
|
-
*/
|
|
903
|
-
function renameParameter(options) {
|
|
904
|
-
var e_1, _a, e_2, _b;
|
|
905
|
-
var pipeline = options.pipeline, oldParameterName = options.oldParameterName, newParameterName = options.newParameterName;
|
|
906
|
-
if (pipeline.parameters.some(function (parameter) { return parameter.name === newParameterName; })) {
|
|
907
|
-
throw new PipelineLogicError("Can not replace {".concat(oldParameterName, "} to {").concat(newParameterName, "} because {").concat(newParameterName, "} is already used in the pipeline"));
|
|
908
|
-
}
|
|
909
|
-
var renamedPipeline = __assign(__assign({}, pipeline), {
|
|
910
|
-
// <- TODO: [🪓] This should be without `as $PipelineJson`
|
|
911
|
-
parameters: __spreadArray([], __read(pipeline.parameters), false), tasks: __spreadArray([], __read(pipeline.tasks), false) });
|
|
912
|
-
try {
|
|
913
|
-
for (var _c = __values(renamedPipeline.parameters), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
914
|
-
var parameter = _d.value;
|
|
915
|
-
if (parameter.name !== oldParameterName) {
|
|
916
|
-
continue;
|
|
917
|
-
}
|
|
918
|
-
parameter.name = newParameterName;
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
922
|
-
finally {
|
|
923
|
-
try {
|
|
924
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
925
|
-
}
|
|
926
|
-
finally { if (e_1) throw e_1.error; }
|
|
927
|
-
}
|
|
928
|
-
try {
|
|
929
|
-
for (var _e = __values(renamedPipeline.tasks), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
930
|
-
var task = _f.value;
|
|
931
|
-
if (task.resultingParameterName === oldParameterName) {
|
|
932
|
-
task.resultingParameterName = newParameterName;
|
|
933
|
-
}
|
|
934
|
-
task.dependentParameterNames = task.dependentParameterNames.map(function (dependentParameterName) {
|
|
935
|
-
return dependentParameterName === oldParameterName ? newParameterName : dependentParameterName;
|
|
936
|
-
});
|
|
937
|
-
task.content = task.content.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
938
|
-
task.title = task.title.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
939
|
-
task.description =
|
|
940
|
-
task.description === undefined
|
|
941
|
-
? undefined
|
|
942
|
-
: task.description.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
946
|
-
finally {
|
|
947
|
-
try {
|
|
948
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
949
|
-
}
|
|
950
|
-
finally { if (e_2) throw e_2.error; }
|
|
951
|
-
}
|
|
952
|
-
return renamedPipeline;
|
|
953
|
-
}
|
|
954
|
-
|
|
955
771
|
/**
|
|
956
772
|
* This error indicates problems parsing the format value
|
|
957
773
|
*
|
|
@@ -1135,6 +951,22 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
1135
951
|
return PipelineExecutionError;
|
|
1136
952
|
}(Error));
|
|
1137
953
|
|
|
954
|
+
/**
|
|
955
|
+
* This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
|
|
956
|
+
*
|
|
957
|
+
* @public exported from `@promptbook/core`
|
|
958
|
+
*/
|
|
959
|
+
var PipelineLogicError = /** @class */ (function (_super) {
|
|
960
|
+
__extends(PipelineLogicError, _super);
|
|
961
|
+
function PipelineLogicError(message) {
|
|
962
|
+
var _this = _super.call(this, message) || this;
|
|
963
|
+
_this.name = 'PipelineLogicError';
|
|
964
|
+
Object.setPrototypeOf(_this, PipelineLogicError.prototype);
|
|
965
|
+
return _this;
|
|
966
|
+
}
|
|
967
|
+
return PipelineLogicError;
|
|
968
|
+
}(Error));
|
|
969
|
+
|
|
1138
970
|
/**
|
|
1139
971
|
* This error indicates errors in referencing promptbooks between each other
|
|
1140
972
|
*
|
|
@@ -1156,7 +988,7 @@ var PipelineUrlError = /** @class */ (function (_super) {
|
|
|
1156
988
|
*
|
|
1157
989
|
* @public exported from `@promptbook/core`
|
|
1158
990
|
*/
|
|
1159
|
-
var
|
|
991
|
+
var PROMPTBOOK_ERRORS = {
|
|
1160
992
|
AbstractFormatError: AbstractFormatError,
|
|
1161
993
|
CsvFormatError: CsvFormatError,
|
|
1162
994
|
CollectionError: CollectionError,
|
|
@@ -1174,6 +1006,35 @@ var ERRORS = {
|
|
|
1174
1006
|
UnexpectedError: UnexpectedError,
|
|
1175
1007
|
// TODO: [🪑]> VersionMismatchError,
|
|
1176
1008
|
};
|
|
1009
|
+
/**
|
|
1010
|
+
* Index of all javascript errors
|
|
1011
|
+
*
|
|
1012
|
+
* @private for internal usage
|
|
1013
|
+
*/
|
|
1014
|
+
var COMMON_JAVASCRIPT_ERRORS = {
|
|
1015
|
+
Error: Error,
|
|
1016
|
+
EvalError: EvalError,
|
|
1017
|
+
RangeError: RangeError,
|
|
1018
|
+
ReferenceError: ReferenceError,
|
|
1019
|
+
SyntaxError: SyntaxError,
|
|
1020
|
+
TypeError: TypeError,
|
|
1021
|
+
URIError: URIError,
|
|
1022
|
+
AggregateError: AggregateError,
|
|
1023
|
+
/*
|
|
1024
|
+
Note: Not widely supported
|
|
1025
|
+
> InternalError,
|
|
1026
|
+
> ModuleError,
|
|
1027
|
+
> HeapError,
|
|
1028
|
+
> WebAssemblyCompileError,
|
|
1029
|
+
> WebAssemblyRuntimeError,
|
|
1030
|
+
*/
|
|
1031
|
+
};
|
|
1032
|
+
/**
|
|
1033
|
+
* Index of all errors
|
|
1034
|
+
*
|
|
1035
|
+
* @private for internal usage
|
|
1036
|
+
*/
|
|
1037
|
+
var ALL_ERRORS = __assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
|
|
1177
1038
|
/**
|
|
1178
1039
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1179
1040
|
*/
|
|
@@ -1184,11 +1045,11 @@ var ERRORS = {
|
|
|
1184
1045
|
* @public exported from `@promptbook/utils`
|
|
1185
1046
|
*/
|
|
1186
1047
|
function deserializeError(error) {
|
|
1187
|
-
|
|
1188
|
-
|
|
1048
|
+
var ErrorClass = ALL_ERRORS[error.name];
|
|
1049
|
+
if (ErrorClass === undefined) {
|
|
1050
|
+
return new Error("".concat(error.name, ": ").concat(error.message));
|
|
1189
1051
|
}
|
|
1190
|
-
|
|
1191
|
-
return new CustomError(error.message);
|
|
1052
|
+
return new ErrorClass(error.message);
|
|
1192
1053
|
}
|
|
1193
1054
|
|
|
1194
1055
|
/**
|
|
@@ -1198,8 +1059,8 @@ function deserializeError(error) {
|
|
|
1198
1059
|
*/
|
|
1199
1060
|
function serializeError(error) {
|
|
1200
1061
|
var name = error.name, message = error.message, stack = error.stack;
|
|
1201
|
-
if (!
|
|
1202
|
-
|
|
1062
|
+
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
1063
|
+
console.error(spaceTrim$2(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
1203
1064
|
}
|
|
1204
1065
|
return {
|
|
1205
1066
|
name: name,
|
|
@@ -1725,6 +1586,34 @@ function searchKeywords(haystack, needle) {
|
|
|
1725
1586
|
*/
|
|
1726
1587
|
var spaceTrim = spaceTrim$1;
|
|
1727
1588
|
|
|
1589
|
+
/**
|
|
1590
|
+
* Parses the task and returns the list of all parameter names
|
|
1591
|
+
*
|
|
1592
|
+
* @param template the string template with parameters in {curly} braces
|
|
1593
|
+
* @returns the list of parameter names
|
|
1594
|
+
* @public exported from `@promptbook/utils`
|
|
1595
|
+
*/
|
|
1596
|
+
function extractParameterNames(template) {
|
|
1597
|
+
var e_1, _a;
|
|
1598
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
1599
|
+
var parameterNames = new Set();
|
|
1600
|
+
try {
|
|
1601
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
1602
|
+
var match = matches_1_1.value;
|
|
1603
|
+
var parameterName = match[0].slice(1, -1);
|
|
1604
|
+
parameterNames.add(parameterName);
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1608
|
+
finally {
|
|
1609
|
+
try {
|
|
1610
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
1611
|
+
}
|
|
1612
|
+
finally { if (e_1) throw e_1.error; }
|
|
1613
|
+
}
|
|
1614
|
+
return parameterNames;
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1728
1617
|
/**
|
|
1729
1618
|
* @@@
|
|
1730
1619
|
*
|
|
@@ -2612,5 +2501,5 @@ function isValidUuid(value) {
|
|
|
2612
2501
|
return /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i.test(value);
|
|
2613
2502
|
}
|
|
2614
2503
|
|
|
2615
|
-
export { $deepFreeze, $getCurrentDate, $isRunningInBrowser, $isRunningInJest, $isRunningInNode, $isRunningInWebWorker, $randomSeed, BOOK_LANGUAGE_VERSION, CHARACTERS_PER_STANDARD_LINE, CountUtils, DIACRITIC_VARIANTS_LETTERS, LINES_PER_STANDARD_PAGE, PROMPTBOOK_ENGINE_VERSION, capitalize, checkSerializableAsJson, clonePipeline, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, decapitalize, deepClone, deserializeError, difference, extractParameterNames,
|
|
2504
|
+
export { $deepFreeze, $getCurrentDate, $isRunningInBrowser, $isRunningInJest, $isRunningInNode, $isRunningInWebWorker, $randomSeed, BOOK_LANGUAGE_VERSION, CHARACTERS_PER_STANDARD_LINE, CountUtils, DIACRITIC_VARIANTS_LETTERS, LINES_PER_STANDARD_PAGE, PROMPTBOOK_ENGINE_VERSION, capitalize, checkSerializableAsJson, clonePipeline, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, decapitalize, deepClone, deserializeError, difference, extractParameterNames, extractVariablesFromScript, forEachAsync, intersection, isHostnameOnPrivateNetwork, isSerializableAsJson, isUrlOnPrivateNetwork, isValidEmail, isValidFilePath, isValidJavascriptName, isValidJsonString, isValidKeyword, isValidPipelineUrl, isValidPromptbookVersion, isValidSemanticVersion, isValidUrl, isValidUuid, nameToUriPart, nameToUriParts, normalizeToKebabCase, normalizeTo_PascalCase, normalizeTo_SCREAMING_CASE, normalizeTo_camelCase, normalizeTo_snake_case, normalizeWhitespaces, parseKeywords, parseKeywordsFromString, parseNumber, removeDiacritics, removeEmojis, removeQuotes, renderPromptbookMermaid, replaceParameters, searchKeywords, serializeError, spaceTrim, splitIntoSentences, titleToName, trimCodeBlock, trimEndOfCodeBlock, union, unwrapResult };
|
|
2616
2505
|
//# sourceMappingURL=index.es.js.map
|