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.

2 lines • 5.65 kB
import{r as e}from"./rolldown-runtime.js";import{O as t,v as n}from"./sdk-contracts.js";import{Q as r,Z as i}from"./sdk-io.js";import"./command.js";var a=e({androidAdbResultError:()=>g,androidDiscoveryCommandError:()=>v,attachAdbFailureHint:()=>p,attachAndroidDiscoveryTimeout:()=>y,attachAndroidHelperInstallTimeoutHint:()=>m,classifyAndroidAdbFailure:()=>f,discloseAdbInputDispatch:()=>b,isAdbHostRefusal:()=>x,withAdbFailureHints:()=>_});const o=String.raw`(?:adb|error): `;function s(e){return RegExp(`^${o}${e}$`)}const c=[[/device unauthorized|device still authorizing/,{reason:`device_unauthorized`,hint:`USB debugging is not authorized — accept the authorization prompt on the device screen (re-plug the cable if none appears), then retry.`},{hostRefusal:s(String.raw`device (?:unauthorized|still authorizing)\.?`)}],[/device offline/,{reason:`device_offline`,hint:`The device is connected but offline — wait for it to finish booting or run adb reconnect, then retry.`,retriable:!0},{hostRefusal:s(String.raw`device (?:'[^']*' )?offline`)}],[/more than one (?:device\/emulator|device and emulator)/,{reason:`multiple_devices`,hint:`Multiple Android devices are connected — pass --serial <serial> (see adb devices) to select one.`},{hostRefusal:s(String.raw`more than one (?:device/emulator|device and emulator)`)}],[/no devices\/emulators found|no devices found/,{reason:`no_devices`,hint:`No Android devices detected — boot an emulator or connect a device and verify it appears in adb devices.`},{hostRefusal:s(String.raw`no devices(?:/emulators)? found`)}],[/device (?:'[^']*' )?not found/,{reason:`device_not_found`,hint:`The device disconnected or is restarting — verify it is listed in adb devices, then retry.`,retriable:!0},{hostRefusal:s(String.raw`device (?:'[^']*' )?not found`)}],[/adb server version \(\d+\) doesn't match this client/,{reason:`server_version_mismatch`,hint:`Multiple adb installs conflict — adb restarts its server automatically, so retry; align PATH to a single adb to stop recurrences.`,retriable:!0}],[/transport error|connection reset|broken pipe|protocol fault/,{reason:`connection_dropped`,hint:`The adb connection dropped — retry; if it persists, run adb kill-server and reconnect the device.`,retriable:!0}],[/install_failed_insufficient_storage/,{reason:`install_insufficient_storage`,hint:`The device is out of storage — free up space or uninstall unused apps, then retry the install.`},{matchStdout:!0}],[/install_failed_update_incompatible/,{reason:`install_update_incompatible`,hint:`The installed app has an incompatible signature — uninstall the existing app first, then retry the install.`},{matchStdout:!0}],[/install_failed_version_downgrade/,{reason:`install_version_downgrade`,hint:`The APK is older than the installed app — uninstall the app first (or install with downgrade allowed), then retry.`},{matchStdout:!0}],[/install_failed_\w+|install_parse_failed_\w+/,{reason:`install_failed`,hint:`The Android package installer rejected the APK — see the INSTALL_FAILED code in the error output for the exact cause.`},{matchStdout:!0}]],l=Object.freeze({reason:`timeout`,hint:`adb timed out — the adb server may be wedged. Run adb kill-server && adb start-server, check adb devices, then retry.`}),u=/^(?:this adb server's \$adb_vendor_keys is not set|try 'adb kill-server' if that seems wrong\.|(?:otherwise|please) check (?:for|the) (?:a )?confirmation dialog on your device\.)$/;function d(e,t){if(t!==``)return;let[n,...r]=e.split(` `).map(e=>e.trim()).filter(e=>e!==``);if(n===void 0||!r.every(e=>u.test(e)))return;let i=c.find(([,,e])=>e?.hostRefusal?.test(n));return i&&{...i[1],hostRefusal:!0}}function f(e,t=``){let n=e.toLowerCase(),r=t.toLowerCase(),i=d(n,r);if(i)return i;for(let[e,t,i]of c)if(e.test(n)||i?.matchStdout&&e.test(r))return t}function p(e){if(!(e instanceof n)||e.code!==`COMMAND_FAILED`)return e;let t=h(e);return t&&(e.details={...e.details,adbFailure:t.reason,...t.hostRefusal?{adbHostRefusal:!0}:{},...typeof e.details?.hint==`string`?{}:{hint:t.hint},...t.retriable!==void 0&&e.details?.retriable===void 0?{retriable:t.retriable}:{}}),e}function m(e){if(!r(e))return e;let t=e.details?.hint;if(typeof t==`string`&&t!==l.hint)return e;let n=p(e);return n.details={...n.details,hint:`The helper install timed out — some OEM builds (ColorOS is one) hold the first install of each package behind a system install-confirmation dialog and adb waits for it. Check the device screen, confirm any pending install prompt, then retry; if none is showing, run adb kill-server && adb start-server and retry.`},n}function h(e){return typeof e.details?.timeoutMs==`number`?l:f(typeof e.details?.stderr==`string`?e.details.stderr:``,typeof e.details?.stdout==`string`?e.details.stdout:``)}function g(e,t,r){let i=t.exitCode===0?{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode,...r}:{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode,processExitError:!0,...r};return p(new n(`COMMAND_FAILED`,e,i))}function _(e){return async(...t)=>{try{return await e(...t)}catch(e){throw p(e)}}}function v(e,t,r){let a=f(t.stderr,t.stdout),o=i(t);return new n(`COMMAND_FAILED`,e,{...o,hint:a?.hint??(typeof o.hint==`string`?o.hint:r),...a?{adbFailure:a.reason}:{},...a?.retriable===void 0?{}:{retriable:a.retriable}})}function y(e){return r(e)&&(e.details={...e.details,adbFailure:l.reason,...typeof e.details?.hint==`string`?{}:{hint:l.hint}}),e}function b(e){return e instanceof n?t(e,e.code===`TOOL_MISSING`||x(e)?`no`:`unknown`):e}function x(e){return e.details?.adbHostRefusal===!0}export{y as a,b as c,p as i,x as l,g as n,m as o,v as r,f as s,a as t,_ as u};