@promptbook/core 0.79.0 → 0.80.0-1

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 (40) hide show
  1. package/README.md +4 -0
  2. package/esm/index.es.js +844 -617
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/books/index.d.ts +6 -6
  5. package/esm/typings/src/_packages/core.index.d.ts +8 -6
  6. package/esm/typings/src/_packages/types.index.d.ts +6 -0
  7. package/esm/typings/src/_packages/utils.index.d.ts +4 -0
  8. package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +32 -0
  9. package/esm/typings/src/commands/_common/getParserForCommand.d.ts +1 -1
  10. package/esm/typings/src/commands/_common/parseCommand.d.ts +1 -1
  11. package/esm/typings/src/commands/_common/stringifyCommand.d.ts +1 -1
  12. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +3 -0
  13. package/esm/typings/src/config.d.ts +0 -25
  14. package/esm/typings/src/constants.d.ts +35 -0
  15. package/esm/typings/src/conversion/{pipelineStringToJson.d.ts → compilePipeline.d.ts} +3 -3
  16. package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -0
  17. package/esm/typings/src/conversion/{pipelineStringToJsonSync.d.ts → precompilePipeline.d.ts} +4 -3
  18. package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +20 -0
  19. package/esm/typings/src/high-level-abstractions/implicit-formfactor/ImplicitFormfactorHla.d.ts +10 -0
  20. package/esm/typings/src/high-level-abstractions/index.d.ts +44 -0
  21. package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +10 -0
  22. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
  23. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  24. package/esm/typings/src/prepare/prepareTasks.d.ts +1 -0
  25. package/esm/typings/src/prepare/unpreparePipeline.d.ts +1 -0
  26. package/esm/typings/src/types/typeAliases.d.ts +1 -1
  27. package/esm/typings/src/utils/normalization/orderJson.d.ts +21 -0
  28. package/esm/typings/src/utils/normalization/orderJson.test.d.ts +4 -0
  29. package/esm/typings/src/utils/organization/keepTypeImported.d.ts +9 -0
  30. package/esm/typings/src/utils/serialization/$deepFreeze.d.ts +1 -1
  31. package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +20 -2
  32. package/esm/typings/src/utils/serialization/deepClone.test.d.ts +1 -0
  33. package/esm/typings/src/utils/serialization/exportJson.d.ts +29 -0
  34. package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +2 -1
  35. package/package.json +2 -1
  36. package/umd/index.umd.js +846 -618
  37. package/umd/index.umd.js.map +1 -1
  38. package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +0 -17
  39. /package/esm/typings/src/conversion/{pipelineStringToJson.test.d.ts → compilePipeline.test.d.ts} +0 -0
  40. /package/esm/typings/src/conversion/{pipelineStringToJsonSync.test.d.ts → precompilePipeline.test.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.78.4';
28
+ var PROMPTBOOK_ENGINE_VERSION = '0.80.0-0';
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
@@ -223,6 +223,7 @@
223
223
  /**
224
224
  * Converts promptbook in JSON format to string format
225
225
  *
226
+ * @deprecated TODO: [🥍][🧠] Backup original files in `PipelineJson` same as in Promptbook.studio
226
227
  * @param pipelineJson Promptbook in JSON format (.book.json)
227
228
  * @returns Promptbook in string format (.book.md)
228
229
  * @public exported from `@promptbook/core`
@@ -584,41 +585,6 @@
584
585
  * @public exported from `@promptbook/core`
585
586
  */
586
587
  var DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME = "index";
587
- /**
588
- * Nonce which is used for replacing things in strings
589
- *
590
- * @private within the repository
591
- */
592
- var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
593
- /**
594
- * The names of the parameters that are reserved for special purposes
595
- *
596
- * @public exported from `@promptbook/core`
597
- */
598
- var RESERVED_PARAMETER_NAMES =
599
- /* !!!!!! $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', _____ as const); */ [
600
- 'content',
601
- 'context',
602
- 'knowledge',
603
- 'examples',
604
- 'modelName',
605
- 'currentDate',
606
- // <- TODO: list here all command names
607
- // <- TODO: Add more like 'date', 'modelName',...
608
- // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
609
- ];
610
- /**
611
- * @@@
612
- *
613
- * @private within the repository
614
- */
615
- var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
616
- /**
617
- * @@@
618
- *
619
- * @private within the repository
620
- */
621
- var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
622
588
  /**
623
589
  * The thresholds for the relative time in the `moment` NPM package.
624
590
  *
@@ -684,45 +650,59 @@
684
650
  // Note: In normal situations, we check the pipeline logic:
685
651
  true);
686
652
  /**
687
- * TODO: Extract `constants.ts` from `config.ts`
688
653
  * Note: [💞] Ignore a discrepancy between file name and entity name
689
654
  * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
690
655
  */
691
656
 
692
657
  /**
693
- * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
658
+ * Orders JSON object by keys
694
659
  *
695
- * @public exported from `@promptbook/core`
696
- */
697
- var ParseError = /** @class */ (function (_super) {
698
- __extends(ParseError, _super);
699
- function ParseError(message) {
700
- var _this = _super.call(this, message) || this;
701
- _this.name = 'ParseError';
702
- Object.setPrototypeOf(_this, ParseError.prototype);
703
- return _this;
704
- }
705
- return ParseError;
706
- }(Error));
707
- /**
708
- * TODO: Maybe split `ParseError` and `ApplyError`
660
+ * @returns The same type of object as the input re-ordered
661
+ * @public exported from `@promptbook/utils`
709
662
  */
663
+ function orderJson(options) {
664
+ var value = options.value, order = options.order;
665
+ var orderedValue = __assign(__assign({}, (order === undefined ? {} : Object.fromEntries(order.map(function (key) { return [key, undefined]; })))), value);
666
+ return orderedValue;
667
+ }
710
668
 
711
669
  /**
712
- * This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
670
+ * Freezes the given object and all its nested objects recursively
713
671
  *
714
- * @public exported from `@promptbook/core`
672
+ * Note: `$` is used to indicate that this function is not a pure function - it mutates given object
673
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
674
+ *
675
+ * @returns The same object as the input, but deeply frozen
676
+ * @public exported from `@promptbook/utils`
715
677
  */
716
- var PipelineLogicError = /** @class */ (function (_super) {
717
- __extends(PipelineLogicError, _super);
718
- function PipelineLogicError(message) {
719
- var _this = _super.call(this, message) || this;
720
- _this.name = 'PipelineLogicError';
721
- Object.setPrototypeOf(_this, PipelineLogicError.prototype);
722
- return _this;
678
+ function $deepFreeze(objectValue) {
679
+ var e_1, _a;
680
+ if (Array.isArray(objectValue)) {
681
+ return Object.freeze(objectValue.map(function (item) { return $deepFreeze(item); }));
723
682
  }
724
- return PipelineLogicError;
725
- }(Error));
683
+ var propertyNames = Object.getOwnPropertyNames(objectValue);
684
+ try {
685
+ for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
686
+ var propertyName = propertyNames_1_1.value;
687
+ var value = objectValue[propertyName];
688
+ if (value && typeof value === 'object') {
689
+ $deepFreeze(value);
690
+ }
691
+ }
692
+ }
693
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
694
+ finally {
695
+ try {
696
+ if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
697
+ }
698
+ finally { if (e_1) throw e_1.error; }
699
+ }
700
+ Object.freeze(objectValue);
701
+ return objectValue;
702
+ }
703
+ /**
704
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
705
+ */
726
706
 
727
707
  /**
728
708
  * Make error report URL for the given error
@@ -758,6 +738,283 @@
758
738
  return UnexpectedError;
759
739
  }(Error));
760
740
 
741
+ /**
742
+ * Checks if the value is [🚉] serializable as JSON
743
+ * If not, throws an UnexpectedError with a rich error message and tracking
744
+ *
745
+ * - Almost all primitives are serializable BUT:
746
+ * - `undefined` is not serializable
747
+ * - `NaN` is not serializable
748
+ * - Objects and arrays are serializable if all their properties are serializable
749
+ * - Functions are not serializable
750
+ * - Circular references are not serializable
751
+ * - `Date` objects are not serializable
752
+ * - `Map` and `Set` objects are not serializable
753
+ * - `RegExp` objects are not serializable
754
+ * - `Error` objects are not serializable
755
+ * - `Symbol` objects are not serializable
756
+ * - And much more...
757
+ *
758
+ * @throws UnexpectedError if the value is not serializable as JSON
759
+ * @public exported from `@promptbook/utils`
760
+ */
761
+ function checkSerializableAsJson(options) {
762
+ var e_1, _a;
763
+ var value = options.value, name = options.name, message = options.message;
764
+ if (value === undefined) {
765
+ throw new UnexpectedError("".concat(name, " is undefined"));
766
+ }
767
+ else if (value === null) {
768
+ return;
769
+ }
770
+ else if (typeof value === 'boolean') {
771
+ return;
772
+ }
773
+ else if (typeof value === 'number' && !isNaN(value)) {
774
+ return;
775
+ }
776
+ else if (typeof value === 'string') {
777
+ return;
778
+ }
779
+ else if (typeof value === 'symbol') {
780
+ throw new UnexpectedError("".concat(name, " is symbol"));
781
+ }
782
+ else if (typeof value === 'function') {
783
+ throw new UnexpectedError("".concat(name, " is function"));
784
+ }
785
+ else if (typeof value === 'object' && Array.isArray(value)) {
786
+ for (var i = 0; i < value.length; i++) {
787
+ checkSerializableAsJson({ name: "".concat(name, "[").concat(i, "]"), value: value[i], message: message });
788
+ }
789
+ }
790
+ else if (typeof value === 'object') {
791
+ if (value instanceof Date) {
792
+ throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is Date\n\n Use `string_date_iso8601` instead\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
793
+ }
794
+ else if (value instanceof Map) {
795
+ throw new UnexpectedError("".concat(name, " is Map"));
796
+ }
797
+ else if (value instanceof Set) {
798
+ throw new UnexpectedError("".concat(name, " is Set"));
799
+ }
800
+ else if (value instanceof RegExp) {
801
+ throw new UnexpectedError("".concat(name, " is RegExp"));
802
+ }
803
+ else if (value instanceof Error) {
804
+ throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is unserialized Error\n\n Use function `serializeError`\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n\n "); }));
805
+ }
806
+ else {
807
+ try {
808
+ for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
809
+ var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
810
+ if (subValue === undefined) {
811
+ // Note: undefined in object is serializable - it is just omited
812
+ continue;
813
+ }
814
+ checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message });
815
+ }
816
+ }
817
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
818
+ finally {
819
+ try {
820
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
821
+ }
822
+ finally { if (e_1) throw e_1.error; }
823
+ }
824
+ try {
825
+ JSON.stringify(value); // <- TODO: [0]
826
+ }
827
+ catch (error) {
828
+ if (!(error instanceof Error)) {
829
+ throw error;
830
+ }
831
+ throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.toString()), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
832
+ }
833
+ /*
834
+ TODO: [0] Is there some more elegant way to check circular references?
835
+ const seen = new Set();
836
+ const stack = [{ value }];
837
+ while (stack.length > 0) {
838
+ const { value } = stack.pop()!;
839
+ if (typeof value === 'object' && value !== null) {
840
+ if (seen.has(value)) {
841
+ throw new UnexpectedError(`${name} has circular reference`);
842
+ }
843
+ seen.add(value);
844
+ if (Array.isArray(value)) {
845
+ stack.push(...value.map((value) => ({ value })));
846
+ } else {
847
+ stack.push(...Object.values(value).map((value) => ({ value })));
848
+ }
849
+ }
850
+ }
851
+ */
852
+ return;
853
+ }
854
+ }
855
+ else {
856
+ throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n `".concat(name, "` is unknown type\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
857
+ }
858
+ }
859
+ /**
860
+ * TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
861
+ * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
862
+ * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
863
+ */
864
+
865
+ /**
866
+ * @@@
867
+ *
868
+ * @public exported from `@promptbook/utils`
869
+ */
870
+ function deepClone(objectValue) {
871
+ return JSON.parse(JSON.stringify(objectValue));
872
+ /*
873
+ !!!!!!!!
874
+ TODO: [🧠] Is there a better implementation?
875
+ > const propertyNames = Object.getOwnPropertyNames(objectValue);
876
+ > for (const propertyName of propertyNames) {
877
+ > const value = (objectValue as really_any)[propertyName];
878
+ > if (value && typeof value === 'object') {
879
+ > deepClone(value);
880
+ > }
881
+ > }
882
+ > return Object.assign({}, objectValue);
883
+ */
884
+ }
885
+ /**
886
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
887
+ */
888
+
889
+ /**
890
+ * Utility to export a JSON object from a function
891
+ *
892
+ * 1) Checks if the value is serializable as JSON
893
+ * 2) Makes a deep clone of the object
894
+ * 2) Orders the object properties
895
+ * 2) Deeply freezes the cloned object
896
+ *
897
+ * Note: This function does not mutates the given object
898
+ *
899
+ * @returns The same type of object as the input but read-only and re-ordered
900
+ * @public exported from `@promptbook/utils`
901
+ */
902
+ function exportJson(options) {
903
+ var name = options.name, value = options.value, order = options.order, message = options.message;
904
+ checkSerializableAsJson({ name: name, value: value, message: message });
905
+ var orderedValue =
906
+ // TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
907
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
908
+ // @ts-ignore
909
+ order === undefined
910
+ ? deepClone(value)
911
+ : orderJson({
912
+ value: value,
913
+ // <- Note: checkSerializableAsJson asserts that the value is serializable as JSON
914
+ order: order,
915
+ });
916
+ $deepFreeze(orderedValue);
917
+ return orderedValue;
918
+ }
919
+ /**
920
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
921
+ */
922
+
923
+ /**
924
+ * Order of keys in the pipeline JSON
925
+ *
926
+ * @public exported from `@promptbook/core`
927
+ */
928
+ var ORDER_OF_PIPELINE_JSON = [
929
+ 'title',
930
+ 'pipelineUrl',
931
+ 'bookVersion',
932
+ 'description',
933
+ 'formfactorName',
934
+ 'parameters',
935
+ 'tasks',
936
+ 'personas',
937
+ 'preparations',
938
+ 'knowledgeSources',
939
+ 'knowledgePieces',
940
+ ];
941
+ /**
942
+ * Nonce which is used for replacing things in strings
943
+ *
944
+ * @private within the repository
945
+ */
946
+ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
947
+ /**
948
+ * @@@
949
+ *
950
+ * @private within the repository
951
+ */
952
+ var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
953
+ /**
954
+ * @@@
955
+ *
956
+ * @private within the repository
957
+ */
958
+ var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
959
+ /**
960
+ * The names of the parameters that are reserved for special purposes
961
+ *
962
+ * @public exported from `@promptbook/core`
963
+ */
964
+ var RESERVED_PARAMETER_NAMES = exportJson({
965
+ name: 'RESERVED_PARAMETER_NAMES',
966
+ message: "The names of the parameters that are reserved for special purposes",
967
+ value: [
968
+ 'content',
969
+ 'context',
970
+ 'knowledge',
971
+ 'examples',
972
+ 'modelName',
973
+ 'currentDate',
974
+ // <- TODO: list here all command names
975
+ // <- TODO: Add more like 'date', 'modelName',...
976
+ // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
977
+ ],
978
+ });
979
+ /**
980
+ * Note: [💞] Ignore a discrepancy between file name and entity name
981
+ */
982
+
983
+ /**
984
+ * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
985
+ *
986
+ * @public exported from `@promptbook/core`
987
+ */
988
+ var ParseError = /** @class */ (function (_super) {
989
+ __extends(ParseError, _super);
990
+ function ParseError(message) {
991
+ var _this = _super.call(this, message) || this;
992
+ _this.name = 'ParseError';
993
+ Object.setPrototypeOf(_this, ParseError.prototype);
994
+ return _this;
995
+ }
996
+ return ParseError;
997
+ }(Error));
998
+ /**
999
+ * TODO: Maybe split `ParseError` and `ApplyError`
1000
+ */
1001
+
1002
+ /**
1003
+ * This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
1004
+ *
1005
+ * @public exported from `@promptbook/core`
1006
+ */
1007
+ var PipelineLogicError = /** @class */ (function (_super) {
1008
+ __extends(PipelineLogicError, _super);
1009
+ function PipelineLogicError(message) {
1010
+ var _this = _super.call(this, message) || this;
1011
+ _this.name = 'PipelineLogicError';
1012
+ Object.setPrototypeOf(_this, PipelineLogicError.prototype);
1013
+ return _this;
1014
+ }
1015
+ return PipelineLogicError;
1016
+ }(Error));
1017
+
761
1018
  /**
762
1019
  * Tests if given string is valid semantic version
763
1020
  *
@@ -995,6 +1252,21 @@
995
1252
  }
996
1253
  };
997
1254
  try {
1255
+ /*
1256
+ TODO: [🧠][🅾] Should be empty pipeline valid or not
1257
+ // Note: Check that pipeline has some tasks
1258
+ if (pipeline.tasks.length === 0) {
1259
+ throw new PipelineLogicError(
1260
+ spaceTrim(
1261
+ (block) => `
1262
+ Pipeline must have at least one task
1263
+
1264
+ ${block(pipelineIdentification)}
1265
+ `,
1266
+ ),
1267
+ );
1268
+ }
1269
+ */
998
1270
  // Note: Check each parameter individually
