@promptbook/cli 0.73.0 → 0.74.0-11

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 (41) hide show
  1. package/README.md +176 -3
  2. package/bin/promptbook-cli.js +6 -1
  3. package/esm/index.es.js +1025 -449
  4. package/esm/index.es.js.map +1 -1
  5. package/esm/typings/src/_packages/anthropic-claude.index.d.ts +2 -2
  6. package/esm/typings/src/_packages/azure-openai.index.d.ts +2 -2
  7. package/esm/typings/src/_packages/browser.index.d.ts +2 -2
  8. package/esm/typings/src/_packages/cli.index.d.ts +2 -2
  9. package/esm/typings/src/_packages/core.index.d.ts +7 -3
  10. package/esm/typings/src/_packages/documents.index.d.ts +2 -2
  11. package/esm/typings/src/_packages/execute-javascript.index.d.ts +2 -2
  12. package/esm/typings/src/_packages/fake-llm.index.d.ts +2 -2
  13. package/esm/typings/src/_packages/langtail.index.d.ts +2 -2
  14. package/esm/typings/src/_packages/legacy-documents.index.d.ts +2 -2
  15. package/esm/typings/src/_packages/markdown-utils.index.d.ts +2 -2
  16. package/esm/typings/src/_packages/node.index.d.ts +2 -2
  17. package/esm/typings/src/_packages/openai.index.d.ts +2 -2
  18. package/esm/typings/src/_packages/pdf.index.d.ts +2 -2
  19. package/esm/typings/src/_packages/remote-client.index.d.ts +2 -2
  20. package/esm/typings/src/_packages/remote-server.index.d.ts +2 -2
  21. package/esm/typings/src/_packages/utils.index.d.ts +2 -2
  22. package/esm/typings/src/_packages/website-crawler.index.d.ts +2 -2
  23. package/esm/typings/src/cli/cli-commands/make.d.ts +0 -1
  24. package/esm/typings/src/cli/cli-commands/run.d.ts +14 -0
  25. package/esm/typings/src/cli/promptbookCli.d.ts +1 -0
  26. package/esm/typings/src/cli/test/ptbk.d.ts +5 -2
  27. package/esm/typings/src/commands/{PROMPTBOOK_VERSION/PromptbookVersionCommand.d.ts → BOOK_VERSION/BookVersionCommand.d.ts} +4 -4
  28. package/esm/typings/src/commands/BOOK_VERSION/bookVersionCommandParser.d.ts +9 -0
  29. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +1 -1
  30. package/esm/typings/src/commands/index.d.ts +1 -1
  31. package/esm/typings/src/config.d.ts +6 -0
  32. package/esm/typings/src/storage/blackhole/BlackholeStorage.d.ts +33 -0
  33. package/esm/typings/src/storage/memory/MemoryStorage.d.ts +1 -1
  34. package/esm/typings/src/storage/{memory/utils → utils}/PrefixStorage.d.ts +1 -1
  35. package/esm/typings/src/version.d.ts +13 -2
  36. package/package.json +8 -4
  37. package/umd/index.umd.js +1030 -453
  38. package/umd/index.umd.js.map +1 -1
  39. package/esm/typings/src/commands/PROMPTBOOK_VERSION/promptbookVersionCommandParser.d.ts +0 -9
  40. /package/esm/typings/src/commands/{PROMPTBOOK_VERSION/promptbookVersionCommand.test.d.ts → BOOK_VERSION/bookVersionCommand.test.d.ts} +0 -0
  41. /package/esm/typings/src/storage/{memory → local-storage}/utils/makePromptbookStorageFromWebStorage.d.ts +0 -0
package/esm/index.es.js CHANGED
@@ -1,6 +1,6 @@
1
+ import colors from 'colors';
1
2
  import commander from 'commander';
2
3
  import spaceTrim$1, { spaceTrim } from 'spacetrim';
3
- import colors from 'colors';
4
4
  import { forTime } from 'waitasecond';
5
5
  import { stat, access, constants, readFile, writeFile, readdir, mkdir, unlink, rm, rmdir, rename } from 'fs/promises';
6
6
  import { join, basename, dirname } from 'path';
@@ -15,6 +15,8 @@ import { promisify } from 'util';
15
15
  import * as dotenv from 'dotenv';
16
16
  import sha256 from 'crypto-js/sha256';
17
17
  import glob from 'glob-promise';
18
+ import prompts from 'prompts';
19
+ import moment from 'moment';
18
20
  import { io } from 'socket.io-client';
19
21
  import Anthropic from '@anthropic-ai/sdk';
20
22
  import { OpenAIClient, AzureKeyCredential } from '@azure/openai';
@@ -25,10 +27,20 @@ import { Converter } from 'showdown';
25
27
 
26
28
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
27
29
  /**
28
- * The version of the Promptbook library
30
+ * The version of the Book language
31
+ *
32
+ * @see https://github.com/webgptorg/book
33
+ */
34
+ var BOOK_LANGUAGE_VERSION = '1.0.0';
35
+ /**
36
+ * The version of the Promptbook engine
37
+ *
38
+ * @see https://github.com/webgptorg/promptbook
39
+ */
40
+ var PROMPTBOOK_ENGINE_VERSION = '0.74.0-10';
41
+ /**
42
+ * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
29
43
  */
30
- var PROMPTBOOK_VERSION = '0.72.0';
31
- // TODO: [main] !!!! List here all the versions and annotate + put into script
32
44
 
33
45
  /*! *****************************************************************************
34
46
  Copyright (c) Microsoft Corporation.
@@ -149,31 +161,6 @@ function __spreadArray(to, from, pack) {
149
161
  return to.concat(ar || Array.prototype.slice.call(from));
150
162
  }
151
163
 
152
- /**
153
- * This error type indicates that you try to use a feature that is not available in the current environment
154
- *
155
- * @public exported from `@promptbook/core`
156
- */
157
- var EnvironmentMismatchError = /** @class */ (function (_super) {
158
- __extends(EnvironmentMismatchError, _super);
159
- function EnvironmentMismatchError(message) {
160
- var _this = _super.call(this, message) || this;
161
- _this.name = 'EnvironmentMismatchError';
162
- Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
163
- return _this;
164
- }
165
- return EnvironmentMismatchError;
166
- }(Error));
167
-
168
- /**
169
- * Detects if the code is running in a Node.js environment
170
- *
171
- * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
172
- *
173
- * @public exported from `@promptbook/utils`
174
- */
175
- var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
176
-
177
164
  /**
178
165
  * Returns the same value that is passed as argument.
179
166
  * No side effects.
@@ -402,6 +389,12 @@ var GENERATOR_WARNING = "\u26A0\uFE0F WARNING: This code has been generated so t
402
389
  */
403
390
  var CLAIM = "Build responsible, controlled and transparent applications on top of LLM models!";
404
391
  // <- TODO: [🐊] Pick the best claim
392
+ /**
393
+ * When the title is not provided, the default title is used
394
+ *
395
+ * @public exported from `@promptbook/core`
396
+ */
397
+ var DEFAULT_TITLE = "Untitled";
405
398
  /**
406
399
  * Warning message for the generated sections and files files
407
400
  *
@@ -515,6 +508,15 @@ var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
515
508
  * @private within the repository
516
509
  */
517
510
  var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
511
+ /**
512
+ * The thresholds for the relative time in the `moment` NPM package.
513
+ *
514
+ * @see https://momentjscom.readthedocs.io/en/latest/moment/07-customization/13-relative-time-threshold/
515
+ * @private within the repository - too low-level in comparison with other constants
516
+ */
517
+ var MOMENT_ARG_THRESHOLDS = {
518
+ ss: 3, // <- least number of seconds to be counted in seconds, minus 1. Must be set after setting the `s` unit or without setting the `s` unit.
519
+ };
518
520
  /**
519
521
  * @@@
520
522
  *
@@ -545,12 +547,6 @@ var DEFAULT_CSV_SETTINGS = Object.freeze({
545
547
  * @public exported from `@promptbook/core`
546
548
  */
547
549
  var DEFAULT_IS_VERBOSE = false;
548
- /**
549
- * @@@
550
- *
551
- * @public exported from `@promptbook/core`
552
- */
553
- var DEFAULT_IS_AUTO_INSTALLED = false;
554
550
  /**
555
551
  * @@@
556
552
  *
@@ -564,6 +560,31 @@ true);
564
560
  * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
565
561
  */
566
562
 
563
+ /**
564
+ * This error type indicates that you try to use a feature that is not available in the current environment
565
+ *
566
+ * @public exported from `@promptbook/core`
567
+ */
568
+ var EnvironmentMismatchError = /** @class */ (function (_super) {
569
+ __extends(EnvironmentMismatchError, _super);
570
+ function EnvironmentMismatchError(message) {
571
+ var _this = _super.call(this, message) || this;
572
+ _this.name = 'EnvironmentMismatchError';
573
+ Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
574
+ return _this;
575
+ }
576
+ return EnvironmentMismatchError;
577
+ }(Error));
578
+
579
+ /**
580
+ * Detects if the code is running in a Node.js environment
581
+ *
582
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
583
+ *
584
+ * @public exported from `@promptbook/utils`
585
+ */
586
+ var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
587
+
567
588
  /**
568
589
  * Initializes `about` command for Promptbook CLI utilities
569
590
  *
@@ -575,12 +596,12 @@ function initializeAboutCommand(program) {
575
596
  makeCommand.description(spaceTrim$1("\n Tells about Promptbook CLI and its abilities\n "));
576
597
  makeCommand.action(function () { return __awaiter(_this, void 0, void 0, function () {
577
598
  return __generator(this, function (_a) {
578
- console.info(colors.cyan("Promptbook"));
579
- console.info(colors.cyan(CLAIM));
580
- console.info(colors.cyan("Version: ".concat(PROMPTBOOK_VERSION)));
599
+ console.info(colors.bold(colors.cyan("Promptbook: ".concat(CLAIM))));
600
+ console.info(colors.cyan("Book language version: ".concat(BOOK_LANGUAGE_VERSION)));
601
+ console.info(colors.cyan("Promptbook engine version: ".concat(PROMPTBOOK_ENGINE_VERSION)));
602
+ console.info(colors.cyan("https://github.com/webgptorg/promptbook"));
581
603
  console.info(colors.cyan("https://ptbk.io"));
582
- process.exit(0);
583
- return [2 /*return*/];
604
+ return [2 /*return*/, process.exit(0)];
584
605
  });
585
606
  }); });
586
607
  }
@@ -611,8 +632,7 @@ function initializeHelloCommand(program) {
611
632
  case 1:
612
633
  _b.sent();
613
634
  console.info(colors.rainbow("Nice to meet you!"));
614
- process.exit(0);
615
- return [2 /*return*/];
635
+ return [2 /*return*/, process.exit(0)];
616
636
  }
617
637
  });
618
638
  });
@@ -1041,6 +1061,188 @@ var UNCERTAIN_USAGE = $deepFreeze({
1041
1061
  },
1042
1062
  });
1043
1063
 
1064
+ /**
1065
+ * @@@
1066
+ *
1067
+ * @public exported from `@promptbook/utils`
1068
+ */
1069
+ function deepClone(objectValue) {
1070
+ return JSON.parse(JSON.stringify(objectValue));
1071
+ /*
1072
+ TODO: [🧠] Is there a better implementation?
1073
+ > const propertyNames = Object.getOwnPropertyNames(objectValue);
1074
+ > for (const propertyName of propertyNames) {
1075
+ > const value = (objectValue as really_any)[propertyName];
1076
+ > if (value && typeof value === 'object') {
1077
+ > deepClone(value);
1078
+ > }
1079
+ > }
1080
+ > return Object.assign({}, objectValue);
1081
+ */
1082
+ }
1083
+ /**
1084
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
1085
+ */
1086
+
1087
+ /**
1088
+ * Function `addUsage` will add multiple usages into one
1089
+ *
1090
+ * Note: If you provide 0 values, it returns ZERO_USAGE
1091
+ *
1092
+ * @public exported from `@promptbook/core`
1093
+ */
1094
+ function addUsage() {
1095
+ var usageItems = [];
1096
+ for (var _i = 0; _i < arguments.length; _i++) {
1097
+ usageItems[_i] = arguments[_i];
1098
+ }
1099
+ return usageItems.reduce(function (acc, item) {
1100
+ var e_1, _a, e_2, _b;
1101
+ var _c;
1102
+ acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
1103
+ try {
1104
+ for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
1105
+ var key = _e.value;
1106
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1107
+ //@ts-ignore
1108
+ if (item.input[key]) {
1109
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1110
+ //@ts-ignore
1111
+ acc.input[key].value += item.input[key].value || 0;
1112
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1113
+ //@ts-ignore
1114
+ if (item.input[key].isUncertain) {
1115
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1116
+ //@ts-ignore
1117
+ acc.input[key].isUncertain = true;
1118
+ }
1119
+ }
1120
+ }
1121
+ }
1122
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1123
+ finally {
1124
+ try {
1125
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
1126
+ }
1127
+ finally { if (e_1) throw e_1.error; }
1128
+ }
1129
+ try {
1130
+ for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
1131
+ var key = _g.value;
1132
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1133
+ //@ts-ignore
1134
+ if (item.output[key]) {
1135
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1136
+ //@ts-ignore
1137
+ acc.output[key].value += item.output[key].value || 0;
1138
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1139
+ //@ts-ignore
1140
+ if (item.output[key].isUncertain) {
1141
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1142
+ //@ts-ignore
1143
+ acc.output[key].isUncertain = true;
1144
+ }
1145
+ }
1146
+ }
1147
+ }
1148
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1149
+ finally {
1150
+ try {
1151
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
1152
+ }
1153
+ finally { if (e_2) throw e_2.error; }
1154
+ }
1155
+ return acc;
1156
+ }, deepClone(ZERO_USAGE));
1157
+ }
1158
+
1159
+ /**
1160
+ * Intercepts LLM tools and counts total usage of the tools
1161
+ *
1162
+ * @param llmTools LLM tools to be intercepted with usage counting
1163
+ * @returns LLM tools with same functionality with added total cost counting
1164
+ * @public exported from `@promptbook/core`
1165
+ */
1166
+ function countTotalUsage(llmTools) {
1167
+ var _this = this;
1168
+ var totalUsage = ZERO_USAGE;
1169
+ var proxyTools = {
1170
+ get title() {
1171
+ // TODO: [🧠] Maybe put here some suffix
1172
+ return llmTools.title;
1173
+ },
1174
+ get description() {
1175
+ // TODO: [🧠] Maybe put here some suffix
1176
+ return llmTools.description;
1177
+ },
1178
+ checkConfiguration: function () {
1179
+ return __awaiter(this, void 0, void 0, function () {
1180
+ return __generator(this, function (_a) {
1181
+ return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
1182
+ });
1183
+ });
1184
+ },
1185
+ listModels: function () {
1186
+ return /* not await */ llmTools.listModels();
1187
+ },
1188
+ getTotalUsage: function () {
1189
+ // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
1190
+ return totalUsage;
1191
+ },
1192
+ };
1193
+ if (llmTools.callChatModel !== undefined) {
1194
+ proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
1195
+ var promptResult;
1196
+ return __generator(this, function (_a) {
1197
+ switch (_a.label) {
1198
+ case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
1199
+ case 1:
1200
+ promptResult = _a.sent();
1201
+ totalUsage = addUsage(totalUsage, promptResult.usage);
1202
+ return [2 /*return*/, promptResult];
1203
+ }
1204
+ });
1205
+ }); };
1206
+ }
1207
+ if (llmTools.callCompletionModel !== undefined) {
1208
+ proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
1209
+ var promptResult;
1210
+ return __generator(this, function (_a) {
1211
+ switch (_a.label) {
1212
+ case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
1213
+ case 1:
1214
+ promptResult = _a.sent();
1215
+ totalUsage = addUsage(totalUsage, promptResult.usage);
1216
+ return [2 /*return*/, promptResult];
1217
+ }
1218
+ });
1219
+ }); };
1220
+ }
1221
+ if (llmTools.callEmbeddingModel !== undefined) {
1222
+ proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
1223
+ var promptResult;
1224
+ return __generator(this, function (_a) {
1225
+ switch (_a.label) {
1226
+ case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
1227
+ case 1:
1228
+ promptResult = _a.sent();
1229
+ totalUsage = addUsage(totalUsage, promptResult.usage);
1230
+ return [2 /*return*/, promptResult];
1231
+ }
1232
+ });
1233
+ }); };
1234
+ }
1235
+ // <- Note: [🤖]
1236
+ return proxyTools;
1237
+ }
1238
+ /**
1239
+ * TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
1240
+ * TODO: [🧠] Is there some meaningfull way how to test this util
1241
+ * TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
1242
+ * > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
1243
+ * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
1244
+ */
1245
+
1044
1246
  /**
1045
1247
  * This error indicates errors during the execution of the pipeline
1046
1248
  *
@@ -1349,188 +1551,6 @@ function joinLlmExecutionTools() {
1349
1551
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
1350
1552
  */
