@promptbook/core 0.81.0-9 → 0.82.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.
Files changed (108) hide show
  1. package/README.md +25 -4
  2. package/esm/index.es.js +1254 -1055
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/books/index.d.ts +38 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +12 -4
  6. package/esm/typings/src/_packages/markdown-utils.index.d.ts +2 -2
  7. package/esm/typings/src/_packages/node.index.d.ts +0 -2
  8. package/esm/typings/src/_packages/remote-client.index.d.ts +7 -3
  9. package/esm/typings/src/_packages/remote-server.index.d.ts +2 -2
  10. package/esm/typings/src/_packages/templates.index.d.ts +2 -2
  11. package/esm/typings/src/_packages/types.index.d.ts +32 -30
  12. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  13. package/esm/typings/src/_packages/wizzard.index.d.ts +44 -0
  14. package/esm/typings/src/cli/cli-commands/make.d.ts +1 -1
  15. package/esm/typings/src/cli/cli-commands/run.d.ts +2 -2
  16. package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +11 -0
  17. package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
  18. package/esm/typings/src/commands/index.d.ts +1 -1
  19. package/esm/typings/src/config.d.ts +3 -3
  20. package/esm/typings/src/conversion/compilePipeline.d.ts +1 -4
  21. package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +18 -0
  22. package/esm/typings/src/conversion/{precompilePipeline.d.ts → parsePipeline.d.ts} +3 -3
  23. package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -3
  24. package/esm/typings/src/conversion/validation/validatePipeline.d.ts +7 -7
  25. package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +1 -1
  26. package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +9 -4
  27. package/esm/typings/src/formfactors/image-generator/ImageGeneratorFormfactorDefinition.d.ts +24 -0
  28. package/esm/typings/src/formfactors/index.d.ts +31 -9
  29. package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +1 -1
  30. package/esm/typings/src/high-level-abstractions/index.d.ts +3 -3
  31. package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +3 -0
  32. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
  33. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
  34. package/esm/typings/src/llm-providers/_common/register/{$provideLlmToolsForCli.d.ts → $provideLlmToolsForWizzardOrCli.d.ts} +2 -2
  35. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
  36. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
  37. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  38. package/esm/typings/src/llm-providers/anthropic-claude/createAnthropicClaudeExecutionTools.d.ts +2 -2
  39. package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +2 -2
  40. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -0
  41. package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +2 -0
  42. package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +1 -0
  43. package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -0
  44. package/esm/typings/src/llm-providers/google/register-configuration.d.ts +1 -0
  45. package/esm/typings/src/llm-providers/google/register-constructor.d.ts +1 -0
  46. package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +1 -1
  47. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -0
  48. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -0
  49. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
  50. package/esm/typings/src/llm-providers/vercel/playground/playground.d.ts +1 -1
  51. package/esm/typings/src/other/templates/getBookTemplates.d.ts +22 -0
  52. package/esm/typings/src/personas/preparePersona.d.ts +4 -4
  53. package/esm/typings/src/pipeline/PipelineString.d.ts +0 -3
  54. package/esm/typings/src/pipeline/book-notation.d.ts +14 -0
  55. package/esm/typings/src/pipeline/isValidPipelineString.d.ts +13 -0
  56. package/esm/typings/src/pipeline/isValidPipelineString.test.d.ts +4 -0
  57. package/esm/typings/src/pipeline/validatePipelineString.d.ts +14 -0
  58. package/esm/typings/src/prepare/isPipelinePrepared.d.ts +3 -1
  59. package/esm/typings/src/prepare/preparePipeline.d.ts +4 -2
  60. package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +14 -0
  61. package/esm/typings/src/prepare/prepareTasks.d.ts +1 -1
  62. package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_Error.d.ts +1 -1
  63. package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_ListModels_Request.d.ts +4 -4
  64. package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_ListModels_Response.d.ts +1 -1
  65. package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_Prompt_Progress.d.ts +1 -1
  66. package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_Prompt_Request.d.ts +5 -5
  67. package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/PromptbookServer_Prompt_Response.d.ts +1 -1
  68. package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/RemoteLlmExecutionToolsOptions.d.ts +7 -7
  69. package/esm/typings/src/{llm-providers/remote → remote-server}/interfaces/RemoteServerOptions.d.ts +10 -10
  70. package/esm/typings/src/scrapers/_common/Converter.d.ts +1 -0
  71. package/esm/typings/src/scrapers/_common/Scraper.d.ts +1 -1
  72. package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +3 -0
  73. package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +2 -0
  74. package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +3 -0
  75. package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -0
  76. package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -0
  77. package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -0
  78. package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -0
  79. package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -0
  80. package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -0
  81. package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +1 -0
  82. package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +1 -1
  83. package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -0
  84. package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +2 -1
  85. package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +3 -1
  86. package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -0
  87. package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -0
  88. package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.test.d.ts +1 -1
  89. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +2 -1
  90. package/esm/typings/src/types/typeAliases.d.ts +8 -2
  91. package/esm/typings/src/utils/markdown/flattenMarkdown.d.ts +1 -1
  92. package/esm/typings/src/utils/markdown/{removeContentComments.d.ts → removeMarkdownComments.d.ts} +2 -2
  93. package/esm/typings/src/utils/organization/$sideEffect.d.ts +9 -0
  94. package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +1 -1
  95. package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +2 -2
  96. package/esm/typings/src/utils/validators/filePath/isRootPath.d.ts +12 -0
  97. package/esm/typings/src/utils/validators/filePath/isRootPath.test.d.ts +4 -0
  98. package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +3 -0
  99. package/esm/typings/src/wizzard/$getCompiledBook.d.ts +16 -0
  100. package/esm/typings/src/wizzard/wizzard.d.ts +51 -7
  101. package/package.json +1 -1
  102. package/umd/index.umd.js +1259 -1056
  103. package/umd/index.umd.js.map +1 -1
  104. package/esm/typings/src/other/templates/getBookTemplate.d.ts +0 -21
  105. package/esm/typings/src/scripting/javascript/utils/unknownToString.d.ts +0 -8
  106. /package/esm/typings/src/conversion/{precompilePipeline.test.d.ts → parsePipeline.test.d.ts} +0 -0
  107. /package/esm/typings/src/{llm-providers/remote → remote-server}/startRemoteServer.d.ts +0 -0
  108. /package/esm/typings/src/utils/markdown/{removeContentComments.test.d.ts → removeMarkdownComments.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.81.0-8';
28
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-23';
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
@@ -177,6 +177,66 @@ function collectionToJson(collection) {
177
177
  * TODO: [🧠] Maybe clear `sourceFile` or clear when exposing through API or remote server
178
178
  */
179
179
 
180
+ /**
181
+ * Function isValidJsonString will tell you if the string is valid JSON or not
182
+ *
183
+ * @public exported from `@promptbook/utils`
184
+ */
185
+ function isValidJsonString(value /* <- [👨‍⚖️] */) {
186
+ try {
187
+ JSON.parse(value);
188
+ return true;
189
+ }
190
+ catch (error) {
191
+ if (!(error instanceof Error)) {
192
+ throw error;
193
+ }
194
+ if (error.message.includes('Unexpected token')) {
195
+ return false;
196
+ }
197
+ return false;
198
+ }
199
+ }
200
+
201
+ /**
202
+ * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
203
+ *
204
+ * @public exported from `@promptbook/core`
205
+ */
206
+ var ParseError = /** @class */ (function (_super) {
207
+ __extends(ParseError, _super);
208
+ function ParseError(message) {
209
+ var _this = _super.call(this, message) || this;
210
+ _this.name = 'ParseError';
211
+ Object.setPrototypeOf(_this, ParseError.prototype);
212
+ return _this;
213
+ }
214
+ return ParseError;
215
+ }(Error));
216
+ /**
217
+ * TODO: Maybe split `ParseError` and `ApplyError`
218
+ */
219
+
220
+ /**
221
+ * Function `validatePipelineString` will validate the if the string is a valid pipeline string
222
+ * 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.
223
+ *
224
+ * @param {string} pipelineString the candidate for a pipeline string
225
+ * @returns {PipelineString} the same string as input, but validated as valid
226
+ * @throws {ParseError} if the string is not a valid pipeline string
227
+ * @public exported from `@promptbook/core`
228
+ */
229
+ function validatePipelineString(pipelineString) {
230
+ if (isValidJsonString(pipelineString)) {
231
+ throw new ParseError('Expected a book, but got a JSON string');
232
+ }
233
+ // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
234
+ return pipelineString;
235
+ }
236
+ /**
237
+ * TODO: [🧠][🈴] Where is the best location for this file
238
+ */
239
+
180
240
  /**
181
241
  * Prettify the html code
182
242
  *
@@ -243,7 +303,7 @@ function pipelineJsonToString(pipelineJson) {
243
303
  if (bookVersion !== "undefined") {
244
304
  commands.push("BOOK VERSION ".concat(bookVersion));
245
305
  }
246
- // TODO: [main] !!!!! This increases size of the bundle and is probbably not necessary
306
+ // TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
247
307
  pipelineString = prettifyMarkdown(pipelineString);
248
308
  try {
249
309
  for (var _g = __values(parameters.filter(function (_a) {
@@ -391,12 +451,12 @@ function pipelineJsonToString(pipelineJson) {
391
451
  pipelineString += '```' + contentLanguage;
392
452
  pipelineString += '\n';
393
453
  pipelineString += spaceTrim(content);
394
- // <- TODO: [main] !!! Escape
454
+ // <- TODO: [main] !!3 Escape
395
455
  // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
396
456
  pipelineString += '\n';
397
457
  pipelineString += '```';
398
458
  pipelineString += '\n\n';
399
- pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use taskParameterJsonToString
459
+ pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
400
460
  }
401
461
  }
402
462
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
@@ -406,7 +466,7 @@ function pipelineJsonToString(pipelineJson) {
406
466
  }
407
467
  finally { if (e_3) throw e_3.error; }
408
468
  }
409
- return pipelineString;
469
+ return validatePipelineString(pipelineString);
410
470
  }
411
471
  /**
412
472
  * @private internal utility of `pipelineJsonToString`
@@ -503,7 +563,7 @@ var LOGO_DARK_SRC = "https://promptbook.studio/_next/static/media/promptbook-log
503
563
  *
504
564
  * @public exported from `@promptbook/core`
505
565
  */
506
- var DEFAULT_TITLE = "Untitled";
566
+ var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
507
567
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
508
568
  /**
509
569
  * The maximum number of iterations for a loops
@@ -564,14 +624,14 @@ var DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹‍♂️]
564
624
  var DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹‍♂️]
565
625
  /**
566
626
  * @@@
567
- * TODO: [🐝][main] !!! Use
627
+ * TODO: [🐝][main] !!3 Use
568
628
  *
569
629
  * @public exported from `@promptbook/core`
570
630
  */
571
631
  var DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH = 3;
572
632
  /**
573
633
  * @@@
574
- * TODO: [🐝][main] !!! Use
634
+ * TODO: [🐝][main] !!3 Use
575
635
  *
576
636
  * @public exported from `@promptbook/core`
577
637
  */
@@ -583,6 +643,7 @@ var DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL = 200;
583
643
  * @public exported from `@promptbook/core`
584
644
  */
585
645
  var DEFAULT_BOOKS_DIRNAME = './books';
646
+ // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
586
647
  /**
587
648
  * Where to store the cache of executions for promptbook CLI
588
649
  *
@@ -733,7 +794,7 @@ function $deepFreeze(objectValue) {
733
794
  /**
734
795
  * Make error report URL for the given error
735
796
  *
736
- * @private !!!!!!
797
+ * @private private within the repository
737
798
  */
738
799
  function getErrorReportUrl(error) {
739
800
  var report = {
@@ -854,7 +915,7 @@ function checkSerializableAsJson(options) {
854
915
  if (!(error instanceof Error)) {
855
916
  throw error;
856
917
  }
857
- throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.toString()), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
918
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.stack || error.message), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
858
919
  }
859
920
  /*
860
921
  TODO: [0] Is there some more elegant way to check circular references?
@@ -884,7 +945,7 @@ function checkSerializableAsJson(options) {
884
945
  }
885
946
  /**
886
947
  * TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
887
- * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
948
+ * TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
888
949
  * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
889
950
  */
890
951
 
@@ -896,7 +957,6 @@ function checkSerializableAsJson(options) {
896
957
  function deepClone(objectValue) {
897
958
  return JSON.parse(JSON.stringify(objectValue));
898
959
  /*
899
- !!!!!!!!
900
960
  TODO: [🧠] Is there a better implementation?
901
961
  > const propertyNames = Object.getOwnPropertyNames(objectValue);
902
962
  > for (const propertyName of propertyNames) {
@@ -1008,25 +1068,6 @@ var RESERVED_PARAMETER_NAMES = exportJson({
1008
1068
  * Note: [💞] Ignore a discrepancy between file name and entity name
1009
1069
  */
1010
1070
 
1011
- /**
1012
- * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
1013
- *
1014
- * @public exported from `@promptbook/core`
1015
- */
1016
- var ParseError = /** @class */ (function (_super) {
1017
- __extends(ParseError, _super);
1018
- function ParseError(message) {
1019
- var _this = _super.call(this, message) || this;
1020
- _this.name = 'ParseError';
1021
- Object.setPrototypeOf(_this, ParseError.prototype);
1022
- return _this;
1023
- }
1024
- return ParseError;
1025
- }(Error));
1026
- /**
1027
- * TODO: Maybe split `ParseError` and `ApplyError`
1028
- */
1029
-
1030
1071
  /**
1031
1072
  * This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
1032
1073
  *
@@ -1081,7 +1122,7 @@ function isValidPromptbookVersion(version) {
1081
1122
  if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
1082
1123
  return false;
1083
1124
  }
1084
- // <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
1125
+ // <- TODO: [main] !!3 Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
1085
1126
  return true;
1086
1127
  }
1087
1128
 
@@ -1181,9 +1222,6 @@ function isValidPipelineUrl(url) {
1181
1222
  if (!url.startsWith('https://')) {
1182
1223
  return false;
1183
1224
  }
1184
- if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
1185
- return false;
1186
- }
1187
1225
  if (url.includes('#')) {
1188
1226
  // TODO: [🐠]
1189
1227
  return false;
@@ -1214,11 +1252,11 @@ function isValidPipelineUrl(url) {
1214
1252
  */
1215
1253
  function validatePipeline(pipeline) {
1216
1254
  if (IS_PIPELINE_LOGIC_VALIDATED) {
1217
- validatePipelineCore(pipeline);
1255
+ validatePipeline_InnerFunction(pipeline);
1218
1256
  }
1219
1257
  else {
1220
1258
  try {
1221
- validatePipelineCore(pipeline);
1259
+ validatePipeline_InnerFunction(pipeline);
1222
1260
  }
1223
1261
  catch (error) {
1224
1262
  if (!(error instanceof PipelineLogicError)) {
@@ -1232,7 +1270,7 @@ function validatePipeline(pipeline) {
1232
1270
  /**
1233
1271
  * @private internal function for `validatePipeline`
1234
1272
  */
1235
- function validatePipelineCore(pipeline) {
1273
+ function validatePipeline_InnerFunction(pipeline) {
1236
1274
  // TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
1237
1275
  var e_1, _a, e_2, _b, e_3, _c;
1238
1276
  var pipelineIdentification = (function () {
@@ -1456,11 +1494,11 @@ function validatePipelineCore(pipeline) {
1456
1494
  _loop_3();
1457
1495
  }
1458
1496
  // Note: Check that formfactor is corresponding to the pipeline interface
1459
- // TODO: !!!!!! Implement this
1497
+ // TODO: !!6 Implement this
1460
1498
  // pipeline.formfactorName
1461
1499
  }
1462
1500
  /**
1463
- * TODO: !! [🧞‍♀️] Do not allow joker + foreach
1501
+ * TODO: [🧞‍♀️] Do not allow joker + foreach
1464
1502
  * TODO: [🧠] Work with promptbookVersion
1465
1503
  * TODO: Use here some json-schema, Zod or something similar and change it to:
1466
1504
  * > /**
@@ -1472,11 +1510,11 @@ function validatePipelineCore(pipeline) {
1472
1510
  * > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
1473
1511
  */
1474
1512
  /**
1475
- * TODO: [🧳][main] !!!! Validate that all examples match expectations
1476
- * TODO: [🧳][🐝][main] !!!! Validate that knowledge is valid (non-void)
1477
- * TODO: [🧳][main] !!!! Validate that persona can be used only with CHAT variant
1478
- * TODO: [🧳][main] !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
1479
- * TODO: [🧳][main] !!!! Validate that reserved parameter is not used as joker
1513
+ * TODO: [🧳][main] !!4 Validate that all examples match expectations
1514
+ * TODO: [🧳][🐝][main] !!4 Validate that knowledge is valid (non-void)
1515
+ * TODO: [🧳][main] !!4 Validate that persona can be used only with CHAT variant
1516
+ * TODO: [🧳][main] !!4 Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
1517
+ * TODO: [🧳][main] !!4 Validate that reserved parameter is not used as joker
1480
1518
  * TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
1481
1519
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
1482
1520
  */
@@ -1612,7 +1650,7 @@ var SimplePipelineCollection = /** @class */ (function () {
1612
1650
  pipelineJsonToString(unpreparePipeline(pipeline)) !==
1613
1651
  pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
1614
1652
  var existing = this.collection.get(pipeline.pipelineUrl);
1615
- throw new PipelineUrlError(spaceTrim$1("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4E\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
1653
+ throw new PipelineUrlError(spaceTrim$1("\n Pipeline with URL ".concat(pipeline.pipelineUrl, " is already in the collection \uD83C\uDF4E\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
1616
1654
  }
1617
1655
  // Note: [🧠] Overwrite existing pipeline with the same URL
1618
1656
  this.collection.set(pipeline.pipelineUrl, pipeline);
@@ -1796,7 +1834,7 @@ function createCollectionFromUrl(url, options) {
1796
1834
  });
1797
1835
  }
1798
1836
  /**
1799
- * TODO: [main] !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
1837
+ * TODO: [main] !!4 [🧠] Library precompilation and do not mix markdown and json promptbooks
1800
1838
  */
1801
1839
 
1802
1840
  /**
@@ -1866,7 +1904,7 @@ function createSubcollection(collection, predicate) {
1866
1904
  case 0: return [4 /*yield*/, collection.isResponsibleForPrompt(prompt)];
1867
1905
  case 1:
1868
1906
  isResponsible = _a.sent();
1869
- // TODO: !! Only if responsible, check if predicate is true
1907
+ // TODO: Only if responsible, check if predicate is true
1870
1908
  return [2 /*return*/, isResponsible];
1871
1909
  }
1872
1910
  });
@@ -1879,6 +1917,8 @@ function createSubcollection(collection, predicate) {
1879
1917
  };
1880
1918
  }
1881
1919
 
1920
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book.md`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n\\`\\`\\`json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n\\`\\`\\`\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book.md",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the task:\n\n> {book}\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Title starts with emoticon",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book.md`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the task:\n\n> {book}\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Title starts with emoticon\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book.md"}];
1921
+
1882
1922
  /**
1883
1923
  * This error type indicates that some tools are missing for pipeline execution or preparation
1884
1924
  *
@@ -1896,815 +1936,230 @@ var MissingToolsError = /** @class */ (function (_super) {
1896
1936
  }(Error));
1897
1937
 
1898
1938
  /**
1899
- * Async version of Array.forEach
1939
+ * This error indicates errors during the execution of the pipeline
1900
1940
  *
1901
- * @param array - Array to iterate over
1902
- * @param options - Options for the function
1903
- * @param callbackfunction - Function to call for each item
1904
- * @public exported from `@promptbook/utils`
1905
- * @deprecated [🪂] Use queues instead
1941
+ * @public exported from `@promptbook/core`
1906
1942
  */
1907
- function forEachAsync(array, options, callbackfunction) {
1908
- return __awaiter(this, void 0, void 0, function () {
1909
- var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
1910
- var e_1, _d;
1911
- return __generator(this, function (_e) {
1912
- switch (_e.label) {
1913
- case 0:
1914
- _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
1915
- index = 0;
1916
- runningTasks = [];
1917
- tasks = [];
1918
- _loop_1 = function (item) {
1919
- var currentIndex, task;
1920
- return __generator(this, function (_f) {
1921
- switch (_f.label) {
1922
- case 0:
1923
- currentIndex = index++;
1924
- task = callbackfunction(item, currentIndex, array);
1925
- tasks.push(task);
1926
- runningTasks.push(task);
1927
- /* not await */ Promise.resolve(task).then(function () {
1928
- runningTasks = runningTasks.filter(function (t) { return t !== task; });
1929
- });
1930
- if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
1931
- return [4 /*yield*/, Promise.race(runningTasks)];
1932
- case 1:
1933
- _f.sent();
1934
- _f.label = 2;
1935
- case 2: return [2 /*return*/];
1936
- }
1937
- });
1938
- };
1939
- _e.label = 1;
1940
- case 1:
1941
- _e.trys.push([1, 6, 7, 8]);
1942
- _b = __values(array), _c = _b.next();
1943
- _e.label = 2;
1944
- case 2:
1945
- if (!!_c.done) return [3 /*break*/, 5];
1946
- item = _c.value;
1947
- return [5 /*yield**/, _loop_1(item)];
1948
- case 3:
1949
- _e.sent();
1950
- _e.label = 4;
1951
- case 4:
1952
- _c = _b.next();
1953
- return [3 /*break*/, 2];
1954
- case 5: return [3 /*break*/, 8];
1955
- case 6:
1956
- e_1_1 = _e.sent();
1957
- e_1 = { error: e_1_1 };
1958
- return [3 /*break*/, 8];
1959
- case 7:
1960
- try {
1961
- if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
1962
- }
1963
- finally { if (e_1) throw e_1.error; }
1964
- return [7 /*endfinally*/];
1965
- case 8: return [4 /*yield*/, Promise.all(tasks)];
1966
- case 9:
1967
- _e.sent();
1968
- return [2 /*return*/];
1969
- }
1970
- });
1971
- });
1972
- }
1943
+ var PipelineExecutionError = /** @class */ (function (_super) {
1944
+ __extends(PipelineExecutionError, _super);
1945
+ function PipelineExecutionError(message) {
1946
+ var _this = _super.call(this, message) || this;
1947
+ _this.name = 'PipelineExecutionError';
1948
+ Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
1949
+ return _this;
1950
+ }
1951
+ return PipelineExecutionError;
1952
+ }(Error));
1973
1953
 
1974
1954
  /**
1975
- * Represents the usage with no resources consumed
1955
+ * This error indicates problems parsing the format value
1956
+ *
1957
+ * For example, when the format value is not a valid JSON or CSV
1958
+ * This is not thrown directly but in extended classes
1976
1959
  *
1977
1960
  * @public exported from `@promptbook/core`
1978
1961
  */
1979
- var ZERO_USAGE = $deepFreeze({
1980
- price: { value: 0 },
1981
- input: {
1982
- tokensCount: { value: 0 },
1983
- charactersCount: { value: 0 },
1984
- wordsCount: { value: 0 },
1985
- sentencesCount: { value: 0 },
1986
- linesCount: { value: 0 },
1987
- paragraphsCount: { value: 0 },
1988
- pagesCount: { value: 0 },
1989
- },
1990
- output: {
1991
- tokensCount: { value: 0 },
1992
- charactersCount: { value: 0 },
1993
- wordsCount: { value: 0 },
1994
- sentencesCount: { value: 0 },
1995
- linesCount: { value: 0 },
1996
- paragraphsCount: { value: 0 },
1997
- pagesCount: { value: 0 },
1998
- },
1999
- });
1962
+ var AbstractFormatError = /** @class */ (function (_super) {
1963
+ __extends(AbstractFormatError, _super);
1964
+ // Note: To allow instanceof do not put here error `name`
1965
+ // public readonly name = 'AbstractFormatError';
1966
+ function AbstractFormatError(message) {
1967
+ var _this = _super.call(this, message) || this;
1968
+ Object.setPrototypeOf(_this, AbstractFormatError.prototype);
1969
+ return _this;
1970
+ }
1971
+ return AbstractFormatError;
1972
+ }(Error));
1973
+
2000
1974
  /**
2001
- * Represents the usage with unknown resources consumed
1975
+ * This error indicates problem with parsing of CSV
2002
1976
  *
2003
1977
  * @public exported from `@promptbook/core`
2004
1978
  */
2005
- var UNCERTAIN_USAGE = $deepFreeze({
2006
- price: { value: 0, isUncertain: true },
2007
- input: {
2008
- tokensCount: { value: 0, isUncertain: true },
2009
- charactersCount: { value: 0, isUncertain: true },
2010
- wordsCount: { value: 0, isUncertain: true },
2011
- sentencesCount: { value: 0, isUncertain: true },
2012
- linesCount: { value: 0, isUncertain: true },
2013
- paragraphsCount: { value: 0, isUncertain: true },
2014
- pagesCount: { value: 0, isUncertain: true },
2015
- },
2016
- output: {
2017
- tokensCount: { value: 0, isUncertain: true },
2018
- charactersCount: { value: 0, isUncertain: true },
2019
- wordsCount: { value: 0, isUncertain: true },
2020
- sentencesCount: { value: 0, isUncertain: true },
2021
- linesCount: { value: 0, isUncertain: true },
2022
- paragraphsCount: { value: 0, isUncertain: true },
2023
- pagesCount: { value: 0, isUncertain: true },
2024
- },
2025
- });
1979
+ var CsvFormatError = /** @class */ (function (_super) {
1980
+ __extends(CsvFormatError, _super);
1981
+ function CsvFormatError(message) {
1982
+ var _this = _super.call(this, message) || this;
1983
+ _this.name = 'CsvFormatError';
1984
+ Object.setPrototypeOf(_this, CsvFormatError.prototype);
1985
+ return _this;
1986
+ }
1987
+ return CsvFormatError;
1988
+ }(AbstractFormatError));
1989
+
2026
1990
  /**
2027
- * Note: [💞] Ignore a discrepancy between file name and entity name
1991
+ * This error indicates that the pipeline collection cannot be propperly loaded
1992
+ *
1993
+ * @public exported from `@promptbook/core`
2028
1994
  */
1995
+ var CollectionError = /** @class */ (function (_super) {
1996
+ __extends(CollectionError, _super);
1997
+ function CollectionError(message) {
1998
+ var _this = _super.call(this, message) || this;
1999
+ _this.name = 'CollectionError';
2000
+ Object.setPrototypeOf(_this, CollectionError.prototype);
2001
+ return _this;
2002
+ }
2003
+ return CollectionError;
2004
+ }(Error));
2029
2005
 
2030
2006
  /**
2031
- * Function `addUsage` will add multiple usages into one
2032
- *
2033
- * Note: If you provide 0 values, it returns ZERO_USAGE
2007
+ * This error type indicates that you try to use a feature that is not available in the current environment
2034
2008
  *
2035
2009
  * @public exported from `@promptbook/core`
2036
2010
  */
2037
- function addUsage() {
2038
- var usageItems = [];
2039
- for (var _i = 0; _i < arguments.length; _i++) {
2040
- usageItems[_i] = arguments[_i];
2041
- }
2042
- return usageItems.reduce(function (acc, item) {
2043
- var e_1, _a, e_2, _b;
2044
- var _c;
2045
- acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
2046
- try {
2047
- for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
2048
- var key = _e.value;
2049
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2050
- //@ts-ignore
2051
- if (item.input[key]) {
2052
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2053
- //@ts-ignore
2054
- acc.input[key].value += item.input[key].value || 0;
2055
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2056
- //@ts-ignore
2057
- if (item.input[key].isUncertain) {
2058
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2059
- //@ts-ignore
2060
- acc.input[key].isUncertain = true;
2061
- }
2062
- }
2063
- }
2064
- }
2065
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2066
- finally {
2067
- try {
2068
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
2069
- }
2070
- finally { if (e_1) throw e_1.error; }
2071
- }
2072
- try {
2073
- for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
2074
- var key = _g.value;
2075
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2076
- //@ts-ignore
2077
- if (item.output[key]) {
2078
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2079
- //@ts-ignore
2080
- acc.output[key].value += item.output[key].value || 0;
2081
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2082
- //@ts-ignore
2083
- if (item.output[key].isUncertain) {
2084
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2085
- //@ts-ignore
2086
- acc.output[key].isUncertain = true;
2087
- }
2088
- }
2089
- }
2090
- }
2091
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
2092
- finally {
2093
- try {
2094
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
2095
- }
2096
- finally { if (e_2) throw e_2.error; }
2097
- }
2098
- return acc;
2099
- }, deepClone(ZERO_USAGE));
2100
- }
2011
+ var EnvironmentMismatchError = /** @class */ (function (_super) {
2012
+ __extends(EnvironmentMismatchError, _super);
2013
+ function EnvironmentMismatchError(message) {
2014
+ var _this = _super.call(this, message) || this;
2015
+ _this.name = 'EnvironmentMismatchError';
2016
+ Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
2017
+ return _this;
2018
+ }
2019
+ return EnvironmentMismatchError;
2020
+ }(Error));
2101
2021
 
2102
2022
  /**
2103
- * Intercepts LLM tools and counts total usage of the tools
2023
+ * This error occurs when some expectation is not met in the execution of the pipeline
2104
2024
  *
2105
- * @param llmTools LLM tools to be intercepted with usage counting
2106
- * @returns LLM tools with same functionality with added total cost counting
2107
2025
  * @public exported from `@promptbook/core`
2026
+ * Note: Do not throw this error, its reserved for `checkExpectations` and `createPipelineExecutor` and public ONLY to be serializable through remote server
2027
+ * Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
2028
+ * Note: This is a kindof subtype of PipelineExecutionError
2108
2029
  */
2109
- function countTotalUsage(llmTools) {
2110
- var _this = this;
2111
- var totalUsage = ZERO_USAGE;
2112
- var proxyTools = {
2113
- get title() {
2114
- // TODO: [🧠] Maybe put here some suffix
2115
- return llmTools.title;
2116
- },
2117
- get description() {
2118
- // TODO: [🧠] Maybe put here some suffix
2119
- return llmTools.description;
2120
- },
2121
- checkConfiguration: function () {
2122
- return __awaiter(this, void 0, void 0, function () {
2123
- return __generator(this, function (_a) {
2124
- return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
2125
- });
2126
- });
2127
- },
2128
- listModels: function () {
2129
- return /* not await */ llmTools.listModels();
2130
- },
2131
- getTotalUsage: function () {
2132
- // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
2133
- return totalUsage;
2134
- },
2135
- };
2136
- if (llmTools.callChatModel !== undefined) {
2137
- proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
2138
- var promptResult;
2139
- return __generator(this, function (_a) {
2140
- switch (_a.label) {
2141
- case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
2142
- case 1:
2143
- promptResult = _a.sent();
2144
- totalUsage = addUsage(totalUsage, promptResult.usage);
2145
- return [2 /*return*/, promptResult];
2146
- }
2147
- });
2148
- }); };
2149
- }
2150
- if (llmTools.callCompletionModel !== undefined) {
2151
- proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
2152
- var promptResult;
2153
- return __generator(this, function (_a) {
2154
- switch (_a.label) {
2155
- case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
2156
- case 1:
2157
- promptResult = _a.sent();
2158
- totalUsage = addUsage(totalUsage, promptResult.usage);
2159
- return [2 /*return*/, promptResult];
2160
- }
2161
- });
2162
- }); };
2163
- }
2164
- if (llmTools.callEmbeddingModel !== undefined) {
2165
- proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
2166
- var promptResult;
2167
- return __generator(this, function (_a) {
2168
- switch (_a.label) {
2169
- case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
2170
- case 1:
2171
- promptResult = _a.sent();
2172
- totalUsage = addUsage(totalUsage, promptResult.usage);
2173
- return [2 /*return*/, promptResult];
2174
- }
2175
- });
2176
- }); };
2030
+ var ExpectError = /** @class */ (function (_super) {
2031
+ __extends(ExpectError, _super);
2032
+ function ExpectError(message) {
2033
+ var _this = _super.call(this, message) || this;
2034
+ _this.name = 'ExpectError';
2035
+ Object.setPrototypeOf(_this, ExpectError.prototype);
2036
+ return _this;
2177
2037
  }
2178
- // <- Note: [🤖]
2179
- return proxyTools;
2180
- }
2038
+ return ExpectError;
2039
+ }(Error));
2040
+
2181
2041
  /**
2182
- * TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
2183
- * TODO: [🧠] Is there some meaningfull way how to test this util
2184
- * TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
2185
- * > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
2186
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2042
+ * This error indicates that the promptbook can not retrieve knowledge from external sources
2043
+ *
2044
+ * @public exported from `@promptbook/core`
2187
2045
  */
2046
+ var KnowledgeScrapeError = /** @class */ (function (_super) {
2047
+ __extends(KnowledgeScrapeError, _super);
2048
+ function KnowledgeScrapeError(message) {
2049
+ var _this = _super.call(this, message) || this;
2050
+ _this.name = 'KnowledgeScrapeError';
2051
+ Object.setPrototypeOf(_this, KnowledgeScrapeError.prototype);
2052
+ return _this;
2053
+ }
2054
+ return KnowledgeScrapeError;
2055
+ }(Error));
2188
2056
 
2189
2057
  /**
2190
- * This error indicates errors during the execution of the pipeline
2058
+ * This error type indicates that some limit was reached
2191
2059
  *
2192
2060
  * @public exported from `@promptbook/core`
2193
2061
  */
2194
- var PipelineExecutionError = /** @class */ (function (_super) {
2195
- __extends(PipelineExecutionError, _super);
2196
- function PipelineExecutionError(message) {
2062
+ var LimitReachedError = /** @class */ (function (_super) {
2063
+ __extends(LimitReachedError, _super);
2064
+ function LimitReachedError(message) {
2197
2065
  var _this = _super.call(this, message) || this;
2198
- _this.name = 'PipelineExecutionError';
2199
- Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
2066
+ _this.name = 'LimitReachedError';
2067
+ Object.setPrototypeOf(_this, LimitReachedError.prototype);
2200
2068
  return _this;
2201
2069
  }
2202
- return PipelineExecutionError;
2070
+ return LimitReachedError;
2203
2071
  }(Error));
2204
2072
 
2205
2073
  /**
2206
- * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
2074
+ * This error type indicates that some part of the code is not implemented yet
2207
2075
  *
2208
- * Note: Internal utility of `joinLlmExecutionTools` but exposed type
2209
2076
  * @public exported from `@promptbook/core`
2210
2077
  */
2211
- var MultipleLlmExecutionTools = /** @class */ (function () {
2212
- /**
2213
- * Gets array of execution tools in order of priority
2214
- */
2215
- function MultipleLlmExecutionTools() {
2216
- var llmExecutionTools = [];
2217
- for (var _i = 0; _i < arguments.length; _i++) {
2218
- llmExecutionTools[_i] = arguments[_i];
2219
- }
2220
- this.llmExecutionTools = llmExecutionTools;
2078
+ var NotYetImplementedError = /** @class */ (function (_super) {
2079
+ __extends(NotYetImplementedError, _super);
2080
+ function NotYetImplementedError(message) {
2081
+ 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;
2082
+ _this.name = 'NotYetImplementedError';
2083
+ Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
2084
+ return _this;
2221
2085
  }
2222
- Object.defineProperty(MultipleLlmExecutionTools.prototype, "title", {
2223
- get: function () {
2224
- return 'Multiple LLM Providers';
2225
- },
2226
- enumerable: false,
2227
- configurable: true
2228
- });
2229
- Object.defineProperty(MultipleLlmExecutionTools.prototype, "description", {
2230
- get: function () {
2231
- return this.llmExecutionTools.map(function (_a, index) {
2232
- var title = _a.title;
2233
- return "".concat(index + 1, ") `").concat(title, "`");
2234
- }).join('\n');
2235
- },
2236
- enumerable: false,
2237
- configurable: true
2238
- });
2239
- /**
2240
- * Check the configuration of all execution tools
2241
- */
2242
- MultipleLlmExecutionTools.prototype.checkConfiguration = function () {
2243
- return __awaiter(this, void 0, void 0, function () {
2244
- var _a, _b, llmExecutionTools, e_1_1;
2245
- var e_1, _c;
2246
- return __generator(this, function (_d) {
2247
- switch (_d.label) {
2248
- case 0:
2249
- _d.trys.push([0, 5, 6, 7]);
2250
- _a = __values(this.llmExecutionTools), _b = _a.next();
2251
- _d.label = 1;
2252
- case 1:
2253
- if (!!_b.done) return [3 /*break*/, 4];
2254
- llmExecutionTools = _b.value;
2255
- return [4 /*yield*/, llmExecutionTools.checkConfiguration()];
2256
- case 2:
2257
- _d.sent();
2258
- _d.label = 3;
2259
- case 3:
2260
- _b = _a.next();
2261
- return [3 /*break*/, 1];
2262
- case 4: return [3 /*break*/, 7];
2263
- case 5:
2264
- e_1_1 = _d.sent();
2265
- e_1 = { error: e_1_1 };
2266
- return [3 /*break*/, 7];
2267
- case 6:
2268
- try {
2269
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
2270
- }
2271
- finally { if (e_1) throw e_1.error; }
2272
- return [7 /*endfinally*/];
2273
- case 7: return [2 /*return*/];
2274
- }
2275
- });
2276
- });
2277
- };
2278
- /**
2279
- * List all available models that can be used
2280
- * This lists is a combination of all available models from all execution tools
2281
- */
2282
- MultipleLlmExecutionTools.prototype.listModels = function () {
2283
- return __awaiter(this, void 0, void 0, function () {
2284
- var availableModels, _a, _b, llmExecutionTools, models, e_2_1;
2285
- var e_2, _c;
2286
- return __generator(this, function (_d) {
2287
- switch (_d.label) {
2288
- case 0:
2289
- availableModels = [];
2290
- _d.label = 1;
2291
- case 1:
2292
- _d.trys.push([1, 6, 7, 8]);
2293
- _a = __values(this.llmExecutionTools), _b = _a.next();
2294
- _d.label = 2;
2295
- case 2:
2296
- if (!!_b.done) return [3 /*break*/, 5];
2297
- llmExecutionTools = _b.value;
2298
- return [4 /*yield*/, llmExecutionTools.listModels()];
2299
- case 3:
2300
- models = _d.sent();
2301
- availableModels.push.apply(availableModels, __spreadArray([], __read(models), false));
2302
- _d.label = 4;
2303
- case 4:
2304
- _b = _a.next();
2305
- return [3 /*break*/, 2];
2306
- case 5: return [3 /*break*/, 8];
2307
- case 6:
2308
- e_2_1 = _d.sent();
2309
- e_2 = { error: e_2_1 };
2310
- return [3 /*break*/, 8];
2311
- case 7:
2312
- try {
2313
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
2314
- }
2315
- finally { if (e_2) throw e_2.error; }
2316
- return [7 /*endfinally*/];
2317
- case 8: return [2 /*return*/, availableModels];
2318
- }
2319
- });
2320
- });
2321
- };
2322
- /**
2323
- * Calls the best available chat model
2324
- */
2325
- MultipleLlmExecutionTools.prototype.callChatModel = function (prompt) {
2326
- return this.callCommonModel(prompt);
2327
- };
2328
- /**
2329
- * Calls the best available completion model
2330
- */
2331
- MultipleLlmExecutionTools.prototype.callCompletionModel = function (prompt) {
2332
- return this.callCommonModel(prompt);
2333
- };
2334
- /**
2335
- * Calls the best available embedding model
2336
- */
2337
- MultipleLlmExecutionTools.prototype.callEmbeddingModel = function (prompt) {
2338
- return this.callCommonModel(prompt);
2339
- };
2340
- // <- Note: [🤖]
2341
- /**
2342
- * Calls the best available model
2343
- *
2344
- * Note: This should be private or protected but is public to be usable with duck typing
2345
- */
2346
- MultipleLlmExecutionTools.prototype.callCommonModel = function (prompt) {
2347
- return __awaiter(this, void 0, void 0, function () {
2348
- var errors, _a, _b, llmExecutionTools, _c, error_1, e_3_1;
2349
- var e_3, _d;
2350
- var _this = this;
2351
- return __generator(this, function (_e) {
2352
- switch (_e.label) {
2353
- case 0:
2354
- errors = [];
2355
- _e.label = 1;
2356
- case 1:
2357
- _e.trys.push([1, 15, 16, 17]);
2358
- _a = __values(this.llmExecutionTools), _b = _a.next();
2359
- _e.label = 2;
2360
- case 2:
2361
- if (!!_b.done) return [3 /*break*/, 14];
2362
- llmExecutionTools = _b.value;
2363
- _e.label = 3;
2364
- case 3:
2365
- _e.trys.push([3, 12, , 13]);
2366
- _c = prompt.modelRequirements.modelVariant;
2367
- switch (_c) {
2368
- case 'CHAT': return [3 /*break*/, 4];
2369
- case 'COMPLETION': return [3 /*break*/, 6];
2370
- case 'EMBEDDING': return [3 /*break*/, 8];
2371
- }
2372
- return [3 /*break*/, 10];
2373
- case 4:
2374
- if (llmExecutionTools.callChatModel === undefined) {
2375
- return [3 /*break*/, 13];
2376
- }
2377
- return [4 /*yield*/, llmExecutionTools.callChatModel(prompt)];
2378
- case 5: return [2 /*return*/, _e.sent()];
2379
- case 6:
2380
- if (llmExecutionTools.callCompletionModel === undefined) {
2381
- return [3 /*break*/, 13];
2382
- }
2383
- return [4 /*yield*/, llmExecutionTools.callCompletionModel(prompt)];
2384
- case 7: return [2 /*return*/, _e.sent()];
2385
- case 8:
2386
- if (llmExecutionTools.callEmbeddingModel === undefined) {
2387
- return [3 /*break*/, 13];
2388
- }
2389
- return [4 /*yield*/, llmExecutionTools.callEmbeddingModel(prompt)];
2390
- case 9: return [2 /*return*/, _e.sent()];
2391
- case 10: throw new UnexpectedError("Unknown model variant \"".concat(prompt.modelRequirements.modelVariant, "\""));
2392
- case 11: return [3 /*break*/, 13];
2393
- case 12:
2394
- error_1 = _e.sent();
2395
- if (!(error_1 instanceof Error) || error_1 instanceof UnexpectedError) {
2396
- throw error_1;
2397
- }
2398
- errors.push(error_1);
2399
- return [3 /*break*/, 13];
2400
- case 13:
2401
- _b = _a.next();
2402
- return [3 /*break*/, 2];
2403
- case 14: return [3 /*break*/, 17];
2404
- case 15:
2405
- e_3_1 = _e.sent();
2406
- e_3 = { error: e_3_1 };
2407
- return [3 /*break*/, 17];
2408
- case 16:
2409
- try {
2410
- if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
2411
- }
2412
- finally { if (e_3) throw e_3.error; }
2413
- return [7 /*endfinally*/];
2414
- case 17:
2415
- if (errors.length === 1) {
2416
- throw errors[0];
2417
- }
2418
- else if (errors.length > 1) {
2419
- throw new PipelineExecutionError(
2420
- // TODO: Tell which execution tools failed like
2421
- // 1) OpenAI throw PipelineExecutionError: Parameter `{knowledge}` is not defined
2422
- // 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
2423
- // 3) ...
2424
- spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
2425
- .map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
2426
- .join('\n')), "\n\n "); }));
2427
- }
2428
- else if (this.llmExecutionTools.length === 0) {
2429
- throw new PipelineExecutionError("You have not provided any `LlmExecutionTools`");
2430
- }
2431
- else {
2432
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\"\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.description), "\n\n "); }));
2433
- }
2434
- }
2435
- });
2436
- });
2437
- };
2438
- return MultipleLlmExecutionTools;
2439
- }());
2440
- /**
2441
- * TODO: [🧠][🎛] Aggregating multiple models - have result not only from one first aviable model BUT all of them
2442
- * TODO: [🏖] If no llmTools have for example not defined `callCompletionModel` this will still return object with defined `callCompletionModel` which just throws `PipelineExecutionError`, make it undefined instead
2443
- * Look how `countTotalUsage` (and `cacheLlmTools`) implements it
2444
- */
2086
+ return NotYetImplementedError;
2087
+ }(Error));
2445
2088
 
2446
2089
  /**
2447
- * Joins multiple LLM Execution Tools into one
2090
+ * Index of all custom errors
2448
2091
  *
2449
- * @returns {LlmExecutionTools} Single wrapper for multiple LlmExecutionTools
2092
+ * @public exported from `@promptbook/core`
2093
+ */
2094
+ var PROMPTBOOK_ERRORS = {
2095
+ AbstractFormatError: AbstractFormatError,
2096
+ CsvFormatError: CsvFormatError,
2097
+ CollectionError: CollectionError,
2098
+ EnvironmentMismatchError: EnvironmentMismatchError,
2099
+ ExpectError: ExpectError,
2100
+ KnowledgeScrapeError: KnowledgeScrapeError,
2101
+ LimitReachedError: LimitReachedError,
2102
+ MissingToolsError: MissingToolsError,
2103
+ NotFoundError: NotFoundError,
2104
+ NotYetImplementedError: NotYetImplementedError,
2105
+ ParseError: ParseError,
2106
+ PipelineExecutionError: PipelineExecutionError,
2107
+ PipelineLogicError: PipelineLogicError,
2108
+ PipelineUrlError: PipelineUrlError,
2109
+ UnexpectedError: UnexpectedError,
2110
+ // TODO: [🪑]> VersionMismatchError,
2111
+ };
2112
+ /**
2113
+ * Index of all javascript errors
2450
2114
  *
2451
- * 0) If there is no LlmExecutionTools, it warns and returns valid but empty LlmExecutionTools
2452
- * 1) If there is only one LlmExecutionTools, it returns it wrapped in a proxy object
2453
- * 2) If there are multiple LlmExecutionTools, first will be used first, second will be used if the first hasn`t defined model variant or fails, etc.
2454
- * 3) When all LlmExecutionTools fail, it throws an error with a list of all errors merged into one
2115
+ * @private for internal usage
2116
+ */
2117
+ var COMMON_JAVASCRIPT_ERRORS = {
2118
+ Error: Error,
2119
+ EvalError: EvalError,
2120
+ RangeError: RangeError,
2121
+ ReferenceError: ReferenceError,
2122
+ SyntaxError: SyntaxError,
2123
+ TypeError: TypeError,
2124
+ URIError: URIError,
2125
+ AggregateError: AggregateError,
2126
+ /*
2127
+ Note: Not widely supported
2128
+ > InternalError,
2129
+ > ModuleError,
2130
+ > HeapError,
2131
+ > WebAssemblyCompileError,
2132
+ > WebAssemblyRuntimeError,
2133
+ */
2134
+ };
2135
+ /**
2136
+ * Index of all errors
2455
2137
  *
2138
+ * @private for internal usage
2139
+ */
2140
+ var ALL_ERRORS = __assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
2141
+ /**
2142
+ * Note: [💞] Ignore a discrepancy between file name and entity name
2143
+ */
2144
+
2145
+ /**
2146
+ * Deserializes the error object
2456
2147
  *
2457
- * Tip: You don't have to use this function directly, just pass an array of LlmExecutionTools to the `ExecutionTools`
2148
+ * @public exported from `@promptbook/utils`
2149
+ */
2150
+ function deserializeError(error) {
2151
+ var ErrorClass = ALL_ERRORS[error.name];
2152
+ if (ErrorClass === undefined) {
2153
+ return new Error("".concat(error.name, ": ").concat(error.message));
2154
+ }
2155
+ return new ErrorClass(error.message);
2156
+ }
2157
+
2158
+ /**
2159
+ * Asserts that the execution of a Promptbook is successful
2458
2160
  *
2459
- * @public exported from `@promptbook/core`
2460
- */
2461
- function joinLlmExecutionTools() {
2462
- var llmExecutionTools = [];
2463
- for (var _i = 0; _i < arguments.length; _i++) {
2464
- llmExecutionTools[_i] = arguments[_i];
2465
- }
2466
- if (llmExecutionTools.length === 0) {
2467
- var warningMessage = spaceTrim("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
2468
- // TODO: [🟥] Detect browser / node and make it colorfull
2469
- console.warn(warningMessage);
2470
- /*
2471
- return {
2472
- async listModels() {
2473
- // TODO: [🟥] Detect browser / node and make it colorfull
2474
- console.warn(
2475
- spaceTrim(
2476
- (block) => `
2477
-
2478
- You can't list models because you have no LLM Execution Tools defined:
2479
-
2480
- tl;dr
2481
-
2482
- ${block(warningMessage)}
2483
- `,
2484
- ),
2485
- );
2486
- return [];
2487
- },
2488
- };
2489
- */
2490
- }
2491
- return new (MultipleLlmExecutionTools.bind.apply(MultipleLlmExecutionTools, __spreadArray([void 0], __read(llmExecutionTools), false)))();
2492
- }
2493
- /**
2494
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2495
- */
2496
-
2497
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book.md`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n\\`\\`\\`json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n\\`\\`\\`\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book.md"}];
2498
-
2499
- /**
2500
- * This error indicates problems parsing the format value
2501
- *
2502
- * For example, when the format value is not a valid JSON or CSV
2503
- * This is not thrown directly but in extended classes
2504
- *
2505
- * @public exported from `@promptbook/core`
2506
- */
2507
- var AbstractFormatError = /** @class */ (function (_super) {
2508
- __extends(AbstractFormatError, _super);
2509
- // Note: To allow instanceof do not put here error `name`
2510
- // public readonly name = 'AbstractFormatError';
2511
- function AbstractFormatError(message) {
2512
- var _this = _super.call(this, message) || this;
2513
- Object.setPrototypeOf(_this, AbstractFormatError.prototype);
2514
- return _this;
2515
- }
2516
- return AbstractFormatError;
2517
- }(Error));
2518
-
2519
- /**
2520
- * This error indicates problem with parsing of CSV
2521
- *
2522
- * @public exported from `@promptbook/core`
2523
- */
2524
- var CsvFormatError = /** @class */ (function (_super) {
2525
- __extends(CsvFormatError, _super);
2526
- function CsvFormatError(message) {
2527
- var _this = _super.call(this, message) || this;
2528
- _this.name = 'CsvFormatError';
2529
- Object.setPrototypeOf(_this, CsvFormatError.prototype);
2530
- return _this;
2531
- }
2532
- return CsvFormatError;
2533
- }(AbstractFormatError));
2534
-
2535
- /**
2536
- * This error indicates that the pipeline collection cannot be propperly loaded
2537
- *
2538
- * @public exported from `@promptbook/core`
2539
- */
2540
- var CollectionError = /** @class */ (function (_super) {
2541
- __extends(CollectionError, _super);
2542
- function CollectionError(message) {
2543
- var _this = _super.call(this, message) || this;
2544
- _this.name = 'CollectionError';
2545
- Object.setPrototypeOf(_this, CollectionError.prototype);
2546
- return _this;
2547
- }
2548
- return CollectionError;
2549
- }(Error));
2550
-
2551
- /**
2552
- * This error type indicates that you try to use a feature that is not available in the current environment
2553
- *
2554
- * @public exported from `@promptbook/core`
2555
- */
2556
- var EnvironmentMismatchError = /** @class */ (function (_super) {
2557
- __extends(EnvironmentMismatchError, _super);
2558
- function EnvironmentMismatchError(message) {
2559
- var _this = _super.call(this, message) || this;
2560
- _this.name = 'EnvironmentMismatchError';
2561
- Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
2562
- return _this;
2563
- }
2564
- return EnvironmentMismatchError;
2565
- }(Error));
2566
-
2567
- /**
2568
- * This error occurs when some expectation is not met in the execution of the pipeline
2569
- *
2570
- * @public exported from `@promptbook/core`
2571
- * Note: Do not throw this error, its reserved for `checkExpectations` and `createPipelineExecutor` and public ONLY to be serializable through remote server
2572
- * Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
2573
- * Note: This is a kindof subtype of PipelineExecutionError
2574
- */
2575
- var ExpectError = /** @class */ (function (_super) {
2576
- __extends(ExpectError, _super);
2577
- function ExpectError(message) {
2578
- var _this = _super.call(this, message) || this;
2579
- _this.name = 'ExpectError';
2580
- Object.setPrototypeOf(_this, ExpectError.prototype);
2581
- return _this;
2582
- }
2583
- return ExpectError;
2584
- }(Error));
2585
-
2586
- /**
2587
- * This error indicates that the promptbook can not retrieve knowledge from external sources
2588
- *
2589
- * @public exported from `@promptbook/core`
2590
- */
2591
- var KnowledgeScrapeError = /** @class */ (function (_super) {
2592
- __extends(KnowledgeScrapeError, _super);
2593
- function KnowledgeScrapeError(message) {
2594
- var _this = _super.call(this, message) || this;
2595
- _this.name = 'KnowledgeScrapeError';
2596
- Object.setPrototypeOf(_this, KnowledgeScrapeError.prototype);
2597
- return _this;
2598
- }
2599
- return KnowledgeScrapeError;
2600
- }(Error));
2601
-
2602
- /**
2603
- * This error type indicates that some limit was reached
2604
- *
2605
- * @public exported from `@promptbook/core`
2606
- */
2607
- var LimitReachedError = /** @class */ (function (_super) {
2608
- __extends(LimitReachedError, _super);
2609
- function LimitReachedError(message) {
2610
- var _this = _super.call(this, message) || this;
2611
- _this.name = 'LimitReachedError';
2612
- Object.setPrototypeOf(_this, LimitReachedError.prototype);
2613
- return _this;
2614
- }
2615
- return LimitReachedError;
2616
- }(Error));
2617
-
2618
- /**
2619
- * This error type indicates that some part of the code is not implemented yet
2620
- *
2621
- * @public exported from `@promptbook/core`
2622
- */
2623
- var NotYetImplementedError = /** @class */ (function (_super) {
2624
- __extends(NotYetImplementedError, _super);
2625
- function NotYetImplementedError(message) {
2626
- 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;
2627
- _this.name = 'NotYetImplementedError';
2628
- Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
2629
- return _this;
2630
- }
2631
- return NotYetImplementedError;
2632
- }(Error));
2633
-
2634
- /**
2635
- * Index of all custom errors
2636
- *
2637
- * @public exported from `@promptbook/core`
2638
- */
2639
- var PROMPTBOOK_ERRORS = {
2640
- AbstractFormatError: AbstractFormatError,
2641
- CsvFormatError: CsvFormatError,
2642
- CollectionError: CollectionError,
2643
- EnvironmentMismatchError: EnvironmentMismatchError,
2644
- ExpectError: ExpectError,
2645
- KnowledgeScrapeError: KnowledgeScrapeError,
2646
- LimitReachedError: LimitReachedError,
2647
- MissingToolsError: MissingToolsError,
2648
- NotFoundError: NotFoundError,
2649
- NotYetImplementedError: NotYetImplementedError,
2650
- ParseError: ParseError,
2651
- PipelineExecutionError: PipelineExecutionError,
2652
- PipelineLogicError: PipelineLogicError,
2653
- PipelineUrlError: PipelineUrlError,
2654
- UnexpectedError: UnexpectedError,
2655
- // TODO: [🪑]> VersionMismatchError,
2656
- };
2657
- /**
2658
- * Index of all javascript errors
2659
- *
2660
- * @private for internal usage
2661
- */
2662
- var COMMON_JAVASCRIPT_ERRORS = {
2663
- Error: Error,
2664
- EvalError: EvalError,
2665
- RangeError: RangeError,
2666
- ReferenceError: ReferenceError,
2667
- SyntaxError: SyntaxError,
2668
- TypeError: TypeError,
2669
- URIError: URIError,
2670
- AggregateError: AggregateError,
2671
- /*
2672
- Note: Not widely supported
2673
- > InternalError,
2674
- > ModuleError,
2675
- > HeapError,
2676
- > WebAssemblyCompileError,
2677
- > WebAssemblyRuntimeError,
2678
- */
2679
- };
2680
- /**
2681
- * Index of all errors
2682
- *
2683
- * @private for internal usage
2684
- */
2685
- var ALL_ERRORS = __assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
2686
- /**
2687
- * Note: [💞] Ignore a discrepancy between file name and entity name
2688
- */
2689
-
2690
- /**
2691
- * Deserializes the error object
2692
- *
2693
- * @public exported from `@promptbook/utils`
2694
- */
2695
- function deserializeError(error) {
2696
- var ErrorClass = ALL_ERRORS[error.name];
2697
- if (ErrorClass === undefined) {
2698
- return new Error("".concat(error.name, ": ").concat(error.message));
2699
- }
2700
- return new ErrorClass(error.message);
2701
- }
2702
-
2703
- /**
2704
- * Asserts that the execution of a Promptbook is successful
2705
- *
2706
- * @param executionResult - The partial result of the Promptbook execution
2707
- * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
2161
+ * @param executionResult - The partial result of the Promptbook execution
2162
+ * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
2708
2163
  * @public exported from `@promptbook/core`
2709
2164
  */
2710
2165
  function assertsExecutionSuccessful(executionResult) {
@@ -2735,11 +2190,16 @@ function assertsExecutionSuccessful(executionResult) {
2735
2190
  /**
2736
2191
  * Determine if the pipeline is fully prepared
2737
2192
  *
2193
+ * @see https://github.com/webgptorg/promptbook/discussions/196
2194
+ *
2738
2195
  * @public exported from `@promptbook/core`
2739
2196
  */
2740
2197
  function isPipelinePrepared(pipeline) {
2741
2198
  // Note: Ignoring `pipeline.preparations` @@@
2742
2199
  // Note: Ignoring `pipeline.knowledgePieces` @@@
2200
+ if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
2201
+ return false;
2202
+ }
2743
2203
  if (!pipeline.personas.every(function (persona) { return persona.modelRequirements !== undefined; })) {
2744
2204
  return false;
2745
2205
  }
@@ -2755,7 +2215,7 @@ function isPipelinePrepared(pipeline) {
2755
2215
  return true;
2756
2216
  }
2757
2217
  /**
2758
- * TODO: [🔃][main] !! If the pipeline was prepared with different version or different set of models, prepare it once again
2218
+ * TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
2759
2219
  * TODO: [🐠] Maybe base this on `makeValidator`
2760
2220
  * TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
2761
2221
  * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
@@ -2857,18 +2317,146 @@ function serializeError(error) {
2857
2317
  }
2858
2318
 
2859
2319
  /**
2860
- * Parses the given script and returns the list of all used variables that are not defined in the script
2320
+ * Represents the usage with no resources consumed
2861
2321
  *
2862
- * @param script from which to extract the variables
2863
- * @returns the list of variable names
2864
- * @throws {ParseError} if the script is invalid
2865
- * @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
2322
+ * @public exported from `@promptbook/core`
2866
2323
  */
2867
- function extractVariablesFromScript(script) {
2868
- var variables = new Set();
2869
- var originalScript = script;
2870
- script = "(()=>{".concat(script, "})()");
2871
- try {
2324
+ var ZERO_USAGE = $deepFreeze({
2325
+ price: { value: 0 },
2326
+ input: {
2327
+ tokensCount: { value: 0 },
2328
+ charactersCount: { value: 0 },
2329
+ wordsCount: { value: 0 },
2330
+ sentencesCount: { value: 0 },
2331
+ linesCount: { value: 0 },
2332
+ paragraphsCount: { value: 0 },
2333
+ pagesCount: { value: 0 },
2334
+ },
2335
+ output: {
2336
+ tokensCount: { value: 0 },
2337
+ charactersCount: { value: 0 },
2338
+ wordsCount: { value: 0 },
2339
+ sentencesCount: { value: 0 },
2340
+ linesCount: { value: 0 },
2341
+ paragraphsCount: { value: 0 },
2342
+ pagesCount: { value: 0 },
2343
+ },
2344
+ });
2345
+ /**
2346
+ * Represents the usage with unknown resources consumed
2347
+ *
2348
+ * @public exported from `@promptbook/core`
2349
+ */
2350
+ var UNCERTAIN_USAGE = $deepFreeze({
2351
+ price: { value: 0, isUncertain: true },
2352
+ input: {
2353
+ tokensCount: { value: 0, isUncertain: true },
2354
+ charactersCount: { value: 0, isUncertain: true },
2355
+ wordsCount: { value: 0, isUncertain: true },
2356
+ sentencesCount: { value: 0, isUncertain: true },
2357
+ linesCount: { value: 0, isUncertain: true },
2358
+ paragraphsCount: { value: 0, isUncertain: true },
2359
+ pagesCount: { value: 0, isUncertain: true },
2360
+ },
2361
+ output: {
2362
+ tokensCount: { value: 0, isUncertain: true },
2363
+ charactersCount: { value: 0, isUncertain: true },
2364
+ wordsCount: { value: 0, isUncertain: true },
2365
+ sentencesCount: { value: 0, isUncertain: true },
2366
+ linesCount: { value: 0, isUncertain: true },
2367
+ paragraphsCount: { value: 0, isUncertain: true },
2368
+ pagesCount: { value: 0, isUncertain: true },
2369
+ },
2370
+ });
2371
+ /**
2372
+ * Note: [💞] Ignore a discrepancy between file name and entity name
2373
+ */
2374
+
2375
+ /**
2376
+ * Function `addUsage` will add multiple usages into one
2377
+ *
2378
+ * Note: If you provide 0 values, it returns ZERO_USAGE
2379
+ *
2380
+ * @public exported from `@promptbook/core`
2381
+ */
2382
+ function addUsage() {
2383
+ var usageItems = [];
2384
+ for (var _i = 0; _i < arguments.length; _i++) {
2385
+ usageItems[_i] = arguments[_i];
2386
+ }
2387
+ return usageItems.reduce(function (acc, item) {
2388
+ var e_1, _a, e_2, _b;
2389
+ var _c;
2390
+ acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
2391
+ try {
2392
+ for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
2393
+ var key = _e.value;
2394
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2395
+ //@ts-ignore
2396
+ if (item.input[key]) {
2397
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2398
+ //@ts-ignore
2399
+ acc.input[key].value += item.input[key].value || 0;
2400
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2401
+ //@ts-ignore
2402
+ if (item.input[key].isUncertain) {
2403
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2404
+ //@ts-ignore
2405
+ acc.input[key].isUncertain = true;
2406
+ }
2407
+ }
2408
+ }
2409
+ }
2410
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2411
+ finally {
2412
+ try {
2413
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
2414
+ }
2415
+ finally { if (e_1) throw e_1.error; }
2416
+ }
2417
+ try {
2418
+ for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
2419
+ var key = _g.value;
2420
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2421
+ //@ts-ignore
2422
+ if (item.output[key]) {
2423
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2424
+ //@ts-ignore
2425
+ acc.output[key].value += item.output[key].value || 0;
2426
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2427
+ //@ts-ignore
2428
+ if (item.output[key].isUncertain) {
2429
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2430
+ //@ts-ignore
2431
+ acc.output[key].isUncertain = true;
2432
+ }
2433
+ }
2434
+ }
2435
+ }
2436
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2437
+ finally {
2438
+ try {
2439
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
2440
+ }
2441
+ finally { if (e_2) throw e_2.error; }
2442
+ }
2443
+ return acc;
2444
+ }, deepClone(ZERO_USAGE));
2445
+ }
2446
+
2447
+ /**
2448
+ * Parses the given script and returns the list of all used variables that are not defined in the script
2449
+ *
2450
+ * @param script from which to extract the variables
2451
+ * @returns the list of variable names
2452
+ * @throws {ParseError} if the script is invalid
2453
+ * @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
2454
+ */
2455
+ function extractVariablesFromScript(script) {
2456
+ var variables = new Set();
2457
+ var originalScript = script;
2458
+ script = "(()=>{".concat(script, "})()");
2459
+ try {
2872
2460
  for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
2873
2461
  try {
2874
2462
  eval(script);
@@ -2910,7 +2498,7 @@ function extractVariablesFromScript(script) {
2910
2498
  if (!(error instanceof Error)) {
2911
2499
  throw error;
2912
2500
  }
2913
- throw new ParseError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n\n\n Found variables:\n\n ").concat(Array.from(variables)
2501
+ throw new ParseError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n ".concat(block(error.stack || error.message), "\n\n Found variables:\n ").concat(Array.from(variables)
2914
2502
  .map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
2915
2503
  .join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
2916
2504
  }
@@ -3190,27 +2778,6 @@ var CsvFormatDefinition = {
3190
2778
  * TODO: [🏢] Allow to expect something inside CSV objects and other formats
3191
2779
  */
3192
2780
 
3193
- /**
3194
- * Function isValidJsonString will tell you if the string is valid JSON or not
3195
- *
3196
- * @public exported from `@promptbook/utils`
3197
- */
3198
- function isValidJsonString(value /* <- [👨‍⚖️] */) {
3199
- try {
3200
- JSON.parse(value);
3201
- return true;
3202
- }
3203
- catch (error) {
3204
- if (!(error instanceof Error)) {
3205
- throw error;
3206
- }
3207
- if (error.message.includes('Unexpected token')) {
3208
- return false;
3209
- }
3210
- return false;
3211
- }
3212
- }
3213
-
3214
2781
  /**
3215
2782
  * Definition for JSON format
3216
2783
  *
@@ -3318,100 +2885,392 @@ var XmlFormatDefinition = {
3318
2885
  subvalueDefinitions: [],
3319
2886
  };
3320
2887
  /**
3321
- * TODO: [🧠] Maybe propper instance of object
3322
- * TODO: [0] Make string_serialized_xml
3323
- * TODO: [1] Make type for XML Settings and Schema
3324
- * TODO: [🧠] What to use for validating XMLs - XSD,...
3325
- * TODO: [🍓] In `XmlFormatDefinition` implement simple `isValid`
3326
- * TODO: [🍓] In `XmlFormatDefinition` implement partial `canBeValid`
3327
- * TODO: [🍓] In `XmlFormatDefinition` implement `heal
3328
- * TODO: [🍓] In `XmlFormatDefinition` implement `subvalueDefinitions`
3329
- * TODO: [🏢] Allow to expect something inside XML and other formats
2888
+ * TODO: [🧠] Maybe propper instance of object
2889
+ * TODO: [0] Make string_serialized_xml
2890
+ * TODO: [1] Make type for XML Settings and Schema
2891
+ * TODO: [🧠] What to use for validating XMLs - XSD,...
2892
+ * TODO: [🍓] In `XmlFormatDefinition` implement simple `isValid`
2893
+ * TODO: [🍓] In `XmlFormatDefinition` implement partial `canBeValid`
2894
+ * TODO: [🍓] In `XmlFormatDefinition` implement `heal
2895
+ * TODO: [🍓] In `XmlFormatDefinition` implement `subvalueDefinitions`
2896
+ * TODO: [🏢] Allow to expect something inside XML and other formats
2897
+ */
2898
+
2899
+ /**
2900
+ * Definitions for all formats supported by Promptbook
2901
+ *
2902
+ * @private internal index of `...` <- TODO [🏢]
2903
+ */
2904
+ var FORMAT_DEFINITIONS = [
2905
+ JsonFormatDefinition,
2906
+ XmlFormatDefinition,
2907
+ TextFormatDefinition,
2908
+ CsvFormatDefinition,
2909
+ ];
2910
+ /**
2911
+ * Note: [💞] Ignore a discrepancy between file name and entity name
2912
+ */
2913
+
2914
+ /**
2915
+ * Maps available parameters to expected parameters
2916
+ *
2917
+ * The strategy is:
2918
+ * 1) @@@
2919
+ * 2) @@@
2920
+ *
2921
+ * @throws {PipelineExecutionError} @@@
2922
+ * @private within the repository used in `createPipelineExecutor`
2923
+ */
2924
+ function mapAvailableToExpectedParameters(options) {
2925
+ var e_1, _a;
2926
+ var expectedParameters = options.expectedParameters, availableParameters = options.availableParameters;
2927
+ var availableParametersNames = new Set(Object.keys(availableParameters));
2928
+ var expectedParameterNames = new Set(Object.keys(expectedParameters));
2929
+ var mappedParameters = {};
2930
+ try {
2931
+ // Phase 1️⃣: Matching mapping
2932
+ for (var _b = __values(Array.from(union(availableParametersNames, expectedParameterNames))), _c = _b.next(); !_c.done; _c = _b.next()) {
2933
+ var parameterName = _c.value;
2934
+ // Situation: Parameter is available and expected
2935
+ if (availableParametersNames.has(parameterName) && expectedParameterNames.has(parameterName)) {
2936
+ mappedParameters[parameterName] = availableParameters[parameterName];
2937
+ // <- Note: [👩‍👩‍👧] Maybe detect parameter collision here?
2938
+ availableParametersNames.delete(parameterName);
2939
+ expectedParameterNames.delete(parameterName);
2940
+ }
2941
+ // Situation: Parameter is available but NOT expected
2942
+ else if (availableParametersNames.has(parameterName) && !expectedParameterNames.has(parameterName)) {
2943
+ // [🐱‍👤] Do not pass this parameter to prompt - Maybe use it non-matching mapping
2944
+ }
2945
+ // Situation: Parameter is NOT available BUT expected
2946
+ else if (!availableParametersNames.has(parameterName) && expectedParameterNames.has(parameterName)) {
2947
+ // Do nothing here - this will be maybe fixed in the non-matching mapping
2948
+ }
2949
+ }
2950
+ }
2951
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2952
+ finally {
2953
+ try {
2954
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2955
+ }
2956
+ finally { if (e_1) throw e_1.error; }
2957
+ }
2958
+ if (expectedParameterNames.size === 0) {
2959
+ // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent @@@
2960
+ Object.freeze(mappedParameters);
2961
+ return mappedParameters;
2962
+ }
2963
+ // Phase 2️⃣: Non-matching mapping
2964
+ if (expectedParameterNames.size !== availableParametersNames.size) {
2965
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Can not map available parameters to expected parameters\n\n Mapped parameters:\n ".concat(block(Object.keys(mappedParameters)
2966
+ .map(function (parameterName) { return "- {".concat(parameterName, "}"); })
2967
+ .join('\n')), "\n\n Expected parameters which can not be mapped:\n ").concat(block(Array.from(expectedParameterNames)
2968
+ .map(function (parameterName) { return "- {".concat(parameterName, "}"); })
2969
+ .join('\n')), "\n\n Remaining available parameters:\n ").concat(block(Array.from(availableParametersNames)
2970
+ .map(function (parameterName) { return "- {".concat(parameterName, "}"); })
2971
+ .join('\n')), "\n\n "); }));
2972
+ }
2973
+ var expectedParameterNamesArray = Array.from(expectedParameterNames);
2974
+ var availableParametersNamesArray = Array.from(availableParametersNames);
2975
+ for (var i = 0; i < expectedParameterNames.size; i++) {
2976
+ mappedParameters[expectedParameterNamesArray[i]] = availableParameters[availableParametersNamesArray[i]];
2977
+ }
2978
+ // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent @@@
2979
+ Object.freeze(mappedParameters);
2980
+ return mappedParameters;
2981
+ }
2982
+
2983
+ /**
2984
+ * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
2985
+ *
2986
+ * Note: Internal utility of `joinLlmExecutionTools` but exposed type
2987
+ * @public exported from `@promptbook/core`
2988
+ */
2989
+ var MultipleLlmExecutionTools = /** @class */ (function () {
2990
+ /**
2991
+ * Gets array of execution tools in order of priority
2992
+ */
2993
+ function MultipleLlmExecutionTools() {
2994
+ var llmExecutionTools = [];
2995
+ for (var _i = 0; _i < arguments.length; _i++) {
2996
+ llmExecutionTools[_i] = arguments[_i];
2997
+ }
2998
+ this.llmExecutionTools = llmExecutionTools;
2999
+ }
3000
+ Object.defineProperty(MultipleLlmExecutionTools.prototype, "title", {
3001
+ get: function () {
3002
+ return 'Multiple LLM Providers';
3003
+ },
3004
+ enumerable: false,
3005
+ configurable: true
3006
+ });
3007
+ Object.defineProperty(MultipleLlmExecutionTools.prototype, "description", {
3008
+ get: function () {
3009
+ return this.llmExecutionTools.map(function (_a, index) {
3010
+ var title = _a.title;
3011
+ return "".concat(index + 1, ") `").concat(title, "`");
3012
+ }).join('\n');
3013
+ },
3014
+ enumerable: false,
3015
+ configurable: true
3016
+ });
3017
+ /**
3018
+ * Check the configuration of all execution tools
3019
+ */
3020
+ MultipleLlmExecutionTools.prototype.checkConfiguration = function () {
3021
+ return __awaiter(this, void 0, void 0, function () {
3022
+ var _a, _b, llmExecutionTools, e_1_1;
3023
+ var e_1, _c;
3024
+ return __generator(this, function (_d) {
3025
+ switch (_d.label) {
3026
+ case 0:
3027
+ _d.trys.push([0, 5, 6, 7]);
3028
+ _a = __values(this.llmExecutionTools), _b = _a.next();
3029
+ _d.label = 1;
3030
+ case 1:
3031
+ if (!!_b.done) return [3 /*break*/, 4];
3032
+ llmExecutionTools = _b.value;
3033
+ return [4 /*yield*/, llmExecutionTools.checkConfiguration()];
3034
+ case 2:
3035
+ _d.sent();
3036
+ _d.label = 3;
3037
+ case 3:
3038
+ _b = _a.next();
3039
+ return [3 /*break*/, 1];
3040
+ case 4: return [3 /*break*/, 7];
3041
+ case 5:
3042
+ e_1_1 = _d.sent();
3043
+ e_1 = { error: e_1_1 };
3044
+ return [3 /*break*/, 7];
3045
+ case 6:
3046
+ try {
3047
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
3048
+ }
3049
+ finally { if (e_1) throw e_1.error; }
3050
+ return [7 /*endfinally*/];
3051
+ case 7: return [2 /*return*/];
3052
+ }
3053
+ });
3054
+ });
3055
+ };
3056
+ /**
3057
+ * List all available models that can be used
3058
+ * This lists is a combination of all available models from all execution tools
3059
+ */
3060
+ MultipleLlmExecutionTools.prototype.listModels = function () {
3061
+ return __awaiter(this, void 0, void 0, function () {
3062
+ var availableModels, _a, _b, llmExecutionTools, models, e_2_1;
3063
+ var e_2, _c;
3064
+ return __generator(this, function (_d) {
3065
+ switch (_d.label) {
3066
+ case 0:
3067
+ availableModels = [];
3068
+ _d.label = 1;
3069
+ case 1:
3070
+ _d.trys.push([1, 6, 7, 8]);
3071
+ _a = __values(this.llmExecutionTools), _b = _a.next();
3072
+ _d.label = 2;
3073
+ case 2:
3074
+ if (!!_b.done) return [3 /*break*/, 5];
3075
+ llmExecutionTools = _b.value;
3076
+ return [4 /*yield*/, llmExecutionTools.listModels()];
3077
+ case 3:
3078
+ models = _d.sent();
3079
+ availableModels.push.apply(availableModels, __spreadArray([], __read(models), false));
3080
+ _d.label = 4;
3081
+ case 4:
3082
+ _b = _a.next();
3083
+ return [3 /*break*/, 2];
3084
+ case 5: return [3 /*break*/, 8];
3085
+ case 6:
3086
+ e_2_1 = _d.sent();
3087
+ e_2 = { error: e_2_1 };
3088
+ return [3 /*break*/, 8];
3089
+ case 7:
3090
+ try {
3091
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
3092
+ }
3093
+ finally { if (e_2) throw e_2.error; }
3094
+ return [7 /*endfinally*/];
3095
+ case 8: return [2 /*return*/, availableModels];
3096
+ }
3097
+ });
3098
+ });
3099
+ };
3100
+ /**
3101
+ * Calls the best available chat model
3102
+ */
3103
+ MultipleLlmExecutionTools.prototype.callChatModel = function (prompt) {
3104
+ return this.callCommonModel(prompt);
3105
+ };
3106
+ /**
3107
+ * Calls the best available completion model
3108
+ */
3109
+ MultipleLlmExecutionTools.prototype.callCompletionModel = function (prompt) {
3110
+ return this.callCommonModel(prompt);
3111
+ };
3112
+ /**
3113
+ * Calls the best available embedding model
3114
+ */
3115
+ MultipleLlmExecutionTools.prototype.callEmbeddingModel = function (prompt) {
3116
+ return this.callCommonModel(prompt);
3117
+ };
3118
+ // <- Note: [🤖]
3119
+ /**
3120
+ * Calls the best available model
3121
+ *
3122
+ * Note: This should be private or protected but is public to be usable with duck typing
3123
+ */
3124
+ MultipleLlmExecutionTools.prototype.callCommonModel = function (prompt) {
3125
+ return __awaiter(this, void 0, void 0, function () {
3126
+ var errors, _a, _b, llmExecutionTools, _c, error_1, e_3_1;
3127
+ var e_3, _d;
3128
+ var _this = this;
3129
+ return __generator(this, function (_e) {
3130
+ switch (_e.label) {
3131
+ case 0:
3132
+ errors = [];
3133
+ _e.label = 1;
3134
+ case 1:
3135
+ _e.trys.push([1, 15, 16, 17]);
3136
+ _a = __values(this.llmExecutionTools), _b = _a.next();
3137
+ _e.label = 2;
3138
+ case 2:
3139
+ if (!!_b.done) return [3 /*break*/, 14];
3140
+ llmExecutionTools = _b.value;
3141
+ _e.label = 3;
3142
+ case 3:
3143
+ _e.trys.push([3, 12, , 13]);
3144
+ _c = prompt.modelRequirements.modelVariant;
3145
+ switch (_c) {
3146
+ case 'CHAT': return [3 /*break*/, 4];
3147
+ case 'COMPLETION': return [3 /*break*/, 6];
3148
+ case 'EMBEDDING': return [3 /*break*/, 8];
3149
+ }
3150
+ return [3 /*break*/, 10];
3151
+ case 4:
3152
+ if (llmExecutionTools.callChatModel === undefined) {
3153
+ return [3 /*break*/, 13];
3154
+ }
3155
+ return [4 /*yield*/, llmExecutionTools.callChatModel(prompt)];
3156
+ case 5: return [2 /*return*/, _e.sent()];
3157
+ case 6:
3158
+ if (llmExecutionTools.callCompletionModel === undefined) {
3159
+ return [3 /*break*/, 13];
3160
+ }
3161
+ return [4 /*yield*/, llmExecutionTools.callCompletionModel(prompt)];
3162
+ case 7: return [2 /*return*/, _e.sent()];
3163
+ case 8:
3164
+ if (llmExecutionTools.callEmbeddingModel === undefined) {
3165
+ return [3 /*break*/, 13];
3166
+ }
3167
+ return [4 /*yield*/, llmExecutionTools.callEmbeddingModel(prompt)];
3168
+ case 9: return [2 /*return*/, _e.sent()];
3169
+ case 10: throw new UnexpectedError("Unknown model variant \"".concat(prompt.modelRequirements.modelVariant, "\""));
3170
+ case 11: return [3 /*break*/, 13];
3171
+ case 12:
3172
+ error_1 = _e.sent();
3173
+ if (!(error_1 instanceof Error) || error_1 instanceof UnexpectedError) {
3174
+ throw error_1;
3175
+ }
3176
+ errors.push(error_1);
3177
+ return [3 /*break*/, 13];
3178
+ case 13:
3179
+ _b = _a.next();
3180
+ return [3 /*break*/, 2];
3181
+ case 14: return [3 /*break*/, 17];
3182
+ case 15:
3183
+ e_3_1 = _e.sent();
3184
+ e_3 = { error: e_3_1 };
3185
+ return [3 /*break*/, 17];
3186
+ case 16:
3187
+ try {
3188
+ if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
3189
+ }
3190
+ finally { if (e_3) throw e_3.error; }
3191
+ return [7 /*endfinally*/];
3192
+ case 17:
3193
+ if (errors.length === 1) {
3194
+ throw errors[0];
3195
+ }
3196
+ else if (errors.length > 1) {
3197
+ throw new PipelineExecutionError(
3198
+ // TODO: Tell which execution tools failed like
3199
+ // 1) OpenAI throw PipelineExecutionError: Parameter `{knowledge}` is not defined
3200
+ // 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
3201
+ // 3) ...
3202
+ spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
3203
+ .map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
3204
+ .join('\n')), "\n\n "); }));
3205
+ }
3206
+ else if (this.llmExecutionTools.length === 0) {
3207
+ throw new PipelineExecutionError("You have not provided any `LlmExecutionTools`");
3208
+ }
3209
+ else {
3210
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\"\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.description), "\n\n "); }));
3211
+ }
3212
+ }
3213
+ });
3214
+ });
3215
+ };
3216
+ return MultipleLlmExecutionTools;
3217
+ }());
3218
+ /**
3219
+ * TODO: [🧠][🎛] Aggregating multiple models - have result not only from one first aviable model BUT all of them
3220
+ * TODO: [🏖] If no llmTools have for example not defined `callCompletionModel` this will still return object with defined `callCompletionModel` which just throws `PipelineExecutionError`, make it undefined instead
3221
+ * Look how `countTotalUsage` (and `cacheLlmTools`) implements it
3330
3222
  */
3331
3223
 
3332
3224
  /**
3333
- * Definitions for all formats supported by Promptbook
3225
+ * Joins multiple LLM Execution Tools into one
3334
3226
  *
3335
- * @private internal index of `...` <- TODO [🏢]
3336
- */
3337
- var FORMAT_DEFINITIONS = [
3338
- JsonFormatDefinition,
3339
- XmlFormatDefinition,
3340
- TextFormatDefinition,
3341
- CsvFormatDefinition,
3342
- ];
3343
- /**
3344
- * Note: [💞] Ignore a discrepancy between file name and entity name
3345
- */
3346
-
3347
- /**
3348
- * Maps available parameters to expected parameters
3227
+ * @returns {LlmExecutionTools} Single wrapper for multiple LlmExecutionTools
3349
3228
  *
3350
- * The strategy is:
3351
- * 1) @@@
3352
- * 2) @@@
3229
+ * 0) If there is no LlmExecutionTools, it warns and returns valid but empty LlmExecutionTools
3230
+ * 1) If there is only one LlmExecutionTools, it returns it wrapped in a proxy object
3231
+ * 2) If there are multiple LlmExecutionTools, first will be used first, second will be used if the first hasn`t defined model variant or fails, etc.
3232
+ * 3) When all LlmExecutionTools fail, it throws an error with a list of all errors merged into one
3353
3233
  *
3354
- * @throws {PipelineExecutionError} @@@
3355
- * @private within the repository used in `createPipelineExecutor`
3234
+ *
3235
+ * Tip: You don't have to use this function directly, just pass an array of LlmExecutionTools to the `ExecutionTools`
3236
+ *
3237
+ * @public exported from `@promptbook/core`
3356
3238
  */
3357
- function mapAvailableToExpectedParameters(options) {
3358
- var e_1, _a;
3359
- var expectedParameters = options.expectedParameters, availableParameters = options.availableParameters;
3360
- var availableParametersNames = new Set(Object.keys(availableParameters));
3361
- var expectedParameterNames = new Set(Object.keys(expectedParameters));
3362
- var mappedParameters = {};
3363
- try {
3364
- // Phase 1️⃣: Matching mapping
3365
- for (var _b = __values(Array.from(union(availableParametersNames, expectedParameterNames))), _c = _b.next(); !_c.done; _c = _b.next()) {
3366
- var parameterName = _c.value;
3367
- // Situation: Parameter is available and expected
3368
- if (availableParametersNames.has(parameterName) && expectedParameterNames.has(parameterName)) {
3369
- mappedParameters[parameterName] = availableParameters[parameterName];
3370
- // <- Note: [👩‍👩‍👧] Maybe detect parameter collision here?
3371
- availableParametersNames.delete(parameterName);
3372
- expectedParameterNames.delete(parameterName);
3373
- }
3374
- // Situation: Parameter is available but NOT expected
3375
- else if (availableParametersNames.has(parameterName) && !expectedParameterNames.has(parameterName)) {
3376
- // [🐱‍👤] Do not pass this parameter to prompt - Maybe use it non-matching mapping
3377
- }
3378
- // Situation: Parameter is NOT available BUT expected
3379
- else if (!availableParametersNames.has(parameterName) && expectedParameterNames.has(parameterName)) {
3380
- // Do nothing here - this will be maybe fixed in the non-matching mapping
3381
- }
3382
- }
3383
- }
3384
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3385
- finally {
3386
- try {
3387
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3388
- }
3389
- finally { if (e_1) throw e_1.error; }
3390
- }
3391
- if (expectedParameterNames.size === 0) {
3392
- // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent @@@
3393
- Object.freeze(mappedParameters);
3394
- return mappedParameters;
3395
- }
3396
- // Phase 2️⃣: Non-matching mapping
3397
- if (expectedParameterNames.size !== availableParametersNames.size) {
3398
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Can not map available parameters to expected parameters\n\n Mapped parameters:\n ".concat(block(Object.keys(mappedParameters)
3399
- .map(function (parameterName) { return "- {".concat(parameterName, "}"); })
3400
- .join('\n')), "\n\n Expected parameters which can not be mapped:\n ").concat(block(Array.from(expectedParameterNames)
3401
- .map(function (parameterName) { return "- {".concat(parameterName, "}"); })
3402
- .join('\n')), "\n\n Remaining available parameters:\n ").concat(block(Array.from(availableParametersNames)
3403
- .map(function (parameterName) { return "- {".concat(parameterName, "}"); })
3404
- .join('\n')), "\n\n "); }));
3239
+ function joinLlmExecutionTools() {
3240
+ var llmExecutionTools = [];
3241
+ for (var _i = 0; _i < arguments.length; _i++) {
3242
+ llmExecutionTools[_i] = arguments[_i];
3405
3243
  }
3406
- var expectedParameterNamesArray = Array.from(expectedParameterNames);
3407
- var availableParametersNamesArray = Array.from(availableParametersNames);
3408
- for (var i = 0; i < expectedParameterNames.size; i++) {
3409
- mappedParameters[expectedParameterNamesArray[i]] = availableParameters[availableParametersNamesArray[i]];
3244
+ if (llmExecutionTools.length === 0) {
3245
+ var warningMessage = spaceTrim("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
3246
+ // TODO: [🟥] Detect browser / node and make it colorfull
3247
+ console.warn(warningMessage);
3248
+ /*
3249
+ return {
3250
+ async listModels() {
3251
+ // TODO: [🟥] Detect browser / node and make it colorfull
3252
+ console.warn(
3253
+ spaceTrim(
3254
+ (block) => `
3255
+
3256
+ You can't list models because you have no LLM Execution Tools defined:
3257
+
3258
+ tl;dr
3259
+
3260
+ ${block(warningMessage)}
3261
+ `,
3262
+ ),
3263
+ );
3264
+ return [];
3265
+ },
3266
+ };
3267
+ */
3410
3268
  }
3411
- // Note: [👨‍👨‍👧] Now we can freeze `mappedParameters` to prevent @@@
3412
- Object.freeze(mappedParameters);
3413
- return mappedParameters;
3269
+ return new (MultipleLlmExecutionTools.bind.apply(MultipleLlmExecutionTools, __spreadArray([void 0], __read(llmExecutionTools), false)))();
3414
3270
  }
3271
+ /**
3272
+ * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
3273
+ */
3415
3274
 
3416
3275
  /**
3417
3276
  * Extracts all code blocks from markdown.
@@ -3604,6 +3463,8 @@ function templateParameters(template, parameters) {
3604
3463
  throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
3605
3464
  }
3606
3465
  parameterValue = valueToString(parameterValue);
3466
+ // Escape curly braces in parameter values to prevent prompt-injection
3467
+ parameterValue = parameterValue.replace(/[{}]/g, '\\$&');
3607
3468
  if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
3608
3469
  parameterValue = parameterValue
3609
3470
  .split('\n')
@@ -4246,7 +4107,7 @@ function executeAttempts(options) {
4246
4107
  promptTitle: task.title,
4247
4108
  promptMessage: templateParameters(task.description || '', parameters),
4248
4109
  defaultValue: templateParameters(preparedContent, parameters),
4249
- // TODO: [🧠] !! Figure out how to define placeholder in .book.md file
4110
+ // TODO: [🧠] Figure out how to define placeholder in .book.md file
4250
4111
  placeholder: undefined,
4251
4112
  priority: priority,
4252
4113
  }))];
@@ -5119,69 +4980,232 @@ function executePipeline(options) {
5119
4980
  });
5120
4981
  });
5121
4982
  }
5122
- /**
5123
- * TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
5124
- */
4983
+ /**
4984
+ * TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
4985
+ */
4986
+
4987
+ /**
4988
+ * Creates executor function from pipeline and execution tools.
4989
+ *
4990
+ * @returns The executor function
4991
+ * @throws {PipelineLogicError} on logical error in the pipeline
4992
+ * @public exported from `@promptbook/core`
4993
+ */
4994
+ function createPipelineExecutor(options) {
4995
+ var _this = this;
4996
+ var pipeline = options.pipeline, tools = options.tools, _a = options.maxExecutionAttempts, maxExecutionAttempts = _a === void 0 ? DEFAULT_MAX_EXECUTION_ATTEMPTS : _a, _b = options.maxParallelCount, maxParallelCount = _b === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _b, _c = options.csvSettings, csvSettings = _c === void 0 ? DEFAULT_CSV_SETTINGS : _c, _d = options.isVerbose, isVerbose = _d === void 0 ? DEFAULT_IS_VERBOSE : _d, _e = options.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _e === void 0 ? false : _e, _f = options.cacheDirname, cacheDirname = _f === void 0 ? DEFAULT_SCRAPE_CACHE_DIRNAME : _f, _g = options.intermediateFilesStrategy, intermediateFilesStrategy = _g === void 0 ? DEFAULT_INTERMEDIATE_FILES_STRATEGY : _g, _h = options.isAutoInstalled, isAutoInstalled = _h === void 0 ? DEFAULT_IS_AUTO_INSTALLED : _h, _j = options.rootDirname, rootDirname = _j === void 0 ? null : _j;
4997
+ validatePipeline(pipeline);
4998
+ var pipelineIdentification = (function () {
4999
+ // Note: This is a 😐 implementation of [🚞]
5000
+ var _ = [];
5001
+ if (pipeline.sourceFile !== undefined) {
5002
+ _.push("File: ".concat(pipeline.sourceFile));
5003
+ }
5004
+ if (pipeline.pipelineUrl !== undefined) {
5005
+ _.push("Url: ".concat(pipeline.pipelineUrl));
5006
+ }
5007
+ return _.join('\n');
5008
+ })();
5009
+ var preparedPipeline;
5010
+ if (isPipelinePrepared(pipeline)) {
5011
+ preparedPipeline = pipeline;
5012
+ }
5013
+ else if (isNotPreparedWarningSupressed !== true) {
5014
+ console.warn(spaceTrim$1(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
5015
+ }
5016
+ var runCount = 0;
5017
+ var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
5018
+ return __generator(this, function (_a) {
5019
+ runCount++;
5020
+ return [2 /*return*/, /* not await */ executePipeline({
5021
+ pipeline: pipeline,
5022
+ preparedPipeline: preparedPipeline,
5023
+ setPreparedPipeline: function (newPreparedPipeline) {
5024
+ preparedPipeline = newPreparedPipeline;
5025
+ },
5026
+ inputParameters: inputParameters,
5027
+ tools: tools,
5028
+ onProgress: onProgress,
5029
+ pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
5030
+ maxExecutionAttempts: maxExecutionAttempts,
5031
+ maxParallelCount: maxParallelCount,
5032
+ csvSettings: csvSettings,
5033
+ isVerbose: isVerbose,
5034
+ isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
5035
+ rootDirname: rootDirname,
5036
+ cacheDirname: cacheDirname,
5037
+ intermediateFilesStrategy: intermediateFilesStrategy,
5038
+ isAutoInstalled: isAutoInstalled,
5039
+ })];
5040
+ });
5041
+ }); };
5042
+ return pipelineExecutor;
5043
+ }
5044
+ /**
5045
+ * TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
5046
+ */
5047
+
5048
+ /**
5049
+ * Async version of Array.forEach
5050
+ *
5051
+ * @param array - Array to iterate over
5052
+ * @param options - Options for the function
5053
+ * @param callbackfunction - Function to call for each item
5054
+ * @public exported from `@promptbook/utils`
5055
+ * @deprecated [🪂] Use queues instead
5056
+ */
5057
+ function forEachAsync(array, options, callbackfunction) {
5058
+ return __awaiter(this, void 0, void 0, function () {
5059
+ var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
5060
+ var e_1, _d;
5061
+ return __generator(this, function (_e) {
5062
+ switch (_e.label) {
5063
+ case 0:
5064
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
5065
+ index = 0;
5066
+ runningTasks = [];
5067
+ tasks = [];
5068
+ _loop_1 = function (item) {
5069
+ var currentIndex, task;
5070
+ return __generator(this, function (_f) {
5071
+ switch (_f.label) {
5072
+ case 0:
5073
+ currentIndex = index++;
5074
+ task = callbackfunction(item, currentIndex, array);
5075
+ tasks.push(task);
5076
+ runningTasks.push(task);
5077
+ /* not await */ Promise.resolve(task).then(function () {
5078
+ runningTasks = runningTasks.filter(function (t) { return t !== task; });
5079
+ });
5080
+ if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
5081
+ return [4 /*yield*/, Promise.race(runningTasks)];
5082
+ case 1:
5083
+ _f.sent();
5084
+ _f.label = 2;
5085
+ case 2: return [2 /*return*/];
5086
+ }
5087
+ });
5088
+ };
5089
+ _e.label = 1;
5090
+ case 1:
5091
+ _e.trys.push([1, 6, 7, 8]);
5092
+ _b = __values(array), _c = _b.next();
5093
+ _e.label = 2;
5094
+ case 2:
5095
+ if (!!_c.done) return [3 /*break*/, 5];
5096
+ item = _c.value;
5097
+ return [5 /*yield**/, _loop_1(item)];
5098
+ case 3:
5099
+ _e.sent();
5100
+ _e.label = 4;
5101
+ case 4:
5102
+ _c = _b.next();
5103
+ return [3 /*break*/, 2];
5104
+ case 5: return [3 /*break*/, 8];
5105
+ case 6:
5106
+ e_1_1 = _e.sent();
5107
+ e_1 = { error: e_1_1 };
5108
+ return [3 /*break*/, 8];
5109
+ case 7:
5110
+ try {
5111
+ if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
5112
+ }
5113
+ finally { if (e_1) throw e_1.error; }
5114
+ return [7 /*endfinally*/];
5115
+ case 8: return [4 /*yield*/, Promise.all(tasks)];
5116
+ case 9:
5117
+ _e.sent();
5118
+ return [2 /*return*/];
5119
+ }
5120
+ });
5121
+ });
5122
+ }
5125
5123
 
5126
5124
  /**
5127
- * Creates executor function from pipeline and execution tools.
5125
+ * Intercepts LLM tools and counts total usage of the tools
5128
5126
  *
5129
- * @returns The executor function
5130
- * @throws {PipelineLogicError} on logical error in the pipeline
5127
+ * @param llmTools LLM tools to be intercepted with usage counting
5128
+ * @returns LLM tools with same functionality with added total cost counting
5131
5129
  * @public exported from `@promptbook/core`
5132
5130
  */
5133
- function createPipelineExecutor(options) {
5131
+ function countTotalUsage(llmTools) {
5134
5132
  var _this = this;
5135
- var pipeline = options.pipeline, tools = options.tools, _a = options.maxExecutionAttempts, maxExecutionAttempts = _a === void 0 ? DEFAULT_MAX_EXECUTION_ATTEMPTS : _a, _b = options.maxParallelCount, maxParallelCount = _b === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _b, _c = options.csvSettings, csvSettings = _c === void 0 ? DEFAULT_CSV_SETTINGS : _c, _d = options.isVerbose, isVerbose = _d === void 0 ? DEFAULT_IS_VERBOSE : _d, _e = options.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _e === void 0 ? false : _e, _f = options.cacheDirname, cacheDirname = _f === void 0 ? DEFAULT_SCRAPE_CACHE_DIRNAME : _f, _g = options.intermediateFilesStrategy, intermediateFilesStrategy = _g === void 0 ? DEFAULT_INTERMEDIATE_FILES_STRATEGY : _g, _h = options.isAutoInstalled, isAutoInstalled = _h === void 0 ? DEFAULT_IS_AUTO_INSTALLED : _h, _j = options.rootDirname, rootDirname = _j === void 0 ? null : _j;
5136
- validatePipeline(pipeline);
5137
- var pipelineIdentification = (function () {
5138
- // Note: This is a 😐 implementation of [🚞]
5139
- var _ = [];
5140
- if (pipeline.sourceFile !== undefined) {
5141
- _.push("File: ".concat(pipeline.sourceFile));
5142
- }
5143
- if (pipeline.pipelineUrl !== undefined) {
5144
- _.push("Url: ".concat(pipeline.pipelineUrl));
5145
- }
5146
- return _.join('\n');
5147
- })();
5148
- var preparedPipeline;
5149
- if (isPipelinePrepared(pipeline)) {
5150
- preparedPipeline = pipeline;
5133
+ var totalUsage = ZERO_USAGE;
5134
+ var proxyTools = {
5135
+ get title() {
5136
+ // TODO: [🧠] Maybe put here some suffix
5137
+ return llmTools.title;
5138
+ },
5139
+ get description() {
5140
+ // TODO: [🧠] Maybe put here some suffix
5141
+ return llmTools.description;
5142
+ },
5143
+ checkConfiguration: function () {
5144
+ return __awaiter(this, void 0, void 0, function () {
5145
+ return __generator(this, function (_a) {
5146
+ return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
5147
+ });
5148
+ });
5149
+ },
5150
+ listModels: function () {
5151
+ return /* not await */ llmTools.listModels();
5152
+ },
5153
+ getTotalUsage: function () {
5154
+ // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
5155
+ return totalUsage;
5156
+ },
5157
+ };
5158
+ if (llmTools.callChatModel !== undefined) {
5159
+ proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
5160
+ var promptResult;
5161
+ return __generator(this, function (_a) {
5162
+ switch (_a.label) {
5163
+ case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
5164
+ case 1:
5165
+ promptResult = _a.sent();
5166
+ totalUsage = addUsage(totalUsage, promptResult.usage);
5167
+ return [2 /*return*/, promptResult];
5168
+ }
5169
+ });
5170
+ }); };
5151
5171
  }
5152
- else if (isNotPreparedWarningSupressed !== true) {
5153
- console.warn(spaceTrim$1(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
5172
+ if (llmTools.callCompletionModel !== undefined) {
5173
+ proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
5174
+ var promptResult;
5175
+ return __generator(this, function (_a) {
5176
+ switch (_a.label) {
5177
+ case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
5178
+ case 1:
5179
+ promptResult = _a.sent();
5180
+ totalUsage = addUsage(totalUsage, promptResult.usage);
5181
+ return [2 /*return*/, promptResult];
5182
+ }
5183
+ });
5184
+ }); };
5154
5185
  }
5155
- var runCount = 0;
5156
- var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
5157
- return __generator(this, function (_a) {
5158
- runCount++;
5159
- return [2 /*return*/, /* not await */ executePipeline({
5160
- pipeline: pipeline,
5161
- preparedPipeline: preparedPipeline,
5162
- setPreparedPipeline: function (newPreparedPipeline) {
5163
- preparedPipeline = newPreparedPipeline;
5164
- },
5165
- inputParameters: inputParameters,
5166
- tools: tools,
5167
- onProgress: onProgress,
5168
- pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
5169
- maxExecutionAttempts: maxExecutionAttempts,
5170
- maxParallelCount: maxParallelCount,
5171
- csvSettings: csvSettings,
5172
- isVerbose: isVerbose,
5173
- isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
5174
- rootDirname: rootDirname,
5175
- cacheDirname: cacheDirname,
5176
- intermediateFilesStrategy: intermediateFilesStrategy,
5177
- isAutoInstalled: isAutoInstalled,
5178
- })];
5179
- });
5180
- }); };
5181
- return pipelineExecutor;
5186
+ if (llmTools.callEmbeddingModel !== undefined) {
5187
+ proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
5188
+ var promptResult;
5189
+ return __generator(this, function (_a) {
5190
+ switch (_a.label) {
5191
+ case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
5192
+ case 1:
5193
+ promptResult = _a.sent();
5194
+ totalUsage = addUsage(totalUsage, promptResult.usage);
5195
+ return [2 /*return*/, promptResult];
5196
+ }
5197
+ });
5198
+ }); };
5199
+ }
5200
+ // <- Note: [🤖]
5201
+ return proxyTools;
5182
5202
  }
