@promptbook/website-crawler 0.112.0-73 → 0.112.0-79

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 (74) hide show
  1. package/README.md +9 -9
  2. package/esm/index.es.js +313 -210
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
  5. package/esm/src/avatars/visuals/octopus3d2AvatarVisual.d.ts +7 -0
  6. package/esm/src/avatars/visuals/octopus3dAvatarVisualShared.d.ts +37 -0
  7. package/esm/src/book-components/Chat/save/_common/chatExportRendering.d.ts +47 -0
  8. package/esm/src/book-components/Chat/save/html/htmlSaveFormatDefinition.d.ts +12 -0
  9. package/esm/src/book-components/Chat/save/index.d.ts +2 -2
  10. package/esm/src/book-components/Chat/save/markdown/mdSaveFormatDefinition.d.ts +5 -3
  11. package/esm/src/book-components/Chat/save/pdf/buildChatPdf.d.ts +3 -3
  12. package/esm/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.d.ts +1 -1
  13. package/esm/src/cli/cli-commands/agent/agentProjectPaths.d.ts +8 -8
  14. package/esm/src/cli/cli-commands/agent/initializeAgentRunnerCommand.d.ts +1 -1
  15. package/esm/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +56 -0
  16. package/esm/src/cli/cli-commands/agents-server/buildAgentsServer.test.d.ts +1 -0
  17. package/esm/src/cli/cli-commands/agents-server/ensureAgentsServerEnvFile.d.ts +7 -0
  18. package/esm/src/cli/cli-commands/agents-server/ensureAgentsServerGitignoreFile.d.ts +7 -0
  19. package/esm/src/cli/cli-commands/agents-server/init.d.ts +9 -0
  20. package/esm/src/cli/cli-commands/agents-server/init.test.d.ts +1 -0
  21. package/esm/src/cli/cli-commands/agents-server/initializeAgentsServerProjectConfiguration.d.ts +17 -0
  22. package/esm/src/cli/cli-commands/agents-server/printAgentsServerInitializationSummary.d.ts +7 -0
  23. package/esm/src/cli/cli-commands/agents-server/run.d.ts +14 -0
  24. package/esm/src/cli/cli-commands/agents-server/run.test.d.ts +1 -0
  25. package/esm/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +23 -0
  26. package/esm/src/cli/cli-commands/agents-server.d.ts +8 -0
  27. package/esm/src/cli/cli-commands/common/projectInitialization.d.ts +65 -0
  28. package/esm/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +44 -0
  29. package/esm/src/cli/common/$deprecateCliCommand.d.ts +8 -0
  30. package/esm/src/cli/common/$deprecateCliCommand.test.d.ts +1 -0
  31. package/esm/src/utils/color/Color.d.ts +4 -44
  32. package/esm/src/utils/color/ColorValue.d.ts +55 -0
  33. package/esm/src/utils/color/isHexColorString.d.ts +10 -0
  34. package/esm/src/utils/color/parseColorString.d.ts +11 -0
  35. package/esm/src/version.d.ts +1 -1
  36. package/package.json +2 -2
  37. package/umd/index.umd.js +313 -210
  38. package/umd/index.umd.js.map +1 -1
  39. package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
  40. package/umd/src/avatars/visuals/octopus3d2AvatarVisual.d.ts +7 -0
  41. package/umd/src/avatars/visuals/octopus3dAvatarVisualShared.d.ts +37 -0
  42. package/umd/src/book-components/Chat/save/_common/chatExportRendering.d.ts +47 -0
  43. package/umd/src/book-components/Chat/save/html/htmlSaveFormatDefinition.d.ts +12 -0
  44. package/umd/src/book-components/Chat/save/index.d.ts +2 -2
  45. package/umd/src/book-components/Chat/save/markdown/mdSaveFormatDefinition.d.ts +5 -3
  46. package/umd/src/book-components/Chat/save/pdf/buildChatPdf.d.ts +3 -3
  47. package/umd/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.d.ts +1 -1
  48. package/umd/src/cli/cli-commands/agent/agentProjectPaths.d.ts +8 -8
  49. package/umd/src/cli/cli-commands/agent/initializeAgentRunnerCommand.d.ts +1 -1
  50. package/umd/src/cli/cli-commands/agents-server/buildAgentsServer.d.ts +56 -0
  51. package/umd/src/cli/cli-commands/agents-server/buildAgentsServer.test.d.ts +1 -0
  52. package/umd/src/cli/cli-commands/agents-server/ensureAgentsServerEnvFile.d.ts +7 -0
  53. package/umd/src/cli/cli-commands/agents-server/ensureAgentsServerGitignoreFile.d.ts +7 -0
  54. package/umd/src/cli/cli-commands/agents-server/init.d.ts +9 -0
  55. package/umd/src/cli/cli-commands/agents-server/init.test.d.ts +1 -0
  56. package/umd/src/cli/cli-commands/agents-server/initializeAgentsServerProjectConfiguration.d.ts +17 -0
  57. package/umd/src/cli/cli-commands/agents-server/printAgentsServerInitializationSummary.d.ts +7 -0
  58. package/umd/src/cli/cli-commands/agents-server/run.d.ts +14 -0
  59. package/umd/src/cli/cli-commands/agents-server/run.test.d.ts +1 -0
  60. package/umd/src/cli/cli-commands/agents-server/startAgentsServer.d.ts +23 -0
  61. package/umd/src/cli/cli-commands/agents-server.d.ts +8 -0
  62. package/umd/src/cli/cli-commands/common/projectInitialization.d.ts +65 -0
  63. package/umd/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +44 -0
  64. package/umd/src/cli/common/$deprecateCliCommand.d.ts +8 -0
  65. package/umd/src/cli/common/$deprecateCliCommand.test.d.ts +1 -0
  66. package/umd/src/utils/color/Color.d.ts +4 -44
  67. package/umd/src/utils/color/ColorValue.d.ts +55 -0
  68. package/umd/src/utils/color/isHexColorString.d.ts +10 -0
  69. package/umd/src/utils/color/parseColorString.d.ts +11 -0
  70. package/umd/src/version.d.ts +1 -1
  71. package/esm/src/cli/cli-commands/coder/appendBlock.d.ts +0 -6
  72. package/esm/src/cli/cli-commands/coder/readTextFileIfExists.d.ts +0 -6
  73. package/umd/src/cli/cli-commands/coder/appendBlock.d.ts +0 -6
  74. package/umd/src/cli/cli-commands/coder/readTextFileIfExists.d.ts +0 -6
