@promptbook/core 0.47.0 → 0.48.0-0

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 (40) hide show
  1. package/README.md +9 -1
  2. package/esm/index.es.js +55 -19
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/_packages/core.index.d.ts +2 -1
  5. package/esm/typings/conversion/prettify/prettifyPromptbookStringCli.d.ts +1 -1
  6. package/esm/typings/conversion/promptbookJsonToString.d.ts +8 -0
  7. package/esm/typings/execution/ExecutionTools.d.ts +1 -1
  8. package/esm/typings/execution/LlmExecutionTools.d.ts +1 -0
  9. package/esm/typings/execution/plugins/llm-execution-tools/langtail/LangtailExecutionTools.d.ts +1 -1
  10. package/esm/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +1 -1
  11. package/esm/typings/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +4 -1
  12. package/esm/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +1 -0
  13. package/esm/typings/library/SimplePromptbookLibrary.d.ts +2 -1
  14. package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +10 -1
  15. package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +20 -1
  16. package/esm/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +5 -6
  17. package/esm/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +13 -0
  18. package/esm/typings/library/constructors/createPromptbookSublibrary.d.ts +10 -1
  19. package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
  20. package/package.json +1 -1
  21. package/umd/index.umd.js +99 -58
  22. package/umd/index.umd.js.map +1 -1
  23. package/umd/typings/_packages/core.index.d.ts +2 -1
  24. package/umd/typings/conversion/prettify/prettifyPromptbookStringCli.d.ts +1 -1
  25. package/umd/typings/conversion/promptbookJsonToString.d.ts +8 -0
  26. package/umd/typings/execution/ExecutionTools.d.ts +1 -1
  27. package/umd/typings/execution/LlmExecutionTools.d.ts +1 -0
  28. package/umd/typings/execution/plugins/llm-execution-tools/langtail/LangtailExecutionTools.d.ts +1 -1
  29. package/umd/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +1 -1
  30. package/umd/typings/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +4 -1
  31. package/umd/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +1 -0
  32. package/umd/typings/library/SimplePromptbookLibrary.d.ts +2 -1
  33. package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +10 -1
  34. package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +20 -1
  35. package/umd/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +5 -6
  36. package/umd/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +13 -0
  37. package/umd/typings/library/constructors/createPromptbookSublibrary.d.ts +10 -1
  38. package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
  39. package/esm/typings/library/constructors/createPromptbookLibraryFromList.d.ts +0 -5
  40. 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.
@@ -130,7 +134,7 @@
130
134
  * @returns {string} The input string with all comments removed.
131
135
  */
132
136
  function removeContentComments(content) {
133
- return spacetrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
137
+ return spaceTrim.spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
134
138
  }
135
139
 
136
140
  /**
@@ -139,7 +143,7 @@
139
143
  var UnexpectedError = /** @class */ (function (_super) {
140
144
  __extends(UnexpectedError, _super);
141
145
  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;
146
+ 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
147
  _this.name = 'UnexpectedError';
144
148
  Object.setPrototypeOf(_this, UnexpectedError.prototype);
145
149
  return _this;
@@ -535,11 +539,10 @@
535
539
  var letters = defaultDiacriticsRemovalMap[i].letters;
536
540
  // tslint:disable-next-line: prefer-for-of
537
541
  for (var j = 0; j < letters.length; j++) {
538
- DIACRITIC_VARIANTS_LETTERS[letters[j]] =
539
- defaultDiacriticsRemovalMap[i].base;
542
+ DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
540
543
  }
541
544
  }
542
- // <- TODO: !!!! Put to maker function
545
+ // <- TODO: [🍓] Put to maker function to save execution time if not needed
543
546
  /*
544
547
  @see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
545
548
  Licensed under the Apache License, Version 2.0 (the "License");
@@ -847,7 +850,7 @@
847
850
  return codeBlocks[0];
848
851
  }
849
852
  /***
850
- * TODO: [🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
853
+ * TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
851
854
  */
852
855
 
853
856
  /**
@@ -1094,7 +1097,7 @@
1094
1097
  }
1095
1098
  if (parent_1.parent === null /* <- Note: We are in root */) {
1096
1099
  // [🌻]
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 "));
1100
+ 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
1101
  }
