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.

3 lines • 4.96 kB
import{r as e}from"./rolldown-runtime.js";import{ft as t}from"./sdk-io.js";import{a as n}from"./version.js";import"./command.js";import{_ as r}from"./adb-executor.js";import{i,o as a,r as o}from"./adb-transport.js";import"./mechanics.js";import"./platform-runtime-android-adb-host.js";import{t as s}from"./await-with-signal.js";import{r as c}from"./scoped-provider.js";import{n as l}from"./android2.js";const u=1048576;function d(e){let t=new AbortController,n,r=new Set,i,a,o=[],c=0,l=e=>{for(o.push(e),c+=Buffer.byteLength(e)+1;c>u&&o.length;)c-=Buffer.byteLength(o.shift())+1},d=()=>{let e=n;n=void 0,e?.controller.abort();for(let t of e?.streams??[])t.stop()},p=i=>{let o={app:i,controller:new AbortController,streams:[]};n=o;let s=AbortSignal.any([t.signal,o.controller.signal]),c=e.client.streamAppLog(i);o.streams.push(c);let d=e.client.streamSyslog();o.streams.push(d);let p,m=!1,h=[],g=0;c.on(`line`,e=>{n===o&&l(e)}),d.on(`line`,e=>{if(n===o){if(m)f(e,i,p)&&l(e);else for(h.push(e),g+=Buffer.byteLength(e)+1;g>u&&h.length;)g-=Buffer.byteLength(h.shift())+1}});for(let e of o.streams)e.on(`error`,e=>{n===o&&(a=e)}),e.on(`close`,()=>{!t.signal.aborted&&n===o&&(a=Error(`Limrun log stream closed`))});let _=(async()=>{try{let{readLimrunAppInfo:t}=await import(`./limrun-ios-files.js`).then(e=>e.n),r=await t(e,i,s);if(n!==o)return;p=typeof r?.CFBundleExecutable==`string`?r.CFBundleExecutable:void 0,m=!0;for(let e of h)f(e,i,p)&&l(e)}catch(e){!s.aborted&&n===o&&(a=e instanceof Error?e:Error(String(e)))}finally{h.length=0}})();r.add(_),_.finally(()=>r.delete(_))};return{readLogs:async(r,u,f)=>{let m=AbortSignal.any([t.signal,f]);if(m.throwIfAborted(),a){let e=a;throw a=void 0,d(),e}if(n?.app!==r){d(),i!==r&&(o.length=0,c=0,i=r);try{let t=await s(e.client.appLogTail(r,u),m);o.length=0,c=0;for(let e of t.split(` `))e&&l(e);p(r)}catch(e){throw d(),e}}return o.slice(-u).join(` `)},[Symbol.asyncDispose]:async()=>{t.abort(),d(),await Promise.all(r)}}}function f(e,t,n){let r=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ \S+ (.+?)\[\d+(?::[^\]]+)?\](?: \(([^)]*)\))?/.exec(e);if(!r)return!1;let[,i,a]=r;return a===t||a?.startsWith(`${t}.`)===!0||i===n||i?.toLowerCase()===t.toLowerCase()}var p=e({createLimrunRuntimeDependencies:()=>m});function m(e){let s=n=>t({host:e,requestEnv:void 0},n);return{clientVersion:n(),android:{bindPerformance:async(e,t,n,r)=>{let{createAndroidPerfOperations:i,withAndroidAdbProvider:a}=await import(`./mechanics.js`).then(e=>e.r),o=c({...n},n=>s(()=>a(t,{serial:e.id},n))),{perfFrames:l,perfMemorySample:u,perfMemorySnapshot:d}=await i({device:e,owner:r,resolveHost:()=>o});return{perfFrames:l,perfMemorySample:u,perfMemorySnapshot:d}},bindDeployment:async(e,t,n)=>{let{createAndroidAppDeploymentOperations:r,withAndroidAdbProvider:i}=await import(`./mechanics.js`).then(e=>e.r),a=await r({...n,device:e});return c({...a},n=>s(()=>i(t,{serial:e.id},n)))},createInteractor:(e,t)=>c(l(e,t),s),createPortReverse:async(e,t)=>{let{createAndroidPortReverseManager:n}=await import(`./mechanics.js`).then(e=>e.r);return n(e,t)},inferAppName:async e=>{let{inferAndroidAppName:t}=await import(`./mechanics.js`).then(e=>e.r);return t(e)},listApps:async(e,t)=>{let{listAndroidAppsWithAdb:n}=await import(`./mechanics.js`).then(e=>e.r);return(await n(e,{filter:t,target:`mobile`})).map(e=>({id:e.package,name:e.name}))},getForegroundApp:async(e,t,n)=>{let{getAndroidAppStateWithAdb:r}=await import(`./platform-runtime2.js`),i=await r(async(e,r)=>await t(e,{...r,signal:n}),n);return i.package?{appId:i.package,activity:i.activity}:void 0},getKeyboardState:async e=>{let{getAndroidKeyboardStatusWithAdb:t}=await import(`./mechanics.js`).then(e=>e.r);return await t(e)},dismissKeyboard:async e=>{let{dismissAndroidKeyboardWithAdb:t}=await import(`./mechanics.js`).then(e=>e.r);return await t(e)},readLogs:async(e,t)=>{let{captureAndroidLogcatWithAdb:n}=await import(`./mechanics.js`).then(e=>e.r);return await n(e,{lines:t,timeoutMs:5e3})},forceStopApp:async(e,t,n)=>{let{runAdbShell:r}=await import(`./mechanics.js`).then(e=>e.r);await r(async(t,r)=>await e(t,{...r,signal:n}),[`am`,`force-stop`,t],{allowFailure:!0})},deviceAdbInvocation:(e,t)=>i(a(e),t),hostAdbInvocation:e=>i(o(),e),adbError:async(e,t,n)=>{let{androidAdbResultError:r,serializeAndroidAdbInvocation:i}=await import(`./mechanics.js`).then(e=>e.r);return r(e,t,n?{command:`adb ${i(n).join(` `)}`}:void 0)}},host:c({runAdb:async(e,t)=>await r(e,t),downloadFile:async e=>{let{downloadLimrunFile:t}=await import(`./limrun-download-file.js`).then(e=>e.n);await t(e)}},s),ios:{createAppLogReader:d,...c({createRunner:async t=>{let{createLimrunIosRunner:n}=await import(`./limrun-ios-runner.js`),{createAppleApplicationTools:r}=await import(`./platform-runtime-apple-application-tools.js`);return n(t,e,r(e.env))},readBundleAppName:async e=>{let{readIosBundleInfo:t}=await import(`./install-artifact-facade.js`);return(await t(e)).appName}},s)}}}export{p as n,m as t};