@promptbook/cli 0.58.0 → 0.59.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 (108) hide show
  1. package/README.md +1 -1
  2. package/esm/index.es.js +371 -332
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/_packages/core.index.d.ts +9 -10
  5. package/esm/typings/_packages/node.index.d.ts +1 -1
  6. package/esm/typings/_packages/types.index.d.ts +11 -70
  7. package/esm/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
  8. package/esm/typings/conversion/promptbookStringToJson.d.ts +17 -2
  9. package/esm/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +1 -1
  10. package/esm/typings/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +1 -1
  11. package/esm/typings/expectations/drafts/isDomainNameFree.d.ts +6 -0
  12. package/esm/typings/expectations/drafts/isGithubNameFree.d.ts +6 -0
  13. package/esm/typings/formats/_common/FormatDefinition.d.ts +20 -4
  14. package/esm/typings/formats/csv/ListFormatDefinition.d.ts +11 -0
  15. package/esm/typings/formats/json/JsonFormatDefinition.d.ts +5 -1
  16. package/esm/typings/formats/list/ListFormatDefinition.d.ts +13 -0
  17. package/esm/typings/formats/xml/XmlFormatDefinition.d.ts +4 -0
  18. package/{umd/typings/knowledgebase → esm/typings/knowledge}/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +1 -1
  19. package/esm/typings/knowledge/prepare-knowledge/_common/IndexPreparer.d.ts +4 -0
  20. package/esm/typings/knowledge/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts +2 -0
  21. package/esm/typings/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +7 -0
  22. package/esm/typings/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +16 -0
  23. package/esm/typings/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +2 -1
  24. package/esm/typings/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
  25. package/esm/typings/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
  26. package/esm/typings/llm-providers/openai/OpenAiExecutionTools.d.ts +1 -1
  27. package/esm/typings/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +1 -1
  28. package/{umd/typings/library → esm/typings/promptbook-library}/constructors/createPromptbookLibraryFromDirectory.d.ts +3 -0
  29. package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.d.ts +3 -0
  30. package/{umd/typings/library → esm/typings/promptbook-library}/constructors/createPromptbookLibraryFromSources.d.ts +4 -1
  31. package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromUrl.d.ts +3 -0
  32. package/esm/typings/scripting/python/PythonExecutionTools.d.ts +1 -1
  33. package/esm/typings/scripting/typescript/TypescriptExecutionTools.d.ts +1 -1
  34. package/esm/typings/types/PromptbookJson/KnowledgeJson.d.ts +6 -0
  35. package/esm/typings/types/PromptbookJson/MaterialKnowledgePieceJson.d.ts +27 -0
  36. package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +8 -6
  37. package/esm/typings/types/typeAliases.d.ts +7 -1
  38. package/package.json +4 -4
  39. package/umd/index.umd.js +371 -332
  40. package/umd/index.umd.js.map +1 -1
  41. package/umd/typings/_packages/core.index.d.ts +9 -10
  42. package/umd/typings/_packages/node.index.d.ts +1 -1
  43. package/umd/typings/_packages/types.index.d.ts +11 -70
  44. package/umd/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
  45. package/umd/typings/conversion/promptbookStringToJson.d.ts +17 -2
  46. package/umd/typings/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +1 -1
  47. package/umd/typings/execution/translation/automatic-translate/automatic-translators/TranslatorOptions.d.ts +1 -1
  48. package/umd/typings/expectations/drafts/isDomainNameFree.d.ts +6 -0
  49. package/umd/typings/expectations/drafts/isGithubNameFree.d.ts +6 -0
  50. package/umd/typings/formats/_common/FormatDefinition.d.ts +20 -4
  51. package/umd/typings/formats/csv/ListFormatDefinition.d.ts +11 -0
  52. package/umd/typings/formats/json/JsonFormatDefinition.d.ts +5 -1
  53. package/umd/typings/formats/list/ListFormatDefinition.d.ts +13 -0
  54. package/umd/typings/formats/xml/XmlFormatDefinition.d.ts +4 -0
  55. package/{esm/typings/knowledgebase → umd/typings/knowledge}/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +1 -1
  56. package/umd/typings/knowledge/prepare-knowledge/_common/IndexPreparer.d.ts +4 -0
  57. package/umd/typings/knowledge/prepare-knowledge/markdown/playground/markdown-knowledge-playground.d.ts +2 -0
  58. package/umd/typings/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +7 -0
  59. package/umd/typings/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +16 -0
  60. package/umd/typings/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +2 -1
  61. package/umd/typings/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
  62. package/umd/typings/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
  63. package/umd/typings/llm-providers/openai/OpenAiExecutionTools.d.ts +1 -1
  64. package/umd/typings/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +1 -1
  65. package/{esm/typings/library → umd/typings/promptbook-library}/constructors/createPromptbookLibraryFromDirectory.d.ts +3 -0
  66. package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.d.ts +3 -0
  67. package/{esm/typings/library → umd/typings/promptbook-library}/constructors/createPromptbookLibraryFromSources.d.ts +4 -1
  68. package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromUrl.d.ts +3 -0
  69. package/umd/typings/scripting/python/PythonExecutionTools.d.ts +1 -1
  70. package/umd/typings/scripting/typescript/TypescriptExecutionTools.d.ts +1 -1
  71. package/umd/typings/types/PromptbookJson/KnowledgeJson.d.ts +6 -0
  72. package/umd/typings/types/PromptbookJson/MaterialKnowledgePieceJson.d.ts +27 -0
  73. package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +8 -6
  74. package/umd/typings/types/typeAliases.d.ts +7 -1
  75. package/esm/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +0 -1
  76. package/esm/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +0 -1
  77. package/esm/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +0 -1
  78. package/umd/typings/execution/plugins/script-execution-tools/custom-function-async.test.ts.test.d.ts +0 -1
  79. package/umd/typings/execution/plugins/script-execution-tools/custom-function-missing.test.d.ts +0 -1
  80. package/umd/typings/execution/plugins/script-execution-tools/custom-function-with-dependencies.test.d.ts +0 -1
  81. package/umd/typings/execution/plugins/script-execution-tools/custom-function.test.d.ts +0 -1
  82. package/umd/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +0 -1
  83. package/umd/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +0 -1
  84. package/umd/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +0 -1
  85. /package/esm/typings/{knowledgebase → knowledge}/dialogs/callback/CallbackInterfaceTools.d.ts +0 -0
  86. /package/esm/typings/{knowledgebase → knowledge}/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +0 -0
  87. /package/esm/typings/{knowledgebase → knowledge}/dialogs/user-interface-execution-tools.test.d.ts +0 -0
  88. /package/esm/typings/{execution/plugins/script-execution-tools/custom-function-async.test.ts.test.d.ts → knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts} +0 -0
  89. /package/esm/typings/{execution/plugins/script-execution-tools/custom-function-missing.test.d.ts → knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts} +0 -0
  90. /package/esm/typings/{library → promptbook-library}/PromptbookLibrary.d.ts +0 -0
  91. /package/esm/typings/{library → promptbook-library}/SimplePromptbookLibrary.d.ts +0 -0
  92. /package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromDirectory.test.d.ts +0 -0
  93. /package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.test.d.ts +0 -0
  94. /package/esm/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromSources.test.d.ts +0 -0
  95. /package/esm/typings/{library → promptbook-library}/constructors/createPromptbookSublibrary.d.ts +0 -0
  96. /package/esm/typings/{library → promptbook-library}/constructors/justTestFsImport.d.ts +0 -0
  97. /package/umd/typings/{knowledgebase → knowledge}/dialogs/callback/CallbackInterfaceTools.d.ts +0 -0
  98. /package/umd/typings/{knowledgebase → knowledge}/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +0 -0
  99. /package/umd/typings/{knowledgebase → knowledge}/dialogs/user-interface-execution-tools.test.d.ts +0 -0
  100. /package/{esm/typings/execution/plugins/script-execution-tools/custom-function-with-dependencies.test.d.ts → umd/typings/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts} +0 -0
  101. /package/{esm/typings/execution/plugins/script-execution-tools/custom-function.test.d.ts → umd/typings/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.test.d.ts} +0 -0
  102. /package/umd/typings/{library → promptbook-library}/PromptbookLibrary.d.ts +0 -0
  103. /package/umd/typings/{library → promptbook-library}/SimplePromptbookLibrary.d.ts +0 -0
  104. /package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromDirectory.test.d.ts +0 -0
  105. /package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromPromise.test.d.ts +0 -0
  106. /package/umd/typings/{library → promptbook-library}/constructors/createPromptbookLibraryFromSources.test.d.ts +0 -0
  107. /package/umd/typings/{library → promptbook-library}/constructors/createPromptbookSublibrary.d.ts +0 -0
  108. /package/umd/typings/{library → promptbook-library}/constructors/justTestFsImport.d.ts +0 -0
