@promptbook/vercel 0.76.0 → 0.77.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.
package/umd/index.umd.js CHANGED
@@ -1,31 +1,703 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-vercel"] = {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
8
- /**
9
- * The version of the Book language
10
- *
11
- * @see https://github.com/webgptorg/book
12
- */
13
- var BOOK_LANGUAGE_VERSION = '1.0.0';
14
- /**
15
- * The version of the Promptbook engine
16
- *
17
- * @see https://github.com/webgptorg/promptbook
18
- */
19
- var PROMPTBOOK_ENGINE_VERSION = '0.75.10';
20
- /**
21
- * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
22
- * Note: [💞] Ignore a discrepancy between file name and entity name
23
- */
24
-
25
- exports.BOOK_LANGUAGE_VERSION = BOOK_LANGUAGE_VERSION;
26
- exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
27
-
28
- Object.defineProperty(exports, '__esModule', { value: true });
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('spacetrim')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'colors', 'spacetrim'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-vercel"] = {}, global.colors, global.spaceTrim));
5
+ })(this, (function (exports, colors, spaceTrim) { 'use strict';
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
10
+ var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
11
+
12
+ // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
13
+ /**
14
+ * The version of the Book language
15
+ *
16
+ * @see https://github.com/webgptorg/book
17
+ */
18
+ var BOOK_LANGUAGE_VERSION = '1.0.0';
19
+ /**
20
+ * The version of the Promptbook engine
21
+ *
22
+ * @see https://github.com/webgptorg/promptbook
23
+ */
24
+ var PROMPTBOOK_ENGINE_VERSION = '0.76.0';
25
+ /**
26
+ * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
27
+ * Note: [💞] Ignore a discrepancy between file name and entity name
28
+ */
29
+
30
+ /*! *****************************************************************************
31
+ Copyright (c) Microsoft Corporation.
32
+
33
+ Permission to use, copy, modify, and/or distribute this software for any
34
+ purpose with or without fee is hereby granted.
35
+
36
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
37
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
38
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
39
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
40
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
41
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
42
+ PERFORMANCE OF THIS SOFTWARE.
43
+ ***************************************************************************** */
44
+ /* global Reflect, Promise */
45
+
46
+ var extendStatics = function(d, b) {
47
+ extendStatics = Object.setPrototypeOf ||
48
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
49
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
50
+ return extendStatics(d, b);
51
+ };
52
+
53
+ function __extends(d, b) {
54
+ if (typeof b !== "function" && b !== null)
55
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
56
+ extendStatics(d, b);
57
+ function __() { this.constructor = d; }
58
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
59
+ }
60
+
61
+ var __assign = function() {
62
+ __assign = Object.assign || function __assign(t) {
63
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
64
+ s = arguments[i];
65
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
66
+ }
67
+ return t;
68
+ };
69
+ return __assign.apply(this, arguments);
70
+ };
71
+
72
+ function __awaiter(thisArg, _arguments, P, generator) {
73
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
74
+ return new (P || (P = Promise))(function (resolve, reject) {
75
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
76
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
77
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
78
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
79
+ });
80
+ }
81
+
82
+ function __generator(thisArg, body) {
83
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
84
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
85
+ function verb(n) { return function (v) { return step([n, v]); }; }
86
+ function step(op) {
87
+ if (f) throw new TypeError("Generator is already executing.");
88
+ while (_) try {
89
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
90
+ if (y = 0, t) op = [op[0] & 2, t.value];
91
+ switch (op[0]) {
92
+ case 0: case 1: t = op; break;
93
+ case 4: _.label++; return { value: op[1], done: false };
94
+ case 5: _.label++; y = op[1]; op = [0]; continue;
95
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
96
+ default:
97
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
98
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
99
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
100
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
101
+ if (t[2]) _.ops.pop();
102
+ _.trys.pop(); continue;
103
+ }
104
+ op = body.call(thisArg, _);
105
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
106
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
107
+ }
108
+ }
109
+
110
+ function __values(o) {
111
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
112
+ if (m) return m.call(o);
113
+ if (o && typeof o.length === "number") return {
114
+ next: function () {
115
+ if (o && i >= o.length) o = void 0;
116
+ return { value: o && o[i++], done: !o };
117
+ }
118
+ };
119
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
120
+ }
121
+
122
+ function __read(o, n) {
123
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
124
+ if (!m) return o;
125
+ var i = m.call(o), r, ar = [], e;
126
+ try {
127
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
128
+ }
129
+ catch (error) { e = { error: error }; }
130
+ finally {
131
+ try {
132
+ if (r && !r.done && (m = i["return"])) m.call(i);
133
+ }
134
+ finally { if (e) throw e.error; }
135
+ }
136
+ return ar;
137
+ }
138
+
139
+ function __spreadArray(to, from, pack) {
140
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
141
+ if (ar || !(i in from)) {
142
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
143
+ ar[i] = from[i];
144
+ }
145
+ }
146
+ return to.concat(ar || Array.prototype.slice.call(from));
147
+ }
148
+
149
+ /**
150
+ * @@@
151
+ *
152
+ * Note: `$` is used to indicate that this function is not a pure function - it mutates given object
153
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
154
+ *
155
+ * @returns The same object as the input, but deeply frozen
156
+ * @public exported from `@promptbook/utils`
157
+ */
158
+ function $deepFreeze(objectValue) {
159
+ var e_1, _a;
160
+ var propertyNames = Object.getOwnPropertyNames(objectValue);
161
+ try {
162
+ for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
163
+ var propertyName = propertyNames_1_1.value;
164
+ var value = objectValue[propertyName];
165
+ if (value && typeof value === 'object') {
166
+ $deepFreeze(value);
167
+ }
168
+ }
169
+ }
170
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
171
+ finally {
172
+ try {
173
+ if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
174
+ }
175
+ finally { if (e_1) throw e_1.error; }
176
+ }
177
+ return Object.freeze(objectValue);
178
+ }
179
+ /**
180
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
181
+ */
182
+
183
+ /**
184
+ * Represents the usage with no resources consumed
185
+ *
186
+ * @public exported from `@promptbook/core`
187
+ */
188
+ $deepFreeze({
189
+ price: { value: 0 },
190
+ input: {
191
+ tokensCount: { value: 0 },
192
+ charactersCount: { value: 0 },
193
+ wordsCount: { value: 0 },
194
+ sentencesCount: { value: 0 },
195
+ linesCount: { value: 0 },
196
+ paragraphsCount: { value: 0 },
197
+ pagesCount: { value: 0 },
198
+ },
199
+ output: {
200
+ tokensCount: { value: 0 },
201
+ charactersCount: { value: 0 },
202
+ wordsCount: { value: 0 },
203
+ sentencesCount: { value: 0 },
204
+ linesCount: { value: 0 },
205
+ paragraphsCount: { value: 0 },
206
+ pagesCount: { value: 0 },
207
+ },
208
+ });
209
+ /**
210
+ * Represents the usage with unknown resources consumed
211
+ *
212
+ * @public exported from `@promptbook/core`
213
+ */
214
+ var UNCERTAIN_USAGE = $deepFreeze({
215
+ price: { value: 0, isUncertain: true },
216
+ input: {
217
+ tokensCount: { value: 0, isUncertain: true },
218
+ charactersCount: { value: 0, isUncertain: true },
219
+ wordsCount: { value: 0, isUncertain: true },
220
+ sentencesCount: { value: 0, isUncertain: true },
221
+ linesCount: { value: 0, isUncertain: true },
222
+ paragraphsCount: { value: 0, isUncertain: true },
223
+ pagesCount: { value: 0, isUncertain: true },
224
+ },
225
+ output: {
226
+ tokensCount: { value: 0, isUncertain: true },
227
+ charactersCount: { value: 0, isUncertain: true },
228
+ wordsCount: { value: 0, isUncertain: true },
229
+ sentencesCount: { value: 0, isUncertain: true },
230
+ linesCount: { value: 0, isUncertain: true },
231
+ paragraphsCount: { value: 0, isUncertain: true },
232
+ pagesCount: { value: 0, isUncertain: true },
233
+ },
234
+ });
235
+ /**
236
+ * Note: [💞] Ignore a discrepancy between file name and entity name
237
+ */
238
+
239
+ /**
240
+ * This error type indicates that the error should not happen and its last check before crashing with some other error
241
+ *
242
+ * @public exported from `@promptbook/core`
243
+ */
244
+ var UnexpectedError = /** @class */ (function (_super) {
245
+ __extends(UnexpectedError, _super);
246
+ function UnexpectedError(message) {
247
+ var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
248
+ _this.name = 'UnexpectedError';
249
+ Object.setPrototypeOf(_this, UnexpectedError.prototype);
250
+ return _this;
251
+ }
252
+ return UnexpectedError;
253
+ }(Error));
254
+
255
+ /**
256
+ * Checks if the value is [🚉] serializable as JSON
257
+ * If not, throws an UnexpectedError with a rich error message and tracking
258
+ *
259
+ * - Almost all primitives are serializable BUT:
260
+ * - `undefined` is not serializable
261
+ * - `NaN` is not serializable
262
+ * - Objects and arrays are serializable if all their properties are serializable
263
+ * - Functions are not serializable
264
+ * - Circular references are not serializable
265
+ * - `Date` objects are not serializable
266
+ * - `Map` and `Set` objects are not serializable
267
+ * - `RegExp` objects are not serializable
268
+ * - `Error` objects are not serializable
269
+ * - `Symbol` objects are not serializable
270
+ * - And much more...
271
+ *
272
+ * @throws UnexpectedError if the value is not serializable as JSON
273
+ * @public exported from `@promptbook/utils`
274
+ */
275
+ function checkSerializableAsJson(name, value) {
276
+ var e_1, _a;
277
+ if (value === undefined) {
278
+ throw new UnexpectedError("".concat(name, " is undefined"));
279
+ }
280
+ else if (value === null) {
281
+ return;
282
+ }
283
+ else if (typeof value === 'boolean') {
284
+ return;
285
+ }
286
+ else if (typeof value === 'number' && !isNaN(value)) {
287
+ return;
288
+ }
289
+ else if (typeof value === 'string') {
290
+ return;
291
+ }
292
+ else if (typeof value === 'symbol') {
293
+ throw new UnexpectedError("".concat(name, " is symbol"));
294
+ }
295
+ else if (typeof value === 'function') {
296
+ throw new UnexpectedError("".concat(name, " is function"));
297
+ }
298
+ else if (typeof value === 'object' && Array.isArray(value)) {
299
+ for (var i = 0; i < value.length; i++) {
300
+ checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
301
+ }
302
+ }
303
+ else if (typeof value === 'object') {
304
+ if (value instanceof Date) {
305
+ throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
306
+ }
307
+ else if (value instanceof Map) {
308
+ throw new UnexpectedError("".concat(name, " is Map"));
309
+ }
310
+ else if (value instanceof Set) {
311
+ throw new UnexpectedError("".concat(name, " is Set"));
312
+ }
313
+ else if (value instanceof RegExp) {
314
+ throw new UnexpectedError("".concat(name, " is RegExp"));
315
+ }
316
+ else if (value instanceof Error) {
317
+ throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
318
+ }
319
+ else {
320
+ try {
321
+ for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
322
+ var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
323
+ if (subValue === undefined) {
324
+ // Note: undefined in object is serializable - it is just omited
325
+ continue;
326
+ }
327
+ checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
328
+ }
329
+ }
330
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
331
+ finally {
332
+ try {
333
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
334
+ }
335
+ finally { if (e_1) throw e_1.error; }
336
+ }
337
+ try {
338
+ JSON.stringify(value); // <- TODO: [0]
339
+ }
340
+ catch (error) {
341
+ if (!(error instanceof Error)) {
342
+ throw error;
343
+ }
344
+ throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
345
+ }
346
+ /*
347
+ TODO: [0] Is there some more elegant way to check circular references?
348
+ const seen = new Set();
349
+ const stack = [{ value }];
350
+ while (stack.length > 0) {
351
+ const { value } = stack.pop()!;
352
+ if (typeof value === 'object' && value !== null) {
353
+ if (seen.has(value)) {
354
+ throw new UnexpectedError(`${name} has circular reference`);
355
+ }
356
+ seen.add(value);
357
+ if (Array.isArray(value)) {
358
+ stack.push(...value.map((value) => ({ value })));
359
+ } else {
360
+ stack.push(...Object.values(value).map((value) => ({ value })));
361
+ }
362
+ }
363
+ }
364
+ */
365
+ return;
366
+ }
367
+ }
368
+ else {
369
+ throw new UnexpectedError("".concat(name, " is unknown"));
370
+ }
371
+ }
372
+ /**
373
+ * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
374
+ * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
375
+ * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
376
+ */
377
+
378
+ /**
379
+ * @@@
380
+ * @@@
381
+ *
382
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
383
+ *
384
+ * @param name - Name of the object for debugging purposes
385
+ * @param objectValue - Object to be deeply frozen
386
+ * @returns The same object as the input, but deeply frozen
387
+ * @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
388
+ */
389
+ function $asDeeplyFrozenSerializableJson(name, objectValue) {
390
+ checkSerializableAsJson(name, objectValue);
391
+ return $deepFreeze(objectValue);
392
+ }
393
+ /**
394
+ * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
395
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
396
+ */
397
+
398
+ // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
399
+ /**
400
+ * The maximum number of iterations for a loops
401
+ *
402
+ * @private within the repository - too low-level in comparison with other `MAX_...`
403
+ */
404
+ var LOOP_LIMIT = 1000;
405
+ /**
406
+ * Nonce which is used for replacing things in strings
407
+ *
408
+ * @private within the repository
409
+ */
410
+ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
411
+ /**
412
+ * The names of the parameters that are reserved for special purposes
413
+ *
414
+ * @public exported from `@promptbook/core`
415
+ */
416
+ $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
417
+ 'content',
418
+ 'context',
419
+ 'knowledge',
420
+ 'examples',
421
+ 'modelName',
422
+ 'currentDate',
423
+ // <- TODO: list here all command names
424
+ // <- TODO: Add more like 'date', 'modelName',...
425
+ // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
426
+ ]);
427
+ /**
428
+ * @@@
429
+ *
430
+ * @private within the repository
431
+ */
432
+ var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
433
+ /**
434
+ * @@@
435
+ *
436
+ * @private within the repository
437
+ */
438
+ var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
439
+ // <- TODO: [🧜‍♂️]
440
+ /**
441
+ * @@@
442
+ *
443
+ * @public exported from `@promptbook/core`
444
+ */
445
+ Object.freeze({
446
+ delimiter: ',',
447
+ quoteChar: '"',
448
+ newline: '\n',
449
+ skipEmptyLines: true,
450
+ });
451
+ /**
452
+ * TODO: Extract `constants.ts` from `config.ts`
453
+ * Note: [💞] Ignore a discrepancy between file name and entity name
454
+ * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
455
+ */
456
+
457
+ /**
458
+ * This error type indicates that some limit was reached
459
+ *
460
+ * @public exported from `@promptbook/core`
461
+ */
462
+ var LimitReachedError = /** @class */ (function (_super) {
463
+ __extends(LimitReachedError, _super);
464
+ function LimitReachedError(message) {
465
+ var _this = _super.call(this, message) || this;
466
+ _this.name = 'LimitReachedError';
467
+ Object.setPrototypeOf(_this, LimitReachedError.prototype);
468
+ return _this;
469
+ }
470
+ return LimitReachedError;
471
+ }(Error));
472
+
473
+ /**
474
+ * This error indicates errors during the execution of the pipeline
475
+ *
476
+ * @public exported from `@promptbook/core`
477
+ */
478
+ var PipelineExecutionError = /** @class */ (function (_super) {
479
+ __extends(PipelineExecutionError, _super);
480
+ function PipelineExecutionError(message) {
481
+ var _this = _super.call(this, message) || this;
482
+ _this.name = 'PipelineExecutionError';
483
+ Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
484
+ return _this;
485
+ }
486
+ return PipelineExecutionError;
487
+ }(Error));
488
+
489
+ /**
490
+ * Replaces parameters in template with values from parameters object
491
+ *
492
+ * @param template the template with parameters in {curly} braces
493
+ * @param parameters the object with parameters
494
+ * @returns the template with replaced parameters
495
+ * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
496
+ * @public exported from `@promptbook/utils`
497
+ */
498
+ function replaceParameters(template, parameters) {
499
+ var e_1, _a;
500
+ try {
501
+ for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
502
+ var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
503
+ if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
504
+ throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
505
+ }
506
+ else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
507
+ // TODO: [🍵]
508
+ throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
509
+ }
510
+ }
511
+ }
512
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
513
+ finally {
514
+ try {
515
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
516
+ }
517
+ finally { if (e_1) throw e_1.error; }
518
+ }
519
+ var replacedTemplates = template;
520
+ var match;
521
+ var loopLimit = LOOP_LIMIT;
522
+ var _loop_1 = function () {
523
+ if (loopLimit-- < 0) {
524
+ throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
525
+ }
526
+ var precol = match.groups.precol;
527
+ var parameterName = match.groups.parameterName;
528
+ if (parameterName === '') {
529
+ return "continue";
530
+ }
531
+ if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
532
+ throw new PipelineExecutionError('Parameter is already opened or not closed');
533
+ }
534
+ if (parameters[parameterName] === undefined) {
535
+ throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
536
+ }
537
+ var parameterValue = parameters[parameterName];
538
+ if (parameterValue === undefined) {
539
+ throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
540
+ }
541
+ parameterValue = parameterValue.toString();
542
+ if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
543
+ parameterValue = parameterValue
544
+ .split('\n')
545
+ .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
546
+ .join('\n');
547
+ }
548
+ replacedTemplates =
549
+ replacedTemplates.substring(0, match.index + precol.length) +
550
+ parameterValue +
551
+ replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
552
+ };
553
+ while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
554
+ .exec(replacedTemplates))) {
555
+ _loop_1();
556
+ }
557
+ // [💫] Check if there are parameters that are not closed properly
558
+ if (/{\w+$/.test(replacedTemplates)) {
559
+ throw new PipelineExecutionError('Parameter is not closed');
560
+ }
561
+ // [💫] Check if there are parameters that are not opened properly
562
+ if (/^\w+}/.test(replacedTemplates)) {
563
+ throw new PipelineExecutionError('Parameter is not opened');
564
+ }
565
+ return replacedTemplates;
566
+ }
567
+
568
+ /**
569
+ * Simple wrapper `new Date().toISOString()`
570
+ *
571
+ * Note: `$` is used to indicate that this function is not a pure function - it is not deterministic because it depends on the current time
572
+ *
573
+ * @returns string_date branded type
574
+ * @public exported from `@promptbook/utils`
575
+ */
576
+ function $getCurrentDate() {
577
+ return new Date().toISOString();
578
+ }
579
+
580
+ // <- TODO: Is there some way to get the type of the provider directly, NOT this stupid way via inferring the return type from a specific vercel provider⁉
581
+ /**
582
+ * !!!!!!
583
+ *
584
+ * @public exported from `@promptbook/vercel`
585
+ */
586
+ function createExecutionToolsFromVercelProvider(vercelProvider, options) {
587
+ if (options === void 0) { options = {}; }
588
+ return {
589
+ title: '!!!',
590
+ description: "!!! (through Vercel)",
591
+ checkConfiguration: function () {
592
+ // TODO: !!!!!!
593
+ return Promise.resolve();
594
+ },
595
+ listModels: function () {
596
+ return __awaiter(this, void 0, void 0, function () {
597
+ return __generator(this, function (_a) {
598
+ return [2 /*return*/, [
599
+ /* TODO: !!!!! */
600
+ ]];
601
+ });
602
+ });
603
+ },
604
+ callChatModel: function (prompt) {
605
+ var _a;
606
+ return __awaiter(this, void 0, void 0, function () {
607
+ var content, parameters, modelRequirements, modelName, model, rawPromptContent, rawRequest, start, rawResponse, complete, usage;
608
+ return __generator(this, function (_b) {
609
+ switch (_b.label) {
610
+ case 0:
611
+ content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
612
+ if (modelRequirements.modelVariant !== 'CHAT') {
613
+ throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
614
+ }
615
+ modelName = 'gpt-4';
616
+ return [4 /*yield*/, vercelProvider.chat(modelName, {
617
+ user: ((_a = options.userId) === null || _a === void 0 ? void 0 : _a.toString()) || undefined,
618
+ })];
619
+ case 1:
620
+ model = _b.sent();
621
+ rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
622
+ rawRequest = {
623
+ // <- TODO: [☂]
624
+ inputFormat: 'messages',
625
+ mode: {
626
+ type: 'regular',
627
+ tools: [
628
+ /* !!!!!! */
629
+ ],
630
+ },
631
+ prompt: __spreadArray(__spreadArray([], __read((modelRequirements.systemMessage === undefined
632
+ ? []
633
+ : [
634
+ {
635
+ role: 'system',
636
+ content: modelRequirements.systemMessage,
637
+ },
638
+ ])), false), [
639
+ {
640
+ role: 'user',
641
+ content: [
642
+ {
643
+ type: 'text',
644
+ text: rawPromptContent,
645
+ },
646
+ ],
647
+ },
648
+ ], false),
649
+ };
650
+ start = $getCurrentDate();
651
+ if (options.isVerbose) {
652
+ console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
653
+ }
654
+ return [4 /*yield*/, model.doGenerate(rawRequest)];
655
+ case 2:
656
+ rawResponse = _b.sent();
657
+ /*
658
+ TODO: !!!!!! Handle errors
659
+ .catch((error) => {
660
+ if (options.isVerbose) {
661
+ console.info(colors.bgRed('error'), error);
662
+ }
663
+ throw error;
664
+ });
665
+ */
666
+ if (options.isVerbose) {
667
+ console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
668
+ }
669
+ if (rawResponse.text === undefined) {
670
+ throw new PipelineExecutionError('No response message');
671
+ }
672
+ complete = $getCurrentDate();
673
+ usage = UNCERTAIN_USAGE;
674
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('createExecutionToolsFromVercelProvider ChatPromptResult', {
675
+ content: rawResponse.text,
676
+ modelName: modelName,
677
+ timing: {
678
+ start: start,
679
+ complete: complete,
680
+ },
681
+ usage: usage,
682
+ rawPromptContent: rawPromptContent,
683
+ rawRequest: rawRequest,
684
+ rawResponse: {
685
+ /* TODO: !!!!!! UnexpectedError: createExecutionToolsFromVercelProvider ChatPromptResult.rawResponse.response.timestamp is Date */
686
+ },
687
+ // <- [🗯]
688
+ })];
689
+ }
690
+ });
691
+ });
692
+ },
693
+ };
694
+ }
695
+
696
+ exports.BOOK_LANGUAGE_VERSION = BOOK_LANGUAGE_VERSION;
697
+ exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
698
+ exports.createExecutionToolsFromVercelProvider = createExecutionToolsFromVercelProvider;
699
+
700
+ Object.defineProperty(exports, '__esModule', { value: true });
29
701
 
30
702
  }));
31
703
  //# sourceMappingURL=index.umd.js.map