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.

3 lines • 12.4 kB
import{P as e,v as t}from"./sdk-contracts.js";import{v as n}from"./host2.js";import{a as r,o as ee,r as te}from"./runner-contract.js";const i={readOnly:!1,queued:!0,readinessProbe:!1,readinessPreflightExempt:!1,readinessPreflightSkipEligibleAfterHealthyMutation:!1},a={...i,readinessPreflightExempt:!0},o={...i,readOnly:!0},s={...o,queued:!1,readinessProbe:!0},c={...o,queued:!1,readinessPreflightExempt:!0},l={...i,readinessPreflightSkipEligibleAfterHealthyMutation:!0},u={tap:l,mouseClick:i,longPress:l,drag:l,remotePress:i,type:i,swipe:l,scroll:l,desktopScroll:l,findText:o,querySelector:o,readText:o,snapshot:o,screenshot:o,backInApp:i,home:i,rotate:i,gesture:l,gestureViewport:o,appSwitcher:i,actionButton:i,volumeUp:i,volumeDown:i,keyboardDismiss:i,keyboardReturn:i,keyboardStatus:o,alert:e=>(e.action??`get`).toLowerCase()===`get`?o:i,sequence:l,recordStart:i,recordStop:i,status:s,uptime:s,appState:o,snapshotBridge:c,pasteboardWrite:i,activate:a,terminate:a,targetReset:a,shutdown:i},d={tap:`app-windows`,mouseClick:`none`,longPress:`app-windows`,drag:`app-windows`,remotePress:`none`,type:`app-windows`,swipe:`app-windows`,scroll:`app-windows`,desktopScroll:`none`,findText:`app-windows`,querySelector:`app-windows`,readText:`app-windows`,snapshot:`app-windows`,screenshot:`observed-screen`,backInApp:`app-windows`,home:`none`,rotate:`none`,gesture:`app-windows`,gestureViewport:`app-windows`,appSwitcher:`app-windows`,actionButton:`none`,volumeUp:`none`,volumeDown:`none`,keyboardDismiss:`app-windows`,keyboardReturn:`none`,keyboardStatus:`app-windows`,alert:`resolved-modal`,sequence:`app-windows`,recordStart:`observed-screen`,recordStop:`none`,status:`none`,uptime:`none`,appState:`none`,snapshotBridge:`none`,pasteboardWrite:`none`,activate:`none`,terminate:`none`,targetReset:`none`,shutdown:`none`};function f(e){return d[e.command]}function p(e){return h(e).readOnly}function ne(e){return h(e).queued}function re(e){return h(e).readinessProbe}function ie(e){return h(e).readinessPreflightExempt}function m(e){return h(e).readinessPreflightSkipEligibleAfterHealthyMutation}function h(e){let t=u[e.command];return typeof t==`function`?t(e):t}const g="If runner build products look stale or corrupted, run `pnpm clean:xcuitest` in a local checkout, or remove ~/.agent-device/apple-runner/derived, then retry.";function _(e){return{runnerConnectFailureReason:e}}const v=`runner_reply_lost`,y=e=>e.reason===v,b=e=>e.reason===r,x=e=>e.runnerErrorCode===te,S=e=>typeof e.devToolsSecurityStatus==`string`,C=e=>typeof e.simulatorSetPath==`string`,w=e=>e.usbmuxDeviceAttached===!1,T=e=>t=>t.runnerConnectFailureReason===e,ae=e=>e.reason===E||e.reason===D,oe=t=>t.runnerReadinessPreflightFailed===!0&&!e(t),E=`simulator_service_hub_unavailable`,D=`simulator_set_destination_not_found`,O=[`dtservicehubclient`,`failed to bless service hub`],k=`build_failed_unclassified`,A={reason:`signing_provisioning_profile_missing`,hint:`Install/select a valid iOS provisioning profile, or set AGENT_DEVICE_IOS_PROVISIONING_PROFILE.`},j=[{reason:v,match:{code:`COMMAND_FAILED`,details:y},verdicts:{retryable:!1,drainResend:!1,connectRetry:!1,restartBeforeSend:!1,restartAfterReadinessPreflight:!1}},{reason:r,match:{code:`COMMAND_FAILED`,details:b},verdicts:{retryable:!1,drainResend:!1,connectRetry:!1,sessionFatalReason:r,restartBeforeSend:!1,restartAfterReadinessPreflight:!1,artifactSuspect:!1}},{reason:`usbmux_device_unattached`,match:{code:`DEVICE_NOT_FOUND`,details:w},verdicts:{connectRetry:!1}},{reason:`runner_busy_refusal`,match:{code:`COMMAND_FAILED`,details:x},verdicts:{retryable:!0,connectRetry:!0,drainResend:!0}},{reason:`xcodebuild_exited_early`,match:{code:`COMMAND_FAILED`,details:T(`xcodebuild_exited_early`)},verdicts:{retryable:!1,connectRetry:!1,artifactSuspect:!1}},{reason:`runner_session_terminal`,match:{code:`COMMAND_FAILED`,details:e=>T(`runner_session_draining`)(e)||T(`runner_session_stopped`)(e)},verdicts:{retryable:!1,connectRetry:!1,artifactSuspect:!1,restartBeforeSend:!1}},{reason:`runner_launch_log_cause`,match:{code:`COMMAND_FAILED`,details:ae},verdicts:{retryable:!1,connectRetry:!1,restartBeforeSend:!1,restartAfterReadinessPreflight:!1,artifactSuspect:!1}},{reason:`device_busy_connecting`,match:{code:`COMMAND_FAILED`,foreignMessageIncludesAll:[`device is busy`,`connecting`]},verdicts:{retryable:!1,connectRetry:!1}},{reason:`runner_forwarding_unavailable`,match:{code:`COMMAND_FAILED`,details:e=>e.reason===`runner_forwarding_unavailable`},verdicts:{retryable:!0,retainSession:!0,postSendRecovery:!1,connectRetry:!0,restartBeforeSend:!1,restartAfterReadinessPreflight:!1,artifactSuspect:!1}},{reason:`runner_readiness_preflight_failed`,match:{code:`COMMAND_FAILED`,details:oe},verdicts:{restartAfterReadinessPreflight:!0}},{reason:`runner_connect_refused`,match:{code:`COMMAND_FAILED`,details:T(`runner_connect_refused`)},verdicts:{retryable:!0,connectRetry:!0,restartBeforeSend:!0,artifactSuspect:!0}},{reason:`runner_endpoint_probe_exhausted`,match:{code:`COMMAND_FAILED`,details:T(`runner_endpoint_probe_exhausted`)},verdicts:{artifactSuspect:!0}},{reason:`fetch_failed`,match:{code:`COMMAND_FAILED`,foreignMessageIncludesAll:[`fetch failed`]},verdicts:{retryable:!0,connectRetry:!0}},{reason:`econnrefused`,match:{code:`COMMAND_FAILED`,foreignMessageIncludesAll:[`econnrefused`]},verdicts:{retryable:!0,connectRetry:!0}},{reason:`socket_hang_up`,match:{code:`COMMAND_FAILED`,foreignMessageIncludesAll:[`socket hang up`]},verdicts:{retryable:!0,connectRetry:!0}},{reason:`ax_snapshot_failure`,match:{code:`IOS_AX_SNAPSHOT_FAILED`},verdicts:{sessionFatalReason:`ax_snapshot_failure`}},{reason:`xctest_recorded_failure`,match:{code:`XCTEST_RECORDED_FAILURE`},verdicts:{sessionFatalReason:`xctest_recorded_failure`}},{reason:`runner_main_thread_wedged`,match:{code:ee},verdicts:{sessionFatalReason:`runner_main_thread_wedged`}},{reason:`simulator_set_destination_not_found`,match:{toolTextIncludesAll:[`matching the provided destination specifier`],details:C},verdicts:{},buildFailure:{reason:`simulator_set_destination_not_found`,hint:"Check that the simulator still exists in the --ios-simulator-device-set this error names (`xcrun simctl --set <set> list devices`). If it does, the Xcode this error names no longer honors -DVTSimulatorSetLocation, so use a simulator in the default set.",messageSuffix:e=>typeof e.simulatorSetPath==`string`&&typeof e.simulatorUdid==`string`?`xcodebuild found no simulator ${e.simulatorUdid} in simulator set ${e.simulatorSetPath}${typeof e.xcodeVersion==`string`?` with Xcode ${e.xcodeVersion}`:``}`:void 0}},{reason:`simulator_service_hub_bless_refused`,match:{toolTextLineIncludesAll:O,toolTextIncludesAll:[`dtservicehubclient code=1 "`,`localdeviceconnectionwitherror:`]},verdicts:{},buildFailure:{reason:E,hint:"This Xcode cannot start its simulator service on this macOS: macOS refuses to load its DTServiceHub. Select an Xcode that supports this macOS on the daemon host (`xcode-select -s /Applications/Xcode.app`, or DEVELOPER_DIR=/Applications/Xcode.app for the daemon process), then retry. Updating Xcode is the fix; restarting the runner or clearing derived data cannot change it.",messageSuffix:()=>`this Xcode cannot start its simulator service on this macOS`}},{reason:`bundle_identifier_registration_failed`,match:{toolTextIncludesAll:[`failed registering bundle identifier`]},verdicts:{},buildFailure:{reason:`bundle_identifier_already_registered`,hint:`Set AGENT_DEVICE_IOS_BUNDLE_ID to a unique reverse-DNS value (for example, com.yourname.agentdevice.runner), then retry.`}},{reason:`bundle_identifier_unavailable`,match:{toolTextLineIncludesAll:[`app identifier`,`not available`]},verdicts:{},buildFailure:{reason:`bundle_identifier_already_registered`,hint:`Set AGENT_DEVICE_IOS_BUNDLE_ID to a unique reverse-DNS value (for example, com.yourname.agentdevice.runner), then retry.`}},{reason:`signing_requires_development_team`,match:{toolTextIncludesAll:[`requires a development team`]},verdicts:{},buildFailure:{reason:`signing_no_development_team`,hint:`Configure signing in Xcode or set AGENT_DEVICE_IOS_TEAM_ID for physical-device runs.`}},{reason:`conflicting_provisioning_settings_unproven`,match:{toolTextIncludesAll:[`conflicting provisioning settings`]},verdicts:{},buildFailure:{reason:k,hint:g}},{reason:`signing_no_profiles_for_bundle_id`,match:{toolTextIncludesAll:[`no profiles for`]},verdicts:{},buildFailure:A},{reason:`signing_provisioning_profile_xcode_error`,match:{toolTextLineIncludesAll:[`provisioning profile`,`ideprovisioningerrordomain`]},verdicts:{},buildFailure:A},{reason:`signing_provisioning_profile_does_not_cover`,match:{toolTextLineIncludesAll:[`provisioning profile`,`doesn't include`]},verdicts:{},buildFailure:A},{reason:`signing_provisioning_profile_expired`,match:{toolTextLineIncludesAll:[`provisioning profile`,`has expired`]},verdicts:{},buildFailure:A},{reason:`signing_unspecified`,match:{toolTextIncludesAll:[`code signing`]},verdicts:{},buildFailure:{reason:`signing_unspecified`,hint:`Enable Automatic Signing in Xcode or provide AGENT_DEVICE_IOS_TEAM_ID and optional AGENT_DEVICE_IOS_SIGNING_IDENTITY.`}},{reason:`devtools_security_refused`,match:{code:`COMMAND_FAILED`,details:S},verdicts:{},buildFailure:{reason:`devtools_security_developer_mode_disabled`,hint:"Run `sudo DevToolsSecurity -enable`, then retry the iOS runner. UI test runners start suspended until Xcode/testmanagerd can attach."}}];function M(e,t){return t.code!==void 0&&e.code!==t.code||!N(e,t.details)||!I(e,t.toolTextIncludesAll)||!L(e,t.toolTextLineIncludesAll)?!1:P(e,t.foreignMessageIncludesAll)}function N(e,t){return t===void 0||t(e.details??{})}function P(e,t){if(!t)return!0;let n=`${e.message??``}`.toLowerCase();return t.every(e=>n.includes(e))}function F(e){let t=e.details??{};return[e.message,t.stdout,t.stderr].filter(e=>typeof e==`string`).join(` `).toLowerCase()}function I(e,t){if(!t)return!0;let n=F(e);return t.every(e=>n.includes(e))}function L(e,t){return!t||F(e).split(` `).some(e=>t.every(t=>e.includes(t)))}function R(e,n){if(e instanceof t){for(let t of j)if(t.verdicts[n]!==void 0&&M(e,t.match))return t.verdicts[n]}}function z(e){return!(e instanceof t)||e.code!==`COMMAND_FAILED`?!1:R(e,`retryable`)??!1}function B(e){return R(e,`retainSession`)??!1}function se(e){return R(e,`postSendRecovery`)??!0}function V(e){return U(e)||H(e)?`occupied`:!W(e)||e.details?.runnerErrorCode===`COMMAND_ALREADY_FINISHED`?`silent`:`drained`}function H(e){return e instanceof t&&e.details?.runnerErrorCode===`MAIN_THREAD_TIMEOUT`}function U(e){return R(e,`drainResend`)??!1}function W(e){return e instanceof t&&e.details?.runner!==void 0}function G(e){return!(e instanceof t)||e.code!==`DEVICE_NOT_FOUND`?!1:w(e.details??{})}function K(e){return R(e,`connectRetry`)??!0}function q(e){return R(e,`restartAfterReadinessPreflight`)??!1}function ce(e){return R(e,`artifactSuspect`)??!1}function le(e){return R(e,`sessionFatalReason`)}function ue(e,t){return J(e)?Z(e)===`no`||p(t):!1}function J(e){return R(e,`restartBeforeSend`)??!1}function Y(e){return J(e)&&X(e)||q(e)||U(e)}function X(e){return e instanceof t&&e.details?.dispatched===`no`||Q(e,0)}function Z(e){return X(e)?`no`:`unknown`}function Q(e,t){return t>4||typeof e!=`object`||!e?!1:e.code===`ECONNREFUSED`?!0:e instanceof AggregateError&&e.errors.length>0?e.errors.every(e=>Q(e,t+1)):Q(e.cause,t+1)}function $(e){if(e instanceof t)for(let t of j){let n=t.buildFailure;if(n&&M(e,t.match))return{reason:n.reason,hint:n.hint,messageSuffix:n.messageSuffix?.(e.details??{}),matched:!0}}return{reason:k,hint:g,matched:!1}}function de(e,n){if(!n||!(e instanceof t))return e;let r=fe(e)===void 0&&n.developerDiskImage===`unavailable`&&!me(e)&&!pe(e);return new t(e.code,e.message,{...e.details??{},...r?{reason:`device_developer_disk_image_unavailable`,hint:n.developerDiskImageHint}:{},developerDiskImage:n.developerDiskImage},e.cause)}function fe(e){let t=e.details?.reason;if(typeof t==`string`&&t!==`build_failed_unclassified`)return t}function pe(e){let t=e.details?.startupHostDeadlineHit;return typeof t==`boolean`?t:n(e)}function me(e){let t=e.details?.startupRuleMatched;return typeof t==`boolean`?t:$(e).matched}export{ne as C,f as D,re as E,m as S,ie as T,se as _,z as a,B as b,H as c,G as d,Z as f,ce as g,V as h,de as i,Y as l,_ as m,v as n,U as o,le as p,$ as r,X as s,g as t,W as u,q as v,p as w,K as x,ue as y};