5183
5203
  /**
5184
- * TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
5204
+ * TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
5205
+ * TODO: [🧠] Is there some meaningfull way how to test this util
5206
+ * TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
5207
+ * > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
5208
+ * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
5185
5209
  */
5186
5210
 
5187
5211
  /**
@@ -5246,10 +5270,10 @@ function preparePersona(personaDescription, tools, options) {
5246
5270
  });
5247
5271
  }
5248
5272
  /**
5249
- * TODO: [🔃][main] !! If the persona was prepared with different version or different set of models, prepare it once again
5250
- * TODO: [🏢] !! Check validity of `modelName` in pipeline
5251
- * TODO: [🏢] !! Check validity of `systemMessage` in pipeline
5252
- * TODO: [🏢] !! Check validity of `temperature` in pipeline
5273
+ * TODO: [🔃][main] If the persona was prepared with different version or different set of models, prepare it once again
5274
+ * TODO: [🏢] Check validity of `modelName` in pipeline
5275
+ * TODO: [🏢] Check validity of `systemMessage` in pipeline
5276
+ * TODO: [🏢] Check validity of `temperature` in pipeline
5253
5277
  */
5254
5278
 
5255
5279
  /**
@@ -5689,21 +5713,44 @@ function isValidFilePath(filename) {
5689
5713
  if (typeof filename !== 'string') {
5690
5714
  return false;
5691
5715
  }
5716
+ if (filename.split('\n').length > 1) {
5717
+ return false;
5718
+ }
5719
+ if (filename.split(' ').length >
5720
+ 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
5721
+ return false;
5722
+ }
5692
5723
  var filenameSlashes = filename.split('\\').join('/');
5693
5724
  // Absolute Unix path: /hello.txt
5694
5725
  if (/^(\/)/i.test(filenameSlashes)) {
5726
+ // console.log(filename, 'Absolute Unix path: /hello.txt');
5695
5727
  return true;
5696
5728
  }
5697
5729
  // Absolute Windows path: /hello.txt
5698
5730
  if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
5731
+ // console.log(filename, 'Absolute Windows path: /hello.txt');
5699
5732
  return true;
5700
5733
  }
5701
5734
  // Relative path: ./hello.txt
5702
5735
  if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
5736
+ // console.log(filename, 'Relative path: ./hello.txt');
5737
+ return true;
5738
+ }
5739
+ // Allow paths like foo/hello
5740
+ if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
5741
+ // console.log(filename, 'Allow paths like foo/hello');
5742
+ return true;
5743
+ }
5744
+ // Allow paths like hello.book
5745
+ if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
5746
+ // console.log(filename, 'Allow paths like hello.book');
5703
5747
  return true;
5704
5748
  }
5705
5749
  return false;
5706
5750
  }
5751
+ /**
5752
+ * TODO: [🍏] Implement for MacOs
5753
+ */
5707
5754
 
