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.47 kB
JavaScript
import{v as e}from"./sdk-contracts.js";import{et as t}from"./sdk-io.js";import"./command.js";import{T as n,_ as r,o as i,r as a,u as o}from"./host-file.js";import{d as s,i as c,s as l}from"./simctl.js";import u from"node:path";const d=new Map;async function f(t,n){if(n.signal?.throwIfAborted(),u.isAbsolute(n.sourcePath)){await p(``,n);return}let r=JSON.stringify([s(n.device),n.bundleId,n.containerType]),i=d.get(r);if(i)try{await p(i,n);return}catch(e){if(n.signal?.throwIfAborted(),await o(i).then(()=>!0,t=>{if(t.code===`ENOENT`)return!1;throw e}))throw e;d.delete(r)}let a=await t.run(l(n.device,[`get_app_container`,n.device.id,n.bundleId,n.containerType]),{timeoutMs:n.timeoutMs,signal:n.signal}),f=c(a.stdout);if(!f)throw new e(`COMMAND_FAILED`,`simctl get_app_container returned no ${n.containerType} container path`);d.set(r,f),await p(f,n)}async function p(e,t){t.signal?.throwIfAborted();let n=u.isAbsolute(t.sourcePath)?t.sourcePath:u.join(e,t.sourcePath);await i(u.dirname(t.destinationPath)),await a(n,t.destinationPath)}async function m(e,a){let{device:o,bundleId:s,containerType:d,timeoutMs:f,signal:p}=a;p?.throwIfAborted();let m=t(await e.run(l(o,[`get_app_container`,o.id,s,d]),{allowFailure:!0,timeoutMs:f,signal:p}),`simctl get_app_container failed for ${s}`),h=c(m.stdout);return h===void 0?null:{path:h,list:()=>r(h),remove:e=>n(u.join(h,e)),ensureDirectory:e=>i(u.join(h,e))}}export{f as copySimulatorFileToHost,m as openSimulatorContainer};