1099
1102
  parent_1 = parent_1.parent;
1100
1103
  }
@@ -1128,7 +1131,7 @@
1128
1131
  return {
1129
1132
  level: level,
1130
1133
  title: title,
1131
- content: spacetrim.spaceTrim(contentLines.join('\n')),
1134
+ content: spaceTrim.spaceTrim(contentLines.join('\n')),
1132
1135
  sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
1133
1136
  };
1134
1137
  }
@@ -1136,7 +1139,7 @@
1136
1139
  /**
1137
1140
  * The version of the Promptbook library
1138
1141
  */
1139
- var PROMPTBOOK_VERSION = '0.47.0-0';
1142
+ var PROMPTBOOK_VERSION = '0.47.0';
1140
1143
 
1141
1144
  /**
1142
1145
  * Parses the given script and returns the list of all used variables that are not defined in the script
@@ -1181,7 +1184,7 @@
1181
1184
  if (!(error instanceof Error)) {
1182
1185
  throw error;
1183
1186
  }
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 "); }));
1187
+ 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
1188
  }
1186
1189
  return variables;
1187
1190
  }
@@ -1246,15 +1249,15 @@
1246
1249
  type.startsWith('PROMPTBOOKURL') ||
1247
1250
  type.startsWith('HTTPS')) {
1248
1251
  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 ")));
1252
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n ")));
1250
1253
  }
1251
1254
  var promptbookUrlString = listItemParts.pop();
1252
1255
  var promptbookUrl = new URL(promptbookUrlString);
1253
1256
  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 ")));
1257
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
1255
1258
  }
1256
1259
  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 ")));
1260
+ 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
1261
  }
1259
1262
  return {
1260
1263
  type: 'PROMPTBOOK_URL',
@@ -1263,7 +1266,7 @@
1263
1266
  }
1264
1267
  else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
1265
1268
  if (listItemParts.length !== 2) {
1266
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
1269
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
1267
1270
  }
1268
1271
  var promptbookVersion = listItemParts.pop();
1269
1272
  // TODO: Validate version
@@ -1278,7 +1281,7 @@
1278
1281
  type.startsWith('SIMPLE_TEMPLATE')) {
1279
1282
  var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
1280
1283
  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 "); }));
1284
+ 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
1285
  }
1283
1286
  return {
1284
1287
  type: 'EXECUTE',
@@ -1303,7 +1306,7 @@
1303
1306
  };
1304
1307
  }
1305
1308
  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 "); }));
1309
+ 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
1310
  }
1308
1311
  }
1309
1312
  if (type.startsWith('MODEL_NAME')) {
@@ -1314,7 +1317,7 @@
1314
1317
  };
1315
1318
  }
1316
1319
  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 "); }));
1320
+ 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
1321
  }
1319
1322
  }
1320
1323
  else if (type.startsWith('PARAM') ||
@@ -1324,12 +1327,12 @@
1324
1327
  listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
1325
1328
  var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
1326
1329
  if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
1327
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1330
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1328
1331
  }
1329
1332
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1330
1333
  var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
1331
1334
  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 ")));
1335
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
1333
1336
  }
1334
1337
  var isInput = type.startsWith('INPUT');
1335
1338
  var isOutput = type.startsWith('OUTPUT');
@@ -1347,11 +1350,11 @@
1347
1350
  }
1348
1351
  else if (type.startsWith('JOKER')) {
1349
1352
  if (listItemParts.length !== 2) {
1350
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
1353
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
1351
1354
  }
1352
1355
  var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
1353
1356
  if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
1354
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1357
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
1355
1358
  }
1356
1359
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1357
1360
  var parameterName = parametersMatch.groups.parameterName;
@@ -1362,7 +1365,7 @@
1362
1365
  }
1363
1366
  else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
1364
1367
  if (listItemParts.length !== 2) {
1365
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
1368
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
1366
1369
  }
1367
1370
  var functionName = listItemParts.pop();
1368
1371
  return {
@@ -1442,7 +1445,7 @@
1442
1445
  if (!(error instanceof Error)) {
1443
1446
  throw error;
1444
1447
  }
1445
- throw new PromptbookSyntaxError(spacetrim.spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
1448
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
1446
1449
  }
1447
1450
  /*
1448
1451
  } else if (type.startsWith('__________________')) {
@@ -1450,7 +1453,7 @@
1450
1453
  */