5708
5755
  /**
5709
5756
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
@@ -5728,6 +5775,9 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
5728
5775
  }
5729
5776
  });
5730
5777
  }); };
5778
+ /**
5779
+ * TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
5780
+ */
5731
5781
 
5732
5782
  /**
5733
5783
  * @@@
@@ -5795,7 +5845,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5795
5845
  },
5796
5846
  }];
5797
5847
  case 2:
5798
- if (!(isValidFilePath(sourceContent) || /\.[a-z]{1,10}$/i.exec(sourceContent))) return [3 /*break*/, 4];
5848
+ if (!isValidFilePath(sourceContent)) return [3 /*break*/, 4];
5799
5849
  if (tools.fs === undefined) {
5800
5850
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
5801
5851
  // <- TODO: [🧠] What is the best error type here`
@@ -5810,7 +5860,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5810
5860
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
5811
5861
  case 3:
5812
5862
  if (!(_f.sent())) {
5813
- 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(filename_1), "\n "); }));
5863
+ 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 "); }));
5814
5864
  }
5815
5865
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
5816
5866
  return [2 /*return*/, {
@@ -5923,7 +5973,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
5923
5973
  partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
5924
5974
  return [2 /*return*/, "break"];
5925
5975
  }
5926
- 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
5976
+ 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
5927
5977
  .split('\n')
5928
5978
  .map(function (line) { return "> ".concat(line); })
5929
5979
  .join('\n')), "\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