999
1271
  for (var _d = __values(pipeline.parameters), _e = _d.next(); !_e.done; _e = _d.next()) {
1000
1272
  var parameter = _e.value;
@@ -1155,6 +1427,9 @@
1155
1427
  while (unresovedTasks.length > 0) {
1156
1428
  _loop_3();
1157
1429
  }
1430
+ // Note: Check that formfactor is corresponding to the pipeline interface
1431
+ // TODO: !!!!!! Implement this
1432
+ // pipeline.formfactorName
1158
1433
  }
1159
1434
  /**
1160
1435
  * TODO: !! [🧞‍♀️] Do not allow joker + foreach
@@ -1188,239 +1463,60 @@
1188
1463
  function NotFoundError(message) {
1189
1464
  var _this = _super.call(this, message) || this;
1190
1465
  _this.name = 'NotFoundError';
1191
- Object.setPrototypeOf(_this, NotFoundError.prototype);
1192
- return _this;
1193
- }
1194
- return NotFoundError;
1195
- }(Error));
1196
-
1197
- /**
1198
- * This error indicates errors in referencing promptbooks between each other
1199
- *
1200
- * @public exported from `@promptbook/core`
1201
- */
1202
- var PipelineUrlError = /** @class */ (function (_super) {
1203
- __extends(PipelineUrlError, _super);
1204
- function PipelineUrlError(message) {
1205
- var _this = _super.call(this, message) || this;
1206
- _this.name = 'PipelineUrlError';
1207
- Object.setPrototypeOf(_this, PipelineUrlError.prototype);
1208
- return _this;
1209
- }
1210
- return PipelineUrlError;
1211
- }(Error));
1212
-
1213
- /**
1214
- * Parses the task and returns the list of all parameter names
1215
- *
1216
- * @param template the string template with parameters in {curly} braces
1217
- * @returns the list of parameter names
1218
- * @public exported from `@promptbook/utils`
1219
- */
1220
- function extractParameterNames(template) {
1221
- var e_1, _a;
1222
- var matches = template.matchAll(/{\w+}/g);
1223
- var parameterNames = new Set();
1224
- try {
1225
- for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
1226
- var match = matches_1_1.value;
1227
- var parameterName = match[0].slice(1, -1);
1228
- parameterNames.add(parameterName);
1229
- }
1230
- }
1231
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1232
- finally {
1233
- try {
1234
- if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
1235
- }
1236
- finally { if (e_1) throw e_1.error; }
1237
- }
1238
- return parameterNames;
1239
- }
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
- if (Array.isArray(objectValue)) {
1253
- return Object.freeze(objectValue.map(function (item) { return $deepFreeze(item); }));
1254
- }
1255
- var propertyNames = Object.getOwnPropertyNames(objectValue);
1256
- try {
1257
- for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
1258
- var propertyName = propertyNames_1_1.value;
1259
- var value = objectValue[propertyName];
1260
- if (value && typeof value === 'object') {
1261
- $deepFreeze(value);
1262
- }
1263
- }
1264
- }
1265
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1266
- finally {
1267
- try {
1268
- if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
1269
- }
1270
- finally { if (e_1) throw e_1.error; }
1271
- }
1272
- return Object.freeze(objectValue);
1273
- }
1274
- /**
1275
- * TODO: [🧠] Is there a way how to meaningfully test this utility
1276
- */
1277
-
1278
- /**
1279
- * Checks if the value is [🚉] serializable as JSON
1280
- * If not, throws an UnexpectedError with a rich error message and tracking
1281
- *
1282
- * - Almost all primitives are serializable BUT:
1283
- * - `undefined` is not serializable
1284
- * - `NaN` is not serializable
1285
- * - Objects and arrays are serializable if all their properties are serializable
1286
- * - Functions are not serializable
1287
- * - Circular references are not serializable
1288
- * - `Date` objects are not serializable
1289
- * - `Map` and `Set` objects are not serializable
1290
- * - `RegExp` objects are not serializable
1291
- * - `Error` objects are not serializable
1292
- * - `Symbol` objects are not serializable
1293
- * - And much more...
1294
- *
1295
- * @throws UnexpectedError if the value is not serializable as JSON
1296
- * @public exported from `@promptbook/utils`
1297
- */
1298
- function checkSerializableAsJson(name, value) {
1299
- var e_1, _a;
1300
- if (value === undefined) {
1301
- throw new UnexpectedError("".concat(name, " is undefined"));
1302
- }
1303
- else if (value === null) {
1304
- return;
1305
- }
1306
- else if (typeof value === 'boolean') {
1307
- return;
1308
- }
1309
- else if (typeof value === 'number' && !isNaN(value)) {
1310
- return;
1311
- }
1312
- else if (typeof value === 'string') {
1313
- return;
1314
- }
1315
- else if (typeof value === 'symbol') {
1316
- throw new UnexpectedError("".concat(name, " is symbol"));
1317
- }
1318
- else if (typeof value === 'function') {
1319
- throw new UnexpectedError("".concat(name, " is function"));
1320
- }
1321
- else if (typeof value === 'object' && Array.isArray(value)) {
1322
- for (var i = 0; i < value.length; i++) {
1323
- checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
1324
- }
1325
- }
1326
- else if (typeof value === 'object') {
1327
- if (value instanceof Date) {
1328
- throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
1329
- }
1330
- else if (value instanceof Map) {
1331
- throw new UnexpectedError("".concat(name, " is Map"));
1332
- }
1333
- else if (value instanceof Set) {
1334
- throw new UnexpectedError("".concat(name, " is Set"));
1335
- }
1336
- else if (value instanceof RegExp) {
1337
- throw new UnexpectedError("".concat(name, " is RegExp"));
1338
- }
1339
- else if (value instanceof Error) {
1340
- throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
1341
- }
1342
- else {
1343
- try {
1344
- for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
1345
- var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
1346
- if (subValue === undefined) {
1347
- // Note: undefined in object is serializable - it is just omited
1348
- continue;
1349
- }
1350
- checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
1351
- }
1352
- }
1353
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1354
- finally {
1355
- try {
1356
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1357
- }
1358
- finally { if (e_1) throw e_1.error; }
1359
- }
1360
- try {
1361
- JSON.stringify(value); // <- TODO: [0]
1362
- }
1363
- catch (error) {
1364
- if (!(error instanceof Error)) {
1365
- throw error;
1366
- }
1367
- throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
1368
- }
1369
- /*
1370
- TODO: [0] Is there some more elegant way to check circular references?
1371
- const seen = new Set();
1372
- const stack = [{ value }];
1373
- while (stack.length > 0) {
1374
- const { value } = stack.pop()!;
1375
- if (typeof value === 'object' && value !== null) {
1376
- if (seen.has(value)) {
1377
- throw new UnexpectedError(`${name} has circular reference`);
1378
- }
1379
- seen.add(value);
1380
- if (Array.isArray(value)) {
1381
- stack.push(...value.map((value) => ({ value })));
1382
- } else {
1383
- stack.push(...Object.values(value).map((value) => ({ value })));
1384
- }
1385
- }
1386
- }
1387
- */
1388
- return;
1389
- }
1390
- }
1391
- else {
1392
- throw new UnexpectedError("".concat(name, " is unknown"));
1466
+ Object.setPrototypeOf(_this, NotFoundError.prototype);
1467
+ return _this;
1393
1468
  }
