@promptbook/editable 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/editable`
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
@@ -17,7 +17,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
17
17
  * @generated
18
18
  * @see https://github.com/webgptorg/promptbook
19
19
  */
20
- var PROMPTBOOK_ENGINE_VERSION = '0.82.0';
20
+ var PROMPTBOOK_ENGINE_VERSION = '0.83.0';
21
21
  /**
22
22
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
23
23
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -182,6 +182,12 @@ var ADMIN_EMAIL = 'me@pavolhejny.com';
182
182
  * @public exported from `@promptbook/core`
183
183
  */
184
184
  var ADMIN_GITHUB_NAME = 'hejny';
185
+ /**
186
+ * When the title is not provided, the default title is used
187
+ *
188
+ * @public exported from `@promptbook/core`
189
+ */
190
+ var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
185
191
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
186
192
  /**
187
193
  * The maximum number of iterations for a loops
@@ -3862,6 +3868,145 @@ function parseCommandVariant(input) {
3862
3868
  return null;
3863
3869
  }
3864
3870
 
3871
+ /**
3872
+ * Function `validatePipelineString` will validate the if the string is a valid pipeline string
3873
+ * It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
3874
+ *
3875
+ * @param {string} pipelineString the candidate for a pipeline string
3876
+ * @returns {PipelineString} the same string as input, but validated as valid
3877
+ * @throws {ParseError} if the string is not a valid pipeline string
3878
+ * @public exported from `@promptbook/core`
3879
+ */
3880
+ function validatePipelineString(pipelineString) {
3881
+ if (isValidJsonString(pipelineString)) {
3882
+ throw new ParseError('Expected a book, but got a JSON string');
3883
+ }
3884
+ // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
3885
+ return pipelineString;
3886
+ }
3887
+ /**
3888
+ * TODO: [🧠][🈴] Where is the best location for this file
3889
+ */
3890
+
3891
+ /**
3892
+ * Removes Markdown (or HTML) comments
3893
+ *
3894
+ * @param {string} content - The string to remove comments from.
3895
+ * @returns {string} The input string with all comments removed.
3896
+ * @public exported from `@promptbook/markdown-utils`
3897
+ */
3898
+ function removeMarkdownComments(content) {
3899
+ return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
3900
+ }
3901
+
3902
+ /**
3903
+ * @@@
3904
+ *
3905
+ * @public exported from `@promptbook/editable`
3906
+ */
3907
+ function isFlatPipeline(pipelineString) {
3908
+ pipelineString = removeMarkdownComments(pipelineString);
3909
+ pipelineString = spaceTrim(pipelineString);
3910
+ var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
3911
+ var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
3912
+ // TODO: Also (double)check
3913
+ // > const usedCommands
3914
+ // > const isBlocksUsed
3915
+ // > const returnStatementCount
3916
+ var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
3917
+ return isFlat;
3918
+ }
3919
+
3920
+ /**
3921
+ * @@@
3922
+ *
3923
+ * @public exported from `@promptbook/editable`
3924
+ */
3925
+ function deflatePipeline(pipelineString) {
3926
+ if (!isFlatPipeline(pipelineString)) {
3927
+ return pipelineString;
3928
+ }
3929
+ var pipelineStringLines = pipelineString.split('\n');
3930
+ var returnStatement = pipelineStringLines.pop();
3931
+ var prompt = spaceTrim(pipelineStringLines.join('\n'));
3932
+ 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 "); }));
3933
+ // <- TODO: Maybe use book` notation
3934
+ return pipelineString;
3935
+ }
3936
+ /**
3937
+ * TODO: Unit test
3938
+ */
3939
+
3940
+ /**
3941
+ * @@@
3942
+ *
3943
+ * @public exported from `@promptbook/editable`
3944
+ */
3945
+ function addPipelineCommand(options) {
3946
+ var e_1, _a;
3947
+ var commandString = options.commandString, pipelineString = options.pipelineString;
3948
+ var deflatedPipelineString = deflatePipeline(pipelineString);
3949
+ var lines = deflatedPipelineString.split('\n');
3950
+ var newLines = [];
3951
+ var isCommandAdded = false;
3952
+ try {
3953
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
3954
+ var line = lines_1_1.value;
3955
+ // Add command before second (or more) heading
3956
+ if (!isCommandAdded && line.startsWith('##')) {
3957
+ newLines.push("- ".concat(commandString));
3958
+ newLines.push('');
3959
+ isCommandAdded = true;
3960
+ }
3961
+ newLines.push(line);
3962
+ }
3963
+ }
3964
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3965
+ finally {
3966
+ try {
3967
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
3968
+ }
3969
+ finally { if (e_1) throw e_1.error; }
3970
+ }
3971
+ if (!isCommandAdded) {
3972
+ // Note: Only situation when this should happen is when pipeline has no tasks
3973
+ if ((newLines[newLines.length - 1] || '').startsWith('#')) {
3974
+ newLines.push('');
3975
+ }
3976
+ newLines.push("- ".concat(commandString));
3977
+ /*
3978
+ TODO: [🧠] Is this error relevant:
3979
+ throw new UnexpectedError(
3980
+ spaceTrim(
3981
+ (block) => `
3982
+ Can not add command to pipeline because there is no second heading in the pipeline
3983
+
3984
+ This should never happen because pipeline is deflated before adding command
3985
+
3986
+ The command to add:
3987
+ ${block(commandString)}
3988
+
3989
+ ---
3990
+ The original pipeline:
3991
+ ${block(pipelineString)}
3992
+
3993
+ ---
3994
+ Deflated pipeline:
3995
+ ${block(deflatedPipelineString)}
3996
+
3997
+ ---
3998
+ `,
3999
+ ),
4000
+ );
4001
+ */
4002
+ }
4003
+ return spaceTrim(newLines.join('\n'));
4004
+ }
4005
+ /**
4006
+ * TODO: [🧠] What is the better solution - `- xxx`, - `- xxx` or preserve (see also next TODO)
4007
+ * TODO: When existing commands 1) as 2) number 3) list, add 4) new command as next number
4008
+ */
4009
+
3865
4010
  /**
3866
4011
  * Function `removePipelineCommand` will remove one command from pipeline string
3867
4012
  *
@@ -3869,8 +4014,8 @@ function parseCommandVariant(input) {
3869
4014
  */
