@promptbook/core 0.52.0-2 → 0.52.0-24

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 (50) hide show
  1. package/README.md +7 -6
  2. package/esm/index.es.js +1105 -179
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/_packages/core.index.d.ts +16 -6
  5. package/esm/typings/_packages/utils.index.d.ts +3 -8
  6. package/esm/typings/execution/ExecutionTools.d.ts +5 -3
  7. package/esm/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
  8. package/esm/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -0
  9. package/esm/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools.d.ts +35 -0
  10. package/esm/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionToolsOptions.d.ts +23 -0
  11. package/esm/typings/execution/plugins/llm-execution-tools/multiple/playground/playground.d.ts +2 -0
  12. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.d.ts +1 -1
  13. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools.d.ts +4 -17
  14. package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +36 -4
  15. package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts +1 -0
  16. package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +2 -2
  17. package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.test.d.ts +1 -0
  18. package/esm/typings/library/constructors/createPromptbookLibraryFromSources.test.d.ts +1 -0
  19. package/esm/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +21 -5
  20. package/esm/typings/library/constructors/justTestFsImport.d.ts +7 -0
  21. package/esm/typings/types/Prompt.d.ts +1 -1
  22. package/esm/typings/types/typeAliases.d.ts +2 -2
  23. package/package.json +3 -2
  24. package/umd/index.umd.js +1117 -182
  25. package/umd/index.umd.js.map +1 -1
  26. package/umd/typings/_packages/core.index.d.ts +16 -6
  27. package/umd/typings/_packages/utils.index.d.ts +3 -8
  28. package/umd/typings/execution/ExecutionTools.d.ts +5 -3
  29. package/umd/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
  30. package/umd/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -0
  31. package/umd/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools.d.ts +35 -0
  32. package/umd/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionToolsOptions.d.ts +23 -0
  33. package/umd/typings/execution/plugins/llm-execution-tools/multiple/playground/playground.d.ts +2 -0
  34. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.d.ts +1 -1
  35. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools.d.ts +4 -17
  36. package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +36 -4
  37. package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts +1 -0
  38. package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +2 -2
  39. package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.test.d.ts +1 -0
  40. package/umd/typings/library/constructors/createPromptbookLibraryFromSources.test.d.ts +1 -0
  41. package/umd/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +21 -5
  42. package/umd/typings/library/constructors/justTestFsImport.d.ts +7 -0
  43. package/umd/typings/types/Prompt.d.ts +1 -1
  44. package/umd/typings/types/typeAliases.d.ts +2 -2
  45. package/esm/typings/_packages/wizzard.index.d.ts +0 -5
  46. package/esm/typings/wizzard/Wizzard.d.ts +0 -4
  47. package/esm/typings/wizzard/sample.d.ts +0 -6
  48. package/umd/typings/_packages/wizzard.index.d.ts +0 -5
  49. package/umd/typings/wizzard/Wizzard.d.ts +0 -4
  50. package/umd/typings/wizzard/sample.d.ts +0 -6
package/esm/index.es.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import spaceTrim$1, { spaceTrim } from 'spacetrim';
2
2
  import { format } from 'prettier';
3
3
  import parserHtml from 'prettier/parser-html';
4
- import 'moment';
4
+ import { join } from 'path';
5
+ import moment from 'moment';
5
6
 
6
7
  /*! *****************************************************************************
7
8
  Copyright (c) Microsoft Corporation.
@@ -447,7 +448,7 @@ function union() {
447
448
  /**
448
449
  * The version of the Promptbook library
449
450
  */
450
- var PROMPTBOOK_VERSION = '0.52.0-1';
451
+ var PROMPTBOOK_VERSION = '0.52.0-23';
451
452
 
452
453
  /**
453
454
  * Parses the template and returns the list of all parameter names
@@ -569,38 +570,6 @@ function extractParametersFromPromptTemplate(promptTemplate) {
569
570
  * TODO: [🔣] If script require contentLanguage
570
571
  */
571
572
 
572
- /**
573
- * Prettify the html code
574
- *
575
- * @param content raw html code
576
- * @returns formatted html code
577
- */
578
- function prettifyMarkdown(content) {
579
- try {
580
- return format(content, {
581
- parser: 'markdown',
582
- plugins: [parserHtml],
583
- // TODO: DRY - make some import or auto-copy of .prettierrc
584
- endOfLine: 'lf',
585
- tabWidth: 4,
586
- singleQuote: true,
587
- trailingComma: 'all',
588
- arrowParens: 'always',
589
- printWidth: 120,
590
- htmlWhitespaceSensitivity: 'ignore',
591
- jsxBracketSameLine: false,
592
- bracketSpacing: true,
593
- });
594
- }
595
- catch (error) {
596
- console.error('There was an error with prettifying the markdown, using the original as the fallback', {
597
- error: error,
598
- html: content,
599
- });
600
- return content;
601
- }
602
- }
603
-
604
573
  /**
605
574
  * Removes emojis from a string and fix whitespaces
606
575
  *
@@ -626,6 +595,64 @@ function titleToName(value) {
626
595
  return value;
627
596
  }
628
597
 
598
+ /**
599
+ * Creates a Mermaid graph based on the promptbook
600
+ *
601
+ * Note: The result is not wrapped in a Markdown code block
602
+ */
603
+ function renderPromptbookMermaid(promptbookJson, options) {
604
+ var _a = (options || {}).linkPromptTemplate, linkPromptTemplate = _a === void 0 ? function () { return null; } : _a;
605
+ var parameterNameToTemplateName = function (parameterName) {
606
+ var parameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
607
+ if (!parameter) {
608
+ throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
609
+ }
610
+ if (parameter.isInput) {
611
+ return 'input';
612
+ }
613
+ var template = promptbookJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
614
+ if (!template) {
615
+ throw new Error("Could not find template for {".concat(parameterName, "}"));
616
+ }
617
+ return normalizeTo_camelCase('template-' + titleToName(template.title));
618
+ };
619
+ var promptbookMermaid = spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(promptbookJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson.promptTemplates
620
+ .flatMap(function (_a) {
621
+ var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
622
+ return __spreadArray([
623
+ "".concat(parameterNameToTemplateName(resultingParameterName), "(\"").concat(title, "\")")
624
+ ], __read(dependentParameterNames.map(function (dependentParameterName) {
625
+ return "".concat(parameterNameToTemplateName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName(resultingParameterName));
626
+ })), false);
627
+ })
628
+ .join('\n')), "\n\n ").concat(block(promptbookJson.parameters
629
+ .filter(function (_a) {
630
+ var isOutput = _a.isOutput;
631
+ return isOutput;
632
+ })
633
+ .map(function (_a) {
634
+ var name = _a.name;
635
+ return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
636
+ })
637
+ .join('\n')), "\n output((Output)):::output\n\n ").concat(block(promptbookJson.promptTemplates
638
+ .map(function (promptTemplate) {
639
+ var link = linkPromptTemplate(promptTemplate);
640
+ if (link === null) {
641
+ return '';
642
+ }
643
+ var href = link.href, title = link.title;
644
+ var templateName = parameterNameToTemplateName(promptTemplate.resultingParameterName);
645
+ return "click ".concat(templateName, " href \"").concat(href, "\" \"").concat(title, "\";");
646
+ })
647
+ .filter(function (line) { return line !== ''; })
648
+ .join('\n')), "\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
649
+ return promptbookMermaid;
650
+ }
651
+ /**
652
+ * TODO: Maybe use some Mermaid library instead of string templating
653
+ * TODO: [🕌] When more than 2 functionalities, split into separate functions
654
+ */
655
+
629
656
  /**
630
657
  * Function parseNumber will parse number from string
631
658
  *
@@ -708,35 +735,80 @@ var PromptbookLogicError = /** @class */ (function (_super) {
708
735
  }(Error));
709
736
 
710
737
  /**
711
- * This error indicates errors during the execution of the promptbook
738
+ * This error occurs during the parameter replacement in the template
739
+ *
740
+ * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
712
741
  */
