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.

1 lines • 1.2 kB
import{F as e}from"./sdk-contracts.js";import{a as t,d as n,h as r,o as i}from"./adb-executor.js";import{_ as a,i as o,l as s}from"./ime-state.js";import{c,i as l,r as u}from"./ime-settings-record.js";async function d(u){let d=o(u);return d?await s(d.stateDir,u.id,async()=>{if(o(u)!==d)return{kind:`not-owned`};let s=t(u),{manifest:m}=await a(i(u));r({level:`warn`,phase:`android_test_ime_rebind`,data:{device:u.id}}),d.rebindUnconfirmed=!0;let h=`record-write`;try{if(!await c(s))return f(u.id,h);h=`command-failed`;for(let e of[`disable`,`enable`,`set`])if((await n(s,[`ime`,e,m.serviceComponent],{allowFailure:!0,timeoutMs:1e4})).exitCode!==0)return f(u.id,h);h=`read-failed`;let e=await l(s);return e===m.serviceComponent?(d.rebindUnconfirmed=!await p(s,u.id),{kind:`confirmed`}):f(u.id,e?`helper-not-selected`:`read-failed`)}catch(t){if(e(t))throw t}return f(u.id,h)}):{kind:`not-owned`}}function f(e,t){return r({level:`warn`,phase:`android_test_ime_rebind_failed`,data:{device:e,cause:t}}),{kind:`unconfirmed`,cause:t}}async function p(e,t){let n=await u(e);return n||r({level:`warn`,phase:`android_test_ime_rebind_record_clear_failed`,data:{device:t}}),n}export{d as rebindAndroidTestIme};