@promptbook/cli 0.59.0-21 → 0.59.0-23

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.
Files changed (48) hide show
  1. package/bin/promptbook-cli.js +1 -1
  2. package/esm/index.es.js +184 -209
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/cli.index.d.ts +2 -2
  5. package/esm/typings/src/_packages/core.index.d.ts +6 -6
  6. package/esm/typings/src/_packages/node.index.d.ts +2 -2
  7. package/esm/typings/src/_packages/types.index.d.ts +2 -1
  8. package/esm/typings/src/cli/actions/hello.d.ts +7 -0
  9. package/esm/typings/src/cli/actions/make.d.ts +7 -0
  10. package/esm/typings/src/cli/actions/prettify.d.ts +7 -0
  11. package/esm/typings/src/{conversion/prettify/prettifyPromptbookStringCli.d.ts → cli/promptbookCli.d.ts} +2 -2
  12. package/esm/typings/src/library/SimplePromptbookLibrary.d.ts +3 -1
  13. package/{umd/typings/src/library/constructors/createPromptbookLibraryFromDirectory.d.ts → esm/typings/src/library/constructors/createLibraryFromDirectory.d.ts} +2 -2
  14. package/esm/typings/src/library/constructors/createLibraryFromJson.d.ts +12 -0
  15. package/{umd/typings/src/library/constructors/createPromptbookLibraryFromPromise.d.ts → esm/typings/src/library/constructors/createLibraryFromPromise.d.ts} +3 -7
  16. package/{umd/typings/src/library/constructors/createPromptbookLibraryFromUrl.d.ts → esm/typings/src/library/constructors/createLibraryFromUrl.d.ts} +2 -2
  17. package/esm/typings/src/library/constructors/{createPromptbookSublibrary.d.ts → createSublibrary.d.ts} +1 -1
  18. package/esm/typings/src/library/libraryToJson.d.ts +8 -0
  19. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  20. package/package.json +2 -2
  21. package/umd/index.umd.js +140 -165
  22. package/umd/index.umd.js.map +1 -1
  23. package/umd/typings/src/_packages/cli.index.d.ts +2 -2
  24. package/umd/typings/src/_packages/core.index.d.ts +6 -6
  25. package/umd/typings/src/_packages/node.index.d.ts +2 -2
  26. package/umd/typings/src/_packages/types.index.d.ts +2 -1
  27. package/umd/typings/src/cli/actions/hello.d.ts +7 -0
  28. package/umd/typings/src/cli/actions/make.d.ts +7 -0
  29. package/umd/typings/src/cli/actions/prettify.d.ts +7 -0
  30. package/umd/typings/src/{conversion/prettify/prettifyPromptbookStringCli.d.ts → cli/promptbookCli.d.ts} +2 -2
  31. package/umd/typings/src/library/SimplePromptbookLibrary.d.ts +3 -1
  32. package/{esm/typings/src/library/constructors/createPromptbookLibraryFromDirectory.d.ts → umd/typings/src/library/constructors/createLibraryFromDirectory.d.ts} +2 -2
  33. package/umd/typings/src/library/constructors/createLibraryFromJson.d.ts +12 -0
  34. package/{esm/typings/src/library/constructors/createPromptbookLibraryFromPromise.d.ts → umd/typings/src/library/constructors/createLibraryFromPromise.d.ts} +3 -7
  35. package/umd/typings/src/library/constructors/createLibraryFromPromise.test.d.ts +1 -0
  36. package/{esm/typings/src/library/constructors/createPromptbookLibraryFromUrl.d.ts → umd/typings/src/library/constructors/createLibraryFromUrl.d.ts} +2 -2
  37. package/umd/typings/src/library/constructors/{createPromptbookSublibrary.d.ts → createSublibrary.d.ts} +1 -1
  38. package/umd/typings/src/library/libraryToJson.d.ts +8 -0
  39. package/umd/typings/src/library/libraryToJson.test.d.ts +1 -0
  40. package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  41. package/esm/typings/src/library/constructors/createPromptbookLibraryFromSources.d.ts +0 -16
  42. package/umd/typings/src/library/constructors/createPromptbookLibraryFromSources.d.ts +0 -16
  43. /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromDirectory.test.d.ts → createLibraryFromDirectory.test.d.ts} +0 -0
  44. /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromPromise.test.d.ts → createLibraryFromJson.test.d.ts} +0 -0
  45. /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromSources.test.d.ts → createLibraryFromPromise.test.d.ts} +0 -0
  46. /package/{umd/typings/src/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts → esm/typings/src/library/libraryToJson.test.d.ts} +0 -0
  47. /package/umd/typings/src/library/constructors/{createPromptbookLibraryFromPromise.test.d.ts → createLibraryFromDirectory.test.d.ts} +0 -0
  48. /package/umd/typings/src/library/constructors/{createPromptbookLibraryFromSources.test.d.ts → createLibraryFromJson.test.d.ts} +0 -0
package/esm/index.es.js CHANGED
@@ -1,9 +1,9 @@
1
- import colors from 'colors';
2
1
  import commander from 'commander';
2
+ import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
3
+ import colors from 'colors';
4
+ import { forTime } from 'waitasecond';
3
5
  import { writeFile, readFile } from 'fs/promises';
4
6
  import glob from 'glob-promise';
5
- import spaceTrim$1, { spaceTrim } from 'spacetrim';
6
- import { forTime } from 'waitasecond';
7
7
  import { format } from 'prettier';
8
8
  import parserHtml from 'prettier/parser-html';
9
9
 
@@ -142,7 +142,37 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
142
142
  /**
143
143
  * The version of the Promptbook library
144
144
  */
