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 • 3.22 kB
JavaScript
import{k as e,v as t}from"./sdk-contracts.js";import{i as n,n as r,r as i}from"./interactor-operation-binding.js";function a(e){let t=t=>t??e.unsupported;return Object.freeze({tapPoint:e.tap,tapRef:t(e.tapRef),longPressPoint:e.longPress,hoverPoint:o(t(e.hover)),hoverRef:o(t(e.hoverRef)),fillPoint:e.fill,fillRef:t(e.fillRef),tapElementSelector:t(e.tapElementSelector)})}function o(e){return e.available?e:Object.freeze({...e,hint:e.hint??`hover raises pointer hover state and is available on web targets only. On touch platforms use longpress for hold gestures.`})}function s(e,t){return{...e.execution,appBundleId:e.appBundleId,signal:t}}function c(e,t,r,i){let a=async n=>(e.throwIfAborted(),await t(s(n,e))),o=async t=>{e.throwIfAborted(),l(t.options,r.longPressPoint);let n=await a(t);return t.options.button!==`primary`&&n.alternateClick?await n.alternateClick(t.point,t.options.button):n.pressPoint?await n.pressPoint(t.point,t.options):await d(n,t.point,t.options,i)},c=async e=>{let t=await a(e);return await n(t.hover,`hoverPoint`).call(t,e.point.x,e.point.y)},u=async e=>await(await a(e)).fill(e.point.x,e.point.y,e.text,e.delayMs,{allowNonHittableCoordinateFallback:e.allowNonHittableCoordinateFallback});return Object.freeze({...r.tapPoint.available?{tapPoint:o}:{},...r.tapRef.available?{tapRef:async e=>{let t=await a(e);return await n(t.tapRef,`tapRef`).call(t,e.ref)}}:{},...r.longPressPoint.available?{longPressPoint:async e=>await(await a(e)).longPress(e.point.x,e.point.y,e.durationMs)}:{},...r.hoverPoint.available?{hoverPoint:c}:{},...r.hoverRef.available?{hoverRef:async e=>{let t=await a(e);return await n(t.hoverRef,`hoverRef`).call(t,e.ref)}}:{},...r.fillPoint.available?{fillPoint:u}:{},...r.fillRef.available?{fillRef:async e=>{let t=await a(e);return await n(t.fillRef,`fillRef`).call(t,e.ref,e.text,e.delayMs)}}:{},...r.tapElementSelector.available?{tapElementSelector:async e=>{let t=await a(e);return await n(t.tapElementSelector,`tapElementSelector`).call(t,e.selector)}}:{}})}function l(e,n){if(!(e.holdMs<=0||n.available))throw new t(`UNSUPPORTED_OPERATION`,`press-and-hold is not supported by this runtime.`,{reason:n.reason,...n.hint===void 0?{}:{hint:n.hint}})}function u(e){if(e.doubleTap)return e.doubleTap;throw new t(`UNSUPPORTED_OPERATION`,`double-tap is not supported by this runtime.`,{reason:`owner-capability-missing`,hint:`This runtime drives single presses; use --count to repeat them.`})}async function d(n,r,i,a){if(i.button!==`primary`)throw new t(`UNSUPPORTED_OPERATION`,`Bound runtime does not implement ${i.button} click.`);let o=i.doubleTap?u(n):void 0,s,c=0;try{for(let e=0;e<i.count;e+=1){let[t,l]=m(e,i.jitterPx),u=await f(n,o,r.x+t,r.y+l,i);c+=1,s??=u,e<i.count-1&&i.intervalMs>0&&await a(i.intervalMs)}}catch(t){throw e(t,c)}return s}async function f(e,t,n,r,i){return t?await t.call(e,n,r):i.holdMs>0?await e.longPress(n,r,i.holdMs):await e.tap(n,r)}const p=[[0,0],[1,0],[0,1],[-1,0],[0,-1],[1,1],[-1,1],[1,-1],[-1,-1]];function m(e,t){if(t<=0)return[0,0];let[n,r]=p[e%p.length];return[n*t,r*t]}function h(e){return c(e.signal,r(e),e.facts,e.pause)}function g(e){return c(e.signal,i({...e,operation:`touch`}),e.facts,e.pause)}export{a as i,g as n,m as r,h as t};