@qontinui/ui-bridge-native 0.5.1 → 0.6.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/core/index.js +38 -4
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +38 -4
- package/dist/core/index.mjs.map +1 -1
- package/dist/core/registry.d.ts +30 -1
- package/dist/core/registry.d.ts.map +1 -1
- package/dist/core/types.d.ts +18 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +175 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +175 -29
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.js +150 -29
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +150 -29
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/useUIElement.d.ts +73 -35
- package/dist/react/useUIElement.d.ts.map +1 -1
- package/dist/server/handlers.d.ts.map +1 -1
- package/dist/server/http-server.d.ts.map +1 -1
- package/dist/server/index.js +84 -3
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +84 -3
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/types.d.ts +4 -0
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +3 -2
package/dist/react/index.mjs
CHANGED
|
@@ -254,7 +254,18 @@ var NativeUIBridgeRegistry = class {
|
|
|
254
254
|
return Array.from(this.elements.values());
|
|
255
255
|
}
|
|
256
256
|
/**
|
|
257
|
-
* Get all registered elements that are visible
|
|
257
|
+
* Get all registered elements that are visible AND have a measured layout.
|
|
258
|
+
*
|
|
259
|
+
* This is the *strict* visibility filter: requires `state.visible === true`
|
|
260
|
+
* AND `state.layout !== null`. Use this when you need both signals
|
|
261
|
+
* (e.g. coord-based tap, where you need an actual rect to hit-test against).
|
|
262
|
+
*
|
|
263
|
+
* Callers driving an LLM agent typically want
|
|
264
|
+
* {@link getMountedVisibleElements} instead — that variant accepts
|
|
265
|
+
* elements that *should* be on screen (visible:true) but whose first
|
|
266
|
+
* `onLayout` has not yet fired. Without it, a snapshot taken in the gap
|
|
267
|
+
* between mount and the first layout pass returns 0 elements on a fully
|
|
268
|
+
* populated screen.
|
|
258
269
|
*/
|
|
259
270
|
getVisibleElements() {
|
|
260
271
|
return this.getAllElements().filter((e) => {
|
|
@@ -262,6 +273,26 @@ var NativeUIBridgeRegistry = class {
|
|
|
262
273
|
return state.visible && state.layout !== null;
|
|
263
274
|
});
|
|
264
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* Get all registered elements marked as visible (regardless of layout).
|
|
278
|
+
*
|
|
279
|
+
* Looser than {@link getVisibleElements}: includes elements whose
|
|
280
|
+
* `onLayout` callback has not yet fired (so `layout === null`). React
|
|
281
|
+
* Native's `onLayout` is async — there's a one-tick window after mount
|
|
282
|
+
* where elements are in the tree, the user *sees* them, but the
|
|
283
|
+
* registry hasn't received their measurements yet. Excluding those
|
|
284
|
+
* elements makes `getSnapshot?visibleOnly=true` return 0 on a populated
|
|
285
|
+
* screen, which is a worse failure mode than including a few elements
|
|
286
|
+
* we can't yet locate spatially.
|
|
287
|
+
*
|
|
288
|
+
* Used by `createSnapshot`'s `visibleOnly` filter and by the
|
|
289
|
+
* `getSnapshot` / `getElements` handlers. Each emitted element carries a
|
|
290
|
+
* `visibility` discriminator (`"visible"` / `"likely-visible"`) so
|
|
291
|
+
* agents that *do* require a known rect can branch downstream.
|
|
292
|
+
*/
|
|
293
|
+
getMountedVisibleElements() {
|
|
294
|
+
return this.getAllElements().filter((e) => e.getState().visible);
|
|
295
|
+
}
|
|
265
296
|
/**
|
|
266
297
|
* Get elements registered on a specific route (for page-scoped filtering)
|
|
267
298
|
*/
|
|
@@ -536,7 +567,7 @@ var NativeUIBridgeRegistry = class {
|
|
|
536
567
|
}
|
|
537
568
|
return { currentRoute: null, segments: void 0 };
|
|
538
569
|
})();
|
|
539
|
-
let elements = options?.visibleOnly ? this.
|
|
570
|
+
let elements = options?.visibleOnly ? this.getMountedVisibleElements() : this.getAllElements();
|
|
540
571
|
if (options?.currentRouteOnly && resolvedRoute.currentRoute) {
|
|
541
572
|
const currentRoute = resolvedRoute.currentRoute;
|
|
542
573
|
elements = elements.filter((e) => e.registrationRoute === currentRoute);
|
|
@@ -545,16 +576,19 @@ var NativeUIBridgeRegistry = class {
|
|
|
545
576
|
timestamp: Date.now(),
|
|
546
577
|
elements: elements.map((e) => {
|
|
547
578
|
const handlers = extractHandlerNames(e.props);
|
|
579
|
+
const state = e.getState();
|
|
580
|
+
const visibility = !state.visible ? "hidden" : state.layout !== null ? "visible" : "likely-visible";
|
|
548
581
|
return {
|
|
549
582
|
id: e.id,
|
|
550
583
|
type: e.type,
|
|
551
584
|
label: e.label,
|
|
552
585
|
identifier: e.getIdentifier(),
|
|
553
|
-
state
|
|
586
|
+
state,
|
|
554
587
|
actions: e.actions,
|
|
555
588
|
customActions: e.customActions ? Object.keys(e.customActions) : void 0,
|
|
556
589
|
registeredHandlers: handlers.length > 0 ? handlers : void 0,
|
|
557
|
-
registrationRoute: e.registrationRoute
|
|
590
|
+
registrationRoute: e.registrationRoute,
|
|
591
|
+
visibility
|
|
558
592
|
};
|
|
559
593
|
}),
|
|
560
594
|
components: this.getAllComponents().map((c) => ({
|
|
@@ -1896,22 +1930,25 @@ function createServerHandlers(registry, executor, config) {
|
|
|
1896
1930
|
getElements: async (ctx) => {
|
|
1897
1931
|
const visibleOnly = ctx.query?.visibleOnly === "true" || ctx.body?.visibleOnly === true;
|
|
1898
1932
|
const forRoute = ctx.query?.route || ctx.body?.route;
|
|
1899
|
-
let allElements = visibleOnly ? registry.
|
|
1933
|
+
let allElements = visibleOnly ? registry.getMountedVisibleElements() : registry.getAllElements();
|
|
1900
1934
|
if (forRoute) {
|
|
1901
1935
|
allElements = allElements.filter((e) => e.registrationRoute === forRoute);
|
|
1902
1936
|
}
|
|
1903
1937
|
const elements = allElements.map((e) => {
|
|
1904
1938
|
const handlers = extractHandlerNames(e.props);
|
|
1939
|
+
const state = e.getState();
|
|
1940
|
+
const visibility = !state.visible ? "hidden" : state.layout !== null ? "visible" : "likely-visible";
|
|
1905
1941
|
return {
|
|
1906
1942
|
id: e.id,
|
|
1907
1943
|
type: e.type,
|
|
1908
1944
|
label: e.label,
|
|
1909
1945
|
identifier: e.getIdentifier(),
|
|
1910
|
-
state
|
|
1946
|
+
state,
|
|
1911
1947
|
actions: e.actions,
|
|
1912
1948
|
customActions: e.customActions ? Object.keys(e.customActions) : void 0,
|
|
1913
1949
|
registeredHandlers: handlers.length > 0 ? handlers : void 0,
|
|
1914
|
-
registrationRoute: e.registrationRoute
|
|
1950
|
+
registrationRoute: e.registrationRoute,
|
|
1951
|
+
visibility
|
|
1915
1952
|
};
|
|
1916
1953
|
});
|
|
1917
1954
|
return success2({ elements });
|
|
@@ -2174,6 +2211,37 @@ function createServerHandlers(registry, executor, config) {
|
|
|
2174
2211
|
"NOT_SUPPORTED"
|
|
2175
2212
|
);
|
|
2176
2213
|
},
|
|
2214
|
+
// AI helpers — runner-only endpoints that have no React Native analog.
|
|
2215
|
+
//
|
|
2216
|
+
// The mobile bridge mounts explicit NOT_SUPPORTED stubs at the runner's
|
|
2217
|
+
// cheatsheet paths so callers (and the /manual-test skill in particular)
|
|
2218
|
+
// get a structured envelope explaining the gap rather than a confusing
|
|
2219
|
+
// HTTP 404. Each error message names an in-tree mobile replacement so
|
|
2220
|
+
// operators aren't left guessing what to use instead.
|
|
2221
|
+
aiForms: async () => {
|
|
2222
|
+
return error2(
|
|
2223
|
+
'ai/forms (form discovery) is runner-only; mobile React Native has no DOM to walk. Use GET /ui-bridge/control/snapshot and filter for type === "input" instead.',
|
|
2224
|
+
"NOT_SUPPORTED"
|
|
2225
|
+
);
|
|
2226
|
+
},
|
|
2227
|
+
aiIdleStatus: async () => {
|
|
2228
|
+
return error2(
|
|
2229
|
+
'ai/idle-status (page-idle signal) is runner-only; mobile React Native has no DOM-mutation / network-idle signals. Use the registry event stream (WS subscribe to "element:registered"/"element:stateChanged") or poll /control/snapshot for stability.',
|
|
2230
|
+
"NOT_SUPPORTED"
|
|
2231
|
+
);
|
|
2232
|
+
},
|
|
2233
|
+
aiChangeBufferEnable: async () => {
|
|
2234
|
+
return error2(
|
|
2235
|
+
'ai/change-buffer (DOM mutation diff buffer) is runner-only; mobile React Native has no DOM. Use the WS event bridge (subscribe to "element:registered"/"element:unregistered"/"element:stateChanged") for change notifications.',
|
|
2236
|
+
"NOT_SUPPORTED"
|
|
2237
|
+
);
|
|
2238
|
+
},
|
|
2239
|
+
aiWaitForElement: async () => {
|
|
2240
|
+
return error2(
|
|
2241
|
+
'POST /ai/wait-for-element is runner-only on mobile. Use the WS "waitForElement" JSON-RPC method or "waitForCondition" instead \u2014 same semantics, no HTTP polling overhead.',
|
|
2242
|
+
"NOT_SUPPORTED"
|
|
2243
|
+
);
|
|
2244
|
+
},
|
|
2177
2245
|
// Meta / Introspection (stub — server constructor overrides with real route table)
|
|
2178
2246
|
getMethods: async () => {
|
|
2179
2247
|
return error2("Methods introspection not configured", "NOT_SUPPORTED");
|
|
@@ -2829,6 +2897,24 @@ var WS_ROUTES = [
|
|
|
2829
2897
|
{ pattern: "meta/methods", handler: "getMethods", httpMethods: ["GET"] },
|
|
2830
2898
|
// AI helpers — mobile parity with the runner's `/ui-bridge/ai/*` family.
|
|
2831
2899
|
{ pattern: "ai/fill-form", handler: "fillForm", httpMethods: ["POST"] },
|
|
2900
|
+
// AI helpers — NOT_SUPPORTED stubs. These endpoints exist on the runner-side
|
|
2901
|
+
// UI Bridge surface (and the /manual-test skill's cheatsheet documents them
|
|
2902
|
+
// as if they're universally available). Mobile React Native has no DOM, so
|
|
2903
|
+
// the mobile bridge mounts explicit stubs so callers get a structured
|
|
2904
|
+
// NOT_SUPPORTED envelope (with a hint pointing at the mobile-native
|
|
2905
|
+
// replacement) instead of a confusing HTTP 404.
|
|
2906
|
+
{ pattern: "ai/forms", handler: "aiForms", httpMethods: ["GET"] },
|
|
2907
|
+
{ pattern: "ai/idle-status", handler: "aiIdleStatus", httpMethods: ["GET"] },
|
|
2908
|
+
{
|
|
2909
|
+
pattern: "ai/change-buffer/enable",
|
|
2910
|
+
handler: "aiChangeBufferEnable",
|
|
2911
|
+
httpMethods: ["POST"]
|
|
2912
|
+
},
|
|
2913
|
+
{
|
|
2914
|
+
pattern: "ai/wait-for-element",
|
|
2915
|
+
handler: "aiWaitForElement",
|
|
2916
|
+
httpMethods: ["POST"]
|
|
2917
|
+
},
|
|
2832
2918
|
// Coord-based tap — synthesizes a press at the given screen coords by
|
|
2833
2919
|
// matching against registered elements' layout rects.
|
|
2834
2920
|
{ pattern: "control/tap", handler: "tapAt", httpMethods: ["POST"] },
|
|
@@ -2901,6 +2987,10 @@ var HANDLER_DESCRIPTIONS = {
|
|
|
2901
2987
|
diffBaseline: "Diff current UI against a saved baseline",
|
|
2902
2988
|
getMethods: "List every handler name (legacy introspection)",
|
|
2903
2989
|
fillForm: "Fill multiple inputs in one call: body { fields: [{elementId, value}] } \u2014 each field dispatches `type` + `clear:true`",
|
|
2990
|
+
aiForms: 'STUB \u2014 runner-only; mobile returns NOT_SUPPORTED. Use /control/snapshot + filter type==="input" instead.',
|
|
2991
|
+
aiIdleStatus: "STUB \u2014 runner-only; mobile returns NOT_SUPPORTED. Subscribe to registry events over WS for change signals.",
|
|
2992
|
+
aiChangeBufferEnable: "STUB \u2014 runner-only; mobile returns NOT_SUPPORTED. Use WS event subscriptions for change notifications.",
|
|
2993
|
+
aiWaitForElement: "STUB \u2014 runner-only; mobile returns NOT_SUPPORTED. Use the WS waitForElement / waitForCondition JSON-RPC methods.",
|
|
2904
2994
|
tapAt: "Synthesize a press at given screen coords by matching registered element layout rects: body { x, y, action? }",
|
|
2905
2995
|
getConsoleErrors: "TEST HOOK \u2014 last-N console.error/console.warn entries; ?since=<ms>&limit=<n>",
|
|
2906
2996
|
getNetworkRequests: "TEST HOOK \u2014 last-N fetch/XHR entries with status + duration; ?since=<ms>&limit=<n>",
|
|
@@ -5021,6 +5111,24 @@ function flattenStateStyles(stateStyles) {
|
|
|
5021
5111
|
if (stateStyles.disabled != null) result.disabled = flattenStyle(stateStyles.disabled);
|
|
5022
5112
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
5023
5113
|
}
|
|
5114
|
+
var warnedDeadButtonIds = /* @__PURE__ */ new Set();
|
|
5115
|
+
function scheduleDeadButtonWarning(bridge, id, type) {
|
|
5116
|
+
if (type !== "button" && type !== "pressable") return;
|
|
5117
|
+
if (warnedDeadButtonIds.has(id)) return;
|
|
5118
|
+
if (!bridge) return;
|
|
5119
|
+
setTimeout(() => {
|
|
5120
|
+
if (warnedDeadButtonIds.has(id)) return;
|
|
5121
|
+
const element = bridge.registry.getElement(id);
|
|
5122
|
+
if (!element) return;
|
|
5123
|
+
const props = element.props ?? {};
|
|
5124
|
+
const hasPress = typeof props.onPress === "function" || typeof props.onPressIn === "function" || typeof props.onResponderRelease === "function";
|
|
5125
|
+
if (hasPress) return;
|
|
5126
|
+
warnedDeadButtonIds.add(id);
|
|
5127
|
+
console.warn(
|
|
5128
|
+
`[UI Bridge] Registered \`${type}\` element "${id}" without an \`onPress\` handler \u2014 UI Bridge \`press\` actions on this element will fail with "No press handler found on element". Use \`useUIElementWithProps\` and \`captureProps({onPress})\` instead.`
|
|
5129
|
+
);
|
|
5130
|
+
}, 0);
|
|
5131
|
+
}
|
|
5024
5132
|
function useUIElement(options) {
|
|
5025
5133
|
const bridge = useUIBridgeNativeOptional();
|
|
5026
5134
|
const ref = useRef(null);
|
|
@@ -5067,6 +5175,7 @@ function useUIElement(options) {
|
|
|
5067
5175
|
registeredRef.current = true;
|
|
5068
5176
|
registeredIdRef.current = id;
|
|
5069
5177
|
setRegistered(true);
|
|
5178
|
+
scheduleDeadButtonWarning(bridge, id, type);
|
|
5070
5179
|
}, [bridge, id, type, label, actions, customActions, treePath, style, stateStylesProp]);
|
|
5071
5180
|
const unregister = useCallback(() => {
|
|
5072
5181
|
if (!bridge || !registeredRef.current) return;
|
|
@@ -5126,30 +5235,42 @@ function useUIElement(options) {
|
|
|
5126
5235
|
const node = ref.current;
|
|
5127
5236
|
if (!node || typeof node.measureInWindow !== "function") return;
|
|
5128
5237
|
let cancelled = false;
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5238
|
+
let pendingTimer = null;
|
|
5239
|
+
const backoffMs = [50, 200, 500, 1e3, 2500];
|
|
5240
|
+
let attempt = 0;
|
|
5241
|
+
const tryMeasure = () => {
|
|
5242
|
+
if (cancelled || !node.measureInWindow) return;
|
|
5243
|
+
node.measureInWindow((pageX, pageY, w, h) => {
|
|
5244
|
+
if (cancelled) return;
|
|
5245
|
+
if (w > 0 && h > 0) {
|
|
5246
|
+
const newLayout = {
|
|
5247
|
+
x: pageX,
|
|
5248
|
+
y: pageY,
|
|
5249
|
+
width: w,
|
|
5250
|
+
height: h,
|
|
5251
|
+
pageX,
|
|
5252
|
+
pageY
|
|
5253
|
+
};
|
|
5254
|
+
setLayout(newLayout);
|
|
5255
|
+
const newState = {
|
|
5256
|
+
mounted: true,
|
|
5257
|
+
visible: true,
|
|
5258
|
+
enabled: true,
|
|
5259
|
+
focused: false,
|
|
5260
|
+
layout: newLayout
|
|
5261
|
+
};
|
|
5262
|
+
bridge.registry.updateElementState(id, newState);
|
|
5263
|
+
onStateChangeRef.current?.(newState);
|
|
5264
|
+
return;
|
|
5265
|
+
}
|
|
5266
|
+
if (attempt >= backoffMs.length) return;
|
|
5267
|
+
pendingTimer = setTimeout(tryMeasure, backoffMs[attempt++]);
|
|
5268
|
+
});
|
|
5269
|
+
};
|
|
5270
|
+
tryMeasure();
|
|
5151
5271
|
return () => {
|
|
5152
5272
|
cancelled = true;
|
|
5273
|
+
if (pendingTimer != null) clearTimeout(pendingTimer);
|
|
5153
5274
|
};
|
|
5154
5275
|
}, [bridge, registered, id]);
|
|
5155
5276
|
const registeredHandlerKeysRef = useRef([]);
|