@promptbook/core 0.77.1 → 0.78.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,6 +23,10 @@
23
23
 
24
24
 
25
25
 
26
+ <blockquote style="color: #ff8811">
27
+ <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
28
+ </blockquote>
29
+
26
30
  ## 📦 Package `@promptbook/core`
27
31
 
28
32
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
package/esm/index.es.js CHANGED
@@ -23,7 +23,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
23
23
  *
24
24
  * @see https://github.com/webgptorg/promptbook
25
25
  */
26
- var PROMPTBOOK_ENGINE_VERSION = '0.77.0';
26
+ var PROMPTBOOK_ENGINE_VERSION = '0.77.1';
27
27
  /**
28
28
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
29
29
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2645,9 +2645,9 @@ function serializeError(error) {
2645
2645
  * @param script from which to extract the variables
2646
2646
  * @returns the list of variable names
2647
2647
  * @throws {ParseError} if the script is invalid
2648
- * @public exported from `@promptbook/utils`
2648
+ * @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
2649
2649
  */
2650
- function extractVariables(script) {
2650
+ function extractVariablesFromScript(script) {
2651
2651
  var variables = new Set();
2652
2652
  script = "(()=>{".concat(script, "})()");
2653
2653
  try {
@@ -2694,7 +2694,7 @@ function extractVariables(script) {
2694
2694
  * @param task the task with used parameters
2695
2695
  * @returns the set of parameter names
2696
2696
  * @throws {ParseError} if the script is invalid
2697
- * @public exported from `@promptbook/utils`
2697
+ * @public exported from `@promptbook/core` <- Note: [👖] This utility is so tightly interconnected with the Promptbook that it is not exported as util but in core
2698
2698
  */
2699
2699
  function extractParameterNamesFromTask(task) {
2700
2700
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
@@ -2715,7 +2715,7 @@ function extractParameterNamesFromTask(task) {
2715
2715
  }
2716
2716
  if (taskType === 'SCRIPT_TASK') {
2717
2717
  try {
2718
- for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
2718
+ for (var _g = __values(extractVariablesFromScript(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
2719
2719
  var parameterName = _h.value;
2720
2720
  parameterNames.add(parameterName);
2721
2721
  }
@@ -8371,6 +8371,7 @@ function splitMarkdownIntoSections(markdown) {
8371
8371
  var e_1, _a;
8372
8372
  var lines = markdown.split('\n');
8373
8373
  var sections = [];
8374
+ // TODO: [🧽] DRY
8374
8375
  var currentType = 'MARKDOWN';
8375
8376
  var buffer = [];
8376
8377
  var finishSection = function () {
@@ -9119,6 +9120,115 @@ function prettifyPipelineString(pipelineString, options) {
9119
9120
  * TODO: [🕌] When more than 2 functionalities, split into separate functions
9120
9121
  */
9121
9122
 
9123
+ /**
9124
+ * Function `removePipelineCommand` will remove one command from pipeline string
9125
+ *
9126
+ * @public exported from `@promptbook/core` <- Note: [👖] This utility is so tightly interconnected with the Promptbook that it is not exported as util but in core
9127
+ */
9128
+ function removePipelineCommand(options) {
9129
+ var e_1, _a;
9130
+ var command = options.command, pipeline = options.pipeline;
9131
+ var lines = pipeline.split('\n');
9132
+ // TODO: [🧽] DRY
9133
+ var currentType = 'MARKDOWN';
9134
+ var newLines = [];
9135
+ try {
9136
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
9137
+ var line = lines_1_1.value;
9138
+ if (currentType === 'MARKDOWN') {
9139
+ if (line.startsWith('```')) {
9140
+ currentType = 'CODE_BLOCK';
9141
+ }
9142
+ else if (line.includes('<!--')) {
9143
+ currentType = 'COMMENT';
9144
+ }
9145
+ }
9146
+ else if (currentType === 'CODE_BLOCK') {
9147
+ if (line.startsWith('```')) {
9148
+ currentType = 'MARKDOWN';
9149
+ }
9150
+ }
9151
+ else if (currentType === 'COMMENT') {
9152
+ if (line.includes('-->')) {
9153
+ currentType = 'MARKDOWN';
9154
+ }
9155
+ }
9156
+ if (currentType === 'MARKDOWN' && /^(-|\d\))/m.test(line) && line.toUpperCase().includes(command)) {
9157
+ continue;
9158
+ }
9159
+ newLines.push(line);
9160
+ }
9161
+ }
9162
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
9163
+ finally {
9164
+ try {
9165
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
9166
+ }
9167
+ finally { if (e_1) throw e_1.error; }
9168
+ }
9169
+ var newPipeline = spaceTrim(newLines.join('\n'));
9170
+ return newPipeline;
9171
+ }
9172
+
9173
+ /**
9174
+ * Function `renamePipelineParameter` will find all usable parameters for given task
9175
+ * In other words, it will find all parameters that are not used in the task itseld and all its dependencies
9176
+ *
9177
+ * @throws {PipelineLogicError} If the new parameter name is already used in the pipeline
9178
+ * @public exported from `@promptbook/core` <- Note: [👖] This utility is so tightly interconnected with the Promptbook that it is not exported as util but in core
9179
+ */
9180
+ function renamePipelineParameter(options) {
9181
+ var e_1, _a, e_2, _b;
9182
+ var pipeline = options.pipeline, oldParameterName = options.oldParameterName, newParameterName = options.newParameterName;
9183
+ if (pipeline.parameters.some(function (parameter) { return parameter.name === newParameterName; })) {
9184
+ throw new PipelineLogicError("Can not replace {".concat(oldParameterName, "} to {").concat(newParameterName, "} because {").concat(newParameterName, "} is already used in the pipeline"));
9185
+ }
9186
+ var renamedPipeline = __assign(__assign({}, pipeline), {
9187
+ // <- TODO: [🪓] This should be without `as $PipelineJson`
9188
+ parameters: __spreadArray([], __read(pipeline.parameters), false), tasks: __spreadArray([], __read(pipeline.tasks), false) });
9189
+ try {
9190
+ for (var _c = __values(renamedPipeline.parameters), _d = _c.next(); !_d.done; _d = _c.next()) {
9191
+ var parameter = _d.value;
9192
+ if (parameter.name !== oldParameterName) {
9193
+ continue;
9194
+ }
9195
+ parameter.name = newParameterName;
9196
+ }
9197
+ }
9198
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
9199
+ finally {
9200
+ try {
9201
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
9202
+ }
9203
+ finally { if (e_1) throw e_1.error; }
9204
+ }
9205
+ try {
9206
+ for (var _e = __values(renamedPipeline.tasks), _f = _e.next(); !_f.done; _f = _e.next()) {
9207
+ var task = _f.value;
9208
+ if (task.resultingParameterName === oldParameterName) {
9209
+ task.resultingParameterName = newParameterName;
9210
+ }
9211
+ task.dependentParameterNames = task.dependentParameterNames.map(function (dependentParameterName) {
9212
+ return dependentParameterName === oldParameterName ? newParameterName : dependentParameterName;
9213
+ });
9214
+ task.content = task.content.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
9215
+ task.title = task.title.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
9216
+ task.description =
9217
+ task.description === undefined
9218
+ ? undefined
9219
+ : task.description.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
9220
+ }
9221
+ }
9222
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
9223
+ finally {
9224
+ try {
9225
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
9226
+ }
9227
+ finally { if (e_2) throw e_2.error; }
9228
+ }
9229
+ return renamedPipeline;
9230
+ }
9231
+
9122
9232
  /**
9123
9233
  * Tests if the value is [🚉] serializable as JSON
9124
9234
  *
@@ -10685,5 +10795,5 @@ var PrefixStorage = /** @class */ (function () {
10685
10795
  return PrefixStorage;
10686
10796
  }());
10687
10797
 
10688
- export { $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, AbstractFormatError, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateError, BoilerplateFormfactorDefinition, CLAIM, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CsvFormatDefinition, CsvFormatError, DEFAULT_BOOKS_DIRNAME, DEFAULT_CSV_SETTINGS, DEFAULT_EXECUTIONS_CACHE_DIRNAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TITLE, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FORMFACTOR_DEFINITIONS, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, KnowledgeScrapeError, LOGO_DARK_SRC, LOGO_LIGHT_SRC, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NAME, NonTaskSectionTypes, NotFoundError, NotYetImplementedError, PROMPTBOOK_ENGINE_VERSION, PROMPTBOOK_ERRORS, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, RESERVED_PARAMETER_NAMES, SET_IS_VERBOSE, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatDefinition, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UnexpectedError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _DocumentScraperMetadataRegistration, _GoogleMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, addUsage, assertsExecutionSuccessful, cacheLlmTools, collectionToJson, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, getPipelineInterface, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTasks, prettifyPipelineString, stringifyPipelineJson, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline };
10798
+ export { $llmToolsMetadataRegister, $llmToolsRegister, $scrapersMetadataRegister, $scrapersRegister, AbstractFormatError, BOOK_LANGUAGE_VERSION, BlackholeStorage, BoilerplateError, BoilerplateFormfactorDefinition, CLAIM, CallbackInterfaceTools, ChatbotFormfactorDefinition, CollectionError, CsvFormatDefinition, CsvFormatError, DEFAULT_BOOKS_DIRNAME, DEFAULT_CSV_SETTINGS, DEFAULT_EXECUTIONS_CACHE_DIRNAME, DEFAULT_INTERMEDIATE_FILES_STRATEGY, DEFAULT_IS_AUTO_INSTALLED, DEFAULT_IS_VERBOSE, DEFAULT_MAX_EXECUTION_ATTEMPTS, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_DEPTH, DEFAULT_MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL, DEFAULT_MAX_PARALLEL_COUNT, DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, DEFAULT_REMOTE_URL, DEFAULT_REMOTE_URL_PATH, DEFAULT_SCRAPE_CACHE_DIRNAME, DEFAULT_TITLE, EXPECTATION_UNITS, EnvironmentMismatchError, ExecutionReportStringOptionsDefaults, ExpectError, FORMFACTOR_DEFINITIONS, GENERIC_PIPELINE_INTERFACE, GeneratorFormfactorDefinition, GenericFormfactorDefinition, KnowledgeScrapeError, LOGO_DARK_SRC, LOGO_LIGHT_SRC, LimitReachedError, MANDATORY_CSV_SETTINGS, MAX_FILENAME_LENGTH, MODEL_VARIANTS, MatcherFormfactorDefinition, MemoryStorage, MissingToolsError, MultipleLlmExecutionTools, NAME, NonTaskSectionTypes, NotFoundError, NotYetImplementedError, PROMPTBOOK_ENGINE_VERSION, PROMPTBOOK_ERRORS, ParseError, PipelineExecutionError, PipelineLogicError, PipelineUrlError, PrefixStorage, RESERVED_PARAMETER_NAMES, SET_IS_VERBOSE, SectionTypes, SheetsFormfactorDefinition, TaskTypes, TextFormatDefinition, TranslatorFormfactorDefinition, UNCERTAIN_USAGE, UnexpectedError, ZERO_USAGE, _AnthropicClaudeMetadataRegistration, _AzureOpenAiMetadataRegistration, _DocumentScraperMetadataRegistration, _GoogleMetadataRegistration, _LegacyDocumentScraperMetadataRegistration, _MarkdownScraperMetadataRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiMetadataRegistration, _PdfScraperMetadataRegistration, _WebsiteScraperMetadataRegistration, addUsage, assertsExecutionSuccessful, cacheLlmTools, collectionToJson, countTotalUsage, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createLlmToolsFromConfiguration, createPipelineExecutor, createSubcollection, embeddingVectorToString, executionReportJsonToString, extractParameterNamesFromTask, getPipelineInterface, isPassingExpectations, isPipelineImplementingInterface, isPipelineInterfacesEqual, isPipelinePrepared, joinLlmExecutionTools, limitTotalUsage, makeKnowledgeSourceHandler, pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, prepareKnowledgePieces, preparePersona, preparePipeline, prepareTasks, prettifyPipelineString, removePipelineCommand, renamePipelineParameter, stringifyPipelineJson, unpreparePipeline, usageToHuman, usageToWorktime, validatePipeline };
10689
10799
  //# sourceMappingURL=index.es.js.map