package/esm/index.es.js CHANGED
@@ -142,7 +142,70 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
142
142
  /**
143
143
  * The version of the Promptbook library
144
144
  */
145
- var PROMPTBOOK_VERSION = '0.57.2';
145
+ var PROMPTBOOK_VERSION = '0.59.0-0';
146
+
147
+ /**
148
+ * Removes HTML or Markdown comments from a string.
149
+ *
150
+ * @param {string} content - The string to remove comments from.
151
+ * @returns {string} The input string with all comments removed.
152
+ */
153
+ function removeContentComments(content) {
154
+ return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
155
+ }
156
+
157
+ /**
158
+ * Add or modify an auto-generated section in a markdown file
159
+ *
160
+ * @private within the library
161
+ */
162
+ function addAutoGeneratedSection(content, options) {
163
+ var sectionName = options.sectionName, sectionContent = options.sectionContent;
164
+ var warningLine = "<!-- \u26A0\uFE0F WARNING: This section was auto-generated -->";
165
+ var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
166
+ var sectionMatch = content.match(sectionRegex);
167
+ if (sectionMatch) {
168
+ return content.replace(sectionRegex, spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
169
+ }
170
+ var placeForSection = removeContentComments(content).match(/^##.*$/im);
171
+ if (!placeForSection) {
172
+ throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
173
+ }
174
+ var _a = __read(placeForSection, 1), heading = _a[0];
175
+ return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
176
+ }
177
+
178
+ /**
179
+ * Prettify the html code
180
+ *
181
+ * @param content raw html code
182
+ * @returns formatted html code
183
+ */
184
+ function prettifyMarkdown(content) {
185
+ try {
186
+ return format(content, {
187
+ parser: 'markdown',
188
+ plugins: [parserHtml],
189
+ // TODO: DRY - make some import or auto-copy of .prettierrc
190
+ endOfLine: 'lf',
191
+ tabWidth: 4,
192
+ singleQuote: true,
193
+ trailingComma: 'all',
194
+ arrowParens: 'always',
195
+ printWidth: 120,
196
+ htmlWhitespaceSensitivity: 'ignore',
197
+ jsxBracketSameLine: false,
198
+ bracketSpacing: true,
199
+ });
200
+ }
201
+ catch (error) {
202
+ console.error('There was an error with prettifying the markdown, using the original as the fallback', {
203
+ error: error,
204
+ html: content,
205
+ });
206
+ return content;
207
+ }
208
+ }
146
209
 
147
210
  /**
148
211
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -158,6 +221,15 @@ var PromptbookSyntaxError = /** @class */ (function (_super) {
158
221
  return PromptbookSyntaxError;
159
222
  }(Error));
160
223
 
224
+ // import prepareKnowledgeFromMarkdownStringPromptbook from './prepare-knowledge-from-markdown.ptbk.md';
225
+ function prepareKnowledgeFromMarkdown(options) {
226
+ return __awaiter(this, void 0, void 0, function () {
227
+ return __generator(this, function (_a) {
228
+ return [2 /*return*/, []];
229
+ });
230
+ });
231
+ }
232
+
161
233
  /**
162
234
  * Supported script languages
163
235
  */
@@ -418,16 +490,6 @@ function extractOneBlockFromMarkdown(markdown) {
418
490
  * TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
419
491
  */
420
492
 
421
- /**
422
- * Removes HTML or Markdown comments from a string.
423
- *
424
- * @param {string} content - The string to remove comments from.
425
- * @returns {string} The input string with all comments removed.
426
- */
427
- function removeContentComments(content) {
428
- return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
429
- }
430
-
431
493
  /**
432
494
  * Creates a new set with all elements that are present in either set
433
495
  */
@@ -1335,250 +1397,267 @@ function titleToName(value) {
1335
1397
  }
1336
1398
 
1337
1399
  /**
1338
- * Parse promptbook from string format to JSON format
1400
+ * Compile promptbook from string (markdown) format to JSON format
1339
1401
  *
1402
+ * @param promptbookString {Promptbook} in string markdown format (.ptbk.md)
1403
+ * @param options - Options and tools for the compilation
1404
+ * @returns {Promptbook} compiled in JSON format (.ptbk.json)
1340
1405
  * @throws {PromptbookSyntaxError} if the promptbook string is not valid
1341
1406
  *
1342
1407
  * Note: This function does not validate logic of the pipeline only the syntax
1408
+ * Note: This function acts as compilation process
1343
1409
  */
1344
- function promptbookStringToJson(promptbookString) {
1345
- var e_1, _a, e_2, _b;
1346
- var promptbookJson = {
1347
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1348
- title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
1349
- promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
1350
- promptbookVersion: PROMPTBOOK_VERSION,
1351
- description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
1352
- parameters: [],
1353
- promptTemplates: [],
1354
- };
1355
- // =============================================================
1356
- // Note: 1️⃣ Normalization of the PROMPTBOOK string
1357
- promptbookString = removeContentComments(promptbookString);
1358
- promptbookString = promptbookString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
1359
- promptbookString = promptbookString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
1360
- // =============================================================
1361
- ///Note: 2️⃣ Function for adding parameters
1362
- var addParam = function (parameterCommand) {
1363
- var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
1364
- var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
1365
- if (existingParameter &&
1366
- existingParameter.description &&
1367
- existingParameter.description !== parameterDescription &&
1368
- parameterDescription) {
1369
- throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description.\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
1370
- }
1371
- if (existingParameter) {
1372
- if (parameterDescription) {
1373
- existingParameter.description = parameterDescription;
1374
- }
1375
- }
1376
- else {
1377
- promptbookJson.parameters.push({
1378
- name: parameterName,
1379
- description: parameterDescription || undefined,
1380
- isInput: isInput,
1381
- isOutput: isOutput,
1382
- });
1383
- }
1384
- };
1385
- // =============================================================
1386
- // Note: 3️⃣ Parse the dynamic part - the template pipeline
1387
- var markdownStructure = markdownToMarkdownStructure(promptbookString);
1388
- var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
1389
- if (markdownStructureDeepness !== 2) {
1390
- throw new PromptbookSyntaxError(spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
1391
- }
1392
- promptbookJson.title = markdownStructure.title;
1393
- // TODO: [1] DRY description
1394
- var description = markdownStructure.content;
1395
- // Note: Remove codeblocks
1396
- description = description.split(/^```.*^```/gms).join('');
1397
- //Note: Remove lists and return statement
1398
- description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
1399
- description = spaceTrim(description);
1400
- if (description === '') {
1401
- description = undefined;
1402
- }
1403
- promptbookJson.description = description;
1404
- var defaultModelRequirements = {};
1405
- var listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
1406
- try {
1407
- for (var listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
1408
- var listItem = listItems_1_1.value;
1409
- var command = parseCommand(listItem);
1410
- switch (command.type) {
1411
- case 'PROMPTBOOK_URL':
1412
- promptbookJson.promptbookUrl = command.promptbookUrl.href;
1413
- break;
1414
- case 'PROMPTBOOK_VERSION':
1415
- promptbookJson.promptbookVersion = command.promptbookVersion;
1416
- break;
1417
- case 'MODEL':
1418
- defaultModelRequirements[command.key] = command.value;
1419
- break;
1420
- case 'PARAMETER':
1421
- addParam(command);
1422
- break;
1423
- default:
1424
- throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
1425
- }
1426
- }
1427
- }
1428
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1429
- finally {
1430
- try {
1431
- if (listItems_1_1 && !listItems_1_1.done && (_a = listItems_1.return)) _a.call(listItems_1);
1432
- }
1433
- finally { if (e_1) throw e_1.error; }
1434
- }
1435
- var _loop_1 = function (section) {
1436
- var e_3, _e;
1437
- // TODO: Parse prompt template description (the content out of the codeblock and lists)
1438
- var templateModelRequirements = __assign({}, defaultModelRequirements);
1439
- var listItems_3 = extractAllListItemsFromMarkdown(section.content);
1440
- var dependentParameterNames = new Set();
1441
- var executionType = 'PROMPT_TEMPLATE';
1442
- var jokers = [];
1443
- var postprocessing = [];
1444
- var expectAmount = {};
1445
- var expectFormat = undefined;
1446
- var isExecutionTypeChanged = false;
1447
- try {
1448
- for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
1449
- var listItem = listItems_2_1.value;
1450
- var command = parseCommand(listItem);
1451
- switch (command.type) {
1452
- case 'JOKER':
1453
- jokers.push(command.parameterName);
1454
- dependentParameterNames.add(command.parameterName);
1455
- break;
1456
- case 'EXECUTE':
1457
- if (isExecutionTypeChanged) {
1458
- throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
1410
+ function promptbookStringToJson(promptbookString, options) {
1411
+ if (options === void 0) { options = {}; }
1412
+ return __awaiter(this, void 0, void 0, function () {
1413
+ var llmTools, promptbookJson, knowledge, addParam, markdownStructure, markdownStructureDeepness, description, defaultModelRequirements, listItems, listItems_1, listItems_1_1, listItem, command, _loop_1, _a, _b, section;
1414
+ var e_1, _c, e_2, _d;
1415
+ return __generator(this, function (_e) {
1416
+ switch (_e.label) {
1417
+ case 0:
1418
+ llmTools = options.llmTools;
1419
+ promptbookJson = {
1420
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1421
+ title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
1422
+ promptbookUrl: undefined /* <- Note: Putting here placeholder to keep `promptbookUrl` on top at final JSON */,
1423
+ promptbookVersion: PROMPTBOOK_VERSION,
1424
+ description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
1425
+ parameters: [],
1426
+ promptTemplates: [],
1427
+ knowledge: [],
1428
+ };
1429
+ if (!llmTools) return [3 /*break*/, 2];
1430
+ return [4 /*yield*/, prepareKnowledgeFromMarkdown()];
1431
+ case 1:
1432
+ knowledge = _e.sent();
1433
+ console.info('!!!! knowledge', knowledge);
1434
+ _e.label = 2;
1435
+ case 2:
1436
+ // =============================================================
1437
+ // Note: 1️⃣ Normalization of the PROMPTBOOK string
1438
+ promptbookString = removeContentComments(promptbookString);
1439
+ promptbookString = promptbookString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
1440
+ promptbookString = promptbookString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
1441
+ addParam = function (parameterCommand) {
1442
+ var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInput = parameterCommand.isInput, isOutput = parameterCommand.isOutput;
1443
+ var existingParameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
1444
+ if (existingParameter &&
1445
+ existingParameter.description &&
1446
+ existingParameter.description !== parameterDescription &&
1447
+ parameterDescription) {
1448
+ throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description.\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
1459
1449
  }
1460
- executionType = command.executionType;
1461
- isExecutionTypeChanged = true;
1462
- break;
1463
- case 'MODEL':
1464
- templateModelRequirements[command.key] = command.value;
1465
- break;
1466
- case 'PARAMETER':
1467
- // Note: This is just for detecting resulitng parameter name
1468
- addParam(command);
1469
- break;
1470
- case 'POSTPROCESS':
1471
- postprocessing.push(command.functionName);
1472
- break;
1473
- case 'EXPECT_AMOUNT':
1474
- // eslint-disable-next-line no-case-declarations
1475
- var unit = command.unit.toLowerCase();
1476
- expectAmount[unit] = expectAmount[unit] || {};
1477
- if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
1478
- if (expectAmount[unit].min !== undefined) {
1479
- throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
1450
+ if (existingParameter) {
1451
+ if (parameterDescription) {
1452
+ existingParameter.description = parameterDescription;
1480
1453
  }
1481
- expectAmount[unit].min = command.amount;
1482
- } /* not else */
1483
- if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
1484
- if (expectAmount[unit].max !== undefined) {
1485
- throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
1454
+ }
1455
+ else {
1456
+ promptbookJson.parameters.push({
1457
+ name: parameterName,
1458
+ description: parameterDescription || undefined,
1459
+ isInput: isInput,
1460
+ isOutput: isOutput,
1461
+ });
1462
+ }
1463
+ };
1464
+ markdownStructure = markdownToMarkdownStructure(promptbookString);
1465
+ markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
1466
+ if (markdownStructureDeepness !== 2) {
1467
+ throw new PromptbookSyntaxError(spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
1468
+ }
1469
+ promptbookJson.title = markdownStructure.title;
1470
+ description = markdownStructure.content;
1471
+ // Note: Remove codeblocks
1472
+ description = description.split(/^```.*^```/gms).join('');
1473
+ //Note: Remove lists and return statement
1474
+ description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
1475
+ description = spaceTrim(description);
1476
+ if (description === '') {
1477
+ description = undefined;
1478
+ }
1479
+ promptbookJson.description = description;
1480
+ defaultModelRequirements = {};
1481
+ listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
1482
+ try {
1483
+ for (listItems_1 = __values(listItems), listItems_1_1 = listItems_1.next(); !listItems_1_1.done; listItems_1_1 = listItems_1.next()) {
1484
+ listItem = listItems_1_1.value;
1485
+ command = parseCommand(listItem);
1486
+ switch (command.type) {
1487
+ case 'PROMPTBOOK_URL':
1488
+ promptbookJson.promptbookUrl = command.promptbookUrl.href;
1489
+ break;
1490
+ case 'PROMPTBOOK_VERSION':
1491
+ promptbookJson.promptbookVersion = command.promptbookVersion;
1492
+ break;
1493
+ case 'MODEL':
1494
+ defaultModelRequirements[command.key] = command.value;
1495
+ break;
1496
+ case 'PARAMETER':
1497
+ addParam(command);
1498
+ break;
1499
+ default:
1500
+ throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the head of the promptbook ONLY at the prompt template block"));
1486
1501
  }
1487
- expectAmount[unit].max = command.amount;
1488
1502
  }
1489
- break;
1490
- case 'EXPECT_FORMAT':
1491
- if (expectFormat !== undefined && command.format !== expectFormat) {
1492
- throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
1503
+ }
1504
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1505
+ finally {
1506
+ try {
1507
+ if (listItems_1_1 && !listItems_1_1.done && (_c = listItems_1.return)) _c.call(listItems_1);
1493
1508
  }
1494
- expectFormat = command.format;
1495
- break;
1496
- default:
1497
- throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
1498
- }
1499
- }
1500
- }
1501
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1502
- finally {
1503
- try {
1504
- if (listItems_2_1 && !listItems_2_1.done && (_e = listItems_2.return)) _e.call(listItems_2);
1505
- }
1506
- finally { if (e_3) throw e_3.error; }
1507
- }
1508
- var _f = extractOneBlockFromMarkdown(section.content), language = _f.language, content = _f.content;
1509
- if (executionType === 'SCRIPT') {
1510
- if (!language) {
1511
- throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
1512
- }
1513
- else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
1514
- throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
1509
+ finally { if (e_1) throw e_1.error; }
1510
+ }
1511
+ _loop_1 = function (section) {
1512
+ var e_3, _f;
1513
+ // TODO: Parse prompt template description (the content out of the codeblock and lists)
1514
+ var templateModelRequirements = __assign({}, defaultModelRequirements);
1515
+ var listItems_3 = extractAllListItemsFromMarkdown(section.content);
1516
+ var dependentParameterNames = new Set();
1517
+ var executionType = 'PROMPT_TEMPLATE';
1518
+ var jokers = [];
1519
+ var postprocessing = [];
1520
+ var expectAmount = {};
1521
+ var expectFormat = undefined;
1522
+ var isExecutionTypeChanged = false;
1523
+ try {
1524
+ for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
1525
+ var listItem = listItems_2_1.value;
1526
+ var command = parseCommand(listItem);
1527
+ switch (command.type) {
1528
+ case 'JOKER':
1529
+ jokers.push(command.parameterName);
1530
+ dependentParameterNames.add(command.parameterName);
1531
+ break;
1532
+ case 'EXECUTE':
1533
+ if (isExecutionTypeChanged) {
1534
+ throw new PromptbookSyntaxError('Execution type is already defined in the prompt template. It can be defined only once.');
1535
+ }
1536
+ executionType = command.executionType;
1537
+ isExecutionTypeChanged = true;
1538
+ break;
1539
+ case 'MODEL':
1540
+ templateModelRequirements[command.key] = command.value;
1541
+ break;
1542
+ case 'PARAMETER':
1543
+ // Note: This is just for detecting resulitng parameter name
1544
+ addParam(command);
1545
+ break;
1546
+ case 'POSTPROCESS':
1547
+ postprocessing.push(command.functionName);
1548
+ break;
1549
+ case 'EXPECT_AMOUNT':
1550
+ // eslint-disable-next-line no-case-declarations
1551
+ var unit = command.unit.toLowerCase();
1552
+ expectAmount[unit] = expectAmount[unit] || {};
1553
+ if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
1554
+ if (expectAmount[unit].min !== undefined) {
1555
+ throw new PromptbookSyntaxError("Already defined minumum ".concat(expectAmount[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
1556
+ }
1557
+ expectAmount[unit].min = command.amount;
1558
+ } /* not else */
1559
+ if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
1560
+ if (expectAmount[unit].max !== undefined) {
1561
+ throw new PromptbookSyntaxError("Already defined maximum ".concat(expectAmount[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
1562
+ }
1563
+ expectAmount[unit].max = command.amount;
1564
+ }
1565
+ break;
1566
+ case 'EXPECT_FORMAT':
1567
+ if (expectFormat !== undefined && command.format !== expectFormat) {
1568
+ throw new PromptbookSyntaxError("Expect format is already defined to \"".concat(expectFormat, "\". Now you try to redefine it by \"").concat(command.format, "\"."));
1569
+ }
1570
+ expectFormat = command.format;
1571
+ break;
1572
+ default:
1573
+ throw new PromptbookSyntaxError("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the promptbook"));
1574
+ }
1575
+ }
1576
+ }
1577
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1578
+ finally {
1579
+ try {
1580
+ if (listItems_2_1 && !listItems_2_1.done && (_f = listItems_2.return)) _f.call(listItems_2);
1581
+ }
1582
+ finally { if (e_3) throw e_3.error; }
1583
+ }
1584
+ var _g = extractOneBlockFromMarkdown(section.content), language = _g.language, content = _g.content;
1585
+ if (executionType === 'SCRIPT') {
1586
+ if (!language) {
1587
+ throw new PromptbookSyntaxError('You must specify the language of the script in the prompt template');
1588
+ }
1589
+ else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
1590
+ throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
1591
+ }
1592
+ }
1593
+ var lastLine = section.content.split('\n').pop();
1594
+ var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
1595
+ if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
1596
+ throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
1597
+ // TODO: Show code of invalid sections each time + DRY
1598
+ section.content
1599
+ .split('\n')
1600
+ .map(function (line) { return "> ".concat(line); })
1601
+ .join('\n')), "\n "); }));
1602
+ }
1603
+ var resultingParameterName = match.groups.resultingParamName;
1604
+ // TODO: [1] DRY description
1605
+ var description_1 = section.content;
1606
+ // Note: Remove codeblocks
1607
+ description_1 = description_1.split(/^```.*^```/gms).join('');
1608
+ //Note: Remove lists and return statement
1609
+ description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
1610
+ description_1 = spaceTrim(description_1);
1611
+ if (description_1 === '') {
1612
+ description_1 = undefined;
1613
+ }
1614
+ if (Object.keys(jokers).length === 0) {
1615
+ jokers = undefined;
1616
+ }
1617
+ if (Object.keys(expectAmount).length === 0) {
1618
+ expectAmount = undefined;
1619
+ }
1620
+ if (Object.keys(postprocessing).length === 0) {
1621
+ postprocessing = undefined;
1622
+ }
1623
+ dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
1624
+ if (templateModelRequirements.modelVariant === undefined) {
1625
+ templateModelRequirements.modelVariant = 'CHAT';
1626
+ }
1627
+ promptbookJson.promptTemplates.push({
1628
+ name: titleToName(section.title),
1629
+ title: section.title,
1630
+ description: description_1,
1631
+ dependentParameterNames: Array.from(dependentParameterNames),
1632
+ executionType: executionType,
1633
+ jokers: jokers,
1634
+ postprocessing: postprocessing,
1635
+ expectations: expectAmount,
1636
+ expectFormat: expectFormat,
1637
+ modelRequirements: templateModelRequirements,
1638
+ contentLanguage: executionType === 'SCRIPT' ? language : undefined,
1639
+ content: content,
1640
+ resultingParameterName: resultingParameterName,
1641
+ });
1642
+ };
1643
+ try {
1644
+ for (_a = __values(markdownStructure.sections), _b = _a.next(); !_b.done; _b = _a.next()) {
1645
+ section = _b.value;
1646
+ _loop_1(section);
1647
+ }
1648
+ }
1649
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1650
+ finally {
1651
+ try {
1652
+ if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
1653
+ }
1654
+ finally { if (e_2) throw e_2.error; }
1655
+ }
1656
+ // =============================================================
1657
+ return [2 /*return*/, promptbookJson];
1515
1658
  }
1516
- }
1517
- var lastLine = section.content.split('\n').pop();
1518
- var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
1519
- if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
1520
- throw new PromptbookSyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
1521
- // TODO: Show code of invalid sections each time + DRY
1522
- section.content
1523
- .split('\n')
1524
- .map(function (line) { return "> ".concat(line); })
1525
- .join('\n')), "\n "); }));
1526
- }
1527
- var resultingParameterName = match.groups.resultingParamName;
1528
- // TODO: [1] DRY description
1529
- var description_1 = section.content;
1530
- // Note: Remove codeblocks
1531
- description_1 = description_1.split(/^```.*^```/gms).join('');
1532
- //Note: Remove lists and return statement
1533
- description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
1534
- description_1 = spaceTrim(description_1);
1535
- if (description_1 === '') {
1536
- description_1 = undefined;
1537
- }
1538
- if (Object.keys(jokers).length === 0) {
1539
- jokers = undefined;
1540
- }
1541
- if (Object.keys(expectAmount).length === 0) {
1542
- expectAmount = undefined;
1543
- }
1544
- if (Object.keys(postprocessing).length === 0) {
1545
- postprocessing = undefined;
1546
- }
1547
- dependentParameterNames = union(dependentParameterNames, extractParametersFromPromptTemplate(__assign(__assign({}, section), { description: description_1, executionType: executionType, content: content })));
1548
- if (templateModelRequirements.modelVariant === undefined) {
1549
- templateModelRequirements.modelVariant = 'CHAT';
1550
- }
1551
- promptbookJson.promptTemplates.push({
1552
- name: titleToName(section.title),
1553
- title: section.title,
1554
- description: description_1,
1555
- dependentParameterNames: Array.from(dependentParameterNames),
1556
- executionType: executionType,
1557
- jokers: jokers,
1558
- postprocessing: postprocessing,
1559
- expectations: expectAmount,
1560
- expectFormat: expectFormat,
1561
- modelRequirements: templateModelRequirements,
1562
- contentLanguage: executionType === 'SCRIPT' ? language : undefined,
1563
- content: content,
1564
- resultingParameterName: resultingParameterName,
1565
1659
  });
1566
- };
1567
- try {
1568
- for (var _c = __values(markdownStructure.sections), _d = _c.next(); !_d.done; _d = _c.next()) {
1569
- var section = _d.value;
1570
- _loop_1(section);
1571
- }
1572
- }
1573
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1574
- finally {
1575
- try {
1576
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
1577
- }
1578
- finally { if (e_2) throw e_2.error; }
1579
- }
1580
- // =============================================================
1581
- return promptbookJson;
1660
+ });
1582
1661
  }