1451
1454
  }
1452
1455
  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 ")));
1456
+ 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
1457
  }
1455
1458
  }
1456
1459
 
@@ -1486,7 +1489,7 @@
1486
1489
  existingParameter.description &&
1487
1490
  existingParameter.description !== parameterDescription &&
1488
1491
  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 "); }));
1492
+ 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
1493
  }
1491
1494
  if (existingParameter) {
1492
1495
  if (parameterDescription) {
@@ -1507,7 +1510,7 @@
1507
1510
  var markdownStructure = markdownToMarkdownStructure(promptbookString);
1508
1511
  var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
1509
1512
  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 ")));
1513
+ 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
1514
  }
1512
1515
  promptbookJson.title = markdownStructure.title;
1513
1516
  // TODO: [1] DRY description
@@ -1516,7 +1519,7 @@
1516
1519
  description = description.split(/^```.*^```/gms).join('');
1517
1520
  //Note: Remove lists and return statement
1518
1521
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
1519
- description = spacetrim.spaceTrim(description);
1522
+ description = spaceTrim.spaceTrim(description);
1520
1523
  if (description === '') {
1521
1524
  description = undefined;
1522
1525
  }
@@ -1631,13 +1634,13 @@
1631
1634
  throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
1632
1635
  }
1633
1636
  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 "); }));
1637
+ 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
1638
  }
1636
1639
  }
1637
1640
  var lastLine = section.content.split('\n').pop();
1638
1641
  var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
1639
1642
  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(
1643
+ throw new PromptbookSyntaxError(spaceTrim.spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
1641
1644
  // TODO: Show code of invalid sections each time + DRY
1642
1645
  section.content
1643
1646
  .split('\n')
@@ -1651,7 +1654,7 @@
1651
1654
  description_1 = description_1.split(/^```.*^```/gms).join('');
1652
1655
  //Note: Remove lists and return statement
1653
1656
  description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
1654
- description_1 = spacetrim.spaceTrim(description_1);
1657
+ description_1 = spaceTrim.spaceTrim(description_1);
1655
1658
  if (description_1 === '') {
1656
1659
  description_1 = undefined;
1657
1660
  }
@@ -1731,6 +1734,15 @@
1731
1734
  * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
1732
1735
  */
1733
1736
 
1737
+ function promptbookJsonToString(promptbookJson) {
1738
+ return spaceTrim__default["default"](function (block) { return "\n\n # ".concat(block(promptbookJson.title), "\n\n "); });
1739
+ }
1740
+ /**
1741
+ * TODO: !!! Implement
1742
+ * TODO: !!! Annotate and warn
1743
+ * TODO: !!! Test + test together with promptbookStringToJson
1744
+ */
1745
+
1734
1746
  /**
1735
1747
  * This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
1736
1748
  */
@@ -1799,12 +1811,12 @@
1799
1811
  if (!parameter.isInput &&
1800
1812
  !parameter.isOutput &&
1801
1813
  !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 ")));
1814
+ 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
1815
  }
1804
1816
  // Note: Testing that parameter is either input or result of some template
1805
1817
  if (!parameter.isInput &&
1806
1818
  !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 ")));
1819
+ 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
1820
  }
1809
1821
  };
1810
1822
  try {
@@ -1839,7 +1851,7 @@
1839
1851
  if (template.executionType === 'PROMPT_TEMPLATE' &&
1840
1852
  (template.modelRequirements.modelVariant === undefined ||
1841
1853
  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 ")));
1854
+ 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
1855
  }
1844
1856
  if (template.jokers && template.jokers.length > 0) {
1845
1857
  if (!template.expectFormat &&
@@ -1914,7 +1926,7 @@
1914
1926
  return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
1915
1927
  });
1916
1928
  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
1929
+ 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
1930
  .map(function (_a) {
1919
1931
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
1920
1932
  return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
@@ -2087,7 +2099,7 @@
2087
2099
  throw errors[0];
2088
2100
  }
2089
2101
  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 "); }));
2102
+ 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
2103
  }
2092
2104
  }
2093
2105
  });