@@ -5961,7 +6011,7 @@ function prepareKnowledgePieces(knowledgeSources, tools, options) {
5961
6011
  return [7 /*endfinally*/];
5962
6012
  case 9:
5963
6013
  if (partialPieces === null) {
5964
- throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Cannot scrape knowledge\n \n The source:\n > ".concat(block(knowledgeSource.sourceContent
6014
+ throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Cannot scrape knowledge\n\n The source:\n > ".concat(block(knowledgeSource.sourceContent
5965
6015
  .split('\n')
5966
6016
  .map(function (line) { return "> ".concat(line); })
5967
6017
  .join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
@@ -6052,7 +6102,7 @@ function prepareTasks(pipeline, tools, options) {
6052
6102
  * TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
6053
6103
  * TODO: [🧠] Add context to each task (if missing)
6054
6104
  * TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
6055
- * TODO: [♨][main] !!! Prepare index the examples and maybe tasks
6105
+ * TODO: [♨][main] !!3 Prepare index the examples and maybe tasks
6056
6106
  * TODO: Write tests for `preparePipeline`
6057
6107
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
6058
6108
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
@@ -6060,7 +6110,9 @@ function prepareTasks(pipeline, tools, options) {
6060
6110
  */
6061
6111
 
6062
6112
  /**
6063
- * Prepare pipeline from string (markdown) format to JSON format
6113
+ * Prepare pipeline locally
6114
+ *
6115
+ * @see https://github.com/webgptorg/promptbook/discussions/196
6064
6116
  *
6065
6117
  * Note: This function does not validate logic of the pipeline
6066
6118
  * Note: This function acts as part of compilation process
@@ -6074,16 +6126,17 @@ function preparePipeline(pipeline, tools, options) {
6074
6126
  <- TODO: [🧠][🪑] `promptbookVersion` */
6075
6127
  knowledgeSources /*
6076
6128
  <- TODO: [🧊] `knowledgePieces` */, personas /*
6077
- <- TODO: [🧊] `preparations` */, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
6129
+ <- TODO: [🧊] `preparations` */, sources, _llms, llmTools, llmToolsWithUsage, currentPreparation, preparations, title, collection, prepareTitleExecutor, _c, result, outputParameters, titleRaw, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, tasksPrepared /* TODO: parameters: parametersPrepared*/;
6130
+ var _d;
6078
6131
  var _this = this;
6079
- return __generator(this, function (_c) {
6080
- switch (_c.label) {
6132
+ return __generator(this, function (_e) {
6133
+ switch (_e.label) {
6081
6134
  case 0:
6082
6135
  if (isPipelinePrepared(pipeline)) {
6083
6136
  return [2 /*return*/, pipeline];
6084
6137
  }
6085
6138
  rootDirname = options.rootDirname, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
6086
- parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
6139
+ parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas, sources = pipeline.sources;
6087
6140
  if (tools === undefined || tools.llm === undefined) {
6088
6141
  throw new MissingToolsError('LLM tools are required for preparing the pipeline');
6089
6142
  }
@@ -6101,6 +6154,33 @@ function preparePipeline(pipeline, tools, options) {
6101
6154
  // <- TODO: [🧊]
6102
6155
  currentPreparation,
6103
6156
  ];
6157
+ title = pipeline.title;
6158
+ if (!(title === undefined || title === '' || title === DEFAULT_BOOK_TITLE)) return [3 /*break*/, 3];
6159
+ collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
6160
+ _c = createPipelineExecutor;
6161
+ _d = {};
6162
+ return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-title.book.md')];
6163
+ case 1:
6164
+ prepareTitleExecutor = _c.apply(void 0, [(_d.pipeline = _e.sent(),
6165
+ _d.tools = tools,
6166
+ _d)]);
6167
+ return [4 /*yield*/, prepareTitleExecutor({
6168
+ book: sources.map(function (_a) {
6169
+ var content = _a.content;
6170
+ return content;
6171
+ }).join('\n\n'),
6172
+ })];
6173
+ case 2:
6174
+ result = _e.sent();
6175
+ assertsExecutionSuccessful(result);
6176
+ outputParameters = result.outputParameters;
6177
+ titleRaw = outputParameters.title;
6178
+ if (isVerbose) {
6179
+ console.info("The title is \"".concat(titleRaw, "\""));
6180
+ }
6181
+ title = titleRaw || DEFAULT_BOOK_TITLE;
6182
+ _e.label = 3;
6183
+ case 3:
6104
6184
  preparedPersonas = new Array(personas.length);
6105
6185
  return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona, index) { return __awaiter(_this, void 0, void 0, function () {
6106
6186
  var modelRequirements, preparedPersona;
@@ -6119,12 +6199,12 @@ function preparePipeline(pipeline, tools, options) {
6119
6199
  }
6120
6200
  });
6121
6201
  }); })];
6122
- case 1:
6123
- _c.sent();
6202
+ case 4:
6203
+ _e.sent();
6124
6204
  knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
6125
6205
  return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), __assign(__assign({}, options), { rootDirname: rootDirname, maxParallelCount: maxParallelCount /* <- TODO: [🪂] */, isVerbose: isVerbose }))];
6126
- case 2:
6127
- partialknowledgePiecesPrepared = _c.sent();
6206
+ case 5:
6207
+ partialknowledgePiecesPrepared = _e.sent();
6128
6208
  knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
6129
6209
  return [4 /*yield*/, prepareTasks({
6130
6210
  parameters: parameters,
@@ -6135,8 +6215,8 @@ function preparePipeline(pipeline, tools, options) {
6135
6215
  maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
6136
6216
  isVerbose: isVerbose,
6137
6217
  })];
6138
- case 3:
6139
- tasksPrepared = (_c.sent()).tasksPrepared;
6218
+ case 6:
6219
+ tasksPrepared = (_e.sent()).tasksPrepared;
6140
6220
  // ----- /Tasks preparation -----
6141
6221
  // TODO: [😂] Use here all `AsyncHighLevelAbstraction`
6142
6222
  // Note: Count total usage
@@ -6147,7 +6227,7 @@ function preparePipeline(pipeline, tools, options) {
6147
6227
  order: ORDER_OF_PIPELINE_JSON,
6148
6228
  value: __assign(__assign({}, pipeline), {
6149
6229
  // <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
6150
- knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
6230
+ title: title, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
6151
6231
  // <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
6152
6232
  personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }),
6153
6233
  })];
@@ -6156,7 +6236,7 @@ function preparePipeline(pipeline, tools, options) {
6156
6236
  });
