@promptbook/cli 0.83.0 → 0.84.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.
@@ -36,8 +36,11 @@ import type { ActionCommand } from '../commands/X_ACTION/ActionCommand';
36
36
  import { actionCommandParser } from '../commands/X_ACTION/actionCommandParser';
37
37
  import type { InstrumentCommand } from '../commands/X_INSTRUMENT/InstrumentCommand';
38
38
  import { instrumentCommandParser } from '../commands/X_INSTRUMENT/instrumentCommandParser';
39
+ import { addPipelineCommand } from '../utils/editable/edit-pipeline-string/addPipelineCommand';
40
+ import { deflatePipeline } from '../utils/editable/edit-pipeline-string/deflatePipeline';
41
+ import { removePipelineCommand } from '../utils/editable/edit-pipeline-string/removePipelineCommand';
39
42
  import type { PipelineEditableSerialized } from '../utils/editable/types/PipelineEditableSerialized';
40
- import { removePipelineCommand } from '../utils/editable/utils/removePipelineCommand';
43
+ import { isFlatPipeline } from '../utils/editable/utils/isFlatPipeline';
41
44
  import { renamePipelineParameter } from '../utils/editable/utils/renamePipelineParameter';
42
45
  import { stringifyPipelineJson } from '../utils/editable/utils/stringifyPipelineJson';
43
46
  export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION };
@@ -78,7 +81,10 @@ export type { ActionCommand };
78
81
  export { actionCommandParser };
79
82
  export type { InstrumentCommand };
80
83
  export { instrumentCommandParser };
81
- export type { PipelineEditableSerialized };
84
+ export { addPipelineCommand };
85
+ export { deflatePipeline };
82
86
  export { removePipelineCommand };
87
+ export type { PipelineEditableSerialized };
88
+ export { isFlatPipeline };
83
89
  export { renamePipelineParameter };
84
90
  export { stringifyPipelineJson };
@@ -0,0 +1,17 @@
1
+ import type { PipelineString } from '../../../pipeline/PipelineString';
2
+ import type { string_markdown_text } from '../../../types/typeAliases';
3
+ type AddPipelineCommandOptions = {
4
+ commandString: string_markdown_text;
5
+ pipelineString: PipelineString;
6
+ };
7
+ /**
8
+ * @@@
9
+ *
10
+ * @public exported from `@promptbook/editable`
11
+ */
12
+ export declare function addPipelineCommand(options: AddPipelineCommandOptions): PipelineString;
13
+ export {};
14
+ /**
15
+ * TODO: [🧠] What is the better solution - `- xxx`, - `- xxx` or preserve (see also next TODO)
16
+ * TODO: When existing commands 1) as 2) number 3) list, add 4) new command as next number
17
+ */
@@ -0,0 +1,10 @@
1
+ import type { PipelineString } from '../../../pipeline/PipelineString';
2
+ /**
3
+ * @@@
4
+ *
5
+ * @public exported from `@promptbook/editable`
6
+ */
7
+ export declare function deflatePipeline(pipelineString: PipelineString): PipelineString;
8
+ /**
9
+ * TODO: Unit test
10
+ */
@@ -11,7 +11,7 @@ type RemovePipelineCommandOptions = {
11
11
  /**
12
12
  * Pipeline you want to remove command from
13
13
  */
14
- pipeline: PipelineString;
14
+ pipelineString: PipelineString;
15
15
  };
