@promptbook/core 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 +1 -1
- package/umd/index.umd.js +90 -24
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -22,7 +22,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
22
22
|
*
|
|
23
23
|
* @see https://github.com/webgptorg/promptbook
|
|
24
24
|
*/
|
|
25
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.74.0-
|
|
25
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.74.0-7';
|
|
26
26
|
/**
|
|
27
27
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
28
28
|
*/
|
|
@@ -3324,10 +3324,12 @@ function countLines(text) {
|
|
|
3324
3324
|
* @public exported from `@promptbook/utils`
|
|
3325
3325
|
*/
|
|
3326
3326
|
function countPages(text) {
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3327
|
+
if (text === '') {
|
|
3328
|
+
return 0;
|
|
3329
|
+
}
|
|
3330
|
+
var pagesByLinesCount = Math.ceil(countLines(text) / 44);
|
|
3331
|
+
var pagesByCharactersCount = Math.ceil(countCharacters(text) / 2772);
|
|
3332
|
+
return Math.max(pagesByLinesCount, pagesByCharactersCount);
|
|
3331
3333
|
}
|
|
3332
3334
|
|
|
3333
3335
|
/**
|
|
@@ -8055,7 +8057,7 @@ function titleToName(value) {
|
|
|
8055
8057
|
* @public exported from `@promptbook/core`
|
|
8056
8058
|
*/
|
|
8057
8059
|
function pipelineStringToJsonSync(pipelineString) {
|
|
8058
|
-
var e_1, _a, e_2, _b;
|
|
8060
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
8059
8061
|
var $pipelineJson = {
|
|
8060
8062
|
title: undefined /* <- Note: [🍙] Putting here placeholder to keep `title` on top at final JSON */,
|
|
8061
8063
|
pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
|
|
@@ -8083,7 +8085,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8083
8085
|
// =============================================================
|
|
8084
8086
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
8085
8087
|
if (pipelineString.startsWith('#!')) {
|
|
8086
|
-
var
|
|
8088
|
+
var _e = __read(pipelineString.split('\n')), shebangLine_1 = _e[0], restLines = _e.slice(1);
|
|
8087
8089
|
if (!(shebangLine_1 || '').includes('ptbk')) {
|
|
8088
8090
|
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 "); }));
|
|
8089
8091
|
}
|
|
@@ -8093,7 +8095,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8093
8095
|
pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
|
|
8094
8096
|
pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
8095
8097
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
8096
|
-
var
|
|
8098
|
+
var _f = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _f[0], pipelineSections = _f.slice(1); /* <- Note: [🥞] */
|
|
8097
8099
|
if (pipelineHead === undefined) {
|
|
8098
8100
|
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 "); }));
|
|
8099
8101
|
}
|
|
@@ -8121,6 +8123,8 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8121
8123
|
if (parameterDescription) {
|
|
8122
8124
|
existingParameter.description = parameterDescription;
|
|
8123
8125
|
}
|
|
8126
|
+
existingParameter.isInput = existingParameter.isInput || isInput;
|
|
8127
|
+
existingParameter.isOutput = existingParameter.isOutput || isOutput;
|
|
8124
8128
|
}
|
|
8125
8129
|
else {
|
|
8126
8130
|
$pipelineJson.parameters.push({
|
|
@@ -8183,10 +8187,10 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8183
8187
|
finally { if (e_1) throw e_1.error; }
|
|
8184
8188
|
}
|
|
8185
8189
|
var _loop_2 = function (section) {
|
|
8186
|
-
var
|
|
8190
|
+
var e_5, _l, e_6, _m;
|
|
8187
8191
|
// TODO: Parse template description (the content out of the codeblock and lists)
|
|
8188
8192
|
var listItems_2 = extractAllListItemsFromMarkdown(section.content);
|
|
8189
|
-
var
|
|
8193
|
+
var _o = extractOneBlockFromMarkdown(section.content), language = _o.language, content = _o.content;
|
|
8190
8194
|
// TODO: [🎾][1] DRY description
|
|
8191
8195
|
var description_1 = section.content;
|
|
8192
8196
|
// Note: Remove codeblocks - TODO: [🎾]
|
|
@@ -8227,7 +8231,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8227
8231
|
}) === false) {
|
|
8228
8232
|
templateCommandParser.$applyToTemplateJson({ type: 'TEMPLATE', templateType: 'PROMPT_TEMPLATE' }, $templateJson, $pipelineJson);
|
|
8229
8233
|
}
|
|
8230
|
-
var
|
|
8234
|
+
var _loop_4 = function (listItem, command) {
|
|
8231
8235
|
var commandParser = getParserForCommand(command);
|
|
8232
8236
|
if (commandParser.isUsedInPipelineTemplate !== true /* <- Note: [🦦][4] */) {
|
|
8233
8237
|
throw new ParseError(spaceTrim$1(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: [🚞]
|
|
@@ -8250,17 +8254,17 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8250
8254
|
};
|
|
8251
8255
|
try {
|
|
8252
8256
|
// TODO [♓️] List commands and before apply order them to achieve order-agnostic commands
|
|
8253
|
-
for (var commands_1 = (
|
|
8254
|
-
var
|
|
8255
|
-
|
|
8257
|
+
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()) {
|
|
8258
|
+
var _p = commands_1_1.value, listItem = _p.listItem, command = _p.command;
|
|
8259
|
+
_loop_4(listItem, command);
|
|
8256
8260
|
}
|
|
8257
8261
|
}
|
|
8258
|
-
catch (
|
|
8262
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
8259
8263
|
finally {
|
|
8260
8264
|
try {
|
|
8261
|
-
if (commands_1_1 && !commands_1_1.done && (
|
|
8265
|
+
if (commands_1_1 && !commands_1_1.done && (_l = commands_1.return)) _l.call(commands_1);
|
|
8262
8266
|
}
|
|
8263
|
-
finally { if (
|
|
8267
|
+
finally { if (e_5) throw e_5.error; }
|
|
8264
8268
|
}
|
|
8265
8269
|
// TODO: [🍧] Should be done in TEMPLATE command
|
|
8266
8270
|
if ($templateJson.templateType === 'SCRIPT_TEMPLATE') {
|
|
@@ -8274,6 +8278,26 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8274
8278
|
language;
|
|
8275
8279
|
}
|
|
8276
8280
|
$templateJson.dependentParameterNames = Array.from(extractParameterNamesFromTemplate($templateJson));
|
|
8281
|
+
try {
|
|
8282
|
+
for (var _q = (e_6 = void 0, __values($templateJson.dependentParameterNames)), _r = _q.next(); !_r.done; _r = _q.next()) {
|
|
8283
|
+
var parameterName = _r.value;
|
|
8284
|
+
// TODO: [🧠] This definition should be made first in the template
|
|
8285
|
+
defineParam({
|
|
8286
|
+
parameterName: parameterName,
|
|
8287
|
+
parameterDescription: null,
|
|
8288
|
+
isInput: false,
|
|
8289
|
+
isOutput: false,
|
|
8290
|
+
// <- 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
|
|
8291
|
+
});
|
|
8292
|
+
}
|
|
8293
|
+
}
|
|
8294
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
8295
|
+
finally {
|
|
8296
|
+
try {
|
|
8297
|
+
if (_r && !_r.done && (_m = _q.return)) _m.call(_q);
|
|
8298
|
+
}
|
|
8299
|
+
finally { if (e_6) throw e_6.error; }
|
|
8300
|
+
}
|
|
8277
8301
|
/*
|
|
8278
8302
|
// TODO: [🍧] This should be checked in `MODEL` command + better error message
|
|
8279
8303
|
if ($templateJson.templateType !== 'PROMPT_TEMPLATE' && $templateJson.modelRequirements !== undefined) {
|
|
@@ -8315,9 +8339,51 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8315
8339
|
finally { if (e_2) throw e_2.error; }
|
|
8316
8340
|
}
|
|
8317
8341
|
// =============================================================
|
|
8318
|
-
// Note: 5️⃣
|
|
8342
|
+
// Note: 5️⃣ Mark parameters as INPUT if not explicitly set
|
|
8343
|
+
if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isInput; })) {
|
|
8344
|
+
var _loop_3 = function (parameter) {
|
|
8345
|
+
var isThisParameterResulting = $pipelineJson.templates.some(function (template) { return template.resultingParameterName === parameter.name; });
|
|
8346
|
+
if (!isThisParameterResulting) {
|
|
8347
|
+
parameter.isInput = true;
|
|
8348
|
+
}
|
|
8349
|
+
};
|
|
8350
|
+
try {
|
|
8351
|
+
for (var _g = __values($pipelineJson.parameters), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
8352
|
+
var parameter = _h.value;
|
|
8353
|
+
_loop_3(parameter);
|
|
8354
|
+
}
|
|
8355
|
+
}
|
|
8356
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
8357
|
+
finally {
|
|
8358
|
+
try {
|
|
8359
|
+
if (_h && !_h.done && (_c = _g.return)) _c.call(_g);
|
|
8360
|
+
}
|
|
8361
|
+
finally { if (e_3) throw e_3.error; }
|
|
8362
|
+
}
|
|
8363
|
+
}
|
|
8364
|
+
// =============================================================
|
|
8365
|
+
// Note: 6️⃣ Mark all non-INPUT parameters as OUTPUT if any OUTPUT is not set
|
|
8366
|
+
if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isOutput; })) {
|
|
8367
|
+
try {
|
|
8368
|
+
for (var _j = __values($pipelineJson.parameters), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
8369
|
+
var parameter = _k.value;
|
|
8370
|
+
if (!parameter.isInput) {
|
|
8371
|
+
parameter.isOutput = true;
|
|
8372
|
+
}
|
|
8373
|
+
}
|
|
8374
|
+
}
|
|
8375
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
8376
|
+
finally {
|
|
8377
|
+
try {
|
|
8378
|
+
if (_k && !_k.done && (_d = _j.return)) _d.call(_j);
|
|
8379
|
+
}
|
|
8380
|
+
finally { if (e_4) throw e_4.error; }
|
|
8381
|
+
}
|
|
8382
|
+
}
|
|
8383
|
+
// =============================================================
|
|
8384
|
+
// Note: 7️⃣ Cleanup of undefined values
|
|
8319
8385
|
$pipelineJson.templates.forEach(function (templates) {
|
|
8320
|
-
var
|
|
8386
|
+
var e_7, _a;
|
|
8321
8387
|
try {
|
|
8322
8388
|
for (var _b = __values(Object.entries(templates)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8323
8389
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8326,16 +8392,16 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8326
8392
|
}
|
|
8327
8393
|
}
|
|
8328
8394
|
}
|
|
8329
|
-
catch (
|
|
8395
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
8330
8396
|
finally {
|
|
8331
8397
|
try {
|
|
8332
8398
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8333
8399
|
}
|
|
8334
|
-
finally { if (
|
|
8400
|
+
finally { if (e_7) throw e_7.error; }
|
|
8335
8401
|
}
|
|
8336
8402
|
});
|
|
8337
8403
|
$pipelineJson.parameters.forEach(function (parameter) {
|
|
8338
|
-
var
|
|
8404
|
+
var e_8, _a;
|
|
8339
8405
|
try {
|
|
8340
8406
|
for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8341
8407
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8344,12 +8410,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8344
8410
|
}
|
|
8345
8411
|
}
|
|
8346
8412
|
}
|
|
8347
|
-
catch (
|
|
8413
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
8348
8414
|
finally {
|
|
8349
8415
|
try {
|
|
8350
8416
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8351
8417
|
}
|
|
8352
|
-
finally { if (
|
|
8418
|
+
finally { if (e_8) throw e_8.error; }
|
|
8353
8419
|
}
|
|
8354
8420
|
});
|
|
8355
8421
|
// =============================================================
|