@promptbook/utils 0.41.0 → 0.41.2
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.
- package/bin/promptbook-cli.js +3 -0
- package/esm/index.es.js +794 -794
- package/esm/typings/_packages/core.index.d.ts +20 -20
- package/esm/typings/_packages/execute-javascript.index.d.ts +3 -3
- package/esm/typings/_packages/openai.index.d.ts +3 -3
- package/esm/typings/_packages/remote-client.index.d.ts +4 -4
- package/esm/typings/_packages/remote-server.index.d.ts +3 -3
- package/esm/typings/_packages/types.index.d.ts +27 -27
- package/esm/typings/_packages/utils.index.d.ts +30 -30
- package/esm/typings/_packages/wizzard.index.d.ts +5 -5
- package/esm/typings/config.d.ts +4 -4
- package/esm/typings/conversion/promptbookStringToJson.d.ts +13 -13
- package/esm/typings/conversion/test/_importPromptbook.d.ts +12 -12
- package/esm/typings/conversion/test/promptbookStringToJson-syntaxErrors.test.d.ts +1 -1
- package/esm/typings/conversion/test/promptbookStringToJson.test.d.ts +1 -1
- package/esm/typings/conversion/test/validatePromptbookJson-logicErrors.test.d.ts +1 -1
- package/esm/typings/conversion/test/validatePromptbookJson.d.ts +26 -26
- package/esm/typings/conversion/test/validatePromptbookJson.test.d.ts +1 -1
- package/esm/typings/conversion/utils/extractVariables.d.ts +10 -10
- package/esm/typings/conversion/utils/extractVariables.test.d.ts +1 -1
- package/esm/typings/conversion/utils/parseCommand.d.ts +8 -8
- package/esm/typings/conversion/utils/parseCommand.test.d.ts +4 -4
- package/esm/typings/conversion/utils/parseNumber.d.ts +12 -12
- package/esm/typings/conversion/utils/parseNumber.test.d.ts +1 -1
- package/esm/typings/errors/ExpectError.d.ts +9 -9
- package/esm/typings/errors/NotFoundError.d.ts +7 -7
- package/esm/typings/errors/PromptbookExecutionError.d.ts +7 -7
- package/esm/typings/errors/PromptbookLogicError.d.ts +7 -7
- package/esm/typings/errors/PromptbookReferenceError.d.ts +7 -7
- package/esm/typings/errors/PromptbookSyntaxError.d.ts +7 -7
- package/esm/typings/errors/UnexpectedError.d.ts +7 -7
- package/esm/typings/execution/CommonExecutionToolsOptions.d.ts +9 -9
- package/esm/typings/execution/ExecutionTools.d.ts +25 -25
- package/esm/typings/execution/NaturalExecutionTools.d.ts +23 -23
- package/esm/typings/execution/PromptResult.d.ts +74 -74
- package/esm/typings/execution/PromptbookExecutor.d.ts +39 -39
- package/esm/typings/execution/ScriptExecutionTools.d.ts +37 -37
- package/esm/typings/execution/UserInterfaceTools.d.ts +45 -45
- package/esm/typings/execution/assertsExecutionSuccessful.d.ts +11 -11
- package/esm/typings/execution/createPromptbookExecutor.d.ts +41 -41
- package/esm/typings/execution/plugins/natural-execution-tools/mocked/MockedEchoNaturalExecutionTools.d.ts +22 -22
- package/esm/typings/execution/plugins/natural-execution-tools/mocked/joker.test.d.ts +4 -4
- package/esm/typings/execution/plugins/natural-execution-tools/mocked/mocked-chat.test.d.ts +4 -4
- package/esm/typings/execution/plugins/natural-execution-tools/mocked/mocked-completion.test.d.ts +4 -4
- package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools.d.ts +28 -28
- package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +16 -16
- package/esm/typings/execution/plugins/natural-execution-tools/openai/computeOpenaiUsage.d.ts +3 -3
- package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionTools.d.ts +35 -35
- package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +23 -23
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Promptbook_Server_Error.d.ts +11 -11
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Promptbook_Server_Progress.d.ts +12 -12
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Promptbook_Server_Request.d.ts +17 -17
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Promptbook_Server_Response.d.ts +12 -12
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +27 -27
- package/esm/typings/execution/plugins/natural-execution-tools/remote/startRemoteServer.d.ts +17 -17
- package/esm/typings/execution/plugins/script-execution-tools/custom-function-async.test.ts.test.d.ts +1 -1
- package/esm/typings/execution/plugins/script-execution-tools/custom-function-missing.test.d.ts +1 -1
- package/esm/typings/execution/plugins/script-execution-tools/custom-function-with-dependencies.test.d.ts +1 -1
- package/esm/typings/execution/plugins/script-execution-tools/custom-function.test.d.ts +1 -1
- package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.d.ts +20 -20
- package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -4
- package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools.d.ts +20 -20
- package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionToolsOptions.d.ts +22 -22
- package/esm/typings/execution/plugins/script-execution-tools/javascript/utils/preserve.d.ts +11 -11
- package/esm/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +1 -1
- package/esm/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +15 -15
- package/esm/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +1 -1
- package/esm/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +1 -1
- package/esm/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +15 -15
- package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +14 -14
- package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +12 -12
- package/esm/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +16 -16
- package/esm/typings/execution/plugins/user-interface-execution-tools/user-interface-execution-tools.test.d.ts +1 -1
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +4 -4
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +9 -9
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +5 -5
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +11 -11
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +4 -4
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +1 -1
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.test.d.ts +1 -1
- package/esm/typings/execution/translation/automatic-translate/translateMessages.d.ts +5 -5
- package/esm/typings/execution/utils/replaceParameters.d.ts +12 -12
- package/esm/typings/execution/utils/replaceParameters.test.d.ts +1 -1
- package/esm/typings/library/PromptbookLibrary.d.ts +25 -25
- package/esm/typings/library/SimplePromptbookLibrary.d.ts +35 -35
- package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +5 -5
- package/esm/typings/library/constructors/createPromptbookLibraryFromList.d.ts +5 -5
- package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +7 -7
- package/esm/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +16 -16
- package/esm/typings/library/constructors/createPromptbookSublibrary.d.ts +6 -6
- package/esm/typings/types/Command.d.ts +98 -98
- package/esm/typings/types/ExecutionTypes.d.ts +13 -13
- package/esm/typings/types/ModelRequirements.d.ts +41 -41
- package/esm/typings/types/Parameters.d.ts +14 -14
- package/esm/typings/types/Prompt.d.ts +41 -41
- package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +126 -126
- package/esm/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +25 -25
- package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +51 -51
- package/esm/typings/types/PromptbookString.d.ts +12 -12
- package/esm/typings/types/ScriptLanguage.d.ts +9 -9
- package/esm/typings/types/TaskProgress.d.ts +42 -42
- package/esm/typings/types/execution-report/ExecutionReportJson.d.ts +56 -56
- package/esm/typings/types/execution-report/ExecutionReportString.d.ts +16 -16
- package/esm/typings/types/execution-report/ExecutionReportStringOptions.d.ts +21 -21
- package/esm/typings/types/execution-report/config.d.ts +8 -8
- package/esm/typings/types/execution-report/countWorkingDuration.d.ts +7 -7
- package/esm/typings/types/execution-report/countWorkingDuration.test.d.ts +1 -1
- package/esm/typings/types/execution-report/executionReportJsonToString.d.ts +11 -11
- package/esm/typings/types/execution-report/executionReportJsonToString.test.d.ts +1 -1
- package/esm/typings/types/typeAliasEmoji.d.ts +9 -9
- package/esm/typings/types/typeAliases.d.ts +432 -432
- package/esm/typings/utils/FromtoItems.d.ts +19 -19
- package/esm/typings/utils/emojis.d.ts +22 -22
- package/esm/typings/utils/expectation-counters/countCharacters.d.ts +5 -5
- package/esm/typings/utils/expectation-counters/countCharacters.test.d.ts +1 -1
- package/esm/typings/utils/expectation-counters/countLines.d.ts +5 -5
- package/esm/typings/utils/expectation-counters/countLines.test.d.ts +1 -1
- package/esm/typings/utils/expectation-counters/countPages.d.ts +5 -5
- package/esm/typings/utils/expectation-counters/countPages.test.d.ts +1 -1
- package/esm/typings/utils/expectation-counters/countParagraphs.d.ts +5 -5
- package/esm/typings/utils/expectation-counters/countParagraphs.test.d.ts +1 -1
- package/esm/typings/utils/expectation-counters/countSentences.d.ts +5 -5
- package/esm/typings/utils/expectation-counters/countSentences.test.d.ts +1 -1
- package/esm/typings/utils/expectation-counters/countWords.d.ts +5 -5
- package/esm/typings/utils/expectation-counters/countWords.test.d.ts +1 -1
- package/esm/typings/utils/expectation-counters/index.d.ts +5 -5
- package/esm/typings/utils/extractParameters.d.ts +10 -10
- package/esm/typings/utils/extractParameters.test.d.ts +1 -1
- package/esm/typings/utils/formatNumber.d.ts +6 -6
- package/esm/typings/utils/formatNumber.test.d.ts +1 -1
- package/esm/typings/utils/getCurrentIsoDate.d.ts +7 -7
- package/esm/typings/utils/isRunningInWhatever.d.ts +12 -12
- package/esm/typings/utils/isValidJsonString.d.ts +4 -4
- package/esm/typings/utils/isValidJsonString.test.d.ts +1 -1
- package/esm/typings/utils/just.d.ts +10 -10
- package/esm/typings/utils/markdown/addAutoGeneratedSection.d.ts +10 -10
- package/esm/typings/utils/markdown/addAutoGeneratedSection.test.d.ts +1 -1
- package/esm/typings/utils/markdown/createMarkdownChart.d.ts +41 -41
- package/esm/typings/utils/markdown/createMarkdownChart.test.d.ts +1 -1
- package/esm/typings/utils/markdown/createMarkdownTable.d.ts +7 -7
- package/esm/typings/utils/markdown/createMarkdownTable.test.d.ts +1 -1
- package/esm/typings/utils/markdown/escapeMarkdownBlock.d.ts +6 -6
- package/esm/typings/utils/markdown/escapeMarkdownBlock.test.d.ts +1 -1
- package/esm/typings/utils/markdown/extractAllBlocksFromMarkdown.d.ts +27 -27
- package/esm/typings/utils/markdown/extractAllBlocksFromMarkdown.test.d.ts +1 -1
- package/esm/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +13 -13
- package/esm/typings/utils/markdown/extractAllListItemsFromMarkdown.test.d.ts +1 -1
- package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +19 -19
- package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.test.d.ts +1 -1
- package/esm/typings/utils/markdown/prettifyMarkdown.d.ts +8 -8
- package/esm/typings/utils/markdown/prettifyMarkdown.test.d.ts +1 -1
- package/esm/typings/utils/markdown/removeContentComments.d.ts +8 -8
- package/esm/typings/utils/markdown/removeContentComments.test.d.ts +1 -1
- package/esm/typings/utils/markdown/removeMarkdownFormatting.d.ts +8 -8
- package/esm/typings/utils/markdown/removeMarkdownFormatting.test.d.ts +1 -1
- package/esm/typings/utils/markdown-json/MarkdownStructure.d.ts +25 -25
- package/esm/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +7 -7
- package/esm/typings/utils/markdown-json/countMarkdownStructureDeepness.test.d.ts +1 -1
- package/esm/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +13 -13
- package/esm/typings/utils/markdown-json/markdownToMarkdownStructure.test.d.ts +1 -1
- package/esm/typings/utils/postprocessing/extractBlock.d.ts +12 -12
- package/esm/typings/utils/removeEmojis.d.ts +7 -7
- package/esm/typings/utils/removeEmojis.test.d.ts +1 -1
- package/esm/typings/utils/removeQuotes.d.ts +13 -13
- package/esm/typings/utils/removeQuotes.test.d.ts +1 -1
- package/esm/typings/utils/trimCodeBlock.d.ts +8 -8
- package/esm/typings/utils/trimCodeBlock.test.d.ts +1 -1
- package/esm/typings/utils/trimEndOfCodeBlock.d.ts +7 -7
- package/esm/typings/utils/trimEndOfCodeBlock.test.d.ts +1 -1
- package/esm/typings/utils/unwrapResult.d.ts +36 -36
- package/esm/typings/utils/unwrapResult.test.d.ts +1 -1
- package/esm/typings/utils/validators/url/isValidUrl.d.ts +7 -7
- package/esm/typings/utils/validators/url/isValidUrl.test.d.ts +1 -1
- package/esm/typings/version.d.ts +5 -5
- package/esm/typings/wizzard/Wizzard.d.ts +4 -4
- package/esm/typings/wizzard/sample.d.ts +6 -6
- package/package.json +4 -1
- package/umd/index.umd.js +794 -794
- package/umd/typings/_packages/core.index.d.ts +20 -20
- package/umd/typings/_packages/execute-javascript.index.d.ts +3 -3
- package/umd/typings/_packages/openai.index.d.ts +3 -3
- package/umd/typings/_packages/remote-client.index.d.ts +4 -4
- package/umd/typings/_packages/remote-server.index.d.ts +3 -3
- package/umd/typings/_packages/types.index.d.ts +27 -27
- package/umd/typings/_packages/utils.index.d.ts +30 -30
- package/umd/typings/_packages/wizzard.index.d.ts +5 -5
- package/umd/typings/config.d.ts +4 -4
- package/umd/typings/conversion/promptbookStringToJson.d.ts +13 -13
- package/umd/typings/conversion/test/_importPromptbook.d.ts +12 -12
- package/umd/typings/conversion/test/promptbookStringToJson-syntaxErrors.test.d.ts +1 -1
- package/umd/typings/conversion/test/promptbookStringToJson.test.d.ts +1 -1
- package/umd/typings/conversion/test/validatePromptbookJson-logicErrors.test.d.ts +1 -1
- package/umd/typings/conversion/test/validatePromptbookJson.d.ts +26 -26
- package/umd/typings/conversion/test/validatePromptbookJson.test.d.ts +1 -1
- package/umd/typings/conversion/utils/extractVariables.d.ts +10 -10
- package/umd/typings/conversion/utils/extractVariables.test.d.ts +1 -1
- package/umd/typings/conversion/utils/parseCommand.d.ts +8 -8
- package/umd/typings/conversion/utils/parseCommand.test.d.ts +4 -4
- package/umd/typings/conversion/utils/parseNumber.d.ts +12 -12
- package/umd/typings/conversion/utils/parseNumber.test.d.ts +1 -1
- package/umd/typings/errors/ExpectError.d.ts +9 -9
- package/umd/typings/errors/NotFoundError.d.ts +7 -7
- package/umd/typings/errors/PromptbookExecutionError.d.ts +7 -7
- package/umd/typings/errors/PromptbookLogicError.d.ts +7 -7
- package/umd/typings/errors/PromptbookReferenceError.d.ts +7 -7
- package/umd/typings/errors/PromptbookSyntaxError.d.ts +7 -7
- package/umd/typings/errors/UnexpectedError.d.ts +7 -7
- package/umd/typings/execution/CommonExecutionToolsOptions.d.ts +9 -9
- package/umd/typings/execution/ExecutionTools.d.ts +25 -25
- package/umd/typings/execution/NaturalExecutionTools.d.ts +23 -23
- package/umd/typings/execution/PromptResult.d.ts +74 -74
- package/umd/typings/execution/PromptbookExecutor.d.ts +39 -39
- package/umd/typings/execution/ScriptExecutionTools.d.ts +37 -37
- package/umd/typings/execution/UserInterfaceTools.d.ts +45 -45
- package/umd/typings/execution/assertsExecutionSuccessful.d.ts +11 -11
- package/umd/typings/execution/createPromptbookExecutor.d.ts +41 -41
- package/umd/typings/execution/plugins/natural-execution-tools/mocked/MockedEchoNaturalExecutionTools.d.ts +22 -22
- package/umd/typings/execution/plugins/natural-execution-tools/mocked/joker.test.d.ts +4 -4
- package/umd/typings/execution/plugins/natural-execution-tools/mocked/mocked-chat.test.d.ts +4 -4
- package/umd/typings/execution/plugins/natural-execution-tools/mocked/mocked-completion.test.d.ts +4 -4
- package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools.d.ts +28 -28
- package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +16 -16
- package/umd/typings/execution/plugins/natural-execution-tools/openai/computeOpenaiUsage.d.ts +3 -3
- package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionTools.d.ts +35 -35
- package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +23 -23
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Promptbook_Server_Error.d.ts +11 -11
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Promptbook_Server_Progress.d.ts +12 -12
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Promptbook_Server_Request.d.ts +17 -17
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Promptbook_Server_Response.d.ts +12 -12
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +27 -27
- package/umd/typings/execution/plugins/natural-execution-tools/remote/startRemoteServer.d.ts +17 -17
- package/umd/typings/execution/plugins/script-execution-tools/custom-function-async.test.ts.test.d.ts +1 -1
- package/umd/typings/execution/plugins/script-execution-tools/custom-function-missing.test.d.ts +1 -1
- package/umd/typings/execution/plugins/script-execution-tools/custom-function-with-dependencies.test.d.ts +1 -1
- package/umd/typings/execution/plugins/script-execution-tools/custom-function.test.d.ts +1 -1
- package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.d.ts +20 -20
- package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -4
- package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools.d.ts +20 -20
- package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionToolsOptions.d.ts +22 -22
- package/umd/typings/execution/plugins/script-execution-tools/javascript/utils/preserve.d.ts +11 -11
- package/umd/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +1 -1
- package/umd/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +15 -15
- package/umd/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +1 -1
- package/umd/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +1 -1
- package/umd/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +15 -15
- package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +14 -14
- package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +12 -12
- package/umd/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +16 -16
- package/umd/typings/execution/plugins/user-interface-execution-tools/user-interface-execution-tools.test.d.ts +1 -1
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +4 -4
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +9 -9
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +5 -5
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +11 -11
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +4 -4
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +1 -1
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.test.d.ts +1 -1
- package/umd/typings/execution/translation/automatic-translate/translateMessages.d.ts +5 -5
- package/umd/typings/execution/utils/replaceParameters.d.ts +12 -12
- package/umd/typings/execution/utils/replaceParameters.test.d.ts +1 -1
- package/umd/typings/library/PromptbookLibrary.d.ts +25 -25
- package/umd/typings/library/SimplePromptbookLibrary.d.ts +35 -35
- package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +5 -5
- package/umd/typings/library/constructors/createPromptbookLibraryFromList.d.ts +5 -5
- package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +7 -7
- package/umd/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +16 -16
- package/umd/typings/library/constructors/createPromptbookSublibrary.d.ts +6 -6
- package/umd/typings/types/Command.d.ts +98 -98
- package/umd/typings/types/ExecutionTypes.d.ts +13 -13
- package/umd/typings/types/ModelRequirements.d.ts +41 -41
- package/umd/typings/types/Parameters.d.ts +14 -14
- package/umd/typings/types/Prompt.d.ts +41 -41
- package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +126 -126
- package/umd/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +25 -25
- package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +51 -51
- package/umd/typings/types/PromptbookString.d.ts +12 -12
- package/umd/typings/types/ScriptLanguage.d.ts +9 -9
- package/umd/typings/types/TaskProgress.d.ts +42 -42
- package/umd/typings/types/execution-report/ExecutionReportJson.d.ts +56 -56
- package/umd/typings/types/execution-report/ExecutionReportString.d.ts +16 -16
- package/umd/typings/types/execution-report/ExecutionReportStringOptions.d.ts +21 -21
- package/umd/typings/types/execution-report/config.d.ts +8 -8
- package/umd/typings/types/execution-report/countWorkingDuration.d.ts +7 -7
- package/umd/typings/types/execution-report/countWorkingDuration.test.d.ts +1 -1
- package/umd/typings/types/execution-report/executionReportJsonToString.d.ts +11 -11
- package/umd/typings/types/execution-report/executionReportJsonToString.test.d.ts +1 -1
- package/umd/typings/types/typeAliasEmoji.d.ts +9 -9
- package/umd/typings/types/typeAliases.d.ts +432 -432
- package/umd/typings/utils/FromtoItems.d.ts +19 -19
- package/umd/typings/utils/emojis.d.ts +22 -22
- package/umd/typings/utils/expectation-counters/countCharacters.d.ts +5 -5
- package/umd/typings/utils/expectation-counters/countCharacters.test.d.ts +1 -1
- package/umd/typings/utils/expectation-counters/countLines.d.ts +5 -5
- package/umd/typings/utils/expectation-counters/countLines.test.d.ts +1 -1
- package/umd/typings/utils/expectation-counters/countPages.d.ts +5 -5
- package/umd/typings/utils/expectation-counters/countPages.test.d.ts +1 -1
- package/umd/typings/utils/expectation-counters/countParagraphs.d.ts +5 -5
- package/umd/typings/utils/expectation-counters/countParagraphs.test.d.ts +1 -1
- package/umd/typings/utils/expectation-counters/countSentences.d.ts +5 -5
- package/umd/typings/utils/expectation-counters/countSentences.test.d.ts +1 -1
- package/umd/typings/utils/expectation-counters/countWords.d.ts +5 -5
- package/umd/typings/utils/expectation-counters/countWords.test.d.ts +1 -1
- package/umd/typings/utils/expectation-counters/index.d.ts +5 -5
- package/umd/typings/utils/extractParameters.d.ts +10 -10
- package/umd/typings/utils/extractParameters.test.d.ts +1 -1
- package/umd/typings/utils/formatNumber.d.ts +6 -6
- package/umd/typings/utils/formatNumber.test.d.ts +1 -1
- package/umd/typings/utils/getCurrentIsoDate.d.ts +7 -7
- package/umd/typings/utils/isRunningInWhatever.d.ts +12 -12
- package/umd/typings/utils/isValidJsonString.d.ts +4 -4
- package/umd/typings/utils/isValidJsonString.test.d.ts +1 -1
- package/umd/typings/utils/just.d.ts +10 -10
- package/umd/typings/utils/markdown/addAutoGeneratedSection.d.ts +10 -10
- package/umd/typings/utils/markdown/addAutoGeneratedSection.test.d.ts +1 -1
- package/umd/typings/utils/markdown/createMarkdownChart.d.ts +41 -41
- package/umd/typings/utils/markdown/createMarkdownChart.test.d.ts +1 -1
- package/umd/typings/utils/markdown/createMarkdownTable.d.ts +7 -7
- package/umd/typings/utils/markdown/createMarkdownTable.test.d.ts +1 -1
- package/umd/typings/utils/markdown/escapeMarkdownBlock.d.ts +6 -6
- package/umd/typings/utils/markdown/escapeMarkdownBlock.test.d.ts +1 -1
- package/umd/typings/utils/markdown/extractAllBlocksFromMarkdown.d.ts +27 -27
- package/umd/typings/utils/markdown/extractAllBlocksFromMarkdown.test.d.ts +1 -1
- package/umd/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +13 -13
- package/umd/typings/utils/markdown/extractAllListItemsFromMarkdown.test.d.ts +1 -1
- package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +19 -19
- package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.test.d.ts +1 -1
- package/umd/typings/utils/markdown/prettifyMarkdown.d.ts +8 -8
- package/umd/typings/utils/markdown/prettifyMarkdown.test.d.ts +1 -1
- package/umd/typings/utils/markdown/removeContentComments.d.ts +8 -8
- package/umd/typings/utils/markdown/removeContentComments.test.d.ts +1 -1
- package/umd/typings/utils/markdown/removeMarkdownFormatting.d.ts +8 -8
- package/umd/typings/utils/markdown/removeMarkdownFormatting.test.d.ts +1 -1
- package/umd/typings/utils/markdown-json/MarkdownStructure.d.ts +25 -25
- package/umd/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +7 -7
- package/umd/typings/utils/markdown-json/countMarkdownStructureDeepness.test.d.ts +1 -1
- package/umd/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +13 -13
- package/umd/typings/utils/markdown-json/markdownToMarkdownStructure.test.d.ts +1 -1
- package/umd/typings/utils/postprocessing/extractBlock.d.ts +12 -12
- package/umd/typings/utils/removeEmojis.d.ts +7 -7
- package/umd/typings/utils/removeEmojis.test.d.ts +1 -1
- package/umd/typings/utils/removeQuotes.d.ts +13 -13
- package/umd/typings/utils/removeQuotes.test.d.ts +1 -1
- package/umd/typings/utils/trimCodeBlock.d.ts +8 -8
- package/umd/typings/utils/trimCodeBlock.test.d.ts +1 -1
- package/umd/typings/utils/trimEndOfCodeBlock.d.ts +7 -7
- package/umd/typings/utils/trimEndOfCodeBlock.test.d.ts +1 -1
- package/umd/typings/utils/unwrapResult.d.ts +36 -36
- package/umd/typings/utils/unwrapResult.test.d.ts +1 -1
- package/umd/typings/utils/validators/url/isValidUrl.d.ts +7 -7
- package/umd/typings/utils/validators/url/isValidUrl.test.d.ts +1 -1
- package/umd/typings/version.d.ts +5 -5
- package/umd/typings/wizzard/Wizzard.d.ts +4 -4
- package/umd/typings/wizzard/sample.d.ts +6 -6
package/umd/index.umd.js
CHANGED
|
@@ -91,858 +91,858 @@
|
|
|
91
91
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
/**
|
|
95
|
-
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
96
|
-
*/
|
|
97
|
-
var PromptbookSyntaxError = /** @class */ (function (_super) {
|
|
98
|
-
__extends(PromptbookSyntaxError, _super);
|
|
99
|
-
function PromptbookSyntaxError(message) {
|
|
100
|
-
var _this = _super.call(this, message) || this;
|
|
101
|
-
_this.name = 'PromptbookSyntaxError';
|
|
102
|
-
Object.setPrototypeOf(_this, PromptbookSyntaxError.prototype);
|
|
103
|
-
return _this;
|
|
104
|
-
}
|
|
105
|
-
return PromptbookSyntaxError;
|
|
94
|
+
/**
|
|
95
|
+
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
96
|
+
*/
|
|
97
|
+
var PromptbookSyntaxError = /** @class */ (function (_super) {
|
|
98
|
+
__extends(PromptbookSyntaxError, _super);
|
|
99
|
+
function PromptbookSyntaxError(message) {
|
|
100
|
+
var _this = _super.call(this, message) || this;
|
|
101
|
+
_this.name = 'PromptbookSyntaxError';
|
|
102
|
+
Object.setPrototypeOf(_this, PromptbookSyntaxError.prototype);
|
|
103
|
+
return _this;
|
|
104
|
+
}
|
|
105
|
+
return PromptbookSyntaxError;
|
|
106
106
|
}(Error));
|
|
107
107
|
|
|
108
|
-
/**
|
|
109
|
-
* Function parseNumber will parse number from string
|
|
110
|
-
*
|
|
111
|
-
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
112
|
-
* Note: it also works only with decimal numbers
|
|
113
|
-
*
|
|
114
|
-
* @private within the parseCommand
|
|
115
|
-
*/
|
|
116
|
-
function parseNumber(value) {
|
|
117
|
-
var originalValue = value;
|
|
118
|
-
if (typeof value === 'number') {
|
|
119
|
-
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
120
|
-
}
|
|
121
|
-
if (typeof value !== 'string') {
|
|
122
|
-
return 0;
|
|
123
|
-
}
|
|
124
|
-
value = value.trim();
|
|
125
|
-
if (value.startsWith('+')) {
|
|
126
|
-
return parseNumber(value.substring(1));
|
|
127
|
-
}
|
|
128
|
-
if (value.startsWith('-')) {
|
|
129
|
-
var number = parseNumber(value.substring(1));
|
|
130
|
-
if (number === 0) {
|
|
131
|
-
return 0; // <- Note: To prevent -0
|
|
132
|
-
}
|
|
133
|
-
return -number;
|
|
134
|
-
}
|
|
135
|
-
value = value.replace(/,/g, '.');
|
|
136
|
-
value = value.toUpperCase();
|
|
137
|
-
if (value === '') {
|
|
138
|
-
return 0;
|
|
139
|
-
}
|
|
140
|
-
if (value === '♾' || value.startsWith('INF')) {
|
|
141
|
-
return Infinity;
|
|
142
|
-
}
|
|
143
|
-
if (value.includes('/')) {
|
|
144
|
-
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
145
|
-
var numerator = parseNumber(numerator_);
|
|
146
|
-
var denominator = parseNumber(denominator_);
|
|
147
|
-
if (denominator === 0) {
|
|
148
|
-
throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
149
|
-
}
|
|
150
|
-
return numerator / denominator;
|
|
151
|
-
}
|
|
152
|
-
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
153
|
-
return 0;
|
|
154
|
-
}
|
|
155
|
-
if (value.includes('E')) {
|
|
156
|
-
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
157
|
-
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
158
|
-
}
|
|
159
|
-
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
160
|
-
throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
161
|
-
}
|
|
162
|
-
var num = parseFloat(value);
|
|
163
|
-
if (isNaN(num)) {
|
|
164
|
-
throw new PromptbookSyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
165
|
-
}
|
|
166
|
-
return num;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
170
|
-
*/
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* This error indicates errors during the execution of the promptbook
|
|
174
|
-
*/
|
|
175
|
-
var PromptbookExecutionError = /** @class */ (function (_super) {
|
|
176
|
-
__extends(PromptbookExecutionError, _super);
|
|
177
|
-
function PromptbookExecutionError(message) {
|
|
178
|
-
var _this = _super.call(this, message) || this;
|
|
179
|
-
_this.name = 'PromptbookExecutionError';
|
|
180
|
-
Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
|
|
181
|
-
return _this;
|
|
182
|
-
}
|
|
183
|
-
return PromptbookExecutionError;
|
|
108
|
+
/**
|
|
109
|
+
* Function parseNumber will parse number from string
|
|
110
|
+
*
|
|
111
|
+
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
112
|
+
* Note: it also works only with decimal numbers
|
|
113
|
+
*
|
|
114
|
+
* @private within the parseCommand
|
|
115
|
+
*/
|
|
116
|
+
function parseNumber(value) {
|
|
117
|
+
var originalValue = value;
|
|
118
|
+
if (typeof value === 'number') {
|
|
119
|
+
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
120
|
+
}
|
|
121
|
+
if (typeof value !== 'string') {
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
value = value.trim();
|
|
125
|
+
if (value.startsWith('+')) {
|
|
126
|
+
return parseNumber(value.substring(1));
|
|
127
|
+
}
|
|
128
|
+
if (value.startsWith('-')) {
|
|
129
|
+
var number = parseNumber(value.substring(1));
|
|
130
|
+
if (number === 0) {
|
|
131
|
+
return 0; // <- Note: To prevent -0
|
|
132
|
+
}
|
|
133
|
+
return -number;
|
|
134
|
+
}
|
|
135
|
+
value = value.replace(/,/g, '.');
|
|
136
|
+
value = value.toUpperCase();
|
|
137
|
+
if (value === '') {
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
if (value === '♾' || value.startsWith('INF')) {
|
|
141
|
+
return Infinity;
|
|
142
|
+
}
|
|
143
|
+
if (value.includes('/')) {
|
|
144
|
+
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
145
|
+
var numerator = parseNumber(numerator_);
|
|
146
|
+
var denominator = parseNumber(denominator_);
|
|
147
|
+
if (denominator === 0) {
|
|
148
|
+
throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
149
|
+
}
|
|
150
|
+
return numerator / denominator;
|
|
151
|
+
}
|
|
152
|
+
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
153
|
+
return 0;
|
|
154
|
+
}
|
|
155
|
+
if (value.includes('E')) {
|
|
156
|
+
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
157
|
+
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
158
|
+
}
|
|
159
|
+
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
160
|
+
throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
161
|
+
}
|
|
162
|
+
var num = parseFloat(value);
|
|
163
|
+
if (isNaN(num)) {
|
|
164
|
+
throw new PromptbookSyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
165
|
+
}
|
|
166
|
+
return num;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* This error indicates errors during the execution of the promptbook
|
|
174
|
+
*/
|
|
175
|
+
var PromptbookExecutionError = /** @class */ (function (_super) {
|
|
176
|
+
__extends(PromptbookExecutionError, _super);
|
|
177
|
+
function PromptbookExecutionError(message) {
|
|
178
|
+
var _this = _super.call(this, message) || this;
|
|
179
|
+
_this.name = 'PromptbookExecutionError';
|
|
180
|
+
Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
|
|
181
|
+
return _this;
|
|
182
|
+
}
|
|
183
|
+
return PromptbookExecutionError;
|
|
184
184
|
}(Error));
|
|
185
185
|
|
|
186
|
-
/**
|
|
187
|
-
* Asserts that the execution of a promptnook is successful
|
|
188
|
-
*
|
|
189
|
-
* @param executionResult - The partial result of the promptnook execution
|
|
190
|
-
* @throws Error - If the execution is not successful or if multiple errors occurred
|
|
191
|
-
*/
|
|
192
|
-
function assertsExecutionSuccessful(executionResult) {
|
|
193
|
-
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
194
|
-
if (isSuccessful === true) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
if (errors.length === 0) {
|
|
198
|
-
throw new PromptbookExecutionError("Promptnook Execution failed because of unknown reason");
|
|
199
|
-
}
|
|
200
|
-
else if (errors.length === 1) {
|
|
201
|
-
throw errors[0];
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
throw new PromptbookExecutionError(spaceTrim__default["default"](function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* TODO: [🧠] Can this return type be better typed than void
|
|
186
|
+
/**
|
|
187
|
+
* Asserts that the execution of a promptnook is successful
|
|
188
|
+
*
|
|
189
|
+
* @param executionResult - The partial result of the promptnook execution
|
|
190
|
+
* @throws Error - If the execution is not successful or if multiple errors occurred
|
|
191
|
+
*/
|
|
192
|
+
function assertsExecutionSuccessful(executionResult) {
|
|
193
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
194
|
+
if (isSuccessful === true) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (errors.length === 0) {
|
|
198
|
+
throw new PromptbookExecutionError("Promptnook Execution failed because of unknown reason");
|
|
199
|
+
}
|
|
200
|
+
else if (errors.length === 1) {
|
|
201
|
+
throw errors[0];
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
throw new PromptbookExecutionError(spaceTrim__default["default"](function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* TODO: [🧠] Can this return type be better typed than void
|
|
209
209
|
*/
|
|
210
210
|
|
|
211
|
-
/**
|
|
212
|
-
* Default options for generating an execution report string
|
|
213
|
-
*/
|
|
214
|
-
var ExecutionReportStringOptionsDefaults = {
|
|
215
|
-
taxRate: 0,
|
|
216
|
-
chartsWidth: 36,
|
|
211
|
+
/**
|
|
212
|
+
* Default options for generating an execution report string
|
|
213
|
+
*/
|
|
214
|
+
var ExecutionReportStringOptionsDefaults = {
|
|
215
|
+
taxRate: 0,
|
|
216
|
+
chartsWidth: 36,
|
|
217
217
|
};
|
|
218
218
|
|
|
219
|
-
/**
|
|
220
|
-
* Format either small or big number
|
|
221
|
-
*
|
|
222
|
-
* @private within the library
|
|
223
|
-
*/
|
|
224
|
-
function formatNumber(value) {
|
|
225
|
-
if (value === 0) {
|
|
226
|
-
return '0';
|
|
227
|
-
}
|
|
228
|
-
for (var exponent = 0; exponent < 15; exponent++) {
|
|
229
|
-
var factor = Math.pow(10, exponent);
|
|
230
|
-
var valueRounded = Math.round(value * factor) / factor;
|
|
231
|
-
if (Math.abs(value - valueRounded) / value <
|
|
232
|
-
0.001 /* <- TODO: Pass as option, pass to executionReportJsonToString as option */) {
|
|
233
|
-
return valueRounded.toFixed(exponent);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return value.toString();
|
|
219
|
+
/**
|
|
220
|
+
* Format either small or big number
|
|
221
|
+
*
|
|
222
|
+
* @private within the library
|
|
223
|
+
*/
|
|
224
|
+
function formatNumber(value) {
|
|
225
|
+
if (value === 0) {
|
|
226
|
+
return '0';
|
|
227
|
+
}
|
|
228
|
+
for (var exponent = 0; exponent < 15; exponent++) {
|
|
229
|
+
var factor = Math.pow(10, exponent);
|
|
230
|
+
var valueRounded = Math.round(value * factor) / factor;
|
|
231
|
+
if (Math.abs(value - valueRounded) / value <
|
|
232
|
+
0.001 /* <- TODO: Pass as option, pass to executionReportJsonToString as option */) {
|
|
233
|
+
return valueRounded.toFixed(exponent);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return value.toString();
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
/**
|
|
240
|
-
* Returns the same value that is passed as argument.
|
|
241
|
-
* No side effects.
|
|
242
|
-
*
|
|
243
|
-
* Note: It can be usefull for leveling indentation
|
|
244
|
-
*
|
|
245
|
-
* @param value any values
|
|
246
|
-
* @returns the same values
|
|
247
|
-
*/
|
|
248
|
-
function just(value) {
|
|
249
|
-
if (value === undefined) {
|
|
250
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
251
|
-
return undefined;
|
|
252
|
-
}
|
|
253
|
-
return value;
|
|
239
|
+
/**
|
|
240
|
+
* Returns the same value that is passed as argument.
|
|
241
|
+
* No side effects.
|
|
242
|
+
*
|
|
243
|
+
* Note: It can be usefull for leveling indentation
|
|
244
|
+
*
|
|
245
|
+
* @param value any values
|
|
246
|
+
* @returns the same values
|
|
247
|
+
*/
|
|
248
|
+
function just(value) {
|
|
249
|
+
if (value === undefined) {
|
|
250
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
return value;
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
-
/**
|
|
257
|
-
* Removes emojis from a string and fix whitespaces
|
|
258
|
-
*
|
|
259
|
-
* @param text with emojis
|
|
260
|
-
* @returns text without emojis
|
|
261
|
-
*/
|
|
262
|
-
function removeEmojis(text) {
|
|
263
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
264
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
265
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
266
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
267
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
268
|
-
return text;
|
|
256
|
+
/**
|
|
257
|
+
* Removes emojis from a string and fix whitespaces
|
|
258
|
+
*
|
|
259
|
+
* @param text with emojis
|
|
260
|
+
* @returns text without emojis
|
|
261
|
+
*/
|
|
262
|
+
function removeEmojis(text) {
|
|
263
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
264
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
265
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
266
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
267
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
268
|
+
return text;
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
-
/**
|
|
272
|
-
* Create a markdown table from a 2D array of strings
|
|
273
|
-
*
|
|
274
|
-
* @private within the library
|
|
275
|
-
*/
|
|
276
|
-
function createMarkdownTable(table) {
|
|
277
|
-
var columnWidths = table.reduce(function (widths, row) {
|
|
278
|
-
row.forEach(function (cell, columnIndex) {
|
|
279
|
-
var cellLength = cell.length;
|
|
280
|
-
if (!widths[columnIndex] || cellLength > widths[columnIndex]) {
|
|
281
|
-
widths[columnIndex] = cellLength;
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
return widths;
|
|
285
|
-
}, []);
|
|
286
|
-
var header = "| ".concat(table[0]
|
|
287
|
-
.map(function (cell, columnIndex) { return cell.padEnd(columnWidths[columnIndex]); })
|
|
288
|
-
.join(' | '), " |");
|
|
289
|
-
var separator = "|".concat(columnWidths.map(function (width) { return '-'.repeat(width + 2); }).join('|'), "|");
|
|
290
|
-
var rows = table.slice(1).map(function (row) {
|
|
291
|
-
var paddedRow = row.map(function (cell, columnIndex) {
|
|
292
|
-
return cell.padEnd(columnWidths[columnIndex]);
|
|
293
|
-
});
|
|
294
|
-
return "| ".concat(paddedRow.join(' | '), " |");
|
|
295
|
-
});
|
|
296
|
-
return __spreadArray([header, separator], __read(rows), false).join('\n');
|
|
271
|
+
/**
|
|
272
|
+
* Create a markdown table from a 2D array of strings
|
|
273
|
+
*
|
|
274
|
+
* @private within the library
|
|
275
|
+
*/
|
|
276
|
+
function createMarkdownTable(table) {
|
|
277
|
+
var columnWidths = table.reduce(function (widths, row) {
|
|
278
|
+
row.forEach(function (cell, columnIndex) {
|
|
279
|
+
var cellLength = cell.length;
|
|
280
|
+
if (!widths[columnIndex] || cellLength > widths[columnIndex]) {
|
|
281
|
+
widths[columnIndex] = cellLength;
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
return widths;
|
|
285
|
+
}, []);
|
|
286
|
+
var header = "| ".concat(table[0]
|
|
287
|
+
.map(function (cell, columnIndex) { return cell.padEnd(columnWidths[columnIndex]); })
|
|
288
|
+
.join(' | '), " |");
|
|
289
|
+
var separator = "|".concat(columnWidths.map(function (width) { return '-'.repeat(width + 2); }).join('|'), "|");
|
|
290
|
+
var rows = table.slice(1).map(function (row) {
|
|
291
|
+
var paddedRow = row.map(function (cell, columnIndex) {
|
|
292
|
+
return cell.padEnd(columnWidths[columnIndex]);
|
|
293
|
+
});
|
|
294
|
+
return "| ".concat(paddedRow.join(' | '), " |");
|
|
295
|
+
});
|
|
296
|
+
return __spreadArray([header, separator], __read(rows), false).join('\n');
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
-
/**
|
|
300
|
-
* Function createMarkdownChart will draw a chart in markdown from ⬛+🟦 tiles
|
|
301
|
-
*
|
|
302
|
-
* @private within the library
|
|
303
|
-
*/
|
|
304
|
-
function createMarkdownChart(options) {
|
|
305
|
-
var e_1, _a;
|
|
306
|
-
var nameHeader = options.nameHeader, valueHeader = options.valueHeader, items = options.items, width = options.width, unitName = options.unitName;
|
|
307
|
-
var from = Math.min.apply(Math, __spreadArray([], __read(items.map(function (item) { return item.from; })), false));
|
|
308
|
-
var to = Math.max.apply(Math, __spreadArray([], __read(items.map(function (item) { return item.to; })), false));
|
|
309
|
-
var scale = width / (to - from);
|
|
310
|
-
var table = [[nameHeader, valueHeader]];
|
|
311
|
-
try {
|
|
312
|
-
for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
313
|
-
var item = items_1_1.value;
|
|
314
|
-
var before = Math.round((item.from - from) * scale);
|
|
315
|
-
var during = Math.round((item.to - item.from) * scale);
|
|
316
|
-
var after = width - before - during;
|
|
317
|
-
table.push([removeEmojis(item.title).trim(), '░'.repeat(before) + '█'.repeat(during) + '░'.repeat(after)]);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
321
|
-
finally {
|
|
322
|
-
try {
|
|
323
|
-
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
324
|
-
}
|
|
325
|
-
finally { if (e_1) throw e_1.error; }
|
|
326
|
-
}
|
|
327
|
-
var legend = "_Note: Each \u2588 represents ".concat(formatNumber(1 / scale), " ").concat(unitName, ", width of ").concat(valueHeader.toLowerCase(), " is ").concat(formatNumber(to - from), " ").concat(unitName, " = ").concat(width, " squares_");
|
|
328
|
-
return createMarkdownTable(table) + '\n\n' + legend;
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* TODO: Maybe use Mermain Gant Diagrams
|
|
332
|
-
* @see https://jojozhuang.github.io/tutorial/mermaid-cheat-sheet/
|
|
299
|
+
/**
|
|
300
|
+
* Function createMarkdownChart will draw a chart in markdown from ⬛+🟦 tiles
|
|
301
|
+
*
|
|
302
|
+
* @private within the library
|
|
303
|
+
*/
|
|
304
|
+
function createMarkdownChart(options) {
|
|
305
|
+
var e_1, _a;
|
|
306
|
+
var nameHeader = options.nameHeader, valueHeader = options.valueHeader, items = options.items, width = options.width, unitName = options.unitName;
|
|
307
|
+
var from = Math.min.apply(Math, __spreadArray([], __read(items.map(function (item) { return item.from; })), false));
|
|
308
|
+
var to = Math.max.apply(Math, __spreadArray([], __read(items.map(function (item) { return item.to; })), false));
|
|
309
|
+
var scale = width / (to - from);
|
|
310
|
+
var table = [[nameHeader, valueHeader]];
|
|
311
|
+
try {
|
|
312
|
+
for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
313
|
+
var item = items_1_1.value;
|
|
314
|
+
var before = Math.round((item.from - from) * scale);
|
|
315
|
+
var during = Math.round((item.to - item.from) * scale);
|
|
316
|
+
var after = width - before - during;
|
|
317
|
+
table.push([removeEmojis(item.title).trim(), '░'.repeat(before) + '█'.repeat(during) + '░'.repeat(after)]);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
321
|
+
finally {
|
|
322
|
+
try {
|
|
323
|
+
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
324
|
+
}
|
|
325
|
+
finally { if (e_1) throw e_1.error; }
|
|
326
|
+
}
|
|
327
|
+
var legend = "_Note: Each \u2588 represents ".concat(formatNumber(1 / scale), " ").concat(unitName, ", width of ").concat(valueHeader.toLowerCase(), " is ").concat(formatNumber(to - from), " ").concat(unitName, " = ").concat(width, " squares_");
|
|
328
|
+
return createMarkdownTable(table) + '\n\n' + legend;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* TODO: Maybe use Mermain Gant Diagrams
|
|
332
|
+
* @see https://jojozhuang.github.io/tutorial/mermaid-cheat-sheet/
|
|
333
333
|
*/
|
|
334
334
|
|
|
335
|
-
/**
|
|
336
|
-
* Function escapeMarkdownBlock will escape markdown block if needed
|
|
337
|
-
* It is useful when you want have block in block
|
|
338
|
-
*/
|
|
339
|
-
function escapeMarkdownBlock(value) {
|
|
340
|
-
return value.replace(/```/g, '\\`\\`\\`');
|
|
335
|
+
/**
|
|
336
|
+
* Function escapeMarkdownBlock will escape markdown block if needed
|
|
337
|
+
* It is useful when you want have block in block
|
|
338
|
+
*/
|
|
339
|
+
function escapeMarkdownBlock(value) {
|
|
340
|
+
return value.replace(/```/g, '\\`\\`\\`');
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
-
/**
|
|
344
|
-
* Prettify the html code
|
|
345
|
-
*
|
|
346
|
-
* @param html raw html code
|
|
347
|
-
* @returns formatted html code
|
|
348
|
-
*/
|
|
349
|
-
function prettifyMarkdown(html) {
|
|
350
|
-
try {
|
|
351
|
-
return prettier.format(html, {
|
|
352
|
-
parser: 'markdown',
|
|
353
|
-
plugins: [parserHtml__default["default"]],
|
|
354
|
-
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
355
|
-
endOfLine: 'lf',
|
|
356
|
-
tabWidth: 4,
|
|
357
|
-
singleQuote: true,
|
|
358
|
-
trailingComma: 'all',
|
|
359
|
-
arrowParens: 'always',
|
|
360
|
-
printWidth: 120,
|
|
361
|
-
htmlWhitespaceSensitivity: 'ignore',
|
|
362
|
-
jsxBracketSameLine: false,
|
|
363
|
-
bracketSpacing: true,
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
catch (error) {
|
|
367
|
-
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
368
|
-
error: error,
|
|
369
|
-
html: html,
|
|
370
|
-
});
|
|
371
|
-
return html;
|
|
372
|
-
}
|
|
343
|
+
/**
|
|
344
|
+
* Prettify the html code
|
|
345
|
+
*
|
|
346
|
+
* @param html raw html code
|
|
347
|
+
* @returns formatted html code
|
|
348
|
+
*/
|
|
349
|
+
function prettifyMarkdown(html) {
|
|
350
|
+
try {
|
|
351
|
+
return prettier.format(html, {
|
|
352
|
+
parser: 'markdown',
|
|
353
|
+
plugins: [parserHtml__default["default"]],
|
|
354
|
+
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
355
|
+
endOfLine: 'lf',
|
|
356
|
+
tabWidth: 4,
|
|
357
|
+
singleQuote: true,
|
|
358
|
+
trailingComma: 'all',
|
|
359
|
+
arrowParens: 'always',
|
|
360
|
+
printWidth: 120,
|
|
361
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
362
|
+
jsxBracketSameLine: false,
|
|
363
|
+
bracketSpacing: true,
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
catch (error) {
|
|
367
|
+
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
368
|
+
error: error,
|
|
369
|
+
html: html,
|
|
370
|
+
});
|
|
371
|
+
return html;
|
|
372
|
+
}
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
-
/**
|
|
376
|
-
* The thresholds for the relative time in the `moment` library.
|
|
377
|
-
*
|
|
378
|
-
* @see https://momentjscom.readthedocs.io/en/latest/moment/07-customization/13-relative-time-threshold/
|
|
379
|
-
*/
|
|
380
|
-
var MOMENT_ARG_THRESHOLDS = {
|
|
381
|
-
ss: 3, // <- least number of seconds to be counted in seconds, minus 1. Must be set after setting the `s` unit or without setting the `s` unit.
|
|
375
|
+
/**
|
|
376
|
+
* The thresholds for the relative time in the `moment` library.
|
|
377
|
+
*
|
|
378
|
+
* @see https://momentjscom.readthedocs.io/en/latest/moment/07-customization/13-relative-time-threshold/
|
|
379
|
+
*/
|
|
380
|
+
var MOMENT_ARG_THRESHOLDS = {
|
|
381
|
+
ss: 3, // <- least number of seconds to be counted in seconds, minus 1. Must be set after setting the `s` unit or without setting the `s` unit.
|
|
382
382
|
};
|
|
383
383
|
|
|
384
|
-
/**
|
|
385
|
-
* Count the duration of working time
|
|
386
|
-
*
|
|
387
|
-
* @private within the library
|
|
388
|
-
*/
|
|
389
|
-
function countWorkingDuration(items) {
|
|
390
|
-
var e_1, _a;
|
|
391
|
-
var steps = Array.from(new Set(items.flatMap(function (item) { return [item.from, item.to]; })));
|
|
392
|
-
steps.sort(function (a, b) { return a - b; });
|
|
393
|
-
var intervals = steps.map(function (step, index) { return [step, steps[index + 1] || 0]; }).slice(0, -1);
|
|
394
|
-
var duration = 0;
|
|
395
|
-
var _loop_1 = function (interval) {
|
|
396
|
-
var _b = __read(interval, 2), from = _b[0], to = _b[1];
|
|
397
|
-
if (items.some(function (item) { return item.from < to && item.to > from; })) {
|
|
398
|
-
duration += to - from;
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
try {
|
|
402
|
-
for (var intervals_1 = __values(intervals), intervals_1_1 = intervals_1.next(); !intervals_1_1.done; intervals_1_1 = intervals_1.next()) {
|
|
403
|
-
var interval = intervals_1_1.value;
|
|
404
|
-
_loop_1(interval);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
408
|
-
finally {
|
|
409
|
-
try {
|
|
410
|
-
if (intervals_1_1 && !intervals_1_1.done && (_a = intervals_1.return)) _a.call(intervals_1);
|
|
411
|
-
}
|
|
412
|
-
finally { if (e_1) throw e_1.error; }
|
|
413
|
-
}
|
|
414
|
-
return duration;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
/**
|
|
418
|
-
* Converts execution report from JSON to string format
|
|
419
|
-
*/
|
|
420
|
-
function executionReportJsonToString(executionReportJson, options) {
|
|
421
|
-
var e_1, _a;
|
|
422
|
-
var _b, _c, _d, _e, _f, _g;
|
|
423
|
-
var _h = __assign(__assign({}, ExecutionReportStringOptionsDefaults), (options || {})), taxRate = _h.taxRate, chartsWidth = _h.chartsWidth;
|
|
424
|
-
var executionReportString = spaceTrim__default["default"](function (block) { return "\n # ".concat(executionReportJson.title || 'Execution report', "\n\n ").concat(block(executionReportJson.description || ''), "\n "); });
|
|
425
|
-
var headerList = [];
|
|
426
|
-
if (executionReportJson.promptbookUrl) {
|
|
427
|
-
headerList.push("PROMPTBOOK URL ".concat(executionReportJson.promptbookUrl));
|
|
428
|
-
}
|
|
429
|
-
headerList.push("PROMPTBOOK VERSION ".concat(executionReportJson.promptbookUsedVersion) +
|
|
430
|
-
(!executionReportJson.promptbookRequestedVersion
|
|
431
|
-
? ''
|
|
432
|
-
: " *(requested ".concat(executionReportJson.promptbookRequestedVersion, ")*")));
|
|
433
|
-
if (executionReportJson.promptExecutions.length !== 0) {
|
|
434
|
-
// TODO: What if startedAt OR/AND completedAt is not defined?
|
|
435
|
-
var startedAt = moment__default["default"](Math.min.apply(Math, __spreadArray([], __read(executionReportJson.promptExecutions
|
|
436
|
-
.filter(function (promptExecution) { var _a, _b; return (_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.start; })
|
|
437
|
-
.map(function (promptExecution) { return moment__default["default"](promptExecution.result.timing.start).valueOf(); })), false)));
|
|
438
|
-
var completedAt = moment__default["default"](Math.max.apply(Math, __spreadArray([], __read(executionReportJson.promptExecutions
|
|
439
|
-
.filter(function (promptExecution) { var _a, _b; return (_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.complete; })
|
|
440
|
-
.map(function (promptExecution) { return moment__default["default"](promptExecution.result.timing.complete).valueOf(); })), false)));
|
|
441
|
-
var timingItems = executionReportJson.promptExecutions.map(function (promptExecution) {
|
|
442
|
-
var _a, _b, _c, _d;
|
|
443
|
-
return ({
|
|
444
|
-
title: promptExecution.prompt.title,
|
|
445
|
-
from: moment__default["default"]((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.start).valueOf() / 1000,
|
|
446
|
-
to: moment__default["default"]((_d = (_c = promptExecution.result) === null || _c === void 0 ? void 0 : _c.timing) === null || _d === void 0 ? void 0 : _d.complete).valueOf() / 1000,
|
|
447
|
-
});
|
|
448
|
-
});
|
|
449
|
-
var costItems = executionReportJson.promptExecutions
|
|
450
|
-
.filter(function (promptExecution) { var _a, _b; return typeof ((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) === 'number'; })
|
|
451
|
-
.map(function (promptExecution) {
|
|
452
|
-
var _a, _b;
|
|
453
|
-
return ({
|
|
454
|
-
title: promptExecution.prompt.title,
|
|
455
|
-
from: 0,
|
|
456
|
-
to: ((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) * (1 + taxRate),
|
|
457
|
-
});
|
|
458
|
-
});
|
|
459
|
-
var duration = moment__default["default"].duration(completedAt.diff(startedAt));
|
|
460
|
-
var naturalDuration = moment__default["default"].duration(countWorkingDuration(timingItems) * 1000);
|
|
461
|
-
var executionsWithKnownCost = executionReportJson.promptExecutions.filter(function (promptExecution) { var _a, _b; return (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) || 'UNKNOWN') !== 'UNKNOWN'; });
|
|
462
|
-
var cost = executionsWithKnownCost.reduce(function (cost, promptExecution) { return cost + (promptExecution.result.usage.price || 0); }, 0);
|
|
463
|
-
headerList.push("STARTED AT ".concat(moment__default["default"](startedAt).format("YYYY-MM-DD HH:mm:ss")));
|
|
464
|
-
headerList.push("COMPLETED AT ".concat(moment__default["default"](completedAt).format("YYYY-MM-DD HH:mm:ss")));
|
|
465
|
-
headerList.push("TOTAL DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
|
|
466
|
-
headerList.push("TOTAL NATURAL DURATION ".concat(naturalDuration.humanize(MOMENT_ARG_THRESHOLDS)));
|
|
467
|
-
headerList.push("TOTAL COST $".concat(formatNumber(cost * (1 + taxRate))) +
|
|
468
|
-
(executionsWithKnownCost.length === executionReportJson.promptExecutions.length
|
|
469
|
-
? ''
|
|
470
|
-
: " *(Some cost is unknown)*") +
|
|
471
|
-
(taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
|
|
472
|
-
executionReportString += '\n\n' + headerList.map(function (header) { return "- ".concat(header); }).join('\n');
|
|
473
|
-
executionReportString +=
|
|
474
|
-
'\n\n' +
|
|
475
|
-
'## 🗃 Index' +
|
|
476
|
-
'\n\n' +
|
|
477
|
-
executionReportJson.promptExecutions
|
|
478
|
-
.map(function (promptExecution) {
|
|
479
|
-
// TODO: Make some better system to convert hedings to links
|
|
480
|
-
var hash = n12.normalizeToKebabCase(promptExecution.prompt.title);
|
|
481
|
-
if (/^\s*\p{Extended_Pictographic}/u.test(promptExecution.prompt.title)) {
|
|
482
|
-
hash = '-' + hash;
|
|
483
|
-
}
|
|
484
|
-
// TODO: Make working hash link for the template in md + pdf
|
|
485
|
-
return "- [".concat(promptExecution.prompt.title, "](#").concat(hash, ")");
|
|
486
|
-
})
|
|
487
|
-
.join('\n');
|
|
488
|
-
executionReportString +=
|
|
489
|
-
'\n\n' +
|
|
490
|
-
'## ⌚ Time chart' +
|
|
491
|
-
'\n\n' +
|
|
492
|
-
createMarkdownChart({
|
|
493
|
-
nameHeader: 'Template',
|
|
494
|
-
valueHeader: 'Timeline',
|
|
495
|
-
items: timingItems,
|
|
496
|
-
width: chartsWidth,
|
|
497
|
-
unitName: 'seconds',
|
|
498
|
-
});
|
|
499
|
-
executionReportString +=
|
|
500
|
-
'\n\n' +
|
|
501
|
-
'## 💸 Cost chart' +
|
|
502
|
-
'\n\n' +
|
|
503
|
-
createMarkdownChart({
|
|
504
|
-
nameHeader: 'Template',
|
|
505
|
-
valueHeader: 'Cost',
|
|
506
|
-
items: costItems,
|
|
507
|
-
width: chartsWidth,
|
|
508
|
-
unitName: 'USD',
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
else {
|
|
512
|
-
headerList.push("TOTAL COST $0 *(Nothing executed)*");
|
|
513
|
-
}
|
|
514
|
-
var _loop_1 = function (promptExecution) {
|
|
515
|
-
executionReportString += '\n\n\n\n' + "## ".concat(promptExecution.prompt.title);
|
|
516
|
-
var templateList = [];
|
|
517
|
-
// TODO: What if startedAt OR/AND completedAt is not defined?
|
|
518
|
-
var startedAt = moment__default["default"]((_c = (_b = promptExecution.result) === null || _b === void 0 ? void 0 : _b.timing) === null || _c === void 0 ? void 0 : _c.start);
|
|
519
|
-
var completedAt = moment__default["default"]((_e = (_d = promptExecution.result) === null || _d === void 0 ? void 0 : _d.timing) === null || _e === void 0 ? void 0 : _e.complete);
|
|
520
|
-
var duration = moment__default["default"].duration(completedAt.diff(startedAt));
|
|
521
|
-
// Not need here:
|
|
522
|
-
// > templateList.push(`STARTED AT ${moment(startedAt).calendar()}`);
|
|
523
|
-
templateList.push("DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
|
|
524
|
-
if (typeof ((_g = (_f = promptExecution.result) === null || _f === void 0 ? void 0 : _f.usage) === null || _g === void 0 ? void 0 : _g.price) === 'number') {
|
|
525
|
-
templateList.push("COST $".concat(formatNumber(promptExecution.result.usage.price * (1 + taxRate))) +
|
|
526
|
-
(taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
|
|
527
|
-
}
|
|
528
|
-
else {
|
|
529
|
-
templateList.push("COST UNKNOWN");
|
|
530
|
-
}
|
|
531
|
-
executionReportString += '\n\n' + templateList.map(function (header) { return "- ".concat(header); }).join('\n');
|
|
532
|
-
/*
|
|
533
|
-
- MODEL VARIANT ${promptExecution.prompt.modelRequirements.modelVariant}
|
|
534
|
-
- MODEL NAME \`${promptExecution.result?.model}\` (requested \`${
|
|
535
|
-
promptExecution.prompt.modelRequirements.modelName
|
|
536
|
-
|
|
537
|
-
*/
|
|
538
|
-
if (just(true)) {
|
|
539
|
-
executionReportString +=
|
|
540
|
-
'\n\n\n\n' +
|
|
541
|
-
spaceTrim__default["default"](function (block) { return "\n\n ### Prompt\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.prompt.content)), "\n ```\n\n "); });
|
|
542
|
-
}
|
|
543
|
-
if (promptExecution.result && promptExecution.result.content) {
|
|
544
|
-
executionReportString +=
|
|
545
|
-
'\n\n\n\n' +
|
|
546
|
-
spaceTrim__default["default"](function (block) { return "\n\n ### Result\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.result.content)), "\n ```\n "); });
|
|
547
|
-
}
|
|
548
|
-
if (promptExecution.error && promptExecution.error.message) {
|
|
549
|
-
executionReportString +=
|
|
550
|
-
'\n\n\n\n' +
|
|
551
|
-
spaceTrim__default["default"](function (block) { return "\n\n ### Error\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.error.message)), "\n ```\n\n "); });
|
|
552
|
-
}
|
|
553
|
-
};
|
|
554
|
-
try {
|
|
555
|
-
for (var _j = __values(executionReportJson.promptExecutions), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
556
|
-
var promptExecution = _k.value;
|
|
557
|
-
_loop_1(promptExecution);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
561
|
-
finally {
|
|
562
|
-
try {
|
|
563
|
-
if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
|
|
564
|
-
}
|
|
565
|
-
finally { if (e_1) throw e_1.error; }
|
|
566
|
-
}
|
|
567
|
-
executionReportString = prettifyMarkdown(executionReportString);
|
|
568
|
-
return executionReportString;
|
|
384
|
+
/**
|
|
385
|
+
* Count the duration of working time
|
|
386
|
+
*
|
|
387
|
+
* @private within the library
|
|
388
|
+
*/
|
|
389
|
+
function countWorkingDuration(items) {
|
|
390
|
+
var e_1, _a;
|
|
391
|
+
var steps = Array.from(new Set(items.flatMap(function (item) { return [item.from, item.to]; })));
|
|
392
|
+
steps.sort(function (a, b) { return a - b; });
|
|
393
|
+
var intervals = steps.map(function (step, index) { return [step, steps[index + 1] || 0]; }).slice(0, -1);
|
|
394
|
+
var duration = 0;
|
|
395
|
+
var _loop_1 = function (interval) {
|
|
396
|
+
var _b = __read(interval, 2), from = _b[0], to = _b[1];
|
|
397
|
+
if (items.some(function (item) { return item.from < to && item.to > from; })) {
|
|
398
|
+
duration += to - from;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
try {
|
|
402
|
+
for (var intervals_1 = __values(intervals), intervals_1_1 = intervals_1.next(); !intervals_1_1.done; intervals_1_1 = intervals_1.next()) {
|
|
403
|
+
var interval = intervals_1_1.value;
|
|
404
|
+
_loop_1(interval);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
408
|
+
finally {
|
|
409
|
+
try {
|
|
410
|
+
if (intervals_1_1 && !intervals_1_1.done && (_a = intervals_1.return)) _a.call(intervals_1);
|
|
411
|
+
}
|
|
412
|
+
finally { if (e_1) throw e_1.error; }
|
|
413
|
+
}
|
|
414
|
+
return duration;
|
|
569
415
|
}
|
|
570
|
-
/**
|
|
571
|
-
* TODO: Add mermaid chart for every report
|
|
572
|
-
* TODO: [🧠] Allow to filter out some parts of the report by options
|
|
573
|
-
*/
|
|
574
416
|
|
|
575
|
-
/**
|
|
576
|
-
*
|
|
577
|
-
*/
|
|
578
|
-
function
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
417
|
+
/**
|
|
418
|
+
* Converts execution report from JSON to string format
|
|
419
|
+
*/
|
|
420
|
+
function executionReportJsonToString(executionReportJson, options) {
|
|
421
|
+
var e_1, _a;
|
|
422
|
+
var _b, _c, _d, _e, _f, _g;
|
|
423
|
+
var _h = __assign(__assign({}, ExecutionReportStringOptionsDefaults), (options || {})), taxRate = _h.taxRate, chartsWidth = _h.chartsWidth;
|
|
424
|
+
var executionReportString = spaceTrim__default["default"](function (block) { return "\n # ".concat(executionReportJson.title || 'Execution report', "\n\n ").concat(block(executionReportJson.description || ''), "\n "); });
|
|
425
|
+
var headerList = [];
|
|
426
|
+
if (executionReportJson.promptbookUrl) {
|
|
427
|
+
headerList.push("PROMPTBOOK URL ".concat(executionReportJson.promptbookUrl));
|
|
428
|
+
}
|
|
429
|
+
headerList.push("PROMPTBOOK VERSION ".concat(executionReportJson.promptbookUsedVersion) +
|
|
430
|
+
(!executionReportJson.promptbookRequestedVersion
|
|
431
|
+
? ''
|
|
432
|
+
: " *(requested ".concat(executionReportJson.promptbookRequestedVersion, ")*")));
|
|
433
|
+
if (executionReportJson.promptExecutions.length !== 0) {
|
|
434
|
+
// TODO: What if startedAt OR/AND completedAt is not defined?
|
|
435
|
+
var startedAt = moment__default["default"](Math.min.apply(Math, __spreadArray([], __read(executionReportJson.promptExecutions
|
|
436
|
+
.filter(function (promptExecution) { var _a, _b; return (_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.start; })
|
|
437
|
+
.map(function (promptExecution) { return moment__default["default"](promptExecution.result.timing.start).valueOf(); })), false)));
|
|
438
|
+
var completedAt = moment__default["default"](Math.max.apply(Math, __spreadArray([], __read(executionReportJson.promptExecutions
|
|
439
|
+
.filter(function (promptExecution) { var _a, _b; return (_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.complete; })
|
|
440
|
+
.map(function (promptExecution) { return moment__default["default"](promptExecution.result.timing.complete).valueOf(); })), false)));
|
|
441
|
+
var timingItems = executionReportJson.promptExecutions.map(function (promptExecution) {
|
|
442
|
+
var _a, _b, _c, _d;
|
|
443
|
+
return ({
|
|
444
|
+
title: promptExecution.prompt.title,
|
|
445
|
+
from: moment__default["default"]((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.start).valueOf() / 1000,
|
|
446
|
+
to: moment__default["default"]((_d = (_c = promptExecution.result) === null || _c === void 0 ? void 0 : _c.timing) === null || _d === void 0 ? void 0 : _d.complete).valueOf() / 1000,
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
var costItems = executionReportJson.promptExecutions
|
|
450
|
+
.filter(function (promptExecution) { var _a, _b; return typeof ((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) === 'number'; })
|
|
451
|
+
.map(function (promptExecution) {
|
|
452
|
+
var _a, _b;
|
|
453
|
+
return ({
|
|
454
|
+
title: promptExecution.prompt.title,
|
|
455
|
+
from: 0,
|
|
456
|
+
to: ((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) * (1 + taxRate),
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
var duration = moment__default["default"].duration(completedAt.diff(startedAt));
|
|
460
|
+
var naturalDuration = moment__default["default"].duration(countWorkingDuration(timingItems) * 1000);
|
|
461
|
+
var executionsWithKnownCost = executionReportJson.promptExecutions.filter(function (promptExecution) { var _a, _b; return (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) || 'UNKNOWN') !== 'UNKNOWN'; });
|
|
462
|
+
var cost = executionsWithKnownCost.reduce(function (cost, promptExecution) { return cost + (promptExecution.result.usage.price || 0); }, 0);
|
|
463
|
+
headerList.push("STARTED AT ".concat(moment__default["default"](startedAt).format("YYYY-MM-DD HH:mm:ss")));
|
|
464
|
+
headerList.push("COMPLETED AT ".concat(moment__default["default"](completedAt).format("YYYY-MM-DD HH:mm:ss")));
|
|
465
|
+
headerList.push("TOTAL DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
|
|
466
|
+
headerList.push("TOTAL NATURAL DURATION ".concat(naturalDuration.humanize(MOMENT_ARG_THRESHOLDS)));
|
|
467
|
+
headerList.push("TOTAL COST $".concat(formatNumber(cost * (1 + taxRate))) +
|
|
468
|
+
(executionsWithKnownCost.length === executionReportJson.promptExecutions.length
|
|
469
|
+
? ''
|
|
470
|
+
: " *(Some cost is unknown)*") +
|
|
471
|
+
(taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
|
|
472
|
+
executionReportString += '\n\n' + headerList.map(function (header) { return "- ".concat(header); }).join('\n');
|
|
473
|
+
executionReportString +=
|
|
474
|
+
'\n\n' +
|
|
475
|
+
'## 🗃 Index' +
|
|
476
|
+
'\n\n' +
|
|
477
|
+
executionReportJson.promptExecutions
|
|
478
|
+
.map(function (promptExecution) {
|
|
479
|
+
// TODO: Make some better system to convert hedings to links
|
|
480
|
+
var hash = n12.normalizeToKebabCase(promptExecution.prompt.title);
|
|
481
|
+
if (/^\s*\p{Extended_Pictographic}/u.test(promptExecution.prompt.title)) {
|
|
482
|
+
hash = '-' + hash;
|
|
483
|
+
}
|
|
484
|
+
// TODO: Make working hash link for the template in md + pdf
|
|
485
|
+
return "- [".concat(promptExecution.prompt.title, "](#").concat(hash, ")");
|
|
486
|
+
})
|
|
487
|
+
.join('\n');
|
|
488
|
+
executionReportString +=
|
|
489
|
+
'\n\n' +
|
|
490
|
+
'## ⌚ Time chart' +
|
|
491
|
+
'\n\n' +
|
|
492
|
+
createMarkdownChart({
|
|
493
|
+
nameHeader: 'Template',
|
|
494
|
+
valueHeader: 'Timeline',
|
|
495
|
+
items: timingItems,
|
|
496
|
+
width: chartsWidth,
|
|
497
|
+
unitName: 'seconds',
|
|
498
|
+
});
|
|
499
|
+
executionReportString +=
|
|
500
|
+
'\n\n' +
|
|
501
|
+
'## 💸 Cost chart' +
|
|
502
|
+
'\n\n' +
|
|
503
|
+
createMarkdownChart({
|
|
504
|
+
nameHeader: 'Template',
|
|
505
|
+
valueHeader: 'Cost',
|
|
506
|
+
items: costItems,
|
|
507
|
+
width: chartsWidth,
|
|
508
|
+
unitName: 'USD',
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
headerList.push("TOTAL COST $0 *(Nothing executed)*");
|
|
513
|
+
}
|
|
514
|
+
var _loop_1 = function (promptExecution) {
|
|
515
|
+
executionReportString += '\n\n\n\n' + "## ".concat(promptExecution.prompt.title);
|
|
516
|
+
var templateList = [];
|
|
517
|
+
// TODO: What if startedAt OR/AND completedAt is not defined?
|
|
518
|
+
var startedAt = moment__default["default"]((_c = (_b = promptExecution.result) === null || _b === void 0 ? void 0 : _b.timing) === null || _c === void 0 ? void 0 : _c.start);
|
|
519
|
+
var completedAt = moment__default["default"]((_e = (_d = promptExecution.result) === null || _d === void 0 ? void 0 : _d.timing) === null || _e === void 0 ? void 0 : _e.complete);
|
|
520
|
+
var duration = moment__default["default"].duration(completedAt.diff(startedAt));
|
|
521
|
+
// Not need here:
|
|
522
|
+
// > templateList.push(`STARTED AT ${moment(startedAt).calendar()}`);
|
|
523
|
+
templateList.push("DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
|
|
524
|
+
if (typeof ((_g = (_f = promptExecution.result) === null || _f === void 0 ? void 0 : _f.usage) === null || _g === void 0 ? void 0 : _g.price) === 'number') {
|
|
525
|
+
templateList.push("COST $".concat(formatNumber(promptExecution.result.usage.price * (1 + taxRate))) +
|
|
526
|
+
(taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
templateList.push("COST UNKNOWN");
|
|
530
|
+
}
|
|
531
|
+
executionReportString += '\n\n' + templateList.map(function (header) { return "- ".concat(header); }).join('\n');
|
|
532
|
+
/*
|
|
533
|
+
- MODEL VARIANT ${promptExecution.prompt.modelRequirements.modelVariant}
|
|
534
|
+
- MODEL NAME \`${promptExecution.result?.model}\` (requested \`${
|
|
535
|
+
promptExecution.prompt.modelRequirements.modelName
|
|
536
|
+
|
|
537
|
+
*/
|
|
538
|
+
if (just(true)) {
|
|
539
|
+
executionReportString +=
|
|
540
|
+
'\n\n\n\n' +
|
|
541
|
+
spaceTrim__default["default"](function (block) { return "\n\n ### Prompt\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.prompt.content)), "\n ```\n\n "); });
|
|
542
|
+
}
|
|
543
|
+
if (promptExecution.result && promptExecution.result.content) {
|
|
544
|
+
executionReportString +=
|
|
545
|
+
'\n\n\n\n' +
|
|
546
|
+
spaceTrim__default["default"](function (block) { return "\n\n ### Result\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.result.content)), "\n ```\n "); });
|
|
547
|
+
}
|
|
548
|
+
if (promptExecution.error && promptExecution.error.message) {
|
|
549
|
+
executionReportString +=
|
|
550
|
+
'\n\n\n\n' +
|
|
551
|
+
spaceTrim__default["default"](function (block) { return "\n\n ### Error\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.error.message)), "\n ```\n\n "); });
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
try {
|
|
555
|
+
for (var _j = __values(executionReportJson.promptExecutions), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
556
|
+
var promptExecution = _k.value;
|
|
557
|
+
_loop_1(promptExecution);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
561
|
+
finally {
|
|
562
|
+
try {
|
|
563
|
+
if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
|
|
564
|
+
}
|
|
565
|
+
finally { if (e_1) throw e_1.error; }
|
|
566
|
+
}
|
|
567
|
+
executionReportString = prettifyMarkdown(executionReportString);
|
|
568
|
+
return executionReportString;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* TODO: Add mermaid chart for every report
|
|
572
|
+
* TODO: [🧠] Allow to filter out some parts of the report by options
|
|
573
|
+
*/
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Counts number of characters in the text
|
|
577
|
+
*/
|
|
578
|
+
function countCharacters(text) {
|
|
579
|
+
// Remove null characters
|
|
580
|
+
text = text.replace(/\0/g, '');
|
|
581
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
582
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
583
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
584
|
+
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
585
|
+
return text.length;
|
|
586
586
|
}
|
|
587
587
|
|
|
588
|
-
/**
|
|
589
|
-
* Counts number of lines in the text
|
|
590
|
-
*/
|
|
591
|
-
function countLines(text) {
|
|
592
|
-
if (text === '') {
|
|
593
|
-
return 0;
|
|
594
|
-
}
|
|
595
|
-
return text.split('\n').length;
|
|
588
|
+
/**
|
|
589
|
+
* Counts number of lines in the text
|
|
590
|
+
*/
|
|
591
|
+
function countLines(text) {
|
|
592
|
+
if (text === '') {
|
|
593
|
+
return 0;
|
|
594
|
+
}
|
|
595
|
+
return text.split('\n').length;
|
|
596
596
|
}
|
|
597
597
|
|
|
598
|
-
/**
|
|
599
|
-
* Counts number of pages in the text
|
|
600
|
-
*/
|
|
601
|
-
function countPages(text) {
|
|
602
|
-
var sentencesPerPage = 5; // Assuming each page has 5 sentences
|
|
603
|
-
var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
604
|
-
var pageCount = Math.ceil(sentences.length / sentencesPerPage);
|
|
605
|
-
return pageCount;
|
|
598
|
+
/**
|
|
599
|
+
* Counts number of pages in the text
|
|
600
|
+
*/
|
|
601
|
+
function countPages(text) {
|
|
602
|
+
var sentencesPerPage = 5; // Assuming each page has 5 sentences
|
|
603
|
+
var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
604
|
+
var pageCount = Math.ceil(sentences.length / sentencesPerPage);
|
|
605
|
+
return pageCount;
|
|
606
606
|
}
|
|
607
607
|
|
|
608
|
-
/**
|
|
609
|
-
* Counts number of paragraphs in the text
|
|
610
|
-
*/
|
|
611
|
-
function countParagraphs(text) {
|
|
612
|
-
return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
|
|
608
|
+
/**
|
|
609
|
+
* Counts number of paragraphs in the text
|
|
610
|
+
*/
|
|
611
|
+
function countParagraphs(text) {
|
|
612
|
+
return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
|
|
613
613
|
}
|
|
614
614
|
|
|
615
|
-
/**
|
|
616
|
-
* Counts number of sentences in the text
|
|
617
|
-
*/
|
|
618
|
-
function countSentences(text) {
|
|
619
|
-
return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; }).length;
|
|
615
|
+
/**
|
|
616
|
+
* Counts number of sentences in the text
|
|
617
|
+
*/
|
|
618
|
+
function countSentences(text) {
|
|
619
|
+
return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; }).length;
|
|
620
620
|
}
|
|
621
621
|
|
|
622
|
-
/**
|
|
623
|
-
* Counts number of words in the text
|
|
624
|
-
*/
|
|
625
|
-
function countWords(text) {
|
|
626
|
-
text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
|
|
627
|
-
text = n12.removeDiacritics(text);
|
|
628
|
-
return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
|
|
622
|
+
/**
|
|
623
|
+
* Counts number of words in the text
|
|
624
|
+
*/
|
|
625
|
+
function countWords(text) {
|
|
626
|
+
text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
|
|
627
|
+
text = n12.removeDiacritics(text);
|
|
628
|
+
return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
|
|
629
629
|
}
|
|
630
630
|
|
|
631
|
-
/**
|
|
632
|
-
* Index of all counter functions
|
|
633
|
-
*/
|
|
634
|
-
var CountUtils = {
|
|
635
|
-
CHARACTERS: countCharacters,
|
|
636
|
-
WORDS: countWords,
|
|
637
|
-
SENTENCES: countSentences,
|
|
638
|
-
PARAGRAPHS: countParagraphs,
|
|
639
|
-
LINES: countLines,
|
|
640
|
-
PAGES: countPages,
|
|
631
|
+
/**
|
|
632
|
+
* Index of all counter functions
|
|
633
|
+
*/
|
|
634
|
+
var CountUtils = {
|
|
635
|
+
CHARACTERS: countCharacters,
|
|
636
|
+
WORDS: countWords,
|
|
637
|
+
SENTENCES: countSentences,
|
|
638
|
+
PARAGRAPHS: countParagraphs,
|
|
639
|
+
LINES: countLines,
|
|
640
|
+
PAGES: countPages,
|
|
641
641
|
};
|
|
642
642
|
|
|
643
|
-
/**
|
|
644
|
-
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
645
|
-
*/
|
|
646
|
-
function isValidJsonString(value) {
|
|
647
|
-
try {
|
|
648
|
-
JSON.parse(value);
|
|
649
|
-
return true;
|
|
650
|
-
}
|
|
651
|
-
catch (error) {
|
|
652
|
-
if (!(error instanceof Error)) {
|
|
653
|
-
throw error;
|
|
654
|
-
}
|
|
655
|
-
if (error.message.includes('Unexpected token')) {
|
|
656
|
-
return false;
|
|
657
|
-
}
|
|
658
|
-
return false;
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
/**
|
|
663
|
-
* Extracts all code blocks from markdown.
|
|
664
|
-
*
|
|
665
|
-
* Note: There are 3 simmilar function:
|
|
666
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
667
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
668
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
669
|
-
*
|
|
670
|
-
* @param markdown any valid markdown
|
|
671
|
-
* @returns code blocks with language and content
|
|
672
|
-
*
|
|
673
|
-
*/
|
|
674
|
-
function extractAllBlocksFromMarkdown(markdown) {
|
|
675
|
-
var e_1, _a;
|
|
676
|
-
var codeBlocks = [];
|
|
677
|
-
var lines = markdown.split('\n');
|
|
678
|
-
var currentCodeBlock = null;
|
|
679
|
-
try {
|
|
680
|
-
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
681
|
-
var line = lines_1_1.value;
|
|
682
|
-
if (line.startsWith('```')) {
|
|
683
|
-
var language = line.slice(3).trim() || null;
|
|
684
|
-
if (currentCodeBlock === null) {
|
|
685
|
-
currentCodeBlock = { language: language, content: '' };
|
|
686
|
-
}
|
|
687
|
-
else {
|
|
688
|
-
if (language !== null) {
|
|
689
|
-
// [🌻]
|
|
690
|
-
throw new Error("".concat(n12.capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
691
|
-
}
|
|
692
|
-
codeBlocks.push(currentCodeBlock);
|
|
693
|
-
currentCodeBlock = null;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
else if (currentCodeBlock !== null) {
|
|
697
|
-
if (currentCodeBlock.content !== '') {
|
|
698
|
-
currentCodeBlock.content += '\n';
|
|
699
|
-
}
|
|
700
|
-
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
705
|
-
finally {
|
|
706
|
-
try {
|
|
707
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
708
|
-
}
|
|
709
|
-
finally { if (e_1) throw e_1.error; }
|
|
710
|
-
}
|
|
711
|
-
if (currentCodeBlock !== null) {
|
|
712
|
-
// [🌻]
|
|
713
|
-
throw new Error("".concat(n12.capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
714
|
-
}
|
|
715
|
-
return codeBlocks;
|
|
643
|
+
/**
|
|
644
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
645
|
+
*/
|
|
646
|
+
function isValidJsonString(value) {
|
|
647
|
+
try {
|
|
648
|
+
JSON.parse(value);
|
|
649
|
+
return true;
|
|
650
|
+
}
|
|
651
|
+
catch (error) {
|
|
652
|
+
if (!(error instanceof Error)) {
|
|
653
|
+
throw error;
|
|
654
|
+
}
|
|
655
|
+
if (error.message.includes('Unexpected token')) {
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
return false;
|
|
659
|
+
}
|
|
716
660
|
}
|
|
717
661
|
|
|
718
|
-
/**
|
|
719
|
-
*
|
|
720
|
-
*
|
|
721
|
-
* Note:
|
|
722
|
-
*
|
|
723
|
-
*
|
|
724
|
-
*
|
|
725
|
-
*
|
|
726
|
-
* @param markdown any valid markdown
|
|
727
|
-
* @returns
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
var
|
|
732
|
-
var
|
|
733
|
-
var
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
var
|
|
738
|
-
if (
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
662
|
+
/**
|
|
663
|
+
* Extracts all code blocks from markdown.
|
|
664
|
+
*
|
|
665
|
+
* Note: There are 3 simmilar function:
|
|
666
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
667
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
668
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
669
|
+
*
|
|
670
|
+
* @param markdown any valid markdown
|
|
671
|
+
* @returns code blocks with language and content
|
|
672
|
+
*
|
|
673
|
+
*/
|
|
674
|
+
function extractAllBlocksFromMarkdown(markdown) {
|
|
675
|
+
var e_1, _a;
|
|
676
|
+
var codeBlocks = [];
|
|
677
|
+
var lines = markdown.split('\n');
|
|
678
|
+
var currentCodeBlock = null;
|
|
679
|
+
try {
|
|
680
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
681
|
+
var line = lines_1_1.value;
|
|
682
|
+
if (line.startsWith('```')) {
|
|
683
|
+
var language = line.slice(3).trim() || null;
|
|
684
|
+
if (currentCodeBlock === null) {
|
|
685
|
+
currentCodeBlock = { language: language, content: '' };
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
if (language !== null) {
|
|
689
|
+
// [🌻]
|
|
690
|
+
throw new Error("".concat(n12.capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
691
|
+
}
|
|
692
|
+
codeBlocks.push(currentCodeBlock);
|
|
693
|
+
currentCodeBlock = null;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
else if (currentCodeBlock !== null) {
|
|
697
|
+
if (currentCodeBlock.content !== '') {
|
|
698
|
+
currentCodeBlock.content += '\n';
|
|
699
|
+
}
|
|
700
|
+
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
705
|
+
finally {
|
|
706
|
+
try {
|
|
707
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
708
|
+
}
|
|
709
|
+
finally { if (e_1) throw e_1.error; }
|
|
710
|
+
}
|
|
711
|
+
if (currentCodeBlock !== null) {
|
|
712
|
+
// [🌻]
|
|
713
|
+
throw new Error("".concat(n12.capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
714
|
+
}
|
|
715
|
+
return codeBlocks;
|
|
755
716
|
}
|
|
756
717
|
|
|
757
|
-
/**
|
|
758
|
-
*
|
|
759
|
-
*
|
|
760
|
-
* Note:
|
|
761
|
-
*
|
|
762
|
-
* Note:
|
|
763
|
-
*
|
|
764
|
-
*
|
|
765
|
-
*
|
|
766
|
-
*
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
var
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
718
|
+
/**
|
|
719
|
+
* Utility function to extract all list items from markdown
|
|
720
|
+
*
|
|
721
|
+
* Note: It works with both ul and ol
|
|
722
|
+
* Note: It omits list items in code blocks
|
|
723
|
+
* Note: It flattens nested lists
|
|
724
|
+
* Note: It can not work with html syntax and comments
|
|
725
|
+
*
|
|
726
|
+
* @param markdown any valid markdown
|
|
727
|
+
* @returns
|
|
728
|
+
*/
|
|
729
|
+
function extractAllListItemsFromMarkdown(markdown) {
|
|
730
|
+
var e_1, _a;
|
|
731
|
+
var lines = markdown.split('\n');
|
|
732
|
+
var listItems = [];
|
|
733
|
+
var isInCodeBlock = false;
|
|
734
|
+
try {
|
|
735
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
736
|
+
var line = lines_1_1.value;
|
|
737
|
+
var trimmedLine = line.trim();
|
|
738
|
+
if (trimmedLine.startsWith('```')) {
|
|
739
|
+
isInCodeBlock = !isInCodeBlock;
|
|
740
|
+
}
|
|
741
|
+
if (!isInCodeBlock && (trimmedLine.startsWith('-') || trimmedLine.match(/^\d+\./))) {
|
|
742
|
+
var listItem = trimmedLine.replace(/^-|\d+\./, '').trim();
|
|
743
|
+
listItems.push(listItem);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
748
|
+
finally {
|
|
749
|
+
try {
|
|
750
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
751
|
+
}
|
|
752
|
+
finally { if (e_1) throw e_1.error; }
|
|
753
|
+
}
|
|
754
|
+
return listItems;
|
|
777
755
|
}
|
|
778
|
-
/***
|
|
779
|
-
* TODO: [🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
780
|
-
*/
|
|
781
756
|
|
|
782
|
-
/**
|
|
783
|
-
*
|
|
784
|
-
*
|
|
785
|
-
*
|
|
786
|
-
*
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
757
|
+
/**
|
|
758
|
+
* Extracts exactly ONE code block from markdown.
|
|
759
|
+
*
|
|
760
|
+
* Note: If there are multiple or no code blocks the function throws an error
|
|
761
|
+
*
|
|
762
|
+
* Note: There are 3 simmilar function:
|
|
763
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
764
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
765
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
766
|
+
*
|
|
767
|
+
* @param markdown any valid markdown
|
|
768
|
+
* @returns code block with language and content
|
|
769
|
+
*/
|
|
770
|
+
function extractOneBlockFromMarkdown(markdown) {
|
|
771
|
+
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
772
|
+
if (codeBlocks.length !== 1) {
|
|
773
|
+
// TODO: Report more specific place where the error happened
|
|
774
|
+
throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
|
|
775
|
+
}
|
|
776
|
+
return codeBlocks[0];
|
|
777
|
+
}
|
|
778
|
+
/***
|
|
779
|
+
* TODO: [🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
780
|
+
*/
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* Removes HTML or Markdown comments from a string.
|
|
784
|
+
*
|
|
785
|
+
* @param {string} content - The string to remove comments from.
|
|
786
|
+
* @returns {string} The input string with all comments removed.
|
|
787
|
+
*/
|
|
788
|
+
function removeContentComments(content) {
|
|
789
|
+
return spaceTrim__default["default"](content.replace(/<!--(.*?)-->/gs, ''));
|
|
790
790
|
}
|
|
791
791
|
|
|
792
|
-
/**
|
|
793
|
-
* Removes Markdown formatting tags from a string.
|
|
794
|
-
*
|
|
795
|
-
* @param {string} str - The string to remove Markdown tags from.
|
|
796
|
-
* @returns {string} The input string with all Markdown tags removed.
|
|
797
|
-
*/
|
|
798
|
-
function removeMarkdownFormatting(str) {
|
|
799
|
-
// Remove bold formatting
|
|
800
|
-
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
801
|
-
// Remove italic formatting
|
|
802
|
-
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
803
|
-
// Remove code formatting
|
|
804
|
-
str = str.replace(/`(.*?)`/g, '$1');
|
|
805
|
-
return str;
|
|
792
|
+
/**
|
|
793
|
+
* Removes Markdown formatting tags from a string.
|
|
794
|
+
*
|
|
795
|
+
* @param {string} str - The string to remove Markdown tags from.
|
|
796
|
+
* @returns {string} The input string with all Markdown tags removed.
|
|
797
|
+
*/
|
|
798
|
+
function removeMarkdownFormatting(str) {
|
|
799
|
+
// Remove bold formatting
|
|
800
|
+
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
801
|
+
// Remove italic formatting
|
|
802
|
+
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
803
|
+
// Remove code formatting
|
|
804
|
+
str = str.replace(/`(.*?)`/g, '$1');
|
|
805
|
+
return str;
|
|
806
806
|
}
|
|
807
807
|
|
|
808
|
-
/**
|
|
809
|
-
* Extracts code block from markdown.
|
|
810
|
-
*
|
|
811
|
-
* Note: If there are multiple or no code blocks the function throws an error
|
|
812
|
-
*
|
|
813
|
-
* Note: There are 3 simmilar function:
|
|
814
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
815
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
816
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
817
|
-
*/
|
|
818
|
-
function extractBlock(markdown) {
|
|
819
|
-
var content = extractOneBlockFromMarkdown(markdown).content;
|
|
820
|
-
return content;
|
|
821
|
-
}
|
|
808
|
+
/**
|
|
809
|
+
* Extracts code block from markdown.
|
|
810
|
+
*
|
|
811
|
+
* Note: If there are multiple or no code blocks the function throws an error
|
|
812
|
+
*
|
|
813
|
+
* Note: There are 3 simmilar function:
|
|
814
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
815
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
816
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
817
|
+
*/
|
|
818
|
+
function extractBlock(markdown) {
|
|
819
|
+
var content = extractOneBlockFromMarkdown(markdown).content;
|
|
820
|
+
return content;
|
|
821
|
+
}
|
|
822
822
|
//
|
|
823
823
|
|
|
824
|
-
/**
|
|
825
|
-
* Removes quotes from a string
|
|
826
|
-
*
|
|
827
|
-
* Tip: This is very usefull for post-processing of the result of the LLM model
|
|
828
|
-
* Note: This function removes only the same quotes from the beginning and the end of the string
|
|
829
|
-
* Note: There are two simmilar functions:
|
|
830
|
-
* - `removeQuotes` which removes only bounding quotes
|
|
831
|
-
* - `unwrapResult` which removes whole introduce sentence
|
|
832
|
-
*
|
|
833
|
-
* @param text optionally quoted text
|
|
834
|
-
* @returns text without quotes
|
|
835
|
-
*/
|
|
836
|
-
function removeQuotes(text) {
|
|
837
|
-
if (text.startsWith('"') && text.endsWith('"')) {
|
|
838
|
-
return text.slice(1, -1);
|
|
839
|
-
}
|
|
840
|
-
if (text.startsWith('\'') && text.endsWith('\'')) {
|
|
841
|
-
return text.slice(1, -1);
|
|
842
|
-
}
|
|
843
|
-
return text;
|
|
824
|
+
/**
|
|
825
|
+
* Removes quotes from a string
|
|
826
|
+
*
|
|
827
|
+
* Tip: This is very usefull for post-processing of the result of the LLM model
|
|
828
|
+
* Note: This function removes only the same quotes from the beginning and the end of the string
|
|
829
|
+
* Note: There are two simmilar functions:
|
|
830
|
+
* - `removeQuotes` which removes only bounding quotes
|
|
831
|
+
* - `unwrapResult` which removes whole introduce sentence
|
|
832
|
+
*
|
|
833
|
+
* @param text optionally quoted text
|
|
834
|
+
* @returns text without quotes
|
|
835
|
+
*/
|
|
836
|
+
function removeQuotes(text) {
|
|
837
|
+
if (text.startsWith('"') && text.endsWith('"')) {
|
|
838
|
+
return text.slice(1, -1);
|
|
839
|
+
}
|
|
840
|
+
if (text.startsWith('\'') && text.endsWith('\'')) {
|
|
841
|
+
return text.slice(1, -1);
|
|
842
|
+
}
|
|
843
|
+
return text;
|
|
844
844
|
}
|
|
845
845
|
|
|
846
|
-
/**
|
|
847
|
-
* Function trimCodeBlock will trim starting and ending code block from the string if it is present.
|
|
848
|
-
*
|
|
849
|
-
* Note: This is usefull for post-processing of the result of the chat LLM model
|
|
850
|
-
* when the model wraps the result in the (markdown) code block.
|
|
851
|
-
*
|
|
852
|
-
*/
|
|
853
|
-
function trimCodeBlock(value) {
|
|
854
|
-
value = spaceTrim__default["default"](value);
|
|
855
|
-
if (!/^```[a-z]*(.*)```$/is.test(value)) {
|
|
856
|
-
return value;
|
|
857
|
-
}
|
|
858
|
-
value = value.replace(/^```[a-z]*/i, '');
|
|
859
|
-
value = value.replace(/```$/i, '');
|
|
860
|
-
value = spaceTrim__default["default"](value);
|
|
861
|
-
return value;
|
|
846
|
+
/**
|
|
847
|
+
* Function trimCodeBlock will trim starting and ending code block from the string if it is present.
|
|
848
|
+
*
|
|
849
|
+
* Note: This is usefull for post-processing of the result of the chat LLM model
|
|
850
|
+
* when the model wraps the result in the (markdown) code block.
|
|
851
|
+
*
|
|
852
|
+
*/
|
|
853
|
+
function trimCodeBlock(value) {
|
|
854
|
+
value = spaceTrim__default["default"](value);
|
|
855
|
+
if (!/^```[a-z]*(.*)```$/is.test(value)) {
|
|
856
|
+
return value;
|
|
857
|
+
}
|
|
858
|
+
value = value.replace(/^```[a-z]*/i, '');
|
|
859
|
+
value = value.replace(/```$/i, '');
|
|
860
|
+
value = spaceTrim__default["default"](value);
|
|
861
|
+
return value;
|
|
862
862
|
}
|
|
863
863
|
|
|
864
|
-
/**
|
|
865
|
-
* Function trimEndOfCodeBlock will remove ending code block from the string if it is present.
|
|
866
|
-
*
|
|
867
|
-
* Note: This is usefull for post-processing of the result of the completion LLM model
|
|
868
|
-
* if you want to start code block in the prompt but you don't want to end it in the result.
|
|
869
|
-
*/
|
|
870
|
-
function trimEndOfCodeBlock(value) {
|
|
871
|
-
value = spaceTrim__default["default"](value);
|
|
872
|
-
value = value.replace(/```$/g, '');
|
|
873
|
-
value = spaceTrim__default["default"](value);
|
|
874
|
-
return value;
|
|
864
|
+
/**
|
|
865
|
+
* Function trimEndOfCodeBlock will remove ending code block from the string if it is present.
|
|
866
|
+
*
|
|
867
|
+
* Note: This is usefull for post-processing of the result of the completion LLM model
|
|
868
|
+
* if you want to start code block in the prompt but you don't want to end it in the result.
|
|
869
|
+
*/
|
|
870
|
+
function trimEndOfCodeBlock(value) {
|
|
871
|
+
value = spaceTrim__default["default"](value);
|
|
872
|
+
value = value.replace(/```$/g, '');
|
|
873
|
+
value = spaceTrim__default["default"](value);
|
|
874
|
+
return value;
|
|
875
875
|
}
|
|
876
876
|
|
|
877
|
-
/**
|
|
878
|
-
* Removes quotes and optional introduce text from a string
|
|
879
|
-
*
|
|
880
|
-
* Tip: This is very usefull for post-processing of the result of the LLM model
|
|
881
|
-
* Note: This function trims the text and removes whole introduce sentence if it is present
|
|
882
|
-
* Note: There are two simmilar functions:
|
|
883
|
-
* - `removeQuotes` which removes only bounding quotes
|
|
884
|
-
* - `unwrapResult` which removes whole introduce sentence
|
|
885
|
-
*
|
|
886
|
-
* @param text optionally quoted text
|
|
887
|
-
* @returns text without quotes
|
|
888
|
-
*/
|
|
889
|
-
function unwrapResult(text, options) {
|
|
890
|
-
var _a = options || {}, _b = _a.isTrimmed, isTrimmed = _b === void 0 ? true : _b, _c = _a.isIntroduceSentenceRemoved, isIntroduceSentenceRemoved = _c === void 0 ? true : _c;
|
|
891
|
-
var trimmedText = text;
|
|
892
|
-
// Remove leading and trailing spaces and newlines
|
|
893
|
-
if (isTrimmed) {
|
|
894
|
-
trimmedText = spaceTrim__default["default"](trimmedText);
|
|
895
|
-
}
|
|
896
|
-
var processedText = trimmedText;
|
|
897
|
-
if (isIntroduceSentenceRemoved) {
|
|
898
|
-
var introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
|
|
899
|
-
if (introduceSentenceRegex.test(text)) {
|
|
900
|
-
// Remove the introduce sentence and quotes by replacing it with an empty string
|
|
901
|
-
processedText = processedText.replace(introduceSentenceRegex, '');
|
|
902
|
-
}
|
|
903
|
-
processedText = spaceTrim__default["default"](processedText);
|
|
904
|
-
}
|
|
905
|
-
if (processedText.length < 3) {
|
|
906
|
-
return trimmedText;
|
|
907
|
-
}
|
|
908
|
-
if (processedText.includes('\n')) {
|
|
909
|
-
return trimmedText;
|
|
910
|
-
}
|
|
911
|
-
// Remove the quotes by extracting the substring without the first and last characters
|
|
912
|
-
var unquotedText = processedText.slice(1, -1);
|
|
913
|
-
// Check if the text starts and ends with quotes
|
|
914
|
-
if ([
|
|
915
|
-
['"', '"'],
|
|
916
|
-
["'", "'"],
|
|
917
|
-
['`', '`'],
|
|
918
|
-
['*', '*'],
|
|
919
|
-
['_', '_'],
|
|
920
|
-
['„', '“'],
|
|
921
|
-
['«', '»'] /* <- QUOTES to config */,
|
|
922
|
-
].some(function (_a) {
|
|
923
|
-
var _b = __read(_a, 2), startQuote = _b[0], endQuote = _b[1];
|
|
924
|
-
if (!processedText.startsWith(startQuote)) {
|
|
925
|
-
return false;
|
|
926
|
-
}
|
|
927
|
-
if (!processedText.endsWith(endQuote)) {
|
|
928
|
-
return false;
|
|
929
|
-
}
|
|
930
|
-
if (unquotedText.includes(startQuote) && !unquotedText.includes(endQuote)) {
|
|
931
|
-
return false;
|
|
932
|
-
}
|
|
933
|
-
if (!unquotedText.includes(startQuote) && unquotedText.includes(endQuote)) {
|
|
934
|
-
return false;
|
|
935
|
-
}
|
|
936
|
-
return true;
|
|
937
|
-
})) {
|
|
938
|
-
return unwrapResult(unquotedText, { isTrimmed: false, isIntroduceSentenceRemoved: false });
|
|
939
|
-
}
|
|
940
|
-
else {
|
|
941
|
-
return processedText;
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
/**
|
|
945
|
-
* TODO: [🧠] Should this also unwrap the (parenthesis)
|
|
877
|
+
/**
|
|
878
|
+
* Removes quotes and optional introduce text from a string
|
|
879
|
+
*
|
|
880
|
+
* Tip: This is very usefull for post-processing of the result of the LLM model
|
|
881
|
+
* Note: This function trims the text and removes whole introduce sentence if it is present
|
|
882
|
+
* Note: There are two simmilar functions:
|
|
883
|
+
* - `removeQuotes` which removes only bounding quotes
|
|
884
|
+
* - `unwrapResult` which removes whole introduce sentence
|
|
885
|
+
*
|
|
886
|
+
* @param text optionally quoted text
|
|
887
|
+
* @returns text without quotes
|
|
888
|
+
*/
|
|
889
|
+
function unwrapResult(text, options) {
|
|
890
|
+
var _a = options || {}, _b = _a.isTrimmed, isTrimmed = _b === void 0 ? true : _b, _c = _a.isIntroduceSentenceRemoved, isIntroduceSentenceRemoved = _c === void 0 ? true : _c;
|
|
891
|
+
var trimmedText = text;
|
|
892
|
+
// Remove leading and trailing spaces and newlines
|
|
893
|
+
if (isTrimmed) {
|
|
894
|
+
trimmedText = spaceTrim__default["default"](trimmedText);
|
|
895
|
+
}
|
|
896
|
+
var processedText = trimmedText;
|
|
897
|
+
if (isIntroduceSentenceRemoved) {
|
|
898
|
+
var introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
|
|
899
|
+
if (introduceSentenceRegex.test(text)) {
|
|
900
|
+
// Remove the introduce sentence and quotes by replacing it with an empty string
|
|
901
|
+
processedText = processedText.replace(introduceSentenceRegex, '');
|
|
902
|
+
}
|
|
903
|
+
processedText = spaceTrim__default["default"](processedText);
|
|
904
|
+
}
|
|
905
|
+
if (processedText.length < 3) {
|
|
906
|
+
return trimmedText;
|
|
907
|
+
}
|
|
908
|
+
if (processedText.includes('\n')) {
|
|
909
|
+
return trimmedText;
|
|
910
|
+
}
|
|
911
|
+
// Remove the quotes by extracting the substring without the first and last characters
|
|
912
|
+
var unquotedText = processedText.slice(1, -1);
|
|
913
|
+
// Check if the text starts and ends with quotes
|
|
914
|
+
if ([
|
|
915
|
+
['"', '"'],
|
|
916
|
+
["'", "'"],
|
|
917
|
+
['`', '`'],
|
|
918
|
+
['*', '*'],
|
|
919
|
+
['_', '_'],
|
|
920
|
+
['„', '“'],
|
|
921
|
+
['«', '»'] /* <- QUOTES to config */,
|
|
922
|
+
].some(function (_a) {
|
|
923
|
+
var _b = __read(_a, 2), startQuote = _b[0], endQuote = _b[1];
|
|
924
|
+
if (!processedText.startsWith(startQuote)) {
|
|
925
|
+
return false;
|
|
926
|
+
}
|
|
927
|
+
if (!processedText.endsWith(endQuote)) {
|
|
928
|
+
return false;
|
|
929
|
+
}
|
|
930
|
+
if (unquotedText.includes(startQuote) && !unquotedText.includes(endQuote)) {
|
|
931
|
+
return false;
|
|
932
|
+
}
|
|
933
|
+
if (!unquotedText.includes(startQuote) && unquotedText.includes(endQuote)) {
|
|
934
|
+
return false;
|
|
935
|
+
}
|
|
936
|
+
return true;
|
|
937
|
+
})) {
|
|
938
|
+
return unwrapResult(unquotedText, { isTrimmed: false, isIntroduceSentenceRemoved: false });
|
|
939
|
+
}
|
|
940
|
+
else {
|
|
941
|
+
return processedText;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
* TODO: [🧠] Should this also unwrap the (parenthesis)
|
|
946
946
|
*/
|
|
947
947
|
|
|
948
948
|
exports.CountUtils = CountUtils;
|