UNPKG

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.

1 lines • 1.01 kB
import{Gi as e,Ji as t,qi as n}from"./sdk-batch.js";const r=[`button`,`menu`,`textfield`,`searchfield`,`checkbox`,`radio`,`switch`];function i(e,t,n=c){let r=e.nodes??[];return t.scope&&(r=a(r,t.scope,e=>!t.interactiveOnly||r.slice(e.start,e.end).some(n))),t.interactiveOnly&&(r=o(r,n)),typeof t.depth==`number`&&(r=s(r,t.depth)),{...e,nodes:r}}function a(r,i,a){let o=n(i);if(!o)return t(r);let s=e(r,o,a);if(!s)return[];let c=r.slice(s.start,s.end);return t(c,c[0]?.depth??0)}function o(e,n){if(e.length===0)return e;let r=new Map(e.map(e=>[e.index,e])),i=new Set;for(let t of e){if(!n(t))continue;let e=t;for(;e&&!i.has(e.index);)i.add(e.index),e=typeof e.parentIndex==`number`?r.get(e.parentIndex):void 0}return i.size===0?e:t(e.filter(e=>i.has(e.index)))}function s(e,n){return t(e.filter(e=>(e.depth??0)<=n))}function c(e){if([e.focused,e.hittable,e.rect].some(Boolean))return!0;let t=`${e.type??``} ${e.role??``} ${e.subrole??``}`.toLowerCase();return r.some(e=>t.includes(e))}export{i as n,a as t};