@promptbook/documents 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 +313 -210
- 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 +313 -210
- 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/esm/index.es.js
CHANGED
|
@@ -26,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
26
26
|
* @generated
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
29
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-80';
|
|
30
30
|
/**
|
|
31
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
32
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -294,6 +294,111 @@ function checkChannelValue(channelName, value) {
|
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
+
/**
|
|
298
|
+
* Shared immutable channel storage and serialization helpers for `Color`.
|
|
299
|
+
*
|
|
300
|
+
* @private base class of Color
|
|
301
|
+
*/
|
|
302
|
+
class ColorValue {
|
|
303
|
+
constructor(red, green, blue, alpha = 255) {
|
|
304
|
+
this.red = red;
|
|
305
|
+
this.green = green;
|
|
306
|
+
this.blue = blue;
|
|
307
|
+
this.alpha = alpha;
|
|
308
|
+
checkChannelValue('Red', red);
|
|
309
|
+
checkChannelValue('Green', green);
|
|
310
|
+
checkChannelValue('Blue', blue);
|
|
311
|
+
checkChannelValue('Alpha', alpha);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Shortcut for `red` property
|
|
315
|
+
* Number from 0 to 255
|
|
316
|
+
* @alias red
|
|
317
|
+
*/
|
|
318
|
+
get r() {
|
|
319
|
+
return this.red;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Shortcut for `green` property
|
|
323
|
+
* Number from 0 to 255
|
|
324
|
+
* @alias green
|
|
325
|
+
*/
|
|
326
|
+
get g() {
|
|
327
|
+
return this.green;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Shortcut for `blue` property
|
|
331
|
+
* Number from 0 to 255
|
|
332
|
+
* @alias blue
|
|
333
|
+
*/
|
|
334
|
+
get b() {
|
|
335
|
+
return this.blue;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Shortcut for `alpha` property
|
|
339
|
+
* Number from 0 (transparent) to 255 (opaque)
|
|
340
|
+
* @alias alpha
|
|
341
|
+
*/
|
|
342
|
+
get a() {
|
|
343
|
+
return this.alpha;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Shortcut for `alpha` property
|
|
347
|
+
* Number from 0 (transparent) to 255 (opaque)
|
|
348
|
+
* @alias alpha
|
|
349
|
+
*/
|
|
350
|
+
get opacity() {
|
|
351
|
+
return this.alpha;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Shortcut for 1-`alpha` property
|
|
355
|
+
*/
|
|
356
|
+
get transparency() {
|
|
357
|
+
return 255 - this.alpha;
|
|
358
|
+
}
|
|
359
|
+
clone() {
|
|
360
|
+
return take(this.createColor(this.red, this.green, this.blue, this.alpha));
|
|
361
|
+
}
|
|
362
|
+
toString() {
|
|
363
|
+
return this.toHex();
|
|
364
|
+
}
|
|
365
|
+
toHex() {
|
|
366
|
+
if (this.alpha === 255) {
|
|
367
|
+
return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
|
|
368
|
+
.toString(16)
|
|
369
|
+
.padStart(2, '0')}`;
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
|
|
373
|
+
.toString(16)
|
|
374
|
+
.padStart(2, '0')}${this.alpha.toString(16).padStart(2, '0')}`;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
toRgb() {
|
|
378
|
+
if (this.alpha === 255) {
|
|
379
|
+
return `rgb(${this.red}, ${this.green}, ${this.blue})`;
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
return `rgba(${this.red}, ${this.green}, ${this.blue}, ${Math.round((this.alpha / 255) * 100)}%)`;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
toHsl() {
|
|
386
|
+
throw new Error(`Getting HSL is not implemented`);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Checks if the given value is a valid hex color string
|
|
392
|
+
*
|
|
393
|
+
* @param value - value to check
|
|
394
|
+
* @returns true if the value is a valid hex color string (e.g., `#009edd`, `#fff`, etc.)
|
|
395
|
+
*
|
|
396
|
+
* @private function of Color
|
|
397
|
+
*/
|
|
398
|
+
function isHexColorString(value) {
|
|
399
|
+
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));
|
|
400
|
+
}
|
|
401
|
+
|
|
297
402
|
/**
|
|
298
403
|
* Constant for short hex lengths.
|
|
299
404
|
*/
|
|
@@ -505,16 +610,53 @@ function parseAlphaValue(value) {
|
|
|
505
610
|
|
|
506
611
|
/**
|
|
507
612
|
* Pattern matching hsl regex.
|
|
613
|
+
*
|
|
614
|
+
* @private function of Color
|
|
508
615
|
*/
|
|
509
616
|
const HSL_REGEX_PATTERN = /^hsl\(\s*([0-9.]+)\s*,\s*([0-9.]+)%\s*,\s*([0-9.]+)%\s*\)$/;
|
|
510
617
|
/**
|
|
511
618
|
* Pattern matching RGB regex.
|
|
619
|
+
*
|
|
620
|
+
* @private function of Color
|
|
512
621
|
*/
|
|
513
622
|
const RGB_REGEX_PATTERN = /^rgb\(\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*\)$/;
|
|
514
623
|
/**
|
|
515
624
|
* Pattern matching rgba regex.
|
|
625
|
+
*
|
|
626
|
+
* @private function of Color
|
|
516
627
|
*/
|
|
517
628
|
const RGBA_REGEX_PATTERN = /^rgba\(\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*\)$/;
|
|
629
|
+
/**
|
|
630
|
+
* Parses a supported color string into RGBA channels.
|
|
631
|
+
*
|
|
632
|
+
* @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`,...
|
|
633
|
+
* @returns RGBA channel values.
|
|
634
|
+
*
|
|
635
|
+
* @private function of Color
|
|
636
|
+
*/
|
|
637
|
+
function parseColorString(color) {
|
|
638
|
+
const trimmed = color.trim();
|
|
639
|
+
const cssColor = CSS_COLORS[trimmed];
|
|
640
|
+
if (cssColor) {
|
|
641
|
+
return parseColorString(cssColor);
|
|
642
|
+
}
|
|
643
|
+
else if (isHexColorString(trimmed)) {
|
|
644
|
+
return parseHexColor(trimmed);
|
|
645
|
+
}
|
|
646
|
+
if (HSL_REGEX_PATTERN.test(trimmed)) {
|
|
647
|
+
return parseHslColor(trimmed);
|
|
648
|
+
}
|
|
649
|
+
else if (RGB_REGEX_PATTERN.test(trimmed)) {
|
|
650
|
+
return parseRgbColor(trimmed);
|
|
651
|
+
}
|
|
652
|
+
else if (RGBA_REGEX_PATTERN.test(trimmed)) {
|
|
653
|
+
return parseRgbaColor(trimmed);
|
|
654
|
+
}
|
|
655
|
+
else {
|
|
656
|
+
throw new Error(`Can not create a new Color instance from string "${trimmed}".`);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
518
660
|
/**
|
|
519
661
|
* Color object represents an RGB color with alpha channel
|
|
520
662
|
*
|
|
@@ -522,7 +664,7 @@ const RGBA_REGEX_PATTERN = /^rgba\(\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.
|
|
|
522
664
|
*
|
|
523
665
|
* @public exported from `@promptbook/color`
|
|
524
666
|
*/
|
|
525
|
-
class Color {
|
|
667
|
+
class Color extends ColorValue {
|
|
526
668
|
/**
|
|
527
669
|
* Creates a new Color instance from miscellaneous formats
|
|
528
670
|
* - It can receive Color instance and just return the same instance
|
|
@@ -595,25 +737,7 @@ class Color {
|
|
|
595
737
|
* @returns Color object
|
|
596
738
|
*/
|
|
597
739
|
static fromString(color) {
|
|
598
|
-
|
|
599
|
-
if (CSS_COLORS[trimmed]) {
|
|
600
|
-
return Color.fromString(CSS_COLORS[trimmed]);
|
|
601
|
-
}
|
|
602
|
-
else if (Color.isHexColorString(trimmed)) {
|
|
603
|
-
return Color.fromHex(trimmed);
|
|
604
|
-
}
|
|
605
|
-
if (HSL_REGEX_PATTERN.test(trimmed)) {
|
|
606
|
-
return Color.fromHsl(trimmed);
|
|
607
|
-
}
|
|
608
|
-
else if (RGB_REGEX_PATTERN.test(trimmed)) {
|
|
609
|
-
return Color.fromRgbString(trimmed);
|
|
610
|
-
}
|
|
611
|
-
else if (RGBA_REGEX_PATTERN.test(trimmed)) {
|
|
612
|
-
return Color.fromRgbaString(trimmed);
|
|
613
|
-
}
|
|
614
|
-
else {
|
|
615
|
-
throw new Error(`Can not create a new Color instance from string "${trimmed}".`);
|
|
616
|
-
}
|
|
740
|
+
return Color.fromColorChannels(parseColorString(color));
|
|
617
741
|
}
|
|
618
742
|
/**
|
|
619
743
|
* Gets common color
|
|
@@ -643,8 +767,7 @@ class Color {
|
|
|
643
767
|
* @returns Color object
|
|
644
768
|
*/
|
|
645
769
|
static fromHex(hex) {
|
|
646
|
-
|
|
647
|
-
return take(new Color(red, green, blue, alpha));
|
|
770
|
+
return Color.fromColorChannels(parseHexColor(hex));
|
|
648
771
|
}
|
|
649
772
|
/**
|
|
650
773
|
* Creates a new Color instance from color in hsl format
|
|
@@ -653,8 +776,7 @@ class Color {
|
|
|
653
776
|
* @returns Color object
|
|
654
777
|
*/
|
|
655
778
|
static fromHsl(hsl) {
|
|
656
|
-
|
|
657
|
-
return take(new Color(red, green, blue, alpha));
|
|
779
|
+
return Color.fromColorChannels(parseHslColor(hsl));
|
|
658
780
|
}
|
|
659
781
|
/**
|
|
660
782
|
* Creates a new Color instance from color in rgb format
|
|
@@ -663,8 +785,7 @@ class Color {
|
|
|
663
785
|
* @returns Color object
|
|
664
786
|
*/
|
|
665
787
|
static fromRgbString(rgb) {
|
|
666
|
-
|
|
667
|
-
return take(new Color(red, green, blue, alpha));
|
|
788
|
+
return Color.fromColorChannels(parseRgbColor(rgb));
|
|
668
789
|
}
|
|
669
790
|
/**
|
|
670
791
|
* Creates a new Color instance from color in rbga format
|
|
@@ -673,8 +794,7 @@ class Color {
|
|
|
673
794
|
* @returns Color object
|
|
674
795
|
*/
|
|
675
796
|
static fromRgbaString(rgba) {
|
|
676
|
-
|
|
677
|
-
return take(new Color(red, green, blue, alpha));
|
|
797
|
+
return Color.fromColorChannels(parseRgbaColor(rgba));
|
|
678
798
|
}
|
|
679
799
|
/**
|
|
680
800
|
* Creates a new Color for color channels values
|
|
@@ -686,7 +806,7 @@ class Color {
|
|
|
686
806
|
* @returns Color object
|
|
687
807
|
*/
|
|
688
808
|
static fromValues(red, green, blue, alpha = 255) {
|
|
689
|
-
return
|
|
809
|
+
return Color.fromColorChannels({ red, green, blue, alpha });
|
|
690
810
|
}
|
|
691
811
|
/**
|
|
692
812
|
* Checks if the given value is a valid Color object.
|
|
@@ -719,8 +839,7 @@ class Color {
|
|
|
719
839
|
* @returns true if the value is a valid hex color string (e.g., `#009edd`, `#fff`, etc.)
|
|
720
840
|
*/
|
|
721
841
|
static isHexColorString(value) {
|
|
722
|
-
return (
|
|
723
|
-
/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(value));
|
|
842
|
+
return isHexColorString(value);
|
|
724
843
|
}
|
|
725
844
|
/**
|
|
726
845
|
* Creates new Color object
|
|
@@ -733,89 +852,13 @@ class Color {
|
|
|
733
852
|
* @param alpha number from 0 (transparent) to 255 (opaque)
|
|
734
853
|
*/
|
|
735
854
|
constructor(red, green, blue, alpha = 255) {
|
|
736
|
-
|
|
737
|
-
this.green = green;
|
|
738
|
-
this.blue = blue;
|
|
739
|
-
this.alpha = alpha;
|
|
740
|
-
checkChannelValue('Red', red);
|
|
741
|
-
checkChannelValue('Green', green);
|
|
742
|
-
checkChannelValue('Blue', blue);
|
|
743
|
-
checkChannelValue('Alpha', alpha);
|
|
855
|
+
super(red, green, blue, alpha);
|
|
744
856
|
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
* Number from 0 to 255
|
|
748
|
-
* @alias red
|
|
749
|
-
*/
|
|
750
|
-
get r() {
|
|
751
|
-
return this.red;
|
|
857
|
+
createColor(red, green, blue, alpha) {
|
|
858
|
+
return new Color(red, green, blue, alpha);
|
|
752
859
|
}
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
* Number from 0 to 255
|
|
756
|
-
* @alias green
|
|
757
|
-
*/
|
|
758
|
-
get g() {
|
|
759
|
-
return this.green;
|
|
760
|
-
}
|
|
761
|
-
/**
|
|
762
|
-
* Shortcut for `blue` property
|
|
763
|
-
* Number from 0 to 255
|
|
764
|
-
* @alias blue
|
|
765
|
-
*/
|
|
766
|
-
get b() {
|
|
767
|
-
return this.blue;
|
|
768
|
-
}
|
|
769
|
-
/**
|
|
770
|
-
* Shortcut for `alpha` property
|
|
771
|
-
* Number from 0 (transparent) to 255 (opaque)
|
|
772
|
-
* @alias alpha
|
|
773
|
-
*/
|
|
774
|
-
get a() {
|
|
775
|
-
return this.alpha;
|
|
776
|
-
}
|
|
777
|
-
/**
|
|
778
|
-
* Shortcut for `alpha` property
|
|
779
|
-
* Number from 0 (transparent) to 255 (opaque)
|
|
780
|
-
* @alias alpha
|
|
781
|
-
*/
|
|
782
|
-
get opacity() {
|
|
783
|
-
return this.alpha;
|
|
784
|
-
}
|
|
785
|
-
/**
|
|
786
|
-
* Shortcut for 1-`alpha` property
|
|
787
|
-
*/
|
|
788
|
-
get transparency() {
|
|
789
|
-
return 255 - this.alpha;
|
|
790
|
-
}
|
|
791
|
-
clone() {
|
|
792
|
-
return take(new Color(this.red, this.green, this.blue, this.alpha));
|
|
793
|
-
}
|
|
794
|
-
toString() {
|
|
795
|
-
return this.toHex();
|
|
796
|
-
}
|
|
797
|
-
toHex() {
|
|
798
|
-
if (this.alpha === 255) {
|
|
799
|
-
return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
|
|
800
|
-
.toString(16)
|
|
801
|
-
.padStart(2, '0')}`;
|
|
802
|
-
}
|
|
803
|
-
else {
|
|
804
|
-
return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
|
|
805
|
-
.toString(16)
|
|
806
|
-
.padStart(2, '0')}${this.alpha.toString(16).padStart(2, '0')}`;
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
toRgb() {
|
|
810
|
-
if (this.alpha === 255) {
|
|
811
|
-
return `rgb(${this.red}, ${this.green}, ${this.blue})`;
|
|
812
|
-
}
|
|
813
|
-
else {
|
|
814
|
-
return `rgba(${this.red}, ${this.green}, ${this.blue}, ${Math.round((this.alpha / 255) * 100)}%)`;
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
toHsl() {
|
|
818
|
-
throw new Error(`Getting HSL is not implemented`);
|
|
860
|
+
static fromColorChannels({ red, green, blue, alpha }) {
|
|
861
|
+
return take(new Color(red, green, blue, alpha));
|
|
819
862
|
}
|
|
820
863
|
}
|
|
821
864
|
|
|
@@ -1977,7 +2020,7 @@ function createJokerCommands(task) {
|
|
|
1977
2020
|
*/
|
|
1978
2021
|
function createPostprocessingCommands(task) {
|
|
1979
2022
|
var _a;
|
|
1980
|
-
return ((_a = task.postprocessingFunctionNames) === null || _a === void 0 ? void 0 : _a.map((postprocessingFunctionName) => `POSTPROCESSING \`${postprocessingFunctionName}\``)) || [];
|
|
2023
|
+
return (((_a = task.postprocessingFunctionNames) === null || _a === void 0 ? void 0 : _a.map((postprocessingFunctionName) => `POSTPROCESSING \`${postprocessingFunctionName}\``)) || []);
|
|
1981
2024
|
}
|
|
1982
2025
|
/**
|
|
1983
2026
|
* Collects expectation commands.
|
|
@@ -2142,120 +2185,183 @@ function $deepFreeze(objectValue) {
|
|
|
2142
2185
|
* @public exported from `@promptbook/utils`
|
|
2143
2186
|
*/
|
|
2144
2187
|
function checkSerializableAsJson(options) {
|
|
2145
|
-
|
|
2188
|
+
checkSerializableValue(options);
|
|
2189
|
+
}
|
|
2190
|
+
// TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
2191
|
+
// TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
|
|
2192
|
+
// Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
2193
|
+
/**
|
|
2194
|
+
* Checks one value and dispatches to the appropriate specialized validator.
|
|
2195
|
+
*
|
|
2196
|
+
* @private function of `checkSerializableAsJson`
|
|
2197
|
+
*/
|
|
2198
|
+
function checkSerializableValue(options) {
|
|
2199
|
+
const { value } = options;
|
|
2200
|
+
if (isSerializablePrimitive(value)) {
|
|
2201
|
+
return;
|
|
2202
|
+
}
|
|
2146
2203
|
if (value === undefined) {
|
|
2147
|
-
throw new UnexpectedError(`${name} is undefined`);
|
|
2204
|
+
throw new UnexpectedError(`${options.name} is undefined`);
|
|
2148
2205
|
}
|
|
2149
|
-
|
|
2150
|
-
|
|
2206
|
+
if (typeof value === 'symbol') {
|
|
2207
|
+
throw new UnexpectedError(`${options.name} is symbol`);
|
|
2151
2208
|
}
|
|
2152
|
-
|
|
2153
|
-
|
|
2209
|
+
if (typeof value === 'function') {
|
|
2210
|
+
throw new UnexpectedError(`${options.name} is function`);
|
|
2154
2211
|
}
|
|
2155
|
-
|
|
2212
|
+
if (Array.isArray(value)) {
|
|
2213
|
+
checkSerializableArray(options, value);
|
|
2156
2214
|
return;
|
|
2157
2215
|
}
|
|
2158
|
-
|
|
2216
|
+
if (value !== null && typeof value === 'object') {
|
|
2217
|
+
checkSerializableObject(options, value);
|
|
2159
2218
|
return;
|
|
2160
2219
|
}
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2220
|
+
throwUnknownTypeError(options);
|
|
2221
|
+
}
|
|
2222
|
+
/**
|
|
2223
|
+
* Checks the primitive values that are directly JSON serializable.
|
|
2224
|
+
*
|
|
2225
|
+
* @private function of `checkSerializableAsJson`
|
|
2226
|
+
*/
|
|
2227
|
+
function isSerializablePrimitive(value) {
|
|
2228
|
+
return (value === null ||
|
|
2229
|
+
typeof value === 'boolean' ||
|
|
2230
|
+
(typeof value === 'number' && !isNaN(value)) ||
|
|
2231
|
+
typeof value === 'string');
|
|
2232
|
+
}
|
|
2233
|
+
/**
|
|
2234
|
+
* Recursively checks JSON array items.
|
|
2235
|
+
*
|
|
2236
|
+
* @private function of `checkSerializableAsJson`
|
|
2237
|
+
*/
|
|
2238
|
+
function checkSerializableArray(context, arrayValue) {
|
|
2239
|
+
for (let index = 0; index < arrayValue.length; index++) {
|
|
2240
|
+
checkSerializableAsJson({
|
|
2241
|
+
...context,
|
|
2242
|
+
name: `${context.name}[${index}]`,
|
|
2243
|
+
value: arrayValue[index],
|
|
2244
|
+
});
|
|
2171
2245
|
}
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2246
|
+
}
|
|
2247
|
+
/**
|
|
2248
|
+
* Checks object-like values and dispatches special unsupported built-ins.
|
|
2249
|
+
*
|
|
2250
|
+
* @private function of `checkSerializableAsJson`
|
|
2251
|
+
*/
|
|
2252
|
+
function checkSerializableObject(context, objectValue) {
|
|
2253
|
+
checkUnsupportedObjectType(context, objectValue);
|
|
2254
|
+
checkSerializableObjectEntries(context, objectValue);
|
|
2255
|
+
assertJsonStringificationSucceeds(context, objectValue);
|
|
2256
|
+
}
|
|
2257
|
+
/**
|
|
2258
|
+
* Rejects built-in objects that must be converted before JSON serialization.
|
|
2259
|
+
*
|
|
2260
|
+
* @private function of `checkSerializableAsJson`
|
|
2261
|
+
*/
|
|
2262
|
+
function checkUnsupportedObjectType(context, objectValue) {
|
|
2263
|
+
if (objectValue instanceof Date) {
|
|
2264
|
+
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
2265
|
+
\`${context.name}\` is Date
|
|
2176
2266
|
|
|
2177
|
-
|
|
2267
|
+
Use \`string_date_iso8601\` instead
|
|
2178
2268
|
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2269
|
+
Additional message for \`${context.name}\`:
|
|
2270
|
+
${block(context.message || '(nothing)')}
|
|
2271
|
+
`));
|
|
2272
|
+
}
|
|
2273
|
+
if (objectValue instanceof Map) {
|
|
2274
|
+
throw new UnexpectedError(`${context.name} is Map`);
|
|
2275
|
+
}
|
|
2276
|
+
if (objectValue instanceof Set) {
|
|
2277
|
+
throw new UnexpectedError(`${context.name} is Set`);
|
|
2278
|
+
}
|
|
2279
|
+
if (objectValue instanceof RegExp) {
|
|
2280
|
+
throw new UnexpectedError(`${context.name} is RegExp`);
|
|
2281
|
+
}
|
|
2282
|
+
if (objectValue instanceof Error) {
|
|
2283
|
+
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
2284
|
+
\`${context.name}\` is unserialized Error
|
|
2195
2285
|
|
|
2196
|
-
|
|
2286
|
+
Use function \`serializeError\`
|
|
2197
2287
|
|
|
2198
|
-
|
|
2199
|
-
|
|
2288
|
+
Additional message for \`${context.name}\`:
|
|
2289
|
+
${block(context.message || '(nothing)')}
|
|
2200
2290
|
|
|
2201
|
-
|
|
2291
|
+
`));
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
/**
|
|
2295
|
+
* Recursively checks object properties while preserving omitted `undefined` keys.
|
|
2296
|
+
*
|
|
2297
|
+
* @private function of `checkSerializableAsJson`
|
|
2298
|
+
*/
|
|
2299
|
+
function checkSerializableObjectEntries(context, objectValue) {
|
|
2300
|
+
for (const [subName, subValue] of Object.entries(objectValue)) {
|
|
2301
|
+
if (subValue === undefined) {
|
|
2302
|
+
// Note: undefined in object is serializable - it is just omitted
|
|
2303
|
+
continue;
|
|
2202
2304
|
}
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2305
|
+
checkSerializableAsJson({
|
|
2306
|
+
...context,
|
|
2307
|
+
name: `${context.name}.${subName}`,
|
|
2308
|
+
value: subValue,
|
|
2309
|
+
});
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
/**
|
|
2313
|
+
* Uses `JSON.stringify` as the final guard for cases like circular references.
|
|
2314
|
+
*
|
|
2315
|
+
* @private function of `checkSerializableAsJson`
|
|
2316
|
+
*/
|
|
2317
|
+
function assertJsonStringificationSucceeds(context, objectValue) {
|
|
2318
|
+
try {
|
|
2319
|
+
JSON.stringify(objectValue); // <- TODO: [0]
|
|
2320
|
+
}
|
|
2321
|
+
catch (error) {
|
|
2322
|
+
assertsError(error);
|
|
2323
|
+
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
2324
|
+
\`${context.name}\` is not serializable
|
|
2218
2325
|
|
|
2219
|
-
|
|
2326
|
+
${block(error.stack || error.message)}
|
|
2220
2327
|
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2328
|
+
Additional message for \`${context.name}\`:
|
|
2329
|
+
${block(context.message || '(nothing)')}
|
|
2330
|
+
`));
|
|
2331
|
+
}
|
|
2332
|
+
/*
|
|
2333
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
2334
|
+
const seen = new Set();
|
|
2335
|
+
const stack = [{ value }];
|
|
2336
|
+
while (stack.length > 0) {
|
|
2337
|
+
const { value } = stack.pop()!;
|
|
2338
|
+
if (typeof value === 'object' && value !== null) {
|
|
2339
|
+
if (seen.has(value)) {
|
|
2340
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
2224
2341
|
}
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
const { value } = stack.pop()!;
|
|
2231
|
-
if (typeof value === 'object' && value !== null) {
|
|
2232
|
-
if (seen.has(value)) {
|
|
2233
|
-
throw new UnexpectedError(`${name} has circular reference`);
|
|
2234
|
-
}
|
|
2235
|
-
seen.add(value);
|
|
2236
|
-
if (Array.isArray(value)) {
|
|
2237
|
-
stack.push(...value.map((value) => ({ value })));
|
|
2238
|
-
} else {
|
|
2239
|
-
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
2240
|
-
}
|
|
2241
|
-
}
|
|
2342
|
+
seen.add(value);
|
|
2343
|
+
if (Array.isArray(value)) {
|
|
2344
|
+
stack.push(...value.map((value) => ({ value })));
|
|
2345
|
+
} else {
|
|
2346
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
2242
2347
|
}
|
|
2243
|
-
*/
|
|
2244
|
-
return;
|
|
2245
2348
|
}
|
|
2246
2349
|
}
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2350
|
+
*/
|
|
2351
|
+
}
|
|
2352
|
+
/**
|
|
2353
|
+
* Throws the fallback error for unsupported value types like `bigint` and `NaN`.
|
|
2354
|
+
*
|
|
2355
|
+
* @private function of `checkSerializableAsJson`
|
|
2356
|
+
*/
|
|
2357
|
+
function throwUnknownTypeError(context) {
|
|
2358
|
+
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
2359
|
+
\`${context.name}\` is unknown type
|
|
2250
2360
|
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
}
|
|
2361
|
+
Additional message for \`${context.name}\`:
|
|
2362
|
+
${block(context.message || '(nothing)')}
|
|
2363
|
+
`));
|
|
2255
2364
|
}
|
|
2256
|
-
// TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
|
|
2257
|
-
// TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
|
|
2258
|
-
// Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
2259
2365
|
|
|
2260
2366
|
/**
|
|
2261
2367
|
* Creates a deep clone of the given object
|
|
@@ -2819,8 +2925,7 @@ function hasTaskJokers(task) {
|
|
|
2819
2925
|
* @private internal utility of `validatePipeline`
|
|
2820
2926
|
*/
|
|
2821
2927
|
function validateTaskSupportsJokers(task, pipelineIdentification) {
|
|
2822
|
-
if (task.format ||
|
|
2823
|
-
task.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
2928
|
+
if (task.format || task.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
|
|
2824
2929
|
return;
|
|
2825
2930
|
}
|
|
2826
2931
|
throw new PipelineLogicError(spaceTrim$1((block) => `
|
|
@@ -7233,9 +7338,7 @@ function createFailuresSummary($failedResults) {
|
|
|
7233
7338
|
${block(quoteMultilineText(((_b = failure.error) === null || _b === void 0 ? void 0 : _b.message) || ''))}
|
|
7234
7339
|
|
|
7235
7340
|
Result:
|
|
7236
|
-
${block(failure.result === null
|
|
7237
|
-
? 'null'
|
|
7238
|
-
: quoteMultilineText(spaceTrim$1(failure.result)))}
|
|
7341
|
+
${block(failure.result === null ? 'null' : quoteMultilineText(spaceTrim$1(failure.result)))}
|
|
7239
7342
|
`;
|
|
7240
7343
|
}))
|
|
7241
7344
|
.join('\n\n---\n\n');
|