@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.
@@ -1,4 +1,6 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node --no-warnings
2
+
3
+ // <- TODO: !!!!!! Is this try to get rid of deprecation warnings in node v23.2.0 working?
2
4
 
3
5
  const { _CLI /* <- Note: [🥠] */ } = require('../umd/index.umd.js');
4
6
 
package/esm/index.es.js CHANGED
@@ -37,7 +37,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
37
37
  *
38
38
  * @see https://github.com/webgptorg/promptbook
39
39
  */
40
- var PROMPTBOOK_ENGINE_VERSION = '0.74.0-6';
40
+ var PROMPTBOOK_ENGINE_VERSION = '0.74.0-7';
41
41
  /**
42
42
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
43
43
  */
@@ -3199,10 +3199,12 @@ function countLines(text) {
3199
3199
  * @public exported from `@promptbook/utils`
3200
3200
  */
3201
3201
  function countPages(text) {
3202
- var sentencesPerPage = 5; // Assuming each page has 5 sentences
3203
- var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
3204
- var pageCount = Math.ceil(sentences.length / sentencesPerPage);
3205
- return pageCount;
3202
+ if (text === '') {
3203
+ return 0;
3204
+ }
3205
+ var pagesByLinesCount = Math.ceil(countLines(text) / 44);
3206
+ var pagesByCharactersCount = Math.ceil(countCharacters(text) / 2772);
3207
+ return Math.max(pagesByLinesCount, pagesByCharactersCount);
3206
3208
  }
3207
3209
 
3208
3210
  /**
@@ -7926,7 +7928,7 @@ function titleToName(value) {
7926
7928
  * @public exported from `@promptbook/core`
7927
7929
  */
7928
7930
  function pipelineStringToJsonSync(pipelineString) {
7929
- var e_1, _a, e_2, _b;
7931
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
7930
7932
  var $pipelineJson = {
7931
7933
  title: undefined /* <- Note: [🍙] Putting here placeholder to keep `title` on top at final JSON */,
7932
7934
  pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
@@ -7954,7 +7956,7 @@ function pipelineStringToJsonSync(pipelineString) {
7954
7956
  // =============================================================
7955
7957
  // Note: 1️⃣ Parsing of the markdown into object
7956
7958
  if (pipelineString.startsWith('#!')) {
7957
- var _c = __read(pipelineString.split('\n')), shebangLine_1 = _c[0], restLines = _c.slice(1);
7959
+ var _e = __read(pipelineString.split('\n')), shebangLine_1 = _e[0], restLines = _e.slice(1);
7958
7960
  if (!(shebangLine_1 || '').includes('ptbk')) {
7959
7961
  throw new ParseError(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 "); }));
7960
7962
  }
@@ -7964,7 +7966,7 @@ function pipelineStringToJsonSync(pipelineString) {
7964
7966
  pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
7965
7967
  pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
7966
7968
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
7967
- var _d = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _d[0], pipelineSections = _d.slice(1); /* <- Note: [🥞] */
7969
+ var _f = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _f[0], pipelineSections = _f.slice(1); /* <- Note: [🥞] */
7968
7970
  if (pipelineHead === undefined) {
7969
7971
  throw new UnexpectedError(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 "); }));
7970
7972
  }
@@ -7992,6 +7994,8 @@ function pipelineStringToJsonSync(pipelineString) {
7992
7994
  if (parameterDescription) {
7993
7995
  existingParameter.description = parameterDescription;
7994
7996
  }
7997
+ existingParameter.isInput = existingParameter.isInput || isInput;
7998
+ existingParameter.isOutput = existingParameter.isOutput || isOutput;
7995
7999
  }
7996
8000
  else {
7997
8001
  $pipelineJson.parameters.push({
@@ -8054,10 +8058,10 @@ function pipelineStringToJsonSync(pipelineString) {
8054
8058
  finally { if (e_1) throw e_1.error; }
8055
8059
  }
8056
8060
  var _loop_2 = function (section) {
8057
- var e_3, _e;
8061
+ var e_5, _l, e_6, _m;
8058
8062
  // TODO: Parse template description (the content out of the codeblock and lists)
8059
8063
  var listItems_2 = extractAllListItemsFromMarkdown(section.content);
8060
- var _f = extractOneBlockFromMarkdown(section.content), language = _f.language, content = _f.content;
8064
+ var _o = extractOneBlockFromMarkdown(section.content), language = _o.language, content = _o.content;
8061
8065
  // TODO: [🎾][1] DRY description
8062
8066
  var description_1 = section.content;
8063
8067
  // Note: Remove codeblocks - TODO: [🎾]
@@ -8098,7 +8102,7 @@ function pipelineStringToJsonSync(pipelineString) {
8098
8102
  }) === false) {
8099
8103
  templateCommandParser.$applyToTemplateJson({ type: 'TEMPLATE', templateType: 'PROMPT_TEMPLATE' }, $templateJson, $pipelineJson);
8100
8104
  }
8101
- var _loop_3 = function (listItem, command) {
8105
+ var _loop_4 = function (listItem, command) {
8102
8106
  var commandParser = getParserForCommand(command);
8103
8107
  if (commandParser.isUsedInPipelineTemplate !== true /* <- Note: [🦦][4] */) {
8104
8108
  throw new ParseError(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: [🚞]
@@ -8121,17 +8125,17 @@ function pipelineStringToJsonSync(pipelineString) {
8121
8125
  };
8122
8126
  try {
8123
8127
  // TODO [♓️] List commands and before apply order them to achieve order-agnostic commands
8124
- for (var commands_1 = (e_3 = void 0, __values(commands)), commands_1_1 = commands_1.next(); !commands_1_1.done; commands_1_1 = commands_1.next()) {
8125
- var _g = commands_1_1.value, listItem = _g.listItem, command = _g.command;
8126
- _loop_3(listItem, command);
8128
+ 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()) {
8129
+ var _p = commands_1_1.value, listItem = _p.listItem, command = _p.command;
8130
+ _loop_4(listItem, command);
8127
8131
  }
8128
8132
  }
8129
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
8133
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
8130
8134
  finally {
8131
8135
  try {
8132
- if (commands_1_1 && !commands_1_1.done && (_e = commands_1.return)) _e.call(commands_1);
8136
+ if (commands_1_1 && !commands_1_1.done && (_l = commands_1.return)) _l.call(commands_1);
8133
8137
  }
8134
- finally { if (e_3) throw e_3.error; }
8138
+ finally { if (e_5) throw e_5.error; }
8135
8139
  }
8136
8140
  // TODO: [🍧] Should be done in TEMPLATE command
8137
8141
  if ($templateJson.templateType === 'SCRIPT_TEMPLATE') {
@@ -8145,6 +8149,26 @@ function pipelineStringToJsonSync(pipelineString) {
8145
8149
  language;
8146
8150
  }
8147
8151
  $templateJson.dependentParameterNames = Array.from(extractParameterNamesFromTemplate($templateJson));
8152
+ try {
8153
+ for (var _q = (e_6 = void 0, __values($templateJson.dependentParameterNames)), _r = _q.next(); !_r.done; _r = _q.next()) {
8154
+ var parameterName = _r.value;
8155
+ // TODO: [🧠] This definition should be made first in the template
8156
+ defineParam({
8157
+ parameterName: parameterName,
8158
+ parameterDescription: null,
8159
+ isInput: false,
8160
+ isOutput: false,
8161
+ // <- 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
8162
+ });
8163
+ }
8164
+ }
8165
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
8166
+ finally {
8167
+ try {
8168
+ if (_r && !_r.done && (_m = _q.return)) _m.call(_q);
8169
+ }
8170
+ finally { if (e_6) throw e_6.error; }
8171
+ }
8148
8172
  /*
8149
8173
  // TODO: [🍧] This should be checked in `MODEL` command + better error message
8150
8174
  if ($templateJson.templateType !== 'PROMPT_TEMPLATE' && $templateJson.modelRequirements !== undefined) {
@@ -8186,9 +8210,51 @@ function pipelineStringToJsonSync(pipelineString) {
8186
8210
  finally { if (e_2) throw e_2.error; }
8187
8211
  }
8188
8212
  // =============================================================
8189
- // Note: 5️⃣ Cleanup of undefined values
8213
+ // Note: 5️⃣ Mark parameters as INPUT if not explicitly set
8214
+ if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isInput; })) {
8215
+ var _loop_3 = function (parameter) {
8216
+ var isThisParameterResulting = $pipelineJson.templates.some(function (template) { return template.resultingParameterName === parameter.name; });
8217
+ if (!isThisParameterResulting) {
8218
+ parameter.isInput = true;
8219
+ }
8220
+ };
8221
+ try {
8222
+ for (var _g = __values($pipelineJson.parameters), _h = _g.next(); !_h.done; _h = _g.next()) {
8223
+ var parameter = _h.value;
8224
+ _loop_3(parameter);
8225
+ }
8226
+ }
8227
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
8228
+ finally {
8229
+ try {
8230
+ if (_h && !_h.done && (_c = _g.return)) _c.call(_g);
8231
+ }
8232
+ finally { if (e_3) throw e_3.error; }
8233
+ }
8234
+ }
8235
+ // =============================================================
8236
+ // Note: 6️⃣ Mark all non-INPUT parameters as OUTPUT if any OUTPUT is not set
8237
+ if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isOutput; })) {
8238
+ try {
8239
+ for (var _j = __values($pipelineJson.parameters), _k = _j.next(); !_k.done; _k = _j.next()) {
8240
+ var parameter = _k.value;
8241
+ if (!parameter.isInput) {
8242
+ parameter.isOutput = true;
8243
+ }
8244
+ }
8245
+ }
8246
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
8247
+ finally {
8248
+ try {
8249
+ if (_k && !_k.done && (_d = _j.return)) _d.call(_j);
8250
+ }
8251
+ finally { if (e_4) throw e_4.error; }
8252
+ }
8253
+ }
8254
+ // =============================================================
8255
+ // Note: 7️⃣ Cleanup of undefined values
8190
8256
  $pipelineJson.templates.forEach(function (templates) {
8191
- var e_4, _a;
8257
+ var e_7, _a;
8192
8258
  try {
8193
8259
  for (var _b = __values(Object.entries(templates)), _c = _b.next(); !_c.done; _c = _b.next()) {
8194
8260
  var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
@@ -8197,16 +8263,16 @@ function pipelineStringToJsonSync(pipelineString) {
8197
8263
  }
8198
8264
  }
8199
8265
  }
8200
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
8266
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
8201
8267
  finally {
8202
8268
  try {
8203
8269
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
8204
8270
  }
8205
- finally { if (e_4) throw e_4.error; }
8271
+ finally { if (e_7) throw e_7.error; }
8206
8272
  }
8207
8273
  });
8208
8274
  $pipelineJson.parameters.forEach(function (parameter) {
8209
- var e_5, _a;
8275
+ var e_8, _a;
8210
8276
  try {
8211
8277
  for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
8212
8278
  var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
@@ -8215,12 +8281,12 @@ function pipelineStringToJsonSync(pipelineString) {
8215
8281
  }
8216
8282
  }
8217
8283
  }
8218
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
8284
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
8219
8285
  finally {
8220
8286
  try {
8221
8287
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
8222
8288
  }
8223
- finally { if (e_5) throw e_5.error; }
8289
+ finally { if (e_8) throw e_8.error; }
8224
8290
  }
8225
8291
  });
8226
8292
  // =============================================================