@promptbook/cli 0.59.0-20 → 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 (50) hide show
  1. package/bin/promptbook-cli.js +1 -1
  2. package/esm/index.es.js +194 -216
  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/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +16 -2
  13. package/esm/typings/src/library/SimplePromptbookLibrary.d.ts +3 -1
  14. package/{umd/typings/src/library/constructors/createPromptbookLibraryFromDirectory.d.ts → esm/typings/src/library/constructors/createLibraryFromDirectory.d.ts} +2 -2
  15. package/esm/typings/src/library/constructors/createLibraryFromJson.d.ts +12 -0
  16. package/{umd/typings/src/library/constructors/createPromptbookLibraryFromPromise.d.ts → esm/typings/src/library/constructors/createLibraryFromPromise.d.ts} +3 -7
  17. package/{umd/typings/src/library/constructors/createPromptbookLibraryFromUrl.d.ts → esm/typings/src/library/constructors/createLibraryFromUrl.d.ts} +2 -2
  18. package/esm/typings/src/library/constructors/{createPromptbookSublibrary.d.ts → createSublibrary.d.ts} +1 -1
  19. package/esm/typings/src/library/libraryToJson.d.ts +8 -0
  20. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  21. package/package.json +2 -2
  22. package/umd/index.umd.js +150 -172
  23. package/umd/index.umd.js.map +1 -1
  24. package/umd/typings/src/_packages/cli.index.d.ts +2 -2
  25. package/umd/typings/src/_packages/core.index.d.ts +6 -6
  26. package/umd/typings/src/_packages/node.index.d.ts +2 -2
  27. package/umd/typings/src/_packages/types.index.d.ts +2 -1
  28. package/umd/typings/src/cli/actions/hello.d.ts +7 -0
  29. package/umd/typings/src/cli/actions/make.d.ts +7 -0
  30. package/umd/typings/src/cli/actions/prettify.d.ts +7 -0
  31. package/umd/typings/src/{conversion/prettify/prettifyPromptbookStringCli.d.ts → cli/promptbookCli.d.ts} +2 -2
  32. package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +16 -2
  33. package/umd/typings/src/library/SimplePromptbookLibrary.d.ts +3 -1
  34. package/{esm/typings/src/library/constructors/createPromptbookLibraryFromDirectory.d.ts → umd/typings/src/library/constructors/createLibraryFromDirectory.d.ts} +2 -2
  35. package/umd/typings/src/library/constructors/createLibraryFromJson.d.ts +12 -0
  36. package/{esm/typings/src/library/constructors/createPromptbookLibraryFromPromise.d.ts → umd/typings/src/library/constructors/createLibraryFromPromise.d.ts} +3 -7
  37. package/umd/typings/src/library/constructors/createLibraryFromPromise.test.d.ts +1 -0
  38. package/{esm/typings/src/library/constructors/createPromptbookLibraryFromUrl.d.ts → umd/typings/src/library/constructors/createLibraryFromUrl.d.ts} +2 -2
  39. package/umd/typings/src/library/constructors/{createPromptbookSublibrary.d.ts → createSublibrary.d.ts} +1 -1
  40. package/umd/typings/src/library/libraryToJson.d.ts +8 -0
  41. package/umd/typings/src/library/libraryToJson.test.d.ts +1 -0
  42. package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  43. package/esm/typings/src/library/constructors/createPromptbookLibraryFromSources.d.ts +0 -16
  44. package/umd/typings/src/library/constructors/createPromptbookLibraryFromSources.d.ts +0 -16
  45. /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromDirectory.test.d.ts → createLibraryFromDirectory.test.d.ts} +0 -0
  46. /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromPromise.test.d.ts → createLibraryFromJson.test.d.ts} +0 -0
  47. /package/esm/typings/src/library/constructors/{createPromptbookLibraryFromSources.test.d.ts → createLibraryFromPromise.test.d.ts} +0 -0
  48. /package/{umd/typings/src/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts → esm/typings/src/library/libraryToJson.test.d.ts} +0 -0
  49. /package/umd/typings/src/library/constructors/{createPromptbookLibraryFromPromise.test.d.ts → createLibraryFromDirectory.test.d.ts} +0 -0
  50. /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-22';
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-22';
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-22",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) {
@@ -2040,15 +2027,15 @@ function normalizeToKebabCase(sentence) {
2040
2027
 
2041
2028
  function prepareKnowledgeFromMarkdown(options) {
2042
2029
  return __awaiter(this, void 0, void 0, function () {
2043
- var content, llmTools, library, promptbook, executor, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
2030
+ var content, llmTools, _a, isVerbose, library, promptbook, executor, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
2044
2031
  var _this = this;
2045
- return __generator(this, function (_a) {
2046
- switch (_a.label) {
2032
+ return __generator(this, function (_b) {
2033
+ switch (_b.label) {
2047
2034
  case 0:
2048
- content = options.content, llmTools = options.llmTools;
2049
- return [4 /*yield*/, createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
2035
+ content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
2036
+ return [4 /*yield*/, createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookLibrary), false))];
2050
2037
  case 1:
2051
- library = _a.sent();
2038
+ library = _b.sent();
2052
2039
  promptbook = library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md');
2053
2040
  executor = createPromptbookExecutor({
2054
2041
  promptbook: promptbook,
@@ -2061,23 +2048,26 @@ function prepareKnowledgeFromMarkdown(options) {
2061
2048
  });
2062
2049
  return [4 /*yield*/, executor({ content: content })];
2063
2050
  case 2:
2064
- result = _a.sent();
2051
+ result = _b.sent();
2065
2052
  assertsExecutionSuccessful(result);
2066
2053
  outputParameters = result.outputParameters;
2067
2054
  knowledgeRaw = outputParameters.knowledge;
2068
2055
  knowledgeTextPieces = (knowledgeRaw || '').split('\n---\n');
2056
+ if (isVerbose) {
2057
+ console.info('knowledgeTextPieces:', knowledgeTextPieces);
2058
+ }
2069
2059
  return [4 /*yield*/, Promise.all(knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
2070
2060
  var name, title, content, keywords, index, sources;
2071
2061
  return __generator(this, function (_a) {
2072
2062
  name = "piece-".concat(i);
2073
- title = spaceTrim$1(knowledgeTextPiece.substring(0, 100));
2074
- content = spaceTrim$1(knowledgeTextPiece);
2063
+ title = spaceTrim(knowledgeTextPiece.substring(0, 100));
2064
+ content = spaceTrim(knowledgeTextPiece);
2075
2065
  keywords = [];
2076
2066
  index = [];
2077
2067
  sources = [];
2078
2068
  try {
2079
2069
  // TODO: !!!! Summarize name and title from the content
2080
- title = spaceTrim$1(knowledgeTextPiece.substring(0, 30));
2070
+ title = spaceTrim(knowledgeTextPiece.substring(0, 30));
2081
2071
  name = normalizeToKebabCase(title);
2082
2072
  // TODO: !!!! Extract keywords via prompt
2083
2073
  // TODO: !!!! Index through LLM model
@@ -2097,7 +2087,7 @@ function prepareKnowledgeFromMarkdown(options) {
2097
2087
  });
2098
2088
  }); }))];
2099
2089
  case 3:
2100
- knowledge = _a.sent();
2090
+ knowledge = _b.sent();
2101
2091
  return [2 /*return*/, knowledge];
2102
2092
  }
2103
2093
  });
@@ -2178,7 +2168,7 @@ function markdownToMarkdownStructure(markdown) {
2178
2168
  }
2179
2169
  if (parent_1.parent === null /* <- Note: We are in root */) {
2180
2170
  // [🌻]
2181
- 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 "));
2182
2172
  }
2183
2173
  parent_1 = parent_1.parent;
2184
2174
  }
@@ -2212,7 +2202,7 @@ function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
2212
2202
  return {
2213
2203
  level: level,
2214
2204
  title: title,
2215
- content: spaceTrim(contentLines.join('\n')),
2205
+ content: spaceTrim$1(contentLines.join('\n')),
2216
2206
  sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
2217
2207
  };
2218
2208
  }
@@ -2443,7 +2433,7 @@ function extractVariables(script) {
2443
2433
  if (!(error instanceof Error)) {
2444
2434
  throw error;
2445
2435
  }
2446
- 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 "); }));
2447
2437
  }
2448
2438
  return variables;
2449
2439
  }
@@ -2703,15 +2693,15 @@ function parseCommand(listItem) {
2703
2693
  type.startsWith('PROMPTBOOKURL') ||
2704
2694
  type.startsWith('HTTPS')) {
2705
2695
  if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
2706
- 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 ")));
2707
2697
  }
2708
2698
  var promptbookUrlString = listItemParts.pop();
2709
2699
  var promptbookUrl = new URL(promptbookUrlString);
2710
2700
  if (promptbookUrl.protocol !== 'https:') {
2711
- 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 ")));
2712
2702
  }
2713
2703
  if (promptbookUrl.hash !== '') {
2714
- 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 ")));
2715
2705
  }
2716
2706
  return {
2717
2707
  type: 'PROMPTBOOK_URL',
@@ -2720,7 +2710,7 @@ function parseCommand(listItem) {
2720
2710
  }
2721
2711
  else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
2722
2712
  if (listItemParts.length !== 2) {
2723
- 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 ")));
2724
2714
  }
2725
2715
  var promptbookVersion = listItemParts.pop();
2726
2716
  // TODO: Validate version
@@ -2735,7 +2725,7 @@ function parseCommand(listItem) {
2735
2725
  type.startsWith('SIMPLE_TEMPLATE')) {
2736
2726
  var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
2737
2727
  if (executionTypes.length !== 1) {
2738
- 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 "); }));
2739
2729
  }
2740
2730
  return {
2741
2731
  type: 'EXECUTE',
@@ -2760,7 +2750,7 @@ function parseCommand(listItem) {
2760
2750
  };
2761
2751
  }
2762
2752
  else {
2763
- 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 "); }));
2764
2754
  }
2765
2755
  }
2766
2756
  if (type.startsWith('MODEL_NAME')) {
@@ -2771,7 +2761,7 @@ function parseCommand(listItem) {
2771
2761
  };
2772
2762
  }
2773
2763
  else {
2774
- 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 "); }));
2775
2765
  }
2776
2766
  }
2777
2767
  else if (type.startsWith('PARAM') ||
@@ -2781,12 +2771,12 @@ function parseCommand(listItem) {
2781
2771
  listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
2782
2772
  var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
2783
2773
  if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
2784
- 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 ")));
2785
2775
  }
2786
2776
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2787
2777
  var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
2788
2778
  if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
2789
- 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 ")));
2790
2780
  }
2791
2781
  var isInput = type.startsWith('INPUT');
2792
2782
  var isOutput = type.startsWith('OUTPUT');
@@ -2804,11 +2794,11 @@ function parseCommand(listItem) {
2804
2794
  }
2805
2795
  else if (type.startsWith('JOKER')) {
2806
2796
  if (listItemParts.length !== 2) {
2807
- 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 ")));
2808
2798
  }
2809
2799
  var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
2810
2800
  if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
2811
- 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 ")));
2812
2802
  }
2813
2803
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2814
2804
  var parameterName = parametersMatch.groups.parameterName;
@@ -2819,7 +2809,7 @@ function parseCommand(listItem) {
2819
2809
  }
2820
2810
  else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
2821
2811
  if (listItemParts.length !== 2) {
2822
- 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 ")));
2823
2813
  }
2824
2814
  var functionName = listItemParts.pop();
2825
2815
  return {
@@ -2899,7 +2889,7 @@ function parseCommand(listItem) {
2899
2889
  if (!(error instanceof Error)) {
2900
2890
  throw error;
2901
2891
  }
2902
- 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 ")));
2903
2893
  }
2904
2894
  /*
2905
2895
  } else if (type.startsWith('__________________')) {
@@ -2907,7 +2897,7 @@ function parseCommand(listItem) {
2907
2897
  */
2908
2898
  }
2909
2899
  else {
2910
- 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 ")));
2911
2901
  }
2912
2902
  }
