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.

2 lines • 3.97 kB
import{v as e}from"./sdk-contracts.js";import{t}from"./script.js";const n={ad:{pattern:t,description:`uppercase letters, digits, and underscores`},maestro:{pattern:/^(?!__proto__$)[A-Za-z_][A-Za-z0-9_.]*$/,description:`letters, digits, underscores, and dots, starting with a letter or underscore (not __proto__)`}};function r(e){return e.startsWith(`AD_`)}function i(t){return new e(`INVALID_ARGS`,`The AD_* namespace is reserved for built-in variables. Rename ${t} to avoid the AD_ prefix.`)}function a(e){let t={};if(e.builtins)for(let[n,r]of Object.entries(e.builtins))t[n]=r;let n=[e.fileEnv,e.shellEnv,e.cliEnv];for(let e of n)if(e)for(let[n,a]of Object.entries(e)){if(r(n))throw i(n);t[n]=a}return{values:t,expandedBuiltinNames:new Set}}function o(e,t){let i={};for(let[a,o]of Object.entries(e)){if(typeof o!=`string`||!a.startsWith(`AD_VAR_`))continue;let e=a.slice(7);e.length!==0&&n[t].pattern.test(e)&&(r(e)||(i[e]=o))}return i}function s(t,a){let o={};for(let s of t){let t=s.indexOf(`=`);if(t<=0)throw new e(`INVALID_ARGS`,`Invalid -e entry "${s}": expected KEY=VALUE.`);let c=s.slice(0,t),l=n[a];if(!l.pattern.test(c))throw new e(`INVALID_ARGS`,`Invalid -e key "${c}": keys must be ${l.description} (e.g. APP_ID).`);if(r(c))throw i(c);o[c]=s.slice(t+1)}return o}function c(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function l(e,t){if(e&&typeof e==`object`&&!Array.isArray(e)){let t={};for(let[n,r]of Object.entries(e))typeof r==`string`&&(t[n]=r);return t}return t}function u(e){return e>=`A`&&e<=`Z`||e>=`a`&&e<=`z`||e===`_`}function d(e){return u(e)||e>=`0`&&e<=`9`||e===`.`}function f(e){return e===` `||e===`\r`||e===`\u2028`||e===`\u2029`}function p(e,t){let n=m(e,t+2);if(n===null)return null;let r=e.slice(t+2,n);return e[n]===`}`?{key:r,fallback:void 0,end:n+1}:e[n]!==`:`||e[n+1]!==`-`?null:h(e,r,n+2)}function m(e,t){if(t>=e.length||!u(e[t]))return null;let n=t+1;for(;n<e.length&&d(e[n]);)n+=1;return n}function h(e,t,n){let r=``,i=n;for(;i<e.length;){let n=e[i];if(n===`}`)return{key:t,fallback:r,end:i+1};if(n!==`\\`){r+=n,i+=1;continue}let a=e[i+1];if(a===void 0)return{abortEnd:e.length};if(f(a))return{abortEnd:i+2};r+=a,i+=2}return{abortEnd:e.length}}function g(e,t){let n=``,r=0;for(let i=e.indexOf("${");i>=0;i=e.indexOf("${",r)){n+=e.slice(r,i);let a=e.indexOf(`}`,i+2);if(a>=0&&t.has(e.slice(i+2,a))){n+=e.slice(i,a+1),r=a+1;continue}n+="\\${",r=i+2}return n+e.slice(r)}function _(e,t,n){let r=``,i=0;for(;i<e.length;){let a=v(e,i,t,n);r+=a.text,i=a.next}return r}function v(e,t,n,r){if(e[t]===`\\`&&e.startsWith("${",t+1))return{text:"${",next:t+3};if(e[t]!==`$`||e[t+1]!==`{`)return{text:e[t],next:t+1};let i=p(e,t);return i===null?{text:`$`,next:t+1}:`abortEnd`in i?{text:e.slice(t,i.abortEnd),next:i.abortEnd}:{text:y(i,n,r),next:i.end}}function y({key:t,fallback:n},i,a){if(Object.prototype.hasOwnProperty.call(i.values,t))return r(t)&&(i.expandedBuiltinNames??=new Set).add(t),String(i.values[t]);if(n!==void 0)return n;throw new e(`INVALID_ARGS`,`Unresolved variable \${${t}} at ${a.file}:${a.line}.`)}function b(e,t,n){return{...e,positionals:(e.positionals??[]).map(e=>_(e,t,n)),flags:x(e.flags,t,n)??{},runtime:x(e.runtime,t,n)}}function x(e,t,n){return e&&w(e,t,n)}function S(e,t){let n=e=>C(e,t);return{...e,positionals:(e.positionals??[]).map(e=>g(e,t)),flags:n(e.flags)??{},runtime:n(e.runtime)}}function C(e,t){return typeof e==`string`?g(e,t):Array.isArray(e)?e.map(e=>C(e,t)):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).map(([e,n])=>[e,C(n,t)])):e}function w(e,t,n){return typeof e==`string`?_(e,t,n):Array.isArray(e)?e.map(e=>w(e,t,n)):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).map(([e,r])=>[e,w(r,t,n)])):e}function T(e){return Object.entries(e.values).filter(([t,n])=>n.length>0&&(!r(t)||e.expandedBuiltinNames?.has(t))).map(([e,t])=>({name:e,value:t})).sort((e,t)=>t.value.length-e.value.length)}export{s as a,b as c,S as i,T as n,c as o,o as r,l as s,a as t};