@@ -2171,7 +2183,7 @@
2171
2183
  throw scriptExecutionErrors[0];
2172
2184
  }
2173
2185
  else {
2174
- throw new PromptbookExecutionError(spacetrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
2186
+ throw new PromptbookExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
2175
2187
  .map(function (error) { return '- ' + error.message; })
2176
2188
  .join('\n\n')), "\n "); }));
2177
2189
  }
@@ -2311,7 +2323,7 @@
2311
2323
  return [7 /*endfinally*/];
2312
2324
  case 47:
2313
2325
  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 "); }));
2326
+ 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
2327
  }
2316
2328
  _o.label = 48;
2317
2329
  case 48:
@@ -2380,7 +2392,7 @@
2380
2392
  return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
2381
2393
  });
2382
2394
  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 "));
2395
+ throw new UnexpectedError(spaceTrim.spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePromptbookJson\n "));
2384
2396
  case 1:
2385
2397
  if (!!currentTemplate) return [3 /*break*/, 3];
2386
2398
  /* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
@@ -2480,7 +2492,7 @@
2480
2492
  case 1:
2481
2493
  answer = _a.sent();
2482
2494
  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 "); }));
2495
+ console.info(spaceTrim.spaceTrim(function (block) { return "\n \uD83D\uDCD6 ".concat(block(options.promptTitle), "\n \uD83D\uDC64 ").concat(block(answer), "\n "); }));
2484
2496
  }
2485
2497
  return [2 /*return*/, answer];
2486
2498
  }
@@ -2507,9 +2519,9 @@
2507
2519
  return __awaiter(this, void 0, void 0, function () {
2508
2520
  var answer;
2509
2521
  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 "); }));
2522
+ answer = window.prompt(spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(options.promptTitle), "\n\n ").concat(block(options.promptMessage), "\n "); }));
2511
2523
  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 "); }));
2524
+ 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
2525
  }
2514
2526
  if (answer === null) {
2515
2527
  throw new PromptbookExecutionError('User cancelled prompt');
@@ -2556,7 +2568,8 @@
2556
2568
  * @see https://github.com/webgptorg/promptbook#promptbook-library
2557
2569
  */
2558
2570
  var SimplePromptbookLibrary = /** @class */ (function () {
2559
- /**!!!
2571
+ /**
2572
+ * Constructs a promptbook library from promptbooks
2560
2573
  *
2561
2574
  * @param promptbooks !!!
2562
2575
  *
@@ -2574,7 +2587,7 @@
2574
2587
  for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
2575
2588
  var promptbook = promptbooks_1_1.value;
2576
2589
  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 ")));
2590
+ 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
2591
  }
2579
2592
  validatePromptbookJson(promptbook);
2580
2593
  this.library.set(promptbook.promptbookUrl, promptbook);
@@ -2603,7 +2616,7 @@
2603
2616
  var _this = this;
2604
2617
  var promptbook = this.library.get(url);
2605
2618
  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()
2619
+ 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
2620
  .map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
2608
2621
  .join('\n')), "\n\n "); }));
2609
2622
  }
@@ -2618,6 +2631,15 @@
2618
2631
  return SimplePromptbookLibrary;
2619
2632
  }());
2620
2633
 
2634
+ /**
2635
+ * Creates PromptbookLibrary from array of PromptbookJson or PromptbookString
2636
+ *
2637
+ * Note: You can combine `PromptbookString` (`.ptbk.md`) with `PromptbookJson` BUT it is not recommended
2638
+ * Note: During the construction syntax and logic of all sources are validated
2639
+ *
2640
+ * @param promptbookSources
2641
+ * @returns PromptbookLibrary
2642
+ */
2621
2643
  function createPromptbookLibraryFromSources() {
2622
2644
  var e_1, _a;
2623
2645
  var promptbookSources = [];
@@ -2649,20 +2671,29 @@
2649
2671
  }
2650
2672
  return new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))();
2651
2673
  }
