@qontinui/ui-bridge-native 0.3.2 → 0.4.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 (108) hide show
  1. package/dist/control/{index.d.mts → action-executor.d.ts} +6 -10
  2. package/dist/control/action-executor.d.ts.map +1 -0
  3. package/dist/control/index.d.ts +5 -95
  4. package/dist/control/index.d.ts.map +1 -0
  5. package/dist/{types-CjEKTDYT.d.ts → control/types.d.ts} +17 -20
  6. package/dist/control/types.d.ts.map +1 -0
  7. package/dist/core/element-identifier.d.ts +41 -0
  8. package/dist/core/element-identifier.d.ts.map +1 -0
  9. package/dist/core/index.d.ts +6 -43
  10. package/dist/core/index.d.ts.map +1 -0
  11. package/dist/{registry-pAUpQq2O.d.ts → core/registry.d.ts} +10 -13
  12. package/dist/core/registry.d.ts.map +1 -0
  13. package/dist/{types-CGVut7mc.d.mts → core/types.d.ts} +41 -41
  14. package/dist/core/types.d.ts.map +1 -0
  15. package/dist/debug/index.d.ts +4 -44
  16. package/dist/debug/index.d.ts.map +1 -0
  17. package/dist/debug/index.js +1 -1
  18. package/dist/debug/index.js.map +1 -1
  19. package/dist/debug/index.mjs +2 -2
  20. package/dist/debug/index.mjs.map +1 -1
  21. package/dist/debug/{index.d.mts → inspector.d.ts} +3 -6
  22. package/dist/debug/inspector.d.ts.map +1 -0
  23. package/dist/design/{index.d.mts → design-inspector-native.d.ts} +7 -11
  24. package/dist/design/design-inspector-native.d.ts.map +1 -0
  25. package/dist/{design-types-BHr6Q1FX.d.mts → design/design-types.d.ts} +10 -11
  26. package/dist/design/design-types.d.ts.map +1 -0
  27. package/dist/design/index.d.ts +5 -60
  28. package/dist/design/index.d.ts.map +1 -0
  29. package/dist/index.d.ts +37 -86
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +3 -3
  32. package/dist/index.js.map +1 -1
  33. package/dist/index.mjs +4 -4
  34. package/dist/index.mjs.map +1 -1
  35. package/dist/modal/index.d.ts +2 -0
  36. package/dist/modal/index.d.ts.map +1 -0
  37. package/dist/modal/modal-detector.d.ts +29 -0
  38. package/dist/modal/modal-detector.d.ts.map +1 -0
  39. package/dist/react/StateAnnotation.d.ts +30 -0
  40. package/dist/react/StateAnnotation.d.ts.map +1 -0
  41. package/dist/react/UIBridgeNativeProvider.d.ts +156 -0
  42. package/dist/react/UIBridgeNativeProvider.d.ts.map +1 -0
  43. package/dist/react/index.d.ts +14 -69
  44. package/dist/react/index.d.ts.map +1 -0
  45. package/dist/react/index.js +3 -3
  46. package/dist/react/index.js.map +1 -1
  47. package/dist/react/index.mjs +4 -4
  48. package/dist/react/index.mjs.map +1 -1
  49. package/dist/react/{index.d.mts → useAutoRegister.d.ts} +7 -15
  50. package/dist/react/useAutoRegister.d.ts.map +1 -0
  51. package/dist/react/useUIBridge.d.ts +103 -0
  52. package/dist/react/useUIBridge.d.ts.map +1 -0
  53. package/dist/react/useUIBridgeModal.d.ts +14 -0
  54. package/dist/react/useUIBridgeModal.d.ts.map +1 -0
  55. package/dist/react/useUIBridgeToast.d.ts +25 -0
  56. package/dist/react/useUIBridgeToast.d.ts.map +1 -0
  57. package/dist/react/useUIComponent.d.ts +112 -0
  58. package/dist/react/useUIComponent.d.ts.map +1 -0
  59. package/dist/react/useUIElement.d.ts +162 -0
  60. package/dist/react/useUIElement.d.ts.map +1 -0
  61. package/dist/server/design-handlers.d.ts +47 -0
  62. package/dist/server/design-handlers.d.ts.map +1 -0
  63. package/dist/server/handlers.d.ts +25 -0
  64. package/dist/server/handlers.d.ts.map +1 -0
  65. package/dist/server/http-server.d.ts +262 -0
  66. package/dist/server/http-server.d.ts.map +1 -0
  67. package/dist/server/index.d.ts +14 -176
  68. package/dist/server/index.d.ts.map +1 -0
  69. package/dist/server/observability.d.ts +55 -0
  70. package/dist/server/observability.d.ts.map +1 -0
  71. package/dist/server/types.d.ts +368 -0
  72. package/dist/server/types.d.ts.map +1 -0
  73. package/dist/server/ws-connection.d.ts +48 -0
  74. package/dist/server/ws-connection.d.ts.map +1 -0
  75. package/dist/server/ws-event-bridge.d.ts +113 -0
  76. package/dist/server/ws-event-bridge.d.ts.map +1 -0
  77. package/dist/server/ws-protocol.d.ts +48 -0
  78. package/dist/server/ws-protocol.d.ts.map +1 -0
  79. package/dist/server/ws-types.d.ts +65 -0
  80. package/dist/server/ws-types.d.ts.map +1 -0
  81. package/dist/toast/index.d.ts +2 -0
  82. package/dist/toast/index.d.ts.map +1 -0
  83. package/dist/toast/toast-capture.d.ts +27 -0
  84. package/dist/toast/toast-capture.d.ts.map +1 -0
  85. package/dist/transport/CloudRelayClient.d.ts +51 -0
  86. package/dist/transport/CloudRelayClient.d.ts.map +1 -0
  87. package/dist/transport/DeviceAnnouncer.d.ts +75 -0
  88. package/dist/transport/DeviceAnnouncer.d.ts.map +1 -0
  89. package/dist/transport/index.d.ts +3 -0
  90. package/dist/transport/index.d.ts.map +1 -0
  91. package/dist/transport/logger.d.ts +23 -0
  92. package/dist/transport/logger.d.ts.map +1 -0
  93. package/dist/undo/index.d.ts +3 -0
  94. package/dist/undo/index.d.ts.map +1 -0
  95. package/dist/undo/undo-tracker.d.ts +59 -0
  96. package/dist/undo/undo-tracker.d.ts.map +1 -0
  97. package/package.json +3 -3
  98. package/dist/StateAnnotation--zm0Jfqj.d.ts +0 -755
  99. package/dist/StateAnnotation-BgFoVWFy.d.mts +0 -755
  100. package/dist/core/index.d.mts +0 -46
  101. package/dist/design-types-BHr6Q1FX.d.ts +0 -205
  102. package/dist/http-server--550eD1F.d.mts +0 -805
  103. package/dist/http-server-C9NaNBEP.d.ts +0 -805
  104. package/dist/index.d.mts +0 -89
  105. package/dist/registry-B5JadBN9.d.mts +0 -300
  106. package/dist/server/index.d.mts +0 -178
  107. package/dist/types-B0XA4vOF.d.mts +0 -197
  108. package/dist/types-CGVut7mc.d.ts +0 -567
