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.21 kB
import{v as e}from"./sdk-contracts.js";import{URL as t}from"node:url";function n(n){if(!n)return;let i=a(n.metroHost),c=o(n.metroPort),l=`http`,u=r(n.bundleUrl);if(u){let n;try{n=new t(u)}catch(t){throw new e(`INVALID_ARGS`,`Invalid runtime bundle URL: ${u}`,{},t)}(n.protocol===`http:`||n.protocol===`https:`)&&(i??=r(n.hostname),c??=o(n.port.length>0?Number(n.port):s(n.protocol)),l=n.protocol===`https:`?`https`:`http`)}if(!(!i||!c))return{host:i,port:c,scheme:l}}function r(e){let t=e?.trim();return t&&t.length>0?t:void 0}function i(e){let r=n(e);if(!r)return;let i=r.host.includes(`:`)&&!r.host.startsWith(`[`)?`[${r.host}]`:r.host,a=new t(`${r.scheme}://${i}:${r.port}`);if(e?.bundleUrl?.trim()){let n=new t(e.bundleUrl).pathname.replace(/\/+$/,``);a.pathname=n.endsWith(`/.expo/.virtual-metro-entry.bundle`)?n.slice(0,-34):/\.(?:bundle|jsbundle|js)$/.test(n)?n.slice(0,n.lastIndexOf(`/`)):n}return a}function a(t){let n=r(t);if(n&&/[/\\?#@\s]/.test(n))throw new e(`INVALID_ARGS`,`Invalid runtime Metro host: ${n}. Use a hostname or IP address.`);return n}function o(e){if(Number.isInteger(e)&&!(e<=0||e>65535))return e}function s(e){if(e===`https:`)return 443;if(e===`http:`)return 80}export{n,r,i as t};