2674
+ /***
2675
+ * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
2676
+ */
2677
+
2652
2678
  /**
2653
- * Constructs Promptbook from any sources
2679
+ * Constructs Promptbook from async sources
2680
+ * It can be one of the following:
2681
+ * - Promise of array of PromptbookJson or PromptbookString
2682
+ * - Factory function that returns Promise of array of PromptbookJson or PromptbookString
2654
2683
  *
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
2684
+ * Note: This is useful as internal tool for other constructor functions like
2685
+ * `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
2686
+ * Consider using those functions instead of this one
2687
+ *
2688
+ * Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
2689
+ * when error occurs in given promise or factory function, it is thrown during `listPromptbooks` or `getPromptbookByUrl` call
2657
2690
  *
2658
- * @param promptbookSources contents of .ptbk.md or .ptbk.json files
2659
- * @param settings settings for creating executor functions
2691
+ *
2692
+ * @param promptbookSourcesPromiseOrFactory
2660
2693
  * @returns PromptbookLibrary
2694
+ *
2695
+ * @deprecated Consider using `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
2661
2696
  */
2662
- /***
2663
- * TODO: !!! Annotate all + all to README and samples
2664
- */
2665
-
2666
2697
  function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
2667
2698
  var library;
2668
2699
  function forSources() {
@@ -2727,9 +2758,18 @@
2727
2758
  };
2728
2759
  }
2729
2760
  /***
2730
- * TODO: !!! Annotate all + all to README and samples
2761
+ * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
2731
2762
  */
2732
2763
 
2764
+ /**
2765
+ * Creates PromptbookLibrary as a subset of another PromptbookLibrary
2766
+ *
2767
+ * Note: You can use any type of library as a parent library - local, remote, etc.
2768
+ * Note: This is just a thin wrapper / proxy around the parent library
2769
+ *
2770
+ * @param promptbookSources
2771
+ * @returns PromptbookLibrary
2772
+ */
2733
2773
  function createPromptbookSublibrary(library, predicate) {
2734
2774
  function listPromptbooks() {
2735
2775
  return __awaiter(this, void 0, void 0, function () {
@@ -2754,7 +2794,7 @@
2754
2794
  case 0:
2755
2795
  if (!!predicate(url)) return [3 /*break*/, 2];
2756
2796
  _a = PromptbookNotFoundError.bind;
2757
- return [4 /*yield*/, spacetrim.spaceTrim(function (block) { return __awaiter(_this, void 0, void 0, function () {
2797
+ return [4 /*yield*/, spaceTrim.spaceTrim(function (block) { return __awaiter(_this, void 0, void 0, function () {
2758
2798
  var _a, _b, _c, _d, _e, _f;
2759
2799
  return __generator(this, function (_g) {
2760
2800
  switch (_g.label) {
@@ -2800,7 +2840,7 @@
2800
2840
  };
2801
2841
  }
2802
2842
  /***
2803
- * TODO: !!! Annotate all + all to README and samples
2843
+ * TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
2804
2844
  */
2805
2845
 
2806
2846
  exports.CallbackInterfaceTools = CallbackInterfaceTools;
@@ -2812,6 +2852,7 @@
2812
2852
  exports.createPromptbookLibraryFromPromise = createPromptbookLibraryFromPromise;
2813
2853
  exports.createPromptbookLibraryFromSources = createPromptbookLibraryFromSources;
2814
2854
  exports.createPromptbookSublibrary = createPromptbookSublibrary;
2855
+ exports.promptbookJsonToString = promptbookJsonToString;
2815
2856
  exports.promptbookStringToJson = promptbookStringToJson;
2816
2857
  exports.validatePromptbookJson = validatePromptbookJson;
2817
2858