@promptbook/core 0.52.0-9 → 0.53.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 (168) hide show
  1. package/README.md +1 -13
  2. package/esm/index.es.js +1094 -817
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/_packages/core.index.d.ts +4 -2
  5. package/esm/typings/_packages/utils.index.d.ts +2 -0
  6. package/esm/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
  7. package/esm/typings/conversion/prettify/renderPromptbookMermaid.d.ts +2 -1
  8. package/esm/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +3 -3
  9. package/esm/typings/conversion/utils/extractVariables.d.ts +2 -1
  10. package/esm/typings/conversion/validation/_importPromptbook.d.ts +2 -2
  11. package/esm/typings/errors/PromptbookLibraryError.d.ts +7 -0
  12. package/esm/typings/execution/ExecutionTools.d.ts +5 -3
  13. package/esm/typings/execution/LlmExecutionTools.d.ts +4 -2
  14. package/esm/typings/execution/PromptResult.d.ts +5 -1
  15. package/esm/typings/execution/ScriptExecutionTools.d.ts +2 -1
  16. package/esm/typings/execution/UserInterfaceTools.d.ts +2 -1
  17. package/esm/typings/execution/createPromptbookExecutor.d.ts +3 -3
  18. package/esm/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +4 -3
  19. package/esm/typings/execution/plugins/llm-execution-tools/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  20. package/esm/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -3
  21. package/esm/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +2 -1
  22. package/esm/typings/execution/plugins/llm-execution-tools/langtail/LangtailExecutionTools.d.ts +0 -3
  23. package/esm/typings/execution/plugins/llm-execution-tools/mocked/MockedEchoLlmExecutionTools.d.ts +4 -2
  24. package/esm/typings/execution/plugins/llm-execution-tools/mocked/MockedFackedLlmExecutionTools.d.ts +4 -2
  25. package/esm/typings/execution/plugins/llm-execution-tools/mocked/fakeTextToExpectations.d.ts +1 -1
  26. package/esm/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools.d.ts +4 -2
  27. package/esm/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionToolsOptions.d.ts +2 -1
  28. package/esm/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +5 -3
  29. package/esm/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
  30. package/esm/typings/execution/plugins/llm-execution-tools/openai/openai-models.d.ts +1 -1
  31. package/esm/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +5 -3
  32. package/esm/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionToolsOptions.d.ts +2 -1
  33. package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Progress.d.ts +1 -1
  34. package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Response.d.ts +1 -1
  35. package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +2 -1
  36. package/esm/typings/execution/plugins/llm-execution-tools/remote/startRemoteServer.d.ts +2 -1
  37. package/esm/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +3 -2
  38. package/esm/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +3 -2
  39. package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +3 -2
  40. package/esm/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -2
  41. package/esm/typings/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +1 -1
  42. package/esm/typings/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +1 -1
  43. package/esm/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +2 -2
  44. package/esm/typings/execution/translation/automatic-translate/translateMessages.d.ts +2 -2
  45. package/esm/typings/execution/utils/forEachAsync.d.ts +18 -0
  46. package/esm/typings/execution/utils/replaceParameters.d.ts +2 -2
  47. package/esm/typings/library/SimplePromptbookLibrary.d.ts +1 -1
  48. package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +30 -6
  49. package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts +1 -0
  50. package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +4 -4
  51. package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.test.d.ts +1 -0
  52. package/esm/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +2 -1
  53. package/esm/typings/library/constructors/createPromptbookLibraryFromSources.test.d.ts +1 -0
  54. package/esm/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +23 -6
  55. package/esm/typings/library/constructors/createPromptbookSublibrary.d.ts +1 -1
  56. package/esm/typings/library/constructors/justTestFsImport.d.ts +7 -0
  57. package/esm/typings/types/Command.d.ts +5 -2
  58. package/esm/typings/types/Prompt.d.ts +5 -2
  59. package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +8 -1
  60. package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +2 -1
  61. package/esm/typings/types/TaskProgress.d.ts +2 -1
  62. package/esm/typings/types/execution-report/ExecutionReportJson.d.ts +2 -1
  63. package/esm/typings/types/execution-report/countWorkingDuration.d.ts +1 -1
  64. package/esm/typings/types/typeAliases.d.ts +2 -2
  65. package/esm/typings/utils/emojis.d.ts +1 -1
  66. package/esm/typings/utils/expectation-counters/index.d.ts +2 -1
  67. package/esm/typings/utils/extractParameters.d.ts +2 -1
  68. package/esm/typings/utils/markdown/addAutoGeneratedSection.d.ts +2 -1
  69. package/esm/typings/utils/markdown/createMarkdownChart.d.ts +2 -2
  70. package/esm/typings/utils/markdown/createMarkdownTable.d.ts +2 -1
  71. package/esm/typings/utils/markdown/escapeMarkdownBlock.d.ts +1 -1
  72. package/esm/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +2 -1
  73. package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
  74. package/esm/typings/utils/markdown/removeContentComments.d.ts +2 -1
  75. package/esm/typings/utils/markdown/removeMarkdownFormatting.d.ts +1 -1
  76. package/esm/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +1 -1
  77. package/esm/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +1 -1
  78. package/esm/typings/utils/normalization/isValidKeyword.d.ts +1 -1
  79. package/esm/typings/utils/normalization/parseKeywords.d.ts +1 -1
  80. package/esm/typings/utils/normalization/parseKeywordsFromString.d.ts +1 -1
  81. package/esm/typings/utils/normalization/searchKeywords.d.ts +1 -1
  82. package/esm/typings/utils/postprocessing/extractBlock.d.ts +1 -1
  83. package/package.json +2 -2
  84. package/umd/index.umd.js +1098 -821
  85. package/umd/index.umd.js.map +1 -1
  86. package/umd/typings/_packages/core.index.d.ts +4 -2
  87. package/umd/typings/_packages/utils.index.d.ts +2 -0
  88. package/umd/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
  89. package/umd/typings/conversion/prettify/renderPromptbookMermaid.d.ts +2 -1
  90. package/umd/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +3 -3
  91. package/umd/typings/conversion/utils/extractVariables.d.ts +2 -1
  92. package/umd/typings/conversion/validation/_importPromptbook.d.ts +2 -2
  93. package/umd/typings/errors/PromptbookLibraryError.d.ts +7 -0
  94. package/umd/typings/execution/ExecutionTools.d.ts +5 -3
  95. package/umd/typings/execution/LlmExecutionTools.d.ts +4 -2
  96. package/umd/typings/execution/PromptResult.d.ts +5 -1
  97. package/umd/typings/execution/ScriptExecutionTools.d.ts +2 -1
  98. package/umd/typings/execution/UserInterfaceTools.d.ts +2 -1
  99. package/umd/typings/execution/createPromptbookExecutor.d.ts +3 -3
  100. package/umd/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +4 -3
  101. package/umd/typings/execution/plugins/llm-execution-tools/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  102. package/umd/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -3
  103. package/umd/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +2 -1
  104. package/umd/typings/execution/plugins/llm-execution-tools/langtail/LangtailExecutionTools.d.ts +0 -3
  105. package/umd/typings/execution/plugins/llm-execution-tools/mocked/MockedEchoLlmExecutionTools.d.ts +4 -2
  106. package/umd/typings/execution/plugins/llm-execution-tools/mocked/MockedFackedLlmExecutionTools.d.ts +4 -2
  107. package/umd/typings/execution/plugins/llm-execution-tools/mocked/fakeTextToExpectations.d.ts +1 -1
  108. package/umd/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools.d.ts +4 -2
  109. package/umd/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionToolsOptions.d.ts +2 -1
  110. package/umd/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +5 -3
  111. package/umd/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
  112. package/umd/typings/execution/plugins/llm-execution-tools/openai/openai-models.d.ts +1 -1
  113. package/umd/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +5 -3
  114. package/umd/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionToolsOptions.d.ts +2 -1
  115. package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Progress.d.ts +1 -1
  116. package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Response.d.ts +1 -1
  117. package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +2 -1
  118. package/umd/typings/execution/plugins/llm-execution-tools/remote/startRemoteServer.d.ts +2 -1
  119. package/umd/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +3 -2
  120. package/umd/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +3 -2
  121. package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +3 -2
  122. package/umd/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -2
  123. package/umd/typings/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +1 -1
  124. package/umd/typings/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +1 -1
  125. package/umd/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +2 -2
  126. package/umd/typings/execution/translation/automatic-translate/translateMessages.d.ts +2 -2
  127. package/umd/typings/execution/utils/forEachAsync.d.ts +18 -0
  128. package/umd/typings/execution/utils/replaceParameters.d.ts +2 -2
  129. package/umd/typings/library/SimplePromptbookLibrary.d.ts +1 -1
  130. package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +30 -6
  131. package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts +1 -0
  132. package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +4 -4
  133. package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.test.d.ts +1 -0
  134. package/umd/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +2 -1
  135. package/umd/typings/library/constructors/createPromptbookLibraryFromSources.test.d.ts +1 -0
  136. package/umd/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +23 -6
  137. package/umd/typings/library/constructors/createPromptbookSublibrary.d.ts +1 -1
  138. package/umd/typings/library/constructors/justTestFsImport.d.ts +7 -0
  139. package/umd/typings/types/Command.d.ts +5 -2
  140. package/umd/typings/types/Prompt.d.ts +5 -2
  141. package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +8 -1
  142. package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +2 -1
  143. package/umd/typings/types/TaskProgress.d.ts +2 -1
  144. package/umd/typings/types/execution-report/ExecutionReportJson.d.ts +2 -1
  145. package/umd/typings/types/execution-report/countWorkingDuration.d.ts +1 -1
  146. package/umd/typings/types/typeAliases.d.ts +2 -2
  147. package/umd/typings/utils/emojis.d.ts +1 -1
  148. package/umd/typings/utils/expectation-counters/index.d.ts +2 -1
  149. package/umd/typings/utils/extractParameters.d.ts +2 -1
  150. package/umd/typings/utils/markdown/addAutoGeneratedSection.d.ts +2 -1
  151. package/umd/typings/utils/markdown/createMarkdownChart.d.ts +2 -2
  152. package/umd/typings/utils/markdown/createMarkdownTable.d.ts +2 -1
  153. package/umd/typings/utils/markdown/escapeMarkdownBlock.d.ts +1 -1
  154. package/umd/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +2 -1
  155. package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
  156. package/umd/typings/utils/markdown/removeContentComments.d.ts +2 -1
  157. package/umd/typings/utils/markdown/removeMarkdownFormatting.d.ts +1 -1
  158. package/umd/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +1 -1
  159. package/umd/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +1 -1
  160. package/umd/typings/utils/normalization/isValidKeyword.d.ts +1 -1
  161. package/umd/typings/utils/normalization/parseKeywords.d.ts +1 -1
  162. package/umd/typings/utils/normalization/parseKeywordsFromString.d.ts +1 -1
  163. package/umd/typings/utils/normalization/searchKeywords.d.ts +1 -1
  164. package/umd/typings/utils/postprocessing/extractBlock.d.ts +1 -1
  165. package/esm/typings/wizzard/Wizzard.d.ts +0 -4
  166. package/esm/typings/wizzard/sample.d.ts +0 -6
  167. package/umd/typings/wizzard/Wizzard.d.ts +0 -4
  168. package/umd/typings/wizzard/sample.d.ts +0 -6
package/esm/index.es.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import spaceTrim$1, { spaceTrim } from 'spacetrim';
2
2
  import { format } from 'prettier';
3
3
  import parserHtml from 'prettier/parser-html';
4
+ import { join } from 'path';
4
5
  import moment from 'moment';
5
6
 