16
16
  /**
17
17
  * Function `removePipelineCommand` will remove one command from pipeline string
@@ -0,0 +1,7 @@
1
+ import type { PipelineString } from '../../../pipeline/PipelineString';
2
+ /**
3
+ * @@@
4
+ *
5
+ * @public exported from `@promptbook/editable`
6
+ */
7
+ export declare function isFlatPipeline(pipelineString: PipelineString): boolean;
@@ -24,3 +24,6 @@ type RenameParameterOptions = {
24
24
  */
25
25
  export declare function renamePipelineParameter(options: RenameParameterOptions): PipelineJson;
26
26
  export {};
27
+ /**
28
+ * TODO: Also variant for `edit-pipeline-string`
29
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/cli",
3
- "version": "0.83.0",
3
+ "version": "0.84.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
@@ -51,7 +51,7 @@
51
51
  * @generated
52
52
  * @see https://github.com/webgptorg/promptbook
53
53
  */
54
- var PROMPTBOOK_ENGINE_VERSION = '0.82.0';
54
+ var PROMPTBOOK_ENGINE_VERSION = '0.83.0';
55
55
  /**
56
56
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
57
57
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -9630,6 +9630,55 @@
9630
9630
  var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
9631
9631
  // <- TODO: [🏥] DRY
9632
9632
 
9633
+ /**
9634
+ * Removes Markdown (or HTML) comments
9635
+ *
9636
+ * @param {string} content - The string to remove comments from.
9637
+ * @returns {string} The input string with all comments removed.
9638
+ * @public exported from `@promptbook/markdown-utils`
9639
+ */
9640
+ function removeMarkdownComments(content) {
9641
+ return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
9642
+ }
9643
+
9644
+ /**
9645
+ * @@@
9646
+ *
9647
+ * @public exported from `@promptbook/editable`
9648
+ */
9649
+ function isFlatPipeline(pipelineString) {
9650
+ pipelineString = removeMarkdownComments(pipelineString);
9651
+ pipelineString = spaceTrim__default["default"](pipelineString);
9652
+ var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
9653
+ var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
9654
+ // TODO: Also (double)check
9655
+ // > const usedCommands
9656
+ // > const isBlocksUsed
9657
+ // > const returnStatementCount
9658
+ var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
9659
+ return isFlat;
9660
+ }
9661
+
9662
+ /**
9663
+ * @@@
9664
+ *
9665
+ * @public exported from `@promptbook/editable`
9666
+ */
9667
+ function deflatePipeline(pipelineString) {
9668
+ if (!isFlatPipeline(pipelineString)) {
9669
+ return pipelineString;
9670
+ }
9671
+ var pipelineStringLines = pipelineString.split('\n');
9672
+ var returnStatement = pipelineStringLines.pop();
9673
+ var prompt = spaceTrim__default["default"](pipelineStringLines.join('\n'));
9674
+ pipelineString = validatePipelineString(spaceTrim__default["default"](function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ```\n ").concat(block(prompt), "\n ```\n\n ").concat(returnStatement, "\n "); }));
9675
+ // <- TODO: Maybe use book` notation
9676
+ return pipelineString;
9677
+ }
9678
+ /**
9679
+ * TODO: Unit test
9680
+ */
9681
+
9633
9682
  /**
9634
9683
  * Utility function to extract all list items from markdown
9635
9684
  *
@@ -9845,17 +9894,6 @@
9845
9894
  * NOW we are working just with markdown string and its good enough
9846
9895
  */
9847
9896
 
9848
- /**
9849
- * Removes Markdown (or HTML) comments
9850
- *
9851
- * @param {string} content - The string to remove comments from.
9852
- * @returns {string} The input string with all comments removed.
9853
- * @public exported from `@promptbook/markdown-utils`
9854
- */
9855
- function removeMarkdownComments(content) {
9856
- return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
9857
- }
9858
-
9859
9897
  /**
9860
9898
  * Compile pipeline from string (markdown) format to JSON format synchronously
9861
9899
  *
@@ -9916,26 +9954,9 @@
9916
9954
  pipelineString = removeMarkdownComments(pipelineString);
9917
9955
  pipelineString = spaceTrim.spaceTrim(pipelineString);
9918
9956
  // <- TODO: [😧] `spaceTrim` should preserve discriminated type *(or at lease `PipelineString`)*
9957
+ pipelineString = deflatePipeline(pipelineString);
9919
9958
  // ==============
9920
- // Note: 1️⃣◽2️⃣ Process flat pipeline
9921
- var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
9922
- var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
9923
- // TODO: Also (double)check
9924
- // > const usedCommands
9925
- // > const isBlocksUsed
9926
- // > const returnStatementCount
9927
- var isFlatPipeline = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
9928
- // console.log({ isMarkdownBeginningWithHeadline, isLastLineReturnStatement, isFlatPipeline });
9929
- if (isFlatPipeline) {
9930
- var pipelineStringLines = pipelineString.split('\n');
9931
- var returnStatement_1 = pipelineStringLines.pop();
9932
- var prompt_1 = spaceTrim.spaceTrim(pipelineStringLines.join('\n'));
9933
- pipelineString = validatePipelineString(spaceTrim.spaceTrim(function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ```\n ").concat(block(prompt_1), "\n ```\n\n ").concat(returnStatement_1, "\n "); }));
9934
- // <- TODO: Maybe use book` notation
9935
- // console.log(pipelineString);
9936
- }
9937
- // ==============
9938
- // Note: 1️⃣◽3️⃣ Parse the markdown
9959
+ // Note: 1️⃣◽2️⃣ Parse the markdown
9939
9960
  pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
9940
9961
  pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
9941
9962
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');