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 • 1.9 kB
import{F as e}from"./sdk-contracts.js";import{Q as t}from"./sdk-io.js";import{t as n}from"./ttl-memo.js";import"./command.js";import{u as r}from"./host-file.js";import{i,s as a}from"./simctl.js";import{remainingLookupBudget as o}from"./simulator-app-budget.js";import s from"node:path";import{fileURLToPath as c}from"node:url";async function l(e,t,n){let r=o(n??{}),i=await e.simctl.run(a(t,[`listapps`,t.id]),{allowFailure:!0,...r()}),s={type:`unreadable`,exitCode:i.exitCode,stderr:String(i.stderr??``)},c=i.stdout.trim();if(!c.startsWith(`{`))return s;let l=u(c)??await d(e.runCommand,c,r());return l?{type:`listed`,apps:Object.entries(l).map(([e,t])=>{let n=f(t);return{bundleId:e,name:t.CFBundleDisplayName??t.CFBundleName??e,...n?{path:n}:{},...t.ApplicationType?{applicationType:t.ApplicationType}:{}}})}:s}function u(e){try{return JSON.parse(e)}catch{return null}}async function d(n,r,i){try{let e=await n(`plutil`,[`-convert`,`json`,`-o`,`-`,`-`],{allowFailure:!0,stdin:r,...i});return e.exitCode!==0||!e.stdout.trim().startsWith(`{`)?null:JSON.parse(e.stdout)}catch(n){if(t(n)||e(n))throw n;return null}}function f(e){if(e.Path)return e.Path;if(e.Bundle)try{return c(e.Bundle)}catch{return}}const p=n({ttlMs:18e5,scheduleExpiry:!0});async function m({simctl:e,runCommand:t},{device:n,bundleId:c,appPath:l,...u}){let d=o(u);if(!l){let t=await e.run(a(n,[`get_app_container`,n.id,c,`app`]),{allowFailure:!0,...d()});if(l=i(String(t.stdout)),t.exitCode!==0||!l)return null}let f=s.join(l,`Info.plist`),m;try{m=`${f}:${(await r(f)).mtimeMs}`}catch{m=void 0}u.signal?.throwIfAborted();let h=m===void 0?void 0:p.get(m);if(h)return h;let g=await t(`plutil`,[`-convert`,`json`,`-o`,`-`,f],{allowFailure:!0,...d()});if(g.exitCode!==0)return null;try{let e=JSON.parse(g.stdout);return m!==void 0&&e&&p.set(m,e),e}catch{return null}}export{m as readSimulatorAppInfoPlist,l as readSimulatorAppMetadata};