@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/umd/index.umd.js CHANGED
@@ -454,7 +454,7 @@
454
454
  /**
455
455
  * The version of the Promptbook library
456
456
  */
457
- var PROMPTBOOK_VERSION = '0.52.0-33';
457
+ var PROMPTBOOK_VERSION = '0.53.0';
458
458
 
459
459
  /**
460
460
  * Parses the template and returns the list of all parameter names
@@ -576,88 +576,108 @@
576
576
  * TODO: [🔣] If script require contentLanguage
577
577
  */
578
578
 
579
+ /* tslint:disable */
580
+ /*
581
+ TODO: Tests
582
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
583
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
584
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
585
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
586
+ */
587
+ function normalizeTo_SCREAMING_CASE(sentence) {
588
+ var e_1, _a;
589
+ var charType;
590
+ var lastCharType = 'OTHER';
591
+ var normalizedName = '';
592
+ try {
593
+ for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
594
+ var char = sentence_1_1.value;
595
+ var normalizedChar = void 0;
596
+ if (/^[a-z]$/.test(char)) {
597
+ charType = 'LOWERCASE';
598
+ normalizedChar = char.toUpperCase();
599
+ }
600
+ else if (/^[A-Z]$/.test(char)) {
601
+ charType = 'UPPERCASE';
602
+ normalizedChar = char;
603
+ }
604
+ else if (/^[0-9]$/.test(char)) {
605
+ charType = 'NUMBER';
606
+ normalizedChar = char;
607
+ }
608
+ else if (/^\/$/.test(char)) {
609
+ charType = 'SLASH';
610
+ normalizedChar = char;
611
+ }
612
+ else {
613
+ charType = 'OTHER';
614
+ normalizedChar = '_';
615
+ }
616
+ if (charType !== lastCharType &&
617
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
618
+ !(lastCharType === 'NUMBER') &&
619
+ !(charType === 'NUMBER')) {
620
+ normalizedName += '_';
621
+ }
622
+ normalizedName += normalizedChar;
623
+ lastCharType = charType;
624
+ }
625
+ }
626
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
627
+ finally {
628
+ try {
629
+ if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
630
+ }
631
+ finally { if (e_1) throw e_1.error; }
632
+ }
633
+ normalizedName = normalizedName.replace(/_+/g, '_');
634
+ normalizedName = normalizedName.replace(/_?\/_?/g, '/');
635
+ normalizedName = normalizedName.replace(/^_/, '');
636
+ normalizedName = normalizedName.replace(/_$/, '');
637
+ return normalizedName;
638
+ }
579
639
  /**
580
- * Removes emojis from a string and fix whitespaces
640
+ * TODO: [🌺] Use some intermediate util splitWords
641
+ */
642
+
643
+ /**
644
+ * Execution type describes the way how the block is executed
581
645
  *
582
- * @param text with emojis
583
- * @returns text without emojis
646
+ * @see https://github.com/webgptorg/promptbook#execution-type
584
647
  */
585
- function removeEmojis(text) {
586
- // Replace emojis (and also ZWJ sequence) with hyphens
587
- text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
588
- text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
589
- text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
590
- text = text.replace(/\p{Extended_Pictographic}/gu, '');
591
- return text;
592
- }
648
+ var ExecutionTypes = [
649
+ 'PROMPT_TEMPLATE',
650
+ 'SIMPLE_TEMPLATE',
651
+ 'SCRIPT',
652
+ 'PROMPT_DIALOG',
653
+ // <- [🥻] Insert here when making new command
654
+ ];
593
655
 
594
656
  /**
595
- * Function normalizes title to name which can be used as identifier
657
+ * Units of text measurement
658
+ */
659
+ var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
660
+ /**
661
+ * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
662
+ * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
663
+ * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
596
664
  */
597
- function titleToName(value) {
598
- value = removeEmojis(value);
599
- value = normalizeToKebabCase(value);
600
- // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
601
- return value;
602
- }
603
665
 
604
666
  /**
605
- * Creates a Mermaid graph based on the promptbook
667
+ * Removes Markdown formatting tags from a string.
606
668
  *
607
- * Note: The result is not wrapped in a Markdown code block
669
+ * @param {string} str - The string to remove Markdown tags from.
670
+ * @returns {string} The input string with all Markdown tags removed.
608
671
  */
