@promptbook/node 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.
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/node`
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
@@ -28,7 +28,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- var PROMPTBOOK_ENGINE_VERSION = '0.82.0';
31
+ var PROMPTBOOK_ENGINE_VERSION = '0.83.0';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -8619,6 +8619,55 @@ var HIGH_LEVEL_ABSTRACTIONS = [
8619
8619
  var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
8620
8620
  // <- TODO: [🏥] DRY
8621
8621
 
8622
+ /**
8623
+ * Removes Markdown (or HTML) comments
8624
+ *
8625
+ * @param {string} content - The string to remove comments from.
8626
+ * @returns {string} The input string with all comments removed.
8627
+ * @public exported from `@promptbook/markdown-utils`
8628
+ */
8629
+ function removeMarkdownComments(content) {
8630
+ return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
8631
+ }
8632
+
8633
+ /**
8634
+ * @@@
8635
+ *
8636
+ * @public exported from `@promptbook/editable`
8637
+ */
8638
+ function isFlatPipeline(pipelineString) {
8639
+ pipelineString = removeMarkdownComments(pipelineString);
8640
+ pipelineString = spaceTrim(pipelineString);
8641
+ var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
8642
+ var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
8643
+ // TODO: Also (double)check
8644
+ // > const usedCommands
8645
+ // > const isBlocksUsed
8646
+ // > const returnStatementCount
8647
+ var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
8648
+ return isFlat;
8649
+ }
8650
+
8651
+ /**
8652
+ * @@@
8653
+ *
8654
+ * @public exported from `@promptbook/editable`
8655
+ */
8656
+ function deflatePipeline(pipelineString) {
8657
+ if (!isFlatPipeline(pipelineString)) {
8658
+ return pipelineString;
8659
+ }
8660
+ var pipelineStringLines = pipelineString.split('\n');
8661
+ var returnStatement = pipelineStringLines.pop();
8662
+ var prompt = spaceTrim(pipelineStringLines.join('\n'));
8663
+ pipelineString = validatePipelineString(spaceTrim(function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ```\n ").concat(block(prompt), "\n ```\n\n ").concat(returnStatement, "\n "); }));
8664
+ // <- TODO: Maybe use book` notation
8665
+ return pipelineString;
8666
+ }
8667
+ /**
8668
+ * TODO: Unit test
8669
+ */
8670
+
8622
8671
  /**
8623
8672
  * Utility function to extract all list items from markdown
8624
8673
  *
@@ -8834,17 +8883,6 @@ function flattenMarkdown(markdown) {
8834
8883
  * NOW we are working just with markdown string and its good enough
8835
8884
  */
8836
8885
 
8837
- /**
8838
- * Removes Markdown (or HTML) comments
8839
- *
8840
- * @param {string} content - The string to remove comments from.
8841
- * @returns {string} The input string with all comments removed.
8842
- * @public exported from `@promptbook/markdown-utils`
8843
- */
8844
- function removeMarkdownComments(content) {
8845
- return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
8846
- }
8847
-
8848
8886
  /**
8849
8887
  * @@@
8850
8888
  *
@@ -8929,26 +8967,9 @@ function parsePipeline(pipelineString) {
8929
8967
  pipelineString = removeMarkdownComments(pipelineString);
8930
8968
  pipelineString = spaceTrim$1(pipelineString);
8931
8969
  // <- TODO: [😧] `spaceTrim` should preserve discriminated type *(or at lease `PipelineString`)*
8970
+ pipelineString = deflatePipeline(pipelineString);
8932
8971
  // ==============
8933
- // Note: 1️⃣◽2️⃣ Process flat pipeline
8934
- var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
8935
- var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
8936
- // TODO: Also (double)check
8937
- // > const usedCommands
8938
- // > const isBlocksUsed
8939
- // > const returnStatementCount
8940
- var isFlatPipeline = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
8941
- // console.log({ isMarkdownBeginningWithHeadline, isLastLineReturnStatement, isFlatPipeline });
8942
- if (isFlatPipeline) {
8943
- var pipelineStringLines = pipelineString.split('\n');
8944
- var returnStatement_1 = pipelineStringLines.pop();
8945
- var prompt_1 = spaceTrim$1(pipelineStringLines.join('\n'));
8946
- pipelineString = validatePipelineString(spaceTrim$1(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 "); }));
8947
- // <- TODO: Maybe use book` notation
8948
- // console.log(pipelineString);
8949
- }
8950
- // ==============
8951
- // Note: 1️⃣◽3️⃣ Parse the markdown
8972
+ // Note: 1️⃣◽2️⃣ Parse the markdown
8952
8973
  pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
8953
8974
  pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
8954
8975
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');