@qontinui/ui-bridge-native 0.6.1 → 0.6.3
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 +45 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +45 -0
- package/dist/core/index.mjs.map +1 -1
- package/dist/core/registry.d.ts +19 -0
- package/dist/core/registry.d.ts.map +1 -1
- package/dist/index.js +333 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +333 -1
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.js +328 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +328 -1
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/useUIElement.d.ts +19 -0
- 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 +268 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +268 -0
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/page-health.d.ts +72 -0
- package/dist/server/page-health.d.ts.map +1 -0
- package/dist/server/types.d.ts +1 -0
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/server/index.mjs
CHANGED
|
@@ -55,6 +55,11 @@ var UI_BRIDGE_NATIVE_ROUTES = {
|
|
|
55
55
|
path: "/ui-bridge/control/snapshot",
|
|
56
56
|
description: "Get full bridge snapshot"
|
|
57
57
|
},
|
|
58
|
+
PAGE_HEALTH: {
|
|
59
|
+
method: "POST",
|
|
60
|
+
path: "/ui-bridge/control/page-health",
|
|
61
|
+
description: "Holistic page health diagnostic: spatial coverage, layout regions, text signals, interactive readiness, anomalies + ASCII heatmap"
|
|
62
|
+
},
|
|
58
63
|
// Workflows
|
|
59
64
|
GET_WORKFLOWS: {
|
|
60
65
|
method: "GET",
|
|
@@ -669,6 +674,245 @@ function createDesignHandlers(registry) {
|
|
|
669
674
|
};
|
|
670
675
|
}
|
|
671
676
|
|
|
677
|
+
// src/server/page-health.ts
|
|
678
|
+
var GRID_SIZE = 20;
|
|
679
|
+
var NAV_TYPES = /* @__PURE__ */ new Set(["button", "heading", "badge", "status-message"]);
|
|
680
|
+
var SKIP_TEXT_TYPES = /* @__PURE__ */ new Set(["button", "link", "tab", "menuitem"]);
|
|
681
|
+
var INTERACTIVE_TYPES = /* @__PURE__ */ new Set([
|
|
682
|
+
"button",
|
|
683
|
+
"input",
|
|
684
|
+
"switch",
|
|
685
|
+
"checkbox",
|
|
686
|
+
"radio",
|
|
687
|
+
"touchable",
|
|
688
|
+
"listItem"
|
|
689
|
+
]);
|
|
690
|
+
var ERROR_PHRASES = [
|
|
691
|
+
"error occurred",
|
|
692
|
+
"failed to",
|
|
693
|
+
"exception",
|
|
694
|
+
"crash",
|
|
695
|
+
"unavailable",
|
|
696
|
+
"something went wrong",
|
|
697
|
+
"could not"
|
|
698
|
+
];
|
|
699
|
+
var LOADING_PHRASES = [
|
|
700
|
+
"loading",
|
|
701
|
+
"starting",
|
|
702
|
+
"connecting",
|
|
703
|
+
"please wait",
|
|
704
|
+
"initializing",
|
|
705
|
+
"fetching"
|
|
706
|
+
];
|
|
707
|
+
var EMPTY_PHRASES = [
|
|
708
|
+
"no data",
|
|
709
|
+
"no results",
|
|
710
|
+
"nothing here",
|
|
711
|
+
"empty",
|
|
712
|
+
"no items",
|
|
713
|
+
"get started"
|
|
714
|
+
];
|
|
715
|
+
function severityRank(s) {
|
|
716
|
+
if (s === "CRITICAL") return 3;
|
|
717
|
+
if (s === "WARNING") return 2;
|
|
718
|
+
return 1;
|
|
719
|
+
}
|
|
720
|
+
function worstSeverity(findings) {
|
|
721
|
+
let worst = "OK";
|
|
722
|
+
for (const f of findings) {
|
|
723
|
+
if (severityRank(f.severity) > severityRank(worst)) {
|
|
724
|
+
worst = f.severity;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
return worst;
|
|
728
|
+
}
|
|
729
|
+
function truncate(s, n) {
|
|
730
|
+
if (s.length <= n) return s;
|
|
731
|
+
return [...s].slice(0, n).join("");
|
|
732
|
+
}
|
|
733
|
+
function normalizeRect(state, viewport) {
|
|
734
|
+
const layout = state.layout;
|
|
735
|
+
if (!layout) return null;
|
|
736
|
+
if (viewport.width <= 0 || viewport.height <= 0) return null;
|
|
737
|
+
const px = layout.pageX ?? layout.x;
|
|
738
|
+
const py = layout.pageY ?? layout.y;
|
|
739
|
+
return {
|
|
740
|
+
x: px / viewport.width,
|
|
741
|
+
y: py / viewport.height,
|
|
742
|
+
width: layout.width / viewport.width,
|
|
743
|
+
height: layout.height / viewport.height
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
function diagnosePageHealth(elements, viewport) {
|
|
747
|
+
const findings = [];
|
|
748
|
+
const projected = elements.map((el) => ({
|
|
749
|
+
el,
|
|
750
|
+
rect: el.state.visible ? normalizeRect(el.state, viewport) : null
|
|
751
|
+
}));
|
|
752
|
+
const visible = projected.filter((p) => p.rect !== null);
|
|
753
|
+
const grid = Array.from(
|
|
754
|
+
{ length: GRID_SIZE },
|
|
755
|
+
() => Array.from({ length: GRID_SIZE }, () => false)
|
|
756
|
+
);
|
|
757
|
+
for (const { rect } of visible) {
|
|
758
|
+
const colStart = Math.max(0, Math.floor(rect.x * GRID_SIZE));
|
|
759
|
+
const colEnd = Math.min(GRID_SIZE, Math.ceil((rect.x + rect.width) * GRID_SIZE));
|
|
760
|
+
const rowStart = Math.max(0, Math.floor(rect.y * GRID_SIZE));
|
|
761
|
+
const rowEnd = Math.min(GRID_SIZE, Math.ceil((rect.y + rect.height) * GRID_SIZE));
|
|
762
|
+
for (let r = rowStart; r < rowEnd; r++) {
|
|
763
|
+
for (let c = colStart; c < colEnd; c++) {
|
|
764
|
+
grid[r][c] = true;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
const totalCells = GRID_SIZE * GRID_SIZE;
|
|
769
|
+
const halfCells = totalCells / 2;
|
|
770
|
+
let filled = 0;
|
|
771
|
+
let leftFilled = 0;
|
|
772
|
+
let rightFilled = 0;
|
|
773
|
+
const half = GRID_SIZE / 2;
|
|
774
|
+
for (let r = 0; r < GRID_SIZE; r++) {
|
|
775
|
+
for (let c = 0; c < GRID_SIZE; c++) {
|
|
776
|
+
if (grid[r][c]) {
|
|
777
|
+
filled++;
|
|
778
|
+
if (c < half) leftFilled++;
|
|
779
|
+
else rightFilled++;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
const coveragePct = Math.round(filled / totalCells * 100);
|
|
784
|
+
const leftHalfPct = Math.round(leftFilled / halfCells * 100);
|
|
785
|
+
const rightHalfPct = Math.round(rightFilled / halfCells * 100);
|
|
786
|
+
let spatialSeverity = "OK";
|
|
787
|
+
if (coveragePct < 15) spatialSeverity = "CRITICAL";
|
|
788
|
+
else if (coveragePct < 30) spatialSeverity = "WARNING";
|
|
789
|
+
if (rightHalfPct < 5 && leftHalfPct > 20) spatialSeverity = "CRITICAL";
|
|
790
|
+
findings.push({
|
|
791
|
+
check: "spatial_coverage",
|
|
792
|
+
severity: spatialSeverity,
|
|
793
|
+
detail: `Elements cover ${coveragePct}% of viewport. Left=${leftHalfPct}%, Right=${rightHalfPct}%`,
|
|
794
|
+
data: {
|
|
795
|
+
coverage_pct: coveragePct,
|
|
796
|
+
left_half_pct: leftHalfPct,
|
|
797
|
+
right_half_pct: rightHalfPct
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
let sidebar = 0;
|
|
801
|
+
let header = 0;
|
|
802
|
+
let content = 0;
|
|
803
|
+
for (const { rect } of visible) {
|
|
804
|
+
const cx = rect.x + rect.width / 2;
|
|
805
|
+
const cy = rect.y + rect.height / 2;
|
|
806
|
+
if (cx < 0.2) sidebar++;
|
|
807
|
+
else if (cy < 0.08) header++;
|
|
808
|
+
else content++;
|
|
809
|
+
}
|
|
810
|
+
let layoutSeverity = "OK";
|
|
811
|
+
if (content === 0) layoutSeverity = "CRITICAL";
|
|
812
|
+
else if (content < 3) layoutSeverity = "WARNING";
|
|
813
|
+
findings.push({
|
|
814
|
+
check: "layout_regions",
|
|
815
|
+
severity: layoutSeverity,
|
|
816
|
+
detail: `sidebar=${sidebar}, header=${header}, content=${content}`,
|
|
817
|
+
data: { sidebar, header, content }
|
|
818
|
+
});
|
|
819
|
+
const typeCounts = {};
|
|
820
|
+
for (const el of elements) {
|
|
821
|
+
const t = el.type || "unknown";
|
|
822
|
+
typeCounts[t] = (typeCounts[t] ?? 0) + 1;
|
|
823
|
+
}
|
|
824
|
+
const allNav = elements.length > 5 && Object.keys(typeCounts).every((k) => NAV_TYPES.has(k));
|
|
825
|
+
const diversitySeverity = allNav ? "WARNING" : "OK";
|
|
826
|
+
findings.push({
|
|
827
|
+
check: "element_diversity",
|
|
828
|
+
severity: diversitySeverity,
|
|
829
|
+
detail: `${Object.keys(typeCounts).length} type(s) across ${elements.length} elements${allNav ? " (navigation-only)" : ""}`,
|
|
830
|
+
data: { types: typeCounts }
|
|
831
|
+
});
|
|
832
|
+
const detectedErrors = [];
|
|
833
|
+
const detectedLoading = [];
|
|
834
|
+
const detectedEmpty = [];
|
|
835
|
+
const detectedCss = [];
|
|
836
|
+
for (const el of elements) {
|
|
837
|
+
const elType = el.type ?? "";
|
|
838
|
+
if (SKIP_TEXT_TYPES.has(elType)) continue;
|
|
839
|
+
const text = (el.state.textContent ?? "").toString();
|
|
840
|
+
if (!text) continue;
|
|
841
|
+
const textLower = text.toLowerCase();
|
|
842
|
+
for (const p of ERROR_PHRASES) {
|
|
843
|
+
if (textLower.includes(p)) {
|
|
844
|
+
detectedErrors.push(truncate(text, 120));
|
|
845
|
+
break;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
for (const p of LOADING_PHRASES) {
|
|
849
|
+
if (textLower.includes(p)) {
|
|
850
|
+
detectedLoading.push(truncate(text, 120));
|
|
851
|
+
break;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
for (const p of EMPTY_PHRASES) {
|
|
855
|
+
if (textLower.includes(p)) {
|
|
856
|
+
detectedEmpty.push(truncate(text, 120));
|
|
857
|
+
break;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
let textSeverity = "OK";
|
|
862
|
+
if (detectedErrors.length > 0) textSeverity = "CRITICAL";
|
|
863
|
+
else if (detectedLoading.length > 0 || detectedEmpty.length > 0) textSeverity = "WARNING";
|
|
864
|
+
findings.push({
|
|
865
|
+
check: "text_signals",
|
|
866
|
+
severity: textSeverity,
|
|
867
|
+
detail: `errors=${detectedErrors.length}, loading=${detectedLoading.length}, empty=${detectedEmpty.length}, css_signals=${detectedCss.length}`,
|
|
868
|
+
data: {
|
|
869
|
+
errors: detectedErrors,
|
|
870
|
+
loading: detectedLoading,
|
|
871
|
+
empty: detectedEmpty,
|
|
872
|
+
css_signals: detectedCss
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
let interactiveTotal = 0;
|
|
876
|
+
let interactiveDisabled = 0;
|
|
877
|
+
for (const el of elements) {
|
|
878
|
+
if (!INTERACTIVE_TYPES.has(el.type)) continue;
|
|
879
|
+
interactiveTotal++;
|
|
880
|
+
if (el.state.enabled === false) interactiveDisabled++;
|
|
881
|
+
}
|
|
882
|
+
const interactiveSeverity = interactiveTotal > 0 && interactiveDisabled / interactiveTotal > 0.5 ? "WARNING" : "OK";
|
|
883
|
+
findings.push({
|
|
884
|
+
check: "interactive_readiness",
|
|
885
|
+
severity: interactiveSeverity,
|
|
886
|
+
detail: `${interactiveTotal} interactive elements, ${interactiveDisabled} disabled`,
|
|
887
|
+
data: { total: interactiveTotal, disabled: interactiveDisabled }
|
|
888
|
+
});
|
|
889
|
+
let zeroSize = 0;
|
|
890
|
+
let outsideViewport = 0;
|
|
891
|
+
for (const { rect } of visible) {
|
|
892
|
+
if (rect.width === 0 || rect.height === 0) zeroSize++;
|
|
893
|
+
if (rect.x + rect.width < 0 || rect.y + rect.height < 0 || rect.x > 1 || rect.y > 1) {
|
|
894
|
+
outsideViewport++;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
const anomalySeverity = zeroSize > 0 || outsideViewport > 0 ? "WARNING" : "OK";
|
|
898
|
+
findings.push({
|
|
899
|
+
check: "visual_anomalies",
|
|
900
|
+
severity: anomalySeverity,
|
|
901
|
+
detail: `zero_size=${zeroSize}, outside_viewport=${outsideViewport}`,
|
|
902
|
+
data: { zero_size: zeroSize, outside_viewport: outsideViewport }
|
|
903
|
+
});
|
|
904
|
+
const heatmap = grid.map(
|
|
905
|
+
(row) => row.map((cell) => cell ? "#" : ".").join("")
|
|
906
|
+
);
|
|
907
|
+
return {
|
|
908
|
+
summary: worstSeverity(findings),
|
|
909
|
+
findings,
|
|
910
|
+
heatmap,
|
|
911
|
+
element_count: elements.length,
|
|
912
|
+
visible_count: visible.length
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
|
|
672
916
|
// src/server/handlers.ts
|
|
673
917
|
async function executeWorkflowStep(step, registry, executor) {
|
|
674
918
|
const startTime = Date.now();
|
|
@@ -1053,6 +1297,25 @@ function createServerHandlers(registry, executor, config) {
|
|
|
1053
1297
|
const snapshot = registry.createSnapshot(void 0, { visibleOnly, currentRouteOnly });
|
|
1054
1298
|
return success2(snapshot);
|
|
1055
1299
|
},
|
|
1300
|
+
getPageHealth: async (ctx) => {
|
|
1301
|
+
const bodyViewport = ctx.body?.viewport;
|
|
1302
|
+
let viewport = bodyViewport;
|
|
1303
|
+
if (!viewport) {
|
|
1304
|
+
try {
|
|
1305
|
+
const { Dimensions } = __require("react-native");
|
|
1306
|
+
const win = Dimensions.get("window");
|
|
1307
|
+
viewport = { width: win.width, height: win.height };
|
|
1308
|
+
} catch {
|
|
1309
|
+
viewport = { width: 0, height: 0 };
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
const elements = registry.getAllElements().map((e) => ({
|
|
1313
|
+
type: e.type,
|
|
1314
|
+
state: e.getState()
|
|
1315
|
+
}));
|
|
1316
|
+
const report = diagnosePageHealth(elements, viewport);
|
|
1317
|
+
return success2(report);
|
|
1318
|
+
},
|
|
1056
1319
|
// Workflows
|
|
1057
1320
|
getWorkflows: async () => {
|
|
1058
1321
|
const workflows = registry.getAllWorkflows().map((w) => ({
|
|
@@ -1801,6 +2064,10 @@ var WS_ROUTES = [
|
|
|
1801
2064
|
{ pattern: "ai/find", handler: "find", httpMethods: ["POST"] },
|
|
1802
2065
|
{ pattern: "control/snapshot", handler: "getSnapshot", httpMethods: ["GET"] },
|
|
1803
2066
|
{ pattern: "control/discover", handler: "getSnapshot" },
|
|
2067
|
+
// Page health — accepts both GET and POST so the canonical skill invocation
|
|
2068
|
+
// (`POST .../control/page-health` with an empty body) and ad-hoc curls both
|
|
2069
|
+
// work without a body-shape gotcha.
|
|
2070
|
+
{ pattern: "control/page-health", handler: "getPageHealth", httpMethods: ["GET", "POST"] },
|
|
1804
2071
|
// Workflows
|
|
1805
2072
|
{ pattern: "control/workflows", handler: "getWorkflows", httpMethods: ["GET"] },
|
|
1806
2073
|
{ pattern: "control/workflow/:id/run", handler: "runWorkflow", httpMethods: ["POST"] },
|
|
@@ -1905,6 +2172,7 @@ var HANDLER_DESCRIPTIONS = {
|
|
|
1905
2172
|
executeComponentAction: "Invoke a component action directly (preferred over button clicks)",
|
|
1906
2173
|
find: "AI-powered element search by natural-language query",
|
|
1907
2174
|
getSnapshot: "Full snapshot: elements + route + state. Supports ?visibleOnly=true and ?currentRouteOnly=true",
|
|
2175
|
+
getPageHealth: 'Holistic page health diagnostic over current snapshot elements (spatial coverage, layout regions, text/anomaly signals, heatmap). Optional body: { viewport?: { width, height } } to override Dimensions.get("window").',
|
|
1908
2176
|
getWorkflows: "List registered workflows",
|
|
1909
2177
|
runWorkflow: "Trigger a workflow by id",
|
|
1910
2178
|
pageRefresh: "Reload the current route",
|