@promptbook/editable 0.83.0 → 0.84.0-10

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.
Files changed (37) hide show
  1. package/README.md +5 -0
  2. package/esm/index.es.js +155 -7
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/cli.index.d.ts +8 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +4 -0
  6. package/esm/typings/src/_packages/editable.index.d.ts +8 -2
  7. package/esm/typings/src/_packages/markitdown.index.d.ts +8 -0
  8. package/esm/typings/src/_packages/pdf.index.d.ts +6 -0
  9. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  10. package/esm/typings/src/_packages/wizzard.index.d.ts +8 -0
  11. package/esm/typings/src/constants.d.ts +1 -1
  12. package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +1 -1
  13. package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +1 -1
  14. package/esm/typings/src/pipeline/book-notation.d.ts +4 -0
  15. package/esm/typings/src/pipeline/prompt-notation.d.ts +18 -0
  16. package/esm/typings/src/pipeline/prompt-notation.test.d.ts +4 -0
  17. package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +43 -0
  18. package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +20 -0
  19. package/esm/typings/src/scrapers/_boilerplate/playground/boilerplate-scraper-playground.d.ts +5 -0
  20. package/esm/typings/src/scrapers/_boilerplate/register-constructor.d.ts +15 -0
  21. package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +28 -0
  22. package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +50 -0
  23. package/esm/typings/src/scrapers/markitdown/createMarkitdownScraper.d.ts +22 -0
  24. package/esm/typings/src/scrapers/markitdown/playground/markitdown-scraper-playground.d.ts +5 -0
  25. package/esm/typings/src/scrapers/markitdown/register-constructor.d.ts +17 -0
  26. package/esm/typings/src/scrapers/markitdown/register-metadata.d.ts +28 -0
  27. package/esm/typings/src/types/typeAliases.d.ts +1 -1
  28. package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +17 -0
  29. package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.d.ts +10 -0
  30. package/esm/typings/src/utils/editable/{utils → edit-pipeline-string}/removePipelineCommand.d.ts +1 -1
  31. package/esm/typings/src/utils/editable/edit-pipeline-string/removePipelineCommand.test.d.ts +1 -0
  32. package/esm/typings/src/utils/editable/utils/isFlatPipeline.d.ts +7 -0
  33. package/esm/typings/src/utils/editable/utils/renamePipelineParameter.d.ts +3 -0
  34. package/package.json +3 -3
  35. package/umd/index.umd.js +157 -6
  36. package/umd/index.umd.js.map +1 -1
  37. /package/esm/typings/src/utils/editable/{utils/removePipelineCommand.test.d.ts → edit-pipeline-string/addPipelineCommand.test.d.ts} +0 -0
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).
@@ -267,6 +271,7 @@ Or you can install them separately:
267
271
  - **[@promptbook/remote-client](https://www.npmjs.com/package/@promptbook/remote-client)** - Remote client for remote execution of promptbooks
268
272
  - **[@promptbook/remote-server](https://www.npmjs.com/package/@promptbook/remote-server)** - Remote server for remote execution of promptbooks
269
273
  - **[@promptbook/pdf](https://www.npmjs.com/package/@promptbook/pdf)** - Read knowledge from `.pdf` documents
274
+ - **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/markitdown)** - Integration of [Markitdown by Microsoft](https://github.com/microsoft/markitdown)
270
275
  - **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/documents)** - Read knowledge from documents like `.docx`, `.odt`,…
271
276
  - **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
272
277
  - **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
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.84.0-9';
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
@@ -175,13 +175,19 @@ var NAME = "Promptbook";
175
175
  *
176
176
  * @public exported from `@promptbook/core`
177
177
  */
178
- var ADMIN_EMAIL = 'me@pavolhejny.com';
178
+ var ADMIN_EMAIL = 'pavol@ptbk.io';
179
179
  /**
180
180
  * Name of the responsible person for the Promptbook on GitHub
181
181
  *
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
@@ -360,7 +366,7 @@ var boilerplateCommandParser = {
360
366
  var NotYetImplementedError = /** @class */ (function (_super) {
361
367
  __extends(NotYetImplementedError, _super);
362
368
  function NotYetImplementedError(message) {
363
- var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
369
+ var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on pavol@ptbk.io\n\n "); })) || this;
364
370
  _this.name = 'NotYetImplementedError';
365
371
  Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
366
372
  return _this;
@@ -1320,7 +1326,7 @@ function exportJson(options) {
1320
1326
  *
1321
1327
  * @private within the repository
1322
1328
  */
1323
- var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
1329
+ var REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
1324
1330
  /**
1325
1331
  * The names of the parameters that are reserved for special purposes
1326
1332
  *
@@ -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