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 • 5.58 kB
import{r as e}from"./rolldown-runtime.js";import{v as t}from"./sdk-contracts.js";import{a as n}from"./version.js";import{c as r,i,n as a}from"./daemon-resolution.js";import{c as o}from"./device-shell.js";import{i as s}from"./daemon-launch-spec.js";import c from"node:fs";var l=e({DAEMON_CONTENDED_REASON:()=>g,REMOTE_DAEMON_UNAVAILABLE_REASON:()=>m,daemonBusyError:()=>w,daemonContendedError:()=>_,daemonDrainTimeoutError:()=>C,daemonIdentityOf:()=>d,daemonIncompatibleError:()=>S,daemonNotRetirableError:()=>E,daemonNotRunningError:()=>v,daemonRecordUnreadableError:()=>A,daemonRegistrationUnprovenError:()=>k,daemonRetirementUnconfirmedError:()=>y,daemonStopCommand:()=>p,daemonTakeoverRetirementError:()=>b,getDaemonMetadataState:()=>D,isDaemonNotRunningError:()=>x,remoteDaemonUnavailableError:()=>h,resolveDaemonStartupHint:()=>O});const u={notRunning:`daemon-not-running`,incompatible:`daemon-incompatible`,busy:a.busy,drainTimeout:`daemon-drain-timeout`};function d(e){return{pid:e.pid,...e.version===void 0?{}:{version:e.version},...e.codeOrigin===void 0?{}:{codeOrigin:e.codeOrigin},...e.codeSignature===void 0?{}:{codeSignature:e.codeSignature},...e.processStartTime===void 0?{}:{processStartTime:e.processStartTime}}}async function f(){let e=await s();return{version:n(),codeOrigin:e.origin,...e.origin===`checkout`?{codeSignature:e.codeSignature}:{}}}function p(e){return`agent-device daemon stop --state-dir ${o(e)}`}const m=`remote_daemon_unavailable`;function h(e){let{daemonBaseUrl:n,attempts:r,healthRecoveryBudgetMs:i,hint:a}=e;return new t(`COMMAND_FAILED`,`Remote daemon is unavailable`,{reason:m,dispatched:`no`,daemonBaseUrl:n,attempts:r,...i===void 0?{}:{healthRecoveryBudgetMs:i},...a===void 0?{}:{hint:a}})}const g=`daemon-contended`;function _(){return new t(`COMMAND_FAILED`,`Another process started a daemon while this one was starting.`,{reason:g})}function v(e,n){return new t(`COMMAND_FAILED`,`No daemon is running for this state directory.`,{reason:u.notRunning,stateDir:e,...n?{daemon:d(n)}:{},hint:`Start one with a local agent-device command that uses the daemon (agent-device devices --state-dir ${o(e)}, for example), or with ensureDaemon({ stateDir: ${JSON.stringify(e)} }) from the SDK, before attaching.${n?` The registered daemon (pid ${n.pid}) does not answer. ${n.ownership===`embedded`?r(n.pid):`${p(e)} clears it.`}`:``}`})}function y(e,n){return new t(`COMMAND_FAILED`,`Daemon replacement could not be confirmed.`,{reason:`daemon_retirement_unconfirmed`,retirement:e,hint:e.error?.hint??O(D(n),n)})}function b(e,t,n){return e.reason===`embedded-owner`?E({info:t,stateDir:n.baseDir}):e.reason===`owner-unproven`?T({info:t,stateDir:n.baseDir}):y(e,n)}function x(e){return e instanceof t&&e.details?.reason===u.notRunning}async function S(e){let{info:n,mismatch:i,stateDir:a}=e;return new t(`COMMAND_FAILED`,`The running daemon cannot serve this client.`,{reason:u.incompatible,mismatch:i,stateDir:a,daemon:d(n),client:await f(),hint:n.ownership===`embedded`?r(n.pid):`Stop it with ${p(a)}, then retry. SDK clients call ensureDaemon() to start a compatible one.`})}async function C(e,n){let r=n.paths.baseDir;return new t(`COMMAND_FAILED`,`The daemon accepted the request to leave but is still running.`,{reason:u.drainTimeout,stateDir:r,daemon:d(e),hint:`It was not signaled. Retry once it has exited, or stop it deliberately with ${p(r)}.`})}function w(e,n,r){return new t(`COMMAND_FAILED`,`The running daemon is busy and was not replaced.`,{reason:u.busy,stateDir:n,daemon:d(e),...r,hint:r?.startingUp?`The daemon is still starting up. Retry in a moment; if it never finishes starting, stop it with ${p(n)}.`:`Wait for its requests, sessions and leases to end and retry, or stop it deliberately with ${p(n)}.`})}function T(e){let{info:n,stateDir:r}=e;return new t(`COMMAND_FAILED`,`This daemon record states an owner this version cannot read, so this client did not replace it.`,{reason:i,stateDir:r,daemon:d(n),hint:`Update agent-device if the record comes from a newer build. Otherwise check what owns pid ${n.pid}, then repair the record: stop that process by its own means and remove ${o(r)}/daemon.json so a daemon can register again.`})}function E(e){let{info:n,stateDir:i}=e;return new t(`COMMAND_FAILED`,`A host process owns this runtime, so it was not retired.`,{reason:a.ownerEmbedded,stateDir:i,daemon:d(n),hint:r(n.pid)})}function D(e){return{hasInfo:c.existsSync(e.infoPath),hasLock:c.existsSync(e.lockPath)}}function O(e,t){let n=[e.hasInfo?t.infoPath:null,e.hasLock?t.lockPath:null].filter(Boolean).join(` and `);return`Daemon startup did not establish a reachable owner. ${n?`State was retained at ${n}. `:``}Read daemon.log in the state directory. Before upgrading, stop all older clients and daemons with their original CLI and prevent them from returning to this state directory. Unverified lock state requires confirming every user stopped before manual recovery; deleting metadata alone is not a safe reset.`}function k(e,n){return new t(`COMMAND_FAILED`,`Daemon registration ownership could not be verified.`,{reason:`daemon_registration_unproven`,inspection:n,stateDir:e.baseDir,hint:O(D(e),e)})}function A(e){return new t(`COMMAND_FAILED`,`The daemon record on ${e.baseDir} cannot identify a usable daemon.`,{reason:`daemon-record-unreadable`,stateDir:e.baseDir,hint:`No daemon was started, replaced or signaled. Inspect the retained record and its ownership before retrying.`})}export{h as _,d as a,v as c,y as d,p as f,x as g,D as h,C as i,A as l,l as m,w as n,S as o,b as p,_ as r,E as s,g as t,k as u,O as v};