1583
1662
  /**
1584
1663
  * TODO: Report here line/column of error
@@ -1586,59 +1665,6 @@ function promptbookStringToJson(promptbookString) {
1586
1665
  * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
1587
1666
  */
1588
1667
 
1589
- /**
1590
- * Add or modify an auto-generated section in a markdown file
1591
- *
1592
- * @private within the library
1593
- */
1594
- function addAutoGeneratedSection(content, options) {
1595
- var sectionName = options.sectionName, sectionContent = options.sectionContent;
1596
- var warningLine = "<!-- \u26A0\uFE0F WARNING: This section was auto-generated -->";
1597
- var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
1598
- var sectionMatch = content.match(sectionRegex);
1599
- if (sectionMatch) {
1600
- return content.replace(sectionRegex, spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
1601
- }
1602
- var placeForSection = removeContentComments(content).match(/^##.*$/im);
1603
- if (!placeForSection) {
1604
- throw new Error("No place where to put the section <!--".concat(sectionName, "-->"));
1605
- }
1606
- var _a = __read(placeForSection, 1), heading = _a[0];
1607
- return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
1608
- }
1609
-
1610
- /**
1611
- * Prettify the html code
1612
- *
1613
- * @param content raw html code
1614
- * @returns formatted html code
1615
- */
1616
- function prettifyMarkdown(content) {
1617
- try {
1618
- return format(content, {
1619
- parser: 'markdown',
1620
- plugins: [parserHtml],
1621
- // TODO: DRY - make some import or auto-copy of .prettierrc
1622
- endOfLine: 'lf',
1623
- tabWidth: 4,
1624
- singleQuote: true,
1625
- trailingComma: 'all',
1626
- arrowParens: 'always',
1627
- printWidth: 120,
1628
- htmlWhitespaceSensitivity: 'ignore',
1629
- jsxBracketSameLine: false,
1630
- bracketSpacing: true,
1631
- });
1632
- }
1633
- catch (error) {
1634
- console.error('There was an error with prettifying the markdown, using the original as the fallback', {
1635
- error: error,
1636
- html: content,
1637
- });
1638
- return content;
1639
- }
1640
- }
1641
-
1642
1668
  /* tslint:disable */
1643
1669
  function normalizeTo_camelCase(sentence, __firstLetterCapital) {
1644
1670
  var e_1, _a;
@@ -1756,24 +1782,35 @@ function renderPromptbookMermaid(promptbookJson, options) {
1756
1782
  * Prettyfies Promptbook string and adds Mermaid graph
1757
1783
  */
1758
1784
  function prettifyPromptbookString(promptbookString, options) {
1759
- var isGraphAdded = options.isGraphAdded, isPrettifyed = options.isPrettifyed;
1760
- if (isGraphAdded) {
1761
- var promptbookJson = promptbookStringToJson(promptbookString);
1762
- var promptbookMermaid_1 = renderPromptbookMermaid(promptbookJson, {
1763
- linkPromptTemplate: function (promptTemplate) {
1764
- return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
1765
- },
1766
- });
1767
- var promptbookMermaidBlock = spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
1768
- promptbookString = addAutoGeneratedSection(promptbookString, {
1769
- sectionName: 'Graph',
1770
- sectionContent: promptbookMermaidBlock,
1785
+ return __awaiter(this, void 0, void 0, function () {
1786
+ var isGraphAdded, isPrettifyed, promptbookJson, promptbookMermaid_1, promptbookMermaidBlock;
1787
+ return __generator(this, function (_a) {
1788
+ switch (_a.label) {
1789
+ case 0:
1790
+ isGraphAdded = options.isGraphAdded, isPrettifyed = options.isPrettifyed;
1791
+ if (!isGraphAdded) return [3 /*break*/, 2];
1792
+ return [4 /*yield*/, promptbookStringToJson(promptbookString /* , {!!!!} */)];
1793
+ case 1:
1794
+ promptbookJson = _a.sent();
1795
+ promptbookMermaid_1 = renderPromptbookMermaid(promptbookJson, {
1796
+ linkPromptTemplate: function (promptTemplate) {
1797
+ return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
1798
+ },
1799
+ });
1800
+ promptbookMermaidBlock = spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
1801
+ promptbookString = addAutoGeneratedSection(promptbookString, {
1802
+ sectionName: 'Graph',
1803
+ sectionContent: promptbookMermaidBlock,
1804
+ });
1805
+ _a.label = 2;
1806
+ case 2:
1807
+ if (isPrettifyed) {
1808
+ promptbookString = prettifyMarkdown(promptbookString);
1809
+ }
1810
+ return [2 /*return*/, promptbookString];
1811
+ }
1771
1812
  });
1772
- }
1773
- if (isPrettifyed) {
1774
- promptbookString = prettifyMarkdown(promptbookString);
1775
- }
1776
- return promptbookString;
1813
+ });
1777
1814
  }
1778
1815
  /**
1779
1816
  * TODO: Maybe use some Mermaid library instead of string templating
@@ -1811,33 +1848,35 @@ function prettifyPromptbookStringCli() {
1811
1848
  filePaths = _c.sent();
1812
1849
  _c.label = 2;
1813
1850
  case 2:
1814
- _c.trys.push([2, 10, 11, 12]);
1851
+ _c.trys.push([2, 11, 12, 13]);
1815
1852
  filePaths_1 = __values(filePaths), filePaths_1_1 = filePaths_1.next();
1816
1853
  _c.label = 3;
1817
1854
  case 3:
1818
- if (!!filePaths_1_1.done) return [3 /*break*/, 9];
1855
+ if (!!filePaths_1_1.done) return [3 /*break*/, 10];
1819
1856
  filePath = filePaths_1_1.value;
1820
1857
  if (!filePath.endsWith('.ptbk.md')) {
1821
1858
  console.warn(colors.yellow("Skipping prettify of non-promptbook ".concat(filePath)));
1822
- return [3 /*break*/, 8];
1859
+ return [3 /*break*/, 9];
1823
1860
  }
1824
1861
  return [4 /*yield*/, readFile(filePath, 'utf-8')];
1825
1862
  case 4:
1826
1863
  promptbookMarkdown = (_c.sent());
1827
1864
  _c.label = 5;
1828
1865
  case 5:
1829
- _c.trys.push([5, 7, , 8]);
1830
- promptbookMarkdown = prettifyPromptbookString(promptbookMarkdown, {
1831
- isGraphAdded: true,
1832
- isPrettifyed: true,
1833
- // <- [🕌]
1834
- });
1835
- return [4 /*yield*/, writeFile(filePath, promptbookMarkdown)];
1866
+ _c.trys.push([5, 8, , 9]);
1867
+ return [4 /*yield*/, prettifyPromptbookString(promptbookMarkdown, {
1868
+ isGraphAdded: true,
1869
+ isPrettifyed: true,
1870
+ // <- [🕌]
1871
+ })];
1836
1872
  case 6:
1873
+ promptbookMarkdown = _c.sent();
1874
+ return [4 /*yield*/, writeFile(filePath, promptbookMarkdown)];
1875
+ case 7:
1837
1876
  _c.sent();
1838
1877
  console.info(colors.green("Prettify ".concat(filePath)));
1839
- return [3 /*break*/, 8];
1840
- case 7:
1878
+ return [3 /*break*/, 9];
1879
+ case 8:
1841
1880
  error_1 = _c.sent();
1842
1881
  if (!(error_1 instanceof Error)) {
1843
1882
  throw error_1;
@@ -1846,22 +1885,22 @@ function prettifyPromptbookStringCli() {
1846
1885
  console.error(colors.bgRed(error_1.name));
1847
1886
  console.error(error_1);
1848
1887
  process.exit(1);
1849
- return [3 /*break*/, 8];
1850
- case 8:
1888
+ return [3 /*break*/, 9];
1889
+ case 9:
1851
1890
  filePaths_1_1 = filePaths_1.next();
1852
1891
  return [3 /*break*/, 3];
1853
- case 9: return [3 /*break*/, 12];
1854
- case 10:
1892
+ case 10: return [3 /*break*/, 13];
1893
+ case 11:
1855
1894
  e_1_1 = _c.sent();
1856
1895
  e_1 = { error: e_1_1 };
1857
- return [3 /*break*/, 12];
1858
- case 11:
1896
+ return [3 /*break*/, 13];
1897
+ case 12:
1859
1898
  try {
1860
1899
  if (filePaths_1_1 && !filePaths_1_1.done && (_b = filePaths_1.return)) _b.call(filePaths_1);
1861
1900
  }
1862
1901
  finally { if (e_1) throw e_1.error; }
1863
1902
  return [7 /*endfinally*/];
1864
- case 12:
1903
+ case 13:
1865
1904
  process.exit(0);
1866
1905
  return [2 /*return*/];
1867
1906
  }