agent-device
Version:
Open source device layer for AI coding agents: a CLI, MCP server, and typed Node.js API to control mobile, web, TV, and desktop apps on devices and simulators, locally or in the cloud.
3 lines • 3.77 kB
JavaScript
import{Di as e}from"./sdk-batch.js";import{ot as t}from"./sdk-contracts.js";import{n,o as r,r as i,s as a,t as o}from"./react-native-overlay.js";const s=/\b(logbox|redbox|reload js|copy stack|component stack|call stack|runtime error|open debugger to view warnings)\b/,c=[/\b[\w.$<>/-]+\.(?:tsx?|jsx?):\d+(?::\d+)?\b/,/\b[\w.$<>/-]+\.(?:tsx?|jsx?)\s+\(\d+:\d+\)/],l=new Set([`x`,`×`,`✕`,`✖`,`⨯`]);function u(e){if(d(e).detected)return[`Hint: React Native warning/error overlay detected. It overlays part of the app and should be handled before interacting.`,`Run: agent-device react-native dismiss-overlay`,`The command verifies the overlay is gone. Run agent-device snapshot -i afterward only when you need fresh refs for the next action.`].join(`
`)}function d(e){let t=f(e),n=t.detected?p(t):null;return{detected:t.detected,dismissNodes:t.dismissNodes,minimizeNodes:t.minimizeNodes,collapsedNodes:t.collapsedNodes,primaryAction:n}}function f(e){let t=e.map(m).join(`
`).toLowerCase(),r=D(e,x),o=D(e,a),s=D(e,i,T),c=D(e,b),l=g(t),u=_(t);return{dismissNodes:r,minimizeNodes:o,collapsedNodes:s,detected:y({text:t,hasReactNativeStackFrame:l,hasOverlayControl:v(t,r,o),hasControllessRedBoxText:u,collapsedNodes:s,collapsedEvidenceNodes:D(s,n),openDebuggerWarningNodes:c})}}function p(e){let t=O(e.dismissNodes);if(t)return j(t,M(t));let n=N(e.collapsedNodes.filter(E));return n?.rect?{action:`close-collapsed-banner`,point:R(n),rect:n.rect,ref:n.ref,label:B(n)}:null}function m(e){return[e.label,e.value,e.identifier,e.type,e.role].filter(Boolean).join(` `)}function h(e){return s.test(e)}function g(e){return c.some(t=>t.test(e))}function _(e){return/\buncaught\b/.test(e)&&/unable to download asset/.test(e)}function v(e,t,n){return t.length>0||n.length>0||/\b(reload js|copy stack)\b/.test(e)}function y(e){let t=e.hasReactNativeStackFrame||h(e.text);return e.collapsedEvidenceNodes.length>0||e.collapsedNodes.length>0&&t||e.openDebuggerWarningNodes.length>0||e.hasControllessRedBoxText||e.hasOverlayControl&&(h(e.text)||e.hasReactNativeStackFrame)}function b(e){return e.includes(`open debugger to view warnings`)||/^!,\s+open debugger\b/.test(e)}function x(e){return r(e)||S(e)||C(e)}function S(e){return/^close(?:\s*\([^)]*\))?$/i.test(e)}function C(e){return l.has(e)}function w(e){return/^!,\s+/.test(e)}function T(e){return!e.rect||e.rect.height<=180}function E(e){let t=B(e)?.trim().toLowerCase()??``;return(b(t)||w(t))&&o(e)}function D(e,t,n=()=>!0){let r=[];for(let i of e)i.ref&&n(i)&&[i.label,i.value,i.identifier].map(e=>e?.trim().toLowerCase()).filter(e=>!!e).some(e=>t(e))&&r.push(i);return r}function O(e){return P(e,A)}function k(e){let t=[e.type,e.role,e.subrole].join(` `).toLowerCase();return/\b(button|menuitem|link)\b/.test(t)}function A(t){return[I(k(t)),I(t.hittable),-(t.rect?e(t.rect):1/0)]}function j(e,n){if(!e.rect)throw Error(`React Native overlay target node must have rect`);return{action:n,point:t(e.rect),rect:e.rect,ref:e.ref,label:B(e)}}function M(e){let t=B(e)?.trim().toLowerCase();return t&&r(t)?`dismiss`:`close`}function N(e){return P(e,F)}function P(e,t){let n=e.filter(e=>e.rect);return n.length===0?null:n.sort((e,n)=>L(t(n),t(e)))[0]??null}function F(e){return[I(e.hittable),e.rect?.width??0,e.rect?.y??0]}function I(e){return+(e===!0)}function L(e,t){for(let n=0;n<e.length;n+=1){let r=e[n]-t[n];if(r!==0)return r}return 0}function R(e){if(!e.rect)throw Error(`Collapsed React Native warning node must have rect`);let t=Math.min(e.rect.height,52),n=Math.min(36,Math.max(18,t*.45));return{x:Math.round(z(e.rect.x+e.rect.width-n,e.rect.x+1,e.rect.x+e.rect.width-1)),y:Math.round(e.rect.y+t/2)}}function z(e,t,n){return Math.min(n,Math.max(t,e))}function B(e){return e.label??e.value??e.identifier}export{u as n,d as t};