@promptbook/core 0.78.4 → 0.80.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/esm/index.es.js +856 -568
- package/esm/index.es.js.map +1 -1
- package/esm/typings/books/index.d.ts +6 -6
- package/esm/typings/src/_packages/core.index.d.ts +4 -2
- package/esm/typings/src/_packages/types.index.d.ts +10 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -0
- package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +32 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +5 -2
- package/esm/typings/src/config.d.ts +0 -25
- package/esm/typings/src/constants.d.ts +35 -0
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -0
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
- package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +6 -1
- package/esm/typings/src/formfactors/index.d.ts +12 -2
- package/esm/typings/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +6 -1
- package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +20 -0
- package/esm/typings/src/high-level-abstractions/implicit-formfactor/ImplicitFormfactorHla.d.ts +10 -0
- package/esm/typings/src/high-level-abstractions/index.d.ts +44 -0
- package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +10 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/esm/typings/src/prepare/prepareTasks.d.ts +1 -0
- package/esm/typings/src/types/typeAliases.d.ts +1 -1
- package/esm/typings/src/utils/normalization/orderJson.d.ts +21 -0
- package/esm/typings/src/utils/normalization/orderJson.test.d.ts +4 -0
- package/esm/typings/src/utils/organization/keepTypeImported.d.ts +9 -0
- package/esm/typings/src/utils/serialization/$deepFreeze.d.ts +1 -1
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +20 -2
- package/esm/typings/src/utils/serialization/deepClone.test.d.ts +1 -0
- package/esm/typings/src/utils/serialization/exportJson.d.ts +29 -0
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +2 -1
- package/package.json +2 -1
- package/umd/index.umd.js +856 -567
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +0 -17
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.79.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
|
-
*
|
|
658
|
+
* Orders JSON object by keys
|
|
694
659
|
*
|
|
695
|
-
* @
|
|
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
|
-
*
|
|
670
|
+
* Freezes the given object and all its nested objects recursively
|
|
713
671
|
*
|
|
714
|
-
*
|
|
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
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
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
|
-
|
|
725
|
-
|
|
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
|
|
@@ -1225,195 +1500,18 @@
|
|
|
1225
1500
|
for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
|
|
1226
1501
|
var match = matches_1_1.value;
|
|
1227
1502
|
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
|
-
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;
|
|
1503
|
+
parameterNames.add(parameterName);
|
|
1386
1504
|
}
|
|
1387
1505
|
}
|
|
1388
|
-
|
|
1389
|
-
|
|
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; }
|
|
1390
1512
|
}
|
|
1513
|
+
return parameterNames;
|
|
1391
1514
|
}
|
|
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
1515
|
|
|
1418
1516
|
/**
|
|
1419
1517
|
* Unprepare just strips the preparation data of the pipeline
|
|
@@ -1432,7 +1530,12 @@
|
|
|
1432
1530
|
delete taskUnprepared.preparedContent;
|
|
1433
1531
|
return taskUnprepared;
|
|
1434
1532
|
});
|
|
1435
|
-
return
|
|
1533
|
+
return exportJson({
|
|
1534
|
+
name: 'pipelineJson',
|
|
1535
|
+
message: "Result of `unpreparePipeline`",
|
|
1536
|
+
order: ORDER_OF_PIPELINE_JSON,
|
|
1537
|
+
value: __assign(__assign({}, pipeline), { tasks: tasks, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }),
|
|
1538
|
+
});
|
|
1436
1539
|
}
|
|
1437
1540
|
/**
|
|
1438
1541
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -1895,29 +1998,6 @@
|
|
|
1895
1998
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
1896
1999
|
*/
|
|
1897
2000
|
|
|
1898
|
-
/**
|
|
1899
|
-
* @@@
|
|
1900
|
-
*
|
|
1901
|
-
* @public exported from `@promptbook/utils`
|
|
1902
|
-
*/
|
|
1903
|
-
function deepClone(objectValue) {
|
|
1904
|
-
return JSON.parse(JSON.stringify(objectValue));
|
|
1905
|
-
/*
|
|
1906
|
-
TODO: [🧠] Is there a better implementation?
|
|
1907
|
-
> const propertyNames = Object.getOwnPropertyNames(objectValue);
|
|
1908
|
-
> for (const propertyName of propertyNames) {
|
|
1909
|
-
> const value = (objectValue as really_any)[propertyName];
|
|
1910
|
-
> if (value && typeof value === 'object') {
|
|
1911
|
-
> deepClone(value);
|
|
1912
|
-
> }
|
|
1913
|
-
> }
|
|
1914
|
-
> return Object.assign({}, objectValue);
|
|
1915
|
-
*/
|
|
1916
|
-
}
|
|
1917
|
-
/**
|
|
1918
|
-
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
1919
|
-
*/
|
|
1920
|
-
|
|
1921
2001
|
/**
|
|
1922
2002
|
* Function `addUsage` will add multiple usages into one
|
|
1923
2003
|
*
|
|
@@ -2385,7 +2465,7 @@
|
|
|
2385
2465
|
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2386
2466
|
*/
|
|
2387
2467
|
|
|
2388
|
-
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"]}],
|
|
2468
|
+
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"}];
|
|
2389
2469
|
|
|
2390
2470
|
/**
|
|
2391
2471
|
* This error indicates problems parsing the format value
|
|
@@ -4657,16 +4737,21 @@
|
|
|
4657
4737
|
// Note: Wait a short time to prevent race conditions
|
|
4658
4738
|
_g.sent();
|
|
4659
4739
|
_g.label = 6;
|
|
4660
|
-
case 6: return [2 /*return*/,
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4740
|
+
case 6: return [2 /*return*/, exportJson({
|
|
4741
|
+
name: "executionReport",
|
|
4742
|
+
message: "Unuccessful PipelineExecutorResult (with missing parameter {".concat(parameter.name, "}) PipelineExecutorResult"),
|
|
4743
|
+
order: [],
|
|
4744
|
+
value: {
|
|
4745
|
+
isSuccessful: false,
|
|
4746
|
+
errors: __spreadArray([
|
|
4747
|
+
new PipelineExecutionError("Parameter `{".concat(parameter.name, "}` is required as an input parameter"))
|
|
4748
|
+
], __read(errors), false).map(serializeError),
|
|
4749
|
+
warnings: [],
|
|
4750
|
+
executionReport: executionReport,
|
|
4751
|
+
outputParameters: {},
|
|
4752
|
+
usage: ZERO_USAGE,
|
|
4753
|
+
preparedPipeline: preparedPipeline,
|
|
4754
|
+
},
|
|
4670
4755
|
})];
|
|
4671
4756
|
case 7:
|
|
4672
4757
|
_b = _a.next();
|
|
@@ -4705,16 +4790,21 @@
|
|
|
4705
4790
|
// Note: Wait a short time to prevent race conditions
|
|
4706
4791
|
_h.sent();
|
|
4707
4792
|
_h.label = 3;
|
|
4708
|
-
case 3: return [2 /*return*/, { value:
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4793
|
+
case 3: return [2 /*return*/, { value: exportJson({
|
|
4794
|
+
name: 'pipelineExecutorResult',
|
|
4795
|
+
message: spaceTrim.spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }),
|
|
4796
|
+
order: [],
|
|
4797
|
+
value: {
|
|
4798
|
+
isSuccessful: false,
|
|
4799
|
+
errors: __spreadArray([
|
|
4800
|
+
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 "); }))
|
|
4801
|
+
], __read(errors), false).map(serializeError),
|
|
4802
|
+
warnings: warnings.map(serializeError),
|
|
4803
|
+
executionReport: executionReport,
|
|
4804
|
+
outputParameters: {},
|
|
4805
|
+
usage: ZERO_USAGE,
|
|
4806
|
+
preparedPipeline: preparedPipeline,
|
|
4807
|
+
},
|
|
4718
4808
|
}) }];
|
|
4719
4809
|
case 4: return [2 /*return*/];
|
|
4720
4810
|
}
|
|
@@ -4868,14 +4958,19 @@
|
|
|
4868
4958
|
// Note: Wait a short time to prevent race conditions
|
|
4869
4959
|
_g.sent();
|
|
4870
4960
|
_g.label = 27;
|
|
4871
|
-
case 27: return [2 /*return*/,
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4961
|
+
case 27: return [2 /*return*/, exportJson({
|
|
4962
|
+
name: 'pipelineExecutorResult',
|
|
4963
|
+
message: "Unuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult",
|
|
4964
|
+
order: [],
|
|
4965
|
+
value: {
|
|
4966
|
+
isSuccessful: false,
|
|
4967
|
+
errors: __spreadArray([error_1], __read(errors), false).map(serializeError),
|
|
4968
|
+
warnings: warnings.map(serializeError),
|
|
4969
|
+
usage: usage_1,
|
|
4970
|
+
executionReport: executionReport,
|
|
4971
|
+
outputParameters: outputParameters_1,
|
|
4972
|
+
preparedPipeline: preparedPipeline,
|
|
4973
|
+
},
|
|
4879
4974
|
})];
|
|
4880
4975
|
case 28:
|
|
4881
4976
|
usage = addUsage.apply(void 0, __spreadArray([], __read(executionReport.promptExecutions.map(function (_a) {
|
|
@@ -4896,14 +4991,19 @@
|
|
|
4896
4991
|
// Note: Wait a short time to prevent race conditions
|
|
4897
4992
|
_g.sent();
|
|
4898
4993
|
_g.label = 30;
|
|
4899
|
-
case 30: return [2 /*return*/,
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4994
|
+
case 30: return [2 /*return*/, exportJson({
|
|
4995
|
+
name: 'pipelineExecutorResult',
|
|
4996
|
+
message: "Successful PipelineExecutorResult",
|
|
4997
|
+
order: [],
|
|
4998
|
+
value: {
|
|
4999
|
+
isSuccessful: true,
|
|
5000
|
+
errors: errors.map(serializeError),
|
|
5001
|
+
warnings: warnings.map(serializeError),
|
|
5002
|
+
usage: usage,
|
|
5003
|
+
executionReport: executionReport,
|
|
5004
|
+
outputParameters: outputParameters,
|
|
5005
|
+
preparedPipeline: preparedPipeline,
|
|
5006
|
+
},
|
|
4907
5007
|
})];
|
|
4908
5008
|
}
|
|
4909
5009
|
});
|
|
@@ -5774,36 +5874,6 @@
|
|
|
5774
5874
|
* [ ] One piece can have multiple sources
|
|
5775
5875
|
*/
|
|
5776
5876
|
|
|
5777
|
-
/**
|
|
5778
|
-
* @@@
|
|
5779
|
-
*
|
|
5780
|
-
* Note: It is usefull @@@
|
|
5781
|
-
*
|
|
5782
|
-
* @param pipeline
|
|
5783
|
-
* @public exported from `@promptbook/utils`
|
|
5784
|
-
*/
|
|
5785
|
-
function clonePipeline(pipeline) {
|
|
5786
|
-
// Note: Not using spread operator (...) because @@@
|
|
5787
|
-
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;
|
|
5788
|
-
return {
|
|
5789
|
-
pipelineUrl: pipelineUrl,
|
|
5790
|
-
sourceFile: sourceFile,
|
|
5791
|
-
title: title,
|
|
5792
|
-
bookVersion: bookVersion,
|
|
5793
|
-
description: description,
|
|
5794
|
-
formfactorName: formfactorName,
|
|
5795
|
-
parameters: parameters,
|
|
5796
|
-
tasks: tasks,
|
|
5797
|
-
knowledgeSources: knowledgeSources,
|
|
5798
|
-
knowledgePieces: knowledgePieces,
|
|
5799
|
-
personas: personas,
|
|
5800
|
-
preparations: preparations,
|
|
5801
|
-
};
|
|
5802
|
-
}
|
|
5803
|
-
/**
|
|
5804
|
-
* TODO: [🍙] Make some standard order of json properties
|
|
5805
|
-
*/
|
|
5806
|
-
|
|
5807
5877
|
/**
|
|
5808
5878
|
* @@@
|
|
5809
5879
|
*
|
|
@@ -5844,6 +5914,7 @@
|
|
|
5844
5914
|
});
|
|
5845
5915
|
}
|
|
5846
5916
|
/**
|
|
5917
|
+
* TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
|
|
5847
5918
|
* TODO: [🧠] Add context to each task (if missing)
|
|
5848
5919
|
* TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
|
|
5849
5920
|
* TODO: [♨][main] !!! Prepare index the examples and maybe tasks
|
|
@@ -5932,11 +6003,19 @@
|
|
|
5932
6003
|
case 3:
|
|
5933
6004
|
tasksPrepared = (_c.sent()).tasksPrepared;
|
|
5934
6005
|
// ----- /Tasks preparation -----
|
|
6006
|
+
// TODO: [😂] Use here all `AsyncHighLevelAbstraction`
|
|
5935
6007
|
// Note: Count total usage
|
|
5936
6008
|
currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
|
|
5937
|
-
return [2 /*return*/,
|
|
5938
|
-
|
|
5939
|
-
|
|
6009
|
+
return [2 /*return*/, exportJson({
|
|
6010
|
+
name: 'pipelineJson',
|
|
6011
|
+
message: "Result of `preparePipeline`",
|
|
6012
|
+
order: ORDER_OF_PIPELINE_JSON,
|
|
6013
|
+
value: __assign(__assign({}, pipeline), {
|
|
6014
|
+
// <- TODO: Probbably deeply clone the pipeline because `$exportJson` freezes the subobjects
|
|
6015
|
+
knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, tasks: __spreadArray([], __read(tasksPrepared), false),
|
|
6016
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just ` tasks: tasksPrepared`
|
|
6017
|
+
personas: preparedPersonas, preparations: __spreadArray([], __read(preparations), false) }),
|
|
6018
|
+
})];
|
|
5940
6019
|
}
|
|
5941
6020
|
});
|
|
5942
6021
|
});
|
|
@@ -6200,7 +6279,8 @@
|
|
|
6200
6279
|
expectResultingParameterName();
|
|
6201
6280
|
var parameter = $pipelineJson.parameters.find(function (param) { return param.name === $taskJson.resultingParameterName; });
|
|
6202
6281
|
if (parameter === undefined) {
|
|
6203
|
-
|
|
6282
|
+
// TODO: !!!!!! Change to logic error for higher level abstractions to work
|
|
6283
|
+
throw new ParseError("Parameter `{".concat($taskJson.resultingParameterName, "}` is not defined so can not define example value of it"));
|
|
6204
6284
|
}
|
|
6205
6285
|
parameter.exampleValues = parameter.exampleValues || [];
|
|
6206
6286
|
parameter.exampleValues.push($taskJson.content);
|
|
@@ -7109,7 +7189,13 @@
|
|
|
7109
7189
|
documentationUrl: "https://github.com/webgptorg/promptbook/discussions/184",
|
|
7110
7190
|
pipelineInterface: {
|
|
7111
7191
|
inputParameters: [
|
|
7112
|
-
|
|
7192
|
+
/* @@@ */
|
|
7193
|
+
{
|
|
7194
|
+
name: 'nonce',
|
|
7195
|
+
description: 'Just to prevent GENERATOR to be set as implicit formfactor',
|
|
7196
|
+
isInput: true,
|
|
7197
|
+
isOutput: false,
|
|
7198
|
+
},
|
|
7113
7199
|
],
|
|
7114
7200
|
outputParameters: [
|
|
7115
7201
|
/* @@@ */
|
|
@@ -7155,7 +7241,13 @@
|
|
|
7155
7241
|
documentationUrl: "https://github.com/webgptorg/promptbook/discussions/177",
|
|
7156
7242
|
pipelineInterface: {
|
|
7157
7243
|
inputParameters: [
|
|
7158
|
-
|
|
7244
|
+
/* @@@ */
|
|
7245
|
+
{
|
|
7246
|
+
name: 'nonce',
|
|
7247
|
+
description: 'Just to prevent EXPERIMENTAL_MATCHER to be set as implicit formfactor',
|
|
7248
|
+
isInput: true,
|
|
7249
|
+
isOutput: false,
|
|
7250
|
+
},
|
|
7159
7251
|
],
|
|
7160
7252
|
outputParameters: [
|
|
7161
7253
|
/* @@@ */
|
|
@@ -7304,6 +7396,9 @@
|
|
|
7304
7396
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
7305
7397
|
*/
|
|
7306
7398
|
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
7399
|
+
if ($pipelineJson.formfactorName !== undefined && $pipelineJson.formfactorName !== command.formfactorName) {
|
|
7400
|
+
throw new ParseError(spaceTrim__default["default"]("\n Redefinition of `FORMFACTOR` in the pipeline head\n\n You have used:\n 1) FORMFACTOR `".concat($pipelineJson.formfactorName, "`\n 2) FORMFACTOR `").concat(command.formfactorName, "`\n ")));
|
|
7401
|
+
}
|
|
7307
7402
|
$pipelineJson.formfactorName = command.formfactorName;
|
|
7308
7403
|
},
|
|
7309
7404
|
/**
|
|
@@ -7491,7 +7586,7 @@
|
|
|
7491
7586
|
// <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
|
|
7492
7587
|
}
|
|
7493
7588
|
else {
|
|
7494
|
-
throw new ParseError(spaceTrim__default["default"]("\n Redefinition of MODEL
|
|
7589
|
+
throw new ParseError(spaceTrim__default["default"]("\n Redefinition of `MODEL ".concat(command.key, "` in the pipeline head\n\n You have used:\n 1) `MODEL ").concat(command.key, " ").concat($pipelineJson.defaultModelRequirements[command.key], "`\n 2) `MODEL ").concat(command.key, " ").concat(command.value, "`\n ")));
|
|
7495
7590
|
}
|
|
7496
7591
|
}
|
|
7497
7592
|
$pipelineJson.defaultModelRequirements[command.key] = command.value;
|
|
@@ -8243,71 +8338,360 @@
|
|
|
8243
8338
|
return command;
|
|
8244
8339
|
}
|
|
8245
8340
|
}
|
|
8246
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) {
|
|
8247
|
-
return "\n Malformed or unknown command:\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
8248
|
-
}));
|
|
8341
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) {
|
|
8342
|
+
return "\n Malformed or unknown command:\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
8343
|
+
}));
|
|
8344
|
+
}
|
|
8345
|
+
/**
|
|
8346
|
+
* @@@
|
|
8347
|
+
*/
|
|
8348
|
+
function getSupportedCommandsMessage() {
|
|
8349
|
+
return COMMANDS.flatMap(function (_a) {
|
|
8350
|
+
var name = _a.name, aliasNames = _a.aliasNames, description = _a.description, documentationUrl = _a.documentationUrl;
|
|
8351
|
+
// <- Note: [🦦] Its strange that this type assertion is needed
|
|
8352
|
+
return __spreadArray([
|
|
8353
|
+
"- **".concat(name, "** ").concat(description, ", see [discussion](").concat(documentationUrl, ")")
|
|
8354
|
+
], __read((aliasNames || []).map(function (aliasName) { return " - **".concat(aliasName, "** Alias for **").concat(name, "**"); })), false);
|
|
8355
|
+
}).join('\n');
|
|
8356
|
+
}
|
|
8357
|
+
/**
|
|
8358
|
+
* @@@
|
|
8359
|
+
*/
|
|
8360
|
+
function parseCommandVariant(input) {
|
|
8361
|
+
var e_1, _a;
|
|
8362
|
+
var commandNameRaw = input.commandNameRaw, usagePlace = input.usagePlace, normalized = input.normalized, args = input.args, raw = input.raw, rawArgs = input.rawArgs;
|
|
8363
|
+
var commandName = normalizeTo_SCREAMING_CASE(commandNameRaw);
|
|
8364
|
+
var _loop_1 = function (commandParser) {
|
|
8365
|
+
// <- Note: [🦦] Its strange that this type assertion is needed
|
|
8366
|
+
var name_1 = commandParser.name, isUsedInPipelineHead = commandParser.isUsedInPipelineHead, isUsedInPipelineTask = commandParser.isUsedInPipelineTask, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
|
|
8367
|
+
if (just(false)) ;
|
|
8368
|
+
else if (usagePlace === 'PIPELINE_HEAD' && !isUsedInPipelineHead) {
|
|
8369
|
+
return "continue";
|
|
8370
|
+
}
|
|
8371
|
+
else if (usagePlace === 'PIPELINE_TASK' && !isUsedInPipelineTask) {
|
|
8372
|
+
return "continue";
|
|
8373
|
+
}
|
|
8374
|
+
var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
|
|
8375
|
+
if (names.includes(commandName)) {
|
|
8376
|
+
try {
|
|
8377
|
+
return { value: parse({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args }) };
|
|
8378
|
+
}
|
|
8379
|
+
catch (error) {
|
|
8380
|
+
if (!(error instanceof ParseError)) {
|
|
8381
|
+
throw error;
|
|
8382
|
+
}
|
|
8383
|
+
throw new ParseError(spaceTrim.spaceTrim(function (block) {
|
|
8384
|
+
return "\n Invalid ".concat(commandName, " command:\n\n Your command:\n - ").concat(raw, "\n\n The detailed error:\n ").concat(block(error.message), "\n\n Usage of ").concat(commandName, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n All supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
8385
|
+
}));
|
|
8386
|
+
}
|
|
8387
|
+
}
|
|
8388
|
+
};
|
|
8389
|
+
try {
|
|
8390
|
+
for (var _b = __values(COMMANDS), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8391
|
+
var commandParser = _c.value;
|
|
8392
|
+
var state_1 = _loop_1(commandParser);
|
|
8393
|
+
if (typeof state_1 === "object")
|
|
8394
|
+
return state_1.value;
|
|
8395
|
+
}
|
|
8396
|
+
}
|
|
8397
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
8398
|
+
finally {
|
|
8399
|
+
try {
|
|
8400
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8401
|
+
}
|
|
8402
|
+
finally { if (e_1) throw e_1.error; }
|
|
8403
|
+
}
|
|
8404
|
+
return null;
|
|
8405
|
+
}
|
|
8406
|
+
|
|
8407
|
+
/**
|
|
8408
|
+
* @@@
|
|
8409
|
+
*
|
|
8410
|
+
* @deprecated https://github.com/webgptorg/promptbook/pull/186
|
|
8411
|
+
* @see https://github.com/webgptorg/promptbook/discussions/171
|
|
8412
|
+
*
|
|
8413
|
+
* @public exported from `@promptbook/core`
|
|
8414
|
+
*/
|
|
8415
|
+
function getPipelineInterface(pipeline) {
|
|
8416
|
+
var e_1, _a, e_2, _b;
|
|
8417
|
+
var pipelineInterface = {
|
|
8418
|
+
inputParameters: [],
|
|
8419
|
+
outputParameters: [],
|
|
8420
|
+
};
|
|
8421
|
+
try {
|
|
8422
|
+
for (var _c = __values(pipeline.parameters), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
8423
|
+
var parameter = _d.value;
|
|
8424
|
+
var isInput = parameter.isInput, isOutput = parameter.isOutput;
|
|
8425
|
+
if (isInput) {
|
|
8426
|
+
pipelineInterface.inputParameters.push(deepClone(parameter));
|
|
8427
|
+
}
|
|
8428
|
+
if (isOutput) {
|
|
8429
|
+
pipelineInterface.outputParameters.push(deepClone(parameter));
|
|
8430
|
+
}
|
|
8431
|
+
}
|
|
8432
|
+
}
|
|
8433
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
8434
|
+
finally {
|
|
8435
|
+
try {
|
|
8436
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
8437
|
+
}
|
|
8438
|
+
finally { if (e_1) throw e_1.error; }
|
|
8439
|
+
}
|
|
8440
|
+
try {
|
|
8441
|
+
for (var _e = __values(['inputParameters', 'outputParameters']), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
8442
|
+
var key = _f.value;
|
|
8443
|
+
pipelineInterface[key].sort(function (_a, _b) {
|
|
8444
|
+
var name1 = _a.name;
|
|
8445
|
+
var name2 = _b.name;
|
|
8446
|
+
return name1.localeCompare(name2);
|
|
8447
|
+
});
|
|
8448
|
+
}
|
|
8449
|
+
}
|
|
8450
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
8451
|
+
finally {
|
|
8452
|
+
try {
|
|
8453
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
8454
|
+
}
|
|
8455
|
+
finally { if (e_2) throw e_2.error; }
|
|
8456
|
+
}
|
|
8457
|
+
return exportJson({
|
|
8458
|
+
name: "pipelineInterface",
|
|
8459
|
+
message: "Result of `getPipelineInterface`",
|
|
8460
|
+
order: ['inputParameters', 'outputParameters'],
|
|
8461
|
+
value: pipelineInterface,
|
|
8462
|
+
});
|
|
8463
|
+
}
|
|
8464
|
+
|
|
8465
|
+
/**
|
|
8466
|
+
* @@@
|
|
8467
|
+
*
|
|
8468
|
+
* @deprecated https://github.com/webgptorg/promptbook/pull/186
|
|
8469
|
+
* @see https://github.com/webgptorg/promptbook/discussions/171
|
|
8470
|
+
*
|
|
8471
|
+
* @public exported from `@promptbook/core`
|
|
8472
|
+
*/
|
|
8473
|
+
function isPipelineInterfacesEqual(pipelineInterface1, pipelineInterface2) {
|
|
8474
|
+
var e_1, _a, e_2, _b;
|
|
8475
|
+
try {
|
|
8476
|
+
for (var _c = __values(['inputParameters', 'outputParameters']), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
8477
|
+
var whichParameters = _d.value;
|
|
8478
|
+
var parameters1 = pipelineInterface1[whichParameters]; // <- Note: `isPipelineInterfacesEqual` is just temporary solution, no need to fix this
|
|
8479
|
+
var parameters2 = pipelineInterface2[whichParameters];
|
|
8480
|
+
if (parameters1.length !== parameters2.length) {
|
|
8481
|
+
return false;
|
|
8482
|
+
}
|
|
8483
|
+
var _loop_1 = function (parameter) {
|
|
8484
|
+
var matchingParameter = parameters2.find(function (_a) {
|
|
8485
|
+
var name = _a.name;
|
|
8486
|
+
return name === parameter.name;
|
|
8487
|
+
});
|
|
8488
|
+
if (!matchingParameter) {
|
|
8489
|
+
return { value: false };
|
|
8490
|
+
}
|
|
8491
|
+
// Note: Do not compare description, it is not relevant for compatibility
|
|
8492
|
+
if (matchingParameter.isInput !== parameter.isInput) {
|
|
8493
|
+
return { value: false };
|
|
8494
|
+
}
|
|
8495
|
+
if (matchingParameter.isOutput !== parameter.isOutput) {
|
|
8496
|
+
return { value: false };
|
|
8497
|
+
}
|
|
8498
|
+
};
|
|
8499
|
+
try {
|
|
8500
|
+
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()) {
|
|
8501
|
+
var parameter = parameters1_1_1.value;
|
|
8502
|
+
var state_1 = _loop_1(parameter);
|
|
8503
|
+
if (typeof state_1 === "object")
|
|
8504
|
+
return state_1.value;
|
|
8505
|
+
}
|
|
8506
|
+
}
|
|
8507
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
8508
|
+
finally {
|
|
8509
|
+
try {
|
|
8510
|
+
if (parameters1_1_1 && !parameters1_1_1.done && (_b = parameters1_1.return)) _b.call(parameters1_1);
|
|
8511
|
+
}
|
|
8512
|
+
finally { if (e_2) throw e_2.error; }
|
|
8513
|
+
}
|
|
8514
|
+
}
|
|
8515
|
+
}
|
|
8516
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
8517
|
+
finally {
|
|
8518
|
+
try {
|
|
8519
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
8520
|
+
}
|
|
8521
|
+
finally { if (e_1) throw e_1.error; }
|
|
8522
|
+
}
|
|
8523
|
+
return true;
|
|
8249
8524
|
}
|
|
8525
|
+
|
|
8250
8526
|
/**
|
|
8251
8527
|
* @@@
|
|
8528
|
+
*
|
|
8529
|
+
* @deprecated https://github.com/webgptorg/promptbook/pull/186
|
|
8530
|
+
* @see https://github.com/webgptorg/promptbook/discussions/171
|
|
8531
|
+
*
|
|
8532
|
+
* @public exported from `@promptbook/core`
|
|
8252
8533
|
*/
|
|
8253
|
-
function
|
|
8254
|
-
|
|
8255
|
-
|
|
8256
|
-
// <- Note: [🦦] Its strange that this type assertion is needed
|
|
8257
|
-
return __spreadArray([
|
|
8258
|
-
"- **".concat(name, "** ").concat(description, ", see [discussion](").concat(documentationUrl, ")")
|
|
8259
|
-
], __read((aliasNames || []).map(function (aliasName) { return " - **".concat(aliasName, "** Alias for **").concat(name, "**"); })), false);
|
|
8260
|
-
}).join('\n');
|
|
8534
|
+
function isPipelineImplementingInterface(options) {
|
|
8535
|
+
var pipeline = options.pipeline, pipelineInterface = options.pipelineInterface;
|
|
8536
|
+
return isPipelineInterfacesEqual(getPipelineInterface(pipeline), pipelineInterface);
|
|
8261
8537
|
}
|
|
8538
|
+
|
|
8262
8539
|
/**
|
|
8263
|
-
*
|
|
8540
|
+
* Set formfactor based on the pipeline interface e
|
|
8541
|
+
*
|
|
8542
|
+
* @private
|
|
8264
8543
|
*/
|
|
8265
|
-
|
|
8266
|
-
|
|
8267
|
-
|
|
8268
|
-
|
|
8269
|
-
|
|
8270
|
-
|
|
8271
|
-
|
|
8272
|
-
if (just(false)) ;
|
|
8273
|
-
else if (usagePlace === 'PIPELINE_HEAD' && !isUsedInPipelineHead) {
|
|
8274
|
-
return "continue";
|
|
8544
|
+
var ImplicitFormfactorHla = {
|
|
8545
|
+
type: 'SYNC',
|
|
8546
|
+
$applyToPipelineJson: function ($pipelineJson) {
|
|
8547
|
+
var e_1, _a;
|
|
8548
|
+
if ($pipelineJson.formfactorName !== undefined) {
|
|
8549
|
+
// Note: When formfactor is already set, do nothing
|
|
8550
|
+
return;
|
|
8275
8551
|
}
|
|
8276
|
-
|
|
8277
|
-
|
|
8552
|
+
try {
|
|
8553
|
+
for (var _b = __values(FORMFACTOR_DEFINITIONS.filter(function (_a) {
|
|
8554
|
+
var name = _a.name;
|
|
8555
|
+
return name !== 'GENERIC';
|
|
8556
|
+
})), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8557
|
+
var formfactorDefinition = _c.value;
|
|
8558
|
+
// <- Note: [♓️][💩] This is the order of the formfactors, make some explicit priority
|
|
8559
|
+
var name_1 = formfactorDefinition.name, pipelineInterface = formfactorDefinition.pipelineInterface;
|
|
8560
|
+
var isCompatible = isPipelineImplementingInterface({
|
|
8561
|
+
pipeline: __assign({ formfactorName: name_1 }, $pipelineJson),
|
|
8562
|
+
pipelineInterface: pipelineInterface,
|
|
8563
|
+
});
|
|
8564
|
+
/*/
|
|
8565
|
+
console.log({
|
|
8566
|
+
subject: `${$pipelineJson.title} implements ${name}`,
|
|
8567
|
+
pipelineTitle: $pipelineJson.title,
|
|
8568
|
+
formfactorName: name,
|
|
8569
|
+
isCompatible,
|
|
8570
|
+
formfactorInterface: pipelineInterface,
|
|
8571
|
+
pipelineInterface: getPipelineInterface($pipelineJson as PipelineJson),
|
|
8572
|
+
});
|
|
8573
|
+
/**/
|
|
8574
|
+
if (isCompatible) {
|
|
8575
|
+
$pipelineJson.formfactorName = name_1;
|
|
8576
|
+
return;
|
|
8577
|
+
}
|
|
8578
|
+
}
|
|
8278
8579
|
}
|
|
8279
|
-
|
|
8280
|
-
|
|
8580
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
8581
|
+
finally {
|
|
8281
8582
|
try {
|
|
8282
|
-
|
|
8283
|
-
}
|
|
8284
|
-
catch (error) {
|
|
8285
|
-
if (!(error instanceof ParseError)) {
|
|
8286
|
-
throw error;
|
|
8287
|
-
}
|
|
8288
|
-
throw new ParseError(spaceTrim.spaceTrim(function (block) {
|
|
8289
|
-
return "\n Invalid ".concat(commandName, " command:\n\n Your command:\n - ").concat(raw, "\n\n The detailed error:\n ").concat(block(error.message), "\n\n Usage of ").concat(commandName, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n All supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
|
|
8290
|
-
}));
|
|
8583
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8291
8584
|
}
|
|
8585
|
+
finally { if (e_1) throw e_1.error; }
|
|
8292
8586
|
}
|
|
8293
|
-
}
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
|
|
8297
|
-
|
|
8298
|
-
|
|
8299
|
-
|
|
8587
|
+
},
|
|
8588
|
+
};
|
|
8589
|
+
|
|
8590
|
+
/**
|
|
8591
|
+
* Allow to define chatbot with no need to write full interface
|
|
8592
|
+
*
|
|
8593
|
+
* @private
|
|
8594
|
+
*/
|
|
8595
|
+
var QuickChatbotHla = {
|
|
8596
|
+
type: 'SYNC',
|
|
8597
|
+
$applyToPipelineJson: function ($pipelineJson) {
|
|
8598
|
+
if ($pipelineJson.tasks.length !== 0) {
|
|
8599
|
+
// Note: When there are already tasks, do nothing
|
|
8600
|
+
return;
|
|
8300
8601
|
}
|
|
8301
|
-
|
|
8302
|
-
|
|
8303
|
-
|
|
8304
|
-
try {
|
|
8305
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8602
|
+
if ($pipelineJson.parameters.length !== 0) {
|
|
8603
|
+
// Note: When there are already parameters, do nothing
|
|
8604
|
+
return;
|
|
8306
8605
|
}
|
|
8307
|
-
|
|
8308
|
-
|
|
8309
|
-
|
|
8310
|
-
|
|
8606
|
+
if ($pipelineJson.personas.length === 0) {
|
|
8607
|
+
// Note: When no personas defined, do nothing
|
|
8608
|
+
return;
|
|
8609
|
+
}
|
|
8610
|
+
var personaName = $pipelineJson.personas[0].name;
|
|
8611
|
+
$pipelineJson.formfactorName = 'CHATBOT';
|
|
8612
|
+
$pipelineJson.parameters.push({
|
|
8613
|
+
name: 'previousTitle',
|
|
8614
|
+
description: 'Previous title of the conversation',
|
|
8615
|
+
isInput: true,
|
|
8616
|
+
isOutput: false,
|
|
8617
|
+
}, {
|
|
8618
|
+
name: 'previousConversationSummary',
|
|
8619
|
+
description: 'Previous conversation summary',
|
|
8620
|
+
isInput: true,
|
|
8621
|
+
isOutput: false,
|
|
8622
|
+
}, {
|
|
8623
|
+
name: 'userMessage',
|
|
8624
|
+
description: 'User message',
|
|
8625
|
+
isInput: true,
|
|
8626
|
+
isOutput: false,
|
|
8627
|
+
}, {
|
|
8628
|
+
name: 'title',
|
|
8629
|
+
description: 'Title of the conversation',
|
|
8630
|
+
isInput: false,
|
|
8631
|
+
isOutput: true,
|
|
8632
|
+
}, {
|
|
8633
|
+
name: 'conversationSummary',
|
|
8634
|
+
description: 'Summary of the conversation',
|
|
8635
|
+
isInput: false,
|
|
8636
|
+
isOutput: true,
|
|
8637
|
+
}, {
|
|
8638
|
+
name: 'chatbotResponse',
|
|
8639
|
+
description: 'Chatbot response',
|
|
8640
|
+
isInput: false,
|
|
8641
|
+
isOutput: true,
|
|
8642
|
+
exampleValues: ['Hello, I am a Pavol`s virtual avatar. How can I help you?'],
|
|
8643
|
+
});
|
|
8644
|
+
// TODO: !!!!!! spaceTrim
|
|
8645
|
+
$pipelineJson.tasks.push({
|
|
8646
|
+
taskType: 'PROMPT_TASK',
|
|
8647
|
+
name: 'create-an-answer',
|
|
8648
|
+
title: 'Create an answer',
|
|
8649
|
+
content: 'Write a response to the user message:\n\n**Question from user**\n\n> {userMessage}\n\n**Previous conversation**\n\n> {previousConversationSummary}',
|
|
8650
|
+
resultingParameterName: 'chatbotResponse',
|
|
8651
|
+
personaName: personaName,
|
|
8652
|
+
dependentParameterNames: ['userMessage', 'previousConversationSummary' /* !!!!!!, 'knowledge'*/],
|
|
8653
|
+
// !!!!!! preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
|
|
8654
|
+
}, {
|
|
8655
|
+
taskType: 'PROMPT_TASK',
|
|
8656
|
+
name: 'summarize-the-conversation',
|
|
8657
|
+
title: 'Summarize the conversation',
|
|
8658
|
+
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}',
|
|
8659
|
+
resultingParameterName: 'conversationSummary',
|
|
8660
|
+
personaName: personaName,
|
|
8661
|
+
expectations: {
|
|
8662
|
+
words: {
|
|
8663
|
+
min: 1,
|
|
8664
|
+
max: 10,
|
|
8665
|
+
},
|
|
8666
|
+
},
|
|
8667
|
+
dependentParameterNames: ['userMessage', 'chatbotResponse' /* !!!!!!, 'knowledge'*/],
|
|
8668
|
+
// !!!!!! preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
|
|
8669
|
+
}, {
|
|
8670
|
+
taskType: 'SIMPLE_TASK',
|
|
8671
|
+
name: 'title',
|
|
8672
|
+
title: 'Title',
|
|
8673
|
+
content: '{conversationSummary}',
|
|
8674
|
+
resultingParameterName: 'title',
|
|
8675
|
+
dependentParameterNames: ['conversationSummary' /* !!!!!!, 'knowledge'*/],
|
|
8676
|
+
// !!!!!! preparedContent: '{content}\n\n## Knowledge\n\n{knowledge}',
|
|
8677
|
+
});
|
|
8678
|
+
},
|
|
8679
|
+
};
|
|
8680
|
+
|
|
8681
|
+
/**
|
|
8682
|
+
* All high-level abstractions
|
|
8683
|
+
*
|
|
8684
|
+
* @private internal index of `pipelineStringToJsonSync` (= used for sync) and `preparePipeline` (= used for async)
|
|
8685
|
+
*/
|
|
8686
|
+
var HIGH_LEVEL_ABSTRACTIONS = [
|
|
8687
|
+
ImplicitFormfactorHla,
|
|
8688
|
+
QuickChatbotHla,
|
|
8689
|
+
// <- Note: [♓️][💩] This is the order of the application of high-level abstractions application on pipeline JSON
|
|
8690
|
+
];
|
|
8691
|
+
/**
|
|
8692
|
+
* TODO: Test that all sync high-level abstractions are before async high-level abstractions
|
|
8693
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
8694
|
+
*/
|
|
8311
8695
|
|
|
8312
8696
|
/**
|
|
8313
8697
|
* Supported script languages
|
|
@@ -8584,20 +8968,15 @@
|
|
|
8584
8968
|
* @public exported from `@promptbook/core`
|
|
8585
8969
|
*/
|
|
8586
8970
|
function pipelineStringToJsonSync(pipelineString) {
|
|
8587
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
|
|
8971
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
8588
8972
|
var $pipelineJson = {
|
|
8589
|
-
title:
|
|
8590
|
-
pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
|
|
8591
|
-
bookVersion: undefined /* <- Note: By default no explicit version */,
|
|
8592
|
-
description: undefined /* <- Note: [🍙] Putting here placeholder to keep `description` on top at final JSON */,
|
|
8593
|
-
formfactorName: 'GENERIC',
|
|
8973
|
+
title: DEFAULT_TITLE,
|
|
8594
8974
|
parameters: [],
|
|
8595
8975
|
tasks: [],
|
|
8596
8976
|
knowledgeSources: [],
|
|
8597
8977
|
knowledgePieces: [],
|
|
8598
8978
|
personas: [],
|
|
8599
8979
|
preparations: [],
|
|
8600
|
-
// <- TODO: [🍙] Some standard order of properties
|
|
8601
8980
|
};
|
|
8602
8981
|
function getPipelineIdentification() {
|
|
8603
8982
|
// Note: This is a 😐 implementation of [🚞]
|
|
@@ -8613,7 +8992,7 @@
|
|
|
8613
8992
|
// =============================================================
|
|
8614
8993
|
// Note: 1️⃣ Parsing of the markdown into object
|
|
8615
8994
|
if (pipelineString.startsWith('#!')) {
|
|
8616
|
-
var
|
|
8995
|
+
var _g = __read(pipelineString.split('\n')), shebangLine_1 = _g[0], restLines = _g.slice(1);
|
|
8617
8996
|
if (!(shebangLine_1 || '').includes('ptbk')) {
|
|
8618
8997
|
throw new ParseError(spaceTrim.spaceTrim(function (block) { return "\n It seems that you try to parse a book file which has non-standard shebang line for book files:\n Shebang line must contain 'ptbk'\n\n You have:\n ".concat(block(shebangLine_1 || '(empty line)'), "\n\n It should look like this:\n #!/usr/bin/env ptbk\n\n ").concat(block(getPipelineIdentification()), "\n "); }));
|
|
8619
8998
|
}
|
|
@@ -8623,7 +9002,7 @@
|
|
|
8623
9002
|
pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
|
|
8624
9003
|
pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
|
|
8625
9004
|
pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
|
|
8626
|
-
var
|
|
9005
|
+
var _h = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _h[0], pipelineSections = _h.slice(1); /* <- Note: [🥞] */
|
|
8627
9006
|
if (pipelineHead === undefined) {
|
|
8628
9007
|
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Pipeline head is not defined\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
|
|
8629
9008
|
}
|
|
@@ -8688,7 +9067,7 @@
|
|
|
8688
9067
|
}
|
|
8689
9068
|
try {
|
|
8690
9069
|
commandParser.$applyToPipelineJson(command, $pipelineJson);
|
|
8691
|
-
// <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion
|
|
9070
|
+
// <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitly
|
|
8692
9071
|
}
|
|
8693
9072
|
catch (error) {
|
|
8694
9073
|
if (!(error instanceof ParseError)) {
|
|
@@ -8745,10 +9124,10 @@
|
|
|
8745
9124
|
return nameWithSuffix;
|
|
8746
9125
|
};
|
|
8747
9126
|
var _loop_2 = function (section) {
|
|
8748
|
-
var
|
|
9127
|
+
var e_7, _q, e_8, _r;
|
|
8749
9128
|
// TODO: Parse section's description (the content out of the codeblock and lists)
|
|
8750
9129
|
var listItems_2 = extractAllListItemsFromMarkdown(section.content);
|
|
8751
|
-
var
|
|
9130
|
+
var _s = extractOneBlockFromMarkdown(section.content), language = _s.language, content = _s.content;
|
|
8752
9131
|
// TODO: [🎾][1] DRY description
|
|
8753
9132
|
var description_1 = section.content;
|
|
8754
9133
|
// Note: Remove codeblocks - TODO: [🎾]
|
|
@@ -8796,7 +9175,7 @@
|
|
|
8796
9175
|
}
|
|
8797
9176
|
try {
|
|
8798
9177
|
commandParser.$applyToTaskJson(
|
|
8799
|
-
// <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion
|
|
9178
|
+
// <- Note: [🦦] Its strange that this assertion must be here, [🦦][4] should do this assertion implicitly
|
|
8800
9179
|
command, $taskJson, $pipelineJson);
|
|
8801
9180
|
}
|
|
8802
9181
|
catch (error) {
|
|
@@ -8812,17 +9191,17 @@
|
|
|
8812
9191
|
};
|
|
8813
9192
|
try {
|
|
8814
9193
|
// TODO [♓️] List commands and before apply order them to achieve order-agnostic commands
|
|
8815
|
-
for (var commands_1 = (
|
|
8816
|
-
var
|
|
9194
|
+
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()) {
|
|
9195
|
+
var _t = commands_1_1.value, listItem = _t.listItem, command = _t.command;
|
|
8817
9196
|
_loop_4(listItem, command);
|
|
8818
9197
|
}
|
|
8819
9198
|
}
|
|
8820
|
-
catch (
|
|
9199
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
8821
9200
|
finally {
|
|
8822
9201
|
try {
|
|
8823
|
-
if (commands_1_1 && !commands_1_1.done && (
|
|
9202
|
+
if (commands_1_1 && !commands_1_1.done && (_q = commands_1.return)) _q.call(commands_1);
|
|
8824
9203
|
}
|
|
8825
|
-
finally { if (
|
|
9204
|
+
finally { if (e_7) throw e_7.error; }
|
|
8826
9205
|
}
|
|
8827
9206
|
// TODO: [🍧] Should be done in SECTION command
|
|
8828
9207
|
if ($taskJson.taskType === 'SCRIPT_TASK') {
|
|
@@ -8836,8 +9215,8 @@
|
|
|
8836
9215
|
}
|
|
8837
9216
|
$taskJson.dependentParameterNames = Array.from(extractParameterNamesFromTask($taskJson));
|
|
8838
9217
|
try {
|
|
8839
|
-
for (var
|
|
8840
|
-
var parameterName =
|
|
9218
|
+
for (var _u = (e_8 = void 0, __values($taskJson.dependentParameterNames)), _v = _u.next(); !_v.done; _v = _u.next()) {
|
|
9219
|
+
var parameterName = _v.value;
|
|
8841
9220
|
// TODO: [🧠] This definition should be made first in the task
|
|
8842
9221
|
defineParam({
|
|
8843
9222
|
parameterName: parameterName,
|
|
@@ -8848,12 +9227,12 @@
|
|
|
8848
9227
|
});
|
|
8849
9228
|
}
|
|
8850
9229
|
}
|
|
8851
|
-
catch (
|
|
9230
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
8852
9231
|
finally {
|
|
8853
9232
|
try {
|
|
8854
|
-
if (
|
|
9233
|
+
if (_v && !_v.done && (_r = _u.return)) _r.call(_u);
|
|
8855
9234
|
}
|
|
8856
|
-
finally { if (
|
|
9235
|
+
finally { if (e_8) throw e_8.error; }
|
|
8857
9236
|
}
|
|
8858
9237
|
/*
|
|
8859
9238
|
// TODO: [🍧] This should be checked in `MODEL` command + better error message
|
|
@@ -8902,18 +9281,22 @@
|
|
|
8902
9281
|
var isThisParameterResulting = $pipelineJson.tasks.some(function (task) { return task.resultingParameterName === parameter.name; });
|
|
8903
9282
|
if (!isThisParameterResulting) {
|
|
8904
9283
|
parameter.isInput = true;
|
|
9284
|
+
// <- TODO: [💔] Why this is making typescript error in vscode but not in cli
|
|
9285
|
+
// > Type 'true' is not assignable to type 'false'.ts(2322)
|
|
9286
|
+
// > (property) isInput: false
|
|
9287
|
+
// > The parameter is input of the pipeline The parameter is NOT input of the pipeline
|
|
8905
9288
|
}
|
|
8906
9289
|
};
|
|
8907
9290
|
try {
|
|
8908
|
-
for (var
|
|
8909
|
-
var parameter =
|
|
9291
|
+
for (var _j = __values($pipelineJson.parameters), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
9292
|
+
var parameter = _k.value;
|
|
8910
9293
|
_loop_3(parameter);
|
|
8911
9294
|
}
|
|
8912
9295
|
}
|
|
8913
9296
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
8914
9297
|
finally {
|
|
8915
9298
|
try {
|
|
8916
|
-
if (
|
|
9299
|
+
if (_k && !_k.done && (_d = _j.return)) _d.call(_j);
|
|
8917
9300
|
}
|
|
8918
9301
|
finally { if (e_4) throw e_4.error; }
|
|
8919
9302
|
}
|
|
@@ -8922,17 +9305,18 @@
|
|
|
8922
9305
|
// Note: 7️⃣ Mark all non-INPUT parameters as OUTPUT if any OUTPUT is not set
|
|
8923
9306
|
if ($pipelineJson.parameters.every(function (parameter) { return !parameter.isOutput; })) {
|
|
8924
9307
|
try {
|
|
8925
|
-
for (var
|
|
8926
|
-
var parameter =
|
|
9308
|
+
for (var _l = __values($pipelineJson.parameters), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
9309
|
+
var parameter = _m.value;
|
|
8927
9310
|
if (!parameter.isInput) {
|
|
8928
9311
|
parameter.isOutput = true;
|
|
9312
|
+
// <- TODO: [💔]
|
|
8929
9313
|
}
|
|
8930
9314
|
}
|
|
8931
9315
|
}
|
|
8932
9316
|
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
8933
9317
|
finally {
|
|
8934
9318
|
try {
|
|
8935
|
-
if (
|
|
9319
|
+
if (_m && !_m.done && (_e = _l.return)) _e.call(_l);
|
|
8936
9320
|
}
|
|
8937
9321
|
finally { if (e_5) throw e_5.error; }
|
|
8938
9322
|
}
|
|
@@ -8940,7 +9324,7 @@
|
|
|
8940
9324
|
// =============================================================
|
|
8941
9325
|
// Note: 8️⃣ Cleanup of undefined values
|
|
8942
9326
|
$pipelineJson.tasks.forEach(function (tasks) {
|
|
8943
|
-
var
|
|
9327
|
+
var e_9, _a;
|
|
8944
9328
|
try {
|
|
8945
9329
|
for (var _b = __values(Object.entries(tasks)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8946
9330
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8949,16 +9333,16 @@
|
|
|
8949
9333
|
}
|
|
8950
9334
|
}
|
|
8951
9335
|
}
|
|
8952
|
-
catch (
|
|
9336
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
8953
9337
|
finally {
|
|
8954
9338
|
try {
|
|
8955
9339
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8956
9340
|
}
|
|
8957
|
-
finally { if (
|
|
9341
|
+
finally { if (e_9) throw e_9.error; }
|
|
8958
9342
|
}
|
|
8959
9343
|
});
|
|
8960
9344
|
$pipelineJson.parameters.forEach(function (parameter) {
|
|
8961
|
-
var
|
|
9345
|
+
var e_10, _a;
|
|
8962
9346
|
try {
|
|
8963
9347
|
for (var _b = __values(Object.entries(parameter)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8964
9348
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
@@ -8967,19 +9351,49 @@
|
|
|
8967
9351
|
}
|
|
8968
9352
|
}
|
|
8969
9353
|
}
|
|
8970
|
-
catch (
|
|
9354
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
8971
9355
|
finally {
|
|
8972
9356
|
try {
|
|
8973
9357
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
8974
9358
|
}
|
|
8975
|
-
finally { if (
|
|
9359
|
+
finally { if (e_10) throw e_10.error; }
|
|
8976
9360
|
}
|
|
8977
9361
|
});
|
|
9362
|
+
try {
|
|
9363
|
+
// =============================================================
|
|
9364
|
+
// Note: 9️⃣ Apply sync high-level abstractions
|
|
9365
|
+
for (var _o = __values(HIGH_LEVEL_ABSTRACTIONS.filter(function (_a) {
|
|
9366
|
+
var type = _a.type;
|
|
9367
|
+
return type === 'SYNC';
|
|
9368
|
+
})), _p = _o.next(); !_p.done; _p = _o.next()) {
|
|
9369
|
+
var highLevelAbstraction = _p.value;
|
|
9370
|
+
highLevelAbstraction.$applyToPipelineJson($pipelineJson);
|
|
9371
|
+
}
|
|
9372
|
+
}
|
|
9373
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
9374
|
+
finally {
|
|
9375
|
+
try {
|
|
9376
|
+
if (_p && !_p.done && (_f = _o.return)) _f.call(_o);
|
|
9377
|
+
}
|
|
9378
|
+
finally { if (e_6) throw e_6.error; }
|
|
9379
|
+
}
|
|
9380
|
+
// =============================================================
|
|
9381
|
+
// Note: 🔟 Default formfactor
|
|
9382
|
+
// Note: [🔆] If formfactor is still not set, set it to 'GENERIC'
|
|
9383
|
+
if ($pipelineJson.formfactorName === undefined) {
|
|
9384
|
+
$pipelineJson.formfactorName = 'GENERIC';
|
|
9385
|
+
}
|
|
8978
9386
|
// =============================================================
|
|
8979
9387
|
// TODO: [🍙] Maybe do reorder of `$pipelineJson` here
|
|
8980
|
-
return
|
|
9388
|
+
return exportJson({
|
|
9389
|
+
name: 'pipelineJson',
|
|
9390
|
+
message: "Result of `pipelineStringToJsonSync`",
|
|
9391
|
+
order: ORDER_OF_PIPELINE_JSON,
|
|
9392
|
+
value: __assign({ formfactorName: 'GENERIC' }, $pipelineJson),
|
|
9393
|
+
});
|
|
8981
9394
|
}
|
|
8982
9395
|
/**
|
|
9396
|
+
* TODO: [🧠] Maybe more things here can be refactored as high-level abstractions
|
|
8983
9397
|
* TODO: [main] !!!! Warn if used only sync version
|
|
8984
9398
|
* TODO: [🚞] Report here line/column of error
|
|
8985
9399
|
* TODO: Use spaceTrim more effectively
|
|
@@ -9023,7 +9437,7 @@
|
|
|
9023
9437
|
pipelineJson = _a.sent();
|
|
9024
9438
|
_a.label = 2;
|
|
9025
9439
|
case 2:
|
|
9026
|
-
// Note: No need to use `$
|
|
9440
|
+
// Note: No need to use `$exportJson` because `pipelineStringToJsonSync` and `preparePipeline` already do that
|
|
9027
9441
|
return [2 /*return*/, pipelineJson];
|
|
9028
9442
|
}
|
|
9029
9443
|
});
|
|
@@ -9277,6 +9691,7 @@
|
|
|
9277
9691
|
return renamedPipeline;
|
|
9278
9692
|
}
|
|
9279
9693
|
|
|
9694
|
+
// <- TODO: !!!!!!! Auto convert to type `import { ... } from 'type-fest';`
|
|
9280
9695
|
/**
|
|
9281
9696
|
* Tests if the value is [🚉] serializable as JSON
|
|
9282
9697
|
*
|
|
@@ -9298,7 +9713,7 @@
|
|
|
9298
9713
|
*/
|
|
9299
9714
|
function isSerializableAsJson(value) {
|
|
9300
9715
|
try {
|
|
9301
|
-
checkSerializableAsJson(
|
|
9716
|
+
checkSerializableAsJson({ value: value });
|
|
9302
9717
|
return true;
|
|
9303
9718
|
}
|
|
9304
9719
|
catch (error) {
|
|
@@ -10496,133 +10911,6 @@
|
|
|
10496
10911
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
10497
10912
|
*/
|
|
10498
10913
|
|
|
10499
|
-
/**
|
|
10500
|
-
* @@@
|
|
10501
|
-
*
|
|
10502
|
-
* @deprecated https://github.com/webgptorg/promptbook/pull/186
|
|
10503
|
-
* @see https://github.com/webgptorg/promptbook/discussions/171
|
|
10504
|
-
*
|
|
10505
|
-
* @public exported from `@promptbook/core`
|
|
10506
|
-
*/
|
|
10507
|
-
function getPipelineInterface(pipeline) {
|
|
10508
|
-
var e_1, _a, e_2, _b;
|
|
10509
|
-
var pipelineInterface = {
|
|
10510
|
-
inputParameters: [],
|
|
10511
|
-
outputParameters: [],
|
|
10512
|
-
};
|
|
10513
|
-
try {
|
|
10514
|
-
for (var _c = __values(pipeline.parameters), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
10515
|
-
var parameter = _d.value;
|
|
10516
|
-
var isInput = parameter.isInput, isOutput = parameter.isOutput;
|
|
10517
|
-
if (isInput) {
|
|
10518
|
-
pipelineInterface.inputParameters.push(parameter);
|
|
10519
|
-
}
|
|
10520
|
-
if (isOutput) {
|
|
10521
|
-
pipelineInterface.outputParameters.push(parameter);
|
|
10522
|
-
}
|
|
10523
|
-
}
|
|
10524
|
-
}
|
|
10525
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
10526
|
-
finally {
|
|
10527
|
-
try {
|
|
10528
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
10529
|
-
}
|
|
10530
|
-
finally { if (e_1) throw e_1.error; }
|
|
10531
|
-
}
|
|
10532
|
-
try {
|
|
10533
|
-
for (var _e = __values(['inputParameters', 'outputParameters']), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
10534
|
-
var key = _f.value;
|
|
10535
|
-
pipelineInterface[key].sort(function (_a, _b) {
|
|
10536
|
-
var name1 = _a.name;
|
|
10537
|
-
var name2 = _b.name;
|
|
10538
|
-
return name1.localeCompare(name2);
|
|
10539
|
-
});
|
|
10540
|
-
}
|
|
10541
|
-
}
|
|
10542
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
10543
|
-
finally {
|
|
10544
|
-
try {
|
|
10545
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
10546
|
-
}
|
|
10547
|
-
finally { if (e_2) throw e_2.error; }
|
|
10548
|
-
}
|
|
10549
|
-
return $deepFreeze(pipelineInterface);
|
|
10550
|
-
}
|
|
10551
|
-
|
|
10552
|
-
/**
|
|
10553
|
-
* @@@
|
|
10554
|
-
*
|
|
10555
|
-
* @deprecated https://github.com/webgptorg/promptbook/pull/186
|
|
10556
|
-
* @see https://github.com/webgptorg/promptbook/discussions/171
|
|
10557
|
-
*
|
|
10558
|
-
* @public exported from `@promptbook/core`
|
|
10559
|
-
*/
|
|
10560
|
-
function isPipelineInterfacesEqual(pipelineInterface1, pipelineInterface2) {
|
|
10561
|
-
var e_1, _a, e_2, _b;
|
|
10562
|
-
try {
|
|
10563
|
-
for (var _c = __values(['inputParameters', 'outputParameters']), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
10564
|
-
var whichParameters = _d.value;
|
|
10565
|
-
var parameters1 = pipelineInterface1[whichParameters]; // <- Note: `isPipelineInterfacesEqual` is just temporary solution, no need to fix this
|
|
10566
|
-
var parameters2 = pipelineInterface2[whichParameters];
|
|
10567
|
-
if (parameters1.length !== parameters2.length) {
|
|
10568
|
-
return false;
|
|
10569
|
-
}
|
|
10570
|
-
var _loop_1 = function (parameter) {
|
|
10571
|
-
var matchingParameter = parameters2.find(function (_a) {
|
|
10572
|
-
var name = _a.name;
|
|
10573
|
-
return name === parameter.name;
|
|
10574
|
-
});
|
|
10575
|
-
if (!matchingParameter) {
|
|
10576
|
-
return { value: false };
|
|
10577
|
-
}
|
|
10578
|
-
// Note: Do not compare description, it is not relevant for compatibility
|
|
10579
|
-
if (matchingParameter.isInput !== parameter.isInput) {
|
|
10580
|
-
return { value: false };
|
|
10581
|
-
}
|
|
10582
|
-
if (matchingParameter.isOutput !== parameter.isOutput) {
|
|
10583
|
-
return { value: false };
|
|
10584
|
-
}
|
|
10585
|
-
};
|
|
10586
|
-
try {
|
|
10587
|
-
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()) {
|
|
10588
|
-
var parameter = parameters1_1_1.value;
|
|
10589
|
-
var state_1 = _loop_1(parameter);
|
|
10590
|
-
if (typeof state_1 === "object")
|
|
10591
|
-
return state_1.value;
|
|
10592
|
-
}
|
|
10593
|
-
}
|
|
10594
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
10595
|
-
finally {
|
|
10596
|
-
try {
|
|
10597
|
-
if (parameters1_1_1 && !parameters1_1_1.done && (_b = parameters1_1.return)) _b.call(parameters1_1);
|
|
10598
|
-
}
|
|
10599
|
-
finally { if (e_2) throw e_2.error; }
|
|
10600
|
-
}
|
|
10601
|
-
}
|
|
10602
|
-
}
|
|
10603
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
10604
|
-
finally {
|
|
10605
|
-
try {
|
|
10606
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
10607
|
-
}
|
|
10608
|
-
finally { if (e_1) throw e_1.error; }
|
|
10609
|
-
}
|
|
10610
|
-
return true;
|
|
10611
|
-
}
|
|
10612
|
-
|
|
10613
|
-
/**
|
|
10614
|
-
* @@@
|
|
10615
|
-
*
|
|
10616
|
-
* @deprecated https://github.com/webgptorg/promptbook/pull/186
|
|
10617
|
-
* @see https://github.com/webgptorg/promptbook/discussions/171
|
|
10618
|
-
*
|
|
10619
|
-
* @public exported from `@promptbook/core`
|
|
10620
|
-
*/
|
|
10621
|
-
function isPipelineImplementingInterface(options) {
|
|
10622
|
-
var pipeline = options.pipeline, pipelineInterface = options.pipelineInterface;
|
|
10623
|
-
return isPipelineInterfacesEqual(getPipelineInterface(pipeline), pipelineInterface);
|
|
10624
|
-
}
|
|
10625
|
-
|
|
10626
10914
|
/**
|
|
10627
10915
|
* Metadata of the scraper
|
|
10628
10916
|
*
|
|
@@ -10640,7 +10928,7 @@
|
|
|
10640
10928
|
'LibreOffice',
|
|
10641
10929
|
// <- TODO: [🧠] Should be 'LibreOffice' here, its dependency of dependency
|
|
10642
10930
|
],
|
|
10643
|
-
}); /* <-
|
|
10931
|
+
}); /* <- Note: [🤛] */
|
|
10644
10932
|
/**
|
|
10645
10933
|
* Registration of known scraper metadata
|
|
10646
10934
|
*
|
|
@@ -10667,7 +10955,7 @@
|
|
|
10667
10955
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
10668
10956
|
isAvilableInBrowser: false,
|
|
10669
10957
|
requiredExecutables: ['Pandoc'],
|
|
10670
|
-
}); /* <-
|
|
10958
|
+
}); /* <- Note: [🤛] */
|
|
10671
10959
|
/**
|
|
10672
10960
|
* Registration of known scraper metadata
|
|
10673
10961
|
*
|
|
@@ -10694,7 +10982,7 @@
|
|
|
10694
10982
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
10695
10983
|
isAvilableInBrowser: true,
|
|
10696
10984
|
requiredExecutables: [],
|
|
10697
|
-
}); /* <-
|
|
10985
|
+
}); /* <- Note: [🤛] */
|
|
10698
10986
|
/**
|
|
10699
10987
|
* Registration of known scraper metadata
|
|
10700
10988
|
*
|
|
@@ -10721,7 +11009,7 @@
|
|
|
10721
11009
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
10722
11010
|
isAvilableInBrowser: true,
|
|
10723
11011
|
requiredExecutables: [],
|
|
10724
|
-
}); /* <-
|
|
11012
|
+
}); /* <- Note: [🤛] */
|
|
10725
11013
|
/**
|
|
10726
11014
|
* Registration of known scraper metadata
|
|
10727
11015
|
*
|
|
@@ -10748,7 +11036,7 @@
|
|
|
10748
11036
|
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/@@',
|
|
10749
11037
|
isAvilableInBrowser: false,
|
|
10750
11038
|
requiredExecutables: [],
|
|
10751
|
-
}); /* <-
|
|
11039
|
+
}); /* <- Note: [🤛] */
|
|
10752
11040
|
/**
|
|
10753
11041
|
* Registration of known scraper metadata
|
|
10754
11042
|
*
|
|
@@ -10897,6 +11185,7 @@
|
|
|
10897
11185
|
exports.NonTaskSectionTypes = NonTaskSectionTypes;
|
|
10898
11186
|
exports.NotFoundError = NotFoundError;
|
|
10899
11187
|
exports.NotYetImplementedError = NotYetImplementedError;
|
|
11188
|
+
exports.ORDER_OF_PIPELINE_JSON = ORDER_OF_PIPELINE_JSON;
|
|
10900
11189
|
exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
|
|
10901
11190
|
exports.PROMPTBOOK_ERRORS = PROMPTBOOK_ERRORS;
|
|
10902
11191
|
exports.ParseError = ParseError;
|