@promptbook/cli 0.59.0-0 → 0.59.0-14
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/README.md +1 -1
- package/esm/index.es.js +2734 -1170
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-library/promptbook-library.d.ts +25 -0
- package/{umd/typings → esm/typings/src}/_packages/core.index.d.ts +2 -1
- package/{umd/typings → esm/typings/src}/conversion/promptbookStringToJson.d.ts +12 -2
- package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +19 -0
- package/esm/typings/{llm-providers → src/llm-providers}/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
- package/{umd/typings → esm/typings/src}/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -0
- package/{umd/typings → esm/typings/src}/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -0
- package/esm/typings/{types → src/types}/PromptbookJson/MaterialKnowledgePieceJson.d.ts +1 -1
- package/esm/typings/{types → src/types}/typeAliases.d.ts +7 -1
- package/package.json +2 -2
- package/umd/index.umd.js +2754 -1189
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/promptbook-library/promptbook-library.d.ts +25 -0
- package/{esm/typings → umd/typings/src}/_packages/core.index.d.ts +2 -1
- package/{esm/typings → umd/typings/src}/conversion/promptbookStringToJson.d.ts +12 -2
- package/umd/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +19 -0
- package/umd/typings/{llm-providers → src/llm-providers}/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
- package/{esm/typings → umd/typings/src}/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -0
- package/{esm/typings → umd/typings/src}/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -0
- package/umd/typings/src/llm-providers/multiple/playground/playground.d.ts +2 -0
- package/umd/typings/src/llm-providers/openai/playground/playground.d.ts +2 -0
- package/umd/typings/{types → src/types}/PromptbookJson/MaterialKnowledgePieceJson.d.ts +1 -1
- package/umd/typings/{types → src/types}/typeAliases.d.ts +7 -1
- package/umd/typings/src/utils/unwrapResult.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/url/isValidUrl.test.d.ts +1 -0
- package/esm/typings/{_packages → src/_packages}/anthropic-claude.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/azure-openai.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/cli.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/execute-javascript.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/fake-llm.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/langtail.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/node.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/openai.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/remote-client.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/remote-server.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/types.index.d.ts +0 -0
- package/esm/typings/{_packages → src/_packages}/utils.index.d.ts +0 -0
- package/esm/typings/{config.d.ts → src/config.d.ts} +0 -0
- package/esm/typings/{conversion → src/conversion}/prettify/PrettifyOptions.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/prettify/prettifyPromptbookString.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/prettify/prettifyPromptbookStringCli.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/prettify/renderPromptbookMermaid.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/promptbookJsonToString.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/promptbookStringToJson.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/extractParametersFromPromptTemplate.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/extractParametersFromPromptTemplate.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/extractVariables.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/extractVariables.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/parseCommand.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/parseCommand.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/parseNumber.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/parseNumber.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/renameParameter.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/renameParameter.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/titleToName.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/utils/titleToName.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/validation/_importPromptbook.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/validation/promptbookStringToJson-syntaxErrors.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/validation/validatePromptbookJson-logicErrors.test.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/validation/validatePromptbookJson.d.ts +0 -0
- package/esm/typings/{conversion → src/conversion}/validation/validatePromptbookJson.test.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/PromptbookExecutionError.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/PromptbookLibraryError.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/PromptbookLogicError.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/PromptbookNotFoundError.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/PromptbookReferenceError.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/PromptbookSyntaxError.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/TemplateError.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/UnexpectedError.d.ts +0 -0
- package/esm/typings/{errors → src/errors}/_ExpectError.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/CommonExecutionToolsOptions.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/ExecutionTools.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/LlmExecutionTools.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/PromptResult.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/PromptbookExecutor.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/ScriptExecutionTools.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/UserInterfaceTools.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/addPromptResultUsage.test.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/assertsExecutionSuccessful.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/createPromptbookExecutor.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.test.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/translation/automatic-translate/translateMessages.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/addUsage.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/addUsage.test.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/checkExpectations.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/checkExpectations.test.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/computeUsageCounts.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/forEachAsync.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/replaceParameters.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/replaceParameters.test.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/uncertainNumber.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/usageToWorktime.d.ts +0 -0
- package/esm/typings/{execution → src/execution}/utils/usageToWorktime.test.d.ts +0 -0
- package/esm/typings/{expectations → src/expectations}/drafts/isDomainNameFree.d.ts +0 -0
- package/esm/typings/{expectations → src/expectations}/drafts/isGithubNameFree.d.ts +0 -0
- package/esm/typings/{formats → src/formats}/_common/FormatDefinition.d.ts +0 -0
- package/esm/typings/{formats → src/formats}/csv/ListFormatDefinition.d.ts +0 -0
- package/esm/typings/{formats → src/formats}/index.d.ts +0 -0
- package/esm/typings/{formats → src/formats}/json/JsonFormatDefinition.d.ts +0 -0
- package/esm/typings/{formats → src/formats}/json/utils/isValidJsonString.d.ts +0 -0
- package/esm/typings/{formats → src/formats}/json/utils/isValidJsonString.test.d.ts +0 -0
- package/esm/typings/{formats → src/formats}/list/ListFormatDefinition.d.ts +0 -0
- package/esm/typings/{formats → src/formats}/xml/XmlFormatDefinition.d.ts +0 -0
- package/esm/typings/{knowledge → src/knowledge}/dialogs/callback/CallbackInterfaceTools.d.ts +0 -0
- package/esm/typings/{knowledge → src/knowledge}/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +0 -0
- package/esm/typings/{knowledge → src/knowledge}/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +0 -0
- package/esm/typings/{knowledge → src/knowledge}/dialogs/user-interface-execution-tools.test.d.ts +0 -0
- package/esm/typings/{knowledge → src/knowledge}/prepare-knowledge/_common/IndexPreparer.d.ts +0 -0
- package/esm/typings/{llm-providers/anthropic-claude/playground/playground.d.ts → src/knowledge/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts} +0 -0
- package/{umd/typings → esm/typings/src}/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- package/esm/typings/{knowledge → src/knowledge}/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +0 -0
- package/esm/typings/{llm-providers/mocked/fakeTextToExpectations.test.d.ts → src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts} +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/anthropic-claude/anthropic-claude-models.d.ts +0 -0
- package/esm/typings/{llm-providers/azure-openai → src/llm-providers/anthropic-claude}/playground/playground.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/azure-openai/AzureOpenAiExecutionTools.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +0 -0
- package/esm/typings/{llm-providers/langtail → src/llm-providers/azure-openai}/playground/playground.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/langtail/LangtailExecutionTools.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/langtail/LangtailExecutionToolsOptions.d.ts +0 -0
- package/esm/typings/{llm-providers/multiple → src/llm-providers/langtail}/playground/playground.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/mocked/fakeTextToExpectations.d.ts +0 -0
- package/{umd/typings → esm/typings/src}/llm-providers/mocked/fakeTextToExpectations.test.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/mocked/faked-completion.test.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/mocked/joker.test.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/mocked/mocked-chat.test.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/mocked/mocked-completion.test.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/multiple/MultipleLlmExecutionTools.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/multiple/MultipleLlmExecutionToolsOptions.d.ts +0 -0
- package/esm/typings/{llm-providers/openai → src/llm-providers/multiple}/playground/playground.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/openai/OpenAiExecutionTools.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/openai/OpenAiExecutionToolsOptions.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/openai/computeOpenaiUsage.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/openai/computeUsage.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/openai/computeUsage.test.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/openai/openai-models.d.ts +0 -0
- package/{umd/typings/llm-providers/anthropic-claude → esm/typings/src/llm-providers/openai}/playground/playground.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/remote/RemoteLlmExecutionTools.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/remote/RemoteLlmExecutionToolsOptions.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Error.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Progress.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Request.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Response.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/remote/interfaces/RemoteServerOptions.d.ts +0 -0
- package/esm/typings/{llm-providers → src/llm-providers}/remote/startRemoteServer.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/PromptbookLibrary.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/SimplePromptbookLibrary.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromDirectory.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromDirectory.test.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromPromise.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromPromise.test.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromSources.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromSources.test.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromUrl.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookSublibrary.d.ts +0 -0
- package/esm/typings/{promptbook-library → src/promptbook-library}/constructors/justTestFsImport.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/_test/custom-function-async.test.ts.test.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/_test/custom-function-missing.test.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/_test/custom-function-with-dependencies.test.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/_test/custom-function.test.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/_test/postprocessing.test.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/_test/script-execution-errors.test.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/_test/script-execution-tools.test.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/javascript/JavascriptEvalExecutionTools.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/javascript/JavascriptEvalExecutionTools.test.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/javascript/JavascriptExecutionTools.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/javascript/JavascriptExecutionToolsOptions.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/javascript/utils/preserve.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/javascript/utils/unknownToString.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/python/PythonExecutionTools.d.ts +0 -0
- package/esm/typings/{scripting → src/scripting}/typescript/TypescriptExecutionTools.d.ts +0 -0
- package/esm/typings/{types → src/types}/Command.d.ts +0 -0
- package/esm/typings/{types → src/types}/ExecutionTypes.d.ts +0 -0
- package/esm/typings/{types → src/types}/ModelRequirements.d.ts +0 -0
- package/esm/typings/{types → src/types}/Parameters.d.ts +0 -0
- package/esm/typings/{types → src/types}/Prompt.d.ts +0 -0
- package/esm/typings/{types → src/types}/PromptbookJson/KnowledgeJson.d.ts +0 -0
- package/esm/typings/{types → src/types}/PromptbookJson/PromptTemplateJson.d.ts +0 -0
- package/esm/typings/{types → src/types}/PromptbookJson/PromptTemplateParameterJson.d.ts +0 -0
- package/esm/typings/{types → src/types}/PromptbookJson/PromptbookJson.d.ts +0 -0
- package/esm/typings/{types → src/types}/PromptbookString.d.ts +0 -0
- package/esm/typings/{types → src/types}/ScriptLanguage.d.ts +0 -0
- package/esm/typings/{types → src/types}/TaskProgress.d.ts +0 -0
- package/esm/typings/{types → src/types}/execution-report/ExecutionReportJson.d.ts +0 -0
- package/esm/typings/{types → src/types}/execution-report/ExecutionReportString.d.ts +0 -0
- package/esm/typings/{types → src/types}/execution-report/ExecutionReportStringOptions.d.ts +0 -0
- package/esm/typings/{types → src/types}/execution-report/config.d.ts +0 -0
- package/esm/typings/{types → src/types}/execution-report/countWorkingDuration.d.ts +0 -0
- package/esm/typings/{types → src/types}/execution-report/countWorkingDuration.test.d.ts +0 -0
- package/esm/typings/{types → src/types}/execution-report/executionReportJsonToString.d.ts +0 -0
- package/esm/typings/{types → src/types}/typeAliasEmoji.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/FromtoItems.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/emojis.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countCharacters.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countCharacters.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countLines.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countLines.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countPages.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countPages.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countParagraphs.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countParagraphs.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countSentences.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countSentences.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countWords.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/countWords.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/expectation-counters/index.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/extractParameters.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/extractParameters.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/formatNumber.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/formatNumber.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/getCurrentIsoDate.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/isRunningInWhatever.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/just.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/addAutoGeneratedSection.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/addAutoGeneratedSection.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/createMarkdownChart.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/createMarkdownChart.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/createMarkdownTable.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/createMarkdownTable.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/escapeMarkdownBlock.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/escapeMarkdownBlock.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/extractAllBlocksFromMarkdown.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/extractAllBlocksFromMarkdown.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/extractAllListItemsFromMarkdown.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/extractAllListItemsFromMarkdown.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/extractOneBlockFromMarkdown.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/extractOneBlockFromMarkdown.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/prettifyMarkdown.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/prettifyMarkdown.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/removeContentComments.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/removeContentComments.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/removeMarkdownFormatting.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown/removeMarkdownFormatting.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown-json/MarkdownStructure.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown-json/countMarkdownStructureDeepness.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown-json/countMarkdownStructureDeepness.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown-json/markdownToMarkdownStructure.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/markdown-json/markdownToMarkdownStructure.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/DIACRITIC_VARIANTS_LETTERS.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/IKeywords.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/capitalize.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/capitalize.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/decapitalize.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/decapitalize.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/isValidKeyword.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/isValidKeyword.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/nameToUriPart.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/nameToUriPart.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/nameToUriParts.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/nameToUriParts.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalize-to-kebab-case.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalize-to-kebab-case.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeTo_PascalCase.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeTo_PascalCase.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeTo_SCREAMING_CASE.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeTo_SCREAMING_CASE.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeTo_camelCase.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeTo_camelCase.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeTo_snake_case.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeTo_snake_case.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeWhitespaces.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/normalizeWhitespaces.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/parseKeywords.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/parseKeywords.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/parseKeywordsFromString.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/parseKeywordsFromString.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/removeDiacritics.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/removeDiacritics.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/searchKeywords.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/normalization/searchKeywords.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/postprocessing/extractBlock.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/removeEmojis.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/removeEmojis.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/removeQuotes.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/removeQuotes.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/sets/difference.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/sets/difference.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/sets/intersection.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/sets/intersection.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/sets/union.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/sets/union.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/trimCodeBlock.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/trimCodeBlock.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/trimEndOfCodeBlock.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/trimEndOfCodeBlock.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/unwrapResult.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/unwrapResult.test.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/validators/url/isValidUrl.d.ts +0 -0
- package/esm/typings/{utils → src/utils}/validators/url/isValidUrl.test.d.ts +0 -0
- package/esm/typings/{version.d.ts → src/version.d.ts} +0 -0
- package/umd/typings/{_packages → src/_packages}/anthropic-claude.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/azure-openai.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/cli.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/execute-javascript.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/fake-llm.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/langtail.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/node.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/openai.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/remote-client.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/remote-server.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/types.index.d.ts +0 -0
- package/umd/typings/{_packages → src/_packages}/utils.index.d.ts +0 -0
- package/umd/typings/{config.d.ts → src/config.d.ts} +0 -0
- package/umd/typings/{conversion → src/conversion}/prettify/PrettifyOptions.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/prettify/prettifyPromptbookString.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/prettify/prettifyPromptbookStringCli.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/prettify/renderPromptbookMermaid.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/promptbookJsonToString.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/promptbookStringToJson.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/extractParametersFromPromptTemplate.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/extractParametersFromPromptTemplate.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/extractVariables.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/extractVariables.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/parseCommand.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/parseCommand.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/parseNumber.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/parseNumber.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/renameParameter.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/renameParameter.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/titleToName.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/utils/titleToName.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/validation/_importPromptbook.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/validation/promptbookStringToJson-syntaxErrors.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/validation/validatePromptbookJson-logicErrors.test.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/validation/validatePromptbookJson.d.ts +0 -0
- package/umd/typings/{conversion → src/conversion}/validation/validatePromptbookJson.test.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/PromptbookExecutionError.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/PromptbookLibraryError.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/PromptbookLogicError.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/PromptbookNotFoundError.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/PromptbookReferenceError.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/PromptbookSyntaxError.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/TemplateError.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/UnexpectedError.d.ts +0 -0
- package/umd/typings/{errors → src/errors}/_ExpectError.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/CommonExecutionToolsOptions.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/ExecutionTools.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/LlmExecutionTools.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/PromptResult.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/PromptbookExecutor.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/ScriptExecutionTools.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/UserInterfaceTools.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/addPromptResultUsage.test.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/assertsExecutionSuccessful.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/createPromptbookExecutor.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.test.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/translation/automatic-translate/translateMessages.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/addUsage.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/addUsage.test.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/checkExpectations.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/checkExpectations.test.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/computeUsageCounts.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/forEachAsync.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/replaceParameters.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/replaceParameters.test.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/uncertainNumber.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/usageToWorktime.d.ts +0 -0
- package/umd/typings/{execution → src/execution}/utils/usageToWorktime.test.d.ts +0 -0
- package/umd/typings/{expectations → src/expectations}/drafts/isDomainNameFree.d.ts +0 -0
- package/umd/typings/{expectations → src/expectations}/drafts/isGithubNameFree.d.ts +0 -0
- package/umd/typings/{formats → src/formats}/_common/FormatDefinition.d.ts +0 -0
- package/umd/typings/{formats → src/formats}/csv/ListFormatDefinition.d.ts +0 -0
- package/umd/typings/{formats → src/formats}/index.d.ts +0 -0
- package/umd/typings/{formats → src/formats}/json/JsonFormatDefinition.d.ts +0 -0
- package/umd/typings/{formats → src/formats}/json/utils/isValidJsonString.d.ts +0 -0
- package/umd/typings/{formats → src/formats}/json/utils/isValidJsonString.test.d.ts +0 -0
- package/umd/typings/{formats → src/formats}/list/ListFormatDefinition.d.ts +0 -0
- package/umd/typings/{formats → src/formats}/xml/XmlFormatDefinition.d.ts +0 -0
- package/umd/typings/{knowledge → src/knowledge}/dialogs/callback/CallbackInterfaceTools.d.ts +0 -0
- package/umd/typings/{knowledge → src/knowledge}/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +0 -0
- package/umd/typings/{knowledge → src/knowledge}/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +0 -0
- package/umd/typings/{knowledge → src/knowledge}/dialogs/user-interface-execution-tools.test.d.ts +0 -0
- package/umd/typings/{knowledge → src/knowledge}/prepare-knowledge/_common/IndexPreparer.d.ts +0 -0
- package/umd/typings/{llm-providers/azure-openai/playground/playground.d.ts → src/knowledge/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts} +0 -0
- package/{esm/typings → umd/typings/src}/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- /package/umd/typings/{knowledge → src/knowledge}/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +0 -0
- /package/umd/typings/{llm-providers/mocked/faked-completion.test.d.ts → src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts} +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/anthropic-claude/anthropic-claude-models.d.ts +0 -0
- /package/umd/typings/{llm-providers/langtail → src/llm-providers/anthropic-claude}/playground/playground.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/azure-openai/AzureOpenAiExecutionTools.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{llm-providers/multiple → src/llm-providers/azure-openai}/playground/playground.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/langtail/LangtailExecutionTools.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/langtail/LangtailExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{llm-providers/openai → src/llm-providers/langtail}/playground/playground.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/mocked/fakeTextToExpectations.d.ts +0 -0
- /package/umd/typings/{llm-providers/openai/computeUsage.test.d.ts → src/llm-providers/mocked/fakeTextToExpectations.test.d.ts} +0 -0
- /package/umd/typings/{promptbook-library/constructors/createPromptbookLibraryFromDirectory.test.d.ts → src/llm-providers/mocked/faked-completion.test.d.ts} +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/mocked/joker.test.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/mocked/mocked-chat.test.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/mocked/mocked-completion.test.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/multiple/MultipleLlmExecutionTools.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/multiple/MultipleLlmExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/openai/OpenAiExecutionTools.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/openai/OpenAiExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/openai/computeOpenaiUsage.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/openai/computeUsage.d.ts +0 -0
- /package/umd/typings/{promptbook-library/constructors/createPromptbookLibraryFromPromise.test.d.ts → src/llm-providers/openai/computeUsage.test.d.ts} +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/openai/openai-models.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/remote/RemoteLlmExecutionTools.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/remote/RemoteLlmExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Error.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Progress.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Request.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/remote/interfaces/Promptbook_Server_Response.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/remote/interfaces/RemoteServerOptions.d.ts +0 -0
- /package/umd/typings/{llm-providers → src/llm-providers}/remote/startRemoteServer.d.ts +0 -0
- /package/umd/typings/{promptbook-library → src/promptbook-library}/PromptbookLibrary.d.ts +0 -0
- /package/umd/typings/{promptbook-library → src/promptbook-library}/SimplePromptbookLibrary.d.ts +0 -0
- /package/umd/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromDirectory.d.ts +0 -0
- /package/umd/typings/{promptbook-library/constructors/createPromptbookLibraryFromSources.test.d.ts → src/promptbook-library/constructors/createPromptbookLibraryFromDirectory.test.d.ts} +0 -0
- /package/umd/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromPromise.d.ts +0 -0
- /package/umd/typings/{scripting/_test/custom-function-async.test.ts.test.d.ts → src/promptbook-library/constructors/createPromptbookLibraryFromPromise.test.d.ts} +0 -0
- /package/umd/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromSources.d.ts +0 -0
- /package/umd/typings/{scripting/_test/custom-function-missing.test.d.ts → src/promptbook-library/constructors/createPromptbookLibraryFromSources.test.d.ts} +0 -0
- /package/umd/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookLibraryFromUrl.d.ts +0 -0
- /package/umd/typings/{promptbook-library → src/promptbook-library}/constructors/createPromptbookSublibrary.d.ts +0 -0
- /package/umd/typings/{promptbook-library → src/promptbook-library}/constructors/justTestFsImport.d.ts +0 -0
- /package/umd/typings/{scripting/_test/custom-function-with-dependencies.test.d.ts → src/scripting/_test/custom-function-async.test.ts.test.d.ts} +0 -0
- /package/umd/typings/{scripting/_test/custom-function.test.d.ts → src/scripting/_test/custom-function-missing.test.d.ts} +0 -0
- /package/umd/typings/{scripting/_test/postprocessing.test.d.ts → src/scripting/_test/custom-function-with-dependencies.test.d.ts} +0 -0
- /package/umd/typings/{scripting/_test/script-execution-errors.test.d.ts → src/scripting/_test/custom-function.test.d.ts} +0 -0
- /package/umd/typings/{scripting/_test/script-execution-tools.test.d.ts → src/scripting/_test/postprocessing.test.d.ts} +0 -0
- /package/umd/typings/{types/execution-report/countWorkingDuration.test.d.ts → src/scripting/_test/script-execution-errors.test.d.ts} +0 -0
- /package/umd/typings/{utils/expectation-counters/countCharacters.test.d.ts → src/scripting/_test/script-execution-tools.test.d.ts} +0 -0
- /package/umd/typings/{scripting → src/scripting}/javascript/JavascriptEvalExecutionTools.d.ts +0 -0
- /package/umd/typings/{scripting → src/scripting}/javascript/JavascriptEvalExecutionTools.test.d.ts +0 -0
- /package/umd/typings/{scripting → src/scripting}/javascript/JavascriptExecutionTools.d.ts +0 -0
- /package/umd/typings/{scripting → src/scripting}/javascript/JavascriptExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{scripting → src/scripting}/javascript/utils/preserve.d.ts +0 -0
- /package/umd/typings/{scripting → src/scripting}/javascript/utils/unknownToString.d.ts +0 -0
- /package/umd/typings/{scripting → src/scripting}/python/PythonExecutionTools.d.ts +0 -0
- /package/umd/typings/{scripting → src/scripting}/typescript/TypescriptExecutionTools.d.ts +0 -0
- /package/umd/typings/{types → src/types}/Command.d.ts +0 -0
- /package/umd/typings/{types → src/types}/ExecutionTypes.d.ts +0 -0
- /package/umd/typings/{types → src/types}/ModelRequirements.d.ts +0 -0
- /package/umd/typings/{types → src/types}/Parameters.d.ts +0 -0
- /package/umd/typings/{types → src/types}/Prompt.d.ts +0 -0
- /package/umd/typings/{types → src/types}/PromptbookJson/KnowledgeJson.d.ts +0 -0
- /package/umd/typings/{types → src/types}/PromptbookJson/PromptTemplateJson.d.ts +0 -0
- /package/umd/typings/{types → src/types}/PromptbookJson/PromptTemplateParameterJson.d.ts +0 -0
- /package/umd/typings/{types → src/types}/PromptbookJson/PromptbookJson.d.ts +0 -0
- /package/umd/typings/{types → src/types}/PromptbookString.d.ts +0 -0
- /package/umd/typings/{types → src/types}/ScriptLanguage.d.ts +0 -0
- /package/umd/typings/{types → src/types}/TaskProgress.d.ts +0 -0
- /package/umd/typings/{types → src/types}/execution-report/ExecutionReportJson.d.ts +0 -0
- /package/umd/typings/{types → src/types}/execution-report/ExecutionReportString.d.ts +0 -0
- /package/umd/typings/{types → src/types}/execution-report/ExecutionReportStringOptions.d.ts +0 -0
- /package/umd/typings/{types → src/types}/execution-report/config.d.ts +0 -0
- /package/umd/typings/{types → src/types}/execution-report/countWorkingDuration.d.ts +0 -0
- /package/umd/typings/{utils/expectation-counters/countLines.test.d.ts → src/types/execution-report/countWorkingDuration.test.d.ts} +0 -0
- /package/umd/typings/{types → src/types}/execution-report/executionReportJsonToString.d.ts +0 -0
- /package/umd/typings/{types → src/types}/typeAliasEmoji.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/FromtoItems.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/emojis.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/expectation-counters/countCharacters.d.ts +0 -0
- /package/umd/typings/{utils/expectation-counters/countPages.test.d.ts → src/utils/expectation-counters/countCharacters.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/expectation-counters/countLines.d.ts +0 -0
- /package/umd/typings/{utils/expectation-counters/countParagraphs.test.d.ts → src/utils/expectation-counters/countLines.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/expectation-counters/countPages.d.ts +0 -0
- /package/umd/typings/{utils/expectation-counters/countSentences.test.d.ts → src/utils/expectation-counters/countPages.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/expectation-counters/countParagraphs.d.ts +0 -0
- /package/umd/typings/{utils/expectation-counters/countWords.test.d.ts → src/utils/expectation-counters/countParagraphs.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/expectation-counters/countSentences.d.ts +0 -0
- /package/umd/typings/{utils/extractParameters.test.d.ts → src/utils/expectation-counters/countSentences.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/expectation-counters/countWords.d.ts +0 -0
- /package/umd/typings/{utils/formatNumber.test.d.ts → src/utils/expectation-counters/countWords.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/expectation-counters/index.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/extractParameters.d.ts +0 -0
- /package/umd/typings/{utils/markdown-json/countMarkdownStructureDeepness.test.d.ts → src/utils/extractParameters.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/formatNumber.d.ts +0 -0
- /package/umd/typings/{utils/markdown-json/markdownToMarkdownStructure.test.d.ts → src/utils/formatNumber.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/getCurrentIsoDate.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/isRunningInWhatever.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/just.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/addAutoGeneratedSection.d.ts +0 -0
- /package/umd/typings/{utils/markdown/createMarkdownTable.test.d.ts → src/utils/markdown/addAutoGeneratedSection.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/createMarkdownChart.d.ts +0 -0
- /package/umd/typings/{utils/markdown/escapeMarkdownBlock.test.d.ts → src/utils/markdown/createMarkdownChart.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/createMarkdownTable.d.ts +0 -0
- /package/umd/typings/{utils/markdown/extractAllBlocksFromMarkdown.test.d.ts → src/utils/markdown/createMarkdownTable.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/escapeMarkdownBlock.d.ts +0 -0
- /package/umd/typings/{utils/markdown/extractAllListItemsFromMarkdown.test.d.ts → src/utils/markdown/escapeMarkdownBlock.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/extractAllBlocksFromMarkdown.d.ts +0 -0
- /package/umd/typings/{utils/markdown/extractOneBlockFromMarkdown.test.d.ts → src/utils/markdown/extractAllBlocksFromMarkdown.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/extractAllListItemsFromMarkdown.d.ts +0 -0
- /package/umd/typings/{utils/markdown/prettifyMarkdown.test.d.ts → src/utils/markdown/extractAllListItemsFromMarkdown.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/extractOneBlockFromMarkdown.d.ts +0 -0
- /package/umd/typings/{utils/markdown/removeContentComments.test.d.ts → src/utils/markdown/extractOneBlockFromMarkdown.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/prettifyMarkdown.d.ts +0 -0
- /package/umd/typings/{utils/markdown/removeMarkdownFormatting.test.d.ts → src/utils/markdown/prettifyMarkdown.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/removeContentComments.d.ts +0 -0
- /package/umd/typings/{utils/normalization/capitalize.test.d.ts → src/utils/markdown/removeContentComments.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown/removeMarkdownFormatting.d.ts +0 -0
- /package/umd/typings/{utils/normalization/decapitalize.test.d.ts → src/utils/markdown/removeMarkdownFormatting.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown-json/MarkdownStructure.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/markdown-json/countMarkdownStructureDeepness.d.ts +0 -0
- /package/umd/typings/{utils/markdown/addAutoGeneratedSection.test.d.ts → src/utils/markdown-json/countMarkdownStructureDeepness.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/markdown-json/markdownToMarkdownStructure.d.ts +0 -0
- /package/umd/typings/{utils/markdown/createMarkdownChart.test.d.ts → src/utils/markdown-json/markdownToMarkdownStructure.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/DIACRITIC_VARIANTS_LETTERS.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/IKeywords.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/capitalize.d.ts +0 -0
- /package/umd/typings/{utils/normalization/isValidKeyword.test.d.ts → src/utils/normalization/capitalize.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/decapitalize.d.ts +0 -0
- /package/umd/typings/{utils/normalization/nameToUriPart.test.d.ts → src/utils/normalization/decapitalize.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/isValidKeyword.d.ts +0 -0
- /package/umd/typings/{utils/normalization/nameToUriParts.test.d.ts → src/utils/normalization/isValidKeyword.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/nameToUriPart.d.ts +0 -0
- /package/umd/typings/{utils/normalization/normalize-to-kebab-case.test.d.ts → src/utils/normalization/nameToUriPart.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/nameToUriParts.d.ts +0 -0
- /package/umd/typings/{utils/normalization/normalizeTo_PascalCase.test.d.ts → src/utils/normalization/nameToUriParts.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/normalize-to-kebab-case.d.ts +0 -0
- /package/umd/typings/{utils/normalization/normalizeTo_SCREAMING_CASE.test.d.ts → src/utils/normalization/normalize-to-kebab-case.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/normalizeTo_PascalCase.d.ts +0 -0
- /package/umd/typings/{utils/normalization/normalizeTo_camelCase.test.d.ts → src/utils/normalization/normalizeTo_PascalCase.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/normalizeTo_SCREAMING_CASE.d.ts +0 -0
- /package/umd/typings/{utils/normalization/normalizeTo_snake_case.test.d.ts → src/utils/normalization/normalizeTo_SCREAMING_CASE.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/normalizeTo_camelCase.d.ts +0 -0
- /package/umd/typings/{utils/normalization/normalizeWhitespaces.test.d.ts → src/utils/normalization/normalizeTo_camelCase.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/normalizeTo_snake_case.d.ts +0 -0
- /package/umd/typings/{utils/normalization/parseKeywords.test.d.ts → src/utils/normalization/normalizeTo_snake_case.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/normalizeWhitespaces.d.ts +0 -0
- /package/umd/typings/{utils/normalization/parseKeywordsFromString.test.d.ts → src/utils/normalization/normalizeWhitespaces.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/parseKeywords.d.ts +0 -0
- /package/umd/typings/{utils/normalization/removeDiacritics.test.d.ts → src/utils/normalization/parseKeywords.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/parseKeywordsFromString.d.ts +0 -0
- /package/umd/typings/{utils/normalization/searchKeywords.test.d.ts → src/utils/normalization/parseKeywordsFromString.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/removeDiacritics.d.ts +0 -0
- /package/umd/typings/{utils/removeEmojis.test.d.ts → src/utils/normalization/removeDiacritics.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/normalization/searchKeywords.d.ts +0 -0
- /package/umd/typings/{utils/removeQuotes.test.d.ts → src/utils/normalization/searchKeywords.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/postprocessing/extractBlock.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/removeEmojis.d.ts +0 -0
- /package/umd/typings/{utils/sets/difference.test.d.ts → src/utils/removeEmojis.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/removeQuotes.d.ts +0 -0
- /package/umd/typings/{utils/sets/intersection.test.d.ts → src/utils/removeQuotes.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/sets/difference.d.ts +0 -0
- /package/umd/typings/{utils/sets/union.test.d.ts → src/utils/sets/difference.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/sets/intersection.d.ts +0 -0
- /package/umd/typings/{utils/trimCodeBlock.test.d.ts → src/utils/sets/intersection.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/sets/union.d.ts +0 -0
- /package/umd/typings/{utils/trimEndOfCodeBlock.test.d.ts → src/utils/sets/union.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/trimCodeBlock.d.ts +0 -0
- /package/umd/typings/{utils/unwrapResult.test.d.ts → src/utils/trimCodeBlock.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/trimEndOfCodeBlock.d.ts +0 -0
- /package/umd/typings/{utils/validators/url/isValidUrl.test.d.ts → src/utils/trimEndOfCodeBlock.test.d.ts} +0 -0
- /package/umd/typings/{utils → src/utils}/unwrapResult.d.ts +0 -0
- /package/umd/typings/{utils → src/utils}/validators/url/isValidUrl.d.ts +0 -0
- /package/umd/typings/{version.d.ts → src/version.d.ts} +0 -0
package/esm/index.es.js
CHANGED
|
@@ -2,7 +2,7 @@ import colors from 'colors';
|
|
|
2
2
|
import commander from 'commander';
|
|
3
3
|
import { writeFile, readFile } from 'fs/promises';
|
|
4
4
|
import glob from 'glob-promise';
|
|
5
|
-
import { spaceTrim } from 'spacetrim';
|
|
5
|
+
import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
6
6
|
import { forTime } from 'waitasecond';
|
|
7
7
|
import { format } from 'prettier';
|
|
8
8
|
import parserHtml from 'prettier/parser-html';
|
|
@@ -142,7 +142,7 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
|
|
|
142
142
|
/**
|
|
143
143
|
* The version of the Promptbook library
|
|
144
144
|
*/
|
|
145
|
-
var PROMPTBOOK_VERSION = '0.
|
|
145
|
+
var PROMPTBOOK_VERSION = '0.59.0-13';
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
148
|
* Removes HTML or Markdown comments from a string.
|
|
@@ -221,40 +221,66 @@ var PromptbookSyntaxError = /** @class */ (function (_super) {
|
|
|
221
221
|
return PromptbookSyntaxError;
|
|
222
222
|
}(Error));
|
|
223
223
|
|
|
224
|
+
var promptbookLibrary = [{ "title": "Prepare Knowledge from Markdown", "promptbookUrl": "https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md", "promptbookVersion": "0.59.0-13", "parameters": [{ "name": "content", "description": "Markdown document content", "isInput": true, "isOutput": false }, { "name": "knowledge", "description": "The knowledge JSON object", "isInput": false, "isOutput": true }], "promptTemplates": [{ "name": "knowledge", "title": "Knowledge", "dependentParameterNames": ["content"], "executionType": "PROMPT_TEMPLATE", "modelRequirements": { "modelVariant": "CHAT", "modelName": "claude-3-opus-20240229" }, "content": "You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {content}", "resultingParameterName": "knowledge" }], "knowledge": [] }];
|
|
225
|
+
|
|
224
226
|
/**
|
|
225
|
-
*
|
|
227
|
+
* This error indicates errors during the execution of the promptbook
|
|
226
228
|
*/
|
|
227
|
-
var
|
|
229
|
+
var PromptbookExecutionError = /** @class */ (function (_super) {
|
|
230
|
+
__extends(PromptbookExecutionError, _super);
|
|
231
|
+
function PromptbookExecutionError(message) {
|
|
232
|
+
var _this = _super.call(this, message) || this;
|
|
233
|
+
_this.name = 'PromptbookExecutionError';
|
|
234
|
+
Object.setPrototypeOf(_this, PromptbookExecutionError.prototype);
|
|
235
|
+
return _this;
|
|
236
|
+
}
|
|
237
|
+
return PromptbookExecutionError;
|
|
238
|
+
}(Error));
|
|
228
239
|
|
|
229
240
|
/**
|
|
230
|
-
*
|
|
241
|
+
* Asserts that the execution of a promptnook is successful
|
|
231
242
|
*
|
|
232
|
-
* @
|
|
243
|
+
* @param executionResult - The partial result of the promptnook execution
|
|
244
|
+
* @throws {PromptbookExecutionError} If the execution is not successful or if multiple errors occurred
|
|
233
245
|
*/
|
|
234
|
-
function
|
|
235
|
-
var
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
for (var _b = __values(markdownStructure.sections), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
239
|
-
var section = _c.value;
|
|
240
|
-
maxDeepness = Math.max(maxDeepness, countMarkdownStructureDeepness(section));
|
|
241
|
-
}
|
|
246
|
+
function assertsExecutionSuccessful(executionResult) {
|
|
247
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
248
|
+
if (isSuccessful === true) {
|
|
249
|
+
return;
|
|
242
250
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
251
|
+
if (errors.length === 0) {
|
|
252
|
+
throw new PromptbookExecutionError("Promptnook Execution failed because of unknown reason");
|
|
253
|
+
}
|
|
254
|
+
else if (errors.length === 1) {
|
|
255
|
+
throw errors[0];
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
throw new PromptbookExecutionError(spaceTrim(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
|
|
249
259
|
}
|
|
250
|
-
return maxDeepness + 1;
|
|
251
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* TODO: [🧠] Can this return type be better typed than void
|
|
263
|
+
*/
|
|
252
264
|
|
|
253
265
|
/**
|
|
254
266
|
* The maximum number of iterations for a loops
|
|
255
267
|
*/
|
|
256
268
|
var LOOP_LIMIT = 1000;
|
|
257
269
|
|
|
270
|
+
/**
|
|
271
|
+
* This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
|
|
272
|
+
*/
|
|
273
|
+
var PromptbookLogicError = /** @class */ (function (_super) {
|
|
274
|
+
__extends(PromptbookLogicError, _super);
|
|
275
|
+
function PromptbookLogicError(message) {
|
|
276
|
+
var _this = _super.call(this, message) || this;
|
|
277
|
+
_this.name = 'PromptbookLogicError';
|
|
278
|
+
Object.setPrototypeOf(_this, PromptbookLogicError.prototype);
|
|
279
|
+
return _this;
|
|
280
|
+
}
|
|
281
|
+
return PromptbookLogicError;
|
|
282
|
+
}(Error));
|
|
283
|
+
|
|
258
284
|
/**
|
|
259
285
|
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
260
286
|
*/
|
|
@@ -270,1047 +296,2215 @@ var UnexpectedError = /** @class */ (function (_super) {
|
|
|
270
296
|
}(Error));
|
|
271
297
|
|
|
272
298
|
/**
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
* Note: This function does work with code blocks
|
|
276
|
-
* Note: This function does not work with markdown comments
|
|
299
|
+
* Tests if given string is valid URL.
|
|
277
300
|
*
|
|
278
|
-
*
|
|
279
|
-
* @returns The MarkdownStructure object.
|
|
280
|
-
*
|
|
281
|
-
* @private within the library
|
|
301
|
+
* Note: Dataurl are considered perfectly valid.
|
|
282
302
|
*/
|
|
283
|
-
function
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
var current = root;
|
|
288
|
-
var isInsideCodeBlock = false;
|
|
303
|
+
function isValidUrl(url) {
|
|
304
|
+
if (typeof url !== 'string') {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
289
307
|
try {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
var headingMatch = line.match(/^(?<mark>#{1,6})\s(?<title>.*)/);
|
|
293
|
-
if (isInsideCodeBlock || !headingMatch) {
|
|
294
|
-
if (line.startsWith('```')) {
|
|
295
|
-
isInsideCodeBlock = !isInsideCodeBlock;
|
|
296
|
-
}
|
|
297
|
-
current.contentLines.push(line);
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
var level = headingMatch.groups.mark.length;
|
|
301
|
-
var title = headingMatch.groups.title.trim();
|
|
302
|
-
var parent_1 = void 0;
|
|
303
|
-
if (level > current.level) {
|
|
304
|
-
// Note: Going deeper (next section is child of current)
|
|
305
|
-
parent_1 = current;
|
|
306
|
-
}
|
|
307
|
-
else {
|
|
308
|
-
// Note: Going up or staying at the same level (next section is sibling or parent or grandparent,... of current)
|
|
309
|
-
parent_1 = current;
|
|
310
|
-
var loopLimit = LOOP_LIMIT;
|
|
311
|
-
while (parent_1.level !== level - 1) {
|
|
312
|
-
if (loopLimit-- < 0) {
|
|
313
|
-
throw new UnexpectedError('Loop limit reached during parsing of markdown structure in `markdownToMarkdownStructure`');
|
|
314
|
-
}
|
|
315
|
-
if (parent_1.parent === null /* <- Note: We are in root */) {
|
|
316
|
-
// [🌻]
|
|
317
|
-
throw new Error(spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
|
|
318
|
-
}
|
|
319
|
-
parent_1 = parent_1.parent;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
var section = { level: level, title: title, contentLines: [], sections: [], parent: parent_1 };
|
|
323
|
-
parent_1.sections.push(section);
|
|
324
|
-
current = section;
|
|
325
|
-
}
|
|
308
|
+
if (url.startsWith('blob:')) {
|
|
309
|
+
url = url.replace(/^blob:/, '');
|
|
326
310
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
311
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
312
|
+
var urlObject = new URL(url);
|
|
313
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
314
|
+
return false;
|
|
332
315
|
}
|
|
333
|
-
|
|
316
|
+
return true;
|
|
334
317
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
return markdownStructure;
|
|
318
|
+
catch (error) {
|
|
319
|
+
return false;
|
|
338
320
|
}
|
|
339
|
-
// [🌻]
|
|
340
|
-
throw new Error('The markdown file must have exactly one top-level section.');
|
|
341
|
-
// return root;
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* @private
|
|
345
|
-
*/
|
|
346
|
-
function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
|
|
347
|
-
var level = parsingMarkdownStructure.level, title = parsingMarkdownStructure.title, contentLines = parsingMarkdownStructure.contentLines, sections = parsingMarkdownStructure.sections;
|
|
348
|
-
return {
|
|
349
|
-
level: level,
|
|
350
|
-
title: title,
|
|
351
|
-
content: spaceTrim(contentLines.join('\n')),
|
|
352
|
-
sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
|
|
353
|
-
};
|
|
354
321
|
}
|
|
355
322
|
|
|
356
323
|
/**
|
|
357
|
-
*
|
|
324
|
+
* Validates PromptbookJson if it is logically valid
|
|
358
325
|
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
* Note: It flattens nested lists
|
|
362
|
-
* Note: It can not work with html syntax and comments
|
|
326
|
+
* It checks:
|
|
327
|
+
* - if it has correct parameters dependency
|
|
363
328
|
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
329
|
+
* It does NOT check:
|
|
330
|
+
* - if it is valid json
|
|
331
|
+
* - if it is meaningful
|
|
332
|
+
*
|
|
333
|
+
* @param promptbook valid or invalid PromptbookJson
|
|
334
|
+
* @returns the same promptbook if it is logically valid
|
|
335
|
+
* @throws {PromptbookLogicError} on logical error in the promptbook
|
|
366
336
|
*/
|
|
367
|
-
function
|
|
368
|
-
|
|
369
|
-
var
|
|
370
|
-
|
|
371
|
-
|
|
337
|
+
function validatePromptbookJson(promptbook) {
|
|
338
|
+
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
339
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
340
|
+
if (promptbook.promptbookUrl !== undefined) {
|
|
341
|
+
if (!isValidUrl(promptbook.promptbookUrl)) {
|
|
342
|
+
// TODO: This should be maybe the syntax error detected during parsing
|
|
343
|
+
throw new PromptbookLogicError("Invalid promptbook URL \"".concat(promptbook.promptbookUrl, "\""));
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
347
|
+
if (!Array.isArray(promptbook.parameters)) {
|
|
348
|
+
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
349
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.parameters expected to be an array, but got ".concat(typeof promptbook.parameters, "\n ")));
|
|
350
|
+
}
|
|
351
|
+
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
352
|
+
if (!Array.isArray(promptbook.promptTemplates)) {
|
|
353
|
+
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
354
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.promptTemplates expected to be an array, but got ".concat(typeof promptbook.promptTemplates, "\n ")));
|
|
355
|
+
}
|
|
356
|
+
var _loop_1 = function (parameter) {
|
|
357
|
+
if (parameter.isInput && parameter.isOutput) {
|
|
358
|
+
throw new PromptbookLogicError("Parameter {".concat(parameter.name, "} can not be both input and output"));
|
|
359
|
+
}
|
|
360
|
+
// Note: Testing that parameter is either intermediate or output BUT not created and unused
|
|
361
|
+
if (!parameter.isInput &&
|
|
362
|
+
!parameter.isOutput &&
|
|
363
|
+
!promptbook.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
|
|
364
|
+
throw new PromptbookLogicError(spaceTrim("\n Parameter {".concat(parameter.name, "} is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ")));
|
|
365
|
+
}
|
|
366
|
+
// Note: Testing that parameter is either input or result of some template
|
|
367
|
+
if (!parameter.isInput &&
|
|
368
|
+
!promptbook.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
|
|
369
|
+
throw new PromptbookLogicError(spaceTrim("\n Parameter {".concat(parameter.name, "} is declared but not defined\n\n You can do one of these:\n - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ")));
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
372
|
try {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
var
|
|
376
|
-
|
|
377
|
-
isInCodeBlock = !isInCodeBlock;
|
|
378
|
-
}
|
|
379
|
-
if (!isInCodeBlock && (trimmedLine.startsWith('-') || trimmedLine.match(/^\d+\./))) {
|
|
380
|
-
var listItem = trimmedLine.replace(/^-|\d+\./, '').trim();
|
|
381
|
-
listItems.push(listItem);
|
|
382
|
-
}
|
|
373
|
+
// Note: Check each parameter individually
|
|
374
|
+
for (var _e = __values(promptbook.parameters), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
375
|
+
var parameter = _f.value;
|
|
376
|
+
_loop_1(parameter);
|
|
383
377
|
}
|
|
384
378
|
}
|
|
385
379
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
386
380
|
finally {
|
|
387
381
|
try {
|
|
388
|
-
if (
|
|
382
|
+
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
389
383
|
}
|
|
390
384
|
finally { if (e_1) throw e_1.error; }
|
|
391
385
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* Extracts all code blocks from markdown.
|
|
405
|
-
*
|
|
406
|
-
* Note: There are 3 simmilar function:
|
|
407
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
408
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
409
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
410
|
-
*
|
|
411
|
-
* @param markdown any valid markdown
|
|
412
|
-
* @returns code blocks with language and content
|
|
413
|
-
*
|
|
414
|
-
*/
|
|
415
|
-
function extractAllBlocksFromMarkdown(markdown) {
|
|
416
|
-
var e_1, _a;
|
|
417
|
-
var codeBlocks = [];
|
|
418
|
-
var lines = markdown.split('\n');
|
|
419
|
-
var currentCodeBlock = null;
|
|
386
|
+
// Note: Check each template individually
|
|
387
|
+
var definedParameters = new Set(promptbook.parameters.filter(function (_a) {
|
|
388
|
+
var isInput = _a.isInput;
|
|
389
|
+
return isInput;
|
|
390
|
+
}).map(function (_a) {
|
|
391
|
+
var name = _a.name;
|
|
392
|
+
return name;
|
|
393
|
+
}));
|
|
420
394
|
try {
|
|
421
|
-
for (var
|
|
422
|
-
var
|
|
423
|
-
if (
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
395
|
+
for (var _g = __values(promptbook.promptTemplates), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
396
|
+
var template = _h.value;
|
|
397
|
+
if (definedParameters.has(template.resultingParameterName)) {
|
|
398
|
+
throw new PromptbookLogicError("Parameter {".concat(template.resultingParameterName, "} is defined multiple times"));
|
|
399
|
+
}
|
|
400
|
+
definedParameters.add(template.resultingParameterName);
|
|
401
|
+
if (template.executionType === 'PROMPT_TEMPLATE' &&
|
|
402
|
+
(template.modelRequirements.modelVariant === undefined)) {
|
|
403
|
+
throw new PromptbookLogicError(spaceTrim("\n\n You must specify MODEL VARIANT in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
|
|
404
|
+
}
|
|
405
|
+
if (template.jokers && template.jokers.length > 0) {
|
|
406
|
+
if (!template.expectFormat &&
|
|
407
|
+
!template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
408
|
+
throw new PromptbookLogicError("Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined"));
|
|
427
409
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
410
|
+
try {
|
|
411
|
+
for (var _j = (e_3 = void 0, __values(template.jokers)), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
412
|
+
var joker = _k.value;
|
|
413
|
+
if (!template.dependentParameterNames.includes(joker)) {
|
|
414
|
+
throw new PromptbookLogicError("Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in dependentParameterNames"));
|
|
415
|
+
}
|
|
432
416
|
}
|
|
433
|
-
|
|
434
|
-
|
|
417
|
+
}
|
|
418
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
419
|
+
finally {
|
|
420
|
+
try {
|
|
421
|
+
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
422
|
+
}
|
|
423
|
+
finally { if (e_3) throw e_3.error; }
|
|
435
424
|
}
|
|
436
425
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
426
|
+
if (template.expectations) {
|
|
427
|
+
try {
|
|
428
|
+
for (var _l = (e_4 = void 0, __values(Object.entries(template.expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
429
|
+
var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
|
|
430
|
+
if (min !== undefined && max !== undefined && min > max) {
|
|
431
|
+
throw new PromptbookLogicError("Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")"));
|
|
432
|
+
}
|
|
433
|
+
if (min !== undefined && min < 0) {
|
|
434
|
+
throw new PromptbookLogicError("Min expectation of ".concat(unit, " must be zero or positive"));
|
|
435
|
+
}
|
|
436
|
+
if (max !== undefined && max <= 0) {
|
|
437
|
+
throw new PromptbookLogicError("Max expectation of ".concat(unit, " must be positive"));
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
442
|
+
finally {
|
|
443
|
+
try {
|
|
444
|
+
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
|
|
445
|
+
}
|
|
446
|
+
finally { if (e_4) throw e_4.error; }
|
|
440
447
|
}
|
|
441
|
-
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
442
448
|
}
|
|
443
449
|
}
|
|
444
450
|
}
|
|
445
|
-
catch (
|
|
451
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
446
452
|
finally {
|
|
447
453
|
try {
|
|
448
|
-
if (
|
|
454
|
+
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
449
455
|
}
|
|
450
|
-
finally { if (
|
|
456
|
+
finally { if (e_2) throw e_2.error; }
|
|
451
457
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
458
|
+
// Note: Detect circular dependencies
|
|
459
|
+
var resovedParameters = promptbook.parameters
|
|
460
|
+
.filter(function (_a) {
|
|
461
|
+
var isInput = _a.isInput;
|
|
462
|
+
return isInput;
|
|
463
|
+
})
|
|
464
|
+
.map(function (_a) {
|
|
465
|
+
var name = _a.name;
|
|
466
|
+
return name;
|
|
467
|
+
});
|
|
468
|
+
var unresovedTemplates = __spreadArray([], __read(promptbook.promptTemplates), false);
|
|
469
|
+
var loopLimit = LOOP_LIMIT;
|
|
470
|
+
var _loop_2 = function () {
|
|
471
|
+
if (loopLimit-- < 0) {
|
|
472
|
+
throw new UnexpectedError('Loop limit reached during detection of circular dependencies in `validatePromptbookJson`');
|
|
473
|
+
}
|
|
474
|
+
var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
|
|
475
|
+
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
476
|
+
});
|
|
477
|
+
if (currentlyResovedTemplates.length === 0) {
|
|
478
|
+
throw new PromptbookLogicError(spaceTrim(function (block) { return "\n\n Can not resolve some parameters\n It may be circular dependencies\n\n Can not resolve:\n ".concat(block(unresovedTemplates
|
|
479
|
+
.map(function (_a) {
|
|
480
|
+
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
481
|
+
return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
|
|
482
|
+
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
483
|
+
.join(', '));
|
|
484
|
+
})
|
|
485
|
+
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameters.map(function (name) { return "- {".concat(name, "}"); }).join('\n')), "\n "); }));
|
|
486
|
+
}
|
|
487
|
+
resovedParameters = __spreadArray(__spreadArray([], __read(resovedParameters), false), __read(currentlyResovedTemplates.map(function (_a) {
|
|
488
|
+
var resultingParameterName = _a.resultingParameterName;
|
|
489
|
+
return resultingParameterName;
|
|
490
|
+
})), false);
|
|
491
|
+
unresovedTemplates = unresovedTemplates.filter(function (template) { return !currentlyResovedTemplates.includes(template); });
|
|
492
|
+
};
|
|
493
|
+
while (unresovedTemplates.length > 0) {
|
|
494
|
+
_loop_2();
|
|
455
495
|
}
|
|
456
|
-
return
|
|
496
|
+
return promptbook;
|
|
457
497
|
}
|
|
498
|
+
/**
|
|
499
|
+
* TODO: [🧠] Work with promptbookVersion
|
|
500
|
+
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
501
|
+
* > /**
|
|
502
|
+
* > * Validates PromptbookJson if it is logically valid.
|
|
503
|
+
* > *
|
|
504
|
+
* > * It checks:
|
|
505
|
+
* > * - it has a valid structure
|
|
506
|
+
* > * - ...
|
|
507
|
+
* > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
|
|
508
|
+
*/
|
|
458
509
|
|
|
459
510
|
/**
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
* Note: If there are multiple or no code blocks the function throws an error
|
|
463
|
-
*
|
|
464
|
-
* Note: There are 3 simmilar function:
|
|
465
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
466
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
467
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
511
|
+
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
468
512
|
*
|
|
469
|
-
* @
|
|
470
|
-
*
|
|
513
|
+
* @private Always catched and rethrown as `PromptbookExecutionError`
|
|
514
|
+
* Note: This is a kindof subtype of PromptbookExecutionError
|
|
471
515
|
*/
|
|
472
|
-
function
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
516
|
+
var ExpectError = /** @class */ (function (_super) {
|
|
517
|
+
__extends(ExpectError, _super);
|
|
518
|
+
function ExpectError(message) {
|
|
519
|
+
var _this = _super.call(this, message) || this;
|
|
520
|
+
_this.name = 'ExpectError';
|
|
521
|
+
Object.setPrototypeOf(_this, ExpectError.prototype);
|
|
522
|
+
return _this;
|
|
477
523
|
}
|
|
478
|
-
return
|
|
479
|
-
}
|
|
480
|
-
/***
|
|
481
|
-
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
482
|
-
*/
|
|
524
|
+
return ExpectError;
|
|
525
|
+
}(Error));
|
|
483
526
|
|
|
484
527
|
/**
|
|
485
|
-
*
|
|
528
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
486
529
|
*/
|
|
487
|
-
function
|
|
488
|
-
var e_1, _a, e_2, _b;
|
|
489
|
-
var sets = [];
|
|
490
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
491
|
-
sets[_i] = arguments[_i];
|
|
492
|
-
}
|
|
493
|
-
var union = new Set();
|
|
494
|
-
try {
|
|
495
|
-
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
496
|
-
var set = sets_1_1.value;
|
|
497
|
-
try {
|
|
498
|
-
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
499
|
-
var item = _d.value;
|
|
500
|
-
union.add(item);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
504
|
-
finally {
|
|
505
|
-
try {
|
|
506
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
507
|
-
}
|
|
508
|
-
finally { if (e_2) throw e_2.error; }
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
513
|
-
finally {
|
|
514
|
-
try {
|
|
515
|
-
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
516
|
-
}
|
|
517
|
-
finally { if (e_1) throw e_1.error; }
|
|
518
|
-
}
|
|
519
|
-
return union;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
/**
|
|
523
|
-
* Parses the template and returns the list of all parameter names
|
|
524
|
-
*
|
|
525
|
-
* @param template the template with parameters in {curly} braces
|
|
526
|
-
* @returns the list of parameter names
|
|
527
|
-
*/
|
|
528
|
-
function extractParameters(template) {
|
|
529
|
-
var e_1, _a;
|
|
530
|
-
var matches = template.matchAll(/{\w+}/g);
|
|
531
|
-
var parameterNames = new Set();
|
|
532
|
-
try {
|
|
533
|
-
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
534
|
-
var match = matches_1_1.value;
|
|
535
|
-
var parameterName = match[0].slice(1, -1);
|
|
536
|
-
parameterNames.add(parameterName);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
540
|
-
finally {
|
|
541
|
-
try {
|
|
542
|
-
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
543
|
-
}
|
|
544
|
-
finally { if (e_1) throw e_1.error; }
|
|
545
|
-
}
|
|
546
|
-
return parameterNames;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
/**
|
|
550
|
-
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
551
|
-
*
|
|
552
|
-
* @param script from which to extract the variables
|
|
553
|
-
* @returns the list of variable names
|
|
554
|
-
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
555
|
-
*/
|
|
556
|
-
function extractVariables(script) {
|
|
557
|
-
var variables = new Set();
|
|
558
|
-
script = "(()=>{".concat(script, "})()");
|
|
530
|
+
function isValidJsonString(value /* <-[👨⚖️] */) {
|
|
559
531
|
try {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
eval(script);
|
|
563
|
-
}
|
|
564
|
-
catch (error) {
|
|
565
|
-
if (!(error instanceof ReferenceError)) {
|
|
566
|
-
throw error;
|
|
567
|
-
}
|
|
568
|
-
var undefinedName = error.message.split(' ')[0];
|
|
569
|
-
/*
|
|
570
|
-
Note: Remapping error
|
|
571
|
-
From: [ReferenceError: thing is not defined],
|
|
572
|
-
To: [Error: Parameter {thing} is not defined],
|
|
573
|
-
*/
|
|
574
|
-
if (!undefinedName) {
|
|
575
|
-
throw error;
|
|
576
|
-
}
|
|
577
|
-
if (script.includes(undefinedName + '(')) {
|
|
578
|
-
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
579
|
-
}
|
|
580
|
-
else {
|
|
581
|
-
variables.add(undefinedName);
|
|
582
|
-
script = "const ".concat(undefinedName, " = '';") + script;
|
|
583
|
-
}
|
|
584
|
-
}
|
|
532
|
+
JSON.parse(value);
|
|
533
|
+
return true;
|
|
585
534
|
}
|
|
586
535
|
catch (error) {
|
|
587
536
|
if (!(error instanceof Error)) {
|
|
588
537
|
throw error;
|
|
589
538
|
}
|
|
590
|
-
|
|
539
|
+
if (error.message.includes('Unexpected token')) {
|
|
540
|
+
return false;
|
|
541
|
+
}
|
|
542
|
+
return false;
|
|
591
543
|
}
|
|
592
|
-
return variables;
|
|
593
544
|
}
|
|
594
|
-
/**
|
|
595
|
-
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
596
|
-
*/
|
|
597
545
|
|
|
598
546
|
/**
|
|
599
|
-
*
|
|
547
|
+
* Function `addUsage` will add multiple usages into one
|
|
600
548
|
*
|
|
601
|
-
*
|
|
602
|
-
* @returns the set of parameter names
|
|
603
|
-
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
549
|
+
* Note: If you provide 0 values, it returns void usage
|
|
604
550
|
*/
|
|
605
|
-
function
|
|
606
|
-
var
|
|
607
|
-
var
|
|
608
|
-
|
|
609
|
-
for (var _c = __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(promptTemplate.title)), false), __read(extractParameters(promptTemplate.description || '')), false), __read(extractParameters(promptTemplate.content)), false)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
610
|
-
var parameterName = _d.value;
|
|
611
|
-
parameterNames.add(parameterName);
|
|
612
|
-
}
|
|
551
|
+
function addUsage() {
|
|
552
|
+
var usageItems = [];
|
|
553
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
554
|
+
usageItems[_i] = arguments[_i];
|
|
613
555
|
}
|
|
614
|
-
|
|
615
|
-
|
|
556
|
+
var initialStructure = {
|
|
557
|
+
price: { value: 0 },
|
|
558
|
+
input: {
|
|
559
|
+
tokensCount: { value: 0 },
|
|
560
|
+
charactersCount: { value: 0 },
|
|
561
|
+
wordsCount: { value: 0 },
|
|
562
|
+
sentencesCount: { value: 0 },
|
|
563
|
+
linesCount: { value: 0 },
|
|
564
|
+
paragraphsCount: { value: 0 },
|
|
565
|
+
pagesCount: { value: 0 },
|
|
566
|
+
},
|
|
567
|
+
output: {
|
|
568
|
+
tokensCount: { value: 0 },
|
|
569
|
+
charactersCount: { value: 0 },
|
|
570
|
+
wordsCount: { value: 0 },
|
|
571
|
+
sentencesCount: { value: 0 },
|
|
572
|
+
linesCount: { value: 0 },
|
|
573
|
+
paragraphsCount: { value: 0 },
|
|
574
|
+
pagesCount: { value: 0 },
|
|
575
|
+
},
|
|
576
|
+
};
|
|
577
|
+
return usageItems.reduce(function (acc, item) {
|
|
578
|
+
var e_1, _a, e_2, _b;
|
|
579
|
+
var _c;
|
|
580
|
+
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
616
581
|
try {
|
|
617
|
-
|
|
582
|
+
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
583
|
+
var key = _e.value;
|
|
584
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
585
|
+
//@ts-ignore
|
|
586
|
+
if (item.input[key]) {
|
|
587
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
588
|
+
//@ts-ignore
|
|
589
|
+
acc.input[key].value += item.input[key].value || 0;
|
|
590
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
591
|
+
//@ts-ignore
|
|
592
|
+
if (item.input[key].isUncertain) {
|
|
593
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
594
|
+
//@ts-ignore
|
|
595
|
+
acc.input[key].isUncertain = true;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
601
|
+
finally {
|
|
602
|
+
try {
|
|
603
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
604
|
+
}
|
|
605
|
+
finally { if (e_1) throw e_1.error; }
|
|
618
606
|
}
|
|
619
|
-
finally { if (e_1) throw e_1.error; }
|
|
620
|
-
}
|
|
621
|
-
if (promptTemplate.executionType === 'SCRIPT') {
|
|
622
607
|
try {
|
|
623
|
-
for (var
|
|
624
|
-
var
|
|
625
|
-
|
|
608
|
+
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
609
|
+
var key = _g.value;
|
|
610
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
611
|
+
//@ts-ignore
|
|
612
|
+
if (item.output[key]) {
|
|
613
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
614
|
+
//@ts-ignore
|
|
615
|
+
acc.output[key].value += item.output[key].value || 0;
|
|
616
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
617
|
+
//@ts-ignore
|
|
618
|
+
if (item.output[key].isUncertain) {
|
|
619
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
620
|
+
//@ts-ignore
|
|
621
|
+
acc.output[key].isUncertain = true;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
626
624
|
}
|
|
627
625
|
}
|
|
628
626
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
629
627
|
finally {
|
|
630
628
|
try {
|
|
631
|
-
if (
|
|
629
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
632
630
|
}
|
|
633
631
|
finally { if (e_2) throw e_2.error; }
|
|
634
632
|
}
|
|
635
|
-
|
|
636
|
-
|
|
633
|
+
return acc;
|
|
634
|
+
}, initialStructure);
|
|
637
635
|
}
|
|
638
|
-
/**
|
|
639
|
-
* TODO: [🔣] If script require contentLanguage
|
|
640
|
-
*/
|
|
641
636
|
|
|
642
|
-
/* tslint:disable */
|
|
643
|
-
/*
|
|
644
|
-
TODO: Tests
|
|
645
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
646
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
647
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
648
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
649
|
-
*/
|
|
650
|
-
function normalizeTo_SCREAMING_CASE(sentence) {
|
|
651
|
-
var e_1, _a;
|
|
652
|
-
var charType;
|
|
653
|
-
var lastCharType = 'OTHER';
|
|
654
|
-
var normalizedName = '';
|
|
655
|
-
try {
|
|
656
|
-
for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
|
|
657
|
-
var char = sentence_1_1.value;
|
|
658
|
-
var normalizedChar = void 0;
|
|
659
|
-
if (/^[a-z]$/.test(char)) {
|
|
660
|
-
charType = 'LOWERCASE';
|
|
661
|
-
normalizedChar = char.toUpperCase();
|
|
662
|
-
}
|
|
663
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
664
|
-
charType = 'UPPERCASE';
|
|
665
|
-
normalizedChar = char;
|
|
666
|
-
}
|
|
667
|
-
else if (/^[0-9]$/.test(char)) {
|
|
668
|
-
charType = 'NUMBER';
|
|
669
|
-
normalizedChar = char;
|
|
670
|
-
}
|
|
671
|
-
else if (/^\/$/.test(char)) {
|
|
672
|
-
charType = 'SLASH';
|
|
673
|
-
normalizedChar = char;
|
|
674
|
-
}
|
|
675
|
-
else {
|
|
676
|
-
charType = 'OTHER';
|
|
677
|
-
normalizedChar = '_';
|
|
678
|
-
}
|
|
679
|
-
if (charType !== lastCharType &&
|
|
680
|
-
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
681
|
-
!(lastCharType === 'NUMBER') &&
|
|
682
|
-
!(charType === 'NUMBER')) {
|
|
683
|
-
normalizedName += '_';
|
|
684
|
-
}
|
|
685
|
-
normalizedName += normalizedChar;
|
|
686
|
-
lastCharType = charType;
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
690
|
-
finally {
|
|
691
|
-
try {
|
|
692
|
-
if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
|
|
693
|
-
}
|
|
694
|
-
finally { if (e_1) throw e_1.error; }
|
|
695
|
-
}
|
|
696
|
-
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
697
|
-
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
698
|
-
normalizedName = normalizedName.replace(/^_/, '');
|
|
699
|
-
normalizedName = normalizedName.replace(/_$/, '');
|
|
700
|
-
return normalizedName;
|
|
701
|
-
}
|
|
702
637
|
/**
|
|
703
|
-
*
|
|
638
|
+
* Counts number of characters in the text
|
|
704
639
|
*/
|
|
640
|
+
function countCharacters(text) {
|
|
641
|
+
// Remove null characters
|
|
642
|
+
text = text.replace(/\0/g, '');
|
|
643
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
644
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
645
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
646
|
+
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
647
|
+
return text.length;
|
|
648
|
+
}
|
|
705
649
|
|
|
706
650
|
/**
|
|
707
|
-
*
|
|
708
|
-
*
|
|
709
|
-
* @see https://github.com/webgptorg/promptbook#execution-type
|
|
651
|
+
* Counts number of lines in the text
|
|
710
652
|
*/
|
|
711
|
-
|
|
712
|
-
'
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
'
|
|
716
|
-
|
|
717
|
-
];
|
|
653
|
+
function countLines(text) {
|
|
654
|
+
if (text === '') {
|
|
655
|
+
return 0;
|
|
656
|
+
}
|
|
657
|
+
return text.split('\n').length;
|
|
658
|
+
}
|
|
718
659
|
|
|
719
660
|
/**
|
|
720
|
-
*
|
|
661
|
+
* Counts number of pages in the text
|
|
721
662
|
*/
|
|
722
|
-
|
|
663
|
+
function countPages(text) {
|
|
664
|
+
var sentencesPerPage = 5; // Assuming each page has 5 sentences
|
|
665
|
+
var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
666
|
+
var pageCount = Math.ceil(sentences.length / sentencesPerPage);
|
|
667
|
+
return pageCount;
|
|
668
|
+
}
|
|
669
|
+
|
|
723
670
|
/**
|
|
724
|
-
*
|
|
725
|
-
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
726
|
-
* TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
|
|
671
|
+
* Counts number of paragraphs in the text
|
|
727
672
|
*/
|
|
673
|
+
function countParagraphs(text) {
|
|
674
|
+
return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
|
|
675
|
+
}
|
|
728
676
|
|
|
729
677
|
/**
|
|
730
|
-
*
|
|
731
|
-
*
|
|
732
|
-
* @param {string} str - The string to remove Markdown tags from.
|
|
733
|
-
* @returns {string} The input string with all Markdown tags removed.
|
|
678
|
+
* Split text into sentences
|
|
734
679
|
*/
|
|
735
|
-
function
|
|
736
|
-
|
|
737
|
-
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
738
|
-
// Remove italic formatting
|
|
739
|
-
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
740
|
-
// Remove code formatting
|
|
741
|
-
str = str.replace(/`(.*?)`/g, '$1');
|
|
742
|
-
return str;
|
|
680
|
+
function splitIntoSentences(text) {
|
|
681
|
+
return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
743
682
|
}
|
|
744
|
-
|
|
745
683
|
/**
|
|
746
|
-
*
|
|
747
|
-
*
|
|
748
|
-
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
749
|
-
* Note: it also works only with decimal numbers
|
|
750
|
-
*
|
|
751
|
-
* @returns parsed number
|
|
752
|
-
* @throws {PromptbookSyntaxError} if the value is not a number
|
|
753
|
-
*
|
|
754
|
-
* @private within the parseCommand
|
|
684
|
+
* Counts number of sentences in the text
|
|
755
685
|
*/
|
|
756
|
-
function
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
686
|
+
function countSentences(text) {
|
|
687
|
+
return splitIntoSentences(text).length;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
var defaultDiacriticsRemovalMap = [
|
|
691
|
+
{
|
|
692
|
+
base: 'A',
|
|
693
|
+
letters: '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F',
|
|
694
|
+
},
|
|
695
|
+
{ base: 'AA', letters: '\uA732' },
|
|
696
|
+
{ base: 'AE', letters: '\u00C6\u01FC\u01E2' },
|
|
697
|
+
{ base: 'AO', letters: '\uA734' },
|
|
698
|
+
{ base: 'AU', letters: '\uA736' },
|
|
699
|
+
{ base: 'AV', letters: '\uA738\uA73A' },
|
|
700
|
+
{ base: 'AY', letters: '\uA73C' },
|
|
701
|
+
{
|
|
702
|
+
base: 'B',
|
|
703
|
+
letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
|
|
704
|
+
},
|
|
705
|
+
{
|
|
706
|
+
base: 'C',
|
|
707
|
+
letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
|
|
708
|
+
},
|
|
709
|
+
{
|
|
710
|
+
base: 'D',
|
|
711
|
+
letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
|
|
712
|
+
},
|
|
713
|
+
{ base: 'DZ', letters: '\u01F1\u01C4' },
|
|
714
|
+
{ base: 'Dz', letters: '\u01F2\u01C5' },
|
|
715
|
+
{
|
|
716
|
+
base: 'E',
|
|
717
|
+
letters: '\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E',
|
|
718
|
+
},
|
|
719
|
+
{ base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
|
|
720
|
+
{
|
|
721
|
+
base: 'G',
|
|
722
|
+
letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
base: 'H',
|
|
726
|
+
letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
base: 'I',
|
|
730
|
+
letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
|
|
731
|
+
},
|
|
732
|
+
{ base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
|
|
733
|
+
{
|
|
734
|
+
base: 'K',
|
|
735
|
+
letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
|
|
736
|
+
},
|
|
737
|
+
{
|
|
738
|
+
base: 'L',
|
|
739
|
+
letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
|
|
740
|
+
},
|
|
741
|
+
{ base: 'LJ', letters: '\u01C7' },
|
|
742
|
+
{ base: 'Lj', letters: '\u01C8' },
|
|
743
|
+
{ base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
|
|
744
|
+
{
|
|
745
|
+
base: 'N',
|
|
746
|
+
letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
|
|
747
|
+
},
|
|
748
|
+
{ base: 'NJ', letters: '\u01CA' },
|
|
749
|
+
{ base: 'Nj', letters: '\u01CB' },
|
|
750
|
+
{
|
|
751
|
+
base: 'O',
|
|
752
|
+
letters: '\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C',
|
|
753
|
+
},
|
|
754
|
+
{ base: 'OI', letters: '\u01A2' },
|
|
755
|
+
{ base: 'OO', letters: '\uA74E' },
|
|
756
|
+
{ base: 'OU', letters: '\u0222' },
|
|
757
|
+
{ base: 'OE', letters: '\u008C\u0152' },
|
|
758
|
+
{ base: 'oe', letters: '\u009C\u0153' },
|
|
759
|
+
{
|
|
760
|
+
base: 'P',
|
|
761
|
+
letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
|
|
762
|
+
},
|
|
763
|
+
{ base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
|
|
764
|
+
{
|
|
765
|
+
base: 'R',
|
|
766
|
+
letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
base: 'S',
|
|
770
|
+
letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
base: 'T',
|
|
774
|
+
letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
|
|
775
|
+
},
|
|
776
|
+
{ base: 'TZ', letters: '\uA728' },
|
|
777
|
+
{
|
|
778
|
+
base: 'U',
|
|
779
|
+
letters: '\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244',
|
|
780
|
+
},
|
|
781
|
+
{ base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
|
|
782
|
+
{ base: 'VY', letters: '\uA760' },
|
|
783
|
+
{
|
|
784
|
+
base: 'W',
|
|
785
|
+
letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
|
|
786
|
+
},
|
|
787
|
+
{ base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
|
|
788
|
+
{
|
|
789
|
+
base: 'Y',
|
|
790
|
+
letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
|
|
791
|
+
},
|
|
792
|
+
{
|
|
793
|
+
base: 'Z',
|
|
794
|
+
letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
base: 'a',
|
|
798
|
+
letters: '\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250',
|
|
799
|
+
},
|
|
800
|
+
{ base: 'aa', letters: '\uA733' },
|
|
801
|
+
{ base: 'ae', letters: '\u00E6\u01FD\u01E3' },
|
|
802
|
+
{ base: 'ao', letters: '\uA735' },
|
|
803
|
+
{ base: 'au', letters: '\uA737' },
|
|
804
|
+
{ base: 'av', letters: '\uA739\uA73B' },
|
|
805
|
+
{ base: 'ay', letters: '\uA73D' },
|
|
806
|
+
{
|
|
807
|
+
base: 'b',
|
|
808
|
+
letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
|
|
809
|
+
},
|
|
810
|
+
{
|
|
811
|
+
base: 'c',
|
|
812
|
+
letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
|
|
813
|
+
},
|
|
814
|
+
{
|
|
815
|
+
base: 'd',
|
|
816
|
+
letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
|
|
817
|
+
},
|
|
818
|
+
{ base: 'dz', letters: '\u01F3\u01C6' },
|
|
819
|
+
{
|
|
820
|
+
base: 'e',
|
|
821
|
+
letters: '\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD',
|
|
822
|
+
},
|
|
823
|
+
{ base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
|
|
824
|
+
{
|
|
825
|
+
base: 'g',
|
|
826
|
+
letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
base: 'h',
|
|
830
|
+
letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
|
|
831
|
+
},
|
|
832
|
+
{ base: 'hv', letters: '\u0195' },
|
|
833
|
+
{
|
|
834
|
+
base: 'i',
|
|
835
|
+
letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
|
|
836
|
+
},
|
|
837
|
+
{ base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
|
|
838
|
+
{
|
|
839
|
+
base: 'k',
|
|
840
|
+
letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
|
|
841
|
+
},
|
|
842
|
+
{
|
|
843
|
+
base: 'l',
|
|
844
|
+
letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
|
|
845
|
+
},
|
|
846
|
+
{ base: 'lj', letters: '\u01C9' },
|
|
847
|
+
{ base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
|
|
848
|
+
{
|
|
849
|
+
base: 'n',
|
|
850
|
+
letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
|
|
851
|
+
},
|
|
852
|
+
{ base: 'nj', letters: '\u01CC' },
|
|
853
|
+
{
|
|
854
|
+
base: 'o',
|
|
855
|
+
letters: '\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275',
|
|
856
|
+
},
|
|
857
|
+
{ base: 'oi', letters: '\u01A3' },
|
|
858
|
+
{ base: 'ou', letters: '\u0223' },
|
|
859
|
+
{ base: 'oo', letters: '\uA74F' },
|
|
860
|
+
{
|
|
861
|
+
base: 'p',
|
|
862
|
+
letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
|
|
863
|
+
},
|
|
864
|
+
{ base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
|
|
865
|
+
{
|
|
866
|
+
base: 'r',
|
|
867
|
+
letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
|
|
868
|
+
},
|
|
869
|
+
{
|
|
870
|
+
base: 's',
|
|
871
|
+
letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
base: 't',
|
|
875
|
+
letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
|
|
876
|
+
},
|
|
877
|
+
{ base: 'tz', letters: '\uA729' },
|
|
878
|
+
{
|
|
879
|
+
base: 'u',
|
|
880
|
+
letters: '\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289',
|
|
881
|
+
},
|
|
882
|
+
{ base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
|
|
883
|
+
{ base: 'vy', letters: '\uA761' },
|
|
884
|
+
{
|
|
885
|
+
base: 'w',
|
|
886
|
+
letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
|
|
887
|
+
},
|
|
888
|
+
{ base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
|
|
889
|
+
{
|
|
890
|
+
base: 'y',
|
|
891
|
+
letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
|
|
892
|
+
},
|
|
893
|
+
{
|
|
894
|
+
base: 'z',
|
|
895
|
+
letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
|
|
896
|
+
},
|
|
897
|
+
];
|
|
898
|
+
/**
|
|
899
|
+
* Map of letters from diacritic variant to diacritless variant
|
|
900
|
+
* Contains lowercase and uppercase separatelly
|
|
901
|
+
*
|
|
902
|
+
* > "á" => "a"
|
|
903
|
+
* > "ě" => "e"
|
|
904
|
+
* > "Ă" => "A"
|
|
905
|
+
* > ...
|
|
906
|
+
*/
|
|
907
|
+
var DIACRITIC_VARIANTS_LETTERS = {};
|
|
908
|
+
// tslint:disable-next-line: prefer-for-of
|
|
909
|
+
for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
910
|
+
var letters = defaultDiacriticsRemovalMap[i].letters;
|
|
911
|
+
// tslint:disable-next-line: prefer-for-of
|
|
912
|
+
for (var j = 0; j < letters.length; j++) {
|
|
913
|
+
DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
|
|
767
914
|
}
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
915
|
+
}
|
|
916
|
+
// <- TODO: [🍓] Put to maker function to save execution time if not needed
|
|
917
|
+
/*
|
|
918
|
+
@see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
|
|
919
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
920
|
+
you may not use this file except in compliance with the License.
|
|
921
|
+
You may obtain a copy of the License at
|
|
922
|
+
|
|
923
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
924
|
+
|
|
925
|
+
Unless required by applicable law or agreed to in writing, software
|
|
926
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
927
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
928
|
+
See the License for the specific language governing permissions and
|
|
929
|
+
limitations under the License.
|
|
930
|
+
*/
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
*
|
|
934
|
+
*/
|
|
935
|
+
function removeDiacritics(input) {
|
|
936
|
+
/*eslint no-control-regex: "off"*/
|
|
937
|
+
return input.replace(/[^\u0000-\u007E]/g, function (a) {
|
|
938
|
+
return DIACRITIC_VARIANTS_LETTERS[a] || a;
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
/**
|
|
943
|
+
* Counts number of words in the text
|
|
944
|
+
*/
|
|
945
|
+
function countWords(text) {
|
|
946
|
+
text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
|
|
947
|
+
text = removeDiacritics(text);
|
|
948
|
+
return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* Index of all counter functions
|
|
953
|
+
*/
|
|
954
|
+
var CountUtils = {
|
|
955
|
+
CHARACTERS: countCharacters,
|
|
956
|
+
WORDS: countWords,
|
|
957
|
+
SENTENCES: countSentences,
|
|
958
|
+
PARAGRAPHS: countParagraphs,
|
|
959
|
+
LINES: countLines,
|
|
960
|
+
PAGES: countPages,
|
|
961
|
+
};
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* Function checkExpectations will check if the expectations on given value are met
|
|
965
|
+
*
|
|
966
|
+
* Note: There are two simmilar functions:
|
|
967
|
+
* - `checkExpectations` which throws an error if the expectations are not met
|
|
968
|
+
* - `isPassingExpectations` which returns a boolean
|
|
969
|
+
*
|
|
970
|
+
* @throws {ExpectError} if the expectations are not met
|
|
971
|
+
* @returns {void} Nothing
|
|
972
|
+
*/
|
|
973
|
+
function checkExpectations(expectations, value) {
|
|
974
|
+
var e_1, _a;
|
|
975
|
+
try {
|
|
976
|
+
for (var _b = __values(Object.entries(expectations)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
977
|
+
var _d = __read(_c.value, 2), unit = _d[0], _e = _d[1], max = _e.max, min = _e.min;
|
|
978
|
+
var amount = CountUtils[unit.toUpperCase()](value);
|
|
979
|
+
if (min && amount < min) {
|
|
980
|
+
throw new ExpectError("Expected at least ".concat(min, " ").concat(unit, " but got ").concat(amount));
|
|
981
|
+
} /* not else */
|
|
982
|
+
if (max && amount > max) {
|
|
983
|
+
throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
988
|
+
finally {
|
|
989
|
+
try {
|
|
990
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
991
|
+
}
|
|
992
|
+
finally { if (e_1) throw e_1.error; }
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* TODO: [💝] Unite object for expecting amount and format
|
|
997
|
+
*/
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* This error occurs during the parameter replacement in the template
|
|
1001
|
+
*
|
|
1002
|
+
* Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
|
|
1003
|
+
*/
|
|
1004
|
+
var TemplateError = /** @class */ (function (_super) {
|
|
1005
|
+
__extends(TemplateError, _super);
|
|
1006
|
+
function TemplateError(message) {
|
|
1007
|
+
var _this = _super.call(this, message) || this;
|
|
1008
|
+
_this.name = 'TemplateError';
|
|
1009
|
+
Object.setPrototypeOf(_this, TemplateError.prototype);
|
|
1010
|
+
return _this;
|
|
1011
|
+
}
|
|
1012
|
+
return TemplateError;
|
|
1013
|
+
}(Error));
|
|
1014
|
+
|
|
1015
|
+
/**
|
|
1016
|
+
* Replaces parameters in template with values from parameters object
|
|
1017
|
+
*
|
|
1018
|
+
* @param template the template with parameters in {curly} braces
|
|
1019
|
+
* @param parameters the object with parameters
|
|
1020
|
+
* @returns the template with replaced parameters
|
|
1021
|
+
* @throws {TemplateError} if parameter is not defined, not closed, or not opened
|
|
1022
|
+
*
|
|
1023
|
+
* @private within the createPromptbookExecutor
|
|
1024
|
+
*/
|
|
1025
|
+
function replaceParameters(template, parameters) {
|
|
1026
|
+
var replacedTemplate = template;
|
|
1027
|
+
var match;
|
|
1028
|
+
var loopLimit = LOOP_LIMIT;
|
|
1029
|
+
var _loop_1 = function () {
|
|
1030
|
+
if (loopLimit-- < 0) {
|
|
1031
|
+
throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
|
|
1032
|
+
}
|
|
1033
|
+
var precol = match.groups.precol;
|
|
1034
|
+
var parameterName = match.groups.parameterName;
|
|
1035
|
+
if (parameterName === '') {
|
|
1036
|
+
return "continue";
|
|
1037
|
+
}
|
|
1038
|
+
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
1039
|
+
throw new TemplateError('Parameter is already opened or not closed');
|
|
1040
|
+
}
|
|
1041
|
+
if (parameters[parameterName] === undefined) {
|
|
1042
|
+
throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
|
|
1043
|
+
}
|
|
1044
|
+
var parameterValue = parameters[parameterName];
|
|
1045
|
+
if (parameterValue === undefined) {
|
|
1046
|
+
throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
|
|
1047
|
+
}
|
|
1048
|
+
parameterValue = parameterValue.toString();
|
|
1049
|
+
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
1050
|
+
parameterValue = parameterValue
|
|
1051
|
+
.split('\n')
|
|
1052
|
+
.map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
|
|
1053
|
+
.join('\n');
|
|
1054
|
+
}
|
|
1055
|
+
replacedTemplate =
|
|
1056
|
+
replacedTemplate.substring(0, match.index + precol.length) +
|
|
1057
|
+
parameterValue +
|
|
1058
|
+
replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
|
|
1059
|
+
};
|
|
1060
|
+
while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
|
|
1061
|
+
.exec(replacedTemplate))) {
|
|
1062
|
+
_loop_1();
|
|
1063
|
+
}
|
|
1064
|
+
// [💫] Check if there are parameters that are not closed properly
|
|
1065
|
+
if (/{\w+$/.test(replacedTemplate)) {
|
|
1066
|
+
throw new TemplateError('Parameter is not closed');
|
|
1067
|
+
}
|
|
1068
|
+
// [💫] Check if there are parameters that are not opened properly
|
|
1069
|
+
if (/^\w+}/.test(replacedTemplate)) {
|
|
1070
|
+
throw new TemplateError('Parameter is not opened');
|
|
1071
|
+
}
|
|
1072
|
+
return replacedTemplate;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
/**
|
|
1076
|
+
* Creates executor function from promptbook and execution tools.
|
|
1077
|
+
*
|
|
1078
|
+
* @returns The executor function
|
|
1079
|
+
* @throws {PromptbookLogicError} on logical error in the promptbook
|
|
1080
|
+
*/
|
|
1081
|
+
function createPromptbookExecutor(options) {
|
|
1082
|
+
var _this = this;
|
|
1083
|
+
var promptbook = options.promptbook, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
1084
|
+
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
|
|
1085
|
+
validatePromptbookJson(promptbook);
|
|
1086
|
+
var promptbookExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
1087
|
+
function executeSingleTemplate(currentTemplate) {
|
|
1088
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1089
|
+
var name, title, priority, prompt, chatThread, completionResult, result, resultString, expectError, scriptExecutionErrors, maxAttempts, jokers, attempt, isJokerAttempt, joker, _a, _b, _c, _d, scriptTools, error_2, e_2_1, _e, _f, functionName, postprocessingError, _g, _h, scriptTools, error_3, e_3_1, e_4_1, error_4;
|
|
1090
|
+
var e_2, _j, e_4, _k, e_3, _l, _m;
|
|
1091
|
+
var _this = this;
|
|
1092
|
+
return __generator(this, function (_o) {
|
|
1093
|
+
switch (_o.label) {
|
|
1094
|
+
case 0:
|
|
1095
|
+
name = "promptbook-executor-frame-".concat(currentTemplate.name);
|
|
1096
|
+
title = currentTemplate.title;
|
|
1097
|
+
priority = promptbook.promptTemplates.length - promptbook.promptTemplates.indexOf(currentTemplate);
|
|
1098
|
+
if (!onProgress /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
|
|
1099
|
+
return [4 /*yield*/, onProgress({
|
|
1100
|
+
name: name,
|
|
1101
|
+
title: title,
|
|
1102
|
+
isStarted: false,
|
|
1103
|
+
isDone: false,
|
|
1104
|
+
executionType: currentTemplate.executionType,
|
|
1105
|
+
parameterName: currentTemplate.resultingParameterName,
|
|
1106
|
+
parameterValue: null,
|
|
1107
|
+
// <- [3]
|
|
1108
|
+
})];
|
|
1109
|
+
case 1:
|
|
1110
|
+
_o.sent();
|
|
1111
|
+
_o.label = 2;
|
|
1112
|
+
case 2:
|
|
1113
|
+
result = null;
|
|
1114
|
+
resultString = null;
|
|
1115
|
+
expectError = null;
|
|
1116
|
+
maxAttempts = currentTemplate.executionType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
|
|
1117
|
+
jokers = currentTemplate.jokers || [];
|
|
1118
|
+
attempt = -jokers.length;
|
|
1119
|
+
_o.label = 3;
|
|
1120
|
+
case 3:
|
|
1121
|
+
if (!(attempt < maxAttempts)) return [3 /*break*/, 49];
|
|
1122
|
+
isJokerAttempt = attempt < 0;
|
|
1123
|
+
joker = jokers[jokers.length + attempt];
|
|
1124
|
+
if (isJokerAttempt && !joker) {
|
|
1125
|
+
throw new UnexpectedError("Joker not found in attempt ".concat(attempt));
|
|
1126
|
+
}
|
|
1127
|
+
result = null;
|
|
1128
|
+
resultString = null;
|
|
1129
|
+
expectError = null;
|
|
1130
|
+
if (isJokerAttempt) {
|
|
1131
|
+
if (typeof parametersToPass[joker] === 'undefined') {
|
|
1132
|
+
throw new PromptbookExecutionError("Joker parameter {".concat(joker, "} not defined"));
|
|
1133
|
+
}
|
|
1134
|
+
resultString = parametersToPass[joker];
|
|
1135
|
+
}
|
|
1136
|
+
_o.label = 4;
|
|
1137
|
+
case 4:
|
|
1138
|
+
_o.trys.push([4, 45, 46, 47]);
|
|
1139
|
+
if (!!isJokerAttempt) return [3 /*break*/, 27];
|
|
1140
|
+
_a = currentTemplate.executionType;
|
|
1141
|
+
switch (_a) {
|
|
1142
|
+
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 5];
|
|
1143
|
+
case 'PROMPT_TEMPLATE': return [3 /*break*/, 6];
|
|
1144
|
+
case 'SCRIPT': return [3 /*break*/, 13];
|
|
1145
|
+
case 'PROMPT_DIALOG': return [3 /*break*/, 24];
|
|
1146
|
+
}
|
|
1147
|
+
return [3 /*break*/, 26];
|
|
1148
|
+
case 5:
|
|
1149
|
+
resultString = replaceParameters(currentTemplate.content, parametersToPass);
|
|
1150
|
+
return [3 /*break*/, 27];
|
|
1151
|
+
case 6:
|
|
1152
|
+
prompt = {
|
|
1153
|
+
title: currentTemplate.title,
|
|
1154
|
+
promptbookUrl: "".concat(promptbook.promptbookUrl
|
|
1155
|
+
? promptbook.promptbookUrl
|
|
1156
|
+
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous PROMPTBOOKs, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
1157
|
+
parameters: parametersToPass,
|
|
1158
|
+
content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
|
|
1159
|
+
modelRequirements: currentTemplate.modelRequirements,
|
|
1160
|
+
expectations: currentTemplate.expectations,
|
|
1161
|
+
expectFormat: currentTemplate.expectFormat,
|
|
1162
|
+
postprocessing: (currentTemplate.postprocessing || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
1163
|
+
var errors, _a, _b, scriptTools, error_5, e_5_1;
|
|
1164
|
+
var e_5, _c;
|
|
1165
|
+
return __generator(this, function (_d) {
|
|
1166
|
+
switch (_d.label) {
|
|
1167
|
+
case 0:
|
|
1168
|
+
errors = [];
|
|
1169
|
+
_d.label = 1;
|
|
1170
|
+
case 1:
|
|
1171
|
+
_d.trys.push([1, 8, 9, 10]);
|
|
1172
|
+
_a = __values(tools.script), _b = _a.next();
|
|
1173
|
+
_d.label = 2;
|
|
1174
|
+
case 2:
|
|
1175
|
+
if (!!_b.done) return [3 /*break*/, 7];
|
|
1176
|
+
scriptTools = _b.value;
|
|
1177
|
+
_d.label = 3;
|
|
1178
|
+
case 3:
|
|
1179
|
+
_d.trys.push([3, 5, , 6]);
|
|
1180
|
+
return [4 /*yield*/, scriptTools.execute({
|
|
1181
|
+
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
1182
|
+
script: "".concat(functionName, "(result)"),
|
|
1183
|
+
parameters: {
|
|
1184
|
+
result: result || '',
|
|
1185
|
+
// Note: No ...parametersToPass, because working with result only
|
|
1186
|
+
},
|
|
1187
|
+
})];
|
|
1188
|
+
case 4: return [2 /*return*/, _d.sent()];
|
|
1189
|
+
case 5:
|
|
1190
|
+
error_5 = _d.sent();
|
|
1191
|
+
if (!(error_5 instanceof Error)) {
|
|
1192
|
+
throw error_5;
|
|
1193
|
+
}
|
|
1194
|
+
errors.push(error_5);
|
|
1195
|
+
return [3 /*break*/, 6];
|
|
1196
|
+
case 6:
|
|
1197
|
+
_b = _a.next();
|
|
1198
|
+
return [3 /*break*/, 2];
|
|
1199
|
+
case 7: return [3 /*break*/, 10];
|
|
1200
|
+
case 8:
|
|
1201
|
+
e_5_1 = _d.sent();
|
|
1202
|
+
e_5 = { error: e_5_1 };
|
|
1203
|
+
return [3 /*break*/, 10];
|
|
1204
|
+
case 9:
|
|
1205
|
+
try {
|
|
1206
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1207
|
+
}
|
|
1208
|
+
finally { if (e_5) throw e_5.error; }
|
|
1209
|
+
return [7 /*endfinally*/];
|
|
1210
|
+
case 10:
|
|
1211
|
+
if (errors.length === 0) {
|
|
1212
|
+
throw new PromptbookExecutionError('Postprocessing in LlmExecutionTools failed because no ScriptExecutionTools were provided');
|
|
1213
|
+
}
|
|
1214
|
+
else if (errors.length === 1) {
|
|
1215
|
+
throw errors[0];
|
|
1216
|
+
}
|
|
1217
|
+
else {
|
|
1218
|
+
throw new PromptbookExecutionError(spaceTrim(function (block) { return "\n Postprocessing in LlmExecutionTools failed ".concat(errors.length, "x\n\n ").concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n\n')), "\n "); }));
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
});
|
|
1222
|
+
}); }; }),
|
|
1223
|
+
};
|
|
1224
|
+
_b = currentTemplate.modelRequirements.modelVariant;
|
|
1225
|
+
switch (_b) {
|
|
1226
|
+
case 'CHAT': return [3 /*break*/, 7];
|
|
1227
|
+
case 'COMPLETION': return [3 /*break*/, 9];
|
|
1228
|
+
}
|
|
1229
|
+
return [3 /*break*/, 11];
|
|
1230
|
+
case 7: return [4 /*yield*/, tools.llm.gptChat(prompt)];
|
|
1231
|
+
case 8:
|
|
1232
|
+
chatThread = _o.sent();
|
|
1233
|
+
// TODO: [🍬] Destroy chatThread
|
|
1234
|
+
result = chatThread;
|
|
1235
|
+
resultString = chatThread.content;
|
|
1236
|
+
return [3 /*break*/, 12];
|
|
1237
|
+
case 9: return [4 /*yield*/, tools.llm.gptComplete(prompt)];
|
|
1238
|
+
case 10:
|
|
1239
|
+
completionResult = _o.sent();
|
|
1240
|
+
result = completionResult;
|
|
1241
|
+
resultString = completionResult.content;
|
|
1242
|
+
return [3 /*break*/, 12];
|
|
1243
|
+
case 11: throw new PromptbookExecutionError("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
|
|
1244
|
+
case 12: return [3 /*break*/, 27];
|
|
1245
|
+
case 13:
|
|
1246
|
+
if (tools.script.length === 0) {
|
|
1247
|
+
throw new PromptbookExecutionError('No script execution tools are available');
|
|
1248
|
+
}
|
|
1249
|
+
if (!currentTemplate.contentLanguage) {
|
|
1250
|
+
throw new PromptbookExecutionError("Script language is not defined for prompt template \"".concat(currentTemplate.name, "\""));
|
|
1251
|
+
}
|
|
1252
|
+
// TODO: DRY [1]
|
|
1253
|
+
scriptExecutionErrors = [];
|
|
1254
|
+
_o.label = 14;
|
|
1255
|
+
case 14:
|
|
1256
|
+
_o.trys.push([14, 21, 22, 23]);
|
|
1257
|
+
_c = (e_2 = void 0, __values(tools.script)), _d = _c.next();
|
|
1258
|
+
_o.label = 15;
|
|
1259
|
+
case 15:
|
|
1260
|
+
if (!!_d.done) return [3 /*break*/, 20];
|
|
1261
|
+
scriptTools = _d.value;
|
|
1262
|
+
_o.label = 16;
|
|
1263
|
+
case 16:
|
|
1264
|
+
_o.trys.push([16, 18, , 19]);
|
|
1265
|
+
return [4 /*yield*/, scriptTools.execute({
|
|
1266
|
+
scriptLanguage: currentTemplate.contentLanguage,
|
|
1267
|
+
script: currentTemplate.content,
|
|
1268
|
+
parameters: parametersToPass,
|
|
1269
|
+
})];
|
|
1270
|
+
case 17:
|
|
1271
|
+
resultString = _o.sent();
|
|
1272
|
+
return [3 /*break*/, 20];
|
|
1273
|
+
case 18:
|
|
1274
|
+
error_2 = _o.sent();
|
|
1275
|
+
if (!(error_2 instanceof Error)) {
|
|
1276
|
+
throw error_2;
|
|
1277
|
+
}
|
|
1278
|
+
scriptExecutionErrors.push(error_2);
|
|
1279
|
+
return [3 /*break*/, 19];
|
|
1280
|
+
case 19:
|
|
1281
|
+
_d = _c.next();
|
|
1282
|
+
return [3 /*break*/, 15];
|
|
1283
|
+
case 20: return [3 /*break*/, 23];
|
|
1284
|
+
case 21:
|
|
1285
|
+
e_2_1 = _o.sent();
|
|
1286
|
+
e_2 = { error: e_2_1 };
|
|
1287
|
+
return [3 /*break*/, 23];
|
|
1288
|
+
case 22:
|
|
1289
|
+
try {
|
|
1290
|
+
if (_d && !_d.done && (_j = _c.return)) _j.call(_c);
|
|
1291
|
+
}
|
|
1292
|
+
finally { if (e_2) throw e_2.error; }
|
|
1293
|
+
return [7 /*endfinally*/];
|
|
1294
|
+
case 23:
|
|
1295
|
+
if (resultString !== null) {
|
|
1296
|
+
return [3 /*break*/, 27];
|
|
1297
|
+
}
|
|
1298
|
+
if (scriptExecutionErrors.length === 1) {
|
|
1299
|
+
throw scriptExecutionErrors[0];
|
|
1300
|
+
}
|
|
1301
|
+
else {
|
|
1302
|
+
throw new PromptbookExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
|
|
1303
|
+
.map(function (error) { return '- ' + error.message; })
|
|
1304
|
+
.join('\n\n')), "\n "); }));
|
|
1305
|
+
}
|
|
1306
|
+
case 24:
|
|
1307
|
+
if (tools.userInterface === undefined) {
|
|
1308
|
+
throw new PromptbookExecutionError('User interface tools are not available');
|
|
1309
|
+
}
|
|
1310
|
+
return [4 /*yield*/, tools.userInterface.promptDialog({
|
|
1311
|
+
promptTitle: currentTemplate.title,
|
|
1312
|
+
promptMessage: replaceParameters(currentTemplate.description || '', parametersToPass),
|
|
1313
|
+
defaultValue: replaceParameters(currentTemplate.content, parametersToPass),
|
|
1314
|
+
// TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
|
|
1315
|
+
placeholder: undefined,
|
|
1316
|
+
priority: priority,
|
|
1317
|
+
})];
|
|
1318
|
+
case 25:
|
|
1319
|
+
// TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
|
|
1320
|
+
resultString = _o.sent();
|
|
1321
|
+
return [3 /*break*/, 27];
|
|
1322
|
+
case 26: throw new PromptbookExecutionError(
|
|
1323
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1324
|
+
"Unknown execution type \"".concat(currentTemplate.executionType, "\""));
|
|
1325
|
+
case 27:
|
|
1326
|
+
if (!(!isJokerAttempt && currentTemplate.postprocessing)) return [3 /*break*/, 44];
|
|
1327
|
+
_o.label = 28;
|
|
1328
|
+
case 28:
|
|
1329
|
+
_o.trys.push([28, 42, 43, 44]);
|
|
1330
|
+
_e = (e_4 = void 0, __values(currentTemplate.postprocessing)), _f = _e.next();
|
|
1331
|
+
_o.label = 29;
|
|
1332
|
+
case 29:
|
|
1333
|
+
if (!!_f.done) return [3 /*break*/, 41];
|
|
1334
|
+
functionName = _f.value;
|
|
1335
|
+
// TODO: DRY [1]
|
|
1336
|
+
scriptExecutionErrors = [];
|
|
1337
|
+
postprocessingError = null;
|
|
1338
|
+
_o.label = 30;
|
|
1339
|
+
case 30:
|
|
1340
|
+
_o.trys.push([30, 37, 38, 39]);
|
|
1341
|
+
_g = (e_3 = void 0, __values(tools.script)), _h = _g.next();
|
|
1342
|
+
_o.label = 31;
|
|
1343
|
+
case 31:
|
|
1344
|
+
if (!!_h.done) return [3 /*break*/, 36];
|
|
1345
|
+
scriptTools = _h.value;
|
|
1346
|
+
_o.label = 32;
|
|
1347
|
+
case 32:
|
|
1348
|
+
_o.trys.push([32, 34, , 35]);
|
|
1349
|
+
return [4 /*yield*/, scriptTools.execute({
|
|
1350
|
+
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
1351
|
+
script: "".concat(functionName, "(resultString)"),
|
|
1352
|
+
parameters: {
|
|
1353
|
+
resultString: resultString || '',
|
|
1354
|
+
// Note: No ...parametersToPass, because working with result only
|
|
1355
|
+
},
|
|
1356
|
+
})];
|
|
1357
|
+
case 33:
|
|
1358
|
+
resultString = _o.sent();
|
|
1359
|
+
postprocessingError = null;
|
|
1360
|
+
return [3 /*break*/, 36];
|
|
1361
|
+
case 34:
|
|
1362
|
+
error_3 = _o.sent();
|
|
1363
|
+
if (!(error_3 instanceof Error)) {
|
|
1364
|
+
throw error_3;
|
|
1365
|
+
}
|
|
1366
|
+
postprocessingError = error_3;
|
|
1367
|
+
scriptExecutionErrors.push(error_3);
|
|
1368
|
+
return [3 /*break*/, 35];
|
|
1369
|
+
case 35:
|
|
1370
|
+
_h = _g.next();
|
|
1371
|
+
return [3 /*break*/, 31];
|
|
1372
|
+
case 36: return [3 /*break*/, 39];
|
|
1373
|
+
case 37:
|
|
1374
|
+
e_3_1 = _o.sent();
|
|
1375
|
+
e_3 = { error: e_3_1 };
|
|
1376
|
+
return [3 /*break*/, 39];
|
|
1377
|
+
case 38:
|
|
1378
|
+
try {
|
|
1379
|
+
if (_h && !_h.done && (_l = _g.return)) _l.call(_g);
|
|
1380
|
+
}
|
|
1381
|
+
finally { if (e_3) throw e_3.error; }
|
|
1382
|
+
return [7 /*endfinally*/];
|
|
1383
|
+
case 39:
|
|
1384
|
+
if (postprocessingError) {
|
|
1385
|
+
throw postprocessingError;
|
|
1386
|
+
}
|
|
1387
|
+
_o.label = 40;
|
|
1388
|
+
case 40:
|
|
1389
|
+
_f = _e.next();
|
|
1390
|
+
return [3 /*break*/, 29];
|
|
1391
|
+
case 41: return [3 /*break*/, 44];
|
|
1392
|
+
case 42:
|
|
1393
|
+
e_4_1 = _o.sent();
|
|
1394
|
+
e_4 = { error: e_4_1 };
|
|
1395
|
+
return [3 /*break*/, 44];
|
|
1396
|
+
case 43:
|
|
1397
|
+
try {
|
|
1398
|
+
if (_f && !_f.done && (_k = _e.return)) _k.call(_e);
|
|
1399
|
+
}
|
|
1400
|
+
finally { if (e_4) throw e_4.error; }
|
|
1401
|
+
return [7 /*endfinally*/];
|
|
1402
|
+
case 44:
|
|
1403
|
+
// TODO: [💝] Unite object for expecting amount and format
|
|
1404
|
+
if (currentTemplate.expectFormat) {
|
|
1405
|
+
if (currentTemplate.expectFormat === 'JSON') {
|
|
1406
|
+
if (!isValidJsonString(resultString || '')) {
|
|
1407
|
+
throw new ExpectError('Expected valid JSON string');
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
// TODO: [💝] Unite object for expecting amount and format
|
|
1412
|
+
if (currentTemplate.expectations) {
|
|
1413
|
+
checkExpectations(currentTemplate.expectations, resultString || '');
|
|
1414
|
+
}
|
|
1415
|
+
return [3 /*break*/, 49];
|
|
1416
|
+
case 45:
|
|
1417
|
+
error_4 = _o.sent();
|
|
1418
|
+
if (!(error_4 instanceof ExpectError)) {
|
|
1419
|
+
throw error_4;
|
|
1420
|
+
}
|
|
1421
|
+
expectError = error_4;
|
|
1422
|
+
return [3 /*break*/, 47];
|
|
1423
|
+
case 46:
|
|
1424
|
+
if (!isJokerAttempt &&
|
|
1425
|
+
currentTemplate.executionType === 'PROMPT_TEMPLATE' &&
|
|
1426
|
+
prompt
|
|
1427
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
|
|
1428
|
+
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
1429
|
+
) {
|
|
1430
|
+
// TODO: [🧠] Maybe put other executionTypes into report
|
|
1431
|
+
executionReport.promptExecutions.push({
|
|
1432
|
+
prompt: {
|
|
1433
|
+
title: currentTemplate.title /* <- Note: If title in promptbook contains emojis, pass it innto report */,
|
|
1434
|
+
content: prompt.content,
|
|
1435
|
+
modelRequirements: prompt.modelRequirements,
|
|
1436
|
+
expectations: prompt.expectations,
|
|
1437
|
+
expectFormat: prompt.expectFormat,
|
|
1438
|
+
// <- Note: Do want to pass ONLY wanted information to the report
|
|
1439
|
+
},
|
|
1440
|
+
result: result || undefined,
|
|
1441
|
+
error: expectError || undefined,
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
return [7 /*endfinally*/];
|
|
1445
|
+
case 47:
|
|
1446
|
+
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
1447
|
+
throw new PromptbookExecutionError(spaceTrim(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
|
|
1448
|
+
}
|
|
1449
|
+
_o.label = 48;
|
|
1450
|
+
case 48:
|
|
1451
|
+
attempt++;
|
|
1452
|
+
return [3 /*break*/, 3];
|
|
1453
|
+
case 49:
|
|
1454
|
+
if (resultString === null) {
|
|
1455
|
+
throw new UnexpectedError('Something went wrong and prompt result is null');
|
|
1456
|
+
}
|
|
1457
|
+
if (onProgress /* <- [3] */) {
|
|
1458
|
+
onProgress({
|
|
1459
|
+
name: name,
|
|
1460
|
+
title: title,
|
|
1461
|
+
isStarted: true,
|
|
1462
|
+
isDone: true,
|
|
1463
|
+
executionType: currentTemplate.executionType,
|
|
1464
|
+
parameterName: currentTemplate.resultingParameterName,
|
|
1465
|
+
parameterValue: resultString,
|
|
1466
|
+
// <- [3]
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
parametersToPass = __assign(__assign({}, parametersToPass), (_m = {}, _m[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because Promptbook checks logic consistency during construction */, _m));
|
|
1470
|
+
return [2 /*return*/];
|
|
1471
|
+
}
|
|
1472
|
+
});
|
|
1473
|
+
});
|
|
772
1474
|
}
|
|
773
|
-
|
|
1475
|
+
var parametersToPass, executionReport, resovedParameters_1, unresovedTemplates, resolving_1, loopLimit, _loop_1, error_1, usage_1, _a, _b, parameter, usage;
|
|
1476
|
+
var e_1, _c;
|
|
1477
|
+
return __generator(this, function (_d) {
|
|
1478
|
+
switch (_d.label) {
|
|
1479
|
+
case 0:
|
|
1480
|
+
parametersToPass = inputParameters;
|
|
1481
|
+
executionReport = {
|
|
1482
|
+
promptbookUrl: promptbook.promptbookUrl,
|
|
1483
|
+
title: promptbook.title,
|
|
1484
|
+
promptbookUsedVersion: PROMPTBOOK_VERSION,
|
|
1485
|
+
promptbookRequestedVersion: promptbook.promptbookVersion,
|
|
1486
|
+
description: promptbook.description,
|
|
1487
|
+
promptExecutions: [],
|
|
1488
|
+
};
|
|
1489
|
+
_d.label = 1;
|
|
1490
|
+
case 1:
|
|
1491
|
+
_d.trys.push([1, 6, , 7]);
|
|
1492
|
+
resovedParameters_1 = promptbook.parameters
|
|
1493
|
+
.filter(function (_a) {
|
|
1494
|
+
var isInput = _a.isInput;
|
|
1495
|
+
return isInput;
|
|
1496
|
+
})
|
|
1497
|
+
.map(function (_a) {
|
|
1498
|
+
var name = _a.name;
|
|
1499
|
+
return name;
|
|
1500
|
+
});
|
|
1501
|
+
unresovedTemplates = __spreadArray([], __read(promptbook.promptTemplates), false);
|
|
1502
|
+
resolving_1 = [];
|
|
1503
|
+
loopLimit = LOOP_LIMIT;
|
|
1504
|
+
_loop_1 = function () {
|
|
1505
|
+
var currentTemplate, work_1;
|
|
1506
|
+
return __generator(this, function (_e) {
|
|
1507
|
+
switch (_e.label) {
|
|
1508
|
+
case 0:
|
|
1509
|
+
if (loopLimit-- < 0) {
|
|
1510
|
+
throw new UnexpectedError('Loop limit reached during resolving parameters promptbook execution');
|
|
1511
|
+
}
|
|
1512
|
+
currentTemplate = unresovedTemplates.find(function (template) {
|
|
1513
|
+
return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
|
|
1514
|
+
});
|
|
1515
|
+
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
1516
|
+
throw new UnexpectedError(spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePromptbookJson\n "));
|
|
1517
|
+
case 1:
|
|
1518
|
+
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
1519
|
+
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
1520
|
+
case 2:
|
|
1521
|
+
/* [5] */ _e.sent();
|
|
1522
|
+
return [3 /*break*/, 4];
|
|
1523
|
+
case 3:
|
|
1524
|
+
unresovedTemplates = unresovedTemplates.filter(function (template) { return template !== currentTemplate; });
|
|
1525
|
+
work_1 = executeSingleTemplate(currentTemplate)
|
|
1526
|
+
.then(function () {
|
|
1527
|
+
resovedParameters_1 = __spreadArray(__spreadArray([], __read(resovedParameters_1), false), [currentTemplate.resultingParameterName], false);
|
|
1528
|
+
})
|
|
1529
|
+
.then(function () {
|
|
1530
|
+
resolving_1 = resolving_1.filter(function (w) { return w !== work_1; });
|
|
1531
|
+
});
|
|
1532
|
+
resolving_1.push(work_1);
|
|
1533
|
+
_e.label = 4;
|
|
1534
|
+
case 4: return [2 /*return*/];
|
|
1535
|
+
}
|
|
1536
|
+
});
|
|
1537
|
+
};
|
|
1538
|
+
_d.label = 2;
|
|
1539
|
+
case 2:
|
|
1540
|
+
if (!(unresovedTemplates.length > 0)) return [3 /*break*/, 4];
|
|
1541
|
+
return [5 /*yield**/, _loop_1()];
|
|
1542
|
+
case 3:
|
|
1543
|
+
_d.sent();
|
|
1544
|
+
return [3 /*break*/, 2];
|
|
1545
|
+
case 4: return [4 /*yield*/, Promise.all(resolving_1)];
|
|
1546
|
+
case 5:
|
|
1547
|
+
_d.sent();
|
|
1548
|
+
return [3 /*break*/, 7];
|
|
1549
|
+
case 6:
|
|
1550
|
+
error_1 = _d.sent();
|
|
1551
|
+
if (!(error_1 instanceof Error)) {
|
|
1552
|
+
throw error_1;
|
|
1553
|
+
}
|
|
1554
|
+
usage_1 = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
1555
|
+
var result = _a.result;
|
|
1556
|
+
return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
|
|
1557
|
+
})), false));
|
|
1558
|
+
return [2 /*return*/, {
|
|
1559
|
+
isSuccessful: false,
|
|
1560
|
+
errors: [error_1],
|
|
1561
|
+
usage: usage_1,
|
|
1562
|
+
executionReport: executionReport,
|
|
1563
|
+
outputParameters: parametersToPass,
|
|
1564
|
+
}];
|
|
1565
|
+
case 7:
|
|
1566
|
+
try {
|
|
1567
|
+
// Note: Filter ONLY output parameters
|
|
1568
|
+
for (_a = __values(promptbook.parameters), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1569
|
+
parameter = _b.value;
|
|
1570
|
+
if (parameter.isOutput) {
|
|
1571
|
+
continue;
|
|
1572
|
+
}
|
|
1573
|
+
delete parametersToPass[parameter.name];
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1577
|
+
finally {
|
|
1578
|
+
try {
|
|
1579
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1580
|
+
}
|
|
1581
|
+
finally { if (e_1) throw e_1.error; }
|
|
1582
|
+
}
|
|
1583
|
+
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
1584
|
+
var result = _a.result;
|
|
1585
|
+
return (result === null || result === void 0 ? void 0 : result.usage) || addUsage();
|
|
1586
|
+
})), false));
|
|
1587
|
+
return [2 /*return*/, {
|
|
1588
|
+
isSuccessful: true,
|
|
1589
|
+
errors: [],
|
|
1590
|
+
usage: usage,
|
|
1591
|
+
executionReport: executionReport,
|
|
1592
|
+
outputParameters: parametersToPass,
|
|
1593
|
+
}];
|
|
1594
|
+
}
|
|
1595
|
+
});
|
|
1596
|
+
}); };
|
|
1597
|
+
return promptbookExecutor;
|
|
1598
|
+
}
|
|
1599
|
+
/**
|
|
1600
|
+
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
1601
|
+
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
1602
|
+
* Note: CreatePromptbookExecutorOptions are just connected to PromptbookExecutor so do not extract to types folder
|
|
1603
|
+
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
1604
|
+
*/
|
|
1605
|
+
|
|
1606
|
+
/**
|
|
1607
|
+
* Makes first letter of a string uppercase
|
|
1608
|
+
*
|
|
1609
|
+
*/
|
|
1610
|
+
function capitalize(word) {
|
|
1611
|
+
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
/**
|
|
1615
|
+
* Converts promptbook in JSON format to string format
|
|
1616
|
+
*
|
|
1617
|
+
* @param promptbookJson Promptbook in JSON format (.ptbk.json)
|
|
1618
|
+
* @returns Promptbook in string format (.ptbk.md)
|
|
1619
|
+
*/
|
|
1620
|
+
function promptbookJsonToString(promptbookJson) {
|
|
1621
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
1622
|
+
var title = promptbookJson.title, promptbookUrl = promptbookJson.promptbookUrl, promptbookVersion = promptbookJson.promptbookVersion, description = promptbookJson.description, parameters = promptbookJson.parameters, promptTemplates = promptbookJson.promptTemplates;
|
|
1623
|
+
var promptbookString = "# ".concat(title);
|
|
1624
|
+
if (description) {
|
|
1625
|
+
promptbookString += '\n\n';
|
|
1626
|
+
promptbookString += description;
|
|
774
1627
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
if (
|
|
778
|
-
|
|
1628
|
+
// TODO:> const commands: Array<Command>
|
|
1629
|
+
var commands = [];
|
|
1630
|
+
if (promptbookUrl) {
|
|
1631
|
+
commands.push("PROMPTBOOK URL ".concat(promptbookUrl));
|
|
779
1632
|
}
|
|
780
|
-
|
|
781
|
-
|
|
1633
|
+
commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
|
|
1634
|
+
promptbookString = prettifyMarkdown(promptbookString);
|
|
1635
|
+
try {
|
|
1636
|
+
for (var _g = __values(parameters.filter(function (_a) {
|
|
1637
|
+
var isInput = _a.isInput;
|
|
1638
|
+
return isInput;
|
|
1639
|
+
})), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
1640
|
+
var parameter = _h.value;
|
|
1641
|
+
commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
1642
|
+
}
|
|
782
1643
|
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
if (denominator === 0) {
|
|
788
|
-
throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
1644
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1645
|
+
finally {
|
|
1646
|
+
try {
|
|
1647
|
+
if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
|
|
789
1648
|
}
|
|
790
|
-
|
|
1649
|
+
finally { if (e_1) throw e_1.error; }
|
|
791
1650
|
}
|
|
792
|
-
|
|
793
|
-
|
|
1651
|
+
try {
|
|
1652
|
+
for (var _j = __values(parameters.filter(function (_a) {
|
|
1653
|
+
var isOutput = _a.isOutput;
|
|
1654
|
+
return isOutput;
|
|
1655
|
+
})), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
1656
|
+
var parameter = _k.value;
|
|
1657
|
+
commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
1658
|
+
}
|
|
794
1659
|
}
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
1660
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1661
|
+
finally {
|
|
1662
|
+
try {
|
|
1663
|
+
if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
|
|
1664
|
+
}
|
|
1665
|
+
finally { if (e_2) throw e_2.error; }
|
|
798
1666
|
}
|
|
799
|
-
|
|
800
|
-
|
|
1667
|
+
promptbookString += '\n\n';
|
|
1668
|
+
promptbookString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
1669
|
+
try {
|
|
1670
|
+
for (var promptTemplates_1 = __values(promptTemplates), promptTemplates_1_1 = promptTemplates_1.next(); !promptTemplates_1_1.done; promptTemplates_1_1 = promptTemplates_1.next()) {
|
|
1671
|
+
var promptTemplate = promptTemplates_1_1.value;
|
|
1672
|
+
var
|
|
1673
|
+
/* Note: Not using:> name, */
|
|
1674
|
+
title_1 = promptTemplate.title, description_1 = promptTemplate.description,
|
|
1675
|
+
/* Note: dependentParameterNames, */
|
|
1676
|
+
jokers = promptTemplate.jokers, executionType = promptTemplate.executionType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessing, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
|
|
1677
|
+
promptbookString += '\n\n';
|
|
1678
|
+
promptbookString += "## ".concat(title_1);
|
|
1679
|
+
if (description_1) {
|
|
1680
|
+
promptbookString += '\n\n';
|
|
1681
|
+
promptbookString += description_1;
|
|
1682
|
+
}
|
|
1683
|
+
// TODO:> const commands: Array<Command>
|
|
1684
|
+
var commands_1 = [];
|
|
1685
|
+
var contentLanguage = 'text';
|
|
1686
|
+
if (executionType === 'PROMPT_TEMPLATE') {
|
|
1687
|
+
var modelRequirements = promptTemplate.modelRequirements;
|
|
1688
|
+
var modelName = modelRequirements.modelName, modelVariant = modelRequirements.modelVariant;
|
|
1689
|
+
commands_1.push("EXECUTE PROMPT TEMPLATE");
|
|
1690
|
+
if (modelVariant) {
|
|
1691
|
+
commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
|
|
1692
|
+
}
|
|
1693
|
+
if (modelName) {
|
|
1694
|
+
commands_1.push("MODEL NAME `".concat(modelName, "`"));
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
else if (executionType === 'SIMPLE_TEMPLATE') {
|
|
1698
|
+
commands_1.push("SIMPLE TEMPLATE");
|
|
1699
|
+
// Note: Nothing special here
|
|
1700
|
+
}
|
|
1701
|
+
else if (executionType === 'SCRIPT') {
|
|
1702
|
+
commands_1.push("EXECUTE SCRIPT");
|
|
1703
|
+
if (promptTemplate.contentLanguage) {
|
|
1704
|
+
contentLanguage = promptTemplate.contentLanguage;
|
|
1705
|
+
}
|
|
1706
|
+
else {
|
|
1707
|
+
contentLanguage = '';
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
else if (executionType === 'PROMPT_DIALOG') {
|
|
1711
|
+
commands_1.push("PROMPT DIALOG");
|
|
1712
|
+
// Note: Nothing special here
|
|
1713
|
+
}
|
|
1714
|
+
if (jokers) {
|
|
1715
|
+
try {
|
|
1716
|
+
for (var jokers_1 = (e_4 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
|
|
1717
|
+
var joker = jokers_1_1.value;
|
|
1718
|
+
commands_1.push("JOKER {".concat(joker, "}"));
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1722
|
+
finally {
|
|
1723
|
+
try {
|
|
1724
|
+
if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
|
|
1725
|
+
}
|
|
1726
|
+
finally { if (e_4) throw e_4.error; }
|
|
1727
|
+
}
|
|
1728
|
+
} /* not else */
|
|
1729
|
+
if (postprocessing) {
|
|
1730
|
+
try {
|
|
1731
|
+
for (var postprocessing_1 = (e_5 = void 0, __values(postprocessing)), postprocessing_1_1 = postprocessing_1.next(); !postprocessing_1_1.done; postprocessing_1_1 = postprocessing_1.next()) {
|
|
1732
|
+
var postprocessingFunctionName = postprocessing_1_1.value;
|
|
1733
|
+
commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1737
|
+
finally {
|
|
1738
|
+
try {
|
|
1739
|
+
if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
|
|
1740
|
+
}
|
|
1741
|
+
finally { if (e_5) throw e_5.error; }
|
|
1742
|
+
}
|
|
1743
|
+
} /* not else */
|
|
1744
|
+
if (expectations) {
|
|
1745
|
+
try {
|
|
1746
|
+
for (var _l = (e_6 = void 0, __values(Object.entries(expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
1747
|
+
var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
|
|
1748
|
+
if (min === max) {
|
|
1749
|
+
commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
1750
|
+
}
|
|
1751
|
+
else {
|
|
1752
|
+
if (min !== undefined) {
|
|
1753
|
+
commands_1.push("EXPECT MIN ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
1754
|
+
} /* not else */
|
|
1755
|
+
if (max !== undefined) {
|
|
1756
|
+
commands_1.push("EXPECT MAX ".concat(max, " ").concat(capitalize(unit + (max > 1 ? 's' : ''))));
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1762
|
+
finally {
|
|
1763
|
+
try {
|
|
1764
|
+
if (_m && !_m.done && (_f = _l.return)) _f.call(_l);
|
|
1765
|
+
}
|
|
1766
|
+
finally { if (e_6) throw e_6.error; }
|
|
1767
|
+
}
|
|
1768
|
+
} /* not else */
|
|
1769
|
+
if (expectFormat) {
|
|
1770
|
+
if (expectFormat === 'JSON') {
|
|
1771
|
+
// TODO: @deprecated remove
|
|
1772
|
+
commands_1.push("EXPECT JSON");
|
|
1773
|
+
}
|
|
1774
|
+
} /* not else */
|
|
1775
|
+
promptbookString += '\n\n';
|
|
1776
|
+
promptbookString += commands_1.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
1777
|
+
promptbookString += '\n\n';
|
|
1778
|
+
promptbookString += '```' + contentLanguage;
|
|
1779
|
+
promptbookString += '\n';
|
|
1780
|
+
promptbookString += spaceTrim$1(content);
|
|
1781
|
+
// <- TODO: !!! Escape
|
|
1782
|
+
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
1783
|
+
promptbookString += '\n';
|
|
1784
|
+
promptbookString += '```';
|
|
1785
|
+
promptbookString += '\n\n';
|
|
1786
|
+
promptbookString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
|
|
1787
|
+
}
|
|
801
1788
|
}
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
1789
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1790
|
+
finally {
|
|
1791
|
+
try {
|
|
1792
|
+
if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
|
|
1793
|
+
}
|
|
1794
|
+
finally { if (e_3) throw e_3.error; }
|
|
805
1795
|
}
|
|
806
|
-
return
|
|
1796
|
+
return promptbookString;
|
|
807
1797
|
}
|
|
808
1798
|
/**
|
|
809
|
-
*
|
|
1799
|
+
* @private internal util of promptbookJsonToString
|
|
1800
|
+
*/
|
|
1801
|
+
function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
1802
|
+
var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
|
|
1803
|
+
var parameterString = "{".concat(name, "}");
|
|
1804
|
+
if (description) {
|
|
1805
|
+
parameterString = "".concat(parameterString, " ").concat(description);
|
|
1806
|
+
}
|
|
1807
|
+
return parameterString;
|
|
1808
|
+
}
|
|
1809
|
+
/**
|
|
1810
|
+
* TODO: Escape all
|
|
810
1811
|
*/
|
|
811
1812
|
|
|
812
1813
|
/**
|
|
813
|
-
*
|
|
814
|
-
*
|
|
815
|
-
* @returns parsed command object
|
|
816
|
-
* @throws {PromptbookSyntaxError} if the command is invalid
|
|
817
|
-
*
|
|
818
|
-
* @private within the promptbookStringToJson
|
|
1814
|
+
* This error indicates that promptbook not found in the library
|
|
819
1815
|
*/
|
|
820
|
-
function
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
1816
|
+
var PromptbookNotFoundError = /** @class */ (function (_super) {
|
|
1817
|
+
__extends(PromptbookNotFoundError, _super);
|
|
1818
|
+
function PromptbookNotFoundError(message) {
|
|
1819
|
+
var _this = _super.call(this, message) || this;
|
|
1820
|
+
_this.name = 'PromptbookNotFoundError';
|
|
1821
|
+
Object.setPrototypeOf(_this, PromptbookNotFoundError.prototype);
|
|
1822
|
+
return _this;
|
|
824
1823
|
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
1824
|
+
return PromptbookNotFoundError;
|
|
1825
|
+
}(Error));
|
|
1826
|
+
|
|
1827
|
+
/**
|
|
1828
|
+
* This error indicates errors in referencing promptbooks between each other
|
|
1829
|
+
*/
|
|
1830
|
+
var PromptbookReferenceError = /** @class */ (function (_super) {
|
|
1831
|
+
__extends(PromptbookReferenceError, _super);
|
|
1832
|
+
function PromptbookReferenceError(message) {
|
|
1833
|
+
var _this = _super.call(this, message) || this;
|
|
1834
|
+
_this.name = 'PromptbookReferenceError';
|
|
1835
|
+
Object.setPrototypeOf(_this, PromptbookReferenceError.prototype);
|
|
1836
|
+
return _this;
|
|
1837
|
+
}
|
|
1838
|
+
return PromptbookReferenceError;
|
|
1839
|
+
}(Error));
|
|
1840
|
+
|
|
1841
|
+
/**
|
|
1842
|
+
* Library of promptbooks that groups together promptbooks for an application.
|
|
1843
|
+
* This implementation is a very thin wrapper around the Array / Map of promptbooks.
|
|
1844
|
+
*
|
|
1845
|
+
* @see https://github.com/webgptorg/promptbook#promptbook-library
|
|
1846
|
+
*/
|
|
1847
|
+
var SimplePromptbookLibrary = /** @class */ (function () {
|
|
1848
|
+
/**
|
|
1849
|
+
* Constructs a promptbook library from promptbooks
|
|
1850
|
+
*
|
|
1851
|
+
* @param promptbooks !!!
|
|
1852
|
+
*
|
|
1853
|
+
* Note: During the construction logic of all promptbooks are validated
|
|
1854
|
+
* Note: It is not recommended to use this constructor directly, use `createPromptbookLibraryFromSources` *(or other variant)* instead
|
|
1855
|
+
*/
|
|
1856
|
+
function SimplePromptbookLibrary() {
|
|
1857
|
+
var e_1, _a;
|
|
1858
|
+
var promptbooks = [];
|
|
1859
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1860
|
+
promptbooks[_i] = arguments[_i];
|
|
856
1861
|
}
|
|
857
|
-
|
|
858
|
-
|
|
1862
|
+
this.library = new Map();
|
|
1863
|
+
try {
|
|
1864
|
+
for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
|
|
1865
|
+
var promptbook = promptbooks_1_1.value;
|
|
1866
|
+
if (promptbook.promptbookUrl === undefined) {
|
|
1867
|
+
throw new PromptbookReferenceError(spaceTrim("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the promptbook library\n\n ")));
|
|
1868
|
+
}
|
|
1869
|
+
validatePromptbookJson(promptbook);
|
|
1870
|
+
// Note: [🦄]
|
|
1871
|
+
if (this.library.has(promptbook.promptbookUrl) &&
|
|
1872
|
+
promptbookJsonToString(promptbook) !==
|
|
1873
|
+
promptbookJsonToString(this.library.get(promptbook.promptbookUrl))) {
|
|
1874
|
+
throw new PromptbookReferenceError(spaceTrim("\n Promptbook with URL \"".concat(promptbook.promptbookUrl, "\" is already in the library\n\n Note: Promptbooks with the same URL are not allowed\n Note: Automatically check whether the promptbooks are the same BUT they are DIFFERENT\n\n ")));
|
|
1875
|
+
}
|
|
1876
|
+
this.library.set(promptbook.promptbookUrl, promptbook);
|
|
1877
|
+
}
|
|
859
1878
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
if (listItemParts.length !== 2) {
|
|
867
|
-
throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
|
|
1879
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1880
|
+
finally {
|
|
1881
|
+
try {
|
|
1882
|
+
if (promptbooks_1_1 && !promptbooks_1_1.done && (_a = promptbooks_1.return)) _a.call(promptbooks_1);
|
|
1883
|
+
}
|
|
1884
|
+
finally { if (e_1) throw e_1.error; }
|
|
868
1885
|
}
|
|
869
|
-
var promptbookVersion = listItemParts.pop();
|
|
870
|
-
// TODO: Validate version
|
|
871
|
-
return {
|
|
872
|
-
type: 'PROMPTBOOK_VERSION',
|
|
873
|
-
promptbookVersion: promptbookVersion,
|
|
874
|
-
};
|
|
875
1886
|
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
1887
|
+
/**
|
|
1888
|
+
* Gets all promptbooks in the library
|
|
1889
|
+
*/
|
|
1890
|
+
SimplePromptbookLibrary.prototype.listPromptbooks = function () {
|
|
1891
|
+
return Array.from(this.library.keys());
|
|
1892
|
+
};
|
|
1893
|
+
/**
|
|
1894
|
+
* Gets promptbook by its URL
|
|
1895
|
+
*
|
|
1896
|
+
* Note: This is not a direct fetching from the URL, but a lookup in the library
|
|
1897
|
+
*/
|
|
1898
|
+
SimplePromptbookLibrary.prototype.getPromptbookByUrl = function (url) {
|
|
1899
|
+
var _this = this;
|
|
1900
|
+
var promptbook = this.library.get(url);
|
|
1901
|
+
if (!promptbook) {
|
|
1902
|
+
if (this.listPromptbooks().length === 0) {
|
|
1903
|
+
throw new PromptbookNotFoundError(spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
|
|
1904
|
+
}
|
|
1905
|
+
throw new PromptbookNotFoundError(spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
|
|
1906
|
+
.map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
|
|
1907
|
+
.join('\n')), "\n\n "); }));
|
|
883
1908
|
}
|
|
884
|
-
return
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
1909
|
+
return promptbook;
|
|
1910
|
+
};
|
|
1911
|
+
/**
|
|
1912
|
+
* Checks whether given prompt was defined in any promptbook in the library
|
|
1913
|
+
*/
|
|
1914
|
+
SimplePromptbookLibrary.prototype.isResponsibleForPrompt = function (prompt) {
|
|
1915
|
+
return true;
|
|
1916
|
+
};
|
|
1917
|
+
return SimplePromptbookLibrary;
|
|
1918
|
+
}());
|
|
1919
|
+
|
|
1920
|
+
/**
|
|
1921
|
+
* Creates PromptbookLibrary from array of PromptbookJson or PromptbookString
|
|
1922
|
+
*
|
|
1923
|
+
* Note: You can combine `PromptbookString` (`.ptbk.md`) with `PromptbookJson` BUT it is not recommended
|
|
1924
|
+
* Note: During the construction syntax and logic of all sources are validated
|
|
1925
|
+
*
|
|
1926
|
+
* @param promptbookSources
|
|
1927
|
+
* @returns PromptbookLibrary
|
|
1928
|
+
*/
|
|
1929
|
+
function createPromptbookLibraryFromSources() {
|
|
1930
|
+
var promptbookSources = [];
|
|
1931
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1932
|
+
promptbookSources[_i] = arguments[_i];
|
|
888
1933
|
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
1934
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1935
|
+
var promptbooks, promptbookSources_1, promptbookSources_1_1, source, promptbook, e_1_1;
|
|
1936
|
+
var e_1, _a;
|
|
1937
|
+
return __generator(this, function (_b) {
|
|
1938
|
+
switch (_b.label) {
|
|
1939
|
+
case 0:
|
|
1940
|
+
promptbooks = new Array();
|
|
1941
|
+
_b.label = 1;
|
|
1942
|
+
case 1:
|
|
1943
|
+
_b.trys.push([1, 8, 9, 10]);
|
|
1944
|
+
promptbookSources_1 = __values(promptbookSources), promptbookSources_1_1 = promptbookSources_1.next();
|
|
1945
|
+
_b.label = 2;
|
|
1946
|
+
case 2:
|
|
1947
|
+
if (!!promptbookSources_1_1.done) return [3 /*break*/, 7];
|
|
1948
|
+
source = promptbookSources_1_1.value;
|
|
1949
|
+
promptbook = void 0;
|
|
1950
|
+
if (!(typeof source === 'string')) return [3 /*break*/, 4];
|
|
1951
|
+
return [4 /*yield*/, promptbookStringToJson(source)];
|
|
1952
|
+
case 3:
|
|
1953
|
+
// Note: When directly creating from string, no need to validate the source
|
|
1954
|
+
// The validation is performed always before execution
|
|
1955
|
+
promptbook = _b.sent();
|
|
1956
|
+
return [3 /*break*/, 5];
|
|
1957
|
+
case 4:
|
|
1958
|
+
promptbook = source;
|
|
1959
|
+
_b.label = 5;
|
|
1960
|
+
case 5:
|
|
1961
|
+
promptbooks.push(promptbook);
|
|
1962
|
+
_b.label = 6;
|
|
1963
|
+
case 6:
|
|
1964
|
+
promptbookSources_1_1 = promptbookSources_1.next();
|
|
1965
|
+
return [3 /*break*/, 2];
|
|
1966
|
+
case 7: return [3 /*break*/, 10];
|
|
1967
|
+
case 8:
|
|
1968
|
+
e_1_1 = _b.sent();
|
|
1969
|
+
e_1 = { error: e_1_1 };
|
|
1970
|
+
return [3 /*break*/, 10];
|
|
1971
|
+
case 9:
|
|
1972
|
+
try {
|
|
1973
|
+
if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
|
|
1974
|
+
}
|
|
1975
|
+
finally { if (e_1) throw e_1.error; }
|
|
1976
|
+
return [7 /*endfinally*/];
|
|
1977
|
+
case 10: return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
|
|
1978
|
+
}
|
|
1979
|
+
});
|
|
1980
|
+
});
|
|
1981
|
+
}
|
|
1982
|
+
/**
|
|
1983
|
+
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
1984
|
+
*/
|
|
1985
|
+
|
|
1986
|
+
/* tslint:disable */
|
|
1987
|
+
function normalizeToKebabCase(sentence) {
|
|
1988
|
+
var e_1, _a;
|
|
1989
|
+
sentence = removeDiacritics(sentence);
|
|
1990
|
+
var charType;
|
|
1991
|
+
var lastCharType = 'OTHER';
|
|
1992
|
+
var normalizedName = '';
|
|
1993
|
+
try {
|
|
1994
|
+
for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
|
|
1995
|
+
var char = sentence_1_1.value;
|
|
1996
|
+
var normalizedChar = void 0;
|
|
1997
|
+
if (/^[a-z]$/.test(char)) {
|
|
1998
|
+
charType = 'LOWERCASE';
|
|
1999
|
+
normalizedChar = char;
|
|
898
2000
|
}
|
|
899
|
-
else if (
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
2001
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
2002
|
+
charType = 'UPPERCASE';
|
|
2003
|
+
normalizedChar = char.toLowerCase();
|
|
2004
|
+
}
|
|
2005
|
+
else if (/^[0-9]$/.test(char)) {
|
|
2006
|
+
charType = 'NUMBER';
|
|
2007
|
+
normalizedChar = char;
|
|
2008
|
+
}
|
|
2009
|
+
else if (/^\/$/.test(char)) {
|
|
2010
|
+
charType = 'SLASH';
|
|
2011
|
+
normalizedChar = char;
|
|
905
2012
|
}
|
|
906
2013
|
else {
|
|
907
|
-
|
|
2014
|
+
charType = 'OTHER';
|
|
2015
|
+
normalizedChar = '-';
|
|
908
2016
|
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
else {
|
|
918
|
-
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
|
|
2017
|
+
if (charType !== lastCharType &&
|
|
2018
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
2019
|
+
!(lastCharType === 'NUMBER') &&
|
|
2020
|
+
!(charType === 'NUMBER')) {
|
|
2021
|
+
normalizedName += '-';
|
|
2022
|
+
}
|
|
2023
|
+
normalizedName += normalizedChar;
|
|
2024
|
+
lastCharType = charType;
|
|
919
2025
|
}
|
|
920
2026
|
}
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
|
|
926
|
-
var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
|
|
927
|
-
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
928
|
-
throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
929
|
-
}
|
|
930
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
931
|
-
var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
|
|
932
|
-
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
|
|
933
|
-
throw new PromptbookSyntaxError(spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
|
|
934
|
-
}
|
|
935
|
-
var isInput = type.startsWith('INPUT');
|
|
936
|
-
var isOutput = type.startsWith('OUTPUT');
|
|
937
|
-
if (listItem.startsWith('> {')) {
|
|
938
|
-
isInput = false;
|
|
939
|
-
isOutput = false;
|
|
2027
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2028
|
+
finally {
|
|
2029
|
+
try {
|
|
2030
|
+
if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
|
|
940
2031
|
}
|
|
941
|
-
|
|
942
|
-
type: 'PARAMETER',
|
|
943
|
-
parameterName: parameterName,
|
|
944
|
-
parameterDescription: parameterDescription.trim() || null,
|
|
945
|
-
isInput: isInput,
|
|
946
|
-
isOutput: isOutput,
|
|
947
|
-
};
|
|
2032
|
+
finally { if (e_1) throw e_1.error; }
|
|
948
2033
|
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
2034
|
+
normalizedName = normalizedName.split(/-+/g).join('-');
|
|
2035
|
+
normalizedName = normalizedName.split(/-?\/-?/g).join('/');
|
|
2036
|
+
normalizedName = normalizedName.replace(/^-/, '');
|
|
2037
|
+
normalizedName = normalizedName.replace(/-$/, '');
|
|
2038
|
+
return normalizedName;
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
function prepareKnowledgeFromMarkdown(options) {
|
|
2042
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2043
|
+
var content, llmTools, library, promptbook, executor, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
|
|
2044
|
+
var _this = this;
|
|
2045
|
+
return __generator(this, function (_a) {
|
|
2046
|
+
switch (_a.label) {
|
|
2047
|
+
case 0:
|
|
2048
|
+
content = options.content, llmTools = options.llmTools;
|
|
2049
|
+
return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
|
|
2050
|
+
case 1:
|
|
2051
|
+
library = _a.sent();
|
|
2052
|
+
promptbook = library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md');
|
|
2053
|
+
executor = createPromptbookExecutor({
|
|
2054
|
+
promptbook: promptbook,
|
|
2055
|
+
tools: {
|
|
2056
|
+
llm: llmTools,
|
|
2057
|
+
script: [
|
|
2058
|
+
/* <- TODO: Allow to just not define script tools */
|
|
2059
|
+
],
|
|
2060
|
+
},
|
|
2061
|
+
});
|
|
2062
|
+
return [4 /*yield*/, executor({ content: content })];
|
|
2063
|
+
case 2:
|
|
2064
|
+
result = _a.sent();
|
|
2065
|
+
assertsExecutionSuccessful(result);
|
|
2066
|
+
outputParameters = result.outputParameters;
|
|
2067
|
+
knowledgeRaw = outputParameters.knowledge;
|
|
2068
|
+
knowledgeTextPieces = (knowledgeRaw || '').split('\n---\n');
|
|
2069
|
+
return [4 /*yield*/, Promise.all(knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
2070
|
+
var name, title, content, keywords, index, sources;
|
|
2071
|
+
return __generator(this, function (_a) {
|
|
2072
|
+
name = "piece-".concat(i);
|
|
2073
|
+
title = spaceTrim$1(knowledgeTextPiece.substring(0, 100));
|
|
2074
|
+
content = spaceTrim$1(knowledgeTextPiece);
|
|
2075
|
+
keywords = [];
|
|
2076
|
+
index = [];
|
|
2077
|
+
sources = [];
|
|
2078
|
+
try {
|
|
2079
|
+
// TODO: !!!! Summarize name and title from the content
|
|
2080
|
+
title = spaceTrim$1(knowledgeTextPiece.substring(0, 30));
|
|
2081
|
+
name = normalizeToKebabCase(title);
|
|
2082
|
+
// TODO: !!!! Extract keywords via prompt
|
|
2083
|
+
// TODO: !!!! Index through LLM model
|
|
2084
|
+
// TODO: [🖖] !!!! Make system for sources and identification of sources
|
|
2085
|
+
}
|
|
2086
|
+
catch (error) {
|
|
2087
|
+
console.error(error);
|
|
2088
|
+
}
|
|
2089
|
+
return [2 /*return*/, {
|
|
2090
|
+
name: name,
|
|
2091
|
+
title: title,
|
|
2092
|
+
content: content,
|
|
2093
|
+
keywords: keywords,
|
|
2094
|
+
index: index,
|
|
2095
|
+
sources: sources,
|
|
2096
|
+
}];
|
|
2097
|
+
});
|
|
2098
|
+
}); }))];
|
|
2099
|
+
case 3:
|
|
2100
|
+
knowledge = _a.sent();
|
|
2101
|
+
return [2 /*return*/, knowledge];
|
|
2102
|
+
}
|
|
2103
|
+
});
|
|
2104
|
+
});
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
/**
|
|
2108
|
+
* Supported script languages
|
|
2109
|
+
*/
|
|
2110
|
+
var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
2111
|
+
|
|
2112
|
+
/**
|
|
2113
|
+
* Computes the deepness of the markdown structure.
|
|
2114
|
+
*
|
|
2115
|
+
* @private within the library
|
|
2116
|
+
*/
|
|
2117
|
+
function countMarkdownStructureDeepness(markdownStructure) {
|
|
2118
|
+
var e_1, _a;
|
|
2119
|
+
var maxDeepness = 0;
|
|
2120
|
+
try {
|
|
2121
|
+
for (var _b = __values(markdownStructure.sections), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2122
|
+
var section = _c.value;
|
|
2123
|
+
maxDeepness = Math.max(maxDeepness, countMarkdownStructureDeepness(section));
|
|
956
2124
|
}
|
|
957
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
958
|
-
var parameterName = parametersMatch.groups.parameterName;
|
|
959
|
-
return {
|
|
960
|
-
type: 'JOKER',
|
|
961
|
-
parameterName: parameterName,
|
|
962
|
-
};
|
|
963
2125
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
2126
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2127
|
+
finally {
|
|
2128
|
+
try {
|
|
2129
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
967
2130
|
}
|
|
968
|
-
|
|
969
|
-
return {
|
|
970
|
-
type: 'POSTPROCESS',
|
|
971
|
-
functionName: functionName,
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
else if (type.startsWith('EXPECT_JSON')) {
|
|
975
|
-
return {
|
|
976
|
-
type: 'EXPECT_FORMAT',
|
|
977
|
-
format: 'JSON',
|
|
978
|
-
};
|
|
979
|
-
// [🥤]
|
|
2131
|
+
finally { if (e_1) throw e_1.error; }
|
|
980
2132
|
}
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
2133
|
+
return maxDeepness + 1;
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
/**
|
|
2137
|
+
* Parse a markdown string into a MarkdownStructure object.
|
|
2138
|
+
*
|
|
2139
|
+
* Note: This function does work with code blocks
|
|
2140
|
+
* Note: This function does not work with markdown comments
|
|
2141
|
+
*
|
|
2142
|
+
* @param markdown The markdown string to parse.
|
|
2143
|
+
* @returns The MarkdownStructure object.
|
|
2144
|
+
*
|
|
2145
|
+
* @private within the library
|
|
2146
|
+
*/
|
|
2147
|
+
function markdownToMarkdownStructure(markdown) {
|
|
2148
|
+
var e_1, _a;
|
|
2149
|
+
var lines = markdown.split('\n');
|
|
2150
|
+
var root = { level: 0, title: '', contentLines: [], sections: [], parent: null };
|
|
2151
|
+
var current = root;
|
|
2152
|
+
var isInsideCodeBlock = false;
|
|
2153
|
+
try {
|
|
2154
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2155
|
+
var line = lines_1_1.value;
|
|
2156
|
+
var headingMatch = line.match(/^(?<mark>#{1,6})\s(?<title>.*)/);
|
|
2157
|
+
if (isInsideCodeBlock || !headingMatch) {
|
|
2158
|
+
if (line.startsWith('```')) {
|
|
2159
|
+
isInsideCodeBlock = !isInsideCodeBlock;
|
|
2160
|
+
}
|
|
2161
|
+
current.contentLines.push(line);
|
|
994
2162
|
}
|
|
995
2163
|
else {
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
var existingUnit = EXPECTATION_UNITS_1_1.value;
|
|
1011
|
-
var existingUnitText = existingUnit;
|
|
1012
|
-
existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
|
|
1013
|
-
if (existingUnitText === 'CHARACTER') {
|
|
1014
|
-
existingUnitText = 'CHAR';
|
|
1015
|
-
}
|
|
1016
|
-
if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
|
|
1017
|
-
new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
|
|
1018
|
-
if (unit !== undefined) {
|
|
1019
|
-
throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
|
|
2164
|
+
var level = headingMatch.groups.mark.length;
|
|
2165
|
+
var title = headingMatch.groups.title.trim();
|
|
2166
|
+
var parent_1 = void 0;
|
|
2167
|
+
if (level > current.level) {
|
|
2168
|
+
// Note: Going deeper (next section is child of current)
|
|
2169
|
+
parent_1 = current;
|
|
2170
|
+
}
|
|
2171
|
+
else {
|
|
2172
|
+
// Note: Going up or staying at the same level (next section is sibling or parent or grandparent,... of current)
|
|
2173
|
+
parent_1 = current;
|
|
2174
|
+
var loopLimit = LOOP_LIMIT;
|
|
2175
|
+
while (parent_1.level !== level - 1) {
|
|
2176
|
+
if (loopLimit-- < 0) {
|
|
2177
|
+
throw new UnexpectedError('Loop limit reached during parsing of markdown structure in `markdownToMarkdownStructure`');
|
|
1020
2178
|
}
|
|
1021
|
-
|
|
2179
|
+
if (parent_1.parent === null /* <- Note: We are in root */) {
|
|
2180
|
+
// [🌻]
|
|
2181
|
+
throw new Error(spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
|
|
2182
|
+
}
|
|
2183
|
+
parent_1 = parent_1.parent;
|
|
1022
2184
|
}
|
|
1023
2185
|
}
|
|
2186
|
+
var section = { level: level, title: title, contentLines: [], sections: [], parent: parent_1 };
|
|
2187
|
+
parent_1.sections.push(section);
|
|
2188
|
+
current = section;
|
|
1024
2189
|
}
|
|
1025
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1026
|
-
finally {
|
|
1027
|
-
try {
|
|
1028
|
-
if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
|
|
1029
|
-
}
|
|
1030
|
-
finally { if (e_1) throw e_1.error; }
|
|
1031
|
-
}
|
|
1032
|
-
if (unit === undefined) {
|
|
1033
|
-
throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
|
|
1034
|
-
}
|
|
1035
|
-
return {
|
|
1036
|
-
type: 'EXPECT_AMOUNT',
|
|
1037
|
-
sign: sign,
|
|
1038
|
-
unit: unit,
|
|
1039
|
-
amount: amount,
|
|
1040
|
-
};
|
|
1041
2190
|
}
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
2191
|
+
}
|
|
2192
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2193
|
+
finally {
|
|
2194
|
+
try {
|
|
2195
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
1047
2196
|
}
|
|
1048
|
-
|
|
1049
|
-
} else if (type.startsWith('__________________')) {
|
|
1050
|
-
// <- [🥻] Insert here when making new command
|
|
1051
|
-
*/
|
|
2197
|
+
finally { if (e_1) throw e_1.error; }
|
|
1052
2198
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
2199
|
+
if (root.sections.length === 1) {
|
|
2200
|
+
var markdownStructure = parsingMarkdownStructureToMarkdownStructure(root.sections[0]);
|
|
2201
|
+
return markdownStructure;
|
|
1055
2202
|
}
|
|
2203
|
+
// [🌻]
|
|
2204
|
+
throw new Error('The markdown file must have exactly one top-level section.');
|
|
2205
|
+
// return root;
|
|
2206
|
+
}
|
|
2207
|
+
/**
|
|
2208
|
+
* @private
|
|
2209
|
+
*/
|
|
2210
|
+
function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
|
|
2211
|
+
var level = parsingMarkdownStructure.level, title = parsingMarkdownStructure.title, contentLines = parsingMarkdownStructure.contentLines, sections = parsingMarkdownStructure.sections;
|
|
2212
|
+
return {
|
|
2213
|
+
level: level,
|
|
2214
|
+
title: title,
|
|
2215
|
+
content: spaceTrim(contentLines.join('\n')),
|
|
2216
|
+
sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
|
|
2217
|
+
};
|
|
2218
|
+
}
|
|
2219
|
+
|
|
2220
|
+
/**
|
|
2221
|
+
* Utility function to extract all list items from markdown
|
|
2222
|
+
*
|
|
2223
|
+
* Note: It works with both ul and ol
|
|
2224
|
+
* Note: It omits list items in code blocks
|
|
2225
|
+
* Note: It flattens nested lists
|
|
2226
|
+
* Note: It can not work with html syntax and comments
|
|
2227
|
+
*
|
|
2228
|
+
* @param markdown any valid markdown
|
|
2229
|
+
* @returns
|
|
2230
|
+
*/
|
|
2231
|
+
function extractAllListItemsFromMarkdown(markdown) {
|
|
2232
|
+
var e_1, _a;
|
|
2233
|
+
var lines = markdown.split('\n');
|
|
2234
|
+
var listItems = [];
|
|
2235
|
+
var isInCodeBlock = false;
|
|
2236
|
+
try {
|
|
2237
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2238
|
+
var line = lines_1_1.value;
|
|
2239
|
+
var trimmedLine = line.trim();
|
|
2240
|
+
if (trimmedLine.startsWith('```')) {
|
|
2241
|
+
isInCodeBlock = !isInCodeBlock;
|
|
2242
|
+
}
|
|
2243
|
+
if (!isInCodeBlock && (trimmedLine.startsWith('-') || trimmedLine.match(/^\d+\./))) {
|
|
2244
|
+
var listItem = trimmedLine.replace(/^-|\d+\./, '').trim();
|
|
2245
|
+
listItems.push(listItem);
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2250
|
+
finally {
|
|
2251
|
+
try {
|
|
2252
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
2253
|
+
}
|
|
2254
|
+
finally { if (e_1) throw e_1.error; }
|
|
2255
|
+
}
|
|
2256
|
+
return listItems;
|
|
1056
2257
|
}
|
|
1057
2258
|
|
|
1058
|
-
var defaultDiacriticsRemovalMap = [
|
|
1059
|
-
{
|
|
1060
|
-
base: 'A',
|
|
1061
|
-
letters: '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F',
|
|
1062
|
-
},
|
|
1063
|
-
{ base: 'AA', letters: '\uA732' },
|
|
1064
|
-
{ base: 'AE', letters: '\u00C6\u01FC\u01E2' },
|
|
1065
|
-
{ base: 'AO', letters: '\uA734' },
|
|
1066
|
-
{ base: 'AU', letters: '\uA736' },
|
|
1067
|
-
{ base: 'AV', letters: '\uA738\uA73A' },
|
|
1068
|
-
{ base: 'AY', letters: '\uA73C' },
|
|
1069
|
-
{
|
|
1070
|
-
base: 'B',
|
|
1071
|
-
letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
|
|
1072
|
-
},
|
|
1073
|
-
{
|
|
1074
|
-
base: 'C',
|
|
1075
|
-
letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
|
|
1076
|
-
},
|
|
1077
|
-
{
|
|
1078
|
-
base: 'D',
|
|
1079
|
-
letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
|
|
1080
|
-
},
|
|
1081
|
-
{ base: 'DZ', letters: '\u01F1\u01C4' },
|
|
1082
|
-
{ base: 'Dz', letters: '\u01F2\u01C5' },
|
|
1083
|
-
{
|
|
1084
|
-
base: 'E',
|
|
1085
|
-
letters: '\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E',
|
|
1086
|
-
},
|
|
1087
|
-
{ base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
|
|
1088
|
-
{
|
|
1089
|
-
base: 'G',
|
|
1090
|
-
letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
|
|
1091
|
-
},
|
|
1092
|
-
{
|
|
1093
|
-
base: 'H',
|
|
1094
|
-
letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
|
|
1095
|
-
},
|
|
1096
|
-
{
|
|
1097
|
-
base: 'I',
|
|
1098
|
-
letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
|
|
1099
|
-
},
|
|
1100
|
-
{ base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
|
|
1101
|
-
{
|
|
1102
|
-
base: 'K',
|
|
1103
|
-
letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
|
|
1104
|
-
},
|
|
1105
|
-
{
|
|
1106
|
-
base: 'L',
|
|
1107
|
-
letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
|
|
1108
|
-
},
|
|
1109
|
-
{ base: 'LJ', letters: '\u01C7' },
|
|
1110
|
-
{ base: 'Lj', letters: '\u01C8' },
|
|
1111
|
-
{ base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
|
|
1112
|
-
{
|
|
1113
|
-
base: 'N',
|
|
1114
|
-
letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
|
|
1115
|
-
},
|
|
1116
|
-
{ base: 'NJ', letters: '\u01CA' },
|
|
1117
|
-
{ base: 'Nj', letters: '\u01CB' },
|
|
1118
|
-
{
|
|
1119
|
-
base: 'O',
|
|
1120
|
-
letters: '\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C',
|
|
1121
|
-
},
|
|
1122
|
-
{ base: 'OI', letters: '\u01A2' },
|
|
1123
|
-
{ base: 'OO', letters: '\uA74E' },
|
|
1124
|
-
{ base: 'OU', letters: '\u0222' },
|
|
1125
|
-
{ base: 'OE', letters: '\u008C\u0152' },
|
|
1126
|
-
{ base: 'oe', letters: '\u009C\u0153' },
|
|
1127
|
-
{
|
|
1128
|
-
base: 'P',
|
|
1129
|
-
letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
|
|
1130
|
-
},
|
|
1131
|
-
{ base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
|
|
1132
|
-
{
|
|
1133
|
-
base: 'R',
|
|
1134
|
-
letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
|
|
1135
|
-
},
|
|
1136
|
-
{
|
|
1137
|
-
base: 'S',
|
|
1138
|
-
letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
|
|
1139
|
-
},
|
|
1140
|
-
{
|
|
1141
|
-
base: 'T',
|
|
1142
|
-
letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
|
|
1143
|
-
},
|
|
1144
|
-
{ base: 'TZ', letters: '\uA728' },
|
|
1145
|
-
{
|
|
1146
|
-
base: 'U',
|
|
1147
|
-
letters: '\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244',
|
|
1148
|
-
},
|
|
1149
|
-
{ base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
|
|
1150
|
-
{ base: 'VY', letters: '\uA760' },
|
|
1151
|
-
{
|
|
1152
|
-
base: 'W',
|
|
1153
|
-
letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
|
|
1154
|
-
},
|
|
1155
|
-
{ base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
|
|
1156
|
-
{
|
|
1157
|
-
base: 'Y',
|
|
1158
|
-
letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
|
|
1159
|
-
},
|
|
1160
|
-
{
|
|
1161
|
-
base: 'Z',
|
|
1162
|
-
letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
|
|
1163
|
-
},
|
|
1164
|
-
{
|
|
1165
|
-
base: 'a',
|
|
1166
|
-
letters: '\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250',
|
|
1167
|
-
},
|
|
1168
|
-
{ base: 'aa', letters: '\uA733' },
|
|
1169
|
-
{ base: 'ae', letters: '\u00E6\u01FD\u01E3' },
|
|
1170
|
-
{ base: 'ao', letters: '\uA735' },
|
|
1171
|
-
{ base: 'au', letters: '\uA737' },
|
|
1172
|
-
{ base: 'av', letters: '\uA739\uA73B' },
|
|
1173
|
-
{ base: 'ay', letters: '\uA73D' },
|
|
1174
|
-
{
|
|
1175
|
-
base: 'b',
|
|
1176
|
-
letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
|
|
1177
|
-
},
|
|
1178
|
-
{
|
|
1179
|
-
base: 'c',
|
|
1180
|
-
letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
|
|
1181
|
-
},
|
|
1182
|
-
{
|
|
1183
|
-
base: 'd',
|
|
1184
|
-
letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
|
|
1185
|
-
},
|
|
1186
|
-
{ base: 'dz', letters: '\u01F3\u01C6' },
|
|
1187
|
-
{
|
|
1188
|
-
base: 'e',
|
|
1189
|
-
letters: '\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD',
|
|
1190
|
-
},
|
|
1191
|
-
{ base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
|
|
1192
|
-
{
|
|
1193
|
-
base: 'g',
|
|
1194
|
-
letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
|
|
1195
|
-
},
|
|
1196
|
-
{
|
|
1197
|
-
base: 'h',
|
|
1198
|
-
letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
|
|
1199
|
-
},
|
|
1200
|
-
{ base: 'hv', letters: '\u0195' },
|
|
1201
|
-
{
|
|
1202
|
-
base: 'i',
|
|
1203
|
-
letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
|
|
1204
|
-
},
|
|
1205
|
-
{ base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
|
|
1206
|
-
{
|
|
1207
|
-
base: 'k',
|
|
1208
|
-
letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
|
|
1209
|
-
},
|
|
1210
|
-
{
|
|
1211
|
-
base: 'l',
|
|
1212
|
-
letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
|
|
1213
|
-
},
|
|
1214
|
-
{ base: 'lj', letters: '\u01C9' },
|
|
1215
|
-
{ base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
|
|
1216
|
-
{
|
|
1217
|
-
base: 'n',
|
|
1218
|
-
letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
|
|
1219
|
-
},
|
|
1220
|
-
{ base: 'nj', letters: '\u01CC' },
|
|
1221
|
-
{
|
|
1222
|
-
base: 'o',
|
|
1223
|
-
letters: '\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275',
|
|
1224
|
-
},
|
|
1225
|
-
{ base: 'oi', letters: '\u01A3' },
|
|
1226
|
-
{ base: 'ou', letters: '\u0223' },
|
|
1227
|
-
{ base: 'oo', letters: '\uA74F' },
|
|
1228
|
-
{
|
|
1229
|
-
base: 'p',
|
|
1230
|
-
letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
|
|
1231
|
-
},
|
|
1232
|
-
{ base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
|
|
1233
|
-
{
|
|
1234
|
-
base: 'r',
|
|
1235
|
-
letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
|
|
1236
|
-
},
|
|
1237
|
-
{
|
|
1238
|
-
base: 's',
|
|
1239
|
-
letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
|
|
1240
|
-
},
|
|
1241
|
-
{
|
|
1242
|
-
base: 't',
|
|
1243
|
-
letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
|
|
1244
|
-
},
|
|
1245
|
-
{ base: 'tz', letters: '\uA729' },
|
|
1246
|
-
{
|
|
1247
|
-
base: 'u',
|
|
1248
|
-
letters: '\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289',
|
|
1249
|
-
},
|
|
1250
|
-
{ base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
|
|
1251
|
-
{ base: 'vy', letters: '\uA761' },
|
|
1252
|
-
{
|
|
1253
|
-
base: 'w',
|
|
1254
|
-
letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
|
|
1255
|
-
},
|
|
1256
|
-
{ base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
|
|
1257
|
-
{
|
|
1258
|
-
base: 'y',
|
|
1259
|
-
letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
|
|
1260
|
-
},
|
|
1261
|
-
{
|
|
1262
|
-
base: 'z',
|
|
1263
|
-
letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
|
|
1264
|
-
},
|
|
1265
|
-
];
|
|
1266
2259
|
/**
|
|
1267
|
-
*
|
|
1268
|
-
*
|
|
2260
|
+
* Extracts all code blocks from markdown.
|
|
2261
|
+
*
|
|
2262
|
+
* Note: There are 3 simmilar function:
|
|
2263
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2264
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2265
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2266
|
+
*
|
|
2267
|
+
* @param markdown any valid markdown
|
|
2268
|
+
* @returns code blocks with language and content
|
|
1269
2269
|
*
|
|
1270
|
-
* > "á" => "a"
|
|
1271
|
-
* > "ě" => "e"
|
|
1272
|
-
* > "Ă" => "A"
|
|
1273
|
-
* > ...
|
|
1274
2270
|
*/
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
var
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
2271
|
+
function extractAllBlocksFromMarkdown(markdown) {
|
|
2272
|
+
var e_1, _a;
|
|
2273
|
+
var codeBlocks = [];
|
|
2274
|
+
var lines = markdown.split('\n');
|
|
2275
|
+
var currentCodeBlock = null;
|
|
2276
|
+
try {
|
|
2277
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
2278
|
+
var line = lines_1_1.value;
|
|
2279
|
+
if (line.startsWith('```')) {
|
|
2280
|
+
var language = line.slice(3).trim() || null;
|
|
2281
|
+
if (currentCodeBlock === null) {
|
|
2282
|
+
currentCodeBlock = { language: language, content: '' };
|
|
2283
|
+
}
|
|
2284
|
+
else {
|
|
2285
|
+
if (language !== null) {
|
|
2286
|
+
// [🌻]
|
|
2287
|
+
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
2288
|
+
}
|
|
2289
|
+
codeBlocks.push(currentCodeBlock);
|
|
2290
|
+
currentCodeBlock = null;
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
else if (currentCodeBlock !== null) {
|
|
2294
|
+
if (currentCodeBlock.content !== '') {
|
|
2295
|
+
currentCodeBlock.content += '\n';
|
|
2296
|
+
}
|
|
2297
|
+
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2302
|
+
finally {
|
|
2303
|
+
try {
|
|
2304
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
2305
|
+
}
|
|
2306
|
+
finally { if (e_1) throw e_1.error; }
|
|
2307
|
+
}
|
|
2308
|
+
if (currentCodeBlock !== null) {
|
|
2309
|
+
// [🌻]
|
|
2310
|
+
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
1282
2311
|
}
|
|
2312
|
+
return codeBlocks;
|
|
1283
2313
|
}
|
|
1284
|
-
// <- TODO: [🍓] Put to maker function to save execution time if not needed
|
|
1285
|
-
/*
|
|
1286
|
-
@see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
|
|
1287
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
1288
|
-
you may not use this file except in compliance with the License.
|
|
1289
|
-
You may obtain a copy of the License at
|
|
1290
2314
|
|
|
1291
|
-
|
|
2315
|
+
/**
|
|
2316
|
+
* Extracts exactly ONE code block from markdown.
|
|
2317
|
+
*
|
|
2318
|
+
* Note: If there are multiple or no code blocks the function throws an error
|
|
2319
|
+
*
|
|
2320
|
+
* Note: There are 3 simmilar function:
|
|
2321
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
2322
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
2323
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
2324
|
+
*
|
|
2325
|
+
* @param markdown any valid markdown
|
|
2326
|
+
* @returns code block with language and content
|
|
2327
|
+
*/
|
|
2328
|
+
function extractOneBlockFromMarkdown(markdown) {
|
|
2329
|
+
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
2330
|
+
if (codeBlocks.length !== 1) {
|
|
2331
|
+
// TODO: Report more specific place where the error happened
|
|
2332
|
+
throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
|
|
2333
|
+
}
|
|
2334
|
+
return codeBlocks[0];
|
|
2335
|
+
}
|
|
2336
|
+
/***
|
|
2337
|
+
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
2338
|
+
*/
|
|
1292
2339
|
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
2340
|
+
/**
|
|
2341
|
+
* Creates a new set with all elements that are present in either set
|
|
2342
|
+
*/
|
|
2343
|
+
function union() {
|
|
2344
|
+
var e_1, _a, e_2, _b;
|
|
2345
|
+
var sets = [];
|
|
2346
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2347
|
+
sets[_i] = arguments[_i];
|
|
2348
|
+
}
|
|
2349
|
+
var union = new Set();
|
|
2350
|
+
try {
|
|
2351
|
+
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
2352
|
+
var set = sets_1_1.value;
|
|
2353
|
+
try {
|
|
2354
|
+
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2355
|
+
var item = _d.value;
|
|
2356
|
+
union.add(item);
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2360
|
+
finally {
|
|
2361
|
+
try {
|
|
2362
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
2363
|
+
}
|
|
2364
|
+
finally { if (e_2) throw e_2.error; }
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2369
|
+
finally {
|
|
2370
|
+
try {
|
|
2371
|
+
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
2372
|
+
}
|
|
2373
|
+
finally { if (e_1) throw e_1.error; }
|
|
2374
|
+
}
|
|
2375
|
+
return union;
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
/**
|
|
2379
|
+
* Parses the template and returns the list of all parameter names
|
|
2380
|
+
*
|
|
2381
|
+
* @param template the template with parameters in {curly} braces
|
|
2382
|
+
* @returns the list of parameter names
|
|
2383
|
+
*/
|
|
2384
|
+
function extractParameters(template) {
|
|
2385
|
+
var e_1, _a;
|
|
2386
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
2387
|
+
var parameterNames = new Set();
|
|
2388
|
+
try {
|
|
2389
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
2390
|
+
var match = matches_1_1.value;
|
|
2391
|
+
var parameterName = match[0].slice(1, -1);
|
|
2392
|
+
parameterNames.add(parameterName);
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2396
|
+
finally {
|
|
2397
|
+
try {
|
|
2398
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
2399
|
+
}
|
|
2400
|
+
finally { if (e_1) throw e_1.error; }
|
|
2401
|
+
}
|
|
2402
|
+
return parameterNames;
|
|
2403
|
+
}
|
|
2404
|
+
|
|
2405
|
+
/**
|
|
2406
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
2407
|
+
*
|
|
2408
|
+
* @param script from which to extract the variables
|
|
2409
|
+
* @returns the list of variable names
|
|
2410
|
+
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
2411
|
+
*/
|
|
2412
|
+
function extractVariables(script) {
|
|
2413
|
+
var variables = new Set();
|
|
2414
|
+
script = "(()=>{".concat(script, "})()");
|
|
2415
|
+
try {
|
|
2416
|
+
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
2417
|
+
try {
|
|
2418
|
+
eval(script);
|
|
2419
|
+
}
|
|
2420
|
+
catch (error) {
|
|
2421
|
+
if (!(error instanceof ReferenceError)) {
|
|
2422
|
+
throw error;
|
|
2423
|
+
}
|
|
2424
|
+
var undefinedName = error.message.split(' ')[0];
|
|
2425
|
+
/*
|
|
2426
|
+
Note: Remapping error
|
|
2427
|
+
From: [ReferenceError: thing is not defined],
|
|
2428
|
+
To: [Error: Parameter {thing} is not defined],
|
|
2429
|
+
*/
|
|
2430
|
+
if (!undefinedName) {
|
|
2431
|
+
throw error;
|
|
2432
|
+
}
|
|
2433
|
+
if (script.includes(undefinedName + '(')) {
|
|
2434
|
+
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
2435
|
+
}
|
|
2436
|
+
else {
|
|
2437
|
+
variables.add(undefinedName);
|
|
2438
|
+
script = "const ".concat(undefinedName, " = '';") + script;
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
catch (error) {
|
|
2443
|
+
if (!(error instanceof Error)) {
|
|
2444
|
+
throw error;
|
|
2445
|
+
}
|
|
2446
|
+
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
2447
|
+
}
|
|
2448
|
+
return variables;
|
|
2449
|
+
}
|
|
2450
|
+
/**
|
|
2451
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
2452
|
+
*/
|
|
1299
2453
|
|
|
1300
2454
|
/**
|
|
1301
|
-
*
|
|
2455
|
+
* Parses the prompt template and returns the set of all used parameters
|
|
2456
|
+
*
|
|
2457
|
+
* @param promptTemplate the template with used parameters
|
|
2458
|
+
* @returns the set of parameter names
|
|
2459
|
+
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
2460
|
+
*/
|
|
2461
|
+
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
2462
|
+
var e_1, _a, e_2, _b;
|
|
2463
|
+
var parameterNames = new Set();
|
|
2464
|
+
try {
|
|
2465
|
+
for (var _c = __values(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameters(promptTemplate.title)), false), __read(extractParameters(promptTemplate.description || '')), false), __read(extractParameters(promptTemplate.content)), false)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2466
|
+
var parameterName = _d.value;
|
|
2467
|
+
parameterNames.add(parameterName);
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2471
|
+
finally {
|
|
2472
|
+
try {
|
|
2473
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
2474
|
+
}
|
|
2475
|
+
finally { if (e_1) throw e_1.error; }
|
|
2476
|
+
}
|
|
2477
|
+
if (promptTemplate.executionType === 'SCRIPT') {
|
|
2478
|
+
try {
|
|
2479
|
+
for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
2480
|
+
var parameterName = _f.value;
|
|
2481
|
+
parameterNames.add(parameterName);
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2485
|
+
finally {
|
|
2486
|
+
try {
|
|
2487
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
2488
|
+
}
|
|
2489
|
+
finally { if (e_2) throw e_2.error; }
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
return parameterNames;
|
|
2493
|
+
}
|
|
2494
|
+
/**
|
|
2495
|
+
* TODO: [🔣] If script require contentLanguage
|
|
1302
2496
|
*/
|
|
1303
|
-
function removeDiacritics(input) {
|
|
1304
|
-
/*eslint no-control-regex: "off"*/
|
|
1305
|
-
return input.replace(/[^\u0000-\u007E]/g, function (a) {
|
|
1306
|
-
return DIACRITIC_VARIANTS_LETTERS[a] || a;
|
|
1307
|
-
});
|
|
1308
|
-
}
|
|
1309
2497
|
|
|
1310
2498
|
/* tslint:disable */
|
|
1311
|
-
|
|
2499
|
+
/*
|
|
2500
|
+
TODO: Tests
|
|
2501
|
+
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
2502
|
+
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
2503
|
+
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
2504
|
+
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
2505
|
+
*/
|
|
2506
|
+
function normalizeTo_SCREAMING_CASE(sentence) {
|
|
1312
2507
|
var e_1, _a;
|
|
1313
|
-
sentence = removeDiacritics(sentence);
|
|
1314
2508
|
var charType;
|
|
1315
2509
|
var lastCharType = 'OTHER';
|
|
1316
2510
|
var normalizedName = '';
|
|
@@ -1320,46 +2514,401 @@ function normalizeToKebabCase(sentence) {
|
|
|
1320
2514
|
var normalizedChar = void 0;
|
|
1321
2515
|
if (/^[a-z]$/.test(char)) {
|
|
1322
2516
|
charType = 'LOWERCASE';
|
|
2517
|
+
normalizedChar = char.toUpperCase();
|
|
2518
|
+
}
|
|
2519
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
2520
|
+
charType = 'UPPERCASE';
|
|
2521
|
+
normalizedChar = char;
|
|
2522
|
+
}
|
|
2523
|
+
else if (/^[0-9]$/.test(char)) {
|
|
2524
|
+
charType = 'NUMBER';
|
|
2525
|
+
normalizedChar = char;
|
|
2526
|
+
}
|
|
2527
|
+
else if (/^\/$/.test(char)) {
|
|
2528
|
+
charType = 'SLASH';
|
|
1323
2529
|
normalizedChar = char;
|
|
1324
2530
|
}
|
|
1325
|
-
else
|
|
1326
|
-
charType = '
|
|
1327
|
-
normalizedChar =
|
|
2531
|
+
else {
|
|
2532
|
+
charType = 'OTHER';
|
|
2533
|
+
normalizedChar = '_';
|
|
2534
|
+
}
|
|
2535
|
+
if (charType !== lastCharType &&
|
|
2536
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
2537
|
+
!(lastCharType === 'NUMBER') &&
|
|
2538
|
+
!(charType === 'NUMBER')) {
|
|
2539
|
+
normalizedName += '_';
|
|
2540
|
+
}
|
|
2541
|
+
normalizedName += normalizedChar;
|
|
2542
|
+
lastCharType = charType;
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2546
|
+
finally {
|
|
2547
|
+
try {
|
|
2548
|
+
if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
|
|
2549
|
+
}
|
|
2550
|
+
finally { if (e_1) throw e_1.error; }
|
|
2551
|
+
}
|
|
2552
|
+
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
2553
|
+
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
2554
|
+
normalizedName = normalizedName.replace(/^_/, '');
|
|
2555
|
+
normalizedName = normalizedName.replace(/_$/, '');
|
|
2556
|
+
return normalizedName;
|
|
2557
|
+
}
|
|
2558
|
+
/**
|
|
2559
|
+
* TODO: [🌺] Use some intermediate util splitWords
|
|
2560
|
+
*/
|
|
2561
|
+
|
|
2562
|
+
/**
|
|
2563
|
+
* Execution type describes the way how the block is executed
|
|
2564
|
+
*
|
|
2565
|
+
* @see https://github.com/webgptorg/promptbook#execution-type
|
|
2566
|
+
*/
|
|
2567
|
+
var ExecutionTypes = [
|
|
2568
|
+
'PROMPT_TEMPLATE',
|
|
2569
|
+
'SIMPLE_TEMPLATE',
|
|
2570
|
+
'SCRIPT',
|
|
2571
|
+
'PROMPT_DIALOG',
|
|
2572
|
+
// <- [🥻] Insert here when making new command
|
|
2573
|
+
];
|
|
2574
|
+
|
|
2575
|
+
/**
|
|
2576
|
+
* Units of text measurement
|
|
2577
|
+
*/
|
|
2578
|
+
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
2579
|
+
/**
|
|
2580
|
+
* TODO: [💝] Unite object for expecting amount and format - remove expectFormat
|
|
2581
|
+
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
2582
|
+
* TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
|
|
2583
|
+
*/
|
|
2584
|
+
|
|
2585
|
+
/**
|
|
2586
|
+
* Removes Markdown formatting tags from a string.
|
|
2587
|
+
*
|
|
2588
|
+
* @param {string} str - The string to remove Markdown tags from.
|
|
2589
|
+
* @returns {string} The input string with all Markdown tags removed.
|
|
2590
|
+
*/
|
|
2591
|
+
function removeMarkdownFormatting(str) {
|
|
2592
|
+
// Remove bold formatting
|
|
2593
|
+
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
2594
|
+
// Remove italic formatting
|
|
2595
|
+
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
2596
|
+
// Remove code formatting
|
|
2597
|
+
str = str.replace(/`(.*?)`/g, '$1');
|
|
2598
|
+
return str;
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
/**
|
|
2602
|
+
* Function parseNumber will parse number from string
|
|
2603
|
+
*
|
|
2604
|
+
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
2605
|
+
* Note: it also works only with decimal numbers
|
|
2606
|
+
*
|
|
2607
|
+
* @returns parsed number
|
|
2608
|
+
* @throws {PromptbookSyntaxError} if the value is not a number
|
|
2609
|
+
*
|
|
2610
|
+
* @private within the parseCommand
|
|
2611
|
+
*/
|
|
2612
|
+
function parseNumber(value) {
|
|
2613
|
+
var originalValue = value;
|
|
2614
|
+
if (typeof value === 'number') {
|
|
2615
|
+
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
2616
|
+
}
|
|
2617
|
+
if (typeof value !== 'string') {
|
|
2618
|
+
return 0;
|
|
2619
|
+
}
|
|
2620
|
+
value = value.trim();
|
|
2621
|
+
if (value.startsWith('+')) {
|
|
2622
|
+
return parseNumber(value.substring(1));
|
|
2623
|
+
}
|
|
2624
|
+
if (value.startsWith('-')) {
|
|
2625
|
+
var number = parseNumber(value.substring(1));
|
|
2626
|
+
if (number === 0) {
|
|
2627
|
+
return 0; // <- Note: To prevent -0
|
|
2628
|
+
}
|
|
2629
|
+
return -number;
|
|
2630
|
+
}
|
|
2631
|
+
value = value.replace(/,/g, '.');
|
|
2632
|
+
value = value.toUpperCase();
|
|
2633
|
+
if (value === '') {
|
|
2634
|
+
return 0;
|
|
2635
|
+
}
|
|
2636
|
+
if (value === '♾' || value.startsWith('INF')) {
|
|
2637
|
+
return Infinity;
|
|
2638
|
+
}
|
|
2639
|
+
if (value.includes('/')) {
|
|
2640
|
+
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
2641
|
+
var numerator = parseNumber(numerator_);
|
|
2642
|
+
var denominator = parseNumber(denominator_);
|
|
2643
|
+
if (denominator === 0) {
|
|
2644
|
+
throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
2645
|
+
}
|
|
2646
|
+
return numerator / denominator;
|
|
2647
|
+
}
|
|
2648
|
+
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
2649
|
+
return 0;
|
|
2650
|
+
}
|
|
2651
|
+
if (value.includes('E')) {
|
|
2652
|
+
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
2653
|
+
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
2654
|
+
}
|
|
2655
|
+
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
2656
|
+
throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
2657
|
+
}
|
|
2658
|
+
var num = parseFloat(value);
|
|
2659
|
+
if (isNaN(num)) {
|
|
2660
|
+
throw new PromptbookSyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
2661
|
+
}
|
|
2662
|
+
return num;
|
|
2663
|
+
}
|
|
2664
|
+
/**
|
|
2665
|
+
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
2666
|
+
*/
|
|
2667
|
+
|
|
2668
|
+
/**
|
|
2669
|
+
* Parses one line of ul/ol to command
|
|
2670
|
+
*
|
|
2671
|
+
* @returns parsed command object
|
|
2672
|
+
* @throws {PromptbookSyntaxError} if the command is invalid
|
|
2673
|
+
*
|
|
2674
|
+
* @private within the promptbookStringToJson
|
|
2675
|
+
*/
|
|
2676
|
+
function parseCommand(listItem) {
|
|
2677
|
+
var e_1, _a;
|
|
2678
|
+
if (listItem.includes('\n') || listItem.includes('\r')) {
|
|
2679
|
+
throw new PromptbookSyntaxError('Command can not contain new line characters:');
|
|
2680
|
+
}
|
|
2681
|
+
var type = listItem.trim();
|
|
2682
|
+
type = type.split('`').join('');
|
|
2683
|
+
type = type.split('"').join('');
|
|
2684
|
+
type = type.split("'").join('');
|
|
2685
|
+
type = type.split('~').join('');
|
|
2686
|
+
type = type.split('[').join('');
|
|
2687
|
+
type = type.split(']').join('');
|
|
2688
|
+
type = type.split('(').join('');
|
|
2689
|
+
type = type.split(')').join('');
|
|
2690
|
+
type = normalizeTo_SCREAMING_CASE(type);
|
|
2691
|
+
type = type.split('DIALOGUE').join('DIALOG');
|
|
2692
|
+
var listItemParts = listItem
|
|
2693
|
+
.split(' ')
|
|
2694
|
+
.map(function (part) { return part.trim(); })
|
|
2695
|
+
.filter(function (item) { return item !== ''; })
|
|
2696
|
+
.filter(function (item) { return !/^PTBK$/i.test(item); })
|
|
2697
|
+
.filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
|
|
2698
|
+
.map(removeMarkdownFormatting);
|
|
2699
|
+
if (type.startsWith('URL') ||
|
|
2700
|
+
type.startsWith('PTBK_URL') ||
|
|
2701
|
+
type.startsWith('PTBKURL') ||
|
|
2702
|
+
type.startsWith('PROMPTBOOK_URL') ||
|
|
2703
|
+
type.startsWith('PROMPTBOOKURL') ||
|
|
2704
|
+
type.startsWith('HTTPS')) {
|
|
2705
|
+
if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
|
|
2706
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
|
|
2707
|
+
}
|
|
2708
|
+
var promptbookUrlString = listItemParts.pop();
|
|
2709
|
+
var promptbookUrl = new URL(promptbookUrlString);
|
|
2710
|
+
if (promptbookUrl.protocol !== 'https:') {
|
|
2711
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
|
|
2712
|
+
}
|
|
2713
|
+
if (promptbookUrl.hash !== '') {
|
|
2714
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
|
|
2715
|
+
}
|
|
2716
|
+
return {
|
|
2717
|
+
type: 'PROMPTBOOK_URL',
|
|
2718
|
+
promptbookUrl: promptbookUrl,
|
|
2719
|
+
};
|
|
2720
|
+
}
|
|
2721
|
+
else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
|
|
2722
|
+
if (listItemParts.length !== 2) {
|
|
2723
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
|
|
2724
|
+
}
|
|
2725
|
+
var promptbookVersion = listItemParts.pop();
|
|
2726
|
+
// TODO: Validate version
|
|
2727
|
+
return {
|
|
2728
|
+
type: 'PROMPTBOOK_VERSION',
|
|
2729
|
+
promptbookVersion: promptbookVersion,
|
|
2730
|
+
};
|
|
2731
|
+
}
|
|
2732
|
+
else if (type.startsWith('EXECUTE') ||
|
|
2733
|
+
type.startsWith('EXEC') ||
|
|
2734
|
+
type.startsWith('PROMPT_DIALOG') ||
|
|
2735
|
+
type.startsWith('SIMPLE_TEMPLATE')) {
|
|
2736
|
+
var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
|
|
2737
|
+
if (executionTypes.length !== 1) {
|
|
2738
|
+
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown execution type in command:\n\n - ".concat(listItem, "\n\n Supported execution types are:\n ").concat(block(ExecutionTypes.join(', ')), "\n "); }));
|
|
2739
|
+
}
|
|
2740
|
+
return {
|
|
2741
|
+
type: 'EXECUTE',
|
|
2742
|
+
executionType: executionTypes[0],
|
|
2743
|
+
};
|
|
2744
|
+
}
|
|
2745
|
+
else if (type.startsWith('MODEL')) {
|
|
2746
|
+
// TODO: Make this more elegant and dynamically
|
|
2747
|
+
if (type.startsWith('MODEL_VARIANT')) {
|
|
2748
|
+
if (type === 'MODEL_VARIANT_CHAT') {
|
|
2749
|
+
return {
|
|
2750
|
+
type: 'MODEL',
|
|
2751
|
+
key: 'modelVariant',
|
|
2752
|
+
value: 'CHAT',
|
|
2753
|
+
};
|
|
2754
|
+
}
|
|
2755
|
+
else if (type === 'MODEL_VARIANT_COMPLETION') {
|
|
2756
|
+
return {
|
|
2757
|
+
type: 'MODEL',
|
|
2758
|
+
key: 'modelVariant',
|
|
2759
|
+
value: 'COMPLETION',
|
|
2760
|
+
};
|
|
1328
2761
|
}
|
|
1329
|
-
else
|
|
1330
|
-
|
|
1331
|
-
normalizedChar = char;
|
|
2762
|
+
else {
|
|
2763
|
+
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n - ".concat(listItem, "\n\n Supported variants are:\n ").concat(block(['CHAT', 'COMPLETION'].join(', ')), "\n "); }));
|
|
1332
2764
|
}
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
2765
|
+
}
|
|
2766
|
+
if (type.startsWith('MODEL_NAME')) {
|
|
2767
|
+
return {
|
|
2768
|
+
type: 'MODEL',
|
|
2769
|
+
key: 'modelName',
|
|
2770
|
+
value: listItemParts.pop(),
|
|
2771
|
+
};
|
|
2772
|
+
}
|
|
2773
|
+
else {
|
|
2774
|
+
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
else if (type.startsWith('PARAM') ||
|
|
2778
|
+
type.startsWith('INPUT_PARAM') ||
|
|
2779
|
+
type.startsWith('OUTPUT_PARAM') ||
|
|
2780
|
+
listItem.startsWith('{') ||
|
|
2781
|
+
listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
|
|
2782
|
+
var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
|
|
2783
|
+
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
2784
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
2785
|
+
}
|
|
2786
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2787
|
+
var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
|
|
2788
|
+
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
|
|
2789
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
|
|
2790
|
+
}
|
|
2791
|
+
var isInput = type.startsWith('INPUT');
|
|
2792
|
+
var isOutput = type.startsWith('OUTPUT');
|
|
2793
|
+
if (listItem.startsWith('> {')) {
|
|
2794
|
+
isInput = false;
|
|
2795
|
+
isOutput = false;
|
|
2796
|
+
}
|
|
2797
|
+
return {
|
|
2798
|
+
type: 'PARAMETER',
|
|
2799
|
+
parameterName: parameterName,
|
|
2800
|
+
parameterDescription: parameterDescription.trim() || null,
|
|
2801
|
+
isInput: isInput,
|
|
2802
|
+
isOutput: isOutput,
|
|
2803
|
+
};
|
|
2804
|
+
}
|
|
2805
|
+
else if (type.startsWith('JOKER')) {
|
|
2806
|
+
if (listItemParts.length !== 2) {
|
|
2807
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
|
|
2808
|
+
}
|
|
2809
|
+
var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
|
|
2810
|
+
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
2811
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
2812
|
+
}
|
|
2813
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2814
|
+
var parameterName = parametersMatch.groups.parameterName;
|
|
2815
|
+
return {
|
|
2816
|
+
type: 'JOKER',
|
|
2817
|
+
parameterName: parameterName,
|
|
2818
|
+
};
|
|
2819
|
+
}
|
|
2820
|
+
else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
|
|
2821
|
+
if (listItemParts.length !== 2) {
|
|
2822
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
|
|
2823
|
+
}
|
|
2824
|
+
var functionName = listItemParts.pop();
|
|
2825
|
+
return {
|
|
2826
|
+
type: 'POSTPROCESS',
|
|
2827
|
+
functionName: functionName,
|
|
2828
|
+
};
|
|
2829
|
+
}
|
|
2830
|
+
else if (type.startsWith('EXPECT_JSON')) {
|
|
2831
|
+
return {
|
|
2832
|
+
type: 'EXPECT_FORMAT',
|
|
2833
|
+
format: 'JSON',
|
|
2834
|
+
};
|
|
2835
|
+
// [🥤]
|
|
2836
|
+
}
|
|
2837
|
+
else if (type.startsWith('EXPECT')) {
|
|
2838
|
+
try {
|
|
2839
|
+
listItemParts.shift();
|
|
2840
|
+
var sign = void 0;
|
|
2841
|
+
var signRaw = listItemParts.shift();
|
|
2842
|
+
if (/^exact/i.test(signRaw)) {
|
|
2843
|
+
sign = 'EXACTLY';
|
|
2844
|
+
}
|
|
2845
|
+
else if (/^min/i.test(signRaw)) {
|
|
2846
|
+
sign = 'MINIMUM';
|
|
2847
|
+
}
|
|
2848
|
+
else if (/^max/i.test(signRaw)) {
|
|
2849
|
+
sign = 'MAXIMUM';
|
|
1336
2850
|
}
|
|
1337
2851
|
else {
|
|
1338
|
-
|
|
1339
|
-
normalizedChar = '-';
|
|
2852
|
+
throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
|
|
1340
2853
|
}
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
normalizedName += '-';
|
|
2854
|
+
var amountRaw = listItemParts.shift();
|
|
2855
|
+
var amount = parseNumber(amountRaw);
|
|
2856
|
+
if (amount < 0) {
|
|
2857
|
+
throw new PromptbookSyntaxError('Amount must be positive number or zero');
|
|
1346
2858
|
}
|
|
1347
|
-
|
|
1348
|
-
|
|
2859
|
+
if (amount !== Math.floor(amount)) {
|
|
2860
|
+
throw new PromptbookSyntaxError('Amount must be whole number');
|
|
2861
|
+
}
|
|
2862
|
+
var unitRaw = listItemParts.shift();
|
|
2863
|
+
var unit = undefined;
|
|
2864
|
+
try {
|
|
2865
|
+
for (var EXPECTATION_UNITS_1 = __values(EXPECTATION_UNITS), EXPECTATION_UNITS_1_1 = EXPECTATION_UNITS_1.next(); !EXPECTATION_UNITS_1_1.done; EXPECTATION_UNITS_1_1 = EXPECTATION_UNITS_1.next()) {
|
|
2866
|
+
var existingUnit = EXPECTATION_UNITS_1_1.value;
|
|
2867
|
+
var existingUnitText = existingUnit;
|
|
2868
|
+
existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
|
|
2869
|
+
if (existingUnitText === 'CHARACTER') {
|
|
2870
|
+
existingUnitText = 'CHAR';
|
|
2871
|
+
}
|
|
2872
|
+
if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
|
|
2873
|
+
new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
|
|
2874
|
+
if (unit !== undefined) {
|
|
2875
|
+
throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
|
|
2876
|
+
}
|
|
2877
|
+
unit = existingUnit;
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2882
|
+
finally {
|
|
2883
|
+
try {
|
|
2884
|
+
if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
|
|
2885
|
+
}
|
|
2886
|
+
finally { if (e_1) throw e_1.error; }
|
|
2887
|
+
}
|
|
2888
|
+
if (unit === undefined) {
|
|
2889
|
+
throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
|
|
2890
|
+
}
|
|
2891
|
+
return {
|
|
2892
|
+
type: 'EXPECT_AMOUNT',
|
|
2893
|
+
sign: sign,
|
|
2894
|
+
unit: unit,
|
|
2895
|
+
amount: amount,
|
|
2896
|
+
};
|
|
1349
2897
|
}
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
2898
|
+
catch (error) {
|
|
2899
|
+
if (!(error instanceof Error)) {
|
|
2900
|
+
throw error;
|
|
2901
|
+
}
|
|
2902
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
|
|
1355
2903
|
}
|
|
1356
|
-
|
|
2904
|
+
/*
|
|
2905
|
+
} else if (type.startsWith('__________________')) {
|
|
2906
|
+
// <- [🥻] Insert here when making new command
|
|
2907
|
+
*/
|
|
2908
|
+
}
|
|
2909
|
+
else {
|
|
2910
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - PROMPTBOOK_URL <url>\n - PROMPTBOOK_VERSION <version>\n - EXECUTE PROMPT TEMPLATE\n - EXECUTE SIMPLE TEMPLATE\n - SIMPLE TEMPLATE\n - EXECUTE SCRIPT\n - EXECUTE PROMPT_DIALOG'\n - PROMPT_DIALOG'\n - MODEL NAME <name>\n - MODEL VARIANT <\"Chat\"|\"Completion\">\n - INPUT PARAM {<name>} <description>\n - OUTPUT PARAM {<name>} <description>\n - POSTPROCESS `{functionName}`\n - JOKER {<name>}\n - EXPECT JSON\n - EXPECT <\"Exactly\"|\"Min\"|\"Max\"> <number> <\"Chars\"|\"Words\"|\"Sentences\"|\"Paragraphs\"|\"Pages\">\n\n ")));
|
|
1357
2911
|
}
|
|
1358
|
-
normalizedName = normalizedName.split(/-+/g).join('-');
|
|
1359
|
-
normalizedName = normalizedName.split(/-?\/-?/g).join('/');
|
|
1360
|
-
normalizedName = normalizedName.replace(/^-/, '');
|
|
1361
|
-
normalizedName = normalizedName.replace(/-$/, '');
|
|
1362
|
-
return normalizedName;
|
|
1363
2912
|
}
|
|
1364
2913
|
|
|
1365
2914
|
/**
|
|
@@ -1391,250 +2940,265 @@ function titleToName(value) {
|
|
|
1391
2940
|
* Compile promptbook from string (markdown) format to JSON format
|
|
1392
2941
|
*
|
|
1393
2942
|
* @param promptbookString {Promptbook} in string markdown format (.ptbk.md)
|
|
1394
|
-
* @param
|
|
2943
|
+
* @param options - Options and tools for the compilation
|
|
1395
2944
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
1396
2945
|
* @throws {PromptbookSyntaxError} if the promptbook string is not valid
|
|
1397
2946
|
*
|
|
1398
2947
|
* Note: This function does not validate logic of the pipeline only the syntax
|
|
1399
2948
|
* Note: This function acts as compilation process
|
|
1400
2949
|
*/
|
|
1401
|
-
function promptbookStringToJson(promptbookString,
|
|
2950
|
+
function promptbookStringToJson(promptbookString, options) {
|
|
2951
|
+
if (options === void 0) { options = {}; }
|
|
1402
2952
|
return __awaiter(this, void 0, void 0, function () {
|
|
1403
|
-
var promptbookJson, addParam, markdownStructure, markdownStructureDeepness, description, defaultModelRequirements, listItems, listItems_1, listItems_1_1, listItem, command, _loop_1, _a, _b, section;
|
|
2953
|
+
var llmTools, promptbookJson, knowledge, addParam, markdownStructure, markdownStructureDeepness, description, defaultModelRequirements, listItems, listItems_1, listItems_1_1, listItem, command, _loop_1, _a, _b, section;
|
|
1404
2954
|
var e_1, _c, e_2, _d;
|
|
1405
2955
|
return __generator(this, function (_e) {
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
2956
|
+
switch (_e.label) {
|
|
2957
|
+
case 0:
|
|
2958
|
+
llmTools = options.llmTools;
|
|
2959
|
+
promptbookJson = {
|
|
2960
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2961
|
+
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
2962
|
+
promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
|
|
2963
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
2964
|
+
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
2965
|
+
parameters: [],
|
|
2966
|
+
promptTemplates: [],
|
|
2967
|
+
knowledge: [],
|
|
2968
|
+
};
|
|
2969
|
+
if (!llmTools) return [3 /*break*/, 2];
|
|
2970
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdown({
|
|
2971
|
+
content: 'Roses are red, violets are blue, programmers use Promptbook, users too',
|
|
2972
|
+
llmTools: llmTools,
|
|
2973
|
+
})];
|
|
2974
|
+
case 1:
|
|
2975
|
+
knowledge = _e.sent();
|
|
2976
|
+
console.info('!!!! knowledge', knowledge);
|
|
2977
|
+
_e.label = 2;
|
|
2978
|
+
case 2:
|
|
2979
|
+
// =============================================================
|
|
2980
|
+
// Note: 1️⃣ Normalization of the PROMPTBOOK string
|
|
2981
|
+
promptbookString = removeContentComments(promptbookString);
|
|
2982
|
+
promptbookString = promptbookString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
2983
|
+
promptbookString = promptbookString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
2984
|
+
addParam = function (parameterCommand) {
|
|
2985
|
+
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
2986
|
+
var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
2987
|
+
if (existingParameter &&
|
|
2988
|
+
existingParameter.description &&
|
|
2989
|
+
existingParameter.description !== parameterDescription &&
|
|
2990
|
+
parameterDescription) {
|
|
2991
|
+
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description.\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
|
|
2992
|
+
}
|
|
2993
|
+
if (existingParameter) {
|
|
2994
|
+
if (parameterDescription) {
|
|
2995
|
+
existingParameter.description = parameterDescription;
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
else {
|
|
2999
|
+
promptbookJson.parameters.push({
|
|
3000
|
+
name: parameterName,
|
|
3001
|
+
description: parameterDescription || undefined,
|
|
3002
|
+
isInput: isInput,
|
|
3003
|
+
isOutput: isOutput,
|
|
3004
|
+
});
|
|
3005
|
+
}
|
|
3006
|
+
};
|
|
3007
|
+
markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
3008
|
+
markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
3009
|
+
if (markdownStructureDeepness !== 2) {
|
|
3010
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
|
|
1433
3011
|
}
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
};
|
|
1444
|
-
markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1445
|
-
markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1446
|
-
if (markdownStructureDeepness !== 2) {
|
|
1447
|
-
throw new PromptbookSyntaxError(spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
|
|
1448
|
-
}
|
|
1449
|
-
promptbookJson.title = markdownStructure.title;
|
|
1450
|
-
description = markdownStructure.content;
|
|
1451
|
-
// Note: Remove codeblocks
|
|
1452
|
-
description = description.split(/^```.*^```/gms).join('');
|
|
1453
|
-
//Note: Remove lists and return statement
|
|
1454
|
-
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1455
|
-
description = spaceTrim(description);
|
|
1456
|
-
if (description === '') {
|
|
1457
|
-
description = undefined;
|
|
1458
|
-
}
|
|
1459
|
-
promptbookJson.description = description;
|
|
1460
|
-
defaultModelRequirements = {};
|
|
1461
|
-
listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
1462
|
-
try {
|
|
1463
|
-
for (listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
1464
|
-
listItem = listItems_1_1.value;
|
|
1465
|
-
command = parseCommand(listItem);
|
|
1466
|
-
switch (command.type) {
|
|
1467
|
-
case 'PROMPTBOOK_URL':
|
|
1468
|
-
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
1469
|
-
break;
|
|
1470
|
-
case 'PROMPTBOOK_VERSION':
|
|
1471
|
-
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
1472
|
-
break;
|
|
1473
|
-
case 'MODEL':
|
|
1474
|
-
defaultModelRequirements[command.key] = command.value;
|
|
1475
|
-
break;
|
|
1476
|
-
case 'PARAMETER':
|
|
1477
|
-
addParam(command);
|
|
1478
|
-
break;
|
|
1479
|
-
default:
|
|
1480
|
-
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
3012
|
+
promptbookJson.title = markdownStructure.title;
|
|
3013
|
+
description = markdownStructure.content;
|
|
3014
|
+
// Note: Remove codeblocks
|
|
3015
|
+
description = description.split(/^```.*^```/gms).join('');
|
|
3016
|
+
//Note: Remove lists and return statement
|
|
3017
|
+
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
3018
|
+
description = spaceTrim(description);
|
|
3019
|
+
if (description === '') {
|
|
3020
|
+
description = undefined;
|
|
1481
3021
|
}
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
var listItem = listItems_2_1.value;
|
|
1506
|
-
var command = parseCommand(listItem);
|
|
1507
|
-
switch (command.type) {
|
|
1508
|
-
case 'JOKER':
|
|
1509
|
-
jokers.push(command.parameterName);
|
|
1510
|
-
dependentParameterNames.add(command.parameterName);
|
|
1511
|
-
break;
|
|
1512
|
-
case 'EXECUTE':
|
|
1513
|
-
if (isExecutionTypeChanged) {
|
|
1514
|
-
throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
1515
|
-
}
|
|
1516
|
-
executionType = command.executionType;
|
|
1517
|
-
isExecutionTypeChanged = true;
|
|
1518
|
-
break;
|
|
1519
|
-
case 'MODEL':
|
|
1520
|
-
templateModelRequirements[command.key] = command.value;
|
|
1521
|
-
break;
|
|
1522
|
-
case 'PARAMETER':
|
|
1523
|
-
// Note: This is just for detecting resulitng parameter name
|
|
1524
|
-
addParam(command);
|
|
1525
|
-
break;
|
|
1526
|
-
case 'POSTPROCESS':
|
|
1527
|
-
postprocessing.push(command.functionName);
|
|
1528
|
-
break;
|
|
1529
|
-
case 'EXPECT_AMOUNT':
|
|
1530
|
-
// eslint-disable-next-line no-case-declarations
|
|
1531
|
-
var unit = command.unit.toLowerCase();
|
|
1532
|
-
expectAmount[unit] = expectAmount[unit] || {};
|
|
1533
|
-
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
1534
|
-
if (expectAmount[unit].min !== undefined) {
|
|
1535
|
-
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1536
|
-
}
|
|
1537
|
-
expectAmount[unit].min = command.amount;
|
|
1538
|
-
} /* not else */
|
|
1539
|
-
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
1540
|
-
if (expectAmount[unit].max !== undefined) {
|
|
1541
|
-
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1542
|
-
}
|
|
1543
|
-
expectAmount[unit].max = command.amount;
|
|
1544
|
-
}
|
|
1545
|
-
break;
|
|
1546
|
-
case 'EXPECT_FORMAT':
|
|
1547
|
-
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
1548
|
-
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
1549
|
-
}
|
|
1550
|
-
expectFormat = command.format;
|
|
1551
|
-
break;
|
|
1552
|
-
default:
|
|
1553
|
-
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
3022
|
+
promptbookJson.description = description;
|
|
3023
|
+
defaultModelRequirements = {};
|
|
3024
|
+
listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
3025
|
+
try {
|
|
3026
|
+
for (listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
3027
|
+
listItem = listItems_1_1.value;
|
|
3028
|
+
command = parseCommand(listItem);
|
|
3029
|
+
switch (command.type) {
|
|
3030
|
+
case 'PROMPTBOOK_URL':
|
|
3031
|
+
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
3032
|
+
break;
|
|
3033
|
+
case 'PROMPTBOOK_VERSION':
|
|
3034
|
+
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
3035
|
+
break;
|
|
3036
|
+
case 'MODEL':
|
|
3037
|
+
defaultModelRequirements[command.key] = command.value;
|
|
3038
|
+
break;
|
|
3039
|
+
case 'PARAMETER':
|
|
3040
|
+
addParam(command);
|
|
3041
|
+
break;
|
|
3042
|
+
default:
|
|
3043
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
3044
|
+
}
|
|
1554
3045
|
}
|
|
1555
3046
|
}
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
3047
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3048
|
+
finally {
|
|
3049
|
+
try {
|
|
3050
|
+
if (listItems_1_1 && !listItems_1_1.done && (_c = listItems_1.return)) _c.call(listItems_1);
|
|
3051
|
+
}
|
|
3052
|
+
finally { if (e_1) throw e_1.error; }
|
|
1561
3053
|
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
3054
|
+
_loop_1 = function (section) {
|
|
3055
|
+
var e_3, _f;
|
|
3056
|
+
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
3057
|
+
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
3058
|
+
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
3059
|
+
var dependentParameterNames = new Set();
|
|
3060
|
+
var executionType = 'PROMPT_TEMPLATE';
|
|
3061
|
+
var jokers = [];
|
|
3062
|
+
var postprocessing = [];
|
|
3063
|
+
var expectAmount = {};
|
|
3064
|
+
var expectFormat = undefined;
|
|
3065
|
+
var isExecutionTypeChanged = false;
|
|
3066
|
+
try {
|
|
3067
|
+
for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
|
|
3068
|
+
var listItem = listItems_2_1.value;
|
|
3069
|
+
var command = parseCommand(listItem);
|
|
3070
|
+
switch (command.type) {
|
|
3071
|
+
case 'JOKER':
|
|
3072
|
+
jokers.push(command.parameterName);
|
|
3073
|
+
dependentParameterNames.add(command.parameterName);
|
|
3074
|
+
break;
|
|
3075
|
+
case 'EXECUTE':
|
|
3076
|
+
if (isExecutionTypeChanged) {
|
|
3077
|
+
throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
3078
|
+
}
|
|
3079
|
+
executionType = command.executionType;
|
|
3080
|
+
isExecutionTypeChanged = true;
|
|
3081
|
+
break;
|
|
3082
|
+
case 'MODEL':
|
|
3083
|
+
templateModelRequirements[command.key] = command.value;
|
|
3084
|
+
break;
|
|
3085
|
+
case 'PARAMETER':
|
|
3086
|
+
// Note: This is just for detecting resulitng parameter name
|
|
3087
|
+
addParam(command);
|
|
3088
|
+
break;
|
|
3089
|
+
case 'POSTPROCESS':
|
|
3090
|
+
postprocessing.push(command.functionName);
|
|
3091
|
+
break;
|
|
3092
|
+
case 'EXPECT_AMOUNT':
|
|
3093
|
+
// eslint-disable-next-line no-case-declarations
|
|
3094
|
+
var unit = command.unit.toLowerCase();
|
|
3095
|
+
expectAmount[unit] = expectAmount[unit] || {};
|
|
3096
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
3097
|
+
if (expectAmount[unit].min !== undefined) {
|
|
3098
|
+
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
3099
|
+
}
|
|
3100
|
+
expectAmount[unit].min = command.amount;
|
|
3101
|
+
} /* not else */
|
|
3102
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
3103
|
+
if (expectAmount[unit].max !== undefined) {
|
|
3104
|
+
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
3105
|
+
}
|
|
3106
|
+
expectAmount[unit].max = command.amount;
|
|
3107
|
+
}
|
|
3108
|
+
break;
|
|
3109
|
+
case 'EXPECT_FORMAT':
|
|
3110
|
+
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
3111
|
+
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
3112
|
+
}
|
|
3113
|
+
expectFormat = command.format;
|
|
3114
|
+
break;
|
|
3115
|
+
default:
|
|
3116
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
3117
|
+
}
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
3121
|
+
finally {
|
|
3122
|
+
try {
|
|
3123
|
+
if (listItems_2_1 && !listItems_2_1.done && (_f = listItems_2.return)) _f.call(listItems_2);
|
|
3124
|
+
}
|
|
3125
|
+
finally { if (e_3) throw e_3.error; }
|
|
3126
|
+
}
|
|
3127
|
+
var _g = extractOneBlockFromMarkdown(section.content), language = _g.language, content = _g.content;
|
|
3128
|
+
if (executionType === 'SCRIPT') {
|
|
3129
|
+
if (!language) {
|
|
3130
|
+
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
3131
|
+
}
|
|
3132
|
+
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
3133
|
+
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
|
|
3134
|
+
}
|
|
3135
|
+
}
|
|
3136
|
+
var lastLine = section.content.split('\n').pop();
|
|
3137
|
+
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
3138
|
+
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
3139
|
+
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
3140
|
+
// TODO: Show code of invalid sections each time + DRY
|
|
3141
|
+
section.content
|
|
3142
|
+
.split('\n')
|
|
3143
|
+
.map(function (line) { return "> ".concat(line); })
|
|
3144
|
+
.join('\n')), "\n "); }));
|
|
3145
|
+
}
|
|
3146
|
+
var resultingParameterName = match.groups.resultingParamName;
|
|
3147
|
+
// TODO: [1] DRY description
|
|
3148
|
+
var description_1 = section.content;
|
|
3149
|
+
// Note: Remove codeblocks
|
|
3150
|
+
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
3151
|
+
//Note: Remove lists and return statement
|
|
3152
|
+
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
3153
|
+
description_1 = spaceTrim(description_1);
|
|
3154
|
+
if (description_1 === '') {
|
|
3155
|
+
description_1 = undefined;
|
|
3156
|
+
}
|
|
3157
|
+
if (Object.keys(jokers).length === 0) {
|
|
3158
|
+
jokers = undefined;
|
|
3159
|
+
}
|
|
3160
|
+
if (Object.keys(expectAmount).length === 0) {
|
|
3161
|
+
expectAmount = undefined;
|
|
3162
|
+
}
|
|
3163
|
+
if (Object.keys(postprocessing).length === 0) {
|
|
3164
|
+
postprocessing = undefined;
|
|
3165
|
+
}
|
|
3166
|
+
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
3167
|
+
if (templateModelRequirements.modelVariant === undefined) {
|
|
3168
|
+
templateModelRequirements.modelVariant = 'CHAT';
|
|
3169
|
+
}
|
|
3170
|
+
promptbookJson.promptTemplates.push({
|
|
3171
|
+
name: titleToName(section.title),
|
|
3172
|
+
title: section.title,
|
|
3173
|
+
description: description_1,
|
|
3174
|
+
dependentParameterNames: Array.from(dependentParameterNames),
|
|
3175
|
+
executionType: executionType,
|
|
3176
|
+
jokers: jokers,
|
|
3177
|
+
postprocessing: postprocessing,
|
|
3178
|
+
expectations: expectAmount,
|
|
3179
|
+
expectFormat: expectFormat,
|
|
3180
|
+
modelRequirements: templateModelRequirements,
|
|
3181
|
+
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
3182
|
+
content: content,
|
|
3183
|
+
resultingParameterName: resultingParameterName,
|
|
3184
|
+
});
|
|
3185
|
+
};
|
|
3186
|
+
try {
|
|
3187
|
+
for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
3188
|
+
section = _b.value;
|
|
3189
|
+
_loop_1(section);
|
|
3190
|
+
}
|
|
1568
3191
|
}
|
|
1569
|
-
|
|
1570
|
-
|
|
3192
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3193
|
+
finally {
|
|
3194
|
+
try {
|
|
3195
|
+
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
3196
|
+
}
|
|
3197
|
+
finally { if (e_2) throw e_2.error; }
|
|
1571
3198
|
}
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1575
|
-
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1576
|
-
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1577
|
-
// TODO: Show code of invalid sections each time + DRY
|
|
1578
|
-
section.content
|
|
1579
|
-
.split('\n')
|
|
1580
|
-
.map(function (line) { return "> ".concat(line); })
|
|
1581
|
-
.join('\n')), "\n "); }));
|
|
1582
|
-
}
|
|
1583
|
-
var resultingParameterName = match.groups.resultingParamName;
|
|
1584
|
-
// TODO: [1] DRY description
|
|
1585
|
-
var description_1 = section.content;
|
|
1586
|
-
// Note: Remove codeblocks
|
|
1587
|
-
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1588
|
-
//Note: Remove lists and return statement
|
|
1589
|
-
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1590
|
-
description_1 = spaceTrim(description_1);
|
|
1591
|
-
if (description_1 === '') {
|
|
1592
|
-
description_1 = undefined;
|
|
1593
|
-
}
|
|
1594
|
-
if (Object.keys(jokers).length === 0) {
|
|
1595
|
-
jokers = undefined;
|
|
1596
|
-
}
|
|
1597
|
-
if (Object.keys(expectAmount).length === 0) {
|
|
1598
|
-
expectAmount = undefined;
|
|
1599
|
-
}
|
|
1600
|
-
if (Object.keys(postprocessing).length === 0) {
|
|
1601
|
-
postprocessing = undefined;
|
|
1602
|
-
}
|
|
1603
|
-
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1604
|
-
if (templateModelRequirements.modelVariant === undefined) {
|
|
1605
|
-
templateModelRequirements.modelVariant = 'CHAT';
|
|
1606
|
-
}
|
|
1607
|
-
promptbookJson.promptTemplates.push({
|
|
1608
|
-
name: titleToName(section.title),
|
|
1609
|
-
title: section.title,
|
|
1610
|
-
description: description_1,
|
|
1611
|
-
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1612
|
-
executionType: executionType,
|
|
1613
|
-
jokers: jokers,
|
|
1614
|
-
postprocessing: postprocessing,
|
|
1615
|
-
expectations: expectAmount,
|
|
1616
|
-
expectFormat: expectFormat,
|
|
1617
|
-
modelRequirements: templateModelRequirements,
|
|
1618
|
-
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
1619
|
-
content: content,
|
|
1620
|
-
resultingParameterName: resultingParameterName,
|
|
1621
|
-
});
|
|
1622
|
-
};
|
|
1623
|
-
try {
|
|
1624
|
-
for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1625
|
-
section = _b.value;
|
|
1626
|
-
_loop_1(section);
|
|
1627
|
-
}
|
|
1628
|
-
}
|
|
1629
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1630
|
-
finally {
|
|
1631
|
-
try {
|
|
1632
|
-
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
1633
|
-
}
|
|
1634
|
-
finally { if (e_2) throw e_2.error; }
|
|
3199
|
+
// =============================================================
|
|
3200
|
+
return [2 /*return*/, promptbookJson];
|
|
1635
3201
|
}
|
|
1636
|
-
// =============================================================
|
|
1637
|
-
return [2 /*return*/, promptbookJson];
|
|
1638
3202
|
});
|
|
1639
3203
|
});
|
|
1640
3204
|
}
|