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