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.
319 lines • 12.3 kB
TypeScript
import { E as PlatformSelector, H as SnapshotPreferredBackend, Q as AppErrorDetails, X as AppError, Z as AppErrorCode, c as DaemonServerMode, f as LeaseBackend, g as ResponseLevel, l as DaemonTransportPreference, m as NetworkIncludeMode, r as DaemonInstallSource, v as SessionIsolationMode, w as DeviceTarget, x as BootPickPolicy, y as SessionRuntimeHints } from "./sdk-contracts.js";
import { y as ClickButton } from "./sdk-selectors.js";
import { F as BackMode, I as SessionSurface, M as SwipePattern, O as ScreenshotRequestFlags } from "./cloud-artifacts.js";
import { a as RecordingExportQuality, i as RecordingScope, n as ReplayScriptSourceBundle } from "./replay.js";
import { a as RemoteConfigProfile, i as RemoteConfigMetroOptions, r as CloudProviderProfileFields } from "./sdk-remote-config.js";
//#region packages/contracts/src/replay-request-fields.d.ts
/**
* The replay/test request vocabulary, declared once.
*
* `CliFlags` and `CommandExecutionOptions` are two views of the same request — the flags a CLI
* invocation parses and the options a programmatic call passes — and every replay/suite field
* appears in both. Stating them here keeps the two views from drifting field by field; each view
* adds only what is genuinely its own (`replayMaestro` and the reporter flags are CLI-side,
* `replayBackend` is the resolved engine the client sends).
*/
type ReplayRequestFields = {
replayUpdate?: boolean;
replayEnv?: string[];
replayShellEnv?: Record<string, string>;
/**
* #1802: the caller-read script text `replay` executes. The daemon never opens a caller path,
* so this is the ONLY source a replay run reads.
*/
replayScriptSource?: ReplayScriptSourceBundle;
/** #1802: `test`'s caller-side discovery result — one bundle per discovered source, in run order. */
replayScriptSources?: ReplayScriptSourceBundle[];
replayFrom?: number;
replayPlanDigest?: string;
/** Replay: leave the session active by suppressing an authored terminal close in native .ad. */
replayKeepSession?: boolean;
failFast?: boolean;
timeoutMs?: number;
retries?: number;
recordVideo?: boolean;
artifactsDir?: string;
shardAll?: number;
shardSplit?: number;
};
//#endregion
//#region packages/contracts/src/cli-flags.d.ts
type CliFlags = CloudProviderProfileFields & RemoteConfigMetroOptions & ScreenshotRequestFlags & ReplayRequestFields & {
json: boolean;
config?: string;
remoteConfig?: string;
stateDir?: string;
daemonBaseUrl?: string;
daemonAuthToken?: string;
daemonTransport?: DaemonTransportPreference;
daemonServerMode?: DaemonServerMode;
proxyHost?: string;
proxyPort?: number;
publicOrigin?: string;
mcpStructured?: boolean;
tenant?: string;
sessionIsolation?: SessionIsolationMode;
runId?: string;
leaseId?: string;
leaseBackend?: LeaseBackend;
provider?: string;
providerSessionId?: string;
force?: boolean;
clean?: boolean;
noLogin?: boolean;
kind?: string;
perfTemplate?: string;
sessionLock?: 'reject' | 'strip';
platform?: PlatformSelector;
target?: DeviceTarget;
device?: string;
udid?: string;
serial?: string;
osVersion?: string;
imageTag?: string;
deviceMode?: string;
deviceBaseline?: string;
physical?: boolean;
stale?: boolean;
iosSimulatorDeviceSet?: string;
iosXctestrunFile?: string;
iosXctestDerivedDataPath?: string;
iosXctestEnvDir?: string;
testIme?: boolean;
androidDeviceAllowlist?: string;
remote?: boolean;
session?: string;
targetApp?: string;
metroHost?: string;
metroPort?: number;
bundleUrl?: string;
launchUrl?: string;
verbose?: boolean;
cost?: boolean;
responseLevel?: ResponseLevel;
snapshotInteractiveOnly?: boolean;
/** Internal (no CLI flag): pin the capture backend for same-backend evidence probes. */
snapshotPreferredBackend?: SnapshotPreferredBackend;
snapshotDiff?: boolean;
snapshotDepth?: number;
snapshotScope?: string;
snapshotRaw?: boolean;
snapshotCustomActions?: boolean;
snapshotObserveOnly?: boolean;
snapshotForceFull?: boolean;
artifact?: string;
dsym?: string;
searchPath?: string;
networkInclude?: NetworkIncludeMode;
baseline?: string;
threshold?: string;
appsFilter?: 'user-installed' | 'all';
count?: number;
pointerCount?: number;
fps?: number;
quality?: RecordingExportQuality | string;
hideTouches?: boolean;
recordingScope?: RecordingScope;
intervalMs?: number;
delayMs?: number;
/** Fill: publish the live text as a late-bound ${VAR} in a recorded .ad script. */
recordAs?: string;
/** Fill: the text came from the CLI's stdin rather than argv; keep it out of logs and scripts. */
textStdin?: boolean;
durationMs?: number;
keyframes?: string;
holdMs?: number;
jitterPx?: number;
pixels?: number;
/** Scroll: repeat passes until this selector is visible on screen. */
until?: string;
maxPasses?: number;
doubleTap?: boolean;
verify?: boolean;
settle?: boolean;
settleQuietMs?: number;
postGestureStabilization?: boolean;
clickButton?: ClickButton;
backMode?: BackMode;
pauseMs?: number;
pattern?: SwipePattern;
activity?: string;
launchConsole?: string;
launchArgs?: string[];
header?: string[];
githubActionsArtifact?: string;
installSource?: DaemonInstallSource;
saveScript?: boolean | string;
shutdown?: boolean;
relaunch?: boolean;
foreground?: boolean;
surface?: SessionSurface;
headless?: boolean;
pick?: BootPickPolicy;
restart?: boolean;
noRecord?: boolean;
/**
* #1271 stage 2 (ADR 0012 amendment): opt-in that forces THIS action into
* a repair-armed heal even though its command is observation-only
* (`snapshot`/`get`/`is`/`find`) — the corrective-read case, where the
* diverged step's repair is itself a read. Mutually exclusive with
* `noRecord` (rejected as `INVALID_ARGS` if both are set); a no-op
* outside a repair-armed session and on any non-observation-only
* command.
*/
record?: boolean;
retainPaths?: boolean;
retentionMs?: number;
waitMs?: number;
replayMaestro?: boolean;
reporter?: string[];
reportJunit?: string;
steps?: string;
stepsFile?: string;
findFirst?: boolean;
findLast?: boolean;
batchOnError?: 'stop';
batchMaxSteps?: number;
batchSteps?: Array<{
command: string;
input: Record<string, unknown>;
runtime?: SessionRuntimeHints;
}>;
out?: string;
help: boolean;
version: boolean;
};
//#endregion
//#region packages/contracts/src/provider-connection.d.ts
type ProviderConnectionResource = {
status: 'verified' | 'configured' | 'deferred' | 'missing';
name?: string;
reference?: string;
platform?: 'android' | 'ios';
osVersion?: string;
version?: string;
availability?: string;
message?: string;
};
type ProviderConnectionVerification = {
provider: string;
service: string;
verificationMessage: string;
project?: {
name?: string;
reference: string;
};
device: ProviderConnectionResource;
app: ProviderConnectionResource;
};
type ConnectionProviderCapabilities = {
leaseKind: 'proxy' | 'direct-device-provider' | 'remote-provider';
requiresAppAttachment: boolean;
requiresRemoteDaemon: boolean;
supportsArtifacts: boolean;
supportsDeferredAppSelection: boolean;
supportsDirectPortReverse: boolean;
usesCloudWebDriverLease: boolean;
/**
* The provider leases a cloud-hosted device that bills while held. Its lease requests the same
* idle window as a proxy or cloud WebDriver lease on each lease-using command, not the daemon
* default.
*/
holdsCloudDevice?: boolean;
/** Clear a released connection lease so the next device command can allocate a replacement. */
forgetsEndedConnectionLease?: boolean;
};
//#endregion
//#region packages/plugins/src/host.d.ts
type ProviderPluginHost = Readonly<{
env: Readonly<Record<string, string | undefined>>;
options: Readonly<Record<string, unknown>>;
clientVersion: string;
createError(code: AppErrorCode, message: string, details?: AppErrorDetails): AppError;
}>;
//#endregion
//#region packages/plugins/src/contract.d.ts
/** The provider plugin contract version this module defines. */
declare const PROVIDER_PLUGIN_API_VERSION = 2;
/**
* The environment variables a plugin reads credentials from. The host fingerprints their values to
* refuse a lease when the shell holds different credentials than the daemon started with. List
* nothing for credentials the embedder passes as factory options.
*/
type PluginCredentials = Readonly<{
variables: readonly string[];
/** Narrows `variables` to what a lease on one backend reads, such as `android-instance`. */
byBackend?: Readonly<Record<string, readonly string[]>>;
}>;
type PluginConnectionContext = Readonly<{
flags: CliFlags;
stateDir: string;
cwd: string;
env: Readonly<Record<string, string | undefined>>;
/** The same host `setup` receives, built from this call's `env`; no runtime is set up. */
host: ProviderPluginHost;
}>;
type PluginConnectionResolution = {
profile: RemoteConfigProfile;
extraFlags?: Partial<CliFlags>;
};
/** What `agent-device connect <provider>` asks the plugin; the host owns the connection state. */
type PluginConnection = Readonly<{
/** Local provider capabilities; `requiresRemoteDaemon` must be false. */
capabilities: ConnectionProviderCapabilities;
resolve(context: PluginConnectionContext): Promise<PluginConnectionResolution> | PluginConnectionResolution;
verify(context: Pick<PluginConnectionContext, 'flags' | 'env' | 'host'>): Promise<ProviderConnectionVerification>;
}>;
/**
* The provider runtime a plugin builds. This type names only `provider` and `shutdown`; the host
* also requires `leaseLifecycle`, `ownsDevice`, `getInteractor` and `deviceInventoryProvider` from
* the provider runtime contract before it registers the runtime.
*/
type PluginProviderRuntime = Readonly<{
provider: string;
shutdown(): Promise<void>;
}>;
type PluginPlatformModule = Readonly<{
owner: Readonly<{
kind: 'provider-runtime';
provider: string;
instance: string;
}>;
loadRuntime(...args: never[]): Promise<unknown>;
}>;
/** A provider runtime the plugin builds itself. */
type PluginRuntimeSetup = Readonly<{
runtime: PluginProviderRuntime;
platformModule: PluginPlatformModule;
/** Called once when the daemon shuts the plugin down, after `runtime.shutdown()`. */
dispose?(): Promise<void> | void;
}>;
/** What the registry reads of a WebDriver descriptor; the composing root owns the rest. */
type WebDriverDescriptor = Readonly<{
provider: string;
}>;
/**
* A hosted WebDriver service. The host interprets the descriptor and builds the runtime; the
* descriptor's type belongs to the composing root, so this package never names a provider.
*/
type PluginWebDriverSetup<WebDriver extends WebDriverDescriptor = WebDriverDescriptor> = Readonly<{
webDriver: WebDriver;
dispose?(): Promise<void> | void;
}>;
type PluginSetupResult<WebDriver extends WebDriverDescriptor = WebDriverDescriptor> = PluginRuntimeSetup | PluginWebDriverSetup<WebDriver>;
type AgentDevicePlugin<WebDriver extends WebDriverDescriptor = WebDriverDescriptor> = Readonly<{
apiVersion: typeof PROVIDER_PLUGIN_API_VERSION;
/** Lowercase id; `cloud` and `proxy` are reserved routing identities. */
provider: string;
credentials: PluginCredentials;
connection?: PluginConnection;
/** Builds the runtime. Keep it free of network I/O and device allocation. */
setup(host: ProviderPluginHost): Promise<PluginSetupResult<WebDriver>> | PluginSetupResult<WebDriver>;
}>;
/**
* The default export of a plugin package's `./agent-device` entry. The store calls it with
* `config.json` `plugins[name].options`; a JS host calls it directly.
*/
type AgentDevicePluginFactory<Options = Record<string, unknown>, WebDriver extends WebDriverDescriptor = WebDriverDescriptor> = (options?: Options) => AgentDevicePlugin<WebDriver> | Promise<AgentDevicePlugin<WebDriver>>;
//#endregion
export { PluginConnectionResolution as a, PluginProviderRuntime as c, PluginWebDriverSetup as d, ProviderPluginHost as f, PluginConnectionContext as i, PluginRuntimeSetup as l, AgentDevicePluginFactory as n, PluginCredentials as o, PluginConnection as r, PluginPlatformModule as s, AgentDevicePlugin as t, PluginSetupResult as u };