@midscene/android 1.9.8 → 1.10.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.
@@ -1,298 +0,0 @@
1
- import { AbstractInterface } from '@midscene/core/device';
2
- import type { ActionParam } from '@midscene/core';
3
- import type { ActionReturn } from '@midscene/core';
4
- import { ADB } from 'appium-adb';
5
- import { Agent } from '@midscene/core/agent';
6
- import { AgentBehaviorInitArgs } from '@midscene/shared/mcp/agent-behavior-init-args';
7
- import { AgentOpt } from '@midscene/core/agent';
8
- import { AndroidDeviceInputOpt } from '@midscene/core/device';
9
- import { AndroidDeviceOpt } from '@midscene/core/device';
10
- import { BaseMCPServer } from '@midscene/shared/mcp';
11
- import { BaseMidsceneTools } from '@midscene/shared/mcp/base-tools';
12
- import { DeviceAction } from '@midscene/core';
13
- import type { ElementInfo } from '@midscene/shared/extractor';
14
- import { InitArgSpec } from '@midscene/shared/mcp/base-tools';
15
- import { InterfaceType } from '@midscene/core';
16
- import { LaunchMCPServerOptions } from '@midscene/shared/mcp';
17
- import { LaunchMCPServerResult } from '@midscene/shared/mcp';
18
- import { MobileInputPrimitives } from '@midscene/core/device';
19
- import { Point } from '@midscene/core';
20
- import { Size } from '@midscene/core';
21
- import { Tool } from '@midscene/shared/mcp';
22
- import type { ToolDefinition } from '@midscene/shared/mcp/types';
23
-
24
- declare type ActionArgs<T extends DeviceAction> = [ActionParam<T>] extends [undefined] ? [] : [ActionParam<T>];
25
-
26
- declare class AndroidAgent extends Agent<AndroidDevice> {
27
- /**
28
- * Trigger the system back operation on Android devices
29
- */
30
- back: WrappedAction<DeviceActionAndroidBackButton>;
31
- /**
32
- * Trigger the system home operation on Android devices
33
- */
34
- home: WrappedAction<DeviceActionAndroidHomeButton>;
35
- /**
36
- * Trigger the system recent apps operation on Android devices
37
- */
38
- recentApps: WrappedAction<DeviceActionAndroidRecentAppsButton>;
39
- /**
40
- * User-provided app name to package name mapping
41
- */
42
- private appNameMapping;
43
- constructor(device: AndroidDevice, opts?: AndroidAgentOpt);
44
- /**
45
- * Launch an Android app or URL
46
- * @param uri - App package name, URL, or app name to launch
47
- */
48
- launch(uri: string): Promise<void>;
49
- /**
50
- * Terminate (force-stop) an Android app by package name
51
- * @param uri - Package name or app name to terminate
52
- */
53
- terminate(uri: string): Promise<void>;
54
- /**
55
- * Execute ADB shell command on Android device
56
- * @param command - ADB shell command to execute
57
- * @param opt - Optional ADB shell execution settings
58
- */
59
- runAdbShell(command: string, opt?: RunAdbShellOpt): Promise<string>;
60
- private createActionWrapper;
61
- }
62
-
63
- declare type AndroidAgentOpt = AgentOpt & {
64
- /**
65
- * Custom mapping of app names to package names
66
- * User-provided mappings will take precedence over default mappings
67
- */
68
- appNameMapping?: Record<string, string>;
69
- };
70
-
71
- declare class AndroidDevice implements AbstractInterface {
72
- private deviceId;
73
- private yadbPushed;
74
- private devicePixelRatio;
75
- private devicePixelRatioInitialized;
76
- private adb;
77
- private connectingAdb;
78
- private destroyed;
79
- private description;
80
- private customActions?;
81
- private cachedScreenSize;
82
- private cachedOrientation;
83
- private cachedPhysicalDisplayId;
84
- private scrcpyAdapter;
85
- private appNameMapping;
86
- private cachedAdjustScale;
87
- private takeScreenshotFailCount;
88
- private static readonly TAKE_SCREENSHOT_FAIL_THRESHOLD;
89
- private static readonly DEFAULT_MIN_SCREENSHOT_BUFFER_SIZE;
90
- interfaceType: InterfaceType;
91
- uri: string | undefined;
92
- options?: AndroidDeviceOpt;
93
- readonly inputPrimitives: MobileInputPrimitives;
94
- actionSpace(): DeviceAction<any>[];
95
- private performActionScroll;
96
- constructor(deviceId: string, options?: AndroidDeviceOpt);
97
- describe(): string;
98
- connect(): Promise<ADB>;
99
- getAdb(): Promise<ADB>;
100
- private createAdbProxy;
101
- /**
102
- * Get or create the scrcpy adapter (lazy initialization)
103
- */
104
- private getScrcpyAdapter;
105
- /**
106
- * Get device physical info needed by scrcpy adapter
107
- */
108
- private getDevicePhysicalInfo;
109
- /**
110
- * Set the app name to package name mapping
111
- */
112
- setAppNameMapping(mapping: Record<string, string>): void;
113
- /**
114
- * Resolve app name to package name using the mapping
115
- * Comparison is case-insensitive and ignores spaces, dashes, and underscores.
116
- * Keys in appNameMapping are pre-normalized, so we only need to normalize the input.
117
- * @param appName The app name to resolve
118
- */
119
- private resolvePackageName;
120
- launch(uri: string): Promise<AndroidDevice>;
121
- /**
122
- * Terminate (force-stop) an Android app by package name.
123
- * Supports app name resolution via setAppNameMapping.
124
- * If uri contains "/" (e.g. com.example.app/.MainActivity), only the package part is used.
125
- */
126
- terminate(uri: string): Promise<void>;
127
- execYadb(keyboardContent: string): Promise<void>;
128
- getElementsInfo(): Promise<ElementInfo[]>;
129
- getElementsNodeTree(): Promise<any>;
130
- getScreenSize(): Promise<{
131
- override: string;
132
- physical: string;
133
- orientation: number;
134
- isCurrentOrientation?: boolean;
135
- }>;
136
- private initializeDevicePixelRatio;
137
- getDisplayDensity(): Promise<number>;
138
- getDisplayOrientation(): Promise<number>;
139
- /**
140
- * Get physical screen dimensions adjusted for current orientation.
141
- * Swaps width/height when the device is in landscape and the reported
142
- * dimensions do not already reflect the current orientation.
143
- */
144
- private getOrientedPhysicalSize;
145
- size(): Promise<Size>;
146
- /**
147
- * Compute and cache the coordinate adjustment scale by comparing
148
- * physical dimensions with logical dimensions from size().
149
- * Cached after first call; invalidated on destroy().
150
- */
151
- private getAdjustScale;
152
- /**
153
- * Convert logical coordinates (from AI) back to physical coordinates (for ADB).
154
- * The ratio is derived from size(), so overriding size() alone is sufficient.
155
- */
156
- private adjustCoordinates;
157
- /**
158
- * Calculate the end point for scroll operations based on start point, scroll delta, and screen boundaries.
159
- * This method ensures that scroll operations stay within screen bounds and maintain a minimum scroll distance
160
- * for effective scrolling gestures on Android devices.
161
- *
162
- * @param start - The starting point of the scroll gesture
163
- * @param deltaX - The horizontal scroll distance (positive = scroll right, negative = scroll left)
164
- * @param deltaY - The vertical scroll distance (positive = scroll down, negative = scroll up)
165
- * @param maxWidth - The maximum width boundary (screen width)
166
- * @param maxHeight - The maximum height boundary (screen height)
167
- * @returns The calculated end point for the scroll gesture
168
- */
169
- private calculateScrollEndPoint;
170
- private warnScrollDistanceClamped;
171
- screenshotBase64(): Promise<string>;
172
- clearInput(element?: ElementInfo): Promise<void>;
173
- forceScreenshot(path: string): Promise<void>;
174
- url(): Promise<string>;
175
- scrollUntilTop(startPoint?: Point): Promise<void>;
176
- scrollUntilBottom(startPoint?: Point): Promise<void>;
177
- scrollUntilLeft(startPoint?: Point): Promise<void>;
178
- scrollUntilRight(startPoint?: Point): Promise<void>;
179
- scrollUp(distance?: number, startPoint?: Point): Promise<void>;
180
- scrollDown(distance?: number, startPoint?: Point): Promise<void>;
181
- scrollLeft(distance?: number, startPoint?: Point): Promise<void>;
182
- scrollRight(distance?: number, startPoint?: Point): Promise<void>;
183
- ensureYadb(): Promise<void>;
184
- /**
185
- * Check if text contains characters that may cause issues with ADB inputText.
186
- * appium-adb's inputText has known bugs with certain characters:
187
- * - Backslash causes broken shell quoting
188
- * - Backtick is not escaped at all
189
- * - Text containing both " and ' throws an error
190
- * - Dollar sign can cause variable expansion issues
191
- *
192
- * For these characters, we route through yadb which handles them correctly
193
- * via escapeForShell + double-quoted shell context.
194
- */
195
- private shouldUseYadbForText;
196
- private typeText;
197
- private normalizeKeyName;
198
- private pressKey;
199
- private tapPoint;
200
- private doubleTapPoint;
201
- mouseMove(): Promise<void>;
202
- private dragPoint;
203
- private swipePoint;
204
- scroll(deltaX: number, deltaY: number, duration?: number, warnOnClamp?: boolean, direction?: ScrollDirection): Promise<void>;
205
- destroy(): Promise<void>;
206
- /**
207
- * Get the current device-local time as a formatted string.
208
- * This avoids formatting an Android epoch timestamp in the host machine's
209
- * timezone, which can disagree with the device status bar.
210
- */
211
- getDeviceLocalTimeString(format?: string): Promise<string>;
212
- back(): Promise<void>;
213
- home(): Promise<void>;
214
- recentApps(): Promise<void>;
215
- private longPressPoint;
216
- pullDown(startPoint?: Point, distance?: number, duration?: number): Promise<void>;
217
- pullDrag(from: {
218
- x: number;
219
- y: number;
220
- }, to: {
221
- x: number;
222
- y: number;
223
- }, duration: number): Promise<void>;
224
- pullUp(startPoint?: Point, distance?: number, duration?: number): Promise<void>;
225
- private getDisplayArg;
226
- getPhysicalDisplayId(): Promise<string | null>;
227
- hideKeyboard(options?: AndroidDeviceInputOpt, timeoutMs?: number): Promise<boolean>;
228
- }
229
-
230
- declare type AndroidInitArgs = AgentBehaviorInitArgs & {
231
- deviceId?: string;
232
- useScrcpy?: boolean;
233
- };
234
-
235
- /**
236
- * Android MCP Server
237
- * Provides MCP tools for Android automation through ADB
238
- */
239
- export declare class AndroidMCPServer extends BaseMCPServer {
240
- constructor(toolsManager?: AndroidMidsceneTools);
241
- protected createToolsManager(): AndroidMidsceneTools;
242
- }
243
-
244
- /**
245
- * Android-specific tools manager
246
- * Extends BaseMidsceneTools to provide Android ADB device connection tools
247
- */
248
- declare class AndroidMidsceneTools extends BaseMidsceneTools<AndroidAgent, AndroidInitArgs> {
249
- private lastInitArgsSignature?;
250
- protected getCliReportSessionName(): string;
251
- protected readonly initArgSpec: InitArgSpec<AndroidInitArgs>;
252
- protected createTemporaryDevice(): AndroidDevice;
253
- protected ensureAgent(initArgs?: AndroidInitArgs): Promise<AndroidAgent>;
254
- /**
255
- * Provide Android-specific platform tools
256
- */
257
- protected preparePlatformTools(): ToolDefinition[];
258
- }
259
-
260
- declare type DeviceActionAndroidBackButton = DeviceAction<undefined, void>;
261
-
262
- declare type DeviceActionAndroidHomeButton = DeviceAction<undefined, void>;
263
-
264
- declare type DeviceActionAndroidRecentAppsButton = DeviceAction<undefined, void>;
265
-
266
- /**
267
- * Create MCP kit for a specific Android Agent
268
- */
269
- export declare function mcpKitForAgent(agent: Agent | AndroidAgent): Promise<{
270
- description: string;
271
- tools: Tool[];
272
- }>;
273
-
274
- /**
275
- * Create an MCP server launcher for a specific Android Agent
276
- */
277
- export declare function mcpServerForAgent(agent: Agent | AndroidAgent): {
278
- launch(options?: {
279
- verbose?: boolean;
280
- }): Promise<LaunchMCPServerResult>;
281
- launchHttp(options: LaunchMCPServerOptions): Promise<LaunchMCPServerResult>;
282
- };
283
-
284
- declare type RunAdbShellOpt = {
285
- /**
286
- * ADB shell command execution timeout in milliseconds.
287
- */
288
- timeout?: number;
289
- };
290
-
291
- declare type ScrollDirection = 'up' | 'down' | 'left' | 'right';
292
-
293
- /**
294
- * Helper type to convert DeviceAction to wrapped method signature
295
- */
296
- declare type WrappedAction<T extends DeviceAction> = (...args: ActionArgs<T>) => Promise<ActionReturn<T>>;
297
-
298
- export { }