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 • 4.71 kB
import{v as e}from"./sdk-contracts.js";import{o as t,y as n}from"./runtime13.js";import{c as r,m as i}from"./browserstack.js";import{o as a}from"./providers.js";import o from"node:path";async function s(t,r){let i=c(t.app),a={username:t.username,accessKey:t.accessKey},o=d(await u(t.devicesEndpoint??`https://api-cloud.browserstack.com/app-automate/devices.json`,a,r)).find(e=>e.device===t.deviceName&&e.os.toLowerCase()===t.platform&&n(e.osVersion,t.osVersion));if(!o)throw new e(`INVALID_ARGS`,`BrowserStack device "${t.deviceName}" with ${t.platform} ${t.osVersion} is not available.`,{hint:`Choose an exact device and OS version from the BrowserStack App Automate device list.`});let s=await l(i,t,a,r);return{provider:`browserstack`,service:`BrowserStack`,verificationMessage:s.status===`verified`?`Credentials, device, and uploaded app verified.`:`Credentials and device access verified; app availability is checked when the session is created.`,device:{status:`verified`,name:o.device,platform:t.platform,osVersion:o.osVersion},app:s}}function c(e){return r(e)??e}async function l(e,t,n,r){if(a(e)){let i=f(await u(t.appsEndpoint??`https://api-cloud.browserstack.com/app-automate/recent_apps?limit=100`,n,r)).find(t=>t.reference===e);return i?{status:`verified`,...i}:{status:`configured`,reference:e,message:`App reference was not found in the 100 most recent uploads; BrowserStack validates it when creating the session.`}}return/^https?:\/\//i.test(e)?{status:`configured`,reference:e,message:`Public app URL configured; BrowserStack validates it when creating the session.`}:{status:`configured`,name:o.basename(e),reference:e,message:`Local app artifact is ready and will be uploaded when creating the session.`}}async function u(e,n,r){return await t(e,{clientVersion:r,auth:n,hints:{service:`BrowserStack`,unauthorizedHint:`Check BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY.`,networkHint:`Check network access to api-cloud.browserstack.com and retry connect.`}})}function d(t){if(!Array.isArray(t))throw new e(`COMMAND_FAILED`,`BrowserStack device verification response was not a list.`);return t.flatMap(e=>{let t=p(e),n=t?.os_version;return t&&typeof t.device==`string`&&typeof t.os==`string`&&(typeof n==`string`||typeof n==`number`)?[{device:t.device,os:t.os,osVersion:String(n)}]:[]})}function f(t){let n=p(t);if(n&&Object.keys(n).length===0)return[];if(!Array.isArray(t))throw new e(`COMMAND_FAILED`,`BrowserStack app verification response was not a list.`);return t.flatMap(e=>{let t=p(e);return!t||typeof t.app_url!=`string`?[]:[{reference:t.app_url,...typeof t.app_name==`string`?{name:t.app_name}:{},...typeof t.app_version==`string`?{version:t.app_version}:{}}]})}function p(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:void 0}async function m(t,n){let r=i({runHostCommand:n,region:t.region}),[a,o,s]=await Promise.all([r(`get-project`,[`--arn`,t.projectArn]),r(`get-device`,[`--arn`,t.deviceArn]),t.appArn?r(`get-upload`,[`--arn`,t.appArn]):void 0]),c=g(a,`project`),l=g(o,`device`),u=_(l.platform);if(u!==t.platform)throw new e(`INVALID_ARGS`,`AWS Device Farm device "${v(l.name)??t.deviceArn}" is ${u}, not ${t.platform}.`);let d=t.appArn?h(g(s,`upload`),t):{status:`missing`,message:`No app upload is attached; AWS Device Farm does not support install after allocation. Reconnect with --aws-app-arn <arn>.`};return{provider:`aws-device-farm`,service:`AWS Device Farm`,verificationMessage:t.appArn?`Credentials, project, device, and app upload verified.`:`Credentials, project, and device verified.`,project:{name:v(c.name),reference:t.projectArn},device:{status:`verified`,name:v(l.name)??t.deviceArn,reference:t.deviceArn,platform:u,osVersion:v(l.os),availability:v(l.availability)},app:d}}function h(t,n){let r=v(t.status);if(r!==`SUCCEEDED`)throw new e(`COMMAND_FAILED`,`AWS Device Farm app upload is not ready (${r??`unknown status`}).`,{status:r,hint:`Wait for the upload to succeed or reconnect with a different --aws-app-arn.`});let i=n.platform===`android`?`ANDROID_APP`:`IOS_APP`,a=v(t.type);if(a!==i)throw new e(`INVALID_ARGS`,`AWS Device Farm app upload type is ${a??`unknown`}, expected ${i}.`);return{status:`verified`,name:v(t.name),reference:n.appArn}}function g(t,n){if(!t||typeof t!=`object`)throw new e(`COMMAND_FAILED`,`AWS Device Farm ${n} response was not an object.`);let r=t[n];if(!r||typeof r!=`object`||Array.isArray(r))throw new e(`COMMAND_FAILED`,`AWS Device Farm response missed ${n}.`);return r}function _(t){if(t===`ANDROID`)return`android`;if(t===`IOS`)return`ios`;throw new e(`UNSUPPORTED_PLATFORM`,`AWS Device Farm device platform is ${String(t)}.`)}function v(e){return typeof e==`string`&&e.length>0?e:void 0}export{s as n,m as t};