@promptbook/cli 0.52.0 → 0.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/esm/index.es.js +631 -661
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
  4. package/esm/typings/conversion/prettify/renderPromptbookMermaid.d.ts +2 -1
  5. package/esm/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +3 -3
  6. package/esm/typings/conversion/utils/extractVariables.d.ts +2 -1
  7. package/esm/typings/conversion/validation/_importPromptbook.d.ts +2 -2
  8. package/esm/typings/execution/LlmExecutionTools.d.ts +4 -2
  9. package/esm/typings/execution/PromptResult.d.ts +5 -1
  10. package/esm/typings/execution/ScriptExecutionTools.d.ts +2 -1
  11. package/esm/typings/execution/UserInterfaceTools.d.ts +2 -1
  12. package/esm/typings/execution/createPromptbookExecutor.d.ts +3 -3
  13. package/esm/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +4 -2
  14. package/esm/typings/execution/plugins/llm-execution-tools/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  15. package/esm/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -2
  16. package/esm/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +2 -1
  17. package/esm/typings/execution/plugins/llm-execution-tools/mocked/MockedEchoLlmExecutionTools.d.ts +4 -2
  18. package/esm/typings/execution/plugins/llm-execution-tools/mocked/MockedFackedLlmExecutionTools.d.ts +4 -2
  19. package/esm/typings/execution/plugins/llm-execution-tools/mocked/fakeTextToExpectations.d.ts +1 -1
  20. package/esm/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools.d.ts +4 -2
  21. package/esm/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionToolsOptions.d.ts +2 -1
  22. package/esm/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +4 -2
  23. package/esm/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
  24. package/esm/typings/execution/plugins/llm-execution-tools/openai/openai-models.d.ts +1 -1
  25. package/esm/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +4 -2
  26. package/esm/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionToolsOptions.d.ts +2 -1
  27. package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Progress.d.ts +1 -1
  28. package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Response.d.ts +1 -1
  29. package/esm/typings/execution/plugins/llm-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +2 -1
  30. package/esm/typings/execution/plugins/llm-execution-tools/remote/startRemoteServer.d.ts +1 -1
  31. package/esm/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +3 -2
  32. package/esm/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +3 -2
  33. package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +3 -2
  34. package/esm/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -2
  35. package/esm/typings/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +1 -1
  36. package/esm/typings/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +1 -1
  37. package/esm/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +2 -2
  38. package/esm/typings/execution/translation/automatic-translate/translateMessages.d.ts +2 -2
  39. package/esm/typings/execution/utils/replaceParameters.d.ts +2 -2
  40. package/esm/typings/library/SimplePromptbookLibrary.d.ts +1 -1
  41. package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +2 -2
  42. package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +2 -2
  43. package/esm/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +2 -1
  44. package/esm/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +2 -2
  45. package/esm/typings/library/constructors/createPromptbookSublibrary.d.ts +1 -1
  46. package/esm/typings/types/Command.d.ts +5 -2
  47. package/esm/typings/types/Prompt.d.ts +4 -1
  48. package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +8 -1
  49. package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +2 -1
  50. package/esm/typings/types/TaskProgress.d.ts +2 -1
  51. package/esm/typings/types/execution-report/ExecutionReportJson.d.ts +2 -1
  52. package/esm/typings/types/execution-report/countWorkingDuration.d.ts +1 -1
  53. package/esm/typings/utils/emojis.d.ts +1 -1
  54. package/esm/typings/utils/expectation-counters/index.d.ts +2 -1
  55. package/esm/typings/utils/extractParameters.d.ts +2 -1
  56. package/esm/typings/utils/markdown/addAutoGeneratedSection.d.ts +2 -1
  57. package/esm/typings/utils/markdown/createMarkdownChart.d.ts +2 -2
  58. package/esm/typings/utils/markdown/createMarkdownTable.d.ts +2 -1
  59. package/esm/typings/utils/markdown/escapeMarkdownBlock.d.ts +1 -1
  60. package/esm/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +2 -1
  61. package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
  62. package/esm/typings/utils/markdown/removeContentComments.d.ts +2 -1
  63. package/esm/typings/utils/markdown/removeMarkdownFormatting.d.ts +1 -1
  64. package/esm/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +1 -1
  65. package/esm/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +1 -1
  66. package/esm/typings/utils/normalization/isValidKeyword.d.ts +1 -1
  67. package/esm/typings/utils/normalization/parseKeywords.d.ts +1 -1
  68. package/esm/typings/utils/normalization/parseKeywordsFromString.d.ts +1 -1
  69. package/esm/typings/utils/normalization/searchKeywords.d.ts +1 -1
  70. package/esm/typings/utils/postprocessing/extractBlock.d.ts +1 -1
  71. package/package.json +2 -2
  72. package/umd/index.umd.js +631 -661
  73. package/umd/index.umd.js.map +1 -1
  74. package/umd/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
  75. package/umd/typings/conversion/prettify/renderPromptbookMermaid.d.ts +2 -1
  76. package/umd/typings/conversion/utils/extractParametersFromPromptTemplate.d.ts +3 -3
  77. package/umd/typings/conversion/utils/extractVariables.d.ts +2 -1
  78. package/umd/typings/conversion/validation/_importPromptbook.d.ts +2 -2
  79. package/umd/typings/execution/LlmExecutionTools.d.ts +4 -2
  80. package/umd/typings/execution/PromptResult.d.ts +5 -1
  81. package/umd/typings/execution/ScriptExecutionTools.d.ts +2 -1
  82. package/umd/typings/execution/UserInterfaceTools.d.ts +2 -1
  83. package/umd/typings/execution/createPromptbookExecutor.d.ts +3 -3
  84. package/umd/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +4 -2
  85. package/umd/typings/execution/plugins/llm-execution-tools/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  86. package/umd/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -2
  87. package/umd/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +2 -1
  88. package/umd/typings/execution/plugins/llm-execution-tools/mocked/MockedEchoLlmExecutionTools.d.ts +4 -2
  89. package/umd/typings/execution/plugins/llm-execution-tools/mocked/MockedFackedLlmExecutionTools.d.ts +4 -2
  90. package/umd/typings/execution/plugins/llm-execution-tools/mocked/fakeTextToExpectations.d.ts +1 -1
  91. package/umd/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools.d.ts +4 -2
  92. package/umd/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionToolsOptions.d.ts +2 -1
  93. package/umd/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +4 -2
  94. package/umd/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +1 -1
  95. package/umd/typings/execution/plugins/llm-execution-tools/openai/openai-models.d.ts +1 -1
  96. package/umd/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +4 -2
  97. package/umd/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionToolsOptions.d.ts +2 -1
  98. package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Progress.d.ts +1 -1
  99. package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/Promptbook_Server_Response.d.ts +1 -1
  100. package/umd/typings/execution/plugins/llm-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +2 -1
  101. package/umd/typings/execution/plugins/llm-execution-tools/remote/startRemoteServer.d.ts +1 -1
  102. package/umd/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +3 -2
  103. package/umd/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +3 -2
  104. package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +3 -2
  105. package/umd/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -2
  106. package/umd/typings/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +1 -1
  107. package/umd/typings/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +1 -1
  108. package/umd/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +2 -2
  109. package/umd/typings/execution/translation/automatic-translate/translateMessages.d.ts +2 -2
  110. package/umd/typings/execution/utils/replaceParameters.d.ts +2 -2
  111. package/umd/typings/library/SimplePromptbookLibrary.d.ts +1 -1
  112. package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +2 -2
  113. package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +2 -2
  114. package/umd/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +2 -1
  115. package/umd/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +2 -2
  116. package/umd/typings/library/constructors/createPromptbookSublibrary.d.ts +1 -1
  117. package/umd/typings/types/Command.d.ts +5 -2
  118. package/umd/typings/types/Prompt.d.ts +4 -1
  119. package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +8 -1
  120. package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +2 -1
  121. package/umd/typings/types/TaskProgress.d.ts +2 -1
  122. package/umd/typings/types/execution-report/ExecutionReportJson.d.ts +2 -1
  123. package/umd/typings/types/execution-report/countWorkingDuration.d.ts +1 -1
  124. package/umd/typings/utils/emojis.d.ts +1 -1
  125. package/umd/typings/utils/expectation-counters/index.d.ts +2 -1
  126. package/umd/typings/utils/extractParameters.d.ts +2 -1
  127. package/umd/typings/utils/markdown/addAutoGeneratedSection.d.ts +2 -1
  128. package/umd/typings/utils/markdown/createMarkdownChart.d.ts +2 -2
  129. package/umd/typings/utils/markdown/createMarkdownTable.d.ts +2 -1
  130. package/umd/typings/utils/markdown/escapeMarkdownBlock.d.ts +1 -1
  131. package/umd/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +2 -1
  132. package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
  133. package/umd/typings/utils/markdown/removeContentComments.d.ts +2 -1
  134. package/umd/typings/utils/markdown/removeMarkdownFormatting.d.ts +1 -1
  135. package/umd/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +1 -1
  136. package/umd/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +1 -1
  137. package/umd/typings/utils/normalization/isValidKeyword.d.ts +1 -1
  138. package/umd/typings/utils/normalization/parseKeywords.d.ts +1 -1
  139. package/umd/typings/utils/normalization/parseKeywordsFromString.d.ts +1 -1
  140. package/umd/typings/utils/normalization/searchKeywords.d.ts +1 -1
  141. package/umd/typings/utils/postprocessing/extractBlock.d.ts +1 -1
