@promptbook/cli 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/bin/promptbook-cli.js +3 -1
- package/esm/index.es.js +90 -24
- package/esm/index.es.js.map +1 -1
- package/package.json +3 -3
- package/umd/index.umd.js +90 -24
- package/umd/index.umd.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/cli",
|
|
3
|
-
"version": "0.74.0-
|
|
3
|
+
"version": "0.74.0-8",
|
|
4
4
|
"description": "Supercharge your use of large language models",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"waitasecond": "1.11.83"
|
|
72
72
|
},
|
|
73
73
|
"bin": {
|
|
74
|
-
"promptbook": "
|
|
75
|
-
"ptbk": "
|
|
74
|
+
"promptbook": "bin/promptbook-cli.js",
|
|
75
|
+
"ptbk": "bin/promptbook-cli.js"
|
|
76
76
|
}
|
|
77
77
|
}
|
package/umd/index.umd.js
CHANGED
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
*
|
|
50
50
|
* @see https://github.com/webgptorg/promptbook
|
|
51
51
|
*/
|
|
52
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.74.0-
|
|
52
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.74.0-7';
|
|
53
53
|
/**
|
|
54
54
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
55
55
|
*/
|
|
@@ -3211,10 +3211,12 @@
|
|
|
3211
3211
|
* @public exported from `@promptbook/utils`
|
|
3212
3212
|
*/
|
|
3213
3213
|
function countPages(text) {
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3214
|
+
if (text === '') {
|
|
3215
|
+
return 0;
|
|
3216
|
+
}
|
|
3217
|
+
var pagesByLinesCount = Math.ceil(countLines(text) / 44);
|
|
3218
|
+
var pagesByCharactersCount = Math.ceil(countCharacters(text) / 2772);
|
|
3219
|
+
return Math.max(pagesByLinesCount, pagesByCharactersCount);
|
|
3218
3220
|
}
|
|
3219
3221
|
|
|
3220
3222
|
/**
|
|
@@ -7938,7 +7940,7 @@
|
|
|
7938
7940
|
* @public exported from `@promptbook/core`
|
|
7939
7941
|
*/
|
|
7940
7942
|
function pipelineStringToJsonSync(pipelineString) {
|
|
7941
|
-
var e_1, _a, e_2, _b;
|
|
7943
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
7942
7944
|
var $pipelineJson = {
|
|
7943
7945
|
title: undefined /* <- Note: [🍙] Putting here placeholder to keep `title` on top at final JSON */,
|
|
7944
7946
|
pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
|
|
@@ -7966,7 +7968,7 @@
|
|
|
7966
7968
|
// =============================================================
|
|
7967
7969
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
7968
7970
|
if (pipelineString.startsWith('#!')) {
|
|
7969
|
-
var
|
|
7971
|
+
var _e = __read(pipelineString.split('\n')), shebangLine_1 = _e[0], restLines = _e.slice(1);
|
|
7970
7972
|
if (!(shebangLine_1 || '').includes('ptbk')) {
|
|
7971
7973
|
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 "); }));
|
|
7972
7974
|
}
|
|
@@ -7976,7 +7978,7 @@
|
|
|
7976
7978
|
pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
|
|
7977
7979
|
pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
7978
7980
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
7979
|
-
var
|
|
7981
|
+
var _f = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _f[0], pipelineSections = _f.slice(1); /* <- Note: [🥞] */
|
|
7980
7982
|
if (pipelineHead === undefined) {
|
|
7981
7983
|
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 "); }));
|
|
7982
7984
|
}
|
|
@@ -8004,6 +8006,8 @@
|
|
|
8004
8006
|
if (parameterDescription) {
|
|
8005
8007
|
existingParameter.description = parameterDescription;
|
|
8006
8008
|
}
|
|
8009
|
+
existingParameter.isInput = existingParameter.isInput || isInput;
|
|
8010
|
+
existingParameter.isOutput = existingParameter.isOutput || isOutput;
|
|
8007
8011
|
}
|
|
8008
8012
|
else {
|
|
8009
8013
|
$pipelineJson.parameters.push({
|
|
@@ -8066,10 +8070,10 @@
|
|
|
8066
8070
|
finally { if (e_1) throw e_1.error; }
|
|
8067
8071
|
}
|
|
8068
8072
|
var _loop_2 = function (section) {
|
|
8069
|
-
var
|
|
8073
|
+
var e_5, _l, e_6, _m;
|
|
8070
8074
|
// TODO: Parse template description (the content out of the codeblock and lists)
|
|
8071
8075
|
var listItems_2 = extractAllListItemsFromMarkdown(section.content);
|
|
8072
|
-
var
|
|
8076
|
+
var _o = extractOneBlockFromMarkdown(section.content), language = _o.language, content = _o.content;
|
|
8073
8077
|
// TODO: [🎾][1] DRY description
|
|
8074
8078
|
var description_1 = section.content;
|
|
8075
8079
|
// Note: Remove codeblocks - TODO: [🎾]
|
|
@@ -8110,7 +8114,7 @@
|
|
|
8110
8114
|
}) === false) {
|
|
8111
8115
|
templateCommandParser.$applyToTemplateJson({ type: 'TEMPLATE', templateType: 'PROMPT_TEMPLATE' }, $templateJson, $pipelineJson);
|
|
8112
8116
|
}
|
|
8113
|
-
var
|
|
8117
|
+
var _loop_4 = function (listItem, command) {
|
|
8114
8118
|
var commandParser = getParserForCommand(command);
|
|
8115
8119
|
if (commandParser.isUsedInPipelineTemplate !== true /* <- Note: [🦦][4] */) {
|
|
8116
8120
|
throw new ParseError(spaceTrim.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: [🚞]
|
|
@@ -8133,17 +8137,17 @@
|
|
|
8133
8137
|
};
|
|
8134
8138
|
try {
|
|
8135
8139
|
// TODO [♓️] List commands and before apply order them to achieve order-agnostic commands
|
|
8136
|
-
for (var commands_1 = (
|
|
8137
|
-
var
|
|
8138
|
-
|
|
8140
|
+
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()) {
|
|
8141
|
+
var _p = commands_1_1.value, listItem = _p.listItem, command = _p.command;
|
|
8142
|
+
_loop_4(listItem, command);
|
|
8139
8143
|
}
|
|
8140
8144
|
}
|
|
8141
|
-
catch (
|
|
8145
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
8142
8146
|
finally {
|
|
8143
8147
|
try {
|
|
8144
|
-
if (commands_1_1 && !commands_1_1.done && (
|
|
8148
|
+
if (commands_1_1 && !commands_1_1.done && (_l = commands_1.return)) _l.call(commands_1);
|
|
8145
8149
|
}
|
|
8146
|
-
finally { if (
|
|
8150
|
+
finally { if (e_5) throw e_5.error; }
|
|
8147
8151
|
}
|
|
8148
8152
|
// TODO: [🍧] Should be done in TEMPLATE command
|
|
8149
8153
|
if ($templateJson.templateType === 'SCRIPT_TEMPLATE') {
|
|
@@ -8157,6 +8161,26 @@
|
|
|
8157
8161
|
language;
|
|
8158
8162
|
}
|
|
8159
8163
|
$templateJson.dependentParameterNames = Array.from(extractParameterNamesFromTemplate($templateJson));
|
|
8164
|
+
try {
|
|
8165
|
+
for (var _q = (e_6 = void 0, __values($templateJson.dependentParameterNames)), _r = _q.next(); !_r.done; _r = _q.next()) {
|
|
8166
|
+
var parameterName = _r.value;
|
|
8167
|
+
// TODO: [🧠] This definition should be made first in the template
|
|
8168
|
+
defineParam({
|
|
8169
|
+
parameterName: parameterName,
|
|
8170
|
+
parameterDescription: null,
|
|
8171
|
+
isInput: false,
|
|
8172
|
+
isOutput: false,
|
|
8173
|
+
// <- 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
|
|
8174
|
+
});
|
|
8175
|
+
}
|
|
8176
|
+
}
|
|
8177
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
8178
|
+
finally {
|
|
8179
|
+
try {
|
|
8180
|
+
if (_r && !_r.done && (_m = _q.return)) _m.call(_q);
|
|
8181
|
+
}
|
|
8182
|
+
finally { if (e_6) throw e_6.error; }
|
|
8183
|
+
}
|
|
8160
8184
|
/*
|
|
8161
8185
|
// TODO: [🍧] This should be checked in `MODEL` command + better error message
|
|
8162
8186
|
if ($templateJson.templateType !== 'PROMPT_TEMPLATE' && $templateJson.modelRequirements !== undefined) {
|
|
@@ -8198,9 +8222,51 @@
|
|
|
8198
8222
|
finally { if (e_2) throw e_2.error; }
|
|
8199
8223
|
}
|
|
8200
8224
|
// =============================================================
|
|
8201
|
-
// Note: 5️⃣
|
|
8225
|
+
// Note: 5️⃣ Mark parameters as INPUT if not explicitly set
|
|
8226
|
+
if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isInput; })) {
|
|
8227
|
+
var _loop_3 = function (parameter) {
|
|
8228
|
+
var isThisParameterResulting = $pipelineJson.templates.some(function (template) { return template.resultingParameterName === parameter.name; });
|
|
8229
|
+
if (!isThisParameterResulting) {
|
|
8230
|
+
parameter.isInput = true;
|
|
8231
|
+
}
|
|
8232
|
+
};
|
|
8233
|
+
try {
|
|
8234
|
+
for (var _g = __values($pipelineJson.parameters), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
8235
|
+
var parameter = _h.value;
|
|
8236
|
+
_loop_3(parameter);
|
|
8237
|
+
}
|
|
8238
|
+
}
|
|
8239
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
8240
|
+
finally {
|
|
8241
|
+
try {
|
|
8242
|
+
if (_h && !_h.done && (_c = _g.return)) _c.call(_g);
|
|
8243
|
+
}
|
|
8244
|
+
finally { if (e_3) throw e_3.error; }
|
|
8245
|
+
}
|
|
8246
|
+
}
|
|
8247
|
+
// =============================================================
|
|
8248
|
+
// Note: 6️⃣ Mark all non-INPUT parameters as OUTPUT if any OUTPUT is not set
|
|
8249
|
+
if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isOutput; })) {
|
|
8250
|
+
try {
|
|
8251
|
+
for (var _j = __values($pipelineJson.parameters), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
8252
|
+
var parameter = _k.value;
|
|
8253
|
+
if (!parameter.isInput) {
|
|
8254
|
+
parameter.isOutput = true;
|
|
8255
|
+
}
|
|
8256
|
+
}
|
|
8257
|
+
}
|
|
8258
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
8259
|
+
finally {
|
|
8260
|
+
try {
|
|
8261
|
+
if (_k && !_k.done && (_d = _j.return)) _d.call(_j);
|
|
8262
|
+
}
|
|
8263
|
+
finally { if (e_4) throw e_4.error; }
|
|
8264
|
+
}
|
|
8265
|
+
}
|
|
8266
|
+
// =============================================================
|
|
8267
|
+
// Note: 7️⃣ Cleanup of undefined values
|
|
8202
8268
|
$pipelineJson.templates.forEach(function (templates) {
|
|
8203
|
-
var
|
|
8269
|
+
var e_7, _a;
|
|
8204
8270
|
try {
|
|
8205
8271
|
for (var _b = __values(Object.entries(templates)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8206
8272
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8209,16 +8275,16 @@
|
|
|
8209
8275
|
}
|
|
8210
8276
|
}
|
|
8211
8277
|
}
|
|
8212
|
-
catch (
|
|
8278
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
8213
8279
|
finally {
|
|
8214
8280
|
try {
|
|
8215
8281
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8216
8282
|
}
|
|
8217
|
-
finally { if (
|
|
8283
|
+
finally { if (e_7) throw e_7.error; }
|
|
8218
8284
|
}
|
|
8219
8285
|
});
|
|
8220
8286
|
$pipelineJson.parameters.forEach(function (parameter) {
|
|
8221
|
-
var
|
|
8287
|
+
var e_8, _a;
|
|
8222
8288
|
try {
|
|
8223
8289
|
for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8224
8290
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8227,12 +8293,12 @@
|
|
|
8227
8293
|
}
|
|
8228
8294
|
}
|
|
8229
8295
|
}
|
|
8230
|
-
catch (
|
|
8296
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
8231
8297
|
finally {
|
|
8232
8298
|
try {
|
|
8233
8299
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8234
8300
|
}
|
|
8235
|
-
finally { if (
|
|
8301
|
+
finally { if (e_8) throw e_8.error; }
|
|
8236
8302
|
}
|
|
8237
8303
|
});
|
|
8238
8304
|
// =============================================================
|