713
- var PromptbookExecutionError = /** @class */ (function (_super) {
714
- __extends(PromptbookExecutionError, _super);
715
- function PromptbookExecutionError(message) {
742
+ var TemplateError = /** @class */ (function (_super) {
743
+ __extends(TemplateError, _super);
744
+ function TemplateError(message) {
716
745
  var _this = _super.call(this, message) || this;
717
- _this.name = 'PromptbookExecutionError';
718
- Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
746
+ _this.name = 'TemplateError';
747
+ Object.setPrototypeOf(_this, TemplateError.prototype);
719
748
  return _this;
720
749
  }
721
- return PromptbookExecutionError;
750
+ return TemplateError;
722
751
  }(Error));
723
752
 
724
753
  /**
725
- * This error occurs when some expectation is not met in the execution of the pipeline
754
+ * Replaces parameters in template with values from parameters object
726
755
  *
727
- * @private Always catched and rethrown as `PromptbookExecutionError`
728
- * Note: This is a kindof subtype of PromptbookExecutionError
756
+ * @param template the template with parameters in {curly} braces
757
+ * @param parameters the object with parameters
758
+ * @returns the template with replaced parameters
759
+ * @throws {TemplateError} if parameter is not defined, not closed, or not opened
760
+ *
761
+ * @private within the createPromptbookExecutor
729
762
  */
730
- var ExpectError = /** @class */ (function (_super) {
731
- __extends(ExpectError, _super);
732
- function ExpectError(message) {
733
- var _this = _super.call(this, message) || this;
734
- _this.name = 'ExpectError';
735
- Object.setPrototypeOf(_this, ExpectError.prototype);
736
- return _this;
763
+ function replaceParameters(template, parameters) {
764
+ var replacedTemplate = template;
765
+ var match;
766
+ var loopLimit = LOOP_LIMIT;
767
+ var _loop_1 = function () {
768
+ if (loopLimit-- < 0) {
769
+ throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
770
+ }
771
+ var precol = match.groups.precol;
772
+ var parameterName = match.groups.parameterName;
773
+ if (parameterName === '') {
774
+ return "continue";
775
+ }
776
+ if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
777
+ throw new TemplateError('Parameter is already opened or not closed');
778
+ }
779
+ if (parameters[parameterName] === undefined) {
780
+ throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
781
+ }
782
+ var parameterValue = parameters[parameterName];
783
+ if (parameterValue === undefined) {
784
+ throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
785
+ }
786
+ parameterValue = parameterValue.toString();
787
+ if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
788
+ parameterValue = parameterValue
789
+ .split('\n')
790
+ .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
791
+ .join('\n');
792
+ }
793
+ replacedTemplate =
794
+ replacedTemplate.substring(0, match.index + precol.length) +
795
+ parameterValue +
796
+ replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
797
+ };
798
+ while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
799
+ .exec(replacedTemplate))) {
800
+ _loop_1();
737
801
  }
738
- return ExpectError;
739
- }(Error));
802
+ // [💫] Check if there are parameters that are not closed properly
803
+ if (/{\w+$/.test(replacedTemplate)) {
804
+ throw new TemplateError('Parameter is not closed');
805
+ }
806
+ // [💫] Check if there are parameters that are not opened properly
807
+ if (/^\w+}/.test(replacedTemplate)) {
808
+ throw new TemplateError('Parameter is not opened');
809
+ }
810
+ return replacedTemplate;
811
+ }
740
812
 
741
813
  /**
742
814
  * Counts number of characters in the text
@@ -1064,118 +1136,6 @@ var CountUtils = {
1064
1136
  PAGES: countPages,
1065
1137
  };
1066
1138
 
1067
- /**
1068
- * Function checkExpectations will check if the expectations on given value are met
1069
- *
1070
- * Note: There are two simmilar functions:
1071
- * - `checkExpectations` which throws an error if the expectations are not met
1072
- * - `isPassingExpectations` which returns a boolean
1073
- *
1074
- * @throws {ExpectError} if the expectations are not met
1075
- * @returns {void} Nothing
1076
- */
1077
- function checkExpectations(expectations, value) {
1078
- var e_1, _a;
1079
- try {
1080
- for (var _b = __values(Object.entries(expectations)), _c = _b.next(); !_c.done; _c = _b.next()) {
1081
- var _d = __read(_c.value, 2), unit = _d[0], _e = _d[1], max = _e.max, min = _e.min;
1082
- var amount = CountUtils[unit.toUpperCase()](value);
1083
- if (min && amount < min) {
1084
- throw new ExpectError("Expected at least ".concat(min, " ").concat(unit, " but got ").concat(amount));
1085
- } /* not else */
1086
- if (max && amount > max) {
1087
- throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
1088
- }
1089
- }
1090
- }
1091
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1092
- finally {
1093
- try {
1094
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1095
- }
1096
- finally { if (e_1) throw e_1.error; }
1097
- }
1098
- }
1099
- /**
1100
- * TODO: [💝] Unite object for expecting amount and format
1101
- */
1102
-
1103
- /**
1104
- * This error occurs during the parameter replacement in the template
1105
- *
1106
- * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
1107
- */
1108
- var TemplateError = /** @class */ (function (_super) {
1109
- __extends(TemplateError, _super);
1110
- function TemplateError(message) {
1111
- var _this = _super.call(this, message) || this;
1112
- _this.name = 'TemplateError';
1113
- Object.setPrototypeOf(_this, TemplateError.prototype);
1114
- return _this;
1115
- }
1116
- return TemplateError;
1117
- }(Error));
1118
-
1119
- /**
1120
- * Replaces parameters in template with values from parameters object
1121
- *
1122
- * @param template the template with parameters in {curly} braces
1123
- * @param parameters the object with parameters
1124
- * @returns the template with replaced parameters
1125
- * @throws {TemplateError} if parameter is not defined, not closed, or not opened
1126
- *
1127
- * @private within the createPromptbookExecutor
1128
- */
1129
- function replaceParameters(template, parameters) {
1130
- var replacedTemplate = template;
1131
- var match;
1132
- var loopLimit = LOOP_LIMIT;
1133
- var _loop_1 = function () {
1134
- if (loopLimit-- < 0) {
1135
- throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
1136
- }
1137
- var precol = match.groups.precol;
1138
- var parameterName = match.groups.parameterName;
1139
- if (parameterName === '') {
1140
- return "continue";
1141
- }
1142
- if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
1143
- throw new TemplateError('Parameter is already opened or not closed');
1144
- }
1145
- if (parameters[parameterName] === undefined) {
1146
- throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
1147
- }
1148
- var parameterValue = parameters[parameterName];
1149
- if (parameterValue === undefined) {
1150
- throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
1151
- }
1152
- parameterValue = parameterValue.toString();
1153
- if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
1154
- parameterValue = parameterValue
1155
- .split('\n')
1156
- .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
1157
- .join('\n');
1158
- }
1159
- replacedTemplate =
1160
- replacedTemplate.substring(0, match.index + precol.length) +
1161
- parameterValue +
1162
- replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
1163
- };
1164
- while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
1165
- .exec(replacedTemplate))) {
1166
- _loop_1();
1167
- }
1168
- // [💫] Check if there are parameters that are not closed properly
1169
- if (/{\w+$/.test(replacedTemplate)) {
1170
- throw new TemplateError('Parameter is not closed');
1171
- }
1172
- // [💫] Check if there are parameters that are not opened properly
1173
- if (/^\w+}/.test(replacedTemplate)) {
1174
- throw new TemplateError('Parameter is not opened');
1175
- }
1176
- return replacedTemplate;
1177
- }
1178
-
1179
1139
  /**
1180
1140
  * Function isValidJsonString will tell you if the string is valid JSON or not
1181
1141
  */
@@ -1330,6 +1290,61 @@ function normalizeToKebabCase(sentence) {
1330
1290
  return normalizedName;
1331
1291
  }
1332
1292
 