package/esm/index.es.js CHANGED
@@ -142,7 +142,7 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
142
142
  /**
143
143
  * The version of the Promptbook library
144
144
  */
145
- var PROMPTBOOK_VERSION = '0.52.0-33';
145
+ var PROMPTBOOK_VERSION = '0.52.0';
146
146
 
147
147
  /**
148
148
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -586,88 +586,108 @@ function extractParametersFromPromptTemplate(promptTemplate) {
586
586
  * TODO: [🔣] If script require contentLanguage
587
587
  */
588
588
 
589
+ /* tslint:disable */
590
+ /*
591
+ TODO: Tests
592
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
593
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
594
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
595
+ expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
596
+ */
597
+ function normalizeTo_SCREAMING_CASE(sentence) {
598
+ var e_1, _a;
599
+ var charType;
600
+ var lastCharType = 'OTHER';
601
+ var normalizedName = '';
602
+ try {
603
+ for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
604
+ var char = sentence_1_1.value;
605
+ var normalizedChar = void 0;
606
+ if (/^[a-z]$/.test(char)) {
607
+ charType = 'LOWERCASE';
608
+ normalizedChar = char.toUpperCase();
609
+ }
610
+ else if (/^[A-Z]$/.test(char)) {
611
+ charType = 'UPPERCASE';
612
+ normalizedChar = char;
613
+ }
614
+ else if (/^[0-9]$/.test(char)) {
615
+ charType = 'NUMBER';
616
+ normalizedChar = char;
617
+ }
618
+ else if (/^\/$/.test(char)) {
619
+ charType = 'SLASH';
620
+ normalizedChar = char;
621
+ }
622
+ else {
623
+ charType = 'OTHER';
624
+ normalizedChar = '_';
625
+ }
626
+ if (charType !== lastCharType &&
627
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
628
+ !(lastCharType === 'NUMBER') &&
629
+ !(charType === 'NUMBER')) {
630
+ normalizedName += '_';
631
+ }
632
+ normalizedName += normalizedChar;
633
+ lastCharType = charType;
634
+ }
635
+ }
636
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
637
+ finally {
638
+ try {
639
+ if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
640
+ }
641
+ finally { if (e_1) throw e_1.error; }
642
+ }
643
+ normalizedName = normalizedName.replace(/_+/g, '_');
644
+ normalizedName = normalizedName.replace(/_?\/_?/g, '/');
645
+ normalizedName = normalizedName.replace(/^_/, '');
646
+ normalizedName = normalizedName.replace(/_$/, '');
647
+ return normalizedName;
648
+ }
589
649
  /**
590
- * Removes emojis from a string and fix whitespaces
650
+ * TODO: [🌺] Use some intermediate util splitWords
651
+ */
652
+
653
+ /**
654
+ * Execution type describes the way how the block is executed
591
655
  *
592
- * @param text with emojis
593
- * @returns text without emojis
656
+ * @see https://github.com/webgptorg/promptbook#execution-type
594
657
  */
595
- function removeEmojis(text) {
596
- // Replace emojis (and also ZWJ sequence) with hyphens
597
- text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
598
- text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
599
- text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
600
- text = text.replace(/\p{Extended_Pictographic}/gu, '');
601
- return text;
602
- }
658
+ var ExecutionTypes = [
659
+ 'PROMPT_TEMPLATE',
660
+ 'SIMPLE_TEMPLATE',
661
+ 'SCRIPT',
662
+ 'PROMPT_DIALOG',
663
+ // <- [🥻] Insert here when making new command
664
+ ];
603
665
 
604
666
  /**
605
- * Function normalizes title to name which can be used as identifier
667
+ * Units of text measurement
668
+ */
669
+ var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
670
+ /**
671
+ * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
672
+ * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
673
+ * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
606
674
  */
607
- function titleToName(value) {
608
- value = removeEmojis(value);
609
- value = normalizeToKebabCase(value);
610
- // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
611
- return value;
612
- }
613
675
 
614
676
  /**
615
- * Creates a Mermaid graph based on the promptbook
677
+ * Removes Markdown formatting tags from a string.
616
678
  *
617
- * Note: The result is not wrapped in a Markdown code block
679
+ * @param {string} str - The string to remove Markdown tags from.
680
+ * @returns {string} The input string with all Markdown tags removed.
618
681
  */
