@midscene/harmony 1.5.3 → 1.5.4-beta-20260310030546.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/dist/es/index.mjs +56 -1
- package/dist/lib/index.js +58 -0
- package/dist/types/index.d.ts +8 -0
- package/package.json +4 -4
- package/static/index.html +1 -1
- package/static/static/js/{index.3509da03.js → index.5dd18cad.js} +3 -3
- package/static/static/js/{index.3509da03.js.map → index.5dd18cad.js.map} +1 -1
- /package/static/static/js/{index.3509da03.js.LICENSE.txt → index.5dd18cad.js.LICENSE.txt} +0 -0
package/dist/es/index.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import { mergeAndNormalizeAppNameMapping, normalizeForComparison, repeat } from
|
|
|
9
9
|
import { execFile } from "node:child_process";
|
|
10
10
|
import { promisify } from "node:util";
|
|
11
11
|
import { Agent } from "@midscene/core/agent";
|
|
12
|
+
import { BaseMidsceneTools } from "@midscene/shared/mcp";
|
|
12
13
|
import { overrideAIConfig } from "@midscene/shared/env";
|
|
13
14
|
function _define_property(obj, key, value) {
|
|
14
15
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
@@ -875,4 +876,58 @@ async function agentFromHdcDevice(deviceId, opts) {
|
|
|
875
876
|
await device.connect();
|
|
876
877
|
return new HarmonyAgent(device, opts);
|
|
877
878
|
}
|
|
878
|
-
|
|
879
|
+
const debug = getDebug('mcp:harmony-tools');
|
|
880
|
+
class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
881
|
+
createTemporaryDevice() {
|
|
882
|
+
return new HarmonyDevice('temp-for-action-space', {});
|
|
883
|
+
}
|
|
884
|
+
async ensureAgent(deviceId) {
|
|
885
|
+
if (this.agent && deviceId) {
|
|
886
|
+
try {
|
|
887
|
+
await this.agent.destroy?.();
|
|
888
|
+
} catch (error) {
|
|
889
|
+
debug('Failed to destroy agent during cleanup:', error);
|
|
890
|
+
}
|
|
891
|
+
this.agent = void 0;
|
|
892
|
+
}
|
|
893
|
+
if (this.agent) return this.agent;
|
|
894
|
+
debug('Creating Harmony agent with deviceId:', deviceId || 'auto-detect');
|
|
895
|
+
const agent = await agentFromHdcDevice(deviceId, {
|
|
896
|
+
autoDismissKeyboard: false
|
|
897
|
+
});
|
|
898
|
+
this.agent = agent;
|
|
899
|
+
return agent;
|
|
900
|
+
}
|
|
901
|
+
preparePlatformTools() {
|
|
902
|
+
return [
|
|
903
|
+
{
|
|
904
|
+
name: 'harmony_connect',
|
|
905
|
+
description: 'Connect to HarmonyOS device via HDC. If deviceId not provided, uses the first available device.',
|
|
906
|
+
schema: {
|
|
907
|
+
deviceId: z.string().optional().describe('HarmonyOS device ID (from hdc list targets)')
|
|
908
|
+
},
|
|
909
|
+
handler: async ({ deviceId })=>{
|
|
910
|
+
const agent = await this.ensureAgent(deviceId);
|
|
911
|
+
const screenshot = await agent.page.screenshotBase64();
|
|
912
|
+
return {
|
|
913
|
+
content: [
|
|
914
|
+
{
|
|
915
|
+
type: 'text',
|
|
916
|
+
text: `Connected to HarmonyOS device${deviceId ? `: ${deviceId}` : ' (auto-detected)'}`
|
|
917
|
+
},
|
|
918
|
+
...this.buildScreenshotContent(screenshot)
|
|
919
|
+
],
|
|
920
|
+
isError: false
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
},
|
|
924
|
+
{
|
|
925
|
+
name: 'harmony_disconnect',
|
|
926
|
+
description: 'Disconnect from current HarmonyOS device and release HDC resources',
|
|
927
|
+
schema: {},
|
|
928
|
+
handler: this.createDisconnectHandler('HarmonyOS device')
|
|
929
|
+
}
|
|
930
|
+
];
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
export { HarmonyAgent, HarmonyDevice, HarmonyMidsceneTools, agentFromHdcDevice, getConnectedDevices, overrideAIConfig };
|
package/dist/lib/index.js
CHANGED
|
@@ -34,6 +34,7 @@ var __webpack_exports__ = {};
|
|
|
34
34
|
__webpack_require__.r(__webpack_exports__);
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
36
|
overrideAIConfig: ()=>env_namespaceObject.overrideAIConfig,
|
|
37
|
+
HarmonyMidsceneTools: ()=>HarmonyMidsceneTools,
|
|
37
38
|
agentFromHdcDevice: ()=>agentFromHdcDevice,
|
|
38
39
|
HarmonyAgent: ()=>HarmonyAgent,
|
|
39
40
|
HarmonyDevice: ()=>HarmonyDevice,
|
|
@@ -917,15 +918,72 @@ async function agentFromHdcDevice(deviceId, opts) {
|
|
|
917
918
|
await device.connect();
|
|
918
919
|
return new HarmonyAgent(device, opts);
|
|
919
920
|
}
|
|
921
|
+
const mcp_namespaceObject = require("@midscene/shared/mcp");
|
|
922
|
+
const debug = (0, logger_namespaceObject.getDebug)('mcp:harmony-tools');
|
|
923
|
+
class HarmonyMidsceneTools extends mcp_namespaceObject.BaseMidsceneTools {
|
|
924
|
+
createTemporaryDevice() {
|
|
925
|
+
return new HarmonyDevice('temp-for-action-space', {});
|
|
926
|
+
}
|
|
927
|
+
async ensureAgent(deviceId) {
|
|
928
|
+
if (this.agent && deviceId) {
|
|
929
|
+
try {
|
|
930
|
+
await this.agent.destroy?.();
|
|
931
|
+
} catch (error) {
|
|
932
|
+
debug('Failed to destroy agent during cleanup:', error);
|
|
933
|
+
}
|
|
934
|
+
this.agent = void 0;
|
|
935
|
+
}
|
|
936
|
+
if (this.agent) return this.agent;
|
|
937
|
+
debug('Creating Harmony agent with deviceId:', deviceId || 'auto-detect');
|
|
938
|
+
const agent = await agentFromHdcDevice(deviceId, {
|
|
939
|
+
autoDismissKeyboard: false
|
|
940
|
+
});
|
|
941
|
+
this.agent = agent;
|
|
942
|
+
return agent;
|
|
943
|
+
}
|
|
944
|
+
preparePlatformTools() {
|
|
945
|
+
return [
|
|
946
|
+
{
|
|
947
|
+
name: 'harmony_connect',
|
|
948
|
+
description: 'Connect to HarmonyOS device via HDC. If deviceId not provided, uses the first available device.',
|
|
949
|
+
schema: {
|
|
950
|
+
deviceId: core_namespaceObject.z.string().optional().describe('HarmonyOS device ID (from hdc list targets)')
|
|
951
|
+
},
|
|
952
|
+
handler: async ({ deviceId })=>{
|
|
953
|
+
const agent = await this.ensureAgent(deviceId);
|
|
954
|
+
const screenshot = await agent.page.screenshotBase64();
|
|
955
|
+
return {
|
|
956
|
+
content: [
|
|
957
|
+
{
|
|
958
|
+
type: 'text',
|
|
959
|
+
text: `Connected to HarmonyOS device${deviceId ? `: ${deviceId}` : ' (auto-detected)'}`
|
|
960
|
+
},
|
|
961
|
+
...this.buildScreenshotContent(screenshot)
|
|
962
|
+
],
|
|
963
|
+
isError: false
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
},
|
|
967
|
+
{
|
|
968
|
+
name: 'harmony_disconnect',
|
|
969
|
+
description: 'Disconnect from current HarmonyOS device and release HDC resources',
|
|
970
|
+
schema: {},
|
|
971
|
+
handler: this.createDisconnectHandler('HarmonyOS device')
|
|
972
|
+
}
|
|
973
|
+
];
|
|
974
|
+
}
|
|
975
|
+
}
|
|
920
976
|
const env_namespaceObject = require("@midscene/shared/env");
|
|
921
977
|
exports.HarmonyAgent = __webpack_exports__.HarmonyAgent;
|
|
922
978
|
exports.HarmonyDevice = __webpack_exports__.HarmonyDevice;
|
|
979
|
+
exports.HarmonyMidsceneTools = __webpack_exports__.HarmonyMidsceneTools;
|
|
923
980
|
exports.agentFromHdcDevice = __webpack_exports__.agentFromHdcDevice;
|
|
924
981
|
exports.getConnectedDevices = __webpack_exports__.getConnectedDevices;
|
|
925
982
|
exports.overrideAIConfig = __webpack_exports__.overrideAIConfig;
|
|
926
983
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
927
984
|
"HarmonyAgent",
|
|
928
985
|
"HarmonyDevice",
|
|
986
|
+
"HarmonyMidsceneTools",
|
|
929
987
|
"agentFromHdcDevice",
|
|
930
988
|
"getConnectedDevices",
|
|
931
989
|
"overrideAIConfig"
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { ActionParam } from '@midscene/core';
|
|
|
3
3
|
import type { ActionReturn } from '@midscene/core';
|
|
4
4
|
import { Agent } from '@midscene/core/agent';
|
|
5
5
|
import { AgentOpt } from '@midscene/core/agent';
|
|
6
|
+
import { BaseMidsceneTools } from '@midscene/shared/mcp';
|
|
6
7
|
import { DeviceAction } from '@midscene/core';
|
|
7
8
|
import type { ElementInfo } from '@midscene/shared/extractor';
|
|
8
9
|
import { HarmonyDeviceOpt } from '@midscene/core/device';
|
|
@@ -11,6 +12,7 @@ import { LocateResultElement } from '@midscene/core';
|
|
|
11
12
|
import { overrideAIConfig } from '@midscene/shared/env';
|
|
12
13
|
import { Point } from '@midscene/core';
|
|
13
14
|
import { Size } from '@midscene/core';
|
|
15
|
+
import { ToolDefinition } from '@midscene/shared/mcp';
|
|
14
16
|
|
|
15
17
|
declare type ActionArgs<T extends DeviceAction> = [ActionParam<T>] extends [undefined] ? [] : [ActionParam<T>];
|
|
16
18
|
|
|
@@ -101,6 +103,12 @@ declare interface HarmonyDeviceInfo {
|
|
|
101
103
|
deviceId: string;
|
|
102
104
|
}
|
|
103
105
|
|
|
106
|
+
export declare class HarmonyMidsceneTools extends BaseMidsceneTools<HarmonyAgent> {
|
|
107
|
+
protected createTemporaryDevice(): HarmonyDevice;
|
|
108
|
+
protected ensureAgent(deviceId?: string): Promise<HarmonyAgent>;
|
|
109
|
+
protected preparePlatformTools(): ToolDefinition[];
|
|
110
|
+
}
|
|
111
|
+
|
|
104
112
|
declare class HdcClient {
|
|
105
113
|
private hdcPath;
|
|
106
114
|
private deviceId;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/harmony",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4-beta-20260310030546.0",
|
|
4
4
|
"description": "HarmonyOS automation library for Midscene",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"HarmonyOS UI automation",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@inquirer/prompts": "^7.8.6",
|
|
43
43
|
"open": "10.1.0",
|
|
44
|
-
"@midscene/
|
|
45
|
-
"@midscene/
|
|
46
|
-
"@midscene/
|
|
44
|
+
"@midscene/core": "1.5.4-beta-20260310030546.0",
|
|
45
|
+
"@midscene/shared": "1.5.4-beta-20260310030546.0",
|
|
46
|
+
"@midscene/playground": "1.5.4-beta-20260310030546.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@rslib/core": "^0.18.3",
|
package/static/index.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!doctype html><html><head><link rel="icon" href="/favicon.ico"><title>Midscene Playground</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><script defer src="/static/js/lib-react.7b1abe58.js"></script><script defer src="/static/js/148.23cd9828.js"></script><script defer src="/static/js/index.
|
|
1
|
+
<!doctype html><html><head><link rel="icon" href="/favicon.ico"><title>Midscene Playground</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><script defer src="/static/js/lib-react.7b1abe58.js"></script><script defer src="/static/js/148.23cd9828.js"></script><script defer src="/static/js/index.5dd18cad.js"></script><link href="/static/css/index.b190a147.css" rel="stylesheet"></head><body><div id="root"></div></body></html>
|