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.76 kB
import{B as e}from"./sdk-contracts.js";import{Et as t,St as n,a as r}from"./sdk-io.js";import"./diagnostics.js";import{h as i}from"./daemon-resolution.js";import{a,i as o,r as s}from"./session-artifact-paths.js";import{t as c}from"./device-claim-reconciliation.js";function l(n){let r=n.composeRecovery??(e=>u(e,n.scope,n.composeGateway));return async i=>{let a=await n.beforeGateway?.(i);if(a?.status===`retained`)return a;let o=r(i.stateDir),s;try{s={status:`fulfilled`,result:await o.reconcile(i,a)}}catch(e){s={status:`rejected`,error:e}}try{await o.dispose()}catch(r){let a;try{a={error:t(e(r))}}catch{a={reason:`diagnostic-data-unserializable`}}try{n.scope.diagnostics.emit({level:`error`,phase:`device_claim_recovery_dispose_failed`,data:{deviceKey:i.deviceKey,ownerSession:i.session,...s.status===`fulfilled`&&s.result.status===`retained`?{retainedReason:s.result.reason}:{},...a}})}catch{}if(s.status===`fulfilled`&&s.result.status===`reconciled`)throw r}if(s.status===`rejected`)throw s.error;return s.result}}function u(e,t,n){let l=i(e),u=n({sessionsDir:l.sessionsDir,ownedProcesses:r({stateDir:l.baseDir,sessionsDir:l.sessionsDir,resolveSessionDir:e=>a(l.sessionsDir,e)}),resolveSessionArtifacts:e=>({outputPath:s(l.sessionsDir,e),pidPath:o(l.sessionsDir,e)})});return{reconcile:c({gateway:u,scope:t}),dispose:async()=>{await u.shutdown()}}}const d=new AbortController().signal;function f(){return Object.freeze({signal:d,diagnostics:Object.freeze({emit:e=>n(e)}),progress:Object.freeze({report:()=>{}})})}async function p(e){return(await import(`./device-claim-admission.js`)).inspectDeviceClaimAdmission(e)}async function m(e){return(await import(`./device-claim-admission.js`)).inspectNewSessionAdmission(e)}export{l as i,m as n,f as r,p as t};