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 • 4.32 kB
import{r as e}from"./rolldown-runtime.js";import{Ci as t,_i as n,bi as r}from"./sdk-batch.js";import{i,n as a,o,r as s,s as c,t as l}from"./android-input-ownership.js";var u=e({TAP_KEYBOARD_OCCLUDES_TARGET_DETAILS:()=>f,TAP_KEYBOARD_OCCLUDES_TARGET_REASON:()=>d,acquireProviderKeyboard:()=>D,observeCompleteTreeKeyboard:()=>O,resolveKeyboardTapOcclusion:()=>j});const d=`tap_keyboard_occludes_target`,f=Object.freeze({reason:d,hint:"The visible keyboard covers this target, so the tap would land on a key instead of on it. End editing first. Press a visible dismiss key such as Hide Keyboard, or the app control that ends editing. On Android, use `keyboard dismiss`. Use `keyboard enter` when you intend to send Return. This reads the snapshot the command measured against, so if the keyboard closed since it was taken, run `snapshot -i` and retry."}),p=new Set([`keyboard`,`key`]);function m(e){return p.has(n(e.type??``))||c(e)}function h(e){return m(e)||i.has(e.role??``)}function g(e){return m(e)||o(e,s)}function _(e,t){if(h(e)||o(e,a)||o(e,l)||g(e))return!0;let n=new Set,r=e.parentIndex;for(;typeof r==`number`&&!n.has(r);){n.add(r);let e=t.get(r);if(!e)return!1;if(o(e,l)||g(e))return!0;r=e.parentIndex}return!1}function v(e){return e!==null&&t(e)}function y(e){return e.flatMap(e=>t(e.rect)?[e.rect]:[])}function b(e,t){let n=new Map(e.map(e=>[e.index,e.parentIndex])),r=new Set(t.map(e=>e.index)),i=new Set;for(let e of t)for(let t of x(n,r,e.index))i.add(t);return i}function x(e,t,n){let r=[],i=new Set,a=e.get(n);for(;typeof a==`number`&&!i.has(a);)i.add(a),t.has(a)&&r.push(a),a=e.get(a);return r}function S(e){let t=e.map(e=>[e.x,e.x+e.width]).sort((e,t)=>e[0]-t[0]),n=t[0]?.[1]??0;for(let[e,r]of t){if(e-n>2)return!1;n=Math.max(n,r)}return!0}function C(e){let t=Math.min(...e.anchorRects.map(e=>e.y)),n=Math.min(...e.anchorRects.map(e=>e.x)),r=Math.max(...e.anchorRects.map(e=>e.x+e.width)),i=e.viewport.y+e.viewport.height;return e.reportedBottom<i-80||r-n<=e.reportedBottom-t?null:{x:n,y:t,width:r-n,height:i-t}}function w(e){let t=y(e.anchorNodes.filter(t=>!e.planeIndices.has(t.index)));return S(t.length>0?t:e.anchorRects)}function T(e){let t=e.filter(e=>h(e)||e.keyboardOwned===!0&&[e.type,e.role].some(e=>n(e??``)===`button`)),r=b(e,t);return y(t.filter(e=>!r.has(e.index)))}function E(e,n){let r=e.filter(m),i=y(r);if(i.length===0||!v(n))return null;let a=e.filter(h),o=y(a);if(o.length===0)return null;let s=C({anchorRects:i,reportedBottom:Math.max(...o.map(e=>e.y+e.height)),viewport:n});return!s||!t(s)||!w({anchorNodes:r,anchorRects:i,planeIndices:b(e,a)})?null:s}function D(e){let t=new Map(e.nodes.map(e=>[e.index,e]));return{nodes:e.nodes.map(e=>({...e,keyboardOwned:_(e,t)})),keyboard:A(e)}}function O(e){let t=A(e);return t.kind!==`unmeasurable`||!e.complete||e.nodes.some(k)?t:{kind:`absent`,treeBound:!0}}function k(e){return e.role===`UIRemoteKeyboardWindow`||h(e)||o(e,a)||o(e,s)||o(e,l)}function A(e){let t=E(e.nodes,e.viewport);return t?{kind:`derived`,derivation:`docked-tree`,frame:t,treeBound:!0}:v(e.viewport)&&e.nodes.some(m)?{kind:`tree-rejected`,derivation:`docked-tree`,...typeof e.visibility==`boolean`?{visible:e.visibility}:{}}:typeof e.visibility==`boolean`?{kind:`visibility-only`,visible:e.visibility}:{kind:`unmeasurable`,reason:e.nodes.some(m)?`keyboard-viewport-unavailable`:e.visibility===`failed`?`keyboard-visibility-probe-failed`:e.visibility===`unsupported`?`keyboard-visibility-probe-unsupported`:`keyboard-not-observed`}}function j(e){if(e.keyboard?.kind===`absent`)return{kind:`no-keyboard`};if(e.keyboard?.kind===`tree-rejected`)return{kind:e.keyboard.visible===!1?`no-keyboard`:`undetermined`};let t=e.keyboard?.kind===`visible`||e.keyboard?.kind===`derived`?e.keyboard.frame:E(e.nodes,e.viewport);if(!t)return{kind:e.keyboard?.kind===`visibility-only`&&!e.keyboard.visible?`no-keyboard`:`undetermined`};let n={frame:t,controlRects:T(e.nodes)};return e.node?e.node.keyboardOwned??_(e.node,new Map(e.nodes.map(e=>[e.index,e])))?{kind:`clear`,surface:n}:r(n.frame,e.point.x,e.point.y)?{kind:`occluded`,surface:n}:{kind:`clear`,surface:n}:M(e.point,n)}function M(e,t){return t.controlRects.some(t=>r(t,e.x,e.y))?{kind:`clear`,surface:t}:r(t.frame,e.x,e.y)?{kind:`occluded`,surface:t}:{kind:`clear`,surface:t}}export{u as a,j as i,D as n,O as r,f as t};