@syntrologie/runtime-sdk 0.2.20 → 1.0.1-canary.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 (110) hide show
  1. package/CAPABILITIES.md +211 -0
  2. package/dist/SmartCanvasElement.js +11 -1
  3. package/dist/SmartCanvasElement.js.map +1 -1
  4. package/dist/api.js +26 -12
  5. package/dist/api.js.map +1 -1
  6. package/dist/bootstrap.d.ts +16 -2
  7. package/dist/bootstrap.js +84 -30
  8. package/dist/bootstrap.js.map +1 -1
  9. package/dist/configFetcher.js +2 -1
  10. package/dist/configFetcher.js.map +1 -1
  11. package/dist/context/ContextManager.d.ts +66 -0
  12. package/dist/context/ContextManager.js +268 -0
  13. package/dist/context/ContextManager.js.map +1 -0
  14. package/dist/context/index.d.ts +7 -0
  15. package/dist/context/index.js +7 -0
  16. package/dist/context/index.js.map +1 -0
  17. package/dist/context/schema.d.ts +360 -0
  18. package/dist/context/schema.js +50 -0
  19. package/dist/context/schema.js.map +1 -0
  20. package/dist/context/types.d.ts +101 -0
  21. package/dist/context/types.js +8 -0
  22. package/dist/context/types.js.map +1 -0
  23. package/dist/decisions/engine.d.ts +43 -0
  24. package/dist/decisions/engine.js +112 -0
  25. package/dist/decisions/engine.js.map +1 -0
  26. package/dist/decisions/index.d.ts +9 -0
  27. package/dist/decisions/index.js +10 -0
  28. package/dist/decisions/index.js.map +1 -0
  29. package/dist/decisions/schema.d.ts +2166 -0
  30. package/dist/decisions/schema.js +143 -0
  31. package/dist/decisions/schema.js.map +1 -0
  32. package/dist/decisions/strategies/rules.d.ts +24 -0
  33. package/dist/decisions/strategies/rules.js +152 -0
  34. package/dist/decisions/strategies/rules.js.map +1 -0
  35. package/dist/decisions/strategies/score.d.ts +10 -0
  36. package/dist/decisions/strategies/score.js +29 -0
  37. package/dist/decisions/strategies/score.js.map +1 -0
  38. package/dist/decisions/types.d.ts +242 -0
  39. package/dist/decisions/types.js +2 -0
  40. package/dist/decisions/types.js.map +1 -0
  41. package/dist/editorLoader.d.ts +10 -0
  42. package/dist/editorLoader.js +68 -29
  43. package/dist/editorLoader.js.map +1 -1
  44. package/dist/events/EventBus.d.ts +59 -0
  45. package/dist/events/EventBus.js +154 -0
  46. package/dist/events/EventBus.js.map +1 -0
  47. package/dist/events/index.d.ts +9 -0
  48. package/dist/events/index.js +10 -0
  49. package/dist/events/index.js.map +1 -0
  50. package/dist/events/normalizers/canvas.d.ts +67 -0
  51. package/dist/events/normalizers/canvas.js +116 -0
  52. package/dist/events/normalizers/canvas.js.map +1 -0
  53. package/dist/events/normalizers/posthog.d.ts +29 -0
  54. package/dist/events/normalizers/posthog.js +155 -0
  55. package/dist/events/normalizers/posthog.js.map +1 -0
  56. package/dist/events/schema.d.ts +70 -0
  57. package/dist/events/schema.js +30 -0
  58. package/dist/events/schema.js.map +1 -0
  59. package/dist/events/types.d.ts +73 -0
  60. package/dist/events/types.js +41 -0
  61. package/dist/events/types.js.map +1 -0
  62. package/dist/hooks/useShadowCanvasConfig.d.ts +5 -1
  63. package/dist/hooks/useShadowCanvasConfig.js +17 -3
  64. package/dist/hooks/useShadowCanvasConfig.js.map +1 -1
  65. package/dist/index.d.ts +6 -0
  66. package/dist/index.js +15 -0
  67. package/dist/index.js.map +1 -1
  68. package/dist/logger.d.ts +29 -0
  69. package/dist/logger.js +81 -0
  70. package/dist/logger.js.map +1 -0
  71. package/dist/overlays/schema.d.ts +55 -55
  72. package/dist/runtime.d.ts +86 -0
  73. package/dist/runtime.js +132 -0
  74. package/dist/runtime.js.map +1 -0
  75. package/dist/smart-canvas.esm.js +11 -11
  76. package/dist/smart-canvas.esm.js.map +4 -4
  77. package/dist/smart-canvas.js +1801 -249
  78. package/dist/smart-canvas.js.map +4 -4
  79. package/dist/smart-canvas.min.js +12 -11
  80. package/dist/smart-canvas.min.js.map +4 -4
  81. package/dist/state/StateStore.d.ts +41 -0
  82. package/dist/state/StateStore.js +170 -0
  83. package/dist/state/StateStore.js.map +1 -0
  84. package/dist/state/helpers/cooldowns.d.ts +7 -0
  85. package/dist/state/helpers/cooldowns.js +31 -0
  86. package/dist/state/helpers/cooldowns.js.map +1 -0
  87. package/dist/state/helpers/dismissals.d.ts +7 -0
  88. package/dist/state/helpers/dismissals.js +34 -0
  89. package/dist/state/helpers/dismissals.js.map +1 -0
  90. package/dist/state/helpers/frequency.d.ts +8 -0
  91. package/dist/state/helpers/frequency.js +43 -0
  92. package/dist/state/helpers/frequency.js.map +1 -0
  93. package/dist/state/index.d.ts +7 -0
  94. package/dist/state/index.js +7 -0
  95. package/dist/state/index.js.map +1 -0
  96. package/dist/state/schema.d.ts +49 -0
  97. package/dist/state/schema.js +25 -0
  98. package/dist/state/schema.js.map +1 -0
  99. package/dist/state/types.d.ts +137 -0
  100. package/dist/state/types.js +9 -0
  101. package/dist/state/types.js.map +1 -0
  102. package/dist/telemetry/adapters/posthog.d.ts +1 -1
  103. package/dist/telemetry/adapters/posthog.js +1 -1
  104. package/dist/telemetry/adapters/posthog.js.map +1 -1
  105. package/dist/token.d.ts +2 -0
  106. package/dist/token.js.map +1 -1
  107. package/dist/types.d.ts +8 -0
  108. package/package.json +7 -4
  109. package/schema/canvas-config.schema.json +205 -0
  110. package/schema/runtime-context.schema.json +131 -0
