@promptbook/node 0.74.0-6 → 0.74.0-8
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/esm/index.es.js +96 -26
- package/esm/index.es.js.map +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +96 -26
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -26,7 +26,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
26
26
|
*
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.74.0-
|
|
29
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.74.0-7';
|
|
30
30
|
/**
|
|
31
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
32
32
|
*/
|
|
@@ -3004,10 +3004,12 @@ function countLines(text) {
|
|
|
3004
3004
|
* @public exported from `@promptbook/utils`
|
|
3005
3005
|
*/
|
|
3006
3006
|
function countPages(text) {
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3007
|
+
if (text === '') {
|
|
3008
|
+
return 0;
|
|
3009
|
+
}
|
|
3010
|
+
var pagesByLinesCount = Math.ceil(countLines(text) / 44);
|
|
3011
|
+
var pagesByCharactersCount = Math.ceil(countCharacters(text) / 2772);
|
|
3012
|
+
return Math.max(pagesByLinesCount, pagesByCharactersCount);
|
|
3011
3013
|
}
|
|
3012
3014
|
|
|
3013
3015
|
/**
|
|
@@ -7731,7 +7733,7 @@ function titleToName(value) {
|
|
|
7731
7733
|
* @public exported from `@promptbook/core`
|
|
7732
7734
|
*/
|
|
7733
7735
|
function pipelineStringToJsonSync(pipelineString) {
|
|
7734
|
-
var e_1, _a, e_2, _b;
|
|
7736
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
7735
7737
|
var $pipelineJson = {
|
|
7736
7738
|
title: undefined /* <- Note: [🍙] Putting here placeholder to keep `title` on top at final JSON */,
|
|
7737
7739
|
pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
|
|
@@ -7758,11 +7760,18 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7758
7760
|
}
|
|
7759
7761
|
// =============================================================
|
|
7760
7762
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
7763
|
+
if (pipelineString.startsWith('#!')) {
|
|
7764
|
+
var _e = __read(pipelineString.split('\n')), shebangLine_1 = _e[0], restLines = _e.slice(1);
|
|
7765
|
+
if (!(shebangLine_1 || '').includes('ptbk')) {
|
|
7766
|
+
throw new ParseError(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 "); }));
|
|
7767
|
+
}
|
|
7768
|
+
pipelineString = restLines.join('\n');
|
|
7769
|
+
}
|
|
7761
7770
|
pipelineString = removeContentComments(pipelineString);
|
|
7762
7771
|
pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
|
|
7763
7772
|
pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
7764
7773
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
7765
|
-
var
|
|
7774
|
+
var _f = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _f[0], pipelineSections = _f.slice(1); /* <- Note: [🥞] */
|
|
7766
7775
|
if (pipelineHead === undefined) {
|
|
7767
7776
|
throw new UnexpectedError(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 "); }));
|
|
7768
7777
|
}
|
|
@@ -7790,6 +7799,8 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7790
7799
|
if (parameterDescription) {
|
|
7791
7800
|
existingParameter.description = parameterDescription;
|
|
7792
7801
|
}
|
|
7802
|
+
existingParameter.isInput = existingParameter.isInput || isInput;
|
|
7803
|
+
existingParameter.isOutput = existingParameter.isOutput || isOutput;
|
|
7793
7804
|
}
|
|
7794
7805
|
else {
|
|
7795
7806
|
$pipelineJson.parameters.push({
|
|
@@ -7852,10 +7863,10 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7852
7863
|
finally { if (e_1) throw e_1.error; }
|
|
7853
7864
|
}
|
|
7854
7865
|
var _loop_2 = function (section) {
|
|
7855
|
-
var
|
|
7866
|
+
var e_5, _l, e_6, _m;
|
|
7856
7867
|
// TODO: Parse template description (the content out of the codeblock and lists)
|
|
7857
7868
|
var listItems_2 = extractAllListItemsFromMarkdown(section.content);
|
|
7858
|
-
var
|
|
7869
|
+
var _o = extractOneBlockFromMarkdown(section.content), language = _o.language, content = _o.content;
|
|
7859
7870
|
// TODO: [🎾][1] DRY description
|
|
7860
7871
|
var description_1 = section.content;
|
|
7861
7872
|
// Note: Remove codeblocks - TODO: [🎾]
|
|
@@ -7896,7 +7907,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7896
7907
|
}) === false) {
|
|
7897
7908
|
templateCommandParser.$applyToTemplateJson({ type: 'TEMPLATE', templateType: 'PROMPT_TEMPLATE' }, $templateJson, $pipelineJson);
|
|
7898
7909
|
}
|
|
7899
|
-
var
|
|
7910
|
+
var _loop_4 = function (listItem, command) {
|
|
7900
7911
|
var commandParser = getParserForCommand(command);
|
|
7901
7912
|
if (commandParser.isUsedInPipelineTemplate !== true /* <- Note: [🦦][4] */) {
|
|
7902
7913
|
throw new ParseError(spaceTrim(function (block) { return "\n Command ".concat(command.type, " is not allowed in the template of the promptbook ONLY at the pipeline head\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
|
|
@@ -7919,17 +7930,17 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7919
7930
|
};
|
|
7920
7931
|
try {
|
|
7921
7932
|
// TODO [♓️] List commands and before apply order them to achieve order-agnostic commands
|
|
7922
|
-
for (var commands_1 = (
|
|
7923
|
-
var
|
|
7924
|
-
|
|
7933
|
+
for (var commands_1 = (e_5 = void 0, __values(commands)), commands_1_1 = commands_1.next(); !commands_1_1.done; commands_1_1 = commands_1.next()) {
|
|
7934
|
+
var _p = commands_1_1.value, listItem = _p.listItem, command = _p.command;
|
|
7935
|
+
_loop_4(listItem, command);
|
|
7925
7936
|
}
|
|
7926
7937
|
}
|
|
7927
|
-
catch (
|
|
7938
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
7928
7939
|
finally {
|
|
7929
7940
|
try {
|
|
7930
|
-
if (commands_1_1 && !commands_1_1.done && (
|
|
7941
|
+
if (commands_1_1 && !commands_1_1.done && (_l = commands_1.return)) _l.call(commands_1);
|
|
7931
7942
|
}
|
|
7932
|
-
finally { if (
|
|
7943
|
+
finally { if (e_5) throw e_5.error; }
|
|
7933
7944
|
}
|
|
7934
7945
|
// TODO: [🍧] Should be done in TEMPLATE command
|
|
7935
7946
|
if ($templateJson.templateType === 'SCRIPT_TEMPLATE') {
|
|
@@ -7943,6 +7954,26 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7943
7954
|
language;
|
|
7944
7955
|
}
|
|
7945
7956
|
$templateJson.dependentParameterNames = Array.from(extractParameterNamesFromTemplate($templateJson));
|
|
7957
|
+
try {
|
|
7958
|
+
for (var _q = (e_6 = void 0, __values($templateJson.dependentParameterNames)), _r = _q.next(); !_r.done; _r = _q.next()) {
|
|
7959
|
+
var parameterName = _r.value;
|
|
7960
|
+
// TODO: [🧠] This definition should be made first in the template
|
|
7961
|
+
defineParam({
|
|
7962
|
+
parameterName: parameterName,
|
|
7963
|
+
parameterDescription: null,
|
|
7964
|
+
isInput: false,
|
|
7965
|
+
isOutput: false,
|
|
7966
|
+
// <- Note: In this case null+false+false means that we do not know yet if it is input or output and we will set it later
|
|
7967
|
+
});
|
|
7968
|
+
}
|
|
7969
|
+
}
|
|
7970
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
7971
|
+
finally {
|
|
7972
|
+
try {
|
|
7973
|
+
if (_r && !_r.done && (_m = _q.return)) _m.call(_q);
|
|
7974
|
+
}
|
|
7975
|
+
finally { if (e_6) throw e_6.error; }
|
|
7976
|
+
}
|
|
7946
7977
|
/*
|
|
7947
7978
|
// TODO: [🍧] This should be checked in `MODEL` command + better error message
|
|
7948
7979
|
if ($templateJson.templateType !== 'PROMPT_TEMPLATE' && $templateJson.modelRequirements !== undefined) {
|
|
@@ -7984,9 +8015,51 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7984
8015
|
finally { if (e_2) throw e_2.error; }
|
|
7985
8016
|
}
|
|
7986
8017
|
// =============================================================
|
|
7987
|
-
// Note: 5️⃣
|
|
8018
|
+
// Note: 5️⃣ Mark parameters as INPUT if not explicitly set
|
|
8019
|
+
if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isInput; })) {
|
|
8020
|
+
var _loop_3 = function (parameter) {
|
|
8021
|
+
var isThisParameterResulting = $pipelineJson.templates.some(function (template) { return template.resultingParameterName === parameter.name; });
|
|
8022
|
+
if (!isThisParameterResulting) {
|
|
8023
|
+
parameter.isInput = true;
|
|
8024
|
+
}
|
|
8025
|
+
};
|
|
8026
|
+
try {
|
|
8027
|
+
for (var _g = __values($pipelineJson.parameters), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
8028
|
+
var parameter = _h.value;
|
|
8029
|
+
_loop_3(parameter);
|
|
8030
|
+
}
|
|
8031
|
+
}
|
|
8032
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
8033
|
+
finally {
|
|
8034
|
+
try {
|
|
8035
|
+
if (_h && !_h.done && (_c = _g.return)) _c.call(_g);
|
|
8036
|
+
}
|
|
8037
|
+
finally { if (e_3) throw e_3.error; }
|
|
8038
|
+
}
|
|
8039
|
+
}
|
|
8040
|
+
// =============================================================
|
|
8041
|
+
// Note: 6️⃣ Mark all non-INPUT parameters as OUTPUT if any OUTPUT is not set
|
|
8042
|
+
if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isOutput; })) {
|
|
8043
|
+
try {
|
|
8044
|
+
for (var _j = __values($pipelineJson.parameters), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
8045
|
+
var parameter = _k.value;
|
|
8046
|
+
if (!parameter.isInput) {
|
|
8047
|
+
parameter.isOutput = true;
|
|
8048
|
+
}
|
|
8049
|
+
}
|
|
8050
|
+
}
|
|
8051
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
8052
|
+
finally {
|
|
8053
|
+
try {
|
|
8054
|
+
if (_k && !_k.done && (_d = _j.return)) _d.call(_j);
|
|
8055
|
+
}
|
|
8056
|
+
finally { if (e_4) throw e_4.error; }
|
|
8057
|
+
}
|
|
8058
|
+
}
|
|
8059
|
+
// =============================================================
|
|
8060
|
+
// Note: 7️⃣ Cleanup of undefined values
|
|
7988
8061
|
$pipelineJson.templates.forEach(function (templates) {
|
|
7989
|
-
var
|
|
8062
|
+
var e_7, _a;
|
|
7990
8063
|
try {
|
|
7991
8064
|
for (var _b = __values(Object.entries(templates)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
7992
8065
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -7995,16 +8068,16 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7995
8068
|
}
|
|
7996
8069
|
}
|
|
7997
8070
|
}
|
|
7998
|
-
catch (
|
|
8071
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
7999
8072
|
finally {
|
|
8000
8073
|
try {
|
|
8001
8074
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8002
8075
|
}
|
|
8003
|
-
finally { if (
|
|
8076
|
+
finally { if (e_7) throw e_7.error; }
|
|
8004
8077
|
}
|
|
8005
8078
|
});
|
|
8006
8079
|
$pipelineJson.parameters.forEach(function (parameter) {
|
|
8007
|
-
var
|
|
8080
|
+
var e_8, _a;
|
|
8008
8081
|
try {
|
|
8009
8082
|
for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8010
8083
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8013,12 +8086,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8013
8086
|
}
|
|
8014
8087
|
}
|
|
8015
8088
|
}
|
|
8016
|
-
catch (
|
|
8089
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
8017
8090
|
finally {
|
|
8018
8091
|
try {
|
|
8019
8092
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8020
8093
|
}
|
|
8021
|
-
finally { if (
|
|
8094
|
+
finally { if (e_8) throw e_8.error; }
|
|
8022
8095
|
}
|
|
8023
8096
|
});
|
|
8024
8097
|
// =============================================================
|
|
@@ -9797,12 +9870,9 @@ function $execCommandNormalizeOptions(options) {
|
|
|
9797
9870
|
})
|
|
9798
9871
|
.filter(function (arg) { return arg !== ''; });
|
|
9799
9872
|
if (_.length > 1) {
|
|
9800
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9801
9873
|
_a = __read(_), command = _a[0], args = _a.slice(1);
|
|
9802
9874
|
}
|
|
9803
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9804
9875
|
if (options.args) {
|
|
9805
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9806
9876
|
args = __spreadArray(__spreadArray([], __read(args), false), __read(options.args), false);
|
|
9807
9877
|
}
|
|
9808
9878
|
var humanReadableCommand = !['npx', 'npm'].includes(command) ? command : args[0];
|