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.69 kB
import{v as e}from"./sdk-contracts.js";import{st as t}from"./sdk-io.js";import{t as n}from"./sdk-remote-config.js";import"./command.js";import{r}from"./remote-config-core.js";function i(e){return e===`android-instance`||e===`ios-instance`}function a(e){return[`exec`,`--yes`,`--package`,`agent-cdp@1.6.1`,`--`,`agent-cdp`,...e]}function o(e){return e.some(e=>e===`--url`||e.startsWith(`--url=`))}function s(e){return e[0]===`target`&&(e[1]===`list`||e[1]===`select`)&&!o(e)}function c(e){let t=new URL(e);t.search=``,t.hash=``;let n=t.pathname.replace(/\/+$/,``);return t.pathname=n.endsWith(`/index.bundle`)?n.slice(0,-13)||`/`:n||`/`,t.toString().replace(/\/+$/,``)}function l(e){let t=e?.metroPublicBaseUrl?.trim();return t?c(t):null}function u(t,n={}){if(!s(t)||!n.flags?.metroProxyBaseUrl||!i(n.flags.leaseBackend))return t;let r=l(n.flags);if(!r)throw new e(`INVALID_ARGS`,`cdp remote bridge target discovery requires a React Native dev-server public base URL.`,{hint:`Include metroPublicBaseUrl in the remote config so cdp can reach the local or tunneled Metro/Re.Pack CDP endpoint without bridge proxy authentication.`});return[...t,`--url`,r]}async function d(e,n){let r=u(e,n);return(await t(`npm`,a(r),{cwd:n.cwd,env:n.env,allowFailure:!0,onStdoutChunk:e=>{process.stdout.write(e)},onStderrChunk:e=>{process.stderr.write(e)}})).exitCode}const f=n.map(e=>e.key);function p(e){let t={};for(let n of f){let r=e[n];r!==void 0&&(t[n]=r)}return t}function m(e){if(!e.remoteConfig)return{flags:{}};let t=r({configPath:e.remoteConfig,cwd:e.cwd,env:e.env});return{flags:{...p(t.profile),remoteConfig:e.remoteConfig},leaseProvider:t.profile.leaseProvider}}export{s as i,m as n,d as r,p as t};