@promptbook/vercel 0.76.0 → 0.77.0-3

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 (32) hide show
  1. package/README.md +5 -1
  2. package/esm/index.es.js +673 -2
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/cli.index.d.ts +4 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +2 -0
  6. package/esm/typings/src/_packages/google.index.d.ts +10 -0
  7. package/esm/typings/src/_packages/types.index.d.ts +6 -0
  8. package/esm/typings/src/_packages/utils.index.d.ts +2 -2
  9. package/esm/typings/src/_packages/vercel.index.d.ts +4 -0
  10. package/esm/typings/src/execution/AvailableModel.d.ts +5 -1
  11. package/esm/typings/src/execution/CommonToolsOptions.d.ts +9 -0
  12. package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +1 -1
  13. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +1 -1
  14. package/esm/typings/src/llm-providers/google/GoogleExecutionToolsOptions.d.ts +12 -0
  15. package/esm/typings/src/llm-providers/google/createGoogleExecutionTools.d.ts +18 -0
  16. package/esm/typings/src/llm-providers/google/register-configuration.d.ts +13 -0
  17. package/esm/typings/src/llm-providers/google/register-constructor.d.ts +14 -0
  18. package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +1 -10
  19. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Request.d.ts +1 -1
  20. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Request.d.ts +1 -1
  21. package/esm/typings/src/llm-providers/remote/interfaces/RemoteLlmExecutionToolsOptions.d.ts +1 -1
  22. package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +1 -1
  23. package/esm/typings/src/llm-providers/vercel/VercelExecutionToolsOptions.d.ts +22 -0
  24. package/esm/typings/src/llm-providers/vercel/VercelProvider.d.ts +13 -0
  25. package/esm/typings/src/llm-providers/vercel/createExecutionToolsFromVercelProvider.d.ts +8 -0
  26. package/esm/typings/src/llm-providers/vercel/playground/playground.d.ts +6 -0
  27. package/esm/typings/src/utils/{$currentDate.d.ts → $getCurrentDate.d.ts} +1 -1
  28. package/package.json +6 -2
  29. package/umd/index.umd.js +701 -27
  30. package/umd/index.umd.js.map +1 -1
  31. package/esm/typings/src/_packages/gemini.index.d.ts +0 -2
  32. package/esm/typings/src/utils/getCurrentIsoDate.d.ts +0 -7
