@midscene/harmony 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,217 +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 { Agent } from '@midscene/core/agent';
5
- import { AgentBehaviorInitArgs } from '@midscene/shared/mcp/agent-behavior-init-args';
6
- import { AgentOpt } from '@midscene/core/agent';
7
- import { BaseMCPServer } from '@midscene/shared/mcp';
8
- import { BaseMidsceneTools } from '@midscene/shared/mcp/base-tools';
9
- import { DeviceAction } from '@midscene/core';
10
- import type { ElementInfo } from '@midscene/shared/extractor';
11
- import { HarmonyDeviceInputOpt as HarmonyDeviceInputOpt_2 } from '@midscene/core/device';
12
- import { HarmonyDeviceOpt as HarmonyDeviceOpt_2 } from '@midscene/core/device';
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 type DeviceActionHarmonyBackButton = DeviceAction<undefined, void>;
26
-
27
- declare type DeviceActionHarmonyHomeButton = DeviceAction<undefined, void>;
28
-
29
- declare type DeviceActionHarmonyRecentAppsButton = DeviceAction<undefined, void>;
30
-
31
- declare class HarmonyAgent extends Agent<HarmonyDevice> {
32
- back: WrappedAction<DeviceActionHarmonyBackButton>;
33
- home: WrappedAction<DeviceActionHarmonyHomeButton>;
34
- recentApps: WrappedAction<DeviceActionHarmonyRecentAppsButton>;
35
- private appNameMapping;
36
- constructor(device: HarmonyDevice, opts?: HarmonyAgentOpt);
37
- launch(uri: string): Promise<void>;
38
- terminate(uri: string): Promise<void>;
39
- runHdcShell(command: string): Promise<string>;
40
- private createActionWrapper;
41
- }
42
-
43
- declare type HarmonyAgentOpt = AgentOpt & {
44
- /**
45
- * Custom mapping of app names to bundle names
46
- * User-provided mappings will take precedence over default mappings
47
- */
48
- appNameMapping?: Record<string, string>;
49
- };
50
-
51
- declare class HarmonyDevice implements AbstractInterface {
52
- private deviceId;
53
- private hdc;
54
- private connecting;
55
- private destroyed;
56
- private descriptionText;
57
- private customActions?;
58
- private cachedScreenSize;
59
- private appNameMapping;
60
- private lastTapPosition;
61
- interfaceType: InterfaceType;
62
- uri: string | undefined;
63
- options?: HarmonyDeviceOpt;
64
- readonly inputPrimitives: MobileInputPrimitives;
65
- actionSpace(): DeviceAction<any>[];
66
- private performActionScroll;
67
- constructor(deviceId: string, options?: HarmonyDeviceOpt);
68
- describe(): string;
69
- connect(): Promise<HdcClient>;
70
- getHdc(): Promise<HdcClient>;
71
- setAppNameMapping(mapping: Record<string, string>): void;
72
- private resolvePackageName;
73
- launch(uri: string): Promise<HarmonyDevice>;
74
- /**
75
- * Terminate (force-stop) a HarmonyOS app by bundle name.
76
- * Supports app name resolution via setAppNameMapping.
77
- * If uri contains "/" (e.g. com.example.app/MainAbility), only the bundle part is used.
78
- */
79
- terminate(uri: string): Promise<void>;
80
- getScreenSize(): Promise<{
81
- width: number;
82
- height: number;
83
- }>;
84
- size(): Promise<Size>;
85
- private remoteScreenshotPath;
86
- private localScreenshotPath;
87
- screenshotBase64(): Promise<string>;
88
- private tapPoint;
89
- private doubleTapPoint;
90
- private longPressPoint;
91
- private typeText;
92
- clearInput(element?: ElementInfo): Promise<void>;
93
- /**
94
- * Decide how many Backspaces `clearTextField` should send. Each
95
- * `uitest uiInput keyEvent` invocation costs ~300ms cold-start, so blindly
96
- * defaulting to 100 makes every clear take ~10s. Instead, snapshot the UI
97
- * once (~1s for `uitest dumpLayout`) and tighten the bound to the current
98
- * field's text length plus a small padding for transient IME composing.
99
- * Falls back to the safe upper bound if the layout can't be parsed.
100
- */
101
- private resolveClearLength;
102
- private pressKey;
103
- scroll(deltaX: number, deltaY: number, speed?: number): Promise<void>;
104
- private scrollInDirection;
105
- scrollDown(distance?: number, startPoint?: Point): Promise<void>;
106
- scrollUp(distance?: number, startPoint?: Point): Promise<void>;
107
- scrollLeft(distance?: number, startPoint?: Point): Promise<void>;
108
- scrollRight(distance?: number, startPoint?: Point): Promise<void>;
109
- private scrollUntilEdge;
110
- scrollUntilTop(startPoint?: Point): Promise<void>;
111
- scrollUntilBottom(startPoint?: Point): Promise<void>;
112
- scrollUntilLeft(startPoint?: Point): Promise<void>;
113
- scrollUntilRight(startPoint?: Point): Promise<void>;
114
- back(): Promise<void>;
115
- home(): Promise<void>;
116
- recentApps(): Promise<void>;
117
- hideKeyboard(options?: HarmonyDeviceInputOpt): Promise<void>;
118
- /**
119
- * Get the current device-local time as a formatted string.
120
- * This avoids formatting a device timestamp in the host machine's timezone.
121
- */
122
- getDeviceLocalTimeString(format?: string): Promise<string>;
123
- destroy(): Promise<void>;
124
- }
125
-
126
- declare type HarmonyDeviceInputOpt = HarmonyDeviceInputOpt_2 & {
127
- keyboardDismissStrategy?: KeyboardDismissStrategy;
128
- };
129
-
130
- declare type HarmonyDeviceOpt = HarmonyDeviceOpt_2 & HarmonyDeviceInputOpt;
131
-
132
- declare type HarmonyInitArgs = AgentBehaviorInitArgs & {
133
- deviceId?: string;
134
- };
135
-
136
- export declare class HarmonyMCPServer extends BaseMCPServer {
137
- constructor(toolsManager?: HarmonyMidsceneTools);
138
- protected createToolsManager(): HarmonyMidsceneTools;
139
- }
140
-
141
- declare class HarmonyMidsceneTools extends BaseMidsceneTools<HarmonyAgent, HarmonyInitArgs> {
142
- private lastInitArgsSignature?;
143
- protected getCliReportSessionName(): string;
144
- protected readonly initArgSpec: InitArgSpec<HarmonyInitArgs>;
145
- protected createTemporaryDevice(): HarmonyDevice;
146
- protected ensureAgent(initArgs?: HarmonyInitArgs): Promise<HarmonyAgent>;
147
- protected preparePlatformTools(): ToolDefinition[];
148
- }
149
-
150
- declare class HdcClient {
151
- private hdcPath;
152
- private deviceId;
153
- private timeout;
154
- private execMutex;
155
- constructor(options: HdcOptions);
156
- private buildArgs;
157
- exec(...args: string[]): Promise<string>;
158
- shell(command: string): Promise<string>;
159
- fileSend(localPath: string, remotePath: string): Promise<void>;
160
- fileRecv(remotePath: string, localPath: string): Promise<void>;
161
- screenshot(remotePath: string): Promise<string>;
162
- /**
163
- * Capture the current UI layout via `uitest dumpLayout` and return the JSON
164
- * string. The dump is written to a fixed device path then `cat`'d back in
165
- * the same shell round-trip to avoid a separate `hdc file recv` call.
166
- */
167
- dumpLayout(): Promise<string>;
168
- click(x: number, y: number): Promise<void>;
169
- doubleClick(x: number, y: number): Promise<void>;
170
- longClick(x: number, y: number): Promise<void>;
171
- swipe(fromX: number, fromY: number, toX: number, toY: number, speed?: number): Promise<void>;
172
- fling(fromX: number, fromY: number, toX: number, toY: number, speed?: number): Promise<void>;
173
- drag(fromX: number, fromY: number, toX: number, toY: number, speed?: number): Promise<void>;
174
- inputText(x: number, y: number, text: string): Promise<void>;
175
- keyEvent(...keys: string[]): Promise<void>;
176
- /**
177
- * Clear the focused text field by sending repeated Backspace(2055) key
178
- * events. `uitest uiInput keyEvent` only accepts up to 3 keyCodes per call
179
- * (any more triggers "Too many parameters." with zero presses injected),
180
- * so we pack codes into 3-key batches and chain the calls with shell `;`
181
- * to keep a single hdc round-trip — mirroring Android adb's
182
- * "one shell, many keys" design despite the per-call cap.
183
- */
184
- clearTextField(length?: number): Promise<void>;
185
- startAbility(bundleName: string, abilityName: string): Promise<void>;
186
- queryMainAbility(bundleName: string): Promise<string | undefined>;
187
- forceStop(bundleName: string): Promise<void>;
188
- getScreenInfo(): Promise<{
189
- width: number;
190
- height: number;
191
- }>;
192
- listTargets(): Promise<string[]>;
193
- }
194
-
195
- declare interface HdcOptions {
196
- hdcPath?: string;
197
- deviceId?: string;
198
- timeout?: number;
199
- }
200
-
201
- declare type KeyboardDismissStrategy = 'esc-first' | 'back-first';
202
-
203
- export declare function mcpKitForAgent(agent: Agent | HarmonyAgent): Promise<{
204
- description: string;
205
- tools: Tool[];
206
- }>;
207
-
208
- export declare function mcpServerForAgent(agent: Agent | HarmonyAgent): {
209
- launch(options?: {
210
- verbose?: boolean;
211
- }): Promise<LaunchMCPServerResult>;
212
- launchHttp(options: LaunchMCPServerOptions): Promise<LaunchMCPServerResult>;
213
- };
214
-
215
- declare type WrappedAction<T extends DeviceAction> = (...args: ActionArgs<T>) => Promise<ActionReturn<T>>;
216
-
217
- export { }