619
- function renderPromptbookMermaid(promptbookJson, options) {
620
- var _a = (options || {}).linkPromptTemplate, linkPromptTemplate = _a === void 0 ? function () { return null; } : _a;
621
- var parameterNameToTemplateName = function (parameterName) {
622
- var parameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
623
- if (!parameter) {
624
- throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
625
- }
626
- if (parameter.isInput) {
627
- return 'input';
628
- }
629
- var template = promptbookJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
630
- if (!template) {
631
- throw new Error("Could not find template for {".concat(parameterName, "}"));
632
- }
633
- return normalizeTo_camelCase('template-' + titleToName(template.title));
634
- };
635
- var promptbookMermaid = spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(promptbookJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson.promptTemplates
636
- .flatMap(function (_a) {
637
- var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
638
- return __spreadArray([
639
- "".concat(parameterNameToTemplateName(resultingParameterName), "(\"").concat(title, "\")")
640
- ], __read(dependentParameterNames.map(function (dependentParameterName) {
641
- return "".concat(parameterNameToTemplateName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName(resultingParameterName));
642
- })), false);
643
- })
644
- .join('\n')), "\n\n ").concat(block(promptbookJson.parameters
645
- .filter(function (_a) {
646
- var isOutput = _a.isOutput;
647
- return isOutput;
648
- })
649
- .map(function (_a) {
650
- var name = _a.name;
651
- return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
652
- })
653
- .join('\n')), "\n output((Output)):::output\n\n ").concat(block(promptbookJson.promptTemplates
654
- .map(function (promptTemplate) {
655
- var link = linkPromptTemplate(promptTemplate);
656
- if (link === null) {
657
- return '';
658
- }
659
- var href = link.href, title = link.title;
660
- var templateName = parameterNameToTemplateName(promptTemplate.resultingParameterName);
661
- return "click ".concat(templateName, " href \"").concat(href, "\" \"").concat(title, "\";");
662
- })
663
- .filter(function (line) { return line !== ''; })
664
- .join('\n')), "\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
665
- return promptbookMermaid;
682
+ function removeMarkdownFormatting(str) {
683
+ // Remove bold formatting
684
+ str = str.replace(/\*\*(.*?)\*\*/g, '$1');
685
+ // Remove italic formatting
686
+ str = str.replace(/\*(.*?)\*/g, '$1');
687
+ // Remove code formatting
688
+ str = str.replace(/`(.*?)`/g, '$1');
689
+ return str;
666
690
  }
667
- /**
668
- * TODO: Maybe use some Mermaid library instead of string templating
669
- * TODO: [🕌] When more than 2 functionalities, split into separate functions
670
- */
671
691
 
672
692
  /**
673
693
  * Function parseNumber will parse number from string
@@ -737,127 +757,343 @@ function parseNumber(value) {
737
757
  */
738
758
 
739
759
  /**
740
- * This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
741
- */
742
- /** @class */ ((function (_super) {
743
- __extends(PromptbookLogicError, _super);
744
- function PromptbookLogicError(message) {
745
- var _this = _super.call(this, message) || this;
746
- _this.name = 'PromptbookLogicError';
747
- Object.setPrototypeOf(_this, PromptbookLogicError.prototype);
748
- return _this;
749
- }
750
- return PromptbookLogicError;
751
- })(Error));
752
-
753
- /**
754
- * This error occurs during the parameter replacement in the template
760
+ * Parses one line of ul/ol to command
761
+ *
762
+ * @returns parsed command object
763
+ * @throws {PromptbookSyntaxError} if the command is invalid
755
764
  *
756
- * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
765
+ * @private within the promptbookStringToJson
757
766
  */
758
- /** @class */ ((function (_super) {
759
- __extends(TemplateError, _super);
760
- function TemplateError(message) {
761
- var _this = _super.call(this, message) || this;
762
- _this.name = 'TemplateError';
763
- Object.setPrototypeOf(_this, TemplateError.prototype);
764
- return _this;
767
+ function parseCommand(listItem) {
768
+ var e_1, _a;
769
+ if (listItem.includes('\n') || listItem.includes('\r')) {
770
+ throw new PromptbookSyntaxError('Command can not contain new line characters:');
765
771
  }
766
- return TemplateError;
767
- })(Error));
768
-
769
- var defaultDiacriticsRemovalMap = [
770
- {
771
- base: 'A',
772
- 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',
773
- },
774
- { base: 'AA', letters: '\uA732' },
775
- { base: 'AE', letters: '\u00C6\u01FC\u01E2' },
776
- { base: 'AO', letters: '\uA734' },
777
- { base: 'AU', letters: '\uA736' },
778
- { base: 'AV', letters: '\uA738\uA73A' },
779
- { base: 'AY', letters: '\uA73C' },
780
- {
781
- base: 'B',
782
- letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
783
- },
784
- {
785
- base: 'C',
786
- letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
787
- },
788
- {
789
- base: 'D',
790
- letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
791
- },
792
- { base: 'DZ', letters: '\u01F1\u01C4' },
793
- { base: 'Dz', letters: '\u01F2\u01C5' },
794
- {
795
- base: 'E',
796
- 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',
797
- },
798
- { base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
799
- {
800
- base: 'G',
801
- letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
802
- },
803
- {
804
- base: 'H',
805
- letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
806
- },
807
- {
808
- base: 'I',
809
- letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
810
- },
811
- { base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
812
- {
813
- base: 'K',
814
- letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
815
- },
816
- {
817
- base: 'L',
818
- letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
819
- },
820
- { base: 'LJ', letters: '\u01C7' },
821
- { base: 'Lj', letters: '\u01C8' },
822
- { base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
823
- {
824
- base: 'N',
825
- letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
826
- },
827
- { base: 'NJ', letters: '\u01CA' },
828
- { base: 'Nj', letters: '\u01CB' },
829
- {
830
- base: 'O',
831
- 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',
832
- },
833
- { base: 'OI', letters: '\u01A2' },
834
- { base: 'OO', letters: '\uA74E' },
835
- { base: 'OU', letters: '\u0222' },
836
- { base: 'OE', letters: '\u008C\u0152' },
837
- { base: 'oe', letters: '\u009C\u0153' },
838
- {
839
- base: 'P',
840
- letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
841
- },
842
- { base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
843
- {
844
- base: 'R',
845
- letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
846
- },
772
+ var type = listItem.trim();
773
+ type = type.split('`').join('');
774
+ type = type.split('"').join('');
775
+ type = type.split("'").join('');
776
+ type = type.split('~').join('');
777
+ type = type.split('[').join('');
778
+ type = type.split(']').join('');
779
+ type = type.split('(').join('');
780
+ type = type.split(')').join('');
781
+ type = normalizeTo_SCREAMING_CASE(type);
782
+ type = type.split('DIALOGUE').join('DIALOG');
783
+ var listItemParts = listItem
784
+ .split(' ')
785
+ .map(function (part) { return part.trim(); })
786
+ .filter(function (item) { return item !== ''; })
787
+ .filter(function (item) { return !/^PTBK$/i.test(item); })
788
+ .filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
789
+ .map(removeMarkdownFormatting);
790
+ if (type.startsWith('URL') ||
791
+ type.startsWith('PTBK_URL') ||
792
+ type.startsWith('PTBKURL') ||
793
+ type.startsWith('PROMPTBOOK_URL') ||
794
+ type.startsWith('PROMPTBOOKURL') ||
795
+ type.startsWith('HTTPS')) {
796
+ if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
797
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
798
+ }
799
+ var promptbookUrlString = listItemParts.pop();
800
+ var promptbookUrl = new URL(promptbookUrlString);
801
+ if (promptbookUrl.protocol !== 'https:') {
802
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
803
+ }
804
+ if (promptbookUrl.hash !== '') {
805
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
806
+ }
807
+ return {
808
+ type: 'PROMPTBOOK_URL',
809
+ promptbookUrl: promptbookUrl,
810
+ };
811
+ }
812
+ else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
813
+ if (listItemParts.length !== 2) {
814
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
815
+ }
816
+ var promptbookVersion = listItemParts.pop();
817
+ // TODO: Validate version
818
+ return {
819
+ type: 'PROMPTBOOK_VERSION',
820
+ promptbookVersion: promptbookVersion,
821
+ };
822
+ }
823
+ else if (type.startsWith('EXECUTE') ||
824
+ type.startsWith('EXEC') ||
825
+ type.startsWith('PROMPT_DIALOG') ||
826
+ type.startsWith('SIMPLE_TEMPLATE')) {
827
+ var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
828
+ if (executionTypes.length !== 1) {
829
+ throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown execution type in command:\n\n - ".concat(listItem, "\n\n Supported execution types are:\n ").concat(block(ExecutionTypes.join(', ')), "\n "); }));
830
+ }
831
+ return {
832
+ type: 'EXECUTE',
833
+ executionType: executionTypes[0],
834
+ };
835
+ }
836
+ else if (type.startsWith('MODEL')) {
837
+ // TODO: Make this more elegant and dynamically
838
+ if (type.startsWith('MODEL_VARIANT')) {
839
+ if (type === 'MODEL_VARIANT_CHAT') {
840
+ return {
841
+ type: 'MODEL',
842
+ key: 'modelVariant',
843
+ value: 'CHAT',
844
+ };
845
+ }
846
+ else if (type === 'MODEL_VARIANT_COMPLETION') {
847
+ return {
848
+ type: 'MODEL',
849
+ key: 'modelVariant',
850
+ value: 'COMPLETION',
851
+ };
852
+ }
853
+ else {
854
+ throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n - ".concat(listItem, "\n\n Supported variants are:\n ").concat(block(['CHAT', 'COMPLETION'].join(', ')), "\n "); }));
855
+ }
856
+ }
857
+ if (type.startsWith('MODEL_NAME')) {
858
+ return {
859
+ type: 'MODEL',
860
+ key: 'modelName',
861
+ value: listItemParts.pop(),
862
+ };
863
+ }
864
+ else {
865
+ throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
866
+ }
867
+ }
868
+ else if (type.startsWith('PARAM') ||
869
+ type.startsWith('INPUT_PARAM') ||
870
+ type.startsWith('OUTPUT_PARAM') ||
871
+ listItem.startsWith('{') ||
872
+ listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
873
+ var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
874
+ if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
875
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
876
+ }
877
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
878
+ var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
879
+ if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
880
+ throw new PromptbookSyntaxError(spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
881
+ }
882
+ var isInput = type.startsWith('INPUT');
883
+ var isOutput = type.startsWith('OUTPUT');
884
+ if (listItem.startsWith('> {')) {
885
+ isInput = false;
886
+ isOutput = false;
887
+ }
888
+ return {
889
+ type: 'PARAMETER',
890
+ parameterName: parameterName,
891
+ parameterDescription: parameterDescription.trim() || null,
892
+ isInput: isInput,
893
+ isOutput: isOutput,
894
+ };
895
+ }
896
+ else if (type.startsWith('JOKER')) {
897
+ if (listItemParts.length !== 2) {
898
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
899
+ }
900
+ var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
901
+ if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
902
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
903
+ }
904
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
905
+ var parameterName = parametersMatch.groups.parameterName;
906
+ return {
907
+ type: 'JOKER',
908
+ parameterName: parameterName,
909
+ };
910
+ }
911
+ else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
912
+ if (listItemParts.length !== 2) {
913
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
914
+ }
915
+ var functionName = listItemParts.pop();
916
+ return {
917
+ type: 'POSTPROCESS',
918
+ functionName: functionName,
919
+ };
920
+ }
921
+ else if (type.startsWith('EXPECT_JSON')) {
922
+ return {
923
+ type: 'EXPECT_FORMAT',
924
+ format: 'JSON',
925
+ };
926
+ // [🥤]
927
+ }
928
+ else if (type.startsWith('EXPECT')) {
929
+ try {
930
+ listItemParts.shift();
931
+ var sign = void 0;
932
+ var signRaw = listItemParts.shift();
933
+ if (/^exact/i.test(signRaw)) {
934
+ sign = 'EXACTLY';
935
+ }
936
+ else if (/^min/i.test(signRaw)) {
937
+ sign = 'MINIMUM';
938
+ }
939
+ else if (/^max/i.test(signRaw)) {
940
+ sign = 'MAXIMUM';
941
+ }
942
+ else {
943
+ throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
944
+ }
945
+ var amountRaw = listItemParts.shift();
946
+ var amount = parseNumber(amountRaw);
947
+ if (amount < 0) {
948
+ throw new PromptbookSyntaxError('Amount must be positive number or zero');
949
+ }
950
+ if (amount !== Math.floor(amount)) {
951
+ throw new PromptbookSyntaxError('Amount must be whole number');
952
+ }
953
+ var unitRaw = listItemParts.shift();
954
+ var unit = undefined;
955
+ try {
956
+ 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()) {
957
+ var existingUnit = EXPECTATION_UNITS_1_1.value;
958
+ var existingUnitText = existingUnit;
959
+ existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
960
+ if (existingUnitText === 'CHARACTER') {
961
+ existingUnitText = 'CHAR';
962
+ }
963
+ if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
964
+ new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
965
+ if (unit !== undefined) {
966
+ throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
967
+ }
968
+ unit = existingUnit;
969
+ }
970
+ }
971
+ }
972
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
973
+ finally {
974
+ try {
975
+ if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
976
+ }
977
+ finally { if (e_1) throw e_1.error; }
978
+ }
979
+ if (unit === undefined) {
980
+ throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
981
+ }
982
+ return {
983
+ type: 'EXPECT_AMOUNT',
984
+ sign: sign,
985
+ unit: unit,
986
+ amount: amount,
987
+ };
988
+ }
989
+ catch (error) {
990
+ if (!(error instanceof Error)) {
991
+ throw error;
992
+ }
993
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
994
+ }
995
+ /*
996
+ } else if (type.startsWith('__________________')) {
997
+ // <- [🥻] Insert here when making new command
998
+ */
999
+ }
1000
+ else {
1001
+ throw new PromptbookSyntaxError(spaceTrim("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - PROMPTBOOK_URL <url>\n - PROMPTBOOK_VERSION <version>\n - EXECUTE PROMPT TEMPLATE\n - EXECUTE SIMPLE TEMPLATE\n - SIMPLE TEMPLATE\n - EXECUTE SCRIPT\n - EXECUTE PROMPT_DIALOG'\n - PROMPT_DIALOG'\n - MODEL NAME <name>\n - MODEL VARIANT <\"Chat\"|\"Completion\">\n - INPUT PARAM {<name>} <description>\n - OUTPUT PARAM {<name>} <description>\n - POSTPROCESS `{functionName}`\n - JOKER {<name>}\n - EXPECT JSON\n - EXPECT <\"Exactly\"|\"Min\"|\"Max\"> <number> <\"Chars\"|\"Words\"|\"Sentences\"|\"Paragraphs\"|\"Pages\">\n\n ")));
1002
+ }
1003
+ }
1004
+
1005
+ var defaultDiacriticsRemovalMap = [
847
1006
  {
848
- base: 'S',
849
- letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
1007
+ base: 'A',
1008
+ 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',
850
1009
  },
1010
+ { base: 'AA', letters: '\uA732' },
1011
+ { base: 'AE', letters: '\u00C6\u01FC\u01E2' },
1012
+ { base: 'AO', letters: '\uA734' },
1013
+ { base: 'AU', letters: '\uA736' },
1014
+ { base: 'AV', letters: '\uA738\uA73A' },
1015
+ { base: 'AY', letters: '\uA73C' },
851
1016
  {
852
- base: 'T',
853
- letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
1017
+ base: 'B',
1018
+ letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
854
1019
  },
855
- { base: 'TZ', letters: '\uA728' },
856
1020
  {
857
- base: 'U',
858
- 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',
1021
+ base: 'C',
1022
+ letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
859
1023
  },
860
- { base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
1024
+ {
1025
+ base: 'D',
1026
+ letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
1027
+ },
1028
+ { base: 'DZ', letters: '\u01F1\u01C4' },
1029
+ { base: 'Dz', letters: '\u01F2\u01C5' },
1030
+ {
1031
+ base: 'E',
1032
+ 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',
1033
+ },
1034
+ { base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
1035
+ {
1036
+ base: 'G',
1037
+ letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
1038
+ },
1039
+ {
1040
+ base: 'H',
1041
+ letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
1042
+ },
1043
+ {
1044
+ base: 'I',
1045
+ letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
1046
+ },
1047
+ { base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
1048
+ {
1049
+ base: 'K',
1050
+ letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
1051
+ },
1052
+ {
1053
+ base: 'L',
1054
+ letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
1055
+ },
1056
+ { base: 'LJ', letters: '\u01C7' },
1057
+ { base: 'Lj', letters: '\u01C8' },
1058
+ { base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
1059
+ {
1060
+ base: 'N',
1061
+ letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
1062
+ },
1063
+ { base: 'NJ', letters: '\u01CA' },
1064
+ { base: 'Nj', letters: '\u01CB' },
1065
+ {
1066
+ base: 'O',
1067
+ 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',
1068
+ },
1069
+ { base: 'OI', letters: '\u01A2' },
1070
+ { base: 'OO', letters: '\uA74E' },
1071
+ { base: 'OU', letters: '\u0222' },
1072
+ { base: 'OE', letters: '\u008C\u0152' },
1073
+ { base: 'oe', letters: '\u009C\u0153' },
1074
+ {
1075
+ base: 'P',
1076
+ letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
1077
+ },
1078
+ { base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
1079
+ {
1080
+ base: 'R',
1081
+ letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
1082
+ },
1083
+ {
1084
+ base: 'S',
1085
+ letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
1086
+ },
1087
+ {
1088
+ base: 'T',
1089
+ letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
1090
+ },
1091
+ { base: 'TZ', letters: '\uA728' },
1092
+ {
1093
+ base: 'U',
1094
+ 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',
1095
+ },
1096
+ { base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
861
1097
  { base: 'VY', letters: '\uA760' },
862
1098
  {
863
1099
  base: 'W',
@@ -989,492 +1225,113 @@ for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
989
1225
  var letters = defaultDiacriticsRemovalMap[i].letters;
990
1226
  // tslint:disable-next-line: prefer-for-of
991
1227
  for (var j = 0; j < letters.length; j++) {
992
- DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
993
- }
994
- }
995
- // <- TODO: [🍓] Put to maker function to save execution time if not needed
996
- /*
997
- @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
998
- Licensed under the Apache License, Version 2.0 (the "License");
999
- you may not use this file except in compliance with the License.
1000
- You may obtain a copy of the License at
1001
-
1002
- http://www.apache.org/licenses/LICENSE-2.0
1003
-
1004
- Unless required by applicable law or agreed to in writing, software
1005
- distributed under the License is distributed on an "AS IS" BASIS,
1006
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1007
- See the License for the specific language governing permissions and
1008
- limitations under the License.
1009
- */
1010
-
1011
- /**
1012
- *
1013
- */
1014
- function removeDiacritics(input) {
1015
- /*eslint no-control-regex: "off"*/
1016
- return input.replace(/[^\u0000-\u007E]/g, function (a) {
1017
- return DIACRITIC_VARIANTS_LETTERS[a] || a;
1018
- });
1019
- }
1020
-
1021
- /**
1022
- * Removes Markdown formatting tags from a string.
1023
- *
1024
- * @param {string} str - The string to remove Markdown tags from.
1025
- * @returns {string} The input string with all Markdown tags removed.
1026
- */
1027
- function removeMarkdownFormatting(str) {
1028
- // Remove bold formatting
1029
- str = str.replace(/\*\*(.*?)\*\*/g, '$1');
1030
- // Remove italic formatting
1031
- str = str.replace(/\*(.*?)\*/g, '$1');
1032
- // Remove code formatting
1033
- str = str.replace(/`(.*?)`/g, '$1');
1034
- return str;
1035
- }
1036
-
1037
- /* tslint:disable */
1038
- /*
1039
- TODO: Tests
1040
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
1041
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
1042
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
1043
- expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
1044
- */
1045
- function normalizeTo_SCREAMING_CASE(sentence) {
1046
- var e_1, _a;
1047
- var charType;
1048
- var lastCharType = 'OTHER';
1049
- var normalizedName = '';
1050
- try {
1051
- for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1052
- var char = sentence_1_1.value;
1053
- var normalizedChar = void 0;
1054
- if (/^[a-z]$/.test(char)) {
1055
- charType = 'LOWERCASE';
1056
- normalizedChar = char.toUpperCase();
1057
- }
1058
- else if (/^[A-Z]$/.test(char)) {
1059
- charType = 'UPPERCASE';
1060
- normalizedChar = char;
1061
- }
1062
- else if (/^[0-9]$/.test(char)) {
1063
- charType = 'NUMBER';
1064
- normalizedChar = char;
1065
- }
1066
- else if (/^\/$/.test(char)) {
1067
- charType = 'SLASH';
1068
- normalizedChar = char;
1069
- }
1070
- else {
1071
- charType = 'OTHER';
1072
- normalizedChar = '_';
1073
- }
1074
- if (charType !== lastCharType &&
1075
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1076
- !(lastCharType === 'NUMBER') &&
1077
- !(charType === 'NUMBER')) {
1078
- normalizedName += '_';
1079
- }
1080
- normalizedName += normalizedChar;
1081
- lastCharType = charType;
1082
- }
1083
- }
1084
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1085
- finally {
1086
- try {
1087
- if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
1088
- }
1089
- finally { if (e_1) throw e_1.error; }
1090
- }
1091
- normalizedName = normalizedName.replace(/_+/g, '_');
1092
- normalizedName = normalizedName.replace(/_?\/_?/g, '/');
1093
- normalizedName = normalizedName.replace(/^_/, '');
1094
- normalizedName = normalizedName.replace(/_$/, '');
1095
- return normalizedName;
1096
- }
1097
- /**
1098
- * TODO: [🌺] Use some intermediate util splitWords
1099
- */
1100
-
1101
- /* tslint:disable */
1102
- function normalizeToKebabCase(sentence) {
1103
- var e_1, _a;
1104
- sentence = removeDiacritics(sentence);
1105
- var charType;
1106
- var lastCharType = 'OTHER';
1107
- var normalizedName = '';
1108
- try {
1109
- for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1110
- var char = sentence_1_1.value;
1111
- var normalizedChar = void 0;
1112
- if (/^[a-z]$/.test(char)) {
1113
- charType = 'LOWERCASE';
1114
- normalizedChar = char;
1115
- }
1116
- else if (/^[A-Z]$/.test(char)) {
1117
- charType = 'UPPERCASE';
1118
- normalizedChar = char.toLowerCase();
1119
- }
1120
- else if (/^[0-9]$/.test(char)) {
1121
- charType = 'NUMBER';
1122
- normalizedChar = char;
1123
- }
1124
- else if (/^\/$/.test(char)) {
1125
- charType = 'SLASH';
1126
- normalizedChar = char;
1127
- }
1128
- else {
1129
- charType = 'OTHER';
1130
- normalizedChar = '-';
1131
- }
1132
- if (charType !== lastCharType &&
1133
- !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1134
- !(lastCharType === 'NUMBER') &&
1135
- !(charType === 'NUMBER')) {
1136
- normalizedName += '-';
1137
- }
1138
- normalizedName += normalizedChar;
1139
- lastCharType = charType;
1140
- }
1141
- }
1142
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1143
- finally {
1144
- try {
1145
- if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
1146
- }
1147
- finally { if (e_1) throw e_1.error; }
1148
- }
1149
- normalizedName = normalizedName.split(/-+/g).join('-');
1150
- normalizedName = normalizedName.split(/-?\/-?/g).join('/');
1151
- normalizedName = normalizedName.replace(/^-/, '');
1152
- normalizedName = normalizedName.replace(/-$/, '');
1153
- return normalizedName;
1154
- }
1155
-
1156
- /* tslint:disable */
1157
- function normalizeTo_camelCase(sentence, __firstLetterCapital) {
1158
- var e_1, _a;
1159
- if (__firstLetterCapital === void 0) { __firstLetterCapital = false; }
1160
- var charType;
1161
- var lastCharType = null;
1162
- var normalizedName = '';
1163
- try {
1164
- for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1165
- var char = sentence_1_1.value;
1166
- var normalizedChar = void 0;
1167
- if (/^[a-z]$/.test(char)) {
1168
- charType = 'LOWERCASE';
1169
- normalizedChar = char;
1170
- }
1171
- else if (/^[A-Z]$/.test(char)) {
1172
- charType = 'UPPERCASE';
1173
- normalizedChar = char.toLowerCase();
1174
- }
1175
- else if (/^[0-9]$/.test(char)) {
1176
- charType = 'NUMBER';
1177
- normalizedChar = char;
1178
- }
1179
- else {
1180
- charType = 'OTHER';
1181
- normalizedChar = '';
1182
- }
1183
- if (!lastCharType) {
1184
- if (__firstLetterCapital) {
1185
- normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
1186
- }
1187
- }
1188
- else if (charType !== lastCharType &&
1189
- !(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
1190
- !(lastCharType === 'NUMBER') &&
1191
- !(charType === 'NUMBER')) {
1192
- normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
1193
- }
1194
- normalizedName += normalizedChar;
1195
- lastCharType = charType;
1196
- }
1197
- }
1198
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1199
- finally {
1200
- try {
1201
- if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
1202
- }
1203
- finally { if (e_1) throw e_1.error; }
1204
- }
1205
- return normalizedName;
1206
- }
1207
- /**
1208
- * TODO: [🌺] Use some intermediate util splitWords
1209
- */
1210
-
1211
- /**
1212
- * Execution type describes the way how the block is executed
1213
- *
1214
- * @see https://github.com/webgptorg/promptbook#execution-type
1215
- */
1216
- var ExecutionTypes = [
1217
- 'PROMPT_TEMPLATE',
1218
- 'SIMPLE_TEMPLATE',
1219
- 'SCRIPT',
1220
- 'PROMPT_DIALOG',
1221
- // <- [🥻] Insert here when making new command
1222
- ];
1223
-
1224
- /**
1225
- * Units of text measurement
1226
- */
1227
- var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
1228
- /**
1229
- * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
1230
- * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
1231
- * TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
1232
- */
1233
-
1234
- /**
1235
- * Parses one line of ul/ol to command
1236
- *
1237
- * @returns parsed command object
1238
- * @throws {PromptbookSyntaxError} if the command is invalid
1239
- *
1240
- * @private within the promptbookStringToJson
1241
- */
1242
- function parseCommand(listItem) {
1243
- var e_1, _a;
1244
- if (listItem.includes('\n') || listItem.includes('\r')) {
1245
- throw new PromptbookSyntaxError('Command can not contain new line characters:');
1246
- }
1247
- var type = listItem.trim();
1248
- type = type.split('`').join('');
1249
- type = type.split('"').join('');
1250
- type = type.split("'").join('');
1251
- type = type.split('~').join('');
1252
- type = type.split('[').join('');
1253
- type = type.split(']').join('');
1254
- type = type.split('(').join('');
1255
- type = type.split(')').join('');
1256
- type = normalizeTo_SCREAMING_CASE(type);
1257
- type = type.split('DIALOGUE').join('DIALOG');
1258
- var listItemParts = listItem
1259
- .split(' ')
1260
- .map(function (part) { return part.trim(); })
1261
- .filter(function (item) { return item !== ''; })
1262
- .filter(function (item) { return !/^PTBK$/i.test(item); })
1263
- .filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
1264
- .map(removeMarkdownFormatting);
1265
- if (type.startsWith('URL') ||
1266
- type.startsWith('PTBK_URL') ||
1267
- type.startsWith('PTBKURL') ||
1268
- type.startsWith('PROMPTBOOK_URL') ||
1269
- type.startsWith('PROMPTBOOKURL') ||
1270
- type.startsWith('HTTPS')) {
1271
- if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
1272
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
1273
- }
1274
- var promptbookUrlString = listItemParts.pop();
1275
- var promptbookUrl = new URL(promptbookUrlString);
1276
- if (promptbookUrl.protocol !== 'https:') {
1277
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
1278
- }
1279
- if (promptbookUrl.hash !== '') {
1280
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
1281
- }
1282
- return {
1283
- type: 'PROMPTBOOK_URL',
1284
- promptbookUrl: promptbookUrl,
1285
- };
1286
- }
1287
- else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
1288
- if (listItemParts.length !== 2) {
1289
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
1290
- }
1291
- var promptbookVersion = listItemParts.pop();
1292
- // TODO: Validate version
1293
- return {
1294
- type: 'PROMPTBOOK_VERSION',
1295
- promptbookVersion: promptbookVersion,
1296
- };
1297
- }
1298
- else if (type.startsWith('EXECUTE') ||
1299
- type.startsWith('EXEC') ||
1300
- type.startsWith('PROMPT_DIALOG') ||
1301
- type.startsWith('SIMPLE_TEMPLATE')) {
1302
- var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
1303
- if (executionTypes.length !== 1) {
1304
- throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown execution type in command:\n\n - ".concat(listItem, "\n\n Supported execution types are:\n ").concat(block(ExecutionTypes.join(', ')), "\n "); }));
1305
- }
1306
- return {
1307
- type: 'EXECUTE',
1308
- executionType: executionTypes[0],
1309
- };
1310
- }
1311
- else if (type.startsWith('MODEL')) {
1312
- // TODO: Make this more elegant and dynamically
1313
- if (type.startsWith('MODEL_VARIANT')) {
1314
- if (type === 'MODEL_VARIANT_CHAT') {
1315
- return {
1316
- type: 'MODEL',
1317
- key: 'modelVariant',
1318
- value: 'CHAT',
1319
- };
1320
- }
1321
- else if (type === 'MODEL_VARIANT_COMPLETION') {
1322
- return {
1323
- type: 'MODEL',
1324
- key: 'modelVariant',
1325
- value: 'COMPLETION',
1326
- };
1327
- }
1328
- else {
1329
- throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n - ".concat(listItem, "\n\n Supported variants are:\n ").concat(block(['CHAT', 'COMPLETION'].join(', ')), "\n "); }));
1330
- }
1331
- }
1332
- if (type.startsWith('MODEL_NAME')) {
1333
- return {
1334
- type: 'MODEL',
1335
- key: 'modelName',
1336
- value: listItemParts.pop(),
1337
- };
1338
- }
1339
- else {
1340
- throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
1341
- }
1342
- }
1343
- else if (type.startsWith('PARAM') ||
1344
- type.startsWith('INPUT_PARAM') ||
1345
- type.startsWith('OUTPUT_PARAM') ||
1346
- listItem.startsWith('{') ||
1347
- listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
1348
- var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
1349
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
1350
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1351
- }
1352
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1353
- var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
1354
- if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
1355
- throw new PromptbookSyntaxError(spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
1356
- }
1357
- var isInput = type.startsWith('INPUT');
1358
- var isOutput = type.startsWith('OUTPUT');
1359
- if (listItem.startsWith('> {')) {
1360
- isInput = false;
1361
- isOutput = false;
1362
- }
1363
- return {
1364
- type: 'PARAMETER',
1365
- parameterName: parameterName,
1366
- parameterDescription: parameterDescription.trim() || null,
1367
- isInput: isInput,
1368
- isOutput: isOutput,
1369
- };
1370
- }
1371
- else if (type.startsWith('JOKER')) {
1372
- if (listItemParts.length !== 2) {
1373
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
1374
- }
1375
- var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
1376
- if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
1377
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1378
- }
1379
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1380
- var parameterName = parametersMatch.groups.parameterName;
1381
- return {
1382
- type: 'JOKER',
1383
- parameterName: parameterName,
1384
- };
1385
- }
1386
- else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
1387
- if (listItemParts.length !== 2) {
1388
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
1389
- }
1390
- var functionName = listItemParts.pop();
1391
- return {
1392
- type: 'POSTPROCESS',
1393
- functionName: functionName,
1394
- };
1395
- }
1396
- else if (type.startsWith('EXPECT_JSON')) {
1397
- return {
1398
- type: 'EXPECT_FORMAT',
1399
- format: 'JSON',
1400
- };
1401
- // [🥤]
1402
- }
1403
- else if (type.startsWith('EXPECT')) {
1404
- try {
1405
- listItemParts.shift();
1406
- var sign = void 0;
1407
- var signRaw = listItemParts.shift();
1408
- if (/^exact/i.test(signRaw)) {
1409
- sign = 'EXACTLY';
1410
- }
1411
- else if (/^min/i.test(signRaw)) {
1412
- sign = 'MINIMUM';
1413
- }
1414
- else if (/^max/i.test(signRaw)) {
1415
- sign = 'MAXIMUM';
1416
- }
1417
- else {
1418
- throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
1419
- }
1420
- var amountRaw = listItemParts.shift();
1421
- var amount = parseNumber(amountRaw);
1422
- if (amount < 0) {
1423
- throw new PromptbookSyntaxError('Amount must be positive number or zero');
1228
+ DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
1229
+ }
1230
+ }
1231
+ // <- TODO: [🍓] Put to maker function to save execution time if not needed
1232
+ /*
1233
+ @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
1234
+ Licensed under the Apache License, Version 2.0 (the "License");
1235
+ you may not use this file except in compliance with the License.
1236
+ You may obtain a copy of the License at
1237
+
1238
+ http://www.apache.org/licenses/LICENSE-2.0
1239
+
1240
+ Unless required by applicable law or agreed to in writing, software
1241
+ distributed under the License is distributed on an "AS IS" BASIS,
1242
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1243
+ See the License for the specific language governing permissions and
1244
+ limitations under the License.
1245
+ */
1246
+
1247
+ /**
1248
+ *
1249
+ */
1250
+ function removeDiacritics(input) {
1251
+ /*eslint no-control-regex: "off"*/
1252
+ return input.replace(/[^\u0000-\u007E]/g, function (a) {
1253
+ return DIACRITIC_VARIANTS_LETTERS[a] || a;
1254
+ });
1255
+ }
1256
+
1257
+ /* tslint:disable */
1258
+ function normalizeToKebabCase(sentence) {
1259
+ var e_1, _a;
1260
+ sentence = removeDiacritics(sentence);
1261
+ var charType;
1262
+ var lastCharType = 'OTHER';
1263
+ var normalizedName = '';
1264
+ try {
1265
+ for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1266
+ var char = sentence_1_1.value;
1267
+ var normalizedChar = void 0;
1268
+ if (/^[a-z]$/.test(char)) {
1269
+ charType = 'LOWERCASE';
1270
+ normalizedChar = char;
1424
1271
  }
1425
- if (amount !== Math.floor(amount)) {
1426
- throw new PromptbookSyntaxError('Amount must be whole number');
1272
+ else if (/^[A-Z]$/.test(char)) {
1273
+ charType = 'UPPERCASE';
1274
+ normalizedChar = char.toLowerCase();
1427
1275
  }
1428
- var unitRaw = listItemParts.shift();
1429
- var unit = undefined;
1430
- try {
1431
- 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()) {
1432
- var existingUnit = EXPECTATION_UNITS_1_1.value;
1433
- var existingUnitText = existingUnit;
1434
- existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
1435
- if (existingUnitText === 'CHARACTER') {
1436
- existingUnitText = 'CHAR';
1437
- }
1438
- if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
1439
- new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
1440
- if (unit !== undefined) {
1441
- throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
1442
- }
1443
- unit = existingUnit;
1444
- }
1445
- }
1276
+ else if (/^[0-9]$/.test(char)) {
1277
+ charType = 'NUMBER';
1278
+ normalizedChar = char;
1446
1279
  }
1447
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1448
- finally {
1449
- try {
1450
- if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
1451
- }
1452
- finally { if (e_1) throw e_1.error; }
1280
+ else if (/^\/$/.test(char)) {
1281
+ charType = 'SLASH';
1282
+ normalizedChar = char;
1453
1283
  }
1454
- if (unit === undefined) {
1455
- throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
1284
+ else {
1285
+ charType = 'OTHER';
1286
+ normalizedChar = '-';
1456
1287
  }
1457
- return {
1458
- type: 'EXPECT_AMOUNT',
1459
- sign: sign,
1460
- unit: unit,
1461
- amount: amount,
1462
- };
1463
- }
1464
- catch (error) {
1465
- if (!(error instanceof Error)) {
1466
- throw error;
1288
+ if (charType !== lastCharType &&
1289
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
1290
+ !(lastCharType === 'NUMBER') &&
1291
+ !(charType === 'NUMBER')) {
1292
+ normalizedName += '-';
1467
1293
  }
1468
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
1294
+ normalizedName += normalizedChar;
1295
+ lastCharType = charType;
1469
1296
  }
1470
- /*
1471
- } else if (type.startsWith('__________________')) {
1472
- // <- [🥻] Insert here when making new command
1473
- */
1474
1297
  }
1475
- else {
1476
- throw new PromptbookSyntaxError(spaceTrim("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - PROMPTBOOK_URL <url>\n - PROMPTBOOK_VERSION <version>\n - EXECUTE PROMPT TEMPLATE\n - EXECUTE SIMPLE TEMPLATE\n - SIMPLE TEMPLATE\n - EXECUTE SCRIPT\n - EXECUTE PROMPT_DIALOG'\n - PROMPT_DIALOG'\n - MODEL NAME <name>\n - MODEL VARIANT <\"Chat\"|\"Completion\">\n - INPUT PARAM {<name>} <description>\n - OUTPUT PARAM {<name>} <description>\n - POSTPROCESS `{functionName}`\n - JOKER {<name>}\n - EXPECT JSON\n - EXPECT <\"Exactly\"|\"Min\"|\"Max\"> <number> <\"Chars\"|\"Words\"|\"Sentences\"|\"Paragraphs\"|\"Pages\">\n\n ")));
1298
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1299
+ finally {
1300
+ try {
1301
+ if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
1302
+ }
1303
+ finally { if (e_1) throw e_1.error; }
1477
1304
  }
1305
+ normalizedName = normalizedName.split(/-+/g).join('-');
1306
+ normalizedName = normalizedName.split(/-?\/-?/g).join('/');
1307
+ normalizedName = normalizedName.replace(/^-/, '');
1308
+ normalizedName = normalizedName.replace(/-$/, '');
1309
+ return normalizedName;
1310
+ }
1311
+
1312
+ /**
1313
+ * Removes emojis from a string and fix whitespaces
1314
+ *
1315
+ * @param text with emojis
1316
+ * @returns text without emojis
1317
+ */
1318
+ function removeEmojis(text) {
1319
+ // Replace emojis (and also ZWJ sequence) with hyphens
1320
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
1321
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
1322
+ text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
1323
+ text = text.replace(/\p{Extended_Pictographic}/gu, '');
1324
+ return text;
1325
+ }
1326
+
1327
+ /**
1328
+ * Function normalizes title to name which can be used as identifier
1329
+ */
1330
+ function titleToName(value) {
1331
+ value = removeEmojis(value);
1332
+ value = normalizeToKebabCase(value);
1333
+ // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
1334
+ return value;
1478
1335
  }
1479
1336
 
1480
1337
  /**
@@ -1782,6 +1639,119 @@ function prettifyMarkdown(content) {
1782
1639
  }
1783
1640
  }
1784
1641
 
1642
+ /* tslint:disable */
1643
+ function normalizeTo_camelCase(sentence, __firstLetterCapital) {
1644
+ var e_1, _a;
1645
+ if (__firstLetterCapital === void 0) { __firstLetterCapital = false; }
1646
+ var charType;
1647
+ var lastCharType = null;
1648
+ var normalizedName = '';
1649
+ try {
1650
+ for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
1651
+ var char = sentence_1_1.value;
1652
+ var normalizedChar = void 0;
1653
+ if (/^[a-z]$/.test(char)) {
1654
+ charType = 'LOWERCASE';
1655
+ normalizedChar = char;
1656
+ }
1657
+ else if (/^[A-Z]$/.test(char)) {
1658
+ charType = 'UPPERCASE';
1659
+ normalizedChar = char.toLowerCase();
1660
+ }
1661
+ else if (/^[0-9]$/.test(char)) {
1662
+ charType = 'NUMBER';
1663
+ normalizedChar = char;
1664
+ }
1665
+ else {
1666
+ charType = 'OTHER';
1667
+ normalizedChar = '';
1668
+ }
1669
+ if (!lastCharType) {
1670
+ if (__firstLetterCapital) {
1671
+ normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
1672
+ }
1673
+ }
1674
+ else if (charType !== lastCharType &&
1675
+ !(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
1676
+ !(lastCharType === 'NUMBER') &&
1677
+ !(charType === 'NUMBER')) {
1678
+ normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
1679
+ }
1680
+ normalizedName += normalizedChar;
1681
+ lastCharType = charType;
1682
+ }
1683
+ }
1684
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1685
+ finally {
1686
+ try {
1687
+ if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
1688
+ }
1689
+ finally { if (e_1) throw e_1.error; }
1690
+ }
1691
+ return normalizedName;
1692
+ }
1693
+ /**
1694
+ * TODO: [🌺] Use some intermediate util splitWords
1695
+ */
1696
+
1697
+ /**
1698
+ * Creates a Mermaid graph based on the promptbook
1699
+ *
1700
+ * Note: The result is not wrapped in a Markdown code block
1701
+ */
1702
+ function renderPromptbookMermaid(promptbookJson, options) {
1703
+ var _a = (options || {}).linkPromptTemplate, linkPromptTemplate = _a === void 0 ? function () { return null; } : _a;
1704
+ var parameterNameToTemplateName = function (parameterName) {
1705
+ var parameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
1706
+ if (!parameter) {
1707
+ throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
1708
+ }
1709
+ if (parameter.isInput) {
1710
+ return 'input';
1711
+ }
1712
+ var template = promptbookJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
1713
+ if (!template) {
1714
+ throw new Error("Could not find template for {".concat(parameterName, "}"));
1715
+ }
1716
+ return normalizeTo_camelCase('template-' + titleToName(template.title));
1717
+ };
1718
+ var promptbookMermaid = spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(promptbookJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson.promptTemplates
1719
+ .flatMap(function (_a) {
1720
+ var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
1721
+ return __spreadArray([
1722
+ "".concat(parameterNameToTemplateName(resultingParameterName), "(\"").concat(title, "\")")
1723
+ ], __read(dependentParameterNames.map(function (dependentParameterName) {
1724
+ return "".concat(parameterNameToTemplateName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName(resultingParameterName));
1725
+ })), false);
1726
+ })
1727
+ .join('\n')), "\n\n ").concat(block(promptbookJson.parameters
1728
+ .filter(function (_a) {
1729
+ var isOutput = _a.isOutput;
1730
+ return isOutput;
1731
+ })
1732
+ .map(function (_a) {
1733
+ var name = _a.name;
1734
+ return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
1735
+ })
1736
+ .join('\n')), "\n output((Output)):::output\n\n ").concat(block(promptbookJson.promptTemplates
1737
+ .map(function (promptTemplate) {
1738
+ var link = linkPromptTemplate(promptTemplate);
1739
+ if (link === null) {
1740
+ return '';
1741
+ }
1742
+ var href = link.href, title = link.title;
1743
+ var templateName = parameterNameToTemplateName(promptTemplate.resultingParameterName);
1744
+ return "click ".concat(templateName, " href \"").concat(href, "\" \"").concat(title, "\";");
1745
+ })
1746
+ .filter(function (line) { return line !== ''; })
1747
+ .join('\n')), "\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
1748
+ return promptbookMermaid;
1749
+ }
1750
+ /**
1751
+ * TODO: Maybe use some Mermaid library instead of string templating
1752
+ * TODO: [🕌] When more than 2 functionalities, split into separate functions
1753
+ */
1754
+
1785
1755
  /**
1786
1756
  * Prettyfies Promptbook string and adds Mermaid graph
1787
1757
  */