3870
4015
  function removePipelineCommand(options) {
3871
4016
  var e_1, _a;
3872
- var command = options.command, pipeline = options.pipeline;
3873
- var lines = pipeline.split('\n');
4017
+ var command = options.command, pipelineString = options.pipelineString;
4018
+ var lines = pipelineString.split('\n');
3874
4019
  // TODO: [🧽] DRY
3875
4020
  var currentType = 'MARKDOWN';
3876
4021
  var newLines = [];
@@ -3986,6 +4131,9 @@ function renamePipelineParameter(options) {
3986
4131
  }
3987
4132
  return renamedPipeline;
3988
4133
  }
4134
+ /**
4135
+ * TODO: Also variant for `edit-pipeline-string`
4136
+ */
3989
4137
 
3990
4138
  // <- TODO: Auto convert to type `import { ... } from 'type-fest';`
3991
4139
  /**
@@ -4048,5 +4196,5 @@ function stringifyPipelineJson(pipeline) {
4048
4196
  * TODO: [🍙] Make some standard order of json properties
4049
4197
  */
4050
4198
 
4051
- export { BOOK_LANGUAGE_VERSION, COMMANDS, PROMPTBOOK_ENGINE_VERSION, actionCommandParser, bookVersionCommandParser, expectCommandParser, foreachCommandParser, formatCommandParser, formfactorCommandParser, getParserForCommand, instrumentCommandParser, jokerCommandParser, knowledgeCommandParser, knowledgeSourceContentToName, modelCommandParser, parameterCommandParser, parseCommand, personaCommandParser, postprocessCommandParser, removePipelineCommand, renamePipelineParameter, sectionCommandParser, stringifyPipelineJson, urlCommandParser };
4199
+ export { BOOK_LANGUAGE_VERSION, COMMANDS, PROMPTBOOK_ENGINE_VERSION, actionCommandParser, addPipelineCommand, bookVersionCommandParser, deflatePipeline, expectCommandParser, foreachCommandParser, formatCommandParser, formfactorCommandParser, getParserForCommand, instrumentCommandParser, isFlatPipeline, jokerCommandParser, knowledgeCommandParser, knowledgeSourceContentToName, modelCommandParser, parameterCommandParser, parseCommand, personaCommandParser, postprocessCommandParser, removePipelineCommand, renamePipelineParameter, sectionCommandParser, stringifyPipelineJson, urlCommandParser };
4052
4200
  //# sourceMappingURL=index.es.js.map