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