145
- var PROMPTBOOK_VERSION = '0.59.0-20';
145
+ var PROMPTBOOK_VERSION = '0.59.0-21';
146
+
147
+ /**
148
+ * Initializes testing `hello` command for Promptbook CLI utilities
149
+ *
150
+ * @private part of `promptbookCli`
151
+ */
152
+ function initializeHello(program) {
153
+ var _this = this;
154
+ var helloCommand = program.command('hello');
155
+ helloCommand.description(spaceTrim("\n Just command for testing\n "));
156
+ helloCommand.argument('<name>', 'Your name');
157
+ helloCommand.option('-g, --greeting <greeting>', "Greeting", 'Hello');
158
+ helloCommand.action(function (name, _a) {
159
+ var greeting = _a.greeting;
160
+ return __awaiter(_this, void 0, void 0, function () {
161
+ return __generator(this, function (_b) {
162
+ switch (_b.label) {
163
+ case 0:
164
+ console.info(colors.cyan("".concat(greeting, " ").concat(name)));
165
+ return [4 /*yield*/, forTime(1000)];
166
+ case 1:
167
+ _b.sent();
168
+ console.info(colors.rainbow("Nice to meet you!"));
169
+ process.exit(0);
170
+ return [2 /*return*/];
171
+ }
172
+ });
173
+ });
174
+ });
175
+ }
146
176
 
147
177
  /**
148
178
  * Removes HTML or Markdown comments from a string.
@@ -151,7 +181,7 @@ var PROMPTBOOK_VERSION = '0.59.0-20';
151
181
  * @returns {string} The input string with all comments removed.
152
182
  */
153
183
  function removeContentComments(content) {
154
- return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
184
+ return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
155
185
  }
156
186
 
157
187
  /**
@@ -165,7 +195,7 @@ function addAutoGeneratedSection(content, options) {
165
195
  var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
166
196
  var sectionMatch = content.match(sectionRegex);
167
197
  if (sectionMatch) {
168
- return content.replace(sectionRegex, spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
198
+ return content.replace(sectionRegex, spaceTrim$1(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
169
199
  }
170
200
  var placeForSection = removeContentComments(content).match(/^##.*$/im);
171
201
  if (!placeForSection) {
@@ -221,7 +251,7 @@ var PromptbookSyntaxError = /** @class */ (function (_super) {
221
251
  return PromptbookSyntaxError;
222
252
  }(Error));
223
253
 
224
- var promptbookLibrary = [{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.59.0-20",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],executionType:"PROMPT_TEMPLATE",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {content}",resultingParameterName:"knowledge"}],knowledge:[]}];
254
+ var promptbookLibrary = [{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.59.0-21",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],executionType:"PROMPT_TEMPLATE",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {content}",resultingParameterName:"knowledge"}],knowledge:[]}];
225
255
 
