@promptbook/core 0.44.0-3 → 0.44.0-5

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.
package/esm/index.es.js CHANGED
@@ -243,86 +243,22 @@ var PromptbookExecutionError = /** @class */ (function (_super) {
243
243
  }(Error));
244
244
 
245
245
  /**
246
- * The maximum number of iterations for a loops
247
- */
248
- var LOOP_LIMIT = 1000;
249
-
250
- /**
251
- * This error occurs during the parameter replacement in the template
246
+ * This error occurs when some expectation is not met in the execution of the pipeline
252
247
  *
253
- * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
248
+ * @private Always catched and rethrown as `PromptbookExecutionError`
249
+ * Note: This is a kindof subtype of PromptbookExecutionError
254
250
  */
255
- var TemplateError = /** @class */ (function (_super) {
256
- __extends(TemplateError, _super);
257
- function TemplateError(message) {
251
+ var ExpectError = /** @class */ (function (_super) {
252
+ __extends(ExpectError, _super);
253
+ function ExpectError(message) {
258
254
  var _this = _super.call(this, message) || this;
259
- _this.name = 'TemplateError';
260
- Object.setPrototypeOf(_this, TemplateError.prototype);
255
+ _this.name = 'ExpectError';
256
+ Object.setPrototypeOf(_this, ExpectError.prototype);
261
257
  return _this;
262
258
  }
263
- return TemplateError;
259
+ return ExpectError;
264
260
  }(Error));
265
261
 
266
- /**
267
- * Replaces parameters in template with values from parameters object
268
- *
269
- * @param template the template with parameters in {curly} braces
270
- * @param parameters the object with parameters
271
- * @returns the template with replaced parameters
272
- * @throws {TemplateError} if parameter is not defined, not closed, or not opened
273
- *
274
- * @private within the createPromptbookExecutor
275
- */
276
- function replaceParameters(template, parameters) {
277
- var replacedTemplate = template;
278
- var match;
279
- var loopLimit = LOOP_LIMIT;
280
- var _loop_1 = function () {
281
- if (loopLimit-- < 0) {
282
- throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
283
- }
284
- var precol = match.groups.precol;
285
- var parameterName = match.groups.parameterName;
286
- if (parameterName === '') {
287
- return "continue";
288
- }
289
- if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
290
- throw new TemplateError('Parameter is already opened or not closed');
291
- }
292
- if (parameters[parameterName] === undefined) {
293
- throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
294
- }
295
- var parameterValue = parameters[parameterName];
296
- if (parameterValue === undefined) {
297
- throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
298
- }
299
- parameterValue = parameterValue.toString();
300
- if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
301
- parameterValue = parameterValue
302
- .split('\n')
303
- .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
304
- .join('\n');
305
- }
306
- replacedTemplate =
307
- replacedTemplate.substring(0, match.index + precol.length) +
308
- parameterValue +
309
- replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
310
- };
311
- while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
312
- .exec(replacedTemplate))) {
313
- _loop_1();
314
- }
315
- // [💫] Check if there are parameters that are not closed properly
316
- if (/{\w+$/.test(replacedTemplate)) {
317
- throw new TemplateError('Parameter is not closed');
318
- }
319
- // [💫] Check if there are parameters that are not opened properly
320
- if (/^\w+}/.test(replacedTemplate)) {
321
- throw new TemplateError('Parameter is not opened');
322
- }
323
- return replacedTemplate;
324
- }
325
-
326
262
  /**
327
263
  * Counts number of characters in the text
328
264
  */
@@ -650,6 +586,144 @@ var CountUtils = {
650
586
  PAGES: countPages,
651
587
  };
652
588
 
