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.42 kB
JavaScript
import{v as e}from"./sdk-contracts.js";import{H as t}from"./sdk-io.js";import{t as n}from"./recording-export-quality.js";import"./retry.js";import{t as r}from"./screen-recording-runtime.js";import{a as i,c as a,n as o,o as s,s as c,t as l}from"./video.js";import{n as u}from"./telemetry.js";import d from"node:fs";import f from"node:path";function p(e=process.platform){if(e!==`darwin`)return`touch overlay burn-in is only available on macOS hosts; returning raw video plus gesture telemetry`}const m=7e4;function h(){return t.fromTimeoutMs(m)}const g=5e3;async function _(t){let{host:n,videoPath:r,scriptArgs:o,commandDescription:s,deadline:l}=t,u=v(r),f=!1;try{let{RECORDING_OVERLAY_SOURCES:t}=await import(`./recording-swift-sources.js`),s=await c({host:n,cacheName:`recording-overlay`,sources:t,timeoutMs:Math.max(1,l.remainingMs())}),p=l.remainingMs(),h=p-g;if(h<=0)throw new e(`COMMAND_FAILED`,`No time was left for the export within the ${m}ms budget`);try{await a(n,s,[`--input`,r,`--output`,u,...o,`--timeout-ms`,String(Math.round(h))],{timeoutMs:p})}catch(e){throw f=l.remainingMs()<=g,e}if(!await i(u,{host:n,deadline:l}))throw f=l.isExpired(),new e(`COMMAND_FAILED`,`The composited video was not verified as playable`);d.renameSync(u,r)}catch(t){let n=f?`${s}: the export did not finish within its ${m}ms budget; a lower --fps renders faster`:s,i=t instanceof e?t:new e(`COMMAND_FAILED`,String(t),void 0,t instanceof Error?t:void 0);throw new e(`COMMAND_FAILED`,n,{...i.details,videoPath:r,script:`recording-overlay.swift`},i)}finally{d.rmSync(u,{force:!0})}}function v(e){let t=f.parse(e),n=`${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`;return f.join(t.dir,`.${t.name}.agent-device-${n}${t.ext||`.mp4`}`)}async function y(e){let{videoPath:t,telemetryPath:r,exportQuality:i=n,targetLabel:a=`recording`}=e;await _({host:e.host,videoPath:t,scriptArgs:[`--events`,r,`--quality`,i,...e.fps===void 0?[]:[`--max-fps`,String(e.fps)]],commandDescription:`Failed to add touch overlays to the ${a}`,deadline:e.deadline})}function b(e){return Object.freeze({sniff:async e=>await x(e),complete:async t=>await S(e,t)})}async function x(e){if(!await l(e.outputPath))throw w(e.outputPath)}async function S(e,t){let n=h();if(await s(t.outputPath),!await i(t.outputPath,{host:e,deadline:n}))throw w(t.outputPath);let r=u({recording:{outPath:t.outputPath,gestureEvents:[...t.gestureEvents]}});return!t.showTouches||t.gestureEvents.length===0?{telemetryPath:r}:await C(e,t,r,n)}async function C(e,t,n,r){let i=p();if(i)return{telemetryPath:n,overlayWarning:i};try{if(await y({host:e,videoPath:t.outputPath,telemetryPath:n,exportQuality:t.exportQuality,...t.fps===void 0?{}:{fps:t.fps},targetLabel:t.targetLabel,deadline:r}),!await o(t.outputPath,e))throw Error(`recording post-processing produced an unplayable video`);return{telemetryPath:n}}catch(e){return{telemetryPath:n,overlayWarning:`failed to overlay recording touches: ${e instanceof Error?e.message:String(e)}`}}}function w(t){return new e(`COMMAND_FAILED`,`recording was not finalized into a playable video: ${t}`,{reason:r,retriable:!0,hint:`Run record stop again: a recorder that is still finalizing its file is playable on the next stop, and the recording keeps its evidence either way. If the recorder died before writing a video, close this session to release the device and record again.`})}export{b as createScreenRecordingFinalizer};