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 • 2.67 kB
JavaScript
import{r as e}from"./rolldown-runtime.js";import{v as t}from"./sdk-contracts.js";import{H as n,K as r,Z as i,et as a}from"./sdk-io.js";import{t as o}from"./ttl-memo.js";import"./command.js";import"./retry.js";import{n as s,t as c}from"./boot-diagnostics.js";import{b as l,f as u,i as d}from"./config.js";import{c as f,s as p}from"./tool-provider.js";import{a as m,r as h}from"./simctl.js";var g=e({SIMULATOR_BOOTED_MEMO_TTL_MS:()=>_,ensureBootedSimulator:()=>w,markSimulatorBooted:()=>x,openIosSimulatorApp:()=>C,readSimulatorBootState:()=>T,requireSimulatorDevice:()=>S,wasSimulatorRecentlyObservedBooted:()=>b});const _=5e3,v=o({ttlMs:_});function y(e){return`${e.id}|${e.simulatorSetPath??``}`}function b(e){return v.get(y(e))===!0}function x(e){v.set(y(e),!0)}function S(e,n){if(e.kind!==`simulator`)throw new t(`UNSUPPORTED_OPERATION`,`${n} is only supported on iOS simulators`)}async function C(e={}){await p(`open`,[`-g`,`-a`,`Simulator`],{allowFailure:!0,signal:e.signal,timeoutMs:l})}async function w(e,o={}){if(e.kind!==`simulator`||(o.signal?.throwIfAborted(),b(e)))return;if(await E(e,o.signal)===`Booted`){x(e);return}let l=n.fromTimeoutMs(d),u,p,m=e=>s({error:e,stdout:p?.stdout??u?.stdout,stderr:p?.stderr??u?.stderr,context:{platform:`ios`,phase:`boot`}});try{await r(async({deadline:n})=>{if(n?.isExpired())throw new t(`COMMAND_FAILED`,`iOS simulator boot deadline exceeded`,{timeoutMs:d});let r=Math.max(1e3,n?.remainingMs()??18e4);u=await f(h(e,[`boot`,e.id]),{allowFailure:!0,signal:o.signal,timeoutMs:r});let s=`${u.stdout}\n${u.stderr}`.toLowerCase(),c=s.includes(`already booted`)||s.includes(`current state: booted`);if(u.exitCode!==0&&!c)throw new t(`COMMAND_FAILED`,`simctl boot failed`,i(u));p=await f(h(e,[`bootstatus`,e.id,`-b`]),{allowFailure:!0,signal:o.signal,timeoutMs:r}),a(p,`simctl bootstatus failed`);let l=await E(e,o.signal);if(l!==`Booted`)throw new t(`COMMAND_FAILED`,`Simulator is still booting`,{state:l})},{maxAttempts:3,baseDelayMs:500,maxDelayMs:2e3,jitter:.2,shouldRetry:e=>{let t=m(e);return t!==`IOS_BOOT_TIMEOUT`&&t!==`CI_RESOURCE_STARVATION_SUSPECTED`}},{deadline:l,phase:`boot`,signal:o.signal,classifyReason:m})}catch(n){let r=m(n);throw new t(`COMMAND_FAILED`,`iOS simulator failed to boot`,{platform:`ios`,deviceId:e.id,timeoutMs:d,elapsedMs:l.elapsedMs(),reason:r,hint:c(r),boot:u,bootstatus:p})}x(e),await C({signal:o.signal})}async function T(e,t){let n=h(e,[`list`,`devices`,`-j`]),r=await f(n,{allowFailure:!0,signal:t.signal,timeoutMs:t.timeoutMs});return r.exitCode===0?m(r.stdout,e.id):null}async function E(e,t){return await T(e,{signal:t,timeoutMs:u})}export{g as a,S as i,x as n,b as o,T as r,w as t};