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