@promptbook/core 0.82.0 → 0.83.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.
Files changed (44) hide show
  1. package/esm/index.es.js +47 -44
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/editable.index.d.ts +74 -0
  4. package/esm/typings/src/_packages/types.index.d.ts +26 -0
  5. package/esm/typings/src/commands/BOOK_VERSION/BookVersionCommand.d.ts +1 -1
  6. package/esm/typings/src/commands/BOOK_VERSION/bookVersionCommandParser.d.ts +1 -1
  7. package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +1 -1
  8. package/esm/typings/src/commands/FOREACH/ForeachCommand.d.ts +1 -1
  9. package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +1 -1
  10. package/esm/typings/src/commands/FORMAT/formatCommandParser.d.ts +1 -1
  11. package/esm/typings/src/commands/FORMFACTOR/FormfactorCommand.d.ts +1 -1
  12. package/esm/typings/src/commands/FORMFACTOR/formfactorCommandParser.d.ts +1 -1
  13. package/esm/typings/src/commands/JOKER/JokerCommand.d.ts +1 -1
  14. package/esm/typings/src/commands/JOKER/jokerCommandParser.d.ts +1 -1
  15. package/esm/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +2 -2
  16. package/esm/typings/src/commands/KNOWLEDGE/knowledgeCommandParser.d.ts +1 -1
  17. package/esm/typings/src/commands/KNOWLEDGE/utils/{sourceContentToName.d.ts → knowledgeSourceContentToName.d.ts} +2 -2
  18. package/esm/typings/src/commands/MODEL/ModelCommand.d.ts +2 -1
  19. package/esm/typings/src/commands/MODEL/modelCommandParser.d.ts +2 -1
  20. package/esm/typings/src/commands/PARAMETER/ParameterCommand.d.ts +1 -1
  21. package/esm/typings/src/commands/PARAMETER/parameterCommandParser.d.ts +1 -1
  22. package/esm/typings/src/commands/PERSONA/PersonaCommand.d.ts +1 -1
  23. package/esm/typings/src/commands/PERSONA/personaCommandParser.d.ts +1 -1
  24. package/esm/typings/src/commands/POSTPROCESS/PostprocessCommand.d.ts +1 -1
  25. package/esm/typings/src/commands/POSTPROCESS/postprocessCommandParser.d.ts +1 -1
  26. package/esm/typings/src/commands/SECTION/SectionCommand.d.ts +1 -1
  27. package/esm/typings/src/commands/SECTION/sectionCommandParser.d.ts +1 -1
  28. package/esm/typings/src/commands/URL/UrlCommand.d.ts +1 -1
  29. package/esm/typings/src/commands/URL/urlCommandParser.d.ts +1 -1
  30. package/esm/typings/src/commands/X_ACTION/ActionCommand.d.ts +1 -1
  31. package/esm/typings/src/commands/X_ACTION/actionCommandParser.d.ts +1 -1
  32. package/esm/typings/src/commands/X_INSTRUMENT/InstrumentCommand.d.ts +1 -1
  33. package/esm/typings/src/commands/X_INSTRUMENT/instrumentCommandParser.d.ts +1 -1
  34. package/esm/typings/src/commands/_common/getParserForCommand.d.ts +1 -1
  35. package/esm/typings/src/commands/_common/parseCommand.d.ts +1 -1
  36. package/esm/typings/src/commands/_common/stringifyCommand.d.ts +1 -0
  37. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +8 -0
  38. package/esm/typings/src/commands/_common/types/CommandUsagePlaces.d.ts +2 -0
  39. package/esm/typings/src/commands/index.d.ts +1 -1
  40. package/esm/typings/src/pipeline/PipelineJson/KnowledgeSourceJson.d.ts +1 -1
  41. package/package.json +1 -1
  42. package/umd/index.umd.js +47 -44
  43. package/umd/index.umd.js.map +1 -1
  44. /package/esm/typings/src/commands/KNOWLEDGE/utils/{sourceContentToName.test.d.ts → knowledgeSourceContentToName.test.d.ts} +0 -0
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-3';
28
+ var PROMPTBOOK_ENGINE_VERSION = '0.82.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
@@ -5642,15 +5642,15 @@ function normalizeToKebabCase(text) {
5642
5642
  /**
5643
5643
  * Creates unique name for the source
5644
5644
  *
5645
- * @private within the repository
5645
+ * @public exported from `@promptbook/editable`
5646
5646
  */
5647
- function sourceContentToName(sourceContent) {
5648
- var hash = SHA256(hexEncoder.parse(JSON.stringify(sourceContent)))
5647
+ function knowledgeSourceContentToName(knowledgeSourceContent) {
5648
+ var hash = SHA256(hexEncoder.parse(JSON.stringify(knowledgeSourceContent)))
5649
5649
  // <- TODO: [🥬] Encapsulate sha256 to some private utility function
5650
5650
  .toString( /* hex */)
5651
5651
  .substring(0, 20);
5652
5652
  // <- TODO: [🥬] Make some system for hashes and ids of promptbook
5653
- var semanticName = normalizeToKebabCase(sourceContent.substring(0, 20));
5653
+ var semanticName = normalizeToKebabCase(knowledgeSourceContent.substring(0, 20));
5654
5654
  var pieces = ['source', semanticName, hash].filter(function (piece) { return piece !== ''; });
5655
5655
  var name = pieces.join('-').split('--').join('-');
5656
5656
  // <- TODO: Use MAX_FILENAME_LENGTH
@@ -5799,19 +5799,19 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
5799
5799
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5800
5800
  var _a;
5801
5801
  return __awaiter(this, void 0, void 0, function () {
5802
- var _b, fetch, sourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
5802
+ var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
5803
5803
  return __generator(this, function (_f) {
5804
5804
  switch (_f.label) {
5805
5805
  case 0:
5806
5806
  _b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
5807
- sourceContent = knowledgeSource.sourceContent;
5807
+ knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
5808
5808
  name = knowledgeSource.name;
5809
5809
  _c = options || {}, _d = _c.rootDirname, rootDirname = _d === void 0 ? null : _d, _c.isVerbose;
5810
5810
  if (!name) {
5811
- name = sourceContentToName(sourceContent);
5811
+ name = knowledgeSourceContentToName(knowledgeSourceContent);
5812
5812
  }
5813
- if (!isValidUrl(sourceContent)) return [3 /*break*/, 2];
5814
- url = sourceContent;
5813
+ if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 2];
5814
+ url = knowledgeSourceContent;
5815
5815
  return [4 /*yield*/, fetch(url)];
5816
5816
  case 1:
5817
5817
  response_1 = _f.sent();
@@ -5857,7 +5857,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5857
5857
  },
5858
5858
  }];
5859
5859
  case 2:
5860
- if (!isValidFilePath(sourceContent)) return [3 /*break*/, 4];
5860
+ if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 4];
5861
5861
  if (tools.fs === undefined) {
5862
5862
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
5863
5863
  // <- TODO: [🧠] What is the best error type here`
@@ -5866,13 +5866,13 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5866
5866
  throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
5867
5867
  // <- TODO: [🧠] What is the best error type here`
5868
5868
  }
5869
- filename_1 = join(rootDirname, sourceContent).split('\\').join('/');
5869
+ filename_1 = join(rootDirname, knowledgeSourceContent).split('\\').join('/');
5870
5870
  fileExtension = getFileExtension(filename_1);
5871
5871
  mimeType = extensionToMimeType(fileExtension || '');
5872
5872
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
5873
5873
  case 3:
5874
5874
  if (!(_f.sent())) {
5875
- throw new NotFoundError(spaceTrim(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(sourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
5875
+ throw new NotFoundError(spaceTrim(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(knowledgeSourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
5876
5876
  }
5877
5877
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
5878
5878
  return [2 /*return*/, {
@@ -5923,7 +5923,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5923
5923
  url: null,
5924
5924
  mimeType: 'text/markdown',
5925
5925
  asText: function () {
5926
- return knowledgeSource.sourceContent;
5926
+ return knowledgeSource.knowledgeSourceContent;
5927
5927
  },
5928
5928
  asJson: function () {
5929
5929
  throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
@@ -5985,7 +5985,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
5985
5985
  partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
5986
5986
  return [2 /*return*/, "break"];
5987
5987
  }
5988
- console.warn(spaceTrim(function (block) { return "\n Cannot scrape knowledge from source despite the scraper `".concat(scraper.metadata.className, "` supports the mime type \"").concat(sourceHandler.mimeType, "\".\n\n The source:\n ").concat(block(knowledgeSource.sourceContent
5988
+ console.warn(spaceTrim(function (block) { return "\n Cannot scrape knowledge from source despite the scraper `".concat(scraper.metadata.className, "` supports the mime type \"").concat(sourceHandler.mimeType, "\".\n\n The source:\n ").concat(block(knowledgeSource.knowledgeSourceContent
5989
5989
  .split('\n')
5990
5990
  .map(function (line) { return "> ".concat(line); })
5991
5991
  .join('\n')), "\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
@@ -6023,7 +6023,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
6023
6023
  return [7 /*endfinally*/];
6024
6024
  case 9:
6025
6025
  if (partialPieces === null) {
6026
- throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Cannot scrape knowledge\n\n The source:\n > ".concat(block(knowledgeSource.sourceContent
6026
+ throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Cannot scrape knowledge\n\n The source:\n > ".concat(block(knowledgeSource.knowledgeSourceContent
6027
6027
  .split('\n')
6028
6028
  .map(function (line) { return "> ".concat(line); })
6029
6029
  .join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
@@ -6294,7 +6294,7 @@ var SectionTypes = __spreadArray(__spreadArray([], __read(TaskTypes.map(function
6294
6294
  * Parses the knowledge command
6295
6295
  *
6296
6296
  * @see `documentationUrl` for more details
6297
- * @private within the commands folder
6297
+ * @public exported from `@promptbook/editable`
6298
6298
  */
6299
6299
  var knowledgeCommandParser = {
6300
6300
  /**
@@ -6330,23 +6330,25 @@ var knowledgeCommandParser = {
6330
6330
  */
6331
6331
  parse: function (input) {
6332
6332
  var args = input.args;
6333
- var sourceContent = spaceTrim(args[0] || '');
6334
- if (sourceContent === '') {
6333
+ var knowledgeSourceContent = spaceTrim(args[0] || '');
6334
+ if (knowledgeSourceContent === '') {
6335
6335
  throw new ParseError("Source is not defined");
6336
6336
  }
6337
6337
  // TODO: [main] !!4 Following checks should be applied every link in the `sourceContent`
6338
- if (sourceContent.startsWith('http://')) {
6338
+ if (knowledgeSourceContent.startsWith('http://')) {
6339
6339
  throw new ParseError("Source is not secure");
6340
6340
  }
6341
- if (!(isValidFilePath(sourceContent) || isValidUrl(sourceContent))) {
6341
+ if (!(isValidFilePath(knowledgeSourceContent) || isValidUrl(knowledgeSourceContent))) {
6342
6342
  throw new ParseError("Source not valid");
6343
6343
  }
6344
- if (sourceContent.startsWith('../') || sourceContent.startsWith('/') || /^[A-Z]:[\\/]+/i.test(sourceContent)) {
6344
+ if (knowledgeSourceContent.startsWith('../') ||
6345
+ knowledgeSourceContent.startsWith('/') ||
6346
+ /^[A-Z]:[\\/]+/i.test(knowledgeSourceContent)) {
6345
6347
  throw new ParseError("Source cannot be outside of the .book.md folder");
6346
6348
  }
6347
6349
  return {
6348
6350
  type: 'KNOWLEDGE',
6349
- sourceContent: sourceContent,
6351
+ knowledgeSourceContent: knowledgeSourceContent,
6350
6352
  };
6351
6353
  },
6352
6354
  /**
@@ -6355,10 +6357,10 @@ var knowledgeCommandParser = {
6355
6357
  * Note: `$` is used to indicate that this function mutates given `pipelineJson`
6356
6358
  */
6357
6359
  $applyToPipelineJson: function (command, $pipelineJson) {
6358
- var sourceContent = command.sourceContent;
6360
+ var knowledgeSourceContent = command.knowledgeSourceContent;
6359
6361
  $pipelineJson.knowledgeSources.push({
6360
- name: sourceContentToName(sourceContent),
6361
- sourceContent: sourceContent,
6362
+ name: knowledgeSourceContentToName(knowledgeSourceContent),
6363
+ knowledgeSourceContent: knowledgeSourceContent,
6362
6364
  });
6363
6365
  },
6364
6366
  /**
@@ -6386,7 +6388,7 @@ var knowledgeCommandParser = {
6386
6388
  * Parses the section command
6387
6389
  *
6388
6390
  * @see `documentationUrl` for more details
6389
- * @private within the commands folder
6391
+ * @public exported from `@promptbook/editable`
6390
6392
  */
6391
6393
  var sectionCommandParser = {
6392
6394
  /**
@@ -6517,7 +6519,7 @@ var sectionCommandParser = {
6517
6519
  if (command.taskType === 'KNOWLEDGE') {
6518
6520
  knowledgeCommandParser.$applyToPipelineJson({
6519
6521
  type: 'KNOWLEDGE',
6520
- sourceContent: $taskJson.content, // <- TODO: [🐝][main] !!3 Work with KNOWLEDGE which not referring to the source file or website, but its content itself
6522
+ knowledgeSourceContent: $taskJson.content, // <- TODO: [🐝][main] !!3 Work with KNOWLEDGE which not referring to the source file or website, but its content itself
6521
6523
  }, $pipelineJson);
6522
6524
  $taskJson.isTask = false;
6523
6525
  return;
@@ -6662,7 +6664,7 @@ var boilerplateCommandParser = {
6662
6664
  * Parses the BOOK_VERSION command
6663
6665
  *
6664
6666
  * @see `documentationUrl` for more details
6665
- * @private within the commands folder
6667
+ * @public exported from `@promptbook/editable`
6666
6668
  */
6667
6669
  var bookVersionCommandParser = {
6668
6670
  /**
@@ -6817,7 +6819,7 @@ function parseNumber(value) {
6817
6819
  * Parses the expect command
6818
6820
  *
6819
6821
  * @see `documentationUrl` for more details
6820
- * @private within the commands folder
6822
+ * @public exported from `@promptbook/editable`
6821
6823
  */
6822
6824
  var expectCommandParser = {
6823
6825
  /**
@@ -7149,7 +7151,7 @@ function validateParameterName(parameterName) {
7149
7151
  * Note: @@@ This command is used as foreach for new commands - it should NOT be used in any `.book.md` file
7150
7152
  *
7151
7153
  * @see `documentationUrl` for more details
7152
- * @private within the commands folder
7154
+ * @public exported from `@promptbook/editable`
7153
7155
  */
7154
7156
  var foreachCommandParser = {
7155
7157
  /**
@@ -7303,7 +7305,7 @@ var foreachCommandParser = {
7303
7305
  * Parses the format command
7304
7306
  *
7305
7307
  * @see `documentationUrl` for more details
7306
- * @private within the commands folder
7308
+ * @public exported from `@promptbook/editable`
7307
7309
  */
7308
7310
  var formatCommandParser = {
7309
7311
  /**
@@ -7600,7 +7602,7 @@ var FORMFACTOR_DEFINITIONS = [
7600
7602
  * Note: @@@ This command is used as formfactor for new commands - it should NOT be used in any `.book.md` file
7601
7603
  *
7602
7604
  * @see `documentationUrl` for more details
7603
- * @private within the commands folder
7605
+ * @public exported from `@promptbook/editable`
7604
7606
  */
7605
7607
  var formfactorCommandParser = {
7606
7608
  /**
@@ -7689,7 +7691,7 @@ var formfactorCommandParser = {
7689
7691
  * Parses the joker command
7690
7692
  *
7691
7693
  * @see `documentationUrl` for more details
7692
- * @private within the commands folder
7694
+ * @public exported from `@promptbook/editable`
7693
7695
  */
7694
7696
  var jokerCommandParser = {
7695
7697
  /**
@@ -7766,7 +7768,8 @@ var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /*
7766
7768
  * Parses the model command
7767
7769
  *
7768
7770
  * @see `documentationUrl` for more details
7769
- * @private within the commands folder
7771
+ * @deprecated Option to manually set the model requirements is not recommended to use, use `PERSONA` instead
7772
+ * @public exported from `@promptbook/editable`
7770
7773
  */
7771
7774
  var modelCommandParser = {
7772
7775
  /**
@@ -7910,7 +7913,7 @@ var modelCommandParser = {
7910
7913
  * Parses the parameter command
7911
7914
  *
7912
7915
  * @see `documentationUrl` for more details
7913
- * @private within the commands folder
7916
+ * @public exported from `@promptbook/editable`
7914
7917
  */
7915
7918
  var parameterCommandParser = {
7916
7919
  /**
@@ -8015,7 +8018,7 @@ var parameterCommandParser = {
8015
8018
  * Parses the persona command
8016
8019
  *
8017
8020
  * @see `documentationUrl` for more details
8018
- * @private within the commands folder
8021
+ * @public exported from `@promptbook/editable`
8019
8022
  */
8020
8023
  var personaCommandParser = {
8021
8024
  /**
@@ -8150,7 +8153,7 @@ function isValidJavascriptName(javascriptName) {
8150
8153
  * Parses the postprocess command
8151
8154
  *
8152
8155
  * @see `documentationUrl` for more details
8153
- * @private within the commands folder
8156
+ * @public exported from `@promptbook/editable`
8154
8157
  */
8155
8158
  var postprocessCommandParser = {
8156
8159
  /**
@@ -8228,7 +8231,7 @@ var postprocessCommandParser = {
8228
8231
  * Parses the url command
8229
8232
  *
8230
8233
  * @see `documentationUrl` for more details
8231
- * @private within the commands folder
8234
+ * @public exported from `@promptbook/editable`
8232
8235
  */
8233
8236
  var urlCommandParser = {
8234
8237
  /**
@@ -8329,7 +8332,7 @@ var urlCommandParser = {
8329
8332
  * Parses the action command
8330
8333
  *
8331
8334
  * @see `documentationUrl` for more details
8332
- * @private within the commands folder
8335
+ * @public exported from `@promptbook/editable`
8333
8336
  */
8334
8337
  var actionCommandParser = {
8335
8338
  /**
@@ -8395,7 +8398,7 @@ var actionCommandParser = {
8395
8398
  * Parses the instrument command
8396
8399
  *
8397
8400
  * @see `documentationUrl` for more details
8398
- * @private within the commands folder
8401
+ * @public exported from `@promptbook/editable`
8399
8402
  */
8400
8403
  var instrumentCommandParser = {
8401
8404
  /**
@@ -8460,7 +8463,7 @@ var instrumentCommandParser = {
8460
8463
  /**
8461
8464
  * All available command parsers
8462
8465
  *
8463
- * @private internal index of `parseCommand`
8466
+ * @public exported from `@promptbook/editable`
8464
8467
  */
8465
8468
  var COMMANDS = [
8466
8469
  sectionCommandParser,
@@ -8491,7 +8494,7 @@ var COMMANDS = [
8491
8494
  * @returns the parser for the command
8492
8495
  * @throws {UnexpectedError} if the parser is not found
8493
8496
  *
8494
- * @private within the compilePipeline
8497
+ * @public exported from `@promptbook/editable`
8495
8498
  */
8496
8499
  function getParserForCommand(command) {
8497
8500
  var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
@@ -8527,7 +8530,7 @@ function removeMarkdownFormatting(str) {
8527
8530
  * @returns parsed command object
8528
8531
  * @throws {ParseError} if the command is invalid
8529
8532
  *
8530
- * @private within the compilePipeline
8533
+ * @public exported from `@promptbook/editable`
8531
8534
  */
8532
8535
  function parseCommand(raw, usagePlace) {
8533
8536
  if (raw.includes('\n') || raw.includes('\r')) {