@promptbook/cli 0.59.0-15 → 0.59.0-3
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/esm/index.es.js +968 -2511
- package/esm/index.es.js.map +1 -1
- package/esm/typings/{src/_packages → _packages}/core.index.d.ts +1 -2
- package/esm/typings/{src/knowledge → knowledge}/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +0 -3
- package/{umd/typings/src → esm/typings}/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +0 -1
- package/esm/typings/{src/llm-providers → llm-providers}/mocked/MockedFackedLlmExecutionTools.d.ts +0 -3
- package/{umd/typings/src → esm/typings}/types/PromptbookJson/MaterialKnowledgePieceJson.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +986 -2530
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/{src/_packages → _packages}/core.index.d.ts +1 -2
- package/umd/typings/{src/knowledge → knowledge}/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +0 -3
- package/{esm/typings/src → umd/typings}/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +0 -1
- package/umd/typings/{src/llm-providers → llm-providers}/mocked/MockedFackedLlmExecutionTools.d.ts +0 -3
- package/{esm/typings/src → umd/typings}/types/PromptbookJson/MaterialKnowledgePieceJson.d.ts +1 -1
- package/esm/typings/promptbook-library/promptbook-library.d.ts +0 -25
- package/umd/typings/promptbook-library/promptbook-library.d.ts +0 -25
- /package/esm/typings/{src/_packages → _packages}/anthropic-claude.index.d.ts +0 -0
- /package/esm/typings/{src/_packages → _packages}/azure-openai.index.d.ts +0 -0
- /package/esm/typings/{src/_packages → _packages}/cli.index.d.ts +0 -0
- /package/esm/typings/{src/_packages → _packages}/execute-javascript.index.d.ts +0 -0
- /package/esm/typings/{src/_packages → _packages}/fake-llm.index.d.ts +0 -0
- /package/esm/typings/{src/_packages → _packages}/langtail.index.d.ts +0 -0
- /package/esm/typings/{src/_packages → _packages}/node.index.d.ts +0 -0
- /package/esm/typings/{src/_packages → _packages}/openai.index.d.ts +0 -0
- /package/esm/typings/{src/_packages → _packages}/remote-client.index.d.ts +0 -0
- /package/esm/typings/{src/_packages → _packages}/remote-server.index.d.ts +0 -0
- /package/esm/typings/{src/_packages → _packages}/types.index.d.ts +0 -0
- /package/esm/typings/{src/_packages → _packages}/utils.index.d.ts +0 -0
- /package/esm/typings/{src/config.d.ts → config.d.ts} +0 -0
- /package/esm/typings/{src/conversion → conversion}/prettify/PrettifyOptions.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/prettify/prettifyPromptbookString.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/prettify/prettifyPromptbookStringCli.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/prettify/renderPromptbookMermaid.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/promptbookJsonToString.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/promptbookStringToJson.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/promptbookStringToJson.test.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/utils/extractParametersFromPromptTemplate.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/utils/extractParametersFromPromptTemplate.test.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/utils/extractVariables.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/utils/extractVariables.test.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/utils/parseCommand.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/utils/parseCommand.test.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/utils/parseNumber.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/utils/parseNumber.test.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/utils/renameParameter.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/utils/renameParameter.test.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/utils/titleToName.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/utils/titleToName.test.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/validation/_importPromptbook.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/validation/promptbookStringToJson-syntaxErrors.test.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/validation/validatePromptbookJson-logicErrors.test.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/validation/validatePromptbookJson.d.ts +0 -0
- /package/esm/typings/{src/conversion → conversion}/validation/validatePromptbookJson.test.d.ts +0 -0
- /package/esm/typings/{src/errors → errors}/PromptbookExecutionError.d.ts +0 -0
- /package/esm/typings/{src/errors → errors}/PromptbookLibraryError.d.ts +0 -0
- /package/esm/typings/{src/errors → errors}/PromptbookLogicError.d.ts +0 -0
- /package/esm/typings/{src/errors → errors}/PromptbookNotFoundError.d.ts +0 -0
- /package/esm/typings/{src/errors → errors}/PromptbookReferenceError.d.ts +0 -0
- /package/esm/typings/{src/errors → errors}/PromptbookSyntaxError.d.ts +0 -0
- /package/esm/typings/{src/errors → errors}/TemplateError.d.ts +0 -0
- /package/esm/typings/{src/errors → errors}/UnexpectedError.d.ts +0 -0
- /package/esm/typings/{src/errors → errors}/_ExpectError.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/CommonExecutionToolsOptions.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/ExecutionTools.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/LlmExecutionTools.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/PromptResult.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/PromptbookExecutor.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/ScriptExecutionTools.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/UserInterfaceTools.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/addPromptResultUsage.test.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/assertsExecutionSuccessful.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/createPromptbookExecutor.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.test.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/translation/automatic-translate/translateMessages.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/utils/addUsage.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/utils/addUsage.test.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/utils/checkExpectations.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/utils/checkExpectations.test.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/utils/computeUsageCounts.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/utils/forEachAsync.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/utils/replaceParameters.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/utils/replaceParameters.test.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/utils/uncertainNumber.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/utils/usageToWorktime.d.ts +0 -0
- /package/esm/typings/{src/execution → execution}/utils/usageToWorktime.test.d.ts +0 -0
- /package/esm/typings/{src/expectations → expectations}/drafts/isDomainNameFree.d.ts +0 -0
- /package/esm/typings/{src/expectations → expectations}/drafts/isGithubNameFree.d.ts +0 -0
- /package/esm/typings/{src/formats → formats}/_common/FormatDefinition.d.ts +0 -0
- /package/esm/typings/{src/formats → formats}/csv/ListFormatDefinition.d.ts +0 -0
- /package/esm/typings/{src/formats → formats}/index.d.ts +0 -0
- /package/esm/typings/{src/formats → formats}/json/JsonFormatDefinition.d.ts +0 -0
- /package/esm/typings/{src/formats → formats}/json/utils/isValidJsonString.d.ts +0 -0
- /package/esm/typings/{src/formats → formats}/json/utils/isValidJsonString.test.d.ts +0 -0
- /package/esm/typings/{src/formats → formats}/list/ListFormatDefinition.d.ts +0 -0
- /package/esm/typings/{src/formats → formats}/xml/XmlFormatDefinition.d.ts +0 -0
- /package/esm/typings/{src/knowledge → knowledge}/dialogs/callback/CallbackInterfaceTools.d.ts +0 -0
- /package/esm/typings/{src/knowledge → knowledge}/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +0 -0
- /package/esm/typings/{src/knowledge → knowledge}/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +0 -0
- /package/esm/typings/{src/knowledge → knowledge}/dialogs/user-interface-execution-tools.test.d.ts +0 -0
- /package/esm/typings/{src/knowledge → knowledge}/prepare-knowledge/_common/IndexPreparer.d.ts +0 -0
- /package/esm/typings/{src/knowledge → knowledge}/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts +0 -0
- /package/esm/typings/{src/knowledge → knowledge}/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +0 -0
- /package/esm/typings/{src/knowledge → knowledge}/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +0 -0
- /package/esm/typings/{src/knowledge → knowledge}/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/anthropic-claude/anthropic-claude-models.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/anthropic-claude/playground/playground.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/azure-openai/AzureOpenAiExecutionTools.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/azure-openai/playground/playground.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/langtail/LangtailExecutionTools.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/langtail/LangtailExecutionToolsOptions.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/langtail/playground/playground.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/mocked/fakeTextToExpectations.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/mocked/fakeTextToExpectations.test.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/mocked/faked-completion.test.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/mocked/joker.test.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/mocked/mocked-chat.test.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/mocked/mocked-completion.test.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/multiple/MultipleLlmExecutionTools.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/multiple/MultipleLlmExecutionToolsOptions.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/multiple/playground/playground.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/openai/OpenAiExecutionTools.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/openai/OpenAiExecutionToolsOptions.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/openai/computeOpenaiUsage.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/openai/computeUsage.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/openai/computeUsage.test.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/openai/openai-models.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/openai/playground/playground.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/remote/RemoteLlmExecutionTools.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/remote/RemoteLlmExecutionToolsOptions.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/remote/interfaces/Promptbook_Server_Error.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/remote/interfaces/Promptbook_Server_Progress.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/remote/interfaces/Promptbook_Server_Request.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/remote/interfaces/Promptbook_Server_Response.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/remote/interfaces/RemoteServerOptions.d.ts +0 -0
- /package/esm/typings/{src/llm-providers → llm-providers}/remote/startRemoteServer.d.ts +0 -0
- /package/esm/typings/{src/promptbook-library → promptbook-library}/PromptbookLibrary.d.ts +0 -0
- /package/esm/typings/{src/promptbook-library → promptbook-library}/SimplePromptbookLibrary.d.ts +0 -0
- /package/esm/typings/{src/promptbook-library → promptbook-library}/constructors/createPromptbookLibraryFromDirectory.d.ts +0 -0
- /package/esm/typings/{src/promptbook-library → promptbook-library}/constructors/createPromptbookLibraryFromDirectory.test.d.ts +0 -0
- /package/esm/typings/{src/promptbook-library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.d.ts +0 -0
- /package/esm/typings/{src/promptbook-library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.test.d.ts +0 -0
- /package/esm/typings/{src/promptbook-library → promptbook-library}/constructors/createPromptbookLibraryFromSources.d.ts +0 -0
- /package/esm/typings/{src/promptbook-library → promptbook-library}/constructors/createPromptbookLibraryFromSources.test.d.ts +0 -0
- /package/esm/typings/{src/promptbook-library → promptbook-library}/constructors/createPromptbookLibraryFromUrl.d.ts +0 -0
- /package/esm/typings/{src/promptbook-library → promptbook-library}/constructors/createPromptbookSublibrary.d.ts +0 -0
- /package/esm/typings/{src/promptbook-library → promptbook-library}/constructors/justTestFsImport.d.ts +0 -0
- /package/esm/typings/{src/scripting → scripting}/_test/custom-function-async.test.ts.test.d.ts +0 -0
- /package/esm/typings/{src/scripting → scripting}/_test/custom-function-missing.test.d.ts +0 -0
- /package/esm/typings/{src/scripting → scripting}/_test/custom-function-with-dependencies.test.d.ts +0 -0
- /package/esm/typings/{src/scripting → scripting}/_test/custom-function.test.d.ts +0 -0
- /package/esm/typings/{src/scripting → scripting}/_test/postprocessing.test.d.ts +0 -0
- /package/esm/typings/{src/scripting → scripting}/_test/script-execution-errors.test.d.ts +0 -0
- /package/esm/typings/{src/scripting → scripting}/_test/script-execution-tools.test.d.ts +0 -0
- /package/esm/typings/{src/scripting → scripting}/javascript/JavascriptEvalExecutionTools.d.ts +0 -0
- /package/esm/typings/{src/scripting → scripting}/javascript/JavascriptEvalExecutionTools.test.d.ts +0 -0
- /package/esm/typings/{src/scripting → scripting}/javascript/JavascriptExecutionTools.d.ts +0 -0
- /package/esm/typings/{src/scripting → scripting}/javascript/JavascriptExecutionToolsOptions.d.ts +0 -0
- /package/esm/typings/{src/scripting → scripting}/javascript/utils/preserve.d.ts +0 -0
- /package/esm/typings/{src/scripting → scripting}/javascript/utils/unknownToString.d.ts +0 -0
- /package/esm/typings/{src/scripting → scripting}/python/PythonExecutionTools.d.ts +0 -0
- /package/esm/typings/{src/scripting → scripting}/typescript/TypescriptExecutionTools.d.ts +0 -0
- /package/esm/typings/{src/types → types}/Command.d.ts +0 -0
- /package/esm/typings/{src/types → types}/ExecutionTypes.d.ts +0 -0
- /package/esm/typings/{src/types → types}/ModelRequirements.d.ts +0 -0
- /package/esm/typings/{src/types → types}/Parameters.d.ts +0 -0
- /package/esm/typings/{src/types → types}/Prompt.d.ts +0 -0
- /package/esm/typings/{src/types → types}/PromptbookJson/KnowledgeJson.d.ts +0 -0
- /package/esm/typings/{src/types → types}/PromptbookJson/PromptTemplateJson.d.ts +0 -0
- /package/esm/typings/{src/types → types}/PromptbookJson/PromptTemplateParameterJson.d.ts +0 -0
- /package/esm/typings/{src/types → types}/PromptbookJson/PromptbookJson.d.ts +0 -0
- /package/esm/typings/{src/types → types}/PromptbookString.d.ts +0 -0
- /package/esm/typings/{src/types → types}/ScriptLanguage.d.ts +0 -0
- /package/esm/typings/{src/types → types}/TaskProgress.d.ts +0 -0
- /package/esm/typings/{src/types → types}/execution-report/ExecutionReportJson.d.ts +0 -0
- /package/esm/typings/{src/types → types}/execution-report/ExecutionReportString.d.ts +0 -0
- /package/esm/typings/{src/types → types}/execution-report/ExecutionReportStringOptions.d.ts +0 -0
- /package/esm/typings/{src/types → types}/execution-report/config.d.ts +0 -0
- /package/esm/typings/{src/types → types}/execution-report/countWorkingDuration.d.ts +0 -0
- /package/esm/typings/{src/types → types}/execution-report/countWorkingDuration.test.d.ts +0 -0
- /package/esm/typings/{src/types → types}/execution-report/executionReportJsonToString.d.ts +0 -0
- /package/esm/typings/{src/types → types}/typeAliasEmoji.d.ts +0 -0
- /package/esm/typings/{src/types → types}/typeAliases.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/FromtoItems.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/emojis.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/expectation-counters/countCharacters.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/expectation-counters/countCharacters.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/expectation-counters/countLines.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/expectation-counters/countLines.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/expectation-counters/countPages.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/expectation-counters/countPages.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/expectation-counters/countParagraphs.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/expectation-counters/countParagraphs.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/expectation-counters/countSentences.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/expectation-counters/countSentences.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/expectation-counters/countWords.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/expectation-counters/countWords.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/expectation-counters/index.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/extractParameters.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/extractParameters.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/formatNumber.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/formatNumber.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/getCurrentIsoDate.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/isRunningInWhatever.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/just.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/addAutoGeneratedSection.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/addAutoGeneratedSection.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/createMarkdownChart.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/createMarkdownChart.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/createMarkdownTable.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/createMarkdownTable.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/escapeMarkdownBlock.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/escapeMarkdownBlock.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/extractAllBlocksFromMarkdown.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/extractAllBlocksFromMarkdown.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/extractAllListItemsFromMarkdown.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/extractAllListItemsFromMarkdown.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/extractOneBlockFromMarkdown.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/extractOneBlockFromMarkdown.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/prettifyMarkdown.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/prettifyMarkdown.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/removeContentComments.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/removeContentComments.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/removeMarkdownFormatting.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown/removeMarkdownFormatting.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown-json/MarkdownStructure.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown-json/countMarkdownStructureDeepness.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown-json/countMarkdownStructureDeepness.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown-json/markdownToMarkdownStructure.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/markdown-json/markdownToMarkdownStructure.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/DIACRITIC_VARIANTS_LETTERS.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/IKeywords.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/capitalize.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/capitalize.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/decapitalize.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/decapitalize.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/isValidKeyword.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/isValidKeyword.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/nameToUriPart.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/nameToUriPart.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/nameToUriParts.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/nameToUriParts.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/normalize-to-kebab-case.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/normalize-to-kebab-case.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/normalizeTo_PascalCase.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/normalizeTo_PascalCase.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/normalizeTo_SCREAMING_CASE.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/normalizeTo_SCREAMING_CASE.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/normalizeTo_camelCase.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/normalizeTo_camelCase.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/normalizeTo_snake_case.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/normalizeTo_snake_case.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/normalizeWhitespaces.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/normalizeWhitespaces.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/parseKeywords.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/parseKeywords.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/parseKeywordsFromString.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/parseKeywordsFromString.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/removeDiacritics.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/removeDiacritics.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/searchKeywords.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/normalization/searchKeywords.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/postprocessing/extractBlock.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/removeEmojis.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/removeEmojis.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/removeQuotes.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/removeQuotes.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/sets/difference.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/sets/difference.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/sets/intersection.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/sets/intersection.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/sets/union.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/sets/union.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/trimCodeBlock.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/trimCodeBlock.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/trimEndOfCodeBlock.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/trimEndOfCodeBlock.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/unwrapResult.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/unwrapResult.test.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/validators/url/isValidUrl.d.ts +0 -0
- /package/esm/typings/{src/utils → utils}/validators/url/isValidUrl.test.d.ts +0 -0
- /package/esm/typings/{src/version.d.ts → version.d.ts} +0 -0
- /package/umd/typings/{src/_packages → _packages}/anthropic-claude.index.d.ts +0 -0
- /package/umd/typings/{src/_packages → _packages}/azure-openai.index.d.ts +0 -0
- /package/umd/typings/{src/_packages → _packages}/cli.index.d.ts +0 -0
- /package/umd/typings/{src/_packages → _packages}/execute-javascript.index.d.ts +0 -0
- /package/umd/typings/{src/_packages → _packages}/fake-llm.index.d.ts +0 -0
- /package/umd/typings/{src/_packages → _packages}/langtail.index.d.ts +0 -0
- /package/umd/typings/{src/_packages → _packages}/node.index.d.ts +0 -0
- /package/umd/typings/{src/_packages → _packages}/openai.index.d.ts +0 -0
- /package/umd/typings/{src/_packages → _packages}/remote-client.index.d.ts +0 -0
- /package/umd/typings/{src/_packages → _packages}/remote-server.index.d.ts +0 -0
- /package/umd/typings/{src/_packages → _packages}/types.index.d.ts +0 -0
- /package/umd/typings/{src/_packages → _packages}/utils.index.d.ts +0 -0
- /package/umd/typings/{src/config.d.ts → config.d.ts} +0 -0
- /package/umd/typings/{src/conversion → conversion}/prettify/PrettifyOptions.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/prettify/prettifyPromptbookString.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/prettify/prettifyPromptbookStringCli.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/prettify/renderPromptbookMermaid.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/promptbookJsonToString.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/promptbookStringToJson.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/promptbookStringToJson.test.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/utils/extractParametersFromPromptTemplate.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/utils/extractParametersFromPromptTemplate.test.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/utils/extractVariables.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/utils/extractVariables.test.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/utils/parseCommand.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/utils/parseCommand.test.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/utils/parseNumber.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/utils/parseNumber.test.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/utils/renameParameter.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/utils/renameParameter.test.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/utils/titleToName.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/utils/titleToName.test.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/validation/_importPromptbook.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/validation/promptbookStringToJson-syntaxErrors.test.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/validation/validatePromptbookJson-logicErrors.test.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/validation/validatePromptbookJson.d.ts +0 -0
- /package/umd/typings/{src/conversion → conversion}/validation/validatePromptbookJson.test.d.ts +0 -0
- /package/umd/typings/{src/errors → errors}/PromptbookExecutionError.d.ts +0 -0
- /package/umd/typings/{src/errors → errors}/PromptbookLibraryError.d.ts +0 -0
- /package/umd/typings/{src/errors → errors}/PromptbookLogicError.d.ts +0 -0
- /package/umd/typings/{src/errors → errors}/PromptbookNotFoundError.d.ts +0 -0
- /package/umd/typings/{src/errors → errors}/PromptbookReferenceError.d.ts +0 -0
- /package/umd/typings/{src/errors → errors}/PromptbookSyntaxError.d.ts +0 -0
- /package/umd/typings/{src/errors → errors}/TemplateError.d.ts +0 -0
- /package/umd/typings/{src/errors → errors}/UnexpectedError.d.ts +0 -0
- /package/umd/typings/{src/errors → errors}/_ExpectError.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/CommonExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/ExecutionTools.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/LlmExecutionTools.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/PromptResult.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/PromptbookExecutor.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/ScriptExecutionTools.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/UserInterfaceTools.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/addPromptResultUsage.test.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/assertsExecutionSuccessful.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/createPromptbookExecutor.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.test.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/translation/automatic-translate/translateMessages.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/utils/addUsage.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/utils/addUsage.test.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/utils/checkExpectations.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/utils/checkExpectations.test.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/utils/computeUsageCounts.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/utils/forEachAsync.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/utils/replaceParameters.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/utils/replaceParameters.test.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/utils/uncertainNumber.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/utils/usageToWorktime.d.ts +0 -0
- /package/umd/typings/{src/execution → execution}/utils/usageToWorktime.test.d.ts +0 -0
- /package/umd/typings/{src/expectations → expectations}/drafts/isDomainNameFree.d.ts +0 -0
- /package/umd/typings/{src/expectations → expectations}/drafts/isGithubNameFree.d.ts +0 -0
- /package/umd/typings/{src/formats → formats}/_common/FormatDefinition.d.ts +0 -0
- /package/umd/typings/{src/formats → formats}/csv/ListFormatDefinition.d.ts +0 -0
- /package/umd/typings/{src/formats → formats}/index.d.ts +0 -0
- /package/umd/typings/{src/formats → formats}/json/JsonFormatDefinition.d.ts +0 -0
- /package/umd/typings/{src/formats → formats}/json/utils/isValidJsonString.d.ts +0 -0
- /package/umd/typings/{src/formats → formats}/json/utils/isValidJsonString.test.d.ts +0 -0
- /package/umd/typings/{src/formats → formats}/list/ListFormatDefinition.d.ts +0 -0
- /package/umd/typings/{src/formats → formats}/xml/XmlFormatDefinition.d.ts +0 -0
- /package/umd/typings/{src/knowledge → knowledge}/dialogs/callback/CallbackInterfaceTools.d.ts +0 -0
- /package/umd/typings/{src/knowledge → knowledge}/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +0 -0
- /package/umd/typings/{src/knowledge → knowledge}/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +0 -0
- /package/umd/typings/{src/knowledge → knowledge}/dialogs/user-interface-execution-tools.test.d.ts +0 -0
- /package/umd/typings/{src/knowledge → knowledge}/prepare-knowledge/_common/IndexPreparer.d.ts +0 -0
- /package/umd/typings/{src/knowledge → knowledge}/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts +0 -0
- /package/umd/typings/{src/knowledge → knowledge}/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +0 -0
- /package/umd/typings/{src/knowledge → knowledge}/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +0 -0
- /package/umd/typings/{src/knowledge → knowledge}/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/anthropic-claude/anthropic-claude-models.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/anthropic-claude/playground/playground.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/azure-openai/AzureOpenAiExecutionTools.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/azure-openai/playground/playground.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/langtail/LangtailExecutionTools.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/langtail/LangtailExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/langtail/playground/playground.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/mocked/fakeTextToExpectations.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/mocked/fakeTextToExpectations.test.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/mocked/faked-completion.test.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/mocked/joker.test.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/mocked/mocked-chat.test.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/mocked/mocked-completion.test.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/multiple/MultipleLlmExecutionTools.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/multiple/MultipleLlmExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/multiple/playground/playground.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/openai/OpenAiExecutionTools.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/openai/OpenAiExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/openai/computeOpenaiUsage.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/openai/computeUsage.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/openai/computeUsage.test.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/openai/openai-models.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/openai/playground/playground.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/remote/RemoteLlmExecutionTools.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/remote/RemoteLlmExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/remote/interfaces/Promptbook_Server_Error.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/remote/interfaces/Promptbook_Server_Progress.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/remote/interfaces/Promptbook_Server_Request.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/remote/interfaces/Promptbook_Server_Response.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/remote/interfaces/RemoteServerOptions.d.ts +0 -0
- /package/umd/typings/{src/llm-providers → llm-providers}/remote/startRemoteServer.d.ts +0 -0
- /package/umd/typings/{src/promptbook-library → promptbook-library}/PromptbookLibrary.d.ts +0 -0
- /package/umd/typings/{src/promptbook-library → promptbook-library}/SimplePromptbookLibrary.d.ts +0 -0
- /package/umd/typings/{src/promptbook-library → promptbook-library}/constructors/createPromptbookLibraryFromDirectory.d.ts +0 -0
- /package/umd/typings/{src/promptbook-library → promptbook-library}/constructors/createPromptbookLibraryFromDirectory.test.d.ts +0 -0
- /package/umd/typings/{src/promptbook-library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.d.ts +0 -0
- /package/umd/typings/{src/promptbook-library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.test.d.ts +0 -0
- /package/umd/typings/{src/promptbook-library → promptbook-library}/constructors/createPromptbookLibraryFromSources.d.ts +0 -0
- /package/umd/typings/{src/promptbook-library → promptbook-library}/constructors/createPromptbookLibraryFromSources.test.d.ts +0 -0
- /package/umd/typings/{src/promptbook-library → promptbook-library}/constructors/createPromptbookLibraryFromUrl.d.ts +0 -0
- /package/umd/typings/{src/promptbook-library → promptbook-library}/constructors/createPromptbookSublibrary.d.ts +0 -0
- /package/umd/typings/{src/promptbook-library → promptbook-library}/constructors/justTestFsImport.d.ts +0 -0
- /package/umd/typings/{src/scripting → scripting}/_test/custom-function-async.test.ts.test.d.ts +0 -0
- /package/umd/typings/{src/scripting → scripting}/_test/custom-function-missing.test.d.ts +0 -0
- /package/umd/typings/{src/scripting → scripting}/_test/custom-function-with-dependencies.test.d.ts +0 -0
- /package/umd/typings/{src/scripting → scripting}/_test/custom-function.test.d.ts +0 -0
- /package/umd/typings/{src/scripting → scripting}/_test/postprocessing.test.d.ts +0 -0
- /package/umd/typings/{src/scripting → scripting}/_test/script-execution-errors.test.d.ts +0 -0
- /package/umd/typings/{src/scripting → scripting}/_test/script-execution-tools.test.d.ts +0 -0
- /package/umd/typings/{src/scripting → scripting}/javascript/JavascriptEvalExecutionTools.d.ts +0 -0
- /package/umd/typings/{src/scripting → scripting}/javascript/JavascriptEvalExecutionTools.test.d.ts +0 -0
- /package/umd/typings/{src/scripting → scripting}/javascript/JavascriptExecutionTools.d.ts +0 -0
- /package/umd/typings/{src/scripting → scripting}/javascript/JavascriptExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{src/scripting → scripting}/javascript/utils/preserve.d.ts +0 -0
- /package/umd/typings/{src/scripting → scripting}/javascript/utils/unknownToString.d.ts +0 -0
- /package/umd/typings/{src/scripting → scripting}/python/PythonExecutionTools.d.ts +0 -0
- /package/umd/typings/{src/scripting → scripting}/typescript/TypescriptExecutionTools.d.ts +0 -0
- /package/umd/typings/{src/types → types}/Command.d.ts +0 -0
- /package/umd/typings/{src/types → types}/ExecutionTypes.d.ts +0 -0
- /package/umd/typings/{src/types → types}/ModelRequirements.d.ts +0 -0
- /package/umd/typings/{src/types → types}/Parameters.d.ts +0 -0
- /package/umd/typings/{src/types → types}/Prompt.d.ts +0 -0
- /package/umd/typings/{src/types → types}/PromptbookJson/KnowledgeJson.d.ts +0 -0
- /package/umd/typings/{src/types → types}/PromptbookJson/PromptTemplateJson.d.ts +0 -0
- /package/umd/typings/{src/types → types}/PromptbookJson/PromptTemplateParameterJson.d.ts +0 -0
- /package/umd/typings/{src/types → types}/PromptbookJson/PromptbookJson.d.ts +0 -0
- /package/umd/typings/{src/types → types}/PromptbookString.d.ts +0 -0
- /package/umd/typings/{src/types → types}/ScriptLanguage.d.ts +0 -0
- /package/umd/typings/{src/types → types}/TaskProgress.d.ts +0 -0
- /package/umd/typings/{src/types → types}/execution-report/ExecutionReportJson.d.ts +0 -0
- /package/umd/typings/{src/types → types}/execution-report/ExecutionReportString.d.ts +0 -0
- /package/umd/typings/{src/types → types}/execution-report/ExecutionReportStringOptions.d.ts +0 -0
- /package/umd/typings/{src/types → types}/execution-report/config.d.ts +0 -0
- /package/umd/typings/{src/types → types}/execution-report/countWorkingDuration.d.ts +0 -0
- /package/umd/typings/{src/types → types}/execution-report/countWorkingDuration.test.d.ts +0 -0
- /package/umd/typings/{src/types → types}/execution-report/executionReportJsonToString.d.ts +0 -0
- /package/umd/typings/{src/types → types}/typeAliasEmoji.d.ts +0 -0
- /package/umd/typings/{src/types → types}/typeAliases.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/FromtoItems.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/emojis.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/expectation-counters/countCharacters.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/expectation-counters/countCharacters.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/expectation-counters/countLines.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/expectation-counters/countLines.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/expectation-counters/countPages.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/expectation-counters/countPages.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/expectation-counters/countParagraphs.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/expectation-counters/countParagraphs.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/expectation-counters/countSentences.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/expectation-counters/countSentences.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/expectation-counters/countWords.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/expectation-counters/countWords.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/expectation-counters/index.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/extractParameters.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/extractParameters.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/formatNumber.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/formatNumber.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/getCurrentIsoDate.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/isRunningInWhatever.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/just.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/addAutoGeneratedSection.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/addAutoGeneratedSection.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/createMarkdownChart.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/createMarkdownChart.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/createMarkdownTable.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/createMarkdownTable.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/escapeMarkdownBlock.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/escapeMarkdownBlock.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/extractAllBlocksFromMarkdown.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/extractAllBlocksFromMarkdown.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/extractAllListItemsFromMarkdown.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/extractAllListItemsFromMarkdown.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/extractOneBlockFromMarkdown.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/extractOneBlockFromMarkdown.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/prettifyMarkdown.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/prettifyMarkdown.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/removeContentComments.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/removeContentComments.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/removeMarkdownFormatting.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown/removeMarkdownFormatting.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown-json/MarkdownStructure.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown-json/countMarkdownStructureDeepness.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown-json/countMarkdownStructureDeepness.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown-json/markdownToMarkdownStructure.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/markdown-json/markdownToMarkdownStructure.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/DIACRITIC_VARIANTS_LETTERS.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/IKeywords.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/capitalize.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/capitalize.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/decapitalize.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/decapitalize.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/isValidKeyword.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/isValidKeyword.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/nameToUriPart.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/nameToUriPart.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/nameToUriParts.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/nameToUriParts.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/normalize-to-kebab-case.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/normalize-to-kebab-case.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/normalizeTo_PascalCase.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/normalizeTo_PascalCase.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/normalizeTo_SCREAMING_CASE.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/normalizeTo_SCREAMING_CASE.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/normalizeTo_camelCase.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/normalizeTo_camelCase.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/normalizeTo_snake_case.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/normalizeTo_snake_case.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/normalizeWhitespaces.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/normalizeWhitespaces.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/parseKeywords.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/parseKeywords.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/parseKeywordsFromString.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/parseKeywordsFromString.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/removeDiacritics.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/removeDiacritics.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/searchKeywords.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/normalization/searchKeywords.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/postprocessing/extractBlock.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/removeEmojis.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/removeEmojis.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/removeQuotes.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/removeQuotes.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/sets/difference.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/sets/difference.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/sets/intersection.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/sets/intersection.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/sets/union.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/sets/union.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/trimCodeBlock.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/trimCodeBlock.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/trimEndOfCodeBlock.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/trimEndOfCodeBlock.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/unwrapResult.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/unwrapResult.test.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/validators/url/isValidUrl.d.ts +0 -0
- /package/umd/typings/{src/utils → utils}/validators/url/isValidUrl.test.d.ts +0 -0
- /package/umd/typings/{src/version.d.ts → 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
|
|
5
|
+
import { 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.59.0-
|
|
145
|
+
var PROMPTBOOK_VERSION = '0.59.0-2';
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
148
|
* Removes HTML or Markdown comments from a string.
|
|
@@ -221,66 +221,49 @@ var PromptbookSyntaxError = /** @class */ (function (_super) {
|
|
|
221
221
|
return PromptbookSyntaxError;
|
|
222
222
|
}(Error));
|
|
223
223
|
|
|
224
|
-
|
|
224
|
+
// import prepareKnowledgeFromMarkdownStringPromptbook from './prepare-knowledge-from-markdown.ptbk.md';
|
|
225
|
+
function prepareKnowledgeFromMarkdown(options) {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
227
|
+
return __generator(this, function (_a) {
|
|
228
|
+
return [2 /*return*/, []];
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
225
232
|
|
|
226
233
|
/**
|
|
227
|
-
*
|
|
234
|
+
* Supported script languages
|
|
228
235
|
*/
|
|
229
|
-
var
|
|
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));
|
|
236
|
+
var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
239
237
|
|
|
240
238
|
/**
|
|
241
|
-
*
|
|
239
|
+
* Computes the deepness of the markdown structure.
|
|
242
240
|
*
|
|
243
|
-
* @
|
|
244
|
-
* @throws {PromptbookExecutionError} If the execution is not successful or if multiple errors occurred
|
|
241
|
+
* @private within the library
|
|
245
242
|
*/
|
|
246
|
-
function
|
|
247
|
-
var
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
else if (errors.length === 1) {
|
|
255
|
-
throw errors[0];
|
|
243
|
+
function countMarkdownStructureDeepness(markdownStructure) {
|
|
244
|
+
var e_1, _a;
|
|
245
|
+
var maxDeepness = 0;
|
|
246
|
+
try {
|
|
247
|
+
for (var _b = __values(markdownStructure.sections), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
248
|
+
var section = _c.value;
|
|
249
|
+
maxDeepness = Math.max(maxDeepness, countMarkdownStructureDeepness(section));
|
|
250
|
+
}
|
|
256
251
|
}
|
|
257
|
-
|
|
258
|
-
|
|
252
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
253
|
+
finally {
|
|
254
|
+
try {
|
|
255
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
256
|
+
}
|
|
257
|
+
finally { if (e_1) throw e_1.error; }
|
|
259
258
|
}
|
|
259
|
+
return maxDeepness + 1;
|
|
260
260
|
}
|
|
261
|
-
/**
|
|
262
|
-
* TODO: [🧠] Can this return type be better typed than void
|
|
263
|
-
*/
|
|
264
261
|
|
|
265
262
|
/**
|
|
266
263
|
* The maximum number of iterations for a loops
|
|
267
264
|
*/
|
|
268
265
|
var LOOP_LIMIT = 1000;
|
|
269
266
|
|
|
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
|
-
|
|
284
267
|
/**
|
|
285
268
|
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
286
269
|
*/
|
|
@@ -296,2619 +279,1096 @@ var UnexpectedError = /** @class */ (function (_super) {
|
|
|
296
279
|
}(Error));
|
|
297
280
|
|
|
298
281
|
/**
|
|
299
|
-
*
|
|
282
|
+
* Parse a markdown string into a MarkdownStructure object.
|
|
283
|
+
*
|
|
284
|
+
* Note: This function does work with code blocks
|
|
285
|
+
* Note: This function does not work with markdown comments
|
|
286
|
+
*
|
|
287
|
+
* @param markdown The markdown string to parse.
|
|
288
|
+
* @returns The MarkdownStructure object.
|
|
300
289
|
*
|
|
301
|
-
*
|
|
290
|
+
* @private within the library
|
|
302
291
|
*/
|
|
303
|
-
function
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
292
|
+
function markdownToMarkdownStructure(markdown) {
|
|
293
|
+
var e_1, _a;
|
|
294
|
+
var lines = markdown.split('\n');
|
|
295
|
+
var root = { level: 0, title: '', contentLines: [], sections: [], parent: null };
|
|
296
|
+
var current = root;
|
|
297
|
+
var isInsideCodeBlock = false;
|
|
307
298
|
try {
|
|
308
|
-
|
|
309
|
-
|
|
299
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
300
|
+
var line = lines_1_1.value;
|
|
301
|
+
var headingMatch = line.match(/^(?<mark>#{1,6})\s(?<title>.*)/);
|
|
302
|
+
if (isInsideCodeBlock || !headingMatch) {
|
|
303
|
+
if (line.startsWith('```')) {
|
|
304
|
+
isInsideCodeBlock = !isInsideCodeBlock;
|
|
305
|
+
}
|
|
306
|
+
current.contentLines.push(line);
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
var level = headingMatch.groups.mark.length;
|
|
310
|
+
var title = headingMatch.groups.title.trim();
|
|
311
|
+
var parent_1 = void 0;
|
|
312
|
+
if (level > current.level) {
|
|
313
|
+
// Note: Going deeper (next section is child of current)
|
|
314
|
+
parent_1 = current;
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
// Note: Going up or staying at the same level (next section is sibling or parent or grandparent,... of current)
|
|
318
|
+
parent_1 = current;
|
|
319
|
+
var loopLimit = LOOP_LIMIT;
|
|
320
|
+
while (parent_1.level !== level - 1) {
|
|
321
|
+
if (loopLimit-- < 0) {
|
|
322
|
+
throw new UnexpectedError('Loop limit reached during parsing of markdown structure in `markdownToMarkdownStructure`');
|
|
323
|
+
}
|
|
324
|
+
if (parent_1.parent === null /* <- Note: We are in root */) {
|
|
325
|
+
// [🌻]
|
|
326
|
+
throw new Error(spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
|
|
327
|
+
}
|
|
328
|
+
parent_1 = parent_1.parent;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
var section = { level: level, title: title, contentLines: [], sections: [], parent: parent_1 };
|
|
332
|
+
parent_1.sections.push(section);
|
|
333
|
+
current = section;
|
|
334
|
+
}
|
|
310
335
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
336
|
+
}
|
|
337
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
338
|
+
finally {
|
|
339
|
+
try {
|
|
340
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
315
341
|
}
|
|
316
|
-
|
|
342
|
+
finally { if (e_1) throw e_1.error; }
|
|
317
343
|
}
|
|
318
|
-
|
|
319
|
-
|
|
344
|
+
if (root.sections.length === 1) {
|
|
345
|
+
var markdownStructure = parsingMarkdownStructureToMarkdownStructure(root.sections[0]);
|
|
346
|
+
return markdownStructure;
|
|
320
347
|
}
|
|
348
|
+
// [🌻]
|
|
349
|
+
throw new Error('The markdown file must have exactly one top-level section.');
|
|
350
|
+
// return root;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* @private
|
|
354
|
+
*/
|
|
355
|
+
function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
|
|
356
|
+
var level = parsingMarkdownStructure.level, title = parsingMarkdownStructure.title, contentLines = parsingMarkdownStructure.contentLines, sections = parsingMarkdownStructure.sections;
|
|
357
|
+
return {
|
|
358
|
+
level: level,
|
|
359
|
+
title: title,
|
|
360
|
+
content: spaceTrim(contentLines.join('\n')),
|
|
361
|
+
sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
|
|
362
|
+
};
|
|
321
363
|
}
|
|
322
364
|
|
|
323
365
|
/**
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
* It checks:
|
|
327
|
-
* - if it has correct parameters dependency
|
|
366
|
+
* Utility function to extract all list items from markdown
|
|
328
367
|
*
|
|
329
|
-
* It
|
|
330
|
-
*
|
|
331
|
-
*
|
|
368
|
+
* Note: It works with both ul and ol
|
|
369
|
+
* Note: It omits list items in code blocks
|
|
370
|
+
* Note: It flattens nested lists
|
|
371
|
+
* Note: It can not work with html syntax and comments
|
|
332
372
|
*
|
|
333
|
-
* @param
|
|
334
|
-
* @returns
|
|
335
|
-
* @throws {PromptbookLogicError} on logical error in the promptbook
|
|
373
|
+
* @param markdown any valid markdown
|
|
374
|
+
* @returns
|
|
336
375
|
*/
|
|
337
|
-
function
|
|
338
|
-
|
|
339
|
-
var
|
|
340
|
-
|
|
341
|
-
|
|
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
|
-
};
|
|
376
|
+
function extractAllListItemsFromMarkdown(markdown) {
|
|
377
|
+
var e_1, _a;
|
|
378
|
+
var lines = markdown.split('\n');
|
|
379
|
+
var listItems = [];
|
|
380
|
+
var isInCodeBlock = false;
|
|
372
381
|
try {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
var
|
|
376
|
-
|
|
382
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
383
|
+
var line = lines_1_1.value;
|
|
384
|
+
var trimmedLine = line.trim();
|
|
385
|
+
if (trimmedLine.startsWith('```')) {
|
|
386
|
+
isInCodeBlock = !isInCodeBlock;
|
|
387
|
+
}
|
|
388
|
+
if (!isInCodeBlock && (trimmedLine.startsWith('-') || trimmedLine.match(/^\d+\./))) {
|
|
389
|
+
var listItem = trimmedLine.replace(/^-|\d+\./, '').trim();
|
|
390
|
+
listItems.push(listItem);
|
|
391
|
+
}
|
|
377
392
|
}
|
|
378
393
|
}
|
|
379
394
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
380
395
|
finally {
|
|
381
396
|
try {
|
|
382
|
-
if (
|
|
397
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
383
398
|
}
|
|
384
399
|
finally { if (e_1) throw e_1.error; }
|
|
385
400
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
401
|
+
return listItems;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Makes first letter of a string uppercase
|
|
406
|
+
*
|
|
407
|
+
*/
|
|
408
|
+
function capitalize(word) {
|
|
409
|
+
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Extracts all code blocks from markdown.
|
|
414
|
+
*
|
|
415
|
+
* Note: There are 3 simmilar function:
|
|
416
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
417
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
418
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
419
|
+
*
|
|
420
|
+
* @param markdown any valid markdown
|
|
421
|
+
* @returns code blocks with language and content
|
|
422
|
+
*
|
|
423
|
+
*/
|
|
424
|
+
function extractAllBlocksFromMarkdown(markdown) {
|
|
425
|
+
var e_1, _a;
|
|
426
|
+
var codeBlocks = [];
|
|
427
|
+
var lines = markdown.split('\n');
|
|
428
|
+
var currentCodeBlock = null;
|
|
394
429
|
try {
|
|
395
|
-
for (var
|
|
396
|
-
var
|
|
397
|
-
if (
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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"));
|
|
409
|
-
}
|
|
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
|
-
}
|
|
416
|
-
}
|
|
430
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
431
|
+
var line = lines_1_1.value;
|
|
432
|
+
if (line.startsWith('```')) {
|
|
433
|
+
var language = line.slice(3).trim() || null;
|
|
434
|
+
if (currentCodeBlock === null) {
|
|
435
|
+
currentCodeBlock = { language: language, content: '' };
|
|
417
436
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
437
|
+
else {
|
|
438
|
+
if (language !== null) {
|
|
439
|
+
// [🌻]
|
|
440
|
+
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
422
441
|
}
|
|
423
|
-
|
|
442
|
+
codeBlocks.push(currentCodeBlock);
|
|
443
|
+
currentCodeBlock = null;
|
|
424
444
|
}
|
|
425
445
|
}
|
|
426
|
-
if (
|
|
427
|
-
|
|
428
|
-
|
|
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; }
|
|
446
|
+
else if (currentCodeBlock !== null) {
|
|
447
|
+
if (currentCodeBlock.content !== '') {
|
|
448
|
+
currentCodeBlock.content += '\n';
|
|
447
449
|
}
|
|
450
|
+
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
448
451
|
}
|
|
449
452
|
}
|
|
450
453
|
}
|
|
451
|
-
catch (
|
|
454
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
452
455
|
finally {
|
|
453
456
|
try {
|
|
454
|
-
if (
|
|
457
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
455
458
|
}
|
|
456
|
-
finally { if (
|
|
459
|
+
finally { if (e_1) throw e_1.error; }
|
|
457
460
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
.
|
|
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();
|
|
461
|
+
if (currentCodeBlock !== null) {
|
|
462
|
+
// [🌻]
|
|
463
|
+
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
495
464
|
}
|
|
496
|
-
return
|
|
465
|
+
return codeBlocks;
|
|
497
466
|
}
|
|
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
|
-
*/
|
|
509
467
|
|
|
510
468
|
/**
|
|
511
|
-
*
|
|
469
|
+
* Extracts exactly ONE code block from markdown.
|
|
470
|
+
*
|
|
471
|
+
* Note: If there are multiple or no code blocks the function throws an error
|
|
512
472
|
*
|
|
513
|
-
*
|
|
514
|
-
*
|
|
473
|
+
* Note: There are 3 simmilar function:
|
|
474
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
475
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
476
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
477
|
+
*
|
|
478
|
+
* @param markdown any valid markdown
|
|
479
|
+
* @returns code block with language and content
|
|
515
480
|
*/
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
Object.setPrototypeOf(_this, ExpectError.prototype);
|
|
522
|
-
return _this;
|
|
481
|
+
function extractOneBlockFromMarkdown(markdown) {
|
|
482
|
+
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
483
|
+
if (codeBlocks.length !== 1) {
|
|
484
|
+
// TODO: Report more specific place where the error happened
|
|
485
|
+
throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
|
|
523
486
|
}
|
|
524
|
-
return
|
|
525
|
-
}
|
|
487
|
+
return codeBlocks[0];
|
|
488
|
+
}
|
|
489
|
+
/***
|
|
490
|
+
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
491
|
+
*/
|
|
526
492
|
|
|
527
493
|
/**
|
|
528
|
-
*
|
|
494
|
+
* Creates a new set with all elements that are present in either set
|
|
529
495
|
*/
|
|
530
|
-
function
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
496
|
+
function union() {
|
|
497
|
+
var e_1, _a, e_2, _b;
|
|
498
|
+
var sets = [];
|
|
499
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
500
|
+
sets[_i] = arguments[_i];
|
|
501
|
+
}
|
|
502
|
+
var union = new Set();
|
|
503
|
+
try {
|
|
504
|
+
for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
|
|
505
|
+
var set = sets_1_1.value;
|
|
506
|
+
try {
|
|
507
|
+
for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
508
|
+
var item = _d.value;
|
|
509
|
+
union.add(item);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
513
|
+
finally {
|
|
514
|
+
try {
|
|
515
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
516
|
+
}
|
|
517
|
+
finally { if (e_2) throw e_2.error; }
|
|
518
|
+
}
|
|
538
519
|
}
|
|
539
|
-
|
|
540
|
-
|
|
520
|
+
}
|
|
521
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
522
|
+
finally {
|
|
523
|
+
try {
|
|
524
|
+
if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
|
|
541
525
|
}
|
|
542
|
-
|
|
526
|
+
finally { if (e_1) throw e_1.error; }
|
|
543
527
|
}
|
|
528
|
+
return union;
|
|
544
529
|
}
|
|
545
530
|
|
|
546
531
|
/**
|
|
547
|
-
*
|
|
532
|
+
* Parses the template and returns the list of all parameter names
|
|
548
533
|
*
|
|
549
|
-
*
|
|
534
|
+
* @param template the template with parameters in {curly} braces
|
|
535
|
+
* @returns the list of parameter names
|
|
550
536
|
*/
|
|
551
|
-
function
|
|
552
|
-
var
|
|
553
|
-
|
|
554
|
-
|
|
537
|
+
function extractParameters(template) {
|
|
538
|
+
var e_1, _a;
|
|
539
|
+
var matches = template.matchAll(/{\w+}/g);
|
|
540
|
+
var parameterNames = new Set();
|
|
541
|
+
try {
|
|
542
|
+
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
543
|
+
var match = matches_1_1.value;
|
|
544
|
+
var parameterName = match[0].slice(1, -1);
|
|
545
|
+
parameterNames.add(parameterName);
|
|
546
|
+
}
|
|
555
547
|
}
|
|
556
|
-
|
|
557
|
-
|
|
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;
|
|
548
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
549
|
+
finally {
|
|
581
550
|
try {
|
|
582
|
-
|
|
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
|
-
}
|
|
551
|
+
if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
|
|
599
552
|
}
|
|
600
|
-
|
|
601
|
-
|
|
553
|
+
finally { if (e_1) throw e_1.error; }
|
|
554
|
+
}
|
|
555
|
+
return parameterNames;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
560
|
+
*
|
|
561
|
+
* @param script from which to extract the variables
|
|
562
|
+
* @returns the list of variable names
|
|
563
|
+
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
564
|
+
*/
|
|
565
|
+
function extractVariables(script) {
|
|
566
|
+
var variables = new Set();
|
|
567
|
+
script = "(()=>{".concat(script, "})()");
|
|
568
|
+
try {
|
|
569
|
+
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
602
570
|
try {
|
|
603
|
-
|
|
571
|
+
eval(script);
|
|
572
|
+
}
|
|
573
|
+
catch (error) {
|
|
574
|
+
if (!(error instanceof ReferenceError)) {
|
|
575
|
+
throw error;
|
|
576
|
+
}
|
|
577
|
+
var undefinedName = error.message.split(' ')[0];
|
|
578
|
+
/*
|
|
579
|
+
Note: Remapping error
|
|
580
|
+
From: [ReferenceError: thing is not defined],
|
|
581
|
+
To: [Error: Parameter {thing} is not defined],
|
|
582
|
+
*/
|
|
583
|
+
if (!undefinedName) {
|
|
584
|
+
throw error;
|
|
585
|
+
}
|
|
586
|
+
if (script.includes(undefinedName + '(')) {
|
|
587
|
+
script = "const ".concat(undefinedName, " = ()=>'';") + script;
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
variables.add(undefinedName);
|
|
591
|
+
script = "const ".concat(undefinedName, " = '';") + script;
|
|
592
|
+
}
|
|
604
593
|
}
|
|
605
|
-
|
|
594
|
+
}
|
|
595
|
+
catch (error) {
|
|
596
|
+
if (!(error instanceof Error)) {
|
|
597
|
+
throw error;
|
|
598
|
+
}
|
|
599
|
+
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 "); }));
|
|
600
|
+
}
|
|
601
|
+
return variables;
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
605
|
+
*/
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Parses the prompt template and returns the set of all used parameters
|
|
609
|
+
*
|
|
610
|
+
* @param promptTemplate the template with used parameters
|
|
611
|
+
* @returns the set of parameter names
|
|
612
|
+
* @throws {PromptbookSyntaxError} if the script is invalid
|
|
613
|
+
*/
|
|
614
|
+
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
615
|
+
var e_1, _a, e_2, _b;
|
|
616
|
+
var parameterNames = new Set();
|
|
617
|
+
try {
|
|
618
|
+
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()) {
|
|
619
|
+
var parameterName = _d.value;
|
|
620
|
+
parameterNames.add(parameterName);
|
|
606
621
|
}
|
|
622
|
+
}
|
|
623
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
624
|
+
finally {
|
|
607
625
|
try {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
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
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
627
|
+
}
|
|
628
|
+
finally { if (e_1) throw e_1.error; }
|
|
629
|
+
}
|
|
630
|
+
if (promptTemplate.executionType === 'SCRIPT') {
|
|
631
|
+
try {
|
|
632
|
+
for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
633
|
+
var parameterName = _f.value;
|
|
634
|
+
parameterNames.add(parameterName);
|
|
624
635
|
}
|
|
625
636
|
}
|
|
626
637
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
627
638
|
finally {
|
|
628
639
|
try {
|
|
629
|
-
if (
|
|
640
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
630
641
|
}
|
|
631
642
|
finally { if (e_2) throw e_2.error; }
|
|
632
643
|
}
|
|
633
|
-
|
|
634
|
-
|
|
644
|
+
}
|
|
645
|
+
return parameterNames;
|
|
635
646
|
}
|
|
636
|
-
|
|
637
647
|
/**
|
|
638
|
-
*
|
|
648
|
+
* TODO: [🔣] If script require contentLanguage
|
|
639
649
|
*/
|
|
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
|
-
}
|
|
649
650
|
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
651
|
+
/* tslint:disable */
|
|
652
|
+
/*
|
|
653
|
+
TODO: Tests
|
|
654
|
+
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
655
|
+
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
656
|
+
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
657
|
+
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
658
|
+
*/
|
|
659
|
+
function normalizeTo_SCREAMING_CASE(sentence) {
|
|
660
|
+
var e_1, _a;
|
|
661
|
+
var charType;
|
|
662
|
+
var lastCharType = 'OTHER';
|
|
663
|
+
var normalizedName = '';
|
|
664
|
+
try {
|
|
665
|
+
for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
|
|
666
|
+
var char = sentence_1_1.value;
|
|
667
|
+
var normalizedChar = void 0;
|
|
668
|
+
if (/^[a-z]$/.test(char)) {
|
|
669
|
+
charType = 'LOWERCASE';
|
|
670
|
+
normalizedChar = char.toUpperCase();
|
|
671
|
+
}
|
|
672
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
673
|
+
charType = 'UPPERCASE';
|
|
674
|
+
normalizedChar = char;
|
|
675
|
+
}
|
|
676
|
+
else if (/^[0-9]$/.test(char)) {
|
|
677
|
+
charType = 'NUMBER';
|
|
678
|
+
normalizedChar = char;
|
|
679
|
+
}
|
|
680
|
+
else if (/^\/$/.test(char)) {
|
|
681
|
+
charType = 'SLASH';
|
|
682
|
+
normalizedChar = char;
|
|
683
|
+
}
|
|
684
|
+
else {
|
|
685
|
+
charType = 'OTHER';
|
|
686
|
+
normalizedChar = '_';
|
|
687
|
+
}
|
|
688
|
+
if (charType !== lastCharType &&
|
|
689
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
690
|
+
!(lastCharType === 'NUMBER') &&
|
|
691
|
+
!(charType === 'NUMBER')) {
|
|
692
|
+
normalizedName += '_';
|
|
693
|
+
}
|
|
694
|
+
normalizedName += normalizedChar;
|
|
695
|
+
lastCharType = charType;
|
|
696
|
+
}
|
|
656
697
|
}
|
|
657
|
-
|
|
698
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
699
|
+
finally {
|
|
700
|
+
try {
|
|
701
|
+
if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
|
|
702
|
+
}
|
|
703
|
+
finally { if (e_1) throw e_1.error; }
|
|
704
|
+
}
|
|
705
|
+
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
706
|
+
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
707
|
+
normalizedName = normalizedName.replace(/^_/, '');
|
|
708
|
+
normalizedName = normalizedName.replace(/_$/, '');
|
|
709
|
+
return normalizedName;
|
|
658
710
|
}
|
|
659
|
-
|
|
660
711
|
/**
|
|
661
|
-
*
|
|
712
|
+
* TODO: [🌺] Use some intermediate util splitWords
|
|
662
713
|
*/
|
|
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
714
|
|
|
670
715
|
/**
|
|
671
|
-
*
|
|
716
|
+
* Execution type describes the way how the block is executed
|
|
717
|
+
*
|
|
718
|
+
* @see https://github.com/webgptorg/promptbook#execution-type
|
|
672
719
|
*/
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
720
|
+
var ExecutionTypes = [
|
|
721
|
+
'PROMPT_TEMPLATE',
|
|
722
|
+
'SIMPLE_TEMPLATE',
|
|
723
|
+
'SCRIPT',
|
|
724
|
+
'PROMPT_DIALOG',
|
|
725
|
+
// <- [🥻] Insert here when making new command
|
|
726
|
+
];
|
|
676
727
|
|
|
677
728
|
/**
|
|
678
|
-
*
|
|
729
|
+
* Units of text measurement
|
|
679
730
|
*/
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
731
|
+
var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPHS', 'PAGES'];
|
|
732
|
+
/**
|
|
733
|
+
* TODO: [💝] Unite object for expecting amount and format - remove expectFormat
|
|
734
|
+
* TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
|
|
735
|
+
* TODO: [👙][🧠] Just selecting gpt3 or gpt4 level of model
|
|
736
|
+
*/
|
|
737
|
+
|
|
683
738
|
/**
|
|
684
|
-
*
|
|
739
|
+
* Removes Markdown formatting tags from a string.
|
|
740
|
+
*
|
|
741
|
+
* @param {string} str - The string to remove Markdown tags from.
|
|
742
|
+
* @returns {string} The input string with all Markdown tags removed.
|
|
685
743
|
*/
|
|
686
|
-
function
|
|
687
|
-
|
|
744
|
+
function removeMarkdownFormatting(str) {
|
|
745
|
+
// Remove bold formatting
|
|
746
|
+
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
747
|
+
// Remove italic formatting
|
|
748
|
+
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
749
|
+
// Remove code formatting
|
|
750
|
+
str = str.replace(/`(.*?)`/g, '$1');
|
|
751
|
+
return str;
|
|
688
752
|
}
|
|
689
753
|
|
|
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;
|
|
914
|
-
}
|
|
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
754
|
/**
|
|
755
|
+
* Function parseNumber will parse number from string
|
|
933
756
|
*
|
|
934
|
-
|
|
935
|
-
|
|
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
|
|
757
|
+
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
758
|
+
* Note: it also works only with decimal numbers
|
|
965
759
|
*
|
|
966
|
-
*
|
|
967
|
-
*
|
|
968
|
-
* - `isPassingExpectations` which returns a boolean
|
|
760
|
+
* @returns parsed number
|
|
761
|
+
* @throws {PromptbookSyntaxError} if the value is not a number
|
|
969
762
|
*
|
|
970
|
-
* @
|
|
971
|
-
* @returns {void} Nothing
|
|
763
|
+
* @private within the parseCommand
|
|
972
764
|
*/
|
|
973
|
-
function
|
|
974
|
-
var
|
|
975
|
-
|
|
976
|
-
|
|
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
|
-
}
|
|
765
|
+
function parseNumber(value) {
|
|
766
|
+
var originalValue = value;
|
|
767
|
+
if (typeof value === 'number') {
|
|
768
|
+
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
986
769
|
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
try {
|
|
990
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
991
|
-
}
|
|
992
|
-
finally { if (e_1) throw e_1.error; }
|
|
770
|
+
if (typeof value !== 'string') {
|
|
771
|
+
return 0;
|
|
993
772
|
}
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
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;
|
|
773
|
+
value = value.trim();
|
|
774
|
+
if (value.startsWith('+')) {
|
|
775
|
+
return parseNumber(value.substring(1));
|
|
1011
776
|
}
|
|
1012
|
-
|
|
1013
|
-
|
|
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');
|
|
777
|
+
if (value.startsWith('-')) {
|
|
778
|
+
var number = parseNumber(value.substring(1));
|
|
779
|
+
if (number === 0) {
|
|
780
|
+
return 0; // <- Note: To prevent -0
|
|
1054
781
|
}
|
|
1055
|
-
|
|
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();
|
|
782
|
+
return -number;
|
|
1063
783
|
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
784
|
+
value = value.replace(/,/g, '.');
|
|
785
|
+
value = value.toUpperCase();
|
|
786
|
+
if (value === '') {
|
|
787
|
+
return 0;
|
|
1067
788
|
}
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
throw new TemplateError('Parameter is not opened');
|
|
789
|
+
if (value === '♾' || value.startsWith('INF')) {
|
|
790
|
+
return Infinity;
|
|
1071
791
|
}
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
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
|
-
});
|
|
792
|
+
if (value.includes('/')) {
|
|
793
|
+
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
794
|
+
var numerator = parseNumber(numerator_);
|
|
795
|
+
var denominator = parseNumber(denominator_);
|
|
796
|
+
if (denominator === 0) {
|
|
797
|
+
throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
1474
798
|
}
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
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;
|
|
799
|
+
return numerator / denominator;
|
|
800
|
+
}
|
|
801
|
+
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
802
|
+
return 0;
|
|
803
|
+
}
|
|
804
|
+
if (value.includes('E')) {
|
|
805
|
+
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
806
|
+
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
807
|
+
}
|
|
808
|
+
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
809
|
+
throw new PromptbookSyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
810
|
+
}
|
|
811
|
+
var num = parseFloat(value);
|
|
812
|
+
if (isNaN(num)) {
|
|
813
|
+
throw new PromptbookSyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
814
|
+
}
|
|
815
|
+
return num;
|
|
1598
816
|
}
|
|
1599
817
|
/**
|
|
1600
|
-
* TODO:
|
|
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
|
|
818
|
+
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
1604
819
|
*/
|
|
1605
820
|
|
|
1606
821
|
/**
|
|
1607
|
-
*
|
|
822
|
+
* Parses one line of ul/ol to command
|
|
1608
823
|
*
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
1612
|
-
}
|
|
1613
|
-
|
|
1614
|
-
/**
|
|
1615
|
-
* Converts promptbook in JSON format to string format
|
|
824
|
+
* @returns parsed command object
|
|
825
|
+
* @throws {PromptbookSyntaxError} if the command is invalid
|
|
1616
826
|
*
|
|
1617
|
-
* @
|
|
1618
|
-
* @returns Promptbook in string format (.ptbk.md)
|
|
827
|
+
* @private within the promptbookStringToJson
|
|
1619
828
|
*/
|
|
1620
|
-
function
|
|
1621
|
-
var e_1, _a
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
if (description) {
|
|
1625
|
-
promptbookString += '\n\n';
|
|
1626
|
-
promptbookString += description;
|
|
1627
|
-
}
|
|
1628
|
-
// TODO:> const commands: Array<Command>
|
|
1629
|
-
var commands = [];
|
|
1630
|
-
if (promptbookUrl) {
|
|
1631
|
-
commands.push("PROMPTBOOK URL ".concat(promptbookUrl));
|
|
829
|
+
function parseCommand(listItem) {
|
|
830
|
+
var e_1, _a;
|
|
831
|
+
if (listItem.includes('\n') || listItem.includes('\r')) {
|
|
832
|
+
throw new PromptbookSyntaxError('Command can not contain new line characters:');
|
|
1632
833
|
}
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
834
|
+
var type = listItem.trim();
|
|
835
|
+
type = type.split('`').join('');
|
|
836
|
+
type = type.split('"').join('');
|
|
837
|
+
type = type.split("'").join('');
|
|
838
|
+
type = type.split('~').join('');
|
|
839
|
+
type = type.split('[').join('');
|
|
840
|
+
type = type.split(']').join('');
|
|
841
|
+
type = type.split('(').join('');
|
|
842
|
+
type = type.split(')').join('');
|
|
843
|
+
type = normalizeTo_SCREAMING_CASE(type);
|
|
844
|
+
type = type.split('DIALOGUE').join('DIALOG');
|
|
845
|
+
var listItemParts = listItem
|
|
846
|
+
.split(' ')
|
|
847
|
+
.map(function (part) { return part.trim(); })
|
|
848
|
+
.filter(function (item) { return item !== ''; })
|
|
849
|
+
.filter(function (item) { return !/^PTBK$/i.test(item); })
|
|
850
|
+
.filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
|
|
851
|
+
.map(removeMarkdownFormatting);
|
|
852
|
+
if (type.startsWith('URL') ||
|
|
853
|
+
type.startsWith('PTBK_URL') ||
|
|
854
|
+
type.startsWith('PTBKURL') ||
|
|
855
|
+
type.startsWith('PROMPTBOOK_URL') ||
|
|
856
|
+
type.startsWith('PROMPTBOOKURL') ||
|
|
857
|
+
type.startsWith('HTTPS')) {
|
|
858
|
+
if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
|
|
859
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
|
|
1642
860
|
}
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
|
|
861
|
+
var promptbookUrlString = listItemParts.pop();
|
|
862
|
+
var promptbookUrl = new URL(promptbookUrlString);
|
|
863
|
+
if (promptbookUrl.protocol !== 'https:') {
|
|
864
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
|
|
1648
865
|
}
|
|
1649
|
-
|
|
866
|
+
if (promptbookUrl.hash !== '') {
|
|
867
|
+
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 ")));
|
|
868
|
+
}
|
|
869
|
+
return {
|
|
870
|
+
type: 'PROMPTBOOK_URL',
|
|
871
|
+
promptbookUrl: promptbookUrl,
|
|
872
|
+
};
|
|
1650
873
|
}
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
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)));
|
|
874
|
+
else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
|
|
875
|
+
if (listItemParts.length !== 2) {
|
|
876
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
|
|
1658
877
|
}
|
|
878
|
+
var promptbookVersion = listItemParts.pop();
|
|
879
|
+
// TODO: Validate version
|
|
880
|
+
return {
|
|
881
|
+
type: 'PROMPTBOOK_VERSION',
|
|
882
|
+
promptbookVersion: promptbookVersion,
|
|
883
|
+
};
|
|
1659
884
|
}
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
885
|
+
else if (type.startsWith('EXECUTE') ||
|
|
886
|
+
type.startsWith('EXEC') ||
|
|
887
|
+
type.startsWith('PROMPT_DIALOG') ||
|
|
888
|
+
type.startsWith('SIMPLE_TEMPLATE')) {
|
|
889
|
+
var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
|
|
890
|
+
if (executionTypes.length !== 1) {
|
|
891
|
+
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 "); }));
|
|
1664
892
|
}
|
|
1665
|
-
|
|
893
|
+
return {
|
|
894
|
+
type: 'EXECUTE',
|
|
895
|
+
executionType: executionTypes[0],
|
|
896
|
+
};
|
|
1666
897
|
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
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
|
|
898
|
+
else if (type.startsWith('MODEL')) {
|
|
899
|
+
// TODO: Make this more elegant and dynamically
|
|
900
|
+
if (type.startsWith('MODEL_VARIANT')) {
|
|
901
|
+
if (type === 'MODEL_VARIANT_CHAT') {
|
|
902
|
+
return {
|
|
903
|
+
type: 'MODEL',
|
|
904
|
+
key: 'modelVariant',
|
|
905
|
+
value: 'CHAT',
|
|
906
|
+
};
|
|
1700
907
|
}
|
|
1701
|
-
else if (
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
contentLanguage = '';
|
|
1708
|
-
}
|
|
908
|
+
else if (type === 'MODEL_VARIANT_COMPLETION') {
|
|
909
|
+
return {
|
|
910
|
+
type: 'MODEL',
|
|
911
|
+
key: 'modelVariant',
|
|
912
|
+
value: 'COMPLETION',
|
|
913
|
+
};
|
|
1709
914
|
}
|
|
1710
|
-
else
|
|
1711
|
-
|
|
1712
|
-
// Note: Nothing special here
|
|
915
|
+
else {
|
|
916
|
+
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 "); }));
|
|
1713
917
|
}
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
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
|
|
918
|
+
}
|
|
919
|
+
if (type.startsWith('MODEL_NAME')) {
|
|
920
|
+
return {
|
|
921
|
+
type: 'MODEL',
|
|
922
|
+
key: 'modelName',
|
|
923
|
+
value: listItemParts.pop(),
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
else {
|
|
927
|
+
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 "); }));
|
|
1787
928
|
}
|
|
1788
929
|
}
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
930
|
+
else if (type.startsWith('PARAM') ||
|
|
931
|
+
type.startsWith('INPUT_PARAM') ||
|
|
932
|
+
type.startsWith('OUTPUT_PARAM') ||
|
|
933
|
+
listItem.startsWith('{') ||
|
|
934
|
+
listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
|
|
935
|
+
var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
|
|
936
|
+
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
937
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
938
|
+
}
|
|
939
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
940
|
+
var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
|
|
941
|
+
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
|
|
942
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
|
|
943
|
+
}
|
|
944
|
+
var isInput = type.startsWith('INPUT');
|
|
945
|
+
var isOutput = type.startsWith('OUTPUT');
|
|
946
|
+
if (listItem.startsWith('> {')) {
|
|
947
|
+
isInput = false;
|
|
948
|
+
isOutput = false;
|
|
1793
949
|
}
|
|
1794
|
-
|
|
950
|
+
return {
|
|
951
|
+
type: 'PARAMETER',
|
|
952
|
+
parameterName: parameterName,
|
|
953
|
+
parameterDescription: parameterDescription.trim() || null,
|
|
954
|
+
isInput: isInput,
|
|
955
|
+
isOutput: isOutput,
|
|
956
|
+
};
|
|
1795
957
|
}
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
958
|
+
else if (type.startsWith('JOKER')) {
|
|
959
|
+
if (listItemParts.length !== 2) {
|
|
960
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
|
|
961
|
+
}
|
|
962
|
+
var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
|
|
963
|
+
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
964
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
965
|
+
}
|
|
966
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
967
|
+
var parameterName = parametersMatch.groups.parameterName;
|
|
968
|
+
return {
|
|
969
|
+
type: 'JOKER',
|
|
970
|
+
parameterName: parameterName,
|
|
971
|
+
};
|
|
1806
972
|
}
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
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;
|
|
973
|
+
else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
|
|
974
|
+
if (listItemParts.length !== 2) {
|
|
975
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
|
|
976
|
+
}
|
|
977
|
+
var functionName = listItemParts.pop();
|
|
978
|
+
return {
|
|
979
|
+
type: 'POSTPROCESS',
|
|
980
|
+
functionName: functionName,
|
|
981
|
+
};
|
|
1823
982
|
}
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
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;
|
|
983
|
+
else if (type.startsWith('EXPECT_JSON')) {
|
|
984
|
+
return {
|
|
985
|
+
type: 'EXPECT_FORMAT',
|
|
986
|
+
format: 'JSON',
|
|
987
|
+
};
|
|
988
|
+
// [🥤]
|
|
1837
989
|
}
|
|
1838
|
-
|
|
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];
|
|
1861
|
-
}
|
|
1862
|
-
this.library = new Map();
|
|
990
|
+
else if (type.startsWith('EXPECT')) {
|
|
1863
991
|
try {
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
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);
|
|
992
|
+
listItemParts.shift();
|
|
993
|
+
var sign = void 0;
|
|
994
|
+
var signRaw = listItemParts.shift();
|
|
995
|
+
if (/^exact/i.test(signRaw)) {
|
|
996
|
+
sign = 'EXACTLY';
|
|
1877
997
|
}
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
finally {
|
|
1881
|
-
try {
|
|
1882
|
-
if (promptbooks_1_1 && !promptbooks_1_1.done && (_a = promptbooks_1.return)) _a.call(promptbooks_1);
|
|
998
|
+
else if (/^min/i.test(signRaw)) {
|
|
999
|
+
sign = 'MINIMUM';
|
|
1883
1000
|
}
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
}
|
|
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 ")));
|
|
1001
|
+
else if (/^max/i.test(signRaw)) {
|
|
1002
|
+
sign = 'MAXIMUM';
|
|
1904
1003
|
}
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
.join('\n')), "\n\n "); }));
|
|
1908
|
-
}
|
|
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];
|
|
1933
|
-
}
|
|
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)))()];
|
|
1004
|
+
else {
|
|
1005
|
+
throw new PromptbookSyntaxError("Invalid sign \"".concat(signRaw, "\", expected EXACTLY, MIN or MAX"));
|
|
1978
1006
|
}
|
|
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;
|
|
1007
|
+
var amountRaw = listItemParts.shift();
|
|
1008
|
+
var amount = parseNumber(amountRaw);
|
|
1009
|
+
if (amount < 0) {
|
|
1010
|
+
throw new PromptbookSyntaxError('Amount must be positive number or zero');
|
|
2000
1011
|
}
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
normalizedChar = char.toLowerCase();
|
|
1012
|
+
if (amount !== Math.floor(amount)) {
|
|
1013
|
+
throw new PromptbookSyntaxError('Amount must be whole number');
|
|
2004
1014
|
}
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
1015
|
+
var unitRaw = listItemParts.shift();
|
|
1016
|
+
var unit = undefined;
|
|
1017
|
+
try {
|
|
1018
|
+
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()) {
|
|
1019
|
+
var existingUnit = EXPECTATION_UNITS_1_1.value;
|
|
1020
|
+
var existingUnitText = existingUnit;
|
|
1021
|
+
existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
|
|
1022
|
+
if (existingUnitText === 'CHARACTER') {
|
|
1023
|
+
existingUnitText = 'CHAR';
|
|
1024
|
+
}
|
|
1025
|
+
if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
|
|
1026
|
+
new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
|
|
1027
|
+
if (unit !== undefined) {
|
|
1028
|
+
throw new PromptbookSyntaxError("Ambiguous unit \"".concat(unitRaw, "\""));
|
|
1029
|
+
}
|
|
1030
|
+
unit = existingUnit;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
2008
1033
|
}
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
1034
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1035
|
+
finally {
|
|
1036
|
+
try {
|
|
1037
|
+
if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
|
|
1038
|
+
}
|
|
1039
|
+
finally { if (e_1) throw e_1.error; }
|
|
2012
1040
|
}
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
normalizedChar = '-';
|
|
1041
|
+
if (unit === undefined) {
|
|
1042
|
+
throw new PromptbookSyntaxError("Invalid unit \"".concat(unitRaw, "\""));
|
|
2016
1043
|
}
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
1044
|
+
return {
|
|
1045
|
+
type: 'EXPECT_AMOUNT',
|
|
1046
|
+
sign: sign,
|
|
1047
|
+
unit: unit,
|
|
1048
|
+
amount: amount,
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
catch (error) {
|
|
1052
|
+
if (!(error instanceof Error)) {
|
|
1053
|
+
throw error;
|
|
2022
1054
|
}
|
|
2023
|
-
|
|
2024
|
-
lastCharType = charType;
|
|
1055
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
|
|
2025
1056
|
}
|
|
1057
|
+
/*
|
|
1058
|
+
} else if (type.startsWith('__________________')) {
|
|
1059
|
+
// <- [🥻] Insert here when making new command
|
|
1060
|
+
*/
|
|
2026
1061
|
}
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
try {
|
|
2030
|
-
if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
|
|
2031
|
-
}
|
|
2032
|
-
finally { if (e_1) throw e_1.error; }
|
|
1062
|
+
else {
|
|
1063
|
+
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 ")));
|
|
2033
1064
|
}
|
|
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
1065
|
}
|
|
2106
1066
|
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
}
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
}
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
}
|
|
2218
|
-
}
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
}
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
}
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
}
|
|
2314
|
-
|
|
2315
|
-
/**
|
|
2316
|
-
*
|
|
2317
|
-
*
|
|
2318
|
-
*
|
|
2319
|
-
*
|
|
2320
|
-
*
|
|
2321
|
-
*
|
|
2322
|
-
*
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
var
|
|
2330
|
-
|
|
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
|
-
*/
|
|
2339
|
-
|
|
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
|
-
*/
|
|
2453
|
-
|
|
2454
|
-
/**
|
|
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
|
|
2496
|
-
*/
|
|
2497
|
-
|
|
2498
|
-
/* tslint:disable */
|
|
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) {
|
|
2507
|
-
var e_1, _a;
|
|
2508
|
-
var charType;
|
|
2509
|
-
var lastCharType = 'OTHER';
|
|
2510
|
-
var normalizedName = '';
|
|
2511
|
-
try {
|
|
2512
|
-
for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
|
|
2513
|
-
var char = sentence_1_1.value;
|
|
2514
|
-
var normalizedChar = void 0;
|
|
2515
|
-
if (/^[a-z]$/.test(char)) {
|
|
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';
|
|
2529
|
-
normalizedChar = char;
|
|
2530
|
-
}
|
|
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
|
-
};
|
|
1067
|
+
var defaultDiacriticsRemovalMap = [
|
|
1068
|
+
{
|
|
1069
|
+
base: 'A',
|
|
1070
|
+
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',
|
|
1071
|
+
},
|
|
1072
|
+
{ base: 'AA', letters: '\uA732' },
|
|
1073
|
+
{ base: 'AE', letters: '\u00C6\u01FC\u01E2' },
|
|
1074
|
+
{ base: 'AO', letters: '\uA734' },
|
|
1075
|
+
{ base: 'AU', letters: '\uA736' },
|
|
1076
|
+
{ base: 'AV', letters: '\uA738\uA73A' },
|
|
1077
|
+
{ base: 'AY', letters: '\uA73C' },
|
|
1078
|
+
{
|
|
1079
|
+
base: 'B',
|
|
1080
|
+
letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
|
|
1081
|
+
},
|
|
1082
|
+
{
|
|
1083
|
+
base: 'C',
|
|
1084
|
+
letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
|
|
1085
|
+
},
|
|
1086
|
+
{
|
|
1087
|
+
base: 'D',
|
|
1088
|
+
letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
|
|
1089
|
+
},
|
|
1090
|
+
{ base: 'DZ', letters: '\u01F1\u01C4' },
|
|
1091
|
+
{ base: 'Dz', letters: '\u01F2\u01C5' },
|
|
1092
|
+
{
|
|
1093
|
+
base: 'E',
|
|
1094
|
+
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',
|
|
1095
|
+
},
|
|
1096
|
+
{ base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
|
|
1097
|
+
{
|
|
1098
|
+
base: 'G',
|
|
1099
|
+
letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
|
|
1100
|
+
},
|
|
1101
|
+
{
|
|
1102
|
+
base: 'H',
|
|
1103
|
+
letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
|
|
1104
|
+
},
|
|
1105
|
+
{
|
|
1106
|
+
base: 'I',
|
|
1107
|
+
letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
|
|
1108
|
+
},
|
|
1109
|
+
{ base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
|
|
1110
|
+
{
|
|
1111
|
+
base: 'K',
|
|
1112
|
+
letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
|
|
1113
|
+
},
|
|
1114
|
+
{
|
|
1115
|
+
base: 'L',
|
|
1116
|
+
letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
|
|
1117
|
+
},
|
|
1118
|
+
{ base: 'LJ', letters: '\u01C7' },
|
|
1119
|
+
{ base: 'Lj', letters: '\u01C8' },
|
|
1120
|
+
{ base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
|
|
1121
|
+
{
|
|
1122
|
+
base: 'N',
|
|
1123
|
+
letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
|
|
1124
|
+
},
|
|
1125
|
+
{ base: 'NJ', letters: '\u01CA' },
|
|
1126
|
+
{ base: 'Nj', letters: '\u01CB' },
|
|
1127
|
+
{
|
|
1128
|
+
base: 'O',
|
|
1129
|
+
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',
|
|
1130
|
+
},
|
|
1131
|
+
{ base: 'OI', letters: '\u01A2' },
|
|
1132
|
+
{ base: 'OO', letters: '\uA74E' },
|
|
1133
|
+
{ base: 'OU', letters: '\u0222' },
|
|
1134
|
+
{ base: 'OE', letters: '\u008C\u0152' },
|
|
1135
|
+
{ base: 'oe', letters: '\u009C\u0153' },
|
|
1136
|
+
{
|
|
1137
|
+
base: 'P',
|
|
1138
|
+
letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
|
|
1139
|
+
},
|
|
1140
|
+
{ base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
|
|
1141
|
+
{
|
|
1142
|
+
base: 'R',
|
|
1143
|
+
letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
|
|
1144
|
+
},
|
|
1145
|
+
{
|
|
1146
|
+
base: 'S',
|
|
1147
|
+
letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
|
|
1148
|
+
},
|
|
1149
|
+
{
|
|
1150
|
+
base: 'T',
|
|
1151
|
+
letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
|
|
1152
|
+
},
|
|
1153
|
+
{ base: 'TZ', letters: '\uA728' },
|
|
1154
|
+
{
|
|
1155
|
+
base: 'U',
|
|
1156
|
+
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',
|
|
1157
|
+
},
|
|
1158
|
+
{ base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
|
|
1159
|
+
{ base: 'VY', letters: '\uA760' },
|
|
1160
|
+
{
|
|
1161
|
+
base: 'W',
|
|
1162
|
+
letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
|
|
1163
|
+
},
|
|
1164
|
+
{ base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
|
|
1165
|
+
{
|
|
1166
|
+
base: 'Y',
|
|
1167
|
+
letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
|
|
1168
|
+
},
|
|
1169
|
+
{
|
|
1170
|
+
base: 'Z',
|
|
1171
|
+
letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
|
|
1172
|
+
},
|
|
1173
|
+
{
|
|
1174
|
+
base: 'a',
|
|
1175
|
+
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',
|
|
1176
|
+
},
|
|
1177
|
+
{ base: 'aa', letters: '\uA733' },
|
|
1178
|
+
{ base: 'ae', letters: '\u00E6\u01FD\u01E3' },
|
|
1179
|
+
{ base: 'ao', letters: '\uA735' },
|
|
1180
|
+
{ base: 'au', letters: '\uA737' },
|
|
1181
|
+
{ base: 'av', letters: '\uA739\uA73B' },
|
|
1182
|
+
{ base: 'ay', letters: '\uA73D' },
|
|
1183
|
+
{
|
|
1184
|
+
base: 'b',
|
|
1185
|
+
letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
|
|
1186
|
+
},
|
|
1187
|
+
{
|
|
1188
|
+
base: 'c',
|
|
1189
|
+
letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
|
|
1190
|
+
},
|
|
1191
|
+
{
|
|
1192
|
+
base: 'd',
|
|
1193
|
+
letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
|
|
1194
|
+
},
|
|
1195
|
+
{ base: 'dz', letters: '\u01F3\u01C6' },
|
|
1196
|
+
{
|
|
1197
|
+
base: 'e',
|
|
1198
|
+
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',
|
|
1199
|
+
},
|
|
1200
|
+
{ base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
|
|
1201
|
+
{
|
|
1202
|
+
base: 'g',
|
|
1203
|
+
letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
|
|
1204
|
+
},
|
|
1205
|
+
{
|
|
1206
|
+
base: 'h',
|
|
1207
|
+
letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
|
|
1208
|
+
},
|
|
1209
|
+
{ base: 'hv', letters: '\u0195' },
|
|
1210
|
+
{
|
|
1211
|
+
base: 'i',
|
|
1212
|
+
letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
|
|
1213
|
+
},
|
|
1214
|
+
{ base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
|
|
1215
|
+
{
|
|
1216
|
+
base: 'k',
|
|
1217
|
+
letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
|
|
1218
|
+
},
|
|
1219
|
+
{
|
|
1220
|
+
base: 'l',
|
|
1221
|
+
letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
|
|
1222
|
+
},
|
|
1223
|
+
{ base: 'lj', letters: '\u01C9' },
|
|
1224
|
+
{ base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
|
|
1225
|
+
{
|
|
1226
|
+
base: 'n',
|
|
1227
|
+
letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
|
|
1228
|
+
},
|
|
1229
|
+
{ base: 'nj', letters: '\u01CC' },
|
|
1230
|
+
{
|
|
1231
|
+
base: 'o',
|
|
1232
|
+
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',
|
|
1233
|
+
},
|
|
1234
|
+
{ base: 'oi', letters: '\u01A3' },
|
|
1235
|
+
{ base: 'ou', letters: '\u0223' },
|
|
1236
|
+
{ base: 'oo', letters: '\uA74F' },
|
|
1237
|
+
{
|
|
1238
|
+
base: 'p',
|
|
1239
|
+
letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
|
|
1240
|
+
},
|
|
1241
|
+
{ base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
|
|
1242
|
+
{
|
|
1243
|
+
base: 'r',
|
|
1244
|
+
letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
|
|
1245
|
+
},
|
|
1246
|
+
{
|
|
1247
|
+
base: 's',
|
|
1248
|
+
letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
|
|
1249
|
+
},
|
|
1250
|
+
{
|
|
1251
|
+
base: 't',
|
|
1252
|
+
letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
|
|
1253
|
+
},
|
|
1254
|
+
{ base: 'tz', letters: '\uA729' },
|
|
1255
|
+
{
|
|
1256
|
+
base: 'u',
|
|
1257
|
+
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',
|
|
1258
|
+
},
|
|
1259
|
+
{ base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
|
|
1260
|
+
{ base: 'vy', letters: '\uA761' },
|
|
1261
|
+
{
|
|
1262
|
+
base: 'w',
|
|
1263
|
+
letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
|
|
1264
|
+
},
|
|
1265
|
+
{ base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
|
|
1266
|
+
{
|
|
1267
|
+
base: 'y',
|
|
1268
|
+
letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
|
|
1269
|
+
},
|
|
1270
|
+
{
|
|
1271
|
+
base: 'z',
|
|
1272
|
+
letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
|
|
1273
|
+
},
|
|
1274
|
+
];
|
|
1275
|
+
/**
|
|
1276
|
+
* Map of letters from diacritic variant to diacritless variant
|
|
1277
|
+
* Contains lowercase and uppercase separatelly
|
|
1278
|
+
*
|
|
1279
|
+
* > "á" => "a"
|
|
1280
|
+
* > "ě" => "e"
|
|
1281
|
+
* > "Ă" => "A"
|
|
1282
|
+
* > ...
|
|
1283
|
+
*/
|
|
1284
|
+
var DIACRITIC_VARIANTS_LETTERS = {};
|
|
1285
|
+
// tslint:disable-next-line: prefer-for-of
|
|
1286
|
+
for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
1287
|
+
var letters = defaultDiacriticsRemovalMap[i].letters;
|
|
1288
|
+
// tslint:disable-next-line: prefer-for-of
|
|
1289
|
+
for (var j = 0; j < letters.length; j++) {
|
|
1290
|
+
DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
|
|
2744
1291
|
}
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
1292
|
+
}
|
|
1293
|
+
// <- TODO: [🍓] Put to maker function to save execution time if not needed
|
|
1294
|
+
/*
|
|
1295
|
+
@see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
|
|
1296
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
1297
|
+
you may not use this file except in compliance with the License.
|
|
1298
|
+
You may obtain a copy of the License at
|
|
1299
|
+
|
|
1300
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
1301
|
+
|
|
1302
|
+
Unless required by applicable law or agreed to in writing, software
|
|
1303
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
1304
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1305
|
+
See the License for the specific language governing permissions and
|
|
1306
|
+
limitations under the License.
|
|
1307
|
+
*/
|
|
1308
|
+
|
|
1309
|
+
/**
|
|
1310
|
+
*
|
|
1311
|
+
*/
|
|
1312
|
+
function removeDiacritics(input) {
|
|
1313
|
+
/*eslint no-control-regex: "off"*/
|
|
1314
|
+
return input.replace(/[^\u0000-\u007E]/g, function (a) {
|
|
1315
|
+
return DIACRITIC_VARIANTS_LETTERS[a] || a;
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
/* tslint:disable */
|
|
1320
|
+
function normalizeToKebabCase(sentence) {
|
|
1321
|
+
var e_1, _a;
|
|
1322
|
+
sentence = removeDiacritics(sentence);
|
|
1323
|
+
var charType;
|
|
1324
|
+
var lastCharType = 'OTHER';
|
|
1325
|
+
var normalizedName = '';
|
|
1326
|
+
try {
|
|
1327
|
+
for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
|
|
1328
|
+
var char = sentence_1_1.value;
|
|
1329
|
+
var normalizedChar = void 0;
|
|
1330
|
+
if (/^[a-z]$/.test(char)) {
|
|
1331
|
+
charType = 'LOWERCASE';
|
|
1332
|
+
normalizedChar = char;
|
|
2764
1333
|
}
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
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';
|
|
1334
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
1335
|
+
charType = 'UPPERCASE';
|
|
1336
|
+
normalizedChar = char.toLowerCase();
|
|
2844
1337
|
}
|
|
2845
|
-
else if (/^
|
|
2846
|
-
|
|
1338
|
+
else if (/^[0-9]$/.test(char)) {
|
|
1339
|
+
charType = 'NUMBER';
|
|
1340
|
+
normalizedChar = char;
|
|
2847
1341
|
}
|
|
2848
|
-
else if (
|
|
2849
|
-
|
|
1342
|
+
else if (/^\/$/.test(char)) {
|
|
1343
|
+
charType = 'SLASH';
|
|
1344
|
+
normalizedChar = char;
|
|
2850
1345
|
}
|
|
2851
1346
|
else {
|
|
2852
|
-
|
|
2853
|
-
|
|
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');
|
|
2858
|
-
}
|
|
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, "\""));
|
|
1347
|
+
charType = 'OTHER';
|
|
1348
|
+
normalizedChar = '-';
|
|
2890
1349
|
}
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
};
|
|
2897
|
-
}
|
|
2898
|
-
catch (error) {
|
|
2899
|
-
if (!(error instanceof Error)) {
|
|
2900
|
-
throw error;
|
|
1350
|
+
if (charType !== lastCharType &&
|
|
1351
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
1352
|
+
!(lastCharType === 'NUMBER') &&
|
|
1353
|
+
!(charType === 'NUMBER')) {
|
|
1354
|
+
normalizedName += '-';
|
|
2901
1355
|
}
|
|
2902
|
-
|
|
1356
|
+
normalizedName += normalizedChar;
|
|
1357
|
+
lastCharType = charType;
|
|
2903
1358
|
}
|
|
2904
|
-
/*
|
|
2905
|
-
} else if (type.startsWith('__________________')) {
|
|
2906
|
-
// <- [🥻] Insert here when making new command
|
|
2907
|
-
*/
|
|
2908
1359
|
}
|
|
2909
|
-
|
|
2910
|
-
|
|
1360
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1361
|
+
finally {
|
|
1362
|
+
try {
|
|
1363
|
+
if (sentence_1_1 && !sentence_1_1.done && (_a = sentence_1.return)) _a.call(sentence_1);
|
|
1364
|
+
}
|
|
1365
|
+
finally { if (e_1) throw e_1.error; }
|
|
2911
1366
|
}
|
|
1367
|
+
normalizedName = normalizedName.split(/-+/g).join('-');
|
|
1368
|
+
normalizedName = normalizedName.split(/-?\/-?/g).join('/');
|
|
1369
|
+
normalizedName = normalizedName.replace(/^-/, '');
|
|
1370
|
+
normalizedName = normalizedName.replace(/-$/, '');
|
|
1371
|
+
return normalizedName;
|
|
2912
1372
|
}
|
|
2913
1373
|
|
|
2914
1374
|
/**
|
|
@@ -2967,10 +1427,7 @@ function promptbookStringToJson(promptbookString, options) {
|
|
|
2967
1427
|
knowledge: [],
|
|
2968
1428
|
};
|
|
2969
1429
|
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
|
-
})];
|
|
1430
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdown()];
|
|
2974
1431
|
case 1:
|
|
2975
1432
|
knowledge = _e.sent();
|
|
2976
1433
|
console.info('!!!! knowledge', knowledge);
|