@@ -1,805 +0,0 @@
1
- import { a as NativeUIBridgeRegistry } from './registry-pAUpQq2O.js';
2
- import { c as ComponentActionResponse, e as PageNavigationResponse, N as NativeActionExecutor } from './types-CjEKTDYT.js';
3
- import { x as NativeUIBridgeConfig, d as NativeActionResponse, n as NativeFindResponse, e as NativeBridgeSnapshot } from './types-CGVut7mc.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
- * Enable test-only HTTP endpoints (currently `control/modal/push` and
77
- * `control/modal/dismiss/:id`) so external runners can drive registry
78
- * state. Default `false`; the React provider mirrors
79
- * `features.testHooks` into this slot.
80
- */
81
- testHooks?: boolean;
82
- }
83
- /**
84
- * Route definition
85
- */
86
- interface RouteDefinition {
87
- method: 'GET' | 'POST' | 'PUT' | 'DELETE';
88
- path: string;
89
- description: string;
90
- }
91
- /**
92
- * All UI Bridge Native routes
93
- */
94
- declare const UI_BRIDGE_NATIVE_ROUTES: Record<string, RouteDefinition>;
95
- /**
96
- * Request body for `POST /ai/fill-form`.
97
- *
98
- * The mobile native bridge has no `setValue` action — text inputs are driven
99
- * via the `type` action (which calls `onChangeText`). The fillForm handler
100
- * dispatches each field as `executor.executeAction(elementId, { action: 'type',
101
- * params: { text: value, clear: true } })` so existing values are atomically
102
- * replaced (matching the web bridge's "setValue" semantics).
103
- *
104
- * Shape mirrors the runner's `POST /ui-bridge/ai/fill-form` documented in
105
- * docs-site/api/runner-features.md (array-of-pairs form), so callers can use
106
- * the same JSON across mobile and web/runner without special-casing.
107
- */
108
- interface FillFormFieldInput {
109
- /** Target element id (registered id, testID, accessibilityLabel, etc.) */
110
- elementId: string;
111
- /** Text value to write into the input. */
112
- value: string;
113
- }
114
- interface FillFormRequest {
115
- fields: FillFormFieldInput[];
116
- }
117
- /**
118
- * Per-field outcome returned by `POST /ai/fill-form`.
119
- */
120
- interface FillFormFieldResult {
121
- /** Element id from the request, echoed back. */
122
- elementId: string;
123
- /** Whether `executor.executeAction` reported success for this field. */
124
- success: boolean;
125
- /** Error message when `success === false`. Omitted on success. */
126
- error?: string;
127
- }
128
- /**
129
- * Response payload returned in `APIResponse.data` for `POST /ai/fill-form`.
130
- */
131
- interface FillFormResponse {
132
- results: FillFormFieldResult[];
133
- succeededCount: number;
134
- failedCount: number;
135
- }
136
- /**
137
- * Request body for `POST /control/tap` — synthesize a press at given screen
138
- * coordinates by searching registered elements whose layout rect contains the
139
- * point.
140
- *
141
- * The handler picks the topmost (smallest-area) match — usually the innermost
142
- * child — then dispatches the requested action via the standard executor.
143
- * `action` defaults to `'press'`.
144
- */
145
- interface TapAtRequest {
146
- x: number;
147
- y: number;
148
- action?: 'press' | 'longPress' | 'doubleTap';
149
- }
150
- /**
151
- * Response payload returned in `APIResponse.data` for `POST /control/tap`.
152
- */
153
- interface TapAtResponse {
154
- /** Element id whose rect contained the tap coords. */
155
- elementId: string;
156
- /** Action that was dispatched. */
157
- action: 'press' | 'longPress' | 'doubleTap';
158
- /** The element's layout rect at dispatch time (best-effort). */
159
- layout: {
160
- x: number;
161
- y: number;
162
- width: number;
163
- height: number;
164
- pageX?: number;
165
- pageY?: number;
166
- } | null;
167
- }
168
- /**
169
- * Single console error/warn entry captured by the observability ring buffer.
170
- * Returned by `GET /control/console-errors`.
171
- */
172
- interface ConsoleErrorEntry {
173
- /** ms since epoch when the entry was captured. */
174
- timestamp: number;
175
- /** `'error'` or `'warn'`. */
176
- level: 'error' | 'warn';
177
- /** Joined message string (matches what console would have printed). */
178
- message: string;
179
- /** Captured stack trace if any of the args was an Error. */
180
- stack?: string;
181
- }
182
- /**
183
- * Response payload for `GET /control/console-errors`.
184
- */
185
- interface ConsoleErrorsResponse {
186
- entries: ConsoleErrorEntry[];
187
- /** Number of entries returned (post `since`/`limit` filtering). */
188
- count: number;
189
- /** Total entries currently held in the ring buffer (pre-filter). */
190
- bufferSize: number;
191
- }
192
- /**
193
- * Single network request entry captured by the observability ring buffer.
194
- * Returned by `GET /sdk/network-requests`.
195
- */
196
- interface NetworkRequestEntry {
197
- /** ms since epoch at request start. */
198
- timestamp: number;
199
- /** HTTP method (uppercased). */
200
- method: string;
201
- /** Resolved request URL. */
202
- url: string;
203
- /** HTTP status code, or 0 if the request errored before a response. */
204
- status: number;
205
- /** Wall-clock duration in ms from start to settlement. */
206
- durationMs: number;
207
- /** Whether the request settled with a 2xx response. */
208
- ok: boolean;
209
- /** Error message when the request rejected before a response. */
210
- error?: string;
211
- }
212
- /**
213
- * Response payload for `GET /sdk/network-requests`.
214
- */
215
- interface NetworkRequestsResponse {
216
- entries: NetworkRequestEntry[];
217
- count: number;
218
- bufferSize: number;
219
- }
220
- /**
221
- * Request body for `POST /control/modal/push`.
222
- *
223
- * Mirrors `ModalDetector.pushModal`'s `ModalPushInput` shape; `metadata` is
224
- * a free-form object the test runner can stash for later assertions but is
225
- * not currently surfaced in the snapshot.
226
- */
227
- interface PushModalRequest {
228
- id: string;
229
- title?: string;
230
- type?: string;
231
- blocking?: boolean;
232
- dismissible?: boolean;
233
- metadata?: Record<string, unknown>;
234
- }
235
- /**
236
- * Response payload for `POST /control/modal/push`.
237
- */
238
- interface PushModalResponse {
239
- pushed: boolean;
240
- id: string;
241
- title?: string;
242
- type?: string;
243
- blocking?: boolean;
244
- dismissible?: boolean;
245
- pushedAt: number;
246
- }
247
- /**
248
- * Response payload for `POST /control/modal/dismiss/:id`.
249
- */
250
- interface DismissModalResponse {
251
- dismissed: string;
252
- }
253
- /**
254
- * API response wrapper
255
- */
256
- interface APIResponse<T = unknown> {
257
- success: boolean;
258
- data?: T;
259
- error?: string;
260
- code?: string;
261
- timestamp: number;
262
- }
263
- /**
264
- * Handler context
265
- */
266
- interface HandlerContext {
267
- params: Record<string, string>;
268
- query: Record<string, string>;
269
- body: unknown;
270
- }
271
- /**
272
- * Handler function type
273
- */
274
- type HandlerFunction<T = unknown> = (context: HandlerContext) => Promise<APIResponse<T>>;
275
- /**
276
- * Server handlers interface
277
- */
278
- interface NativeServerHandlers {
279
- getElements: HandlerFunction<{
280
- elements: unknown[];
281
- }>;
282
- getElement: HandlerFunction<{
283
- element: unknown;
284
- }>;
285
- getElementState: HandlerFunction<{
286
- state: unknown;
287
- }>;
288
- executeAction: HandlerFunction<NativeActionResponse>;
289
- getComponents: HandlerFunction<{
290
- components: unknown[];
291
- }>;
292
- getComponent: HandlerFunction<{
293
- component: unknown;
294
- }>;
295
- executeComponentAction: HandlerFunction<ComponentActionResponse>;
296
- find: HandlerFunction<NativeFindResponse>;
297
- getSnapshot: HandlerFunction<NativeBridgeSnapshot>;
298
- getWorkflows: HandlerFunction<{
299
- workflows: unknown[];
300
- }>;
301
- runWorkflow: HandlerFunction<{
302
- runId: string;
303
- status: string;
304
- steps: Array<{
305
- stepId: string;
306
- type: string;
307
- status: string;
308
- result?: unknown;
309
- error?: string;
310
- durationMs: number;
311
- }>;
312
- totalSteps: number;
313
- completedSteps: number;
314
- failedSteps: number;
315
- skippedSteps: number;
316
- durationMs: number;
317
- }>;
318
- pageRefresh: HandlerFunction<PageNavigationResponse>;
319
- pageNavigate: HandlerFunction<PageNavigationResponse>;
320
- pageReplace: HandlerFunction<PageNavigationResponse>;
321
- pageGoBack: HandlerFunction<PageNavigationResponse>;
322
- pageGoForward: HandlerFunction<PageNavigationResponse>;
323
- getScreenshot: HandlerFunction<{
324
- screenshot: string;
325
- width: number;
326
- height: number;
327
- }>;
328
- getElementStyles: HandlerFunction<ElementDesignData>;
329
- getElementStateStyles: HandlerFunction<{
330
- elementId: string;
331
- stateStyles: StateStyles[];
332
- }>;
333
- getDesignSnapshot: HandlerFunction<{
334
- elements: ElementDesignData[];
335
- timestamp: number;
336
- }>;
337
- getResponsiveSnapshots: HandlerFunction<ResponsiveSnapshot[]>;
338
- runDesignAudit: HandlerFunction<unknown>;
339
- loadStyleGuide: HandlerFunction<{
340
- loaded: boolean;
341
- }>;
342
- getStyleGuide: HandlerFunction<unknown>;
343
- clearStyleGuide: HandlerFunction<{
344
- cleared: boolean;
345
- }>;
346
- evaluateQuality: HandlerFunction<unknown>;
347
- getQualityContexts: HandlerFunction<Array<{
348
- name: string;
349
- description: string;
350
- }>>;
351
- saveBaseline: HandlerFunction<{
352
- saved: boolean;
353
- elementCount: number;
354
- }>;
355
- diffBaseline: HandlerFunction<unknown>;
356
- getMethods: HandlerFunction<{
357
- methods: Array<{
358
- method: string;
359
- httpMethods?: string[];
360
- description?: string;
361
- }>;
362
- }>;
363
- fillForm: HandlerFunction<FillFormResponse>;
364
- tapAt: HandlerFunction<TapAtResponse>;
365
- getConsoleErrors: HandlerFunction<ConsoleErrorsResponse>;
366
- getNetworkRequests: HandlerFunction<NetworkRequestsResponse>;
367
- pushModal: HandlerFunction<PushModalResponse>;
368
- dismissModal: HandlerFunction<DismissModalResponse>;
369
- health: HandlerFunction<Record<string, unknown>>;
370
- }
371
-
372
- /**
373
- * WebSocket JSON-RPC message types for the UI Bridge protocol.
374
- */
375
- /** Standard JSON-RPC request */
376
- interface JsonRpcRequest {
377
- id: number | string;
378
- method: string;
379
- params?: Record<string, unknown>;
380
- }
381
- /** Batch request — execute multiple requests concurrently */
382
- interface JsonRpcBatchRequest {
383
- id: number | string;
384
- batch: JsonRpcRequest[];
385
- }
386
- /** Subscribe to registry events */
387
- interface JsonRpcSubscribe {
388
- id: number | string;
389
- method: 'subscribe';
390
- params: {
391
- events: string[];
392
- /** Optional throttle in ms — batch rapid events within this window */
393
- throttleMs?: number;
394
- };
395
- }
396
- /** Unsubscribe from registry events */
397
- interface JsonRpcUnsubscribe {
398
- id: number | string;
399
- method: 'unsubscribe';
400
- params: {
401
- events: string[];
402
- };
403
- }
404
- /** Any client message */
405
- type JsonRpcClientMessage = JsonRpcRequest | JsonRpcBatchRequest | JsonRpcSubscribe | JsonRpcUnsubscribe;
406
- /** Standard JSON-RPC response */
407
- interface JsonRpcResponse {
408
- id: number | string;
409
- result?: {
410
- success: boolean;
411
- data?: unknown;
412
- error?: string;
413
- code?: string;
414
- timestamp?: number;
415
- };
416
- }
417
- /** Batch response */
418
- interface JsonRpcBatchResponse {
419
- id: number | string;
420
- results: JsonRpcResponse[];
421
- }
422
- /** Server-pushed event (no id — not a response to a request) */
423
- interface JsonRpcEvent {
424
- event: string;
425
- data: unknown;
426
- timestamp: number;
427
- }
428
- /** Any server message */
429
- type JsonRpcServerMessage = JsonRpcResponse | JsonRpcBatchResponse | JsonRpcEvent;
430
- /** Check if a message is a batch request */
431
- declare function isBatchRequest(msg: unknown): msg is JsonRpcBatchRequest;
432
- /** Check if a message is a subscribe request */
433
- declare function isSubscribe(msg: unknown): msg is JsonRpcSubscribe;
434
- /** Check if a message is an unsubscribe request */
435
- declare function isUnsubscribe(msg: unknown): msg is JsonRpcUnsubscribe;
436
-
437
- /**
438
- * WebSocket connection wrapper for the UI Bridge server.
439
- *
440
- * Manages a single WebSocket connection after the HTTP upgrade handshake,
441
- * handling frame-level I/O, heartbeat, and event subscriptions.
442
- */
443
-
444
- /**
445
- * Callback for text messages received from the client.
446
- * Returns a response string to send back, or null for no response.
447
- */
448
- type WebSocketMessageHandler = (connId: string, message: string) => Promise<string | null>;
449
- declare class WebSocketConnection {
450
- readonly id: string;
451
- readonly subscriptions: Set<string>;
452
- /** Heartbeat liveness flag — set false before ping, set true on pong */
453
- alive: boolean;
454
- private socket;
455
- private buffer;
456
- private fragmentBuffer;
457
- private fragmentOpcode;
458
- private closed;
459
- private onMessage;
460
- private onClose;
461
- constructor(id: string, socket: WebSocketConnection['socket'], onMessage: WebSocketMessageHandler, onClose: (connId: string) => void);
462
- /** Send a text message to the client. */
463
- send(message: string): void;
464
- /**
465
- * Send an event if the client is subscribed to it. Subscription patterns
466
- * may be exact event names, `*` (all), or glob patterns containing `*`
467
- * (e.g. `element:*`, `*:stateChanged`). Exact matches and `*` are checked
468
- * via fast Set lookups; glob patterns fall through to a regex test.
469
- */
470
- sendEvent(event: JsonRpcEvent): void;
471
- private matchesSubscription;
472
- /** Send a ping frame for heartbeat. */
473
- ping(): void;
474
- /** Close the connection gracefully. */
475
- close(code?: number, reason?: string): void;
476
- /** Forcefully destroy the connection without a close frame. */
477
- destroy(): void;
478
- /** Whether the connection is still open. */
479
- get isOpen(): boolean;
480
- private writeRaw;
481
- private handleData;
482
- private handleFrame;
483
- }
484
-
485
- /**
486
- * Bridges NativeUIBridgeRegistry events to WebSocket clients.
487
- *
488
- * Subscribes to all registry event types and broadcasts them as
489
- * JsonRpcEvent messages to connected WebSocket clients based on
490
- * their per-connection subscription sets.
491
- */
492
-
493
- /** Options for the WebSocketEventBridge constructor. */
494
- interface WebSocketEventBridgeOptions {
495
- /** Heartbeat ping interval in ms (default 30000) */
496
- heartbeatIntervalMs?: number;
497
- /** Max number of events to retain in the replay history buffer (default 100, 0 disables) */
498
- maxHistory?: number;
499
- }
500
- declare class WebSocketEventBridge {
501
- private connections;
502
- private throttles;
503
- private unsubscribers;
504
- private heartbeatTimer;
505
- private registry;
506
- private heartbeatIntervalMs;
507
- /**
508
- * True ring buffer for event replay history.
509
- *
510
- * `historyBuf` is a fixed-capacity slot array; `historyHead` points at the
511
- * NEXT write position; `historyCount` is the number of valid slots
512
- * (clamped to capacity). Append is O(1) — no array shifting.
513
- */
514
- private historyBuf;
515
- private historyHead;
516
- private historyCount;
517
- constructor(registry: NativeUIBridgeRegistry, optionsOrHeartbeatMs?: WebSocketEventBridgeOptions | number);
518
- /** Effective ring buffer capacity. 0 means history is disabled. */
519
- private get historyCapacity();
520
- /**
521
- * Start listening to registry events and broadcasting to WS clients.
522
- * Also starts the heartbeat timer.
523
- */
524
- start(): void;
525
- /** Stop listening to registry events and clear connections. */
526
- stop(): void;
527
- /** Register a new WebSocket connection. */
528
- addConnection(conn: WebSocketConnection): void;
529
- /** Remove a WebSocket connection (called on disconnect). */
530
- removeConnection(connId: string): void;
531
- /** Get the number of active connections. */
532
- get connectionCount(): number;
533
- /**
534
- * Add event subscriptions for a connection.
535
- *
536
- * Event names are stored as glob patterns. Supported forms:
537
- * - Exact: "element:registered"
538
- * - Prefix: "element:*"
539
- * - Suffix: "*:stateChanged"
540
- * - All: "*"
541
- *
542
- * @param throttleMs — if >0, batch rapid events within this window before sending
543
- */
544
- handleSubscribe(connId: string, events: string[], throttleMs?: number): boolean;
545
- /**
546
- * Remove event subscriptions for a connection.
547
- * If all subscriptions are cleared, also drops the throttle entry
548
- * (and any pending flush timer) so a subsequent resubscribe starts clean.
549
- */
550
- handleUnsubscribe(connId: string, events: string[]): boolean;
551
- /**
552
- * Get the subscription set for a connection.
553
- * Returns the original pattern strings (not compiled regexes).
554
- */
555
- getSubscriptions(connId: string): string[];
556
- /**
557
- * Check if a connection is subscribed to a specific event.
558
- * Matches exact names first (fast path), then tests each stored
559
- * pattern as a glob against the event type.
560
- */
561
- isSubscribed(connId: string, eventType: string): boolean;
562
- /** Get the throttle window (in ms) configured for a connection, or undefined if none. */
563
- getThrottleMs(connId: string): number | undefined;
564
- /**
565
- * Get recent events from the replay history buffer.
566
- *
567
- * @param filter.events — optional list of glob patterns to match event types against
568
- * @param filter.since — optional timestamp (ms); only events at or after this time
569
- */
570
- getHistory(filter?: {
571
- events?: string[];
572
- since?: number;
573
- }): JsonRpcEvent[];
574
- /**
575
- * Configure the max history buffer size at runtime. 0 disables history.
576
- * Reallocates the ring buffer, preserving the most recent
577
- * min(historyCount, newCapacity) events in chronological order.
578
- */
579
- setMaxHistory(maxHistory: number): void;
580
- private broadcastEvent;
581
- /** Queue an event for throttled delivery, flushing after the throttle window. */
582
- private enqueueThrottled;
583
- private startHeartbeat;
584
- }
585
-
586
- /**
587
- * UI Bridge Native HTTP Server
588
- *
589
- * Abstract HTTP server implementation for React Native.
590
- * This provides a framework-agnostic server interface that can be
591
- * implemented using various React Native HTTP server libraries.
592
- *
593
- * Supported libraries:
594
- * - react-native-http-bridge (recommended)
595
- * - @aspect/react-native-http-server
596
- * - Custom implementations
597
- */
598
-
599
- /**
600
- * HTTP Request interface (library-agnostic)
601
- */
602
- interface HTTPRequest {
603
- method: string;
604
- path: string;
605
- headers: Record<string, string>;
606
- query: Record<string, string>;
607
- body?: unknown;
608
- }
609
- /**
610
- * HTTP Response interface (library-agnostic)
611
- */
612
- interface HTTPResponse {
613
- status: number;
614
- headers: Record<string, string>;
615
- body: string;
616
- }
617
- /**
618
- * Request handler type
619
- */
620
- type RequestHandler = (request: HTTPRequest) => Promise<HTTPResponse>;
621
- /**
622
- * Server adapter interface
623
- *
624
- * Implement this interface to integrate with your chosen HTTP server library.
625
- */
626
- interface ServerAdapter {
627
- /** Start the server */
628
- start(port: number, handler: RequestHandler): Promise<void>;
629
- /** Stop the server */
630
- stop(): Promise<void>;
631
- /** Check if server is running */
632
- isRunning(): boolean;
633
- }
634
- /**
635
- * WebSocket-aware server adapter interface.
636
- *
637
- * Extends ServerAdapter with callbacks for WebSocket connections.
638
- * The adapter manages the raw TCP/WS layer; these callbacks let the
639
- * UI Bridge server handle message routing and event broadcasting.
640
- */
641
- interface WebSocketServerAdapter extends ServerAdapter {
642
- /** Called when a JSON text frame is received from a WS client. Returns response string or null. */
643
- onWebSocketMessage?: (connId: string, message: string) => Promise<string | null>;
644
- /** Called when a new WS connection is established after the HTTP 101 upgrade. */
645
- onWebSocketConnect?: (connId: string) => void;
646
- /** Called when a WS connection is closed or drops. */
647
- onWebSocketDisconnect?: (connId: string) => void;
648
- /** Send a message to a specific WS connection by ID. */
649
- sendToConnection?: (connId: string, message: string) => void;
650
- /** Send a message to all connected WS clients. */
651
- broadcast?: (message: string) => void;
652
- }
653
- /**
654
- * Native UI Bridge HTTP Server
655
- */
656
- declare class NativeUIBridgeServer {
657
- private registry;
658
- private executor;
659
- private config;
660
- private handlers;
661
- private adapter?;
662
- private running;
663
- /**
664
- * Per-connection cleanup thunks for in-flight waiters (waitForElement,
665
- * waitForCondition, ...). Aborted when a client disconnects so the
666
- * underlying timers/listeners don't leak.
667
- */
668
- private pendingWaiters;
669
- /**
670
- * Observability ring buffers backing `/control/console-errors` and
671
- * `/sdk/network-requests`. Allocated unconditionally so the handler can
672
- * always read them, but the global patches (`install()`) only fire on
673
- * `start()` when `testHooks` is set — production builds don't monkey-patch.
674
- */
675
- private consoleErrorBuffer;
676
- private networkRequestBuffer;
677
- constructor(registry: NativeUIBridgeRegistry, executor: NativeActionExecutor, config?: NativeServerConfig);
678
- /**
679
- * Set the server adapter
680
- */
681
- setAdapter(adapter: ServerAdapter): void;
682
- /**
683
- * Set a navigation provider for programmatic route navigation.
684
- * This enables `control/page/navigate` and `control/page/back` on native.
685
- */
686
- setNavigationProvider(provider: NavigationProvider): void;
687
- /**
688
- * Set a route provider for reporting the current navigation route.
689
- * When set, `control/snapshot` responses include `currentRoute` and `segments`.
690
- *
691
- * Also forwards the provider into the registry so the *default*
692
- * `getSnapshot` handler (and any other call site of
693
- * `registry.createSnapshot`) reads the route too — without this the
694
- * cloud-relay/bare-server path returned `currentRoute: null` even when
695
- * a `RouteTracker` was wired, because that path never installed the
696
- * server-level handler override below.
697
- */
698
- setRouteProvider(provider: RouteProvider): void;
699
- /**
700
- * Set a screenshot provider for native screen capture.
701
- * This enables `control/screenshot` on native.
702
- */
703
- setScreenshotProvider(provider: ScreenshotProvider): void;
704
- /**
705
- * Start the HTTP server
706
- */
707
- start(): Promise<void>;
708
- /**
709
- * Stop the HTTP server
710
- */
711
- stop(): Promise<void>;
712
- /**
713
- * Check if server is running
714
- */
715
- isRunning(): boolean;
716
- private eventBridge?;
717
- /**
718
- * Set the event bridge for WebSocket event broadcasting and subscriptions.
719
- */
720
- setEventBridge(bridge: WebSocketEventBridge): void;
721
- /**
722
- * Handle a JSON-RPC message from a WebSocket client.
723
- * Parses the message, routes to the appropriate handler, and returns
724
- * a JSON string response (or null for events that need no response).
725
- */
726
- handleWebSocketMessage(connId: string, rawMessage: string): Promise<string | null>;
727
- /**
728
- * Execute a batch of JSON-RPC requests concurrently.
729
- */
730
- handleBatchRequest(batch: JsonRpcRequest[]): Promise<JsonRpcResponse[]>;
731
- /**
732
- * Register an in-flight waiter's cleanup thunk under the given connection.
733
- * Returns an `unregister` thunk that the natural-resolution path should
734
- * call so the cleanup isn't re-invoked on disconnect.
735
- */
736
- private registerWaiter;
737
- /**
738
- * Abort all pending waiters associated with a connection. Called by the
739
- * provider's WS disconnect handler so timers/listeners don't leak after
740
- * the client goes away.
741
- */
742
- abortWaitersForConnection(connId: string): void;
743
- /**
744
- * Wait for an element to be registered, or resolve immediately if it already exists.
745
- * Returns a JsonRpcResponse JSON string.
746
- */
747
- private handleWaitForElement;
748
- /**
749
- * Wait for an arbitrary element-state predicate to become true.
750
- *
751
- * Supported `condition` shapes:
752
- * {field: "mounted"|"visible"|"enabled"|"focused", equals: boolean}
753
- * {field: "layout", exists: true}
754
- * {field: string, equals: unknown} // generic: state[field] === equals
755
- *
756
- * Resolves immediately with `waited:false` if the predicate already
757
- * holds. Otherwise subscribes to `element:registered` and
758
- * `element:stateChanged` until the predicate matches or timeout fires.
759
- */
760
- private handleWaitForCondition;
761
- /**
762
- * Execute a sequence of JSON-RPC steps in order, stopping on first failure.
763
- * Returns a JsonRpcResponse JSON string with per-step results.
764
- */
765
- private handleSequence;
766
- /**
767
- * Route a JSON-RPC method string to the appropriate handler using path-style matching.
768
- *
769
- * Method strings mirror HTTP routes but without the /ui-bridge/ prefix.
770
- * Path params are extracted from :name placeholders in the route pattern.
771
- *
772
- * Examples:
773
- * "health" → handlers.health
774
- * "control/snapshot" → handlers.getSnapshot
775
- * "control/element/tab-runs/action" → handlers.executeAction ({id:'tab-runs'})
776
- * "control/component/my-comp/action/submit" → handlers.executeComponentAction
777
- */
778
- private routeMethodToHandler;
779
- /**
780
- * Handle incoming HTTP request
781
- *
782
- * Exposed as public so that CloudRelayClient can call it directly (without
783
- * loopback TCP overhead) when processing tunneled requests.
784
- */
785
- handleRequest(request: HTTPRequest): Promise<HTTPResponse>;
786
- /**
787
- * Route an HTTP request to the appropriate handler using WS_ROUTES.
788
- *
789
- * Strips the `/ui-bridge/` prefix from the path, then iterates the shared
790
- * WS_ROUTES table. Each route's `pattern` is matched against the stripped
791
- * path via the module-level `parsePath` helper; path params are merged
792
- * with the request body into a HandlerContext.
793
- *
794
- * `httpMethods` disambiguates routes that share a pattern but differ
795
- * by verb (e.g. GET vs DELETE on `design/style-guide`). A route without
796
- * `httpMethods` is WS-only and will not be matched on HTTP.
797
- */
798
- private routeRequest;
799
- }
800
- /**
801
- * Create a UI Bridge Native server
802
- */
803
- declare function createNativeServer(registry: NativeUIBridgeRegistry, executor: NativeActionExecutor, config?: NativeServerConfig): NativeUIBridgeServer;
804
-
805
- export { type APIResponse as A, type NetworkRequestsResponse as B, type ConsoleErrorEntry as C, type DismissModalResponse as D, type PushModalResponse as E, type FillFormFieldInput as F, type TapAtResponse as G, type HTTPRequest as H, isBatchRequest as I, type JsonRpcBatchRequest as J, isSubscribe as K, isUnsubscribe as L, type NativeServerConfig as N, type PushModalRequest as P, type RequestHandler as R, type ScreenshotProvider as S, type TapAtRequest as T, UI_BRIDGE_NATIVE_ROUTES as U, WebSocketConnection as W, type FillFormFieldResult as a, type FillFormRequest as b, type FillFormResponse as c, type HTTPResponse as d, type HandlerContext as e, type HandlerFunction as f, type JsonRpcBatchResponse as g, type JsonRpcEvent as h, type JsonRpcRequest as i, type JsonRpcResponse as j, type NativeServerHandlers as k, NativeUIBridgeServer as l, type NavigationProvider as m, type RouteDefinition as n, type RouteProvider as o, type ServerAdapter as p, WebSocketEventBridge as q, type WebSocketMessageHandler as r, type WebSocketServerAdapter as s, createNativeServer as t, type NetworkRequestEntry as u, type ConsoleErrorsResponse as v, type JsonRpcClientMessage as w, type JsonRpcServerMessage as x, type JsonRpcSubscribe as y, type JsonRpcUnsubscribe as z };