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.19 kB
JavaScript
import{v as e}from"./sdk-contracts.js";import{g as t}from"./sdk-batch-runner.js";import{a as n}from"./manifest.js";import{t as r}from"./host5.js";import{pathToFileURL as i}from"node:url";function a(a,s,c){let l=a.agentDevicePlugin,u=async t=>{let r=await import(i(n(s,l.entry)).href);if(typeof r.default!=`function`)throw new e(`INVALID_ARGS`,`Plugin must export a default factory: ${a.name}`,{reason:`invalid_plugin`});return await r.default(t)},d=async(n,i)=>{let s=await u(r(n,c));try{let n=t(s)?s.connection:void 0;if(!t(n)||!o(n.resolve)||!o(n.verify))throw new e(`INVALID_ARGS`,`Plugin connection must provide resolve and verify: ${a.name}`,{reason:`invalid_plugin`});return await i(n)}finally{let e=t(s)?s.runtime:void 0;o(e?.shutdown)&&await Promise.allSettled([e.shutdown()])}};return{apiVersion:2,provider:l.provider,credentials:{variables:l.credentialVariables??[]},...l.connection?{connection:{capabilities:l.connection,resolve:async e=>await d(e.env,t=>t.resolve(e)),verify:async e=>await d(e.env,t=>t.verify(e))}}:{},setup:async e=>{let n=await u(e);return t(n)&&`webDriver`in n?{webDriver:n.webDriver}:n}}}function o(e){return typeof e==`function`}export{a as adaptLegacyPlugin};