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 • 3.51 kB
JavaScript
import{v as e}from"./sdk-contracts.js";import{f as t,h as n}from"./file.js";import{r,s as i}from"./version.js";import a from"node:crypto";import o from"node:fs";import s from"node:path";function c(e,t={}){let n=l(e,t);return{baseDir:n,infoPath:s.join(n,`daemon.json`),lockPath:s.join(n,`daemon.lock`),logPath:s.join(n,`daemon.log`),allocationsDir:s.join(n,`allocations`),sessionsDir:s.join(n,`sessions`)}}function l(r,i){let a=(r??``).trim();if(!a)return u(i);let o=t(a,{env:i.env});if(s.isAbsolute(o))return o;if(i.cwd===void 0)throw new e(`INVALID_ARGS`,`State dir "${a}" is relative and no working directory was given.`,{reason:`relative_state_dir_without_cwd`});return n(a,{env:i.env,cwd:i.cwd})}function u(e={}){let n=s.join(t(`~`,{env:e.env}),`.agent-device`),a=e.projectRoot??r();return i(a)?s.join(n,`dev`,d(a)):n}function d(e){let t=f(e),n=s.basename(t).replaceAll(/[^a-zA-Z0-9._-]+/g,`-`),r=a.createHash(`sha1`).update(t).digest(`hex`).slice(0,12);return`${n||`agent-device`}-${r}`}function f(e){try{return o.realpathSync.native(e)}catch{return s.resolve(e)}}function p(e){let t;try{t=o.readFileSync(e,`utf8`)}catch(e){let t=e?.code;return{status:t===`ENOENT`||t===`ENOTDIR`?`absent`:`unreadable`}}try{let e=JSON.parse(t);return typeof e==`object`&&e&&!Array.isArray(e)?{status:`present`,record:e}:{status:`invalid`}}catch{return{status:`invalid`}}}function m(e){return e===`socket`||e===`http`||e===`dual`?e:void 0}function h(e){let t=(e??``).trim().toLowerCase();return t===`http`?`http`:t===`dual`?`dual`:`socket`}function g(e){let t=(e??``).trim().toLowerCase();return t===`auto`?`auto`:t===`socket`?`socket`:t===`http`?`http`:`auto`}const _=[`quiesce`,`script-artifacts`],v=[`detached`,`embedded`,`unknown`];function y(e){return v.includes(e)?e:e===void 0?`detached`:`unknown`}const b=`daemon_quiesce`,x=`daemon_shutting_down`,S={busy:`daemon-busy`,instanceMismatch:`daemon-instance-mismatch`,ownerEmbedded:`daemon-owner-embedded`},C=`daemon-owner-unrecognized`;function w(e){let{token:t,fence:n,requestId:r}=e;return{token:t,session:`default`,command:b,positionals:[],input:{pid:n.pid,processStartTime:n.processStartTime},meta:{requestId:r}}}function T(e){if(typeof e!=`object`||!e)return;let{pid:t,processStartTime:n}=e;if(Number.isInteger(t)&&(n===null||typeof n==`string`))return{pid:t,processStartTime:n}}function E(t){if(!t?.includes(`script-artifacts`))throw new e(`INVALID_ARGS`,`The remote daemon cannot deliver session scripts.`,{reason:`remote_script_artifacts_unsupported`,daemonRequestSent:!1,hint:`Upgrade the daemon that owns the session. Through a proxy, the upstream daemon must report the script-artifacts capability in its /health response.`})}function D(e){return Array.isArray(e)?_.filter(t=>e.includes(t)):[]}function O(e){if(typeof e!=`object`||!e)return;let{startingUp:t,inFlightRequests:n,sessions:r,repairSessions:i,leases:a}=e;if((t===void 0||typeof t==`boolean`)&&[n,r,i,a].every(e=>Number.isSafeInteger(e)&&e>=0))return{startingUp:t===!0,inFlightRequests:n,sessions:r,repairSessions:i,leases:a}}function k(e){return`${e===void 0?`The runtime is owned by its host process.`:`The runtime is owned by host process ${e}.`} Close it there with the handle returned by startAgentDevice(). Recovery with daemon stop or ensureDaemon() for this state directory retires the abandoned registration only when the recorded host lifetime has provably exited.`}export{g as _,x as a,k as c,T as d,y as f,h as g,c as h,C as i,D as l,m,S as n,E as o,p,b as r,w as s,_ as t,O as u};