package/esm/index.es.js CHANGED
@@ -27,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
27
27
  * @generated
28
28
  * @see https://github.com/webgptorg/promptbook
29
29
  */
30
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-73';
30
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-79';
31
31
  /**
32
32
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
33
33
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -321,6 +321,111 @@ function checkChannelValue(channelName, value) {
321
321
  }
322
322
  }
323
323
 
324
+ /**
325
+ * Shared immutable channel storage and serialization helpers for `Color`.
326
+ *
327
+ * @private base class of Color
328
+ */
329
+ class ColorValue {
330
+ constructor(red, green, blue, alpha = 255) {
331
+ this.red = red;
332
+ this.green = green;
333
+ this.blue = blue;
334
+ this.alpha = alpha;
335
+ checkChannelValue('Red', red);
336
+ checkChannelValue('Green', green);
337
+ checkChannelValue('Blue', blue);
338
+ checkChannelValue('Alpha', alpha);
339
+ }
340
+ /**
341
+ * Shortcut for `red` property
342
+ * Number from 0 to 255
343
+ * @alias red
344
+ */
345
+ get r() {
346
+ return this.red;
347
+ }
348
+ /**
349
+ * Shortcut for `green` property
350
+ * Number from 0 to 255
351
+ * @alias green
352
+ */
353
+ get g() {
354
+ return this.green;
355
+ }
356
+ /**
357
+ * Shortcut for `blue` property
358
+ * Number from 0 to 255
359
+ * @alias blue
360
+ */
361
+ get b() {
362
+ return this.blue;
363
+ }
364
+ /**
365
+ * Shortcut for `alpha` property
366
+ * Number from 0 (transparent) to 255 (opaque)
367
+ * @alias alpha
368
+ */
369
+ get a() {
370
+ return this.alpha;
371
+ }
372
+ /**
373
+ * Shortcut for `alpha` property
374
+ * Number from 0 (transparent) to 255 (opaque)
375
+ * @alias alpha
376
+ */
377
+ get opacity() {
378
+ return this.alpha;
379
+ }
380
+ /**
381
+ * Shortcut for 1-`alpha` property
382
+ */
383
+ get transparency() {
384
+ return 255 - this.alpha;
385
+ }
386
+ clone() {
387
+ return take(this.createColor(this.red, this.green, this.blue, this.alpha));
388
+ }
389
+ toString() {
390
+ return this.toHex();
391
+ }
392
+ toHex() {
393
+ if (this.alpha === 255) {
394
+ return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
395
+ .toString(16)
396
+ .padStart(2, '0')}`;
397
+ }
398
+ else {
399
+ return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
400
+ .toString(16)
401
+ .padStart(2, '0')}${this.alpha.toString(16).padStart(2, '0')}`;
402
+ }
403
+ }
404
+ toRgb() {
405
+ if (this.alpha === 255) {
406
+ return `rgb(${this.red}, ${this.green}, ${this.blue})`;
407
+ }
408
+ else {
409
+ return `rgba(${this.red}, ${this.green}, ${this.blue}, ${Math.round((this.alpha / 255) * 100)}%)`;
410
+ }
411
+ }
412
+ toHsl() {
413
+ throw new Error(`Getting HSL is not implemented`);
414
+ }
415
+ }
416
+
417
+ /**
418
+ * Checks if the given value is a valid hex color string
419
+ *
420
+ * @param value - value to check
421
+ * @returns true if the value is a valid hex color string (e.g., `#009edd`, `#fff`, etc.)
422
+ *
423
+ * @private function of Color
424
+ */
425
+ function isHexColorString(value) {
426
+ 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));
427
+ }
428
+
324
429
  /**
325
430
  * Constant for short hex lengths.
326
431
  */