6
7
  /*! *****************************************************************************
@@ -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-8';
451
+ var PROMPTBOOK_VERSION = '0.52.0';
451
452
 
452
453
  /**
453
454
  * Parses the template and returns the list of all parameter names
@@ -569,88 +570,108 @@ function extractParametersFromPromptTemplate(promptTemplate) {
569
570
  * TODO: [🔣] If script require contentLanguage
570
571
  */
571
572
 
573
+ /* tslint:disable */
574
+ /*
575
+ TODO: Tests
576
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
577
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
578
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
579
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
580
+ */
581
+ function normalizeTo_SCREAMING_CASE(sentence) {
582
+ var e_1, _a;
583
+ var charType;
584
+ var lastCharType = 'OTHER';
585
+ var normalizedName = '';
586
+ try {
587
+ for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
588
+ var char = sentence_1_1.value;
589
+ var normalizedChar = void 0;
590
+ if (/^[a-z]$/.test(char)) {
591
+ charType = 'LOWERCASE';
592
+ normalizedChar = char.toUpperCase();
593
+ }
594
+ else if (/^[A-Z]$/.test(char)) {
595
+ charType = 'UPPERCASE';
596
+ normalizedChar = char;
597
+ }
598
+ else if (/^[0-9]$/.test(char)) {
599
+ charType = 'NUMBER';
600
+ normalizedChar = char;
601
+ }
602
+ else if (/^\/$/.test(char)) {
603
+ charType = 'SLASH';
604
+ normalizedChar = char;
605
+ }
606
+ else {
607
+ charType = 'OTHER';
608
+ normalizedChar = '_';
609
+ }
610
+ if (charType !== lastCharType &&
611
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
612
+ !(lastCharType === 'NUMBER') &&
613
+ !(charType === 'NUMBER')) {
614
+ normalizedName += '_';
615
+ }
616
+ normalizedName += normalizedChar;
617
+ lastCharType = charType;
618
+ }
619
+ }
620
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
621
+ finally {
622
+ try {
623
+ if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
624
+ }
625
+ finally { if (e_1) throw e_1.error; }
626
+ }
627
+ normalizedName = normalizedName.replace(/_+/g, '_');
628
+ normalizedName = normalizedName.replace(/_?\/_?/g, '/');
629
+ normalizedName = normalizedName.replace(/^_/, '');
630
+ normalizedName = normalizedName.replace(/_$/, '');
631
+ return normalizedName;
632
+ }
572
633
  /**
573
- * Removes emojis from a string and fix whitespaces
634
+ * TODO: [🌺] Use some intermediate util splitWords
635
+ */
636
+
637
+ /**
638
+ * Execution type describes the way how the block is executed
574
639
  *
575
- * @param text with emojis
576
- * @returns text without emojis
640
+ * @see https://github.com/webgptorg/promptbook#execution-type
577
641
  */
578
- function removeEmojis(text) {
579
- // Replace emojis (and also ZWJ sequence) with hyphens
580
- text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
581
- text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
582
- text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
583
- text = text.replace(/\p{Extended_Pictographic}/gu, '');
584
- return text;
585
- }
642
+ var ExecutionTypes = [
643
+ 'PROMPT_TEMPLATE',
644
+ 'SIMPLE_TEMPLATE',
645
+ 'SCRIPT',
646
+ 'PROMPT_DIALOG',
647
+ // <- [🥻] Insert here when making new command
648
+ ];
586
649
 
587
650
  /**
588
- * Function normalizes title to name which can be used as identifier
651
+ * Units of text measurement
652
+ */
653
+ var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
654
+ /**
655
+ * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
656
+ * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
657
+ * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
589
658
  */
590
- function titleToName(value) {
591
- value = removeEmojis(value);
592
- value = normalizeToKebabCase(value);
593
- // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
594
- return value;
595
- }
596
659
 
597
660
  /**
598
- * Creates a Mermaid graph based on the promptbook
661
+ * Removes Markdown formatting tags from a string.
599
662
  *
600
- * Note: The result is not wrapped in a Markdown code block
663
+ * @param {string} str - The string to remove Markdown tags from.
664
+ * @returns {string} The input string with all Markdown tags removed.
601
665
  */
