@promptbook/core 0.23.2 → 0.24.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/esm/index.es.js +292 -35
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/_packages/types.index.d.ts +2 -2
  4. package/esm/typings/_packages/utils.index.d.ts +11 -1
  5. package/esm/typings/conversion/parseCommand.d.ts +2 -2
  6. package/esm/typings/execution/PromptResult.d.ts +1 -1
  7. package/esm/typings/types/Command.d.ts +17 -4
  8. package/esm/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +21 -2
  9. package/esm/typings/types/execution-report/ExecutionReportJson.d.ts +19 -0
  10. package/esm/typings/types/execution-report/ExecutionReportString.d.ts +16 -0
  11. package/esm/typings/types/execution-report/executionReportJsonToString.d.ts +6 -0
  12. package/esm/typings/types/typeAliases.d.ts +3 -1
  13. package/esm/typings/utils/expectation-counters/countCharacters.d.ts +5 -0
  14. package/esm/typings/utils/expectation-counters/countCharacters.test.d.ts +1 -0
  15. package/esm/typings/utils/expectation-counters/countLines.d.ts +5 -0
  16. package/esm/typings/utils/expectation-counters/countLines.test.d.ts +1 -0
  17. package/esm/typings/utils/expectation-counters/countPages.d.ts +5 -0
  18. package/esm/typings/utils/expectation-counters/countPages.test.d.ts +1 -0
  19. package/esm/typings/utils/expectation-counters/countParagraphs.d.ts +5 -0
  20. package/esm/typings/utils/expectation-counters/countParagraphs.test.d.ts +1 -0
  21. package/esm/typings/utils/expectation-counters/countSentences.d.ts +5 -0
  22. package/esm/typings/utils/expectation-counters/countSentences.test.d.ts +1 -0
  23. package/esm/typings/utils/expectation-counters/countWords.d.ts +5 -0
  24. package/esm/typings/utils/expectation-counters/countWords.test.d.ts +1 -0
  25. package/esm/typings/utils/expectation-counters/index.d.ts +5 -0
  26. package/esm/typings/utils/parseNumber.d.ts +10 -0
  27. package/esm/typings/utils/parseNumber.test.d.ts +1 -0
  28. package/esm/typings/utils/trimCodeBlock.d.ts +8 -0
  29. package/esm/typings/utils/trimCodeBlock.test.d.ts +1 -0
  30. package/esm/typings/utils/trimEndOfCodeBlock.d.ts +2 -1
  31. package/package.json +1 -1
  32. package/umd/index.umd.js +291 -34
  33. package/umd/index.umd.js.map +1 -1
  34. package/umd/typings/_packages/types.index.d.ts +2 -2
  35. package/umd/typings/_packages/utils.index.d.ts +11 -1
  36. package/umd/typings/conversion/parseCommand.d.ts +2 -2
  37. package/umd/typings/execution/PromptResult.d.ts +1 -1
  38. package/umd/typings/types/Command.d.ts +17 -4
  39. package/umd/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +21 -2
  40. package/umd/typings/types/execution-report/ExecutionReportJson.d.ts +19 -0
  41. package/umd/typings/types/execution-report/ExecutionReportString.d.ts +16 -0
  42. package/umd/typings/types/execution-report/executionReportJsonToString.d.ts +6 -0
  43. package/umd/typings/types/typeAliases.d.ts +3 -1
  44. package/umd/typings/utils/expectation-counters/countCharacters.d.ts +5 -0
  45. package/umd/typings/utils/expectation-counters/countCharacters.test.d.ts +1 -0
  46. package/umd/typings/utils/expectation-counters/countLines.d.ts +5 -0
  47. package/umd/typings/utils/expectation-counters/countLines.test.d.ts +1 -0
  48. package/umd/typings/utils/expectation-counters/countPages.d.ts +5 -0
  49. package/umd/typings/utils/expectation-counters/countPages.test.d.ts +1 -0
  50. package/umd/typings/utils/expectation-counters/countParagraphs.d.ts +5 -0
  51. package/umd/typings/utils/expectation-counters/countParagraphs.test.d.ts +1 -0
  52. package/umd/typings/utils/expectation-counters/countSentences.d.ts +5 -0
  53. package/umd/typings/utils/expectation-counters/countSentences.test.d.ts +1 -0
  54. package/umd/typings/utils/expectation-counters/countWords.d.ts +5 -0
  55. package/umd/typings/utils/expectation-counters/countWords.test.d.ts +1 -0
  56. package/umd/typings/utils/expectation-counters/index.d.ts +5 -0
  57. package/umd/typings/utils/parseNumber.d.ts +10 -0
  58. package/umd/typings/utils/parseNumber.test.d.ts +1 -0
  59. package/umd/typings/utils/trimCodeBlock.d.ts +8 -0
  60. package/umd/typings/utils/trimCodeBlock.test.d.ts +1 -0
  61. package/umd/typings/utils/trimEndOfCodeBlock.d.ts +2 -1
