@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.
@@ -30,6 +30,9 @@ import { pipelineJsonToString } from '../conversion/pipelineJsonToString';
30
30
  import { pipelineStringToJson } from '../conversion/pipelineStringToJson';
31
31
  import { pipelineStringToJsonSync } from '../conversion/pipelineStringToJsonSync';
32
32
  import { prettifyPipelineString } from '../conversion/prettify/prettifyPipelineString';
33
+ import { extractParameterNamesFromTask } from '../conversion/utils/extractParameterNamesFromTask';
34
+ import { removePipelineCommand } from '../conversion/utils/removePipelineCommand';
35
+ import { renamePipelineParameter } from '../conversion/utils/renamePipelineParameter';
33
36
  import { stringifyPipelineJson } from '../conversion/utils/stringifyPipelineJson';
34
37
  import { validatePipeline } from '../conversion/validation/validatePipeline';
35
38
  import { CallbackInterfaceTools } from '../dialogs/callback/CallbackInterfaceTools';
@@ -145,6 +148,9 @@ export { pipelineJsonToString };
145
148
  export { pipelineStringToJson };
146
149
  export { pipelineStringToJsonSync };
147
150
  export { prettifyPipelineString };
151
+ export { extractParameterNamesFromTask };
152
+ export { removePipelineCommand };
153
+ export { renamePipelineParameter };
148
154
  export { stringifyPipelineJson };
149
155
  export { validatePipeline };
150
156
  export { CallbackInterfaceTools };
@@ -5,6 +5,8 @@ import type { PipelineBothCommandParser } from '../commands/_common/types/Comman
5
5
  import type { PipelineHeadCommandParser } from '../commands/_common/types/CommandParser';
6
6
  import type { PipelineTaskCommandParser } from '../commands/_common/types/CommandParser';
7
7
  import type { CommandParserInput } from '../commands/_common/types/CommandParser';
8
+ import type { CommandType } from '../commands/_common/types/CommandType';
9
+ import type { CommandTypeOrAlias } from '../commands/_common/types/CommandType';
8
10
  import type { CommandUsagePlace } from '../commands/_common/types/CommandUsagePlaces';
9
11
  import type { ExpectCommand } from '../commands/EXPECT/ExpectCommand';
10
12
  import type { ForeachJson } from '../commands/FOREACH/ForeachJson';
@@ -263,6 +265,8 @@ export type { PipelineBothCommandParser };
263
265
  export type { PipelineHeadCommandParser };
264
266
  export type { PipelineTaskCommandParser };
265
267
  export type { CommandParserInput };
268
+ export type { CommandType };
269
+ export type { CommandTypeOrAlias };
266
270
  export type { CommandUsagePlace };
267
271
  export type { ExpectCommand };
268
272
  export type { ForeachJson };
@@ -1,9 +1,6 @@
1
1
  import { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION } from '../version';
2
2
  import { renderPromptbookMermaid } from '../conversion/prettify/renderPipelineMermaidOptions';
3
- import { extractParameterNamesFromTask } from '../conversion/utils/extractParameterNamesFromTask';
4
- import { extractVariables } from '../conversion/utils/extractVariables';
5
- import { renameParameter } from '../conversion/utils/renameParameter';
6
- import { titleToName } from '../conversion/utils/titleToName';
3
+ import { extractVariablesFromScript } from '../conversion/utils/extractVariablesFromScript';
7
4
  import { deserializeError } from '../errors/utils/deserializeError';
8
5
  import { serializeError } from '../errors/utils/serializeError';
9
6
  import { forEachAsync } from '../execution/utils/forEachAsync';
@@ -45,6 +42,7 @@ import { parseKeywords } from '../utils/normalization/parseKeywords';
45
42
  import { parseKeywordsFromString } from '../utils/normalization/parseKeywordsFromString';
46
43
  import { removeDiacritics } from '../utils/normalization/removeDiacritics';
47
44
  import { searchKeywords } from '../utils/normalization/searchKeywords';
45
+ import { titleToName } from '../utils/normalization/titleToName';
48
46
  import { spaceTrim } from '../utils/organization/spaceTrim';
49
47
  import { extractParameterNames } from '../utils/parameters/extractParameterNames';
50
48
  import { replaceParameters } from '../utils/parameters/replaceParameters';
