@qontinui/ui-bridge-native 0.1.6 → 0.2.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 (94) hide show
  1. package/dist/control/{action-executor.d.ts → index.d.mts} +14 -6
  2. package/dist/control/index.d.ts +95 -5
  3. package/dist/control/index.js +74 -11
  4. package/dist/control/index.js.map +1 -1
  5. package/dist/control/index.mjs +74 -11
  6. package/dist/control/index.mjs.map +1 -1
  7. package/dist/core/index.d.mts +46 -0
  8. package/dist/core/index.d.ts +43 -6
  9. package/dist/core/index.js +69 -1
  10. package/dist/core/index.js.map +1 -1
  11. package/dist/core/index.mjs +69 -1
  12. package/dist/core/index.mjs.map +1 -1
  13. package/dist/debug/{inspector.d.ts → index.d.mts} +6 -3
  14. package/dist/debug/index.d.ts +44 -4
  15. package/dist/debug/index.js.map +1 -1
  16. package/dist/debug/index.mjs.map +1 -1
  17. package/dist/design/{design-inspector-native.d.ts → index.d.mts} +11 -7
  18. package/dist/design/index.d.ts +60 -5
  19. package/dist/{design/design-types.d.ts → design-types-BHr6Q1FX.d.mts} +11 -10
  20. package/dist/design-types-BHr6Q1FX.d.ts +205 -0
  21. package/dist/http-server-DCdR8WlL.d.mts +622 -0
  22. package/dist/http-server-Dj3grQW4.d.ts +622 -0
  23. package/dist/index.d.mts +89 -0
  24. package/dist/index.d.ts +86 -28
  25. package/dist/index.js +391 -12
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +386 -13
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/react/{useAutoRegister.d.ts → index.d.mts} +15 -7
  30. package/dist/react/index.d.ts +69 -8
  31. package/dist/react/index.js +388 -12
  32. package/dist/react/index.js.map +1 -1
  33. package/dist/react/index.mjs +386 -13
  34. package/dist/react/index.mjs.map +1 -1
  35. package/dist/registry-Cahd8Gn2.d.mts +230 -0
  36. package/dist/{core/registry.d.ts → registry-z-3WJsxp.d.ts} +28 -10
  37. package/dist/server/index.d.mts +119 -0
  38. package/dist/server/index.d.ts +117 -13
  39. package/dist/server/index.js.map +1 -1
  40. package/dist/server/index.mjs.map +1 -1
  41. package/dist/types-DAfCeWXc.d.mts +197 -0
  42. package/dist/{core/types.d.ts → types-Oz13YLZq.d.mts} +124 -30
  43. package/dist/types-Oz13YLZq.d.ts +477 -0
  44. package/dist/{control/types.d.ts → types-ajakyp-l.d.ts} +36 -15
  45. package/dist/useUIBridgeToast-D32KXyL1.d.ts +720 -0
  46. package/dist/useUIBridgeToast-GmT1TzUe.d.mts +720 -0
  47. package/package.json +1 -1
  48. package/dist/control/action-executor.d.ts.map +0 -1
  49. package/dist/control/index.d.ts.map +0 -1
  50. package/dist/control/types.d.ts.map +0 -1
  51. package/dist/core/element-identifier.d.ts +0 -41
  52. package/dist/core/element-identifier.d.ts.map +0 -1
  53. package/dist/core/index.d.ts.map +0 -1
  54. package/dist/core/registry.d.ts.map +0 -1
  55. package/dist/core/types.d.ts.map +0 -1
  56. package/dist/debug/index.d.ts.map +0 -1
  57. package/dist/debug/inspector.d.ts.map +0 -1
  58. package/dist/design/design-inspector-native.d.ts.map +0 -1
  59. package/dist/design/design-types.d.ts.map +0 -1
  60. package/dist/design/index.d.ts.map +0 -1
  61. package/dist/index.d.ts.map +0 -1
  62. package/dist/react/UIBridgeNativeProvider.d.ts +0 -147
  63. package/dist/react/UIBridgeNativeProvider.d.ts.map +0 -1
  64. package/dist/react/index.d.ts.map +0 -1
  65. package/dist/react/useAutoRegister.d.ts.map +0 -1
  66. package/dist/react/useUIBridge.d.ts +0 -103
  67. package/dist/react/useUIBridge.d.ts.map +0 -1
  68. package/dist/react/useUIComponent.d.ts +0 -112
  69. package/dist/react/useUIComponent.d.ts.map +0 -1
  70. package/dist/react/useUIElement.d.ts +0 -162
  71. package/dist/react/useUIElement.d.ts.map +0 -1
  72. package/dist/server/design-handlers.d.ts +0 -47
  73. package/dist/server/design-handlers.d.ts.map +0 -1
  74. package/dist/server/handlers.d.ts +0 -20
  75. package/dist/server/handlers.d.ts.map +0 -1
  76. package/dist/server/http-server.d.ts +0 -247
  77. package/dist/server/http-server.d.ts.map +0 -1
  78. package/dist/server/index.d.ts.map +0 -1
  79. package/dist/server/types.d.ts +0 -200
  80. package/dist/server/types.d.ts.map +0 -1
  81. package/dist/server/ws-connection.d.ts +0 -48
  82. package/dist/server/ws-connection.d.ts.map +0 -1
  83. package/dist/server/ws-event-bridge.d.ts +0 -113
  84. package/dist/server/ws-event-bridge.d.ts.map +0 -1
  85. package/dist/server/ws-protocol.d.ts +0 -48
  86. package/dist/server/ws-protocol.d.ts.map +0 -1
  87. package/dist/server/ws-types.d.ts +0 -65
  88. package/dist/server/ws-types.d.ts.map +0 -1
  89. package/dist/transport/CloudRelayClient.d.ts +0 -51
  90. package/dist/transport/CloudRelayClient.d.ts.map +0 -1
  91. package/dist/transport/DeviceAnnouncer.d.ts +0 -75
  92. package/dist/transport/DeviceAnnouncer.d.ts.map +0 -1
  93. package/dist/transport/index.d.ts +0 -3
  94. package/dist/transport/index.d.ts.map +0 -1
