@promptbook/core 0.47.0 → 0.48.0-1

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 (46) hide show
  1. package/README.md +12 -1
  2. package/esm/index.es.js +464 -407
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/_packages/core.index.d.ts +2 -1
  5. package/esm/typings/_packages/utils.index.d.ts +2 -1
  6. package/esm/typings/conversion/prettify/prettifyPromptbookStringCli.d.ts +1 -1
  7. package/esm/typings/conversion/promptbookJsonToString.d.ts +8 -0
  8. package/esm/typings/conversion/utils/titleToName.d.ts +4 -0
  9. package/esm/typings/conversion/utils/titleToName.test.d.ts +1 -0
  10. package/esm/typings/execution/ExecutionTools.d.ts +1 -1
  11. package/esm/typings/execution/LlmExecutionTools.d.ts +1 -0
  12. package/esm/typings/execution/plugins/llm-execution-tools/langtail/LangtailExecutionTools.d.ts +1 -1
  13. package/esm/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +1 -1
  14. package/esm/typings/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +4 -1
  15. package/esm/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +1 -0
  16. package/esm/typings/library/SimplePromptbookLibrary.d.ts +2 -1
  17. package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +10 -1
  18. package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +20 -1
  19. package/esm/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +5 -6
  20. package/esm/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +13 -0
  21. package/esm/typings/library/constructors/createPromptbookSublibrary.d.ts +10 -1
  22. package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
  23. package/package.json +1 -1
  24. package/umd/index.umd.js +506 -444
  25. package/umd/index.umd.js.map +1 -1
  26. package/umd/typings/_packages/core.index.d.ts +2 -1
  27. package/umd/typings/_packages/utils.index.d.ts +2 -1
  28. package/umd/typings/conversion/prettify/prettifyPromptbookStringCli.d.ts +1 -1
  29. package/umd/typings/conversion/promptbookJsonToString.d.ts +8 -0
  30. package/umd/typings/conversion/utils/titleToName.d.ts +4 -0
  31. package/umd/typings/conversion/utils/titleToName.test.d.ts +1 -0
  32. package/umd/typings/execution/ExecutionTools.d.ts +1 -1
  33. package/umd/typings/execution/LlmExecutionTools.d.ts +1 -0
  34. package/umd/typings/execution/plugins/llm-execution-tools/langtail/LangtailExecutionTools.d.ts +1 -1
  35. package/umd/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +1 -1
  36. package/umd/typings/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +4 -1
  37. package/umd/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +1 -0
  38. package/umd/typings/library/SimplePromptbookLibrary.d.ts +2 -1
  39. package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +10 -1
  40. package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +20 -1
  41. package/umd/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +5 -6
  42. package/umd/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +13 -0
  43. package/umd/typings/library/constructors/createPromptbookSublibrary.d.ts +10 -1
  44. package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
  45. package/esm/typings/library/constructors/createPromptbookLibraryFromList.d.ts +0 -5
  46. package/umd/typings/library/constructors/createPromptbookLibraryFromList.d.ts +0 -5
