@promptbook/core 0.52.0 → 0.54.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 (145) hide show
  1. package/esm/index.es.js +989 -989
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/_packages/core.index.d.ts +10 -0
  4. package/esm/typings/_packages/types.index.d.ts +0 -1
  5. package/esm/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
  6. package/esm/typings/conversion/prettify/renderPromptbookMermaid.d.ts +2 -1
  7. package/esm/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +3 -3
  8. package/esm/typings/conversion/utils/extractVariables.d.ts +2 -1
  9. package/esm/typings/conversion/validation/_importPromptbook.d.ts +2 -2
  10. package/esm/typings/execution/LlmExecutionTools.d.ts +4 -2
  11. package/esm/typings/execution/PromptResult.d.ts +5 -1
  12. package/esm/typings/execution/ScriptExecutionTools.d.ts +2 -1
  13. package/esm/typings/execution/UserInterfaceTools.d.ts +2 -1
  14. package/esm/typings/execution/createPromptbookExecutor.d.ts +3 -3
  15. package/esm/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +4 -2
  16. package/esm/typings/execution/plugins/llm-execution-tools/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  17. package/esm/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -2
  18. package/esm/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +2 -1
  19. package/esm/typings/execution/plugins/llm-execution-tools/mocked/MockedEchoLlmExecutionTools.d.ts +4 -2
  20. package/esm/typings/execution/plugins/llm-execution-tools/mocked/MockedFackedLlmExecutionTools.d.ts +4 -2
  21. package/esm/typings/execution/plugins/llm-execution-tools/mocked/fakeTextToExpectations.d.ts +1 -1
  22. package/esm/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools.d.ts +4 -2
  23. package/esm/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionToolsOptions.d.ts +2 -1
  24. package/esm/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +4 -2
  25. package/esm/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
  26. package/esm/typings/execution/plugins/llm-execution-tools/openai/openai-models.d.ts +1 -1
  27. package/esm/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +4 -2
  28. package/esm/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionToolsOptions.d.ts +2 -1
  29. package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Progress.d.ts +1 -1
  30. package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Response.d.ts +1 -1
  31. package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +2 -1
  32. package/esm/typings/execution/plugins/llm-execution-tools/remote/startRemoteServer.d.ts +1 -1
  33. package/esm/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +3 -2
  34. package/esm/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +3 -2
  35. package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +3 -2
  36. package/esm/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -2
  37. package/esm/typings/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +1 -1
  38. package/esm/typings/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +1 -1
  39. package/esm/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +2 -2
  40. package/esm/typings/execution/translation/automatic-translate/translateMessages.d.ts +2 -2
  41. package/esm/typings/execution/utils/replaceParameters.d.ts +2 -2
  42. package/esm/typings/library/SimplePromptbookLibrary.d.ts +1 -1
  43. package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +2 -2
  44. package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +2 -2
  45. package/esm/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +2 -1
  46. package/esm/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +2 -2
  47. package/esm/typings/library/constructors/createPromptbookSublibrary.d.ts +1 -1
  48. package/esm/typings/types/Command.d.ts +5 -2
  49. package/esm/typings/types/Prompt.d.ts +4 -1
  50. package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +8 -1
  51. package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +2 -1
  52. package/esm/typings/types/TaskProgress.d.ts +2 -1
  53. package/esm/typings/types/execution-report/ExecutionReportJson.d.ts +2 -1
  54. package/esm/typings/types/execution-report/countWorkingDuration.d.ts +1 -1
  55. package/esm/typings/utils/emojis.d.ts +1 -1
  56. package/esm/typings/utils/expectation-counters/index.d.ts +2 -1
  57. package/esm/typings/utils/extractParameters.d.ts +2 -1
  58. package/esm/typings/utils/markdown/addAutoGeneratedSection.d.ts +2 -1
  59. package/esm/typings/utils/markdown/createMarkdownChart.d.ts +2 -2
  60. package/esm/typings/utils/markdown/createMarkdownTable.d.ts +2 -1
  61. package/esm/typings/utils/markdown/escapeMarkdownBlock.d.ts +1 -1
  62. package/esm/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +2 -1
  63. package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
  64. package/esm/typings/utils/markdown/removeContentComments.d.ts +2 -1
  65. package/esm/typings/utils/markdown/removeMarkdownFormatting.d.ts +1 -1
  66. package/esm/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +1 -1
  67. package/esm/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +1 -1
  68. package/esm/typings/utils/normalization/isValidKeyword.d.ts +1 -1
  69. package/esm/typings/utils/normalization/parseKeywords.d.ts +1 -1
  70. package/esm/typings/utils/normalization/parseKeywordsFromString.d.ts +1 -1
  71. package/esm/typings/utils/normalization/searchKeywords.d.ts +1 -1
  72. package/esm/typings/utils/postprocessing/extractBlock.d.ts +1 -1
  73. package/package.json +1 -1
  74. package/umd/index.umd.js +997 -988
  75. package/umd/index.umd.js.map +1 -1
  76. package/umd/typings/_packages/core.index.d.ts +10 -0
  77. package/umd/typings/_packages/types.index.d.ts +0 -1
  78. package/umd/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
  79. package/umd/typings/conversion/prettify/renderPromptbookMermaid.d.ts +2 -1
  80. package/umd/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +3 -3
  81. package/umd/typings/conversion/utils/extractVariables.d.ts +2 -1
  82. package/umd/typings/conversion/validation/_importPromptbook.d.ts +2 -2
  83. package/umd/typings/execution/LlmExecutionTools.d.ts +4 -2
  84. package/umd/typings/execution/PromptResult.d.ts +5 -1
  85. package/umd/typings/execution/ScriptExecutionTools.d.ts +2 -1
  86. package/umd/typings/execution/UserInterfaceTools.d.ts +2 -1
  87. package/umd/typings/execution/createPromptbookExecutor.d.ts +3 -3
  88. package/umd/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +4 -2
  89. package/umd/typings/execution/plugins/llm-execution-tools/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  90. package/umd/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -2
  91. package/umd/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +2 -1
  92. package/umd/typings/execution/plugins/llm-execution-tools/mocked/MockedEchoLlmExecutionTools.d.ts +4 -2
  93. package/umd/typings/execution/plugins/llm-execution-tools/mocked/MockedFackedLlmExecutionTools.d.ts +4 -2
  94. package/umd/typings/execution/plugins/llm-execution-tools/mocked/fakeTextToExpectations.d.ts +1 -1
  95. package/umd/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools.d.ts +4 -2
  96. package/umd/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionToolsOptions.d.ts +2 -1
  97. package/umd/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +4 -2
  98. package/umd/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
  99. package/umd/typings/execution/plugins/llm-execution-tools/openai/openai-models.d.ts +1 -1
  100. package/umd/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +4 -2
  101. package/umd/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionToolsOptions.d.ts +2 -1
  102. package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Progress.d.ts +1 -1
  103. package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Response.d.ts +1 -1
  104. package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +2 -1
  105. package/umd/typings/execution/plugins/llm-execution-tools/remote/startRemoteServer.d.ts +1 -1
  106. package/umd/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +3 -2
  107. package/umd/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +3 -2
  108. package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +3 -2
  109. package/umd/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -2
  110. package/umd/typings/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +1 -1
  111. package/umd/typings/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +1 -1
  112. package/umd/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +2 -2
  113. package/umd/typings/execution/translation/automatic-translate/translateMessages.d.ts +2 -2
  114. package/umd/typings/execution/utils/replaceParameters.d.ts +2 -2
  115. package/umd/typings/library/SimplePromptbookLibrary.d.ts +1 -1
  116. package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +2 -2
  117. package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +2 -2
  118. package/umd/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +2 -1
  119. package/umd/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +2 -2
  120. package/umd/typings/library/constructors/createPromptbookSublibrary.d.ts +1 -1
  121. package/umd/typings/types/Command.d.ts +5 -2
  122. package/umd/typings/types/Prompt.d.ts +4 -1
  123. package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +8 -1
  124. package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +2 -1
  125. package/umd/typings/types/TaskProgress.d.ts +2 -1
  126. package/umd/typings/types/execution-report/ExecutionReportJson.d.ts +2 -1
  127. package/umd/typings/types/execution-report/countWorkingDuration.d.ts +1 -1
  128. package/umd/typings/utils/emojis.d.ts +1 -1
  129. package/umd/typings/utils/expectation-counters/index.d.ts +2 -1
  130. package/umd/typings/utils/extractParameters.d.ts +2 -1
  131. package/umd/typings/utils/markdown/addAutoGeneratedSection.d.ts +2 -1
  132. package/umd/typings/utils/markdown/createMarkdownChart.d.ts +2 -2
  133. package/umd/typings/utils/markdown/createMarkdownTable.d.ts +2 -1
  134. package/umd/typings/utils/markdown/escapeMarkdownBlock.d.ts +1 -1
  135. package/umd/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +2 -1
  136. package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
  137. package/umd/typings/utils/markdown/removeContentComments.d.ts +2 -1
  138. package/umd/typings/utils/markdown/removeMarkdownFormatting.d.ts +1 -1
  139. package/umd/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +1 -1
  140. package/umd/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +1 -1
  141. package/umd/typings/utils/normalization/isValidKeyword.d.ts +1 -1
  142. package/umd/typings/utils/normalization/parseKeywords.d.ts +1 -1
  143. package/umd/typings/utils/normalization/parseKeywordsFromString.d.ts +1 -1
  144. package/umd/typings/utils/normalization/searchKeywords.d.ts +1 -1
  145. package/umd/typings/utils/postprocessing/extractBlock.d.ts +1 -1
