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.6 kB
JavaScript
import{v as e}from"./sdk-contracts.js";import{yt as t}from"./sdk-io.js";import{i as n,n as r,r as i}from"./sdk-remote-config.js";import{h as a}from"./file.js";import o from"node:fs";import s from"node:path";function c(r){let{env:i}=r,c=d(r);if(!o.existsSync(c))throw new e(`INVALID_ARGS`,`Remote config file not found: ${c}`);let l;try{l=o.readFileSync(c,`utf8`)}catch(t){throw new e(`INVALID_ARGS`,`Failed to read remote config file: ${c}`,{cause:t instanceof Error?t.message:String(t)})}let u;try{u=JSON.parse(l)}catch(t){throw new e(`INVALID_ARGS`,`Invalid JSON in remote config file: ${c}`,{cause:t instanceof Error?t.message:String(t)})}if(!u||typeof u!=`object`||Array.isArray(u))throw new e(`INVALID_ARGS`,`Remote config file must contain a JSON object: ${c}`);let f={},p=u,m=s.dirname(c);for(let[r,o]of Object.entries(p)){let s=n(r);if(!s)throw new e(`INVALID_ARGS`,`Unsupported remote config key "${r}" in remote config file ${c}.`);let l=t(s,o,`remote config file ${c}`,r);f[s.key]=typeof l==`string`&&`path`in s&&s.path?a(l,{cwd:m,env:i}):l}return{resolvedPath:c,profile:f}}function l(e){let n={};for(let a of r){let r=i(a.key).map(t=>({name:t,value:e[t]})).find(e=>typeof e.value==`string`&&e.value.trim().length>0);r&&(n[a.key]=t(a,r.value,`environment variable ${r.name}`,r.name))}return n}function u(...e){let t={};for(let n of e)if(n)for(let e of r){let r=n[e.key];r!==void 0&&(t[e.key]=r)}return t}function d(e){let{env:t}=e;return a(e.configPath,{cwd:e.cwd,env:t})}function f(e){let t=c(e);return{resolvedPath:t.resolvedPath,profile:u(l(e.env),t.profile)}}export{d as n,f as r,c as t};