@promptbook/core 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 -23
- package/esm/index.es.js.map +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +96 -23
- 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 */,
|
|
@@ -8082,11 +8084,18 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8082
8084
|
}
|
|
8083
8085
|
// =============================================================
|
|
8084
8086
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
8087
|
+
if (pipelineString.startsWith('#!')) {
|
|
8088
|
+
var _e = __read(pipelineString.split('\n')), shebangLine_1 = _e[0], restLines = _e.slice(1);
|
|
8089
|
+
if (!(shebangLine_1 || '').includes('ptbk')) {
|
|
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 "); }));
|
|
8091
|
+
}
|
|
8092
|
+
pipelineString = restLines.join('\n');
|
|
8093
|
+
}
|
|
8085
8094
|
pipelineString = removeContentComments(pipelineString);
|
|
8086
8095
|
pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
|
|
8087
8096
|
pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
8088
8097
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
8089
|
-
var
|
|
8098
|
+
var _f = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _f[0], pipelineSections = _f.slice(1); /* <- Note: [🥞] */
|
|
8090
8099
|
if (pipelineHead === undefined) {
|
|
8091
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 "); }));
|
|
8092
8101
|
}
|
|
@@ -8114,6 +8123,8 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8114
8123
|
if (parameterDescription) {
|
|
8115
8124
|
existingParameter.description = parameterDescription;
|
|
8116
8125
|
}
|
|
8126
|
+
existingParameter.isInput = existingParameter.isInput || isInput;
|
|
8127
|
+
existingParameter.isOutput = existingParameter.isOutput || isOutput;
|
|
8117
8128
|
}
|
|
8118
8129
|
else {
|
|
8119
8130
|
$pipelineJson.parameters.push({
|
|
@@ -8176,10 +8187,10 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8176
8187
|
finally { if (e_1) throw e_1.error; }
|
|
8177
8188
|
}
|
|
8178
8189
|
var _loop_2 = function (section) {
|
|
8179
|
-
var
|
|
8190
|
+
var e_5, _l, e_6, _m;
|
|
8180
8191
|
// TODO: Parse template description (the content out of the codeblock and lists)
|
|
8181
8192
|
var listItems_2 = extractAllListItemsFromMarkdown(section.content);
|
|
8182
|
-
var
|
|
8193
|
+
var _o = extractOneBlockFromMarkdown(section.content), language = _o.language, content = _o.content;
|
|
8183
8194
|
// TODO: [🎾][1] DRY description
|
|
8184
8195
|
var description_1 = section.content;
|
|
8185
8196
|
// Note: Remove codeblocks - TODO: [🎾]
|
|
@@ -8220,7 +8231,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8220
8231
|
}) === false) {
|
|
8221
8232
|
templateCommandParser.$applyToTemplateJson({ type: 'TEMPLATE', templateType: 'PROMPT_TEMPLATE' }, $templateJson, $pipelineJson);
|
|
8222
8233
|
}
|
|
8223
|
-
var
|
|
8234
|
+
var _loop_4 = function (listItem, command) {
|
|
8224
8235
|
var commandParser = getParserForCommand(command);
|
|
8225
8236
|
if (commandParser.isUsedInPipelineTemplate !== true /* <- Note: [🦦][4] */) {
|
|
8226
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: [🚞]
|
|
@@ -8243,17 +8254,17 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8243
8254
|
};
|
|
8244
8255
|
try {
|
|
8245
8256
|
// TODO [♓️] List commands and before apply order them to achieve order-agnostic commands
|
|
8246
|
-
for (var commands_1 = (
|
|
8247
|
-
var
|
|
8248
|
-
|
|
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);
|
|
8249
8260
|
}
|
|
8250
8261
|
}
|
|
8251
|
-
catch (
|
|
8262
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
8252
8263
|
finally {
|
|
8253
8264
|
try {
|
|
8254
|
-
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);
|
|
8255
8266
|
}
|
|
8256
|
-
finally { if (
|
|
8267
|
+
finally { if (e_5) throw e_5.error; }
|
|
8257
8268
|
}
|
|
8258
8269
|
// TODO: [🍧] Should be done in TEMPLATE command
|
|
8259
8270
|
if ($templateJson.templateType === 'SCRIPT_TEMPLATE') {
|
|
@@ -8267,6 +8278,26 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8267
8278
|
language;
|
|
8268
8279
|
}
|
|
8269
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
|
+
}
|
|
8270
8301
|
/*
|
|
8271
8302
|
// TODO: [🍧] This should be checked in `MODEL` command + better error message
|
|
8272
8303
|
if ($templateJson.templateType !== 'PROMPT_TEMPLATE' && $templateJson.modelRequirements !== undefined) {
|
|
@@ -8308,9 +8339,51 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8308
8339
|
finally { if (e_2) throw e_2.error; }
|
|
8309
8340
|
}
|
|
8310
8341
|
// =============================================================
|
|
8311
|
-
// 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
|
|
8312
8385
|
$pipelineJson.templates.forEach(function (templates) {
|
|
8313
|
-
var
|
|
8386
|
+
var e_7, _a;
|
|
8314
8387
|
try {
|
|
8315
8388
|
for (var _b = __values(Object.entries(templates)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8316
8389
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8319,16 +8392,16 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8319
8392
|
}
|
|
8320
8393
|
}
|
|
8321
8394
|
}
|
|
8322
|
-
catch (
|
|
8395
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
8323
8396
|
finally {
|
|
8324
8397
|
try {
|
|
8325
8398
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8326
8399
|
}
|
|
8327
|
-
finally { if (
|
|
8400
|
+
finally { if (e_7) throw e_7.error; }
|
|
8328
8401
|
}
|
|
8329
8402
|
});
|
|
8330
8403
|
$pipelineJson.parameters.forEach(function (parameter) {
|
|
8331
|
-
var
|
|
8404
|
+
var e_8, _a;
|
|
8332
8405
|
try {
|
|
8333
8406
|
for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8334
8407
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8337,12 +8410,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
8337
8410
|
}
|
|
8338
8411
|
}
|
|
8339
8412
|
}
|
|
8340
|
-
catch (
|
|
8413
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
8341
8414
|
finally {
|
|
8342
8415
|
try {
|
|
8343
8416
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8344
8417
|
}
|
|
8345
|
-
finally { if (
|
|
8418
|
+
finally { if (e_8) throw e_8.error; }
|
|
8346
8419
|
}
|
|
8347
8420
|
});
|
|
8348
8421
|
// =============================================================
|