@promptbook/core 0.57.2 → 0.59.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +484 -434
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/anthropic-claude.index.d.ts +2 -2
- package/esm/typings/_packages/azure-openai.index.d.ts +3 -4
- package/esm/typings/_packages/core.index.d.ts +11 -10
- package/esm/typings/_packages/execute-javascript.index.d.ts +2 -2
- package/esm/typings/_packages/fake-llm.index.d.ts +2 -2
- package/esm/typings/_packages/langtail.index.d.ts +3 -4
- package/esm/typings/_packages/node.index.d.ts +1 -1
- package/esm/typings/_packages/openai.index.d.ts +4 -5
- package/esm/typings/_packages/remote-client.index.d.ts +4 -5
- package/esm/typings/_packages/remote-server.index.d.ts +3 -4
- package/esm/typings/_packages/types.index.d.ts +4 -2
- package/esm/typings/_packages/utils.index.d.ts +6 -4
- package/esm/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
- package/esm/typings/conversion/promptbookStringToJson.d.ts +7 -2
- package/esm/typings/execution/ScriptExecutionTools.d.ts +1 -1
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +1 -1
- package/esm/typings/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +1 -1
- package/esm/typings/expectations/drafts/isDomainNameFree.d.ts +6 -0
- package/esm/typings/expectations/drafts/isGithubNameFree.d.ts +6 -0
- package/esm/typings/formats/_common/FormatDefinition.d.ts +69 -0
- package/esm/typings/formats/csv/ListFormatDefinition.d.ts +11 -0
- package/esm/typings/formats/index.d.ts +4 -0
- package/esm/typings/formats/json/JsonFormatDefinition.d.ts +15 -0
- package/esm/typings/formats/list/ListFormatDefinition.d.ts +13 -0
- package/esm/typings/formats/xml/XmlFormatDefinition.d.ts +15 -0
- package/{umd/typings/execution/plugins/user-interface-execution-tools → esm/typings/knowledge/dialogs}/callback/CallbackInterfaceTools.d.ts +2 -2
- package/esm/typings/{execution/plugins/user-interface-execution-tools → knowledge/dialogs}/callback/CallbackInterfaceToolsOptions.d.ts +2 -2
- package/{umd/typings/execution/plugins/user-interface-execution-tools → esm/typings/knowledge/dialogs}/simple-prompt/SimplePromptInterfaceTools.d.ts +4 -4
- package/esm/typings/knowledge/prepare-knowledge/_common/IndexPreparer.d.ts +4 -0
- package/esm/typings/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +7 -0
- package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +6 -6
- package/{umd/typings/execution/plugins/llm-execution-tools → esm/typings/llm-providers}/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/{umd/typings/execution/plugins/llm-execution-tools → esm/typings/llm-providers}/anthropic-claude/anthropic-claude-models.d.ts +2 -2
- package/{umd/typings/execution/plugins/llm-execution-tools → esm/typings/llm-providers}/azure-openai/AzureOpenAiExecutionTools.d.ts +5 -5
- package/{umd/typings/execution/plugins/llm-execution-tools → esm/typings/llm-providers}/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +3 -3
- package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/langtail/LangtailExecutionTools.d.ts +1 -1
- package/{umd/typings/execution/plugins/llm-execution-tools → esm/typings/llm-providers}/mocked/MockedEchoLlmExecutionTools.d.ts +7 -7
- package/{umd/typings/execution/plugins/llm-execution-tools → esm/typings/llm-providers}/mocked/MockedFackedLlmExecutionTools.d.ts +7 -7
- package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/mocked/fakeTextToExpectations.d.ts +2 -2
- package/{umd/typings/execution/plugins/llm-execution-tools → esm/typings/llm-providers}/multiple/MultipleLlmExecutionTools.d.ts +5 -5
- package/{umd/typings/execution/plugins/llm-execution-tools → esm/typings/llm-providers}/multiple/MultipleLlmExecutionToolsOptions.d.ts +3 -3
- package/{umd/typings/execution/plugins/llm-execution-tools → esm/typings/llm-providers}/openai/OpenAiExecutionTools.d.ts +6 -6
- package/{umd/typings/execution/plugins/llm-execution-tools → esm/typings/llm-providers}/openai/OpenAiExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/openai/computeOpenaiUsage.d.ts +3 -3
- package/{umd/typings/execution/plugins/llm-execution-tools → esm/typings/llm-providers}/openai/openai-models.d.ts +2 -2
- package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/remote/RemoteLlmExecutionTools.d.ts +5 -5
- package/{umd/typings/execution/plugins/llm-execution-tools → esm/typings/llm-providers}/remote/RemoteLlmExecutionToolsOptions.d.ts +3 -3
- package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/remote/interfaces/Promptbook_Server_Progress.d.ts +1 -1
- package/{umd/typings/execution/plugins/llm-execution-tools → esm/typings/llm-providers}/remote/interfaces/Promptbook_Server_Request.d.ts +2 -2
- package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/remote/interfaces/Promptbook_Server_Response.d.ts +1 -1
- package/{umd/typings/execution/plugins/llm-execution-tools → esm/typings/llm-providers}/remote/interfaces/RemoteServerOptions.d.ts +5 -5
- package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromDirectory.d.ts +3 -0
- package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.d.ts +3 -0
- package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromSources.d.ts +4 -1
- package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromUrl.d.ts +3 -0
- package/esm/typings/{execution/plugins/script-execution-tools → scripting}/javascript/JavascriptEvalExecutionTools.d.ts +2 -2
- package/esm/typings/{execution/plugins/script-execution-tools → scripting}/javascript/JavascriptExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/scripting/python/PythonExecutionTools.d.ts +16 -0
- package/esm/typings/scripting/typescript/TypescriptExecutionTools.d.ts +16 -0
- package/esm/typings/types/Prompt.d.ts +1 -1
- package/esm/typings/types/PromptbookJson/KnowledgeJson.d.ts +6 -0
- package/esm/typings/types/PromptbookJson/MaterialKnowledgePieceJson.d.ts +27 -0
- package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +8 -6
- package/package.json +2 -2
- package/umd/index.umd.js +484 -434
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/anthropic-claude.index.d.ts +2 -2
- package/umd/typings/_packages/azure-openai.index.d.ts +3 -4
- package/umd/typings/_packages/core.index.d.ts +11 -10
- package/umd/typings/_packages/execute-javascript.index.d.ts +2 -2
- package/umd/typings/_packages/fake-llm.index.d.ts +2 -2
- package/umd/typings/_packages/langtail.index.d.ts +3 -4
- package/umd/typings/_packages/node.index.d.ts +1 -1
- package/umd/typings/_packages/openai.index.d.ts +4 -5
- package/umd/typings/_packages/remote-client.index.d.ts +4 -5
- package/umd/typings/_packages/remote-server.index.d.ts +3 -4
- package/umd/typings/_packages/types.index.d.ts +4 -2
- package/umd/typings/_packages/utils.index.d.ts +6 -4
- package/umd/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
- package/umd/typings/conversion/promptbookStringToJson.d.ts +7 -2
- package/umd/typings/execution/ScriptExecutionTools.d.ts +1 -1
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +1 -1
- package/umd/typings/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +1 -1
- package/umd/typings/expectations/drafts/isDomainNameFree.d.ts +6 -0
- package/umd/typings/expectations/drafts/isGithubNameFree.d.ts +6 -0
- package/umd/typings/formats/_common/FormatDefinition.d.ts +69 -0
- package/umd/typings/formats/csv/ListFormatDefinition.d.ts +11 -0
- package/umd/typings/formats/index.d.ts +4 -0
- package/umd/typings/formats/json/JsonFormatDefinition.d.ts +15 -0
- package/umd/typings/formats/list/ListFormatDefinition.d.ts +13 -0
- package/umd/typings/formats/xml/XmlFormatDefinition.d.ts +15 -0
- package/{esm/typings/execution/plugins/user-interface-execution-tools → umd/typings/knowledge/dialogs}/callback/CallbackInterfaceTools.d.ts +2 -2
- package/umd/typings/{execution/plugins/user-interface-execution-tools → knowledge/dialogs}/callback/CallbackInterfaceToolsOptions.d.ts +2 -2
- package/{esm/typings/execution/plugins/user-interface-execution-tools → umd/typings/knowledge/dialogs}/simple-prompt/SimplePromptInterfaceTools.d.ts +4 -4
- package/umd/typings/knowledge/prepare-knowledge/_common/IndexPreparer.d.ts +4 -0
- package/umd/typings/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +7 -0
- package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +6 -6
- package/{esm/typings/execution/plugins/llm-execution-tools → umd/typings/llm-providers}/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/{esm/typings/execution/plugins/llm-execution-tools → umd/typings/llm-providers}/anthropic-claude/anthropic-claude-models.d.ts +2 -2
- package/{esm/typings/execution/plugins/llm-execution-tools → umd/typings/llm-providers}/azure-openai/AzureOpenAiExecutionTools.d.ts +5 -5
- package/{esm/typings/execution/plugins/llm-execution-tools → umd/typings/llm-providers}/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +3 -3
- package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/langtail/LangtailExecutionTools.d.ts +1 -1
- package/{esm/typings/execution/plugins/llm-execution-tools → umd/typings/llm-providers}/mocked/MockedEchoLlmExecutionTools.d.ts +7 -7
- package/{esm/typings/execution/plugins/llm-execution-tools → umd/typings/llm-providers}/mocked/MockedFackedLlmExecutionTools.d.ts +7 -7
- package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/mocked/fakeTextToExpectations.d.ts +2 -2
- package/{esm/typings/execution/plugins/llm-execution-tools → umd/typings/llm-providers}/multiple/MultipleLlmExecutionTools.d.ts +5 -5
- package/{esm/typings/execution/plugins/llm-execution-tools → umd/typings/llm-providers}/multiple/MultipleLlmExecutionToolsOptions.d.ts +3 -3
- package/{esm/typings/execution/plugins/llm-execution-tools → umd/typings/llm-providers}/openai/OpenAiExecutionTools.d.ts +6 -6
- package/{esm/typings/execution/plugins/llm-execution-tools → umd/typings/llm-providers}/openai/OpenAiExecutionToolsOptions.d.ts +2 -2
- package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/openai/computeOpenaiUsage.d.ts +3 -3
- package/{esm/typings/execution/plugins/llm-execution-tools → umd/typings/llm-providers}/openai/openai-models.d.ts +2 -2
- package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/remote/RemoteLlmExecutionTools.d.ts +5 -5
- package/{esm/typings/execution/plugins/llm-execution-tools → umd/typings/llm-providers}/remote/RemoteLlmExecutionToolsOptions.d.ts +3 -3
- package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/remote/interfaces/Promptbook_Server_Progress.d.ts +1 -1
- package/{esm/typings/execution/plugins/llm-execution-tools → umd/typings/llm-providers}/remote/interfaces/Promptbook_Server_Request.d.ts +2 -2
- package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/remote/interfaces/Promptbook_Server_Response.d.ts +1 -1
- package/{esm/typings/execution/plugins/llm-execution-tools → umd/typings/llm-providers}/remote/interfaces/RemoteServerOptions.d.ts +5 -5
- package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromDirectory.d.ts +3 -0
- package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.d.ts +3 -0
- package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromSources.d.ts +4 -1
- package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromUrl.d.ts +3 -0
- package/umd/typings/scripting/_test/script-execution-errors.test.d.ts +1 -0
- package/umd/typings/scripting/_test/script-execution-tools.test.d.ts +1 -0
- package/umd/typings/{execution/plugins/script-execution-tools → scripting}/javascript/JavascriptEvalExecutionTools.d.ts +2 -2
- package/umd/typings/{execution/plugins/script-execution-tools → scripting}/javascript/JavascriptExecutionToolsOptions.d.ts +2 -2
- package/umd/typings/scripting/python/PythonExecutionTools.d.ts +16 -0
- package/umd/typings/scripting/typescript/TypescriptExecutionTools.d.ts +16 -0
- package/umd/typings/types/Prompt.d.ts +1 -1
- package/umd/typings/types/PromptbookJson/KnowledgeJson.d.ts +6 -0
- package/umd/typings/types/PromptbookJson/MaterialKnowledgePieceJson.d.ts +27 -0
- package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +8 -6
- package/esm/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +0 -16
- package/esm/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +0 -16
- package/umd/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +0 -16
- package/umd/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +0 -16
- /package/esm/typings/{utils → formats/json/utils}/isValidJsonString.d.ts +0 -0
- /package/esm/typings/{utils → formats/json/utils}/isValidJsonString.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/user-interface-execution-tools → knowledge/dialogs}/user-interface-execution-tools.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/llm-execution-tools/mocked/fakeTextToExpectations.test.d.ts → knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts} +0 -0
- /package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/anthropic-claude/playground/playground.d.ts +0 -0
- /package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/azure-openai/playground/playground.d.ts +0 -0
- /package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/langtail/LangtailExecutionToolsOptions.d.ts +0 -0
- /package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/langtail/playground/playground.d.ts +0 -0
- /package/{umd/typings/execution/plugins/llm-execution-tools → esm/typings/llm-providers}/mocked/fakeTextToExpectations.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/mocked/faked-completion.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/mocked/joker.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/mocked/mocked-chat.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/mocked/mocked-completion.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/multiple/playground/playground.d.ts +0 -0
- /package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/openai/computeUsage.d.ts +0 -0
- /package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/openai/computeUsage.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/openai/playground/playground.d.ts +0 -0
- /package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/remote/interfaces/Promptbook_Server_Error.d.ts +0 -0
- /package/esm/typings/{execution/plugins/llm-execution-tools → llm-providers}/remote/startRemoteServer.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/PromptbookLibrary.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/SimplePromptbookLibrary.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromDirectory.test.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.test.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromSources.test.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/constructors/createPromptbookSublibrary.d.ts +0 -0
- /package/esm/typings/{library → promptbook-library}/constructors/justTestFsImport.d.ts +0 -0
- /package/esm/typings/{execution/plugins/script-execution-tools → scripting/_test}/custom-function-async.test.ts.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/script-execution-tools → scripting/_test}/custom-function-missing.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/script-execution-tools → scripting/_test}/custom-function-with-dependencies.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/script-execution-tools → scripting/_test}/custom-function.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/script-execution-tools → scripting/_test}/postprocessing.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/script-execution-tools → scripting/_test}/script-execution-errors.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/script-execution-tools → scripting/_test}/script-execution-tools.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/script-execution-tools → scripting}/javascript/JavascriptEvalExecutionTools.test.d.ts +0 -0
- /package/esm/typings/{execution/plugins/script-execution-tools → scripting}/javascript/JavascriptExecutionTools.d.ts +0 -0
- /package/esm/typings/{execution/plugins/script-execution-tools → scripting}/javascript/utils/preserve.d.ts +0 -0
- /package/esm/typings/{execution/plugins/script-execution-tools → scripting}/javascript/utils/unknownToString.d.ts +0 -0
- /package/umd/typings/{utils → formats/json/utils}/isValidJsonString.d.ts +0 -0
- /package/umd/typings/{utils → formats/json/utils}/isValidJsonString.test.d.ts +0 -0
- /package/umd/typings/{execution/plugins/user-interface-execution-tools → knowledge/dialogs}/user-interface-execution-tools.test.d.ts +0 -0
- /package/umd/typings/{execution/plugins/llm-execution-tools/mocked/faked-completion.test.d.ts → knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts} +0 -0
- /package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/anthropic-claude/playground/playground.d.ts +0 -0
- /package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/azure-openai/playground/playground.d.ts +0 -0
- /package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/langtail/LangtailExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/langtail/playground/playground.d.ts +0 -0
- /package/umd/typings/{execution/plugins/llm-execution-tools/openai/computeUsage.test.d.ts → llm-providers/mocked/fakeTextToExpectations.test.d.ts} +0 -0
- /package/umd/typings/{execution/plugins/script-execution-tools/custom-function-async.test.ts.test.d.ts → llm-providers/mocked/faked-completion.test.d.ts} +0 -0
- /package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/mocked/joker.test.d.ts +0 -0
- /package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/mocked/mocked-chat.test.d.ts +0 -0
- /package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/mocked/mocked-completion.test.d.ts +0 -0
- /package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/multiple/playground/playground.d.ts +0 -0
- /package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/openai/computeUsage.d.ts +0 -0
- /package/umd/typings/{execution/plugins/script-execution-tools/custom-function-missing.test.d.ts → llm-providers/openai/computeUsage.test.d.ts} +0 -0
- /package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/openai/playground/playground.d.ts +0 -0
- /package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/remote/interfaces/Promptbook_Server_Error.d.ts +0 -0
- /package/umd/typings/{execution/plugins/llm-execution-tools → llm-providers}/remote/startRemoteServer.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/PromptbookLibrary.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/SimplePromptbookLibrary.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromDirectory.test.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.test.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromSources.test.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/constructors/createPromptbookSublibrary.d.ts +0 -0
- /package/umd/typings/{library → promptbook-library}/constructors/justTestFsImport.d.ts +0 -0
- /package/umd/typings/{execution/plugins/script-execution-tools/custom-function-with-dependencies.test.d.ts → scripting/_test/custom-function-async.test.ts.test.d.ts} +0 -0
- /package/umd/typings/{execution/plugins/script-execution-tools/custom-function.test.d.ts → scripting/_test/custom-function-missing.test.d.ts} +0 -0
- /package/umd/typings/{execution/plugins/script-execution-tools/postprocessing.test.d.ts → scripting/_test/custom-function-with-dependencies.test.d.ts} +0 -0
- /package/umd/typings/{execution/plugins/script-execution-tools/script-execution-errors.test.d.ts → scripting/_test/custom-function.test.d.ts} +0 -0
- /package/umd/typings/{execution/plugins/script-execution-tools/script-execution-tools.test.d.ts → scripting/_test/postprocessing.test.d.ts} +0 -0
- /package/umd/typings/{execution/plugins/script-execution-tools → scripting}/javascript/JavascriptEvalExecutionTools.test.d.ts +0 -0
- /package/umd/typings/{execution/plugins/script-execution-tools → scripting}/javascript/JavascriptExecutionTools.d.ts +0 -0
- /package/umd/typings/{execution/plugins/script-execution-tools → scripting}/javascript/utils/preserve.d.ts +0 -0
- /package/umd/typings/{execution/plugins/script-execution-tools → scripting}/javascript/utils/unknownToString.d.ts +0 -0
package/esm/index.es.js
CHANGED
|
@@ -122,6 +122,69 @@ function __spreadArray(to, from, pack) {
|
|
|
122
122
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Removes HTML or Markdown comments from a string.
|
|
127
|
+
*
|
|
128
|
+
* @param {string} content - The string to remove comments from.
|
|
129
|
+
* @returns {string} The input string with all comments removed.
|
|
130
|
+
*/
|
|
131
|
+
function removeContentComments(content) {
|
|
132
|
+
return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Add or modify an auto-generated section in a markdown file
|
|
137
|
+
*
|
|
138
|
+
* @private within the library
|
|
139
|
+
*/
|
|
140
|
+
function addAutoGeneratedSection(content, options) {
|
|
141
|
+
var sectionName = options.sectionName, sectionContent = options.sectionContent;
|
|
142
|
+
var warningLine = "<!-- \u26A0\uFE0F WARNING: This section was auto-generated -->";
|
|
143
|
+
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
144
|
+
var sectionMatch = content.match(sectionRegex);
|
|
145
|
+
if (sectionMatch) {
|
|
146
|
+
return content.replace(sectionRegex, spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
|
|
147
|
+
}
|
|
148
|
+
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
149
|
+
if (!placeForSection) {
|
|
150
|
+
throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
|
|
151
|
+
}
|
|
152
|
+
var _a = __read(placeForSection, 1), heading = _a[0];
|
|
153
|
+
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Prettify the html code
|
|
158
|
+
*
|
|
159
|
+
* @param content raw html code
|
|
160
|
+
* @returns formatted html code
|
|
161
|
+
*/
|
|
162
|
+
function prettifyMarkdown(content) {
|
|
163
|
+
try {
|
|
164
|
+
return format(content, {
|
|
165
|
+
parser: 'markdown',
|
|
166
|
+
plugins: [parserHtml],
|
|
167
|
+
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
168
|
+
endOfLine: 'lf',
|
|
169
|
+
tabWidth: 4,
|
|
170
|
+
singleQuote: true,
|
|
171
|
+
trailingComma: 'all',
|
|
172
|
+
arrowParens: 'always',
|
|
173
|
+
printWidth: 120,
|
|
174
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
175
|
+
jsxBracketSameLine: false,
|
|
176
|
+
bracketSpacing: true,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
181
|
+
error: error,
|
|
182
|
+
html: content,
|
|
183
|
+
});
|
|
184
|
+
return content;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
125
188
|
/**
|
|
126
189
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
127
190
|
*/
|
|
@@ -141,6 +204,23 @@ var PromptbookSyntaxError = /** @class */ (function (_super) {
|
|
|
141
204
|
*/
|
|
142
205
|
var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
143
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Returns the same value that is passed as argument.
|
|
209
|
+
* No side effects.
|
|
210
|
+
*
|
|
211
|
+
* Note: It can be usefull for leveling indentation
|
|
212
|
+
*
|
|
213
|
+
* @param value any values
|
|
214
|
+
* @returns the same values
|
|
215
|
+
*/
|
|
216
|
+
function just(value) {
|
|
217
|
+
if (value === undefined) {
|
|
218
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
return value;
|
|
222
|
+
}
|
|
223
|
+
|
|
144
224
|
/**
|
|
145
225
|
* Computes the deepness of the markdown structure.
|
|
146
226
|
*
|
|
@@ -396,16 +476,6 @@ function extractOneBlockFromMarkdown(markdown) {
|
|
|
396
476
|
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
397
477
|
*/
|
|
398
478
|
|
|
399
|
-
/**
|
|
400
|
-
* Removes HTML or Markdown comments from a string.
|
|
401
|
-
*
|
|
402
|
-
* @param {string} content - The string to remove comments from.
|
|
403
|
-
* @returns {string} The input string with all comments removed.
|
|
404
|
-
*/
|
|
405
|
-
function removeContentComments(content) {
|
|
406
|
-
return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
407
|
-
}
|
|
408
|
-
|
|
409
479
|
/**
|
|
410
480
|
* Creates a new set with all elements that are present in either set
|
|
411
481
|
*/
|
|
@@ -447,7 +517,7 @@ function union() {
|
|
|
447
517
|
/**
|
|
448
518
|
* The version of the Promptbook library
|
|
449
519
|
*/
|
|
450
|
-
var PROMPTBOOK_VERSION = '0.
|
|
520
|
+
var PROMPTBOOK_VERSION = '0.58.0';
|
|
451
521
|
|
|
452
522
|
/**
|
|
453
523
|
* Parses the template and returns the list of all parameter names
|
|
@@ -1318,250 +1388,255 @@ function titleToName(value) {
|
|
|
1318
1388
|
}
|
|
1319
1389
|
|
|
1320
1390
|
/**
|
|
1321
|
-
*
|
|
1391
|
+
* Compile promptbook from string (markdown) format to JSON format
|
|
1322
1392
|
*
|
|
1393
|
+
* @param promptbookString {Promptbook} in string markdown format (.ptbk.md)
|
|
1394
|
+
* @param llmTools {LlmExecutionTools} - tools for processing required for knowledge processing *(not for actual execution)*
|
|
1395
|
+
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
1323
1396
|
* @throws {PromptbookSyntaxError} if the promptbook string is not valid
|
|
1324
1397
|
*
|
|
1325
1398
|
* Note: This function does not validate logic of the pipeline only the syntax
|
|
1399
|
+
* Note: This function acts as compilation process
|
|
1326
1400
|
*/
|
|
1327
|
-
function promptbookStringToJson(promptbookString) {
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
existingParameter
|
|
1401
|
+
function promptbookStringToJson(promptbookString, llmTools) {
|
|
1402
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1403
|
+
var promptbookJson, addParam, markdownStructure, markdownStructureDeepness, description, defaultModelRequirements, listItems, listItems_1, listItems_1_1, listItem, command, _loop_1, _a, _b, section;
|
|
1404
|
+
var e_1, _c, e_2, _d;
|
|
1405
|
+
return __generator(this, function (_e) {
|
|
1406
|
+
promptbookJson = {
|
|
1407
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1408
|
+
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
1409
|
+
promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
|
|
1410
|
+
promptbookVersion: PROMPTBOOK_VERSION,
|
|
1411
|
+
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
1412
|
+
parameters: [],
|
|
1413
|
+
promptTemplates: [],
|
|
1414
|
+
knowledge: [],
|
|
1415
|
+
};
|
|
1416
|
+
// =============================================================
|
|
1417
|
+
// Note: 1️⃣ Normalization of the PROMPTBOOK string
|
|
1418
|
+
promptbookString = removeContentComments(promptbookString);
|
|
1419
|
+
promptbookString = promptbookString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
1420
|
+
promptbookString = promptbookString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
1421
|
+
addParam = function (parameterCommand) {
|
|
1422
|
+
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
|
|
1423
|
+
var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
1424
|
+
if (existingParameter &&
|
|
1425
|
+
existingParameter.description &&
|
|
1426
|
+
existingParameter.description !== parameterDescription &&
|
|
1427
|
+
parameterDescription) {
|
|
1428
|
+
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description.\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
|
|
1429
|
+
}
|
|
1430
|
+
if (existingParameter) {
|
|
1431
|
+
if (parameterDescription) {
|
|
1432
|
+
existingParameter.description = parameterDescription;
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
else {
|
|
1436
|
+
promptbookJson.parameters.push({
|
|
1437
|
+
name: parameterName,
|
|
1438
|
+
description: parameterDescription || undefined,
|
|
1439
|
+
isInput: isInput,
|
|
1440
|
+
isOutput: isOutput,
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1443
|
+
};
|
|
1444
|
+
markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1445
|
+
markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1446
|
+
if (markdownStructureDeepness !== 2) {
|
|
1447
|
+
throw new PromptbookSyntaxError(spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
|
|
1448
|
+
}
|
|
1449
|
+
promptbookJson.title = markdownStructure.title;
|
|
1450
|
+
description = markdownStructure.content;
|
|
1451
|
+
// Note: Remove codeblocks
|
|
1452
|
+
description = description.split(/^```.*^```/gms).join('');
|
|
1453
|
+
//Note: Remove lists and return statement
|
|
1454
|
+
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1455
|
+
description = spaceTrim(description);
|
|
1456
|
+
if (description === '') {
|
|
1457
|
+
description = undefined;
|
|
1458
|
+
}
|
|
1459
|
+
promptbookJson.description = description;
|
|
1460
|
+
defaultModelRequirements = {};
|
|
1461
|
+
listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
1462
|
+
try {
|
|
1463
|
+
for (listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
1464
|
+
listItem = listItems_1_1.value;
|
|
1465
|
+
command = parseCommand(listItem);
|
|
1466
|
+
switch (command.type) {
|
|
1467
|
+
case 'PROMPTBOOK_URL':
|
|
1468
|
+
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
1469
|
+
break;
|
|
1470
|
+
case 'PROMPTBOOK_VERSION':
|
|
1471
|
+
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
1472
|
+
break;
|
|
1473
|
+
case 'MODEL':
|
|
1474
|
+
defaultModelRequirements[command.key] = command.value;
|
|
1475
|
+
break;
|
|
1476
|
+
case 'PARAMETER':
|
|
1477
|
+
addParam(command);
|
|
1478
|
+
break;
|
|
1479
|
+
default:
|
|
1480
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1357
1483
|
}
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
isOutput: isOutput,
|
|
1365
|
-
});
|
|
1366
|
-
}
|
|
1367
|
-
};
|
|
1368
|
-
// =============================================================
|
|
1369
|
-
// Note: 3️⃣ Parse the dynamic part - the template pipeline
|
|
1370
|
-
var markdownStructure = markdownToMarkdownStructure(promptbookString);
|
|
1371
|
-
var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
1372
|
-
if (markdownStructureDeepness !== 2) {
|
|
1373
|
-
throw new PromptbookSyntaxError(spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
|
|
1374
|
-
}
|
|
1375
|
-
promptbookJson.title = markdownStructure.title;
|
|
1376
|
-
// TODO: [1] DRY description
|
|
1377
|
-
var description = markdownStructure.content;
|
|
1378
|
-
// Note: Remove codeblocks
|
|
1379
|
-
description = description.split(/^```.*^```/gms).join('');
|
|
1380
|
-
//Note: Remove lists and return statement
|
|
1381
|
-
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1382
|
-
description = spaceTrim(description);
|
|
1383
|
-
if (description === '') {
|
|
1384
|
-
description = undefined;
|
|
1385
|
-
}
|
|
1386
|
-
promptbookJson.description = description;
|
|
1387
|
-
var defaultModelRequirements = {};
|
|
1388
|
-
var listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
1389
|
-
try {
|
|
1390
|
-
for (var listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
|
|
1391
|
-
var listItem = listItems_1_1.value;
|
|
1392
|
-
var command = parseCommand(listItem);
|
|
1393
|
-
switch (command.type) {
|
|
1394
|
-
case 'PROMPTBOOK_URL':
|
|
1395
|
-
promptbookJson.promptbookUrl = command.promptbookUrl.href;
|
|
1396
|
-
break;
|
|
1397
|
-
case 'PROMPTBOOK_VERSION':
|
|
1398
|
-
promptbookJson.promptbookVersion = command.promptbookVersion;
|
|
1399
|
-
break;
|
|
1400
|
-
case 'MODEL':
|
|
1401
|
-
defaultModelRequirements[command.key] = command.value;
|
|
1402
|
-
break;
|
|
1403
|
-
case 'PARAMETER':
|
|
1404
|
-
addParam(command);
|
|
1405
|
-
break;
|
|
1406
|
-
default:
|
|
1407
|
-
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
|
|
1484
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1485
|
+
finally {
|
|
1486
|
+
try {
|
|
1487
|
+
if (listItems_1_1 && !listItems_1_1.done && (_c = listItems_1.return)) _c.call(listItems_1);
|
|
1488
|
+
}
|
|
1489
|
+
finally { if (e_1) throw e_1.error; }
|
|
1408
1490
|
}
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
break;
|
|
1473
|
-
case 'EXPECT_FORMAT':
|
|
1474
|
-
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
1475
|
-
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
1491
|
+
_loop_1 = function (section) {
|
|
1492
|
+
var e_3, _f;
|
|
1493
|
+
// TODO: Parse prompt template description (the content out of the codeblock and lists)
|
|
1494
|
+
var templateModelRequirements = __assign({}, defaultModelRequirements);
|
|
1495
|
+
var listItems_3 = extractAllListItemsFromMarkdown(section.content);
|
|
1496
|
+
var dependentParameterNames = new Set();
|
|
1497
|
+
var executionType = 'PROMPT_TEMPLATE';
|
|
1498
|
+
var jokers = [];
|
|
1499
|
+
var postprocessing = [];
|
|
1500
|
+
var expectAmount = {};
|
|
1501
|
+
var expectFormat = undefined;
|
|
1502
|
+
var isExecutionTypeChanged = false;
|
|
1503
|
+
try {
|
|
1504
|
+
for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
|
|
1505
|
+
var listItem = listItems_2_1.value;
|
|
1506
|
+
var command = parseCommand(listItem);
|
|
1507
|
+
switch (command.type) {
|
|
1508
|
+
case 'JOKER':
|
|
1509
|
+
jokers.push(command.parameterName);
|
|
1510
|
+
dependentParameterNames.add(command.parameterName);
|
|
1511
|
+
break;
|
|
1512
|
+
case 'EXECUTE':
|
|
1513
|
+
if (isExecutionTypeChanged) {
|
|
1514
|
+
throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
|
|
1515
|
+
}
|
|
1516
|
+
executionType = command.executionType;
|
|
1517
|
+
isExecutionTypeChanged = true;
|
|
1518
|
+
break;
|
|
1519
|
+
case 'MODEL':
|
|
1520
|
+
templateModelRequirements[command.key] = command.value;
|
|
1521
|
+
break;
|
|
1522
|
+
case 'PARAMETER':
|
|
1523
|
+
// Note: This is just for detecting resulitng parameter name
|
|
1524
|
+
addParam(command);
|
|
1525
|
+
break;
|
|
1526
|
+
case 'POSTPROCESS':
|
|
1527
|
+
postprocessing.push(command.functionName);
|
|
1528
|
+
break;
|
|
1529
|
+
case 'EXPECT_AMOUNT':
|
|
1530
|
+
// eslint-disable-next-line no-case-declarations
|
|
1531
|
+
var unit = command.unit.toLowerCase();
|
|
1532
|
+
expectAmount[unit] = expectAmount[unit] || {};
|
|
1533
|
+
if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
|
|
1534
|
+
if (expectAmount[unit].min !== undefined) {
|
|
1535
|
+
throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1536
|
+
}
|
|
1537
|
+
expectAmount[unit].min = command.amount;
|
|
1538
|
+
} /* not else */
|
|
1539
|
+
if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
|
|
1540
|
+
if (expectAmount[unit].max !== undefined) {
|
|
1541
|
+
throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
|
|
1542
|
+
}
|
|
1543
|
+
expectAmount[unit].max = command.amount;
|
|
1544
|
+
}
|
|
1545
|
+
break;
|
|
1546
|
+
case 'EXPECT_FORMAT':
|
|
1547
|
+
if (expectFormat !== undefined && command.format !== expectFormat) {
|
|
1548
|
+
throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
|
|
1549
|
+
}
|
|
1550
|
+
expectFormat = command.format;
|
|
1551
|
+
break;
|
|
1552
|
+
default:
|
|
1553
|
+
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
1476
1554
|
}
|
|
1477
|
-
|
|
1478
|
-
break;
|
|
1479
|
-
default:
|
|
1480
|
-
throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
|
|
1555
|
+
}
|
|
1481
1556
|
}
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1557
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1558
|
+
finally {
|
|
1559
|
+
try {
|
|
1560
|
+
if (listItems_2_1 && !listItems_2_1.done && (_f = listItems_2.return)) _f.call(listItems_2);
|
|
1561
|
+
}
|
|
1562
|
+
finally { if (e_3) throw e_3.error; }
|
|
1563
|
+
}
|
|
1564
|
+
var _g = extractOneBlockFromMarkdown(section.content), language = _g.language, content = _g.content;
|
|
1565
|
+
if (executionType === 'SCRIPT') {
|
|
1566
|
+
if (!language) {
|
|
1567
|
+
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
1568
|
+
}
|
|
1569
|
+
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
1570
|
+
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
var lastLine = section.content.split('\n').pop();
|
|
1574
|
+
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1575
|
+
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1576
|
+
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1577
|
+
// TODO: Show code of invalid sections each time + DRY
|
|
1578
|
+
section.content
|
|
1579
|
+
.split('\n')
|
|
1580
|
+
.map(function (line) { return "> ".concat(line); })
|
|
1581
|
+
.join('\n')), "\n "); }));
|
|
1582
|
+
}
|
|
1583
|
+
var resultingParameterName = match.groups.resultingParamName;
|
|
1584
|
+
// TODO: [1] DRY description
|
|
1585
|
+
var description_1 = section.content;
|
|
1586
|
+
// Note: Remove codeblocks
|
|
1587
|
+
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1588
|
+
//Note: Remove lists and return statement
|
|
1589
|
+
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1590
|
+
description_1 = spaceTrim(description_1);
|
|
1591
|
+
if (description_1 === '') {
|
|
1592
|
+
description_1 = undefined;
|
|
1593
|
+
}
|
|
1594
|
+
if (Object.keys(jokers).length === 0) {
|
|
1595
|
+
jokers = undefined;
|
|
1596
|
+
}
|
|
1597
|
+
if (Object.keys(expectAmount).length === 0) {
|
|
1598
|
+
expectAmount = undefined;
|
|
1599
|
+
}
|
|
1600
|
+
if (Object.keys(postprocessing).length === 0) {
|
|
1601
|
+
postprocessing = undefined;
|
|
1602
|
+
}
|
|
1603
|
+
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1604
|
+
if (templateModelRequirements.modelVariant === undefined) {
|
|
1605
|
+
templateModelRequirements.modelVariant = 'CHAT';
|
|
1606
|
+
}
|
|
1607
|
+
promptbookJson.promptTemplates.push({
|
|
1608
|
+
name: titleToName(section.title),
|
|
1609
|
+
title: section.title,
|
|
1610
|
+
description: description_1,
|
|
1611
|
+
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1612
|
+
executionType: executionType,
|
|
1613
|
+
jokers: jokers,
|
|
1614
|
+
postprocessing: postprocessing,
|
|
1615
|
+
expectations: expectAmount,
|
|
1616
|
+
expectFormat: expectFormat,
|
|
1617
|
+
modelRequirements: templateModelRequirements,
|
|
1618
|
+
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
1619
|
+
content: content,
|
|
1620
|
+
resultingParameterName: resultingParameterName,
|
|
1621
|
+
});
|
|
1622
|
+
};
|
|
1486
1623
|
try {
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
var _f = extractOneBlockFromMarkdown(section.content), language = _f.language, content = _f.content;
|
|
1492
|
-
if (executionType === 'SCRIPT') {
|
|
1493
|
-
if (!language) {
|
|
1494
|
-
throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
|
|
1624
|
+
for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1625
|
+
section = _b.value;
|
|
1626
|
+
_loop_1(section);
|
|
1627
|
+
}
|
|
1495
1628
|
}
|
|
1496
|
-
|
|
1497
|
-
|
|
1629
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1630
|
+
finally {
|
|
1631
|
+
try {
|
|
1632
|
+
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
1633
|
+
}
|
|
1634
|
+
finally { if (e_2) throw e_2.error; }
|
|
1498
1635
|
}
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
1502
|
-
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
1503
|
-
throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
1504
|
-
// TODO: Show code of invalid sections each time + DRY
|
|
1505
|
-
section.content
|
|
1506
|
-
.split('\n')
|
|
1507
|
-
.map(function (line) { return "> ".concat(line); })
|
|
1508
|
-
.join('\n')), "\n "); }));
|
|
1509
|
-
}
|
|
1510
|
-
var resultingParameterName = match.groups.resultingParamName;
|
|
1511
|
-
// TODO: [1] DRY description
|
|
1512
|
-
var description_1 = section.content;
|
|
1513
|
-
// Note: Remove codeblocks
|
|
1514
|
-
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
1515
|
-
//Note: Remove lists and return statement
|
|
1516
|
-
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
1517
|
-
description_1 = spaceTrim(description_1);
|
|
1518
|
-
if (description_1 === '') {
|
|
1519
|
-
description_1 = undefined;
|
|
1520
|
-
}
|
|
1521
|
-
if (Object.keys(jokers).length === 0) {
|
|
1522
|
-
jokers = undefined;
|
|
1523
|
-
}
|
|
1524
|
-
if (Object.keys(expectAmount).length === 0) {
|
|
1525
|
-
expectAmount = undefined;
|
|
1526
|
-
}
|
|
1527
|
-
if (Object.keys(postprocessing).length === 0) {
|
|
1528
|
-
postprocessing = undefined;
|
|
1529
|
-
}
|
|
1530
|
-
dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
|
|
1531
|
-
if (templateModelRequirements.modelVariant === undefined) {
|
|
1532
|
-
templateModelRequirements.modelVariant = 'CHAT';
|
|
1533
|
-
}
|
|
1534
|
-
promptbookJson.promptTemplates.push({
|
|
1535
|
-
name: titleToName(section.title),
|
|
1536
|
-
title: section.title,
|
|
1537
|
-
description: description_1,
|
|
1538
|
-
dependentParameterNames: Array.from(dependentParameterNames),
|
|
1539
|
-
executionType: executionType,
|
|
1540
|
-
jokers: jokers,
|
|
1541
|
-
postprocessing: postprocessing,
|
|
1542
|
-
expectations: expectAmount,
|
|
1543
|
-
expectFormat: expectFormat,
|
|
1544
|
-
modelRequirements: templateModelRequirements,
|
|
1545
|
-
contentLanguage: executionType === 'SCRIPT' ? language : undefined,
|
|
1546
|
-
content: content,
|
|
1547
|
-
resultingParameterName: resultingParameterName,
|
|
1636
|
+
// =============================================================
|
|
1637
|
+
return [2 /*return*/, promptbookJson];
|
|
1548
1638
|
});
|
|
1549
|
-
};
|
|
1550
|
-
try {
|
|
1551
|
-
for (var _c = __values(markdownStructure.sections), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1552
|
-
var section = _d.value;
|
|
1553
|
-
_loop_1(section);
|
|
1554
|
-
}
|
|
1555
|
-
}
|
|
1556
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1557
|
-
finally {
|
|
1558
|
-
try {
|
|
1559
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
1560
|
-
}
|
|
1561
|
-
finally { if (e_2) throw e_2.error; }
|
|
1562
|
-
}
|
|
1563
|
-
// =============================================================
|
|
1564
|
-
return promptbookJson;
|
|
1639
|
+
});
|
|
1565
1640
|
}
|
|
1566
1641
|
/**
|
|
1567
1642
|
* TODO: Report here line/column of error
|
|
@@ -1569,59 +1644,6 @@ function promptbookStringToJson(promptbookString) {
|
|
|
1569
1644
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
1570
1645
|
*/
|
|
1571
1646
|
|
|
1572
|
-
/**
|
|
1573
|
-
* Add or modify an auto-generated section in a markdown file
|
|
1574
|
-
*
|
|
1575
|
-
* @private within the library
|
|
1576
|
-
*/
|
|
1577
|
-
function addAutoGeneratedSection(content, options) {
|
|
1578
|
-
var sectionName = options.sectionName, sectionContent = options.sectionContent;
|
|
1579
|
-
var warningLine = "<!-- \u26A0\uFE0F WARNING: This section was auto-generated -->";
|
|
1580
|
-
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
1581
|
-
var sectionMatch = content.match(sectionRegex);
|
|
1582
|
-
if (sectionMatch) {
|
|
1583
|
-
return content.replace(sectionRegex, spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
|
|
1584
|
-
}
|
|
1585
|
-
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
1586
|
-
if (!placeForSection) {
|
|
1587
|
-
throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
|
|
1588
|
-
}
|
|
1589
|
-
var _a = __read(placeForSection, 1), heading = _a[0];
|
|
1590
|
-
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
1591
|
-
}
|
|
1592
|
-
|
|
1593
|
-
/**
|
|
1594
|
-
* Prettify the html code
|
|
1595
|
-
*
|
|
1596
|
-
* @param content raw html code
|
|
1597
|
-
* @returns formatted html code
|
|
1598
|
-
*/
|
|
1599
|
-
function prettifyMarkdown(content) {
|
|
1600
|
-
try {
|
|
1601
|
-
return format(content, {
|
|
1602
|
-
parser: 'markdown',
|
|
1603
|
-
plugins: [parserHtml],
|
|
1604
|
-
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
1605
|
-
endOfLine: 'lf',
|
|
1606
|
-
tabWidth: 4,
|
|
1607
|
-
singleQuote: true,
|
|
1608
|
-
trailingComma: 'all',
|
|
1609
|
-
arrowParens: 'always',
|
|
1610
|
-
printWidth: 120,
|
|
1611
|
-
htmlWhitespaceSensitivity: 'ignore',
|
|
1612
|
-
jsxBracketSameLine: false,
|
|
1613
|
-
bracketSpacing: true,
|
|
1614
|
-
});
|
|
1615
|
-
}
|
|
1616
|
-
catch (error) {
|
|
1617
|
-
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
1618
|
-
error: error,
|
|
1619
|
-
html: content,
|
|
1620
|
-
});
|
|
1621
|
-
return content;
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
1647
|
/* tslint:disable */
|
|
1626
1648
|
function normalizeTo_camelCase(sentence, __firstLetterCapital) {
|
|
1627
1649
|
var e_1, _a;
|
|
@@ -1739,24 +1761,35 @@ function renderPromptbookMermaid(promptbookJson, options) {
|
|
|
1739
1761
|
* Prettyfies Promptbook string and adds Mermaid graph
|
|
1740
1762
|
*/
|
|
1741
1763
|
function prettifyPromptbookString(promptbookString, options) {
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1764
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1765
|
+
var isGraphAdded, isPrettifyed, promptbookJson, promptbookMermaid_1, promptbookMermaidBlock;
|
|
1766
|
+
return __generator(this, function (_a) {
|
|
1767
|
+
switch (_a.label) {
|
|
1768
|
+
case 0:
|
|
1769
|
+
isGraphAdded = options.isGraphAdded, isPrettifyed = options.isPrettifyed;
|
|
1770
|
+
if (!isGraphAdded) return [3 /*break*/, 2];
|
|
1771
|
+
return [4 /*yield*/, promptbookStringToJson(promptbookString /* , {!!!!} */)];
|
|
1772
|
+
case 1:
|
|
1773
|
+
promptbookJson = _a.sent();
|
|
1774
|
+
promptbookMermaid_1 = renderPromptbookMermaid(promptbookJson, {
|
|
1775
|
+
linkPromptTemplate: function (promptTemplate) {
|
|
1776
|
+
return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
|
|
1777
|
+
},
|
|
1778
|
+
});
|
|
1779
|
+
promptbookMermaidBlock = spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
|
|
1780
|
+
promptbookString = addAutoGeneratedSection(promptbookString, {
|
|
1781
|
+
sectionName: 'Graph',
|
|
1782
|
+
sectionContent: promptbookMermaidBlock,
|
|
1783
|
+
});
|
|
1784
|
+
_a.label = 2;
|
|
1785
|
+
case 2:
|
|
1786
|
+
if (isPrettifyed) {
|
|
1787
|
+
promptbookString = prettifyMarkdown(promptbookString);
|
|
1788
|
+
}
|
|
1789
|
+
return [2 /*return*/, promptbookString];
|
|
1790
|
+
}
|
|
1754
1791
|
});
|
|
1755
|
-
}
|
|
1756
|
-
if (isPrettifyed) {
|
|
1757
|
-
promptbookString = prettifyMarkdown(promptbookString);
|
|
1758
|
-
}
|
|
1759
|
-
return promptbookString;
|
|
1792
|
+
});
|
|
1760
1793
|
}
|
|
1761
1794
|
/**
|
|
1762
1795
|
* TODO: Maybe use some Mermaid library instead of string templating
|
|
@@ -2305,7 +2338,7 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
2305
2338
|
/**
|
|
2306
2339
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
2307
2340
|
*/
|
|
2308
|
-
function isValidJsonString(value) {
|
|
2341
|
+
function isValidJsonString(value /* <-[👨⚖️] */) {
|
|
2309
2342
|
try {
|
|
2310
2343
|
JSON.parse(value);
|
|
2311
2344
|
return true;
|
|
@@ -3134,6 +3167,86 @@ function createPromptbookExecutor(options) {
|
|
|
3134
3167
|
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
3135
3168
|
*/
|
|
3136
3169
|
|
|
3170
|
+
/**
|
|
3171
|
+
* Function usageToWorktime will take usage and estimate saved worktime in hours of reading / writing
|
|
3172
|
+
*
|
|
3173
|
+
* Note: This is an estimate based of theese sources:
|
|
3174
|
+
* - https://jecas.cz/doba-cteni
|
|
3175
|
+
* - https://www.originalnitonery.cz/blog/psani-vsemi-deseti-se-muzete-naucit-i-sami-doma
|
|
3176
|
+
*/
|
|
3177
|
+
function usageToWorktime(usage) {
|
|
3178
|
+
var value = usage.input.wordsCount.value / (200 /* words per minute */ * 60) +
|
|
3179
|
+
usage.output.wordsCount.value / (40 /* words per minute */ * 60);
|
|
3180
|
+
var isUncertain = usage.input.wordsCount.isUncertain || usage.output.wordsCount.isUncertain;
|
|
3181
|
+
var uncertainNumber = { value: value };
|
|
3182
|
+
if (isUncertain === true) {
|
|
3183
|
+
uncertainNumber.isUncertain = true;
|
|
3184
|
+
}
|
|
3185
|
+
return uncertainNumber;
|
|
3186
|
+
}
|
|
3187
|
+
|
|
3188
|
+
/**
|
|
3189
|
+
* Delagates the user interaction to a async callback function
|
|
3190
|
+
* You need to provide your own implementation of this callback function and its bind to UI.
|
|
3191
|
+
*/
|
|
3192
|
+
var CallbackInterfaceTools = /** @class */ (function () {
|
|
3193
|
+
function CallbackInterfaceTools(options) {
|
|
3194
|
+
this.options = options;
|
|
3195
|
+
}
|
|
3196
|
+
/**
|
|
3197
|
+
* Trigger the custom callback function
|
|
3198
|
+
*/
|
|
3199
|
+
CallbackInterfaceTools.prototype.promptDialog = function (options) {
|
|
3200
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3201
|
+
var answer;
|
|
3202
|
+
return __generator(this, function (_a) {
|
|
3203
|
+
switch (_a.label) {
|
|
3204
|
+
case 0: return [4 /*yield*/, this.options.callback(options)];
|
|
3205
|
+
case 1:
|
|
3206
|
+
answer = _a.sent();
|
|
3207
|
+
if (this.options.isVerbose) {
|
|
3208
|
+
console.info(spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer), "\n "); }));
|
|
3209
|
+
}
|
|
3210
|
+
return [2 /*return*/, answer];
|
|
3211
|
+
}
|
|
3212
|
+
});
|
|
3213
|
+
});
|
|
3214
|
+
};
|
|
3215
|
+
return CallbackInterfaceTools;
|
|
3216
|
+
}());
|
|
3217
|
+
|
|
3218
|
+
/**
|
|
3219
|
+
* Wrapper around `window.prompt` synchronous function that interacts with the user via browser prompt
|
|
3220
|
+
*
|
|
3221
|
+
* Warning: It is used for testing and mocking
|
|
3222
|
+
* **NOT intended to use in the production** due to its synchronous nature.
|
|
3223
|
+
*/
|
|
3224
|
+
var SimplePromptInterfaceTools = /** @class */ (function () {
|
|
3225
|
+
function SimplePromptInterfaceTools(options) {
|
|
3226
|
+
if (options === void 0) { options = {}; }
|
|
3227
|
+
this.options = options;
|
|
3228
|
+
}
|
|
3229
|
+
/**
|
|
3230
|
+
* Trigger window.PROMPT DIALOG
|
|
3231
|
+
*/
|
|
3232
|
+
SimplePromptInterfaceTools.prototype.promptDialog = function (options) {
|
|
3233
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3234
|
+
var answer;
|
|
3235
|
+
return __generator(this, function (_a) {
|
|
3236
|
+
answer = window.prompt(spaceTrim(function (block) { return "\n ".concat(block(options.promptTitle), "\n\n ").concat(block(options.promptMessage), "\n "); }));
|
|
3237
|
+
if (this.options.isVerbose) {
|
|
3238
|
+
console.info(spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer || '🚫 User cancelled prompt'), "\n "); }));
|
|
3239
|
+
}
|
|
3240
|
+
if (answer === null) {
|
|
3241
|
+
throw new PromptbookExecutionError('User cancelled prompt');
|
|
3242
|
+
}
|
|
3243
|
+
return [2 /*return*/, answer];
|
|
3244
|
+
});
|
|
3245
|
+
});
|
|
3246
|
+
};
|
|
3247
|
+
return SimplePromptInterfaceTools;
|
|
3248
|
+
}());
|
|
3249
|
+
|
|
3137
3250
|
/**
|
|
3138
3251
|
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
3139
3252
|
*
|
|
@@ -3265,85 +3378,6 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
3265
3378
|
return MultipleLlmExecutionTools;
|
|
3266
3379
|
}());
|
|
3267
3380
|
|
|
3268
|
-
/**
|
|
3269
|
-
* Delagates the user interaction to a async callback function
|
|
3270
|
-
* You need to provide your own implementation of this callback function and its bind to UI.
|
|
3271
|
-
*/
|
|
3272
|
-
var CallbackInterfaceTools = /** @class */ (function () {
|
|
3273
|
-
function CallbackInterfaceTools(options) {
|
|
3274
|
-
this.options = options;
|
|
3275
|
-
}
|
|
3276
|
-
/**
|
|
3277
|
-
* Trigger the custom callback function
|
|
3278
|
-
*/
|
|
3279
|
-
CallbackInterfaceTools.prototype.promptDialog = function (options) {
|
|
3280
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3281
|
-
var answer;
|
|
3282
|
-
return __generator(this, function (_a) {
|
|
3283
|
-
switch (_a.label) {
|
|
3284
|
-
case 0: return [4 /*yield*/, this.options.callback(options)];
|
|
3285
|
-
case 1:
|
|
3286
|
-
answer = _a.sent();
|
|
3287
|
-
if (this.options.isVerbose) {
|
|
3288
|
-
console.info(spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer), "\n "); }));
|
|
3289
|
-
}
|
|
3290
|
-
return [2 /*return*/, answer];
|
|
3291
|
-
}
|
|
3292
|
-
});
|
|
3293
|
-
});
|
|
3294
|
-
};
|
|
3295
|
-
return CallbackInterfaceTools;
|
|
3296
|
-
}());
|
|
3297
|
-
|
|
3298
|
-
/**
|
|
3299
|
-
* Wrapper around `window.prompt` synchronous function that interacts with the user via browser prompt
|
|
3300
|
-
*
|
|
3301
|
-
* Warning: It is used for testing and mocking
|
|
3302
|
-
* **NOT intended to use in the production** due to its synchronous nature.
|
|
3303
|
-
*/
|
|
3304
|
-
var SimplePromptInterfaceTools = /** @class */ (function () {
|
|
3305
|
-
function SimplePromptInterfaceTools(options) {
|
|
3306
|
-
this.options = options;
|
|
3307
|
-
}
|
|
3308
|
-
/**
|
|
3309
|
-
* Trigger window.PROMPT DIALOG
|
|
3310
|
-
*/
|
|
3311
|
-
SimplePromptInterfaceTools.prototype.promptDialog = function (options) {
|
|
3312
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3313
|
-
var answer;
|
|
3314
|
-
return __generator(this, function (_a) {
|
|
3315
|
-
answer = window.prompt(spaceTrim(function (block) { return "\n ".concat(block(options.promptTitle), "\n\n ").concat(block(options.promptMessage), "\n "); }));
|
|
3316
|
-
if (this.options.isVerbose) {
|
|
3317
|
-
console.info(spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer || '🚫 User cancelled prompt'), "\n "); }));
|
|
3318
|
-
}
|
|
3319
|
-
if (answer === null) {
|
|
3320
|
-
throw new PromptbookExecutionError('User cancelled prompt');
|
|
3321
|
-
}
|
|
3322
|
-
return [2 /*return*/, answer];
|
|
3323
|
-
});
|
|
3324
|
-
});
|
|
3325
|
-
};
|
|
3326
|
-
return SimplePromptInterfaceTools;
|
|
3327
|
-
}());
|
|
3328
|
-
|
|
3329
|
-
/**
|
|
3330
|
-
* Function usageToWorktime will take usage and estimate saved worktime in hours of reading / writing
|
|
3331
|
-
*
|
|
3332
|
-
* Note: This is an estimate based of theese sources:
|
|
3333
|
-
* - https://jecas.cz/doba-cteni
|
|
3334
|
-
* - https://www.originalnitonery.cz/blog/psani-vsemi-deseti-se-muzete-naucit-i-sami-doma
|
|
3335
|
-
*/
|
|
3336
|
-
function usageToWorktime(usage) {
|
|
3337
|
-
var value = usage.input.wordsCount.value / (200 /* words per minute */ * 60) +
|
|
3338
|
-
usage.output.wordsCount.value / (40 /* words per minute */ * 60);
|
|
3339
|
-
var isUncertain = usage.input.wordsCount.isUncertain || usage.output.wordsCount.isUncertain;
|
|
3340
|
-
var uncertainNumber = { value: value };
|
|
3341
|
-
if (isUncertain === true) {
|
|
3342
|
-
uncertainNumber.isUncertain = true;
|
|
3343
|
-
}
|
|
3344
|
-
return uncertainNumber;
|
|
3345
|
-
}
|
|
3346
|
-
|
|
3347
3381
|
/**
|
|
3348
3382
|
* Library of promptbooks that groups together promptbooks for an application.
|
|
3349
3383
|
* This implementation is a very thin wrapper around the Array / Map of promptbooks.
|
|
@@ -3433,36 +3467,61 @@ var SimplePromptbookLibrary = /** @class */ (function () {
|
|
|
3433
3467
|
* @returns PromptbookLibrary
|
|
3434
3468
|
*/
|
|
3435
3469
|
function createPromptbookLibraryFromSources() {
|
|
3436
|
-
var e_1, _a;
|
|
3437
3470
|
var promptbookSources = [];
|
|
3438
3471
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3439
3472
|
promptbookSources[_i] = arguments[_i];
|
|
3440
3473
|
}
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3474
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3475
|
+
var promptbooks, promptbookSources_1, promptbookSources_1_1, source, promptbook, e_1_1;
|
|
3476
|
+
var e_1, _a;
|
|
3477
|
+
return __generator(this, function (_b) {
|
|
3478
|
+
switch (_b.label) {
|
|
3479
|
+
case 0:
|
|
3480
|
+
promptbooks = new Array();
|
|
3481
|
+
_b.label = 1;
|
|
3482
|
+
case 1:
|
|
3483
|
+
_b.trys.push([1, 8, 9, 10]);
|
|
3484
|
+
promptbookSources_1 = __values(promptbookSources), promptbookSources_1_1 = promptbookSources_1.next();
|
|
3485
|
+
_b.label = 2;
|
|
3486
|
+
case 2:
|
|
3487
|
+
if (!!promptbookSources_1_1.done) return [3 /*break*/, 7];
|
|
3488
|
+
source = promptbookSources_1_1.value;
|
|
3489
|
+
promptbook = void 0;
|
|
3490
|
+
if (!(typeof source === 'string')) return [3 /*break*/, 4];
|
|
3491
|
+
return [4 /*yield*/, promptbookStringToJson(source)];
|
|
3492
|
+
case 3:
|
|
3493
|
+
// Note: When directly creating from string, no need to validate the source
|
|
3494
|
+
// The validation is performed always before execution
|
|
3495
|
+
promptbook = _b.sent();
|
|
3496
|
+
return [3 /*break*/, 5];
|
|
3497
|
+
case 4:
|
|
3498
|
+
promptbook = source;
|
|
3499
|
+
_b.label = 5;
|
|
3500
|
+
case 5:
|
|
3501
|
+
promptbooks.push(promptbook);
|
|
3502
|
+
_b.label = 6;
|
|
3503
|
+
case 6:
|
|
3504
|
+
promptbookSources_1_1 = promptbookSources_1.next();
|
|
3505
|
+
return [3 /*break*/, 2];
|
|
3506
|
+
case 7: return [3 /*break*/, 10];
|
|
3507
|
+
case 8:
|
|
3508
|
+
e_1_1 = _b.sent();
|
|
3509
|
+
e_1 = { error: e_1_1 };
|
|
3510
|
+
return [3 /*break*/, 10];
|
|
3511
|
+
case 9:
|
|
3512
|
+
try {
|
|
3513
|
+
if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
|
|
3514
|
+
}
|
|
3515
|
+
finally { if (e_1) throw e_1.error; }
|
|
3516
|
+
return [7 /*endfinally*/];
|
|
3517
|
+
case 10: return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
|
|
3453
3518
|
}
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
}
|
|
3457
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3458
|
-
finally {
|
|
3459
|
-
try {
|
|
3460
|
-
if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
|
|
3461
|
-
}
|
|
3462
|
-
finally { if (e_1) throw e_1.error; }
|
|
3463
|
-
}
|
|
3464
|
-
return new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))();
|
|
3519
|
+
});
|
|
3520
|
+
});
|
|
3465
3521
|
}
|
|
3522
|
+
/**
|
|
3523
|
+
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
3524
|
+
*/
|
|
3466
3525
|
|
|
3467
3526
|
/**
|
|
3468
3527
|
* Constructs Promptbook from async sources
|
|
@@ -3498,7 +3557,9 @@ function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
3498
3557
|
return [4 /*yield*/, promptbookSourcesPromiseOrFactory];
|
|
3499
3558
|
case 1:
|
|
3500
3559
|
promptbookSources = _a.sent();
|
|
3501
|
-
|
|
3560
|
+
return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookSources), false))];
|
|
3561
|
+
case 2:
|
|
3562
|
+
library = _a.sent();
|
|
3502
3563
|
return [2 /*return*/];
|
|
3503
3564
|
}
|
|
3504
3565
|
});
|
|
@@ -3546,6 +3607,9 @@ function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
3546
3607
|
isResponsibleForPrompt: isResponsibleForPrompt,
|
|
3547
3608
|
};
|
|
3548
3609
|
}
|
|
3610
|
+
/**
|
|
3611
|
+
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
3612
|
+
*/
|
|
3549
3613
|
|
|
3550
3614
|
/**
|
|
3551
3615
|
* Constructs Promptbook from remote Promptbase URL
|
|
@@ -3578,6 +3642,9 @@ function createPromptbookLibraryFromUrl(url, options) {
|
|
|
3578
3642
|
});
|
|
3579
3643
|
});
|
|
3580
3644
|
}
|
|
3645
|
+
/**
|
|
3646
|
+
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
3647
|
+
*/
|
|
3581
3648
|
|
|
3582
3649
|
/**
|
|
3583
3650
|
* Creates PromptbookLibrary as a subset of another PromptbookLibrary
|
|
@@ -3678,23 +3745,6 @@ function formatNumber(value) {
|
|
|
3678
3745
|
return value.toString();
|
|
3679
3746
|
}
|
|
3680
3747
|
|
|
3681
|
-
/**
|
|
3682
|
-
* Returns the same value that is passed as argument.
|
|
3683
|
-
* No side effects.
|
|
3684
|
-
*
|
|
3685
|
-
* Note: It can be usefull for leveling indentation
|
|
3686
|
-
*
|
|
3687
|
-
* @param value any values
|
|
3688
|
-
* @returns the same values
|
|
3689
|
-
*/
|
|
3690
|
-
function just(value) {
|
|
3691
|
-
if (value === undefined) {
|
|
3692
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3693
|
-
return undefined;
|
|
3694
|
-
}
|
|
3695
|
-
return value;
|
|
3696
|
-
}
|
|
3697
|
-
|
|
3698
3748
|
/**
|
|
3699
3749
|
* Create a markdown table from a 2D array of strings
|
|
3700
3750
|
*
|