@@ -75,10 +73,7 @@ import { isValidUrl } from '../utils/validators/url/isValidUrl';
75
73
  import { isValidUuid } from '../utils/validators/uuid/isValidUuid';
76
74
  export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION };
77
75
  export { renderPromptbookMermaid };
78
- export { extractParameterNamesFromTask };
79
- export { extractVariables };
80
- export { renameParameter };
81
- export { titleToName };
76
+ export { extractVariablesFromScript };
82
77
  export { deserializeError };
83
78
  export { serializeError };
84
79
  export { forEachAsync };
@@ -120,6 +115,7 @@ export { parseKeywords };
120
115
  export { parseKeywordsFromString };
121
116
  export { removeDiacritics };
122
117
  export { searchKeywords };
118
+ export { titleToName };
123
119
  export { spaceTrim };
124
120
  export { extractParameterNames };
125
121
  export { replaceParameters };
@@ -0,0 +1,17 @@
1
+ import type { Command } from './Command';
2
+ /**
3
+ * Command is one piece of the book file section which adds some logic to the task or the whole pipeline.
4
+ * It is parsed from the markdown from ul/ol items - one command per one item.
5
+ *
6
+ * This is a type of the command like "KNOWLEDGE" or "PERSONA"
7
+ */
8
+ export type CommandType = Command['type'];
9
+ /**
10
+ * Command is one piece of the book file section which adds some logic to the task or the whole pipeline.
11
+ * It is parsed from the markdown from ul/ol items - one command per one item.
12
+ *
13
+ * This is a type of the command like "KNOWLEDGE" or "PERSONA"
14
+ *
15
+ export type CommandTypeOrAlias = Command['type'] | Command['aliasNames'] | Command['deprecatedNames'];
16
+ // <- TODO: [🧘] Implement
17
+ */
@@ -7,7 +7,7 @@ import type { string_parameter_name } from '../../types/typeAliases';
7
7
  * @param task the task with used parameters
8
8
  * @returns the set of parameter names
9
9
  * @throws {ParseError} if the script is invalid
10
- * @public exported from `@promptbook/utils`
10
+ * @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
11
11
  */
12
12
  export declare function extractParameterNamesFromTask(task: ReadonlyDeep<Pick<TaskJson, 'title' | 'description' | 'taskType' | 'content' | 'preparedContent' | 'jokerParameterNames' | 'foreach'>>): Set<string_parameter_name>;
13
13
  /**
@@ -6,9 +6,9 @@ import type { string_javascript_name } from '../../types/typeAliases';
6
6
  * @param script from which to extract the variables
7
7
  * @returns the list of variable names
8
8
  * @throws {ParseError} if the script is invalid
9
- * @public exported from `@promptbook/utils`
9
+ * @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
10
10
  */
11
- export declare function extractVariables(script: string_javascript): Set<string_javascript_name>;
11
+ export declare function extractVariablesFromScript(script: string_javascript): Set<string_javascript_name>;
12
12
  /**
13
13
  * TODO: [🔣] Support for multiple languages - python, java,...
14
14
  */
@@ -0,0 +1,22 @@
1
+ import type { CommandType } from '../../commands/_common/types/CommandType';
2
+ import type { PipelineString } from '../../pipeline/PipelineString';
3
+ /**
4
+ * Options for `removePipelineCommand`
5
+ */
6
+ type RemovePipelineCommandOptions = {
7
+ /**
8
+ * The command you want to remove
9
+ */
10
+ command: CommandType;
11
+ /**
12
+ * Pipeline you want to remove command from
13
+ */
14
+ pipeline: PipelineString;
15
+ };
16
+ /**
17
+ * Function `removePipelineCommand` will remove one command from pipeline string
18
+ *
19
+ * @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
20
+ */
21
+ export declare function removePipelineCommand(options: RemovePipelineCommandOptions): PipelineString;
22
+ export {};
@@ -16,11 +16,11 @@ type RenameParameterOptions = {
16
16
  readonly newParameterName: string_name;
17
17
  };