589
+ /**
590
+ * Function checkExpectations will check if the expectations on given value are met
591
+ *
592
+ * Note: There are two simmilar functions:
593
+ * - `checkExpectations` which throws an error if the expectations are not met
594
+ * - `isPassingExpectations` which returns a boolean
595
+ *
596
+ * @throws {ExpectError} if the expectations are not met
597
+ * @returns {void} Nothing
598
+ */
599
+ function checkExpectations(expectations, value) {
600
+ var e_1, _a;
601
+ try {
602
+ for (var _b = __values(Object.entries(expectations)), _c = _b.next(); !_c.done; _c = _b.next()) {
603
+ var _d = __read(_c.value, 2), unit = _d[0], _e = _d[1], max = _e.max, min = _e.min;
604
+ var amount = CountUtils[unit.toUpperCase()](value);
605
+ if (min && amount < min) {
606
+ throw new ExpectError("Expected at least ".concat(min, " ").concat(unit, " but got ").concat(amount));
607
+ } /* not else */
608
+ if (max && amount > max) {
609
+ throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
610
+ }
611
+ }
612
+ }
613
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
614
+ finally {
615
+ try {
616
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
617
+ }
618
+ finally { if (e_1) throw e_1.error; }
619
+ }
620
+ }
621
+ /**
622
+ * Function checkExpectations will check if the expectations on given value are met
623
+ *
624
+ * Note: There are two simmilar functions:
625
+ * - `checkExpectations` which throws an error if the expectations are not met
626
+ * - `isPassingExpectations` which returns a boolean
627
+ *
628
+ * @returns {boolean} True if the expectations are met
629
+ */
630
+ function isPassingExpectations(expectations, value) {
631
+ try {
632
+ checkExpectations(expectations, value);
633
+ return true;
634
+ }
635
+ catch (error) {
636
+ if (!(error instanceof ExpectError)) {
637
+ throw error;
638
+ }
639
+ return false;
640
+ }
641
+ }
642
+ /**
643
+ * TODO: [💝] Unite object for expecting amount and format
644
+ */
645
+
646
+ /**
647
+ * The maximum number of iterations for a loops
648
+ */
649
+ var LOOP_LIMIT = 1000;
650
+
651
+ /**
652
+ * This error occurs during the parameter replacement in the template
653
+ *
654
+ * Note: This is a kindof subtype of PromptbookExecutionError because it occurs during the execution of the pipeline
655
+ */
656
+ var TemplateError = /** @class */ (function (_super) {
657
+ __extends(TemplateError, _super);
658
+ function TemplateError(message) {
659
+ var _this = _super.call(this, message) || this;
660
+ _this.name = 'TemplateError';
661
+ Object.setPrototypeOf(_this, TemplateError.prototype);
662
+ return _this;
663
+ }
664
+ return TemplateError;
665
+ }(Error));
666
+
667
+ /**
668
+ * Replaces parameters in template with values from parameters object
669
+ *
670
+ * @param template the template with parameters in {curly} braces
671
+ * @param parameters the object with parameters
672
+ * @returns the template with replaced parameters
673
+ * @throws {TemplateError} if parameter is not defined, not closed, or not opened
674
+ *
675
+ * @private within the createPromptbookExecutor
676
+ */
677
+ function replaceParameters(template, parameters) {
678
+ var replacedTemplate = template;
679
+ var match;
680
+ var loopLimit = LOOP_LIMIT;
681
+ var _loop_1 = function () {
682
+ if (loopLimit-- < 0) {
683
+ throw new UnexpectedError('Loop limit reached during parameters replacement in `replaceParameters`');
684
+ }
685
+ var precol = match.groups.precol;
686
+ var parameterName = match.groups.parameterName;
687
+ if (parameterName === '') {
688
+ return "continue";
689
+ }
690
+ if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
691
+ throw new TemplateError('Parameter is already opened or not closed');
692
+ }
693
+ if (parameters[parameterName] === undefined) {
694
+ throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
695
+ }
696
+ var parameterValue = parameters[parameterName];
697
+ if (parameterValue === undefined) {
698
+ throw new TemplateError("Parameter {".concat(parameterName, "} is not defined"));
699
+ }
700
+ parameterValue = parameterValue.toString();
701
+ if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
702
+ parameterValue = parameterValue
703
+ .split('\n')
704
+ .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
705
+ .join('\n');
706
+ }
707
+ replacedTemplate =
708
+ replacedTemplate.substring(0, match.index + precol.length) +
709
+ parameterValue +
710
+ replacedTemplate.substring(match.index + precol.length + parameterName.length + 2);
711
+ };
712
+ while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
713
+ .exec(replacedTemplate))) {
714
+ _loop_1();
715
+ }
716
+ // [💫] Check if there are parameters that are not closed properly
717
+ if (/{\w+$/.test(replacedTemplate)) {
718
+ throw new TemplateError('Parameter is not closed');
719
+ }
720
+ // [💫] Check if there are parameters that are not opened properly
721
+ if (/^\w+}/.test(replacedTemplate)) {
722
+ throw new TemplateError('Parameter is not opened');
723
+ }
724
+ return replacedTemplate;
725
+ }
726
+
653
727
  /**
654
728
  * Function isValidJsonString will tell you if the string is valid JSON or not
655
729
  */
