@promptbook/node 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 +2 -2
  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
@@ -28,7 +28,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- var PROMPTBOOK_ENGINE_VERSION = '0.82.0-3';
31
+ var PROMPTBOOK_ENGINE_VERSION = '0.82.0';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -5290,15 +5290,15 @@ function normalizeToKebabCase(text) {
5290
5290
  /**
5291
5291
  * Creates unique name for the source
5292
5292
  *
5293
- * @private within the repository
5293
+ * @public exported from `@promptbook/editable`
5294
5294
  */
5295
- function sourceContentToName(sourceContent) {
5296
- var hash = SHA256(hexEncoder.parse(JSON.stringify(sourceContent)))
5295
+ function knowledgeSourceContentToName(knowledgeSourceContent) {
5296
+ var hash = SHA256(hexEncoder.parse(JSON.stringify(knowledgeSourceContent)))
5297
5297
  // <- TODO: [🥬] Encapsulate sha256 to some private utility function
5298
5298
  .toString( /* hex */)
5299
5299
  .substring(0, 20);
5300
5300
  // <- TODO: [🥬] Make some system for hashes and ids of promptbook
5301
- var semanticName = normalizeToKebabCase(sourceContent.substring(0, 20));
5301
+ var semanticName = normalizeToKebabCase(knowledgeSourceContent.substring(0, 20));
5302
5302
  var pieces = ['source', semanticName, hash].filter(function (piece) { return piece !== ''; });
5303
5303
  var name = pieces.join('-').split('--').join('-');
5304
5304
  // <- TODO: Use MAX_FILENAME_LENGTH
@@ -5447,19 +5447,19 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
5447
5447
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5448
5448
  var _a;
5449
5449
  return __awaiter(this, void 0, void 0, function () {
5450
- var _b, fetch, sourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
5450
+ var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
5451
5451
  return __generator(this, function (_f) {
5452
5452
  switch (_f.label) {
5453
5453
  case 0:
5454
5454
  _b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
5455
- sourceContent = knowledgeSource.sourceContent;
5455
+ knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
5456
5456
  name = knowledgeSource.name;
5457
5457
  _c = options || {}, _d = _c.rootDirname, rootDirname = _d === void 0 ? null : _d, _c.isVerbose;
5458
5458
  if (!name) {
5459
- name = sourceContentToName(sourceContent);
5459
+ name = knowledgeSourceContentToName(knowledgeSourceContent);
5460
5460
  }
5461
- if (!isValidUrl(sourceContent)) return [3 /*break*/, 2];
5462
- url = sourceContent;
5461
+ if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 2];
5462
+ url = knowledgeSourceContent;
5463
5463
  return [4 /*yield*/, fetch(url)];
5464
5464
  case 1:
5465
5465
  response_1 = _f.sent();
@@ -5505,7 +5505,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5505
5505
  },
5506
5506
  }];
5507
5507
  case 2:
5508
- if (!isValidFilePath(sourceContent)) return [3 /*break*/, 4];
5508
+ if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 4];
5509
5509
  if (tools.fs === undefined) {
5510
5510
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
5511
5511
  // <- TODO: [🧠] What is the best error type here`
@@ -5514,13 +5514,13 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5514
5514
  throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
5515
5515
  // <- TODO: [🧠] What is the best error type here`
5516
5516
  }
5517
- filename_1 = join(rootDirname, sourceContent).split('\\').join('/');
5517
+ filename_1 = join(rootDirname, knowledgeSourceContent).split('\\').join('/');
5518
5518
  fileExtension = getFileExtension(filename_1);
5519
5519
  mimeType = extensionToMimeType(fileExtension || '');
5520
5520
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
5521
5521
  case 3:
5522
5522
  if (!(_f.sent())) {
5523
- 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 "); }));
5523
+ 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 "); }));
5524
5524
  }
5525
5525
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
5526
5526
  return [2 /*return*/, {
@@ -5571,7 +5571,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5571
5571
  url: null,
5572
5572
  mimeType: 'text/markdown',
5573
5573
  asText: function () {
5574
- return knowledgeSource.sourceContent;
5574
+ return knowledgeSource.knowledgeSourceContent;
5575
5575
  },
5576
5576
  asJson: function () {
5577
5577
  throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
@@ -5633,7 +5633,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
5633
5633
  partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
5634
5634
  return [2 /*return*/, "break"];
5635
5635
  }
5636
- 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
5636
+ 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
5637
5637
  .split('\n')
5638
5638
  .map(function (line) { return "> ".concat(line); })
5639
5639
  .join('\n')), "\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
@@ -5671,7 +5671,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
5671
5671
  return [7 /*endfinally*/];
5672
5672
  case 9:
5673
5673
  if (partialPieces === null) {
5674
- throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Cannot scrape knowledge\n\n The source:\n > ".concat(block(knowledgeSource.sourceContent
5674
+ throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Cannot scrape knowledge\n\n The source:\n > ".concat(block(knowledgeSource.knowledgeSourceContent
5675
5675
  .split('\n')
5676
5676
  .map(function (line) { return "> ".concat(line); })
5677
5677
  .join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
@@ -5942,7 +5942,7 @@ var SectionTypes = __spreadArray(__spreadArray([], __read(TaskTypes.map(function
5942
5942
  * Parses the knowledge command
5943
5943
  *
5944
5944
  * @see `documentationUrl` for more details
5945
- * @private within the commands folder
5945
+ * @public exported from `@promptbook/editable`
5946
5946
  */
5947
5947
  var knowledgeCommandParser = {
5948
5948
  /**
@@ -5978,23 +5978,25 @@ var knowledgeCommandParser = {
5978
5978
  */
5979
5979
  parse: function (input) {
5980
5980
  var args = input.args;
5981
- var sourceContent = spaceTrim(args[0] || '');
5982
- if (sourceContent === '') {
5981
+ var knowledgeSourceContent = spaceTrim(args[0] || '');
5982
+ if (knowledgeSourceContent === '') {
5983
5983
  throw new ParseError("Source is not defined");
5984
5984
  }
5985
5985
  // TODO: [main] !!4 Following checks should be applied every link in the `sourceContent`
5986
- if (sourceContent.startsWith('http://')) {
5986
+ if (knowledgeSourceContent.startsWith('http://')) {
5987
5987
  throw new ParseError("Source is not secure");
5988
5988
  }
5989
- if (!(isValidFilePath(sourceContent) || isValidUrl(sourceContent))) {
5989
+ if (!(isValidFilePath(knowledgeSourceContent) || isValidUrl(knowledgeSourceContent))) {
5990
5990
  throw new ParseError("Source not valid");
5991
5991
  }
5992
- if (sourceContent.startsWith('../') || sourceContent.startsWith('/') || /^[A-Z]:[\\/]+/i.test(sourceContent)) {
5992
+ if (knowledgeSourceContent.startsWith('../') ||
5993
+ knowledgeSourceContent.startsWith('/') ||
5994
+ /^[A-Z]:[\\/]+/i.test(knowledgeSourceContent)) {
5993
5995
  throw new ParseError("Source cannot be outside of the .book.md folder");
5994
5996
  }
5995
5997
  return {
5996
5998
  type: 'KNOWLEDGE',
5997
- sourceContent: sourceContent,
5999
+ knowledgeSourceContent: knowledgeSourceContent,
5998
6000
  };
5999
6001
  },
6000
6002
  /**
@@ -6003,10 +6005,10 @@ var knowledgeCommandParser = {
6003
6005
  * Note: `$` is used to indicate that this function mutates given `pipelineJson`
6004
6006
  */
6005
6007
  $applyToPipelineJson: function (command, $pipelineJson) {
6006
- var sourceContent = command.sourceContent;
6008
+ var knowledgeSourceContent = command.knowledgeSourceContent;
6007
6009
  $pipelineJson.knowledgeSources.push({
6008
- name: sourceContentToName(sourceContent),
6009
- sourceContent: sourceContent,
6010
+ name: knowledgeSourceContentToName(knowledgeSourceContent),
6011
+ knowledgeSourceContent: knowledgeSourceContent,
6010
6012
  });
6011
6013
  },
6012
6014
  /**
@@ -6034,7 +6036,7 @@ var knowledgeCommandParser = {
6034
6036
  * Parses the section command
6035
6037
  *
6036
6038
  * @see `documentationUrl` for more details
6037
- * @private within the commands folder
6039
+ * @public exported from `@promptbook/editable`
6038
6040
  */
6039
6041
  var sectionCommandParser = {
6040
6042
  /**
@@ -6165,7 +6167,7 @@ var sectionCommandParser = {
6165
6167
  if (command.taskType === 'KNOWLEDGE') {
6166
6168
  knowledgeCommandParser.$applyToPipelineJson({
6167
6169
  type: 'KNOWLEDGE',
6168
- sourceContent: $taskJson.content, // <- TODO: [🐝][main] !!3 Work with KNOWLEDGE which not referring to the source file or website, but its content itself
6170
+ knowledgeSourceContent: $taskJson.content, // <- TODO: [🐝][main] !!3 Work with KNOWLEDGE which not referring to the source file or website, but its content itself
6169
6171
  }, $pipelineJson);
6170
6172
  $taskJson.isTask = false;
6171
6173
  return;
@@ -6310,7 +6312,7 @@ var boilerplateCommandParser = {
6310
6312
  * Parses the BOOK_VERSION command
6311
6313
  *
6312
6314
  * @see `documentationUrl` for more details
6313
- * @private within the commands folder
6315
+ * @public exported from `@promptbook/editable`
6314
6316
  */
6315
6317
  var bookVersionCommandParser = {
6316
6318
  /**
@@ -6465,7 +6467,7 @@ function parseNumber(value) {
6465
6467
  * Parses the expect command
6466
6468
  *
6467
6469
  * @see `documentationUrl` for more details
6468
- * @private within the commands folder
6470
+ * @public exported from `@promptbook/editable`
6469
6471
  */
6470
6472
  var expectCommandParser = {
6471
6473
  /**
@@ -6797,7 +6799,7 @@ function validateParameterName(parameterName) {
6797
6799
  * Note: @@@ This command is used as foreach for new commands - it should NOT be used in any `.book.md` file
6798
6800
  *
6799
6801
  * @see `documentationUrl` for more details
6800
- * @private within the commands folder
6802
+ * @public exported from `@promptbook/editable`
6801
6803
  */
6802
6804
  var foreachCommandParser = {
6803
6805
  /**
@@ -6951,7 +6953,7 @@ var foreachCommandParser = {
6951
6953
  * Parses the format command
6952
6954
  *
6953
6955
  * @see `documentationUrl` for more details
6954
- * @private within the commands folder
6956
+ * @public exported from `@promptbook/editable`
6955
6957
  */
6956
6958
  var formatCommandParser = {
6957
6959
  /**
@@ -7248,7 +7250,7 @@ var FORMFACTOR_DEFINITIONS = [
7248
7250
  * Note: @@@ This command is used as formfactor for new commands - it should NOT be used in any `.book.md` file
7249
7251
  *
7250
7252
  * @see `documentationUrl` for more details
7251
- * @private within the commands folder
7253
+ * @public exported from `@promptbook/editable`
7252
7254
  */
7253
7255
  var formfactorCommandParser = {
7254
7256
  /**
@@ -7337,7 +7339,7 @@ var formfactorCommandParser = {
7337
7339
  * Parses the joker command
7338
7340
  *
7339
7341
  * @see `documentationUrl` for more details
7340
- * @private within the commands folder
7342
+ * @public exported from `@promptbook/editable`
7341
7343
  */
7342
7344
  var jokerCommandParser = {
7343
7345
  /**
@@ -7414,7 +7416,8 @@ var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /*
7414
7416
  * Parses the model command
7415
7417
  *
7416
7418
  * @see `documentationUrl` for more details
7417
- * @private within the commands folder
7419
+ * @deprecated Option to manually set the model requirements is not recommended to use, use `PERSONA` instead
7420
+ * @public exported from `@promptbook/editable`
7418
7421
  */
7419
7422
  var modelCommandParser = {
7420
7423
  /**
@@ -7558,7 +7561,7 @@ var modelCommandParser = {
7558
7561
  * Parses the parameter command
7559
7562
  *
7560
7563
  * @see `documentationUrl` for more details
7561
- * @private within the commands folder
7564
+ * @public exported from `@promptbook/editable`
7562
7565
  */
7563
7566
  var parameterCommandParser = {
7564
7567
  /**
@@ -7663,7 +7666,7 @@ var parameterCommandParser = {
7663
7666
  * Parses the persona command
7664
7667
  *
7665
7668
  * @see `documentationUrl` for more details
7666
- * @private within the commands folder
7669
+ * @public exported from `@promptbook/editable`
7667
7670
  */
7668
7671
  var personaCommandParser = {
7669
7672
  /**
@@ -7798,7 +7801,7 @@ function isValidJavascriptName(javascriptName) {
7798
7801
  * Parses the postprocess command
7799
7802
  *
7800
7803
  * @see `documentationUrl` for more details
7801
- * @private within the commands folder
7804
+ * @public exported from `@promptbook/editable`
7802
7805
  */
7803
7806
  var postprocessCommandParser = {
7804
7807
  /**
@@ -7876,7 +7879,7 @@ var postprocessCommandParser = {
7876
7879
  * Parses the url command
7877
7880
  *
7878
7881
  * @see `documentationUrl` for more details
7879
- * @private within the commands folder
7882
+ * @public exported from `@promptbook/editable`
7880
7883
  */
7881
7884
  var urlCommandParser = {
7882
7885
  /**
@@ -7977,7 +7980,7 @@ var urlCommandParser = {
7977
7980
  * Parses the action command
7978
7981
  *
7979
7982
  * @see `documentationUrl` for more details
7980
- * @private within the commands folder
7983
+ * @public exported from `@promptbook/editable`
7981
7984
  */
7982
7985
  var actionCommandParser = {
7983
7986
  /**
@@ -8043,7 +8046,7 @@ var actionCommandParser = {
8043
8046
  * Parses the instrument command
8044
8047
  *
8045
8048
  * @see `documentationUrl` for more details
8046
- * @private within the commands folder
8049
+ * @public exported from `@promptbook/editable`
8047
8050
  */
8048
8051
  var instrumentCommandParser = {
8049
8052
  /**
@@ -8108,7 +8111,7 @@ var instrumentCommandParser = {
8108
8111
  /**
8109
8112
  * All available command parsers
8110
8113
  *
8111
- * @private internal index of `parseCommand`
8114
+ * @public exported from `@promptbook/editable`
8112
8115
  */
8113
8116
  var COMMANDS = [
8114
8117
  sectionCommandParser,
@@ -8139,7 +8142,7 @@ var COMMANDS = [
8139
8142
  * @returns the parser for the command
8140
8143
  * @throws {UnexpectedError} if the parser is not found
8141
8144
  *
8142
- * @private within the compilePipeline
8145
+ * @public exported from `@promptbook/editable`
8143
8146
  */
8144
8147
  function getParserForCommand(command) {
8145
8148
  var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
@@ -8175,7 +8178,7 @@ function removeMarkdownFormatting(str) {
8175
8178
  * @returns parsed command object
8176
8179
  * @throws {ParseError} if the command is invalid
8177
8180
  *
8178
- * @private within the compilePipeline
8181
+ * @public exported from `@promptbook/editable`
8179
8182
  */
8180
8183
  function parseCommand(raw, usagePlace) {
8181
8184
  if (raw.includes('\n') || raw.includes('\r')) {