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 • 3.88 kB
JavaScript
import{r as e}from"./rolldown-runtime.js";import{v as t}from"./sdk-contracts.js";import{Q as n,Z as r}from"./sdk-io.js";import{r as i}from"./version.js";import"./command.js";import{f as a}from"./host-file.js";import{u as o}from"./config.js";import{s}from"./tool-provider.js";import{t as c}from"./simctl-execution.js";import{i as l,n as u,t as d}from"./host3.js";import{a as f,i as p,n as m,r as h,t as g}from"./cache.js";import _ from"node:path";const v=`Fold.m`,y=3e4,b=p+y;async function x(e={}){let t=e.host??S(),n=u(b,e.signal);try{let r=e.sourceRoot??_.join(i(),`apple`,`fold-helper`),o=await h(t,r,[v],n),s=await f(t,n),c=e.cacheRoot??_.join(a(),`.agent-device`,`fold-helper`);return await g({host:t,deadline:n,lockDescription:`iOS Simulator fold helper cache`,cacheRoot:c,binaryFilename:`fold-helper`,keyInputs:{schemaVersion:1,sourceHash:o,toolchain:s,compileArgv:C({sourceRoot:``,outputPath:``})},build:e=>w(t,n,r,e)})}catch(e){throw T(e)}}function S(){return d(s)}function C(e){return[`--sdk`,`iphonesimulator`,`clang`,`-mios-simulator-version-min=15.0`,`-fobjc-arc`,`-Wall`,`-Wextra`,`-framework`,`Foundation`,`-framework`,`IOKit`,_.join(e.sourceRoot,v),`-o`,e.outputPath]}async function w(e,t,n,i){let a=await m({host:e,deadline:t,argv:C({sourceRoot:n,outputPath:i}),budgetMs:y,label:`fold helper`});if(a.exitCode!==0||!e.exists(i))throw E(r(a))}function T(e){return!(e instanceof l)||e.buildFailureKind===`cancelled`?e:E({...e.buildDetails,cause:e.buildFailureCode},e)}function E(e,n){return new t(`COMMAND_FAILED`,`Unable to build the simulator fold helper`,{hint:`Select an Xcode with the iOS simulator SDK and foldable HID support using DEVELOPER_DIR.`,...e,reason:`fold-helper-build-failed`},n)}var D=e({HINGE_ANGLE_NO_SAMPLE_REASON:()=>O,createFoldHelper:()=>k,parseHingeReading:()=>F});const O=`fold-hinge-angle-no-sample`;function k(e){let i,a=async(a,o,s)=>{let{signal:l,timeoutMs:u,failure:d}=o;l?.throwIfAborted();let{path:f}=await(i??=x({signal:l}));l?.throwIfAborted();let p;try{p=await c(e,[`spawn`,e.id,f,...a],{signal:l,timeoutMs:u,kill:{signal:`SIGTERM`,graceMs:1e3},allowFailure:!0})}catch(r){throw l?.aborted||!n(r)?r:new t(`COMMAND_FAILED`,d.message,{...r.details,deviceId:e.id,...d.details},r)}let m=p.exitCode===0?s(p.stdout):void 0;if(m!==void 0)return m;throw new t(`COMMAND_FAILED`,d.message,r(p,{deviceId:e.id,...d.details}))};return Object.freeze({async setPose(e,t){let n=typeof e==`string`?0:e.at(-1).atMs,r=typeof e==`string`?e:JSON.stringify(e);await a([`set`,r],{signal:t,timeoutMs:n+1e4,failure:A},()=>!0)},async rotate(e,t){await a([`rotate`,e],{signal:t,timeoutMs:5e3,failure:j},()=>!0)},async readHingeAngle({signal:e,windowMs:t=0}={}){return await a([`hinge`,String(t)],{signal:e,timeoutMs:o+t,failure:M},F)},async readPanelPayload({signal:e,timeoutMs:t}){return await a([`panels`],{signal:e,timeoutMs:t,failure:N},e=>{let t=P(e)?.displays;return Array.isArray(t)?{result:{displays:t}}:void 0})}})}const A={message:`Unable to send the simulator hinge pose`,details:{reason:`fold-hid-dispatch-failed`}},j={message:`Unable to send the simulator orientation`,details:{reason:`orientation-hid-dispatch-failed`}},M={message:`The simulator reported no hinge angle sample`,details:{reason:O,hint:`The fold helper's hinge read returned no valid CoreMotion sample. The details name the cause: stderr such as a simulator runtime without CMAngleManager, or timeoutMs when the read did not finish.`}},N={message:`The simulator reported no panel table`,details:{reason:`fold-helper-panels-unreadable`}};function P(e){let t=e.trim().split(`
`).at(-1);if(!t)return;let n;try{n=JSON.parse(t)}catch{return}if(typeof n!=`object`||!n)return;let r=n;return r.version===1?r:void 0}function F(e){let t=P(e);if(!t||t.angleValid!==!0)return;let n=t.angleDegrees;if(!(typeof n!=`number`||!Number.isFinite(n)||n<0||n>180))return n}export{k as n,D as r,O as t};