@@ -1083,7 +1157,7 @@ function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
1083
1157
  /**
1084
1158
  * The version of the Promptbook library
1085
1159
  */
1086
- var PROMPTBOOK_VERSION = '0.44.0-2';
1160
+ var PROMPTBOOK_VERSION = '0.44.0-4';
1087
1161
 
1088
1162
  /**
1089
1163
  * Parses the given script and returns the list of all used variables that are not defined in the script
@@ -1151,6 +1225,7 @@ var ExecutionTypes = [
1151
1225
  */
1152
1226
  var EXPECTATION_UNITS = ['CHARACTERS', 'WORDS', 'SENTENCES', 'PARAGRAPHS', 'LINES', 'PAGES'];
1153
1227
  /**
1228
+ * TODO: [💝] Unite object for expecting amount and format - remove expectFormat
1154
1229
  * TODO: use one helper type> (string_prompt | string_javascript | string_markdown) & string_template
1155
1230
  */
1156
1231
 
@@ -1891,23 +1966,6 @@ function validatePromptbookJson(promptbook) {
1891
1966
  * > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
1892
1967
  */
1893
1968
 
1894
- /**
1895
- * This error occurs when some expectation is not met in the execution of the pipeline
1896
- *
1897
- * @private Always catched and rethrown as `PromptbookExecutionError`
1898
- * Note: This is a kindof subtype of PromptbookExecutionError
1899
- */
1900
- var ExpectError = /** @class */ (function (_super) {
1901
- __extends(ExpectError, _super);
1902
- function ExpectError(message) {
1903
- var _this = _super.call(this, message) || this;
1904
- _this.name = 'ExpectError';
1905
- Object.setPrototypeOf(_this, ExpectError.prototype);
1906
- return _this;
1907
- }
1908
- return ExpectError;
1909
- }(Error));
1910
-
1911
1969
  /**
1912
1970
  * Creates executor function from promptbook and execution tools.
1913
1971
  *
@@ -1922,10 +1980,10 @@ function createPromptbookExecutor(options) {
1922
1980
  var promptbookExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
1923
1981
  function executeSingleTemplate(currentTemplate) {
1924
1982
  return __awaiter(this, void 0, void 0, function () {
1925
- var name, title, priority, prompt, chatThread, completionResult, result, resultString, expectError, scriptExecutionErrors, maxAttempts, jokers, attempt, isJokerAttempt, joker, _a, _b, _c, _d, scriptTools, error_2, e_2_1, _e, _f, functionName, postprocessingError, _g, _h, scriptTools, error_3, e_3_1, e_4_1, _j, _k, _l, unit, _m, max, min, amount, error_4;
1926
- var e_2, _o, e_4, _p, e_3, _q, e_5, _r, _s;
1927
- return __generator(this, function (_t) {
1928
- switch (_t.label) {
1983
+ var name, title, priority, prompt, chatThread, completionResult, result, resultString, expectError, scriptExecutionErrors, maxAttempts, jokers, attempt, isJokerAttempt, joker, _a, _b, _c, _d, scriptTools, error_2, e_2_1, _e, _f, functionName, postprocessingError, _g, _h, scriptTools, error_3, e_3_1, e_4_1, error_4;
1984
+ var e_2, _j, e_4, _k, e_3, _l, _m;
1985
+ return __generator(this, function (_o) {
1986
+ switch (_o.label) {
1929
1987
  case 0:
1930
1988
  name = "promptbook-executor-frame-".concat(currentTemplate.name);
1931
1989
  title = currentTemplate.title;
@@ -1942,8 +2000,8 @@ function createPromptbookExecutor(options) {
1942
2000
  // <- [3]
1943
2001
  })];
1944
2002
  case 1:
1945
- _t.sent();
1946
- _t.label = 2;
2003
+ _o.sent();
2004
+ _o.label = 2;
1947
2005
  case 2:
1948
2006
  result = null;
1949
2007
  resultString = null;
@@ -1951,7 +2009,7 @@ function createPromptbookExecutor(options) {
1951
2009
  maxAttempts = currentTemplate.executionType === 'PROMPT_DIALOG' ? Infinity : maxExecutionAttempts;
1952
2010
  jokers = currentTemplate.jokers || [];
1953
2011
  attempt = -jokers.length;
1954
- _t.label = 3;
2012
+ _o.label = 3;
1955
2013
  case 3:
1956
2014
  if (!(attempt < maxAttempts)) return [3 /*break*/, 49];
