@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/esm/index.es.js
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import colors from 'colors';
|
|
2
|
-
import { access, constants, readFile, readdir } from 'fs/promises';
|
|
3
|
-
import { join } from 'path';
|
|
2
|
+
import { access, constants, readFile, readdir, stat, writeFile, mkdir, unlink } from 'fs/promises';
|
|
3
|
+
import { join, dirname } from 'path';
|
|
4
4
|
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
5
5
|
import { format } from 'prettier';
|
|
6
6
|
import parserHtml from 'prettier/parser-html';
|
|
7
7
|
import * as dotenv from 'dotenv';
|
|
8
8
|
import Anthropic from '@anthropic-ai/sdk';
|
|
9
9
|
import OpenAI from 'openai';
|
|
10
|
+
import hexEncoder from 'crypto-js/enc-hex';
|
|
11
|
+
import sha256 from 'crypto-js/sha256';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The version of the Promptbook library
|
|
15
|
+
*
|
|
16
|
+
* @public exported from all packages
|
|
17
|
+
*/
|
|
18
|
+
var PROMPTBOOK_VERSION = '0.62.0';
|
|
19
|
+
// TODO: !!!! List here all the versions and annotate + put into script
|
|
10
20
|
|
|
11
21
|
/*! *****************************************************************************
|
|
12
22
|
Copyright (c) Microsoft Corporation.
|
|
@@ -160,6 +170,7 @@ function deepFreeze(objectValue) {
|
|
|
160
170
|
* @@@
|
|
161
171
|
*
|
|
162
172
|
* @returns The same object as the input, but deeply frozen
|
|
173
|
+
* @public exported from `@promptbook/utils`
|
|
163
174
|
*
|
|
164
175
|
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
165
176
|
*/
|
|
@@ -167,24 +178,37 @@ function deepFreezeWithSameType(objectValue) {
|
|
|
167
178
|
return deepFreeze(objectValue);
|
|
168
179
|
}
|
|
169
180
|
/**
|
|
170
|
-
* TODO: [🔼] Export from `@promptbook/utils`
|
|
171
181
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
172
182
|
*/
|
|
173
183
|
|
|
174
184
|
/**
|
|
175
185
|
* The maximum number of iterations for a loops
|
|
186
|
+
*
|
|
187
|
+
* @private within the repository - too low-level in comparison to other `MAX_...`
|
|
176
188
|
*/
|
|
177
189
|
var LOOP_LIMIT = 1000;
|
|
178
190
|
/**
|
|
179
191
|
* The maximum number of (LLM) tasks running in parallel
|
|
192
|
+
*
|
|
193
|
+
* @public exported from `@promptbook/core`
|
|
180
194
|
*/
|
|
181
195
|
var MAX_PARALLEL_COUNT = 5;
|
|
182
196
|
/**
|
|
183
197
|
* The maximum number of attempts to execute LLM task before giving up
|
|
198
|
+
*
|
|
199
|
+
* @public exported from `@promptbook/core`
|
|
184
200
|
*/
|
|
185
201
|
var MAX_EXECUTION_ATTEMPTS = 3;
|
|
202
|
+
/**
|
|
203
|
+
* The maximum length of the (generated) filename
|
|
204
|
+
*
|
|
205
|
+
* @public exported from `@promptbook/core`
|
|
206
|
+
*/
|
|
207
|
+
var MAX_FILENAME_LENGTH = 30;
|
|
186
208
|
/**
|
|
187
209
|
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
210
|
+
*
|
|
211
|
+
* @public exported from `@promptbook/core`
|
|
188
212
|
*/
|
|
189
213
|
var PIPELINE_COLLECTION_BASE_FILENAME = "index";
|
|
190
214
|
/**
|
|
@@ -193,6 +217,8 @@ var PIPELINE_COLLECTION_BASE_FILENAME = "index";
|
|
|
193
217
|
var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
|
|
194
218
|
/**
|
|
195
219
|
* The names of the parameters that are reserved for special purposes
|
|
220
|
+
*
|
|
221
|
+
* @public exported from `@promptbook/core`
|
|
196
222
|
*/
|
|
197
223
|
var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
198
224
|
'content',
|
|
@@ -206,10 +232,14 @@ var RESERVED_PARAMETER_NAMES = deepFreeze([
|
|
|
206
232
|
]);
|
|
207
233
|
/**
|
|
208
234
|
* @@@
|
|
235
|
+
*
|
|
236
|
+
* @private within the repository
|
|
209
237
|
*/
|
|
210
238
|
var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
211
239
|
/**
|
|
212
240
|
* @@@
|
|
241
|
+
*
|
|
242
|
+
* @private within the repository
|
|
213
243
|
*/
|
|
214
244
|
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
215
245
|
/*
|
|
@@ -217,7 +247,7 @@ TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
|
|
|
217
247
|
*/
|
|
218
248
|
// [🟡][🟢][🔵][⚪]
|
|
219
249
|
/**
|
|
220
|
-
* TODO:
|
|
250
|
+
* TODO: !!!!!! Check that all @private contains some normalized explanation
|
|
221
251
|
*/
|
|
222
252
|
|
|
223
253
|
/**
|
|
@@ -257,6 +287,7 @@ function prettifyMarkdown(content) {
|
|
|
257
287
|
/**
|
|
258
288
|
* Makes first letter of a string uppercase
|
|
259
289
|
*
|
|
290
|
+
* @public exported from `@promptbook/utils`
|
|
260
291
|
*/
|
|
261
292
|
function capitalize(word) {
|
|
262
293
|
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
@@ -267,6 +298,7 @@ function capitalize(word) {
|
|
|
267
298
|
*
|
|
268
299
|
* @param pipelineJson Promptbook in JSON format (.ptbk.json)
|
|
269
300
|
* @returns Promptbook in string format (.ptbk.md)
|
|
301
|
+
* @public exported from `@promptbook/core`
|
|
270
302
|
*/
|
|
271
303
|
function pipelineJsonToString(pipelineJson) {
|
|
272
304
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
@@ -466,6 +498,8 @@ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
|
466
498
|
|
|
467
499
|
/**
|
|
468
500
|
* @@@
|
|
501
|
+
*
|
|
502
|
+
* @public exported from `@promptbook/utils`
|
|
469
503
|
*/
|
|
470
504
|
function deepClone(objectValue) {
|
|
471
505
|
return JSON.parse(JSON.stringify(objectValue));
|
|
@@ -482,14 +516,13 @@ function deepClone(objectValue) {
|
|
|
482
516
|
*/
|
|
483
517
|
}
|
|
484
518
|
/**
|
|
485
|
-
* TODO: [🔼] Export from `@promptbook/utils`
|
|
486
519
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
487
520
|
*/
|
|
488
521
|
|
|
489
522
|
/**
|
|
490
523
|
* @@@
|
|
491
524
|
*
|
|
492
|
-
*
|
|
525
|
+
* @public exported from `@promptbook/core`
|
|
493
526
|
*/
|
|
494
527
|
var ZERO_USAGE = deepFreeze({
|
|
495
528
|
price: { value: 0 },
|
|
@@ -516,6 +549,8 @@ var ZERO_USAGE = deepFreeze({
|
|
|
516
549
|
* Function `addUsage` will add multiple usages into one
|
|
517
550
|
*
|
|
518
551
|
* Note: If you provide 0 values, it returns ZERO_USAGE
|
|
552
|
+
*
|
|
553
|
+
* @public exported from `@promptbook/core`
|
|
519
554
|
*/
|
|
520
555
|
function addUsage() {
|
|
521
556
|
var usageItems = [];
|
|
@@ -588,6 +623,7 @@ function addUsage() {
|
|
|
588
623
|
* @param array - Array to iterate over
|
|
589
624
|
* @param options - Options for the function
|
|
590
625
|
* @param callbackfunction - Function to call for each item
|
|
626
|
+
* @public exported from `@promptbook/utils`
|
|
591
627
|
*/
|
|
592
628
|
function forEachAsync(array, options, callbackfunction) {
|
|
593
629
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -656,10 +692,12 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
656
692
|
});
|
|
657
693
|
}
|
|
658
694
|
|
|
659
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.62.0
|
|
695
|
+
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"}];
|
|
660
696
|
|
|
661
697
|
/**
|
|
662
698
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
699
|
+
*
|
|
700
|
+
* @public exported from `@promptbook/core`
|
|
663
701
|
*/
|
|
664
702
|
var ParsingError = /** @class */ (function (_super) {
|
|
665
703
|
__extends(ParsingError, _super);
|
|
@@ -674,6 +712,8 @@ var ParsingError = /** @class */ (function (_super) {
|
|
|
674
712
|
|
|
675
713
|
/**
|
|
676
714
|
* This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
|
|
715
|
+
*
|
|
716
|
+
* @public exported from `@promptbook/core`
|
|
677
717
|
*/
|
|
678
718
|
var PipelineLogicError = /** @class */ (function (_super) {
|
|
679
719
|
__extends(PipelineLogicError, _super);
|
|
@@ -688,6 +728,8 @@ var PipelineLogicError = /** @class */ (function (_super) {
|
|
|
688
728
|
|
|
689
729
|
/**
|
|
690
730
|
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
731
|
+
*
|
|
732
|
+
* @public exported from `@promptbook/core`
|
|
691
733
|
*/
|
|
692
734
|
var UnexpectedError = /** @class */ (function (_super) {
|
|
693
735
|
__extends(UnexpectedError, _super);
|
|
@@ -706,6 +748,8 @@ var UnexpectedError = /** @class */ (function (_super) {
|
|
|
706
748
|
* Note: There are two simmilar functions:
|
|
707
749
|
* - `isValidSemanticVersion` which tests any semantic version
|
|
708
750
|
* - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
|
|
751
|
+
*
|
|
752
|
+
* @public exported from `@promptbook/utils`
|
|
709
753
|
*/
|
|
710
754
|
function isValidSemanticVersion(version) {
|
|
711
755
|
if (typeof version !== 'string') {
|
|
@@ -726,6 +770,8 @@ function isValidSemanticVersion(version) {
|
|
|
726
770
|
* Note: There are two simmilar functions:
|
|
727
771
|
* - `isValidSemanticVersion` which tests any semantic version
|
|
728
772
|
* - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
|
|
773
|
+
*
|
|
774
|
+
* @public exported from `@promptbook/utils`
|
|
729
775
|
*/
|
|
730
776
|
function isValidPromptbookVersion(version) {
|
|
731
777
|
if (!isValidSemanticVersion(version)) {
|
|
@@ -744,6 +790,8 @@ function isValidPromptbookVersion(version) {
|
|
|
744
790
|
* Note: There are two simmilar functions:
|
|
745
791
|
* - `isUrlOnPrivateNetwork` which tests full URL
|
|
746
792
|
* - `isHostnameOnPrivateNetwork` *(this one)* which tests just hostname
|
|
793
|
+
*
|
|
794
|
+
* @public exported from `@promptbook/utils`
|
|
747
795
|
*/
|
|
748
796
|
function isHostnameOnPrivateNetwork(hostname) {
|
|
749
797
|
if (hostname === 'example.com' ||
|
|
@@ -778,6 +826,7 @@ function isHostnameOnPrivateNetwork(hostname) {
|
|
|
778
826
|
*
|
|
779
827
|
* @param {string} ipAddress - The IP address to check.
|
|
780
828
|
* @returns {boolean} Returns true if the IP address is reserved for private networks or localhost, otherwise false.
|
|
829
|
+
* @public exported from `@promptbook/utils`
|
|
781
830
|
*/
|
|
782
831
|
function isUrlOnPrivateNetwork(url) {
|
|
783
832
|
if (typeof url === 'string') {
|
|
@@ -793,6 +842,8 @@ function isUrlOnPrivateNetwork(url) {
|
|
|
793
842
|
* Note: There are two simmilar functions:
|
|
794
843
|
* - `isValidUrl` which tests any URL
|
|
795
844
|
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
845
|
+
*
|
|
846
|
+
* @public exported from `@promptbook/utils`
|
|
796
847
|
*/
|
|
797
848
|
function isValidUrl(url) {
|
|
798
849
|
if (typeof url !== 'string') {
|
|
@@ -819,6 +870,8 @@ function isValidUrl(url) {
|
|
|
819
870
|
* Note: There are two simmilar functions:
|
|
820
871
|
* - `isValidUrl` which tests any URL
|
|
821
872
|
* - `isValidPipelineUrl` *(this one)* which tests just pipeline URL
|
|
873
|
+
*
|
|
874
|
+
* @public exported from `@promptbook/utils`
|
|
822
875
|
*/
|
|
823
876
|
function isValidPipelineUrl(url) {
|
|
824
877
|
if (!isValidUrl(url)) {
|
|
@@ -856,6 +909,7 @@ function isValidPipelineUrl(url) {
|
|
|
856
909
|
* @param pipeline valid or invalid PipelineJson
|
|
857
910
|
* @returns the same pipeline if it is logically valid
|
|
858
911
|
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
912
|
+
* @public exported from `@promptbook/core`
|
|
859
913
|
*/
|
|
860
914
|
function validatePipeline(pipeline) {
|
|
861
915
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
@@ -1085,6 +1139,8 @@ function validatePipeline(pipeline) {
|
|
|
1085
1139
|
|
|
1086
1140
|
/**
|
|
1087
1141
|
* This error indicates that promptbook not found in the collection
|
|
1142
|
+
*
|
|
1143
|
+
* @public exported from `@promptbook/core`
|
|
1088
1144
|
*/
|
|
1089
1145
|
var NotFoundError = /** @class */ (function (_super) {
|
|
1090
1146
|
__extends(NotFoundError, _super);
|
|
@@ -1099,6 +1155,8 @@ var NotFoundError = /** @class */ (function (_super) {
|
|
|
1099
1155
|
|
|
1100
1156
|
/**
|
|
1101
1157
|
* This error indicates errors in referencing promptbooks between each other
|
|
1158
|
+
*
|
|
1159
|
+
* @public exported from `@promptbook/core`
|
|
1102
1160
|
*/
|
|
1103
1161
|
var ReferenceError$1 = /** @class */ (function (_super) {
|
|
1104
1162
|
__extends(ReferenceError, _super);
|
|
@@ -1116,6 +1174,7 @@ var ReferenceError$1 = /** @class */ (function (_super) {
|
|
|
1116
1174
|
*
|
|
1117
1175
|
* @param template the template with parameters in {curly} braces
|
|
1118
1176
|
* @returns the list of parameter names
|
|
1177
|
+
* @public exported from `@promptbook/utils`
|
|
1119
1178
|
*/
|
|
1120
1179
|
function extractParameterNames(template) {
|
|
1121
1180
|
var e_1, _a;
|
|
@@ -1140,6 +1199,8 @@ function extractParameterNames(template) {
|
|
|
1140
1199
|
|
|
1141
1200
|
/**
|
|
1142
1201
|
* Unprepare just strips the preparation data of the pipeline
|
|
1202
|
+
*
|
|
1203
|
+
* @public exported from `@promptbook/core`
|
|
1143
1204
|
*/
|
|
1144
1205
|
function unpreparePipeline(pipeline) {
|
|
1145
1206
|
var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources, promptTemplates = pipeline.promptTemplates;
|
|
@@ -1156,7 +1217,6 @@ function unpreparePipeline(pipeline) {
|
|
|
1156
1217
|
return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
|
|
1157
1218
|
}
|
|
1158
1219
|
/**
|
|
1159
|
-
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
1160
1220
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
1161
1221
|
* TODO: Write tests for `preparePipeline`
|
|
1162
1222
|
* TODO: [🍙] Make some standart order of json properties
|
|
@@ -1258,6 +1318,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1258
1318
|
*
|
|
1259
1319
|
* @param promptbookSources
|
|
1260
1320
|
* @returns PipelineCollection
|
|
1321
|
+
* @public exported from `@promptbook/core`
|
|
1261
1322
|
*/
|
|
1262
1323
|
function createCollectionFromJson() {
|
|
1263
1324
|
var promptbooks = [];
|
|
@@ -1483,6 +1544,8 @@ var defaultDiacriticsRemovalMap = [
|
|
|
1483
1544
|
* > "ě" => "e"
|
|
1484
1545
|
* > "Ă" => "A"
|
|
1485
1546
|
* > ...
|
|
1547
|
+
*
|
|
1548
|
+
* @public exported from `@promptbook/utils`
|
|
1486
1549
|
*/
|
|
1487
1550
|
var DIACRITIC_VARIANTS_LETTERS = {};
|
|
1488
1551
|
// tslint:disable-next-line: prefer-for-of
|
|
@@ -1510,7 +1573,11 @@ for (var i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
|
1510
1573
|
*/
|
|
1511
1574
|
|
|
1512
1575
|
/**
|
|
1576
|
+
* @@@
|
|
1513
1577
|
*
|
|
1578
|
+
* @param input @@@
|
|
1579
|
+
* @returns @@@
|
|
1580
|
+
* @public exported from `@promptbook/utils`
|
|
1514
1581
|
*/
|
|
1515
1582
|
function removeDiacritics(input) {
|
|
1516
1583
|
/*eslint no-control-regex: "off"*/
|
|
@@ -1518,7 +1585,19 @@ function removeDiacritics(input) {
|
|
|
1518
1585
|
return DIACRITIC_VARIANTS_LETTERS[a] || a;
|
|
1519
1586
|
});
|
|
1520
1587
|
}
|
|
1588
|
+
/**
|
|
1589
|
+
* TODO: [Ж] Variant for cyrillic (and in general non-latin) letters
|
|
1590
|
+
*/
|
|
1521
1591
|
|
|
1592
|
+
/**
|
|
1593
|
+
* @@@
|
|
1594
|
+
*
|
|
1595
|
+
* @param text @@@
|
|
1596
|
+
* @returns @@@
|
|
1597
|
+
* @example 'hello-world'
|
|
1598
|
+
* @example 'i-love-promptbook'
|
|
1599
|
+
* @public exported from `@promptbook/utils`
|
|
1600
|
+
*/
|
|
1522
1601
|
function normalizeToKebabCase(text) {
|
|
1523
1602
|
var e_1, _a;
|
|
1524
1603
|
text = removeDiacritics(text);
|
|
@@ -1578,6 +1657,7 @@ function normalizeToKebabCase(text) {
|
|
|
1578
1657
|
*
|
|
1579
1658
|
* @param text with emojis
|
|
1580
1659
|
* @returns text without emojis
|
|
1660
|
+
* @public exported from `@promptbook/utils`
|
|
1581
1661
|
*/
|
|
1582
1662
|
function removeEmojis(text) {
|
|
1583
1663
|
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
@@ -1589,7 +1669,12 @@ function removeEmojis(text) {
|
|
|
1589
1669
|
}
|
|
1590
1670
|
|
|
1591
1671
|
/**
|
|
1592
|
-
*
|
|
1672
|
+
* @@@
|
|
1673
|
+
*
|
|
1674
|
+
* @param value @@@
|
|
1675
|
+
* @returns @@@
|
|
1676
|
+
* @example @@@
|
|
1677
|
+
* @public exported from `@promptbook/utils`
|
|
1593
1678
|
*/
|
|
1594
1679
|
function titleToName(value) {
|
|
1595
1680
|
if (value.startsWith('http://') || value.startsWith('https://')) {
|
|
@@ -1608,6 +1693,8 @@ function titleToName(value) {
|
|
|
1608
1693
|
|
|
1609
1694
|
/**
|
|
1610
1695
|
* This error indicates errors during the execution of the pipeline
|
|
1696
|
+
*
|
|
1697
|
+
* @public exported from `@promptbook/core`
|
|
1611
1698
|
*/
|
|
1612
1699
|
var PipelineExecutionError = /** @class */ (function (_super) {
|
|
1613
1700
|
__extends(PipelineExecutionError, _super);
|
|
@@ -1625,6 +1712,7 @@ var PipelineExecutionError = /** @class */ (function (_super) {
|
|
|
1625
1712
|
*
|
|
1626
1713
|
* @param executionResult - The partial result of the promptnook execution
|
|
1627
1714
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
1715
|
+
* @public exported from `@promptbook/core`
|
|
1628
1716
|
*/
|
|
1629
1717
|
function assertsExecutionSuccessful(executionResult) {
|
|
1630
1718
|
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
@@ -1655,6 +1743,7 @@ function assertsExecutionSuccessful(executionResult) {
|
|
|
1655
1743
|
* @param script from which to extract the variables
|
|
1656
1744
|
* @returns the list of variable names
|
|
1657
1745
|
* @throws {ParsingError} if the script is invalid
|
|
1746
|
+
* @public exported from `@promptbook/utils`
|
|
1658
1747
|
*/
|
|
1659
1748
|
function extractVariables(script) {
|
|
1660
1749
|
var variables = new Set();
|
|
@@ -1703,6 +1792,7 @@ function extractVariables(script) {
|
|
|
1703
1792
|
* @param promptTemplate the template with used parameters
|
|
1704
1793
|
* @returns the set of parameter names
|
|
1705
1794
|
* @throws {ParsingError} if the script is invalid
|
|
1795
|
+
* @public exported from `@promptbook/utils`
|
|
1706
1796
|
*/
|
|
1707
1797
|
function extractParameterNamesFromPromptTemplate(promptTemplate) {
|
|
1708
1798
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
@@ -1776,6 +1866,8 @@ var ExpectError = /** @class */ (function (_super) {
|
|
|
1776
1866
|
|
|
1777
1867
|
/**
|
|
1778
1868
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1869
|
+
*
|
|
1870
|
+
* @public exported from `@promptbook/utils`
|
|
1779
1871
|
*/
|
|
1780
1872
|
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
1781
1873
|
try {
|
|
@@ -2002,6 +2094,8 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2002
2094
|
*
|
|
2003
2095
|
*
|
|
2004
2096
|
* Tip: You don't have to use this function directly, just pass an array of LlmExecutionTools to the `ExecutionTools`
|
|
2097
|
+
*
|
|
2098
|
+
* @public exported from `@promptbook/core`
|
|
2005
2099
|
*/
|
|
2006
2100
|
function joinLlmExecutionTools() {
|
|
2007
2101
|
var llmExecutionTools = [];
|
|
@@ -2041,6 +2135,8 @@ function joinLlmExecutionTools() {
|
|
|
2041
2135
|
|
|
2042
2136
|
/**
|
|
2043
2137
|
* Determine if the pipeline is fully prepared
|
|
2138
|
+
*
|
|
2139
|
+
* @public exported from `@promptbook/core`
|
|
2044
2140
|
*/
|
|
2045
2141
|
function isPipelinePrepared(pipeline) {
|
|
2046
2142
|
// Note: Ignoring `pipeline.preparations` @@@
|
|
@@ -2061,7 +2157,6 @@ function isPipelinePrepared(pipeline) {
|
|
|
2061
2157
|
}
|
|
2062
2158
|
/**
|
|
2063
2159
|
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2064
|
-
* TODO: [🔼] Export via core or utils
|
|
2065
2160
|
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2066
2161
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
2067
2162
|
* - [🏍] ? Is context in each template
|
|
@@ -2107,6 +2202,8 @@ function TODO_USE() {
|
|
|
2107
2202
|
|
|
2108
2203
|
/**
|
|
2109
2204
|
* This error type indicates that some limit was reached
|
|
2205
|
+
*
|
|
2206
|
+
* @public exported from `@promptbook/core`
|
|
2110
2207
|
*/
|
|
2111
2208
|
var LimitReachedError = /** @class */ (function (_super) {
|
|
2112
2209
|
__extends(LimitReachedError, _super);
|
|
@@ -2126,6 +2223,7 @@ var LimitReachedError = /** @class */ (function (_super) {
|
|
|
2126
2223
|
* @param parameters the object with parameters
|
|
2127
2224
|
* @returns the template with replaced parameters
|
|
2128
2225
|
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
2226
|
+
* @public exported from `@promptbook/utils`
|
|
2129
2227
|
*/
|
|
2130
2228
|
function replaceParameters(template, parameters) {
|
|
2131
2229
|
var e_1, _a;
|
|
@@ -2201,6 +2299,7 @@ function replaceParameters(template, parameters) {
|
|
|
2201
2299
|
* Create difference set of two sets.
|
|
2202
2300
|
*
|
|
2203
2301
|
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2302
|
+
* @public exported from `@promptbook/utils`
|
|
2204
2303
|
*/
|
|
2205
2304
|
function difference(a, b, isEqual) {
|
|
2206
2305
|
var e_1, _a;
|
|
@@ -2234,6 +2333,7 @@ function difference(a, b, isEqual) {
|
|
|
2234
2333
|
* Creates a new set with all elements that are present in either set
|
|
2235
2334
|
*
|
|
2236
2335
|
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
2336
|
+
* @public exported from `@promptbook/utils`
|
|
2237
2337
|
*/
|
|
2238
2338
|
function union() {
|
|
2239
2339
|
var e_1, _a, e_2, _b;
|
|
@@ -2270,14 +2370,10 @@ function union() {
|
|
|
2270
2370
|
return union;
|
|
2271
2371
|
}
|
|
2272
2372
|
|
|
2273
|
-
/**
|
|
2274
|
-
* The version of the Promptbook library
|
|
2275
|
-
*/
|
|
2276
|
-
var PROMPTBOOK_VERSION = '0.62.0-1';
|
|
2277
|
-
// TODO: !!!! List here all the versions and annotate + put into script
|
|
2278
|
-
|
|
2279
2373
|
/**
|
|
2280
2374
|
* Counts number of characters in the text
|
|
2375
|
+
*
|
|
2376
|
+
* @public exported from `@promptbook/utils`
|
|
2281
2377
|
*/
|
|
2282
2378
|
function countCharacters(text) {
|
|
2283
2379
|
// Remove null characters
|
|
@@ -2291,6 +2387,8 @@ function countCharacters(text) {
|
|
|
2291
2387
|
|
|
2292
2388
|
/**
|
|
2293
2389
|
* Counts number of lines in the text
|
|
2390
|
+
*
|
|
2391
|
+
* @public exported from `@promptbook/utils`
|
|
2294
2392
|
*/
|
|
2295
2393
|
function countLines(text) {
|
|
2296
2394
|
if (text === '') {
|
|
@@ -2301,6 +2399,8 @@ function countLines(text) {
|
|
|
2301
2399
|
|
|
2302
2400
|
/**
|
|
2303
2401
|
* Counts number of pages in the text
|
|
2402
|
+
*
|
|
2403
|
+
* @public exported from `@promptbook/utils`
|
|
2304
2404
|
*/
|
|
2305
2405
|
function countPages(text) {
|
|
2306
2406
|
var sentencesPerPage = 5; // Assuming each page has 5 sentences
|
|
@@ -2311,6 +2411,8 @@ function countPages(text) {
|
|
|
2311
2411
|
|
|
2312
2412
|
/**
|
|
2313
2413
|
* Counts number of paragraphs in the text
|
|
2414
|
+
*
|
|
2415
|
+
* @public exported from `@promptbook/utils`
|
|
2314
2416
|
*/
|
|
2315
2417
|
function countParagraphs(text) {
|
|
2316
2418
|
return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
|
|
@@ -2318,12 +2420,16 @@ function countParagraphs(text) {
|
|
|
2318
2420
|
|
|
2319
2421
|
/**
|
|
2320
2422
|
* Split text into sentences
|
|
2423
|
+
*
|
|
2424
|
+
* @public exported from `@promptbook/utils`
|
|
2321
2425
|
*/
|
|
2322
2426
|
function splitIntoSentences(text) {
|
|
2323
2427
|
return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
|
|
2324
2428
|
}
|
|
2325
2429
|
/**
|
|
2326
2430
|
* Counts number of sentences in the text
|
|
2431
|
+
*
|
|
2432
|
+
* @public exported from `@promptbook/utils`
|
|
2327
2433
|
*/
|
|
2328
2434
|
function countSentences(text) {
|
|
2329
2435
|
return splitIntoSentences(text).length;
|
|
@@ -2331,6 +2437,8 @@ function countSentences(text) {
|
|
|
2331
2437
|
|
|
2332
2438
|
/**
|
|
2333
2439
|
* Counts number of words in the text
|
|
2440
|
+
*
|
|
2441
|
+
* @public exported from `@promptbook/utils`
|
|
2334
2442
|
*/
|
|
2335
2443
|
function countWords(text) {
|
|
2336
2444
|
text = text.replace(/[\p{Extended_Pictographic}]/gu, 'a');
|
|
@@ -2340,6 +2448,8 @@ function countWords(text) {
|
|
|
2340
2448
|
|
|
2341
2449
|
/**
|
|
2342
2450
|
* Index of all counter functions
|
|
2451
|
+
*
|
|
2452
|
+
* @public exported from `@promptbook/utils`
|
|
2343
2453
|
*/
|
|
2344
2454
|
var CountUtils = {
|
|
2345
2455
|
CHARACTERS: countCharacters,
|
|
@@ -2359,6 +2469,7 @@ var CountUtils = {
|
|
|
2359
2469
|
*
|
|
2360
2470
|
* @throws {ExpectError} if the expectations are not met
|
|
2361
2471
|
* @returns {void} Nothing
|
|
2472
|
+
* @public exported from `@promptbook/core`
|
|
2362
2473
|
*/
|
|
2363
2474
|
function checkExpectations(expectations, value) {
|
|
2364
2475
|
var e_1, _a;
|
|
@@ -2391,6 +2502,7 @@ function checkExpectations(expectations, value) {
|
|
|
2391
2502
|
*
|
|
2392
2503
|
* @returns The executor function
|
|
2393
2504
|
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
2505
|
+
* @public exported from `@promptbook/core`
|
|
2394
2506
|
*/
|
|
2395
2507
|
function createPipelineExecutor(options) {
|
|
2396
2508
|
var _this = this;
|
|
@@ -3179,6 +3291,8 @@ function createPipelineExecutor(options) {
|
|
|
3179
3291
|
|
|
3180
3292
|
/**
|
|
3181
3293
|
* @@@
|
|
3294
|
+
*
|
|
3295
|
+
* @public exported from `@promptbook/core`
|
|
3182
3296
|
*/
|
|
3183
3297
|
function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?maybe not) Always the file */, options) {
|
|
3184
3298
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3314,6 +3428,7 @@ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?mayb
|
|
|
3314
3428
|
* Prepares the knowle
|
|
3315
3429
|
*
|
|
3316
3430
|
* @see https://github.com/webgptorg/promptbook/discussions/41
|
|
3431
|
+
* @public exported from `@promptbook/core`
|
|
3317
3432
|
*/
|
|
3318
3433
|
function prepareKnowledgePieces(knowledgeSources, options) {
|
|
3319
3434
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3328,7 +3443,7 @@ function prepareKnowledgePieces(knowledgeSources, options) {
|
|
|
3328
3443
|
var partialPieces, pieces;
|
|
3329
3444
|
return __generator(this, function (_a) {
|
|
3330
3445
|
switch (_a.label) {
|
|
3331
|
-
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝] !!! Unhardcode markdown, detect which type it is
|
|
3446
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝] !!! Unhardcode markdown, detect which type it is - BE AWARE of big package size
|
|
3332
3447
|
options)];
|
|
3333
3448
|
case 1:
|
|
3334
3449
|
partialPieces = _a.sent();
|
|
@@ -3366,7 +3481,6 @@ TODO: [🧊] This is how it can look in future
|
|
|
3366
3481
|
> ):
|
|
3367
3482
|
*/
|
|
3368
3483
|
/**
|
|
3369
|
-
* TODO: [🐝][🔼] !!! Export via `@promptbook/core`
|
|
3370
3484
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
3371
3485
|
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
3372
3486
|
* TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
|
|
@@ -3380,6 +3494,7 @@ TODO: [🧊] This is how it can look in future
|
|
|
3380
3494
|
*
|
|
3381
3495
|
* @param llmTools LLM tools to be intercepted with usage counting
|
|
3382
3496
|
* @returns LLM tools with same functionality with added total cost counting
|
|
3497
|
+
* @public exported from `@promptbook/core`
|
|
3383
3498
|
*/
|
|
3384
3499
|
function countTotalUsage(llmTools) {
|
|
3385
3500
|
var _this = this;
|
|
@@ -3447,7 +3562,6 @@ function countTotalUsage(llmTools) {
|
|
|
3447
3562
|
return proxyTools;
|
|
3448
3563
|
}
|
|
3449
3564
|
/**
|
|
3450
|
-
* TODO: [🔼] !!! Export via `@promptbookcore/`
|
|
3451
3565
|
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
3452
3566
|
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
3453
3567
|
* TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
|
|
@@ -3459,6 +3573,7 @@ function countTotalUsage(llmTools) {
|
|
|
3459
3573
|
* Prepares the persona for the pipeline
|
|
3460
3574
|
*
|
|
3461
3575
|
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
3576
|
+
* @public exported from `@promptbook/core`
|
|
3462
3577
|
*/
|
|
3463
3578
|
function preparePersona(personaDescription, options) {
|
|
3464
3579
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3513,7 +3628,6 @@ function preparePersona(personaDescription, options) {
|
|
|
3513
3628
|
});
|
|
3514
3629
|
}
|
|
3515
3630
|
/**
|
|
3516
|
-
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3517
3631
|
* TODO: [🏢] !! Check validity of `modelName` in pipeline
|
|
3518
3632
|
* TODO: [🏢] !! Check validity of `systemMessage` in pipeline
|
|
3519
3633
|
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
@@ -3521,6 +3635,8 @@ function preparePersona(personaDescription, options) {
|
|
|
3521
3635
|
|
|
3522
3636
|
/**
|
|
3523
3637
|
* @@@
|
|
3638
|
+
*
|
|
3639
|
+
* @public exported from `@promptbook/core`
|
|
3524
3640
|
*/
|
|
3525
3641
|
function prepareTemplates(pipeline, options) {
|
|
3526
3642
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3562,7 +3678,6 @@ function prepareTemplates(pipeline, options) {
|
|
|
3562
3678
|
* TODO: [🧠] Add context to each template (if missing)
|
|
3563
3679
|
* TODO: [🧠] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
|
|
3564
3680
|
* TODO: [♨] !!! Prepare index the samples and maybe templates
|
|
3565
|
-
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3566
3681
|
* TODO: Write tests for `preparePipeline`
|
|
3567
3682
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3568
3683
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -3575,6 +3690,7 @@ function prepareTemplates(pipeline, options) {
|
|
|
3575
3690
|
*
|
|
3576
3691
|
* Note: This function does not validate logic of the pipeline
|
|
3577
3692
|
* Note: This function acts as part of compilation process
|
|
3693
|
+
* @public exported from `@promptbook/core`
|
|
3578
3694
|
*/
|
|
3579
3695
|
function preparePipeline(pipeline, options) {
|
|
3580
3696
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3651,7 +3767,6 @@ function preparePipeline(pipeline, options) {
|
|
|
3651
3767
|
});
|
|
3652
3768
|
}
|
|
3653
3769
|
/**
|
|
3654
|
-
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
3655
3770
|
* TODO: Write tests for `preparePipeline`
|
|
3656
3771
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3657
3772
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -3662,6 +3777,7 @@ function preparePipeline(pipeline, options) {
|
|
|
3662
3777
|
* Tests if given string is valid URL.
|
|
3663
3778
|
*
|
|
3664
3779
|
* Note: This does not check if the file exists only if the path is valid
|
|
3780
|
+
* @public exported from `@promptbook/utils`
|
|
3665
3781
|
*/
|
|
3666
3782
|
function isValidFilePath(filePath) {
|
|
3667
3783
|
if (typeof filePath !== 'string') {
|
|
@@ -3844,6 +3960,7 @@ var personaCommandParser = {
|
|
|
3844
3960
|
*
|
|
3845
3961
|
* @param {string} str - The string to remove Markdown tags from.
|
|
3846
3962
|
* @returns {string} The input string with all Markdown tags removed.
|
|
3963
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
3847
3964
|
*/
|
|
3848
3965
|
function removeMarkdownFormatting(str) {
|
|
3849
3966
|
// Remove bold formatting
|
|
@@ -3855,6 +3972,15 @@ function removeMarkdownFormatting(str) {
|
|
|
3855
3972
|
return str;
|
|
3856
3973
|
}
|
|
3857
3974
|
|
|
3975
|
+
/**
|
|
3976
|
+
* @@@
|
|
3977
|
+
*
|
|
3978
|
+
* @param text @@@
|
|
3979
|
+
* @returns @@@
|
|
3980
|
+
* @example 'HELLO_WORLD'
|
|
3981
|
+
* @example 'I_LOVE_PROMPTBOOK'
|
|
3982
|
+
* @public exported from `@promptbook/utils`
|
|
3983
|
+
*/
|
|
3858
3984
|
function normalizeTo_SCREAMING_CASE(text) {
|
|
3859
3985
|
var e_1, _a;
|
|
3860
3986
|
var charType;
|
|
@@ -3920,6 +4046,7 @@ function normalizeTo_SCREAMING_CASE(text) {
|
|
|
3920
4046
|
* Block type describes the way how the block is blockd
|
|
3921
4047
|
*
|
|
3922
4048
|
* @see https://github.com/webgptorg/promptbook#block-type
|
|
4049
|
+
* @public exported from `@promptbook/core`
|
|
3923
4050
|
*/
|
|
3924
4051
|
var BlockTypes = [
|
|
3925
4052
|
'PROMPT_TEMPLATE',
|
|
@@ -4039,7 +4166,7 @@ var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'LINES', 'PARAGRAPH
|
|
|
4039
4166
|
* @returns parsed number
|
|
4040
4167
|
* @throws {ParsingError} if the value is not a number
|
|
4041
4168
|
*
|
|
4042
|
-
* @
|
|
4169
|
+
* @public exported from `@promptbook/utils`
|
|
4043
4170
|
*/
|
|
4044
4171
|
function parseNumber(value) {
|
|
4045
4172
|
var originalValue = value;
|
|
@@ -4095,6 +4222,7 @@ function parseNumber(value) {
|
|
|
4095
4222
|
}
|
|
4096
4223
|
/**
|
|
4097
4224
|
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
4225
|
+
* TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
|
|
4098
4226
|
*/
|
|
4099
4227
|
|
|
4100
4228
|
/**
|
|
@@ -4406,6 +4534,13 @@ var parameterCommandParser = {
|
|
|
4406
4534
|
},
|
|
4407
4535
|
};
|
|
4408
4536
|
|
|
4537
|
+
/**
|
|
4538
|
+
* @@@
|
|
4539
|
+
*
|
|
4540
|
+
* @param javascriptName @@@
|
|
4541
|
+
* @returns @@@
|
|
4542
|
+
* @public exported from `@promptbook/utils`
|
|
4543
|
+
*/
|
|
4409
4544
|
function isValidJavascriptName(javascriptName) {
|
|
4410
4545
|
if (typeof javascriptName !== 'string') {
|
|
4411
4546
|
return false;
|
|
@@ -4878,6 +5013,8 @@ function parseCommandVariant(input) {
|
|
|
4878
5013
|
|
|
4879
5014
|
/**
|
|
4880
5015
|
* This error type indicates that some part of the code is not implemented yet
|
|
5016
|
+
*
|
|
5017
|
+
* @public exported from `@promptbook/core`
|
|
4881
5018
|
*/
|
|
4882
5019
|
var NotYetImplementedError = /** @class */ (function (_super) {
|
|
4883
5020
|
__extends(NotYetImplementedError, _super);
|
|
@@ -4904,7 +5041,8 @@ var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
|
|
|
4904
5041
|
* Note: It can not work with html syntax and comments
|
|
4905
5042
|
*
|
|
4906
5043
|
* @param markdown any valid markdown
|
|
4907
|
-
* @returns
|
|
5044
|
+
* @returns @@@
|
|
5045
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
4908
5046
|
*/
|
|
4909
5047
|
function extractAllListItemsFromMarkdown(markdown) {
|
|
4910
5048
|
var e_1, _a;
|
|
@@ -4944,7 +5082,7 @@ function extractAllListItemsFromMarkdown(markdown) {
|
|
|
4944
5082
|
*
|
|
4945
5083
|
* @param markdown any valid markdown
|
|
4946
5084
|
* @returns code blocks with language and content
|
|
4947
|
-
*
|
|
5085
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
4948
5086
|
*/
|
|
4949
5087
|
function extractAllBlocksFromMarkdown(markdown) {
|
|
4950
5088
|
var e_1, _a;
|
|
@@ -5021,6 +5159,7 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
5021
5159
|
*
|
|
5022
5160
|
* @param markdown any valid markdown
|
|
5023
5161
|
* @returns code block with language and content
|
|
5162
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5024
5163
|
*/
|
|
5025
5164
|
function extractOneBlockFromMarkdown(markdown) {
|
|
5026
5165
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
@@ -5035,6 +5174,8 @@ function extractOneBlockFromMarkdown(markdown) {
|
|
|
5035
5174
|
|
|
5036
5175
|
/**
|
|
5037
5176
|
* Parses markdown section to title its level and content
|
|
5177
|
+
*
|
|
5178
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5038
5179
|
*/
|
|
5039
5180
|
function parseMarkdownSection(value) {
|
|
5040
5181
|
var _a, _b;
|
|
@@ -5059,6 +5200,8 @@ function parseMarkdownSection(value) {
|
|
|
5059
5200
|
|
|
5060
5201
|
/**
|
|
5061
5202
|
* Splits the markdown into sections by headings
|
|
5203
|
+
*
|
|
5204
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5062
5205
|
*/
|
|
5063
5206
|
function splitMarkdownIntoSections(markdown) {
|
|
5064
5207
|
var e_1, _a;
|
|
@@ -5120,6 +5263,7 @@ function splitMarkdownIntoSections(markdown) {
|
|
|
5120
5263
|
return sections;
|
|
5121
5264
|
}
|
|
5122
5265
|
/**
|
|
5266
|
+
* TODO: [🏛] This can be part of markdown builder
|
|
5123
5267
|
* Note: [🕞] In past (commit 42086e1603cbed506482997c00a8ee979af0a247) there was much more
|
|
5124
5268
|
* sophisticated implementation of this function through parsing markdown into JSON structure
|
|
5125
5269
|
* and flattening the actual structure
|
|
@@ -5131,6 +5275,8 @@ function splitMarkdownIntoSections(markdown) {
|
|
|
5131
5275
|
*
|
|
5132
5276
|
* - It always have h1 - if there is no h1 in the markdown, it will be added "# Untitled"
|
|
5133
5277
|
* - All other headings are normalized to h2
|
|
5278
|
+
*
|
|
5279
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5134
5280
|
*/
|
|
5135
5281
|
function flattenMarkdown(markdown) {
|
|
5136
5282
|
var e_1, _a;
|
|
@@ -5166,6 +5312,7 @@ function flattenMarkdown(markdown) {
|
|
|
5166
5312
|
return spaceTrim(flattenedMarkdown);
|
|
5167
5313
|
}
|
|
5168
5314
|
/**
|
|
5315
|
+
* TODO: [🏛] This can be part of markdown builder
|
|
5169
5316
|
* Note: [🕞] In past (commit 42086e1603cbed506482997c00a8ee979af0a247) there was much more
|
|
5170
5317
|
* sophisticated implementation of this function through parsing markdown into JSON structure
|
|
5171
5318
|
* and flattening the actual structure
|
|
@@ -5177,6 +5324,7 @@ function flattenMarkdown(markdown) {
|
|
|
5177
5324
|
*
|
|
5178
5325
|
* @param {string} content - The string to remove comments from.
|
|
5179
5326
|
* @returns {string} The input string with all comments removed.
|
|
5327
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
5180
5328
|
*/
|
|
5181
5329
|
function removeContentComments(content) {
|
|
5182
5330
|
return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
|
|
@@ -5190,12 +5338,13 @@ function removeContentComments(content) {
|
|
|
5190
5338
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
5191
5339
|
* - `preparePipeline` - just one step in the compilation process
|
|
5192
5340
|
*
|
|
5341
|
+
* Note: This function does not validate logic of the pipeline only the syntax
|
|
5342
|
+
* Note: This function acts as compilation process
|
|
5343
|
+
*
|
|
5193
5344
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
5194
5345
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
5195
5346
|
* @throws {ParsingError} if the promptbook string is not valid
|
|
5196
|
-
*
|
|
5197
|
-
* Note: This function does not validate logic of the pipeline only the syntax
|
|
5198
|
-
* Note: This function acts as compilation process
|
|
5347
|
+
* @public exported from `@promptbook/core`
|
|
5199
5348
|
*/
|
|
5200
5349
|
function pipelineStringToJsonSync(pipelineString) {
|
|
5201
5350
|
var e_1, _a, e_2, _b;
|
|
@@ -5588,13 +5737,14 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5588
5737
|
* - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
|
|
5589
5738
|
* - `preparePipeline` - just one step in the compilation process
|
|
5590
5739
|
*
|
|
5740
|
+
* Note: This function does not validate logic of the pipeline only the syntax
|
|
5741
|
+
* Note: This function acts as compilation process
|
|
5742
|
+
*
|
|
5591
5743
|
* @param pipelineString {Promptbook} in string markdown format (.ptbk.md)
|
|
5592
5744
|
* @param options - Options and tools for the compilation
|
|
5593
5745
|
* @returns {Promptbook} compiled in JSON format (.ptbk.json)
|
|
5594
5746
|
* @throws {ParsingError} if the promptbook string is not valid
|
|
5595
|
-
*
|
|
5596
|
-
* Note: This function does not validate logic of the pipeline only the syntax
|
|
5597
|
-
* Note: This function acts as compilation process
|
|
5747
|
+
* @public exported from `@promptbook/core`
|
|
5598
5748
|
*/
|
|
5599
5749
|
function pipelineStringToJson(pipelineString, options) {
|
|
5600
5750
|
if (options === void 0) { options = { llmTools: null }; }
|
|
@@ -5622,6 +5772,8 @@ function pipelineStringToJson(pipelineString, options) {
|
|
|
5622
5772
|
|
|
5623
5773
|
/**
|
|
5624
5774
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
5775
|
+
*
|
|
5776
|
+
* @public exported from `@promptbook/core`
|
|
5625
5777
|
*/
|
|
5626
5778
|
var CollectionError = /** @class */ (function (_super) {
|
|
5627
5779
|
__extends(CollectionError, _super);
|
|
@@ -5636,19 +5788,22 @@ var CollectionError = /** @class */ (function (_super) {
|
|
|
5636
5788
|
|
|
5637
5789
|
/**
|
|
5638
5790
|
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
|
5791
|
+
*
|
|
5792
|
+
* @public exported from `@promptbook/utils`
|
|
5639
5793
|
*/
|
|
5640
5794
|
new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
|
|
5641
5795
|
/**
|
|
5642
5796
|
* Detects if the code is running in a Node.js environment
|
|
5797
|
+
*
|
|
5798
|
+
* @public exported from `@promptbook/utils`
|
|
5643
5799
|
*/
|
|
5644
5800
|
var isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
|
|
5645
5801
|
/**
|
|
5646
5802
|
* Detects if the code is running in a web worker
|
|
5803
|
+
*
|
|
5804
|
+
* @public exported from `@promptbook/utils`
|
|
5647
5805
|
*/
|
|
5648
5806
|
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");
|
|
5649
|
-
/**
|
|
5650
|
-
* TODO: [🔼] !!! Export via `@promptbook/utils`
|
|
5651
|
-
*/
|
|
5652
5807
|
|
|
5653
5808
|
/**
|
|
5654
5809
|
* Constructs Promptbook from async sources
|
|
@@ -5668,6 +5823,7 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
|
|
|
5668
5823
|
* @param promptbookSourcesPromiseOrFactory
|
|
5669
5824
|
* @returns PipelineCollection
|
|
5670
5825
|
* @deprecated Do not use, it will became internal tool for other constructor functions
|
|
5826
|
+
* @public exported from `@promptbook/core`
|
|
5671
5827
|
*/
|
|
5672
5828
|
function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
5673
5829
|
var collection = null;
|
|
@@ -5744,6 +5900,7 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
5744
5900
|
* @param path - path to the directory with pipelines
|
|
5745
5901
|
* @param options - Misc options for the collection
|
|
5746
5902
|
* @returns PipelineCollection
|
|
5903
|
+
* @public exported from `@promptbook/node`
|
|
5747
5904
|
*/
|
|
5748
5905
|
function createCollectionFromDirectory(path, options) {
|
|
5749
5906
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -5988,6 +6145,8 @@ function listAllFiles(path, isRecursive) {
|
|
|
5988
6145
|
|
|
5989
6146
|
/**
|
|
5990
6147
|
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
6148
|
+
*
|
|
6149
|
+
* @public exported from `@promptbook/core`
|
|
5991
6150
|
*/
|
|
5992
6151
|
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
5993
6152
|
__extends(EnvironmentMismatchError, _super);
|
|
@@ -6126,6 +6285,8 @@ var ANTHROPIC_CLAUDE_MODELS = [
|
|
|
6126
6285
|
|
|
6127
6286
|
/**
|
|
6128
6287
|
* Execution Tools for calling Anthropic Claude API.
|
|
6288
|
+
*
|
|
6289
|
+
* @public exported from `@promptbook/anthropic-claude`
|
|
6129
6290
|
*/
|
|
6130
6291
|
var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
6131
6292
|
/**
|
|
@@ -6351,6 +6512,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
|
|
|
6351
6512
|
*
|
|
6352
6513
|
* @see https://platform.openai.com/docs/models/
|
|
6353
6514
|
* @see https://openai.com/api/pricing/
|
|
6515
|
+
* @public exported from `@promptbook/openai`
|
|
6354
6516
|
*/
|
|
6355
6517
|
var OPENAI_MODELS = [
|
|
6356
6518
|
/*/
|
|
@@ -6731,6 +6893,8 @@ resultContent, rawResponse) {
|
|
|
6731
6893
|
|
|
6732
6894
|
/**
|
|
6733
6895
|
* Execution Tools for calling OpenAI API.
|
|
6896
|
+
*
|
|
6897
|
+
* @public exported from `@promptbook/openai`
|
|
6734
6898
|
*/
|
|
6735
6899
|
var OpenAiExecutionTools = /** @class */ (function () {
|
|
6736
6900
|
/**
|
|
@@ -7042,6 +7206,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
7042
7206
|
* - `process.env.ANTHROPIC_CLAUDE_API_KEY`
|
|
7043
7207
|
*
|
|
7044
7208
|
* @returns @@@
|
|
7209
|
+
* @public exported from `@promptbook/node`
|
|
7045
7210
|
*/
|
|
7046
7211
|
function createLlmToolsFromEnv(options) {
|
|
7047
7212
|
if (options === void 0) { options = {}; }
|
|
@@ -7075,7 +7240,6 @@ function createLlmToolsFromEnv(options) {
|
|
|
7075
7240
|
}
|
|
7076
7241
|
/**
|
|
7077
7242
|
* TODO: [🍜] Use `createLlmToolsFromConfiguration`
|
|
7078
|
-
* TODO: [🔼] !!! Export via `@promptbook/node`
|
|
7079
7243
|
* TODO: @@@ write discussion about this - wizzard
|
|
7080
7244
|
* TODO: Add Azure
|
|
7081
7245
|
* TODO: [🧠] Which name is better `createLlmToolsFromEnv` or `createLlmToolsFromEnvironment`?
|
|
@@ -7085,5 +7249,135 @@ function createLlmToolsFromEnv(options) {
|
|
|
7085
7249
|
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
7086
7250
|
*/
|
|
7087
7251
|
|
|
7088
|
-
|
|
7252
|
+
/**
|
|
7253
|
+
* Stringify the PipelineJson with proper formatting
|
|
7254
|
+
*
|
|
7255
|
+
* Note: [0] It can be used for more JSON types like whole collection of pipelines, single knowledge piece, etc.
|
|
7256
|
+
* Note: In contrast to JSON.stringify, this function ensures that **embedding index** is on single line
|
|
7257
|
+
*
|
|
7258
|
+
* @public exported from `@promptbook/core`
|
|
7259
|
+
*/
|
|
7260
|
+
function stringifyPipelineJson(pipeline) {
|
|
7261
|
+
var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
|
|
7262
|
+
for (var i = 0; i < LOOP_LIMIT; i++) {
|
|
7263
|
+
pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms, "$1".concat(REPLACING_NONCE, "$2"));
|
|
7264
|
+
}
|
|
7265
|
+
pipelineJsonStringified = pipelineJsonStringified.split(REPLACING_NONCE).join(', ');
|
|
7266
|
+
pipelineJsonStringified += '\n';
|
|
7267
|
+
return pipelineJsonStringified;
|
|
7268
|
+
}
|
|
7269
|
+
/**
|
|
7270
|
+
* TODO: [🐝] Not Working propperly @see https://promptbook.studio/samples/mixed-knowledge.ptbk.md
|
|
7271
|
+
* TODO: [🧠][0] Maybe rename to `stringifyPipelineJson`, `stringifyIndexedJson`,...
|
|
7272
|
+
* TODO: [🧠] Maybe more elegant solution than replacing via regex
|
|
7273
|
+
* TODO: [🍙] Make some standart order of json properties
|
|
7274
|
+
*/
|
|
7275
|
+
|
|
7276
|
+
/**
|
|
7277
|
+
* @@@
|
|
7278
|
+
*
|
|
7279
|
+
* @private for `FilesStorage`
|
|
7280
|
+
*/
|
|
7281
|
+
function nameToSubfolderPath(name) {
|
|
7282
|
+
return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
|
|
7283
|
+
}
|
|
7284
|
+
|
|
7285
|
+
/**
|
|
7286
|
+
* @@@
|
|
7287
|
+
*
|
|
7288
|
+
* @public exported from `@promptbook/node`
|
|
7289
|
+
*/
|
|
7290
|
+
var FilesStorage = /** @class */ (function () {
|
|
7291
|
+
function FilesStorage(options) {
|
|
7292
|
+
this.options = options;
|
|
7293
|
+
if (!isRunningInNode()) {
|
|
7294
|
+
throw new EnvironmentMismatchError("FilesStorage works only in Node.js environment");
|
|
7295
|
+
}
|
|
7296
|
+
}
|
|
7297
|
+
/**
|
|
7298
|
+
* @@@
|
|
7299
|
+
*/
|
|
7300
|
+
FilesStorage.prototype.getFilenameForKey = function (key) {
|
|
7301
|
+
var name = titleToName(key);
|
|
7302
|
+
var hash = sha256(hexEncoder.parse(name)).toString( /* hex */);
|
|
7303
|
+
return 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));
|
|
7304
|
+
};
|
|
7305
|
+
/**
|
|
7306
|
+
* @@@ 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.
|
|
7307
|
+
*/
|
|
7308
|
+
FilesStorage.prototype.getItem = function (key) {
|
|
7309
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7310
|
+
var filename, isFileExisting, fileContent, value;
|
|
7311
|
+
return __generator(this, function (_a) {
|
|
7312
|
+
switch (_a.label) {
|
|
7313
|
+
case 0:
|
|
7314
|
+
filename = this.getFilenameForKey(key);
|
|
7315
|
+
return [4 /*yield*/, stat(filename)
|
|
7316
|
+
.then(function (fileStat) { return fileStat.isFile(); })
|
|
7317
|
+
.catch(function () { return false; })];
|
|
7318
|
+
case 1:
|
|
7319
|
+
isFileExisting = _a.sent();
|
|
7320
|
+
if (!isFileExisting) {
|
|
7321
|
+
return [2 /*return*/, null];
|
|
7322
|
+
}
|
|
7323
|
+
return [4 /*yield*/, readFile(filename, 'utf-8')];
|
|
7324
|
+
case 2:
|
|
7325
|
+
fileContent = _a.sent();
|
|
7326
|
+
value = JSON.parse(fileContent);
|
|
7327
|
+
// TODO: [🌗]
|
|
7328
|
+
return [2 /*return*/, value];
|
|
7329
|
+
}
|
|
7330
|
+
});
|
|
7331
|
+
});
|
|
7332
|
+
};
|
|
7333
|
+
/**
|
|
7334
|
+
* @@@ Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
|
|
7335
|
+
*/
|
|
7336
|
+
FilesStorage.prototype.setItem = function (key, value) {
|
|
7337
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7338
|
+
var filename, fileContent;
|
|
7339
|
+
return __generator(this, function (_a) {
|
|
7340
|
+
switch (_a.label) {
|
|
7341
|
+
case 0:
|
|
7342
|
+
filename = this.getFilenameForKey(key);
|
|
7343
|
+
fileContent = stringifyPipelineJson(value);
|
|
7344
|
+
return [4 /*yield*/, mkdir(dirname(filename), { recursive: true })];
|
|
7345
|
+
case 1:
|
|
7346
|
+
_a.sent(); // <- [0]
|
|
7347
|
+
return [4 /*yield*/, writeFile(filename, fileContent, 'utf-8')];
|
|
7348
|
+
case 2:
|
|
7349
|
+
_a.sent();
|
|
7350
|
+
return [2 /*return*/];
|
|
7351
|
+
}
|
|
7352
|
+
});
|
|
7353
|
+
});
|
|
7354
|
+
};
|
|
7355
|
+
/**
|
|
7356
|
+
* @@@ 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.
|
|
7357
|
+
*/
|
|
7358
|
+
FilesStorage.prototype.removeItem = function (key) {
|
|
7359
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7360
|
+
var filename;
|
|
7361
|
+
return __generator(this, function (_a) {
|
|
7362
|
+
switch (_a.label) {
|
|
7363
|
+
case 0:
|
|
7364
|
+
filename = this.getFilenameForKey(key);
|
|
7365
|
+
// TODO: [🧠] What to use `unlink` or `rm`
|
|
7366
|
+
return [4 /*yield*/, unlink(filename)];
|
|
7367
|
+
case 1:
|
|
7368
|
+
// TODO: [🧠] What to use `unlink` or `rm`
|
|
7369
|
+
_a.sent();
|
|
7370
|
+
return [2 /*return*/];
|
|
7371
|
+
}
|
|
7372
|
+
});
|
|
7373
|
+
});
|
|
7374
|
+
};
|
|
7375
|
+
return FilesStorage;
|
|
7376
|
+
}());
|
|
7377
|
+
/**
|
|
7378
|
+
* TODO: [🌗] Maybe some checkers, not all valid JSONs are desired and valid values
|
|
7379
|
+
* Note: [🟢] This code should never be published outside of `@promptbook/node`
|
|
7380
|
+
*/
|
|
7381
|
+
|
|
7382
|
+
export { FilesStorage, PROMPTBOOK_VERSION, createCollectionFromDirectory, createLlmToolsFromEnv };
|
|
7089
7383
|
//# sourceMappingURL=index.es.js.map
|