18
18
  /**
19
- * Function `renameParameter` will find all usable parameters for given task
19
+ * Function `renamePipelineParameter` will find all usable parameters for given task
20
20
  * In other words, it will find all parameters that are not used in the task itseld and all its dependencies
21
21
  *
22
22
  * @throws {PipelineLogicError} If the new parameter name is already used in the pipeline
23
- * @public exported from `@promptbook/utils`
23
+ * @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
24
24
  */
25
- export declare function renameParameter(options: RenameParameterOptions): PipelineJson;
25
+ export declare function renamePipelineParameter(options: RenameParameterOptions): PipelineJson;
26
26
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/cli",
3
- "version": "0.77.1",
3
+ "version": "0.78.0-0",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "--note-0": " <- [🐊]",
6
6
  "private": false,
package/umd/index.umd.js CHANGED
@@ -49,7 +49,7 @@
49
49
  *
50
50
  * @see https://github.com/webgptorg/promptbook
51
51
  */
52
- var PROMPTBOOK_ENGINE_VERSION = '0.77.0';
52
+ var PROMPTBOOK_ENGINE_VERSION = '0.77.1';
53
53
  /**
54
54
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
55
55
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -768,6 +768,84 @@
768
768
  * TODO: [🍙] Make some standard order of json properties
769
769
  */
770
770
 
771
+ /**
772
+ * Checks if the file exists
773
+ *
774
+ * @private within the repository
775
+ */
776
+ function isFileExisting(filename, fs) {
777
+ return __awaiter(this, void 0, void 0, function () {
778
+ var isReadAccessAllowed, isFile;
779
+ return __generator(this, function (_a) {
780
+ switch (_a.label) {
781
+ case 0: return [4 /*yield*/, fs
782
+ .access(filename, fs.constants.R_OK)
783
+ .then(function () { return true; })
784
+ .catch(function () { return false; })];
785
+ case 1:
786
+ isReadAccessAllowed = _a.sent();
787
+ if (!isReadAccessAllowed) {
788
+ return [2 /*return*/, false];
789
+ }
790
+ return [4 /*yield*/, fs
791
+ .stat(filename)
792
+ .then(function (fileStat) { return fileStat.isFile(); })
793
+ .catch(function () { return false; })];
794
+ case 2:
795
+ isFile = _a.sent();
796
+ return [2 /*return*/, isFile];
797
+ }
798
+ });
799
+ });
800
+ }
801
+ /**
802
+ * Note: Not [~🟢~] because it is not directly dependent on `fs
803
+ * TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
804
+ * TODO: [🖇] What about symlinks?
805
+ */
806
+
807
+ /**
808
+ * Removes emojis from a string and fix whitespaces
809
+ *
810
+ * @param text with emojis
811
+ * @returns text without emojis
812
+ * @public exported from `@promptbook/utils`
813
+ */
814
+ function removeEmojis(text) {
815
+ // Replace emojis (and also ZWJ sequence) with hyphens
816
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
817
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
818
+ text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
819
+ text = text.replace(/\p{Extended_Pictographic}/gu, '');
820
+ return text;
821
+ }
822
+
823
+ /**
824
+ * Tests if given string is valid URL.
825
+ *
826
+ * Note: This does not check if the file exists only if the path is valid
827
+ * @public exported from `@promptbook/utils`
828
+ */
829
+ function isValidFilePath(filename) {
830
+ if (typeof filename !== 'string') {
831
+ return false;
832
+ }
833
+ var filenameSlashes = filename.split('\\').join('/');
834
+ // Absolute Unix path: /hello.txt
835
+ if (/^(\/)/i.test(filenameSlashes)) {
836
+ return true;
837
+ }
838
+ // Absolute Windows path: /hello.txt
839
+ if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
840
+ return true;
841
+ }
842
+ // Relative path: ./hello.txt
843
+ if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
844
+ return true;
845
+ }
846
+ return false;
847
+ }
848
+
771
849
  /**
772
850
  * Tests if given string is valid URL.
773
851
  *
@@ -1120,48 +1198,6 @@
1120
1198
  * Note: [💞] Ignore a discrepancy between file name and entity name
1121
1199
  */
1122
1200
 
