@promptbook/core 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/core`
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
@@ -25,7 +25,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- var PROMPTBOOK_ENGINE_VERSION = '0.82.0';
28
+ var PROMPTBOOK_ENGINE_VERSION = '0.83.0';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -8971,6 +8971,55 @@ var HIGH_LEVEL_ABSTRACTIONS = [
8971
8971
  var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
8972
8972
  // <- TODO: [🏥] DRY
8973
8973
 
8974
+ /**
8975
+ * Removes Markdown (or HTML) comments
8976
+ *
8977
+ * @param {string} content - The string to remove comments from.
8978
+ * @returns {string} The input string with all comments removed.
8979
+ * @public exported from `@promptbook/markdown-utils`
8980
+ */
8981
+ function removeMarkdownComments(content) {
8982
+ return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
8983
+ }
8984
+
8985
+ /**
8986
+ * @@@
8987
+ *
8988
+ * @public exported from `@promptbook/editable`
8989
+ */
8990
+ function isFlatPipeline(pipelineString) {
8991
+ pipelineString = removeMarkdownComments(pipelineString);
8992
+ pipelineString = spaceTrim(pipelineString);
8993
+ var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
8994
+ var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
8995
+ // TODO: Also (double)check
8996
+ // > const usedCommands
8997
+ // > const isBlocksUsed
8998
+ // > const returnStatementCount
8999
+ var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
9000
+ return isFlat;
9001
+ }
9002
+
9003
+ /**
9004
+ * @@@
9005
+ *
9006
+ * @public exported from `@promptbook/editable`
9007
+ */
9008
+ function deflatePipeline(pipelineString) {
9009
+ if (!isFlatPipeline(pipelineString)) {
9010
+ return pipelineString;
9011
+ }
9012
+ var pipelineStringLines = pipelineString.split('\n');
9013
+ var returnStatement = pipelineStringLines.pop();
9014
+ var prompt = spaceTrim(pipelineStringLines.join('\n'));
9015
+ 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 "); }));
9016
+ // <- TODO: Maybe use book` notation
9017
+ return pipelineString;
9018
+ }
9019
+ /**
9020
+ * TODO: Unit test
9021
+ */
9022
+
8974
9023
  /**
8975
9024
  * Utility function to extract all list items from markdown
8976
9025
  *
@@ -9186,17 +9235,6 @@ function flattenMarkdown(markdown) {
9186
9235
  * NOW we are working just with markdown string and its good enough
9187
9236
  */
9188
9237
 
9189
- /**
9190
- * Removes Markdown (or HTML) comments
9191
- *
9192
- * @param {string} content - The string to remove comments from.
9193
- * @returns {string} The input string with all comments removed.
9194
- * @public exported from `@promptbook/markdown-utils`
9195
- */
9196
- function removeMarkdownComments(content) {
9197
- return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
9198
- }
9199
-
9200
9238
  /**
9201
9239
  * @@@
9202
9240
  *
@@ -9281,26 +9319,9 @@ function parsePipeline(pipelineString) {
9281
9319
  pipelineString = removeMarkdownComments(pipelineString);
9282
9320
  pipelineString = spaceTrim$1(pipelineString);
9283
9321
  // <- TODO: [😧] `spaceTrim` should preserve discriminated type *(or at lease `PipelineString`)*
9322
+ pipelineString = deflatePipeline(pipelineString);
9284
9323
  // ==============
9285
- // Note: 1️⃣◽2️⃣ Process flat pipeline
9286
- var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
9287
- var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
9288
- // TODO: Also (double)check
9289
- // > const usedCommands
9290
- // > const isBlocksUsed
9291
- // > const returnStatementCount
9292
- var isFlatPipeline = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
9293
- // console.log({ isMarkdownBeginningWithHeadline, isLastLineReturnStatement, isFlatPipeline });
9294
- if (isFlatPipeline) {
9295
- var pipelineStringLines = pipelineString.split('\n');
9296
- var returnStatement_1 = pipelineStringLines.pop();
9297
- var prompt_1 = spaceTrim$1(pipelineStringLines.join('\n'));
9298
- 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 "); }));
9299
- // <- TODO: Maybe use book` notation
9300
- // console.log(pipelineString);
9301
- }
9302
- // ==============
9303
- // Note: 1️⃣◽3️⃣ Parse the markdown
9324
+ // Note: 1️⃣◽2️⃣ Parse the markdown
9304
9325
  pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
9305
9326
  pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
9306
9327
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');