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.94 kB
JavaScript
import{k as e,v as t}from"./sdk-contracts.js";import{U as n,x as r}from"./sdk-device.js";import{_ as i,u as a}from"./runner-contract.js";import{r as o}from"./touch-runtime.js";async function s(t,n,o,s,p){let m=l(u(t,n,o),20).map(e=>a(e,s)),h,g,_=0,v=[],y=0,b,x=r(t)&&m.length>1;for(let t of m){let n;try{n=await p(b===void 0?t:{...t,sequenceOrientation:b})}catch(t){throw e(t,_)}h??=n,g=n;let r;try{r=i(n)}catch(t){throw e(f(t,y),_+d(t))}_+=r.completedSteps,v.push(...r.results),y+=t.steps?.length??0,x&&(b??=c(r.sequenceOrientation,_))}return{...h??{},completedSteps:_,sequenceResults:v,...g?.gestureEndUptimeMs===void 0?{}:{gestureEndUptimeMs:g.gestureEndUptimeMs},timingMode:`runner-sequence`}}function c(n,r){if(n!==void 0)return n;throw e(new t(`COMMAND_FAILED`,`The runner did not return the press series orientation`,{reason:`runner_sequence_orientation_unavailable`,completedSteps:r,hint:`Run snapshot -i to inspect the current UI before continuing with the remaining actions.`}),r)}function l(e,t,n=2e4){let r=[],i=[],a=0;for(let o of e){let e=(o.durationMs??0)+(o.pauseMs??0)+250;i.length>0&&(i.length>=t||a+e>n)&&(r.push(i),i=[],a=0),i.push(o),a+=e}return i.length>0&&r.push(i),r}function u(e,t,r){let i=r.doubleTap?`doubleTap`:r.holdMs>0?`longPress`:`tap`,a=i===`tap`&&n(e);return Array.from({length:r.count},(e,n)=>{let[s,c]=o(n,r.jitterPx);return{kind:i,x:t.x+s,y:t.y+c,...a?{synthesized:!0}:{},...r.holdMs>0?{durationMs:r.holdMs}:{},...n<r.count-1&&r.intervalMs>0?{pauseMs:r.intervalMs}:{}}})}function d(e){let n=e instanceof t?e.details?.completedSteps:void 0;return typeof n==`number`?n:0}function f(e,n){if(n===0||!(e instanceof t)||!e.details)return e;let r=e.details.failedStepIndex;if(typeof r!=`number`)return e;let i=e.details.completedSteps;return new t(e.code,e.message,{...e.details,failedStepIndex:r+n,chunkStepIndex:r,...typeof i==`number`?{completedSteps:n+i}:{}},e.cause)}export{s as runApplePressSeries};