@phone-use/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # @phone-use/sdk
2
+
3
+ Typed mobile-device SDK for AI agents: launch or connect to a device, observe
4
+ the screen as structured elements, and act on it with auto-waiting, verified
5
+ gestures. The engine-as-object API is deliberately Playwright-shaped —
6
+ `launch → observe → act → close`.
7
+
8
+ ## Quick start (iOS Simulator)
9
+
10
+ Requires macOS with Xcode (`xcrun simctl`) and an iOS Simulator runtime.
11
+ Node >= 22 or Bun.
12
+
13
+ ```ts
14
+ import { ios } from '@phone-use/sdk';
15
+
16
+ const device = await ios.launch(); // creates + boots a dedicated simulator
17
+ await device.apps.open('Settings');
18
+ const result = await device.tap('General'); // resolves by label, auto-waits, verifies
19
+ console.log(result.message, result.changed);
20
+ await device.close(); // shuts the sim down and deletes it
21
+ ```
22
+
23
+ Or with `await using` — the device closes itself at scope exit:
24
+
25
+ ```ts
26
+ import { ios } from '@phone-use/sdk';
27
+
28
+ await using device = await ios.connect(); // attach to the booted simulator
29
+ await device.apps.open('Settings');
30
+ console.log((await device.observe()).rendered);
31
+ ```
32
+
33
+ ## Platforms
34
+
35
+ **iOS Simulator today.** Android support lands with the android engine
36
+ (`android.launch()` / `android.connect()`) — the backend contract and config
37
+ union already carry the Android shape, but there is no working Android engine
38
+ in this release, so no example is shown.
39
+
40
+ ## Observe → act: portable actions
41
+
42
+ `device.observe()` returns structured elements plus portable `Action`
43
+ descriptors whose targets are **re-resolvable element queries** (id → exact
44
+ label → substring → fuzzy, with `role`/`near` disambiguators) — not stale
45
+ handles. `device.act(action)` re-resolves against the live screen and executes
46
+ deterministically, so a recorded `Action[]` replays with zero model calls.
47
+
48
+ Every verb auto-waits (target visible + enabled + screen settled) and returns
49
+ a structured `{ success, message, ... }` result instead of throwing for normal
50
+ outcomes like "not found" or "ambiguous — here are the candidates".
51
+
52
+ ## Errors
53
+
54
+ Infrastructure failures throw `PhoneUseError` subclasses, each with a stable
55
+ `code` and an explicit `retryable` flag:
56
+
57
+ | Error | `code` | `retryable` |
58
+ | --- | --- | --- |
59
+ | `DeviceNotFoundError` | `DEVICE_NOT_FOUND` | no |
60
+ | `DeviceInUseError` | `DEVICE_IN_USE` | yes |
61
+ | `SessionNotFoundError` | `SESSION_NOT_FOUND` | no |
62
+ | `TimeoutError` | `TIMEOUT` | yes |
63
+ | `ActionFailedError` | `ACTION_FAILED` | yes |
64
+ | `UnsupportedCapabilityError` | `UNSUPPORTED_CAPABILITY` | no |
65
+ | `AbortedError` | `ABORTED` | no |
66
+ | `PhoneUseError` (base) | `BACKEND_NOT_FOUND` / `UNKNOWN` | no |
67
+
68
+ No backend/transport error type ever crosses the public API — everything is
69
+ normalized at the boundary by `toPhoneUseError`.
70
+
71
+ ## `%name%` secrets
72
+
73
+ Store secret values on the device and reference them by name — values are
74
+ substituted only at the moment of typing, and redacted from results,
75
+ observations, and stored actions:
76
+
77
+ ```ts
78
+ device.secrets.set('password', process.env.APP_PASSWORD!);
79
+ await device.type('%password%', { field: 'Password', submit: true });
80
+ // result.message: 'filled "Password", pressed Return' — never the value
81
+ ```
82
+
83
+ ## Testing subpath
84
+
85
+ `@phone-use/sdk/testing` ships the device-free test doubles the SDK's own
86
+ suite runs on: `FakeBackend` (scripted snapshot screens, records every call),
87
+ `el`/`screen` fixture sugar, and `scriptedExecRunner` for lifecycle tests.
88
+
89
+ ```ts
90
+ import { FakeBackend, el, screen } from '@phone-use/sdk/testing';
91
+
92
+ const backend = new FakeBackend({ screens: [screen([el({ ref: '1', label: 'General' })])] });
93
+ ```
94
+
95
+ ## Stability
96
+
97
+ Pre-1.0: minor versions may break APIs. The `Action`/`CompiledSkill` *format*
98
+ (`formatVersion: 0`) is explicitly unstable — it cannot responsibly freeze
99
+ before both platforms exist. Pin exact versions.
100
+
101
+ ## License
102
+
103
+ Apache-2.0
@@ -0,0 +1,316 @@
1
+ //#region src/device.d.ts
2
+ /** Element geometry in screen points (same space as screenshot pixels at @1x). */
3
+ type Rect = {
4
+ x: number;
5
+ y: number;
6
+ width: number;
7
+ height: number;
8
+ };
9
+ /**
10
+ * One accessibility-tree node as reported by a backend snapshot. The SDK's own
11
+ * vocabulary — structurally compatible with agent-device's nodes but never
12
+ * importing its types (docs/20 item 2: no backend type in the public API).
13
+ */
14
+ type SnapshotNode = {
15
+ ref?: string | undefined;
16
+ type?: string | undefined;
17
+ role?: string | undefined;
18
+ label?: string | undefined;
19
+ value?: string | undefined;
20
+ identifier?: string | undefined;
21
+ enabled?: boolean | undefined;
22
+ selected?: boolean | undefined;
23
+ focused?: boolean | undefined;
24
+ interactionBlocked?: string | undefined;
25
+ rect?: Rect | undefined;
26
+ };
27
+ /** One backend snapshot: the node list plus the frontmost app when known. */
28
+ type Snapshot = {
29
+ nodes: SnapshotNode[];
30
+ appName?: string | undefined;
31
+ appBundleId?: string | undefined;
32
+ };
33
+ /** Scroll gesture direction. */
34
+ type ScrollDirection = 'up' | 'down' | 'left' | 'right';
35
+ /** A press target: an element ref from a snapshot, or raw screen coordinates. */
36
+ type PressTarget = {
37
+ ref: string;
38
+ } | {
39
+ x: number;
40
+ y: number;
41
+ };
42
+ /** What to do with a system alert: read it, accept it, or dismiss it. */
43
+ type AlertAction = 'get' | 'accept' | 'dismiss';
44
+ /** Raw result of a backend's system-alert command. */
45
+ type BackendAlertResult = {
46
+ alert?: {
47
+ title?: string | undefined;
48
+ message?: string | undefined;
49
+ buttons?: string[] | undefined;
50
+ } | null | undefined;
51
+ handled?: boolean | undefined;
52
+ button?: string | undefined;
53
+ };
54
+ /** What a backend reports after opening an app or URL. */
55
+ type OpenAppResult = {
56
+ appName?: string | undefined;
57
+ appBundleId?: string | undefined;
58
+ };
59
+ /** A backend feature a caller can query via `backend.capabilities`. */
60
+ type Capability = 'snapshot' | 'screenshot' | 'press' | 'longPress' | 'fill' | 'type' | 'key' | 'scroll' | 'pan' | 'waitForText' | 'alert' | 'home' | 'back' | 'openApp' | 'openUrl' | 'listApps' | 'closeSession';
61
+ /** Every capability — what a full backend (agent-device iOS) declares. */
62
+ declare const ALL_CAPABILITIES: readonly Capability[];
63
+ //#endregion
64
+ //#region src/errors.d.ts
65
+ /**
66
+ * Stable machine-readable error codes carried by every {@link PhoneUseError}.
67
+ *
68
+ * Codes are deliberately string-identical to agent-device's where a concept
69
+ * maps 1:1 (DEVICE_NOT_FOUND, SESSION_NOT_FOUND, ...) so existing harness
70
+ * checks like `(e as {code?: string}).code === 'SESSION_NOT_FOUND'` keep
71
+ * working unchanged across the normalization boundary.
72
+ */
73
+ type PhoneUseErrorCode = 'DEVICE_NOT_FOUND' | 'DEVICE_IN_USE' | 'SESSION_NOT_FOUND' | 'TIMEOUT' | 'ACTION_FAILED' | 'UNSUPPORTED_CAPABILITY' | 'BACKEND_NOT_FOUND' | 'ABORTED' | 'UNKNOWN';
74
+ /** Structured, code-specific context attached to a {@link PhoneUseError}. */
75
+ type PhoneUseErrorDetails = Record<string, unknown> & {
76
+ /** Preserved from agent-device details.hint — describeError renders it. */
77
+ hint?: string | undefined;
78
+ /** The raw backend code when we collapse to ACTION_FAILED. */
79
+ backendCode?: string | undefined;
80
+ };
81
+ /**
82
+ * Root of the typed error tree (docs/19 §Artifacts, errors; docs/20 item 2).
83
+ * Every backend method rejects only with PhoneUseError subclasses; agent-device
84
+ * (or any transport) errors are normalized at the boundary by
85
+ * {@link toPhoneUseError} so no backend type ever reaches the public API. Each
86
+ * error carries a stable `code` and an explicit `retryable` flag — the field
87
+ * agent loops need to decide retry-vs-replan.
88
+ */
89
+ declare class PhoneUseError extends Error {
90
+ /** Stable machine-readable code — the field to branch on. */
91
+ readonly code: PhoneUseErrorCode;
92
+ /** Whether retrying the same call can plausibly succeed. */
93
+ readonly retryable: boolean;
94
+ /** Optional structured context (hint, raw backend code, ...). */
95
+ readonly details?: PhoneUseErrorDetails | undefined;
96
+ constructor(message: string, opts: {
97
+ code: PhoneUseErrorCode;
98
+ retryable: boolean;
99
+ details?: PhoneUseErrorDetails | undefined;
100
+ cause?: unknown;
101
+ });
102
+ }
103
+ /** No device matched the selection (`DEVICE_NOT_FOUND`, not retryable). */
104
+ declare class DeviceNotFoundError extends PhoneUseError {
105
+ constructor(message: string, opts?: {
106
+ details?: PhoneUseErrorDetails | undefined;
107
+ cause?: unknown;
108
+ });
109
+ }
110
+ /** The device is held by another session (`DEVICE_IN_USE`, retryable). */
111
+ declare class DeviceInUseError extends PhoneUseError {
112
+ constructor(message: string, opts?: {
113
+ details?: PhoneUseErrorDetails | undefined;
114
+ cause?: unknown;
115
+ });
116
+ }
117
+ /** No live session — the device/session was closed (`SESSION_NOT_FOUND`, not retryable). */
118
+ declare class SessionNotFoundError extends PhoneUseError {
119
+ constructor(message: string, opts?: {
120
+ details?: PhoneUseErrorDetails | undefined;
121
+ cause?: unknown;
122
+ });
123
+ }
124
+ /** A deadline elapsed before the operation completed (`TIMEOUT`, retryable). */
125
+ declare class TimeoutError extends PhoneUseError {
126
+ constructor(message: string, opts?: {
127
+ details?: PhoneUseErrorDetails | undefined;
128
+ cause?: unknown;
129
+ });
130
+ }
131
+ /** A device action failed to execute (`ACTION_FAILED`, retryable). */
132
+ declare class ActionFailedError extends PhoneUseError {
133
+ constructor(message: string, opts?: {
134
+ details?: PhoneUseErrorDetails | undefined;
135
+ cause?: unknown;
136
+ });
137
+ }
138
+ /** The backend does not implement the capability (`UNSUPPORTED_CAPABILITY`, not retryable). */
139
+ declare class UnsupportedCapabilityError extends PhoneUseError {
140
+ /** The backend that rejected the call. */
141
+ readonly backend: string;
142
+ /** The missing capability. */
143
+ readonly capability: string;
144
+ constructor(opts: {
145
+ backend: string;
146
+ capability: string;
147
+ cause?: unknown;
148
+ });
149
+ }
150
+ /**
151
+ * The caller's AbortSignal fired (`ABORTED`, not retryable). Abort is caller
152
+ * control flow, not a device outcome — never retried.
153
+ */
154
+ declare class AbortedError extends PhoneUseError {
155
+ constructor(message?: string, opts?: {
156
+ cause?: unknown;
157
+ });
158
+ }
159
+ /**
160
+ * Boundary normalizer: ANY thrown value → PhoneUseError. agent-device AppError
161
+ * codes map per the table below; an existing PhoneUseError passes through
162
+ * untouched; unknown values wrap as UNKNOWN (not retryable). The original
163
+ * error always rides on `cause`; details (including hint) are preserved.
164
+ */
165
+ declare function toPhoneUseError(err: unknown, ctx?: {
166
+ backend?: string;
167
+ capability?: string;
168
+ }): PhoneUseError;
169
+ //#endregion
170
+ //#region src/config.d.ts
171
+ /** Fields shared by every platform's device config (session/daemon pinning). */
172
+ type CommonDeviceConfig = {
173
+ /** agent-device session name pinning. */
174
+ session?: string | undefined;
175
+ /** Remote daemon endpoint (API surface reserved; local-only this cycle). */
176
+ daemonBaseUrl?: string | undefined;
177
+ daemonAuthToken?: string | undefined;
178
+ };
179
+ /** iOS device selection: pin by udid, name match, or custom device set. */
180
+ type IosDeviceConfig = CommonDeviceConfig & {
181
+ platform: 'ios';
182
+ /** Pin a specific simulator/device by udid. */
183
+ udid?: string | undefined;
184
+ /** Name match, e.g. "iPhone 16". */
185
+ device?: string | undefined;
186
+ /** Custom simulator device set directory. */
187
+ simulatorDeviceSet?: string | undefined;
188
+ };
189
+ /** Android device selection: pin by adb serial or name match. */
190
+ type AndroidDeviceConfig = CommonDeviceConfig & {
191
+ platform: 'android';
192
+ /** Pin a specific device/emulator by adb serial. */
193
+ serial?: string | undefined;
194
+ /** Name match. */
195
+ device?: string | undefined;
196
+ };
197
+ /**
198
+ * Device configuration: a discriminated union on `platform`, never a
199
+ * stringly-typed capability blob (docs/19 §Backend contract, learning from
200
+ * Appium's leaks). Plain types — no zod in the SDK public API.
201
+ */
202
+ type DeviceConfig = IosDeviceConfig | AndroidDeviceConfig;
203
+ //#endregion
204
+ //#region src/backend.d.ts
205
+ /**
206
+ * The backend contract (docs/19 §Backend contract): a STRUCTURAL interface —
207
+ * any object with these methods is a backend — plus an optional
208
+ * {@link BaseDeviceBackend} class with the plumbing done (Appium BaseDriver
209
+ * ergonomics). Methods reject only with PhoneUseError subclasses; backends
210
+ * normalize their transport's errors at the boundary.
211
+ */
212
+ interface DeviceBackend {
213
+ /** Stable backend identifier, e.g. `"agent-device"`. */
214
+ readonly backendName: string;
215
+ /** The capabilities this backend actually implements. */
216
+ readonly capabilities: ReadonlySet<Capability>;
217
+ /** Capture the accessibility tree of the frontmost app. */
218
+ snapshot(opts?: {
219
+ interactiveOnly?: boolean | undefined;
220
+ depth?: number | undefined;
221
+ }): Promise<Snapshot>;
222
+ /** Save a screenshot to `path` (optionally with `@ref` overlays drawn). */
223
+ screenshot(opts: {
224
+ path: string;
225
+ overlayRefs?: boolean | undefined;
226
+ }): Promise<{
227
+ path: string;
228
+ }>;
229
+ /** Tap an element ref or raw coordinates. */
230
+ press(target: PressTarget): Promise<void>;
231
+ /** Long-press an element ref. */
232
+ longPress(ref: string, durationMs?: number): Promise<void>;
233
+ /** Focus an element and replace its text. */
234
+ fill(ref: string, text: string): Promise<void>;
235
+ /** Type into whatever currently has keyboard focus. */
236
+ typeText(text: string): Promise<void>;
237
+ /** Press a hardware/keyboard key (Return only, this cycle). */
238
+ pressKey(key: 'return'): Promise<void>;
239
+ /** Scroll the active scroll view one step. */
240
+ scroll(direction: ScrollDirection): Promise<void>;
241
+ /** Coordinate drag: touch down at (x,y), move by (dx,dy). Operates picker wheels, sliders, carousels. */
242
+ pan(x: number, y: number, dx: number, dy: number, durationMs?: number): Promise<void>;
243
+ /** Block until `text` appears on screen or the timeout elapses. */
244
+ waitForText(text: string, timeoutMs?: number): Promise<void>;
245
+ /** Read/accept/dismiss the app's own alert via the transport's alert command. */
246
+ systemAlert(action: AlertAction): Promise<BackendAlertResult>;
247
+ /** Go to the home screen. */
248
+ home(): Promise<void>;
249
+ /** Navigate back (hardware back / nav-bar back). */
250
+ back(): Promise<void>;
251
+ /** Open an app by name/bundle id, or a URL (deep link). */
252
+ openApp(opts: {
253
+ app?: string | undefined;
254
+ url?: string | undefined;
255
+ relaunch?: boolean | undefined;
256
+ }): Promise<OpenAppResult>;
257
+ /** List installed app bundle ids. */
258
+ listApps(): Promise<string[]>;
259
+ /** Close the transport session (idempotent; safe when none is open). */
260
+ closeSession(): Promise<void>;
261
+ }
262
+ /**
263
+ * Optional plumbing base: every method rejects with a typed
264
+ * UnsupportedCapabilityError until overridden. Subclasses declare their
265
+ * capability set and override exactly what they support.
266
+ */
267
+ declare abstract class BaseDeviceBackend implements DeviceBackend {
268
+ readonly backendName: string;
269
+ readonly capabilities: ReadonlySet<Capability>;
270
+ protected constructor(backendName: string, capabilities: Iterable<Capability>);
271
+ protected unsupported(capability: Capability): UnsupportedCapabilityError;
272
+ /** Throws UnsupportedCapabilityError unless this backend declares `capability`. */
273
+ requireCapability(capability: Capability): void;
274
+ snapshot(_opts?: {
275
+ interactiveOnly?: boolean | undefined;
276
+ depth?: number | undefined;
277
+ }): Promise<Snapshot>;
278
+ screenshot(_opts: {
279
+ path: string;
280
+ overlayRefs?: boolean | undefined;
281
+ }): Promise<{
282
+ path: string;
283
+ }>;
284
+ press(_target: PressTarget): Promise<void>;
285
+ longPress(_ref: string, _durationMs?: number): Promise<void>;
286
+ fill(_ref: string, _text: string): Promise<void>;
287
+ typeText(_text: string): Promise<void>;
288
+ pressKey(_key: 'return'): Promise<void>;
289
+ scroll(_direction: ScrollDirection): Promise<void>;
290
+ pan(_x: number, _y: number, _dx: number, _dy: number, _durationMs?: number): Promise<void>;
291
+ waitForText(_text: string, _timeoutMs?: number): Promise<void>;
292
+ systemAlert(_action: AlertAction): Promise<BackendAlertResult>;
293
+ home(): Promise<void>;
294
+ back(): Promise<void>;
295
+ openApp(_opts: {
296
+ app?: string | undefined;
297
+ url?: string | undefined;
298
+ relaunch?: boolean | undefined;
299
+ }): Promise<OpenAppResult>;
300
+ listApps(): Promise<string[]>;
301
+ closeSession(): Promise<void>;
302
+ }
303
+ /** Builds a backend from an optional {@link DeviceConfig}. */
304
+ type BackendFactory = (config?: DeviceConfig) => DeviceBackend | Promise<DeviceBackend>;
305
+ /**
306
+ * Register a backend factory under a unique name (the `phone-backend-*`
307
+ * convention for third parties). Throws if the name is already taken.
308
+ */
309
+ declare function registerBackend(name: string, factory: BackendFactory): void;
310
+ /** Look up a registered factory by name; throws `BACKEND_NOT_FOUND` if absent. */
311
+ declare function getBackendFactory(name: string): BackendFactory;
312
+ /** Names of every registered backend, in registration order. */
313
+ declare function listBackends(): string[];
314
+ //#endregion
315
+ export { Snapshot as A, AlertAction as C, PressTarget as D, OpenAppResult as E, Rect as O, ALL_CAPABILITIES as S, Capability as T, PhoneUseErrorDetails as _, listBackends as a, UnsupportedCapabilityError as b, CommonDeviceConfig as c, AbortedError as d, ActionFailedError as f, PhoneUseErrorCode as g, PhoneUseError as h, getBackendFactory as i, SnapshotNode as j, ScrollDirection as k, DeviceConfig as l, DeviceNotFoundError as m, BaseDeviceBackend as n, registerBackend as o, DeviceInUseError as p, DeviceBackend as r, AndroidDeviceConfig as s, BackendFactory as t, IosDeviceConfig as u, SessionNotFoundError as v, BackendAlertResult as w, toPhoneUseError as x, TimeoutError as y };
316
+ //# sourceMappingURL=backend-Cbr2tIN-.d.mts.map