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 • 2.35 kB
import{J as e}from"./sdk-device.js";import{a as t,r as n}from"./durable-resource.js";import{n as r}from"./screen-recording-runtime.js";import{n as i}from"./async-lifecycle.js";import{n as a,t as o}from"./screen-recording-completion.js";import{t as s}from"./screen-recording-options.js";function c(e){return Object.freeze({resourceKind:r,version:1,encode:e=>({...e}),decode:t=>t.backend===e&&typeof t.outputPath==`string`?{status:`decoded`,descriptor:Object.freeze({backend:e,outputPath:t.outputPath})}:{status:`invalid`,message:`Invalid ${e} screen-recording descriptor`}})}function l(e){return{status:`unreattachable`,reason:`transport-not-reattachable`,message:e}}function u(e){return{status:`cleanup-pending`,reason:`manual-recovery-required`,message:e}}async function d(l){let{host:u,device:d,owner:m,input:h,signal:g,transport:_}=l;s(h,l.support,l.unsupported),g.throwIfAborted(),await u.screenRecording.outputs.prepare(h.outputPath);let v=f(_),y=!1;try{await _.start(g),y=!0,g.throwIfAborted()}catch(e){throw y&&await v().catch(()=>{}),g.throwIfAborted(),e}let b=a(p(_.backend,h),{finish:async e=>{let t=await v();_.collect&&await _.collect(t,e.outPath);let n=await u.screenRecording.finalize.complete({outputPath:e.outPath,showTouches:!1,gestureEvents:e.gestureEvents,...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},targetLabel:_.targetLabel});return o(e,n,{stopObservation:{recorder:`confirmed`},showTouches:!1})},forceCleanup:async()=>{try{return await v(),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`${_.backend} recording cleanup failed`}}}});return Object.freeze({pendingHandle:new i(b),envelope:n({resourceKind:r,sessionId:h.sessionId,device:e(d),owner:m,fence:h.fence,lifecycle:`open`,descriptor:t(c(_.backend),{backend:_.backend,outputPath:h.outputPath})})})}function f(e){let t;return()=>t??=e.stop().catch(e=>{throw t=void 0,e})}function p(e,t){return Object.freeze({backend:e,outPath:t.outputPath,...t.clientOutputPath===void 0?{}:{clientOutPath:t.clientOutputPath},startedAt:Date.now(),scope:t.scope,showTouches:!1,recordOnlySession:t.recordOnlySession,...t.activeSessionApp===void 0?{}:{activeSessionApp:t.activeSessionApp},...t.exportQuality===void 0?{}:{exportQuality:t.exportQuality},gestureEvents:[]})}export{u as n,l as r,d as t};