1394
- }
1469
+ return NotFoundError;
1470
+ }(Error));
1471
+
1395
1472
  /**
1396
- * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
1397
- * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
1398
- * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
1473
+ * This error indicates errors in referencing promptbooks between each other
1474
+ *
1475
+ * @public exported from `@promptbook/core`
1399
1476
  */
1477
+ var PipelineUrlError = /** @class */ (function (_super) {
1478
+ __extends(PipelineUrlError, _super);
1479
+ function PipelineUrlError(message) {
1480
+ var _this = _super.call(this, message) || this;
1481
+ _this.name = 'PipelineUrlError';
1482
+ Object.setPrototypeOf(_this, PipelineUrlError.prototype);
1483
+ return _this;
1484
+ }
1485
+ return PipelineUrlError;
1486
+ }(Error));
1400
1487
 
1401
1488
  /**
1402
- * @@@
1403
- * @@@
1404
- *
1405
- * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
1489
+ * Parses the task and returns the list of all parameter names
1406
1490
  *
1407
- * @param name - Name of the object for debugging purposes
1408
- * @param objectValue - Object to be deeply frozen
1409
- * @returns The same object as the input, but deeply frozen
1410
- * @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
1491
+ * @param template the string template with parameters in {curly} braces
1492
+ * @returns the list of parameter names
1493
+ * @public exported from `@promptbook/utils`
1411
1494
  */
1412
- function $asDeeplyFrozenSerializableJson(name, objectValue) {
1413
- checkSerializableAsJson(name, objectValue);
1414
- return $deepFreeze(objectValue);
1495
+ function extractParameterNames(template) {
1496
+ var e_1, _a;
1497
+ var matches = template.matchAll(/{\w+}/g);
1498
+ var parameterNames = new Set();
1499
+ try {
1500
+ for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
1501
+ var match = matches_1_1.value;
1502
+ var parameterName = match[0].slice(1, -1);
1503
+ parameterNames.add(parameterName);
1504
+ }
1505
+ }
1506
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1507
+ finally {
1508
+ try {
1509
+ if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1);
1510
+ }
1511
+ finally { if (e_1) throw e_1.error; }
1512
+ }
1513
+ return parameterNames;
1415
1514
  }
1416
- /**
1417
- * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
1418
- * TODO: [🧠] Is there a way how to meaningfully test this utility
1419
- */
1420
1515
 
1421
1516
  /**
1422
1517
  * Unprepare just strips the preparation data of the pipeline
1423
1518
  *
1519
+ * @deprecated In future version this function will be removed or deprecated
1424
1520
  * @public exported from `@promptbook/core`
1425
1521
  */
1426
1522
  function unpreparePipeline(pipeline) {
@@ -1435,7 +1531,12 @@
1435
1531
  delete taskUnprepared.preparedContent;
1436
1532
  return taskUnprepared;
1437
1533
  });
1438
- return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { tasks: tasks, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
1534
+ return exportJson({
1535
+ name: 'pipelineJson',
1536
+ message: "Result of `unpreparePipeline`",
1537
+ order: ORDER_OF_PIPELINE_JSON,
1538
+ value: __assign(__assign({}, pipeline), { tasks: tasks, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }),
1539
+ });
1439
1540
  }
1440
1541
  /**
1441
1542
  * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
@@ -1898,29 +1999,6 @@
1898
1999
  * Note: [💞] Ignore a discrepancy between file name and entity name
1899
2000
  */
1900
2001
 
1901
- /**
1902
- * @@@
1903
- *
1904
- * @public exported from `@promptbook/utils`
1905
- */
1906
- function deepClone(objectValue) {
1907
- return JSON.parse(JSON.stringify(objectValue));
1908
- /*
1909
- TODO: [🧠] Is there a better implementation?
1910
- > const propertyNames = Object.getOwnPropertyNames(objectValue);
1911
- > for (const propertyName of propertyNames) {
1912
- > const value = (objectValue as really_any)[propertyName];
1913
- > if (value && typeof value === 'object') {
1914
- > deepClone(value);
1915
- > }
1916
- > }
1917
- > return Object.assign({}, objectValue);
1918
- */
1919
- }
1920
- /**
1921
- * TODO: [🧠] Is there a way how to meaningfully test this utility
1922
- */
1923
-
1924
2002
  /**
1925
2003
  * Function `addUsage` will add multiple usages into one
1926
2004
  *
@@ -2388,7 +2466,7 @@
2388
2466
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2389
2467
  */
