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 • 1.73 kB
JavaScript
import{v as e}from"./sdk-contracts.js";const t=/^[A-Za-z0-9_@%+=:,./-]+$/;function n(e){return`'${e.replaceAll(`'`,String.raw`'\''`)}'`}function r(e){return t.test(e)?e:n(e)}function i(e){return Object.freeze({script:e})}const a=new WeakMap,o=/[\\$"`]/g;function s(e){return e.replaceAll(o,e=>`\\${e}`)}function c(t,n){if(typeof t==`number`)return String(t);if(typeof t==`string`){if(n===`hdc`){if(t===``)throw new e(`INVALID_ARGS`,`hdc drops an empty element instead of carrying it, so the device command would lose an operand.`,{reason:`hdc-empty-word-unsupported`,hint:`Pass a value the transport can carry, or use a device action that needs no operand.`});return s(t)}return r(t)}if(n===`hdc`)throw new e(`INVALID_ARGS`,`hdc wraps every element in double quotes, so a shell fragment would reach the device as literal text instead of a script.`,{reason:`hdc-shell-fragment-unsupported`});return t.script}function l(e,t,n,r=[]){let i=Object.freeze([...r,t,...n.map(t=>c(t,e))]);return a.set(i,r.length),i}function u(e,t,n){if(n===0)return e;let r=a.get(e),i=[...e.slice(0,t),...e.slice(t+n)];if(r===void 0||t+n>r)return i;let o=r-n,s=Object.freeze(i);return a.set(s,o),s}function d(e,t){let n=a.get(t),r=Object.freeze([...e,...t]);return n!==void 0&&a.set(r,e.length+n),r}function f(t,n){if(!(!t.includes(`shell`)&&!t.includes(`exec-out`))&&!a.has(t))throw new e(`INVALID_ARGS`,`${n}: device-shell argv must be built with deviceShellArgv (got ${JSON.stringify(t)}).`,{reason:`unguarded-device-shell-argv`})}function p(e){let t=e.slice(Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`))+1).replace(/\.(?:com|exe|bat|cmd)$/i,``);return t===`adb`||t===`hdc`?t:void 0}export{u as a,r as c,d as i,l as n,i as o,p as r,n as s,f as t};