@@ -532,16 +637,53 @@ function parseAlphaValue(value) {
532
637
 
533
638
  /**
534
639
  * Pattern matching hsl regex.
640
+ *
641
+ * @private function of Color
535
642
  */
536
643
  const HSL_REGEX_PATTERN = /^hsl\(\s*([0-9.]+)\s*,\s*([0-9.]+)%\s*,\s*([0-9.]+)%\s*\)$/;
537
644
  /**
538
645
  * Pattern matching RGB regex.
646
+ *
647
+ * @private function of Color
539
648
  */
540
649
  const RGB_REGEX_PATTERN = /^rgb\(\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*\)$/;
541
650
  /**
542
651
  * Pattern matching rgba regex.
652
+ *
653
+ * @private function of Color
543
654
  */
544
655
  const RGBA_REGEX_PATTERN = /^rgba\(\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*\)$/;
656
+ /**
657
+ * Parses a supported color string into RGBA channels.
658
+ *
659
+ * @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`,...
660
+ * @returns RGBA channel values.
661
+ *
662
+ * @private function of Color
663
+ */
664
+ function parseColorString(color) {
665
+ const trimmed = color.trim();
666
+ const cssColor = CSS_COLORS[trimmed];
667
+ if (cssColor) {
668
+ return parseColorString(cssColor);
669
+ }
670
+ else if (isHexColorString(trimmed)) {
671
+ return parseHexColor(trimmed);
672
+ }
673
+ if (HSL_REGEX_PATTERN.test(trimmed)) {
674
+ return parseHslColor(trimmed);
675
+ }
676
+ else if (RGB_REGEX_PATTERN.test(trimmed)) {
677
+ return parseRgbColor(trimmed);
678
+ }
679
+ else if (RGBA_REGEX_PATTERN.test(trimmed)) {
680
+ return parseRgbaColor(trimmed);
681
+ }
682
+ else {
683
+ throw new Error(`Can not create a new Color instance from string "${trimmed}".`);
684
+ }
685
+ }
686
+
545
687
  /**
546
688
  * Color object represents an RGB color with alpha channel
547
689
  *
@@ -549,7 +691,7 @@ const RGBA_REGEX_PATTERN = /^rgba\(\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.
549
691
  *
550
692
  * @public exported from `@promptbook/color`
551
693
  */
552
- class Color {
694
+ class Color extends ColorValue {
553
695
  /**
554
696
  * Creates a new Color instance from miscellaneous formats
555
697
  * - It can receive Color instance and just return the same instance
@@ -622,25 +764,7 @@ class Color {
622
764
  * @returns Color object
623
765
  */
624
766
  static fromString(color) {
625
- const trimmed = color.trim();
626
- if (CSS_COLORS[trimmed]) {
627
- return Color.fromString(CSS_COLORS[trimmed]);
628
- }
629
- else if (Color.isHexColorString(trimmed)) {
630
- return Color.fromHex(trimmed);
631
- }
632
- if (HSL_REGEX_PATTERN.test(trimmed)) {
633
- return Color.fromHsl(trimmed);
634
- }
635
- else if (RGB_REGEX_PATTERN.test(trimmed)) {
636
- return Color.fromRgbString(trimmed);
637
- }
638
- else if (RGBA_REGEX_PATTERN.test(trimmed)) {
639
- return Color.fromRgbaString(trimmed);
640
- }
641
- else {
642
- throw new Error(`Can not create a new Color instance from string "${trimmed}".`);
643
- }
767
+ return Color.fromColorChannels(parseColorString(color));
644
768
  }
645
769
  /**
646
770
  * Gets common color
@@ -670,8 +794,7 @@ class Color {
670
794
  * @returns Color object
671
795
  */
672
796
  static fromHex(hex) {
673
- const { red, green, blue, alpha } = parseHexColor(hex);
674
- return take(new Color(red, green, blue, alpha));
797
+ return Color.fromColorChannels(parseHexColor(hex));
675
798
  }
676
799
  /**
677
800
  * Creates a new Color instance from color in hsl format
@@ -680,8 +803,7 @@ class Color {
680
803
  * @returns Color object
681
804
  */
682
805
  static fromHsl(hsl) {
683
- const { red, green, blue, alpha } = parseHslColor(hsl);
684
- return take(new Color(red, green, blue, alpha));
806
+ return Color.fromColorChannels(parseHslColor(hsl));
685
807
  }
686
808
  /**
687
809
  * Creates a new Color instance from color in rgb format
@@ -690,8 +812,7 @@ class Color {
690
812
  * @returns Color object
691
813
  */
692
814
  static fromRgbString(rgb) {
693
- const { red, green, blue, alpha } = parseRgbColor(rgb);
694
- return take(new Color(red, green, blue, alpha));
815
+ return Color.fromColorChannels(parseRgbColor(rgb));
695
816
  }
696
817
  /**
697
818
  * Creates a new Color instance from color in rbga format
@@ -700,8 +821,7 @@ class Color {
700
821
  * @returns Color object
701
822
  */
702
823
  static fromRgbaString(rgba) {
703
- const { red, green, blue, alpha } = parseRgbaColor(rgba);
704
- return take(new Color(red, green, blue, alpha));
824
+ return Color.fromColorChannels(parseRgbaColor(rgba));
705
825
  }
706
826
  /**
707
827
  * Creates a new Color for color channels values
@@ -713,7 +833,7 @@ class Color {
713
833
  * @returns Color object
714
834
  */
715
835
  static fromValues(red, green, blue, alpha = 255) {
716
- return take(new Color(red, green, blue, alpha));
836
+ return Color.fromColorChannels({ red, green, blue, alpha });
717
837
  }
718
838
  /**
719
839
  * Checks if the given value is a valid Color object.
@@ -746,8 +866,7 @@ class Color {
746
866
  * @returns true if the value is a valid hex color string (e.g., `#009edd`, `#fff`, etc.)
747
867
  */
748
868
  static isHexColorString(value) {
749
- return (typeof value === 'string' &&
750
- /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(value));
869
+ return isHexColorString(value);
751
870
  }
752
871
  /**
753
872
  * Creates new Color object
@@ -760,89 +879,13 @@ class Color {
760
879
  * @param alpha number from 0 (transparent) to 255 (opaque)
761
880
  */
762
881
  constructor(red, green, blue, alpha = 255) {
763
- this.red = red;
764
- this.green = green;
765
- this.blue = blue;
766
- this.alpha = alpha;
767
- checkChannelValue('Red', red);
768
- checkChannelValue('Green', green);
769
- checkChannelValue('Blue', blue);
770
- checkChannelValue('Alpha', alpha);
882
+ super(red, green, blue, alpha);
771
883
  }
772
- /**
773
- * Shortcut for `red` property
774
- * Number from 0 to 255
775
- * @alias red
776
- */
777
- get r() {
778
- return this.red;
884
+ createColor(red, green, blue, alpha) {
885
+ return new Color(red, green, blue, alpha);
779
886
  }
780
- /**
781
- * Shortcut for `green` property
782
- * Number from 0 to 255
783
- * @alias green
784
- */
785
- get g() {
786
- return this.green;
787
- }
788
- /**
789
- * Shortcut for `blue` property
790
- * Number from 0 to 255
791
- * @alias blue
792
- */
793
- get b() {
794
- return this.blue;
795
- }
796
- /**
797
- * Shortcut for `alpha` property
798
- * Number from 0 (transparent) to 255 (opaque)
799
- * @alias alpha
800
- */
801
- get a() {
802
- return this.alpha;
803
- }
804
- /**
805
- * Shortcut for `alpha` property
806
- * Number from 0 (transparent) to 255 (opaque)
807
- * @alias alpha
808
- */
809
- get opacity() {
810
- return this.alpha;
811
- }
812
- /**
813
- * Shortcut for 1-`alpha` property
814
- */
815
- get transparency() {
816
- return 255 - this.alpha;
817
- }
818
- clone() {
819
- return take(new Color(this.red, this.green, this.blue, this.alpha));
820
- }
821
- toString() {
822
- return this.toHex();
823
- }
824
- toHex() {
825
- if (this.alpha === 255) {
826
- return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
827
- .toString(16)
828
- .padStart(2, '0')}`;
829
- }
830
- else {
831
- return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
832
- .toString(16)
833
- .padStart(2, '0')}${this.alpha.toString(16).padStart(2, '0')}`;
834
- }
835
- }
836
- toRgb() {
837
- if (this.alpha === 255) {
838
- return `rgb(${this.red}, ${this.green}, ${this.blue})`;
839
- }
840
- else {
841
- return `rgba(${this.red}, ${this.green}, ${this.blue}, ${Math.round((this.alpha / 255) * 100)}%)`;
842
- }
843
- }
844
- toHsl() {
845
- throw new Error(`Getting HSL is not implemented`);
887
+ static fromColorChannels({ red, green, blue, alpha }) {
888
+ return take(new Color(red, green, blue, alpha));
846
889
  }
847
890
  }
848
891
 
@@ -1966,7 +2009,7 @@ function createJokerCommands(task) {
1966
2009
  */
1967
2010
  function createPostprocessingCommands(task) {
1968
2011
  var _a;
1969
- return ((_a = task.postprocessingFunctionNames) === null || _a === void 0 ? void 0 : _a.map((postprocessingFunctionName) => `POSTPROCESSING \`${postprocessingFunctionName}\``)) || [];
2012
+ return (((_a = task.postprocessingFunctionNames) === null || _a === void 0 ? void 0 : _a.map((postprocessingFunctionName) => `POSTPROCESSING \`${postprocessingFunctionName}\``)) || []);
1970
2013
  }
1971
2014
  /**
1972
2015
  * Collects expectation commands.
@@ -2105,120 +2148,183 @@ function orderJson(options) {
2105
2148
  * @public exported from `@promptbook/utils`
2106
2149
  */
2107
2150
  function checkSerializableAsJson(options) {
2108
- const { value, name, message } = options;
2151
+ checkSerializableValue(options);
2152
+ }
2153
+ // TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
2154
+ // TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
2155
+ // Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
2156
+ /**
2157
+ * Checks one value and dispatches to the appropriate specialized validator.
2158
+ *
2159
+ * @private function of `checkSerializableAsJson`
2160
+ */
2161
+ function checkSerializableValue(options) {
2162
+ const { value } = options;
2163
+ if (isSerializablePrimitive(value)) {
2164
+ return;
2165
+ }
2109
2166
  if (value === undefined) {
2110
- throw new UnexpectedError(`${name} is undefined`);
2167
+ throw new UnexpectedError(`${options.name} is undefined`);
2111
2168
  }
2112
- else if (value === null) {
2113
- return;
2169
+ if (typeof value === 'symbol') {
2170
+ throw new UnexpectedError(`${options.name} is symbol`);
2114
2171
  }
2115
- else if (typeof value === 'boolean') {
2116
- return;
2172
+ if (typeof value === 'function') {
2173
+ throw new UnexpectedError(`${options.name} is function`);
2117
2174
  }
2118
- else if (typeof value === 'number' && !isNaN(value)) {
2175
+ if (Array.isArray(value)) {
2176
+ checkSerializableArray(options, value);
2119
2177
  return;
2120
2178
  }
2121
- else if (typeof value === 'string') {
2179
+ if (value !== null && typeof value === 'object') {
2180
+ checkSerializableObject(options, value);
2122
2181
  return;
2123
2182
  }
2124
- else if (typeof value === 'symbol') {
2125
- throw new UnexpectedError(`${name} is symbol`);
2126
- }
2127
- else if (typeof value === 'function') {
2128
- throw new UnexpectedError(`${name} is function`);
2129
- }
2130
- else if (typeof value === 'object' && Array.isArray(value)) {
2131
- for (let i = 0; i < value.length; i++) {
2132
- checkSerializableAsJson({ name: `${name}[${i}]`, value: value[i], message });
2133
- }
2183
+ throwUnknownTypeError(options);
2184
+ }
2185
+ /**
2186
+ * Checks the primitive values that are directly JSON serializable.
2187
+ *
2188
+ * @private function of `checkSerializableAsJson`
2189
+ */
2190
+ function isSerializablePrimitive(value) {
2191
+ return (value === null ||
2192
+ typeof value === 'boolean' ||
2193
+ (typeof value === 'number' && !isNaN(value)) ||
2194
+ typeof value === 'string');
2195
+ }
2196
+ /**
2197
+ * Recursively checks JSON array items.
2198
+ *
2199
+ * @private function of `checkSerializableAsJson`
2200
+ */
2201
+ function checkSerializableArray(context, arrayValue) {
2202
+ for (let index = 0; index < arrayValue.length; index++) {
2203
+ checkSerializableAsJson({
2204
+ ...context,
2205
+ name: `${context.name}[${index}]`,
2206
+ value: arrayValue[index],
2207
+ });
2134
2208
  }
2135
- else if (typeof value === 'object') {
2136
- if (value instanceof Date) {
2137
- throw new UnexpectedError(spaceTrim$1((block) => `
2138
- \`${name}\` is Date
2209
+ }
2210
+ /**
2211
+ * Checks object-like values and dispatches special unsupported built-ins.
2212
+ *
2213
+ * @private function of `checkSerializableAsJson`
2214
+ */
2215
+ function checkSerializableObject(context, objectValue) {
2216
+ checkUnsupportedObjectType(context, objectValue);
2217
+ checkSerializableObjectEntries(context, objectValue);
2218
+ assertJsonStringificationSucceeds(context, objectValue);
2219
+ }
2220
+ /**
2221
+ * Rejects built-in objects that must be converted before JSON serialization.
2222
+ *
2223
+ * @private function of `checkSerializableAsJson`
2224
+ */
2225
+ function checkUnsupportedObjectType(context, objectValue) {
2226
+ if (objectValue instanceof Date) {
2227
+ throw new UnexpectedError(spaceTrim$1((block) => `
2228
+ \`${context.name}\` is Date
2139
2229
 
2140
- Use \`string_date_iso8601\` instead
2230
+ Use \`string_date_iso8601\` instead
2141
2231
 
2142
- Additional message for \`${name}\`:
2143
- ${block(message || '(nothing)')}
2144
- `));
2145
- }
2146
- else if (value instanceof Map) {
2147
- throw new UnexpectedError(`${name} is Map`);
2148
- }
2149
- else if (value instanceof Set) {
2150
- throw new UnexpectedError(`${name} is Set`);
2151
- }
2152
- else if (value instanceof RegExp) {
2153
- throw new UnexpectedError(`${name} is RegExp`);
2154
- }
2155
- else if (value instanceof Error) {
2156
- throw new UnexpectedError(spaceTrim$1((block) => `
2157
- \`${name}\` is unserialized Error
2232
+ Additional message for \`${context.name}\`:
2233
+ ${block(context.message || '(nothing)')}
2234
+ `));
2235
+ }
2236
+ if (objectValue instanceof Map) {
2237
+ throw new UnexpectedError(`${context.name} is Map`);
2238
+ }
2239
+ if (objectValue instanceof Set) {
2240
+ throw new UnexpectedError(`${context.name} is Set`);
2241
+ }
2242
+ if (objectValue instanceof RegExp) {
2243
+ throw new UnexpectedError(`${context.name} is RegExp`);
2244
+ }
2245
+ if (objectValue instanceof Error) {
2246
+ throw new UnexpectedError(spaceTrim$1((block) => `
2247
+ \`${context.name}\` is unserialized Error
2158
2248
 
2159
- Use function \`serializeError\`
2249
+ Use function \`serializeError\`
2160
2250
 
2161
- Additional message for \`${name}\`:
2162
- ${block(message || '(nothing)')}
2251
+ Additional message for \`${context.name}\`:
2252
+ ${block(context.message || '(nothing)')}
2163
2253
 
2164
- `));
2254
+ `));
2255
+ }
2256
+ }
2257
+ /**
2258
+ * Recursively checks object properties while preserving omitted `undefined` keys.
2259
+ *
2260
+ * @private function of `checkSerializableAsJson`
2261
+ */
2262
+ function checkSerializableObjectEntries(context, objectValue) {
2263
+ for (const [subName, subValue] of Object.entries(objectValue)) {
2264
+ if (subValue === undefined) {
2265
+ // Note: undefined in object is serializable - it is just omitted
2266
+ continue;
2165
2267
  }
2166
- else {
2167
- for (const [subName, subValue] of Object.entries(value)) {
2168
- if (subValue === undefined) {
2169
- // Note: undefined in object is serializable - it is just omitted
2170
- continue;
2171
- }
2172
- checkSerializableAsJson({ name: `${name}.${subName}`, value: subValue, message });
2173
- }
2174
- try {
2175
- JSON.stringify(value); // <- TODO: [0]
2176
- }
2177
- catch (error) {
2178
- assertsError(error);
2179
- throw new UnexpectedError(spaceTrim$1((block) => `
2180
- \`${name}\` is not serializable
2268
+ checkSerializableAsJson({
2269
+ ...context,
2270
+ name: `${context.name}.${subName}`,
2271
+ value: subValue,
2272
+ });
2273
+ }
2274
+ }
2275
+ /**
2276
+ * Uses `JSON.stringify` as the final guard for cases like circular references.
2277
+ *
2278
+ * @private function of `checkSerializableAsJson`
2279
+ */
2280
+ function assertJsonStringificationSucceeds(context, objectValue) {
2281
+ try {
2282
+ JSON.stringify(objectValue); // <- TODO: [0]
2283
+ }
2284
+ catch (error) {
2285
+ assertsError(error);
2286
+ throw new UnexpectedError(spaceTrim$1((block) => `
2287
+ \`${context.name}\` is not serializable
2181
2288
 
2182
- ${block(error.stack || error.message)}
2289
+ ${block(error.stack || error.message)}
2183
2290
 
2184
- Additional message for \`${name}\`:
2185
- ${block(message || '(nothing)')}
2186
- `));
2291
+ Additional message for \`${context.name}\`:
2292
+ ${block(context.message || '(nothing)')}
2293
+ `));
2294
+ }
2295
+ /*
2296
+ TODO: [0] Is there some more elegant way to check circular references?
2297
+ const seen = new Set();
2298
+ const stack = [{ value }];
2299
+ while (stack.length > 0) {
2300
+ const { value } = stack.pop()!;
2301
+ if (typeof value === 'object' && value !== null) {
2302
+ if (seen.has(value)) {
2303
+ throw new UnexpectedError(`${name} has circular reference`);
2187
2304
  }
2188
- /*
2189
- TODO: [0] Is there some more elegant way to check circular references?
2190
- const seen = new Set();
2191
- const stack = [{ value }];
2192
- while (stack.length > 0) {
2193
- const { value } = stack.pop()!;
2194
- if (typeof value === 'object' && value !== null) {
2195
- if (seen.has(value)) {
2196
- throw new UnexpectedError(`${name} has circular reference`);
2197
- }
2198
- seen.add(value);
2199
- if (Array.isArray(value)) {
2200
- stack.push(...value.map((value) => ({ value })));
2201
- } else {
2202
- stack.push(...Object.values(value).map((value) => ({ value })));
2203
- }
2204
- }
2305
+ seen.add(value);
2306
+ if (Array.isArray(value)) {
2307
+ stack.push(...value.map((value) => ({ value })));
2308
+ } else {
2309
+ stack.push(...Object.values(value).map((value) => ({ value })));
2205
2310
  }
2206
- */
2207
- return;
2208
2311
  }
2209
2312
  }
2210
- else {
2211
- throw new UnexpectedError(spaceTrim$1((block) => `
2212
- \`${name}\` is unknown type
2313
+ */
2314
+ }
2315
+ /**
2316
+ * Throws the fallback error for unsupported value types like `bigint` and `NaN`.
2317
+ *
2318
+ * @private function of `checkSerializableAsJson`
2319
+ */
2320
+ function throwUnknownTypeError(context) {
2321
+ throw new UnexpectedError(spaceTrim$1((block) => `
2322
+ \`${context.name}\` is unknown type
2213
2323
 
2214
- Additional message for \`${name}\`:
2215
- ${block(message || '(nothing)')}
2216
- `));
2217
- }
2324
+ Additional message for \`${context.name}\`:
2325
+ ${block(context.message || '(nothing)')}
2326
+ `));
2218
2327
  }
2219
- // TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
2220
- // TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
2221
- // Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
2222
2328
 
2223
2329
  /**
2224
2330
  * Creates a deep clone of the given object
@@ -2782,8 +2888,7 @@ function hasTaskJokers(task) {
2782
2888
  * @private internal utility of `validatePipeline`
2783
2889
  */
2784
2890
  function validateTaskSupportsJokers(task, pipelineIdentification) {
2785
- if (task.format ||
2786
- task.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
2891
+ if (task.format || task.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
2787
2892
  return;
2788
2893
  }
2789
2894
  throw new PipelineLogicError(spaceTrim$1((block) => `
@@ -7078,9 +7183,7 @@ function createFailuresSummary($failedResults) {
7078
7183
  ${block(quoteMultilineText(((_b = failure.error) === null || _b === void 0 ? void 0 : _b.message) || ''))}
7079
7184
 
7080
7185
  Result:
7081
- ${block(failure.result === null
7082
- ? 'null'
7083
- : quoteMultilineText(spaceTrim$1(failure.result)))}
7186
+ ${block(failure.result === null ? 'null' : quoteMultilineText(spaceTrim$1(failure.result)))}
7084
7187
  `;
7085
7188
  }))
7086
7189
  .join('\n\n---\n\n');