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.3 kB
JavaScript
import{v as e}from"./sdk-contracts.js";import{St as t}from"./sdk-io.js";import"./diagnostics.js";import{t as n}from"./ttl-memo.js";import"./config.js";import{d as r}from"./simctl.js";import{a as i,i as a,o,s}from"./display-inventory.js";import{n as c}from"./fold-helper.js";import{t as l}from"./runtime6.js";const u=n({ttlMs:5e3});let d=0;const f=new Map;function p(e,t){u.delete(e.id),f.set(e.id,Math.max(t,f.get(e.id)??0))}async function m(e,t){if(!l(e).setFoldPose.available)return!1;let n=i(e);if(n!==void 0)return n;let r=++d,a=await s(e,{signal:t});return!a.unresolved&&(p(e,r),a.multiScreen)}async function h(e,t){if(!l(e).setFoldPose.available)return{kind:`single-panel`};let n=i(e);if(n===!1||n===void 0&&u.get(e.id))return{kind:`single-panel`};let r=++d,a=await s(e,t);if(a.unresolved){if(n)return{kind:`unreadable`};let i=(f.get(e.id)??0)>r;return t.timeoutMs>=5e3&&!t.signal?.aborted&&!i&&u.set(e.id,!0),{kind:`single-panel`}}return p(e,r),a.multiScreen?{kind:`multi-panel`,inventory:a}:{kind:`single-panel`}}const g={outer:{portrait:`portrait`,"landscape-left":`landscape-left`,"landscape-right":`landscape-right`},inner:{portrait:`landscape-left`,"landscape-left":`portrait-upside-down`,"landscape-right":`portrait`}};async function _(n,i,a={}){let{signal:o}=a;if(i===`portrait-upside-down`)throw new e(`UNSUPPORTED_OPERATION`,`${n.name} cannot rotate to ${i}`,{deviceId:n.id,requestedOrientation:i,reason:`unsupported-foldable-orientation`,hint:`A foldable simulator accepts portrait, landscape-left, and landscape-right as rotation targets.`});let s=c(n),l,u;for(let e=1;e<=6;e+=1){if(o?.throwIfAborted(),u=await y(n,s,{signal:o}),u?.rotation===i)return{orientation:i};if(u&&u.panel.displayId!==l){let a=(u.panel.primary?g.outer:g.inner)[i];await s.rotate(a,o),l=u.panel.displayId,t({level:`info`,phase:`apple_foldable_orientation_dispatched`,data:{deviceId:n.id,orientation:a,requestedOrientation:i,scopedSet:!!r(n).simulatorSetPath,attempt:e,observedOrientation:u.rotation,litDisplay:u.panel.name}})}await b()}if(u=await y(n,s,{signal:o,requireTable:!0}),u?.rotation===i)return{orientation:i};throw v(n,i,u)}function v(t,n,r){return new e(`COMMAND_FAILED`,`${t.name} did not confirm rotation to ${n}: ${r?`the lit panel shows ${r.rotation}`:`the last panel table read named no single lit panel`}`,{deviceId:t.id,requestedOrientation:n,...r?{observedOrientation:r.rotation,rawPanelOrientation:r.panel.currentOrientation}:{},reason:`orientation-unverified`,hint:`The lit panel did not show the requested orientation, or the simulator never reported a single lit panel; the app in front may not support that orientation. Take a screenshot to see the screen, then retry.`})}async function y(t,n,r){let i=await s(t,{signal:r.signal,source:`guest`,foldHelper:n});if(i.unresolved&&r.requireTable)throw new e(`COMMAND_FAILED`,`The guest panel table could not be read`,{deviceId:t.id,reason:`orientation-panel-table-unavailable`,hint:`The fold helper could not provide a usable display table. Check the apple_display_inventory_unresolved diagnostic for the helper or display-table failure, then retry.`});let c=a(i);if(!c)return;let l=o(c.currentOrientation);return l===void 0?void 0:{panel:c,rotation:l}}async function b(){await new Promise(e=>{setTimeout(e,600)})}export{h as n,_ as r,m as t};