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 • 4.17 kB
JavaScript
import{g as e}from"./sdk-batch-runner.js";import{T as t,w as n}from"./sdk-device.js";import{r}from"./recording-export-quality.js";import{r as i}from"./recording-scope.js";import{i as a,n as o}from"./recording-stop-observation.js";import{t as s}from"./artifact-paths.js";import{t as c}from"./screen-recording-completion.js";async function l(e,t){try{return await e()}catch{if(t?.aborted)throw t.reason;return!1}}function u(e){return e.exitCode===0}function d(e){return process.platform===`darwin`&&(t(e)||n(e)&&e.kind===`simulator`||e.platform===`android`&&e.kind===`emulator`)}const f=[`scope`,`showTouches`,`recordOnlySession`,`activeSessionApp`,`exportQuality`,`fps`];function p(e){return i(e.scope)&&typeof e.showTouches==`boolean`&&typeof e.recordOnlySession==`boolean`&&(e.exportQuality===void 0||r(e.exportQuality))&&m(e.fps)&&h(e.activeSessionApp)}function m(e){return e===void 0||typeof e==`number`&&Number.isInteger(e)&&e>0}function h(t){return t===void 0?!0:!e(t)||!g(t.bundleId)?!1:t.name===void 0||g(t.name)}function g(e){return typeof e==`string`&&e.length>0}function _(e){return e.exportPath===void 0?e.observation===void 0||e.observation.recorder===`unconfirmed`:!1}const v=`stopObservation`,y=`stoppedAtMs`,b=`stopRecorderWarning`,x=`collectedPath`,S=`exportPath`,C=`stopFinalization`,w=Symbol(`unreadable`),T={telemetryPath:M(),warning:M(),overlayWarning:M(),nativePathDisposition:{encode:e=>e,read:e=>e===void 0?void 0:a(e)?e:w},chunks:{encode:e=>e.map(N),read:e=>e===void 0?void 0:P(e)??w},capturedDurationMs:{encode:e=>e,read:e=>e===void 0?void 0:I(e)?e:w}};function E(e){return{...e.observation===void 0?{}:{[v]:O(e.observation)},...e.stoppedAtMs===void 0?{}:{[y]:e.stoppedAtMs},...e.recorderWarning===void 0?{}:{[b]:e.recorderWarning},...e.collectedPath===void 0?{}:{[x]:e.collectedPath},...e.exportPath===void 0?{}:{[S]:e.exportPath},...e.finalization===void 0?{}:{[C]:k(e.finalization)}}}function D(e){let t=e?.[v],n=e?.[y],r=L(e?.[b]),i=L(e?.[x]),a=L(e?.[S]),s=A(e?.[C]);return{...o(t)?{observation:t}:{},...I(n)?{stoppedAtMs:n}:{},...r===void 0?{}:{recorderWarning:r},...i===void 0?{}:{collectedPath:i},...a===void 0?{}:{exportPath:a},...s===void 0?{}:{finalization:s}}}function O(e){return e.recorder===`confirmed`?{recorder:e.recorder}:{recorder:e.recorder,why:e.why}}function k(e){let t={};for(let n of j()){let r=e[n];r!==void 0&&(t[n]=T[n].encode(r))}return t}function A(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e,n={};for(let e of j()){let r=T[e].read(t[e]);if(r===w)return;r!==void 0&&(n[e]=r)}return Object.keys(n).length===0?void 0:n}function j(){return Object.keys(T)}function M(){return{encode:e=>e,read:L}}function N(e){return{index:e.index,path:e.path,...e.clientOutPath===void 0?{}:{clientOutPath:e.clientOutPath}}}function P(e){if(!Array.isArray(e))return;let t=e.map(F);return t.every(e=>e!==void 0)?t:void 0}function F(e){if(typeof e!=`object`||!e)return;let{index:t,path:n,clientOutPath:r}=e,i=L(n),a=L(r);if(!(!Number.isInteger(t)||t<1||i===void 0)&&(r===void 0||a!==void 0))return{index:t,path:i,...a===void 0?{}:{clientOutPath:a}}}function I(e){return typeof e==`number`&&Number.isFinite(e)&&e>=0}function L(e){return typeof e==`string`&&e.length>0?e:void 0}async function R(e){let{steps:t,snapshot:n,progress:r,now:i=Date.now}=e,a=D(r?.learned),o=a.observation,l=a.recorderWarning,u=a.stoppedAtMs;if(_(a)){u=i();let e=await t.stop();o=e.observation,l=e.warning,r?.record(E({observation:o,stoppedAtMs:u,recorderWarning:e.warning}))}if(o===void 0)throw Error(`record stop reached collection without an observation of its recorder and a committed export`);let d=a.collectedPath??s(n.outPath);a.collectedPath===void 0&&(await t.collect(d),r?.record(E({collectedPath:d})));let f=a.finalization??await t.finalize({collectedPath:d,exportPath:n.outPath,stoppedAtMs:u??i()});r?.record(E({exportPath:n.outPath,finalization:f})),await t.discard(d);let{nativePathDisposition:p,warning:m,...h}=f,g=[m,l].filter(e=>e!==void 0&&e.length>0);return c(n,{...h,...g.length===0?{}:{warning:g.join(` `)}},{stopObservation:o,...p===void 0?{}:{nativePathDisposition:p}})}export{d as a,p as i,D as n,u as o,f as r,l as s,R as t};