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 • 1.84 kB
JavaScript
import{v as e}from"./sdk-contracts.js";import{o as t}from"./adb.js";import{t as n}from"./app-resolution-cache.js";import{t as r}from"./open-target.js";const i={settings:{type:`intent`,value:`android.settings.SETTINGS`}},a=`Run agent-device apps --platform android to discover the installed package name, then retry open with that exact package.`,o=n();function s(e){return{platform:`android`,deviceId:e.id,variant:e.target??``}}async function c(e,t){return await o.invalidateWhile(s(e),t)}async function l(n,a,c={}){let l=a.trim(),d=r(l)===`package`;if(d&&!c.installedOnly)return{type:`package`,value:l};let f=i[l.toLowerCase()];if(f)return f;let p=s(n),m=c.installedOnly?void 0:o.get(p,l);if(m)return m;let h=c.userId===void 0?[]:[`--user`,String(c.userId)],g=(await t(n,[`pm`,`list`,`packages`,...h])).stdout.split(`
`).map(e=>e.replace(`package:`,``).trim()).filter(Boolean),_=e=>c.userId===void 0?o.set(p,l,e):e;if(d){if(!g.includes(l))throw u(a);return _({type:`package`,value:l})}let v=g.filter(e=>e.toLowerCase().includes(l.toLowerCase())),y=v[0];if(y!==void 0&&v.length===1)return _({type:`package`,value:y});throw v.length>1?new e(`INVALID_ARGS`,`Multiple packages matched "${a}"`,{matches:v,hint:`Run agent-device apps --platform android to see the exact installed package names before retrying open.`}):u(a)}function u(t){return new e(`APP_NOT_INSTALLED`,`No package found matching "${t}"`,{hint:a})}function d(e){let t=new Set([`com`,`android`,`google`,`app`,`apps`,`service`,`services`,`mobile`,`client`]),n=e.split(`.`).flatMap(e=>e.split(/[_-]+/)).map(e=>e.trim().toLowerCase()).filter(e=>e.length>0),r=n.at(-1)??e;for(let e=n.length-1;e>=0;--e){let i=n[e];if(i&&!t.has(i)){r=i;break}}return r.split(/[^a-z0-9]+/i).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}export{c as i,d as n,l as r,a as t};