6157
6237
  }
6158
6238
  /**
6159
- * TODO: Write tests for `preparePipeline`
6239
+ * TODO: Write tests for `preparePipeline` and `preparePipelineOnRemoteServer`
6160
6240
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
6161
6241
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
6162
6242
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
@@ -6242,7 +6322,7 @@ var knowledgeCommandParser = {
6242
6322
  if (sourceContent === '') {
6243
6323
  throw new ParseError("Source is not defined");
6244
6324
  }
6245
- // TODO: [main] !!!! Following checks should be applied every link in the `sourceContent`
6325
+ // TODO: [main] !!4 Following checks should be applied every link in the `sourceContent`
6246
6326
  if (sourceContent.startsWith('http://')) {
6247
6327
  throw new ParseError("Source is not secure");
6248
6328
  }
@@ -6414,7 +6494,7 @@ var sectionCommandParser = {
6414
6494
  expectResultingParameterName();
6415
6495
  var parameter = $pipelineJson.parameters.find(function (param) { return param.name === $taskJson.resultingParameterName; });
6416
6496
  if (parameter === undefined) {
6417
- // TODO: !!!!!! Change to logic error for higher level abstractions to work
6497
+ // TODO: !!6 Change to logic error for higher level abstraction of chatbot to work
6418
6498
  throw new ParseError("Parameter `{".concat($taskJson.resultingParameterName, "}` is not defined so can not define example value of it"));
6419
6499
  }
6420
6500
  parameter.exampleValues = parameter.exampleValues || [];
@@ -6425,7 +6505,7 @@ var sectionCommandParser = {
6425
6505
  if (command.taskType === 'KNOWLEDGE') {
6426
6506
  knowledgeCommandParser.$applyToPipelineJson({
6427
6507
  type: 'KNOWLEDGE',
6428
- sourceContent: $taskJson.content, // <- TODO: [🐝][main] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
6508
+ sourceContent: $taskJson.content, // <- TODO: [🐝][main] !!3 Work with KNOWLEDGE which not referring to the source file or website, but its content itself
6429
6509
  }, $pipelineJson);
6430
6510
  $taskJson.isTask = false;
6431
6511
  return;
@@ -7320,20 +7400,24 @@ var ChatbotFormfactorDefinition = {
7320
7400
  */
