@promptbook/core 0.77.0 → 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 +4 -0
- package/esm/index.es.js +235 -65
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +8 -2
- package/esm/typings/src/_packages/types.index.d.ts +4 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -8
- package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
- package/esm/typings/src/commands/_common/types/CommandType.d.ts +17 -0
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTask.d.ts +1 -1
- package/esm/typings/src/conversion/utils/{extractVariables.d.ts → extractVariablesFromScript.d.ts} +2 -2
- package/esm/typings/src/conversion/utils/removePipelineCommand.d.ts +22 -0
- package/esm/typings/src/conversion/utils/{renameParameter.d.ts → renamePipelineParameter.d.ts} +3 -3
- package/esm/typings/src/errors/0-index.d.ts +46 -1
- package/esm/typings/src/errors/utils/ErrorJson.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/titleToName.test.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +238 -65
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/conversion/utils/{extractVariables.test.d.ts → extractVariablesFromScript.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/utils/{renameParameter.test.d.ts → removePipelineCommand.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/utils/{titleToName.test.d.ts → renamePipelineParameter.test.d.ts} +0 -0
- /package/esm/typings/src/{conversion/utils → utils/normalization}/titleToName.d.ts +0 -0
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.
|
|
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
|
|
@@ -2494,7 +2494,7 @@ var NotYetImplementedError = /** @class */ (function (_super) {
|
|
|
2494
2494
|
*
|
|
2495
2495
|
* @public exported from `@promptbook/core`
|
|
2496
2496
|
*/
|
|
2497
|
-
var
|
|
2497
|
+
var PROMPTBOOK_ERRORS = {
|
|
2498
2498
|
AbstractFormatError: AbstractFormatError,
|
|
2499
2499
|
CsvFormatError: CsvFormatError,
|
|
2500
2500
|
CollectionError: CollectionError,
|
|
@@ -2512,6 +2512,35 @@ var ERRORS = {
|
|
|
2512
2512
|
UnexpectedError: UnexpectedError,
|
|
2513
2513
|
// TODO: [🪑]> VersionMismatchError,
|
|
2514
2514
|
};
|
|
2515
|
+
/**
|
|
2516
|
+
* Index of all javascript errors
|
|
2517
|
+
*
|
|
2518
|
+
* @private for internal usage
|
|
2519
|
+
*/
|
|
2520
|
+
var COMMON_JAVASCRIPT_ERRORS = {
|
|
2521
|
+
Error: Error,
|
|
2522
|
+
EvalError: EvalError,
|
|
2523
|
+
RangeError: RangeError,
|
|
2524
|
+
ReferenceError: ReferenceError,
|
|
2525
|
+
SyntaxError: SyntaxError,
|
|
2526
|
+
TypeError: TypeError,
|
|
2527
|
+
URIError: URIError,
|
|
2528
|
+
AggregateError: AggregateError,
|
|
2529
|
+
/*
|
|
2530
|
+
Note: Not widely supported
|
|
2531
|
+
> InternalError,
|
|
2532
|
+
> ModuleError,
|
|
2533
|
+
> HeapError,
|
|
2534
|
+
> WebAssemblyCompileError,
|
|
2535
|
+
> WebAssemblyRuntimeError,
|
|
2536
|
+
*/
|
|
2537
|
+
};
|
|
2538
|
+
/**
|
|
2539
|
+
* Index of all errors
|
|
2540
|
+
*
|
|
2541
|
+
* @private for internal usage
|
|
2542
|
+
*/
|
|
2543
|
+
var ALL_ERRORS = __assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
|
|
2515
2544
|
/**
|
|
2516
2545
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2517
2546
|
*/
|
|
@@ -2522,11 +2551,11 @@ var ERRORS = {
|
|
|
2522
2551
|
* @public exported from `@promptbook/utils`
|
|
2523
2552
|
*/
|
|
2524
2553
|
function deserializeError(error) {
|
|
2525
|
-
|
|
2526
|
-
|
|
2554
|
+
var ErrorClass = ALL_ERRORS[error.name];
|
|
2555
|
+
if (ErrorClass === undefined) {
|
|
2556
|
+
return new Error("".concat(error.name, ": ").concat(error.message));
|
|
2527
2557
|
}
|
|
2528
|
-
|
|
2529
|
-
return new CustomError(error.message);
|
|
2558
|
+
return new ErrorClass(error.message);
|
|
2530
2559
|
}
|
|
2531
2560
|
|
|
2532
2561
|
/**
|
|
@@ -2600,8 +2629,8 @@ function isPipelinePrepared(pipeline) {
|
|
|
2600
2629
|
*/
|
|
2601
2630
|
function serializeError(error) {
|
|
2602
2631
|
var name = error.name, message = error.message, stack = error.stack;
|
|
2603
|
-
if (!
|
|
2604
|
-
|
|
2632
|
+
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2633
|
+
console.error(spaceTrim(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2605
2634
|
}
|
|
2606
2635
|
return {
|
|
2607
2636
|
name: name,
|
|
@@ -2616,9 +2645,9 @@ function serializeError(error) {
|
|
|
2616
2645
|
* @param script from which to extract the variables
|
|
2617
2646
|
* @returns the list of variable names
|
|
2618
2647
|
* @throws {ParseError} if the script is invalid
|
|
2619
|
-
* @public exported from `@promptbook/utils`
|
|
2648
|
+
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
2620
2649
|
*/
|
|
2621
|
-
function
|
|
2650
|
+
function extractVariablesFromScript(script) {
|
|
2622
2651
|
var variables = new Set();
|
|
2623
2652
|
script = "(()=>{".concat(script, "})()");
|
|
2624
2653
|
try {
|
|
@@ -2665,7 +2694,7 @@ function extractVariables(script) {
|
|
|
2665
2694
|
* @param task the task with used parameters
|
|
2666
2695
|
* @returns the set of parameter names
|
|
2667
2696
|
* @throws {ParseError} if the script is invalid
|
|
2668
|
-
* @public exported from `@promptbook/
|
|
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
|
|
2669
2698
|
*/
|
|
2670
2699
|
function extractParameterNamesFromTask(task) {
|
|
2671
2700
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
@@ -2686,7 +2715,7 @@ function extractParameterNamesFromTask(task) {
|
|
|
2686
2715
|
}
|
|
2687
2716
|
if (taskType === 'SCRIPT_TASK') {
|
|
2688
2717
|
try {
|
|
2689
|
-
for (var _g = __values(
|
|
2718
|
+
for (var _g = __values(extractVariablesFromScript(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
2690
2719
|
var parameterName = _h.value;
|
|
2691
2720
|
parameterNames.add(parameterName);
|
|
2692
2721
|
}
|
|
@@ -8342,6 +8371,7 @@ function splitMarkdownIntoSections(markdown) {
|
|
|
8342
8371
|
var e_1, _a;
|
|
8343
8372
|
var lines = markdown.split('\n');
|
|
8344
8373
|
var sections = [];
|
|
8374
|
+
// TODO: [🧽] DRY
|
|
8345
8375
|
var currentType = 'MARKDOWN';
|
|
8346
8376
|
var buffer = [];
|
|
8347
8377
|
var finishSection = function () {
|
|
@@ -8506,7 +8536,7 @@ function titleToName(value) {
|
|
|
8506
8536
|
* @public exported from `@promptbook/core`
|
|
8507
8537
|
*/
|
|
8508
8538
|
function pipelineStringToJsonSync(pipelineString) {
|
|
8509
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
8539
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
|
|
8510
8540
|
var $pipelineJson = {
|
|
8511
8541
|
title: undefined /* <- Note: [🍙] Putting here placeholder to keep `title` on top at final JSON */,
|
|
8512
8542
|
pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
|
|
@@ -8535,7 +8565,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8535
8565
|
// =============================================================
|
|
8536
8566
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
8537
8567
|
if (pipelineString.startsWith('#!')) {
|
|
8538
|
-
var
|
|
8568
|
+
var _f = __read(pipelineString.split('\n')), shebangLine_1 = _f[0], restLines = _f.slice(1);
|
|
8539
8569
|
if (!(shebangLine_1 || '').includes('ptbk')) {
|
|
8540
8570
|
throw new ParseError(spaceTrim$1(function (block) { return "\n It seems that you try to parse a book file which has non-standard shebang line for book files:\n Shebang line must contain 'ptbk'\n\n You have:\n ".concat(block(shebangLine_1 || '(empty line)'), "\n\n It should look like this:\n #!/usr/bin/env ptbk\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
|
|
8541
8571
|
}
|
|
@@ -8545,7 +8575,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8545
8575
|
pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
|
|
8546
8576
|
pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
8547
8577
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
8548
|
-
var
|
|
8578
|
+
var _g = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _g[0], pipelineSections = _g.slice(1); /* <- Note: [🥞] */
|
|
8549
8579
|
if (pipelineHead === undefined) {
|
|
8550
8580
|
throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Pipeline head is not defined\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
|
|
8551
8581
|
}
|
|
@@ -8636,11 +8666,41 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8636
8666
|
}
|
|
8637
8667
|
finally { if (e_1) throw e_1.error; }
|
|
8638
8668
|
}
|
|
8669
|
+
// =============================================================
|
|
8670
|
+
// Note: 4️⃣ Prepare unique section names with indexes when needed
|
|
8671
|
+
var sectionCounts = {};
|
|
8672
|
+
try {
|
|
8673
|
+
for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
|
|
8674
|
+
var section = pipelineSections_1_1.value;
|
|
8675
|
+
var name_1 = titleToName(section.title);
|
|
8676
|
+
if (sectionCounts[name_1] === undefined) {
|
|
8677
|
+
sectionCounts[name_1] = { count: 0, currentIndex: 0 };
|
|
8678
|
+
}
|
|
8679
|
+
sectionCounts[name_1].count++;
|
|
8680
|
+
}
|
|
8681
|
+
}
|
|
8682
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
8683
|
+
finally {
|
|
8684
|
+
try {
|
|
8685
|
+
if (pipelineSections_1_1 && !pipelineSections_1_1.done && (_b = pipelineSections_1.return)) _b.call(pipelineSections_1);
|
|
8686
|
+
}
|
|
8687
|
+
finally { if (e_2) throw e_2.error; }
|
|
8688
|
+
}
|
|
8689
|
+
var getUniqueSectionName = function (title) {
|
|
8690
|
+
var name = titleToName(title);
|
|
8691
|
+
var count = sectionCounts[name];
|
|
8692
|
+
if (count.count === 1) {
|
|
8693
|
+
return name;
|
|
8694
|
+
}
|
|
8695
|
+
var nameWithSuffix = "".concat(name, "-").concat(count.currentIndex);
|
|
8696
|
+
count.currentIndex++;
|
|
8697
|
+
return nameWithSuffix;
|
|
8698
|
+
};
|
|
8639
8699
|
var _loop_2 = function (section) {
|
|
8640
|
-
var
|
|
8700
|
+
var e_6, _m, e_7, _o;
|
|
8641
8701
|
// TODO: Parse section's description (the content out of the codeblock and lists)
|
|
8642
8702
|
var listItems_2 = extractAllListItemsFromMarkdown(section.content);
|
|
8643
|
-
var
|
|
8703
|
+
var _p = extractOneBlockFromMarkdown(section.content), language = _p.language, content = _p.content;
|
|
8644
8704
|
// TODO: [🎾][1] DRY description
|
|
8645
8705
|
var description_1 = section.content;
|
|
8646
8706
|
// Note: Remove codeblocks - TODO: [🎾]
|
|
@@ -8656,7 +8716,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8656
8716
|
isSectionTypeSet: false,
|
|
8657
8717
|
isTask: true,
|
|
8658
8718
|
taskType: undefined /* <- Note: [🍙] Putting here placeholder to keep `taskType` on top at final JSON */,
|
|
8659
|
-
name:
|
|
8719
|
+
name: getUniqueSectionName(section.title),
|
|
8660
8720
|
title: section.title,
|
|
8661
8721
|
description: description_1,
|
|
8662
8722
|
content: content,
|
|
@@ -8704,17 +8764,17 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8704
8764
|
};
|
|
8705
8765
|
try {
|
|
8706
8766
|
// TODO [♓️] List commands and before apply order them to achieve order-agnostic commands
|
|
8707
|
-
for (var commands_1 = (
|
|
8708
|
-
var
|
|
8767
|
+
for (var commands_1 = (e_6 = void 0, __values(commands)), commands_1_1 = commands_1.next(); !commands_1_1.done; commands_1_1 = commands_1.next()) {
|
|
8768
|
+
var _q = commands_1_1.value, listItem = _q.listItem, command = _q.command;
|
|
8709
8769
|
_loop_4(listItem, command);
|
|
8710
8770
|
}
|
|
8711
8771
|
}
|
|
8712
|
-
catch (
|
|
8772
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
8713
8773
|
finally {
|
|
8714
8774
|
try {
|
|
8715
|
-
if (commands_1_1 && !commands_1_1.done && (
|
|
8775
|
+
if (commands_1_1 && !commands_1_1.done && (_m = commands_1.return)) _m.call(commands_1);
|
|
8716
8776
|
}
|
|
8717
|
-
finally { if (
|
|
8777
|
+
finally { if (e_6) throw e_6.error; }
|
|
8718
8778
|
}
|
|
8719
8779
|
// TODO: [🍧] Should be done in SECTION command
|
|
8720
8780
|
if ($taskJson.taskType === 'SCRIPT_TASK') {
|
|
@@ -8728,8 +8788,8 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8728
8788
|
}
|
|
8729
8789
|
$taskJson.dependentParameterNames = Array.from(extractParameterNamesFromTask($taskJson));
|
|
8730
8790
|
try {
|
|
8731
|
-
for (var
|
|
8732
|
-
var parameterName =
|
|
8791
|
+
for (var _r = (e_7 = void 0, __values($taskJson.dependentParameterNames)), _s = _r.next(); !_s.done; _s = _r.next()) {
|
|
8792
|
+
var parameterName = _s.value;
|
|
8733
8793
|
// TODO: [🧠] This definition should be made first in the task
|
|
8734
8794
|
defineParam({
|
|
8735
8795
|
parameterName: parameterName,
|
|
@@ -8740,12 +8800,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8740
8800
|
});
|
|
8741
8801
|
}
|
|
8742
8802
|
}
|
|
8743
|
-
catch (
|
|
8803
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
8744
8804
|
finally {
|
|
8745
8805
|
try {
|
|
8746
|
-
if (
|
|
8806
|
+
if (_s && !_s.done && (_o = _r.return)) _o.call(_r);
|
|
8747
8807
|
}
|
|
8748
|
-
finally { if (
|
|
8808
|
+
finally { if (e_7) throw e_7.error; }
|
|
8749
8809
|
}
|
|
8750
8810
|
/*
|
|
8751
8811
|
// TODO: [🍧] This should be checked in `MODEL` command + better error message
|
|
@@ -8774,21 +8834,21 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8774
8834
|
};
|
|
8775
8835
|
try {
|
|
8776
8836
|
// =============================================================
|
|
8777
|
-
// Note:
|
|
8778
|
-
for (var
|
|
8779
|
-
var section =
|
|
8837
|
+
// Note: 5️⃣ Process each section of the pipeline
|
|
8838
|
+
for (var pipelineSections_2 = __values(pipelineSections), pipelineSections_2_1 = pipelineSections_2.next(); !pipelineSections_2_1.done; pipelineSections_2_1 = pipelineSections_2.next()) {
|
|
8839
|
+
var section = pipelineSections_2_1.value;
|
|
8780
8840
|
_loop_2(section);
|
|
8781
8841
|
}
|
|
8782
8842
|
}
|
|
8783
|
-
catch (
|
|
8843
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
8784
8844
|
finally {
|
|
8785
8845
|
try {
|
|
8786
|
-
if (
|
|
8846
|
+
if (pipelineSections_2_1 && !pipelineSections_2_1.done && (_c = pipelineSections_2.return)) _c.call(pipelineSections_2);
|
|
8787
8847
|
}
|
|
8788
|
-
finally { if (
|
|
8848
|
+
finally { if (e_3) throw e_3.error; }
|
|
8789
8849
|
}
|
|
8790
8850
|
// =============================================================
|
|
8791
|
-
// Note:
|
|
8851
|
+
// Note: 6️⃣ Mark parameters as INPUT if not explicitly set
|
|
8792
8852
|
if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isInput; })) {
|
|
8793
8853
|
var _loop_3 = function (parameter) {
|
|
8794
8854
|
var isThisParameterResulting = $pipelineJson.tasks.some(function (task) { return task.resultingParameterName === parameter.name; });
|
|
@@ -8797,42 +8857,42 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8797
8857
|
}
|
|
8798
8858
|
};
|
|
8799
8859
|
try {
|
|
8800
|
-
for (var
|
|
8801
|
-
var parameter =
|
|
8860
|
+
for (var _h = __values($pipelineJson.parameters), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
8861
|
+
var parameter = _j.value;
|
|
8802
8862
|
_loop_3(parameter);
|
|
8803
8863
|
}
|
|
8804
8864
|
}
|
|
8805
|
-
catch (
|
|
8865
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
8806
8866
|
finally {
|
|
8807
8867
|
try {
|
|
8808
|
-
if (
|
|
8868
|
+
if (_j && !_j.done && (_d = _h.return)) _d.call(_h);
|
|
8809
8869
|
}
|
|
8810
|
-
finally { if (
|
|
8870
|
+
finally { if (e_4) throw e_4.error; }
|
|
8811
8871
|
}
|
|
8812
8872
|
}
|
|
8813
8873
|
// =============================================================
|
|
8814
|
-
// Note:
|
|
8874
|
+
// Note: 7️⃣ Mark all non-INPUT parameters as OUTPUT if any OUTPUT is not set
|
|
8815
8875
|
if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isOutput; })) {
|
|
8816
8876
|
try {
|
|
8817
|
-
for (var
|
|
8818
|
-
var parameter =
|
|
8877
|
+
for (var _k = __values($pipelineJson.parameters), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
8878
|
+
var parameter = _l.value;
|
|
8819
8879
|
if (!parameter.isInput) {
|
|
8820
8880
|
parameter.isOutput = true;
|
|
8821
8881
|
}
|
|
8822
8882
|
}
|
|
8823
8883
|
}
|
|
8824
|
-
catch (
|
|
8884
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
8825
8885
|
finally {
|
|
8826
8886
|
try {
|
|
8827
|
-
if (
|
|
8887
|
+
if (_l && !_l.done && (_e = _k.return)) _e.call(_k);
|
|
8828
8888
|
}
|
|
8829
|
-
finally { if (
|
|
8889
|
+
finally { if (e_5) throw e_5.error; }
|
|
8830
8890
|
}
|
|
8831
8891
|
}
|
|
8832
8892
|
// =============================================================
|
|
8833
|
-
// Note:
|
|
8893
|
+
// Note: 8️⃣ Cleanup of undefined values
|
|
8834
8894
|
$pipelineJson.tasks.forEach(function (tasks) {
|
|
8835
|
-
var
|
|
8895
|
+
var e_8, _a;
|
|
8836
8896
|
try {
|
|
8837
8897
|
for (var _b = __values(Object.entries(tasks)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8838
8898
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8841,16 +8901,16 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8841
8901
|
}
|
|
8842
8902
|
}
|
|
8843
8903
|
}
|
|
8844
|
-
catch (
|
|
8904
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
8845
8905
|
finally {
|
|
8846
8906
|
try {
|
|
8847
8907
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8848
8908
|
}
|
|
8849
|
-
finally { if (
|
|
8909
|
+
finally { if (e_8) throw e_8.error; }
|
|
8850
8910
|
}
|
|
8851
8911
|
});
|
|
8852
8912
|
$pipelineJson.parameters.forEach(function (parameter) {
|
|
8853
|
-
var
|
|
8913
|
+
var e_9, _a;
|
|
8854
8914
|
try {
|
|
8855
8915
|
for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8856
8916
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8859,12 +8919,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8859
8919
|
}
|
|
8860
8920
|
}
|
|
8861
8921
|
}
|
|
8862
|
-
catch (
|
|
8922
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
8863
8923
|
finally {
|
|
8864
8924
|
try {
|
|
8865
8925
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8866
8926
|
}
|
|
8867
|
-
finally { if (
|
|
8927
|
+
finally { if (e_9) throw e_9.error; }
|
|
8868
8928
|
}
|
|
8869
8929
|
});
|
|
8870
8930
|
// =============================================================
|
|
@@ -8937,18 +8997,19 @@ function addAutoGeneratedSection(content, options) {
|
|
|
8937
8997
|
var warningLine = "<!-- ".concat(GENERATOR_WARNING, " -->");
|
|
8938
8998
|
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
8939
8999
|
var sectionMatch = content.match(sectionRegex);
|
|
9000
|
+
var contentToInsert = spaceTrim$1(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); });
|
|
8940
9001
|
if (sectionMatch) {
|
|
8941
|
-
return content.replace(sectionRegex,
|
|
9002
|
+
return content.replace(sectionRegex, contentToInsert);
|
|
8942
9003
|
}
|
|
9004
|
+
// Note: Following is the case when the section is not found in the file so we add it there
|
|
8943
9005
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
8944
|
-
if (
|
|
8945
|
-
|
|
8946
|
-
|
|
8947
|
-
|
|
8948
|
-
|
|
8949
|
-
|
|
8950
|
-
|
|
8951
|
-
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
9006
|
+
if (placeForSection !== null) {
|
|
9007
|
+
var _a = __read(placeForSection, 1), heading_1 = _a[0];
|
|
9008
|
+
return content.replace(heading_1, spaceTrim$1(function (block) { return "\n ".concat(block(contentToInsert), "\n \n ").concat(block(heading_1), "\n "); }));
|
|
9009
|
+
}
|
|
9010
|
+
console.warn("No place where to put the section <!--".concat(sectionName, "-->, using the end of the file"));
|
|
9011
|
+
// <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
|
|
9012
|
+
return spaceTrim$1(function (block) { return "\n ".concat(block(content), "\n \n ").concat(block(contentToInsert), "\n "); });
|
|
8952
9013
|
}
|
|
8953
9014
|
/**
|
|
8954
9015
|
* TODO: [🏛] This can be part of markdown builder
|
|
@@ -8976,7 +9037,7 @@ function renderPromptbookMermaid(pipelineJson, options) {
|
|
|
8976
9037
|
if (!task) {
|
|
8977
9038
|
throw new Error("Could not find task for {".concat(parameterName, "}"));
|
|
8978
9039
|
}
|
|
8979
|
-
return normalizeTo_camelCase('task-' + titleToName(task.title));
|
|
9040
|
+
return task.name || normalizeTo_camelCase('task-' + titleToName(task.title));
|
|
8980
9041
|
};
|
|
8981
9042
|
var promptbookMermaid = spaceTrim$1(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.tasks
|
|
8982
9043
|
.flatMap(function (_a) {
|
|
@@ -9039,7 +9100,7 @@ function prettifyPipelineString(pipelineString, options) {
|
|
|
9039
9100
|
return { href: "#".concat(task.name), title: task.title };
|
|
9040
9101
|
},
|
|
9041
9102
|
});
|
|
9042
|
-
promptbookMermaidBlock = spaceTrim$1(function (block) { return "\n
|
|
9103
|
+
promptbookMermaidBlock = spaceTrim$1(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
|
|
9043
9104
|
pipelineString = addAutoGeneratedSection(pipelineString, {
|
|
9044
9105
|
sectionName: 'Graph',
|
|
9045
9106
|
sectionContent: promptbookMermaidBlock,
|
|
@@ -9059,6 +9120,115 @@ function prettifyPipelineString(pipelineString, options) {
|
|
|
9059
9120
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
9060
9121
|
*/
|
|
9061
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
|
+
|
|
9062
9232
|
/**
|
|
9063
9233
|
* Tests if the value is [🚉] serializable as JSON
|
|
9064
9234
|
*
|
|
@@ -10625,5 +10795,5 @@ var PrefixStorage = /** @class */ (function () {
|
|
|
10625
10795
|
return PrefixStorage;
|
|
10626
10796
|
}());
|
|
10627
10797
|
|
|
10628
|
-
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,
|
|
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 };
|
|
10629
10799
|
//# sourceMappingURL=index.es.js.map
|