2390
2468
 
2391
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./books/prepare-persona.book.md"}];
2469
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sourceFile:"./books/prepare-persona.book.md"}];
2392
2470
 
2393
2471
  /**
2394
2472
  * This error indicates problems parsing the format value
@@ -4660,16 +4738,21 @@
4660
4738
  // Note: Wait a short time to prevent race conditions
4661
4739
  _g.sent();
4662
4740
  _g.label = 6;
4663
- case 6: return [2 /*return*/, $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with missing parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
4664
- isSuccessful: false,
4665
- errors: __spreadArray([
4666
- new PipelineExecutionError("Parameter `{".concat(parameter.name, "}` is required as an input parameter"))
4667
- ], __read(errors), false).map(serializeError),
4668
- warnings: [],
4669
- executionReport: executionReport,
4670
- outputParameters: {},
4671
- usage: ZERO_USAGE,
4672
- preparedPipeline: preparedPipeline,
4741
+ case 6: return [2 /*return*/, exportJson({
4742
+ name: "executionReport",
4743
+ message: "Unuccessful PipelineExecutorResult (with missing parameter {".concat(parameter.name, "}) PipelineExecutorResult"),
4744
+ order: [],
4745
+ value: {
4746
+ isSuccessful: false,
4747
+ errors: __spreadArray([
4748
+ new PipelineExecutionError("Parameter `{".concat(parameter.name, "}` is required as an input parameter"))
4749
+ ], __read(errors), false).map(serializeError),
4750
+ warnings: [],
4751
+ executionReport: executionReport,
4752
+ outputParameters: {},
4753
+ usage: ZERO_USAGE,
4754
+ preparedPipeline: preparedPipeline,
4755
+ },
4673
4756
  })];
4674
4757
  case 7:
4675
4758
  _b = _a.next();
@@ -4708,16 +4791,21 @@
4708
4791
  // Note: Wait a short time to prevent race conditions
4709
4792
  _h.sent();
4710
4793
  _h.label = 3;
4711
- case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim.spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
4712
- isSuccessful: false,
4713
- errors: __spreadArray([
4714
- new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
4715
- ], __read(errors), false).map(serializeError),
4716
- warnings: warnings.map(serializeError),
4717
- executionReport: executionReport,
4718
- outputParameters: {},
4719
- usage: ZERO_USAGE,
4720
- preparedPipeline: preparedPipeline,
4794
+ case 3: return [2 /*return*/, { value: exportJson({
4795
+ name: 'pipelineExecutorResult',
4796
+ message: spaceTrim.spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }),
4797
+ order: [],
4798
+ value: {
4799
+ isSuccessful: false,
4800
+ errors: __spreadArray([
4801
+ new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Parameter `{".concat(parameter.name, "}` is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
4802
+ ], __read(errors), false).map(serializeError),
4803
+ warnings: warnings.map(serializeError),
4804
+ executionReport: executionReport,
4805
+ outputParameters: {},
4806
+ usage: ZERO_USAGE,
4807
+ preparedPipeline: preparedPipeline,
4808
+ },
4721
4809
  }) }];
4722
4810
  case 4: return [2 /*return*/];
4723
4811
  }
@@ -4871,14 +4959,19 @@
4871
4959
  // Note: Wait a short time to prevent race conditions
4872
4960
  _g.sent();
4873
4961
  _g.label = 27;