7321
7401
  var GeneratorFormfactorDefinition = {
7322
7402
  name: 'GENERATOR',
7323
- description: "@@@",
7403
+ description: "Generates any kind (in HTML with possible scripts and css format) of content from input message",
7324
7404
  documentationUrl: "https://github.com/webgptorg/promptbook/discussions/184",
7325
7405
  pipelineInterface: {
7326
7406
  inputParameters: [
7327
- /* @@@ */
7328
7407
  {
7329
- name: 'nonce',
7330
- description: 'Just to prevent GENERATOR to be set as implicit formfactor',
7408
+ name: 'inputMessage',
7409
+ description: "Input message to be image made from",
7331
7410
  isInput: true,
7332
7411
  isOutput: false,
7333
7412
  },
7334
7413
  ],
7335
7414
  outputParameters: [
7336
- /* @@@ */
7415
+ {
7416
+ name: 'result',
7417
+ description: "Result in HTML to be shown to user",
7418
+ isInput: false,
7419
+ isOutput: true,
7420
+ },
7337
7421
  ],
7338
7422
  },
7339
7423
  };
@@ -7365,6 +7449,35 @@ var GenericFormfactorDefinition = {
7365
7449
  pipelineInterface: GENERIC_PIPELINE_INTERFACE,
7366
7450
  };
