@promptbook/vercel 0.102.0-9 → 0.103.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.
Files changed (33) hide show
  1. package/esm/index.es.js +942 -11
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/color.index.d.ts +2 -0
  4. package/esm/typings/src/_packages/components.index.d.ts +4 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +6 -0
  6. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  7. package/esm/typings/src/book-components/Chat/Chat/ChatMessageItem.d.ts +9 -1
  8. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +4 -0
  9. package/esm/typings/src/book-components/Chat/save/_common/ChatSaveFormatDefinition.d.ts +43 -5
  10. package/esm/typings/src/book-components/Chat/save/html/htmlSaveFormatDefinition.d.ts +9 -2
  11. package/esm/typings/src/book-components/Chat/save/index.d.ts +38 -8
  12. package/esm/typings/src/book-components/Chat/save/json/jsonSaveFormatDefinition.d.ts +6 -2
  13. package/esm/typings/src/book-components/Chat/save/markdown/mdSaveFormatDefinition.d.ts +5 -1
  14. package/esm/typings/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.d.ts +6 -2
  15. package/esm/typings/src/book-components/Chat/save/react/reactSaveFormatDefinition.d.ts +16 -0
  16. package/esm/typings/src/book-components/Chat/save/text/txtSaveFormatDefinition.d.ts +5 -1
  17. package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +1 -1
  18. package/esm/typings/src/book-components/Chat/types/ChatParticipant.d.ts +1 -1
  19. package/esm/typings/src/book-components/Chat/utils/exportChatHistory.d.ts +1 -1
  20. package/esm/typings/src/book-components/icons/SaveIcon.d.ts +10 -0
  21. package/esm/typings/src/config.d.ts +26 -4
  22. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
  23. package/esm/typings/src/utils/color/Color.d.ts +8 -0
  24. package/esm/typings/src/utils/color/operators/darken.d.ts +2 -1
  25. package/esm/typings/src/utils/color/operators/grayscale.d.ts +2 -1
  26. package/esm/typings/src/utils/color/operators/lighten.d.ts +2 -1
  27. package/esm/typings/src/utils/color/operators/mixWithColor.d.ts +2 -1
  28. package/esm/typings/src/utils/color/operators/saturate.d.ts +13 -0
  29. package/esm/typings/src/utils/serialization/serializeToPromptbookJavascript.d.ts +22 -0
  30. package/esm/typings/src/version.d.ts +1 -1
  31. package/package.json +2 -2
  32. package/umd/index.umd.js +942 -11
  33. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -16,7 +16,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
16
16
  * @generated
17
17
  * @see https://github.com/webgptorg/promptbook
18
18
  */
