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 • 6.16 kB
import{r as e}from"./rolldown-runtime.js";import{Ci as t,Li as n,Ri as r,Xi as i,_i as a,fi as o,mi as s}from"./sdk-batch.js";import{at as c,ht as l,it as u,rt as d}from"./sdk-contracts.js";import{a as f,t as p}from"./snapshot-capture-annotations.js";import{i as m,l as h,s as g,u as _}from"./snapshot-private-evidence.js";import"./capture.js";import{n as v,t as y}from"./snapshot-occlusion.js";import{s as b}from"./android-input-ownership.js";import{t as x}from"./snapshot-desktop-projection.js";import{a as S}from"./ios-snapshot-planning.js";function C(e,t,n){if(n?.(e.length+t.length)===!1)return;let r=w(t);if(r.length===0)return 0;let i=1/0,a=-1/0;for(let e of r)i=Math.min(i,e.x),a=Math.max(a,e.endX);let o=w(e).filter(e=>e.x<a&&e.endX>i);if(o.length===0)return 0;let s=[...r.flatMap(e=>[e.x,e.endX]),...o.flatMap(e=>[Math.max(e.x,i),Math.min(e.endX,a)])];if(n?.(r.length+o.length+s.length)===!1)return;r.sort(T),o.sort(T);let c=[...new Set(s)].sort((e,t)=>e-t),l=[],u=[],d=0,f=0,p=0,m=0;for(let e=0;e<c.length-1;e+=1){let t=c[e],i=c[e+1];for(l=l.filter(e=>e.endX>t),u=u.filter(e=>e.endX>t);d<r.length&&r[d].x<=t;)l.push(r[d]),d+=1;for(;f<o.length&&o[f].x<=t;)u.push(o[f]),f+=1;if(n?.(1+l.length+u.length)===!1)return;let a=E(l),s=E(u),h=i-t;p+=h*D(a),m+=h*O(a,s)}return p<=0?0:m/p}function w(e){return e.filter(t).map(e=>({...e,endX:e.x+e.width}))}function T(e,t){return e.x-t.x||e.endX-t.endX}function E(e){let t=e.map(e=>({start:e.y,end:e.y+e.height})).sort((e,t)=>e.start-t.start||e.end-t.end),n=[];for(let e of t){let t=n.at(-1);!t||e.start>t.end?n.push({...e}):t.end=Math.max(t.end,e.end)}return n}function D(e){return e.reduce((e,t)=>e+t.end-t.start,0)}function O(e,t){let n=0,r=0,i=0;for(;r<e.length&&i<t.length;){let a=e[r],o=t[i];n+=Math.max(0,Math.min(a.end,o.end)-Math.max(a.start,o.start)),a.end<=o.end?r+=1:i+=1}return n}function k(e,t=new Map){if(t.size===0)return new Set;let n=N(e),r=P(e,n),i={remaining:Math.max(1024,e.length*128),exhausted:!1},a=A(n,{footprints:r,siblingOrders:t,budget:i});return i.exhausted?new Set:W(a,n)}function A(e,t){let n=new Set;for(let r of e.values())for(let e of r)if(j(e,r,t)&&n.add(e.index),t.budget.exhausted)return n;return n}function j(e,t,n){let r=n.siblingOrders.get(e.index),i=n.footprints.get(e.index);if(!r||!i)return!1;for(let e of t){if(!H(n.budget))return!1;if(M(r,i,e,n))return!0}return!1}function M(e,t,n,r){let i=r.siblingOrders.get(n.index),a=r.footprints.get(n.index);if(!i||!a?.hasAction||i.group!==e.group||i.order<=e.order)return!1;let o=V(a,`paint`,r.budget),s=V(t,`show`,r.budget);if(r.budget.exhausted)return!1;let c=C(o,s,e=>U(r.budget,e));return c!==void 0&&c>=.9}function N(e){let t=new Map;for(let n of e){if(typeof n.parentIndex!=`number`)continue;let e=t.get(n.parentIndex)??[];e.push(n),t.set(n.parentIndex,e)}return t}function P(e,t){let n=new Map;for(let r=e.length-1;r>=0;--r){let i=e[r],a=t.get(i.index)??[],o=a.flatMap(e=>n.get(e.index)??[]);n.set(i.index,F(i,a.length,o))}return n}function F(e,t,n){let r=L(e,t),i=r??R(e);return{...i?{showRect:i}:{},showChildren:r?[]:n,...r?{paintRect:r}:{},paintChildren:r?[]:n,hasAction:e.hittable===!0||n.some(I)}}function I(e){return e.hasAction}function L(e,n){if(t(e.rect))return e.hittable===!0||i(e.type)||n===0&&z(e)?e.rect:void 0}function R(e){return t(e.rect)&&B(e)?e.rect:void 0}function z(e){return!!(e.label?.trim()||e.value?.trim())}function B(e){return!!(e.label?.trim()||e.value?.trim()||e.identifier?.trim())}function V(e,t,n){let r=[],i=[e];for(;i.length>0;){if(!H(n))return r;let e=i.pop(),a=t===`paint`?e.paintRect:e.showRect;a&&r.push(a),i.push(...t===`paint`?e.paintChildren:e.showChildren)}return r}function H(e){return U(e,1)}function U(e,t){return t>e.remaining?(e.exhausted=!0,!1):(e.remaining-=t,!0)}function W(e,t){let n=new Set,r=[...e];for(;r.length>0;){let e=r.pop();if(!n.has(e)){n.add(e);for(let n of t.get(e)??[])r.push(n.index)}}return n}function G(e){let t=new Map;for(let[n,r]of e.entries())t.set(r.index,n);let n=[],r=[];for(let[i,a]of e.entries()){let e=Math.max(0,a.depth??0);for(;r.length>0&&e<=r.at(-1).depth;)r.pop();let o=i,s=typeof a.parentIndex==`number`?t.get(a.parentIndex):void 0,c=typeof s==`number`&&s<o?s:r.at(-1)?.index;n.push({...a,index:o,depth:e,parentIndex:c}),r.push({depth:e,index:o})}return n}function K(e){let t=[],n=[];for(let r of e){let e=r.depth??0;for(;t.length>0&&e<=t.at(-1);)t.pop();let i=a(r.type??``),c=s(o(r));if((i===`group`||i===`ioscontentgroup`)&&!c){t.push(e);continue}let l=Math.max(0,e-t.length);n.push({...r,depth:l})}return n}var q=e({buildSnapshotState:()=>Y,snapshotPresentationOptionsFromFlags:()=>J});function J(e){return l(e,d)}function Y(e,t){let i=e?.nodes??[],a=t?.snapshotRaw,o=Q(e,i,a===!0),s=G(a?o:K(o)),l=t?.snapshotScope&&te(e?.backend)?x(s,t.snapshotScope):s,d=f(e),h=J(t),v=u(a?l:Z(y(l,{...$(e?.backend),producer:e?.producer})),n(e)),b=_(e.nodes);return b&&m(v,b),g(e.nodes,v),{nodes:v,truncated:e?.truncated,createdAt:Date.now(),...r(e),...p({quality:d.quality,qualityNotes:d.qualityNotes}),...e.comparisonIdentity?{comparisonKey:S(e.comparisonIdentity)}:{},...e.systemSurface?{iosSystemSurfaceBundleId:e.systemSurface.bundleId}:{},...e.presentedSurface?{presentedSurface:e.presentedSurface}:{},...e.targetActivation?{targetActivation:e.targetActivation}:{},...e.keyboard?{keyboard:e.keyboard}:{},...X(e),presentationKey:c(h),presentation:h,comparisonSafe:ne(e?.backend,t)}}function X(e){return{...e.viewport?{viewport:e.viewport}:{},...e.captureScale?{captureScale:e.captureScale}:{}}}function Z(e){return e.map(e=>e.rect&&!t(e.rect)?{...e,presentationHints:[...e.presentationHints??[],`unmeasured`]}:e)}function Q(e,t,n){return e.backend===`android`&&!n?ee(e,t):t}function $(e){return e===`android`?{isAdditionalOverlayNode:b}:{}}function ee(e,t){let n=h(e),r=k(n?.nodes??t,n?.androidSiblingOrderByNodeIndex);return v(t,e=>{let t=n?.sourceIndexByNodeIndex.get(e.index)??e.index;return r.has(t)})}function te(e){return e===void 0||e===`linux-atspi`||e===`harmonyos-arkui`||e===`web`}function ne(e,t){return e===`android`&&t?.snapshotInteractiveOnly!==!0&&typeof t?.snapshotDepth!=`number`&&!t?.snapshotScope}export{J as n,q as r,Y as t};