package/umd/index.umd.js CHANGED
@@ -1,31 +1,705 @@
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.77.0-2';
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
+ * This error indicates errors during the execution of the pipeline
151
+ *
152
+ * @public exported from `@promptbook/core`
153
+ */
154
+ var PipelineExecutionError = /** @class */ (function (_super) {
155
+ __extends(PipelineExecutionError, _super);
156
+ function PipelineExecutionError(message) {
157
+ var _this = _super.call(this, message) || this;
158
+ _this.name = 'PipelineExecutionError';
159
+ Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
160
+ return _this;
161
+ }
162
+ return PipelineExecutionError;
163
+ }(Error));
164
+
165
+ /**
166
+ * @@@
167
+ *
168
+ * Note: `$` is used to indicate that this function is not a pure function - it mutates given object
169
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
170
+ *
171
+ * @returns The same object as the input, but deeply frozen
172
+ * @public exported from `@promptbook/utils`
173
+ */
174
+ function $deepFreeze(objectValue) {
175
+ var e_1, _a;
176
+ var propertyNames = Object.getOwnPropertyNames(objectValue);
177
+ try {
178
+ for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
179
+ var propertyName = propertyNames_1_1.value;
180
+ var value = objectValue[propertyName];
181
+ if (value && typeof value === 'object') {
182
+ $deepFreeze(value);
183
+ }
184
+ }
185
+ }
186
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
187
+ finally {
188
+ try {
189
+ if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
190
+ }
191
+ finally { if (e_1) throw e_1.error; }
192
+ }
193
+ return Object.freeze(objectValue);
194
+ }
195
+ /**
196
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
197
+ */
198
+
199
+ /**
200
+ * Represents the usage with no resources consumed
201
+ *
202
+ * @public exported from `@promptbook/core`
203
+ */
204
+ $deepFreeze({
205
+ price: { value: 0 },
206
+ input: {
207
+ tokensCount: { value: 0 },
208
+ charactersCount: { value: 0 },
209
+ wordsCount: { value: 0 },
210
+ sentencesCount: { value: 0 },
211
+ linesCount: { value: 0 },
212
+ paragraphsCount: { value: 0 },
213
+ pagesCount: { value: 0 },
214
+ },
215
+ output: {
216
+ tokensCount: { value: 0 },
217
+ charactersCount: { value: 0 },
218
+ wordsCount: { value: 0 },
219
+ sentencesCount: { value: 0 },
220
+ linesCount: { value: 0 },
221
+ paragraphsCount: { value: 0 },
222
+ pagesCount: { value: 0 },
223
+ },
224
+ });
225
+ /**
226
+ * Represents the usage with unknown resources consumed
227
+ *
228
+ * @public exported from `@promptbook/core`
229
+ */
230
+ var UNCERTAIN_USAGE = $deepFreeze({
231
+ price: { value: 0, isUncertain: true },
232
+ input: {
233
+ tokensCount: { value: 0, isUncertain: true },
234
+ charactersCount: { value: 0, isUncertain: true },
235
+ wordsCount: { value: 0, isUncertain: true },
236
+ sentencesCount: { value: 0, isUncertain: true },
237
+ linesCount: { value: 0, isUncertain: true },
238
+ paragraphsCount: { value: 0, isUncertain: true },
239
+ pagesCount: { value: 0, isUncertain: true },
240
+ },
241
+ output: {
242
+ tokensCount: { value: 0, isUncertain: true },
243
+ charactersCount: { value: 0, isUncertain: true },
244
+ wordsCount: { value: 0, isUncertain: true },
245
+ sentencesCount: { value: 0, isUncertain: true },
246
+ linesCount: { value: 0, isUncertain: true },
247
+ paragraphsCount: { value: 0, isUncertain: true },
248
+ pagesCount: { value: 0, isUncertain: true },
249
+ },
250
+ });
251
+ /**
252
+ * Note: [💞] Ignore a discrepancy between file name and entity name
253
+ */
254
+
255
+ /**
256
+ * Simple wrapper `new Date().toISOString()`
257
+ *
258
+ * Note: `$` is used to indicate that this function is not a pure function - it is not deterministic because it depends on the current time
259
+ *
260
+ * @returns string_date branded type
261
+ * @public exported from `@promptbook/utils`
262
+ */
263
+ function $getCurrentDate() {
264
+ return new Date().toISOString();
265
+ }
266
+
267
+ /**
268
+ * This error type indicates that the error should not happen and its last check before crashing with some other error
269
+ *
270
+ * @public exported from `@promptbook/core`
271
+ */
272
+ var UnexpectedError = /** @class */ (function (_super) {
273
+ __extends(UnexpectedError, _super);
274
+ function UnexpectedError(message) {
275
+ 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;
276
+ _this.name = 'UnexpectedError';
277
+ Object.setPrototypeOf(_this, UnexpectedError.prototype);
278
+ return _this;
279
+ }
280
+ return UnexpectedError;
281
+ }(Error));
282
+
283
+ /**
284
+ * Checks if the value is [🚉] serializable as JSON
285
+ * If not, throws an UnexpectedError with a rich error message and tracking
286
+ *
287
+ * - Almost all primitives are serializable BUT:
288
+ * - `undefined` is not serializable
289
+ * - `NaN` is not serializable
290
+ * - Objects and arrays are serializable if all their properties are serializable
291
+ * - Functions are not serializable
292
+ * - Circular references are not serializable
293
+ * - `Date` objects are not serializable
294
+ * - `Map` and `Set` objects are not serializable
295
+ * - `RegExp` objects are not serializable
296
+ * - `Error` objects are not serializable
297
+ * - `Symbol` objects are not serializable
298
+ * - And much more...
299
+ *
300
+ * @throws UnexpectedError if the value is not serializable as JSON
301
+ * @public exported from `@promptbook/utils`
302
+ */
303
+ function checkSerializableAsJson(name, value) {
304
+ var e_1, _a;
305
+ if (value === undefined) {
306
+ throw new UnexpectedError("".concat(name, " is undefined"));
307
+ }
308
+ else if (value === null) {
309
+ return;
310
+ }
311
+ else if (typeof value === 'boolean') {
312
+ return;
313
+ }
314
+ else if (typeof value === 'number' && !isNaN(value)) {
315
+ return;
316
+ }
317
+ else if (typeof value === 'string') {
318
+ return;
319
+ }
320
+ else if (typeof value === 'symbol') {
321
+ throw new UnexpectedError("".concat(name, " is symbol"));
322
+ }
323
+ else if (typeof value === 'function') {
324
+ throw new UnexpectedError("".concat(name, " is function"));
325
+ }
326
+ else if (typeof value === 'object' && Array.isArray(value)) {
327
+ for (var i = 0; i < value.length; i++) {
328
+ checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
329
+ }
330
+ }
331
+ else if (typeof value === 'object') {
332
+ if (value instanceof Date) {
333
+ throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
334
+ }
335
+ else if (value instanceof Map) {
336
+ throw new UnexpectedError("".concat(name, " is Map"));
337
+ }
338
+ else if (value instanceof Set) {
339
+ throw new UnexpectedError("".concat(name, " is Set"));
340
+ }
341
+ else if (value instanceof RegExp) {
342
+ throw new UnexpectedError("".concat(name, " is RegExp"));
343
+ }
344
+ else if (value instanceof Error) {
345
+ throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
346
+ }
347
+ else {
348
+ try {
349
+ for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
350
+ var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
351
+ if (subValue === undefined) {
352
+ // Note: undefined in object is serializable - it is just omited
353
+ continue;
354
+ }
355
+ checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
356
+ }
357
+ }
358
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
359
+ finally {
360
+ try {
361
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
362
+ }
363
+ finally { if (e_1) throw e_1.error; }
364
+ }
365
+ try {
366
+ JSON.stringify(value); // <- TODO: [0]
367
+ }
368
+ catch (error) {
369
+ if (!(error instanceof Error)) {
370
+ throw error;
371
+ }
372
+ throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
373
+ }
374
+ /*
375
+ TODO: [0] Is there some more elegant way to check circular references?
376
+ const seen = new Set();
377
+ const stack = [{ value }];
378
+ while (stack.length > 0) {
379
+ const { value } = stack.pop()!;
380
+ if (typeof value === 'object' && value !== null) {
381
+ if (seen.has(value)) {
382
+ throw new UnexpectedError(`${name} has circular reference`);
383
+ }
384
+ seen.add(value);
385
+ if (Array.isArray(value)) {
386
+ stack.push(...value.map((value) => ({ value })));
387
+ } else {
388
+ stack.push(...Object.values(value).map((value) => ({ value })));
389
+ }
390
+ }
391
+ }
392
+ */
393
+ return;
394
+ }
395
+ }
396
+ else {
397
+ throw new UnexpectedError("".concat(name, " is unknown"));
398
+ }
399
+ }
400
+ /**
401
+ * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
402
+ * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
403
+ * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
404
+ */
405
+
406
+ /**
407
+ * @@@
408
+ * @@@
409
+ *
410
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
411
+ *
412
+ * @param name - Name of the object for debugging purposes
413
+ * @param objectValue - Object to be deeply frozen
414
+ * @returns The same object as the input, but deeply frozen
415
+ * @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
416
+ */
417
+ function $asDeeplyFrozenSerializableJson(name, objectValue) {
418
+ checkSerializableAsJson(name, objectValue);
419
+ return $deepFreeze(objectValue);
420
+ }
421
+ /**
422
+ * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
423
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
424
+ */
425
+
426
+ // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
427
+ /**
428
+ * The maximum number of iterations for a loops
429
+ *
430
+ * @private within the repository - too low-level in comparison with other `MAX_...`
431
+ */
432
+ var LOOP_LIMIT = 1000;
433
+ /**
434
+ * Nonce which is used for replacing things in strings
435
+ *
436
+ * @private within the repository
437
+ */
438
+ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
439
+ /**
440
+ * The names of the parameters that are reserved for special purposes
441
+ *
442
+ * @public exported from `@promptbook/core`
443
+ */
444
+ $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
445
+ 'content',
446
+ 'context',
447
+ 'knowledge',
448
+ 'examples',
449
+ 'modelName',
450
+ 'currentDate',
451
+ // <- TODO: list here all command names
452
+ // <- TODO: Add more like 'date', 'modelName',...
453
+ // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
454
+ ]);
455
+ /**
456
+ * @@@
457
+ *
458
+ * @private within the repository
459
+ */
460
+ var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
461
+ /**
462
+ * @@@
463
+ *
464
+ * @private within the repository
465
+ */
466
+ var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
467
+ // <- TODO: [🧜‍♂️]
468
+ /**
469
+ * @@@
470
+ *
471
+ * @public exported from `@promptbook/core`
472
+ */
473
+ Object.freeze({
474
+ delimiter: ',',
475
+ quoteChar: '"',
476
+ newline: '\n',
477
+ skipEmptyLines: true,
478
+ });
479
+ /**
480
+ * TODO: Extract `constants.ts` from `config.ts`
481
+ * Note: [💞] Ignore a discrepancy between file name and entity name
482
+ * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
483
+ */
484
+
485
+ /**
486
+ * This error type indicates that some limit was reached
487
+ *
488
+ * @public exported from `@promptbook/core`
489
+ */
490
+ var LimitReachedError = /** @class */ (function (_super) {
491
+ __extends(LimitReachedError, _super);
492
+ function LimitReachedError(message) {
493
+ var _this = _super.call(this, message) || this;
494
+ _this.name = 'LimitReachedError';
495
+ Object.setPrototypeOf(_this, LimitReachedError.prototype);
496
+ return _this;
497
+ }
498
+ return LimitReachedError;
499
+ }(Error));
500
+
501
+ /**
502
+ * Replaces parameters in template with values from parameters object
503
+ *
504
+ * @param template the template with parameters in {curly} braces
505
+ * @param parameters the object with parameters
506
+ * @returns the template with replaced parameters
507
+ * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
508
+ * @public exported from `@promptbook/utils`
509
+ */
510
+ function replaceParameters(template, parameters) {
511
+ var e_1, _a;
512
+ try {
513
+ for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
514
+ var _d = __read(_c.value, 2), parameterName = _d[0], parameterValue = _d[1];
515
+ if (parameterValue === RESERVED_PARAMETER_MISSING_VALUE) {
516
+ throw new UnexpectedError("Parameter `{".concat(parameterName, "}` has missing value"));
517
+ }
518
+ else if (parameterValue === RESERVED_PARAMETER_RESTRICTED) {
519
+ // TODO: [🍵]
520
+ throw new UnexpectedError("Parameter `{".concat(parameterName, "}` is restricted to use"));
521
+ }
522
+ }
523
+ }
524
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
525
+ finally {
526
+ try {
527
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
528
+ }
529
+ finally { if (e_1) throw e_1.error; }
530
+ }
531
+ var replacedTemplates = template;
532
+ var match;
533
+ var loopLimit = LOOP_LIMIT;
534
+ var _loop_1 = function () {
535
+ if (loopLimit-- < 0) {
536
+ throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
537
+ }
538
+ var precol = match.groups.precol;
539
+ var parameterName = match.groups.parameterName;
540
+ if (parameterName === '') {
541
+ return "continue";
542
+ }
543
+ if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
544
+ throw new PipelineExecutionError('Parameter is already opened or not closed');
545
+ }
546
+ if (parameters[parameterName] === undefined) {
547
+ throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
548
+ }
549
+ var parameterValue = parameters[parameterName];
550
+ if (parameterValue === undefined) {
551
+ throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
552
+ }
553
+ parameterValue = parameterValue.toString();
554
+ if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
555
+ parameterValue = parameterValue
556
+ .split('\n')
557
+ .map(function (line, index) { return (index === 0 ? line : "".concat(precol).concat(line)); })
558
+ .join('\n');
559
+ }
560
+ replacedTemplates =
561
+ replacedTemplates.substring(0, match.index + precol.length) +
562
+ parameterValue +
563
+ replacedTemplates.substring(match.index + precol.length + parameterName.length + 2);
564
+ };
565
+ while ((match = /^(?<precol>.*){(?<parameterName>\w+)}(.*)/m /* <- Not global */
566
+ .exec(replacedTemplates))) {
567
+ _loop_1();
568
+ }
569
+ // [💫] Check if there are parameters that are not closed properly
570
+ if (/{\w+$/.test(replacedTemplates)) {
571
+ throw new PipelineExecutionError('Parameter is not closed');
572
+ }
573
+ // [💫] Check if there are parameters that are not opened properly
574
+ if (/^\w+}/.test(replacedTemplates)) {
575
+ throw new PipelineExecutionError('Parameter is not opened');
576
+ }
577
+ return replacedTemplates;
578
+ }
579
+
580
+ /**
581
+ * !!!!!!
582
+ *
583
+ * @public exported from `@promptbook/vercel`
584
+ */
585
+ function createExecutionToolsFromVercelProvider(options) {
586
+ var vercelProvider = options.vercelProvider, availableModels = options.availableModels, userId = options.userId, _a = options.additionalChatSettings, additionalChatSettings = _a === void 0 ? {} : _a;
587
+ return {
588
+ title: '!!!',
589
+ description: "!!! (through Vercel)",
590
+ checkConfiguration: function () {
591
+ // TODO: !!!!!!
592
+ return Promise.resolve();
593
+ },
594
+ listModels: function () {
595
+ return __awaiter(this, void 0, void 0, function () {
596
+ return __generator(this, function (_a) {
597
+ return [2 /*return*/, availableModels];
598
+ });
599
+ });
600
+ },
601
+ callChatModel: function (prompt) {
602
+ var _a;
603
+ return __awaiter(this, void 0, void 0, function () {
604
+ var content, parameters, modelRequirements, modelName, model, rawPromptContent, rawRequest, start, rawResponse, complete, usage;
605
+ return __generator(this, function (_b) {
606
+ switch (_b.label) {
607
+ case 0:
608
+ content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
609
+ if (modelRequirements.modelVariant !== 'CHAT') {
610
+ throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
611
+ }
612
+ modelName = modelRequirements.modelName ||
613
+ ((_a = availableModels.find(function (_a) {
614
+ var modelVariant = _a.modelVariant;
615
+ return modelVariant === 'CHAT';
616
+ })) === null || _a === void 0 ? void 0 : _a.modelName);
617
+ if (!modelName) {
618
+ throw new PipelineExecutionError(spaceTrim__default["default"]("\n Can not determine which model to use.\n\n You need to provide at least one of:\n 1) In `createExecutionToolsFromVercelProvider` options, provide `availableModels` with at least one model\n 2) In `prompt.modelRequirements`, provide `modelName` with the name of the model to use\n \n "));
619
+ }
620
+ return [4 /*yield*/, vercelProvider.chat(modelName, __assign({ user: (userId === null || userId === void 0 ? void 0 : userId.toString()) || undefined }, additionalChatSettings))];
621
+ case 1:
622
+ model = _b.sent();
623
+ rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
624
+ rawRequest = {
625
+ // <- TODO: [☂]
626
+ inputFormat: 'messages',
627
+ mode: {
628
+ type: 'regular',
629
+ tools: [
630
+ /* !!!!!! */
631
+ ],
632
+ },
633
+ prompt: __spreadArray(__spreadArray([], __read((modelRequirements.systemMessage === undefined
634
+ ? []
635
+ : [
636
+ {
637
+ role: 'system',
638
+ content: modelRequirements.systemMessage,
639
+ },
640
+ ])), false), [
641
+ {
642
+ role: 'user',
643
+ content: [
644
+ {
645
+ type: 'text',
646
+ text: rawPromptContent,
647
+ },
648
+ ],
649
+ },
650
+ ], false),
651
+ };
652
+ start = $getCurrentDate();
653
+ if (options.isVerbose) {
654
+ console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
655
+ }
656
+ return [4 /*yield*/, model.doGenerate(rawRequest)];
657
+ case 2:
658
+ rawResponse = _b.sent();
659
+ /*
660
+ TODO: !!!!!! Handle errors
661
+ .catch((error) => {
662
+ if (options.isVerbose) {
663
+ console.info(colors.bgRed('error'), error);
664
+ }
665
+ throw error;
666
+ });
667
+ */
668
+ if (options.isVerbose) {
669
+ console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
670
+ }
671
+ if (rawResponse.text === undefined) {
672
+ throw new PipelineExecutionError('No response message');
673
+ }
674
+ complete = $getCurrentDate();
675
+ usage = UNCERTAIN_USAGE;
676
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('createExecutionToolsFromVercelProvider ChatPromptResult', {
677
+ content: rawResponse.text,
678
+ modelName: modelName,
679
+ timing: {
680
+ start: start,
681
+ complete: complete,
682
+ },
683
+ usage: usage,
684
+ rawPromptContent: rawPromptContent,
685
+ rawRequest: rawRequest,
686
+ rawResponse: {
687
+ /* TODO: !!!!!! UnexpectedError: createExecutionToolsFromVercelProvider ChatPromptResult.rawResponse.response.timestamp is Date */
688
+ },
689
+ // <- [🗯]
690
+ })];
691
+ }
692
+ });
693
+ });
694
+ },
695
+ };
696
+ }
697
+
698
+ exports.BOOK_LANGUAGE_VERSION = BOOK_LANGUAGE_VERSION;
699
+ exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
700
+ exports.createExecutionToolsFromVercelProvider = createExecutionToolsFromVercelProvider;
701
+
702
+ Object.defineProperty(exports, '__esModule', { value: true });
29
703
 
30
704
  }));
31
705
  //# sourceMappingURL=index.umd.js.map