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.

224 lines • 9.53 kB
import { F as Rect } from "./sdk-contracts.js"; import { a as MultiTouchGesturePlan, c as SinglePointerGesturePlan, n as KeyboardReturnKey, o as PointerTrajectory, s as PointerTrajectorySample } from "./keyboard.js"; import { Readable, Stream, Writable } from "node:stream"; //#region packages/platform-android/src/helper-artifacts.d.ts type AndroidImeHelperManifest = { name: 'android-ime-helper'; version: string; assetName: string; sha256: string; packageName: string; versionCode: number; serviceComponent: string; broadcastProtocol: 'android-ime-helper-v1'; }; type AndroidImeHelperArtifact = { apkPath: string; manifest: AndroidImeHelperManifest; }; type AndroidSnapshotHelperManifest = { name: 'android-snapshot-helper'; version: string; releaseTag?: string; assetName?: string; apkUrl: string | null; sha256: string; checksumName?: string; packageName: string; versionCode: number; instrumentationRunner: string; minSdk: number; targetSdk?: number; outputFormat: 'uiautomator-xml'; statusProtocol: 'android-snapshot-helper-v1'; }; type AndroidSnapshotHelperArtifact = { apkPath: string; manifest: AndroidSnapshotHelperManifest; }; //#endregion //#region packages/platform-android/src/touch-plan-lowering.d.ts type AndroidLongPressTouchPlan = { topology: 'single'; intent: 'longPress'; durationMs: number; pointers: readonly [PointerTrajectory]; }; /** * Transport samples are strictly denser than the canonical endpoint pair, so the shared plan a * command builds cannot satisfy the transport types: skipping the lowering below is a type error * at every injection seam rather than a silently sparse gesture. */ type AndroidTransportSamples = readonly [PointerTrajectorySample, PointerTrajectorySample, PointerTrajectorySample, ...PointerTrajectorySample[]]; type AndroidTransportSinglePointerTrajectory = { pointerId: 0; samples: AndroidTransportSamples; }; type AndroidTransportSinglePointerGesturePlan = Omit<SinglePointerGesturePlan, 'pointers'> & { pointers: readonly [AndroidTransportSinglePointerTrajectory]; }; type AndroidTransportGesturePlan = AndroidTransportSinglePointerGesturePlan | MultiTouchGesturePlan; type AndroidProviderTouchPlan = AndroidTransportGesturePlan | (AndroidLongPressTouchPlan & { viewport: Rect; }); //#endregion //#region packages/platform-android/src/adb-transport.d.ts type AndroidAdbExecutorOptions = { allowFailure?: boolean; timeoutMs?: number; binaryStdout?: boolean; stdin?: string | Buffer; signal?: AbortSignal; env?: Record<string, string | undefined>; serverPort?: number; }; type AndroidAdbExecutorResult = { exitCode: number; stdout: string; stderr: string; stdoutBuffer?: Buffer; /** The signal that ended the process, when one did. */ signal?: string; }; /** Structural mirror of node's StdioOptions; R13 bars the child_process import that names it. */ type AndroidAdbStdioOption = 'overlapped' | 'pipe' | 'ignore' | 'inherit'; /** * A spawned adb process is long-lived — the snapshot helper session rides it for the whole session * — so `timeoutMs` is not part of its options: background spawns arm no deadline, and a field that * looked like one invited callers to kill their own helper. */ type AndroidAdbSpawnOptions = Omit<AndroidAdbExecutorOptions, 'timeoutMs'> & { cwd?: string; detached?: boolean; /** Max stdout/stderr bytes for synchronous runs (default Node ~1MB). */ maxBuffer?: number; stdio?: AndroidAdbStdioOption | Array<AndroidAdbStdioOption | 'ipc' | Stream | number | null | undefined>; /** * Capture stdout/stderr into the wait result when the child has piped stdio. * Set false when the caller owns, ignores, or forwards the streams. */ captureOutput?: boolean; }; type AndroidAdbProcess = { pid?: number; exitCode?: number | null; signalCode?: NodeJS.Signals | null; stdin: Writable | null; stdout: Readable | null; stderr: Readable | null; killed: boolean; kill(signal?: NodeJS.Signals | number): boolean; once(event: 'exit' | 'close', listener: (code: number | null, signal: NodeJS.Signals | null) => void): unknown; on(event: 'error', listener: (error: Error) => void): unknown; on(event: 'exit' | 'close', listener: (code: number | null, signal: NodeJS.Signals | null) => void): unknown; }; /** * Runs device-scoped adb arguments after the device serial has already been selected. * Implementations must be safe to call concurrently for one request. */ type AndroidAdbExecutor = (args: readonly string[], options?: AndroidAdbExecutorOptions) => Promise<AndroidAdbExecutorResult>; type AndroidAdbSpawner = (args: readonly string[], options?: AndroidAdbSpawnOptions) => AndroidAdbProcess; type AndroidPortReverseEndpoint = `tcp:${number}` | `localabstract:${string}`; type AndroidPortReverseMapping = { local: AndroidPortReverseEndpoint; remote: AndroidPortReverseEndpoint; ownerId?: string; }; type AndroidPortReverseOptions = { signal?: AbortSignal; timeoutMs?: number; }; type AndroidPortReverseProvider = { ensure(mapping: AndroidPortReverseMapping, options?: AndroidPortReverseOptions): Promise<void>; remove(local: AndroidPortReverseEndpoint, options?: AndroidPortReverseOptions): Promise<void>; removeAllOwned(ownerId: string, options?: AndroidPortReverseOptions): Promise<void>; list?(options?: AndroidPortReverseOptions): Promise<AndroidPortReverseMapping[]>; }; type AndroidAdbTransferOptions = AndroidAdbExecutorOptions; type AndroidAdbInstallOptions = AndroidAdbTransferOptions & { replace?: boolean; }; type AndroidAdbPuller = (remotePath: string, localPath: string, options?: AndroidAdbTransferOptions) => Promise<AndroidAdbExecutorResult>; /** * Installs an APK path. Implementations are responsible for honoring the * semantic `replace` option (`adb install -r`). */ type AndroidAdbInstaller = (apkPath: string, options?: AndroidAdbInstallOptions) => Promise<AndroidAdbExecutorResult>; type AndroidBundleInstaller = (bundlePath: string, options: Readonly<{ mode: string; signal?: AbortSignal; timeoutMs?: number; }>) => Promise<void>; type AndroidTextInputAction = 'type' | 'fill'; type AndroidTextInjectionRequest = { action: AndroidTextInputAction; text: string; delayMs?: number; /** * Present only for fill. Providers must make this target the focused input AND replace its * contents with `text`, not inject into an unrelated currently focused field and not insert at * its cursor. An empty `text` is the clear request: the target must end up empty, and the * provider may complete it without any text-set call of its own. */ target?: { x: number; y: number; }; }; type AndroidTextInjector = (request: AndroidTextInjectionRequest) => Promise<void>; type AndroidTouchInjector = (request: AndroidProviderTouchPlan) => Promise<Record<string, unknown> | void>; type AndroidGestureViewportProvider = () => Promise<Rect>; type AndroidAdbProviderBase = { /** * Fallback executor for device-scoped adb arguments. Providers may omit explicit * methods to keep the legacy exec-shaped pull/install fallback. */ exec: AndroidAdbExecutor; spawn?: AndroidAdbSpawner; reverse?: AndroidPortReverseProvider; pull?: AndroidAdbPuller; install?: AndroidAdbInstaller; installBundle?: AndroidBundleInstaller; text?: AndroidTextInjector; snapshotHelperArtifact?: AndroidSnapshotHelperArtifact; imeHelperArtifact?: AndroidImeHelperArtifact; }; type AndroidTouchCapabilities = { touch?: never; gestureViewport?: never; } | { touch: AndroidTouchInjector; gestureViewport: AndroidGestureViewportProvider; }; type AndroidAdbProvider = AndroidAdbProviderBase & AndroidTouchCapabilities; //#endregion //#region packages/contracts/src/android-input-ownership.d.ts type AndroidInputOwner = 'app' | 'ime' | 'unknown'; //#endregion //#region packages/platform-android/src/device-input-state.d.ts type AndroidKeyboardType = 'text' | 'number' | 'email' | 'phone' | 'password' | 'datetime' | 'unknown'; type AndroidKeyboardState = { visible: boolean; inputType?: string; type?: AndroidKeyboardType; inputMethodPackage?: string; focusedPackage?: string; focusedResourceId?: string; inputOwner: AndroidInputOwner; /** What the current editor's return key offers; absent when the keyboard is not visible. */ returnKey?: KeyboardReturnKey; /** The editor's own custom action label, with its surrounding whitespace trimmed; absent when the * editor names none. */ returnKeyLabel?: string; }; type AndroidKeyboardDismissResult = AndroidKeyboardState & { attempts: number; wasVisible: boolean; dismissed: boolean; }; declare function getAndroidKeyboardStatusWithAdb(adb: AndroidAdbExecutor): Promise<AndroidKeyboardState>; declare function dismissAndroidKeyboardWithAdb(adb: AndroidAdbExecutor): Promise<AndroidKeyboardDismissResult>; declare function readAndroidClipboardWithAdb(adb: AndroidAdbExecutor): Promise<string>; declare function writeAndroidClipboardWithAdb(adb: AndroidAdbExecutor, text: string): Promise<void>; //#endregion export { readAndroidClipboardWithAdb as a, AndroidAdbExecutor as c, AndroidAdbProvider as d, AndroidPortReverseEndpoint as f, getAndroidKeyboardStatusWithAdb as i, AndroidAdbExecutorOptions as l, AndroidTextInjectionRequest as m, AndroidKeyboardState as n, writeAndroidClipboardWithAdb as o, AndroidPortReverseProvider as p, dismissAndroidKeyboardWithAdb as r, AndroidInputOwner as s, AndroidKeyboardDismissResult as t, AndroidAdbExecutorResult as u };