@promptbook/node 0.62.0 → 0.63.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/README.md +2 -2
- package/esm/index.es.js +330 -36
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/anthropic-claude.index.d.ts +3 -2
- package/esm/typings/src/_packages/azure-openai.index.d.ts +4 -2
- package/esm/typings/src/_packages/browser.index.d.ts +6 -0
- package/esm/typings/src/_packages/cli.index.d.ts +1 -7
- package/esm/typings/src/_packages/core.index.d.ts +87 -13
- package/esm/typings/src/_packages/execute-javascript.index.d.ts +5 -45
- package/esm/typings/src/_packages/fake-llm.index.d.ts +4 -5
- package/esm/typings/src/_packages/langtail.index.d.ts +4 -2
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +23 -4
- package/esm/typings/src/_packages/node.index.d.ts +5 -2
- package/esm/typings/src/_packages/openai.index.d.ts +5 -2
- package/esm/typings/src/_packages/remote-client.index.d.ts +5 -2
- package/esm/typings/src/_packages/remote-server.index.d.ts +4 -2
- package/esm/typings/src/_packages/types.index.d.ts +441 -21
- package/esm/typings/src/_packages/utils.index.d.ts +84 -31
- package/esm/typings/src/cli/main.d.ts +12 -0
- package/esm/typings/src/collection/collectionToJson.d.ts +2 -0
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -0
- package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +1 -0
- package/esm/typings/src/collection/constructors/createCollectionFromPromise.d.ts +1 -0
- package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createSubcollection.d.ts +1 -0
- package/esm/typings/src/commands/BLOCK/BlockTypes.d.ts +2 -0
- package/esm/typings/src/config.d.ts +27 -1
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -0
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +6 -3
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +4 -3
- package/esm/typings/src/conversion/prettify/prettifyPipelineString.d.ts +2 -0
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +2 -0
- package/esm/typings/src/conversion/utils/extractParameterNamesFromPromptTemplate.d.ts +1 -0
- package/esm/typings/src/conversion/utils/extractVariables.d.ts +1 -0
- package/esm/typings/src/conversion/utils/renameParameter.d.ts +1 -0
- package/esm/typings/src/conversion/utils/stringifyPipelineJson.d.ts +2 -0
- package/esm/typings/src/conversion/utils/titleToName.d.ts +6 -1
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +1 -0
- package/esm/typings/src/errors/CollectionError.d.ts +2 -0
- package/esm/typings/src/errors/EnvironmentMismatchError.d.ts +2 -0
- package/esm/typings/src/errors/LimitReachedError.d.ts +2 -0
- package/esm/typings/src/errors/NotFoundError.d.ts +2 -0
- package/esm/typings/src/errors/NotYetImplementedError.d.ts +2 -0
- package/esm/typings/src/errors/ParsingError.d.ts +2 -0
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +2 -0
- package/esm/typings/src/errors/PipelineLogicError.d.ts +2 -0
- package/esm/typings/src/errors/ReferenceError.d.ts +2 -0
- package/esm/typings/src/errors/UnexpectedError.d.ts +2 -0
- package/esm/typings/src/errors/VersionMismatchError.d.ts +2 -0
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -0
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +1 -0
- package/esm/typings/src/execution/embeddingVectorToString.d.ts +2 -0
- package/esm/typings/src/execution/utils/addUsage.d.ts +3 -1
- package/esm/typings/src/execution/utils/checkExpectations.d.ts +2 -0
- package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -0
- package/esm/typings/src/execution/utils/usageToHuman.d.ts +2 -0
- package/esm/typings/src/execution/utils/usageToWorktime.d.ts +2 -0
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +2 -1
- package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +2 -0
- package/esm/typings/src/knowledge/dialogs/callback/CallbackInterfaceTools.d.ts +2 -0
- package/esm/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +2 -0
- package/esm/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -1
- package/esm/typings/src/knowledge/prepare-knowledge/_common/Scraper.d.ts +10 -0
- package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +2 -0
- package/esm/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +4 -1
- package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/countTotalUsage.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +2 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +2 -1
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +2 -0
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +1 -0
- package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +2 -0
- package/esm/typings/src/llm-providers/langtail/LangtailExecutionToolsOptions.d.ts +2 -0
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +2 -0
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +2 -0
- package/esm/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +2 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +2 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +2 -0
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +2 -0
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +7 -1
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
- package/esm/typings/src/personas/preparePersona.d.ts +1 -1
- package/esm/typings/src/postprocessing/utils/extractBlock.d.ts +5 -0
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +2 -1
- package/esm/typings/src/prepare/preparePipeline.d.ts +1 -1
- package/esm/typings/src/prepare/prepareTemplates.d.ts +2 -1
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +2 -1
- package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.d.ts +2 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionTools.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +51 -0
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +0 -1
- package/esm/typings/src/storage/files-storage/FilesStorage.d.ts +2 -1
- package/esm/typings/src/storage/files-storage/FilesStorageOptions.d.ts +0 -3
- package/esm/typings/src/storage/local-storage/getLocalStorage.d.ts +2 -1
- package/esm/typings/src/storage/local-storage/getSessionStorage.d.ts +2 -1
- package/esm/typings/src/storage/memory/MemoryStorage.d.ts +2 -3
- package/esm/typings/src/storage/utils/PrefixStorage.d.ts +2 -3
- package/esm/typings/src/types/ModelRequirements.d.ts +0 -1
- package/esm/typings/src/types/Prompt.d.ts +0 -1
- package/esm/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +4 -0
- package/esm/typings/src/types/execution-report/executionReportJsonToString.d.ts +2 -0
- package/esm/typings/src/types/typeAliases.d.ts +9 -2
- package/esm/typings/src/utils/currentDate.d.ts +1 -0
- package/esm/typings/src/utils/deepClone.d.ts +2 -1
- package/esm/typings/src/utils/deepFreeze.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +2 -0
- package/esm/typings/src/utils/expectation-counters/countLines.d.ts +2 -0
- package/esm/typings/src/utils/expectation-counters/countPages.d.ts +2 -0
- package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +2 -0
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +4 -0
- package/esm/typings/src/utils/expectation-counters/countWords.d.ts +2 -0
- package/esm/typings/src/utils/expectation-counters/index.d.ts +2 -0
- package/esm/typings/src/utils/extractParameterNames.d.ts +1 -0
- package/esm/typings/src/utils/isRunningInWhatever.d.ts +6 -3
- package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +4 -1
- package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
- package/esm/typings/src/utils/markdown/createMarkdownTable.d.ts +4 -1
- package/esm/typings/src/utils/markdown/escapeMarkdownBlock.d.ts +5 -0
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
- package/esm/typings/src/utils/markdown/extractAllListItemsFromMarkdown.d.ts +2 -1
- package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -0
- package/esm/typings/src/utils/markdown/flattenMarkdown.d.ts +3 -0
- package/esm/typings/src/utils/markdown/parseMarkdownSection.d.ts +4 -0
- package/esm/typings/src/utils/markdown/removeContentComments.d.ts +1 -0
- package/esm/typings/src/utils/markdown/removeMarkdownFormatting.d.ts +1 -0
- package/esm/typings/src/utils/markdown/splitMarkdownIntoSections.d.ts +3 -0
- package/esm/typings/src/utils/normalization/DIACRITIC_VARIANTS_LETTERS.d.ts +2 -0
- package/esm/typings/src/utils/normalization/IKeywords.d.ts +3 -0
- package/esm/typings/src/utils/normalization/capitalize.d.ts +1 -0
- package/esm/typings/src/utils/normalization/decapitalize.d.ts +1 -0
- package/esm/typings/src/utils/normalization/isValidKeyword.d.ts +2 -0
- package/esm/typings/src/utils/normalization/nameToUriPart.d.ts +8 -0
- package/esm/typings/src/utils/normalization/nameToUriParts.d.ts +8 -0
- package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +10 -0
- package/esm/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +9 -0
- package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +10 -0
- package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +11 -0
- package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +9 -0
- package/esm/typings/src/utils/normalization/parseKeywords.d.ts +1 -0
- package/esm/typings/src/utils/normalization/parseKeywordsFromString.d.ts +1 -0
- package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +7 -0
- package/esm/typings/src/utils/normalization/searchKeywords.d.ts +5 -0
- package/esm/typings/src/utils/parseNumber.d.ts +2 -1
- package/esm/typings/src/utils/random/randomSeed.d.ts +1 -0
- package/esm/typings/src/utils/removeEmojis.d.ts +1 -0
- package/esm/typings/src/utils/removeQuotes.d.ts +1 -0
- package/esm/typings/src/utils/replaceParameters.d.ts +1 -0
- package/esm/typings/src/utils/sets/difference.d.ts +1 -0
- package/esm/typings/src/utils/sets/intersection.d.ts +1 -0
- package/esm/typings/src/utils/sets/union.d.ts +1 -0
- package/esm/typings/src/utils/trimCodeBlock.d.ts +1 -0
- package/esm/typings/src/utils/trimEndOfCodeBlock.d.ts +2 -0
- package/esm/typings/src/utils/unwrapResult.d.ts +1 -0
- package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +1 -0
- package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +7 -0
- package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +2 -0
- package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +2 -0
- package/esm/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.d.ts +2 -0
- package/esm/typings/src/utils/validators/url/isUrlOnPrivateNetwork.d.ts +1 -0
- package/esm/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +2 -0
- package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +2 -0
- package/esm/typings/src/utils/validators/uuid/isValidUuid.d.ts +2 -0
- package/esm/typings/src/version.d.ts +2 -0
- package/package.json +2 -2
- package/umd/index.umd.js +332 -37
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/src/_packages/anthropic-claude.index.d.ts +3 -2
- package/umd/typings/src/_packages/azure-openai.index.d.ts +4 -2
- package/umd/typings/src/_packages/browser.index.d.ts +6 -0
- package/umd/typings/src/_packages/cli.index.d.ts +1 -7
- package/umd/typings/src/_packages/core.index.d.ts +87 -13
- package/umd/typings/src/_packages/execute-javascript.index.d.ts +5 -45
- package/umd/typings/src/_packages/fake-llm.index.d.ts +4 -5
- package/umd/typings/src/_packages/langtail.index.d.ts +4 -2
- package/umd/typings/src/_packages/markdown-utils.index.d.ts +23 -4
- package/umd/typings/src/_packages/node.index.d.ts +5 -2
- package/umd/typings/src/_packages/openai.index.d.ts +5 -2
- package/umd/typings/src/_packages/remote-client.index.d.ts +5 -2
- package/umd/typings/src/_packages/remote-server.index.d.ts +4 -2
- package/umd/typings/src/_packages/types.index.d.ts +441 -21
- package/umd/typings/src/_packages/utils.index.d.ts +84 -31
- package/umd/typings/src/cli/main.d.ts +12 -0
- package/umd/typings/src/collection/collectionToJson.d.ts +2 -0
- package/umd/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -0
- package/umd/typings/src/collection/constructors/createCollectionFromJson.d.ts +1 -0
- package/umd/typings/src/collection/constructors/createCollectionFromPromise.d.ts +1 -0
- package/umd/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
- package/umd/typings/src/collection/constructors/createSubcollection.d.ts +1 -0
- package/umd/typings/src/commands/BLOCK/BlockTypes.d.ts +2 -0
- package/umd/typings/src/config.d.ts +27 -1
- package/umd/typings/src/conversion/pipelineJsonToString.d.ts +1 -0
- package/umd/typings/src/conversion/pipelineStringToJson.d.ts +6 -3
- package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +4 -3
- package/umd/typings/src/conversion/prettify/prettifyPipelineString.d.ts +2 -0
- package/umd/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +2 -0
- package/umd/typings/src/conversion/utils/extractParameterNamesFromPromptTemplate.d.ts +1 -0
- package/umd/typings/src/conversion/utils/extractVariables.d.ts +1 -0
- package/umd/typings/src/conversion/utils/renameParameter.d.ts +1 -0
- package/umd/typings/src/conversion/utils/stringifyPipelineJson.d.ts +2 -0
- package/umd/typings/src/conversion/utils/titleToName.d.ts +6 -1
- package/umd/typings/src/conversion/validation/validatePipeline.d.ts +1 -0
- package/umd/typings/src/errors/CollectionError.d.ts +2 -0
- package/umd/typings/src/errors/EnvironmentMismatchError.d.ts +2 -0
- package/umd/typings/src/errors/LimitReachedError.d.ts +2 -0
- package/umd/typings/src/errors/NotFoundError.d.ts +2 -0
- package/umd/typings/src/errors/NotYetImplementedError.d.ts +2 -0
- package/umd/typings/src/errors/ParsingError.d.ts +2 -0
- package/umd/typings/src/errors/PipelineExecutionError.d.ts +2 -0
- package/umd/typings/src/errors/PipelineLogicError.d.ts +2 -0
- package/umd/typings/src/errors/ReferenceError.d.ts +2 -0
- package/umd/typings/src/errors/UnexpectedError.d.ts +2 -0
- package/umd/typings/src/errors/VersionMismatchError.d.ts +2 -0
- package/umd/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -0
- package/umd/typings/src/execution/createPipelineExecutor.d.ts +1 -0
- package/umd/typings/src/execution/embeddingVectorToString.d.ts +2 -0
- package/umd/typings/src/execution/utils/addUsage.d.ts +3 -1
- package/umd/typings/src/execution/utils/checkExpectations.d.ts +2 -0
- package/umd/typings/src/execution/utils/forEachAsync.d.ts +1 -0
- package/umd/typings/src/execution/utils/usageToHuman.d.ts +2 -0
- package/umd/typings/src/execution/utils/usageToWorktime.d.ts +2 -0
- package/umd/typings/src/formats/_common/FormatDefinition.d.ts +2 -1
- package/umd/typings/src/formats/json/utils/isValidJsonString.d.ts +2 -0
- package/umd/typings/src/knowledge/dialogs/callback/CallbackInterfaceTools.d.ts +2 -0
- package/umd/typings/src/knowledge/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +2 -0
- package/umd/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -1
- package/umd/typings/src/knowledge/prepare-knowledge/_common/Scraper.d.ts +10 -0
- package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +2 -0
- package/umd/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +4 -1
- package/umd/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +1 -1
- package/umd/typings/src/llm-providers/_common/utils/count-total-usage/countTotalUsage.d.ts +1 -1
- package/umd/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -1
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +2 -0
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +2 -1
- package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +2 -0
- package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +1 -0
- package/umd/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +2 -0
- package/umd/typings/src/llm-providers/langtail/LangtailExecutionToolsOptions.d.ts +2 -0
- package/umd/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +2 -0
- package/umd/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +2 -0
- package/umd/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +2 -0
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +2 -0
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +2 -0
- package/umd/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
- package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -0
- package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionToolsOptions.d.ts +2 -0
- package/umd/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +7 -1
- package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
- package/umd/typings/src/personas/preparePersona.d.ts +1 -1
- package/umd/typings/src/postprocessing/utils/extractBlock.d.ts +5 -0
- package/umd/typings/src/prepare/isPipelinePrepared.d.ts +2 -1
- package/umd/typings/src/prepare/preparePipeline.d.ts +1 -1
- package/umd/typings/src/prepare/prepareTemplates.d.ts +2 -1
- package/umd/typings/src/prepare/unpreparePipeline.d.ts +2 -1
- package/umd/typings/src/scripting/javascript/JavascriptEvalExecutionTools.d.ts +2 -0
- package/umd/typings/src/scripting/javascript/JavascriptExecutionTools.d.ts +1 -0
- package/umd/typings/src/scripting/javascript/postprocessing-functions.d.ts +51 -0
- package/umd/typings/src/storage/_common/PromptbookStorage.d.ts +0 -1
- package/umd/typings/src/storage/files-storage/FilesStorage.d.ts +2 -1
- package/umd/typings/src/storage/files-storage/FilesStorageOptions.d.ts +0 -3
- package/umd/typings/src/storage/local-storage/getLocalStorage.d.ts +2 -1
- package/umd/typings/src/storage/local-storage/getSessionStorage.d.ts +2 -1
- package/umd/typings/src/storage/memory/MemoryStorage.d.ts +2 -3
- package/umd/typings/src/storage/utils/PrefixStorage.d.ts +2 -3
- package/umd/typings/src/types/ModelRequirements.d.ts +0 -1
- package/umd/typings/src/types/Prompt.d.ts +0 -1
- package/umd/typings/src/types/execution-report/ExecutionReportStringOptions.d.ts +4 -0
- package/umd/typings/src/types/execution-report/executionReportJsonToString.d.ts +2 -0
- package/umd/typings/src/types/typeAliases.d.ts +9 -2
- package/umd/typings/src/utils/currentDate.d.ts +1 -0
- package/umd/typings/src/utils/deepClone.d.ts +2 -1
- package/umd/typings/src/utils/deepFreeze.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countCharacters.d.ts +2 -0
- package/umd/typings/src/utils/expectation-counters/countLines.d.ts +2 -0
- package/umd/typings/src/utils/expectation-counters/countPages.d.ts +2 -0
- package/umd/typings/src/utils/expectation-counters/countParagraphs.d.ts +2 -0
- package/umd/typings/src/utils/expectation-counters/countSentences.d.ts +4 -0
- package/umd/typings/src/utils/expectation-counters/countWords.d.ts +2 -0
- package/umd/typings/src/utils/expectation-counters/index.d.ts +2 -0
- package/umd/typings/src/utils/extractParameterNames.d.ts +1 -0
- package/umd/typings/src/utils/isRunningInWhatever.d.ts +6 -3
- package/umd/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +4 -1
- package/umd/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
- package/umd/typings/src/utils/markdown/createMarkdownTable.d.ts +4 -1
- package/umd/typings/src/utils/markdown/escapeMarkdownBlock.d.ts +5 -0
- package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
- package/umd/typings/src/utils/markdown/extractAllListItemsFromMarkdown.d.ts +2 -1
- package/umd/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -0
- package/umd/typings/src/utils/markdown/flattenMarkdown.d.ts +3 -0
- package/umd/typings/src/utils/markdown/parseMarkdownSection.d.ts +4 -0
- package/umd/typings/src/utils/markdown/removeContentComments.d.ts +1 -0
- package/umd/typings/src/utils/markdown/removeMarkdownFormatting.d.ts +1 -0
- package/umd/typings/src/utils/markdown/splitMarkdownIntoSections.d.ts +3 -0
- package/umd/typings/src/utils/normalization/DIACRITIC_VARIANTS_LETTERS.d.ts +2 -0
- package/umd/typings/src/utils/normalization/IKeywords.d.ts +3 -0
- package/umd/typings/src/utils/normalization/capitalize.d.ts +1 -0
- package/umd/typings/src/utils/normalization/decapitalize.d.ts +1 -0
- package/umd/typings/src/utils/normalization/isValidKeyword.d.ts +2 -0
- package/umd/typings/src/utils/normalization/nameToUriPart.d.ts +8 -0
- package/umd/typings/src/utils/normalization/nameToUriParts.d.ts +8 -0
- package/umd/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +10 -0
- package/umd/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +9 -0
- package/umd/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +10 -0
- package/umd/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +11 -0
- package/umd/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +9 -0
- package/umd/typings/src/utils/normalization/parseKeywords.d.ts +1 -0
- package/umd/typings/src/utils/normalization/parseKeywordsFromString.d.ts +1 -0
- package/umd/typings/src/utils/normalization/removeDiacritics.d.ts +7 -0
- package/umd/typings/src/utils/normalization/searchKeywords.d.ts +5 -0
- package/umd/typings/src/utils/parseNumber.d.ts +2 -1
- package/umd/typings/src/utils/random/randomSeed.d.ts +1 -0
- package/umd/typings/src/utils/removeEmojis.d.ts +1 -0
- package/umd/typings/src/utils/removeQuotes.d.ts +1 -0
- package/umd/typings/src/utils/replaceParameters.d.ts +1 -0
- package/umd/typings/src/utils/sets/difference.d.ts +1 -0
- package/umd/typings/src/utils/sets/intersection.d.ts +1 -0
- package/umd/typings/src/utils/sets/union.d.ts +1 -0
- package/umd/typings/src/utils/trimCodeBlock.d.ts +1 -0
- package/umd/typings/src/utils/trimEndOfCodeBlock.d.ts +2 -0
- package/umd/typings/src/utils/unwrapResult.d.ts +1 -0
- package/umd/typings/src/utils/validators/filePath/isValidFilePath.d.ts +1 -0
- package/umd/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +7 -0
- package/umd/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +2 -0
- package/umd/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +2 -0
- package/umd/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.d.ts +2 -0
- package/umd/typings/src/utils/validators/url/isUrlOnPrivateNetwork.d.ts +1 -0
- package/umd/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +2 -0
- package/umd/typings/src/utils/validators/url/isValidUrl.d.ts +2 -0
- package/umd/typings/src/utils/validators/uuid/isValidUuid.d.ts +2 -0
- package/umd/typings/src/version.d.ts +2 -0
package/umd/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('fs/promises'), require('path'), require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('dotenv'), require('@anthropic-ai/sdk'), require('openai')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'colors', 'fs/promises', 'path', 'spacetrim', 'prettier', 'prettier/parser-html', 'dotenv', '@anthropic-ai/sdk', 'openai'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-node"] = {}, global.colors, global.promises, global.path, global.spaceTrim, global.prettier, global.parserHtml, global.dotenv, global.Anthropic, global.OpenAI));
|
|
5
|
-
})(this, (function (exports, colors, promises, path, spaceTrim, prettier, parserHtml, dotenv, Anthropic, OpenAI) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('fs/promises'), require('path'), require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('dotenv'), require('@anthropic-ai/sdk'), require('openai'), require('crypto-js/enc-hex'), require('crypto-js/sha256')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'colors', 'fs/promises', 'path', 'spacetrim', 'prettier', 'prettier/parser-html', 'dotenv', '@anthropic-ai/sdk', 'openai', 'crypto-js/enc-hex', 'crypto-js/sha256'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-node"] = {}, global.colors, global.promises, global.path, global.spaceTrim, global.prettier, global.parserHtml, global.dotenv, global.Anthropic, global.OpenAI, global.hexEncoder, global.sha256));
|
|
5
|
+
})(this, (function (exports, colors, promises, path, spaceTrim, prettier, parserHtml, dotenv, Anthropic, OpenAI, hexEncoder, sha256) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -30,6 +30,16 @@
|
|
|
30
30
|
var dotenv__namespace = /*#__PURE__*/_interopNamespace(dotenv);
|
|
31
31
|
var Anthropic__default = /*#__PURE__*/_interopDefaultLegacy(Anthropic);
|
|
32
32
|
var OpenAI__default = /*#__PURE__*/_interopDefaultLegacy(OpenAI);
|
|
33
|
+
var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
|
|
34
|
+
var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The version of the Promptbook library
|
|
38
|
+
*
|
|
39
|
+
* @public exported from all packages
|
|
40
|
+
*/
|
|
41
|
+
var PROMPTBOOK_VERSION = '0.62.0';
|
|
42
|
+
// TODO: !!!! List here all the versions and annotate + put into script
|
|
33
43
|
|
|
34
44
|
/*! *****************************************************************************
|
|
35
45
|
Copyright (c) Microsoft Corporation.
|
|
@@ -183,6 +193,7 @@
|
|
|
183
193
|
* @@@
|
|
184
194
|
*
|
|
185
195
|
* @returns The same object as the input, but deeply frozen
|
|
196
|
+
* @public exported from `@promptbook/utils`
|
|
186
197
|
*
|
|
187
198
|
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
188
199
|
*/
|
|
@@ -190,24 +201,37 @@
|
|
|
190
201
|
return deepFreeze(objectValue);
|
|
191
202
|
}
|
|
192
203
|
/**
|
|
193
|
-
* TODO: [🔼] Export from `@promptbook/utils`
|
|
194
204
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
195
205
|
*/
|
|
196
206
|
|
|
197
207
|
/**
|
|
198
208
|
* The maximum number of iterations for a loops
|
|
209
|
+
*
|
|
210
|
+
* @private within the repository - too low-level in comparison to other `MAX_...`
|
|
199
211
|
*/
|
|
200
212
|
var LOOP_LIMIT = 1000;
|
|
201
213
|
/**
|
|
202
214
|
* The maximum number of (LLM) tasks running in parallel
|
|
215
|
+
*
|
|
216
|
+
* @public exported from `@promptbook/core`
|
|
203
217
|
*/
|
|
204
218
|
var MAX_PARALLEL_COUNT = 5;
|
|
205
219
|
/**
|
|
206
220
|
* The maximum number of attempts to execute LLM task before giving up
|
|
221
|
+
*
|
|
222
|
+
* @public exported from `@promptbook/core`
|
|
207
223
|
*/
|
|
208
224
|
var MAX_EXECUTION_ATTEMPTS = 3;
|
|
225
|
+
/**
|
|
226
|
+
* The maximum length of the (generated) filename
|
|
227
|
+
*
|
|
228
|
+
* @public exported from `@promptbook/core`
|
|
229
|
+
*/
|
|
230
|
+
var MAX_FILENAME_LENGTH = 30;
|
|
209
231
|
/**
|
|
210
232
|
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
233
|
+
*
|
|
234
|
+
* @public exported from `@promptbook/core`
|
|
211
235
|
*/
|
|
212
236
|
var PIPELINE_COLLECTION_BASE_FILENAME = "index";
|
|
213
237
|
/**
|
|
@@ -216,6 +240,8 @@
|
|
|
216
240
|
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
217
241
|
/**
|
|
218
242
|
* The names of the parameters that are reserved for special purposes
|
|
243
|
+
*
|
|
244
|
+
* @public exported from `@promptbook/core`
|
|
219
245
|
*/
|
|
220
246
|
var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
221
247
|
'content',
|
|
@@ -229,10 +255,14 @@
|
|
|
229
255
|
]);
|
|
230
256
|
/**
|
|
231
257
|
* @@@
|
|
258
|
+
*
|
|
259
|
+
* @private within the repository
|
|
232
260
|
*/
|
|
233
261
|
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
234
262
|
/**
|
|
235
263
|
* @@@
|
|
264
|
+
*
|
|
265
|
+
* @private within the repository
|
|
236
266
|
*/
|
|
237
267
|
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
238
268
|
/*
|
|
@@ -240,7 +270,7 @@
|
|
|
240
270
|
*/
|
|
241
271
|
// [🟡][🟢][🔵][⚪]
|
|
242
272
|
/**
|
|
243
|
-
* TODO:
|
|
273
|
+
* TODO: !!!!!! Check that all @private contains some normalized explanation
|
|
244
274
|
*/
|
|
245
275
|
|
|
246
276
|
/**
|
|
@@ -280,6 +310,7 @@
|
|
|
280
310
|
/**
|
|
281
311
|
* Makes first letter of a string uppercase
|
|
282
312
|
*
|
|
313
|
+
* @public exported from `@promptbook/utils`
|
|
283
314
|
*/
|
|
284
315
|
function capitalize(word) {
|
|
285
316
|
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
@@ -290,6 +321,7 @@
|
|
|
290
321
|
*
|
|
291
322
|
* @param pipelineJson Promptbook in JSON format (.ptbk.json)
|
|
292
323
|
* @returns Promptbook in string format (.ptbk.md)
|
|
324
|
+
* @public exported from `@promptbook/core`
|
|
293
325
|
*/
|
|
294
326
|
function pipelineJsonToString(pipelineJson) {
|
|
295
327
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
@@ -489,6 +521,8 @@
|
|
|
489
521
|
|
|
490
522
|
/**
|
|
491
523
|
* @@@
|
|
524
|
+
*
|
|
525
|
+
* @public exported from `@promptbook/utils`
|
|
492
526
|
*/
|
|
493
527
|
function deepClone(objectValue) {
|
|
494
528
|
return JSON.parse(JSON.stringify(objectValue));
|
|
@@ -505,14 +539,13 @@
|
|
|
505
539
|
*/
|
|
506
540
|
}
|
|
507
541
|
/**
|
|
508
|
-
* TODO: [🔼] Export from `@promptbook/utils`
|
|
509
542
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
510
543
|
*/
|
|
511
544
|
|
|
512
545
|
/**
|
|
513
546
|
* @@@
|
|
514
547
|
*
|
|
515
|
-
*
|
|
548
|
+
* @public exported from `@promptbook/core`
|
|
516
549
|
*/
|
|
517
550
|
var ZERO_USAGE = deepFreeze({
|
|
518
551
|
price: { value: 0 },
|
|
@@ -539,6 +572,8 @@
|
|
|
539
572
|
* Function `addUsage` will add multiple usages into one
|
|
540
573
|
*
|
|
541
574
|
* Note: If you provide 0 values, it returns ZERO_USAGE
|
|
575
|
+
*
|
|
576
|
+
* @public exported from `@promptbook/core`
|
|
542
577
|
*/
|
|
543
578
|
function addUsage() {
|
|
544
579
|
var usageItems = [];
|
|
@@ -611,6 +646,7 @@
|
|
|
611
646
|
* @param array - Array to iterate over
|
|
612
647
|
* @param options - Options for the function
|
|
613
648
|
* @param callbackfunction - Function to call for each item
|
|
649
|
+
* @public exported from `@promptbook/utils`
|
|
614
650
|
*/
|
|
615
651
|
function forEachAsync(array, options, callbackfunction) {
|
|
616
652
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -679,10 +715,12 @@
|
|
|
679
715
|
});
|
|
680
716
|
}
|
|
681
717
|
|
|
682
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.62.0
|
|
718
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.62.0",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.62.0",usage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.62.0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.62.0",usage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.62.0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.62.0",usage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.62.0",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Option `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.62.0",usage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
683
719
|
|
|
684
720
|
/**
|
|
685
721
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
722
|
+
*
|
|
723
|
+
* @public exported from `@promptbook/core`
|
|
686
724
|
*/
|
|
687
725
|
var ParsingError = /** @class */ (function (_super) {
|
|
688
726
|
__extends(ParsingError, _super);
|
|
@@ -697,6 +735,8 @@
|
|
|
697
735
|
|
|
698
736
|
/**
|
|
699
737
|
* This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
|
|
738
|
+
*
|
|
739
|
+
* @public exported from `@promptbook/core`
|
|
700
740
|
*/
|
|
701
741
|
var PipelineLogicError = /** @class */ (function (_super) {
|
|
702
742
|
__extends(PipelineLogicError, _super);
|
|
@@ -711,6 +751,8 @@
|
|
|
711
751
|
|
|
712
752
|
/**
|
|
713
753
|
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
754
|
+
*
|
|
755
|
+
* @public exported from `@promptbook/core`
|
|
714
756
|
*/
|
|
715
757
|
var UnexpectedError = /** @class */ (function (_super) {
|
|
716
758
|
__extends(UnexpectedError, _super);
|
|
@@ -729,6 +771,8 @@
|
|
|
729
771
|
* Note: There are two simmilar functions:
|
|
730
772
|
* - `isValidSemanticVersion` which tests any semantic version
|
|
731
773
|
* - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
|
|
774
|
+
*
|
|
775
|
+
* @public exported from `@promptbook/utils`
|
|
732
776
|
*/
|
|
733
777
|
function isValidSemanticVersion(version) {
|
|
734
778
|
if (typeof version !== 'string') {
|
|
@@ -749,6 +793,8 @@
|
|
|
749
793
|
* Note: There are two simmilar functions:
|
|
750
794
|
* - `isValidSemanticVersion` which tests any semantic version
|
|
751
795
|
* - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
|
|
796
|
+
*
|
|
797
|
+
* @public exported from `@promptbook/utils`
|
|
752
798
|
*/
|
|
753
799
|
function isValidPromptbookVersion(version) {
|
|
754
800
|
if (!isValidSemanticVersion(version)) {
|
|
@@ -767,6 +813,8 @@
|
|
|
767
813
|
* Note: There are two simmilar functions:
|
|
768
814
|
* - `isUrlOnPrivateNetwork` which tests full URL
|
|
769
815
|
* - `isHostnameOnPrivateNetwork` *(this one)* which tests just hostname
|
|
816
|
+
*
|
|
817
|
+
* @public exported from `@promptbook/utils`
|
|
770
818
|
*/
|
|
771
819
|
function isHostnameOnPrivateNetwork(hostname) {
|
|
772
820
|
if (hostname === 'example.com' ||
|
|
@@ -801,6 +849,7 @@
|
|
|
801
849
|
*
|
|
802
850
|
* @param {string} ipAddress - The IP address to check.
|
|
803
851
|
* @returns {boolean} Returns true if the IP address is reserved for private networks or localhost, otherwise false.
|
|
852
|
+
* @public exported from `@promptbook/utils`
|
|
804
853
|
*/
|
|
805
854
|
function isUrlOnPrivateNetwork(url) {
|
|
806
855
|
if (typeof url === 'string') {
|
|
@@ -816,6 +865,8 @@
|
|
|
816
865
|
* Note: There are two simmilar functions:
|
|
817
866
|
* - `isValidUrl` which tests any URL
|
|
818
867
|
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
868
|
+
*
|
|
869
|
+
* @public exported from `@promptbook/utils`
|
|
819
870
|
*/
|
|
820
871
|
function isValidUrl(url) {
|
|
821
872
|
if (typeof url !== 'string') {
|
|
@@ -842,6 +893,8 @@
|
|
|
842
893
|
* Note: There are two simmilar functions:
|
|
843
894
|
* - `isValidUrl` which tests any URL
|
|
844
895
|
* - `isValidPipelineUrl` *(this one)* which tests just pipeline URL
|
|
896
|
+
*
|
|
897
|
+
* @public exported from `@promptbook/utils`
|
|
845
898
|
*/
|
|
846
899
|
function isValidPipelineUrl(url) {
|
|
847
900
|
if (!isValidUrl(url)) {
|
|
@@ -879,6 +932,7 @@
|
|
|
879
932
|
* @param pipeline valid or invalid PipelineJson
|
|
880
933
|
* @returns the same pipeline if it is logically valid
|
|
881
934
|
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
935
|
+
* @public exported from `@promptbook/core`
|
|
882
936
|
*/
|
|
883
937
|
function validatePipeline(pipeline) {
|
|
884
938
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
@@ -1108,6 +1162,8 @@
|
|
|
1108
1162
|
|
|
1109
1163
|
/**
|
|
1110
1164
|
* This error indicates that promptbook not found in the collection
|
|
1165
|
+
*
|
|
1166
|
+
* @public exported from `@promptbook/core`
|
|
1111
1167
|
*/
|
|
1112
1168
|
var NotFoundError = /** @class */ (function (_super) {
|
|
1113
1169
|
__extends(NotFoundError, _super);
|
|
@@ -1122,6 +1178,8 @@
|
|
|
1122
1178
|
|
|
1123
1179
|
/**
|
|
1124
1180
|
* This error indicates errors in referencing promptbooks between each other
|
|
1181
|
+
*
|
|
1182
|
+
* @public exported from `@promptbook/core`
|
|
1125
1183
|
*/
|
|
1126
1184
|
var ReferenceError$1 = /** @class */ (function (_super) {
|
|
1127
1185
|
__extends(ReferenceError, _super);
|
|
@@ -1139,6 +1197,7 @@
|
|
|
1139
1197
|
*
|
|
1140
1198
|
* @param template the template with parameters in {curly} braces
|
|
1141
1199
|
* @returns the list of parameter names
|
|
1200
|
+
* @public exported from `@promptbook/utils`
|
|
1142
1201
|
*/
|
|
1143
1202
|
function extractParameterNames(template) {
|
|
1144
1203
|
var e_1, _a;
|
|
@@ -1163,6 +1222,8 @@
|
|
|
1163
1222
|
|
|
1164
1223
|
/**
|
|
1165
1224
|
* Unprepare just strips the preparation data of the pipeline
|
|
1225
|
+
*
|
|
1226
|
+
* @public exported from `@promptbook/core`
|
|
1166
1227
|
*/
|
|
1167
1228
|
function unpreparePipeline(pipeline) {
|
|
1168
1229
|
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, promptTemplates = pipeline.promptTemplates;
|
|
@@ -1179,7 +1240,6 @@
|
|
|
1179
1240
|
return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
|
|
1180
1241
|
}
|
|
1181
1242
|
/**
|
|
1182
|
-
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
1183
1243
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
1184
1244
|
* TODO: Write tests for `preparePipeline`
|
|
1185
1245
|
* TODO: [🍙] Make some standart order of json properties
|
|
@@ -1281,6 +1341,7 @@
|
|
|
1281
1341
|
*
|
|
1282
1342
|
* @param promptbookSources
|
|
1283
1343
|
* @returns PipelineCollection
|
|
1344
|
+
* @public exported from `@promptbook/core`
|
|
1284
1345
|
*/
|
|
1285
1346
|
function createCollectionFromJson() {
|
|
1286
1347
|
var promptbooks = [];
|
|
@@ -1506,6 +1567,8 @@
|
|
|
1506
1567
|
* > "ě" => "e"
|
|
1507
1568
|
* > "Ă" => "A"
|
|
1508
1569
|
* > ...
|
|
1570
|
+
*
|
|
1571
|
+
* @public exported from `@promptbook/utils`
|
|
1509
1572
|
*/
|
|
1510
1573
|
var DIACRITIC_VARIANTS_LETTERS = {};
|
|
1511
1574
|
// tslint:disable-next-line: prefer-for-of
|
|
@@ -1533,7 +1596,11 @@
|
|
|
1533
1596
|
*/
|
|
1534
1597
|
|
|
1535
1598
|
/**
|
|
1599
|
+
* @@@
|
|
1536
1600
|
*
|
|
1601
|
+
* @param input @@@
|
|
1602
|
+
* @returns @@@
|
|
1603
|
+
* @public exported from `@promptbook/utils`
|
|
1537
1604
|
*/
|
|
1538
1605
|
function removeDiacritics(input) {
|
|
1539
1606
|
/*eslint no-control-regex: "off"*/
|
|
@@ -1541,7 +1608,19 @@
|
|
|
1541
1608
|
return DIACRITIC_VARIANTS_LETTERS[a] || a;
|
|
1542
1609
|
});
|
|
1543
1610
|
}
|
|
1611
|
+
/**
|
|
1612
|
+
* TODO: [Ж] Variant for cyrillic (and in general non-latin) letters
|
|
1613
|
+
*/
|
|
1544
1614
|
|
|
1615
|
+
/**
|
|
1616
|
+
* @@@
|
|
1617
|
+
*
|
|
1618
|
+
* @param text @@@
|
|
1619
|
+
* @returns @@@
|
|
1620
|
+
* @example 'hello-world'
|
|
1621
|
+
* @example 'i-love-promptbook'
|
|
1622
|
+
* @public exported from `@promptbook/utils`
|
|
1623
|
+
*/
|
|
1545
1624
|
function normalizeToKebabCase(text) {
|
|
1546
1625
|
var e_1, _a;
|
|
1547
1626
|
text = removeDiacritics(text);
|
|
@@ -1601,6 +1680,7 @@
|
|
|
1601
1680
|
*
|
|
1602
1681
|
* @param text with emojis
|
|
1603
1682
|
* @returns text without emojis
|
|
1683
|
+
* @public exported from `@promptbook/utils`
|
|
1604
1684
|
*/
|
|
1605
1685
|
function removeEmojis(text) {
|
|
1606
1686
|
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
@@ -1612,7 +1692,12 @@
|
|
|
1612
1692
|
}
|
|
1613
1693
|
|
|
1614
1694
|
/**
|
|
1615
|
-
*
|
|
1695
|
+
* @@@
|
|
1696
|
+
*
|
|
1697
|
+
* @param value @@@
|
|
1698
|
+
* @returns @@@
|
|
1699
|
+
* @example @@@
|
|
1700
|
+
* @public exported from `@promptbook/utils`
|
|
1616
1701
|
*/
|
|
1617
1702
|
function titleToName(value) {
|
|
1618
1703
|
if (value.startsWith('http://') || value.startsWith('https://')) {
|
|
@@ -1631,6 +1716,8 @@
|
|
|
1631
1716
|
|
|
1632
1717
|
/**
|
|
1633
1718
|
* This error indicates errors during the execution of the pipeline
|
|
1719
|
+
*
|
|
1720
|
+
* @public exported from `@promptbook/core`
|
|
1634
1721
|
*/
|
|
1635
1722
|
var PipelineExecutionError = /** @class */ (function (_super) {
|
|
1636
1723
|
__extends(PipelineExecutionError, _super);
|
|
@@ -1648,6 +1735,7 @@
|
|
|
1648
1735
|
*
|
|
1649
1736
|
* @param executionResult - The partial result of the promptnook execution
|
|
1650
1737
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
1738
|
+
* @public exported from `@promptbook/core`
|
|
1651
1739
|
*/
|
|
1652
1740
|
function assertsExecutionSuccessful(executionResult) {
|
|
1653
1741
|
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
@@ -1678,6 +1766,7 @@
|
|
|
1678
1766
|
* @param script from which to extract the variables
|
|
1679
1767
|
* @returns the list of variable names
|
|
1680
1768
|
* @throws {ParsingError} if the script is invalid
|
|
1769
|
+
* @public exported from `@promptbook/utils`
|
|
1681
1770
|
*/
|
|
1682
1771
|
function extractVariables(script) {
|
|
1683
1772
|
var variables = new Set();
|
|
@@ -1726,6 +1815,7 @@
|
|
|
1726
1815
|
* @param promptTemplate the template with used parameters
|
|
1727
1816
|
* @returns the set of parameter names
|
|
1728
1817
|
* @throws {ParsingError} if the script is invalid
|
|
1818
|
+
* @public exported from `@promptbook/utils`
|
|
1729
1819
|
*/
|
|
1730
1820
|
function extractParameterNamesFromPromptTemplate(promptTemplate) {
|
|
1731
1821
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
@@ -1799,6 +1889,8 @@
|
|
|
1799
1889
|
|
|
1800
1890
|
/**
|
|
1801
1891
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1892
|
+
*
|
|
1893
|
+
* @public exported from `@promptbook/utils`
|
|
1802
1894
|
*/
|
|
1803
1895
|
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
1804
1896
|
try {
|
|
@@ -2025,6 +2117,8 @@
|
|
|
2025
2117
|
*
|
|
2026
2118
|
*
|
|
2027
2119
|
* Tip: You don't have to use this function directly, just pass an array of LlmExecutionTools to the `ExecutionTools`
|
|
2120
|
+
*
|
|
2121
|
+
* @public exported from `@promptbook/core`
|
|
2028
2122
|
*/
|
|
2029
2123
|
function joinLlmExecutionTools() {
|
|
2030
2124
|
var llmExecutionTools = [];
|
|
@@ -2064,6 +2158,8 @@
|
|
|
2064
2158
|
|
|
2065
2159
|
/**
|
|
2066
2160
|
* Determine if the pipeline is fully prepared
|
|
2161
|
+
*
|
|
2162
|
+
* @public exported from `@promptbook/core`
|
|
2067
2163
|
*/
|
|
2068
2164
|
function isPipelinePrepared(pipeline) {
|
|
2069
2165
|
// Note: Ignoring `pipeline.preparations` @@@
|
|
@@ -2084,7 +2180,6 @@
|
|
|
2084
2180
|
}
|
|
2085
2181
|
/**
|
|
2086
2182
|
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2087
|
-
* TODO: [🔼] Export via core or utils
|
|
2088
2183
|
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2089
2184
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2090
2185
|
* - [🏍] ? Is context in each template
|
|
@@ -2130,6 +2225,8 @@
|
|
|
2130
2225
|
|
|
2131
2226
|
/**
|
|
2132
2227
|
* This error type indicates that some limit was reached
|
|
2228
|
+
*
|
|
2229
|
+
* @public exported from `@promptbook/core`
|
|
2133
2230
|
*/
|
|
2134
2231
|
var LimitReachedError = /** @class */ (function (_super) {
|
|
2135
2232
|
__extends(LimitReachedError, _super);
|
|
@@ -2149,6 +2246,7 @@
|
|
|
2149
2246
|
* @param parameters the object with parameters
|
|
2150
2247
|
* @returns the template with replaced parameters
|
|
2151
2248
|
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
2249
|
+
* @public exported from `@promptbook/utils`
|
|
2152
2250
|
*/
|
|
2153
2251
|
function replaceParameters(template, parameters) {
|
|
2154
2252
|
var e_1, _a;
|
|
@@ -2224,6 +2322,7 @@
|
|
|
2224
2322
|
* Create difference set of two sets.
|
|
2225
2323
|
*
|
|
2226
2324
|
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2325
|
+
* @public exported from `@promptbook/utils`
|
|
2227
2326
|
*/
|
|
2228
2327
|
function difference(a, b, isEqual) {
|
|
2229
2328
|
var e_1, _a;
|
|
@@ -2257,6 +2356,7 @@
|
|
|
2257
2356
|
* Creates a new set with all elements that are present in either set
|
|
2258
2357
|
*
|
|
2259
2358
|
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2359
|
+
* @public exported from `@promptbook/utils`
|
|
2260
2360
|
*/
|
|
2261
2361
|
function union() {
|
|
2262
2362
|
var e_1, _a, e_2, _b;
|
|
@@ -2293,14 +2393,10 @@
|
|
|
2293
2393
|
return union;
|
|
2294
2394
|
}
|
|
2295
2395
|
|
|
2296
|
-
/**
|
|
2297
|
-
* The version of the Promptbook library
|
|
2298
|
-
*/
|
|
2299
|
-
var PROMPTBOOK_VERSION = '0.62.0-1';
|
|
2300
|
-
// TODO: !!!! List here all the versions and annotate + put into script
|
|
2301
|
-
|
|
2302
2396
|
/**
|
|
2303
2397
|
* Counts number of characters in the text
|
|
2398
|
+
*
|
|
2399
|
+
* @public exported from `@promptbook/utils`
|
|
2304
2400
|
*/
|
|
2305
2401
|
function countCharacters(text) {
|
|
2306
2402
|
// Remove null characters
|
|
@@ -2314,6 +2410,8 @@
|
|
|
2314
2410
|
|
|
2315
2411
|
/**
|
|
2316
2412
|
* Counts number of lines in the text
|
|
2413
|
+
*
|
|
2414
|
+
* @public exported from `@promptbook/utils`
|
|
2317
2415
|
*/
|
|
2318
2416
|
function countLines(text) {
|
|
2319
2417
|
if (text === '') {
|
|
@@ -2324,6 +2422,8 @@
|
|
|
2324
2422
|
|
|
2325
2423
|
/**
|
|
2326
2424
|
* Counts number of pages in the text
|
|
2425
|
+
*
|
|
2426
|
+
* @public exported from `@promptbook/utils`
|
|
2327
2427
|
*/
|
|
2328
2428
|
function countPages(text) {
|
|
2329
2429
|
var sentencesPerPage = 5; // Assuming each page has 5 sentences
|
|
@@ -2334,6 +2434,8 @@
|
|
|
2334
2434
|
|
|
2335
2435
|
/**
|
|
2336
2436
|
* Counts number of paragraphs in the text
|
|
2437
|
+
*
|
|
2438
|
+
* @public exported from `@promptbook/utils`
|
|
2337
2439
|
*/
|
|
2338
2440
|
function countParagraphs(text) {
|
|
2339
2441
|
return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
|
|
@@ -2341,12 +2443,16 @@
|
|
|
2341
2443
|
|
|
2342
2444
|
/**
|
|
2343
2445
|
* Split text into sentences
|
|
2446
|
+
*
|
|
2447
|
+
* @public exported from `@promptbook/utils`
|
|
2344
2448
|
*/
|
|
2345
2449
|
function splitIntoSentences(text) {
|
|
2346
2450
|
return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
2347
2451
|
}
|
|
2348
2452
|
/**
|
|
2349
2453
|
* Counts number of sentences in the text
|
|
2454
|
+
*
|
|
2455
|
+
* @public exported from `@promptbook/utils`
|
|
2350
2456
|
*/
|
|
2351
2457
|
function countSentences(text) {
|
|
2352
2458
|
return splitIntoSentences(text).length;
|
|
@@ -2354,6 +2460,8 @@
|
|
|
2354
2460
|
|
|
2355
2461
|
/**
|
|
2356
2462
|
* Counts number of words in the text
|
|
2463
|
+
*
|
|
2464
|
+
* @public exported from `@promptbook/utils`
|
|
2357
2465
|
*/
|
|
2358
2466
|
function countWords(text) {
|
|
2359
2467
|
text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
|
|
@@ -2363,6 +2471,8 @@
|
|
|
2363
2471
|
|
|
2364
2472
|
/**
|
|
2365
2473
|
* Index of all counter functions
|
|
2474
|
+
*
|
|
2475
|
+
* @public exported from `@promptbook/utils`
|
|
2366
2476
|
*/
|
|
2367
2477
|
var CountUtils = {
|
|
2368
2478
|
CHARACTERS: countCharacters,
|
|
@@ -2382,6 +2492,7 @@
|
|
|
2382
2492
|
*
|
|
2383
2493
|
* @throws {ExpectError} if the expectations are not met
|
|
2384
2494
|
* @returns {void} Nothing
|
|
2495
|
+
* @public exported from `@promptbook/core`
|
|
2385
2496
|
*/
|
|
2386
2497
|
function checkExpectations(expectations, value) {
|
|
2387
2498
|
var e_1, _a;
|
|
@@ -2414,6 +2525,7 @@
|
|
|
2414
2525
|
*
|
|
2415
2526
|
* @returns The executor function
|
|
2416
2527
|
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
2528
|
+
* @public exported from `@promptbook/core`
|
|
2417
2529
|
*/
|
|
2418
2530
|
function createPipelineExecutor(options) {
|
|
2419
2531
|
var _this = this;
|
|
@@ -3202,6 +3314,8 @@
|
|
|
3202
3314
|
|
|
3203
3315
|
/**
|
|
3204
3316
|
* @@@
|
|
3317
|
+
*
|
|
3318
|
+
* @public exported from `@promptbook/core`
|
|
3205
3319
|
*/
|
|
3206
3320
|
function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
|
|
3207
3321
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3337,6 +3451,7 @@
|
|
|
3337
3451
|
* Prepares the knowle
|
|
3338
3452
|
*
|
|
3339
3453
|
* @see https://github.com/webgptorg/promptbook/discussions/41
|
|
3454
|
+
* @public exported from `@promptbook/core`
|
|
3340
3455
|
*/
|
|
3341
3456
|
function prepareKnowledgePieces(knowledgeSources, options) {
|
|
3342
3457
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3351,7 +3466,7 @@
|
|
|
3351
3466
|
var partialPieces, pieces;
|
|
3352
3467
|
return __generator(this, function (_a) {
|
|
3353
3468
|
switch (_a.label) {
|
|
3354
|
-
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝] !!! Unhardcode markdown, detect which type it is
|
|
3469
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝] !!! Unhardcode markdown, detect which type it is - BE AWARE of big package size
|
|
3355
3470
|
options)];
|
|
3356
3471
|
case 1:
|
|
3357
3472
|
partialPieces = _a.sent();
|
|
@@ -3389,7 +3504,6 @@
|
|
|
3389
3504
|
> ):
|
|
3390
3505
|
*/
|
|
3391
3506
|
/**
|
|
3392
|
-
* TODO: [🐝][🔼] !!! Export via `@promptbook/core`
|
|
3393
3507
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
3394
3508
|
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
3395
3509
|
* TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
|
|
@@ -3403,6 +3517,7 @@
|
|
|
3403
3517
|
*
|
|
3404
3518
|
* @param llmTools LLM tools to be intercepted with usage counting
|
|
3405
3519
|
* @returns LLM tools with same functionality with added total cost counting
|
|
3520
|
+
* @public exported from `@promptbook/core`
|
|
3406
3521
|
*/
|
|
3407
3522
|
function countTotalUsage(llmTools) {
|
|
3408
3523
|
var _this = this;
|
|
@@ -3470,7 +3585,6 @@
|
|
|
3470
3585
|
return proxyTools;
|
|
3471
3586
|
}
|
|
3472
3587
|
/**
|
|
3473
|
-
* TODO: [🔼] !!! Export via `@promptbookcore/`
|
|
3474
3588
|
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
3475
3589
|
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
3476
3590
|
* TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
|
|
@@ -3482,6 +3596,7 @@
|
|
|
3482
3596
|
* Prepares the persona for the pipeline
|
|
3483
3597
|
*
|
|
3484
3598
|
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
3599
|
+
* @public exported from `@promptbook/core`
|
|
3485
3600
|
*/
|
|
3486
3601
|
function preparePersona(personaDescription, options) {
|
|
3487
3602
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3536,7 +3651,6 @@
|
|
|
3536
3651
|
});
|
|
3537
3652
|
}
|
|
3538
3653
|
/**
|
|
3539
|
-
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3540
3654
|
* TODO: [🏢] !! Check validity of `modelName` in pipeline
|
|
3541
3655
|
* TODO: [🏢] !! Check validity of `systemMessage` in pipeline
|
|
3542
3656
|
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
@@ -3544,6 +3658,8 @@
|
|
|
3544
3658
|
|
|
3545
3659
|
/**
|
|
3546
3660
|
* @@@
|
|
3661
|
+
*
|
|
3662
|
+
* @public exported from `@promptbook/core`
|
|
3547
3663
|
*/
|
|
3548
3664
|
function prepareTemplates(pipeline, options) {
|
|
3549
3665
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3585,7 +3701,6 @@
|
|
|
3585
3701
|
* TODO: [🧠] Add context to each template (if missing)
|
|
3586
3702
|
* TODO: [🧠] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
|
|
3587
3703
|
* TODO: [♨] !!! Prepare index the samples and maybe templates
|
|
3588
|
-
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3589
3704
|
* TODO: Write tests for `preparePipeline`
|
|
3590
3705
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3591
3706
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -3598,6 +3713,7 @@
|
|
|
3598
3713
|
*
|
|
3599
3714
|
* Note: This function does not validate logic of the pipeline
|
|
3600
3715
|
* Note: This function acts as part of compilation process
|
|
3716
|
+
* @public exported from `@promptbook/core`
|
|
3601
3717
|
*/
|
|
3602
3718
|
function preparePipeline(pipeline, options) {
|
|
3603
3719
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3674,7 +3790,6 @@
|
|
|
3674
3790
|
});
|
|
3675
3791
|
}
|
|
3676
3792
|
/**
|
|
3677
|
-
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3678
3793
|
* TODO: Write tests for `preparePipeline`
|
|
3679
3794
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3680
3795
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -3685,6 +3800,7 @@
|
|
|
3685
3800
|
* Tests if given string is valid URL.
|
|
3686
3801
|
*
|
|
3687
3802
|
* Note: This does not check if the file exists only if the path is valid
|
|
3803
|
+
* @public exported from `@promptbook/utils`
|
|
3688
3804
|
*/
|
|
3689
3805
|
function isValidFilePath(filePath) {
|
|
3690
3806
|
if (typeof filePath !== 'string') {
|
|
@@ -3867,6 +3983,7 @@
|
|
|
3867
3983
|
*
|
|
3868
3984
|
* @param {string} str - The string to remove Markdown tags from.
|
|
3869
3985
|
* @returns {string} The input string with all Markdown tags removed.
|
|
3986
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
3870
3987
|
*/
|
|
3871
3988
|
function removeMarkdownFormatting(str) {
|
|
3872
3989
|
// Remove bold formatting
|
|
@@ -3878,6 +3995,15 @@
|
|
|
3878
3995
|
return str;
|
|
3879
3996
|
}
|
|
3880
3997
|
|
|
3998
|
+
/**
|
|
3999
|
+
* @@@
|
|
4000
|
+
*
|
|
4001
|
+
* @param text @@@
|
|
4002
|
+
* @returns @@@
|
|
4003
|
+
* @example 'HELLO_WORLD'
|
|
4004
|
+
* @example 'I_LOVE_PROMPTBOOK'
|
|
4005
|
+
* @public exported from `@promptbook/utils`
|
|
4006
|
+
*/
|
|
3881
4007
|
function normalizeTo_SCREAMING_CASE(text) {
|
|
3882
4008
|
var e_1, _a;
|
|
3883
4009
|
var charType;
|
|
@@ -3943,6 +4069,7 @@
|
|
|
3943
4069
|
* Block type describes the way how the block is blockd
|
|
3944
4070
|
*
|
|
3945
4071
|
* @see https://github.com/webgptorg/promptbook#block-type
|
|
4072
|
+
* @public exported from `@promptbook/core`
|
|
3946
4073
|
*/
|
|
3947
4074
|
var BlockTypes = [
|
|
3948
4075
|
'PROMPT_TEMPLATE',
|
|
@@ -4062,7 +4189,7 @@
|
|
|
4062
4189
|
* @returns parsed number
|
|
4063
4190
|
* @throws {ParsingError} if the value is not a number
|
|
4064
4191
|
*
|
|
4065
|
-
* @
|
|
4192
|
+
* @public exported from `@promptbook/utils`
|
|
4066
4193
|
*/
|
|
4067
4194
|
function parseNumber(value) {
|
|
4068
4195
|
var originalValue = value;
|
|
@@ -4118,6 +4245,7 @@
|
|
|
4118
4245
|
}
|
|
4119
4246
|
/**
|
|
4120
4247
|
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
4248
|
+
* TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
|
|
4121
4249
|
*/
|
|
4122
4250
|
|
|
4123
4251
|
/**
|
|
@@ -4429,6 +4557,13 @@
|
|
|
4429
4557
|
},
|
|
4430
4558
|
};
|
|
4431
4559
|
|
|
4560
|
+
/**
|
|
4561
|
+
* @@@
|
|
4562
|
+
*
|
|
4563
|
+
* @param javascriptName @@@
|
|
4564
|
+
* @returns @@@
|
|
4565
|
+
* @public exported from `@promptbook/utils`
|
|
4566
|
+
*/
|
|
4432
4567
|
function isValidJavascriptName(javascriptName) {
|
|
4433
4568
|
if (typeof javascriptName !== 'string') {
|
|
4434
4569
|
return false;
|
|
@@ -4901,6 +5036,8 @@
|
|
|
4901
5036
|
|
|
4902
5037
|
/**
|
|
4903
5038
|
* This error type indicates that some part of the code is not implemented yet
|
|
5039
|
+
*
|
|
5040
|
+
* @public exported from `@promptbook/core`
|
|
4904
5041
|
*/
|
|
4905
5042
|
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
4906
5043
|
__extends(NotYetImplementedError, _super);
|
|
@@ -4927,7 +5064,8 @@
|
|
|
4927
5064
|
* Note: It can not work with html syntax and comments
|
|
4928
5065
|
*
|
|
4929
5066
|
* @param markdown any valid markdown
|
|
4930
|
-
* @returns
|
|
5067
|
+
* @returns @@@
|
|
5068
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
4931
5069
|
*/
|
|
4932
5070
|
function extractAllListItemsFromMarkdown(markdown) {
|
|
4933
5071
|
var e_1, _a;
|
|
@@ -4967,7 +5105,7 @@
|
|
|
4967
5105
|
*
|
|
4968
5106
|
* @param markdown any valid markdown
|
|
4969
5107
|
* @returns code blocks with language and content
|
|
4970
|
-
*
|
|
5108
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
4971
5109
|
*/
|
|
4972
5110
|
function extractAllBlocksFromMarkdown(markdown) {
|
|
4973
5111
|
var e_1, _a;
|
|
@@ -5044,6 +5182,7 @@
|
|
|
5044
5182
|
*
|
|
5045
5183
|
* @param markdown any valid markdown
|
|
5046
5184
|
* @returns code block with language and content
|
|
5185
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5047
5186
|
*/
|
|
5048
5187
|
function extractOneBlockFromMarkdown(markdown) {
|
|
5049
5188
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
@@ -5058,6 +5197,8 @@
|
|
|
5058
5197
|
|
|
5059
5198
|
/**
|
|
5060
5199
|
* Parses markdown section to title its level and content
|
|
5200
|
+
*
|
|
5201
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5061
5202
|
*/
|
|
5062
5203
|
function parseMarkdownSection(value) {
|
|
5063
5204
|
var _a, _b;
|
|
@@ -5082,6 +5223,8 @@
|
|
|
5082
5223
|
|
|
5083
5224
|
/**
|
|
5084
5225
|
* Splits the markdown into sections by headings
|
|
5226
|
+
*
|
|
5227
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5085
5228
|
*/
|
|
5086
5229
|
function splitMarkdownIntoSections(markdown) {
|
|
5087
5230
|
var e_1, _a;
|
|
@@ -5143,6 +5286,7 @@
|
|
|
5143
5286
|
return sections;
|
|
5144
5287
|
}
|
|
5145
5288
|
/**
|
|
5289
|
+
* TODO: [🏛] This can be part of markdown builder
|
|
5146
5290
|
* Note: [🕞] In past (commit 42086e1603cbed506482997c00a8ee979af0a247) there was much more
|
|
5147
5291
|
* sophisticated implementation of this function through parsing markdown into JSON structure
|
|
5148
5292
|
* and flattening the actual structure
|
|
@@ -5154,6 +5298,8 @@
|
|
|
5154
5298
|
*
|
|
5155
5299
|
* - It always have h1 - if there is no h1 in the markdown, it will be added "# Untitled"
|
|
5156
5300
|
* - All other headings are normalized to h2
|
|
5301
|
+
*
|
|
5302
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5157
5303
|
*/
|
|
5158
5304
|
function flattenMarkdown(markdown) {
|
|
5159
5305
|
var e_1, _a;
|
|
@@ -5189,6 +5335,7 @@
|
|
|
5189
5335
|
return spaceTrim__default["default"](flattenedMarkdown);
|
|
5190
5336
|
}
|
|
5191
5337
|
/**
|
|
5338
|
+
* TODO: [🏛] This can be part of markdown builder
|
|
5192
5339
|
* Note: [🕞] In past (commit 42086e1603cbed506482997c00a8ee979af0a247) there was much more
|
|
5193
5340
|
* sophisticated implementation of this function through parsing markdown into JSON structure
|
|
5194
5341
|
* and flattening the actual structure
|
|
@@ -5200,6 +5347,7 @@
|
|
|
5200
5347
|
*
|
|
5201
5348
|
* @param {string} content - The string to remove comments from.
|
|
5202
5349
|
* @returns {string} The input string with all comments removed.
|
|
5350
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5203
5351
|
*/
|
|
5204
5352
|
function removeContentComments(content) {
|
|
5205
5353
|
return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
@@ -5213,12 +5361,13 @@
|
|
|
5213
5361
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
5214
5362
|
* - `preparePipeline` - just one step in the compilation process
|
|
5215
5363
|
*
|
|
5364
|
+
* Note: This function does not validate logic of the pipeline only the syntax
|
|
5365
|
+
* Note: This function acts as compilation process
|
|
5366
|
+
*
|
|
5216
5367
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
5217
5368
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
5218
5369
|
* @throws {ParsingError} if the promptbook string is not valid
|
|
5219
|
-
*
|
|
5220
|
-
* Note: This function does not validate logic of the pipeline only the syntax
|
|
5221
|
-
* Note: This function acts as compilation process
|
|
5370
|
+
* @public exported from `@promptbook/core`
|
|
5222
5371
|
*/
|
|
5223
5372
|
function pipelineStringToJsonSync(pipelineString) {
|
|
5224
5373
|
var e_1, _a, e_2, _b;
|
|
@@ -5611,13 +5760,14 @@
|
|
|
5611
5760
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
5612
5761
|
* - `preparePipeline` - just one step in the compilation process
|
|
5613
5762
|
*
|
|
5763
|
+
* Note: This function does not validate logic of the pipeline only the syntax
|
|
5764
|
+
* Note: This function acts as compilation process
|
|
5765
|
+
*
|
|
5614
5766
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
5615
5767
|
* @param options - Options and tools for the compilation
|
|
5616
5768
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
5617
5769
|
* @throws {ParsingError} if the promptbook string is not valid
|
|
5618
|
-
*
|
|
5619
|
-
* Note: This function does not validate logic of the pipeline only the syntax
|
|
5620
|
-
* Note: This function acts as compilation process
|
|
5770
|
+
* @public exported from `@promptbook/core`
|
|
5621
5771
|
*/
|
|
5622
5772
|
function pipelineStringToJson(pipelineString, options) {
|
|
5623
5773
|
if (options === void 0) { options = { llmTools: null }; }
|
|
@@ -5645,6 +5795,8 @@
|
|
|
5645
5795
|
|
|
5646
5796
|
/**
|
|
5647
5797
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
5798
|
+
*
|
|
5799
|
+
* @public exported from `@promptbook/core`
|
|
5648
5800
|
*/
|
|
5649
5801
|
var CollectionError = /** @class */ (function (_super) {
|
|
5650
5802
|
__extends(CollectionError, _super);
|
|
@@ -5659,19 +5811,22 @@
|
|
|
5659
5811
|
|
|
5660
5812
|
/**
|
|
5661
5813
|
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
|
5814
|
+
*
|
|
5815
|
+
* @public exported from `@promptbook/utils`
|
|
5662
5816
|
*/
|
|
5663
5817
|
new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
|
|
5664
5818
|
/**
|
|
5665
5819
|
* Detects if the code is running in a Node.js environment
|
|
5820
|
+
*
|
|
5821
|
+
* @public exported from `@promptbook/utils`
|
|
5666
5822
|
*/
|
|
5667
5823
|
var isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
5668
5824
|
/**
|
|
5669
5825
|
* Detects if the code is running in a web worker
|
|
5826
|
+
*
|
|
5827
|
+
* @public exported from `@promptbook/utils`
|
|
5670
5828
|
*/
|
|
5671
5829
|
new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
|
|
5672
|
-
/**
|
|
5673
|
-
* TODO: [🔼] !!! Export via `@promptbook/utils`
|
|
5674
|
-
*/
|
|
5675
5830
|
|
|
5676
5831
|
/**
|
|
5677
5832
|
* Constructs Promptbook from async sources
|
|
@@ -5691,6 +5846,7 @@
|
|
|
5691
5846
|
* @param promptbookSourcesPromiseOrFactory
|
|
5692
5847
|
* @returns PipelineCollection
|
|
5693
5848
|
* @deprecated Do not use, it will became internal tool for other constructor functions
|
|
5849
|
+
* @public exported from `@promptbook/core`
|
|
5694
5850
|
*/
|
|
5695
5851
|
function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
5696
5852
|
var collection = null;
|
|
@@ -5767,6 +5923,7 @@
|
|
|
5767
5923
|
* @param path - path to the directory with pipelines
|
|
5768
5924
|
* @param options - Misc options for the collection
|
|
5769
5925
|
* @returns PipelineCollection
|
|
5926
|
+
* @public exported from `@promptbook/node`
|
|
5770
5927
|
*/
|
|
5771
5928
|
function createCollectionFromDirectory(path$1, options) {
|
|
5772
5929
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -6011,6 +6168,8 @@
|
|
|
6011
6168
|
|
|
6012
6169
|
/**
|
|
6013
6170
|
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
6171
|
+
*
|
|
6172
|
+
* @public exported from `@promptbook/core`
|
|
6014
6173
|
*/
|
|
6015
6174
|
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
6016
6175
|
__extends(EnvironmentMismatchError, _super);
|
|
@@ -6149,6 +6308,8 @@
|
|
|
6149
6308
|
|
|
6150
6309
|
/**
|
|
6151
6310
|
* Execution Tools for calling Anthropic Claude API.
|
|
6311
|
+
*
|
|
6312
|
+
* @public exported from `@promptbook/anthropic-claude`
|
|
6152
6313
|
*/
|
|
6153
6314
|
var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
6154
6315
|
/**
|
|
@@ -6374,6 +6535,7 @@
|
|
|
6374
6535
|
*
|
|
6375
6536
|
* @see https://platform.openai.com/docs/models/
|
|
6376
6537
|
* @see https://openai.com/api/pricing/
|
|
6538
|
+
* @public exported from `@promptbook/openai`
|
|
6377
6539
|
*/
|
|
6378
6540
|
var OPENAI_MODELS = [
|
|
6379
6541
|
/*/
|
|
@@ -6754,6 +6916,8 @@
|
|
|
6754
6916
|
|
|
6755
6917
|
/**
|
|
6756
6918
|
* Execution Tools for calling OpenAI API.
|
|
6919
|
+
*
|
|
6920
|
+
* @public exported from `@promptbook/openai`
|
|
6757
6921
|
*/
|
|
6758
6922
|
var OpenAiExecutionTools = /** @class */ (function () {
|
|
6759
6923
|
/**
|
|
@@ -7065,6 +7229,7 @@
|
|
|
7065
7229
|
* - `process.env.ANTHROPIC_CLAUDE_API_KEY`
|
|
7066
7230
|
*
|
|
7067
7231
|
* @returns @@@
|
|
7232
|
+
* @public exported from `@promptbook/node`
|
|
7068
7233
|
*/
|
|
7069
7234
|
function createLlmToolsFromEnv(options) {
|
|
7070
7235
|
if (options === void 0) { options = {}; }
|
|
@@ -7098,7 +7263,6 @@
|
|
|
7098
7263
|
}
|
|
7099
7264
|
/**
|
|
7100
7265
|
* TODO: [🍜] Use `createLlmToolsFromConfiguration`
|
|
7101
|
-
* TODO: [🔼] !!! Export via `@promptbook/node`
|
|
7102
7266
|
* TODO: @@@ write discussion about this - wizzard
|
|
7103
7267
|
* TODO: Add Azure
|
|
7104
7268
|
* TODO: [🧠] Which name is better `createLlmToolsFromEnv` or `createLlmToolsFromEnvironment`?
|
|
@@ -7108,6 +7272,137 @@
|
|
|
7108
7272
|
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
7109
7273
|
*/
|
|
7110
7274
|
|
|
7275
|
+
/**
|
|
7276
|
+
* Stringify the PipelineJson with proper formatting
|
|
7277
|
+
*
|
|
7278
|
+
* Note: [0] It can be used for more JSON types like whole collection of pipelines, single knowledge piece, etc.
|
|
7279
|
+
* Note: In contrast to JSON.stringify, this function ensures that **embedding index** is on single line
|
|
7280
|
+
*
|
|
7281
|
+
* @public exported from `@promptbook/core`
|
|
7282
|
+
*/
|
|
7283
|
+
function stringifyPipelineJson(pipeline) {
|
|
7284
|
+
var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
|
|
7285
|
+
for (var i = 0; i < LOOP_LIMIT; i++) {
|
|
7286
|
+
pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms, "$1".concat(REPLACING_NONCE, "$2"));
|
|
7287
|
+
}
|
|
7288
|
+
pipelineJsonStringified = pipelineJsonStringified.split(REPLACING_NONCE).join(', ');
|
|
7289
|
+
pipelineJsonStringified += '\n';
|
|
7290
|
+
return pipelineJsonStringified;
|
|
7291
|
+
}
|
|
7292
|
+
/**
|
|
7293
|
+
* TODO: [🐝] Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
|
|
7294
|
+
* TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
|
|
7295
|
+
* TODO: [🧠] Maybe more elegant solution than replacing via regex
|
|
7296
|
+
* TODO: [🍙] Make some standart order of json properties
|
|
7297
|
+
*/
|
|
7298
|
+
|
|
7299
|
+
/**
|
|
7300
|
+
* @@@
|
|
7301
|
+
*
|
|
7302
|
+
* @private for `FilesStorage`
|
|
7303
|
+
*/
|
|
7304
|
+
function nameToSubfolderPath(name) {
|
|
7305
|
+
return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
|
|
7306
|
+
}
|
|
7307
|
+
|
|
7308
|
+
/**
|
|
7309
|
+
* @@@
|
|
7310
|
+
*
|
|
7311
|
+
* @public exported from `@promptbook/node`
|
|
7312
|
+
*/
|
|
7313
|
+
var FilesStorage = /** @class */ (function () {
|
|
7314
|
+
function FilesStorage(options) {
|
|
7315
|
+
this.options = options;
|
|
7316
|
+
if (!isRunningInNode()) {
|
|
7317
|
+
throw new EnvironmentMismatchError("FilesStorage works only in Node.js environment");
|
|
7318
|
+
}
|
|
7319
|
+
}
|
|
7320
|
+
/**
|
|
7321
|
+
* @@@
|
|
7322
|
+
*/
|
|
7323
|
+
FilesStorage.prototype.getFilenameForKey = function (key) {
|
|
7324
|
+
var name = titleToName(key);
|
|
7325
|
+
var hash = sha256__default["default"](hexEncoder__default["default"].parse(name)).toString( /* hex */);
|
|
7326
|
+
return path.join.apply(void 0, __spreadArray(__spreadArray([this.options.cacheFolderPath], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(name.substring(0, MAX_FILENAME_LENGTH), ".json")], false));
|
|
7327
|
+
};
|
|
7328
|
+
/**
|
|
7329
|
+
* @@@ Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object.
|
|
7330
|
+
*/
|
|
7331
|
+
FilesStorage.prototype.getItem = function (key) {
|
|
7332
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7333
|
+
var filename, isFileExisting, fileContent, value;
|
|
7334
|
+
return __generator(this, function (_a) {
|
|
7335
|
+
switch (_a.label) {
|
|
7336
|
+
case 0:
|
|
7337
|
+
filename = this.getFilenameForKey(key);
|
|
7338
|
+
return [4 /*yield*/, promises.stat(filename)
|
|
7339
|
+
.then(function (fileStat) { return fileStat.isFile(); })
|
|
7340
|
+
.catch(function () { return false; })];
|
|
7341
|
+
case 1:
|
|
7342
|
+
isFileExisting = _a.sent();
|
|
7343
|
+
if (!isFileExisting) {
|
|
7344
|
+
return [2 /*return*/, null];
|
|
7345
|
+
}
|
|
7346
|
+
return [4 /*yield*/, promises.readFile(filename, 'utf-8')];
|
|
7347
|
+
case 2:
|
|
7348
|
+
fileContent = _a.sent();
|
|
7349
|
+
value = JSON.parse(fileContent);
|
|
7350
|
+
// TODO: [🌗]
|
|
7351
|
+
return [2 /*return*/, value];
|
|
7352
|
+
}
|
|
7353
|
+
});
|
|
7354
|
+
});
|
|
7355
|
+
};
|
|
7356
|
+
/**
|
|
7357
|
+
* @@@ Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
|
|
7358
|
+
*/
|
|
7359
|
+
FilesStorage.prototype.setItem = function (key, value) {
|
|
7360
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7361
|
+
var filename, fileContent;
|
|
7362
|
+
return __generator(this, function (_a) {
|
|
7363
|
+
switch (_a.label) {
|
|
7364
|
+
case 0:
|
|
7365
|
+
filename = this.getFilenameForKey(key);
|
|
7366
|
+
fileContent = stringifyPipelineJson(value);
|
|
7367
|
+
return [4 /*yield*/, promises.mkdir(path.dirname(filename), { recursive: true })];
|
|
7368
|
+
case 1:
|
|
7369
|
+
_a.sent(); // <- [0]
|
|
7370
|
+
return [4 /*yield*/, promises.writeFile(filename, fileContent, 'utf-8')];
|
|
7371
|
+
case 2:
|
|
7372
|
+
_a.sent();
|
|
7373
|
+
return [2 /*return*/];
|
|
7374
|
+
}
|
|
7375
|
+
});
|
|
7376
|
+
});
|
|
7377
|
+
};
|
|
7378
|
+
/**
|
|
7379
|
+
* @@@ Removes the key/value pair with the given key from the list associated with the object, if a key/value pair with the given key exists.
|
|
7380
|
+
*/
|
|
7381
|
+
FilesStorage.prototype.removeItem = function (key) {
|
|
7382
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7383
|
+
var filename;
|
|
7384
|
+
return __generator(this, function (_a) {
|
|
7385
|
+
switch (_a.label) {
|
|
7386
|
+
case 0:
|
|
7387
|
+
filename = this.getFilenameForKey(key);
|
|
7388
|
+
// TODO: [🧠] What to use `unlink` or `rm`
|
|
7389
|
+
return [4 /*yield*/, promises.unlink(filename)];
|
|
7390
|
+
case 1:
|
|
7391
|
+
// TODO: [🧠] What to use `unlink` or `rm`
|
|
7392
|
+
_a.sent();
|
|
7393
|
+
return [2 /*return*/];
|
|
7394
|
+
}
|
|
7395
|
+
});
|
|
7396
|
+
});
|
|
7397
|
+
};
|
|
7398
|
+
return FilesStorage;
|
|
7399
|
+
}());
|
|
7400
|
+
/**
|
|
7401
|
+
* TODO: [🌗] Maybe some checkers, not all valid JSONs are desired and valid values
|
|
7402
|
+
* Note: [🟢] This code should never be published outside of `@promptbook/node`
|
|
7403
|
+
*/
|
|
7404
|
+
|
|
7405
|
+
exports.FilesStorage = FilesStorage;
|
|
7111
7406
|
exports.PROMPTBOOK_VERSION = PROMPTBOOK_VERSION;
|
|
7112
7407
|
exports.createCollectionFromDirectory = createCollectionFromDirectory;
|
|
7113
7408
|
exports.createLlmToolsFromEnv = createLlmToolsFromEnv;
|