@syntrologie/runtime-sdk 0.2.19 → 0.2.21

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 (101) hide show
  1. package/CAPABILITIES.md +211 -0
  2. package/dist/api.js +7 -6
  3. package/dist/api.js.map +1 -1
  4. package/dist/bootstrap.d.ts +16 -2
  5. package/dist/bootstrap.js +63 -14
  6. package/dist/bootstrap.js.map +1 -1
  7. package/dist/context/ContextManager.d.ts +66 -0
  8. package/dist/context/ContextManager.js +268 -0
  9. package/dist/context/ContextManager.js.map +1 -0
  10. package/dist/context/index.d.ts +7 -0
  11. package/dist/context/index.js +7 -0
  12. package/dist/context/index.js.map +1 -0
  13. package/dist/context/schema.d.ts +360 -0
  14. package/dist/context/schema.js +50 -0
  15. package/dist/context/schema.js.map +1 -0
  16. package/dist/context/types.d.ts +101 -0
  17. package/dist/context/types.js +8 -0
  18. package/dist/context/types.js.map +1 -0
  19. package/dist/decisions/engine.d.ts +43 -0
  20. package/dist/decisions/engine.js +112 -0
  21. package/dist/decisions/engine.js.map +1 -0
  22. package/dist/decisions/index.d.ts +9 -0
  23. package/dist/decisions/index.js +10 -0
  24. package/dist/decisions/index.js.map +1 -0
  25. package/dist/decisions/schema.d.ts +2166 -0
  26. package/dist/decisions/schema.js +143 -0
  27. package/dist/decisions/schema.js.map +1 -0
  28. package/dist/decisions/strategies/rules.d.ts +24 -0
  29. package/dist/decisions/strategies/rules.js +152 -0
  30. package/dist/decisions/strategies/rules.js.map +1 -0
  31. package/dist/decisions/strategies/score.d.ts +10 -0
  32. package/dist/decisions/strategies/score.js +29 -0
  33. package/dist/decisions/strategies/score.js.map +1 -0
  34. package/dist/decisions/types.d.ts +242 -0
  35. package/dist/decisions/types.js +2 -0
  36. package/dist/decisions/types.js.map +1 -0
  37. package/dist/editorLoader.d.ts +10 -0
  38. package/dist/editorLoader.js +38 -0
  39. package/dist/editorLoader.js.map +1 -1
  40. package/dist/events/EventBus.d.ts +59 -0
  41. package/dist/events/EventBus.js +154 -0
  42. package/dist/events/EventBus.js.map +1 -0
  43. package/dist/events/index.d.ts +9 -0
  44. package/dist/events/index.js +10 -0
  45. package/dist/events/index.js.map +1 -0
  46. package/dist/events/normalizers/canvas.d.ts +67 -0
  47. package/dist/events/normalizers/canvas.js +116 -0
  48. package/dist/events/normalizers/canvas.js.map +1 -0
  49. package/dist/events/normalizers/posthog.d.ts +29 -0
  50. package/dist/events/normalizers/posthog.js +155 -0
  51. package/dist/events/normalizers/posthog.js.map +1 -0
  52. package/dist/events/schema.d.ts +70 -0
  53. package/dist/events/schema.js +30 -0
  54. package/dist/events/schema.js.map +1 -0
  55. package/dist/events/types.d.ts +73 -0
  56. package/dist/events/types.js +41 -0
  57. package/dist/events/types.js.map +1 -0
  58. package/dist/hooks/useShadowCanvasConfig.d.ts +5 -1
  59. package/dist/hooks/useShadowCanvasConfig.js +17 -3
  60. package/dist/hooks/useShadowCanvasConfig.js.map +1 -1
  61. package/dist/index.d.ts +6 -0
  62. package/dist/index.js +15 -0
  63. package/dist/index.js.map +1 -1
  64. package/dist/overlays/schema.d.ts +48 -48
  65. package/dist/runtime.d.ts +86 -0
  66. package/dist/runtime.js +132 -0
  67. package/dist/runtime.js.map +1 -0
  68. package/dist/smart-canvas.esm.js +11 -11
  69. package/dist/smart-canvas.esm.js.map +4 -4
  70. package/dist/smart-canvas.js +1504 -17
  71. package/dist/smart-canvas.js.map +4 -4
  72. package/dist/smart-canvas.min.js +11 -11
  73. package/dist/smart-canvas.min.js.map +4 -4
  74. package/dist/state/StateStore.d.ts +41 -0
  75. package/dist/state/StateStore.js +170 -0
  76. package/dist/state/StateStore.js.map +1 -0
  77. package/dist/state/helpers/cooldowns.d.ts +7 -0
  78. package/dist/state/helpers/cooldowns.js +31 -0
  79. package/dist/state/helpers/cooldowns.js.map +1 -0
  80. package/dist/state/helpers/dismissals.d.ts +7 -0
  81. package/dist/state/helpers/dismissals.js +34 -0
  82. package/dist/state/helpers/dismissals.js.map +1 -0
  83. package/dist/state/helpers/frequency.d.ts +8 -0
  84. package/dist/state/helpers/frequency.js +43 -0
  85. package/dist/state/helpers/frequency.js.map +1 -0
  86. package/dist/state/index.d.ts +7 -0
  87. package/dist/state/index.js +7 -0
  88. package/dist/state/index.js.map +1 -0
  89. package/dist/state/schema.d.ts +49 -0
  90. package/dist/state/schema.js +25 -0
  91. package/dist/state/schema.js.map +1 -0
  92. package/dist/state/types.d.ts +137 -0
  93. package/dist/state/types.js +9 -0
  94. package/dist/state/types.js.map +1 -0
  95. package/dist/telemetry/adapters/posthog.d.ts +1 -1
  96. package/dist/telemetry/adapters/posthog.js +1 -1
  97. package/dist/telemetry/adapters/posthog.js.map +1 -1
  98. package/dist/types.d.ts +8 -0
  99. package/package.json +2 -2
  100. package/schema/canvas-config.schema.json +205 -0
  101. package/schema/runtime-context.schema.json +131 -0
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Creates a default RuntimeContext.
3
+ */
4
+ function createDefaultContext() {
5
+ const now = Date.now();
6
+ return {
7
+ page: {
8
+ url: typeof window !== "undefined" ? window.location.href : "",
9
+ title: typeof document !== "undefined" ? document.title : undefined,
10
+ },
11
+ session: {
12
+ sessionId: "",
13
+ startTs: now,
14
+ pageHistory: [],
15
+ },
16
+ viewport: {
17
+ width: typeof window !== "undefined" ? window.innerWidth : 0,
18
+ height: typeof window !== "undefined" ? window.innerHeight : 0,
19
+ },
20
+ };
21
+ }
22
+ /**
23
+ * Match a URL against route patterns from RoutesConfig.
24
+ * Returns the matched pattern or undefined.
25
+ */
26
+ function matchRoute(url, routes) {
27
+ if (!routes)
28
+ return undefined;
29
+ // Extract pathname from URL
30
+ let pathname;
31
+ try {
32
+ pathname = new URL(url).pathname;
33
+ }
34
+ catch {
35
+ pathname = url;
36
+ }
37
+ // Check exclude patterns first
38
+ if (routes.exclude) {
39
+ for (const pattern of routes.exclude) {
40
+ if (matchPattern(pathname, pattern)) {
41
+ return undefined; // Excluded route
42
+ }
43
+ }
44
+ }
45
+ // Check include patterns
46
+ if (routes.include) {
47
+ for (const pattern of routes.include) {
48
+ if (matchPattern(pathname, pattern)) {
49
+ return pattern;
50
+ }
51
+ }
52
+ return undefined; // No match in include list
53
+ }
54
+ return pathname; // No include list, return pathname as route
55
+ }
56
+ /**
57
+ * Simple pattern matching for routes.
58
+ * Supports:
59
+ * - Exact matches: "/products"
60
+ * - Wildcard segments: "/products/*"
61
+ * - Parameter segments: "/products/:id"
62
+ */
63
+ function matchPattern(pathname, pattern) {
64
+ // Normalize paths
65
+ const normalizedPath = pathname.replace(/\/$/, "") || "/";
66
+ const normalizedPattern = pattern.replace(/\/$/, "") || "/";
67
+ // Exact match
68
+ if (normalizedPath === normalizedPattern)
69
+ return true;
70
+ // Convert pattern to regex
71
+ const regexPattern = normalizedPattern
72
+ .replace(/:[^/]+/g, "[^/]+") // :param -> [^/]+
73
+ .replace(/\*/g, ".*"); // * -> .*
74
+ const regex = new RegExp(`^${regexPattern}$`);
75
+ return regex.test(normalizedPath);
76
+ }
77
+ /**
78
+ * ContextManager class for managing runtime context.
79
+ */
80
+ export class ContextManager {
81
+ constructor(options = {}) {
82
+ var _a;
83
+ this.listeners = new Set();
84
+ // Event listener cleanup functions
85
+ this.cleanupFns = [];
86
+ this.telemetry = options.telemetry;
87
+ this.routes = options.routes;
88
+ // Initialize context
89
+ this.context = createDefaultContext();
90
+ this.previousContext = { ...this.context };
91
+ // Set initial session ID from telemetry
92
+ if ((_a = options.telemetry) === null || _a === void 0 ? void 0 : _a.getSessionId) {
93
+ const sessionId = options.telemetry.getSessionId();
94
+ if (sessionId) {
95
+ this.context.session.sessionId = sessionId;
96
+ }
97
+ }
98
+ // Set initial page history
99
+ if (options.initialPageHistory) {
100
+ this.context.session.pageHistory = options.initialPageHistory;
101
+ }
102
+ // Set initial route ID
103
+ this.context.page.routeId = matchRoute(this.context.page.url, this.routes);
104
+ // Add current page to history
105
+ this.addPageToHistory(this.context.page.url);
106
+ // Setup browser event listeners
107
+ if (typeof window !== "undefined") {
108
+ this.setupBrowserListeners();
109
+ }
110
+ }
111
+ /**
112
+ * Get the current runtime context.
113
+ */
114
+ get() {
115
+ return { ...this.context };
116
+ }
117
+ /**
118
+ * Subscribe to context changes.
119
+ * Returns an unsubscribe function.
120
+ */
121
+ subscribe(callback) {
122
+ this.listeners.add(callback);
123
+ return () => {
124
+ this.listeners.delete(callback);
125
+ };
126
+ }
127
+ /**
128
+ * Update the routes config (e.g., when config is fetched).
129
+ */
130
+ setRoutes(routes) {
131
+ this.routes = routes;
132
+ // Re-evaluate current route
133
+ const newRouteId = matchRoute(this.context.page.url, this.routes);
134
+ if (newRouteId !== this.context.page.routeId) {
135
+ this.updateContext({ page: { ...this.context.page, routeId: newRouteId } });
136
+ }
137
+ }
138
+ /**
139
+ * Update anchor states.
140
+ */
141
+ setAnchors(anchors) {
142
+ this.updateContext({ anchors });
143
+ }
144
+ /**
145
+ * Manually update the session ID (e.g., when telemetry initializes).
146
+ */
147
+ setSessionId(sessionId) {
148
+ if (sessionId !== this.context.session.sessionId) {
149
+ this.updateContext({
150
+ session: { ...this.context.session, sessionId },
151
+ });
152
+ }
153
+ }
154
+ /**
155
+ * Clean up event listeners and subscriptions.
156
+ */
157
+ destroy() {
158
+ for (const cleanup of this.cleanupFns) {
159
+ cleanup();
160
+ }
161
+ this.cleanupFns = [];
162
+ this.listeners.clear();
163
+ }
164
+ // ==================== Private Methods ====================
165
+ setupBrowserListeners() {
166
+ // Viewport resize listener (debounced)
167
+ let resizeTimeout;
168
+ const handleResize = () => {
169
+ clearTimeout(resizeTimeout);
170
+ resizeTimeout = setTimeout(() => {
171
+ this.updateViewport();
172
+ }, 100);
173
+ };
174
+ window.addEventListener("resize", handleResize);
175
+ this.cleanupFns.push(() => window.removeEventListener("resize", handleResize));
176
+ // Navigation listener (popstate for back/forward)
177
+ const handlePopState = () => {
178
+ this.updatePage();
179
+ };
180
+ window.addEventListener("popstate", handlePopState);
181
+ this.cleanupFns.push(() => window.removeEventListener("popstate", handlePopState));
182
+ // History pushState/replaceState interception
183
+ const originalPushState = history.pushState.bind(history);
184
+ const originalReplaceState = history.replaceState.bind(history);
185
+ history.pushState = (...args) => {
186
+ originalPushState(...args);
187
+ this.updatePage();
188
+ };
189
+ history.replaceState = (...args) => {
190
+ originalReplaceState(...args);
191
+ this.updatePage();
192
+ };
193
+ this.cleanupFns.push(() => {
194
+ history.pushState = originalPushState;
195
+ history.replaceState = originalReplaceState;
196
+ });
197
+ }
198
+ updateViewport() {
199
+ const newViewport = {
200
+ width: window.innerWidth,
201
+ height: window.innerHeight,
202
+ };
203
+ if (newViewport.width !== this.context.viewport.width ||
204
+ newViewport.height !== this.context.viewport.height) {
205
+ this.updateContext({ viewport: newViewport });
206
+ }
207
+ }
208
+ updatePage() {
209
+ const url = window.location.href;
210
+ const title = document.title;
211
+ const routeId = matchRoute(url, this.routes);
212
+ const newPage = {
213
+ url,
214
+ title,
215
+ routeId,
216
+ };
217
+ // Only update if something changed
218
+ if (newPage.url !== this.context.page.url ||
219
+ newPage.title !== this.context.page.title ||
220
+ newPage.routeId !== this.context.page.routeId) {
221
+ // Add to page history if URL changed
222
+ if (newPage.url !== this.context.page.url) {
223
+ this.addPageToHistory(newPage.url);
224
+ }
225
+ this.updateContext({ page: newPage });
226
+ }
227
+ }
228
+ addPageToHistory(url) {
229
+ const entry = {
230
+ url,
231
+ ts: Date.now(),
232
+ };
233
+ const pageHistory = [...(this.context.session.pageHistory || []), entry];
234
+ // Keep last 50 pages in history
235
+ if (pageHistory.length > 50) {
236
+ pageHistory.shift();
237
+ }
238
+ this.context.session.pageHistory = pageHistory;
239
+ }
240
+ updateContext(partial) {
241
+ // Save previous context
242
+ this.previousContext = { ...this.context };
243
+ // Merge updates
244
+ this.context = {
245
+ ...this.context,
246
+ ...partial,
247
+ };
248
+ // Notify listeners
249
+ this.notifyListeners();
250
+ }
251
+ notifyListeners() {
252
+ for (const callback of this.listeners) {
253
+ try {
254
+ callback(this.context, this.previousContext);
255
+ }
256
+ catch (err) {
257
+ console.error("[ContextManager] Listener error:", err);
258
+ }
259
+ }
260
+ }
261
+ }
262
+ /**
263
+ * Create a ContextManager instance.
264
+ */
265
+ export function createContextManager(options = {}) {
266
+ return new ContextManager(options);
267
+ }
268
+ //# sourceMappingURL=ContextManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextManager.js","sourceRoot":"","sources":["../../src/context/ContextManager.ts"],"names":[],"mappings":"AA8BA;;GAEG;AACH,SAAS,oBAAoB;IAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,OAAO;QACL,IAAI,EAAE;YACJ,GAAG,EAAE,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YAC9D,KAAK,EAAE,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SACpE;QACD,OAAO,EAAE;YACP,SAAS,EAAE,EAAE;YACb,OAAO,EAAE,GAAG;YACZ,WAAW,EAAE,EAAE;SAChB;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC5D,MAAM,EAAE,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;SAC/D;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,UAAU,CAAC,GAAW,EAAE,MAAqB;IACpD,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAE9B,4BAA4B;IAC5B,IAAI,QAAgB,CAAC;IACrB,IAAI,CAAC;QACH,QAAQ,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;IACnC,CAAC;IAAC,MAAM,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,EAAE,GAAG,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,UAAiC,EAAE;IAEnC,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Context module exports.
3
+ */
4
+ export * from "./types";
5
+ export * from "./schema";
6
+ export { ContextManager, createContextManager } from "./ContextManager";
7
+ export type { ContextManagerOptions } from "./ContextManager";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Context module exports.
3
+ */
4
+ export * from "./types";
5
+ export * from "./schema";
6
+ export { ContextManager, createContextManager } from "./ContextManager";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,360 @@
1
+ /**
2
+ * Zod schemas for RuntimeContext validation.
3
+ */
4
+ import { z } from "zod";
5
+ export declare const PageContextZ: z.ZodObject<{
6
+ url: z.ZodString;
7
+ routeId: z.ZodOptional<z.ZodString>;
8
+ title: z.ZodOptional<z.ZodString>;
9
+ locale: z.ZodOptional<z.ZodString>;
10
+ }, "strip", z.ZodTypeAny, {
11
+ url: string;
12
+ title?: string | undefined;
13
+ routeId?: string | undefined;
14
+ locale?: string | undefined;
15
+ }, {
16
+ url: string;
17
+ title?: string | undefined;
18
+ routeId?: string | undefined;
19
+ locale?: string | undefined;
20
+ }>;
21
+ export declare const PageHistoryEntryZ: z.ZodObject<{
22
+ url: z.ZodString;
23
+ ts: z.ZodNumber;
24
+ }, "strip", z.ZodTypeAny, {
25
+ url: string;
26
+ ts: number;
27
+ }, {
28
+ url: string;
29
+ ts: number;
30
+ }>;
31
+ export declare const SessionContextZ: z.ZodObject<{
32
+ sessionId: z.ZodString;
33
+ startTs: z.ZodNumber;
34
+ pageHistory: z.ZodOptional<z.ZodArray<z.ZodObject<{
35
+ url: z.ZodString;
36
+ ts: z.ZodNumber;
37
+ }, "strip", z.ZodTypeAny, {
38
+ url: string;
39
+ ts: number;
40
+ }, {
41
+ url: string;
42
+ ts: number;
43
+ }>, "many">>;
44
+ }, "strip", z.ZodTypeAny, {
45
+ sessionId: string;
46
+ startTs: number;
47
+ pageHistory?: {
48
+ url: string;
49
+ ts: number;
50
+ }[] | undefined;
51
+ }, {
52
+ sessionId: string;
53
+ startTs: number;
54
+ pageHistory?: {
55
+ url: string;
56
+ ts: number;
57
+ }[] | undefined;
58
+ }>;
59
+ export declare const ViewportContextZ: z.ZodObject<{
60
+ width: z.ZodNumber;
61
+ height: z.ZodNumber;
62
+ }, "strip", z.ZodTypeAny, {
63
+ width: number;
64
+ height: number;
65
+ }, {
66
+ width: number;
67
+ height: number;
68
+ }>;
69
+ export declare const BoundingBoxZ: z.ZodObject<{
70
+ x: z.ZodNumber;
71
+ y: z.ZodNumber;
72
+ w: z.ZodNumber;
73
+ h: z.ZodNumber;
74
+ }, "strip", z.ZodTypeAny, {
75
+ x: number;
76
+ y: number;
77
+ w: number;
78
+ h: number;
79
+ }, {
80
+ x: number;
81
+ y: number;
82
+ w: number;
83
+ h: number;
84
+ }>;
85
+ export declare const AnchorStateZ: z.ZodObject<{
86
+ anchorId: z.ZodString;
87
+ present: z.ZodBoolean;
88
+ visible: z.ZodOptional<z.ZodBoolean>;
89
+ boundingBox: z.ZodOptional<z.ZodObject<{
90
+ x: z.ZodNumber;
91
+ y: z.ZodNumber;
92
+ w: z.ZodNumber;
93
+ h: z.ZodNumber;
94
+ }, "strip", z.ZodTypeAny, {
95
+ x: number;
96
+ y: number;
97
+ w: number;
98
+ h: number;
99
+ }, {
100
+ x: number;
101
+ y: number;
102
+ w: number;
103
+ h: number;
104
+ }>>;
105
+ }, "strip", z.ZodTypeAny, {
106
+ present: boolean;
107
+ anchorId: string;
108
+ visible?: boolean | undefined;
109
+ boundingBox?: {
110
+ x: number;
111
+ y: number;
112
+ w: number;
113
+ h: number;
114
+ } | undefined;
115
+ }, {
116
+ present: boolean;
117
+ anchorId: string;
118
+ visible?: boolean | undefined;
119
+ boundingBox?: {
120
+ x: number;
121
+ y: number;
122
+ w: number;
123
+ h: number;
124
+ } | undefined;
125
+ }>;
126
+ export declare const AugmentationZ: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodUndefined]>>;
127
+ export declare const RuntimeContextZ: z.ZodObject<{
128
+ page: z.ZodObject<{
129
+ url: z.ZodString;
130
+ routeId: z.ZodOptional<z.ZodString>;
131
+ title: z.ZodOptional<z.ZodString>;
132
+ locale: z.ZodOptional<z.ZodString>;
133
+ }, "strip", z.ZodTypeAny, {
134
+ url: string;
135
+ title?: string | undefined;
136
+ routeId?: string | undefined;
137
+ locale?: string | undefined;
138
+ }, {
139
+ url: string;
140
+ title?: string | undefined;
141
+ routeId?: string | undefined;
142
+ locale?: string | undefined;
143
+ }>;
144
+ session: z.ZodObject<{
145
+ sessionId: z.ZodString;
146
+ startTs: z.ZodNumber;
147
+ pageHistory: z.ZodOptional<z.ZodArray<z.ZodObject<{
148
+ url: z.ZodString;
149
+ ts: z.ZodNumber;
150
+ }, "strip", z.ZodTypeAny, {
151
+ url: string;
152
+ ts: number;
153
+ }, {
154
+ url: string;
155
+ ts: number;
156
+ }>, "many">>;
157
+ }, "strip", z.ZodTypeAny, {
158
+ sessionId: string;
159
+ startTs: number;
160
+ pageHistory?: {
161
+ url: string;
162
+ ts: number;
163
+ }[] | undefined;
164
+ }, {
165
+ sessionId: string;
166
+ startTs: number;
167
+ pageHistory?: {
168
+ url: string;
169
+ ts: number;
170
+ }[] | undefined;
171
+ }>;
172
+ viewport: z.ZodObject<{
173
+ width: z.ZodNumber;
174
+ height: z.ZodNumber;
175
+ }, "strip", z.ZodTypeAny, {
176
+ width: number;
177
+ height: number;
178
+ }, {
179
+ width: number;
180
+ height: number;
181
+ }>;
182
+ anchors: z.ZodOptional<z.ZodArray<z.ZodObject<{
183
+ anchorId: z.ZodString;
184
+ present: z.ZodBoolean;
185
+ visible: z.ZodOptional<z.ZodBoolean>;
186
+ boundingBox: z.ZodOptional<z.ZodObject<{
187
+ x: z.ZodNumber;
188
+ y: z.ZodNumber;
189
+ w: z.ZodNumber;
190
+ h: z.ZodNumber;
191
+ }, "strip", z.ZodTypeAny, {
192
+ x: number;
193
+ y: number;
194
+ w: number;
195
+ h: number;
196
+ }, {
197
+ x: number;
198
+ y: number;
199
+ w: number;
200
+ h: number;
201
+ }>>;
202
+ }, "strip", z.ZodTypeAny, {
203
+ present: boolean;
204
+ anchorId: string;
205
+ visible?: boolean | undefined;
206
+ boundingBox?: {
207
+ x: number;
208
+ y: number;
209
+ w: number;
210
+ h: number;
211
+ } | undefined;
212
+ }, {
213
+ present: boolean;
214
+ anchorId: string;
215
+ visible?: boolean | undefined;
216
+ boundingBox?: {
217
+ x: number;
218
+ y: number;
219
+ w: number;
220
+ h: number;
221
+ } | undefined;
222
+ }>, "many">>;
223
+ augmented: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodUndefined]>>>;
224
+ }, "strip", z.ZodTypeAny, {
225
+ viewport: {
226
+ width: number;
227
+ height: number;
228
+ };
229
+ page: {
230
+ url: string;
231
+ title?: string | undefined;
232
+ routeId?: string | undefined;
233
+ locale?: string | undefined;
234
+ };
235
+ session: {
236
+ sessionId: string;
237
+ startTs: number;
238
+ pageHistory?: {
239
+ url: string;
240
+ ts: number;
241
+ }[] | undefined;
242
+ };
243
+ anchors?: {
244
+ present: boolean;
245
+ anchorId: string;
246
+ visible?: boolean | undefined;
247
+ boundingBox?: {
248
+ x: number;
249
+ y: number;
250
+ w: number;
251
+ h: number;
252
+ } | undefined;
253
+ }[] | undefined;
254
+ augmented?: Record<string, string | number | boolean | undefined> | undefined;
255
+ }, {
256
+ viewport: {
257
+ width: number;
258
+ height: number;
259
+ };
260
+ page: {
261
+ url: string;
262
+ title?: string | undefined;
263
+ routeId?: string | undefined;
264
+ locale?: string | undefined;
265
+ };
266
+ session: {
267
+ sessionId: string;
268
+ startTs: number;
269
+ pageHistory?: {
270
+ url: string;
271
+ ts: number;
272
+ }[] | undefined;
273
+ };
274
+ anchors?: {
275
+ present: boolean;
276
+ anchorId: string;
277
+ visible?: boolean | undefined;
278
+ boundingBox?: {
279
+ x: number;
280
+ y: number;
281
+ w: number;
282
+ h: number;
283
+ } | undefined;
284
+ }[] | undefined;
285
+ augmented?: Record<string, string | number | boolean | undefined> | undefined;
286
+ }>;
287
+ /**
288
+ * Validate a RuntimeContext object.
289
+ */
290
+ export declare function validateRuntimeContext(data: unknown): z.SafeParseReturnType<{
291
+ viewport: {
292
+ width: number;
293
+ height: number;
294
+ };
295
+ page: {
296
+ url: string;
297
+ title?: string | undefined;
298
+ routeId?: string | undefined;
299
+ locale?: string | undefined;
300
+ };
301
+ session: {
302
+ sessionId: string;
303
+ startTs: number;
304
+ pageHistory?: {
305
+ url: string;
306
+ ts: number;
307
+ }[] | undefined;
308
+ };
309
+ anchors?: {
310
+ present: boolean;
311
+ anchorId: string;
312
+ visible?: boolean | undefined;
313
+ boundingBox?: {
314
+ x: number;
315
+ y: number;
316
+ w: number;
317
+ h: number;
318
+ } | undefined;
319
+ }[] | undefined;
320
+ augmented?: Record<string, string | number | boolean | undefined> | undefined;
321
+ }, {
322
+ viewport: {
323
+ width: number;
324
+ height: number;
325
+ };
326
+ page: {
327
+ url: string;
328
+ title?: string | undefined;
329
+ routeId?: string | undefined;
330
+ locale?: string | undefined;
331
+ };
332
+ session: {
333
+ sessionId: string;
334
+ startTs: number;
335
+ pageHistory?: {
336
+ url: string;
337
+ ts: number;
338
+ }[] | undefined;
339
+ };
340
+ anchors?: {
341
+ present: boolean;
342
+ anchorId: string;
343
+ visible?: boolean | undefined;
344
+ boundingBox?: {
345
+ x: number;
346
+ y: number;
347
+ w: number;
348
+ h: number;
349
+ } | undefined;
350
+ }[] | undefined;
351
+ augmented?: Record<string, string | number | boolean | undefined> | undefined;
352
+ }>;
353
+ /**
354
+ * Type inference from Zod schema.
355
+ */
356
+ export type RuntimeContextSchema = z.infer<typeof RuntimeContextZ>;
357
+ export type PageContextSchema = z.infer<typeof PageContextZ>;
358
+ export type SessionContextSchema = z.infer<typeof SessionContextZ>;
359
+ export type ViewportContextSchema = z.infer<typeof ViewportContextZ>;
360
+ export type AnchorStateSchema = z.infer<typeof AnchorStateZ>;