2913
2903
 
@@ -2988,7 +2978,7 @@ function promptbookStringToJson(promptbookString, options) {
2988
2978
  existingParameter.description &&
2989
2979
  existingParameter.description !== parameterDescription &&
2990
2980
  parameterDescription) {
2991
- 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 "); }));
2992
2982
  }
2993
2983
  if (existingParameter) {
2994
2984
  if (parameterDescription) {
@@ -3007,7 +2997,7 @@ function promptbookStringToJson(promptbookString, options) {
3007
2997
  markdownStructure = markdownToMarkdownStructure(promptbookString);
3008
2998
  markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
3009
2999
  if (markdownStructureDeepness !== 2) {
3010
- 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 ")));
3011
3001
  }
3012
3002
  promptbookJson.title = markdownStructure.title;
3013
3003
  description = markdownStructure.content;
@@ -3015,7 +3005,7 @@ function promptbookStringToJson(promptbookString, options) {
3015
3005
  description = description.split(/^```.*^```/gms).join('');
3016
3006
  //Note: Remove lists and return statement
3017
3007
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
3018
- description = spaceTrim(description);
3008
+ description = spaceTrim$1(description);
3019
3009
  if (description === '') {
3020
3010
  description = undefined;
3021
3011
  }
@@ -3130,13 +3120,13 @@ function promptbookStringToJson(promptbookString, options) {
3130
3120
  throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
3131
3121
  }
3132
3122
  else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
3133
- 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 "); }));
3134
3124
  }
3135
3125
  }
3136
3126
  var lastLine = section.content.split('\n').pop();
3137
3127
  var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
3138
3128
  if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
3139
- 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(
3140
3130
  // TODO: Show code of invalid sections each time + DRY
3141
3131
  section.content
3142
3132
  .split('\n')
@@ -3150,7 +3140,7 @@ function promptbookStringToJson(promptbookString, options) {
3150
3140
  description_1 = description_1.split(/^```.*^```/gms).join('');
3151
3141
  //Note: Remove lists and return statement
3152
3142
  description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
3153
- description_1 = spaceTrim(description_1);
3143
+ description_1 = spaceTrim$1(description_1);
3154
3144
  if (description_1 === '') {
3155
3145
  description_1 = undefined;
3156
3146
  }
@@ -3284,7 +3274,7 @@ function renderPromptbookMermaid(promptbookJson, options) {
3284
3274
  }
3285
3275
  return normalizeTo_camelCase('template-' + titleToName(template.title));
3286
3276
  };
3287
- 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
3288
3278
  .flatMap(function (_a) {
3289
3279
  var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
3290
3280
  return __spreadArray([
@@ -3340,7 +3330,7 @@ function prettifyPromptbookString(promptbookString, options) {
3340
3330
  return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
3341
3331
  },
3342
3332
  });
3343
- 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 "); });
3344
3334
  promptbookString = addAutoGeneratedSection(promptbookString, {
3345
3335
  sectionName: 'Graph',
3346
3336
  sectionContent: promptbookMermaidBlock,
@@ -3361,117 +3351,105 @@ function prettifyPromptbookString(promptbookString, options) {
3361
3351
  */
3362
3352
 
3363
3353
  /**
3364
- * Runs CLI script for prettifying promptbooks
3354
+ * Initializes `prettify` command for Promptbook CLI utilities
3355
+ *
3356
+ * @private part of `promptbookCli`
3365
3357
  */
3366
- 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() {
3367
3441
  return __awaiter(this, void 0, void 0, function () {
3368
- var program, prettifyCommand, helloCommand;
3369
- var _this = this;
3442
+ var program;
3370
3443
  return __generator(this, function (_a) {
3371
3444
  if (!isRunningInNode()) {
3372
- 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 "));
3373
3446
  }
3374
3447
  program = new commander.Command();
3375
3448
  program.name('promptbook');
3376
3449
  program.version(PROMPTBOOK_VERSION);
3377
- program.description(spaceTrim("\n Promptbook utilities\n "));
3378
- prettifyCommand = program.command('prettify');
3379
- 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 "));
3380
- prettifyCommand.argument('<filesGlob>', 'Promptbooks to prettify as glob pattern');
3381
- prettifyCommand.option('-i, --ignore <glob>', "Ignore as glob pattern");
3382
- prettifyCommand.action(function (filesGlob, _a) {
3383
- var ignore = _a.ignore;
3384
- return __awaiter(_this, void 0, void 0, function () {
3385
- var filePaths, filePaths_1, filePaths_1_1, filePath, promptbookMarkdown, error_1, e_1_1;
3386
- var e_1, _b;
3387
- return __generator(this, function (_c) {
3388
- switch (_c.label) {
3389
- case 0: return [4 /*yield*/, glob(filesGlob, { ignore: ignore })];
3390
- case 1:
3391
- filePaths = _c.sent();
3392
- _c.label = 2;
3393
- case 2:
3394
- _c.trys.push([2, 11, 12, 13]);
3395
- filePaths_1 = __values(filePaths), filePaths_1_1 = filePaths_1.next();
3396
- _c.label = 3;
3397
- case 3:
3398
- if (!!filePaths_1_1.done) return [3 /*break*/, 10];
3399
- filePath = filePaths_1_1.value;
3400
- if (!filePath.endsWith('.ptbk.md')) {
3401
- console.warn(colors.yellow("Skipping prettify of non-promptbook ".concat(filePath)));
3402
- return [3 /*break*/, 9];
3403
- }
3404
- return [4 /*yield*/, readFile(filePath, 'utf-8')];
3405
- case 4:
3406
- promptbookMarkdown = (_c.sent());
3407
- _c.label = 5;
3408
- case 5:
3409
- _c.trys.push([5, 8, , 9]);
3410
- return [4 /*yield*/, prettifyPromptbookString(promptbookMarkdown, {
3411
- isGraphAdded: true,
3412
- isPrettifyed: true,
3413
- // <- [🕌]
3414
- })];
3415
- case 6:
3416
- promptbookMarkdown = _c.sent();
3417
- return [4 /*yield*/, writeFile(filePath, promptbookMarkdown)];
3418
- case 7:
3419
- _c.sent();
3420
- console.info(colors.green("Prettify ".concat(filePath)));
3421
- return [3 /*break*/, 9];
3422
- case 8:
3423
- error_1 = _c.sent();
3424
- if (!(error_1 instanceof Error)) {
3425
- throw error_1;
3426
- }
3427
- console.info(colors.red("Prettify ".concat(error_1.name, " ").concat(filePath)));
3428
- console.error(colors.bgRed(error_1.name));
3429
- console.error(error_1);
3430
- process.exit(1);
3431
- return [3 /*break*/, 9];
3432
- case 9:
3433
- filePaths_1_1 = filePaths_1.next();
3434
- return [3 /*break*/, 3];
3435
- case 10: return [3 /*break*/, 13];
3436
- case 11:
3437
- e_1_1 = _c.sent();
3438
- e_1 = { error: e_1_1 };
3439
- return [3 /*break*/, 13];
3440
- case 12:
3441
- try {
3442
- if (filePaths_1_1 && !filePaths_1_1.done && (_b = filePaths_1.return)) _b.call(filePaths_1);
3443
- }
3444
- finally { if (e_1) throw e_1.error; }
3445
- return [7 /*endfinally*/];
3446
- case 13:
3447
- process.exit(0);
3448
- return [2 /*return*/];
3449
- }
3450
- });
3451
- });
3452
- });
3453
- helloCommand = program.command('hello');
3454
- helloCommand.description(spaceTrim("\n Just command for testing\n "));
3455
- helloCommand.argument('<name>', 'Your name');
3456
- helloCommand.option('-g, --greeting <greeting>', "Greeting", 'Hello');
3457
- helloCommand.action(function (name, _a) {
3458
- var greeting = _a.greeting;
3459
- return __awaiter(_this, void 0, void 0, function () {
3460
- return __generator(this, function (_b) {
3461
- switch (_b.label) {
3462
- case 0:
3463
- console.info(colors.cyan("".concat(greeting, " ").concat(name)));
3464
- return [4 /*yield*/, forTime(1000)];
3465
- case 1:
3466
- _b.sent();
3467
- console.info(colors.rainbow("Nice to meet you!"));
3468
- process.exit(0);
3469
- return [2 /*return*/];
3470
- }
3471
- });
3472
- });
3473
- });
3474
- //------
3450
+ program.description(spaceTrim$1("\n Promptbook utilities for enhancing workflow with promptbooks\n "));
3451
+ initializeHello(program);
3452
+ initializePrettify(program);
3475
3453
  program.parse(process.argv);
3476
3454
  return [2 /*return*/];
3477
3455
  });
@@ -3489,7 +3467,7 @@ function prettifyPromptbookStringCli() {
3489
3467
  */
3490
3468
  var __ = {
3491
3469
  // Note: [🥠]
3492
- prettifyPromptbookStringCli: prettifyPromptbookStringCli,
3470
+ promptbookCli: promptbookCli,
3493
3471
  };
3494
3472
 
3495
3473
  export { PROMPTBOOK_VERSION, __ };