@qontinui/ui-bridge 0.2.0 → 0.3.1
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.
- package/dist/ai/index.d.mts +312 -155
- package/dist/ai/index.d.ts +312 -155
- package/dist/ai/index.js +2363 -67
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/index.mjs +2328 -68
- package/dist/ai/index.mjs.map +1 -1
- package/dist/annotations/index.d.mts +218 -0
- package/dist/annotations/index.d.ts +218 -0
- package/dist/annotations/index.js +246 -0
- package/dist/annotations/index.js.map +1 -0
- package/dist/annotations/index.mjs +241 -0
- package/dist/annotations/index.mjs.map +1 -0
- package/dist/assertions-BSR3afVr.d.ts +161 -0
- package/dist/assertions-CTw1hfOx.d.mts +161 -0
- package/dist/babel-plugin/index.js +504 -0
- package/dist/babel-plugin/index.js.map +1 -0
- package/dist/babel-plugin/index.mjs +488 -0
- package/dist/babel-plugin/index.mjs.map +1 -0
- package/dist/browser-capture-Bms60T6f.d.mts +47 -0
- package/dist/browser-capture-CsTU29mb.d.ts +47 -0
- package/dist/control/index.d.mts +26 -7
- package/dist/control/index.d.ts +26 -7
- package/dist/control/index.js +276 -48
- package/dist/control/index.js.map +1 -1
- package/dist/control/index.mjs +276 -48
- package/dist/control/index.mjs.map +1 -1
- package/dist/core/index.d.mts +115 -44
- package/dist/core/index.d.ts +115 -44
- package/dist/core/index.js +0 -1560
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +1 -1549
- package/dist/core/index.mjs.map +1 -1
- package/dist/debug/index.d.mts +5 -3
- package/dist/debug/index.d.ts +5 -3
- package/dist/debug/index.js +925 -1
- package/dist/debug/index.js.map +1 -1
- package/dist/debug/index.mjs +924 -2
- package/dist/debug/index.mjs.map +1 -1
- package/dist/index.d.mts +13 -9
- package/dist/index.d.ts +13 -9
- package/dist/index.js +8310 -3777
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8246 -3766
- package/dist/index.mjs.map +1 -1
- package/dist/{metrics-NC3csD0R.d.mts → metrics-DuA2qIIz.d.mts} +2 -2
- package/dist/{metrics-C9XRi_mL.d.ts → metrics-KFAAKNEB.d.ts} +2 -2
- package/dist/native/control/index.js +448 -0
- package/dist/native/control/index.js.map +1 -0
- package/dist/native/control/index.mjs +445 -0
- package/dist/native/control/index.mjs.map +1 -0
- package/dist/native/core/index.js +486 -0
- package/dist/native/core/index.js.map +1 -0
- package/dist/native/core/index.mjs +475 -0
- package/dist/native/core/index.mjs.map +1 -0
- package/dist/native/debug/index.js +408 -0
- package/dist/native/debug/index.js.map +1 -0
- package/dist/native/debug/index.mjs +406 -0
- package/dist/native/debug/index.mjs.map +1 -0
- package/dist/native/index.js +2232 -0
- package/dist/native/index.js.map +1 -0
- package/dist/native/index.mjs +2204 -0
- package/dist/native/index.mjs.map +1 -0
- package/dist/native/react/index.js +1377 -0
- package/dist/native/react/index.js.map +1 -0
- package/dist/native/react/index.mjs +1365 -0
- package/dist/native/react/index.mjs.map +1 -0
- package/dist/native/server/index.js +440 -0
- package/dist/native/server/index.js.map +1 -0
- package/dist/native/server/index.mjs +435 -0
- package/dist/native/server/index.mjs.map +1 -0
- package/dist/react/index.d.mts +121 -9
- package/dist/react/index.d.ts +121 -9
- package/dist/react/index.js +2239 -91
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +2239 -92
- package/dist/react/index.mjs.map +1 -1
- package/dist/{registry-CIEDjbQ9.d.ts → registry-C6dDtn1v.d.ts} +34 -15
- package/dist/{registry-SsSDq46X.d.mts → registry-POtcxnal.d.mts} +34 -15
- package/dist/render-log/index.d.mts +1 -1
- package/dist/render-log/index.d.ts +1 -1
- package/dist/server/express.d.mts +37 -0
- package/dist/server/express.d.ts +37 -0
- package/dist/server/express.js +298 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/express.mjs +294 -0
- package/dist/server/express.mjs.map +1 -0
- package/dist/server/handlers.d.mts +124 -0
- package/dist/server/handlers.d.ts +124 -0
- package/dist/server/handlers.js +7183 -0
- package/dist/server/handlers.js.map +1 -0
- package/dist/server/handlers.mjs +7180 -0
- package/dist/server/handlers.mjs.map +1 -0
- package/dist/server/index.d.mts +12 -0
- package/dist/server/index.d.ts +12 -0
- package/dist/server/index.js +8384 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +8369 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/server/nextjs.d.mts +128 -0
- package/dist/server/nextjs.d.ts +128 -0
- package/dist/server/nextjs.js +390 -0
- package/dist/server/nextjs.js.map +1 -0
- package/dist/server/nextjs.mjs +385 -0
- package/dist/server/nextjs.mjs.map +1 -0
- package/dist/server/standalone.d.mts +7 -0
- package/dist/server/standalone.d.ts +7 -0
- package/dist/server/standalone.js +845 -0
- package/dist/server/standalone.js.map +1 -0
- package/dist/server/standalone.mjs +841 -0
- package/dist/server/standalone.mjs.map +1 -0
- package/dist/specs/index.d.mts +365 -0
- package/dist/specs/index.d.ts +365 -0
- package/dist/specs/index.js +2809 -0
- package/dist/specs/index.js.map +1 -0
- package/dist/specs/index.mjs +2786 -0
- package/dist/specs/index.mjs.map +1 -0
- package/dist/standalone-B6GLIEmR.d.ts +216 -0
- package/dist/standalone-CjdYqj3P.d.mts +216 -0
- package/dist/swc-plugin/index.d.mts +79 -0
- package/dist/swc-plugin/index.d.ts +79 -0
- package/dist/swc-plugin/index.js +15 -0
- package/dist/swc-plugin/index.js.map +1 -0
- package/dist/swc-plugin/index.mjs +9 -0
- package/dist/swc-plugin/index.mjs.map +1 -0
- package/dist/types-B2EfvEaq.d.ts +236 -0
- package/dist/{types-Dr6tH-bm.d.mts → types-C7gVYRnF.d.ts} +72 -2
- package/dist/{types-oCTrRxSw.d.ts → types-CJGrBEhC.d.mts} +72 -2
- package/dist/types-CebMQj76.d.ts +1275 -0
- package/dist/types-D_ypYl3T.d.mts +1275 -0
- package/dist/types-UBtp7R0u.d.mts +132 -0
- package/dist/types-UBtp7R0u.d.ts +132 -0
- package/dist/types-gO696T_t.d.mts +236 -0
- package/dist/{types-CPMbN_Iw.d.mts → types-suaYwWWg.d.mts} +519 -152
- package/dist/{types-CPMbN_Iw.d.ts → types-suaYwWWg.d.ts} +519 -152
- package/package.json +123 -4
- package/swc-plugin-wasm/ui_bridge_swc_plugin.wasm +0 -0
- package/dist/types-BvCfFuEV.d.ts +0 -534
- package/dist/types-CFT3Dnx4.d.mts +0 -534
- package/dist/websocket-client-CX4QJesI.d.ts +0 -124
- package/dist/websocket-client-C_Na0OSp.d.mts +0 -124
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { k as BridgeEventListener, l as BridgeEventType, F as ElementType, Z as StandardAction, x as CustomAction, u as ContentMetadata, X as RegisteredElement, _ as StateGetter, W as RegisteredComponent, r as ComponentStateResponse, az as Workflow, a3 as UIState, a4 as UIStateGroup, a5 as UITransition, a0 as TransitionResult, T as PathResult, O as NavigationResult, $ as StateSnapshot, m as BridgeSnapshot } from './types-suaYwWWg.js';
|
|
2
|
+
import { a8 as SearchCriteria, aa as SearchResult } from './types-CebMQj76.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Element and Component Registry
|
|
@@ -53,7 +53,25 @@ declare class UIBridgeRegistry {
|
|
|
53
53
|
label?: string;
|
|
54
54
|
actions?: StandardAction[];
|
|
55
55
|
customActions?: Record<string, CustomAction>;
|
|
56
|
+
category?: 'interactive' | 'content';
|
|
57
|
+
contentMetadata?: ContentMetadata;
|
|
56
58
|
}): RegisteredElement;
|
|
59
|
+
/**
|
|
60
|
+
* Register a content (non-interactive) element
|
|
61
|
+
*/
|
|
62
|
+
registerContentElement(id: string, element: HTMLElement, options: {
|
|
63
|
+
contentType: string;
|
|
64
|
+
contentMetadata: ContentMetadata;
|
|
65
|
+
label?: string;
|
|
66
|
+
}): RegisteredElement;
|
|
67
|
+
/**
|
|
68
|
+
* Get all content (non-interactive) elements
|
|
69
|
+
*/
|
|
70
|
+
getAllContentElements(): RegisteredElement[];
|
|
71
|
+
/**
|
|
72
|
+
* Get all interactive elements
|
|
73
|
+
*/
|
|
74
|
+
getAllInteractiveElements(): RegisteredElement[];
|
|
57
75
|
/**
|
|
58
76
|
* Unregister an element
|
|
59
77
|
*/
|
|
@@ -103,6 +121,8 @@ declare class UIBridgeRegistry {
|
|
|
103
121
|
handler: (params?: unknown) => unknown | Promise<unknown>;
|
|
104
122
|
}>;
|
|
105
123
|
elementIds?: string[];
|
|
124
|
+
getState?: StateGetter<Record<string, unknown>>;
|
|
125
|
+
getComputed?: () => Record<string, unknown>;
|
|
106
126
|
}): RegisteredComponent;
|
|
107
127
|
/**
|
|
108
128
|
* Unregister a component
|
|
@@ -116,6 +136,10 @@ declare class UIBridgeRegistry {
|
|
|
116
136
|
* Get all registered components
|
|
117
137
|
*/
|
|
118
138
|
getAllComponents(): RegisteredComponent[];
|
|
139
|
+
/**
|
|
140
|
+
* Get the current state and computed properties of a component
|
|
141
|
+
*/
|
|
142
|
+
getComponentState(id: string): ComponentStateResponse | null;
|
|
119
143
|
/**
|
|
120
144
|
* Register a workflow
|
|
121
145
|
*/
|
|
@@ -239,6 +263,13 @@ declare class UIBridgeRegistry {
|
|
|
239
263
|
* Create a snapshot of the current state
|
|
240
264
|
*/
|
|
241
265
|
createSnapshot(): BridgeSnapshot;
|
|
266
|
+
/**
|
|
267
|
+
* Create a snapshot asynchronously, processing elements in batches to avoid
|
|
268
|
+
* blocking the main thread. This prevents "Page Unresponsive" dialogs when
|
|
269
|
+
* there are many registered elements (200-500+), since getState() and
|
|
270
|
+
* getIdentifier() force layout/style recalculation for each element.
|
|
271
|
+
*/
|
|
272
|
+
createSnapshotAsync(batchSize?: number): Promise<BridgeSnapshot>;
|
|
242
273
|
/**
|
|
243
274
|
* Clear all registrations
|
|
244
275
|
*/
|
|
@@ -258,17 +289,5 @@ declare class UIBridgeRegistry {
|
|
|
258
289
|
activeStateCount: number;
|
|
259
290
|
};
|
|
260
291
|
}
|
|
261
|
-
/**
|
|
262
|
-
* Get or create the global registry
|
|
263
|
-
*/
|
|
264
|
-
declare function getGlobalRegistry(): UIBridgeRegistry;
|
|
265
|
-
/**
|
|
266
|
-
* Set the global registry
|
|
267
|
-
*/
|
|
268
|
-
declare function setGlobalRegistry(registry: UIBridgeRegistry): void;
|
|
269
|
-
/**
|
|
270
|
-
* Reset the global registry
|
|
271
|
-
*/
|
|
272
|
-
declare function resetGlobalRegistry(): void;
|
|
273
292
|
|
|
274
|
-
export {
|
|
293
|
+
export { UIBridgeRegistry as U };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { k as BridgeEventListener, l as BridgeEventType, F as ElementType, Z as StandardAction, x as CustomAction, u as ContentMetadata, X as RegisteredElement, _ as StateGetter, W as RegisteredComponent, r as ComponentStateResponse, az as Workflow, a3 as UIState, a4 as UIStateGroup, a5 as UITransition, a0 as TransitionResult, T as PathResult, O as NavigationResult, $ as StateSnapshot, m as BridgeSnapshot } from './types-suaYwWWg.mjs';
|
|
2
|
+
import { a8 as SearchCriteria, aa as SearchResult } from './types-D_ypYl3T.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Element and Component Registry
|
|
@@ -53,7 +53,25 @@ declare class UIBridgeRegistry {
|
|
|
53
53
|
label?: string;
|
|
54
54
|
actions?: StandardAction[];
|
|
55
55
|
customActions?: Record<string, CustomAction>;
|
|
56
|
+
category?: 'interactive' | 'content';
|
|
57
|
+
contentMetadata?: ContentMetadata;
|
|
56
58
|
}): RegisteredElement;
|
|
59
|
+
/**
|
|
60
|
+
* Register a content (non-interactive) element
|
|
61
|
+
*/
|
|
62
|
+
registerContentElement(id: string, element: HTMLElement, options: {
|
|
63
|
+
contentType: string;
|
|
64
|
+
contentMetadata: ContentMetadata;
|
|
65
|
+
label?: string;
|
|
66
|
+
}): RegisteredElement;
|
|
67
|
+
/**
|
|
68
|
+
* Get all content (non-interactive) elements
|
|
69
|
+
*/
|
|
70
|
+
getAllContentElements(): RegisteredElement[];
|
|
71
|
+
/**
|
|
72
|
+
* Get all interactive elements
|
|
73
|
+
*/
|
|
74
|
+
getAllInteractiveElements(): RegisteredElement[];
|
|
57
75
|
/**
|
|
58
76
|
* Unregister an element
|
|
59
77
|
*/
|
|
@@ -103,6 +121,8 @@ declare class UIBridgeRegistry {
|
|
|
103
121
|
handler: (params?: unknown) => unknown | Promise<unknown>;
|
|
104
122
|
}>;
|
|
105
123
|
elementIds?: string[];
|
|
124
|
+
getState?: StateGetter<Record<string, unknown>>;
|
|
125
|
+
getComputed?: () => Record<string, unknown>;
|
|
106
126
|
}): RegisteredComponent;
|
|
107
127
|
/**
|
|
108
128
|
* Unregister a component
|
|
@@ -116,6 +136,10 @@ declare class UIBridgeRegistry {
|
|
|
116
136
|
* Get all registered components
|
|
117
137
|
*/
|
|
118
138
|
getAllComponents(): RegisteredComponent[];
|
|
139
|
+
/**
|
|
140
|
+
* Get the current state and computed properties of a component
|
|
141
|
+
*/
|
|
142
|
+
getComponentState(id: string): ComponentStateResponse | null;
|
|
119
143
|
/**
|
|
120
144
|
* Register a workflow
|
|
121
145
|
*/
|
|
@@ -239,6 +263,13 @@ declare class UIBridgeRegistry {
|
|
|
239
263
|
* Create a snapshot of the current state
|
|
240
264
|
*/
|
|
241
265
|
createSnapshot(): BridgeSnapshot;
|
|
266
|
+
/**
|
|
267
|
+
* Create a snapshot asynchronously, processing elements in batches to avoid
|
|
268
|
+
* blocking the main thread. This prevents "Page Unresponsive" dialogs when
|
|
269
|
+
* there are many registered elements (200-500+), since getState() and
|
|
270
|
+
* getIdentifier() force layout/style recalculation for each element.
|
|
271
|
+
*/
|
|
272
|
+
createSnapshotAsync(batchSize?: number): Promise<BridgeSnapshot>;
|
|
242
273
|
/**
|
|
243
274
|
* Clear all registrations
|
|
244
275
|
*/
|
|
@@ -258,17 +289,5 @@ declare class UIBridgeRegistry {
|
|
|
258
289
|
activeStateCount: number;
|
|
259
290
|
};
|
|
260
291
|
}
|
|
261
|
-
/**
|
|
262
|
-
* Get or create the global registry
|
|
263
|
-
*/
|
|
264
|
-
declare function getGlobalRegistry(): UIBridgeRegistry;
|
|
265
|
-
/**
|
|
266
|
-
* Set the global registry
|
|
267
|
-
*/
|
|
268
|
-
declare function setGlobalRegistry(registry: UIBridgeRegistry): void;
|
|
269
|
-
/**
|
|
270
|
-
* Reset the global registry
|
|
271
|
-
*/
|
|
272
|
-
declare function resetGlobalRegistry(): void;
|
|
273
292
|
|
|
274
|
-
export {
|
|
293
|
+
export { UIBridgeRegistry as U };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import { U as UIBridgeServerConfig, c as UIBridgeServerHandlers } from '../types-gO696T_t.mjs';
|
|
3
|
+
import '../types-suaYwWWg.mjs';
|
|
4
|
+
import '../types-CJGrBEhC.mjs';
|
|
5
|
+
import '../types-D_ypYl3T.mjs';
|
|
6
|
+
import '../render-log/index.mjs';
|
|
7
|
+
import '../types-UBtp7R0u.mjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Express Adapter
|
|
11
|
+
*
|
|
12
|
+
* Express.js middleware for UI Bridge server.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Express-specific configuration
|
|
17
|
+
*/
|
|
18
|
+
interface ExpressAdapterConfig extends UIBridgeServerConfig {
|
|
19
|
+
/** Use JSON body parser (if not already configured) */
|
|
20
|
+
useBodyParser?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create Express router with UI Bridge routes
|
|
24
|
+
*/
|
|
25
|
+
declare function createExpressRouter(handlers: UIBridgeServerHandlers, config?: ExpressAdapterConfig): Router;
|
|
26
|
+
/**
|
|
27
|
+
* Create Express app with UI Bridge routes
|
|
28
|
+
*
|
|
29
|
+
* Convenience function that creates a complete Express app with UI Bridge.
|
|
30
|
+
*/
|
|
31
|
+
declare function createExpressApp(handlers: UIBridgeServerHandlers, config?: ExpressAdapterConfig): unknown;
|
|
32
|
+
/**
|
|
33
|
+
* Express middleware that adds UI Bridge to an existing app
|
|
34
|
+
*/
|
|
35
|
+
declare function uiBridgeMiddleware(handlers: UIBridgeServerHandlers, config?: ExpressAdapterConfig): Router;
|
|
36
|
+
|
|
37
|
+
export { type ExpressAdapterConfig, createExpressApp, createExpressRouter, uiBridgeMiddleware };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import { U as UIBridgeServerConfig, c as UIBridgeServerHandlers } from '../types-B2EfvEaq.js';
|
|
3
|
+
import '../types-suaYwWWg.js';
|
|
4
|
+
import '../types-C7gVYRnF.js';
|
|
5
|
+
import '../types-CebMQj76.js';
|
|
6
|
+
import '../render-log/index.js';
|
|
7
|
+
import '../types-UBtp7R0u.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Express Adapter
|
|
11
|
+
*
|
|
12
|
+
* Express.js middleware for UI Bridge server.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Express-specific configuration
|
|
17
|
+
*/
|
|
18
|
+
interface ExpressAdapterConfig extends UIBridgeServerConfig {
|
|
19
|
+
/** Use JSON body parser (if not already configured) */
|
|
20
|
+
useBodyParser?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create Express router with UI Bridge routes
|
|
24
|
+
*/
|
|
25
|
+
declare function createExpressRouter(handlers: UIBridgeServerHandlers, config?: ExpressAdapterConfig): Router;
|
|
26
|
+
/**
|
|
27
|
+
* Create Express app with UI Bridge routes
|
|
28
|
+
*
|
|
29
|
+
* Convenience function that creates a complete Express app with UI Bridge.
|
|
30
|
+
*/
|
|
31
|
+
declare function createExpressApp(handlers: UIBridgeServerHandlers, config?: ExpressAdapterConfig): unknown;
|
|
32
|
+
/**
|
|
33
|
+
* Express middleware that adds UI Bridge to an existing app
|
|
34
|
+
*/
|
|
35
|
+
declare function uiBridgeMiddleware(handlers: UIBridgeServerHandlers, config?: ExpressAdapterConfig): Router;
|
|
36
|
+
|
|
37
|
+
export { type ExpressAdapterConfig, createExpressApp, createExpressRouter, uiBridgeMiddleware };
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// src/server/types.ts
|
|
11
|
+
var UI_BRIDGE_ROUTES = [
|
|
12
|
+
// Render log
|
|
13
|
+
{ method: "GET", path: "/render-log", handler: "getRenderLog" },
|
|
14
|
+
{ method: "DELETE", path: "/render-log", handler: "clearRenderLog" },
|
|
15
|
+
{ method: "POST", path: "/render-log/snapshot", handler: "captureSnapshot" },
|
|
16
|
+
{ method: "GET", path: "/render-log/path", handler: "getRenderLogPath" },
|
|
17
|
+
// Control - Elements
|
|
18
|
+
{ method: "GET", path: "/control/elements", handler: "getElements" },
|
|
19
|
+
{ method: "GET", path: "/control/element/:id", handler: "getElement", params: ["id"] },
|
|
20
|
+
{ method: "GET", path: "/control/element/:id/state", handler: "getElementState", params: ["id"] },
|
|
21
|
+
{
|
|
22
|
+
method: "POST",
|
|
23
|
+
path: "/control/element/:id/action",
|
|
24
|
+
handler: "executeElementAction",
|
|
25
|
+
params: ["id"],
|
|
26
|
+
bodyRequired: true
|
|
27
|
+
},
|
|
28
|
+
// Control - Components
|
|
29
|
+
{ method: "GET", path: "/control/components", handler: "getComponents" },
|
|
30
|
+
{ method: "GET", path: "/control/component/:id", handler: "getComponent", params: ["id"] },
|
|
31
|
+
{
|
|
32
|
+
method: "GET",
|
|
33
|
+
path: "/control/component/:id/state",
|
|
34
|
+
handler: "getComponentState",
|
|
35
|
+
params: ["id"]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
method: "POST",
|
|
39
|
+
path: "/control/component/:id/action/:actionId",
|
|
40
|
+
handler: "executeComponentAction",
|
|
41
|
+
params: ["id", "actionId"],
|
|
42
|
+
bodyRequired: true
|
|
43
|
+
},
|
|
44
|
+
// Find (formerly Discovery)
|
|
45
|
+
{ method: "POST", path: "/control/find", handler: "find" },
|
|
46
|
+
{ method: "POST", path: "/control/discover", handler: "discover" },
|
|
47
|
+
// @deprecated Use /control/find
|
|
48
|
+
{ method: "GET", path: "/control/snapshot", handler: "getControlSnapshot" },
|
|
49
|
+
// Workflows
|
|
50
|
+
{ method: "GET", path: "/control/workflows", handler: "getWorkflows" },
|
|
51
|
+
{ method: "POST", path: "/control/workflow/:id/run", handler: "runWorkflow", params: ["id"] },
|
|
52
|
+
{
|
|
53
|
+
method: "GET",
|
|
54
|
+
path: "/control/workflow/:runId/status",
|
|
55
|
+
handler: "getWorkflowStatus",
|
|
56
|
+
params: ["runId"]
|
|
57
|
+
},
|
|
58
|
+
// Debug
|
|
59
|
+
{ method: "GET", path: "/debug/action-history", handler: "getActionHistory" },
|
|
60
|
+
{ method: "GET", path: "/debug/metrics", handler: "getMetrics" },
|
|
61
|
+
{ method: "POST", path: "/debug/highlight/:id", handler: "highlightElement", params: ["id"] },
|
|
62
|
+
{ method: "GET", path: "/debug/element-tree", handler: "getElementTree" },
|
|
63
|
+
{ method: "GET", path: "/control/console-errors", handler: "getConsoleErrors" },
|
|
64
|
+
{ method: "POST", path: "/control/console-errors/clear", handler: "clearConsoleErrors" },
|
|
65
|
+
// AI-native endpoints
|
|
66
|
+
{ method: "POST", path: "/ai/search", handler: "aiSearch", bodyRequired: true },
|
|
67
|
+
{ method: "POST", path: "/ai/execute", handler: "aiExecute", bodyRequired: true },
|
|
68
|
+
{ method: "POST", path: "/ai/assert", handler: "aiAssert", bodyRequired: true },
|
|
69
|
+
{ method: "POST", path: "/ai/assert/batch", handler: "aiAssertBatch", bodyRequired: true },
|
|
70
|
+
{ method: "GET", path: "/ai/snapshot", handler: "getSemanticSnapshot" },
|
|
71
|
+
{ method: "GET", path: "/ai/diff", handler: "getSemanticDiff" },
|
|
72
|
+
{ method: "GET", path: "/ai/summary", handler: "getPageSummary" },
|
|
73
|
+
{ method: "POST", path: "/ai/semantic-search", handler: "aiSemanticSearch", bodyRequired: true },
|
|
74
|
+
// State management (static routes before parameterized)
|
|
75
|
+
{ method: "GET", path: "/control/states", handler: "getStates" },
|
|
76
|
+
{ method: "GET", path: "/control/states/active", handler: "getActiveStates" },
|
|
77
|
+
{ method: "GET", path: "/control/states/snapshot", handler: "getStateSnapshot" },
|
|
78
|
+
{ method: "POST", path: "/control/states/find-path", handler: "findPath", bodyRequired: true },
|
|
79
|
+
{ method: "POST", path: "/control/states/navigate", handler: "navigateTo", bodyRequired: true },
|
|
80
|
+
{ method: "GET", path: "/control/state/:id", handler: "getState", params: ["id"] },
|
|
81
|
+
{ method: "POST", path: "/control/state/:id/activate", handler: "activateState", params: ["id"] },
|
|
82
|
+
{
|
|
83
|
+
method: "POST",
|
|
84
|
+
path: "/control/state/:id/deactivate",
|
|
85
|
+
handler: "deactivateState",
|
|
86
|
+
params: ["id"]
|
|
87
|
+
},
|
|
88
|
+
{ method: "GET", path: "/control/state-groups", handler: "getStateGroups" },
|
|
89
|
+
{
|
|
90
|
+
method: "POST",
|
|
91
|
+
path: "/control/state-group/:id/activate",
|
|
92
|
+
handler: "activateStateGroup",
|
|
93
|
+
params: ["id"]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
method: "POST",
|
|
97
|
+
path: "/control/state-group/:id/deactivate",
|
|
98
|
+
handler: "deactivateStateGroup",
|
|
99
|
+
params: ["id"]
|
|
100
|
+
},
|
|
101
|
+
{ method: "GET", path: "/control/transitions", handler: "getTransitions" },
|
|
102
|
+
{
|
|
103
|
+
method: "GET",
|
|
104
|
+
path: "/control/transition/:id/can-execute",
|
|
105
|
+
handler: "canExecuteTransition",
|
|
106
|
+
params: ["id"]
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
method: "POST",
|
|
110
|
+
path: "/control/transition/:id/execute",
|
|
111
|
+
handler: "executeTransition",
|
|
112
|
+
params: ["id"]
|
|
113
|
+
},
|
|
114
|
+
// Intent endpoints
|
|
115
|
+
{ method: "GET", path: "/ai/intents", handler: "listIntents" },
|
|
116
|
+
{ method: "POST", path: "/ai/intents/execute", handler: "executeIntent", bodyRequired: true },
|
|
117
|
+
{ method: "POST", path: "/ai/intents/find", handler: "findIntent", bodyRequired: true },
|
|
118
|
+
{ method: "POST", path: "/ai/intents/register", handler: "registerIntent", bodyRequired: true },
|
|
119
|
+
{
|
|
120
|
+
method: "POST",
|
|
121
|
+
path: "/ai/intents/execute-from-query",
|
|
122
|
+
handler: "executeIntentFromQuery",
|
|
123
|
+
bodyRequired: true
|
|
124
|
+
},
|
|
125
|
+
// Recovery endpoints
|
|
126
|
+
{
|
|
127
|
+
method: "POST",
|
|
128
|
+
path: "/ai/recovery/attempt",
|
|
129
|
+
handler: "attemptRecovery",
|
|
130
|
+
bodyRequired: true
|
|
131
|
+
},
|
|
132
|
+
// Cross-app analysis endpoints
|
|
133
|
+
{ method: "GET", path: "/ai/analyze/data", handler: "analyzePageData" },
|
|
134
|
+
{ method: "GET", path: "/ai/analyze/regions", handler: "analyzePageRegions" },
|
|
135
|
+
{ method: "GET", path: "/ai/analyze/structured-data", handler: "analyzeStructuredData" },
|
|
136
|
+
{
|
|
137
|
+
method: "POST",
|
|
138
|
+
path: "/ai/analyze/cross-app-compare",
|
|
139
|
+
handler: "crossAppCompare",
|
|
140
|
+
bodyRequired: true
|
|
141
|
+
},
|
|
142
|
+
// Page navigation
|
|
143
|
+
{ method: "POST", path: "/control/page/refresh", handler: "pageRefresh" },
|
|
144
|
+
{ method: "POST", path: "/control/page/navigate", handler: "pageNavigate", bodyRequired: true },
|
|
145
|
+
{ method: "POST", path: "/control/page/back", handler: "pageGoBack" },
|
|
146
|
+
{ method: "POST", path: "/control/page/forward", handler: "pageGoForward" },
|
|
147
|
+
// Annotations (static routes before parameterized)
|
|
148
|
+
{ method: "GET", path: "/annotations", handler: "getAnnotations" },
|
|
149
|
+
{ method: "GET", path: "/annotations/export", handler: "exportAnnotations" },
|
|
150
|
+
{ method: "GET", path: "/annotations/coverage", handler: "getAnnotationCoverage" },
|
|
151
|
+
{ method: "POST", path: "/annotations/import", handler: "importAnnotations", bodyRequired: true },
|
|
152
|
+
{ method: "GET", path: "/annotations/:id", handler: "getAnnotation", params: ["id"] },
|
|
153
|
+
{
|
|
154
|
+
method: "PUT",
|
|
155
|
+
path: "/annotations/:id",
|
|
156
|
+
handler: "setAnnotation",
|
|
157
|
+
params: ["id"],
|
|
158
|
+
bodyRequired: true
|
|
159
|
+
},
|
|
160
|
+
{ method: "DELETE", path: "/annotations/:id", handler: "deleteAnnotation", params: ["id"] },
|
|
161
|
+
// Performance diagnostics
|
|
162
|
+
{ method: "GET", path: "/control/performance-entries", handler: "getPerformanceEntries" },
|
|
163
|
+
{
|
|
164
|
+
method: "POST",
|
|
165
|
+
path: "/control/performance-entries/clear",
|
|
166
|
+
handler: "clearPerformanceEntries"
|
|
167
|
+
},
|
|
168
|
+
{ method: "GET", path: "/control/browser-events", handler: "getBrowserEvents" }
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
// src/server/express.ts
|
|
172
|
+
function createCORSMiddleware(options) {
|
|
173
|
+
const corsOptions = typeof options === "boolean" ? { origin: options, methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"] } : options;
|
|
174
|
+
return (req, res, next) => {
|
|
175
|
+
if (corsOptions.origin === true) {
|
|
176
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
177
|
+
} else if (typeof corsOptions.origin === "string") {
|
|
178
|
+
res.setHeader("Access-Control-Allow-Origin", corsOptions.origin);
|
|
179
|
+
} else if (Array.isArray(corsOptions.origin)) {
|
|
180
|
+
const origin = req.headers.origin;
|
|
181
|
+
if (origin && corsOptions.origin.includes(origin)) {
|
|
182
|
+
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (corsOptions.methods) {
|
|
186
|
+
res.setHeader("Access-Control-Allow-Methods", corsOptions.methods.join(", "));
|
|
187
|
+
}
|
|
188
|
+
if (corsOptions.headers) {
|
|
189
|
+
res.setHeader("Access-Control-Allow-Headers", corsOptions.headers.join(", "));
|
|
190
|
+
} else {
|
|
191
|
+
res.setHeader(
|
|
192
|
+
"Access-Control-Allow-Headers",
|
|
193
|
+
"Content-Type, Authorization, X-Requested-With"
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
if (corsOptions.credentials) {
|
|
197
|
+
res.setHeader("Access-Control-Allow-Credentials", "true");
|
|
198
|
+
}
|
|
199
|
+
if (corsOptions.maxAge) {
|
|
200
|
+
res.setHeader("Access-Control-Max-Age", String(corsOptions.maxAge));
|
|
201
|
+
}
|
|
202
|
+
if (req.method === "OPTIONS") {
|
|
203
|
+
res.status(204).end();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
next();
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function wrapError(error, code) {
|
|
210
|
+
return {
|
|
211
|
+
success: false,
|
|
212
|
+
error: typeof error === "string" ? error : error.message,
|
|
213
|
+
code,
|
|
214
|
+
timestamp: Date.now()
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
function createExpressRouter(handlers, config = {}) {
|
|
218
|
+
const express = __require("express");
|
|
219
|
+
const router = express.Router();
|
|
220
|
+
if (config.cors) {
|
|
221
|
+
router.use(createCORSMiddleware(config.cors));
|
|
222
|
+
}
|
|
223
|
+
if (config.useBodyParser) {
|
|
224
|
+
router.use(express.json());
|
|
225
|
+
}
|
|
226
|
+
if (config.authenticate) {
|
|
227
|
+
router.use(async (req, res, next) => {
|
|
228
|
+
try {
|
|
229
|
+
const authenticated = await config.authenticate(req);
|
|
230
|
+
if (!authenticated) {
|
|
231
|
+
res.status(401).json(wrapError("Unauthorized", "UNAUTHORIZED"));
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
next();
|
|
235
|
+
} catch (error) {
|
|
236
|
+
res.status(500).json(wrapError(error, "AUTH_ERROR"));
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
for (const route of UI_BRIDGE_ROUTES) {
|
|
241
|
+
const method = route.method.toLowerCase();
|
|
242
|
+
const path = route.path;
|
|
243
|
+
const handlerName = route.handler;
|
|
244
|
+
const handler = handlers[handlerName];
|
|
245
|
+
if (!handler) {
|
|
246
|
+
console.warn(`Handler not found for route: ${route.method} ${route.path}`);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
router[method](
|
|
250
|
+
path,
|
|
251
|
+
createRouteHandler(route, handler)
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
return router;
|
|
255
|
+
}
|
|
256
|
+
function createRouteHandler(route, handler) {
|
|
257
|
+
return async (req, res) => {
|
|
258
|
+
try {
|
|
259
|
+
const args = [];
|
|
260
|
+
if (route.params) {
|
|
261
|
+
for (const param of route.params) {
|
|
262
|
+
args.push(req.params[param]);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (route.bodyRequired || route.method === "POST") {
|
|
266
|
+
args.push(req.body);
|
|
267
|
+
}
|
|
268
|
+
if (route.method === "GET" && Object.keys(req.query).length > 0) {
|
|
269
|
+
args.push(req.query);
|
|
270
|
+
}
|
|
271
|
+
const result = await handler(...args);
|
|
272
|
+
res.json(result);
|
|
273
|
+
} catch (error) {
|
|
274
|
+
res.status(500).json(wrapError(error, "INTERNAL_ERROR"));
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function createExpressApp(handlers, config = {}) {
|
|
279
|
+
const express = __require("express");
|
|
280
|
+
const app = express();
|
|
281
|
+
app.use(express.json());
|
|
282
|
+
const basePath = config.basePath || "/ui-bridge";
|
|
283
|
+
const router = createExpressRouter(handlers, { ...config, useBodyParser: false });
|
|
284
|
+
app.use(basePath, router);
|
|
285
|
+
app.get("/health", (_req, res) => {
|
|
286
|
+
res.json({ status: "ok", timestamp: Date.now() });
|
|
287
|
+
});
|
|
288
|
+
return app;
|
|
289
|
+
}
|
|
290
|
+
function uiBridgeMiddleware(handlers, config = {}) {
|
|
291
|
+
return createExpressRouter(handlers, config);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
exports.createExpressApp = createExpressApp;
|
|
295
|
+
exports.createExpressRouter = createExpressRouter;
|
|
296
|
+
exports.uiBridgeMiddleware = uiBridgeMiddleware;
|
|
297
|
+
//# sourceMappingURL=express.js.map
|
|
298
|
+
//# sourceMappingURL=express.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/server/types.ts","../../src/server/express.ts"],"names":[],"mappings":";;;;;;;;;;AAuSO,IAAM,gBAAA,GAAsC;AAAA;AAAA,EAEjD,EAAE,MAAA,EAAQ,KAAA,EAAO,IAAA,EAAM,aAAA,EAAe,SAAS,cAAA,EAAe;AAAA,EAC9D,EAAE,MAAA,EAAQ,QAAA,EAAU,IAAA,EAAM,aAAA,EAAe,SAAS,gBAAA,EAAiB;AAAA,EACnE,EAAE,MAAA,EAAQ,MAAA,EAAQ,IAAA,EAAM,sBAAA,EAAwB,SAAS,iBAAA,EAAkB;AAAA,EAC3E,EAAE,MAAA,EAAQ,KAAA,EAAO,IAAA,EAAM,kBAAA,EAAoB,SAAS,kBAAA,EAAmB;AAAA;AAAA,EAGvE,EAAE,MAAA,EAAQ,KAAA,EAAO,IAAA,EAAM,mBAAA,EAAqB,SAAS,aAAA,EAAc;AAAA,EACnE,EAAE,MAAA,EAAQ,KAAA,EAAO,IAAA,EAAM,sBAAA,EAAwB,SAAS,YAAA,EAAc,MAAA,EAAQ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Content":["/**\n * UI Bridge Server Types\n *\n * Shared types for server adapters.\n */\n\nimport type { UIBridgeConfig } from '../core';\nimport type {\n ControlActionRequest,\n ControlActionResponse,\n ComponentActionRequest,\n ComponentActionResponse,\n FindRequest,\n FindResponse,\n ControlSnapshot,\n WorkflowRunRequest,\n WorkflowRunResponse,\n PageNavigateRequest,\n PageNavigationResponse,\n} from '../control';\nimport type { RenderLogEntry, RenderLogEntryType } from '../render-log';\nimport type {\n SearchCriteria,\n SearchResponse,\n NLActionRequest,\n NLActionResponse,\n AssertionRequest,\n AssertionResult,\n BatchAssertionRequest,\n BatchAssertionResult,\n SemanticSnapshot,\n SemanticDiff,\n SemanticSearchCriteria,\n SemanticSearchResponse,\n Intent,\n IntentSearchResponse,\n IntentExecutionResult,\n RecoveryAttemptRequest,\n RecoveryAttemptResult,\n PageDataMap,\n PageRegionMap,\n StructuredDataExtraction,\n CrossAppComparisonReport,\n ComponentInfo,\n} from '../ai';\nimport type {\n UIState,\n UIStateGroup,\n UITransition,\n PathResult,\n TransitionResult,\n NavigationResult,\n StateSnapshot,\n} from '../core';\nimport type { ElementAnnotation, AnnotationConfig, AnnotationCoverage } from '../annotations';\nimport type { CapturedError } from '../debug/browser-capture-types';\n\n/**\n * Server configuration\n */\nexport interface UIBridgeServerConfig extends UIBridgeConfig {\n /** Base path for API routes */\n basePath?: string;\n /** Enable CORS */\n cors?: boolean | CORSOptions;\n /** Authentication middleware */\n authenticate?: (req: unknown) => boolean | Promise<boolean>;\n /** Rate limiting */\n rateLimit?: RateLimitOptions;\n}\n\n/**\n * CORS options\n */\nexport interface CORSOptions {\n /** Allowed origins */\n origin?: string | string[] | boolean;\n /** Allowed methods */\n methods?: string[];\n /** Allowed headers */\n headers?: string[];\n /** Expose headers */\n exposeHeaders?: string[];\n /** Allow credentials */\n credentials?: boolean;\n /** Max age for preflight cache */\n maxAge?: number;\n}\n\n/**\n * Rate limit options\n */\nexport interface RateLimitOptions {\n /** Time window in milliseconds */\n windowMs?: number;\n /** Max requests per window */\n max?: number;\n /** Message when rate limited */\n message?: string;\n}\n\n/**\n * API response wrapper\n */\nexport interface APIResponse<T = unknown> {\n /** Whether the request succeeded */\n success: boolean;\n /** Response data */\n data?: T;\n /** Error message if failed */\n error?: string;\n /** Error code */\n code?: string;\n /** Request timestamp */\n timestamp: number;\n}\n\n/**\n * Render log query parameters\n */\nexport interface RenderLogQuery {\n /** Filter by entry type */\n type?: RenderLogEntryType;\n /** Filter entries since timestamp */\n since?: number;\n /** Filter entries until timestamp */\n until?: number;\n /** Limit number of results */\n limit?: number;\n}\n\n/**\n * Server handler interface\n *\n * Implementations provide these handlers for different frameworks.\n */\nexport interface UIBridgeServerHandlers {\n // Render log endpoints\n getRenderLog: (query?: RenderLogQuery) => Promise<APIResponse<RenderLogEntry[]>>;\n clearRenderLog: () => Promise<APIResponse<void>>;\n captureSnapshot: () => Promise<APIResponse<unknown>>;\n getRenderLogPath: () => Promise<APIResponse<{ path: string }>>;\n\n // Control endpoints\n getElements: () => Promise<APIResponse<ControlSnapshot['elements']>>;\n getElement: (id: string) => Promise<APIResponse<ControlSnapshot['elements'][0]>>;\n getElementState: (id: string) => Promise<APIResponse<unknown>>;\n executeElementAction: (\n id: string,\n request: ControlActionRequest\n ) => Promise<APIResponse<ControlActionResponse>>;\n\n // Component endpoints\n getComponents: () => Promise<APIResponse<ControlSnapshot['components']>>;\n getComponent: (id: string) => Promise<APIResponse<ControlSnapshot['components'][0]>>;\n getComponentState: (id: string) => Promise<\n APIResponse<{\n state: Record<string, unknown>;\n computed: Record<string, unknown>;\n timestamp: number;\n }>\n >;\n executeComponentAction: (\n id: string,\n request: ComponentActionRequest\n ) => Promise<APIResponse<ComponentActionResponse>>;\n\n // Find endpoints\n find: (request?: FindRequest) => Promise<APIResponse<FindResponse>>;\n /**\n * @deprecated Use find() instead\n */\n discover: (request?: FindRequest) => Promise<APIResponse<FindResponse>>;\n getControlSnapshot: () => Promise<APIResponse<ControlSnapshot>>;\n\n // Workflow endpoints\n getWorkflows: () => Promise<APIResponse<ControlSnapshot['workflows']>>;\n runWorkflow: (\n id: string,\n request?: WorkflowRunRequest\n ) => Promise<APIResponse<WorkflowRunResponse>>;\n getWorkflowStatus: (runId: string) => Promise<APIResponse<WorkflowRunResponse>>;\n\n // Debug endpoints\n getActionHistory: (limit?: number) => Promise<APIResponse<unknown[]>>;\n getMetrics: () => Promise<APIResponse<unknown>>;\n highlightElement: (id: string) => Promise<APIResponse<void>>;\n getElementTree: () => Promise<APIResponse<unknown>>;\n getConsoleErrors: (params?: {\n since?: number;\n limit?: number;\n }) => Promise<APIResponse<{ errors: CapturedError[]; count: number }>>;\n clearConsoleErrors: () => Promise<APIResponse<{ cleared: boolean }>>;\n\n // AI-native endpoints\n aiSearch: (criteria: SearchCriteria) => Promise<APIResponse<SearchResponse>>;\n aiExecute: (request: NLActionRequest) => Promise<APIResponse<NLActionResponse>>;\n aiAssert: (request: AssertionRequest) => Promise<APIResponse<AssertionResult>>;\n aiAssertBatch: (request: BatchAssertionRequest) => Promise<APIResponse<BatchAssertionResult>>;\n getSemanticSnapshot: () => Promise<APIResponse<SemanticSnapshot>>;\n getSemanticDiff: (since?: number) => Promise<APIResponse<SemanticDiff | null>>;\n getPageSummary: () => Promise<APIResponse<string>>;\n\n // Semantic search (embedding-based)\n aiSemanticSearch: (\n criteria: SemanticSearchCriteria\n ) => Promise<APIResponse<SemanticSearchResponse>>;\n\n // State management endpoints\n getStates: () => Promise<APIResponse<UIState[]>>;\n getState: (id: string) => Promise<APIResponse<UIState>>;\n getActiveStates: () => Promise<APIResponse<UIState[]>>;\n activateState: (id: string) => Promise<APIResponse<void>>;\n deactivateState: (id: string) => Promise<APIResponse<void>>;\n getStateGroups: () => Promise<APIResponse<UIStateGroup[]>>;\n activateStateGroup: (id: string) => Promise<APIResponse<void>>;\n deactivateStateGroup: (id: string) => Promise<APIResponse<void>>;\n getTransitions: () => Promise<APIResponse<UITransition[]>>;\n canExecuteTransition: (\n id: string\n ) => Promise<APIResponse<{ canExecute: boolean; reason?: string }>>;\n executeTransition: (id: string) => Promise<APIResponse<TransitionResult>>;\n findPath: (request: { targetStates: string[] }) => Promise<APIResponse<PathResult>>;\n navigateTo: (request: { targetStates: string[] }) => Promise<APIResponse<NavigationResult>>;\n getStateSnapshot: () => Promise<APIResponse<StateSnapshot>>;\n\n // Intent endpoints\n executeIntent: (request: {\n intentId: string;\n params?: Record<string, unknown>;\n }) => Promise<APIResponse<IntentExecutionResult>>;\n findIntent: (request: { query: string }) => Promise<APIResponse<IntentSearchResponse>>;\n listIntents: () => Promise<APIResponse<Intent[]>>;\n registerIntent: (intent: Intent) => Promise<APIResponse<Intent>>;\n executeIntentFromQuery: (request: {\n query: string;\n params?: Record<string, unknown>;\n }) => Promise<APIResponse<IntentExecutionResult>>;\n\n // Recovery endpoints\n attemptRecovery: (request: RecoveryAttemptRequest) => Promise<APIResponse<RecoveryAttemptResult>>;\n\n // Cross-app analysis endpoints\n analyzePageData: () => Promise<APIResponse<PageDataMap>>;\n analyzePageRegions: () => Promise<APIResponse<PageRegionMap>>;\n analyzeStructuredData: () => Promise<APIResponse<StructuredDataExtraction>>;\n crossAppCompare: (request: {\n sourceSnapshot: SemanticSnapshot;\n targetSnapshot: SemanticSnapshot;\n sourceComponents?: ComponentInfo[];\n targetComponents?: ComponentInfo[];\n }) => Promise<APIResponse<CrossAppComparisonReport>>;\n\n // Page navigation endpoints\n pageRefresh: () => Promise<APIResponse<PageNavigationResponse>>;\n pageNavigate: (request: PageNavigateRequest) => Promise<APIResponse<PageNavigationResponse>>;\n pageGoBack: () => Promise<APIResponse<PageNavigationResponse>>;\n pageGoForward: () => Promise<APIResponse<PageNavigationResponse>>;\n\n // Annotation endpoints\n getAnnotations: () => Promise<APIResponse<Record<string, ElementAnnotation>>>;\n getAnnotation: (id: string) => Promise<APIResponse<ElementAnnotation>>;\n setAnnotation: (\n id: string,\n annotation: ElementAnnotation\n ) => Promise<APIResponse<ElementAnnotation>>;\n deleteAnnotation: (id: string) => Promise<APIResponse<void>>;\n importAnnotations: (config: AnnotationConfig) => Promise<APIResponse<{ count: number }>>;\n exportAnnotations: () => Promise<APIResponse<AnnotationConfig>>;\n getAnnotationCoverage: () => Promise<APIResponse<AnnotationCoverage>>;\n\n // Performance diagnostics endpoints\n getPerformanceEntries: () => Promise<APIResponse<unknown>>;\n clearPerformanceEntries: () => Promise<APIResponse<{ cleared: boolean }>>;\n getBrowserEvents: (params?: {\n type?: string;\n since?: number;\n limit?: number;\n }) => Promise<APIResponse<{ events: unknown[]; count: number }>>;\n}\n\n/**\n * Route definition\n */\nexport interface RouteDefinition {\n method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n path: string;\n handler: string; // Key in UIBridgeServerHandlers\n params?: string[]; // URL params to extract\n bodyRequired?: boolean;\n}\n\n/**\n * All UI Bridge routes\n */\nexport const UI_BRIDGE_ROUTES: RouteDefinition[] = [\n // Render log\n { method: 'GET', path: '/render-log', handler: 'getRenderLog' },\n { method: 'DELETE', path: '/render-log', handler: 'clearRenderLog' },\n { method: 'POST', path: '/render-log/snapshot', handler: 'captureSnapshot' },\n { method: 'GET', path: '/render-log/path', handler: 'getRenderLogPath' },\n\n // Control - Elements\n { method: 'GET', path: '/control/elements', handler: 'getElements' },\n { method: 'GET', path: '/control/element/:id', handler: 'getElement', params: ['id'] },\n { method: 'GET', path: '/control/element/:id/state', handler: 'getElementState', params: ['id'] },\n {\n method: 'POST',\n path: '/control/element/:id/action',\n handler: 'executeElementAction',\n params: ['id'],\n bodyRequired: true,\n },\n\n // Control - Components\n { method: 'GET', path: '/control/components', handler: 'getComponents' },\n { method: 'GET', path: '/control/component/:id', handler: 'getComponent', params: ['id'] },\n {\n method: 'GET',\n path: '/control/component/:id/state',\n handler: 'getComponentState',\n params: ['id'],\n },\n {\n method: 'POST',\n path: '/control/component/:id/action/:actionId',\n handler: 'executeComponentAction',\n params: ['id', 'actionId'],\n bodyRequired: true,\n },\n\n // Find (formerly Discovery)\n { method: 'POST', path: '/control/find', handler: 'find' },\n { method: 'POST', path: '/control/discover', handler: 'discover' }, // @deprecated Use /control/find\n { method: 'GET', path: '/control/snapshot', handler: 'getControlSnapshot' },\n\n // Workflows\n { method: 'GET', path: '/control/workflows', handler: 'getWorkflows' },\n { method: 'POST', path: '/control/workflow/:id/run', handler: 'runWorkflow', params: ['id'] },\n {\n method: 'GET',\n path: '/control/workflow/:runId/status',\n handler: 'getWorkflowStatus',\n params: ['runId'],\n },\n\n // Debug\n { method: 'GET', path: '/debug/action-history', handler: 'getActionHistory' },\n { method: 'GET', path: '/debug/metrics', handler: 'getMetrics' },\n { method: 'POST', path: '/debug/highlight/:id', handler: 'highlightElement', params: ['id'] },\n { method: 'GET', path: '/debug/element-tree', handler: 'getElementTree' },\n { method: 'GET', path: '/control/console-errors', handler: 'getConsoleErrors' },\n { method: 'POST', path: '/control/console-errors/clear', handler: 'clearConsoleErrors' },\n\n // AI-native endpoints\n { method: 'POST', path: '/ai/search', handler: 'aiSearch', bodyRequired: true },\n { method: 'POST', path: '/ai/execute', handler: 'aiExecute', bodyRequired: true },\n { method: 'POST', path: '/ai/assert', handler: 'aiAssert', bodyRequired: true },\n { method: 'POST', path: '/ai/assert/batch', handler: 'aiAssertBatch', bodyRequired: true },\n { method: 'GET', path: '/ai/snapshot', handler: 'getSemanticSnapshot' },\n { method: 'GET', path: '/ai/diff', handler: 'getSemanticDiff' },\n { method: 'GET', path: '/ai/summary', handler: 'getPageSummary' },\n { method: 'POST', path: '/ai/semantic-search', handler: 'aiSemanticSearch', bodyRequired: true },\n\n // State management (static routes before parameterized)\n { method: 'GET', path: '/control/states', handler: 'getStates' },\n { method: 'GET', path: '/control/states/active', handler: 'getActiveStates' },\n { method: 'GET', path: '/control/states/snapshot', handler: 'getStateSnapshot' },\n { method: 'POST', path: '/control/states/find-path', handler: 'findPath', bodyRequired: true },\n { method: 'POST', path: '/control/states/navigate', handler: 'navigateTo', bodyRequired: true },\n { method: 'GET', path: '/control/state/:id', handler: 'getState', params: ['id'] },\n { method: 'POST', path: '/control/state/:id/activate', handler: 'activateState', params: ['id'] },\n {\n method: 'POST',\n path: '/control/state/:id/deactivate',\n handler: 'deactivateState',\n params: ['id'],\n },\n { method: 'GET', path: '/control/state-groups', handler: 'getStateGroups' },\n {\n method: 'POST',\n path: '/control/state-group/:id/activate',\n handler: 'activateStateGroup',\n params: ['id'],\n },\n {\n method: 'POST',\n path: '/control/state-group/:id/deactivate',\n handler: 'deactivateStateGroup',\n params: ['id'],\n },\n { method: 'GET', path: '/control/transitions', handler: 'getTransitions' },\n {\n method: 'GET',\n path: '/control/transition/:id/can-execute',\n handler: 'canExecuteTransition',\n params: ['id'],\n },\n {\n method: 'POST',\n path: '/control/transition/:id/execute',\n handler: 'executeTransition',\n params: ['id'],\n },\n\n // Intent endpoints\n { method: 'GET', path: '/ai/intents', handler: 'listIntents' },\n { method: 'POST', path: '/ai/intents/execute', handler: 'executeIntent', bodyRequired: true },\n { method: 'POST', path: '/ai/intents/find', handler: 'findIntent', bodyRequired: true },\n { method: 'POST', path: '/ai/intents/register', handler: 'registerIntent', bodyRequired: true },\n {\n method: 'POST',\n path: '/ai/intents/execute-from-query',\n handler: 'executeIntentFromQuery',\n bodyRequired: true,\n },\n\n // Recovery endpoints\n {\n method: 'POST',\n path: '/ai/recovery/attempt',\n handler: 'attemptRecovery',\n bodyRequired: true,\n },\n\n // Cross-app analysis endpoints\n { method: 'GET', path: '/ai/analyze/data', handler: 'analyzePageData' },\n { method: 'GET', path: '/ai/analyze/regions', handler: 'analyzePageRegions' },\n { method: 'GET', path: '/ai/analyze/structured-data', handler: 'analyzeStructuredData' },\n {\n method: 'POST',\n path: '/ai/analyze/cross-app-compare',\n handler: 'crossAppCompare',\n bodyRequired: true,\n },\n\n // Page navigation\n { method: 'POST', path: '/control/page/refresh', handler: 'pageRefresh' },\n { method: 'POST', path: '/control/page/navigate', handler: 'pageNavigate', bodyRequired: true },\n { method: 'POST', path: '/control/page/back', handler: 'pageGoBack' },\n { method: 'POST', path: '/control/page/forward', handler: 'pageGoForward' },\n\n // Annotations (static routes before parameterized)\n { method: 'GET', path: '/annotations', handler: 'getAnnotations' },\n { method: 'GET', path: '/annotations/export', handler: 'exportAnnotations' },\n { method: 'GET', path: '/annotations/coverage', handler: 'getAnnotationCoverage' },\n { method: 'POST', path: '/annotations/import', handler: 'importAnnotations', bodyRequired: true },\n { method: 'GET', path: '/annotations/:id', handler: 'getAnnotation', params: ['id'] },\n {\n method: 'PUT',\n path: '/annotations/:id',\n handler: 'setAnnotation',\n params: ['id'],\n bodyRequired: true,\n },\n { method: 'DELETE', path: '/annotations/:id', handler: 'deleteAnnotation', params: ['id'] },\n\n // Performance diagnostics\n { method: 'GET', path: '/control/performance-entries', handler: 'getPerformanceEntries' },\n {\n method: 'POST',\n path: '/control/performance-entries/clear',\n handler: 'clearPerformanceEntries',\n },\n { method: 'GET', path: '/control/browser-events', handler: 'getBrowserEvents' },\n];\n\n/**\n * WebSocket message types\n */\nexport type WebSocketMessageType =\n | 'subscribe'\n | 'unsubscribe'\n | 'event'\n | 'snapshot'\n | 'action'\n | 'error';\n\n/**\n * WebSocket message\n */\nexport interface WebSocketMessage<T = unknown> {\n type: WebSocketMessageType;\n channel?: string;\n data?: T;\n error?: string;\n timestamp: number;\n}\n","/**\n * Express Adapter\n *\n * Express.js middleware for UI Bridge server.\n */\n\nimport type { Router, Request, Response, NextFunction } from 'express';\nimport type {\n UIBridgeServerConfig,\n UIBridgeServerHandlers,\n APIResponse,\n RouteDefinition,\n CORSOptions,\n} from './types';\nimport { UI_BRIDGE_ROUTES } from './types';\n\n/**\n * Express-specific configuration\n */\nexport interface ExpressAdapterConfig extends UIBridgeServerConfig {\n /** Use JSON body parser (if not already configured) */\n useBodyParser?: boolean;\n}\n\n/**\n * Create CORS middleware\n */\nfunction createCORSMiddleware(options: CORSOptions | boolean) {\n const corsOptions: CORSOptions =\n typeof options === 'boolean'\n ? { origin: options, methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'] }\n : options;\n\n return (req: Request, res: Response, next: NextFunction) => {\n // Origin\n if (corsOptions.origin === true) {\n res.setHeader('Access-Control-Allow-Origin', '*');\n } else if (typeof corsOptions.origin === 'string') {\n res.setHeader('Access-Control-Allow-Origin', corsOptions.origin);\n } else if (Array.isArray(corsOptions.origin)) {\n const origin = req.headers.origin;\n if (origin && corsOptions.origin.includes(origin)) {\n res.setHeader('Access-Control-Allow-Origin', origin);\n }\n }\n\n // Methods\n if (corsOptions.methods) {\n res.setHeader('Access-Control-Allow-Methods', corsOptions.methods.join(', '));\n }\n\n // Headers\n if (corsOptions.headers) {\n res.setHeader('Access-Control-Allow-Headers', corsOptions.headers.join(', '));\n } else {\n res.setHeader(\n 'Access-Control-Allow-Headers',\n 'Content-Type, Authorization, X-Requested-With'\n );\n }\n\n // Credentials\n if (corsOptions.credentials) {\n res.setHeader('Access-Control-Allow-Credentials', 'true');\n }\n\n // Max age\n if (corsOptions.maxAge) {\n res.setHeader('Access-Control-Max-Age', String(corsOptions.maxAge));\n }\n\n // Handle preflight\n if (req.method === 'OPTIONS') {\n res.status(204).end();\n return;\n }\n\n next();\n };\n}\n\n/**\n * Wrap error in API format\n */\nfunction wrapError(error: Error | string, code?: string): APIResponse<never> {\n return {\n success: false,\n error: typeof error === 'string' ? error : error.message,\n code,\n timestamp: Date.now(),\n };\n}\n\n/**\n * Create Express router with UI Bridge routes\n */\nexport function createExpressRouter(\n handlers: UIBridgeServerHandlers,\n config: ExpressAdapterConfig = {}\n): Router {\n // Dynamic import to avoid bundling Express if not used\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const express = require('express');\n const router: Router = express.Router();\n\n // Add CORS middleware if configured\n if (config.cors) {\n router.use(createCORSMiddleware(config.cors));\n }\n\n // Add body parser if requested\n if (config.useBodyParser) {\n router.use(express.json());\n }\n\n // Add authentication middleware if configured\n if (config.authenticate) {\n router.use(async (req: Request, res: Response, next: NextFunction) => {\n try {\n const authenticated = await config.authenticate!(req);\n if (!authenticated) {\n res.status(401).json(wrapError('Unauthorized', 'UNAUTHORIZED'));\n return;\n }\n next();\n } catch (error) {\n res.status(500).json(wrapError(error as Error, 'AUTH_ERROR'));\n }\n });\n }\n\n // Register routes\n for (const route of UI_BRIDGE_ROUTES) {\n const method = route.method.toLowerCase() as 'get' | 'post' | 'put' | 'delete' | 'patch';\n const path = route.path;\n const handlerName = route.handler as keyof UIBridgeServerHandlers;\n const handler = handlers[handlerName];\n\n if (!handler) {\n console.warn(`Handler not found for route: ${route.method} ${route.path}`);\n continue;\n }\n\n router[method](\n path,\n createRouteHandler(route, handler as (...args: unknown[]) => Promise<APIResponse<unknown>>)\n );\n }\n\n return router;\n}\n\n/**\n * Create a route handler from a route definition\n */\nfunction createRouteHandler(\n route: RouteDefinition,\n handler: (...args: unknown[]) => Promise<APIResponse<unknown>>\n) {\n return async (req: Request, res: Response) => {\n try {\n // Extract params\n const args: unknown[] = [];\n\n if (route.params) {\n for (const param of route.params) {\n args.push(req.params[param]);\n }\n }\n\n // Add body if required\n if (route.bodyRequired || route.method === 'POST') {\n args.push(req.body);\n }\n\n // Add query params for GET requests\n if (route.method === 'GET' && Object.keys(req.query).length > 0) {\n args.push(req.query);\n }\n\n const result = await handler(...args);\n res.json(result);\n } catch (error) {\n res.status(500).json(wrapError(error as Error, 'INTERNAL_ERROR'));\n }\n };\n}\n\n/**\n * Create Express app with UI Bridge routes\n *\n * Convenience function that creates a complete Express app with UI Bridge.\n */\nexport function createExpressApp(\n handlers: UIBridgeServerHandlers,\n config: ExpressAdapterConfig = {}\n): unknown {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const express = require('express');\n const app = express();\n\n app.use(express.json());\n\n const basePath = config.basePath || '/ui-bridge';\n const router = createExpressRouter(handlers, { ...config, useBodyParser: false });\n\n app.use(basePath, router);\n\n // Health check\n app.get('/health', (_req: Request, res: Response) => {\n res.json({ status: 'ok', timestamp: Date.now() });\n });\n\n return app;\n}\n\n/**\n * Express middleware that adds UI Bridge to an existing app\n */\nexport function uiBridgeMiddleware(\n handlers: UIBridgeServerHandlers,\n config: ExpressAdapterConfig = {}\n): Router {\n return createExpressRouter(handlers, config);\n}\n"]}
|