1957
2015
  isJokerAttempt = attempt < 0;
@@ -1968,9 +2026,9 @@ function createPromptbookExecutor(options) {
1968
2026
  }
1969
2027
  resultString = parametersToPass[joker];
1970
2028
  }
1971
- _t.label = 4;
2029
+ _o.label = 4;
1972
2030
  case 4:
1973
- _t.trys.push([4, 45, 46, 47]);
2031
+ _o.trys.push([4, 45, 46, 47]);
1974
2032
  if (!!isJokerAttempt) return [3 /*break*/, 27];
1975
2033
  _a = currentTemplate.executionType;
1976
2034
  switch (_a) {
@@ -2002,14 +2060,14 @@ function createPromptbookExecutor(options) {
2002
2060
  return [3 /*break*/, 11];
2003
2061
  case 7: return [4 /*yield*/, tools.natural.gptChat(prompt)];
2004
2062
  case 8:
2005
- chatThread = _t.sent();
2063
+ chatThread = _o.sent();
2006
2064
  // TODO: [🍬] Destroy chatThread
2007
2065
  result = chatThread;
2008
2066
  resultString = chatThread.content;
2009
2067
  return [3 /*break*/, 12];
2010
2068
  case 9: return [4 /*yield*/, tools.natural.gptComplete(prompt)];
2011
2069
  case 10:
2012
- completionResult = _t.sent();
2070
+ completionResult = _o.sent();
2013
2071
  result = completionResult;
2014
2072
  resultString = completionResult.content;
2015
2073
  return [3 /*break*/, 12];
@@ -2024,27 +2082,27 @@ function createPromptbookExecutor(options) {
2024
2082
  }
2025
2083
  // TODO: DRY [1]
2026
2084
  scriptExecutionErrors = [];
2027
- _t.label = 14;
2085
+ _o.label = 14;
2028
2086
  case 14:
2029
- _t.trys.push([14, 21, 22, 23]);
2087
+ _o.trys.push([14, 21, 22, 23]);
2030
2088
  _c = (e_2 = void 0, __values(tools.script)), _d = _c.next();
2031
- _t.label = 15;
2089
+ _o.label = 15;
2032
2090
  case 15:
2033
2091
  if (!!_d.done) return [3 /*break*/, 20];
2034
2092
  scriptTools = _d.value;
2035
- _t.label = 16;
2093
+ _o.label = 16;
2036
2094
  case 16:
2037
- _t.trys.push([16, 18, , 19]);
2095
+ _o.trys.push([16, 18, , 19]);
2038
2096
  return [4 /*yield*/, scriptTools.execute({
2039
2097
  scriptLanguage: currentTemplate.contentLanguage,
2040
2098
  script: currentTemplate.content,
2041
2099
  parameters: parametersToPass,
2042
2100
  })];
2043
2101
  case 17:
2044
- resultString = _t.sent();
2102
+ resultString = _o.sent();
2045
2103
  return [3 /*break*/, 20];
2046
2104
  case 18:
2047
- error_2 = _t.sent();
2105
+ error_2 = _o.sent();
2048
2106
  if (!(error_2 instanceof Error)) {
2049
2107
  throw error_2;
2050
2108
  }
@@ -2055,12 +2113,12 @@ function createPromptbookExecutor(options) {
2055
2113
  return [3 /*break*/, 15];
2056
2114
  case 20: return [3 /*break*/, 23];
2057
2115
  case 21:
2058
- e_2_1 = _t.sent();
2116
+ e_2_1 = _o.sent();
2059
2117
  e_2 = { error: e_2_1 };
2060
2118
  return [3 /*break*/, 23];
2061
2119
  case 22:
2062
2120
  try {
2063
- if (_d && !_d.done && (_o = _c.return)) _o.call(_c);
2121
+ if (_d && !_d.done && (_j = _c.return)) _j.call(_c);
2064
2122
  }
2065
2123
  finally { if (e_2) throw e_2.error; }
2066
2124
  return [7 /*endfinally*/];
@@ -2086,46 +2144,46 @@ function createPromptbookExecutor(options) {
2086
2144
  })];
2087
2145
  case 25:
2088
2146
  // TODO: [🌹] When making next attempt for `PROMPT DIALOG`, preserve the previous user input
2089
- resultString = _t.sent();
2147
+ resultString = _o.sent();
2090
2148
  return [3 /*break*/, 27];
2091
2149
  case 26: throw new PromptbookExecutionError(
2092
2150
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2093
2151
  "Unknown execution type \"".concat(currentTemplate.executionType, "\""));
2094
2152
  case 27:
2095
2153
  if (!(!isJokerAttempt && currentTemplate.postprocessing)) return [3 /*break*/, 44];
2096
- _t.label = 28;
2154
+ _o.label = 28;
2097
2155
  case 28:
2098
- _t.trys.push([28, 42, 43, 44]);
2156
+ _o.trys.push([28, 42, 43, 44]);
2099
2157
  _e = (e_4 = void 0, __values(currentTemplate.postprocessing)), _f = _e.next();
2100
- _t.label = 29;
2158
+ _o.label = 29;
2101
2159
  case 29:
2102
2160
  if (!!_f.done) return [3 /*break*/, 41];
2103
2161
  functionName = _f.value;
2104
2162
  // TODO: DRY [1]
2105
2163
  scriptExecutionErrors = [];
2106
2164
  postprocessingError = null;
2107
- _t.label = 30;
2165
+ _o.label = 30;
2108
2166
  case 30:
2109
- _t.trys.push([30, 37, 38, 39]);
2167
+ _o.trys.push([30, 37, 38, 39]);
2110
2168
  _g = (e_3 = void 0, __values(tools.script)), _h = _g.next();
2111
- _t.label = 31;
2169
+ _o.label = 31;
2112
2170
  case 31:
2113
2171
  if (!!_h.done) return [3 /*break*/, 36];
2114
2172
  scriptTools = _h.value;
2115
- _t.label = 32;
2173
+ _o.label = 32;
2116
2174
  case 32:
2117
- _t.trys.push([32, 34, , 35]);
2175
+ _o.trys.push([32, 34, , 35]);
2118
2176
  return [4 /*yield*/, scriptTools.execute({
2119
2177
  scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
2120
2178
  script: "".concat(functionName, "(resultString)"),
2121
2179
  parameters: __assign(__assign({}, parametersToPass), { resultString: resultString || '' }),
2122
2180
  })];
2123
2181
  case 33:
2124
- resultString = _t.sent();
2182
+ resultString = _o.sent();
2125
2183
  postprocessingError = null;
2126
2184
  return [3 /*break*/, 36];
2127
2185
  case 34:
2128
- error_3 = _t.sent();
2186
+ error_3 = _o.sent();
2129
2187
  if (!(error_3 instanceof Error)) {
2130
2188
  throw error_3;
2131
2189
  }
@@ -2137,12 +2195,12 @@ function createPromptbookExecutor(options) {
2137
2195
  return [3 /*break*/, 31];
2138
2196
  case 36: return [3 /*break*/, 39];
2139
2197
  case 37:
2140
- e_3_1 = _t.sent();
2198
+ e_3_1 = _o.sent();
2141
2199
  e_3 = { error: e_3_1 };
2142
2200
  return [3 /*break*/, 39];
2143
2201
  case 38:
2144
2202
  try {
2145
- if (_h && !_h.done && (_q = _g.return)) _q.call(_g);
2203
+ if (_h && !_h.done && (_l = _g.return)) _l.call(_g);
2146
2204
  }
2147
2205
  finally { if (e_3) throw e_3.error; }
2148
2206
  return [7 /*endfinally*/];
@@ -2150,22 +2208,23 @@ function createPromptbookExecutor(options) {
2150
2208
  if (postprocessingError) {
2151
2209
  throw postprocessingError;
2152
2210
  }
2153
- _t.label = 40;
2211
+ _o.label = 40;
2154
2212
  case 40:
2155
2213
  _f = _e.next();
2156
2214
  return [3 /*break*/, 29];
2157
2215
  case 41: return [3 /*break*/, 44];
2158
2216
  case 42:
2159
- e_4_1 = _t.sent();
2217
+ e_4_1 = _o.sent();
2160
2218
  e_4 = { error: e_4_1 };
2161
2219
  return [3 /*break*/, 44];
2162
2220
  case 43:
2163
2221
  try {
2164
- if (_f && !_f.done && (_p = _e.return)) _p.call(_e);
2222
+ if (_f && !_f.done && (_k = _e.return)) _k.call(_e);
2165
2223
  }
2166
2224
  finally { if (e_4) throw e_4.error; }
2167
2225
  return [7 /*endfinally*/];
2168
2226
  case 44:
2227
+ // TODO: [💝] Unite object for expecting amount and format
2169
2228
  if (currentTemplate.expectFormat) {
2170
2229
  if (currentTemplate.expectFormat === 'JSON') {
2171
2230
  if (!isValidJsonString(resultString || '')) {
@@ -2173,30 +2232,13 @@ function createPromptbookExecutor(options) {
2173
2232
  }
2174
2233
  }
2175
2234
  }
2235
+ // TODO: [💝] Unite object for expecting amount and format
2176
2236
  if (currentTemplate.expectations) {
2177
- try {
2178
- for (_j = (e_5 = void 0, __values(Object.entries(currentTemplate.expectations))), _k = _j.next(); !_k.done; _k = _j.next()) {
2179
- _l = __read(_k.value, 2), unit = _l[0], _m = _l[1], max = _m.max, min = _m.min;
2180
- amount = CountUtils[unit.toUpperCase()](resultString || '');
2181
- if (min && amount < min) {
2182
- throw new ExpectError("Expected at least ".concat(min, " ").concat(unit, " but got ").concat(amount));
2183
- } /* not else */
2184
- if (max && amount > max) {
2185
- throw new ExpectError("Expected at most ".concat(max, " ").concat(unit, " but got ").concat(amount));
2186
- }
2187
- }
2188
- }
2189
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
2190
- finally {
2191
- try {
2192
- if (_k && !_k.done && (_r = _j.return)) _r.call(_j);
2193
- }
2194
- finally { if (e_5) throw e_5.error; }
2195
- }
2237
+ checkExpectations(currentTemplate.expectations, resultString || '');
2196
2238
  }
2197
2239
  return [3 /*break*/, 49];
2198
2240
  case 45:
2199
- error_4 = _t.sent();
2241
+ error_4 = _o.sent();
2200
2242
  if (!(error_4 instanceof ExpectError)) {
2201
2243
  throw error_4;
2202
2244
  }
@@ -2227,7 +2269,7 @@ function createPromptbookExecutor(options) {
2227
2269
  if (expectError !== null && attempt === maxAttempts - 1) {
2228
2270
  throw new PromptbookExecutionError(spaceTrim(function (block) { return "\n Natural execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n "); }));
2229
2271
  }
2230
- _t.label = 48;
2272
+ _o.label = 48;
2231
2273
  case 48:
2232
2274
  attempt++;
2233
2275
  return [3 /*break*/, 3];
@@ -2247,7 +2289,7 @@ function createPromptbookExecutor(options) {
2247
2289
  // <- [3]
2248
2290
  });
2249
2291
  }
2250
- parametersToPass = __assign(__assign({}, parametersToPass), (_s = {}, _s[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because Promptbook checks logic consistency during construction */, _s));
2292
+ parametersToPass = __assign(__assign({}, parametersToPass), (_m = {}, _m[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because Promptbook checks logic consistency during construction */, _m));
2251
2293
  return [2 /*return*/];
2252
2294
  }
2253
2295
  });
@@ -2460,19 +2502,26 @@ var MockedEchoNaturalExecutionTools = /** @class */ (function () {
2460
2502
  * @private internal util for MockedFackedNaturalExecutionTools
2461
2503
  */
2462
2504
  function $fakeTextToExpectations(expectations) {
2463
- var lorem = new LoremIpsum({
2464
- sentencesPerParagraph: {
2465
- max: 8,
2466
- min: 4,
2467
- },
2468
- wordsPerSentence: {
2469
- max: 16,
2470
- min: 4,
2471
- },
2472
- });
2473
- // TODO: !!! Really use the expectations to generate the text
2474
- return lorem.generateSentences(5);
2505
+ var lorem = new LoremIpsum({});
2506
+ var loremText = '';
2507
+ var text = '';
2508
+ for (var loopLimit = LOOP_LIMIT; loopLimit-- > 0;) {
2509
+ if (isPassingExpectations(expectations, text)) {
2510
+ return text;
2511
+ }
2512
+ if (loremText === '') {
2513
+ loremText = lorem.generateParagraphs(2);
2514
+ }
2515
+ text += loremText.substring(0, 1);
2516
+ loremText = loremText.substring(1);
2517
+ console.log(text);
2518
+ }
2519
+ throw new Error('Can not generate fake text to met the expectations; Loop limit reached');
2475
2520
  }
2521
+ /**
2522
+ * TODO: Implement better
2523
+ * TODO: [💝] Unite object for expecting amount and format - use here also a format
2524
+ */
2476
2525
 
2477
2526
  /**
2478
2527
  * Mocked execution Tools for just faking expected responses for testing purposes