1351
1553
 
1352
- /**
1353
- * @@@
1354
- *
1355
- * @public exported from `@promptbook/utils`
1356
- */
1357
- function deepClone(objectValue) {
1358
- return JSON.parse(JSON.stringify(objectValue));
1359
- /*
1360
- TODO: [🧠] Is there a better implementation?
1361
- > const propertyNames = Object.getOwnPropertyNames(objectValue);
1362
- > for (const propertyName of propertyNames) {
1363
- > const value = (objectValue as really_any)[propertyName];
1364
- > if (value && typeof value === 'object') {
1365
- > deepClone(value);
1366
- > }
1367
- > }
1368
- > return Object.assign({}, objectValue);
1369
- */
1370
- }
1371
- /**
1372
- * TODO: [🧠] Is there a way how to meaningfully test this utility
1373
- */
1374
-
1375
- /**
1376
- * Function `addUsage` will add multiple usages into one
1377
- *
1378
- * Note: If you provide 0 values, it returns ZERO_USAGE
1379
- *
1380
- * @public exported from `@promptbook/core`
1381
- */
1382
- function addUsage() {
1383
- var usageItems = [];
1384
- for (var _i = 0; _i < arguments.length; _i++) {
1385
- usageItems[_i] = arguments[_i];
1386
- }
1387
- return usageItems.reduce(function (acc, item) {
1388
- var e_1, _a, e_2, _b;
1389
- var _c;
1390
- acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
1391
- try {
1392
- for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
1393
- var key = _e.value;
1394
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1395
- //@ts-ignore
1396
- if (item.input[key]) {
1397
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1398
- //@ts-ignore
1399
- acc.input[key].value += item.input[key].value || 0;
1400
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1401
- //@ts-ignore
1402
- if (item.input[key].isUncertain) {
1403
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1404
- //@ts-ignore
1405
- acc.input[key].isUncertain = true;
1406
- }
1407
- }
1408
- }
1409
- }
1410
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1411
- finally {
1412
- try {
1413
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
1414
- }
1415
- finally { if (e_1) throw e_1.error; }
1416
- }
1417
- try {
1418
- for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
1419
- var key = _g.value;
1420
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1421
- //@ts-ignore
1422
- if (item.output[key]) {
1423
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1424
- //@ts-ignore
1425
- acc.output[key].value += item.output[key].value || 0;
1426
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1427
- //@ts-ignore
1428
- if (item.output[key].isUncertain) {
1429
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1430
- //@ts-ignore
1431
- acc.output[key].isUncertain = true;
1432
- }
1433
- }
1434
- }
1435
- }
1436
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1437
- finally {
1438
- try {
1439
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
1440
- }
1441
- finally { if (e_2) throw e_2.error; }
1442
- }
1443
- return acc;
1444
- }, deepClone(ZERO_USAGE));
1445
- }
1446
-
1447
- /**
1448
- * Intercepts LLM tools and counts total usage of the tools
1449
- *
1450
- * @param llmTools LLM tools to be intercepted with usage counting
1451
- * @returns LLM tools with same functionality with added total cost counting
1452
- * @public exported from `@promptbook/core`
1453
- */
1454
- function countTotalUsage(llmTools) {
1455
- var _this = this;
1456
- var totalUsage = ZERO_USAGE;
1457
- var proxyTools = {
1458
- get title() {
1459
- // TODO: [🧠] Maybe put here some suffix
1460
- return llmTools.title;
1461
- },
1462
- get description() {
1463
- // TODO: [🧠] Maybe put here some suffix
1464
- return llmTools.description;
1465
- },
1466
- checkConfiguration: function () {
1467
- return __awaiter(this, void 0, void 0, function () {
1468
- return __generator(this, function (_a) {
1469
- return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
1470
- });
1471
- });
1472
- },
1473
- listModels: function () {
1474
- return /* not await */ llmTools.listModels();
1475
- },
1476
- getTotalUsage: function () {
1477
- // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
1478
- return totalUsage;
1479
- },
1480
- };
1481
- if (llmTools.callChatModel !== undefined) {
1482
- proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
1483
- var promptResult;
1484
- return __generator(this, function (_a) {
1485
- switch (_a.label) {
1486
- case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
1487
- case 1:
1488
- promptResult = _a.sent();
1489
- totalUsage = addUsage(totalUsage, promptResult.usage);
1490
- return [2 /*return*/, promptResult];
1491
- }
1492
- });
1493
- }); };
1494
- }
1495
- if (llmTools.callCompletionModel !== undefined) {
1496
- proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
1497
- var promptResult;
1498
- return __generator(this, function (_a) {
1499
- switch (_a.label) {
1500
- case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
1501
- case 1:
1502
- promptResult = _a.sent();
1503
- totalUsage = addUsage(totalUsage, promptResult.usage);
1504
- return [2 /*return*/, promptResult];
1505
- }
1506
- });
1507
- }); };
1508
- }
1509
- if (llmTools.callEmbeddingModel !== undefined) {
1510
- proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
1511
- var promptResult;
1512
- return __generator(this, function (_a) {
1513
- switch (_a.label) {
1514
- case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
1515
- case 1:
1516
- promptResult = _a.sent();
1517
- totalUsage = addUsage(totalUsage, promptResult.usage);
1518
- return [2 /*return*/, promptResult];
1519
- }
1520
- });
1521
- }); };
1522
- }
1523
- // <- Note: [🤖]
1524
- return proxyTools;
1525
- }
1526
- /**
1527
- * TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
1528
- * TODO: [🧠] Is there some meaningfull way how to test this util
1529
- * TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
1530
- * > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
1531
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
1532
- */
1533
-
1534
1554
  var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
1535
1555
 
1536
1556
  /**
@@ -1606,7 +1626,7 @@ function isValidPromptbookVersion(version) {
1606
1626
  if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
1607
1627
  return false;
1608
1628
  }
1609
- // <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
1629
+ // <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
1610
1630
  return true;
1611
1631
  }
1612
1632
 
@@ -1706,7 +1726,7 @@ function isValidPipelineUrl(url) {
1706
1726
  if (!url.startsWith('https://')) {
1707
1727
  return false;
1708
1728
  }
1709
- if (!url.endsWith('.ptbk.md')) {
1729
+ if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.ptbk.md') || url.endsWith('.ptbk'))) {
1710
1730
  return false;
1711
1731
  }
1712
1732
  if (url.includes('#')) {
@@ -2566,10 +2586,6 @@ function union() {
2566
2586
  * @private within the repository
2567
2587
  */
2568
2588
  function TODO_USE() {
2569
- var value = [];
2570
- for (var _i = 0; _i < arguments.length; _i++) {
2571
- value[_i] = arguments[_i];
2572
- }
2573
2589
  }
2574
2590
 
2575
2591
  /**
@@ -2628,22 +2644,12 @@ var CsvFormatDefinition = {
2628
2644
  formatName: 'CSV',
2629
2645
  aliases: ['SPREADSHEET', 'TABLE'],
2630
2646
  isValid: function (value, settings, schema) {
2631
- // TODO: Implement CSV validation
2632
- TODO_USE(value /* <- TODO: Use value here */);
2633
- TODO_USE(settings /* <- TODO: Use settings here */);
2634
- TODO_USE(schema /* <- TODO: Use schema here */);
2635
2647
  return true;
2636
2648
  },
2637
2649
  canBeValid: function (partialValue, settings, schema) {
2638
- TODO_USE(partialValue /* <- TODO: Use partialValue here */);
2639
- TODO_USE(settings /* <- TODO: Use settings here */);
2640
- TODO_USE(schema /* <- TODO: Use schema here */);
2641
2650
  return true;
2642
2651
  },
2643
2652
  heal: function (value, settings, schema) {
2644
- TODO_USE(value /* <- TODO: Use partialValue here */);
2645
- TODO_USE(settings /* <- TODO: Use settings here */);
2646
- TODO_USE(schema /* <- TODO: Use schema here */);
2647
2653
  throw new Error('Not implemented');
2648
2654
  },
