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.56 kB
JavaScript
import{j as e,v as t}from"./sdk-contracts.js";const n=new Set([`__proto__`,`constructor`,`prototype`]);async function r(e,t){return(await a(e,t,`evalScript`,{})).outputEnv}async function i(e,t,n,r){return await a(e,t,r,{maestro:{platform:n}})}async function a(n,r,i,a){let c=s(r),u=o(n),{default:d}=await import(`node:vm`),f={...r,...a,output:c},p;try{p=d.runInNewContext(u,f,{filename:i,timeout:1e4})}catch(n){throw new t(`COMMAND_FAILED`,`Maestro ${i} failed: ${e(n)}`,void 0,n instanceof Error?n:void 0)}return{value:p,outputEnv:l(f.output)}}function o(e){let t=e.trim();return t.startsWith("${")&&t.endsWith(`}`)?t.slice(2,-1):t}function s(e){let t=Object.create(null);for(let[n,r]of Object.entries(e))!n.startsWith(`output.`)||n===`output`||c(t,n.slice(7),r);return t}function c(e,t,n){let r=t.split(`.`).filter(d);if(r.length===0)return;let i=e;for(let e of r.slice(0,-1)){let t=i[e];(typeof t!=`object`||!t)&&(i[e]=Object.create(null)),i=i[e]}i[r.at(-1)]=n}function l(e){let t={};return u(e,[],t,new Set),t}function u(e,t,n,r){if(e!==void 0){if(typeof e!=`object`||!e){n[`output${t.map(e=>`.${e}`).join(``)}`]=f(e);return}if(!r.has(e)){r.add(e);try{let i=Array.isArray(e)?[...e.keys(),`length`]:Object.keys(e).filter(d);for(let a of i){let i=String(a);u(Array.isArray(e)&&i===`length`?e.length:e[i],[...t,i],n,r)}}finally{r.delete(e)}}}}function d(e){return!n.has(e)}function f(e){return typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}export{i as evaluateMaestroConditionScript,r as evaluateMaestroEvalScript};