package/esm/index.es.js CHANGED
@@ -448,7 +448,7 @@ function union() {
448
448
  /**
449
449
  * The version of the Promptbook library
450
450
  */
451
- var PROMPTBOOK_VERSION = '0.52.0-33';
451
+ var PROMPTBOOK_VERSION = '0.53.0';
452
452
 
453
453
  /**
454
454
  * Parses the template and returns the list of all parameter names
@@ -570,88 +570,108 @@ function extractParametersFromPromptTemplate(promptTemplate) {
570
570
  * TODO: [🔣] If script require contentLanguage
571
571
  */
572
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
+ }
573
633
  /**
574
- * 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
575
639
  *
576
- * @param text with emojis
577
- * @returns text without emojis
640
+ * @see https://github.com/webgptorg/promptbook#execution-type
578
641
  */
579
- function removeEmojis(text) {
580
- // Replace emojis (and also ZWJ sequence) with hyphens
581
- text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
582
- text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
583
- text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
584
- text = text.replace(/\p{Extended_Pictographic}/gu, '');
585
- return text;
586
- }
642
+ var ExecutionTypes = [
643
+ 'PROMPT_TEMPLATE',
644
+ 'SIMPLE_TEMPLATE',
645
+ 'SCRIPT',
646
+ 'PROMPT_DIALOG',
647
+ // <- [🥻] Insert here when making new command
648
+ ];
587
649
 
588
650
  /**
589
- * 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
590
658
  */
591
- function titleToName(value) {
592
- value = removeEmojis(value);
593
- value = normalizeToKebabCase(value);
594
- // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
595
- return value;
596
- }
597
659
 
598
660
  /**
599
- * Creates a Mermaid graph based on the promptbook
661
+ * Removes Markdown formatting tags from a string.
600
662
  *
601
- * 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.
602
665
  */
603
- function renderPromptbookMermaid(promptbookJson, options) {
604
- var _a = (options || {}).linkPromptTemplate, linkPromptTemplate = _a === void 0 ? function () { return null; } : _a;
605
- var parameterNameToTemplateName = function (parameterName) {
606
- var parameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
607
- if (!parameter) {
608
- throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
609
- }
610
- if (parameter.isInput) {
611
- return 'input';
612
- }
613
- var template = promptbookJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
614
- if (!template) {
615
- throw new Error("Could not find template for {".concat(parameterName, "}"));
616
- }
617
- return normalizeTo_camelCase('template-' + titleToName(template.title));
618
- };
619
- var promptbookMermaid = spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(promptbookJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson.promptTemplates
620
- .flatMap(function (_a) {
621
- var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
622
- return __spreadArray([
623
- "".concat(parameterNameToTemplateName(resultingParameterName), "(\"").concat(title, "\")")
624
- ], __read(dependentParameterNames.map(function (dependentParameterName) {
625
- return "".concat(parameterNameToTemplateName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName(resultingParameterName));
626
- })), false);
627
- })
628
- .join('\n')), "\n\n ").concat(block(promptbookJson.parameters
629
- .filter(function (_a) {
630
- var isOutput = _a.isOutput;
631
- return isOutput;
632
- })
633
- .map(function (_a) {
634
- var name = _a.name;
635
- return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
636
- })
637
- .join('\n')), "\n output((Output)):::output\n\n ").concat(block(promptbookJson.promptTemplates
638
- .map(function (promptTemplate) {
639
- var link = linkPromptTemplate(promptTemplate);
640
- if (link === null) {
641
- return '';
642
- }
643
- var href = link.href, title = link.title;
644
- var templateName = parameterNameToTemplateName(promptTemplate.resultingParameterName);
645
- return "click ".concat(templateName, " href \"").concat(href, "\" \"").concat(title, "\";");
646
- })
647
- .filter(function (line) { return line !== ''; })
648
- .join('\n')), "\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
649
- return promptbookMermaid;
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;
650
674
  }
651
- /**
652
- * TODO: Maybe use some Mermaid library instead of string templating
653
- * TODO: [🕌] When more than 2 functionalities, split into separate functions
654
- */
655
675
 
656
676
  /**
657
677
  * Function parseNumber will parse number from string
@@ -721,897 +741,581 @@ function parseNumber(value) {
721
741
  */
722
742
 
723
743
  /**
724
- * This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
725
- */
726
- var PromptbookLogicError = /** @class */ (function (_super) {
727
- __extends(PromptbookLogicError, _super);
728
- function PromptbookLogicError(message) {
729
- var _this = _super.call(this, message) || this;
730
- _this.name = 'PromptbookLogicError';
731
- Object.setPrototypeOf(_this, PromptbookLogicError.prototype);
732
- return _this;
733
- }
734
- return PromptbookLogicError;
735
- }(Error));
736
-
737
- /**
738
- * This error occurs during the parameter replacement in the template
739
- *
740
- * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
741
- */
742
- var TemplateError = /** @class */ (function (_super) {
743
- __extends(TemplateError, _super);
744
- function TemplateError(message) {
745
- var _this = _super.call(this, message) || this;
746
- _this.name = 'TemplateError';
747
- Object.setPrototypeOf(_this, TemplateError.prototype);
748
- return _this;
749
- }
750
- return TemplateError;
751
- }(Error));
752
-
753
- /**
754
- * Replaces parameters in template with values from parameters object
744
+ * Parses one line of ul/ol to command
755
745
  *
756
- * @param template the template with parameters in {curly} braces
757
- * @param parameters the object with parameters
758
- * @returns the template with replaced parameters
759
- * @throws {TemplateError} if parameter is not defined, not closed, or not opened
746
+ * @returns parsed command object
747
+ * @throws {PromptbookSyntaxError} if the command is invalid
760
748
  *
761
- * @private within the createPromptbookExecutor
749
+ * @private within the promptbookStringToJson
762
750
  */