2649
2655
  subvalueDefinitions: [
@@ -2762,20 +2768,12 @@ var JsonFormatDefinition = {
2762
2768
  formatName: 'JSON',
2763
2769
  mimeType: 'application/json',
2764
2770
  isValid: function (value, settings, schema) {
2765
- TODO_USE(schema /* <- TODO: Use schema here */);
2766
- TODO_USE(settings /* <- TODO: Use settings here */);
2767
2771
  return isValidJsonString(value);
2768
2772
  },
2769
2773
  canBeValid: function (partialValue, settings, schema) {
2770
- TODO_USE(partialValue /* <- TODO: Use partialValue here */);
2771
- TODO_USE(settings /* <- TODO: Use settings here */);
2772
- TODO_USE(schema /* <- TODO: Use schema here */);
2773
2774
  return true;
2774
2775
  },
2775
2776
  heal: function (value, settings, schema) {
2776
- TODO_USE(value /* <- TODO: Use partialValue here */);
2777
- TODO_USE(settings /* <- TODO: Use settings here */);
2778
- TODO_USE(schema /* <- TODO: Use schema here */);
2779
2777
  throw new Error('Not implemented');
2780
2778
  },
2781
2779
  subvalueDefinitions: [],
@@ -2857,21 +2855,12 @@ var XmlFormatDefinition = {
2857
2855
  formatName: 'XML',
2858
2856
  mimeType: 'application/xml',
2859
2857
  isValid: function (value, settings, schema) {
2860
- TODO_USE(value /* <- TODO: Use value here */);
2861
- TODO_USE(settings /* <- TODO: Use settings here */);
2862
- TODO_USE(schema /* <- TODO: Use schema here */);
2863
2858
  return true;
2864
2859
  },
2865
2860
  canBeValid: function (partialValue, settings, schema) {
2866
- TODO_USE(partialValue /* <- TODO: Use partialValue here */);
2867
- TODO_USE(settings /* <- TODO: Use settings here */);
2868
- TODO_USE(schema /* <- TODO: Use schema here */);
2869
2861
  return true;
2870
2862
  },
2871
2863
  heal: function (value, settings, schema) {
2872
- TODO_USE(value /* <- TODO: Use partialValue here */);
2873
- TODO_USE(settings /* <- TODO: Use settings here */);
2874
- TODO_USE(schema /* <- TODO: Use schema here */);
2875
2864
  throw new Error('Not implemented');
2876
2865
  },
2877
2866
  subvalueDefinitions: [],
@@ -3104,27 +3093,6 @@ function arrayableToArray(input) {
3104
3093
  return [input];
3105
3094
  }
3106
3095
 
3107
- /**
3108
- * Just says that the variable is not used but should be kept
3109
- * No side effects.
3110
- *
3111
- * Note: It can be usefull for:
3112
- *
3113
- * 1) Suppressing eager optimization of unused imports
3114
- * 2) Suppressing eslint errors of unused variables in the tests
3115
- * 3) Keeping the type of the variable for type testing
3116
- *
3117
- * @param value any values
3118
- * @returns void
3119
- * @private within the repository
3120
- */
3121
- function keepUnused() {
3122
- var valuesToKeep = [];
3123
- for (var _i = 0; _i < arguments.length; _i++) {
3124
- valuesToKeep[_i] = arguments[_i];
3125
- }
3126
- }
3127
-
3128
3096
  /**
3129
3097
  * Replaces parameters in template with values from parameters object
3130
3098
  *
@@ -3237,10 +3205,12 @@ function countLines(text) {
3237
3205
  * @public exported from `@promptbook/utils`
3238
3206
  */
3239
3207
  function countPages(text) {
3240
- var sentencesPerPage = 5; // Assuming each page has 5 sentences
3241
- var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
3242
- var pageCount = Math.ceil(sentences.length / sentencesPerPage);
3243
- return pageCount;
3208
+ if (text === '') {
3209
+ return 0;
3210
+ }
3211
+ var pagesByLinesCount = Math.ceil(countLines(text) / 44);
3212
+ var pagesByCharactersCount = Math.ceil(countCharacters(text) / 2772);
3213
+ return Math.max(pagesByLinesCount, pagesByCharactersCount);
3244
3214
  }
3245
3215
 
3246
3216
  /**
@@ -3879,7 +3849,6 @@ function executeAttempts(options) {
3879
3849
  $ongoingTemplateResult.$resultString = extractJsonBlock($ongoingTemplateResult.$resultString || '');
3880
3850
  }
3881
3851
  catch (error) {
3882
- keepUnused(error);
3883
3852
  throw new ExpectError(spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
3884
3853
  /*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
3885
3854
  }
@@ -4057,7 +4026,6 @@ function executeFormatSubvalues(options) {
4057
4026
  function getContextForTemplate(template) {
4058
4027
  return __awaiter(this, void 0, void 0, function () {
4059
4028
  return __generator(this, function (_a) {
4060
- TODO_USE(template);
4061
4029
  return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
4062
4030
  });
4063
4031
  });
@@ -4070,11 +4038,9 @@ function getContextForTemplate(template) {
4070
4038
  */
4071
4039
  function getKnowledgeForTemplate(options) {
4072
4040
  return __awaiter(this, void 0, void 0, function () {
4073
- var preparedPipeline, template;
4041
+ var preparedPipeline;
4074
4042
  return __generator(this, function (_a) {
4075
- preparedPipeline = options.preparedPipeline, template = options.template;
4076
- // TODO: [♨] Implement Better - use real index and keyword search from `template` and {examples}
4077
- TODO_USE(template);
4043
+ preparedPipeline = options.preparedPipeline, options.template;
4078
4044
  return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
4079
4045
  var content = _a.content;
4080
4046
  return "- ".concat(content);
@@ -4091,8 +4057,6 @@ function getKnowledgeForTemplate(options) {
4091
4057
  function getExamplesForTemplate(template) {
4092
4058
  return __awaiter(this, void 0, void 0, function () {
4093
4059
  return __generator(this, function (_a) {
4094
- // TODO: [♨] Implement Better - use real index and keyword search
4095
- TODO_USE(template);
4096
4060
  return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
4097
4061
  });
4098
4062
  });
@@ -4111,13 +4075,13 @@ function getReservedParametersForTemplate(options) {
4111
4075
  switch (_b.label) {
4112
4076
  case 0:
4113
4077
  preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
4114
- return [4 /*yield*/, getContextForTemplate(template)];
4078
+ return [4 /*yield*/, getContextForTemplate()];
4115
4079
  case 1:
4116
4080
  context = _b.sent();
4117
4081
  return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
4118
4082
  case 2:
4119
4083
  knowledge = _b.sent();
4120
- return [4 /*yield*/, getExamplesForTemplate(template)];
4084
+ return [4 /*yield*/, getExamplesForTemplate()];
4121
4085
  case 3:
4122
4086
  examples = _b.sent();
4123
4087
  currentDate = new Date().toISOString();
@@ -4352,7 +4316,7 @@ function executePipeline(options) {
4352
4316
  executionReport = {
4353
4317
  pipelineUrl: preparedPipeline.pipelineUrl,
4354
4318
  title: preparedPipeline.title,
4355
- promptbookUsedVersion: PROMPTBOOK_VERSION,
4319
+ promptbookUsedVersion: PROMPTBOOK_ENGINE_VERSION,
4356
4320
  promptbookRequestedVersion: preparedPipeline.promptbookVersion,
4357
4321
  description: preparedPipeline.description,
4358
4322
  promptExecutions: [],
@@ -5199,16 +5163,13 @@ function isValidFilePath(filename) {
5199
5163
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5200
5164
  var _a;
5201
5165
  return __awaiter(this, void 0, void 0, function () {
5202
- var sourceContent, name, _b, _c, rootDirname, _d,
5203
- // <- TODO: process.cwd() if running in Node.js
5204
- isVerbose, url, response_1, mimeType, filename_1, fileExtension, mimeType;
5166
+ var sourceContent, name, _b, _c, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
5205
5167
  return __generator(this, function (_e) {
5206
5168
  switch (_e.label) {
5207
5169
  case 0:
5208
5170
  sourceContent = knowledgeSource.sourceContent;
5209
5171
  name = knowledgeSource.name;
5210
- _b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _d = _b.isVerbose, isVerbose = _d === void 0 ? DEFAULT_IS_VERBOSE : _d;
5211
- TODO_USE(isVerbose);
5172
+ _b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _b.isVerbose;
5212
5173
  if (!name) {
5213
5174
  name = sourceContentToName(sourceContent);
5214
5175
  }
@@ -5488,15 +5449,13 @@ function clonePipeline(pipeline) {
5488
5449
  */
5489
5450
  function prepareTemplates(pipeline, tools, options) {
5490
5451
  return __awaiter(this, void 0, void 0, function () {
5491
- var _a, maxParallelCount, templates, parameters, knowledgePiecesCount, templatesPrepared;
5452
+ var _a, maxParallelCount, templates, knowledgePiecesCount, templatesPrepared;
5492
5453
  var _this = this;
5493
5454
  return __generator(this, function (_b) {
5494
5455
  switch (_b.label) {
5495
5456
  case 0:
5496
5457
  _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a;
5497
- templates = pipeline.templates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
5498
- // TODO: [main] !! Apply examples to each template (if missing and is for the template defined)
5499
- TODO_USE(parameters);
5458
+ templates = pipeline.templates, pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
5500
5459
  templatesPrepared = new Array(templates.length);
5501
5460
  return [4 /*yield*/, forEachAsync(templates, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
5502
5461
  var dependentParameterNames, preparedContent, preparedTemplate;
@@ -5566,7 +5525,7 @@ function preparePipeline(pipeline, tools, options) {
5566
5525
  currentPreparation = {
5567
5526
  id: 1,
5568
5527
  // TODO: [🍥]> date: $currentDate(),
5569
- promptbookVersion: PROMPTBOOK_VERSION,
5528
+ promptbookVersion: PROMPTBOOK_ENGINE_VERSION,
5570
5529
  usage: ZERO_USAGE,
5571
5530
  };
5572
5531
  preparations = [
@@ -5706,7 +5665,6 @@ var knowledgeCommandParser = {
5706
5665
  * Note: This is used in `pipelineJsonToString` utility
5707
5666
  */
5708
5667
  stringify: function (command) {
5709
- keepUnused(command);
5710
5668
  return "---"; // <- TODO: [🛋] Implement
5711
5669
  },
5712
5670
  /**
@@ -5715,7 +5673,6 @@ var knowledgeCommandParser = {
5715
5673
  * Note: This is used in `pipelineJsonToString` utility
5716
5674
  */
5717
5675
  takeFromPipelineJson: function (pipelineJson) {
5718
- keepUnused(pipelineJson);
5719
5676
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
5720
5677
  },
5721
5678
  };
@@ -5898,7 +5855,6 @@ var templateCommandParser = {
5898
5855
  * Note: This is used in `pipelineJsonToString` utility
5899
5856
  */
5900
5857
  stringify: function (command) {
5901
- keepUnused(command);
5902
5858
  return "---"; // <- TODO: [🛋] Implement
5903
5859
  },
5904
5860
  /**
@@ -5907,7 +5863,6 @@ var templateCommandParser = {
5907
5863
  * Note: This is used in `pipelineJsonToString` utility
5908
5864
  */
5909
5865
  takeFromTemplateJson: function ($templateJson) {
5910
- keepUnused($templateJson);
5911
5866
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
5912
5867
  },
5913
5868
  };
@@ -6139,7 +6094,6 @@ var expectCommandParser = {
6139
6094
  * Note: This is used in `pipelineJsonToString` utility
6140
6095
  */
6141
6096
  stringify: function (command) {
6142
- keepUnused(command);
6143
6097
  return "---"; // <- TODO: [🛋] Implement
6144
6098
  },
6145
6099
  /**
@@ -6148,7 +6102,6 @@ var expectCommandParser = {
6148
6102
  * Note: This is used in `pipelineJsonToString` utility
6149
6103
  */
6150
6104
  takeFromTemplateJson: function ($templateJson) {
6151
- keepUnused($templateJson);
6152
6105
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
6153
6106
  },
6154
6107
  };
@@ -6467,7 +6420,6 @@ var foreachCommandParser = {
6467
6420
  inputSubparameterNames: inputSubparameterNames,
6468
6421
  outputSubparameterName: outputSubparameterName,
6469
6422
  };
6470
- keepUnused($pipelineJson); // <- TODO: [🧠] Maybe register subparameter from foreach into parameters of the pipeline
6471
6423
  // Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
6472
6424
  },
6473
6425
  /**
@@ -6476,7 +6428,6 @@ var foreachCommandParser = {
6476
6428
  * Note: This is used in `pipelineJsonToString` utility
6477
6429
  */
6478
6430
  stringify: function (command) {
6479
- keepUnused(command);
6480
6431
  return "---"; // <- TODO: [🛋] Implement
6481
6432
  },
6482
6433
  /**
@@ -6485,7 +6436,6 @@ var foreachCommandParser = {
6485
6436
  * Note: This is used in `pipelineJsonToString` utility
6486
6437
  */
6487
6438
  takeFromTemplateJson: function ($templateJson) {
6488
- keepUnused($templateJson);
6489
6439
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
6490
6440
  },
6491
6441
  };
@@ -6553,7 +6503,6 @@ var formatCommandParser = {
6553
6503
  * Note: This is used in `pipelineJsonToString` utility
6554
6504
  */
6555
6505
  stringify: function (command) {
6556
- keepUnused(command);
6557
6506
  return "---"; // <- TODO: [🛋] Implement
6558
6507
  },
6559
6508
  /**
@@ -6562,7 +6511,6 @@ var formatCommandParser = {
6562
6511
  * Note: This is used in `pipelineJsonToString` utility
6563
6512
  */
6564
6513
  takeFromTemplateJson: function ($templateJson) {
6565
- keepUnused($templateJson);
6566
6514
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
6567
6515
  },
6568
6516
  };
@@ -6625,7 +6573,6 @@ var jokerCommandParser = {
6625
6573
  * Note: This is used in `pipelineJsonToString` utility
6626
6574
  */
6627
6575
  stringify: function (command) {
6628
- keepUnused(command);
6629
6576
  return "---"; // <- TODO: [🛋] Implement
6630
6577
  },
6631
6578
  /**
@@ -6634,7 +6581,6 @@ var jokerCommandParser = {
6634
6581
  * Note: This is used in `pipelineJsonToString` utility
6635
6582
  */
6636
6583
  takeFromTemplateJson: function ($templateJson) {
6637
- keepUnused($templateJson);
6638
6584
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
6639
6585
  },
6640
6586
  };
@@ -6770,7 +6716,6 @@ var modelCommandParser = {
6770
6716
  * Note: This is used in `pipelineJsonToString` utility
6771
6717
  */
6772
6718
  stringify: function (command) {
6773
- keepUnused(command);
6774
6719
  return "---"; // <- TODO: [🛋] Implement
6775
6720
  },
6776
6721
  /**
@@ -6779,7 +6724,6 @@ var modelCommandParser = {
6779
6724
  * Note: This is used in `pipelineJsonToString` utility
6780
6725
  */
6781
6726
  takeFromPipelineJson: function (pipelineJson) {
6782
- keepUnused(pipelineJson);
6783
6727
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
6784
6728
  },
6785
6729
  /**
@@ -6788,7 +6732,6 @@ var modelCommandParser = {
6788
6732
  * Note: This is used in `pipelineJsonToString` utility
6789
6733
  */
6790
6734
  takeFromTemplateJson: function ($templateJson) {
6791
- keepUnused($templateJson);
6792
6735
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
6793
6736
  },
6794
6737
  };
@@ -6862,7 +6805,6 @@ var parameterCommandParser = {
6862
6805
  * Note: `$` is used to indicate that this function mutates given `pipelineJson`
6863
6806
  */
6864
6807
  $applyToPipelineJson: function (command, $pipelineJson) {
6865
- keepUnused(command, $pipelineJson);
6866
6808
  // Note: [🍣] Do nothing, its application is implemented separately in `pipelineStringToJsonSync`
6867
6809
  },
6868
6810
  /**
@@ -6871,7 +6813,6 @@ var parameterCommandParser = {
6871
6813
  * Note: `$` is used to indicate that this function mutates given `templateJson`
6872
6814
  */
6873
6815
  $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
6874
- keepUnused(command, $templateJson, $pipelineJson);
6875
6816
  // Note: [🍣] Do nothing, its application is implemented separately in `pipelineStringToJsonSync`
6876
6817
  },
6877
6818
  /**
@@ -6880,7 +6821,6 @@ var parameterCommandParser = {
6880
6821
  * Note: This is used in `pipelineJsonToString` utility
6881
6822
  */
6882
6823
  stringify: function (command) {
6883
- keepUnused(command);
6884
6824
  return "---"; // <- TODO: [🛋] Implement
6885
6825
  },
6886
6826
  /**
@@ -6889,7 +6829,6 @@ var parameterCommandParser = {
6889
6829
  * Note: This is used in `pipelineJsonToString` utility
6890
6830
  */
6891
6831
  takeFromPipelineJson: function (pipelineJson) {
6892
- keepUnused(pipelineJson);
6893
6832
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
6894
6833
  },
6895
6834
  /**
@@ -6898,7 +6837,6 @@ var parameterCommandParser = {
6898
6837
  * Note: This is used in `pipelineJsonToString` utility
6899
6838
  */
6900
6839
  takeFromTemplateJson: function ($templateJson) {
6901
- keepUnused($templateJson);
6902
6840
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
6903
6841
  },
6904
6842
  };
@@ -6970,7 +6908,6 @@ var personaCommandParser = {
6970
6908
  * Note: This is used in `pipelineJsonToString` utility
6971
6909
  */
6972
6910
  stringify: function (command) {
6973
- keepUnused(command);
6974
6911
  return "---"; // <- TODO: [🛋] Implement
6975
6912
  },
6976
6913
  /**
@@ -6979,7 +6916,6 @@ var personaCommandParser = {
6979
6916
  * Note: This is used in `pipelineJsonToString` utility
6980
6917
  */
6981
6918
  takeFromPipelineJson: function (pipelineJson) {
6982
- keepUnused(pipelineJson);
6983
6919
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
6984
6920
  },
6985
6921
  /**
@@ -6988,7 +6924,6 @@ var personaCommandParser = {
6988
6924
  * Note: This is used in `pipelineJsonToString` utility
6989
6925
  */
6990
6926
  takeFromTemplateJson: function ($templateJson) {
6991
- keepUnused($templateJson);
6992
6927
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
6993
6928
  },
6994
6929
  };
@@ -7107,7 +7042,6 @@ var postprocessCommandParser = {
7107
7042
  * Note: This is used in `pipelineJsonToString` utility
7108
7043
  */
7109
7044
  stringify: function (command) {
7110
- keepUnused(command);
7111
7045
  return "---"; // <- TODO: [🛋] Implement
7112
7046
  },
7113
7047
  /**
@@ -7116,42 +7050,41 @@ var postprocessCommandParser = {
7116
7050
  * Note: This is used in `pipelineJsonToString` utility
7117
7051
  */
7118
7052
  takeFromTemplateJson: function ($templateJson) {
7119
- keepUnused($templateJson);
7120
7053
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
7121
7054
  },
7122
7055
  };
7123
7056
 
7124
7057
  /**
7125
- * Parses the PROMPTBOOK_VERSION command
7058
+ * Parses the BOOK_VERSION command
7126
7059
  *
7127
7060
  * @see `documentationUrl` for more details
7128
7061
  * @private within the commands folder
7129
7062
  */
7130
- var promptbookVersionCommandParser = {
7063
+ var bookVersionCommandParser = {
7131
7064
  /**
7132
7065
  * Name of the command
7133
7066
  */
7134
- name: 'PROMPTBOOK_VERSION',
7135
- aliasNames: ['PTBK_VERSION', 'PTBK_V', 'PTBKV'],
7067
+ name: 'BOOK_VERSION',
7068
+ aliasNames: ['PTBK_VERSION', 'PROMPTBOOK_VERSION', 'BOOK'],
7136
7069
  /**
7137
7070
  * BOILERPLATE command can be used in:
7138
7071
  */
7139
7072
  isUsedInPipelineHead: true,
7140
7073
  isUsedInPipelineTemplate: false,
7141
7074
  /**
7142
- * Description of the PROMPTBOOK_VERSION command
7075
+ * Description of the BOOK_VERSION command
7143
7076
  */
7144
- description: "Which version of the promptbook is the .ptbk.md using",
7077
+ description: "Which version of the Book language is the .ptbk.md using",
7145
7078
  /**
7146
7079
  * Link to documentation
7147
7080
  */
7148
7081
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/69',
7149
7082
  /**
7150
- * Example usages of the PROMPTBOOK_VERSION command
7083
+ * Example usages of the BOOK_VERSION command
7151
7084
  */
7152
- examples: ["PROMPTBOOK VERSION ".concat(PROMPTBOOK_VERSION), "PTBKV ".concat(PROMPTBOOK_VERSION)],
7085
+ examples: ["BOOK VERSION ".concat(BOOK_LANGUAGE_VERSION), "BOOK ".concat(BOOK_LANGUAGE_VERSION)],
7153
7086
  /**
7154
- * Parses the PROMPTBOOK_VERSION command
7087
+ * Parses the BOOK_VERSION command
7155
7088
  */
7156
7089
  parse: function (input) {
7157
7090
  var args = input.args;
@@ -7162,16 +7095,16 @@ var promptbookVersionCommandParser = {
7162
7095
  if (!isValidPromptbookVersion(promptbookVersion)) {
7163
7096
  throw new ParseError("Invalid Promptbook version \"".concat(promptbookVersion, "\""));
7164
7097
  }
7165
- if (args.length > 0) {
7098
+ if (args.length > 0 && !(((args.length === 1 && args[0]) || '').toUpperCase() === 'VERSION')) {
7166
7099
  throw new ParseError("Can not have more than one Promptbook version");
7167
7100
  }
7168
7101
  return {
7169
- type: 'PROMPTBOOK_VERSION',
7102
+ type: 'BOOK_VERSION',
7170
7103
  promptbookVersion: promptbookVersion,
7171
7104
  };
7172
7105
  },
7173
7106
  /**
7174
- * Apply the PROMPTBOOK_VERSION command to the `pipelineJson`
7107
+ * Apply the BOOK_VERSION command to the `pipelineJson`
7175
7108
  *
7176
7109
  * Note: `$` is used to indicate that this function mutates given `pipelineJson`
7177
7110
  */
@@ -7180,21 +7113,19 @@ var promptbookVersionCommandParser = {
7180
7113
  $pipelineJson.promptbookVersion = command.promptbookVersion;
7181
7114
  },
7182
7115
  /**
7183
- * Converts the PROMPTBOOK_VERSION command back to string
7116
+ * Converts the BOOK_VERSION command back to string
7184
7117
  *
7185
7118
  * Note: This is used in `pipelineJsonToString` utility
7186
7119
  */
7187
7120
  stringify: function (command) {
7188
- keepUnused(command);
7189
7121
  return "---"; // <- TODO: [🛋] Implement
7190
7122
  },
7191
7123
  /**
7192
- * Reads the PROMPTBOOK_VERSION command from the `PipelineJson`
7124
+ * Reads the BOOK_VERSION command from the `PipelineJson`
7193
7125
  *
7194
7126
  * Note: This is used in `pipelineJsonToString` utility
7195
7127
  */
7196
7128
  takeFromPipelineJson: function (pipelineJson) {
7197
- keepUnused(pipelineJson);
7198
7129
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
7199
7130
  },
7200
7131
  };
@@ -7288,7 +7219,6 @@ var urlCommandParser = {
7288
7219
  * Note: This is used in `pipelineJsonToString` utility
7289
7220
  */
7290
7221
  stringify: function (command) {
7291
- keepUnused(command);
7292
7222
  return "---"; // <- TODO: [🛋] Implement
7293
7223
  },
7294
7224
  /**
@@ -7297,7 +7227,6 @@ var urlCommandParser = {
7297
7227
  * Note: This is used in `pipelineJsonToString` utility
7298
7228
  */
7299
7229
  takeFromPipelineJson: function (pipelineJson) {
7300
- keepUnused(pipelineJson);
7301
7230
  throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
7302
7231
  },
7303
7232
  };
@@ -7334,8 +7263,7 @@ var actionCommandParser = {
7334
7263
  * Parses the ACTION command
7335
7264
  */
7336
7265
  parse: function (input) {
7337
- var args = input.args;
7338
- TODO_USE(args);
7266
+ input.args;
7339
7267
  return {
7340
7268
  type: 'ACTION',
7341
7269
  };
@@ -7346,7 +7274,6 @@ var actionCommandParser = {
7346
7274
  * Note: `$` is used to indicate that this function mutates given `pipelineJson`
7347
7275
  */
7348
7276
  $applyToPipelineJson: function (command, $pipelineJson) {
7349
- keepUnused(command, $pipelineJson);
7350
7277
  console.error(new NotYetImplementedError('[🛠] Actions are not implemented yet'));
7351
7278
  },
7352
7279
  /**
@@ -7355,7 +7282,6 @@ var actionCommandParser = {
7355
7282
  * Note: This is used in `pipelineJsonToString` utility
7356
7283
  */
7357
7284
  stringify: function (command) {
7358
- keepUnused(command);
7359
7285
  throw new NotYetImplementedError('[🛠] Actions are not implemented yet');
7360
7286
  },
7361
7287
  /**
@@ -7364,7 +7290,6 @@ var actionCommandParser = {
7364
7290
  * Note: This is used in `pipelineJsonToString` utility
7365
7291
  */
7366
7292
  takeFromPipelineJson: function (pipelineJson) {
7367
- keepUnused(pipelineJson);
7368
7293
  throw new NotYetImplementedError('[🛠] Actions are not implemented yet');
7369
7294
  },
7370
7295
  };
@@ -7404,9 +7329,7 @@ var instrumentCommandParser = {
7404
7329
  * Parses the INSTRUMENT command
7405
7330
  */
7406
7331
  parse: function (input) {
7407
- var args = input.args;
7408
- // TODO: [🛠] Implement
7409
- TODO_USE(args);
7332
+ input.args;
7410
7333
  return {
7411
7334
  type: 'INSTRUMENT',
7412
7335
  };
@@ -7417,7 +7340,6 @@ var instrumentCommandParser = {
7417
7340
  * Note: `$` is used to indicate that this function mutates given `pipelineJson`
7418
7341
  */
7419
7342
  $applyToPipelineJson: function (command, $pipelineJson) {
7420
- keepUnused(command, $pipelineJson);
7421
7343
  console.error(new NotYetImplementedError('[🛠] Instruments are not implemented yet'));
7422
7344
  },
7423
7345
  /**
@@ -7426,7 +7348,6 @@ var instrumentCommandParser = {
7426
7348
  * Note: This is used in `pipelineJsonToString` utility
7427
7349
  */
7428
7350
  stringify: function (command) {
7429
- keepUnused(command);
7430
7351
  throw new NotYetImplementedError('[🛠] Instruments are not implemented yet');
7431
7352
  },
7432
7353
  /**
@@ -7435,7 +7356,6 @@ var instrumentCommandParser = {
7435
7356
  * Note: This is used in `pipelineJsonToString` utility
7436
7357
  */
7437
7358
  takeFromPipelineJson: function (pipelineJson) {
7438
- keepUnused(pipelineJson);
7439
7359
  throw new NotYetImplementedError('[🛠] Instruments are not implemented yet');
7440
7360
  },
7441
7361
  };
@@ -7500,7 +7420,6 @@ var boilerplateCommandParser = {
7500
7420
  * Note: `$` is used to indicate that this function mutates given `pipelineJson`
7501
7421
  */
7502
7422
  $applyToPipelineJson: function (command, $pipelineJson) {
7503
- keepUnused(command, $pipelineJson);
7504
7423
  throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
7505
7424
  },
7506
7425
  /**
@@ -7509,7 +7428,6 @@ var boilerplateCommandParser = {
7509
7428
  * Note: `$` is used to indicate that this function mutates given `templateJson`
7510
7429
  */
7511
7430
  $applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
7512
- keepUnused(command, $templateJson, $pipelineJson);
7513
7431
  throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
7514
7432
  },
7515
7433
  /**
@@ -7518,7 +7436,6 @@ var boilerplateCommandParser = {
7518
7436
  * Note: This is used in `pipelineJsonToString` utility
7519
7437
  */
7520
7438
  stringify: function (command) {
7521
- keepUnused(command);
7522
7439
  return "---"; // <- TODO: [🛋] Implement
7523
7440
  },
7524
7441
  /**
@@ -7527,7 +7444,6 @@ var boilerplateCommandParser = {
7527
7444
  * Note: This is used in `pipelineJsonToString` utility
7528
7445
  */
7529
7446
  takeFromPipelineJson: function (pipelineJson) {
7530
- keepUnused(pipelineJson);
7531
7447
  throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
7532
7448
  },
7533
7449
  /**
@@ -7536,7 +7452,6 @@ var boilerplateCommandParser = {
7536
7452
  * Note: This is used in `pipelineJsonToString` utility
7537
7453
  */
7538
7454
  takeFromTemplateJson: function ($templateJson) {
7539
- keepUnused($templateJson);
7540
7455
  throw new ParseError("BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file");
7541
7456
  },
7542
7457
  };
@@ -7554,7 +7469,7 @@ var COMMANDS = [
7554
7469
  modelCommandParser,
7555
7470
  parameterCommandParser,
7556
7471
  postprocessCommandParser,
7557
- promptbookVersionCommandParser,
7472
+ bookVersionCommandParser,
7558
7473
  urlCommandParser,
7559
7474
  knowledgeCommandParser,
7560
7475
  actionCommandParser,
@@ -7706,9 +7621,7 @@ function parseCommandVariant(input) {
7706
7621
  var _loop_1 = function (commandParser) {
7707
7622
  // <- Note: [🦦] Its strange that this type assertion is needed
7708
7623
  var name_1 = commandParser.name, isUsedInPipelineHead = commandParser.isUsedInPipelineHead, isUsedInPipelineTemplate = commandParser.isUsedInPipelineTemplate, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
7709
- if (just(false)) {
7710
- keepUnused( /* for better indentation */);
7711
- }
7624
+ if (just(false)) ;
7712
7625
  else if (usagePlace === 'PIPELINE_HEAD' && !isUsedInPipelineHead) {
7713
7626
  return "continue";
7714
7627
  }
@@ -7868,7 +7781,7 @@ function splitMarkdownIntoSections(markdown) {
7868
7781
  return;
7869
7782
  }
7870
7783
  if (!section.startsWith('#')) {
7871
- section = "# Untitled\n\n".concat(section);
7784
+ section = "# ".concat(DEFAULT_TITLE, "\n\n").concat(section);
7872
7785
  }
7873
7786
  sections.push(section);
7874
7787
  buffer = [];
@@ -7932,7 +7845,7 @@ function flattenMarkdown(markdown) {
7932
7845
  var e_1, _a;
7933
7846
  var sections = splitMarkdownIntoSections(markdown);
7934
7847
  if (sections.length === 0) {
7935
- return '# Untitled';
7848
+ return "# ".concat(DEFAULT_TITLE);
7936
7849
  }
7937
7850
  var flattenedMarkdown = '';
7938
7851
  var parsedSections = sections.map(parseMarkdownSection);
@@ -7943,7 +7856,7 @@ function flattenMarkdown(markdown) {
7943
7856
  }
7944
7857
  else {
7945
7858
  parsedSections.unshift(firstSection);
7946
- flattenedMarkdown += "# Untitled" + "\n\n"; // <- [🧠] Maybe 3 new lines?
7859
+ flattenedMarkdown += "# ".concat(DEFAULT_TITLE) + "\n\n"; // <- [🧠] Maybe 3 new lines?
7947
7860
  }
7948
7861
  try {
7949
7862
  for (var parsedSections_1 = __values(parsedSections), parsedSections_1_1 = parsedSections_1.next(); !parsedSections_1_1.done; parsedSections_1_1 = parsedSections_1.next()) {
@@ -8021,7 +7934,7 @@ function titleToName(value) {
8021
7934
  * @public exported from `@promptbook/core`
8022
7935
  */
8023
7936
  function pipelineStringToJsonSync(pipelineString) {
8024
- var e_1, _a, e_2, _b;
7937
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
8025
7938
  var $pipelineJson = {
8026
7939
  title: undefined /* <- Note: [🍙] Putting here placeholder to keep `title` on top at final JSON */,
8027
7940
  pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
@@ -8048,11 +7961,18 @@ function pipelineStringToJsonSync(pipelineString) {
8048
7961
  }
8049
7962
  // =============================================================
8050
7963
  // Note: 1️⃣ Parsing of the markdown into object
7964
+ if (pipelineString.startsWith('#!')) {
7965
+ var _e = __read(pipelineString.split('\n')), shebangLine_1 = _e[0], restLines = _e.slice(1);
7966
+ if (!(shebangLine_1 || '').includes('ptbk')) {
7967
+ throw new ParseError(spaceTrim(function (block) { return "\n It seems that you try to parse a book file which has non-standard shebang line for book files:\n Shebang line must contain 'ptbk'\n\n You have:\n ".concat(block(shebangLine_1 || '(empty line)'), "\n\n It should look like this:\n #!/usr/bin/env ptbk\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
7968
+ }
7969
+ pipelineString = restLines.join('\n');
7970
+ }
8051
7971
  pipelineString = removeContentComments(pipelineString);
8052
7972
  pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
8053
7973
  pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
8054
7974
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
8055
- var _c = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _c[0], pipelineSections = _c.slice(1); /* <- Note: [🥞] */
7975
+ var _f = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _f[0], pipelineSections = _f.slice(1); /* <- Note: [🥞] */
8056
7976
  if (pipelineHead === undefined) {
8057
7977
  throw new UnexpectedError(spaceTrim(function (block) { return "\n Pipeline head is not defined\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
8058
7978
  }
@@ -8080,6 +8000,8 @@ function pipelineStringToJsonSync(pipelineString) {
8080
8000
  if (parameterDescription) {
8081
8001
  existingParameter.description = parameterDescription;
8082
8002
  }
8003
+ existingParameter.isInput = existingParameter.isInput || isInput;
8004
+ existingParameter.isOutput = existingParameter.isOutput || isOutput;
8083
8005
  }
8084
8006
  else {
8085
8007
  $pipelineJson.parameters.push({
@@ -8142,10 +8064,10 @@ function pipelineStringToJsonSync(pipelineString) {
8142
8064
  finally { if (e_1) throw e_1.error; }
8143
8065
  }
8144
8066
  var _loop_2 = function (section) {
8145
- var e_3, _d;
8067
+ var e_5, _l, e_6, _m;
8146
8068
  // TODO: Parse template description (the content out of the codeblock and lists)
8147
8069
  var listItems_2 = extractAllListItemsFromMarkdown(section.content);
8148
- var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
8070
+ var _o = extractOneBlockFromMarkdown(section.content), language = _o.language, content = _o.content;
8149
8071
  // TODO: [🎾][1] DRY description
8150
8072
  var description_1 = section.content;
8151
8073
  // Note: Remove codeblocks - TODO: [🎾]
@@ -8186,7 +8108,7 @@ function pipelineStringToJsonSync(pipelineString) {
8186
8108
  }) === false) {
8187
8109
  templateCommandParser.$applyToTemplateJson({ type: 'TEMPLATE', templateType: 'PROMPT_TEMPLATE' }, $templateJson, $pipelineJson);
8188
8110
  }
8189
- var _loop_3 = function (listItem, command) {
8111
+ var _loop_4 = function (listItem, command) {
8190
8112
  var commandParser = getParserForCommand(command);
8191
8113
  if (commandParser.isUsedInPipelineTemplate !== true /* <- Note: [🦦][4] */) {
8192
8114
  throw new ParseError(spaceTrim(function (block) { return "\n Command ".concat(command.type, " is not allowed in the template of the promptbook ONLY at the pipeline head\n\n ").concat(block(getPipelineIdentification()), "\n "); })); // <- TODO: [🚞]
@@ -8209,17 +8131,17 @@ function pipelineStringToJsonSync(pipelineString) {
8209
8131
  };
8210
8132
  try {
8211
8133
  // TODO [♓️] List commands and before apply order them to achieve order-agnostic commands
8212
- for (var commands_1 = (e_3 = void 0, __values(commands)), commands_1_1 = commands_1.next(); !commands_1_1.done; commands_1_1 = commands_1.next()) {
8213
- var _f = commands_1_1.value, listItem = _f.listItem, command = _f.command;
8214
- _loop_3(listItem, command);
8134
+ for (var commands_1 = (e_5 = void 0, __values(commands)), commands_1_1 = commands_1.next(); !commands_1_1.done; commands_1_1 = commands_1.next()) {
8135
+ var _p = commands_1_1.value, listItem = _p.listItem, command = _p.command;
8136
+ _loop_4(listItem, command);
8215
8137
  }
8216
8138
  }
8217
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
8139
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
8218
8140
  finally {
8219
8141
  try {
8220
- if (commands_1_1 && !commands_1_1.done && (_d = commands_1.return)) _d.call(commands_1);
8142
+ if (commands_1_1 && !commands_1_1.done && (_l = commands_1.return)) _l.call(commands_1);
8221
8143
  }
8222
- finally { if (e_3) throw e_3.error; }
8144
+ finally { if (e_5) throw e_5.error; }
8223
8145
  }
8224
8146
  // TODO: [🍧] Should be done in TEMPLATE command
8225
8147
  if ($templateJson.templateType === 'SCRIPT_TEMPLATE') {
@@ -8233,6 +8155,26 @@ function pipelineStringToJsonSync(pipelineString) {
8233
8155
  language;
8234
8156
  }
8235
8157
  $templateJson.dependentParameterNames = Array.from(extractParameterNamesFromTemplate($templateJson));
8158
+ try {
8159
+ for (var _q = (e_6 = void 0, __values($templateJson.dependentParameterNames)), _r = _q.next(); !_r.done; _r = _q.next()) {
8160
+ var parameterName = _r.value;
8161
+ // TODO: [🧠] This definition should be made first in the template
8162
+ defineParam({
8163
+ parameterName: parameterName,
8164
+ parameterDescription: null,
8165
+ isInput: false,
8166
+ isOutput: false,
8167
+ // <- Note: In this case null+false+false means that we do not know yet if it is input or output and we will set it later
8168
+ });
8169
+ }
8170
+ }
8171
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
8172
+ finally {
8173
+ try {
8174
+ if (_r && !_r.done && (_m = _q.return)) _m.call(_q);
8175
+ }
8176
+ finally { if (e_6) throw e_6.error; }
8177
+ }
8236
8178
  /*
8237
8179
  // TODO: [🍧] This should be checked in `MODEL` command + better error message
8238
8180
  if ($templateJson.templateType !== 'PROMPT_TEMPLATE' && $templateJson.modelRequirements !== undefined) {
@@ -8271,12 +8213,54 @@ function pipelineStringToJsonSync(pipelineString) {
8271
8213
  try {
8272
8214
  if (pipelineSections_1_1 && !pipelineSections_1_1.done && (_b = pipelineSections_1.return)) _b.call(pipelineSections_1);
8273
8215
  }
8274
- finally { if (e_2) throw e_2.error; }
8216
+ finally { if (e_2) throw e_2.error; }
8217
+ }
8218
+ // =============================================================
8219
+ // Note: 5️⃣ Mark parameters as INPUT if not explicitly set
8220
+ if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isInput; })) {
8221
+ var _loop_3 = function (parameter) {
8222
+ var isThisParameterResulting = $pipelineJson.templates.some(function (template) { return template.resultingParameterName === parameter.name; });
8223
+ if (!isThisParameterResulting) {
8224
+ parameter.isInput = true;
8225
+ }
8226
+ };
8227
+ try {
8228
+ for (var _g = __values($pipelineJson.parameters), _h = _g.next(); !_h.done; _h = _g.next()) {
8229
+ var parameter = _h.value;
8230
+ _loop_3(parameter);
8231
+ }
8232
+ }
8233
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
8234
+ finally {
8235
+ try {
8236
+ if (_h && !_h.done && (_c = _g.return)) _c.call(_g);
8237
+ }
8238
+ finally { if (e_3) throw e_3.error; }
8239
+ }
8240
+ }
8241
+ // =============================================================
8242
+ // Note: 6️⃣ Mark all non-INPUT parameters as OUTPUT if any OUTPUT is not set
8243
+ if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isOutput; })) {
8244
+ try {
8245
+ for (var _j = __values($pipelineJson.parameters), _k = _j.next(); !_k.done; _k = _j.next()) {
8246
+ var parameter = _k.value;
8247
+ if (!parameter.isInput) {
8248
+ parameter.isOutput = true;
8249
+ }
8250
+ }
8251
+ }
8252
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
8253
+ finally {
8254
+ try {
8255
+ if (_k && !_k.done && (_d = _j.return)) _d.call(_j);
8256
+ }
8257
+ finally { if (e_4) throw e_4.error; }
8258
+ }
8275
8259
  }
8276
8260
  // =============================================================
8277
- // Note: 5️⃣ Cleanup of undefined values
8261
+ // Note: 7️⃣ Cleanup of undefined values
8278
8262
  $pipelineJson.templates.forEach(function (templates) {
8279
- var e_4, _a;
8263
+ var e_7, _a;
8280
8264
  try {
8281
8265
  for (var _b = __values(Object.entries(templates)), _c = _b.next(); !_c.done; _c = _b.next()) {
8282
8266
  var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
@@ -8285,16 +8269,16 @@ function pipelineStringToJsonSync(pipelineString) {
8285
8269
  }
8286
8270
  }
8287
8271
  }
8288
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
8272
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
8289
8273
  finally {
8290
8274
  try {
8291
8275
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
8292
8276
  }
8293
- finally { if (e_4) throw e_4.error; }
8277
+ finally { if (e_7) throw e_7.error; }
8294
8278
  }
8295
8279
  });
8296
8280
  $pipelineJson.parameters.forEach(function (parameter) {
8297
- var e_5, _a;
8281
+ var e_8, _a;
8298
8282
  try {
8299
8283
  for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
8300
8284
  var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
@@ -8303,12 +8287,12 @@ function pipelineStringToJsonSync(pipelineString) {
8303
8287
  }
8304
8288
  }
8305
8289
  }
8306
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
8290
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
8307
8291
  finally {
8308
8292
  try {
8309
8293
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
8310
8294
  }
8311
- finally { if (e_5) throw e_5.error; }
8295
+ finally { if (e_8) throw e_8.error; }
8312
8296
  }
8313
8297
  });
8314
8298
  // =============================================================
@@ -8418,8 +8402,7 @@ function $provideFilesystemForNode(options) {
8418
8402
  if (!$isRunningInNode()) {
8419
8403
  throw new EnvironmentMismatchError('Function `$provideFilesystemForNode` works only in Node.js environment');
8420
8404
  }
8421
- var _a = (options || {}).isVerbose, isVerbose = _a === void 0 ? DEFAULT_IS_VERBOSE : _a;
8422
- TODO_USE(isVerbose);
8405
+ (options || {}).isVerbose;
8423
8406
  return {
8424
8407
  stat: stat,
8425
8408
  access: access,
@@ -8665,7 +8648,7 @@ function locatePandoc() {
8665
8648
  */
8666
8649
  function $provideExecutablesForNode(options) {
8667
8650
  return __awaiter(this, void 0, void 0, function () {
8668
- var _a, _b, isAutoInstalled, _c, isVerbose;
8651
+ var _a;
8669
8652
  var _d;
8670
8653
  return __generator(this, function (_e) {
8671
8654
  switch (_e.label) {
@@ -8673,9 +8656,7 @@ function $provideExecutablesForNode(options) {
8673
8656
  if (!$isRunningInNode()) {
8674
8657
  throw new EnvironmentMismatchError('Function `$getScrapersForNode` works only in Node.js environment');
8675
8658
  }
8676
- _a = options || {}, _b = _a.isAutoInstalled, isAutoInstalled = _b === void 0 ? DEFAULT_IS_AUTO_INSTALLED : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? DEFAULT_IS_VERBOSE : _c;
8677
- TODO_USE(isAutoInstalled); // <- TODO: [🔱][🧠] Auto-install the executables
8678
- TODO_USE(isVerbose);
8659
+ _a = options || {}, _a.isAutoInstalled, _a.isVerbose;
8679
8660
  _d = {};
8680
8661
  return [4 /*yield*/, locatePandoc()];
8681
8662
  case 1:
@@ -8932,7 +8913,7 @@ function $provideLlmToolsFromEnv(options) {
8932
8913
  */
8933
8914
  function $provideScrapersForNode(tools, options) {
8934
8915
  return __awaiter(this, void 0, void 0, function () {
8935
- var _a, _b, isAutoInstalled, _c, isVerbose, scrapers, _d, _e, scraperFactory, scraper, e_1_1;
8916
+ var _a, scrapers, _d, _e, scraperFactory, scraper, e_1_1;
8936
8917
  var e_1, _f;
8937
8918
  return __generator(this, function (_g) {
8938
8919
  switch (_g.label) {
@@ -8940,9 +8921,7 @@ function $provideScrapersForNode(tools, options) {
8940
8921
  if (!$isRunningInNode()) {
8941
8922
  throw new EnvironmentMismatchError('Function `$getScrapersForNode` works only in Node.js environment');
8942
8923
  }
8943
- _a = options || {}, _b = _a.isAutoInstalled, isAutoInstalled = _b === void 0 ? DEFAULT_IS_AUTO_INSTALLED : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? DEFAULT_IS_VERBOSE : _c;
8944
- TODO_USE(isAutoInstalled);
8945
- TODO_USE(isVerbose);
8924
+ _a = options || {}, _a.isAutoInstalled, _a.isVerbose;
8946
8925
  scrapers = [];
8947
8926
  _g.label = 1;
8948
8927
  case 1:
@@ -10101,7 +10080,7 @@ var FileCacheStorage = /** @class */ (function () {
10101
10080
  */
10102
10081
 
10103
10082
  /**
10104
- * Stores
10083
+ * Stores data in memory (HEAP)
10105
10084
  *
10106
10085
  * @public exported from `@promptbook/core`
10107
10086
  */
@@ -10231,13 +10210,18 @@ function cacheLlmTools(llmTools, options) {
10231
10210
  promptResult = _c.sent();
10232
10211
  return [3 /*break*/, 11];
10233
10212
  case 10: throw new PipelineExecutionError("Unknown model variant \"".concat(prompt.modelRequirements.modelVariant, "\""));
10234
- case 11: return [4 /*yield*/, storage.setItem(key, {
10213
+ case 11:
10214
+ // TODO: [🧠] !!!!!! How to do timing in mixed cache / non-cache situation
10215
+ // promptResult.timing: FromtoItems
10216
+ return [4 /*yield*/, storage.setItem(key, {
10235
10217
  date: $currentDate(),
10236
- promptbookVersion: PROMPTBOOK_VERSION,
10218
+ promptbookVersion: PROMPTBOOK_ENGINE_VERSION,
10237
10219
  prompt: prompt,
10238
10220
  promptResult: promptResult,
10239
10221
  })];
10240
10222
  case 12:
10223
+ // TODO: [🧠] !!!!!! How to do timing in mixed cache / non-cache situation
10224
+ // promptResult.timing: FromtoItems
10241
10225
  _c.sent();
10242
10226
  return [2 /*return*/, promptResult];
10243
10227
  }
@@ -10311,6 +10295,7 @@ function initializeMakeCommand(program) {
10311
10295
  var _this = this;
10312
10296
  var makeCommand = program.command('make');
10313
10297
  makeCommand.description(spaceTrim$1("\n Makes a new pipeline collection in given folder\n "));
10298
+ // TODO: [🧅] DRY command arguments
10314
10299
  makeCommand.argument('[path]',
10315
10300
  // <- TODO: [🧟‍♂️] Unite path to promptbook collection argument
10316
10301
  'Path to promptbook collection directory', './promptbook-collection');
@@ -10318,13 +10303,13 @@ function initializeMakeCommand(program) {
10318
10303
  makeCommand.option('-f, --format <format>', spaceTrim$1("\n Output format of builded collection \"javascript\", \"typescript\" or \"json\"\n\n Note: You can use multiple formats separated by comma\n "), 'javascript' /* <- Note: [🏳‍🌈] */);
10319
10304
  makeCommand.option('--no-validation', "Do not validate logic of pipelines in collection", true);
10320
10305
  makeCommand.option('--validation', "Types of validations separated by comma (options \"logic\",\"imports\")", 'logic,imports');
10321
- makeCommand.option('--reload', "Call LLM models even if same prompt with result is in the cache", false);
10322
- makeCommand.option('--verbose', "Is output verbose", false);
10306
+ makeCommand.option('-r, --reload', "Call LLM models even if same prompt with result is in the cache", false);
10307
+ makeCommand.option('-v, --verbose', "Is output verbose", false);
10323
10308
  makeCommand.option('-o, --out-file <path>', spaceTrim$1("\n Where to save the builded collection\n\n Note: If you keep it \"".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, "\" it will be saved in the root of the promptbook directory\n If you set it to a path, it will be saved in that path\n BUT you can use only one format and set correct extension\n ")), DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME);
10324
10309
  makeCommand.action(function (path, _a) {
10325
- var projectName = _a.projectName, format = _a.format, validation = _a.validation, isCacheReloaded = _a.reloadCache, isVerbose = _a.verbose, outFile = _a.outFile;
10310
+ var projectName = _a.projectName, format = _a.format, validation = _a.validation, isCacheReloaded = _a.reload, isVerbose = _a.verbose, outFile = _a.outFile;
10326
10311
  return __awaiter(_this, void 0, void 0, function () {
10327
- var formats, validations, options, fs, llm, executables, tools, collection, validations_1, validations_1_1, validation_1, _b, _c, pipelineUrl, pipeline, e_1_1, e_2_1, collectionJson, collectionJsonString, collectionJsonItems, saveFile;
10312
+ var formats, validations, prepareAndScrapeOptions, fs, llm, executables, tools, collection, validations_1, validations_1_1, validation_1, _b, _c, pipelineUrl, pipeline, e_1_1, e_2_1, collectionJson, collectionJsonString, collectionJsonItems, saveFile;
10328
10313
  var _d, e_2, _e, e_1, _f;
10329
10314
  var _this = this;
10330
10315
  return __generator(this, function (_g) {
@@ -10340,22 +10325,22 @@ function initializeMakeCommand(program) {
10340
10325
  .filter(function (_) { return _ !== ''; });
10341
10326
  if (outFile !== DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME && formats.length !== 1) {
10342
10327
  console.error(colors.red("You can only use one format if you specify --out-file"));
10343
- process.exit(1);
10328
+ return [2 /*return*/, process.exit(1)];
10344
10329
  }
10345
- options = {
10330
+ prepareAndScrapeOptions = {
10346
10331
  isVerbose: isVerbose,
10347
10332
  isCacheReloaded: isCacheReloaded,
10348
10333
  };
10349
- fs = $provideFilesystemForNode(options);
10350
- llm = $provideLlmToolsForCli(options);
10351
- return [4 /*yield*/, $provideExecutablesForNode(options)];
10334
+ fs = $provideFilesystemForNode(prepareAndScrapeOptions);
10335
+ llm = $provideLlmToolsForCli(prepareAndScrapeOptions);
10336
+ return [4 /*yield*/, $provideExecutablesForNode(prepareAndScrapeOptions)];
10352
10337
  case 1:
10353
10338
  executables = _g.sent();
10354
10339
  _d = {
10355
10340
  llm: llm,
10356
10341
  fs: fs
10357
10342
  };
10358
- return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables }, options)];
10343
+ return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables }, prepareAndScrapeOptions)];
10359
10344
  case 2:
10360
10345
  tools = (_d.scrapers = _g.sent(),
10361
10346
  _d.script = [
@@ -10492,8 +10477,7 @@ function initializeMakeCommand(program) {
10492
10477
  if (isVerbose) {
10493
10478
  console.info(colors.cyan(usageToHuman(llm.getTotalUsage())));
10494
10479
  }
10495
- process.exit(0);
10496
- return [2 /*return*/];
10480
+ return [2 /*return*/, process.exit(0)];
10497
10481
  }
10498
10482
  });
10499
10483
  });
@@ -10501,7 +10485,6 @@ function initializeMakeCommand(program) {
10501
10485
  }
10502
10486
  /**
10503
10487
  * TODO: [🥃][main] !!! Allow `ptbk make` without configuring any llm tools
10504
- * TODO: Maybe remove this command - "about" command should be enough?
10505
10488
  * TODO: [0] DRY Javascript and typescript - Maybe make ONLY typescript and for javascript just remove types
10506
10489
  * Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
10507
10490
  * TODO: [🖇] What about symlinks? Maybe flag --follow-symlinks
@@ -10702,8 +10685,7 @@ function initializePrettifyCommand(program) {
10702
10685
  console.info(colors.red("Prettify ".concat(error_1.name, " ").concat(filename)));
10703
10686
  console.error(colors.bgRed(error_1.name /* <- 11:11 */));
10704
10687
  console.error(colors.red(error_1.stack || error_1.message));
10705
- process.exit(1);
10706
- return [3 /*break*/, 9];
10688
+ return [2 /*return*/, process.exit(1)];
10707
10689
  case 9:
10708
10690
  filenames_1_1 = filenames_1.next();
10709
10691
  return [3 /*break*/, 3];
@@ -10720,8 +10702,7 @@ function initializePrettifyCommand(program) {
10720
10702
  return [7 /*endfinally*/];
10721
10703
  case 13:
10722
10704
  console.info(colors.green("All pipelines are prettified"));
10723
- process.exit(0);
10724
- return [2 /*return*/];
10705
+ return [2 /*return*/, process.exit(0)];
10725
10706
  }
10726
10707
  });
10727
10708
  });
@@ -10733,6 +10714,606 @@ function initializePrettifyCommand(program) {
10733
10714
  * TODO: [🖇] What about symlinks? Maybe flag --follow-symlinks
10734
10715
  */
10735
10716
 
10717
+ /**
10718
+ * Pretty print an embedding vector for logging
10719
+ *
10720
+ * @public exported from `@promptbook/core`
10721
+ */
10722
+ function embeddingVectorToString(embeddingVector) {
10723
+ var vectorLength = Math.pow(embeddingVector.reduce(function (acc, val) { return acc + Math.pow(val, 2); }, 0), 0.5);
10724
+ return "[EmbeddingVector; ".concat(embeddingVector.length, " dimensions; length: ").concat(vectorLength.toFixed(2), "; ").concat(embeddingVector.slice(0, 3).join(', '), "...]");
10725
+ }
10726
+
10727
+ /**
10728
+ * Format either small or big number
10729
+ *
10730
+ * @private within the repository
10731
+ */
10732
+ function formatNumber(value) {
10733
+ if (value === 0) {
10734
+ return '0';
10735
+ }
10736
+ for (var exponent = 0; exponent < 15; exponent++) {
10737
+ var factor = Math.pow(10, exponent);
10738
+ var valueRounded = Math.round(value * factor) / factor;
10739
+ if (Math.abs(value - valueRounded) / value <
10740
+ 0.001 /* <- TODO: Pass as option, pass to executionReportJsonToString as option */) {
10741
+ return valueRounded.toFixed(exponent);
10742
+ }
10743
+ }
10744
+ return value.toString();
10745
+ }
10746
+
10747
+ /**
10748
+ * Create a markdown table from a 2D array of strings
10749
+ *
10750
+ * @public exported from `@promptbook/markdown-utils`
10751
+ */
10752
+ function createMarkdownTable(table) {
10753
+ var columnWidths = table.reduce(function (widths, row) {
10754
+ row.forEach(function (subformat, columnIndex) {
10755
+ var cellLength = subformat.length;
10756
+ if (!widths[columnIndex] || cellLength > widths[columnIndex]) {
10757
+ widths[columnIndex] = cellLength;
10758
+ }
10759
+ });
10760
+ return widths;
10761
+ }, []);
10762
+ var header = "| ".concat(table[0]
10763
+ .map(function (subformat, columnIndex) { return subformat.padEnd(columnWidths[columnIndex]); })
10764
+ .join(' | '), " |");
10765
+ var separator = "|".concat(columnWidths.map(function (width) { return '-'.repeat(width + 2); }).join('|'), "|");
10766
+ var rows = table.slice(1).map(function (row) {
10767
+ var paddedRow = row.map(function (subformat, columnIndex) {
10768
+ return subformat.padEnd(columnWidths[columnIndex]);
10769
+ });
10770
+ return "| ".concat(paddedRow.join(' | '), " |");
10771
+ });
10772
+ return __spreadArray([header, separator], __read(rows), false).join('\n');
10773
+ }
10774
+ /**
10775
+ * TODO: [🏛] This can be part of markdown builder
10776
+ */
10777
+
10778
+ /**
10779
+ * Function createMarkdownChart will draw a chart in markdown from ⬛+🟦 tiles
10780
+ *
10781
+ * @public exported from `@promptbook/markdown-utils`
10782
+ */
10783
+ function createMarkdownChart(options) {
10784
+ var e_1, _a;
10785
+ var nameHeader = options.nameHeader, valueHeader = options.valueHeader, items = options.items, width = options.width, unitName = options.unitName;
10786
+ var from = Math.min.apply(Math, __spreadArray([], __read(items.map(function (item) { return item.from; })), false));
10787
+ var to = Math.max.apply(Math, __spreadArray([], __read(items.map(function (item) { return item.to; })), false));
10788
+ var scale = width / (to - from);
10789
+ var table = [[nameHeader, valueHeader]];
10790
+ try {
10791
+ for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
10792
+ var item = items_1_1.value;
10793
+ var before = Math.round((item.from - from) * scale);
10794
+ var during = Math.round((item.to - item.from) * scale);
10795
+ var after = width - before - during;
10796
+ table.push([removeEmojis(item.title).trim(), '░'.repeat(before) + '█'.repeat(during) + '░'.repeat(after)]);
10797
+ }
10798
+ }
10799
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
10800
+ finally {
10801
+ try {
10802
+ if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
10803
+ }
10804
+ finally { if (e_1) throw e_1.error; }
10805
+ }
10806
+ var legend = "_Note: Each \u2588 represents ".concat(formatNumber(1 / scale), " ").concat(unitName, ", width of ").concat(valueHeader.toLowerCase(), " is ").concat(formatNumber(to - from), " ").concat(unitName, " = ").concat(width, " squares_");
10807
+ return createMarkdownTable(table) + '\n\n' + legend;
10808
+ }
10809
+ /**
10810
+ * TODO: Maybe use Mermain Gant Diagrams
10811
+ * @see https://jojozhuang.github.io/tutorial/mermaid-cheat-sheet/
10812
+ */
10813
+
10814
+ /**
10815
+ * Function escapeMarkdownBlock will escape markdown block if needed
10816
+ * It is useful when you want have block in block
10817
+ *
10818
+ * @public exported from `@promptbook/markdown-utils`
10819
+ */
10820
+ function escapeMarkdownBlock(value) {
10821
+ return value.replace(/```/g, '\\`\\`\\`');
10822
+ }
10823
+ /**
10824
+ * TODO: [🏛] This can be part of markdown builder
10825
+ */
10826
+
10827
+ /**
10828
+ * Default options for generating an execution report string
10829
+ *
10830
+ * @public exported from `@promptbook/core`
10831
+ */
10832
+ var ExecutionReportStringOptionsDefaults = {
10833
+ taxRate: 0,
10834
+ chartsWidth: 36,
10835
+ };
10836
+
10837
+ /**
10838
+ * Count the duration of working time
10839
+ *
10840
+ * @private within the repository
10841
+ */
10842
+ function countWorkingDuration(items) {
10843
+ var e_1, _a;
10844
+ var steps = Array.from(new Set(items.flatMap(function (item) { return [item.from, item.to]; })));
10845
+ steps.sort(function (a, b) { return a - b; });
10846
+ var intervals = steps.map(function (step, index) { return [step, steps[index + 1] || 0]; }).slice(0, -1);
10847
+ var duration = 0;
10848
+ var _loop_1 = function (interval) {
10849
+ var _b = __read(interval, 2), from = _b[0], to = _b[1];
10850
+ if (items.some(function (item) { return item.from < to && item.to > from; })) {
10851
+ duration += to - from;
10852
+ }
10853
+ };
10854
+ try {
10855
+ for (var intervals_1 = __values(intervals), intervals_1_1 = intervals_1.next(); !intervals_1_1.done; intervals_1_1 = intervals_1.next()) {
10856
+ var interval = intervals_1_1.value;
10857
+ _loop_1(interval);
10858
+ }
10859
+ }
10860
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
10861
+ finally {
10862
+ try {
10863
+ if (intervals_1_1 && !intervals_1_1.done && (_a = intervals_1.return)) _a.call(intervals_1);
10864
+ }
10865
+ finally { if (e_1) throw e_1.error; }
10866
+ }
10867
+ return duration;
10868
+ }
10869
+
10870
+ /**
10871
+ * Converts execution report from JSON to string format
10872
+ *
10873
+ * @public exported from `@promptbook/core`
10874
+ */
10875
+ function executionReportJsonToString(executionReportJson, options) {
10876
+ var e_1, _a;
10877
+ var _b, _c, _d, _e, _f, _g;
10878
+ var _h = __assign(__assign({}, ExecutionReportStringOptionsDefaults), (options || {})), taxRate = _h.taxRate, chartsWidth = _h.chartsWidth;
10879
+ var executionReportString = spaceTrim(function (block) { return "\n # ".concat(executionReportJson.title || 'Execution report', "\n\n ").concat(block(executionReportJson.description || ''), "\n "); });
10880
+ var headerList = [];
10881
+ if (executionReportJson.pipelineUrl) {
10882
+ headerList.push("PIPELINE URL ".concat(executionReportJson.pipelineUrl));
10883
+ }
10884
+ headerList.push("PROMPTBOOK VERSION ".concat(executionReportJson.promptbookUsedVersion) +
10885
+ (!executionReportJson.promptbookRequestedVersion
10886
+ ? ''
10887
+ : " *(requested ".concat(executionReportJson.promptbookRequestedVersion, ")*")));
10888
+ if (executionReportJson.promptExecutions.length !== 0) {
10889
+ // TODO: What if startedAt OR/AND completedAt is not defined?
10890
+ var startedAt = moment(Math.min.apply(Math, __spreadArray([], __read(executionReportJson.promptExecutions
10891
+ .filter(function (promptExecution) { var _a, _b; return (_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.start; })
10892
+ .map(function (promptExecution) { return moment(promptExecution.result.timing.start).valueOf(); })), false)));
10893
+ var completedAt = moment(Math.max.apply(Math, __spreadArray([], __read(executionReportJson.promptExecutions
10894
+ .filter(function (promptExecution) { var _a, _b; return (_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.complete; })
10895
+ .map(function (promptExecution) { return moment(promptExecution.result.timing.complete).valueOf(); })), false)));
10896
+ var timingItems = executionReportJson.promptExecutions.map(function (promptExecution) {
10897
+ var _a, _b, _c, _d;
10898
+ return ({
10899
+ title: promptExecution.prompt.title,
10900
+ from: moment((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.timing) === null || _b === void 0 ? void 0 : _b.start).valueOf() / 1000,
10901
+ to: moment((_d = (_c = promptExecution.result) === null || _c === void 0 ? void 0 : _c.timing) === null || _d === void 0 ? void 0 : _d.complete).valueOf() / 1000,
10902
+ });
10903
+ });
10904
+ var costItems = executionReportJson.promptExecutions
10905
+ .filter(function (promptExecution) { var _a, _b; return typeof ((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) === 'number'; })
10906
+ .map(function (promptExecution) {
10907
+ var _a, _b;
10908
+ return ({
10909
+ title: promptExecution.prompt.title,
10910
+ from: 0,
10911
+ to: (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price.value) || 0) /* <- TODO: look at uncertain numbers */ *
10912
+ (1 + taxRate),
10913
+ });
10914
+ });
10915
+ var duration = moment.duration(completedAt.diff(startedAt));
10916
+ var llmDuration = moment.duration(countWorkingDuration(timingItems) * 1000);
10917
+ var executionsWithKnownCost = executionReportJson.promptExecutions.filter(function (promptExecution) { var _a, _b; return (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) || 'UNKNOWN') !== 'UNKNOWN'; });
10918
+ var cost = executionsWithKnownCost.reduce(function (cost, promptExecution) {
10919
+ return cost + (promptExecution.result.usage.price.value /* <- Look at uncertain number */ || 0);
10920
+ }, 0);
10921
+ headerList.push("STARTED AT ".concat(moment(startedAt).format("YYYY-MM-DD HH:mm:ss")));
10922
+ headerList.push("COMPLETED AT ".concat(moment(completedAt).format("YYYY-MM-DD HH:mm:ss")));
10923
+ headerList.push("TOTAL DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
10924
+ headerList.push("TOTAL LLM DURATION ".concat(llmDuration.humanize(MOMENT_ARG_THRESHOLDS)));
10925
+ headerList.push("TOTAL COST $".concat(formatNumber(cost * (1 + taxRate))) +
10926
+ (executionsWithKnownCost.length === executionReportJson.promptExecutions.length
10927
+ ? ''
10928
+ : " *(Some cost is unknown)*") +
10929
+ (taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
10930
+ executionReportString += '\n\n' + headerList.map(function (header) { return "- ".concat(header); }).join('\n');
10931
+ executionReportString +=
10932
+ '\n\n' +
10933
+ '## 🗃 Index' +
10934
+ '\n\n' +
10935
+ executionReportJson.promptExecutions
10936
+ .map(function (promptExecution) {
10937
+ // TODO: Make some better system to convert hedings to links
10938
+ var hash = normalizeToKebabCase(promptExecution.prompt.title);
10939
+ if (/^\s*\p{Extended_Pictographic}/u.test(promptExecution.prompt.title)) {
10940
+ hash = '-' + hash;
10941
+ }
10942
+ // TODO: Make working hash link for the template in md + pdf
10943
+ return "- [".concat(promptExecution.prompt.title, "](#").concat(hash, ")");
10944
+ })
10945
+ .join('\n');
10946
+ executionReportString +=
10947
+ '\n\n' +
10948
+ '## ⌚ Time chart' +
10949
+ '\n\n' +
10950
+ createMarkdownChart({
10951
+ nameHeader: 'Template',
10952
+ valueHeader: 'Timeline',
10953
+ items: timingItems,
10954
+ width: chartsWidth,
10955
+ unitName: 'seconds',
10956
+ });
10957
+ executionReportString +=
10958
+ '\n\n' +
10959
+ '## 💸 Cost chart' +
10960
+ '\n\n' +
10961
+ createMarkdownChart({
10962
+ nameHeader: 'Template',
10963
+ valueHeader: 'Cost',
10964
+ items: costItems,
10965
+ width: chartsWidth,
10966
+ unitName: 'USD',
10967
+ });
10968
+ }
10969
+ else {
10970
+ headerList.push("TOTAL COST $0 *(Nothing executed)*");
10971
+ }
10972
+ var _loop_1 = function (promptExecution) {
10973
+ executionReportString += '\n\n\n\n' + "## ".concat(promptExecution.prompt.title);
10974
+ var templateList = [];
10975
+ // TODO: What if startedAt OR/AND completedAt is not defined?
10976
+ var startedAt = moment((_c = (_b = promptExecution.result) === null || _b === void 0 ? void 0 : _b.timing) === null || _c === void 0 ? void 0 : _c.start);
10977
+ var completedAt = moment((_e = (_d = promptExecution.result) === null || _d === void 0 ? void 0 : _d.timing) === null || _e === void 0 ? void 0 : _e.complete);
10978
+ var duration = moment.duration(completedAt.diff(startedAt));
10979
+ // Not need here:
10980
+ // > templateList.push(`STARTED AT ${moment(startedAt).calendar()}`);
10981
+ templateList.push("DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
10982
+ if (typeof ((_g = (_f = promptExecution.result) === null || _f === void 0 ? void 0 : _f.usage) === null || _g === void 0 ? void 0 : _g.price) === 'number') {
10983
+ templateList.push("COST $".concat(formatNumber(promptExecution.result.usage.price * (1 + taxRate))) +
10984
+ (taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
10985
+ }
10986
+ else {
10987
+ templateList.push("COST UNKNOWN");
10988
+ }
10989
+ executionReportString += '\n\n' + templateList.map(function (header) { return "- ".concat(header); }).join('\n');
10990
+ /*
10991
+ - MODEL VARIANT ${promptExecution.prompt.modelRequirements.modelVariant}
10992
+ - MODEL NAME \`${promptExecution.result?.model}\` (requested \`${
10993
+ promptExecution.prompt.modelRequirements.modelName
10994
+
10995
+ */
10996
+ if (just(true)) {
10997
+ executionReportString +=
10998
+ '\n\n\n\n' +
10999
+ spaceTrim(function (block) {
11000
+ var _a;
11001
+ return "\n\n ### Prompt\n\n ```\n ".concat(block(escapeMarkdownBlock(((_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.rawPromptContent) || promptExecution.prompt.content)), "\n ```\n\n ");
11002
+ });
11003
+ }
11004
+ if (promptExecution.result && promptExecution.result.content) {
11005
+ executionReportString += '\n\n\n\n' + '### Result' + '\n\n';
11006
+ if (promptExecution.result === undefined) {
11007
+ executionReportString += '*No result*';
11008
+ }
11009
+ else if (typeof promptExecution.result.content === 'string') {
11010
+ executionReportString += spaceTrim(function (block) { return "\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.result.content)), "\n ```\n "); });
11011
+ }
11012
+ else {
11013
+ executionReportString += embeddingVectorToString(promptExecution.result.content);
11014
+ }
11015
+ }
11016
+ if (promptExecution.error && promptExecution.error.message) {
11017
+ executionReportString +=
11018
+ '\n\n\n\n' +
11019
+ spaceTrim(function (block) { return "\n\n ### Error\n\n ```\n ".concat(block(escapeMarkdownBlock(promptExecution.error.message)), "\n ```\n\n "); });
11020
+ }
11021
+ };
11022
+ try {
11023
+ for (var _j = __values(executionReportJson.promptExecutions), _k = _j.next(); !_k.done; _k = _j.next()) {
11024
+ var promptExecution = _k.value;
11025
+ _loop_1(promptExecution);
11026
+ }
11027
+ }
11028
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
11029
+ finally {
11030
+ try {
11031
+ if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
11032
+ }
11033
+ finally { if (e_1) throw e_1.error; }
11034
+ }
11035
+ executionReportString = prettifyMarkdown(executionReportString);
11036
+ return executionReportString;
11037
+ }
11038
+ /**
11039
+ * TODO: Add mermaid chart for every report
11040
+ * TODO: [🧠] Allow to filter out some parts of the report by options
11041
+ * TODO: [🧠] Should be in generated file GENERATOR_WARNING
11042
+ */
11043
+
11044
+ /**
11045
+ * Initializes `run` command for Promptbook CLI utilities
11046
+ *
11047
+ * @private internal function of `promptbookCli`
11048
+ */
11049
+ function initializeRunCommand(program) {
11050
+ var _this = this;
11051
+ var runCommand = program.command('run', { isDefault: true });
11052
+ runCommand.description(spaceTrim$1("\n Runs a pipeline\n "));
11053
+ // TODO: [🧅] DRY command arguments
11054
+ runCommand.argument('<path>',
11055
+ // <- Note: [🧟‍♂️] This is NOT promptbook collection directory BUT direct path to .ptbk.md file
11056
+ 'Path to book file');
11057
+ runCommand.option('-r, --reload', "Call LLM models even if same prompt with result is in the cache", false);
11058
+ runCommand.option('-v, --verbose', "Is output verbose", false);
11059
+ runCommand.option('--no-interactive', "Input is not interactive", false);
11060
+ runCommand.option('-s, --save-report <path>', "Save report to file");
11061
+ // TODO: !!!!!! Implement non-interactive mode - allow to pass input parameters as JSON
11062
+ // TODO: !!!!!! JSON output
11063
+ runCommand.action(function (filePathRaw, options) { return __awaiter(_this, void 0, void 0, function () {
11064
+ var isCacheReloaded, isVerbose, saveReport, prepareAndScrapeOptions, fs, filePath, filePathCandidates, filePathCandidates_1, filePathCandidates_1_1, filePathCandidate, e_1_1, llm, executables, tools, pipelineString, pipeline, error_1, pipelineExecutor, questions, response, inputParameters, result, isSuccessful, errors, warnings, outputParameters, executionReport, executionReportString, _a, _b, error, _c, _d, warning, _e, _f, key, value, separator;
11065
+ var e_1, _g, _h, e_2, _j, e_3, _k, e_4, _l;
11066
+ return __generator(this, function (_m) {
11067
+ switch (_m.label) {
11068
+ case 0:
11069
+ isCacheReloaded = options.reload, options.interactive, isVerbose = options.verbose, saveReport = options.saveReport;
11070
+ if (saveReport && !saveReport.endsWith('.json') && !saveReport.endsWith('.md')) {
11071
+ console.error(colors.red("Report file must be .json or .md"));
11072
+ return [2 /*return*/, process.exit(1)];
11073
+ }
11074
+ prepareAndScrapeOptions = {
11075
+ isVerbose: isVerbose,
11076
+ isCacheReloaded: isCacheReloaded,
11077
+ };
11078
+ if (isVerbose) {
11079
+ console.info(colors.gray('--- Preparing tools ---'));
11080
+ }
11081
+ fs = $provideFilesystemForNode(prepareAndScrapeOptions);
11082
+ filePath = null;
11083
+ filePathCandidates = [
11084
+ filePathRaw,
11085
+ "".concat(filePathRaw, ".md"),
11086
+ "".concat(filePathRaw, ".book.md"),
11087
+ "".concat(filePathRaw, ".ptbk.md"),
11088
+ ];
11089
+ _m.label = 1;
11090
+ case 1:
11091
+ _m.trys.push([1, 6, 7, 8]);
11092
+ filePathCandidates_1 = __values(filePathCandidates), filePathCandidates_1_1 = filePathCandidates_1.next();
11093
+ _m.label = 2;
11094
+ case 2:
11095
+ if (!!filePathCandidates_1_1.done) return [3 /*break*/, 5];
11096
+ filePathCandidate = filePathCandidates_1_1.value;
11097
+ return [4 /*yield*/, isFileExisting(filePathCandidate, fs)
11098
+ // <- TODO: Also test that among the candidates the file is book not just any file
11099
+ ];
11100
+ case 3:
11101
+ if (_m.sent()
11102
+ // <- TODO: Also test that among the candidates the file is book not just any file
11103
+ ) {
11104
+ filePath = filePathCandidate;
11105
+ return [3 /*break*/, 5];
11106
+ }
11107
+ _m.label = 4;
11108
+ case 4:
11109
+ filePathCandidates_1_1 = filePathCandidates_1.next();
11110
+ return [3 /*break*/, 2];
11111
+ case 5: return [3 /*break*/, 8];
11112
+ case 6:
11113
+ e_1_1 = _m.sent();
11114
+ e_1 = { error: e_1_1 };
11115
+ return [3 /*break*/, 8];
11116
+ case 7:
11117
+ try {
11118
+ if (filePathCandidates_1_1 && !filePathCandidates_1_1.done && (_g = filePathCandidates_1.return)) _g.call(filePathCandidates_1);
11119
+ }
11120
+ finally { if (e_1) throw e_1.error; }
11121
+ return [7 /*endfinally*/];
11122
+ case 8:
11123
+ if (filePath === null) {
11124
+ console.error(colors.red("File \"".concat(filePathRaw, "\" does not exist")));
11125
+ return [2 /*return*/, process.exit(1)];
11126
+ }
11127
+ try {
11128
+ llm = $provideLlmToolsForCli(prepareAndScrapeOptions);
11129
+ }
11130
+ catch (error) {
11131
+ if (!(error instanceof Error)) {
11132
+ throw error;
11133
+ }
11134
+ if (!error.message.includes('No LLM tools')) {
11135
+ throw error;
11136
+ }
11137
+ console.error(colors.red(spaceTrim$1("\n You need to configure LLM tools first\n\n 1) Create .env file\n 2) Add OPENAI_API_KEY=...\n 3) *(and/or)* Add ANTHROPIC_CLAUDE_API_KEY=...\n ")));
11138
+ return [2 /*return*/, process.exit(1)];
11139
+ }
11140
+ return [4 /*yield*/, $provideExecutablesForNode(prepareAndScrapeOptions)];
11141
+ case 9:
11142
+ executables = _m.sent();
11143
+ _h = {
11144
+ llm: llm,
11145
+ fs: fs
11146
+ };
11147
+ return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables }, prepareAndScrapeOptions)];
11148
+ case 10:
11149
+ tools = (_h.scrapers = _m.sent(),
11150
+ _h.script = [
11151
+ /*new JavascriptExecutionTools(options)*/
11152
+ ],
11153
+ _h);
11154
+ if (isVerbose) {
11155
+ console.info(colors.gray('--- Reading file ---'));
11156
+ }
11157
+ return [4 /*yield*/, readFile(filePath, 'utf-8')];
11158
+ case 11:
11159
+ pipelineString = (_m.sent());
11160
+ if (isVerbose) {
11161
+ console.info(colors.gray('--- Preparing pipeline ---'));
11162
+ }
11163
+ _m.label = 12;
11164
+ case 12:
11165
+ _m.trys.push([12, 14, , 15]);
11166
+ return [4 /*yield*/, pipelineStringToJson(pipelineString, tools)];
11167
+ case 13:
11168
+ pipeline = _m.sent();
11169
+ return [3 /*break*/, 15];
11170
+ case 14:
11171
+ error_1 = _m.sent();
11172
+ if (!(error_1 instanceof ParseError)) {
11173
+ throw error_1;
11174
+ }
11175
+ console.error(colors.red(spaceTrim$1(function (block) { return "\n ".concat(block(error_1.message), "\n\n in ").concat(filePath, "\n "); })));
11176
+ return [2 /*return*/, process.exit(1)];
11177
+ case 15:
11178
+ if (isVerbose) {
11179
+ console.info(colors.gray('--- Validating pipeline ---'));
11180
+ }
11181
+ // TODO: !!!!!! Same try-catch for LogicError
11182
+ validatePipeline(pipeline);
11183
+ if (isVerbose) {
11184
+ console.info(colors.gray('--- Creating executor ---'));
11185
+ }
11186
+ pipelineExecutor = createPipelineExecutor({
11187
+ pipeline: pipeline,
11188
+ tools: tools,
11189
+ isNotPreparedWarningSupressed: true,
11190
+ maxExecutionAttempts: 3,
11191
+ // <- TODO: !!!!!! Why "LLM execution failed undefinedx"
11192
+ maxParallelCount: 1, // <- TODO: !!!!!! Pass
11193
+ });
11194
+ if (isVerbose) {
11195
+ console.info(colors.gray('--- Getting input parameters ---'));
11196
+ }
11197
+ questions = pipeline.parameters
11198
+ .filter(function (_a) {
11199
+ var isInput = _a.isInput;
11200
+ return isInput;
11201
+ })
11202
+ .map(function (_a) {
11203
+ var name = _a.name, exampleValues = _a.exampleValues;
11204
+ var message = name;
11205
+ var initial = '';
11206
+ if (exampleValues && exampleValues.length > 0) {
11207
+ var exampleValuesFiltered = exampleValues.filter(function (exampleValue) { return countLines(exampleValue) <= 1 && countCharacters(exampleValue) <= 30; });
11208
+ if (exampleValuesFiltered.length !== 0) {
11209
+ message += " (e.g. ".concat(exampleValuesFiltered.join(', '), ")");
11210
+ }
11211
+ initial = exampleValues[0] || '';
11212
+ }
11213
+ return {
11214
+ type: 'text',
11215
+ name: name,
11216
+ message: message,
11217
+ initial: initial,
11218
+ // TODO: Maybe use> validate: value => value < 18 ? `Forbidden` : true
11219
+ };
11220
+ });
11221
+ return [4 /*yield*/, prompts(questions)];
11222
+ case 16:
11223
+ response = _m.sent();
11224
+ inputParameters = response;
11225
+ if (isVerbose) {
11226
+ console.info(colors.gray('--- Executing ---'));
11227
+ }
11228
+ return [4 /*yield*/, pipelineExecutor(inputParameters, function (taskProgress) {
11229
+ if (isVerbose) {
11230
+ console.info(colors.gray('--- Progress ---'));
11231
+ console.info(taskProgress);
11232
+ }
11233
+ })];
11234
+ case 17:
11235
+ result = _m.sent();
11236
+ isSuccessful = result.isSuccessful, errors = result.errors, warnings = result.warnings, outputParameters = result.outputParameters, executionReport = result.executionReport;
11237
+ if (isVerbose) {
11238
+ console.info(colors.gray('--- Detailed Result ---'));
11239
+ console.info({ isSuccessful: isSuccessful, errors: errors, warnings: warnings, outputParameters: outputParameters, executionReport: executionReport });
11240
+ }
11241
+ if (!(saveReport && saveReport.endsWith('.json'))) return [3 /*break*/, 19];
11242
+ return [4 /*yield*/, writeFile(saveReport, JSON.stringify(executionReport, null, 4) + '\n', 'utf-8')];
11243
+ case 18:
11244
+ _m.sent();
11245
+ return [3 /*break*/, 21];
11246
+ case 19:
11247
+ if (!(saveReport && saveReport.endsWith('.md'))) return [3 /*break*/, 21];
11248
+ executionReportString = executionReportJsonToString(executionReport);
11249
+ return [4 /*yield*/, writeFile(saveReport, executionReportString, 'utf-8')];
11250
+ case 20:
11251
+ _m.sent();
11252
+ _m.label = 21;
11253
+ case 21:
11254
+ if (saveReport && isVerbose) {
11255
+ console.info(colors.green("Report saved to ".concat(saveReport)));
11256
+ }
11257
+ if (isVerbose) {
11258
+ console.info(colors.gray('--- Usage ---'));
11259
+ console.info(colors.cyan(usageToHuman(result.usage)));
11260
+ }
11261
+ console.info(colors.gray('--- Result ---'));
11262
+ try {
11263
+ // TODO: [🧠] Should be errors or warnings shown first
11264
+ for (_a = __values(errors || []), _b = _a.next(); !_b.done; _b = _a.next()) {
11265
+ error = _b.value;
11266
+ console.error(colors.red(colors.bold(error.name) + ': ' + error.message));
11267
+ }
11268
+ }
11269
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
11270
+ finally {
11271
+ try {
11272
+ if (_b && !_b.done && (_j = _a.return)) _j.call(_a);
11273
+ }
11274
+ finally { if (e_2) throw e_2.error; }
11275
+ }
11276
+ try {
11277
+ for (_c = __values(warnings || []), _d = _c.next(); !_d.done; _d = _c.next()) {
11278
+ warning = _d.value;
11279
+ console.error(colors.red(colors.bold(warning.name) + ': ' + warning.message));
11280
+ }
11281
+ }
11282
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
11283
+ finally {
11284
+ try {
11285
+ if (_d && !_d.done && (_k = _c.return)) _k.call(_c);
11286
+ }
11287
+ finally { if (e_3) throw e_3.error; }
11288
+ }
11289
+ try {
11290
+ for (_e = __values(Object.keys(outputParameters)), _f = _e.next(); !_f.done; _f = _e.next()) {
11291
+ key = _f.value;
11292
+ value = outputParameters[key] || colors.grey(colors.italic('(nothing)'));
11293
+ separator = countLines(value) > 1 || countWords(value) > 100 ? ':\n' : ': ';
11294
+ console.info(colors.green(colors.bold(key) + separator + value));
11295
+ }
11296
+ }
11297
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
11298
+ finally {
11299
+ try {
11300
+ if (_f && !_f.done && (_l = _e.return)) _l.call(_e);
11301
+ }
11302
+ finally { if (e_4) throw e_4.error; }
11303
+ }
11304
+ return [2 /*return*/, process.exit(0)];
11305
+ }
11306
+ });
11307
+ }); });
11308
+ }
11309
+ /**
11310
+ * TODO: !!!!!! Catch and wrap all errors from CLI
11311
+ * TODO: [🧠] Pass `maxExecutionAttempts`, `csvSettings`
11312
+ * TODO: [🥃][main] !!! Allow `ptbk run` without configuring any llm tools
11313
+ * Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
11314
+ * TODO: [🖇] What about symlinks? Maybe flag --follow-symlinks
11315
+ */
11316
+
10736
11317
  /**
10737
11318
  * Initializes `test` command for Promptbook CLI utilities
10738
11319
  *
@@ -10746,30 +11327,30 @@ function initializeTestCommand(program) {
10746
11327
  // <- TODO: [🧟‍♂️] Unite path to promptbook collection argument
10747
11328
  'Pipelines to test as glob pattern');
10748
11329
  testCommand.option('-i, --ignore <glob>', "Ignore as glob pattern");
10749
- testCommand.option('--reload', "Call LLM models even if same prompt with result is in the cache ", false);
11330
+ testCommand.option('-r, --reload', "Call LLM models even if same prompt with result is in the cache ", false);
10750
11331
  testCommand.option('-v, --verbose', "Is output verbose", false);
10751
11332
  testCommand.action(function (filesGlob, _a) {
10752
- var ignore = _a.ignore, isCacheReloaded = _a.reloadCache, isVerbose = _a.verbose;
11333
+ var ignore = _a.ignore, isCacheReloaded = _a.reload, isVerbose = _a.verbose;
10753
11334
  return __awaiter(_this, void 0, void 0, function () {
10754
- var options, fs, llm, executables, tools, filenames, filenames_1, filenames_1_1, filename, pipeline, pipelineMarkdown, _b, _c, error_1, e_1_1;
11335
+ var prepareAndScrapeOptions, fs, llm, executables, tools, filenames, filenames_1, filenames_1_1, filename, pipeline, pipelineMarkdown, _b, _c, error_1, e_1_1;
10755
11336
  var _d, e_1, _e;
10756
11337
  return __generator(this, function (_f) {
10757
11338
  switch (_f.label) {
10758
11339
  case 0:
10759
- options = {
11340
+ prepareAndScrapeOptions = {
10760
11341
  isVerbose: isVerbose,
10761
11342
  isCacheReloaded: isCacheReloaded,
10762
11343
  };
10763
- fs = $provideFilesystemForNode(options);
10764
- llm = $provideLlmToolsForCli(options);
10765
- return [4 /*yield*/, $provideExecutablesForNode(options)];
11344
+ fs = $provideFilesystemForNode(prepareAndScrapeOptions);
11345
+ llm = $provideLlmToolsForCli(prepareAndScrapeOptions);
11346
+ return [4 /*yield*/, $provideExecutablesForNode(prepareAndScrapeOptions)];
10766
11347
  case 1:
10767
11348
  executables = _f.sent();
10768
11349
  _d = {
10769
11350
  llm: llm,
10770
11351
  fs: fs
10771
11352
  };
10772
- return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables }, options)];
11353
+ return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables }, prepareAndScrapeOptions)];
10773
11354
  case 2:
10774
11355
  tools = (_d.scrapers = _f.sent(),
10775
11356
  _d.script = [
@@ -10826,8 +11407,7 @@ function initializeTestCommand(program) {
10826
11407
  console.info(colors.red("Pipeline is not valid ".concat(filename)));
10827
11408
  console.error(colors.bgRed(error_1.name /* <- 11:11 */));
10828
11409
  console.error(colors.red(error_1.stack || error_1.message));
10829
- process.exit(1);
10830
- return [3 /*break*/, 14];
11410
+ return [2 /*return*/, process.exit(1)];
10831
11411
  case 14:
10832
11412
  filenames_1_1 = filenames_1.next();
10833
11413
  return [3 /*break*/, 5];
@@ -10844,8 +11424,7 @@ function initializeTestCommand(program) {
10844
11424
  return [7 /*endfinally*/];
10845
11425
  case 18:
10846
11426
  console.info(colors.green("All pipelines are valid"));
10847
- process.exit(0);
10848
- return [2 /*return*/];
11427
+ return [2 /*return*/, process.exit(0)];
10849
11428
  }
10850
11429
  });
10851
11430
  });
@@ -10865,17 +11444,23 @@ function initializeTestCommand(program) {
10865
11444
  */
10866
11445
  function promptbookCli() {
10867
11446
  return __awaiter(this, void 0, void 0, function () {
10868
- var program;
11447
+ var isVerbose, program;
10869
11448
  return __generator(this, function (_a) {
10870
11449
  if (!$isRunningInNode()) {
10871
11450
  throw new EnvironmentMismatchError(spaceTrim("\n Function promptbookCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use function exported from `@promptbook/utils` or `@promptbook/core` directly, for example `prettifyPipelineString`.\n\n "));
10872
11451
  }
11452
+ isVerbose = process.argv.some(function (arg) { return arg === '--verbose' || arg === '-v'; });
11453
+ // <- TODO: Can be this be done with commander before the commander commands are initialized?
11454
+ if (isVerbose) {
11455
+ console.info(colors.gray("Promptbook CLI version ".concat(PROMPTBOOK_ENGINE_VERSION, " in ").concat(__filename.split('\\').join('/'))));
11456
+ }
10873
11457
  program = new commander.Command();
10874
11458
  program.name('promptbook');
10875
11459
  program.alias('ptbk');
10876
- program.version(PROMPTBOOK_VERSION);
10877
- program.description(spaceTrim("\n Promptbook utilities for enhancing workflow with promptbooks\n "));
11460
+ program.version(PROMPTBOOK_ENGINE_VERSION);
11461
+ program.description(CLAIM);
10878
11462
  initializeAboutCommand(program);
11463
+ initializeRunCommand(program);
10879
11464
  initializeHelloCommand(program);
10880
11465
  initializeMakeCommand(program);
10881
11466
  initializePrettifyCommand(program);
@@ -10886,6 +11471,7 @@ function promptbookCli() {
10886
11471
  });
10887
11472
  }
10888
11473
  /**
11474
+ * TODO: [🧠] Maybe `run` command the default, instead of `ptbk run ./foo.ptbk.md` -> `ptbk ./foo.ptbk.md`
10889
11475
  * TODO: [🥠] Do not export, its just for CLI script
10890
11476
  * TODO: [🕌] When more functionalities, rename
10891
11477
  * Note: 11:11
@@ -12475,8 +13061,6 @@ var _OpenAiAssistantMetadataRegistration = $llmToolsMetadataRegister.register({
12475
13061
  };
12476
13062
  },
12477
13063
  createConfigurationFromEnv: function (env) {
12478
- // TODO: Maybe auto-configure (multiple) assistants from env variables
12479
- keepUnused(env);
12480
13064
  return null;
12481
13065
  /*
12482
13066
  if (typeof env.OPENAI_API_KEY === 'string' || typeof env.OPENAI_XXX === 'string') {
@@ -13203,12 +13787,9 @@ function $execCommandNormalizeOptions(options) {
13203
13787
  })
13204
13788
  .filter(function (arg) { return arg !== ''; });
13205
13789
  if (_.length > 1) {
13206
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
13207
13790
  _a = __read(_), command = _a[0], args = _a.slice(1);
13208
13791
  }
13209
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
13210
13792
  if (options.args) {
13211
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
13212
13793
  args = __spreadArray(__spreadArray([], __read(args), false), __read(options.args), false);
13213
13794
  }
13214
13795
  var humanReadableCommand = !['npx', 'npm'].includes(command) ? command : args[0];
@@ -13329,12 +13910,12 @@ function $execCommand(options) {
13329
13910
  */
13330
13911
  function getScraperIntermediateSource(source, options) {
13331
13912
  return __awaiter(this, void 0, void 0, function () {
13332
- var sourceFilename, url, rootDirname, cacheDirname, intermediateFilesStrategy, extension, isVerbose, hash, semanticName, pieces, name, cacheFilename, isDestroyed, fileHandler;
13913
+ var sourceFilename, url, cacheDirname, intermediateFilesStrategy, extension, isVerbose, hash, semanticName, pieces, name, cacheFilename, isDestroyed, fileHandler;
13333
13914
  return __generator(this, function (_a) {
13334
13915
  switch (_a.label) {
13335
13916
  case 0:
13336
13917
  sourceFilename = source.filename, url = source.url;
13337
- rootDirname = options.rootDirname, cacheDirname = options.cacheDirname, intermediateFilesStrategy = options.intermediateFilesStrategy, extension = options.extension, isVerbose = options.isVerbose;
13918
+ options.rootDirname, cacheDirname = options.cacheDirname, intermediateFilesStrategy = options.intermediateFilesStrategy, extension = options.extension, isVerbose = options.isVerbose;
13338
13919
  hash = SHA256(
13339
13920
  // <- TODO: [🥬] Encapsulate sha256 to some private utility function
13340
13921
  hexEncoder.parse(sourceFilename || url || 'untitled'))
@@ -13343,8 +13924,6 @@ function getScraperIntermediateSource(source, options) {
13343
13924
  semanticName = normalizeToKebabCase(titleToName((sourceFilename || url || '').split('intermediate').join(''))).substring(0, 20);
13344
13925
  pieces = ['intermediate', semanticName, hash].filter(function (piece) { return piece !== ''; });
13345
13926
  name = pieces.join('-').split('--').join('-');
13346
- // <- TODO: Use MAX_FILENAME_LENGTH
13347
- TODO_USE(rootDirname); // <- TODO: [😡]
13348
13927
  cacheFilename = join.apply(void 0, __spreadArray(__spreadArray([process.cwd(),
13349
13928
  cacheDirname], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), [name], false)).split('\\')
13350
13929
  .join('/') +
@@ -13443,13 +14022,13 @@ var MarkdownScraper = /** @class */ (function () {
13443
14022
  */
13444
14023
  MarkdownScraper.prototype.scrape = function (source) {
13445
14024
  return __awaiter(this, void 0, void 0, function () {
13446
- var _a, _b, maxParallelCount, _c, isVerbose, llm, _llms, llmTools, collection, prepareKnowledgeFromMarkdownExecutor, _d, prepareTitleExecutor, _e, prepareKeywordsExecutor, _f, knowledgeContent, result, outputParameters, knowledgePiecesRaw, knowledgeTextPieces, knowledge;
14025
+ var _a, _c, isVerbose, llm, _llms, llmTools, collection, prepareKnowledgeFromMarkdownExecutor, _d, prepareTitleExecutor, _e, prepareKeywordsExecutor, _f, knowledgeContent, result, outputParameters, knowledgePiecesRaw, knowledgeTextPieces, knowledge;
13447
14026
  var _g, _h, _j;
13448
14027
  var _this = this;
13449
14028
  return __generator(this, function (_k) {
13450
14029
  switch (_k.label) {
13451
14030
  case 0:
13452
- _a = this.options, _b = _a.maxParallelCount, maxParallelCount = _b === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? DEFAULT_IS_VERBOSE : _c;
14031
+ _a = this.options, _a.maxParallelCount, _c = _a.isVerbose, isVerbose = _c === void 0 ? DEFAULT_IS_VERBOSE : _c;
13453
14032
  llm = this.tools.llm;
13454
14033
  if (llm === undefined) {
13455
14034
  throw new MissingToolsError('LLM tools are required for scraping external files');
@@ -13457,7 +14036,6 @@ var MarkdownScraper = /** @class */ (function () {
13457
14036
  }
13458
14037
  _llms = arrayableToArray(llm);
13459
14038
  llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(_llms), false));
13460
- TODO_USE(maxParallelCount); // <- [🪂]
13461
14039
  collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
13462
14040
  _d = createPipelineExecutor;
13463
14041
  _g = {};
@@ -14048,7 +14626,6 @@ var PdfScraper = /** @class */ (function () {
14048
14626
  PdfScraper.prototype.$convert = function (source) {
14049
14627
  return __awaiter(this, void 0, void 0, function () {
14050
14628
  return __generator(this, function (_a) {
14051
- TODO_USE(source);
14052
14629
  TODO_USE(this.options);
14053
14630
  throw new NotYetImplementedError('PDF conversion not yet implemented');
14054
14631
  });
@@ -14060,7 +14637,6 @@ var PdfScraper = /** @class */ (function () {
14060
14637
  PdfScraper.prototype.scrape = function (source) {
14061
14638
  return __awaiter(this, void 0, void 0, function () {
14062
14639
  return __generator(this, function (_a) {
14063
- TODO_USE(source);
14064
14640
  TODO_USE(this.options);
14065
14641
  /*
14066
14642
  const {
@@ -14303,5 +14879,5 @@ var _WebsiteScraperRegistration = $scrapersRegister.register(createWebsiteScrape
14303
14879
  * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
14304
14880
  */
14305
14881
 
14306
- export { PROMPTBOOK_VERSION, _AnthropicClaudeMetadataRegistration, _AnthropicClaudeRegistration, _AzureOpenAiMetadataRegistration, _AzureOpenAiRegistration, _CLI, _DocumentScraperMetadataRegistration, _DocumentScraperRegistration, _LegacyDocumentScraperMetadataRegistration, _LegacyDocumentScraperRegistration, _MarkdownScraperMetadataRegistration, _MarkdownScraperRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiAssistantRegistration, _OpenAiMetadataRegistration, _OpenAiRegistration, _PdfScraperMetadataRegistration, _PdfScraperRegistration, _WebsiteScraperMetadataRegistration, _WebsiteScraperRegistration };
14882
+ export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION, _AnthropicClaudeMetadataRegistration, _AnthropicClaudeRegistration, _AzureOpenAiMetadataRegistration, _AzureOpenAiRegistration, _CLI, _DocumentScraperMetadataRegistration, _DocumentScraperRegistration, _LegacyDocumentScraperMetadataRegistration, _LegacyDocumentScraperRegistration, _MarkdownScraperMetadataRegistration, _MarkdownScraperRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiAssistantRegistration, _OpenAiMetadataRegistration, _OpenAiRegistration, _PdfScraperMetadataRegistration, _PdfScraperRegistration, _WebsiteScraperMetadataRegistration, _WebsiteScraperRegistration };
14307
14883
  //# sourceMappingURL=index.es.js.map