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 • 2.87 kB
JavaScript
import{v as e}from"./sdk-contracts.js";import{y as t}from"./sdk-device.js";import{F as n,O as r,P as i,j as a}from"./device.js";function o(e){let t=s(e.registry,e.loadHost),r=e.provider,o=async(e,o)=>{if(o.signal.throwIfAborted(),e.leaseProvider&&!e.leaseId)throw n(e.leaseProvider);if(r){let t=await r.discover(i(e),o.signal);if(o.signal.throwIfAborted(),g(t),t.kind===`inventory`)return{devices:a(t.devices.map(e=>({...e})),e),source:`provider`}}return{devices:await t.discover(e,o),source:`local`}},c=Object.freeze({discover:async(e,t)=>(await o(e,t)).devices,discoverWithSource:o});return Object.freeze({providerFirst:c,localOnly:t,findInstalledApp:e.findInstalledApp,resolveAppDevice:e.resolveAppDevice})}function s(e,t){let n,i=async()=>{n??=t();try{return await n}catch(e){throw n=void 0,e}},a=new Map,o=async t=>{let n=a.get(t);if(n)return await n;let r=c(e.get(t),i);a.set(t,r);try{return await r}catch(e){throw a.get(t)===r&&a.delete(t),e}};return Object.freeze({discover:async(e,t)=>{if(t.signal.throwIfAborted(),e.platform)return await m(o,_(e.platform),e,t);let n=await Promise.all(r.map(async n=>{try{let r=await m(o,_(n),{...e,platform:n},t);return Array.isArray(r)?r:[]}catch{return[]}}));return t.signal.throwIfAborted(),n.flat()}})}async function c(e,t){switch(e.family){case`apple`:return await e.loadInventory(l(await t()));case`android`:return await e.loadInventory(u(await t()));case`harmonyos`:return await e.loadInventory(d(await t()));case`vega`:return await e.loadInventory(f(await t()));case`linux`:return await e.loadInventory(p(await t()));case`web`:return await e.loadInventory()}}function l(e){return Object.freeze({appleTools:e.appleTools,files:e.files,hostName:e.hostName,hostOs:e.hostOs,observations:e.observations})}function u(e){return Object.freeze({commands:e.commands,files:e.files,homeDirectory:e.homeDirectory,toolchains:e.toolchains})}function d(e){return Object.freeze({commands:e.commands,files:e.files,toolchains:e.toolchains})}function f(e){return Object.freeze({commands:e.commands,files:e.files,homeDirectory:e.homeDirectory})}function p(e){return Object.freeze({hostName:e.hostName,hostOs:e.hostOs})}async function m(e,t,n,r){let i=await e(t);r.signal.throwIfAborted();let o=await i.discover(n,r);return r.signal.throwIfAborted(),h(t,o),a(o,n)}function h(t,n){let r=n.find(e=>e.platform!==t);if(r)throw new e(`COMMAND_FAILED`,`Platform inventory source ${t} returned a ${r.platform} device.`,{expectedFamily:t,actualFamily:r.platform,deviceId:r.id})}function g(t){if(typeof t==`object`&&t){let e=t;if(e.kind===`declined`&&!(`devices`in e)||e.kind===`inventory`&&Array.isArray(e.devices))return}throw new e(`COMMAND_FAILED`,`Provider device inventory returned an invalid outcome.`,{reason:`provider_inventory_contract_violation`})}function _(e){return t(e)?`apple`:e}export{o as createComposedDeviceInventoryGateways};