@promptbook/cli 0.78.0-0 → 0.78.2
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/README.md +0 -4
- package/esm/index.es.js +416 -374
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- package/esm/typings/src/config.d.ts +14 -0
- package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +6 -0
- package/esm/typings/src/execution/execution-report/ExecutionReportString.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineString.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +244 -202
- package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js
CHANGED
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
*
|
|
50
50
|
* @see https://github.com/webgptorg/promptbook
|
|
51
51
|
*/
|
|
52
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
52
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.78.1';
|
|
53
53
|
/**
|
|
54
54
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
55
55
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -195,204 +195,31 @@
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
/**
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
201
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
202
|
-
*
|
|
203
|
-
* @returns The same object as the input, but deeply frozen
|
|
204
|
-
* @public exported from `@promptbook/utils`
|
|
205
|
-
*/
|
|
206
|
-
function $deepFreeze(objectValue) {
|
|
207
|
-
var e_1, _a;
|
|
208
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
209
|
-
try {
|
|
210
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
211
|
-
var propertyName = propertyNames_1_1.value;
|
|
212
|
-
var value = objectValue[propertyName];
|
|
213
|
-
if (value && typeof value === 'object') {
|
|
214
|
-
$deepFreeze(value);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
219
|
-
finally {
|
|
220
|
-
try {
|
|
221
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
222
|
-
}
|
|
223
|
-
finally { if (e_1) throw e_1.error; }
|
|
224
|
-
}
|
|
225
|
-
return Object.freeze(objectValue);
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
229
|
-
*/
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
198
|
+
* Warning message for the generated sections and files files
|
|
233
199
|
*
|
|
234
|
-
* @
|
|
200
|
+
* @private within the repository
|
|
235
201
|
*/
|
|
236
|
-
var
|
|
237
|
-
__extends(UnexpectedError, _super);
|
|
238
|
-
function UnexpectedError(message) {
|
|
239
|
-
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;
|
|
240
|
-
_this.name = 'UnexpectedError';
|
|
241
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
242
|
-
return _this;
|
|
243
|
-
}
|
|
244
|
-
return UnexpectedError;
|
|
245
|
-
}(Error));
|
|
246
|
-
|
|
202
|
+
var GENERATOR_WARNING = "\u26A0\uFE0F WARNING: This code has been generated so that any manual changes will be overwritten";
|
|
247
203
|
/**
|
|
248
|
-
*
|
|
249
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
204
|
+
* Name for the Promptbook
|
|
250
205
|
*
|
|
251
|
-
*
|
|
252
|
-
* - `undefined` is not serializable
|
|
253
|
-
* - `NaN` is not serializable
|
|
254
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
255
|
-
* - Functions are not serializable
|
|
256
|
-
* - Circular references are not serializable
|
|
257
|
-
* - `Date` objects are not serializable
|
|
258
|
-
* - `Map` and `Set` objects are not serializable
|
|
259
|
-
* - `RegExp` objects are not serializable
|
|
260
|
-
* - `Error` objects are not serializable
|
|
261
|
-
* - `Symbol` objects are not serializable
|
|
262
|
-
* - And much more...
|
|
206
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
263
207
|
*
|
|
264
|
-
* @
|
|
265
|
-
* @public exported from `@promptbook/utils`
|
|
266
|
-
*/
|
|
267
|
-
function checkSerializableAsJson(name, value) {
|
|
268
|
-
var e_1, _a;
|
|
269
|
-
if (value === undefined) {
|
|
270
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
271
|
-
}
|
|
272
|
-
else if (value === null) {
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
else if (typeof value === 'boolean') {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
else if (typeof value === 'string') {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
else if (typeof value === 'symbol') {
|
|
285
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
286
|
-
}
|
|
287
|
-
else if (typeof value === 'function') {
|
|
288
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
289
|
-
}
|
|
290
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
291
|
-
for (var i = 0; i < value.length; i++) {
|
|
292
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
else if (typeof value === 'object') {
|
|
296
|
-
if (value instanceof Date) {
|
|
297
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
298
|
-
}
|
|
299
|
-
else if (value instanceof Map) {
|
|
300
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
301
|
-
}
|
|
302
|
-
else if (value instanceof Set) {
|
|
303
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
304
|
-
}
|
|
305
|
-
else if (value instanceof RegExp) {
|
|
306
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
307
|
-
}
|
|
308
|
-
else if (value instanceof Error) {
|
|
309
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
try {
|
|
313
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
314
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
315
|
-
if (subValue === undefined) {
|
|
316
|
-
// Note: undefined in object is serializable - it is just omited
|
|
317
|
-
continue;
|
|
318
|
-
}
|
|
319
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
323
|
-
finally {
|
|
324
|
-
try {
|
|
325
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
326
|
-
}
|
|
327
|
-
finally { if (e_1) throw e_1.error; }
|
|
328
|
-
}
|
|
329
|
-
try {
|
|
330
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
331
|
-
}
|
|
332
|
-
catch (error) {
|
|
333
|
-
if (!(error instanceof Error)) {
|
|
334
|
-
throw error;
|
|
335
|
-
}
|
|
336
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
337
|
-
}
|
|
338
|
-
/*
|
|
339
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
340
|
-
const seen = new Set();
|
|
341
|
-
const stack = [{ value }];
|
|
342
|
-
while (stack.length > 0) {
|
|
343
|
-
const { value } = stack.pop()!;
|
|
344
|
-
if (typeof value === 'object' && value !== null) {
|
|
345
|
-
if (seen.has(value)) {
|
|
346
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
347
|
-
}
|
|
348
|
-
seen.add(value);
|
|
349
|
-
if (Array.isArray(value)) {
|
|
350
|
-
stack.push(...value.map((value) => ({ value })));
|
|
351
|
-
} else {
|
|
352
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
*/
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
else {
|
|
361
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
366
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
367
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
208
|
+
* @public exported from `@promptbook/core`
|
|
368
209
|
*/
|
|
369
|
-
|
|
210
|
+
var NAME = "Promptbook";
|
|
370
211
|
/**
|
|
371
|
-
*
|
|
372
|
-
* @@@
|
|
212
|
+
* Email of the responsible person
|
|
373
213
|
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
* @param name - Name of the object for debugging purposes
|
|
377
|
-
* @param objectValue - Object to be deeply frozen
|
|
378
|
-
* @returns The same object as the input, but deeply frozen
|
|
379
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
380
|
-
*/
|
|
381
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
382
|
-
checkSerializableAsJson(name, objectValue);
|
|
383
|
-
return $deepFreeze(objectValue);
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
387
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
214
|
+
* @public exported from `@promptbook/core`
|
|
388
215
|
*/
|
|
389
|
-
|
|
216
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
390
217
|
/**
|
|
391
|
-
*
|
|
218
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
392
219
|
*
|
|
393
|
-
* @
|
|
220
|
+
* @public exported from `@promptbook/core`
|
|
394
221
|
*/
|
|
395
|
-
var
|
|
222
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
396
223
|
/**
|
|
397
224
|
* Claim for the Promptbook
|
|
398
225
|
*
|
|
@@ -504,7 +331,8 @@
|
|
|
504
331
|
*
|
|
505
332
|
* @public exported from `@promptbook/core`
|
|
506
333
|
*/
|
|
507
|
-
var RESERVED_PARAMETER_NAMES =
|
|
334
|
+
var RESERVED_PARAMETER_NAMES =
|
|
335
|
+
/* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
|
|
508
336
|
'content',
|
|
509
337
|
'context',
|
|
510
338
|
'knowledge',
|
|
@@ -514,7 +342,7 @@
|
|
|
514
342
|
// <- TODO: list here all command names
|
|
515
343
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
516
344
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
517
|
-
]
|
|
345
|
+
];
|
|
518
346
|
/**
|
|
519
347
|
* @@@
|
|
520
348
|
*
|
|
@@ -708,6 +536,163 @@
|
|
|
708
536
|
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
709
537
|
*/
|
|
710
538
|
|
|
539
|
+
/**
|
|
540
|
+
* Make error report URL for the given error
|
|
541
|
+
*
|
|
542
|
+
* @private !!!!!!
|
|
543
|
+
*/
|
|
544
|
+
function getErrorReportUrl(error) {
|
|
545
|
+
var report = {
|
|
546
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
547
|
+
body: spaceTrim__default["default"](function (block) { return "\n\n\n `".concat(error.name || 'Error', "` has occurred in the [").concat(NAME, "], please look into it @").concat(ADMIN_GITHUB_NAME, ".\n\n ```\n ").concat(block(error.message || '(no error message)'), "\n ```\n\n\n ## More info:\n\n - **Promptbook engine version:** ").concat(PROMPTBOOK_ENGINE_VERSION, "\n - **Book language version:** ").concat(BOOK_LANGUAGE_VERSION, "\n - **Time:** ").concat(new Date().toISOString(), "\n\n <details>\n <summary>Stack trace:</summary>\n\n ## Stack trace:\n\n ```stacktrace\n ").concat(block(error.stack || '(empty)'), "\n ```\n </details>\n\n "); }),
|
|
548
|
+
};
|
|
549
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
550
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
551
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
552
|
+
reportUrl.searchParams.set('title', report.title);
|
|
553
|
+
reportUrl.searchParams.set('body', report.body);
|
|
554
|
+
return reportUrl;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
559
|
+
*
|
|
560
|
+
* @public exported from `@promptbook/core`
|
|
561
|
+
*/
|
|
562
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
563
|
+
__extends(UnexpectedError, _super);
|
|
564
|
+
function UnexpectedError(message) {
|
|
565
|
+
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 ").concat(block(getErrorReportUrl(new Error(message)).href), "\n\n Or contact us on ").concat(ADMIN_EMAIL, "\n\n "); })) || this;
|
|
566
|
+
_this.name = 'UnexpectedError';
|
|
567
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
568
|
+
return _this;
|
|
569
|
+
}
|
|
570
|
+
return UnexpectedError;
|
|
571
|
+
}(Error));
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
575
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
576
|
+
*
|
|
577
|
+
* - Almost all primitives are serializable BUT:
|
|
578
|
+
* - `undefined` is not serializable
|
|
579
|
+
* - `NaN` is not serializable
|
|
580
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
581
|
+
* - Functions are not serializable
|
|
582
|
+
* - Circular references are not serializable
|
|
583
|
+
* - `Date` objects are not serializable
|
|
584
|
+
* - `Map` and `Set` objects are not serializable
|
|
585
|
+
* - `RegExp` objects are not serializable
|
|
586
|
+
* - `Error` objects are not serializable
|
|
587
|
+
* - `Symbol` objects are not serializable
|
|
588
|
+
* - And much more...
|
|
589
|
+
*
|
|
590
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
591
|
+
* @public exported from `@promptbook/utils`
|
|
592
|
+
*/
|
|
593
|
+
function checkSerializableAsJson(name, value) {
|
|
594
|
+
var e_1, _a;
|
|
595
|
+
if (value === undefined) {
|
|
596
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
597
|
+
}
|
|
598
|
+
else if (value === null) {
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
else if (typeof value === 'boolean') {
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
else if (typeof value === 'string') {
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
else if (typeof value === 'symbol') {
|
|
611
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
612
|
+
}
|
|
613
|
+
else if (typeof value === 'function') {
|
|
614
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
615
|
+
}
|
|
616
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
617
|
+
for (var i = 0; i < value.length; i++) {
|
|
618
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
else if (typeof value === 'object') {
|
|
622
|
+
if (value instanceof Date) {
|
|
623
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
624
|
+
}
|
|
625
|
+
else if (value instanceof Map) {
|
|
626
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
627
|
+
}
|
|
628
|
+
else if (value instanceof Set) {
|
|
629
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
630
|
+
}
|
|
631
|
+
else if (value instanceof RegExp) {
|
|
632
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
633
|
+
}
|
|
634
|
+
else if (value instanceof Error) {
|
|
635
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
try {
|
|
639
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
640
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
641
|
+
if (subValue === undefined) {
|
|
642
|
+
// Note: undefined in object is serializable - it is just omited
|
|
643
|
+
continue;
|
|
644
|
+
}
|
|
645
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
649
|
+
finally {
|
|
650
|
+
try {
|
|
651
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
652
|
+
}
|
|
653
|
+
finally { if (e_1) throw e_1.error; }
|
|
654
|
+
}
|
|
655
|
+
try {
|
|
656
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
657
|
+
}
|
|
658
|
+
catch (error) {
|
|
659
|
+
if (!(error instanceof Error)) {
|
|
660
|
+
throw error;
|
|
661
|
+
}
|
|
662
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
663
|
+
}
|
|
664
|
+
/*
|
|
665
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
666
|
+
const seen = new Set();
|
|
667
|
+
const stack = [{ value }];
|
|
668
|
+
while (stack.length > 0) {
|
|
669
|
+
const { value } = stack.pop()!;
|
|
670
|
+
if (typeof value === 'object' && value !== null) {
|
|
671
|
+
if (seen.has(value)) {
|
|
672
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
673
|
+
}
|
|
674
|
+
seen.add(value);
|
|
675
|
+
if (Array.isArray(value)) {
|
|
676
|
+
stack.push(...value.map((value) => ({ value })));
|
|
677
|
+
} else {
|
|
678
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
*/
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
else {
|
|
687
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
692
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
693
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
694
|
+
*/
|
|
695
|
+
|
|
711
696
|
/**
|
|
712
697
|
* Tests if the value is [🚉] serializable as JSON
|
|
713
698
|
*
|
|
@@ -1550,6 +1535,40 @@
|
|
|
1550
1535
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1551
1536
|
*/
|
|
1552
1537
|
|
|
1538
|
+
/**
|
|
1539
|
+
* @@@
|
|
1540
|
+
*
|
|
1541
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
1542
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1543
|
+
*
|
|
1544
|
+
* @returns The same object as the input, but deeply frozen
|
|
1545
|
+
* @public exported from `@promptbook/utils`
|
|
1546
|
+
*/
|
|
1547
|
+
function $deepFreeze(objectValue) {
|
|
1548
|
+
var e_1, _a;
|
|
1549
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1550
|
+
try {
|
|
1551
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
1552
|
+
var propertyName = propertyNames_1_1.value;
|
|
1553
|
+
var value = objectValue[propertyName];
|
|
1554
|
+
if (value && typeof value === 'object') {
|
|
1555
|
+
$deepFreeze(value);
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1560
|
+
finally {
|
|
1561
|
+
try {
|
|
1562
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
1563
|
+
}
|
|
1564
|
+
finally { if (e_1) throw e_1.error; }
|
|
1565
|
+
}
|
|
1566
|
+
return Object.freeze(objectValue);
|
|
1567
|
+
}
|
|
1568
|
+
/**
|
|
1569
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1570
|
+
*/
|
|
1571
|
+
|
|
1553
1572
|
/**
|
|
1554
1573
|
* Represents the usage with no resources consumed
|
|
1555
1574
|
*
|
|
@@ -3397,6 +3416,26 @@
|
|
|
3397
3416
|
return parameterNames;
|
|
3398
3417
|
}
|
|
3399
3418
|
|
|
3419
|
+
/**
|
|
3420
|
+
* @@@
|
|
3421
|
+
* @@@
|
|
3422
|
+
*
|
|
3423
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
3424
|
+
*
|
|
3425
|
+
* @param name - Name of the object for debugging purposes
|
|
3426
|
+
* @param objectValue - Object to be deeply frozen
|
|
3427
|
+
* @returns The same object as the input, but deeply frozen
|
|
3428
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
3429
|
+
*/
|
|
3430
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
3431
|
+
checkSerializableAsJson(name, objectValue);
|
|
3432
|
+
return $deepFreeze(objectValue);
|
|
3433
|
+
}
|
|
3434
|
+
/**
|
|
3435
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
3436
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
3437
|
+
*/
|
|
3438
|
+
|
|
3400
3439
|
/**
|
|
3401
3440
|
* Unprepare just strips the preparation data of the pipeline
|
|
3402
3441
|
*
|
|
@@ -3790,6 +3829,7 @@
|
|
|
3790
3829
|
*/
|
|
3791
3830
|
function extractVariablesFromScript(script) {
|
|
3792
3831
|
var variables = new Set();
|
|
3832
|
+
var originalScript = script;
|
|
3793
3833
|
script = "(()=>{".concat(script, "})()");
|
|
3794
3834
|
try {
|
|
3795
3835
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
@@ -3821,7 +3861,9 @@
|
|
|
3821
3861
|
if (!(error instanceof Error)) {
|
|
3822
3862
|
throw error;
|
|
3823
3863
|
}
|
|
3824
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n
|
|
3864
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n\n\n Found variables:\n\n ").concat(Array.from(variables)
|
|
3865
|
+
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
3866
|
+
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
3825
3867
|
}
|
|
3826
3868
|
return variables;
|
|
3827
3869
|
}
|
|
@@ -6727,7 +6769,7 @@
|
|
|
6727
6769
|
throw new ParseError(spaceTrim__default["default"]("\n Section type is already defined in the section.\n It can be defined only once.\n "));
|
|
6728
6770
|
}
|
|
6729
6771
|
$taskJson.isSectionTypeSet = true;
|
|
6730
|
-
// TODO: [🍧] Rearrange better - but at bottom and unwrap from function
|
|
6772
|
+
// TODO: [🍧][💩] Rearrange better - but at bottom and unwrap from function
|
|
6731
6773
|
var expectResultingParameterName = function () {
|
|
6732
6774
|
if ($taskJson.resultingParameterName) {
|
|
6733
6775
|
return;
|
|
@@ -8013,7 +8055,7 @@
|
|
|
8013
8055
|
if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
|
|
8014
8056
|
if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
|
|
8015
8057
|
console.warn("Multiple commands `MODEL ".concat(command.key, " ").concat(command.value, "` in the pipeline head"));
|
|
8016
|
-
// <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
|
|
8058
|
+
// <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
|
|
8017
8059
|
}
|
|
8018
8060
|
else {
|
|
8019
8061
|
throw new ParseError(spaceTrim__default["default"]("\n Redefinition of MODEL `".concat(command.key, "` in the pipeline head\n\n You have used:\n - MODEL ").concat(command.key, " ").concat($pipelineJson.defaultModelRequirements[command.key], "\n - MODEL ").concat(command.key, " ").concat(command.value, "\n ")));
|
|
@@ -8648,7 +8690,7 @@
|
|
|
8648
8690
|
personaCommandParser,
|
|
8649
8691
|
foreachCommandParser,
|
|
8650
8692
|
boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
|
|
8651
|
-
// <- Note: [♓️] This is the order of the commands in the pipeline, BUT its not used in parsing and before usage maybe it should be done better
|
|
8693
|
+
// <- Note: [♓️][💩] This is the order of the commands in the pipeline, BUT its not used in parsing and before usage maybe it should be done better
|
|
8652
8694
|
];
|
|
8653
8695
|
/**
|
|
8654
8696
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -10104,10 +10146,10 @@
|
|
|
10104
10146
|
return __generator(this, function (_a) {
|
|
10105
10147
|
switch (_a.label) {
|
|
10106
10148
|
case 0:
|
|
10107
|
-
// TODO: Change to `await forEver` or something better
|
|
10149
|
+
// TODO: [💩] Change to `await forEver` or something better
|
|
10108
10150
|
return [4 /*yield*/, waitasecond.forTime(100000000)];
|
|
10109
10151
|
case 1:
|
|
10110
|
-
// TODO: Change to `await forEver` or something better
|
|
10152
|
+
// TODO: [💩] Change to `await forEver` or something better
|
|
10111
10153
|
_a.sent();
|
|
10112
10154
|
_a.label = 2;
|
|
10113
10155
|
case 2:
|
|
@@ -11061,11 +11103,11 @@
|
|
|
11061
11103
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
11062
11104
|
if (placeForSection !== null) {
|
|
11063
11105
|
var _a = __read(placeForSection, 1), heading_1 = _a[0];
|
|
11064
|
-
return content.replace(heading_1, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(contentToInsert), "\n
|
|
11106
|
+
return content.replace(heading_1, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(contentToInsert), "\n\n ").concat(block(heading_1), "\n "); }));
|
|
11065
11107
|
}
|
|
11066
11108
|
console.warn("No place where to put the section <!--".concat(sectionName, "-->, using the end of the file"));
|
|
11067
|
-
// <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
|
|
11068
|
-
return spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(content), "\n
|
|
11109
|
+
// <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
|
|
11110
|
+
return spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(content), "\n\n ").concat(block(contentToInsert), "\n "); });
|
|
11069
11111
|
}
|
|
11070
11112
|
/**
|
|
11071
11113
|
* TODO: [🏛] This can be part of markdown builder
|
|
@@ -11490,7 +11532,7 @@
|
|
|
11490
11532
|
'\n\n' +
|
|
11491
11533
|
executionReportJson.promptExecutions
|
|
11492
11534
|
.map(function (promptExecution) {
|
|
11493
|
-
// TODO: Make some better system to convert
|
|
11535
|
+
// TODO: [💩] Make some better system to convert headings to links
|
|
11494
11536
|
var hash = normalizeToKebabCase(promptExecution.prompt.title);
|
|
11495
11537
|
if (/^\s*\p{Extended_Pictographic}/u.test(promptExecution.prompt.title)) {
|
|
11496
11538
|
hash = '-' + hash;
|
|
@@ -12258,7 +12300,7 @@
|
|
|
12258
12300
|
socket.on('connect', function () {
|
|
12259
12301
|
resolve(socket);
|
|
12260
12302
|
});
|
|
12261
|
-
// TODO: [
|
|
12303
|
+
// TODO: [💩] Better timeout handling
|
|
12262
12304
|
setTimeout(function () {
|
|
12263
12305
|
reject(new Error("Timeout while connecting to ".concat(_this.options.remoteUrl)));
|
|
12264
12306
|
}, CONNECTION_TIMEOUT_MS);
|
|
@@ -13236,7 +13278,7 @@
|
|
|
13236
13278
|
modelVariant: 'CHAT',
|
|
13237
13279
|
modelTitle: 'o1-preview-2024-09-12',
|
|
13238
13280
|
modelName: 'o1-preview-2024-09-12',
|
|
13239
|
-
// <- TODO: [
|
|
13281
|
+
// <- TODO: [💩] Some better system to organize theese date suffixes and versions
|
|
13240
13282
|
pricing: {
|
|
13241
13283
|
prompt: computeUsage("$15.00 / 1M tokens"),
|
|
13242
13284
|
output: computeUsage("$60.00 / 1M tokens"),
|
|
@@ -13286,7 +13328,7 @@
|
|
|
13286
13328
|
* @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
|
|
13287
13329
|
* @see https://openai.com/api/pricing/
|
|
13288
13330
|
* @see /other/playground/playground.ts
|
|
13289
|
-
* TODO: [🍓] Make better
|
|
13331
|
+
* TODO: [🍓][💩] Make better
|
|
13290
13332
|
* TODO: Change model titles to human eg: "gpt-4-turbo-2024-04-09" -> "GPT-4 Turbo (2024-04-09)"
|
|
13291
13333
|
* TODO: [🚸] Not all models are compatible with JSON mode, add this information here and use it
|
|
13292
13334
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|