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.
3 lines • 3.03 kB
JavaScript
import{r as e}from"./rolldown-runtime.js";import{v as t}from"./sdk-contracts.js";import n from"node:crypto";import{types as r}from"node:util";function i(e,t){let n=[],r=e+t.toString(),i=r.indexOf(`
`);for(;i!==-1;){let e=r.slice(0,i).trim();r=r.slice(i+1),e&&n.push(e),i=r.indexOf(`
`)}return{lines:n,buffer:r}}async function a(e){return e===`https:`?(await import(`node:https`)).default:(await import(`node:http`)).default}function o(e,t){return new Promise((n,r)=>{let i=``;e.setEncoding(`utf8`),e.on(`data`,e=>{t?.(e),i+=e}),e.on(`end`,()=>n(i)),e.on(`error`,r)})}async function s(e,n,r){let i=[],a=0;for await(let o of e){let e=Buffer.isBuffer(o)?o:Buffer.from(o);if(a+=e.length,a>n)throw new t(`INVALID_ARGS`,r);i.push(e)}return Buffer.concat(i)}function c(e,t){let r=n.createHash(`sha256`).update(e).digest(),i=n.createHash(`sha256`).update(t).digest();return n.timingSafeEqual(r,i)}function l(e,t,n){let i=Object.getOwnPropertyDescriptor(e,`write`),a=e.write,o=!0,s=()=>{o=!1},c=function(...i){let[s,c]=i,l=typeof c==`function`?1:2,u=i[l],d=typeof c==`string`?c.toLowerCase():void 0,f=typeof s==`string`?d===`hex`||d===`base64`||d===`base64url`?Buffer.from(s,d).byteLength>0:s.length>0:r.isUint8Array(s)&&s.byteLength>0;return o&&f&&(i[l]=r=>{!r&&o&&!e.destroyed&&!t.aborted&&n(),typeof u==`function`&&u(r)}),Reflect.apply(a,this,i)};return e.write=c,e.prependListener(`response`,s),()=>{o=!1,e.off(`response`,s),e.write===c&&(i?Object.defineProperty(e,"write",i):Reflect.deleteProperty(e,`write`))}}const u=3e4,d=3e4,f=12e4,p=new Set([`request-body`,`response-body`]),m=`transfer_phase_timeout`;function h(e){let t=new AbortController,n=e?AbortSignal.any([e,t.signal]):t.signal,r,i,a=!1,o=()=>{i!==void 0&&clearTimeout(i),i=void 0;let e=r;!e||a||(i=setTimeout(()=>{i=void 0,t.abort(g(e.phase,e.timeoutMs))},e.timeoutMs),i.unref())};return{signal:n,arm(e,t){n.aborted||(a=!1,r={phase:e,timeoutMs:t},o())},touchBody(){!r||!p.has(r.phase)||o()},suspend(){a=!0,i!==void 0&&clearTimeout(i),i=void 0},dispose(){r=void 0,i!==void 0&&clearTimeout(i),i=void 0}}}function g(e,n){return new t(`COMMAND_FAILED`,`Artifact transfer ${e} timed out`,{reason:m,transferPhase:e,timeoutMs:n})}function _(e){return e instanceof t&&e.details?.reason===m}function v(e,t){let n=!1,r=!1,i=!1,a,o,s=()=>{i||t.signal.aborted||!n||(r?t.arm(`response-headers`,d):t.arm(`request-body`,f))},c=()=>{n=!0,s()},l=e=>{if(!e.connecting){n=!0,s();return}a=e,o=e.encrypted===!0?`secureConnect`:`connect`,e.once(o,c)},u=()=>{r=!0,s()},p=()=>{i=!0,t.arm(`response-body`,f)};return e.on(`socket`,l),e.on(`finish`,u),e.prependListener(`response`,p),{get responseStarted(){return i},dispose(){e.off(`socket`,l),e.off(`finish`,u),e.off(`response`,p),a&&o&&a.off(o,c)}}}var y=e({TRANSFER_BODY_INACTIVITY_TIMEOUT_MS:()=>f,TRANSFER_CONNECT_TIMEOUT_MS:()=>u,TRANSFER_RESPONSE_HEADER_TIMEOUT_MS:()=>d,createTransferPhaseWatchdog:()=>h,isTransferPhaseTimeoutError:()=>_});export{i as a,a as c,s as d,o as f,d as i,v as l,f as n,h as o,c as p,u as r,_ as s,y as t,l as u};