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.

1 lines • 5.27 kB
import{jn as e}from"./sdk-batch.js";import{v as t}from"./sdk-contracts.js";import{R as n}from"./sdk-device.js";const r={support:`supported`},i={support:`unsupported`},a={support:`partial`,note:`Uses provider/Appium mobile pressKey support where available.`},o={lease:r,inventory:{support:`partial`,note:`Inventory exposes only the leased cloud device, not the provider catalog.`},install:{support:`partial`,note:`Requires provider-specific upload or a path visible to the remote Appium server.`},snapshot:{support:`partial`,note:`Uses Appium page source XML, not agent-device native snapshot backends.`},screenshot:r,tap:r,doubleTap:r,longPress:r,swipe:r,scroll:{support:`partial`,note:`Implemented as viewport-relative W3C pointer gestures.`},fill:r,type:r,keyboard:{support:`partial`,note:"Enter presses Android keycode 66 through `mobile: pressKey` and types a newline into the focused iOS field; dismiss uses the Appium hide-keyboard route, and Android status uses the Appium keyboard probe."},back:r,home:{support:`partial`,note:"Presses the XCUITest `mobile: pressButton` home button on iOS and KEYCODE_HOME through `mobile: pressKey` on Android."},orientation:{support:`partial`,note:`Uses the WebDriver rotation/orientation endpoints; four-way rotation collapses to portrait/landscape on drivers that only accept the two-way endpoint. Rotates the current display, so an activity that does not pin its orientation may need rotating again once it is foreground.`},appSwitcher:{support:`unsupported`,note:"XCUITest `mobile: pressButton` has no app-switcher button."},volumeUp:{support:`partial`,note:`Uses provider/Appium mobile pressButton volumeup support where available; real devices only.`},volumeDown:{support:`partial`,note:`Uses provider/Appium mobile pressButton volumedown support where available; real devices only.`},power:i,mute:i,sleep:i,wake:i,mediaPlayPause:i,mediaNext:i,mediaPrevious:i,mediaRewind:i,mediaFastForward:i,tvRemote:i,"clipboard.read":{support:`partial`,note:`Uses provider/Appium clipboard extension support where available.`},"clipboard.write":{support:`partial`,note:`Uses provider/Appium clipboard extension support where available.`},settings:i,alert:i,pinch:i,rotateGesture:i,transformGesture:i,tapGesture:i,logs:i,record:i,artifacts:i,portReverse:i,nativeSnapshotBackend:{support:`unsupported`,note:`Cloud WebDriver cannot upload or run agent-device native runner/helper backends.`}};function s(e){let t=e.platform===`android`?{...o,appSwitcher:{support:`partial`,note:"Presses KEYCODE_APP_SWITCH through `mobile: pressKey`."},volumeUp:a,volumeDown:a,power:a,mute:a,sleep:a,wake:a,mediaPlayPause:a,mediaNext:a,mediaPrevious:a,mediaRewind:a,mediaFastForward:a}:o;return{provider:e.provider,platform:e.platform,snapshotBackend:e.platform===`ios`?`xctest`:`android`,snapshotSource:`appium-page-source`,operations:u(t,e.overrides)}}function c(e,t){return e.operations[t].support!==`unsupported`}function l(e,t){let n=e.operations[t],r=n.note?` ${n.note}`:``;return`${e.provider} WebDriver runtime does not support ${t}.${r}`}function u(e,t){let n={...e};for(let[r,i]of Object.entries(t??{}))n[r]=typeof i==`string`?{...e[r],support:i}:{...e[r],...i};return n}function d(e,t,n={}){return{platformName:e===`ios`?`iOS`:`Android`,"appium:deviceName":t,...n}}function f(e,t){let n=e?.bundleId??t?.appIdentifierHint,r=e?.packageName??t?.packageNameHint;return{bundleId:n,packageName:r,appName:e?.appName,launchTarget:m(e?.launchTarget,n,r)}}function p(e){return e===`ios`?`xctest`:`android`}function m(...e){return e.find(e=>e!==void 0)}const h=e(`owner-capability-missing`,`The WebDriver provider session is no longer active for this device.`);function g(e){let t=async(t,n,r,i,a)=>{let o=e.findSessionForDevice(t);if(!o)return;let s=await v(e,o,t,n,r.uploadPath,i,a);return await o.client.installApp(s?.appReference??r.appPath,a),f(s,i)},n=async(e,n,r,i,a)=>await t(e,n,{appPath:r,uploadPath:r},i,a);return Object.freeze({fact:t=>_(e.findSessionForDevice(t)),installApp:n,installInstallablePath:async(e,t,r,i)=>await n(e,``,t,r,i),deployApp:async(e,t,r)=>y(await n(e,t.app,t.appPath,{relaunch:t.replaceExisting,appIdentifierHint:t.app,packageNameHint:t.app},r),t.app),deployMaterializedApp:async(e,n,r)=>y(await t(e,``,{appPath:n.artifact.installablePath,uploadPath:n.artifact.uploadPath??n.artifact.installablePath},{appIdentifierHint:n.artifact.bundleId,packageNameHint:n.artifact.packageName},r))})}function _(t){return t?c(t.capabilities,`install`)?Object.freeze({available:!0}):e(`owner-capability-missing`,l(t.capabilities,`install`)):h}async function v(e,r,i,a,o,s,u){if(!c(r.capabilities,`install`))throw new t(`UNSUPPORTED_OPERATION`,l(r.capabilities,`install`),{provider:e.provider,deviceId:i.id,platform:n(i)});let d=r.prepared.uploadApp??e.uploadApp;if(d)return await d({provider:e.provider,lease:r.lease,device:i,app:a,appPath:o,options:s,signal:u})}function y(e,n){if(!e)throw new t(`UNSUPPORTED_OPERATION`,`The WebDriver provider session no longer supports app deployment.`);return{...e.bundleId?{bundleId:e.bundleId}:{},...e.packageName?{packageName:e.packageName}:{},...e.appName?{appName:e.appName}:{},...e.launchTarget??n?{launchTarget:e.launchTarget??n}:{}}}export{c as a,d as i,h as n,s as o,p as r,l as s,g as t};