@qontinui/ui-bridge 0.2.0 → 0.3.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.
- package/dist/ai/index.d.mts +4 -4
- package/dist/ai/index.d.ts +4 -4
- package/dist/babel-plugin/index.js +515 -0
- package/dist/babel-plugin/index.js.map +1 -0
- package/dist/babel-plugin/index.mjs +499 -0
- package/dist/babel-plugin/index.mjs.map +1 -0
- package/dist/control/index.d.mts +5 -5
- package/dist/control/index.d.ts +5 -5
- 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 +3 -3
- package/dist/debug/index.d.ts +3 -3
- package/dist/index.d.mts +7 -8
- package/dist/index.d.ts +7 -8
- package/dist/index.js +859 -873
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +860 -862
- package/dist/index.mjs.map +1 -1
- package/dist/{metrics-C9XRi_mL.d.ts → metrics-BfiT_rhZ.d.ts} +2 -2
- package/dist/{metrics-NC3csD0R.d.mts → metrics-DTA2bwG7.d.mts} +2 -2
- package/dist/native/control/index.js +453 -0
- package/dist/native/control/index.js.map +1 -0
- package/dist/native/control/index.mjs +450 -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 +451 -0
- package/dist/native/debug/index.js.map +1 -0
- package/dist/native/debug/index.mjs +449 -0
- package/dist/native/debug/index.mjs.map +1 -0
- package/dist/native/index.js +2274 -0
- package/dist/native/index.js.map +1 -0
- package/dist/native/index.mjs +2246 -0
- package/dist/native/index.mjs.map +1 -0
- package/dist/native/react/index.js +1401 -0
- package/dist/native/react/index.js.map +1 -0
- package/dist/native/react/index.mjs +1389 -0
- package/dist/native/react/index.mjs.map +1 -0
- package/dist/native/server/index.js +415 -0
- package/dist/native/server/index.js.map +1 -0
- package/dist/native/server/index.mjs +410 -0
- package/dist/native/server/index.mjs.map +1 -0
- package/dist/react/index.d.mts +20 -7
- package/dist/react/index.d.ts +20 -7
- package/dist/react/index.js +42 -4
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +42 -4
- package/dist/react/index.mjs.map +1 -1
- package/dist/{registry-CIEDjbQ9.d.ts → registry-BKLEm-yk.d.ts} +9 -15
- package/dist/{registry-SsSDq46X.d.mts → registry-BmZgyCz8.d.mts} +9 -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 +36 -0
- package/dist/server/express.d.ts +36 -0
- package/dist/server/express.js +196 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/express.mjs +192 -0
- package/dist/server/express.mjs.map +1 -0
- package/dist/server/handlers.d.mts +93 -0
- package/dist/server/handlers.d.ts +93 -0
- package/dist/server/handlers.js +4278 -0
- package/dist/server/handlers.js.map +1 -0
- package/dist/server/handlers.mjs +4275 -0
- package/dist/server/handlers.mjs.map +1 -0
- package/dist/server/index.d.mts +10 -0
- package/dist/server/index.d.ts +10 -0
- package/dist/server/index.js +5352 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +5337 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/server/nextjs.d.mts +126 -0
- package/dist/server/nextjs.d.ts +126 -0
- package/dist/server/nextjs.js +287 -0
- package/dist/server/nextjs.js.map +1 -0
- package/dist/server/nextjs.mjs +282 -0
- package/dist/server/nextjs.mjs.map +1 -0
- package/dist/server/standalone.d.mts +6 -0
- package/dist/server/standalone.d.ts +6 -0
- package/dist/server/standalone.js +719 -0
- package/dist/server/standalone.js.map +1 -0
- package/dist/server/standalone.mjs +715 -0
- package/dist/server/standalone.mjs.map +1 -0
- package/dist/standalone-BURj8J3G.d.ts +212 -0
- package/dist/standalone-Dwmel29d.d.mts +212 -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-CFT3Dnx4.d.mts → types-B5Q0GVo0.d.mts} +115 -3
- package/dist/{types-Dr6tH-bm.d.mts → types-B7J7noLK.d.mts} +1 -1
- package/dist/{types-oCTrRxSw.d.ts → types-BkNRILUa.d.ts} +1 -1
- package/dist/types-CEQLnFMv.d.mts +156 -0
- package/dist/types-CHnlwiTK.d.ts +156 -0
- package/dist/{types-BvCfFuEV.d.ts → types-DfPqwU-i.d.ts} +115 -3
- package/dist/{types-CPMbN_Iw.d.mts → types-jKVgTI6_.d.mts} +356 -160
- package/dist/{types-CPMbN_Iw.d.ts → types-jKVgTI6_.d.ts} +356 -160
- package/package.json +106 -3
- package/swc-plugin-wasm/ui_bridge_swc_plugin.wasm +0 -0
- 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 { S as SearchCriteria, o as SearchResult } from './types-
|
|
1
|
+
import { j as BridgeEventListener, k as BridgeEventType, r as ElementType, S as StandardAction, o as CustomAction, x as RegisteredElement, y as StateGetter, w as RegisteredComponent, m as ComponentStateResponse, af as Workflow, F as UIState, G as UIStateGroup, H as UITransition, T as TransitionResult, v as PathResult, N as NavigationResult, z as StateSnapshot, l as BridgeSnapshot } from './types-jKVgTI6_.js';
|
|
2
|
+
import { S as SearchCriteria, o as SearchResult } from './types-DfPqwU-i.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Element and Component Registry
|
|
@@ -103,6 +103,8 @@ declare class UIBridgeRegistry {
|
|
|
103
103
|
handler: (params?: unknown) => unknown | Promise<unknown>;
|
|
104
104
|
}>;
|
|
105
105
|
elementIds?: string[];
|
|
106
|
+
getState?: StateGetter<Record<string, unknown>>;
|
|
107
|
+
getComputed?: () => Record<string, unknown>;
|
|
106
108
|
}): RegisteredComponent;
|
|
107
109
|
/**
|
|
108
110
|
* Unregister a component
|
|
@@ -116,6 +118,10 @@ declare class UIBridgeRegistry {
|
|
|
116
118
|
* Get all registered components
|
|
117
119
|
*/
|
|
118
120
|
getAllComponents(): RegisteredComponent[];
|
|
121
|
+
/**
|
|
122
|
+
* Get the current state and computed properties of a component
|
|
123
|
+
*/
|
|
124
|
+
getComponentState(id: string): ComponentStateResponse | null;
|
|
119
125
|
/**
|
|
120
126
|
* Register a workflow
|
|
121
127
|
*/
|
|
@@ -258,17 +264,5 @@ declare class UIBridgeRegistry {
|
|
|
258
264
|
activeStateCount: number;
|
|
259
265
|
};
|
|
260
266
|
}
|
|
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
267
|
|
|
274
|
-
export {
|
|
268
|
+
export { UIBridgeRegistry as U };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { S as SearchCriteria, o as SearchResult } from './types-
|
|
1
|
+
import { j as BridgeEventListener, k as BridgeEventType, r as ElementType, S as StandardAction, o as CustomAction, x as RegisteredElement, y as StateGetter, w as RegisteredComponent, m as ComponentStateResponse, af as Workflow, F as UIState, G as UIStateGroup, H as UITransition, T as TransitionResult, v as PathResult, N as NavigationResult, z as StateSnapshot, l as BridgeSnapshot } from './types-jKVgTI6_.mjs';
|
|
2
|
+
import { S as SearchCriteria, o as SearchResult } from './types-B5Q0GVo0.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Element and Component Registry
|
|
@@ -103,6 +103,8 @@ declare class UIBridgeRegistry {
|
|
|
103
103
|
handler: (params?: unknown) => unknown | Promise<unknown>;
|
|
104
104
|
}>;
|
|
105
105
|
elementIds?: string[];
|
|
106
|
+
getState?: StateGetter<Record<string, unknown>>;
|
|
107
|
+
getComputed?: () => Record<string, unknown>;
|
|
106
108
|
}): RegisteredComponent;
|
|
107
109
|
/**
|
|
108
110
|
* Unregister a component
|
|
@@ -116,6 +118,10 @@ declare class UIBridgeRegistry {
|
|
|
116
118
|
* Get all registered components
|
|
117
119
|
*/
|
|
118
120
|
getAllComponents(): RegisteredComponent[];
|
|
121
|
+
/**
|
|
122
|
+
* Get the current state and computed properties of a component
|
|
123
|
+
*/
|
|
124
|
+
getComponentState(id: string): ComponentStateResponse | null;
|
|
119
125
|
/**
|
|
120
126
|
* Register a workflow
|
|
121
127
|
*/
|
|
@@ -258,17 +264,5 @@ declare class UIBridgeRegistry {
|
|
|
258
264
|
activeStateCount: number;
|
|
259
265
|
};
|
|
260
266
|
}
|
|
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
267
|
|
|
274
|
-
export {
|
|
268
|
+
export { UIBridgeRegistry as U };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import { U as UIBridgeServerConfig, c as UIBridgeServerHandlers } from '../types-CEQLnFMv.mjs';
|
|
3
|
+
import '../types-jKVgTI6_.mjs';
|
|
4
|
+
import '../types-B7J7noLK.mjs';
|
|
5
|
+
import '../types-B5Q0GVo0.mjs';
|
|
6
|
+
import '../render-log/index.mjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Express Adapter
|
|
10
|
+
*
|
|
11
|
+
* Express.js middleware for UI Bridge server.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Express-specific configuration
|
|
16
|
+
*/
|
|
17
|
+
interface ExpressAdapterConfig extends UIBridgeServerConfig {
|
|
18
|
+
/** Use JSON body parser (if not already configured) */
|
|
19
|
+
useBodyParser?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create Express router with UI Bridge routes
|
|
23
|
+
*/
|
|
24
|
+
declare function createExpressRouter(handlers: UIBridgeServerHandlers, config?: ExpressAdapterConfig): Router;
|
|
25
|
+
/**
|
|
26
|
+
* Create Express app with UI Bridge routes
|
|
27
|
+
*
|
|
28
|
+
* Convenience function that creates a complete Express app with UI Bridge.
|
|
29
|
+
*/
|
|
30
|
+
declare function createExpressApp(handlers: UIBridgeServerHandlers, config?: ExpressAdapterConfig): unknown;
|
|
31
|
+
/**
|
|
32
|
+
* Express middleware that adds UI Bridge to an existing app
|
|
33
|
+
*/
|
|
34
|
+
declare function uiBridgeMiddleware(handlers: UIBridgeServerHandlers, config?: ExpressAdapterConfig): Router;
|
|
35
|
+
|
|
36
|
+
export { type ExpressAdapterConfig, createExpressApp, createExpressRouter, uiBridgeMiddleware };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import { U as UIBridgeServerConfig, c as UIBridgeServerHandlers } from '../types-CHnlwiTK.js';
|
|
3
|
+
import '../types-jKVgTI6_.js';
|
|
4
|
+
import '../types-BkNRILUa.js';
|
|
5
|
+
import '../types-DfPqwU-i.js';
|
|
6
|
+
import '../render-log/index.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Express Adapter
|
|
10
|
+
*
|
|
11
|
+
* Express.js middleware for UI Bridge server.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Express-specific configuration
|
|
16
|
+
*/
|
|
17
|
+
interface ExpressAdapterConfig extends UIBridgeServerConfig {
|
|
18
|
+
/** Use JSON body parser (if not already configured) */
|
|
19
|
+
useBodyParser?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create Express router with UI Bridge routes
|
|
23
|
+
*/
|
|
24
|
+
declare function createExpressRouter(handlers: UIBridgeServerHandlers, config?: ExpressAdapterConfig): Router;
|
|
25
|
+
/**
|
|
26
|
+
* Create Express app with UI Bridge routes
|
|
27
|
+
*
|
|
28
|
+
* Convenience function that creates a complete Express app with UI Bridge.
|
|
29
|
+
*/
|
|
30
|
+
declare function createExpressApp(handlers: UIBridgeServerHandlers, config?: ExpressAdapterConfig): unknown;
|
|
31
|
+
/**
|
|
32
|
+
* Express middleware that adds UI Bridge to an existing app
|
|
33
|
+
*/
|
|
34
|
+
declare function uiBridgeMiddleware(handlers: UIBridgeServerHandlers, config?: ExpressAdapterConfig): Router;
|
|
35
|
+
|
|
36
|
+
export { type ExpressAdapterConfig, createExpressApp, createExpressRouter, uiBridgeMiddleware };
|
|
@@ -0,0 +1,196 @@
|
|
|
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
|
+
{ method: "GET", path: "/control/component/:id/state", handler: "getComponentState", params: ["id"] },
|
|
32
|
+
{
|
|
33
|
+
method: "POST",
|
|
34
|
+
path: "/control/component/:id/action/:actionId",
|
|
35
|
+
handler: "executeComponentAction",
|
|
36
|
+
params: ["id", "actionId"],
|
|
37
|
+
bodyRequired: true
|
|
38
|
+
},
|
|
39
|
+
// Find (formerly Discovery)
|
|
40
|
+
{ method: "POST", path: "/control/find", handler: "find" },
|
|
41
|
+
{ method: "POST", path: "/control/discover", handler: "discover" },
|
|
42
|
+
// @deprecated Use /control/find
|
|
43
|
+
{ method: "GET", path: "/control/snapshot", handler: "getControlSnapshot" },
|
|
44
|
+
// Workflows
|
|
45
|
+
{ method: "GET", path: "/control/workflows", handler: "getWorkflows" },
|
|
46
|
+
{ method: "POST", path: "/control/workflow/:id/run", handler: "runWorkflow", params: ["id"] },
|
|
47
|
+
{
|
|
48
|
+
method: "GET",
|
|
49
|
+
path: "/control/workflow/:runId/status",
|
|
50
|
+
handler: "getWorkflowStatus",
|
|
51
|
+
params: ["runId"]
|
|
52
|
+
},
|
|
53
|
+
// Debug
|
|
54
|
+
{ method: "GET", path: "/debug/action-history", handler: "getActionHistory" },
|
|
55
|
+
{ method: "GET", path: "/debug/metrics", handler: "getMetrics" },
|
|
56
|
+
{ method: "POST", path: "/debug/highlight/:id", handler: "highlightElement", params: ["id"] },
|
|
57
|
+
{ method: "GET", path: "/debug/element-tree", handler: "getElementTree" },
|
|
58
|
+
// AI-native endpoints
|
|
59
|
+
{ method: "POST", path: "/ai/search", handler: "aiSearch", bodyRequired: true },
|
|
60
|
+
{ method: "POST", path: "/ai/execute", handler: "aiExecute", bodyRequired: true },
|
|
61
|
+
{ method: "POST", path: "/ai/assert", handler: "aiAssert", bodyRequired: true },
|
|
62
|
+
{ method: "POST", path: "/ai/assert/batch", handler: "aiAssertBatch", bodyRequired: true },
|
|
63
|
+
{ method: "GET", path: "/ai/snapshot", handler: "getSemanticSnapshot" },
|
|
64
|
+
{ method: "GET", path: "/ai/diff", handler: "getSemanticDiff" },
|
|
65
|
+
{ method: "GET", path: "/ai/summary", handler: "getPageSummary" },
|
|
66
|
+
{ method: "POST", path: "/ai/semantic-search", handler: "aiSemanticSearch", bodyRequired: true }
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
// src/server/express.ts
|
|
70
|
+
function createCORSMiddleware(options) {
|
|
71
|
+
const corsOptions = typeof options === "boolean" ? { origin: options, methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"] } : options;
|
|
72
|
+
return (req, res, next) => {
|
|
73
|
+
if (corsOptions.origin === true) {
|
|
74
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
75
|
+
} else if (typeof corsOptions.origin === "string") {
|
|
76
|
+
res.setHeader("Access-Control-Allow-Origin", corsOptions.origin);
|
|
77
|
+
} else if (Array.isArray(corsOptions.origin)) {
|
|
78
|
+
const origin = req.headers.origin;
|
|
79
|
+
if (origin && corsOptions.origin.includes(origin)) {
|
|
80
|
+
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (corsOptions.methods) {
|
|
84
|
+
res.setHeader("Access-Control-Allow-Methods", corsOptions.methods.join(", "));
|
|
85
|
+
}
|
|
86
|
+
if (corsOptions.headers) {
|
|
87
|
+
res.setHeader("Access-Control-Allow-Headers", corsOptions.headers.join(", "));
|
|
88
|
+
} else {
|
|
89
|
+
res.setHeader(
|
|
90
|
+
"Access-Control-Allow-Headers",
|
|
91
|
+
"Content-Type, Authorization, X-Requested-With"
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
if (corsOptions.credentials) {
|
|
95
|
+
res.setHeader("Access-Control-Allow-Credentials", "true");
|
|
96
|
+
}
|
|
97
|
+
if (corsOptions.maxAge) {
|
|
98
|
+
res.setHeader("Access-Control-Max-Age", String(corsOptions.maxAge));
|
|
99
|
+
}
|
|
100
|
+
if (req.method === "OPTIONS") {
|
|
101
|
+
res.status(204).end();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
next();
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function wrapError(error, code) {
|
|
108
|
+
return {
|
|
109
|
+
success: false,
|
|
110
|
+
error: typeof error === "string" ? error : error.message,
|
|
111
|
+
code,
|
|
112
|
+
timestamp: Date.now()
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function createExpressRouter(handlers, config = {}) {
|
|
116
|
+
const express = __require("express");
|
|
117
|
+
const router = express.Router();
|
|
118
|
+
if (config.cors) {
|
|
119
|
+
router.use(createCORSMiddleware(config.cors));
|
|
120
|
+
}
|
|
121
|
+
if (config.useBodyParser) {
|
|
122
|
+
router.use(express.json());
|
|
123
|
+
}
|
|
124
|
+
if (config.authenticate) {
|
|
125
|
+
router.use(async (req, res, next) => {
|
|
126
|
+
try {
|
|
127
|
+
const authenticated = await config.authenticate(req);
|
|
128
|
+
if (!authenticated) {
|
|
129
|
+
res.status(401).json(wrapError("Unauthorized", "UNAUTHORIZED"));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
next();
|
|
133
|
+
} catch (error) {
|
|
134
|
+
res.status(500).json(wrapError(error, "AUTH_ERROR"));
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
for (const route of UI_BRIDGE_ROUTES) {
|
|
139
|
+
const method = route.method.toLowerCase();
|
|
140
|
+
const path = route.path;
|
|
141
|
+
const handlerName = route.handler;
|
|
142
|
+
const handler = handlers[handlerName];
|
|
143
|
+
if (!handler) {
|
|
144
|
+
console.warn(`Handler not found for route: ${route.method} ${route.path}`);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
router[method](
|
|
148
|
+
path,
|
|
149
|
+
createRouteHandler(route, handler)
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return router;
|
|
153
|
+
}
|
|
154
|
+
function createRouteHandler(route, handler) {
|
|
155
|
+
return async (req, res) => {
|
|
156
|
+
try {
|
|
157
|
+
const args = [];
|
|
158
|
+
if (route.params) {
|
|
159
|
+
for (const param of route.params) {
|
|
160
|
+
args.push(req.params[param]);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (route.bodyRequired || route.method === "POST") {
|
|
164
|
+
args.push(req.body);
|
|
165
|
+
}
|
|
166
|
+
if (route.method === "GET" && Object.keys(req.query).length > 0) {
|
|
167
|
+
args.push(req.query);
|
|
168
|
+
}
|
|
169
|
+
const result = await handler(...args);
|
|
170
|
+
res.json(result);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
res.status(500).json(wrapError(error, "INTERNAL_ERROR"));
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function createExpressApp(handlers, config = {}) {
|
|
177
|
+
const express = __require("express");
|
|
178
|
+
const app = express();
|
|
179
|
+
app.use(express.json());
|
|
180
|
+
const basePath = config.basePath || "/ui-bridge";
|
|
181
|
+
const router = createExpressRouter(handlers, { ...config, useBodyParser: false });
|
|
182
|
+
app.use(basePath, router);
|
|
183
|
+
app.get("/health", (_req, res) => {
|
|
184
|
+
res.json({ status: "ok", timestamp: Date.now() });
|
|
185
|
+
});
|
|
186
|
+
return app;
|
|
187
|
+
}
|
|
188
|
+
function uiBridgeMiddleware(handlers, config = {}) {
|
|
189
|
+
return createExpressRouter(handlers, config);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
exports.createExpressApp = createExpressApp;
|
|
193
|
+
exports.createExpressRouter = createExpressRouter;
|
|
194
|
+
exports.uiBridgeMiddleware = uiBridgeMiddleware;
|
|
195
|
+
//# sourceMappingURL=express.js.map
|
|
196
|
+
//# sourceMappingURL=express.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/server/types.ts","../../src/server/express.ts"],"names":[],"mappings":";;;;;;;;;;AA2LO,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,CAAC,IAAI,CAAA,EAAE;AAAA,EACrF,EAAE,MAAA,EAAQ,KAAA,EAAO,IAAA,EAAM,4BA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,CAAI,GAAA,CAAI,UAAU,MAAM,CAAA;AAGxB,EAAA,GAAA,CAAI,GAAA,CAAI,SAAA,EAAW,CAAC,IAAA,EAAe,GAAA,KAAkB;AACnD,IAAA,GAAA,CAAI,IAAA,CAAK,EAAE,MAAA,EAAQ,IAAA,EAAM,WAAW,IAAA,CAAK,GAAA,IAAO,CAAA;AAAA,EAClD,CAAC,CAAA;AAED,EAAA,OAAO,GAAA;AACT;AAKO,SAAS,kBAAA,CACd,QAAA,EACA,MAAA,GAA+B,EAAC,EACxB;AACR,EAAA,OAAO,mBAAA,CAAoB,UAAU,MAAM,CAAA;AAC7C","file":"express.js","sourcesContent":["/**\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} 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} from '../ai';\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<APIResponse<{ state: Record<string, unknown>; computed: Record<string, unknown>; timestamp: number }>>;\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\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: (criteria: SemanticSearchCriteria) => Promise<APIResponse<SemanticSearchResponse>>;\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 { method: 'GET', path: '/control/component/:id/state', handler: 'getComponentState', params: ['id'] },\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\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\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"]}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/server/types.ts
|
|
9
|
+
var UI_BRIDGE_ROUTES = [
|
|
10
|
+
// Render log
|
|
11
|
+
{ method: "GET", path: "/render-log", handler: "getRenderLog" },
|
|
12
|
+
{ method: "DELETE", path: "/render-log", handler: "clearRenderLog" },
|
|
13
|
+
{ method: "POST", path: "/render-log/snapshot", handler: "captureSnapshot" },
|
|
14
|
+
{ method: "GET", path: "/render-log/path", handler: "getRenderLogPath" },
|
|
15
|
+
// Control - Elements
|
|
16
|
+
{ method: "GET", path: "/control/elements", handler: "getElements" },
|
|
17
|
+
{ method: "GET", path: "/control/element/:id", handler: "getElement", params: ["id"] },
|
|
18
|
+
{ method: "GET", path: "/control/element/:id/state", handler: "getElementState", params: ["id"] },
|
|
19
|
+
{
|
|
20
|
+
method: "POST",
|
|
21
|
+
path: "/control/element/:id/action",
|
|
22
|
+
handler: "executeElementAction",
|
|
23
|
+
params: ["id"],
|
|
24
|
+
bodyRequired: true
|
|
25
|
+
},
|
|
26
|
+
// Control - Components
|
|
27
|
+
{ method: "GET", path: "/control/components", handler: "getComponents" },
|
|
28
|
+
{ method: "GET", path: "/control/component/:id", handler: "getComponent", params: ["id"] },
|
|
29
|
+
{ method: "GET", path: "/control/component/:id/state", handler: "getComponentState", params: ["id"] },
|
|
30
|
+
{
|
|
31
|
+
method: "POST",
|
|
32
|
+
path: "/control/component/:id/action/:actionId",
|
|
33
|
+
handler: "executeComponentAction",
|
|
34
|
+
params: ["id", "actionId"],
|
|
35
|
+
bodyRequired: true
|
|
36
|
+
},
|
|
37
|
+
// Find (formerly Discovery)
|
|
38
|
+
{ method: "POST", path: "/control/find", handler: "find" },
|
|
39
|
+
{ method: "POST", path: "/control/discover", handler: "discover" },
|
|
40
|
+
// @deprecated Use /control/find
|
|
41
|
+
{ method: "GET", path: "/control/snapshot", handler: "getControlSnapshot" },
|
|
42
|
+
// Workflows
|
|
43
|
+
{ method: "GET", path: "/control/workflows", handler: "getWorkflows" },
|
|
44
|
+
{ method: "POST", path: "/control/workflow/:id/run", handler: "runWorkflow", params: ["id"] },
|
|
45
|
+
{
|
|
46
|
+
method: "GET",
|
|
47
|
+
path: "/control/workflow/:runId/status",
|
|
48
|
+
handler: "getWorkflowStatus",
|
|
49
|
+
params: ["runId"]
|
|
50
|
+
},
|
|
51
|
+
// Debug
|
|
52
|
+
{ method: "GET", path: "/debug/action-history", handler: "getActionHistory" },
|
|
53
|
+
{ method: "GET", path: "/debug/metrics", handler: "getMetrics" },
|
|
54
|
+
{ method: "POST", path: "/debug/highlight/:id", handler: "highlightElement", params: ["id"] },
|
|
55
|
+
{ method: "GET", path: "/debug/element-tree", handler: "getElementTree" },
|
|
56
|
+
// AI-native endpoints
|
|
57
|
+
{ method: "POST", path: "/ai/search", handler: "aiSearch", bodyRequired: true },
|
|
58
|
+
{ method: "POST", path: "/ai/execute", handler: "aiExecute", bodyRequired: true },
|
|
59
|
+
{ method: "POST", path: "/ai/assert", handler: "aiAssert", bodyRequired: true },
|
|
60
|
+
{ method: "POST", path: "/ai/assert/batch", handler: "aiAssertBatch", bodyRequired: true },
|
|
61
|
+
{ method: "GET", path: "/ai/snapshot", handler: "getSemanticSnapshot" },
|
|
62
|
+
{ method: "GET", path: "/ai/diff", handler: "getSemanticDiff" },
|
|
63
|
+
{ method: "GET", path: "/ai/summary", handler: "getPageSummary" },
|
|
64
|
+
{ method: "POST", path: "/ai/semantic-search", handler: "aiSemanticSearch", bodyRequired: true }
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
// src/server/express.ts
|
|
68
|
+
function createCORSMiddleware(options) {
|
|
69
|
+
const corsOptions = typeof options === "boolean" ? { origin: options, methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"] } : options;
|
|
70
|
+
return (req, res, next) => {
|
|
71
|
+
if (corsOptions.origin === true) {
|
|
72
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
73
|
+
} else if (typeof corsOptions.origin === "string") {
|
|
74
|
+
res.setHeader("Access-Control-Allow-Origin", corsOptions.origin);
|
|
75
|
+
} else if (Array.isArray(corsOptions.origin)) {
|
|
76
|
+
const origin = req.headers.origin;
|
|
77
|
+
if (origin && corsOptions.origin.includes(origin)) {
|
|
78
|
+
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (corsOptions.methods) {
|
|
82
|
+
res.setHeader("Access-Control-Allow-Methods", corsOptions.methods.join(", "));
|
|
83
|
+
}
|
|
84
|
+
if (corsOptions.headers) {
|
|
85
|
+
res.setHeader("Access-Control-Allow-Headers", corsOptions.headers.join(", "));
|
|
86
|
+
} else {
|
|
87
|
+
res.setHeader(
|
|
88
|
+
"Access-Control-Allow-Headers",
|
|
89
|
+
"Content-Type, Authorization, X-Requested-With"
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
if (corsOptions.credentials) {
|
|
93
|
+
res.setHeader("Access-Control-Allow-Credentials", "true");
|
|
94
|
+
}
|
|
95
|
+
if (corsOptions.maxAge) {
|
|
96
|
+
res.setHeader("Access-Control-Max-Age", String(corsOptions.maxAge));
|
|
97
|
+
}
|
|
98
|
+
if (req.method === "OPTIONS") {
|
|
99
|
+
res.status(204).end();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
next();
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function wrapError(error, code) {
|
|
106
|
+
return {
|
|
107
|
+
success: false,
|
|
108
|
+
error: typeof error === "string" ? error : error.message,
|
|
109
|
+
code,
|
|
110
|
+
timestamp: Date.now()
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function createExpressRouter(handlers, config = {}) {
|
|
114
|
+
const express = __require("express");
|
|
115
|
+
const router = express.Router();
|
|
116
|
+
if (config.cors) {
|
|
117
|
+
router.use(createCORSMiddleware(config.cors));
|
|
118
|
+
}
|
|
119
|
+
if (config.useBodyParser) {
|
|
120
|
+
router.use(express.json());
|
|
121
|
+
}
|
|
122
|
+
if (config.authenticate) {
|
|
123
|
+
router.use(async (req, res, next) => {
|
|
124
|
+
try {
|
|
125
|
+
const authenticated = await config.authenticate(req);
|
|
126
|
+
if (!authenticated) {
|
|
127
|
+
res.status(401).json(wrapError("Unauthorized", "UNAUTHORIZED"));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
next();
|
|
131
|
+
} catch (error) {
|
|
132
|
+
res.status(500).json(wrapError(error, "AUTH_ERROR"));
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
for (const route of UI_BRIDGE_ROUTES) {
|
|
137
|
+
const method = route.method.toLowerCase();
|
|
138
|
+
const path = route.path;
|
|
139
|
+
const handlerName = route.handler;
|
|
140
|
+
const handler = handlers[handlerName];
|
|
141
|
+
if (!handler) {
|
|
142
|
+
console.warn(`Handler not found for route: ${route.method} ${route.path}`);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
router[method](
|
|
146
|
+
path,
|
|
147
|
+
createRouteHandler(route, handler)
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
return router;
|
|
151
|
+
}
|
|
152
|
+
function createRouteHandler(route, handler) {
|
|
153
|
+
return async (req, res) => {
|
|
154
|
+
try {
|
|
155
|
+
const args = [];
|
|
156
|
+
if (route.params) {
|
|
157
|
+
for (const param of route.params) {
|
|
158
|
+
args.push(req.params[param]);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (route.bodyRequired || route.method === "POST") {
|
|
162
|
+
args.push(req.body);
|
|
163
|
+
}
|
|
164
|
+
if (route.method === "GET" && Object.keys(req.query).length > 0) {
|
|
165
|
+
args.push(req.query);
|
|
166
|
+
}
|
|
167
|
+
const result = await handler(...args);
|
|
168
|
+
res.json(result);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
res.status(500).json(wrapError(error, "INTERNAL_ERROR"));
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function createExpressApp(handlers, config = {}) {
|
|
175
|
+
const express = __require("express");
|
|
176
|
+
const app = express();
|
|
177
|
+
app.use(express.json());
|
|
178
|
+
const basePath = config.basePath || "/ui-bridge";
|
|
179
|
+
const router = createExpressRouter(handlers, { ...config, useBodyParser: false });
|
|
180
|
+
app.use(basePath, router);
|
|
181
|
+
app.get("/health", (_req, res) => {
|
|
182
|
+
res.json({ status: "ok", timestamp: Date.now() });
|
|
183
|
+
});
|
|
184
|
+
return app;
|
|
185
|
+
}
|
|
186
|
+
function uiBridgeMiddleware(handlers, config = {}) {
|
|
187
|
+
return createExpressRouter(handlers, config);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export { createExpressApp, createExpressRouter, uiBridgeMiddleware };
|
|
191
|
+
//# sourceMappingURL=express.mjs.map
|
|
192
|
+
//# sourceMappingURL=express.mjs.map
|