@@ -15,11 +15,11 @@ export declare const SelectorZ: z.ZodUnion<[z.ZodObject<{
15
15
  type: z.ZodLiteral<"css">;
16
16
  value: z.ZodString;
17
17
  }, "strip", z.ZodTypeAny, {
18
- value: string;
19
18
  type: "css";
20
- }, {
21
19
  value: string;
20
+ }, {
22
21
  type: "css";
22
+ value: string;
23
23
  }>, z.ZodObject<{
24
24
  type: z.ZodLiteral<"aria">;
25
25
  role: z.ZodOptional<z.ZodString>;
@@ -36,11 +36,11 @@ export declare const SelectorZ: z.ZodUnion<[z.ZodObject<{
36
36
  type: z.ZodLiteral<"shadow-css">;
37
37
  value: z.ZodString;
38
38
  }, "strip", z.ZodTypeAny, {
39
- value: string;
40
39
  type: "shadow-css";
41
- }, {
42
40
  value: string;
41
+ }, {
43
42
  type: "shadow-css";
43
+ value: string;
44
44
  }>, z.ZodObject<{
45
45
  type: z.ZodLiteral<"ref">;
46
46
  el: z.ZodAny;
@@ -70,11 +70,11 @@ export declare const TooltipStepZ: z.ZodObject<{
70
70
  type: z.ZodLiteral<"css">;
71
71
  value: z.ZodString;
72
72
  }, "strip", z.ZodTypeAny, {
73
- value: string;
74
73
  type: "css";
75
- }, {
76
74
  value: string;
75
+ }, {
77
76
  type: "css";
77
+ value: string;
78
78
  }>, z.ZodObject<{
79
79
  type: z.ZodLiteral<"aria">;
80
80
  role: z.ZodOptional<z.ZodString>;
@@ -91,11 +91,11 @@ export declare const TooltipStepZ: z.ZodObject<{
91
91
  type: z.ZodLiteral<"shadow-css">;
92
92
  value: z.ZodString;
93
93
  }, "strip", z.ZodTypeAny, {
94
- value: string;
95
94
  type: "shadow-css";
96
- }, {
97
95
  value: string;
96
+ }, {
98
97
  type: "shadow-css";
98
+ value: string;
99
99
  }>, z.ZodObject<{
100
100
  type: z.ZodLiteral<"ref">;
101
101
  el: z.ZodAny;
@@ -139,15 +139,15 @@ export declare const TooltipStepZ: z.ZodObject<{
139
139
  key: string;
140
140
  value?: string | undefined;
141
141
  } | {
142
- value: string;
143
142
  type: "css";
143
+ value: string;
144
144
  } | {
145
145
  type: "aria";
146
146
  label?: string | undefined;
147
147
  role?: string | undefined;
148
148
  } | {
149
- value: string;
150
149
  type: "shadow-css";
150
+ value: string;
151
151
  } | {
152
152
  type: "ref";
153
153
  el?: any;
@@ -173,15 +173,15 @@ export declare const TooltipStepZ: z.ZodObject<{
173
173
  key: string;
174
174
  value?: string | undefined;
175
175
  } | {
176
- value: string;
177
176
  type: "css";
177
+ value: string;
178
178
  } | {
179
179
  type: "aria";
180
180
  label?: string | undefined;
181
181
  role?: string | undefined;
182
182
  } | {
183
- value: string;
184
183
  type: "shadow-css";
184
+ value: string;
185
185
  } | {
186
186
  type: "ref";
187
187
  el?: any;
@@ -221,11 +221,11 @@ export declare const HighlightStepZ: z.ZodObject<{
221
221
  type: z.ZodLiteral<"css">;
222
222
  value: z.ZodString;
223
223
  }, "strip", z.ZodTypeAny, {
224
- value: string;
225
224
  type: "css";
226
- }, {
227
225
  value: string;
226
+ }, {
228
227
  type: "css";
228
+ value: string;
229
229
  }>, z.ZodObject<{
230
230
  type: z.ZodLiteral<"aria">;
231
231
  role: z.ZodOptional<z.ZodString>;
@@ -242,11 +242,11 @@ export declare const HighlightStepZ: z.ZodObject<{
242
242
  type: z.ZodLiteral<"shadow-css">;
243
243
  value: z.ZodString;
244
244
  }, "strip", z.ZodTypeAny, {
245
- value: string;
246
245
  type: "shadow-css";
247
- }, {
248
246
  value: string;
247
+ }, {
249
248
  type: "shadow-css";
249
+ value: string;
250
250
  }>, z.ZodObject<{
251
251
  type: z.ZodLiteral<"ref">;
252
252
  el: z.ZodAny;
@@ -296,28 +296,28 @@ export declare const HighlightStepZ: z.ZodObject<{
296
296
  key: string;
297
297
  value?: string | undefined;
298
298
  } | {
299
- value: string;
300
299
  type: "css";
300
+ value: string;
301
301
  } | {
302
302
  type: "aria";
303
303
  label?: string | undefined;
304
304
  role?: string | undefined;
305
305
  } | {
306
- value: string;
307
306
  type: "shadow-css";
307
+ value: string;
308
308
  } | {
309
309
  type: "ref";
310
310
  el?: any;
311
311
  };
312
312
  kind: "highlight";
313
313
  id: string;
314
+ copy?: string | undefined;
314
315
  blocking?: boolean | undefined;
315
316
  dismiss?: {
316
317
  onEsc?: boolean | undefined;
317
318
  timeoutMs?: number | undefined;
318
319
  onClickOutside?: boolean | undefined;
319
320
  } | undefined;
320
- copy?: string | undefined;
321
321
  ring?: {
322
322
  paddingPx?: number | undefined;
323
323
  radiusPx?: number | undefined;
@@ -332,28 +332,28 @@ export declare const HighlightStepZ: z.ZodObject<{
332
332
  key: string;
333
333
  value?: string | undefined;
334
334
  } | {
335
- value: string;
336
335
  type: "css";
336
+ value: string;
337
337
  } | {
338
338
  type: "aria";
339
339
  label?: string | undefined;
340
340
  role?: string | undefined;
341
341
  } | {
342
- value: string;
343
342
  type: "shadow-css";
343
+ value: string;
344
344
  } | {
345
345
  type: "ref";
346
346
  el?: any;
347
347
  };
348
348
  kind: "highlight";
349
349
  id: string;
350
+ copy?: string | undefined;
350
351
  blocking?: boolean | undefined;
351
352
  dismiss?: {
352
353
  onEsc?: boolean | undefined;
353
354
  timeoutMs?: number | undefined;
354
355
  onClickOutside?: boolean | undefined;
355
356
  } | undefined;
356
- copy?: string | undefined;
357
357
  ring?: {
358
358
  paddingPx?: number | undefined;
359
359
  radiusPx?: number | undefined;
@@ -386,11 +386,11 @@ export declare const CanvasRecipeZ: z.ZodObject<{
386
386
  type: z.ZodLiteral<"css">;
387
387
  value: z.ZodString;
388
388
  }, "strip", z.ZodTypeAny, {
389
- value: string;
390
389
  type: "css";
391
- }, {
392
390
  value: string;
391
+ }, {
393
392
  type: "css";
393
+ value: string;
394
394
  }>, z.ZodObject<{
395
395
  type: z.ZodLiteral<"aria">;
396
396
  role: z.ZodOptional<z.ZodString>;
@@ -407,11 +407,11 @@ export declare const CanvasRecipeZ: z.ZodObject<{
407
407
  type: z.ZodLiteral<"shadow-css">;
408
408
  value: z.ZodString;
409
409
  }, "strip", z.ZodTypeAny, {
410
- value: string;
411
410
  type: "shadow-css";
412
- }, {
413
411
  value: string;
412
+ }, {
414
413
  type: "shadow-css";
414
+ value: string;
415
415
  }>, z.ZodObject<{
416
416
  type: z.ZodLiteral<"ref">;
417
417
  el: z.ZodAny;
@@ -455,15 +455,15 @@ export declare const CanvasRecipeZ: z.ZodObject<{
455
455
  key: string;
456
456
  value?: string | undefined;
457
457
  } | {
458
- value: string;
459
458
  type: "css";
459
+ value: string;
460
460
  } | {
461
461
  type: "aria";
462
462
  label?: string | undefined;
463
463
  role?: string | undefined;
464
464
  } | {
465
- value: string;
466
465
  type: "shadow-css";
466
+ value: string;
467
467
  } | {
468
468
  type: "ref";
469
469
  el?: any;
@@ -489,15 +489,15 @@ export declare const CanvasRecipeZ: z.ZodObject<{
489
489
  key: string;
490
490
  value?: string | undefined;
491
491
  } | {
492
- value: string;
493
492
  type: "css";
493
+ value: string;
494
494
  } | {
495
495
  type: "aria";
496
496
  label?: string | undefined;
497
497
  role?: string | undefined;
498
498
  } | {
499
- value: string;
500
499
  type: "shadow-css";
500
+ value: string;
501
501
  } | {
502
502
  type: "ref";
503
503
  el?: any;
@@ -536,11 +536,11 @@ export declare const CanvasRecipeZ: z.ZodObject<{
536
536
  type: z.ZodLiteral<"css">;
537
537
  value: z.ZodString;
538
538
  }, "strip", z.ZodTypeAny, {
539
- value: string;
540
539
  type: "css";
541
- }, {
542
540
  value: string;
541
+ }, {
543
542
  type: "css";
543
+ value: string;
544
544
  }>, z.ZodObject<{
545
545
  type: z.ZodLiteral<"aria">;
546
546
  role: z.ZodOptional<z.ZodString>;
@@ -557,11 +557,11 @@ export declare const CanvasRecipeZ: z.ZodObject<{
557
557
  type: z.ZodLiteral<"shadow-css">;
558
558
  value: z.ZodString;
559
559
  }, "strip", z.ZodTypeAny, {
560
- value: string;
561
560
  type: "shadow-css";
562
- }, {
563
561
  value: string;
562
+ }, {
564
563
  type: "shadow-css";
564
+ value: string;
565
565
  }>, z.ZodObject<{
566
566
  type: z.ZodLiteral<"ref">;
567
567
  el: z.ZodAny;
@@ -611,28 +611,28 @@ export declare const CanvasRecipeZ: z.ZodObject<{
611
611
  key: string;
612
612
  value?: string | undefined;
613
613
  } | {
614
- value: string;
615
614
  type: "css";
615
+ value: string;
616
616
  } | {
617
617
  type: "aria";
618
618
  label?: string | undefined;
619
619
  role?: string | undefined;
620
620
  } | {
621
- value: string;
622
621
  type: "shadow-css";
622
+ value: string;
623
623
  } | {
624
624
  type: "ref";
625
625
  el?: any;
626
626
  };
627
627
  kind: "highlight";
628
628
  id: string;
629
+ copy?: string | undefined;
629
630
  blocking?: boolean | undefined;
630
631
  dismiss?: {
631
632
  onEsc?: boolean | undefined;
632
633
  timeoutMs?: number | undefined;
633
634
  onClickOutside?: boolean | undefined;
634
635
  } | undefined;
635
- copy?: string | undefined;
636
636
  ring?: {
637
637
  paddingPx?: number | undefined;
638
638
  radiusPx?: number | undefined;
@@ -647,28 +647,28 @@ export declare const CanvasRecipeZ: z.ZodObject<{
647
647
  key: string;
648
648
  value?: string | undefined;
649
649
  } | {
650
- value: string;
651
650
  type: "css";
651
+ value: string;
652
652
  } | {
653
653
  type: "aria";
654
654
  label?: string | undefined;
655
655
  role?: string | undefined;
656
656
  } | {
657
- value: string;
658
657
  type: "shadow-css";
658
+ value: string;
659
659
  } | {
660
660
  type: "ref";
661
661
  el?: any;
662
662
  };
663
663
  kind: "highlight";
664
664
  id: string;
665
+ copy?: string | undefined;
665
666
  blocking?: boolean | undefined;
666
667
  dismiss?: {
667
668
  onEsc?: boolean | undefined;
668
669
  timeoutMs?: number | undefined;
669
670
  onClickOutside?: boolean | undefined;
670
671
  } | undefined;
671
- copy?: string | undefined;
672
672
  ring?: {
673
673
  paddingPx?: number | undefined;
674
674
  radiusPx?: number | undefined;
@@ -685,15 +685,15 @@ export declare const CanvasRecipeZ: z.ZodObject<{
685
685
  key: string;
686
686
  value?: string | undefined;
687
687
  } | {
688
- value: string;
689
688
  type: "css";
689
+ value: string;
690
690
  } | {
691
691
  type: "aria";
692
692
  label?: string | undefined;
693
693
  role?: string | undefined;
694
694
  } | {
695
- value: string;
696
695
  type: "shadow-css";
696
+ value: string;
697
697
  } | {
698
698
  type: "ref";
699
699
  el?: any;
@@ -719,28 +719,28 @@ export declare const CanvasRecipeZ: z.ZodObject<{
719
719
  key: string;
720
720
  value?: string | undefined;
721
721
  } | {
722
- value: string;
723
722
  type: "css";
723
+ value: string;
724
724
  } | {
725
725
  type: "aria";
726
726
  label?: string | undefined;
727
727
  role?: string | undefined;
728
728
  } | {
729
- value: string;
730
729
  type: "shadow-css";
730
+ value: string;
731
731
  } | {
732
732
  type: "ref";
733
733
  el?: any;
734
734
  };
735
735
  kind: "highlight";
736
736
  id: string;
737
+ copy?: string | undefined;
737
738
  blocking?: boolean | undefined;
738
739
  dismiss?: {
739
740
  onEsc?: boolean | undefined;
740
741
  timeoutMs?: number | undefined;
741
742
  onClickOutside?: boolean | undefined;
742
743
  } | undefined;
743
- copy?: string | undefined;
744
744
  ring?: {
745
745
  paddingPx?: number | undefined;
746
746
  radiusPx?: number | undefined;
@@ -760,15 +760,15 @@ export declare const CanvasRecipeZ: z.ZodObject<{
760
760
  key: string;
761
761
  value?: string | undefined;
762
762
  } | {
763
- value: string;
764
763
  type: "css";
764
+ value: string;
765
765
  } | {
766
766
  type: "aria";
767
767
  label?: string | undefined;
768
768
  role?: string | undefined;
769
769
  } | {
770
- value: string;
771
770
  type: "shadow-css";
771
+ value: string;
772
772
  } | {
773
773
  type: "ref";
774
774
  el?: any;
@@ -794,28 +794,28 @@ export declare const CanvasRecipeZ: z.ZodObject<{
794
794
  key: string;
795
795
  value?: string | undefined;
796
796
  } | {
797
- value: string;
798
797
  type: "css";
798
+ value: string;
799
799
  } | {
800
800
  type: "aria";
801
801
  label?: string | undefined;
802
802
  role?: string | undefined;
803
803
  } | {
804
- value: string;
805
804
  type: "shadow-css";
805
+ value: string;
806
806
  } | {
807
807
  type: "ref";
808
808
  el?: any;
809
809
  };
810
810
  kind: "highlight";
811
811
  id: string;
812
+ copy?: string | undefined;
812
813
  blocking?: boolean | undefined;
813
814
  dismiss?: {
814
815
  onEsc?: boolean | undefined;
815
816
  timeoutMs?: number | undefined;
816
817
  onClickOutside?: boolean | undefined;
817
818
  } | undefined;
818
- copy?: string | undefined;
819
819
  ring?: {
820
820
  paddingPx?: number | undefined;
821
821
  radiusPx?: number | undefined;
@@ -836,15 +836,15 @@ export declare function validateRecipe(json: unknown): {
836
836
  key: string;
837
837
  value?: string | undefined;
838
838
  } | {
839
- value: string;
840
839
  type: "css";
840
+ value: string;
841
841
  } | {
842
842
  type: "aria";
843
843
  label?: string | undefined;
844
844
  role?: string | undefined;
845
845
  } | {
846
- value: string;
847
846
  type: "shadow-css";
847
+ value: string;
848
848
  } | {
849
849
  type: "ref";
850
850
  el?: any;
@@ -870,28 +870,28 @@ export declare function validateRecipe(json: unknown): {
870
870
  key: string;
871
871
  value?: string | undefined;
872
872
  } | {
873
- value: string;
874
873
  type: "css";
874
+ value: string;
875
875
  } | {
876
876
  type: "aria";
877
877
  label?: string | undefined;
878
878
  role?: string | undefined;
879
879
  } | {
880
- value: string;
881
880
  type: "shadow-css";
881
+ value: string;
882
882
  } | {
883
883
  type: "ref";
884
884
  el?: any;
885
885
  };
886
886
  kind: "highlight";
887
887
  id: string;
888
+ copy?: string | undefined;
888
889
  blocking?: boolean | undefined;
889
890
  dismiss?: {
890
891
  onEsc?: boolean | undefined;
891
892
  timeoutMs?: number | undefined;
892
893
  onClickOutside?: boolean | undefined;
893
894
  } | undefined;
894
- copy?: string | undefined;
895
895
  ring?: {
896
896
  paddingPx?: number | undefined;
897
897
  radiusPx?: number | undefined;
@@ -0,0 +1,86 @@
1
+ /**
2
+ * SmartCanvasRuntime - Unified runtime for v2 adaptives.
3
+ *
4
+ * The runtime provides access to all core providers:
5
+ * - telemetry: Event tracking (PostHog)
6
+ * - context: Page/session/viewport state
7
+ * - events: Normalized event stream
8
+ * - state: Persistent state storage
9
+ *
10
+ * Note: ExperimentClient (GrowthBook) is NOT part of the runtime.
11
+ * GrowthBook's job is done at page load when it selects which config to deliver.
12
+ * The runtime receives the config and makes decisions using DecisionStrategy.
13
+ */
14
+ import type { TelemetryClient } from "./telemetry/types";
15
+ import { ContextManager } from "./context/ContextManager";
16
+ import { EventBus } from "./events/EventBus";
17
+ import { StateStore } from "./state/StateStore";
18
+ import type { DecisionStrategy, DecisionResult } from "./decisions/types";
19
+ import type { SessionMetricTracker } from "./metrics/sessionMetrics";
20
+ import type { RoutesConfig, TileConfig } from "./types";
21
+ /**
22
+ * Runtime version.
23
+ */
24
+ export declare const RUNTIME_VERSION = "2.0.0";
25
+ /**
26
+ * Runtime mode.
27
+ */
28
+ export type RuntimeMode = "production" | "development" | "editor" | "audit";
29
+ /**
30
+ * SmartCanvasRuntime interface.
31
+ */
32
+ export interface SmartCanvasRuntime {
33
+ /** Telemetry client for event tracking */
34
+ telemetry?: TelemetryClient;
35
+ /** Context manager for page/session/viewport state */
36
+ context: ContextManager;
37
+ /** Event bus for normalized event stream */
38
+ events: EventBus;
39
+ /** State store for persistent state */
40
+ state: StateStore;
41
+ /** Session metric tracker (optional) */
42
+ sessionMetrics?: SessionMetricTracker;
43
+ /** Runtime version */
44
+ version: string;
45
+ /** Runtime mode */
46
+ mode: RuntimeMode;
47
+ /**
48
+ * Evaluate a decision strategy against the current context.
49
+ */
50
+ evaluate<T>(strategy: DecisionStrategy<T>): Promise<DecisionResult<T>>;
51
+ /**
52
+ * Synchronously evaluate a decision strategy (for simple strategies).
53
+ */
54
+ evaluateSync<T>(strategy: DecisionStrategy<T>): DecisionResult<T>;
55
+ /**
56
+ * Filter tiles based on their activation configs.
57
+ */
58
+ filterTiles(tiles: TileConfig[]): Promise<TileConfig[]>;
59
+ /**
60
+ * Update the routes config (e.g., when config is fetched).
61
+ */
62
+ setRoutes(routes: RoutesConfig): void;
63
+ /**
64
+ * Clean up runtime resources.
65
+ */
66
+ destroy(): void;
67
+ }
68
+ /**
69
+ * Options for creating a SmartCanvasRuntime.
70
+ */
71
+ export interface SmartCanvasRuntimeOptions {
72
+ /** Telemetry client */
73
+ telemetry?: TelemetryClient;
74
+ /** Session metric tracker */
75
+ sessionMetrics?: SessionMetricTracker;
76
+ /** Initial routes config */
77
+ routes?: RoutesConfig;
78
+ /** Runtime mode */
79
+ mode?: RuntimeMode;
80
+ /** State namespace */
81
+ namespace?: string;
82
+ }
83
+ /**
84
+ * Create a SmartCanvasRuntime instance.
85
+ */
86
+ export declare function createSmartCanvasRuntime(options?: SmartCanvasRuntimeOptions): SmartCanvasRuntime;
@@ -0,0 +1,132 @@
1
+ import { createContextManager } from "./context/ContextManager";
2
+ import { createEventBus } from "./events/EventBus";
3
+ import { createStateStore } from "./state/StateStore";
4
+ import { createDecisionEngine } from "./decisions/engine";
5
+ /**
6
+ * Runtime version.
7
+ */
8
+ export const RUNTIME_VERSION = "2.0.0";
9
+ /**
10
+ * Check if a URL matches a route filter.
11
+ */
12
+ function matchesRouteFilter(url, filter) {
13
+ if (!filter)
14
+ return true;
15
+ // Extract pathname
16
+ let pathname;
17
+ try {
18
+ pathname = new URL(url).pathname;
19
+ }
20
+ catch {
21
+ pathname = url;
22
+ }
23
+ // Normalize pathname
24
+ const normalizedPath = pathname.replace(/\/$/, "") || "/";
25
+ // Check exclude patterns first
26
+ if (filter.exclude) {
27
+ for (const pattern of filter.exclude) {
28
+ if (matchRoutePattern(normalizedPath, pattern)) {
29
+ return false; // Explicitly excluded
30
+ }
31
+ }
32
+ }
33
+ // If include list exists, must match at least one
34
+ if (filter.include && filter.include.length > 0) {
35
+ for (const pattern of filter.include) {
36
+ if (matchRoutePattern(normalizedPath, pattern)) {
37
+ return true; // Matches include list
38
+ }
39
+ }
40
+ return false; // Didn't match any include pattern
41
+ }
42
+ // No include list, not excluded = pass
43
+ return true;
44
+ }
45
+ /**
46
+ * Match a pathname against a route pattern.
47
+ */
48
+ function matchRoutePattern(pathname, pattern) {
49
+ const normalizedPattern = pattern.replace(/\/$/, "") || "/";
50
+ // Exact match
51
+ if (pathname === normalizedPattern)
52
+ return true;
53
+ // Convert pattern to regex
54
+ const regexPattern = normalizedPattern
55
+ .replace(/[.+^${}()|[\]\\]/g, "\\$&") // Escape regex chars
56
+ .replace(/\*\*/g, ".*") // ** matches anything
57
+ .replace(/\*/g, "[^/]*") // * matches within path segment
58
+ .replace(/:[^/]+/g, "[^/]+"); // :param matches any segment
59
+ const regex = new RegExp(`^${regexPattern}$`);
60
+ return regex.test(pathname);
61
+ }
62
+ /**
63
+ * Create a SmartCanvasRuntime instance.
64
+ */
65
+ export function createSmartCanvasRuntime(options = {}) {
66
+ const { telemetry, sessionMetrics, routes, mode = "production", namespace } = options;
67
+ // Create core providers
68
+ const context = createContextManager({
69
+ telemetry,
70
+ routes,
71
+ });
72
+ const events = createEventBus();
73
+ const state = createStateStore({
74
+ namespace,
75
+ });
76
+ // Create decision engine with bound options
77
+ const decisionEngine = createDecisionEngine({
78
+ state,
79
+ events,
80
+ sessionMetrics,
81
+ });
82
+ const runtime = {
83
+ telemetry,
84
+ context,
85
+ events,
86
+ state,
87
+ sessionMetrics,
88
+ version: RUNTIME_VERSION,
89
+ mode,
90
+ async evaluate(strategy) {
91
+ return decisionEngine.evaluate(strategy, context.get());
92
+ },
93
+ evaluateSync(strategy) {
94
+ return decisionEngine.evaluateSync(strategy, context.get());
95
+ },
96
+ async filterTiles(tiles) {
97
+ const currentUrl = context.get().page.url;
98
+ const results = [];
99
+ for (const tile of tiles) {
100
+ const activation = tile.activation;
101
+ // If no activation config, tile always renders
102
+ if (!activation) {
103
+ results.push(tile);
104
+ continue;
105
+ }
106
+ // Check route filter first
107
+ if (!matchesRouteFilter(currentUrl, activation.routes)) {
108
+ continue; // Doesn't match route filter
109
+ }
110
+ // If no strategy, tile renders (route filter passed)
111
+ if (!activation.strategy) {
112
+ results.push(tile);
113
+ continue;
114
+ }
115
+ // Evaluate strategy
116
+ const result = await this.evaluate(activation.strategy);
117
+ if (result.value) {
118
+ results.push(tile);
119
+ }
120
+ }
121
+ return results;
122
+ },
123
+ setRoutes(routes) {
124
+ context.setRoutes(routes);
125
+ },
126
+ destroy() {
127
+ context.destroy();
128
+ },
129
+ };
130
+ return runtime;
131
+ }
132
+ //# sourceMappingURL=runtime.js.map