@midscene/harmony 1.4.7-beta-20260226072540.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/LICENSE +21 -0
- package/bin/midscene-harmony +2 -0
- package/dist/es/cli.mjs +882 -0
- package/dist/es/index.mjs +821 -0
- package/dist/es/mcp-server.mjs +905 -0
- package/dist/lib/cli.js +911 -0
- package/dist/lib/index.js +878 -0
- package/dist/lib/mcp-server.js +956 -0
- package/dist/types/cli.d.ts +1 -0
- package/dist/types/index.d.ts +139 -0
- package/dist/types/mcp-server.d.ts +157 -0
- package/package.json +58 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { }
|
|
@@ -0,0 +1,139 @@
|
|
|
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 { AgentOpt } from '@midscene/core/agent';
|
|
6
|
+
import { DeviceAction } from '@midscene/core';
|
|
7
|
+
import type { ElementInfo } from '@midscene/shared/extractor';
|
|
8
|
+
import { HarmonyDeviceOpt } from '@midscene/core/device';
|
|
9
|
+
import { InterfaceType } from '@midscene/core';
|
|
10
|
+
import { LocateResultElement } from '@midscene/core';
|
|
11
|
+
import { overrideAIConfig } from '@midscene/shared/env';
|
|
12
|
+
import { Point } from '@midscene/core';
|
|
13
|
+
import { Size } from '@midscene/core';
|
|
14
|
+
|
|
15
|
+
declare type ActionArgs<T extends DeviceAction> = [ActionParam<T>] extends [undefined] ? [] : [ActionParam<T>];
|
|
16
|
+
|
|
17
|
+
export declare function agentFromHdcDevice(deviceId?: string, opts?: HarmonyAgentOpt & HarmonyDeviceOpt): Promise<HarmonyAgent>;
|
|
18
|
+
|
|
19
|
+
declare type DeviceActionHarmonyBackButton = DeviceAction<undefined, void>;
|
|
20
|
+
|
|
21
|
+
declare type DeviceActionHarmonyHomeButton = DeviceAction<undefined, void>;
|
|
22
|
+
|
|
23
|
+
declare type DeviceActionHarmonyRecentAppsButton = DeviceAction<undefined, void>;
|
|
24
|
+
|
|
25
|
+
export declare function getConnectedDevices(hdcPath?: string): Promise<HarmonyDevice_2[]>;
|
|
26
|
+
|
|
27
|
+
export declare class HarmonyAgent extends Agent<HarmonyDevice> {
|
|
28
|
+
back: WrappedAction<DeviceActionHarmonyBackButton>;
|
|
29
|
+
home: WrappedAction<DeviceActionHarmonyHomeButton>;
|
|
30
|
+
recentApps: WrappedAction<DeviceActionHarmonyRecentAppsButton>;
|
|
31
|
+
private appNameMapping;
|
|
32
|
+
constructor(device: HarmonyDevice, opts?: HarmonyAgentOpt);
|
|
33
|
+
launch(uri: string): Promise<void>;
|
|
34
|
+
runHdcShell(command: string): Promise<string>;
|
|
35
|
+
private createActionWrapper;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export declare type HarmonyAgentOpt = AgentOpt & {
|
|
39
|
+
/**
|
|
40
|
+
* Custom mapping of app names to bundle names
|
|
41
|
+
* User-provided mappings will take precedence over default mappings
|
|
42
|
+
*/
|
|
43
|
+
appNameMapping?: Record<string, string>;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export declare class HarmonyDevice implements AbstractInterface {
|
|
47
|
+
private deviceId;
|
|
48
|
+
private hdc;
|
|
49
|
+
private connecting;
|
|
50
|
+
private destroyed;
|
|
51
|
+
private descriptionText;
|
|
52
|
+
private customActions?;
|
|
53
|
+
private cachedScreenSize;
|
|
54
|
+
private appNameMapping;
|
|
55
|
+
private lastTapPosition;
|
|
56
|
+
interfaceType: InterfaceType;
|
|
57
|
+
uri: string | undefined;
|
|
58
|
+
options?: HarmonyDeviceOpt;
|
|
59
|
+
actionSpace(): DeviceAction<any>[];
|
|
60
|
+
constructor(deviceId: string, options?: HarmonyDeviceOpt);
|
|
61
|
+
describe(): string;
|
|
62
|
+
connect(): Promise<HdcClient>;
|
|
63
|
+
getHdc(): Promise<HdcClient>;
|
|
64
|
+
setAppNameMapping(mapping: Record<string, string>): void;
|
|
65
|
+
private resolvePackageName;
|
|
66
|
+
launch(uri: string): Promise<HarmonyDevice>;
|
|
67
|
+
getScreenSize(): Promise<{
|
|
68
|
+
width: number;
|
|
69
|
+
height: number;
|
|
70
|
+
}>;
|
|
71
|
+
size(): Promise<Size>;
|
|
72
|
+
screenshotBase64(): Promise<string>;
|
|
73
|
+
tap(x: number, y: number): Promise<void>;
|
|
74
|
+
doubleTap(x: number, y: number): Promise<void>;
|
|
75
|
+
longPress(x: number, y: number): Promise<void>;
|
|
76
|
+
inputText(text: string, element?: LocateResultElement, shouldReplace?: boolean): Promise<void>;
|
|
77
|
+
clearInput(_element?: ElementInfo): Promise<void>;
|
|
78
|
+
keyboardPress(key: string): Promise<void>;
|
|
79
|
+
private normalizeKeyName;
|
|
80
|
+
scroll(deltaX: number, deltaY: number, speed?: number): Promise<void>;
|
|
81
|
+
scrollDown(distance?: number, startPoint?: Point): Promise<void>;
|
|
82
|
+
scrollUp(distance?: number, startPoint?: Point): Promise<void>;
|
|
83
|
+
scrollLeft(distance?: number, startPoint?: Point): Promise<void>;
|
|
84
|
+
scrollRight(distance?: number, startPoint?: Point): Promise<void>;
|
|
85
|
+
scrollUntilTop(startPoint?: Point): Promise<void>;
|
|
86
|
+
scrollUntilBottom(startPoint?: Point): Promise<void>;
|
|
87
|
+
scrollUntilLeft(startPoint?: Point): Promise<void>;
|
|
88
|
+
scrollUntilRight(startPoint?: Point): Promise<void>;
|
|
89
|
+
back(): Promise<void>;
|
|
90
|
+
home(): Promise<void>;
|
|
91
|
+
recentApps(): Promise<void>;
|
|
92
|
+
hideKeyboard(): Promise<void>;
|
|
93
|
+
getTimestamp(): Promise<number>;
|
|
94
|
+
destroy(): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
declare interface HarmonyDevice_2 {
|
|
98
|
+
deviceId: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
declare class HdcClient {
|
|
102
|
+
private hdcPath;
|
|
103
|
+
private deviceId;
|
|
104
|
+
private timeout;
|
|
105
|
+
constructor(options: HdcOptions);
|
|
106
|
+
private buildArgs;
|
|
107
|
+
exec(...args: string[]): Promise<string>;
|
|
108
|
+
shell(command: string): Promise<string>;
|
|
109
|
+
fileSend(localPath: string, remotePath: string): Promise<void>;
|
|
110
|
+
fileRecv(remotePath: string, localPath: string): Promise<void>;
|
|
111
|
+
screenshot(remotePath: string): Promise<void>;
|
|
112
|
+
click(x: number, y: number): Promise<void>;
|
|
113
|
+
doubleClick(x: number, y: number): Promise<void>;
|
|
114
|
+
longClick(x: number, y: number): Promise<void>;
|
|
115
|
+
swipe(fromX: number, fromY: number, toX: number, toY: number, speed?: number): Promise<void>;
|
|
116
|
+
fling(fromX: number, fromY: number, toX: number, toY: number, speed?: number): Promise<void>;
|
|
117
|
+
drag(fromX: number, fromY: number, toX: number, toY: number, speed?: number): Promise<void>;
|
|
118
|
+
inputText(x: number, y: number, text: string): Promise<void>;
|
|
119
|
+
keyEvent(...keys: string[]): Promise<void>;
|
|
120
|
+
startAbility(bundleName: string, abilityName: string): Promise<void>;
|
|
121
|
+
forceStop(bundleName: string): Promise<void>;
|
|
122
|
+
getScreenInfo(): Promise<{
|
|
123
|
+
width: number;
|
|
124
|
+
height: number;
|
|
125
|
+
}>;
|
|
126
|
+
listTargets(): Promise<string[]>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
declare interface HdcOptions {
|
|
130
|
+
hdcPath?: string;
|
|
131
|
+
deviceId?: string;
|
|
132
|
+
timeout?: number;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export { overrideAIConfig }
|
|
136
|
+
|
|
137
|
+
declare type WrappedAction<T extends DeviceAction> = (...args: ActionArgs<T>) => Promise<ActionReturn<T>>;
|
|
138
|
+
|
|
139
|
+
export { }
|
|
@@ -0,0 +1,157 @@
|
|
|
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 { AgentOpt } from '@midscene/core/agent';
|
|
6
|
+
import { BaseMCPServer } from '@midscene/shared/mcp';
|
|
7
|
+
import { BaseMidsceneTools } from '@midscene/shared/mcp';
|
|
8
|
+
import { DeviceAction } from '@midscene/core';
|
|
9
|
+
import type { ElementInfo } from '@midscene/shared/extractor';
|
|
10
|
+
import { HarmonyDeviceOpt } from '@midscene/core/device';
|
|
11
|
+
import { InterfaceType } from '@midscene/core';
|
|
12
|
+
import { LaunchMCPServerOptions } from '@midscene/shared/mcp';
|
|
13
|
+
import { LaunchMCPServerResult } from '@midscene/shared/mcp';
|
|
14
|
+
import { LocateResultElement } from '@midscene/core';
|
|
15
|
+
import { Point } from '@midscene/core';
|
|
16
|
+
import { Size } from '@midscene/core';
|
|
17
|
+
import { Tool } from '@midscene/shared/mcp';
|
|
18
|
+
import { ToolDefinition } from '@midscene/shared/mcp';
|
|
19
|
+
|
|
20
|
+
declare type ActionArgs<T extends DeviceAction> = [ActionParam<T>] extends [undefined] ? [] : [ActionParam<T>];
|
|
21
|
+
|
|
22
|
+
declare type DeviceActionHarmonyBackButton = DeviceAction<undefined, void>;
|
|
23
|
+
|
|
24
|
+
declare type DeviceActionHarmonyHomeButton = DeviceAction<undefined, void>;
|
|
25
|
+
|
|
26
|
+
declare type DeviceActionHarmonyRecentAppsButton = DeviceAction<undefined, void>;
|
|
27
|
+
|
|
28
|
+
declare class HarmonyAgent extends Agent<HarmonyDevice> {
|
|
29
|
+
back: WrappedAction<DeviceActionHarmonyBackButton>;
|
|
30
|
+
home: WrappedAction<DeviceActionHarmonyHomeButton>;
|
|
31
|
+
recentApps: WrappedAction<DeviceActionHarmonyRecentAppsButton>;
|
|
32
|
+
private appNameMapping;
|
|
33
|
+
constructor(device: HarmonyDevice, opts?: HarmonyAgentOpt);
|
|
34
|
+
launch(uri: string): Promise<void>;
|
|
35
|
+
runHdcShell(command: string): Promise<string>;
|
|
36
|
+
private createActionWrapper;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare type HarmonyAgentOpt = AgentOpt & {
|
|
40
|
+
/**
|
|
41
|
+
* Custom mapping of app names to bundle names
|
|
42
|
+
* User-provided mappings will take precedence over default mappings
|
|
43
|
+
*/
|
|
44
|
+
appNameMapping?: Record<string, string>;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
declare class HarmonyDevice implements AbstractInterface {
|
|
48
|
+
private deviceId;
|
|
49
|
+
private hdc;
|
|
50
|
+
private connecting;
|
|
51
|
+
private destroyed;
|
|
52
|
+
private descriptionText;
|
|
53
|
+
private customActions?;
|
|
54
|
+
private cachedScreenSize;
|
|
55
|
+
private appNameMapping;
|
|
56
|
+
private lastTapPosition;
|
|
57
|
+
interfaceType: InterfaceType;
|
|
58
|
+
uri: string | undefined;
|
|
59
|
+
options?: HarmonyDeviceOpt;
|
|
60
|
+
actionSpace(): DeviceAction<any>[];
|
|
61
|
+
constructor(deviceId: string, options?: HarmonyDeviceOpt);
|
|
62
|
+
describe(): string;
|
|
63
|
+
connect(): Promise<HdcClient>;
|
|
64
|
+
getHdc(): Promise<HdcClient>;
|
|
65
|
+
setAppNameMapping(mapping: Record<string, string>): void;
|
|
66
|
+
private resolvePackageName;
|
|
67
|
+
launch(uri: string): Promise<HarmonyDevice>;
|
|
68
|
+
getScreenSize(): Promise<{
|
|
69
|
+
width: number;
|
|
70
|
+
height: number;
|
|
71
|
+
}>;
|
|
72
|
+
size(): Promise<Size>;
|
|
73
|
+
screenshotBase64(): Promise<string>;
|
|
74
|
+
tap(x: number, y: number): Promise<void>;
|
|
75
|
+
doubleTap(x: number, y: number): Promise<void>;
|
|
76
|
+
longPress(x: number, y: number): Promise<void>;
|
|
77
|
+
inputText(text: string, element?: LocateResultElement, shouldReplace?: boolean): Promise<void>;
|
|
78
|
+
clearInput(_element?: ElementInfo): Promise<void>;
|
|
79
|
+
keyboardPress(key: string): Promise<void>;
|
|
80
|
+
private normalizeKeyName;
|
|
81
|
+
scroll(deltaX: number, deltaY: number, speed?: number): Promise<void>;
|
|
82
|
+
scrollDown(distance?: number, startPoint?: Point): Promise<void>;
|
|
83
|
+
scrollUp(distance?: number, startPoint?: Point): Promise<void>;
|
|
84
|
+
scrollLeft(distance?: number, startPoint?: Point): Promise<void>;
|
|
85
|
+
scrollRight(distance?: number, startPoint?: Point): Promise<void>;
|
|
86
|
+
scrollUntilTop(startPoint?: Point): Promise<void>;
|
|
87
|
+
scrollUntilBottom(startPoint?: Point): Promise<void>;
|
|
88
|
+
scrollUntilLeft(startPoint?: Point): Promise<void>;
|
|
89
|
+
scrollUntilRight(startPoint?: Point): Promise<void>;
|
|
90
|
+
back(): Promise<void>;
|
|
91
|
+
home(): Promise<void>;
|
|
92
|
+
recentApps(): Promise<void>;
|
|
93
|
+
hideKeyboard(): Promise<void>;
|
|
94
|
+
getTimestamp(): Promise<number>;
|
|
95
|
+
destroy(): Promise<void>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export declare class HarmonyMCPServer extends BaseMCPServer {
|
|
99
|
+
constructor(toolsManager?: HarmonyMidsceneTools);
|
|
100
|
+
protected createToolsManager(): HarmonyMidsceneTools;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
declare class HarmonyMidsceneTools extends BaseMidsceneTools<HarmonyAgent> {
|
|
104
|
+
protected createTemporaryDevice(): HarmonyDevice;
|
|
105
|
+
protected ensureAgent(deviceId?: string): Promise<HarmonyAgent>;
|
|
106
|
+
protected preparePlatformTools(): ToolDefinition[];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
declare class HdcClient {
|
|
110
|
+
private hdcPath;
|
|
111
|
+
private deviceId;
|
|
112
|
+
private timeout;
|
|
113
|
+
constructor(options: HdcOptions);
|
|
114
|
+
private buildArgs;
|
|
115
|
+
exec(...args: string[]): Promise<string>;
|
|
116
|
+
shell(command: string): Promise<string>;
|
|
117
|
+
fileSend(localPath: string, remotePath: string): Promise<void>;
|
|
118
|
+
fileRecv(remotePath: string, localPath: string): Promise<void>;
|
|
119
|
+
screenshot(remotePath: string): Promise<void>;
|
|
120
|
+
click(x: number, y: number): Promise<void>;
|
|
121
|
+
doubleClick(x: number, y: number): Promise<void>;
|
|
122
|
+
longClick(x: number, y: number): Promise<void>;
|
|
123
|
+
swipe(fromX: number, fromY: number, toX: number, toY: number, speed?: number): Promise<void>;
|
|
124
|
+
fling(fromX: number, fromY: number, toX: number, toY: number, speed?: number): Promise<void>;
|
|
125
|
+
drag(fromX: number, fromY: number, toX: number, toY: number, speed?: number): Promise<void>;
|
|
126
|
+
inputText(x: number, y: number, text: string): Promise<void>;
|
|
127
|
+
keyEvent(...keys: string[]): Promise<void>;
|
|
128
|
+
startAbility(bundleName: string, abilityName: string): Promise<void>;
|
|
129
|
+
forceStop(bundleName: string): Promise<void>;
|
|
130
|
+
getScreenInfo(): Promise<{
|
|
131
|
+
width: number;
|
|
132
|
+
height: number;
|
|
133
|
+
}>;
|
|
134
|
+
listTargets(): Promise<string[]>;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
declare interface HdcOptions {
|
|
138
|
+
hdcPath?: string;
|
|
139
|
+
deviceId?: string;
|
|
140
|
+
timeout?: number;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export declare function mcpKitForAgent(agent: Agent | HarmonyAgent): Promise<{
|
|
144
|
+
description: string;
|
|
145
|
+
tools: Tool[];
|
|
146
|
+
}>;
|
|
147
|
+
|
|
148
|
+
export declare function mcpServerForAgent(agent: Agent | HarmonyAgent): {
|
|
149
|
+
launch(options?: {
|
|
150
|
+
verbose?: boolean;
|
|
151
|
+
}): Promise<LaunchMCPServerResult>;
|
|
152
|
+
launchHttp(options: LaunchMCPServerOptions): Promise<LaunchMCPServerResult>;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
declare type WrappedAction<T extends DeviceAction> = (...args: ActionArgs<T>) => Promise<ActionReturn<T>>;
|
|
156
|
+
|
|
157
|
+
export { }
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@midscene/harmony",
|
|
3
|
+
"version": "1.4.7-beta-20260226072540.0",
|
|
4
|
+
"description": "HarmonyOS automation library for Midscene",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"HarmonyOS UI automation",
|
|
7
|
+
"HarmonyOS AI testing",
|
|
8
|
+
"HarmonyOS automation library",
|
|
9
|
+
"HarmonyOS automation tool",
|
|
10
|
+
"HarmonyOS NEXT"
|
|
11
|
+
],
|
|
12
|
+
"main": "./dist/lib/index.js",
|
|
13
|
+
"module": "./dist/es/index.mjs",
|
|
14
|
+
"types": "./dist/types/index.d.ts",
|
|
15
|
+
"bin": {
|
|
16
|
+
"midscene-harmony": "./bin/midscene-harmony"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"bin",
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/types/index.d.ts",
|
|
26
|
+
"import": "./dist/es/index.mjs",
|
|
27
|
+
"require": "./dist/lib/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./mcp-server": {
|
|
30
|
+
"types": "./dist/types/mcp-server.d.ts",
|
|
31
|
+
"import": "./dist/es/mcp-server.mjs",
|
|
32
|
+
"require": "./dist/lib/mcp-server.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@midscene/core": "1.4.7-beta-20260226072540.0",
|
|
38
|
+
"@midscene/shared": "1.4.7-beta-20260226072540.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@rslib/core": "^0.18.3",
|
|
42
|
+
"@types/node": "^18.0.0",
|
|
43
|
+
"dotenv": "^16.4.5",
|
|
44
|
+
"typescript": "^5.8.3",
|
|
45
|
+
"vitest": "3.0.5",
|
|
46
|
+
"zod": "3.24.3"
|
|
47
|
+
},
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"scripts": {
|
|
50
|
+
"dev": "npm run build:watch",
|
|
51
|
+
"build": "rslib build",
|
|
52
|
+
"build:watch": "rslib build --watch --no-clean",
|
|
53
|
+
"test": "vitest --run",
|
|
54
|
+
"test:u": "vitest --run -u",
|
|
55
|
+
"test:ai": "AI_TEST_TYPE=harmony npm run test",
|
|
56
|
+
"test:ai:cache": "MIDSCENE_CACHE=true AI_TEST_TYPE=harmony npm run test"
|
|
57
|
+
}
|
|
58
|
+
}
|