1123
- /**
1124
- * Removes emojis from a string and fix whitespaces
1125
- *
1126
- * @param text with emojis
1127
- * @returns text without emojis
1128
- * @public exported from `@promptbook/utils`
1129
- */
1130
- function removeEmojis(text) {
1131
- // Replace emojis (and also ZWJ sequence) with hyphens
1132
- text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
1133
- text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
1134
- text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
1135
- text = text.replace(/\p{Extended_Pictographic}/gu, '');
1136
- return text;
1137
- }
1138
-
1139
- /**
1140
- * Tests if given string is valid URL.
1141
- *
1142
- * Note: This does not check if the file exists only if the path is valid
1143
- * @public exported from `@promptbook/utils`
1144
- */
1145
- function isValidFilePath(filename) {
1146
- if (typeof filename !== 'string') {
1147
- return false;
1148
- }
1149
- var filenameSlashes = filename.split('\\').join('/');
1150
- // Absolute Unix path: /hello.txt
1151
- if (/^(\/)/i.test(filenameSlashes)) {
1152
- return true;
1153
- }
1154
- // Absolute Windows path: /hello.txt
1155
- if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
1156
- return true;
1157
- }
1158
- // Relative path: ./hello.txt
1159
- if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
1160
- return true;
1161
- }
1162
- return false;
1163
- }
1164
-
1165
1201
  /**
1166
1202
  * @@@
1167
1203
  *
@@ -1186,42 +1222,6 @@
1186
1222
  return value;
1187
1223
  }
1188
1224
 
1189
- /**
1190
- * Checks if the file exists
1191
- *
1192
- * @private within the repository
1193
- */
1194
- function isFileExisting(filename, fs) {
1195
- return __awaiter(this, void 0, void 0, function () {
1196
- var isReadAccessAllowed, isFile;
1197
- return __generator(this, function (_a) {
1198
- switch (_a.label) {
1199
- case 0: return [4 /*yield*/, fs
1200
- .access(filename, fs.constants.R_OK)
1201
- .then(function () { return true; })
1202
- .catch(function () { return false; })];
1203
- case 1:
1204
- isReadAccessAllowed = _a.sent();
1205
- if (!isReadAccessAllowed) {
1206
- return [2 /*return*/, false];
1207
- }
1208
- return [4 /*yield*/, fs
1209
- .stat(filename)
1210
- .then(function (fileStat) { return fileStat.isFile(); })
1211
- .catch(function () { return false; })];
1212
- case 2:
1213
- isFile = _a.sent();
1214
- return [2 /*return*/, isFile];
1215
- }
1216
- });
1217
- });
1218
- }
1219
- /**
1220
- * Note: Not [~🟢~] because it is not directly dependent on `fs
1221
- * TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
1222
- * TODO: [🖇] What about symlinks?
1223
- */
1224
-
1225
1225
  /**
1226
1226
  * @@@
1227
1227
  *
@@ -3786,9 +3786,9 @@
3786
3786
  * @param script from which to extract the variables
3787
3787
  * @returns the list of variable names
3788
3788
  * @throws {ParseError} if the script is invalid
3789
- * @public exported from `@promptbook/utils`
3789
+ * @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
3790
3790
  */
3791
- function extractVariables(script) {
3791
+ function extractVariablesFromScript(script) {
3792
3792
  var variables = new Set();
3793
3793
  script = "(()=>{".concat(script, "})()");
3794
3794
  try {
@@ -3835,7 +3835,7 @@
3835
3835
  * @param task the task with used parameters
3836
3836
  * @returns the set of parameter names
3837
3837
  * @throws {ParseError} if the script is invalid
3838
- * @public exported from `@promptbook/utils`
3838
+ * @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
3839
3839
  */
3840
3840
  function extractParameterNamesFromTask(task) {
3841
3841
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
@@ -3856,7 +3856,7 @@
3856
3856
  }
3857
3857
  if (taskType === 'SCRIPT_TASK') {
3858
3858
  try {
3859
- for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
3859
+ for (var _g = __values(extractVariablesFromScript(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
3860
3860
  var parameterName = _h.value;
3861
3861
  parameterNames.add(parameterName);
3862
3862
  }
@@ -8944,6 +8944,7 @@
8944
8944
  var e_1, _a;
8945
8945
  var lines = markdown.split('\n');
8946
8946
  var sections = [];
8947
+ // TODO: [🧽] DRY
8947
8948
  var currentType = 'MARKDOWN';
8948
8949
  var buffer = [];
8949
8950
  var finishSection = function () {