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.55 kB
JavaScript
import{v as e}from"./sdk-contracts.js";import{h as t}from"./sdk-io.js";import{t as n}from"./src.js";import{h as r}from"./daemon-resolution.js";async function i(i){let a=i.host??t(process),o={env:{...a.env},cwd:a.cwd};if(typeof i.stateDir!=`string`||i.stateDir.trim().length===0)throw new e(`INVALID_ARGS`,`startAgentDevice requires a stateDir.`,{hint:`Pass an explicit stateDir to startAgentDevice({ stateDir }).`});let s=(i.plugins??[]).map(e=>({source:`embedder`,load:()=>e})),c={env:{...o.env,AGENT_DEVICE_STATE_DIR:i.stateDir,AGENT_DEVICE_DAEMON_SERVER_MODE:`socket`},cwd:o.cwd},l=r(i.stateDir,{env:c.env,cwd:c.cwd}).baseDir,[{startDaemonRuntime:u},{composeDaemonRuntimeDeps:d},{resolveLocalDaemonCodeIdentity:f}]=await Promise.all([import(`./src2.js`).then(e=>e.t),import(`./daemon-composition.js`),import(`./src4.js`).then(e=>e.a)]),p=await f(),m={write:()=>{}},h=await u({host:c,stdout:m,stderr:m,ownership:`embedded`,codeIdentity:p,composeDeps:async e=>await d(e,s)});try{let t=h.identity;if(t.startTime===null)throw new e(`COMMAND_FAILED`,`This host cannot pin its runtime identity.`,{reason:`host_instance_unreadable`,pid:t.pid,hint:`Use a detached daemon on this platform.`});let r=Object.freeze({stateDir:l,daemonLifecycle:`attach`,daemonTransport:`socket`,cwd:o.cwd,daemonBaseUrl:``,daemonBinding:Object.freeze({token:h.token,pid:t.pid,processStartTime:t.startTime})});return Object.freeze({client:n(r,{host:o}),clientConfig:r,close:()=>h.close()})}catch(e){throw await h.close({cause:e}).catch(()=>{}),e}}export{i as startAgentDevice};