609
- function renderPromptbookMermaid(promptbookJson, options) {
610
- var _a = (options || {}).linkPromptTemplate, linkPromptTemplate = _a === void 0 ? function () { return null; } : _a;
611
- var parameterNameToTemplateName = function (parameterName) {
612
- var parameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
613
- if (!parameter) {
614
- throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
615
- }
616
- if (parameter.isInput) {
617
- return 'input';
618
- }
619
- var template = promptbookJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
620
- if (!template) {
621
- throw new Error("Could not find template for {".concat(parameterName, "}"));
622
- }
623
- return normalizeTo_camelCase('template-' + titleToName(template.title));
624
- };
625
- var promptbookMermaid = spaceTrim.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
626
- .flatMap(function (_a) {
627
- var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
628
- return __spreadArray([
629
- "".concat(parameterNameToTemplateName(resultingParameterName), "(\"").concat(title, "\")")
630
- ], __read(dependentParameterNames.map(function (dependentParameterName) {
631
- return "".concat(parameterNameToTemplateName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName(resultingParameterName));
632
- })), false);
633
- })
634
- .join('\n')), "\n\n ").concat(block(promptbookJson.parameters
635
- .filter(function (_a) {
636
- var isOutput = _a.isOutput;
637
- return isOutput;
638
- })
639
- .map(function (_a) {
640
- var name = _a.name;
641
- return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
642
- })
643
- .join('\n')), "\n output((Output)):::output\n\n ").concat(block(promptbookJson.promptTemplates
644
- .map(function (promptTemplate) {
645
- var link = linkPromptTemplate(promptTemplate);
646
- if (link === null) {
647
- return '';
648
- }
649
- var href = link.href, title = link.title;
650
- var templateName = parameterNameToTemplateName(promptTemplate.resultingParameterName);
651
- return "click ".concat(templateName, " href \"").concat(href, "\" \"").concat(title, "\";");
652
- })
653
- .filter(function (line) { return line !== ''; })
654
- .join('\n')), "\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
655
- return promptbookMermaid;
672
+ function removeMarkdownFormatting(str) {
673
+ // Remove bold formatting
674
+ str = str.replace(/\*\*(.*?)\*\*/g, '$1');
675
+ // Remove italic formatting
676
+ str = str.replace(/\*(.*?)\*/g, '$1');
677
+ // Remove code formatting
678
+ str = str.replace(/`(.*?)`/g, '$1');
679
+ return str;
656
680
  }
657
- /**
658
- * TODO: Maybe use some Mermaid library instead of string templating
659
- * TODO: [🕌] When more than 2 functionalities, split into separate functions
660
- */
661
681
 
662
682
  /**
663
683
  * Function parseNumber will parse number from string
@@ -727,897 +747,581 @@
727
747
  */
728
748
 
729
749
  /**
730
- * This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
731
- */
732
- var PromptbookLogicError = /** @class */ (function (_super) {
733
- __extends(PromptbookLogicError, _super);
734
- function PromptbookLogicError(message) {
735
- var _this = _super.call(this, message) || this;
736
- _this.name = 'PromptbookLogicError';
737
- Object.setPrototypeOf(_this, PromptbookLogicError.prototype);
738
- return _this;
739
- }
740
- return PromptbookLogicError;
741
- }(Error));
742
-
743
- /**
744
- * This error occurs during the parameter replacement in the template
745
- *
746
- * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
747
- */
748
- var TemplateError = /** @class */ (function (_super) {
749
- __extends(TemplateError, _super);
750
- function TemplateError(message) {
751
- var _this = _super.call(this, message) || this;
752
- _this.name = 'TemplateError';
753
- Object.setPrototypeOf(_this, TemplateError.prototype);
754
- return _this;
755
- }
756
- return TemplateError;
757
- }(Error));
758
-
759
- /**
760
- * Replaces parameters in template with values from parameters object
750
+ * Parses one line of ul/ol to command
761
751
  *
762
- * @param template the template with parameters in {curly} braces
763
- * @param parameters the object with parameters
764
- * @returns the template with replaced parameters
765
- * @throws {TemplateError} if parameter is not defined, not closed, or not opened
752
+ * @returns parsed command object
753
+ * @throws {PromptbookSyntaxError} if the command is invalid
766
754
  *
767
- * @private within the createPromptbookExecutor
755
+ * @private within the promptbookStringToJson
768
756
  */
769
- function replaceParameters(template, parameters) {
770
- var replacedTemplate = template;
771
- var match;
772
- var loopLimit = LOOP_LIMIT;
773
- var _loop_1 = function () {
774
- if (loopLimit-- < 0) {
775
- throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
776
- }
777
- var precol = match.groups.precol;
778
- var parameterName = match.groups.parameterName;
779
- if (parameterName === '') {
780
- return "continue";
757
+ function parseCommand(listItem) {
758
+ var e_1, _a;
759
+ if (listItem.includes('\n') || listItem.includes('\r')) {
760
+ throw new PromptbookSyntaxError('Command can not contain new line characters:');
761
+ }
762
+ var type = listItem.trim();
763
+ type = type.split('`').join('');
764
+ type = type.split('"').join('');
765
+ type = type.split("'").join('');
766
+ type = type.split('~').join('');
767
+ type = type.split('[').join('');
768
+ type = type.split(']').join('');
769
+ type = type.split('(').join('');
770
+ type = type.split(')').join('');
771
+ type = normalizeTo_SCREAMING_CASE(type);
772
+ type = type.split('DIALOGUE').join('DIALOG');
773
+ var listItemParts = listItem
774
+ .split(' ')
775
+ .map(function (part) { return part.trim(); })
776
+ .filter(function (item) { return item !== ''; })
777
+ .filter(function (item) { return !/^PTBK$/i.test(item); })
778
+ .filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
779
+ .map(removeMarkdownFormatting);
780
+ if (type.startsWith('URL') ||
781
+ type.startsWith('PTBK_URL') ||
782
+ type.startsWith('PTBKURL') ||
783
+ type.startsWith('PROMPTBOOK_URL') ||
784
+ type.startsWith('PROMPTBOOKURL') ||
785
+ type.startsWith('HTTPS')) {
786
+ if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
787
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
781
788
  }
782
- if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
783
- throw new TemplateError('Parameter is already opened or not closed');
789
+ var promptbookUrlString = listItemParts.pop();
790
+ var promptbookUrl = new URL(promptbookUrlString);
791
+ if (promptbookUrl.protocol !== 'https:') {
792
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
784
793
  }
785
- if (parameters[parameterName] === undefined) {
786
- throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
794
+ if (promptbookUrl.hash !== '') {
795
+ throw new PromptbookSyntaxError(spaceTrim.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 ")));
787
796
  }
788
- var parameterValue = parameters[parameterName];
789
- if (parameterValue === undefined) {
790
- throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
791
- }
792
- parameterValue = parameterValue.toString();
793
- if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
794
- parameterValue = parameterValue
795
- .split('\n')
796
- .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
797
- .join('\n');
798
- }
799
- replacedTemplate =
800
- replacedTemplate.substring(0, match.index + precol.length) +
801
- parameterValue +
802
- replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
803
- };
804
- while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
805
- .exec(replacedTemplate))) {
806
- _loop_1();
807
- }
808
- // [💫] Check if there are parameters that are not closed properly
809
- if (/{\w+$/.test(replacedTemplate)) {
810
- throw new TemplateError('Parameter is not closed');
811
- }
812
- // [💫] Check if there are parameters that are not opened properly
813
- if (/^\w+}/.test(replacedTemplate)) {
814
- throw new TemplateError('Parameter is not opened');
815
- }
816
- return replacedTemplate;
817
- }
818
-
819
- /**
820
- * Counts number of characters in the text
821
- */
822
- function countCharacters(text) {
823
- // Remove null characters
824
- text = text.replace(/\0/g, '');
825
- // Replace emojis (and also ZWJ sequence) with hyphens
826
- text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
827
- text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
828
- text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
829
- return text.length;
830
- }
831
-
832
- /**
833
- * Counts number of lines in the text
834
- */
835
- function countLines(text) {
836
- if (text === '') {
837
- return 0;
838
- }
839
- return text.split('\n').length;
840
- }
841
-
842
- /**
843
- * Counts number of pages in the text
844
- */
845
- function countPages(text) {
846
- var sentencesPerPage = 5; // Assuming each page has 5 sentences
847
- var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
848
- var pageCount = Math.ceil(sentences.length / sentencesPerPage);
849
- return pageCount;
850
- }
851
-
852
- /**
853
- * Counts number of paragraphs in the text
854
- */
855
- function countParagraphs(text) {
856
- return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
857
- }
858
-
859
- /**
860
- * Split text into sentences
861
- */
862
- function splitIntoSentences(text) {
863
- return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
864
- }
865
- /**
866
- * Counts number of sentences in the text
867
- */
868
- function countSentences(text) {
869
- return splitIntoSentences(text).length;
870
- }
871
-
872
- var defaultDiacriticsRemovalMap = [
873
- {
874
- base: 'A',
875
- 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',
876
- },
877
- { base: 'AA', letters: '\uA732' },
878
- { base: 'AE', letters: '\u00C6\u01FC\u01E2' },
879
- { base: 'AO', letters: '\uA734' },
880
- { base: 'AU', letters: '\uA736' },
881
- { base: 'AV', letters: '\uA738\uA73A' },
882
- { base: 'AY', letters: '\uA73C' },
883
- {
884
- base: 'B',
885
- letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
886
- },
887
- {
888
- base: 'C',
889
- letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
890
- },
891
- {
892
- base: 'D',
893
- letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
894
- },
895
- { base: 'DZ', letters: '\u01F1\u01C4' },
896
- { base: 'Dz', letters: '\u01F2\u01C5' },
897
- {
898
- base: 'E',
899
- 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',
900
- },
901
- { base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
902
- {
903
- base: 'G',
904
- letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
905
- },
906
- {
907
- base: 'H',
908
- letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
909
- },
910
- {
911
- base: 'I',
912
- letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
913
- },
914
- { base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
915
- {
916
- base: 'K',
917
- letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
918
- },
919
- {
920
- base: 'L',
921
- letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
922
- },
923
- { base: 'LJ', letters: '\u01C7' },
924
- { base: 'Lj', letters: '\u01C8' },
925
- { base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
926
- {
927
- base: 'N',
928
- letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
929
- },
930
- { base: 'NJ', letters: '\u01CA' },
931
- { base: 'Nj', letters: '\u01CB' },
932
- {
933
- base: 'O',
934
- 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',
935
- },
936
- { base: 'OI', letters: '\u01A2' },
937
- { base: 'OO', letters: '\uA74E' },
938
- { base: 'OU', letters: '\u0222' },
939
- { base: 'OE', letters: '\u008C\u0152' },
940
- { base: 'oe', letters: '\u009C\u0153' },
941
- {
942
- base: 'P',
943
- letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
944
- },
945
- { base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
946
- {
947
- base: 'R',
948
- letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
949
- },
950
- {
951
- base: 'S',
952
- letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
953
- },
954
- {
955
- base: 'T',
956
- letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
957
- },
958
- { base: 'TZ', letters: '\uA728' },
959
- {
960
- base: 'U',
961
- 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',
962
- },
963
- { base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
964
- { base: 'VY', letters: '\uA760' },
965
- {
966
- base: 'W',
967
- letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
968
- },
969
- { base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
970
- {
971
- base: 'Y',
972
- letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
973
- },
974
- {
975
- base: 'Z',
976
- letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
977
- },
978
- {
979
- base: 'a',
980
- 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',
981
- },
982
- { base: 'aa', letters: '\uA733' },
983
- { base: 'ae', letters: '\u00E6\u01FD\u01E3' },
984
- { base: 'ao', letters: '\uA735' },
985
- { base: 'au', letters: '\uA737' },
986
- { base: 'av', letters: '\uA739\uA73B' },
987
- { base: 'ay', letters: '\uA73D' },
988
- {
989
- base: 'b',
990
- letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
991
- },
992
- {
993
- base: 'c',
994
- letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
995
- },
996
- {
997
- base: 'd',
998
- letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
999
- },
1000
- { base: 'dz', letters: '\u01F3\u01C6' },
1001
- {
1002
- base: 'e',
1003
- 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',
1004
- },
1005
- { base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
1006
- {
1007
- base: 'g',
1008
- letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
1009
- },
1010
- {
1011
- base: 'h',
1012
- letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
1013
- },
1014
- { base: 'hv', letters: '\u0195' },
1015
- {
1016
- base: 'i',
1017
- letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
1018
- },
1019
- { base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
1020
- {
1021
- base: 'k',
1022
- letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
1023
- },
1024
- {
1025
- base: 'l',
1026
- letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
1027
- },
1028
- { base: 'lj', letters: '\u01C9' },
1029
- { base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
1030
- {
1031
- base: 'n',
1032
- letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
1033
- },
1034
- { base: 'nj', letters: '\u01CC' },
1035
- {
1036
- base: 'o',
1037
- 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',
1038
- },
1039
- { base: 'oi', letters: '\u01A3' },
1040
- { base: 'ou', letters: '\u0223' },
1041
- { base: 'oo', letters: '\uA74F' },
1042
- {
1043
- base: 'p',
1044
- letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
1045
- },
1046
- { base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
1047
- {
1048
- base: 'r',
1049
- letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
1050
- },
1051
- {
1052
- base: 's',
1053
- letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
1054
- },
1055
- {
1056
- base: 't',
1057
- letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
1058
- },
1059
- { base: 'tz', letters: '\uA729' },
1060
- {
1061
- base: 'u',
1062
- 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',
1063
- },
1064
- { base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
1065
- { base: 'vy', letters: '\uA761' },
1066
- {
1067
- base: 'w',
1068
- letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
1069
- },
1070
- { base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
1071
- {
1072
- base: 'y',
1073
- letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
1074
- },
1075
- {
1076
- base: 'z',
1077
- letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
1078
- },
1079
- ];
1080
- /**
1081
- * Map of letters from diacritic variant to diacritless variant
1082
- * Contains lowercase and uppercase separatelly
1083
- *
1084
- * > "á" => "a"
1085
- * > "ě" => "e"
1086
- * > "Ă" => "A"
1087
- * > ...
1088
- */
1089
- var DIACRITIC_VARIANTS_LETTERS = {};
1090
- // tslint:disable-next-line: prefer-for-of
1091
- for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
1092
- var letters = defaultDiacriticsRemovalMap[i].letters;
1093
- // tslint:disable-next-line: prefer-for-of
1094
- for (var j = 0; j < letters.length; j++) {
1095
- DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
1096
- }
1097
- }
1098
- // <- TODO: [🍓] Put to maker function to save execution time if not needed
1099
- /*
1100
- @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
1101
- Licensed under the Apache License, Version 2.0 (the "License");
1102
- you may not use this file except in compliance with the License.
1103
- You may obtain a copy of the License at
1104
-
1105
- http://www.apache.org/licenses/LICENSE-2.0
1106
-
1107
- Unless required by applicable law or agreed to in writing, software
1108
- distributed under the License is distributed on an "AS IS" BASIS,
1109
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1110
- See the License for the specific language governing permissions and
1111
- limitations under the License.
1112
- */
1113
-
1114
- /**
1115
- *
1116
- */
1117
- function removeDiacritics(input) {
1118
- /*eslint no-control-regex: "off"*/
1119
- return input.replace(/[^\u0000-\u007E]/g, function (a) {
1120
- return DIACRITIC_VARIANTS_LETTERS[a] || a;
1121
- });
1122
- }
1123
-
1124
- /**
1125
- * Counts number of words in the text
1126
- */
1127
- function countWords(text) {
1128
- text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
1129
- text = removeDiacritics(text);
1130
- return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
1131
- }
1132
-
1133
- /**
1134
- * Index of all counter functions
1135
- */
1136
- var CountUtils = {
1137
- CHARACTERS: countCharacters,
1138
- WORDS: countWords,
1139
- SENTENCES: countSentences,
1140
- PARAGRAPHS: countParagraphs,
1141
- LINES: countLines,
1142
- PAGES: countPages,
1143
- };
1144
-
1145
- /**
1146
- * Function isValidJsonString will tell you if the string is valid JSON or not
1147
- */
1148
- function isValidJsonString(value) {
1149
- try {
1150
- JSON.parse(value);
1151
- return true;
1152
- }
1153
- catch (error) {
1154
- if (!(error instanceof Error)) {
1155
- throw error;
1156
- }
1157
- if (error.message.includes('Unexpected token')) {
1158
- return false;
1159
- }
1160
- return false;
1161
- }
1162
- }
1163
-
1164
- /**
1165
- * Removes Markdown formatting tags from a string.
1166
- *
1167
- * @param {string} str - The string to remove Markdown tags from.
1168
- * @returns {string} The input string with all Markdown tags removed.
1169
- */
1170
- function removeMarkdownFormatting(str) {
1171
- // Remove bold formatting
1172
- str = str.replace(/\*\*(.*?)\*\*/g, '$1');
1173
- // Remove italic formatting
1174
- str = str.replace(/\*(.*?)\*/g, '$1');
1175
- // Remove code formatting
1176
- str = str.replace(/`(.*?)`/g, '$1');
1177
- return str;
1178
- }
1179
-
1180
- /* tslint:disable */
1181
- /*
1182
- TODO: Tests
1183
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
1184
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
1185
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
1186
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
1187
- */
1188
- function normalizeTo_SCREAMING_CASE(sentence) {
1189
- var e_1, _a;
1190
- var charType;
1191
- var lastCharType = 'OTHER';
1192
- var normalizedName = '';
1193
- try {
1194
- for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1195
- var char = sentence_1_1.value;
1196
- var normalizedChar = void 0;
1197
- if (/^[a-z]$/.test(char)) {
1198
- charType = 'LOWERCASE';
1199
- normalizedChar = char.toUpperCase();
1200
- }
1201
- else if (/^[A-Z]$/.test(char)) {
1202
- charType = 'UPPERCASE';
1203
- normalizedChar = char;
1204
- }
1205
- else if (/^[0-9]$/.test(char)) {
1206
- charType = 'NUMBER';
1207
- normalizedChar = char;
1208
- }
1209
- else if (/^\/$/.test(char)) {
1210
- charType = 'SLASH';
1211
- normalizedChar = char;
1212
- }
1213
- else {
1214
- charType = 'OTHER';
1215
- normalizedChar = '_';
1216
- }
1217
- if (charType !== lastCharType &&
1218
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1219
- !(lastCharType === 'NUMBER') &&
1220
- !(charType === 'NUMBER')) {
1221
- normalizedName += '_';
1222
- }
1223
- normalizedName += normalizedChar;
1224
- lastCharType = charType;
797
+ return {
798
+ type: 'PROMPTBOOK_URL',
799
+ promptbookUrl: promptbookUrl,
800
+ };
801
+ }
802
+ else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
803
+ if (listItemParts.length !== 2) {
804
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
1225
805
  }
806
+ var promptbookVersion = listItemParts.pop();
807
+ // TODO: Validate version
808
+ return {
809
+ type: 'PROMPTBOOK_VERSION',
810
+ promptbookVersion: promptbookVersion,
811
+ };
1226
812
  }
1227
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1228
- finally {
1229
- try {
1230
- if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
813
+ else if (type.startsWith('EXECUTE') ||
814
+ type.startsWith('EXEC') ||
815
+ type.startsWith('PROMPT_DIALOG') ||
816
+ type.startsWith('SIMPLE_TEMPLATE')) {
817
+ var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
818
+ if (executionTypes.length !== 1) {
819
+ throw new PromptbookSyntaxError(spaceTrim.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 "); }));
1231
820
  }
1232
- finally { if (e_1) throw e_1.error; }
821
+ return {
822
+ type: 'EXECUTE',
823
+ executionType: executionTypes[0],
824
+ };
1233
825
  }
1234
- normalizedName = normalizedName.replace(/_+/g, '_');
1235
- normalizedName = normalizedName.replace(/_?\/_?/g, '/');
1236
- normalizedName = normalizedName.replace(/^_/, '');
1237
- normalizedName = normalizedName.replace(/_$/, '');
1238
- return normalizedName;
1239
- }
1240
- /**
1241
- * TODO: [🌺] Use some intermediate util splitWords
1242
- */
1243
-
1244
- /* tslint:disable */
1245
- function normalizeToKebabCase(sentence) {
1246
- var e_1, _a;
1247
- sentence = removeDiacritics(sentence);
1248
- var charType;
1249
- var lastCharType = 'OTHER';
1250
- var normalizedName = '';
1251
- try {
1252
- for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1253
- var char = sentence_1_1.value;
1254
- var normalizedChar = void 0;
1255
- if (/^[a-z]$/.test(char)) {
1256
- charType = 'LOWERCASE';
1257
- normalizedChar = char;
1258
- }
1259
- else if (/^[A-Z]$/.test(char)) {
1260
- charType = 'UPPERCASE';
1261
- normalizedChar = char.toLowerCase();
1262
- }
1263
- else if (/^[0-9]$/.test(char)) {
1264
- charType = 'NUMBER';
1265
- normalizedChar = char;
826
+ else if (type.startsWith('MODEL')) {
827
+ // TODO: Make this more elegant and dynamically
828
+ if (type.startsWith('MODEL_VARIANT')) {
829
+ if (type === 'MODEL_VARIANT_CHAT') {
830
+ return {
831
+ type: 'MODEL',
832
+ key: 'modelVariant',
833
+ value: 'CHAT',
834
+ };
1266
835
  }
1267
- else if (/^\/$/.test(char)) {
1268
- charType = 'SLASH';
1269
- normalizedChar = char;
836
+ else if (type === 'MODEL_VARIANT_COMPLETION') {
837
+ return {
838
+ type: 'MODEL',
839
+ key: 'modelVariant',
840
+ value: 'COMPLETION',
841
+ };
1270
842
  }
1271
843
  else {
1272
- charType = 'OTHER';
1273
- normalizedChar = '-';
1274
- }
1275
- if (charType !== lastCharType &&
1276
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1277
- !(lastCharType === 'NUMBER') &&
1278
- !(charType === 'NUMBER')) {
1279
- normalizedName += '-';
844
+ throw new PromptbookSyntaxError(spaceTrim.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 "); }));
1280
845
  }
1281
- normalizedName += normalizedChar;
1282
- lastCharType = charType;
846
+ }
847
+ if (type.startsWith('MODEL_NAME')) {
848
+ return {
849
+ type: 'MODEL',
850
+ key: 'modelName',
851
+ value: listItemParts.pop(),
852
+ };
853
+ }
854
+ else {
855
+ throw new PromptbookSyntaxError(spaceTrim.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 "); }));
1283
856
  }
1284
857
  }
1285
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1286
- finally {
1287
- try {
1288
- if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
858
+ else if (type.startsWith('PARAM') ||
859
+ type.startsWith('INPUT_PARAM') ||
860
+ type.startsWith('OUTPUT_PARAM') ||
861
+ listItem.startsWith('{') ||
862
+ listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
863
+ var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
864
+ if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
865
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1289
866
  }
1290
- finally { if (e_1) throw e_1.error; }
867
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
868
+ var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
869
+ if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
870
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
871
+ }
872
+ var isInput = type.startsWith('INPUT');
873
+ var isOutput = type.startsWith('OUTPUT');
874
+ if (listItem.startsWith('> {')) {
875
+ isInput = false;
876
+ isOutput = false;
877
+ }
878
+ return {
879
+ type: 'PARAMETER',
880
+ parameterName: parameterName,
881
+ parameterDescription: parameterDescription.trim() || null,
882
+ isInput: isInput,
883
+ isOutput: isOutput,
884
+ };
1291
885
  }
1292
- normalizedName = normalizedName.split(/-+/g).join('-');
1293
- normalizedName = normalizedName.split(/-?\/-?/g).join('/');
1294
- normalizedName = normalizedName.replace(/^-/, '');
1295
- normalizedName = normalizedName.replace(/-$/, '');
1296
- return normalizedName;
1297
- }
1298
-
1299
- /* tslint:disable */
1300
- function normalizeTo_camelCase(sentence, __firstLetterCapital) {
1301
- var e_1, _a;
1302
- if (__firstLetterCapital === void 0) { __firstLetterCapital = false; }
1303
- var charType;
1304
- var lastCharType = null;
1305
- var normalizedName = '';
1306
- try {
1307
- for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1308
- var char = sentence_1_1.value;
1309
- var normalizedChar = void 0;
1310
- if (/^[a-z]$/.test(char)) {
1311
- charType = 'LOWERCASE';
1312
- normalizedChar = char;
886
+ else if (type.startsWith('JOKER')) {
887
+ if (listItemParts.length !== 2) {
888
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
889
+ }
890
+ var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
891
+ if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
892
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
893
+ }
894
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
895
+ var parameterName = parametersMatch.groups.parameterName;
896
+ return {
897
+ type: 'JOKER',
898
+ parameterName: parameterName,
899
+ };
900
+ }
901
+ else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
902
+ if (listItemParts.length !== 2) {
903
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
904
+ }
905
+ var functionName = listItemParts.pop();
906
+ return {
907
+ type: 'POSTPROCESS',
908
+ functionName: functionName,
909
+ };
910
+ }
911
+ else if (type.startsWith('EXPECT_JSON')) {
912
+ return {
913
+ type: 'EXPECT_FORMAT',
914
+ format: 'JSON',
915
+ };
916
+ // [🥤]
917
+ }
918
+ else if (type.startsWith('EXPECT')) {
919
+ try {
920
+ listItemParts.shift();
921
+ var sign = void 0;
922
+ var signRaw = listItemParts.shift();
923
+ if (/^exact/i.test(signRaw)) {
924
+ sign = 'EXACTLY';
1313
925
  }
1314
- else if (/^[A-Z]$/.test(char)) {
1315
- charType = 'UPPERCASE';
1316
- normalizedChar = char.toLowerCase();
926
+ else if (/^min/i.test(signRaw)) {
927
+ sign = 'MINIMUM';
1317
928
  }
1318
- else if (/^[0-9]$/.test(char)) {
1319
- charType = 'NUMBER';
1320
- normalizedChar = char;
929
+ else if (/^max/i.test(signRaw)) {
930
+ sign = 'MAXIMUM';
1321
931
  }
1322
932
  else {
1323
- charType = 'OTHER';
1324
- normalizedChar = '';
933
+ throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
1325
934
  }
1326
- if (!lastCharType) {
1327
- if (__firstLetterCapital) {
1328
- normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
935
+ var amountRaw = listItemParts.shift();
936
+ var amount = parseNumber(amountRaw);
937
+ if (amount < 0) {
938
+ throw new PromptbookSyntaxError('Amount must be positive number or zero');
939
+ }
940
+ if (amount !== Math.floor(amount)) {
941
+ throw new PromptbookSyntaxError('Amount must be whole number');
942
+ }
943
+ var unitRaw = listItemParts.shift();
944
+ var unit = undefined;
945
+ try {
946
+ 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()) {
947
+ var existingUnit = EXPECTATION_UNITS_1_1.value;
948
+ var existingUnitText = existingUnit;
949
+ existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
950
+ if (existingUnitText === 'CHARACTER') {
951
+ existingUnitText = 'CHAR';
952
+ }
953
+ if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
954
+ new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
955
+ if (unit !== undefined) {
956
+ throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
957
+ }
958
+ unit = existingUnit;
959
+ }
1329
960
  }
1330
961
  }
1331
- else if (charType !== lastCharType &&
1332
- !(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
1333
- !(lastCharType === 'NUMBER') &&
1334
- !(charType === 'NUMBER')) {
1335
- normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
962
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
963
+ finally {
964
+ try {
965
+ if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
966
+ }
967
+ finally { if (e_1) throw e_1.error; }
968
+ }
969
+ if (unit === undefined) {
970
+ throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
971
+ }
972
+ return {
973
+ type: 'EXPECT_AMOUNT',
974
+ sign: sign,
975
+ unit: unit,
976
+ amount: amount,
977
+ };
978
+ }
979
+ catch (error) {
980
+ if (!(error instanceof Error)) {
981
+ throw error;
1336
982
  }
1337
- normalizedName += normalizedChar;
1338
- lastCharType = charType;
983
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
1339
984
  }
985
+ /*
986
+ } else if (type.startsWith('__________________')) {
987
+ // <- [🥻] Insert here when making new command
988
+ */
1340
989
  }
1341
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1342
- finally {
1343
- try {
1344
- if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
1345
- }
1346
- finally { if (e_1) throw e_1.error; }
990
+ else {
991
+ throw new PromptbookSyntaxError(spaceTrim.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 ")));
1347
992
  }
1348
- return normalizedName;
1349
993
  }
1350
- /**
1351
- * TODO: [🌺] Use some intermediate util splitWords
1352
- */
1353
994
 
995
+ var defaultDiacriticsRemovalMap = [
996
+ {
997
+ base: 'A',
998
+ 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',
999
+ },
1000
+ { base: 'AA', letters: '\uA732' },
1001
+ { base: 'AE', letters: '\u00C6\u01FC\u01E2' },
1002
+ { base: 'AO', letters: '\uA734' },
1003
+ { base: 'AU', letters: '\uA736' },
1004
+ { base: 'AV', letters: '\uA738\uA73A' },
1005
+ { base: 'AY', letters: '\uA73C' },
1006
+ {
1007
+ base: 'B',
1008
+ letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
1009
+ },
1010
+ {
1011
+ base: 'C',
1012
+ letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
1013
+ },
1014
+ {
1015
+ base: 'D',
1016
+ letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
1017
+ },
1018
+ { base: 'DZ', letters: '\u01F1\u01C4' },
1019
+ { base: 'Dz', letters: '\u01F2\u01C5' },
1020
+ {
1021
+ base: 'E',
1022
+ 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',
1023
+ },
1024
+ { base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
1025
+ {
1026
+ base: 'G',
1027
+ letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
1028
+ },
1029
+ {
1030
+ base: 'H',
1031
+ letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
1032
+ },
1033
+ {
1034
+ base: 'I',
1035
+ letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
1036
+ },
1037
+ { base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
1038
+ {
1039
+ base: 'K',
1040
+ letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
1041
+ },
1042
+ {
1043
+ base: 'L',
1044
+ letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
1045
+ },
1046
+ { base: 'LJ', letters: '\u01C7' },
1047
+ { base: 'Lj', letters: '\u01C8' },
1048
+ { base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
1049
+ {
1050
+ base: 'N',
1051
+ letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
1052
+ },
1053
+ { base: 'NJ', letters: '\u01CA' },
1054
+ { base: 'Nj', letters: '\u01CB' },
1055
+ {
1056
+ base: 'O',
1057
+ 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',
1058
+ },
1059
+ { base: 'OI', letters: '\u01A2' },
1060
+ { base: 'OO', letters: '\uA74E' },
1061
+ { base: 'OU', letters: '\u0222' },
1062
+ { base: 'OE', letters: '\u008C\u0152' },
1063
+ { base: 'oe', letters: '\u009C\u0153' },
1064
+ {
1065
+ base: 'P',
1066
+ letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
1067
+ },
1068
+ { base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
1069
+ {
1070
+ base: 'R',
1071
+ letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
1072
+ },
1073
+ {
1074
+ base: 'S',
1075
+ letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
1076
+ },
1077
+ {
1078
+ base: 'T',
1079
+ letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
1080
+ },
1081
+ { base: 'TZ', letters: '\uA728' },
1082
+ {
1083
+ base: 'U',
1084
+ 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',
1085
+ },
1086
+ { base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
1087
+ { base: 'VY', letters: '\uA760' },
1088
+ {
1089
+ base: 'W',
1090
+ letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
1091
+ },
1092
+ { base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
1093
+ {
1094
+ base: 'Y',
1095
+ letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
1096
+ },
1097
+ {
1098
+ base: 'Z',
1099
+ letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
1100
+ },
1101
+ {
1102
+ base: 'a',
1103
+ 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',
1104
+ },
1105
+ { base: 'aa', letters: '\uA733' },
1106
+ { base: 'ae', letters: '\u00E6\u01FD\u01E3' },
1107
+ { base: 'ao', letters: '\uA735' },
1108
+ { base: 'au', letters: '\uA737' },
1109
+ { base: 'av', letters: '\uA739\uA73B' },
1110
+ { base: 'ay', letters: '\uA73D' },
1111
+ {
1112
+ base: 'b',
1113
+ letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
1114
+ },
1115
+ {
1116
+ base: 'c',
1117
+ letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
1118
+ },
1119
+ {
1120
+ base: 'd',
1121
+ letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
1122
+ },
1123
+ { base: 'dz', letters: '\u01F3\u01C6' },
1124
+ {
1125
+ base: 'e',
1126
+ 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',
1127
+ },
1128
+ { base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
1129
+ {
1130
+ base: 'g',
1131
+ letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
1132
+ },
1133
+ {
1134
+ base: 'h',
1135
+ letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
1136
+ },
1137
+ { base: 'hv', letters: '\u0195' },
1138
+ {
1139
+ base: 'i',
1140
+ letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
1141
+ },
1142
+ { base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
1143
+ {
1144
+ base: 'k',
1145
+ letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
1146
+ },
1147
+ {
1148
+ base: 'l',
1149
+ letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
1150
+ },
1151
+ { base: 'lj', letters: '\u01C9' },
1152
+ { base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
1153
+ {
1154
+ base: 'n',
1155
+ letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
1156
+ },
1157
+ { base: 'nj', letters: '\u01CC' },
1158
+ {
1159
+ base: 'o',
1160
+ 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',
1161
+ },
1162
+ { base: 'oi', letters: '\u01A3' },
1163
+ { base: 'ou', letters: '\u0223' },
1164
+ { base: 'oo', letters: '\uA74F' },
1165
+ {
1166
+ base: 'p',
1167
+ letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
1168
+ },
1169
+ { base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
1170
+ {
1171
+ base: 'r',
1172
+ letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
1173
+ },
1174
+ {
1175
+ base: 's',
1176
+ letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
1177
+ },
1178
+ {
1179
+ base: 't',
1180
+ letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
1181
+ },
1182
+ { base: 'tz', letters: '\uA729' },
1183
+ {
1184
+ base: 'u',
1185
+ 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',
1186
+ },
1187
+ { base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
1188
+ { base: 'vy', letters: '\uA761' },
1189
+ {
1190
+ base: 'w',
1191
+ letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
1192
+ },
1193
+ { base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
1194
+ {
1195
+ base: 'y',
1196
+ letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
1197
+ },
1198
+ {
1199
+ base: 'z',
1200
+ letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
1201
+ },
1202
+ ];
1354
1203
  /**
1355
- * Execution type describes the way how the block is executed
1204
+ * Map of letters from diacritic variant to diacritless variant
1205
+ * Contains lowercase and uppercase separatelly
1356
1206
  *
1357
- * @see https://github.com/webgptorg/promptbook#execution-type
1207
+ * > "á" => "a"
1208
+ * > "ě" => "e"
1209
+ * > "Ă" => "A"
1210
+ * > ...
1358
1211
  */
1359
- var ExecutionTypes = [
1360
- 'PROMPT_TEMPLATE',
1361
- 'SIMPLE_TEMPLATE',
1362
- 'SCRIPT',
1363
- 'PROMPT_DIALOG',
1364
- // <- [🥻] Insert here when making new command
1365
- ];
1212
+ var DIACRITIC_VARIANTS_LETTERS = {};
1213
+ // tslint:disable-next-line: prefer-for-of
1214
+ for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
1215
+ var letters = defaultDiacriticsRemovalMap[i].letters;
1216
+ // tslint:disable-next-line: prefer-for-of
1217
+ for (var j = 0; j < letters.length; j++) {
1218
+ DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
1219
+ }
1220
+ }
1221
+ // <- TODO: [🍓] Put to maker function to save execution time if not needed
1222
+ /*
1223
+ @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
1224
+ Licensed under the Apache License, Version 2.0 (the "License");
1225
+ you may not use this file except in compliance with the License.
1226
+ You may obtain a copy of the License at
1366
1227
 
1367
- /**
1368
- * Units of text measurement
1369
- */
1370
- var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
1371
- /**
1372
- * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
1373
- * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
1374
- * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
1375
- */
1228
+ http://www.apache.org/licenses/LICENSE-2.0
1229
+
1230
+ Unless required by applicable law or agreed to in writing, software
1231
+ distributed under the License is distributed on an "AS IS" BASIS,
1232
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1233
+ See the License for the specific language governing permissions and
1234
+ limitations under the License.
1235
+ */
1376
1236
 
1377
1237
  /**
1378
- * Parses one line of ul/ol to command
1379
- *
1380
- * @returns parsed command object
1381
- * @throws {PromptbookSyntaxError} if the command is invalid
1382
1238
  *
1383
- * @private within the promptbookStringToJson
1384
1239
  */
1385
- function parseCommand(listItem) {
1240
+ function removeDiacritics(input) {
1241
+ /*eslint no-control-regex: "off"*/
1242
+ return input.replace(/[^\u0000-\u007E]/g, function (a) {
1243
+ return DIACRITIC_VARIANTS_LETTERS[a] || a;
1244
+ });
1245
+ }
1246
+
1247
+ /* tslint:disable */
1248
+ function normalizeToKebabCase(sentence) {
1386
1249
  var e_1, _a;
1387
- if (listItem.includes('\n') || listItem.includes('\r')) {
1388
- throw new PromptbookSyntaxError('Command can not contain new line characters:');
1389
- }
1390
- var type = listItem.trim();
1391
- type = type.split('`').join('');
1392
- type = type.split('"').join('');
1393
- type = type.split("'").join('');
1394
- type = type.split('~').join('');
1395
- type = type.split('[').join('');
1396
- type = type.split(']').join('');
1397
- type = type.split('(').join('');
1398
- type = type.split(')').join('');
1399
- type = normalizeTo_SCREAMING_CASE(type);
1400
- type = type.split('DIALOGUE').join('DIALOG');
1401
- var listItemParts = listItem
1402
- .split(' ')
1403
- .map(function (part) { return part.trim(); })
1404
- .filter(function (item) { return item !== ''; })
1405
- .filter(function (item) { return !/^PTBK$/i.test(item); })
1406
- .filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
1407
- .map(removeMarkdownFormatting);
1408
- if (type.startsWith('URL') ||
1409
- type.startsWith('PTBK_URL') ||
1410
- type.startsWith('PTBKURL') ||
1411
- type.startsWith('PROMPTBOOK_URL') ||
1412
- type.startsWith('PROMPTBOOKURL') ||
1413
- type.startsWith('HTTPS')) {
1414
- if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
1415
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
1416
- }
1417
- var promptbookUrlString = listItemParts.pop();
1418
- var promptbookUrl = new URL(promptbookUrlString);
1419
- if (promptbookUrl.protocol !== 'https:') {
1420
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
1421
- }
1422
- if (promptbookUrl.hash !== '') {
1423
- throw new PromptbookSyntaxError(spaceTrim.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 ")));
1424
- }
1425
- return {
1426
- type: 'PROMPTBOOK_URL',
1427
- promptbookUrl: promptbookUrl,
1428
- };
1429
- }
1430
- else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
1431
- if (listItemParts.length !== 2) {
1432
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
1433
- }
1434
- var promptbookVersion = listItemParts.pop();
1435
- // TODO: Validate version
1436
- return {
1437
- type: 'PROMPTBOOK_VERSION',
1438
- promptbookVersion: promptbookVersion,
1439
- };
1440
- }
1441
- else if (type.startsWith('EXECUTE') ||
1442
- type.startsWith('EXEC') ||
1443
- type.startsWith('PROMPT_DIALOG') ||
1444
- type.startsWith('SIMPLE_TEMPLATE')) {
1445
- var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
1446
- if (executionTypes.length !== 1) {
1447
- throw new PromptbookSyntaxError(spaceTrim.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 "); }));
1448
- }
1449
- return {
1450
- type: 'EXECUTE',
1451
- executionType: executionTypes[0],
1452
- };
1453
- }
1454
- else if (type.startsWith('MODEL')) {
1455
- // TODO: Make this more elegant and dynamically
1456
- if (type.startsWith('MODEL_VARIANT')) {
1457
- if (type === 'MODEL_VARIANT_CHAT') {
1458
- return {
1459
- type: 'MODEL',
1460
- key: 'modelVariant',
1461
- value: 'CHAT',
1462
- };
1463
- }
1464
- else if (type === 'MODEL_VARIANT_COMPLETION') {
1465
- return {
1466
- type: 'MODEL',
1467
- key: 'modelVariant',
1468
- value: 'COMPLETION',
1469
- };
1470
- }
1471
- else {
1472
- throw new PromptbookSyntaxError(spaceTrim.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 "); }));
1473
- }
1474
- }
1475
- if (type.startsWith('MODEL_NAME')) {
1476
- return {
1477
- type: 'MODEL',
1478
- key: 'modelName',
1479
- value: listItemParts.pop(),
1480
- };
1481
- }
1482
- else {
1483
- throw new PromptbookSyntaxError(spaceTrim.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 "); }));
1484
- }
1485
- }
1486
- else if (type.startsWith('PARAM') ||
1487
- type.startsWith('INPUT_PARAM') ||
1488
- type.startsWith('OUTPUT_PARAM') ||
1489
- listItem.startsWith('{') ||
1490
- listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
1491
- var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
1492
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
1493
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1494
- }
1495
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1496
- var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
1497
- if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
1498
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
1499
- }
1500
- var isInput = type.startsWith('INPUT');
1501
- var isOutput = type.startsWith('OUTPUT');
1502
- if (listItem.startsWith('> {')) {
1503
- isInput = false;
1504
- isOutput = false;
1505
- }
1506
- return {
1507
- type: 'PARAMETER',
1508
- parameterName: parameterName,
1509
- parameterDescription: parameterDescription.trim() || null,
1510
- isInput: isInput,
1511
- isOutput: isOutput,
1512
- };
1513
- }
1514
- else if (type.startsWith('JOKER')) {
1515
- if (listItemParts.length !== 2) {
1516
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
1517
- }
1518
- var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
1519
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
1520
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1521
- }
1522
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1523
- var parameterName = parametersMatch.groups.parameterName;
1524
- return {
1525
- type: 'JOKER',
1526
- parameterName: parameterName,
1527
- };
1528
- }
1529
- else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
1530
- if (listItemParts.length !== 2) {
1531
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
1532
- }
1533
- var functionName = listItemParts.pop();
1534
- return {
1535
- type: 'POSTPROCESS',
1536
- functionName: functionName,
1537
- };
1538
- }
1539
- else if (type.startsWith('EXPECT_JSON')) {
1540
- return {
1541
- type: 'EXPECT_FORMAT',
1542
- format: 'JSON',
1543
- };
1544
- // [🥤]
1545
- }
1546
- else if (type.startsWith('EXPECT')) {
1547
- try {
1548
- listItemParts.shift();
1549
- var sign = void 0;
1550
- var signRaw = listItemParts.shift();
1551
- if (/^exact/i.test(signRaw)) {
1552
- sign = 'EXACTLY';
1553
- }
1554
- else if (/^min/i.test(signRaw)) {
1555
- sign = 'MINIMUM';
1556
- }
1557
- else if (/^max/i.test(signRaw)) {
1558
- sign = 'MAXIMUM';
1559
- }
1560
- else {
1561
- throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
1562
- }
1563
- var amountRaw = listItemParts.shift();
1564
- var amount = parseNumber(amountRaw);
1565
- if (amount < 0) {
1566
- throw new PromptbookSyntaxError('Amount must be positive number or zero');
1567
- }
1568
- if (amount !== Math.floor(amount)) {
1569
- throw new PromptbookSyntaxError('Amount must be whole number');
1250
+ sentence = removeDiacritics(sentence);
1251
+ var charType;
1252
+ var lastCharType = 'OTHER';
1253
+ var normalizedName = '';
1254
+ try {
1255
+ for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1256
+ var char = sentence_1_1.value;
1257
+ var normalizedChar = void 0;
1258
+ if (/^[a-z]$/.test(char)) {
1259
+ charType = 'LOWERCASE';
1260
+ normalizedChar = char;
1570
1261
  }
1571
- var unitRaw = listItemParts.shift();
1572
- var unit = undefined;
1573
- try {
1574
- 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()) {
1575
- var existingUnit = EXPECTATION_UNITS_1_1.value;
1576
- var existingUnitText = existingUnit;
1577
- existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
1578
- if (existingUnitText === 'CHARACTER') {
1579
- existingUnitText = 'CHAR';
1580
- }
1581
- if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
1582
- new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
1583
- if (unit !== undefined) {
1584
- throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
1585
- }
1586
- unit = existingUnit;
1587
- }
1588
- }
1262
+ else if (/^[A-Z]$/.test(char)) {
1263
+ charType = 'UPPERCASE';
1264
+ normalizedChar = char.toLowerCase();
1589
1265
  }
1590
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1591
- finally {
1592
- try {
1593
- if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
1594
- }
1595
- finally { if (e_1) throw e_1.error; }
1266
+ else if (/^[0-9]$/.test(char)) {
1267
+ charType = 'NUMBER';
1268
+ normalizedChar = char;
1596
1269
  }
1597
- if (unit === undefined) {
1598
- throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
1270
+ else if (/^\/$/.test(char)) {
1271
+ charType = 'SLASH';
1272
+ normalizedChar = char;
1599
1273
  }
1600
- return {
1601
- type: 'EXPECT_AMOUNT',
1602
- sign: sign,
1603
- unit: unit,
1604
- amount: amount,
1605
- };
1606
- }
1607
- catch (error) {
1608
- if (!(error instanceof Error)) {
1609
- throw error;
1274
+ else {
1275
+ charType = 'OTHER';
1276
+ normalizedChar = '-';
1610
1277
  }
1611
- throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
1278
+ if (charType !== lastCharType &&
1279
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1280
+ !(lastCharType === 'NUMBER') &&
1281
+ !(charType === 'NUMBER')) {
1282
+ normalizedName += '-';
1283
+ }
1284
+ normalizedName += normalizedChar;
1285
+ lastCharType = charType;
1612
1286
  }
1613
- /*
1614
- } else if (type.startsWith('__________________')) {
1615
- // <- [🥻] Insert here when making new command
1616
- */
1617
1287
  }
1618
- else {
1619
- throw new PromptbookSyntaxError(spaceTrim.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 ")));
1288
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1289
+ finally {
1290
+ try {
1291
+ if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
1292
+ }
1293
+ finally { if (e_1) throw e_1.error; }
1620
1294
  }
1295
+ normalizedName = normalizedName.split(/-+/g).join('-');
1296
+ normalizedName = normalizedName.split(/-?\/-?/g).join('/');
1297
+ normalizedName = normalizedName.replace(/^-/, '');
1298
+ normalizedName = normalizedName.replace(/-$/, '');
1299
+ return normalizedName;
1300
+ }
1301
+
1302
+ /**
1303
+ * Removes emojis from a string and fix whitespaces
1304
+ *
1305
+ * @param text with emojis
1306
+ * @returns text without emojis
1307
+ */
1308
+ function removeEmojis(text) {
1309
+ // Replace emojis (and also ZWJ sequence) with hyphens
1310
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
1311
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
1312
+ text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
1313
+ text = text.replace(/\p{Extended_Pictographic}/gu, '');
1314
+ return text;
1315
+ }
1316
+
1317
+ /**
1318
+ * Function normalizes title to name which can be used as identifier
1319
+ */
1320
+ function titleToName(value) {
1321
+ value = removeEmojis(value);
1322
+ value = normalizeToKebabCase(value);
1323
+ // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
1324
+ return value;
1621
1325
  }
1622
1326
 
1623
1327
  /**
@@ -1925,6 +1629,119 @@
1925
1629
  }
1926
1630
  }
1927
1631
 
1632
+ /* tslint:disable */
1633
+ function normalizeTo_camelCase(sentence, __firstLetterCapital) {
1634
+ var e_1, _a;
1635
+ if (__firstLetterCapital === void 0) { __firstLetterCapital = false; }
1636
+ var charType;
1637
+ var lastCharType = null;
1638
+ var normalizedName = '';
1639
+ try {
1640
+ for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1641
+ var char = sentence_1_1.value;
1642
+ var normalizedChar = void 0;
1643
+ if (/^[a-z]$/.test(char)) {
1644
+ charType = 'LOWERCASE';
1645
+ normalizedChar = char;
1646
+ }
1647
+ else if (/^[A-Z]$/.test(char)) {
1648
+ charType = 'UPPERCASE';
1649
+ normalizedChar = char.toLowerCase();
1650
+ }
1651
+ else if (/^[0-9]$/.test(char)) {
1652
+ charType = 'NUMBER';
1653
+ normalizedChar = char;
1654
+ }
1655
+ else {
1656
+ charType = 'OTHER';
1657
+ normalizedChar = '';
1658
+ }
1659
+ if (!lastCharType) {
1660
+ if (__firstLetterCapital) {
1661
+ normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
1662
+ }
1663
+ }
1664
+ else if (charType !== lastCharType &&
1665
+ !(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
1666
+ !(lastCharType === 'NUMBER') &&
1667
+ !(charType === 'NUMBER')) {
1668
+ normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
1669
+ }
1670
+ normalizedName += normalizedChar;
1671
+ lastCharType = charType;
1672
+ }
1673
+ }
1674
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1675
+ finally {
1676
+ try {
1677
+ if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
1678
+ }
1679
+ finally { if (e_1) throw e_1.error; }
1680
+ }
1681
+ return normalizedName;
1682
+ }
1683
+ /**
1684
+ * TODO: [🌺] Use some intermediate util splitWords
1685
+ */
1686
+
1687
+ /**
1688
+ * Creates a Mermaid graph based on the promptbook
1689
+ *
1690
+ * Note: The result is not wrapped in a Markdown code block
1691
+ */
1692
+ function renderPromptbookMermaid(promptbookJson, options) {
1693
+ var _a = (options || {}).linkPromptTemplate, linkPromptTemplate = _a === void 0 ? function () { return null; } : _a;
1694
+ var parameterNameToTemplateName = function (parameterName) {
1695
+ var parameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
1696
+ if (!parameter) {
1697
+ throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
1698
+ }
1699
+ if (parameter.isInput) {
1700
+ return 'input';
1701
+ }
1702
+ var template = promptbookJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
1703
+ if (!template) {
1704
+ throw new Error("Could not find template for {".concat(parameterName, "}"));
1705
+ }
1706
+ return normalizeTo_camelCase('template-' + titleToName(template.title));
1707
+ };
1708
+ var promptbookMermaid = spaceTrim.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
1709
+ .flatMap(function (_a) {
1710
+ var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
1711
+ return __spreadArray([
1712
+ "".concat(parameterNameToTemplateName(resultingParameterName), "(\"").concat(title, "\")")
1713
+ ], __read(dependentParameterNames.map(function (dependentParameterName) {
1714
+ return "".concat(parameterNameToTemplateName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName(resultingParameterName));
1715
+ })), false);
1716
+ })
1717
+ .join('\n')), "\n\n ").concat(block(promptbookJson.parameters
1718
+ .filter(function (_a) {
1719
+ var isOutput = _a.isOutput;
1720
+ return isOutput;
1721
+ })
1722
+ .map(function (_a) {
1723
+ var name = _a.name;
1724
+ return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
1725
+ })
1726
+ .join('\n')), "\n output((Output)):::output\n\n ").concat(block(promptbookJson.promptTemplates
1727
+ .map(function (promptTemplate) {
1728
+ var link = linkPromptTemplate(promptTemplate);
1729
+ if (link === null) {
1730
+ return '';
1731
+ }
1732
+ var href = link.href, title = link.title;
1733
+ var templateName = parameterNameToTemplateName(promptTemplate.resultingParameterName);
1734
+ return "click ".concat(templateName, " href \"").concat(href, "\" \"").concat(title, "\";");
1735
+ })
1736
+ .filter(function (line) { return line !== ''; })
1737
+ .join('\n')), "\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
1738
+ return promptbookMermaid;
1739
+ }
1740
+ /**
1741
+ * TODO: Maybe use some Mermaid library instead of string templating
1742
+ * TODO: [🕌] When more than 2 functionalities, split into separate functions
1743
+ */
1744
+
1928
1745
  /**
1929
1746
  * Prettyfies Promptbook string and adds Mermaid graph
1930
1747
  */
@@ -2139,6 +1956,20 @@
2139
1956
  * TODO: Escape all
2140
1957
  */
2141
1958
 
1959
+ /**
1960
+ * This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
1961
+ */
1962
+ var PromptbookLogicError = /** @class */ (function (_super) {
1963
+ __extends(PromptbookLogicError, _super);
1964
+ function PromptbookLogicError(message) {
1965
+ var _this = _super.call(this, message) || this;
1966
+ _this.name = 'PromptbookLogicError';
1967
+ Object.setPrototypeOf(_this, PromptbookLogicError.prototype);
1968
+ return _this;
1969
+ }
1970
+ return PromptbookLogicError;
1971
+ }(Error));
1972
+
2142
1973
  /**
2143
1974
  * Tests if given string is valid URL.
2144
1975
  *
@@ -2337,32 +2168,107 @@
2337
2168
  while (unresovedTemplates.length > 0) {
2338
2169
  _loop_2();
2339
2170
  }
2340
- return promptbook;
2341
- }
2171
+ return promptbook;
2172
+ }
2173
+ /**
2174
+ * TODO: [🧠] Work with promptbookVersion
2175
+ * TODO: Use here some json-schema, Zod or something similar and change it to:
2176
+ * > /**
2177
+ * > * Validates PromptbookJson if it is logically valid.
2178
+ * > *
2179
+ * > * It checks:
2180
+ * > * - it has a valid structure
2181
+ * > * - ...
2182
+ * > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
2183
+ */
2184
+
2185
+ /**
2186
+ * This error occurs when some expectation is not met in the execution of the pipeline
2187
+ *
2188
+ * @private Always catched and rethrown as `PromptbookExecutionError`
2189
+ * Note: This is a kindof subtype of PromptbookExecutionError
2190
+ */
2191
+ var ExpectError = /** @class */ (function (_super) {
2192
+ __extends(ExpectError, _super);
2193
+ function ExpectError(message) {
2194
+ var _this = _super.call(this, message) || this;
2195
+ _this.name = 'ExpectError';
2196
+ Object.setPrototypeOf(_this, ExpectError.prototype);
2197
+ return _this;
2198
+ }
2199
+ return ExpectError;
2200
+ }(Error));
2201
+
2202
+ /**
2203
+ * This error indicates errors during the execution of the promptbook
2204
+ */
2205
+ var PromptbookExecutionError = /** @class */ (function (_super) {
2206
+ __extends(PromptbookExecutionError, _super);
2207
+ function PromptbookExecutionError(message) {
2208
+ var _this = _super.call(this, message) || this;
2209
+ _this.name = 'PromptbookExecutionError';
2210
+ Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
2211
+ return _this;
2212
+ }
2213
+ return PromptbookExecutionError;
2214
+ }(Error));
2215
+
2216
+ /**
2217
+ * This error indicates that the promptbook library cannot be propperly loaded
2218
+ */
2219
+ var PromptbookLibraryError = /** @class */ (function (_super) {
2220
+ __extends(PromptbookLibraryError, _super);
2221
+ function PromptbookLibraryError(message) {
2222
+ var _this = _super.call(this, message) || this;
2223
+ _this.name = 'PromptbookLibraryError';
2224
+ Object.setPrototypeOf(_this, PromptbookLibraryError.prototype);
2225
+ return _this;
2226
+ }
2227
+ return PromptbookLibraryError;
2228
+ }(Error));
2229
+
2230
+ /**
2231
+ * This error indicates that promptbook not found in the library
2232
+ */
2233
+ var PromptbookNotFoundError = /** @class */ (function (_super) {
2234
+ __extends(PromptbookNotFoundError, _super);
2235
+ function PromptbookNotFoundError(message) {
2236
+ var _this = _super.call(this, message) || this;
2237
+ _this.name = 'PromptbookNotFoundError';
2238
+ Object.setPrototypeOf(_this, PromptbookNotFoundError.prototype);
2239
+ return _this;
2240
+ }
2241
+ return PromptbookNotFoundError;
2242
+ }(Error));
2243
+
2342
2244
  /**
2343
- * TODO: [🧠] Work with promptbookVersion
2344
- * TODO: Use here some json-schema, Zod or something similar and change it to:
2345
- * > /**
2346
- * > * Validates PromptbookJson if it is logically valid.
2347
- * > *
2348
- * > * It checks:
2349
- * > * - it has a valid structure
2350
- * > * - ...
2351
- * > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
2245
+ * This error indicates errors in referencing promptbooks between each other
2352
2246
  */
2247
+ var PromptbookReferenceError = /** @class */ (function (_super) {
2248
+ __extends(PromptbookReferenceError, _super);
2249
+ function PromptbookReferenceError(message) {
2250
+ var _this = _super.call(this, message) || this;
2251
+ _this.name = 'PromptbookReferenceError';
2252
+ Object.setPrototypeOf(_this, PromptbookReferenceError.prototype);
2253
+ return _this;
2254
+ }
2255
+ return PromptbookReferenceError;
2256
+ }(Error));
2353
2257
 
2354
2258
  /**
2355
- * This error indicates errors during the execution of the promptbook
2259
+ * This error occurs during the parameter replacement in the template
2260
+ *
2261
+ * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
2356
2262
  */
2357
- var PromptbookExecutionError = /** @class */ (function (_super) {
2358
- __extends(PromptbookExecutionError, _super);
2359
- function PromptbookExecutionError(message) {
2263
+ var TemplateError = /** @class */ (function (_super) {
2264
+ __extends(TemplateError, _super);
2265
+ function TemplateError(message) {
2360
2266
  var _this = _super.call(this, message) || this;
2361
- _this.name = 'PromptbookExecutionError';
2362
- Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
2267
+ _this.name = 'TemplateError';
2268
+ Object.setPrototypeOf(_this, TemplateError.prototype);
2363
2269
  return _this;
2364
2270
  }
2365
- return PromptbookExecutionError;
2271
+ return TemplateError;
2366
2272
  }(Error));
2367
2273
 
2368
2274
  /**
@@ -2391,21 +2297,97 @@
2391
2297
  */
2392
2298
 
2393
2299
  /**
2394
- * This error occurs when some expectation is not met in the execution of the pipeline
2395
- *
2396
- * @private Always catched and rethrown as `PromptbookExecutionError`
2397
- * Note: This is a kindof subtype of PromptbookExecutionError
2300
+ * Function isValidJsonString will tell you if the string is valid JSON or not
2398
2301
  */
2399
- var ExpectError = /** @class */ (function (_super) {
2400
- __extends(ExpectError, _super);
2401
- function ExpectError(message) {
2402
- var _this = _super.call(this, message) || this;
2403
- _this.name = 'ExpectError';
2404
- Object.setPrototypeOf(_this, ExpectError.prototype);
2405
- return _this;
2302
+ function isValidJsonString(value) {
2303
+ try {
2304
+ JSON.parse(value);
2305
+ return true;
2406
2306
  }
2407
- return ExpectError;
2408
- }(Error));
2307
+ catch (error) {
2308
+ if (!(error instanceof Error)) {
2309
+ throw error;
2310
+ }
2311
+ if (error.message.includes('Unexpected token')) {
2312
+ return false;
2313
+ }
2314
+ return false;
2315
+ }
2316
+ }
2317
+
2318
+ /**
2319
+ * Counts number of characters in the text
2320
+ */
2321
+ function countCharacters(text) {
2322
+ // Remove null characters
2323
+ text = text.replace(/\0/g, '');
2324
+ // Replace emojis (and also ZWJ sequence) with hyphens
2325
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
2326
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
2327
+ text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
2328
+ return text.length;
2329
+ }
2330
+
2331
+ /**
2332
+ * Counts number of lines in the text
2333
+ */
2334
+ function countLines(text) {
2335
+ if (text === '') {
2336
+ return 0;
2337
+ }
2338
+ return text.split('\n').length;
2339
+ }
2340
+
2341
+ /**
2342
+ * Counts number of pages in the text
2343
+ */
2344
+ function countPages(text) {
2345
+ var sentencesPerPage = 5; // Assuming each page has 5 sentences
2346
+ var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
2347
+ var pageCount = Math.ceil(sentences.length / sentencesPerPage);
2348
+ return pageCount;
2349
+ }
2350
+
2351
+ /**
2352
+ * Counts number of paragraphs in the text
2353
+ */
2354
+ function countParagraphs(text) {
2355
+ return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
2356
+ }
2357
+
2358
+ /**
2359
+ * Split text into sentences
2360
+ */
2361
+ function splitIntoSentences(text) {
2362
+ return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
2363
+ }
2364
+ /**
2365
+ * Counts number of sentences in the text
2366
+ */
2367
+ function countSentences(text) {
2368
+ return splitIntoSentences(text).length;
2369
+ }
2370
+
2371
+ /**
2372
+ * Counts number of words in the text
2373
+ */
2374
+ function countWords(text) {
2375
+ text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
2376
+ text = removeDiacritics(text);
2377
+ return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
2378
+ }
2379
+
2380
+ /**
2381
+ * Index of all counter functions
2382
+ */
2383
+ var CountUtils = {
2384
+ CHARACTERS: countCharacters,
2385
+ WORDS: countWords,
2386
+ SENTENCES: countSentences,
2387
+ PARAGRAPHS: countParagraphs,
2388
+ LINES: countLines,
2389
+ PAGES: countPages,
2390
+ };
2409
2391
 
2410
2392
  /**
2411
2393
  * Function checkExpectations will check if the expectations on given value are met
@@ -2464,6 +2446,66 @@
2464
2446
  * TODO: [💝] Unite object for expecting amount and format
2465
2447
  */
2466
2448
 
2449
+ /**
2450
+ * Replaces parameters in template with values from parameters object
2451
+ *
2452
+ * @param template the template with parameters in {curly} braces
2453
+ * @param parameters the object with parameters
2454
+ * @returns the template with replaced parameters
2455
+ * @throws {TemplateError} if parameter is not defined, not closed, or not opened
2456
+ *
2457
+ * @private within the createPromptbookExecutor
2458
+ */
2459
+ function replaceParameters(template, parameters) {
2460
+ var replacedTemplate = template;
2461
+ var match;
2462
+ var loopLimit = LOOP_LIMIT;
2463
+ var _loop_1 = function () {
2464
+ if (loopLimit-- < 0) {
2465
+ throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
2466
+ }
2467
+ var precol = match.groups.precol;
2468
+ var parameterName = match.groups.parameterName;
2469
+ if (parameterName === '') {
2470
+ return "continue";
2471
+ }
2472
+ if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
2473
+ throw new TemplateError('Parameter is already opened or not closed');
2474
+ }
2475
+ if (parameters[parameterName] === undefined) {
2476
+ throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
2477
+ }
2478
+ var parameterValue = parameters[parameterName];
2479
+ if (parameterValue === undefined) {
2480
+ throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
2481
+ }
2482
+ parameterValue = parameterValue.toString();
2483
+ if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
2484
+ parameterValue = parameterValue
2485
+ .split('\n')
2486
+ .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
2487
+ .join('\n');
2488
+ }
2489
+ replacedTemplate =
2490
+ replacedTemplate.substring(0, match.index + precol.length) +
2491
+ parameterValue +
2492
+ replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
2493
+ };
2494
+ while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
2495
+ .exec(replacedTemplate))) {
2496
+ _loop_1();
2497
+ }
2498
+ // [💫] Check if there are parameters that are not closed properly
2499
+ if (/{\w+$/.test(replacedTemplate)) {
2500
+ throw new TemplateError('Parameter is not closed');
2501
+ }
2502
+ // [💫] Check if there are parameters that are not opened properly
2503
+ if (/^\w+}/.test(replacedTemplate)) {
2504
+ throw new TemplateError('Parameter is not opened');
2505
+ }
2506
+ return replacedTemplate;
2507
+ }
2508
+
2467
2509
  /**
2468
2510
  * Creates executor function from promptbook and execution tools.
2469
2511
  *
@@ -3175,20 +3217,6 @@
3175
3217
  return SimplePromptInterfaceTools;
3176
3218
  }());
3177
3219
 
3178
- /**
3179
- * This error indicates that the promptbook library cannot be propperly loaded
3180
- */
3181
- var PromptbookLibraryError = /** @class */ (function (_super) {
3182
- __extends(PromptbookLibraryError, _super);
3183
- function PromptbookLibraryError(message) {
3184
- var _this = _super.call(this, message) || this;
3185
- _this.name = 'PromptbookLibraryError';
3186
- Object.setPrototypeOf(_this, PromptbookLibraryError.prototype);
3187
- return _this;
3188
- }
3189
- return PromptbookLibraryError;
3190
- }(Error));
3191
-
3192
3220
  /**
3193
3221
  * Detects if the code is running in a browser environment in main thread (Not in a web worker)
3194
3222
  */
@@ -3219,34 +3247,6 @@
3219
3247
  return value;
3220
3248
  }
3221
3249
 
3222
- /**
3223
- * This error indicates that promptbook not found in the library
3224
- */
3225
- var PromptbookNotFoundError = /** @class */ (function (_super) {
3226
- __extends(PromptbookNotFoundError, _super);
3227
- function PromptbookNotFoundError(message) {
3228
- var _this = _super.call(this, message) || this;
3229
- _this.name = 'PromptbookNotFoundError';
3230
- Object.setPrototypeOf(_this, PromptbookNotFoundError.prototype);
3231
- return _this;
3232
- }
3233
- return PromptbookNotFoundError;
3234
- }(Error));
3235
-
3236
- /**
3237
- * This error indicates errors in referencing promptbooks between each other
3238
- */
3239
- var PromptbookReferenceError = /** @class */ (function (_super) {
3240
- __extends(PromptbookReferenceError, _super);
3241
- function PromptbookReferenceError(message) {
3242
- var _this = _super.call(this, message) || this;
3243
- _this.name = 'PromptbookReferenceError';
3244
- Object.setPrototypeOf(_this, PromptbookReferenceError.prototype);
3245
- return _this;
3246
- }
3247
- return PromptbookReferenceError;
3248
- }(Error));
3249
-
3250
3250
  /**
3251
3251
  * Library of promptbooks that groups together promptbooks for an application.
3252
3252
  * This implementation is a very thin wrapper around the Array / Map of promptbooks.
@@ -4119,10 +4119,19 @@
4119
4119
  exports.CallbackInterfaceTools = CallbackInterfaceTools;
4120
4120
  exports.ExecutionReportStringOptionsDefaults = ExecutionReportStringOptionsDefaults;
4121
4121
  exports.ExecutionTypes = ExecutionTypes;
4122
+ exports.ExpectError = ExpectError;
4122
4123
  exports.MultipleLlmExecutionTools = MultipleLlmExecutionTools;
4123
4124
  exports.PROMPTBOOK_VERSION = PROMPTBOOK_VERSION;
4125
+ exports.PromptbookExecutionError = PromptbookExecutionError;
4126
+ exports.PromptbookLibraryError = PromptbookLibraryError;
4127
+ exports.PromptbookLogicError = PromptbookLogicError;
4128
+ exports.PromptbookNotFoundError = PromptbookNotFoundError;
4129
+ exports.PromptbookReferenceError = PromptbookReferenceError;
4130
+ exports.PromptbookSyntaxError = PromptbookSyntaxError;
4124
4131
  exports.SimplePromptInterfaceTools = SimplePromptInterfaceTools;
4125
4132
  exports.SimplePromptbookLibrary = SimplePromptbookLibrary;
4133
+ exports.TemplateError = TemplateError;
4134
+ exports.UnexpectedError = UnexpectedError;
4126
4135
  exports.assertsExecutionSuccessful = assertsExecutionSuccessful;
4127
4136
  exports.checkExpectations = checkExpectations;
4128
4137
  exports.createPromptbookExecutor = createPromptbookExecutor;