@promptbook/node 0.74.0-7 → 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 +90 -24
- package/esm/index.es.js.map +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +90 -24
- 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 */,
|
|
@@ -7759,7 +7761,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7759
7761
|
// =============================================================
|
|
7760
7762
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
7761
7763
|
if (pipelineString.startsWith('#!')) {
|
|
7762
|
-
var
|
|
7764
|
+
var _e = __read(pipelineString.split('\n')), shebangLine_1 = _e[0], restLines = _e.slice(1);
|
|
7763
7765
|
if (!(shebangLine_1 || '').includes('ptbk')) {
|
|
7764
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 "); }));
|
|
7765
7767
|
}
|
|
@@ -7769,7 +7771,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7769
7771
|
pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
|
|
7770
7772
|
pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
7771
7773
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
7772
|
-
var
|
|
7774
|
+
var _f = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _f[0], pipelineSections = _f.slice(1); /* <- Note: [🥞] */
|
|
7773
7775
|
if (pipelineHead === undefined) {
|
|
7774
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 "); }));
|
|
7775
7777
|
}
|
|
@@ -7797,6 +7799,8 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7797
7799
|
if (parameterDescription) {
|
|
7798
7800
|
existingParameter.description = parameterDescription;
|
|
7799
7801
|
}
|
|
7802
|
+
existingParameter.isInput = existingParameter.isInput || isInput;
|
|
7803
|
+
existingParameter.isOutput = existingParameter.isOutput || isOutput;
|
|
7800
7804
|
}
|
|
7801
7805
|
else {
|
|
7802
7806
|
$pipelineJson.parameters.push({
|
|
@@ -7859,10 +7863,10 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7859
7863
|
finally { if (e_1) throw e_1.error; }
|
|
7860
7864
|
}
|
|
7861
7865
|
var _loop_2 = function (section) {
|
|
7862
|
-
var
|
|
7866
|
+
var e_5, _l, e_6, _m;
|
|
7863
7867
|
// TODO: Parse template description (the content out of the codeblock and lists)
|
|
7864
7868
|
var listItems_2 = extractAllListItemsFromMarkdown(section.content);
|
|
7865
|
-
var
|
|
7869
|
+
var _o = extractOneBlockFromMarkdown(section.content), language = _o.language, content = _o.content;
|
|
7866
7870
|
// TODO: [🎾][1] DRY description
|
|
7867
7871
|
var description_1 = section.content;
|
|
7868
7872
|
// Note: Remove codeblocks - TODO: [🎾]
|
|
@@ -7903,7 +7907,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7903
7907
|
}) === false) {
|
|
7904
7908
|
templateCommandParser.$applyToTemplateJson({ type: 'TEMPLATE', templateType: 'PROMPT_TEMPLATE' }, $templateJson, $pipelineJson);
|
|
7905
7909
|
}
|
|
7906
|
-
var
|
|
7910
|
+
var _loop_4 = function (listItem, command) {
|
|
7907
7911
|
var commandParser = getParserForCommand(command);
|
|
7908
7912
|
if (commandParser.isUsedInPipelineTemplate !== true /* <- Note: [🦦][4] */) {
|
|
7909
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: [🚞]
|
|
@@ -7926,17 +7930,17 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7926
7930
|
};
|
|
7927
7931
|
try {
|
|
7928
7932
|
// TODO [♓️] List commands and before apply order them to achieve order-agnostic commands
|
|
7929
|
-
for (var commands_1 = (
|
|
7930
|
-
var
|
|
7931
|
-
|
|
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);
|
|
7932
7936
|
}
|
|
7933
7937
|
}
|
|
7934
|
-
catch (
|
|
7938
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
7935
7939
|
finally {
|
|
7936
7940
|
try {
|
|
7937
|
-
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);
|
|
7938
7942
|
}
|
|
7939
|
-
finally { if (
|
|
7943
|
+
finally { if (e_5) throw e_5.error; }
|
|
7940
7944
|
}
|
|
7941
7945
|
// TODO: [🍧] Should be done in TEMPLATE command
|
|
7942
7946
|
if ($templateJson.templateType === 'SCRIPT_TEMPLATE') {
|
|
@@ -7950,6 +7954,26 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7950
7954
|
language;
|
|
7951
7955
|
}
|
|
7952
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
|
+
}
|
|
7953
7977
|
/*
|
|
7954
7978
|
// TODO: [🍧] This should be checked in `MODEL` command + better error message
|
|
7955
7979
|
if ($templateJson.templateType !== 'PROMPT_TEMPLATE' && $templateJson.modelRequirements !== undefined) {
|
|
@@ -7991,9 +8015,51 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
7991
8015
|
finally { if (e_2) throw e_2.error; }
|
|
7992
8016
|
}
|
|
7993
8017
|
// =============================================================
|
|
7994
|
-
// 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
|
|
7995
8061
|
$pipelineJson.templates.forEach(function (templates) {
|
|
7996
|
-
var
|
|
8062
|
+
var e_7, _a;
|
|
7997
8063
|
try {
|
|
7998
8064
|
for (var _b = __values(Object.entries(templates)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
7999
8065
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8002,16 +8068,16 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8002
8068
|
}
|
|
8003
8069
|
}
|
|
8004
8070
|
}
|
|
8005
|
-
catch (
|
|
8071
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
8006
8072
|
finally {
|
|
8007
8073
|
try {
|
|
8008
8074
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8009
8075
|
}
|
|
8010
|
-
finally { if (
|
|
8076
|
+
finally { if (e_7) throw e_7.error; }
|
|
8011
8077
|
}
|
|
8012
8078
|
});
|
|
8013
8079
|
$pipelineJson.parameters.forEach(function (parameter) {
|
|
8014
|
-
var
|
|
8080
|
+
var e_8, _a;
|
|
8015
8081
|
try {
|
|
8016
8082
|
for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8017
8083
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8020,12 +8086,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8020
8086
|
}
|
|
8021
8087
|
}
|
|
8022
8088
|
}
|
|
8023
|
-
catch (
|
|
8089
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
8024
8090
|
finally {
|
|
8025
8091
|
try {
|
|
8026
8092
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8027
8093
|
}
|
|
8028
|
-
finally { if (
|
|
8094
|
+
finally { if (e_8) throw e_8.error; }
|
|
8029
8095
|
}
|
|
8030
8096
|
});
|
|
8031
8097
|
// =============================================================
|