226
256
  /**
227
257
  * This error indicates errors during the execution of the promptbook
@@ -255,7 +285,7 @@ function assertsExecutionSuccessful(executionResult) {
255
285
  throw errors[0];
256
286
  }
257
287
  else {
258
- throw new PromptbookExecutionError(spaceTrim(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
288
+ throw new PromptbookExecutionError(spaceTrim$1(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
259
289
  }
260
290
  }
261
291
  /**
@@ -287,7 +317,7 @@ var PromptbookLogicError = /** @class */ (function (_super) {
287
317
  var UnexpectedError = /** @class */ (function (_super) {
288
318
  __extends(UnexpectedError, _super);
289
319
  function UnexpectedError(message) {
290
- var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the promptbook library\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
320
+ var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the promptbook library\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
291
321
  _this.name = 'UnexpectedError';
292
322
  Object.setPrototypeOf(_this, UnexpectedError.prototype);
293
323
  return _this;
@@ -346,12 +376,12 @@ function validatePromptbookJson(promptbook) {
346
376
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
347
377
  if (!Array.isArray(promptbook.parameters)) {
348
378
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
349
- throw new PromptbookSyntaxError(spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.parameters expected to be an array, but got ".concat(typeof promptbook.parameters, "\n ")));
379
+ throw new PromptbookSyntaxError(spaceTrim$1("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.parameters expected to be an array, but got ".concat(typeof promptbook.parameters, "\n ")));
350
380
  }
351
381
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
352
382
  if (!Array.isArray(promptbook.promptTemplates)) {
353
383
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
354
- throw new PromptbookSyntaxError(spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.promptTemplates expected to be an array, but got ".concat(typeof promptbook.promptTemplates, "\n ")));
384
+ throw new PromptbookSyntaxError(spaceTrim$1("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.promptTemplates expected to be an array, but got ".concat(typeof promptbook.promptTemplates, "\n ")));
355
385
  }
356
386
  var _loop_1 = function (parameter) {
357
387
  if (parameter.isInput && parameter.isOutput) {
@@ -361,12 +391,12 @@ function validatePromptbookJson(promptbook) {
361
391
  if (!parameter.isInput &&
362
392
  !parameter.isOutput &&
363
393
  !promptbook.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
364
- throw new PromptbookLogicError(spaceTrim("\n Parameter {".concat(parameter.name, "} is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ")));
394
+ throw new PromptbookLogicError(spaceTrim$1("\n Parameter {".concat(parameter.name, "} is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ")));
365
395
  }
366
396
  // Note: Testing that parameter is either input or result of some template
367
397
  if (!parameter.isInput &&
368
398
  !promptbook.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
369
- throw new PromptbookLogicError(spaceTrim("\n Parameter {".concat(parameter.name, "} is declared but not defined\n\n You can do one of these:\n - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ")));
399
+ throw new PromptbookLogicError(spaceTrim$1("\n Parameter {".concat(parameter.name, "} is declared but not defined\n\n You can do one of these:\n - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ")));
370
400
  }
371
401
  };
372
402
  try {
@@ -400,7 +430,7 @@ function validatePromptbookJson(promptbook) {
400
430
  definedParameters.add(template.resultingParameterName);
401
431
  if (template.executionType === 'PROMPT_TEMPLATE' &&
402
432
  (template.modelRequirements.modelVariant === undefined)) {
403
- throw new PromptbookLogicError(spaceTrim("\n\n You must specify MODEL VARIANT in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
433
+ throw new PromptbookLogicError(spaceTrim$1("\n\n You must specify MODEL VARIANT in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
404
434
  }
405
435
  if (template.jokers && template.jokers.length > 0) {
406
436
  if (!template.expectFormat &&
@@ -475,7 +505,7 @@ function validatePromptbookJson(promptbook) {
475
505
  return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
476
506
  });
477
507
  if (currentlyResovedTemplates.length === 0) {
478
- throw new PromptbookLogicError(spaceTrim(function (block) { return "\n\n Can not resolve some parameters\n It may be circular dependencies\n\n Can not resolve:\n ".concat(block(unresovedTemplates
508
+ throw new PromptbookLogicError(spaceTrim$1(function (block) { return "\n\n Can not resolve some parameters\n It may be circular dependencies\n\n Can not resolve:\n ".concat(block(unresovedTemplates
479
509
  .map(function (_a) {
480
510
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
481
511
  return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
@@ -1215,7 +1245,7 @@ function createPromptbookExecutor(options) {
1215
1245
  throw errors[0];
1216
1246
  }
1217
1247
  else {
1218
- throw new PromptbookExecutionError(spaceTrim(function (block) { return "\n Postprocessing in LlmExecutionTools failed ".concat(errors.length, "x\n\n ").concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n\n')), "\n "); }));
1248
+ throw new PromptbookExecutionError(spaceTrim$1(function (block) { return "\n Postprocessing in LlmExecutionTools failed ".concat(errors.length, "x\n\n ").concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n\n')), "\n "); }));
1219
1249
  }
1220
1250
  }
1221
1251
  });
@@ -1299,7 +1329,7 @@ function createPromptbookExecutor(options) {
1299
1329
  throw scriptExecutionErrors[0];
1300
1330
  }
1301
1331
  else {
1302
- throw new PromptbookExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
1332
+ throw new PromptbookExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
1303
1333
  .map(function (error) { return '- ' + error.message; })
1304
1334
  .join('\n\n')), "\n "); }));
1305
1335
  }
@@ -1444,7 +1474,7 @@ function createPromptbookExecutor(options) {
1444
1474
  return [7 /*endfinally*/];
1445
1475
  case 47:
1446
1476
  if (expectError !== null && attempt === maxAttempts - 1) {
1447
- throw new PromptbookExecutionError(spaceTrim(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
1477
+ throw new PromptbookExecutionError(spaceTrim$1(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
1448
1478
  }
1449
1479
  _o.label = 48;
1450
1480
  case 48:
@@ -1513,7 +1543,7 @@ function createPromptbookExecutor(options) {
1513
1543
  return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
1514
1544
  });
1515
1545
  if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
1516
- throw new UnexpectedError(spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePromptbookJson\n "));
1546
+ throw new UnexpectedError(spaceTrim$1("\n Can not resolve some parameters\n\n Note: This should be catched during validatePromptbookJson\n "));
1517
1547
  case 1:
1518
1548
  if (!!currentTemplate) return [3 /*break*/, 3];
1519
1549
  /* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
@@ -1777,7 +1807,7 @@ function promptbookJsonToString(promptbookJson) {
1777
1807
  promptbookString += '\n\n';
1778
1808
  promptbookString += '```' + contentLanguage;
1779
1809
  promptbookString += '\n';
1780
- promptbookString += spaceTrim$1(content);
1810
+ promptbookString += spaceTrim(content);
1781
1811
  // <- TODO: !!! Escape
1782
1812
  // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
1783
1813
  promptbookString += '\n';
@@ -1842,6 +1872,7 @@ var PromptbookReferenceError = /** @class */ (function (_super) {
1842
1872
  * Library of promptbooks that groups together promptbooks for an application.
1843
1873
  * This implementation is a very thin wrapper around the Array / Map of promptbooks.
1844
1874
  *
1875
+ * @private use `createLibraryFromJson` instead
1845
1876
  * @see https://github.com/webgptorg/promptbook#promptbook-library
1846
1877
  */
1847
1878
  var SimplePromptbookLibrary = /** @class */ (function () {
@@ -1850,8 +1881,9 @@ var SimplePromptbookLibrary = /** @class */ (function () {
1850
1881
  *
1851
1882
  * @param promptbooks !!!
1852
1883
  *
1884
+ * @private Use instead `createLibraryFromJson`
1853
1885
  * Note: During the construction logic of all promptbooks are validated
1854
- * Note: It is not recommended to use this constructor directly, use `createPromptbookLibraryFromSources` *(or other variant)* instead
1886
+ * Note: It is not recommended to use this constructor directly, use `createLibraryFromJson` *(or other variant)* instead
1855
1887
  */
1856
1888
  function SimplePromptbookLibrary() {
1857
1889
  var e_1, _a;
@@ -1864,14 +1896,14 @@ var SimplePromptbookLibrary = /** @class */ (function () {
1864
1896
  for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
1865
1897
  var promptbook = promptbooks_1_1.value;
1866
1898
  if (promptbook.promptbookUrl === undefined) {
1867
- throw new PromptbookReferenceError(spaceTrim("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the promptbook library\n\n ")));
1899
+ throw new PromptbookReferenceError(spaceTrim$1("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the promptbook library\n\n ")));
1868
1900
  }
1869
1901
  validatePromptbookJson(promptbook);
1870
1902
  // Note: [🦄]
1871
1903
  if (this.library.has(promptbook.promptbookUrl) &&
1872
1904
  promptbookJsonToString(promptbook) !==
1873
1905
  promptbookJsonToString(this.library.get(promptbook.promptbookUrl))) {
1874
- throw new PromptbookReferenceError(spaceTrim("\n Promptbook with URL \"".concat(promptbook.promptbookUrl, "\" is already in the library\n\n Note: Promptbooks with the same URL are not allowed\n Note: Automatically check whether the promptbooks are the same BUT they are DIFFERENT\n\n ")));
1906
+ throw new PromptbookReferenceError(spaceTrim$1("\n Promptbook with URL \"".concat(promptbook.promptbookUrl, "\" is already in the library\n\n Note: Promptbooks with the same URL are not allowed\n Note: Automatically check whether the promptbooks are the same BUT they are DIFFERENT\n\n ")));
1875
1907
  }
1876
1908
  this.library.set(promptbook.promptbookUrl, promptbook);
1877
1909
  }
@@ -1900,9 +1932,9 @@ var SimplePromptbookLibrary = /** @class */ (function () {
1900
1932
  var promptbook = this.library.get(url);
1901
1933
  if (!promptbook) {
1902
1934
  if (this.listPromptbooks().length === 0) {
1903
- throw new PromptbookNotFoundError(spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
1935
+ throw new PromptbookNotFoundError(spaceTrim$1("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
1904
1936
  }
1905
- throw new PromptbookNotFoundError(spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
1937
+ throw new PromptbookNotFoundError(spaceTrim$1(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
1906
1938
  .map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
1907
1939
  .join('\n')), "\n\n "); }));
1908
1940
  }
@@ -1920,68 +1952,23 @@ var SimplePromptbookLibrary = /** @class */ (function () {
1920
1952
  /**
1921
1953
  * Creates PromptbookLibrary from array of PromptbookJson or PromptbookString
1922
1954
  *
1923
- * Note: You can combine `PromptbookString` (`.ptbk.md`) with `PromptbookJson` BUT it is not recommended
1955
+ * Note: Functions `libraryToJson` and `createLibraryFromJson` are complementary
1924
1956
  * Note: During the construction syntax and logic of all sources are validated
1925
1957
  *
1926
1958
  * @param promptbookSources
1927
1959
  * @returns PromptbookLibrary
1928
1960
  */
1929
- function createPromptbookLibraryFromSources() {
1930
- var promptbookSources = [];
1961
+ function createLibraryFromJson() {
1962
+ var promptbooks = [];
1931
1963
  for (var _i = 0; _i < arguments.length; _i++) {
1932
- promptbookSources[_i] = arguments[_i];
1964
+ promptbooks[_i] = arguments[_i];
1933
1965
  }
1934
1966
  return __awaiter(this, void 0, void 0, function () {
1935
- var promptbooks, promptbookSources_1, promptbookSources_1_1, source, promptbook, e_1_1;
1936
- var e_1, _a;
1937
- return __generator(this, function (_b) {
1938
- switch (_b.label) {
1939
- case 0:
1940
- promptbooks = new Array();
1941
- _b.label = 1;
1942
- case 1:
1943
- _b.trys.push([1, 8, 9, 10]);
1944
- promptbookSources_1 = __values(promptbookSources), promptbookSources_1_1 = promptbookSources_1.next();
1945
- _b.label = 2;
1946
- case 2:
1947
- if (!!promptbookSources_1_1.done) return [3 /*break*/, 7];
1948
- source = promptbookSources_1_1.value;
1949
- promptbook = void 0;
1950
- if (!(typeof source === 'string')) return [3 /*break*/, 4];
1951
- return [4 /*yield*/, promptbookStringToJson(source)];
1952
- case 3:
1953
- // Note: When directly creating from string, no need to validate the source
1954
- // The validation is performed always before execution
1955
- promptbook = _b.sent();
1956
- return [3 /*break*/, 5];
1957
- case 4:
1958
- promptbook = source;
1959
- _b.label = 5;
1960
- case 5:
1961
- promptbooks.push(promptbook);
1962
- _b.label = 6;
1963
- case 6:
1964
- promptbookSources_1_1 = promptbookSources_1.next();
1965
- return [3 /*break*/, 2];
1966
- case 7: return [3 /*break*/, 10];
1967
- case 8:
1968
- e_1_1 = _b.sent();
1969
- e_1 = { error: e_1_1 };
1970
- return [3 /*break*/, 10];
1971
- case 9:
1972
- try {
1973
- if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
1974
- }
1975
- finally { if (e_1) throw e_1.error; }
1976
- return [7 /*endfinally*/];
1977
- case 10: return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
1978
- }
1967
+ return __generator(this, function (_a) {
1968
+ return [2 /*return*/, new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))()];
1979
1969
  });
1980
1970
  });
1981
1971
  }
1982
- /**
1983
- * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
1984
- */
1985
1972
 
1986
1973
  /* tslint:disable */
1987
1974
  function normalizeToKebabCase(sentence) {
@@ -2046,7 +2033,7 @@ function prepareKnowledgeFromMarkdown(options) {
2046
2033
  switch (_b.label) {
2047
2034
  case 0:
2048
2035
  content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
2049
- return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
2036
+ return [4 /*yield*/, createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
2050
2037
  case 1:
2051
2038
  library = _b.sent();
2052
2039
  promptbook = library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md');
@@ -2073,14 +2060,14 @@ function prepareKnowledgeFromMarkdown(options) {
2073
2060
  var name, title, content, keywords, index, sources;
2074
2061
  return __generator(this, function (_a) {
2075
2062
  name = "piece-".concat(i);
2076
- title = spaceTrim$1(knowledgeTextPiece.substring(0, 100));
2077
- content = spaceTrim$1(knowledgeTextPiece);
2063
+ title = spaceTrim(knowledgeTextPiece.substring(0, 100));
2064
+ content = spaceTrim(knowledgeTextPiece);
2078
2065
  keywords = [];
2079
2066
  index = [];
2080
2067
  sources = [];
2081
2068
  try {
2082
2069
  // TODO: !!!! Summarize name and title from the content
2083
- title = spaceTrim$1(knowledgeTextPiece.substring(0, 30));
2070
+ title = spaceTrim(knowledgeTextPiece.substring(0, 30));
2084
2071
  name = normalizeToKebabCase(title);
2085
2072
  // TODO: !!!! Extract keywords via prompt
2086
2073
  // TODO: !!!! Index through LLM model
@@ -2181,7 +2168,7 @@ function markdownToMarkdownStructure(markdown) {
2181
2168
  }
2182
2169
  if (parent_1.parent === null /* <- Note: We are in root */) {
2183
2170
  // [🌻]
2184
- throw new Error(spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
2171
+ throw new Error(spaceTrim$1("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
2185
2172
  }
2186
2173
  parent_1 = parent_1.parent;
2187
2174
  }
@@ -2215,7 +2202,7 @@ function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
2215
2202
  return {
2216
2203
  level: level,
2217
2204
  title: title,
2218
- content: spaceTrim(contentLines.join('\n')),
2205
+ content: spaceTrim$1(contentLines.join('\n')),
2219
2206
  sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
2220
2207
  };
2221
2208
  }
@@ -2446,7 +2433,7 @@ function extractVariables(script) {
2446
2433
  if (!(error instanceof Error)) {
2447
2434
  throw error;
2448
2435
  }
2449
- throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
2436
+ throw new PromptbookSyntaxError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
2450
2437
  }
2451
2438
  return variables;
2452
2439
  }
@@ -2706,15 +2693,15 @@ function parseCommand(listItem) {
2706
2693
  type.startsWith('PROMPTBOOKURL') ||
2707
2694
  type.startsWith('HTTPS')) {
2708
2695
  if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
2709
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
2696
+ throw new PromptbookSyntaxError(spaceTrim$1("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
2710
2697
  }
2711
2698
  var promptbookUrlString = listItemParts.pop();
2712
2699
  var promptbookUrl = new URL(promptbookUrlString);
2713
2700
  if (promptbookUrl.protocol !== 'https:') {
2714
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
2701
+ throw new PromptbookSyntaxError(spaceTrim$1("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
2715
2702
  }
2716
2703
  if (promptbookUrl.hash !== '') {
2717
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
2704
+ throw new PromptbookSyntaxError(spaceTrim$1("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
2718
2705
  }
2719
2706
  return {
2720
2707
  type: 'PROMPTBOOK_URL',
@@ -2723,7 +2710,7 @@ function parseCommand(listItem) {
2723
2710
  }
2724
2711
  else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
2725
2712
  if (listItemParts.length !== 2) {
2726
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
2713
+ throw new PromptbookSyntaxError(spaceTrim$1("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
2727
2714
  }
2728
2715
  var promptbookVersion = listItemParts.pop();
2729
2716
  // TODO: Validate version
@@ -2738,7 +2725,7 @@ function parseCommand(listItem) {
2738
2725
  type.startsWith('SIMPLE_TEMPLATE')) {
2739
2726
  var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
2740
2727
  if (executionTypes.length !== 1) {
2741
- throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown execution type in command:\n\n - ".concat(listItem, "\n\n Supported execution types are:\n ").concat(block(ExecutionTypes.join(', ')), "\n "); }));
2728
+ throw new PromptbookSyntaxError(spaceTrim$1(function (block) { return "\n Unknown execution type in command:\n\n - ".concat(listItem, "\n\n Supported execution types are:\n ").concat(block(ExecutionTypes.join(', ')), "\n "); }));
2742
2729
  }
2743
2730
  return {
2744
2731
  type: 'EXECUTE',
@@ -2763,7 +2750,7 @@ function parseCommand(listItem) {
2763
2750
  };
2764
2751
  }
2765
2752
  else {
2766
- throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n - ".concat(listItem, "\n\n Supported variants are:\n ").concat(block(['CHAT', 'COMPLETION'].join(', ')), "\n "); }));
2753
+ throw new PromptbookSyntaxError(spaceTrim$1(function (block) { return "\n Unknown model variant in command:\n\n - ".concat(listItem, "\n\n Supported variants are:\n ").concat(block(['CHAT', 'COMPLETION'].join(', ')), "\n "); }));
2767
2754
  }
2768
2755
  }
2769
2756
  if (type.startsWith('MODEL_NAME')) {
@@ -2774,7 +2761,7 @@ function parseCommand(listItem) {
2774
2761
  };
2775
2762
  }
2776
2763
  else {
2777
- throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
2764
+ throw new PromptbookSyntaxError(spaceTrim$1(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
2778
2765
  }
2779
2766
  }
2780
2767
  else if (type.startsWith('PARAM') ||
@@ -2784,12 +2771,12 @@ function parseCommand(listItem) {
2784
2771
  listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
2785
2772
  var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
2786
2773
  if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
2787
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
2774
+ throw new PromptbookSyntaxError(spaceTrim$1("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
2788
2775
  }
2789
2776
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2790
2777
  var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
2791
2778
  if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
2792
- throw new PromptbookSyntaxError(spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
2779
+ throw new PromptbookSyntaxError(spaceTrim$1("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
2793
2780
  }
2794
2781
  var isInput = type.startsWith('INPUT');
2795
2782
  var isOutput = type.startsWith('OUTPUT');
@@ -2807,11 +2794,11 @@ function parseCommand(listItem) {
2807
2794
  }
2808
2795
  else if (type.startsWith('JOKER')) {
2809
2796
  if (listItemParts.length !== 2) {
2810
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
2797
+ throw new PromptbookSyntaxError(spaceTrim$1("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
2811
2798
  }
2812
2799
  var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
2813
2800
  if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
2814
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
2801
+ throw new PromptbookSyntaxError(spaceTrim$1("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
2815
2802
  }
2816
2803
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2817
2804
  var parameterName = parametersMatch.groups.parameterName;
@@ -2822,7 +2809,7 @@ function parseCommand(listItem) {
2822
2809
  }
2823
2810
  else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
2824
2811
  if (listItemParts.length !== 2) {
2825
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
2812
+ throw new PromptbookSyntaxError(spaceTrim$1("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
2826
2813
  }
2827
2814
  var functionName = listItemParts.pop();
2828
2815
  return {
@@ -2902,7 +2889,7 @@ function parseCommand(listItem) {
2902
2889
  if (!(error instanceof Error)) {
2903
2890
  throw error;
2904
2891
  }
2905
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
2892
+ throw new PromptbookSyntaxError(spaceTrim$1("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
2906
2893
  }
2907
2894
  /*
2908
2895
  } else if (type.startsWith('__________________')) {
@@ -2910,7 +2897,7 @@ function parseCommand(listItem) {
2910
2897
  */
2911
2898
  }
2912
2899
  else {
2913
- throw new PromptbookSyntaxError(spaceTrim("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - PROMPTBOOK_URL <url>\n - PROMPTBOOK_VERSION <version>\n - EXECUTE PROMPT TEMPLATE\n - EXECUTE SIMPLE TEMPLATE\n - SIMPLE TEMPLATE\n - EXECUTE SCRIPT\n - EXECUTE PROMPT_DIALOG'\n - PROMPT_DIALOG'\n - MODEL NAME <name>\n - MODEL VARIANT <\"Chat\"|\"Completion\">\n - INPUT PARAM {<name>} <description>\n - OUTPUT PARAM {<name>} <description>\n - POSTPROCESS `{functionName}`\n - JOKER {<name>}\n - EXPECT JSON\n - EXPECT <\"Exactly\"|\"Min\"|\"Max\"> <number> <\"Chars\"|\"Words\"|\"Sentences\"|\"Paragraphs\"|\"Pages\">\n\n ")));
2900
+ throw new PromptbookSyntaxError(spaceTrim$1("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - PROMPTBOOK_URL <url>\n - PROMPTBOOK_VERSION <version>\n - EXECUTE PROMPT TEMPLATE\n - EXECUTE SIMPLE TEMPLATE\n - SIMPLE TEMPLATE\n - EXECUTE SCRIPT\n - EXECUTE PROMPT_DIALOG'\n - PROMPT_DIALOG'\n - MODEL NAME <name>\n - MODEL VARIANT <\"Chat\"|\"Completion\">\n - INPUT PARAM {<name>} <description>\n - OUTPUT PARAM {<name>} <description>\n - POSTPROCESS `{functionName}`\n - JOKER {<name>}\n - EXPECT JSON\n - EXPECT <\"Exactly\"|\"Min\"|\"Max\"> <number> <\"Chars\"|\"Words\"|\"Sentences\"|\"Paragraphs\"|\"Pages\">\n\n ")));
2914
2901
  }
2915
2902
  }
2916
2903
 
@@ -2991,7 +2978,7 @@ function promptbookStringToJson(promptbookString, options) {
2991
2978
  existingParameter.description &&
2992
2979
  existingParameter.description !== parameterDescription &&
2993
2980
  parameterDescription) {
2994
- throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description.\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
2981
+ throw new PromptbookSyntaxError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description.\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
2995
2982
  }
2996
2983
  if (existingParameter) {
2997
2984
  if (parameterDescription) {
@@ -3010,7 +2997,7 @@ function promptbookStringToJson(promptbookString, options) {
3010
2997
  markdownStructure = markdownToMarkdownStructure(promptbookString);
3011
2998
  markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
3012
2999
  if (markdownStructureDeepness !== 2) {
3013
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
3000
+ throw new PromptbookSyntaxError(spaceTrim$1("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
3014
3001
  }
3015
3002
  promptbookJson.title = markdownStructure.title;
3016
3003
  description = markdownStructure.content;
@@ -3018,7 +3005,7 @@ function promptbookStringToJson(promptbookString, options) {
3018
3005
  description = description.split(/^```.*^```/gms).join('');
3019
3006
  //Note: Remove lists and return statement
3020
3007
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
3021
- description = spaceTrim(description);
3008
+ description = spaceTrim$1(description);
3022
3009
  if (description === '') {
3023
3010
  description = undefined;
3024
3011
  }
@@ -3133,13 +3120,13 @@ function promptbookStringToJson(promptbookString, options) {
3133
3120
  throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
3134
3121
  }
3135
3122
  else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
3136
- throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
3123
+ throw new PromptbookSyntaxError(spaceTrim$1(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
3137
3124
  }
3138
3125
  }
3139
3126
  var lastLine = section.content.split('\n').pop();
3140
3127
  var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
3141
3128
  if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
3142
- throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
3129
+ throw new PromptbookSyntaxError(spaceTrim$1(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
3143
3130
  // TODO: Show code of invalid sections each time + DRY
3144
3131
  section.content
3145
3132
  .split('\n')
@@ -3153,7 +3140,7 @@ function promptbookStringToJson(promptbookString, options) {
3153
3140
  description_1 = description_1.split(/^```.*^```/gms).join('');
3154
3141
  //Note: Remove lists and return statement
3155
3142
  description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
3156
- description_1 = spaceTrim(description_1);
3143
+ description_1 = spaceTrim$1(description_1);
3157
3144
  if (description_1 === '') {
3158
3145
  description_1 = undefined;
3159
3146
  }
@@ -3287,7 +3274,7 @@ function renderPromptbookMermaid(promptbookJson, options) {
3287
3274
  }
3288
3275
  return normalizeTo_camelCase('template-' + titleToName(template.title));
3289
3276
  };
3290
- var promptbookMermaid = spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(promptbookJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson.promptTemplates
3277
+ var promptbookMermaid = spaceTrim$1(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(promptbookJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson.promptTemplates
3291
3278
  .flatMap(function (_a) {
3292
3279
  var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
3293
3280
  return __spreadArray([
@@ -3343,7 +3330,7 @@ function prettifyPromptbookString(promptbookString, options) {
3343
3330
  return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
3344
3331
  },
3345
3332
  });
3346
- promptbookMermaidBlock = spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
3333
+ promptbookMermaidBlock = spaceTrim$1(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
3347
3334
  promptbookString = addAutoGeneratedSection(promptbookString, {
3348
3335
  sectionName: 'Graph',
3349
3336
  sectionContent: promptbookMermaidBlock,
@@ -3364,117 +3351,105 @@ function prettifyPromptbookString(promptbookString, options) {
3364
3351
  */
3365
3352
 
3366
3353
  /**
3367
- * Runs CLI script for prettifying promptbooks
3354
+ * Initializes `prettify` command for Promptbook CLI utilities
3355
+ *
3356
+ * @private part of `promptbookCli`
3368
3357
  */
3369
- function prettifyPromptbookStringCli() {
3358
+ function initializePrettify(program) {
3359
+ var _this = this;
3360
+ var prettifyCommand = program.command('prettify');
3361
+ prettifyCommand.description(spaceTrim("\n Iterates over promptbooks and does multiple enhancing operations on them:\n\n 1) Adds Mermaid graph\n 2) Prettifies the markdown\n "));
3362
+ prettifyCommand.argument('<filesGlob>', 'Promptbooks to prettify as glob pattern');
3363
+ prettifyCommand.option('-i, --ignore <glob>', "Ignore as glob pattern");
3364
+ prettifyCommand.action(function (filesGlob, _a) {
3365
+ var ignore = _a.ignore;
3366
+ return __awaiter(_this, void 0, void 0, function () {
3367
+ var filePaths, filePaths_1, filePaths_1_1, filePath, promptbookMarkdown, error_1, e_1_1;
3368
+ var e_1, _b;
3369
+ return __generator(this, function (_c) {
3370
+ switch (_c.label) {
3371
+ case 0: return [4 /*yield*/, glob(filesGlob, { ignore: ignore })];
3372
+ case 1:
3373
+ filePaths = _c.sent();
3374
+ _c.label = 2;
3375
+ case 2:
3376
+ _c.trys.push([2, 11, 12, 13]);
3377
+ filePaths_1 = __values(filePaths), filePaths_1_1 = filePaths_1.next();
3378
+ _c.label = 3;
3379
+ case 3:
3380
+ if (!!filePaths_1_1.done) return [3 /*break*/, 10];
3381
+ filePath = filePaths_1_1.value;
3382
+ if (!filePath.endsWith('.ptbk.md')) {
3383
+ console.warn(colors.yellow("Skipping prettify of non-promptbook ".concat(filePath)));
3384
+ return [3 /*break*/, 9];
3385
+ }
3386
+ return [4 /*yield*/, readFile(filePath, 'utf-8')];
3387
+ case 4:
3388
+ promptbookMarkdown = (_c.sent());
3389
+ _c.label = 5;
3390
+ case 5:
3391
+ _c.trys.push([5, 8, , 9]);
3392
+ return [4 /*yield*/, prettifyPromptbookString(promptbookMarkdown, {
3393
+ isGraphAdded: true,
3394
+ isPrettifyed: true,
3395
+ // <- [🕌]
3396
+ })];
3397
+ case 6:
3398
+ promptbookMarkdown = _c.sent();
3399
+ return [4 /*yield*/, writeFile(filePath, promptbookMarkdown)];
3400
+ case 7:
3401
+ _c.sent();
3402
+ console.info(colors.green("Prettify ".concat(filePath)));
3403
+ return [3 /*break*/, 9];
3404
+ case 8:
3405
+ error_1 = _c.sent();
3406
+ if (!(error_1 instanceof Error)) {
3407
+ throw error_1;
3408
+ }
3409
+ console.info(colors.red("Prettify ".concat(error_1.name, " ").concat(filePath)));
3410
+ console.error(colors.bgRed(error_1.name));
3411
+ console.error(error_1);
3412
+ process.exit(1);
3413
+ return [3 /*break*/, 9];
3414
+ case 9:
3415
+ filePaths_1_1 = filePaths_1.next();
3416
+ return [3 /*break*/, 3];
3417
+ case 10: return [3 /*break*/, 13];
3418
+ case 11:
3419
+ e_1_1 = _c.sent();
3420
+ e_1 = { error: e_1_1 };
3421
+ return [3 /*break*/, 13];
3422
+ case 12:
3423
+ try {
3424
+ if (filePaths_1_1 && !filePaths_1_1.done && (_b = filePaths_1.return)) _b.call(filePaths_1);
3425
+ }
3426
+ finally { if (e_1) throw e_1.error; }
3427
+ return [7 /*endfinally*/];
3428
+ case 13:
3429
+ process.exit(0);
3430
+ return [2 /*return*/];
3431
+ }
3432
+ });
3433
+ });
3434
+ });
3435
+ }
3436
+
3437
+ /**
3438
+ * Runs CLI utilities of Promptbook package
3439
+ */
3440
+ function promptbookCli() {
3370
3441
  return __awaiter(this, void 0, void 0, function () {
3371
- var program, prettifyCommand, helloCommand;
3372
- var _this = this;
3442
+ var program;
3373
3443
  return __generator(this, function (_a) {
3374
3444
  if (!isRunningInNode()) {
3375
- throw new Error(spaceTrim("\n Function prettifyPromptbookStringCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use prettifyPromptbookString.\n\n "));
3445
+ throw new Error(spaceTrim$1("\n Function promptbookCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use function exported from `@promptbook/utils` or `@promptbook/core` directly, for example `prettifyPromptbookString`.\n\n "));
3376
3446
  }
3377
3447
  program = new commander.Command();
3378
3448
  program.name('promptbook');
3379
3449
  program.version(PROMPTBOOK_VERSION);
3380
- program.description(spaceTrim("\n Promptbook utilities\n "));
3381
- prettifyCommand = program.command('prettify');
3382
- prettifyCommand.description(spaceTrim("\n Iterates over promptbooks and does multiple enhancing operations on them:\n 1) Adds Mermaid graph\n 2) Prettifies the markdown\n "));
3383
- prettifyCommand.argument('<filesGlob>', 'Promptbooks to prettify as glob pattern');
3384
- prettifyCommand.option('-i, --ignore <glob>', "Ignore as glob pattern");
3385
- prettifyCommand.action(function (filesGlob, _a) {
3386
- var ignore = _a.ignore;
3387
- return __awaiter(_this, void 0, void 0, function () {
3388
- var filePaths, filePaths_1, filePaths_1_1, filePath, promptbookMarkdown, error_1, e_1_1;
3389
- var e_1, _b;
3390
- return __generator(this, function (_c) {
3391
- switch (_c.label) {
3392
- case 0: return [4 /*yield*/, glob(filesGlob, { ignore: ignore })];
3393
- case 1:
3394
- filePaths = _c.sent();
3395
- _c.label = 2;
3396
- case 2:
3397
- _c.trys.push([2, 11, 12, 13]);
3398
- filePaths_1 = __values(filePaths), filePaths_1_1 = filePaths_1.next();
3399
- _c.label = 3;
3400
- case 3:
3401
- if (!!filePaths_1_1.done) return [3 /*break*/, 10];
3402
- filePath = filePaths_1_1.value;
3403
- if (!filePath.endsWith('.ptbk.md')) {
3404
- console.warn(colors.yellow("Skipping prettify of non-promptbook ".concat(filePath)));
3405
- return [3 /*break*/, 9];
3406
- }
3407
- return [4 /*yield*/, readFile(filePath, 'utf-8')];
3408
- case 4:
3409
- promptbookMarkdown = (_c.sent());
3410
- _c.label = 5;
3411
- case 5:
3412
- _c.trys.push([5, 8, , 9]);
3413
- return [4 /*yield*/, prettifyPromptbookString(promptbookMarkdown, {
3414
- isGraphAdded: true,
3415
- isPrettifyed: true,
3416
- // <- [🕌]
3417
- })];
3418
- case 6:
3419
- promptbookMarkdown = _c.sent();
3420
- return [4 /*yield*/, writeFile(filePath, promptbookMarkdown)];
3421
- case 7:
3422
- _c.sent();
3423
- console.info(colors.green("Prettify ".concat(filePath)));
3424
- return [3 /*break*/, 9];
3425
- case 8:
3426
- error_1 = _c.sent();
3427
- if (!(error_1 instanceof Error)) {
3428
- throw error_1;
3429
- }
3430
- console.info(colors.red("Prettify ".concat(error_1.name, " ").concat(filePath)));
3431
- console.error(colors.bgRed(error_1.name));
3432
- console.error(error_1);
3433
- process.exit(1);
3434
- return [3 /*break*/, 9];
3435
- case 9:
3436
- filePaths_1_1 = filePaths_1.next();
3437
- return [3 /*break*/, 3];
3438
- case 10: return [3 /*break*/, 13];
3439
- case 11:
3440
- e_1_1 = _c.sent();
3441
- e_1 = { error: e_1_1 };
3442
- return [3 /*break*/, 13];
3443
- case 12:
3444
- try {
3445
- if (filePaths_1_1 && !filePaths_1_1.done && (_b = filePaths_1.return)) _b.call(filePaths_1);
3446
- }
3447
- finally { if (e_1) throw e_1.error; }
3448
- return [7 /*endfinally*/];
3449
- case 13:
3450
- process.exit(0);
3451
- return [2 /*return*/];
3452
- }
3453
- });
3454
- });
3455
- });
3456
- helloCommand = program.command('hello');
3457
- helloCommand.description(spaceTrim("\n Just command for testing\n "));
3458
- helloCommand.argument('<name>', 'Your name');
3459
- helloCommand.option('-g, --greeting <greeting>', "Greeting", 'Hello');
3460
- helloCommand.action(function (name, _a) {
3461
- var greeting = _a.greeting;
3462
- return __awaiter(_this, void 0, void 0, function () {
3463
- return __generator(this, function (_b) {
3464
- switch (_b.label) {
3465
- case 0:
3466
- console.info(colors.cyan("".concat(greeting, " ").concat(name)));
3467
- return [4 /*yield*/, forTime(1000)];
3468
- case 1:
3469
- _b.sent();
3470
- console.info(colors.rainbow("Nice to meet you!"));
3471
- process.exit(0);
3472
- return [2 /*return*/];
3473
- }
3474
- });
3475
- });
3476
- });
3477
- //------
3450
+ program.description(spaceTrim$1("\n Promptbook utilities for enhancing workflow with promptbooks\n "));
3451
+ initializeHello(program);
3452
+ initializePrettify(program);
3478
3453
  program.parse(process.argv);
3479
3454
  return [2 /*return*/];
3480
3455
  });
@@ -3492,7 +3467,7 @@ function prettifyPromptbookStringCli() {
3492
3467
  */
3493
3468
  var __ = {
3494
3469
  // Note: [🥠]
3495
- prettifyPromptbookStringCli: prettifyPromptbookStringCli,
3470
+ promptbookCli: promptbookCli,
3496
3471
  };
3497
3472
 
3498
3473
  export { PROMPTBOOK_VERSION, __ };