UNPKG

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.

2 lines • 1.79 kB
import{v as e}from"./sdk-contracts.js";import{n as t}from"./device-shell.js";import n from"node:path";function r(e,t={}){return{discover:async(n,r)=>await a(e,t,n,r)}}function i(e){return e.split(` `).map(e=>e.trim()).filter(e=>e.length>0&&e!==`[Empty]`)}async function a(t,n,r,a){await t.toolchains.prepare(`harmonyos`);let u=await s(t,o(n));if(!u)throw new e(`TOOL_MISSING`,`hdc not found in PATH`,{hint:`Install HarmonyOS Command Line Tools, then add its sdk/default/openharmony/toolchains directory to PATH.`});let d=await l(t,u,[`list`,`targets`],a);if(d.exitCode!==0)throw new e(`COMMAND_FAILED`,`hdc list targets failed`,{stderr:d.stderr,hint:`Confirm the HarmonyOS emulator or device is running, then run hdc list targets.`});let f=i(d.stdout).filter(e=>!r.serial||r.serial===e);return await Promise.all(f.map(async e=>await c(t,u,e,a)))}function o(e){return[e.hdcSdkPath,e.devecoSdkHome&&n.join(e.devecoSdkHome,`default`,`openharmony`,`toolchains`),e.commandLineToolsHome&&n.join(e.commandLineToolsHome,`sdk`,`default`,`openharmony`,`toolchains`)].filter(e=>e!==void 0)}async function s(e,t){for(let r of t){let t=n.join(r,`hdc`);if(await e.files.isExecutable(t))return t}return await e.commands.which(`hdc`)}async function c(e,n,r,i){let[a,o]=await Promise.all([l(e,n,t(`hdc`,`shell`,[`param`,`get`,`const.product.name`],[`-t`,r]),i),l(e,n,t(`hdc`,`shell`,[`param`,`get`,`const.build.characteristics`],[`-t`,r]),i)]),s=a.exitCode===0?a.stdout.trim():``,c=s.toLowerCase()===`emulator`;return{platform:`harmonyos`,id:r,name:s||r,kind:c?`emulator`:`device`,target:o.stdout.toLowerCase().includes(`tv`)?`tv`:`mobile`,booted:!0}}async function l(e,t,n,r){return await e.commands.run({executable:t,args:n,allowFailure:!0,timeoutMs:1e4},r.signal)}export{r as createHarmonyInventory};