763
- function replaceParameters(template, parameters) {
764
- var replacedTemplate = template;
765
- var match;
766
- var loopLimit = LOOP_LIMIT;
767
- var _loop_1 = function () {
768
- if (loopLimit-- < 0) {
769
- throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
770
- }
771
- var precol = match.groups.precol;
772
- var parameterName = match.groups.parameterName;
773
- if (parameterName === '') {
774
- return "continue";
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 ")));
775
782
  }
776
- if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
777
- 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 ")));
778
787
  }
779
- if (parameters[parameterName] === undefined) {
780
- 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 ")));
781
790
  }
782
- var parameterValue = parameters[parameterName];
783
- if (parameterValue === undefined) {
784
- throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
785
- }
786
- parameterValue = parameterValue.toString();
787
- if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
788
- parameterValue = parameterValue
789
- .split('\n')
790
- .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
791
- .join('\n');
792
- }
793
- replacedTemplate =
794
- replacedTemplate.substring(0, match.index + precol.length) +
795
- parameterValue +
796
- replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
797
- };
798
- while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
799
- .exec(replacedTemplate))) {
800
- _loop_1();
801
- }
802
- // [💫] Check if there are parameters that are not closed properly
803
- if (/{\w+$/.test(replacedTemplate)) {
804
- throw new TemplateError('Parameter is not closed');
805
- }
806
- // [💫] Check if there are parameters that are not opened properly
807
- if (/^\w+}/.test(replacedTemplate)) {
808
- throw new TemplateError('Parameter is not opened');
809
- }
810
- return replacedTemplate;
811
- }
812
-
813
- /**
814
- * Counts number of characters in the text
815
- */
816
- function countCharacters(text) {
817
- // Remove null characters
818
- text = text.replace(/\0/g, '');
819
- // Replace emojis (and also ZWJ sequence) with hyphens
820
- text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
821
- text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
822
- text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
823
- return text.length;
824
- }
825
-
826
- /**
827
- * Counts number of lines in the text
828
- */
829
- function countLines(text) {
830
- if (text === '') {
831
- return 0;
832
- }
833
- return text.split('\n').length;
834
- }
835
-
836
- /**
837
- * Counts number of pages in the text
838
- */
839
- function countPages(text) {
840
- var sentencesPerPage = 5; // Assuming each page has 5 sentences
841
- var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
842
- var pageCount = Math.ceil(sentences.length / sentencesPerPage);
843
- return pageCount;
844
- }
845
-
846
- /**
847
- * Counts number of paragraphs in the text
848
- */
849
- function countParagraphs(text) {
850
- return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
851
- }
852
-
853
- /**
854
- * Split text into sentences
855
- */
856
- function splitIntoSentences(text) {
857
- return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
858
- }
859
- /**
860
- * Counts number of sentences in the text
861
- */
862
- function countSentences(text) {
863
- return splitIntoSentences(text).length;
864
- }
865
-
866
- var defaultDiacriticsRemovalMap = [
867
- {
868
- base: 'A',
869
- letters: '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F',
870
- },
871
- { base: 'AA', letters: '\uA732' },
872
- { base: 'AE', letters: '\u00C6\u01FC\u01E2' },
873
- { base: 'AO', letters: '\uA734' },
874
- { base: 'AU', letters: '\uA736' },
875
- { base: 'AV', letters: '\uA738\uA73A' },
876
- { base: 'AY', letters: '\uA73C' },
877
- {
878
- base: 'B',
879
- letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
880
- },
881
- {
882
- base: 'C',
883
- letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
884
- },
885
- {
886
- base: 'D',
887
- letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
888
- },
889
- { base: 'DZ', letters: '\u01F1\u01C4' },
890
- { base: 'Dz', letters: '\u01F2\u01C5' },
891
- {
892
- base: 'E',
893
- letters: '\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E',
894
- },
895
- { base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
896
- {
897
- base: 'G',
898
- letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
899
- },
900
- {
901
- base: 'H',
902
- letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
903
- },
904
- {
905
- base: 'I',
906
- letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
907
- },
908
- { base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
909
- {
910
- base: 'K',
911
- letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
912
- },
913
- {
914
- base: 'L',
915
- letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
916
- },
917
- { base: 'LJ', letters: '\u01C7' },
918
- { base: 'Lj', letters: '\u01C8' },
919
- { base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
920
- {
921
- base: 'N',
922
- letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
923
- },
924
- { base: 'NJ', letters: '\u01CA' },
925
- { base: 'Nj', letters: '\u01CB' },
926
- {
927
- base: 'O',
928
- letters: '\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C',
929
- },
930
- { base: 'OI', letters: '\u01A2' },
931
- { base: 'OO', letters: '\uA74E' },
932
- { base: 'OU', letters: '\u0222' },
933
- { base: 'OE', letters: '\u008C\u0152' },
934
- { base: 'oe', letters: '\u009C\u0153' },
935
- {
936
- base: 'P',
937
- letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
938
- },
939
- { base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
940
- {
941
- base: 'R',
942
- letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
943
- },
944
- {
945
- base: 'S',
946
- letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
947
- },
948
- {
949
- base: 'T',
950
- letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
951
- },
952
- { base: 'TZ', letters: '\uA728' },
953
- {
954
- base: 'U',
955
- letters: '\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244',
956
- },
957
- { base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
958
- { base: 'VY', letters: '\uA760' },
959
- {
960
- base: 'W',
961
- letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
962
- },
963
- { base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
964
- {
965
- base: 'Y',
966
- letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
967
- },
968
- {
969
- base: 'Z',
970
- letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
971
- },
972
- {
973
- base: 'a',
974
- letters: '\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250',
975
- },
976
- { base: 'aa', letters: '\uA733' },
977
- { base: 'ae', letters: '\u00E6\u01FD\u01E3' },
978
- { base: 'ao', letters: '\uA735' },
979
- { base: 'au', letters: '\uA737' },
980
- { base: 'av', letters: '\uA739\uA73B' },
981
- { base: 'ay', letters: '\uA73D' },
982
- {
983
- base: 'b',
984
- letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
985
- },
986
- {
987
- base: 'c',
988
- letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
989
- },
990
- {
991
- base: 'd',
992
- letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
993
- },
994
- { base: 'dz', letters: '\u01F3\u01C6' },
995
- {
996
- base: 'e',
997
- letters: '\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD',
998
- },
999
- { base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
1000
- {
1001
- base: 'g',
1002
- letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
1003
- },
1004
- {
1005
- base: 'h',
1006
- letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
1007
- },
1008
- { base: 'hv', letters: '\u0195' },
1009
- {
1010
- base: 'i',
1011
- letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
1012
- },
1013
- { base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
1014
- {
1015
- base: 'k',
1016
- letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
1017
- },
1018
- {
1019
- base: 'l',
1020
- letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
1021
- },
1022
- { base: 'lj', letters: '\u01C9' },
1023
- { base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
1024
- {
1025
- base: 'n',
1026
- letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
1027
- },
1028
- { base: 'nj', letters: '\u01CC' },
1029
- {
1030
- base: 'o',
1031
- letters: '\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275',
1032
- },
1033
- { base: 'oi', letters: '\u01A3' },
1034
- { base: 'ou', letters: '\u0223' },
1035
- { base: 'oo', letters: '\uA74F' },
1036
- {
1037
- base: 'p',
1038
- letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
1039
- },
1040
- { base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
1041
- {
1042
- base: 'r',
1043
- letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
1044
- },
1045
- {
1046
- base: 's',
1047
- letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
1048
- },
1049
- {
1050
- base: 't',
1051
- letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
1052
- },
1053
- { base: 'tz', letters: '\uA729' },
1054
- {
1055
- base: 'u',
1056
- letters: '\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289',
1057
- },
1058
- { base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
1059
- { base: 'vy', letters: '\uA761' },
1060
- {
1061
- base: 'w',
1062
- letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
1063
- },
1064
- { base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
1065
- {
1066
- base: 'y',
1067
- letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
1068
- },
1069
- {
1070
- base: 'z',
1071
- letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
1072
- },
1073
- ];
1074
- /**
1075
- * Map of letters from diacritic variant to diacritless variant
1076
- * Contains lowercase and uppercase separatelly
1077
- *
1078
- * > "á" => "a"
1079
- * > "ě" => "e"
1080
- * > "Ă" => "A"
1081
- * > ...
1082
- */
1083
- var DIACRITIC_VARIANTS_LETTERS = {};
1084
- // tslint:disable-next-line: prefer-for-of
1085
- for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
1086
- var letters = defaultDiacriticsRemovalMap[i].letters;
1087
- // tslint:disable-next-line: prefer-for-of
1088
- for (var j = 0; j < letters.length; j++) {
1089
- DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
1090
- }
1091
- }
1092
- // <- TODO: [🍓] Put to maker function to save execution time if not needed
1093
- /*
1094
- @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
1095
- Licensed under the Apache License, Version 2.0 (the "License");
1096
- you may not use this file except in compliance with the License.
1097
- You may obtain a copy of the License at
1098
-
1099
- http://www.apache.org/licenses/LICENSE-2.0
1100
-
1101
- Unless required by applicable law or agreed to in writing, software
1102
- distributed under the License is distributed on an "AS IS" BASIS,
1103
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1104
- See the License for the specific language governing permissions and
1105
- limitations under the License.
1106
- */
1107
-
1108
- /**
1109
- *
1110
- */
1111
- function removeDiacritics(input) {
1112
- /*eslint no-control-regex: "off"*/
1113
- return input.replace(/[^\u0000-\u007E]/g, function (a) {
1114
- return DIACRITIC_VARIANTS_LETTERS[a] || a;
1115
- });
1116
- }
1117
-
1118
- /**
1119
- * Counts number of words in the text
1120
- */
1121
- function countWords(text) {
1122
- text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
1123
- text = removeDiacritics(text);
1124
- return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
1125
- }
1126
-
1127
- /**
1128
- * Index of all counter functions
1129
- */
1130
- var CountUtils = {
1131
- CHARACTERS: countCharacters,
1132
- WORDS: countWords,
1133
- SENTENCES: countSentences,
1134
- PARAGRAPHS: countParagraphs,
1135
- LINES: countLines,
1136
- PAGES: countPages,
1137
- };
1138
-
1139
- /**
1140
- * Function isValidJsonString will tell you if the string is valid JSON or not
1141
- */
1142
- function isValidJsonString(value) {
1143
- try {
1144
- JSON.parse(value);
1145
- return true;
1146
- }
1147
- catch (error) {
1148
- if (!(error instanceof Error)) {
1149
- throw error;
1150
- }
1151
- if (error.message.includes('Unexpected token')) {
1152
- return false;
1153
- }
1154
- return false;
1155
- }
1156
- }
1157
-
1158
- /**
1159
- * Removes Markdown formatting tags from a string.
1160
- *
1161
- * @param {string} str - The string to remove Markdown tags from.
1162
- * @returns {string} The input string with all Markdown tags removed.
1163
- */
1164
- function removeMarkdownFormatting(str) {
1165
- // Remove bold formatting
1166
- str = str.replace(/\*\*(.*?)\*\*/g, '$1');
1167
- // Remove italic formatting
1168
- str = str.replace(/\*(.*?)\*/g, '$1');
1169
- // Remove code formatting
1170
- str = str.replace(/`(.*?)`/g, '$1');
1171
- return str;
1172
- }
1173
-
1174
- /* tslint:disable */
1175
- /*
1176
- TODO: Tests
1177
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
1178
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
1179
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
1180
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
1181
- */
1182
- function normalizeTo_SCREAMING_CASE(sentence) {
1183
- var e_1, _a;
1184
- var charType;
1185
- var lastCharType = 'OTHER';
1186
- var normalizedName = '';
1187
- try {
1188
- for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1189
- var char = sentence_1_1.value;
1190
- var normalizedChar = void 0;
1191
- if (/^[a-z]$/.test(char)) {
1192
- charType = 'LOWERCASE';
1193
- normalizedChar = char.toUpperCase();
1194
- }
1195
- else if (/^[A-Z]$/.test(char)) {
1196
- charType = 'UPPERCASE';
1197
- normalizedChar = char;
1198
- }
1199
- else if (/^[0-9]$/.test(char)) {
1200
- charType = 'NUMBER';
1201
- normalizedChar = char;
1202
- }
1203
- else if (/^\/$/.test(char)) {
1204
- charType = 'SLASH';
1205
- normalizedChar = char;
1206
- }
1207
- else {
1208
- charType = 'OTHER';
1209
- normalizedChar = '_';
1210
- }
1211
- if (charType !== lastCharType &&
1212
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1213
- !(lastCharType === 'NUMBER') &&
1214
- !(charType === 'NUMBER')) {
1215
- normalizedName += '_';
1216
- }
1217
- normalizedName += normalizedChar;
1218
- lastCharType = charType;
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 ")));
1219
799
  }
800
+ var promptbookVersion = listItemParts.pop();
801
+ // TODO: Validate version
802
+ return {
803
+ type: 'PROMPTBOOK_VERSION',
804
+ promptbookVersion: promptbookVersion,
805
+ };
1220
806
  }
1221
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1222
- finally {
1223
- try {
1224
- if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
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 "); }));
1225
814
  }
1226
- finally { if (e_1) throw e_1.error; }
815
+ return {
816
+ type: 'EXECUTE',
817
+ executionType: executionTypes[0],
818
+ };
1227
819
  }
1228
- normalizedName = normalizedName.replace(/_+/g, '_');
1229
- normalizedName = normalizedName.replace(/_?\/_?/g, '/');
1230
- normalizedName = normalizedName.replace(/^_/, '');
1231
- normalizedName = normalizedName.replace(/_$/, '');
1232
- return normalizedName;
1233
- }
1234
- /**
1235
- * TODO: [🌺] Use some intermediate util splitWords
1236
- */
1237
-
1238
- /* tslint:disable */
1239
- function normalizeToKebabCase(sentence) {
1240
- var e_1, _a;
1241
- sentence = removeDiacritics(sentence);
1242
- var charType;
1243
- var lastCharType = 'OTHER';
1244
- var normalizedName = '';
1245
- try {
1246
- for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1247
- var char = sentence_1_1.value;
1248
- var normalizedChar = void 0;
1249
- if (/^[a-z]$/.test(char)) {
1250
- charType = 'LOWERCASE';
1251
- normalizedChar = char;
1252
- }
1253
- else if (/^[A-Z]$/.test(char)) {
1254
- charType = 'UPPERCASE';
1255
- normalizedChar = char.toLowerCase();
1256
- }
1257
- else if (/^[0-9]$/.test(char)) {
1258
- charType = 'NUMBER';
1259
- normalizedChar = char;
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
+ };
1260
829
  }
1261
- else if (/^\/$/.test(char)) {
1262
- charType = 'SLASH';
1263
- normalizedChar = char;
830
+ else if (type === 'MODEL_VARIANT_COMPLETION') {
831
+ return {
832
+ type: 'MODEL',
833
+ key: 'modelVariant',
834
+ value: 'COMPLETION',
835
+ };
1264
836
  }
1265
837
  else {
1266
- charType = 'OTHER';
1267
- normalizedChar = '-';
1268
- }
1269
- if (charType !== lastCharType &&
1270
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1271
- !(lastCharType === 'NUMBER') &&
1272
- !(charType === 'NUMBER')) {
1273
- normalizedName += '-';
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 "); }));
1274
839
  }
1275
- normalizedName += normalizedChar;
1276
- lastCharType = charType;
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 "); }));
1277
850
  }
1278
851
  }
1279
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1280
- finally {
1281
- try {
1282
- if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
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 ")));
1283
860
  }
1284
- finally { if (e_1) throw e_1.error; }
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
+ };
1285
879
  }
1286
- normalizedName = normalizedName.split(/-+/g).join('-');
1287
- normalizedName = normalizedName.split(/-?\/-?/g).join('/');
1288
- normalizedName = normalizedName.replace(/^-/, '');
1289
- normalizedName = normalizedName.replace(/-$/, '');
1290
- return normalizedName;
1291
- }
1292
-
1293
- /* tslint:disable */
1294
- function normalizeTo_camelCase(sentence, __firstLetterCapital) {
1295
- var e_1, _a;
1296
- if (__firstLetterCapital === void 0) { __firstLetterCapital = false; }
1297
- var charType;
1298
- var lastCharType = null;
1299
- var normalizedName = '';
1300
- try {
1301
- for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1302
- var char = sentence_1_1.value;
1303
- var normalizedChar = void 0;
1304
- if (/^[a-z]$/.test(char)) {
1305
- charType = 'LOWERCASE';
1306
- normalizedChar = char;
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';
1307
919
  }
1308
- else if (/^[A-Z]$/.test(char)) {
1309
- charType = 'UPPERCASE';
1310
- normalizedChar = char.toLowerCase();
920
+ else if (/^min/i.test(signRaw)) {
921
+ sign = 'MINIMUM';
1311
922
  }
1312
- else if (/^[0-9]$/.test(char)) {
1313
- charType = 'NUMBER';
1314
- normalizedChar = char;
923
+ else if (/^max/i.test(signRaw)) {
924
+ sign = 'MAXIMUM';
1315
925
  }
1316
926
  else {
1317
- charType = 'OTHER';
1318
- normalizedChar = '';
927
+ throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
1319
928
  }
1320
- if (!lastCharType) {
1321
- if (__firstLetterCapital) {
1322
- normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
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
+ }
1323
954
  }
1324
955
  }
1325
- else if (charType !== lastCharType &&
1326
- !(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
1327
- !(lastCharType === 'NUMBER') &&
1328
- !(charType === 'NUMBER')) {
1329
- normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
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;
1330
976
  }
1331
- normalizedName += normalizedChar;
1332
- lastCharType = charType;
977
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
1333
978
  }
979
+ /*
980
+ } else if (type.startsWith('__________________')) {
981
+ // <- [🥻] Insert here when making new command
982
+ */
1334
983
  }
1335
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1336
- finally {
1337
- try {
1338
- if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
1339
- }
1340
- finally { if (e_1) throw e_1.error; }
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 ")));
1341
986
  }
1342
- return normalizedName;
1343
987
  }
1344
- /**
1345
- * TODO: [🌺] Use some intermediate util splitWords
1346
- */
1347
988
 
989
+ var defaultDiacriticsRemovalMap = [
990
+ {
991
+ base: 'A',
992
+ letters: '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F',
993
+ },
994
+ { base: 'AA', letters: '\uA732' },
995
+ { base: 'AE', letters: '\u00C6\u01FC\u01E2' },
996
+ { base: 'AO', letters: '\uA734' },
997
+ { base: 'AU', letters: '\uA736' },
998
+ { base: 'AV', letters: '\uA738\uA73A' },
999
+ { base: 'AY', letters: '\uA73C' },
1000
+ {
1001
+ base: 'B',
1002
+ letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
1003
+ },
1004
+ {
1005
+ base: 'C',
1006
+ letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
1007
+ },
1008
+ {
1009
+ base: 'D',
1010
+ letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
1011
+ },
1012
+ { base: 'DZ', letters: '\u01F1\u01C4' },
1013
+ { base: 'Dz', letters: '\u01F2\u01C5' },
1014
+ {
1015
+ base: 'E',
1016
+ letters: '\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E',
1017
+ },
1018
+ { base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
1019
+ {
1020
+ base: 'G',
1021
+ letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
1022
+ },
1023
+ {
1024
+ base: 'H',
1025
+ letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
1026
+ },
1027
+ {
1028
+ base: 'I',
1029
+ letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
1030
+ },
1031
+ { base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
1032
+ {
1033
+ base: 'K',
1034
+ letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
1035
+ },
1036
+ {
1037
+ base: 'L',
1038
+ letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
1039
+ },
1040
+ { base: 'LJ', letters: '\u01C7' },
1041
+ { base: 'Lj', letters: '\u01C8' },
1042
+ { base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
1043
+ {
1044
+ base: 'N',
1045
+ letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
1046
+ },
1047
+ { base: 'NJ', letters: '\u01CA' },
1048
+ { base: 'Nj', letters: '\u01CB' },
1049
+ {
1050
+ base: 'O',
1051
+ letters: '\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C',
1052
+ },
1053
+ { base: 'OI', letters: '\u01A2' },
1054
+ { base: 'OO', letters: '\uA74E' },
1055
+ { base: 'OU', letters: '\u0222' },
1056
+ { base: 'OE', letters: '\u008C\u0152' },
1057
+ { base: 'oe', letters: '\u009C\u0153' },
1058
+ {
1059
+ base: 'P',
1060
+ letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
1061
+ },
1062
+ { base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
1063
+ {
1064
+ base: 'R',
1065
+ letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
1066
+ },
1067
+ {
1068
+ base: 'S',
1069
+ letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
1070
+ },
1071
+ {
1072
+ base: 'T',
1073
+ letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
1074
+ },
1075
+ { base: 'TZ', letters: '\uA728' },
1076
+ {
1077
+ base: 'U',
1078
+ letters: '\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244',
1079
+ },
1080
+ { base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
1081
+ { base: 'VY', letters: '\uA760' },
1082
+ {
1083
+ base: 'W',
1084
+ letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
1085
+ },
1086
+ { base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
1087
+ {
1088
+ base: 'Y',
1089
+ letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
1090
+ },
1091
+ {
1092
+ base: 'Z',
1093
+ letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
1094
+ },
1095
+ {
1096
+ base: 'a',
1097
+ letters: '\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250',
1098
+ },
1099
+ { base: 'aa', letters: '\uA733' },
1100
+ { base: 'ae', letters: '\u00E6\u01FD\u01E3' },
1101
+ { base: 'ao', letters: '\uA735' },
1102
+ { base: 'au', letters: '\uA737' },
1103
+ { base: 'av', letters: '\uA739\uA73B' },
1104
+ { base: 'ay', letters: '\uA73D' },
1105
+ {
1106
+ base: 'b',
1107
+ letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
1108
+ },
1109
+ {
1110
+ base: 'c',
1111
+ letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
1112
+ },
1113
+ {
1114
+ base: 'd',
1115
+ letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
1116
+ },
1117
+ { base: 'dz', letters: '\u01F3\u01C6' },
1118
+ {
1119
+ base: 'e',
1120
+ letters: '\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD',
1121
+ },
1122
+ { base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
1123
+ {
1124
+ base: 'g',
1125
+ letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
1126
+ },
1127
+ {
1128
+ base: 'h',
1129
+ letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
1130
+ },
1131
+ { base: 'hv', letters: '\u0195' },
1132
+ {
1133
+ base: 'i',
1134
+ letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
1135
+ },
1136
+ { base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
1137
+ {
1138
+ base: 'k',
1139
+ letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
1140
+ },
1141
+ {
1142
+ base: 'l',
1143
+ letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
1144
+ },
1145
+ { base: 'lj', letters: '\u01C9' },
1146
+ { base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
1147
+ {
1148
+ base: 'n',
1149
+ letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
1150
+ },
1151
+ { base: 'nj', letters: '\u01CC' },
1152
+ {
1153
+ base: 'o',
1154
+ letters: '\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275',
1155
+ },
1156
+ { base: 'oi', letters: '\u01A3' },
1157
+ { base: 'ou', letters: '\u0223' },
1158
+ { base: 'oo', letters: '\uA74F' },
1159
+ {
1160
+ base: 'p',
1161
+ letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
1162
+ },
1163
+ { base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
1164
+ {
1165
+ base: 'r',
1166
+ letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
1167
+ },
1168
+ {
1169
+ base: 's',
1170
+ letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
1171
+ },
1172
+ {
1173
+ base: 't',
1174
+ letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
1175
+ },
1176
+ { base: 'tz', letters: '\uA729' },
1177
+ {
1178
+ base: 'u',
1179
+ letters: '\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289',
1180
+ },
1181
+ { base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
1182
+ { base: 'vy', letters: '\uA761' },
1183
+ {
1184
+ base: 'w',
1185
+ letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
1186
+ },
1187
+ { base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
1188
+ {
1189
+ base: 'y',
1190
+ letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
1191
+ },
1192
+ {
1193
+ base: 'z',
1194
+ letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
1195
+ },
1196
+ ];
1348
1197
  /**
1349
- * Execution type describes the way how the block is executed
1198
+ * Map of letters from diacritic variant to diacritless variant
1199
+ * Contains lowercase and uppercase separatelly
1350
1200
  *
1351
- * @see https://github.com/webgptorg/promptbook#execution-type
1201
+ * > "á" => "a"
1202
+ * > "ě" => "e"
1203
+ * > "Ă" => "A"
1204
+ * > ...
1352
1205
  */
1353
- var ExecutionTypes = [
1354
- 'PROMPT_TEMPLATE',
1355
- 'SIMPLE_TEMPLATE',
1356
- 'SCRIPT',
1357
- 'PROMPT_DIALOG',
1358
- // <- [🥻] Insert here when making new command
1359
- ];
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;
1213
+ }
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
1360
1221
 
1361
- /**
1362
- * Units of text measurement
1363
- */
1364
- var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
1365
- /**
1366
- * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
1367
- * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
1368
- * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
1369
- */
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
+ */
1370
1230
 
1371
1231
  /**
1372
- * Parses one line of ul/ol to command
1373
- *
1374
- * @returns parsed command object
1375
- * @throws {PromptbookSyntaxError} if the command is invalid
1376
1232
  *
1377
- * @private within the promptbookStringToJson
1378
1233
  */
1379
- function parseCommand(listItem) {
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) {
1380
1243
  var e_1, _a;
1381
- if (listItem.includes('\n') || listItem.includes('\r')) {
1382
- throw new PromptbookSyntaxError('Command can not contain new line characters:');
1383
- }
1384
- var type = listItem.trim();
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 = type.split(')').join('');
1393
- type = normalizeTo_SCREAMING_CASE(type);
1394
- type = type.split('DIALOGUE').join('DIALOG');
1395
- var listItemParts = listItem
1396
- .split(' ')
1397
- .map(function (part) { return part.trim(); })
1398
- .filter(function (item) { return item !== ''; })
1399
- .filter(function (item) { return !/^PTBK$/i.test(item); })
1400
- .filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
1401
- .map(removeMarkdownFormatting);
1402
- if (type.startsWith('URL') ||
1403
- type.startsWith('PTBK_URL') ||
1404
- type.startsWith('PTBKURL') ||
1405
- type.startsWith('PROMPTBOOK_URL') ||
1406
- type.startsWith('PROMPTBOOKURL') ||
1407
- type.startsWith('HTTPS')) {
1408
- if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
1409
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
1410
- }
1411
- var promptbookUrlString = listItemParts.pop();
1412
- var promptbookUrl = new URL(promptbookUrlString);
1413
- if (promptbookUrl.protocol !== 'https:') {
1414
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
1415
- }
1416
- if (promptbookUrl.hash !== '') {
1417
- 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 ")));
1418
- }
1419
- return {
1420
- type: 'PROMPTBOOK_URL',
1421
- promptbookUrl: promptbookUrl,
1422
- };
1423
- }
1424
- else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
1425
- if (listItemParts.length !== 2) {
1426
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
1427
- }
1428
- var promptbookVersion = listItemParts.pop();
1429
- // TODO: Validate version
1430
- return {
1431
- type: 'PROMPTBOOK_VERSION',
1432
- promptbookVersion: promptbookVersion,
1433
- };
1434
- }
1435
- else if (type.startsWith('EXECUTE') ||
1436
- type.startsWith('EXEC') ||
1437
- type.startsWith('PROMPT_DIALOG') ||
1438
- type.startsWith('SIMPLE_TEMPLATE')) {
1439
- var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
1440
- if (executionTypes.length !== 1) {
1441
- 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 "); }));
1442
- }
1443
- return {
1444
- type: 'EXECUTE',
1445
- executionType: executionTypes[0],
1446
- };
1447
- }
1448
- else if (type.startsWith('MODEL')) {
1449
- // TODO: Make this more elegant and dynamically
1450
- if (type.startsWith('MODEL_VARIANT')) {
1451
- if (type === 'MODEL_VARIANT_CHAT') {
1452
- return {
1453
- type: 'MODEL',
1454
- key: 'modelVariant',
1455
- value: 'CHAT',
1456
- };
1457
- }
1458
- else if (type === 'MODEL_VARIANT_COMPLETION') {
1459
- return {
1460
- type: 'MODEL',
1461
- key: 'modelVariant',
1462
- value: 'COMPLETION',
1463
- };
1464
- }
1465
- else {
1466
- 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 "); }));
1467
- }
1468
- }
1469
- if (type.startsWith('MODEL_NAME')) {
1470
- return {
1471
- type: 'MODEL',
1472
- key: 'modelName',
1473
- value: listItemParts.pop(),
1474
- };
1475
- }
1476
- else {
1477
- 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 "); }));
1478
- }
1479
- }
1480
- else if (type.startsWith('PARAM') ||
1481
- type.startsWith('INPUT_PARAM') ||
1482
- type.startsWith('OUTPUT_PARAM') ||
1483
- listItem.startsWith('{') ||
1484
- listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
1485
- var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
1486
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
1487
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1488
- }
1489
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1490
- var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
1491
- if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
1492
- throw new PromptbookSyntaxError(spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
1493
- }
1494
- var isInput = type.startsWith('INPUT');
1495
- var isOutput = type.startsWith('OUTPUT');
1496
- if (listItem.startsWith('> {')) {
1497
- isInput = false;
1498
- isOutput = false;
1499
- }
1500
- return {
1501
- type: 'PARAMETER',
1502
- parameterName: parameterName,
1503
- parameterDescription: parameterDescription.trim() || null,
1504
- isInput: isInput,
1505
- isOutput: isOutput,
1506
- };
1507
- }
1508
- else if (type.startsWith('JOKER')) {
1509
- if (listItemParts.length !== 2) {
1510
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
1511
- }
1512
- var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
1513
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
1514
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1515
- }
1516
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1517
- var parameterName = parametersMatch.groups.parameterName;
1518
- return {
1519
- type: 'JOKER',
1520
- parameterName: parameterName,
1521
- };
1522
- }
1523
- else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
1524
- if (listItemParts.length !== 2) {
1525
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
1526
- }
1527
- var functionName = listItemParts.pop();
1528
- return {
1529
- type: 'POSTPROCESS',
1530
- functionName: functionName,
1531
- };
1532
- }
1533
- else if (type.startsWith('EXPECT_JSON')) {
1534
- return {
1535
- type: 'EXPECT_FORMAT',
1536
- format: 'JSON',
1537
- };
1538
- // [🥤]
1539
- }
1540
- else if (type.startsWith('EXPECT')) {
1541
- try {
1542
- listItemParts.shift();
1543
- var sign = void 0;
1544
- var signRaw = listItemParts.shift();
1545
- if (/^exact/i.test(signRaw)) {
1546
- sign = 'EXACTLY';
1547
- }
1548
- else if (/^min/i.test(signRaw)) {
1549
- sign = 'MINIMUM';
1550
- }
1551
- else if (/^max/i.test(signRaw)) {
1552
- sign = 'MAXIMUM';
1553
- }
1554
- else {
1555
- throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
1556
- }
1557
- var amountRaw = listItemParts.shift();
1558
- var amount = parseNumber(amountRaw);
1559
- if (amount < 0) {
1560
- throw new PromptbookSyntaxError('Amount must be positive number or zero');
1561
- }
1562
- if (amount !== Math.floor(amount)) {
1563
- throw new PromptbookSyntaxError('Amount must be whole number');
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;
1564
1255
  }
1565
- var unitRaw = listItemParts.shift();
1566
- var unit = undefined;
1567
- try {
1568
- 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()) {
1569
- var existingUnit = EXPECTATION_UNITS_1_1.value;
1570
- var existingUnitText = existingUnit;
1571
- existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
1572
- if (existingUnitText === 'CHARACTER') {
1573
- existingUnitText = 'CHAR';
1574
- }
1575
- if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
1576
- new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
1577
- if (unit !== undefined) {
1578
- throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
1579
- }
1580
- unit = existingUnit;
1581
- }
1582
- }
1256
+ else if (/^[A-Z]$/.test(char)) {
1257
+ charType = 'UPPERCASE';
1258
+ normalizedChar = char.toLowerCase();
1583
1259
  }
1584
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1585
- finally {
1586
- try {
1587
- if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
1588
- }
1589
- finally { if (e_1) throw e_1.error; }
1260
+ else if (/^[0-9]$/.test(char)) {
1261
+ charType = 'NUMBER';
1262
+ normalizedChar = char;
1590
1263
  }
1591
- if (unit === undefined) {
1592
- throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
1264
+ else if (/^\/$/.test(char)) {
1265
+ charType = 'SLASH';
1266
+ normalizedChar = char;
1593
1267
  }
1594
- return {
1595
- type: 'EXPECT_AMOUNT',
1596
- sign: sign,
1597
- unit: unit,
1598
- amount: amount,
1599
- };
1600
- }
1601
- catch (error) {
1602
- if (!(error instanceof Error)) {
1603
- throw error;
1268
+ else {
1269
+ charType = 'OTHER';
1270
+ normalizedChar = '-';
1604
1271
  }
1605
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
1272
+ if (charType !== lastCharType &&
1273
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1274
+ !(lastCharType === 'NUMBER') &&
1275
+ !(charType === 'NUMBER')) {
1276
+ normalizedName += '-';
1277
+ }
1278
+ normalizedName += normalizedChar;
1279
+ lastCharType = charType;
1606
1280
  }
1607
- /*
1608
- } else if (type.startsWith('__________________')) {
1609
- // <- [🥻] Insert here when making new command
1610
- */
1611
1281
  }
1612
- else {
1613
- 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; }
1614
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;
1615
1319
  }
1616
1320
 
1617
1321
  /**
@@ -1919,6 +1623,119 @@ function prettifyMarkdown(content) {
1919
1623
  }
1920
1624
  }
1921
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
+
1922
1739
  /**
1923
1740
  * Prettyfies Promptbook string and adds Mermaid graph
1924
1741
  */
@@ -2133,6 +1950,20 @@ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
2133
1950
  * TODO: Escape all
2134
1951
  */
2135
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
+
2136
1967
  /**
2137
1968
  * Tests if given string is valid URL.
2138
1969
  *
@@ -2331,32 +2162,107 @@ function validatePromptbookJson(promptbook) {
2331
2162
  while (unresovedTemplates.length > 0) {
2332
2163
  _loop_2();
2333
2164
  }
2334
- return promptbook;
2335
- }
2165
+ return promptbook;
2166
+ }
2167
+ /**
2168
+ * TODO: [🧠] Work with promptbookVersion
2169
+ * TODO: Use here some json-schema, Zod or something similar and change it to:
2170
+ * > /**
2171
+ * > * Validates PromptbookJson if it is logically valid.
2172
+ * > *
2173
+ * > * It checks:
2174
+ * > * - it has a valid structure
2175
+ * > * - ...
2176
+ * > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
2177
+ */
2178
+
2179
+ /**
2180
+ * This error occurs when some expectation is not met in the execution of the pipeline
2181
+ *
2182
+ * @private Always catched and rethrown as `PromptbookExecutionError`
2183
+ * Note: This is a kindof subtype of PromptbookExecutionError
2184
+ */
2185
+ var ExpectError = /** @class */ (function (_super) {
2186
+ __extends(ExpectError, _super);
2187
+ function ExpectError(message) {
2188
+ var _this = _super.call(this, message) || this;
2189
+ _this.name = 'ExpectError';
2190
+ Object.setPrototypeOf(_this, ExpectError.prototype);
2191
+ return _this;
2192
+ }
2193
+ return ExpectError;
2194
+ }(Error));
2195
+
2196
+ /**
2197
+ * This error indicates errors during the execution of the promptbook
2198
+ */
2199
+ var PromptbookExecutionError = /** @class */ (function (_super) {
2200
+ __extends(PromptbookExecutionError, _super);
2201
+ function PromptbookExecutionError(message) {
2202
+ var _this = _super.call(this, message) || this;
2203
+ _this.name = 'PromptbookExecutionError';
2204
+ Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
2205
+ return _this;
2206
+ }
2207
+ return PromptbookExecutionError;
2208
+ }(Error));
2209
+
2210
+ /**
2211
+ * This error indicates that the promptbook library cannot be propperly loaded
2212
+ */
2213
+ var PromptbookLibraryError = /** @class */ (function (_super) {
2214
+ __extends(PromptbookLibraryError, _super);
2215
+ function PromptbookLibraryError(message) {
2216
+ var _this = _super.call(this, message) || this;
2217
+ _this.name = 'PromptbookLibraryError';
2218
+ Object.setPrototypeOf(_this, PromptbookLibraryError.prototype);
2219
+ return _this;
2220
+ }
2221
+ return PromptbookLibraryError;
2222
+ }(Error));
2223
+
2224
+ /**
2225
+ * This error indicates that promptbook not found in the library
2226
+ */
2227
+ var PromptbookNotFoundError = /** @class */ (function (_super) {
2228
+ __extends(PromptbookNotFoundError, _super);
2229
+ function PromptbookNotFoundError(message) {
2230
+ var _this = _super.call(this, message) || this;
2231
+ _this.name = 'PromptbookNotFoundError';
2232
+ Object.setPrototypeOf(_this, PromptbookNotFoundError.prototype);
2233
+ return _this;
2234
+ }
2235
+ return PromptbookNotFoundError;
2236
+ }(Error));
2237
+
2336
2238
  /**
2337
- * TODO: [🧠] Work with promptbookVersion
2338
- * TODO: Use here some json-schema, Zod or something similar and change it to:
2339
- * > /**
2340
- * > * Validates PromptbookJson if it is logically valid.
2341
- * > *
2342
- * > * It checks:
2343
- * > * - it has a valid structure
2344
- * > * - ...
2345
- * > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
2239
+ * This error indicates errors in referencing promptbooks between each other
2346
2240
  */
2241
+ var PromptbookReferenceError = /** @class */ (function (_super) {
2242
+ __extends(PromptbookReferenceError, _super);
2243
+ function PromptbookReferenceError(message) {
2244
+ var _this = _super.call(this, message) || this;
2245
+ _this.name = 'PromptbookReferenceError';
2246
+ Object.setPrototypeOf(_this, PromptbookReferenceError.prototype);
2247
+ return _this;
2248
+ }
2249
+ return PromptbookReferenceError;
2250
+ }(Error));
2347
2251
 
2348
2252
  /**
2349
- * This error indicates errors during the execution of the promptbook
2253
+ * This error occurs during the parameter replacement in the template
2254
+ *
2255
+ * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
2350
2256
  */
2351
- var PromptbookExecutionError = /** @class */ (function (_super) {
2352
- __extends(PromptbookExecutionError, _super);
2353
- function PromptbookExecutionError(message) {
2257
+ var TemplateError = /** @class */ (function (_super) {
2258
+ __extends(TemplateError, _super);
2259
+ function TemplateError(message) {
2354
2260
  var _this = _super.call(this, message) || this;
2355
- _this.name = 'PromptbookExecutionError';
2356
- Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
2261
+ _this.name = 'TemplateError';
2262
+ Object.setPrototypeOf(_this, TemplateError.prototype);
2357
2263
  return _this;
2358
2264
  }
2359
- return PromptbookExecutionError;
2265
+ return TemplateError;
2360
2266
  }(Error));
2361
2267
 
2362
2268
  /**
@@ -2385,21 +2291,97 @@ function assertsExecutionSuccessful(executionResult) {
2385
2291
  */
2386
2292
 
2387
2293
  /**
2388
- * This error occurs when some expectation is not met in the execution of the pipeline
2389
- *
2390
- * @private Always catched and rethrown as `PromptbookExecutionError`
2391
- * Note: This is a kindof subtype of PromptbookExecutionError
2294
+ * Function isValidJsonString will tell you if the string is valid JSON or not
2392
2295
  */
2393
- var ExpectError = /** @class */ (function (_super) {
2394
- __extends(ExpectError, _super);
2395
- function ExpectError(message) {
2396
- var _this = _super.call(this, message) || this;
2397
- _this.name = 'ExpectError';
2398
- Object.setPrototypeOf(_this, ExpectError.prototype);
2399
- return _this;
2296
+ function isValidJsonString(value) {
2297
+ try {
2298
+ JSON.parse(value);
2299
+ return true;
2400
2300
  }
2401
- return ExpectError;
2402
- }(Error));
2301
+ catch (error) {
2302
+ if (!(error instanceof Error)) {
2303
+ throw error;
2304
+ }
2305
+ if (error.message.includes('Unexpected token')) {
2306
+ return false;
2307
+ }
2308
+ return false;
2309
+ }
2310
+ }
2311
+
2312
+ /**
2313
+ * Counts number of characters in the text
2314
+ */
2315
+ function countCharacters(text) {
2316
+ // Remove null characters
2317
+ text = text.replace(/\0/g, '');
2318
+ // Replace emojis (and also ZWJ sequence) with hyphens
2319
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
2320
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
2321
+ text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
2322
+ return text.length;
2323
+ }
2324
+
2325
+ /**
2326
+ * Counts number of lines in the text
2327
+ */
2328
+ function countLines(text) {
2329
+ if (text === '') {
2330
+ return 0;
2331
+ }
2332
+ return text.split('\n').length;
2333
+ }
2334
+
2335
+ /**
2336
+ * Counts number of pages in the text
2337
+ */
2338
+ function countPages(text) {
2339
+ var sentencesPerPage = 5; // Assuming each page has 5 sentences
2340
+ var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
2341
+ var pageCount = Math.ceil(sentences.length / sentencesPerPage);
2342
+ return pageCount;
2343
+ }
2344
+
2345
+ /**
2346
+ * Counts number of paragraphs in the text
2347
+ */
2348
+ function countParagraphs(text) {
2349
+ return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
2350
+ }
2351
+
2352
+ /**
2353
+ * Split text into sentences
2354
+ */
2355
+ function splitIntoSentences(text) {
2356
+ return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
2357
+ }
2358
+ /**
2359
+ * Counts number of sentences in the text
2360
+ */
2361
+ function countSentences(text) {
2362
+ return splitIntoSentences(text).length;
2363
+ }
2364
+
2365
+ /**
2366
+ * Counts number of words in the text
2367
+ */
2368
+ function countWords(text) {
2369
+ text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
2370
+ text = removeDiacritics(text);
2371
+ return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
2372
+ }
2373
+
2374
+ /**
2375
+ * Index of all counter functions
2376
+ */
2377
+ var CountUtils = {
2378
+ CHARACTERS: countCharacters,
2379
+ WORDS: countWords,
2380
+ SENTENCES: countSentences,
2381
+ PARAGRAPHS: countParagraphs,
2382
+ LINES: countLines,
2383
+ PAGES: countPages,
2384
+ };
2403
2385
 
2404
2386
  /**
2405
2387
  * Function checkExpectations will check if the expectations on given value are met
@@ -2458,6 +2440,66 @@ function isPassingExpectations(expectations, value) {
2458
2440
  * TODO: [💝] Unite object for expecting amount and format
2459
2441
  */
2460
2442
 
2443
+ /**
2444
+ * Replaces parameters in template with values from parameters object
2445
+ *
2446
+ * @param template the template with parameters in {curly} braces
2447
+ * @param parameters the object with parameters
2448
+ * @returns the template with replaced parameters
2449
+ * @throws {TemplateError} if parameter is not defined, not closed, or not opened
2450
+ *
2451
+ * @private within the createPromptbookExecutor
2452
+ */
2453
+ function replaceParameters(template, parameters) {
2454
+ var replacedTemplate = template;
2455
+ var match;
2456
+ var loopLimit = LOOP_LIMIT;
2457
+ var _loop_1 = function () {
2458
+ if (loopLimit-- < 0) {
2459
+ throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
2460
+ }
2461
+ var precol = match.groups.precol;
2462
+ var parameterName = match.groups.parameterName;
2463
+ if (parameterName === '') {
2464
+ return "continue";
2465
+ }
2466
+ if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
2467
+ throw new TemplateError('Parameter is already opened or not closed');
2468
+ }
2469
+ if (parameters[parameterName] === undefined) {
2470
+ throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
2471
+ }
2472
+ var parameterValue = parameters[parameterName];
2473
+ if (parameterValue === undefined) {
2474
+ throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
2475
+ }
2476
+ parameterValue = parameterValue.toString();
2477
+ if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
2478
+ parameterValue = parameterValue
2479
+ .split('\n')
2480
+ .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
2481
+ .join('\n');
2482
+ }
2483
+ replacedTemplate =
2484
+ replacedTemplate.substring(0, match.index + precol.length) +
2485
+ parameterValue +
2486
+ replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
2487
+ };
2488
+ while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
2489
+ .exec(replacedTemplate))) {
2490
+ _loop_1();
2491
+ }
2492
+ // [💫] Check if there are parameters that are not closed properly
2493
+ if (/{\w+$/.test(replacedTemplate)) {
2494
+ throw new TemplateError('Parameter is not closed');
2495
+ }
2496
+ // [💫] Check if there are parameters that are not opened properly
2497
+ if (/^\w+}/.test(replacedTemplate)) {
2498
+ throw new TemplateError('Parameter is not opened');
2499
+ }
2500
+ return replacedTemplate;
2501
+ }
2502
+
2461
2503
  /**
2462
2504
  * Creates executor function from promptbook and execution tools.
2463
2505
  *
@@ -3169,20 +3211,6 @@ var SimplePromptInterfaceTools = /** @class */ (function () {
3169
3211
  return SimplePromptInterfaceTools;
3170
3212
  }());
3171
3213
 
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
-
3186
3214
  /**
3187
3215
  * Detects if the code is running in a browser environment in main thread (Not in a web worker)
3188
3216
  */
@@ -3213,34 +3241,6 @@ function just(value) {
3213
3241
  return value;
3214
3242
  }
3215
3243
 
3216
- /**
3217
- * This error indicates that promptbook not found in the library
3218
- */
3219
- var PromptbookNotFoundError = /** @class */ (function (_super) {
3220
- __extends(PromptbookNotFoundError, _super);
3221
- function PromptbookNotFoundError(message) {
3222
- var _this = _super.call(this, message) || this;
3223
- _this.name = 'PromptbookNotFoundError';
3224
- Object.setPrototypeOf(_this, PromptbookNotFoundError.prototype);
3225
- return _this;
3226
- }
3227
- return PromptbookNotFoundError;
3228
- }(Error));
3229
-
3230
- /**
3231
- * This error indicates errors in referencing promptbooks between each other
3232
- */
3233
- var PromptbookReferenceError = /** @class */ (function (_super) {
3234
- __extends(PromptbookReferenceError, _super);
3235
- function PromptbookReferenceError(message) {
3236
- var _this = _super.call(this, message) || this;
3237
- _this.name = 'PromptbookReferenceError';
3238
- Object.setPrototypeOf(_this, PromptbookReferenceError.prototype);
3239
- return _this;
3240
- }
3241
- return PromptbookReferenceError;
3242
- }(Error));
3243
-
3244
3244
  /**
3245
3245
  * Library of promptbooks that groups together promptbooks for an application.
3246
3246
  * This implementation is a very thin wrapper around the Array / Map of promptbooks.
@@ -4110,5 +4110,5 @@ function executionReportJsonToString(executionReportJson, options) {
4110
4110
  * TODO: [🧠] Allow to filter out some parts of the report by options
4111
4111
  */
4112
4112
 
4113
- export { CallbackInterfaceTools, ExecutionReportStringOptionsDefaults, ExecutionTypes, MultipleLlmExecutionTools, PROMPTBOOK_VERSION, SimplePromptInterfaceTools, SimplePromptbookLibrary, assertsExecutionSuccessful, checkExpectations, createPromptbookExecutor, createPromptbookLibraryFromDirectory, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, executionReportJsonToString, isPassingExpectations, justTestFsImport, prettifyPromptbookString, promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
4113
+ export { CallbackInterfaceTools, ExecutionReportStringOptionsDefaults, ExecutionTypes, ExpectError, MultipleLlmExecutionTools, PROMPTBOOK_VERSION, PromptbookExecutionError, PromptbookLibraryError, PromptbookLogicError, PromptbookNotFoundError, PromptbookReferenceError, PromptbookSyntaxError, SimplePromptInterfaceTools, SimplePromptbookLibrary, TemplateError, UnexpectedError, assertsExecutionSuccessful, checkExpectations, createPromptbookExecutor, createPromptbookLibraryFromDirectory, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, executionReportJsonToString, isPassingExpectations, justTestFsImport, prettifyPromptbookString, promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
4114
4114
  //# sourceMappingURL=index.es.js.map