1293
+ /* tslint:disable */
1294
+ function normalizeTo_camelCase(sentence, __firstLetterCapital) {
1295
+ var e_1, _a;
1296
+ if (__firstLetterCapital === void 0) { __firstLetterCapital = false; }
1297
+ var charType;
1298
+ var lastCharType = null;
1299
+ var normalizedName = '';
1300
+ try {
1301
+ for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1302
+ var char = sentence_1_1.value;
1303
+ var normalizedChar = void 0;
1304
+ if (/^[a-z]$/.test(char)) {
1305
+ charType = 'LOWERCASE';
1306
+ normalizedChar = char;
1307
+ }
1308
+ else if (/^[A-Z]$/.test(char)) {
1309
+ charType = 'UPPERCASE';
1310
+ normalizedChar = char.toLowerCase();
1311
+ }
1312
+ else if (/^[0-9]$/.test(char)) {
1313
+ charType = 'NUMBER';
1314
+ normalizedChar = char;
1315
+ }
1316
+ else {
1317
+ charType = 'OTHER';
1318
+ normalizedChar = '';
1319
+ }
1320
+ if (!lastCharType) {
1321
+ if (__firstLetterCapital) {
1322
+ normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
1323
+ }
1324
+ }
1325
+ else if (charType !== lastCharType &&
1326
+ !(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
1327
+ !(lastCharType === 'NUMBER') &&
1328
+ !(charType === 'NUMBER')) {
1329
+ normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
1330
+ }
1331
+ normalizedName += normalizedChar;
1332
+ lastCharType = charType;
1333
+ }
1334
+ }
1335
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1336
+ finally {
1337
+ try {
1338
+ if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
1339
+ }
1340
+ finally { if (e_1) throw e_1.error; }
1341
+ }
1342
+ return normalizedName;
1343
+ }
1344
+ /**
1345
+ * TODO: [🌺] Use some intermediate util splitWords
1346
+ */
1347
+
1333
1348
  /**
1334
1349
  * Execution type describes the way how the block is executed
1335
1350
  *
@@ -1848,6 +1863,87 @@ function promptbookStringToJson(promptbookString) {
1848
1863
  * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
1849
1864
  */
1850
1865
 