602
- function renderPromptbookMermaid(promptbookJson, options) {
603
- var _a = (options || {}).linkPromptTemplate, linkPromptTemplate = _a === void 0 ? function () { return null; } : _a;
604
- var parameterNameToTemplateName = function (parameterName) {
605
- var parameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
606
- if (!parameter) {
607
- throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
608
- }
609
- if (parameter.isInput) {
610
- return 'input';
611
- }
612
- var template = promptbookJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
613
- if (!template) {
614
- throw new Error("Could not find template for {".concat(parameterName, "}"));
615
- }
616
- return normalizeTo_camelCase('template-' + titleToName(template.title));
617
- };
618
- 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
619
- .flatMap(function (_a) {
620
- var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
621
- return __spreadArray([
622
- "".concat(parameterNameToTemplateName(resultingParameterName), "(\"").concat(title, "\")")
623
- ], __read(dependentParameterNames.map(function (dependentParameterName) {
624
- return "".concat(parameterNameToTemplateName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName(resultingParameterName));
625
- })), false);
626
- })
627
- .join('\n')), "\n\n ").concat(block(promptbookJson.parameters
628
- .filter(function (_a) {
629
- var isOutput = _a.isOutput;
630
- return isOutput;
631
- })
632
- .map(function (_a) {
633
- var name = _a.name;
634
- return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
635
- })
636
- .join('\n')), "\n output((Output)):::output\n\n ").concat(block(promptbookJson.promptTemplates
637
- .map(function (promptTemplate) {
638
- var link = linkPromptTemplate(promptTemplate);
639
- if (link === null) {
640
- return '';
641
- }
642
- var href = link.href, title = link.title;
643
- var templateName = parameterNameToTemplateName(promptTemplate.resultingParameterName);
644
- return "click ".concat(templateName, " href \"").concat(href, "\" \"").concat(title, "\";");
645
- })
646
- .filter(function (line) { return line !== ''; })
647
- .join('\n')), "\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
648
- return promptbookMermaid;
666
+ function removeMarkdownFormatting(str) {
667
+ // Remove bold formatting
668
+ str = str.replace(/\*\*(.*?)\*\*/g, '$1');
669
+ // Remove italic formatting
670
+ str = str.replace(/\*(.*?)\*/g, '$1');
671
+ // Remove code formatting
672
+ str = str.replace(/`(.*?)`/g, '$1');
673
+ return str;
649
674
  }
650
- /**
651
- * TODO: Maybe use some Mermaid library instead of string templating
652
- * TODO: [🕌] When more than 2 functionalities, split into separate functions
653
- */
654
675
 
655
676
  /**
656
677
  * Function parseNumber will parse number from string
@@ -720,146 +741,249 @@ function parseNumber(value) {
720
741
  */
721
742
 
722
743
  /**
723
- * This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
724
- */
725
- var PromptbookLogicError = /** @class */ (function (_super) {
726
- __extends(PromptbookLogicError, _super);
727
- function PromptbookLogicError(message) {
728
- var _this = _super.call(this, message) || this;
729
- _this.name = 'PromptbookLogicError';
730
- Object.setPrototypeOf(_this, PromptbookLogicError.prototype);
731
- return _this;
732
- }
733
- return PromptbookLogicError;
734
- }(Error));
735
-
736
- /**
737
- * This error occurs during the parameter replacement in the template
738
- *
739
- * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
740
- */
741
- var TemplateError = /** @class */ (function (_super) {
742
- __extends(TemplateError, _super);
743
- function TemplateError(message) {
744
- var _this = _super.call(this, message) || this;
745
- _this.name = 'TemplateError';
746
- Object.setPrototypeOf(_this, TemplateError.prototype);
747
- return _this;
748
- }
749
- return TemplateError;
750
- }(Error));
751
-
752
- /**
753
- * Replaces parameters in template with values from parameters object
744
+ * Parses one line of ul/ol to command
754
745
  *
755
- * @param template the template with parameters in {curly} braces
756
- * @param parameters the object with parameters
757
- * @returns the template with replaced parameters
758
- * @throws {TemplateError} if parameter is not defined, not closed, or not opened
746
+ * @returns parsed command object
747
+ * @throws {PromptbookSyntaxError} if the command is invalid
759
748
  *
760
- * @private within the createPromptbookExecutor
749
+ * @private within the promptbookStringToJson
761
750
  */
762
- function replaceParameters(template, parameters) {
763
- var replacedTemplate = template;
764
- var match;
765
- var loopLimit = LOOP_LIMIT;
766
- var _loop_1 = function () {
767
- if (loopLimit-- < 0) {
768
- throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
769
- }
770
- var precol = match.groups.precol;
771
- var parameterName = match.groups.parameterName;
772
- if (parameterName === '') {
773
- return "continue";
751
+ function parseCommand(listItem) {
752
+ var e_1, _a;
753
+ if (listItem.includes('\n') || listItem.includes('\r')) {
754
+ throw new PromptbookSyntaxError('Command can not contain new line characters:');
755
+ }
756
+ var type = listItem.trim();
757
+ type = type.split('`').join('');
758
+ type = type.split('"').join('');
759
+ type = type.split("'").join('');
760
+ type = type.split('~').join('');
761
+ type = type.split('[').join('');
762
+ type = type.split(']').join('');
763
+ type = type.split('(').join('');
764
+ type = type.split(')').join('');
765
+ type = normalizeTo_SCREAMING_CASE(type);
766
+ type = type.split('DIALOGUE').join('DIALOG');
767
+ var listItemParts = listItem
768
+ .split(' ')
769
+ .map(function (part) { return part.trim(); })
770
+ .filter(function (item) { return item !== ''; })
771
+ .filter(function (item) { return !/^PTBK$/i.test(item); })
772
+ .filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
773
+ .map(removeMarkdownFormatting);
774
+ if (type.startsWith('URL') ||
775
+ type.startsWith('PTBK_URL') ||
776
+ type.startsWith('PTBKURL') ||
777
+ type.startsWith('PROMPTBOOK_URL') ||
778
+ type.startsWith('PROMPTBOOKURL') ||
779
+ type.startsWith('HTTPS')) {
780
+ if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
781
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
774
782
  }
775
- if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
776
- throw new TemplateError('Parameter is already opened or not closed');
783
+ var promptbookUrlString = listItemParts.pop();
784
+ var promptbookUrl = new URL(promptbookUrlString);
785
+ if (promptbookUrl.protocol !== 'https:') {
786
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
777
787
  }
778
- if (parameters[parameterName] === undefined) {
779
- throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
788
+ if (promptbookUrl.hash !== '') {
789
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
780
790
  }
781
- var parameterValue = parameters[parameterName];
782
- if (parameterValue === undefined) {
783
- throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
791
+ return {
792
+ type: 'PROMPTBOOK_URL',
793
+ promptbookUrl: promptbookUrl,
794
+ };
795
+ }
796
+ else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
797
+ if (listItemParts.length !== 2) {
798
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
784
799
  }
785
- parameterValue = parameterValue.toString();
786
- if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
787
- parameterValue = parameterValue
788
- .split('\n')
789
- .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
790
- .join('\n');
800
+ var promptbookVersion = listItemParts.pop();
801
+ // TODO: Validate version
802
+ return {
803
+ type: 'PROMPTBOOK_VERSION',
804
+ promptbookVersion: promptbookVersion,
805
+ };
806
+ }
807
+ else if (type.startsWith('EXECUTE') ||
808
+ type.startsWith('EXEC') ||
809
+ type.startsWith('PROMPT_DIALOG') ||
810
+ type.startsWith('SIMPLE_TEMPLATE')) {
811
+ var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
812
+ if (executionTypes.length !== 1) {
813
+ throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown execution type in command:\n\n - ".concat(listItem, "\n\n Supported execution types are:\n ").concat(block(ExecutionTypes.join(', ')), "\n "); }));
791
814
  }
792
- replacedTemplate =
793
- replacedTemplate.substring(0, match.index + precol.length) +
794
- parameterValue +
795
- replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
796
- };
797
- while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
798
- .exec(replacedTemplate))) {
799
- _loop_1();
815
+ return {
816
+ type: 'EXECUTE',
817
+ executionType: executionTypes[0],
818
+ };
800
819
  }
801
- // [💫] Check if there are parameters that are not closed properly
802
- if (/{\w+$/.test(replacedTemplate)) {
803
- throw new TemplateError('Parameter is not closed');
820
+ else if (type.startsWith('MODEL')) {
821
+ // TODO: Make this more elegant and dynamically
822
+ if (type.startsWith('MODEL_VARIANT')) {
823
+ if (type === 'MODEL_VARIANT_CHAT') {
824
+ return {
825
+ type: 'MODEL',
826
+ key: 'modelVariant',
827
+ value: 'CHAT',
828
+ };
829
+ }
830
+ else if (type === 'MODEL_VARIANT_COMPLETION') {
831
+ return {
832
+ type: 'MODEL',
833
+ key: 'modelVariant',
834
+ value: 'COMPLETION',
835
+ };
836
+ }
837
+ else {
838
+ throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n - ".concat(listItem, "\n\n Supported variants are:\n ").concat(block(['CHAT', 'COMPLETION'].join(', ')), "\n "); }));
839
+ }
840
+ }
841
+ if (type.startsWith('MODEL_NAME')) {
842
+ return {
843
+ type: 'MODEL',
844
+ key: 'modelName',
845
+ value: listItemParts.pop(),
846
+ };
847
+ }
848
+ else {
849
+ throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
850
+ }
804
851
  }
805
- // [💫] Check if there are parameters that are not opened properly
806
- if (/^\w+}/.test(replacedTemplate)) {
807
- throw new TemplateError('Parameter is not opened');
852
+ else if (type.startsWith('PARAM') ||
853
+ type.startsWith('INPUT_PARAM') ||
854
+ type.startsWith('OUTPUT_PARAM') ||
855
+ listItem.startsWith('{') ||
856
+ listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
857
+ var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
858
+ if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
859
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
860
+ }
861
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
862
+ var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
863
+ if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
864
+ throw new PromptbookSyntaxError(spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
865
+ }
866
+ var isInput = type.startsWith('INPUT');
867
+ var isOutput = type.startsWith('OUTPUT');
868
+ if (listItem.startsWith('> {')) {
869
+ isInput = false;
870
+ isOutput = false;
871
+ }
872
+ return {
873
+ type: 'PARAMETER',
874
+ parameterName: parameterName,
875
+ parameterDescription: parameterDescription.trim() || null,
876
+ isInput: isInput,
877
+ isOutput: isOutput,
878
+ };
808
879
  }
809
- return replacedTemplate;
810
- }
811
-
812
- /**
813
- * Counts number of characters in the text
814
- */
815
- function countCharacters(text) {
816
- // Remove null characters
817
- text = text.replace(/\0/g, '');
818
- // Replace emojis (and also ZWJ sequence) with hyphens
819
- text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
820
- text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
821
- text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
822
- return text.length;
823
- }
824
-
825
- /**
826
- * Counts number of lines in the text
827
- */
828
- function countLines(text) {
829
- if (text === '') {
830
- return 0;
880
+ else if (type.startsWith('JOKER')) {
881
+ if (listItemParts.length !== 2) {
882
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
883
+ }
884
+ var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
885
+ if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
886
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
887
+ }
888
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
889
+ var parameterName = parametersMatch.groups.parameterName;
890
+ return {
891
+ type: 'JOKER',
892
+ parameterName: parameterName,
893
+ };
894
+ }
895
+ else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
896
+ if (listItemParts.length !== 2) {
897
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
898
+ }
899
+ var functionName = listItemParts.pop();
900
+ return {
901
+ type: 'POSTPROCESS',
902
+ functionName: functionName,
903
+ };
904
+ }
905
+ else if (type.startsWith('EXPECT_JSON')) {
906
+ return {
907
+ type: 'EXPECT_FORMAT',
908
+ format: 'JSON',
909
+ };
910
+ // [🥤]
911
+ }
912
+ else if (type.startsWith('EXPECT')) {
913
+ try {
914
+ listItemParts.shift();
915
+ var sign = void 0;
916
+ var signRaw = listItemParts.shift();
917
+ if (/^exact/i.test(signRaw)) {
918
+ sign = 'EXACTLY';
919
+ }
920
+ else if (/^min/i.test(signRaw)) {
921
+ sign = 'MINIMUM';
922
+ }
923
+ else if (/^max/i.test(signRaw)) {
924
+ sign = 'MAXIMUM';
925
+ }
926
+ else {
927
+ throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
928
+ }
929
+ var amountRaw = listItemParts.shift();
930
+ var amount = parseNumber(amountRaw);
931
+ if (amount < 0) {
932
+ throw new PromptbookSyntaxError('Amount must be positive number or zero');
933
+ }
934
+ if (amount !== Math.floor(amount)) {
935
+ throw new PromptbookSyntaxError('Amount must be whole number');
936
+ }
937
+ var unitRaw = listItemParts.shift();
938
+ var unit = undefined;
939
+ try {
940
+ for (var EXPECTATION_UNITS_1 = __values(EXPECTATION_UNITS), EXPECTATION_UNITS_1_1 = EXPECTATION_UNITS_1.next(); !EXPECTATION_UNITS_1_1.done; EXPECTATION_UNITS_1_1 = EXPECTATION_UNITS_1.next()) {
941
+ var existingUnit = EXPECTATION_UNITS_1_1.value;
942
+ var existingUnitText = existingUnit;
943
+ existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
944
+ if (existingUnitText === 'CHARACTER') {
945
+ existingUnitText = 'CHAR';
946
+ }
947
+ if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
948
+ new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
949
+ if (unit !== undefined) {
950
+ throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
951
+ }
952
+ unit = existingUnit;
953
+ }
954
+ }
955
+ }
956
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
957
+ finally {
958
+ try {
959
+ if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
960
+ }
961
+ finally { if (e_1) throw e_1.error; }
962
+ }
963
+ if (unit === undefined) {
964
+ throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
965
+ }
966
+ return {
967
+ type: 'EXPECT_AMOUNT',
968
+ sign: sign,
969
+ unit: unit,
970
+ amount: amount,
971
+ };
972
+ }
973
+ catch (error) {
974
+ if (!(error instanceof Error)) {
975
+ throw error;
976
+ }
977
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
978
+ }
979
+ /*
980
+ } else if (type.startsWith('__________________')) {
981
+ // <- [🥻] Insert here when making new command
982
+ */
983
+ }
984
+ else {
985
+ throw new PromptbookSyntaxError(spaceTrim("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - PROMPTBOOK_URL <url>\n - PROMPTBOOK_VERSION <version>\n - EXECUTE PROMPT TEMPLATE\n - EXECUTE SIMPLE TEMPLATE\n - SIMPLE TEMPLATE\n - EXECUTE SCRIPT\n - EXECUTE PROMPT_DIALOG'\n - PROMPT_DIALOG'\n - MODEL NAME <name>\n - MODEL VARIANT <\"Chat\"|\"Completion\">\n - INPUT PARAM {<name>} <description>\n - OUTPUT PARAM {<name>} <description>\n - POSTPROCESS `{functionName}`\n - JOKER {<name>}\n - EXPECT JSON\n - EXPECT <\"Exactly\"|\"Min\"|\"Max\"> <number> <\"Chars\"|\"Words\"|\"Sentences\"|\"Paragraphs\"|\"Pages\">\n\n ")));
831
986
  }
832
- return text.split('\n').length;
833
- }
834
-
835
- /**
836
- * Counts number of pages in the text
837
- */
838
- function countPages(text) {
839
- var sentencesPerPage = 5; // Assuming each page has 5 sentences
840
- var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
841
- var pageCount = Math.ceil(sentences.length / sentencesPerPage);
842
- return pageCount;
843
- }
844
-
845
- /**
846
- * Counts number of paragraphs in the text
847
- */
848
- function countParagraphs(text) {
849
- return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
850
- }
851
-
852
- /**
853
- * Split text into sentences
854
- */
855
- function splitIntoSentences(text) {
856
- return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
857
- }
858
- /**
859
- * Counts number of sentences in the text
860
- */
861
- function countSentences(text) {
862
- return splitIntoSentences(text).length;
863
987
  }
864
988
 
865
989
  var defaultDiacriticsRemovalMap = [
@@ -1071,546 +1195,127 @@ var defaultDiacriticsRemovalMap = [
1071
1195
  },
1072
1196
  ];
