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 • 3.82 kB
import{B as e,p as t,s as n}from"./sdk-contracts.js";import{A as r}from"./sdk-batch-runner.js";import{r as i}from"./success-text.js";import{n as a}from"./catalog.js";import{o}from"./snapshot-runtime-capture-input.js";import{n as s}from"./touch-reference-frame.js";import{t as c}from"./snapshot-quality-verdict.js";import{t as l}from"./react-native-overlay2.js";import{o as u,u as d}from"./interaction-ref-policy.js";import{captureSnapshotForSession as f}from"./interaction.js";import{n as p,t as m}from"./touch-runtime2.js";async function h(r){r=d(r);let{req:i,sessionStore:o}=r;if(i.command!==a.reactNative)return null;let s=g(i.positionals??[]);if(!s.ok)return s.response;let u=r.sessionRef?o.requireCurrent(r.sessionRef):void 0;if(!u)return t();let m=await p({device:u.device,command:`press`,requiresCapture:!1,inspectFacts:r.inspectFacts,platformServices:r.platformServices,bindDevice:r.bindDevice,unavailableResponse:e=>n(`UNSUPPORTED_OPERATION`,`react-native dismiss-overlay is not supported on this device`,void 0,e.hint?{hint:e.hint}:void 0)});if(!m.ok)return m.response;try{let e=await f(r.sessionRef,i.flags,o,r.contextFromFlags,{interactiveOnly:!0});if(c(e.snapshotQuality))return v(e.snapshotQuality);let t=l(e.nodes),n=t.primaryAction;return n?await y(r,u,e,n,m.runtime):_(t.detected)}catch(t){return{ok:!1,error:e(t)}}}function g(e){return e.length===1&&e[0]===`dismiss-overlay`?{ok:!0}:{ok:!1,response:n(`INVALID_ARGS`,`react-native supports only: dismiss-overlay`)}}function _(e){return e?n(`COMMAND_FAILED`,`React Native overlay detected, but no safe dismiss target was found`,{hint:`Use screenshot --overlay-refs for visual evidence and report the overlay instead of pressing the warning body.`}):{ok:!0,data:{action:`dismiss-overlay`,detected:!1,dismissed:!1,...i(`No React Native overlay detected`)}}}function v(e){return n(`COMMAND_FAILED`,`React Native overlay state could not be determined because the accessibility tree is unreadable`,{reason:e.reason,hint:`The snapshot quality verdict is sparse. Use screenshot as visual truth; if an overlay is visible, report it or navigate with coordinates, then retry snapshot or dismiss-overlay on a readable screen.`})}async function y(e,t,a,c,l){let{req:d,sessionStore:f}=e,p=e.contextFromFlags(d.flags,t.appBundleId,t.trace?.outPath),h=m(l,p).tapPoint;if(!h)return n(`UNSUPPORTED_OPERATION`,`react-native dismiss-overlay is not supported on this device`);let g=Date.now();o(t);let _=await h(c.point),v=Date.now(),y=await b(e),S=r({...s(a.nodes),..._,action:`dismiss-overlay`,overlayAction:c.action,x:c.point.x,y:c.point.y,ref:c.ref,label:c.label,warning:c.warning,dismissed:!0,verified:y.verified,verificationRequired:!y.verified,verificationWarning:y.verificationWarning,nextCommand:y.nextCommand,...i(x(y))});return u({ref:e.sessionRef,sessionStore:f,command:d.command,positionals:d.positionals??[],flags:d.flags,result:S,responseData:S,actionStartedAt:g,actionFinishedAt:v})}async function b(e){let{req:t,sessionStore:n}=e,r=await f(e.sessionRef,t.flags,n,e.contextFromFlags,{interactiveOnly:!0});return c(r.snapshotQuality)?{verified:!1,verificationWarning:`React Native overlay dismissal could not be verified because the post-dismiss accessibility tree is unreadable. Use screenshot as visual truth.`,nextCommand:`agent-device screenshot`}:l(r.nodes).detected?{verified:!1,verificationWarning:`React Native overlay is still detected after dismissal. Use screenshot --overlay-refs for visual evidence and report the overlay instead of pressing the warning body.`,nextCommand:`agent-device screenshot --overlay-refs`}:{verified:!0}}function x(e){return e.verified?`React Native overlay dismiss action sent and verified gone`:`React Native overlay dismiss action sent, but verification still detects an overlay`}export{h as handleReactNativeCommands};