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