@promptbook/remote-client 0.112.0-73 → 0.112.0-80
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 +9 -9
- package/esm/index.es.js +310 -204
- package/esm/index.es.js.map +1 -1
- package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
- package/esm/src/avatars/visuals/octopus3d2AvatarVisual.d.ts +7 -0
- package/esm/src/avatars/visuals/octopus3dAvatarVisualShared.d.ts +37 -0
- package/esm/src/book-components/Chat/save/_common/chatExportRendering.d.ts +47 -0
- package/esm/src/book-components/Chat/save/html/htmlSaveFormatDefinition.d.ts +12 -0
- package/esm/src/book-components/Chat/save/index.d.ts +2 -2
- package/esm/src/book-components/Chat/save/markdown/mdSaveFormatDefinition.d.ts +5 -3
- package/esm/src/book-components/Chat/save/pdf/buildChatPdf.d.ts +3 -3
- package/esm/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.d.ts +1 -1
- package/esm/src/cli/cli-commands/agent/agentProjectPaths.d.ts +8 -8
- package/esm/src/cli/cli-commands/agent/initializeAgentRunnerCommand.d.ts +1 -1
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +56 -0
- package/esm/src/cli/cli-commands/agents-server/buildAgentsServer.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/agents-server/ensureAgentsServerEnvFile.d.ts +7 -0
- package/esm/src/cli/cli-commands/agents-server/ensureAgentsServerGitignoreFile.d.ts +7 -0
- package/esm/src/cli/cli-commands/agents-server/init.d.ts +9 -0
- package/esm/src/cli/cli-commands/agents-server/init.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/agents-server/initializeAgentsServerProjectConfiguration.d.ts +17 -0
- package/esm/src/cli/cli-commands/agents-server/printAgentsServerInitializationSummary.d.ts +7 -0
- package/esm/src/cli/cli-commands/agents-server/run.d.ts +14 -0
- package/esm/src/cli/cli-commands/agents-server/run.test.d.ts +1 -0
- package/esm/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +23 -0
- package/esm/src/cli/cli-commands/agents-server.d.ts +8 -0
- package/esm/src/cli/cli-commands/common/projectInitialization.d.ts +65 -0
- package/esm/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +44 -0
- package/esm/src/cli/common/$deprecateCliCommand.d.ts +8 -0
- package/esm/src/cli/common/$deprecateCliCommand.test.d.ts +1 -0
- package/esm/src/utils/color/Color.d.ts +4 -44
- package/esm/src/utils/color/ColorValue.d.ts +55 -0
- package/esm/src/utils/color/isHexColorString.d.ts +10 -0
- package/esm/src/utils/color/parseColorString.d.ts +11 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +310 -204
- package/umd/index.umd.js.map +1 -1
- package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
- package/umd/src/avatars/visuals/octopus3d2AvatarVisual.d.ts +7 -0
- package/umd/src/avatars/visuals/octopus3dAvatarVisualShared.d.ts +37 -0
- package/umd/src/book-components/Chat/save/_common/chatExportRendering.d.ts +47 -0
- package/umd/src/book-components/Chat/save/html/htmlSaveFormatDefinition.d.ts +12 -0
- package/umd/src/book-components/Chat/save/index.d.ts +2 -2
- package/umd/src/book-components/Chat/save/markdown/mdSaveFormatDefinition.d.ts +5 -3
- package/umd/src/book-components/Chat/save/pdf/buildChatPdf.d.ts +3 -3
- package/umd/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.d.ts +1 -1
- package/umd/src/cli/cli-commands/agent/agentProjectPaths.d.ts +8 -8
- package/umd/src/cli/cli-commands/agent/initializeAgentRunnerCommand.d.ts +1 -1
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +56 -0
- package/umd/src/cli/cli-commands/agents-server/buildAgentsServer.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/agents-server/ensureAgentsServerEnvFile.d.ts +7 -0
- package/umd/src/cli/cli-commands/agents-server/ensureAgentsServerGitignoreFile.d.ts +7 -0
- package/umd/src/cli/cli-commands/agents-server/init.d.ts +9 -0
- package/umd/src/cli/cli-commands/agents-server/init.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/agents-server/initializeAgentsServerProjectConfiguration.d.ts +17 -0
- package/umd/src/cli/cli-commands/agents-server/printAgentsServerInitializationSummary.d.ts +7 -0
- package/umd/src/cli/cli-commands/agents-server/run.d.ts +14 -0
- package/umd/src/cli/cli-commands/agents-server/run.test.d.ts +1 -0
- package/umd/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +23 -0
- package/umd/src/cli/cli-commands/agents-server.d.ts +8 -0
- package/umd/src/cli/cli-commands/common/projectInitialization.d.ts +65 -0
- package/umd/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +44 -0
- package/umd/src/cli/common/$deprecateCliCommand.d.ts +8 -0
- package/umd/src/cli/common/$deprecateCliCommand.test.d.ts +1 -0
- package/umd/src/utils/color/Color.d.ts +4 -44
- package/umd/src/utils/color/ColorValue.d.ts +55 -0
- package/umd/src/utils/color/isHexColorString.d.ts +10 -0
- package/umd/src/utils/color/parseColorString.d.ts +11 -0
- package/umd/src/version.d.ts +1 -1
- package/esm/src/cli/cli-commands/coder/appendBlock.d.ts +0 -6
- package/esm/src/cli/cli-commands/coder/readTextFileIfExists.d.ts +0 -6
- package/umd/src/cli/cli-commands/coder/appendBlock.d.ts +0 -6
- package/umd/src/cli/cli-commands/coder/readTextFileIfExists.d.ts +0 -6
package/umd/index.umd.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* @generated
|
|
23
23
|
* @see https://github.com/webgptorg/promptbook
|
|
24
24
|
*/
|
|
25
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
25
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-80';
|
|
26
26
|
/**
|
|
27
27
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
28
28
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -564,6 +564,111 @@
|
|
|
564
564
|
}
|
|
565
565
|
}
|
|
566
566
|
|
|
567
|
+
/**
|
|
568
|
+
* Shared immutable channel storage and serialization helpers for `Color`.
|
|
569
|
+
*
|
|
570
|
+
* @private base class of Color
|
|
571
|
+
*/
|
|
572
|
+
class ColorValue {
|
|
573
|
+
constructor(red, green, blue, alpha = 255) {
|
|
574
|
+
this.red = red;
|
|
575
|
+
this.green = green;
|
|
576
|
+
this.blue = blue;
|
|
577
|
+
this.alpha = alpha;
|
|
578
|
+
checkChannelValue('Red', red);
|
|
579
|
+
checkChannelValue('Green', green);
|
|
580
|
+
checkChannelValue('Blue', blue);
|
|
581
|
+
checkChannelValue('Alpha', alpha);
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Shortcut for `red` property
|
|
585
|
+
* Number from 0 to 255
|
|
586
|
+
* @alias red
|
|
587
|
+
*/
|
|
588
|
+
get r() {
|
|
589
|
+
return this.red;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Shortcut for `green` property
|
|
593
|
+
* Number from 0 to 255
|
|
594
|
+
* @alias green
|
|
595
|
+
*/
|
|
596
|
+
get g() {
|
|
597
|
+
return this.green;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Shortcut for `blue` property
|
|
601
|
+
* Number from 0 to 255
|
|
602
|
+
* @alias blue
|
|
603
|
+
*/
|
|
604
|
+
get b() {
|
|
605
|
+
return this.blue;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Shortcut for `alpha` property
|
|
609
|
+
* Number from 0 (transparent) to 255 (opaque)
|
|
610
|
+
* @alias alpha
|
|
611
|
+
*/
|
|
612
|
+
get a() {
|
|
613
|
+
return this.alpha;
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Shortcut for `alpha` property
|
|
617
|
+
* Number from 0 (transparent) to 255 (opaque)
|
|
618
|
+
* @alias alpha
|
|
619
|
+
*/
|
|
620
|
+
get opacity() {
|
|
621
|
+
return this.alpha;
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Shortcut for 1-`alpha` property
|
|
625
|
+
*/
|
|
626
|
+
get transparency() {
|
|
627
|
+
return 255 - this.alpha;
|
|
628
|
+
}
|
|
629
|
+
clone() {
|
|
630
|
+
return take(this.createColor(this.red, this.green, this.blue, this.alpha));
|
|
631
|
+
}
|
|
632
|
+
toString() {
|
|
633
|
+
return this.toHex();
|
|
634
|
+
}
|
|
635
|
+
toHex() {
|
|
636
|
+
if (this.alpha === 255) {
|
|
637
|
+
return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
|
|
638
|
+
.toString(16)
|
|
639
|
+
.padStart(2, '0')}`;
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
|
|
643
|
+
.toString(16)
|
|
644
|
+
.padStart(2, '0')}${this.alpha.toString(16).padStart(2, '0')}`;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
toRgb() {
|
|
648
|
+
if (this.alpha === 255) {
|
|
649
|
+
return `rgb(${this.red}, ${this.green}, ${this.blue})`;
|
|
650
|
+
}
|
|
651
|
+
else {
|
|
652
|
+
return `rgba(${this.red}, ${this.green}, ${this.blue}, ${Math.round((this.alpha / 255) * 100)}%)`;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
toHsl() {
|
|
656
|
+
throw new Error(`Getting HSL is not implemented`);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Checks if the given value is a valid hex color string
|
|
662
|
+
*
|
|
663
|
+
* @param value - value to check
|
|
664
|
+
* @returns true if the value is a valid hex color string (e.g., `#009edd`, `#fff`, etc.)
|
|
665
|
+
*
|
|
666
|
+
* @private function of Color
|
|
667
|
+
*/
|
|
668
|
+
function isHexColorString(value) {
|
|
669
|
+
return (typeof value === 'string' && /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(value));
|
|
670
|
+
}
|
|
671
|
+
|
|
567
672
|
/**
|
|
568
673
|
* Constant for short hex lengths.
|
|
569
674
|
*/
|
|
@@ -775,16 +880,53 @@
|
|
|
775
880
|
|
|
776
881
|
/**
|
|
777
882
|
* Pattern matching hsl regex.
|
|
883
|
+
*
|
|
884
|
+
* @private function of Color
|
|
778
885
|
*/
|
|
779
886
|
const HSL_REGEX_PATTERN = /^hsl\(\s*([0-9.]+)\s*,\s*([0-9.]+)%\s*,\s*([0-9.]+)%\s*\)$/;
|
|
780
887
|
/**
|
|
781
888
|
* Pattern matching RGB regex.
|
|
889
|
+
*
|
|
890
|
+
* @private function of Color
|
|
782
891
|
*/
|
|
783
892
|
const RGB_REGEX_PATTERN = /^rgb\(\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*\)$/;
|
|
784
893
|
/**
|
|
785
894
|
* Pattern matching rgba regex.
|
|
895
|
+
*
|
|
896
|
+
* @private function of Color
|
|
786
897
|
*/
|
|
787
898
|
const RGBA_REGEX_PATTERN = /^rgba\(\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*\)$/;
|
|
899
|
+
/**
|
|
900
|
+
* Parses a supported color string into RGBA channels.
|
|
901
|
+
*
|
|
902
|
+
* @param color as a string for example `#009edd`, `rgb(0,158,221)`, `rgb(0%,62%,86.7%)`, `hsl(197.1,100%,43.3%)`, `red`, `darkgrey`,...
|
|
903
|
+
* @returns RGBA channel values.
|
|
904
|
+
*
|
|
905
|
+
* @private function of Color
|
|
906
|
+
*/
|
|
907
|
+
function parseColorString(color) {
|
|
908
|
+
const trimmed = color.trim();
|
|
909
|
+
const cssColor = CSS_COLORS[trimmed];
|
|
910
|
+
if (cssColor) {
|
|
911
|
+
return parseColorString(cssColor);
|
|
912
|
+
}
|
|
913
|
+
else if (isHexColorString(trimmed)) {
|
|
914
|
+
return parseHexColor(trimmed);
|
|
915
|
+
}
|
|
916
|
+
if (HSL_REGEX_PATTERN.test(trimmed)) {
|
|
917
|
+
return parseHslColor(trimmed);
|
|
918
|
+
}
|
|
919
|
+
else if (RGB_REGEX_PATTERN.test(trimmed)) {
|
|
920
|
+
return parseRgbColor(trimmed);
|
|
921
|
+
}
|
|
922
|
+
else if (RGBA_REGEX_PATTERN.test(trimmed)) {
|
|
923
|
+
return parseRgbaColor(trimmed);
|
|
924
|
+
}
|
|
925
|
+
else {
|
|
926
|
+
throw new Error(`Can not create a new Color instance from string "${trimmed}".`);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
|
|
788
930
|
/**
|
|
789
931
|
* Color object represents an RGB color with alpha channel
|
|
790
932
|
*
|
|
@@ -792,7 +934,7 @@
|
|
|
792
934
|
*
|
|
793
935
|
* @public exported from `@promptbook/color`
|
|
794
936
|
*/
|
|
795
|
-
class Color {
|
|
937
|
+
class Color extends ColorValue {
|
|
796
938
|
/**
|
|
797
939
|
* Creates a new Color instance from miscellaneous formats
|
|
798
940
|
* - It can receive Color instance and just return the same instance
|
|
@@ -865,25 +1007,7 @@
|
|
|
865
1007
|
* @returns Color object
|
|
866
1008
|
*/
|
|
867
1009
|
static fromString(color) {
|
|
868
|
-
|
|
869
|
-
if (CSS_COLORS[trimmed]) {
|
|
870
|
-
return Color.fromString(CSS_COLORS[trimmed]);
|
|
871
|
-
}
|
|
872
|
-
else if (Color.isHexColorString(trimmed)) {
|
|
873
|
-
return Color.fromHex(trimmed);
|
|
874
|
-
}
|
|
875
|
-
if (HSL_REGEX_PATTERN.test(trimmed)) {
|
|
876
|
-
return Color.fromHsl(trimmed);
|
|
877
|
-
}
|
|
878
|
-
else if (RGB_REGEX_PATTERN.test(trimmed)) {
|
|
879
|
-
return Color.fromRgbString(trimmed);
|
|
880
|
-
}
|
|
881
|
-
else if (RGBA_REGEX_PATTERN.test(trimmed)) {
|
|
882
|
-
return Color.fromRgbaString(trimmed);
|
|
883
|
-
}
|
|
884
|
-
else {
|
|
885
|
-
throw new Error(`Can not create a new Color instance from string "${trimmed}".`);
|
|
886
|
-
}
|
|
1010
|
+
return Color.fromColorChannels(parseColorString(color));
|
|
887
1011
|
}
|
|
888
1012
|
/**
|
|
889
1013
|
* Gets common color
|
|
@@ -913,8 +1037,7 @@
|
|
|
913
1037
|
* @returns Color object
|
|
914
1038
|
*/
|
|
915
1039
|
static fromHex(hex) {
|
|
916
|
-
|
|
917
|
-
return take(new Color(red, green, blue, alpha));
|
|
1040
|
+
return Color.fromColorChannels(parseHexColor(hex));
|
|
918
1041
|
}
|
|
919
1042
|
/**
|
|
920
1043
|
* Creates a new Color instance from color in hsl format
|
|
@@ -923,8 +1046,7 @@
|
|
|
923
1046
|
* @returns Color object
|
|
924
1047
|
*/
|
|
925
1048
|
static fromHsl(hsl) {
|
|
926
|
-
|
|
927
|
-
return take(new Color(red, green, blue, alpha));
|
|
1049
|
+
return Color.fromColorChannels(parseHslColor(hsl));
|
|
928
1050
|
}
|
|
929
1051
|
/**
|
|
930
1052
|
* Creates a new Color instance from color in rgb format
|
|
@@ -933,8 +1055,7 @@
|
|
|
933
1055
|
* @returns Color object
|
|
934
1056
|
*/
|
|
935
1057
|
static fromRgbString(rgb) {
|
|
936
|
-
|
|
937
|
-
return take(new Color(red, green, blue, alpha));
|
|
1058
|
+
return Color.fromColorChannels(parseRgbColor(rgb));
|
|
938
1059
|
}
|
|
939
1060
|
/**
|
|
940
1061
|
* Creates a new Color instance from color in rbga format
|
|
@@ -943,8 +1064,7 @@
|
|
|
943
1064
|
* @returns Color object
|
|
944
1065
|
*/
|
|
945
1066
|
static fromRgbaString(rgba) {
|
|
946
|
-
|
|
947
|
-
return take(new Color(red, green, blue, alpha));
|
|
1067
|
+
return Color.fromColorChannels(parseRgbaColor(rgba));
|
|
948
1068
|
}
|
|
949
1069
|
/**
|
|
950
1070
|
* Creates a new Color for color channels values
|
|
@@ -956,7 +1076,7 @@
|
|
|
956
1076
|
* @returns Color object
|
|
957
1077
|
*/
|
|
958
1078
|
static fromValues(red, green, blue, alpha = 255) {
|
|
959
|
-
return
|
|
1079
|
+
return Color.fromColorChannels({ red, green, blue, alpha });
|
|
960
1080
|
}
|
|
961
1081
|
/**
|
|
962
1082
|
* Checks if the given value is a valid Color object.
|
|
@@ -989,8 +1109,7 @@
|
|
|
989
1109
|
* @returns true if the value is a valid hex color string (e.g., `#009edd`, `#fff`, etc.)
|
|
990
1110
|
*/
|
|
991
1111
|
static isHexColorString(value) {
|
|
992
|
-
return (
|
|
993
|
-
/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(value));
|
|
1112
|
+
return isHexColorString(value);
|
|
994
1113
|
}
|
|
995
1114
|
/**
|
|
996
1115
|
* Creates new Color object
|
|
@@ -1003,89 +1122,13 @@
|
|
|
1003
1122
|
* @param alpha number from 0 (transparent) to 255 (opaque)
|
|
1004
1123
|
*/
|
|
1005
1124
|
constructor(red, green, blue, alpha = 255) {
|
|
1006
|
-
|
|
1007
|
-
this.green = green;
|
|
1008
|
-
this.blue = blue;
|
|
1009
|
-
this.alpha = alpha;
|
|
1010
|
-
checkChannelValue('Red', red);
|
|
1011
|
-
checkChannelValue('Green', green);
|
|
1012
|
-
checkChannelValue('Blue', blue);
|
|
1013
|
-
checkChannelValue('Alpha', alpha);
|
|
1014
|
-
}
|
|
1015
|
-
/**
|
|
1016
|
-
* Shortcut for `red` property
|
|
1017
|
-
* Number from 0 to 255
|
|
1018
|
-
* @alias red
|
|
1019
|
-
*/
|
|
1020
|
-
get r() {
|
|
1021
|
-
return this.red;
|
|
1022
|
-
}
|
|
1023
|
-
/**
|
|
1024
|
-
* Shortcut for `green` property
|
|
1025
|
-
* Number from 0 to 255
|
|
1026
|
-
* @alias green
|
|
1027
|
-
*/
|
|
1028
|
-
get g() {
|
|
1029
|
-
return this.green;
|
|
1030
|
-
}
|
|
1031
|
-
/**
|
|
1032
|
-
* Shortcut for `blue` property
|
|
1033
|
-
* Number from 0 to 255
|
|
1034
|
-
* @alias blue
|
|
1035
|
-
*/
|
|
1036
|
-
get b() {
|
|
1037
|
-
return this.blue;
|
|
1038
|
-
}
|
|
1039
|
-
/**
|
|
1040
|
-
* Shortcut for `alpha` property
|
|
1041
|
-
* Number from 0 (transparent) to 255 (opaque)
|
|
1042
|
-
* @alias alpha
|
|
1043
|
-
*/
|
|
1044
|
-
get a() {
|
|
1045
|
-
return this.alpha;
|
|
1125
|
+
super(red, green, blue, alpha);
|
|
1046
1126
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
* Number from 0 (transparent) to 255 (opaque)
|
|
1050
|
-
* @alias alpha
|
|
1051
|
-
*/
|
|
1052
|
-
get opacity() {
|
|
1053
|
-
return this.alpha;
|
|
1127
|
+
createColor(red, green, blue, alpha) {
|
|
1128
|
+
return new Color(red, green, blue, alpha);
|
|
1054
1129
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
*/
|
|
1058
|
-
get transparency() {
|
|
1059
|
-
return 255 - this.alpha;
|
|
1060
|
-
}
|
|
1061
|
-
clone() {
|
|
1062
|
-
return take(new Color(this.red, this.green, this.blue, this.alpha));
|
|
1063
|
-
}
|
|
1064
|
-
toString() {
|
|
1065
|
-
return this.toHex();
|
|
1066
|
-
}
|
|
1067
|
-
toHex() {
|
|
1068
|
-
if (this.alpha === 255) {
|
|
1069
|
-
return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
|
|
1070
|
-
.toString(16)
|
|
1071
|
-
.padStart(2, '0')}`;
|
|
1072
|
-
}
|
|
1073
|
-
else {
|
|
1074
|
-
return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
|
|
1075
|
-
.toString(16)
|
|
1076
|
-
.padStart(2, '0')}${this.alpha.toString(16).padStart(2, '0')}`;
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
toRgb() {
|
|
1080
|
-
if (this.alpha === 255) {
|
|
1081
|
-
return `rgb(${this.red}, ${this.green}, ${this.blue})`;
|
|
1082
|
-
}
|
|
1083
|
-
else {
|
|
1084
|
-
return `rgba(${this.red}, ${this.green}, ${this.blue}, ${Math.round((this.alpha / 255) * 100)}%)`;
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
toHsl() {
|
|
1088
|
-
throw new Error(`Getting HSL is not implemented`);
|
|
1130
|
+
static fromColorChannels({ red, green, blue, alpha }) {
|
|
1131
|
+
return take(new Color(red, green, blue, alpha));
|
|
1089
1132
|
}
|
|
1090
1133
|
}
|
|
1091
1134
|
|
|
@@ -2618,120 +2661,183 @@
|
|
|
2618
2661
|
* @public exported from `@promptbook/utils`
|
|
2619
2662
|
*/
|
|
2620
2663
|
function checkSerializableAsJson(options) {
|
|
2621
|
-
|
|
2664
|
+
checkSerializableValue(options);
|
|
2665
|
+
}
|
|
2666
|
+
// TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
2667
|
+
// TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
|
|
2668
|
+
// Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
2669
|
+
/**
|
|
2670
|
+
* Checks one value and dispatches to the appropriate specialized validator.
|
|
2671
|
+
*
|
|
2672
|
+
* @private function of `checkSerializableAsJson`
|
|
2673
|
+
*/
|
|
2674
|
+
function checkSerializableValue(options) {
|
|
2675
|
+
const { value } = options;
|
|
2676
|
+
if (isSerializablePrimitive(value)) {
|
|
2677
|
+
return;
|
|
2678
|
+
}
|
|
2622
2679
|
if (value === undefined) {
|
|
2623
|
-
throw new UnexpectedError(`${name} is undefined`);
|
|
2680
|
+
throw new UnexpectedError(`${options.name} is undefined`);
|
|
2624
2681
|
}
|
|
2625
|
-
|
|
2626
|
-
|
|
2682
|
+
if (typeof value === 'symbol') {
|
|
2683
|
+
throw new UnexpectedError(`${options.name} is symbol`);
|
|
2627
2684
|
}
|
|
2628
|
-
|
|
2629
|
-
|
|
2685
|
+
if (typeof value === 'function') {
|
|
2686
|
+
throw new UnexpectedError(`${options.name} is function`);
|
|
2630
2687
|
}
|
|
2631
|
-
|
|
2688
|
+
if (Array.isArray(value)) {
|
|
2689
|
+
checkSerializableArray(options, value);
|
|
2632
2690
|
return;
|
|
2633
2691
|
}
|
|
2634
|
-
|
|
2692
|
+
if (value !== null && typeof value === 'object') {
|
|
2693
|
+
checkSerializableObject(options, value);
|
|
2635
2694
|
return;
|
|
2636
2695
|
}
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2696
|
+
throwUnknownTypeError(options);
|
|
2697
|
+
}
|
|
2698
|
+
/**
|
|
2699
|
+
* Checks the primitive values that are directly JSON serializable.
|
|
2700
|
+
*
|
|
2701
|
+
* @private function of `checkSerializableAsJson`
|
|
2702
|
+
*/
|
|
2703
|
+
function isSerializablePrimitive(value) {
|
|
2704
|
+
return (value === null ||
|
|
2705
|
+
typeof value === 'boolean' ||
|
|
2706
|
+
(typeof value === 'number' && !isNaN(value)) ||
|
|
2707
|
+
typeof value === 'string');
|
|
2708
|
+
}
|
|
2709
|
+
/**
|
|
2710
|
+
* Recursively checks JSON array items.
|
|
2711
|
+
*
|
|
2712
|
+
* @private function of `checkSerializableAsJson`
|
|
2713
|
+
*/
|
|
2714
|
+
function checkSerializableArray(context, arrayValue) {
|
|
2715
|
+
for (let index = 0; index < arrayValue.length; index++) {
|
|
2716
|
+
checkSerializableAsJson({
|
|
2717
|
+
...context,
|
|
2718
|
+
name: `${context.name}[${index}]`,
|
|
2719
|
+
value: arrayValue[index],
|
|
2720
|
+
});
|
|
2647
2721
|
}
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2722
|
+
}
|
|
2723
|
+
/**
|
|
2724
|
+
* Checks object-like values and dispatches special unsupported built-ins.
|
|
2725
|
+
*
|
|
2726
|
+
* @private function of `checkSerializableAsJson`
|
|
2727
|
+
*/
|
|
2728
|
+
function checkSerializableObject(context, objectValue) {
|
|
2729
|
+
checkUnsupportedObjectType(context, objectValue);
|
|
2730
|
+
checkSerializableObjectEntries(context, objectValue);
|
|
2731
|
+
assertJsonStringificationSucceeds(context, objectValue);
|
|
2732
|
+
}
|
|
2733
|
+
/**
|
|
2734
|
+
* Rejects built-in objects that must be converted before JSON serialization.
|
|
2735
|
+
*
|
|
2736
|
+
* @private function of `checkSerializableAsJson`
|
|
2737
|
+
*/
|
|
2738
|
+
function checkUnsupportedObjectType(context, objectValue) {
|
|
2739
|
+
if (objectValue instanceof Date) {
|
|
2740
|
+
throw new UnexpectedError(spacetrim.spaceTrim((block) => `
|
|
2741
|
+
\`${context.name}\` is Date
|
|
2652
2742
|
|
|
2653
|
-
|
|
2743
|
+
Use \`string_date_iso8601\` instead
|
|
2654
2744
|
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2745
|
+
Additional message for \`${context.name}\`:
|
|
2746
|
+
${block(context.message || '(nothing)')}
|
|
2747
|
+
`));
|
|
2748
|
+
}
|
|
2749
|
+
if (objectValue instanceof Map) {
|
|
2750
|
+
throw new UnexpectedError(`${context.name} is Map`);
|
|
2751
|
+
}
|
|
2752
|
+
if (objectValue instanceof Set) {
|
|
2753
|
+
throw new UnexpectedError(`${context.name} is Set`);
|
|
2754
|
+
}
|
|
2755
|
+
if (objectValue instanceof RegExp) {
|
|
2756
|
+
throw new UnexpectedError(`${context.name} is RegExp`);
|
|
2757
|
+
}
|
|
2758
|
+
if (objectValue instanceof Error) {
|
|
2759
|
+
throw new UnexpectedError(spacetrim.spaceTrim((block) => `
|
|
2760
|
+
\`${context.name}\` is unserialized Error
|
|
2671
2761
|
|
|
2672
|
-
|
|
2762
|
+
Use function \`serializeError\`
|
|
2673
2763
|
|
|
2674
|
-
|
|
2675
|
-
|
|
2764
|
+
Additional message for \`${context.name}\`:
|
|
2765
|
+
${block(context.message || '(nothing)')}
|
|
2676
2766
|
|
|
2677
|
-
|
|
2767
|
+
`));
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
/**
|
|
2771
|
+
* Recursively checks object properties while preserving omitted `undefined` keys.
|
|
2772
|
+
*
|
|
2773
|
+
* @private function of `checkSerializableAsJson`
|
|
2774
|
+
*/
|
|
2775
|
+
function checkSerializableObjectEntries(context, objectValue) {
|
|
2776
|
+
for (const [subName, subValue] of Object.entries(objectValue)) {
|
|
2777
|
+
if (subValue === undefined) {
|
|
2778
|
+
// Note: undefined in object is serializable - it is just omitted
|
|
2779
|
+
continue;
|
|
2678
2780
|
}
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2781
|
+
checkSerializableAsJson({
|
|
2782
|
+
...context,
|
|
2783
|
+
name: `${context.name}.${subName}`,
|
|
2784
|
+
value: subValue,
|
|
2785
|
+
});
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
/**
|
|
2789
|
+
* Uses `JSON.stringify` as the final guard for cases like circular references.
|
|
2790
|
+
*
|
|
2791
|
+
* @private function of `checkSerializableAsJson`
|
|
2792
|
+
*/
|
|
2793
|
+
function assertJsonStringificationSucceeds(context, objectValue) {
|
|
2794
|
+
try {
|
|
2795
|
+
JSON.stringify(objectValue); // <- TODO: [0]
|
|
2796
|
+
}
|
|
2797
|
+
catch (error) {
|
|
2798
|
+
assertsError(error);
|
|
2799
|
+
throw new UnexpectedError(spacetrim.spaceTrim((block) => `
|
|
2800
|
+
\`${context.name}\` is not serializable
|
|
2694
2801
|
|
|
2695
|
-
|
|
2802
|
+
${block(error.stack || error.message)}
|
|
2696
2803
|
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2804
|
+
Additional message for \`${context.name}\`:
|
|
2805
|
+
${block(context.message || '(nothing)')}
|
|
2806
|
+
`));
|
|
2807
|
+
}
|
|
2808
|
+
/*
|
|
2809
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
2810
|
+
const seen = new Set();
|
|
2811
|
+
const stack = [{ value }];
|
|
2812
|
+
while (stack.length > 0) {
|
|
2813
|
+
const { value } = stack.pop()!;
|
|
2814
|
+
if (typeof value === 'object' && value !== null) {
|
|
2815
|
+
if (seen.has(value)) {
|
|
2816
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
2700
2817
|
}
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
const { value } = stack.pop()!;
|
|
2707
|
-
if (typeof value === 'object' && value !== null) {
|
|
2708
|
-
if (seen.has(value)) {
|
|
2709
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
2710
|
-
}
|
|
2711
|
-
seen.add(value);
|
|
2712
|
-
if (Array.isArray(value)) {
|
|
2713
|
-
stack.push(...value.map((value) => ({ value })));
|
|
2714
|
-
} else {
|
|
2715
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
2716
|
-
}
|
|
2717
|
-
}
|
|
2818
|
+
seen.add(value);
|
|
2819
|
+
if (Array.isArray(value)) {
|
|
2820
|
+
stack.push(...value.map((value) => ({ value })));
|
|
2821
|
+
} else {
|
|
2822
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
2718
2823
|
}
|
|
2719
|
-
*/
|
|
2720
|
-
return;
|
|
2721
2824
|
}
|
|
2722
2825
|
}
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2826
|
+
*/
|
|
2827
|
+
}
|
|
2828
|
+
/**
|
|
2829
|
+
* Throws the fallback error for unsupported value types like `bigint` and `NaN`.
|
|
2830
|
+
*
|
|
2831
|
+
* @private function of `checkSerializableAsJson`
|
|
2832
|
+
*/
|
|
2833
|
+
function throwUnknownTypeError(context) {
|
|
2834
|
+
throw new UnexpectedError(spacetrim.spaceTrim((block) => `
|
|
2835
|
+
\`${context.name}\` is unknown type
|
|
2726
2836
|
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
}
|
|
2837
|
+
Additional message for \`${context.name}\`:
|
|
2838
|
+
${block(context.message || '(nothing)')}
|
|
2839
|
+
`));
|
|
2731
2840
|
}
|
|
2732
|
-
// TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
2733
|
-
// TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
|
|
2734
|
-
// Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
2735
2841
|
|
|
2736
2842
|
/**
|
|
2737
2843
|
* Creates a deep clone of the given object
|