1073
1197
  /**
1074
- * Map of letters from diacritic variant to diacritless variant
1075
- * Contains lowercase and uppercase separatelly
1076
- *
1077
- * > "á" => "a"
1078
- * > "ě" => "e"
1079
- * > "Ă" => "A"
1080
- * > ...
1081
- */
1082
- var DIACRITIC_VARIANTS_LETTERS = {};
1083
- // tslint:disable-next-line: prefer-for-of
1084
- for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
1085
- var letters = defaultDiacriticsRemovalMap[i].letters;
1086
- // tslint:disable-next-line: prefer-for-of
1087
- for (var j = 0; j < letters.length; j++) {
1088
- DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
1089
- }
1090
- }
1091
- // <- TODO: [🍓] Put to maker function to save execution time if not needed
1092
- /*
1093
- @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
1094
- Licensed under the Apache License, Version 2.0 (the "License");
1095
- you may not use this file except in compliance with the License.
1096
- You may obtain a copy of the License at
1097
-
1098
- http://www.apache.org/licenses/LICENSE-2.0
1099
-
1100
- Unless required by applicable law or agreed to in writing, software
1101
- distributed under the License is distributed on an "AS IS" BASIS,
1102
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1103
- See the License for the specific language governing permissions and
1104
- limitations under the License.
1105
- */
1106
-
1107
- /**
1108
- *
1109
- */
1110
- function removeDiacritics(input) {
1111
- /*eslint no-control-regex: "off"*/
1112
- return input.replace(/[^\u0000-\u007E]/g, function (a) {
1113
- return DIACRITIC_VARIANTS_LETTERS[a] || a;
1114
- });
1115
- }
1116
-
1117
- /**
1118
- * Counts number of words in the text
1119
- */
1120
- function countWords(text) {
1121
- text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
1122
- text = removeDiacritics(text);
1123
- return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
1124
- }
1125
-
1126
- /**
1127
- * Index of all counter functions
1128
- */
1129
- var CountUtils = {
1130
- CHARACTERS: countCharacters,
1131
- WORDS: countWords,
1132
- SENTENCES: countSentences,
1133
- PARAGRAPHS: countParagraphs,
1134
- LINES: countLines,
1135
- PAGES: countPages,
1136
- };
1137
-
1138
- /**
1139
- * Function isValidJsonString will tell you if the string is valid JSON or not
1140
- */
1141
- function isValidJsonString(value) {
1142
- try {
1143
- JSON.parse(value);
1144
- return true;
1145
- }
1146
- catch (error) {
1147
- if (!(error instanceof Error)) {
1148
- throw error;
1149
- }
1150
- if (error.message.includes('Unexpected token')) {
1151
- return false;
1152
- }
1153
- return false;
1154
- }
1155
- }
1156
-
1157
- /**
1158
- * Removes Markdown formatting tags from a string.
1159
- *
1160
- * @param {string} str - The string to remove Markdown tags from.
1161
- * @returns {string} The input string with all Markdown tags removed.
1162
- */
1163
- function removeMarkdownFormatting(str) {
1164
- // Remove bold formatting
1165
- str = str.replace(/\*\*(.*?)\*\*/g, '$1');
1166
- // Remove italic formatting
1167
- str = str.replace(/\*(.*?)\*/g, '$1');
1168
- // Remove code formatting
1169
- str = str.replace(/`(.*?)`/g, '$1');
1170
- return str;
1171
- }
1172
-
1173
- /* tslint:disable */
1174
- /*
1175
- TODO: Tests
1176
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
1177
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
1178
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
1179
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
1180
- */
1181
- function normalizeTo_SCREAMING_CASE(sentence) {
1182
- var e_1, _a;
1183
- var charType;
1184
- var lastCharType = 'OTHER';
1185
- var normalizedName = '';
1186
- try {
1187
- for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1188
- var char = sentence_1_1.value;
1189
- var normalizedChar = void 0;
1190
- if (/^[a-z]$/.test(char)) {
1191
- charType = 'LOWERCASE';
1192
- normalizedChar = char.toUpperCase();
1193
- }
1194
- else if (/^[A-Z]$/.test(char)) {
1195
- charType = 'UPPERCASE';
1196
- normalizedChar = char;
1197
- }
1198
- else if (/^[0-9]$/.test(char)) {
1199
- charType = 'NUMBER';
1200
- normalizedChar = char;
1201
- }
1202
- else if (/^\/$/.test(char)) {
1203
- charType = 'SLASH';
1204
- normalizedChar = char;
1205
- }
1206
- else {
1207
- charType = 'OTHER';
1208
- normalizedChar = '_';
1209
- }
1210
- if (charType !== lastCharType &&
1211
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1212
- !(lastCharType === 'NUMBER') &&
1213
- !(charType === 'NUMBER')) {
1214
- normalizedName += '_';
1215
- }
1216
- normalizedName += normalizedChar;
1217
- lastCharType = charType;
1218
- }
1219
- }
1220
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1221
- finally {
1222
- try {
1223
- if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
1224
- }
1225
- finally { if (e_1) throw e_1.error; }
1226
- }
1227
- normalizedName = normalizedName.replace(/_+/g, '_');
1228
- normalizedName = normalizedName.replace(/_?\/_?/g, '/');
1229
- normalizedName = normalizedName.replace(/^_/, '');
1230
- normalizedName = normalizedName.replace(/_$/, '');
1231
- return normalizedName;
1232
- }
1233
- /**
1234
- * TODO: [🌺] Use some intermediate util splitWords
1235
- */
1236
-
1237
- /* tslint:disable */
1238
- function normalizeToKebabCase(sentence) {
1239
- var e_1, _a;
1240
- sentence = removeDiacritics(sentence);
1241
- var charType;
1242
- var lastCharType = 'OTHER';
1243
- var normalizedName = '';
1244
- try {
1245
- for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1246
- var char = sentence_1_1.value;
1247
- var normalizedChar = void 0;
1248
- if (/^[a-z]$/.test(char)) {
1249
- charType = 'LOWERCASE';
1250
- normalizedChar = char;
1251
- }
1252
- else if (/^[A-Z]$/.test(char)) {
1253
- charType = 'UPPERCASE';
1254
- normalizedChar = char.toLowerCase();
1255
- }
1256
- else if (/^[0-9]$/.test(char)) {
1257
- charType = 'NUMBER';
1258
- normalizedChar = char;
1259
- }
1260
- else if (/^\/$/.test(char)) {
1261
- charType = 'SLASH';
1262
- normalizedChar = char;
1263
- }
1264
- else {
1265
- charType = 'OTHER';
1266
- normalizedChar = '-';
1267
- }
1268
- if (charType !== lastCharType &&
1269
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1270
- !(lastCharType === 'NUMBER') &&
1271
- !(charType === 'NUMBER')) {
1272
- normalizedName += '-';
1273
- }
1274
- normalizedName += normalizedChar;
1275
- lastCharType = charType;
1276
- }
1277
- }
1278
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1279
- finally {
1280
- try {
1281
- if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
1282
- }
1283
- finally { if (e_1) throw e_1.error; }
1284
- }
1285
- normalizedName = normalizedName.split(/-+/g).join('-');
1286
- normalizedName = normalizedName.split(/-?\/-?/g).join('/');
1287
- normalizedName = normalizedName.replace(/^-/, '');
1288
- normalizedName = normalizedName.replace(/-$/, '');
1289
- return normalizedName;
1290
- }
1291
-
1292
- /* tslint:disable */
1293
- function normalizeTo_camelCase(sentence, __firstLetterCapital) {
1294
- var e_1, _a;
1295
- if (__firstLetterCapital === void 0) { __firstLetterCapital = false; }
1296
- var charType;
1297
- var lastCharType = null;
1298
- var normalizedName = '';
1299
- try {
1300
- for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1301
- var char = sentence_1_1.value;
1302
- var normalizedChar = void 0;
1303
- if (/^[a-z]$/.test(char)) {
1304
- charType = 'LOWERCASE';
1305
- normalizedChar = char;
1306
- }
1307
- else if (/^[A-Z]$/.test(char)) {
1308
- charType = 'UPPERCASE';
1309
- normalizedChar = char.toLowerCase();
1310
- }
1311
- else if (/^[0-9]$/.test(char)) {
1312
- charType = 'NUMBER';
1313
- normalizedChar = char;
1314
- }
1315
- else {
1316
- charType = 'OTHER';
1317
- normalizedChar = '';
1318
- }
1319
- if (!lastCharType) {
1320
- if (__firstLetterCapital) {
1321
- normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
1322
- }
1323
- }
1324
- else if (charType !== lastCharType &&
1325
- !(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
1326
- !(lastCharType === 'NUMBER') &&
1327
- !(charType === 'NUMBER')) {
1328
- normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
1329
- }
1330
- normalizedName += normalizedChar;
1331
- lastCharType = charType;
1332
- }
1333
- }
1334
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1335
- finally {
1336
- try {
1337
- if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
1338
- }
1339
- finally { if (e_1) throw e_1.error; }
1340
- }
1341
- return normalizedName;
1342
- }
1343
- /**
1344
- * TODO: [🌺] Use some intermediate util splitWords
1345
- */
1346
-
1347
- /**
1348
- * Execution type describes the way how the block is executed
1349
- *
1350
- * @see https://github.com/webgptorg/promptbook#execution-type
1351
- */
1352
- var ExecutionTypes = [
1353
- 'PROMPT_TEMPLATE',
1354
- 'SIMPLE_TEMPLATE',
1355
- 'SCRIPT',
1356
- 'PROMPT_DIALOG',
1357
- // <- [🥻] Insert here when making new command
1358
- ];
1359
-
1360
- /**
1361
- * Units of text measurement
1362
- */
1363
- var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
1364
- /**
1365
- * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
1366
- * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
1367
- * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
1368
- */
1369
-
1370
- /**
1371
- * Parses one line of ul/ol to command
1372
- *
1373
- * @returns parsed command object
1374
- * @throws {PromptbookSyntaxError} if the command is invalid
1375
- *
1376
- * @private within the promptbookStringToJson
1377
- */
1378
- function parseCommand(listItem) {
1379
- var e_1, _a;
1380
- if (listItem.includes('\n') || listItem.includes('\r')) {
1381
- throw new PromptbookSyntaxError('Command can not contain new line characters:');
1382
- }
1383
- var type = listItem.trim();
1384
- type = type.split('`').join('');
1385
- type = type.split('"').join('');
1386
- type = type.split("'").join('');
1387
- type = type.split('~').join('');
1388
- type = type.split('[').join('');
1389
- type = type.split(']').join('');
1390
- type = type.split('(').join('');
1391
- type = type.split(')').join('');
1392
- type = normalizeTo_SCREAMING_CASE(type);
1393
- type = type.split('DIALOGUE').join('DIALOG');
1394
- var listItemParts = listItem
1395
- .split(' ')
1396
- .map(function (part) { return part.trim(); })
1397
- .filter(function (item) { return item !== ''; })
1398
- .filter(function (item) { return !/^PTBK$/i.test(item); })
1399
- .filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
1400
- .map(removeMarkdownFormatting);
1401
- if (type.startsWith('URL') ||
1402
- type.startsWith('PTBK_URL') ||
1403
- type.startsWith('PTBKURL') ||
1404
- type.startsWith('PROMPTBOOK_URL') ||
1405
- type.startsWith('PROMPTBOOKURL') ||
1406
- type.startsWith('HTTPS')) {
1407
- if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
1408
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
1409
- }
1410
- var promptbookUrlString = listItemParts.pop();
1411
- var promptbookUrl = new URL(promptbookUrlString);
1412
- if (promptbookUrl.protocol !== 'https:') {
1413
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
1414
- }
1415
- if (promptbookUrl.hash !== '') {
1416
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
1417
- }
1418
- return {
1419
- type: 'PROMPTBOOK_URL',
1420
- promptbookUrl: promptbookUrl,
1421
- };
1422
- }
1423
- else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
1424
- if (listItemParts.length !== 2) {
1425
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
1426
- }
1427
- var promptbookVersion = listItemParts.pop();
1428
- // TODO: Validate version
1429
- return {
1430
- type: 'PROMPTBOOK_VERSION',
1431
- promptbookVersion: promptbookVersion,
1432
- };
1433
- }
1434
- else if (type.startsWith('EXECUTE') ||
1435
- type.startsWith('EXEC') ||
1436
- type.startsWith('PROMPT_DIALOG') ||
1437
- type.startsWith('SIMPLE_TEMPLATE')) {
1438
- var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
1439
- if (executionTypes.length !== 1) {
1440
- throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown execution type in command:\n\n - ".concat(listItem, "\n\n Supported execution types are:\n ").concat(block(ExecutionTypes.join(', ')), "\n "); }));
1441
- }
1442
- return {
1443
- type: 'EXECUTE',
1444
- executionType: executionTypes[0],
1445
- };
1198
+ * Map of letters from diacritic variant to diacritless variant
1199
+ * Contains lowercase and uppercase separatelly
1200
+ *
1201
+ * > "á" => "a"
1202
+ * > "ě" => "e"
1203
+ * > "Ă" => "A"
1204
+ * > ...
1205
+ */
1206
+ var DIACRITIC_VARIANTS_LETTERS = {};
1207
+ // tslint:disable-next-line: prefer-for-of
1208
+ for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
1209
+ var letters = defaultDiacriticsRemovalMap[i].letters;
1210
+ // tslint:disable-next-line: prefer-for-of
1211
+ for (var j = 0; j < letters.length; j++) {
1212
+ DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
1446
1213
  }
1447
- else if (type.startsWith('MODEL')) {
1448
- // TODO: Make this more elegant and dynamically
1449
- if (type.startsWith('MODEL_VARIANT')) {
1450
- if (type === 'MODEL_VARIANT_CHAT') {
1451
- return {
1452
- type: 'MODEL',
1453
- key: 'modelVariant',
1454
- value: 'CHAT',
1455
- };
1456
- }
1457
- else if (type === 'MODEL_VARIANT_COMPLETION') {
1458
- return {
1459
- type: 'MODEL',
1460
- key: 'modelVariant',
1461
- value: 'COMPLETION',
1462
- };
1463
- }
1464
- else {
1465
- throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n - ".concat(listItem, "\n\n Supported variants are:\n ").concat(block(['CHAT', 'COMPLETION'].join(', ')), "\n "); }));
1214
+ }
1215
+ // <- TODO: [🍓] Put to maker function to save execution time if not needed
1216
+ /*
1217
+ @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
1218
+ Licensed under the Apache License, Version 2.0 (the "License");
1219
+ you may not use this file except in compliance with the License.
1220
+ You may obtain a copy of the License at
1221
+
1222
+ http://www.apache.org/licenses/LICENSE-2.0
1223
+
1224
+ Unless required by applicable law or agreed to in writing, software
1225
+ distributed under the License is distributed on an "AS IS" BASIS,
1226
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1227
+ See the License for the specific language governing permissions and
1228
+ limitations under the License.
1229
+ */
1230
+
1231
+ /**
1232
+ *
1233
+ */
1234
+ function removeDiacritics(input) {
1235
+ /*eslint no-control-regex: "off"*/
1236
+ return input.replace(/[^\u0000-\u007E]/g, function (a) {
1237
+ return DIACRITIC_VARIANTS_LETTERS[a] || a;
1238
+ });
1239
+ }
1240
+
1241
+ /* tslint:disable */
1242
+ function normalizeToKebabCase(sentence) {
1243
+ var e_1, _a;
1244
+ sentence = removeDiacritics(sentence);
1245
+ var charType;
1246
+ var lastCharType = 'OTHER';
1247
+ var normalizedName = '';
1248
+ try {
1249
+ for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1250
+ var char = sentence_1_1.value;
1251
+ var normalizedChar = void 0;
1252
+ if (/^[a-z]$/.test(char)) {
1253
+ charType = 'LOWERCASE';
1254
+ normalizedChar = char;
1466
1255
  }
1467
- }
1468
- if (type.startsWith('MODEL_NAME')) {
1469
- return {
1470
- type: 'MODEL',
1471
- key: 'modelName',
1472
- value: listItemParts.pop(),
1473
- };
1474
- }
1475
- else {
1476
- throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
1477
- }
1478
- }
1479
- else if (type.startsWith('PARAM') ||
1480
- type.startsWith('INPUT_PARAM') ||
1481
- type.startsWith('OUTPUT_PARAM') ||
1482
- listItem.startsWith('{') ||
1483
- listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
1484
- var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
1485
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
1486
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1487
- }
1488
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1489
- var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
1490
- if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
1491
- throw new PromptbookSyntaxError(spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
1492
- }
1493
- var isInput = type.startsWith('INPUT');
1494
- var isOutput = type.startsWith('OUTPUT');
1495
- if (listItem.startsWith('> {')) {
1496
- isInput = false;
1497
- isOutput = false;
1498
- }
1499
- return {
1500
- type: 'PARAMETER',
1501
- parameterName: parameterName,
1502
- parameterDescription: parameterDescription.trim() || null,
1503
- isInput: isInput,
1504
- isOutput: isOutput,
1505
- };
1506
- }
1507
- else if (type.startsWith('JOKER')) {
1508
- if (listItemParts.length !== 2) {
1509
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
1510
- }
1511
- var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
1512
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
1513
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1514
- }
1515
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1516
- var parameterName = parametersMatch.groups.parameterName;
1517
- return {
1518
- type: 'JOKER',
1519
- parameterName: parameterName,
1520
- };
1521
- }
1522
- else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
1523
- if (listItemParts.length !== 2) {
1524
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
1525
- }
1526
- var functionName = listItemParts.pop();
1527
- return {
1528
- type: 'POSTPROCESS',
1529
- functionName: functionName,
1530
- };
1531
- }
1532
- else if (type.startsWith('EXPECT_JSON')) {
1533
- return {
1534
- type: 'EXPECT_FORMAT',
1535
- format: 'JSON',
1536
- };
1537
- // [🥤]
1538
- }
1539
- else if (type.startsWith('EXPECT')) {
1540
- try {
1541
- listItemParts.shift();
1542
- var sign = void 0;
1543
- var signRaw = listItemParts.shift();
1544
- if (/^exact/i.test(signRaw)) {
1545
- sign = 'EXACTLY';
1256
+ else if (/^[A-Z]$/.test(char)) {
1257
+ charType = 'UPPERCASE';
1258
+ normalizedChar = char.toLowerCase();
1546
1259
  }
1547
- else if (/^min/i.test(signRaw)) {
1548
- sign = 'MINIMUM';
1260
+ else if (/^[0-9]$/.test(char)) {
1261
+ charType = 'NUMBER';
1262
+ normalizedChar = char;
1549
1263
  }
1550
- else if (/^max/i.test(signRaw)) {
1551
- sign = 'MAXIMUM';
1264
+ else if (/^\/$/.test(char)) {
1265
+ charType = 'SLASH';
1266
+ normalizedChar = char;
1552
1267
  }
1553
1268
  else {
1554
- throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
1555
- }
1556
- var amountRaw = listItemParts.shift();
1557
- var amount = parseNumber(amountRaw);
1558
- if (amount < 0) {
1559
- throw new PromptbookSyntaxError('Amount must be positive number or zero');
1560
- }
1561
- if (amount !== Math.floor(amount)) {
1562
- throw new PromptbookSyntaxError('Amount must be whole number');
1563
- }
1564
- var unitRaw = listItemParts.shift();
1565
- var unit = undefined;
1566
- try {
1567
- for (var EXPECTATION_UNITS_1 = __values(EXPECTATION_UNITS), EXPECTATION_UNITS_1_1 = EXPECTATION_UNITS_1.next(); !EXPECTATION_UNITS_1_1.done; EXPECTATION_UNITS_1_1 = EXPECTATION_UNITS_1.next()) {
1568
- var existingUnit = EXPECTATION_UNITS_1_1.value;
1569
- var existingUnitText = existingUnit;
1570
- existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
1571
- if (existingUnitText === 'CHARACTER') {
1572
- existingUnitText = 'CHAR';
1573
- }
1574
- if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
1575
- new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
1576
- if (unit !== undefined) {
1577
- throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
1578
- }
1579
- unit = existingUnit;
1580
- }
1581
- }
1582
- }
1583
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1584
- finally {
1585
- try {
1586
- if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
1587
- }
1588
- finally { if (e_1) throw e_1.error; }
1589
- }
1590
- if (unit === undefined) {
1591
- throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
1269
+ charType = 'OTHER';
1270
+ normalizedChar = '-';
1592
1271
  }
1593
- return {
1594
- type: 'EXPECT_AMOUNT',
1595
- sign: sign,
1596
- unit: unit,
1597
- amount: amount,
1598
- };
1599
- }
1600
- catch (error) {
1601
- if (!(error instanceof Error)) {
1602
- throw error;
1272
+ if (charType !== lastCharType &&
1273
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1274
+ !(lastCharType === 'NUMBER') &&
1275
+ !(charType === 'NUMBER')) {
1276
+ normalizedName += '-';
1603
1277
  }
1604
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
1278
+ normalizedName += normalizedChar;
1279
+ lastCharType = charType;
1605
1280
  }
1606
- /*
1607
- } else if (type.startsWith('__________________')) {
1608
- // <- [🥻] Insert here when making new command
1609
- */
1610
1281
  }
1611
- else {
1612
- throw new PromptbookSyntaxError(spaceTrim("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - PROMPTBOOK_URL <url>\n - PROMPTBOOK_VERSION <version>\n - EXECUTE PROMPT TEMPLATE\n - EXECUTE SIMPLE TEMPLATE\n - SIMPLE TEMPLATE\n - EXECUTE SCRIPT\n - EXECUTE PROMPT_DIALOG'\n - PROMPT_DIALOG'\n - MODEL NAME <name>\n - MODEL VARIANT <\"Chat\"|\"Completion\">\n - INPUT PARAM {<name>} <description>\n - OUTPUT PARAM {<name>} <description>\n - POSTPROCESS `{functionName}`\n - JOKER {<name>}\n - EXPECT JSON\n - EXPECT <\"Exactly\"|\"Min\"|\"Max\"> <number> <\"Chars\"|\"Words\"|\"Sentences\"|\"Paragraphs\"|\"Pages\">\n\n ")));
1282
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1283
+ finally {
1284
+ try {
1285
+ if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
1286
+ }
1287
+ finally { if (e_1) throw e_1.error; }
1613
1288
  }
1289
+ normalizedName = normalizedName.split(/-+/g).join('-');
1290
+ normalizedName = normalizedName.split(/-?\/-?/g).join('/');
1291
+ normalizedName = normalizedName.replace(/^-/, '');
1292
+ normalizedName = normalizedName.replace(/-$/, '');
1293
+ return normalizedName;
1294
+ }
1295
+
1296
+ /**
1297
+ * Removes emojis from a string and fix whitespaces
1298
+ *
1299
+ * @param text with emojis
1300
+ * @returns text without emojis
1301
+ */
1302
+ function removeEmojis(text) {
1303
+ // Replace emojis (and also ZWJ sequence) with hyphens
1304
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
1305
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
1306
+ text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
1307
+ text = text.replace(/\p{Extended_Pictographic}/gu, '');
1308
+ return text;
1309
+ }
1310
+
1311
+ /**
1312
+ * Function normalizes title to name which can be used as identifier
1313
+ */
1314
+ function titleToName(value) {
1315
+ value = removeEmojis(value);
1316
+ value = normalizeToKebabCase(value);
1317
+ // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
1318
+ return value;
1614
1319
  }
1615
1320
 
1616
1321
  /**
@@ -1824,6 +1529,9 @@ function promptbookStringToJson(promptbookString) {
1824
1529
  postprocessing = undefined;
1825
1530
  }
1826
1531
  dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
1532
+ if (templateModelRequirements.modelVariant === undefined) {
1533
+ templateModelRequirements.modelVariant = 'CHAT';
1534
+ }
1827
1535
  promptbookJson.promptTemplates.push({
1828
1536
  name: titleToName(section.title),
1829
1537
  title: section.title,
@@ -1915,6 +1623,119 @@ function prettifyMarkdown(content) {
1915
1623
  }
1916
1624
  }
1917
1625
 
1626
+ /* tslint:disable */
1627
+ function normalizeTo_camelCase(sentence, __firstLetterCapital) {
1628
+ var e_1, _a;
1629
+ if (__firstLetterCapital === void 0) { __firstLetterCapital = false; }
1630
+ var charType;
1631
+ var lastCharType = null;
1632
+ var normalizedName = '';
1633
+ try {
1634
+ for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1635
+ var char = sentence_1_1.value;
1636
+ var normalizedChar = void 0;
1637
+ if (/^[a-z]$/.test(char)) {
1638
+ charType = 'LOWERCASE';
1639
+ normalizedChar = char;
1640
+ }
1641
+ else if (/^[A-Z]$/.test(char)) {
1642
+ charType = 'UPPERCASE';
1643
+ normalizedChar = char.toLowerCase();
1644
+ }
1645
+ else if (/^[0-9]$/.test(char)) {
1646
+ charType = 'NUMBER';
1647
+ normalizedChar = char;
1648
+ }
1649
+ else {
1650
+ charType = 'OTHER';
1651
+ normalizedChar = '';
1652
+ }
1653
+ if (!lastCharType) {
1654
+ if (__firstLetterCapital) {
1655
+ normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
1656
+ }
1657
+ }
1658
+ else if (charType !== lastCharType &&
1659
+ !(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
1660
+ !(lastCharType === 'NUMBER') &&
1661
+ !(charType === 'NUMBER')) {
1662
+ normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
1663
+ }
1664
+ normalizedName += normalizedChar;
1665
+ lastCharType = charType;
1666
+ }
1667
+ }
1668
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1669
+ finally {
1670
+ try {
1671
+ if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
1672
+ }
1673
+ finally { if (e_1) throw e_1.error; }
1674
+ }
1675
+ return normalizedName;
1676
+ }
1677
+ /**
1678
+ * TODO: [🌺] Use some intermediate util splitWords
1679
+ */
1680
+
1681
+ /**
1682
+ * Creates a Mermaid graph based on the promptbook
1683
+ *
1684
+ * Note: The result is not wrapped in a Markdown code block
1685
+ */
1686
+ function renderPromptbookMermaid(promptbookJson, options) {
1687
+ var _a = (options || {}).linkPromptTemplate, linkPromptTemplate = _a === void 0 ? function () { return null; } : _a;
1688
+ var parameterNameToTemplateName = function (parameterName) {
1689
+ var parameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
1690
+ if (!parameter) {
1691
+ throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
1692
+ }
1693
+ if (parameter.isInput) {
1694
+ return 'input';
1695
+ }
1696
+ var template = promptbookJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
1697
+ if (!template) {
1698
+ throw new Error("Could not find template for {".concat(parameterName, "}"));
1699
+ }
1700
+ return normalizeTo_camelCase('template-' + titleToName(template.title));
1701
+ };
1702
+ 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
1703
+ .flatMap(function (_a) {
1704
+ var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
1705
+ return __spreadArray([
1706
+ "".concat(parameterNameToTemplateName(resultingParameterName), "(\"").concat(title, "\")")
1707
+ ], __read(dependentParameterNames.map(function (dependentParameterName) {
1708
+ return "".concat(parameterNameToTemplateName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName(resultingParameterName));
1709
+ })), false);
1710
+ })
1711
+ .join('\n')), "\n\n ").concat(block(promptbookJson.parameters
1712
+ .filter(function (_a) {
1713
+ var isOutput = _a.isOutput;
1714
+ return isOutput;
1715
+ })
1716
+ .map(function (_a) {
1717
+ var name = _a.name;
1718
+ return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
1719
+ })
1720
+ .join('\n')), "\n output((Output)):::output\n\n ").concat(block(promptbookJson.promptTemplates
1721
+ .map(function (promptTemplate) {
1722
+ var link = linkPromptTemplate(promptTemplate);
1723
+ if (link === null) {
1724
+ return '';
1725
+ }
1726
+ var href = link.href, title = link.title;
1727
+ var templateName = parameterNameToTemplateName(promptTemplate.resultingParameterName);
1728
+ return "click ".concat(templateName, " href \"").concat(href, "\" \"").concat(title, "\";");
1729
+ })
1730
+ .filter(function (line) { return line !== ''; })
1731
+ .join('\n')), "\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
1732
+ return promptbookMermaid;
1733
+ }
1734
+ /**
1735
+ * TODO: Maybe use some Mermaid library instead of string templating
1736
+ * TODO: [🕌] When more than 2 functionalities, split into separate functions
1737
+ */
1738
+
1918
1739
  /**
1919
1740
  * Prettyfies Promptbook string and adds Mermaid graph
1920
1741
  */
@@ -2129,6 +1950,20 @@ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
2129
1950
  * TODO: Escape all
2130
1951
  */
2131
1952
 
1953
+ /**
1954
+ * This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
1955
+ */
1956
+ var PromptbookLogicError = /** @class */ (function (_super) {
1957
+ __extends(PromptbookLogicError, _super);
1958
+ function PromptbookLogicError(message) {
1959
+ var _this = _super.call(this, message) || this;
1960
+ _this.name = 'PromptbookLogicError';
1961
+ Object.setPrototypeOf(_this, PromptbookLogicError.prototype);
1962
+ return _this;
1963
+ }
1964
+ return PromptbookLogicError;
1965
+ }(Error));
1966
+
2132
1967
  /**
2133
1968
  * Tests if given string is valid URL.
2134
1969
  *
@@ -2169,6 +2004,7 @@ function isValidUrl(url) {
2169
2004
  * @throws {PromptbookLogicError} on logical error in the promptbook
2170
2005
  */
2171
2006
  function validatePromptbookJson(promptbook) {
2007
+ // TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
2172
2008
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
2173
2009
  if (promptbook.promptbookUrl !== undefined) {
2174
2010
  if (!isValidUrl(promptbook.promptbookUrl)) {
@@ -2176,6 +2012,16 @@ function validatePromptbookJson(promptbook) {
2176
2012
  throw new PromptbookLogicError("Invalid promptbook URL \"".concat(promptbook.promptbookUrl, "\""));
2177
2013
  }
2178
2014
  }
2015
+ // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
2016
+ if (!Array.isArray(promptbook.parameters)) {
2017
+ // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
2018
+ throw new PromptbookSyntaxError(spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.parameters expected to be an array, but got ".concat(typeof promptbook.parameters, "\n ")));
2019
+ }
2020
+ // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
2021
+ if (!Array.isArray(promptbook.promptTemplates)) {
2022
+ // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
2023
+ throw new PromptbookSyntaxError(spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.promptTemplates expected to be an array, but got ".concat(typeof promptbook.promptTemplates, "\n ")));
2024
+ }
2179
2025
  var _loop_1 = function (parameter) {
2180
2026
  if (parameter.isInput && parameter.isOutput) {
2181
2027
  throw new PromptbookLogicError("Parameter {".concat(parameter.name, "} can not be both input and output"));
@@ -2222,9 +2068,8 @@ function validatePromptbookJson(promptbook) {
2222
2068
  }
2223
2069
  definedParameters.add(template.resultingParameterName);
2224
2070
  if (template.executionType === 'PROMPT_TEMPLATE' &&
2225
- (template.modelRequirements.modelVariant === undefined ||
2226
- template.modelRequirements.modelName === undefined)) {
2227
- throw new PromptbookLogicError(spaceTrim("\n\n You must specify MODEL VARIANT and MODEL NAME in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
2071
+ (template.modelRequirements.modelVariant === undefined)) {
2072
+ throw new PromptbookLogicError(spaceTrim("\n\n You must specify MODEL VARIANT in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
2228
2073
  }
2229
2074
  if (template.jokers && template.jokers.length > 0) {
2230
2075
  if (!template.expectFormat &&
@@ -2332,60 +2177,153 @@ function validatePromptbookJson(promptbook) {
2332
2177
  */
2333
2178
 
2334
2179
  /**
2335
- * This error indicates errors during the execution of the promptbook
2180
+ * This error indicates errors during the execution of the promptbook
2181
+ */
2182
+ var PromptbookExecutionError = /** @class */ (function (_super) {
2183
+ __extends(PromptbookExecutionError, _super);
2184
+ function PromptbookExecutionError(message) {
2185
+ var _this = _super.call(this, message) || this;
2186
+ _this.name = 'PromptbookExecutionError';
2187
+ Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
2188
+ return _this;
2189
+ }
2190
+ return PromptbookExecutionError;
2191
+ }(Error));
2192
+
2193
+ /**
2194
+ * Asserts that the execution of a promptnook is successful
2195
+ *
2196
+ * @param executionResult - The partial result of the promptnook execution
2197
+ * @throws {PromptbookExecutionError} If the execution is not successful or if multiple errors occurred
2198
+ */
2199
+ function assertsExecutionSuccessful(executionResult) {
2200
+ var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
2201
+ if (isSuccessful === true) {
2202
+ return;
2203
+ }
2204
+ if (errors.length === 0) {
2205
+ throw new PromptbookExecutionError("Promptnook Execution failed because of unknown reason");
2206
+ }
2207
+ else if (errors.length === 1) {
2208
+ throw errors[0];
2209
+ }
2210
+ else {
2211
+ 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 "); }));
2212
+ }
2213
+ }
2214
+ /**
2215
+ * TODO: [🧠] Can this return type be better typed than void
2216
+ */
2217
+
2218
+ /**
2219
+ * This error occurs when some expectation is not met in the execution of the pipeline
2220
+ *
2221
+ * @private Always catched and rethrown as `PromptbookExecutionError`
2222
+ * Note: This is a kindof subtype of PromptbookExecutionError
2223
+ */
2224
+ var ExpectError = /** @class */ (function (_super) {
2225
+ __extends(ExpectError, _super);
2226
+ function ExpectError(message) {
2227
+ var _this = _super.call(this, message) || this;
2228
+ _this.name = 'ExpectError';
2229
+ Object.setPrototypeOf(_this, ExpectError.prototype);
2230
+ return _this;
2231
+ }
2232
+ return ExpectError;
2233
+ }(Error));
2234
+
2235
+ /**
2236
+ * Function isValidJsonString will tell you if the string is valid JSON or not
2237
+ */
2238
+ function isValidJsonString(value) {
2239
+ try {
2240
+ JSON.parse(value);
2241
+ return true;
2242
+ }
2243
+ catch (error) {
2244
+ if (!(error instanceof Error)) {
2245
+ throw error;
2246
+ }
2247
+ if (error.message.includes('Unexpected token')) {
2248
+ return false;
2249
+ }
2250
+ return false;
2251
+ }
2252
+ }
2253
+
2254
+ /**
2255
+ * Counts number of characters in the text
2256
+ */
2257
+ function countCharacters(text) {
2258
+ // Remove null characters
2259
+ text = text.replace(/\0/g, '');
2260
+ // Replace emojis (and also ZWJ sequence) with hyphens
2261
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
2262
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
2263
+ text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
2264
+ return text.length;
2265
+ }
2266
+
2267
+ /**
2268
+ * Counts number of lines in the text
2269
+ */
2270
+ function countLines(text) {
2271
+ if (text === '') {
2272
+ return 0;
2273
+ }
2274
+ return text.split('\n').length;
2275
+ }
2276
+
2277
+ /**
2278
+ * Counts number of pages in the text
2279
+ */
2280
+ function countPages(text) {
2281
+ var sentencesPerPage = 5; // Assuming each page has 5 sentences
2282
+ var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
2283
+ var pageCount = Math.ceil(sentences.length / sentencesPerPage);
2284
+ return pageCount;
2285
+ }
2286
+
2287
+ /**
2288
+ * Counts number of paragraphs in the text
2289
+ */
2290
+ function countParagraphs(text) {
2291
+ return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
2292
+ }
2293
+
2294
+ /**
2295
+ * Split text into sentences
2336
2296
  */
2337
- var PromptbookExecutionError = /** @class */ (function (_super) {
2338
- __extends(PromptbookExecutionError, _super);
2339
- function PromptbookExecutionError(message) {
2340
- var _this = _super.call(this, message) || this;
2341
- _this.name = 'PromptbookExecutionError';
2342
- Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
2343
- return _this;
2344
- }
2345
- return PromptbookExecutionError;
2346
- }(Error));
2347
-
2297
+ function splitIntoSentences(text) {
2298
+ return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
2299
+ }
2348
2300
  /**
2349
- * Asserts that the execution of a promptnook is successful
2350
- *
2351
- * @param executionResult - The partial result of the promptnook execution
2352
- * @throws {PromptbookExecutionError} If the execution is not successful or if multiple errors occurred
2301
+ * Counts number of sentences in the text
2353
2302
  */
2354
- function assertsExecutionSuccessful(executionResult) {
2355
- var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
2356
- if (isSuccessful === true) {
2357
- return;
2358
- }
2359
- if (errors.length === 0) {
2360
- throw new PromptbookExecutionError("Promptnook Execution failed because of unknown reason");
2361
- }
2362
- else if (errors.length === 1) {
2363
- throw errors[0];
2364
- }
2365
- else {
2366
- 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 "); }));
2367
- }
2303
+ function countSentences(text) {
2304
+ return splitIntoSentences(text).length;
2368
2305
  }
2306
+
2369
2307
  /**
2370
- * TODO: [🧠] Can this return type be better typed than void
2308
+ * Counts number of words in the text
2371
2309
  */
2310
+ function countWords(text) {
2311
+ text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
2312
+ text = removeDiacritics(text);
2313
+ return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
2314
+ }
2372
2315
 
2373
2316
  /**
2374
- * This error occurs when some expectation is not met in the execution of the pipeline
2375
- *
2376
- * @private Always catched and rethrown as `PromptbookExecutionError`
2377
- * Note: This is a kindof subtype of PromptbookExecutionError
2317
+ * Index of all counter functions
2378
2318
  */
2379
- var ExpectError = /** @class */ (function (_super) {
2380
- __extends(ExpectError, _super);
2381
- function ExpectError(message) {
2382
- var _this = _super.call(this, message) || this;
2383
- _this.name = 'ExpectError';
2384
- Object.setPrototypeOf(_this, ExpectError.prototype);
2385
- return _this;
2386
- }
2387
- return ExpectError;
2388
- }(Error));
2319
+ var CountUtils = {
2320
+ CHARACTERS: countCharacters,
2321
+ WORDS: countWords,
2322
+ SENTENCES: countSentences,
2323
+ PARAGRAPHS: countParagraphs,
2324
+ LINES: countLines,
2325
+ PAGES: countPages,
2326
+ };
2389
2327
 
2390
2328
  /**
2391
2329
  * Function checkExpectations will check if the expectations on given value are met
@@ -2444,6 +2382,82 @@ function isPassingExpectations(expectations, value) {
2444
2382
  * TODO: [💝] Unite object for expecting amount and format
2445
2383
  */
2446
2384
 
2385
+ /**
2386
+ * This error occurs during the parameter replacement in the template
2387
+ *
2388
+ * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
2389
+ */
2390
+ var TemplateError = /** @class */ (function (_super) {
2391
+ __extends(TemplateError, _super);
2392
+ function TemplateError(message) {
2393
+ var _this = _super.call(this, message) || this;
2394
+ _this.name = 'TemplateError';
2395
+ Object.setPrototypeOf(_this, TemplateError.prototype);
2396
+ return _this;
2397
+ }
2398
+ return TemplateError;
2399
+ }(Error));
2400
+
2401
+ /**
2402
+ * Replaces parameters in template with values from parameters object
2403
+ *
2404
+ * @param template the template with parameters in {curly} braces
2405
+ * @param parameters the object with parameters
2406
+ * @returns the template with replaced parameters
2407
+ * @throws {TemplateError} if parameter is not defined, not closed, or not opened
2408
+ *
2409
+ * @private within the createPromptbookExecutor
2410
+ */
2411
+ function replaceParameters(template, parameters) {
2412
+ var replacedTemplate = template;
2413
+ var match;
2414
+ var loopLimit = LOOP_LIMIT;
2415
+ var _loop_1 = function () {
2416
+ if (loopLimit-- < 0) {
2417
+ throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
2418
+ }
2419
+ var precol = match.groups.precol;
2420
+ var parameterName = match.groups.parameterName;
2421
+ if (parameterName === '') {
2422
+ return "continue";
2423
+ }
2424
+ if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
2425
+ throw new TemplateError('Parameter is already opened or not closed');
2426
+ }
2427
+ if (parameters[parameterName] === undefined) {
2428
+ throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
2429
+ }
2430
+ var parameterValue = parameters[parameterName];
2431
+ if (parameterValue === undefined) {
2432
+ throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
2433
+ }
2434
+ parameterValue = parameterValue.toString();
2435
+ if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
2436
+ parameterValue = parameterValue
2437
+ .split('\n')
2438
+ .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
2439
+ .join('\n');
2440
+ }
2441
+ replacedTemplate =
2442
+ replacedTemplate.substring(0, match.index + precol.length) +
2443
+ parameterValue +
2444
+ replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
2445
+ };
2446
+ while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
2447
+ .exec(replacedTemplate))) {
2448
+ _loop_1();
2449
+ }
2450
+ // [💫] Check if there are parameters that are not closed properly
2451
+ if (/{\w+$/.test(replacedTemplate)) {
2452
+ throw new TemplateError('Parameter is not closed');
2453
+ }
2454
+ // [💫] Check if there are parameters that are not opened properly
2455
+ if (/^\w+}/.test(replacedTemplate)) {
2456
+ throw new TemplateError('Parameter is not opened');
2457
+ }
2458
+ return replacedTemplate;
2459
+ }
2460
+
2447
2461
  /**
2448
2462
  * Creates executor function from promptbook and execution tools.
2449
2463
  *
@@ -2525,7 +2539,7 @@ function createPromptbookExecutor(options) {
2525
2539
  title: currentTemplate.title,
2526
2540
  promptbookUrl: "".concat(promptbook.promptbookUrl
2527
2541
  ? promptbook.promptbookUrl
2528
- : 'anonymous' /* <- [🧠][🈴] How to deal with anonymous PROMPTBOOKs, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
2542
+ : 'anonymous' /* <- TODO: [🧠] How to deal with anonymous PROMPTBOOKs, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
2529
2543
  parameters: parametersToPass,
2530
2544
  content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
2531
2545
  modelRequirements: currentTemplate.modelRequirements,
@@ -3155,6 +3169,20 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
3155
3169
  return SimplePromptInterfaceTools;
3156
3170
  }());
3157
3171
 
3172
+ /**
3173
+ * This error indicates that the promptbook library cannot be propperly loaded
3174
+ */
3175
+ var PromptbookLibraryError = /** @class */ (function (_super) {
3176
+ __extends(PromptbookLibraryError, _super);
3177
+ function PromptbookLibraryError(message) {
3178
+ var _this = _super.call(this, message) || this;
3179
+ _this.name = 'PromptbookLibraryError';
3180
+ Object.setPrototypeOf(_this, PromptbookLibraryError.prototype);
3181
+ return _this;
3182
+ }
3183
+ return PromptbookLibraryError;
3184
+ }(Error));
3185
+
3158
3186
  /**
3159
3187
  * Detects if the code is running in a browser environment in main thread (Not in a web worker)
3160
3188
  */
@@ -3168,6 +3196,23 @@ var isRunningInNode = new Function("\n try {\n return this === global;
3168
3196
  */
3169
3197
  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");
3170
3198
 
3199
+ /**
3200
+ * Returns the same value that is passed as argument.
3201
+ * No side effects.
3202
+ *
3203
+ * Note: It can be usefull for leveling indentation
3204
+ *
3205
+ * @param value any values
3206
+ * @returns the same values
3207
+ */
3208
+ function just(value) {
3209
+ if (value === undefined) {
3210
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3211
+ return undefined;
3212
+ }
3213
+ return value;
3214
+ }
3215
+
3171
3216
  /**
3172
3217
  * This error indicates that promptbook not found in the library
3173
3218
  */
@@ -3225,6 +3270,12 @@ var SimplePromptbookLibrary = /** @class */ (function () {
3225
3270
  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 ")));
3226
3271
  }
3227
3272
  validatePromptbookJson(promptbook);
3273
+ // Note: [🦄]
3274
+ if (this.library.has(promptbook.promptbookUrl) &&
3275
+ promptbookJsonToString(promptbook) !==
3276
+ promptbookJsonToString(this.library.get(promptbook.promptbookUrl))) {
3277
+ 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 ")));
3278
+ }
3228
3279
  this.library.set(promptbook.promptbookUrl, promptbook);
3229
3280
  }
3230
3281
  }
@@ -3251,6 +3302,9 @@ var SimplePromptbookLibrary = /** @class */ (function () {
3251
3302
  var _this = this;
3252
3303
  var promptbook = this.library.get(url);
3253
3304
  if (!promptbook) {
3305
+ if (this.listPromptbooks().length === 0) {
3306
+ throw new PromptbookNotFoundError(spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
3307
+ }
3254
3308
  throw new PromptbookNotFoundError(spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
3255
3309
  .map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
3256
3310
  .join('\n')), "\n\n "); }));
@@ -3323,11 +3377,11 @@ function createPromptbookLibraryFromSources() {
3323
3377
  * Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
3324
3378
  * when error occurs in given promise or factory function, it is thrown during `listPromptbooks` or `getPromptbookByUrl` call
3325
3379
  *
3380
+ * Note: Consider using `createPromptbookLibraryFromDirectory` or `createPromptbookLibraryFromUrl`
3326
3381
  *
3327
3382
  * @param promptbookSourcesPromiseOrFactory
3328
3383
  * @returns PromptbookLibrary
3329
- *
3330
- * @deprecated Consider using `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
3384
+ * @private Just internal tool for other constructor functions
3331
3385
  */
3332
3386
  function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3333
3387
  var library;
@@ -3400,37 +3454,252 @@ function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
3400
3454
  * Constructs Promptbook from given directory
3401
3455
  *
3402
3456
  * Note: Works only in Node.js environment because it reads the file system
3403
- * Note: The function does NOT return promise it returns the library directly which dynamically loads promptbooks when needed
3404
- * SO during the construction syntax and logic sources IS NOT validated
3405
3457
  *
3406
3458
  * @param path - path to the directory with promptbooks
3407
3459
  * @param options - Misc options for the library
3408
3460
  * @returns PromptbookLibrary
3409
3461
  */
3410
3462
  function createPromptbookLibraryFromDirectory(path, options) {
3411
- var _this = this;
3412
- if (!isRunningInNode()) {
3413
- throw new Error('Function `createPromptbookLibraryFromDirectory` can only be run in Node.js environment because it reads the file system.');
3414
- }
3415
- var _a = (options || {}).isRecursive, isRecursive = _a === void 0 ? true : _a;
3416
- return createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3417
- var readdir, readdirResult;
3418
- return __generator(this, function (_a) {
3419
- switch (_a.label) {
3420
- case 0: return [4 /*yield*/, import('fs/promises')];
3463
+ return __awaiter(this, void 0, void 0, function () {
3464
+ var _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashOnError, library;
3465
+ var _this = this;
3466
+ return __generator(this, function (_f) {
3467
+ switch (_f.label) {
3468
+ case 0:
3469
+ if (!isRunningInNode()) {
3470
+ throw new Error('Function `createPromptbookLibraryFromDirectory` can only be run in Node.js environment because it reads the file system.');
3471
+ }
3472
+ _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, _e = _a.isCrashOnError, isCrashOnError = _e === void 0 ? true : _e;
3473
+ library = createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3474
+ var fsPromises, readFile, fileNames, promptbooks, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
3475
+ var e_1, _a;
3476
+ return __generator(this, function (_b) {
3477
+ switch (_b.label) {
3478
+ case 0:
3479
+ if (isVerbose) {
3480
+ console.info("Creating promptbook library from path ".concat(path));
3481
+ }
3482
+ fsPromises = require(just('fs/promises') /* <- Note: [1] */);
3483
+ readFile = fsPromises.readFile;
3484
+ return [4 /*yield*/, listAllFiles(path, isRecursive)];
3485
+ case 1:
3486
+ fileNames = _b.sent();
3487
+ if (isVerbose) {
3488
+ console.info('createPromptbookLibraryFromDirectory', { path: path, isRecursive: isRecursive, fileNames: fileNames });
3489
+ }
3490
+ promptbooks = [];
3491
+ _loop_1 = function (fileName) {
3492
+ var promptbook, promptbookString, _c, _d, error_1, wrappedErrorMessage;
3493
+ return __generator(this, function (_e) {
3494
+ switch (_e.label) {
3495
+ case 0:
3496
+ _e.trys.push([0, 6, , 7]);
3497
+ promptbook = null;
3498
+ if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 2];
3499
+ return [4 /*yield*/, readFile(fileName, 'utf8')];
3500
+ case 1:
3501
+ promptbookString = (_e.sent());
3502
+ promptbook = promptbookStringToJson(promptbookString);
3503
+ return [3 /*break*/, 5];
3504
+ case 2:
3505
+ if (!fileName.endsWith('.ptbk.json')) return [3 /*break*/, 4];
3506
+ if (isVerbose) {
3507
+ console.info("Loading ".concat(fileName));
3508
+ }
3509
+ _d = (_c = JSON).parse;
3510
+ return [4 /*yield*/, readFile(fileName, 'utf8')];
3511
+ case 3:
3512
+ // TODO: Handle non-valid JSON files
3513
+ promptbook = _d.apply(_c, [_e.sent()]);
3514
+ return [3 /*break*/, 5];
3515
+ case 4:
3516
+ if (isVerbose) {
3517
+ console.info("Skipping file ".concat(fileName));
3518
+ }
3519
+ _e.label = 5;
3520
+ case 5:
3521
+ // ---
3522
+ if (promptbook !== null) {
3523
+ if (!promptbook.promptbookUrl) {
3524
+ if (isVerbose) {
3525
+ console.info("Not loading ".concat(fileName, " - missing URL"));
3526
+ }
3527
+ }
3528
+ else {
3529
+ if (isVerbose) {
3530
+ console.info("Loading ".concat(fileName));
3531
+ }
3532
+ if (!isCrashOnError) {
3533
+ // Note: Validate promptbook to check if it is logically correct to not crash on invalid promptbooks
3534
+ // But be handled in current try-catch block
3535
+ validatePromptbookJson(promptbook);
3536
+ }
3537
+ // Note: [🦄] Promptbook with same url uniqueness will be checked automatically in SimplePromptbookLibrary
3538
+ promptbooks.push(promptbook);
3539
+ }
3540
+ }
3541
+ return [3 /*break*/, 7];
3542
+ case 6:
3543
+ error_1 = _e.sent();
3544
+ if (!(error_1 instanceof Error)) {
3545
+ throw error_1;
3546
+ }
3547
+ wrappedErrorMessage = spaceTrim$1(function (block) { return "\n Error during loading promptbook from file ".concat(fileName.split('\\').join('/'), ":\n\n ").concat(block(error_1.message), "\n\n "); });
3548
+ if (isCrashOnError) {
3549
+ throw new PromptbookLibraryError(wrappedErrorMessage);
3550
+ }
3551
+ console.error(wrappedErrorMessage);
3552
+ return [3 /*break*/, 7];
3553
+ case 7: return [2 /*return*/];
3554
+ }
3555
+ });
3556
+ };
3557
+ _b.label = 2;
3558
+ case 2:
3559
+ _b.trys.push([2, 7, 8, 9]);
3560
+ fileNames_1 = __values(fileNames), fileNames_1_1 = fileNames_1.next();
3561
+ _b.label = 3;
3562
+ case 3:
3563
+ if (!!fileNames_1_1.done) return [3 /*break*/, 6];
3564
+ fileName = fileNames_1_1.value;
3565
+ return [5 /*yield**/, _loop_1(fileName)];
3566
+ case 4:
3567
+ _b.sent();
3568
+ _b.label = 5;
3569
+ case 5:
3570
+ fileNames_1_1 = fileNames_1.next();
3571
+ return [3 /*break*/, 3];
3572
+ case 6: return [3 /*break*/, 9];
3573
+ case 7:
3574
+ e_1_1 = _b.sent();
3575
+ e_1 = { error: e_1_1 };
3576
+ return [3 /*break*/, 9];
3577
+ case 8:
3578
+ try {
3579
+ if (fileNames_1_1 && !fileNames_1_1.done && (_a = fileNames_1.return)) _a.call(fileNames_1);
3580
+ }
3581
+ finally { if (e_1) throw e_1.error; }
3582
+ return [7 /*endfinally*/];
3583
+ case 9: return [2 /*return*/, promptbooks];
3584
+ }
3585
+ });
3586
+ }); });
3587
+ if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
3588
+ return [4 /*yield*/, library.listPromptbooks()];
3589
+ case 1:
3590
+ _f.sent();
3591
+ _f.label = 2;
3592
+ case 2: return [2 /*return*/, library];
3593
+ }
3594
+ });
3595
+ });
3596
+ }
3597
+ /**
3598
+ * Reads all files in the directory
3599
+ *
3600
+ * @param path
3601
+ * @param isRecursive
3602
+ * @returns List of all files in the directory
3603
+ * @private internal function for `createPromptbookLibraryFromDirectory`
3604
+ */
3605
+ function listAllFiles(path, isRecursive) {
3606
+ return __awaiter(this, void 0, void 0, function () {
3607
+ var fsPromises, readdir, dirents, fileNames, _a, _b, dirent, subPath, _c, _d, _e, _f, e_2_1;
3608
+ var e_2, _g;
3609
+ return __generator(this, function (_h) {
3610
+ switch (_h.label) {
3611
+ case 0:
3612
+ fsPromises = require(just('fs/promises') /* <- Note: [1] */);
3613
+ readdir = fsPromises.readdir;
3614
+ return [4 /*yield*/, readdir(path, {
3615
+ withFileTypes: true /* Note: This is not working: recursive: isRecursive */,
3616
+ })];
3421
3617
  case 1:
3422
- readdir = (_a.sent()).readdir;
3423
- return [4 /*yield*/, readdir(path)];
3618
+ dirents = _h.sent();
3619
+ fileNames = dirents.filter(function (dirent) { return dirent.isFile(); }).map(function (_a) {
3620
+ var name = _a.name;
3621
+ return join(path, name);
3622
+ });
3623
+ if (!isRecursive) return [3 /*break*/, 9];
3624
+ _h.label = 2;
3424
3625
  case 2:
3425
- readdirResult = _a.sent();
3426
- // TODO: !!! Implement
3427
- console.info('createPromptbookLibraryFromDirectory', { path: path, isRecursive: isRecursive, readdirResult: readdirResult });
3428
- throw new Error('Not implemented yet');
3626
+ _h.trys.push([2, 7, 8, 9]);
3627
+ _a = __values(dirents.filter(function (dirent) { return dirent.isDirectory(); })), _b = _a.next();
3628
+ _h.label = 3;
3629
+ case 3:
3630
+ if (!!_b.done) return [3 /*break*/, 6];
3631
+ dirent = _b.value;
3632
+ subPath = join(path, dirent.name);
3633
+ _d = (_c = fileNames.push).apply;
3634
+ _e = [fileNames];
3635
+ _f = [[]];
3636
+ return [4 /*yield*/, listAllFiles(subPath, isRecursive)];
3637
+ case 4:
3638
+ _d.apply(_c, _e.concat([__spreadArray.apply(void 0, _f.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
3639
+ _h.label = 5;
3640
+ case 5:
3641
+ _b = _a.next();
3642
+ return [3 /*break*/, 3];
3643
+ case 6: return [3 /*break*/, 9];
3644
+ case 7:
3645
+ e_2_1 = _h.sent();
3646
+ e_2 = { error: e_2_1 };
3647
+ return [3 /*break*/, 9];
3648
+ case 8:
3649
+ try {
3650
+ if (_b && !_b.done && (_g = _a.return)) _g.call(_a);
3651
+ }
3652
+ finally { if (e_2) throw e_2.error; }
3653
+ return [7 /*endfinally*/];
3654
+ case 9: return [2 /*return*/, fileNames];
3655
+ }
3656
+ });
3657
+ });
3658
+ }
3659
+ /***
3660
+ * TODO: [🧠] Maybe do not do hacks like [1] and just create package @promptbook/node
3661
+ * [🍓][🚯] maybe make `@promptbook/library` package
3662
+ * TODO: Fix the dynamic import issue in Webpack (! Not working !)
3663
+ * > ./node_modules/@promptbook/core/esm/index.es.js
3664
+ * > Critical dependency: the request of a dependency is an expression
3665
+ *
3666
+ * Note: [1] Using require(just('fs/promises')) to allow
3667
+ * the `@promptbook/core` work for both Node.js and browser environments
3668
+ */
3669
+
3670
+ /**
3671
+ * Constructs Promptbook from remote Promptbase URL
3672
+
3673
+ * @returns PromptbookLibrary
3674
+ */
3675
+ function createPromptbookLibraryFromUrl(url, options) {
3676
+ return __awaiter(this, void 0, void 0, function () {
3677
+ var _a, _b, isVerbose, _c, isLazyLoaded, library;
3678
+ var _this = this;
3679
+ return __generator(this, function (_d) {
3680
+ switch (_d.label) {
3681
+ case 0:
3682
+ _a = options || {}, _b = _a.isVerbose, isVerbose = _b === void 0 ? false : _b, _c = _a.isLazyLoaded, isLazyLoaded = _c === void 0 ? false : _c;
3683
+ library = createPromptbookLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
3684
+ return __generator(this, function (_a) {
3685
+ if (isVerbose) {
3686
+ console.info("Creating promptbook library from url ".concat(url.toString()));
3687
+ }
3688
+ throw new Error('Not implemented yet');
3689
+ });
3690
+ }); });
3691
+ if (!(isLazyLoaded === false)) return [3 /*break*/, 2];
3692
+ return [4 /*yield*/, library.listPromptbooks()];
3693
+ case 1:
3694
+ _d.sent();
3695
+ _d.label = 2;
3696
+ case 2: return [2 /*return*/, library];
3429
3697
  }
3430
3698
  });
3431
- }); });
3699
+ });
3432
3700
  }
3433
3701
  /***
3702
+ * TODO: [⚖] Compatible with remote server
3434
3703
  * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
3435
3704
  */
3436
3705
 
@@ -3516,6 +3785,31 @@ function createPromptbookSublibrary(library, predicate) {
3516
3785
  * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
3517
3786
  */
3518
3787
 
3788
+ /**
3789
+ * Just testing imports and compatibility
3790
+ */
3791
+ function justTestFsImport() {
3792
+ return __awaiter(this, void 0, void 0, function () {
3793
+ var files;
3794
+ return __generator(this, function (_a) {
3795
+ switch (_a.label) {
3796
+ case 0:
3797
+ if (!isRunningInNode()) {
3798
+ throw new Error('Function `testFiles` can only be run in Node.js environment because it reads the file system.');
3799
+ }
3800
+ return [4 /*yield*/, require(just('glob-promise'))('/**/*')];
3801
+ case 1:
3802
+ files = _a.sent();
3803
+ console.info('testFiles', { files: files });
3804
+ return [2 /*return*/];
3805
+ }
3806
+ });
3807
+ });
3808
+ }
3809
+ /**
3810
+ * TODO: !!! Remove this file
3811
+ */
3812
+
3519
3813
  /**
3520
3814
  * Format either small or big number
3521
3815
  *
@@ -3536,23 +3830,6 @@ function formatNumber(value) {
3536
3830
  return value.toString();
3537
3831
  }
3538
3832
 
3539
- /**
3540
- * Returns the same value that is passed as argument.
3541
- * No side effects.
3542
- *
3543
- * Note: It can be usefull for leveling indentation
3544
- *
3545
- * @param value any values
3546
- * @returns the same values
3547
- */
3548
- function just(value) {
3549
- if (value === undefined) {
3550
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3551
- return undefined;
3552
- }
3553
- return value;
3554
- }
3555
-
3556
3833
  /**
3557
3834
  * Create a markdown table from a 2D array of strings
3558
3835
  *
@@ -3833,5 +4110,5 @@ function executionReportJsonToString(executionReportJson, options) {
3833
4110
  * TODO: [🧠] Allow to filter out some parts of the report by options
3834
4111
  */
3835
4112
 
3836
- export { CallbackInterfaceTools, ExecutionReportStringOptionsDefaults, ExecutionTypes, MultipleLlmExecutionTools, PROMPTBOOK_VERSION, SimplePromptInterfaceTools, SimplePromptbookLibrary, assertsExecutionSuccessful, checkExpectations, createPromptbookExecutor, createPromptbookLibraryFromDirectory, createPromptbookLibraryFromPromise, createPromptbookLibraryFromSources, createPromptbookSublibrary, executionReportJsonToString, isPassingExpectations, prettifyPromptbookString, promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
4113
+ export { CallbackInterfaceTools, ExecutionReportStringOptionsDefaults, ExecutionTypes, MultipleLlmExecutionTools, PROMPTBOOK_VERSION, SimplePromptInterfaceTools, SimplePromptbookLibrary, assertsExecutionSuccessful, checkExpectations, createPromptbookExecutor, createPromptbookLibraryFromDirectory, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, executionReportJsonToString, isPassingExpectations, justTestFsImport, prettifyPromptbookString, promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
3837
4114
  //# sourceMappingURL=index.es.js.map