7367
7451
 
7452
+ /**
7453
+ * Image generator is form of app that generates image from input message
7454
+ *
7455
+ * @public exported from `@promptbook/core`
7456
+ */
7457
+ var ImageGeneratorFormfactorDefinition = {
7458
+ name: 'IMAGE_GENERATOR',
7459
+ description: "Generates prompt for image generation from input message",
7460
+ documentationUrl: "https://github.com/webgptorg/promptbook/discussions/184",
7461
+ pipelineInterface: {
7462
+ inputParameters: [
7463
+ {
7464
+ name: 'inputMessage',
7465
+ description: "Input message to be image made from",
7466
+ isInput: true,
7467
+ isOutput: false,
7468
+ },
7469
+ ],
7470
+ outputParameters: [
7471
+ {
7472
+ name: 'prompt',
7473
+ description: "Prompt to be used for image generation",
7474
+ isInput: false,
7475
+ isOutput: true,
7476
+ },
7477
+ ],
7478
+ },
7479
+ };
7480
+
7368
7481
  /**
7369
7482
  * Matcher is form of app that @@@
7370
7483
  *
@@ -7463,6 +7576,7 @@ var FORMFACTOR_DEFINITIONS = [
7463
7576
  SheetsFormfactorDefinition,
7464
7577
  MatcherFormfactorDefinition,
7465
7578
  GeneratorFormfactorDefinition,
7579
+ ImageGeneratorFormfactorDefinition,
7466
7580
  ];
7467
7581
  /**
7468
7582
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -7849,7 +7963,7 @@ var parameterCommandParser = {
7849
7963
  * Note: `$` is used to indicate that this function mutates given `pipelineJson`
7850
7964
  */
7851
7965
  $applyToPipelineJson: function (command, $pipelineJson) {
7852
- // Note: [🍣] Do nothing, its application is implemented separately in `precompilePipeline`
7966
+ // Note: [🍣] Do nothing, its application is implemented separately in `parsePipeline`
7853
7967
  },
7854
7968
  /**
7855
7969
  * Apply the PARAMETER command to the `pipelineJson`
@@ -7857,7 +7971,7 @@ var parameterCommandParser = {
7857
7971
  * Note: `$` is used to indicate that this function mutates given `taskJson`
7858
7972
  */
7859
7973
  $applyToTaskJson: function (command, $taskJson, $pipelineJson) {
7860
- // Note: [🍣] Do nothing, its application is implemented separately in `precompilePipeline`
7974
+ // Note: [🍣] Do nothing, its application is implemented separately in `parsePipeline`
7861
7975
  },
7862
7976
  /**
7863
7977
  * Converts the PARAMETER command back to string
@@ -8352,7 +8466,7 @@ var COMMANDS = [
8352
8466
  instrumentCommandParser,
8353
8467
  personaCommandParser,
8354
8468
  foreachCommandParser,
8355
- boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
8469
+ boilerplateCommandParser, // <- TODO: Only in development, remove in production
8356
8470
  // <- Note: [♓️][💩] This is the order of the commands in the pipeline, BUT its not used in parsing and before usage maybe it should be done better
8357
8471
  ];
8358
8472
  /**
@@ -8776,7 +8890,7 @@ var QuickChatbotHla = {
8776
8890
  isOutput: true,
8777
8891
  exampleValues: ['Hello, I am a Pavol`s virtual avatar. How can I help you?'],
8778
8892
  });
8779
- // TODO: !!!!!! spaceTrim
8893
+ // TODO: Use spaceTrim in multiline strings
8780
8894
  $pipelineJson.tasks.push({
8781
8895
  taskType: 'PROMPT_TASK',
8782
8896
  name: 'create-an-answer',
@@ -8784,8 +8898,11 @@ var QuickChatbotHla = {
8784
8898
  content: 'Write a response to the user message:\n\n**Question from user**\n\n> {userMessage}\n\n**Previous conversation**\n\n> {previousConversationSummary}',
8785
8899
  resultingParameterName: 'chatbotResponse',
8786
8900
  personaName: personaName,
8787
- dependentParameterNames: ['userMessage', 'previousConversationSummary' /* !!!!!!, 'knowledge'*/],
8788
- // !!!!!! preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
8901
+ dependentParameterNames: [
8902
+ 'userMessage',
8903
+ 'previousConversationSummary' /* TODO: [🧠][📛], 'knowledge'*/,
8904
+ ],
8905
+ // TODO: [🧠][📛] preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
8789
8906
  }, {
8790
8907
  taskType: 'PROMPT_TASK',
8791
8908
  name: 'summarize-the-conversation',
@@ -8799,24 +8916,27 @@ var QuickChatbotHla = {
8799
8916
  max: 10,
8800
8917
  },
8801
8918
  },
8802
- dependentParameterNames: ['userMessage', 'chatbotResponse' /* !!!!!!, 'knowledge'*/],
8803
- // !!!!!! preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
8919
+ dependentParameterNames: ['userMessage', 'chatbotResponse' /* TODO: [🧠][📛], 'knowledge'*/],
8920
+ // TODO: [🧠][📛] preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
8804
8921
  }, {
8805
8922
  taskType: 'SIMPLE_TASK',
8806
8923
  name: 'title',
8807
8924
  title: 'Title',
8808
8925
  content: '{conversationSummary}',
8809
8926
  resultingParameterName: 'title',
8810
- dependentParameterNames: ['conversationSummary' /* !!!!!!, 'knowledge'*/],
8811
- // !!!!!! preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
8927
+ dependentParameterNames: ['conversationSummary' /* TODO: [🧠][📛], 'knowledge'*/],
8928
+ // TODO: [🧠][📛] preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
8812
8929
  });
8813
8930
  },
8814
8931
  };
8932
+ /**
8933
+ * TODO: [🧠][📛] Should this be here?
8934
+ */
8815
8935
 
8816
8936
  /**
8817
8937
  * All high-level abstractions
8818
8938
  *
8819
- * @private internal index of `precompilePipeline` (= used for sync) and `preparePipeline` (= used for async)
8939
+ * @private internal index of `parsePipeline` (= used for sync) and `preparePipeline` (= used for async)
8820
8940
  */