1866
+ /**
1867
+ * Add or modify an auto-generated section in a markdown file
1868
+ *
1869
+ * @private within the library
1870
+ */
1871
+ function addAutoGeneratedSection(content, options) {
1872
+ var sectionName = options.sectionName, sectionContent = options.sectionContent;
1873
+ var warningLine = "<!-- \u26A0\uFE0F WARNING: This section was auto-generated -->";
1874
+ var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
1875
+ var sectionMatch = content.match(sectionRegex);
1876
+ if (sectionMatch) {
1877
+ return content.replace(sectionRegex, spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
1878
+ }
1879
+ var placeForSection = removeContentComments(content).match(/^##.*$/im);
1880
+ if (!placeForSection) {
1881
+ throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
1882
+ }
1883
+ var _a = __read(placeForSection, 1), heading = _a[0];
1884
+ return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
1885
+ }
1886
+
1887
+ /**
1888
+ * Prettify the html code
1889
+ *
1890
+ * @param content raw html code
1891
+ * @returns formatted html code
1892
+ */
1893
+ function prettifyMarkdown(content) {
1894
+ try {
1895
+ return format(content, {
1896
+ parser: 'markdown',
1897
+ plugins: [parserHtml],
1898
+ // TODO: DRY - make some import or auto-copy of .prettierrc
1899
+ endOfLine: 'lf',
1900
+ tabWidth: 4,
1901
+ singleQuote: true,
1902
+ trailingComma: 'all',
1903
+ arrowParens: 'always',
1904
+ printWidth: 120,
1905
+ htmlWhitespaceSensitivity: 'ignore',
1906
+ jsxBracketSameLine: false,
1907
+ bracketSpacing: true,
1908
+ });
1909
+ }
1910
+ catch (error) {
1911
+ console.error('There was an error with prettifying the markdown, using the original as the fallback', {
1912
+ error: error,
1913
+ html: content,
1914
+ });
1915
+ return content;
1916
+ }
1917
+ }
1918
+
1919
+ /**
1920
+ * Prettyfies Promptbook string and adds Mermaid graph
1921
+ */
1922
+ function prettifyPromptbookString(promptbookString, options) {
1923
+ var isGraphAdded = options.isGraphAdded, isPrettifyed = options.isPrettifyed;
1924
+ if (isGraphAdded) {
1925
+ var promptbookJson = promptbookStringToJson(promptbookString);
1926
+ var promptbookMermaid_1 = renderPromptbookMermaid(promptbookJson, {
1927
+ linkPromptTemplate: function (promptTemplate) {
1928
+ return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
1929
+ },
1930
+ });
1931
+ var promptbookMermaidBlock = spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
1932
+ promptbookString = addAutoGeneratedSection(promptbookString, {
1933
+ sectionName: 'Graph',
1934
+ sectionContent: promptbookMermaidBlock,
1935
+ });
1936
+ }
1937
+ if (isPrettifyed) {
1938
+ promptbookString = prettifyMarkdown(promptbookString);
1939
+ }
1940
+ return promptbookString;
1941
+ }
1942
+ /**
1943
+ * TODO: Maybe use some Mermaid library instead of string templating
1944
+ * TODO: [🕌] When more than 2 functionalities, split into separate functions
1945
+ */
1946
+
1851
1947
  /**
1852
1948
  * Converts promptbook in JSON format to string format
1853
1949
  *
@@ -2222,18 +2318,131 @@ function validatePromptbookJson(promptbook) {
2222
2318
  while (unresovedTemplates.length > 0) {
2223
2319
  _loop_2();
2224
2320
  }
2225
- return promptbook;
2321
+ return promptbook;
2322
+ }
2323
+ /**
2324
+ * TODO: [🧠] Work with promptbookVersion
2325
+ * TODO: Use here some json-schema, Zod or something similar and change it to:
2326
+ * > /**
2327
+ * > * Validates PromptbookJson if it is logically valid.
2328
+ * > *
2329
+ * > * It checks:
2330
+ * > * - it has a valid structure
2331
+ * > * - ...
2332
+ * > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
2333
+ */
2334
+
2335
+ /**
2336
+ * This error indicates errors during the execution of the promptbook
2337
+ */
2338
+ var PromptbookExecutionError = /** @class */ (function (_super) {
2339
+ __extends(PromptbookExecutionError, _super);
2340
+ function PromptbookExecutionError(message) {
2341
+ var _this = _super.call(this, message) || this;
2342
+ _this.name = 'PromptbookExecutionError';
2343
+ Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
2344
+ return _this;
2345
+ }
2346
+ return PromptbookExecutionError;
2347
+ }(Error));
2348
+
2349
+ /**
2350
+ * Asserts that the execution of a promptnook is successful
2351
+ *
2352
+ * @param executionResult - The partial result of the promptnook execution
2353
+ * @throws {PromptbookExecutionError} If the execution is not successful or if multiple errors occurred
2354
+ */
2355
+ function assertsExecutionSuccessful(executionResult) {
2356
+ var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
2357
+ if (isSuccessful === true) {
2358
+ return;
2359
+ }
2360
+ if (errors.length === 0) {
2361
+ throw new PromptbookExecutionError("Promptnook Execution failed because of unknown reason");
2362
+ }
2363
+ else if (errors.length === 1) {
2364
+ throw errors[0];
2365
+ }
2366
+ else {
2367
+ throw new PromptbookExecutionError(spaceTrim(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
2368
+ }
2369
+ }
2370
+ /**
2371
+ * TODO: [🧠] Can this return type be better typed than void
2372
+ */
2373
+
2374
+ /**
2375
+ * This error occurs when some expectation is not met in the execution of the pipeline
2376
+ *
2377
+ * @private Always catched and rethrown as `PromptbookExecutionError`
2378
+ * Note: This is a kindof subtype of PromptbookExecutionError
2379
+ */
2380
+ var ExpectError = /** @class */ (function (_super) {
2381
+ __extends(ExpectError, _super);
2382
+ function ExpectError(message) {
2383
+ var _this = _super.call(this, message) || this;
2384
+ _this.name = 'ExpectError';
2385
+ Object.setPrototypeOf(_this, ExpectError.prototype);
2386
+ return _this;
2387
+ }
2388
+ return ExpectError;
2389
+ }(Error));
2390
+
2391
+ /**
2392
+ * Function checkExpectations will check if the expectations on given value are met
2393
+ *
2394
+ * Note: There are two simmilar functions:
2395
+ * - `checkExpectations` which throws an error if the expectations are not met
2396
+ * - `isPassingExpectations` which returns a boolean
2397
+ *
2398
+ * @throws {ExpectError} if the expectations are not met
2399
+ * @returns {void} Nothing
2400
+ */
2401
+ function checkExpectations(expectations, value) {
2402
+ var e_1, _a;
2403
+ try {
2404
+ for (var _b = __values(Object.entries(expectations)), _c = _b.next(); !_c.done; _c = _b.next()) {
2405
+ var _d = __read(_c.value, 2), unit = _d[0], _e = _d[1], max = _e.max, min = _e.min;
2406
+ var amount = CountUtils[unit.toUpperCase()](value);
2407
+ if (min && amount < min) {
2408
+ throw new ExpectError("Expected at least ".concat(min, " ").concat(unit, " but got ").concat(amount));
2409
+ } /* not else */
2410
+ if (max && amount > max) {
2411
+ throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
2412
+ }
2413
+ }
2414
+ }
2415
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2416
+ finally {
2417
+ try {
2418
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2419
+ }
2420
+ finally { if (e_1) throw e_1.error; }
2421
+ }
2422
+ }
2423
+ /**
2424
+ * Function checkExpectations will check if the expectations on given value are met
2425
+ *
2426
+ * Note: There are two simmilar functions:
2427
+ * - `checkExpectations` which throws an error if the expectations are not met
2428
+ * - `isPassingExpectations` which returns a boolean
2429
+ *
2430
+ * @returns {boolean} True if the expectations are met
2431
+ */
2432
+ function isPassingExpectations(expectations, value) {
2433
+ try {
2434
+ checkExpectations(expectations, value);
2435
+ return true;
2436
+ }
2437
+ catch (error) {
2438
+ if (!(error instanceof ExpectError)) {
2439
+ throw error;
2440
+ }
2441
+ return false;
2442
+ }
2226
2443
  }
2227
2444
  /**
2228
- * TODO: [🧠] Work with promptbookVersion
2229
- * TODO: Use here some json-schema, Zod or something similar and change it to:
2230
- * > /**
2231
- * > * Validates PromptbookJson if it is logically valid.
2232
- * > *
2233
- * > * It checks:
2234
- * > * - it has a valid structure
2235
- * > * - ...
2236
- * > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
2445
+ * TODO: [💝] Unite object for expecting amount and format
2237
2446
  */
2238
2447
 
2239
2448
  /**
@@ -2317,7 +2526,7 @@ function createPromptbookExecutor(options) {
2317
2526
  title: currentTemplate.title,
2318
2527
  promptbookUrl: "".concat(promptbook.promptbookUrl
2319
2528
  ? promptbook.promptbookUrl
2320
- : 'anonymous' /* <- [🧠][🈴] How to deal with anonymous PROMPTBOOKs, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
2529
+ : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous PROMPTBOOKs, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
2321
2530
  parameters: parametersToPass,
2322
2531
  content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
2323
2532
  modelRequirements: currentTemplate.modelRequirements,
@@ -2755,6 +2964,137 @@ function createPromptbookExecutor(options) {
2755
2964
  * TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
2756
2965
  */
2757
2966
 
2967
+ /**
2968
+ * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
2969
+ *
2970
+ * @see https://github.com/webgptorg/promptbook#multiple-server
2971
+ */
2972
+ var MultipleLlmExecutionTools = /** @class */ (function () {
2973
+ /**
2974
+ * Gets array of execution tools in order of priority
2975
+ */
2976
+ function MultipleLlmExecutionTools() {
2977
+ var llmExecutionTools = [];
2978
+ for (var _i = 0; _i < arguments.length; _i++) {
2979
+ llmExecutionTools[_i] = arguments[_i];
2980
+ }
2981
+ this.llmExecutionTools = llmExecutionTools;
2982
+ }
2983
+ /**
2984
+ * Calls the best available chat model
2985
+ */
2986
+ MultipleLlmExecutionTools.prototype.gptChat = function (prompt) {
2987
+ return this.gptCommon(prompt);
2988
+ };
2989
+ /**
2990
+ * Calls the best available completion model
2991
+ */
2992
+ MultipleLlmExecutionTools.prototype.gptComplete = function (prompt) {
2993
+ return this.gptCommon(prompt);
2994
+ };
2995
+ /**
2996
+ * Calls the best available model
2997
+ */
2998
+ MultipleLlmExecutionTools.prototype.gptCommon = function (prompt) {
2999
+ return __awaiter(this, void 0, void 0, function () {
3000
+ var errors, _a, _b, llmExecutionTools, error_1, e_1_1;
3001
+ var e_1, _c;
3002
+ return __generator(this, function (_d) {
3003
+ switch (_d.label) {
3004
+ case 0:
3005
+ errors = [];
3006
+ _d.label = 1;
3007
+ case 1:
3008
+ _d.trys.push([1, 11, 12, 13]);
3009
+ _a = __values(this.llmExecutionTools), _b = _a.next();
3010
+ _d.label = 2;
3011
+ case 2:
3012
+ if (!!_b.done) return [3 /*break*/, 10];
3013
+ llmExecutionTools = _b.value;
3014
+ _d.label = 3;
3015
+ case 3:
3016
+ _d.trys.push([3, 8, , 9]);
3017
+ if (!(prompt.modelRequirements.modelVariant === 'CHAT')) return [3 /*break*/, 5];
3018
+ return [4 /*yield*/, llmExecutionTools.gptChat(prompt)];
3019
+ case 4: return [2 /*return*/, _d.sent()];
3020
+ case 5:
3021
+ if (!(prompt.modelRequirements.modelVariant === 'COMPLETION')) return [3 /*break*/, 7];
3022
+ return [4 /*yield*/, llmExecutionTools.gptComplete(prompt)];
3023
+ case 6: return [2 /*return*/, _d.sent()];
3024
+ case 7: return [3 /*break*/, 9];
3025
+ case 8:
3026
+ error_1 = _d.sent();
3027
+ if (!(error_1 instanceof Error)) {
3028
+ throw error_1;
3029
+ }
3030
+ errors.push(error_1);
3031
+ return [3 /*break*/, 9];
3032
+ case 9:
3033
+ _b = _a.next();
3034
+ return [3 /*break*/, 2];
3035
+ case 10: return [3 /*break*/, 13];
3036
+ case 11:
3037
+ e_1_1 = _d.sent();
3038
+ e_1 = { error: e_1_1 };
3039
+ return [3 /*break*/, 13];
3040
+ case 12:
3041
+ try {
3042
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
3043
+ }
3044
+ finally { if (e_1) throw e_1.error; }
3045
+ return [7 /*endfinally*/];
3046
+ case 13: throw new Error(spaceTrim$1(function (block) { return "\n All execution tools failed:\n \n ".concat(block(errors.map(function (error) { return "- ".concat(error.name || 'Error', ": ").concat(error.message); }).join('\n')), "\n \n "); }));
3047
+ }
3048
+ });
3049
+ });
3050
+ };
3051
+ /**
3052
+ * List all available models that can be used
3053
+ * This liost is a combination of all available models from all execution tools
3054
+ */
3055
+ MultipleLlmExecutionTools.prototype.listModels = function () {
3056
+ return __awaiter(this, void 0, void 0, function () {
3057
+ var availableModels, _a, _b, llmExecutionTools, models, e_2_1;
3058
+ var e_2, _c;
3059
+ return __generator(this, function (_d) {
3060
+ switch (_d.label) {
3061
+ case 0:
3062
+ availableModels = [];
3063
+ _d.label = 1;
3064
+ case 1:
3065
+ _d.trys.push([1, 6, 7, 8]);
3066
+ _a = __values(this.llmExecutionTools), _b = _a.next();
3067
+ _d.label = 2;
3068
+ case 2:
3069
+ if (!!_b.done) return [3 /*break*/, 5];
3070
+ llmExecutionTools = _b.value;
3071
+ return [4 /*yield*/, llmExecutionTools.listModels()];
3072
+ case 3:
3073
+ models = _d.sent();
3074
+ availableModels.push.apply(availableModels, __spreadArray([], __read(models), false));
3075
+ _d.label = 4;
3076
+ case 4:
3077
+ _b = _a.next();
3078
+ return [3 /*break*/, 2];
3079
+ case 5: return [3 /*break*/, 8];
3080
+ case 6:
3081
+ e_2_1 = _d.sent();
3082
+ e_2 = { error: e_2_1 };
3083
+ return [3 /*break*/, 8];
3084
+ case 7:
3085
+ try {
3086
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
3087
+ }
3088
+ finally { if (e_2) throw e_2.error; }
3089
+ return [7 /*endfinally*/];
3090
+ case 8: return [2 /*return*/, availableModels];
3091
+ }
3092
+ });
3093
+ });
3094
+ };
3095
+ return MultipleLlmExecutionTools;
3096
+ }());
3097
+
2758
3098
  /**
2759
3099
  * Delagates the user interaction to a async callback function
2760
3100
  * You need to provide your own implementation of this callback function and its bind to UI.
@@ -2816,6 +3156,36 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
2816
3156
  return SimplePromptInterfaceTools;
2817
3157
  }());
2818
3158
 
3159
+ /**
3160
+ * Detects if the code is running in a browser environment in main thread (Not in a web worker)
3161
+ */
3162
+ new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
3163
+ /**
3164
+ * Detects if the code is running in a Node.js environment
3165
+ */
3166
+ var isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
3167
+ /**
3168
+ * Detects if the code is running in a web worker
3169
+ */
3170
+ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
3171
+
3172
+ /**
3173
+ * Returns the same value that is passed as argument.
3174
+ * No side effects.
3175
+ *
3176
+ * Note: It can be usefull for leveling indentation
3177
+ *
3178
+ * @param value any values
3179
+ * @returns the same values
3180
+ */
3181
+ function just(value) {
3182
+ if (value === undefined) {
3183
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3184
+ return undefined;
3185
+ }
3186
+ return value;
3187
+ }
3188
+
2819
3189
  /**
2820
3190
  * This error indicates that promptbook not found in the library
2821
3191
  */
@@ -2873,6 +3243,12 @@ var SimplePromptbookLibrary = /** @class */ (function () {
2873
3243
  throw new PromptbookReferenceError(spaceTrim("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the promptbook library\n\n ")));
2874
3244
  }
2875
3245
  validatePromptbookJson(promptbook);
3246
+ // Note: [🦄]
3247
+ if (this.library.has(promptbook.promptbookUrl) &&
3248
+ promptbookJsonToString(promptbook) !==
3249
+ promptbookJsonToString(this.library.get(promptbook.promptbookUrl))) {
3250
+ throw new PromptbookReferenceError(spaceTrim("\n Promptbook with URL \"".concat(promptbook.promptbookUrl, "\" is already in the library\n\n Note: Promptbooks with the same URL are not allowed\n Note: Automatically check whether the promptbooks are the same BUT they are DIFFERENT\n\n ")));
3251
+ }
2876
3252
  this.library.set(promptbook.promptbookUrl, promptbook);
2877
3253
  }
2878
3254
  }
@@ -2899,6 +3275,9 @@ var SimplePromptbookLibrary = /** @class */ (function () {
2899
3275
  var _this = this;
2900
3276
  var promptbook = this.library.get(url);
2901
3277
  if (!promptbook) {
3278
+ if (this.listPromptbooks().length === 0) {
3279
+ throw new PromptbookNotFoundError(spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
3280
+ }
2902
3281
  throw new PromptbookNotFoundError(spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
2903
3282
  .map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
2904
3283
  .join('\n')), "\n\n "); }));
@@ -2971,11 +3350,11 @@ function createPromptbookLibraryFromSources() {
2971
3350
  * Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
2972
3351
  * when error occurs in given promise or factory function, it is thrown during `listPromptbooks` or `getPromptbookByUrl` call
2973
3352
  *
3353
+ * Note: Consider using `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
2974
3354
  *
2975
3355
  * @param promptbookSourcesPromiseOrFactory
2976
3356
  * @returns PromptbookLibrary
2977
- *
2978
- * @deprecated Consider using `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
3357
+ * @private Just internal tool for other constructor functions
2979
3358
  */
2980
3359
  function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
2981
3360
  var library;
@@ -3044,6 +3423,228 @@ function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3044
3423
  * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
3045
3424
  */
3046
3425
 
3426
+ /**
3427
+ * Constructs Promptbook from given directory
3428
+ *
3429
+ * Note: Works only in Node.js environment because it reads the file system
3430
+ *
3431
+ * @param path - path to the directory with promptbooks
3432
+ * @param options - Misc options for the library
3433
+ * @returns PromptbookLibrary
3434
+ */
3435
+ function createPromptbookLibraryFromDirectory(path, options) {
3436
+ return __awaiter(this, void 0, void 0, function () {
3437
+ var _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, library;
3438
+ var _this = this;
3439
+ return __generator(this, function (_e) {
3440
+ switch (_e.label) {
3441
+ case 0:
3442
+ if (!isRunningInNode()) {
3443
+ throw new Error('Function `createPromptbookLibraryFromDirectory` can only be run in Node.js environment because it reads the file system.');
3444
+ }
3445
+ _a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d;
3446
+ library = createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3447
+ var fsPromises, readFile, fileNames, promptbooks, fileNames_1, fileNames_1_1, fileName, promptbook, promptbookString, _a, _b, e_1_1;
3448
+ var e_1, _c;
3449
+ return __generator(this, function (_d) {
3450
+ switch (_d.label) {
3451
+ case 0:
3452
+ if (isVerbose) {
3453
+ console.info("Creating promptbook library from path ".concat(path));
3454
+ }
3455
+ fsPromises = require(just('fs/promises') /* <- Note: [1] */);
3456
+ readFile = fsPromises.readFile;
3457
+ return [4 /*yield*/, listAllFiles(path, isRecursive)];
3458
+ case 1:
3459
+ fileNames = _d.sent();
3460
+ if (isVerbose) {
3461
+ console.info('createPromptbookLibraryFromDirectory', { path: path, isRecursive: isRecursive, fileNames: fileNames });
3462
+ }
3463
+ promptbooks = [];
3464
+ _d.label = 2;
3465
+ case 2:
3466
+ _d.trys.push([2, 11, 12, 13]);
3467
+ fileNames_1 = __values(fileNames), fileNames_1_1 = fileNames_1.next();
3468
+ _d.label = 3;
3469
+ case 3:
3470
+ if (!!fileNames_1_1.done) return [3 /*break*/, 10];
3471
+ fileName = fileNames_1_1.value;
3472
+ promptbook = null;
3473
+ if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 5];
3474
+ return [4 /*yield*/, readFile(fileName, 'utf8')];
3475
+ case 4:
3476
+ promptbookString = (_d.sent());
3477
+ promptbook = promptbookStringToJson(promptbookString);
3478
+ return [3 /*break*/, 8];
3479
+ case 5:
3480
+ if (!fileName.endsWith('.ptbk.json')) return [3 /*break*/, 7];
3481
+ if (isVerbose) {
3482
+ console.info("Loading ".concat(fileName));
3483
+ }
3484
+ _b = (_a = JSON).parse;
3485
+ return [4 /*yield*/, readFile(fileName, 'utf8')];
3486
+ case 6:
3487
+ // TODO: Handle non-valid JSON files
3488
+ promptbook = _b.apply(_a, [_d.sent()]);
3489
+ return [3 /*break*/, 8];
3490
+ case 7:
3491
+ if (isVerbose) {
3492
+ console.info("Skipping file ".concat(fileName));
3493
+ }
3494
+ _d.label = 8;
3495
+ case 8:
3496
+ // ---
3497
+ if (promptbook !== null) {
3498
+ if (!promptbook.promptbookUrl) {
3499
+ if (isVerbose) {
3500
+ console.info("Not loading ".concat(fileName, " - missing URL"));
3501
+ }
3502
+ }
3503
+ else {
3504
+ if (isVerbose) {
3505
+ console.info("Loading ".concat(fileName));
3506
+ }
3507
+ // Note: [🦄] Promptbook with same url uniqueness will be checked automatically in SimplePromptbookLibrary
3508
+ promptbooks.push(promptbook);
3509
+ }
3510
+ }
3511
+ _d.label = 9;
3512
+ case 9:
3513
+ fileNames_1_1 = fileNames_1.next();
3514
+ return [3 /*break*/, 3];
3515
+ case 10: return [3 /*break*/, 13];
3516
+ case 11:
3517
+ e_1_1 = _d.sent();
3518
+ e_1 = { error: e_1_1 };
3519
+ return [3 /*break*/, 13];
3520
+ case 12:
3521
+ try {
3522
+ if (fileNames_1_1 && !fileNames_1_1.done && (_c = fileNames_1.return)) _c.call(fileNames_1);
3523
+ }
3524
+ finally { if (e_1) throw e_1.error; }
3525
+ return [7 /*endfinally*/];
3526
+ case 13: return [2 /*return*/, promptbooks];
3527
+ }
3528
+ });
3529
+ }); });
3530
+ if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
3531
+ return [4 /*yield*/, library.listPromptbooks()];
3532
+ case 1:
3533
+ _e.sent();
3534
+ _e.label = 2;
3535
+ case 2: return [2 /*return*/, library];
3536
+ }
3537
+ });
3538
+ });
3539
+ }
3540
+ /**
3541
+ * Reads all files in the directory
3542
+ *
3543
+ * @param path
3544
+ * @param isRecursive
3545
+ * @returns List of all files in the directory
3546
+ * @private internal function for `createPromptbookLibraryFromDirectory`
3547
+ */
3548
+ function listAllFiles(path, isRecursive) {
3549
+ return __awaiter(this, void 0, void 0, function () {
3550
+ var fsPromises, readdir, dirents, fileNames, _a, _b, dirent, subPath, _c, _d, _e, _f, e_2_1;
3551
+ var e_2, _g;
3552
+ return __generator(this, function (_h) {
3553
+ switch (_h.label) {
3554
+ case 0:
3555
+ fsPromises = require(just('fs/promises') /* <- Note: [1] */);
3556
+ readdir = fsPromises.readdir;
3557
+ return [4 /*yield*/, readdir(path, {
3558
+ withFileTypes: true /* Note: This is not working: recursive: isRecursive */,
3559
+ })];
3560
+ case 1:
3561
+ dirents = _h.sent();
3562
+ fileNames = dirents.filter(function (dirent) { return dirent.isFile(); }).map(function (_a) {
3563
+ var name = _a.name;
3564
+ return join(path, name);
3565
+ });
3566
+ if (!isRecursive) return [3 /*break*/, 9];
3567
+ _h.label = 2;
3568
+ case 2:
3569
+ _h.trys.push([2, 7, 8, 9]);
3570
+ _a = __values(dirents.filter(function (dirent) { return dirent.isDirectory(); })), _b = _a.next();
3571
+ _h.label = 3;
3572
+ case 3:
3573
+ if (!!_b.done) return [3 /*break*/, 6];
3574
+ dirent = _b.value;
3575
+ subPath = join(path, dirent.name);
3576
+ _d = (_c = fileNames.push).apply;
3577
+ _e = [fileNames];
3578
+ _f = [[]];
3579
+ return [4 /*yield*/, listAllFiles(subPath, isRecursive)];
3580
+ case 4:
3581
+ _d.apply(_c, _e.concat([__spreadArray.apply(void 0, _f.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
3582
+ _h.label = 5;
3583
+ case 5:
3584
+ _b = _a.next();
3585
+ return [3 /*break*/, 3];
3586
+ case 6: return [3 /*break*/, 9];
3587
+ case 7:
3588
+ e_2_1 = _h.sent();
3589
+ e_2 = { error: e_2_1 };
3590
+ return [3 /*break*/, 9];
3591
+ case 8:
3592
+ try {
3593
+ if (_b && !_b.done && (_g = _a.return)) _g.call(_a);
3594
+ }
3595
+ finally { if (e_2) throw e_2.error; }
3596
+ return [7 /*endfinally*/];
3597
+ case 9: return [2 /*return*/, fileNames];
3598
+ }
3599
+ });
3600
+ });
3601
+ }
3602
+ /***
3603
+ * TODO: [🧠] Maybe do not do hacks like [1] and just create package @promptbook/node
3604
+ * [🍓][🚯] maybe make `@promptbook/library` package
3605
+ * TODO: Fix the dynamic import issue in Webpack (! Not working !)
3606
+ * > ./node_modules/@promptbook/core/esm/index.es.js
3607
+ * > Critical dependency: the request of a dependency is an expression
3608
+ *
3609
+ * Note: [1] Using require(just('fs/promises')) to allow
3610
+ * the `@promptbook/core` work for both Node.js and browser environments
3611
+ */
3612
+
3613
+ /**
3614
+ * Constructs Promptbook from remote Promptbase URL
3615
+
3616
+ * @returns PromptbookLibrary
3617
+ */
3618
+ function createPromptbookLibraryFromUrl(url, options) {
3619
+ return __awaiter(this, void 0, void 0, function () {
3620
+ var _a, _b, isVerbose, _c, isLazyLoaded, library;
3621
+ var _this = this;
3622
+ return __generator(this, function (_d) {
3623
+ switch (_d.label) {
3624
+ case 0:
3625
+ _a = options || {}, _b = _a.isVerbose, isVerbose = _b === void 0 ? false : _b, _c = _a.isLazyLoaded, isLazyLoaded = _c === void 0 ? false : _c;
3626
+ library = createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3627
+ return __generator(this, function (_a) {
3628
+ if (isVerbose) {
3629
+ console.info("Creating promptbook library from url ".concat(url.toString()));
3630
+ }
3631
+ throw new Error('Not implemented yet');
3632
+ });
3633
+ }); });
3634
+ if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
3635
+ return [4 /*yield*/, library.listPromptbooks()];
3636
+ case 1:
3637
+ _d.sent();
3638
+ _d.label = 2;
3639
+ case 2: return [2 /*return*/, library];
3640
+ }
3641
+ });
3642
+ });
3643
+ }
3644
+ /***
3645
+ * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
3646
+ */
3647
+
3047
3648
  /**
3048
3649
  * Creates PromptbookLibrary as a subset of another PromptbookLibrary
3049
3650
  *
@@ -3126,5 +3727,330 @@ function createPromptbookSublibrary(library, predicate) {
3126
3727
  * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
3127
3728
  */
