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.

2 lines • 2.62 kB
import{c as e,v as t}from"./sdk-contracts.js";import{r as n}from"./src.js";import{h as r}from"./file.js";import{t as i}from"./cli-runner.js";import{n as a,r as o}from"./src7.js";import{t as s}from"./command-policy.js";import{n as c}from"./shared.js";const l=async({positionals:t,flags:r,client:a,host:o})=>{let s=await i({client:a,command:`screenshot`,positionals:t,flags:r,env:o.env});if(e(r.responseLevel))return await c(r,s,()=>JSON.stringify(s,null,2)),!0;let l={...n(s),...s.scriptDeliveryFailure?{scriptDeliveryFailure:s.scriptDeliveryFailure}:{}};return await c(r,l,()=>{let e=s.overlayRefs?`Annotated ${s.overlayRefs.length} refs onto ${s.path}`:f(s),t=s.warnings??[];return t.length>0?[e,...t].join(` `):e}),!0},u=async({positionals:e,flags:n,client:l,host:u})=>{if(e[0]===`snapshot`){let t=await i({client:l,command:`diff`,positionals:e,flags:n,env:u.env});return await c(n,t,()=>o(t,u.env,process.stdout)),!0}if(e[0]!==`screenshot`)return!1;let f=n.baseline;if(!f||typeof f!=`string`)throw new t(`INVALID_ARGS`,`diff screenshot requires --baseline <path>`);let p=r(f,{cwd:u.cwd}),h=typeof n.out==`string`?r(n.out,{cwd:u.cwd}):void 0,g=e[1];if(e.length>2)throw new t(`INVALID_ARGS`,`diff screenshot accepts at most one current screenshot path`);let[{createCommandSurfaceAgentDevice:_},{createLocalArtifactAdapter:v}]=await Promise.all([import(`./src9.js`),import(`./sdk-io.js`).then(e=>e.n)]),y=await _({backend:d(l,n),artifacts:v({cwd:u.cwd}),sessions:{get:e=>({name:e}),set:()=>{}},policy:s()}).capture.diffScreenshot({session:n.session,baseline:{kind:`path`,path:p},current:g?{kind:`path`,path:r(g,{cwd:u.cwd})}:{kind:`live`},...h?{out:{kind:`path`,path:h}}:{},threshold:m(n.threshold),overlayRefs:n.overlayRefs,normalizeStatusBar:n.screenshotNormalizeStatusBar,screenMask:n.screenshotScreenMask,surface:n.surface});return await c(n,y,()=>a(y,u,process.stdout)),!0};function d(e,t){return{platform:p(t),captureScreenshot:async(t,r,i)=>{let a=await e.capture.screenshot({path:r,session:t.session,overlayRefs:i?.overlayRefs,pixelDensity:i?.pixelDensity,fullscreen:i?.fullscreen,normalizeStatusBar:i?.normalizeStatusBar,screenMask:i?.screenMask,stabilize:i?.stabilize,surface:i?.surface});return n(a)}}}function f(e){if(typeof e.width!=`number`||typeof e.height!=`number`)return e.path;let t=typeof e.pixelDensity==`number`?` @${e.pixelDensity}x`:``;return`${e.path} (${e.width}x${e.height}${t})`}function p(e){switch(e.platform){case`android`:case`linux`:case`macos`:return e.platform;default:return`ios`}}function m(e){if(e!=null&&e!==``)return Number(e)}export{u as diffCommand,l as screenshotCommand};