@promptbook/javascript 0.88.0-1
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 +431 -0
- package/esm/index.es.js +1796 -0
- package/esm/index.es.js.map +1 -0
- package/esm/typings/books/index.d.ts +131 -0
- package/esm/typings/src/_packages/anthropic-claude.index.d.ts +16 -0
- package/esm/typings/src/_packages/azure-openai.index.d.ts +10 -0
- package/esm/typings/src/_packages/browser.index.d.ts +10 -0
- package/esm/typings/src/_packages/cli.index.d.ts +56 -0
- package/esm/typings/src/_packages/core.index.d.ts +260 -0
- package/esm/typings/src/_packages/deepseek.index.d.ts +8 -0
- package/esm/typings/src/_packages/documents.index.d.ts +8 -0
- package/esm/typings/src/_packages/editable.index.d.ts +90 -0
- package/esm/typings/src/_packages/fake-llm.index.d.ts +6 -0
- package/esm/typings/src/_packages/google.index.d.ts +10 -0
- package/esm/typings/src/_packages/javascript.index.d.ts +10 -0
- package/esm/typings/src/_packages/legacy-documents.index.d.ts +8 -0
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +48 -0
- package/esm/typings/src/_packages/markitdown.index.d.ts +8 -0
- package/esm/typings/src/_packages/node.index.d.ts +24 -0
- package/esm/typings/src/_packages/openai.index.d.ts +20 -0
- package/esm/typings/src/_packages/pdf.index.d.ts +14 -0
- package/esm/typings/src/_packages/remote-client.index.d.ts +18 -0
- package/esm/typings/src/_packages/remote-server.index.d.ts +12 -0
- package/esm/typings/src/_packages/templates.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +564 -0
- package/esm/typings/src/_packages/utils.index.d.ts +162 -0
- package/esm/typings/src/_packages/vercel.index.d.ts +6 -0
- package/esm/typings/src/_packages/website-crawler.index.d.ts +8 -0
- package/esm/typings/src/_packages/wizzard.index.d.ts +56 -0
- package/esm/typings/src/cli/cli-commands/_boilerplate.d.ts +13 -0
- package/esm/typings/src/cli/cli-commands/about.d.ts +14 -0
- package/esm/typings/src/cli/cli-commands/hello.d.ts +14 -0
- package/esm/typings/src/cli/cli-commands/list-models.d.ts +13 -0
- package/esm/typings/src/cli/cli-commands/list-scrapers.d.ts +13 -0
- package/esm/typings/src/cli/cli-commands/make.d.ts +16 -0
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +15 -0
- package/esm/typings/src/cli/cli-commands/run.d.ts +17 -0
- package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +32 -0
- package/esm/typings/src/cli/cli-commands/start-server.d.ts +13 -0
- package/esm/typings/src/cli/cli-commands/test-command.d.ts +16 -0
- package/esm/typings/src/cli/main.d.ts +16 -0
- package/esm/typings/src/cli/promptbookCli.d.ts +13 -0
- package/esm/typings/src/cli/test/ptbk.d.ts +5 -0
- package/esm/typings/src/cli/test/ptbk.test.d.ts +1 -0
- package/esm/typings/src/cli/test/ptbk2.d.ts +5 -0
- package/esm/typings/src/collection/PipelineCollection.d.ts +27 -0
- package/esm/typings/src/collection/SimplePipelineCollection.d.ts +37 -0
- package/esm/typings/src/collection/collectionToJson.d.ts +13 -0
- package/esm/typings/src/collection/collectionToJson.test.d.ts +7 -0
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +65 -0
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.test.d.ts +1 -0
- package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +13 -0
- package/esm/typings/src/collection/constructors/createCollectionFromJson.test.d.ts +1 -0
- package/esm/typings/src/collection/constructors/createCollectionFromPromise.d.ts +23 -0
- package/esm/typings/src/collection/constructors/createCollectionFromPromise.test.d.ts +1 -0
- package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +29 -0
- package/esm/typings/src/collection/constructors/createSubcollection.d.ts +13 -0
- package/esm/typings/src/commands/BOOK_VERSION/BookVersionCommand.d.ts +11 -0
- package/esm/typings/src/commands/BOOK_VERSION/bookVersionCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/BOOK_VERSION/bookVersionCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/EXPECT/ExpectCommand.d.ts +17 -0
- package/esm/typings/src/commands/EXPECT/expectCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/FOREACH/ForeachCommand.d.ts +10 -0
- package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +27 -0
- package/esm/typings/src/commands/FOREACH/foreachCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +14 -0
- package/esm/typings/src/commands/FORMAT/FormatCommand.d.ts +9 -0
- package/esm/typings/src/commands/FORMAT/formatCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/FORMAT/formatCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/FORMFACTOR/FormfactorCommand.d.ts +11 -0
- package/esm/typings/src/commands/FORMFACTOR/formfactorCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/FORMFACTOR/formfactorCommandParser.d.ts +11 -0
- package/esm/typings/src/commands/JOKER/JokerCommand.d.ts +11 -0
- package/esm/typings/src/commands/JOKER/jokerCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/JOKER/jokerCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +11 -0
- package/esm/typings/src/commands/KNOWLEDGE/knowledgeCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/KNOWLEDGE/knowledgeCommandParser.d.ts +12 -0
- package/esm/typings/src/commands/KNOWLEDGE/utils/knowledgeSourceContentToName.d.ts +11 -0
- package/esm/typings/src/commands/KNOWLEDGE/utils/knowledgeSourceContentToName.test.d.ts +4 -0
- package/esm/typings/src/commands/MODEL/ModelCommand.d.ts +14 -0
- package/esm/typings/src/commands/MODEL/modelCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/MODEL/modelCommandParser.d.ts +10 -0
- package/esm/typings/src/commands/PARAMETER/ParameterCommand.d.ts +15 -0
- package/esm/typings/src/commands/PARAMETER/parameterCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/PARAMETER/parameterCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/PERSONA/PersonaCommand.d.ts +13 -0
- package/esm/typings/src/commands/PERSONA/personaCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/PERSONA/personaCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/POSTPROCESS/PostprocessCommand.d.ts +11 -0
- package/esm/typings/src/commands/POSTPROCESS/postprocessCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/POSTPROCESS/postprocessCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/SECTION/SectionCommand.d.ts +11 -0
- package/esm/typings/src/commands/SECTION/sectionCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/SECTION/sectionCommandParser.d.ts +20 -0
- package/esm/typings/src/commands/URL/UrlCommand.d.ts +10 -0
- package/esm/typings/src/commands/URL/urlCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/URL/urlCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/X_ACTION/ActionCommand.d.ts +9 -0
- package/esm/typings/src/commands/X_ACTION/actionCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/X_ACTION/actionCommandParser.d.ts +12 -0
- package/esm/typings/src/commands/X_INSTRUMENT/InstrumentCommand.d.ts +9 -0
- package/esm/typings/src/commands/X_INSTRUMENT/instrumentCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/X_INSTRUMENT/instrumentCommandParser.d.ts +12 -0
- package/esm/typings/src/commands/_BOILERPLATE/BoilerplateCommand.d.ts +10 -0
- package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +11 -0
- package/esm/typings/src/commands/_common/getParserForCommand.d.ts +11 -0
- package/esm/typings/src/commands/_common/getParserForCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/_common/parseCommand.d.ts +12 -0
- package/esm/typings/src/commands/_common/parseCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/_common/stringifyCommand.d.ts +12 -0
- package/esm/typings/src/commands/_common/stringifyCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/_common/types/Command.d.ts +6 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +197 -0
- package/esm/typings/src/commands/_common/types/CommandType.d.ts +17 -0
- package/esm/typings/src/commands/_common/types/CommandUsagePlaces.d.ts +13 -0
- package/esm/typings/src/commands/index.d.ts +9 -0
- package/esm/typings/src/config.d.ts +285 -0
- package/esm/typings/src/config.test.d.ts +4 -0
- package/esm/typings/src/constants.d.ts +35 -0
- package/esm/typings/src/conversion/archive/loadArchive.d.ts +16 -0
- package/esm/typings/src/conversion/archive/saveArchive.d.ts +18 -0
- package/esm/typings/src/conversion/compilePipeline.d.ts +25 -0
- package/esm/typings/src/conversion/compilePipeline.test.d.ts +1 -0
- package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +21 -0
- package/esm/typings/src/conversion/parsePipeline.d.ts +30 -0
- package/esm/typings/src/conversion/parsePipeline.test.d.ts +1 -0
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +18 -0
- package/esm/typings/src/conversion/prettify/PrettifyOptions.d.ts +13 -0
- package/esm/typings/src/conversion/prettify/prettifyPipelineString.d.ts +12 -0
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +30 -0
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTask.d.ts +15 -0
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTask.test.d.ts +1 -0
- package/esm/typings/src/conversion/validation/_importPipeline.d.ts +23 -0
- package/esm/typings/src/conversion/validation/pipelineStringToJson-parseErrors.test.d.ts +4 -0
- package/esm/typings/src/conversion/validation/validatePipeline-logicErrors.test.d.ts +4 -0
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +42 -0
- package/esm/typings/src/conversion/validation/validatePipeline.test.d.ts +4 -0
- package/esm/typings/src/dialogs/callback/CallbackInterfaceTools.d.ts +17 -0
- package/esm/typings/src/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +14 -0
- package/esm/typings/src/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +22 -0
- package/esm/typings/src/dialogs/user-interface-execution-tools.test.d.ts +1 -0
- package/esm/typings/src/errors/0-BoilerplateError.d.ts +12 -0
- package/esm/typings/src/errors/0-index.d.ts +85 -0
- package/esm/typings/src/errors/AbstractFormatError.d.ts +11 -0
- package/esm/typings/src/errors/CollectionError.d.ts +9 -0
- package/esm/typings/src/errors/EnvironmentMismatchError.d.ts +9 -0
- package/esm/typings/src/errors/ExpectError.d.ts +12 -0
- package/esm/typings/src/errors/KnowledgeScrapeError.d.ts +9 -0
- package/esm/typings/src/errors/LimitReachedError.d.ts +9 -0
- package/esm/typings/src/errors/MissingToolsError.d.ts +9 -0
- package/esm/typings/src/errors/NotFoundError.d.ts +9 -0
- package/esm/typings/src/errors/NotYetImplementedError.d.ts +9 -0
- package/esm/typings/src/errors/ParseError.d.ts +12 -0
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +9 -0
- package/esm/typings/src/errors/PipelineLogicError.d.ts +9 -0
- package/esm/typings/src/errors/PipelineUrlError.d.ts +9 -0
- package/esm/typings/src/errors/UnexpectedError.d.ts +9 -0
- package/esm/typings/src/errors/utils/ErrorJson.d.ts +20 -0
- package/esm/typings/src/errors/utils/deserializeError.d.ts +7 -0
- package/esm/typings/src/errors/utils/deserializeError.test.d.ts +1 -0
- package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +6 -0
- package/esm/typings/src/errors/utils/serializeError.d.ts +7 -0
- package/esm/typings/src/errors/utils/serializeError.test.d.ts +1 -0
- package/esm/typings/src/executables/$provideExecutablesForNode.d.ts +12 -0
- package/esm/typings/src/executables/apps/locateLibreoffice.d.ts +11 -0
- package/esm/typings/src/executables/apps/locateLibreoffice.test.d.ts +1 -0
- package/esm/typings/src/executables/apps/locatePandoc.d.ts +11 -0
- package/esm/typings/src/executables/apps/locatePandoc.test.d.ts +1 -0
- package/esm/typings/src/executables/locateApp.d.ts +33 -0
- package/esm/typings/src/executables/locateApp.test.d.ts +1 -0
- package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +12 -0
- package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +12 -0
- package/esm/typings/src/executables/platforms/locateAppOnWindows.d.ts +12 -0
- package/esm/typings/src/execution/AbstractTaskResult.d.ts +25 -0
- package/esm/typings/src/execution/AvailableModel.d.ts +38 -0
- package/esm/typings/src/execution/CommonToolsOptions.d.ts +24 -0
- package/esm/typings/src/execution/EmbeddingVector.d.ts +8 -0
- package/esm/typings/src/execution/Executables.d.ts +18 -0
- package/esm/typings/src/execution/ExecutionTask.d.ts +75 -0
- package/esm/typings/src/execution/ExecutionTools.d.ts +69 -0
- package/esm/typings/src/execution/FilesystemTools.d.ts +9 -0
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +61 -0
- package/esm/typings/src/execution/LlmExecutionToolsConstructor.d.ts +10 -0
- package/esm/typings/src/execution/PipelineExecutor.d.ts +16 -0
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +37 -0
- package/esm/typings/src/execution/PromptResult.d.ts +101 -0
- package/esm/typings/src/execution/PromptResultUsage.d.ts +33 -0
- package/esm/typings/src/execution/PromptbookFetch.d.ts +12 -0
- package/esm/typings/src/execution/PromptbookFetch.test-type.d.ts +5 -0
- package/esm/typings/src/execution/ScriptExecutionTools.d.ts +39 -0
- package/esm/typings/src/execution/UncertainNumber.d.ts +19 -0
- package/esm/typings/src/execution/UserInterfaceTools.d.ts +46 -0
- package/esm/typings/src/execution/assertsTaskSuccessful.d.ts +14 -0
- package/esm/typings/src/execution/createPipelineExecutor/$OngoingTaskResult.d.ts +45 -0
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +46 -0
- package/esm/typings/src/execution/createPipelineExecutor/00-createPipelineExecutor.d.ts +10 -0
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +45 -0
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +48 -0
- package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +15 -0
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +64 -0
- package/esm/typings/src/execution/createPipelineExecutor/filterJustOutputParameters.d.ts +34 -0
- package/esm/typings/src/execution/createPipelineExecutor/getContextForTask.d.ts +10 -0
- package/esm/typings/src/execution/createPipelineExecutor/getExamplesForTask.d.ts +10 -0
- package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +27 -0
- package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +30 -0
- package/esm/typings/src/execution/embeddingVectorToString.d.ts +7 -0
- package/esm/typings/src/execution/execution-report/ExecutionPromptReportJson.d.ts +24 -0
- package/esm/typings/src/execution/execution-report/ExecutionReportJson.d.ts +41 -0
- package/esm/typings/src/execution/execution-report/ExecutionReportString.d.ts +16 -0
- package/esm/typings/src/execution/execution-report/ExecutionReportStringOptions.d.ts +25 -0
- package/esm/typings/src/execution/execution-report/countWorkingDuration.d.ts +7 -0
- package/esm/typings/src/execution/execution-report/countWorkingDuration.test.d.ts +1 -0
- package/esm/typings/src/execution/execution-report/executionReportJsonToString.d.ts +15 -0
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/AutomaticTranslator.d.ts +7 -0
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/DebugAutomaticTranslator.d.ts +11 -0
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/FakeAutomaticTranslator.d.ts +8 -0
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +22 -0
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +7 -0
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +8 -0
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.test.d.ts +1 -0
- package/esm/typings/src/execution/translation/automatic-translate/translateMessages.d.ts +12 -0
- package/esm/typings/src/execution/utils/$provideExecutionToolsForNode.d.ts +13 -0
- package/esm/typings/src/execution/utils/addUsage.d.ts +9 -0
- package/esm/typings/src/execution/utils/addUsage.test.d.ts +1 -0
- package/esm/typings/src/execution/utils/checkExpectations.d.ts +29 -0
- package/esm/typings/src/execution/utils/checkExpectations.test.d.ts +1 -0
- package/esm/typings/src/execution/utils/computeUsageCounts.d.ts +10 -0
- package/esm/typings/src/execution/utils/forEachAsync.d.ts +20 -0
- package/esm/typings/src/execution/utils/uncertainNumber.d.ts +9 -0
- package/esm/typings/src/execution/utils/usage-constants.d.ts +130 -0
- package/esm/typings/src/execution/utils/usageToHuman.d.ts +26 -0
- package/esm/typings/src/execution/utils/usageToWorktime.d.ts +20 -0
- package/esm/typings/src/execution/utils/usageToWorktime.test.d.ts +1 -0
- package/esm/typings/src/expectations/drafts/isDomainNameFree.d.ts +10 -0
- package/esm/typings/src/expectations/drafts/isGithubNameFree.d.ts +10 -0
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +70 -0
- package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +31 -0
- package/esm/typings/src/formats/csv/CsvFormatDefinition.d.ts +17 -0
- package/esm/typings/src/formats/csv/CsvFormatError.d.ts +10 -0
- package/esm/typings/src/formats/csv/CsvSettings.d.ts +13 -0
- package/esm/typings/src/formats/index.d.ts +9 -0
- package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +19 -0
- package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +6 -0
- package/esm/typings/src/formats/json/utils/isValidJsonString.test.d.ts +1 -0
- package/esm/typings/src/formats/text/TextFormatDefinition.d.ts +19 -0
- package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +19 -0
- package/esm/typings/src/formfactors/_boilerplate/BoilerplateFormfactorDefinition.d.ts +14 -0
- package/esm/typings/src/formfactors/_common/AbstractFormfactorDefinition.d.ts +40 -0
- package/esm/typings/src/formfactors/_common/FormfactorDefinition.d.ts +8 -0
- package/esm/typings/src/formfactors/_common/string_formfactor_name.d.ts +5 -0
- package/esm/typings/src/formfactors/chatbot/ChatbotFormfactorDefinition.d.ts +45 -0
- package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +24 -0
- package/esm/typings/src/formfactors/generic/GenericFormfactorDefinition.d.ts +14 -0
- package/esm/typings/src/formfactors/image-generator/ImageGeneratorFormfactorDefinition.d.ts +24 -0
- package/esm/typings/src/formfactors/index.d.ts +145 -0
- package/esm/typings/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +19 -0
- package/esm/typings/src/formfactors/sheets/SheetsFormfactorDefinition.d.ts +25 -0
- package/esm/typings/src/formfactors/translator/TranslatorFormfactorDefinition.d.ts +24 -0
- package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +20 -0
- package/esm/typings/src/high-level-abstractions/implicit-formfactor/ImplicitFormfactorHla.d.ts +10 -0
- package/esm/typings/src/high-level-abstractions/index.d.ts +54 -0
- package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +13 -0
- package/esm/typings/src/llm-providers/_common/register/$llmToolsMetadataRegister.d.ts +13 -0
- package/esm/typings/src/llm-providers/_common/register/$llmToolsRegister.d.ts +13 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +25 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +24 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +15 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +27 -0
- package/esm/typings/src/llm-providers/_common/register/$registeredLlmToolsMessage.d.ts +22 -0
- package/esm/typings/src/llm-providers/_common/register/LlmToolsConfiguration.d.ts +23 -0
- package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +36 -0
- package/esm/typings/src/llm-providers/_common/register/LlmToolsOptions.d.ts +10 -0
- package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +40 -0
- package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.test.d.ts +1 -0
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +28 -0
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +19 -0
- package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +19 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +15 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/countTotalUsage.d.ts +17 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +36 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +60 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +31 -0
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +24 -0
- package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +18 -0
- package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.test.d.ts +4 -0
- package/esm/typings/src/llm-providers/anthropic-claude/createAnthropicClaudeExecutionTools.d.ts +19 -0
- package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +7 -0
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +14 -0
- package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +16 -0
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +63 -0
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +37 -0
- package/esm/typings/src/llm-providers/azure-openai/createAzureOpenAiExecutionTools.d.ts +15 -0
- package/esm/typings/src/llm-providers/azure-openai/playground/playground.d.ts +6 -0
- package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +14 -0
- package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +15 -0
- package/esm/typings/src/llm-providers/deepseek/DeepseekExecutionToolsOptions.d.ts +9 -0
- package/esm/typings/src/llm-providers/deepseek/createDeepseekExecutionTools.d.ts +14 -0
- package/esm/typings/src/llm-providers/deepseek/register-configuration.d.ts +14 -0
- package/esm/typings/src/llm-providers/deepseek/register-constructor.d.ts +15 -0
- package/esm/typings/src/llm-providers/google/GoogleExecutionToolsOptions.d.ts +9 -0
- package/esm/typings/src/llm-providers/google/createGoogleExecutionTools.d.ts +14 -0
- package/esm/typings/src/llm-providers/google/register-configuration.d.ts +14 -0
- package/esm/typings/src/llm-providers/google/register-constructor.d.ts +15 -0
- package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +15 -0
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +40 -0
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +44 -0
- package/esm/typings/src/llm-providers/mocked/test/fakeTextToExpectations.test.d.ts +1 -0
- package/esm/typings/src/llm-providers/mocked/test/faked-completion.test.d.ts +1 -0
- package/esm/typings/src/llm-providers/mocked/test/joker.test.d.ts +4 -0
- package/esm/typings/src/llm-providers/mocked/test/mocked-chat.test.d.ts +5 -0
- package/esm/typings/src/llm-providers/mocked/test/mocked-completion.test.d.ts +4 -0
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +63 -0
- package/esm/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +21 -0
- package/esm/typings/src/llm-providers/multiple/playground/playground.d.ts +5 -0
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +36 -0
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionToolsOptions.d.ts +14 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +84 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +11 -0
- package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.d.ts +18 -0
- package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.test.d.ts +4 -0
- package/esm/typings/src/llm-providers/openai/computeUsage.d.ts +16 -0
- package/esm/typings/src/llm-providers/openai/computeUsage.test.d.ts +1 -0
- package/esm/typings/src/llm-providers/openai/createOpenAiAssistantExecutionTools.d.ts +15 -0
- package/esm/typings/src/llm-providers/openai/createOpenAiExecutionTools.d.ts +15 -0
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +31 -0
- package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +6 -0
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +24 -0
- package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +25 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +59 -0
- package/esm/typings/src/llm-providers/remote/playground/playground.d.ts +5 -0
- package/esm/typings/src/llm-providers/vercel/VercelExecutionToolsOptions.d.ts +23 -0
- package/esm/typings/src/llm-providers/vercel/VercelProvider.d.ts +13 -0
- package/esm/typings/src/llm-providers/vercel/createExecutionToolsFromVercelProvider.d.ts +8 -0
- package/esm/typings/src/llm-providers/vercel/playground/playground.d.ts +6 -0
- package/esm/typings/src/other/templates/getBookTemplates.d.ts +24 -0
- package/esm/typings/src/other/templates/getTemplatesPipelineCollection.d.ts +10 -0
- package/esm/typings/src/personas/preparePersona.d.ts +17 -0
- package/esm/typings/src/pipeline/PipelineInterface/PipelineInterface.d.ts +22 -0
- package/esm/typings/src/pipeline/PipelineInterface/constants.d.ts +14 -0
- package/esm/typings/src/pipeline/PipelineInterface/getPipelineInterface.d.ts +11 -0
- package/esm/typings/src/pipeline/PipelineInterface/isPipelineImplementingInterface.d.ts +26 -0
- package/esm/typings/src/pipeline/PipelineInterface/isPipelineInterfacesEqual.d.ts +10 -0
- package/esm/typings/src/pipeline/PipelineJson/CommonTaskJson.d.ts +100 -0
- package/esm/typings/src/pipeline/PipelineJson/DialogTaskJson.d.ts +13 -0
- package/esm/typings/src/pipeline/PipelineJson/Expectations.d.ts +40 -0
- package/esm/typings/src/pipeline/PipelineJson/KnowledgePieceJson.d.ts +73 -0
- package/esm/typings/src/pipeline/PipelineJson/KnowledgeSourceJson.d.ts +44 -0
- package/esm/typings/src/pipeline/PipelineJson/ParameterJson.d.ts +98 -0
- package/esm/typings/src/pipeline/PipelineJson/PersonaJson.d.ts +45 -0
- package/esm/typings/src/pipeline/PipelineJson/PipelineJson.d.ts +112 -0
- package/esm/typings/src/pipeline/PipelineJson/PreparationJson.d.ts +22 -0
- package/esm/typings/src/pipeline/PipelineJson/PromptTaskJson.d.ts +26 -0
- package/esm/typings/src/pipeline/PipelineJson/ScriptTaskJson.d.ts +20 -0
- package/esm/typings/src/pipeline/PipelineJson/SimpleTaskJson.d.ts +13 -0
- package/esm/typings/src/pipeline/PipelineJson/TaskJson.d.ts +11 -0
- package/esm/typings/src/pipeline/PipelineString.d.ts +9 -0
- package/esm/typings/src/pipeline/book-notation.d.ts +19 -0
- package/esm/typings/src/pipeline/isValidPipelineString.d.ts +13 -0
- package/esm/typings/src/pipeline/isValidPipelineString.test.d.ts +4 -0
- package/esm/typings/src/pipeline/prompt-notation.d.ts +31 -0
- package/esm/typings/src/pipeline/prompt-notation.test.d.ts +4 -0
- package/esm/typings/src/pipeline/validatePipelineString.d.ts +14 -0
- package/esm/typings/src/postprocessing/utils/extractBlock.d.ts +16 -0
- package/esm/typings/src/postprocessing/utils/extractJsonBlock.d.ts +25 -0
- package/esm/typings/src/postprocessing/utils/extractJsonBlock.test.d.ts +1 -0
- package/esm/typings/src/prepare/PrepareAndScrapeOptions.d.ts +51 -0
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +18 -0
- package/esm/typings/src/prepare/isPipelinePrepared.test.d.ts +1 -0
- package/esm/typings/src/prepare/preparePipeline.d.ts +22 -0
- package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +17 -0
- package/esm/typings/src/prepare/prepareTasks.d.ts +33 -0
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +13 -0
- package/esm/typings/src/remote-server/createRemoteClient.d.ts +10 -0
- package/esm/typings/src/remote-server/socket-types/_common/PromptbookServer_Error.d.ts +7 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +52 -0
- package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +17 -0
- package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Response.d.ts +17 -0
- package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +17 -0
- package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Response.d.ts +12 -0
- package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +17 -0
- package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Response.d.ts +12 -0
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +26 -0
- package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +32 -0
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +75 -0
- package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +43 -0
- package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/_boilerplate/playground/boilerplate-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/_boilerplate/register-constructor.d.ts +15 -0
- package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +28 -0
- package/esm/typings/src/scrapers/_common/Converter.d.ts +23 -0
- package/esm/typings/src/scrapers/_common/Scraper.d.ts +59 -0
- package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +14 -0
- package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +19 -0
- package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.test.d.ts +1 -0
- package/esm/typings/src/scrapers/_common/register/$provideFilesystemForNode.d.ts +11 -0
- package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +12 -0
- package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +15 -0
- package/esm/typings/src/scrapers/_common/register/$provideScriptingForNode.d.ts +11 -0
- package/esm/typings/src/scrapers/_common/register/$registeredScrapersMessage.d.ts +13 -0
- package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +13 -0
- package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +13 -0
- package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +43 -0
- package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +12 -0
- package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +34 -0
- package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.test.d.ts +4 -0
- package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +11 -0
- package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +10 -0
- package/esm/typings/src/scrapers/document/DocumentScraper.d.ts +43 -0
- package/esm/typings/src/scrapers/document/DocumentScraper.test.d.ts +4 -0
- package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/document/playground/document-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/document/register-constructor.d.ts +15 -0
- package/esm/typings/src/scrapers/document/register-metadata.d.ts +28 -0
- package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +43 -0
- package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.test.d.ts +4 -0
- package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/document-legacy/playground/legacy-document-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +15 -0
- package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +28 -0
- package/esm/typings/src/scrapers/markdown/MarkdownScraper.d.ts +29 -0
- package/esm/typings/src/scrapers/markdown/MarkdownScraper.test.d.ts +4 -0
- package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/markdown/playground/markdown-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +15 -0
- package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +28 -0
- package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +50 -0
- package/esm/typings/src/scrapers/markitdown/createMarkitdownScraper.d.ts +22 -0
- package/esm/typings/src/scrapers/markitdown/playground/markitdown-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/markitdown/register-constructor.d.ts +17 -0
- package/esm/typings/src/scrapers/markitdown/register-metadata.d.ts +28 -0
- package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +41 -0
- package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/pdf/playground/pdf-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +15 -0
- package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +28 -0
- package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +50 -0
- package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +22 -0
- package/esm/typings/src/scrapers/website/playground/website-scraper-playground.d.ts +5 -0
- package/esm/typings/src/scrapers/website/register-constructor.d.ts +15 -0
- package/esm/typings/src/scrapers/website/register-metadata.d.ts +28 -0
- package/esm/typings/src/scrapers/website/utils/createShowdownConverter.d.ts +7 -0
- package/esm/typings/src/scrapers/website/utils/createShowdownConverter.test.d.ts +1 -0
- package/esm/typings/src/scripting/_test/custom-function-async.test.ts.test.d.ts +1 -0
- package/esm/typings/src/scripting/_test/custom-function-missing.test.d.ts +1 -0
- package/esm/typings/src/scripting/_test/custom-function-with-dependencies.test.d.ts +1 -0
- package/esm/typings/src/scripting/_test/custom-function.test.d.ts +1 -0
- package/esm/typings/src/scripting/_test/postprocessing.test.d.ts +1 -0
- package/esm/typings/src/scripting/_test/script-execution-errors.test.d.ts +1 -0
- package/esm/typings/src/scripting/_test/script-execution-tools.test.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.d.ts +22 -0
- package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionTools.d.ts +8 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +26 -0
- package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +52 -0
- package/esm/typings/src/scripting/javascript/utils/extractVariablesFromJavascript.d.ts +14 -0
- package/esm/typings/src/scripting/javascript/utils/extractVariablesFromJavascript.test.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/utils/extractVariablesFromScript.test.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +14 -0
- package/esm/typings/src/scripting/python/PythonExecutionTools.d.ts +18 -0
- package/esm/typings/src/scripting/typescript/TypescriptExecutionTools.d.ts +18 -0
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +24 -0
- package/esm/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
- package/esm/typings/src/storage/blackhole/BlackholeStorage.d.ts +33 -0
- package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +33 -0
- package/esm/typings/src/storage/file-cache-storage/FileCacheStorageOptions.d.ts +10 -0
- package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.d.ts +7 -0
- package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
- package/esm/typings/src/storage/local-storage/getLocalStorage.d.ts +10 -0
- package/esm/typings/src/storage/local-storage/getSessionStorage.d.ts +10 -0
- package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromWebStorage.d.ts +11 -0
- package/esm/typings/src/storage/memory/MemoryStorage.d.ts +33 -0
- package/esm/typings/src/storage/utils/PrefixStorage.d.ts +25 -0
- package/esm/typings/src/types/Arrayable.d.ts +11 -0
- package/esm/typings/src/types/IntermediateFilesStrategy.d.ts +7 -0
- package/esm/typings/src/types/ModelRequirements.d.ts +104 -0
- package/esm/typings/src/types/ModelVariant.d.ts +15 -0
- package/esm/typings/src/types/NonEmptyArray.d.ts +8 -0
- package/esm/typings/src/types/Prompt.d.ts +111 -0
- package/esm/typings/src/types/ScriptLanguage.d.ts +13 -0
- package/esm/typings/src/types/SectionType.d.ts +21 -0
- package/esm/typings/src/types/TaskType.d.ts +15 -0
- package/esm/typings/src/types/typeAliasEmoji.d.ts +12 -0
- package/esm/typings/src/types/typeAliases.d.ts +644 -0
- package/esm/typings/src/utils/$Register.d.ts +39 -0
- package/esm/typings/src/utils/$getCurrentDate.d.ts +10 -0
- package/esm/typings/src/utils/FromtoItems.d.ts +19 -0
- package/esm/typings/src/utils/arrayableToArray.d.ts +11 -0
- package/esm/typings/src/utils/arrayableToArray.test.d.ts +1 -0
- package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +17 -0
- package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.test.d.ts +1 -0
- package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.d.ts +10 -0
- package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.test.d.ts +1 -0
- package/esm/typings/src/utils/editable/edit-pipeline-string/removePipelineCommand.d.ts +22 -0
- package/esm/typings/src/utils/editable/edit-pipeline-string/removePipelineCommand.test.d.ts +1 -0
- package/esm/typings/src/utils/editable/types/PipelineEditableSerialized.d.ts +27 -0
- package/esm/typings/src/utils/editable/utils/isFlatPipeline.d.ts +7 -0
- package/esm/typings/src/utils/editable/utils/isFlatPipeline.test.d.ts +1 -0
- package/esm/typings/src/utils/editable/utils/renamePipelineParameter.d.ts +29 -0
- package/esm/typings/src/utils/editable/utils/renamePipelineParameter.test.d.ts +1 -0
- package/esm/typings/src/utils/editable/utils/stringifyPipelineJson.d.ts +16 -0
- package/esm/typings/src/utils/emojis.d.ts +24 -0
- package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +9 -0
- package/esm/typings/src/utils/environment/$isRunningInBrowser.d.ts +11 -0
- package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +11 -0
- package/esm/typings/src/utils/environment/$isRunningInNode.d.ts +11 -0
- package/esm/typings/src/utils/environment/$isRunningInWebWorker.d.ts +11 -0
- package/esm/typings/src/utils/execCommand/$execCommand.d.ts +16 -0
- package/esm/typings/src/utils/execCommand/$execCommandNormalizeOptions.d.ts +12 -0
- package/esm/typings/src/utils/execCommand/$execCommands.d.ts +18 -0
- package/esm/typings/src/utils/execCommand/ExecCommandOptions.d.ts +45 -0
- package/esm/typings/src/utils/execCommand/execCommand.test.d.ts +1 -0
- package/esm/typings/src/utils/execCommand/execCommandNormalizeOptions.test.d.ts +1 -0
- package/esm/typings/src/utils/expectation-counters/constants.d.ts +16 -0
- package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +7 -0
- package/esm/typings/src/utils/expectation-counters/countCharacters.test.d.ts +1 -0
- package/esm/typings/src/utils/expectation-counters/countLines.d.ts +9 -0
- package/esm/typings/src/utils/expectation-counters/countLines.test.d.ts +1 -0
- package/esm/typings/src/utils/expectation-counters/countPages.d.ts +9 -0
- package/esm/typings/src/utils/expectation-counters/countPages.test.d.ts +1 -0
- package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +7 -0
- package/esm/typings/src/utils/expectation-counters/countParagraphs.test.d.ts +1 -0
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +13 -0
- package/esm/typings/src/utils/expectation-counters/countSentences.test.d.ts +1 -0
- package/esm/typings/src/utils/expectation-counters/countWords.d.ts +7 -0
- package/esm/typings/src/utils/expectation-counters/countWords.test.d.ts +1 -0
- package/esm/typings/src/utils/expectation-counters/index.d.ts +12 -0
- package/esm/typings/src/utils/files/extensionToMimeType.d.ts +8 -0
- package/esm/typings/src/utils/files/extensionToMimeType.test.d.ts +1 -0
- package/esm/typings/src/utils/files/getFileExtension.d.ts +8 -0
- package/esm/typings/src/utils/files/getFileExtension.test.d.ts +1 -0
- package/esm/typings/src/utils/files/isDirectoryExisting.d.ts +14 -0
- package/esm/typings/src/utils/files/isDirectoryExisting.test.d.ts +1 -0
- package/esm/typings/src/utils/files/isExecutable.d.ts +11 -0
- package/esm/typings/src/utils/files/isFileExisting.d.ts +13 -0
- package/esm/typings/src/utils/files/isFileExisting.test.d.ts +1 -0
- package/esm/typings/src/utils/files/listAllFiles.d.ts +17 -0
- package/esm/typings/src/utils/files/listAllFiles.test.d.ts +1 -0
- package/esm/typings/src/utils/files/mimeTypeToExtension.d.ts +10 -0
- package/esm/typings/src/utils/files/mimeTypeToExtension.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +14 -0
- package/esm/typings/src/utils/markdown/addAutoGeneratedSection.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +38 -0
- package/esm/typings/src/utils/markdown/createMarkdownChart.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/createMarkdownTable.d.ts +11 -0
- package/esm/typings/src/utils/markdown/createMarkdownTable.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/escapeMarkdownBlock.d.ts +11 -0
- package/esm/typings/src/utils/markdown/escapeMarkdownBlock.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +36 -0
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/extractAllListItemsFromMarkdown.d.ts +15 -0
- package/esm/typings/src/utils/markdown/extractAllListItemsFromMarkdown.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +22 -0
- package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/flattenMarkdown.d.ts +17 -0
- package/esm/typings/src/utils/markdown/flattenMarkdown.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/parseMarkdownSection.d.ts +34 -0
- package/esm/typings/src/utils/markdown/parseMarkdownSection.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/prettifyMarkdown.d.ts +9 -0
- package/esm/typings/src/utils/markdown/prettifyMarkdown.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/removeMarkdownComments.d.ts +10 -0
- package/esm/typings/src/utils/markdown/removeMarkdownComments.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/removeMarkdownFormatting.d.ts +9 -0
- package/esm/typings/src/utils/markdown/removeMarkdownFormatting.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/splitMarkdownIntoSections.d.ts +15 -0
- package/esm/typings/src/utils/markdown/splitMarkdownIntoSections.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/DIACRITIC_VARIANTS_LETTERS.d.ts +12 -0
- package/esm/typings/src/utils/normalization/IKeywords.d.ts +21 -0
- package/esm/typings/src/utils/normalization/capitalize.d.ts +6 -0
- package/esm/typings/src/utils/normalization/capitalize.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/decapitalize.d.ts +6 -0
- package/esm/typings/src/utils/normalization/decapitalize.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/isValidKeyword.d.ts +10 -0
- package/esm/typings/src/utils/normalization/isValidKeyword.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/nameToUriPart.d.ts +9 -0
- package/esm/typings/src/utils/normalization/nameToUriPart.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/nameToUriParts.d.ts +9 -0
- package/esm/typings/src/utils/normalization/nameToUriParts.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +21 -0
- package/esm/typings/src/utils/normalization/normalize-to-kebab-case.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +17 -0
- package/esm/typings/src/utils/normalization/normalizeTo_PascalCase.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +26 -0
- package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +22 -0
- package/esm/typings/src/utils/normalization/normalizeTo_camelCase.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +17 -0
- package/esm/typings/src/utils/normalization/normalizeTo_snake_case.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/normalizeWhitespaces.d.ts +6 -0
- package/esm/typings/src/utils/normalization/normalizeWhitespaces.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/orderJson.d.ts +21 -0
- package/esm/typings/src/utils/normalization/orderJson.test.d.ts +4 -0
- package/esm/typings/src/utils/normalization/parseKeywords.d.ts +16 -0
- package/esm/typings/src/utils/normalization/parseKeywords.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/parseKeywordsFromString.d.ts +9 -0
- package/esm/typings/src/utils/normalization/parseKeywordsFromString.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +11 -0
- package/esm/typings/src/utils/normalization/removeDiacritics.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/searchKeywords.d.ts +10 -0
- package/esm/typings/src/utils/normalization/searchKeywords.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/suffixUrl.d.ts +7 -0
- package/esm/typings/src/utils/normalization/suffixUrl.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/titleToName.d.ts +9 -0
- package/esm/typings/src/utils/normalization/titleToName.test.d.ts +1 -0
- package/esm/typings/src/utils/organization/$sideEffect.d.ts +9 -0
- package/esm/typings/src/utils/organization/TODO_USE.d.ts +12 -0
- package/esm/typings/src/utils/organization/TODO_any.d.ts +6 -0
- package/esm/typings/src/utils/organization/TODO_object.d.ts +6 -0
- package/esm/typings/src/utils/organization/TODO_remove_as.d.ts +6 -0
- package/esm/typings/src/utils/organization/TODO_string.d.ts +6 -0
- package/esm/typings/src/utils/organization/TODO_unknown.d.ts +6 -0
- package/esm/typings/src/utils/organization/___and___.d.ts +7 -0
- package/esm/typings/src/utils/organization/___or___.d.ts +6 -0
- package/esm/typings/src/utils/organization/empty_object.d.ts +10 -0
- package/esm/typings/src/utils/organization/just.d.ts +14 -0
- package/esm/typings/src/utils/organization/just_empty_object.d.ts +12 -0
- package/esm/typings/src/utils/organization/keepTypeImported.d.ts +9 -0
- package/esm/typings/src/utils/organization/keepUnused.d.ts +16 -0
- package/esm/typings/src/utils/organization/really_any.d.ts +6 -0
- package/esm/typings/src/utils/organization/really_unknown.d.ts +6 -0
- package/esm/typings/src/utils/organization/spaceTrim.d.ts +11 -0
- package/esm/typings/src/utils/parameters/extractParameterNames.d.ts +10 -0
- package/esm/typings/src/utils/parameters/extractParameterNames.test.d.ts +1 -0
- package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +27 -0
- package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.test.d.ts +1 -0
- package/esm/typings/src/utils/parameters/numberToString.d.ts +7 -0
- package/esm/typings/src/utils/parameters/numberToString.test.d.ts +1 -0
- package/esm/typings/src/utils/parameters/templateParameters.d.ts +16 -0
- package/esm/typings/src/utils/parameters/templateParameters.test.d.ts +1 -0
- package/esm/typings/src/utils/parameters/valueToString.d.ts +17 -0
- package/esm/typings/src/utils/parameters/valueToString.test.d.ts +1 -0
- package/esm/typings/src/utils/parseNumber.d.ts +16 -0
- package/esm/typings/src/utils/parseNumber.test.d.ts +1 -0
- package/esm/typings/src/utils/random/$randomSeed.d.ts +10 -0
- package/esm/typings/src/utils/random/$randomToken.d.ts +13 -0
- package/esm/typings/src/utils/removeEmojis.d.ts +8 -0
- package/esm/typings/src/utils/removeEmojis.test.d.ts +1 -0
- package/esm/typings/src/utils/removeQuotes.d.ts +14 -0
- package/esm/typings/src/utils/removeQuotes.test.d.ts +1 -0
- package/esm/typings/src/utils/serialization/$deepFreeze.d.ts +14 -0
- package/esm/typings/src/utils/serialization/asSerializable.d.ts +15 -0
- package/esm/typings/src/utils/serialization/asSerializable.test.d.ts +1 -0
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +45 -0
- package/esm/typings/src/utils/serialization/clonePipeline.d.ts +13 -0
- package/esm/typings/src/utils/serialization/deepClone.d.ts +10 -0
- package/esm/typings/src/utils/serialization/deepClone.test.d.ts +1 -0
- package/esm/typings/src/utils/serialization/exportJson.d.ts +29 -0
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +25 -0
- package/esm/typings/src/utils/serialization/isSerializableAsJson.test.d.ts +1 -0
- package/esm/typings/src/utils/sets/difference.d.ts +10 -0
- package/esm/typings/src/utils/sets/difference.test.d.ts +1 -0
- package/esm/typings/src/utils/sets/intersection.d.ts +7 -0
- package/esm/typings/src/utils/sets/intersection.test.d.ts +1 -0
- package/esm/typings/src/utils/sets/union.d.ts +7 -0
- package/esm/typings/src/utils/sets/union.test.d.ts +1 -0
- package/esm/typings/src/utils/trimCodeBlock.d.ts +9 -0
- package/esm/typings/src/utils/trimCodeBlock.test.d.ts +1 -0
- package/esm/typings/src/utils/trimEndOfCodeBlock.d.ts +9 -0
- package/esm/typings/src/utils/trimEndOfCodeBlock.test.d.ts +1 -0
- package/esm/typings/src/utils/unwrapResult.d.ts +37 -0
- package/esm/typings/src/utils/unwrapResult.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/email/isValidEmail.d.ts +8 -0
- package/esm/typings/src/utils/validators/email/isValidEmail.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/filePath/isRootPath.d.ts +12 -0
- package/esm/typings/src/utils/validators/filePath/isRootPath.test.d.ts +4 -0
- package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +12 -0
- package/esm/typings/src/utils/validators/filePath/isValidFilePath.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +10 -0
- package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +10 -0
- package/esm/typings/src/utils/validators/parameterName/validateParameterName.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +15 -0
- package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +12 -0
- package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.d.ts +11 -0
- package/esm/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/url/isUrlOnPrivateNetwork.d.ts +13 -0
- package/esm/typings/src/utils/validators/url/isUrlOnPrivateNetwork.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +15 -0
- package/esm/typings/src/utils/validators/url/isValidPipelineUrl.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +13 -0
- package/esm/typings/src/utils/validators/url/isValidUrl.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/uuid/isValidUuid.d.ts +8 -0
- package/esm/typings/src/utils/validators/uuid/isValidUuid.test.d.ts +1 -0
- package/esm/typings/src/version.d.ts +25 -0
- package/esm/typings/src/wizzard/$getCompiledBook.d.ts +16 -0
- package/esm/typings/src/wizzard/wizzard.d.ts +68 -0
- package/package.json +57 -0
- package/umd/index.umd.js +1810 -0
- package/umd/index.umd.js.map +1 -0
package/umd/index.umd.js
ADDED
|
@@ -0,0 +1,1810 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('path'), require('prettier'), require('prettier/parser-html'), require('waitasecond')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'path', 'prettier', 'prettier/parser-html', 'waitasecond'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-javascript"] = {}, global.spaceTrim, null, global.prettier, global.parserHtml, global.waitasecond));
|
|
5
|
+
})(this, (function (exports, spaceTrim, path, prettier, parserHtml, waitasecond) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
|
|
10
|
+
var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
|
|
11
|
+
|
|
12
|
+
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
13
|
+
/**
|
|
14
|
+
* The version of the Book language
|
|
15
|
+
*
|
|
16
|
+
* @generated
|
|
17
|
+
* @see https://github.com/webgptorg/book
|
|
18
|
+
*/
|
|
19
|
+
const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
20
|
+
/**
|
|
21
|
+
* The version of the Promptbook engine
|
|
22
|
+
*
|
|
23
|
+
* @generated
|
|
24
|
+
* @see https://github.com/webgptorg/promptbook
|
|
25
|
+
*/
|
|
26
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.88.0-1';
|
|
27
|
+
/**
|
|
28
|
+
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
29
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Name for the Promptbook
|
|
34
|
+
*
|
|
35
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
36
|
+
*
|
|
37
|
+
* @public exported from `@promptbook/core`
|
|
38
|
+
*/
|
|
39
|
+
const NAME = `Promptbook`;
|
|
40
|
+
/**
|
|
41
|
+
* Email of the responsible person
|
|
42
|
+
*
|
|
43
|
+
* @public exported from `@promptbook/core`
|
|
44
|
+
*/
|
|
45
|
+
const ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
46
|
+
/**
|
|
47
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
48
|
+
*
|
|
49
|
+
* @public exported from `@promptbook/core`
|
|
50
|
+
*/
|
|
51
|
+
const ADMIN_GITHUB_NAME = 'hejny';
|
|
52
|
+
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
53
|
+
/**
|
|
54
|
+
* The maximum number of iterations for a loops
|
|
55
|
+
*
|
|
56
|
+
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
57
|
+
*/
|
|
58
|
+
const LOOP_LIMIT = 1000;
|
|
59
|
+
/**
|
|
60
|
+
* Strings to represent various values in the context of parameter values
|
|
61
|
+
*
|
|
62
|
+
* @public exported from `@promptbook/utils`
|
|
63
|
+
*/
|
|
64
|
+
const VALUE_STRINGS = {
|
|
65
|
+
empty: '(nothing; empty string)',
|
|
66
|
+
null: '(no value; null)',
|
|
67
|
+
undefined: '(unknown value; undefined)',
|
|
68
|
+
nan: '(not a number; NaN)',
|
|
69
|
+
infinity: '(infinity; ∞)',
|
|
70
|
+
negativeInfinity: '(negative infinity; -∞)',
|
|
71
|
+
unserializable: '(unserializable value)',
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Small number limit
|
|
75
|
+
*
|
|
76
|
+
* @public exported from `@promptbook/utils`
|
|
77
|
+
*/
|
|
78
|
+
const SMALL_NUMBER = 0.001;
|
|
79
|
+
// <- TODO: [🧜♂️]
|
|
80
|
+
/**
|
|
81
|
+
* @@@
|
|
82
|
+
*
|
|
83
|
+
* @public exported from `@promptbook/core`
|
|
84
|
+
*/
|
|
85
|
+
Object.freeze({
|
|
86
|
+
delimiter: ',',
|
|
87
|
+
quoteChar: '"',
|
|
88
|
+
newline: '\n',
|
|
89
|
+
skipEmptyLines: true,
|
|
90
|
+
});
|
|
91
|
+
/**
|
|
92
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
93
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Make error report URL for the given error
|
|
98
|
+
*
|
|
99
|
+
* @private private within the repository
|
|
100
|
+
*/
|
|
101
|
+
function getErrorReportUrl(error) {
|
|
102
|
+
const report = {
|
|
103
|
+
title: `🐜 Error report from ${NAME}`,
|
|
104
|
+
body: spaceTrim__default["default"]((block) => `
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
108
|
+
|
|
109
|
+
\`\`\`
|
|
110
|
+
${block(error.message || '(no error message)')}
|
|
111
|
+
\`\`\`
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
## More info:
|
|
115
|
+
|
|
116
|
+
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
117
|
+
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
118
|
+
- **Time:** ${new Date().toISOString()}
|
|
119
|
+
|
|
120
|
+
<details>
|
|
121
|
+
<summary>Stack trace:</summary>
|
|
122
|
+
|
|
123
|
+
## Stack trace:
|
|
124
|
+
|
|
125
|
+
\`\`\`stacktrace
|
|
126
|
+
${block(error.stack || '(empty)')}
|
|
127
|
+
\`\`\`
|
|
128
|
+
</details>
|
|
129
|
+
|
|
130
|
+
`),
|
|
131
|
+
};
|
|
132
|
+
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
133
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
134
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
135
|
+
reportUrl.searchParams.set('title', report.title);
|
|
136
|
+
reportUrl.searchParams.set('body', report.body);
|
|
137
|
+
return reportUrl;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
142
|
+
*
|
|
143
|
+
* @public exported from `@promptbook/core`
|
|
144
|
+
*/
|
|
145
|
+
class UnexpectedError extends Error {
|
|
146
|
+
constructor(message) {
|
|
147
|
+
super(spaceTrim.spaceTrim((block) => `
|
|
148
|
+
${block(message)}
|
|
149
|
+
|
|
150
|
+
Note: This error should not happen.
|
|
151
|
+
It's probbably a bug in the pipeline collection
|
|
152
|
+
|
|
153
|
+
Please report issue:
|
|
154
|
+
${block(getErrorReportUrl(new Error(message)).href)}
|
|
155
|
+
|
|
156
|
+
Or contact us on ${ADMIN_EMAIL}
|
|
157
|
+
|
|
158
|
+
`));
|
|
159
|
+
this.name = 'UnexpectedError';
|
|
160
|
+
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @@@
|
|
166
|
+
*
|
|
167
|
+
* @param text @@@
|
|
168
|
+
* @param _isFirstLetterCapital @@@
|
|
169
|
+
* @returns @@@
|
|
170
|
+
* @example 'helloWorld'
|
|
171
|
+
* @example 'iLovePromptbook'
|
|
172
|
+
* @public exported from `@promptbook/utils`
|
|
173
|
+
*/
|
|
174
|
+
function normalizeTo_camelCase(text, _isFirstLetterCapital = false) {
|
|
175
|
+
let charType;
|
|
176
|
+
let lastCharType = null;
|
|
177
|
+
let normalizedName = '';
|
|
178
|
+
for (const char of text) {
|
|
179
|
+
let normalizedChar;
|
|
180
|
+
if (/^[a-z]$/.test(char)) {
|
|
181
|
+
charType = 'LOWERCASE';
|
|
182
|
+
normalizedChar = char;
|
|
183
|
+
}
|
|
184
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
185
|
+
charType = 'UPPERCASE';
|
|
186
|
+
normalizedChar = char.toLowerCase();
|
|
187
|
+
}
|
|
188
|
+
else if (/^[0-9]$/.test(char)) {
|
|
189
|
+
charType = 'NUMBER';
|
|
190
|
+
normalizedChar = char;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
charType = 'OTHER';
|
|
194
|
+
normalizedChar = '';
|
|
195
|
+
}
|
|
196
|
+
if (!lastCharType) {
|
|
197
|
+
if (_isFirstLetterCapital) {
|
|
198
|
+
normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
else if (charType !== lastCharType &&
|
|
202
|
+
!(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
|
|
203
|
+
!(lastCharType === 'NUMBER') &&
|
|
204
|
+
!(charType === 'NUMBER')) {
|
|
205
|
+
normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
|
|
206
|
+
}
|
|
207
|
+
normalizedName += normalizedChar;
|
|
208
|
+
lastCharType = charType;
|
|
209
|
+
}
|
|
210
|
+
return normalizedName;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* TODO: [🌺] Use some intermediate util splitWords
|
|
214
|
+
*/
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Removes emojis from a string and fix whitespaces
|
|
218
|
+
*
|
|
219
|
+
* @param text with emojis
|
|
220
|
+
* @returns text without emojis
|
|
221
|
+
* @public exported from `@promptbook/utils`
|
|
222
|
+
*/
|
|
223
|
+
function removeEmojis(text) {
|
|
224
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
225
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
226
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
227
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
228
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
229
|
+
return text;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const defaultDiacriticsRemovalMap = [
|
|
233
|
+
{
|
|
234
|
+
base: 'A',
|
|
235
|
+
letters: '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F',
|
|
236
|
+
},
|
|
237
|
+
{ base: 'AA', letters: '\uA732' },
|
|
238
|
+
{ base: 'AE', letters: '\u00C6\u01FC\u01E2' },
|
|
239
|
+
{ base: 'AO', letters: '\uA734' },
|
|
240
|
+
{ base: 'AU', letters: '\uA736' },
|
|
241
|
+
{ base: 'AV', letters: '\uA738\uA73A' },
|
|
242
|
+
{ base: 'AY', letters: '\uA73C' },
|
|
243
|
+
{
|
|
244
|
+
base: 'B',
|
|
245
|
+
letters: '\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181',
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
base: 'C',
|
|
249
|
+
letters: '\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E',
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
base: 'D',
|
|
253
|
+
letters: '\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779\u00D0',
|
|
254
|
+
},
|
|
255
|
+
{ base: 'DZ', letters: '\u01F1\u01C4' },
|
|
256
|
+
{ base: 'Dz', letters: '\u01F2\u01C5' },
|
|
257
|
+
{
|
|
258
|
+
base: 'E',
|
|
259
|
+
letters: '\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E',
|
|
260
|
+
},
|
|
261
|
+
{ base: 'F', letters: '\u0046\u24BB\uFF26\u1E1E\u0191\uA77B' },
|
|
262
|
+
{
|
|
263
|
+
base: 'G',
|
|
264
|
+
letters: '\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E',
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
base: 'H',
|
|
268
|
+
letters: '\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D',
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
base: 'I',
|
|
272
|
+
letters: '\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197',
|
|
273
|
+
},
|
|
274
|
+
{ base: 'J', letters: '\u004A\u24BF\uFF2A\u0134\u0248' },
|
|
275
|
+
{
|
|
276
|
+
base: 'K',
|
|
277
|
+
letters: '\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2',
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
base: 'L',
|
|
281
|
+
letters: '\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780',
|
|
282
|
+
},
|
|
283
|
+
{ base: 'LJ', letters: '\u01C7' },
|
|
284
|
+
{ base: 'Lj', letters: '\u01C8' },
|
|
285
|
+
{ base: 'M', letters: '\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C' },
|
|
286
|
+
{
|
|
287
|
+
base: 'N',
|
|
288
|
+
letters: '\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4',
|
|
289
|
+
},
|
|
290
|
+
{ base: 'NJ', letters: '\u01CA' },
|
|
291
|
+
{ base: 'Nj', letters: '\u01CB' },
|
|
292
|
+
{
|
|
293
|
+
base: 'O',
|
|
294
|
+
letters: '\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C',
|
|
295
|
+
},
|
|
296
|
+
{ base: 'OI', letters: '\u01A2' },
|
|
297
|
+
{ base: 'OO', letters: '\uA74E' },
|
|
298
|
+
{ base: 'OU', letters: '\u0222' },
|
|
299
|
+
{ base: 'OE', letters: '\u008C\u0152' },
|
|
300
|
+
{ base: 'oe', letters: '\u009C\u0153' },
|
|
301
|
+
{
|
|
302
|
+
base: 'P',
|
|
303
|
+
letters: '\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754',
|
|
304
|
+
},
|
|
305
|
+
{ base: 'Q', letters: '\u0051\u24C6\uFF31\uA756\uA758\u024A' },
|
|
306
|
+
{
|
|
307
|
+
base: 'R',
|
|
308
|
+
letters: '\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782',
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
base: 'S',
|
|
312
|
+
letters: '\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784',
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
base: 'T',
|
|
316
|
+
letters: '\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786',
|
|
317
|
+
},
|
|
318
|
+
{ base: 'TZ', letters: '\uA728' },
|
|
319
|
+
{
|
|
320
|
+
base: 'U',
|
|
321
|
+
letters: '\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244',
|
|
322
|
+
},
|
|
323
|
+
{ base: 'V', letters: '\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245' },
|
|
324
|
+
{ base: 'VY', letters: '\uA760' },
|
|
325
|
+
{
|
|
326
|
+
base: 'W',
|
|
327
|
+
letters: '\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72',
|
|
328
|
+
},
|
|
329
|
+
{ base: 'X', letters: '\u0058\u24CD\uFF38\u1E8A\u1E8C' },
|
|
330
|
+
{
|
|
331
|
+
base: 'Y',
|
|
332
|
+
letters: '\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE',
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
base: 'Z',
|
|
336
|
+
letters: '\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762',
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
base: 'a',
|
|
340
|
+
letters: '\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250',
|
|
341
|
+
},
|
|
342
|
+
{ base: 'aa', letters: '\uA733' },
|
|
343
|
+
{ base: 'ae', letters: '\u00E6\u01FD\u01E3' },
|
|
344
|
+
{ base: 'ao', letters: '\uA735' },
|
|
345
|
+
{ base: 'au', letters: '\uA737' },
|
|
346
|
+
{ base: 'av', letters: '\uA739\uA73B' },
|
|
347
|
+
{ base: 'ay', letters: '\uA73D' },
|
|
348
|
+
{
|
|
349
|
+
base: 'b',
|
|
350
|
+
letters: '\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253',
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
base: 'c',
|
|
354
|
+
letters: '\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184',
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
base: 'd',
|
|
358
|
+
letters: '\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A',
|
|
359
|
+
},
|
|
360
|
+
{ base: 'dz', letters: '\u01F3\u01C6' },
|
|
361
|
+
{
|
|
362
|
+
base: 'e',
|
|
363
|
+
letters: '\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD',
|
|
364
|
+
},
|
|
365
|
+
{ base: 'f', letters: '\u0066\u24D5\uFF46\u1E1F\u0192\uA77C' },
|
|
366
|
+
{
|
|
367
|
+
base: 'g',
|
|
368
|
+
letters: '\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F',
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
base: 'h',
|
|
372
|
+
letters: '\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265',
|
|
373
|
+
},
|
|
374
|
+
{ base: 'hv', letters: '\u0195' },
|
|
375
|
+
{
|
|
376
|
+
base: 'i',
|
|
377
|
+
letters: '\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131',
|
|
378
|
+
},
|
|
379
|
+
{ base: 'j', letters: '\u006A\u24D9\uFF4A\u0135\u01F0\u0249' },
|
|
380
|
+
{
|
|
381
|
+
base: 'k',
|
|
382
|
+
letters: '\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3',
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
base: 'l',
|
|
386
|
+
letters: '\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747',
|
|
387
|
+
},
|
|
388
|
+
{ base: 'lj', letters: '\u01C9' },
|
|
389
|
+
{ base: 'm', letters: '\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F' },
|
|
390
|
+
{
|
|
391
|
+
base: 'n',
|
|
392
|
+
letters: '\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5',
|
|
393
|
+
},
|
|
394
|
+
{ base: 'nj', letters: '\u01CC' },
|
|
395
|
+
{
|
|
396
|
+
base: 'o',
|
|
397
|
+
letters: '\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275',
|
|
398
|
+
},
|
|
399
|
+
{ base: 'oi', letters: '\u01A3' },
|
|
400
|
+
{ base: 'ou', letters: '\u0223' },
|
|
401
|
+
{ base: 'oo', letters: '\uA74F' },
|
|
402
|
+
{
|
|
403
|
+
base: 'p',
|
|
404
|
+
letters: '\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755',
|
|
405
|
+
},
|
|
406
|
+
{ base: 'q', letters: '\u0071\u24E0\uFF51\u024B\uA757\uA759' },
|
|
407
|
+
{
|
|
408
|
+
base: 'r',
|
|
409
|
+
letters: '\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783',
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
base: 's',
|
|
413
|
+
letters: '\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B',
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
base: 't',
|
|
417
|
+
letters: '\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787',
|
|
418
|
+
},
|
|
419
|
+
{ base: 'tz', letters: '\uA729' },
|
|
420
|
+
{
|
|
421
|
+
base: 'u',
|
|
422
|
+
letters: '\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289',
|
|
423
|
+
},
|
|
424
|
+
{ base: 'v', letters: '\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C' },
|
|
425
|
+
{ base: 'vy', letters: '\uA761' },
|
|
426
|
+
{
|
|
427
|
+
base: 'w',
|
|
428
|
+
letters: '\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73',
|
|
429
|
+
},
|
|
430
|
+
{ base: 'x', letters: '\u0078\u24E7\uFF58\u1E8B\u1E8D' },
|
|
431
|
+
{
|
|
432
|
+
base: 'y',
|
|
433
|
+
letters: '\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF',
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
base: 'z',
|
|
437
|
+
letters: '\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763',
|
|
438
|
+
},
|
|
439
|
+
];
|
|
440
|
+
/**
|
|
441
|
+
* Map of letters from diacritic variant to diacritless variant
|
|
442
|
+
* Contains lowercase and uppercase separatelly
|
|
443
|
+
*
|
|
444
|
+
* > "á" => "a"
|
|
445
|
+
* > "ě" => "e"
|
|
446
|
+
* > "Ă" => "A"
|
|
447
|
+
* > ...
|
|
448
|
+
*
|
|
449
|
+
* @public exported from `@promptbook/utils`
|
|
450
|
+
*/
|
|
451
|
+
const DIACRITIC_VARIANTS_LETTERS = {};
|
|
452
|
+
// tslint:disable-next-line: prefer-for-of
|
|
453
|
+
for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
|
|
454
|
+
const letters = defaultDiacriticsRemovalMap[i].letters;
|
|
455
|
+
// tslint:disable-next-line: prefer-for-of
|
|
456
|
+
for (let j = 0; j < letters.length; j++) {
|
|
457
|
+
DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
// <- TODO: [🍓] Put to maker function to save execution time if not needed
|
|
461
|
+
/*
|
|
462
|
+
@see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
|
|
463
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
464
|
+
you may not use this file except in compliance with the License.
|
|
465
|
+
You may obtain a copy of the License at
|
|
466
|
+
|
|
467
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
468
|
+
|
|
469
|
+
Unless required by applicable law or agreed to in writing, software
|
|
470
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
471
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
472
|
+
See the License for the specific language governing permissions and
|
|
473
|
+
limitations under the License.
|
|
474
|
+
*/
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* @@@
|
|
478
|
+
*
|
|
479
|
+
* @param input @@@
|
|
480
|
+
* @returns @@@
|
|
481
|
+
* @public exported from `@promptbook/utils`
|
|
482
|
+
*/
|
|
483
|
+
function removeDiacritics(input) {
|
|
484
|
+
/*eslint no-control-regex: "off"*/
|
|
485
|
+
return input.replace(/[^\u0000-\u007E]/g, (a) => {
|
|
486
|
+
return DIACRITIC_VARIANTS_LETTERS[a] || a;
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* TODO: [Ж] Variant for cyrillic (and in general non-latin) letters
|
|
491
|
+
*/
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* @@@
|
|
495
|
+
*
|
|
496
|
+
* @param text @@@
|
|
497
|
+
* @returns @@@
|
|
498
|
+
* @example 'hello-world'
|
|
499
|
+
* @example 'i-love-promptbook'
|
|
500
|
+
* @public exported from `@promptbook/utils`
|
|
501
|
+
*/
|
|
502
|
+
function normalizeToKebabCase(text) {
|
|
503
|
+
text = removeDiacritics(text);
|
|
504
|
+
let charType;
|
|
505
|
+
let lastCharType = 'OTHER';
|
|
506
|
+
let normalizedName = '';
|
|
507
|
+
for (const char of text) {
|
|
508
|
+
let normalizedChar;
|
|
509
|
+
if (/^[a-z]$/.test(char)) {
|
|
510
|
+
charType = 'LOWERCASE';
|
|
511
|
+
normalizedChar = char;
|
|
512
|
+
}
|
|
513
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
514
|
+
charType = 'UPPERCASE';
|
|
515
|
+
normalizedChar = char.toLowerCase();
|
|
516
|
+
}
|
|
517
|
+
else if (/^[0-9]$/.test(char)) {
|
|
518
|
+
charType = 'NUMBER';
|
|
519
|
+
normalizedChar = char;
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
charType = 'OTHER';
|
|
523
|
+
normalizedChar = '-';
|
|
524
|
+
}
|
|
525
|
+
if (charType !== lastCharType &&
|
|
526
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
527
|
+
!(lastCharType === 'NUMBER') &&
|
|
528
|
+
!(charType === 'NUMBER')) {
|
|
529
|
+
normalizedName += '-';
|
|
530
|
+
}
|
|
531
|
+
normalizedName += normalizedChar;
|
|
532
|
+
lastCharType = charType;
|
|
533
|
+
}
|
|
534
|
+
normalizedName = normalizedName.split(/-+/g).join('-');
|
|
535
|
+
normalizedName = normalizedName.split(/-?\/-?/g).join('/');
|
|
536
|
+
normalizedName = normalizedName.replace(/^-/, '');
|
|
537
|
+
normalizedName = normalizedName.replace(/-$/, '');
|
|
538
|
+
return normalizedName;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
542
|
+
*/
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
546
|
+
*
|
|
547
|
+
* @public exported from `@promptbook/core`
|
|
548
|
+
*/
|
|
549
|
+
class ParseError extends Error {
|
|
550
|
+
constructor(message) {
|
|
551
|
+
super(message);
|
|
552
|
+
this.name = 'ParseError';
|
|
553
|
+
Object.setPrototypeOf(this, ParseError.prototype);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
558
|
+
*/
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* This error indicates errors during the execution of the pipeline
|
|
562
|
+
*
|
|
563
|
+
* @public exported from `@promptbook/core`
|
|
564
|
+
*/
|
|
565
|
+
class PipelineExecutionError extends Error {
|
|
566
|
+
constructor(message) {
|
|
567
|
+
super(message);
|
|
568
|
+
this.name = 'PipelineExecutionError';
|
|
569
|
+
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Index of all javascript errors
|
|
575
|
+
*
|
|
576
|
+
* @private for internal usage
|
|
577
|
+
*/
|
|
578
|
+
({
|
|
579
|
+
Error,
|
|
580
|
+
EvalError,
|
|
581
|
+
RangeError,
|
|
582
|
+
ReferenceError,
|
|
583
|
+
SyntaxError,
|
|
584
|
+
TypeError,
|
|
585
|
+
URIError,
|
|
586
|
+
AggregateError,
|
|
587
|
+
/*
|
|
588
|
+
Note: Not widely supported
|
|
589
|
+
> InternalError,
|
|
590
|
+
> ModuleError,
|
|
591
|
+
> HeapError,
|
|
592
|
+
> WebAssemblyCompileError,
|
|
593
|
+
> WebAssemblyRuntimeError,
|
|
594
|
+
*/
|
|
595
|
+
});
|
|
596
|
+
/**
|
|
597
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
598
|
+
*/
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Orders JSON object by keys
|
|
602
|
+
*
|
|
603
|
+
* @returns The same type of object as the input re-ordered
|
|
604
|
+
* @public exported from `@promptbook/utils`
|
|
605
|
+
*/
|
|
606
|
+
function orderJson(options) {
|
|
607
|
+
const { value, order } = options;
|
|
608
|
+
const orderedValue = {
|
|
609
|
+
...(order === undefined ? {} : Object.fromEntries(order.map((key) => [key, undefined]))),
|
|
610
|
+
...value,
|
|
611
|
+
};
|
|
612
|
+
return orderedValue;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Freezes the given object and all its nested objects recursively
|
|
617
|
+
*
|
|
618
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
619
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
620
|
+
*
|
|
621
|
+
* @returns The same object as the input, but deeply frozen
|
|
622
|
+
* @public exported from `@promptbook/utils`
|
|
623
|
+
*/
|
|
624
|
+
function $deepFreeze(objectValue) {
|
|
625
|
+
if (Array.isArray(objectValue)) {
|
|
626
|
+
return Object.freeze(objectValue.map((item) => $deepFreeze(item)));
|
|
627
|
+
}
|
|
628
|
+
const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
629
|
+
for (const propertyName of propertyNames) {
|
|
630
|
+
const value = objectValue[propertyName];
|
|
631
|
+
if (value && typeof value === 'object') {
|
|
632
|
+
$deepFreeze(value);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
Object.freeze(objectValue);
|
|
636
|
+
return objectValue;
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
640
|
+
*/
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
644
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
645
|
+
*
|
|
646
|
+
* - Almost all primitives are serializable BUT:
|
|
647
|
+
* - `undefined` is not serializable
|
|
648
|
+
* - `NaN` is not serializable
|
|
649
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
650
|
+
* - Functions are not serializable
|
|
651
|
+
* - Circular references are not serializable
|
|
652
|
+
* - `Date` objects are not serializable
|
|
653
|
+
* - `Map` and `Set` objects are not serializable
|
|
654
|
+
* - `RegExp` objects are not serializable
|
|
655
|
+
* - `Error` objects are not serializable
|
|
656
|
+
* - `Symbol` objects are not serializable
|
|
657
|
+
* - And much more...
|
|
658
|
+
*
|
|
659
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
660
|
+
* @public exported from `@promptbook/utils`
|
|
661
|
+
*/
|
|
662
|
+
function checkSerializableAsJson(options) {
|
|
663
|
+
const { value, name, message } = options;
|
|
664
|
+
if (value === undefined) {
|
|
665
|
+
throw new UnexpectedError(`${name} is undefined`);
|
|
666
|
+
}
|
|
667
|
+
else if (value === null) {
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
else if (typeof value === 'boolean') {
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
else if (typeof value === 'string') {
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
else if (typeof value === 'symbol') {
|
|
680
|
+
throw new UnexpectedError(`${name} is symbol`);
|
|
681
|
+
}
|
|
682
|
+
else if (typeof value === 'function') {
|
|
683
|
+
throw new UnexpectedError(`${name} is function`);
|
|
684
|
+
}
|
|
685
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
686
|
+
for (let i = 0; i < value.length; i++) {
|
|
687
|
+
checkSerializableAsJson({ name: `${name}[${i}]`, value: value[i], message });
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
else if (typeof value === 'object') {
|
|
691
|
+
if (value instanceof Date) {
|
|
692
|
+
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
693
|
+
\`${name}\` is Date
|
|
694
|
+
|
|
695
|
+
Use \`string_date_iso8601\` instead
|
|
696
|
+
|
|
697
|
+
Additional message for \`${name}\`:
|
|
698
|
+
${block(message || '(nothing)')}
|
|
699
|
+
`));
|
|
700
|
+
}
|
|
701
|
+
else if (value instanceof Map) {
|
|
702
|
+
throw new UnexpectedError(`${name} is Map`);
|
|
703
|
+
}
|
|
704
|
+
else if (value instanceof Set) {
|
|
705
|
+
throw new UnexpectedError(`${name} is Set`);
|
|
706
|
+
}
|
|
707
|
+
else if (value instanceof RegExp) {
|
|
708
|
+
throw new UnexpectedError(`${name} is RegExp`);
|
|
709
|
+
}
|
|
710
|
+
else if (value instanceof Error) {
|
|
711
|
+
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
712
|
+
\`${name}\` is unserialized Error
|
|
713
|
+
|
|
714
|
+
Use function \`serializeError\`
|
|
715
|
+
|
|
716
|
+
Additional message for \`${name}\`:
|
|
717
|
+
${block(message || '(nothing)')}
|
|
718
|
+
|
|
719
|
+
`));
|
|
720
|
+
}
|
|
721
|
+
else {
|
|
722
|
+
for (const [subName, subValue] of Object.entries(value)) {
|
|
723
|
+
if (subValue === undefined) {
|
|
724
|
+
// Note: undefined in object is serializable - it is just omited
|
|
725
|
+
continue;
|
|
726
|
+
}
|
|
727
|
+
checkSerializableAsJson({ name: `${name}.${subName}`, value: subValue, message });
|
|
728
|
+
}
|
|
729
|
+
try {
|
|
730
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
731
|
+
}
|
|
732
|
+
catch (error) {
|
|
733
|
+
if (!(error instanceof Error)) {
|
|
734
|
+
throw error;
|
|
735
|
+
}
|
|
736
|
+
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
737
|
+
\`${name}\` is not serializable
|
|
738
|
+
|
|
739
|
+
${block(error.stack || error.message)}
|
|
740
|
+
|
|
741
|
+
Additional message for \`${name}\`:
|
|
742
|
+
${block(message || '(nothing)')}
|
|
743
|
+
`));
|
|
744
|
+
}
|
|
745
|
+
/*
|
|
746
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
747
|
+
const seen = new Set();
|
|
748
|
+
const stack = [{ value }];
|
|
749
|
+
while (stack.length > 0) {
|
|
750
|
+
const { value } = stack.pop()!;
|
|
751
|
+
if (typeof value === 'object' && value !== null) {
|
|
752
|
+
if (seen.has(value)) {
|
|
753
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
754
|
+
}
|
|
755
|
+
seen.add(value);
|
|
756
|
+
if (Array.isArray(value)) {
|
|
757
|
+
stack.push(...value.map((value) => ({ value })));
|
|
758
|
+
} else {
|
|
759
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
*/
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
else {
|
|
768
|
+
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
769
|
+
\`${name}\` is unknown type
|
|
770
|
+
|
|
771
|
+
Additional message for \`${name}\`:
|
|
772
|
+
${block(message || '(nothing)')}
|
|
773
|
+
`));
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
778
|
+
* TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
|
|
779
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
780
|
+
*/
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* @@@
|
|
784
|
+
*
|
|
785
|
+
* @public exported from `@promptbook/utils`
|
|
786
|
+
*/
|
|
787
|
+
function deepClone(objectValue) {
|
|
788
|
+
return JSON.parse(JSON.stringify(objectValue));
|
|
789
|
+
/*
|
|
790
|
+
TODO: [🧠] Is there a better implementation?
|
|
791
|
+
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
792
|
+
> for (const propertyName of propertyNames) {
|
|
793
|
+
> const value = (objectValue as really_any)[propertyName];
|
|
794
|
+
> if (value && typeof value === 'object') {
|
|
795
|
+
> deepClone(value);
|
|
796
|
+
> }
|
|
797
|
+
> }
|
|
798
|
+
> return Object.assign({}, objectValue);
|
|
799
|
+
*/
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
803
|
+
*/
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* Utility to export a JSON object from a function
|
|
807
|
+
*
|
|
808
|
+
* 1) Checks if the value is serializable as JSON
|
|
809
|
+
* 2) Makes a deep clone of the object
|
|
810
|
+
* 2) Orders the object properties
|
|
811
|
+
* 2) Deeply freezes the cloned object
|
|
812
|
+
*
|
|
813
|
+
* Note: This function does not mutates the given object
|
|
814
|
+
*
|
|
815
|
+
* @returns The same type of object as the input but read-only and re-ordered
|
|
816
|
+
* @public exported from `@promptbook/utils`
|
|
817
|
+
*/
|
|
818
|
+
function exportJson(options) {
|
|
819
|
+
const { name, value, order, message } = options;
|
|
820
|
+
checkSerializableAsJson({ name, value, message });
|
|
821
|
+
const orderedValue =
|
|
822
|
+
// TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
|
|
823
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
824
|
+
// @ts-ignore
|
|
825
|
+
order === undefined
|
|
826
|
+
? deepClone(value)
|
|
827
|
+
: orderJson({
|
|
828
|
+
value: value,
|
|
829
|
+
// <- Note: checkSerializableAsJson asserts that the value is serializable as JSON
|
|
830
|
+
order: order,
|
|
831
|
+
});
|
|
832
|
+
$deepFreeze(orderedValue);
|
|
833
|
+
return orderedValue;
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
837
|
+
*/
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* The names of the parameters that are reserved for special purposes
|
|
841
|
+
*
|
|
842
|
+
* @public exported from `@promptbook/core`
|
|
843
|
+
*/
|
|
844
|
+
exportJson({
|
|
845
|
+
name: 'RESERVED_PARAMETER_NAMES',
|
|
846
|
+
message: `The names of the parameters that are reserved for special purposes`,
|
|
847
|
+
value: [
|
|
848
|
+
'content',
|
|
849
|
+
'context',
|
|
850
|
+
'knowledge',
|
|
851
|
+
'examples',
|
|
852
|
+
'modelName',
|
|
853
|
+
'currentDate',
|
|
854
|
+
// <- TODO: list here all command names
|
|
855
|
+
// <- TODO: Add more like 'date', 'modelName',...
|
|
856
|
+
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
857
|
+
],
|
|
858
|
+
});
|
|
859
|
+
/**
|
|
860
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
861
|
+
*/
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
* Format either small or big number
|
|
865
|
+
*
|
|
866
|
+
* @public exported from `@promptbook/utils`
|
|
867
|
+
*/
|
|
868
|
+
function numberToString(value) {
|
|
869
|
+
if (value === 0) {
|
|
870
|
+
return '0';
|
|
871
|
+
}
|
|
872
|
+
else if (Number.isNaN(value)) {
|
|
873
|
+
return VALUE_STRINGS.nan;
|
|
874
|
+
}
|
|
875
|
+
else if (value === Infinity) {
|
|
876
|
+
return VALUE_STRINGS.infinity;
|
|
877
|
+
}
|
|
878
|
+
else if (value === -Infinity) {
|
|
879
|
+
return VALUE_STRINGS.negativeInfinity;
|
|
880
|
+
}
|
|
881
|
+
for (let exponent = 0; exponent < 15; exponent++) {
|
|
882
|
+
const factor = 10 ** exponent;
|
|
883
|
+
const valueRounded = Math.round(value * factor) / factor;
|
|
884
|
+
if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
|
|
885
|
+
return valueRounded.toFixed(exponent);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
return value.toString();
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* Function `valueToString` will convert the given value to string
|
|
893
|
+
* This is useful and used in the `templateParameters` function
|
|
894
|
+
*
|
|
895
|
+
* Note: This function is not just calling `toString` method
|
|
896
|
+
* It's more complex and can handle this conversion specifically for LLM models
|
|
897
|
+
* See `VALUE_STRINGS`
|
|
898
|
+
*
|
|
899
|
+
* Note: There are 2 similar functions
|
|
900
|
+
* - `valueToString` converts value to string for LLM models as human-readable string
|
|
901
|
+
* - `asSerializable` converts value to string to preserve full information to be able to convert it back
|
|
902
|
+
*
|
|
903
|
+
* @public exported from `@promptbook/utils`
|
|
904
|
+
*/
|
|
905
|
+
function valueToString(value) {
|
|
906
|
+
try {
|
|
907
|
+
if (value === '') {
|
|
908
|
+
return VALUE_STRINGS.empty;
|
|
909
|
+
}
|
|
910
|
+
else if (value === null) {
|
|
911
|
+
return VALUE_STRINGS.null;
|
|
912
|
+
}
|
|
913
|
+
else if (value === undefined) {
|
|
914
|
+
return VALUE_STRINGS.undefined;
|
|
915
|
+
}
|
|
916
|
+
else if (typeof value === 'string') {
|
|
917
|
+
return value;
|
|
918
|
+
}
|
|
919
|
+
else if (typeof value === 'number') {
|
|
920
|
+
return numberToString(value);
|
|
921
|
+
}
|
|
922
|
+
else if (value instanceof Date) {
|
|
923
|
+
return value.toISOString();
|
|
924
|
+
}
|
|
925
|
+
else {
|
|
926
|
+
return JSON.stringify(value);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
catch (error) {
|
|
930
|
+
if (!(error instanceof Error)) {
|
|
931
|
+
throw error;
|
|
932
|
+
}
|
|
933
|
+
console.error(error);
|
|
934
|
+
return VALUE_STRINGS.unserializable;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
|
940
|
+
*
|
|
941
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
942
|
+
*
|
|
943
|
+
* @public exported from `@promptbook/utils`
|
|
944
|
+
*/
|
|
945
|
+
new Function(`
|
|
946
|
+
try {
|
|
947
|
+
return this === window;
|
|
948
|
+
} catch (e) {
|
|
949
|
+
return false;
|
|
950
|
+
}
|
|
951
|
+
`);
|
|
952
|
+
/**
|
|
953
|
+
* TODO: [🎺]
|
|
954
|
+
*/
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* Detects if the code is running in jest environment
|
|
958
|
+
*
|
|
959
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
960
|
+
*
|
|
961
|
+
* @public exported from `@promptbook/utils`
|
|
962
|
+
*/
|
|
963
|
+
new Function(`
|
|
964
|
+
try {
|
|
965
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
966
|
+
} catch (e) {
|
|
967
|
+
return false;
|
|
968
|
+
}
|
|
969
|
+
`);
|
|
970
|
+
/**
|
|
971
|
+
* TODO: [🎺]
|
|
972
|
+
*/
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* Detects if the code is running in a Node.js environment
|
|
976
|
+
*
|
|
977
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
978
|
+
*
|
|
979
|
+
* @public exported from `@promptbook/utils`
|
|
980
|
+
*/
|
|
981
|
+
new Function(`
|
|
982
|
+
try {
|
|
983
|
+
return this === global;
|
|
984
|
+
} catch (e) {
|
|
985
|
+
return false;
|
|
986
|
+
}
|
|
987
|
+
`);
|
|
988
|
+
/**
|
|
989
|
+
* TODO: [🎺]
|
|
990
|
+
*/
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Detects if the code is running in a web worker
|
|
994
|
+
*
|
|
995
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
996
|
+
*
|
|
997
|
+
* @public exported from `@promptbook/utils`
|
|
998
|
+
*/
|
|
999
|
+
new Function(`
|
|
1000
|
+
try {
|
|
1001
|
+
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
|
|
1002
|
+
return true;
|
|
1003
|
+
} else {
|
|
1004
|
+
return false;
|
|
1005
|
+
}
|
|
1006
|
+
} catch (e) {
|
|
1007
|
+
return false;
|
|
1008
|
+
}
|
|
1009
|
+
`);
|
|
1010
|
+
/**
|
|
1011
|
+
* TODO: [🎺]
|
|
1012
|
+
*/
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* Makes first letter of a string uppercase
|
|
1016
|
+
*
|
|
1017
|
+
* @public exported from `@promptbook/utils`
|
|
1018
|
+
*/
|
|
1019
|
+
function capitalize(word) {
|
|
1020
|
+
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
/**
|
|
1024
|
+
* Makes first letter of a string uppercase
|
|
1025
|
+
*
|
|
1026
|
+
* @public exported from `@promptbook/utils`
|
|
1027
|
+
*/
|
|
1028
|
+
function decapitalize(word) {
|
|
1029
|
+
return word.substring(0, 1).toLowerCase() + word.substring(1);
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* @@@
|
|
1034
|
+
*
|
|
1035
|
+
* @param text @@@
|
|
1036
|
+
* @returns @@@
|
|
1037
|
+
* @example 'HELLO_WORLD'
|
|
1038
|
+
* @example 'I_LOVE_PROMPTBOOK'
|
|
1039
|
+
* @public exported from `@promptbook/utils`
|
|
1040
|
+
*/
|
|
1041
|
+
function normalizeTo_SCREAMING_CASE(text) {
|
|
1042
|
+
let charType;
|
|
1043
|
+
let lastCharType = 'OTHER';
|
|
1044
|
+
let normalizedName = '';
|
|
1045
|
+
for (const char of text) {
|
|
1046
|
+
let normalizedChar;
|
|
1047
|
+
if (/^[a-z]$/.test(char)) {
|
|
1048
|
+
charType = 'LOWERCASE';
|
|
1049
|
+
normalizedChar = char.toUpperCase();
|
|
1050
|
+
}
|
|
1051
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
1052
|
+
charType = 'UPPERCASE';
|
|
1053
|
+
normalizedChar = char;
|
|
1054
|
+
}
|
|
1055
|
+
else if (/^[0-9]$/.test(char)) {
|
|
1056
|
+
charType = 'NUMBER';
|
|
1057
|
+
normalizedChar = char;
|
|
1058
|
+
}
|
|
1059
|
+
else {
|
|
1060
|
+
charType = 'OTHER';
|
|
1061
|
+
normalizedChar = '_';
|
|
1062
|
+
}
|
|
1063
|
+
if (charType !== lastCharType &&
|
|
1064
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
1065
|
+
!(lastCharType === 'NUMBER') &&
|
|
1066
|
+
!(charType === 'NUMBER')) {
|
|
1067
|
+
normalizedName += '_';
|
|
1068
|
+
}
|
|
1069
|
+
normalizedName += normalizedChar;
|
|
1070
|
+
lastCharType = charType;
|
|
1071
|
+
}
|
|
1072
|
+
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
1073
|
+
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
1074
|
+
normalizedName = normalizedName.replace(/^_/, '');
|
|
1075
|
+
normalizedName = normalizedName.replace(/_$/, '');
|
|
1076
|
+
return normalizedName;
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* TODO: Tests
|
|
1080
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
1081
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
1082
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
1083
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
1084
|
+
* TODO: [🌺] Use some intermediate util splitWords
|
|
1085
|
+
*/
|
|
1086
|
+
|
|
1087
|
+
/**
|
|
1088
|
+
* Parses keywords from a string
|
|
1089
|
+
*
|
|
1090
|
+
* @param {string} input
|
|
1091
|
+
* @returns {Set} of keywords without diacritics in lowercase
|
|
1092
|
+
* @public exported from `@promptbook/utils`
|
|
1093
|
+
*/
|
|
1094
|
+
function parseKeywordsFromString(input) {
|
|
1095
|
+
const keywords = normalizeTo_SCREAMING_CASE(removeDiacritics(input))
|
|
1096
|
+
.toLowerCase()
|
|
1097
|
+
.split(/[^a-z0-9]+/gs)
|
|
1098
|
+
.filter((value) => value);
|
|
1099
|
+
return new Set(keywords);
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
/**
|
|
1103
|
+
* @@@
|
|
1104
|
+
*
|
|
1105
|
+
* @param name @@@
|
|
1106
|
+
* @returns @@@
|
|
1107
|
+
* @example @@@
|
|
1108
|
+
* @public exported from `@promptbook/utils`
|
|
1109
|
+
*/
|
|
1110
|
+
function nameToUriPart(name) {
|
|
1111
|
+
let uriPart = name;
|
|
1112
|
+
uriPart = uriPart.toLowerCase();
|
|
1113
|
+
uriPart = removeDiacritics(uriPart);
|
|
1114
|
+
uriPart = uriPart.replace(/[^a-zA-Z0-9]+/g, '-');
|
|
1115
|
+
uriPart = uriPart.replace(/^-+/, '');
|
|
1116
|
+
uriPart = uriPart.replace(/-+$/, '');
|
|
1117
|
+
return uriPart;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
/**
|
|
1121
|
+
* @@@
|
|
1122
|
+
*
|
|
1123
|
+
* @param name @@@
|
|
1124
|
+
* @returns @@@
|
|
1125
|
+
* @example @@@
|
|
1126
|
+
* @public exported from `@promptbook/utils`
|
|
1127
|
+
*/
|
|
1128
|
+
function nameToUriParts(name) {
|
|
1129
|
+
return nameToUriPart(name)
|
|
1130
|
+
.split('-')
|
|
1131
|
+
.filter((value) => value !== '');
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
/**
|
|
1135
|
+
*
|
|
1136
|
+
* @param text @public exported from `@promptbook/utils`
|
|
1137
|
+
* @returns
|
|
1138
|
+
* @example 'HelloWorld'
|
|
1139
|
+
* @example 'ILovePromptbook'
|
|
1140
|
+
* @public exported from `@promptbook/utils`
|
|
1141
|
+
*/
|
|
1142
|
+
function normalizeTo_PascalCase(text) {
|
|
1143
|
+
return normalizeTo_camelCase(text, true);
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
/**
|
|
1147
|
+
* @@@
|
|
1148
|
+
*
|
|
1149
|
+
* @param text @@@
|
|
1150
|
+
* @returns @@@
|
|
1151
|
+
* @example 'hello_world'
|
|
1152
|
+
* @example 'i_love_promptbook'
|
|
1153
|
+
* @public exported from `@promptbook/utils`
|
|
1154
|
+
*/
|
|
1155
|
+
function normalizeTo_snake_case(text) {
|
|
1156
|
+
return normalizeTo_SCREAMING_CASE(text).toLowerCase();
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
/**
|
|
1160
|
+
* Take every whitespace (space, new line, tab) and replace it with a single space
|
|
1161
|
+
*
|
|
1162
|
+
* @public exported from `@promptbook/utils`
|
|
1163
|
+
*/
|
|
1164
|
+
function normalizeWhitespaces(sentence) {
|
|
1165
|
+
return sentence.replace(/\s+/gs, ' ').trim();
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
/**
|
|
1169
|
+
* Removes quotes from a string
|
|
1170
|
+
*
|
|
1171
|
+
* Tip: This is very usefull for post-processing of the result of the LLM model
|
|
1172
|
+
* Note: This function removes only the same quotes from the beginning and the end of the string
|
|
1173
|
+
* Note: There are two simmilar functions:
|
|
1174
|
+
* - `removeQuotes` which removes only bounding quotes
|
|
1175
|
+
* - `unwrapResult` which removes whole introduce sentence
|
|
1176
|
+
*
|
|
1177
|
+
* @param text optionally quoted text
|
|
1178
|
+
* @returns text without quotes
|
|
1179
|
+
* @public exported from `@promptbook/utils`
|
|
1180
|
+
*/
|
|
1181
|
+
function removeQuotes(text) {
|
|
1182
|
+
if (text.startsWith('"') && text.endsWith('"')) {
|
|
1183
|
+
return text.slice(1, -1);
|
|
1184
|
+
}
|
|
1185
|
+
if (text.startsWith('\'') && text.endsWith('\'')) {
|
|
1186
|
+
return text.slice(1, -1);
|
|
1187
|
+
}
|
|
1188
|
+
return text;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
/**
|
|
1192
|
+
* Function trimCodeBlock will trim starting and ending code block from the string if it is present.
|
|
1193
|
+
*
|
|
1194
|
+
* Note: This is usefull for post-processing of the result of the chat LLM model
|
|
1195
|
+
* when the model wraps the result in the (markdown) code block.
|
|
1196
|
+
*
|
|
1197
|
+
* @public exported from `@promptbook/utils`
|
|
1198
|
+
*/
|
|
1199
|
+
function trimCodeBlock(value) {
|
|
1200
|
+
value = spaceTrim.spaceTrim(value);
|
|
1201
|
+
if (!/^```[a-z]*(.*)```$/is.test(value)) {
|
|
1202
|
+
return value;
|
|
1203
|
+
}
|
|
1204
|
+
value = value.replace(/^```[a-z]*/i, '');
|
|
1205
|
+
value = value.replace(/```$/i, '');
|
|
1206
|
+
value = spaceTrim.spaceTrim(value);
|
|
1207
|
+
return value;
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
/**
|
|
1211
|
+
* Function trimEndOfCodeBlock will remove ending code block from the string if it is present.
|
|
1212
|
+
*
|
|
1213
|
+
* Note: This is usefull for post-processing of the result of the completion LLM model
|
|
1214
|
+
* if you want to start code block in the prompt but you don't want to end it in the result.
|
|
1215
|
+
*
|
|
1216
|
+
* @public exported from `@promptbook/utils`
|
|
1217
|
+
*/
|
|
1218
|
+
function trimEndOfCodeBlock(value) {
|
|
1219
|
+
value = spaceTrim.spaceTrim(value);
|
|
1220
|
+
value = value.replace(/```$/g, '');
|
|
1221
|
+
value = spaceTrim.spaceTrim(value);
|
|
1222
|
+
return value;
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
* Removes quotes and optional introduce text from a string
|
|
1227
|
+
*
|
|
1228
|
+
* Tip: This is very usefull for post-processing of the result of the LLM model
|
|
1229
|
+
* Note: This function trims the text and removes whole introduce sentence if it is present
|
|
1230
|
+
* Note: There are two simmilar functions:
|
|
1231
|
+
* - `removeQuotes` which removes only bounding quotes
|
|
1232
|
+
* - `unwrapResult` which removes whole introduce sentence
|
|
1233
|
+
*
|
|
1234
|
+
* @param text optionally quoted text
|
|
1235
|
+
* @returns text without quotes
|
|
1236
|
+
* @public exported from `@promptbook/utils`
|
|
1237
|
+
*/
|
|
1238
|
+
function unwrapResult(text, options) {
|
|
1239
|
+
const { isTrimmed = true, isIntroduceSentenceRemoved = true } = options || {};
|
|
1240
|
+
let trimmedText = text;
|
|
1241
|
+
// Remove leading and trailing spaces and newlines
|
|
1242
|
+
if (isTrimmed) {
|
|
1243
|
+
trimmedText = spaceTrim.spaceTrim(trimmedText);
|
|
1244
|
+
}
|
|
1245
|
+
let processedText = trimmedText;
|
|
1246
|
+
if (isIntroduceSentenceRemoved) {
|
|
1247
|
+
const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
|
|
1248
|
+
if (introduceSentenceRegex.test(text)) {
|
|
1249
|
+
// Remove the introduce sentence and quotes by replacing it with an empty string
|
|
1250
|
+
processedText = processedText.replace(introduceSentenceRegex, '');
|
|
1251
|
+
}
|
|
1252
|
+
processedText = spaceTrim.spaceTrim(processedText);
|
|
1253
|
+
}
|
|
1254
|
+
if (processedText.length < 3) {
|
|
1255
|
+
return trimmedText;
|
|
1256
|
+
}
|
|
1257
|
+
if (processedText.includes('\n')) {
|
|
1258
|
+
return trimmedText;
|
|
1259
|
+
}
|
|
1260
|
+
// Remove the quotes by extracting the substring without the first and last characters
|
|
1261
|
+
const unquotedText = processedText.slice(1, -1);
|
|
1262
|
+
// Check if the text starts and ends with quotes
|
|
1263
|
+
if ([
|
|
1264
|
+
['"', '"'],
|
|
1265
|
+
["'", "'"],
|
|
1266
|
+
['`', '`'],
|
|
1267
|
+
['*', '*'],
|
|
1268
|
+
['_', '_'],
|
|
1269
|
+
['„', '“'],
|
|
1270
|
+
['«', '»'] /* <- QUOTES to config */,
|
|
1271
|
+
].some(([startQuote, endQuote]) => {
|
|
1272
|
+
if (!processedText.startsWith(startQuote)) {
|
|
1273
|
+
return false;
|
|
1274
|
+
}
|
|
1275
|
+
if (!processedText.endsWith(endQuote)) {
|
|
1276
|
+
return false;
|
|
1277
|
+
}
|
|
1278
|
+
if (unquotedText.includes(startQuote) && !unquotedText.includes(endQuote)) {
|
|
1279
|
+
return false;
|
|
1280
|
+
}
|
|
1281
|
+
if (!unquotedText.includes(startQuote) && unquotedText.includes(endQuote)) {
|
|
1282
|
+
return false;
|
|
1283
|
+
}
|
|
1284
|
+
return true;
|
|
1285
|
+
})) {
|
|
1286
|
+
return unwrapResult(unquotedText, { isTrimmed: false, isIntroduceSentenceRemoved: false });
|
|
1287
|
+
}
|
|
1288
|
+
else {
|
|
1289
|
+
return processedText;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* TODO: [🧠] Should this also unwrap the (parenthesis)
|
|
1294
|
+
*/
|
|
1295
|
+
|
|
1296
|
+
/**
|
|
1297
|
+
* Extracts all code blocks from markdown.
|
|
1298
|
+
*
|
|
1299
|
+
* Note: There are multiple simmilar function:
|
|
1300
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
1301
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
1302
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
1303
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
1304
|
+
*
|
|
1305
|
+
* @param markdown any valid markdown
|
|
1306
|
+
* @returns code blocks with language and content
|
|
1307
|
+
* @throws {ParseError} if block is not closed properly
|
|
1308
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
1309
|
+
*/
|
|
1310
|
+
function extractAllBlocksFromMarkdown(markdown) {
|
|
1311
|
+
const codeBlocks = [];
|
|
1312
|
+
const lines = markdown.split('\n');
|
|
1313
|
+
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
1314
|
+
lines.push('');
|
|
1315
|
+
let currentCodeBlock = null;
|
|
1316
|
+
for (const line of lines) {
|
|
1317
|
+
if (line.startsWith('> ') || line === '>') {
|
|
1318
|
+
if (currentCodeBlock === null) {
|
|
1319
|
+
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
1320
|
+
} /* not else */
|
|
1321
|
+
if (currentCodeBlock.blockNotation === '>') {
|
|
1322
|
+
if (currentCodeBlock.content !== '') {
|
|
1323
|
+
currentCodeBlock.content += '\n';
|
|
1324
|
+
}
|
|
1325
|
+
currentCodeBlock.content += line.slice(2);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
1329
|
+
codeBlocks.push(currentCodeBlock);
|
|
1330
|
+
currentCodeBlock = null;
|
|
1331
|
+
}
|
|
1332
|
+
/* not else */
|
|
1333
|
+
if (line.startsWith('```')) {
|
|
1334
|
+
const language = line.slice(3).trim() || null;
|
|
1335
|
+
if (currentCodeBlock === null) {
|
|
1336
|
+
currentCodeBlock = { blockNotation: '```', language, content: '' };
|
|
1337
|
+
}
|
|
1338
|
+
else {
|
|
1339
|
+
if (language !== null) {
|
|
1340
|
+
throw new ParseError(`${capitalize(currentCodeBlock.language || 'the')} code block was not closed and already opening new ${language} code block`);
|
|
1341
|
+
}
|
|
1342
|
+
codeBlocks.push(currentCodeBlock);
|
|
1343
|
+
currentCodeBlock = null;
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
1347
|
+
if (currentCodeBlock.content !== '') {
|
|
1348
|
+
currentCodeBlock.content += '\n';
|
|
1349
|
+
}
|
|
1350
|
+
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
if (currentCodeBlock !== null) {
|
|
1354
|
+
throw new ParseError(`${capitalize(currentCodeBlock.language || 'the')} code block was not closed at the end of the markdown`);
|
|
1355
|
+
}
|
|
1356
|
+
return codeBlocks;
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
1360
|
+
*/
|
|
1361
|
+
|
|
1362
|
+
/**
|
|
1363
|
+
* Extracts exactly ONE code block from markdown.
|
|
1364
|
+
*
|
|
1365
|
+
* - When there are multiple or no code blocks the function throws a `ParseError`
|
|
1366
|
+
*
|
|
1367
|
+
* Note: There are multiple simmilar function:
|
|
1368
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
1369
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
1370
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
1371
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
1372
|
+
*
|
|
1373
|
+
* @param markdown any valid markdown
|
|
1374
|
+
* @returns code block with language and content
|
|
1375
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
1376
|
+
* @throws {ParseError} if there is not exactly one code block in the markdown
|
|
1377
|
+
*/
|
|
1378
|
+
function extractOneBlockFromMarkdown(markdown) {
|
|
1379
|
+
const codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
1380
|
+
if (codeBlocks.length !== 1) {
|
|
1381
|
+
throw new ParseError(spaceTrim__default["default"]((block) => `
|
|
1382
|
+
There should be exactly 1 code block in task section, found ${codeBlocks.length} code blocks
|
|
1383
|
+
|
|
1384
|
+
${block(codeBlocks.map((block, i) => `Block ${i + 1}:\n${block.content}`).join('\n\n\n'))}
|
|
1385
|
+
`));
|
|
1386
|
+
}
|
|
1387
|
+
return codeBlocks[0];
|
|
1388
|
+
}
|
|
1389
|
+
/***
|
|
1390
|
+
* TODO: [🍓][🌻] Decide of this is internal utility, external util OR validator/postprocessor
|
|
1391
|
+
*/
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* Extracts code block from markdown.
|
|
1395
|
+
*
|
|
1396
|
+
* - When there are multiple or no code blocks the function throws a `ParseError`
|
|
1397
|
+
*
|
|
1398
|
+
* Note: There are multiple simmilar function:
|
|
1399
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
1400
|
+
* - `extractJsonBlock` extracts exactly one valid JSON code block
|
|
1401
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
1402
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
1403
|
+
*
|
|
1404
|
+
* @public exported from `@promptbook/markdown-utils`
|
|
1405
|
+
* @throws {ParseError} if there is not exactly one code block in the markdown
|
|
1406
|
+
*/
|
|
1407
|
+
function extractBlock(markdown) {
|
|
1408
|
+
const { content } = extractOneBlockFromMarkdown(markdown);
|
|
1409
|
+
return content;
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
/**
|
|
1413
|
+
* Prettify the html code
|
|
1414
|
+
*
|
|
1415
|
+
* @param content raw html code
|
|
1416
|
+
* @returns formatted html code
|
|
1417
|
+
* @private withing the package because of HUGE size of prettier dependency
|
|
1418
|
+
*/
|
|
1419
|
+
function prettifyMarkdown(content) {
|
|
1420
|
+
try {
|
|
1421
|
+
return prettier.format(content, {
|
|
1422
|
+
parser: 'markdown',
|
|
1423
|
+
plugins: [parserHtml__default["default"]],
|
|
1424
|
+
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
1425
|
+
endOfLine: 'lf',
|
|
1426
|
+
tabWidth: 4,
|
|
1427
|
+
singleQuote: true,
|
|
1428
|
+
trailingComma: 'all',
|
|
1429
|
+
arrowParens: 'always',
|
|
1430
|
+
printWidth: 120,
|
|
1431
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
1432
|
+
jsxBracketSameLine: false,
|
|
1433
|
+
bracketSpacing: true,
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
catch (error) {
|
|
1437
|
+
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
1438
|
+
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
1439
|
+
error,
|
|
1440
|
+
html: content,
|
|
1441
|
+
});
|
|
1442
|
+
return content;
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
/**
|
|
1447
|
+
* Does nothing, but preserves the function in the bundle
|
|
1448
|
+
* Compiler is tricked into thinking the function is used
|
|
1449
|
+
*
|
|
1450
|
+
* @param value any function to preserve
|
|
1451
|
+
* @returns nothing
|
|
1452
|
+
* @private internal function of `JavascriptExecutionTools` and `JavascriptEvalExecutionTools`
|
|
1453
|
+
*/
|
|
1454
|
+
function preserve(func) {
|
|
1455
|
+
// Note: NOT calling the function
|
|
1456
|
+
(async () => {
|
|
1457
|
+
// TODO: [💩] Change to `await forEver` or something better
|
|
1458
|
+
await waitasecond.forTime(100000000);
|
|
1459
|
+
// [1]
|
|
1460
|
+
try {
|
|
1461
|
+
await func();
|
|
1462
|
+
}
|
|
1463
|
+
finally {
|
|
1464
|
+
// do nothing
|
|
1465
|
+
}
|
|
1466
|
+
})();
|
|
1467
|
+
}
|
|
1468
|
+
/**
|
|
1469
|
+
* TODO: Probbably remove in favour of `keepImported`
|
|
1470
|
+
* TODO: [1] This maybe does memory leak
|
|
1471
|
+
*/
|
|
1472
|
+
|
|
1473
|
+
// Note: [💎]
|
|
1474
|
+
/**
|
|
1475
|
+
* ScriptExecutionTools for JavaScript implemented via eval
|
|
1476
|
+
*
|
|
1477
|
+
* Warning: It is used for testing and mocking
|
|
1478
|
+
* **NOT intended to use in the production** due to its unsafe nature, use `JavascriptExecutionTools` instead.
|
|
1479
|
+
*
|
|
1480
|
+
* @public exported from `@promptbook/javascript`
|
|
1481
|
+
*/
|
|
1482
|
+
class JavascriptEvalExecutionTools {
|
|
1483
|
+
constructor(options) {
|
|
1484
|
+
this.options = options || {};
|
|
1485
|
+
}
|
|
1486
|
+
/**
|
|
1487
|
+
* Executes a JavaScript
|
|
1488
|
+
*/
|
|
1489
|
+
async execute(options) {
|
|
1490
|
+
const { scriptLanguage, parameters } = options;
|
|
1491
|
+
let { script } = options;
|
|
1492
|
+
if (scriptLanguage !== 'javascript') {
|
|
1493
|
+
throw new PipelineExecutionError(`Script language ${scriptLanguage} not supported to be executed by JavascriptEvalExecutionTools`);
|
|
1494
|
+
}
|
|
1495
|
+
// Note: [💎]
|
|
1496
|
+
// Note: Using direct eval, following variables are in same scope as eval call so they are accessible from inside the evaluated script:
|
|
1497
|
+
const spaceTrim = (_) => spaceTrim__default["default"](_);
|
|
1498
|
+
preserve(spaceTrim);
|
|
1499
|
+
const removeQuotes$1 = removeQuotes;
|
|
1500
|
+
preserve(removeQuotes$1);
|
|
1501
|
+
const unwrapResult$1 = unwrapResult;
|
|
1502
|
+
preserve(unwrapResult$1);
|
|
1503
|
+
const trimEndOfCodeBlock$1 = trimEndOfCodeBlock;
|
|
1504
|
+
preserve(trimEndOfCodeBlock$1);
|
|
1505
|
+
const trimCodeBlock$1 = trimCodeBlock;
|
|
1506
|
+
preserve(trimCodeBlock$1);
|
|
1507
|
+
// TODO: DRY [🍯]
|
|
1508
|
+
const trim = (str) => str.trim();
|
|
1509
|
+
preserve(trim);
|
|
1510
|
+
// TODO: DRY [🍯]
|
|
1511
|
+
const reverse = (str) => str.split('').reverse().join('');
|
|
1512
|
+
preserve(reverse);
|
|
1513
|
+
const removeEmojis$1 = removeEmojis;
|
|
1514
|
+
preserve(removeEmojis$1);
|
|
1515
|
+
const prettifyMarkdown$1 = prettifyMarkdown;
|
|
1516
|
+
preserve(prettifyMarkdown$1);
|
|
1517
|
+
//-------[n12:]---
|
|
1518
|
+
const capitalize$1 = capitalize;
|
|
1519
|
+
const decapitalize$1 = decapitalize;
|
|
1520
|
+
const nameToUriPart$1 = nameToUriPart;
|
|
1521
|
+
const nameToUriParts$1 = nameToUriParts;
|
|
1522
|
+
const removeDiacritics$1 = removeDiacritics;
|
|
1523
|
+
const normalizeWhitespaces$1 = normalizeWhitespaces;
|
|
1524
|
+
const normalizeToKebabCase$1 = normalizeToKebabCase;
|
|
1525
|
+
const normalizeTo_camelCase$1 = normalizeTo_camelCase;
|
|
1526
|
+
const normalizeTo_snake_case$1 = normalizeTo_snake_case;
|
|
1527
|
+
const normalizeTo_PascalCase$1 = normalizeTo_PascalCase;
|
|
1528
|
+
const parseKeywords = (input) =>
|
|
1529
|
+
// TODO: DRY [🍯]
|
|
1530
|
+
Array.from(parseKeywordsFromString(input)).join(', '); /* <- TODO: [🧠] What is the best format comma list, bullet list,...? */
|
|
1531
|
+
const normalizeTo_SCREAMING_CASE$1 = normalizeTo_SCREAMING_CASE;
|
|
1532
|
+
preserve(capitalize$1);
|
|
1533
|
+
preserve(decapitalize$1);
|
|
1534
|
+
preserve(nameToUriPart$1);
|
|
1535
|
+
preserve(nameToUriParts$1);
|
|
1536
|
+
preserve(removeDiacritics$1);
|
|
1537
|
+
preserve(normalizeWhitespaces$1);
|
|
1538
|
+
preserve(normalizeToKebabCase$1);
|
|
1539
|
+
preserve(normalizeTo_camelCase$1);
|
|
1540
|
+
preserve(normalizeTo_snake_case$1);
|
|
1541
|
+
preserve(normalizeTo_PascalCase$1);
|
|
1542
|
+
preserve(parseKeywords);
|
|
1543
|
+
preserve(normalizeTo_SCREAMING_CASE$1);
|
|
1544
|
+
//-------[/n12]---
|
|
1545
|
+
if (!script.includes('return')) {
|
|
1546
|
+
script = `return ${script}`;
|
|
1547
|
+
}
|
|
1548
|
+
// TODO: DRY [🍯]
|
|
1549
|
+
const buildinFunctions = {
|
|
1550
|
+
// TODO: [🍯] DRY all these functions across the file
|
|
1551
|
+
spaceTrim,
|
|
1552
|
+
removeQuotes: removeQuotes$1,
|
|
1553
|
+
unwrapResult: unwrapResult$1,
|
|
1554
|
+
trimEndOfCodeBlock: trimEndOfCodeBlock$1,
|
|
1555
|
+
trimCodeBlock: trimCodeBlock$1,
|
|
1556
|
+
trim,
|
|
1557
|
+
reverse,
|
|
1558
|
+
removeEmojis: removeEmojis$1,
|
|
1559
|
+
prettifyMarkdown: prettifyMarkdown$1,
|
|
1560
|
+
capitalize: capitalize$1,
|
|
1561
|
+
decapitalize: decapitalize$1,
|
|
1562
|
+
nameToUriPart: nameToUriPart$1,
|
|
1563
|
+
nameToUriParts: nameToUriParts$1,
|
|
1564
|
+
removeDiacritics: removeDiacritics$1,
|
|
1565
|
+
normalizeWhitespaces: normalizeWhitespaces$1,
|
|
1566
|
+
normalizeToKebabCase: normalizeToKebabCase$1,
|
|
1567
|
+
normalizeTo_camelCase: normalizeTo_camelCase$1,
|
|
1568
|
+
normalizeTo_snake_case: normalizeTo_snake_case$1,
|
|
1569
|
+
normalizeTo_PascalCase: normalizeTo_PascalCase$1,
|
|
1570
|
+
parseKeywords,
|
|
1571
|
+
normalizeTo_SCREAMING_CASE: normalizeTo_SCREAMING_CASE$1,
|
|
1572
|
+
extractBlock, // <- [🍓] Remove balast in all other functions, use this one as example
|
|
1573
|
+
};
|
|
1574
|
+
const buildinFunctionsStatement = Object.keys(buildinFunctions)
|
|
1575
|
+
.map((functionName) =>
|
|
1576
|
+
// Note: Custom functions are exposed to the current scope as variables
|
|
1577
|
+
`const ${functionName} = buildinFunctions.${functionName};`)
|
|
1578
|
+
.join('\n');
|
|
1579
|
+
// TODO: DRY [🍯]
|
|
1580
|
+
const customFunctions = this.options.functions || {};
|
|
1581
|
+
const customFunctionsStatement = Object.keys(customFunctions)
|
|
1582
|
+
.map((functionName) =>
|
|
1583
|
+
// Note: Custom functions are exposed to the current scope as variables
|
|
1584
|
+
`const ${functionName} = customFunctions.${functionName};`)
|
|
1585
|
+
.join('\n');
|
|
1586
|
+
// script = templateParameters(script, parameters);
|
|
1587
|
+
// <- TODO: [🧠][🥳] Should be this is one of two variants how to use parameters in script
|
|
1588
|
+
const statementToEvaluate = spaceTrim__default["default"]((block) => `
|
|
1589
|
+
|
|
1590
|
+
// Build-in functions:
|
|
1591
|
+
${block(buildinFunctionsStatement)}
|
|
1592
|
+
|
|
1593
|
+
// Custom functions:
|
|
1594
|
+
${block(customFunctionsStatement || '// -- No custom functions --')}
|
|
1595
|
+
|
|
1596
|
+
// The script:
|
|
1597
|
+
${block(Object.entries(parameters)
|
|
1598
|
+
.map(([key, value]) => `const ${key} = ${JSON.stringify(value)};`)
|
|
1599
|
+
.join('\n'))}
|
|
1600
|
+
(()=>{ ${script} })()
|
|
1601
|
+
`);
|
|
1602
|
+
if (this.options.isVerbose) {
|
|
1603
|
+
console.info(spaceTrim__default["default"]((block) => `
|
|
1604
|
+
🚀 Evaluating ${scriptLanguage} script:
|
|
1605
|
+
|
|
1606
|
+
${block(statementToEvaluate)}`));
|
|
1607
|
+
}
|
|
1608
|
+
let result;
|
|
1609
|
+
try {
|
|
1610
|
+
result = await eval(statementToEvaluate);
|
|
1611
|
+
if (typeof result !== 'string') {
|
|
1612
|
+
throw new PipelineExecutionError(`Script must return a string, but returned ${valueToString(result)}`);
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
catch (error) {
|
|
1616
|
+
if (!(error instanceof Error)) {
|
|
1617
|
+
throw error;
|
|
1618
|
+
}
|
|
1619
|
+
if (error instanceof ReferenceError) {
|
|
1620
|
+
const undefinedName = error.message.split(' ')[0];
|
|
1621
|
+
/*
|
|
1622
|
+
Note: Remapping error
|
|
1623
|
+
From: [PipelineUrlError: thing is not defined],
|
|
1624
|
+
To: [PipelineExecutionError: Parameter `{thing}` is not defined],
|
|
1625
|
+
*/
|
|
1626
|
+
if (!statementToEvaluate.includes(undefinedName + '(')) {
|
|
1627
|
+
throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
|
|
1628
|
+
|
|
1629
|
+
Parameter \`{${undefinedName}}\` is not defined
|
|
1630
|
+
|
|
1631
|
+
This happen during evaluation of the javascript, which has access to the following parameters as javascript variables:
|
|
1632
|
+
|
|
1633
|
+
${block(Object.keys(parameters)
|
|
1634
|
+
.map((key) => ` - ${key}\n`)
|
|
1635
|
+
.join(''))}
|
|
1636
|
+
|
|
1637
|
+
The script is:
|
|
1638
|
+
\`\`\`javascript
|
|
1639
|
+
${block(script)}
|
|
1640
|
+
\`\`\`
|
|
1641
|
+
|
|
1642
|
+
Original error message:
|
|
1643
|
+
${block(error.message)}
|
|
1644
|
+
|
|
1645
|
+
|
|
1646
|
+
`));
|
|
1647
|
+
}
|
|
1648
|
+
else {
|
|
1649
|
+
throw new PipelineExecutionError(spaceTrim__default["default"]((block) => `
|
|
1650
|
+
Function ${undefinedName}() is not defined
|
|
1651
|
+
|
|
1652
|
+
- Make sure that the function is one of built-in functions
|
|
1653
|
+
- Or you have to defined the function during construction of JavascriptEvalExecutionTools
|
|
1654
|
+
|
|
1655
|
+
Original error message:
|
|
1656
|
+
${block(error.message)}
|
|
1657
|
+
|
|
1658
|
+
`));
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
throw error;
|
|
1662
|
+
}
|
|
1663
|
+
if (typeof result !== 'string') {
|
|
1664
|
+
throw new PipelineExecutionError(`Script must return a string, but ${valueToString(result)}`);
|
|
1665
|
+
}
|
|
1666
|
+
return result;
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
/**
|
|
1670
|
+
* TODO: Put predefined functions (like removeQuotes, spaceTrim, etc.) into annotation OR pass into constructor
|
|
1671
|
+
* TODO: [🧠][💙] Distinct between options passed into ExecutionTools and to ExecutionTools.execute
|
|
1672
|
+
*/
|
|
1673
|
+
|
|
1674
|
+
/**
|
|
1675
|
+
* Placeholder for better implementation of JavascriptExecutionTools - some propper sandboxing
|
|
1676
|
+
*
|
|
1677
|
+
* @alias JavascriptExecutionTools
|
|
1678
|
+
* @public exported from `@promptbook/javascript`
|
|
1679
|
+
*/
|
|
1680
|
+
const JavascriptExecutionTools = JavascriptEvalExecutionTools;
|
|
1681
|
+
|
|
1682
|
+
const parseKeywords = (input) =>
|
|
1683
|
+
// TODO: DRY [🍯]
|
|
1684
|
+
Array.from(parseKeywordsFromString(input)).join(', '); /* <- TODO: [🧠] What is the best format comma list, bullet list,...? */
|
|
1685
|
+
// TODO: DRY [🍯]
|
|
1686
|
+
const trim = (str) => str.trim();
|
|
1687
|
+
// TODO: DRY [🍯]
|
|
1688
|
+
const reverse = (str) => str.split('').reverse().join('');
|
|
1689
|
+
/**
|
|
1690
|
+
* @@@
|
|
1691
|
+
*
|
|
1692
|
+
* @public exported from `@promptbook/javascript`
|
|
1693
|
+
*/
|
|
1694
|
+
const POSTPROCESSING_FUNCTIONS = {
|
|
1695
|
+
spaceTrim: spaceTrim__default["default"],
|
|
1696
|
+
removeQuotes,
|
|
1697
|
+
unwrapResult,
|
|
1698
|
+
trimEndOfCodeBlock,
|
|
1699
|
+
trimCodeBlock,
|
|
1700
|
+
trim,
|
|
1701
|
+
reverse,
|
|
1702
|
+
removeEmojis,
|
|
1703
|
+
prettifyMarkdown,
|
|
1704
|
+
capitalize,
|
|
1705
|
+
decapitalize,
|
|
1706
|
+
nameToUriPart,
|
|
1707
|
+
nameToUriParts,
|
|
1708
|
+
removeDiacritics,
|
|
1709
|
+
normalizeWhitespaces,
|
|
1710
|
+
normalizeToKebabCase,
|
|
1711
|
+
normalizeTo_camelCase,
|
|
1712
|
+
normalizeTo_snake_case,
|
|
1713
|
+
normalizeTo_PascalCase,
|
|
1714
|
+
parseKeywords,
|
|
1715
|
+
normalizeTo_SCREAMING_CASE,
|
|
1716
|
+
extractBlock, // <- [🍓] Remove balast in all other functions, use this one as example
|
|
1717
|
+
};
|
|
1718
|
+
/**
|
|
1719
|
+
* TODO: DRY [🍯], [🧠] Where should be POSTPROCESSING_FUNCTIONS located and how it should be named
|
|
1720
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1721
|
+
*/
|
|
1722
|
+
|
|
1723
|
+
/**
|
|
1724
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
1725
|
+
*
|
|
1726
|
+
* @param script from which to extract the variables
|
|
1727
|
+
* @returns the list of variable names
|
|
1728
|
+
* @throws {ParseError} if the script is invalid
|
|
1729
|
+
* @public exported from `@promptbook/javascript`
|
|
1730
|
+
*/
|
|
1731
|
+
function extractVariablesFromJavascript(script) {
|
|
1732
|
+
const variables = new Set();
|
|
1733
|
+
const originalScript = script;
|
|
1734
|
+
script = `(()=>{${script}})()`;
|
|
1735
|
+
try {
|
|
1736
|
+
for (let i = 0; i < LOOP_LIMIT; i++)
|
|
1737
|
+
try {
|
|
1738
|
+
eval(script); // <- TODO: Use `JavascriptExecutionTools.execute` here
|
|
1739
|
+
}
|
|
1740
|
+
catch (error) {
|
|
1741
|
+
if (!(error instanceof ReferenceError)) {
|
|
1742
|
+
throw error;
|
|
1743
|
+
}
|
|
1744
|
+
/*
|
|
1745
|
+
Note: Parsing the error
|
|
1746
|
+
🌟 Most devices:
|
|
1747
|
+
[PipelineUrlError: thing is not defined]
|
|
1748
|
+
|
|
1749
|
+
🍏 iPhone`s Safari:
|
|
1750
|
+
[PipelineUrlError: Can't find variable: thing]
|
|
1751
|
+
*/
|
|
1752
|
+
let variableName = undefined;
|
|
1753
|
+
if (error.message.startsWith(`Can't`)) {
|
|
1754
|
+
// 🍏 Case
|
|
1755
|
+
variableName = error.message.split(' ').pop();
|
|
1756
|
+
}
|
|
1757
|
+
else {
|
|
1758
|
+
// 🌟 Case
|
|
1759
|
+
variableName = error.message.split(' ').shift();
|
|
1760
|
+
}
|
|
1761
|
+
if (variableName === undefined) {
|
|
1762
|
+
throw error;
|
|
1763
|
+
}
|
|
1764
|
+
if (script.includes(variableName + '(')) {
|
|
1765
|
+
script = `const ${variableName} = ()=>'';` + script;
|
|
1766
|
+
}
|
|
1767
|
+
else {
|
|
1768
|
+
variables.add(variableName);
|
|
1769
|
+
script = `const ${variableName} = '';` + script;
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
catch (error) {
|
|
1774
|
+
if (!(error instanceof Error)) {
|
|
1775
|
+
throw error;
|
|
1776
|
+
}
|
|
1777
|
+
throw new ParseError(spaceTrim.spaceTrim((block) => `
|
|
1778
|
+
Can not extract variables from the script
|
|
1779
|
+
${block(error.stack || error.message)}
|
|
1780
|
+
|
|
1781
|
+
Found variables:
|
|
1782
|
+
${Array.from(variables)
|
|
1783
|
+
.map((variableName, i) => `${i + 1}) ${variableName}`)
|
|
1784
|
+
.join('\n')}
|
|
1785
|
+
|
|
1786
|
+
|
|
1787
|
+
The script:
|
|
1788
|
+
|
|
1789
|
+
\`\`\`javascript
|
|
1790
|
+
${block(originalScript)}
|
|
1791
|
+
\`\`\`
|
|
1792
|
+
`));
|
|
1793
|
+
}
|
|
1794
|
+
return variables;
|
|
1795
|
+
}
|
|
1796
|
+
/**
|
|
1797
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
1798
|
+
*/
|
|
1799
|
+
|
|
1800
|
+
exports.BOOK_LANGUAGE_VERSION = BOOK_LANGUAGE_VERSION;
|
|
1801
|
+
exports.JavascriptEvalExecutionTools = JavascriptEvalExecutionTools;
|
|
1802
|
+
exports.JavascriptExecutionTools = JavascriptExecutionTools;
|
|
1803
|
+
exports.POSTPROCESSING_FUNCTIONS = POSTPROCESSING_FUNCTIONS;
|
|
1804
|
+
exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
|
|
1805
|
+
exports.extractVariablesFromJavascript = extractVariablesFromJavascript;
|
|
1806
|
+
|
|
1807
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1808
|
+
|
|
1809
|
+
}));
|
|
1810
|
+
//# sourceMappingURL=index.umd.js.map
|