@midscene/harmony 1.9.7 → 1.9.8-beta-20260618091332.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/cli.mjs +26 -8
- package/dist/es/index.mjs +25 -7
- package/dist/es/mcp-server.mjs +26 -8
- package/dist/lib/cli.js +26 -8
- package/dist/lib/index.js +25 -7
- package/dist/lib/mcp-server.js +26 -8
- package/dist/types/index.d.ts +9 -3
- package/dist/types/mcp-server.d.ts +9 -3
- package/package.json +4 -4
- package/static/index.html +1 -1
- package/static/static/js/{index.50e06ed5.js → index.64bb287d.js} +52 -52
- package/static/static/js/index.64bb287d.js.map +1 -0
- package/static/static/js/index.50e06ed5.js.map +0 -1
- /package/static/static/js/{index.50e06ed5.js.LICENSE.txt → index.64bb287d.js.LICENSE.txt} +0 -0
package/dist/es/cli.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createReportCliCommands, z } from "@midscene/core";
|
|
2
2
|
import { reportCLIError, runToolsCLI } from "@midscene/shared/cli";
|
|
3
3
|
import { getDebug } from "@midscene/shared/logger";
|
|
4
|
+
import { agentBehaviorInitArgShape, extractAgentBehaviorInitArgs, getAgentInitArgsSignature, shouldRebuildAgentForInitArgs } from "@midscene/shared/mcp/agent-behavior-init-args";
|
|
4
5
|
import { BaseMidsceneTools } from "@midscene/shared/mcp/base-tools";
|
|
5
6
|
import { Agent } from "@midscene/core/agent";
|
|
6
7
|
import { mergeAndNormalizeAppNameMapping, normalizeForComparison, repeat } from "@midscene/shared/utils";
|
|
@@ -986,6 +987,16 @@ function mcp_tools_define_property(obj, key, value) {
|
|
|
986
987
|
return obj;
|
|
987
988
|
}
|
|
988
989
|
const debug = getDebug('mcp:harmony-tools');
|
|
990
|
+
function adaptHarmonyInitArgs(extracted) {
|
|
991
|
+
if (!extracted) return;
|
|
992
|
+
const initArgs = {
|
|
993
|
+
...'string' == typeof extracted.deviceId ? {
|
|
994
|
+
deviceId: extracted.deviceId
|
|
995
|
+
} : {},
|
|
996
|
+
...extractAgentBehaviorInitArgs(extracted) ?? {}
|
|
997
|
+
};
|
|
998
|
+
return Object.keys(initArgs).length > 0 ? initArgs : void 0;
|
|
999
|
+
}
|
|
989
1000
|
class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
990
1001
|
getCliReportSessionName() {
|
|
991
1002
|
return 'midscene-harmony';
|
|
@@ -993,8 +1004,10 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
|
993
1004
|
createTemporaryDevice() {
|
|
994
1005
|
return new HarmonyDevice('temp-for-action-space', {});
|
|
995
1006
|
}
|
|
996
|
-
async ensureAgent(
|
|
997
|
-
|
|
1007
|
+
async ensureAgent(initArgs) {
|
|
1008
|
+
const deviceId = initArgs?.deviceId;
|
|
1009
|
+
const nextSignature = getAgentInitArgsSignature(initArgs);
|
|
1010
|
+
if (this.agent && shouldRebuildAgentForInitArgs(this.lastInitArgsSignature, nextSignature)) {
|
|
998
1011
|
try {
|
|
999
1012
|
await this.agent.destroy?.();
|
|
1000
1013
|
} catch (error) {
|
|
@@ -1007,9 +1020,11 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
|
1007
1020
|
const reportOptions = this.readCliReportAgentOptions();
|
|
1008
1021
|
const agent = await agentFromHdcDevice(deviceId, {
|
|
1009
1022
|
autoDismissKeyboard: false,
|
|
1023
|
+
...extractAgentBehaviorInitArgs(initArgs) ?? {},
|
|
1010
1024
|
...reportOptions ?? {}
|
|
1011
1025
|
});
|
|
1012
1026
|
this.agent = agent;
|
|
1027
|
+
this.lastInitArgsSignature = nextSignature;
|
|
1013
1028
|
return agent;
|
|
1014
1029
|
}
|
|
1015
1030
|
preparePlatformTools() {
|
|
@@ -1020,7 +1035,8 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
|
1020
1035
|
schema: this.getAgentInitArgSchema(),
|
|
1021
1036
|
cli: this.getAgentInitArgCliMetadata(),
|
|
1022
1037
|
handler: async (args)=>{
|
|
1023
|
-
const
|
|
1038
|
+
const initArgs = this.extractAgentInitParam(args);
|
|
1039
|
+
const deviceId = initArgs?.deviceId;
|
|
1024
1040
|
const reportSession = this.createNewCliReportSession(deviceId ?? 'auto');
|
|
1025
1041
|
this.commitCliReportSession(reportSession);
|
|
1026
1042
|
if (this.agent) {
|
|
@@ -1030,8 +1046,9 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
|
1030
1046
|
debug('Failed to destroy agent during connect:', error);
|
|
1031
1047
|
}
|
|
1032
1048
|
this.agent = void 0;
|
|
1049
|
+
this.lastInitArgsSignature = void 0;
|
|
1033
1050
|
}
|
|
1034
|
-
const agent = await this.ensureAgent(
|
|
1051
|
+
const agent = await this.ensureAgent(initArgs);
|
|
1035
1052
|
const screenshot = await agent.page.screenshotBase64();
|
|
1036
1053
|
return {
|
|
1037
1054
|
content: [
|
|
@@ -1054,22 +1071,23 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
|
1054
1071
|
];
|
|
1055
1072
|
}
|
|
1056
1073
|
constructor(...args){
|
|
1057
|
-
super(...args), mcp_tools_define_property(this, "initArgSpec", {
|
|
1074
|
+
super(...args), mcp_tools_define_property(this, "lastInitArgsSignature", void 0), mcp_tools_define_property(this, "initArgSpec", {
|
|
1058
1075
|
namespace: 'harmony',
|
|
1059
1076
|
shape: {
|
|
1060
|
-
deviceId: z.string().optional().describe('HarmonyOS device ID (from hdc list targets)')
|
|
1077
|
+
deviceId: z.string().optional().describe('HarmonyOS device ID (from hdc list targets)'),
|
|
1078
|
+
...agentBehaviorInitArgShape
|
|
1061
1079
|
},
|
|
1062
1080
|
cli: {
|
|
1063
1081
|
preferBareKeys: true
|
|
1064
1082
|
},
|
|
1065
|
-
adapt:
|
|
1083
|
+
adapt: adaptHarmonyInitArgs
|
|
1066
1084
|
});
|
|
1067
1085
|
}
|
|
1068
1086
|
}
|
|
1069
1087
|
const tools = new HarmonyMidsceneTools();
|
|
1070
1088
|
runToolsCLI(tools, 'midscene-harmony', {
|
|
1071
1089
|
stripPrefix: 'harmony_',
|
|
1072
|
-
version: "1.9.
|
|
1090
|
+
version: "1.9.8-beta-20260618091332.0",
|
|
1073
1091
|
extraCommands: createReportCliCommands()
|
|
1074
1092
|
}).catch((e)=>{
|
|
1075
1093
|
process.exit(reportCLIError(e));
|
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 { agentBehaviorInitArgShape, extractAgentBehaviorInitArgs, getAgentInitArgsSignature, shouldRebuildAgentForInitArgs } from "@midscene/shared/mcp/agent-behavior-init-args";
|
|
12
13
|
import { BaseMidsceneTools } from "@midscene/shared/mcp/base-tools";
|
|
13
14
|
import { overrideAIConfig } from "@midscene/shared/env";
|
|
14
15
|
import node_path from "node:path";
|
|
@@ -991,6 +992,16 @@ function mcp_tools_define_property(obj, key, value) {
|
|
|
991
992
|
return obj;
|
|
992
993
|
}
|
|
993
994
|
const debug = getDebug('mcp:harmony-tools');
|
|
995
|
+
function adaptHarmonyInitArgs(extracted) {
|
|
996
|
+
if (!extracted) return;
|
|
997
|
+
const initArgs = {
|
|
998
|
+
...'string' == typeof extracted.deviceId ? {
|
|
999
|
+
deviceId: extracted.deviceId
|
|
1000
|
+
} : {},
|
|
1001
|
+
...extractAgentBehaviorInitArgs(extracted) ?? {}
|
|
1002
|
+
};
|
|
1003
|
+
return Object.keys(initArgs).length > 0 ? initArgs : void 0;
|
|
1004
|
+
}
|
|
994
1005
|
class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
995
1006
|
getCliReportSessionName() {
|
|
996
1007
|
return 'midscene-harmony';
|
|
@@ -998,8 +1009,10 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
|
998
1009
|
createTemporaryDevice() {
|
|
999
1010
|
return new HarmonyDevice('temp-for-action-space', {});
|
|
1000
1011
|
}
|
|
1001
|
-
async ensureAgent(
|
|
1002
|
-
|
|
1012
|
+
async ensureAgent(initArgs) {
|
|
1013
|
+
const deviceId = initArgs?.deviceId;
|
|
1014
|
+
const nextSignature = getAgentInitArgsSignature(initArgs);
|
|
1015
|
+
if (this.agent && shouldRebuildAgentForInitArgs(this.lastInitArgsSignature, nextSignature)) {
|
|
1003
1016
|
try {
|
|
1004
1017
|
await this.agent.destroy?.();
|
|
1005
1018
|
} catch (error) {
|
|
@@ -1012,9 +1025,11 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
|
1012
1025
|
const reportOptions = this.readCliReportAgentOptions();
|
|
1013
1026
|
const agent = await agentFromHdcDevice(deviceId, {
|
|
1014
1027
|
autoDismissKeyboard: false,
|
|
1028
|
+
...extractAgentBehaviorInitArgs(initArgs) ?? {},
|
|
1015
1029
|
...reportOptions ?? {}
|
|
1016
1030
|
});
|
|
1017
1031
|
this.agent = agent;
|
|
1032
|
+
this.lastInitArgsSignature = nextSignature;
|
|
1018
1033
|
return agent;
|
|
1019
1034
|
}
|
|
1020
1035
|
preparePlatformTools() {
|
|
@@ -1025,7 +1040,8 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
|
1025
1040
|
schema: this.getAgentInitArgSchema(),
|
|
1026
1041
|
cli: this.getAgentInitArgCliMetadata(),
|
|
1027
1042
|
handler: async (args)=>{
|
|
1028
|
-
const
|
|
1043
|
+
const initArgs = this.extractAgentInitParam(args);
|
|
1044
|
+
const deviceId = initArgs?.deviceId;
|
|
1029
1045
|
const reportSession = this.createNewCliReportSession(deviceId ?? 'auto');
|
|
1030
1046
|
this.commitCliReportSession(reportSession);
|
|
1031
1047
|
if (this.agent) {
|
|
@@ -1035,8 +1051,9 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
|
1035
1051
|
debug('Failed to destroy agent during connect:', error);
|
|
1036
1052
|
}
|
|
1037
1053
|
this.agent = void 0;
|
|
1054
|
+
this.lastInitArgsSignature = void 0;
|
|
1038
1055
|
}
|
|
1039
|
-
const agent = await this.ensureAgent(
|
|
1056
|
+
const agent = await this.ensureAgent(initArgs);
|
|
1040
1057
|
const screenshot = await agent.page.screenshotBase64();
|
|
1041
1058
|
return {
|
|
1042
1059
|
content: [
|
|
@@ -1059,15 +1076,16 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
|
1059
1076
|
];
|
|
1060
1077
|
}
|
|
1061
1078
|
constructor(...args){
|
|
1062
|
-
super(...args), mcp_tools_define_property(this, "initArgSpec", {
|
|
1079
|
+
super(...args), mcp_tools_define_property(this, "lastInitArgsSignature", void 0), mcp_tools_define_property(this, "initArgSpec", {
|
|
1063
1080
|
namespace: 'harmony',
|
|
1064
1081
|
shape: {
|
|
1065
|
-
deviceId: z.string().optional().describe('HarmonyOS device ID (from hdc list targets)')
|
|
1082
|
+
deviceId: z.string().optional().describe('HarmonyOS device ID (from hdc list targets)'),
|
|
1083
|
+
...agentBehaviorInitArgShape
|
|
1066
1084
|
},
|
|
1067
1085
|
cli: {
|
|
1068
1086
|
preferBareKeys: true
|
|
1069
1087
|
},
|
|
1070
|
-
adapt:
|
|
1088
|
+
adapt: adaptHarmonyInitArgs
|
|
1071
1089
|
});
|
|
1072
1090
|
}
|
|
1073
1091
|
}
|
package/dist/es/mcp-server.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseMCPServer, createMCPServerLauncher } from "@midscene/shared/mcp";
|
|
2
2
|
import { z } from "@midscene/core";
|
|
3
3
|
import { getDebug } from "@midscene/shared/logger";
|
|
4
|
+
import { agentBehaviorInitArgShape, extractAgentBehaviorInitArgs, getAgentInitArgsSignature, shouldRebuildAgentForInitArgs } from "@midscene/shared/mcp/agent-behavior-init-args";
|
|
4
5
|
import { BaseMidsceneTools } from "@midscene/shared/mcp/base-tools";
|
|
5
6
|
import { Agent } from "@midscene/core/agent";
|
|
6
7
|
import { mergeAndNormalizeAppNameMapping, normalizeForComparison, repeat } from "@midscene/shared/utils";
|
|
@@ -986,6 +987,16 @@ function mcp_tools_define_property(obj, key, value) {
|
|
|
986
987
|
return obj;
|
|
987
988
|
}
|
|
988
989
|
const debug = getDebug('mcp:harmony-tools');
|
|
990
|
+
function adaptHarmonyInitArgs(extracted) {
|
|
991
|
+
if (!extracted) return;
|
|
992
|
+
const initArgs = {
|
|
993
|
+
...'string' == typeof extracted.deviceId ? {
|
|
994
|
+
deviceId: extracted.deviceId
|
|
995
|
+
} : {},
|
|
996
|
+
...extractAgentBehaviorInitArgs(extracted) ?? {}
|
|
997
|
+
};
|
|
998
|
+
return Object.keys(initArgs).length > 0 ? initArgs : void 0;
|
|
999
|
+
}
|
|
989
1000
|
class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
990
1001
|
getCliReportSessionName() {
|
|
991
1002
|
return 'midscene-harmony';
|
|
@@ -993,8 +1004,10 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
|
993
1004
|
createTemporaryDevice() {
|
|
994
1005
|
return new HarmonyDevice('temp-for-action-space', {});
|
|
995
1006
|
}
|
|
996
|
-
async ensureAgent(
|
|
997
|
-
|
|
1007
|
+
async ensureAgent(initArgs) {
|
|
1008
|
+
const deviceId = initArgs?.deviceId;
|
|
1009
|
+
const nextSignature = getAgentInitArgsSignature(initArgs);
|
|
1010
|
+
if (this.agent && shouldRebuildAgentForInitArgs(this.lastInitArgsSignature, nextSignature)) {
|
|
998
1011
|
try {
|
|
999
1012
|
await this.agent.destroy?.();
|
|
1000
1013
|
} catch (error) {
|
|
@@ -1007,9 +1020,11 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
|
1007
1020
|
const reportOptions = this.readCliReportAgentOptions();
|
|
1008
1021
|
const agent = await agentFromHdcDevice(deviceId, {
|
|
1009
1022
|
autoDismissKeyboard: false,
|
|
1023
|
+
...extractAgentBehaviorInitArgs(initArgs) ?? {},
|
|
1010
1024
|
...reportOptions ?? {}
|
|
1011
1025
|
});
|
|
1012
1026
|
this.agent = agent;
|
|
1027
|
+
this.lastInitArgsSignature = nextSignature;
|
|
1013
1028
|
return agent;
|
|
1014
1029
|
}
|
|
1015
1030
|
preparePlatformTools() {
|
|
@@ -1020,7 +1035,8 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
|
1020
1035
|
schema: this.getAgentInitArgSchema(),
|
|
1021
1036
|
cli: this.getAgentInitArgCliMetadata(),
|
|
1022
1037
|
handler: async (args)=>{
|
|
1023
|
-
const
|
|
1038
|
+
const initArgs = this.extractAgentInitParam(args);
|
|
1039
|
+
const deviceId = initArgs?.deviceId;
|
|
1024
1040
|
const reportSession = this.createNewCliReportSession(deviceId ?? 'auto');
|
|
1025
1041
|
this.commitCliReportSession(reportSession);
|
|
1026
1042
|
if (this.agent) {
|
|
@@ -1030,8 +1046,9 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
|
1030
1046
|
debug('Failed to destroy agent during connect:', error);
|
|
1031
1047
|
}
|
|
1032
1048
|
this.agent = void 0;
|
|
1049
|
+
this.lastInitArgsSignature = void 0;
|
|
1033
1050
|
}
|
|
1034
|
-
const agent = await this.ensureAgent(
|
|
1051
|
+
const agent = await this.ensureAgent(initArgs);
|
|
1035
1052
|
const screenshot = await agent.page.screenshotBase64();
|
|
1036
1053
|
return {
|
|
1037
1054
|
content: [
|
|
@@ -1054,15 +1071,16 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
|
1054
1071
|
];
|
|
1055
1072
|
}
|
|
1056
1073
|
constructor(...args){
|
|
1057
|
-
super(...args), mcp_tools_define_property(this, "initArgSpec", {
|
|
1074
|
+
super(...args), mcp_tools_define_property(this, "lastInitArgsSignature", void 0), mcp_tools_define_property(this, "initArgSpec", {
|
|
1058
1075
|
namespace: 'harmony',
|
|
1059
1076
|
shape: {
|
|
1060
|
-
deviceId: z.string().optional().describe('HarmonyOS device ID (from hdc list targets)')
|
|
1077
|
+
deviceId: z.string().optional().describe('HarmonyOS device ID (from hdc list targets)'),
|
|
1078
|
+
...agentBehaviorInitArgShape
|
|
1061
1079
|
},
|
|
1062
1080
|
cli: {
|
|
1063
1081
|
preferBareKeys: true
|
|
1064
1082
|
},
|
|
1065
|
-
adapt:
|
|
1083
|
+
adapt: adaptHarmonyInitArgs
|
|
1066
1084
|
});
|
|
1067
1085
|
}
|
|
1068
1086
|
}
|
|
@@ -1073,7 +1091,7 @@ class HarmonyMCPServer extends BaseMCPServer {
|
|
|
1073
1091
|
constructor(toolsManager){
|
|
1074
1092
|
super({
|
|
1075
1093
|
name: '@midscene/harmony-mcp',
|
|
1076
|
-
version: "1.9.
|
|
1094
|
+
version: "1.9.8-beta-20260618091332.0",
|
|
1077
1095
|
description: 'Control the HarmonyOS device using natural language commands'
|
|
1078
1096
|
}, toolsManager);
|
|
1079
1097
|
}
|
package/dist/lib/cli.js
CHANGED
|
@@ -24,6 +24,7 @@ var __webpack_exports__ = {};
|
|
|
24
24
|
const core_namespaceObject = require("@midscene/core");
|
|
25
25
|
const cli_namespaceObject = require("@midscene/shared/cli");
|
|
26
26
|
const logger_namespaceObject = require("@midscene/shared/logger");
|
|
27
|
+
const agent_behavior_init_args_namespaceObject = require("@midscene/shared/mcp/agent-behavior-init-args");
|
|
27
28
|
const base_tools_namespaceObject = require("@midscene/shared/mcp/base-tools");
|
|
28
29
|
const agent_namespaceObject = require("@midscene/core/agent");
|
|
29
30
|
const utils_namespaceObject = require("@midscene/shared/utils");
|
|
@@ -1011,6 +1012,16 @@ function mcp_tools_define_property(obj, key, value) {
|
|
|
1011
1012
|
return obj;
|
|
1012
1013
|
}
|
|
1013
1014
|
const debug = (0, logger_namespaceObject.getDebug)('mcp:harmony-tools');
|
|
1015
|
+
function adaptHarmonyInitArgs(extracted) {
|
|
1016
|
+
if (!extracted) return;
|
|
1017
|
+
const initArgs = {
|
|
1018
|
+
...'string' == typeof extracted.deviceId ? {
|
|
1019
|
+
deviceId: extracted.deviceId
|
|
1020
|
+
} : {},
|
|
1021
|
+
...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(extracted) ?? {}
|
|
1022
|
+
};
|
|
1023
|
+
return Object.keys(initArgs).length > 0 ? initArgs : void 0;
|
|
1024
|
+
}
|
|
1014
1025
|
class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools {
|
|
1015
1026
|
getCliReportSessionName() {
|
|
1016
1027
|
return 'midscene-harmony';
|
|
@@ -1018,8 +1029,10 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1018
1029
|
createTemporaryDevice() {
|
|
1019
1030
|
return new HarmonyDevice('temp-for-action-space', {});
|
|
1020
1031
|
}
|
|
1021
|
-
async ensureAgent(
|
|
1022
|
-
|
|
1032
|
+
async ensureAgent(initArgs) {
|
|
1033
|
+
const deviceId = initArgs?.deviceId;
|
|
1034
|
+
const nextSignature = (0, agent_behavior_init_args_namespaceObject.getAgentInitArgsSignature)(initArgs);
|
|
1035
|
+
if (this.agent && (0, agent_behavior_init_args_namespaceObject.shouldRebuildAgentForInitArgs)(this.lastInitArgsSignature, nextSignature)) {
|
|
1023
1036
|
try {
|
|
1024
1037
|
await this.agent.destroy?.();
|
|
1025
1038
|
} catch (error) {
|
|
@@ -1032,9 +1045,11 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1032
1045
|
const reportOptions = this.readCliReportAgentOptions();
|
|
1033
1046
|
const agent = await agentFromHdcDevice(deviceId, {
|
|
1034
1047
|
autoDismissKeyboard: false,
|
|
1048
|
+
...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(initArgs) ?? {},
|
|
1035
1049
|
...reportOptions ?? {}
|
|
1036
1050
|
});
|
|
1037
1051
|
this.agent = agent;
|
|
1052
|
+
this.lastInitArgsSignature = nextSignature;
|
|
1038
1053
|
return agent;
|
|
1039
1054
|
}
|
|
1040
1055
|
preparePlatformTools() {
|
|
@@ -1045,7 +1060,8 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1045
1060
|
schema: this.getAgentInitArgSchema(),
|
|
1046
1061
|
cli: this.getAgentInitArgCliMetadata(),
|
|
1047
1062
|
handler: async (args)=>{
|
|
1048
|
-
const
|
|
1063
|
+
const initArgs = this.extractAgentInitParam(args);
|
|
1064
|
+
const deviceId = initArgs?.deviceId;
|
|
1049
1065
|
const reportSession = this.createNewCliReportSession(deviceId ?? 'auto');
|
|
1050
1066
|
this.commitCliReportSession(reportSession);
|
|
1051
1067
|
if (this.agent) {
|
|
@@ -1055,8 +1071,9 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1055
1071
|
debug('Failed to destroy agent during connect:', error);
|
|
1056
1072
|
}
|
|
1057
1073
|
this.agent = void 0;
|
|
1074
|
+
this.lastInitArgsSignature = void 0;
|
|
1058
1075
|
}
|
|
1059
|
-
const agent = await this.ensureAgent(
|
|
1076
|
+
const agent = await this.ensureAgent(initArgs);
|
|
1060
1077
|
const screenshot = await agent.page.screenshotBase64();
|
|
1061
1078
|
return {
|
|
1062
1079
|
content: [
|
|
@@ -1079,22 +1096,23 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1079
1096
|
];
|
|
1080
1097
|
}
|
|
1081
1098
|
constructor(...args){
|
|
1082
|
-
super(...args), mcp_tools_define_property(this, "initArgSpec", {
|
|
1099
|
+
super(...args), mcp_tools_define_property(this, "lastInitArgsSignature", void 0), mcp_tools_define_property(this, "initArgSpec", {
|
|
1083
1100
|
namespace: 'harmony',
|
|
1084
1101
|
shape: {
|
|
1085
|
-
deviceId: core_namespaceObject.z.string().optional().describe('HarmonyOS device ID (from hdc list targets)')
|
|
1102
|
+
deviceId: core_namespaceObject.z.string().optional().describe('HarmonyOS device ID (from hdc list targets)'),
|
|
1103
|
+
...agent_behavior_init_args_namespaceObject.agentBehaviorInitArgShape
|
|
1086
1104
|
},
|
|
1087
1105
|
cli: {
|
|
1088
1106
|
preferBareKeys: true
|
|
1089
1107
|
},
|
|
1090
|
-
adapt:
|
|
1108
|
+
adapt: adaptHarmonyInitArgs
|
|
1091
1109
|
});
|
|
1092
1110
|
}
|
|
1093
1111
|
}
|
|
1094
1112
|
const tools = new HarmonyMidsceneTools();
|
|
1095
1113
|
(0, cli_namespaceObject.runToolsCLI)(tools, 'midscene-harmony', {
|
|
1096
1114
|
stripPrefix: 'harmony_',
|
|
1097
|
-
version: "1.9.
|
|
1115
|
+
version: "1.9.8-beta-20260618091332.0",
|
|
1098
1116
|
extraCommands: (0, core_namespaceObject.createReportCliCommands)()
|
|
1099
1117
|
}).catch((e)=>{
|
|
1100
1118
|
process.exit((0, cli_namespaceObject.reportCLIError)(e));
|
package/dist/lib/index.js
CHANGED
|
@@ -1018,6 +1018,7 @@ async function agentFromHdcDevice(deviceId, opts) {
|
|
|
1018
1018
|
await device.connect();
|
|
1019
1019
|
return new HarmonyAgent(device, opts);
|
|
1020
1020
|
}
|
|
1021
|
+
const agent_behavior_init_args_namespaceObject = require("@midscene/shared/mcp/agent-behavior-init-args");
|
|
1021
1022
|
const base_tools_namespaceObject = require("@midscene/shared/mcp/base-tools");
|
|
1022
1023
|
function mcp_tools_define_property(obj, key, value) {
|
|
1023
1024
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
@@ -1030,6 +1031,16 @@ function mcp_tools_define_property(obj, key, value) {
|
|
|
1030
1031
|
return obj;
|
|
1031
1032
|
}
|
|
1032
1033
|
const debug = (0, logger_namespaceObject.getDebug)('mcp:harmony-tools');
|
|
1034
|
+
function adaptHarmonyInitArgs(extracted) {
|
|
1035
|
+
if (!extracted) return;
|
|
1036
|
+
const initArgs = {
|
|
1037
|
+
...'string' == typeof extracted.deviceId ? {
|
|
1038
|
+
deviceId: extracted.deviceId
|
|
1039
|
+
} : {},
|
|
1040
|
+
...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(extracted) ?? {}
|
|
1041
|
+
};
|
|
1042
|
+
return Object.keys(initArgs).length > 0 ? initArgs : void 0;
|
|
1043
|
+
}
|
|
1033
1044
|
class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools {
|
|
1034
1045
|
getCliReportSessionName() {
|
|
1035
1046
|
return 'midscene-harmony';
|
|
@@ -1037,8 +1048,10 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1037
1048
|
createTemporaryDevice() {
|
|
1038
1049
|
return new HarmonyDevice('temp-for-action-space', {});
|
|
1039
1050
|
}
|
|
1040
|
-
async ensureAgent(
|
|
1041
|
-
|
|
1051
|
+
async ensureAgent(initArgs) {
|
|
1052
|
+
const deviceId = initArgs?.deviceId;
|
|
1053
|
+
const nextSignature = (0, agent_behavior_init_args_namespaceObject.getAgentInitArgsSignature)(initArgs);
|
|
1054
|
+
if (this.agent && (0, agent_behavior_init_args_namespaceObject.shouldRebuildAgentForInitArgs)(this.lastInitArgsSignature, nextSignature)) {
|
|
1042
1055
|
try {
|
|
1043
1056
|
await this.agent.destroy?.();
|
|
1044
1057
|
} catch (error) {
|
|
@@ -1051,9 +1064,11 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1051
1064
|
const reportOptions = this.readCliReportAgentOptions();
|
|
1052
1065
|
const agent = await agentFromHdcDevice(deviceId, {
|
|
1053
1066
|
autoDismissKeyboard: false,
|
|
1067
|
+
...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(initArgs) ?? {},
|
|
1054
1068
|
...reportOptions ?? {}
|
|
1055
1069
|
});
|
|
1056
1070
|
this.agent = agent;
|
|
1071
|
+
this.lastInitArgsSignature = nextSignature;
|
|
1057
1072
|
return agent;
|
|
1058
1073
|
}
|
|
1059
1074
|
preparePlatformTools() {
|
|
@@ -1064,7 +1079,8 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1064
1079
|
schema: this.getAgentInitArgSchema(),
|
|
1065
1080
|
cli: this.getAgentInitArgCliMetadata(),
|
|
1066
1081
|
handler: async (args)=>{
|
|
1067
|
-
const
|
|
1082
|
+
const initArgs = this.extractAgentInitParam(args);
|
|
1083
|
+
const deviceId = initArgs?.deviceId;
|
|
1068
1084
|
const reportSession = this.createNewCliReportSession(deviceId ?? 'auto');
|
|
1069
1085
|
this.commitCliReportSession(reportSession);
|
|
1070
1086
|
if (this.agent) {
|
|
@@ -1074,8 +1090,9 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1074
1090
|
debug('Failed to destroy agent during connect:', error);
|
|
1075
1091
|
}
|
|
1076
1092
|
this.agent = void 0;
|
|
1093
|
+
this.lastInitArgsSignature = void 0;
|
|
1077
1094
|
}
|
|
1078
|
-
const agent = await this.ensureAgent(
|
|
1095
|
+
const agent = await this.ensureAgent(initArgs);
|
|
1079
1096
|
const screenshot = await agent.page.screenshotBase64();
|
|
1080
1097
|
return {
|
|
1081
1098
|
content: [
|
|
@@ -1098,15 +1115,16 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1098
1115
|
];
|
|
1099
1116
|
}
|
|
1100
1117
|
constructor(...args){
|
|
1101
|
-
super(...args), mcp_tools_define_property(this, "initArgSpec", {
|
|
1118
|
+
super(...args), mcp_tools_define_property(this, "lastInitArgsSignature", void 0), mcp_tools_define_property(this, "initArgSpec", {
|
|
1102
1119
|
namespace: 'harmony',
|
|
1103
1120
|
shape: {
|
|
1104
|
-
deviceId: core_namespaceObject.z.string().optional().describe('HarmonyOS device ID (from hdc list targets)')
|
|
1121
|
+
deviceId: core_namespaceObject.z.string().optional().describe('HarmonyOS device ID (from hdc list targets)'),
|
|
1122
|
+
...agent_behavior_init_args_namespaceObject.agentBehaviorInitArgShape
|
|
1105
1123
|
},
|
|
1106
1124
|
cli: {
|
|
1107
1125
|
preferBareKeys: true
|
|
1108
1126
|
},
|
|
1109
|
-
adapt:
|
|
1127
|
+
adapt: adaptHarmonyInitArgs
|
|
1110
1128
|
});
|
|
1111
1129
|
}
|
|
1112
1130
|
}
|
package/dist/lib/mcp-server.js
CHANGED
|
@@ -40,6 +40,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
40
40
|
const mcp_namespaceObject = require("@midscene/shared/mcp");
|
|
41
41
|
const core_namespaceObject = require("@midscene/core");
|
|
42
42
|
const logger_namespaceObject = require("@midscene/shared/logger");
|
|
43
|
+
const agent_behavior_init_args_namespaceObject = require("@midscene/shared/mcp/agent-behavior-init-args");
|
|
43
44
|
const base_tools_namespaceObject = require("@midscene/shared/mcp/base-tools");
|
|
44
45
|
const agent_namespaceObject = require("@midscene/core/agent");
|
|
45
46
|
const utils_namespaceObject = require("@midscene/shared/utils");
|
|
@@ -1027,6 +1028,16 @@ function mcp_tools_define_property(obj, key, value) {
|
|
|
1027
1028
|
return obj;
|
|
1028
1029
|
}
|
|
1029
1030
|
const debug = (0, logger_namespaceObject.getDebug)('mcp:harmony-tools');
|
|
1031
|
+
function adaptHarmonyInitArgs(extracted) {
|
|
1032
|
+
if (!extracted) return;
|
|
1033
|
+
const initArgs = {
|
|
1034
|
+
...'string' == typeof extracted.deviceId ? {
|
|
1035
|
+
deviceId: extracted.deviceId
|
|
1036
|
+
} : {},
|
|
1037
|
+
...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(extracted) ?? {}
|
|
1038
|
+
};
|
|
1039
|
+
return Object.keys(initArgs).length > 0 ? initArgs : void 0;
|
|
1040
|
+
}
|
|
1030
1041
|
class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools {
|
|
1031
1042
|
getCliReportSessionName() {
|
|
1032
1043
|
return 'midscene-harmony';
|
|
@@ -1034,8 +1045,10 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1034
1045
|
createTemporaryDevice() {
|
|
1035
1046
|
return new HarmonyDevice('temp-for-action-space', {});
|
|
1036
1047
|
}
|
|
1037
|
-
async ensureAgent(
|
|
1038
|
-
|
|
1048
|
+
async ensureAgent(initArgs) {
|
|
1049
|
+
const deviceId = initArgs?.deviceId;
|
|
1050
|
+
const nextSignature = (0, agent_behavior_init_args_namespaceObject.getAgentInitArgsSignature)(initArgs);
|
|
1051
|
+
if (this.agent && (0, agent_behavior_init_args_namespaceObject.shouldRebuildAgentForInitArgs)(this.lastInitArgsSignature, nextSignature)) {
|
|
1039
1052
|
try {
|
|
1040
1053
|
await this.agent.destroy?.();
|
|
1041
1054
|
} catch (error) {
|
|
@@ -1048,9 +1061,11 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1048
1061
|
const reportOptions = this.readCliReportAgentOptions();
|
|
1049
1062
|
const agent = await agentFromHdcDevice(deviceId, {
|
|
1050
1063
|
autoDismissKeyboard: false,
|
|
1064
|
+
...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(initArgs) ?? {},
|
|
1051
1065
|
...reportOptions ?? {}
|
|
1052
1066
|
});
|
|
1053
1067
|
this.agent = agent;
|
|
1068
|
+
this.lastInitArgsSignature = nextSignature;
|
|
1054
1069
|
return agent;
|
|
1055
1070
|
}
|
|
1056
1071
|
preparePlatformTools() {
|
|
@@ -1061,7 +1076,8 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1061
1076
|
schema: this.getAgentInitArgSchema(),
|
|
1062
1077
|
cli: this.getAgentInitArgCliMetadata(),
|
|
1063
1078
|
handler: async (args)=>{
|
|
1064
|
-
const
|
|
1079
|
+
const initArgs = this.extractAgentInitParam(args);
|
|
1080
|
+
const deviceId = initArgs?.deviceId;
|
|
1065
1081
|
const reportSession = this.createNewCliReportSession(deviceId ?? 'auto');
|
|
1066
1082
|
this.commitCliReportSession(reportSession);
|
|
1067
1083
|
if (this.agent) {
|
|
@@ -1071,8 +1087,9 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1071
1087
|
debug('Failed to destroy agent during connect:', error);
|
|
1072
1088
|
}
|
|
1073
1089
|
this.agent = void 0;
|
|
1090
|
+
this.lastInitArgsSignature = void 0;
|
|
1074
1091
|
}
|
|
1075
|
-
const agent = await this.ensureAgent(
|
|
1092
|
+
const agent = await this.ensureAgent(initArgs);
|
|
1076
1093
|
const screenshot = await agent.page.screenshotBase64();
|
|
1077
1094
|
return {
|
|
1078
1095
|
content: [
|
|
@@ -1095,15 +1112,16 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1095
1112
|
];
|
|
1096
1113
|
}
|
|
1097
1114
|
constructor(...args){
|
|
1098
|
-
super(...args), mcp_tools_define_property(this, "initArgSpec", {
|
|
1115
|
+
super(...args), mcp_tools_define_property(this, "lastInitArgsSignature", void 0), mcp_tools_define_property(this, "initArgSpec", {
|
|
1099
1116
|
namespace: 'harmony',
|
|
1100
1117
|
shape: {
|
|
1101
|
-
deviceId: core_namespaceObject.z.string().optional().describe('HarmonyOS device ID (from hdc list targets)')
|
|
1118
|
+
deviceId: core_namespaceObject.z.string().optional().describe('HarmonyOS device ID (from hdc list targets)'),
|
|
1119
|
+
...agent_behavior_init_args_namespaceObject.agentBehaviorInitArgShape
|
|
1102
1120
|
},
|
|
1103
1121
|
cli: {
|
|
1104
1122
|
preferBareKeys: true
|
|
1105
1123
|
},
|
|
1106
|
-
adapt:
|
|
1124
|
+
adapt: adaptHarmonyInitArgs
|
|
1107
1125
|
});
|
|
1108
1126
|
}
|
|
1109
1127
|
}
|
|
@@ -1114,7 +1132,7 @@ class HarmonyMCPServer extends mcp_namespaceObject.BaseMCPServer {
|
|
|
1114
1132
|
constructor(toolsManager){
|
|
1115
1133
|
super({
|
|
1116
1134
|
name: '@midscene/harmony-mcp',
|
|
1117
|
-
version: "1.9.
|
|
1135
|
+
version: "1.9.8-beta-20260618091332.0",
|
|
1118
1136
|
description: 'Control the HarmonyOS device using natural language commands'
|
|
1119
1137
|
}, toolsManager);
|
|
1120
1138
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { AbstractInterface } from '@midscene/core/device';
|
|
|
2
2
|
import type { ActionParam } from '@midscene/core';
|
|
3
3
|
import type { ActionReturn } from '@midscene/core';
|
|
4
4
|
import { Agent } from '@midscene/core/agent';
|
|
5
|
+
import { AgentBehaviorInitArgs } from '@midscene/shared/mcp/agent-behavior-init-args';
|
|
5
6
|
import { AgentOpt } from '@midscene/core/agent';
|
|
6
7
|
import { BaseMidsceneTools } from '@midscene/shared/mcp/base-tools';
|
|
7
8
|
import { DeviceAction } from '@midscene/core';
|
|
@@ -138,11 +139,16 @@ declare type HarmonyDeviceInputOpt = HarmonyDeviceInputOpt_2 & {
|
|
|
138
139
|
|
|
139
140
|
declare type HarmonyDeviceOpt = HarmonyDeviceOpt_2 & HarmonyDeviceInputOpt;
|
|
140
141
|
|
|
141
|
-
|
|
142
|
+
declare type HarmonyInitArgs = AgentBehaviorInitArgs & {
|
|
143
|
+
deviceId?: string;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export declare class HarmonyMidsceneTools extends BaseMidsceneTools<HarmonyAgent, HarmonyInitArgs> {
|
|
147
|
+
private lastInitArgsSignature?;
|
|
142
148
|
protected getCliReportSessionName(): string;
|
|
143
|
-
protected readonly initArgSpec: InitArgSpec<
|
|
149
|
+
protected readonly initArgSpec: InitArgSpec<HarmonyInitArgs>;
|
|
144
150
|
protected createTemporaryDevice(): HarmonyDevice;
|
|
145
|
-
protected ensureAgent(
|
|
151
|
+
protected ensureAgent(initArgs?: HarmonyInitArgs): Promise<HarmonyAgent>;
|
|
146
152
|
protected preparePlatformTools(): ToolDefinition[];
|
|
147
153
|
}
|
|
148
154
|
|
|
@@ -2,6 +2,7 @@ import { AbstractInterface } from '@midscene/core/device';
|
|
|
2
2
|
import type { ActionParam } from '@midscene/core';
|
|
3
3
|
import type { ActionReturn } from '@midscene/core';
|
|
4
4
|
import { Agent } from '@midscene/core/agent';
|
|
5
|
+
import { AgentBehaviorInitArgs } from '@midscene/shared/mcp/agent-behavior-init-args';
|
|
5
6
|
import { AgentOpt } from '@midscene/core/agent';
|
|
6
7
|
import { BaseMCPServer } from '@midscene/shared/mcp';
|
|
7
8
|
import { BaseMidsceneTools } from '@midscene/shared/mcp/base-tools';
|
|
@@ -128,16 +129,21 @@ declare type HarmonyDeviceInputOpt = HarmonyDeviceInputOpt_2 & {
|
|
|
128
129
|
|
|
129
130
|
declare type HarmonyDeviceOpt = HarmonyDeviceOpt_2 & HarmonyDeviceInputOpt;
|
|
130
131
|
|
|
132
|
+
declare type HarmonyInitArgs = AgentBehaviorInitArgs & {
|
|
133
|
+
deviceId?: string;
|
|
134
|
+
};
|
|
135
|
+
|
|
131
136
|
export declare class HarmonyMCPServer extends BaseMCPServer {
|
|
132
137
|
constructor(toolsManager?: HarmonyMidsceneTools);
|
|
133
138
|
protected createToolsManager(): HarmonyMidsceneTools;
|
|
134
139
|
}
|
|
135
140
|
|
|
136
|
-
declare class HarmonyMidsceneTools extends BaseMidsceneTools<HarmonyAgent,
|
|
141
|
+
declare class HarmonyMidsceneTools extends BaseMidsceneTools<HarmonyAgent, HarmonyInitArgs> {
|
|
142
|
+
private lastInitArgsSignature?;
|
|
137
143
|
protected getCliReportSessionName(): string;
|
|
138
|
-
protected readonly initArgSpec: InitArgSpec<
|
|
144
|
+
protected readonly initArgSpec: InitArgSpec<HarmonyInitArgs>;
|
|
139
145
|
protected createTemporaryDevice(): HarmonyDevice;
|
|
140
|
-
protected ensureAgent(
|
|
146
|
+
protected ensureAgent(initArgs?: HarmonyInitArgs): Promise<HarmonyAgent>;
|
|
141
147
|
protected preparePlatformTools(): ToolDefinition[];
|
|
142
148
|
}
|
|
143
149
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/harmony",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.8-beta-20260618091332.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/web-infra-dev/midscene.git",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@inquirer/prompts": "^7.8.6",
|
|
48
48
|
"open": "10.1.0",
|
|
49
|
-
"@midscene/
|
|
50
|
-
"@midscene/
|
|
51
|
-
"@midscene/
|
|
49
|
+
"@midscene/playground": "1.9.8-beta-20260618091332.0",
|
|
50
|
+
"@midscene/shared": "1.9.8-beta-20260618091332.0",
|
|
51
|
+
"@midscene/core": "1.9.8-beta-20260618091332.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@rslib/core": "^0.18.3",
|