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.92 kB
JavaScript
import{v as e}from"./sdk-contracts.js";import t from"node:fs";import n from"node:path";const r=[`cloud`,`proxy`],i=/^[A-Z_][A-Z0-9_]*$/;function a(t){return new e(`INVALID_ARGS`,t,{reason:`invalid_plugin`})}function o(e){if(e!==void 0&&(!e||typeof e!=`object`||e.leaseKind!==`direct-device-provider`||[`requiresAppAttachment`,`requiresRemoteDaemon`,`supportsArtifacts`,`supportsDeferredAppSelection`,`supportsDirectPortReverse`,`usesCloudWebDriverLease`].some(t=>typeof e[t]!=`boolean`)||e.holdsCloudDevice!==void 0&&typeof e.holdsCloudDevice!=`boolean`||e.forgetsEndedConnectionLease!==void 0&&typeof e.forgetsEndedConnectionLease!=`boolean`||e.requiresRemoteDaemon))throw a(`Plugin connection must declare local provider capabilities`)}function s(e){if(e!==void 0&&(!Array.isArray(e)||!e.every(e=>typeof e==`string`&&i.test(e))))throw a(`Plugin credential variables must list environment variable names`)}function c(r){let i;try{let e=n.join(r,`package.json`);i=JSON.parse(t.readFileSync(e,`utf8`))}catch(t){throw new e(`INVALID_ARGS`,`Cannot read plugin manifest: ${r}`,{},t)}let a=i?.agentDevicePlugin;if(typeof i?.name!=`string`||typeof i?.version!=`string`||!a||a.apiVersion!==1||typeof a.provider!=`string`||!/^[a-z][a-z0-9-]*$/.test(a.provider)||typeof a.entry!=`string`||!a.entry.startsWith(`./`))throw new e(`INVALID_ARGS`,`Package does not declare a compatible provider plugin`,{reason:`incompatible_plugin`,apiVersion:1,hint:`Install a plugin release supporting agentDevicePlugin.apiVersion 1.`});return l(r,a.entry),o(a.connection),s(a.credentialVariables),i}function l(r,i){try{let e=t.realpathSync(r),a=t.realpathSync(n.resolve(r,i));if(i.startsWith(`./`)&&a.startsWith(`${e}${n.sep}`)&&t.statSync(a).isFile())return a}catch{}throw new e(`INVALID_ARGS`,`Plugin entry must be a readable file inside its package`,{reason:`plugin_load_failed`,directory:r,entry:i})}export{l as a,c as i,s as n,o as r,r as t};