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 • 4.48 kB
JavaScript
import{r as e}from"./rolldown-runtime.js";import{v as t}from"./sdk-contracts.js";import{g as n}from"./sdk-batch-runner.js";import{gt as r,p as i,rt as a}from"./sdk-io.js";import{m as o,n as s}from"./file.js";import"./command.js";import{t as c}from"./manifest.js";import{a as l,i as u,n as d,o as f,r as p,t as m}from"./store-legacy.js";import h from"node:crypto";import g from"node:fs";import _ from"node:path";import{pathToFileURL as v}from"node:url";var y=e({changePlugin:()=>O,legacyStoreManifests:()=>p,listPlugins:()=>T,storePluginCandidates:()=>C});async function b(e,n,r){let{discoverPluginEntry:i,readPackageJson:a}=await import(`./discovery.js`),o=a(n);if(o.name!==e)throw new t(`INVALID_ARGS`,`Plugin package identity mismatch: ${e}`);let s=typeof o.version==`string`?o.version:void 0;if(s===void 0)throw new t(`INVALID_ARGS`,`Plugin package has no version: ${e}`,{reason:`invalid_plugin`});return{name:e,version:s,directory:n,selection:r,entry:i(n)}}async function x(e,t,n){return f(t,n),b(t,m(e,t,n.installation),n)}async function S({name:e,directory:n,selection:r,entry:i}){if(i.kind===`v1`){let{adaptLegacyPlugin:e}=await import(`./legacy.js`);return e(i.manifest,n,r.options)}let a=await import(v(i.file).href);if(typeof a.default!=`function`)throw new t(`INVALID_ARGS`,`Plugin must export a default factory: ${e}`,{reason:`invalid_plugin`});return await a.default(r.options)}async function C(e){let t=l(e),n;try{n=Object.entries(u(e).plugins??{})}catch(e){return[{source:`store`,load:()=>Promise.reject(e)}]}let r=n.sort(([e],[t])=>e<t?-1:+(e>t));return await Promise.all(r.map(async([e,n])=>{try{let r=await x(t,e,n);return{source:`store`,package:e,version:r.version,...r.entry.kind===`v1`?{provider:r.entry.manifest.agentDevicePlugin.provider}:{},...n.options?{hostOptions:n.options}:{},load:()=>S(r)}}catch(r){return{source:`store`,package:e,...await w(t,e,n),load:()=>Promise.reject(r)}}}))}async function w(e,t,n){try{f(t,n);let{readPackageJson:r}=await import(`./discovery.js`),i=r(m(e,t,n.installation)).version;return typeof i==`string`?{version:i}:{}}catch{return{}}}async function T(e,t){let{claimProviderIds:n,resolveProviderPlugins:r}=await import(`./registry.js`);return(await r([...n(t),...await C(e)])).inventory().map(e=>({name:e.package,...e.version===void 0?{}:{version:e.version},...e.provider===void 0?{}:{provider:e.provider},compatible:e.state===`active`,...e.error?{error:e.error}:{}}))}function E(e,n){if(e===`remove`)return{name:n,version:void 0};let r=/^(@[a-z0-9][a-z0-9._-]*\/[a-z0-9][a-z0-9._-]*|[a-z0-9][a-z0-9._-]*)(?:@(.+))?$/.exec(n);if(!r||!r[1]||r[2]!==void 0&&!d(r[2]))throw new t(`INVALID_ARGS`,`Expected an npm package name, optionally followed by @version or @tag`);if(e===`update`&&r[2]!==void 0)throw new t(`INVALID_ARGS`,`update accepts a package name without a version`);return{name:r[1],version:r[2]}}async function D(e,t,n,r){let i=h.randomUUID(),o=_.join(e,`plugins`,i);g.mkdirSync(o,{recursive:!0,mode:448});try{return g.writeFileSync(_.join(o,`package.json`),JSON.stringify({private:!0,dependencies:{[t]:n??`latest`}})),await a(`npm`,[`install`,`--ignore-scripts`,`--no-audit`,`--no-fund`,`--global=false`,`--prefix`,o,`--workspaces=false`,`--package-lock=true`],{cwd:o,env:r,timeoutMs:12e4}),{installation:i,project:o,entry:(await b(t,m(e,t,i),{installation:i})).entry}}catch(e){throw g.rmSync(o,{recursive:!0,force:!0}),e}}async function O(e,a,c,l){let{name:f,version:m}=E(e,a),h=o(c),v=_.dirname(h);g.mkdirSync(v,{recursive:!0,mode:448});let y=await s({lockDirPath:_.join(v,`plugins.lock`),owner:{...i(),acquiredAtMs:Date.now()},description:`plugin installation`}),b;try{let i=u(c),a={...i.plugins},o=Object.hasOwn(a,f)?a[f]:void 0;if(e!==`add`&&!Object.hasOwn(a,f))throw new t(`INVALID_ARGS`,`Plugin is not installed: ${f}`);if(e===`remove`)delete a[f];else{let t=e===`update`&&d(o?.version)?o.version:m;b=await D(v,f,t,c),k([...p(c).filter(e=>e.name!==f),...b.entry.kind===`v1`?[b.entry.manifest]:[]],l),a[f]={installation:b.installation,version:t,...n(o?.options)?{options:o.options}:{}}}r({destination:h,contents:`${JSON.stringify({...i,plugins:a},null,2)}\n`,mode:384})}catch(e){throw b&&g.rmSync(b.project,{recursive:!0,force:!0}),e}finally{await y()}}function k(e,n){let r=new Set([...c,...n]);for(let{agentDevicePlugin:n}of e){if(r.has(n.provider))throw new t(`INVALID_ARGS`,`Duplicate provider plugin: ${n.provider}`,{reason:`duplicate_provider`});r.add(n.provider)}}export{y as i,T as n,C as r,O as t};