@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.
@@ -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/editable",
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,
@@ -54,7 +54,7 @@
54
54
  "module": "./esm/index.es.js",
55
55
  "typings": "./esm/typings/src/_packages/editable.index.d.ts",
56
56
  "peerDependencies": {
57
- "@promptbook/core": "0.83.0"
57
+ "@promptbook/core": "0.84.0-0"
58
58
  },
59
59
  "dependencies": {
60
60
  "crypto-js": "4.2.0",
package/umd/index.umd.js CHANGED
@@ -23,7 +23,7 @@
23
23
  * @generated
24
24
  * @see https://github.com/webgptorg/promptbook
25
25
  */
26
- var PROMPTBOOK_ENGINE_VERSION = '0.82.0';
26
+ var PROMPTBOOK_ENGINE_VERSION = '0.83.0';
27
27
  /**
28
28
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
29
29
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -188,6 +188,12 @@
188
188
  * @public exported from `@promptbook/core`
189
189
  */
190
190
  var ADMIN_GITHUB_NAME = 'hejny';
191
+ /**
192
+ * When the title is not provided, the default title is used
193
+ *
194
+ * @public exported from `@promptbook/core`
195
+ */
196
+ var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
191
197
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
192
198
  /**
193
199
  * The maximum number of iterations for a loops
@@ -3868,6 +3874,145 @@
3868
3874
  return null;
3869
3875
  }
3870
3876
 
3877
+ /**
3878
+ * Function `validatePipelineString` will validate the if the string is a valid pipeline string
3879
+ * 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.
3880
+ *
3881
+ * @param {string} pipelineString the candidate for a pipeline string
3882
+ * @returns {PipelineString} the same string as input, but validated as valid
3883
+ * @throws {ParseError} if the string is not a valid pipeline string
3884
+ * @public exported from `@promptbook/core`
3885
+ */
3886
+ function validatePipelineString(pipelineString) {
3887
+ if (isValidJsonString(pipelineString)) {
3888
+ throw new ParseError('Expected a book, but got a JSON string');
3889
+ }
3890
+ // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
3891
+ return pipelineString;
3892
+ }
3893
+ /**
3894
+ * TODO: [🧠][🈴] Where is the best location for this file
3895
+ */
3896
+
3897
+ /**
3898
+ * Removes Markdown (or HTML) comments
3899
+ *
3900
+ * @param {string} content - The string to remove comments from.
3901
+ * @returns {string} The input string with all comments removed.
3902
+ * @public exported from `@promptbook/markdown-utils`
3903
+ */
3904
+ function removeMarkdownComments(content) {
3905
+ return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
3906
+ }
3907
+
3908
+ /**
3909
+ * @@@
3910
+ *
3911
+ * @public exported from `@promptbook/editable`
3912
+ */
3913
+ function isFlatPipeline(pipelineString) {
3914
+ pipelineString = removeMarkdownComments(pipelineString);
3915
+ pipelineString = spaceTrim__default["default"](pipelineString);
3916
+ var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
3917
+ var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
3918
+ // TODO: Also (double)check
3919
+ // > const usedCommands
3920
+ // > const isBlocksUsed
3921
+ // > const returnStatementCount
3922
+ var isFlat = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
3923
+ return isFlat;
3924
+ }
3925
+
3926
+ /**
3927
+ * @@@
3928
+ *
3929
+ * @public exported from `@promptbook/editable`
3930
+ */
3931
+ function deflatePipeline(pipelineString) {
3932
+ if (!isFlatPipeline(pipelineString)) {
3933
+ return pipelineString;
3934
+ }
3935
+ var pipelineStringLines = pipelineString.split('\n');
3936
+ var returnStatement = pipelineStringLines.pop();
3937
+ var prompt = spaceTrim__default["default"](pipelineStringLines.join('\n'));
3938
+ 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 "); }));
3939
+ // <- TODO: Maybe use book` notation
3940
+ return pipelineString;
3941
+ }
3942
+ /**
3943
+ * TODO: Unit test
3944
+ */
3945
+
3946
+ /**
3947
+ * @@@
3948
+ *
3949
+ * @public exported from `@promptbook/editable`
3950
+ */
3951
+ function addPipelineCommand(options) {
3952
+ var e_1, _a;
3953
+ var commandString = options.commandString, pipelineString = options.pipelineString;
3954
+ var deflatedPipelineString = deflatePipeline(pipelineString);
3955
+ var lines = deflatedPipelineString.split('\n');
3956
+ var newLines = [];
3957
+ var isCommandAdded = false;
3958
+ try {
3959
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
3960
+ var line = lines_1_1.value;
3961
+ // Add command before second (or more) heading
3962
+ if (!isCommandAdded && line.startsWith('##')) {
3963
+ newLines.push("- ".concat(commandString));
3964
+ newLines.push('');
3965
+ isCommandAdded = true;
3966
+ }
3967
+ newLines.push(line);
3968
+ }
3969
+ }
3970
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3971
+ finally {
3972
+ try {
3973
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
3974
+ }
3975
+ finally { if (e_1) throw e_1.error; }
3976
+ }
3977
+ if (!isCommandAdded) {
3978
+ // Note: Only situation when this should happen is when pipeline has no tasks
3979
+ if ((newLines[newLines.length - 1] || '').startsWith('#')) {
3980
+ newLines.push('');
3981
+ }
3982
+ newLines.push("- ".concat(commandString));
3983
+ /*
3984
+ TODO: [🧠] Is this error relevant:
3985
+ throw new UnexpectedError(
3986
+ spaceTrim(
3987
+ (block) => `
3988
+ Can not add command to pipeline because there is no second heading in the pipeline
3989
+
3990
+ This should never happen because pipeline is deflated before adding command
3991
+
3992
+ The command to add:
3993
+ ${block(commandString)}
3994
+
3995
+ ---
3996
+ The original pipeline:
3997
+ ${block(pipelineString)}
3998
+
3999
+ ---
4000
+ Deflated pipeline:
4001
+ ${block(deflatedPipelineString)}
4002
+
4003
+ ---
4004
+ `,
4005
+ ),
4006
+ );
4007
+ */
4008
+ }
4009
+ return spaceTrim__default["default"](newLines.join('\n'));
4010
+ }
4011
+ /**
4012
+ * TODO: [🧠] What is the better solution - `- xxx`, - `- xxx` or preserve (see also next TODO)
4013
+ * TODO: When existing commands 1) as 2) number 3) list, add 4) new command as next number
4014
+ */
4015
+
3871
4016
  /**
3872
4017
  * Function `removePipelineCommand` will remove one command from pipeline string
3873
4018
  *
@@ -3875,8 +4020,8 @@
3875
4020
  */
