@phone-use/sdk 0.4.1 → 0.5.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/dist/index.d.mts +345 -136
- package/dist/index.mjs +934 -232
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/backends/android-hierarchy.ts +153 -0
- package/src/backends/android.ts +890 -0
- package/src/backends/cloud-sandbox.ts +42 -1
- package/src/index.ts +17 -2
- package/src/lifecycle.ts +3 -3
|
@@ -42,7 +42,18 @@ export type SandboxRpcMethod =
|
|
|
42
42
|
| 'back'
|
|
43
43
|
| 'openApp'
|
|
44
44
|
| 'listApps'
|
|
45
|
-
| 'closeSession'
|
|
45
|
+
| 'closeSession'
|
|
46
|
+
| 'checkpoint'
|
|
47
|
+
| 'restoreCheckpoint'
|
|
48
|
+
| 'listCheckpoints'
|
|
49
|
+
| 'deleteCheckpoint';
|
|
50
|
+
|
|
51
|
+
/** One saved device state, as reported by the worker. */
|
|
52
|
+
export type SandboxCheckpointInfo = {
|
|
53
|
+
id: string;
|
|
54
|
+
label?: string | undefined;
|
|
55
|
+
createdAt: string;
|
|
56
|
+
};
|
|
46
57
|
|
|
47
58
|
/** Body of `POST <endpoint>/rpc`: one verb and its positional arguments. */
|
|
48
59
|
export type SandboxRpcRequest = { method: SandboxRpcMethod; args: unknown[] };
|
|
@@ -162,6 +173,36 @@ export class CloudSandboxBackend extends BaseDeviceBackend {
|
|
|
162
173
|
return this.rpc('closeSession');
|
|
163
174
|
}
|
|
164
175
|
|
|
176
|
+
// -------------------------------------------------------------------------
|
|
177
|
+
// Checkpoints: save/restore the WHOLE device state (apps, logins, photos,
|
|
178
|
+
// settings). Not a UI snapshot — see `snapshot` for the accessibility tree.
|
|
179
|
+
// The device is briefly unavailable while a checkpoint saves or restores
|
|
180
|
+
// (shutdown → clone → boot on the worker); verbs issued meanwhile fail and
|
|
181
|
+
// should be retried after the checkpoint call resolves.
|
|
182
|
+
// -------------------------------------------------------------------------
|
|
183
|
+
|
|
184
|
+
/** Save the device's current state. Returns the checkpoint's id. */
|
|
185
|
+
checkpoint(opts?: { label?: string }): Promise<SandboxCheckpointInfo> {
|
|
186
|
+
return this.rpc('checkpoint', opts);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Restore a checkpoint by id or label. The checkpoint survives — restore as
|
|
190
|
+
* often as needed. Device identity may change server-side; the sandbox
|
|
191
|
+
* endpoint/token stay valid. */
|
|
192
|
+
restoreCheckpoint(ref: string): Promise<{ checkpointId: string }> {
|
|
193
|
+
return this.rpc('restoreCheckpoint', ref);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** List this sandbox's checkpoints. */
|
|
197
|
+
listCheckpoints(): Promise<SandboxCheckpointInfo[]> {
|
|
198
|
+
return this.rpc('listCheckpoints');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Delete a checkpoint by id or label. */
|
|
202
|
+
deleteCheckpoint(ref: string): Promise<{ deleted: boolean }> {
|
|
203
|
+
return this.rpc('deleteCheckpoint', ref);
|
|
204
|
+
}
|
|
205
|
+
|
|
165
206
|
/** Upload a zipped .app bundle (base64) and install it on the sandbox device. */
|
|
166
207
|
/**
|
|
167
208
|
* Upload a zipped .app as a raw stream. Prefer this over {@link installApp}:
|
package/src/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @phone-use/sdk — the device runtime SDK: engine-as-object lifecycle
|
|
3
|
-
* (ios.launch/connect → Device), Device backends, config, errors, capabilities,
|
|
3
|
+
* (ios.launch/connect and android.launch/connect → Device), Device backends, config, errors, capabilities,
|
|
4
4
|
* and the action verb surface.
|
|
5
5
|
*
|
|
6
6
|
* The test double (FakeBackend) lives on the "@phone-use/sdk/testing" subpath,
|
|
7
7
|
* deliberately not re-exported here.
|
|
8
8
|
*/
|
|
9
9
|
/** The published package version (kept in sync with package.json by the release flow). */
|
|
10
|
-
export const VERSION = '0.
|
|
10
|
+
export const VERSION = '0.5.0';
|
|
11
11
|
|
|
12
12
|
export {
|
|
13
13
|
type Action,
|
|
@@ -31,10 +31,23 @@ export {
|
|
|
31
31
|
registerBackend,
|
|
32
32
|
} from './backend.ts';
|
|
33
33
|
export { createAgentDeviceBackend } from './backends/agent-device.ts';
|
|
34
|
+
export {
|
|
35
|
+
AndroidBackend,
|
|
36
|
+
type AndroidBackendOptions,
|
|
37
|
+
type AndroidConnectOptions,
|
|
38
|
+
type AndroidDeviceInfo,
|
|
39
|
+
type AndroidLaunchOptions,
|
|
40
|
+
type AndroidListOptions,
|
|
41
|
+
android,
|
|
42
|
+
type BinaryExecRunner,
|
|
43
|
+
createAndroidBackend,
|
|
44
|
+
type EmulatorProcess,
|
|
45
|
+
} from './backends/android.ts';
|
|
34
46
|
export {
|
|
35
47
|
CloudSandboxBackend,
|
|
36
48
|
type CloudSandboxBackendOptions,
|
|
37
49
|
createCloudSandboxBackend,
|
|
50
|
+
type SandboxCheckpointInfo,
|
|
38
51
|
type SandboxRpcFailure,
|
|
39
52
|
type SandboxRpcMethod,
|
|
40
53
|
type SandboxRpcRequest,
|
|
@@ -97,5 +110,7 @@ export { SecretStore } from './secrets.ts';
|
|
|
97
110
|
// of the *published* dist, where the barrel is the entry).
|
|
98
111
|
import { registerBackend as _register } from './backend.ts';
|
|
99
112
|
import { createAgentDeviceBackend as _createAd } from './backends/agent-device.ts';
|
|
113
|
+
import { createAndroidBackend as _createAndroid } from './backends/android.ts';
|
|
100
114
|
|
|
101
115
|
_register('agent-device', _createAd);
|
|
116
|
+
_register('android-adb', _createAndroid);
|
package/src/lifecycle.ts
CHANGED
|
@@ -21,8 +21,8 @@ export type DeviceStatus = 'running' | 'closed';
|
|
|
21
21
|
/**
|
|
22
22
|
* The Device lifecycle handle: id, pinned backend, close/dispose, idle lease +
|
|
23
23
|
* reaper — plus the action verb surface layered onto the same type.
|
|
24
|
-
* `ios.launch()` and `
|
|
25
|
-
*
|
|
24
|
+
* `ios.launch()`/`ios.connect()` and `android.launch()`/`android.connect()`
|
|
25
|
+
* all return it, built over `createDeviceHandle`.
|
|
26
26
|
*/
|
|
27
27
|
export interface Device {
|
|
28
28
|
/** udid (iOS) / serial (Android). */
|
|
@@ -177,7 +177,7 @@ export type CreateDeviceHandleOptions = {
|
|
|
177
177
|
|
|
178
178
|
/**
|
|
179
179
|
* Assemble a Device handle over a backend: lease/reaper, verb surface,
|
|
180
|
-
* close/dispose semantics. Engine authors (ios
|
|
180
|
+
* close/dispose semantics. Engine authors (ios and android here,
|
|
181
181
|
* phone-backend-* third parties) build on this; tests fabricate devices with
|
|
182
182
|
* it over a FakeBackend.
|
|
183
183
|
*/
|