19
- const PROMPTBOOK_ENGINE_VERSION = '0.102.0-9';
19
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-0';
20
20
  /**
21
21
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
22
22
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -584,6 +584,895 @@ function $getCurrentDate() {
584
584
  return new Date().toISOString();
585
585
  }
586
586
 
587
+ /**
588
+ * @private util of `@promptbook/color`
589
+ * @de
590
+ */
591
+ class TakeChain {
592
+ constructor(value) {
593
+ this.value = value;
594
+ }
595
+ then(callback) {
596
+ const newValue = callback(this.value);
597
+ return take(newValue);
598
+ }
599
+ }
600
+
601
+ /**
602
+ * A function that takes an initial value and returns a proxy object with chainable methods.
603
+ *
604
+ * @param {*} initialValue - The initial value.
605
+ * @returns {Proxy<WithTake<TValue>>} - A proxy object with a `take` method.
606
+ *
607
+ * @private util of `@promptbook/color`
608
+ * @deprecated [🤡] Use some better functional library instead of `TakeChain`
609
+ */
610
+ function take(initialValue) {
611
+ if (initialValue instanceof TakeChain) {
612
+ return initialValue;
613
+ }
614
+ return new Proxy(new TakeChain(initialValue), {
615
+ get(target, property, receiver) {
616
+ if (Reflect.has(target, property)) {
617
+ return Reflect.get(target, property, receiver);
618
+ }
619
+ else if (Reflect.has(initialValue, property)) {
620
+ return Reflect.get(initialValue, property, receiver);
621
+ }
622
+ else {
623
+ return undefined;
624
+ }
625
+ },
626
+ });
627
+ }
628
+
629
+ /**
630
+ * 🎨 List of all 140 color names which are supported by CSS
631
+ *
632
+ * @public exported from `@promptbook/color`
633
+ */
634
+ const CSS_COLORS = {
635
+ transparent: 'rgba(0,0,0,0)',
636
+ aliceblue: '#f0f8ff',
637
+ antiquewhite: '#faebd7',
638
+ aqua: '#00ffff',
639
+ aquamarine: '#7fffd4',
640
+ azure: '#f0ffff',
641
+ beige: '#f5f5dc',
642
+ bisque: '#ffe4c4',
643
+ black: '#000000',
644
+ blanchedalmond: '#ffebcd',
645
+ blue: '#0000ff',
646
+ blueviolet: '#8a2be2',
647
+ brown: '#a52a2a',
648
+ burlywood: '#deb887',
649
+ cadetblue: '#5f9ea0',
650
+ chartreuse: '#7fff00',
651
+ chocolate: '#d2691e',
652
+ coral: '#ff7f50',
653
+ cornflowerblue: '#6495ed',
654
+ cornsilk: '#fff8dc',
655
+ crimson: '#dc143c',
656
+ cyan: '#00ffff',
657
+ darkblue: '#00008b',
658
+ darkcyan: '#008b8b',
659
+ darkgoldenrod: '#b8860b',
660
+ darkgray: '#a9a9a9',
661
+ darkgrey: '#a9a9a9',
662
+ darkgreen: '#006400',
663
+ darkkhaki: '#bdb76b',
664
+ darkmagenta: '#8b008b',
665
+ darkolivegreen: '#556b2f',
666
+ darkorange: '#ff8c00',
667
+ darkorchid: '#9932cc',
668
+ darkred: '#8b0000',
669
+ darksalmon: '#e9967a',
670
+ darkseagreen: '#8fbc8f',
671
+ darkslateblue: '#483d8b',
672
+ darkslategray: '#2f4f4f',
673
+ darkslategrey: '#2f4f4f',
674
+ darkturquoise: '#00ced1',
675
+ darkviolet: '#9400d3',
676
+ deeppink: '#ff1493',
677
+ deepskyblue: '#00bfff',
678
+ dimgray: '#696969',
679
+ dimgrey: '#696969',
680
+ dodgerblue: '#1e90ff',
681
+ firebrick: '#b22222',
682
+ floralwhite: '#fffaf0',
683
+ forestgreen: '#228b22',
684
+ fuchsia: '#ff00ff',
685
+ gainsboro: '#dcdcdc',
686
+ ghostwhite: '#f8f8ff',
687
+ gold: '#ffd700',
688
+ goldenrod: '#daa520',
689
+ gray: '#808080',
690
+ grey: '#808080',
691
+ green: '#008000',
692
+ greenyellow: '#adff2f',
693
+ honeydew: '#f0fff0',
694
+ hotpink: '#ff69b4',
695
+ indianred: '#cd5c5c',
696
+ indigo: '#4b0082',
697
+ ivory: '#fffff0',
698
+ khaki: '#f0e68c',
699
+ lavender: '#e6e6fa',
700
+ lavenderblush: '#fff0f5',
701
+ lawngreen: '#7cfc00',
702
+ lemonchiffon: '#fffacd',
703
+ lightblue: '#add8e6',
704
+ lightcoral: '#f08080',
705
+ lightcyan: '#e0ffff',
706
+ lightgoldenrodyellow: '#fafad2',
707
+ lightgray: '#d3d3d3',
708
+ lightgrey: '#d3d3d3',
709
+ lightgreen: '#90ee90',
710
+ lightpink: '#ffb6c1',
711
+ lightsalmon: '#ffa07a',
712
+ lightseagreen: '#20b2aa',
713
+ lightskyblue: '#87cefa',
714
+ lightslategray: '#778899',
715
+ lightslategrey: '#778899',
716
+ lightsteelblue: '#b0c4de',
717
+ lightyellow: '#ffffe0',
718
+ lime: '#00ff00',
719
+ limegreen: '#32cd32',
720
+ linen: '#faf0e6',
721
+ magenta: '#ff00ff',
722
+ maroon: '#800000',
723
+ mediumaquamarine: '#66cdaa',
724
+ mediumblue: '#0000cd',
725
+ mediumorchid: '#ba55d3',
726
+ mediumpurple: '#9370db',
727
+ mediumseagreen: '#3cb371',
728
+ mediumslateblue: '#7b68ee',
729
+ mediumspringgreen: '#00fa9a',
730
+ mediumturquoise: '#48d1cc',
731
+ mediumvioletred: '#c71585',
732
+ midnightblue: '#191970',
733
+ mintcream: '#f5fffa',
734
+ mistyrose: '#ffe4e1',
735
+ moccasin: '#ffe4b5',
736
+ navajowhite: '#ffdead',
737
+ navy: '#000080',
738
+ oldlace: '#fdf5e6',
739
+ olive: '#808000',
740
+ olivedrab: '#6b8e23',
741
+ orange: '#ffa500',
742
+ orangered: '#ff4500',
743
+ orchid: '#da70d6',
744
+ palegoldenrod: '#eee8aa',
745
+ palegreen: '#98fb98',
746
+ paleturquoise: '#afeeee',
747
+ palevioletred: '#db7093',
748
+ papayawhip: '#ffefd5',
749
+ peachpuff: '#ffdab9',
750
+ peru: '#cd853f',
751
+ pink: '#ffc0cb',
752
+ plum: '#dda0dd',
753
+ powderblue: '#b0e0e6',
754
+ purple: '#800080',
755
+ rebeccapurple: '#663399',
756
+ red: '#ff0000',
757
+ rosybrown: '#bc8f8f',
758
+ royalblue: '#4169e1',
759
+ saddlebrown: '#8b4513',
760
+ salmon: '#fa8072',
761
+ sandybrown: '#f4a460',
762
+ seagreen: '#2e8b57',
763
+ seashell: '#fff5ee',
764
+ sienna: '#a0522d',
765
+ silver: '#c0c0c0',
766
+ skyblue: '#87ceeb',
767
+ slateblue: '#6a5acd',
768
+ slategray: '#708090',
769
+ slategrey: '#708090',
770
+ snow: '#fffafa',
771
+ springgreen: '#00ff7f',
772
+ steelblue: '#4682b4',
773
+ tan: '#d2b48c',
774
+ teal: '#008080',
775
+ thistle: '#d8bfd8',
776
+ tomato: '#ff6347',
777
+ turquoise: '#40e0d0',
778
+ violet: '#ee82ee',
779
+ wheat: '#f5deb3',
780
+ white: '#ffffff',
781
+ whitesmoke: '#f5f5f5',
782
+ yellow: '#ffff00',
783
+ yellowgreen: '#9acd32',
784
+ };
785
+ /**
786
+ * Note: [💞] Ignore a discrepancy between file name and entity name
787
+ */
788
+
789
+ /**
790
+ * Validates that a channel value is a valid number within the range of 0 to 255.
791
+ * Throws an error if the value is not valid.
792
+ *
793
+ * @param channelName - The name of the channel being validated.
794
+ * @param value - The value of the channel to validate.
795
+ * @throws Will throw an error if the value is not a valid channel number.
796
+ *
797
+ * @private util of `@promptbook/color`
798
+ */
799
+ function checkChannelValue(channelName, value) {
800
+ if (typeof value !== 'number') {
801
+ throw new Error(`${channelName} channel value is not number but ${typeof value}`);
802
+ }
803
+ if (isNaN(value)) {
804
+ throw new Error(`${channelName} channel value is NaN`);
805
+ }
806
+ if (Math.round(value) !== value) {
807
+ throw new Error(`${channelName} channel is not whole number, it is ${value}`);
808
+ }
809
+ if (value < 0) {
810
+ throw new Error(`${channelName} channel is lower than 0, it is ${value}`);
811
+ }
812
+ if (value > 255) {
813
+ throw new Error(`${channelName} channel is greater than 255, it is ${value}`);
814
+ }
815
+ }
816
+ /**
817
+ * TODO: [🧠][🚓] Is/which combination it better to use asserts/check, validate or is utility function?
818
+ */
819
+
820
+ /**
821
+ * Color object represents an RGB color with alpha channel
822
+ *
823
+ * Note: There is no fromObject/toObject because the most logical way to serialize color is as a hex string (#009edd)
824
+ *
825
+ * @public exported from `@promptbook/color`
826
+ */
827
+ class Color {
828
+ /**
829
+ * Creates a new Color instance from miscellaneous formats
830
+ * - It can receive Color instance and just return the same instance
831
+ * - It can receive color in string format for example `#009edd`, `rgb(0,158,221)`, `rgb(0%,62%,86.7%)`, `hsl(197.1,100%,43.3%)`
832
+ *
833
+ * Note: This is not including fromImage because detecting color from an image is heavy task which requires async stuff and we cannot safely determine with overloading if return value will be a promise
834
+ *
835
+ * @param color
836
+ * @returns Color object
837
+ */
838
+ static from(color) {
839
+ if (color instanceof Color) {
840
+ return take(color);
841
+ }
842
+ else if (Color.isColor(color)) {
843
+ return take(color);
844
+ }
845
+ else if (typeof color === 'string') {
846
+ return Color.fromString(color);
847
+ }
848
+ else {
849
+ console.error({ color });
850
+ throw new Error(`Can not create color from given object`);
851
+ }
852
+ }
853
+ /**
854
+ * Creates a new Color instance from miscellaneous string formats
855
+ *
856
+ * @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`,...
857
+ * @returns Color object
858
+ */
859
+ static fromString(color) {
860
+ if (CSS_COLORS[color]) {
861
+ return Color.fromString(CSS_COLORS[color]);
862
+ // -----
863
+ }
864
+ else if (Color.isHexColorString(color)) {
865
+ return Color.fromHex(color);
866
+ // -----
867
+ }
868
+ else if (/^hsl\(\s*(\d+)\s*,\s*(\d+(?:\.\d+)?%)\s*,\s*(\d+(?:\.\d+)?%)\)$/.test(color)) {
869
+ return Color.fromHsl(color);
870
+ // -----
871
+ }
872
+ else if (/^rgb\((\s*[0-9-.%]+\s*,?){3}\)$/.test(color)) {
873
+ // TODO: [0] Should be fromRgbString and fromRgbaString one or two functions
874
+ return Color.fromRgbString(color);
875
+ // -----
876
+ }
877
+ else if (/^rgba\((\s*[0-9-.%]+\s*,?){4}\)$/.test(color)) {
878
+ return Color.fromRgbaString(color);
879
+ // -----
880
+ }
881
+ else {
882
+ throw new Error(`Can not create a new Color instance from string "${color}".`);
883
+ }
884
+ }
885
+ /**
886
+ * Gets common color
887
+ *
888
+ * @param key as a css string like `midnightblue`
889
+ * @returns Color object
890
+ */
891
+ static get(key) {
892
+ if (!CSS_COLORS[key]) {
893
+ throw new Error(`"${key}" is not a common css color.`);
894
+ }
895
+ return Color.fromString(CSS_COLORS[key]);
896
+ }
897
+ /**
898
+ * Creates a new Color instance from average color of given image
899
+ *
900
+ * @param image as a source for example `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAA1JREFUGFdjYJh39z8ABJgCe/ZvAS4AAAAASUVORK5CYII=`
901
+ * @returns Color object
902
+ */
903
+ static async fromImage(image) {
904
+ return Color.fromHex(`#009edd`);
905
+ }
906
+ /**
907
+ * Creates a new Color instance from color in hex format
908
+ *
909
+ * @param color in hex for example `#009edd`, `009edd`, `#555`,...
910
+ * @returns Color object
911
+ */
912
+ static fromHex(hex) {
913
+ const hexOriginal = hex;
914
+ if (hex.startsWith('#')) {
915
+ hex = hex.substring(1);
916
+ }
917
+ if (hex.length === 3) {
918
+ return Color.fromHex3(hex);
919
+ }
920
+ if (hex.length === 6) {
921
+ return Color.fromHex6(hex);
922
+ }
923
+ if (hex.length === 8) {
924
+ return Color.fromHex8(hex);
925
+ }
926
+ throw new Error(`Can not parse color from hex string "${hexOriginal}"`);
927
+ }
928
+ /**
929
+ * Creates a new Color instance from color in hex format with 3 color digits (without alpha channel)
930
+ *
931
+ * @param color in hex for example `09d`
932
+ * @returns Color object
933
+ */
934
+ static fromHex3(hex) {
935
+ const r = parseInt(hex.substr(0, 1), 16) * 16;
936
+ const g = parseInt(hex.substr(1, 1), 16) * 16;
937
+ const b = parseInt(hex.substr(2, 1), 16) * 16;
938
+ return take(new Color(r, g, b));
939
+ }
940
+ /**
941
+ * Creates a new Color instance from color in hex format with 6 color digits (without alpha channel)
942
+ *
943
+ * @param color in hex for example `009edd`
944
+ * @returns Color object
945
+ */
946
+ static fromHex6(hex) {
947
+ const r = parseInt(hex.substr(0, 2), 16);
948
+ const g = parseInt(hex.substr(2, 2), 16);
949
+ const b = parseInt(hex.substr(4, 2), 16);
950
+ return take(new Color(r, g, b));
951
+ }
952
+ /**
953
+ * Creates a new Color instance from color in hex format with 8 color digits (with alpha channel)
954
+ *
955
+ * @param color in hex for example `009edd`
956
+ * @returns Color object
957
+ */
958
+ static fromHex8(hex) {
959
+ const r = parseInt(hex.substr(0, 2), 16);
960
+ const g = parseInt(hex.substr(2, 2), 16);
961
+ const b = parseInt(hex.substr(4, 2), 16);
962
+ const a = parseInt(hex.substr(6, 2), 16);
963
+ return take(new Color(r, g, b, a));
964
+ }
965
+ /**
966
+ * Creates a new Color instance from color in hsl format
967
+ *
968
+ * @param color as a hsl for example `hsl(197.1,100%,43.3%)`
969
+ * @returns Color object
970
+ */
971
+ static fromHsl(hsl) {
972
+ const match = hsl.match(/^hsl\(\s*([0-9.]+)\s*,\s*([0-9.]+)%\s*,\s*([0-9.]+)%\s*\)$/);
973
+ if (!match) {
974
+ throw new Error(`Invalid hsl string format: "${hsl}"`);
975
+ }
976
+ const h = parseFloat(match[1]);
977
+ const s = parseFloat(match[2]) / 100;
978
+ const l = parseFloat(match[3]) / 100;
979
+ // HSL to RGB conversion
980
+ const c = (1 - Math.abs(2 * l - 1)) * s;
981
+ const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
982
+ const m = l - c / 2;
983
+ let r1 = 0, g1 = 0, b1 = 0;
984
+ if (h >= 0 && h < 60) {
985
+ r1 = c;
986
+ g1 = x;
987
+ b1 = 0;
988
+ }
989
+ else if (h >= 60 && h < 120) {
990
+ r1 = x;
991
+ g1 = c;
992
+ b1 = 0;
993
+ }
994
+ else if (h >= 120 && h < 180) {
995
+ r1 = 0;
996
+ g1 = c;
997
+ b1 = x;
998
+ }
999
+ else if (h >= 180 && h < 240) {
1000
+ r1 = 0;
1001
+ g1 = x;
1002
+ b1 = c;
1003
+ }
1004
+ else if (h >= 240 && h < 300) {
1005
+ r1 = x;
1006
+ g1 = 0;
1007
+ b1 = c;
1008
+ }
1009
+ else if (h >= 300 && h < 360) {
1010
+ r1 = c;
1011
+ g1 = 0;
1012
+ b1 = x;
1013
+ }
1014
+ const r = Math.round((r1 + m) * 255);
1015
+ const g = Math.round((g1 + m) * 255);
1016
+ const b = Math.round((b1 + m) * 255);
1017
+ return take(new Color(r, g, b));
1018
+ }
1019
+ /**
1020
+ * Creates a new Color instance from color in rgb format
1021
+ *
1022
+ * @param color as a rgb for example `rgb(0,158,221)`, `rgb(0%,62%,86.7%)`
1023
+ * @returns Color object
1024
+ */
1025
+ static fromRgbString(rgb) {
1026
+ const match = rgb.match(/^rgb\(\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*\)$/);
1027
+ if (!match) {
1028
+ throw new Error(`Invalid rgb string format: "${rgb}"`);
1029
+ }
1030
+ const parseChannel = (value) => {
1031
+ if (value.endsWith('%')) {
1032
+ // Percentage value
1033
+ const percent = parseFloat(value);
1034
+ return Math.round((percent / 100) * 255);
1035
+ }
1036
+ else {
1037
+ // Numeric value
1038
+ return Math.round(parseFloat(value));
1039
+ }
1040
+ };
1041
+ const r = parseChannel(match[1]);
1042
+ const g = parseChannel(match[2]);
1043
+ const b = parseChannel(match[3]);
1044
+ return take(new Color(r, g, b));
1045
+ }
1046
+ /**
1047
+ * Creates a new Color instance from color in rbga format
1048
+ *
1049
+ * @param color as a rgba for example `rgba(0,158,221,0.5)`, `rgb(0%,62%,86.7%,50%)`
1050
+ * @returns Color object
1051
+ */
1052
+ static fromRgbaString(rgba) {
1053
+ const match = rgba.match(/^rgba\(\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*\)$/);
1054
+ if (!match) {
1055
+ throw new Error(`Invalid rgba string format: "${rgba}"`);
1056
+ }
1057
+ const parseChannel = (value) => {
1058
+ if (value.endsWith('%')) {
1059
+ const percent = parseFloat(value);
1060
+ return Math.round((percent / 100) * 255);
1061
+ }
1062
+ else {
1063
+ return Math.round(parseFloat(value));
1064
+ }
1065
+ };
1066
+ const parseAlpha = (value) => {
1067
+ if (value.endsWith('%')) {
1068
+ const percent = parseFloat(value);
1069
+ return Math.round((percent / 100) * 255);
1070
+ }
1071
+ else {
1072
+ const alphaFloat = parseFloat(value);
1073
+ // If alpha is between 0 and 1, treat as float
1074
+ if (alphaFloat <= 1) {
1075
+ return Math.round(alphaFloat * 255);
1076
+ }
1077
+ // Otherwise, treat as 0-255
1078
+ return Math.round(alphaFloat);
1079
+ }
1080
+ };
1081
+ const r = parseChannel(match[1]);
1082
+ const g = parseChannel(match[2]);
1083
+ const b = parseChannel(match[3]);
1084
+ const a = parseAlpha(match[4]);
1085
+ return take(new Color(r, g, b, a));
1086
+ }
1087
+ /**
1088
+ * Creates a new Color for color channels values
1089
+ *
1090
+ * @param red number from 0 to 255
1091
+ * @param green number from 0 to 255
1092
+ * @param blue number from 0 to 255
1093
+ * @param alpha number from 0 (transparent) to 255 (opaque = default)
1094
+ * @returns Color object
1095
+ */
1096
+ static fromValues(red, green, blue, alpha = 255) {
1097
+ return take(new Color(red, green, blue, alpha));
1098
+ }
1099
+ /**
1100
+ * Checks if the given value is a valid Color object.
1101
+ *
1102
+ * @param {unknown} value - The value to check.
1103
+ * @return {value is WithTake<Color>} Returns true if the value is a valid Color object, false otherwise.
1104
+ */
1105
+ static isColor(value) {
1106
+ if (typeof value !== 'object') {
1107
+ return false;
1108
+ }
1109
+ if (value === null) {
1110
+ return false;
1111
+ }
1112
+ if (typeof value.red !== 'number' ||
1113
+ typeof value.green !== 'number' ||
1114
+ typeof value.blue !== 'number' ||
1115
+ typeof value.alpha !== 'number') {
1116
+ return false;
1117
+ }
1118
+ if (typeof value.then !== 'function') {
1119
+ return false;
1120
+ }
1121
+ return true;
1122
+ }
1123
+ /**
1124
+ * Checks if the given value is a valid hex color string
1125
+ *
1126
+ * @param value - value to check
1127
+ * @returns true if the value is a valid hex color string (e.g., `#009edd`, `#fff`, etc.)
1128
+ */
1129
+ static isHexColorString(value) {
1130
+ return typeof value === 'string' && /^#(?:[0-9a-fA-F]{3}){1,2}$/.test(value);
1131
+ }
1132
+ /**
1133
+ * Creates new Color object
1134
+ *
1135
+ * Note: Consider using one of static methods like `from` or `fromString`
1136
+ *
1137
+ * @param red number from 0 to 255
1138
+ * @param green number from 0 to 255
1139
+ * @param blue number from 0 to 255
1140
+ * @param alpha number from 0 (transparent) to 255 (opaque)
1141
+ */
1142
+ constructor(red, green, blue, alpha = 255) {
1143
+ this.red = red;
1144
+ this.green = green;
1145
+ this.blue = blue;
1146
+ this.alpha = alpha;
1147
+ checkChannelValue('Red', red);
1148
+ checkChannelValue('Green', green);
1149
+ checkChannelValue('Blue', blue);
1150
+ checkChannelValue('Alpha', alpha);
1151
+ }
1152
+ /**
1153
+ * Shortcut for `red` property
1154
+ * Number from 0 to 255
1155
+ * @alias red
1156
+ */
1157
+ get r() {
1158
+ return this.red;
1159
+ }
1160
+ /**
1161
+ * Shortcut for `green` property
1162
+ * Number from 0 to 255
1163
+ * @alias green
1164
+ */
1165
+ get g() {
1166
+ return this.green;
1167
+ }
1168
+ /**
1169
+ * Shortcut for `blue` property
1170
+ * Number from 0 to 255
1171
+ * @alias blue
1172
+ */
1173
+ get b() {
1174
+ return this.blue;
1175
+ }
1176
+ /**
1177
+ * Shortcut for `alpha` property
1178
+ * Number from 0 (transparent) to 255 (opaque)
1179
+ * @alias alpha
1180
+ */
1181
+ get a() {
1182
+ return this.alpha;
1183
+ }
1184
+ /**
1185
+ * Shortcut for `alpha` property
1186
+ * Number from 0 (transparent) to 255 (opaque)
1187
+ * @alias alpha
1188
+ */
1189
+ get opacity() {
1190
+ return this.alpha;
1191
+ }
1192
+ /**
1193
+ * Shortcut for 1-`alpha` property
1194
+ */
1195
+ get transparency() {
1196
+ return 255 - this.alpha;
1197
+ }
1198
+ clone() {
1199
+ return take(new Color(this.red, this.green, this.blue, this.alpha));
1200
+ }
1201
+ toString() {
1202
+ return this.toHex();
1203
+ }
1204
+ toHex() {
1205
+ if (this.alpha === 255) {
1206
+ return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
1207
+ .toString(16)
1208
+ .padStart(2, '0')}`;
1209
+ }
1210
+ else {
1211
+ return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
1212
+ .toString(16)
1213
+ .padStart(2, '0')}${this.alpha.toString(16).padStart(2, '0')}`;
1214
+ }
1215
+ }
1216
+ toRgb() {
1217
+ if (this.alpha === 255) {
1218
+ return `rgb(${this.red}, ${this.green}, ${this.blue})`;
1219
+ }
1220
+ else {
1221
+ return `rgba(${this.red}, ${this.green}, ${this.blue}, ${Math.round((this.alpha / 255) * 100)}%)`;
1222
+ }
1223
+ }
1224
+ toHsl() {
1225
+ throw new Error(`Getting HSL is not implemented`);
1226
+ }
1227
+ }
1228
+ /**
1229
+ * TODO: [🥻] Split Color class and color type
1230
+ * TODO: For each method a corresponding static method should be created
1231
+ * Like clone can be done by color.clone() OR Color.clone(color)
1232
+ * TODO: Probably as an independent LIB OR add to LIB xyzt (ask @roseckyj)
1233
+ * TODO: !! Transfer back to Collboard (whole directory)
1234
+ * TODO: Maybe [🏌️‍♂️] change ACRY toString => (toHex) toRgb when there will be toRgb and toRgba united
1235
+ * TODO: Convert getters to methods - getters only for values
1236
+ * TODO: Write tests
1237
+ * TODO: Getters for alpha, opacity, transparency, r, b, g, h, s, l, a,...
1238
+ * TODO: [0] Should be fromRgbString and fromRgbaString one or two functions + one or two regex
1239
+ * TODO: Use rgb, rgba, hsl for testing and parsing with the same regex
1240
+ * TODO: Regex for rgb, rgba, hsl does not support all options like deg, rad, turn,...
1241
+ * TODO: Convolution matrix
1242
+ * TODO: Maybe connect with textures
1243
+ */
1244
+
1245
+ /**
1246
+ * Converts HSL values to RGB values
1247
+ *
1248
+ * @param hue [0-1]
1249
+ * @param saturation [0-1]
1250
+ * @param lightness [0-1]
1251
+ * @returns [red, green, blue] [0-255]
1252
+ *
1253
+ * @private util of `@promptbook/color`
1254
+ */
1255
+ function hslToRgb(hue, saturation, lightness) {
1256
+ let red;
1257
+ let green;
1258
+ let blue;
1259
+ if (saturation === 0) {
1260
+ // achromatic
1261
+ red = lightness;
1262
+ green = lightness;
1263
+ blue = lightness;
1264
+ }
1265
+ else {
1266
+ // TODO: Extract to separate function
1267
+ const hue2rgb = (p, q, t) => {
1268
+ if (t < 0)
1269
+ t += 1;
1270
+ if (t > 1)
1271
+ t -= 1;
1272
+ if (t < 1 / 6)
1273
+ return p + (q - p) * 6 * t;
1274
+ if (t < 1 / 2)
1275
+ return q;
1276
+ if (t < 2 / 3)
1277
+ return p + (q - p) * (2 / 3 - t) * 6;
1278
+ return p;
1279
+ };
1280
+ const q = lightness < 0.5 ? lightness * (1 + saturation) : lightness + saturation - lightness * saturation;
1281
+ const p = 2 * lightness - q;
1282
+ red = hue2rgb(p, q, hue + 1 / 3);
1283
+ green = hue2rgb(p, q, hue);
1284
+ blue = hue2rgb(p, q, hue - 1 / 3);
1285
+ }
1286
+ return [Math.round(red * 255), Math.round(green * 255), Math.round(blue * 255)];
1287
+ }
1288
+ /**
1289
+ * TODO: Properly name all used internal variables
1290
+ */
1291
+
1292
+ /**
1293
+ * Converts RGB values to HSL values
1294
+ *
1295
+ * @param red [0-255]
1296
+ * @param green [0-255]
1297
+ * @param blue [0-255]
1298
+ * @returns [hue, saturation, lightness] [0-1]
1299
+ *
1300
+ * @private util of `@promptbook/color`
1301
+ */
1302
+ function rgbToHsl(red, green, blue) {
1303
+ red /= 255;
1304
+ green /= 255;
1305
+ blue /= 255;
1306
+ const max = Math.max(red, green, blue);
1307
+ const min = Math.min(red, green, blue);
1308
+ let hue;
1309
+ let saturation;
1310
+ const lightness = (max + min) / 2;
1311
+ if (max === min) {
1312
+ // achromatic
1313
+ hue = 0;
1314
+ saturation = 0;
1315
+ }
1316
+ else {
1317
+ const d = max - min;
1318
+ saturation = lightness > 0.5 ? d / (2 - max - min) : d / (max + min);
1319
+ switch (max) {
1320
+ case red:
1321
+ hue = (green - blue) / d + (green < blue ? 6 : 0);
1322
+ break;
1323
+ case green:
1324
+ hue = (blue - red) / d + 2;
1325
+ break;
1326
+ case blue:
1327
+ hue = (red - green) / d + 4;
1328
+ break;
1329
+ default:
1330
+ hue = 0;
1331
+ }
1332
+ hue /= 6;
1333
+ }
1334
+ return [hue, saturation, lightness];
1335
+ }
1336
+ /**
1337
+ * TODO: Properly name all used internal variables
1338
+ */
1339
+
1340
+ /**
1341
+ * Makes color transformer which lighten the given color
1342
+ *
1343
+ * @param amount from 0 to 1
1344
+ *
1345
+ * @public exported from `@promptbook/color`
1346
+ */
1347
+ function lighten(amount) {
1348
+ return ({ red, green, blue, alpha }) => {
1349
+ const [h, s, lInitial] = rgbToHsl(red, green, blue);
1350
+ let l = lInitial + amount;
1351
+ l = Math.max(0, Math.min(l, 1)); // Replace lodash clamp with Math.max and Math.min
1352
+ const [r, g, b] = hslToRgb(h, s, l);
1353
+ return Color.fromValues(r, g, b, alpha);
1354
+ };
1355
+ }
1356
+ /**
1357
+ * TODO: Maybe implement by mix+hsl
1358
+ */
1359
+
1360
+ /**
1361
+ * Calculates distance between two colors
1362
+ *
1363
+ * @param color1 first color
1364
+ * @param color2 second color
1365
+ *
1366
+ * Note: This function is inefficient. Use colorDistanceSquared instead if possible.
1367
+ *
1368
+ * @public exported from `@promptbook/color`
1369
+ */
1370
+ /**
1371
+ * Calculates distance between two colors without square root
1372
+ *
1373
+ * @param color1 first color
1374
+ * @param color2 second color
1375
+ *
1376
+ * @public exported from `@promptbook/color`
1377
+ */
1378
+ function colorDistanceSquared(color1, color2) {
1379
+ const rmean = (color1.red + color2.red) / 2;
1380
+ const r = color1.red - color2.red;
1381
+ const g = color1.green - color2.green;
1382
+ const b = color1.blue - color2.blue;
1383
+ const weightR = 2 + rmean / 256;
1384
+ const weightG = 4.0;
1385
+ const weightB = 2 + (255 - rmean) / 256;
1386
+ const distance = weightR * r * r + weightG * g * g + weightB * b * b;
1387
+ return distance;
1388
+ }
1389
+
1390
+ /**
1391
+ * Makes color transformer which finds the nearest color from the given list
1392
+ *
1393
+ * @param colors array of colors to choose from
1394
+ *
1395
+ * @public exported from `@promptbook/color`
1396
+ */
1397
+ function nearest(...colors) {
1398
+ return (color) => {
1399
+ const distances = colors.map((c) => colorDistanceSquared(c, color));
1400
+ const minDistance = Math.min(...distances);
1401
+ const minIndex = distances.indexOf(minDistance);
1402
+ const nearestColor = colors[minIndex];
1403
+ return nearestColor;
1404
+ };
1405
+ }
1406
+
1407
+ /**
1408
+ * Color transformer which returns the negative color
1409
+ *
1410
+ * @public exported from `@promptbook/color`
1411
+ */
1412
+ function negative(color) {
1413
+ const r = 255 - color.red;
1414
+ const g = 255 - color.green;
1415
+ const b = 255 - color.blue;
1416
+ return Color.fromValues(r, g, b, color.alpha);
1417
+ }
1418
+
1419
+ /**
1420
+ * Makes color transformer which finds the furthest color from the given list
1421
+ *
1422
+ * @param colors array of colors to choose from
1423
+ *
1424
+ * @public exported from `@promptbook/color`
1425
+ */
1426
+ function furthest(...colors) {
1427
+ return (color) => {
1428
+ const furthestColor = negative(nearest(...colors.map(negative))(color));
1429
+ return furthestColor;
1430
+ };
1431
+ }
1432
+ /**
1433
+ * Makes color transformer which finds the best text color (black or white) for the given background color
1434
+ *
1435
+ * @public exported from `@promptbook/color`
1436
+ */
1437
+ furthest(Color.get('white'), Color.from('black'));
1438
+
1439
+ /**
1440
+ * Makes color transformer which returns a grayscale version of the color
1441
+ *
1442
+ * @param amount from 0 to 1
1443
+ *
1444
+ * @public exported from `@promptbook/color`
1445
+ */
1446
+ function grayscale(amount) {
1447
+ return ({ red, green, blue, alpha }) => {
1448
+ const average = (red + green + blue) / 3;
1449
+ red = Math.round(average * amount + red * (1 - amount));
1450
+ green = Math.round(average * amount + green * (1 - amount));
1451
+ blue = Math.round(average * amount + blue * (1 - amount));
1452
+ return Color.fromValues(red, green, blue, alpha);
1453
+ };
1454
+ }
1455
+
1456
+ /**
1457
+ * Makes color transformer which saturate the given color
1458
+ *
1459
+ * @param amount from -1 to 1
1460
+ *
1461
+ * @public exported from `@promptbook/color`
1462
+ */
1463
+ function saturate(amount) {
1464
+ return ({ red, green, blue, alpha }) => {
1465
+ const [h, sInitial, l] = rgbToHsl(red, green, blue);
1466
+ let s = sInitial + amount;
1467
+ s = Math.max(0, Math.min(s, 1));
1468
+ const [r, g, b] = hslToRgb(h, s, l);
1469
+ return Color.fromValues(r, g, b, alpha);
1470
+ };
1471
+ }
1472
+ /**
1473
+ * TODO: Maybe implement by mix+hsl
1474
+ */
1475
+
587
1476
  /**
588
1477
  * Name for the Promptbook
589
1478
  *
@@ -604,6 +1493,32 @@ const ADMIN_EMAIL = 'pavol@ptbk.io';
604
1493
  * @public exported from `@promptbook/core`
605
1494
  */