package/umd/index.umd.js CHANGED
@@ -1,8 +1,12 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('moment')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'moment'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spacetrim));
5
- })(this, (function (exports, spacetrim) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.spaceTrim));
5
+ })(this, (function (exports, spaceTrim) { 'use strict';
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
6
10
 
7
11
  /*! *****************************************************************************
8
12
  Copyright (c) Microsoft Corporation.
@@ -123,6 +127,311 @@
123
127
  return to.concat(ar || Array.prototype.slice.call(from));
124
128
  }
125
129
 
130
+ /**
131
+ * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
132
+ */
133
+ var PromptbookSyntaxError = /** @class */ (function (_super) {
134
+ __extends(PromptbookSyntaxError, _super);
135
+ function PromptbookSyntaxError(message) {
136
+ var _this = _super.call(this, message) || this;
137
+ _this.name = 'PromptbookSyntaxError';
138
+ Object.setPrototypeOf(_this, PromptbookSyntaxError.prototype);
139
+ return _this;
140
+ }
141
+ return PromptbookSyntaxError;
142
+ }(Error));
143
+
144
+ /**
145
+ * Supported script languages
146
+ */
147
+ var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
148
+
149
+ /**
150
+ * Parses the template and returns the list of all parameter names
151
+ *
152
+ * @param template the template with parameters in {curly} braces
153
+ * @returns the list of parameter names
154
+ *
155
+ * @private within the library
156
+ */
157
+ function extractParameters(template) {
158
+ var e_1, _a;
159
+ var matches = template.matchAll(/{\w+}/g);
160
+ var parameterNames = [];
161
+ try {
162
+ for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
163
+ var match = matches_1_1.value;
164
+ var parameterName = match[0].slice(1, -1);
165
+ if (!parameterNames.includes(parameterName)) {
166
+ parameterNames.push(parameterName);
167
+ }
168
+ }
169
+ }
170
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
171
+ finally {
172
+ try {
173
+ if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
174
+ }
175
+ finally { if (e_1) throw e_1.error; }
176
+ }
177
+ return parameterNames;
178
+ }
179
+
180
+ /**
181
+ * Computes the deepness of the markdown structure.
182
+ *
183
+ * @private within the library
184
+ */
185
+ function countMarkdownStructureDeepness(markdownStructure) {
186
+ var e_1, _a;
187
+ var maxDeepness = 0;
188
+ try {
189
+ for (var _b = __values(markdownStructure.sections), _c = _b.next(); !_c.done; _c = _b.next()) {
190
+ var section = _c.value;
191
+ maxDeepness = Math.max(maxDeepness, countMarkdownStructureDeepness(section));
192
+ }
193
+ }
194
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
195
+ finally {
196
+ try {
197
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
198
+ }
199
+ finally { if (e_1) throw e_1.error; }
200
+ }
201
+ return maxDeepness + 1;
202
+ }
203
+
204
+ /**
205
+ * The maximum number of iterations for a loops
206
+ */
207
+ var LOOP_LIMIT = 1000;
208
+
209
+ /**
210
+ * This error type indicates that the error should not happen and its last check before crashing with some other error
211
+ */
212
+ var UnexpectedError = /** @class */ (function (_super) {
213
+ __extends(UnexpectedError, _super);
214
+ function UnexpectedError(message) {
215
+ var _this = _super.call(this, spaceTrim.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;
216
+ _this.name = 'UnexpectedError';
217
+ Object.setPrototypeOf(_this, UnexpectedError.prototype);
218
+ return _this;
219
+ }
220
+ return UnexpectedError;
221
+ }(Error));
222
+
223
+ /**
224
+ * Parse a markdown string into a MarkdownStructure object.
225
+ *
226
+ * Note: This function does work with code blocks
227
+ * Note: This function does not work with markdown comments
228
+ *
229
+ * @param markdown The markdown string to parse.
230
+ * @returns The MarkdownStructure object.
231
+ *
232
+ * @private within the library
233
+ */
234
+ function markdownToMarkdownStructure(markdown) {
235
+ var e_1, _a;
236
+ var lines = markdown.split('\n');
237
+ var root = { level: 0, title: '', contentLines: [], sections: [], parent: null };
238
+ var current = root;
239
+ var isInsideCodeBlock = false;
240
+ try {
241
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
242
+ var line = lines_1_1.value;
243
+ var headingMatch = line.match(/^(?<mark>#{1,6})\s(?<title>.*)/);
244
+ if (isInsideCodeBlock || !headingMatch) {
245
+ if (line.startsWith('```')) {
246
+ isInsideCodeBlock = !isInsideCodeBlock;
247
+ }
248
+ current.contentLines.push(line);
249
+ }
250
+ else {
251
+ var level = headingMatch.groups.mark.length;
252
+ var title = headingMatch.groups.title.trim();
253
+ var parent_1 = void 0;
254
+ if (level > current.level) {
255
+ // Note: Going deeper (next section is child of current)
256
+ parent_1 = current;
257
+ }
258
+ else {
259
+ // Note: Going up or staying at the same level (next section is sibling or parent or grandparent,... of current)
260
+ parent_1 = current;
261
+ var loopLimit = LOOP_LIMIT;
262
+ while (parent_1.level !== level - 1) {
263
+ if (loopLimit-- < 0) {
264
+ throw new UnexpectedError('Loop limit reached during parsing of markdown structure in `markdownToMarkdownStructure`');
265
+ }
266
+ if (parent_1.parent === null /* <- Note: We are in root */) {
267
+ // [🌻]
268
+ throw new Error(spaceTrim.spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
269
+ }
270
+ parent_1 = parent_1.parent;
271
+ }
272
+ }
273
+ var section = { level: level, title: title, contentLines: [], sections: [], parent: parent_1 };
274
+ parent_1.sections.push(section);
275
+ current = section;
276
+ }
277
+ }
278
+ }
279
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
280
+ finally {
281
+ try {
282
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
283
+ }
284
+ finally { if (e_1) throw e_1.error; }
285
+ }
286
+ if (root.sections.length === 1) {
287
+ var markdownStructure = parsingMarkdownStructureToMarkdownStructure(root.sections[0]);
288
+ return markdownStructure;
289
+ }
290
+ // [🌻]
291
+ throw new Error('The markdown file must have exactly one top-level section.');
292
+ // return root;
293
+ }
294
+ /**
295
+ * @private
296
+ */
297
+ function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
298
+ var level = parsingMarkdownStructure.level, title = parsingMarkdownStructure.title, contentLines = parsingMarkdownStructure.contentLines, sections = parsingMarkdownStructure.sections;
299
+ return {
300
+ level: level,
301
+ title: title,
302
+ content: spaceTrim.spaceTrim(contentLines.join('\n')),
303
+ sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
304
+ };
305
+ }
306
+
307
+ /**
308
+ * Utility function to extract all list items from markdown
309
+ *
310
+ * Note: It works with both ul and ol
311
+ * Note: It omits list items in code blocks
312
+ * Note: It flattens nested lists
313
+ * Note: It can not work with html syntax and comments
314
+ *
315
+ * @param markdown any valid markdown
316
+ * @returns
317
+ */
318
+ function extractAllListItemsFromMarkdown(markdown) {
319
+ var e_1, _a;
320
+ var lines = markdown.split('\n');
321
+ var listItems = [];
322
+ var isInCodeBlock = false;
323
+ try {
324
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
325
+ var line = lines_1_1.value;
326
+ var trimmedLine = line.trim();
327
+ if (trimmedLine.startsWith('```')) {
328
+ isInCodeBlock = !isInCodeBlock;
329
+ }
330
+ if (!isInCodeBlock && (trimmedLine.startsWith('-') || trimmedLine.match(/^\d+\./))) {
331
+ var listItem = trimmedLine.replace(/^-|\d+\./, '').trim();
332
+ listItems.push(listItem);
333
+ }
334
+ }
335
+ }
336
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
337
+ finally {
338
+ try {
339
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
340
+ }
341
+ finally { if (e_1) throw e_1.error; }
342
+ }
343
+ return listItems;
344
+ }
345
+
346
+ /**
347
+ * Makes first letter of a string uppercase
348
+ *
349
+ */
350
+ function capitalize(word) {
351
+ return word.substring(0, 1).toUpperCase() + word.substring(1);
352
+ }
353
+
354
+ /**
355
+ * Extracts all code blocks from markdown.
356
+ *
357
+ * Note: There are 3 simmilar function:
358
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
359
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
360
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
361
+ *
362
+ * @param markdown any valid markdown
363
+ * @returns code blocks with language and content
364
+ *
365
+ */
366
+ function extractAllBlocksFromMarkdown(markdown) {
367
+ var e_1, _a;
368
+ var codeBlocks = [];
369
+ var lines = markdown.split('\n');
370
+ var currentCodeBlock = null;
371
+ try {
372
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
373
+ var line = lines_1_1.value;
374
+ if (line.startsWith('```')) {
375
+ var language = line.slice(3).trim() || null;
376
+ if (currentCodeBlock === null) {
377
+ currentCodeBlock = { language: language, content: '' };
378
+ }
379
+ else {
380
+ if (language !== null) {
381
+ // [🌻]
382
+ throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
383
+ }
384
+ codeBlocks.push(currentCodeBlock);
385
+ currentCodeBlock = null;
386
+ }
387
+ }
388
+ else if (currentCodeBlock !== null) {
389
+ if (currentCodeBlock.content !== '') {
390
+ currentCodeBlock.content += '\n';
391
+ }
392
+ currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
393
+ }
394
+ }
395
+ }
396
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
397
+ finally {
398
+ try {
399
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
400
+ }
401
+ finally { if (e_1) throw e_1.error; }
402
+ }
403
+ if (currentCodeBlock !== null) {
404
+ // [🌻]
405
+ throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
406
+ }
407
+ return codeBlocks;
408
+ }
409
+
410
+ /**
411
+ * Extracts exactly ONE code block from markdown.
412
+ *
413
+ * Note: If there are multiple or no code blocks the function throws an error
414
+ *
415
+ * Note: There are 3 simmilar function:
416
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
417
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
418
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
419
+ *
420
+ * @param markdown any valid markdown
421
+ * @returns code block with language and content
422
+ */
423
+ function extractOneBlockFromMarkdown(markdown) {
424
+ var codeBlocks = extractAllBlocksFromMarkdown(markdown);
425
+ if (codeBlocks.length !== 1) {
426
+ // TODO: Report more specific place where the error happened
427
+ throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
428
+ }
429
+ return codeBlocks[0];
430
+ }
431
+ /***
432
+ * TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
433
+ */
434
+
126
435
  /**
127
436
  * Removes HTML or Markdown comments from a string.
128
437
  *
@@ -130,36 +439,86 @@
130
439
  * @returns {string} The input string with all comments removed.
131
440
  */
132
441
  function removeContentComments(content) {
133
- return spacetrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
442
+ return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
134
443
  }
135
444
 
136
445
  /**
137
- * This error type indicates that the error should not happen and its last check before crashing with some other error
446
+ * The version of the Promptbook library
138
447
  */
139
- var UnexpectedError = /** @class */ (function (_super) {
140
- __extends(UnexpectedError, _super);
141
- function UnexpectedError(message) {
142
- var _this = _super.call(this, spacetrim.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;
143
- _this.name = 'UnexpectedError';
144
- Object.setPrototypeOf(_this, UnexpectedError.prototype);
145
- return _this;
146
- }
147
- return UnexpectedError;
148
- }(Error));
448
+ var PROMPTBOOK_VERSION = '0.48.0-0';
149
449
 
150
450
  /**
151
- * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
451
+ * Parses the given script and returns the list of all used variables that are not defined in the script
452
+ *
453
+ * @param script from which to extract the variables
454
+ * @returns the list of variable names
455
+ * @throws {PromptbookSyntaxError} if the script is invalid
456
+ *
457
+ * @private within the promptbookStringToJson
152
458
  */
153
- var PromptbookSyntaxError = /** @class */ (function (_super) {
154
- __extends(PromptbookSyntaxError, _super);
155
- function PromptbookSyntaxError(message) {
156
- var _this = _super.call(this, message) || this;
157
- _this.name = 'PromptbookSyntaxError';
158
- Object.setPrototypeOf(_this, PromptbookSyntaxError.prototype);
159
- return _this;
459
+ function extractVariables(script) {
460
+ var variables = [];
461
+ script = "(()=>{".concat(script, "})()");
462
+ try {
463
+ for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
464
+ try {
465
+ eval(script);
466
+ }
467
+ catch (error) {
468
+ if (!(error instanceof ReferenceError)) {
469
+ throw error;
470
+ }
471
+ var undefinedName = error.message.split(' ')[0];
472
+ /*
473
+ Note: Remapping error
474
+ From: [ReferenceError: thing is not defined],
475
+ To: [Error: Parameter {thing} is not defined],
476
+ */
477
+ if (!undefinedName) {
478
+ throw error;
479
+ }
480
+ if (script.includes(undefinedName + '(')) {
481
+ script = "const ".concat(undefinedName, " = ()=>'';") + script;
482
+ }
483
+ else {
484
+ variables.push(undefinedName);
485
+ script = "const ".concat(undefinedName, " = '';") + script;
486
+ }
487
+ }
160
488
  }
161
- return PromptbookSyntaxError;
162
- }(Error));
489
+ catch (error) {
490
+ if (!(error instanceof Error)) {
491
+ throw error;
492
+ }
493
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
494
+ }
495
+ return variables;
496
+ }
497
+
498
+ /**
499
+ * Removes emojis from a string and fix whitespaces
500
+ *
501
+ * @param text with emojis
502
+ * @returns text without emojis
503
+ */
504
+ function removeEmojis(text) {
505
+ // Replace emojis (and also ZWJ sequence) with hyphens
506
+ text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
507
+ text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
508
+ text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
509
+ text = text.replace(/\p{Extended_Pictographic}/gu, '');
510
+ return text;
511
+ }
512
+
513
+ /**
514
+ * Function normalizes title to name which can be used as identifier
515
+ */
516
+ function titleToName(value) {
517
+ value = removeEmojis(value);
518
+ value = normalizeToKebabCase(value);
519
+ // TODO: [🧠] Maybe warn or add some padding to short name which are not good identifiers
520
+ return value;
521
+ }
163
522
 
164
523
  /**
165
524
  * Function parseNumber will parse number from string
@@ -535,11 +894,10 @@
535
894
  var letters = defaultDiacriticsRemovalMap[i].letters;
536
895
  // tslint:disable-next-line: prefer-for-of
537
896
  for (var j = 0; j < letters.length; j++) {
538
- DIACRITIC_VARIANTS_LETTERS[letters[j]] =
539
- defaultDiacriticsRemovalMap[i].base;
897
+ DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
540
898
  }
541
899
  }
542
- // <- TODO: !!!! Put to maker function
900
+ // <- TODO: [🍓] Put to maker function to save execution time if not needed
543
901
  /*
544
902
  @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
545
903
  Licensed under the Apache License, Version 2.0 (the "License");
@@ -622,11 +980,6 @@
622
980
  * TODO: [💝] Unite object for expecting amount and format
623
981
  */
624
982
 
625
- /**
626
- * The maximum number of iterations for a loops
627
- */
628
- var LOOP_LIMIT = 1000;
629
-
630
983
  /**
631
984
  * This error occurs during the parameter replacement in the template
632
985
  *
@@ -697,158 +1050,30 @@
697
1050
  throw new TemplateError('Parameter is not closed');
698
1051
  }
699
1052
  // [💫] Check if there are parameters that are not opened properly
700
- if (/^\w+}/.test(replacedTemplate)) {
701
- throw new TemplateError('Parameter is not opened');
702
- }
703
- return replacedTemplate;
704
- }
705
-
706
- /**
707
- * Function isValidJsonString will tell you if the string is valid JSON or not
708
- */
709
- function isValidJsonString(value) {
710
- try {
711
- JSON.parse(value);
712
- return true;
713
- }
714
- catch (error) {
715
- if (!(error instanceof Error)) {
716
- throw error;
717
- }
718
- if (error.message.includes('Unexpected token')) {
719
- return false;
720
- }
721
- return false;
722
- }
723
- }
724
-
725
- /**
726
- * Makes first letter of a string uppercase
727
- *
728
- */
729
- function capitalize(word) {
730
- return word.substring(0, 1).toUpperCase() + word.substring(1);
731
- }
732
-
733
- /**
734
- * Extracts all code blocks from markdown.
735
- *
736
- * Note: There are 3 simmilar function:
737
- * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
738
- * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
739
- * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
740
- *
741
- * @param markdown any valid markdown
742
- * @returns code blocks with language and content
743
- *
744
- */
745
- function extractAllBlocksFromMarkdown(markdown) {
746
- var e_1, _a;
747
- var codeBlocks = [];
748
- var lines = markdown.split('\n');
749
- var currentCodeBlock = null;
750
- try {
751
- for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
752
- var line = lines_1_1.value;
753
- if (line.startsWith('```')) {
754
- var language = line.slice(3).trim() || null;
755
- if (currentCodeBlock === null) {
756
- currentCodeBlock = { language: language, content: '' };
757
- }
758
- else {
759
- if (language !== null) {
760
- // [🌻]
761
- throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
762
- }
763
- codeBlocks.push(currentCodeBlock);
764
- currentCodeBlock = null;
765
- }
766
- }
767
- else if (currentCodeBlock !== null) {
768
- if (currentCodeBlock.content !== '') {
769
- currentCodeBlock.content += '\n';
770
- }
771
- currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
772
- }
773
- }
774
- }
775
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
776
- finally {
777
- try {
778
- if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
779
- }
780
- finally { if (e_1) throw e_1.error; }
781
- }
782
- if (currentCodeBlock !== null) {
783
- // [🌻]
784
- throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
785
- }
786
- return codeBlocks;
787
- }
788
-
789
- /**
790
- * Utility function to extract all list items from markdown
791
- *
792
- * Note: It works with both ul and ol
793
- * Note: It omits list items in code blocks
794
- * Note: It flattens nested lists
795
- * Note: It can not work with html syntax and comments
796
- *
797
- * @param markdown any valid markdown
798
- * @returns
799
- */
800
- function extractAllListItemsFromMarkdown(markdown) {
801
- var e_1, _a;
802
- var lines = markdown.split('\n');
803
- var listItems = [];
804
- var isInCodeBlock = false;
805
- try {
806
- for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
807
- var line = lines_1_1.value;
808
- var trimmedLine = line.trim();
809
- if (trimmedLine.startsWith('```')) {
810
- isInCodeBlock = !isInCodeBlock;
811
- }
812
- if (!isInCodeBlock && (trimmedLine.startsWith('-') || trimmedLine.match(/^\d+\./))) {
813
- var listItem = trimmedLine.replace(/^-|\d+\./, '').trim();
814
- listItems.push(listItem);
815
- }
816
- }
817
- }
818
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
819
- finally {
820
- try {
821
- if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
822
- }
823
- finally { if (e_1) throw e_1.error; }
824
- }
825
- return listItems;
826
- }
827
-
828
- /**
829
- * Extracts exactly ONE code block from markdown.
830
- *
831
- * Note: If there are multiple or no code blocks the function throws an error
832
- *
833
- * Note: There are 3 simmilar function:
834
- * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
835
- * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
836
- * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
837
- *
838
- * @param markdown any valid markdown
839
- * @returns code block with language and content
840
- */
841
- function extractOneBlockFromMarkdown(markdown) {
842
- var codeBlocks = extractAllBlocksFromMarkdown(markdown);
843
- if (codeBlocks.length !== 1) {
844
- // TODO: Report more specific place where the error happened
845
- throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
1053
+ if (/^\w+}/.test(replacedTemplate)) {
1054
+ throw new TemplateError('Parameter is not opened');
846
1055
  }
847
- return codeBlocks[0];
1056
+ return replacedTemplate;
848
1057
  }
849
- /***
850
- * TODO: [🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
1058
+
1059
+ /**
1060
+ * Function isValidJsonString will tell you if the string is valid JSON or not
851
1061
  */
1062
+ function isValidJsonString(value) {
1063
+ try {
1064
+ JSON.parse(value);
1065
+ return true;
1066
+ }
1067
+ catch (error) {
1068
+ if (!(error instanceof Error)) {
1069
+ throw error;
1070
+ }
1071
+ if (error.message.includes('Unexpected token')) {
1072
+ return false;
1073
+ }
1074
+ return false;
1075
+ }
1076
+ }
852
1077
 
853
1078
  /**
854
1079
  * Removes Markdown formatting tags from a string.
@@ -931,11 +1156,11 @@
931
1156
  */
932
1157
 
933
1158
  /* tslint:disable */
934
- function normalizeTo_camelCase(sentence, __firstLetterCapital) {
1159
+ function normalizeToKebabCase(sentence) {
935
1160
  var e_1, _a;
936
- if (__firstLetterCapital === void 0) { __firstLetterCapital = false; }
1161
+ sentence = removeDiacritics(sentence);
937
1162
  var charType;
938
- var lastCharType = null;
1163
+ var lastCharType = 'OTHER';
939
1164
  var normalizedName = '';
940
1165
  try {
941
1166
  for (var sentence_1 = __values(sentence), sentence_1_1 = sentence_1.next(); !sentence_1_1.done; sentence_1_1 = sentence_1.next()) {
@@ -953,20 +1178,19 @@
953
1178
  charType = 'NUMBER';
954
1179
  normalizedChar = char;
955
1180
  }
1181
+ else if (/^\/$/.test(char)) {
1182
+ charType = 'SLASH';
1183
+ normalizedChar = char;
1184
+ }
956
1185
  else {
957
1186
  charType = 'OTHER';
958
- normalizedChar = '';
1187
+ normalizedChar = '-';
959
1188
  }
960
- if (!lastCharType) {
961
- if (__firstLetterCapital) {
962
- normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
963
- }
964
- }
965
- else if (charType !== lastCharType &&
966
- !(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
1189
+ if (charType !== lastCharType &&
1190
+ !(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
967
1191
  !(lastCharType === 'NUMBER') &&
968
1192
  !(charType === 'NUMBER')) {
969
- normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
1193
+ normalizedName += '-';
970
1194
  }
971
1195
  normalizedName += normalizedChar;
972
1196
  lastCharType = charType;
@@ -979,212 +1203,12 @@
979
1203
  }
980
1204
  finally { if (e_1) throw e_1.error; }
981
1205
  }
1206
+ normalizedName = normalizedName.split(/-+/g).join('-');
1207
+ normalizedName = normalizedName.split(/-?\/-?/g).join('/');
1208
+ normalizedName = normalizedName.replace(/^-/, '');
1209
+ normalizedName = normalizedName.replace(/-$/, '');
982
1210
  return normalizedName;
983
1211
  }
984
- /**
985
- * TODO: [🌺] Use some intermediate util splitWords
986
- */
987
-
988
- function normalizeTo_PascalCase(sentence) {
989
- return normalizeTo_camelCase(sentence, true);
990
- }
991
-
992
- /**
993
- * Supported script languages
994
- */
995
- var SUPPORTED_SCRIPT_LANGUAGES = ['javascript', 'typescript', 'python'];
996
-
997
- /**
998
- * Parses the template and returns the list of all parameter names
999
- *
1000
- * @param template the template with parameters in {curly} braces
1001
- * @returns the list of parameter names
1002
- *
1003
- * @private within the library
1004
- */
1005
- function extractParameters(template) {
1006
- var e_1, _a;
1007
- var matches = template.matchAll(/{\w+}/g);
1008
- var parameterNames = [];
1009
- try {
1010
- for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
1011
- var match = matches_1_1.value;
1012
- var parameterName = match[0].slice(1, -1);
1013
- if (!parameterNames.includes(parameterName)) {
1014
- parameterNames.push(parameterName);
1015
- }
1016
- }
1017
- }
1018
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1019
- finally {
1020
- try {
1021
- if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
1022
- }
1023
- finally { if (e_1) throw e_1.error; }
1024
- }
1025
- return parameterNames;
1026
- }
1027
-
1028
- /**
1029
- * Computes the deepness of the markdown structure.
1030
- *
1031
- * @private within the library
1032
- */
1033
- function countMarkdownStructureDeepness(markdownStructure) {
1034
- var e_1, _a;
1035
- var maxDeepness = 0;
1036
- try {
1037
- for (var _b = __values(markdownStructure.sections), _c = _b.next(); !_c.done; _c = _b.next()) {
1038
- var section = _c.value;
1039
- maxDeepness = Math.max(maxDeepness, countMarkdownStructureDeepness(section));
1040
- }
1041
- }
1042
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1043
- finally {
1044
- try {
1045
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1046
- }
1047
- finally { if (e_1) throw e_1.error; }
1048
- }
1049
- return maxDeepness + 1;
1050
- }
1051
-
1052
- /**
1053
- * Parse a markdown string into a MarkdownStructure object.
1054
- *
1055
- * Note: This function does work with code blocks
1056
- * Note: This function does not work with markdown comments
1057
- *
1058
- * @param markdown The markdown string to parse.
1059
- * @returns The MarkdownStructure object.
1060
- *
1061
- * @private within the library
1062
- */
1063
- function markdownToMarkdownStructure(markdown) {
1064
- var e_1, _a;
1065
- var lines = markdown.split('\n');
1066
- var root = { level: 0, title: '', contentLines: [], sections: [], parent: null };
1067
- var current = root;
1068
- var isInsideCodeBlock = false;
1069
- try {
1070
- for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
1071
- var line = lines_1_1.value;
1072
- var headingMatch = line.match(/^(?<mark>#{1,6})\s(?<title>.*)/);
1073
- if (isInsideCodeBlock || !headingMatch) {
1074
- if (line.startsWith('```')) {
1075
- isInsideCodeBlock = !isInsideCodeBlock;
1076
- }
1077
- current.contentLines.push(line);
1078
- }
1079
- else {
1080
- var level = headingMatch.groups.mark.length;
1081
- var title = headingMatch.groups.title.trim();
1082
- var parent_1 = void 0;
1083
- if (level > current.level) {
1084
- // Note: Going deeper (next section is child of current)
1085
- parent_1 = current;
1086
- }
1087
- else {
1088
- // Note: Going up or staying at the same level (next section is sibling or parent or grandparent,... of current)
1089
- parent_1 = current;
1090
- var loopLimit = LOOP_LIMIT;
1091
- while (parent_1.level !== level - 1) {
1092
- if (loopLimit-- < 0) {
1093
- throw new UnexpectedError('Loop limit reached during parsing of markdown structure in `markdownToMarkdownStructure`');
1094
- }
1095
- if (parent_1.parent === null /* <- Note: We are in root */) {
1096
- // [🌻]
1097
- throw new Error(spacetrim.spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
1098
- }
1099
- parent_1 = parent_1.parent;
1100
- }
1101
- }
1102
- var section = { level: level, title: title, contentLines: [], sections: [], parent: parent_1 };
1103
- parent_1.sections.push(section);
1104
- current = section;
1105
- }
1106
- }
1107
- }
1108
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1109
- finally {
1110
- try {
1111
- if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
1112
- }
1113
- finally { if (e_1) throw e_1.error; }
1114
- }
1115
- if (root.sections.length === 1) {
1116
- var markdownStructure = parsingMarkdownStructureToMarkdownStructure(root.sections[0]);
1117
- return markdownStructure;
1118
- }
1119
- // [🌻]
1120
- throw new Error('The markdown file must have exactly one top-level section.');
1121
- // return root;
1122
- }
1123
- /**
1124
- * @private
1125
- */
1126
- function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
1127
- var level = parsingMarkdownStructure.level, title = parsingMarkdownStructure.title, contentLines = parsingMarkdownStructure.contentLines, sections = parsingMarkdownStructure.sections;
1128
- return {
1129
- level: level,
1130
- title: title,
1131
- content: spacetrim.spaceTrim(contentLines.join('\n')),
1132
- sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
1133
- };
1134
- }
1135
-
1136
- /**
1137
- * The version of the Promptbook library
1138
- */
1139
- var PROMPTBOOK_VERSION = '0.47.0-0';
1140
-
1141
- /**
1142
- * Parses the given script and returns the list of all used variables that are not defined in the script
1143
- *
1144
- * @param script from which to extract the variables
1145
- * @returns the list of variable names
1146
- * @throws {PromptbookSyntaxError} if the script is invalid
1147
- *
1148
- * @private within the promptbookStringToJson
1149
- */
1150
- function extractVariables(script) {
1151
- var variables = [];
1152
- script = "(()=>{".concat(script, "})()");
1153
- try {
1154
- for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
1155
- try {
1156
- eval(script);
1157
- }
1158
- catch (error) {
1159
- if (!(error instanceof ReferenceError)) {
1160
- throw error;
1161
- }
1162
- var undefinedName = error.message.split(' ')[0];
1163
- /*
1164
- Note: Remapping error
1165
- From: [ReferenceError: thing is not defined],
1166
- To: [Error: Parameter {thing} is not defined],
1167
- */
1168
- if (!undefinedName) {
1169
- throw error;
1170
- }
1171
- if (script.includes(undefinedName + '(')) {
1172
- script = "const ".concat(undefinedName, " = ()=>'';") + script;
1173
- }
1174
- else {
1175
- variables.push(undefinedName);
1176
- script = "const ".concat(undefinedName, " = '';") + script;
1177
- }
1178
- }
1179
- }
1180
- catch (error) {
1181
- if (!(error instanceof Error)) {
1182
- throw error;
1183
- }
1184
- throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
1185
- }
1186
- return variables;
1187
- }
1188
1212
 
1189
1213
  /**
1190
1214
  * Execution type describes the way how the block is executed
@@ -1246,15 +1270,15 @@
1246
1270
  type.startsWith('PROMPTBOOKURL') ||
1247
1271
  type.startsWith('HTTPS')) {
1248
1272
  if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
1249
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
1273
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
1250
1274
  }
1251
1275
  var promptbookUrlString = listItemParts.pop();
1252
1276
  var promptbookUrl = new URL(promptbookUrlString);
1253
1277
  if (promptbookUrl.protocol !== 'https:') {
1254
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
1278
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
1255
1279
  }
1256
1280
  if (promptbookUrl.hash !== '') {
1257
- throw new PromptbookSyntaxError(spacetrim.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 ")));
1281
+ throw new PromptbookSyntaxError(spaceTrim.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 ")));
1258
1282
  }
1259
1283
  return {
1260
1284
  type: 'PROMPTBOOK_URL',
@@ -1263,7 +1287,7 @@
1263
1287
  }
1264
1288
  else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
1265
1289
  if (listItemParts.length !== 2) {
1266
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
1290
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
1267
1291
  }
1268
1292
  var promptbookVersion = listItemParts.pop();
1269
1293
  // TODO: Validate version
@@ -1278,7 +1302,7 @@
1278
1302
  type.startsWith('SIMPLE_TEMPLATE')) {
1279
1303
  var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
1280
1304
  if (executionTypes.length !== 1) {
1281
- throw new PromptbookSyntaxError(spacetrim.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 "); }));
1305
+ throw new PromptbookSyntaxError(spaceTrim.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 "); }));
1282
1306
  }
1283
1307
  return {
1284
1308
  type: 'EXECUTE',
@@ -1303,7 +1327,7 @@
1303
1327
  };
1304
1328
  }
1305
1329
  else {
1306
- throw new PromptbookSyntaxError(spacetrim.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 "); }));
1330
+ throw new PromptbookSyntaxError(spaceTrim.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 "); }));
1307
1331
  }
1308
1332
  }
1309
1333
  if (type.startsWith('MODEL_NAME')) {
@@ -1314,7 +1338,7 @@
1314
1338
  };
1315
1339
  }
1316
1340
  else {
1317
- throw new PromptbookSyntaxError(spacetrim.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 "); }));
1341
+ throw new PromptbookSyntaxError(spaceTrim.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 "); }));
1318
1342
  }
1319
1343
  }
1320
1344
  else if (type.startsWith('PARAM') ||
@@ -1324,12 +1348,12 @@
1324
1348
  listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
1325
1349
  var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
1326
1350
  if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
1327
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1351
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1328
1352
  }
1329
1353
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1330
1354
  var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
1331
1355
  if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
1332
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
1356
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
1333
1357
  }
1334
1358
  var isInput = type.startsWith('INPUT');
1335
1359
  var isOutput = type.startsWith('OUTPUT');
@@ -1347,11 +1371,11 @@
1347
1371
  }
1348
1372
  else if (type.startsWith('JOKER')) {
1349
1373
  if (listItemParts.length !== 2) {
1350
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
1374
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
1351
1375
  }
1352
1376
  var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
1353
1377
  if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
1354
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1378
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1355
1379
  }
1356
1380
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1357
1381
  var parameterName = parametersMatch.groups.parameterName;
@@ -1362,7 +1386,7 @@
1362
1386
  }
1363
1387
  else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
1364
1388
  if (listItemParts.length !== 2) {
1365
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
1389
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
1366
1390
  }
1367
1391
  var functionName = listItemParts.pop();
1368
1392
  return {
@@ -1442,7 +1466,7 @@
1442
1466
  if (!(error instanceof Error)) {
1443
1467
  throw error;
1444
1468
  }
1445
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
1469
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
1446
1470
  }
1447
1471
  /*
1448
1472
  } else if (type.startsWith('__________________')) {
@@ -1450,7 +1474,7 @@
1450
1474
  */
1451
1475
  }
1452
1476
  else {
1453
- throw new PromptbookSyntaxError(spacetrim.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 ")));
1477
+ throw new PromptbookSyntaxError(spaceTrim.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 ")));
1454
1478
  }
1455
1479
  }
1456
1480
 
@@ -1486,7 +1510,7 @@
1486
1510
  existingParameter.description &&
1487
1511
  existingParameter.description !== parameterDescription &&
1488
1512
  parameterDescription) {
1489
- throw new PromptbookSyntaxError(spacetrim.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 "); }));
1513
+ throw new PromptbookSyntaxError(spaceTrim.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 "); }));
1490
1514
  }
1491
1515
  if (existingParameter) {
1492
1516
  if (parameterDescription) {
@@ -1507,7 +1531,7 @@
1507
1531
  var markdownStructure = markdownToMarkdownStructure(promptbookString);
1508
1532
  var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
1509
1533
  if (markdownStructureDeepness !== 2) {
1510
- throw new PromptbookSyntaxError(spacetrim.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 ")));
1534
+ throw new PromptbookSyntaxError(spaceTrim.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 ")));
1511
1535
  }
1512
1536
  promptbookJson.title = markdownStructure.title;
1513
1537
  // TODO: [1] DRY description
@@ -1516,7 +1540,7 @@
1516
1540
  description = description.split(/^```.*^```/gms).join('');
1517
1541
  //Note: Remove lists and return statement
1518
1542
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
1519
- description = spacetrim.spaceTrim(description);
1543
+ description = spaceTrim.spaceTrim(description);
1520
1544
  if (description === '') {
1521
1545
  description = undefined;
1522
1546
  }
@@ -1631,13 +1655,13 @@
1631
1655
  throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
1632
1656
  }
1633
1657
  else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
1634
- throw new PromptbookSyntaxError(spacetrim.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 "); }));
1658
+ throw new PromptbookSyntaxError(spaceTrim.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 "); }));
1635
1659
  }
1636
1660
  }
1637
1661
  var lastLine = section.content.split('\n').pop();
1638
1662
  var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
1639
1663
  if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
1640
- throw new PromptbookSyntaxError(spacetrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
1664
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
1641
1665
  // TODO: Show code of invalid sections each time + DRY
1642
1666
  section.content
1643
1667
  .split('\n')
@@ -1651,7 +1675,7 @@
1651
1675
  description_1 = description_1.split(/^```.*^```/gms).join('');
1652
1676
  //Note: Remove lists and return statement
1653
1677
  description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
1654
- description_1 = spacetrim.spaceTrim(description_1);
1678
+ description_1 = spaceTrim.spaceTrim(description_1);
1655
1679
  if (description_1 === '') {
1656
1680
  description_1 = undefined;
1657
1681
  }
@@ -1694,7 +1718,7 @@
1694
1718
  }
1695
1719
  dependentParameterNames = __spreadArray([], __read(new Set(dependentParameterNames)), false);
1696
1720
  promptbookJson.promptTemplates.push({
1697
- name: normalizeTo_PascalCase(section.title),
1721
+ name: titleToName(section.title),
1698
1722
  title: section.title,
1699
1723
  description: description_1,
1700
1724
  dependentParameterNames: dependentParameterNames,
@@ -1731,6 +1755,15 @@
1731
1755
  * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
1732
1756
  */
1733
1757
 
1758
+ function promptbookJsonToString(promptbookJson) {
1759
+ return spaceTrim__default["default"](function (block) { return "\n\n # ".concat(block(promptbookJson.title), "\n\n "); });
1760
+ }
1761
+ /**
1762
+ * TODO: !!!!! Implement
1763
+ * TODO: !!!!! Annotate and warn
1764
+ * TODO: !!!!! Test + test together with promptbookStringToJson
1765
+ */
1766
+
1734
1767
  /**
1735
1768
  * This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
1736
1769
  */
@@ -1799,12 +1832,12 @@
1799
1832
  if (!parameter.isInput &&
1800
1833
  !parameter.isOutput &&
1801
1834
  !promptbook.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
1802
- throw new PromptbookLogicError(spacetrim.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 ")));
1835
+ throw new PromptbookLogicError(spaceTrim.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 ")));
1803
1836
  }
1804
1837
  // Note: Testing that parameter is either input or result of some template
1805
1838
  if (!parameter.isInput &&
1806
1839
  !promptbook.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
1807
- throw new PromptbookLogicError(spacetrim.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 ")));
1840
+ throw new PromptbookLogicError(spaceTrim.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 ")));
1808
1841
  }
1809
1842
  };
1810
1843
  try {
@@ -1839,7 +1872,7 @@
1839
1872
  if (template.executionType === 'PROMPT_TEMPLATE' &&
1840
1873
  (template.modelRequirements.modelVariant === undefined ||
1841
1874
  template.modelRequirements.modelName === undefined)) {
1842
- throw new PromptbookLogicError(spacetrim.spaceTrim("\n\n You must specify MODEL VARIANT and MODEL NAME in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
1875
+ throw new PromptbookLogicError(spaceTrim.spaceTrim("\n\n You must specify MODEL VARIANT and MODEL NAME in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
1843
1876
  }
1844
1877
  if (template.jokers && template.jokers.length > 0) {
1845
1878
  if (!template.expectFormat &&
@@ -1914,7 +1947,7 @@
1914
1947
  return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
1915
1948
  });
1916
1949
  if (currentlyResovedTemplates.length === 0) {
1917
- throw new PromptbookLogicError(spacetrim.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
1950
+ throw new PromptbookLogicError(spaceTrim.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
1918
1951
  .map(function (_a) {
1919
1952
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
1920
1953
  return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
@@ -2087,7 +2120,7 @@
2087
2120
  throw errors[0];
2088
2121
  }
2089
2122
  else {
2090
- throw new PromptbookExecutionError(spacetrim.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 "); }));
2123
+ throw new PromptbookExecutionError(spaceTrim.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 "); }));
2091
2124
  }
2092
2125
  }
2093
2126
  });
@@ -2171,7 +2204,7 @@
2171
2204
  throw scriptExecutionErrors[0];
2172
2205
  }
2173
2206
  else {
2174
- throw new PromptbookExecutionError(spacetrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
2207
+ throw new PromptbookExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
2175
2208
  .map(function (error) { return '- ' + error.message; })
2176
2209
  .join('\n\n')), "\n "); }));
2177
2210
  }
@@ -2311,7 +2344,7 @@
2311
2344
  return [7 /*endfinally*/];
2312
2345
  case 47:
2313
2346
  if (expectError !== null && attempt === maxAttempts - 1) {
2314
- throw new PromptbookExecutionError(spacetrim.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 "); }));
2347
+ throw new PromptbookExecutionError(spaceTrim.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 "); }));
2315
2348
  }
2316
2349
  _o.label = 48;
2317
2350
  case 48:
@@ -2380,7 +2413,7 @@
2380
2413
  return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
2381
2414
  });
2382
2415
  if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
2383
- throw new UnexpectedError(spacetrim.spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePromptbookJson\n "));
2416
+ throw new UnexpectedError(spaceTrim.spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePromptbookJson\n "));
2384
2417
  case 1:
2385
2418
  if (!!currentTemplate) return [3 /*break*/, 3];
2386
2419
  /* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
@@ -2480,7 +2513,7 @@
2480
2513
  case 1:
2481
2514
  answer = _a.sent();
2482
2515
  if (this.options.isVerbose) {
2483
- console.info(spacetrim.spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer), "\n "); }));
2516
+ console.info(spaceTrim.spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer), "\n "); }));
2484
2517
  }
2485
2518
  return [2 /*return*/, answer];
2486
2519
  }
@@ -2507,9 +2540,9 @@
2507
2540
  return __awaiter(this, void 0, void 0, function () {
2508
2541
  var answer;
2509
2542
  return __generator(this, function (_a) {
2510
- answer = window.prompt(spacetrim.spaceTrim(function (block) { return "\n ".concat(block(options.promptTitle), "\n\n ").concat(block(options.promptMessage), "\n "); }));
2543
+ answer = window.prompt(spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(options.promptTitle), "\n\n ").concat(block(options.promptMessage), "\n "); }));
2511
2544
  if (this.options.isVerbose) {
2512
- console.info(spacetrim.spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer || '🚫 User cancelled prompt'), "\n "); }));
2545
+ console.info(spaceTrim.spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer || '🚫 User cancelled prompt'), "\n "); }));
2513
2546
  }
2514
2547
  if (answer === null) {
2515
2548
  throw new PromptbookExecutionError('User cancelled prompt');
@@ -2556,7 +2589,8 @@
2556
2589
  * @see https://github.com/webgptorg/promptbook#promptbook-library
2557
2590
  */
2558
2591
  var SimplePromptbookLibrary = /** @class */ (function () {
2559
- /**!!!
2592
+ /**
2593
+ * Constructs a promptbook library from promptbooks
2560
2594
  *
2561
2595
  * @param promptbooks !!!
2562
2596
  *
@@ -2574,7 +2608,7 @@
2574
2608
  for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
2575
2609
  var promptbook = promptbooks_1_1.value;
2576
2610
  if (promptbook.promptbookUrl === undefined) {
2577
- throw new PromptbookReferenceError(spacetrim.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 ")));
2611
+ throw new PromptbookReferenceError(spaceTrim.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 ")));
2578
2612
  }
2579
2613
  validatePromptbookJson(promptbook);
2580
2614
  this.library.set(promptbook.promptbookUrl, promptbook);
@@ -2603,7 +2637,7 @@
2603
2637
  var _this = this;
2604
2638
  var promptbook = this.library.get(url);
2605
2639
  if (!promptbook) {
2606
- throw new PromptbookNotFoundError(spacetrim.spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
2640
+ throw new PromptbookNotFoundError(spaceTrim.spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
2607
2641
  .map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
2608
2642
  .join('\n')), "\n\n "); }));
2609
2643
  }
@@ -2618,6 +2652,15 @@
2618
2652
  return SimplePromptbookLibrary;
2619
2653
  }());
2620
2654
 
2655
+ /**
2656
+ * Creates PromptbookLibrary from array of PromptbookJson or PromptbookString
2657
+ *
2658
+ * Note: You can combine `PromptbookString` (`.ptbk.md`) with `PromptbookJson` BUT it is not recommended
2659
+ * Note: During the construction syntax and logic of all sources are validated
2660
+ *
2661
+ * @param promptbookSources
2662
+ * @returns PromptbookLibrary
2663
+ */
2621
2664
  function createPromptbookLibraryFromSources() {
2622
2665
  var e_1, _a;
2623
2666
  var promptbookSources = [];
@@ -2649,20 +2692,29 @@
2649
2692
  }
2650
2693
  return new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))();
2651
2694
  }
2695
+ /***
2696
+ * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
2697
+ */
2698
+
2652
2699
  /**
2653
- * Constructs Promptbook from any sources
2700
+ * Constructs Promptbook from async sources
2701
+ * It can be one of the following:
2702
+ * - Promise of array of PromptbookJson or PromptbookString
2703
+ * - Factory function that returns Promise of array of PromptbookJson or PromptbookString
2654
2704
  *
2655
- * Note: During the construction syntax and logic of all sources are validated
2656
- * Note: You can combine .ptbk.md and .ptbk.json files BUT it is not recommended
2705
+ * Note: This is useful as internal tool for other constructor functions like
2706
+ * `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
2707
+ * Consider using those functions instead of this one
2708
+ *
2709
+ * Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
2710
+ * when error occurs in given promise or factory function, it is thrown during `listPromptbooks` or `getPromptbookByUrl` call
2657
2711
  *
2658
- * @param promptbookSources contents of .ptbk.md or .ptbk.json files
2659
- * @param settings settings for creating executor functions
2712
+ *
2713
+ * @param promptbookSourcesPromiseOrFactory
2660
2714
  * @returns PromptbookLibrary
2715
+ *
2716
+ * @deprecated Consider using `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
2661
2717
  */
2662
- /***
2663
- * TODO: !!! Annotate all + all to README and samples
2664
- */
2665
-
2666
2718
  function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
2667
2719
  var library;
2668
2720
  function forSources() {
@@ -2727,9 +2779,18 @@
2727
2779
  };
2728
2780
  }
2729
2781
  /***
2730
- * TODO: !!! Annotate all + all to README and samples
2782
+ * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
2731
2783
  */
2732
2784
 
2785
+ /**
2786
+ * Creates PromptbookLibrary as a subset of another PromptbookLibrary
2787
+ *
2788
+ * Note: You can use any type of library as a parent library - local, remote, etc.
2789
+ * Note: This is just a thin wrapper / proxy around the parent library
2790
+ *
2791
+ * @param promptbookSources
2792
+ * @returns PromptbookLibrary
2793
+ */
2733
2794
  function createPromptbookSublibrary(library, predicate) {
2734
2795
  function listPromptbooks() {
2735
2796
  return __awaiter(this, void 0, void 0, function () {
@@ -2754,7 +2815,7 @@
2754
2815
  case 0:
2755
2816
  if (!!predicate(url)) return [3 /*break*/, 2];
2756
2817
  _a = PromptbookNotFoundError.bind;
2757
- return [4 /*yield*/, spacetrim.spaceTrim(function (block) { return __awaiter(_this, void 0, void 0, function () {
2818
+ return [4 /*yield*/, spaceTrim.spaceTrim(function (block) { return __awaiter(_this, void 0, void 0, function () {
2758
2819
  var _a, _b, _c, _d, _e, _f;
2759
2820
  return __generator(this, function (_g) {
2760
2821
  switch (_g.label) {
@@ -2800,7 +2861,7 @@
2800
2861
  };
2801
2862
  }
2802
2863
  /***
2803
- * TODO: !!! Annotate all + all to README and samples
2864
+ * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
2804
2865
  */
2805
2866
 
2806
2867
  exports.CallbackInterfaceTools = CallbackInterfaceTools;
@@ -2812,6 +2873,7 @@
2812
2873
  exports.createPromptbookLibraryFromPromise = createPromptbookLibraryFromPromise;
2813
2874
  exports.createPromptbookLibraryFromSources = createPromptbookLibraryFromSources;
2814
2875
  exports.createPromptbookSublibrary = createPromptbookSublibrary;
2876
+ exports.promptbookJsonToString = promptbookJsonToString;
2815
2877
  exports.promptbookStringToJson = promptbookStringToJson;
2816
2878
  exports.validatePromptbookJson = validatePromptbookJson;
2817
2879