@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ALL_ERRORS } from '../0-index';
|
|
2
2
|
/**
|
|
3
3
|
* Represents a serialized error or custom Promptbook error
|
|
4
4
|
*
|
|
@@ -8,7 +8,7 @@ export type ErrorJson = {
|
|
|
8
8
|
/**
|
|
9
9
|
* The type of the error
|
|
10
10
|
*/
|
|
11
|
-
readonly name: keyof typeof
|
|
11
|
+
readonly name: keyof typeof ALL_ERRORS;
|
|
12
12
|
/**
|
|
13
13
|
* The message of the error
|
|
14
14
|
*/
|
package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
*
|
|
21
21
|
* @see https://github.com/webgptorg/promptbook
|
|
22
22
|
*/
|
|
23
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.77.
|
|
23
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.77.1';
|
|
24
24
|
/**
|
|
25
25
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
26
26
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -225,6 +225,48 @@
|
|
|
225
225
|
* TODO: [🌺] Use some intermediate util splitWords
|
|
226
226
|
*/
|
|
227
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Removes emojis from a string and fix whitespaces
|
|
230
|
+
*
|
|
231
|
+
* @param text with emojis
|
|
232
|
+
* @returns text without emojis
|
|
233
|
+
* @public exported from `@promptbook/utils`
|
|
234
|
+
*/
|
|
235
|
+
function removeEmojis(text) {
|
|
236
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
237
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
238
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
239
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
240
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
241
|
+
return text;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Tests if given string is valid URL.
|
|
246
|
+
*
|
|
247
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
248
|
+
* @public exported from `@promptbook/utils`
|
|
249
|
+
*/
|
|
250
|
+
function isValidFilePath(filename) {
|
|
251
|
+
if (typeof filename !== 'string') {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
var filenameSlashes = filename.split('\\').join('/');
|
|
255
|
+
// Absolute Unix path: /hello.txt
|
|
256
|
+
if (/^(\/)/i.test(filenameSlashes)) {
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
// Absolute Windows path: /hello.txt
|
|
260
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
// Relative path: ./hello.txt
|
|
264
|
+
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
|
|
228
270
|
/**
|
|
229
271
|
* Tests if given string is valid URL.
|
|
230
272
|
*
|
|
@@ -577,48 +619,6 @@
|
|
|
577
619
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
578
620
|
*/
|
|
579
621
|
|
|
580
|
-
/**
|
|
581
|
-
* Removes emojis from a string and fix whitespaces
|
|
582
|
-
*
|
|
583
|
-
* @param text with emojis
|
|
584
|
-
* @returns text without emojis
|
|
585
|
-
* @public exported from `@promptbook/utils`
|
|
586
|
-
*/
|
|
587
|
-
function removeEmojis(text) {
|
|
588
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
589
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
590
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
591
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
592
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
593
|
-
return text;
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
/**
|
|
597
|
-
* Tests if given string is valid URL.
|
|
598
|
-
*
|
|
599
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
600
|
-
* @public exported from `@promptbook/utils`
|
|
601
|
-
*/
|
|
602
|
-
function isValidFilePath(filename) {
|
|
603
|
-
if (typeof filename !== 'string') {
|
|
604
|
-
return false;
|
|
605
|
-
}
|
|
606
|
-
var filenameSlashes = filename.split('\\').join('/');
|
|
607
|
-
// Absolute Unix path: /hello.txt
|
|
608
|
-
if (/^(\/)/i.test(filenameSlashes)) {
|
|
609
|
-
return true;
|
|
610
|
-
}
|
|
611
|
-
// Absolute Windows path: /hello.txt
|
|
612
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
613
|
-
return true;
|
|
614
|
-
}
|
|
615
|
-
// Relative path: ./hello.txt
|
|
616
|
-
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
617
|
-
return true;
|
|
618
|
-
}
|
|
619
|
-
return false;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
622
|
/**
|
|
623
623
|
* @@@
|
|
624
624
|
*
|
|
@@ -665,7 +665,7 @@
|
|
|
665
665
|
if (!task) {
|
|
666
666
|
throw new Error("Could not find task for {".concat(parameterName, "}"));
|
|
667
667
|
}
|
|
668
|
-
return normalizeTo_camelCase('task-' + titleToName(task.title));
|
|
668
|
+
return task.name || normalizeTo_camelCase('task-' + titleToName(task.title));
|
|
669
669
|
};
|
|
670
670
|
var promptbookMermaid = spaceTrim$1.spaceTrim(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
|
|
671
671
|
.flatMap(function (_a) {
|
|
@@ -707,34 +707,6 @@
|
|
|
707
707
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
708
708
|
*/
|
|
709
709
|
|
|
710
|
-
/**
|
|
711
|
-
* Parses the task and returns the list of all parameter names
|
|
712
|
-
*
|
|
713
|
-
* @param template the string template with parameters in {curly} braces
|
|
714
|
-
* @returns the list of parameter names
|
|
715
|
-
* @public exported from `@promptbook/utils`
|
|
716
|
-
*/
|
|
717
|
-
function extractParameterNames(template) {
|
|
718
|
-
var e_1, _a;
|
|
719
|
-
var matches = template.matchAll(/{\w+}/g);
|
|
720
|
-
var parameterNames = new Set();
|
|
721
|
-
try {
|
|
722
|
-
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
723
|
-
var match = matches_1_1.value;
|
|
724
|
-
var parameterName = match[0].slice(1, -1);
|
|
725
|
-
parameterNames.add(parameterName);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
729
|
-
finally {
|
|
730
|
-
try {
|
|
731
|
-
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
732
|
-
}
|
|
733
|
-
finally { if (e_1) throw e_1.error; }
|
|
734
|
-
}
|
|
735
|
-
return parameterNames;
|
|
736
|
-
}
|
|
737
|
-
|
|
738
710
|
/**
|
|
739
711
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
740
712
|
*
|
|
@@ -760,9 +732,9 @@
|
|
|
760
732
|
* @param script from which to extract the variables
|
|
761
733
|
* @returns the list of variable names
|
|
762
734
|
* @throws {ParseError} if the script is invalid
|
|
763
|
-
* @public exported from `@promptbook/utils`
|
|
735
|
+
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
764
736
|
*/
|
|
765
|
-
function
|
|
737
|
+
function extractVariablesFromScript(script) {
|
|
766
738
|
var variables = new Set();
|
|
767
739
|
script = "(()=>{".concat(script, "})()");
|
|
768
740
|
try {
|
|
@@ -803,162 +775,6 @@
|
|
|
803
775
|
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
804
776
|
*/
|
|
805
777
|
|
|
806
|
-
/**
|
|
807
|
-
* Parses the task and returns the set of all used parameters
|
|
808
|
-
*
|
|
809
|
-
* @param task the task with used parameters
|
|
810
|
-
* @returns the set of parameter names
|
|
811
|
-
* @throws {ParseError} if the script is invalid
|
|
812
|
-
* @public exported from `@promptbook/utils`
|
|
813
|
-
*/
|
|
814
|
-
function extractParameterNamesFromTask(task) {
|
|
815
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
816
|
-
var title = task.title, description = task.description, taskType = task.taskType, content = task.content, preparedContent = task.preparedContent, jokerParameterNames = task.jokerParameterNames, foreach = task.foreach;
|
|
817
|
-
var parameterNames = new Set();
|
|
818
|
-
try {
|
|
819
|
-
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()) {
|
|
820
|
-
var parameterName = _f.value;
|
|
821
|
-
parameterNames.add(parameterName);
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
825
|
-
finally {
|
|
826
|
-
try {
|
|
827
|
-
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
828
|
-
}
|
|
829
|
-
finally { if (e_1) throw e_1.error; }
|
|
830
|
-
}
|
|
831
|
-
if (taskType === 'SCRIPT_TASK') {
|
|
832
|
-
try {
|
|
833
|
-
for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
834
|
-
var parameterName = _h.value;
|
|
835
|
-
parameterNames.add(parameterName);
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
839
|
-
finally {
|
|
840
|
-
try {
|
|
841
|
-
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
842
|
-
}
|
|
843
|
-
finally { if (e_2) throw e_2.error; }
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
try {
|
|
847
|
-
for (var _j = __values(jokerParameterNames || []), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
848
|
-
var jokerName = _k.value;
|
|
849
|
-
parameterNames.add(jokerName);
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
853
|
-
finally {
|
|
854
|
-
try {
|
|
855
|
-
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
856
|
-
}
|
|
857
|
-
finally { if (e_3) throw e_3.error; }
|
|
858
|
-
}
|
|
859
|
-
parameterNames.delete('content');
|
|
860
|
-
// <- Note {websiteContent} is used in `preparedContent`
|
|
861
|
-
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
862
|
-
if (foreach !== undefined) {
|
|
863
|
-
try {
|
|
864
|
-
for (var _l = __values(foreach.inputSubparameterNames), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
865
|
-
var subparameterName = _m.value;
|
|
866
|
-
if (parameterNames.has(subparameterName)) {
|
|
867
|
-
parameterNames.delete(subparameterName);
|
|
868
|
-
parameterNames.add(foreach.parameterName);
|
|
869
|
-
// <- TODO: [🚎] Warn/logic error when `subparameterName` not used
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
874
|
-
finally {
|
|
875
|
-
try {
|
|
876
|
-
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
|
|
877
|
-
}
|
|
878
|
-
finally { if (e_4) throw e_4.error; }
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
return parameterNames;
|
|
882
|
-
}
|
|
883
|
-
/**
|
|
884
|
-
* TODO: [🔣] If script require contentLanguage
|
|
885
|
-
*/
|
|
886
|
-
|
|
887
|
-
/**
|
|
888
|
-
* This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
|
|
889
|
-
*
|
|
890
|
-
* @public exported from `@promptbook/core`
|
|
891
|
-
*/
|
|
892
|
-
var PipelineLogicError = /** @class */ (function (_super) {
|
|
893
|
-
__extends(PipelineLogicError, _super);
|
|
894
|
-
function PipelineLogicError(message) {
|
|
895
|
-
var _this = _super.call(this, message) || this;
|
|
896
|
-
_this.name = 'PipelineLogicError';
|
|
897
|
-
Object.setPrototypeOf(_this, PipelineLogicError.prototype);
|
|
898
|
-
return _this;
|
|
899
|
-
}
|
|
900
|
-
return PipelineLogicError;
|
|
901
|
-
}(Error));
|
|
902
|
-
|
|
903
|
-
/**
|
|
904
|
-
* Function `renameParameter` will find all usable parameters for given task
|
|
905
|
-
* In other words, it will find all parameters that are not used in the task itseld and all its dependencies
|
|
906
|
-
*
|
|
907
|
-
* @throws {PipelineLogicError} If the new parameter name is already used in the pipeline
|
|
908
|
-
* @public exported from `@promptbook/utils`
|
|
909
|
-
*/
|
|
910
|
-
function renameParameter(options) {
|
|
911
|
-
var e_1, _a, e_2, _b;
|
|
912
|
-
var pipeline = options.pipeline, oldParameterName = options.oldParameterName, newParameterName = options.newParameterName;
|
|
913
|
-
if (pipeline.parameters.some(function (parameter) { return parameter.name === newParameterName; })) {
|
|
914
|
-
throw new PipelineLogicError("Can not replace {".concat(oldParameterName, "} to {").concat(newParameterName, "} because {").concat(newParameterName, "} is already used in the pipeline"));
|
|
915
|
-
}
|
|
916
|
-
var renamedPipeline = __assign(__assign({}, pipeline), {
|
|
917
|
-
// <- TODO: [🪓] This should be without `as $PipelineJson`
|
|
918
|
-
parameters: __spreadArray([], __read(pipeline.parameters), false), tasks: __spreadArray([], __read(pipeline.tasks), false) });
|
|
919
|
-
try {
|
|
920
|
-
for (var _c = __values(renamedPipeline.parameters), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
921
|
-
var parameter = _d.value;
|
|
922
|
-
if (parameter.name !== oldParameterName) {
|
|
923
|
-
continue;
|
|
924
|
-
}
|
|
925
|
-
parameter.name = newParameterName;
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
929
|
-
finally {
|
|
930
|
-
try {
|
|
931
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
932
|
-
}
|
|
933
|
-
finally { if (e_1) throw e_1.error; }
|
|
934
|
-
}
|
|
935
|
-
try {
|
|
936
|
-
for (var _e = __values(renamedPipeline.tasks), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
937
|
-
var task = _f.value;
|
|
938
|
-
if (task.resultingParameterName === oldParameterName) {
|
|
939
|
-
task.resultingParameterName = newParameterName;
|
|
940
|
-
}
|
|
941
|
-
task.dependentParameterNames = task.dependentParameterNames.map(function (dependentParameterName) {
|
|
942
|
-
return dependentParameterName === oldParameterName ? newParameterName : dependentParameterName;
|
|
943
|
-
});
|
|
944
|
-
task.content = task.content.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
945
|
-
task.title = task.title.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
946
|
-
task.description =
|
|
947
|
-
task.description === undefined
|
|
948
|
-
? undefined
|
|
949
|
-
: task.description.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
953
|
-
finally {
|
|
954
|
-
try {
|
|
955
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
956
|
-
}
|
|
957
|
-
finally { if (e_2) throw e_2.error; }
|
|
958
|
-
}
|
|
959
|
-
return renamedPipeline;
|
|
960
|
-
}
|
|
961
|
-
|
|
962
778
|
/**
|
|
963
779
|
* This error indicates problems parsing the format value
|
|
964
780
|
*
|
|
@@ -1142,6 +958,22 @@
|
|
|
1142
958
|
return PipelineExecutionError;
|
|
1143
959
|
}(Error));
|
|
1144
960
|
|
|
961
|
+
/**
|
|
962
|
+
* This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
|
|
963
|
+
*
|
|
964
|
+
* @public exported from `@promptbook/core`
|
|
965
|
+
*/
|
|
966
|
+
var PipelineLogicError = /** @class */ (function (_super) {
|
|
967
|
+
__extends(PipelineLogicError, _super);
|
|
968
|
+
function PipelineLogicError(message) {
|
|
969
|
+
var _this = _super.call(this, message) || this;
|
|
970
|
+
_this.name = 'PipelineLogicError';
|
|
971
|
+
Object.setPrototypeOf(_this, PipelineLogicError.prototype);
|
|
972
|
+
return _this;
|
|
973
|
+
}
|
|
974
|
+
return PipelineLogicError;
|
|
975
|
+
}(Error));
|
|
976
|
+
|
|
1145
977
|
/**
|
|
1146
978
|
* This error indicates errors in referencing promptbooks between each other
|
|
1147
979
|
*
|
|
@@ -1163,7 +995,7 @@
|
|
|
1163
995
|
*
|
|
1164
996
|
* @public exported from `@promptbook/core`
|
|
1165
997
|
*/
|
|
1166
|
-
var
|
|
998
|
+
var PROMPTBOOK_ERRORS = {
|
|
1167
999
|
AbstractFormatError: AbstractFormatError,
|
|
1168
1000
|
CsvFormatError: CsvFormatError,
|
|
1169
1001
|
CollectionError: CollectionError,
|
|
@@ -1181,6 +1013,35 @@
|
|
|
1181
1013
|
UnexpectedError: UnexpectedError,
|
|
1182
1014
|
// TODO: [🪑]> VersionMismatchError,
|
|
1183
1015
|
};
|
|
1016
|
+
/**
|
|
1017
|
+
* Index of all javascript errors
|
|
1018
|
+
*
|
|
1019
|
+
* @private for internal usage
|
|
1020
|
+
*/
|
|
1021
|
+
var COMMON_JAVASCRIPT_ERRORS = {
|
|
1022
|
+
Error: Error,
|
|
1023
|
+
EvalError: EvalError,
|
|
1024
|
+
RangeError: RangeError,
|
|
1025
|
+
ReferenceError: ReferenceError,
|
|
1026
|
+
SyntaxError: SyntaxError,
|
|
1027
|
+
TypeError: TypeError,
|
|
1028
|
+
URIError: URIError,
|
|
1029
|
+
AggregateError: AggregateError,
|
|
1030
|
+
/*
|
|
1031
|
+
Note: Not widely supported
|
|
1032
|
+
> InternalError,
|
|
1033
|
+
> ModuleError,
|
|
1034
|
+
> HeapError,
|
|
1035
|
+
> WebAssemblyCompileError,
|
|
1036
|
+
> WebAssemblyRuntimeError,
|
|
1037
|
+
*/
|
|
1038
|
+
};
|
|
1039
|
+
/**
|
|
1040
|
+
* Index of all errors
|
|
1041
|
+
*
|
|
1042
|
+
* @private for internal usage
|
|
1043
|
+
*/
|
|
1044
|
+
var ALL_ERRORS = __assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
|
|
1184
1045
|
/**
|
|
1185
1046
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1186
1047
|
*/
|
|
@@ -1191,11 +1052,11 @@
|
|
|
1191
1052
|
* @public exported from `@promptbook/utils`
|
|
1192
1053
|
*/
|
|
1193
1054
|
function deserializeError(error) {
|
|
1194
|
-
|
|
1195
|
-
|
|
1055
|
+
var ErrorClass = ALL_ERRORS[error.name];
|
|
1056
|
+
if (ErrorClass === undefined) {
|
|
1057
|
+
return new Error("".concat(error.name, ": ").concat(error.message));
|
|
1196
1058
|
}
|
|
1197
|
-
|
|
1198
|
-
return new CustomError(error.message);
|
|
1059
|
+
return new ErrorClass(error.message);
|
|
1199
1060
|
}
|
|
1200
1061
|
|
|
1201
1062
|
/**
|
|
@@ -1205,8 +1066,8 @@
|
|
|
1205
1066
|
*/
|
|
1206
1067
|
function serializeError(error) {
|
|
1207
1068
|
var name = error.name, message = error.message, stack = error.stack;
|
|
1208
|
-
if (!
|
|
1209
|
-
|
|
1069
|
+
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
1070
|
+
console.error(spaceTrim__default["default"](function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
1210
1071
|
}
|
|
1211
1072
|
return {
|
|
1212
1073
|
name: name,
|
|
@@ -1732,6 +1593,34 @@
|
|
|
1732
1593
|
*/
|
|
1733
1594
|
var spaceTrim = spaceTrim$1.spaceTrim;
|
|
1734
1595
|
|
|
1596
|
+
/**
|
|
1597
|
+
* Parses the task and returns the list of all parameter names
|
|
1598
|
+
*
|
|
1599
|
+
* @param template the string template with parameters in {curly} braces
|
|
1600
|
+
* @returns the list of parameter names
|
|
1601
|
+
* @public exported from `@promptbook/utils`
|
|
1602
|
+
*/
|
|
1603
|
+
function extractParameterNames(template) {
|
|
1604
|
+
var e_1, _a;
|
|
1605
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
1606
|
+
var parameterNames = new Set();
|
|
1607
|
+
try {
|
|
1608
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
1609
|
+
var match = matches_1_1.value;
|
|
1610
|
+
var parameterName = match[0].slice(1, -1);
|
|
1611
|
+
parameterNames.add(parameterName);
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1615
|
+
finally {
|
|
1616
|
+
try {
|
|
1617
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
1618
|
+
}
|
|
1619
|
+
finally { if (e_1) throw e_1.error; }
|
|
1620
|
+
}
|
|
1621
|
+
return parameterNames;
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1735
1624
|
/**
|
|
1736
1625
|
* @@@
|
|
1737
1626
|
*
|
|
@@ -2646,8 +2535,7 @@
|
|
|
2646
2535
|
exports.deserializeError = deserializeError;
|
|
2647
2536
|
exports.difference = difference;
|
|
2648
2537
|
exports.extractParameterNames = extractParameterNames;
|
|
2649
|
-
exports.
|
|
2650
|
-
exports.extractVariables = extractVariables;
|
|
2538
|
+
exports.extractVariablesFromScript = extractVariablesFromScript;
|
|
2651
2539
|
exports.forEachAsync = forEachAsync;
|
|
2652
2540
|
exports.intersection = intersection;
|
|
2653
2541
|
exports.isHostnameOnPrivateNetwork = isHostnameOnPrivateNetwork;
|
|
@@ -2677,7 +2565,6 @@
|
|
|
2677
2565
|
exports.removeDiacritics = removeDiacritics;
|
|
2678
2566
|
exports.removeEmojis = removeEmojis;
|
|
2679
2567
|
exports.removeQuotes = removeQuotes;
|
|
2680
|
-
exports.renameParameter = renameParameter;
|
|
2681
2568
|
exports.renderPromptbookMermaid = renderPromptbookMermaid;
|
|
2682
2569
|
exports.replaceParameters = replaceParameters;
|
|
2683
2570
|
exports.searchKeywords = searchKeywords;
|