606
1495
  const ADMIN_GITHUB_NAME = 'hejny';
1496
+ // <- TODO: [🐊] Pick the best claim
1497
+ /**
1498
+ * Color of the Promptbook
1499
+ *
1500
+ * TODO: [🗽] Unite branding and make single place for it
1501
+ *
1502
+ * @public exported from `@promptbook/core`
1503
+ */
1504
+ const PROMPTBOOK_COLOR = Color.fromHex('#79EAFD');
1505
+ // <- TODO: [🧠] Using `Color` here increases the package size approx 3kb, maybe remove it
1506
+ /**
1507
+ * Dark color of the Promptbook
1508
+ *
1509
+ * TODO: [🗽] Unite branding and make single place for it
1510
+ *
1511
+ * @public exported from `@promptbook/core`
1512
+ */
1513
+ PROMPTBOOK_COLOR.then(lighten(0.1)).then(saturate(0.9)).then(grayscale(0.9));
1514
+ /**
1515
+ * Color of the user (in chat)
1516
+ *
1517
+ * TODO: [🗽] Unite branding and make single place for it
1518
+ *
1519
+ * @public exported from `@promptbook/core`
1520
+ */
1521
+ Color.fromHex('#1D4ED8');
607
1522
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
608
1523
  /**
609
1524
  * The maximum number of iterations for a loops
@@ -1289,16 +2204,21 @@ function createExecutionToolsFromVercelProvider(options) {
1289
2204
  ...additionalChatSettings,
1290
2205
  });
1291
2206
  const rawPromptContent = templateParameters(content, { ...parameters, modelName });
1292
- const rawRequest = {
1293
- // <- TODO: [☂]
1294
- inputFormat: 'messages',
1295
- mode: {
1296
- type: 'regular',
1297
- tools: [
1298
- /* <- TODO: Pass the tools */
2207
+ // Support for passing a chat thread (multi-message conversation)
2208
+ let promptMessages;
2209
+ if ('thread' in prompt && Array.isArray(prompt.thread)) {
2210
+ promptMessages = prompt.thread.map((msg) => ({
2211
+ role: msg.role === 'assistant' ? 'assistant' : (msg.role === 'system' ? 'system' : 'user'),
2212
+ content: [
2213
+ {
2214
+ type: 'text',
2215
+ text: msg.content,
2216
+ },
1299
2217
  ],
1300
- },
1301
- prompt: [
2218
+ }));
2219
+ }
2220
+ else {
2221
+ promptMessages = [
1302
2222
  ...(modelRequirements.systemMessage === undefined
1303
2223
  ? []
1304
2224
  : [
@@ -1316,7 +2236,18 @@ function createExecutionToolsFromVercelProvider(options) {
1316
2236
  },
1317
2237
  ],
1318
2238
  },
1319
- ],
2239
+ ];
2240
+ }
2241
+ const rawRequest = {
2242
+ // <- TODO: [☂]
2243
+ inputFormat: 'messages',
2244
+ mode: {
2245
+ type: 'regular',
2246
+ tools: [
2247
+ /* <- TODO: Pass the tools */
2248
+ ],
2249
+ },
2250
+ prompt: promptMessages,
1320
2251
  };
1321
2252
  const start = $getCurrentDate();
1322
2253
  if (options.isVerbose) {