@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/umd/index.umd.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.77.
|
|
28
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.77.1';
|
|
29
29
|
/**
|
|
30
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
31
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -2496,7 +2496,7 @@
|
|
|
2496
2496
|
*
|
|
2497
2497
|
* @public exported from `@promptbook/core`
|
|
2498
2498
|
*/
|
|
2499
|
-
var
|
|
2499
|
+
var PROMPTBOOK_ERRORS = {
|
|
2500
2500
|
AbstractFormatError: AbstractFormatError,
|
|
2501
2501
|
CsvFormatError: CsvFormatError,
|
|
2502
2502
|
CollectionError: CollectionError,
|
|
@@ -2514,6 +2514,35 @@
|
|
|
2514
2514
|
UnexpectedError: UnexpectedError,
|
|
2515
2515
|
// TODO: [🪑]> VersionMismatchError,
|
|
2516
2516
|
};
|
|
2517
|
+
/**
|
|
2518
|
+
* Index of all javascript errors
|
|
2519
|
+
*
|
|
2520
|
+
* @private for internal usage
|
|
2521
|
+
*/
|
|
2522
|
+
var COMMON_JAVASCRIPT_ERRORS = {
|
|
2523
|
+
Error: Error,
|
|
2524
|
+
EvalError: EvalError,
|
|
2525
|
+
RangeError: RangeError,
|
|
2526
|
+
ReferenceError: ReferenceError,
|
|
2527
|
+
SyntaxError: SyntaxError,
|
|
2528
|
+
TypeError: TypeError,
|
|
2529
|
+
URIError: URIError,
|
|
2530
|
+
AggregateError: AggregateError,
|
|
2531
|
+
/*
|
|
2532
|
+
Note: Not widely supported
|
|
2533
|
+
> InternalError,
|
|
2534
|
+
> ModuleError,
|
|
2535
|
+
> HeapError,
|
|
2536
|
+
> WebAssemblyCompileError,
|
|
2537
|
+
> WebAssemblyRuntimeError,
|
|
2538
|
+
*/
|
|
2539
|
+
};
|
|
2540
|
+
/**
|
|
2541
|
+
* Index of all errors
|
|
2542
|
+
*
|
|
2543
|
+
* @private for internal usage
|
|
2544
|
+
*/
|
|
2545
|
+
var ALL_ERRORS = __assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
|
|
2517
2546
|
/**
|
|
2518
2547
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2519
2548
|
*/
|
|
@@ -2524,11 +2553,11 @@
|
|
|
2524
2553
|
* @public exported from `@promptbook/utils`
|
|
2525
2554
|
*/
|
|
2526
2555
|
function deserializeError(error) {
|
|
2527
|
-
|
|
2528
|
-
|
|
2556
|
+
var ErrorClass = ALL_ERRORS[error.name];
|
|
2557
|
+
if (ErrorClass === undefined) {
|
|
2558
|
+
return new Error("".concat(error.name, ": ").concat(error.message));
|
|
2529
2559
|
}
|
|
2530
|
-
|
|
2531
|
-
return new CustomError(error.message);
|
|
2560
|
+
return new ErrorClass(error.message);
|
|
2532
2561
|
}
|
|
2533
2562
|
|
|
2534
2563
|
/**
|
|
@@ -2602,8 +2631,8 @@
|
|
|
2602
2631
|
*/
|
|
2603
2632
|
function serializeError(error) {
|
|
2604
2633
|
var name = error.name, message = error.message, stack = error.stack;
|
|
2605
|
-
if (!
|
|
2606
|
-
|
|
2634
|
+
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2635
|
+
console.error(spaceTrim__default["default"](function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
|
|
2607
2636
|
}
|
|
2608
2637
|
return {
|
|
2609
2638
|
name: name,
|
|
@@ -2618,9 +2647,9 @@
|
|
|
2618
2647
|
* @param script from which to extract the variables
|
|
2619
2648
|
* @returns the list of variable names
|
|
2620
2649
|
* @throws {ParseError} if the script is invalid
|
|
2621
|
-
* @public exported from `@promptbook/utils`
|
|
2650
|
+
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
2622
2651
|
*/
|
|
2623
|
-
function
|
|
2652
|
+
function extractVariablesFromScript(script) {
|
|
2624
2653
|
var variables = new Set();
|
|
2625
2654
|
script = "(()=>{".concat(script, "})()");
|
|
2626
2655
|
try {
|
|
@@ -2667,7 +2696,7 @@
|
|
|
2667
2696
|
* @param task the task with used parameters
|
|
2668
2697
|
* @returns the set of parameter names
|
|
2669
2698
|
* @throws {ParseError} if the script is invalid
|
|
2670
|
-
* @public exported from `@promptbook/
|
|
2699
|
+
* @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
|
|
2671
2700
|
*/
|
|
2672
2701
|
function extractParameterNamesFromTask(task) {
|
|
2673
2702
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
@@ -2688,7 +2717,7 @@
|
|
|
2688
2717
|
}
|
|
2689
2718
|
if (taskType === 'SCRIPT_TASK') {
|
|
2690
2719
|
try {
|
|
2691
|
-
for (var _g = __values(
|
|
2720
|
+
for (var _g = __values(extractVariablesFromScript(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
2692
2721
|
var parameterName = _h.value;
|
|
2693
2722
|
parameterNames.add(parameterName);
|
|
2694
2723
|
}
|
|
@@ -8344,6 +8373,7 @@
|
|
|
8344
8373
|
var e_1, _a;
|
|
8345
8374
|
var lines = markdown.split('\n');
|
|
8346
8375
|
var sections = [];
|
|
8376
|
+
// TODO: [🧽] DRY
|
|
8347
8377
|
var currentType = 'MARKDOWN';
|
|
8348
8378
|
var buffer = [];
|
|
8349
8379
|
var finishSection = function () {
|
|
@@ -8508,7 +8538,7 @@
|
|
|
8508
8538
|
* @public exported from `@promptbook/core`
|
|
8509
8539
|
*/
|
|
8510
8540
|
function pipelineStringToJsonSync(pipelineString) {
|
|
8511
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
8541
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
|
|
8512
8542
|
var $pipelineJson = {
|
|
8513
8543
|
title: undefined /* <- Note: [🍙] Putting here placeholder to keep `title` on top at final JSON */,
|
|
8514
8544
|
pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
|
|
@@ -8537,7 +8567,7 @@
|
|
|
8537
8567
|
// =============================================================
|
|
8538
8568
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
8539
8569
|
if (pipelineString.startsWith('#!')) {
|
|
8540
|
-
var
|
|
8570
|
+
var _f = __read(pipelineString.split('\n')), shebangLine_1 = _f[0], restLines = _f.slice(1);
|
|
8541
8571
|
if (!(shebangLine_1 || '').includes('ptbk')) {
|
|
8542
8572
|
throw new ParseError(spaceTrim.spaceTrim(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 "); }));
|
|
8543
8573
|
}
|
|
@@ -8547,7 +8577,7 @@
|
|
|
8547
8577
|
pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
|
|
8548
8578
|
pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
8549
8579
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
8550
|
-
var
|
|
8580
|
+
var _g = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _g[0], pipelineSections = _g.slice(1); /* <- Note: [🥞] */
|
|
8551
8581
|
if (pipelineHead === undefined) {
|
|
8552
8582
|
throw new UnexpectedError(spaceTrim.spaceTrim(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 "); }));
|
|
8553
8583
|
}
|
|
@@ -8638,11 +8668,41 @@
|
|
|
8638
8668
|
}
|
|
8639
8669
|
finally { if (e_1) throw e_1.error; }
|
|
8640
8670
|
}
|
|
8671
|
+
// =============================================================
|
|
8672
|
+
// Note: 4️⃣ Prepare unique section names with indexes when needed
|
|
8673
|
+
var sectionCounts = {};
|
|
8674
|
+
try {
|
|
8675
|
+
for (var pipelineSections_1 = __values(pipelineSections), pipelineSections_1_1 = pipelineSections_1.next(); !pipelineSections_1_1.done; pipelineSections_1_1 = pipelineSections_1.next()) {
|
|
8676
|
+
var section = pipelineSections_1_1.value;
|
|
8677
|
+
var name_1 = titleToName(section.title);
|
|
8678
|
+
if (sectionCounts[name_1] === undefined) {
|
|
8679
|
+
sectionCounts[name_1] = { count: 0, currentIndex: 0 };
|
|
8680
|
+
}
|
|
8681
|
+
sectionCounts[name_1].count++;
|
|
8682
|
+
}
|
|
8683
|
+
}
|
|
8684
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
8685
|
+
finally {
|
|
8686
|
+
try {
|
|
8687
|
+
if (pipelineSections_1_1 && !pipelineSections_1_1.done && (_b = pipelineSections_1.return)) _b.call(pipelineSections_1);
|
|
8688
|
+
}
|
|
8689
|
+
finally { if (e_2) throw e_2.error; }
|
|
8690
|
+
}
|
|
8691
|
+
var getUniqueSectionName = function (title) {
|
|
8692
|
+
var name = titleToName(title);
|
|
8693
|
+
var count = sectionCounts[name];
|
|
8694
|
+
if (count.count === 1) {
|
|
8695
|
+
return name;
|
|
8696
|
+
}
|
|
8697
|
+
var nameWithSuffix = "".concat(name, "-").concat(count.currentIndex);
|
|
8698
|
+
count.currentIndex++;
|
|
8699
|
+
return nameWithSuffix;
|
|
8700
|
+
};
|
|
8641
8701
|
var _loop_2 = function (section) {
|
|
8642
|
-
var
|
|
8702
|
+
var e_6, _m, e_7, _o;
|
|
8643
8703
|
// TODO: Parse section's description (the content out of the codeblock and lists)
|
|
8644
8704
|
var listItems_2 = extractAllListItemsFromMarkdown(section.content);
|
|
8645
|
-
var
|
|
8705
|
+
var _p = extractOneBlockFromMarkdown(section.content), language = _p.language, content = _p.content;
|
|
8646
8706
|
// TODO: [🎾][1] DRY description
|
|
8647
8707
|
var description_1 = section.content;
|
|
8648
8708
|
// Note: Remove codeblocks - TODO: [🎾]
|
|
@@ -8658,7 +8718,7 @@
|
|
|
8658
8718
|
isSectionTypeSet: false,
|
|
8659
8719
|
isTask: true,
|
|
8660
8720
|
taskType: undefined /* <- Note: [🍙] Putting here placeholder to keep `taskType` on top at final JSON */,
|
|
8661
|
-
name:
|
|
8721
|
+
name: getUniqueSectionName(section.title),
|
|
8662
8722
|
title: section.title,
|
|
8663
8723
|
description: description_1,
|
|
8664
8724
|
content: content,
|
|
@@ -8706,17 +8766,17 @@
|
|
|
8706
8766
|
};
|
|
8707
8767
|
try {
|
|
8708
8768
|
// TODO [♓️] List commands and before apply order them to achieve order-agnostic commands
|
|
8709
|
-
for (var commands_1 = (
|
|
8710
|
-
var
|
|
8769
|
+
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()) {
|
|
8770
|
+
var _q = commands_1_1.value, listItem = _q.listItem, command = _q.command;
|
|
8711
8771
|
_loop_4(listItem, command);
|
|
8712
8772
|
}
|
|
8713
8773
|
}
|
|
8714
|
-
catch (
|
|
8774
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
8715
8775
|
finally {
|
|
8716
8776
|
try {
|
|
8717
|
-
if (commands_1_1 && !commands_1_1.done && (
|
|
8777
|
+
if (commands_1_1 && !commands_1_1.done && (_m = commands_1.return)) _m.call(commands_1);
|
|
8718
8778
|
}
|
|
8719
|
-
finally { if (
|
|
8779
|
+
finally { if (e_6) throw e_6.error; }
|
|
8720
8780
|
}
|
|
8721
8781
|
// TODO: [🍧] Should be done in SECTION command
|
|
8722
8782
|
if ($taskJson.taskType === 'SCRIPT_TASK') {
|
|
@@ -8730,8 +8790,8 @@
|
|
|
8730
8790
|
}
|
|
8731
8791
|
$taskJson.dependentParameterNames = Array.from(extractParameterNamesFromTask($taskJson));
|
|
8732
8792
|
try {
|
|
8733
|
-
for (var
|
|
8734
|
-
var parameterName =
|
|
8793
|
+
for (var _r = (e_7 = void 0, __values($taskJson.dependentParameterNames)), _s = _r.next(); !_s.done; _s = _r.next()) {
|
|
8794
|
+
var parameterName = _s.value;
|
|
8735
8795
|
// TODO: [🧠] This definition should be made first in the task
|
|
8736
8796
|
defineParam({
|
|
8737
8797
|
parameterName: parameterName,
|
|
@@ -8742,12 +8802,12 @@
|
|
|
8742
8802
|
});
|
|
8743
8803
|
}
|
|
8744
8804
|
}
|
|
8745
|
-
catch (
|
|
8805
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
8746
8806
|
finally {
|
|
8747
8807
|
try {
|
|
8748
|
-
if (
|
|
8808
|
+
if (_s && !_s.done && (_o = _r.return)) _o.call(_r);
|
|
8749
8809
|
}
|
|
8750
|
-
finally { if (
|
|
8810
|
+
finally { if (e_7) throw e_7.error; }
|
|
8751
8811
|
}
|
|
8752
8812
|
/*
|
|
8753
8813
|
// TODO: [🍧] This should be checked in `MODEL` command + better error message
|
|
@@ -8776,21 +8836,21 @@
|
|
|
8776
8836
|
};
|
|
8777
8837
|
try {
|
|
8778
8838
|
// =============================================================
|
|
8779
|
-
// Note:
|
|
8780
|
-
for (var
|
|
8781
|
-
var section =
|
|
8839
|
+
// Note: 5️⃣ Process each section of the pipeline
|
|
8840
|
+
for (var pipelineSections_2 = __values(pipelineSections), pipelineSections_2_1 = pipelineSections_2.next(); !pipelineSections_2_1.done; pipelineSections_2_1 = pipelineSections_2.next()) {
|
|
8841
|
+
var section = pipelineSections_2_1.value;
|
|
8782
8842
|
_loop_2(section);
|
|
8783
8843
|
}
|
|
8784
8844
|
}
|
|
8785
|
-
catch (
|
|
8845
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
8786
8846
|
finally {
|
|
8787
8847
|
try {
|
|
8788
|
-
if (
|
|
8848
|
+
if (pipelineSections_2_1 && !pipelineSections_2_1.done && (_c = pipelineSections_2.return)) _c.call(pipelineSections_2);
|
|
8789
8849
|
}
|
|
8790
|
-
finally { if (
|
|
8850
|
+
finally { if (e_3) throw e_3.error; }
|
|
8791
8851
|
}
|
|
8792
8852
|
// =============================================================
|
|
8793
|
-
// Note:
|
|
8853
|
+
// Note: 6️⃣ Mark parameters as INPUT if not explicitly set
|
|
8794
8854
|
if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isInput; })) {
|
|
8795
8855
|
var _loop_3 = function (parameter) {
|
|
8796
8856
|
var isThisParameterResulting = $pipelineJson.tasks.some(function (task) { return task.resultingParameterName === parameter.name; });
|
|
@@ -8799,42 +8859,42 @@
|
|
|
8799
8859
|
}
|
|
8800
8860
|
};
|
|
8801
8861
|
try {
|
|
8802
|
-
for (var
|
|
8803
|
-
var parameter =
|
|
8862
|
+
for (var _h = __values($pipelineJson.parameters), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
8863
|
+
var parameter = _j.value;
|
|
8804
8864
|
_loop_3(parameter);
|
|
8805
8865
|
}
|
|
8806
8866
|
}
|
|
8807
|
-
catch (
|
|
8867
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
8808
8868
|
finally {
|
|
8809
8869
|
try {
|
|
8810
|
-
if (
|
|
8870
|
+
if (_j && !_j.done && (_d = _h.return)) _d.call(_h);
|
|
8811
8871
|
}
|
|
8812
|
-
finally { if (
|
|
8872
|
+
finally { if (e_4) throw e_4.error; }
|
|
8813
8873
|
}
|
|
8814
8874
|
}
|
|
8815
8875
|
// =============================================================
|
|
8816
|
-
// Note:
|
|
8876
|
+
// Note: 7️⃣ Mark all non-INPUT parameters as OUTPUT if any OUTPUT is not set
|
|
8817
8877
|
if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isOutput; })) {
|
|
8818
8878
|
try {
|
|
8819
|
-
for (var
|
|
8820
|
-
var parameter =
|
|
8879
|
+
for (var _k = __values($pipelineJson.parameters), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
8880
|
+
var parameter = _l.value;
|
|
8821
8881
|
if (!parameter.isInput) {
|
|
8822
8882
|
parameter.isOutput = true;
|
|
8823
8883
|
}
|
|
8824
8884
|
}
|
|
8825
8885
|
}
|
|
8826
|
-
catch (
|
|
8886
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
8827
8887
|
finally {
|
|
8828
8888
|
try {
|
|
8829
|
-
if (
|
|
8889
|
+
if (_l && !_l.done && (_e = _k.return)) _e.call(_k);
|
|
8830
8890
|
}
|
|
8831
|
-
finally { if (
|
|
8891
|
+
finally { if (e_5) throw e_5.error; }
|
|
8832
8892
|
}
|
|
8833
8893
|
}
|
|
8834
8894
|
// =============================================================
|
|
8835
|
-
// Note:
|
|
8895
|
+
// Note: 8️⃣ Cleanup of undefined values
|
|
8836
8896
|
$pipelineJson.tasks.forEach(function (tasks) {
|
|
8837
|
-
var
|
|
8897
|
+
var e_8, _a;
|
|
8838
8898
|
try {
|
|
8839
8899
|
for (var _b = __values(Object.entries(tasks)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8840
8900
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8843,16 +8903,16 @@
|
|
|
8843
8903
|
}
|
|
8844
8904
|
}
|
|
8845
8905
|
}
|
|
8846
|
-
catch (
|
|
8906
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
8847
8907
|
finally {
|
|
8848
8908
|
try {
|
|
8849
8909
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8850
8910
|
}
|
|
8851
|
-
finally { if (
|
|
8911
|
+
finally { if (e_8) throw e_8.error; }
|
|
8852
8912
|
}
|
|
8853
8913
|
});
|
|
8854
8914
|
$pipelineJson.parameters.forEach(function (parameter) {
|
|
8855
|
-
var
|
|
8915
|
+
var e_9, _a;
|
|
8856
8916
|
try {
|
|
8857
8917
|
for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8858
8918
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8861,12 +8921,12 @@
|
|
|
8861
8921
|
}
|
|
8862
8922
|
}
|
|
8863
8923
|
}
|
|
8864
|
-
catch (
|
|
8924
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
8865
8925
|
finally {
|
|
8866
8926
|
try {
|
|
8867
8927
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8868
8928
|
}
|
|
8869
|
-
finally { if (
|
|
8929
|
+
finally { if (e_9) throw e_9.error; }
|
|
8870
8930
|
}
|
|
8871
8931
|
});
|
|
8872
8932
|
// =============================================================
|
|
@@ -8939,18 +8999,19 @@
|
|
|
8939
8999
|
var warningLine = "<!-- ".concat(GENERATOR_WARNING, " -->");
|
|
8940
9000
|
var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
|
|
8941
9001
|
var sectionMatch = content.match(sectionRegex);
|
|
9002
|
+
var contentToInsert = spaceTrim.spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); });
|
|
8942
9003
|
if (sectionMatch) {
|
|
8943
|
-
return content.replace(sectionRegex,
|
|
9004
|
+
return content.replace(sectionRegex, contentToInsert);
|
|
8944
9005
|
}
|
|
9006
|
+
// Note: Following is the case when the section is not found in the file so we add it there
|
|
8945
9007
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
8946
|
-
if (
|
|
8947
|
-
|
|
8948
|
-
|
|
8949
|
-
|
|
8950
|
-
|
|
8951
|
-
|
|
8952
|
-
|
|
8953
|
-
return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
|
|
9008
|
+
if (placeForSection !== null) {
|
|
9009
|
+
var _a = __read(placeForSection, 1), heading_1 = _a[0];
|
|
9010
|
+
return content.replace(heading_1, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(contentToInsert), "\n \n ").concat(block(heading_1), "\n "); }));
|
|
9011
|
+
}
|
|
9012
|
+
console.warn("No place where to put the section <!--".concat(sectionName, "-->, using the end of the file"));
|
|
9013
|
+
// <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
|
|
9014
|
+
return spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(content), "\n \n ").concat(block(contentToInsert), "\n "); });
|
|
8954
9015
|
}
|
|
8955
9016
|
/**
|
|
8956
9017
|
* TODO: [🏛] This can be part of markdown builder
|
|
@@ -8978,7 +9039,7 @@
|
|
|
8978
9039
|
if (!task) {
|
|
8979
9040
|
throw new Error("Could not find task for {".concat(parameterName, "}"));
|
|
8980
9041
|
}
|
|
8981
|
-
return normalizeTo_camelCase('task-' + titleToName(task.title));
|
|
9042
|
+
return task.name || normalizeTo_camelCase('task-' + titleToName(task.title));
|
|
8982
9043
|
};
|
|
8983
9044
|
var promptbookMermaid = spaceTrim.spaceTrim(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
|
|
8984
9045
|
.flatMap(function (_a) {
|
|
@@ -9041,7 +9102,7 @@
|
|
|
9041
9102
|
return { href: "#".concat(task.name), title: task.title };
|
|
9042
9103
|
},
|
|
9043
9104
|
});
|
|
9044
|
-
promptbookMermaidBlock = spaceTrim.spaceTrim(function (block) { return "\n
|
|
9105
|
+
promptbookMermaidBlock = spaceTrim.spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
|
|
9045
9106
|
pipelineString = addAutoGeneratedSection(pipelineString, {
|
|
9046
9107
|
sectionName: 'Graph',
|
|
9047
9108
|
sectionContent: promptbookMermaidBlock,
|
|
@@ -9061,6 +9122,115 @@
|
|
|
9061
9122
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
9062
9123
|
*/
|
|
9063
9124
|
|
|
9125
|
+
/**
|
|
9126
|
+
* Function `removePipelineCommand` will remove one command from pipeline string
|
|
9127
|
+
*
|
|
9128
|
+
* @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
|
|
9129
|
+
*/
|
|
9130
|
+
function removePipelineCommand(options) {
|
|
9131
|
+
var e_1, _a;
|
|
9132
|
+
var command = options.command, pipeline = options.pipeline;
|
|
9133
|
+
var lines = pipeline.split('\n');
|
|
9134
|
+
// TODO: [🧽] DRY
|
|
9135
|
+
var currentType = 'MARKDOWN';
|
|
9136
|
+
var newLines = [];
|
|
9137
|
+
try {
|
|
9138
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
9139
|
+
var line = lines_1_1.value;
|
|
9140
|
+
if (currentType === 'MARKDOWN') {
|
|
9141
|
+
if (line.startsWith('```')) {
|
|
9142
|
+
currentType = 'CODE_BLOCK';
|
|
9143
|
+
}
|
|
9144
|
+
else if (line.includes('<!--')) {
|
|
9145
|
+
currentType = 'COMMENT';
|
|
9146
|
+
}
|
|
9147
|
+
}
|
|
9148
|
+
else if (currentType === 'CODE_BLOCK') {
|
|
9149
|
+
if (line.startsWith('```')) {
|
|
9150
|
+
currentType = 'MARKDOWN';
|
|
9151
|
+
}
|
|
9152
|
+
}
|
|
9153
|
+
else if (currentType === 'COMMENT') {
|
|
9154
|
+
if (line.includes('-->')) {
|
|
9155
|
+
currentType = 'MARKDOWN';
|
|
9156
|
+
}
|
|
9157
|
+
}
|
|
9158
|
+
if (currentType === 'MARKDOWN' && /^(-|\d\))/m.test(line) && line.toUpperCase().includes(command)) {
|
|
9159
|
+
continue;
|
|
9160
|
+
}
|
|
9161
|
+
newLines.push(line);
|
|
9162
|
+
}
|
|
9163
|
+
}
|
|
9164
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
9165
|
+
finally {
|
|
9166
|
+
try {
|
|
9167
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
9168
|
+
}
|
|
9169
|
+
finally { if (e_1) throw e_1.error; }
|
|
9170
|
+
}
|
|
9171
|
+
var newPipeline = spaceTrim__default["default"](newLines.join('\n'));
|
|
9172
|
+
return newPipeline;
|
|
9173
|
+
}
|
|
9174
|
+
|
|
9175
|
+
/**
|
|
9176
|
+
* Function `renamePipelineParameter` will find all usable parameters for given task
|
|
9177
|
+
* In other words, it will find all parameters that are not used in the task itseld and all its dependencies
|
|
9178
|
+
*
|
|
9179
|
+
* @throws {PipelineLogicError} If the new parameter name is already used in the pipeline
|
|
9180
|
+
* @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
|
|
9181
|
+
*/
|
|
9182
|
+
function renamePipelineParameter(options) {
|
|
9183
|
+
var e_1, _a, e_2, _b;
|
|
9184
|
+
var pipeline = options.pipeline, oldParameterName = options.oldParameterName, newParameterName = options.newParameterName;
|
|
9185
|
+
if (pipeline.parameters.some(function (parameter) { return parameter.name === newParameterName; })) {
|
|
9186
|
+
throw new PipelineLogicError("Can not replace {".concat(oldParameterName, "} to {").concat(newParameterName, "} because {").concat(newParameterName, "} is already used in the pipeline"));
|
|
9187
|
+
}
|
|
9188
|
+
var renamedPipeline = __assign(__assign({}, pipeline), {
|
|
9189
|
+
// <- TODO: [🪓] This should be without `as $PipelineJson`
|
|
9190
|
+
parameters: __spreadArray([], __read(pipeline.parameters), false), tasks: __spreadArray([], __read(pipeline.tasks), false) });
|
|
9191
|
+
try {
|
|
9192
|
+
for (var _c = __values(renamedPipeline.parameters), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
9193
|
+
var parameter = _d.value;
|
|
9194
|
+
if (parameter.name !== oldParameterName) {
|
|
9195
|
+
continue;
|
|
9196
|
+
}
|
|
9197
|
+
parameter.name = newParameterName;
|
|
9198
|
+
}
|
|
9199
|
+
}
|
|
9200
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
9201
|
+
finally {
|
|
9202
|
+
try {
|
|
9203
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
9204
|
+
}
|
|
9205
|
+
finally { if (e_1) throw e_1.error; }
|
|
9206
|
+
}
|
|
9207
|
+
try {
|
|
9208
|
+
for (var _e = __values(renamedPipeline.tasks), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
9209
|
+
var task = _f.value;
|
|
9210
|
+
if (task.resultingParameterName === oldParameterName) {
|
|
9211
|
+
task.resultingParameterName = newParameterName;
|
|
9212
|
+
}
|
|
9213
|
+
task.dependentParameterNames = task.dependentParameterNames.map(function (dependentParameterName) {
|
|
9214
|
+
return dependentParameterName === oldParameterName ? newParameterName : dependentParameterName;
|
|
9215
|
+
});
|
|
9216
|
+
task.content = task.content.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
9217
|
+
task.title = task.title.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
9218
|
+
task.description =
|
|
9219
|
+
task.description === undefined
|
|
9220
|
+
? undefined
|
|
9221
|
+
: task.description.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
9222
|
+
}
|
|
9223
|
+
}
|
|
9224
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
9225
|
+
finally {
|
|
9226
|
+
try {
|
|
9227
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
9228
|
+
}
|
|
9229
|
+
finally { if (e_2) throw e_2.error; }
|
|
9230
|
+
}
|
|
9231
|
+
return renamedPipeline;
|
|
9232
|
+
}
|
|
9233
|
+
|
|
9064
9234
|
/**
|
|
9065
9235
|
* Tests if the value is [🚉] serializable as JSON
|
|
9066
9236
|
*
|
|
@@ -10656,7 +10826,6 @@
|
|
|
10656
10826
|
exports.DEFAULT_REMOTE_URL_PATH = DEFAULT_REMOTE_URL_PATH;
|
|
10657
10827
|
exports.DEFAULT_SCRAPE_CACHE_DIRNAME = DEFAULT_SCRAPE_CACHE_DIRNAME;
|
|
10658
10828
|
exports.DEFAULT_TITLE = DEFAULT_TITLE;
|
|
10659
|
-
exports.ERRORS = ERRORS;
|
|
10660
10829
|
exports.EXPECTATION_UNITS = EXPECTATION_UNITS;
|
|
10661
10830
|
exports.EnvironmentMismatchError = EnvironmentMismatchError;
|
|
10662
10831
|
exports.ExecutionReportStringOptionsDefaults = ExecutionReportStringOptionsDefaults;
|
|
@@ -10681,6 +10850,7 @@
|
|
|
10681
10850
|
exports.NotFoundError = NotFoundError;
|
|
10682
10851
|
exports.NotYetImplementedError = NotYetImplementedError;
|
|
10683
10852
|
exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
|
|
10853
|
+
exports.PROMPTBOOK_ERRORS = PROMPTBOOK_ERRORS;
|
|
10684
10854
|
exports.ParseError = ParseError;
|
|
10685
10855
|
exports.PipelineExecutionError = PipelineExecutionError;
|
|
10686
10856
|
exports.PipelineLogicError = PipelineLogicError;
|
|
@@ -10719,6 +10889,7 @@
|
|
|
10719
10889
|
exports.createSubcollection = createSubcollection;
|
|
10720
10890
|
exports.embeddingVectorToString = embeddingVectorToString;
|
|
10721
10891
|
exports.executionReportJsonToString = executionReportJsonToString;
|
|
10892
|
+
exports.extractParameterNamesFromTask = extractParameterNamesFromTask;
|
|
10722
10893
|
exports.getPipelineInterface = getPipelineInterface;
|
|
10723
10894
|
exports.isPassingExpectations = isPassingExpectations;
|
|
10724
10895
|
exports.isPipelineImplementingInterface = isPipelineImplementingInterface;
|
|
@@ -10735,6 +10906,8 @@
|
|
|
10735
10906
|
exports.preparePipeline = preparePipeline;
|
|
10736
10907
|
exports.prepareTasks = prepareTasks;
|
|
10737
10908
|
exports.prettifyPipelineString = prettifyPipelineString;
|
|
10909
|
+
exports.removePipelineCommand = removePipelineCommand;
|
|
10910
|
+
exports.renamePipelineParameter = renamePipelineParameter;
|
|
10738
10911
|
exports.stringifyPipelineJson = stringifyPipelineJson;
|
|
10739
10912
|
exports.unpreparePipeline = unpreparePipeline;
|
|
10740
10913
|
exports.usageToHuman = usageToHuman;
|