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 • 2.61 kB
import{rt as e,ut as t}from"./sdk-io.js";import{t as n}from"./platform-runtime-android-mechanics.js";import"./command.js";import{r,t as i}from"./device-shell.js";import{p as a}from"./host-file.js";import{constants as o}from"node:fs";import s from"node:os";import c from"node:path";import{access as l,mkdtemp as u,readFile as d,rm as f,writeFile as p}from"node:fs/promises";function m(){return Object.freeze({isXcrunAvailable:async e=>{let{resolveAppleToolProvider:t}=await h(async()=>await import(`./tool-provider-facade.js`).then(e=>e.t),e),n=t();return await h(async()=>await n.whichCommand(`xcrun`),e)},run:async(e,t)=>{let{resolveAppleToolProvider:n,runXcrun:r}=await h(async()=>await import(`./tool-provider-facade.js`).then(e=>e.t),t),i={allowFailure:e.allowFailure,signal:t,timeoutMs:e.timeoutMs},a=await h(async()=>e.tool===`simctl`?await n().simctl.run(e.args,i):await r([e.tool,...e.args],i),t);return{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode}}})}async function h(e,t){t?.throwIfAborted();try{let n=await e();return t?.throwIfAborted(),n}catch(e){throw t?.throwIfAborted(),e}}function g(e){return Object.freeze({prepare:async t=>{if(t===`android`){let{ensureAndroidSdkPathConfigured:t}=await n();await t(e);return}if(t===`harmonyos`){let{ensureHarmonyToolchainPathConfigured:t}=await import(`./src11.js`).then(e=>e.b);await t(e)}}})}function _(e){let t=r(e.executable);return t&&i(e.args,t),e.args}function v(n){let r=n.env;return Object.freeze({which:async e=>await t(e,r)?e:void 0,run:async(t,n)=>{let i=await e(t.executable,_(t),{allowFailure:t.allowFailure,cwd:t.cwd,env:t.env?{...r,...t.env}:void 0,signal:n,timeoutMs:t.timeoutMs});return{stdout:i.stdout,stderr:i.stderr,exitCode:i.exitCode}}})}function y(e){let t=e.env,n=a(t);return Object.freeze({commands:v(e),appleTools:m(),toolchains:g(t),files:Object.freeze({isExecutable:async e=>await x(e),createTemporaryTextFile:async e=>await S(e)}),hostOs:b(process.platform),hostName:s.hostname(),homeDirectory:n,observations:Object.freeze({deviceBooted:async e=>{let{markSimulatorBooted:t}=await import(`./simulator-facade.js`);t(e)}})})}function b(e){return e===`darwin`||e===`linux`||e===`win32`?e:`other`}async function x(e){try{return await l(e,o.X_OK),!0}catch{return!1}}async function S(e){let t=await u(c.join(s.tmpdir(),e.prefix)),n=c.join(t,`value${e.suffix}`),r=!1;return{path:n,readText:async()=>await d(n,`utf8`),writeText:async e=>await p(n,e,`utf8`),[Symbol.asyncDispose]:async()=>{r||(r=!0,await f(t,{recursive:!0,force:!0}))}}}export{y as createDeviceInventoryHost,S as createTemporaryTextFile,g as n,m as r,v as t};