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.37 kB
JavaScript
import{s as e}from"./sdk-contracts.js";import{a as t,n}from"./recording-scope.js";import{o as r}from"./session-store.js";import{V as i}from"./parameterized-recorded-fill.js";import{t as a}from"./session-paths.js";import"./screen-recording-admission-ledger.js";import{n as o}from"./context.js";import{t as s}from"./record-runtime.js";import c from"node:fs";import l from"node:path";function u(r){let i=t(r.req.positionals);if(!i)return e(`INVALID_ARGS`,n);let a=r.sessionStore.lookup(r.sessionName);return a?i===`start`?d(r.host,r.req,r.sessionStore,a):f(r.host,r.req,r.sessionStore,a):e(`SESSION_NOT_FOUND`,`No active session`)}function d(t,n,i,s){let u=i.requireCurrent(s);if(u.trace)return e(`INVALID_ARGS`,`trace already in progress`);let d=a(n.positionals?.[1]??i.defaultTracePath(u),o(n,t));return c.mkdirSync(l.dirname(d),{recursive:!0}),c.appendFileSync(d,``),u.trace={outPath:d,startedAt:Date.now(),clientOutPath:n.meta?.clientArtifactPaths?.outPath,...n.internal?.publicNetworkOnly?{remoteCaptureOutputPath:d}:{},remoteCaptureTenantId:u.lease?.tenantId??n.meta?.tenantId},r(i,s,n,n.command,{action:`start`,outPath:d}),{ok:!0,data:{trace:`started`,outPath:d}}}function f(t,n,a,s){let c=a.requireCurrent(s);if(!c.trace)return e(`INVALID_ARGS`,`no active trace`);let u=p(o(n,t),c.trace.outPath,n.positionals?.[1]),d=c.trace.remoteCaptureOutputPath===u,f=c.trace.remoteCaptureTenantId,m=n.meta?.clientArtifactPaths?.outPath??c.trace.clientOutPath??(n.internal?.publicNetworkOnly?void 0:u);return c.trace=void 0,r(a,s,n,n.command,{action:`stop`,outPath:u}),{ok:!0,data:i({trace:`stopped`,outPath:u,artifacts:[{field:`outPath`,artifactType:`trace-log`,path:u,localPath:m,fileName:l.basename(m??u)}]},d?`daemon`:`caller`,f)}}function p(e,t,n){if(!n)return t;let r=a(n,e);return c.mkdirSync(l.dirname(r),{recursive:!0}),c.existsSync(t)?c.renameSync(t,r):c.appendFileSync(r,``),r}async function m(e){let{req:t,sessionName:n,sessionStore:r}=e,i=t.command;return i===`record`?s({req:t,sessionName:n,sessionStore:r,bindDevice:e.bindDevice,platformServices:e.platformServices,bindExactDevice:e.bindExactDevice,admissionLedger:e.admissionLedger,requestScope:e.requestScope,retainDeviceExecutionLock:e.retainDeviceExecutionLock,throwIfCanceled:e.throwIfCanceled}):i===`trace`?u({host:e.host,req:t,sessionName:n,sessionStore:r}):null}export{m as handleRecordTraceCommands};