package/esm/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { capitalize, normalizeTo_SCREAMING_CASE, normalizeTo_PascalCase, normalizeTo_camelCase } from 'n12';
1
+ import { capitalize, normalizeTo_SCREAMING_CASE, normalizeTo_PascalCase, normalizeTo_camelCase, removeDiacritics } from 'n12';
2
2
  import spaceTrim from 'spacetrim';
3
3
 
4
4
  /*! *****************************************************************************
@@ -342,6 +342,14 @@ function removeContentComments(content) {
342
342
  */
343
343
  var ExecutionTypes = ['PROMPT_TEMPLATE', 'SIMPLE_TEMPLATE', 'SCRIPT', 'PROMPT_DIALOG'];
344
344
 
345
+ /**
346
+ * Units of text measurement
347
+ */
348
+ var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'PARAGRAPHS', 'LINES', 'PAGES'];
349
+ /**
350
+ * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
351
+ */
352
+
345
353
  /**
346
354
  * Removes Markdown formatting tags from a string.
347
355
  *
@@ -358,10 +366,73 @@ function removeMarkdownFormatting(str) {
358
366
  return str;
359
367
  }
360
368
 
369
+ /**
370
+ * Function parseNumber will parse number from string
371
+ *
372
+ * Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
373
+ * Note: it also works only with decimal numbers
374
+ */
375
+ function parseNumber(value) {
376
+ var originalValue = value;
377
+ if (typeof value === 'number') {
378
+ value = value.toString(); // <- TODO: Maybe more efficient way to do this
379
+ }
380
+ if (typeof value !== 'string') {
381
+ return 0;
382
+ }
383
+ value = value.trim();
384
+ if (value.startsWith('+')) {
385
+ return parseNumber(value.substring(1));
386
+ }
387
+ if (value.startsWith('-')) {
388
+ var number = parseNumber(value.substring(1));
389
+ if (number === 0) {
390
+ return 0; // <- Note: To prevent -0
391
+ }
392
+ return -number;
393
+ }
394
+ value = value.replace(/,/g, '.');
395
+ value = value.toUpperCase();
396
+ if (value === '') {
397
+ return 0;
398
+ }
399
+ if (value === '♾' || value.startsWith('INF')) {
400
+ return Infinity;
401
+ }
402
+ if (value.includes('/')) {
403
+ var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
404
+ var numerator = parseNumber(numerator_);
405
+ var denominator = parseNumber(denominator_);
406
+ if (denominator === 0) {
407
+ throw new Error("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
408
+ }
409
+ return numerator / denominator;
410
+ }
411
+ if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
412
+ return 0;
413
+ }
414
+ if (value.includes('E')) {
415
+ var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
416
+ return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
417
+ }
418
+ if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
419
+ throw new Error("Unable to parse number from \"".concat(originalValue, "\""));
420
+ }
421
+ var num = parseFloat(value);
422
+ if (isNaN(num)) {
423
+ throw new Error("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
424
+ }
425
+ return num;
426
+ }
427
+ /**
428
+ * TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
429
+ */
430
+
361
431
  /**
362
432
  * Parses one line of ul/ol to command
363
433
  */