@@ -0,0 +1,622 @@
1
+ import { a as NativeUIBridgeRegistry } from './registry-z-3WJsxp.js';
2
+ import { c as ComponentActionResponse, e as PageNavigationResponse, N as NativeActionExecutor } from './types-ajakyp-l.js';
3
+ import { w as NativeUIBridgeConfig, d as NativeActionResponse, n as NativeFindResponse, e as NativeBridgeSnapshot } from './types-Oz13YLZq.js';
4
+ import { E as ElementDesignData, S as StateStyles, R as ResponsiveSnapshot } from './design-types-BHr6Q1FX.js';
5
+
6
+ /**
7
+ * UI Bridge Native Server Types
8
+ *
9
+ * Types for the embedded HTTP server.
10
+ */
11
+
12
+ /**
13
+ * Navigation provider for React Native apps.
14
+ *
15
+ * Apps supply this to enable programmatic navigation via the UI Bridge
16
+ * (e.g., `control/page/navigate` and `control/page/back`).
17
+ * For Expo Router: pass `router.push` and `router.back`.
18
+ */
19
+ interface NavigationProvider {
20
+ navigate: (url: string) => void;
21
+ back?: () => void;
22
+ /** Replace current route (no back-stack entry). For Expo Router: router.replace */
23
+ replace?: (url: string) => void;
24
+ /** Refresh the current route. For Expo Router: router.replace(currentPath) */
25
+ refresh?: () => void;
26
+ }
27
+ /**
28
+ * Screenshot provider for React Native apps.
29
+ *
30
+ * Apps supply this to enable screen capture via the UI Bridge
31
+ * (`control/screenshot`). For react-native-view-shot: pass a function
32
+ * that calls `captureRef` on the root view and returns base64 PNG data.
33
+ */
34
+ interface ScreenshotProvider {
35
+ /** Capture the current screen and return base64-encoded PNG data (no data: prefix). */
36
+ capture: () => Promise<{
37
+ base64: string;
38
+ width: number;
39
+ height: number;
40
+ }>;
41
+ }
42
+ /**
43
+ * Route provider for React Native apps.
44
+ *
45
+ * Apps supply this to expose the current navigation route in UI Bridge snapshots.
46
+ * For Expo Router: render a RouteTracker component inside the router context that
47
+ * calls `usePathname()` / `useSegments()` and writes the result to a module-level ref.
48
+ */
49
+ interface RouteProvider {
50
+ /** Return the current route path (e.g. "/(tabs)/runs"), or null if unknown. */
51
+ getCurrentRoute: () => string | null;
52
+ /** Return the current route segments (e.g. ["(tabs)", "runs"]), if available. */
53
+ getSegments?: () => string[];
54
+ /**
55
+ * Subscribe to route changes. Required so the UI Bridge can clear stale
56
+ * layouts on route changes with zero lag.
57
+ *
58
+ * Implementers must invoke `listener` synchronously whenever the route
59
+ * changes, passing the new route (or null if unknown). The returned function
60
+ * must unsubscribe the listener.
61
+ *
62
+ * For Expo Router: wrap your RouteTracker component in a module-level
63
+ * listener set and call each listener from within the tracker's effect.
64
+ */
65
+ subscribe: (listener: (route: string | null) => void) => () => void;
66
+ }
67
+ /**
68
+ * Server configuration
69
+ */
70
+ interface NativeServerConfig extends NativeUIBridgeConfig {
71
+ /** Enable CORS */
72
+ cors?: boolean;
73
+ /** Allowed origins for CORS */
74
+ allowedOrigins?: string[];
75
+ }
76
+ /**
77
+ * Route definition
78
+ */
79
+ interface RouteDefinition {
80
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE';
81
+ path: string;
82
+ description: string;
83
+ }
84
+ /**
85
+ * All UI Bridge Native routes
86
+ */
87
+ declare const UI_BRIDGE_NATIVE_ROUTES: Record<string, RouteDefinition>;
88
+ /**
89
+ * API response wrapper
90
+ */
91
+ interface APIResponse<T = unknown> {
92
+ success: boolean;
93
+ data?: T;
94
+ error?: string;
95
+ code?: string;
96
+ timestamp: number;
97
+ }
98
+ /**
99
+ * Handler context
100
+ */
101
+ interface HandlerContext {
102
+ params: Record<string, string>;
103
+ query: Record<string, string>;
104
+ body: unknown;
105
+ }
106
+ /**
107
+ * Handler function type
108
+ */
109
+ type HandlerFunction<T = unknown> = (context: HandlerContext) => Promise<APIResponse<T>>;
110
+ /**
111
+ * Server handlers interface
112
+ */
113
+ interface NativeServerHandlers {
114
+ getElements: HandlerFunction<{
115
+ elements: unknown[];
116
+ }>;
117
+ getElement: HandlerFunction<{
118
+ element: unknown;
119
+ }>;
120
+ getElementState: HandlerFunction<{
121
+ state: unknown;
122
+ }>;
123
+ executeAction: HandlerFunction<NativeActionResponse>;
124
+ getComponents: HandlerFunction<{
125
+ components: unknown[];
126
+ }>;
127
+ getComponent: HandlerFunction<{
128
+ component: unknown;
129
+ }>;
130
+ executeComponentAction: HandlerFunction<ComponentActionResponse>;
131
+ find: HandlerFunction<NativeFindResponse>;
132
+ getSnapshot: HandlerFunction<NativeBridgeSnapshot>;
133
+ getWorkflows: HandlerFunction<{
134
+ workflows: unknown[];
135
+ }>;
136
+ runWorkflow: HandlerFunction<{
137
+ runId: string;
138
+ status: string;
139
+ steps: Array<{
140
+ stepId: string;
141
+ type: string;
142
+ status: string;
143
+ result?: unknown;
144
+ error?: string;
145
+ durationMs: number;
146
+ }>;
147
+ totalSteps: number;
148
+ completedSteps: number;
149
+ failedSteps: number;
150
+ skippedSteps: number;
151
+ durationMs: number;
152
+ }>;
153
+ pageRefresh: HandlerFunction<PageNavigationResponse>;
154
+ pageNavigate: HandlerFunction<PageNavigationResponse>;
155
+ pageReplace: HandlerFunction<PageNavigationResponse>;
156
+ pageGoBack: HandlerFunction<PageNavigationResponse>;
157
+ pageGoForward: HandlerFunction<PageNavigationResponse>;
158
+ getScreenshot: HandlerFunction<{
159
+ screenshot: string;
160
+ width: number;
161
+ height: number;
162
+ }>;
163
+ getElementStyles: HandlerFunction<ElementDesignData>;
164
+ getElementStateStyles: HandlerFunction<{
165
+ elementId: string;
166
+ stateStyles: StateStyles[];
167
+ }>;
168
+ getDesignSnapshot: HandlerFunction<{
169
+ elements: ElementDesignData[];
170
+ timestamp: number;
171
+ }>;
172
+ getResponsiveSnapshots: HandlerFunction<ResponsiveSnapshot[]>;
173
+ runDesignAudit: HandlerFunction<unknown>;
174
+ loadStyleGuide: HandlerFunction<{
175
+ loaded: boolean;
176
+ }>;
177
+ getStyleGuide: HandlerFunction<unknown>;
178
+ clearStyleGuide: HandlerFunction<{
179
+ cleared: boolean;
180
+ }>;
181
+ evaluateQuality: HandlerFunction<unknown>;
182
+ getQualityContexts: HandlerFunction<Array<{
183
+ name: string;
184
+ description: string;
185
+ }>>;
186
+ saveBaseline: HandlerFunction<{
187
+ saved: boolean;
188
+ elementCount: number;
189
+ }>;
190
+ diffBaseline: HandlerFunction<unknown>;
191
+ getMethods: HandlerFunction<{
192
+ methods: Array<{
193
+ method: string;
194
+ httpMethods?: string[];
195
+ description?: string;
196
+ }>;
197
+ }>;
198
+ health: HandlerFunction<{
199
+ status: string;
200
+ timestamp: number;
201
+ }>;
202
+ }
203
+
204
+ /**
205
+ * WebSocket JSON-RPC message types for the UI Bridge protocol.
206
+ */
207
+ /** Standard JSON-RPC request */
208
+ interface JsonRpcRequest {
209
+ id: number | string;
210
+ method: string;
211
+ params?: Record<string, unknown>;
212
+ }
213
+ /** Batch request — execute multiple requests concurrently */
214
+ interface JsonRpcBatchRequest {
215
+ id: number | string;
216
+ batch: JsonRpcRequest[];
217
+ }
218
+ /** Subscribe to registry events */
219
+ interface JsonRpcSubscribe {
220
+ id: number | string;
221
+ method: 'subscribe';
222
+ params: {
223
+ events: string[];
224
+ /** Optional throttle in ms — batch rapid events within this window */
225
+ throttleMs?: number;
226
+ };
227
+ }
228
+ /** Unsubscribe from registry events */
229
+ interface JsonRpcUnsubscribe {
230
+ id: number | string;
231
+ method: 'unsubscribe';
232
+ params: {
233
+ events: string[];
234
+ };
235
+ }
236
+ /** Any client message */
237
+ type JsonRpcClientMessage = JsonRpcRequest | JsonRpcBatchRequest | JsonRpcSubscribe | JsonRpcUnsubscribe;
238
+ /** Standard JSON-RPC response */
239
+ interface JsonRpcResponse {
240
+ id: number | string;
241
+ result?: {
242
+ success: boolean;
243
+ data?: unknown;
244
+ error?: string;
245
+ code?: string;
246
+ timestamp?: number;
247
+ };
248
+ }
249
+ /** Batch response */
250
+ interface JsonRpcBatchResponse {
251
+ id: number | string;
252
+ results: JsonRpcResponse[];
253
+ }
254
+ /** Server-pushed event (no id — not a response to a request) */
255
+ interface JsonRpcEvent {
256
+ event: string;
257
+ data: unknown;
258
+ timestamp: number;
259
+ }
260
+ /** Any server message */
261
+ type JsonRpcServerMessage = JsonRpcResponse | JsonRpcBatchResponse | JsonRpcEvent;
262
+ /** Check if a message is a batch request */
263
+ declare function isBatchRequest(msg: unknown): msg is JsonRpcBatchRequest;
264
+ /** Check if a message is a subscribe request */
265
+ declare function isSubscribe(msg: unknown): msg is JsonRpcSubscribe;
266
+ /** Check if a message is an unsubscribe request */
267
+ declare function isUnsubscribe(msg: unknown): msg is JsonRpcUnsubscribe;
268
+
269
+ /**
270
+ * WebSocket connection wrapper for the UI Bridge server.
271
+ *
272
+ * Manages a single WebSocket connection after the HTTP upgrade handshake,
273
+ * handling frame-level I/O, heartbeat, and event subscriptions.
274
+ */
275
+
276
+ /**
277
+ * Callback for text messages received from the client.
278
+ * Returns a response string to send back, or null for no response.
279
+ */
280
+ type WebSocketMessageHandler = (connId: string, message: string) => Promise<string | null>;
281
+ declare class WebSocketConnection {
282
+ readonly id: string;
283
+ readonly subscriptions: Set<string>;
284
+ /** Heartbeat liveness flag — set false before ping, set true on pong */
285
+ alive: boolean;
286
+ private socket;
287
+ private buffer;
288
+ private fragmentBuffer;
289
+ private fragmentOpcode;
290
+ private closed;
291
+ private onMessage;
292
+ private onClose;
293
+ constructor(id: string, socket: WebSocketConnection['socket'], onMessage: WebSocketMessageHandler, onClose: (connId: string) => void);
294
+ /** Send a text message to the client. */
295
+ send(message: string): void;
296
+ /**
297
+ * Send an event if the client is subscribed to it. Subscription patterns
298
+ * may be exact event names, `*` (all), or glob patterns containing `*`
299
+ * (e.g. `element:*`, `*:stateChanged`). Exact matches and `*` are checked
300
+ * via fast Set lookups; glob patterns fall through to a regex test.
301
+ */
302
+ sendEvent(event: JsonRpcEvent): void;
303
+ private matchesSubscription;
304
+ /** Send a ping frame for heartbeat. */
305
+ ping(): void;
306
+ /** Close the connection gracefully. */
307
+ close(code?: number, reason?: string): void;
308
+ /** Forcefully destroy the connection without a close frame. */
309
+ destroy(): void;
310
+ /** Whether the connection is still open. */
311
+ get isOpen(): boolean;
312
+ private writeRaw;
313
+ private handleData;
314
+ private handleFrame;
315
+ }
316
+
317
+ /**
318
+ * Bridges NativeUIBridgeRegistry events to WebSocket clients.
319
+ *
320
+ * Subscribes to all registry event types and broadcasts them as
321
+ * JsonRpcEvent messages to connected WebSocket clients based on
322
+ * their per-connection subscription sets.
323
+ */
324
+
325
+ /** Options for the WebSocketEventBridge constructor. */
326
+ interface WebSocketEventBridgeOptions {
327
+ /** Heartbeat ping interval in ms (default 30000) */
328
+ heartbeatIntervalMs?: number;
329
+ /** Max number of events to retain in the replay history buffer (default 100, 0 disables) */
330
+ maxHistory?: number;
331
+ }
332
+ declare class WebSocketEventBridge {
333
+ private connections;
334
+ private throttles;
335
+ private unsubscribers;
336
+ private heartbeatTimer;
337
+ private registry;
338
+ private heartbeatIntervalMs;
339
+ /**
340
+ * True ring buffer for event replay history.
341
+ *
342
+ * `historyBuf` is a fixed-capacity slot array; `historyHead` points at the
343
+ * NEXT write position; `historyCount` is the number of valid slots
344
+ * (clamped to capacity). Append is O(1) — no array shifting.
345
+ */
346
+ private historyBuf;
347
+ private historyHead;
348
+ private historyCount;
349
+ constructor(registry: NativeUIBridgeRegistry, optionsOrHeartbeatMs?: WebSocketEventBridgeOptions | number);
350
+ /** Effective ring buffer capacity. 0 means history is disabled. */
351
+ private get historyCapacity();
352
+ /**
353
+ * Start listening to registry events and broadcasting to WS clients.
354
+ * Also starts the heartbeat timer.
355
+ */
356
+ start(): void;
357
+ /** Stop listening to registry events and clear connections. */
358
+ stop(): void;
359
+ /** Register a new WebSocket connection. */
360
+ addConnection(conn: WebSocketConnection): void;
361
+ /** Remove a WebSocket connection (called on disconnect). */
362
+ removeConnection(connId: string): void;
363
+ /** Get the number of active connections. */
364
+ get connectionCount(): number;
365
+ /**
366
+ * Add event subscriptions for a connection.
367
+ *
368
+ * Event names are stored as glob patterns. Supported forms:
369
+ * - Exact: "element:registered"
370
+ * - Prefix: "element:*"
371
+ * - Suffix: "*:stateChanged"
372
+ * - All: "*"
373
+ *
374
+ * @param throttleMs — if >0, batch rapid events within this window before sending
375
+ */
376
+ handleSubscribe(connId: string, events: string[], throttleMs?: number): boolean;
377
+ /**
378
+ * Remove event subscriptions for a connection.
379
+ * If all subscriptions are cleared, also drops the throttle entry
380
+ * (and any pending flush timer) so a subsequent resubscribe starts clean.
381
+ */
382
+ handleUnsubscribe(connId: string, events: string[]): boolean;
383
+ /**
384
+ * Get the subscription set for a connection.
385
+ * Returns the original pattern strings (not compiled regexes).
386
+ */
387
+ getSubscriptions(connId: string): string[];
388
+ /**
389
+ * Check if a connection is subscribed to a specific event.
390
+ * Matches exact names first (fast path), then tests each stored
391
+ * pattern as a glob against the event type.
392
+ */
393
+ isSubscribed(connId: string, eventType: string): boolean;
394
+ /** Get the throttle window (in ms) configured for a connection, or undefined if none. */
395
+ getThrottleMs(connId: string): number | undefined;
396
+ /**
397
+ * Get recent events from the replay history buffer.
398
+ *
399
+ * @param filter.events — optional list of glob patterns to match event types against
400
+ * @param filter.since — optional timestamp (ms); only events at or after this time
401
+ */
402
+ getHistory(filter?: {
403
+ events?: string[];
404
+ since?: number;
405
+ }): JsonRpcEvent[];
406
+ /**
407
+ * Configure the max history buffer size at runtime. 0 disables history.
408
+ * Reallocates the ring buffer, preserving the most recent
409
+ * min(historyCount, newCapacity) events in chronological order.
410
+ */
411
+ setMaxHistory(maxHistory: number): void;
412
+ private broadcastEvent;
413
+ /** Queue an event for throttled delivery, flushing after the throttle window. */
414
+ private enqueueThrottled;
415
+ private startHeartbeat;
416
+ }
417
+
418
+ /**
419
+ * UI Bridge Native HTTP Server
420
+ *
421
+ * Abstract HTTP server implementation for React Native.
422
+ * This provides a framework-agnostic server interface that can be
423
+ * implemented using various React Native HTTP server libraries.
424
+ *
425
+ * Supported libraries:
426
+ * - react-native-http-bridge (recommended)
427
+ * - @aspect/react-native-http-server
428
+ * - Custom implementations
429
+ */
430
+
431
+ /**
432
+ * HTTP Request interface (library-agnostic)
433
+ */
434
+ interface HTTPRequest {
435
+ method: string;
436
+ path: string;
437
+ headers: Record<string, string>;
438
+ query: Record<string, string>;
439
+ body?: unknown;
440
+ }
441
+ /**
442
+ * HTTP Response interface (library-agnostic)
443
+ */
444
+ interface HTTPResponse {
445
+ status: number;
446
+ headers: Record<string, string>;
447
+ body: string;
448
+ }
449
+ /**
450
+ * Request handler type
451
+ */
452
+ type RequestHandler = (request: HTTPRequest) => Promise<HTTPResponse>;
453
+ /**
454
+ * Server adapter interface
455
+ *
456
+ * Implement this interface to integrate with your chosen HTTP server library.
457
+ */
458
+ interface ServerAdapter {
459
+ /** Start the server */
460
+ start(port: number, handler: RequestHandler): Promise<void>;
461
+ /** Stop the server */
462
+ stop(): Promise<void>;
463
+ /** Check if server is running */
464
+ isRunning(): boolean;
465
+ }
466
+ /**
467
+ * WebSocket-aware server adapter interface.
468
+ *
469
+ * Extends ServerAdapter with callbacks for WebSocket connections.
470
+ * The adapter manages the raw TCP/WS layer; these callbacks let the
471
+ * UI Bridge server handle message routing and event broadcasting.
472
+ */
473
+ interface WebSocketServerAdapter extends ServerAdapter {
474
+ /** Called when a JSON text frame is received from a WS client. Returns response string or null. */
475
+ onWebSocketMessage?: (connId: string, message: string) => Promise<string | null>;
476
+ /** Called when a new WS connection is established after the HTTP 101 upgrade. */
477
+ onWebSocketConnect?: (connId: string) => void;
478
+ /** Called when a WS connection is closed or drops. */
479
+ onWebSocketDisconnect?: (connId: string) => void;
480
+ /** Send a message to a specific WS connection by ID. */
481
+ sendToConnection?: (connId: string, message: string) => void;
482
+ /** Send a message to all connected WS clients. */
483
+ broadcast?: (message: string) => void;
484
+ }
485
+ /**
486
+ * Native UI Bridge HTTP Server
487
+ */
488
+ declare class NativeUIBridgeServer {
489
+ private registry;
490
+ private executor;
491
+ private config;
492
+ private handlers;
493
+ private adapter?;
494
+ private running;
495
+ /**
496
+ * Per-connection cleanup thunks for in-flight waiters (waitForElement,
497
+ * waitForCondition, ...). Aborted when a client disconnects so the
498
+ * underlying timers/listeners don't leak.
499
+ */
500
+ private pendingWaiters;
501
+ constructor(registry: NativeUIBridgeRegistry, executor: NativeActionExecutor, config?: NativeServerConfig);
502
+ /**
503
+ * Set the server adapter
504
+ */
505
+ setAdapter(adapter: ServerAdapter): void;
506
+ /**
507
+ * Set a navigation provider for programmatic route navigation.
508
+ * This enables `control/page/navigate` and `control/page/back` on native.
509
+ */
510
+ setNavigationProvider(provider: NavigationProvider): void;
511
+ /**
512
+ * Set a route provider for reporting the current navigation route.
513
+ * When set, `control/snapshot` responses include `currentRoute` and `segments`.
514
+ */
515
+ setRouteProvider(provider: RouteProvider): void;
516
+ /**
517
+ * Set a screenshot provider for native screen capture.
518
+ * This enables `control/screenshot` on native.
519
+ */
520
+ setScreenshotProvider(provider: ScreenshotProvider): void;
521
+ /**
522
+ * Start the HTTP server
523
+ */
524
+ start(): Promise<void>;
525
+ /**
526
+ * Stop the HTTP server
527
+ */
528
+ stop(): Promise<void>;
529
+ /**
530
+ * Check if server is running
531
+ */
532
+ isRunning(): boolean;
533
+ private eventBridge?;
534
+ /**
535
+ * Set the event bridge for WebSocket event broadcasting and subscriptions.
536
+ */
537
+ setEventBridge(bridge: WebSocketEventBridge): void;
538
+ /**
539
+ * Handle a JSON-RPC message from a WebSocket client.
540
+ * Parses the message, routes to the appropriate handler, and returns
541
+ * a JSON string response (or null for events that need no response).
542
+ */
543
+ handleWebSocketMessage(connId: string, rawMessage: string): Promise<string | null>;
544
+ /**
545
+ * Execute a batch of JSON-RPC requests concurrently.
546
+ */
547
+ handleBatchRequest(batch: JsonRpcRequest[]): Promise<JsonRpcResponse[]>;
548
+ /**
549
+ * Register an in-flight waiter's cleanup thunk under the given connection.
550
+ * Returns an `unregister` thunk that the natural-resolution path should
551
+ * call so the cleanup isn't re-invoked on disconnect.
552
+ */
553
+ private registerWaiter;
554
+ /**
555
+ * Abort all pending waiters associated with a connection. Called by the
556
+ * provider's WS disconnect handler so timers/listeners don't leak after
557
+ * the client goes away.
558
+ */
559
+ abortWaitersForConnection(connId: string): void;
560
+ /**
561
+ * Wait for an element to be registered, or resolve immediately if it already exists.
562
+ * Returns a JsonRpcResponse JSON string.
563
+ */
564
+ private handleWaitForElement;
565
+ /**
566
+ * Wait for an arbitrary element-state predicate to become true.
567
+ *
568
+ * Supported `condition` shapes:
569
+ * {field: "mounted"|"visible"|"enabled"|"focused", equals: boolean}
570
+ * {field: "layout", exists: true}
571
+ * {field: string, equals: unknown} // generic: state[field] === equals
572
+ *
573
+ * Resolves immediately with `waited:false` if the predicate already
574
+ * holds. Otherwise subscribes to `element:registered` and
575
+ * `element:stateChanged` until the predicate matches or timeout fires.
576
+ */
577
+ private handleWaitForCondition;
578
+ /**
579
+ * Execute a sequence of JSON-RPC steps in order, stopping on first failure.
580
+ * Returns a JsonRpcResponse JSON string with per-step results.
581
+ */
582
+ private handleSequence;
583
+ /**
584
+ * Route a JSON-RPC method string to the appropriate handler using path-style matching.
585
+ *
586
+ * Method strings mirror HTTP routes but without the /ui-bridge/ prefix.
587
+ * Path params are extracted from :name placeholders in the route pattern.
588
+ *
589
+ * Examples:
590
+ * "health" → handlers.health
591
+ * "control/snapshot" → handlers.getSnapshot
592
+ * "control/element/tab-runs/action" → handlers.executeAction ({id:'tab-runs'})
593
+ * "control/component/my-comp/action/submit" → handlers.executeComponentAction
594
+ */
595
+ private routeMethodToHandler;
596
+ /**
597
+ * Handle incoming HTTP request
598
+ *
599
+ * Exposed as public so that CloudRelayClient can call it directly (without
600
+ * loopback TCP overhead) when processing tunneled requests.
601
+ */
602
+ handleRequest(request: HTTPRequest): Promise<HTTPResponse>;
603
+ /**
604
+ * Route an HTTP request to the appropriate handler using WS_ROUTES.
605
+ *
606
+ * Strips the `/ui-bridge/` prefix from the path, then iterates the shared
607
+ * WS_ROUTES table. Each route's `pattern` is matched against the stripped
608
+ * path via the module-level `parsePath` helper; path params are merged
609
+ * with the request body into a HandlerContext.
610
+ *
611
+ * `httpMethods` disambiguates routes that share a pattern but differ
612
+ * by verb (e.g. GET vs DELETE on `design/style-guide`). A route without
613
+ * `httpMethods` is WS-only and will not be matched on HTTP.
614
+ */
615
+ private routeRequest;
616
+ }
617
+ /**
618
+ * Create a UI Bridge Native server
619
+ */
620
+ declare function createNativeServer(registry: NativeUIBridgeRegistry, executor: NativeActionExecutor, config?: NativeServerConfig): NativeUIBridgeServer;
621
+
622
+ export { type APIResponse as A, type HTTPRequest as H, type JsonRpcBatchRequest as J, type NativeServerConfig as N, type RequestHandler as R, type ScreenshotProvider as S, UI_BRIDGE_NATIVE_ROUTES as U, WebSocketConnection as W, type HTTPResponse as a, type HandlerContext as b, type HandlerFunction as c, type JsonRpcBatchResponse as d, type JsonRpcEvent as e, type JsonRpcRequest as f, type JsonRpcResponse as g, type NativeServerHandlers as h, NativeUIBridgeServer as i, type NavigationProvider as j, type RouteDefinition as k, type RouteProvider as l, type ServerAdapter as m, WebSocketEventBridge as n, type WebSocketMessageHandler as o, type WebSocketServerAdapter as p, createNativeServer as q, type JsonRpcClientMessage as r, type JsonRpcServerMessage as s, type JsonRpcSubscribe as t, type JsonRpcUnsubscribe as u, isBatchRequest as v, isSubscribe as w, isUnsubscribe as x };