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.85 kB
JavaScript
import{r as e}from"./rolldown-runtime.js";import{C as t,v as n}from"./sdk-contracts.js";import r from"node:fs";import i from"node:path";import{Readable as a}from"node:stream";import{pipeline as o}from"node:stream/promises";var s=e({downloadLimrunFile:()=>c});async function c(e){let t=AbortSignal.timeout(e.timeoutMs),s=e.signal?AbortSignal.any([t,e.signal]):t;try{await r.promises.mkdir(i.dirname(e.destinationPath),{recursive:!0});let t=await fetch(e.url,{method:`GET`,headers:e.headers,signal:s});if(!t.ok)throw await l(t,e);if(!t.body)throw new n(`COMMAND_FAILED`,`Limrun download returned no body`,{url:e.url});await o(a.fromWeb(t.body),r.createWriteStream(e.destinationPath),{signal:s})}catch(n){throw await r.promises.rm(e.destinationPath,{force:!0}).catch(()=>{}),d(n,e,t,s)}}async function l(e,t){return new n(`COMMAND_FAILED`,`Limrun download failed with HTTP ${e.status}`,{url:t.url,statusCode:e.status,reason:`limrun_download_http_error`,body:await u(e)})}async function u(e){if(!e.body)return``;let t=e.body.getReader(),n=[],r=0;try{for(;r<500;){let{done:e,value:i}=await t.read();if(e)break;let a=500-r;n.push(i.subarray(0,a)),r+=i.byteLength}}finally{t.cancel().catch(()=>{})}return Buffer.concat(n).toString(`utf8`)}function d(e,r,i,a){if(e instanceof n)return e;if(r.signal?.aborted&&a.reason===r.signal.reason){let e=r.signal.reason;return e instanceof n?e:e instanceof Error&&e.name===`TimeoutError`?new n(`COMMAND_FAILED`,`Limrun download deadline expired`,{url:r.url,reason:`limrun_download_timeout`,timeoutMs:r.timeoutMs},e):t(void 0,e)}return i.aborted?new n(`COMMAND_FAILED`,`Limrun download timed out`,{url:r.url,timeoutMs:r.timeoutMs,reason:`limrun_download_timeout`}):new n(`COMMAND_FAILED`,`Limrun download failed`,{url:r.url,reason:`limrun_download_failed`,cause:e instanceof Error?e.message:String(e)})}export{s as n,c as t};