364
434
  function parseCommand(listItem) {
435
+ var e_1, _a;
365
436
  if (listItem.includes('\n') || listItem.includes('\r')) {
366
437
  throw new Error('Command can not contain new line characters:');
367
438
  }
@@ -468,7 +539,7 @@ function parseCommand(listItem) {
468
539
  throw new Error(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
469
540
  }
470
541
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
471
- var _a = parametersMatch.groups, parameterName = _a.parameterName, parameterDescription = _a.parameterDescription;
542
+ var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
472
543
  if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
473
544
  throw new Error(spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
474
545
  }
@@ -490,6 +561,74 @@ function parseCommand(listItem) {
490
561
  functionName: functionName,
491
562
  };
492
563
  }
564
+ else if (type.startsWith('EXPECT')) {
565
+ try {
566
+ listItemParts.shift();
567
+ var sign = void 0;
568
+ var signRaw = listItemParts.shift();
569
+ if (/^exact/i.test(signRaw)) {
570
+ sign = 'EXACTLY';
571
+ }
572
+ else if (/^min/i.test(signRaw)) {
573
+ sign = 'MINIMUM';
574
+ }
575
+ else if (/^max/i.test(signRaw)) {
576
+ sign = 'MAXIMUM';
577
+ }
578
+ else {
579
+ throw new Error("Invalid sign \"".concat(signRaw, "\""));
580
+ }
581
+ var amountRaw = listItemParts.shift();
582
+ var amount = parseNumber(amountRaw);
583
+ if (amount < 0) {
584
+ throw new Error('Amount must be positive number or zero');
585
+ }
586
+ if (amount !== Math.floor(amount)) {
587
+ throw new Error('Amount must be whole number');
588
+ }
589
+ var unitRaw = listItemParts.shift();
590
+ var unit = undefined;
591
+ try {
592
+ for (var EXPECTATION_UNITS_1 = __values(EXPECTATION_UNITS), EXPECTATION_UNITS_1_1 = EXPECTATION_UNITS_1.next(); !EXPECTATION_UNITS_1_1.done; EXPECTATION_UNITS_1_1 = EXPECTATION_UNITS_1.next()) {
593
+ var existingUnit = EXPECTATION_UNITS_1_1.value;
594
+ var existingUnitText = existingUnit;
595
+ existingUnitText = existingUnitText.substring(0, existingUnitText.length - 1);
596
+ if (existingUnitText === 'CHARACTER') {
597
+ existingUnitText = 'CHAR';
598
+ }
599
+ if (new RegExp("^".concat(existingUnitText.toLowerCase())).test(unitRaw.toLowerCase()) ||
600
+ new RegExp("^".concat(unitRaw.toLowerCase())).test(existingUnitText.toLowerCase())) {
601
+ if (unit !== undefined) {
602
+ throw new Error("Ambiguous unit \"".concat(unitRaw, "\""));
603
+ }
604
+ unit = existingUnit;
605
+ }
606
+ }
607
+ }
608
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
609
+ finally {
610
+ try {
611
+ if (EXPECTATION_UNITS_1_1 && !EXPECTATION_UNITS_1_1.done && (_a = EXPECTATION_UNITS_1.return)) _a.call(EXPECTATION_UNITS_1);
612
+ }
613
+ finally { if (e_1) throw e_1.error; }
614
+ }
615
+ if (unit === undefined) {
616
+ throw new Error("Invalid unit \"".concat(unitRaw, "\""));
617
+ }
618
+ return {
619
+ type: 'EXPECT',
620
+ sign: sign,
621
+ unit: unit,
622
+ amount: amount,
623
+ };
624
+ }
625
+ catch (error) {
626
+ if (!(error instanceof Error)) {
627
+ throw error;
628
+ }
629
+ throw new Error(spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
630
+ }
631
+ }
493
632
  else {
494
633
  throw new Error(spaceTrim("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - Execute\n - Model\n - Parameter\n - Input parameter\n - Output parameter\n - PTBK Version\n ")));
495
634
  }
@@ -598,6 +737,7 @@ function promptTemplatePipelineStringToJson(promptTemplatePipelineString) {
598
737
  var postprocessingCommands = [];
599
738
  var listItems_3 = extractAllListItemsFromMarkdown(section.content);
600
739
  var executionType = 'PROMPT_TEMPLATE';
740
+ var expectations = {};
601
741
  var isExecutionTypeChanged = false;
602
742
  try {
603
743
  for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
@@ -621,6 +761,23 @@ function promptTemplatePipelineStringToJson(promptTemplatePipelineString) {
621
761
  case 'POSTPROCESS':
622
762
  postprocessingCommands.push(command);
623
763
  break;
764
+ case 'EXPECT':
765
+ // eslint-disable-next-line no-case-declarations
766
+ var unit = command.unit.toLowerCase();
767
+ expectations[unit] = expectations[unit] || {};
768
+ if (command.sign === 'MINIMUM' || command.sign === 'EXACTLY') {
769
+ if (expectations[unit].min !== undefined) {
770
+ throw new Error("Already defined minumum ".concat(expectations[unit].min, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
771
+ }
772
+ expectations[unit].min = command.amount;
773
+ } /* not else */
774
+ if (command.sign === 'MAXIMUM' || command.sign === 'EXACTLY') {
775
+ if (expectations[unit].max !== undefined) {
776
+ throw new Error("Already defined maximum ".concat(expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
777
+ }
778
+ expectations[unit].max = command.amount;
779
+ }
780
+ break;
624
781
  default:
625
782
  throw new Error("Command ".concat(command.type, " is not allowed in the block of the prompt template ONLY at the head of the prompt template pipeline"));
626
783
  }
@@ -684,6 +841,7 @@ function promptTemplatePipelineStringToJson(promptTemplatePipelineString) {
684
841
  title: section.title,
685
842
  description: description_1,
686
843
  executionType: executionType,
844
+ expectations: expectations,
687
845
  modelRequirements: templateModelRequirements,
688
846
  contentLanguage: executionType === 'SCRIPT' ? language : undefined,
689
847
  content: content,
@@ -920,6 +1078,74 @@ var PromptTemplatePipeline = /** @class */ (function () {
920
1078
  * TODO: [🧠] Each PromptTemplatePipeline should have its unique hash to be able to compare them and execute on server ONLY the desired ones
921
1079
  */
922
1080
 
1081
+ /**
1082
+ * Counts number of characters in the text
1083
+ */
1084
+ function countCharacters(text) {
1085
+ // Remove null characters
1086
+ text = text.replace(/\0/g, '');
1087
+ // Replace emojis (and also ZWJ sequence) with hyphens
1088
+ text = text.replace(/(\p{Emoji})\p{Modifier_Symbol}/gu, '$1');
1089
+ text = text.replace(/(\p{Emoji})[\u{FE00}-\u{FE0F}]/gu, '$1');
1090
+ text = text.replace(/\p{Emoji}(\u{200D}\p{Emoji})*/gu, '-');
1091
+ return text.length;
1092
+ }
1093
+
1094
+ /**
1095
+ * Counts number of lines in the text
1096
+ */
1097
+ function countLines(text) {
1098
+ if (text === '') {
1099
+ return 0;
1100
+ }
1101
+ return text.split('\n').length;
1102
+ }
1103
+
1104
+ /**
1105
+ * Counts number of pages in the text
1106
+ */
1107
+ function countPages(text) {
1108
+ var sentencesPerPage = 5; // Assuming each page has 5 sentences
1109
+ var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
1110
+ var pageCount = Math.ceil(sentences.length / sentencesPerPage);
1111
+ return pageCount;
1112
+ }
1113
+
1114
+ /**
1115
+ * Counts number of paragraphs in the text
1116
+ */
1117
+ function countParagraphs(text) {
1118
+ return text.split(/\n\s*\n/).filter(function (paragraph) { return paragraph.trim() !== ''; }).length;
1119
+ }
1120
+
1121
+ /**
1122
+ * Counts number of sentences in the text
1123
+ */
1124
+ function countSentences(text) {
1125
+ return text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; }).length;
1126
+ }
1127
+
1128
+ /**
1129
+ * Counts number of words in the text
1130
+ */
1131
+ function countWords(text) {
1132
+ text = text.replace(/[\p{Emoji}]/gu, 'a');
1133
+ text = removeDiacritics(text);
1134
+ return text.split(/[^a-zа-я0-9]+/i).filter(function (word) { return word.length > 0; }).length;
1135
+ }
1136
+
1137
+ /**
1138
+ * Index of all counter functions
1139
+ */
1140
+ var CountUtils = {
1141
+ CHARACTERS: countCharacters,
1142
+ WORDS: countWords,
1143
+ SENTENCES: countSentences,
1144
+ PARAGRAPHS: countParagraphs,
1145
+ LINES: countLines,
1146
+ PAGES: countPages,
1147
+ };
1148
+
923
1149
  /**
924
1150
  * All possible emoji chars like "🍆", "🍡", "🍤"...
925
1151
  * Note: this will be needed to update annually - now updated at 2022-01-19
@@ -1045,17 +1271,18 @@ function createPtpExecutor(options) {
1045
1271
  var _this = this;
1046
1272
  var ptp = options.ptp, tools = options.tools;
1047
1273
  var ptpExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
1048
- var parametersToPass, currentTemplate, _loop_1;
1274
+ var parametersToPass, currentTemplate, executionReport, _loop_1;
1049
1275
  return __generator(this, function (_a) {
1050
1276
  switch (_a.label) {
1051
1277
  case 0:
1052
1278
  parametersToPass = inputParameters;
1053
1279
  currentTemplate = ptp.entryPromptTemplate;
1280
+ executionReport = [];
1054
1281
  _loop_1 = function () {
1055
- var resultingParameter, name_1, title, prompt_1, chatThread, completionResult, promptResult, scriptExecutionErrors, isScriptExecutionSuccessful, _b, _c, _d, _e, scriptTools, error_1, e_1_1;
1056
- var e_1, _f, _g;
1057
- return __generator(this, function (_h) {
1058
- switch (_h.label) {
1282
+ var resultingParameter, name_1, title, prompt_1, chatThread, completionResult, result, resultString, scriptExecutionErrors, isScriptExecutionSuccessful, _b, _c, _d, _e, _f, unit, _g, max, min, amount, _h, _j, scriptTools, error_1, e_1_1;
1283
+ var e_2, _k, e_1, _l, _m;
1284
+ return __generator(this, function (_o) {
1285
+ switch (_o.label) {
1059
1286
  case 0:
1060
1287
  resultingParameter = ptp.getResultingParameter(currentTemplate.name);
1061
1288
  name_1 = "ptp-executor-frame-".concat(currentTemplate.name);
@@ -1071,13 +1298,14 @@ function createPtpExecutor(options) {
1071
1298
  parameterValue: null,
1072
1299
  })];
1073
1300
  case 1:
1074
- _h.sent();
1075
- _h.label = 2;
1301
+ _o.sent();
1302
+ _o.label = 2;
1076
1303
  case 2:
1077
1304
  prompt_1 = void 0;
1078
1305
  chatThread = void 0;
1079
1306
  completionResult = void 0;
1080
- promptResult = null;
1307
+ result = void 0;
1308
+ resultString = null;
1081
1309
  isScriptExecutionSuccessful = void 0;
1082
1310
  _b = currentTemplate.executionType;
1083
1311
  switch (_b) {
@@ -1088,7 +1316,7 @@ function createPtpExecutor(options) {
1088
1316
  }
1089
1317
  return [3 /*break*/, 24];
1090
1318
  case 3:
1091
- promptResult = replaceParameters(currentTemplate.content, parametersToPass);
1319
+ resultString = replaceParameters(currentTemplate.content, parametersToPass);
1092
1320
  return [3 /*break*/, 25];
1093
1321
  case 4:
1094
1322
  prompt_1 = {
@@ -1107,19 +1335,48 @@ function createPtpExecutor(options) {
1107
1335
  return [3 /*break*/, 9];
1108
1336
  case 5: return [4 /*yield*/, tools.natural.gptChat(prompt_1)];
1109
1337
  case 6:
1110
- chatThread = _h.sent();
1111
- // TODO: Use all information from chatThread like "model"
1338
+ chatThread = _o.sent();
1112
1339
  // TODO: [🍬] Destroy chatThread
1113
- promptResult = chatThread.content;
1340
+ result = chatThread;
1341
+ resultString = chatThread.content;
1114
1342
  return [3 /*break*/, 10];
1115
1343
  case 7: return [4 /*yield*/, tools.natural.gptComplete(prompt_1)];
1116
1344
  case 8:
1117
- completionResult = _h.sent();
1118
- // TODO: Use all information from chatThread like "model"
1119
- promptResult = completionResult.content;
1345
+ completionResult = _o.sent();
1346
+ result = completionResult;
1347
+ resultString = completionResult.content;
1120
1348
  return [3 /*break*/, 10];
1121
1349
  case 9: throw new Error("Unknown model variant \"".concat(currentTemplate.modelRequirements.modelVariant, "\""));
1122
- case 10: return [3 /*break*/, 25];
1350
+ case 10:
1351
+ try {
1352
+ for (_d = (e_2 = void 0, __values(Object.entries(currentTemplate.expectations))), _e = _d.next(); !_e.done; _e = _d.next()) {
1353
+ _f = __read(_e.value, 2), unit = _f[0], _g = _f[1], max = _g.max, min = _g.min;
1354
+ amount = CountUtils[unit](resultString);
1355
+ // TODO: !!!!! Do not crash BUT retry some amount of times
1356
+ if (min && amount < min) {
1357
+ throw new Error("Expected at least ".concat(min, " ").concat(unit, " but got ").concat(amount));
1358
+ } /* not else */
1359
+ if (max && amount > max) {
1360
+ throw new Error("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
1361
+ }
1362
+ }
1363
+ }
1364
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1365
+ finally {
1366
+ try {
1367
+ if (_e && !_e.done && (_k = _d.return)) _k.call(_d);
1368
+ }
1369
+ finally { if (e_2) throw e_2.error; }
1370
+ }
1371
+ executionReport.push({
1372
+ prompt: {
1373
+ content: prompt_1.content,
1374
+ modelRequirements: prompt_1.modelRequirements,
1375
+ // <- Note: Do want to pass ONLY wanted information to the report
1376
+ },
1377
+ result: result,
1378
+ });
1379
+ return [3 /*break*/, 25];
1123
1380
  case 11:
1124
1381
  if (tools.script.length === 0) {
1125
1382
  throw new Error('No script execution tools are available');
@@ -1129,44 +1386,44 @@ function createPtpExecutor(options) {
1129
1386
  }
1130
1387
  scriptExecutionErrors = [];
1131
1388
  isScriptExecutionSuccessful = false;
1132
- _h.label = 12;
1389
+ _o.label = 12;
1133
1390
  case 12:
1134
- _h.trys.push([12, 19, 20, 21]);
1135
- _d = (e_1 = void 0, __values(tools.script)), _e = _d.next();
1136
- _h.label = 13;
1391
+ _o.trys.push([12, 19, 20, 21]);
1392
+ _h = (e_1 = void 0, __values(tools.script)), _j = _h.next();
1393
+ _o.label = 13;
1137
1394
  case 13:
1138
- if (!!_e.done) return [3 /*break*/, 18];
1139
- scriptTools = _e.value;
1140
- _h.label = 14;
1395
+ if (!!_j.done) return [3 /*break*/, 18];
1396
+ scriptTools = _j.value;
1397
+ _o.label = 14;
1141
1398
  case 14:
1142
- _h.trys.push([14, 16, , 17]);
1399
+ _o.trys.push([14, 16, , 17]);
1143
1400
  return [4 /*yield*/, scriptTools.execute({
1144
1401
  scriptLanguage: currentTemplate.contentLanguage,
1145
1402
  script: currentTemplate.content,
1146
1403
  parameters: parametersToPass,
1147
1404
  })];
1148
1405
  case 15:
1149
- promptResult = _h.sent();
1406
+ resultString = _o.sent();
1150
1407
  isScriptExecutionSuccessful = true;
1151
1408
  return [3 /*break*/, 18];
1152
1409
  case 16:
1153
- error_1 = _h.sent();
1410
+ error_1 = _o.sent();
1154
1411
  if (!(error_1 instanceof Error)) {
1155
1412
  throw error_1;
1156
1413
  }
1157
1414
  scriptExecutionErrors.push(error_1);
1158
1415
  return [3 /*break*/, 17];
1159
1416
  case 17:
1160
- _e = _d.next();
1417
+ _j = _h.next();
1161
1418
  return [3 /*break*/, 13];
1162
1419
  case 18: return [3 /*break*/, 21];
1163
1420
  case 19:
1164
- e_1_1 = _h.sent();
1421
+ e_1_1 = _o.sent();
1165
1422
  e_1 = { error: e_1_1 };
1166
1423
  return [3 /*break*/, 21];
1167
1424
  case 20:
1168
1425
  try {
1169
- if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
1426
+ if (_j && !_j.done && (_l = _h.return)) _l.call(_h);
1170
1427
  }
1171
1428
  finally { if (e_1) throw e_1.error; }
1172
1429
  return [7 /*endfinally*/];
@@ -1187,13 +1444,13 @@ function createPtpExecutor(options) {
1187
1444
  placeholder: undefined,
1188
1445
  })];
1189
1446
  case 23:
1190
- promptResult = _h.sent();
1447
+ resultString = _o.sent();
1191
1448
  return [3 /*break*/, 25];
1192
1449
  case 24:
1193
1450
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1194
1451
  throw new Error("Unknown execution type \"".concat(currentTemplate.executionType, "\""));
1195
1452
  case 25:
1196
- if (promptResult === null) {
1453
+ if (resultString === null) {
1197
1454
  // <- TODO: [🥨] Make some NeverShouldHappenError
1198
1455
  throw new Error('Something went wrong and prompt result is null');
1199
1456
  }
@@ -1205,10 +1462,10 @@ function createPtpExecutor(options) {
1205
1462
  isDone: true,
1206
1463
  executionType: currentTemplate.executionType,
1207
1464
  parameterName: resultingParameter.name,
1208
- parameterValue: promptResult,
1465
+ parameterValue: resultString,
1209
1466
  });
1210
1467
  }
1211
- parametersToPass = __assign(__assign({}, parametersToPass), (_g = {}, _g[resultingParameter.name] = promptResult /* <- Note: Not need to detect parameter collision here because PromptTemplatePipeline checks logic consistency during construction */, _g));
1468
+ parametersToPass = __assign(__assign({}, parametersToPass), (_m = {}, _m[resultingParameter.name] = resultString /* <- Note: Not need to detect parameter collision here because PromptTemplatePipeline checks logic consistency during construction */, _m));
1212
1469
  currentTemplate = ptp.getFollowingPromptTemplate(currentTemplate.name);
1213
1470
  return [2 /*return*/];
1214
1471
  }