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.
3 lines • 8.28 kB
JavaScript
import{r as e}from"./rolldown-runtime.js";import{v as t}from"./sdk-contracts.js";import{A as n,P as r,T as i,a,w as o,y as ee}from"./sdk-device.js";const s=[`android`,`harmonyos`,`apple`,`vega`,`linux`];function c(e){let{booted:t,kind:n,...r}=e;return r}const l={platform:`web`,id:`agent-browser-chrome`,name:`Agent Browser Chrome`,kind:`device`,target:`desktop`,booted:!0};function u(e){let t=f();for(let n of e){let e=p(n);t[e].available+=1,n.booted===!0&&(t[e].booted+=1)}return t}function d(e,t){return e.filter(e=>r(e,t.platform)&&(t.target===void 0||(e.target??`mobile`)===t.target)&&(t.kind===void 0||e.kind===t.kind)&&(t.booted===void 0||e.booted===t.booted))}function f(){return{android:{available:0,booted:0},harmonyos:{available:0,booted:0},apple:{available:0,booted:0},vega:{available:0,booted:0},linux:{available:0,booted:0},web:{available:0,booted:0}}}function p(e){return o(e)||i(e)?`apple`:e.platform}const m=new Set([`DEVICE_CLAIM_LIVE_OWNER`,`DEVICE_CLAIM_RECOVERY_PENDING`,`DEVICE_CLAIM_OWNER_UNCERTAIN`]);function h(e){return m.has(e)}function g(e){return new t(`DEVICE_NOT_FOUND`,`The provider connection has no allocated instance.`,{reason:`provider_instance_unallocated`,hint:`Run boot or open to allocate an instance. SDK callers allocate one with leases.allocate and pass its leaseId.`,leaseProvider:e})}const _=[`platform`,`device`,`udid`,`serial`];function v(e,t){(!x(e)||Object.keys(e).length===0)&&b(`devicePin in ${t} must be a non-empty selector object.`,t);let r={};for(let[n,i]of Object.entries(e))(!_.includes(n)||typeof i!=`string`||!i.trim()||n===`platform`&&!a.includes(i))&&b(`Invalid devicePin.${n} in ${t}.`,t),Object.assign(r,{[n]:i});return(r.udid&&r.serial||r.platform&&(r.udid&&!ee(r.platform)||r.serial&&!n(r.platform)))&&b(`devicePin in ${t} contains incompatible selectors.`,t),r}function y(e){if(e===void 0)return;let t=`daemon request metadata`;(!x(e)||Object.keys(e).some(e=>e!==`selector`&&e!==`source`)||!x(e.source))&&b(`devicePin must contain selector and source objects.`,t);let{kind:n,path:r}=e.source;(n!==`user`&&n!==`project`&&n!==`explicit`||typeof r!=`string`||!r.trim()||Object.keys(e.source).some(e=>e!==`kind`&&e!==`path`))&&b(`devicePin.source must contain a config kind and non-empty path.`,t);let i=`${n===`project`?`project `:``}config file ${r}`;return{selector:v(e.selector,i),source:{kind:n,path:r}}}function b(e,n){throw new t(`INVALID_ARGS`,e,{reason:`invalid_device_pin`,pinSource:n})}function x(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const S=`native-panel`,C=[`portrait`,`portrait-upside-down`,`landscape-left`,`landscape-right`],w={portrait:0,"landscape-left":1,"portrait-upside-down":2,"landscape-right":3};function T(e){return C.find(t=>w[t]===e)}function E(e){return typeof e==`string`&&C.includes(e)}function D(e){return w[e]*90}function O(e){return w[e]%2==0?`PORTRAIT`:`LANDSCAPE`}function k(e){if(e===void 0)throw new t(`INVALID_ARGS`,`orientation requires an orientation argument. Use portrait|portrait-upside-down|landscape-left|landscape-right.`);switch(e?.trim().toLowerCase()){case`portrait`:return`portrait`;case`portrait-upside-down`:case`upside-down`:return`portrait-upside-down`;case`landscape-left`:case`left`:return`landscape-left`;case`landscape-right`:case`right`:return`landscape-right`;default:throw new t(`INVALID_ARGS`,`Invalid rotation: ${e}. Use portrait|portrait-upside-down|landscape-left|landscape-right.`)}}const A=[...C,`auto`];function j(e){return e?.trim().toLowerCase()===`auto`?`auto`:k(e)}const M=[`volume-up`,`volume-down`,`power`,`mute`,`sleep`,`wake`,`media-play-pause`,`media-next`,`media-previous`,`media-rewind`,`media-fast-forward`],N=`<${M.join(`|`)}>`,P={volumeUp:`volume-up`,volumeDown:`volume-down`,power:`power`,mute:`mute`,sleep:`sleep`,wake:`wake`,mediaPlayPause:`media-play-pause`,mediaNext:`media-next`,mediaPrevious:`media-previous`,mediaRewind:`media-rewind`,mediaFastForward:`media-fast-forward`},F=new Map(Object.entries(P).map(([e,t])=>[t,e]));function I(e){let n=e?.toLowerCase(),r=n===void 0?void 0:F.get(n);if(r)return r;throw new t(`INVALID_ARGS`,`hardware-button button must be one of: ${M.join(`, `)}.`)}function L(e){if(e.length!==1)throw new t(`INVALID_ARGS`,`hardware-button requires exactly one button: ${M.join(`, `)}.`);return I(e[0])}const R=[`closed`,`half-open`,`open`],z=`closed|half-open|open`;function B(e){if(Number.isFinite(e))return e<=V?`closed`:e>=te?`open`:`half-open`}const V=1,te=179;function H(e){if(e===void 0)throw new t(`INVALID_ARGS`,`fold requires a pose argument. Use ${z}.`);switch(e.trim().toLowerCase()){case`closed`:case`close`:case`fold`:case`folded`:return`closed`;case`half-open`:case`half`:case`half-unfolded`:case`partially-open`:case`book`:return`half-open`;case`open`:case`unfold`:case`unfolded`:case`fully-open`:case`flat`:return`open`;default:throw new t(`INVALID_ARGS`,`Invalid fold pose: ${e}. Use ${z}.`)}}const U=6e4;function W(e){if(e.keyframes===void 0){if(e.pose===void 0)throw new t(`INVALID_ARGS`,`fold requires a pose or keyframes`);if(typeof e.pose!=`string`)throw new t(`INVALID_ARGS`,`fold pose must be a string`);return{pose:H(e.pose)}}if(e.pose!==void 0)throw new t(`INVALID_ARGS`,`fold accepts either pose or keyframes`);return{keyframes:G(e.keyframes)}}function G(e){if(!Array.isArray(e)||e.length<2||e.length>64)throw new t(`INVALID_ARGS`,`fold requires 2–64 keyframes`);let n=e.map(q);if(n[0].atMs!==0||n.some((e,t)=>t>0&&e.atMs<=n[t-1].atMs))throw new t(`INVALID_ARGS`,`Fold keyframes must start at 0ms and increase strictly`);return n}function K(e,t){return typeof e==`number`&&Number.isFinite(e)&&e>=0&&e<=t}function q(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new t(`INVALID_ARGS`,`Each fold keyframe requires atMs and angle`);let{atMs:n,angle:r}=e;if(Object.keys(e).some(e=>e!==`atMs`&&e!==`angle`))throw new t(`INVALID_ARGS`,`Fold keyframes only accept atMs and angle`);if(!K(n,6e4)||!Number.isSafeInteger(n))throw new t(`INVALID_ARGS`,`Fold keyframe times must be integers from 0 to ${U}ms`);if(!K(r,180))throw new t(`INVALID_ARGS`,`Fold keyframe angles must be finite numbers from 0 to 180`);return{atMs:n,angle:r}}function J(e){let n;try{n=JSON.parse(e)}catch{throw new t(`INVALID_ARGS`,`--keyframes requires a JSON array of {atMs, angle} objects`)}return G(n)}const Y=[`call`,`accept`,`cancel`],X=[...Y,`sms`],Z=`telephony call|accept|cancel <number> | telephony sms <number> <text>`,Q=/^\+?\d{1,15}$/,ne=/[\u0000-\u0009\u000b-\u001f\u007f-\u009f]/;function re(e){if(e===void 0)throw new t(`INVALID_ARGS`,`telephony requires an action. Use ${Z}.`);let n=typeof e==`string`?e.trim().toLowerCase():void 0,r=X.find(e=>e===n);if(!r)throw new t(`INVALID_ARGS`,`Invalid telephony action: ${String(e)}. Use ${X.join(`, `)}.`);return r}function $(e){let n=re(e.action),r=oe(e.number,n);if(n!==`sms`){if(e.text!==void 0)throw new t(`INVALID_ARGS`,`telephony ${n} takes only a phone number.`);return{action:n,number:r}}return{action:n,number:r,text:se(e.text)}}function ie(e){let[t,n,...r]=e;return $({action:t,number:n,text:r.length>0?r.join(` `):void 0})}function ae(e){return e.action===`sms`?[e.action,e.number,e.text]:[e.action,e.number]}function oe(e,n){if(typeof e!=`string`||e.trim()===``)throw new t(`INVALID_ARGS`,`telephony ${n} requires a phone number.`);let r=e.trim();if(!Q.test(r))throw new t(`INVALID_ARGS`,`Invalid phone number: ${r}.`,{hint:`Use digits with an optional leading +, for example 5551234 or +15551234567.`});return r}function se(e){if(typeof e!=`string`||e===``)throw new t(`INVALID_ARGS`,`telephony sms requires message text.`);let n=e.replaceAll(`\r
`,`
`);if(ne.test(n))throw new t(`INVALID_ARGS`,`telephony sms text must not contain control characters.`,{hint:`Line breaks (LF or CRLF) are allowed; tabs, lone carriage returns, and other control characters are not.`});return n}var ce=e({FOLD_POSE_USAGE:()=>z,FOLD_SCREEN_COORDINATE_SPACE:()=>S,HARDWARE_BUTTON_NAME_LABELS:()=>P,MAX_FOLD_DURATION_MS:()=>U,MAX_FOLD_KEYFRAMES:()=>64,TELEPHONY_USAGE:()=>Z});export{u as A,W as C,j as D,L as E,g as F,y as I,h as M,v as N,s as O,c as P,E as S,H as T,A as _,$ as a,D as b,C as c,z as d,S as f,U as g,N as h,Z as i,d as j,l as k,w as l,P as m,X as n,ie as o,M as p,Y as r,ae as s,ce as t,R as u,T as v,J as w,B as x,O as y};