4874
- case 27: return [2 /*return*/, $asDeeplyFrozenSerializableJson('Unuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult', {
4875
- isSuccessful: false,
4876
- errors: __spreadArray([error_1], __read(errors), false).map(serializeError),
4877
- warnings: warnings.map(serializeError),
4878
- usage: usage_1,
4879
- executionReport: executionReport,
4880
- outputParameters: outputParameters_1,
4881
- preparedPipeline: preparedPipeline,
4962
+ case 27: return [2 /*return*/, exportJson({
4963
+ name: 'pipelineExecutorResult',
4964
+ message: "Unuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult",
4965
+ order: [],
4966
+ value: {
4967
+ isSuccessful: false,
4968
+ errors: __spreadArray([error_1], __read(errors), false).map(serializeError),
4969
+ warnings: warnings.map(serializeError),
4970
+ usage: usage_1,
4971
+ executionReport: executionReport,
4972
+ outputParameters: outputParameters_1,
4973
+ preparedPipeline: preparedPipeline,
4974
+ },
4882
4975
  })];
4883
4976
  case 28:
4884
4977
  usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
@@ -4899,14 +4992,19 @@
4899
4992
  // Note: Wait a short time to prevent race conditions
4900
4993
  _g.sent();
4901
4994
  _g.label = 30;
4902
- case 30: return [2 /*return*/, $asDeeplyFrozenSerializableJson('Successful PipelineExecutorResult', {
4903
- isSuccessful: true,
4904
- errors: errors.map(serializeError),
4905
- warnings: warnings.map(serializeError),
4906
- usage: usage,
4907
- executionReport: executionReport,
4908
- outputParameters: outputParameters,
4909
- preparedPipeline: preparedPipeline,
4995
+ case 30: return [2 /*return*/, exportJson({
4996
+ name: 'pipelineExecutorResult',
4997
+ message: "Successful PipelineExecutorResult",
4998
+ order: [],
4999
+ value: {
5000
+ isSuccessful: true,
5001
+ errors: errors.map(serializeError),
5002
+ warnings: warnings.map(serializeError),
5003
+ usage: usage,
5004
+ executionReport: executionReport,
5005
+ outputParameters: outputParameters,
5006
+ preparedPipeline: preparedPipeline,
5007
+ },
4910
5008
  })];
4911
5009
  }
4912
5010
  });
@@ -5777,36 +5875,6 @@
5777
5875
  * [ ] One piece can have multiple sources
5778
5876
  */
5779
5877
 
5780
- /**
5781
- * @@@
5782
- *
5783
- * Note: It is usefull @@@
5784
- *
5785
- * @param pipeline
5786
- * @public exported from `@promptbook/utils`
5787
- */
5788
- function clonePipeline(pipeline) {
5789
- // Note: Not using spread operator (...) because @@@
5790
- var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
5791
- return {
5792
- pipelineUrl: pipelineUrl,
5793
- sourceFile: sourceFile,
5794
- title: title,
5795
- bookVersion: bookVersion,
5796
- description: description,
5797
- formfactorName: formfactorName,
5798
- parameters: parameters,
5799
- tasks: tasks,
5800
- knowledgeSources: knowledgeSources,
5801
- knowledgePieces: knowledgePieces,
5802
- personas: personas,
5803
- preparations: preparations,
5804
- };
5805
- }
5806
- /**
5807
- * TODO: [🍙] Make some standard order of json properties
5808
- */
5809
-
5810
5878
  /**
5811
5879
  * @@@
5812
5880
  *
@@ -5847,6 +5915,7 @@
5847
5915
  });
5848
5916
  }
5849
5917
  /**
5918
+ * TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
5850
5919
  * TODO: [🧠] Add context to each task (if missing)
5851
5920
  * TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
5852
5921
  * TODO: [♨][main] !!! Prepare index the examples and maybe tasks
@@ -5894,191 +5963,72 @@
5894
5963
  usage: ZERO_USAGE,
5895
5964
  };
5896
5965
  preparations = [
5897
- // ...preparations
5898
- // <- TODO: [🧊]
5899
- currentPreparation,
5900
- ];
5901
- preparedPersonas = new Array(personas.length);
5902
- return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona, index) { return __awaiter(_this, void 0, void 0, function () {
5903
- var modelRequirements, preparedPersona;
5904
- return __generator(this, function (_a) {
5905
- switch (_a.label) {
5906
- case 0: return [4 /*yield*/, preparePersona(persona.description, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), {
5907
- rootDirname: rootDirname,
5908
- maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
5909
- isVerbose: isVerbose,
5910
- })];
5911
- case 1:
5912
- modelRequirements = _a.sent();
5913
- preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
5914
- preparedPersonas[index] = preparedPersona;
5915
- return [2 /*return*/];
5916
- }
5917
- });
5918
- }); })];
5919
- case 1:
5920
- _c.sent();
5921
- knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
5922
- return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), __assign(__assign({}, options), { rootDirname: rootDirname, maxParallelCount: maxParallelCount /* <- TODO: [🪂] */, isVerbose: isVerbose }))];
5923
- case 2:
5924
- partialknowledgePiecesPrepared = _c.sent();
5925
- knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
5926
- return [4 /*yield*/, prepareTasks({
5927
- parameters: parameters,
5928
- tasks: tasks,
5929
- knowledgePiecesCount: knowledgePiecesPrepared.length,
5930
- }, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), {
5931
- rootDirname: rootDirname,
5932
- maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
5933
- isVerbose: isVerbose,
5934
- })];
5935
- case 3:
5936
- tasksPrepared = (_c.sent()).tasksPrepared;
5937
- // ----- /Tasks preparation -----
5938
- // Note: Count total usage
5939
- currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
5940
- return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { tasks: __spreadArray([], __read(tasksPrepared), false),
5941
- // <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
5942
- knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }))];
5943
- }
5944
- });
5945
- });
5946
- }
5947
- /**
5948
- * TODO: Write tests for `preparePipeline`
5949
- * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
5950
- * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
5951
- * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
5952
- * TODO: [🧠][♏] Maybe if expecting JSON (In Anthropic Claude and other models without non-json) and its not specified in prompt content, append the instructions
5953
- * @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
5954
- */
5955
-
5956
- /**
5957
- * @@@
5958
- *
5959
- * @deprecated https://github.com/webgptorg/promptbook/pull/186
5960
- * @see https://github.com/webgptorg/promptbook/discussions/171
5961
- *
5962
- * @public exported from `@promptbook/core`
5963
- */
5964
- function getPipelineInterface(pipeline) {
5965
- var e_1, _a, e_2, _b;
5966
- var pipelineInterface = {
5967
- inputParameters: [],
5968
- outputParameters: [],
5969
- };
5970
- try {
5971
- for (var _c = __values(pipeline.parameters), _d = _c.next(); !_d.done; _d = _c.next()) {
5972
- var parameter = _d.value;
5973
- var isInput = parameter.isInput, isOutput = parameter.isOutput;
5974
- if (isInput) {
5975
- pipelineInterface.inputParameters.push(deepClone(parameter));
5976
- }
5977
- if (isOutput) {
5978
- pipelineInterface.outputParameters.push(deepClone(parameter));
5979
- }
5980
- }
5981
- }
5982
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
5983
- finally {
5984
- try {
5985
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
5986
- }
5987
- finally { if (e_1) throw e_1.error; }
5988
- }
5989
- try {
5990
- for (var _e = __values(['inputParameters', 'outputParameters']), _f = _e.next(); !_f.done; _f = _e.next()) {
5991
- var key = _f.value;
5992
- pipelineInterface[key].sort(function (_a, _b) {
5993
- var name1 = _a.name;
5994
- var name2 = _b.name;
5995
- return name1.localeCompare(name2);
5996
- });
5997
- }
5998
- }
5999
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
6000
- finally {
6001
- try {
6002
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
6003
- }
6004
- finally { if (e_2) throw e_2.error; }
6005
- }
6006
- return $deepFreeze(pipelineInterface);
6007
- }
6008
-
6009
- /**
6010
- * @@@
6011
- *
6012
- * @deprecated https://github.com/webgptorg/promptbook/pull/186
6013
- * @see https://github.com/webgptorg/promptbook/discussions/171
6014
- *
6015
- * @public exported from `@promptbook/core`
6016
- */
6017
- function isPipelineInterfacesEqual(pipelineInterface1, pipelineInterface2) {
6018
- var e_1, _a, e_2, _b;
6019
- try {
6020
- for (var _c = __values(['inputParameters', 'outputParameters']), _d = _c.next(); !_d.done; _d = _c.next()) {
6021
- var whichParameters = _d.value;
6022
- var parameters1 = pipelineInterface1[whichParameters]; // <- Note: `isPipelineInterfacesEqual` is just temporary solution, no need to fix this
6023
- var parameters2 = pipelineInterface2[whichParameters];
6024
- if (parameters1.length !== parameters2.length) {
6025
- return false;
6026
- }
6027
- var _loop_1 = function (parameter) {
6028
- var matchingParameter = parameters2.find(function (_a) {
6029
- var name = _a.name;
6030
- return name === parameter.name;
6031
- });
6032
- if (!matchingParameter) {
6033
- return { value: false };
6034
- }
6035
- // Note: Do not compare description, it is not relevant for compatibility
6036
- if (matchingParameter.isInput !== parameter.isInput) {
6037
- return { value: false };
6038
- }
6039
- if (matchingParameter.isOutput !== parameter.isOutput) {
6040
- return { value: false };
6041
- }
6042
- };
6043
- try {
6044
- for (var parameters1_1 = (e_2 = void 0, __values(parameters1)), parameters1_1_1 = parameters1_1.next(); !parameters1_1_1.done; parameters1_1_1 = parameters1_1.next()) {
6045
- var parameter = parameters1_1_1.value;
6046
- var state_1 = _loop_1(parameter);
6047
- if (typeof state_1 === "object")
6048
- return state_1.value;
6049
- }
6050
- }
6051
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
6052
- finally {
6053
- try {
6054
- if (parameters1_1_1 && !parameters1_1_1.done && (_b = parameters1_1.return)) _b.call(parameters1_1);
6055
- }
6056
- finally { if (e_2) throw e_2.error; }
5966
+ // ...preparations
5967
+ // <- TODO: [🧊]
5968
+ currentPreparation,
5969
+ ];
5970
+ preparedPersonas = new Array(personas.length);
5971
+ return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona, index) { return __awaiter(_this, void 0, void 0, function () {
5972
+ var modelRequirements, preparedPersona;
5973
+ return __generator(this, function (_a) {
5974
+ switch (_a.label) {
5975
+ case 0: return [4 /*yield*/, preparePersona(persona.description, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), {
5976
+ rootDirname: rootDirname,
5977
+ maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
5978
+ isVerbose: isVerbose,
5979
+ })];
5980
+ case 1:
5981
+ modelRequirements = _a.sent();
5982
+ preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
5983
+ preparedPersonas[index] = preparedPersona;
5984
+ return [2 /*return*/];
5985
+ }
5986
+ });
5987
+ }); })];
5988
+ case 1:
5989
+ _c.sent();
5990
+ knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
5991
+ return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), __assign(__assign({}, options), { rootDirname: rootDirname, maxParallelCount: maxParallelCount /* <- TODO: [🪂] */, isVerbose: isVerbose }))];
5992
+ case 2:
5993
+ partialknowledgePiecesPrepared = _c.sent();
5994
+ knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
5995
+ return [4 /*yield*/, prepareTasks({
5996
+ parameters: parameters,
5997
+ tasks: tasks,
5998
+ knowledgePiecesCount: knowledgePiecesPrepared.length,
5999
+ }, __assign(__assign({}, tools), { llm: llmToolsWithUsage }), {
6000
+ rootDirname: rootDirname,
6001
+ maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
6002
+ isVerbose: isVerbose,
6003
+ })];
6004
+ case 3:
6005
+ tasksPrepared = (_c.sent()).tasksPrepared;
6006
+ // ----- /Tasks preparation -----
6007
+ // TODO: [😂] Use here all `AsyncHighLevelAbstraction`
6008
+ // Note: Count total usage
6009
+ currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
6010
+ return [2 /*return*/, exportJson({
6011
+ name: 'pipelineJson',
6012
+ message: "Result of `preparePipeline`",
6013
+ order: ORDER_OF_PIPELINE_JSON,
6014
+ value: __assign(__assign({}, pipeline), {
6015
+ // <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
6016
+ knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
6017
+ // <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
6018
+ personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }),
6019
+ })];
6057
6020
  }
6058
- }
6059
- }
6060
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
6061
- finally {
6062
- try {
6063
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
6064
- }
6065
- finally { if (e_1) throw e_1.error; }
6066
- }
6067
- return true;
6021
+ });
6022
+ });
6068
6023
  }
6069
-
6070
6024
  /**
6071
- * @@@
6072
- *
6073
- * @deprecated https://github.com/webgptorg/promptbook/pull/186
6074
- * @see https://github.com/webgptorg/promptbook/discussions/171
6075
- *
6076
- * @public exported from `@promptbook/core`
6025
+ * TODO: Write tests for `preparePipeline`
6026
+ * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
6027
+ * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
6028
+ * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
6029
+ * TODO: [🧠][♏] Maybe if expecting JSON (In Anthropic Claude and other models without non-json) and its not specified in prompt content, append the instructions
6030
+ * @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
6077
6031
  */
6078
- function isPipelineImplementingInterface(options) {
6079
- var pipeline = options.pipeline, pipelineInterface = options.pipelineInterface;
6080
- return isPipelineInterfacesEqual(getPipelineInterface(pipeline), pipelineInterface);
6081
- }
6082
6032
 
6083
6033
  /**
6084
6034
  * All available task types
@@ -6330,7 +6280,8 @@
6330
6280
  expectResultingParameterName();
6331
6281
  var parameter = $pipelineJson.parameters.find(function (param) { return param.name === $taskJson.resultingParameterName; });
6332
6282
  if (parameter === undefined) {
6333
- throw new ParseError("Can not find parameter {".concat($taskJson.resultingParameterName, "} to assign example value on it"));
6283
+ // TODO: !!!!!! Change to logic error for higher level abstractions to work
6284
+ throw new ParseError("Parameter `{".concat($taskJson.resultingParameterName, "}` is not defined so can not define example value of it"));
6334
6285
  }
6335
6286
  parameter.exampleValues = parameter.exampleValues || [];
6336
6287
  parameter.exampleValues.push($taskJson.content);
@@ -7764,7 +7715,7 @@
7764
7715
  * Note: `$` is used to indicate that this function mutates given `pipelineJson`
7765
7716
  */
7766
7717
  $applyToPipelineJson: function (command, $pipelineJson) {
7767
- // Note: [🍣] Do nothing, its application is implemented separately in `pipelineStringToJsonSync`
7718
+ // Note: [🍣] Do nothing, its application is implemented separately in `precompilePipeline`
7768
7719
  },
7769
7720
  /**
7770
7721
  * Apply the PARAMETER command to the `pipelineJson`
@@ -7772,7 +7723,7 @@
7772
7723
  * Note: `$` is used to indicate that this function mutates given `taskJson`
7773
7724
  */
7774
7725
  $applyToTaskJson: function (command, $taskJson, $pipelineJson) {
7775
- // Note: [🍣] Do nothing, its application is implemented separately in `pipelineStringToJsonSync`
7726
+ // Note: [🍣] Do nothing, its application is implemented separately in `precompilePipeline`
7776
7727
  },
7777
7728
  /**
7778
7729
  * Converts the PARAMETER command back to string
@@ -8280,7 +8231,7 @@
8280
8231
  * @returns the parser for the command
8281
8232
  * @throws {UnexpectedError} if the parser is not found
8282
8233
  *
8283
- * @private within the pipelineStringToJson
8234
+ * @private within the compilePipeline
8284
8235
  */
