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 • 2.19 kB
import{v as e}from"./sdk-contracts.js";import{q as t}from"./sdk-io.js";import{d as n}from"./scroll-gesture.js";import"./retry.js";import{r}from"./hdc.js";import{n as i,t as a}from"./snapshot3.js";async function o(e,t,n){await r(e,[`uitest`,`uiInput`,`click`,t,n])}async function s(e,t,n){await r(e,[`uitest`,`uiInput`,`doubleClick`,t,n])}async function c(e,t,n,i=800){await r(e,[`uitest`,`uiInput`,`longClick`,t,n])}async function l(e,n,i=0){await r(e,[`uitest`,`uiInput`,`text`,n]),i>0&&await t(i)}async function u(e,n,i,a,o=0){await r(e,[`uitest`,`uiInput`,`inputText`,n,i,a]),o>0&&await t(o)}async function d(e,t,a){let o=await i(e),s=n({direction:t,amount:a?.amount,pixels:a?.pixels,referenceWidth:o.width,referenceHeight:o.height});return await r(e,[`uitest`,`uiInput`,`swipe`,s.x1,s.y1,s.x2,s.y2,a?.durationMs??300]),s}async function f(t,n){if(n.topology!==`single`)throw new e(`UNSUPPORTED_OPERATION`,`HarmonyOS HDC does not support multi-touch gestures`);let i=n.pointers[0].samples,a=i[0],o=i.at(-1);if(!a||!o)throw new e(`COMMAND_FAILED`,`HarmonyOS gesture plan has no pointer endpoints`);let s=Math.hypot(o.point.x-a.point.x,o.point.y-a.point.y),c=Math.max(200,Math.min(4e4,Math.round(s/n.durationMs*1e3))),l=n.intent===`fling`?`fling`:`swipe`;return await r(t,[`uitest`,`uiInput`,l,Math.round(a.point.x),Math.round(a.point.y),Math.round(o.point.x),Math.round(o.point.y),c]),{backend:`harmonyos-hdc-uiinput`,command:l,velocity:c,viewport:n.viewport}}async function p(e){await r(e,[`uitest`,`uiInput`,`keyEvent`,`Back`]),a(e)}async function m(e){await r(e,[`uitest`,`uiInput`,`keyEvent`,`Home`]),a(e)}async function h(e){await r(e,[`uitest`,`uiInput`,`keyEvent`,`Recent`]),a(e)}async function g(e,t){if(t===`Back`){await p(e);return}await r(e,[`uitest`,`uiInput`,`keyEvent`,t])}async function _(t,n){throw new e(`UNSUPPORTED_OPERATION`,`HarmonyOS orientation control is not available through the public HDC API.`)}export{h as appSwitcherHarmony,p as backHarmony,s as doubleClickHarmony,u as fillHarmony,m as homeHarmony,c as longPressHarmony,f as performHarmonyGesture,o as pressHarmony,g as pressHarmonyKeyboardKey,d as scrollHarmony,_ as setHarmonyOrientation,l as typeHarmony};