@promptbook/cli 0.77.1 → 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 +84 -83
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +6 -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/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/utils/normalization/titleToName.test.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +84 -83
- 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/cli`
|
|
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
|
@@ -37,7 +37,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
37
37
|
*
|
|
38
38
|
* @see https://github.com/webgptorg/promptbook
|
|
39
39
|
*/
|
|
40
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.77.
|
|
40
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.77.1';
|
|
41
41
|
/**
|
|
42
42
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
43
43
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -756,6 +756,84 @@ function stringifyPipelineJson(pipeline) {
|
|
|
756
756
|
* TODO: [🍙] Make some standard order of json properties
|
|
757
757
|
*/
|
|
758
758
|
|
|
759
|
+
/**
|
|
760
|
+
* Checks if the file exists
|
|
761
|
+
*
|
|
762
|
+
* @private within the repository
|
|
763
|
+
*/
|
|
764
|
+
function isFileExisting(filename, fs) {
|
|
765
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
766
|
+
var isReadAccessAllowed, isFile;
|
|
767
|
+
return __generator(this, function (_a) {
|
|
768
|
+
switch (_a.label) {
|
|
769
|
+
case 0: return [4 /*yield*/, fs
|
|
770
|
+
.access(filename, fs.constants.R_OK)
|
|
771
|
+
.then(function () { return true; })
|
|
772
|
+
.catch(function () { return false; })];
|
|
773
|
+
case 1:
|
|
774
|
+
isReadAccessAllowed = _a.sent();
|
|
775
|
+
if (!isReadAccessAllowed) {
|
|
776
|
+
return [2 /*return*/, false];
|
|
777
|
+
}
|
|
778
|
+
return [4 /*yield*/, fs
|
|
779
|
+
.stat(filename)
|
|
780
|
+
.then(function (fileStat) { return fileStat.isFile(); })
|
|
781
|
+
.catch(function () { return false; })];
|
|
782
|
+
case 2:
|
|
783
|
+
isFile = _a.sent();
|
|
784
|
+
return [2 /*return*/, isFile];
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Note: Not [~🟢~] because it is not directly dependent on `fs
|
|
791
|
+
* TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
|
|
792
|
+
* TODO: [🖇] What about symlinks?
|
|
793
|
+
*/
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* Removes emojis from a string and fix whitespaces
|
|
797
|
+
*
|
|
798
|
+
* @param text with emojis
|
|
799
|
+
* @returns text without emojis
|
|
800
|
+
* @public exported from `@promptbook/utils`
|
|
801
|
+
*/
|
|
802
|
+
function removeEmojis(text) {
|
|
803
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
804
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
805
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
806
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
807
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
808
|
+
return text;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* Tests if given string is valid URL.
|
|
813
|
+
*
|
|
814
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
815
|
+
* @public exported from `@promptbook/utils`
|
|
816
|
+
*/
|
|
817
|
+
function isValidFilePath(filename) {
|
|
818
|
+
if (typeof filename !== 'string') {
|
|
819
|
+
return false;
|
|
820
|
+
}
|
|
821
|
+
var filenameSlashes = filename.split('\\').join('/');
|
|
822
|
+
// Absolute Unix path: /hello.txt
|
|
823
|
+
if (/^(\/)/i.test(filenameSlashes)) {
|
|
824
|
+
return true;
|
|
825
|
+
}
|
|
826
|
+
// Absolute Windows path: /hello.txt
|
|
827
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
828
|
+
return true;
|
|
829
|
+
}
|
|
830
|
+
// Relative path: ./hello.txt
|
|
831
|
+
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
832
|
+
return true;
|
|
833
|
+
}
|
|
834
|
+
return false;
|
|
835
|
+
}
|
|
836
|
+
|
|
759
837
|
/**
|
|
760
838
|
* Tests if given string is valid URL.
|
|
761
839
|
*
|
|
@@ -1108,48 +1186,6 @@ function normalizeToKebabCase(text) {
|
|
|
1108
1186
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1109
1187
|
*/
|
|
1110
1188
|
|
|
1111
|
-
/**
|
|
1112
|
-
* Removes emojis from a string and fix whitespaces
|
|
1113
|
-
*
|
|
1114
|
-
* @param text with emojis
|
|
1115
|
-
* @returns text without emojis
|
|
1116
|
-
* @public exported from `@promptbook/utils`
|
|
1117
|
-
*/
|
|
1118
|
-
function removeEmojis(text) {
|
|
1119
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
1120
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
1121
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
1122
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
1123
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
1124
|
-
return text;
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
/**
|
|
1128
|
-
* Tests if given string is valid URL.
|
|
1129
|
-
*
|
|
1130
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
1131
|
-
* @public exported from `@promptbook/utils`
|
|
1132
|
-
*/
|
|
1133
|
-
function isValidFilePath(filename) {
|
|
1134
|
-
if (typeof filename !== 'string') {
|
|
1135
|
-
return false;
|
|
1136
|
-
}
|
|
1137
|
-
var filenameSlashes = filename.split('\\').join('/');
|
|
1138
|
-
// Absolute Unix path: /hello.txt
|
|
1139
|
-
if (/^(\/)/i.test(filenameSlashes)) {
|
|
1140
|
-
return true;
|
|
1141
|
-
}
|
|
1142
|
-
// Absolute Windows path: /hello.txt
|
|
1143
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
1144
|
-
return true;
|
|
1145
|
-
}
|
|
1146
|
-
// Relative path: ./hello.txt
|
|
1147
|
-
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
1148
|
-
return true;
|
|
1149
|
-
}
|
|
1150
|
-
return false;
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
1189
|
/**
|
|
1154
1190
|
* @@@
|
|
1155
1191
|
*
|
|
@@ -1174,42 +1210,6 @@ function titleToName(value) {
|
|
|
1174
1210
|
return value;
|
|
1175
1211
|
}
|
|
1176
1212
|
|
|
1177
|
-
/**
|
|
1178
|
-
* Checks if the file exists
|
|
1179
|
-
*
|
|
1180
|
-
* @private within the repository
|
|
1181
|
-
*/
|
|
1182
|
-
function isFileExisting(filename, fs) {
|
|
1183
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1184
|
-
var isReadAccessAllowed, isFile;
|
|
1185
|
-
return __generator(this, function (_a) {
|
|
1186
|
-
switch (_a.label) {
|
|
1187
|
-
case 0: return [4 /*yield*/, fs
|
|
1188
|
-
.access(filename, fs.constants.R_OK)
|
|
1189
|
-
.then(function () { return true; })
|
|
1190
|
-
.catch(function () { return false; })];
|
|
1191
|
-
case 1:
|
|
1192
|
-
isReadAccessAllowed = _a.sent();
|
|
1193
|
-
if (!isReadAccessAllowed) {
|
|
1194
|
-
return [2 /*return*/, false];
|
|
1195
|
-
}
|
|
1196
|
-
return [4 /*yield*/, fs
|
|
1197
|
-
.stat(filename)
|
|
1198
|
-
.then(function (fileStat) { return fileStat.isFile(); })
|
|
1199
|
-
.catch(function () { return false; })];
|
|
1200
|
-
case 2:
|
|
1201
|
-
isFile = _a.sent();
|
|
1202
|
-
return [2 /*return*/, isFile];
|
|
1203
|
-
}
|
|
1204
|
-
});
|
|
1205
|
-
});
|
|
1206
|
-
}
|
|
1207
|
-
/**
|
|
1208
|
-
* Note: Not [~🟢~] because it is not directly dependent on `fs
|
|
1209
|
-
* TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
|
|
1210
|
-
* TODO: [🖇] What about symlinks?
|
|
1211
|
-
*/
|
|
1212
|
-
|
|
1213
1213
|
/**
|
|
1214
1214
|
* @@@
|
|
1215
1215
|
*
|
|
@@ -3774,9 +3774,9 @@ function serializeError(error) {
|
|
|
3774
3774
|
* @param script from which to extract the variables
|
|
3775
3775
|
* @returns the list of variable names
|
|
3776
3776
|
* @throws {ParseError} if the script is invalid
|
|
3777
|
-
* @public exported from `@promptbook/utils`
|
|
3777
|
+
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
3778
3778
|
*/
|
|
3779
|
-
function
|
|
3779
|
+
function extractVariablesFromScript(script) {
|
|
3780
3780
|
var variables = new Set();
|
|
3781
3781
|
script = "(()=>{".concat(script, "})()");
|
|
3782
3782
|
try {
|
|
@@ -3823,7 +3823,7 @@ function extractVariables(script) {
|
|
|
3823
3823
|
* @param task the task with used parameters
|
|
3824
3824
|
* @returns the set of parameter names
|
|
3825
3825
|
* @throws {ParseError} if the script is invalid
|
|
3826
|
-
* @public exported from `@promptbook/
|
|
3826
|
+
* @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
|
|
3827
3827
|
*/
|
|
3828
3828
|
function extractParameterNamesFromTask(task) {
|
|
3829
3829
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
@@ -3844,7 +3844,7 @@ function extractParameterNamesFromTask(task) {
|
|
|
3844
3844
|
}
|
|
3845
3845
|
if (taskType === 'SCRIPT_TASK') {
|
|
3846
3846
|
try {
|
|
3847
|
-
for (var _g = __values(
|
|
3847
|
+
for (var _g = __values(extractVariablesFromScript(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
3848
3848
|
var parameterName = _h.value;
|
|
3849
3849
|
parameterNames.add(parameterName);
|
|
3850
3850
|
}
|
|
@@ -8932,6 +8932,7 @@ function splitMarkdownIntoSections(markdown) {
|
|
|
8932
8932
|
var e_1, _a;
|
|
8933
8933
|
var lines = markdown.split('\n');
|
|
8934
8934
|
var sections = [];
|
|
8935
|
+
// TODO: [🧽] DRY
|
|
8935
8936
|
var currentType = 'MARKDOWN';
|
|
8936
8937
|
var buffer = [];
|
|
8937
8938
|
var finishSection = function () {
|