8285
8236
  function getParserForCommand(command) {
8286
8237
  var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
@@ -8316,7 +8267,7 @@
8316
8267
  * @returns parsed command object
8317
8268
  * @throws {ParseError} if the command is invalid
8318
8269
  *
8319
- * @private within the pipelineStringToJson
8270
+ * @private within the compilePipeline
8320
8271
  */
8321
8272
  function parseCommand(raw, usagePlace) {
8322
8273
  if (raw.includes('\n') || raw.includes('\r')) {
@@ -8454,6 +8405,295 @@
8454
8405
  return null;
8455
8406
  }
8456
8407
 
8408
+ /**
8409
+ * @@@
8410
+ *
8411
+ * @deprecated https://github.com/webgptorg/promptbook/pull/186
8412
+ * @see https://github.com/webgptorg/promptbook/discussions/171
8413
+ *
8414
+ * @public exported from `@promptbook/core`
8415
+ */
8416
+ function getPipelineInterface(pipeline) {
8417
+ var e_1, _a, e_2, _b;
8418
+ var pipelineInterface = {
8419
+ inputParameters: [],
8420
+ outputParameters: [],
8421
+ };
8422
+ try {
8423
+ for (var _c = __values(pipeline.parameters), _d = _c.next(); !_d.done; _d = _c.next()) {
8424
+ var parameter = _d.value;
8425
+ var isInput = parameter.isInput, isOutput = parameter.isOutput;
8426
+ if (isInput) {
8427
+ pipelineInterface.inputParameters.push(deepClone(parameter));
8428
+ }
8429
+ if (isOutput) {
8430
+ pipelineInterface.outputParameters.push(deepClone(parameter));
8431
+ }
8432
+ }
8433
+ }
8434
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
8435
+ finally {
8436
+ try {
8437
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
8438
+ }
8439
+ finally { if (e_1) throw e_1.error; }
8440
+ }
8441
+ try {
8442
+ for (var _e = __values(['inputParameters', 'outputParameters']), _f = _e.next(); !_f.done; _f = _e.next()) {
8443
+ var key = _f.value;
8444
+ pipelineInterface[key].sort(function (_a, _b) {
8445
+ var name1 = _a.name;
8446
+ var name2 = _b.name;
8447
+ return name1.localeCompare(name2);
8448
+ });
8449
+ }
8450
+ }
8451
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
8452
+ finally {
8453
+ try {
8454
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
8455
+ }
8456
+ finally { if (e_2) throw e_2.error; }
8457
+ }
8458
+ return exportJson({
8459
+ name: "pipelineInterface",
8460
+ message: "Result of `getPipelineInterface`",
8461
+ order: ['inputParameters', 'outputParameters'],
8462
+ value: pipelineInterface,
8463
+ });
8464
+ }
8465
+
8466
+ /**
8467
+ * @@@
8468
+ *
8469
+ * @deprecated https://github.com/webgptorg/promptbook/pull/186
8470
+ * @see https://github.com/webgptorg/promptbook/discussions/171
8471
+ *
8472
+ * @public exported from `@promptbook/core`
8473
+ */
8474
+ function isPipelineInterfacesEqual(pipelineInterface1, pipelineInterface2) {
8475
+ var e_1, _a, e_2, _b;
8476
+ try {
8477
+ for (var _c = __values(['inputParameters', 'outputParameters']), _d = _c.next(); !_d.done; _d = _c.next()) {
8478
+ var whichParameters = _d.value;
8479
+ var parameters1 = pipelineInterface1[whichParameters]; // <- Note: `isPipelineInterfacesEqual` is just temporary solution, no need to fix this
8480
+ var parameters2 = pipelineInterface2[whichParameters];
8481
+ if (parameters1.length !== parameters2.length) {
8482
+ return false;
8483
+ }
8484
+ var _loop_1 = function (parameter) {
8485
+ var matchingParameter = parameters2.find(function (_a) {
8486
+ var name = _a.name;
8487
+ return name === parameter.name;
8488
+ });
8489
+ if (!matchingParameter) {
8490
+ return { value: false };
8491
+ }
8492
+ // Note: Do not compare description, it is not relevant for compatibility
8493
+ if (matchingParameter.isInput !== parameter.isInput) {
8494
+ return { value: false };
8495
+ }
8496
+ if (matchingParameter.isOutput !== parameter.isOutput) {
8497
+ return { value: false };
8498
+ }
8499
+ };
8500
+ try {
8501
+ for (var parameters1_1 = (e_2 = void 0, __values(parameters1)), parameters1_1_1 = parameters1_1.next(); !parameters1_1_1.done; parameters1_1_1 = parameters1_1.next()) {
8502
+ var parameter = parameters1_1_1.value;
8503
+ var state_1 = _loop_1(parameter);
8504
+ if (typeof state_1 === "object")
8505
+ return state_1.value;
8506
+ }
8507
+ }
8508
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
8509
+ finally {
8510
+ try {
8511
+ if (parameters1_1_1 && !parameters1_1_1.done && (_b = parameters1_1.return)) _b.call(parameters1_1);
8512
+ }
8513
+ finally { if (e_2) throw e_2.error; }
8514
+ }
8515
+ }
8516
+ }
8517
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
8518
+ finally {
8519
+ try {
8520
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
8521
+ }
8522
+ finally { if (e_1) throw e_1.error; }
8523
+ }
8524
+ return true;
8525
+ }
8526
+
8527
+ /**
8528
+ * @@@
8529
+ *
8530
+ * @deprecated https://github.com/webgptorg/promptbook/pull/186
8531
+ * @see https://github.com/webgptorg/promptbook/discussions/171
8532
+ *
8533
+ * @public exported from `@promptbook/core`
8534
+ */
8535
+ function isPipelineImplementingInterface(options) {
8536
+ var pipeline = options.pipeline, pipelineInterface = options.pipelineInterface;
8537
+ return isPipelineInterfacesEqual(getPipelineInterface(pipeline), pipelineInterface);
8538
+ }
8539
+
8540
+ /**
8541
+ * Set formfactor based on the pipeline interface e
8542
+ *
8543
+ * @private
8544
+ */
8545
+ var ImplicitFormfactorHla = {
8546
+ type: 'SYNC',
8547
+ $applyToPipelineJson: function ($pipelineJson) {
8548
+ var e_1, _a;
8549
+ if ($pipelineJson.formfactorName !== undefined) {
8550
+ // Note: When formfactor is already set, do nothing
8551
+ return;
8552
+ }
8553
+ try {
8554
+ for (var _b = __values(FORMFACTOR_DEFINITIONS.filter(function (_a) {
8555
+ var name = _a.name;
8556
+ return name !== 'GENERIC';
8557
+ })), _c = _b.next(); !_c.done; _c = _b.next()) {
8558
+ var formfactorDefinition = _c.value;
8559
+ // <- Note: [♓️][💩] This is the order of the formfactors, make some explicit priority
8560
+ var name_1 = formfactorDefinition.name, pipelineInterface = formfactorDefinition.pipelineInterface;
8561
+ var isCompatible = isPipelineImplementingInterface({
8562
+ pipeline: __assign({ formfactorName: name_1 }, $pipelineJson),
8563
+ pipelineInterface: pipelineInterface,
8564
+ });
8565
+ /*/
8566
+ console.log({
8567
+ subject: `${$pipelineJson.title} implements ${name}`,
8568
+ pipelineTitle: $pipelineJson.title,
8569
+ formfactorName: name,
8570
+ isCompatible,
8571
+ formfactorInterface: pipelineInterface,
8572
+ pipelineInterface: getPipelineInterface($pipelineJson as PipelineJson),
8573
+ });
8574
+ /**/
8575
+ if (isCompatible) {
8576
+ $pipelineJson.formfactorName = name_1;
8577
+ return;
8578
+ }
8579
+ }
8580
+ }
8581
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
8582
+ finally {
8583
+ try {
8584
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
8585
+ }
8586
+ finally { if (e_1) throw e_1.error; }
8587
+ }
8588
+ },
8589
+ };
8590
+
8591
+ /**
8592
+ * Allow to define chatbot with no need to write full interface
8593
+ *
8594
+ * @private
8595
+ */
8596
+ var QuickChatbotHla = {
8597
+ type: 'SYNC',
8598
+ $applyToPipelineJson: function ($pipelineJson) {
8599
+ if ($pipelineJson.tasks.length !== 0) {
8600
+ // Note: When there are already tasks, do nothing
8601
+ return;
8602
+ }
8603
+ if ($pipelineJson.parameters.length !== 0) {
8604
+ // Note: When there are already parameters, do nothing
8605
+ return;
8606
+ }
8607
+ if ($pipelineJson.personas.length === 0) {
8608
+ // Note: When no personas defined, do nothing
8609
+ return;
8610
+ }
8611
+ var personaName = $pipelineJson.personas[0].name;
8612
+ $pipelineJson.formfactorName = 'CHATBOT';
8613
+ $pipelineJson.parameters.push({
8614
+ name: 'previousTitle',
8615
+ description: 'Previous title of the conversation',
8616
+ isInput: true,
8617
+ isOutput: false,
8618
+ }, {
8619
+ name: 'previousConversationSummary',
8620
+ description: 'Previous conversation summary',
8621
+ isInput: true,
8622
+ isOutput: false,
8623
+ }, {
8624
+ name: 'userMessage',
8625
+ description: 'User message',
8626
+ isInput: true,
8627
+ isOutput: false,
8628
+ }, {
8629
+ name: 'title',
8630
+ description: 'Title of the conversation',
8631
+ isInput: false,
8632
+ isOutput: true,
8633
+ }, {
8634
+ name: 'conversationSummary',
8635
+ description: 'Summary of the conversation',
8636
+ isInput: false,
8637
+ isOutput: true,
8638
+ }, {
8639
+ name: 'chatbotResponse',
8640
+ description: 'Chatbot response',
8641
+ isInput: false,
8642
+ isOutput: true,
8643
+ exampleValues: ['Hello, I am a Pavol`s virtual avatar. How can I help you?'],
8644
+ });
8645
+ // TODO: !!!!!! spaceTrim
8646
+ $pipelineJson.tasks.push({
8647
+ taskType: 'PROMPT_TASK',
8648
+ name: 'create-an-answer',
8649
+ title: 'Create an answer',
8650
+ content: 'Write a response to the user message:\n\n**Question from user**\n\n> {userMessage}\n\n**Previous conversation**\n\n> {previousConversationSummary}',
8651
+ resultingParameterName: 'chatbotResponse',
8652
+ personaName: personaName,
8653
+ dependentParameterNames: ['userMessage', 'previousConversationSummary' /* !!!!!!, 'knowledge'*/],
8654
+ // !!!!!! preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
8655
+ }, {
8656
+ taskType: 'PROMPT_TASK',
8657
+ name: 'summarize-the-conversation',
8658
+ title: 'Summarize the conversation',
8659
+ content: 'Summarize the conversation in a few words:\n\n## Rules\n\n- Summarise the text of the conversation in a few words\n- Convert the text to its basic idea\n- Imagine you are writing the headline or subject line of an email\n- Respond with a few words of summary only\n\n## Conversation\n\n**User:**\n\n> {userMessage}\n\n**You:**\n\n> {chatbotResponse}',
8660
+ resultingParameterName: 'conversationSummary',
8661
+ personaName: personaName,
8662
+ expectations: {
8663
+ words: {
8664
+ min: 1,
8665
+ max: 10,
8666
+ },
8667
+ },
8668
+ dependentParameterNames: ['userMessage', 'chatbotResponse' /* !!!!!!, 'knowledge'*/],
8669
+ // !!!!!! preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
8670
+ }, {
8671
+ taskType: 'SIMPLE_TASK',
8672
+ name: 'title',
8673
+ title: 'Title',
8674
+ content: '{conversationSummary}',
8675
+ resultingParameterName: 'title',
8676
+ dependentParameterNames: ['conversationSummary' /* !!!!!!, 'knowledge'*/],
8677
+ // !!!!!! preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
8678
+ });
8679
+ },
8680
+ };
8681
+
8682
+ /**
8683
+ * All high-level abstractions
8684
+ *
8685
+ * @private internal index of `precompilePipeline` (= used for sync) and `preparePipeline` (= used for async)
8686
+ */
8687
+ var HIGH_LEVEL_ABSTRACTIONS = [
8688
+ ImplicitFormfactorHla,
8689
+ QuickChatbotHla,
8690
+ // <- Note: [♓️][💩] This is the order of the application of high-level abstractions application on pipeline JSON
8691
+ ];
8692
+ /**
8693
+ * TODO: Test that all sync high-level abstractions are before async high-level abstractions
8694
+ * Note: [💞] Ignore a discrepancy between file name and entity name
8695
+ */
8696
+
8457
8697
  /**
8458
8698
  * Supported script languages
8459
8699
  *
@@ -8716,8 +8956,8 @@
8716
8956
  * Compile pipeline from string (markdown) format to JSON format synchronously
8717
8957
  *
8718
8958
  * Note: There are 3 similar functions:
8719
- * - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
8720
- * - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
8959
+ * - `compilePipeline` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
8960
+ * - `precompilePipeline` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
8721
8961
  * - `preparePipeline` - just one step in the compilation process
8722
8962
  *
8723
8963
  * Note: This function does not validate logic of the pipeline only the parsing
@@ -8728,7 +8968,7 @@
8728
8968
  * @throws {ParseError} if the promptbook string is not valid
8729
8969
  * @public exported from `@promptbook/core`
8730
8970
  */
8731
- function pipelineStringToJsonSync(pipelineString) {
8971
+ function precompilePipeline(pipelineString) {
8732
8972
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
8733
8973
  var $pipelineJson = {
8734
8974
  title: DEFAULT_TITLE,
@@ -8828,7 +9068,7 @@
8828
9068
  }
8829
9069
  try {
8830
9070
  commandParser.$applyToPipelineJson(command, $pipelineJson);
8831
- // <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitelly
9071
+ // <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitly
8832
9072
  }
8833
9073
  catch (error) {
8834
9074
  if (!(error instanceof ParseError)) {
@@ -8885,10 +9125,10 @@
8885
9125
  return nameWithSuffix;
8886
9126
  };
8887
9127
  var _loop_2 = function (section) {
8888
- var e_7, _o, e_8, _p;
9128
+ var e_7, _q, e_8, _r;
8889
9129
  // TODO: Parse section's description (the content out of the codeblock and lists)
8890
9130
  var listItems_2 = extractAllListItemsFromMarkdown(section.content);
8891
- var _q = extractOneBlockFromMarkdown(section.content), language = _q.language, content = _q.content;
9131
+ var _s = extractOneBlockFromMarkdown(section.content), language = _s.language, content = _s.content;
8892
9132
  // TODO: [🎾][1] DRY description
8893
9133
  var description_1 = section.content;
8894
9134
  // Note: Remove codeblocks - TODO: [🎾]
@@ -8936,7 +9176,7 @@
8936
9176
  }
8937
9177
  try {
8938
9178
  commandParser.$applyToTaskJson(
8939
- // <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitelly
9179
+ // <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitly
8940
9180
  command, $taskJson, $pipelineJson);
8941
9181
  }
8942
9182
  catch (error) {
@@ -8953,14 +9193,14 @@
8953
9193
  try {
8954
9194
  // TODO [♓️] List commands and before apply order them to achieve order-agnostic commands
8955
9195
  for (var commands_1 = (e_7 = void 0, __values(commands)), commands_1_1 = commands_1.next(); !commands_1_1.done; commands_1_1 = commands_1.next()) {
8956
- var _r = commands_1_1.value, listItem = _r.listItem, command = _r.command;
9196
+ var _t = commands_1_1.value, listItem = _t.listItem, command = _t.command;
8957
9197
  _loop_4(listItem, command);
8958
9198
  }
8959
9199
  }
8960
9200
  catch (e_7_1) { e_7 = { error: e_7_1 }; }
8961
9201
  finally {
8962
9202
  try {
8963
- if (commands_1_1 && !commands_1_1.done && (_o = commands_1.return)) _o.call(commands_1);
9203
+ if (commands_1_1 && !commands_1_1.done && (_q = commands_1.return)) _q.call(commands_1);
8964
9204
  }
8965
9205
  finally { if (e_7) throw e_7.error; }
8966
9206
  }
@@ -8976,8 +9216,8 @@
8976
9216
  }
8977
9217
  $taskJson.dependentParameterNames = Array.from(extractParameterNamesFromTask($taskJson));
8978
9218
  try {
8979
- for (var _s = (e_8 = void 0, __values($taskJson.dependentParameterNames)), _t = _s.next(); !_t.done; _t = _s.next()) {
8980
- var parameterName = _t.value;
9219
+ for (var _u = (e_8 = void 0, __values($taskJson.dependentParameterNames)), _v = _u.next(); !_v.done; _v = _u.next()) {
9220
+ var parameterName = _v.value;
8981
9221
  // TODO: [🧠] This definition should be made first in the task
8982
9222
  defineParam({
8983
9223
  parameterName: parameterName,
@@ -8991,7 +9231,7 @@
8991
9231
  catch (e_8_1) { e_8 = { error: e_8_1 }; }
8992
9232
  finally {
8993
9233
  try {
8994
- if (_t && !_t.done && (_p = _s.return)) _p.call(_s);
9234
+ if (_v && !_v.done && (_r = _u.return)) _r.call(_u);
8995
9235
  }
8996
9236
  finally { if (e_8) throw e_8.error; }
8997
9237
  }
@@ -9122,53 +9362,39 @@
9122
9362
  });
9123
9363
  try {
9124
9364
  // =============================================================
9125
- // Note: 9️⃣ Implicit and default formfactor
9126
- for (var FORMFACTOR_DEFINITIONS_1 = __values(FORMFACTOR_DEFINITIONS), FORMFACTOR_DEFINITIONS_1_1 = FORMFACTOR_DEFINITIONS_1.next(); !FORMFACTOR_DEFINITIONS_1_1.done; FORMFACTOR_DEFINITIONS_1_1 = FORMFACTOR_DEFINITIONS_1.next()) {
9127
- var formfactorDefinition = FORMFACTOR_DEFINITIONS_1_1.value;
9128
- // <- Note: [♓️][💩] This is the order of the formfactors, make some explicit priority
9129
- var name_2 = formfactorDefinition.name, pipelineInterface = formfactorDefinition.pipelineInterface;
9130
- // Note: Skip GENERIC formfactor, it will be used as a fallback if no other formfactor is compatible
9131
- if (name_2 === 'GENERIC') {
9132
- continue;
9133
- }
9134
- var isCompatible = isPipelineImplementingInterface({
9135
- pipeline: __assign({ formfactorName: name_2 }, $pipelineJson),
9136
- pipelineInterface: pipelineInterface,
9137
- });
9138
- /*/
9139
- console.log({
9140
- subject: `${$pipelineJson.title} implements ${name}`,
9141
- pipelineTitle: $pipelineJson.title,
9142
- formfactorName: name,
9143
- isCompatible,
9144
- formfactorInterface: pipelineInterface,
9145
- pipelineInterface: getPipelineInterface($pipelineJson as PipelineJson),
9146
- });
9147
- /**/
9148
- if (isCompatible) {
9149
- $pipelineJson.formfactorName = name_2;
9150
- break;
9151
- }
9365
+ // Note: 9️⃣ Apply sync high-level abstractions
9366
+ for (var _o = __values(HIGH_LEVEL_ABSTRACTIONS.filter(function (_a) {
9367
+ var type = _a.type;
9368
+ return type === 'SYNC';
9369
+ })), _p = _o.next(); !_p.done; _p = _o.next()) {
9370
+ var highLevelAbstraction = _p.value;
9371
+ highLevelAbstraction.$applyToPipelineJson($pipelineJson);
9152
9372
  }
9153
9373
  }
9154
9374
  catch (e_6_1) { e_6 = { error: e_6_1 }; }
9155
9375
  finally {
9156
9376
  try {
9157
- if (FORMFACTOR_DEFINITIONS_1_1 && !FORMFACTOR_DEFINITIONS_1_1.done && (_f = FORMFACTOR_DEFINITIONS_1.return)) _f.call(FORMFACTOR_DEFINITIONS_1);
9377
+ if (_p && !_p.done && (_f = _o.return)) _f.call(_o);
9158
9378
  }
9159
9379
  finally { if (e_6) throw e_6.error; }
9160
9380
  }
9381
+ // =============================================================
9382
+ // Note: 🔟 Default formfactor
9161
9383
  // Note: [🔆] If formfactor is still not set, set it to 'GENERIC'
9162
9384
  if ($pipelineJson.formfactorName === undefined) {
9163
9385
  $pipelineJson.formfactorName = 'GENERIC';
9164
9386
  }
9165
9387
  // =============================================================
9166
9388
  // TODO: [🍙] Maybe do reorder of `$pipelineJson` here
9167
- return $asDeeplyFrozenSerializableJson('pipelineJson', __assign({ title: DEFAULT_TITLE, pipelineUrl: undefined, bookVersion: undefined, description: undefined, formfactorName: 'GENERIC',
9168
- // <- Note: [🔆] Setting `formfactorName` is redundant to satisfy the typescript
9169
- parameters: [], tasks: [], knowledgeSources: [], knowledgePieces: [], personas: [], preparations: [] }, $pipelineJson));
9389
+ return exportJson({
9390
+ name: 'pipelineJson',
9391
+ message: "Result of `precompilePipeline`",
9392
+ order: ORDER_OF_PIPELINE_JSON,
9393
+ value: __assign({ formfactorName: 'GENERIC' }, $pipelineJson),
9394
+ });
9170
9395
  }
9171
9396
  /**
9397
+ * TODO: [🧠] Maybe more things here can be refactored as high-level abstractions
9172
9398
  * TODO: [main] !!!! Warn if used only sync version
9173
9399
  * TODO: [🚞] Report here line/column of error
9174
9400
  * TODO: Use spaceTrim more effectively
@@ -9183,8 +9409,8 @@
9183
9409
  * Compile pipeline from string (markdown) format to JSON format
9184
9410
  *
9185
9411
  * Note: There are 3 similar functions:
9186
- * - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
9187
- * - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
9412
+ * - `compilePipeline` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
9413
+ * - `precompilePipeline` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
9188
9414
  * - `preparePipeline` - just one step in the compilation process
9189
9415
  *
9190
9416
  * Note: This function does not validate logic of the pipeline only the parsing
@@ -9197,13 +9423,13 @@
9197
9423
  * @throws {ParseError} if the promptbook string is not valid
9198
9424
  * @public exported from `@promptbook/core`
9199
9425
  */
9200
- function pipelineStringToJson(pipelineString, tools, options) {
9426
+ function compilePipeline(pipelineString, tools, options) {
9201
9427
  return __awaiter(this, void 0, void 0, function () {
9202
9428
  var pipelineJson;
9203
9429
  return __generator(this, function (_a) {
9204
9430
  switch (_a.label) {
9205
9431
  case 0:
9206
- pipelineJson = pipelineStringToJsonSync(pipelineString);
9432
+ pipelineJson = precompilePipeline(pipelineString);
9207
9433
  if (!(tools !== undefined && tools.llm !== undefined)) return [3 /*break*/, 2];
9208
9434
  return [4 /*yield*/, preparePipeline(pipelineJson, tools, options || {
9209
9435
  rootDirname: null,
@@ -9212,7 +9438,7 @@
9212
9438
  pipelineJson = _a.sent();
9213
9439
  _a.label = 2;
9214
9440
  case 2:
9215
- // Note: No need to use `$asDeeplyFrozenSerializableJson` because `pipelineStringToJsonSync` and `preparePipeline` already do that
9441
+ // Note: No need to use `$exportJson` because `precompilePipeline` and `preparePipeline` already do that
9216
9442
  return [2 /*return*/, pipelineJson];
9217
9443
  }
9218
9444
  });
@@ -9329,7 +9555,7 @@
9329
9555
  case 0:
9330
9556
  isGraphAdded = options.isGraphAdded, isPrettifyed = options.isPrettifyed;
9331
9557
  if (!isGraphAdded) return [3 /*break*/, 2];
9332
- return [4 /*yield*/, pipelineStringToJson(pipelineString)];
9558
+ return [4 /*yield*/, compilePipeline(pipelineString)];
9333
9559
  case 1:
9334
9560
  pipelineJson = _a.sent();
9335
9561
  promptbookMermaid_1 = renderPromptbookMermaid(pipelineJson, {
@@ -9466,6 +9692,7 @@
9466
9692
  return renamedPipeline;
9467
9693
  }
9468
9694
 
9695
+ // <- TODO: !!!!!!! Auto convert to type `import { ... } from 'type-fest';`
9469
9696
  /**
9470
9697
  * Tests if the value is [🚉] serializable as JSON
9471
9698
  *
@@ -9487,7 +9714,7 @@
9487
9714
  */
9488
9715
  function isSerializableAsJson(value) {
9489
9716
  try {
9490
- checkSerializableAsJson('', value);
9717
+ checkSerializableAsJson({ value: value });
9491
9718
  return true;
9492
9719
  }
9493
9720
  catch (error) {
@@ -10702,7 +10929,7 @@
10702
10929
  'LibreOffice',
10703
10930
  // <- TODO: [🧠] Should be 'LibreOffice' here, its dependency of dependency
10704
10931
  ],
10705
- }); /* <- TODO: [🤛] */
10932
+ }); /* <- Note: [🤛] */
10706
10933
  /**
10707
10934
  * Registration of known scraper metadata
10708
10935
  *
@@ -10729,7 +10956,7 @@
10729
10956
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
10730
10957
  isAvilableInBrowser: false,
10731
10958
  requiredExecutables: ['Pandoc'],
10732
- }); /* <- TODO: [🤛] */
10959
+ }); /* <- Note: [🤛] */
10733
10960
  /**
10734
10961
  * Registration of known scraper metadata
10735
10962
  *
@@ -10756,7 +10983,7 @@
10756
10983
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
10757
10984
  isAvilableInBrowser: true,
10758
10985
  requiredExecutables: [],
10759
- }); /* <- TODO: [🤛] */
10986
+ }); /* <- Note: [🤛] */
10760
10987
  /**
10761
10988
  * Registration of known scraper metadata
10762
10989
  *
@@ -10783,7 +11010,7 @@
10783
11010
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
10784
11011
  isAvilableInBrowser: true,
10785
11012
  requiredExecutables: [],
10786
- }); /* <- TODO: [🤛] */
11013
+ }); /* <- Note: [🤛] */
10787
11014
  /**
10788
11015
  * Registration of known scraper metadata
10789
11016
  *
@@ -10810,7 +11037,7 @@
10810
11037
  documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
10811
11038
  isAvilableInBrowser: false,
10812
11039
  requiredExecutables: [],
10813
- }); /* <- TODO: [🤛] */
11040
+ }); /* <- Note: [🤛] */
10814
11041
  /**
10815
11042
  * Registration of known scraper metadata
10816
11043
  *
@@ -10959,6 +11186,7 @@
10959
11186
  exports.NonTaskSectionTypes = NonTaskSectionTypes;
10960
11187
  exports.NotFoundError = NotFoundError;
10961
11188
  exports.NotYetImplementedError = NotYetImplementedError;
11189
+ exports.ORDER_OF_PIPELINE_JSON = ORDER_OF_PIPELINE_JSON;
10962
11190
  exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
10963
11191
  exports.PROMPTBOOK_ERRORS = PROMPTBOOK_ERRORS;
10964
11192
  exports.ParseError = ParseError;
@@ -10990,6 +11218,7 @@
10990
11218
  exports.assertsExecutionSuccessful = assertsExecutionSuccessful;
10991
11219
  exports.cacheLlmTools = cacheLlmTools;
10992
11220
  exports.collectionToJson = collectionToJson;
11221
+ exports.compilePipeline = compilePipeline;
10993
11222
  exports.countTotalUsage = countTotalUsage;
10994
11223
  exports.createCollectionFromJson = createCollectionFromJson;
10995
11224
  exports.createCollectionFromPromise = createCollectionFromPromise;
@@ -11009,8 +11238,7 @@
11009
11238
  exports.limitTotalUsage = limitTotalUsage;
11010
11239
  exports.makeKnowledgeSourceHandler = makeKnowledgeSourceHandler;
11011
11240
  exports.pipelineJsonToString = pipelineJsonToString;
11012
- exports.pipelineStringToJson = pipelineStringToJson;
11013
- exports.pipelineStringToJsonSync = pipelineStringToJsonSync;
11241
+ exports.precompilePipeline = precompilePipeline;
11014
11242
  exports.prepareKnowledgePieces = prepareKnowledgePieces;
11015
11243
  exports.preparePersona = preparePersona;
11016
11244
  exports.preparePipeline = preparePipeline;