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.49 kB
JavaScript
import{v as e}from"./sdk-contracts.js";import{T as t,w as n}from"./sdk-device.js";let r;const i=()=>r??=import(`./runner-operations-facade.js`).then(e=>e.t);let a;const o=()=>a??=import(`./platform-runtime-runtime-hints.js`);let s;const c=()=>s??=import(`./platform-runtime-open-target.js`);let l;const u=()=>l??=import(`./app-resolution-facade.js`);let d;const f=()=>d??=import(`./macos-facade.js`);let p;const m=()=>p??=import(`./retry.js`).then(e=>e.t);function h(e){return Object.freeze({resolveOpenTarget:async(t,n)=>await g(t,n,e),prewarmRunnerCache:async(e,t,n)=>{let{prewarmAppleRunnerCache:r}=await i();await r(e,y(t,n))},prewarmRunnerSession:async(e,t,n,r,a)=>{let{prewarmIosRunnerSession:o}=await i();await o(e,{...y(t,n),propagateError:r,...a})},notifyRunnerAppRelaunched:async(e,t,n)=>{let{notifyIosRunnerAppRelaunched:r}=await i();await r(e,y(t,n))},stopRunnerSession:async e=>{let{stopIosRunnerSession:t}=await i();await t(e)},hasLiveRunnerSession:async(e,t)=>{let{hasLiveIosRunnerSession:n}=await i();return n(e,{requestId:t.requestId})},releaseSpeculativeRunner:async(e,t)=>{let{releaseSpeculativeIosRunnerSessionFor:n}=await i();return await n(e,{requestId:t.requestId})},releaseRunnerOnClose:async(e,t)=>{let{releaseIosRunnerOnClose:n}=await i();await n(e,t)},prepareRunner:async(e,t,n)=>{let{Deadline:r}=await m(),{prepareIosRunner:a}=await i(),o=Date.now();return await a(e,{...y(t.execution,n),cleanStaleBundles:!0,buildTimeoutMs:t.timeoutMs,healthTimeoutMs:t.timeoutMs,prepareDeadline:r.fromTimeoutMs(t.timeoutMs,o),startupTimeoutMs:t.timeoutMs})},applyRuntimeHints:async(e,t)=>{let{applyRuntimeHintValues:n}=await o();await n({device:e,...t})},clearRuntimeHints:async(e,t)=>{let{clearRuntimeHintValues:n}=await o();await n({device:e,...t})},dismissCloseAlerts:async(t,n)=>await b(t,n,e),detachRunnerSessionsForShutdown:async()=>{let{detachIosRunnerSessionsForShutdown:e}=await i();return await e()},finalizeRunnerSessionsForShutdown:async()=>{let{stopAllIosRunnerSessions:e}=await i();return await e()}})}async function g(t,n,r){if(n.foreground){let n=await _(t);if(n)return n;throw new e(`AMBIGUOUS_MATCH`,`open --foreground requires exactly one running app on the selected iOS simulator.`,{reason:`foreground_app_ambiguous`,hint:`Pass an explicit app instead: agent-device open <app> --platform ios.`})}if(t.hostApp){let{resolveMacOsAppDeviceOpenTarget:e}=await u();return await e(t,n.target)}let i=await v(t,n.surface,r),{resolveSessionAppBundleIdForTarget:a}=await c();return{appBundleId:i.appBundleId??await a(t,n.target,n.currentAppBundleId),appName:i.appName??n.target}}async function _(e){if(!n(e)||e.kind!==`simulator`)return;let{detectSoleRunningIosSimulatorApp:t}=await u(),r=await t(e);return r?{appBundleId:r.bundleId,appName:r.name}:void 0}async function v(e,n,r){if(!t(e)||n===`app`||n===`desktop`||n===`menubar`)return{};let{resolveFrontmostMacOsApp:i}=await f(),a=await i(r);return{appBundleId:a.bundleId,appName:a.appName}}function y(e,t){return{requestId:e.requestId,logPath:e.logPath,traceLogPath:e.traceLogPath,verbose:e.verbose,iosXctestrunFile:e.iosXctestrunFile,iosXctestDerivedDataPath:e.iosXctestDerivedDataPath,iosXctestEnvDir:e.iosXctestEnvDir,runnerLeaseContext:e.runnerLeaseContext,signal:t}}async function b(e,n,r){if(!t(e))return;let{runMacOsAlertAction:i}=await f();await i(`dismiss`,{...n.surface===`frontmost-app`?{surface:`frontmost-app`}:n.appBundleId?{bundleId:n.appBundleId}:{},env:r})}export{h as createAppleApplicationTools};