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 • 9.55 kB
import{O as e,v as t,x as n}from"./sdk-contracts.js";const r=[`grant`,`deny`,`reset`],i=[`full`,`limited`],a=[`all`,`camera`,`microphone`,`photos`,`contacts`,`contacts-limited`,`notifications`,`calendar`,`location`,`location-always`,`media-library`,`motion`,`reminders`,`siri`],o=[`accessibility`,`screen-recording`,`input-monitoring`],s=[`extra-small`,`small`,`medium`,`large`,`extra-large`,`extra-extra-large`,`extra-extra-extra-large`,`accessibility-medium`,`accessibility-large`,`accessibility-extra-large`,`accessibility-extra-extra-large`,`accessibility-extra-extra-extra-large`],c=[`light`,`dark`,`toggle`],l={wifi:{forms:[{kind:`on-off`}],help:`Android switches Wi-Fi with svc wifi; an Apple simulator overrides only its status bar.`},bluetooth:{forms:[{kind:`on-off`}],app:`input`,appScope:{mobile:`device-level`},help:`Android over adb turns its Bluetooth adapter on or off with svc bluetooth, from Android 8.1. It reports the bluetooth state the device holds afterwards, or fails with bluetooth-not-applied or bluetooth-unreadable. A device without an adapter refuses with android_bluetooth_adapter_missing, and an adapter on a build older than 8.1 with android_bluetooth_command_unavailable, before anything changes. --app is refused.`},airplane:{forms:[{kind:`on-off`}],help:`Android applies it through the connectivity service (Android 11+) and reports the airplaneMode that service holds; older builds fail without changing anything. An Apple simulator overrides only its status bar.`},"mobile-data":{forms:[{kind:`on-off`}],app:`input`,appScope:{mobile:`device-level`},help:`Android only. Runs svc data and reports the stored mobileData state, or fails with mobile-data-not-applied or mobile-data-unreadable. Multi-SIM read-back is not covered yet, and --app is refused.`},location:{forms:[{kind:`on-off`,appScope:{apple:`app-scoped`,mobile:`device-level`}},{kind:`coordinates`,appScope:{apple:`device-level`,mobile:`device-level`}}],app:`input`,help:`on|off writes Android's device-wide location_mode, and on an Apple simulator grants or revokes the app's location permission. set <lat> <lon> moves the device's own coordinates on Apple simulators and Android emulators.`},animations:{forms:[{kind:`on-off`}],help:`Android sets its window, transition, and animator duration scales to 1 or 0.`},appearance:{forms:[{kind:`choice`,states:c}],help:`Switches to light or dark mode, or toggles it, on Android, Apple simulators, and the macOS host.`},"text-size":{forms:[{kind:`choice`,states:s}],readable:!0,help:`Reads the preferred text size without a category and applies one with it, on iPhone and iPad simulators (simctl content size) and Android (system font_scale). Android has no ladder of its own: a read names the nearest rung and reports the multiplier as platformValue. A running app adopts a new size at its next configuration change, so relaunch it.`},faceid:{forms:[{kind:`choice`,states:[`match`,`nonmatch`,`enroll`,`unenroll`]}],help:`Simulates Face ID on iPhone and iPad simulators.`},touchid:{forms:[{kind:`choice`,states:[`match`,`nonmatch`,`enroll`,`unenroll`]}],help:`Simulates Touch ID on iPhone and iPad simulators.`},fingerprint:{forms:[{kind:`choice`,states:[`match`,`nonmatch`]}],help:`Simulates a fingerprint touch on Android emulators, and on devices that expose cmd fingerprint.`},"clear-app-state":{forms:[{kind:`app-id`}],app:`positional`,appRequired:!0,appScope:{apple:`app-scoped`,mobile:`app-scoped`},help:`Clears the data of the positional app, the --app app, or the session app, and refuses two different apps. It leaves the keychain alone. An app with no data container, such as a simulator system app, refuses with app-no-data-container.`},"reset-keychain":{forms:[{kind:`choice`,states:[`clear`]}],help:`Resets the whole iOS simulator keychain, for every app on it: simctl has no per-app reset. A fresh-install reset needs this and clear-app-state; relaunch the app afterwards to see it signed out.`},permission:{forms:[{kind:`permission`,actions:r,targets:a,modes:i},{kind:`permission`,actions:[`grant`,`reset`],targets:o}],app:`input`,appScope:{apple:`app-scoped`,mobile:`app-scoped`,"macos-host":`device-level`},help:`Changes a permission of the --app app or the session app. An iOS simulator, local or Limrun, resolves --app to an installed bundle id or display name, and Android to an installed package. On Android, deny|reset of a held permission kills a running app; the response reports priorGrantState and warns, and open <app> --relaunch restores it. Android needs a resolvable foreground user and changes nothing without one. On the macOS host, grant|reset change the host TCC grants for the three desktop targets and take no --app.`}},u=Object.keys(l);function d(e){let t=e?.trim().toLowerCase();return t!==void 0&&Object.hasOwn(l,t)?l[t]:void 0}function f(e,t){return Object.freeze({setting:`text-size`,category:e,platformValue:t})}function p(e){return`Text size is ${e.category}`}function m(e,t,n){return e===`clear-app-state`?`Cleared user data for ${n}`:e===`text-size`?`Text size set to ${t}`:`Updated setting: ${e}`}function h(e,t,n){let r=d(t);if(r===void 0)return`unknown`;let i=r.forms.length===1?r.forms[0]:r.forms.find(e=>k(e,n));return((i&&`appScope`in i?i.appScope:void 0)??r.appScope)?.[e]??`unknown`}function g(e,t,n){let r=t===void 0?e:`${e} ${t}`;return{code:`INVALID_ARGS`,message:`settings ${r} applies to the target itself, not to an app: ${n} names nothing it can grant or revoke.`,details:{reason:`setting_app_not_consumed`,dispatched:`no`,setting:r,app:n},hint:`Drop the --app option and run \`settings ${r}\`, or aim the app at an app-scoped setting such as \`settings permission grant location --app ${n}\`.`}}const _=`setting_app_not_package`;async function v(r,i){try{return await i(r)}catch(i){throw i instanceof t?(i.code===`APP_NOT_INSTALLED`&&(i.details={...i.details,...n(),app:r,hint:`Run apps --all for the exact bundle id or package name, or install the app, then retry with that id in --app.`}),e(i,`no`)):i}}function y(e,t){switch(e.kind){case`on-off`:return`<on|off>`;case`choice`:{let n=e.states.join(`|`);return t?`[${n}]`:e.states.length===1?n:`<${n}>`}case`coordinates`:return`set <lat> <lon>`;case`permission`:{let t=e.modes?` [${e.modes.join(`|`)}]`:``;return`<${e.actions.join(`|`)}> <${e.targets.join(`|`)}>${t}`}case`app-id`:return`[app-id]`}}function b(){let e=new Map;for(let t of u){let n=l[t];for(let r of n.forms){let i=y(r,n.readable===!0);e.set(i,[...e.get(i)??[],t])}}return[...e].map(([e,t])=>t.length===1?`${t[0]} ${e}`:`<${t.join(`|`)}> ${e}`)}const x=b().map(e=>`settings ${e}`).join(` | `),S=`settings requires ${b().join(`, `).replace(/, (?!.*, )/,`, or `)}`;function C(){return u.map(e=>`${e}: ${l[e].help}`)}function w(e){let t=d(e[0]);if(t===void 0)throw D();let n=A(e[0]),r=A(e[1]);if(t.forms.some(e=>e.kind===`app-id`)){let t=r===`clear`;if(e.length>(t?3:2))throw D();let i=t?e[2]:e[1];return{setting:n,state:`clear`,...i===void 0?{}:{app:i}}}let i=t.forms.find(e=>k(e,r));if(i===void 0||r===void 0)throw O(n,t,r);return T(n,r,i,t,e)}function T(e,t,n,r,i){switch(n.kind){case`coordinates`:if(i.length!==4)throw D();return{setting:e,state:t,latitude:i[2],longitude:i[3]};case`permission`:return{setting:e,state:t,...E(r,t,i)};case`on-off`:if(i.length!==2)throw D();return{setting:e,state:L(t)?`on`:`off`};default:if(i.length!==2)throw D();return{setting:e,state:t}}}function E(e,n,r){let i=e.forms.filter(e=>e.kind===`permission`),a=i.flatMap(e=>e.targets),o=N(a,r[2]),s=i.find(e=>e.targets.includes(o??``));if(o===void 0||s===void 0)throw new t(`INVALID_ARGS`,`settings permission requires a target: ${a.join(`|`)}`);if(N(s.actions,n)===void 0)throw new t(`INVALID_ARGS`,`settings permission ${n} does not apply to ${o}. Use ${s.actions.join(`|`)}.`);if(r.length===3)return{permission:o};let c=N(s.modes??[],r[3]);if(c===void 0||r.length>4)throw new t(`INVALID_ARGS`,s.modes===void 0?`settings permission ${o} takes no mode.`:`settings permission mode must be ${s.modes.join(`|`)}.`);return{permission:o,mode:c}}function D(){return new t(`INVALID_ARGS`,S)}function O(e,n,r){let i=n.forms.map(e=>e.kind===`choice`?e.states.join(`|`):y(e,!1)).join(` | `).replace(`<on|off>`,`on|off`);return new t(`INVALID_ARGS`,r===void 0?`settings ${e} requires a state: ${i}.`:`Invalid ${e} state: ${r}. Use ${i}.`)}function k(e,t){switch(e.kind){case`on-off`:return L(A(t))!==void 0;case`choice`:return N(e.states,t)!==void 0;case`coordinates`:return A(t)===`set`;case`permission`:return N(e.actions,t)!==void 0;case`app-id`:return!0}}function A(e){return e?.trim().toLowerCase()}function j(e){let t=M(e);if(t!==void 0)return t;throw O(`text-size`,l[`text-size`],e)}function M(e){return N(s,e)}function N(e,t){let n=A(t);return n===void 0?void 0:e.find(e=>e===n)}function P(e){let n=N(r,e);if(n!==void 0)return n;throw new t(`INVALID_ARGS`,`Invalid permission action: ${e}. Use ${r.join(`|`)}.`)}function F(e){let n=N(a,e);if(n!==void 0)return n;throw new t(`INVALID_ARGS`,`permission setting requires a target: ${a.join(`|`)}`)}function I(e){let n=N(c,e);if(n!==void 0)return n;throw new t(`INVALID_ARGS`,`Invalid appearance state: ${e}. Use ${c.join(`|`)}.`)}function L(e){let t=A(e);if(t===`on`||t===`true`||t===`1`)return!0;if(t===`off`||t===`false`||t===`0`)return!1}function R(e){let n=L(e);if(n!==void 0)return n;throw new t(`INVALID_ARGS`,`Invalid setting state: ${e}`)}export{o as _,I as a,s as b,R as c,M as d,v as f,f as g,C as h,m as i,w as l,h as m,x as n,P as o,g as p,p as r,F as s,_ as t,j as u,i as v,d as x,u as y};