8821
8941
  var HIGH_LEVEL_ABSTRACTIONS = [
8822
8942
  ImplicitFormfactorHla,
@@ -8950,7 +9070,7 @@ function splitMarkdownIntoSections(markdown) {
8950
9070
  return;
8951
9071
  }
8952
9072
  if (!section.startsWith('#')) {
8953
- section = "# ".concat(DEFAULT_TITLE, "\n\n").concat(section);
9073
+ section = "# ".concat(DEFAULT_BOOK_TITLE, "\n\n").concat(section);
8954
9074
  }
8955
9075
  sections.push(section);
8956
9076
  buffer = [];
@@ -9005,7 +9125,7 @@ function splitMarkdownIntoSections(markdown) {
9005
9125
  /**
9006
9126
  * Normalizes the markdown by flattening the structure
9007
9127
  *
9008
- * - It always have h1 - if there is no h1 in the markdown, it will be added "# Untitled"
9128
+ * - It always have h1 - if there is no h1 in the markdown, it will be added `DEFAULT_BOOK_TITLE`
9009
9129
  * - All other headings are normalized to h2
9010
9130
  *
9011
9131
  * @public exported from `@promptbook/markdown-utils`
@@ -9014,7 +9134,7 @@ function flattenMarkdown(markdown) {
9014
9134
  var e_1, _a;
9015
9135
  var sections = splitMarkdownIntoSections(markdown);
9016
9136
  if (sections.length === 0) {
9017
- return "# ".concat(DEFAULT_TITLE);
9137
+ return "# ".concat(DEFAULT_BOOK_TITLE);
9018
9138
  }
9019
9139
  var flattenedMarkdown = '';
9020
9140
  var parsedSections = sections.map(parseMarkdownSection);
@@ -9025,7 +9145,7 @@ function flattenMarkdown(markdown) {
9025
9145
  }
9026
9146
  else {
9027
9147
  parsedSections.unshift(firstSection);
9028
- flattenedMarkdown += "# ".concat(DEFAULT_TITLE) + "\n\n"; // <- [🧠] Maybe 3 new lines?
9148
+ flattenedMarkdown += "# ".concat(DEFAULT_BOOK_TITLE) + "\n\n"; // <- [🧠] Maybe 3 new lines?
9029
9149
  }
9030
9150
  try {
9031
9151
  for (var parsedSections_1 = __values(parsedSections), parsedSections_1_1 = parsedSections_1.next(); !parsedSections_1_1.done; parsedSections_1_1 = parsedSections_1.next()) {
@@ -9052,13 +9172,13 @@ function flattenMarkdown(markdown) {
9052
9172
  */
9053
9173
 
9054
9174
  /**
9055
- * Removes HTML or Markdown comments from a string.
9175
+ * Removes Markdown (or HTML) comments
9056
9176
  *
9057
9177
  * @param {string} content - The string to remove comments from.
9058
9178
  * @returns {string} The input string with all comments removed.
9059
9179
  * @public exported from `@promptbook/markdown-utils`
9060
9180
  */
9061
- function removeContentComments(content) {
9181
+ function removeMarkdownComments(content) {
9062
9182
  return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
9063
9183
  }
9064
9184
 
@@ -9091,7 +9211,7 @@ function titleToName(value) {
9091
9211
  *
9092
9212
  * Note: There are 3 similar functions:
9093
9213
  * - `compilePipeline` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
9094
- * - `precompilePipeline` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
9214
+ * - `parsePipeline` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
9095
9215
  * - `preparePipeline` - just one step in the compilation process
9096
9216
  *
9097
9217
  * Note: This function does not validate logic of the pipeline only the parsing
@@ -9102,10 +9222,10 @@ function titleToName(value) {
9102
9222
  * @throws {ParseError} if the promptbook string is not valid
9103
9223
  * @public exported from `@promptbook/core`
9104
9224
  */
9105
- function precompilePipeline(pipelineString) {
9225
+ function parsePipeline(pipelineString) {
9106
9226
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
9107
9227
  var $pipelineJson = {
9108
- title: DEFAULT_TITLE,
9228
+ title: DEFAULT_BOOK_TITLE,
9109
9229
  parameters: [],
9110
9230
  tasks: [],
9111
9231
  knowledgeSources: [],
@@ -9116,7 +9236,7 @@ function precompilePipeline(pipelineString) {
9116
9236
  {
9117
9237
  type: 'BOOK',
9118
9238
  path: null,
9119
- // <- TODO: !!!!!! Pass here path of the file
9239
+ // <- TODO: !!6 Pass here path of the file
9120
9240
  content: pipelineString,
9121
9241
  },
9122
9242
  ],
@@ -9141,16 +9261,29 @@ function precompilePipeline(pipelineString) {
9141
9261
  if (!(shebangLine_1 || '').includes('ptbk')) {
9142
9262
  throw new ParseError(spaceTrim$1(function (block) { return "\n It seems that you try to parse a book file which has non-standard shebang line for book files:\n Shebang line must contain 'ptbk'\n\n You have:\n ".concat(block(shebangLine_1 || '(empty line)'), "\n\n It should look like this:\n #!/usr/bin/env ptbk\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
9143
9263
  }
9144
- pipelineString = restLines.join('\n');
9264
+ pipelineString = validatePipelineString(restLines.join('\n'));
9145
9265
  }
9146
- pipelineString = removeContentComments(pipelineString);
9266
+ pipelineString = removeMarkdownComments(pipelineString);
9267
+ pipelineString = spaceTrim$1(pipelineString);
9268
+ // <- TODO: [😧] `spaceTrim` should preserve discriminated type *(or at lease `PipelineString`)*
9147
9269
  // ==============
9148
9270
  // Note: 1️⃣◽2️⃣ Process flat pipeline
9149
- // TODO: !!!!!!
9150
- // const isMarkdownBeginningWithHeadline =
9151
- // const isMarkdown
9152
- // const isMarkdown
9153
- // const isMarkdown
9271
+ var isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
9272
+ var isLastLineReturnStatement = pipelineString.split('\n').pop().split('`').join('').startsWith('->');
9273
+ // TODO: Also (double)check
9274
+ // > const usedCommands
9275
+ // > const isBlocksUsed
9276
+ // > const returnStatementCount
9277
+ var isFlatPipeline = !isMarkdownBeginningWithHeadline && isLastLineReturnStatement;
9278
+ // console.log({ isMarkdownBeginningWithHeadline, isLastLineReturnStatement, isFlatPipeline });
9279
+ if (isFlatPipeline) {
9280
+ var pipelineStringLines = pipelineString.split('\n');
9281
+ var returnStatement_1 = pipelineStringLines.pop();
9282
+ var prompt_1 = spaceTrim$1(pipelineStringLines.join('\n'));
9283
+ pipelineString = validatePipelineString(spaceTrim$1(function (block) { return "\n # ".concat(DEFAULT_BOOK_TITLE, "\n\n ## Prompt\n\n ```\n ").concat(block(prompt_1), "\n ```\n\n ").concat(returnStatement_1, "\n "); }));
9284
+ // <- TODO: Maybe use book` notation
9285
+ // console.log(pipelineString);
9286
+ }
9154
9287
  // ==============
9155
9288
  // Note: 1️⃣◽3️⃣ Parse the markdown
9156
9289
  pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
@@ -9542,14 +9675,14 @@ function precompilePipeline(pipelineString) {
9542
9675
  // =============================================================
9543
9676
  return exportJson({
9544
9677
  name: 'pipelineJson',
9545
- message: "Result of `precompilePipeline`",
9678
+ message: "Result of `parsePipeline`",
9546
9679
  order: ORDER_OF_PIPELINE_JSON,
9547
9680
  value: __assign({ formfactorName: 'GENERIC' }, $pipelineJson),
9548
9681
  });
9549
9682
  }
9550
9683
  /**
9551
9684
  * TODO: [🧠] Maybe more things here can be refactored as high-level abstractions
9552
- * TODO: [main] !!!! Warn if used only sync version
9685
+ * TODO: [main] !!4 Warn if used only sync version
9553
9686
  * TODO: [🚞] Report here line/column of error
9554
9687
  * TODO: Use spaceTrim more effectively
9555
9688
  * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
@@ -9562,10 +9695,7 @@ function precompilePipeline(pipelineString) {
9562
9695
  /**
9563
9696
  * Compile pipeline from string (markdown) format to JSON format
9564
9697
  *
9565
- * Note: There are 3 similar functions:
9566
- * - `compilePipeline` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
9567
- * - `precompilePipeline` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
9568
- * - `preparePipeline` - just one step in the compilation process
9698
+ * @see https://github.com/webgptorg/promptbook/discussions/196
9569
9699
  *
9570
9700
  * Note: This function does not validate logic of the pipeline only the parsing
9571
9701
  * Note: This function acts as compilation process
@@ -9583,7 +9713,7 @@ function compilePipeline(pipelineString, tools, options) {
9583
9713
  return __generator(this, function (_a) {
9584
9714
  switch (_a.label) {
9585
9715
  case 0:
9586
- pipelineJson = precompilePipeline(pipelineString);
9716
+ pipelineJson = parsePipeline(pipelineString);
9587
9717
  if (!(tools !== undefined && tools.llm !== undefined)) return [3 /*break*/, 2];
9588
9718
  return [4 /*yield*/, preparePipeline(pipelineJson, tools, options || {
9589
9719
  rootDirname: null,
@@ -9592,7 +9722,7 @@ function compilePipeline(pipelineString, tools, options) {
9592
9722
  pipelineJson = _a.sent();
9593
9723
  _a.label = 2;
9594
9724
  case 2:
9595
- // Note: No need to use `$exportJson` because `precompilePipeline` and `preparePipeline` already do that
9725
+ // Note: No need to use `$exportJson` because `parsePipeline` and `preparePipeline` already do that
9596
9726
  return [2 /*return*/, pipelineJson];
9597
9727
  }
9598
9728
  });
@@ -9619,7 +9749,7 @@ function addAutoGeneratedSection(content, options) {
9619
9749
  return content.replace(sectionRegex, contentToInsert);
9620
9750
  }
9621
9751
  // Note: Following is the case when the section is not found in the file so we add it there
9622
- var placeForSection = removeContentComments(content).match(/^##.*$/im);
9752
+ var placeForSection = removeMarkdownComments(content).match(/^##.*$/im);
9623
9753
  if (placeForSection !== null) {
9624
9754
  var _a = __read(placeForSection, 1), heading_1 = _a[0];
9625
9755
  return content.replace(heading_1, spaceTrim$1(function (block) { return "\n ".concat(block(contentToInsert), "\n\n ").concat(block(heading_1), "\n "); }));
@@ -9645,7 +9775,7 @@ function renderPromptbookMermaid(pipelineJson, options) {
9645
9775
  var parameter = pipelineJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
9646
9776
  if (!parameter) {
9647
9777
  throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
9648
- // <- TODO: !!!!!! This causes problems when {knowledge} and other reserved parameters are used
9778
+ // <- TODO: !!6 This causes problems when {knowledge} and other reserved parameters are used
9649
9779
  }
9650
9780
  if (parameter.isInput) {
9651
9781
  return 'input';
@@ -9689,9 +9819,9 @@ function renderPromptbookMermaid(pipelineJson, options) {
9689
9819
  return promptbookMermaid;
9690
9820
  }
9691
9821
  /**
9692
- * TODO: [🧠] !! FOREACH in mermaid graph
9693
- * TODO: [🧠] !! Knowledge in mermaid graph
9694
- * TODO: [🧠] !! Personas in mermaid graph
9822
+ * TODO: [🧠] FOREACH in mermaid graph
9823
+ * TODO: [🧠] Knowledge in mermaid graph
9824
+ * TODO: [🧠] Personas in mermaid graph
9695
9825
  * TODO: Maybe use some Mermaid package instead of string templating
9696
9826
  * TODO: [🕌] When more than 2 functionalities, split into separate functions
9697
9827
  */
@@ -9726,6 +9856,7 @@ function prettifyPipelineString(pipelineString, options) {
9726
9856
  case 2:
9727
9857
  if (isPrettifyed) {
9728
9858
  pipelineString = prettifyMarkdown(pipelineString);
9859
+ // <- TODO: [😧] `prettifyMarkdown` should preserve discriminated type *(or at lease `PipelineString`)*
9729
9860
  }
9730
9861
  return [2 /*return*/, pipelineString];
9731
9862
  }
@@ -10527,7 +10658,7 @@ function cacheLlmTools(llmTools, options) {
10527
10658
  return [3 /*break*/, 11];
10528
10659
  case 10: throw new PipelineExecutionError("Unknown model variant \"".concat(prompt.modelRequirements.modelVariant, "\""));
10529
10660
  case 11:
10530
- // TODO: [🧠] !!!!! How to do timing in mixed cache / non-cache situation
10661
+ // TODO: [🧠] !!5 How to do timing in mixed cache / non-cache situation
10531
10662
  // promptResult.timing: FromtoItems
10532
10663
  return [4 /*yield*/, storage.setItem(key, {
10533
10664
  date: $getCurrentDate(),
@@ -10536,7 +10667,7 @@ function cacheLlmTools(llmTools, options) {
10536
10667
  promptResult: promptResult,
10537
10668
  })];
10538
10669
  case 12:
10539
- // TODO: [🧠] !!!!! How to do timing in mixed cache / non-cache situation
10670
+ // TODO: [🧠] !!5 How to do timing in mixed cache / non-cache situation
10540
10671
  // promptResult.timing: FromtoItems
10541
10672
  _c.sent();
10542
10673
  return [2 /*return*/, promptResult];
@@ -10627,6 +10758,7 @@ function limitTotalUsage(llmTools, options) {
10627
10758
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
10628
10759
  *
10629
10760
  * @public exported from `@promptbook/core`
10761
+ * @public exported from `@promptbook/wizzard`
10630
10762
  * @public exported from `@promptbook/cli`
10631
10763
  */
10632
10764
  var _AnthropicClaudeMetadataRegistration = $llmToolsMetadataRegister.register({
@@ -10672,6 +10804,7 @@ var _AnthropicClaudeMetadataRegistration = $llmToolsMetadataRegister.register({
10672
10804
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
10673
10805
  *
10674
10806
  * @public exported from `@promptbook/core`
10807
+ * @public exported from `@promptbook/wizzard`
10675
10808
  * @public exported from `@promptbook/cli`
10676
10809
  */
10677
10810
  var _AzureOpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
@@ -10748,6 +10881,7 @@ var $isRunningInJest = new Function("\n try {\n return process.env.JES
10748
10881
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
10749
10882
  *
10750
10883
  * @public exported from `@promptbook/core`
10884
+ * @public exported from `@promptbook/wizzard`
10751
10885
  * @public exported from `@promptbook/cli`
10752
10886
  */
10753
10887
  var _GoogleMetadataRegistration = $llmToolsMetadataRegister.register({
@@ -10796,6 +10930,7 @@ var _GoogleMetadataRegistration = $llmToolsMetadataRegister.register({
10796
10930
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
10797
10931
  *
10798
10932
  * @public exported from `@promptbook/core`
10933
+ * @public exported from `@promptbook/wizzard`
10799
10934
  * @public exported from `@promptbook/cli`
10800
10935
  */
10801
10936
  var _OpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
@@ -10834,6 +10969,7 @@ var _OpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
10834
10969
  * Note: [🏐] Configurations registrations are done in @@@ BUT constructor @@@
10835
10970
  *
10836
10971
  * @public exported from `@promptbook/core`
10972
+ * @public exported from `@promptbook/wizzard`
10837
10973
  * @public exported from `@promptbook/cli`
10838
10974
  */
10839
10975
  var _OpenAiAssistantMetadataRegistration = $llmToolsMetadataRegister.register({
@@ -10876,6 +11012,59 @@ var _OpenAiAssistantMetadataRegistration = $llmToolsMetadataRegister.register({
10876
11012
  * Note: [💞] Ignore a discrepancy between file name and entity name
10877
11013
  */
10878
11014
 
11015
+ /**
11016
+ * Function `isValidPipelineString` will validate the if the string is a valid pipeline string
11017
+ * 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.
11018
+ *
11019
+ * @param {string} pipelineString the candidate for a pipeline string
11020
+ * @returns {boolean} if the string is a valid pipeline string
11021
+ * @public exported from `@promptbook/core`
11022
+ */
11023
+ function isValidPipelineString(pipelineString) {
11024
+ try {
11025
+ validatePipelineString(pipelineString);
11026
+ return true;
11027
+ }
11028
+ catch (error) {
11029
+ if (!(error instanceof Error)) {
11030
+ throw error;
11031
+ }
11032
+ return false;
11033
+ }
11034
+ }
11035
+ /**
11036
+ * TODO: [🧠][🈴] Where is the best location for this file
11037
+ */
11038
+
11039
+ /**
11040
+ * Tag function for notating a pipeline with a book\`...\ notation as template literal
11041
+ *
11042
+ * @param strings @@@
11043
+ * @param values @@@
11044
+ * @returns the pipeline string
11045
+ * @public exported from `@promptbook/core`
11046
+ */
11047
+ function book(strings) {
11048
+ var values = [];
11049
+ for (var _i = 1; _i < arguments.length; _i++) {
11050
+ values[_i - 1] = arguments[_i];
11051
+ }
11052
+ if (strings.length !== 1 && values.length !== 0) {
11053
+ throw new NotYetImplementedError("Only one string without interpolated value is supported for now in book`...` notation");
11054
+ }
11055
+ var pipelineString = strings[0];
11056
+ pipelineString = spaceTrim(pipelineString);
11057
+ if (!isValidPipelineString(pipelineString)) {
11058
+ // TODO: Make the CustomError for this
11059
+ throw new Error(spaceTrim("\n The string is not a valid pipeline string\n\n book`\n ".concat(pipelineString, "\n `\n ")));
11060
+ }
11061
+ return pipelineString;
11062
+ }
11063
+ /**
11064
+ * TODO: [🧠][🈴] Where is the best location for this file
11065
+ * Note: [💞] Ignore a discrepancy between file name and entity name
11066
+ */
11067
+
10879
11068
  /**
10880
11069
  * Metadata of the scraper
10881
11070
  *
@@ -10888,6 +11077,7 @@ var legacyDocumentScraperMetadata = $deepFreeze({
10888
11077
  mimeTypes: ['application/msword', 'text/rtf'],
10889
11078
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
10890
11079
  isAvilableInBrowser: false,
11080
+ // <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
10891
11081
  requiredExecutables: [
10892
11082
  'Pandoc',
10893
11083
  'LibreOffice',
@@ -10900,6 +11090,7 @@ var legacyDocumentScraperMetadata = $deepFreeze({
10900
11090
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
10901
11091
  *
10902
11092
  * @public exported from `@promptbook/core`
11093
+ * @public exported from `@promptbook/wizzard`
10903
11094
  * @public exported from `@promptbook/cli`
10904
11095
  */
10905
11096
  var _LegacyDocumentScraperMetadataRegistration = $scrapersMetadataRegister.register(legacyDocumentScraperMetadata);
@@ -10919,6 +11110,7 @@ var documentScraperMetadata = $deepFreeze({
10919
11110
  mimeTypes: ['application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
10920
11111
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
10921
11112
  isAvilableInBrowser: false,
11113
+ // <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
10922
11114
  requiredExecutables: ['Pandoc'],
10923
11115
  }); /* <- Note: [🤛] */
10924
11116
  /**
@@ -10927,6 +11119,7 @@ var documentScraperMetadata = $deepFreeze({
10927
11119
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
10928
11120
  *
10929
11121
  * @public exported from `@promptbook/core`
11122
+ * @public exported from `@promptbook/wizzard`
10930
11123
  * @public exported from `@promptbook/cli`
10931
11124
  */
10932
11125
  var _DocumentScraperMetadataRegistration = $scrapersMetadataRegister.register(documentScraperMetadata);
@@ -10946,6 +11139,7 @@ var markdownScraperMetadata = $deepFreeze({
10946
11139
  mimeTypes: ['text/markdown', 'text/plain'],
10947
11140
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
10948
11141
  isAvilableInBrowser: true,
11142
+ // <- Note: [🌏] This is the only scraper which makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
10949
11143
  requiredExecutables: [],
10950
11144
  }); /* <- Note: [🤛] */
10951
11145
  /**
@@ -10954,6 +11148,7 @@ var markdownScraperMetadata = $deepFreeze({
10954
11148
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
10955
11149
  *
10956
11150
  * @public exported from `@promptbook/core`
11151
+ * @public exported from `@promptbook/wizzard`
10957
11152
  * @public exported from `@promptbook/cli`
10958
11153
  */
10959
11154
  var _MarkdownScraperMetadataRegistration = $scrapersMetadataRegister.register(markdownScraperMetadata);
@@ -10972,7 +11167,8 @@ var pdfScraperMetadata = $deepFreeze({
10972
11167
  className: 'PdfScraper',
10973
11168
  mimeTypes: ['application/pdf'],
10974
11169
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
10975
- isAvilableInBrowser: true,
11170
+ isAvilableInBrowser: false,
11171
+ // <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
10976
11172
  requiredExecutables: [],
10977
11173
  }); /* <- Note: [🤛] */
10978
11174
  /**
@@ -10981,6 +11177,7 @@ var pdfScraperMetadata = $deepFreeze({
10981
11177
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
10982
11178
  *
10983
11179
  * @public exported from `@promptbook/core`
11180
+ * @public exported from `@promptbook/wizzard`
10984
11181
  * @public exported from `@promptbook/cli`
10985
11182
  */
10986
11183
  var _PdfScraperMetadataRegistration = $scrapersMetadataRegister.register(pdfScraperMetadata);
@@ -11000,6 +11197,7 @@ var websiteScraperMetadata = $deepFreeze({
11000
11197
  mimeTypes: ['text/html'],
11001
11198
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
11002
11199
  isAvilableInBrowser: false,
11200
+ // <- Note: [🌏] Only `MarkdownScraper` makes sense to be available in the browser, for scraping non-markdown sources in the browser use a remote server
11003
11201
  requiredExecutables: [],
11004
11202
  }); /* <- Note: [🤛] */
11005
11203
  /**
@@ -11008,6 +11206,7 @@ var websiteScraperMetadata = $deepFreeze({
11008
11206
  * Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available known scrapers
11009
11207
  *
11010
11208
  * @public exported from `@promptbook/core`
11209
+ * @public exported from `@promptbook/wizzard`
11011
11210
  * @public exported from `@promptbook/cli`
11012
11211
  */
11013
11212
  var _WebsiteScraperMetadataRegistration = $scrapersMetadataRegister.register(websiteScraperMetadata);
@@ -11096,5 +11295,5 @@ var PrefixStorage = /** @class */ (function () {
11096
11295
  return PrefixStorage;
11097
11296
  }());
11098
11297
 
11099
- export { $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, ADMIN_EMAIL, ADMIN_GITHUB_NAME, AbstractFormatError, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateError, BoilerplateFormfactorDefinition, CLAIM, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CsvFormatDefinition, CsvFormatError, DEFAULT_BOOKS_DIRNAME, DEFAULT_CSV_SETTINGS, DEFAULT_EXECUTIONS_CACHE_DIRNAME, DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TITLE, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FORMFACTOR_DEFINITIONS, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, KnowledgeScrapeError, LOGO_DARK_SRC, LOGO_LIGHT_SRC, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NAME, NonTaskSectionTypes, NotFoundError, NotYetImplementedError, ORDER_OF_PIPELINE_JSON, PROMPTBOOK_ENGINE_VERSION, PROMPTBOOK_ERRORS, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, RESERVED_PARAMETER_NAMES, SET_IS_VERBOSE, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatDefinition, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UnexpectedError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _DocumentScraperMetadataRegistration, _GoogleMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, addUsage, assertsExecutionSuccessful, cacheLlmTools, collectionToJson, compilePipeline, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, extractParameterNamesFromTask, getPipelineInterface, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, pipelineJsonToString, precompilePipeline, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTasks, prettifyPipelineString, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline };
11298
+ export { $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, ADMIN_EMAIL, ADMIN_GITHUB_NAME, AbstractFormatError, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateError, BoilerplateFormfactorDefinition, CLAIM, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CsvFormatDefinition, CsvFormatError, DEFAULT_BOOKS_DIRNAME, DEFAULT_BOOK_TITLE, DEFAULT_CSV_SETTINGS, DEFAULT_EXECUTIONS_CACHE_DIRNAME, DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, DEFAULT_SCRAPE_CACHE_DIRNAME, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FORMFACTOR_DEFINITIONS, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, ImageGeneratorFormfactorDefinition, KnowledgeScrapeError, LOGO_DARK_SRC, LOGO_LIGHT_SRC, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NAME, NonTaskSectionTypes, NotFoundError, NotYetImplementedError, ORDER_OF_PIPELINE_JSON, PROMPTBOOK_ENGINE_VERSION, PROMPTBOOK_ERRORS, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, RESERVED_PARAMETER_NAMES, SET_IS_VERBOSE, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatDefinition, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UnexpectedError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _DocumentScraperMetadataRegistration, _GoogleMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, addUsage, assertsExecutionSuccessful, book, cacheLlmTools, collectionToJson, compilePipeline, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, extractParameterNamesFromTask, getPipelineInterface, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, isValidPipelineString, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, parsePipeline, pipelineJsonToString, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTasks, prettifyPipelineString, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline, validatePipelineString };
11100
11299
  //# sourceMappingURL=index.es.js.map