@promptbook/core 0.77.1 → 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/esm/index.es.js +353 -209
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +10 -0
- package/esm/typings/src/_packages/types.index.d.ts +4 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -8
- package/esm/typings/src/commands/_common/types/CommandType.d.ts +17 -0
- package/esm/typings/src/config.d.ts +14 -0
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTask.d.ts +1 -1
- package/esm/typings/src/conversion/utils/{extractVariables.d.ts → extractVariablesFromScript.d.ts} +2 -2
- package/esm/typings/src/conversion/utils/removePipelineCommand.d.ts +22 -0
- package/esm/typings/src/conversion/utils/{renameParameter.d.ts → renamePipelineParameter.d.ts} +3 -3
- 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/esm/typings/src/utils/normalization/titleToName.test.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +357 -208
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/conversion/utils/{extractVariables.test.d.ts → extractVariablesFromScript.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/utils/{renameParameter.test.d.ts → removePipelineCommand.test.d.ts} +0 -0
- /package/esm/typings/src/conversion/utils/{titleToName.test.d.ts → renamePipelineParameter.test.d.ts} +0 -0
- /package/esm/typings/src/{conversion/utils → utils/normalization}/titleToName.d.ts +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
28
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.78.1';
|
|
29
29
|
/**
|
|
30
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
31
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -446,199 +446,6 @@
|
|
|
446
446
|
return value;
|
|
447
447
|
}
|
|
448
448
|
|
|
449
|
-
/**
|
|
450
|
-
* @@@
|
|
451
|
-
*
|
|
452
|
-
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
453
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
454
|
-
*
|
|
455
|
-
* @returns The same object as the input, but deeply frozen
|
|
456
|
-
* @public exported from `@promptbook/utils`
|
|
457
|
-
*/
|
|
458
|
-
function $deepFreeze(objectValue) {
|
|
459
|
-
var e_1, _a;
|
|
460
|
-
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
461
|
-
try {
|
|
462
|
-
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
463
|
-
var propertyName = propertyNames_1_1.value;
|
|
464
|
-
var value = objectValue[propertyName];
|
|
465
|
-
if (value && typeof value === 'object') {
|
|
466
|
-
$deepFreeze(value);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
471
|
-
finally {
|
|
472
|
-
try {
|
|
473
|
-
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
474
|
-
}
|
|
475
|
-
finally { if (e_1) throw e_1.error; }
|
|
476
|
-
}
|
|
477
|
-
return Object.freeze(objectValue);
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
481
|
-
*/
|
|
482
|
-
|
|
483
|
-
/**
|
|
484
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
485
|
-
*
|
|
486
|
-
* @public exported from `@promptbook/core`
|
|
487
|
-
*/
|
|
488
|
-
var UnexpectedError = /** @class */ (function (_super) {
|
|
489
|
-
__extends(UnexpectedError, _super);
|
|
490
|
-
function UnexpectedError(message) {
|
|
491
|
-
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;
|
|
492
|
-
_this.name = 'UnexpectedError';
|
|
493
|
-
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
494
|
-
return _this;
|
|
495
|
-
}
|
|
496
|
-
return UnexpectedError;
|
|
497
|
-
}(Error));
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Checks if the value is [🚉] serializable as JSON
|
|
501
|
-
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
502
|
-
*
|
|
503
|
-
* - Almost all primitives are serializable BUT:
|
|
504
|
-
* - `undefined` is not serializable
|
|
505
|
-
* - `NaN` is not serializable
|
|
506
|
-
* - Objects and arrays are serializable if all their properties are serializable
|
|
507
|
-
* - Functions are not serializable
|
|
508
|
-
* - Circular references are not serializable
|
|
509
|
-
* - `Date` objects are not serializable
|
|
510
|
-
* - `Map` and `Set` objects are not serializable
|
|
511
|
-
* - `RegExp` objects are not serializable
|
|
512
|
-
* - `Error` objects are not serializable
|
|
513
|
-
* - `Symbol` objects are not serializable
|
|
514
|
-
* - And much more...
|
|
515
|
-
*
|
|
516
|
-
* @throws UnexpectedError if the value is not serializable as JSON
|
|
517
|
-
* @public exported from `@promptbook/utils`
|
|
518
|
-
*/
|
|
519
|
-
function checkSerializableAsJson(name, value) {
|
|
520
|
-
var e_1, _a;
|
|
521
|
-
if (value === undefined) {
|
|
522
|
-
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
523
|
-
}
|
|
524
|
-
else if (value === null) {
|
|
525
|
-
return;
|
|
526
|
-
}
|
|
527
|
-
else if (typeof value === 'boolean') {
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
else if (typeof value === 'number' && !isNaN(value)) {
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
|
-
else if (typeof value === 'string') {
|
|
534
|
-
return;
|
|
535
|
-
}
|
|
536
|
-
else if (typeof value === 'symbol') {
|
|
537
|
-
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
538
|
-
}
|
|
539
|
-
else if (typeof value === 'function') {
|
|
540
|
-
throw new UnexpectedError("".concat(name, " is function"));
|
|
541
|
-
}
|
|
542
|
-
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
543
|
-
for (var i = 0; i < value.length; i++) {
|
|
544
|
-
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
else if (typeof value === 'object') {
|
|
548
|
-
if (value instanceof Date) {
|
|
549
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
550
|
-
}
|
|
551
|
-
else if (value instanceof Map) {
|
|
552
|
-
throw new UnexpectedError("".concat(name, " is Map"));
|
|
553
|
-
}
|
|
554
|
-
else if (value instanceof Set) {
|
|
555
|
-
throw new UnexpectedError("".concat(name, " is Set"));
|
|
556
|
-
}
|
|
557
|
-
else if (value instanceof RegExp) {
|
|
558
|
-
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
559
|
-
}
|
|
560
|
-
else if (value instanceof Error) {
|
|
561
|
-
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
562
|
-
}
|
|
563
|
-
else {
|
|
564
|
-
try {
|
|
565
|
-
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
566
|
-
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
567
|
-
if (subValue === undefined) {
|
|
568
|
-
// Note: undefined in object is serializable - it is just omited
|
|
569
|
-
continue;
|
|
570
|
-
}
|
|
571
|
-
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
575
|
-
finally {
|
|
576
|
-
try {
|
|
577
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
578
|
-
}
|
|
579
|
-
finally { if (e_1) throw e_1.error; }
|
|
580
|
-
}
|
|
581
|
-
try {
|
|
582
|
-
JSON.stringify(value); // <- TODO: [0]
|
|
583
|
-
}
|
|
584
|
-
catch (error) {
|
|
585
|
-
if (!(error instanceof Error)) {
|
|
586
|
-
throw error;
|
|
587
|
-
}
|
|
588
|
-
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
589
|
-
}
|
|
590
|
-
/*
|
|
591
|
-
TODO: [0] Is there some more elegant way to check circular references?
|
|
592
|
-
const seen = new Set();
|
|
593
|
-
const stack = [{ value }];
|
|
594
|
-
while (stack.length > 0) {
|
|
595
|
-
const { value } = stack.pop()!;
|
|
596
|
-
if (typeof value === 'object' && value !== null) {
|
|
597
|
-
if (seen.has(value)) {
|
|
598
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
599
|
-
}
|
|
600
|
-
seen.add(value);
|
|
601
|
-
if (Array.isArray(value)) {
|
|
602
|
-
stack.push(...value.map((value) => ({ value })));
|
|
603
|
-
} else {
|
|
604
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
*/
|
|
609
|
-
return;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
else {
|
|
613
|
-
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
/**
|
|
617
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
618
|
-
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
619
|
-
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
620
|
-
*/
|
|
621
|
-
|
|
622
|
-
/**
|
|
623
|
-
* @@@
|
|
624
|
-
* @@@
|
|
625
|
-
*
|
|
626
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
627
|
-
*
|
|
628
|
-
* @param name - Name of the object for debugging purposes
|
|
629
|
-
* @param objectValue - Object to be deeply frozen
|
|
630
|
-
* @returns The same object as the input, but deeply frozen
|
|
631
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
632
|
-
*/
|
|
633
|
-
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
634
|
-
checkSerializableAsJson(name, objectValue);
|
|
635
|
-
return $deepFreeze(objectValue);
|
|
636
|
-
}
|
|
637
|
-
/**
|
|
638
|
-
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
639
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
640
|
-
*/
|
|
641
|
-
|
|
642
449
|
/**
|
|
643
450
|
* Warning message for the generated sections and files files
|
|
644
451
|
*
|
|
@@ -653,6 +460,18 @@
|
|
|
653
460
|
* @public exported from `@promptbook/core`
|
|
654
461
|
*/
|
|
655
462
|
var NAME = "Promptbook";
|
|
463
|
+
/**
|
|
464
|
+
* Email of the responsible person
|
|
465
|
+
*
|
|
466
|
+
* @public exported from `@promptbook/core`
|
|
467
|
+
*/
|
|
468
|
+
var ADMIN_EMAIL = 'me@pavolhejny.com';
|
|
469
|
+
/**
|
|
470
|
+
* Name of the responsible person for the Promptbook on GitHub
|
|
471
|
+
*
|
|
472
|
+
* @public exported from `@promptbook/core`
|
|
473
|
+
*/
|
|
474
|
+
var ADMIN_GITHUB_NAME = 'hejny';
|
|
656
475
|
/**
|
|
657
476
|
* Claim for the Promptbook
|
|
658
477
|
*
|
|
@@ -776,7 +595,8 @@
|
|
|
776
595
|
*
|
|
777
596
|
* @public exported from `@promptbook/core`
|
|
778
597
|
*/
|
|
779
|
-
var RESERVED_PARAMETER_NAMES =
|
|
598
|
+
var RESERVED_PARAMETER_NAMES =
|
|
599
|
+
/* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
|
|
780
600
|
'content',
|
|
781
601
|
'context',
|
|
782
602
|
'knowledge',
|
|
@@ -786,7 +606,7 @@
|
|
|
786
606
|
// <- TODO: list here all command names
|
|
787
607
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
788
608
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
789
|
-
]
|
|
609
|
+
];
|
|
790
610
|
/**
|
|
791
611
|
* @@@
|
|
792
612
|
*
|
|
@@ -904,6 +724,40 @@
|
|
|
904
724
|
return PipelineLogicError;
|
|
905
725
|
}(Error));
|
|
906
726
|
|
|
727
|
+
/**
|
|
728
|
+
* Make error report URL for the given error
|
|
729
|
+
*
|
|
730
|
+
* @private !!!!!!
|
|
731
|
+
*/
|
|
732
|
+
function getErrorReportUrl(error) {
|
|
733
|
+
var report = {
|
|
734
|
+
title: "\uD83D\uDC1C Error report from ".concat(NAME),
|
|
735
|
+
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 "); }),
|
|
736
|
+
};
|
|
737
|
+
var reportUrl = new URL("https://github.com/webgptorg/promptbook/issues/new");
|
|
738
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
739
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
740
|
+
reportUrl.searchParams.set('title', report.title);
|
|
741
|
+
reportUrl.searchParams.set('body', report.body);
|
|
742
|
+
return reportUrl;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
747
|
+
*
|
|
748
|
+
* @public exported from `@promptbook/core`
|
|
749
|
+
*/
|
|
750
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
751
|
+
__extends(UnexpectedError, _super);
|
|
752
|
+
function UnexpectedError(message) {
|
|
753
|
+
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;
|
|
754
|
+
_this.name = 'UnexpectedError';
|
|
755
|
+
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
756
|
+
return _this;
|
|
757
|
+
}
|
|
758
|
+
return UnexpectedError;
|
|
759
|
+
}(Error));
|
|
760
|
+
|
|
907
761
|
/**
|
|
908
762
|
* Tests if given string is valid semantic version
|
|
909
763
|
*
|
|
@@ -1384,6 +1238,183 @@
|
|
|
1384
1238
|
return parameterNames;
|
|
1385
1239
|
}
|
|
1386
1240
|
|
|
1241
|
+
/**
|
|
1242
|
+
* @@@
|
|
1243
|
+
*
|
|
1244
|
+
* Note: `$` is used to indicate that this function is not a pure function - it mutates given object
|
|
1245
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1246
|
+
*
|
|
1247
|
+
* @returns The same object as the input, but deeply frozen
|
|
1248
|
+
* @public exported from `@promptbook/utils`
|
|
1249
|
+
*/
|
|
1250
|
+
function $deepFreeze(objectValue) {
|
|
1251
|
+
var e_1, _a;
|
|
1252
|
+
var propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1253
|
+
try {
|
|
1254
|
+
for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
|
|
1255
|
+
var propertyName = propertyNames_1_1.value;
|
|
1256
|
+
var value = objectValue[propertyName];
|
|
1257
|
+
if (value && typeof value === 'object') {
|
|
1258
|
+
$deepFreeze(value);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1263
|
+
finally {
|
|
1264
|
+
try {
|
|
1265
|
+
if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
|
|
1266
|
+
}
|
|
1267
|
+
finally { if (e_1) throw e_1.error; }
|
|
1268
|
+
}
|
|
1269
|
+
return Object.freeze(objectValue);
|
|
1270
|
+
}
|
|
1271
|
+
/**
|
|
1272
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1273
|
+
*/
|
|
1274
|
+
|
|
1275
|
+
/**
|
|
1276
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
1277
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
1278
|
+
*
|
|
1279
|
+
* - Almost all primitives are serializable BUT:
|
|
1280
|
+
* - `undefined` is not serializable
|
|
1281
|
+
* - `NaN` is not serializable
|
|
1282
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
1283
|
+
* - Functions are not serializable
|
|
1284
|
+
* - Circular references are not serializable
|
|
1285
|
+
* - `Date` objects are not serializable
|
|
1286
|
+
* - `Map` and `Set` objects are not serializable
|
|
1287
|
+
* - `RegExp` objects are not serializable
|
|
1288
|
+
* - `Error` objects are not serializable
|
|
1289
|
+
* - `Symbol` objects are not serializable
|
|
1290
|
+
* - And much more...
|
|
1291
|
+
*
|
|
1292
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
1293
|
+
* @public exported from `@promptbook/utils`
|
|
1294
|
+
*/
|
|
1295
|
+
function checkSerializableAsJson(name, value) {
|
|
1296
|
+
var e_1, _a;
|
|
1297
|
+
if (value === undefined) {
|
|
1298
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
1299
|
+
}
|
|
1300
|
+
else if (value === null) {
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
else if (typeof value === 'boolean') {
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
1307
|
+
return;
|
|
1308
|
+
}
|
|
1309
|
+
else if (typeof value === 'string') {
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1312
|
+
else if (typeof value === 'symbol') {
|
|
1313
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
1314
|
+
}
|
|
1315
|
+
else if (typeof value === 'function') {
|
|
1316
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
1317
|
+
}
|
|
1318
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
1319
|
+
for (var i = 0; i < value.length; i++) {
|
|
1320
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
else if (typeof value === 'object') {
|
|
1324
|
+
if (value instanceof Date) {
|
|
1325
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
1326
|
+
}
|
|
1327
|
+
else if (value instanceof Map) {
|
|
1328
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
1329
|
+
}
|
|
1330
|
+
else if (value instanceof Set) {
|
|
1331
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
1332
|
+
}
|
|
1333
|
+
else if (value instanceof RegExp) {
|
|
1334
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
1335
|
+
}
|
|
1336
|
+
else if (value instanceof Error) {
|
|
1337
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
1338
|
+
}
|
|
1339
|
+
else {
|
|
1340
|
+
try {
|
|
1341
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1342
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
1343
|
+
if (subValue === undefined) {
|
|
1344
|
+
// Note: undefined in object is serializable - it is just omited
|
|
1345
|
+
continue;
|
|
1346
|
+
}
|
|
1347
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1351
|
+
finally {
|
|
1352
|
+
try {
|
|
1353
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1354
|
+
}
|
|
1355
|
+
finally { if (e_1) throw e_1.error; }
|
|
1356
|
+
}
|
|
1357
|
+
try {
|
|
1358
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
1359
|
+
}
|
|
1360
|
+
catch (error) {
|
|
1361
|
+
if (!(error instanceof Error)) {
|
|
1362
|
+
throw error;
|
|
1363
|
+
}
|
|
1364
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
1365
|
+
}
|
|
1366
|
+
/*
|
|
1367
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
1368
|
+
const seen = new Set();
|
|
1369
|
+
const stack = [{ value }];
|
|
1370
|
+
while (stack.length > 0) {
|
|
1371
|
+
const { value } = stack.pop()!;
|
|
1372
|
+
if (typeof value === 'object' && value !== null) {
|
|
1373
|
+
if (seen.has(value)) {
|
|
1374
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
1375
|
+
}
|
|
1376
|
+
seen.add(value);
|
|
1377
|
+
if (Array.isArray(value)) {
|
|
1378
|
+
stack.push(...value.map((value) => ({ value })));
|
|
1379
|
+
} else {
|
|
1380
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
*/
|
|
1385
|
+
return;
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
else {
|
|
1389
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1394
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
1395
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
1396
|
+
*/
|
|
1397
|
+
|
|
1398
|
+
/**
|
|
1399
|
+
* @@@
|
|
1400
|
+
* @@@
|
|
1401
|
+
*
|
|
1402
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
1403
|
+
*
|
|
1404
|
+
* @param name - Name of the object for debugging purposes
|
|
1405
|
+
* @param objectValue - Object to be deeply frozen
|
|
1406
|
+
* @returns The same object as the input, but deeply frozen
|
|
1407
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
1408
|
+
*/
|
|
1409
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
1410
|
+
checkSerializableAsJson(name, objectValue);
|
|
1411
|
+
return $deepFreeze(objectValue);
|
|
1412
|
+
}
|
|
1413
|
+
/**
|
|
1414
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1415
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1416
|
+
*/
|
|
1417
|
+
|
|
1387
1418
|
/**
|
|
1388
1419
|
* Unprepare just strips the preparation data of the pipeline
|
|
1389
1420
|
*
|
|
@@ -2647,10 +2678,11 @@
|
|
|
2647
2678
|
* @param script from which to extract the variables
|
|
2648
2679
|
* @returns the list of variable names
|
|
2649
2680
|
* @throws {ParseError} if the script is invalid
|
|
2650
|
-
* @public exported from `@promptbook/utils`
|
|
2681
|
+
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
2651
2682
|
*/
|
|
2652
|
-
function
|
|
2683
|
+
function extractVariablesFromScript(script) {
|
|
2653
2684
|
var variables = new Set();
|
|
2685
|
+
var originalScript = script;
|
|
2654
2686
|
script = "(()=>{".concat(script, "})()");
|
|
2655
2687
|
try {
|
|
2656
2688
|
for (var i = 0; i < 100 /* <- TODO: This limit to configuration */; i++)
|
|
@@ -2682,7 +2714,9 @@
|
|
|
2682
2714
|
if (!(error instanceof Error)) {
|
|
2683
2715
|
throw error;
|
|
2684
2716
|
}
|
|
2685
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n
|
|
2717
|
+
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)
|
|
2718
|
+
.map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
|
|
2719
|
+
.join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
|
|
2686
2720
|
}
|
|
2687
2721
|
return variables;
|
|
2688
2722
|
}
|
|
@@ -2696,7 +2730,7 @@
|
|
|
2696
2730
|
* @param task the task with used parameters
|
|
2697
2731
|
* @returns the set of parameter names
|
|
2698
2732
|
* @throws {ParseError} if the script is invalid
|
|
2699
|
-
* @public exported from `@promptbook/
|
|
2733
|
+
* @public exported from `@promptbook/core` <- Note: [👖] This utility is so tightly interconnected with the Promptbook that it is not exported as util but in core
|
|
2700
2734
|
*/
|
|
2701
2735
|
function extractParameterNamesFromTask(task) {
|
|
2702
2736
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
@@ -2717,7 +2751,7 @@
|
|
|
2717
2751
|
}
|
|
2718
2752
|
if (taskType === 'SCRIPT_TASK') {
|
|
2719
2753
|
try {
|
|
2720
|
-
for (var _g = __values(
|
|
2754
|
+
for (var _g = __values(extractVariablesFromScript(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
2721
2755
|
var parameterName = _h.value;
|
|
2722
2756
|
parameterNames.add(parameterName);
|
|
2723
2757
|
}
|
|
@@ -6140,7 +6174,7 @@
|
|
|
6140
6174
|
throw new ParseError(spaceTrim__default["default"]("\n Section type is already defined in the section.\n It can be defined only once.\n "));
|
|
6141
6175
|
}
|
|
6142
6176
|
$taskJson.isSectionTypeSet = true;
|
|
6143
|
-
// TODO: [🍧] Rearrange better - but at bottom and unwrap from function
|
|
6177
|
+
// TODO: [🍧][💩] Rearrange better - but at bottom and unwrap from function
|
|
6144
6178
|
var expectResultingParameterName = function () {
|
|
6145
6179
|
if ($taskJson.resultingParameterName) {
|
|
6146
6180
|
return;
|
|
@@ -7442,7 +7476,7 @@
|
|
|
7442
7476
|
if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
|
|
7443
7477
|
if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
|
|
7444
7478
|
console.warn("Multiple commands `MODEL ".concat(command.key, " ").concat(command.value, "` in the pipeline head"));
|
|
7445
|
-
// <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
|
|
7479
|
+
// <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
|
|
7446
7480
|
}
|
|
7447
7481
|
else {
|
|
7448
7482
|
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 ")));
|
|
@@ -8077,7 +8111,7 @@
|
|
|
8077
8111
|
personaCommandParser,
|
|
8078
8112
|
foreachCommandParser,
|
|
8079
8113
|
boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
|
|
8080
|
-
// <- 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
|
|
8114
|
+
// <- 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
|
|
8081
8115
|
];
|
|
8082
8116
|
/**
|
|
8083
8117
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -8373,6 +8407,7 @@
|
|
|
8373
8407
|
var e_1, _a;
|
|
8374
8408
|
var lines = markdown.split('\n');
|
|
8375
8409
|
var sections = [];
|
|
8410
|
+
// TODO: [🧽] DRY
|
|
8376
8411
|
var currentType = 'MARKDOWN';
|
|
8377
8412
|
var buffer = [];
|
|
8378
8413
|
var finishSection = function () {
|
|
@@ -9006,11 +9041,11 @@
|
|
|
9006
9041
|
var placeForSection = removeContentComments(content).match(/^##.*$/im);
|
|
9007
9042
|
if (placeForSection !== null) {
|
|
9008
9043
|
var _a = __read(placeForSection, 1), heading_1 = _a[0];
|
|
9009
|
-
return content.replace(heading_1, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(contentToInsert), "\n
|
|
9044
|
+
return content.replace(heading_1, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(contentToInsert), "\n\n ").concat(block(heading_1), "\n "); }));
|
|
9010
9045
|
}
|
|
9011
9046
|
console.warn("No place where to put the section <!--".concat(sectionName, "-->, using the end of the file"));
|
|
9012
|
-
// <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
|
|
9013
|
-
return spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(content), "\n
|
|
9047
|
+
// <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
|
|
9048
|
+
return spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(content), "\n\n ").concat(block(contentToInsert), "\n "); });
|
|
9014
9049
|
}
|
|
9015
9050
|
/**
|
|
9016
9051
|
* TODO: [🏛] This can be part of markdown builder
|
|
@@ -9121,6 +9156,115 @@
|
|
|
9121
9156
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
9122
9157
|
*/
|
|
9123
9158
|
|
|
9159
|
+
/**
|
|
9160
|
+
* Function `removePipelineCommand` will remove one command from pipeline string
|
|
9161
|
+
*
|
|
9162
|
+
* @public exported from `@promptbook/core` <- Note: [👖] This utility is so tightly interconnected with the Promptbook that it is not exported as util but in core
|
|
9163
|
+
*/
|
|
9164
|
+
function removePipelineCommand(options) {
|
|
9165
|
+
var e_1, _a;
|
|
9166
|
+
var command = options.command, pipeline = options.pipeline;
|
|
9167
|
+
var lines = pipeline.split('\n');
|
|
9168
|
+
// TODO: [🧽] DRY
|
|
9169
|
+
var currentType = 'MARKDOWN';
|
|
9170
|
+
var newLines = [];
|
|
9171
|
+
try {
|
|
9172
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
9173
|
+
var line = lines_1_1.value;
|
|
9174
|
+
if (currentType === 'MARKDOWN') {
|
|
9175
|
+
if (line.startsWith('```')) {
|
|
9176
|
+
currentType = 'CODE_BLOCK';
|
|
9177
|
+
}
|
|
9178
|
+
else if (line.includes('<!--')) {
|
|
9179
|
+
currentType = 'COMMENT';
|
|
9180
|
+
}
|
|
9181
|
+
}
|
|
9182
|
+
else if (currentType === 'CODE_BLOCK') {
|
|
9183
|
+
if (line.startsWith('```')) {
|
|
9184
|
+
currentType = 'MARKDOWN';
|
|
9185
|
+
}
|
|
9186
|
+
}
|
|
9187
|
+
else if (currentType === 'COMMENT') {
|
|
9188
|
+
if (line.includes('-->')) {
|
|
9189
|
+
currentType = 'MARKDOWN';
|
|
9190
|
+
}
|
|
9191
|
+
}
|
|
9192
|
+
if (currentType === 'MARKDOWN' && /^(-|\d\))/m.test(line) && line.toUpperCase().includes(command)) {
|
|
9193
|
+
continue;
|
|
9194
|
+
}
|
|
9195
|
+
newLines.push(line);
|
|
9196
|
+
}
|
|
9197
|
+
}
|
|
9198
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
9199
|
+
finally {
|
|
9200
|
+
try {
|
|
9201
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
9202
|
+
}
|
|
9203
|
+
finally { if (e_1) throw e_1.error; }
|
|
9204
|
+
}
|
|
9205
|
+
var newPipeline = spaceTrim__default["default"](newLines.join('\n'));
|
|
9206
|
+
return newPipeline;
|
|
9207
|
+
}
|
|
9208
|
+
|
|
9209
|
+
/**
|
|
9210
|
+
* Function `renamePipelineParameter` will find all usable parameters for given task
|
|
9211
|
+
* In other words, it will find all parameters that are not used in the task itseld and all its dependencies
|
|
9212
|
+
*
|
|
9213
|
+
* @throws {PipelineLogicError} If the new parameter name is already used in the pipeline
|
|
9214
|
+
* @public exported from `@promptbook/core` <- Note: [👖] This utility is so tightly interconnected with the Promptbook that it is not exported as util but in core
|
|
9215
|
+
*/
|
|
9216
|
+
function renamePipelineParameter(options) {
|
|
9217
|
+
var e_1, _a, e_2, _b;
|
|
9218
|
+
var pipeline = options.pipeline, oldParameterName = options.oldParameterName, newParameterName = options.newParameterName;
|
|
9219
|
+
if (pipeline.parameters.some(function (parameter) { return parameter.name === newParameterName; })) {
|
|
9220
|
+
throw new PipelineLogicError("Can not replace {".concat(oldParameterName, "} to {").concat(newParameterName, "} because {").concat(newParameterName, "} is already used in the pipeline"));
|
|
9221
|
+
}
|
|
9222
|
+
var renamedPipeline = __assign(__assign({}, pipeline), {
|
|
9223
|
+
// <- TODO: [🪓] This should be without `as $PipelineJson`
|
|
9224
|
+
parameters: __spreadArray([], __read(pipeline.parameters), false), tasks: __spreadArray([], __read(pipeline.tasks), false) });
|
|
9225
|
+
try {
|
|
9226
|
+
for (var _c = __values(renamedPipeline.parameters), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
9227
|
+
var parameter = _d.value;
|
|
9228
|
+
if (parameter.name !== oldParameterName) {
|
|
9229
|
+
continue;
|
|
9230
|
+
}
|
|
9231
|
+
parameter.name = newParameterName;
|
|
9232
|
+
}
|
|
9233
|
+
}
|
|
9234
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
9235
|
+
finally {
|
|
9236
|
+
try {
|
|
9237
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
9238
|
+
}
|
|
9239
|
+
finally { if (e_1) throw e_1.error; }
|
|
9240
|
+
}
|
|
9241
|
+
try {
|
|
9242
|
+
for (var _e = __values(renamedPipeline.tasks), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
9243
|
+
var task = _f.value;
|
|
9244
|
+
if (task.resultingParameterName === oldParameterName) {
|
|
9245
|
+
task.resultingParameterName = newParameterName;
|
|
9246
|
+
}
|
|
9247
|
+
task.dependentParameterNames = task.dependentParameterNames.map(function (dependentParameterName) {
|
|
9248
|
+
return dependentParameterName === oldParameterName ? newParameterName : dependentParameterName;
|
|
9249
|
+
});
|
|
9250
|
+
task.content = task.content.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
9251
|
+
task.title = task.title.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
9252
|
+
task.description =
|
|
9253
|
+
task.description === undefined
|
|
9254
|
+
? undefined
|
|
9255
|
+
: task.description.replace(new RegExp("{".concat(oldParameterName, "}"), 'g'), "{".concat(newParameterName, "}"));
|
|
9256
|
+
}
|
|
9257
|
+
}
|
|
9258
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
9259
|
+
finally {
|
|
9260
|
+
try {
|
|
9261
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
9262
|
+
}
|
|
9263
|
+
finally { if (e_2) throw e_2.error; }
|
|
9264
|
+
}
|
|
9265
|
+
return renamedPipeline;
|
|
9266
|
+
}
|
|
9267
|
+
|
|
9124
9268
|
/**
|
|
9125
9269
|
* Tests if the value is [🚉] serializable as JSON
|
|
9126
9270
|
*
|
|
@@ -9452,7 +9596,7 @@
|
|
|
9452
9596
|
'\n\n' +
|
|
9453
9597
|
executionReportJson.promptExecutions
|
|
9454
9598
|
.map(function (promptExecution) {
|
|
9455
|
-
// TODO: Make some better system to convert
|
|
9599
|
+
// TODO: [💩] Make some better system to convert headings to links
|
|
9456
9600
|
var hash = normalizeToKebabCase(promptExecution.prompt.title);
|
|
9457
9601
|
if (/^\s*\p{Extended_Pictographic}/u.test(promptExecution.prompt.title)) {
|
|
9458
9602
|
hash = '-' + hash;
|
|
@@ -10691,6 +10835,8 @@
|
|
|
10691
10835
|
exports.$llmToolsRegister = $llmToolsRegister;
|
|
10692
10836
|
exports.$scrapersMetadataRegister = $scrapersMetadataRegister;
|
|
10693
10837
|
exports.$scrapersRegister = $scrapersRegister;
|
|
10838
|
+
exports.ADMIN_EMAIL = ADMIN_EMAIL;
|
|
10839
|
+
exports.ADMIN_GITHUB_NAME = ADMIN_GITHUB_NAME;
|
|
10694
10840
|
exports.AbstractFormatError = AbstractFormatError;
|
|
10695
10841
|
exports.BOOK_LANGUAGE_VERSION = BOOK_LANGUAGE_VERSION;
|
|
10696
10842
|
exports.BlackholeStorage = BlackholeStorage;
|
|
@@ -10779,6 +10925,7 @@
|
|
|
10779
10925
|
exports.createSubcollection = createSubcollection;
|
|
10780
10926
|
exports.embeddingVectorToString = embeddingVectorToString;
|
|
10781
10927
|
exports.executionReportJsonToString = executionReportJsonToString;
|
|
10928
|
+
exports.extractParameterNamesFromTask = extractParameterNamesFromTask;
|
|
10782
10929
|
exports.getPipelineInterface = getPipelineInterface;
|
|
10783
10930
|
exports.isPassingExpectations = isPassingExpectations;
|
|
10784
10931
|
exports.isPipelineImplementingInterface = isPipelineImplementingInterface;
|
|
@@ -10795,6 +10942,8 @@
|
|
|
10795
10942
|
exports.preparePipeline = preparePipeline;
|
|
10796
10943
|
exports.prepareTasks = prepareTasks;
|
|
10797
10944
|
exports.prettifyPipelineString = prettifyPipelineString;
|
|
10945
|
+
exports.removePipelineCommand = removePipelineCommand;
|
|
10946
|
+
exports.renamePipelineParameter = renamePipelineParameter;
|
|
10798
10947
|
exports.stringifyPipelineJson = stringifyPipelineJson;
|
|
10799
10948
|
exports.unpreparePipeline = unpreparePipeline;
|
|
10800
10949
|
exports.usageToHuman = usageToHuman;
|