3876
4021
  function removePipelineCommand(options) {
3877
4022
  var e_1, _a;
3878
- var command = options.command, pipeline = options.pipeline;
3879
- var lines = pipeline.split('\n');
4023
+ var command = options.command, pipelineString = options.pipelineString;
4024
+ var lines = pipelineString.split('\n');
3880
4025
  // TODO: [🧽] DRY
3881
4026
  var currentType = 'MARKDOWN';
3882
4027
  var newLines = [];
@@ -3992,6 +4137,9 @@
3992
4137
  }
3993
4138
  return renamedPipeline;
3994
4139
  }
4140
+ /**
4141
+ * TODO: Also variant for `edit-pipeline-string`
4142
+ */
3995
4143
 
3996
4144
  // <- TODO: Auto convert to type `import { ... } from 'type-fest';`
3997
4145
  /**
@@ -4058,13 +4206,16 @@
4058
4206
  exports.COMMANDS = COMMANDS;
4059
4207
  exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
4060
4208
  exports.actionCommandParser = actionCommandParser;
4209
+ exports.addPipelineCommand = addPipelineCommand;
4061
4210
  exports.bookVersionCommandParser = bookVersionCommandParser;
4211
+ exports.deflatePipeline = deflatePipeline;
4062
4212
  exports.expectCommandParser = expectCommandParser;
4063
4213
  exports.foreachCommandParser = foreachCommandParser;
4064
4214
  exports.formatCommandParser = formatCommandParser;
4065
4215
  exports.formfactorCommandParser = formfactorCommandParser;
4066
4216
  exports.getParserForCommand = getParserForCommand;
4067
4217
  exports.instrumentCommandParser = instrumentCommandParser;
4218
+ exports.isFlatPipeline = isFlatPipeline;
4068
4219
  exports.jokerCommandParser = jokerCommandParser;
4069
4220
  exports.knowledgeCommandParser = knowledgeCommandParser;
4070
4221
  exports.knowledgeSourceContentToName = knowledgeSourceContentToName;