3128
3729
 
3129
- export { CallbackInterfaceTools, ExecutionTypes, PROMPTBOOK_VERSION, SimplePromptInterfaceTools, SimplePromptbookLibrary, createPromptbookExecutor, createPromptbookLibraryFromPromise, createPromptbookLibraryFromSources, createPromptbookSublibrary, promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
3730
+ /**
3731
+ * Just testing imports and compatibility
3732
+ */
3733
+ function justTestFsImport() {
3734
+ return __awaiter(this, void 0, void 0, function () {
3735
+ var files;
3736
+ return __generator(this, function (_a) {
3737
+ switch (_a.label) {
3738
+ case 0:
3739
+ if (!isRunningInNode()) {
3740
+ throw new Error('Function `testFiles` can only be run in Node.js environment because it reads the file system.');
3741
+ }
3742
+ return [4 /*yield*/, require(just('glob-promise'))('/**/*')];
3743
+ case 1:
3744
+ files = _a.sent();
3745
+ console.info('testFiles', { files: files });
3746
+ return [2 /*return*/];
3747
+ }
3748
+ });
3749
+ });
3750
+ }
3751
+ /**
3752
+ * TODO: !!! Remove this file
3753
+ */
3754
+
3755
+ /**
3756
+ * Format either small or big number
3757
+ *
3758
+ * @private within the library
3759
+ */
3760
+ function formatNumber(value) {
3761
+ if (value === 0) {
3762
+ return '0';
3763
+ }
3764
+ for (var exponent = 0; exponent < 15; exponent++) {
3765
+ var factor = Math.pow(10, exponent);
3766
+ var valueRounded = Math.round(value * factor) / factor;
3767
+ if (Math.abs(value - valueRounded) / value <
3768
+ 0.001 /* <- TODO: Pass as option, pass to executionReportJsonToString as option */) {
3769
+ return valueRounded.toFixed(exponent);
3770
+ }
3771
+ }
3772
+ return value.toString();
3773
+ }
3774
+
3775
+ /**
3776
+ * Create a markdown table from a 2D array of strings
3777
+ *
3778
+ * @private within the library
3779
+ */
3780
+ function createMarkdownTable(table) {
3781
+ var columnWidths = table.reduce(function (widths, row) {
3782
+ row.forEach(function (cell, columnIndex) {
3783
+ var cellLength = cell.length;
3784
+ if (!widths[columnIndex] || cellLength > widths[columnIndex]) {
3785
+ widths[columnIndex] = cellLength;
3786
+ }
3787
+ });
3788
+ return widths;
3789
+ }, []);
3790
+ var header = "| ".concat(table[0]
3791
+ .map(function (cell, columnIndex) { return cell.padEnd(columnWidths[columnIndex]); })
3792
+ .join(' | '), " |");
3793
+ var separator = "|".concat(columnWidths.map(function (width) { return '-'.repeat(width + 2); }).join('|'), "|");
3794
+ var rows = table.slice(1).map(function (row) {
3795
+ var paddedRow = row.map(function (cell, columnIndex) {
3796
+ return cell.padEnd(columnWidths[columnIndex]);
3797
+ });
3798
+ return "| ".concat(paddedRow.join(' | '), " |");
3799
+ });
3800
+ return __spreadArray([header, separator], __read(rows), false).join('\n');
3801
+ }
3802
+
3803
+ /**
3804
+ * Function createMarkdownChart will draw a chart in markdown from ⬛+🟦 tiles
3805
+ *
3806
+ * @private within the library
3807
+ */
3808
+ function createMarkdownChart(options) {
3809
+ var e_1, _a;
3810
+ var nameHeader = options.nameHeader, valueHeader = options.valueHeader, items = options.items, width = options.width, unitName = options.unitName;
3811
+ var from = Math.min.apply(Math, __spreadArray([], __read(items.map(function (item) { return item.from; })), false));
3812
+ var to = Math.max.apply(Math, __spreadArray([], __read(items.map(function (item) { return item.to; })), false));
3813
+ var scale = width / (to - from);
3814
+ var table = [[nameHeader, valueHeader]];
3815
+ try {
3816
+ for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
3817
+ var item = items_1_1.value;
3818
+ var before = Math.round((item.from - from) * scale);
3819
+ var during = Math.round((item.to - item.from) * scale);
3820
+ var after = width - before - during;
3821
+ table.push([removeEmojis(item.title).trim(), '░'.repeat(before) + '█'.repeat(during) + '░'.repeat(after)]);
3822
+ }
3823
+ }
3824
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3825
+ finally {
3826
+ try {
3827
+ if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
3828
+ }
3829
+ finally { if (e_1) throw e_1.error; }
3830
+ }
3831
+ var legend = "_Note: Each \u2588 represents ".concat(formatNumber(1 / scale), " ").concat(unitName, ", width of ").concat(valueHeader.toLowerCase(), " is ").concat(formatNumber(to - from), " ").concat(unitName, " = ").concat(width, " squares_");
3832
+ return createMarkdownTable(table) + '\n\n' + legend;
3833
+ }
3834
+ /**
3835
+ * TODO: Maybe use Mermain Gant Diagrams
3836
+ * @see https://jojozhuang.github.io/tutorial/mermaid-cheat-sheet/
3837
+ */
3838
+
3839
+ /**
3840
+ * Function escapeMarkdownBlock will escape markdown block if needed
3841
+ * It is useful when you want have block in block
3842
+ */
3843
+ function escapeMarkdownBlock(value) {
3844
+ return value.replace(/```/g, '\\`\\`\\`');
3845
+ }
3846
+
3847
+ /**
3848
+ * Default options for generating an execution report string
3849
+ */
3850
+ var ExecutionReportStringOptionsDefaults = {
3851
+ taxRate: 0,
3852
+ chartsWidth: 36,
3853
+ };
3854
+
3855
+ /**
3856
+ * The thresholds for the relative time in the `moment` library.
3857
+ *
3858
+ * @see https://momentjscom.readthedocs.io/en/latest/moment/07-customization/13-relative-time-threshold/
3859
+ */
3860
+ var MOMENT_ARG_THRESHOLDS = {
3861
+ ss: 3, // <- least number of seconds to be counted in seconds, minus 1. Must be set after setting the `s` unit or without setting the `s` unit.
3862
+ };
3863
+
3864
+ /**
3865
+ * Count the duration of working time
3866
+ *
3867
+ * @private within the library
3868
+ */
3869
+ function countWorkingDuration(items) {
3870
+ var e_1, _a;
3871
+ var steps = Array.from(new Set(items.flatMap(function (item) { return [item.from, item.to]; })));
3872
+ steps.sort(function (a, b) { return a - b; });
3873
+ var intervals = steps.map(function (step, index) { return [step, steps[index + 1] || 0]; }).slice(0, -1);
3874
+ var duration = 0;
3875
+ var _loop_1 = function (interval) {
3876
+ var _b = __read(interval, 2), from = _b[0], to = _b[1];
3877
+ if (items.some(function (item) { return item.from < to && item.to > from; })) {
3878
+ duration += to - from;
3879
+ }
3880
+ };
3881
+ try {
3882
+ for (var intervals_1 = __values(intervals), intervals_1_1 = intervals_1.next(); !intervals_1_1.done; intervals_1_1 = intervals_1.next()) {
3883
+ var interval = intervals_1_1.value;
3884
+ _loop_1(interval);
3885
+ }
3886
+ }
3887
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3888
+ finally {
3889
+ try {
3890
+ if (intervals_1_1 && !intervals_1_1.done && (_a = intervals_1.return)) _a.call(intervals_1);
3891
+ }
3892
+ finally { if (e_1) throw e_1.error; }
3893
+ }
3894
+ return duration;
3895
+ }
3896
+
3897
+ /**
3898
+ * Converts execution report from JSON to string format
3899
+ */
3900
+ function executionReportJsonToString(executionReportJson, options) {
3901
+ var e_1, _a;
3902
+ var _b, _c, _d, _e, _f, _g;
3903
+ var _h = __assign(__assign({}, ExecutionReportStringOptionsDefaults), (options || {})), taxRate = _h.taxRate, chartsWidth = _h.chartsWidth;
3904
+ var executionReportString = spaceTrim(function (block) { return "\n # ".concat(executionReportJson.title || 'Execution report', "\n\n ").concat(block(executionReportJson.description || ''), "\n "); });
3905
+ var headerList = [];
3906
+ if (executionReportJson.promptbookUrl) {
3907
+ headerList.push("PROMPTBOOK URL ".concat(executionReportJson.promptbookUrl));
3908
+ }
3909
+ headerList.push("PROMPTBOOK VERSION ".concat(executionReportJson.promptbookUsedVersion) +
3910
+ (!executionReportJson.promptbookRequestedVersion
3911
+ ? ''
3912
+ : " *(requested ".concat(executionReportJson.promptbookRequestedVersion, ")*")));
3913
+ if (executionReportJson.promptExecutions.length !== 0) {
3914
+ // TODO: What if startedAt OR/AND completedAt is not defined?
3915
+ var startedAt = moment(Math.min.apply(Math, __spreadArray([], __read(executionReportJson.promptExecutions
3916
+ .filter(function (promptExecution) { var _a, _b; return (_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.start; })
3917
+ .map(function (promptExecution) { return moment(promptExecution.result.timing.start).valueOf(); })), false)));
3918
+ var completedAt = moment(Math.max.apply(Math, __spreadArray([], __read(executionReportJson.promptExecutions
3919
+ .filter(function (promptExecution) { var _a, _b; return (_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.complete; })
3920
+ .map(function (promptExecution) { return moment(promptExecution.result.timing.complete).valueOf(); })), false)));
3921
+ var timingItems = executionReportJson.promptExecutions.map(function (promptExecution) {
3922
+ var _a, _b, _c, _d;
3923
+ return ({
3924
+ title: promptExecution.prompt.title,
3925
+ from: moment((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.start).valueOf() / 1000,
3926
+ to: moment((_d = (_c = promptExecution.result) === null || _c === void 0 ? void 0 : _c.timing) === null || _d === void 0 ? void 0 : _d.complete).valueOf() / 1000,
3927
+ });
3928
+ });
3929
+ var costItems = executionReportJson.promptExecutions
3930
+ .filter(function (promptExecution) { var _a, _b; return typeof ((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) === 'number'; })
3931
+ .map(function (promptExecution) {
3932
+ var _a, _b;
3933
+ return ({
3934
+ title: promptExecution.prompt.title,
3935
+ from: 0,
3936
+ to: ((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) * (1 + taxRate),
3937
+ });
3938
+ });
3939
+ var duration = moment.duration(completedAt.diff(startedAt));
3940
+ var llmDuration = moment.duration(countWorkingDuration(timingItems) * 1000);
3941
+ var executionsWithKnownCost = executionReportJson.promptExecutions.filter(function (promptExecution) { var _a, _b; return (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) || 'UNKNOWN') !== 'UNKNOWN'; });
3942
+ var cost = executionsWithKnownCost.reduce(function (cost, promptExecution) { return cost + (promptExecution.result.usage.price || 0); }, 0);
3943
+ headerList.push("STARTED AT ".concat(moment(startedAt).format("YYYY-MM-DD HH:mm:ss")));
3944
+ headerList.push("COMPLETED AT ".concat(moment(completedAt).format("YYYY-MM-DD HH:mm:ss")));
3945
+ headerList.push("TOTAL DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
3946
+ headerList.push("TOTAL LLM DURATION ".concat(llmDuration.humanize(MOMENT_ARG_THRESHOLDS)));
3947
+ headerList.push("TOTAL COST $".concat(formatNumber(cost * (1 + taxRate))) +
3948
+ (executionsWithKnownCost.length === executionReportJson.promptExecutions.length
3949
+ ? ''
3950
+ : " *(Some cost is unknown)*") +
3951
+ (taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
3952
+ executionReportString += '\n\n' + headerList.map(function (header) { return "- ".concat(header); }).join('\n');
3953
+ executionReportString +=
3954
+ '\n\n' +
3955
+ '## 🗃 Index' +
3956
+ '\n\n' +
3957
+ executionReportJson.promptExecutions
3958
+ .map(function (promptExecution) {
3959
+ // TODO: Make some better system to convert hedings to links
3960
+ var hash = normalizeToKebabCase(promptExecution.prompt.title);
3961
+ if (/^\s*\p{Extended_Pictographic}/u.test(promptExecution.prompt.title)) {
3962
+ hash = '-' + hash;
3963
+ }
3964
+ // TODO: Make working hash link for the template in md + pdf
3965
+ return "- [".concat(promptExecution.prompt.title, "](#").concat(hash, ")");
3966
+ })
3967
+ .join('\n');
3968
+ executionReportString +=
3969
+ '\n\n' +
3970
+ '## ⌚ Time chart' +
3971
+ '\n\n' +
3972
+ createMarkdownChart({
3973
+ nameHeader: 'Template',
3974
+ valueHeader: 'Timeline',
3975
+ items: timingItems,
3976
+ width: chartsWidth,
3977
+ unitName: 'seconds',
3978
+ });
3979
+ executionReportString +=
3980
+ '\n\n' +
3981
+ '## 💸 Cost chart' +
3982
+ '\n\n' +
3983
+ createMarkdownChart({
3984
+ nameHeader: 'Template',
3985
+ valueHeader: 'Cost',
3986
+ items: costItems,
3987
+ width: chartsWidth,
3988
+ unitName: 'USD',
3989
+ });
3990
+ }
3991
+ else {
3992
+ headerList.push("TOTAL COST $0 *(Nothing executed)*");
3993
+ }
3994
+ var _loop_1 = function (promptExecution) {
3995
+ executionReportString += '\n\n\n\n' + "## ".concat(promptExecution.prompt.title);
3996
+ var templateList = [];
3997
+ // TODO: What if startedAt OR/AND completedAt is not defined?
3998
+ var startedAt = moment((_c = (_b = promptExecution.result) === null || _b === void 0 ? void 0 : _b.timing) === null || _c === void 0 ? void 0 : _c.start);
3999
+ var completedAt = moment((_e = (_d = promptExecution.result) === null || _d === void 0 ? void 0 : _d.timing) === null || _e === void 0 ? void 0 : _e.complete);
4000
+ var duration = moment.duration(completedAt.diff(startedAt));
4001
+ // Not need here:
4002
+ // > templateList.push(`STARTED AT ${moment(startedAt).calendar()}`);
4003
+ templateList.push("DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
4004
+ if (typeof ((_g = (_f = promptExecution.result) === null || _f === void 0 ? void 0 : _f.usage) === null || _g === void 0 ? void 0 : _g.price) === 'number') {
4005
+ templateList.push("COST $".concat(formatNumber(promptExecution.result.usage.price * (1 + taxRate))) +
4006
+ (taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
4007
+ }
4008
+ else {
4009
+ templateList.push("COST UNKNOWN");
4010
+ }
4011
+ executionReportString += '\n\n' + templateList.map(function (header) { return "- ".concat(header); }).join('\n');
4012
+ /*
4013
+ - MODEL VARIANT ${promptExecution.prompt.modelRequirements.modelVariant}
4014
+ - MODEL NAME \`${promptExecution.result?.model}\` (requested \`${
4015
+ promptExecution.prompt.modelRequirements.modelName
4016
+
4017
+ */
4018
+ if (just(true)) {
4019
+ executionReportString +=
4020
+ '\n\n\n\n' +
4021
+ spaceTrim(function (block) { return "\n\n ### Prompt\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.prompt.content)), "\n ```\n\n "); });
4022
+ }
4023
+ if (promptExecution.result && promptExecution.result.content) {
4024
+ executionReportString +=
4025
+ '\n\n\n\n' +
4026
+ spaceTrim(function (block) { return "\n\n ### Result\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.result.content)), "\n ```\n "); });
4027
+ }
4028
+ if (promptExecution.error && promptExecution.error.message) {
4029
+ executionReportString +=
4030
+ '\n\n\n\n' +
4031
+ spaceTrim(function (block) { return "\n\n ### Error\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.error.message)), "\n ```\n\n "); });
4032
+ }
4033
+ };
4034
+ try {
4035
+ for (var _j = __values(executionReportJson.promptExecutions), _k = _j.next(); !_k.done; _k = _j.next()) {
4036
+ var promptExecution = _k.value;
4037
+ _loop_1(promptExecution);
4038
+ }
4039
+ }
4040
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
4041
+ finally {
4042
+ try {
4043
+ if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
4044
+ }
4045
+ finally { if (e_1) throw e_1.error; }
4046
+ }
4047
+ executionReportString = prettifyMarkdown(executionReportString);
4048
+ return executionReportString;
4049
+ }
4050
+ /**
4051
+ * TODO: Add mermaid chart for every report
4052
+ * TODO: [🧠] Allow to filter out some parts of the report by options
4053
+ */
4054
+
4055
+ export { CallbackInterfaceTools, ExecutionReportStringOptionsDefaults, ExecutionTypes, MultipleLlmExecutionTools, PROMPTBOOK_VERSION, SimplePromptInterfaceTools, SimplePromptbookLibrary, assertsExecutionSuccessful, checkExpectations, createPromptbookExecutor, createPromptbookLibraryFromDirectory, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, executionReportJsonToString, isPassingExpectations, justTestFsImport, prettifyPromptbookString, promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
3130
4056
  //# sourceMappingURL=index.es.js.map